Search in sources :

Example 21 with Type

use of com.acgist.snail.pojo.bean.M3u8.Type in project cel-java by projectnessie.

the class Types method substitute.

/**
 * substitute replaces all direct and indirect occurrences of bound type parameters. Unbound type
 * parameters are replaced by DYN if typeParamToDyn is true.
 */
static Type substitute(Mapping m, Type t, boolean typeParamToDyn) {
    Type tSub = m.find(t);
    if (tSub != null) {
        return substitute(m, tSub, typeParamToDyn);
    }
    Kind kind = kindOf(t);
    if (typeParamToDyn && kind == Kind.kindTypeParam) {
        return Decls.Dyn;
    }
    switch(kind) {
        case kindAbstract:
            // TODO: implement!
            AbstractType at = t.getAbstractType();
            List<Type> params = new ArrayList<>(at.getParameterTypesCount());
            for (Type p : at.getParameterTypesList()) {
                params.add(substitute(m, p, typeParamToDyn));
            }
            return Decls.newAbstractType(at.getName(), params);
        case kindFunction:
            FunctionType fn = t.getFunction();
            Type rt = substitute(m, fn.getResultType(), typeParamToDyn);
            List<Type> args = new ArrayList<>(fn.getArgTypesCount());
            for (Type a : fn.getArgTypesList()) {
                args.add(substitute(m, a, typeParamToDyn));
            }
            return Decls.newFunctionType(rt, args);
        case kindList:
            return Decls.newListType(substitute(m, t.getListType().getElemType(), typeParamToDyn));
        case kindMap:
            MapType mt = t.getMapType();
            return Decls.newMapType(substitute(m, mt.getKeyType(), typeParamToDyn), substitute(m, mt.getValueType(), typeParamToDyn));
        case kindType:
            if (t.getType() != Type.getDefaultInstance()) {
                return Decls.newTypeType(substitute(m, t.getType(), typeParamToDyn));
            }
            return t;
        default:
            return t;
    }
}
Also used : AbstractType(com.google.api.expr.v1alpha1.Type.AbstractType) PrimitiveType(com.google.api.expr.v1alpha1.Type.PrimitiveType) Type(com.google.api.expr.v1alpha1.Type) WellKnownType(com.google.api.expr.v1alpha1.Type.WellKnownType) FunctionType(com.google.api.expr.v1alpha1.Type.FunctionType) MapType(com.google.api.expr.v1alpha1.Type.MapType) FunctionType(com.google.api.expr.v1alpha1.Type.FunctionType) AbstractType(com.google.api.expr.v1alpha1.Type.AbstractType) ArrayList(java.util.ArrayList) MapType(com.google.api.expr.v1alpha1.Type.MapType)

Example 22 with Type

use of com.acgist.snail.pojo.bean.M3u8.Type in project cel-java by projectnessie.

the class AttributesTest method benchmarkResolverFieldQualifier.

@Test
void benchmarkResolverFieldQualifier() {
    TestAllTypes msg = TestAllTypes.newBuilder().setSingleNestedMessage(NestedMessage.newBuilder().setBb(123)).build();
    TypeRegistry reg = newRegistry(msg);
    AttributeFactory attrs = newAttributeFactory(Container.defaultContainer, reg, reg);
    Activation vars = newActivation(mapOf("msg", msg));
    NamespacedAttribute attr = attrs.absoluteAttribute(1, "msg");
    Type opType = reg.findType("google.api.expr.test.v1.proto3.TestAllTypes");
    assertThat(opType).isNotNull();
    Type fieldType = reg.findType("google.api.expr.test.v1.proto3.TestAllTypes.NestedMessage");
    assertThat(fieldType).isNotNull();
    attr.addQualifier(makeQualifier(attrs, opType.getType(), 2, "single_nested_message"));
    attr.addQualifier(makeQualifier(attrs, fieldType.getType(), 3, "bb"));
// Note: migrated to JMH
}
Also used : IntType(org.projectnessie.cel.common.types.IntT.IntType) Type(com.google.api.expr.v1alpha1.Type) NamespacedAttribute(org.projectnessie.cel.interpreter.AttributeFactory.NamespacedAttribute) AttributePattern.newPartialAttributeFactory(org.projectnessie.cel.interpreter.AttributePattern.newPartialAttributeFactory) AttributeFactory.newAttributeFactory(org.projectnessie.cel.interpreter.AttributeFactory.newAttributeFactory) Activation.emptyActivation(org.projectnessie.cel.interpreter.Activation.emptyActivation) Activation.newPartialActivation(org.projectnessie.cel.interpreter.Activation.newPartialActivation) Activation.newActivation(org.projectnessie.cel.interpreter.Activation.newActivation) TestAllTypes(com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes) TypeRegistry(org.projectnessie.cel.common.types.ref.TypeRegistry) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with Type

use of com.acgist.snail.pojo.bean.M3u8.Type in project cel-java by projectnessie.

the class FieldDescriptionTest method fieldDescription.

@Test
void fieldDescription() {
    Db pbdb = newDb();
    NestedTestAllTypes msg = NestedTestAllTypes.getDefaultInstance();
    String msgName = msg.getDescriptorForType().getFullName();
    pbdb.registerMessage(msg);
    PbTypeDescription td = pbdb.describeType(msgName);
    assertThat(td).isNotNull();
    FieldDescription fd = td.fieldByName("payload");
    assertThat(fd).isNotNull();
    assertThat(fd).extracting(FieldDescription::name).isEqualTo("payload");
    assertThat(fd).extracting(FieldDescription::isOneof).isEqualTo(false);
    assertThat(fd).extracting(FieldDescription::isMap).isEqualTo(false);
    assertThat(fd).extracting(FieldDescription::isMessage).isEqualTo(true);
    assertThat(fd).extracting(FieldDescription::isEnum).isEqualTo(false);
    assertThat(fd).extracting(FieldDescription::isList).isEqualTo(false);
    // Access the field by its Go struct name and check to see that it's index
    // matches the one determined by the TypeDescription utils.
    Type got = fd.checkedType();
    Type wanted = Type.newBuilder().setMessageType("google.api.expr.test.v1.proto3.TestAllTypes").build();
    assertThat(got).isEqualTo(wanted);
}
Also used : Type(com.google.api.expr.v1alpha1.Type) Db.newDb(org.projectnessie.cel.common.types.pb.Db.newDb) NestedTestAllTypes(com.google.api.expr.test.v1.proto3.TestAllTypesProto.NestedTestAllTypes) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with Type

use of com.acgist.snail.pojo.bean.M3u8.Type in project cel-java by projectnessie.

the class PbTypeDescriptionTest method checkedType.

@Test
void checkedType() {
    Db pbdb = newDb();
    TestAllTypes msg = TestAllTypes.getDefaultInstance();
    String msgName = msg.getDescriptorForType().getFullName();
    pbdb.registerMessage(msg);
    PbTypeDescription td = pbdb.describeType(msgName);
    assertThat(td).isNotNull();
    FieldDescription field = td.fieldByName("map_string_string");
    assertThat(field).isNotNull();
    Type mapType = Decls.newMapType(Decls.String, Decls.String);
    assertThat(field.checkedType()).isEqualTo(mapType);
    field = td.fieldByName("repeated_nested_message");
    assertThat(field).isNotNull();
    Type listType = Decls.newListType(Decls.newObjectType("google.api.expr.test.v1.proto3.TestAllTypes.NestedMessage"));
    assertThat(field.checkedType()).isEqualTo(listType);
}
Also used : Type(com.google.api.expr.v1alpha1.Type) ByteString(com.google.protobuf.ByteString) TestAllTypes(com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes) NestedTestAllTypes(com.google.api.expr.test.v1.proto3.TestAllTypesProto.NestedTestAllTypes) Db.newDb(org.projectnessie.cel.common.types.pb.Db.newDb) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with Type

use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.

the class CVC4FormulaCreator method getFormulaType.

@SuppressWarnings("unchecked")
@Override
public <T extends Formula> FormulaType<T> getFormulaType(T pFormula) {
    Type t = extractInfo(pFormula).getType();
    if (pFormula instanceof BitvectorFormula) {
        checkArgument(t.isBitVector(), "BitvectorFormula with actual type %s: %s", t, pFormula);
        return (FormulaType<T>) getFormulaType(extractInfo(pFormula));
    } else if (pFormula instanceof FloatingPointFormula) {
        checkArgument(t.isFloatingPoint(), "FloatingPointFormula with actual type %s: %s", t, pFormula);
        edu.stanford.CVC4.FloatingPointType fpType = new edu.stanford.CVC4.FloatingPointType(t);
        return (FormulaType<T>) FormulaType.getFloatingPointType((int) fpType.getExponentSize(), // without sign bit
        (int) fpType.getSignificandSize() - 1);
    } else if (pFormula instanceof ArrayFormula<?, ?>) {
        FormulaType<T> arrayIndexType = getArrayFormulaIndexType((ArrayFormula<T, T>) pFormula);
        FormulaType<T> arrayElementType = getArrayFormulaElementType((ArrayFormula<T, T>) pFormula);
        return (FormulaType<T>) FormulaType.getArrayType(arrayIndexType, arrayElementType);
    }
    return super.getFormulaType(pFormula);
}
Also used : BitvectorFormula(org.sosy_lab.java_smt.api.BitvectorFormula) CVC4BitvectorFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4BitvectorFormula) FloatingPointType(org.sosy_lab.java_smt.api.FormulaType.FloatingPointType) CVC4.vectorType(edu.stanford.CVC4.vectorType) Type(edu.stanford.CVC4.Type) BitVectorType(edu.stanford.CVC4.BitVectorType) FormulaType(org.sosy_lab.java_smt.api.FormulaType) ArrayFormulaType(org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType) ArrayType(edu.stanford.CVC4.ArrayType) FunctionType(edu.stanford.CVC4.FunctionType) FloatingPointFormula(org.sosy_lab.java_smt.api.FloatingPointFormula) CVC4FloatingPointFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4FloatingPointFormula) ArrayFormula(org.sosy_lab.java_smt.api.ArrayFormula) CVC4ArrayFormula(org.sosy_lab.java_smt.solvers.cvc4.CVC4Formula.CVC4ArrayFormula) FormulaType(org.sosy_lab.java_smt.api.FormulaType) ArrayFormulaType(org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType) FloatingPointType(org.sosy_lab.java_smt.api.FormulaType.FloatingPointType)

Aggregations

Type (com.google.api.expr.v1alpha1.Type)30 Test (org.junit.Test)16 Type (edu.stanford.CVC4.Type)14 Type (com.google.spanner.v1.Type)12 ArrayType (edu.stanford.CVC4.ArrayType)11 BitVectorType (edu.stanford.CVC4.BitVectorType)11 Expr (edu.stanford.CVC4.Expr)11 MapType (com.google.api.expr.v1alpha1.Type.MapType)10 Type (org.apache.xbean.asm9.Type)10 ByteString (com.google.protobuf.ByteString)9 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)9 ArrayList (java.util.ArrayList)9 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)8 FieldType (org.projectnessie.cel.common.types.ref.FieldType)8 FormulaType (org.sosy_lab.java_smt.api.FormulaType)8 ListValue (com.google.protobuf.ListValue)7 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)7 CheckerEnv.dynElementType (org.projectnessie.cel.checker.CheckerEnv.dynElementType)7 CheckerEnv.getObjectWellKnownType (org.projectnessie.cel.checker.CheckerEnv.getObjectWellKnownType)7 CheckerEnv.isObjectWellKnownType (org.projectnessie.cel.checker.CheckerEnv.isObjectWellKnownType)7