Search in sources :

Example 1 with Pos

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;
}
Also used : PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig) Sig(edu.mit.csail.sdg.ast.Sig) SubsetSig(edu.mit.csail.sdg.ast.Sig.SubsetSig) SubsetSig(edu.mit.csail.sdg.ast.Sig.SubsetSig) ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Pos(edu.mit.csail.sdg.alloy4.Pos) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig)

Example 2 with Pos

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));
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Pos(edu.mit.csail.sdg.alloy4.Pos) Symbol(java_cup.runtime.Symbol)

Example 3 with Pos

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));
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Pos(edu.mit.csail.sdg.alloy4.Pos) Symbol(java_cup.runtime.Symbol)

Example 4 with Pos

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);
}
Also used : PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig) Sig(edu.mit.csail.sdg.ast.Sig) ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Pos(edu.mit.csail.sdg.alloy4.Pos)

Example 5 with Pos

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;
}
Also used : Pos(edu.mit.csail.sdg.alloy4.Pos)

Aggregations

Pos (edu.mit.csail.sdg.alloy4.Pos)42 ArrayList (java.util.ArrayList)17 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)15 Expr (edu.mit.csail.sdg.ast.Expr)14 LinkedHashMap (java.util.LinkedHashMap)13 Err (edu.mit.csail.sdg.alloy4.Err)12 Sig (edu.mit.csail.sdg.ast.Sig)12 IOException (java.io.IOException)12 ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)11 HashMap (java.util.HashMap)10 AlloyLanguageServerUtil.createRangeFromPos (org.alloytools.alloy.lsp.provider.AlloyLanguageServerUtil.createRangeFromPos)10 AlloyLanguageServerUtil.positionToPos (org.alloytools.alloy.lsp.provider.AlloyLanguageServerUtil.positionToPos)10 Map (java.util.Map)9 ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)8 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)8 ErrorWarning (edu.mit.csail.sdg.alloy4.ErrorWarning)7 Func (edu.mit.csail.sdg.ast.Func)7 Field (edu.mit.csail.sdg.ast.Sig.Field)7 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)7 CompModule (edu.mit.csail.sdg.parser.CompModule)7