use of edu.mit.csail.sdg.alloy4.JoinableList 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));
}
Aggregations