Skip to content

Commit a81711e

Browse files
jckingcopybara-github
authored andcommitted
Remove most cel::TypeFactory functions
PiperOrigin-RevId: 689449183
1 parent 8744d3f commit a81711e

16 files changed

+62
-160
lines changed

common/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ cc_test(
426426
srcs = ["value_testing_test.cc"],
427427
deps = [
428428
":memory",
429+
":type",
429430
":value",
430431
":value_testing",
431432
"//internal:testing",
@@ -521,7 +522,6 @@ cc_library(
521522
],
522523
) + [
523524
"type.cc",
524-
"type_factory.cc",
525525
"type_introspector.cc",
526526
"type_manager.cc",
527527
],

common/json.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,6 @@ class AnyToJsonConverter {
490490
virtual absl::StatusOr<Json> ConvertToJson(absl::string_view type_url,
491491
const absl::Cord& value) = 0;
492492

493-
absl::StatusOr<Json> ConvertToJson(const google::protobuf::Any& any) {
494-
return ConvertToJson(any.type_url(), GetAnyValueAsCord(any));
495-
}
496-
497493
virtual absl::Nullable<const google::protobuf::DescriptorPool*> descriptor_pool()
498494
const {
499495
return nullptr;

common/type_factory.cc

Lines changed: 0 additions & 29 deletions
This file was deleted.

common/type_factory.h

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define THIRD_PARTY_CEL_CPP_COMMON_TYPE_FACTORY_H_
1717

1818
#include "common/memory.h"
19-
#include "common/type.h"
2019

2120
namespace cel {
2221

@@ -35,65 +34,6 @@ class TypeFactory {
3534
// data structures as well as created types.
3635
virtual MemoryManagerRef GetMemoryManager() const = 0;
3736

38-
// `GetDynListType` gets a view of the `ListType` type `list(dyn)`.
39-
ListType GetDynListType();
40-
41-
// `GetDynDynMapType` gets a view of the `MapType` type `map(dyn, dyn)`.
42-
MapType GetDynDynMapType();
43-
44-
// `GetDynDynMapType` gets a view of the `MapType` type `map(string, dyn)`.
45-
MapType GetStringDynMapType();
46-
47-
// `GetDynOptionalType` gets a view of the `OptionalType` type
48-
// `optional(dyn)`.
49-
OptionalType GetDynOptionalType();
50-
51-
NullType GetNullType() { return NullType{}; }
52-
53-
ErrorType GetErrorType() { return ErrorType{}; }
54-
55-
DynType GetDynType() { return DynType{}; }
56-
57-
AnyType GetAnyType() { return AnyType{}; }
58-
59-
BoolType GetBoolType() { return BoolType{}; }
60-
61-
IntType GetIntType() { return IntType{}; }
62-
63-
UintType GetUintType() { return UintType{}; }
64-
65-
DoubleType GetDoubleType() { return DoubleType{}; }
66-
67-
StringType GetStringType() { return StringType{}; }
68-
69-
BytesType GetBytesType() { return BytesType{}; }
70-
71-
DurationType GetDurationType() { return DurationType{}; }
72-
73-
TimestampType GetTimestampType() { return TimestampType{}; }
74-
75-
TypeType GetTypeType() { return TypeType{}; }
76-
77-
UnknownType GetUnknownType() { return UnknownType{}; }
78-
79-
BoolWrapperType GetBoolWrapperType() { return BoolWrapperType{}; }
80-
81-
BytesWrapperType GetBytesWrapperType() { return BytesWrapperType{}; }
82-
83-
DoubleWrapperType GetDoubleWrapperType() { return DoubleWrapperType{}; }
84-
85-
IntWrapperType GetIntWrapperType() { return IntWrapperType{}; }
86-
87-
StringWrapperType GetStringWrapperType() { return StringWrapperType{}; }
88-
89-
UintWrapperType GetUintWrapperType() { return UintWrapperType{}; }
90-
91-
Type GetJsonValueType() { return DynType{}; }
92-
93-
ListType GetJsonListType() { return ListType(GetDynListType()); }
94-
95-
MapType GetJsonMapType() { return MapType(GetStringDynMapType()); }
96-
9737
protected:
9838
friend class common_internal::PiecewiseValueManager;
9939
};

common/type_reflector_test.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ TYPE_REFLECTOR_NEW_MAP_VALUE_BUILDER_TEST(DynType, DynType)
159159

160160
TEST_P(TypeReflectorTest, NewListValueBuilderCoverage_Dynamic) {
161161
ASSERT_OK_AND_ASSIGN(auto builder,
162-
value_manager().NewListValueBuilder(
163-
ListType(type_factory().GetDynListType())));
162+
value_manager().NewListValueBuilder(cel::ListType()));
164163
EXPECT_OK(builder->Add(IntValue(0)));
165164
EXPECT_OK(builder->Add(IntValue(1)));
166165
EXPECT_OK(builder->Add(IntValue(2)));
@@ -208,8 +207,8 @@ TEST_P(TypeReflectorTest, NewMapValueBuilderCoverage_DynamicStatic) {
208207
}
209208

210209
TEST_P(TypeReflectorTest, JsonKeyCoverage) {
211-
ASSERT_OK_AND_ASSIGN(auto builder, value_manager().NewMapValueBuilder(MapType(
212-
type_factory().GetDynDynMapType())));
210+
ASSERT_OK_AND_ASSIGN(auto builder, value_manager().NewMapValueBuilder(
211+
MapType(cel::MapType())));
213212
EXPECT_OK(builder->Put(BoolValue(true), IntValue(1)));
214213
EXPECT_OK(builder->Put(IntValue(1), IntValue(2)));
215214
EXPECT_OK(builder->Put(UintValue(2), IntValue(3)));

common/value_factory_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ JsonObject NewJsonObjectForTesting(bool with_array, bool with_nested_object) {
136136
TEST_P(ValueFactoryTest, JsonValueArray) {
137137
auto value = value_factory().CreateValueFromJson(NewJsonArrayForTesting());
138138
ASSERT_TRUE(InstanceOf<ListValue>(value));
139-
EXPECT_EQ(Type(value.GetRuntimeType()), type_factory().GetDynListType());
139+
EXPECT_EQ(Type(value.GetRuntimeType()), cel::ListType());
140140
auto list_value = Cast<ListValue>(value);
141141
EXPECT_THAT(list_value.IsEmpty(), IsOkAndHolds(false));
142142
EXPECT_THAT(list_value.Size(), IsOkAndHolds(6));

common/value_testing_test.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "absl/status/status.h"
2121
#include "absl/time/time.h"
2222
#include "common/memory.h"
23+
#include "common/type.h"
2324
#include "common/value.h"
2425
#include "internal/testing.h"
2526

@@ -228,8 +229,8 @@ TEST_P(ValueMatcherTest, OptionalValueIsEmptyNotOptional) {
228229
}
229230

230231
TEST_P(ValueMatcherTest, ListMatcherBasic) {
231-
ASSERT_OK_AND_ASSIGN(auto builder, value_manager().NewListValueBuilder(
232-
value_manager().GetDynListType()));
232+
ASSERT_OK_AND_ASSIGN(auto builder,
233+
value_manager().NewListValueBuilder(cel::ListType()));
233234

234235
ASSERT_OK(builder->Add(IntValue(42)));
235236

@@ -242,8 +243,8 @@ TEST_P(ValueMatcherTest, ListMatcherBasic) {
242243
}
243244

244245
TEST_P(ValueMatcherTest, ListMatcherMatchesElements) {
245-
ASSERT_OK_AND_ASSIGN(auto builder, value_manager().NewListValueBuilder(
246-
value_manager().GetDynListType()));
246+
ASSERT_OK_AND_ASSIGN(auto builder,
247+
value_manager().NewListValueBuilder(cel::ListType()));
247248
ASSERT_OK(builder->Add(IntValue(42)));
248249
ASSERT_OK(builder->Add(IntValue(1337)));
249250
ASSERT_OK(builder->Add(IntValue(42)));
@@ -256,8 +257,8 @@ TEST_P(ValueMatcherTest, ListMatcherMatchesElements) {
256257
}
257258

258259
TEST_P(ValueMatcherTest, MapMatcherBasic) {
259-
ASSERT_OK_AND_ASSIGN(auto builder, value_manager().NewMapValueBuilder(
260-
value_manager().GetDynDynMapType()));
260+
ASSERT_OK_AND_ASSIGN(auto builder,
261+
value_manager().NewMapValueBuilder(cel::MapType()));
261262

262263
ASSERT_OK(builder->Put(IntValue(42), IntValue(42)));
263264

@@ -270,8 +271,8 @@ TEST_P(ValueMatcherTest, MapMatcherBasic) {
270271
}
271272

272273
TEST_P(ValueMatcherTest, MapMatcherMatchesElements) {
273-
ASSERT_OK_AND_ASSIGN(auto builder, value_manager().NewMapValueBuilder(
274-
value_manager().GetDynDynMapType()));
274+
ASSERT_OK_AND_ASSIGN(auto builder,
275+
value_manager().NewMapValueBuilder(cel::MapType()));
275276

276277
ASSERT_OK(builder->Put(IntValue(42), StringValue("answer")));
277278
ASSERT_OK(builder->Put(IntValue(1337), StringValue("leet")));

eval/eval/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ cc_library(
346346
":expression_step_base",
347347
"//base/ast_internal:expr",
348348
"//common:casting",
349+
"//common:type",
349350
"//common:value",
350351
"//internal:status_macros",
351352
"@com_google_absl//absl/container:flat_hash_set",
@@ -394,7 +395,6 @@ cc_library(
394395
":evaluator_core",
395396
":expression_step_base",
396397
"//common:casting",
397-
"//common:memory",
398398
"//common:type",
399399
"//common:value",
400400
"//internal:status_macros",
@@ -501,6 +501,7 @@ cc_test(
501501
":ident_step",
502502
"//base:data",
503503
"//base/ast_internal:expr",
504+
"//common:type",
504505
"//common:value",
505506
"//common:value_testing",
506507
"//eval/public:activation",

eval/eval/comprehension_step_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "absl/strings/string_view.h"
1313
#include "base/ast_internal/expr.h"
1414
#include "base/type_provider.h"
15+
#include "common/type.h"
1516
#include "common/value.h"
1617
#include "common/value_testing.h"
1718
#include "eval/eval/attribute_trail.h"
@@ -273,9 +274,8 @@ class DirectComprehensionTest : public testing::Test {
273274

274275
// returns a two element list for testing [1, 2].
275276
absl::StatusOr<cel::ListValue> MakeList() {
276-
CEL_ASSIGN_OR_RETURN(auto builder,
277-
value_manager_.get().NewListValueBuilder(
278-
value_manager_.get().GetDynListType()));
277+
CEL_ASSIGN_OR_RETURN(auto builder, value_manager_.get().NewListValueBuilder(
278+
cel::ListType()));
279279

280280
CEL_RETURN_IF_ERROR(builder->Add(IntValue(1)));
281281
CEL_RETURN_IF_ERROR(builder->Add(IntValue(2)));

eval/eval/create_list_step.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "absl/types/optional.h"
1313
#include "base/ast_internal/expr.h"
1414
#include "common/casting.h"
15+
#include "common/type.h"
1516
#include "common/value.h"
1617
#include "common/values/list_value_builder.h"
1718
#include "eval/eval/attribute_trail.h"
@@ -82,9 +83,8 @@ absl::Status CreateListStep::Evaluate(ExecutionFrame* frame) const {
8283
}
8384
}
8485

85-
CEL_ASSIGN_OR_RETURN(auto builder,
86-
frame->value_manager().NewListValueBuilder(
87-
frame->value_manager().GetDynListType()));
86+
CEL_ASSIGN_OR_RETURN(auto builder, frame->value_manager().NewListValueBuilder(
87+
cel::ListType()));
8888

8989
builder->Reserve(args.size());
9090
for (size_t i = 0; i < args.size(); ++i) {
@@ -130,9 +130,9 @@ class CreateListDirectStep : public DirectExpressionStep {
130130

131131
absl::Status Evaluate(ExecutionFrameBase& frame, Value& result,
132132
AttributeTrail& attribute_trail) const override {
133-
CEL_ASSIGN_OR_RETURN(auto builder,
134-
frame.value_manager().NewListValueBuilder(
135-
frame.value_manager().GetDynListType()));
133+
CEL_ASSIGN_OR_RETURN(
134+
auto builder,
135+
frame.value_manager().NewListValueBuilder(cel::ListType()));
136136

137137
builder->Reserve(elements_.size());
138138
AttributeUtility::Accumulator unknowns =
@@ -231,9 +231,8 @@ class DirectMutableListStep : public DirectExpressionStep {
231231
absl::Status DirectMutableListStep::Evaluate(
232232
ExecutionFrameBase& frame, Value& result,
233233
AttributeTrail& attribute_trail) const {
234-
CEL_ASSIGN_OR_RETURN(auto builder,
235-
frame.value_manager().NewListValueBuilder(
236-
frame.value_manager().GetDynListType()));
234+
CEL_ASSIGN_OR_RETURN(
235+
auto builder, frame.value_manager().NewListValueBuilder(cel::ListType()));
237236
result = cel::ParsedListValue(cel::common_internal::NewMutableListValue(
238237
frame.value_manager().GetMemoryManager().arena()));
239238
return absl::OkStatus();

0 commit comments

Comments
 (0)