Search in sources :

Example 6 with ErrorAPI

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

the class ScopeComputer method setMaxSeq.

/**
 * Modifies the maximum sequence length.
 */
private void setMaxSeq(Pos pos, int newMaxSeq) throws ErrorAPI, ErrorSyntax {
    if (newMaxSeq > max())
        throw new ErrorSyntax(pos, "With integer bitwidth of " + bitwidth + ", you cannot have sequence length longer than " + max());
    if (newMaxSeq < 0)
        // throw new ErrorSyntax(pos, "The maximum sequence
        newMaxSeq = 0;
    // length cannot be negative.");
    maxseq = newMaxSeq;
    sig2scope.put(SEQIDX, maxseq);
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax)

Example 7 with ErrorAPI

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

the class ScopeComputer method setBitwidth.

/**
 * Modifies the integer bitwidth of this solution's model (and sets the max
 * sequence length to 0)
 */
private void setBitwidth(Pos pos, int newBitwidth) throws ErrorAPI, ErrorSyntax {
    if (newBitwidth < 0)
        throw new ErrorSyntax(pos, "Cannot specify a bitwidth less than 0");
    if (newBitwidth > 30)
        throw new ErrorSyntax(pos, "Cannot specify a bitwidth greater than 30");
    bitwidth = newBitwidth;
    maxseq = 0;
    sig2scope.put(SIGINT, bitwidth < 1 ? 0 : 1 << bitwidth);
    sig2scope.put(SEQIDX, 0);
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax)

Example 8 with ErrorAPI

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

the class ExampleUsingTheCompiler method main.

/*
     * Execute every command in every file. This method parses every file, then
     * execute every command. If there are syntax or type errors, it may throw a
     * ErrorSyntax or ErrorType or ErrorAPI or ErrorFatal exception. You should
     * catch them and display them, and they may contain filename/line/column
     * information.
     */
public static void main(String[] args) throws Err {
    // The visualizer (We will initialize it to nonnull when we visualize an
    // Alloy solution)
    VizGUI viz = null;
    // Alloy4 sends diagnostic messages and progress reports to the
    // A4Reporter.
    // By default, the A4Reporter ignores all these events (but you can
    // extend the A4Reporter to display the event for the user)
    A4Reporter rep = new A4Reporter() {

        // For example, here we choose to display each "warning" by printing
        // it to System.out
        @Override
        public void warning(ErrorWarning msg) {
            System.out.print("Relevance Warning:\n" + (msg.toString().trim()) + "\n\n");
            System.out.flush();
        }
    };
    for (String filename : args) {
        // Parse+typecheck the model
        System.out.println("=========== Parsing+Typechecking " + filename + " =============");
        Module world = CompUtil.parseEverything_fromFile(rep, null, filename);
        // Choose some default options for how you want to execute the
        // commands
        A4Options options = new A4Options();
        options.solver = A4Options.SatSolver.SAT4J;
        for (Command command : world.getAllCommands()) {
            // Execute the command
            System.out.println("============ Command " + command + ": ============");
            A4Solution ans = TranslateAlloyToKodkod.execute_command(rep, world.getAllReachableSigs(), command, options);
            // Print the outcome
            System.out.println(ans);
            // If satisfiable...
            if (ans.satisfiable()) {
                // You can query "ans" to find out the values of each set or
                // type.
                // This can be useful for debugging.
                // 
                // You can also write the outcome to an XML file
                ans.writeXML("alloy_example_output.xml");
                // You can then visualize the XML file by calling this:
                if (viz == null) {
                    viz = new VizGUI(false, "alloy_example_output.xml", null);
                } else {
                    viz.loadXML("alloy_example_output.xml", true);
                }
            }
        }
    }
}
Also used : VizGUI(edu.mit.csail.sdg.alloy4viz.VizGUI) Command(edu.mit.csail.sdg.ast.Command) A4Reporter(edu.mit.csail.sdg.alloy4.A4Reporter) A4Options(edu.mit.csail.sdg.translator.A4Options) ErrorWarning(edu.mit.csail.sdg.alloy4.ErrorWarning) Module(edu.mit.csail.sdg.ast.Module) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Example 9 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 field 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(Field field, SimTupleset value) throws Err {
    if (value == null) {
        sfs.remove(field);
        return;
    }
    if (!value.empty() && value.arity() != field.type().arity())
        throw new ErrorType("Evaluator encountered an error: field " + field.label + " arity must not be " + value.arity());
    if (field.defined)
        throw new ErrorAPI("Evaluator cannot prebind the value of a defined field.");
    sfs.put(field, value);
    cacheUNIV = null;
    cacheSTRING = null;
    cacheForConstants.clear();
}
Also used : ErrorAPI(edu.mit.csail.sdg.alloy4.ErrorAPI) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType)

Example 10 with ErrorAPI

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

the class A4TupleSet method minus.

/**
 * Construct a new tupleset as the subtraction 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 minus(A4TupleSet that) throws ErrorAPI {
    if (that == null)
        return this;
    if (sol != that.sol)
        throw new ErrorAPI("A4TupleSet.minus() requires 2 tuplesets from the same A4Solution.");
    if (arity() != that.arity())
        throw new ErrorAPI("A4TupleSet.minus() requires 2 tuplesets with the same arity.");
    if (tuples.size() == 0 || that.tuples.size() == 0)
        // special short cut
        return this;
    TupleSet ts = tuples.clone();
    ts.removeAll(that.tuples);
    if (tuples.size() != ts.size())
        return new A4TupleSet(ts, sol);
    else
        return this;
}
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