Search in sources :

Example 51 with Pos

use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.

the class ExprList method span.

// ============================================================================================================//
/**
 * {@inheritDoc}
 */
@Override
public Pos span() {
    Pos p = span;
    if (p == null) {
        p = pos.merge(closingBracket);
        for (Expr a : args) p = p.merge(a.span());
        span = p;
    }
    return p;
}
Also used : Pos(edu.mit.csail.sdg.alloy4.Pos)

Example 52 with Pos

use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.

the class ExprUnary method resolve.

// ============================================================================================================//
/**
 * {@inheritDoc}
 */
@Override
public Expr resolve(Type p, Collection<ErrorWarning> warns) {
    if (errors.size() > 0)
        return this;
    ErrorWarning w1 = null, w2 = null;
    Type s = p;
    switch(op) {
        case NOT:
            s = Type.FORMULA;
            break;
        case TRANSPOSE:
        case RCLOSURE:
        case CLOSURE:
            if (warns != null && op != Op.TRANSPOSE && type.join(type).hasNoTuple())
                w1 = new ErrorWarning(pos, this + " is redundant since its domain and range are disjoint: " + sub.type.extract(2));
            s = (op != Op.TRANSPOSE) ? resolveClosure(p, sub.type) : sub.type.transpose().intersect(p).transpose();
            if (warns != null && s == EMPTY && p.hasTuple())
                w2 = new ErrorWarning(sub.span(), "The value of this expression does not contribute to the value of the parent.\nParent's relevant type = " + p + "\nThis expression's type = " + sub.type.extract(2));
            break;
        case CARDINALITY:
        case NO:
        case ONE:
        case SOME:
        case LONE:
            s = Type.removesBoolAndInt(sub.type);
            break;
        case CAST2SIGINT:
            s = Type.smallIntType();
            break;
        case CAST2INT:
            s = sub.type.intersect(SIGINT.type);
            if (warns != null && s.hasNoTuple())
                w1 = new ErrorWarning(sub.span(), "This expression should contain Int atoms.\nInstead, its possible type(s) are:\n" + sub.type.extract(1));
            break;
    }
    Expr sub = this.sub.resolve(s, warns);
    if (w1 != null)
        warns.add(w1);
    if (w2 != null)
        warns.add(w2);
    return (sub == this.sub) ? this : op.make(pos, sub, null, weight - (this.sub.weight));
}
Also used : ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) ProductType(edu.mit.csail.sdg.ast.Type.ProductType) ErrorWarning(edu.mit.csail.sdg.alloy4.ErrorWarning)

Example 53 with Pos

use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.

the class Decl method span.

/**
 * Returns a Pos object representing the entire span of this expression and all
 * its subexpressions.
 */
public Pos span() {
    Pos p = span;
    if (p == null) {
        p = expr.span().merge(disjoint).merge(disjoint2);
        for (ExprHasName n : names) p = p.merge(n.span());
        span = p;
    }
    return p;
}
Also used : Pos(edu.mit.csail.sdg.alloy4.Pos)

Example 54 with Pos

use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.

the class ExprCall method resolve.

// ============================================================================================================//
/**
 * {@inheritDoc}
 */
@Override
public Expr resolve(Type t, Collection<ErrorWarning> warns) {
    if (errors.size() > 0)
        return this;
    TempList<Expr> args = new TempList<Expr>(this.args.size());
    boolean changed = false;
    for (int i = 0; i < this.args.size(); i++) {
        Type p = fun.get(i).type;
        Expr x = this.args.get(i);
        // Use the
        Expr y = x.resolve(p, warns).typecheck_as_set();
        // the choices
        if (x != y)
            changed = true;
        args.add(y);
    // if (warns!=null && Version.experimental &&
    // !y.type.isSubtypeOf(p))
    // warns.add(new ErrorWarning(x.span(), "This argument may contain a
    // tuple not in the parameter's type.\n"
    // +"The Alloy Analyzer's analysis may be unsound\n"
    // +"if the argument has a tuple outside the parameter's type.\n"
    // +"The argument has type "+y.type+"\nbut the parameter has type
    // "+p));
    }
    return changed ? make(pos, closingBracket, fun, args.makeConst(), extraWeight) : this;
}
Also used : ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) TempList(edu.mit.csail.sdg.alloy4.ConstList.TempList)

Example 55 with Pos

use of edu.mit.csail.sdg.alloy4.Pos in project org.alloytools.alloy by AlloyTools.

the class ExprCall method span.

// ============================================================================================================//
/**
 * {@inheritDoc}
 */
@Override
public Pos span() {
    Pos p = span;
    if (p == null) {
        p = pos.merge(closingBracket);
        for (Expr a : args) p = p.merge(a.span());
        span = p;
    }
    return p;
}
Also used : Pos(edu.mit.csail.sdg.alloy4.Pos)

Aggregations

Pos (edu.mit.csail.sdg.alloy4.Pos)28 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)24 ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)16 ArrayList (java.util.ArrayList)12 Expr (edu.mit.csail.sdg.ast.Expr)10 Sig (edu.mit.csail.sdg.ast.Sig)10 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)10 Err (edu.mit.csail.sdg.alloy4.Err)9 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)8 TempList (edu.mit.csail.sdg.alloy4.ConstList.TempList)7 LinkedHashMap (java.util.LinkedHashMap)7 ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)6 Command (edu.mit.csail.sdg.ast.Command)5 ExprVar (edu.mit.csail.sdg.ast.ExprVar)5 Func (edu.mit.csail.sdg.ast.Func)5 IOException (java.io.IOException)5 Symbol (java_cup.runtime.Symbol)5 Field (edu.mit.csail.sdg.ast.Sig.Field)4 ErrorWarning (edu.mit.csail.sdg.alloy4.ErrorWarning)3 HashMap (java.util.HashMap)3