Search in sources :

Example 86 with Err

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);
        }
    }
}
Also used : Err(edu.mit.csail.sdg.alloy4.Err) Command(edu.mit.csail.sdg.ast.Command) A4Reporter(edu.mit.csail.sdg.alloy4.A4Reporter) A4Options(edu.mit.csail.sdg.translator.A4Options) Module(edu.mit.csail.sdg.ast.Module) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Example 87 with Err

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("]");
            }
        }
    }
}
Also used : ErrorAPI(edu.mit.csail.sdg.alloy4.ErrorAPI) A4Reporter(edu.mit.csail.sdg.alloy4.A4Reporter) A4TupleSet(edu.mit.csail.sdg.translator.A4TupleSet) Sig(edu.mit.csail.sdg.ast.Sig) Field(edu.mit.csail.sdg.ast.Sig.Field) A4Tuple(edu.mit.csail.sdg.translator.A4Tuple) CompModule(edu.mit.csail.sdg.parser.CompModule) Command(edu.mit.csail.sdg.ast.Command) A4Options(edu.mit.csail.sdg.translator.A4Options) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Example 88 with Err

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));
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Err(edu.mit.csail.sdg.alloy4.Err) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType)

Aggregations

ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)32 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)28 ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)27 Err (edu.mit.csail.sdg.alloy4.Err)25 Expr (edu.mit.csail.sdg.ast.Expr)25 Sig (edu.mit.csail.sdg.ast.Sig)24 Pos (edu.mit.csail.sdg.alloy4.Pos)16 ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)15 ExprVar (edu.mit.csail.sdg.ast.ExprVar)15 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)15 ArrayList (java.util.ArrayList)15 Field (edu.mit.csail.sdg.ast.Sig.Field)12 LinkedHashMap (java.util.LinkedHashMap)10 IOException (java.io.IOException)9 TempList (edu.mit.csail.sdg.alloy4.ConstList.TempList)8 Func (edu.mit.csail.sdg.ast.Func)8 TupleSet (kodkod.instance.TupleSet)8 Command (edu.mit.csail.sdg.ast.Command)7 ErrorAPI (edu.mit.csail.sdg.alloy4.ErrorAPI)6 XMLNode (edu.mit.csail.sdg.alloy4.XMLNode)5