Skip to content

Commit

Permalink
[recursion] Fixes the infinite recursion in the check for integers an… (
Browse files Browse the repository at this point in the history
#22)

* [recursion] Fixes the infinite recursion in the check for integers and strings

* [recurs] More output and added hamcrest.

* [recurs] Wrong project

* [recurse] Tests need sat4j on the path

* [recurse] Running in some problems with the split

- Moved models to core
- Application had wrong resource directory
- Core gradle file was including a wrong dependency (all deps must go through bnd)
  • Loading branch information
pkriens authored Nov 17, 2017
1 parent 7abd6cb commit b145939
Show file tree
Hide file tree
Showing 51 changed files with 171 additions and 16 deletions.
2 changes: 1 addition & 1 deletion org.alloytools.alloy.application/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<classpath>
<classpathentry excluding="test/java/" kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="src" path="src/resources"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="output" path="target/classes"/>
Expand Down
6 changes: 4 additions & 2 deletions org.alloytools.alloy.application/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
-includeresource: \
src/resources
src/main/resources

-buildpath: \
lib/apple-osx-ui.jar;version=file,\
org.alloytools.alloy.core;version=latest,\
org.alloytools.kodkod.core;version=latest

-testpath: \
osgi.enroute.junit.wrapper
osgi.enroute.junit.wrapper, \
osgi.enroute.hamcrest.wrapper, \
org.sat4j.core

Private-Package: \
edu.mit.csail.sdg.alloy4graph,\
Expand Down
3 changes: 2 additions & 1 deletion org.alloytools.alloy.core/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<classpath>
<classpathentry excluding="test/java/" kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="src" path="src/resources"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="output" path="target/classes"/>
Expand Down
8 changes: 7 additions & 1 deletion org.alloytools.alloy.core/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

-includeresource: \
src/main/resources

-buildpath: \
org.alloytools.kodkod.core;version=latest, \
org.sat4j.core,\
Expand All @@ -9,7 +12,10 @@
org.alloytools.kodkod.nativesat.x86-windows;version=latest

-testpath: \
osgi.enroute.junit.wrapper
osgi.enroute.junit.wrapper, \
osgi.enroute.hamcrest.wrapper, \
src/main/resources;version=file


Export-Package: \
edu.mit.csail.sdg.alloy4,\
Expand Down
4 changes: 0 additions & 4 deletions org.alloytools.alloy.core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
apply plugin: 'java'

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}

task jflex(type: JavaExec) {
inputs.files("src/main/java/edu/mit/csail/sdg/parser/Alloy.lex")
outputs.files("src/main/java/edu/mit/csail/sdg/parser/CompLexer.java")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import java.util.List;
import java.util.Set;

import edu.mit.csail.sdg.alloy4.Err;
import edu.mit.csail.sdg.alloy4.Pos;
import edu.mit.csail.sdg.alloy4.ConstList;
import edu.mit.csail.sdg.alloy4.Util;
import edu.mit.csail.sdg.alloy4.ConstList.TempList;
import edu.mit.csail.sdg.alloy4.Err;
import edu.mit.csail.sdg.alloy4.ErrorSyntax;
import edu.mit.csail.sdg.alloy4.Pos;
import edu.mit.csail.sdg.alloy4.Util;

/**
* Immutable; reresents a "run" or "check" command.
Expand Down Expand Up @@ -269,7 +269,7 @@ public ConstList<Sig> getGrowableSigs() {
*/
public Set<String> getAllStringConstants(Iterable<Sig> sigs) throws Err {
final Set<String> set = new HashSet<String>();
final VisitQuery<Object> findString = new VisitQuery<Object>() {
final VisitQuery<Object> findString = new VisitQueryOnce<Object>() {
@Override
public final Object visit(ExprConstant x) throws Err {
if (x.op == ExprConstant.Op.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

package edu.mit.csail.sdg.ast;

import java.util.HashSet;
import java.util.Set;

import edu.mit.csail.sdg.alloy4.Err;
import edu.mit.csail.sdg.ast.Sig.Field;

Expand All @@ -30,7 +33,7 @@
*/

public abstract class VisitQuery<T> extends VisitReturn<T> {

/** Constructs a VisitQuery object. */
public VisitQuery() {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package edu.mit.csail.sdg.ast;

import java.util.HashSet;
import java.util.Set;

import edu.mit.csail.sdg.alloy4.Err;
import edu.mit.csail.sdg.ast.Sig.Field;

/**
* Acts like VisitQuery but never traverses a node more than once.
*
*/
public class VisitQueryOnce<T> extends VisitQuery<T> {
final Set<Expr> visited = new HashSet<>();

@Override
public T visit(ExprBinary x) throws Err {
if (visited(x))
return null;
else
return super.visit(x);
}

/**
* Visits an ExprList node F[X1,X2,X3..] by calling accept() on X1, X2,
* X3...
*/
@Override
public T visit(ExprList x) throws Err {
if (visited(x))
return null;
else
return super.visit(x);
}

/**
* Visits an ExprCall node F[X1,X2,X3..] by calling accept() on X1, X2,
* X3...
*/
@Override
public T visit(ExprCall x) throws Err {
if (visited(x))
return null;
else
return super.visit(x);
}

/**
* Visits an ExprConstant node (this default implementation simply returns
* null)
*/
@Override
public T visit(ExprConstant x) throws Err {
if (visited(x))
return null;
else
return super.visit(x);
}

/**
* Visits an ExprITE node (C => X else Y) by calling accept() on C, X, then
* Y.
*/
@Override
public T visit(ExprITE x) throws Err {
if (visited(x))
return null;
else
return super.visit(x);
}

/**
* Visits an ExprLet node (let a=x | y) by calling accept() on "a", "x",
* then "y".
*/
@Override
public T visit(ExprLet x) throws Err {
if (visited(x))
return null;
else
return super.visit(x);
}

/**
* Visits an ExprQt node (all a,b,c:X1, d,e,f:X2... | F) by calling accept()
* on a,b,c,X1,d,e,f,X2... then on F.
*/
@Override
public T visit(ExprQt x) throws Err {
if (visited(x))
return null;
else
return super.visit(x);
}

/** Visits an ExprUnary node (OP X) by calling accept() on X. */
@Override
public T visit(ExprUnary x) throws Err {
if (visited(x))
return null;
else
return super.visit(x);
}

/**
* Visits a ExprVar node (this default implementation simply returns null)
*/
@Override
public T visit(ExprVar x) throws Err {
if (visited(x))
return null;
else
return super.visit(x);
}

/** Visits a Sig node (this default implementation simply returns null) */
@Override
public T visit(Sig x) throws Err {
if (visited(x))
return null;
else
return super.visit(x);
}

/** Visits a Field node (this default implementation simply returns null) */
@Override
public T visit(Field x) throws Err {
if (visited(x))
return null;
else
return super.visit(x);
}

private boolean visited(Expr x) {
return visited.add(x);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import edu.mit.csail.sdg.ast.Module;
import edu.mit.csail.sdg.ast.Sig;
import edu.mit.csail.sdg.ast.VisitQuery;
import edu.mit.csail.sdg.ast.VisitQueryOnce;
import edu.mit.csail.sdg.ast.ExprUnary.Op;
import edu.mit.csail.sdg.ast.Sig.Field;
import edu.mit.csail.sdg.ast.Type.ProductType;
Expand Down Expand Up @@ -150,7 +151,7 @@ public static boolean areIntsUsed(Iterable<Sig> sigs, Command cmd) {
/* check expressions; look for CAST2SIGING (Int[]) */
try {
Object intTriggerNode;
intTriggerNode = cmd.formula.accept(new VisitQuery<Object>() {
intTriggerNode = cmd.formula.accept(new VisitQueryOnce<Object>() {
@Override
public Object visit(ExprCall x) throws Err {
// skip integer arithmetic functions, because their
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package edu.mit.csail.sdg.alloy4whole;
package org.alloytools.alloy.core;


import org.junit.Test;

Expand All @@ -18,11 +19,13 @@ public void testRecursion() throws Exception {
Module world = CompUtil.parseEverything_fromFile(A4Reporter.NOP, null, filename);

A4Options options = new A4Options();
options.unrolls = 10;
for (Command command : world.getAllCommands()) {
A4Solution ans = TranslateAlloyToKodkod.execute_command(A4Reporter.NOP, world.getAllReachableSigs(),
command, options);
while (ans.satisfiable()) {
String hc = "Answer: " + ans.toString().hashCode();
System.out.println(hc);
ans = ans.next();
}
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sig Foo { n : lone Foo }
pred a[ f : Foo ] { some f.n implies b[f.n] }
pred b[ f : Foo ] { some f.n implies a[f.n] }

run a for 4

0 comments on commit b145939

Please sign in to comment.