Search in sources :

Example 26 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 visit.

/**
 * {@inheritDoc}
 */
@Override
public Object visit(ExprCall x) throws Err {
    final Func f = x.fun;
    final Object candidate = f.count() == 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.");
    final int n = f.count();
    int maxRecursion = unrolls;
    for (Func ff : current_function) if (ff == f) {
        if (maxRecursion < 0) {
            throw new ErrorSyntax(x.span(), "" + f + " cannot call itself recursively!");
        }
        if (maxRecursion == 0) {
            Type t = f.returnDecl.type();
            if (t.is_bool)
                return Formula.FALSE;
            if (t.is_int())
                return IntConstant.constant(0);
            int i = t.arity();
            Expression ans = Expression.NONE;
            while (i > 1) {
                ans = ans.product(Expression.NONE);
                i--;
            }
            return ans;
        }
        maxRecursion--;
    }
    Env<ExprVar, Object> newenv = new Env<ExprVar, Object>();
    for (int i = 0; i < n; i++) newenv.put(f.get(i), cset(x.args.get(i)));
    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 (ans instanceof Formula)
        k2pos((Formula) ans, x);
    if (f.count() == 0)
        cacheForConstants.put(f, ans);
    return ans;
}
Also used : ExprVar(edu.mit.csail.sdg.ast.ExprVar) QuantifiedFormula(kodkod.ast.QuantifiedFormula) Formula(kodkod.ast.Formula) ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Type(edu.mit.csail.sdg.ast.Type) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Expr(edu.mit.csail.sdg.ast.Expr) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Func(edu.mit.csail.sdg.ast.Func) Expression(kodkod.ast.Expression) BinaryExpression(kodkod.ast.BinaryExpression) IntExpression(kodkod.ast.IntExpression) Env(edu.mit.csail.sdg.alloy4.Env)

Example 27 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 ExprITE method make.

/**
 * Constructs a ExprITE expression.
 *
 * @param cond - the condition formula
 * @param left - the then-clause
 * @param right - the else-clause
 */
public static Expr make(Pos pos, Expr cond, Expr left, Expr right) {
    JoinableList<Err> errs = emptyListOfErrors;
    if (cond.mult != 0)
        errs = errs.make(new ErrorSyntax(cond.span(), "Multiplicity expression not allowed here."));
    if (left.mult != 0)
        errs = errs.make(new ErrorSyntax(left.span(), "Multiplicity expression not allowed here."));
    if (right.mult != 0)
        errs = errs.make(new ErrorSyntax(right.span(), "Multiplicity expression not allowed here."));
    Type c = EMPTY;
    while (left.errors.isEmpty() && right.errors.isEmpty()) {
        Type a = left.type, b = right.type;
        c = a.unionWithCommonArity(b);
        // if (a.is_int && b.is_int) c=Type.makeInt(c);
        if (a.is_bool && b.is_bool)
            c = Type.makeBool(c);
        if (c == EMPTY) {
            // [AM]
            // if (Type.SIGINT2INT) {
            // if (a.is_int && b.intersects(SIGINT.type)) {
            // right=right.cast2int(); continue; }
            // if (b.is_int && a.intersects(SIGINT.type)) {
            // left=left.cast2int(); continue; }
            // }
            // if (Type.INT2SIGINT) {
            // if (a.is_int && b.hasArity(1)) { left=left.cast2sigint();
            // continue; }
            // if (b.is_int && a.hasArity(1)) { right=right.cast2sigint();
            // continue; }
            // }
            errs = errs.make(new ErrorType(cond.span().merge(right.span()).merge(left.span()), "The then-clause and the else-clause must match.\nThe then-clause has type: " + a + "\nand the else-clause has type: " + b));
        }
        break;
    }
    cond = cond.typecheck_as_formula();
    return new ExprITE(pos, cond, left, right, c, errs.make(cond.errors).make(left.errors).make(right.errors));
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Err(edu.mit.csail.sdg.alloy4.Err) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType)

Example 28 with ErrorType

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

the class OnfExperimenterErrorFactory method deserialize.

@Override
public ErrorMessage deserialize(ByteBuf message) {
    ErrorMessageBuilder builder = new ErrorMessageBuilder();
    builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    builder.setXid(message.readUnsignedInt());
    int type = message.readUnsignedShort();
    ErrorType errorType = ErrorType.forValue(type);
    if (errorType != null && errorType.equals(ErrorType.EXPERIMENTER)) {
        builder.setType(errorType.getIntValue());
        builder.setTypeString(errorType.getName());
    } else {
        LOG.warn("Deserializing other than {} error message with {}", ErrorType.EXPERIMENTER.getName(), this.getClass().getCanonicalName());
        builder.setType(type);
        builder.setTypeString(UNKNOWN_TYPE);
    }
    int code = message.readUnsignedShort();
    OnfExperimenterErrorCode errorCode = OnfExperimenterErrorCode.forValue(code);
    if (errorCode != null) {
        builder.setCode(errorCode.getIntValue());
        builder.setCodeString(errorCode.getName());
    } else {
        builder.setCode(code);
        builder.setCodeString(UNKNOWN_CODE);
    }
    builder.addAugmentation(ExperimenterIdError.class, new ExperimenterIdErrorBuilder().setExperimenter(new ExperimenterId(message.readUnsignedInt())).build());
    if (message.readableBytes() > 0) {
        byte[] data = new byte[message.readableBytes()];
        message.readBytes(data);
        builder.setData(data);
    }
    return builder.build();
}
Also used : ErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder) ErrorType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType) OnfExperimenterErrorCode(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.OnfExperimenterErrorCode) ExperimenterIdErrorBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdErrorBuilder) ExperimenterId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId)

Example 29 with ErrorType

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

the class ErrorMessageFactory method deserialize.

@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public ErrorMessage deserialize(ByteBuf rawMessage) {
    Objects.requireNonNull(registry);
    int startIndex = rawMessage.readerIndex();
    ErrorMessageBuilder builder = new ErrorMessageBuilder();
    builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    int type = rawMessage.readUnsignedShort();
    ErrorType errorType = ErrorType.forValue(type);
    if (ErrorType.EXPERIMENTER.equals(errorType)) {
        OFDeserializer<ErrorMessage> deserializer = registry.getDeserializer(ExperimenterDeserializerKeyFactory.createExperimenterErrorDeserializerKey(EncodeConstants.OF13_VERSION_ID, rawMessage.getUnsignedInt(rawMessage.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES)));
        rawMessage.readerIndex(startIndex);
        return deserializer.deserialize(rawMessage);
    }
    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) ErrorType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType) ErrorMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

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