use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.
the class CompModule method addModelName.
/**
* Add the "MODULE" declaration.
*/
void addModelName(Pos pos, String moduleName, List<ExprVar> list) throws Err {
if (status > 0)
throw new ErrorSyntax(pos, "The \"module\" declaration must occur at the top,\n" + "and can occur at most once.");
this.moduleName = moduleName;
this.modulePos = pos;
boolean nextIsExact = false;
if (list != null)
for (ExprVar expr : list) {
if (expr == null) {
nextIsExact = true;
continue;
}
String name = expr.label;
dup(expr.span(), name, true);
if (path.length() == 0) {
Sig newSig = addSig(name, null, null, null, null, WHERE.make(expr.span()));
if (nextIsExact)
exactSigs.add(newSig);
} else {
params.put(name, null);
if (nextIsExact)
exactParams.add(name);
}
nextIsExact = false;
}
// This line must be at the end, since "addSig" will
this.status = 1;
// otherwise bump the status value to 3
}
use of edu.mit.csail.sdg.alloy4.Pos 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.alloy4.Pos in project org.alloytools.alloy by AlloyTools.
the class CompModule method resolveSig.
/**
* The given Sig will now point to a nonnull Sig.
*/
private static Sig resolveSig(CompModule res, Set<Object> topo, Sig oldS) throws Err {
if (res.new2old.containsKey(oldS))
return oldS;
Sig realSig;
final Pos pos = oldS.pos;
final CompModule u = res.sig2module.get(oldS);
final String name = base(oldS);
final String fullname = (u.path.length() == 0) ? ("this/" + name) : (u.path + "/" + name);
if (!topo.add(oldS))
throw new ErrorType(pos, "Sig " + oldS + " is involved in a cyclic inheritance.");
if (oldS instanceof SubsetSig) {
List<Sig> parents = new ArrayList<Sig>();
for (Sig n : ((SubsetSig) oldS).parents) {
Sig parentAST = u.getRawSIG(n.pos, n.label);
if (parentAST == null)
throw new ErrorSyntax(n.pos, "The sig \"" + n.label + "\" cannot be found.");
parents.add(resolveSig(res, topo, parentAST));
}
realSig = new SubsetSig(fullname, parents, oldS.attributes.toArray(new Attr[0]));
} else {
Sig sup = ((PrimSig) oldS).parent;
Sig parentAST = u.getRawSIG(sup.pos, sup.label);
if (parentAST == null)
throw new ErrorSyntax(sup.pos, "The sig \"" + sup.label + "\" cannot be found.");
Sig parent = resolveSig(res, topo, parentAST);
if (!(parent instanceof PrimSig))
throw new ErrorSyntax(sup.pos, "Cannot extend the subset signature \"" + parent + "\".\n" + "A signature can only extend a toplevel signature or a subsignature.");
PrimSig p = (PrimSig) parent;
realSig = new PrimSig(fullname, p, oldS.attributes.toArray(new Attr[0]));
}
res.new2old.put(realSig, oldS);
res.sig2module.put(realSig, u);
for (CompModule m : res.allModules) {
for (Map.Entry<String, Sig> e : m.sigs.entrySet()) if (e.getValue() == oldS)
e.setValue(realSig);
for (Map.Entry<String, Sig> e : m.params.entrySet()) if (e.getValue() == oldS)
e.setValue(realSig);
}
if (res.exactSigs.remove(oldS))
res.exactSigs.add(realSig);
return realSig;
}
use of edu.mit.csail.sdg.alloy4.Pos 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.alloy4.Pos in project org.alloytools.alloy by AlloyTools.
the class A4Solution method k2pos.
/**
* Associates the Kodkod formula to a particular Alloy Expr (if the Kodkod
* formula is not already associated with an Alloy Expr or Alloy Pos)
*/
Formula k2pos(Formula formula, Expr expr) throws Err {
if (solved)
throw new ErrorFatal("Cannot alter the k->pos mapping since solve() has completed.");
if (formula == null || expr == null || k2pos.containsKey(formula))
return formula;
k2pos.put(formula, expr);
if (formula instanceof BinaryFormula) {
BinaryFormula b = (BinaryFormula) formula;
if (b.op() == FormulaOperator.AND) {
k2pos(b.left(), expr);
k2pos(b.right(), expr);
}
}
return formula;
}
Aggregations