Search in sources :

Example 1 with ErrorFatal

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

the class SimInstance method visit.

/**
 * {@inheritDoc}
 */
@Override
public Object visit(ExprVar x) throws Err {
    Object ans = env.get(x);
    if (ans == null)
        ans = sfs.get(x);
    if (ans == null) {
        SimAtom a = SimAtom.make(x.label);
        if (!hasAtom(a))
            throw new ErrorFatal(x.pos, "Variable \"" + x + "\" is not bound to a legal value during translation.\n");
        ans = SimTupleset.make(SimTuple.make(a));
    }
    return ans;
}
Also used : ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal)

Example 2 with ErrorFatal

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

the class A4Solution method shrink.

/**
 * Shrink the bounds for the given relation; throws an exception if the new
 * bounds is not sameAs/subsetOf the old bounds.
 */
void shrink(Relation relation, TupleSet lowerBound, TupleSet upperBound) throws Err {
    if (solved)
        throw new ErrorFatal("Cannot shrink a Kodkod relation since solve() has completed.");
    TupleSet oldL = bounds.lowerBound(relation);
    TupleSet oldU = bounds.upperBound(relation);
    if (oldU.containsAll(upperBound) && upperBound.containsAll(lowerBound) && lowerBound.containsAll(oldL)) {
        bounds.bound(relation, lowerBound, upperBound);
    } else {
        throw new ErrorAPI("Inconsistent bounds shrinking on relation: " + relation);
    }
}
Also used : TupleSet(kodkod.instance.TupleSet) ErrorAPI(edu.mit.csail.sdg.alloy4.ErrorAPI) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal)

Example 3 with ErrorFatal

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

the class A4Solution method k2pos.

/**
 * Associates the Kodkod formula to a particular Alloy Expr (if the Kodkod
 * formula is not already associated with an Alloy Expr or Alloy Pos)
 */
Formula k2pos(Formula formula, Expr expr) throws Err {
    if (solved)
        throw new ErrorFatal("Cannot alter the k->pos mapping since solve() has completed.");
    if (formula == null || expr == null || k2pos.containsKey(formula))
        return formula;
    k2pos.put(formula, expr);
    if (formula instanceof BinaryFormula) {
        BinaryFormula b = (BinaryFormula) formula;
        if (b.op() == FormulaOperator.AND) {
            k2pos(b.left(), expr);
            k2pos(b.right(), expr);
        }
    }
    return formula;
}
Also used : ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) BinaryFormula(kodkod.ast.BinaryFormula)

Example 4 with ErrorFatal

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

the class A4Solution method addSkolem.

/**
 * Add a new skolem to this solution and associate it with the given expression.
 * <br>
 * The expression must contain only constant Relations or Relations that are
 * already bound in this solution.
 */
private ExprVar addSkolem(String label, Type type, Expression expr) throws Err {
    if (solved)
        throw new ErrorFatal("Cannot add an additional skolem since solve() has completed.");
    int a = type.arity();
    if (a < 1)
        throw new ErrorFatal("Skolem " + label + " must be associated with a relational value.");
    if (a != expr.arity())
        throw new ErrorFatal("Skolem " + label + " must be associated with an " + a + "-ary relational value.");
    ExprVar v = ExprVar.make(Pos.UNKNOWN, label, type);
    a2k.put(v, expr);
    skolems.add(v);
    return v;
}
Also used : ExprVar(edu.mit.csail.sdg.ast.ExprVar) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal)

Example 5 with ErrorFatal

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

the class A4Solution method k2pos.

/**
 * Associates the Kodkod formula to a particular Alloy Pos (if the Kodkod
 * formula is not already associated with an Alloy Expr or Alloy Pos)
 */
Formula k2pos(Formula formula, Pos pos) throws Err {
    if (solved)
        throw new ErrorFatal("Cannot alter the k->pos mapping since solve() has completed.");
    if (formula == null || pos == null || pos == Pos.UNKNOWN || k2pos.containsKey(formula))
        return formula;
    k2pos.put(formula, pos);
    if (formula instanceof BinaryFormula) {
        BinaryFormula b = (BinaryFormula) formula;
        if (b.op() == FormulaOperator.AND) {
            k2pos(b.left(), pos);
            k2pos(b.right(), pos);
        }
    }
    return formula;
}
Also used : ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) BinaryFormula(kodkod.ast.BinaryFormula)

Aggregations

ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)29 Err (edu.mit.csail.sdg.alloy4.Err)8 Expr (edu.mit.csail.sdg.ast.Expr)6 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)6 Pos (edu.mit.csail.sdg.alloy4.Pos)4 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)3 ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)3 ExprVar (edu.mit.csail.sdg.ast.ExprVar)3 Sig (edu.mit.csail.sdg.ast.Sig)3 IOException (java.io.IOException)3 LinkedHashSet (java.util.LinkedHashSet)3 BinaryExpression (kodkod.ast.BinaryExpression)3 CapacityExceededException (kodkod.engine.CapacityExceededException)3 HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)3 ErrorAPI (edu.mit.csail.sdg.alloy4.ErrorAPI)2 Field (edu.mit.csail.sdg.ast.Sig.Field)2 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)2 A4Tuple (edu.mit.csail.sdg.translator.A4Tuple)2