Search in sources :

Example 11 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 ExprCall method make.

// ============================================================================================================//
/**
 * Constructs an ExprCall node with the given predicate/function "fun" and the
 * list of arguments "args".
 */
public static Expr make(Pos pos, Pos closingBracket, Func fun, List<Expr> args, long extraPenalty) {
    if (extraPenalty < 0)
        extraPenalty = 0;
    if (args == null)
        args = ConstList.make();
    long weight = extraPenalty;
    boolean ambiguous = false;
    JoinableList<Err> errs = emptyListOfErrors;
    TempList<Expr> newargs = new TempList<Expr>(args.size());
    if (args.size() != fun.count()) {
        errs = errs.make(new ErrorSyntax(pos, "" + fun + " has " + fun.count() + " parameters but is called with " + args.size() + " arguments."));
    }
    for (int i = 0; i < args.size(); i++) {
        final int a = (i < fun.count()) ? fun.get(i).type.arity() : 0;
        final Expr x = args.get(i).typecheck_as_set();
        ambiguous = ambiguous || x.ambiguous;
        errs = errs.make(x.errors);
        weight = weight + x.weight;
        if (x.mult != 0)
            errs = errs.make(new ErrorSyntax(x.span(), "Multiplicity expression not allowed here."));
        if (a > 0 && x.errors.isEmpty() && !x.type.hasArity(a))
            errs = errs.make(new ErrorType(x.span(), "This should have arity " + a + " but instead its possible type(s) are " + x.type));
        newargs.add(x);
    }
    Type t = Type.FORMULA;
    if (!fun.isPred && errs.size() == 0) {
        final Type tt = fun.returnDecl.type;
        try {
            // This provides a limited form of polymorphic function,
            // by using actual arguments at each call site to derive a
            // tighter bound on the return value.
            DeduceType d = new DeduceType();
            for (int i = 0; i < args.size(); i++) {
                ExprVar param = fun.get(i);
                d.env.put(param, newargs.get(i).type.extract(param.type.arity()));
            }
            t = fun.returnDecl.accept(d);
            if (t == null || t.is_int() || t.is_bool || t.arity() != tt.arity())
                // Just in case an error occurred...
                t = tt;
        } catch (Throwable ex) {
            // Just in case an error occurred...
            t = tt;
        }
    }
    return new ExprCall(pos, closingBracket, ambiguous, t, fun, newargs.makeConst(), extraPenalty, weight, errs);
}
Also used : Err(edu.mit.csail.sdg.alloy4.Err) ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) TempList(edu.mit.csail.sdg.alloy4.ConstList.TempList) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType)

Example 12 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 ExprChoice method make.

// ============================================================================================================//
/**
 * Construct an ExprChoice node.
 */
public static Expr make(boolean ignoreIntFuns, Pos pos, ConstList<Expr> choices, ConstList<String> reasons) {
    if (choices.size() == 0)
        return new ExprBad(pos, "", new ErrorType(pos, "This expression failed to be typechecked."));
    if (choices.size() == 1 && choices.get(0).errors.isEmpty())
        // Shortcut
        return choices.get(0);
    if (ignoreIntFuns) {
        int n = choices.size();
        TempList<Expr> ch = new TempList<Expr>(n);
        TempList<String> rs = new TempList<String>(n);
        for (int i = 0; i < n; i++) {
            Expr e = choices.get(i);
            if (!((e instanceof ExprCall) && e.toString().startsWith("integer/"))) {
                ch.add(e);
                rs.add(reasons.get(i));
            }
        }
        return make(false, pos, ch.makeConst(), rs.makeConst());
    }
    Type type = EMPTY;
    boolean first = true;
    long weight = 0;
    for (Expr x : choices) {
        type = x.type.merge(type);
        if (first || weight > x.weight)
            if (x.type != EMPTY) {
                weight = x.weight;
                first = false;
            }
    }
    return new ExprChoice(pos, choices, reasons, type, weight);
}
Also used : ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) TempList(edu.mit.csail.sdg.alloy4.ConstList.TempList)

Example 13 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 ExprChoice method resolveHelper.

// ============================================================================================================//
/**
 * Resolve the list of choices, or return an ExprBad object containing the list
 * of unresolvable ambiguities.
 */
private Expr resolveHelper(boolean firstPass, final Type t, List<Expr> choices, List<String> reasons, Collection<ErrorWarning> warns) {
    List<Expr> ch = new ArrayList<Expr>(choices.size());
    List<String> re = new ArrayList<String>(choices.size());
    // We first prefer exact matches
    for (int i = 0; i < choices.size(); i++) {
        Type tt = choices.get(i).type;
        if (/* [AM](t.is_int() && tt.is_int()) || */
        (t.is_bool && tt.is_bool) || t.intersects(tt)) {
            ch.add(choices.get(i));
            re.add(reasons.get(i));
        }
    }
    // If none, we try any legal matches
    if (ch.size() == 0) {
        for (int i = 0; i < choices.size(); i++) if (choices.get(i).type.hasCommonArity(t)) {
            ch.add(choices.get(i));
            re.add(reasons.get(i));
        }
    }
    // If too many, then keep the choices with the smallest weight
    if (ch.size() > 1) {
        List<Expr> ch2 = new ArrayList<Expr>(ch.size());
        List<String> re2 = new ArrayList<String>(ch.size());
        long w = 0;
        for (int i = 0; i < ch.size(); i++) {
            Expr c = ch.get(i);
            String r = re.get(i);
            if (ch2.size() > 0 && c.weight > w)
                continue;
            else if (ch2.size() == 0 || c.weight < w) {
                ch2.clear();
                re2.clear();
                w = c.weight;
            }
            ch2.add(c);
            re2.add(r);
        }
        ch = ch2;
        re = re2;
        // resolve them all and try again
        if (firstPass && ch.size() > 1) {
            ch2 = new ArrayList<Expr>(ch.size());
            for (Expr c : ch) ch2.add(c.resolve(t, null));
            return resolveHelper(false, t, ch2, re, warns);
        }
    }
    // If we are down to exactly 1 match, return it
    if (ch.size() == 1)
        return ch.get(0).resolve(t, warns);
    // emptyset-of-the-same-arity, then just return emptyset
    none: while (ch.size() > 1) {
        int arity = -1;
        for (Expr c : ch) {
            if (c.type.is_bool || c.type.is_int() || c.type.hasTuple())
                break none;
            int a = c.type.arity();
            if (a < 1)
                break none;
            if (arity < 0)
                arity = a;
            else if (arity != a)
                break none;
        }
        Expr ans = Sig.NONE;
        while (arity > 1) {
            ans = ans.product(Sig.NONE);
            arity--;
        }
        return ExprUnary.Op.NOOP.make(span(), ans);
    }
    // Otherwise, complain!
    String txt;
    if (ch.size() > 1) {
        txt = "\nThis name is ambiguous due to multiple matches:";
    } else {
        txt = "\nThis name cannot be resolved; its relevant type does not intersect with any of the following candidates:";
        re = reasons;
    }
    StringBuilder msg = new StringBuilder(txt);
    for (String r : re) msg.append('\n').append(r);
    return new ExprBad(pos, toString(), new ErrorType(pos, msg.toString()));
}
Also used : ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) ArrayList(java.util.ArrayList)

Example 14 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 ExprList method make.

/**
 * Generates a call to a builtin predicate
 */
public static ExprList make(Pos pos, Pos closingBracket, Op op, List<? extends Expr> args) {
    boolean ambiguous = false;
    JoinableList<Err> errs = emptyListOfErrors;
    TempList<Expr> newargs = new TempList<Expr>(args.size());
    long weight = 0;
    Type commonArity = null;
    for (int i = 0; i < args.size(); i++) {
        Expr a = (op == Op.AND || op == Op.OR) ? args.get(i).typecheck_as_formula() : args.get(i).typecheck_as_set();
        ambiguous = ambiguous || a.ambiguous;
        weight = weight + a.weight;
        if (a.mult != 0)
            errs = errs.make(new ErrorSyntax(a.span(), "Multiplicity expression not allowed here."));
        if (!a.errors.isEmpty())
            errs = errs.make(a.errors);
        else if (commonArity == null)
            commonArity = a.type;
        else
            commonArity = commonArity.pickCommonArity(a.type);
        if (op == Op.AND)
            addAND(newargs, a);
        else if (op == Op.OR)
            addOR(newargs, a);
        else
            newargs.add(a);
    }
    if (op == Op.TOTALORDER) {
        if (newargs.size() != 3) {
            errs = errs.make(new ErrorSyntax(pos, "The builtin pred/totalOrder[] predicate must be called with exactly three arguments."));
        } else if (errs.isEmpty()) {
            if (!newargs.get(0).type.hasArity(1))
                errs = errs.make(new ErrorType(pos, "The first argument to pred/totalOrder must be unary."));
            if (!newargs.get(1).type.hasArity(1))
                errs = errs.make(new ErrorType(pos, "The second argument to pred/totalOrder must be unary."));
            if (!newargs.get(2).type.hasArity(2))
                errs = errs.make(new ErrorType(pos, "The third argument to pred/totalOrder must be binary."));
        }
    }
    if (op == Op.DISJOINT) {
        if (newargs.size() < 2)
            errs = errs.make(new ErrorSyntax(pos, "The builtin disjoint[] predicate must be called with at least two arguments."));
        if (commonArity == EMPTY)
            errs = errs.make(new ErrorType(pos, "The builtin predicate disjoint[] cannot be used among expressions of different arities."));
    }
    return new ExprList(pos, closingBracket, op, ambiguous, newargs.makeConst(), weight, errs);
}
Also used : ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Err(edu.mit.csail.sdg.alloy4.Err) TempList(edu.mit.csail.sdg.alloy4.ConstList.TempList) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType)

Example 15 with ErrorType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType in project openflowplugin by opendaylight.

the class OF10ErrorMessageFactory method deserialize.

@Override
public ErrorMessage deserialize(ByteBuf rawMessage) {
    ErrorMessageBuilder builder = new ErrorMessageBuilder();
    builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    int type = rawMessage.readUnsignedShort();
    ErrorTypeV10 errorType = ErrorTypeV10.forValue(type);
    decodeType(builder, errorType, type);
    decodeCode(rawMessage, builder, errorType);
    int remainingBytes = rawMessage.readableBytes();
    if (remainingBytes > 0) {
        byte[] data = new byte[remainingBytes];
        rawMessage.readBytes(data);
        builder.setData(data);
    }
    return builder.build();
}
Also used : ErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder) ErrorTypeV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorTypeV10)

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