getAllFunctionNames() {
+ return stream(StandardFunction.values()).map(f -> f.functionName).collect(toImmutableSet());
+ }
+
+ /**
+ * Deprecated standard functions maintained for backward compatibility reasons.
+ *
+ * Note: Keep this package-private.
+ */
+ static ImmutableSet deprecatedFunctions() {
+ return DEPRECATED_STANDARD_FUNCTIONS;
+ }
+
+ /** Builder for constructing the set of standard function/identifiers. */
+ public static final class Builder {
+
+ private ImmutableSet includeFunctions;
+ private ImmutableSet excludeFunctions;
+ private FunctionFilter functionFilter;
+
+ private ImmutableSet includeIdentifiers;
+ private ImmutableSet excludeIdentifiers;
+ private IdentifierFilter identifierFilter;
+
+ @CanIgnoreReturnValue
+ public Builder excludeFunctions(StandardFunction... functions) {
+ return excludeFunctions(ImmutableSet.copyOf(functions));
+ }
+
+ @CanIgnoreReturnValue
+ public Builder excludeFunctions(Iterable functions) {
+ this.excludeFunctions = checkNotNull(ImmutableSet.copyOf(functions));
+ return this;
+ }
+
+ @CanIgnoreReturnValue
+ public Builder includeFunctions(StandardFunction... functions) {
+ return includeFunctions(ImmutableSet.copyOf(functions));
+ }
+
+ @CanIgnoreReturnValue
+ public Builder includeFunctions(Iterable functions) {
+ this.includeFunctions = checkNotNull(ImmutableSet.copyOf(functions));
+ return this;
+ }
+
+ @CanIgnoreReturnValue
+ public Builder filterFunctions(FunctionFilter functionFilter) {
+ this.functionFilter = functionFilter;
+ return this;
+ }
+
+ @CanIgnoreReturnValue
+ public Builder excludeIdentifiers(StandardIdentifier... identifiers) {
+ return excludeIdentifiers(ImmutableSet.copyOf(identifiers));
+ }
+
+ @CanIgnoreReturnValue
+ public Builder excludeIdentifiers(Iterable identifiers) {
+ this.excludeIdentifiers = checkNotNull(ImmutableSet.copyOf(identifiers));
+ return this;
+ }
+
+ @CanIgnoreReturnValue
+ public Builder includeIdentifiers(StandardIdentifier... identifiers) {
+ return includeIdentifiers(ImmutableSet.copyOf(identifiers));
+ }
+
+ @CanIgnoreReturnValue
+ public Builder includeIdentifiers(Iterable identifiers) {
+ this.includeIdentifiers = checkNotNull(ImmutableSet.copyOf(identifiers));
+ return this;
+ }
+
+ @CanIgnoreReturnValue
+ public Builder filterIdentifiers(IdentifierFilter identifierFilter) {
+ this.identifierFilter = identifierFilter;
+ return this;
+ }
+
+ private static void assertOneSettingIsSet(
+ boolean a, boolean b, boolean c, String errorMessage) {
+ int count = 0;
+ if (a) {
+ count++;
+ }
+ if (b) {
+ count++;
+ }
+ if (c) {
+ count++;
+ }
+
+ if (count > 1) {
+ throw new IllegalArgumentException(errorMessage);
+ }
+ }
+
+ CelStandardDeclarations build() {
+ boolean hasIncludeFunctions = !this.includeFunctions.isEmpty();
+ boolean hasExcludeFunctions = !this.excludeFunctions.isEmpty();
+ boolean hasFilterFunction = this.functionFilter != null;
+ assertOneSettingIsSet(
+ hasIncludeFunctions,
+ hasExcludeFunctions,
+ hasFilterFunction,
+ "You may only populate one of the following builder methods: includeFunctions,"
+ + " excludeFunctions or filterFunctions");
+ boolean hasIncludeIdentifiers = !this.includeIdentifiers.isEmpty();
+ boolean hasExcludeIdentifiers = !this.excludeIdentifiers.isEmpty();
+ boolean hasIdentifierFilter = this.identifierFilter != null;
+ assertOneSettingIsSet(
+ hasIncludeIdentifiers,
+ hasExcludeIdentifiers,
+ hasIdentifierFilter,
+ "You may only populate one of the following builder methods: includeIdentifiers,"
+ + " excludeIdentifiers or filterIdentifiers");
+
+ ImmutableSet.Builder functionDeclBuilder = ImmutableSet.builder();
+ for (StandardFunction standardFunction : StandardFunction.values()) {
+ if (hasIncludeFunctions) {
+ if (this.includeFunctions.contains(standardFunction)) {
+ functionDeclBuilder.add(standardFunction.celFunctionDecl);
+ }
+ continue;
+ }
+ if (hasExcludeFunctions) {
+ if (!this.excludeFunctions.contains(standardFunction)) {
+ functionDeclBuilder.add(standardFunction.celFunctionDecl);
+ }
+ continue;
+ }
+ if (hasFilterFunction) {
+ ImmutableSet.Builder overloadBuilder = ImmutableSet.builder();
+ for (StandardOverload standardOverload : standardFunction.standardOverloads) {
+ boolean includeOverload = functionFilter.include(standardFunction, standardOverload);
+ if (includeOverload) {
+ overloadBuilder.add(standardOverload);
+ }
+ }
+
+ ImmutableSet overloads = overloadBuilder.build();
+ if (!overloads.isEmpty()) {
+ functionDeclBuilder.add(standardFunction.withOverloads(overloadBuilder.build()));
+ }
+ continue;
+ }
+
+ functionDeclBuilder.add(standardFunction.celFunctionDecl);
+ }
+
+ ImmutableSet.Builder identBuilder = ImmutableSet.builder();
+ for (StandardIdentifier standardIdentifier : StandardIdentifier.values()) {
+ if (hasIncludeIdentifiers) {
+ if (this.includeIdentifiers.contains(standardIdentifier)) {
+ identBuilder.add(standardIdentifier.identDecl);
+ }
+ continue;
+ }
+
+ if (hasExcludeIdentifiers) {
+ if (!this.excludeIdentifiers.contains(standardIdentifier)) {
+ identBuilder.add(standardIdentifier.identDecl);
+ }
+ continue;
+ }
+
+ if (hasIdentifierFilter) {
+ boolean includeIdent = identifierFilter.include(standardIdentifier);
+ if (includeIdent) {
+ identBuilder.add(standardIdentifier.identDecl);
+ }
+ continue;
+ }
+
+ identBuilder.add(standardIdentifier.identDecl);
+ }
+
+ return new CelStandardDeclarations(functionDeclBuilder.build(), identBuilder.build());
+ }
+
+ private Builder() {
+ this.includeFunctions = ImmutableSet.of();
+ this.excludeFunctions = ImmutableSet.of();
+ this.includeIdentifiers = ImmutableSet.of();
+ this.excludeIdentifiers = ImmutableSet.of();
+ }
+
+ /**
+ * Functional interface for filtering standard functions. Returning true in the callback will
+ * include the function in the environment.
+ */
+ @FunctionalInterface
+ public interface FunctionFilter {
+ boolean include(StandardFunction standardFunction, StandardOverload standardOverload);
+ }
+
+ /**
+ * Functional interface for filtering standard identifiers. Returning true in the callback will
+ * include the identifier in the environment.
+ */
+ @FunctionalInterface
+ public interface IdentifierFilter {
+ boolean include(StandardIdentifier standardIdentifier);
+ }
+ }
+
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ ImmutableSet functionDecls() {
+ return celFunctionDecls;
+ }
+
+ ImmutableSet identifierDecls() {
+ return celIdentDecls;
+ }
+
+ private CelStandardDeclarations(
+ ImmutableSet celFunctionDecls, ImmutableSet celIdentDecls) {
+ this.celFunctionDecls = celFunctionDecls;
+ this.celIdentDecls = celIdentDecls;
+ }
+}
diff --git a/checker/src/main/java/dev/cel/checker/Env.java b/checker/src/main/java/dev/cel/checker/Env.java
index 613bef166..588b98c3e 100644
--- a/checker/src/main/java/dev/cel/checker/Env.java
+++ b/checker/src/main/java/dev/cel/checker/Env.java
@@ -27,6 +27,8 @@
import com.google.common.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.CheckReturnValue;
+import dev.cel.checker.CelStandardDeclarations.StandardFunction.Overload.Comparison;
+import dev.cel.checker.CelStandardDeclarations.StandardFunction.Overload.Conversions;
import dev.cel.common.CelFunctionDecl;
import dev.cel.common.CelOptions;
import dev.cel.common.CelOverloadDecl;
@@ -38,6 +40,7 @@
import dev.cel.common.ast.CelReference;
import dev.cel.common.internal.Errors;
import dev.cel.common.types.CelKind;
+import dev.cel.common.types.CelProtoTypes;
import dev.cel.common.types.CelType;
import dev.cel.common.types.CelTypes;
import dev.cel.common.types.SimpleType;
@@ -219,9 +222,53 @@ public static Env standard(Errors errors, CelOptions celOptions) {
* subsequent declarations with the same signature.
*/
public static Env standard(Errors errors, TypeProvider typeProvider, CelOptions celOptions) {
+ CelStandardDeclarations celStandardDeclaration =
+ CelStandardDeclarations.newBuilder()
+ .filterFunctions(
+ (function, overload) -> {
+ switch (function) {
+ case INT:
+ if (!celOptions.enableUnsignedLongs()
+ && overload.equals(Conversions.INT64_TO_INT64)) {
+ return false;
+ }
+ break;
+ case TIMESTAMP:
+ // TODO: Remove this flag guard once the feature has been
+ // auto-enabled.
+ if (!celOptions.enableTimestampEpoch()
+ && overload.equals(Conversions.INT64_TO_TIMESTAMP)) {
+ return false;
+ }
+ break;
+ default:
+ if (!celOptions.enableHeterogeneousNumericComparisons()
+ && overload instanceof Comparison) {
+ Comparison comparison = (Comparison) overload;
+ if (comparison.isHeterogeneousComparison()) {
+ return false;
+ }
+ }
+ break;
+ }
+ return true;
+ })
+ .build();
+
+ return standard(celStandardDeclaration, errors, typeProvider, celOptions);
+ }
+
+ public static Env standard(
+ CelStandardDeclarations celStandardDeclaration,
+ Errors errors,
+ TypeProvider typeProvider,
+ CelOptions celOptions) {
Env env = Env.unconfigured(errors, typeProvider, celOptions);
// Isolate the standard declarations into their own scope for forward compatibility.
- Standard.add(env);
+ CelStandardDeclarations.deprecatedFunctions().forEach(env::add);
+ celStandardDeclaration.functionDecls().forEach(env::add);
+ celStandardDeclaration.identifierDecls().forEach(env::add);
+
env.enterScope();
return env;
}
@@ -296,7 +343,7 @@ public Map getTypeMap() {
@Deprecated
public Type getType(Expr expr) {
Preconditions.checkNotNull(expr);
- return CelTypes.celTypeToType(getType(CelExprConverter.fromExpr(expr)));
+ return CelProtoTypes.celTypeToType(getType(CelExprConverter.fromExpr(expr)));
}
/**
@@ -349,7 +396,7 @@ public Env add(Decl decl) {
CelIdentDecl.Builder identBuilder =
CelIdentDecl.newBuilder()
.setName(decl.getName())
- .setType(CelTypes.typeToCelType(decl.getIdent().getType()))
+ .setType(CelProtoTypes.typeToCelType(decl.getIdent().getType()))
// Note: Setting doc and constant value exists for compatibility reason. This should
// not be set by the users.
.setDoc(decl.getIdent().getDoc());
@@ -394,7 +441,7 @@ public Env add(CelIdentDecl celIdentDecl) {
@CanIgnoreReturnValue
@Deprecated
public Env add(String name, Type type) {
- return add(CelIdentDecl.newIdentDeclaration(name, CelTypes.typeToCelType(type)));
+ return add(CelIdentDecl.newIdentDeclaration(name, CelProtoTypes.typeToCelType(type)));
}
/**
@@ -720,7 +767,7 @@ public IdentBuilder(String name) {
@CanIgnoreReturnValue
public IdentBuilder type(Type value) {
Preconditions.checkNotNull(value);
- builder.setType(CelTypes.typeToCelType(Preconditions.checkNotNull(value)));
+ builder.setType(CelProtoTypes.typeToCelType(Preconditions.checkNotNull(value)));
return this;
}
@@ -802,12 +849,12 @@ public FunctionBuilder add(String id, Type resultType, Type... argTypes) {
public FunctionBuilder add(String id, Type resultType, Iterable argTypes) {
ImmutableList.Builder argumentBuilder = new ImmutableList.Builder<>();
for (Type type : argTypes) {
- argumentBuilder.add(CelTypes.typeToCelType(type));
+ argumentBuilder.add(CelProtoTypes.typeToCelType(type));
}
this.overloads.add(
CelOverloadDecl.newBuilder()
.setOverloadId(id)
- .setResultType(CelTypes.typeToCelType(resultType))
+ .setResultType(CelProtoTypes.typeToCelType(resultType))
.addParameterTypes(argumentBuilder.build())
.setIsInstanceFunction(isInstance)
.build());
@@ -827,12 +874,12 @@ public FunctionBuilder add(
String id, List typeParams, Type resultType, Iterable argTypes) {
ImmutableList.Builder argumentBuilder = new ImmutableList.Builder<>();
for (Type type : argTypes) {
- argumentBuilder.add(CelTypes.typeToCelType(type));
+ argumentBuilder.add(CelProtoTypes.typeToCelType(type));
}
this.overloads.add(
CelOverloadDecl.newBuilder()
.setOverloadId(id)
- .setResultType(CelTypes.typeToCelType(resultType))
+ .setResultType(CelProtoTypes.typeToCelType(resultType))
.addParameterTypes(argumentBuilder.build())
.setIsInstanceFunction(isInstance)
.build());
diff --git a/checker/src/main/java/dev/cel/checker/ExprChecker.java b/checker/src/main/java/dev/cel/checker/ExprChecker.java
index f4f485e08..c39e4d00c 100644
--- a/checker/src/main/java/dev/cel/checker/ExprChecker.java
+++ b/checker/src/main/java/dev/cel/checker/ExprChecker.java
@@ -35,6 +35,7 @@
import dev.cel.common.ast.CelExpr;
import dev.cel.common.ast.CelReference;
import dev.cel.common.types.CelKind;
+import dev.cel.common.types.CelProtoTypes;
import dev.cel.common.types.CelType;
import dev.cel.common.types.CelTypes;
import dev.cel.common.types.ListType;
@@ -88,7 +89,7 @@ public static CheckedExpr typecheck(
Env env, String inContainer, ParsedExpr parsedExpr, Optional expectedResultType) {
Optional type =
expectedResultType.isPresent()
- ? Optional.of(CelTypes.typeToCelType(expectedResultType.get()))
+ ? Optional.of(CelProtoTypes.typeToCelType(expectedResultType.get()))
: Optional.absent();
CelAbstractSyntaxTree ast =
typecheck(
diff --git a/checker/src/main/java/dev/cel/checker/Standard.java b/checker/src/main/java/dev/cel/checker/Standard.java
deleted file mode 100644
index acdc185eb..000000000
--- a/checker/src/main/java/dev/cel/checker/Standard.java
+++ /dev/null
@@ -1,846 +0,0 @@
-// Copyright 2023 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package dev.cel.checker;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.errorprone.annotations.CanIgnoreReturnValue;
-import dev.cel.common.CelFunctionDecl;
-import dev.cel.common.CelOverloadDecl;
-import dev.cel.common.annotations.Internal;
-import dev.cel.common.types.CelType;
-import dev.cel.common.types.CelTypes;
-import dev.cel.common.types.ListType;
-import dev.cel.common.types.MapType;
-import dev.cel.common.types.SimpleType;
-import dev.cel.common.types.TypeParamType;
-import dev.cel.common.types.TypeType;
-import dev.cel.parser.Operator;
-
-/**
- * Standard declarations for CEL.
- *
- * CEL Library Internals. Do Not Use.
- */
-@Internal
-public final class Standard {
-
- private static final ImmutableList CORE_FUNCTION_DECLARATIONS =
- coreFunctionDeclarations();
- private static final ImmutableList CORE_IDENT_DECLARATIONS =
- coreIdentDeclarations();
-
- /** Enumeration of Standard Functions that are not present in {@link Operator}). */
- public enum Function {
- BOOL("bool"),
- BYTES("bytes"),
- CONTAINS("contains"),
- DOUBLE("double"),
- DURATION("duration"),
- DYN("dyn"),
- ENDS_WITH("endsWith"),
- GET_DATE("getDate"),
- GET_DAY_OF_MONTH("getDayOfMonth"),
- GET_DAY_OF_WEEK("getDayOfWeek"),
- GET_DAY_OF_YEAR("getDayOfYear"),
- GET_FULL_YEAR("getFullYear"),
- GET_HOURS("getHours"),
- GET_MILLISECONDS("getMilliseconds"),
- GET_MINUTES("getMinutes"),
- GET_MONTH("getMonth"),
- GET_SECONDS("getSeconds"),
- INT("int"),
- LIST("list"),
- MAP("map"),
- MATCHES("matches"),
- NULL_TYPE("null_type"),
- SIZE("size"),
- STARTS_WITH("startsWith"),
- STRING("string"),
- TIMESTAMP("timestamp"),
- TYPE("type"),
- UINT("uint");
-
- private final String functionName;
-
- public String getFunction() {
- return functionName;
- }
-
- Function(String functionName) {
- this.functionName = functionName;
- }
- }
-
- /**
- * Adds the standard declarations of CEL to the environment.
- *
- * Note: Standard declarations should be provided in their own scope to avoid collisions with
- * custom declarations. The {@link Env#standard} helper method does this by default.
- */
- @CanIgnoreReturnValue
- public static Env add(Env env) {
- CORE_FUNCTION_DECLARATIONS.forEach(env::add);
- CORE_IDENT_DECLARATIONS.forEach(env::add);
-
- // TODO: Remove this flag guard once the feature has been auto-enabled.
- timestampConversionDeclarations(env.enableTimestampEpoch()).forEach(env::add);
- numericComparisonDeclarations(env.enableHeterogeneousNumericComparisons()).forEach(env::add);
-
- if (env.enableUnsignedLongs()) {
- env.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.INT.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "int64_to_int64", "type conversion (identity)", SimpleType.INT, SimpleType.INT)));
- }
-
- return env;
- }
-
- /** Do the expensive work of setting up all the objects in the environment. */
- private static ImmutableList coreIdentDeclarations() {
- ImmutableList.Builder identDeclBuilder = ImmutableList.builder();
-
- // Type Denotations
- for (CelType type :
- ImmutableList.of(
- SimpleType.INT,
- SimpleType.UINT,
- SimpleType.BOOL,
- SimpleType.DOUBLE,
- SimpleType.BYTES,
- SimpleType.STRING,
- SimpleType.DYN)) {
- identDeclBuilder.add(
- CelIdentDecl.newBuilder()
- .setName(CelTypes.format(type))
- .setType(TypeType.create(type))
- .setDoc("type denotation")
- .build());
- }
- identDeclBuilder.add(
- CelIdentDecl.newBuilder()
- .setName("type")
- .setType(TypeType.create(SimpleType.DYN))
- .setDoc("type denotation")
- .build());
- identDeclBuilder.add(
- CelIdentDecl.newBuilder()
- .setName("null_type")
- .setType(TypeType.create(SimpleType.NULL_TYPE))
- .setDoc("type denotation")
- .build());
- identDeclBuilder.add(
- CelIdentDecl.newBuilder()
- .setName("list")
- .setType(TypeType.create(ListType.create(SimpleType.DYN)))
- .setDoc("type denotation")
- .build());
- identDeclBuilder.add(
- CelIdentDecl.newBuilder()
- .setName("map")
- .setType(TypeType.create(MapType.create(SimpleType.DYN, SimpleType.DYN)))
- .setDoc("type denotation")
- .build());
-
- return identDeclBuilder.build();
- }
-
- /** Do the expensive work of setting up all the objects in the environment. */
- private static ImmutableList coreFunctionDeclarations() {
- // Some shortcuts we use when building declarations.
- TypeParamType typeParamA = TypeParamType.create("A");
- ListType listOfA = ListType.create(typeParamA);
- TypeParamType typeParamB = TypeParamType.create("B");
- MapType mapOfAb = MapType.create(typeParamA, typeParamB);
-
- ImmutableList.Builder celFunctionDeclBuilder = ImmutableList.builder();
-
- // Booleans
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Operator.CONDITIONAL.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "conditional",
- "conditional",
- typeParamA,
- SimpleType.BOOL,
- typeParamA,
- typeParamA)));
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Operator.LOGICAL_AND.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "logical_and", "logical_and", SimpleType.BOOL, SimpleType.BOOL, SimpleType.BOOL)));
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Operator.LOGICAL_OR.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "logical_or", "logical or", SimpleType.BOOL, SimpleType.BOOL, SimpleType.BOOL)));
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Operator.LOGICAL_NOT.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "logical_not", "logical not", SimpleType.BOOL, SimpleType.BOOL)));
- CelFunctionDecl notStrictlyFalse =
- CelFunctionDecl.newFunctionDeclaration(
- Operator.OLD_NOT_STRICTLY_FALSE.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "not_strictly_false",
- "false if argument is false, true otherwise (including errors and unknowns)",
- SimpleType.BOOL,
- SimpleType.BOOL));
- celFunctionDeclBuilder.add(notStrictlyFalse);
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newBuilder()
- .setName(Operator.NOT_STRICTLY_FALSE.getFunction())
- .addOverloads(sameAs(notStrictlyFalse, "", ""))
- .build());
-
- // Relations
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Operator.EQUALS.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "equals", "equality", SimpleType.BOOL, typeParamA, typeParamA)));
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Operator.NOT_EQUALS.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "not_equals", "inequality", SimpleType.BOOL, typeParamA, typeParamA)));
-
- // Algebra
- CelFunctionDecl commonArithmetic =
- CelFunctionDecl.newFunctionDeclaration(
- Operator.SUBTRACT.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "common_int64", "arithmetic", SimpleType.INT, SimpleType.INT, SimpleType.INT),
- CelOverloadDecl.newGlobalOverload(
- "common_uint64", "arithmetic", SimpleType.UINT, SimpleType.UINT, SimpleType.UINT),
- CelOverloadDecl.newGlobalOverload(
- "common_double",
- "arithmetic",
- SimpleType.DOUBLE,
- SimpleType.DOUBLE,
- SimpleType.DOUBLE));
- CelFunctionDecl subtract =
- CelFunctionDecl.newBuilder()
- .setName(Operator.SUBTRACT.getFunction())
- .addOverloads(sameAs(commonArithmetic, "common", "subtract"))
- .addOverloads(
- CelOverloadDecl.newGlobalOverload(
- "subtract_timestamp_timestamp",
- "arithmetic",
- SimpleType.DURATION,
- SimpleType.TIMESTAMP,
- SimpleType.TIMESTAMP),
- CelOverloadDecl.newGlobalOverload(
- "subtract_timestamp_duration",
- "arithmetic",
- SimpleType.TIMESTAMP,
- SimpleType.TIMESTAMP,
- SimpleType.DURATION),
- CelOverloadDecl.newGlobalOverload(
- "subtract_duration_duration",
- "arithmetic",
- SimpleType.DURATION,
- SimpleType.DURATION,
- SimpleType.DURATION))
- .build();
- celFunctionDeclBuilder.add(subtract);
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newBuilder()
- .setName(Operator.MULTIPLY.getFunction())
- .addOverloads(sameAs(commonArithmetic, "common", "multiply"))
- .build());
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newBuilder()
- .setName(Operator.DIVIDE.getFunction())
- .addOverloads(sameAs(commonArithmetic, "common", "divide"))
- .build());
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Operator.MODULO.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "modulo_int64", "arithmetic", SimpleType.INT, SimpleType.INT, SimpleType.INT),
- CelOverloadDecl.newGlobalOverload(
- "modulo_uint64", "arithmetic", SimpleType.UINT, SimpleType.UINT, SimpleType.UINT)));
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newBuilder()
- .setName(Operator.ADD.getFunction())
- .addOverloads(sameAs(commonArithmetic, "common", "add"))
- .addOverloads(
- CelOverloadDecl.newGlobalOverload(
- "add_string",
- "string concatenation",
- SimpleType.STRING,
- SimpleType.STRING,
- SimpleType.STRING),
- CelOverloadDecl.newGlobalOverload(
- "add_bytes",
- "bytes concatenation",
- SimpleType.BYTES,
- SimpleType.BYTES,
- SimpleType.BYTES),
- CelOverloadDecl.newGlobalOverload(
- "add_list", "list concatenation", listOfA, listOfA, listOfA),
- CelOverloadDecl.newGlobalOverload(
- "add_timestamp_duration",
- "arithmetic",
- SimpleType.TIMESTAMP,
- SimpleType.TIMESTAMP,
- SimpleType.DURATION),
- CelOverloadDecl.newGlobalOverload(
- "add_duration_timestamp",
- "arithmetic",
- SimpleType.TIMESTAMP,
- SimpleType.DURATION,
- SimpleType.TIMESTAMP),
- CelOverloadDecl.newGlobalOverload(
- "add_duration_duration",
- "arithmetic",
- SimpleType.DURATION,
- SimpleType.DURATION,
- SimpleType.DURATION))
- .build());
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Operator.NEGATE.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "negate_int64", "negation", SimpleType.INT, SimpleType.INT),
- CelOverloadDecl.newGlobalOverload(
- "negate_double", "negation", SimpleType.DOUBLE, SimpleType.DOUBLE)));
-
- // Index
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Operator.INDEX.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "index_list", "list indexing", typeParamA, listOfA, SimpleType.INT),
- CelOverloadDecl.newGlobalOverload(
- "index_map", "map indexing", typeParamB, mapOfAb, typeParamA)));
-
- // Collections
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- "size",
- CelOverloadDecl.newGlobalOverload(
- "size_string", "string length", SimpleType.INT, SimpleType.STRING),
- CelOverloadDecl.newGlobalOverload(
- "size_bytes", "bytes length", SimpleType.INT, SimpleType.BYTES),
- CelOverloadDecl.newGlobalOverload("size_list", "list size", SimpleType.INT, listOfA),
- CelOverloadDecl.newGlobalOverload("size_map", "map size", SimpleType.INT, mapOfAb),
- CelOverloadDecl.newMemberOverload(
- "string_size", "string length", SimpleType.INT, SimpleType.STRING),
- CelOverloadDecl.newMemberOverload(
- "bytes_size", "bytes length", SimpleType.INT, SimpleType.BYTES),
- CelOverloadDecl.newMemberOverload("list_size", "list size", SimpleType.INT, listOfA),
- CelOverloadDecl.newMemberOverload("map_size", "map size", SimpleType.INT, mapOfAb)));
-
- // Set membership 'in' operator.
- CelFunctionDecl inOperator =
- CelFunctionDecl.newFunctionDeclaration(
- Operator.OLD_IN.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "in_list", "list membership", SimpleType.BOOL, typeParamA, listOfA),
- CelOverloadDecl.newGlobalOverload(
- "in_map", "map key membership", SimpleType.BOOL, typeParamA, mapOfAb));
- celFunctionDeclBuilder.add(inOperator);
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newBuilder()
- .setName(Operator.IN.getFunction())
- .addOverloads(sameAs(inOperator, "", ""))
- .build());
-
- // Conversions to type
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.TYPE.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "type", "returns type of value", TypeType.create(typeParamA), typeParamA)));
-
- // Conversions to int
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.INT.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "uint64_to_int64", "type conversion", SimpleType.INT, SimpleType.UINT),
- CelOverloadDecl.newGlobalOverload(
- "double_to_int64", "type conversion", SimpleType.INT, SimpleType.DOUBLE),
- CelOverloadDecl.newGlobalOverload(
- "string_to_int64", "type conversion", SimpleType.INT, SimpleType.STRING),
- CelOverloadDecl.newGlobalOverload(
- "timestamp_to_int64",
- "Convert timestamp to int64 in seconds since Unix epoch.",
- SimpleType.INT,
- SimpleType.TIMESTAMP)));
-
- // Conversions to uint
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.UINT.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "uint64_to_uint64", "type conversion (identity)", SimpleType.UINT, SimpleType.UINT),
- CelOverloadDecl.newGlobalOverload(
- "int64_to_uint64", "type conversion", SimpleType.UINT, SimpleType.INT),
- CelOverloadDecl.newGlobalOverload(
- "double_to_uint64", "type conversion", SimpleType.UINT, SimpleType.DOUBLE),
- CelOverloadDecl.newGlobalOverload(
- "string_to_uint64", "type conversion", SimpleType.UINT, SimpleType.STRING)));
-
- // Conversions to double
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.DOUBLE.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "double_to_double",
- "type conversion (identity)",
- SimpleType.DOUBLE,
- SimpleType.DOUBLE),
- CelOverloadDecl.newGlobalOverload(
- "int64_to_double", "type conversion", SimpleType.DOUBLE, SimpleType.INT),
- CelOverloadDecl.newGlobalOverload(
- "uint64_to_double", "type conversion", SimpleType.DOUBLE, SimpleType.UINT),
- CelOverloadDecl.newGlobalOverload(
- "string_to_double", "type conversion", SimpleType.DOUBLE, SimpleType.STRING)));
-
- // Conversions to string
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.STRING.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "string_to_string",
- "type conversion (identity)",
- SimpleType.STRING,
- SimpleType.STRING),
- CelOverloadDecl.newGlobalOverload(
- "int64_to_string", "type conversion", SimpleType.STRING, SimpleType.INT),
- CelOverloadDecl.newGlobalOverload(
- "uint64_to_string", "type conversion", SimpleType.STRING, SimpleType.UINT),
- CelOverloadDecl.newGlobalOverload(
- "double_to_string", "type conversion", SimpleType.STRING, SimpleType.DOUBLE),
- CelOverloadDecl.newGlobalOverload(
- "bytes_to_string", "type conversion", SimpleType.STRING, SimpleType.BYTES),
- CelOverloadDecl.newGlobalOverload(
- "timestamp_to_string", "type_conversion", SimpleType.STRING, SimpleType.TIMESTAMP),
- CelOverloadDecl.newGlobalOverload(
- "duration_to_string", "type_conversion", SimpleType.STRING, SimpleType.DURATION)));
-
- // Conversions to bytes
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.BYTES.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "bytes_to_bytes", "type conversion (identity)", SimpleType.BYTES, SimpleType.BYTES),
- CelOverloadDecl.newGlobalOverload(
- "string_to_bytes", "type conversion", SimpleType.BYTES, SimpleType.STRING)));
-
- // Conversions to dyn
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.DYN.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "to_dyn", "type conversion", SimpleType.DYN, typeParamA)));
-
- // Conversions to Duration
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.DURATION.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "duration_to_duration",
- "type conversion (identity)",
- SimpleType.DURATION,
- SimpleType.DURATION),
- CelOverloadDecl.newGlobalOverload(
- "string_to_duration",
- "type conversion, duration should be end with \"s\", which stands for seconds",
- SimpleType.DURATION,
- SimpleType.STRING)));
-
- // Conversions to boolean
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.BOOL.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "bool_to_bool", "type conversion (identity)", SimpleType.BOOL, SimpleType.BOOL),
- CelOverloadDecl.newGlobalOverload(
- "string_to_bool", "type conversion", SimpleType.BOOL, SimpleType.STRING)));
-
- // String functions
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.MATCHES.getFunction(),
- CelOverloadDecl.newGlobalOverload(
- "matches",
- "matches first argument against regular expression in second argument",
- SimpleType.BOOL,
- SimpleType.STRING,
- SimpleType.STRING)));
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.MATCHES.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "matches_string",
- "matches the self argument against regular expression in first argument",
- SimpleType.BOOL,
- SimpleType.STRING,
- SimpleType.STRING)));
-
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.CONTAINS.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "contains_string",
- "tests whether the string operand contains the substring",
- SimpleType.BOOL,
- SimpleType.STRING,
- SimpleType.STRING)));
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.ENDS_WITH.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "ends_with_string",
- "tests whether the string operand ends with the suffix argument",
- SimpleType.BOOL,
- SimpleType.STRING,
- SimpleType.STRING)));
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.STARTS_WITH.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "starts_with_string",
- "tests whether the string operand starts with the prefix argument",
- SimpleType.BOOL,
- SimpleType.STRING,
- SimpleType.STRING)));
-
- // Date/time functions
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.GET_FULL_YEAR.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_year",
- "get year from the date in UTC",
- SimpleType.INT,
- SimpleType.TIMESTAMP),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_year_with_tz",
- "get year from the date with timezone",
- SimpleType.INT,
- SimpleType.TIMESTAMP,
- SimpleType.STRING)));
-
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.GET_MONTH.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_month",
- "get month from the date in UTC, 0-11",
- SimpleType.INT,
- SimpleType.TIMESTAMP),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_month_with_tz",
- "get month from the date with timezone, 0-11",
- SimpleType.INT,
- SimpleType.TIMESTAMP,
- SimpleType.STRING)));
-
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.GET_DAY_OF_YEAR.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_day_of_year",
- "get day of year from the date in UTC, zero-based indexing",
- SimpleType.INT,
- SimpleType.TIMESTAMP),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_day_of_year_with_tz",
- "get day of year from the date with timezone, zero-based indexing",
- SimpleType.INT,
- SimpleType.TIMESTAMP,
- SimpleType.STRING)));
-
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.GET_DAY_OF_MONTH.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_day_of_month",
- "get day of month from the date in UTC, zero-based indexing",
- SimpleType.INT,
- SimpleType.TIMESTAMP),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_day_of_month_with_tz",
- "get day of month from the date with timezone, zero-based indexing",
- SimpleType.INT,
- SimpleType.TIMESTAMP,
- SimpleType.STRING)));
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.GET_DATE.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_day_of_month_1_based",
- "get day of month from the date in UTC, one-based indexing",
- SimpleType.INT,
- SimpleType.TIMESTAMP),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_day_of_month_1_based_with_tz",
- "get day of month from the date with timezone, one-based indexing",
- SimpleType.INT,
- SimpleType.TIMESTAMP,
- SimpleType.STRING)));
-
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.GET_DAY_OF_WEEK.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_day_of_week",
- "get day of week from the date in UTC, zero-based, zero for Sunday",
- SimpleType.INT,
- SimpleType.TIMESTAMP),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_day_of_week_with_tz",
- "get day of week from the date with timezone, zero-based, zero for Sunday",
- SimpleType.INT,
- SimpleType.TIMESTAMP,
- SimpleType.STRING)));
-
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.GET_HOURS.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_hours",
- "get hours from the date in UTC, 0-23",
- SimpleType.INT,
- SimpleType.TIMESTAMP),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_hours_with_tz",
- "get hours from the date with timezone, 0-23",
- SimpleType.INT,
- SimpleType.TIMESTAMP,
- SimpleType.STRING),
- CelOverloadDecl.newMemberOverload(
- "duration_to_hours",
- "get hours from duration",
- SimpleType.INT,
- SimpleType.DURATION)));
-
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.GET_MINUTES.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_minutes",
- "get minutes from the date in UTC, 0-59",
- SimpleType.INT,
- SimpleType.TIMESTAMP),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_minutes_with_tz",
- "get minutes from the date with timezone, 0-59",
- SimpleType.INT,
- SimpleType.TIMESTAMP,
- SimpleType.STRING),
- CelOverloadDecl.newMemberOverload(
- "duration_to_minutes",
- "get minutes from duration",
- SimpleType.INT,
- SimpleType.DURATION)));
-
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.GET_SECONDS.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_seconds",
- "get seconds from the date in UTC, 0-59",
- SimpleType.INT,
- SimpleType.TIMESTAMP),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_seconds_with_tz",
- "get seconds from the date with timezone, 0-59",
- SimpleType.INT,
- SimpleType.TIMESTAMP,
- SimpleType.STRING),
- CelOverloadDecl.newMemberOverload(
- "duration_to_seconds",
- "get seconds from duration",
- SimpleType.INT,
- SimpleType.DURATION)));
-
- celFunctionDeclBuilder.add(
- CelFunctionDecl.newFunctionDeclaration(
- Function.GET_MILLISECONDS.getFunction(),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_milliseconds",
- "get milliseconds from the date in UTC, 0-999",
- SimpleType.INT,
- SimpleType.TIMESTAMP),
- CelOverloadDecl.newMemberOverload(
- "timestamp_to_milliseconds_with_tz",
- "get milliseconds from the date with timezone, 0-999",
- SimpleType.INT,
- SimpleType.TIMESTAMP,
- SimpleType.STRING),
- CelOverloadDecl.newMemberOverload(
- "duration_to_milliseconds",
- "milliseconds from duration, 0-999",
- SimpleType.INT,
- SimpleType.DURATION)));
-
- return celFunctionDeclBuilder.build();
- }
-
- private static ImmutableList timestampConversionDeclarations(boolean withEpoch) {
- CelFunctionDecl.Builder timestampBuilder =
- CelFunctionDecl.newBuilder()
- .setName("timestamp")
- .addOverloads(
- CelOverloadDecl.newGlobalOverload(
- "string_to_timestamp",
- "Type conversion of strings to timestamps according to RFC3339. Example:"
- + " \"1972-01-01T10:00:20.021-05:00\".",
- SimpleType.TIMESTAMP,
- SimpleType.STRING),
- CelOverloadDecl.newGlobalOverload(
- "timestamp_to_timestamp",
- "type conversion (identity)",
- SimpleType.TIMESTAMP,
- SimpleType.TIMESTAMP));
- if (withEpoch) {
- timestampBuilder.addOverloads(
- CelOverloadDecl.newGlobalOverload(
- "int64_to_timestamp",
- "Type conversion of integers as Unix epoch seconds to timestamps.",
- SimpleType.TIMESTAMP,
- SimpleType.INT));
- }
- return ImmutableList.of(timestampBuilder.build());
- }
-
- private static ImmutableList numericComparisonDeclarations(
- boolean withHeterogeneousComparisons) {
- CelFunctionDecl.Builder lessBuilder =
- CelFunctionDecl.newBuilder()
- .setName(Operator.LESS.getFunction())
- .addOverloads(
- CelOverloadDecl.newGlobalOverload(
- "less_bool", "ordering", SimpleType.BOOL, SimpleType.BOOL, SimpleType.BOOL),
- CelOverloadDecl.newGlobalOverload(
- "less_int64", "ordering", SimpleType.BOOL, SimpleType.INT, SimpleType.INT),
- CelOverloadDecl.newGlobalOverload(
- "less_uint64", "ordering", SimpleType.BOOL, SimpleType.UINT, SimpleType.UINT),
- CelOverloadDecl.newGlobalOverload(
- "less_double",
- "ordering",
- SimpleType.BOOL,
- SimpleType.DOUBLE,
- SimpleType.DOUBLE),
- CelOverloadDecl.newGlobalOverload(
- "less_string",
- "ordering",
- SimpleType.BOOL,
- SimpleType.STRING,
- SimpleType.STRING),
- CelOverloadDecl.newGlobalOverload(
- "less_bytes", "ordering", SimpleType.BOOL, SimpleType.BYTES, SimpleType.BYTES),
- CelOverloadDecl.newGlobalOverload(
- "less_timestamp",
- "ordering",
- SimpleType.BOOL,
- SimpleType.TIMESTAMP,
- SimpleType.TIMESTAMP),
- CelOverloadDecl.newGlobalOverload(
- "less_duration",
- "ordering",
- SimpleType.BOOL,
- SimpleType.DURATION,
- SimpleType.DURATION));
-
- if (withHeterogeneousComparisons) {
- lessBuilder.addOverloads(
- CelOverloadDecl.newGlobalOverload(
- "less_int64_uint64",
- "Compare a signed integer value to an unsigned integer value",
- SimpleType.BOOL,
- SimpleType.INT,
- SimpleType.UINT),
- CelOverloadDecl.newGlobalOverload(
- "less_uint64_int64",
- "Compare an unsigned integer value to a signed integer value",
- SimpleType.BOOL,
- SimpleType.UINT,
- SimpleType.INT),
- CelOverloadDecl.newGlobalOverload(
- "less_int64_double",
- "Compare a signed integer value to a double value, coalesces the integer to a double",
- SimpleType.BOOL,
- SimpleType.INT,
- SimpleType.DOUBLE),
- CelOverloadDecl.newGlobalOverload(
- "less_double_int64",
- "Compare a double value to a signed integer value, coalesces the integer to a double",
- SimpleType.BOOL,
- SimpleType.DOUBLE,
- SimpleType.INT),
- CelOverloadDecl.newGlobalOverload(
- "less_uint64_double",
- "Compare an unsigned integer value to a double value, coalesces the unsigned integer"
- + " to a double",
- SimpleType.BOOL,
- SimpleType.UINT,
- SimpleType.DOUBLE),
- CelOverloadDecl.newGlobalOverload(
- "less_double_uint64",
- "Compare a double value to an unsigned integer value, coalesces the unsigned integer"
- + " to a double",
- SimpleType.BOOL,
- SimpleType.DOUBLE,
- SimpleType.UINT));
- }
-
- CelFunctionDecl less = lessBuilder.build();
- return ImmutableList.of(
- less,
- CelFunctionDecl.newBuilder()
- .setName(Operator.LESS_EQUALS.getFunction())
- .addOverloads(sameAs(less, "less", "less_equals"))
- .build(),
- CelFunctionDecl.newBuilder()
- .setName(Operator.GREATER.getFunction())
- .addOverloads(sameAs(less, "less", "greater"))
- .build(),
- CelFunctionDecl.newBuilder()
- .setName(Operator.GREATER_EQUALS.getFunction())
- .addOverloads(sameAs(less, "less", "greater_equals"))
- .build());
- }
-
- /**
- * Add the overloads of another function to this function, after replacing the overload id as
- * specified.
- */
- private static ImmutableList sameAs(
- CelFunctionDecl func, String idPart, String idPartReplace) {
- ImmutableList.Builder overloads = new ImmutableList.Builder<>();
- Preconditions.checkNotNull(func);
- for (CelOverloadDecl overload : func.overloads()) {
- overloads.add(
- overload.toBuilder()
- .setOverloadId(overload.overloadId().replace(idPart, idPartReplace))
- .build());
- }
- return overloads.build();
- }
-
- private Standard() {}
-}
diff --git a/checker/src/main/java/dev/cel/checker/TypeProvider.java b/checker/src/main/java/dev/cel/checker/TypeProvider.java
index 10ce2a7d6..2dd5261ab 100644
--- a/checker/src/main/java/dev/cel/checker/TypeProvider.java
+++ b/checker/src/main/java/dev/cel/checker/TypeProvider.java
@@ -18,8 +18,8 @@
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import dev.cel.common.types.CelProtoTypes;
import dev.cel.common.types.CelType;
-import dev.cel.common.types.CelTypes;
import java.util.Optional;
import java.util.function.Function;
import org.jspecify.annotations.Nullable;
@@ -38,7 +38,7 @@ public interface TypeProvider {
/** Lookup the a {@link CelType} given a qualified {@code typeName}. Returns null if not found. */
default Optional lookupCelType(String typeName) {
Type type = lookupType(typeName);
- return Optional.ofNullable(type).map(CelTypes::typeToCelType);
+ return Optional.ofNullable(type).map(CelProtoTypes::typeToCelType);
}
/** Lookup the {@code Integer} enum value given an {@code enumName}. Returns null if not found. */
@@ -61,7 +61,7 @@ default Optional lookupCelType(String typeName) {
* check is supported via the ('has') macro.
*/
default @Nullable FieldType lookupFieldType(CelType type, String fieldName) {
- return lookupFieldType(CelTypes.celTypeToType(type), fieldName);
+ return lookupFieldType(CelProtoTypes.celTypeToType(type), fieldName);
}
/**
@@ -89,7 +89,7 @@ public abstract class FieldType {
public abstract Type type();
public CelType celType() {
- return CelTypes.typeToCelType(type());
+ return CelProtoTypes.typeToCelType(type());
}
/** Create a new {@code FieldType} instance from the provided {@code type}. */
diff --git a/checker/src/main/java/dev/cel/checker/TypeProviderLegacyImpl.java b/checker/src/main/java/dev/cel/checker/TypeProviderLegacyImpl.java
index 4d1e0ea32..b2ac51d95 100644
--- a/checker/src/main/java/dev/cel/checker/TypeProviderLegacyImpl.java
+++ b/checker/src/main/java/dev/cel/checker/TypeProviderLegacyImpl.java
@@ -18,9 +18,9 @@
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.CheckReturnValue;
import dev.cel.common.annotations.Internal;
+import dev.cel.common.types.CelProtoTypes;
import dev.cel.common.types.CelType;
import dev.cel.common.types.CelTypeProvider;
-import dev.cel.common.types.CelTypes;
import dev.cel.common.types.EnumType;
import dev.cel.common.types.ProtoMessageType;
import dev.cel.common.types.StructType;
@@ -45,7 +45,7 @@ final class TypeProviderLegacyImpl implements TypeProvider {
@Override
public @Nullable Type lookupType(String typeName) {
- return lookupCelType(typeName).map(CelTypes::celTypeToType).orElse(null);
+ return lookupCelType(typeName).map(CelProtoTypes::celTypeToType).orElse(null);
}
@Override
@@ -65,13 +65,13 @@ public Optional lookupCelType(String typeName) {
return structType
.findField(fieldName)
- .map(f -> FieldType.of(CelTypes.celTypeToType(f.type())))
+ .map(f -> FieldType.of(CelProtoTypes.celTypeToType(f.type())))
.orElse(null);
}
@Override
public @Nullable FieldType lookupFieldType(Type type, String fieldName) {
- return lookupFieldType(CelTypes.typeToCelType(type), fieldName);
+ return lookupFieldType(CelProtoTypes.typeToCelType(type), fieldName);
}
@Override
@@ -114,7 +114,8 @@ public Optional lookupCelType(String typeName) {
.map(
et ->
ExtensionFieldType.of(
- CelTypes.celTypeToType(et.type()), CelTypes.celTypeToType(et.messageType())))
+ CelProtoTypes.celTypeToType(et.type()),
+ CelProtoTypes.celTypeToType(et.messageType())))
.orElse(null);
}
}
diff --git a/checker/src/main/java/dev/cel/checker/Types.java b/checker/src/main/java/dev/cel/checker/Types.java
index 7f249fc92..62a3b66e9 100644
--- a/checker/src/main/java/dev/cel/checker/Types.java
+++ b/checker/src/main/java/dev/cel/checker/Types.java
@@ -26,8 +26,8 @@
import com.google.protobuf.NullValue;
import dev.cel.common.annotations.Internal;
import dev.cel.common.types.CelKind;
+import dev.cel.common.types.CelProtoTypes;
import dev.cel.common.types.CelType;
-import dev.cel.common.types.CelTypes;
import dev.cel.common.types.ListType;
import dev.cel.common.types.MapType;
import dev.cel.common.types.NullableType;
@@ -177,7 +177,7 @@ public static Type createWrapper(Type type) {
*/
@Deprecated
public static boolean isDynOrError(Type type) {
- return isDynOrError(CelTypes.typeToCelType(type));
+ return isDynOrError(CelProtoTypes.typeToCelType(type));
}
/** Tests whether the type has error or dyn kind. Both have the property to match any type. */
@@ -238,18 +238,18 @@ public static CelType mostGeneral(CelType type1, CelType type2) {
subs.entrySet().stream()
.collect(
Collectors.toMap(
- k -> CelTypes.typeToCelType(k.getKey()),
- v -> CelTypes.typeToCelType(v.getValue()),
+ k -> CelProtoTypes.typeToCelType(k.getKey()),
+ v -> CelProtoTypes.typeToCelType(v.getValue()),
(prev, next) -> next,
HashMap::new));
if (internalIsAssignable(
- subsCopy, CelTypes.typeToCelType(type1), CelTypes.typeToCelType(type2))) {
+ subsCopy, CelProtoTypes.typeToCelType(type1), CelProtoTypes.typeToCelType(type2))) {
return subsCopy.entrySet().stream()
.collect(
Collectors.toMap(
- k -> CelTypes.celTypeToType(k.getKey()),
- v -> CelTypes.celTypeToType(v.getValue()),
+ k -> CelProtoTypes.celTypeToType(k.getKey()),
+ v -> CelProtoTypes.celTypeToType(v.getValue()),
(prev, next) -> next,
HashMap::new));
}
@@ -384,7 +384,8 @@ private static boolean isAssignableFromNull(CelType targetType) {
*/
@Deprecated
public static boolean isEqualOrLessSpecific(Type type1, Type type2) {
- return isEqualOrLessSpecific(CelTypes.typeToCelType(type1), CelTypes.typeToCelType(type2));
+ return isEqualOrLessSpecific(
+ CelProtoTypes.typeToCelType(type1), CelProtoTypes.typeToCelType(type2));
}
/**
@@ -426,7 +427,7 @@ public static boolean isEqualOrLessSpecific(CelType type1, CelType type2) {
TypeType typeType2 = (TypeType) type2;
return isEqualOrLessSpecific(typeType1.type(), typeType2.type());
- // Message, primitive, well-known, and wrapper type names must be equal to be equivalent.
+ // Message, primitive, well-known, and wrapper type names must be equal to be equivalent.
default:
return type1.equals(type2);
}
@@ -493,10 +494,11 @@ private static boolean notReferencedIn(
public static Type substitute(Map subs, Type type, boolean typeParamToDyn) {
ImmutableMap.Builder subsMap = ImmutableMap.builder();
for (Map.Entry sub : subs.entrySet()) {
- subsMap.put(CelTypes.typeToCelType(sub.getKey()), CelTypes.typeToCelType(sub.getValue()));
+ subsMap.put(
+ CelProtoTypes.typeToCelType(sub.getKey()), CelProtoTypes.typeToCelType(sub.getValue()));
}
- return CelTypes.celTypeToType(
- substitute(subsMap.buildOrThrow(), CelTypes.typeToCelType(type), typeParamToDyn));
+ return CelProtoTypes.celTypeToType(
+ substitute(subsMap.buildOrThrow(), CelProtoTypes.typeToCelType(type), typeParamToDyn));
}
/**
diff --git a/checker/src/test/java/dev/cel/checker/BUILD.bazel b/checker/src/test/java/dev/cel/checker/BUILD.bazel
index e3e410429..51daf6cbf 100644
--- a/checker/src/test/java/dev/cel/checker/BUILD.bazel
+++ b/checker/src/test/java/dev/cel/checker/BUILD.bazel
@@ -11,7 +11,6 @@ java_library(
srcs = glob(["*Test.java"]),
resources = ["//checker/src/test/resources:baselines"],
deps = [
- "@maven//:com_google_protobuf_protobuf_java",
# "//java/com/google/testing/testsize:annotations",
"//:auto_value",
"//checker",
@@ -20,17 +19,19 @@ java_library(
"//checker:checker_legacy_environment",
"//checker:proto_expr_visitor",
"//checker:proto_type_mask",
+ "//checker:standard_decl",
"//checker:type_inferencer",
"//checker:type_provider_legacy_impl",
"//common",
"//common:compiler_common",
+ "//common:options",
"//common:proto_ast",
"//common/ast",
"//common/internal:env_visitor",
"//common/internal:errors",
"//common/resources/testdata/proto3:standalone_global_enum_java_proto",
"//common/types",
- "//common/types:cel_types",
+ "//common/types:cel_proto_types",
"//common/types:json",
"//common/types:message_type_provider",
"//common/types:type_providers",
@@ -40,16 +41,16 @@ java_library(
"//parser:operator",
"//testing:adorner",
"//testing:cel_baseline_test_case",
- "@maven//:com_google_errorprone_error_prone_annotations",
- "@maven//:org_jspecify_jspecify",
"@maven//:junit_junit",
+ "@maven//:com_google_testparameterinjector_test_parameter_injector",
"//:java_truth",
"@maven//:com_google_truth_extensions_truth_proto_extension",
"@cel_spec//proto/cel/expr:expr_java_proto",
- "@cel_spec//proto/test/v1/proto2:test_all_types_java_proto",
- "@cel_spec//proto/test/v1/proto3:test_all_types_java_proto",
+ "@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
+ "@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",
"@com_google_googleapis//google/rpc/context:attribute_context_java_proto",
"@maven//:com_google_guava_guava",
+ "@maven//:com_google_protobuf_protobuf_java",
],
)
diff --git a/checker/src/test/java/dev/cel/checker/CelCheckerLegacyImplTest.java b/checker/src/test/java/dev/cel/checker/CelCheckerLegacyImplTest.java
index 4e0c15576..a19770c6a 100644
--- a/checker/src/test/java/dev/cel/checker/CelCheckerLegacyImplTest.java
+++ b/checker/src/test/java/dev/cel/checker/CelCheckerLegacyImplTest.java
@@ -16,12 +16,12 @@
import static com.google.common.truth.Truth.assertThat;
-import com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes;
import dev.cel.common.CelFunctionDecl;
import dev.cel.common.CelOverloadDecl;
import dev.cel.common.CelVarDecl;
import dev.cel.common.types.SimpleType;
import dev.cel.compiler.CelCompilerFactory;
+import dev.cel.expr.conformance.proto3.TestAllTypes;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -63,7 +63,7 @@ public void toCheckerBuilder_collectionProperties_copied() {
.addMessageTypes(TestAllTypes.getDescriptor())
.addFileTypes(TestAllTypes.getDescriptor().getFile())
.addProtoTypeMasks(
- ProtoTypeMask.ofAllFields("google.api.expr.test.v1.proto3.TestAllTypes"))
+ ProtoTypeMask.ofAllFields("cel.expr.conformance.proto3.TestAllTypes"))
.addLibraries(new CelCheckerLibrary() {});
CelCheckerLegacyImpl celChecker = (CelCheckerLegacyImpl) celCheckerBuilder.build();
@@ -93,7 +93,7 @@ public void toCheckerBuilder_collectionProperties_areImmutable() {
celCheckerBuilder.addMessageTypes(TestAllTypes.getDescriptor());
celCheckerBuilder.addFileTypes(TestAllTypes.getDescriptor().getFile());
celCheckerBuilder.addProtoTypeMasks(
- ProtoTypeMask.ofAllFields("google.api.expr.test.v1.proto3.TestAllTypes"));
+ ProtoTypeMask.ofAllFields("cel.expr.conformance.proto3.TestAllTypes"));
celCheckerBuilder.addLibraries(new CelCheckerLibrary() {});
assertThat(newCheckerBuilder.getFunctionDecls().build()).isEmpty();
diff --git a/checker/src/test/java/dev/cel/checker/CelOverloadDeclTest.java b/checker/src/test/java/dev/cel/checker/CelOverloadDeclTest.java
index f78a4fa62..0dd7d83df 100644
--- a/checker/src/test/java/dev/cel/checker/CelOverloadDeclTest.java
+++ b/checker/src/test/java/dev/cel/checker/CelOverloadDeclTest.java
@@ -22,7 +22,7 @@
import dev.cel.expr.Decl.FunctionDecl.Overload;
import com.google.common.collect.ImmutableList;
import dev.cel.common.CelOverloadDecl;
-import dev.cel.common.types.CelTypes;
+import dev.cel.common.types.CelProtoTypes;
import dev.cel.common.types.SimpleType;
import dev.cel.common.types.TypeParamType;
import org.junit.Test;
@@ -81,9 +81,10 @@ public void toProtoOverload_withTypeParams() {
Overload protoOverload = CelOverloadDecl.celOverloadToOverload(celOverloadDecl);
assertThat(protoOverload.getOverloadId()).isEqualTo("overloadId");
assertThat(protoOverload.getIsInstanceFunction()).isTrue();
- assertThat(protoOverload.getResultType()).isEqualTo(CelTypes.createTypeParam("A"));
+ assertThat(protoOverload.getResultType()).isEqualTo(CelProtoTypes.createTypeParam("A"));
assertThat(protoOverload.getParamsList())
- .containsExactly(CelTypes.STRING, CelTypes.DOUBLE, CelTypes.createTypeParam("B"));
+ .containsExactly(
+ CelProtoTypes.STRING, CelProtoTypes.DOUBLE, CelProtoTypes.createTypeParam("B"));
assertThat(protoOverload.getTypeParamsList()).containsExactly("A", "B");
}
diff --git a/checker/src/test/java/dev/cel/checker/CelProtoExprVisitorTest.java b/checker/src/test/java/dev/cel/checker/CelProtoExprVisitorTest.java
index 3b598d4c7..37e734853 100644
--- a/checker/src/test/java/dev/cel/checker/CelProtoExprVisitorTest.java
+++ b/checker/src/test/java/dev/cel/checker/CelProtoExprVisitorTest.java
@@ -19,12 +19,12 @@
import dev.cel.expr.Constant;
import dev.cel.expr.Expr;
-import com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes;
import com.google.auto.value.AutoValue;
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.types.SimpleType;
import dev.cel.compiler.CelCompiler;
import dev.cel.compiler.CelCompilerFactory;
+import dev.cel.expr.conformance.proto3.TestAllTypes;
import dev.cel.parser.CelStandardMacro;
import dev.cel.parser.Operator;
import java.util.Optional;
diff --git a/checker/src/test/java/dev/cel/checker/CelStandardDeclarationsTest.java b/checker/src/test/java/dev/cel/checker/CelStandardDeclarationsTest.java
new file mode 100644
index 000000000..17a7212a1
--- /dev/null
+++ b/checker/src/test/java/dev/cel/checker/CelStandardDeclarationsTest.java
@@ -0,0 +1,275 @@
+// Copyright 2024 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package dev.cel.checker;
+
+import static com.google.common.truth.Truth.assertThat;
+import static dev.cel.common.CelFunctionDecl.newFunctionDeclaration;
+import static org.junit.Assert.assertThrows;
+
+import com.google.testing.junit.testparameterinjector.TestParameterInjector;
+import com.google.testing.junit.testparameterinjector.TestParameters;
+import dev.cel.checker.CelStandardDeclarations.StandardFunction;
+import dev.cel.checker.CelStandardDeclarations.StandardFunction.Overload.Arithmetic;
+import dev.cel.checker.CelStandardDeclarations.StandardIdentifier;
+import dev.cel.common.CelOptions;
+import dev.cel.common.CelValidationException;
+import dev.cel.compiler.CelCompiler;
+import dev.cel.compiler.CelCompilerFactory;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(TestParameterInjector.class)
+public class CelStandardDeclarationsTest {
+
+ @Test
+ @TestParameters("{includeFunction: true, excludeFunction: true, filterFunction: true}")
+ @TestParameters("{includeFunction: true, excludeFunction: true, filterFunction: false}")
+ @TestParameters("{includeFunction: true, excludeFunction: false, filterFunction: true}")
+ @TestParameters("{includeFunction: false, excludeFunction: true, filterFunction: true}")
+ public void standardDeclaration_moreThanOneFunctionFilterSet_throws(
+ boolean includeFunction, boolean excludeFunction, boolean filterFunction) {
+ CelStandardDeclarations.Builder builder = CelStandardDeclarations.newBuilder();
+ if (includeFunction) {
+ builder.includeFunctions(StandardFunction.ADD);
+ }
+ if (excludeFunction) {
+ builder.excludeFunctions(StandardFunction.SUBTRACT);
+ }
+ if (filterFunction) {
+ builder.filterFunctions((func, over) -> true);
+ }
+
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, builder::build);
+ assertThat(e)
+ .hasMessageThat()
+ .contains(
+ "You may only populate one of the following builder methods: includeFunctions,"
+ + " excludeFunctions or filterFunctions");
+ }
+
+ @Test
+ @TestParameters("{includeIdentifier: true, excludeIdentifier: true, filterIdentifier: true}")
+ @TestParameters("{includeIdentifier: true, excludeIdentifier: true, filterIdentifier: false}")
+ @TestParameters("{includeIdentifier: true, excludeIdentifier: false, filterIdentifier: true}")
+ @TestParameters("{includeIdentifier: false, excludeIdentifier: true, filterIdentifier: true}")
+ public void standardDeclaration_moreThanOneIdentifierFilterSet_throws(
+ boolean includeIdentifier, boolean excludeIdentifier, boolean filterIdentifier) {
+ CelStandardDeclarations.Builder builder = CelStandardDeclarations.newBuilder();
+ if (includeIdentifier) {
+ builder.includeIdentifiers(StandardIdentifier.MAP);
+ }
+ if (excludeIdentifier) {
+ builder.excludeIdentifiers(StandardIdentifier.BOOL);
+ }
+ if (filterIdentifier) {
+ builder.filterIdentifiers((ident) -> true);
+ }
+
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class, builder::build);
+ assertThat(e)
+ .hasMessageThat()
+ .contains(
+ "You may only populate one of the following builder methods: includeIdentifiers,"
+ + " excludeIdentifiers or filterIdentifiers");
+ }
+
+ @Test
+ public void compiler_standardEnvironmentEnabled_throwsWhenOverridingDeclarations() {
+ IllegalArgumentException e =
+ assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ CelCompilerFactory.standardCelCompilerBuilder()
+ .setStandardEnvironmentEnabled(true)
+ .setStandardDeclarations(
+ CelStandardDeclarations.newBuilder()
+ .includeFunctions(StandardFunction.ADD, StandardFunction.SUBTRACT)
+ .build())
+ .build());
+
+ assertThat(e)
+ .hasMessageThat()
+ .contains(
+ "setStandardEnvironmentEnabled must be set to false to override standard"
+ + " declarations.");
+ }
+
+ @Test
+ public void standardDeclarations_includeFunctions() {
+ CelStandardDeclarations celStandardDeclaration =
+ CelStandardDeclarations.newBuilder()
+ .includeFunctions(StandardFunction.ADD, StandardFunction.SUBTRACT)
+ .build();
+
+ assertThat(celStandardDeclaration.functionDecls())
+ .containsExactly(
+ StandardFunction.ADD.functionDecl(), StandardFunction.SUBTRACT.functionDecl());
+ }
+
+ @Test
+ public void standardDeclarations_excludeFunctions() {
+ CelStandardDeclarations celStandardDeclaration =
+ CelStandardDeclarations.newBuilder()
+ .excludeFunctions(StandardFunction.ADD, StandardFunction.SUBTRACT)
+ .build();
+
+ assertThat(celStandardDeclaration.functionDecls())
+ .doesNotContain(StandardFunction.ADD.functionDecl());
+ assertThat(celStandardDeclaration.functionDecls())
+ .doesNotContain(StandardFunction.SUBTRACT.functionDecl());
+ }
+
+ @Test
+ public void standardDeclarations_filterFunctions() {
+ CelStandardDeclarations celStandardDeclaration =
+ CelStandardDeclarations.newBuilder()
+ .filterFunctions(
+ (func, over) -> {
+ if (func.equals(StandardFunction.ADD) && over.equals(Arithmetic.ADD_INT64)) {
+ return true;
+ }
+
+ if (func.equals(StandardFunction.SUBTRACT)
+ && over.equals(Arithmetic.SUBTRACT_INT64)) {
+ return true;
+ }
+
+ return false;
+ })
+ .build();
+
+ assertThat(celStandardDeclaration.functionDecls())
+ .containsExactly(
+ newFunctionDeclaration(
+ StandardFunction.ADD.functionName(), Arithmetic.ADD_INT64.celOverloadDecl()),
+ newFunctionDeclaration(
+ StandardFunction.SUBTRACT.functionName(),
+ Arithmetic.SUBTRACT_INT64.celOverloadDecl()));
+ }
+
+ @Test
+ public void standardDeclarations_includeIdentifiers() {
+ CelStandardDeclarations celStandardDeclaration =
+ CelStandardDeclarations.newBuilder()
+ .includeIdentifiers(StandardIdentifier.INT, StandardIdentifier.UINT)
+ .build();
+
+ assertThat(celStandardDeclaration.identifierDecls())
+ .containsExactly(StandardIdentifier.INT.identDecl(), StandardIdentifier.UINT.identDecl());
+ }
+
+ @Test
+ public void standardDeclarations_excludeIdentifiers() {
+ CelStandardDeclarations celStandardDeclaration =
+ CelStandardDeclarations.newBuilder()
+ .excludeIdentifiers(StandardIdentifier.INT, StandardIdentifier.UINT)
+ .build();
+
+ assertThat(celStandardDeclaration.identifierDecls())
+ .doesNotContain(StandardIdentifier.INT.identDecl());
+ assertThat(celStandardDeclaration.identifierDecls())
+ .doesNotContain(StandardIdentifier.UINT.identDecl());
+ }
+
+ @Test
+ public void standardDeclarations_filterIdentifiers() {
+ CelStandardDeclarations celStandardDeclaration =
+ CelStandardDeclarations.newBuilder()
+ .filterIdentifiers(ident -> ident.equals(StandardIdentifier.MAP))
+ .build();
+
+ assertThat(celStandardDeclaration.identifierDecls())
+ .containsExactly(StandardIdentifier.MAP.identDecl());
+ }
+
+ @Test
+ public void standardEnvironment_subsetEnvironment() throws Exception {
+ CelCompiler celCompiler =
+ CelCompilerFactory.standardCelCompilerBuilder()
+ .setStandardEnvironmentEnabled(false)
+ .setStandardDeclarations(
+ CelStandardDeclarations.newBuilder()
+ .includeFunctions(StandardFunction.ADD, StandardFunction.SUBTRACT)
+ .build())
+ .build();
+
+ assertThat(celCompiler.compile("1 + 2 - 3").getAst()).isNotNull();
+ CelValidationException e =
+ assertThrows(CelValidationException.class, () -> celCompiler.compile("1 * 2 / 3").getAst());
+ assertThat(e).hasMessageThat().contains("undeclared reference to '_*_'");
+ assertThat(e).hasMessageThat().contains("undeclared reference to '_/_'");
+ }
+
+ @Test
+ @TestParameters("{expression: '1 > 2.0'}")
+ @TestParameters("{expression: '2.0 > 1'}")
+ @TestParameters("{expression: '1 > 2u'}")
+ @TestParameters("{expression: '2u > 1'}")
+ @TestParameters("{expression: '2u > 1.0'}")
+ @TestParameters("{expression: '1.0 > 2u'}")
+ @TestParameters("{expression: '1 >= 2.0'}")
+ @TestParameters("{expression: '2.0 >= 1'}")
+ @TestParameters("{expression: '1 >= 2u'}")
+ @TestParameters("{expression: '2u >= 1'}")
+ @TestParameters("{expression: '2u >= 1.0'}")
+ @TestParameters("{expression: '1.0 >= 2u'}")
+ @TestParameters("{expression: '1 < 2.0'}")
+ @TestParameters("{expression: '2.0 < 1'}")
+ @TestParameters("{expression: '1 < 2u'}")
+ @TestParameters("{expression: '2u < 1'}")
+ @TestParameters("{expression: '2u < 1.0'}")
+ @TestParameters("{expression: '1.0 < 2u'}")
+ @TestParameters("{expression: '1 <= 2.0'}")
+ @TestParameters("{expression: '2.0 <= 1'}")
+ @TestParameters("{expression: '1 <= 2u'}")
+ @TestParameters("{expression: '2u <= 1'}")
+ @TestParameters("{expression: '2u <= 1.0'}")
+ @TestParameters("{expression: '1.0 <= 2u'}")
+ public void heterogeneousEqualityDisabled_mixedTypeComparisons_throws(String expression) {
+ CelCompiler celCompiler =
+ CelCompilerFactory.standardCelCompilerBuilder()
+ .setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(false).build())
+ .build();
+
+ CelValidationException e =
+ assertThrows(CelValidationException.class, () -> celCompiler.compile(expression).getAst());
+ assertThat(e).hasMessageThat().contains("found no matching overload for");
+ }
+
+ @Test
+ public void unsignedLongsDisabled_int64Identity_throws() {
+ CelCompiler celCompiler =
+ CelCompilerFactory.standardCelCompilerBuilder()
+ .setOptions(CelOptions.current().enableUnsignedLongs(false).build())
+ .build();
+
+ CelValidationException e =
+ assertThrows(CelValidationException.class, () -> celCompiler.compile("int(1)").getAst());
+ assertThat(e).hasMessageThat().contains("found no matching overload for");
+ }
+
+ @Test
+ public void timestampEpochDisabled_int64Identity_throws() {
+ CelCompiler celCompiler =
+ CelCompilerFactory.standardCelCompilerBuilder()
+ .setOptions(CelOptions.current().enableTimestampEpoch(false).build())
+ .build();
+
+ CelValidationException e =
+ assertThrows(
+ CelValidationException.class, () -> celCompiler.compile("timestamp(10000)").getAst());
+ assertThat(e).hasMessageThat().contains("found no matching overload for");
+ }
+}
diff --git a/checker/src/test/java/dev/cel/checker/DescriptorTypeProviderTest.java b/checker/src/test/java/dev/cel/checker/DescriptorTypeProviderTest.java
index 46e3a419d..11366a68b 100644
--- a/checker/src/test/java/dev/cel/checker/DescriptorTypeProviderTest.java
+++ b/checker/src/test/java/dev/cel/checker/DescriptorTypeProviderTest.java
@@ -17,13 +17,13 @@
import static com.google.common.truth.Truth.assertThat;
import dev.cel.expr.Type;
-import com.google.api.expr.test.v1.proto2.TestAllTypesExtensions;
-import com.google.api.expr.test.v1.proto2.TestAllTypesProto.TestAllTypes;
import com.google.common.collect.ImmutableList;
import com.google.rpc.context.AttributeContext;
import dev.cel.checker.TypeProvider.CombinedTypeProvider;
import dev.cel.checker.TypeProvider.ExtensionFieldType;
-import dev.cel.common.types.CelTypes;
+import dev.cel.common.types.CelProtoTypes;
+import dev.cel.expr.conformance.proto2.TestAllTypes;
+import dev.cel.expr.conformance.proto2.TestAllTypesExtensions;
import java.util.Arrays;
import org.junit.Assert;
import org.junit.Test;
@@ -36,7 +36,7 @@ public final class DescriptorTypeProviderTest {
@Test
public void lookupFieldNames_nonMessageType() {
TypeProvider typeProvider = new DescriptorTypeProvider();
- assertThat(typeProvider.lookupFieldNames(CelTypes.STRING)).isNull();
+ assertThat(typeProvider.lookupFieldNames(CelProtoTypes.STRING)).isNull();
}
@Test
@@ -44,20 +44,21 @@ public void lookupFieldNames_undeclaredMessageType() {
TypeProvider typeProvider = new DescriptorTypeProvider();
assertThat(
typeProvider.lookupFieldNames(
- CelTypes.createMessage("google.rpc.context.AttributeContext")))
+ CelProtoTypes.createMessage("google.rpc.context.AttributeContext")))
.isNull();
}
@Test
public void lookupFieldNames_groupTypeField() throws Exception {
- Type proto2MessageType = CelTypes.createMessage("google.api.expr.test.v1.proto2.TestAllTypes");
+ Type proto2MessageType =
+ CelProtoTypes.createMessage("cel.expr.conformance.proto2.TestAllTypes");
TypeProvider typeProvider =
new DescriptorTypeProvider(
ImmutableList.of(
TestAllTypes.getDescriptor().getFile(), TestAllTypesExtensions.getDescriptor()));
assertThat(typeProvider.lookupFieldType(proto2MessageType, "nestedgroup").type())
.isEqualTo(
- CelTypes.createMessage("google.api.expr.test.v1.proto2.TestAllTypes.NestedGroup"));
+ CelProtoTypes.createMessage("cel.expr.conformance.proto2.TestAllTypes.NestedGroup"));
}
@Test
@@ -100,35 +101,36 @@ public void lookupExtensionType_combinedProvider() {
makePartialTypeProvider(configuredProvider);
final TypeProvider typeProvider =
new CombinedTypeProvider(ImmutableList.of(partialProvider, configuredProvider));
- final Type messageType = CelTypes.createMessage("google.api.expr.test.v1.proto2.TestAllTypes");
+ final Type messageType =
+ CelProtoTypes.createMessage("cel.expr.conformance.proto2.TestAllTypes");
assertThat(typeProvider.lookupExtensionType("non.existent")).isNull();
ExtensionFieldType nestedExt =
- typeProvider.lookupExtensionType("google.api.expr.test.v1.proto2.nested_ext");
+ typeProvider.lookupExtensionType("cel.expr.conformance.proto2.nested_ext");
assertThat(nestedExt).isNotNull();
assertThat(nestedExt.fieldType().type()).isEqualTo(messageType);
assertThat(nestedExt.messageType()).isEqualTo(messageType);
ExtensionFieldType int32Ext =
- typeProvider.lookupExtensionType("google.api.expr.test.v1.proto2.int32_ext");
+ typeProvider.lookupExtensionType("cel.expr.conformance.proto2.int32_ext");
assertThat(int32Ext).isNotNull();
- assertThat(int32Ext.fieldType().type()).isEqualTo(CelTypes.INT64);
+ assertThat(int32Ext.fieldType().type()).isEqualTo(CelProtoTypes.INT64);
assertThat(int32Ext.messageType()).isEqualTo(messageType);
ExtensionFieldType repeatedExt =
- typeProvider.lookupExtensionType("google.api.expr.test.v1.proto2.repeated_test_all_types");
+ typeProvider.lookupExtensionType("cel.expr.conformance.proto2.repeated_test_all_types");
assertThat(repeatedExt).isNotNull();
assertThat(repeatedExt.fieldType().type())
.isEqualTo(
- CelTypes.createList(
- CelTypes.createMessage("google.api.expr.test.v1.proto2.TestAllTypes")));
+ CelProtoTypes.createList(
+ CelProtoTypes.createMessage("cel.expr.conformance.proto2.TestAllTypes")));
assertThat(repeatedExt.messageType()).isEqualTo(messageType);
// With leading dot '.'.
assertThat(
typeProvider.lookupExtensionType(
- ".google.api.expr.test.v1.proto2.repeated_test_all_types"))
+ ".cel.expr.conformance.proto2.repeated_test_all_types"))
.isNotNull();
}
diff --git a/checker/src/test/java/dev/cel/checker/ExprCheckerTest.java b/checker/src/test/java/dev/cel/checker/ExprCheckerTest.java
index c232441fc..b2ecd5a73 100644
--- a/checker/src/test/java/dev/cel/checker/ExprCheckerTest.java
+++ b/checker/src/test/java/dev/cel/checker/ExprCheckerTest.java
@@ -14,13 +14,13 @@
package dev.cel.checker;
-import static dev.cel.common.types.CelTypes.createList;
-import static dev.cel.common.types.CelTypes.createMap;
-import static dev.cel.common.types.CelTypes.createMessage;
-import static dev.cel.common.types.CelTypes.createOptionalType;
-import static dev.cel.common.types.CelTypes.createTypeParam;
-import static dev.cel.common.types.CelTypes.createWrapper;
-import static dev.cel.common.types.CelTypes.format;
+import static dev.cel.common.types.CelProtoTypes.createList;
+import static dev.cel.common.types.CelProtoTypes.createMap;
+import static dev.cel.common.types.CelProtoTypes.createMessage;
+import static dev.cel.common.types.CelProtoTypes.createOptionalType;
+import static dev.cel.common.types.CelProtoTypes.createTypeParam;
+import static dev.cel.common.types.CelProtoTypes.createWrapper;
+import static dev.cel.common.types.CelProtoTypes.format;
import dev.cel.expr.CheckedExpr;
import dev.cel.expr.Constant;
@@ -31,8 +31,6 @@
import dev.cel.expr.Type;
import dev.cel.expr.Type.AbstractType;
import dev.cel.expr.Type.PrimitiveType;
-import com.google.api.expr.test.v1.proto2.TestAllTypesProto;
-import com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
@@ -42,11 +40,12 @@
import dev.cel.common.CelProtoAbstractSyntaxTree;
import dev.cel.common.internal.EnvVisitable;
import dev.cel.common.internal.Errors;
-import dev.cel.common.types.CelTypes;
+import dev.cel.common.types.CelProtoTypes;
import dev.cel.common.types.ListType;
import dev.cel.common.types.MapType;
import dev.cel.common.types.ProtoMessageTypeProvider;
import dev.cel.common.types.SimpleType;
+import dev.cel.expr.conformance.proto3.TestAllTypes;
import dev.cel.testing.CelAdorner;
import dev.cel.testing.CelBaselineTestCase;
import dev.cel.testing.CelDebug;
@@ -76,7 +75,8 @@ private void runTest() throws Exception {
CelAbstractSyntaxTree ast =
prepareTest(
Arrays.asList(
- TestAllTypes.getDescriptor(), TestAllTypesProto.TestAllTypes.getDescriptor()));
+ TestAllTypes.getDescriptor(),
+ dev.cel.expr.conformance.proto2.TestAllTypes.getDescriptor()));
if (ast != null) {
testOutput()
.println(
@@ -152,7 +152,7 @@ public void operatorsBytes() throws Exception {
@Test
public void operatorsConditional() throws Exception {
- declareVariable("x", createMessage("google.api.expr.test.v1.proto3.TestAllTypes"));
+ declareVariable("x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
source = "false ? x.single_timestamp : null";
runTest();
}
@@ -163,19 +163,19 @@ public void operatorsConditional() throws Exception {
@Test
public void referenceTypeRelative() throws Exception {
source = "proto3.TestAllTypes";
- container = "google.api.expr.test.v1.TestAllTypes";
+ container = "cel.expr.conformance.TestAllTypes";
runTest();
}
@Test
public void referenceTypeAbsolute() throws Exception {
- source = ".google.api.expr.test.v1.proto3.TestAllTypes";
+ source = ".cel.expr.conformance.proto3.TestAllTypes";
runTest();
}
@Test
public void referenceValue() throws Exception {
- declareVariable("container.x", createMessage("google.api.expr.test.v1.proto3.TestAllTypes"));
+ declareVariable("container.x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
source = "x";
container = "container";
runTest();
@@ -192,19 +192,19 @@ public void referenceUndefinedError() throws Exception {
@Test
public void anyMessage() throws Exception {
- declareVariable("x", CelTypes.ANY);
+ declareVariable("x", CelProtoTypes.ANY);
declareVariable("y", createWrapper(PrimitiveType.INT64));
source =
"x == google.protobuf.Any{"
- + "type_url:'types.googleapis.com/google.api.expr.test.v1.proto3.TestAllTypes'}"
+ + "type_url:'types.googleapis.com/cel.expr.conformance.proto3.TestAllTypes'}"
+ " && x.single_nested_message.bb == 43 || x =="
- + " google.api.expr.test.v1.proto3.TestAllTypes{} || y < x|| x >= x";
+ + " cel.expr.conformance.proto3.TestAllTypes{} || y < x|| x >= x";
runTest();
}
@Test
public void messageFieldSelect() throws Exception {
- declareVariable("x", createMessage("google.api.expr.test.v1.proto3.TestAllTypes"));
+ declareVariable("x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
source =
"x.single_nested_message.bb == 43 && has(x.single_nested_message) && has(x.single_int32)"
+ " && has(x.repeated_int32) && has(x.map_int64_nested_type)";
@@ -213,7 +213,7 @@ public void messageFieldSelect() throws Exception {
@Test
public void messageFieldSelectError() throws Exception {
- declareVariable("x", createMessage("google.api.expr.test.v1.proto3.TestAllTypes"));
+ declareVariable("x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
source = "x.single_nested_message.undefined == x.undefined";
runTest();
}
@@ -223,7 +223,7 @@ public void messageFieldSelectError() throws Exception {
@Test
public void listOperators() throws Exception {
- declareVariable("x", createList(createMessage("google.api.expr.test.v1.proto3.TestAllTypes")));
+ declareVariable("x", createList(createMessage("cel.expr.conformance.proto3.TestAllTypes")));
source = "(x + x)[1].single_int32 == size(x)";
runTest();
@@ -233,14 +233,14 @@ public void listOperators() throws Exception {
@Test
public void listRepeatedOperators() throws Exception {
- declareVariable("x", createMessage("google.api.expr.test.v1.proto3.TestAllTypes"));
+ declareVariable("x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
source = "x.repeated_int64[x.single_int32] == 23";
runTest();
}
@Test
public void listIndexTypeError() throws Exception {
- declareVariable("x", createList(createMessage("google.api.expr.test.v1.proto3.TestAllTypes")));
+ declareVariable("x", createList(createMessage("cel.expr.conformance.proto3.TestAllTypes")));
source = "x[1u]";
runTest();
}
@@ -253,8 +253,8 @@ public void identError() throws Exception {
@Test
public void listElemTypeError() throws Exception {
- declareVariable("x", createList(createMessage("google.api.expr.test.v1.proto3.TestAllTypes")));
- declareVariable("y", createList(CelTypes.INT64));
+ declareVariable("x", createList(createMessage("cel.expr.conformance.proto3.TestAllTypes")));
+ declareVariable("y", createList(CelProtoTypes.INT64));
source = "x + y";
runTest();
}
@@ -266,7 +266,7 @@ public void listElemTypeError() throws Exception {
public void mapOperators() throws Exception {
declareVariable(
"x",
- createMap(CelTypes.STRING, createMessage("google.api.expr.test.v1.proto3.TestAllTypes")));
+ createMap(CelProtoTypes.STRING, createMessage("cel.expr.conformance.proto3.TestAllTypes")));
source = "x[\"a\"].single_int32 == 23";
runTest();
@@ -278,14 +278,14 @@ public void mapOperators() throws Exception {
public void mapIndexTypeError() throws Exception {
declareVariable(
"x",
- createMap(CelTypes.STRING, createMessage("google.api.expr.test.v1.proto3.TestAllTypes")));
+ createMap(CelProtoTypes.STRING, createMessage("cel.expr.conformance.proto3.TestAllTypes")));
source = "x[2].single_int32 == 23";
runTest();
}
@Test
public void mapEmpty() throws Exception {
- declareVariable("x", createMessage("google.api.expr.test.v1.proto3.TestAllTypes"));
+ declareVariable("x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
source = "size(x.map_int64_nested_type) == 0";
runTest();
}
@@ -295,14 +295,14 @@ public void mapEmpty() throws Exception {
@Test
public void wrapper() throws Exception {
- declareVariable("x", createMessage("google.api.expr.test.v1.proto3.TestAllTypes"));
+ declareVariable("x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
source = "x.single_int64_wrapper + 1 != 23";
runTest();
}
@Test
public void equalsWrapper() throws Exception {
- declareVariable("x", createMessage("google.api.expr.test.v1.proto3.TestAllTypes"));
+ declareVariable("x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
source =
"x.single_int64_wrapper == 1 && "
+ "x.single_int32_wrapper != 2 && "
@@ -318,18 +318,18 @@ public void equalsWrapper() throws Exception {
@Test
public void nullableWrapper() throws Exception {
- declareVariable("x", createMessage("google.api.expr.test.v1.proto3.TestAllTypes"));
+ declareVariable("x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
source = "x.single_int64_wrapper == null";
runTest();
}
@Test
public void nullableMessage() throws Exception {
- declareVariable("x", createMessage("google.api.expr.test.v1.proto3.TestAllTypes"));
+ declareVariable("x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
source = "x.single_nested_message != null";
runTest();
- container = "google.api.expr.test.v1.proto3.TestAllTypesProto";
+ container = "cel.expr.conformance.proto3.TestAllTypesProto";
source = "null == TestAllTypes{} || TestAllTypes{} == null";
runTest();
}
@@ -342,7 +342,7 @@ public void nullNull() throws Exception {
@Test
public void nullablePrimitiveError() throws Exception {
- declareVariable("x", createMessage("google.api.expr.test.v1.proto3.TestAllTypes"));
+ declareVariable("x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
source = "x.single_int64 != null";
runTest();
}
@@ -352,14 +352,14 @@ public void nullablePrimitiveError() throws Exception {
@Test
public void dynOperators() throws Exception {
- declareVariable("x", createMessage("google.api.expr.test.v1.proto3.TestAllTypes"));
+ declareVariable("x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
source = "x.single_value + 1 / x.single_struct.y == 23";
runTest();
}
@Test
public void dynOperatorsAtRuntime() throws Exception {
- declareVariable("x", createMessage("google.api.expr.test.v1.proto3.TestAllTypes"));
+ declareVariable("x", createMessage("cel.expr.conformance.proto3.TestAllTypes"));
source = "x.single_value[23] + x.single_struct['y']";
runTest();
}
@@ -424,8 +424,11 @@ public void callStyle() throws Exception {
declareFunction(
"size",
memberOverload(
- "my_size", ImmutableList.of(createList(param)), ImmutableList.of("A"), CelTypes.INT64));
- declareVariable("x", createList(CelTypes.INT64));
+ "my_size",
+ ImmutableList.of(createList(param)),
+ ImmutableList.of("A"),
+ CelProtoTypes.INT64));
+ declareVariable("x", createList(CelProtoTypes.INT64));
source = "size(x) == x.size()";
runTest();
}
@@ -436,12 +439,12 @@ public void userFunction() throws Exception {
"myfun",
memberOverload(
"myfun_instance",
- ImmutableList.of(CelTypes.INT64, CelTypes.BOOL, CelTypes.UINT64),
- CelTypes.INT64),
+ ImmutableList.of(CelProtoTypes.INT64, CelProtoTypes.BOOL, CelProtoTypes.UINT64),
+ CelProtoTypes.INT64),
globalOverload(
"myfun_static",
- ImmutableList.of(CelTypes.INT64, CelTypes.BOOL, CelTypes.UINT64),
- CelTypes.INT64));
+ ImmutableList.of(CelProtoTypes.INT64, CelProtoTypes.BOOL, CelProtoTypes.UINT64),
+ CelProtoTypes.INT64));
source = "myfun(1, true, 3u) + 1.myfun(false, 3u).myfun(true, 42u)";
runTest();
}
@@ -450,7 +453,8 @@ public void userFunction() throws Exception {
public void namespacedFunctions() throws Exception {
declareFunction(
"ns.func",
- globalOverload("ns_func_overload", ImmutableList.of(CelTypes.STRING), CelTypes.INT64));
+ globalOverload(
+ "ns_func_overload", ImmutableList.of(CelProtoTypes.STRING), CelProtoTypes.INT64));
source = "ns.func('hello')";
runTest();
@@ -458,8 +462,8 @@ public void namespacedFunctions() throws Exception {
"member",
memberOverload(
"ns_member_overload",
- ImmutableList.of(CelTypes.INT64, CelTypes.INT64),
- CelTypes.INT64));
+ ImmutableList.of(CelProtoTypes.INT64, CelProtoTypes.INT64),
+ CelProtoTypes.INT64));
source = "ns.func('hello').member(ns.func('test'))";
runTest();
@@ -490,13 +494,13 @@ public void namespacedFunctions() throws Exception {
@Test
public void namespacedVariables() throws Exception {
container = "ns";
- declareVariable("ns.x", CelTypes.INT64);
+ declareVariable("ns.x", CelProtoTypes.INT64);
source = "x";
runTest();
- container = "google.api.expr.test.v1.proto3";
- Type messageType = createMessage("google.api.expr.test.v1.proto3.TestAllTypes");
- declareVariable("google.api.expr.test.v1.proto3.msgVar", messageType);
+ container = "cel.expr.conformance.proto3";
+ Type messageType = createMessage("cel.expr.conformance.proto3.TestAllTypes");
+ declareVariable("cel.expr.conformance.proto3.msgVar", messageType);
source = "msgVar.single_int32";
runTest();
}
@@ -507,8 +511,8 @@ public void userFunctionMultipleOverloadsWithSanitization() throws Exception {
declareVariable("s", structType);
declareFunction(
"myfun",
- globalOverload("myfun_int", ImmutableList.of(CelTypes.INT64), CelTypes.INT64),
- globalOverload("myfun_struct", ImmutableList.of(structType), CelTypes.INT64));
+ globalOverload("myfun_int", ImmutableList.of(CelProtoTypes.INT64), CelProtoTypes.INT64),
+ globalOverload("myfun_struct", ImmutableList.of(structType), CelProtoTypes.INT64));
source = "myfun(1) + myfun(s)";
runTest();
}
@@ -525,25 +529,26 @@ public void userFunctionOverlaps() throws Exception {
"my_size",
ImmutableList.of(createList(param)),
ImmutableList.of("TEST"),
- CelTypes.UINT64));
- declareVariable("x", createList(CelTypes.INT64));
+ CelProtoTypes.UINT64));
+ declareVariable("x", createList(CelProtoTypes.INT64));
source = "size(x) == 1u";
runTest();
}
@Test
public void userFunctionAddsOverload() throws Exception {
- Type messageType = createMessage("google.api.expr.test.v1.proto3.TestAllTypes");
+ Type messageType = createMessage("cel.expr.conformance.proto3.TestAllTypes");
declareVariable("x", messageType);
declareFunction(
- "size", globalOverload("size_message", ImmutableList.of(messageType), CelTypes.INT64));
+ "size", globalOverload("size_message", ImmutableList.of(messageType), CelProtoTypes.INT64));
source = "size(x) > 4";
runTest();
}
@Test
public void userFunctionAddsMacroError() throws Exception {
- declareFunction("has", globalOverload("has_id", ImmutableList.of(CelTypes.DYN), CelTypes.DYN));
+ declareFunction(
+ "has", globalOverload("has_id", ImmutableList.of(CelProtoTypes.DYN), CelProtoTypes.DYN));
source = "false";
runTest();
}
@@ -553,7 +558,7 @@ public void userFunctionAddsMacroError() throws Exception {
@Test
public void proto2PrimitiveField() throws Exception {
- declareVariable("x", createMessage("google.api.expr.test.v1.proto2.TestAllTypes"));
+ declareVariable("x", createMessage("cel.expr.conformance.proto2.TestAllTypes"));
source = "x.single_fixed32 != 0u && x.single_fixed64 > 1u && x.single_int32 != null";
runTest();
source = "x.nestedgroup.single_name == ''";
@@ -565,21 +570,21 @@ public void proto2PrimitiveField() throws Exception {
@Test
public void aggregateMessage() throws Exception {
- container = "google.api.expr.test.v1.proto3.TestAllTypesProto";
+ container = "cel.expr.conformance.proto3";
source = "TestAllTypes{single_int32: 1, single_int64: 2}";
runTest();
}
@Test
public void aggregateMessageFieldUndefinedError() throws Exception {
- container = "google.api.expr.test.v1.proto3.TestAllTypesProto";
+ container = "cel.expr.conformance.proto3";
source = "TestAllTypes{single_int32: 1, undefined: 2}";
runTest();
}
@Test
public void aggregateMessageFieldTypeError() throws Exception {
- container = "google.api.expr.test.v1.proto3.TestAllTypesProto";
+ container = "cel.expr.conformance.proto3";
source = "TestAllTypes{single_int32: 1u}";
runTest();
}
@@ -663,7 +668,7 @@ public void types() throws Exception {
@Test
public void enumValues() throws Exception {
- container = "google.api.expr.test.v1.proto3.TestAllTypesProto";
+ container = "cel.expr.conformance.proto3";
source = "TestAllTypes.NestedEnum.BAR != 99";
runTest();
}
@@ -675,7 +680,7 @@ public void nestedEnums() throws Exception {
source = "x.single_nested_enum == TestAllTypes.NestedEnum.BAR";
runTest();
- declareVariable("single_nested_enum", CelTypes.INT64);
+ declareVariable("single_nested_enum", CelProtoTypes.INT64);
source = "single_nested_enum == TestAllTypes.NestedEnum.BAR";
runTest();
@@ -686,7 +691,7 @@ public void nestedEnums() throws Exception {
@Test
public void globalEnumValues() throws Exception {
- container = "google.api.expr.test.v1.proto3.TestAllTypesProto";
+ container = "cel.expr.conformance.proto3";
source = "GlobalEnum.GAZ == 2";
runTest();
}
@@ -696,7 +701,7 @@ public void globalEnumValues() throws Exception {
@Test
public void globalStandaloneEnumValues() throws Exception {
- container = "dev.cel.testing.testdata.proto3.TestAllTypesProto";
+ container = "dev.cel.testing.testdata.proto3";
source = "StandaloneGlobalEnum.SGAZ == 2";
FileDescriptorSet.Builder descriptorBuilder = FileDescriptorSet.newBuilder();
@@ -726,7 +731,7 @@ public void conversions() throws Exception {
@Test
public void quantifiers() throws Exception {
- Type messageType = createMessage("google.api.expr.test.v1.proto3.TestAllTypes");
+ Type messageType = createMessage("cel.expr.conformance.proto3.TestAllTypes");
declareVariable("x", messageType);
source =
"x.repeated_int64.all(e, e > 0) "
@@ -737,7 +742,7 @@ public void quantifiers() throws Exception {
@Test
public void quantifiersErrors() throws Exception {
- Type messageType = createMessage("google.api.expr.test.v1.proto3.TestAllTypes");
+ Type messageType = createMessage("cel.expr.conformance.proto3.TestAllTypes");
declareVariable("x", messageType);
source = "x.all(e, 0)";
runTest();
@@ -745,7 +750,7 @@ public void quantifiersErrors() throws Exception {
@Test
public void mapExpr() throws Exception {
- Type messageType = createMessage("google.api.expr.test.v1.proto3.TestAllTypes");
+ Type messageType = createMessage("cel.expr.conformance.proto3.TestAllTypes");
declareVariable("x", messageType);
source = "x.repeated_int64.map(x, double(x))";
runTest();
@@ -759,16 +764,16 @@ public void mapExpr() throws Exception {
@Test
public void mapFilterExpr() throws Exception {
- Type messageType = createMessage("google.api.expr.test.v1.proto3.TestAllTypes");
+ Type messageType = createMessage("cel.expr.conformance.proto3.TestAllTypes");
declareVariable("x", messageType);
source = "x.repeated_int64.map(x, x > 0, double(x))";
runTest();
- declareVariable("lists", CelTypes.DYN);
+ declareVariable("lists", CelProtoTypes.DYN);
source = "lists.filter(x, x > 1.5)";
runTest();
- declareVariable("args", createMap(CelTypes.STRING, CelTypes.DYN));
+ declareVariable("args", createMap(CelProtoTypes.STRING, CelProtoTypes.DYN));
source = "args.user[\"myextension\"].customAttributes.filter(x, x.name == \"hobbies\")";
runTest();
}
@@ -781,12 +786,12 @@ public void abstractTypeParameterLess() throws Exception {
Type abstractType =
Type.newBuilder().setAbstractType(AbstractType.newBuilder().setName("abs")).build();
// Declare the identifier 'abs' to bind to the abstract type.
- declareVariable("abs", CelTypes.create(abstractType));
+ declareVariable("abs", CelProtoTypes.create(abstractType));
// Declare a function to create a new value of abstract type.
declareFunction("make_abs", globalOverload("make_abs", ImmutableList.of(), abstractType));
// Declare a function to consume value of abstract type.
declareFunction(
- "as_bool", memberOverload("as_bool", ImmutableList.of(abstractType), CelTypes.BOOL));
+ "as_bool", memberOverload("as_bool", ImmutableList.of(abstractType), CelProtoTypes.BOOL));
source = "type(make_abs()) == abs && make_abs().as_bool()";
runTest();
@@ -794,7 +799,7 @@ public void abstractTypeParameterLess() throws Exception {
@Test
public void abstractTypeParameterized() throws Exception {
- Type typeParam = createTypeParam("T");
+ Type typeParam = CelProtoTypes.createTypeParam("T");
Type abstractType =
Type.newBuilder()
.setAbstractType(
@@ -805,14 +810,14 @@ public void abstractTypeParameterized() throws Exception {
"vector",
// Declare the function 'vector' to create the abstract type.
globalOverload(
- "vector",
- ImmutableList.of(CelTypes.create(typeParam)),
+ "vector_type",
+ ImmutableList.of(CelProtoTypes.create(typeParam)),
ImmutableList.of("T"),
- CelTypes.create(abstractType)),
+ CelProtoTypes.create(abstractType)),
// Declare a function to create a new value of abstract type based on a list.
globalOverload(
- "vector",
- ImmutableList.of(createList(typeParam)),
+ "vector_list",
+ ImmutableList.of(CelProtoTypes.createList(typeParam)),
ImmutableList.of("T"),
abstractType));
@@ -820,8 +825,8 @@ public void abstractTypeParameterized() throws Exception {
declareFunction(
"at",
memberOverload(
- "at",
- ImmutableList.of(abstractType, CelTypes.INT64),
+ "vector_at_int",
+ ImmutableList.of(abstractType, CelProtoTypes.INT64),
ImmutableList.of("T"),
typeParam));
@@ -843,13 +848,13 @@ public void abstractTypeParameterizedInListLiteral() throws Exception {
"vector",
// Declare the function 'vector' to create the abstract type.
globalOverload(
- "vector",
- ImmutableList.of(CelTypes.create(typeParam)),
+ "vector_type",
+ ImmutableList.of(CelProtoTypes.create(typeParam)),
ImmutableList.of("T"),
- CelTypes.create(abstractType)),
+ CelProtoTypes.create(abstractType)),
// Declare a function to create a new value of abstract type based on a list.
globalOverload(
- "vector",
+ "vector_list",
ImmutableList.of(createList(typeParam)),
ImmutableList.of("T"),
abstractType));
@@ -870,23 +875,24 @@ public void abstractTypeParameterizedError() throws Exception {
"vector",
// Declare the function 'vector' to create the abstract type.
globalOverload(
- "vector",
- ImmutableList.of(CelTypes.create(typeParam)),
+ "vector_type",
+ ImmutableList.of(CelProtoTypes.create(typeParam)),
ImmutableList.of("T"),
- CelTypes.create(abstractType)),
+ CelProtoTypes.create(abstractType)),
// Declare a function to create a new value of abstract type based on a list.
globalOverload(
- "vector",
+ "vector_list",
ImmutableList.of(createList(typeParam)),
ImmutableList.of("T"),
abstractType));
declareFunction(
"add",
globalOverload(
- "add",
- ImmutableList.of(CelTypes.create(abstractType), CelTypes.create(abstractType)),
+ "add_vector_type",
+ ImmutableList.of(
+ CelProtoTypes.create(abstractType), CelProtoTypes.create(abstractType)),
ImmutableList.of("T"),
- abstractType));
+ CelProtoTypes.create(abstractType)));
source = "add(vector([1, 2]), vector([2u, -1])) == vector([1, 2, 2u, -1])";
runTest();
}
@@ -894,12 +900,12 @@ public void abstractTypeParameterizedError() throws Exception {
// Optionals
@Test
public void optionals() throws Exception {
- declareVariable("a", createMap(CelTypes.STRING, CelTypes.STRING));
+ declareVariable("a", createMap(CelProtoTypes.STRING, CelProtoTypes.STRING));
source = "a.?b";
runTest();
clearAllDeclarations();
- declareVariable("x", createOptionalType(createMap(CelTypes.STRING, CelTypes.STRING)));
+ declareVariable("x", createOptionalType(createMap(CelProtoTypes.STRING, CelProtoTypes.STRING)));
source = "x.y";
runTest();
@@ -907,7 +913,7 @@ public void optionals() throws Exception {
runTest();
clearAllDeclarations();
- declareVariable("d", createOptionalType(CelTypes.DYN));
+ declareVariable("d", createOptionalType(CelProtoTypes.DYN));
source = "d.dynamic";
runTest();
@@ -915,7 +921,7 @@ public void optionals() throws Exception {
runTest();
clearAllDeclarations();
- declareVariable("e", createOptionalType(createMap(CelTypes.STRING, CelTypes.DYN)));
+ declareVariable("e", createOptionalType(createMap(CelProtoTypes.STRING, CelProtoTypes.DYN)));
source = "has(e.?b.c)";
runTest();
@@ -926,13 +932,13 @@ public void optionals() throws Exception {
source = "{?'key': {'a': 'b'}.?value}.key";
runTest();
- container = "google.api.expr.test.v1.proto3.TestAllTypesProto";
+ container = "cel.expr.conformance.proto3";
source = "TestAllTypes{?single_int32: {}.?i}";
runTest();
container = "";
- declareVariable("a", createOptionalType(CelTypes.STRING));
- declareVariable("b", createOptionalType(CelTypes.STRING));
+ declareVariable("a", createOptionalType(CelProtoTypes.STRING));
+ declareVariable("b", createOptionalType(CelProtoTypes.STRING));
source = "[?a, ?b, 'world']";
runTest();
@@ -951,12 +957,12 @@ public void optionalErrors() throws Exception {
source = "[?'value']";
runTest();
- container = "google.api.expr.test.v1.proto3.TestAllTypesProto";
+ container = "cel.expr.conformance.proto3";
source = "TestAllTypes{?single_int32: 1}";
runTest();
source = "a.?b";
- declareVariable("a", createMap(CelTypes.STRING, CelTypes.STRING));
+ declareVariable("a", createMap(CelProtoTypes.STRING, CelProtoTypes.STRING));
prepareCompiler(new ProtoMessageTypeProvider());
ParsedExpr parsedExpr =
CelProtoAbstractSyntaxTree.fromCelAst(celCompiler.parse(source).getAst()).toParsedExpr();
diff --git a/checker/src/test/java/dev/cel/checker/TypeProviderLegacyImplTest.java b/checker/src/test/java/dev/cel/checker/TypeProviderLegacyImplTest.java
index 9195bb3d5..4569877c3 100644
--- a/checker/src/test/java/dev/cel/checker/TypeProviderLegacyImplTest.java
+++ b/checker/src/test/java/dev/cel/checker/TypeProviderLegacyImplTest.java
@@ -18,13 +18,13 @@
import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;
import dev.cel.expr.Type;
-import com.google.api.expr.test.v1.proto2.Proto2ExtensionScopedMessage;
-import com.google.api.expr.test.v1.proto2.TestAllTypesProto.TestAllTypes;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.protobuf.Descriptors.Descriptor;
-import dev.cel.common.types.CelTypes;
+import dev.cel.common.types.CelProtoTypes;
import dev.cel.common.types.ProtoMessageTypeProvider;
+import dev.cel.expr.conformance.proto2.Proto2ExtensionScopedMessage;
+import dev.cel.expr.conformance.proto2.TestAllTypes;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -45,9 +45,8 @@ public final class TypeProviderLegacyImplTest {
@Test
public void lookupType() {
- assertThat(compatTypeProvider.lookupType("google.api.expr.test.v1.proto2.TestAllTypes"))
- .isEqualTo(
- descriptorTypeProvider.lookupType("google.api.expr.test.v1.proto2.TestAllTypes"));
+ assertThat(compatTypeProvider.lookupType("cel.expr.conformance.proto2.TestAllTypes"))
+ .isEqualTo(descriptorTypeProvider.lookupType("cel.expr.conformance.proto2.TestAllTypes"));
assertThat(compatTypeProvider.lookupType("not.registered.TypeName"))
.isEqualTo(descriptorTypeProvider.lookupType("not.registered.TypeName"));
}
@@ -55,9 +54,7 @@ public void lookupType() {
@Test
public void lookupFieldNames() {
Type nestedTestAllTypes =
- compatTypeProvider
- .lookupType("google.api.expr.test.v1.proto2.NestedTestAllTypes")
- .getType();
+ compatTypeProvider.lookupType("cel.expr.conformance.proto2.NestedTestAllTypes").getType();
ImmutableSet fieldNames = compatTypeProvider.lookupFieldNames(nestedTestAllTypes);
assertThat(fieldNames)
.containsExactlyElementsIn(descriptorTypeProvider.lookupFieldNames(nestedTestAllTypes));
@@ -67,9 +64,7 @@ public void lookupFieldNames() {
@Test
public void lookupFieldType() {
Type nestedTestAllTypes =
- compatTypeProvider
- .lookupType("google.api.expr.test.v1.proto2.NestedTestAllTypes")
- .getType();
+ compatTypeProvider.lookupType("cel.expr.conformance.proto2.NestedTestAllTypes").getType();
assertThat(compatTypeProvider.lookupFieldType(nestedTestAllTypes, "payload"))
.isEqualTo(descriptorTypeProvider.lookupFieldType(nestedTestAllTypes, "payload"));
assertThat(compatTypeProvider.lookupFieldType(nestedTestAllTypes, "child"))
@@ -79,7 +74,7 @@ public void lookupFieldType() {
@Test
public void lookupFieldType_inputNotMessage() {
Type globalEnumType =
- compatTypeProvider.lookupType("google.api.expr.test.v1.proto2.GlobalEnum").getType();
+ compatTypeProvider.lookupType("cel.expr.conformance.proto2.GlobalEnum").getType();
assertThat(compatTypeProvider.lookupFieldType(globalEnumType, "payload")).isNull();
assertThat(compatTypeProvider.lookupFieldType(globalEnumType, "payload"))
.isEqualTo(descriptorTypeProvider.lookupFieldType(globalEnumType, "payload"));
@@ -88,47 +83,44 @@ public void lookupFieldType_inputNotMessage() {
@Test
public void lookupExtension() {
TypeProvider.ExtensionFieldType extensionType =
- compatTypeProvider.lookupExtensionType("google.api.expr.test.v1.proto2.nested_enum_ext");
+ compatTypeProvider.lookupExtensionType("cel.expr.conformance.proto2.nested_enum_ext");
assertThat(extensionType.messageType())
- .isEqualTo(CelTypes.createMessage("google.api.expr.test.v1.proto2.TestAllTypes"));
- assertThat(extensionType.fieldType().type()).isEqualTo(CelTypes.INT64);
+ .isEqualTo(CelProtoTypes.createMessage("cel.expr.conformance.proto2.TestAllTypes"));
+ assertThat(extensionType.fieldType().type()).isEqualTo(CelProtoTypes.INT64);
assertThat(extensionType)
.isEqualTo(
descriptorTypeProvider.lookupExtensionType(
- "google.api.expr.test.v1.proto2.nested_enum_ext"));
+ "cel.expr.conformance.proto2.nested_enum_ext"));
}
@Test
public void lookupEnumValue() {
Integer enumValue =
- compatTypeProvider.lookupEnumValue("google.api.expr.test.v1.proto2.GlobalEnum.GAR");
+ compatTypeProvider.lookupEnumValue("cel.expr.conformance.proto2.GlobalEnum.GAR");
assertThat(enumValue).isEqualTo(1);
assertThat(enumValue)
.isEqualTo(
- descriptorTypeProvider.lookupEnumValue(
- "google.api.expr.test.v1.proto2.GlobalEnum.GAR"));
+ descriptorTypeProvider.lookupEnumValue("cel.expr.conformance.proto2.GlobalEnum.GAR"));
}
@Test
public void lookupEnumValue_notFoundValue() {
Integer enumValue =
- compatTypeProvider.lookupEnumValue("google.api.expr.test.v1.proto2.GlobalEnum.BAR");
+ compatTypeProvider.lookupEnumValue("cel.expr.conformance.proto2.GlobalEnum.BAR");
assertThat(enumValue).isNull();
assertThat(enumValue)
.isEqualTo(
- descriptorTypeProvider.lookupEnumValue(
- "google.api.expr.test.v1.proto2.GlobalEnum.BAR"));
+ descriptorTypeProvider.lookupEnumValue("cel.expr.conformance.proto2.GlobalEnum.BAR"));
}
@Test
public void lookupEnumValue_notFoundEnumType() {
Integer enumValue =
- compatTypeProvider.lookupEnumValue("google.api.expr.test.v1.proto2.InvalidEnum.TEST");
+ compatTypeProvider.lookupEnumValue("cel.expr.conformance.proto2.InvalidEnum.TEST");
assertThat(enumValue).isNull();
assertThat(enumValue)
.isEqualTo(
- descriptorTypeProvider.lookupEnumValue(
- "google.api.expr.test.v1.proto2.InvalidEnum.TEST"));
+ descriptorTypeProvider.lookupEnumValue("cel.expr.conformance.proto2.InvalidEnum.TEST"));
}
@Test
diff --git a/checker/src/test/java/dev/cel/checker/TypesTest.java b/checker/src/test/java/dev/cel/checker/TypesTest.java
index 60be88bb8..960ebec3f 100644
--- a/checker/src/test/java/dev/cel/checker/TypesTest.java
+++ b/checker/src/test/java/dev/cel/checker/TypesTest.java
@@ -19,8 +19,8 @@
import dev.cel.expr.Type;
import dev.cel.expr.Type.PrimitiveType;
import dev.cel.common.types.CelKind;
+import dev.cel.common.types.CelProtoTypes;
import dev.cel.common.types.CelType;
-import dev.cel.common.types.CelTypes;
import dev.cel.common.types.SimpleType;
import java.util.HashMap;
import java.util.Map;
@@ -34,8 +34,8 @@ public class TypesTest {
@Test
public void isAssignable_usingProtoTypes() {
Map subs = new HashMap<>();
- Type typeParamA = CelTypes.createTypeParam("A");
- Type stringType = CelTypes.create(PrimitiveType.STRING);
+ Type typeParamA = CelProtoTypes.createTypeParam("A");
+ Type stringType = CelProtoTypes.create(PrimitiveType.STRING);
Map result = Types.isAssignable(subs, typeParamA, stringType);
diff --git a/checker/src/test/resources/abstractTypeParameterized.baseline b/checker/src/test/resources/abstractTypeParameterized.baseline
index 948f61ec9..28cc0000a 100644
--- a/checker/src/test/resources/abstractTypeParameterized.baseline
+++ b/checker/src/test/resources/abstractTypeParameterized.baseline
@@ -1,10 +1,10 @@
Source: type(vector([1])) == vector(dyn) && vector([1]).at(0) == 1
declare vector {
- function vector (type(T)) -> type(vector(T))
- function vector (list(T)) -> vector(T)
+ function vector_type (type(T)) -> type(vector(T))
+ function vector_list (list(T)) -> vector(T)
}
declare at {
- function at vector(T).(int) -> T
+ function vector_at_int vector(T).(int) -> T
}
=====>
_&&_(
@@ -14,20 +14,20 @@ _&&_(
[
1~int
]~list(int)
- )~vector(int)^vector
+ )~vector(int)^vector_list
)~type(vector(int))^type,
vector(
dyn~type(dyn)^dyn
- )~type(vector(dyn))^vector
+ )~type(vector(dyn))^vector_type
)~bool^equals,
_==_(
vector(
[
1~int
]~list(int)
- )~vector(int)^vector.at(
+ )~vector(int)^vector_list.at(
0~int
- )~int^at,
+ )~int^vector_at_int,
1~int
)~bool^equals
)~bool^logical_and
diff --git a/checker/src/test/resources/abstractTypeParameterizedError.baseline b/checker/src/test/resources/abstractTypeParameterizedError.baseline
index 140202ab1..8ef50993e 100644
--- a/checker/src/test/resources/abstractTypeParameterizedError.baseline
+++ b/checker/src/test/resources/abstractTypeParameterizedError.baseline
@@ -1,10 +1,10 @@
Source: add(vector([1, 2]), vector([2u, -1])) == vector([1, 2, 2u, -1])
declare vector {
- function vector (type(T)) -> type(vector(T))
- function vector (list(T)) -> vector(T)
+ function vector_type (type(T)) -> type(vector(T))
+ function vector_list (list(T)) -> vector(T)
}
declare add {
- function add (type(vector(T)), type(vector(T))) -> vector(T)
+ function add_vector_type (type(vector(T)), type(vector(T))) -> type(vector(T))
}
=====>
ERROR: test_location:1:4: found no matching overload for 'add' applied to '(vector(int), vector(dyn))' (candidates: (type(vector(%T4)), type(vector(%T4))))
diff --git a/checker/src/test/resources/abstractTypeParameterizedInListLiteral.baseline b/checker/src/test/resources/abstractTypeParameterizedInListLiteral.baseline
index e07a05598..3425e0325 100644
--- a/checker/src/test/resources/abstractTypeParameterizedInListLiteral.baseline
+++ b/checker/src/test/resources/abstractTypeParameterizedInListLiteral.baseline
@@ -1,7 +1,7 @@
Source: size([vector([1, 2]), vector([2u, -1])]) == 2
declare vector {
- function vector (type(T)) -> type(vector(T))
- function vector (list(T)) -> vector(T)
+ function vector_type (type(T)) -> type(vector(T))
+ function vector_list (list(T)) -> vector(T)
}
=====>
_==_(
@@ -12,13 +12,13 @@ _==_(
1~int,
2~int
]~list(int)
- )~vector(int)^vector,
+ )~vector(int)^vector_list,
vector(
[
2u~uint,
-1~int
]~list(dyn)
- )~vector(dyn)^vector
+ )~vector(dyn)^vector_list
]~list(vector(dyn))
)~int^size_list,
2~int
diff --git a/checker/src/test/resources/aggregateMessage.baseline b/checker/src/test/resources/aggregateMessage.baseline
index 506b5deb6..7bace8021 100644
--- a/checker/src/test/resources/aggregateMessage.baseline
+++ b/checker/src/test/resources/aggregateMessage.baseline
@@ -3,5 +3,5 @@ Source: TestAllTypes{single_int32: 1, single_int64: 2}
TestAllTypes{
single_int32:1~int,
single_int64:2~int
-}~google.api.expr.test.v1.proto3.TestAllTypes^google.api.expr.test.v1.proto3.TestAllTypes
+}~cel.expr.conformance.proto3.TestAllTypes^cel.expr.conformance.proto3.TestAllTypes
diff --git a/checker/src/test/resources/anyMessage.baseline b/checker/src/test/resources/anyMessage.baseline
index 83b50bac3..9c94a0b24 100644
--- a/checker/src/test/resources/anyMessage.baseline
+++ b/checker/src/test/resources/anyMessage.baseline
@@ -1,4 +1,4 @@
-Source: x == google.protobuf.Any{type_url:'types.googleapis.com/google.api.expr.test.v1.proto3.TestAllTypes'} && x.single_nested_message.bb == 43 || x == google.api.expr.test.v1.proto3.TestAllTypes{} || y < x|| x >= x
+Source: x == google.protobuf.Any{type_url:'types.googleapis.com/cel.expr.conformance.proto3.TestAllTypes'} && x.single_nested_message.bb == 43 || x == cel.expr.conformance.proto3.TestAllTypes{} || y < x|| x >= x
declare x {
value any
}
@@ -12,7 +12,7 @@ _||_(
_==_(
x~any^x,
google.protobuf.Any{
- type_url:"types.googleapis.com/google.api.expr.test.v1.proto3.TestAllTypes"~string
+ type_url:"types.googleapis.com/cel.expr.conformance.proto3.TestAllTypes"~string
}~any^google.protobuf.Any
)~bool^equals,
_==_(
@@ -22,7 +22,7 @@ _||_(
)~bool^logical_and,
_==_(
x~any^x,
- google.api.expr.test.v1.proto3.TestAllTypes{}~google.api.expr.test.v1.proto3.TestAllTypes^google.api.expr.test.v1.proto3.TestAllTypes
+ cel.expr.conformance.proto3.TestAllTypes{}~cel.expr.conformance.proto3.TestAllTypes^cel.expr.conformance.proto3.TestAllTypes
)~bool^equals
)~bool^logical_or,
_||_(
diff --git a/checker/src/test/resources/dynOperators.baseline b/checker/src/test/resources/dynOperators.baseline
index ae4ea2c41..ceb4ce9e6 100644
--- a/checker/src/test/resources/dynOperators.baseline
+++ b/checker/src/test/resources/dynOperators.baseline
@@ -1,14 +1,14 @@
Source: x.single_value + 1 / x.single_struct.y == 23
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_==_(
_+_(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_value~dyn,
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_value~dyn,
_/_(
1~int,
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_struct~map(string, dyn).y~dyn
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_struct~map(string, dyn).y~dyn
)~int^divide_int64
)~int^add_int64,
23~int
diff --git a/checker/src/test/resources/dynOperatorsAtRuntime.baseline b/checker/src/test/resources/dynOperatorsAtRuntime.baseline
index 8730c3c35..470289997 100644
--- a/checker/src/test/resources/dynOperatorsAtRuntime.baseline
+++ b/checker/src/test/resources/dynOperatorsAtRuntime.baseline
@@ -1,15 +1,15 @@
Source: x.single_value[23] + x.single_struct['y']
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_+_(
_[_](
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_value~dyn,
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_value~dyn,
23~int
)~dyn^index_list|index_map,
_[_](
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_struct~map(string, dyn),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_struct~map(string, dyn),
"y"~string
)~dyn^index_map
)~dyn^add_int64|add_uint64|add_double|add_string|add_bytes|add_list|add_timestamp_duration|add_duration_timestamp|add_duration_duration
diff --git a/checker/src/test/resources/enumValues.baseline b/checker/src/test/resources/enumValues.baseline
index b861e12d7..be343985a 100644
--- a/checker/src/test/resources/enumValues.baseline
+++ b/checker/src/test/resources/enumValues.baseline
@@ -1,6 +1,6 @@
Source: TestAllTypes.NestedEnum.BAR != 99
=====>
_!=_(
- google.api.expr.test.v1.proto3.TestAllTypes.NestedEnum.BAR~int^google.api.expr.test.v1.proto3.TestAllTypes.NestedEnum.BAR,
+ cel.expr.conformance.proto3.TestAllTypes.NestedEnum.BAR~int^cel.expr.conformance.proto3.TestAllTypes.NestedEnum.BAR,
99~int
)~bool^not_equals
diff --git a/checker/src/test/resources/equalsWrapper.baseline b/checker/src/test/resources/equalsWrapper.baseline
index 0f7fdbe4e..ad105a5bd 100644
--- a/checker/src/test/resources/equalsWrapper.baseline
+++ b/checker/src/test/resources/equalsWrapper.baseline
@@ -1,38 +1,38 @@
Source: x.single_int64_wrapper == 1 && x.single_int32_wrapper != 2 && x.single_double_wrapper != 2.0 && x.single_float_wrapper == 1.0 && x.single_uint32_wrapper == 1u && x.single_uint64_wrapper != 42u
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_&&_(
_&&_(
_&&_(
_==_(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_int64_wrapper~wrapper(int),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_int64_wrapper~wrapper(int),
1~int
)~bool^equals,
_!=_(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_int32_wrapper~wrapper(int),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_int32_wrapper~wrapper(int),
2~int
)~bool^not_equals
)~bool^logical_and,
_!=_(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_double_wrapper~wrapper(double),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_double_wrapper~wrapper(double),
2.0~double
)~bool^not_equals
)~bool^logical_and,
_&&_(
_&&_(
_==_(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_float_wrapper~wrapper(double),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_float_wrapper~wrapper(double),
1.0~double
)~bool^equals,
_==_(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_uint32_wrapper~wrapper(uint),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_uint32_wrapper~wrapper(uint),
1u~uint
)~bool^equals
)~bool^logical_and,
_!=_(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_uint64_wrapper~wrapper(uint),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_uint64_wrapper~wrapper(uint),
42u~uint
)~bool^not_equals
)~bool^logical_and
diff --git a/checker/src/test/resources/globalEnumValues.baseline b/checker/src/test/resources/globalEnumValues.baseline
index b2f7ac7dc..9a16481e6 100644
--- a/checker/src/test/resources/globalEnumValues.baseline
+++ b/checker/src/test/resources/globalEnumValues.baseline
@@ -1,6 +1,6 @@
Source: GlobalEnum.GAZ == 2
=====>
_==_(
- google.api.expr.test.v1.proto3.GlobalEnum.GAZ~int^google.api.expr.test.v1.proto3.GlobalEnum.GAZ,
+ cel.expr.conformance.proto3.GlobalEnum.GAZ~int^cel.expr.conformance.proto3.GlobalEnum.GAZ,
2~int
)~bool^equals
diff --git a/checker/src/test/resources/jsonStructTypeError.baseline b/checker/src/test/resources/jsonStructTypeError.baseline
index 83d6bd717..9923ddcda 100644
--- a/checker/src/test/resources/jsonStructTypeError.baseline
+++ b/checker/src/test/resources/jsonStructTypeError.baseline
@@ -1,8 +1,8 @@
-ource: x["iss"] != TestAllTypes{single_int32: 1}
+Source: x["iss"] != TestAllTypes{single_int32: 1}
declare x {
value google.protobuf.Struct
}
=====>
-ERROR: test_location:1:10: found no matching overload for '_!=_' applied to '(google.protobuf.Value, google.api.expr.test.v1.proto3.TestAllTypes)' (candidates: (%A3, %A3))
+ERROR: test_location:1:10: found no matching overload for '_!=_' applied to '(google.protobuf.Value, cel.expr.conformance.proto3.TestAllTypes)' (candidates: (%A3, %A3))
| x["iss"] != TestAllTypes{single_int32: 1}
| .........^
diff --git a/checker/src/test/resources/listElemTypeError.baseline b/checker/src/test/resources/listElemTypeError.baseline
index 469e5b0e6..47f3ccc95 100644
--- a/checker/src/test/resources/listElemTypeError.baseline
+++ b/checker/src/test/resources/listElemTypeError.baseline
@@ -1,11 +1,11 @@
Source: x + y
declare x {
- value list(google.api.expr.test.v1.proto3.TestAllTypes)
+ value list(cel.expr.conformance.proto3.TestAllTypes)
}
declare y {
value list(int)
}
=====>
-ERROR: test_location:1:3: found no matching overload for '_+_' applied to '(list(google.api.expr.test.v1.proto3.TestAllTypes), list(int))' (candidates: (int, int),(uint, uint),(double, double),(string, string),(bytes, bytes),(list(%A0), list(%A0)),(google.protobuf.Timestamp, google.protobuf.Duration),(google.protobuf.Duration, google.protobuf.Timestamp),(google.protobuf.Duration, google.protobuf.Duration))
+ERROR: test_location:1:3: found no matching overload for '_+_' applied to '(list(cel.expr.conformance.proto3.TestAllTypes), list(int))' (candidates: (int, int),(uint, uint),(double, double),(string, string),(bytes, bytes),(list(%A0), list(%A0)),(google.protobuf.Timestamp, google.protobuf.Duration),(google.protobuf.Duration, google.protobuf.Timestamp),(google.protobuf.Duration, google.protobuf.Duration))
| x + y
| ..^
\ No newline at end of file
diff --git a/checker/src/test/resources/listIndexTypeError.baseline b/checker/src/test/resources/listIndexTypeError.baseline
index 898590535..c0fca99bf 100644
--- a/checker/src/test/resources/listIndexTypeError.baseline
+++ b/checker/src/test/resources/listIndexTypeError.baseline
@@ -1,8 +1,8 @@
Source: x[1u]
declare x {
- value list(google.api.expr.test.v1.proto3.TestAllTypes)
+ value list(cel.expr.conformance.proto3.TestAllTypes)
}
=====>
-ERROR: test_location:1:2: found no matching overload for '_[_]' applied to '(list(google.api.expr.test.v1.proto3.TestAllTypes), uint)' (candidates: (list(%A0), int),(map(%A1, %B2), %A1))
+ERROR: test_location:1:2: found no matching overload for '_[_]' applied to '(list(cel.expr.conformance.proto3.TestAllTypes), uint)' (candidates: (list(%A0), int),(map(%A1, %B2), %A1))
| x[1u]
| .^
diff --git a/checker/src/test/resources/listOperators.baseline b/checker/src/test/resources/listOperators.baseline
index dba29ba4c..5ca16ba91 100644
--- a/checker/src/test/resources/listOperators.baseline
+++ b/checker/src/test/resources/listOperators.baseline
@@ -1,30 +1,30 @@
Source: (x + x)[1].single_int32 == size(x)
declare x {
- value list(google.api.expr.test.v1.proto3.TestAllTypes)
+ value list(cel.expr.conformance.proto3.TestAllTypes)
}
=====>
_==_(
_[_](
_+_(
- x~list(google.api.expr.test.v1.proto3.TestAllTypes)^x,
- x~list(google.api.expr.test.v1.proto3.TestAllTypes)^x
- )~list(google.api.expr.test.v1.proto3.TestAllTypes)^add_list,
+ x~list(cel.expr.conformance.proto3.TestAllTypes)^x,
+ x~list(cel.expr.conformance.proto3.TestAllTypes)^x
+ )~list(cel.expr.conformance.proto3.TestAllTypes)^add_list,
1~int
- )~google.api.expr.test.v1.proto3.TestAllTypes^index_list.single_int32~int,
+ )~cel.expr.conformance.proto3.TestAllTypes^index_list.single_int32~int,
size(
- x~list(google.api.expr.test.v1.proto3.TestAllTypes)^x
+ x~list(cel.expr.conformance.proto3.TestAllTypes)^x
)~int^size_list
)~bool^equals
Source: x.size() == size(x)
declare x {
- value list(google.api.expr.test.v1.proto3.TestAllTypes)
+ value list(cel.expr.conformance.proto3.TestAllTypes)
}
=====>
_==_(
- x~list(google.api.expr.test.v1.proto3.TestAllTypes)^x.size()~int^list_size,
+ x~list(cel.expr.conformance.proto3.TestAllTypes)^x.size()~int^list_size,
size(
- x~list(google.api.expr.test.v1.proto3.TestAllTypes)^x
+ x~list(cel.expr.conformance.proto3.TestAllTypes)^x
)~int^size_list
)~bool^equals
diff --git a/checker/src/test/resources/listRepeatedOperators.baseline b/checker/src/test/resources/listRepeatedOperators.baseline
index 4fd1fe5d5..e04335f98 100644
--- a/checker/src/test/resources/listRepeatedOperators.baseline
+++ b/checker/src/test/resources/listRepeatedOperators.baseline
@@ -1,12 +1,12 @@
Source: x.repeated_int64[x.single_int32] == 23
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_==_(
_[_](
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.repeated_int64~list(int),
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_int32~int
+ x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int64~list(int),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_int32~int
)~int^index_list,
23~int
)~bool^equals
diff --git a/checker/src/test/resources/mapEmpty.baseline b/checker/src/test/resources/mapEmpty.baseline
index a7dc95415..d8ec99820 100644
--- a/checker/src/test/resources/mapEmpty.baseline
+++ b/checker/src/test/resources/mapEmpty.baseline
@@ -1,11 +1,11 @@
Source: size(x.map_int64_nested_type) == 0
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_==_(
size(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.map_int64_nested_type~map(int, google.api.expr.test.v1.proto3.NestedTestAllTypes)
+ x~cel.expr.conformance.proto3.TestAllTypes^x.map_int64_nested_type~map(int, cel.expr.conformance.proto3.NestedTestAllTypes)
)~int^size_map,
0~int
)~bool^equals
diff --git a/checker/src/test/resources/mapExpr.baseline b/checker/src/test/resources/mapExpr.baseline
index 4fabfed85..2f7964bc0 100644
--- a/checker/src/test/resources/mapExpr.baseline
+++ b/checker/src/test/resources/mapExpr.baseline
@@ -1,22 +1,22 @@
Source: x.repeated_int64.map(x, double(x))
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
__comprehension__(
// Variable
x,
// Target
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.repeated_int64~list(int),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int64~list(int),
// Accumulator
- __result__,
+ @result,
// Init
[]~list(double),
// LoopCondition
true~bool,
// LoopStep
_+_(
- __result__~list(double)^__result__,
+ @result~list(double)^@result,
[
double(
x~int^x
@@ -24,20 +24,20 @@ __comprehension__(
]~list(double)
)~list(double)^add_list,
// Result
- __result__~list(double)^__result__)~list(double)
+ @result~list(double)^@result)~list(double)
Source: [].map(x, [].map(y, x in y && y in x))
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
ERROR: test_location:1:33: found no matching overload for '@in' applied to '(list(%elem0), %elem0)' (candidates: (%A7, list(%A7)),(%A8, map(%A8, %B9)))
- | [].map(x, [].map(y, x in y && y in x))
- | ................................^
+ | [].map(x, [].map(y, x in y && y in x))
+ | ................................^
Source: [{}.map(c,c,c)]+[{}.map(c,c,c)]
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_+_(
@@ -48,7 +48,7 @@ _+_(
// Target
{}~map(bool, dyn),
// Accumulator
- __result__,
+ @result,
// Init
[]~list(bool),
// LoopCondition
@@ -57,15 +57,15 @@ _+_(
_?_:_(
c~bool^c,
_+_(
- __result__~list(bool)^__result__,
+ @result~list(bool)^@result,
[
c~bool^c
]~list(bool)
)~list(bool)^add_list,
- __result__~list(bool)^__result__
+ @result~list(bool)^@result
)~list(bool)^conditional,
// Result
- __result__~list(bool)^__result__)~list(bool)
+ @result~list(bool)^@result)~list(bool)
]~list(list(bool)),
[
__comprehension__(
@@ -74,7 +74,7 @@ _+_(
// Target
{}~map(bool, dyn),
// Accumulator
- __result__,
+ @result,
// Init
[]~list(bool),
// LoopCondition
@@ -83,14 +83,14 @@ _+_(
_?_:_(
c~bool^c,
_+_(
- __result__~list(bool)^__result__,
+ @result~list(bool)^@result,
[
c~bool^c
]~list(bool)
)~list(bool)^add_list,
- __result__~list(bool)^__result__
+ @result~list(bool)^@result
)~list(bool)^conditional,
// Result
- __result__~list(bool)^__result__)~list(bool)
+ @result~list(bool)^@result)~list(bool)
]~list(list(bool))
-)~list(list(bool))^add_list
+)~list(list(bool))^add_list
\ No newline at end of file
diff --git a/checker/src/test/resources/mapFilterExpr.baseline b/checker/src/test/resources/mapFilterExpr.baseline
index 7e7c0175a..1a66e493c 100644
--- a/checker/src/test/resources/mapFilterExpr.baseline
+++ b/checker/src/test/resources/mapFilterExpr.baseline
@@ -1,15 +1,15 @@
Source: x.repeated_int64.map(x, x > 0, double(x))
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
__comprehension__(
// Variable
x,
// Target
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.repeated_int64~list(int),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int64~list(int),
// Accumulator
- __result__,
+ @result,
// Init
[]~list(double),
// LoopCondition
@@ -21,21 +21,21 @@ __comprehension__(
0~int
)~bool^greater_int64,
_+_(
- __result__~list(double)^__result__,
+ @result~list(double)^@result,
[
double(
x~int^x
)~double^int64_to_double
]~list(double)
)~list(double)^add_list,
- __result__~list(double)^__result__
+ @result~list(double)^@result
)~list(double)^conditional,
// Result
- __result__~list(double)^__result__)~list(double)
+ @result~list(double)^@result)~list(double)
Source: lists.filter(x, x > 1.5)
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
declare lists {
value dyn
@@ -47,7 +47,7 @@ __comprehension__(
// Target
lists~dyn^lists,
// Accumulator
- __result__,
+ @result,
// Init
[]~list(dyn),
// LoopCondition
@@ -59,19 +59,19 @@ __comprehension__(
1.5~double
)~bool^greater_double|greater_int64_double|greater_uint64_double,
_+_(
- __result__~list(dyn)^__result__,
+ @result~list(dyn)^@result,
[
x~dyn^x
]~list(dyn)
)~list(dyn)^add_list,
- __result__~list(dyn)^__result__
+ @result~list(dyn)^@result
)~list(dyn)^conditional,
// Result
- __result__~list(dyn)^__result__)~list(dyn)
+ @result~list(dyn)^@result)~list(dyn)
Source: args.user["myextension"].customAttributes.filter(x, x.name == "hobbies")
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
declare lists {
value dyn
@@ -89,7 +89,7 @@ __comprehension__(
"myextension"~string
)~dyn^index_map.customAttributes~dyn,
// Accumulator
- __result__,
+ @result,
// Init
[]~list(dyn),
// LoopCondition
@@ -101,12 +101,12 @@ __comprehension__(
"hobbies"~string
)~bool^equals,
_+_(
- __result__~list(dyn)^__result__,
+ @result~list(dyn)^@result,
[
x~dyn^x
]~list(dyn)
)~list(dyn)^add_list,
- __result__~list(dyn)^__result__
+ @result~list(dyn)^@result
)~list(dyn)^conditional,
// Result
- __result__~list(dyn)^__result__)~list(dyn)
+ @result~list(dyn)^@result)~list(dyn)
\ No newline at end of file
diff --git a/checker/src/test/resources/mapIndexTypeError.baseline b/checker/src/test/resources/mapIndexTypeError.baseline
index ad31488db..02fee54dd 100644
--- a/checker/src/test/resources/mapIndexTypeError.baseline
+++ b/checker/src/test/resources/mapIndexTypeError.baseline
@@ -1,8 +1,8 @@
Source: x[2].single_int32 == 23
declare x {
- value map(string, google.api.expr.test.v1.proto3.TestAllTypes)
+ value map(string, cel.expr.conformance.proto3.TestAllTypes)
}
=====>
-ERROR: test_location:1:2: found no matching overload for '_[_]' applied to '(map(string, google.api.expr.test.v1.proto3.TestAllTypes), int)' (candidates: (list(%A0), int),(map(%A1, %B2), %A1))
+ERROR: test_location:1:2: found no matching overload for '_[_]' applied to '(map(string, cel.expr.conformance.proto3.TestAllTypes), int)' (candidates: (list(%A0), int),(map(%A1, %B2), %A1))
| x[2].single_int32 == 23
| .^
diff --git a/checker/src/test/resources/mapOperators.baseline b/checker/src/test/resources/mapOperators.baseline
index 454d7f024..cf040f056 100644
--- a/checker/src/test/resources/mapOperators.baseline
+++ b/checker/src/test/resources/mapOperators.baseline
@@ -1,25 +1,25 @@
Source: x["a"].single_int32 == 23
declare x {
- value map(string, google.api.expr.test.v1.proto3.TestAllTypes)
+ value map(string, cel.expr.conformance.proto3.TestAllTypes)
}
=====>
_==_(
_[_](
- x~map(string, google.api.expr.test.v1.proto3.TestAllTypes)^x,
+ x~map(string, cel.expr.conformance.proto3.TestAllTypes)^x,
"a"~string
- )~google.api.expr.test.v1.proto3.TestAllTypes^index_map.single_int32~int,
+ )~cel.expr.conformance.proto3.TestAllTypes^index_map.single_int32~int,
23~int
)~bool^equals
Source: x.size() == size(x)
declare x {
- value map(string, google.api.expr.test.v1.proto3.TestAllTypes)
+ value map(string, cel.expr.conformance.proto3.TestAllTypes)
}
=====>
_==_(
- x~map(string, google.api.expr.test.v1.proto3.TestAllTypes)^x.size()~int^map_size,
+ x~map(string, cel.expr.conformance.proto3.TestAllTypes)^x.size()~int^map_size,
size(
- x~map(string, google.api.expr.test.v1.proto3.TestAllTypes)^x
+ x~map(string, cel.expr.conformance.proto3.TestAllTypes)^x
)~int^size_map
)~bool^equals
diff --git a/checker/src/test/resources/messageFieldSelect.baseline b/checker/src/test/resources/messageFieldSelect.baseline
index 8a219faaf..2247ce751 100644
--- a/checker/src/test/resources/messageFieldSelect.baseline
+++ b/checker/src/test/resources/messageFieldSelect.baseline
@@ -1,22 +1,22 @@
Source: x.single_nested_message.bb == 43 && has(x.single_nested_message) && has(x.single_int32) && has(x.repeated_int32) && has(x.map_int64_nested_type)
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_&&_(
_&&_(
_&&_(
_==_(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_nested_message~google.api.expr.test.v1.proto3.TestAllTypes.NestedMessage.bb~int,
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_nested_message~cel.expr.conformance.proto3.TestAllTypes.NestedMessage.bb~int,
43~int
)~bool^equals,
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_nested_message~test-only~~bool
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_nested_message~test-only~~bool
)~bool^logical_and,
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_int32~test-only~~bool
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_int32~test-only~~bool
)~bool^logical_and,
_&&_(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.repeated_int32~test-only~~bool,
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.map_int64_nested_type~test-only~~bool
+ x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int32~test-only~~bool,
+ x~cel.expr.conformance.proto3.TestAllTypes^x.map_int64_nested_type~test-only~~bool
)~bool^logical_and
)~bool^logical_and
diff --git a/checker/src/test/resources/messageFieldSelectError.baseline b/checker/src/test/resources/messageFieldSelectError.baseline
index 8c1808f1d..2bf3ad7f7 100644
--- a/checker/src/test/resources/messageFieldSelectError.baseline
+++ b/checker/src/test/resources/messageFieldSelectError.baseline
@@ -1,6 +1,6 @@
Source: x.single_nested_message.undefined == x.undefined
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
ERROR: test_location:1:24: undefined field 'undefined'
diff --git a/checker/src/test/resources/namespacedFunctions.baseline b/checker/src/test/resources/namespacedFunctions.baseline
index 449ea5110..b6ace0e3e 100644
--- a/checker/src/test/resources/namespacedFunctions.baseline
+++ b/checker/src/test/resources/namespacedFunctions.baseline
@@ -84,14 +84,14 @@ __comprehension__(
)~int^ns_func_overload
]~list(int),
// Accumulator
- __result__,
+ @result,
// Init
[]~list(int),
// LoopCondition
true~bool,
// LoopStep
_+_(
- __result__~list(int)^__result__,
+ @result~list(int)^@result,
[
_*_(
x~int^x,
@@ -100,7 +100,7 @@ __comprehension__(
]~list(int)
)~list(int)^add_list,
// Result
- __result__~list(int)^__result__)~list(int)
+ @result~list(int)^@result)~list(int)
Source: [1, 2].map(x, x * ns.func('test'))
declare ns.func {
@@ -119,14 +119,14 @@ __comprehension__(
2~int
]~list(int),
// Accumulator
- __result__,
+ @result,
// Init
[]~list(int),
// LoopCondition
true~bool,
// LoopStep
_+_(
- __result__~list(int)^__result__,
+ @result~list(int)^@result,
[
_*_(
x~int^x,
@@ -137,7 +137,7 @@ __comprehension__(
]~list(int)
)~list(int)^add_list,
// Result
- __result__~list(int)^__result__)~list(int)
+ @result~list(int)^@result)~list(int)
Source: func('hello')
declare ns.func {
@@ -165,4 +165,4 @@ ns.func(
ns.func(
"test"~string
)~int^ns_func_overload
-)~int^ns_member_overload
+)~int^ns_member_overload
\ No newline at end of file
diff --git a/checker/src/test/resources/namespacedVariables.baseline b/checker/src/test/resources/namespacedVariables.baseline
index ecb3cfc30..b7594c820 100644
--- a/checker/src/test/resources/namespacedVariables.baseline
+++ b/checker/src/test/resources/namespacedVariables.baseline
@@ -9,8 +9,8 @@ Source: msgVar.single_int32
declare ns.x {
value int
}
-declare google.api.expr.test.v1.proto3.msgVar {
- value google.api.expr.test.v1.proto3.TestAllTypes
+declare cel.expr.conformance.proto3.msgVar {
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
-google.api.expr.test.v1.proto3.msgVar~google.api.expr.test.v1.proto3.TestAllTypes^google.api.expr.test.v1.proto3.msgVar.single_int32~int
+cel.expr.conformance.proto3.msgVar~cel.expr.conformance.proto3.TestAllTypes^cel.expr.conformance.proto3.msgVar.single_int32~int
diff --git a/checker/src/test/resources/nestedEnums.baseline b/checker/src/test/resources/nestedEnums.baseline
index 98b5477c7..211fbf4c0 100644
--- a/checker/src/test/resources/nestedEnums.baseline
+++ b/checker/src/test/resources/nestedEnums.baseline
@@ -1,16 +1,16 @@
Source: x.single_nested_enum == TestAllTypes.NestedEnum.BAR
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_==_(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_nested_enum~int,
- google.api.expr.test.v1.proto3.TestAllTypes.NestedEnum.BAR~int^google.api.expr.test.v1.proto3.TestAllTypes.NestedEnum.BAR
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_nested_enum~int,
+ cel.expr.conformance.proto3.TestAllTypes.NestedEnum.BAR~int^cel.expr.conformance.proto3.TestAllTypes.NestedEnum.BAR
)~bool^equals
Source: single_nested_enum == TestAllTypes.NestedEnum.BAR
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
declare single_nested_enum {
value int
@@ -18,12 +18,12 @@ declare single_nested_enum {
=====>
_==_(
single_nested_enum~int^single_nested_enum,
- google.api.expr.test.v1.proto3.TestAllTypes.NestedEnum.BAR~int^google.api.expr.test.v1.proto3.TestAllTypes.NestedEnum.BAR
+ cel.expr.conformance.proto3.TestAllTypes.NestedEnum.BAR~int^cel.expr.conformance.proto3.TestAllTypes.NestedEnum.BAR
)~bool^equals
Source: TestAllTypes{single_nested_enum : TestAllTypes.NestedEnum.BAR}.single_nested_enum == 1
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
declare single_nested_enum {
value int
@@ -31,7 +31,7 @@ declare single_nested_enum {
=====>
_==_(
TestAllTypes{
- single_nested_enum:google.api.expr.test.v1.proto3.TestAllTypes.NestedEnum.BAR~int^google.api.expr.test.v1.proto3.TestAllTypes.NestedEnum.BAR
- }~google.api.expr.test.v1.proto3.TestAllTypes^google.api.expr.test.v1.proto3.TestAllTypes.single_nested_enum~int,
+ single_nested_enum:cel.expr.conformance.proto3.TestAllTypes.NestedEnum.BAR~int^cel.expr.conformance.proto3.TestAllTypes.NestedEnum.BAR
+ }~cel.expr.conformance.proto3.TestAllTypes^cel.expr.conformance.proto3.TestAllTypes.single_nested_enum~int,
1~int
)~bool^equals
diff --git a/checker/src/test/resources/nullableMessage.baseline b/checker/src/test/resources/nullableMessage.baseline
index d6920cede..6b5c13a68 100644
--- a/checker/src/test/resources/nullableMessage.baseline
+++ b/checker/src/test/resources/nullableMessage.baseline
@@ -1,25 +1,25 @@
Source: x.single_nested_message != null
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_!=_(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_nested_message~google.api.expr.test.v1.proto3.TestAllTypes.NestedMessage,
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_nested_message~cel.expr.conformance.proto3.TestAllTypes.NestedMessage,
null~null
)~bool^not_equals
Source: null == TestAllTypes{} || TestAllTypes{} == null
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_||_(
_==_(
null~null,
- TestAllTypes{}~google.api.expr.test.v1.proto3.TestAllTypes^google.api.expr.test.v1.proto3.TestAllTypes
+ TestAllTypes{}~cel.expr.conformance.proto3.TestAllTypes^cel.expr.conformance.proto3.TestAllTypes
)~bool^equals,
_==_(
- TestAllTypes{}~google.api.expr.test.v1.proto3.TestAllTypes^google.api.expr.test.v1.proto3.TestAllTypes,
+ TestAllTypes{}~cel.expr.conformance.proto3.TestAllTypes^cel.expr.conformance.proto3.TestAllTypes,
null~null
)~bool^equals
)~bool^logical_or
diff --git a/checker/src/test/resources/nullablePrimitiveError.baseline b/checker/src/test/resources/nullablePrimitiveError.baseline
index b6e4a7dc7..202497f03 100644
--- a/checker/src/test/resources/nullablePrimitiveError.baseline
+++ b/checker/src/test/resources/nullablePrimitiveError.baseline
@@ -1,6 +1,6 @@
Source: x.single_int64 != null
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
ERROR: test_location:1:16: found no matching overload for '_!=_' applied to '(int, null)' (candidates: (%A0, %A0))
diff --git a/checker/src/test/resources/nullableWrapper.baseline b/checker/src/test/resources/nullableWrapper.baseline
index f2e0165b0..d8e323193 100644
--- a/checker/src/test/resources/nullableWrapper.baseline
+++ b/checker/src/test/resources/nullableWrapper.baseline
@@ -1,10 +1,10 @@
Source: x.single_int64_wrapper == null
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_==_(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_int64_wrapper~wrapper(int),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_int64_wrapper~wrapper(int),
null~null
)~bool^equals
diff --git a/checker/src/test/resources/operatorsConditional.baseline b/checker/src/test/resources/operatorsConditional.baseline
index 72123b2ee..f567eb9d5 100644
--- a/checker/src/test/resources/operatorsConditional.baseline
+++ b/checker/src/test/resources/operatorsConditional.baseline
@@ -1,10 +1,10 @@
Source: false ? x.single_timestamp : null
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_?_:_(
false~bool,
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_timestamp~google.protobuf.Timestamp,
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_timestamp~google.protobuf.Timestamp,
null~null
)~google.protobuf.Timestamp^conditional
diff --git a/checker/src/test/resources/optionals.baseline b/checker/src/test/resources/optionals.baseline
index c78f5cc5a..a86fb1fc7 100644
--- a/checker/src/test/resources/optionals.baseline
+++ b/checker/src/test/resources/optionals.baseline
@@ -77,7 +77,7 @@ TestAllTypes{
{}~map(dyn, int),
"i"
)~optional_type(int)^select_optional_field
-}~google.api.expr.test.v1.proto3.TestAllTypes^google.api.expr.test.v1.proto3.TestAllTypes
+}~cel.expr.conformance.proto3.TestAllTypes^cel.expr.conformance.proto3.TestAllTypes
Source: [?a, ?b, 'world']
declare a {
diff --git a/checker/src/test/resources/proto2PrimitiveField.baseline b/checker/src/test/resources/proto2PrimitiveField.baseline
index 6d5351988..47546cc8b 100644
--- a/checker/src/test/resources/proto2PrimitiveField.baseline
+++ b/checker/src/test/resources/proto2PrimitiveField.baseline
@@ -1,6 +1,6 @@
Source: x.single_fixed32 != 0u && x.single_fixed64 > 1u && x.single_int32 != null
declare x {
- value google.api.expr.test.v1.proto2.TestAllTypes
+ value cel.expr.conformance.proto2.TestAllTypes
}
=====>
ERROR: test_location:1:67: found no matching overload for '_!=_' applied to '(int, null)' (candidates: (%A1, %A1))
@@ -9,10 +9,10 @@ ERROR: test_location:1:67: found no matching overload for '_!=_' applied to '(in
Source: x.nestedgroup.single_name == ''
declare x {
- value google.api.expr.test.v1.proto2.TestAllTypes
+ value cel.expr.conformance.proto2.TestAllTypes
}
=====>
_==_(
- x~google.api.expr.test.v1.proto2.TestAllTypes^x.nestedgroup~google.api.expr.test.v1.proto2.TestAllTypes.NestedGroup.single_name~string,
+ x~cel.expr.conformance.proto2.TestAllTypes^x.nestedgroup~cel.expr.conformance.proto2.TestAllTypes.NestedGroup.single_name~string,
""~string
)~bool^equals
diff --git a/checker/src/test/resources/quantifiers.baseline b/checker/src/test/resources/quantifiers.baseline
index b2d651c8c..3f204a6f5 100644
--- a/checker/src/test/resources/quantifiers.baseline
+++ b/checker/src/test/resources/quantifiers.baseline
@@ -1,6 +1,6 @@
Source: x.repeated_int64.all(e, e > 0) && x.repeated_int64.exists(e, e < 0) && x.repeated_int64.exists_one(e, e == 0)
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_&&_(
@@ -9,58 +9,58 @@ _&&_(
// Variable
e,
// Target
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.repeated_int64~list(int),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int64~list(int),
// Accumulator
- __result__,
+ @result,
// Init
true~bool,
// LoopCondition
@not_strictly_false(
- __result__~bool^__result__
+ @result~bool^@result
)~bool^not_strictly_false,
// LoopStep
_&&_(
- __result__~bool^__result__,
+ @result~bool^@result,
_>_(
e~int^e,
0~int
)~bool^greater_int64
)~bool^logical_and,
// Result
- __result__~bool^__result__)~bool,
+ @result~bool^@result)~bool,
__comprehension__(
// Variable
e,
// Target
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.repeated_int64~list(int),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int64~list(int),
// Accumulator
- __result__,
+ @result,
// Init
false~bool,
// LoopCondition
@not_strictly_false(
!_(
- __result__~bool^__result__
+ @result~bool^@result
)~bool^logical_not
)~bool^not_strictly_false,
// LoopStep
_||_(
- __result__~bool^__result__,
+ @result~bool^@result,
_<_(
e~int^e,
0~int
)~bool^less_int64
)~bool^logical_or,
// Result
- __result__~bool^__result__)~bool
+ @result~bool^@result)~bool
)~bool^logical_and,
__comprehension__(
// Variable
e,
// Target
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.repeated_int64~list(int),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int64~list(int),
// Accumulator
- __result__,
+ @result,
// Init
0~int,
// LoopCondition
@@ -72,14 +72,14 @@ _&&_(
0~int
)~bool^equals,
_+_(
- __result__~int^__result__,
+ @result~int^@result,
1~int
)~int^add_int64,
- __result__~int^__result__
+ @result~int^@result
)~int^conditional,
// Result
_==_(
- __result__~int^__result__,
+ @result~int^@result,
1~int
)~bool^equals)~bool
-)~bool^logical_and
+)~bool^logical_and
\ No newline at end of file
diff --git a/checker/src/test/resources/quantifiersErrors.baseline b/checker/src/test/resources/quantifiersErrors.baseline
index 2f6d1eac6..17c1736c5 100644
--- a/checker/src/test/resources/quantifiersErrors.baseline
+++ b/checker/src/test/resources/quantifiersErrors.baseline
@@ -1,9 +1,9 @@
Source: x.all(e, 0)
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
-ERROR: test_location:1:1: expression of type 'google.api.expr.test.v1.proto3.TestAllTypes' cannot be range of a comprehension (must be list, map, or dynamic)
+ERROR: test_location:1:1: expression of type 'cel.expr.conformance.proto3.TestAllTypes' cannot be range of a comprehension (must be list, map, or dynamic)
| x.all(e, 0)
| ^
ERROR: test_location:1:6: found no matching overload for '_&&_' applied to '(bool, int)' (candidates: (bool, bool))
diff --git a/checker/src/test/resources/referenceTypeAbsolute.baseline b/checker/src/test/resources/referenceTypeAbsolute.baseline
index 7bd4487e5..7680854d4 100644
--- a/checker/src/test/resources/referenceTypeAbsolute.baseline
+++ b/checker/src/test/resources/referenceTypeAbsolute.baseline
@@ -1,3 +1,3 @@
-Source: .google.api.expr.test.v1.proto3.TestAllTypes
+Source: .cel.expr.conformance.proto3.TestAllTypes
=====>
-google.api.expr.test.v1.proto3.TestAllTypes~type(google.api.expr.test.v1.proto3.TestAllTypes)^google.api.expr.test.v1.proto3.TestAllTypes
+cel.expr.conformance.proto3.TestAllTypes~type(cel.expr.conformance.proto3.TestAllTypes)^cel.expr.conformance.proto3.TestAllTypes
diff --git a/checker/src/test/resources/referenceTypeRelative.baseline b/checker/src/test/resources/referenceTypeRelative.baseline
index abe4260d5..e0c681d61 100644
--- a/checker/src/test/resources/referenceTypeRelative.baseline
+++ b/checker/src/test/resources/referenceTypeRelative.baseline
@@ -1,3 +1,3 @@
Source: proto3.TestAllTypes
=====>
-google.api.expr.test.v1.proto3.TestAllTypes~type(google.api.expr.test.v1.proto3.TestAllTypes)^google.api.expr.test.v1.proto3.TestAllTypes
+cel.expr.conformance.proto3.TestAllTypes~type(cel.expr.conformance.proto3.TestAllTypes)^cel.expr.conformance.proto3.TestAllTypes
diff --git a/checker/src/test/resources/referenceValue.baseline b/checker/src/test/resources/referenceValue.baseline
index a6ded5464..165b0bc6b 100644
--- a/checker/src/test/resources/referenceValue.baseline
+++ b/checker/src/test/resources/referenceValue.baseline
@@ -1,6 +1,6 @@
Source: x
declare container.x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
-container.x~google.api.expr.test.v1.proto3.TestAllTypes^container.x
+container.x~cel.expr.conformance.proto3.TestAllTypes^container.x
diff --git a/checker/src/test/resources/standardEnvDump.baseline b/checker/src/test/resources/standardEnvDump.baseline
index df1c66553..60d19f66d 100644
--- a/checker/src/test/resources/standardEnvDump.baseline
+++ b/checker/src/test/resources/standardEnvDump.baseline
@@ -218,11 +218,11 @@ declare getSeconds {
}
declare int {
value type(int)
+ function int64_to_int64 (int) -> int
function uint64_to_int64 (uint) -> int
function double_to_int64 (double) -> int
function string_to_int64 (string) -> int
function timestamp_to_int64 (google.protobuf.Timestamp) -> int
- function int64_to_int64 (int) -> int
}
declare list {
value type(list(dyn))
diff --git a/checker/src/test/resources/types.baseline b/checker/src/test/resources/types.baseline
index 61f3f4423..939e0ed97 100644
--- a/checker/src/test/resources/types.baseline
+++ b/checker/src/test/resources/types.baseline
@@ -27,14 +27,14 @@ __comprehension__(
// Target
{}~map(dyn, dyn),
// Accumulator
- __result__,
+ @result,
// Init
[]~list(list(dyn)),
// LoopCondition
true~bool,
// LoopStep
_+_(
- __result__~list(list(dyn))^__result__,
+ @result~list(list(dyn))^@result,
[
[
c~dyn^c,
@@ -45,4 +45,4 @@ __comprehension__(
]~list(list(dyn))
)~list(list(dyn))^add_list,
// Result
- __result__~list(list(dyn))^__result__)~list(list(dyn))
+ @result~list(list(dyn))^@result)~list(list(dyn))
\ No newline at end of file
diff --git a/checker/src/test/resources/userFunctionAddsOverload.baseline b/checker/src/test/resources/userFunctionAddsOverload.baseline
index 3a8cb44ad..515afa9eb 100644
--- a/checker/src/test/resources/userFunctionAddsOverload.baseline
+++ b/checker/src/test/resources/userFunctionAddsOverload.baseline
@@ -1,14 +1,14 @@
Source: size(x) > 4
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
declare size {
- function size_message (google.api.expr.test.v1.proto3.TestAllTypes) -> int
+ function size_message (cel.expr.conformance.proto3.TestAllTypes) -> int
}
=====>
_>_(
size(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x
+ x~cel.expr.conformance.proto3.TestAllTypes^x
)~int^size_message,
4~int
)~bool^greater_int64
diff --git a/checker/src/test/resources/wrapper.baseline b/checker/src/test/resources/wrapper.baseline
index 2180c4a5f..3b3b82375 100644
--- a/checker/src/test/resources/wrapper.baseline
+++ b/checker/src/test/resources/wrapper.baseline
@@ -1,11 +1,11 @@
Source: x.single_int64_wrapper + 1 != 23
declare x {
- value google.api.expr.test.v1.proto3.TestAllTypes
+ value cel.expr.conformance.proto3.TestAllTypes
}
=====>
_!=_(
_+_(
- x~google.api.expr.test.v1.proto3.TestAllTypes^x.single_int64_wrapper~wrapper(int),
+ x~cel.expr.conformance.proto3.TestAllTypes^x.single_int64_wrapper~wrapper(int),
1~int
)~int^add_int64,
23~int
diff --git a/common/ast/BUILD.bazel b/common/ast/BUILD.bazel
index 0a27ae0bc..c4e2455d5 100644
--- a/common/ast/BUILD.bazel
+++ b/common/ast/BUILD.bazel
@@ -30,11 +30,6 @@ java_library(
exports = ["//common/src/main/java/dev/cel/common/ast:expr_factory"],
)
-java_library(
- name = "expr_util",
- exports = ["//common/src/main/java/dev/cel/common/ast:expr_util"],
-)
-
java_library(
name = "mutable_expr",
exports = ["//common/src/main/java/dev/cel/common/ast:mutable_expr"],
diff --git a/common/src/main/java/dev/cel/common/BUILD.bazel b/common/src/main/java/dev/cel/common/BUILD.bazel
index 9e4fa12fd..31fd401c5 100644
--- a/common/src/main/java/dev/cel/common/BUILD.bazel
+++ b/common/src/main/java/dev/cel/common/BUILD.bazel
@@ -60,7 +60,6 @@ java_library(
"//common/types",
"//common/types:cel_types",
"//common/types:type_providers",
- "@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
@@ -79,7 +78,7 @@ java_library(
"//:auto_value",
"//common/annotations",
"//common/internal:safe_string_formatter",
- "//common/types:cel_types",
+ "//common/types:cel_proto_types",
"//common/types:type_providers",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
@@ -119,7 +118,7 @@ java_library(
deps = [
"//common",
"//common/ast:expr_converter",
- "//common/types:cel_types",
+ "//common/types:cel_proto_types",
"@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
diff --git a/common/src/main/java/dev/cel/common/CelAbstractSyntaxTree.java b/common/src/main/java/dev/cel/common/CelAbstractSyntaxTree.java
index 59023adfd..6b3b6a74f 100644
--- a/common/src/main/java/dev/cel/common/CelAbstractSyntaxTree.java
+++ b/common/src/main/java/dev/cel/common/CelAbstractSyntaxTree.java
@@ -14,7 +14,6 @@
package dev.cel.common;
-import dev.cel.expr.Type;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -24,7 +23,6 @@
import dev.cel.common.ast.CelExpr;
import dev.cel.common.ast.CelReference;
import dev.cel.common.types.CelType;
-import dev.cel.common.types.CelTypes;
import dev.cel.common.types.SimpleType;
import java.util.Map;
import java.util.NoSuchElementException;
@@ -94,14 +92,6 @@ public CelType getResultType() {
return isChecked() ? getType(getExpr().id()).get() : SimpleType.DYN;
}
- /**
- * For a type checked abstract syntax tree the resulting type is returned in proto format
- * described in checked.proto. Otherwise, the dynamic type is returned.
- */
- public Type getProtoResultType() {
- return CelTypes.celTypeToType(getResultType());
- }
-
/**
* Returns the {@link CelSource} that was used during construction of the abstract syntax tree.
*/
diff --git a/common/src/main/java/dev/cel/common/CelException.java b/common/src/main/java/dev/cel/common/CelException.java
index 55c8623a4..9d80a9ba1 100644
--- a/common/src/main/java/dev/cel/common/CelException.java
+++ b/common/src/main/java/dev/cel/common/CelException.java
@@ -27,6 +27,11 @@ public CelException(String message, Throwable cause) {
super(message, cause);
}
+ public CelException(String message, CelErrorCode errorCode) {
+ super(message);
+ this.errorCode = errorCode;
+ }
+
public CelException(String message, Throwable cause, CelErrorCode errorCode) {
super(message, cause);
this.errorCode = errorCode;
diff --git a/common/src/main/java/dev/cel/common/CelOptions.java b/common/src/main/java/dev/cel/common/CelOptions.java
index 2568099fb..3e841471f 100644
--- a/common/src/main/java/dev/cel/common/CelOptions.java
+++ b/common/src/main/java/dev/cel/common/CelOptions.java
@@ -67,6 +67,8 @@ public enum ProtoUnsetFieldOptions {
public abstract boolean retainUnbalancedLogicalExpressions();
+ public abstract boolean enableHiddenAccumulatorVar();
+
// Type-Checker related options
public abstract boolean enableCompileTimeOverloadResolution();
@@ -109,6 +111,14 @@ public enum ProtoUnsetFieldOptions {
public abstract ProtoUnsetFieldOptions fromProtoUnsetFieldOption();
+ public abstract boolean enableStringConversion();
+
+ public abstract boolean enableStringConcatenation();
+
+ public abstract boolean enableListConcatenation();
+
+ public abstract boolean enableComprehension();
+
public abstract Builder toBuilder();
public ImmutableSet toExprFeatures() {
@@ -180,6 +190,7 @@ public static Builder newBuilder() {
.populateMacroCalls(false)
.retainRepeatedUnaryOperators(false)
.retainUnbalancedLogicalExpressions(false)
+ .enableHiddenAccumulatorVar(false)
// Type-Checker options
.enableCompileTimeOverloadResolution(false)
.enableHomogeneousLiterals(false)
@@ -200,7 +211,11 @@ public static Builder newBuilder() {
.enableCelValue(false)
.comprehensionMaxIterations(-1)
.unwrapWellKnownTypesOnFunctionDispatch(true)
- .fromProtoUnsetFieldOption(ProtoUnsetFieldOptions.BIND_DEFAULT);
+ .fromProtoUnsetFieldOption(ProtoUnsetFieldOptions.BIND_DEFAULT)
+ .enableStringConversion(true)
+ .enableStringConcatenation(true)
+ .enableListConcatenation(true)
+ .enableComprehension(true);
}
/**
@@ -307,6 +322,16 @@ public abstract static class Builder {
*/
public abstract Builder retainUnbalancedLogicalExpressions(boolean value);
+ /**
+ * Enable the use of a hidden accumulator variable name.
+ *
+ * This is a temporary option to transition to using an internal identifier for the
+ * accumulator variable used by builtin comprehension macros. When enabled, parses result in a
+ * semantically equivalent AST, but with a different accumulator variable that can't be directly
+ * referenced in the source expression.
+ */
+ public abstract Builder enableHiddenAccumulatorVar(boolean value);
+
// Type-Checker related options
/**
@@ -417,7 +442,11 @@ public abstract static class Builder {
/**
* Use {@code UnsignedLong} values to represent unsigned integers within CEL instead of the
* nearest Java equivalent of {@code Long}.
+ *
+ * @deprecated Do not use. This option is enabled by default in the currently supported feature
+ * set {@link CelOptions#DEFAULT}. This flag will be removed in the future.
*/
+ @Deprecated
public abstract Builder enableUnsignedLongs(boolean value);
/**
@@ -504,6 +533,31 @@ public abstract static class Builder {
*/
public abstract Builder fromProtoUnsetFieldOption(ProtoUnsetFieldOptions value);
+ /**
+ * Enables string() overloads for the runtime. This option exists to maintain parity with
+ * cel-cpp interpreter options.
+ */
+ public abstract Builder enableStringConversion(boolean value);
+
+ /**
+ * Enables string concatenation overload for the runtime. This option exists to maintain parity
+ * with cel-cpp interpreter options.
+ */
+ public abstract Builder enableStringConcatenation(boolean value);
+
+ /**
+ * Enables list concatenation overload for the runtime. This option exists to maintain parity
+ * with cel-cpp interpreter options.
+ */
+ public abstract Builder enableListConcatenation(boolean value);
+
+ /**
+ * Enables comprehension (macros) for the runtime. Setting false has the same effect with
+ * assigning 0 for {@link #comprehensionMaxIterations()}. This option exists to maintain parity
+ * with cel-cpp interpreter options.
+ */
+ public abstract Builder enableComprehension(boolean value);
+
public abstract CelOptions build();
}
}
diff --git a/common/src/main/java/dev/cel/common/CelOverloadDecl.java b/common/src/main/java/dev/cel/common/CelOverloadDecl.java
index 247f86bc1..1d9c61e9d 100644
--- a/common/src/main/java/dev/cel/common/CelOverloadDecl.java
+++ b/common/src/main/java/dev/cel/common/CelOverloadDecl.java
@@ -25,8 +25,8 @@
import com.google.errorprone.annotations.CheckReturnValue;
import com.google.errorprone.annotations.Immutable;
import dev.cel.common.types.CelKind;
+import dev.cel.common.types.CelProtoTypes;
import dev.cel.common.types.CelType;
-import dev.cel.common.types.CelTypes;
import java.util.Arrays;
import java.util.List;
@@ -230,10 +230,10 @@ public static Overload celOverloadToOverload(CelOverloadDecl overload) {
return Overload.newBuilder()
.setIsInstanceFunction(overload.isInstanceFunction())
.setOverloadId(overload.overloadId())
- .setResultType(CelTypes.celTypeToType(overload.resultType()))
+ .setResultType(CelProtoTypes.celTypeToType(overload.resultType()))
.addAllParams(
overload.parameterTypes().stream()
- .map(CelTypes::celTypeToType)
+ .map(CelProtoTypes::celTypeToType)
.collect(toImmutableList()))
.addAllTypeParams(overload.typeParameterNames())
.setDoc(overload.doc())
@@ -244,11 +244,11 @@ public static CelOverloadDecl overloadToCelOverload(Overload overload) {
return CelOverloadDecl.newBuilder()
.setIsInstanceFunction(overload.getIsInstanceFunction())
.setOverloadId(overload.getOverloadId())
- .setResultType(CelTypes.typeToCelType(overload.getResultType()))
+ .setResultType(CelProtoTypes.typeToCelType(overload.getResultType()))
.setDoc(overload.getDoc())
.addParameterTypes(
overload.getParamsList().stream()
- .map(CelTypes::typeToCelType)
+ .map(CelProtoTypes::typeToCelType)
.collect(toImmutableList()))
.build();
}
diff --git a/common/src/main/java/dev/cel/common/CelProtoAbstractSyntaxTree.java b/common/src/main/java/dev/cel/common/CelProtoAbstractSyntaxTree.java
index f8374e114..7230c80af 100644
--- a/common/src/main/java/dev/cel/common/CelProtoAbstractSyntaxTree.java
+++ b/common/src/main/java/dev/cel/common/CelProtoAbstractSyntaxTree.java
@@ -29,7 +29,7 @@
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CheckReturnValue;
import dev.cel.common.ast.CelExprConverter;
-import dev.cel.common.types.CelTypes;
+import dev.cel.common.types.CelProtoTypes;
import java.util.Collection;
import java.util.Map.Entry;
@@ -66,7 +66,8 @@ private CelProtoAbstractSyntaxTree(CheckedExpr checkedExpr) {
Entry::getKey,
v -> CelExprConverter.exprReferenceToCelReference(v.getValue()))),
checkedExpr.getTypeMapMap().entrySet().stream()
- .collect(toImmutableMap(Entry::getKey, v -> CelTypes.typeToCelType(v.getValue()))));
+ .collect(
+ toImmutableMap(Entry::getKey, v -> CelProtoTypes.typeToCelType(v.getValue()))));
}
private CelProtoAbstractSyntaxTree(CelAbstractSyntaxTree ast) {
@@ -98,7 +99,8 @@ private CelProtoAbstractSyntaxTree(CelAbstractSyntaxTree ast) {
v -> CelExprConverter.celReferenceToExprReference(v.getValue()))));
checkedExprBuilder.putAllTypeMap(
ast.getTypeMap().entrySet().stream()
- .collect(toImmutableMap(Entry::getKey, v -> CelTypes.celTypeToType(v.getValue()))));
+ .collect(
+ toImmutableMap(Entry::getKey, v -> CelProtoTypes.celTypeToType(v.getValue()))));
}
this.checkedExpr = checkedExprBuilder.build();
@@ -182,7 +184,7 @@ public ParsedExpr toParsedExpr() {
*/
@CheckReturnValue
public Type getProtoResultType() {
- return CelTypes.celTypeToType(ast.getResultType());
+ return CelProtoTypes.celTypeToType(ast.getResultType());
}
private static ImmutableList fromCelExtensionsToExprExtensions(
diff --git a/common/src/main/java/dev/cel/common/ast/BUILD.bazel b/common/src/main/java/dev/cel/common/ast/BUILD.bazel
index a5736cff9..a30f144e6 100644
--- a/common/src/main/java/dev/cel/common/ast/BUILD.bazel
+++ b/common/src/main/java/dev/cel/common/ast/BUILD.bazel
@@ -103,22 +103,6 @@ java_library(
],
)
-java_library(
- name = "expr_util",
- srcs = ["CelExprUtil.java"],
- tags = [
- ],
- deps = [
- ":ast",
- "//bundle:cel",
- "//common",
- "//common:compiler_common",
- "//runtime",
- "@maven//:com_google_errorprone_error_prone_annotations",
- "@maven//:com_google_guava_guava",
- ],
-)
-
java_library(
name = "mutable_expr",
srcs = MUTABLE_EXPR_SOURCES,
diff --git a/common/src/main/java/dev/cel/common/ast/CelExprUtil.java b/common/src/main/java/dev/cel/common/ast/CelExprUtil.java
deleted file mode 100644
index 20217128e..000000000
--- a/common/src/main/java/dev/cel/common/ast/CelExprUtil.java
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2023 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package dev.cel.common.ast;
-
-import com.google.errorprone.annotations.CanIgnoreReturnValue;
-import dev.cel.bundle.Cel;
-import dev.cel.common.CelAbstractSyntaxTree;
-import dev.cel.common.CelSource;
-import dev.cel.common.CelValidationException;
-import dev.cel.runtime.CelEvaluationException;
-
-/** Utility class for working with CelExpr. */
-public final class CelExprUtil {
-
- /**
- * Type-checks and evaluates a CelExpr. This method should be used in the context of validating or
- * optimizing an AST.
- *
- * @return Evaluated result.
- * @throws CelValidationException if CelExpr fails to type-check.
- * @throws CelEvaluationException if CelExpr fails to evaluate.
- */
- @CanIgnoreReturnValue
- public static Object evaluateExpr(Cel cel, CelExpr expr)
- throws CelValidationException, CelEvaluationException {
- CelAbstractSyntaxTree ast =
- CelAbstractSyntaxTree.newParsedAst(expr, CelSource.newBuilder().build());
- ast = cel.check(ast).getAst();
-
- return cel.createProgram(ast).eval();
- }
-
- /**
- * Type-checks and evaluates a CelExpr. The evaluated result is then checked to see if it's the
- * expected result type.
- *
- * This method should be used in the context of validating or optimizing an AST.
- *
- * @return Evaluated result.
- * @throws CelValidationException if CelExpr fails to type-check.
- * @throws CelEvaluationException if CelExpr fails to evaluate.
- * @throws IllegalStateException if the evaluated result is not of type {@code
- * expectedResultType}.
- */
- @CanIgnoreReturnValue
- public static Object evaluateExpr(Cel cel, CelExpr expr, Class> expectedResultType)
- throws CelValidationException, CelEvaluationException {
- Object result = evaluateExpr(cel, expr);
- if (!expectedResultType.isInstance(result)) {
- throw new IllegalStateException(
- String.format(
- "Expected %s type but got %s instead",
- expectedResultType.getName(), result.getClass().getName()));
- }
- return result;
- }
-
- private CelExprUtil() {}
-}
diff --git a/common/src/main/java/dev/cel/common/internal/BUILD.bazel b/common/src/main/java/dev/cel/common/internal/BUILD.bazel
index 6b83b441a..bb9d67bff 100644
--- a/common/src/main/java/dev/cel/common/internal/BUILD.bazel
+++ b/common/src/main/java/dev/cel/common/internal/BUILD.bazel
@@ -126,7 +126,6 @@ java_library(
"//common:proto_json_adapter",
"//common:runtime_exception",
"//common/annotations",
- "@cel_spec//proto/cel/expr:expr_java_proto",
"@maven//:com_google_code_findbugs_annotations",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
diff --git a/common/src/main/java/dev/cel/common/internal/BasicCodePointArray.java b/common/src/main/java/dev/cel/common/internal/BasicCodePointArray.java
index a240df763..9f1bb5cb6 100644
--- a/common/src/main/java/dev/cel/common/internal/BasicCodePointArray.java
+++ b/common/src/main/java/dev/cel/common/internal/BasicCodePointArray.java
@@ -38,7 +38,7 @@
@SuppressWarnings("Immutable") // char[] is not exposed externally, thus cannot be mutated.
public abstract class BasicCodePointArray extends CelCodePointArray {
- @SuppressWarnings("AutoValueImmutableFields")
+ @SuppressWarnings("mutable")
abstract char[] codePoints();
abstract int offset();
diff --git a/common/src/main/java/dev/cel/common/internal/Latin1CodePointArray.java b/common/src/main/java/dev/cel/common/internal/Latin1CodePointArray.java
index 9e54c3a6c..d9536cbb4 100644
--- a/common/src/main/java/dev/cel/common/internal/Latin1CodePointArray.java
+++ b/common/src/main/java/dev/cel/common/internal/Latin1CodePointArray.java
@@ -38,7 +38,7 @@
@SuppressWarnings("Immutable") // byte[] is not exposed externally, thus cannot be mutated.
public abstract class Latin1CodePointArray extends CelCodePointArray {
- @SuppressWarnings("AutoValueImmutableFields")
+ @SuppressWarnings("mutable")
abstract byte[] codePoints();
abstract int offset();
diff --git a/common/src/main/java/dev/cel/common/internal/ProtoAdapter.java b/common/src/main/java/dev/cel/common/internal/ProtoAdapter.java
index 29fece49c..28da7e5d0 100644
--- a/common/src/main/java/dev/cel/common/internal/ProtoAdapter.java
+++ b/common/src/main/java/dev/cel/common/internal/ProtoAdapter.java
@@ -17,7 +17,6 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
-import dev.cel.expr.ExprValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.primitives.Ints;
@@ -205,9 +204,6 @@ public Object adaptProtoToValue(MessageOrBuilder proto) {
@SuppressWarnings({"unchecked", "rawtypes"})
public Optional