Search in sources :

Example 1 with Clause

use of edu.mit.csail.sdg.ast.Clause in project org.alloytools.alloy by AlloyTools.

the class CompModule method resolveCommand.

/**
 * Resolve a particular command.
 */
private Command resolveCommand(Command cmd, ConstList<Sig> exactSigs, Expr globalFacts) throws Err {
    Command parent = cmd.parent == null ? null : resolveCommand(cmd.parent, exactSigs, globalFacts);
    String cname = ((ExprVar) (cmd.formula)).label;
    Expr e;
    Clause declaringClause = null;
    if (cmd.check) {
        // We prefer assertion in the
        List<Object> m = getRawQS(2, cname);
        // topmost module
        if (m.size() == 0 && cname.indexOf('/') < 0)
            m = getRawNQS(this, 2, cname);
        if (m.size() > 1)
            unique(cmd.pos, cname, m);
        if (m.size() < 1)
            throw new ErrorSyntax(cmd.pos, "The assertion \"" + cname + "\" cannot be found.");
        Expr expr = (Expr) (m.get(0));
        e = expr.not();
    } else {
        // We prefer fun/pred in the
        List<Object> m = getRawQS(4, cname);
        // topmost module
        if (m.size() == 0 && cname.indexOf('/') < 0)
            m = getRawNQS(this, 4, cname);
        if (m.size() > 1)
            unique(cmd.pos, cname, m);
        if (m.size() < 1)
            throw new ErrorSyntax(cmd.pos, "The predicate/function \"" + cname + "\" cannot be found.");
        Func f = (Func) (m.get(0));
        declaringClause = f;
        e = f.getBody();
        if (!f.isPred)
            e = e.in(f.returnDecl);
        if (f.decls.size() > 0)
            e = ExprQt.Op.SOME.make(null, null, f.decls, e);
    }
    if (e == null)
        e = ExprConstant.TRUE;
    TempList<CommandScope> sc = new TempList<CommandScope>(cmd.scope.size());
    for (CommandScope et : cmd.scope) {
        Sig s = getRawSIG(et.sig.pos, et.sig.label);
        if (s == null)
            throw new ErrorSyntax(et.sig.pos, "The sig \"" + et.sig.label + "\" cannot be found.");
        sc.add(new CommandScope(null, s, et.isExact, et.startingScope, et.endingScope, et.increment));
    }
    if (cmd.nameExpr != null) {
        cmd.nameExpr.setReferenced(declaringClause);
    }
    return new Command(cmd.pos, cmd.nameExpr, cmd.label, cmd.check, cmd.overall, cmd.bitwidth, cmd.maxseq, cmd.expects, sc.makeConst(), exactSigs, globalFacts.and(e), parent);
}
Also used : ExprVar(edu.mit.csail.sdg.ast.ExprVar) Func(edu.mit.csail.sdg.ast.Func) 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) Expr(edu.mit.csail.sdg.ast.Expr) TempList(edu.mit.csail.sdg.alloy4.ConstList.TempList) Command(edu.mit.csail.sdg.ast.Command) Clause(edu.mit.csail.sdg.ast.Clause) CommandScope(edu.mit.csail.sdg.ast.CommandScope)

Example 2 with Clause

use of edu.mit.csail.sdg.ast.Clause in project org.alloytools.alloy by AlloyTools.

the class OurSyntaxWidget method doNav.

private void doNav() {
    try {
        String text = pane.getText();
        int[] sel = getCurrentWordSelection(text);
        Pos pos = Pos.toPos(text, sel[0], sel[1]);
        if (pos == null)
            return;
        String currentWord = getCurrentWord();
        if (currentWord == null)
            return;
        CompModule module = getModule();
        if (module == null)
            return;
        Expr expr = module.find(pos);
        if (expr != null) {
            Clause clause = expr.referenced();
            if (clause != null) {
                Pos where = clause.pos();
                if (where.sameFile(module.pos()))
                    select(where);
                else {
                    OurSyntaxWidget ow = parent.open(where);
                    if (ow != null) {
                        ow.select(where);
                    }
                }
            }
        }
    } catch (Exception e) {
    // Ignore, this is a best effort thingy
    }
}
Also used : CompModule(edu.mit.csail.sdg.parser.CompModule) Expr(edu.mit.csail.sdg.ast.Expr) Clause(edu.mit.csail.sdg.ast.Clause) BadLocationException(javax.swing.text.BadLocationException)

Example 3 with Clause

use of edu.mit.csail.sdg.ast.Clause in project org.alloytools.alloy by AlloyTools.

the class OurSyntaxWidget method getTooltip.

public String getTooltip(MouseEvent event) {
    try {
        int offset = pane.viewToModel(event.getPoint());
        CompModule module = getModule();
        if (module == null)
            return null;
        String text = pane.getText();
        Pos pos = Pos.toPos(text, offset, offset + 1);
        Expr expr = module.find(pos);
        if (expr instanceof ExprBad) {
            return expr.toString();
        }
        if (expr != null) {
            Clause referenced = expr.referenced();
            if (referenced != null) {
                String s = referenced.explain();
                String table = "<html><pre>" + s + "</pre></html>";
                s = table.replaceAll("\n", "<br/>");
                return s;
            } else if (expr instanceof ExprConstant) {
                String token = pos.substring(text);
                if (token != null) {
                    String match = expr.toString();
                    if (!Objects.equals(token, match))
                        return match;
                }
            }
        }
    } catch (Exception e) {
    // e.printStackTrace();
    // ignore compile errors etc.
    }
    return null;
}
Also used : ExprBad(edu.mit.csail.sdg.ast.ExprBad) CompModule(edu.mit.csail.sdg.parser.CompModule) Expr(edu.mit.csail.sdg.ast.Expr) Clause(edu.mit.csail.sdg.ast.Clause) ExprConstant(edu.mit.csail.sdg.ast.ExprConstant) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

Clause (edu.mit.csail.sdg.ast.Clause)3 Expr (edu.mit.csail.sdg.ast.Expr)3 CompModule (edu.mit.csail.sdg.parser.CompModule)2 BadLocationException (javax.swing.text.BadLocationException)2 TempList (edu.mit.csail.sdg.alloy4.ConstList.TempList)1 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)1 Command (edu.mit.csail.sdg.ast.Command)1 CommandScope (edu.mit.csail.sdg.ast.CommandScope)1 ExprBad (edu.mit.csail.sdg.ast.ExprBad)1 ExprConstant (edu.mit.csail.sdg.ast.ExprConstant)1 ExprVar (edu.mit.csail.sdg.ast.ExprVar)1 Func (edu.mit.csail.sdg.ast.Func)1 Sig (edu.mit.csail.sdg.ast.Sig)1 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)1 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)1