Search in sources :

Example 26 with ErrorFatal

use of edu.mit.csail.sdg.alloy4.ErrorFatal in project org.alloytools.alloy by AlloyTools.

the class TranslateAlloyToKodkod method execute_command.

/**
 * Based on the specified "options", execute one command and return the
 * resulting A4Solution object.
 *
 * @param rep - if nonnull, we'll send compilation diagnostic messages to it
 * @param sigs - the list of sigs; this list must be complete
 * @param cmd - the Command to execute
 * @param opt - the set of options guiding the execution of the command
 * @return null if the user chose "save to FILE" as the SAT solver, and nonnull
 *         if the solver finishes the entire solving and is either satisfiable
 *         or unsatisfiable.
 *         <p>
 *         If the return value X is satisfiable, you can call X.next() to get
 *         the next satisfying solution X2; and you can call X2.next() to get
 *         the next satisfying solution X3... until you get an unsatisfying
 *         solution.
 */
public static A4Solution execute_command(A4Reporter rep, Iterable<Sig> sigs, Command cmd, A4Options opt) throws Err {
    if (rep == null)
        rep = A4Reporter.NOP;
    TranslateAlloyToKodkod tr = null;
    try {
        if (cmd.parent != null || !cmd.getGrowableSigs().isEmpty())
            return execute_greedyCommand(rep, sigs, cmd, opt);
        tr = new TranslateAlloyToKodkod(rep, opt, sigs, cmd);
        tr.makeFacts(cmd.formula);
        return tr.frame.solve(rep, cmd, new Simplifier(), false);
    } catch (UnsatisfiedLinkError ex) {
        throw new ErrorFatal("The required JNI library cannot be found: " + ex.toString().trim(), ex);
    } catch (CapacityExceededException ex) {
        throw rethrow(ex);
    } catch (HigherOrderDeclException ex) {
        Pos p = tr != null ? tr.frame.kv2typepos(ex.decl().variable()).b : Pos.UNKNOWN;
        throw new ErrorType(p, "Analysis cannot be performed since it requires higher-order quantification that could not be skolemized.");
    } catch (Throwable ex) {
        if (ex instanceof Err)
            throw (Err) ex;
        else
            throw new ErrorFatal("Unknown exception occurred: " + ex, ex);
    }
}
Also used : CapacityExceededException(kodkod.engine.CapacityExceededException) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Err(edu.mit.csail.sdg.alloy4.Err) Pos(edu.mit.csail.sdg.alloy4.Pos) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException)

Example 27 with ErrorFatal

use of edu.mit.csail.sdg.alloy4.ErrorFatal in project org.alloytools.alloy by AlloyTools.

the class TranslateAlloyToKodkod method alloy2kodkod.

/**
 * Translate the Alloy expression into an equivalent Kodkod Expression or
 * IntExpression or Formula object.
 *
 * @param sol - an existing satisfiable A4Solution object
 * @param expr - this is the Alloy expression we want to translate
 */
public static Object alloy2kodkod(A4Solution sol, Expr expr) throws Err {
    if (expr.ambiguous && !expr.errors.isEmpty())
        expr = expr.resolve(expr.type(), null);
    if (!expr.errors.isEmpty())
        throw expr.errors.pick();
    TranslateAlloyToKodkod tr = new TranslateAlloyToKodkod(sol.getBitwidth(), sol.unrolls(), sol.a2k(), sol.s2k());
    Object ans;
    try {
        ans = tr.visitThis(expr);
    } catch (UnsatisfiedLinkError ex) {
        throw new ErrorFatal("The required JNI library cannot be found: " + ex.toString().trim());
    } catch (CapacityExceededException ex) {
        throw rethrow(ex);
    } catch (HigherOrderDeclException ex) {
        throw new ErrorType("Analysis cannot be performed since it requires higher-order quantification that could not be skolemized.");
    } catch (Throwable ex) {
        if (ex instanceof Err)
            throw (Err) ex;
        throw new ErrorFatal("Unknown exception occurred: " + ex, ex);
    }
    if ((ans instanceof IntExpression) || (ans instanceof Formula) || (ans instanceof Expression))
        return ans;
    throw new ErrorFatal("Unknown internal error encountered in the evaluator.");
}
Also used : QuantifiedFormula(kodkod.ast.QuantifiedFormula) Formula(kodkod.ast.Formula) CapacityExceededException(kodkod.engine.CapacityExceededException) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Err(edu.mit.csail.sdg.alloy4.Err) Expression(kodkod.ast.Expression) BinaryExpression(kodkod.ast.BinaryExpression) IntExpression(kodkod.ast.IntExpression) IntExpression(kodkod.ast.IntExpression) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException)

Example 28 with ErrorFatal

use of edu.mit.csail.sdg.alloy4.ErrorFatal in project org.alloytools.alloy by AlloyTools.

the class CompUtil method parseEverything_fromFile.

// =============================================================================================================//
/**
 * Read everything from "file" and parse it; if it mentions submodules, open
 * them and parse them too.
 *
 * @param rep - if nonnull, we will report compilation progress messages to it
 * @param loaded - a cache of files that have been pre-fetched (can be null if
 *            there were no prefetching)
 * @param filename - the main module we are parsing
 * @return the root Module which contains pointers to all submodules
 * @throws Err if an error occurred
 *             <p>
 *             And if loaded!=null, it will contain all the files needed for
 *             this parse, and furthermore, other entries will be deleted.
 */
public static CompModule parseEverything_fromFile(A4Reporter rep, Map<String, String> loaded, String filename) throws Err {
    try {
        filename = Util.canon(filename);
        Set<String> thispath = new LinkedHashSet<String>();
        if (loaded == null)
            loaded = new LinkedHashMap<String, String>();
        Map<String, String> fc = new LinkedHashMap<String, String>(loaded);
        loaded.clear();
        List<Object> seenDollar = new ArrayList<Object>();
        CompModule root = parseRecursively(seenDollar, loaded, fc, new Pos(filename, 1, 1), filename, null, "", thispath, 1);
        root.seenDollar = seenDollar.size() > 0;
        return CompModule.resolveAll(rep == null ? A4Reporter.NOP : rep, root);
    } catch (FileNotFoundException ex) {
        throw new ErrorSyntax("File cannot be found.\n" + ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new ErrorFatal("IOException occurred: " + ex.getMessage(), ex);
    } catch (Throwable ex) {
        if (ex instanceof Err)
            throw (Err) ex;
        else
            throw new ErrorFatal("Unknown exception occurred: " + ex, ex);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Err(edu.mit.csail.sdg.alloy4.Err) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) Pos(edu.mit.csail.sdg.alloy4.Pos)

Example 29 with ErrorFatal

use of edu.mit.csail.sdg.alloy4.ErrorFatal in project org.alloytools.alloy by AlloyTools.

the class StaticInstanceReader method sig.

/**
 * Returns the AlloyType corresponding to the given sig; create an AlloyType for
 * it if none existed before.
 */
private AlloyType sig(PrimSig s) throws Err {
    if (s == Sig.NONE)
        throw new ErrorFatal("Unexpected sig \"none\" encountered.");
    AlloyType ans = sig2type.get(s);
    if (ans == null) {
        ans = makeType(s.label, s.isOne != null, s.isAbstract != null, false, s.isPrivate != null, s.isMeta != null, s.isEnum != null);
        sig2type.put(s, ans);
        if (s.parent != Sig.UNIV)
            ts.put(ans, sig(s.parent));
    }
    return ans;
}
Also used : ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal)

Example 30 with ErrorFatal

use of edu.mit.csail.sdg.alloy4.ErrorFatal in project org.alloytools.alloy by AlloyTools.

the class SimpleGUI method convert.

/**
 * Converts an A4TupleSet into a SimTupleset object.
 */
private static SimTupleset convert(Object object) throws Err {
    if (!(object instanceof A4TupleSet))
        throw new ErrorFatal("Unexpected type error: expecting an A4TupleSet.");
    A4TupleSet s = (A4TupleSet) object;
    if (s.size() == 0)
        return SimTupleset.EMPTY;
    List<SimTuple> list = new ArrayList<SimTuple>(s.size());
    int arity = s.arity();
    for (A4Tuple t : s) {
        String[] array = new String[arity];
        for (int i = 0; i < t.arity(); i++) array[i] = t.atom(i);
        list.add(SimTuple.make(array));
    }
    return SimTupleset.make(list);
}
Also used : A4Tuple(edu.mit.csail.sdg.translator.A4Tuple) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) SimTuple(edu.mit.csail.sdg.sim.SimTuple) ArrayList(java.util.ArrayList) A4TupleSet(edu.mit.csail.sdg.translator.A4TupleSet)

Aggregations

ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)29 Err (edu.mit.csail.sdg.alloy4.Err)8 Expr (edu.mit.csail.sdg.ast.Expr)6 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)6 Pos (edu.mit.csail.sdg.alloy4.Pos)4 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)3 ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)3 ExprVar (edu.mit.csail.sdg.ast.ExprVar)3 Sig (edu.mit.csail.sdg.ast.Sig)3 IOException (java.io.IOException)3 LinkedHashSet (java.util.LinkedHashSet)3 BinaryExpression (kodkod.ast.BinaryExpression)3 CapacityExceededException (kodkod.engine.CapacityExceededException)3 HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)3 ErrorAPI (edu.mit.csail.sdg.alloy4.ErrorAPI)2 Field (edu.mit.csail.sdg.ast.Sig.Field)2 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)2 A4Tuple (edu.mit.csail.sdg.translator.A4Tuple)2