Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/src/main/java/dev/cel/extensions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ java_library(
deps = [
"//common:compiler_common",
"//common/ast",
"//common/types",
"//compiler:compiler_builder",
"//extensions:extension_library",
"//parser:macro",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import com.google.errorprone.annotations.Immutable;
import dev.cel.common.CelFunctionDecl;
import dev.cel.common.CelIssue;
import dev.cel.common.CelOverloadDecl;
import dev.cel.common.ast.CelExpr;
import dev.cel.common.types.ListType;
import dev.cel.common.types.SimpleType;
import dev.cel.common.types.TypeParamType;
import dev.cel.compiler.CelCompilerLibrary;
import dev.cel.parser.CelMacro;
import dev.cel.parser.CelMacroExprFactory;
Expand Down Expand Up @@ -62,7 +66,15 @@ public int version() {

@Override
public ImmutableSet<CelFunctionDecl> functions() {
return ImmutableSet.of();
// TODO: Add bindings for block once decorator support is available.
return ImmutableSet.of(
CelFunctionDecl.newFunctionDeclaration(
"cel.@block",
CelOverloadDecl.newGlobalOverload(
"cel_block_list",
TypeParamType.create("T"),
ListType.create(SimpleType.DYN),
TypeParamType.create("T"))));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,18 @@ public void setRuntimeOptions(CelRuntimeBuilder runtimeBuilder) {
@Override
public void setRuntimeOptions(
CelRuntimeBuilder runtimeBuilder, RuntimeEquality runtimeEquality, CelOptions celOptions) {
for (Function function : functions) {
for (CelOverloadDecl overload : function.functionDecl.overloads()) {
switch (overload.overloadId()) {
case MAP_INSERT_OVERLOAD_MAP_MAP:
runtimeBuilder.addFunctionBindings(
CelFunctionBinding.from(
MAP_INSERT_OVERLOAD_MAP_MAP,
Map.class,
Map.class,
(map1, map2) -> mapInsertMap(map1, map2, runtimeEquality)));
break;
case MAP_INSERT_OVERLOAD_KEY_VALUE:
runtimeBuilder.addFunctionBindings(
CelFunctionBinding.from(
MAP_INSERT_OVERLOAD_KEY_VALUE,
ImmutableList.of(Map.class, Object.class, Object.class),
args -> mapInsertKeyValue(args, runtimeEquality)));
break;
default:
// Nothing to add.
}
}
}
runtimeBuilder.addFunctionBindings(
CelFunctionBinding.fromOverloads(
MAP_INSERT_FUNCTION,
CelFunctionBinding.from(
MAP_INSERT_OVERLOAD_MAP_MAP,
Map.class,
Map.class,
(map1, map2) -> mapInsertMap(map1, map2, runtimeEquality)),
CelFunctionBinding.from(
MAP_INSERT_OVERLOAD_KEY_VALUE,
ImmutableList.of(Map.class, Object.class, Object.class),
args -> mapInsertKeyValue(args, runtimeEquality))));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public void library() {
CelExtensions.getExtensionLibrary("bindings", CelOptions.DEFAULT);
assertThat(library.name()).isEqualTo("bindings");
assertThat(library.latest().version()).isEqualTo(0);
assertThat(library.version(0).functions()).isEmpty();
assertThat(library.version(0).functions().stream().map(CelFunctionDecl::name))
.containsExactly("cel.@block");
assertThat(library.version(0).macros().stream().map(CelMacro::getFunction))
.containsExactly("bind");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ java_library(
"//parser:unparser",
"//runtime",
"//runtime:function_binding",
"//runtime:partial_vars",
"//runtime:program",
"//runtime:unknown_attributes",
"//testing:baseline_test_case",
"@maven//:junit_junit",
"@maven//:com_google_testparameterinjector_test_parameter_injector",
Expand Down
Loading
Loading