use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.
the class Macro method instantiate.
/**
* Instantiate it.
*
* @param warnings - the list that will receive any warning we generate; can be
* null if we wish to ignore warnings
*/
Expr instantiate(Context cx, List<ErrorWarning> warnings) throws Err {
if (cx.unrolls <= 0) {
Pos p = span();
return new ExprBad(p, toString(), new ErrorType(p, "Macro substitution too deep; possibly indicating an infinite recursion."));
}
if (params.size() != args.size())
return this;
Context cx2 = new Context(realModule, warnings, cx.unrolls - 1);
for (int n = params.size(), i = 0; i < n; i++) {
Expr tmp = args.get(i);
if (!(tmp instanceof Macro))
tmp = tmp.resolve(tmp.type(), warnings);
cx2.put(params.get(i).label, tmp);
}
return cx2.check(body);
}
use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.
the class A4Solution method highLevelCore.
/**
* If this solution is unsatisfiable and its unsat core is available, then
* return the core; else return an empty set.
*/
public Pair<Set<Pos>, Set<Pos>> highLevelCore() {
if (hCoreCache != null)
return hCoreCache;
Set<Pos> ans1 = new LinkedHashSet<Pos>(), ans2 = new LinkedHashSet<Pos>();
if (hCore != null)
for (Node f : hCore) {
Object x = k2pos(f);
if (x instanceof Pos) {
// System.out.println("F: "+f+" at "+x+"\n");
// System.out.flush();
ans1.add((Pos) x);
} else if (x instanceof Expr) {
Expr expr = (Expr) x;
Pos p = ((Expr) x).span();
ans1.add(p);
// System.out.flush();
for (Func func : expr.findAllFunctions()) ans2.add(func.getBody().span());
}
}
return hCoreCache = new Pair<Set<Pos>, Set<Pos>>(Collections.unmodifiableSet(ans1), Collections.unmodifiableSet(ans2));
}
use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.
the class CompLexer method alloy_string.
private final Symbol alloy_string(String txt) throws Err {
Pos p = alloy_here(txt);
if (!Version.experimental)
throw new ErrorSyntax(p, "String literal is not currently supported.");
StringBuilder sb = new StringBuilder(txt.length());
for (int i = 0; i < txt.length(); i++) {
char c = txt.charAt(i);
if (c == '\r' || c == '\n')
throw new ErrorSyntax(p, "String literal cannot span multiple lines; use \\n instead.");
if (c == '\\') {
i++;
if (i >= txt.length())
throw new ErrorSyntax(p, "String literal cannot end with a single \\");
c = txt.charAt(i);
if (c == 'n')
c = '\n';
else if (c != '\'' && c != '\"' && c != '\\')
throw new ErrorSyntax(p, "String literal currenty only supports\nfour escape sequences: \\\\, \\n, \\\', and \\\"");
}
sb.append(c);
}
txt = sb.toString();
if (txt.length() == 2)
throw new ErrorSyntax(p, "Empty string is not allowed; try rewriting your model to use an empty set instead.");
return new Symbol(CompSym.STR, p, ExprConstant.Op.STRING.make(p, txt));
}
use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.
the class CompLexer method alloy_binarynum.
private final Symbol alloy_binarynum(String txt) throws Err {
Pos p = alloy_here(txt);
int n = 0;
try {
txt = txt.substring(2).replaceAll("_", "");
n = Integer.parseInt(txt, 2);
} catch (NumberFormatException ex) {
throw new ErrorSyntax(p, "The binary number " + txt + " " + ex);
}
return new Symbol(CompSym.NUMBER, p, ExprConstant.Op.NUMBER.make(p, n));
}
use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.
the class CompModule method addSig.
Sig addSig(String name, ExprVar par, List<ExprVar> parents, List<Decl> fields, Expr fact, Attr... attributes) throws Err {
Sig obj;
Pos pos = Pos.UNKNOWN.merge(WHERE.find(attributes));
status = 3;
dup(pos, name, true);
String full = (path.length() == 0) ? "this/" + name : path + "/" + name;
Pos subset = null, subsig = null;
boolean exact = false;
if (par != null) {
if (par.label.equals("extends")) {
subsig = par.span().merge(parents.get(0).span());
} else {
exact = !par.label.equals("in");
subset = par.span();
for (ExprVar p : parents) subset = p.span().merge(subset);
}
}
attributes = Util.append(attributes, exact ? Attr.EXACT : null);
if (subset != null) {
attributes = Util.append(attributes, SUBSET.makenull(subset));
List<Sig> newParents = new ArrayList<Sig>(parents == null ? 0 : parents.size());
if (parents != null)
for (ExprVar p : parents) newParents.add(new PrimSig(p.label, WHERE.make(p.pos)));
obj = new SubsetSig(full, newParents, attributes);
} else {
attributes = Util.append(attributes, SUBSIG.makenull(subsig));
PrimSig newParent = (parents != null && parents.size() > 0) ? (new PrimSig(parents.get(0).label, WHERE.make(parents.get(0).pos))) : UNIV;
obj = new PrimSig(full, newParent, attributes);
}
sigs.put(name, obj);
old2fields.put(obj, fields);
old2appendedfacts.put(obj, fact);
return obj;
}
Aggregations