Search in sources :

Example 1 with ErrorSyntax

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

Example 2 with ErrorSyntax

use of edu.mit.csail.sdg.alloy4.ErrorSyntax 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);
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Command(edu.mit.csail.sdg.ast.Command)

Example 3 with ErrorSyntax

use of edu.mit.csail.sdg.alloy4.ErrorSyntax in project org.alloytools.alloy by AlloyTools.

the class CompModule method parseOneExpressionFromString.

/**
 * Parse one expression by starting fromt this module as the root module.
 */
@Override
public Expr parseOneExpressionFromString(String input) throws Err, FileNotFoundException, IOException {
    Map<String, String> fc = new LinkedHashMap<String, String>();
    // We prepend the line "run{"
    fc.put("", "run {\n" + input + "}");
    CompModule m = CompUtil.parse(new ArrayList<Object>(), null, fc, null, -1, "", "", 1);
    if (m.funcs.size() == 0)
        throw new ErrorSyntax("The input does not correspond to an Alloy expression.");
    Expr body = m.funcs.values().iterator().next().get(0).getBody();
    Context cx = new Context(this, null);
    body = cx.check(body);
    body = body.resolve(body.type(), null);
    if (body.errors.size() > 0)
        throw body.errors.pick();
    else
        return body;
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Expr(edu.mit.csail.sdg.ast.Expr) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with ErrorSyntax

use of edu.mit.csail.sdg.alloy4.ErrorSyntax 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 5 with ErrorSyntax

use of edu.mit.csail.sdg.alloy4.ErrorSyntax 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);
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Command(edu.mit.csail.sdg.ast.Command) ArrayList(java.util.ArrayList)

Aggregations

ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)35 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)10 Pos (edu.mit.csail.sdg.alloy4.Pos)9 Expr (edu.mit.csail.sdg.ast.Expr)9 Sig (edu.mit.csail.sdg.ast.Sig)9 ExprVar (edu.mit.csail.sdg.ast.ExprVar)7 ArrayList (java.util.ArrayList)7 ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)6 Symbol (java_cup.runtime.Symbol)6 Err (edu.mit.csail.sdg.alloy4.Err)5 Func (edu.mit.csail.sdg.ast.Func)5 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)5 LinkedHashMap (java.util.LinkedHashMap)5 TempList (edu.mit.csail.sdg.alloy4.ConstList.TempList)4 Command (edu.mit.csail.sdg.ast.Command)4 IOException (java.io.IOException)4 ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)3 Env (edu.mit.csail.sdg.alloy4.Env)2 Decl (edu.mit.csail.sdg.ast.Decl)2 ExprHasName (edu.mit.csail.sdg.ast.ExprHasName)2