Search in sources :

Example 6 with Type

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

the class ProtoTypeRegistry method register.

@Override
public void register(Object t) {
    if (t instanceof Message) {
        Set<FileDescriptor> fds = collectFileDescriptorSet((Message) t);
        for (FileDescriptor fd : fds) {
            registerDescriptor(fd);
        }
        registerMessage((Message) t);
    } else if (t instanceof org.projectnessie.cel.common.types.ref.Type) {
        registerType((org.projectnessie.cel.common.types.ref.Type) t);
    } else {
        throw new RuntimeException(String.format("unsupported type: %s", t.getClass().getName()));
    }
}
Also used : DoubleType(org.projectnessie.cel.common.types.DoubleT.DoubleType) IntType(org.projectnessie.cel.common.types.IntT.IntType) MapType(org.projectnessie.cel.common.types.MapT.MapType) FieldType(org.projectnessie.cel.common.types.ref.FieldType) Err.anyWithEmptyType(org.projectnessie.cel.common.types.Err.anyWithEmptyType) DurationType(org.projectnessie.cel.common.types.DurationT.DurationType) UintType(org.projectnessie.cel.common.types.UintT.UintType) TypeType(org.projectnessie.cel.common.types.TypeT.TypeType) JavaType(com.google.protobuf.Descriptors.FieldDescriptor.JavaType) StringType(org.projectnessie.cel.common.types.StringT.StringType) NullType(org.projectnessie.cel.common.types.NullT.NullType) Type(com.google.api.expr.v1alpha1.Type) BytesType(org.projectnessie.cel.common.types.BytesT.BytesType) ListType(org.projectnessie.cel.common.types.ListT.ListType) BoolType(org.projectnessie.cel.common.types.BoolT.BoolType) Err.unknownType(org.projectnessie.cel.common.types.Err.unknownType) TimestampType(org.projectnessie.cel.common.types.TimestampT.TimestampType) PbTypeDescription.typeNameFromMessage(org.projectnessie.cel.common.types.pb.PbTypeDescription.typeNameFromMessage) Message(com.google.protobuf.Message) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor)

Example 7 with Type

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

the class CELTest method Customtypes.

@Test
void Customtypes() {
    Type exprType = Decls.newObjectType("google.api.expr.v1alpha1.Expr");
    TypeRegistry reg = newEmptyRegistry();
    Env e = newEnv(customTypeAdapter(reg), customTypeProvider(reg), container("google.api.expr.v1alpha1"), types(Expr.getDefaultInstance(), BoolT.BoolType, IntT.IntType, StringT.StringType), declarations(Decls.newVar("expr", exprType)));
    AstIssuesTuple astIss = e.compile("expr == Expr{id: 2,\n" + "\t\t\tcall_expr: Expr.Call{\n" + "\t\t\t\tfunction: \"_==_\",\n" + "\t\t\t\targs: [\n" + "\t\t\t\t\tExpr{id: 1, ident_expr: Expr.Ident{ name: \"a\" }},\n" + "\t\t\t\t\tExpr{id: 3, ident_expr: Expr.Ident{ name: \"b\" }}]\n" + "\t\t\t}}");
    assertThat(astIss.getAst().getResultType()).isEqualTo(Decls.Bool);
    Program prg = e.program(astIss.getAst());
    Object vars = mapOf("expr", Expr.newBuilder().setId(2).setCallExpr(Call.newBuilder().setFunction("_==_").addAllArgs(asList(Expr.newBuilder().setId(1).setIdentExpr(Ident.newBuilder().setName("a")).build(), Expr.newBuilder().setId(3).setIdentExpr(Ident.newBuilder().setName("b")).build()))).build());
    EvalResult out = prg.eval(vars);
    assertThat(out.getVal()).isSameAs(True);
}
Also used : Type(com.google.api.expr.v1alpha1.Type) EvalResult(org.projectnessie.cel.Program.EvalResult) Env.newEnv(org.projectnessie.cel.Env.newEnv) Env.newCustomEnv(org.projectnessie.cel.Env.newCustomEnv) AstIssuesTuple(org.projectnessie.cel.Env.AstIssuesTuple) TypeRegistry(org.projectnessie.cel.common.types.ref.TypeRegistry) Test(org.junit.jupiter.api.Test)

Example 8 with Type

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

the class CheckerEnvTest method overlappingOverload.

@Test
void overlappingOverload() {
    CheckerEnv env = newStandardCheckerEnv(Container.defaultContainer, newRegistry());
    Type paramA = Decls.newTypeParamType("A");
    List<String> typeParamAList = singletonList("A");
    Assertions.assertThatThrownBy(() -> env.add(Decls.newFunction(Overloads.TypeConvertDyn, Decls.newParameterizedOverload(Overloads.ToDyn, singletonList(paramA), Decls.Dyn, typeParamAList)))).hasMessage("overlapping overload for name 'dyn' (type '(type_param: \"A\") -> dyn' with overloadId: 'to_dyn' cannot be distinguished from '(type_param: \"A\") -> dyn' with overloadId: 'to_dyn')");
}
Also used : Type(com.google.api.expr.v1alpha1.Type) CheckerEnv.newStandardCheckerEnv(org.projectnessie.cel.checker.CheckerEnv.newStandardCheckerEnv) Test(org.junit.jupiter.api.Test)

Example 9 with Type

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

the class Checker method checkCreateMap.

void checkCreateMap(Expr.Builder e) {
    CreateStruct.Builder mapVal = e.getStructExprBuilder();
    Type keyType = null;
    Type valueType = null;
    for (Entry.Builder ent : mapVal.getEntriesBuilderList()) {
        Expr.Builder key = ent.getMapKeyBuilder();
        check(key);
        keyType = joinTypes(location(key), keyType, getType(key));
        Expr.Builder val = ent.getValueBuilder();
        check(val);
        valueType = joinTypes(location(val), valueType, getType(val));
    }
    if (keyType == null) {
        // If the map is empty, assign free type variables to typeKey and value type.
        keyType = newTypeVar();
        valueType = newTypeVar();
    }
    setType(e, Decls.newMapType(keyType, valueType));
}
Also used : CheckerEnv.getObjectWellKnownType(org.projectnessie.cel.checker.CheckerEnv.getObjectWellKnownType) CheckerEnv.isObjectWellKnownType(org.projectnessie.cel.checker.CheckerEnv.isObjectWellKnownType) CheckerEnv.dynElementType(org.projectnessie.cel.checker.CheckerEnv.dynElementType) Type(com.google.api.expr.v1alpha1.Type) MapType(com.google.api.expr.v1alpha1.Type.MapType) FieldType(org.projectnessie.cel.common.types.ref.FieldType) Entry(com.google.api.expr.v1alpha1.Expr.CreateStruct.Entry) CreateStruct(com.google.api.expr.v1alpha1.Expr.CreateStruct) Expr(com.google.api.expr.v1alpha1.Expr) CheckedExpr(com.google.api.expr.v1alpha1.CheckedExpr)

Example 10 with Type

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

the class Checker method checkSelect.

void checkSelect(Expr.Builder e) {
    Select.Builder sel = e.getSelectExprBuilder();
    // Before traversing down the tree, try to interpret as qualified name.
    String qname = Container.toQualifiedName(e.build());
    if (qname != null) {
        Decl ident = env.lookupIdent(qname);
        if (ident != null) {
            if (sel.getTestOnly()) {
                errors.expressionDoesNotSelectField(location(e));
                setType(e, Decls.Bool);
                return;
            }
            // Rewrite the node to be a variable reference to the resolved fully-qualified
            // variable name.
            setType(e, ident.getIdent().getType());
            setReference(e, newIdentReference(ident.getName(), ident.getIdent().getValue()));
            String identName = ident.getName();
            e.getIdentExprBuilder().setName(identName);
            return;
        }
    }
    // Interpret as field selection, first traversing down the operand.
    check(sel.getOperandBuilder());
    Type targetType = getType(sel.getOperandBuilder());
    // Assume error type by default as most types do not support field selection.
    Type resultType = Decls.Error;
    switch(kindOf(targetType)) {
        case kindMap:
            // Maps yield their value type as the selection result type.
            MapType mapType = targetType.getMapType();
            resultType = mapType.getValueType();
            break;
        case kindObject:
            // Objects yield their field type declaration as the selection result type, but only if
            // the field is defined.
            FieldType fieldType = lookupFieldType(location(e), targetType.getMessageType(), sel.getField());
            if (fieldType != null) {
                resultType = fieldType.type;
            }
            break;
        case kindTypeParam:
            // Set the operand type to DYN to prevent assignment to a potentionally incorrect type
            // at a later point in type-checking. The isAssignable call will update the type
            // substitutions for the type param under the covers.
            isAssignable(Decls.Dyn, targetType);
            // Also, set the result type to DYN.
            resultType = Decls.Dyn;
            break;
        default:
            // in order to allow forward progress on the check.
            if (isDynOrError(targetType)) {
                resultType = Decls.Dyn;
            } else {
                errors.typeDoesNotSupportFieldSelection(location(e), targetType);
            }
            break;
    }
    if (sel.getTestOnly()) {
        resultType = Decls.Bool;
    }
    setType(e, resultType);
}
Also used : CheckerEnv.getObjectWellKnownType(org.projectnessie.cel.checker.CheckerEnv.getObjectWellKnownType) CheckerEnv.isObjectWellKnownType(org.projectnessie.cel.checker.CheckerEnv.isObjectWellKnownType) CheckerEnv.dynElementType(org.projectnessie.cel.checker.CheckerEnv.dynElementType) Type(com.google.api.expr.v1alpha1.Type) MapType(com.google.api.expr.v1alpha1.Type.MapType) FieldType(org.projectnessie.cel.common.types.ref.FieldType) Select(com.google.api.expr.v1alpha1.Expr.Select) IdentDecl(com.google.api.expr.v1alpha1.Decl.IdentDecl) Decl(com.google.api.expr.v1alpha1.Decl) MapType(com.google.api.expr.v1alpha1.Type.MapType) FieldType(org.projectnessie.cel.common.types.ref.FieldType)

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