use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.
the class CompModule method addCommand.
// ============================================================================================================================//
/**
* Add a COMMAND declaration.
*/
void addCommand(boolean followUp, Pos pos, ExprVar name, boolean check, int overall, int bitwidth, int seq, int exp, List<CommandScope> scopes, ExprVar label) throws Err {
if (followUp && !Version.experimental)
throw new ErrorSyntax(pos, "Syntax error encountering => symbol.");
if (label != null)
pos = Pos.UNKNOWN.merge(pos).merge(label.pos);
status = 3;
if (name.label.length() == 0)
throw new ErrorSyntax(pos, "Predicate/assertion name cannot be empty.");
if (name.label.indexOf('@') >= 0)
throw new ErrorSyntax(pos, "Predicate/assertion name cannot contain \'@\'");
String labelName = (label == null || label.label.length() == 0) ? name.label : label.label;
Command parent = followUp ? commands.get(commands.size() - 1) : null;
Command newcommand = new Command(pos, name, labelName, check, overall, bitwidth, seq, exp, scopes, null, name, parent);
if (parent != null)
commands.set(commands.size() - 1, newcommand);
else
commands.add(newcommand);
}
use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.
the class CompModule method addCommand.
/**
* Add a COMMAND declaration.
*/
void addCommand(boolean followUp, Pos pos, Expr e, boolean check, int overall, int bitwidth, int seq, int expects, List<CommandScope> scopes, ExprVar label) throws Err {
if (followUp && !Version.experimental)
throw new ErrorSyntax(pos, "Syntax error encountering => symbol.");
if (label != null)
pos = Pos.UNKNOWN.merge(pos).merge(label.pos);
status = 3;
String n;
if (check)
n = addAssertion(pos, "check$" + (1 + commands.size()), e);
else
addFunc(e.span().merge(pos), Pos.UNKNOWN, n = "run$" + (1 + commands.size()), null, new ArrayList<Decl>(), null, e);
String labelName = (label == null || label.label.length() == 0) ? n : label.label;
Command parent = followUp ? commands.get(commands.size() - 1) : null;
Command newcommand = new Command(e.span().merge(pos), e, labelName, check, overall, bitwidth, seq, expects, scopes, null, ExprVar.make(null, n), parent);
if (parent != null)
commands.set(commands.size() - 1, newcommand);
else
commands.add(newcommand);
}
use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.
the class CompModule method resolveCommand.
/**
* Resolve a particular command.
*/
private Command resolveCommand(Command cmd, ConstList<Sig> exactSigs, Expr globalFacts) throws Err {
Command parent = cmd.parent == null ? null : resolveCommand(cmd.parent, exactSigs, globalFacts);
String cname = ((ExprVar) (cmd.formula)).label;
Expr e;
Clause declaringClause = null;
if (cmd.check) {
// We prefer assertion in the
List<Object> m = getRawQS(2, cname);
// topmost module
if (m.size() == 0 && cname.indexOf('/') < 0)
m = getRawNQS(this, 2, cname);
if (m.size() > 1)
unique(cmd.pos, cname, m);
if (m.size() < 1)
throw new ErrorSyntax(cmd.pos, "The assertion \"" + cname + "\" cannot be found.");
Expr expr = (Expr) (m.get(0));
e = expr.not();
} else {
// We prefer fun/pred in the
List<Object> m = getRawQS(4, cname);
// topmost module
if (m.size() == 0 && cname.indexOf('/') < 0)
m = getRawNQS(this, 4, cname);
if (m.size() > 1)
unique(cmd.pos, cname, m);
if (m.size() < 1)
throw new ErrorSyntax(cmd.pos, "The predicate/function \"" + cname + "\" cannot be found.");
Func f = (Func) (m.get(0));
declaringClause = f;
e = f.getBody();
if (!f.isPred)
e = e.in(f.returnDecl);
if (f.decls.size() > 0)
e = ExprQt.Op.SOME.make(null, null, f.decls, e);
}
if (e == null)
e = ExprConstant.TRUE;
TempList<CommandScope> sc = new TempList<CommandScope>(cmd.scope.size());
for (CommandScope et : cmd.scope) {
Sig s = getRawSIG(et.sig.pos, et.sig.label);
if (s == null)
throw new ErrorSyntax(et.sig.pos, "The sig \"" + et.sig.label + "\" cannot be found.");
sc.add(new CommandScope(null, s, et.isExact, et.startingScope, et.endingScope, et.increment));
}
if (cmd.nameExpr != null) {
cmd.nameExpr.setReferenced(declaringClause);
}
return new Command(cmd.pos, cmd.nameExpr, cmd.label, cmd.check, cmd.overall, cmd.bitwidth, cmd.maxseq, cmd.expects, sc.makeConst(), exactSigs, globalFacts.and(e), parent);
}
use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.
the class SimpleReporter method resultSAT.
/**
* {@inheritDoc}
*/
@Override
public void resultSAT(Object command, long solvingTime, Object solution) {
if (!(solution instanceof A4Solution) || !(command instanceof Command))
return;
A4Solution sol = (A4Solution) solution;
Command cmd = (Command) command;
String formula = recordKodkod ? sol.debugExtractKInput() : "";
String filename = tempfile + ".xml";
synchronized (SimpleReporter.class) {
try {
cb("R3", " Writing the XML file...");
if (latestModule != null)
writeXML(this, latestModule, filename, sol, latestKodkodSRC);
} catch (Throwable ex) {
cb("bold", "\n" + (ex.toString().trim()) + "\nStackTrace:\n" + (MailBug.dump(ex).trim()) + "\n");
return;
}
latestKodkods.clear();
latestKodkods.add(sol.toString());
latestKodkod = sol;
latestKodkodXML = filename;
}
String formulafilename = "";
if (formula.length() > 0 && tempfile != null) {
formulafilename = tempfile + ".java";
try {
Util.writeAll(formulafilename, formula);
formulafilename = "CNF: " + formulafilename;
} catch (Throwable ex) {
formulafilename = "";
}
}
cb("sat", cmd.check, cmd.expects, filename, formulafilename, System.currentTimeMillis() - lastTime);
}
use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.
the class SimpleReporter method resultUNSAT.
/**
* {@inheritDoc}
*/
@Override
public void resultUNSAT(Object command, long solvingTime, Object solution) {
if (!(solution instanceof A4Solution) || !(command instanceof Command))
return;
A4Solution sol = (A4Solution) solution;
Command cmd = (Command) command;
String originalFormula = recordKodkod ? sol.debugExtractKInput() : "";
String corefilename = "", formulafilename = "";
if (originalFormula.length() > 0 && tempfile != null) {
formulafilename = tempfile + ".java";
try {
Util.writeAll(formulafilename, originalFormula);
formulafilename = "CNF: " + formulafilename;
} catch (Throwable ex) {
formulafilename = "";
}
}
Pair<Set<Pos>, Set<Pos>> core = sol.highLevelCore();
if ((core.a.size() > 0 || core.b.size() > 0) && tempfile != null) {
corefilename = tempfile + ".core";
OutputStream fs = null;
ObjectOutputStream os = null;
try {
fs = new FileOutputStream(corefilename);
os = new ObjectOutputStream(fs);
os.writeObject(core);
os.writeObject(sol.lowLevelCore());
corefilename = "CORE: " + corefilename;
} catch (Throwable ex) {
corefilename = "";
} finally {
Util.close(os);
Util.close(fs);
}
}
if (minimized == 0)
cb("unsat", cmd.check, cmd.expects, (System.currentTimeMillis() - lastTime), formulafilename);
else
cb("unsat", cmd.check, cmd.expects, minimized - lastTime, formulafilename, corefilename, minimizedBefore, minimizedAfter, (System.currentTimeMillis() - minimized));
}
Aggregations