Search in sources :

Example 36 with ErrorSyntax

use of edu.mit.csail.sdg.alloy4.ErrorSyntax 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

ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)35 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)10 Pos (edu.mit.csail.sdg.alloy4.Pos)9 Expr (edu.mit.csail.sdg.ast.Expr)9 Sig (edu.mit.csail.sdg.ast.Sig)9 ExprVar (edu.mit.csail.sdg.ast.ExprVar)7 ArrayList (java.util.ArrayList)7 ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)6 Symbol (java_cup.runtime.Symbol)6 Err (edu.mit.csail.sdg.alloy4.Err)5 Func (edu.mit.csail.sdg.ast.Func)5 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)5 LinkedHashMap (java.util.LinkedHashMap)5 TempList (edu.mit.csail.sdg.alloy4.ConstList.TempList)4 Command (edu.mit.csail.sdg.ast.Command)4 IOException (java.io.IOException)4 ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)3 Env (edu.mit.csail.sdg.alloy4.Env)2 Decl (edu.mit.csail.sdg.ast.Decl)2 ExprHasName (edu.mit.csail.sdg.ast.ExprHasName)2