use of xmashrush2.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 xmashrush2.Pos in project org.alloytools.alloy by AlloyTools.
the class CompLexer method alloy_num.
private final Symbol alloy_num(String txt) throws Err {
Pos p = alloy_here(txt);
int n = 0;
try {
txt = txt.replaceAll("_", "");
n = Integer.parseInt(txt);
} catch (NumberFormatException ex) {
throw new ErrorSyntax(p, "The number " + txt + " " + ex);
}
return new Symbol(CompSym.NUMBER, p, ExprConstant.Op.NUMBER.make(p, n));
}
use of xmashrush2.Pos in project org.alloytools.alloy by AlloyTools.
the class CompLexer method alloy_hexnum.
private final Symbol alloy_hexnum(String txt) throws Err {
Pos p = alloy_here(txt);
int n = 0;
try {
txt = txt.substring(2).replaceAll("_", "");
n = Integer.parseInt(txt, 16);
} catch (NumberFormatException ex) {
throw new ErrorSyntax(p, "The hex number " + txt + " " + ex);
}
return new Symbol(CompSym.NUMBER, p, ExprConstant.Op.NUMBER.make(p, n));
}
use of xmashrush2.Pos in project org.alloytools.alloy by AlloyTools.
the class CUP$CompParser$actions method c.
private void c(boolean follow, ExprVar o, ExprVar x, ExprVar n, Expr e, List<CommandScope> s, ExprConstant c) throws Err {
if (n != null)
nod(n);
int bitwidth = (-1), maxseq = (-1), overall = (-1), expects = (c == null ? -1 : c.num);
Pos p = o.pos.merge(n != null ? n.span() : e.span());
for (int i = s.size() - 1; i >= 0; i--) {
Sig j = s.get(i).sig;
int k = s.get(i).startingScope;
p = p.merge(j.pos);
if (j.label.equals("univ")) {
overall = k;
s.remove(i);
continue;
}
if (j.label.equals("int")) {
if (bitwidth >= 0)
throw new ErrorSyntax(j.pos, "The bitwidth cannot be specified more than once.");
bitwidth = k;
s.remove(i);
continue;
}
if (j.label.equals("seq")) {
if (maxseq >= 0)
throw new ErrorSyntax(j.pos, "The maximum sequence length cannot be specified more than once.");
maxseq = k;
s.remove(i);
continue;
}
}
if (n != null)
parser.alloymodule.addCommand(follow, p, n, o.label.equals("c"), overall, bitwidth, maxseq, expects, s, x);
else
parser.alloymodule.addCommand(follow, p, e, o.label.equals("c"), overall, bitwidth, maxseq, expects, s, x);
}
use of xmashrush2.Pos in project org.alloytools.alloy by AlloyTools.
the class ExprBadCall method span.
/**
* {@inheritDoc}
*/
@Override
public Pos span() {
Pos p = span;
if (p == null) {
p = pos.merge(closingBracket);
for (Expr a : args) p = p.merge(a.span());
span = p;
}
return p;
}
Aggregations