4040
4141namespace cel ::checker_internal {
4242
43- class TypeCheckerBuilderImpl ;
44-
4543// Builder for TypeChecker instances.
4644class TypeCheckerBuilderImpl : public TypeCheckerBuilder {
4745 public:
@@ -51,7 +49,18 @@ class TypeCheckerBuilderImpl : public TypeCheckerBuilder {
5149 const CheckerOptions& options)
5250 : options_(options),
5351 target_config_ (&default_config_),
54- descriptor_pool_(std::move(descriptor_pool)) {}
52+ template_env_(std::move(descriptor_pool)) {}
53+
54+ // Constructor for building an extended TypeChecker.
55+ explicit TypeCheckerBuilderImpl (const CheckerOptions& options,
56+ const TypeCheckEnv& template_env)
57+ : options_(options),
58+ target_config_(&default_config_),
59+ template_env_(template_env) {
60+ if (auto arena = template_env_.arena (); arena != nullptr ) {
61+ type_arena_ = std::move (arena);
62+ }
63+ }
5564
5665 // Move only.
5766 TypeCheckerBuilderImpl (const TypeCheckerBuilderImpl&) = delete;
@@ -83,14 +92,14 @@ class TypeCheckerBuilderImpl : public TypeCheckerBuilder {
8392 const CheckerOptions& options () const override { return options_; }
8493
8594 google::protobuf::Arena* absl_nonnull arena () override {
86- if (arena_ == nullptr ) {
87- arena_ = std::make_shared<google::protobuf::Arena>();
95+ if (type_arena_ == nullptr ) {
96+ type_arena_ = std::make_shared<google::protobuf::Arena>();
8897 }
89- return arena_ .get ();
98+ return type_arena_ .get ();
9099 }
91100
92101 const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool () const override {
93- return descriptor_pool_. get ();
102+ return template_env_. descriptor_pool ();
94103 }
95104
96105 private:
@@ -129,19 +138,21 @@ class TypeCheckerBuilderImpl : public TypeCheckerBuilder {
129138 absl::Status ApplyConfig (ConfigRecord config, const TypeCheckerSubset* subset,
130139 TypeCheckEnv& env);
131140
141+ absl::Status ConfigureTypeCheckEnv (TypeCheckEnv& env);
142+
132143 CheckerOptions options_;
133144 // Default target for configuration changes. Used for direct calls to
134145 // AddVariable, AddFunction, etc.
135146 ConfigRecord default_config_;
136147 // Active target for configuration changes.
137148 // This is used to track which library the change is made on behalf of.
138149 ConfigRecord* absl_nonnull target_config_;
139- std::shared_ptr< const google::protobuf::DescriptorPool> descriptor_pool_ ;
140- std::shared_ptr<google::protobuf::Arena> arena_ ;
150+ TypeCheckEnv template_env_ ;
151+ std::shared_ptr<google::protobuf::Arena> type_arena_ ;
141152 std::vector<CheckerLibrary> libraries_;
142153 absl::flat_hash_map<std::string, TypeCheckerSubset> subsets_;
143154 absl::flat_hash_set<std::string> library_ids_;
144- ExpressionContainer expression_container_;
155+ absl::optional< ExpressionContainer> expression_container_;
145156 absl::optional<Type> expected_type_;
146157};
147158
0 commit comments