use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.
the class PosTest method assertPos.
private void assertPos(String text, int start, int end, int row, int col, int row2, int col2, String sub) {
Pos a = Pos.toPos(text, start, end);
assertEquals(row, a.y);
assertEquals(col, a.x);
assertEquals(row2, a.y2);
assertEquals(col2, a.x2);
assertEquals(sub, a.substring(text));
int[] startEnd = a.toStartEnd(text);
assertEquals(start, startEnd[0]);
// assertEquals( Math.min(end, text.length()), startEnd[1]);
}
use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.
the class SimpleGUI method do_action.
/**
* {@inheritDoc}
*/
@Override
public Object do_action(Object sender, Event e, Object arg) {
if (sender instanceof OurTree && e == Event.CLICK && arg instanceof Browsable) {
Pos p = ((Browsable) arg).pos();
if (p == Pos.UNKNOWN)
p = ((Browsable) arg).span();
text.shade(p);
}
return true;
}
use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.
the class SimpleGUI method doRefreshRun.
// ===============================================================================================================//
/**
* This method refreshes the "run" menu.
*/
private Runner doRefreshRun() {
if (wrap)
return wrapMe();
KeyStroke ac = KeyStroke.getKeyStroke(VK_E, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
try {
wrap = true;
runmenu.removeAll();
menuItem(runmenu, "Execute Latest Command", 'E', 'E', doExecuteLatest());
runmenu.add(new JSeparator());
menuItem(runmenu, "Show Latest Instance", 'L', 'L', doShowLatest(), latestInstance.length() > 0);
menuItem(runmenu, "Show Metamodel", 'M', 'M', doShowMetaModel());
if (Version.experimental)
menuItem(runmenu, "Show Parse Tree", 'P', doShowParseTree());
menuItem(runmenu, "Open Evaluator", 'V', doLoadEvaluator());
} finally {
wrap = false;
}
List<Command> cp = commands;
if (cp == null) {
try {
String source = text.get().getText();
cp = CompUtil.parseOneModule_fromString(source);
} catch (Err e) {
commands = null;
runmenu.getItem(0).setEnabled(false);
runmenu.getItem(3).setEnabled(false);
text.shade(new Pos(text.get().getFilename(), e.pos.x, e.pos.y, e.pos.x2, e.pos.y2));
if (AlloyCore.isDebug() && VerbosityPref.get() == Verbosity.FULLDEBUG)
log.logRed("Fatal Exception!" + e.dump() + "\n\n");
else
log.logRed(e.toString() + "\n\n");
return null;
} catch (Throwable e) {
commands = null;
runmenu.getItem(0).setEnabled(false);
runmenu.getItem(3).setEnabled(false);
log.logRed("Cannot parse the model.\n" + e.toString() + "\n\n");
return null;
}
commands = cp;
}
text.clearShade();
// To clear any residual error message
log.clearError();
if (cp == null) {
runmenu.getItem(0).setEnabled(false);
runmenu.getItem(3).setEnabled(false);
return null;
}
if (cp.size() == 0) {
runmenu.getItem(0).setEnabled(false);
return null;
}
if (latestCommand >= cp.size())
latestCommand = cp.size() - 1;
runmenu.remove(0);
try {
wrap = true;
for (int i = 0; i < cp.size(); i++) {
JMenuItem y = new JMenuItem(cp.get(i).toString(), null);
y.addActionListener(doRun(i));
if (i == latestCommand) {
y.setMnemonic(VK_E);
y.setAccelerator(ac);
}
runmenu.add(y, i);
}
if (cp.size() >= 2) {
JMenuItem y = new JMenuItem("Execute All", null);
y.setMnemonic(VK_A);
y.addActionListener(doRun(-1));
runmenu.add(y, 0);
runmenu.add(new JSeparator(), 1);
}
} finally {
wrap = false;
}
return null;
}
use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.
the class ExprITE method make.
/**
* Constructs a ExprITE expression.
*
* @param cond - the condition formula
* @param left - the then-clause
* @param right - the else-clause
*/
public static Expr make(Pos pos, Expr cond, Expr left, Expr right) {
JoinableList<Err> errs = emptyListOfErrors;
if (cond.mult != 0)
errs = errs.make(new ErrorSyntax(cond.span(), "Multiplicity expression not allowed here."));
if (left.mult != 0)
errs = errs.make(new ErrorSyntax(left.span(), "Multiplicity expression not allowed here."));
if (right.mult != 0)
errs = errs.make(new ErrorSyntax(right.span(), "Multiplicity expression not allowed here."));
Type c = EMPTY;
while (left.errors.isEmpty() && right.errors.isEmpty()) {
Type a = left.type, b = right.type;
c = a.unionWithCommonArity(b);
// if (a.is_int && b.is_int) c=Type.makeInt(c);
if (a.is_bool && b.is_bool)
c = Type.makeBool(c);
if (c == EMPTY) {
// [AM]
// if (Type.SIGINT2INT) {
// if (a.is_int && b.intersects(SIGINT.type)) {
// right=right.cast2int(); continue; }
// if (b.is_int && a.intersects(SIGINT.type)) {
// left=left.cast2int(); continue; }
// }
// if (Type.INT2SIGINT) {
// if (a.is_int && b.hasArity(1)) { left=left.cast2sigint();
// continue; }
// if (b.is_int && a.hasArity(1)) { right=right.cast2sigint();
// continue; }
// }
errs = errs.make(new ErrorType(cond.span().merge(right.span()).merge(left.span()), "The then-clause and the else-clause must match.\nThe then-clause has type: " + a + "\nand the else-clause has type: " + b));
}
break;
}
cond = cond.typecheck_as_formula();
return new ExprITE(pos, cond, left, right, c, errs.make(cond.errors).make(left.errors).make(right.errors));
}
use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.
the class ExprList method resolve.
// ============================================================================================================//
/**
* {@inheritDoc}
*/
@Override
public Expr resolve(Type p, Collection<ErrorWarning> warns) {
TempList<Expr> newargs = new TempList<Expr>(args.size());
boolean changed = false;
if (errors.size() > 0)
return this;
if (op == Op.AND || op == Op.OR) {
for (int i = 0; i < args.size(); i++) {
Expr x = args.get(i);
Expr y = x.resolve(Type.FORMULA, warns).typecheck_as_formula();
if (x != y)
changed = true;
newargs.add(y);
}
}
if (op == Op.DISJOINT) {
for (int i = 0; i < args.size(); i++) {
if (i == 0)
p = Type.removesBoolAndInt(args.get(i).type);
else
p = p.unionWithCommonArity(args.get(i).type);
}
for (int i = 0; i < args.size(); i++) {
Expr x = args.get(i);
Expr y = x.resolve(p, warns).typecheck_as_set();
if (x != y)
changed = true;
newargs.add(y);
}
}
if (op == Op.TOTALORDER) {
Type t = args.get(0).type.pickUnary();
Expr a = args.get(0).resolve(t, warns).typecheck_as_set();
Expr b = args.get(1).resolve(t, warns).typecheck_as_set();
Expr c = args.get(2).resolve(t.product(t), warns).typecheck_as_set();
changed = (a != args.get(0) || b != args.get(1) || c != args.get(2));
newargs.add(a).add(b).add(c);
}
return changed ? make(pos, closingBracket, op, newargs.makeConst()) : this;
}
Aggregations