Skip to content

Commit

Permalink
Add library declaring CEL optional definitions for the C++ type checker.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 682469153
  • Loading branch information
jnthntatum authored and copybara-github committed Oct 4, 2024
1 parent fd93666 commit 4088278
Show file tree
Hide file tree
Showing 16 changed files with 729 additions and 102 deletions.
40 changes: 37 additions & 3 deletions checker/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,10 @@ cc_library(
"//checker/internal:builtins_arena",
"//common:constant",
"//common:decl",
"//common:memory",
"//common:type",
"//internal:status_macros",
"@com_google_absl//absl/base:no_destructor",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/status",
"@com_google_protobuf//:protobuf",
],
)

Expand All @@ -146,3 +143,40 @@ cc_test(
"@com_google_absl//absl/status:status_matchers",
],
)

cc_library(
name = "optional",
srcs = ["optional.cc"],
hdrs = ["optional.h"],
deps = [
":type_checker_builder",
"//base:builtins",
"//checker/internal:builtins_arena",
"//common:decl",
"//common:type",
"//internal:status_macros",
"@com_google_absl//absl/base:no_destructor",
"@com_google_absl//absl/status",
],
)

cc_test(
name = "optional_test",
srcs = ["optional_test.cc"],
deps = [
":optional",
":standard_library",
":type_check_issue",
":type_checker",
":type_checker_builder",
"//base/ast_internal:ast_impl",
"//base/ast_internal:expr",
"//checker/internal:test_ast_helpers",
"//extensions/protobuf:value",
"//internal:testing",
"@com_google_absl//absl/status:status_matchers",
"@com_google_absl//absl/strings",
"@com_google_cel_spec//proto/test/v1/proto3:test_all_types_cc_proto",
"@com_google_protobuf//:protobuf",
],
)
1 change: 1 addition & 0 deletions checker/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ cc_library(
"//extensions/protobuf:ast_converters",
"//internal:status_macros",
"//parser",
"//parser:options",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings:string_view",
],
Expand Down
6 changes: 5 additions & 1 deletion checker/internal/test_ast_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "common/ast.h"
#include "extensions/protobuf/ast_converters.h"
#include "internal/status_macros.h"
#include "parser/options.h"
#include "parser/parser.h"

namespace cel::checker_internal {
Expand All @@ -30,7 +31,10 @@ using ::google::api::expr::parser::Parse;

absl::StatusOr<std::unique_ptr<Ast>> MakeTestParsedAst(
absl::string_view expression) {
CEL_ASSIGN_OR_RETURN(auto parsed, Parse(expression));
static ParserOptions options;
options.enable_optional_syntax = true;
CEL_ASSIGN_OR_RETURN(auto parsed,
Parse(expression, /*description=*/expression, options));

return CreateAstFromParsedExpr(std::move(parsed));
}
Expand Down
4 changes: 4 additions & 0 deletions checker/internal/type_check_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ class TypeCheckEnv {
return functions_.insert({decl.name(), std::move(decl)}).second;
}

void InsertOrReplaceFunction(FunctionDecl decl) {
functions_[decl.name()] = std::move(decl);
}

absl::Nullable<const TypeCheckEnv*> parent() const { return parent_; }
void set_parent(TypeCheckEnv* parent) { parent_ = parent; }

Expand Down
Loading

0 comments on commit 4088278

Please sign in to comment.