Search in sources :

Example 6 with JoinableList

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));
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Err(edu.mit.csail.sdg.alloy4.Err) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType)

Aggregations

Err (edu.mit.csail.sdg.alloy4.Err)6 TempList (edu.mit.csail.sdg.alloy4.ConstList.TempList)3 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)3 ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)3 ErrorWarning (edu.mit.csail.sdg.alloy4.ErrorWarning)2 Decl (edu.mit.csail.sdg.ast.Decl)2 Expr (edu.mit.csail.sdg.ast.Expr)2 ExprHasName (edu.mit.csail.sdg.ast.ExprHasName)2 Func (edu.mit.csail.sdg.ast.Func)2 JoinableList (edu.mit.csail.sdg.alloy4.JoinableList)1 ExprVar (edu.mit.csail.sdg.ast.ExprVar)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 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1