use of edu.mit.csail.sdg.alloy4.ErrorType in project org.alloytools.alloy by AlloyTools.
the class Macro method instantiate.
/**
* Instantiate it.
*
* @param warnings - the list that will receive any warning we generate; can be
* null if we wish to ignore warnings
*/
Expr instantiate(Context cx, List<ErrorWarning> warnings) throws Err {
if (cx.unrolls <= 0) {
Pos p = span();
return new ExprBad(p, toString(), new ErrorType(p, "Macro substitution too deep; possibly indicating an infinite recursion."));
}
if (params.size() != args.size())
return this;
Context cx2 = new Context(realModule, warnings, cx.unrolls - 1);
for (int n = params.size(), i = 0; i < n; i++) {
Expr tmp = args.get(i);
if (!(tmp instanceof Macro))
tmp = tmp.resolve(tmp.type(), warnings);
cx2.put(params.get(i).label, tmp);
}
return cx2.check(body);
}
use of edu.mit.csail.sdg.alloy4.ErrorType in project org.alloytools.alloy by AlloyTools.
the class SimInstance method init.
/**
* Initializes the given var 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(ExprVar var, SimTupleset value) throws Err {
if (value == null) {
sfs.remove(var);
return;
}
if (!value.empty() && value.arity() != var.type().arity())
throw new ErrorType("Evaluator encountered an error: skolem " + var.label + " arity must not be " + value.arity());
sfs.put(var, value);
cacheUNIV = null;
cacheSTRING = null;
cacheForConstants.clear();
}
use of edu.mit.csail.sdg.alloy4.ErrorType 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.ErrorType in project org.alloytools.alloy by AlloyTools.
the class CompModule method rejectNameClash.
// ============================================================================================================================//
private static void rejectNameClash(final List<CompModule> modules) throws Err {
// The Alloy language forbids two overlapping sigs from having fields
// with the same name.
// In other words: if 2 fields have the same name, then their type's
// first column must not intersect.
final Map<String, List<Field>> fieldname2fields = new LinkedHashMap<String, List<Field>>();
for (CompModule m : modules) {
for (Sig sig : m.sigs.values()) {
for (Field field : sig.getFields()) {
List<Field> peers = fieldname2fields.get(field.label);
if (peers == null) {
peers = new ArrayList<Field>();
fieldname2fields.put(field.label, peers);
}
for (Field field2 : peers) if (field.type().firstColumnOverlaps(field2.type()))
throw new ErrorType(field.pos, "Two overlapping signatures cannot have\n" + "two fields with the same name \"" + field.label + "\":\n\n1) one is in sig \"" + field.sig + "\"\n" + field.pos + "\n\n2) the other is in sig \"" + field2.sig + "\"\n" + field2.pos);
peers.add(field);
}
}
}
}
use of edu.mit.csail.sdg.alloy4.ErrorType in project org.alloytools.alloy by AlloyTools.
the class TranslateAlloyToKodkod method execute_command.
/**
* Based on the specified "options", execute one command and return the
* resulting A4Solution object.
*
* @param rep - if nonnull, we'll send compilation diagnostic messages to it
* @param sigs - the list of sigs; this list must be complete
* @param cmd - the Command to execute
* @param opt - the set of options guiding the execution of the command
* @return null if the user chose "save to FILE" as the SAT solver, and nonnull
* if the solver finishes the entire solving and is either satisfiable
* or unsatisfiable.
* <p>
* If the return value X is satisfiable, you can call X.next() to get
* the next satisfying solution X2; and you can call X2.next() to get
* the next satisfying solution X3... until you get an unsatisfying
* solution.
*/
public static A4Solution execute_command(A4Reporter rep, Iterable<Sig> sigs, Command cmd, A4Options opt) throws Err {
if (rep == null)
rep = A4Reporter.NOP;
TranslateAlloyToKodkod tr = null;
try {
if (cmd.parent != null || !cmd.getGrowableSigs().isEmpty())
return execute_greedyCommand(rep, sigs, cmd, opt);
tr = new TranslateAlloyToKodkod(rep, opt, sigs, cmd);
tr.makeFacts(cmd.formula);
return tr.frame.solve(rep, cmd, new Simplifier(), false);
} catch (UnsatisfiedLinkError ex) {
throw new ErrorFatal("The required JNI library cannot be found: " + ex.toString().trim(), ex);
} catch (CapacityExceededException ex) {
throw rethrow(ex);
} catch (HigherOrderDeclException ex) {
Pos p = tr != null ? tr.frame.kv2typepos(ex.decl().variable()).b : Pos.UNKNOWN;
throw new ErrorType(p, "Analysis cannot be performed since it requires higher-order quantification that could not be skolemized.");
} catch (Throwable ex) {
if (ex instanceof Err)
throw (Err) ex;
else
throw new ErrorFatal("Unknown exception occurred: " + ex, ex);
}
}
Aggregations