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);
}
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
}
}
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;
}
Aggregations