Search in sources :

Example 6 with ErrorType

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;
}
Also used : PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig) Sig(edu.mit.csail.sdg.ast.Sig) SubsetSig(edu.mit.csail.sdg.ast.Sig.SubsetSig) SubsetSig(edu.mit.csail.sdg.ast.Sig.SubsetSig) ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Pos(edu.mit.csail.sdg.alloy4.Pos) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig)

Example 7 with ErrorType

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();
}
Also used : ErrorAPI(edu.mit.csail.sdg.alloy4.ErrorAPI) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType)

Example 8 with ErrorType

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;
}
Also used : ExprVar(edu.mit.csail.sdg.ast.ExprVar) Func(edu.mit.csail.sdg.ast.Func) ArrayList(java.util.ArrayList) Env(edu.mit.csail.sdg.alloy4.Env) IOException(java.io.IOException) ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Expr(edu.mit.csail.sdg.ast.Expr) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType)

Example 9 with ErrorType

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;
}
Also used : ErrorType(edu.mit.csail.sdg.alloy4.ErrorType)

Example 10 with ErrorType

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);
    }
}
Also used : CapacityExceededException(kodkod.engine.CapacityExceededException) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Err(edu.mit.csail.sdg.alloy4.Err) Pos(edu.mit.csail.sdg.alloy4.Pos) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException)

Aggregations

ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)18 ArrayList (java.util.ArrayList)9 Err (edu.mit.csail.sdg.alloy4.Err)6 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)6 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)6 Pos (edu.mit.csail.sdg.alloy4.Pos)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)5 TempList (edu.mit.csail.sdg.alloy4.ConstList.TempList)4 CapacityExceededException (kodkod.engine.CapacityExceededException)4 HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)4 ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)3 Expr (edu.mit.csail.sdg.ast.Expr)3 Sig (edu.mit.csail.sdg.ast.Sig)3 ExecutionException (java.util.concurrent.ExecutionException)3 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)3 VpnInstance (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance)3 ErrorMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder)3 RpcError (org.opendaylight.yangtools.yang.common.RpcError)3 Env (edu.mit.csail.sdg.alloy4.Env)2