use of edu.mit.csail.sdg.alloy4.ErrorFatal in project org.alloytools.alloy by AlloyTools.
the class StaticInstanceReader method sigMETA.
/**
* Returns the AlloyType corresponding to the given sig; create an AlloyType for
* it if none existed before.
*/
private AlloyType sigMETA(PrimSig s) throws Err {
if (s == Sig.NONE)
throw new ErrorFatal("Unexpected sig \"none\" encountered.");
AlloyType type = sig2type.get(s);
if (type != null)
return type;
if (s == Sig.UNIV)
type = AlloyType.UNIV;
else if (s == Sig.SIGINT)
type = AlloyType.INT;
else if (s == Sig.SEQIDX)
type = AlloyType.SEQINT;
else if (s == Sig.STRING)
type = AlloyType.STRING;
else
type = makeType(s.label, s.isOne != null, s.isAbstract != null, false, s.isPrivate != null, s.isMeta != null, s.isEnum != null);
sig2type.put(s, type);
AlloyAtom atom = new AlloyAtom(type, (type == AlloyType.SEQINT ? Integer.MIN_VALUE : Integer.MAX_VALUE), s.label);
atom2sets.put(atom, new LinkedHashSet<AlloySet>());
sig2atom.put(s, atom);
if (s.parent != Sig.UNIV && s.parent != null)
ts.put(type, sigMETA(s.parent));
if (s.parent != null)
exts.add(new AlloyTuple(atom, sig2atom.get(s.parent)));
Iterable<PrimSig> children = (s == Sig.UNIV ? toplevels : s.children());
for (PrimSig sub : children) sigMETA(sub);
return type;
}
use of edu.mit.csail.sdg.alloy4.ErrorFatal in project org.alloytools.alloy by AlloyTools.
the class ExampleUsingTheCompiler method main.
/*
* Execute every command in every file. This method parses every file, then
* execute every command. If there are syntax or type errors, it may throw a
* ErrorSyntax or ErrorType or ErrorAPI or ErrorFatal exception. You should
* catch them and display them, and they may contain filename/line/column
* information.
*/
public static void main(String[] args) throws Err {
// The visualizer (We will initialize it to nonnull when we visualize an
// Alloy solution)
VizGUI viz = null;
// Alloy4 sends diagnostic messages and progress reports to the
// A4Reporter.
// By default, the A4Reporter ignores all these events (but you can
// extend the A4Reporter to display the event for the user)
A4Reporter rep = new A4Reporter() {
// For example, here we choose to display each "warning" by printing
// it to System.out
@Override
public void warning(ErrorWarning msg) {
System.out.print("Relevance Warning:\n" + (msg.toString().trim()) + "\n\n");
System.out.flush();
}
};
for (String filename : args) {
// Parse+typecheck the model
System.out.println("=========== Parsing+Typechecking " + filename + " =============");
Module world = CompUtil.parseEverything_fromFile(rep, null, filename);
// Choose some default options for how you want to execute the
// commands
A4Options options = new A4Options();
options.solver = A4Options.SatSolver.SAT4J;
for (Command command : world.getAllCommands()) {
// Execute the command
System.out.println("============ Command " + command + ": ============");
A4Solution ans = TranslateAlloyToKodkod.execute_command(rep, world.getAllReachableSigs(), command, options);
// Print the outcome
System.out.println(ans);
// If satisfiable...
if (ans.satisfiable()) {
// You can query "ans" to find out the values of each set or
// type.
// This can be useful for debugging.
//
// You can also write the outcome to an XML file
ans.writeXML("alloy_example_output.xml");
// You can then visualize the XML file by calling this:
if (viz == null) {
viz = new VizGUI(false, "alloy_example_output.xml", null);
} else {
viz.loadXML("alloy_example_output.xml", true);
}
}
}
}
}
use of edu.mit.csail.sdg.alloy4.ErrorFatal in project org.alloytools.alloy by AlloyTools.
the class CompModule method resolveParams.
/**
* Every param in every module will now point to a nonnull Sig.
*/
private static void resolveParams(A4Reporter rep, List<CompModule> modules) throws Err {
while (true) {
boolean chg = false;
Open missing = null;
String missingName = "";
for (CompModule mod : modules) for (Open open : mod.opens.values()) {
CompModule sub = open.realModule;
if (open.args.size() != sub.params.size())
throw new ErrorSyntax(open.pos, "You supplied " + open.args.size() + " arguments to the open statement, but the imported module requires " + sub.params.size() + " arguments.");
int i = 0;
for (Map.Entry<String, Sig> p : sub.params.entrySet()) {
Sig old = p.getValue();
String kn = p.getKey(), vn = open.args.get(i);
i++;
Sig vv = mod.getRawSIG(open.pos, vn);
if (vv == null) {
if (old == null) {
missing = open;
missingName = vn;
}
continue;
}
if (old == vv)
continue;
if (old != null)
throw new ErrorFatal(open.pos, "Internal error (module re-instantiated with different arguments)");
if (vv == NONE)
throw new ErrorSyntax(open.pos, "You cannot use \"none\" as an instantiating argument.");
chg = true;
p.setValue(vv);
rep.parse("RESOLVE: " + (sub.path.length() == 0 ? "this/" : sub.path) + "/" + kn + " := " + vv + "\n");
}
}
if (!chg && missing == null)
return;
if (!chg)
throw new ErrorSyntax(missing.pos, "The signature name \"" + missingName + "\" cannot be found.");
}
}
use of edu.mit.csail.sdg.alloy4.ErrorFatal in project org.alloytools.alloy by AlloyTools.
the class SimInstance method visit.
/**
* {@inheritDoc}
*/
@Override
public Object visit(ExprQt x) throws Err {
Expr xx = x.desugar();
if (xx instanceof ExprQt)
x = (ExprQt) xx;
else
return visitThis(xx);
if (x.op == ExprQt.Op.COMPREHENSION) {
TempList<SimTuple> ans = new TempList<SimTuple>();
enumerate(ans, 0, x, x.sub, 0);
return SimTupleset.make(ans.makeConst());
}
if (x.op == ExprQt.Op.ALL)
return enumerate(null, 0, x, x.sub.not(), 0) == 0;
if (x.op == ExprQt.Op.NO)
return enumerate(null, 0, x, x.sub, 0) == 0;
if (x.op == ExprQt.Op.SOME)
return enumerate(null, 0, x, x.sub, 0) >= 1;
if (x.op == ExprQt.Op.LONE)
return enumerate(null, 0, x, x.sub, 0) <= 1;
if (x.op == ExprQt.Op.ONE)
return enumerate(null, 0, x, x.sub, 0) == 1;
if (x.op == ExprQt.Op.SUM)
return trunc(enumerate(null, 0, x, x.sub, 0));
throw new ErrorFatal(x.pos, "Unsupported operator (" + x.op + ") encountered during ExprQt.accept()");
}
use of edu.mit.csail.sdg.alloy4.ErrorFatal in project org.alloytools.alloy by AlloyTools.
the class SimInstance method visit.
/**
* {@inheritDoc}
*/
@Override
public SimTupleset visit(Field x) throws Err {
if (x.defined) {
final ExprVar v = (ExprVar) (x.sig.decl.get());
final Expr b = x.decl().expr;
final Env<ExprVar, Object> oldenv = env;
env = new Env<ExprVar, Object>();
if (!b.hasVar(v)) {
SimTupleset ans = cset(x.sig).product(cset(b));
env = oldenv;
return ans;
}
SimTupleset ans = SimTupleset.EMPTY;
for (SimTuple a : visit(x.sig)) {
SimTupleset left = SimTupleset.make(a);
env.put(v, left);
SimTupleset right = cset(b);
env.remove(v);
ans = left.product(right).union(ans);
}
env = oldenv;
return ans;
}
Object ans = sfs.get(x);
if (ans instanceof SimTupleset)
return (SimTupleset) ans;
else
throw new ErrorFatal("Unknown field " + x + " encountered during evaluation.");
}
Aggregations