use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType in project org.alloytools.alloy by AlloyTools.
the class CompModule method resolveSig.
/**
* The given Sig will now point to a nonnull Sig.
*/
private static Sig resolveSig(CompModule res, Set<Object> topo, Sig oldS) throws Err {
if (res.new2old.containsKey(oldS))
return oldS;
Sig realSig;
final Pos pos = oldS.pos;
final CompModule u = res.sig2module.get(oldS);
final String name = base(oldS);
final String fullname = (u.path.length() == 0) ? ("this/" + name) : (u.path + "/" + name);
if (!topo.add(oldS))
throw new ErrorType(pos, "Sig " + oldS + " is involved in a cyclic inheritance.");
if (oldS instanceof SubsetSig) {
List<Sig> parents = new ArrayList<Sig>();
for (Sig n : ((SubsetSig) oldS).parents) {
Sig parentAST = u.getRawSIG(n.pos, n.label);
if (parentAST == null)
throw new ErrorSyntax(n.pos, "The sig \"" + n.label + "\" cannot be found.");
parents.add(resolveSig(res, topo, parentAST));
}
realSig = new SubsetSig(fullname, parents, oldS.attributes.toArray(new Attr[0]));
} else {
Sig sup = ((PrimSig) oldS).parent;
Sig parentAST = u.getRawSIG(sup.pos, sup.label);
if (parentAST == null)
throw new ErrorSyntax(sup.pos, "The sig \"" + sup.label + "\" cannot be found.");
Sig parent = resolveSig(res, topo, parentAST);
if (!(parent instanceof PrimSig))
throw new ErrorSyntax(sup.pos, "Cannot extend the subset signature \"" + parent + "\".\n" + "A signature can only extend a toplevel signature or a subsignature.");
PrimSig p = (PrimSig) parent;
realSig = new PrimSig(fullname, p, oldS.attributes.toArray(new Attr[0]));
}
res.new2old.put(realSig, oldS);
res.sig2module.put(realSig, u);
for (CompModule m : res.allModules) {
for (Map.Entry<String, Sig> e : m.sigs.entrySet()) if (e.getValue() == oldS)
e.setValue(realSig);
for (Map.Entry<String, Sig> e : m.params.entrySet()) if (e.getValue() == oldS)
e.setValue(realSig);
}
if (res.exactSigs.remove(oldS))
res.exactSigs.add(realSig);
return realSig;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType 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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType in project org.alloytools.alloy by AlloyTools.
the class SimInstance method visit.
/**
* {@inheritDoc}
*/
@Override
public Object visit(ExprCall x) throws Err {
final Func f = x.fun;
final int n = f.count();
final Object candidate = n == 0 ? cacheForConstants.get(f) : null;
if (candidate != null)
return candidate;
final Expr body = f.getBody();
if (body.type().arity() < 0 || body.type().arity() != f.returnDecl.type().arity())
throw new ErrorType(body.span(), "Function return value not fully resolved.");
for (Func ff : current_function) if (ff == f)
throw new ErrorSyntax(x.span(), "" + f + " cannot call itself recursively!");
Env<ExprVar, Object> newenv = new Env<ExprVar, Object>();
List<SimTupleset> list = new ArrayList<SimTupleset>(x.args.size());
for (int i = 0; i < n; i++) {
SimTupleset ts = cset(x.args.get(i));
newenv.put(f.get(i), ts);
list.add(ts);
}
final SimCallback cb = callbacks.get(f);
if (cb != null) {
try {
Object answer = cb.compute(f, list);
if (answer != null) {
if (x.args.size() == 0)
cacheForConstants.put(f, answer);
return answer;
}
} catch (Exception ex) {
// if the callback failed, we can just continue with our
// original attempt to evaluate this call
}
}
Env<ExprVar, Object> oldenv = env;
env = newenv;
current_function.add(f);
Object ans = visitThis(body);
env = oldenv;
current_function.remove(current_function.size() - 1);
if (f.count() == 0)
cacheForConstants.put(f, ans);
return ans;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType in project org.alloytools.alloy by AlloyTools.
the class Type method toExpr.
/**
* Convert this type into a UNION of PRODUCT of sigs.
*
* @throws ErrorType if it does not contain exactly one arity
* @throws ErrorType if is_int is true
* @throws ErrorType if is_bool is true
*/
public Expr toExpr() throws Err {
int arity = arity();
if (is_bool || arity < 1)
throw new ErrorType("Cannot convert this type into a bounding expression.");
Expr ans = null;
for (ProductType pt : this) {
Expr pro = null;
for (int i = 0; i < arity; i++) if (pro == null)
pro = pt.types[i];
else
pro = pro.product(pt.types[i]);
if (ans == null)
ans = pro;
else
ans = ans.plus(pro);
}
return ans;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType in project org.alloytools.alloy by AlloyTools.
the class TranslateAlloyToKodkod method execute_commandFromBook.
/**
* Based on the specified "options", execute one command and return the
* resulting A4Solution object.
* <p>
* Note: it will first test whether the model fits one of the model from the
* "Software Abstractions" book; if so, it will use the exact instance that was
* in the book.
*
* @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_commandFromBook(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(), true);
} 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