Search in sources :

Example 1 with ErrorAPI

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

the class SimInstance method makeAtom.

/**
 * Create a fresh atom for the given sig, then return the newly created atom.
 *
 * @throws ErrorAPI if attempting to add an atom to an abstract sig with
 *             children, or a builtin sig, or a subset sig.
 */
public SimAtom makeAtom(Sig sig) throws Err {
    if (sig.builtin)
        throw new ErrorAPI("Cannot add an atom to a builtin sig.");
    if (!(sig instanceof PrimSig))
        throw new ErrorAPI("Cannot add an atom to a subset sig.");
    PrimSig s = (PrimSig) sig;
    if (s.isAbstract != null && !s.children().isEmpty())
        throw new ErrorAPI("Cannot add an atom to an abstract parent sig.");
    String label = sig.label + "$";
    if (label.startsWith("this/"))
        label = label.substring(5);
    for (int i = 0; ; i++) {
        SimAtom atom = SimAtom.make(label + i);
        if (hasAtom(atom))
            continue;
        SimTupleset add = SimTupleset.make(SimTuple.make(atom));
        if (cacheUNIV != null)
            cacheUNIV = cacheUNIV.union(add);
        for (; s != null; s = s.parent) if (!s.builtin) {
            SimTupleset old = sfs.get(s);
            if (old == null || old.empty())
                sfs.put(s, add);
            else if (!add.in(old))
                sfs.put(s, old.union(add));
            else
                break;
        }
        return atom;
    }
}
Also used : ErrorAPI(edu.mit.csail.sdg.alloy4.ErrorAPI) PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig)

Example 2 with ErrorAPI

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

the class SimInstance method init.

/**
 * Initializes the given sig to be associated with the given unary value; should
 * only be called at the beginning.
 * <p>
 * The resulting instance may or may not satisfy all facts, and should be
 * checked for consistency.
 */
public void init(Sig sig, SimTupleset value) throws Err {
    if (value == null) {
        sfs.remove(sig);
        return;
    }
    if (value.arity() > 1)
        throw new ErrorType("Evaluator encountered an error: sig " + sig.label + " arity must not be " + value.arity());
    if (sig.builtin)
        throw new ErrorAPI("Evaluator cannot prebind the builtin sig \"" + sig.label + "\"");
    sfs.put(sig, value);
    cacheUNIV = null;
    cacheSTRING = null;
    cacheForConstants.clear();
}
Also used : ErrorAPI(edu.mit.csail.sdg.alloy4.ErrorAPI) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType)

Example 3 with ErrorAPI

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

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

the class A4SolutionWriter method writeInstance.

/**
 * If this solution is a satisfiable solution, this method will write it out in
 * XML format.
 */
static void writeInstance(A4Reporter rep, A4Solution sol, PrintWriter out, Iterable<Func> extraSkolems, Map<String, String> sources) throws Err {
    if (!sol.satisfiable())
        throw new ErrorAPI("This solution is unsatisfiable.");
    try {
        Util.encodeXMLs(out, "<alloy builddate=\"", Version.buildDate(), "\">\n\n");
        new A4SolutionWriter(rep, sol, sol.getAllReachableSigs(), sol.getBitwidth(), sol.getMaxSeq(), sol.getOriginalCommand(), sol.getOriginalFilename(), out, extraSkolems);
        if (sources != null)
            for (Map.Entry<String, String> e : sources.entrySet()) {
                Util.encodeXMLs(out, "\n<source filename=\"", e.getKey(), "\" content=\"", e.getValue(), "\"/>\n");
            }
        out.print("\n</alloy>\n");
    } catch (Throwable ex) {
        if (ex instanceof Err)
            throw (Err) ex;
        else
            throw new ErrorFatal("Error writing the solution XML file.", ex);
    }
    if (out.checkError())
        throw new ErrorFatal("Error writing the solution XML file.");
}
Also used : ErrorAPI(edu.mit.csail.sdg.alloy4.ErrorAPI) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) Err(edu.mit.csail.sdg.alloy4.Err)

Example 5 with ErrorAPI

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

the class A4TupleSet method plus.

/**
 * Construct a new tupleset as the union of this and that; this and that must be
 * come from the same solution. Note: if that==null, then the method returns
 * this A4TupleSet as-is.
 */
public A4TupleSet plus(A4TupleSet that) throws ErrorAPI {
    if (that == null)
        return this;
    if (sol != that.sol)
        throw new ErrorAPI("A4TupleSet.plus() requires 2 tuplesets from the same A4Solution.");
    if (arity() != that.arity())
        throw new ErrorAPI("A4TupleSet.plus() requires 2 tuplesets with the same arity.");
    if (this == that || tuples.size() == 0)
        return that;
    else if (that.tuples.size() == 0)
        // special short cut
        return this;
    TupleSet ts = tuples.clone();
    ts.addAll(that.tuples);
    if (tuples.size() == ts.size())
        return this;
    if (that.tuples.size() == ts.size())
        return that;
    return new A4TupleSet(ts, sol);
}
Also used : TupleSet(kodkod.instance.TupleSet) ErrorAPI(edu.mit.csail.sdg.alloy4.ErrorAPI)

Aggregations

ErrorAPI (edu.mit.csail.sdg.alloy4.ErrorAPI)9 TupleSet (kodkod.instance.TupleSet)4 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)2 ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)2 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)2 ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)2 Command (edu.mit.csail.sdg.ast.Command)2 A4Options (edu.mit.csail.sdg.translator.A4Options)2 A4Solution (edu.mit.csail.sdg.translator.A4Solution)2 Err (edu.mit.csail.sdg.alloy4.Err)1 ErrorWarning (edu.mit.csail.sdg.alloy4.ErrorWarning)1 VizGUI (edu.mit.csail.sdg.alloy4viz.VizGUI)1 Module (edu.mit.csail.sdg.ast.Module)1 Sig (edu.mit.csail.sdg.ast.Sig)1 Field (edu.mit.csail.sdg.ast.Sig.Field)1 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)1 CompModule (edu.mit.csail.sdg.parser.CompModule)1 A4Tuple (edu.mit.csail.sdg.translator.A4Tuple)1 A4TupleSet (edu.mit.csail.sdg.translator.A4TupleSet)1