Support for declaring a subset to filter definitions from a checker l… · google/cel-cpp@bec24e4

@@ -94,7 +94,15 @@ class TypeCheckEnv {

9494

descriptor_pool)

9595

: descriptor_pool_(std::move(descriptor_pool)),

9696

container_(""),

97-

parent_(nullptr) {};

97+

parent_(nullptr) {}

98+99+

TypeCheckEnv(absl::Nonnull<std::shared_ptr<const google::protobuf::DescriptorPool>>

100+

descriptor_pool,

101+

std::shared_ptr<google::protobuf::Arena> arena)

102+

: descriptor_pool_(std::move(descriptor_pool)),

103+

arena_(std::move(arena)),

104+

container_(""),

105+

parent_(nullptr) {}

9810699107

// Move-only.

100108

TypeCheckEnv(TypeCheckEnv&&) = default;

@@ -110,14 +118,19 @@ class TypeCheckEnv {

110118111119

const absl::optional<Type>& expected_type() const { return expected_type_; }

112120113-

absl::Span<const std::unique_ptr<TypeIntrospector>> type_providers() const {

121+

absl::Span<const std::shared_ptr<const TypeIntrospector>> type_providers()

122+

const {

114123

return type_providers_;

115124

}

116125117126

void AddTypeProvider(std::unique_ptr<TypeIntrospector> provider) {

118127

type_providers_.push_back(std::move(provider));

119128

}

120129130+

void AddTypeProvider(std::shared_ptr<const TypeIntrospector> provider) {

131+

type_providers_.push_back(std::move(provider));

132+

}

133+121134

const absl::flat_hash_map<std::string, VariableDecl>& variables() const {

122135

return variables_;

123136

}

@@ -179,17 +192,6 @@ class TypeCheckEnv {

179192

return descriptor_pool_.get();

180193

}

181194182-

// Return an arena that can be used to allocate memory for types that will be

183-

// used by the TypeChecker being built.

184-

//

185-

// This is only intended to be used for configuration.

186-

google::protobuf::Arena* ABSL_NONNULL arena() {

187-

if (arena_ == nullptr) {

188-

arena_ = std::make_unique<google::protobuf::Arena>();

189-

}

190-

return arena_.get();

191-

}

192-193195

private:

194196

explicit TypeCheckEnv(const TypeCheckEnv* ABSL_NONNULL parent)

195197

: descriptor_pool_(parent->descriptor_pool_),

@@ -200,7 +202,8 @@ class TypeCheckEnv {

200202

absl::string_view type, absl::string_view value) const;

201203202204

ABSL_NONNULL std::shared_ptr<const google::protobuf::DescriptorPool> descriptor_pool_;

203-

ABSL_NULLABLE std::unique_ptr<google::protobuf::Arena> arena_;

205+

// If set, an arena was needed to allocate types in the environment.

206+

ABSL_NULLABLE std::shared_ptr<const google::protobuf::Arena> arena_;

204207

std::string container_;

205208

const TypeCheckEnv* ABSL_NULLABLE parent_;

206209

@@ -209,7 +212,7 @@ class TypeCheckEnv {

209212

absl::flat_hash_map<std::string, FunctionDecl> functions_;

210213211214

// Type providers for custom types.

212-

std::vector<std::unique_ptr<TypeIntrospector>> type_providers_;

215+

std::vector<std::shared_ptr<const TypeIntrospector>> type_providers_;

213216214217

absl::optional<Type> expected_type_;

215218

};