use of edu.mit.csail.sdg.alloy4.Err in project org.alloytools.alloy by AlloyTools.
the class AlloyTest method main.
public static void main(String[] args) throws Exception {
A4Reporter rep = new A4Reporter();
Module world = CompUtil.parseEverything_fromFile(rep, null, "/home/aleks/mvc.als");
A4Options options = new A4Options();
options.solver = A4Options.SatSolver.SAT4J;
options.skolemDepth = 1;
for (Command command : world.getAllCommands()) {
A4Solution ans = null;
try {
ans = TranslateAlloyToKodkod.execute_commandFromBook(rep, world.getAllReachableSigs(), command, options);
System.out.println(ans);
} catch (Err ex) {
Logger.getLogger(AlloyTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
use of edu.mit.csail.sdg.alloy4.Err in project org.alloytools.alloy by AlloyTools.
the class ExampleCompilingFromSource method compileModuleAndRun.
public static void compileModuleAndRun(String model) throws Err {
A4Reporter rep = new A4Reporter();
// parse model from string
CompModule world = CompUtil.parseEverything_fromString(rep, model);
ConstList<Command> commands = world.getAllCommands();
if (commands.size() != 1)
throw new ErrorAPI("Must specify exactly one command; number of commands found: " + commands.size());
Command cmd = commands.get(0);
A4Options opt = new A4Options();
opt.solver = A4Options.SatSolver.SAT4J;
// solve
A4Solution sol = TranslateAlloyToKodkod.execute_command(rep, world.getAllSigs(), cmd, opt);
// print solution
System.out.println(sol);
for (Sig sig : world.getAllReachableSigs()) {
System.out.println("traversing sig: " + sig);
SafeList<Field> fields = sig.getFields();
for (Field field : fields) {
System.out.println(" traversing field: " + field);
A4TupleSet ts = (sol.eval(field));
for (A4Tuple t : ts) {
System.out.print(" [");
for (int i = 0; i < t.arity(); i++) System.out.print(t.atom(i) + " ");
System.out.println("]");
}
}
}
}
use of edu.mit.csail.sdg.alloy4.Err in project org.alloytools.alloy by AlloyTools.
the class ExprITE method make.
/**
* Constructs a ExprITE expression.
*
* @param cond - the condition formula
* @param left - the then-clause
* @param right - the else-clause
*/
public static Expr make(Pos pos, Expr cond, Expr left, Expr right) {
JoinableList<Err> errs = emptyListOfErrors;
if (cond.mult != 0)
errs = errs.make(new ErrorSyntax(cond.span(), "Multiplicity expression not allowed here."));
if (left.mult != 0)
errs = errs.make(new ErrorSyntax(left.span(), "Multiplicity expression not allowed here."));
if (right.mult != 0)
errs = errs.make(new ErrorSyntax(right.span(), "Multiplicity expression not allowed here."));
Type c = EMPTY;
while (left.errors.isEmpty() && right.errors.isEmpty()) {
Type a = left.type, b = right.type;
c = a.unionWithCommonArity(b);
// if (a.is_int && b.is_int) c=Type.makeInt(c);
if (a.is_bool && b.is_bool)
c = Type.makeBool(c);
if (c == EMPTY) {
// [AM]
// if (Type.SIGINT2INT) {
// if (a.is_int && b.intersects(SIGINT.type)) {
// right=right.cast2int(); continue; }
// if (b.is_int && a.intersects(SIGINT.type)) {
// left=left.cast2int(); continue; }
// }
// if (Type.INT2SIGINT) {
// if (a.is_int && b.hasArity(1)) { left=left.cast2sigint();
// continue; }
// if (b.is_int && a.hasArity(1)) { right=right.cast2sigint();
// continue; }
// }
errs = errs.make(new ErrorType(cond.span().merge(right.span()).merge(left.span()), "The then-clause and the else-clause must match.\nThe then-clause has type: " + a + "\nand the else-clause has type: " + b));
}
break;
}
cond = cond.typecheck_as_formula();
return new ExprITE(pos, cond, left, right, c, errs.make(cond.errors).make(left.errors).make(right.errors));
}
Aggregations