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);
}
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);
}
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);
}
}
}
}
}
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();
}
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;
}
Aggregations