use of edu.mit.csail.sdg.alloy4.ErrorWarning 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;
}
use of edu.mit.csail.sdg.alloy4.ErrorWarning 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));
}
use of edu.mit.csail.sdg.alloy4.ErrorWarning in project org.alloytools.alloy by AlloyTools.
the class Expr method resolve_as_set.
/**
* Converts this into a "set or relation" if possible, then resolves it if
* ambiguous.
* <p>
* On success: the return value will be a well-typed unambiguous set or relation
* expression
* <p>
* On failure: the return value's "errors" list will be nonempty
* <p>
* If we detect any type warnings, we will add the type warnings to the
* "warnings" collection.
*
* @param warnings - the list that will receive any warning we generate; can be
* null if we wish to ignore warnings
*/
public final Expr resolve_as_set(Collection<ErrorWarning> warnings) {
Expr x = typecheck_as_set();
Type t = x.type;
return x.resolve(Type.removesBoolAndInt(t), warnings).typecheck_as_set();
}
use of edu.mit.csail.sdg.alloy4.ErrorWarning 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;
}
Aggregations