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);
}
}
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.");
}
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);
}
}
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;
}
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);
}
Aggregations