Search in sources :

Example 56 with Type

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

the class ConformanceServerTest method FullUp.

/**
 * TestFullUp tests Parse, Check, and Eval back-to-back.
 */
@Test
void FullUp() {
    ParseRequest preq = ParseRequest.newBuilder().setCelSource("x + y").build();
    ParseResponse pres = stub.parse(preq);
    assertThat(pres.isInitialized()).isTrue();
    ParsedExpr parsedExpr = pres.getParsedExpr();
    assertThat(parsedExpr.isInitialized()).isTrue();
    CheckRequest creq = CheckRequest.newBuilder().setParsedExpr(parsedExpr).addTypeEnv(Decls.newVar("x", Decls.Int)).addTypeEnv(Decls.newVar("y", Decls.Int)).build();
    CheckResponse cres = stub.check(creq);
    assertThat(cres.isInitialized()).isTrue();
    CheckedExpr checkedExpr = cres.getCheckedExpr();
    assertThat(checkedExpr.isInitialized()).isTrue();
    Type tp = checkedExpr.getTypeMapMap().get(1L);
    assertThat(tp).isNotNull();
    assertThat(tp.getTypeKindCase()).isSameAs(TypeKindCase.PRIMITIVE);
    assertThat(tp.getPrimitive()).isSameAs(PrimitiveType.INT64);
    EvalRequest ereq = EvalRequest.newBuilder().setCheckedExpr(checkedExpr).putBindings("x", exprValueInt64(1)).putBindings("y", exprValueInt64(2)).build();
    EvalResponse eres = stub.eval(ereq);
    assertThat(eres.isInitialized()).isTrue();
    assertThat(eres.getResult().isInitialized()).isTrue();
    assertThat(eres.getResult().getKindCase()).isSameAs(KindCase.VALUE);
    assertThat(eres.getResult().getValue().getKindCase()).isSameAs(Value.KindCase.INT64_VALUE);
    assertThat(eres.getResult().getValue().getInt64Value()).isEqualTo(3L);
}
Also used : EvalRequest(com.google.api.expr.v1alpha1.EvalRequest) PrimitiveType(com.google.api.expr.v1alpha1.Type.PrimitiveType) Type(com.google.api.expr.v1alpha1.Type) ParseRequest(com.google.api.expr.v1alpha1.ParseRequest) CheckedExpr(com.google.api.expr.v1alpha1.CheckedExpr) ParsedExpr(com.google.api.expr.v1alpha1.ParsedExpr) CheckResponse(com.google.api.expr.v1alpha1.CheckResponse) CheckRequest(com.google.api.expr.v1alpha1.CheckRequest) ParseResponse(com.google.api.expr.v1alpha1.ParseResponse) EvalResponse(com.google.api.expr.v1alpha1.EvalResponse) Test(org.junit.jupiter.api.Test)

Example 57 with Type

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

the class CEL method newProgram.

/**
 * newProgram creates a program instance with an environment, an ast, and an optional list of
 * ProgramOption values.
 *
 * <p>If the program cannot be configured the prog will be nil, with a non-nil error response.
 */
public static Program newProgram(Env e, Ast ast, ProgramOption... opts) {
    // Build the dispatcher, interpreter, and default program value.
    Dispatcher disp = newDispatcher();
    // Ensure the default attribute factory is set after the adapter and provider are
    // configured.
    Prog p = new Prog(e, disp);
    // Configure the program via the ProgramOption values.
    for (ProgramOption opt : opts) {
        if (opt == null) {
            throw new NullPointerException("program options should be non-nil");
        }
        p = opt.apply(p);
        if (p == null) {
            throw new NullPointerException(String.format("program option of type '%s' returned null", opt.getClass().getName()));
        }
    }
    // Set the attribute factory after the options have been set.
    if (p.evalOpts.contains(EvalOption.OptPartialEval)) {
        p.attrFactory = newPartialAttributeFactory(e.getContainer(), e.getTypeAdapter(), e.getTypeProvider());
    } else {
        p.attrFactory = newAttributeFactory(e.getContainer(), e.getTypeAdapter(), e.getTypeProvider());
    }
    Interpreter interp = newInterpreter(disp, e.getContainer(), e.getTypeProvider(), e.getTypeAdapter(), p.attrFactory);
    p.interpreter = interp;
    // Translate the EvalOption flags into InterpretableDecorator instances.
    List<InterpretableDecorator> decorators = new ArrayList<>(p.decorators);
    // Enable constant folding first.
    if (p.evalOpts.contains(EvalOption.OptOptimize)) {
        decorators.add(optimize());
    }
    Prog pp = p;
    // Enable exhaustive eval over state tracking since it offers a superset of features.
    if (p.evalOpts.contains(EvalOption.OptExhaustiveEval)) {
        // State tracking requires that each Eval() call operate on an isolated EvalState
        // object; hence, the presence of the factory.
        ProgFactory factory = state -> {
            List<InterpretableDecorator> decs = new ArrayList<>(decorators);
            decs.add(exhaustiveEval(state));
            Prog clone = new Prog(e, pp.evalOpts, pp.defaultVars, disp, interp, state);
            return initInterpretable(clone, ast, decs);
        };
        return initProgGen(factory);
    } else if (p.evalOpts.contains(EvalOption.OptTrackState)) {
        // Enable state tracking last since it too requires the factory approach but is less
        // featured than the ExhaustiveEval decorator.
        ProgFactory factory = state -> {
            List<InterpretableDecorator> decs = new ArrayList<>(decorators);
            decs.add(trackState(state));
            Prog clone = new Prog(e, pp.evalOpts, pp.defaultVars, disp, interp, state);
            return initInterpretable(clone, ast, decs);
        };
        return initProgGen(factory);
    }
    return initInterpretable(p, ast, decorators);
}
Also used : SourceInfo(com.google.api.expr.v1alpha1.SourceInfo) Interpreter(org.projectnessie.cel.interpreter.Interpreter) AttributePattern.newPartialAttributeFactory(org.projectnessie.cel.interpreter.AttributePattern.newPartialAttributeFactory) Interpreter.exhaustiveEval(org.projectnessie.cel.interpreter.Interpreter.exhaustiveEval) PartialActivation(org.projectnessie.cel.interpreter.Activation.PartialActivation) Interpreter.optimize(org.projectnessie.cel.interpreter.Interpreter.optimize) AttributePattern.newAttributePattern(org.projectnessie.cel.interpreter.AttributePattern.newAttributePattern) EvalState.newEvalState(org.projectnessie.cel.interpreter.EvalState.newEvalState) Activation.emptyActivation(org.projectnessie.cel.interpreter.Activation.emptyActivation) InterpretableDecorator(org.projectnessie.cel.interpreter.InterpretableDecorator) ArrayList(java.util.ArrayList) Dispatcher(org.projectnessie.cel.interpreter.Dispatcher) Interpreter.newInterpreter(org.projectnessie.cel.interpreter.Interpreter.newInterpreter) Interpreter.trackState(org.projectnessie.cel.interpreter.Interpreter.trackState) Source.newInfoSource(org.projectnessie.cel.common.Source.newInfoSource) Map(java.util.Map) Type(com.google.api.expr.v1alpha1.Type) ParsedExpr(com.google.api.expr.v1alpha1.ParsedExpr) Unparser.unparse(org.projectnessie.cel.parser.Unparser.unparse) AttributeFactory.newAttributeFactory(org.projectnessie.cel.interpreter.AttributeFactory.newAttributeFactory) Coster(org.projectnessie.cel.interpreter.Coster) Expr(com.google.api.expr.v1alpha1.Expr) Cost(org.projectnessie.cel.interpreter.Coster.Cost) AttributePattern(org.projectnessie.cel.interpreter.AttributePattern) CheckedExpr(com.google.api.expr.v1alpha1.CheckedExpr) Activation(org.projectnessie.cel.interpreter.Activation) List(java.util.List) Dispatcher.newDispatcher(org.projectnessie.cel.interpreter.Dispatcher.newDispatcher) Activation.newPartialActivation(org.projectnessie.cel.interpreter.Activation.newPartialActivation) Reference(com.google.api.expr.v1alpha1.Reference) Interpreter(org.projectnessie.cel.interpreter.Interpreter) Interpreter.newInterpreter(org.projectnessie.cel.interpreter.Interpreter.newInterpreter) ArrayList(java.util.ArrayList) InterpretableDecorator(org.projectnessie.cel.interpreter.InterpretableDecorator) ArrayList(java.util.ArrayList) List(java.util.List) Dispatcher(org.projectnessie.cel.interpreter.Dispatcher) Dispatcher.newDispatcher(org.projectnessie.cel.interpreter.Dispatcher.newDispatcher)

Example 58 with Type

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

the class Checker method checkCreateMessage.

void checkCreateMessage(Expr.Builder e) {
    CreateStruct.Builder msgVal = e.getStructExprBuilder();
    // Determine the type of the message.
    Type messageType = Decls.Error;
    Decl decl = env.lookupIdent(msgVal.getMessageName());
    if (decl == null) {
        errors.undeclaredReference(location(e), env.container.name(), msgVal.getMessageName());
        return;
    }
    // Ensure the type name is fully qualified in the AST.
    msgVal.setMessageName(decl.getName());
    setReference(e, newIdentReference(decl.getName(), null));
    IdentDecl ident = decl.getIdent();
    Types.Kind identKind = kindOf(ident.getType());
    if (identKind != Kind.kindError) {
        if (identKind != Kind.kindType) {
            errors.notAType(location(e), ident.getType());
        } else {
            messageType = ident.getType().getType();
            if (kindOf(messageType) != Kind.kindObject) {
                errors.notAMessageType(location(e), messageType);
                messageType = Decls.Error;
            }
        }
    }
    if (isObjectWellKnownType(messageType)) {
        setType(e, getObjectWellKnownType(messageType));
    } else {
        setType(e, messageType);
    }
    // Check the field initializers.
    for (Entry.Builder ent : msgVal.getEntriesBuilderList()) {
        String field = ent.getFieldKey();
        Expr.Builder value = ent.getValueBuilder();
        check(value);
        Type fieldType = Decls.Error;
        FieldType t = lookupFieldType(locationByID(ent.getId()), messageType.getMessageType(), field);
        if (t != null) {
            fieldType = t.type;
        }
        if (!isAssignable(fieldType, getType(value))) {
            errors.fieldTypeMismatch(locationByID(ent.getId()), field, fieldType, getType(value));
        }
    }
}
Also used : CreateStruct(com.google.api.expr.v1alpha1.Expr.CreateStruct) IdentDecl(com.google.api.expr.v1alpha1.Decl.IdentDecl) Decl(com.google.api.expr.v1alpha1.Decl) FieldType(org.projectnessie.cel.common.types.ref.FieldType) 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) Expr(com.google.api.expr.v1alpha1.Expr) CheckedExpr(com.google.api.expr.v1alpha1.CheckedExpr) Kind(org.projectnessie.cel.checker.Types.Kind) IdentDecl(com.google.api.expr.v1alpha1.Decl.IdentDecl)

Example 59 with Type

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

the class CheckerEnv method sanitizeIdent.

/**
 * sanitizeIdent replaces the identifier's well-known types referenced by message name with
 * references to CEL built-in type instances.
 */
Decl sanitizeIdent(Decl decl) {
    IdentDecl id = decl.getIdent();
    Type t = id.getType();
    if (!isObjectWellKnownType(t)) {
        return decl;
    }
    return Decls.newIdent(decl.getName(), getObjectWellKnownType(t), id.getValue());
}
Also used : Types.formatCheckedType(org.projectnessie.cel.checker.Types.formatCheckedType) Type(com.google.api.expr.v1alpha1.Type) ErrType(org.projectnessie.cel.common.types.Err.ErrType) IdentDecl(com.google.api.expr.v1alpha1.Decl.IdentDecl)

Example 60 with Type

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

the class Standard method makeStandardDeclarations.

// StandardDeclarations returns the Decls for all functions and constants in the evaluator.
static List<Decl> makeStandardDeclarations() {
    // Some shortcuts we use when building declarations.
    Type paramA = Decls.newTypeParamType("A");
    List<String> typeParamAList = singletonList("A");
    Type listOfA = Decls.newListType(paramA);
    Type paramB = Decls.newTypeParamType("B");
    List<String> typeParamABList = asList("A", "B");
    Type mapOfAB = Decls.newMapType(paramA, paramB);
    List<Decl> idents = new ArrayList<>();
    for (Type t : asList(Decls.Int, Decls.Uint, Decls.Bool, Decls.Double, Decls.Bytes, Decls.String)) {
        idents.add(Decls.newVar(formatCheckedType(t), Decls.newTypeType(t)));
    }
    idents.add(Decls.newVar("list", Decls.newTypeType(listOfA)));
    idents.add(Decls.newVar("map", Decls.newTypeType(mapOfAB)));
    idents.add(Decls.newVar("null_type", Decls.newTypeType(Decls.Null)));
    idents.add(Decls.newVar("type", Decls.newTypeType(Decls.newTypeType(null))));
    // Booleans
    // TODO: allow the conditional to return a heterogenous type.
    idents.add(Decls.newFunction(Operator.Conditional.id, Decls.newParameterizedOverload(Overloads.Conditional, asList(Decls.Bool, paramA, paramA), paramA, typeParamAList)));
    idents.add(Decls.newFunction(Operator.LogicalAnd.id, Decls.newOverload(Overloads.LogicalAnd, asList(Decls.Bool, Decls.Bool), Decls.Bool)));
    idents.add(Decls.newFunction(Operator.LogicalOr.id, Decls.newOverload(Overloads.LogicalOr, asList(Decls.Bool, Decls.Bool), Decls.Bool)));
    idents.add(Decls.newFunction(Operator.LogicalNot.id, Decls.newOverload(Overloads.LogicalNot, singletonList(Decls.Bool), Decls.Bool)));
    idents.add(Decls.newFunction(Operator.NotStrictlyFalse.id, Decls.newOverload(Overloads.NotStrictlyFalse, singletonList(Decls.Bool), Decls.Bool)));
    // Relations.
    idents.add(Decls.newFunction(Operator.Less.id, Decls.newOverload(Overloads.LessBool, asList(Decls.Bool, Decls.Bool), Decls.Bool), Decls.newOverload(Overloads.LessInt64, asList(Decls.Int, Decls.Int), Decls.Bool), Decls.newOverload(Overloads.LessUint64, asList(Decls.Uint, Decls.Uint), Decls.Bool), Decls.newOverload(Overloads.LessDouble, asList(Decls.Double, Decls.Double), Decls.Bool), Decls.newOverload(Overloads.LessString, asList(Decls.String, Decls.String), Decls.Bool), Decls.newOverload(Overloads.LessBytes, asList(Decls.Bytes, Decls.Bytes), Decls.Bool), Decls.newOverload(Overloads.LessTimestamp, asList(Decls.Timestamp, Decls.Timestamp), Decls.Bool), Decls.newOverload(Overloads.LessDuration, asList(Decls.Duration, Decls.Duration), Decls.Bool)));
    idents.add(Decls.newFunction(Operator.LessEquals.id, Decls.newOverload(Overloads.LessEqualsBool, asList(Decls.Bool, Decls.Bool), Decls.Bool), Decls.newOverload(Overloads.LessEqualsInt64, asList(Decls.Int, Decls.Int), Decls.Bool), Decls.newOverload(Overloads.LessEqualsUint64, asList(Decls.Uint, Decls.Uint), Decls.Bool), Decls.newOverload(Overloads.LessEqualsDouble, asList(Decls.Double, Decls.Double), Decls.Bool), Decls.newOverload(Overloads.LessEqualsString, asList(Decls.String, Decls.String), Decls.Bool), Decls.newOverload(Overloads.LessEqualsBytes, asList(Decls.Bytes, Decls.Bytes), Decls.Bool), Decls.newOverload(Overloads.LessEqualsTimestamp, asList(Decls.Timestamp, Decls.Timestamp), Decls.Bool), Decls.newOverload(Overloads.LessEqualsDuration, asList(Decls.Duration, Decls.Duration), Decls.Bool)));
    idents.add(Decls.newFunction(Operator.Greater.id, Decls.newOverload(Overloads.GreaterBool, asList(Decls.Bool, Decls.Bool), Decls.Bool), Decls.newOverload(Overloads.GreaterInt64, asList(Decls.Int, Decls.Int), Decls.Bool), Decls.newOverload(Overloads.GreaterUint64, asList(Decls.Uint, Decls.Uint), Decls.Bool), Decls.newOverload(Overloads.GreaterDouble, asList(Decls.Double, Decls.Double), Decls.Bool), Decls.newOverload(Overloads.GreaterString, asList(Decls.String, Decls.String), Decls.Bool), Decls.newOverload(Overloads.GreaterBytes, asList(Decls.Bytes, Decls.Bytes), Decls.Bool), Decls.newOverload(Overloads.GreaterTimestamp, asList(Decls.Timestamp, Decls.Timestamp), Decls.Bool), Decls.newOverload(Overloads.GreaterDuration, asList(Decls.Duration, Decls.Duration), Decls.Bool)));
    idents.add(Decls.newFunction(Operator.GreaterEquals.id, Decls.newOverload(Overloads.GreaterEqualsBool, asList(Decls.Bool, Decls.Bool), Decls.Bool), Decls.newOverload(Overloads.GreaterEqualsInt64, asList(Decls.Int, Decls.Int), Decls.Bool), Decls.newOverload(Overloads.GreaterEqualsUint64, asList(Decls.Uint, Decls.Uint), Decls.Bool), Decls.newOverload(Overloads.GreaterEqualsDouble, asList(Decls.Double, Decls.Double), Decls.Bool), Decls.newOverload(Overloads.GreaterEqualsString, asList(Decls.String, Decls.String), Decls.Bool), Decls.newOverload(Overloads.GreaterEqualsBytes, asList(Decls.Bytes, Decls.Bytes), Decls.Bool), Decls.newOverload(Overloads.GreaterEqualsTimestamp, asList(Decls.Timestamp, Decls.Timestamp), Decls.Bool), Decls.newOverload(Overloads.GreaterEqualsDuration, asList(Decls.Duration, Decls.Duration), Decls.Bool)));
    idents.add(Decls.newFunction(Operator.Equals.id, Decls.newParameterizedOverload(Overloads.Equals, asList(paramA, paramA), Decls.Bool, typeParamAList)));
    idents.add(Decls.newFunction(Operator.NotEquals.id, Decls.newParameterizedOverload(Overloads.NotEquals, asList(paramA, paramA), Decls.Bool, typeParamAList)));
    // Algebra.
    idents.add(Decls.newFunction(Operator.Subtract.id, Decls.newOverload(Overloads.SubtractInt64, asList(Decls.Int, Decls.Int), Decls.Int), Decls.newOverload(Overloads.SubtractUint64, asList(Decls.Uint, Decls.Uint), Decls.Uint), Decls.newOverload(Overloads.SubtractDouble, asList(Decls.Double, Decls.Double), Decls.Double), Decls.newOverload(Overloads.SubtractTimestampTimestamp, asList(Decls.Timestamp, Decls.Timestamp), Decls.Duration), Decls.newOverload(Overloads.SubtractTimestampDuration, asList(Decls.Timestamp, Decls.Duration), Decls.Timestamp), Decls.newOverload(Overloads.SubtractDurationDuration, asList(Decls.Duration, Decls.Duration), Decls.Duration)));
    idents.add(Decls.newFunction(Operator.Multiply.id, Decls.newOverload(Overloads.MultiplyInt64, asList(Decls.Int, Decls.Int), Decls.Int), Decls.newOverload(Overloads.MultiplyUint64, asList(Decls.Uint, Decls.Uint), Decls.Uint), Decls.newOverload(Overloads.MultiplyDouble, asList(Decls.Double, Decls.Double), Decls.Double)));
    idents.add(Decls.newFunction(Operator.Divide.id, Decls.newOverload(Overloads.DivideInt64, asList(Decls.Int, Decls.Int), Decls.Int), Decls.newOverload(Overloads.DivideUint64, asList(Decls.Uint, Decls.Uint), Decls.Uint), Decls.newOverload(Overloads.DivideDouble, asList(Decls.Double, Decls.Double), Decls.Double)));
    idents.add(Decls.newFunction(Operator.Modulo.id, Decls.newOverload(Overloads.ModuloInt64, asList(Decls.Int, Decls.Int), Decls.Int), Decls.newOverload(Overloads.ModuloUint64, asList(Decls.Uint, Decls.Uint), Decls.Uint)));
    idents.add(Decls.newFunction(Operator.Add.id, Decls.newOverload(Overloads.AddInt64, asList(Decls.Int, Decls.Int), Decls.Int), Decls.newOverload(Overloads.AddUint64, asList(Decls.Uint, Decls.Uint), Decls.Uint), Decls.newOverload(Overloads.AddDouble, asList(Decls.Double, Decls.Double), Decls.Double), Decls.newOverload(Overloads.AddString, asList(Decls.String, Decls.String), Decls.String), Decls.newOverload(Overloads.AddBytes, asList(Decls.Bytes, Decls.Bytes), Decls.Bytes), Decls.newParameterizedOverload(Overloads.AddList, asList(listOfA, listOfA), listOfA, typeParamAList), Decls.newOverload(Overloads.AddTimestampDuration, asList(Decls.Timestamp, Decls.Duration), Decls.Timestamp), Decls.newOverload(Overloads.AddDurationTimestamp, asList(Decls.Duration, Decls.Timestamp), Decls.Timestamp), Decls.newOverload(Overloads.AddDurationDuration, asList(Decls.Duration, Decls.Duration), Decls.Duration)));
    idents.add(Decls.newFunction(Operator.Negate.id, Decls.newOverload(Overloads.NegateInt64, singletonList(Decls.Int), Decls.Int), Decls.newOverload(Overloads.NegateDouble, singletonList(Decls.Double), Decls.Double)));
    // Index.
    idents.add(Decls.newFunction(Operator.Index.id, Decls.newParameterizedOverload(Overloads.IndexList, asList(listOfA, Decls.Int), paramA, typeParamAList), Decls.newParameterizedOverload(Overloads.IndexMap, asList(mapOfAB, paramA), paramB, typeParamABList)));
    // Decls.newOverload(Overloads.IndexMessage,
    // []*expr.Type{Decls.Dyn, Decls.String}, Decls.Dyn)));
    // Collections.
    idents.add(Decls.newFunction(Overloads.Size, Decls.newInstanceOverload(Overloads.SizeStringInst, singletonList(Decls.String), Decls.Int), Decls.newInstanceOverload(Overloads.SizeBytesInst, singletonList(Decls.Bytes), Decls.Int), Decls.newParameterizedInstanceOverload(Overloads.SizeListInst, singletonList(listOfA), Decls.Int, typeParamAList), Decls.newParameterizedInstanceOverload(Overloads.SizeMapInst, singletonList(mapOfAB), Decls.Int, typeParamABList), Decls.newOverload(Overloads.SizeString, singletonList(Decls.String), Decls.Int), Decls.newOverload(Overloads.SizeBytes, singletonList(Decls.Bytes), Decls.Int), Decls.newParameterizedOverload(Overloads.SizeList, singletonList(listOfA), Decls.Int, typeParamAList), Decls.newParameterizedOverload(Overloads.SizeMap, singletonList(mapOfAB), Decls.Int, typeParamABList)));
    idents.add(Decls.newFunction(Operator.In.id, Decls.newParameterizedOverload(Overloads.InList, asList(paramA, listOfA), Decls.Bool, typeParamAList), Decls.newParameterizedOverload(Overloads.InMap, asList(paramA, mapOfAB), Decls.Bool, typeParamABList)));
    // Deprecated 'in()' function.
    idents.add(Decls.newFunction(Overloads.DeprecatedIn, Decls.newParameterizedOverload(Overloads.InList, asList(paramA, listOfA), Decls.Bool, typeParamAList), Decls.newParameterizedOverload(Overloads.InMap, asList(paramA, mapOfAB), Decls.Bool, typeParamABList)));
    // Decls.newOverload(Overloads.InMessage,
    // []*expr.Type{Dyn, Decls.String},Decls.Bool)));
    // Conversions to type.
    idents.add(Decls.newFunction(Overloads.TypeConvertType, Decls.newParameterizedOverload(Overloads.TypeConvertType, singletonList(paramA), Decls.newTypeType(paramA), typeParamAList)));
    // Conversions to int.
    idents.add(Decls.newFunction(Overloads.TypeConvertInt, Decls.newOverload(Overloads.IntToInt, singletonList(Decls.Int), Decls.Int), Decls.newOverload(Overloads.UintToInt, singletonList(Decls.Uint), Decls.Int), Decls.newOverload(Overloads.DoubleToInt, singletonList(Decls.Double), Decls.Int), Decls.newOverload(Overloads.StringToInt, singletonList(Decls.String), Decls.Int), Decls.newOverload(Overloads.TimestampToInt, singletonList(Decls.Timestamp), Decls.Int), Decls.newOverload(Overloads.DurationToInt, singletonList(Decls.Duration), Decls.Int)));
    // Conversions to uint.
    idents.add(Decls.newFunction(Overloads.TypeConvertUint, Decls.newOverload(Overloads.UintToUint, singletonList(Decls.Uint), Decls.Uint), Decls.newOverload(Overloads.IntToUint, singletonList(Decls.Int), Decls.Uint), Decls.newOverload(Overloads.DoubleToUint, singletonList(Decls.Double), Decls.Uint), Decls.newOverload(Overloads.StringToUint, singletonList(Decls.String), Decls.Uint)));
    // Conversions to double.
    idents.add(Decls.newFunction(Overloads.TypeConvertDouble, Decls.newOverload(Overloads.DoubleToDouble, singletonList(Decls.Double), Decls.Double), Decls.newOverload(Overloads.IntToDouble, singletonList(Decls.Int), Decls.Double), Decls.newOverload(Overloads.UintToDouble, singletonList(Decls.Uint), Decls.Double), Decls.newOverload(Overloads.StringToDouble, singletonList(Decls.String), Decls.Double)));
    // Conversions to bool.
    idents.add(Decls.newFunction(Overloads.TypeConvertBool, Decls.newOverload(Overloads.BoolToBool, singletonList(Decls.Bool), Decls.Bool), Decls.newOverload(Overloads.StringToBool, singletonList(Decls.String), Decls.Bool)));
    // Conversions to string.
    idents.add(Decls.newFunction(Overloads.TypeConvertString, Decls.newOverload(Overloads.StringToString, singletonList(Decls.String), Decls.String), Decls.newOverload(Overloads.BoolToString, singletonList(Decls.Bool), Decls.String), Decls.newOverload(Overloads.IntToString, singletonList(Decls.Int), Decls.String), Decls.newOverload(Overloads.UintToString, singletonList(Decls.Uint), Decls.String), Decls.newOverload(Overloads.DoubleToString, singletonList(Decls.Double), Decls.String), Decls.newOverload(Overloads.BytesToString, singletonList(Decls.Bytes), Decls.String), Decls.newOverload(Overloads.TimestampToString, singletonList(Decls.Timestamp), Decls.String), Decls.newOverload(Overloads.DurationToString, singletonList(Decls.Duration), Decls.String)));
    // Conversions to bytes.
    idents.add(Decls.newFunction(Overloads.TypeConvertBytes, Decls.newOverload(Overloads.BytesToBytes, singletonList(Decls.Bytes), Decls.Bytes), Decls.newOverload(Overloads.StringToBytes, singletonList(Decls.String), Decls.Bytes)));
    // Conversions to timestamps.
    idents.add(Decls.newFunction(Overloads.TypeConvertTimestamp, Decls.newOverload(Overloads.TimestampToTimestamp, singletonList(Decls.Timestamp), Decls.Timestamp), Decls.newOverload(Overloads.StringToTimestamp, singletonList(Decls.String), Decls.Timestamp), Decls.newOverload(Overloads.IntToTimestamp, singletonList(Decls.Int), Decls.Timestamp)));
    // Conversions to durations.
    idents.add(Decls.newFunction(Overloads.TypeConvertDuration, Decls.newOverload(Overloads.DurationToDuration, singletonList(Decls.Duration), Decls.Duration), Decls.newOverload(Overloads.StringToDuration, singletonList(Decls.String), Decls.Duration), Decls.newOverload(Overloads.IntToDuration, singletonList(Decls.Int), Decls.Duration)));
    // Conversions to Dyn.
    idents.add(Decls.newFunction(Overloads.TypeConvertDyn, Decls.newParameterizedOverload(Overloads.ToDyn, singletonList(paramA), Decls.Dyn, typeParamAList)));
    // String functions.
    idents.add(Decls.newFunction(Overloads.Contains, Decls.newInstanceOverload(Overloads.ContainsString, asList(Decls.String, Decls.String), Decls.Bool)));
    idents.add(Decls.newFunction(Overloads.EndsWith, Decls.newInstanceOverload(Overloads.EndsWithString, asList(Decls.String, Decls.String), Decls.Bool)));
    idents.add(Decls.newFunction(Overloads.Matches, Decls.newInstanceOverload(Overloads.MatchesString, asList(Decls.String, Decls.String), Decls.Bool)));
    idents.add(Decls.newFunction(Overloads.StartsWith, Decls.newInstanceOverload(Overloads.StartsWithString, asList(Decls.String, Decls.String), Decls.Bool)));
    // Date/time functions.
    idents.add(Decls.newFunction(Overloads.TimeGetFullYear, Decls.newInstanceOverload(Overloads.TimestampToYear, singletonList(Decls.Timestamp), Decls.Int), Decls.newInstanceOverload(Overloads.TimestampToYearWithTz, asList(Decls.Timestamp, Decls.String), Decls.Int)));
    idents.add(Decls.newFunction(Overloads.TimeGetMonth, Decls.newInstanceOverload(Overloads.TimestampToMonth, singletonList(Decls.Timestamp), Decls.Int), Decls.newInstanceOverload(Overloads.TimestampToMonthWithTz, asList(Decls.Timestamp, Decls.String), Decls.Int)));
    idents.add(Decls.newFunction(Overloads.TimeGetDayOfYear, Decls.newInstanceOverload(Overloads.TimestampToDayOfYear, singletonList(Decls.Timestamp), Decls.Int), Decls.newInstanceOverload(Overloads.TimestampToDayOfYearWithTz, asList(Decls.Timestamp, Decls.String), Decls.Int)));
    idents.add(Decls.newFunction(Overloads.TimeGetDayOfMonth, Decls.newInstanceOverload(Overloads.TimestampToDayOfMonthZeroBased, singletonList(Decls.Timestamp), Decls.Int), Decls.newInstanceOverload(Overloads.TimestampToDayOfMonthZeroBasedWithTz, asList(Decls.Timestamp, Decls.String), Decls.Int)));
    idents.add(Decls.newFunction(Overloads.TimeGetDate, Decls.newInstanceOverload(Overloads.TimestampToDayOfMonthOneBased, singletonList(Decls.Timestamp), Decls.Int), Decls.newInstanceOverload(Overloads.TimestampToDayOfMonthOneBasedWithTz, asList(Decls.Timestamp, Decls.String), Decls.Int)));
    idents.add(Decls.newFunction(Overloads.TimeGetDayOfWeek, Decls.newInstanceOverload(Overloads.TimestampToDayOfWeek, singletonList(Decls.Timestamp), Decls.Int), Decls.newInstanceOverload(Overloads.TimestampToDayOfWeekWithTz, asList(Decls.Timestamp, Decls.String), Decls.Int)));
    idents.add(Decls.newFunction(Overloads.TimeGetHours, Decls.newInstanceOverload(Overloads.TimestampToHours, singletonList(Decls.Timestamp), Decls.Int), Decls.newInstanceOverload(Overloads.TimestampToHoursWithTz, asList(Decls.Timestamp, Decls.String), Decls.Int), Decls.newInstanceOverload(Overloads.DurationToHours, singletonList(Decls.Duration), Decls.Int)));
    idents.add(Decls.newFunction(Overloads.TimeGetMinutes, Decls.newInstanceOverload(Overloads.TimestampToMinutes, singletonList(Decls.Timestamp), Decls.Int), Decls.newInstanceOverload(Overloads.TimestampToMinutesWithTz, asList(Decls.Timestamp, Decls.String), Decls.Int), Decls.newInstanceOverload(Overloads.DurationToMinutes, singletonList(Decls.Duration), Decls.Int)));
    idents.add(Decls.newFunction(Overloads.TimeGetSeconds, Decls.newInstanceOverload(Overloads.TimestampToSeconds, singletonList(Decls.Timestamp), Decls.Int), Decls.newInstanceOverload(Overloads.TimestampToSecondsWithTz, asList(Decls.Timestamp, Decls.String), Decls.Int), Decls.newInstanceOverload(Overloads.DurationToSeconds, singletonList(Decls.Duration), Decls.Int)));
    idents.add(Decls.newFunction(Overloads.TimeGetMilliseconds, Decls.newInstanceOverload(Overloads.TimestampToMilliseconds, singletonList(Decls.Timestamp), Decls.Int), Decls.newInstanceOverload(Overloads.TimestampToMillisecondsWithTz, asList(Decls.Timestamp, Decls.String), Decls.Int), Decls.newInstanceOverload(Overloads.DurationToMilliseconds, singletonList(Decls.Duration), Decls.Int)));
    return unmodifiableList(idents);
}
Also used : Types.formatCheckedType(org.projectnessie.cel.checker.Types.formatCheckedType) Type(com.google.api.expr.v1alpha1.Type) ArrayList(java.util.ArrayList) Decl(com.google.api.expr.v1alpha1.Decl)

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