use of edu.mit.csail.sdg.alloy4.Err 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.Err in project org.alloytools.alloy by AlloyTools.
the class ScopeComputer method sig2scope.
/**
* Sets the scope for a sig; returns true iff the sig's scope is changed by this
* call.
*/
private void sig2scope(Sig sig, int newValue) throws Err {
if (sig.builtin)
throw new ErrorSyntax(cmd.pos, "Cannot specify a scope for the builtin signature \"" + sig + "\"");
if (!(sig instanceof PrimSig))
throw new ErrorSyntax(cmd.pos, "Cannot specify a scope for a subset signature \"" + sig + "\"");
if (newValue < 0)
throw new ErrorSyntax(cmd.pos, "Cannot specify a negative scope for sig \"" + sig + "\"");
int old = sig2scope(sig);
if (old == newValue)
return;
if (old >= 0)
throw new ErrorSyntax(cmd.pos, "Sig \"" + sig + "\" already has a scope of " + old + ", so we cannot set it to be " + newValue);
sig2scope.put((PrimSig) sig, newValue);
rep.scope("Sig " + sig + " scope <= " + newValue + "\n");
}
use of edu.mit.csail.sdg.alloy4.Err in project org.alloytools.alloy by AlloyTools.
the class ScopeComputer method derive_scope_from_parent.
// ===========================================================================================================================//
/**
* If A is not toplevel, and we haven't been able to derive its scope yet, then
* give it its parent's scope.
*/
private boolean derive_scope_from_parent(Iterable<Sig> sigs) throws Err {
boolean changed = false;
Sig trouble = null;
for (Sig s : sigs) if (!s.builtin && !s.isTopLevel() && sig2scope(s) < 0 && (s instanceof PrimSig)) {
PrimSig p = ((PrimSig) s).parent;
int pb = sig2scope(p);
if (pb >= 0) {
sig2scope(s, pb);
changed = true;
} else {
trouble = s;
}
}
if (changed)
return true;
if (trouble == null)
return false;
throw new ErrorSyntax(cmd.pos, "You must specify a scope for sig \"" + trouble + "\"");
}
use of edu.mit.csail.sdg.alloy4.Err in project org.alloytools.alloy by AlloyTools.
the class ScopeComputer method derive_overall_scope.
// ===========================================================================================================================//
/**
* If A is toplevel, and we haven't been able to derive its scope yet, then let
* it get the "overall" scope.
*/
private boolean derive_overall_scope(Iterable<Sig> sigs) throws Err {
boolean changed = false;
final int overall = (cmd.overall < 0 && cmd.scope.size() == 0) ? 3 : cmd.overall;
for (Sig s : sigs) if (!s.builtin && s.isTopLevel() && sig2scope(s) < 0) {
if (s.isEnum != null) {
sig2scope(s, 0);
continue;
}
// enum without children should get the empty set
if (overall < 0)
throw new ErrorSyntax(cmd.pos, "You must specify a scope for sig \"" + s + "\"");
sig2scope(s, overall);
changed = true;
}
return changed;
}
use of edu.mit.csail.sdg.alloy4.Err 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