diff --git a/common/BUILD b/common/BUILD index ab1aeeb73..0140aec4d 100644 --- a/common/BUILD +++ b/common/BUILD @@ -610,7 +610,6 @@ cc_library( "type_reflector.cc", "value.cc", "value_factory.cc", - "value_interface.cc", "value_manager.cc", ], hdrs = glob( @@ -625,7 +624,6 @@ cc_library( "type_reflector.h", "value.h", "value_factory.h", - "value_interface.h", "value_manager.h", ], deps = [ diff --git a/common/legacy_value.cc b/common/legacy_value.cc index c7bcaabe9..3e8ba53ef 100644 --- a/common/legacy_value.cc +++ b/common/legacy_value.cc @@ -389,9 +389,9 @@ CelValue LegacyTrivialListValue(absl::Nonnull arena, .GetValuesDescriptor(), arena)); } - if (auto parsed_list_value = value.AsParsedList(); parsed_list_value) { + if (auto custom_list_value = value.AsCustomList(); custom_list_value) { auto status_or_compat_list = - common_internal::MakeCompatListValue(arena, *parsed_list_value); + common_internal::MakeCompatListValue(arena, *custom_list_value); if (!status_or_compat_list.ok()) { return CelValue::CreateError(google::protobuf::Arena::Create( arena, std::move(status_or_compat_list).status())); @@ -426,9 +426,9 @@ CelValue LegacyTrivialMapValue(absl::Nonnull arena, .GetFieldsDescriptor(), arena)); } - if (auto parsed_map_value = value.AsParsedMap(); parsed_map_value) { + if (auto custom_map_value = value.AsCustomMap(); custom_map_value) { auto status_or_compat_map = - common_internal::MakeCompatMapValue(arena, *parsed_map_value); + common_internal::MakeCompatMapValue(arena, *custom_map_value); if (!status_or_compat_map.ok()) { return CelValue::CreateError(google::protobuf::Arena::Create( arena, std::move(status_or_compat_map).status())); diff --git a/common/value.cc b/common/value.cc index a6a041ebc..8e613f4fa 100644 --- a/common/value.cc +++ b/common/value.cc @@ -235,7 +235,7 @@ absl::Status Value::ConvertToJsonArray( message_factory, json); }, [descriptor_pool, message_factory, - json](const ParsedListValue& alternative) -> absl::Status { + json](const CustomListValue& alternative) -> absl::Status { return alternative.ConvertToJsonArray(descriptor_pool, message_factory, json); }, @@ -280,7 +280,7 @@ absl::Status Value::ConvertToJsonObject( message_factory, json); }, [descriptor_pool, message_factory, - json](const ParsedMapValue& alternative) -> absl::Status { + json](const CustomMapValue& alternative) -> absl::Status { return alternative.ConvertToJsonObject(descriptor_pool, message_factory, json); }, @@ -301,7 +301,7 @@ absl::Status Value::ConvertToJsonObject( message_factory, json); }, [descriptor_pool, message_factory, - json](const ParsedStructValue& alternative) -> absl::Status { + json](const CustomStructValue& alternative) -> absl::Status { return alternative.ConvertToJsonObject(descriptor_pool, message_factory, json); }, @@ -1952,7 +1952,7 @@ absl::optional Value::AsList() const& { alternative != nullptr) { return *alternative; } - if (const auto* alternative = absl::get_if(&variant_); + if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return *alternative; } @@ -1974,7 +1974,7 @@ absl::optional Value::AsList() && { alternative != nullptr) { return std::move(*alternative); } - if (auto* alternative = absl::get_if(&variant_); + if (auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return std::move(*alternative); } @@ -1995,7 +1995,7 @@ absl::optional Value::AsMap() const& { alternative != nullptr) { return *alternative; } - if (const auto* alternative = absl::get_if(&variant_); + if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return *alternative; } @@ -2016,7 +2016,7 @@ absl::optional Value::AsMap() && { alternative != nullptr) { return std::move(*alternative); } - if (auto* alternative = absl::get_if(&variant_); + if (auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return std::move(*alternative); } @@ -2119,32 +2119,32 @@ absl::optional Value::AsParsedJsonMap() && { return absl::nullopt; } -optional_ref Value::AsParsedList() const& { - if (const auto* alternative = absl::get_if(&variant_); +optional_ref Value::AsCustomList() const& { + if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return *alternative; } return absl::nullopt; } -absl::optional Value::AsParsedList() && { - if (auto* alternative = absl::get_if(&variant_); +absl::optional Value::AsCustomList() && { + if (auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return std::move(*alternative); } return absl::nullopt; } -optional_ref Value::AsParsedMap() const& { - if (const auto* alternative = absl::get_if(&variant_); +optional_ref Value::AsCustomMap() const& { + if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return *alternative; } return absl::nullopt; } -absl::optional Value::AsParsedMap() && { - if (auto* alternative = absl::get_if(&variant_); +absl::optional Value::AsCustomMap() && { + if (auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return std::move(*alternative); } @@ -2201,16 +2201,16 @@ absl::optional Value::AsParsedRepeatedField() && { return absl::nullopt; } -optional_ref Value::AsParsedStruct() const& { - if (const auto* alternative = absl::get_if(&variant_); +optional_ref Value::AsCustomStruct() const& { + if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return *alternative; } return absl::nullopt; } -absl::optional Value::AsParsedStruct() && { - if (auto* alternative = absl::get_if(&variant_); +absl::optional Value::AsCustomStruct() && { + if (auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return std::move(*alternative); } @@ -2239,7 +2239,7 @@ absl::optional Value::AsStruct() const& { alternative != nullptr) { return *alternative; } - if (const auto* alternative = absl::get_if(&variant_); + if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return *alternative; } @@ -2256,7 +2256,7 @@ absl::optional Value::AsStruct() && { alternative != nullptr) { return std::move(*alternative); } - if (auto* alternative = absl::get_if(&variant_); + if (auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return std::move(*alternative); } @@ -2369,7 +2369,7 @@ ListValue Value::GetList() const& { alternative != nullptr) { return *alternative; } - if (const auto* alternative = absl::get_if(&variant_); + if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return *alternative; } @@ -2392,7 +2392,7 @@ ListValue Value::GetList() && { alternative != nullptr) { return std::move(*alternative); } - if (auto* alternative = absl::get_if(&variant_); + if (auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return std::move(*alternative); } @@ -2414,7 +2414,7 @@ MapValue Value::GetMap() const& { alternative != nullptr) { return *alternative; } - if (const auto* alternative = absl::get_if(&variant_); + if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return *alternative; } @@ -2436,7 +2436,7 @@ MapValue Value::GetMap() && { alternative != nullptr) { return std::move(*alternative); } - if (auto* alternative = absl::get_if(&variant_); + if (auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return std::move(*alternative); } @@ -2507,24 +2507,24 @@ ParsedJsonMapValue Value::GetParsedJsonMap() && { return absl::get(std::move(variant_)); } -const ParsedListValue& Value::GetParsedList() const& { - ABSL_DCHECK(IsParsedList()) << *this; - return absl::get(variant_); +const CustomListValue& Value::GetCustomList() const& { + ABSL_DCHECK(IsCustomList()) << *this; + return absl::get(variant_); } -ParsedListValue Value::GetParsedList() && { - ABSL_DCHECK(IsParsedList()) << *this; - return absl::get(std::move(variant_)); +CustomListValue Value::GetCustomList() && { + ABSL_DCHECK(IsCustomList()) << *this; + return absl::get(std::move(variant_)); } -const ParsedMapValue& Value::GetParsedMap() const& { - ABSL_DCHECK(IsParsedMap()) << *this; - return absl::get(variant_); +const CustomMapValue& Value::GetCustomMap() const& { + ABSL_DCHECK(IsCustomMap()) << *this; + return absl::get(variant_); } -ParsedMapValue Value::GetParsedMap() && { - ABSL_DCHECK(IsParsedMap()) << *this; - return absl::get(std::move(variant_)); +CustomMapValue Value::GetCustomMap() && { + ABSL_DCHECK(IsCustomMap()) << *this; + return absl::get(std::move(variant_)); } const ParsedMapFieldValue& Value::GetParsedMapField() const& { @@ -2557,14 +2557,14 @@ ParsedRepeatedFieldValue Value::GetParsedRepeatedField() && { return absl::get(std::move(variant_)); } -const ParsedStructValue& Value::GetParsedStruct() const& { - ABSL_DCHECK(IsParsedMap()) << *this; - return absl::get(variant_); +const CustomStructValue& Value::GetCustomStruct() const& { + ABSL_DCHECK(IsCustomStruct()) << *this; + return absl::get(variant_); } -ParsedStructValue Value::GetParsedStruct() && { - ABSL_DCHECK(IsParsedMap()) << *this; - return absl::get(std::move(variant_)); +CustomStructValue Value::GetCustomStruct() && { + ABSL_DCHECK(IsCustomStruct()) << *this; + return absl::get(std::move(variant_)); } const StringValue& Value::GetString() const& { @@ -2584,7 +2584,7 @@ StructValue Value::GetStruct() const& { alternative != nullptr) { return *alternative; } - if (const auto* alternative = absl::get_if(&variant_); + if (const auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return *alternative; } @@ -2602,7 +2602,7 @@ StructValue Value::GetStruct() && { alternative != nullptr) { return std::move(*alternative); } - if (auto* alternative = absl::get_if(&variant_); + if (auto* alternative = absl::get_if(&variant_); alternative != nullptr) { return std::move(*alternative); } diff --git a/common/value.h b/common/value.h index b260c9a29..5251f532e 100644 --- a/common/value.h +++ b/common/value.h @@ -43,10 +43,12 @@ #include "common/native_type.h" #include "common/optional_ref.h" #include "common/type.h" -#include "common/value_interface.h" // IWYU pragma: export #include "common/value_kind.h" #include "common/values/bool_value.h" // IWYU pragma: export #include "common/values/bytes_value.h" // IWYU pragma: export +#include "common/values/custom_list_value.h" // IWYU pragma: export +#include "common/values/custom_map_value.h" // IWYU pragma: export +#include "common/values/custom_struct_value.h" // IWYU pragma: export #include "common/values/double_value.h" // IWYU pragma: export #include "common/values/duration_value.h" // IWYU pragma: export #include "common/values/enum_value.h" // IWYU pragma: export @@ -505,7 +507,7 @@ class Value final { bool IsList() const { return absl::holds_alternative( variant_) || - absl::holds_alternative(variant_) || + absl::holds_alternative(variant_) || absl::holds_alternative(variant_) || absl::holds_alternative(variant_); } @@ -513,7 +515,7 @@ class Value final { // Returns `true` if this value is an instance of a map value. bool IsMap() const { return absl::holds_alternative(variant_) || - absl::holds_alternative(variant_) || + absl::holds_alternative(variant_) || absl::holds_alternative(variant_) || absl::holds_alternative(variant_); } @@ -556,18 +558,18 @@ class Value final { return absl::holds_alternative(variant_); } - // Returns `true` if this value is an instance of a parsed list value. If + // Returns `true` if this value is an instance of a custom list value. If // `true` is returned, it is implied that `IsList()` would also return // true. - bool IsParsedList() const { - return absl::holds_alternative(variant_); + bool IsCustomList() const { + return absl::holds_alternative(variant_); } - // Returns `true` if this value is an instance of a parsed map value. If + // Returns `true` if this value is an instance of a custom map value. If // `true` is returned, it is implied that `IsMap()` would also return // true. - bool IsParsedMap() const { - return absl::holds_alternative(variant_); + bool IsCustomMap() const { + return absl::holds_alternative(variant_); } // Returns `true` if this value is an instance of a parsed map field value. If @@ -591,11 +593,11 @@ class Value final { return absl::holds_alternative(variant_); } - // Returns `true` if this value is an instance of a parsed struct value. If + // Returns `true` if this value is an instance of a custom struct value. If // `true` is returned, it is implied that `IsStruct()` would also return // true. - bool IsParsedStruct() const { - return absl::holds_alternative(variant_); + bool IsCustomStruct() const { + return absl::holds_alternative(variant_); } // Returns `true` if this value is an instance of a string value. @@ -607,7 +609,7 @@ class Value final { bool IsStruct() const { return absl::holds_alternative( variant_) || - absl::holds_alternative(variant_) || + absl::holds_alternative(variant_) || absl::holds_alternative(variant_); } @@ -726,17 +728,17 @@ class Value final { } // Convenience method for use with template metaprogramming. See - // `IsParsedList()`. + // `IsCustomList()`. template - std::enable_if_t, bool> Is() const { - return IsParsedList(); + std::enable_if_t, bool> Is() const { + return IsCustomList(); } // Convenience method for use with template metaprogramming. See - // `IsParsedMap()`. + // `IsCustomMap()`. template - std::enable_if_t, bool> Is() const { - return IsParsedMap(); + std::enable_if_t, bool> Is() const { + return IsCustomMap(); } // Convenience method for use with template metaprogramming. See @@ -764,8 +766,8 @@ class Value final { // Convenience method for use with template metaprogramming. See // `IsParsedStruct()`. template - std::enable_if_t, bool> Is() const { - return IsParsedStruct(); + std::enable_if_t, bool> Is() const { + return IsCustomStruct(); } // Convenience method for use with template metaprogramming. See @@ -946,32 +948,32 @@ class Value final { return common_internal::AsOptional(AsParsedJsonMap()); } - // Performs a checked cast from a value to a parsed list value, + // Performs a checked cast from a value to a custom list value, // returning a non-empty optional with either a value or reference to the - // parsed list value. Otherwise an empty optional is returned. - optional_ref AsParsedList() & + // custom list value. Otherwise an empty optional is returned. + optional_ref AsCustomList() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return std::as_const(*this).AsParsedList(); + return std::as_const(*this).AsCustomList(); } - optional_ref AsParsedList() + optional_ref AsCustomList() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; - absl::optional AsParsedList() &&; - absl::optional AsParsedList() const&& { - return common_internal::AsOptional(AsParsedList()); + absl::optional AsCustomList() &&; + absl::optional AsCustomList() const&& { + return common_internal::AsOptional(AsCustomList()); } - // Performs a checked cast from a value to a parsed map value, + // Performs a checked cast from a value to a custom map value, // returning a non-empty optional with either a value or reference to the - // parsed map value. Otherwise an empty optional is returned. - optional_ref AsParsedMap() & + // custom map value. Otherwise an empty optional is returned. + optional_ref AsCustomMap() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return std::as_const(*this).AsParsedMap(); + return std::as_const(*this).AsCustomMap(); } - optional_ref AsParsedMap() + optional_ref AsCustomMap() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; - absl::optional AsParsedMap() &&; - absl::optional AsParsedMap() const&& { - return common_internal::AsOptional(AsParsedMap()); + absl::optional AsCustomMap() &&; + absl::optional AsCustomMap() const&& { + return common_internal::AsOptional(AsCustomMap()); } // Performs a checked cast from a value to a parsed map field value, @@ -1016,18 +1018,18 @@ class Value final { return common_internal::AsOptional(AsParsedRepeatedField()); } - // Performs a checked cast from a value to a parsed struct value, + // Performs a checked cast from a value to a custom struct value, // returning a non-empty optional with either a value or reference to the - // parsed struct value. Otherwise an empty optional is returned. - optional_ref AsParsedStruct() & + // custom struct value. Otherwise an empty optional is returned. + optional_ref AsCustomStruct() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return std::as_const(*this).AsParsedStruct(); + return std::as_const(*this).AsCustomStruct(); } - optional_ref AsParsedStruct() + optional_ref AsCustomStruct() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; - absl::optional AsParsedStruct() &&; - absl::optional AsParsedStruct() const&& { - return common_internal::AsOptional(AsParsedStruct()); + absl::optional AsCustomStruct() &&; + absl::optional AsCustomStruct() const&& { + return common_internal::AsOptional(AsCustomStruct()); } // Performs a checked cast from a value to a string value, @@ -1439,57 +1441,57 @@ class Value final { } // Convenience method for use with template metaprogramming. See - // `AsParsedList()`. + // `AsCustomList()`. template - std::enable_if_t, - optional_ref> + std::enable_if_t, + optional_ref> As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return AsParsedList(); + return AsCustomList(); } template - std::enable_if_t, - optional_ref> + std::enable_if_t, + optional_ref> As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { - return AsParsedList(); + return AsCustomList(); } template - std::enable_if_t, - absl::optional> + std::enable_if_t, + absl::optional> As() && { - return std::move(*this).AsParsedList(); + return std::move(*this).AsCustomList(); } template - std::enable_if_t, - absl::optional> + std::enable_if_t, + absl::optional> As() const&& { - return std::move(*this).AsParsedList(); + return std::move(*this).AsCustomList(); } // Convenience method for use with template metaprogramming. See - // `AsParsedMap()`. + // `AsCustomMap()`. template - std::enable_if_t, - optional_ref> + std::enable_if_t, + optional_ref> As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return AsParsedMap(); + return AsCustomMap(); } template - std::enable_if_t, - optional_ref> + std::enable_if_t, + optional_ref> As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { - return AsParsedMap(); + return AsCustomMap(); } template - std::enable_if_t, - absl::optional> + std::enable_if_t, + absl::optional> As() && { - return std::move(*this).AsParsedMap(); + return std::move(*this).AsCustomMap(); } template - std::enable_if_t, - absl::optional> + std::enable_if_t, + absl::optional> As() const&& { - return std::move(*this).AsParsedMap(); + return std::move(*this).AsCustomMap(); } // Convenience method for use with template metaprogramming. See @@ -1574,30 +1576,30 @@ class Value final { } // Convenience method for use with template metaprogramming. See - // `AsParsedStruct()`. + // `AsCustomStruct()`. template - std::enable_if_t, - optional_ref> + std::enable_if_t, + optional_ref> As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return AsParsedStruct(); + return AsCustomStruct(); } template - std::enable_if_t, - optional_ref> + std::enable_if_t, + optional_ref> As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { - return AsParsedStruct(); + return AsCustomStruct(); } template - std::enable_if_t, - absl::optional> + std::enable_if_t, + absl::optional> As() && { - return std::move(*this).AsParsedStruct(); + return std::move(*this).AsCustomStruct(); } template - std::enable_if_t, - absl::optional> + std::enable_if_t, + absl::optional> As() const&& { - return std::move(*this).AsParsedStruct(); + return std::move(*this).AsCustomStruct(); } // Convenience method for use with template metaprogramming. See @@ -1863,25 +1865,25 @@ class Value final { ParsedJsonMapValue GetParsedJsonMap() &&; ParsedJsonMapValue GetParsedJsonMap() const&& { return GetParsedJsonMap(); } - // Performs an unchecked cast from a value to a parsed list value. In - // debug builds a best effort is made to crash. If `IsParsedList()` would + // Performs an unchecked cast from a value to a custom list value. In + // debug builds a best effort is made to crash. If `IsCustomList()` would // return false, calling this method is undefined behavior. - const ParsedListValue& GetParsedList() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return std::as_const(*this).GetParsedList(); + const CustomListValue& GetCustomList() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetCustomList(); } - const ParsedListValue& GetParsedList() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; - ParsedListValue GetParsedList() &&; - ParsedListValue GetParsedList() const&& { return GetParsedList(); } + const CustomListValue& GetCustomList() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; + CustomListValue GetCustomList() &&; + CustomListValue GetCustomList() const&& { return GetCustomList(); } - // Performs an unchecked cast from a value to a parsed map value. In - // debug builds a best effort is made to crash. If `IsParsedMap()` would + // Performs an unchecked cast from a value to a custom map value. In + // debug builds a best effort is made to crash. If `IsCustomMap()` would // return false, calling this method is undefined behavior. - const ParsedMapValue& GetParsedMap() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return std::as_const(*this).GetParsedMap(); + const CustomMapValue& GetCustomMap() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetCustomMap(); } - const ParsedMapValue& GetParsedMap() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; - ParsedMapValue GetParsedMap() &&; - ParsedMapValue GetParsedMap() const&& { return GetParsedMap(); } + const CustomMapValue& GetCustomMap() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; + CustomMapValue GetCustomMap() &&; + CustomMapValue GetCustomMap() const&& { return GetCustomMap(); } // Performs an unchecked cast from a value to a parsed map field value. In // debug builds a best effort is made to crash. If `IsParsedMapField()` would @@ -1923,16 +1925,16 @@ class Value final { return GetParsedRepeatedField(); } - // Performs an unchecked cast from a value to a parsed struct value. In - // debug builds a best effort is made to crash. If `IsParsedStruct()` would + // Performs an unchecked cast from a value to a custom struct value. In + // debug builds a best effort is made to crash. If `IsCustomStruct()` would // return false, calling this method is undefined behavior. - const ParsedStructValue& GetParsedStruct() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return std::as_const(*this).GetParsedStruct(); + const CustomStructValue& GetCustomStruct() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetCustomStruct(); } - const ParsedStructValue& GetParsedStruct() + const CustomStructValue& GetCustomStruct() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; - ParsedStructValue GetParsedStruct() &&; - ParsedStructValue GetParsedStruct() const&& { return GetParsedStruct(); } + CustomStructValue GetCustomStruct() &&; + CustomStructValue GetCustomStruct() const&& { return GetCustomStruct(); } // Performs an unchecked cast from a value to a string value. In // debug builds a best effort is made to crash. If `IsString()` would return @@ -2273,49 +2275,49 @@ class Value final { } // Convenience method for use with template metaprogramming. See - // `GetParsedList()`. + // `GetCustomList()`. template - std::enable_if_t, - const ParsedListValue&> + std::enable_if_t, + const CustomListValue&> Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return GetParsedList(); + return GetCustomList(); } template - std::enable_if_t, const ParsedListValue&> + std::enable_if_t, const CustomListValue&> Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { - return GetParsedList(); + return GetCustomList(); } template - std::enable_if_t, ParsedListValue> + std::enable_if_t, CustomListValue> Get() && { - return std::move(*this).GetParsedList(); + return std::move(*this).GetCustomList(); } template - std::enable_if_t, ParsedListValue> Get() + std::enable_if_t, CustomListValue> Get() const&& { - return std::move(*this).GetParsedList(); + return std::move(*this).GetCustomList(); } // Convenience method for use with template metaprogramming. See - // `GetParsedMap()`. + // `GetCustomMap()`. template - std::enable_if_t, const ParsedMapValue&> + std::enable_if_t, const CustomMapValue&> Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return GetParsedMap(); + return GetCustomMap(); } template - std::enable_if_t, const ParsedMapValue&> + std::enable_if_t, const CustomMapValue&> Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { - return GetParsedMap(); + return GetCustomMap(); } template - std::enable_if_t, ParsedMapValue> Get() && { - return std::move(*this).GetParsedMap(); + std::enable_if_t, CustomMapValue> Get() && { + return std::move(*this).GetCustomMap(); } template - std::enable_if_t, ParsedMapValue> Get() + std::enable_if_t, CustomMapValue> Get() const&& { - return std::move(*this).GetParsedMap(); + return std::move(*this).GetCustomMap(); } // Convenience method for use with template metaprogramming. See @@ -2396,28 +2398,28 @@ class Value final { } // Convenience method for use with template metaprogramming. See - // `GetParsedStruct()`. + // `GetCustomStruct()`. template - std::enable_if_t, - const ParsedStructValue&> + std::enable_if_t, + const CustomStructValue&> Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return GetParsedStruct(); + return GetCustomStruct(); } template - std::enable_if_t, - const ParsedStructValue&> + std::enable_if_t, + const CustomStructValue&> Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { - return GetParsedStruct(); + return GetCustomStruct(); } template - std::enable_if_t, ParsedStructValue> + std::enable_if_t, CustomStructValue> Get() && { - return std::move(*this).GetParsedStruct(); + return std::move(*this).GetCustomStruct(); } template - std::enable_if_t, ParsedStructValue> + std::enable_if_t, CustomStructValue> Get() const&& { - return std::move(*this).GetParsedStruct(); + return std::move(*this).GetCustomStruct(); } // Convenience method for use with template metaprogramming. See @@ -2701,33 +2703,33 @@ using StructValueBuilderInterface = StructValueBuilder; // Now that Value is complete, we can define various parts of list, map, opaque, // and struct which depend on Value. -inline absl::Status ParsedListValue::Get(ValueManager& value_manager, +inline absl::Status CustomListValue::Get(ValueManager& value_manager, size_t index, Value& result) const { return interface_->Get(value_manager, index, result); } -inline absl::Status ParsedListValue::ForEach(ValueManager& value_manager, +inline absl::Status CustomListValue::ForEach(ValueManager& value_manager, ForEachCallback callback) const { return interface_->ForEach(value_manager, callback); } -inline absl::Status ParsedListValue::ForEach( +inline absl::Status CustomListValue::ForEach( ValueManager& value_manager, ForEachWithIndexCallback callback) const { return interface_->ForEach(value_manager, callback); } inline absl::StatusOr> -ParsedListValue::NewIterator(ValueManager& value_manager) const { +CustomListValue::NewIterator(ValueManager& value_manager) const { return interface_->NewIterator(value_manager); } -inline absl::Status ParsedListValue::Equal(ValueManager& value_manager, +inline absl::Status CustomListValue::Equal(ValueManager& value_manager, const Value& other, Value& result) const { return interface_->Equal(value_manager, other, result); } -inline absl::Status ParsedListValue::Contains(ValueManager& value_manager, +inline absl::Status CustomListValue::Contains(ValueManager& value_manager, const Value& other, Value& result) const { return interface_->Contains(value_manager, other, result); @@ -2751,69 +2753,69 @@ inline void OptionalValue::Value(cel::Value& result) const { inline cel::Value OptionalValue::Value() const { return (*this)->Value(); } -inline absl::Status ParsedMapValue::Get(ValueManager& value_manager, +inline absl::Status CustomMapValue::Get(ValueManager& value_manager, const Value& key, Value& result) const { return interface_->Get(value_manager, key, result); } -inline absl::StatusOr ParsedMapValue::Find(ValueManager& value_manager, +inline absl::StatusOr CustomMapValue::Find(ValueManager& value_manager, const Value& key, Value& result) const { return interface_->Find(value_manager, key, result); } -inline absl::Status ParsedMapValue::Has(ValueManager& value_manager, +inline absl::Status CustomMapValue::Has(ValueManager& value_manager, const Value& key, Value& result) const { return interface_->Has(value_manager, key, result); } -inline absl::Status ParsedMapValue::ListKeys(ValueManager& value_manager, +inline absl::Status CustomMapValue::ListKeys(ValueManager& value_manager, ListValue& result) const { return interface_->ListKeys(value_manager, result); } -inline absl::Status ParsedMapValue::ForEach(ValueManager& value_manager, +inline absl::Status CustomMapValue::ForEach(ValueManager& value_manager, ForEachCallback callback) const { return interface_->ForEach(value_manager, callback); } inline absl::StatusOr> -ParsedMapValue::NewIterator(ValueManager& value_manager) const { +CustomMapValue::NewIterator(ValueManager& value_manager) const { return interface_->NewIterator(value_manager); } -inline absl::Status ParsedMapValue::Equal(ValueManager& value_manager, +inline absl::Status CustomMapValue::Equal(ValueManager& value_manager, const Value& other, Value& result) const { return interface_->Equal(value_manager, other, result); } -inline absl::Status ParsedStructValue::GetFieldByName( +inline absl::Status CustomStructValue::GetFieldByName( ValueManager& value_manager, absl::string_view name, Value& result, ProtoWrapperTypeOptions unboxing_options) const { return interface_->GetFieldByName(value_manager, name, result, unboxing_options); } -inline absl::Status ParsedStructValue::GetFieldByNumber( +inline absl::Status CustomStructValue::GetFieldByNumber( ValueManager& value_manager, int64_t number, Value& result, ProtoWrapperTypeOptions unboxing_options) const { return interface_->GetFieldByNumber(value_manager, number, result, unboxing_options); } -inline absl::Status ParsedStructValue::Equal(ValueManager& value_manager, +inline absl::Status CustomStructValue::Equal(ValueManager& value_manager, const Value& other, Value& result) const { return interface_->Equal(value_manager, other, result); } -inline absl::Status ParsedStructValue::ForEachField( +inline absl::Status CustomStructValue::ForEachField( ValueManager& value_manager, ForEachFieldCallback callback) const { return interface_->ForEachField(value_manager, callback); } -inline absl::StatusOr ParsedStructValue::Qualify( +inline absl::StatusOr CustomStructValue::Qualify( ValueManager& value_manager, absl::Span qualifiers, bool presence_test, Value& result) const { return interface_->Qualify(value_manager, qualifiers, presence_test, result); diff --git a/common/value_test.cc b/common/value_test.cc index 7ef8c006a..894141a42 100644 --- a/common/value_test.cc +++ b/common/value_test.cc @@ -141,8 +141,8 @@ TEST(Value, Is) { EXPECT_TRUE(Value(IntValue()).Is()); EXPECT_TRUE(Value(ListValue()).Is()); - EXPECT_TRUE(Value(ParsedListValue()).Is()); - EXPECT_TRUE(Value(ParsedListValue()).Is()); + EXPECT_TRUE(Value(CustomListValue()).Is()); + EXPECT_TRUE(Value(CustomListValue()).Is()); EXPECT_TRUE(Value(ParsedJsonListValue()).Is()); EXPECT_TRUE(Value(ParsedJsonListValue()).Is()); { @@ -158,8 +158,8 @@ TEST(Value, Is) { } EXPECT_TRUE(Value(MapValue()).Is()); - EXPECT_TRUE(Value(ParsedMapValue()).Is()); - EXPECT_TRUE(Value(ParsedMapValue()).Is()); + EXPECT_TRUE(Value(CustomMapValue()).Is()); + EXPECT_TRUE(Value(CustomMapValue()).Is()); EXPECT_TRUE(Value(ParsedJsonMapValue()).Is()); EXPECT_TRUE(Value(ParsedJsonMapValue()).Is()); { @@ -299,7 +299,7 @@ TEST(Value, As) { } { - Value value(ParsedListValue{}); + Value value(CustomListValue{}); Value other_value = value; EXPECT_THAT(AsLValueRef(value).As(), Optional(An())); @@ -313,16 +313,16 @@ TEST(Value, As) { } { - Value value(ParsedListValue{}); + Value value(CustomListValue{}); Value other_value = value; - EXPECT_THAT(AsLValueRef(value).As(), - Optional(An())); - EXPECT_THAT(AsConstLValueRef(value).As(), - Optional(An())); - EXPECT_THAT(AsRValueRef(value).As(), - Optional(An())); - EXPECT_THAT(AsConstRValueRef(other_value).As(), - Optional(An())); + EXPECT_THAT(AsLValueRef(value).As(), + Optional(An())); + EXPECT_THAT(AsConstLValueRef(value).As(), + Optional(An())); + EXPECT_THAT(AsRValueRef(value).As(), + Optional(An())); + EXPECT_THAT(AsConstRValueRef(other_value).As(), + Optional(An())); } { @@ -404,7 +404,7 @@ TEST(Value, As) { } { - Value value(ParsedMapValue{}); + Value value(CustomMapValue{}); Value other_value = value; EXPECT_THAT(AsLValueRef(value).As(), Optional(An())); @@ -418,16 +418,16 @@ TEST(Value, As) { } { - Value value(ParsedMapValue{}); + Value value(CustomMapValue{}); Value other_value = value; - EXPECT_THAT(AsLValueRef(value).As(), - Optional(An())); - EXPECT_THAT(AsConstLValueRef(value).As(), - Optional(An())); - EXPECT_THAT(AsRValueRef(value).As(), - Optional(An())); - EXPECT_THAT(AsConstRValueRef(other_value).As(), - Optional(An())); + EXPECT_THAT(AsLValueRef(value).As(), + Optional(An())); + EXPECT_THAT(AsConstLValueRef(value).As(), + Optional(An())); + EXPECT_THAT(AsRValueRef(value).As(), + Optional(An())); + EXPECT_THAT(AsConstRValueRef(other_value).As(), + Optional(An())); } { @@ -689,7 +689,7 @@ TEST(Value, Get) { } { - Value value(ParsedListValue{}); + Value value(CustomListValue{}); Value other_value = value; EXPECT_THAT(DoGet(AsLValueRef(value)), An()); EXPECT_THAT(DoGet(AsConstLValueRef(value)), @@ -700,16 +700,16 @@ TEST(Value, Get) { } { - Value value(ParsedListValue{}); + Value value(CustomListValue{}); Value other_value = value; - EXPECT_THAT(DoGet(AsLValueRef(value)), - An()); - EXPECT_THAT(DoGet(AsConstLValueRef(value)), - An()); - EXPECT_THAT(DoGet(AsRValueRef(value)), - An()); - EXPECT_THAT(DoGet(AsConstRValueRef(other_value)), - An()); + EXPECT_THAT(DoGet(AsLValueRef(value)), + An()); + EXPECT_THAT(DoGet(AsConstLValueRef(value)), + An()); + EXPECT_THAT(DoGet(AsRValueRef(value)), + An()); + EXPECT_THAT(DoGet(AsConstRValueRef(other_value)), + An()); } { @@ -783,7 +783,7 @@ TEST(Value, Get) { } { - Value value(ParsedMapValue{}); + Value value(CustomMapValue{}); Value other_value = value; EXPECT_THAT(DoGet(AsLValueRef(value)), An()); EXPECT_THAT(DoGet(AsConstLValueRef(value)), @@ -794,16 +794,16 @@ TEST(Value, Get) { } { - Value value(ParsedMapValue{}); + Value value(CustomMapValue{}); Value other_value = value; - EXPECT_THAT(DoGet(AsLValueRef(value)), - An()); - EXPECT_THAT(DoGet(AsConstLValueRef(value)), - An()); - EXPECT_THAT(DoGet(AsRValueRef(value)), - An()); - EXPECT_THAT(DoGet(AsConstRValueRef(other_value)), - An()); + EXPECT_THAT(DoGet(AsLValueRef(value)), + An()); + EXPECT_THAT(DoGet(AsConstLValueRef(value)), + An()); + EXPECT_THAT(DoGet(AsRValueRef(value)), + An()); + EXPECT_THAT(DoGet(AsConstRValueRef(other_value)), + An()); } { diff --git a/common/values/parsed_list_value.cc b/common/values/custom_list_value.cc similarity index 89% rename from common/values/parsed_list_value.cc rename to common/values/custom_list_value.cc index 2cd1f0401..b40699425 100644 --- a/common/values/parsed_list_value.cc +++ b/common/values/custom_list_value.cc @@ -91,8 +91,8 @@ class EmptyListValue final : public common_internal::CompatListValue { return absl::OkStatus(); } - ParsedListValue Clone(ArenaAllocator<>) const override { - return ParsedListValue(); + CustomListValue Clone(ArenaAllocator<>) const override { + return CustomListValue(); } int size() const override { return 0; } @@ -128,10 +128,10 @@ absl::Nonnull EmptyCompatListValue() { } // namespace common_internal -class ParsedListValueInterfaceIterator final : public ValueIterator { +class CustomListValueInterfaceIterator final : public ValueIterator { public: - explicit ParsedListValueInterfaceIterator( - const ParsedListValueInterface& interface, ValueManager& value_manager) + explicit CustomListValueInterfaceIterator( + const CustomListValueInterface& interface, ValueManager& value_manager) : interface_(interface), value_manager_(value_manager), size_(interface_.Size()) {} @@ -148,13 +148,13 @@ class ParsedListValueInterfaceIterator final : public ValueIterator { } private: - const ParsedListValueInterface& interface_; + const CustomListValueInterface& interface_; ValueManager& value_manager_; const size_t size_; size_t index_ = 0; }; -absl::Status ParsedListValueInterface::SerializeTo( +absl::Status CustomListValueInterface::SerializeTo( absl::Nonnull descriptor_pool, absl::Nonnull message_factory, absl::Cord& value) const { @@ -181,7 +181,7 @@ absl::Status ParsedListValueInterface::SerializeTo( return absl::OkStatus(); } -absl::Status ParsedListValueInterface::Get(ValueManager& value_manager, +absl::Status CustomListValueInterface::Get(ValueManager& value_manager, size_t index, Value& result) const { if (ABSL_PREDICT_FALSE(index >= Size())) { result = IndexOutOfBoundsError(index); @@ -190,7 +190,7 @@ absl::Status ParsedListValueInterface::Get(ValueManager& value_manager, return GetImpl(value_manager, index, result); } -absl::Status ParsedListValueInterface::ForEach(ValueManager& value_manager, +absl::Status CustomListValueInterface::ForEach(ValueManager& value_manager, ForEachCallback callback) const { return ForEach( value_manager, @@ -199,7 +199,7 @@ absl::Status ParsedListValueInterface::ForEach(ValueManager& value_manager, }); } -absl::Status ParsedListValueInterface::ForEach( +absl::Status CustomListValueInterface::ForEach( ValueManager& value_manager, ForEachWithIndexCallback callback) const { const size_t size = Size(); for (size_t index = 0; index < size; ++index) { @@ -214,12 +214,12 @@ absl::Status ParsedListValueInterface::ForEach( } absl::StatusOr> -ParsedListValueInterface::NewIterator(ValueManager& value_manager) const { - return std::make_unique(*this, +CustomListValueInterface::NewIterator(ValueManager& value_manager) const { + return std::make_unique(*this, value_manager); } -absl::Status ParsedListValueInterface::Equal(ValueManager& value_manager, +absl::Status CustomListValueInterface::Equal(ValueManager& value_manager, const Value& other, Value& result) const { if (auto list_value = other.As(); list_value.has_value()) { @@ -229,7 +229,7 @@ absl::Status ParsedListValueInterface::Equal(ValueManager& value_manager, return absl::OkStatus(); } -absl::Status ParsedListValueInterface::Contains(ValueManager& value_manager, +absl::Status CustomListValueInterface::Contains(ValueManager& value_manager, const Value& other, Value& result) const { Value outcome = BoolValue(false); @@ -250,14 +250,14 @@ absl::Status ParsedListValueInterface::Contains(ValueManager& value_manager, return absl::OkStatus(); } -ParsedListValue::ParsedListValue() - : ParsedListValue( +CustomListValue::CustomListValue() + : CustomListValue( common_internal::MakeShared(&EmptyListValue::Get(), nullptr)) {} -ParsedListValue ParsedListValue::Clone(Allocator<> allocator) const { +CustomListValue CustomListValue::Clone(Allocator<> allocator) const { ABSL_DCHECK(*this); if (ABSL_PREDICT_FALSE(!interface_)) { - return ParsedListValue(); + return CustomListValue(); } if (absl::Nullable arena = allocator.arena(); arena != nullptr && diff --git a/common/values/parsed_list_value.h b/common/values/custom_list_value.h similarity index 71% rename from common/values/parsed_list_value.h rename to common/values/custom_list_value.h index 5c7fdaeb4..ce9394b02 100644 --- a/common/values/parsed_list_value.h +++ b/common/values/custom_list_value.h @@ -15,11 +15,11 @@ // IWYU pragma: private, include "common/value.h" // IWYU pragma: friend "common/value.h" -// `ParsedListValue` represents values of the primitive `list` type. -// `ParsedListValueView` is a non-owning view of `ParsedListValue`. -// `ParsedListValueInterface` is the abstract base class of implementations. -// `ParsedListValue` and `ParsedListValueView` act as smart pointers to -// `ParsedListValueInterface`. +// `CustomListValue` represents values of the primitive `list` type. +// `CustomListValueView` is a non-owning view of `CustomListValue`. +// `CustomListValueInterface` is the abstract base class of implementations. +// `CustomListValue` and `CustomListValueView` act as smart pointers to +// `CustomListValueInterface`. #ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_PARSED_LIST_VALUE_H_ #define THIRD_PARTY_CEL_CPP_COMMON_VALUES_PARSED_LIST_VALUE_H_ @@ -31,6 +31,7 @@ #include #include "absl/base/nullability.h" +#include "absl/functional/function_ref.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/cord.h" @@ -38,9 +39,8 @@ #include "common/allocator.h" #include "common/memory.h" #include "common/native_type.h" -#include "common/value_interface.h" #include "common/value_kind.h" -#include "common/values/list_value_interface.h" +#include "common/values/custom_value_interface.h" #include "common/values/values.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" @@ -48,17 +48,28 @@ namespace cel { class Value; -class ParsedListValueInterface; -class ParsedListValueInterfaceIterator; -class ParsedListValue; +class CustomListValueInterface; +class CustomListValueInterfaceIterator; +class CustomListValue; class ValueManager; // `Is` checks whether `lhs` and `rhs` have the same identity. -bool Is(const ParsedListValue& lhs, const ParsedListValue& rhs); +bool Is(const CustomListValue& lhs, const CustomListValue& rhs); -class ParsedListValueInterface : public ListValueInterface { +class CustomListValueInterface : public CustomValueInterface { public: - using alternative_type = ParsedListValue; + using alternative_type = CustomListValue; + + static constexpr ValueKind kKind = ValueKind::kList; + + ValueKind kind() const final { return kKind; } + + absl::string_view GetTypeName() const final { return "list"; } + + using ForEachCallback = absl::FunctionRef(const Value&)>; + + using ForEachWithIndexCallback = + absl::FunctionRef(size_t, const Value&)>; absl::Status SerializeTo( absl::Nonnull descriptor_pool, @@ -92,32 +103,32 @@ class ParsedListValueInterface : public ListValueInterface { virtual absl::Status Contains(ValueManager& value_manager, const Value& other, Value& result) const; - virtual ParsedListValue Clone(ArenaAllocator<> allocator) const = 0; + virtual CustomListValue Clone(ArenaAllocator<> allocator) const = 0; protected: - friend class ParsedListValueInterfaceIterator; + friend class CustomListValueInterfaceIterator; virtual absl::Status GetImpl(ValueManager& value_manager, size_t index, Value& result) const = 0; }; -class ParsedListValue { +class CustomListValue { public: - using interface_type = ParsedListValueInterface; + using interface_type = CustomListValueInterface; - static constexpr ValueKind kKind = ParsedListValueInterface::kKind; + static constexpr ValueKind kKind = CustomListValueInterface::kKind; // NOLINTNEXTLINE(google-explicit-constructor) - ParsedListValue(Shared interface) + CustomListValue(Shared interface) : interface_(std::move(interface)) {} // By default, this creates an empty list whose type is `list(dyn)`. Unless // you can help it, you should use a more specific typed list value. - ParsedListValue(); - ParsedListValue(const ParsedListValue&) = default; - ParsedListValue(ParsedListValue&&) = default; - ParsedListValue& operator=(const ParsedListValue&) = default; - ParsedListValue& operator=(ParsedListValue&&) = default; + CustomListValue(); + CustomListValue(const CustomListValue&) = default; + CustomListValue(CustomListValue&&) = default; + CustomListValue& operator=(const CustomListValue&) = default; + CustomListValue& operator=(CustomListValue&&) = default; constexpr ValueKind kind() const { return kKind; } @@ -155,7 +166,7 @@ class ParsedListValue { bool IsZeroValue() const { return interface_->IsZeroValue(); } - ParsedListValue Clone(Allocator<> allocator) const; + CustomListValue Clone(Allocator<> allocator) const; bool IsEmpty() const { return interface_->IsEmpty(); } @@ -165,10 +176,10 @@ class ParsedListValue { absl::Status Get(ValueManager& value_manager, size_t index, Value& result) const; - using ForEachCallback = typename ListValueInterface::ForEachCallback; + using ForEachCallback = typename CustomListValueInterface::ForEachCallback; using ForEachWithIndexCallback = - typename ListValueInterface::ForEachWithIndexCallback; + typename CustomListValueInterface::ForEachWithIndexCallback; absl::Status ForEach(ValueManager& value_manager, ForEachCallback callback) const; @@ -182,7 +193,7 @@ class ParsedListValue { absl::Status Contains(ValueManager& value_manager, const Value& other, Value& result) const; - void swap(ParsedListValue& other) noexcept { + void swap(CustomListValue& other) noexcept { using std::swap; swap(interface_, other.interface_); } @@ -196,47 +207,47 @@ class ParsedListValue { explicit operator bool() const { return static_cast(interface_); } private: - friend struct NativeTypeTraits; - friend bool Is(const ParsedListValue& lhs, const ParsedListValue& rhs); + friend struct NativeTypeTraits; + friend bool Is(const CustomListValue& lhs, const CustomListValue& rhs); - Shared interface_; + Shared interface_; }; -inline void swap(ParsedListValue& lhs, ParsedListValue& rhs) noexcept { +inline void swap(CustomListValue& lhs, CustomListValue& rhs) noexcept { lhs.swap(rhs); } inline std::ostream& operator<<(std::ostream& out, - const ParsedListValue& type) { + const CustomListValue& type) { return out << type.DebugString(); } template <> -struct NativeTypeTraits final { - static NativeTypeId Id(const ParsedListValue& type) { +struct NativeTypeTraits final { + static NativeTypeId Id(const CustomListValue& type) { return NativeTypeId::Of(*type.interface_); } - static bool SkipDestructor(const ParsedListValue& type) { + static bool SkipDestructor(const CustomListValue& type) { return NativeType::SkipDestructor(type.interface_); } }; template struct NativeTypeTraits>, - std::is_base_of>>> + std::negation>, + std::is_base_of>>> final { static NativeTypeId Id(const T& type) { - return NativeTypeTraits::Id(type); + return NativeTypeTraits::Id(type); } static bool SkipDestructor(const T& type) { - return NativeTypeTraits::SkipDestructor(type); + return NativeTypeTraits::SkipDestructor(type); } }; -inline bool Is(const ParsedListValue& lhs, const ParsedListValue& rhs) { +inline bool Is(const CustomListValue& lhs, const CustomListValue& rhs) { return lhs.interface_.operator->() == rhs.interface_.operator->(); } diff --git a/common/values/parsed_map_value.cc b/common/values/custom_map_value.cc similarity index 94% rename from common/values/parsed_map_value.cc rename to common/values/custom_map_value.cc index 27ac5f3b5..ec8c062ba 100644 --- a/common/values/parsed_map_value.cc +++ b/common/values/custom_map_value.cc @@ -126,8 +126,8 @@ class EmptyMapValue final : public common_internal::CompatMapValue { return absl::OkStatus(); } - ParsedMapValue Clone(ArenaAllocator<>) const override { - return ParsedMapValue(); + CustomMapValue Clone(ArenaAllocator<>) const override { + return CustomMapValue(); } absl::optional operator[](CelValue key) const override { @@ -172,7 +172,7 @@ absl::Nonnull EmptyCompatMapValue() { } // namespace common_internal -absl::Status ParsedMapValueInterface::SerializeTo( +absl::Status CustomMapValueInterface::SerializeTo( absl::Nonnull descriptor_pool, absl::Nonnull message_factory, absl::Cord& value) const { @@ -199,7 +199,7 @@ absl::Status ParsedMapValueInterface::SerializeTo( return absl::OkStatus(); } -absl::Status ParsedMapValueInterface::Get(ValueManager& value_manager, +absl::Status CustomMapValueInterface::Get(ValueManager& value_manager, const Value& key, Value& result) const { CEL_ASSIGN_OR_RETURN(bool ok, Find(value_manager, key, result)); @@ -217,7 +217,7 @@ absl::Status ParsedMapValueInterface::Get(ValueManager& value_manager, return absl::OkStatus(); } -absl::StatusOr ParsedMapValueInterface::Find(ValueManager& value_manager, +absl::StatusOr CustomMapValueInterface::Find(ValueManager& value_manager, const Value& key, Value& result) const { switch (key.kind()) { @@ -246,7 +246,7 @@ absl::StatusOr ParsedMapValueInterface::Find(ValueManager& value_manager, return false; } -absl::Status ParsedMapValueInterface::Has(ValueManager& value_manager, +absl::Status CustomMapValueInterface::Has(ValueManager& value_manager, const Value& key, Value& result) const { switch (key.kind()) { @@ -271,7 +271,7 @@ absl::Status ParsedMapValueInterface::Has(ValueManager& value_manager, return absl::OkStatus(); } -absl::Status ParsedMapValueInterface::ForEach(ValueManager& value_manager, +absl::Status CustomMapValueInterface::ForEach(ValueManager& value_manager, ForEachCallback callback) const { CEL_ASSIGN_OR_RETURN(auto iterator, NewIterator(value_manager)); while (iterator->HasNext()) { @@ -287,7 +287,7 @@ absl::Status ParsedMapValueInterface::ForEach(ValueManager& value_manager, return absl::OkStatus(); } -absl::Status ParsedMapValueInterface::Equal(ValueManager& value_manager, +absl::Status CustomMapValueInterface::Equal(ValueManager& value_manager, const Value& other, Value& result) const { if (auto list_value = other.As(); list_value.has_value()) { @@ -297,14 +297,14 @@ absl::Status ParsedMapValueInterface::Equal(ValueManager& value_manager, return absl::OkStatus(); } -ParsedMapValue::ParsedMapValue() - : ParsedMapValue( +CustomMapValue::CustomMapValue() + : CustomMapValue( common_internal::MakeShared(&EmptyMapValue::Get(), nullptr)) {} -ParsedMapValue ParsedMapValue::Clone(Allocator<> allocator) const { +CustomMapValue CustomMapValue::Clone(Allocator<> allocator) const { ABSL_DCHECK(*this); if (ABSL_PREDICT_FALSE(!interface_)) { - return ParsedMapValue(); + return CustomMapValue(); } if (absl::Nullable arena = allocator.arena(); arena != nullptr && diff --git a/common/values/parsed_map_value.h b/common/values/custom_map_value.h similarity index 79% rename from common/values/parsed_map_value.h rename to common/values/custom_map_value.h index 97cb71ffe..fa7d87de9 100644 --- a/common/values/parsed_map_value.h +++ b/common/values/custom_map_value.h @@ -15,11 +15,11 @@ // IWYU pragma: private, include "common/value.h" // IWYU pragma: friend "common/value.h" -// `ParsedMapValue` represents values of the primitive `map` type. -// `ParsedMapValueView` is a non-owning view of `ParsedMapValue`. -// `ParsedMapValueInterface` is the abstract base class of implementations. -// `ParsedMapValue` and `ParsedMapValueView` act as smart pointers to -// `ParsedMapValueInterface`. +// `CustomMapValue` represents values of the primitive `map` type. +// `CustomMapValueView` is a non-owning view of `CustomMapValue`. +// `CustomMapValueInterface` is the abstract base class of implementations. +// `CustomMapValue` and `CustomMapValueView` act as smart pointers to +// `CustomMapValueInterface`. #ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_PARSED_MAP_VALUE_H_ #define THIRD_PARTY_CEL_CPP_COMMON_VALUES_PARSED_MAP_VALUE_H_ @@ -32,6 +32,7 @@ #include "absl/base/attributes.h" #include "absl/base/nullability.h" +#include "absl/functional/function_ref.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/cord.h" @@ -39,9 +40,8 @@ #include "common/allocator.h" #include "common/memory.h" #include "common/native_type.h" -#include "common/value_interface.h" #include "common/value_kind.h" -#include "common/values/map_value_interface.h" +#include "common/values/custom_value_interface.h" #include "common/values/values.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" @@ -50,15 +50,22 @@ namespace cel { class Value; class ListValue; -class ParsedMapValueInterface; -class ParsedMapValue; +class CustomMapValueInterface; +class CustomMapValue; class ValueManager; -class ParsedMapValueInterface : public MapValueInterface { +class CustomMapValueInterface : public CustomValueInterface { public: - using alternative_type = ParsedMapValue; + using alternative_type = CustomMapValue; - static constexpr ValueKind kKind = MapValueInterface::kKind; + static constexpr ValueKind kKind = ValueKind::kMap; + + ValueKind kind() const final { return kKind; } + + absl::string_view GetTypeName() const final { return "map"; } + + using ForEachCallback = + absl::FunctionRef(const Value&, const Value&)>; absl::Status SerializeTo( absl::Nonnull descriptor_pool, @@ -107,7 +114,7 @@ class ParsedMapValueInterface : public MapValueInterface { virtual absl::StatusOr> NewIterator( ValueManager& value_manager) const = 0; - virtual ParsedMapValue Clone(ArenaAllocator<> allocator) const = 0; + virtual CustomMapValue Clone(ArenaAllocator<> allocator) const = 0; protected: // Called by `Find` after performing various argument checks. @@ -120,23 +127,23 @@ class ParsedMapValueInterface : public MapValueInterface { const Value& key) const = 0; }; -class ParsedMapValue { +class CustomMapValue { public: - using interface_type = ParsedMapValueInterface; + using interface_type = CustomMapValueInterface; - static constexpr ValueKind kKind = ParsedMapValueInterface::kKind; + static constexpr ValueKind kKind = CustomMapValueInterface::kKind; // NOLINTNEXTLINE(google-explicit-constructor) - ParsedMapValue(Shared interface) + CustomMapValue(Shared interface) : interface_(std::move(interface)) {} // By default, this creates an empty map whose type is `map(dyn, dyn)`. Unless // you can help it, you should use a more specific typed map value. - ParsedMapValue(); - ParsedMapValue(const ParsedMapValue&) = default; - ParsedMapValue(ParsedMapValue&&) = default; - ParsedMapValue& operator=(const ParsedMapValue&) = default; - ParsedMapValue& operator=(ParsedMapValue&&) = default; + CustomMapValue(); + CustomMapValue(const CustomMapValue&) = default; + CustomMapValue(CustomMapValue&&) = default; + CustomMapValue& operator=(const CustomMapValue&) = default; + CustomMapValue& operator=(CustomMapValue&&) = default; constexpr ValueKind kind() const { return kKind; } @@ -174,7 +181,7 @@ class ParsedMapValue { bool IsZeroValue() const { return interface_->IsZeroValue(); } - ParsedMapValue Clone(Allocator<> allocator) const; + CustomMapValue Clone(Allocator<> allocator) const; bool IsEmpty() const { return interface_->IsEmpty(); } @@ -201,7 +208,7 @@ class ParsedMapValue { // See the corresponding type declaration of `MapValueInterface` for // documentation. - using ForEachCallback = typename MapValueInterface::ForEachCallback; + using ForEachCallback = typename CustomMapValueInterface::ForEachCallback; // See the corresponding member function of `MapValueInterface` for // documentation. @@ -213,7 +220,7 @@ class ParsedMapValue { absl::StatusOr> NewIterator( ValueManager& value_manager) const; - void swap(ParsedMapValue& other) noexcept { + void swap(CustomMapValue& other) noexcept { using std::swap; swap(interface_, other.interface_); } @@ -227,41 +234,41 @@ class ParsedMapValue { explicit operator bool() const { return static_cast(interface_); } private: - friend struct NativeTypeTraits; + friend struct NativeTypeTraits; - Shared interface_; + Shared interface_; }; -inline void swap(ParsedMapValue& lhs, ParsedMapValue& rhs) noexcept { +inline void swap(CustomMapValue& lhs, CustomMapValue& rhs) noexcept { lhs.swap(rhs); } -inline std::ostream& operator<<(std::ostream& out, const ParsedMapValue& type) { +inline std::ostream& operator<<(std::ostream& out, const CustomMapValue& type) { return out << type.DebugString(); } template <> -struct NativeTypeTraits final { - static NativeTypeId Id(const ParsedMapValue& type) { +struct NativeTypeTraits final { + static NativeTypeId Id(const CustomMapValue& type) { return NativeTypeId::Of(*type.interface_); } - static bool SkipDestructor(const ParsedMapValue& type) { + static bool SkipDestructor(const CustomMapValue& type) { return NativeType::SkipDestructor(type.interface_); } }; template struct NativeTypeTraits>, - std::is_base_of>>> + std::negation>, + std::is_base_of>>> final { static NativeTypeId Id(const T& type) { - return NativeTypeTraits::Id(type); + return NativeTypeTraits::Id(type); } static bool SkipDestructor(const T& type) { - return NativeTypeTraits::SkipDestructor(type); + return NativeTypeTraits::SkipDestructor(type); } }; diff --git a/common/values/parsed_struct_value.cc b/common/values/custom_struct_value.cc similarity index 84% rename from common/values/parsed_struct_value.cc rename to common/values/custom_struct_value.cc index b0470c7a3..e59db040f 100644 --- a/common/values/parsed_struct_value.cc +++ b/common/values/custom_struct_value.cc @@ -29,10 +29,10 @@ namespace cel { -absl::Status ParsedStructValueInterface::Equal(ValueManager& value_manager, +absl::Status CustomStructValueInterface::Equal(ValueManager& value_manager, const Value& other, Value& result) const { - if (auto parsed_struct_value = As(other); + if (auto parsed_struct_value = As(other); parsed_struct_value.has_value() && NativeTypeId::Of(*this) == NativeTypeId::Of(*parsed_struct_value)) { return EqualImpl(value_manager, *parsed_struct_value, result); @@ -45,16 +45,16 @@ absl::Status ParsedStructValueInterface::Equal(ValueManager& value_manager, return absl::OkStatus(); } -absl::Status ParsedStructValueInterface::EqualImpl( - ValueManager& value_manager, const ParsedStructValue& other, +absl::Status CustomStructValueInterface::EqualImpl( + ValueManager& value_manager, const CustomStructValue& other, Value& result) const { return common_internal::StructValueEqual(value_manager, *this, other, result); } -ParsedStructValue ParsedStructValue::Clone(Allocator<> allocator) const { +CustomStructValue CustomStructValue::Clone(Allocator<> allocator) const { ABSL_DCHECK(*this); if (ABSL_PREDICT_FALSE(!interface_)) { - return ParsedStructValue(); + return CustomStructValue(); } if (absl::Nullable arena = allocator.arena(); arena != nullptr && @@ -64,7 +64,7 @@ ParsedStructValue ParsedStructValue::Clone(Allocator<> allocator) const { return *this; } -absl::StatusOr ParsedStructValueInterface::Qualify( +absl::StatusOr CustomStructValueInterface::Qualify( ValueManager&, absl::Span, bool, Value&) const { return absl::UnimplementedError("Qualify not supported."); } diff --git a/common/values/parsed_struct_value.h b/common/values/custom_struct_value.h similarity index 74% rename from common/values/parsed_struct_value.h rename to common/values/custom_struct_value.h index 28d777abf..41b3d7bac 100644 --- a/common/values/parsed_struct_value.h +++ b/common/values/custom_struct_value.h @@ -25,6 +25,7 @@ #include #include "absl/base/nullability.h" +#include "absl/functional/function_ref.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/cord.h" @@ -36,21 +37,32 @@ #include "common/native_type.h" #include "common/type.h" #include "common/value_kind.h" -#include "common/values/struct_value_interface.h" +#include "common/values/custom_value_interface.h" #include "runtime/runtime_options.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" namespace cel { -class ParsedStructValueInterface; -class ParsedStructValue; +class CustomStructValueInterface; +class CustomStructValue; class Value; class ValueManager; -class ParsedStructValueInterface : public StructValueInterface { +class CustomStructValueInterface : public CustomValueInterface { public: - using alternative_type = ParsedStructValue; + using alternative_type = CustomStructValue; + + static constexpr ValueKind kKind = ValueKind::kStruct; + + ValueKind kind() const final { return kKind; } + + virtual StructType GetRuntimeType() const { + return common_internal::MakeBasicStructType(GetTypeName()); + } + + using ForEachFieldCallback = + absl::FunctionRef(absl::string_view, const Value&)>; absl::Status Equal(ValueManager& value_manager, const Value& other, Value& result) const; @@ -76,29 +88,29 @@ class ParsedStructValueInterface : public StructValueInterface { ValueManager& value_manager, absl::Span qualifiers, bool presence_test, Value& result) const; - virtual ParsedStructValue Clone(ArenaAllocator<> allocator) const = 0; + virtual CustomStructValue Clone(ArenaAllocator<> allocator) const = 0; protected: virtual absl::Status EqualImpl(ValueManager& value_manager, - const ParsedStructValue& other, + const CustomStructValue& other, Value& result) const; }; -class ParsedStructValue { +class CustomStructValue { public: - using interface_type = ParsedStructValueInterface; + using interface_type = CustomStructValueInterface; - static constexpr ValueKind kKind = ParsedStructValueInterface::kKind; + static constexpr ValueKind kKind = CustomStructValueInterface::kKind; // NOLINTNEXTLINE(google-explicit-constructor) - ParsedStructValue(Shared interface) + CustomStructValue(Shared interface) : interface_(std::move(interface)) {} - ParsedStructValue() = default; - ParsedStructValue(const ParsedStructValue&) = default; - ParsedStructValue(ParsedStructValue&&) = default; - ParsedStructValue& operator=(const ParsedStructValue&) = default; - ParsedStructValue& operator=(ParsedStructValue&&) = default; + CustomStructValue() = default; + CustomStructValue(const CustomStructValue&) = default; + CustomStructValue(CustomStructValue&&) = default; + CustomStructValue& operator=(const CustomStructValue&) = default; + CustomStructValue& operator=(CustomStructValue&&) = default; constexpr ValueKind kind() const { return kKind; } @@ -138,9 +150,9 @@ class ParsedStructValue { bool IsZeroValue() const { return interface_->IsZeroValue(); } - ParsedStructValue Clone(Allocator<> allocator) const; + CustomStructValue Clone(Allocator<> allocator) const; - void swap(ParsedStructValue& other) noexcept { + void swap(CustomStructValue& other) noexcept { using std::swap; swap(interface_, other.interface_); } @@ -161,7 +173,7 @@ class ParsedStructValue { return interface_->HasFieldByNumber(number); } - using ForEachFieldCallback = StructValueInterface::ForEachFieldCallback; + using ForEachFieldCallback = CustomStructValueInterface::ForEachFieldCallback; absl::Status ForEachField(ValueManager& value_manager, ForEachFieldCallback callback) const; @@ -179,27 +191,27 @@ class ParsedStructValue { explicit operator bool() const { return static_cast(interface_); } private: - friend struct NativeTypeTraits; + friend struct NativeTypeTraits; - Shared interface_; + Shared interface_; }; -inline void swap(ParsedStructValue& lhs, ParsedStructValue& rhs) noexcept { +inline void swap(CustomStructValue& lhs, CustomStructValue& rhs) noexcept { lhs.swap(rhs); } inline std::ostream& operator<<(std::ostream& out, - const ParsedStructValue& value) { + const CustomStructValue& value) { return out << value.DebugString(); } template <> -struct NativeTypeTraits final { - static NativeTypeId Id(const ParsedStructValue& type) { +struct NativeTypeTraits final { + static NativeTypeId Id(const CustomStructValue& type) { return NativeTypeId::Of(*type.interface_); } - static bool SkipDestructor(const ParsedStructValue& type) { + static bool SkipDestructor(const CustomStructValue& type) { return NativeType::SkipDestructor(type.interface_); } }; @@ -207,15 +219,15 @@ struct NativeTypeTraits final { template struct NativeTypeTraits< T, std::enable_if_t< - std::conjunction_v>, - std::is_base_of>>> + std::conjunction_v>, + std::is_base_of>>> final { static NativeTypeId Id(const T& type) { - return NativeTypeTraits::Id(type); + return NativeTypeTraits::Id(type); } static bool SkipDestructor(const T& type) { - return NativeTypeTraits::SkipDestructor(type); + return NativeTypeTraits::SkipDestructor(type); } }; diff --git a/common/value_interface.cc b/common/values/custom_value_interface.cc similarity index 93% rename from common/value_interface.cc rename to common/values/custom_value_interface.cc index 6c7f99e5f..b6ec20f2d 100644 --- a/common/value_interface.cc +++ b/common/values/custom_value_interface.cc @@ -23,7 +23,7 @@ namespace cel { -absl::Status ValueInterface::SerializeTo( +absl::Status CustomValueInterface::SerializeTo( absl::Nonnull descriptor_pool, absl::Nonnull message_factory, absl::Cord& value) const { @@ -34,7 +34,7 @@ absl::Status ValueInterface::SerializeTo( absl::StrCat(GetTypeName(), " is unserializable")); } -absl::Status ValueInterface::ConvertToJson( +absl::Status CustomValueInterface::ConvertToJson( absl::Nonnull descriptor_pool, absl::Nonnull message_factory, absl::Nonnull json) const { @@ -48,7 +48,7 @@ absl::Status ValueInterface::ConvertToJson( absl::StrCat(GetTypeName(), " is not convertable to JSON")); } -absl::Status ValueInterface::ConvertToJsonArray( +absl::Status CustomValueInterface::ConvertToJsonArray( absl::Nonnull descriptor_pool, absl::Nonnull message_factory, absl::Nonnull json) const { @@ -62,7 +62,7 @@ absl::Status ValueInterface::ConvertToJsonArray( absl::StrCat(GetTypeName(), " is not convertable to JSON array")); } -absl::Status ValueInterface::ConvertToJsonObject( +absl::Status CustomValueInterface::ConvertToJsonObject( absl::Nonnull descriptor_pool, absl::Nonnull message_factory, absl::Nonnull json) const { diff --git a/common/value_interface.h b/common/values/custom_value_interface.h similarity index 89% rename from common/value_interface.h rename to common/values/custom_value_interface.h index cb584ecb2..005b059ab 100644 --- a/common/value_interface.h +++ b/common/values/custom_value_interface.h @@ -15,8 +15,8 @@ // IWYU pragma: private, include "common/value.h" // IWYU pragma: friend "common/value.h" -#ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUE_INTERFACE_H_ -#define THIRD_PARTY_CEL_CPP_COMMON_VALUE_INTERFACE_H_ +#ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_CUSTOM_VALUE_INTERFACE_H_ +#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_CUSTOM_VALUE_INTERFACE_H_ #include @@ -31,10 +31,7 @@ namespace cel { -class TypeManager; -class ValueManager; - -class ValueInterface : public common_internal::DataInterface { +class CustomValueInterface : public common_internal::DataInterface { public: using DataInterface::DataInterface; @@ -71,4 +68,4 @@ class ValueInterface : public common_internal::DataInterface { } // namespace cel -#endif // THIRD_PARTY_CEL_CPP_COMMON_VALUE_INTERFACE_H_ +#endif // THIRD_PARTY_CEL_CPP_COMMON_VALUES_CUSTOM_VALUE_INTERFACE_H_ diff --git a/common/values/legacy_list_value.cc b/common/values/legacy_list_value.cc index 36c599232..58fc1feb3 100644 --- a/common/values/legacy_list_value.cc +++ b/common/values/legacy_list_value.cc @@ -64,18 +64,18 @@ absl::optional AsLegacyListValue(const Value& value) { if (IsLegacyListValue(value)) { return GetLegacyListValue(value); } - if (auto parsed_list_value = value.AsParsedList(); parsed_list_value) { - NativeTypeId native_type_id = NativeTypeId::Of(*parsed_list_value); + if (auto custom_list_value = value.AsCustomList(); custom_list_value) { + NativeTypeId native_type_id = NativeTypeId::Of(*custom_list_value); if (native_type_id == NativeTypeId::For()) { return LegacyListValue(reinterpret_cast( static_cast( cel::internal::down_cast( - (*parsed_list_value).operator->())))); + (*custom_list_value).operator->())))); } else if (native_type_id == NativeTypeId::For()) { return LegacyListValue(reinterpret_cast( static_cast( cel::internal::down_cast( - (*parsed_list_value).operator->())))); + (*custom_list_value).operator->())))); } } return absl::nullopt; diff --git a/common/values/legacy_list_value.h b/common/values/legacy_list_value.h index a5abc4009..f060ac49f 100644 --- a/common/values/legacy_list_value.h +++ b/common/values/legacy_list_value.h @@ -30,7 +30,7 @@ #include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "common/value_kind.h" -#include "common/values/list_value_interface.h" +#include "common/values/custom_list_value.h" #include "common/values/values.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" @@ -100,10 +100,10 @@ class LegacyListValue final { absl::Status Get(ValueManager& value_manager, size_t index, Value& result) const; - using ForEachCallback = typename ListValueInterface::ForEachCallback; + using ForEachCallback = typename CustomListValueInterface::ForEachCallback; using ForEachWithIndexCallback = - typename ListValueInterface::ForEachWithIndexCallback; + typename CustomListValueInterface::ForEachWithIndexCallback; absl::Status ForEach(ValueManager& value_manager, ForEachCallback callback) const; diff --git a/common/values/legacy_map_value.cc b/common/values/legacy_map_value.cc index 770397cd3..a52197b52 100644 --- a/common/values/legacy_map_value.cc +++ b/common/values/legacy_map_value.cc @@ -24,7 +24,6 @@ #include "common/native_type.h" #include "common/value_manager.h" #include "common/values/map_value_builder.h" -#include "common/values/map_value_interface.h" #include "common/values/values.h" #include "eval/public/cel_value.h" #include "internal/casts.h" @@ -53,18 +52,18 @@ absl::optional AsLegacyMapValue(const Value& value) { if (IsLegacyMapValue(value)) { return GetLegacyMapValue(value); } - if (auto parsed_map_value = value.AsParsedMap(); parsed_map_value) { - NativeTypeId native_type_id = NativeTypeId::Of(*parsed_map_value); + if (auto custom_map_value = value.AsCustomMap(); custom_map_value) { + NativeTypeId native_type_id = NativeTypeId::Of(*custom_map_value); if (native_type_id == NativeTypeId::For()) { return LegacyMapValue(reinterpret_cast( static_cast( cel::internal::down_cast( - (*parsed_map_value).operator->())))); + (*custom_map_value).operator->())))); } else if (native_type_id == NativeTypeId::For()) { return LegacyMapValue(reinterpret_cast( static_cast( cel::internal::down_cast( - (*parsed_map_value).operator->())))); + (*custom_map_value).operator->())))); } } return absl::nullopt; diff --git a/common/values/legacy_map_value.h b/common/values/legacy_map_value.h index 2d93a3766..600377acc 100644 --- a/common/values/legacy_map_value.h +++ b/common/values/legacy_map_value.h @@ -31,7 +31,7 @@ #include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "common/value_kind.h" -#include "common/values/map_value_interface.h" +#include "common/values/custom_map_value.h" #include "common/values/values.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" @@ -107,7 +107,7 @@ class LegacyMapValue final { absl::Status ListKeys(ValueManager& value_manager, ListValue& result) const; - using ForEachCallback = typename MapValueInterface::ForEachCallback; + using ForEachCallback = typename CustomMapValueInterface::ForEachCallback; absl::Status ForEach(ValueManager& value_manager, ForEachCallback callback) const; diff --git a/common/values/legacy_struct_value.h b/common/values/legacy_struct_value.h index 488af477d..8e27c954b 100644 --- a/common/values/legacy_struct_value.h +++ b/common/values/legacy_struct_value.h @@ -33,7 +33,7 @@ #include "base/attribute.h" #include "common/type.h" #include "common/value_kind.h" -#include "common/values/struct_value_interface.h" +#include "common/values/custom_struct_value.h" #include "runtime/runtime_options.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" @@ -112,7 +112,7 @@ class LegacyStructValue final { absl::StatusOr HasFieldByNumber(int64_t number) const; - using ForEachFieldCallback = StructValueInterface::ForEachFieldCallback; + using ForEachFieldCallback = CustomStructValueInterface::ForEachFieldCallback; absl::Status ForEachField(ValueManager& value_manager, ForEachFieldCallback callback) const; diff --git a/common/values/list_value.cc b/common/values/list_value.cc index bee07df73..7869956ea 100644 --- a/common/values/list_value.cc +++ b/common/values/list_value.cc @@ -137,7 +137,7 @@ absl::Status ListValueEqual(ValueManager& value_manager, const ListValue& lhs, } absl::Status ListValueEqual(ValueManager& value_manager, - const ParsedListValueInterface& lhs, + const CustomListValueInterface& lhs, const ListValue& rhs, Value& result) { auto lhs_size = lhs.Size(); CEL_ASSIGN_OR_RETURN(auto rhs_size, rhs.Size()); @@ -168,29 +168,29 @@ absl::Status ListValueEqual(ValueManager& value_manager, } // namespace common_internal -optional_ref ListValue::AsParsed() const& { - if (const auto* alt = absl::get_if(&variant_); +optional_ref ListValue::AsCustom() const& { + if (const auto* alt = absl::get_if(&variant_); alt != nullptr) { return *alt; } return absl::nullopt; } -absl::optional ListValue::AsParsed() && { - if (auto* alt = absl::get_if(&variant_); alt != nullptr) { +absl::optional ListValue::AsCustom() && { + if (auto* alt = absl::get_if(&variant_); alt != nullptr) { return std::move(*alt); } return absl::nullopt; } -const ParsedListValue& ListValue::GetParsed() const& { - ABSL_DCHECK(IsParsed()); - return absl::get(variant_); +const CustomListValue& ListValue::GetCustom() const& { + ABSL_DCHECK(IsCustom()); + return absl::get(variant_); } -ParsedListValue ListValue::GetParsed() && { - ABSL_DCHECK(IsParsed()); - return absl::get(std::move(variant_)); +CustomListValue ListValue::GetCustom() && { + ABSL_DCHECK(IsCustom()); + return absl::get(std::move(variant_)); } common_internal::ValueVariant ListValue::ToValueVariant() const& { diff --git a/common/values/list_value.h b/common/values/list_value.h index f5aca213d..48639f636 100644 --- a/common/values/list_value.h +++ b/common/values/list_value.h @@ -43,10 +43,9 @@ #include "common/native_type.h" #include "common/optional_ref.h" #include "common/value_kind.h" -#include "common/values/legacy_list_value.h" // IWYU pragma: export -#include "common/values/list_value_interface.h" // IWYU pragma: export +#include "common/values/custom_list_value.h" +#include "common/values/legacy_list_value.h" #include "common/values/parsed_json_list_value.h" -#include "common/values/parsed_list_value.h" // IWYU pragma: export #include "common/values/parsed_repeated_field_value.h" #include "common/values/values.h" #include "google/protobuf/descriptor.h" @@ -64,7 +63,7 @@ class ListValue final { public: using interface_type = ListValueInterface; - static constexpr ValueKind kKind = ListValueInterface::kKind; + static constexpr ValueKind kKind = CustomListValueInterface::kKind; // Copy constructor for alternative struct values. template < @@ -122,7 +121,7 @@ class ListValue final { ABSL_DCHECK(this != std::addressof(other)) << "ListValue should not be moved to itself"; variant_ = std::move(other.variant_); - other.variant_.emplace(); + other.variant_.emplace(); return *this; } @@ -169,10 +168,10 @@ class ListValue final { Value& result) const; absl::StatusOr Get(ValueManager& value_manager, size_t index) const; - using ForEachCallback = typename ListValueInterface::ForEachCallback; + using ForEachCallback = typename CustomListValueInterface::ForEachCallback; using ForEachWithIndexCallback = - typename ListValueInterface::ForEachWithIndexCallback; + typename CustomListValueInterface::ForEachWithIndexCallback; absl::Status ForEach(ValueManager& value_manager, ForEachCallback callback) const; @@ -188,91 +187,91 @@ class ListValue final { absl::StatusOr Contains(ValueManager& value_manager, const Value& other) const; - // Returns `true` if this value is an instance of a parsed list value. - bool IsParsed() const { - return absl::holds_alternative(variant_); + // Returns `true` if this value is an instance of a custom list value. + bool IsCustom() const { + return absl::holds_alternative(variant_); } // Convenience method for use with template metaprogramming. See // `IsParsed()`. template - std::enable_if_t, bool> Is() const { - return IsParsed(); + std::enable_if_t, bool> Is() const { + return IsCustom(); } - // Performs a checked cast from a value to a parsed list value, + // Performs a checked cast from a value to a custom list value, // returning a non-empty optional with either a value or reference to the - // parsed list value. Otherwise an empty optional is returned. - optional_ref AsParsed() & + // custom list value. Otherwise an empty optional is returned. + optional_ref AsCustom() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return std::as_const(*this).AsParsed(); + return std::as_const(*this).AsCustom(); } - optional_ref AsParsed() + optional_ref AsCustom() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; - absl::optional AsParsed() &&; - absl::optional AsParsed() const&& { - return common_internal::AsOptional(AsParsed()); + absl::optional AsCustom() &&; + absl::optional AsCustom() const&& { + return common_internal::AsOptional(AsCustom()); } // Convenience method for use with template metaprogramming. See - // `AsParsed()`. + // `AsCustom()`. template - std::enable_if_t, - optional_ref> + std::enable_if_t, + optional_ref> As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return AsParsed(); + return AsCustom(); } template - std::enable_if_t, - optional_ref> + std::enable_if_t, + optional_ref> As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { - return AsParsed(); + return AsCustom(); } template - std::enable_if_t, - absl::optional> + std::enable_if_t, + absl::optional> As() && { - return std::move(*this).AsParsed(); + return std::move(*this).AsCustom(); } template - std::enable_if_t, - absl::optional> + std::enable_if_t, + absl::optional> As() const&& { - return std::move(*this).AsParsed(); + return std::move(*this).AsCustom(); } - // Performs an unchecked cast from a value to a parsed list value. In - // debug builds a best effort is made to crash. If `IsParsed()` would + // Performs an unchecked cast from a value to a custom list value. In + // debug builds a best effort is made to crash. If `IsCustom()` would // return false, calling this method is undefined behavior. - const ParsedListValue& GetParsed() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return std::as_const(*this).GetParsed(); + const CustomListValue& GetCustom() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetCustom(); } - const ParsedListValue& GetParsed() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; - ParsedListValue GetParsed() &&; - ParsedListValue GetParsed() const&& { return GetParsed(); } + const CustomListValue& GetCustom() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; + CustomListValue GetCustom() &&; + CustomListValue GetCustom() const&& { return GetCustom(); } // Convenience method for use with template metaprogramming. See - // `GetParsed()`. + // `GetCustom()`. template - std::enable_if_t, - const ParsedListValue&> + std::enable_if_t, + const CustomListValue&> Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return GetParsed(); + return GetCustom(); } template - std::enable_if_t, const ParsedListValue&> + std::enable_if_t, const CustomListValue&> Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { - return GetParsed(); + return GetCustom(); } template - std::enable_if_t, ParsedListValue> + std::enable_if_t, CustomListValue> Get() && { - return std::move(*this).GetParsed(); + return std::move(*this).GetCustom(); } template - std::enable_if_t, ParsedListValue> Get() + std::enable_if_t, CustomListValue> Get() const&& { - return std::move(*this).GetParsed(); + return std::move(*this).GetCustom(); } private: diff --git a/common/values/list_value_builder.h b/common/values/list_value_builder.h index 0845ced08..c8bd8a4a2 100644 --- a/common/values/list_value_builder.h +++ b/common/values/list_value_builder.h @@ -37,7 +37,7 @@ namespace common_internal { // Special implementation of list which is both a modern list and legacy list. // Do not try this at home. This should only be implemented in // `list_value_builder.cc`. -class CompatListValue : public ParsedListValueInterface, +class CompatListValue : public CustomListValueInterface, public google::api::expr::runtime::CelList { private: NativeTypeId GetNativeTypeId() const final { @@ -48,7 +48,7 @@ class CompatListValue : public ParsedListValueInterface, absl::Nonnull EmptyCompatListValue(); absl::StatusOr> MakeCompatListValue( - absl::Nonnull arena, const ParsedListValue& value); + absl::Nonnull arena, const CustomListValue& value); // Extension of ParsedListValueInterface which is also mutable. Accessing this // like a normal list before all elements are finished being appended is a bug. @@ -56,7 +56,7 @@ absl::StatusOr> MakeCompatListValue( // which accumulate results into a list. // // IMPORTANT: This type is only meant to be utilized by the runtime. -class MutableListValue : public ParsedListValueInterface { +class MutableListValue : public CustomListValueInterface { public: virtual absl::Status Append(Value value) const = 0; diff --git a/common/values/list_value_interface.h b/common/values/list_value_interface.h deleted file mode 100644 index 10a4fc689..000000000 --- a/common/values/list_value_interface.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// IWYU pragma: private, include "common/value.h" -// IWYU pragma: friend "common/value.h" - -#ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_LIST_VALUE_INTERFACE_H_ -#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_LIST_VALUE_INTERFACE_H_ - -#include - -#include "absl/functional/function_ref.h" -#include "absl/status/statusor.h" -#include "absl/strings/string_view.h" -#include "common/value_interface.h" -#include "common/value_kind.h" - -namespace cel { - -class Value; -class ListValue; - -class ListValueInterface : public ValueInterface { - public: - using alternative_type = ListValue; - - static constexpr ValueKind kKind = ValueKind::kList; - - ValueKind kind() const final { return kKind; } - - absl::string_view GetTypeName() const final { return "list"; } - - using ForEachCallback = absl::FunctionRef(const Value&)>; - - using ForEachWithIndexCallback = - absl::FunctionRef(size_t, const Value&)>; -}; - -} // namespace cel - -#endif // THIRD_PARTY_CEL_CPP_COMMON_VALUES_LIST_VALUE_INTERFACE_H_ diff --git a/common/values/map_value.cc b/common/values/map_value.cc index 5ad8835fe..aefc77e76 100644 --- a/common/values/map_value.cc +++ b/common/values/map_value.cc @@ -154,7 +154,7 @@ absl::Status MapValueEqual(ValueManager& value_manager, const MapValue& lhs, } absl::Status MapValueEqual(ValueManager& value_manager, - const ParsedMapValueInterface& lhs, + const CustomMapValueInterface& lhs, const MapValue& rhs, Value& result) { auto lhs_size = lhs.Size(); CEL_ASSIGN_OR_RETURN(auto rhs_size, rhs.Size()); @@ -207,29 +207,29 @@ absl::Status CheckMapKey(const Value& key) { } } -optional_ref MapValue::AsParsed() const& { - if (const auto* alt = absl::get_if(&variant_); +optional_ref MapValue::AsCustom() const& { + if (const auto* alt = absl::get_if(&variant_); alt != nullptr) { return *alt; } return absl::nullopt; } -absl::optional MapValue::AsParsed() && { - if (auto* alt = absl::get_if(&variant_); alt != nullptr) { +absl::optional MapValue::AsCustom() && { + if (auto* alt = absl::get_if(&variant_); alt != nullptr) { return std::move(*alt); } return absl::nullopt; } -const ParsedMapValue& MapValue::GetParsed() const& { - ABSL_DCHECK(IsParsed()); - return absl::get(variant_); +const CustomMapValue& MapValue::GetCustom() const& { + ABSL_DCHECK(IsCustom()); + return absl::get(variant_); } -ParsedMapValue MapValue::GetParsed() && { - ABSL_DCHECK(IsParsed()); - return absl::get(std::move(variant_)); +CustomMapValue MapValue::GetCustom() && { + ABSL_DCHECK(IsCustom()); + return absl::get(std::move(variant_)); } common_internal::ValueVariant MapValue::ToValueVariant() const& { diff --git a/common/values/map_value.h b/common/values/map_value.h index 3fbf56e85..3f8d2f887 100644 --- a/common/values/map_value.h +++ b/common/values/map_value.h @@ -44,11 +44,10 @@ #include "common/native_type.h" #include "common/optional_ref.h" #include "common/value_kind.h" -#include "common/values/legacy_map_value.h" // IWYU pragma: export -#include "common/values/map_value_interface.h" // IWYU pragma: export +#include "common/values/custom_map_value.h" +#include "common/values/legacy_map_value.h" #include "common/values/parsed_json_map_value.h" #include "common/values/parsed_map_field_value.h" -#include "common/values/parsed_map_value.h" // IWYU pragma: export #include "common/values/values.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" @@ -67,7 +66,7 @@ class MapValue final { public: using interface_type = MapValueInterface; - static constexpr ValueKind kKind = MapValueInterface::kKind; + static constexpr ValueKind kKind = CustomMapValueInterface::kKind; // Copy constructor for alternative struct values. template (); + other.variant_.emplace(); return *this; } @@ -192,7 +191,7 @@ class MapValue final { // See the corresponding type declaration of `MapValueInterface` for // documentation. - using ForEachCallback = typename MapValueInterface::ForEachCallback; + using ForEachCallback = typename CustomMapValueInterface::ForEachCallback; // See the corresponding member function of `MapValueInterface` for // documentation. @@ -204,89 +203,89 @@ class MapValue final { absl::StatusOr> NewIterator( ValueManager& value_manager) const; - // Returns `true` if this value is an instance of a parsed map value. - bool IsParsed() const { - return absl::holds_alternative(variant_); + // Returns `true` if this value is an instance of a custom map value. + bool IsCustom() const { + return absl::holds_alternative(variant_); } // Convenience method for use with template metaprogramming. See - // `IsParsed()`. + // `IsCustom()`. template - std::enable_if_t, bool> Is() const { - return IsParsed(); + std::enable_if_t, bool> Is() const { + return IsCustom(); } - // Performs a checked cast from a value to a parsed map value, + // Performs a checked cast from a value to a custom map value, // returning a non-empty optional with either a value or reference to the - // parsed map value. Otherwise an empty optional is returned. - optional_ref AsParsed() & + // custom map value. Otherwise an empty optional is returned. + optional_ref AsCustom() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return std::as_const(*this).AsParsed(); + return std::as_const(*this).AsCustom(); } - optional_ref AsParsed() + optional_ref AsCustom() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; - absl::optional AsParsed() &&; - absl::optional AsParsed() const&& { - return common_internal::AsOptional(AsParsed()); + absl::optional AsCustom() &&; + absl::optional AsCustom() const&& { + return common_internal::AsOptional(AsCustom()); } // Convenience method for use with template metaprogramming. See - // `AsParsed()`. + // `AsCustom()`. template - std::enable_if_t, - optional_ref> + std::enable_if_t, + optional_ref> As() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return AsParsed(); + return AsCustom(); } template - std::enable_if_t, - optional_ref> + std::enable_if_t, + optional_ref> As() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { - return AsParsed(); + return AsCustom(); } template - std::enable_if_t, - absl::optional> + std::enable_if_t, + absl::optional> As() && { - return std::move(*this).AsParsed(); + return std::move(*this).AsCustom(); } template - std::enable_if_t, - absl::optional> + std::enable_if_t, + absl::optional> As() const&& { - return std::move(*this).AsParsed(); + return std::move(*this).AsCustom(); } - // Performs an unchecked cast from a value to a parsed map value. In - // debug builds a best effort is made to crash. If `IsParsed()` would + // Performs an unchecked cast from a value to a custom map value. In + // debug builds a best effort is made to crash. If `IsCustom()` would // return false, calling this method is undefined behavior. - const ParsedMapValue& GetParsed() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return std::as_const(*this).GetParsed(); + const CustomMapValue& GetCustom() & ABSL_ATTRIBUTE_LIFETIME_BOUND { + return std::as_const(*this).GetCustom(); } - const ParsedMapValue& GetParsed() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; - ParsedMapValue GetParsed() &&; - ParsedMapValue GetParsed() const&& { return GetParsed(); } + const CustomMapValue& GetCustom() const& ABSL_ATTRIBUTE_LIFETIME_BOUND; + CustomMapValue GetCustom() &&; + CustomMapValue GetCustom() const&& { return GetCustom(); } // Convenience method for use with template metaprogramming. See - // `GetParsed()`. + // `GetCustom()`. template - std::enable_if_t, const ParsedMapValue&> + std::enable_if_t, const CustomMapValue&> Get() & ABSL_ATTRIBUTE_LIFETIME_BOUND { - return GetParsed(); + return GetCustom(); } template - std::enable_if_t, const ParsedMapValue&> + std::enable_if_t, const CustomMapValue&> Get() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { - return GetParsed(); + return GetCustom(); } template - std::enable_if_t, ParsedMapValue> Get() && { - return std::move(*this).GetParsed(); + std::enable_if_t, CustomMapValue> Get() && { + return std::move(*this).GetCustom(); } template - std::enable_if_t, ParsedMapValue> Get() + std::enable_if_t, CustomMapValue> Get() const&& { - return std::move(*this).GetParsed(); + return std::move(*this).GetCustom(); } private: diff --git a/common/values/map_value_builder.h b/common/values/map_value_builder.h index ac2cdb1dd..af8995f4d 100644 --- a/common/values/map_value_builder.h +++ b/common/values/map_value_builder.h @@ -37,7 +37,7 @@ namespace common_internal { // Special implementation of map which is both a modern map and legacy map. Do // not try this at home. This should only be implemented in // `map_value_builder.cc`. -class CompatMapValue : public ParsedMapValueInterface, +class CompatMapValue : public CustomMapValueInterface, public google::api::expr::runtime::CelMap { private: NativeTypeId GetNativeTypeId() const final { @@ -48,7 +48,7 @@ class CompatMapValue : public ParsedMapValueInterface, absl::Nonnull EmptyCompatMapValue(); absl::StatusOr> MakeCompatMapValue( - absl::Nonnull arena, const ParsedMapValue& value); + absl::Nonnull arena, const CustomMapValue& value); // Extension of ParsedMapValueInterface which is also mutable. Accessing this // like a normal map before all entries are finished being inserted is a bug. @@ -56,7 +56,7 @@ absl::StatusOr> MakeCompatMapValue( // which accumulate results into a map. // // IMPORTANT: This type is only meant to be utilized by the runtime. -class MutableMapValue : public ParsedMapValueInterface { +class MutableMapValue : public CustomMapValueInterface { public: virtual absl::Status Put(Value key, Value value) const = 0; diff --git a/common/values/map_value_interface.h b/common/values/map_value_interface.h deleted file mode 100644 index 04f5a608f..000000000 --- a/common/values/map_value_interface.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// IWYU pragma: private, include "common/value.h" -// IWYU pragma: friend "common/value.h" - -#ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_MAP_VALUE_INTERFACE_H_ -#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_MAP_VALUE_INTERFACE_H_ - -#include "absl/functional/function_ref.h" -#include "absl/status/statusor.h" -#include "absl/strings/string_view.h" -#include "common/value_interface.h" -#include "common/value_kind.h" - -namespace cel { - -class Value; -class MapValue; - -class MapValueInterface : public ValueInterface { - public: - using alternative_type = MapValue; - - static constexpr ValueKind kKind = ValueKind::kMap; - - ValueKind kind() const final { return kKind; } - - absl::string_view GetTypeName() const final { return "map"; } - - using ForEachCallback = - absl::FunctionRef(const Value&, const Value&)>; -}; - -} // namespace cel - -#endif // THIRD_PARTY_CEL_CPP_COMMON_VALUES_MAP_VALUE_INTERFACE_H_ diff --git a/common/values/message_value.h b/common/values/message_value.h index 2a73d69d7..5842b7917 100644 --- a/common/values/message_value.h +++ b/common/values/message_value.h @@ -43,8 +43,8 @@ #include "common/optional_ref.h" #include "common/type.h" #include "common/value_kind.h" +#include "common/values/custom_struct_value.h" #include "common/values/parsed_message_value.h" -#include "common/values/struct_value_interface.h" #include "common/values/values.h" #include "runtime/runtime_options.h" #include "google/protobuf/descriptor.h" @@ -134,7 +134,7 @@ class MessageValue final { absl::StatusOr HasFieldByNumber(int64_t number) const; - using ForEachFieldCallback = StructValueInterface::ForEachFieldCallback; + using ForEachFieldCallback = CustomStructValueInterface::ForEachFieldCallback; absl::Status ForEachField(ValueManager& value_manager, ForEachFieldCallback callback) const; diff --git a/common/values/mutable_list_value_test.cc b/common/values/mutable_list_value_test.cc index 18344f34b..1a8d8f84f 100644 --- a/common/values/mutable_list_value_test.cc +++ b/common/values/mutable_list_value_test.cc @@ -154,25 +154,25 @@ TEST_P(MutableListValueTest, Get) { TEST_P(MutableListValueTest, IsMutablListValue) { auto mutable_list_value = NewMutableListValue(allocator()); - EXPECT_TRUE(IsMutableListValue(Value(ParsedListValue(mutable_list_value)))); + EXPECT_TRUE(IsMutableListValue(Value(CustomListValue(mutable_list_value)))); EXPECT_TRUE( - IsMutableListValue(ListValue(ParsedListValue(mutable_list_value)))); + IsMutableListValue(ListValue(CustomListValue(mutable_list_value)))); } TEST_P(MutableListValueTest, AsMutableListValue) { auto mutable_list_value = NewMutableListValue(allocator()); - EXPECT_EQ(AsMutableListValue(Value(ParsedListValue(mutable_list_value))), + EXPECT_EQ(AsMutableListValue(Value(CustomListValue(mutable_list_value))), mutable_list_value.operator->()); - EXPECT_EQ(AsMutableListValue(ListValue(ParsedListValue(mutable_list_value))), + EXPECT_EQ(AsMutableListValue(ListValue(CustomListValue(mutable_list_value))), mutable_list_value.operator->()); } TEST_P(MutableListValueTest, GetMutableListValue) { auto mutable_list_value = NewMutableListValue(allocator()); - EXPECT_EQ(&GetMutableListValue(Value(ParsedListValue(mutable_list_value))), + EXPECT_EQ(&GetMutableListValue(Value(CustomListValue(mutable_list_value))), mutable_list_value.operator->()); EXPECT_EQ( - &GetMutableListValue(ListValue(ParsedListValue(mutable_list_value))), + &GetMutableListValue(ListValue(CustomListValue(mutable_list_value))), mutable_list_value.operator->()); } diff --git a/common/values/mutable_map_value_test.cc b/common/values/mutable_map_value_test.cc index 81136da73..e316c1ef1 100644 --- a/common/values/mutable_map_value_test.cc +++ b/common/values/mutable_map_value_test.cc @@ -183,23 +183,23 @@ TEST_P(MutableMapValueTest, FindHas) { TEST_P(MutableMapValueTest, IsMutableMapValue) { auto mutable_map_value = NewMutableMapValue(allocator()); - EXPECT_TRUE(IsMutableMapValue(Value(ParsedMapValue(mutable_map_value)))); - EXPECT_TRUE(IsMutableMapValue(MapValue(ParsedMapValue(mutable_map_value)))); + EXPECT_TRUE(IsMutableMapValue(Value(CustomMapValue(mutable_map_value)))); + EXPECT_TRUE(IsMutableMapValue(MapValue(CustomMapValue(mutable_map_value)))); } TEST_P(MutableMapValueTest, AsMutableMapValue) { auto mutable_map_value = NewMutableMapValue(allocator()); - EXPECT_EQ(AsMutableMapValue(Value(ParsedMapValue(mutable_map_value))), + EXPECT_EQ(AsMutableMapValue(Value(CustomMapValue(mutable_map_value))), mutable_map_value.operator->()); - EXPECT_EQ(AsMutableMapValue(MapValue(ParsedMapValue(mutable_map_value))), + EXPECT_EQ(AsMutableMapValue(MapValue(CustomMapValue(mutable_map_value))), mutable_map_value.operator->()); } TEST_P(MutableMapValueTest, GetMutableMapValue) { auto mutable_map_value = NewMutableMapValue(allocator()); - EXPECT_EQ(&GetMutableMapValue(Value(ParsedMapValue(mutable_map_value))), + EXPECT_EQ(&GetMutableMapValue(Value(CustomMapValue(mutable_map_value))), mutable_map_value.operator->()); - EXPECT_EQ(&GetMutableMapValue(MapValue(ParsedMapValue(mutable_map_value))), + EXPECT_EQ(&GetMutableMapValue(MapValue(CustomMapValue(mutable_map_value))), mutable_map_value.operator->()); } diff --git a/common/values/opaque_value.h b/common/values/opaque_value.h index 02d8ebc1e..6aa2aa77f 100644 --- a/common/values/opaque_value.h +++ b/common/values/opaque_value.h @@ -41,8 +41,8 @@ #include "common/native_type.h" #include "common/optional_ref.h" #include "common/type.h" -#include "common/value_interface.h" #include "common/value_kind.h" +#include "common/values/custom_value_interface.h" #include "common/values/values.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" @@ -56,7 +56,7 @@ class OpaqueValue; class TypeFactory; class ValueManager; -class OpaqueValueInterface : public ValueInterface { +class OpaqueValueInterface : public CustomValueInterface { public: using alternative_type = OpaqueValue; diff --git a/common/values/optional_value.h b/common/values/optional_value.h index c099b5b74..341fedb81 100644 --- a/common/values/optional_value.h +++ b/common/values/optional_value.h @@ -33,7 +33,6 @@ #include "common/native_type.h" #include "common/optional_ref.h" #include "common/type.h" -#include "common/value_interface.h" #include "common/values/opaque_value.h" #include "internal/casts.h" diff --git a/common/values/parsed_json_list_value.h b/common/values/parsed_json_list_value.h index f75791770..649a9a4d3 100644 --- a/common/values/parsed_json_list_value.h +++ b/common/values/parsed_json_list_value.h @@ -37,7 +37,7 @@ #include "common/memory.h" #include "common/type.h" #include "common/value_kind.h" -#include "common/values/list_value_interface.h" +#include "common/values/custom_list_value.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" @@ -128,10 +128,10 @@ class ParsedJsonListValue final { Value& result) const; absl::StatusOr Get(ValueManager& value_manager, size_t index) const; - using ForEachCallback = typename ListValueInterface::ForEachCallback; + using ForEachCallback = typename CustomListValueInterface::ForEachCallback; using ForEachWithIndexCallback = - typename ListValueInterface::ForEachWithIndexCallback; + typename CustomListValueInterface::ForEachWithIndexCallback; absl::Status ForEach(ValueManager& value_manager, ForEachCallback callback) const; diff --git a/common/values/parsed_json_map_value.h b/common/values/parsed_json_map_value.h index f9907dcae..1b418b3e0 100644 --- a/common/values/parsed_json_map_value.h +++ b/common/values/parsed_json_map_value.h @@ -37,7 +37,7 @@ #include "common/memory.h" #include "common/type.h" #include "common/value_kind.h" -#include "common/values/map_value_interface.h" +#include "common/values/custom_map_value.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" @@ -142,7 +142,7 @@ class ParsedJsonMapValue final { absl::Status ListKeys(ValueManager& value_manager, ListValue& result) const; absl::StatusOr ListKeys(ValueManager& value_manager) const; - using ForEachCallback = typename MapValueInterface::ForEachCallback; + using ForEachCallback = typename CustomMapValueInterface::ForEachCallback; absl::Status ForEach(ValueManager& value_manager, ForEachCallback callback) const; diff --git a/common/values/parsed_map_field_value.h b/common/values/parsed_map_field_value.h index f710eb147..5933ec5b5 100644 --- a/common/values/parsed_map_field_value.h +++ b/common/values/parsed_map_field_value.h @@ -36,7 +36,7 @@ #include "common/memory.h" #include "common/type.h" #include "common/value_kind.h" -#include "common/values/map_value_interface.h" +#include "common/values/custom_map_value.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" @@ -128,7 +128,7 @@ class ParsedMapFieldValue final { absl::Status ListKeys(ValueManager& value_manager, ListValue& result) const; absl::StatusOr ListKeys(ValueManager& value_manager) const; - using ForEachCallback = typename MapValueInterface::ForEachCallback; + using ForEachCallback = typename CustomMapValueInterface::ForEachCallback; absl::Status ForEach(ValueManager& value_manager, ForEachCallback callback) const; diff --git a/common/values/parsed_message_value.h b/common/values/parsed_message_value.h index 8347f7131..089abd746 100644 --- a/common/values/parsed_message_value.h +++ b/common/values/parsed_message_value.h @@ -40,7 +40,7 @@ #include "common/memory.h" #include "common/type.h" #include "common/value_kind.h" -#include "common/values/struct_value_interface.h" +#include "common/values/custom_struct_value.h" #include "runtime/runtime_options.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" @@ -153,7 +153,7 @@ class ParsedMessageValue final { absl::StatusOr HasFieldByNumber(int64_t number) const; - using ForEachFieldCallback = StructValueInterface::ForEachFieldCallback; + using ForEachFieldCallback = CustomStructValueInterface::ForEachFieldCallback; absl::Status ForEachField(ValueManager& value_manager, ForEachFieldCallback callback) const; diff --git a/common/values/parsed_repeated_field_value.h b/common/values/parsed_repeated_field_value.h index 5ee23f9e9..3e273a187 100644 --- a/common/values/parsed_repeated_field_value.h +++ b/common/values/parsed_repeated_field_value.h @@ -36,7 +36,7 @@ #include "common/memory.h" #include "common/type.h" #include "common/value_kind.h" -#include "common/values/list_value_interface.h" +#include "common/values/custom_list_value.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" @@ -115,10 +115,10 @@ class ParsedRepeatedFieldValue final { Value& result) const; absl::StatusOr Get(ValueManager& value_manager, size_t index) const; - using ForEachCallback = typename ListValueInterface::ForEachCallback; + using ForEachCallback = typename CustomListValueInterface::ForEachCallback; using ForEachWithIndexCallback = - typename ListValueInterface::ForEachWithIndexCallback; + typename CustomListValueInterface::ForEachWithIndexCallback; absl::Status ForEach(ValueManager& value_manager, ForEachCallback callback) const; diff --git a/common/values/struct_value.cc b/common/values/struct_value.cc index b8e08b643..be3cc43cc 100644 --- a/common/values/struct_value.cc +++ b/common/values/struct_value.cc @@ -241,7 +241,7 @@ absl::Status StructValueEqual(ValueManager& value_manager, } absl::Status StructValueEqual(ValueManager& value_manager, - const ParsedStructValueInterface& lhs, + const CustomStructValueInterface& lhs, const StructValue& rhs, Value& result) { if (lhs.GetTypeName() != rhs.GetTypeName()) { result = BoolValue{false}; diff --git a/common/values/struct_value.h b/common/values/struct_value.h index ae0e39cf6..9e7a1ebff 100644 --- a/common/values/struct_value.h +++ b/common/values/struct_value.h @@ -45,11 +45,10 @@ #include "common/optional_ref.h" #include "common/type.h" #include "common/value_kind.h" -#include "common/values/legacy_struct_value.h" // IWYU pragma: export +#include "common/values/custom_struct_value.h" +#include "common/values/legacy_struct_value.h" #include "common/values/message_value.h" #include "common/values/parsed_message_value.h" -#include "common/values/parsed_struct_value.h" // IWYU pragma: export -#include "common/values/struct_value_interface.h" // IWYU pragma: export #include "common/values/values.h" #include "runtime/runtime_options.h" #include "google/protobuf/descriptor.h" @@ -57,7 +56,6 @@ namespace cel { -class StructValueInterface; class StructValue; class Value; class ValueManager; @@ -65,9 +63,7 @@ class TypeManager; class StructValue final { public: - using interface_type = StructValueInterface; - - static constexpr ValueKind kKind = StructValueInterface::kKind; + static constexpr ValueKind kKind = CustomStructValueInterface::kKind; // Copy constructor for alternative struct values. template < @@ -196,7 +192,7 @@ class StructValue final { absl::StatusOr HasFieldByNumber(int64_t number) const; - using ForEachFieldCallback = StructValueInterface::ForEachFieldCallback; + using ForEachFieldCallback = CustomStructValueInterface::ForEachFieldCallback; absl::Status ForEachField(ValueManager& value_manager, ForEachFieldCallback callback) const; diff --git a/common/values/struct_value_interface.h b/common/values/struct_value_interface.h deleted file mode 100644 index b892e6ca4..000000000 --- a/common/values/struct_value_interface.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// IWYU pragma: private, include "common/value.h" -// IWYU pragma: friend "common/value.h" - -#ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_STRUCT_VALUE_INTERFACE_H_ -#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_STRUCT_VALUE_INTERFACE_H_ - -#include "absl/functional/function_ref.h" -#include "absl/status/statusor.h" -#include "absl/strings/string_view.h" -#include "common/type.h" -#include "common/value_interface.h" -#include "common/value_kind.h" - -namespace cel { - -class Value; -class StructValue; - -class StructValueInterface : public ValueInterface { - public: - using alternative_type = StructValue; - - static constexpr ValueKind kKind = ValueKind::kStruct; - - ValueKind kind() const final { return kKind; } - - virtual StructType GetRuntimeType() const { - return common_internal::MakeBasicStructType(GetTypeName()); - } - - using ForEachFieldCallback = - absl::FunctionRef(absl::string_view, const Value&)>; -}; - -} // namespace cel - -#endif // THIRD_PARTY_CEL_CPP_COMMON_VALUES_STRUCT_VALUE_INTERFACE_H_ diff --git a/common/values/value_builder.cc b/common/values/value_builder.cc index 63fd1453a..2888e5ced 100644 --- a/common/values/value_builder.cc +++ b/common/values/value_builder.cc @@ -205,12 +205,12 @@ class TrivialListValueImpl final : public CompatListValue { json); } - ParsedListValue Clone(ArenaAllocator<> allocator) const override { - // This is unreachable with the current logic in ParsedListValue, but could - // be called once we keep track of the owning arena in ParsedListValue. + CustomListValue Clone(ArenaAllocator<> allocator) const override { + // This is unreachable with the current logic in CustomListValue, but could + // be called once we keep track of the owning arena in CustomListValue. TrivialValueVector cloned_elements( elements_, ArenaAllocator{allocator.arena()}); - return ParsedListValue( + return CustomListValue( MemoryManager(allocator).MakeShared( std::move(cloned_elements))); } @@ -291,7 +291,7 @@ namespace common_internal { namespace { -class NonTrivialListValueImpl final : public ParsedListValueInterface { +class NonTrivialListValueImpl final : public CustomListValueInterface { public: explicit NonTrivialListValueImpl(NonTrivialValueVector&& elements) : elements_(std::move(elements)) {} @@ -316,7 +316,7 @@ class NonTrivialListValueImpl final : public ParsedListValueInterface { json); } - ParsedListValue Clone(ArenaAllocator<> allocator) const override { + CustomListValue Clone(ArenaAllocator<> allocator) const override { TrivialValueVector cloned_elements( ArenaAllocator{allocator.arena()}); cloned_elements.reserve(elements_.size()); @@ -324,7 +324,7 @@ class NonTrivialListValueImpl final : public ParsedListValueInterface { cloned_elements.emplace_back( MakeTrivialValue(*element, allocator.arena())); } - return ParsedListValue( + return CustomListValue( MemoryManager(allocator).MakeShared( std::move(cloned_elements))); } @@ -398,12 +398,12 @@ class TrivialMutableListValueImpl final : public MutableCompatListValue { json); } - ParsedListValue Clone(ArenaAllocator<> allocator) const override { - // This is unreachable with the current logic in ParsedListValue, but could - // be called once we keep track of the owning arena in ParsedListValue. + CustomListValue Clone(ArenaAllocator<> allocator) const override { + // This is unreachable with the current logic in CustomListValue, but could + // be called once we keep track of the owning arena in CustomListValue. TrivialValueVector cloned_elements( elements_, ArenaAllocator{allocator.arena()}); - return ParsedListValue( + return CustomListValue( MemoryManager(allocator).MakeShared( std::move(cloned_elements))); } @@ -518,7 +518,7 @@ class NonTrivialMutableListValueImpl final : public MutableListValue { json); } - ParsedListValue Clone(ArenaAllocator<> allocator) const override { + CustomListValue Clone(ArenaAllocator<> allocator) const override { TrivialValueVector cloned_elements( ArenaAllocator{allocator.arena()}); cloned_elements.reserve(elements_.size()); @@ -526,7 +526,7 @@ class NonTrivialMutableListValueImpl final : public MutableListValue { cloned_elements.emplace_back( MakeTrivialValue(*element, allocator.arena())); } - return ParsedListValue( + return CustomListValue( MemoryManager(allocator).MakeShared( std::move(cloned_elements))); } @@ -599,7 +599,7 @@ class TrivialListValueBuilderImpl final : public ListValueBuilder { if (elements_.empty()) { return ListValue(); } - return ParsedListValue( + return CustomListValue( MemoryManager::Pooling(arena_).MakeShared( std::move(elements_))); } @@ -627,7 +627,7 @@ class NonTrivialListValueBuilderImpl final : public ListValueBuilder { if (elements_.empty()) { return ListValue(); } - return ParsedListValue( + return CustomListValue( MemoryManager::ReferenceCounting().MakeShared( std::move(elements_))); } @@ -639,7 +639,7 @@ class NonTrivialListValueBuilderImpl final : public ListValueBuilder { } // namespace absl::StatusOr> MakeCompatListValue( - absl::Nonnull arena, const ParsedListValue& value) { + absl::Nonnull arena, const CustomListValue& value) { if (value.IsEmpty()) { return EmptyCompatListValue(); } @@ -667,8 +667,8 @@ Shared NewMutableListValue(Allocator<> allocator) { } bool IsMutableListValue(const Value& value) { - if (auto parsed_list_value = value.AsParsedList(); parsed_list_value) { - NativeTypeId native_type_id = NativeTypeId::Of(**parsed_list_value); + if (auto custom_list_value = value.AsCustomList(); custom_list_value) { + NativeTypeId native_type_id = NativeTypeId::Of(**custom_list_value); if (native_type_id == NativeTypeId::For() || native_type_id == NativeTypeId::For()) { return true; @@ -678,8 +678,8 @@ bool IsMutableListValue(const Value& value) { } bool IsMutableListValue(const ListValue& value) { - if (auto parsed_list_value = value.AsParsed(); parsed_list_value) { - NativeTypeId native_type_id = NativeTypeId::Of(**parsed_list_value); + if (auto custom_list_value = value.AsCustom(); custom_list_value) { + NativeTypeId native_type_id = NativeTypeId::Of(**custom_list_value); if (native_type_id == NativeTypeId::For() || native_type_id == NativeTypeId::For()) { return true; @@ -689,15 +689,15 @@ bool IsMutableListValue(const ListValue& value) { } absl::Nullable AsMutableListValue(const Value& value) { - if (auto parsed_list_value = value.AsParsedList(); parsed_list_value) { - NativeTypeId native_type_id = NativeTypeId::Of(**parsed_list_value); + if (auto custom_list_value = value.AsCustomList(); custom_list_value) { + NativeTypeId native_type_id = NativeTypeId::Of(**custom_list_value); if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - (*parsed_list_value).operator->()); + (*custom_list_value).operator->()); } if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - (*parsed_list_value).operator->()); + (*custom_list_value).operator->()); } } return nullptr; @@ -705,15 +705,15 @@ absl::Nullable AsMutableListValue(const Value& value) { absl::Nullable AsMutableListValue( const ListValue& value) { - if (auto parsed_list_value = value.AsParsed(); parsed_list_value) { - NativeTypeId native_type_id = NativeTypeId::Of(**parsed_list_value); + if (auto custom_list_value = value.AsCustom(); custom_list_value) { + NativeTypeId native_type_id = NativeTypeId::Of(**custom_list_value); if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - (*parsed_list_value).operator->()); + (*custom_list_value).operator->()); } if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - (*parsed_list_value).operator->()); + (*custom_list_value).operator->()); } } return nullptr; @@ -721,30 +721,30 @@ absl::Nullable AsMutableListValue( const MutableListValue& GetMutableListValue(const Value& value) { ABSL_DCHECK(IsMutableListValue(value)) << value; - const auto& parsed_list_value = value.GetParsedList(); - NativeTypeId native_type_id = NativeTypeId::Of(*parsed_list_value); + const auto& custom_list_value = value.GetCustomList(); + NativeTypeId native_type_id = NativeTypeId::Of(*custom_list_value); if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - *parsed_list_value); + *custom_list_value); } if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - *parsed_list_value); + *custom_list_value); } ABSL_UNREACHABLE(); } const MutableListValue& GetMutableListValue(const ListValue& value) { ABSL_DCHECK(IsMutableListValue(value)) << value; - const auto& parsed_list_value = value.GetParsed(); - NativeTypeId native_type_id = NativeTypeId::Of(*parsed_list_value); + const auto& custom_list_value = value.GetCustom(); + NativeTypeId native_type_id = NativeTypeId::Of(*custom_list_value); if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - *parsed_list_value); + *custom_list_value); } if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - *parsed_list_value); + *custom_list_value); } ABSL_UNREACHABLE(); } @@ -1110,12 +1110,12 @@ class TrivialMapValueImpl final : public CompatMapValue { return MapValueToJsonObject(map_, descriptor_pool, message_factory, json); } - ParsedMapValue Clone(ArenaAllocator<> allocator) const override { - // This is unreachable with the current logic in ParsedMapValue, but could - // be called once we keep track of the owning arena in ParsedListValue. + CustomMapValue Clone(ArenaAllocator<> allocator) const override { + // This is unreachable with the current logic in CustomMapValue, but could + // be called once we keep track of the owning arena in CustomListValue. TrivialValueFlatHashMap cloned_entries( map_, ArenaAllocator{allocator.arena()}); - return ParsedMapValue( + return CustomMapValue( MemoryManager(allocator).MakeShared( std::move(cloned_entries))); } @@ -1124,7 +1124,7 @@ class TrivialMapValueImpl final : public CompatMapValue { absl::Status ListKeys(ValueManager& value_manager, ListValue& result) const override { - result = ParsedListValue(MakeShared(kAdoptRef, ProjectKeys(), nullptr)); + result = CustomListValue(MakeShared(kAdoptRef, ProjectKeys(), nullptr)); return absl::OkStatus(); } @@ -1230,7 +1230,7 @@ namespace common_internal { namespace { -class NonTrivialMapValueImpl final : public ParsedMapValueInterface { +class NonTrivialMapValueImpl final : public CustomMapValueInterface { public: explicit NonTrivialMapValueImpl(NonTrivialValueFlatHashMap&& map) : map_(std::move(map)) {} @@ -1253,9 +1253,9 @@ class NonTrivialMapValueImpl final : public ParsedMapValueInterface { return MapValueToJsonObject(map_, descriptor_pool, message_factory, json); } - ParsedMapValue Clone(ArenaAllocator<> allocator) const override { - // This is unreachable with the current logic in ParsedMapValue, but could - // be called once we keep track of the owning arena in ParsedListValue. + CustomMapValue Clone(ArenaAllocator<> allocator) const override { + // This is unreachable with the current logic in CustomMapValue, but could + // be called once we keep track of the owning arena in CustomListValue. TrivialValueFlatHashMap cloned_entries( ArenaAllocator{allocator.arena()}); cloned_entries.reserve(map_.size()); @@ -1268,7 +1268,7 @@ class NonTrivialMapValueImpl final : public ParsedMapValueInterface { .second; ABSL_DCHECK(inserted); } - return ParsedMapValue( + return CustomMapValue( MemoryManager(allocator).MakeShared( std::move(cloned_entries))); } @@ -1350,12 +1350,12 @@ class TrivialMutableMapValueImpl final : public MutableCompatMapValue { return MapValueToJsonObject(map_, descriptor_pool, message_factory, json); } - ParsedMapValue Clone(ArenaAllocator<> allocator) const override { - // This is unreachable with the current logic in ParsedMapValue, but could - // be called once we keep track of the owning arena in ParsedListValue. + CustomMapValue Clone(ArenaAllocator<> allocator) const override { + // This is unreachable with the current logic in CustomMapValue, but could + // be called once we keep track of the owning arena in CustomListValue. TrivialValueFlatHashMap cloned_entries( map_, ArenaAllocator{allocator.arena()}); - return ParsedMapValue( + return CustomMapValue( MemoryManager(allocator).MakeShared( std::move(cloned_entries))); } @@ -1364,7 +1364,7 @@ class TrivialMutableMapValueImpl final : public MutableCompatMapValue { absl::Status ListKeys(ValueManager& value_manager, ListValue& result) const override { - result = ParsedListValue(MakeShared(kAdoptRef, ProjectKeys(), nullptr)); + result = CustomListValue(MakeShared(kAdoptRef, ProjectKeys(), nullptr)); return absl::OkStatus(); } @@ -1509,9 +1509,9 @@ class NonTrivialMutableMapValueImpl final : public MutableMapValue { return MapValueToJsonObject(map_, descriptor_pool, message_factory, json); } - ParsedMapValue Clone(ArenaAllocator<> allocator) const override { - // This is unreachable with the current logic in ParsedMapValue, but could - // be called once we keep track of the owning arena in ParsedListValue. + CustomMapValue Clone(ArenaAllocator<> allocator) const override { + // This is unreachable with the current logic in CustomMapValue, but could + // be called once we keep track of the owning arena in CustomListValue. TrivialValueFlatHashMap cloned_entries( ArenaAllocator{allocator.arena()}); cloned_entries.reserve(map_.size()); @@ -1524,7 +1524,7 @@ class NonTrivialMutableMapValueImpl final : public MutableMapValue { .second; ABSL_DCHECK(inserted); } - return ParsedMapValue( + return CustomMapValue( MemoryManager(allocator).MakeShared( std::move(cloned_entries))); } @@ -1621,7 +1621,7 @@ class TrivialMapValueBuilderImpl final : public MapValueBuilder { if (map_.empty()) { return MapValue(); } - return ParsedMapValue( + return CustomMapValue( MemoryManager::Pooling(arena_).MakeShared( std::move(map_))); } @@ -1656,7 +1656,7 @@ class NonTrivialMapValueBuilderImpl final : public MapValueBuilder { if (map_.empty()) { return MapValue(); } - return ParsedMapValue( + return CustomMapValue( MemoryManager::ReferenceCounting().MakeShared( std::move(map_))); } @@ -1668,7 +1668,7 @@ class NonTrivialMapValueBuilderImpl final : public MapValueBuilder { } // namespace absl::StatusOr> MakeCompatMapValue( - absl::Nonnull arena, const ParsedMapValue& value) { + absl::Nonnull arena, const CustomMapValue& value) { if (value.IsEmpty()) { return EmptyCompatMapValue(); } @@ -1702,8 +1702,8 @@ Shared NewMutableMapValue(Allocator<> allocator) { } bool IsMutableMapValue(const Value& value) { - if (auto parsed_map_value = value.AsParsedMap(); parsed_map_value) { - NativeTypeId native_type_id = NativeTypeId::Of(**parsed_map_value); + if (auto custom_map_value = value.AsCustomMap(); custom_map_value) { + NativeTypeId native_type_id = NativeTypeId::Of(**custom_map_value); if (native_type_id == NativeTypeId::For() || native_type_id == NativeTypeId::For()) { return true; @@ -1713,8 +1713,8 @@ bool IsMutableMapValue(const Value& value) { } bool IsMutableMapValue(const MapValue& value) { - if (auto parsed_map_value = value.AsParsed(); parsed_map_value) { - NativeTypeId native_type_id = NativeTypeId::Of(**parsed_map_value); + if (auto custom_map_value = value.AsCustom(); custom_map_value) { + NativeTypeId native_type_id = NativeTypeId::Of(**custom_map_value); if (native_type_id == NativeTypeId::For() || native_type_id == NativeTypeId::For()) { return true; @@ -1724,15 +1724,15 @@ bool IsMutableMapValue(const MapValue& value) { } absl::Nullable AsMutableMapValue(const Value& value) { - if (auto parsed_map_value = value.AsParsedMap(); parsed_map_value) { - NativeTypeId native_type_id = NativeTypeId::Of(**parsed_map_value); + if (auto custom_map_value = value.AsCustomMap(); custom_map_value) { + NativeTypeId native_type_id = NativeTypeId::Of(**custom_map_value); if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - (*parsed_map_value).operator->()); + (*custom_map_value).operator->()); } if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - (*parsed_map_value).operator->()); + (*custom_map_value).operator->()); } } return nullptr; @@ -1740,15 +1740,15 @@ absl::Nullable AsMutableMapValue(const Value& value) { absl::Nullable AsMutableMapValue( const MapValue& value) { - if (auto parsed_map_value = value.AsParsed(); parsed_map_value) { - NativeTypeId native_type_id = NativeTypeId::Of(**parsed_map_value); + if (auto custom_map_value = value.AsCustom(); custom_map_value) { + NativeTypeId native_type_id = NativeTypeId::Of(**custom_map_value); if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - (*parsed_map_value).operator->()); + (*custom_map_value).operator->()); } if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - (*parsed_map_value).operator->()); + (*custom_map_value).operator->()); } } return nullptr; @@ -1756,28 +1756,28 @@ absl::Nullable AsMutableMapValue( const MutableMapValue& GetMutableMapValue(const Value& value) { ABSL_DCHECK(IsMutableMapValue(value)) << value; - const auto& parsed_map_value = value.GetParsedMap(); - NativeTypeId native_type_id = NativeTypeId::Of(*parsed_map_value); + const auto& custom_map_value = value.GetCustomMap(); + NativeTypeId native_type_id = NativeTypeId::Of(*custom_map_value); if (native_type_id == NativeTypeId::For()) { - return cel::internal::down_cast(*parsed_map_value); + return cel::internal::down_cast(*custom_map_value); } if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - *parsed_map_value); + *custom_map_value); } ABSL_UNREACHABLE(); } const MutableMapValue& GetMutableMapValue(const MapValue& value) { ABSL_DCHECK(IsMutableMapValue(value)) << value; - const auto& parsed_map_value = value.GetParsed(); - NativeTypeId native_type_id = NativeTypeId::Of(*parsed_map_value); + const auto& custom_map_value = value.GetCustom(); + NativeTypeId native_type_id = NativeTypeId::Of(*custom_map_value); if (native_type_id == NativeTypeId::For()) { - return cel::internal::down_cast(*parsed_map_value); + return cel::internal::down_cast(*custom_map_value); } if (native_type_id == NativeTypeId::For()) { return cel::internal::down_cast( - *parsed_map_value); + *custom_map_value); } ABSL_UNREACHABLE(); } diff --git a/common/values/values.h b/common/values/values.h index d4e779512..59437ed56 100644 --- a/common/values/values.h +++ b/common/values/values.h @@ -56,14 +56,14 @@ class ParsedRepeatedFieldValue; class ParsedJsonListValue; class ParsedJsonMapValue; -class ParsedListValue; -class ParsedListValueInterface; +class CustomListValue; +class CustomListValueInterface; -class ParsedMapValue; -class ParsedMapValueInterface; +class CustomMapValue; +class CustomMapValueInterface; -class ParsedStructValue; -class ParsedStructValueInterface; +class CustomStructValue; +class CustomStructValueInterface; class ValueIterator; using ValueIteratorPtr = std::unique_ptr; @@ -90,7 +90,7 @@ inline constexpr bool IsListValueInterfaceV = IsListValueInterface::value; template struct IsListValueAlternative - : std::bool_constant, + : std::bool_constant, std::is_same>> { }; @@ -99,7 +99,7 @@ inline constexpr bool IsListValueAlternativeV = IsListValueAlternative::value; using ListValueVariant = - absl::variant; template @@ -113,14 +113,14 @@ inline constexpr bool IsMapValueInterfaceV = IsMapValueInterface::value; template struct IsMapValueAlternative - : std::bool_constant, + : std::bool_constant, std::is_same>> { }; template inline constexpr bool IsMapValueAlternativeV = IsMapValueAlternative::value; -using MapValueVariant = absl::variant; template @@ -136,14 +136,14 @@ inline constexpr bool IsStructValueInterfaceV = template struct IsStructValueAlternative : std::bool_constant< - std::disjunction_v, + std::disjunction_v, std::is_same>> {}; template inline constexpr bool IsStructValueAlternativeV = IsStructValueAlternative::value; -using StructValueVariant = absl::variant; template @@ -172,10 +172,10 @@ inline constexpr bool IsValueAlternativeV = IsValueAlternative::value; using ValueVariant = absl::variant< absl::monostate, BoolValue, BytesValue, DoubleValue, DurationValue, - ErrorValue, IntValue, LegacyListValue, ParsedListValue, + ErrorValue, IntValue, LegacyListValue, CustomListValue, ParsedRepeatedFieldValue, ParsedJsonListValue, LegacyMapValue, - ParsedMapValue, ParsedMapFieldValue, ParsedJsonMapValue, NullValue, - OpaqueValue, StringValue, LegacyStructValue, ParsedStructValue, + CustomMapValue, ParsedMapFieldValue, ParsedJsonMapValue, NullValue, + OpaqueValue, StringValue, LegacyStructValue, CustomStructValue, ParsedMessageValue, TimestampValue, TypeValue, UintValue, UnknownValue>; // Get the base type alternative for the given alternative or interface. The @@ -192,8 +192,8 @@ struct BaseValueAlternativeFor>> template struct BaseValueAlternativeFor< - T, std::enable_if_t>> { - using type = ParsedListValue; + T, std::enable_if_t>> { + using type = CustomListValue; }; template @@ -204,14 +204,14 @@ struct BaseValueAlternativeFor< template struct BaseValueAlternativeFor< - T, std::enable_if_t>> { - using type = ParsedMapValue; + T, std::enable_if_t>> { + using type = CustomMapValue; }; template struct BaseValueAlternativeFor< - T, std::enable_if_t>> { - using type = ParsedStructValue; + T, std::enable_if_t>> { + using type = CustomStructValue; }; template @@ -230,8 +230,8 @@ struct BaseListValueAlternativeFor struct BaseListValueAlternativeFor< - T, std::enable_if_t>> { - using type = ParsedListValue; + T, std::enable_if_t>> { + using type = CustomListValue; }; template @@ -250,8 +250,8 @@ struct BaseMapValueAlternativeFor>> template struct BaseMapValueAlternativeFor< - T, std::enable_if_t>> { - using type = ParsedMapValue; + T, std::enable_if_t>> { + using type = CustomMapValue; }; template @@ -271,8 +271,8 @@ struct BaseStructValueAlternativeFor< template struct BaseStructValueAlternativeFor< - T, std::enable_if_t>> { - using type = ParsedStructValue; + T, std::enable_if_t>> { + using type = CustomStructValue; }; template @@ -281,9 +281,9 @@ using BaseStructValueAlternativeForT = ErrorValue GetDefaultErrorValue(); -ParsedListValue GetEmptyDynListValue(); +CustomListValue GetEmptyDynListValue(); -ParsedMapValue GetEmptyDynDynMapValue(); +CustomMapValue GetEmptyDynDynMapValue(); OptionalValue GetEmptyDynOptionalValue(); @@ -291,14 +291,14 @@ absl::Status ListValueEqual(ValueManager& value_manager, const ListValue& lhs, const ListValue& rhs, Value& result); absl::Status ListValueEqual(ValueManager& value_manager, - const ParsedListValueInterface& lhs, + const CustomListValueInterface& lhs, const ListValue& rhs, Value& result); absl::Status MapValueEqual(ValueManager& value_manager, const MapValue& lhs, const MapValue& rhs, Value& result); absl::Status MapValueEqual(ValueManager& value_manager, - const ParsedMapValueInterface& lhs, + const CustomMapValueInterface& lhs, const MapValue& rhs, Value& result); absl::Status StructValueEqual(ValueManager& value_manager, @@ -306,7 +306,7 @@ absl::Status StructValueEqual(ValueManager& value_manager, Value& result); absl::Status StructValueEqual(ValueManager& value_manager, - const ParsedStructValueInterface& lhs, + const CustomStructValueInterface& lhs, const StructValue& rhs, Value& result); const SharedByteString& AsSharedByteString(const BytesValue& value); diff --git a/eval/eval/create_list_step.cc b/eval/eval/create_list_step.cc index 3636ab8b8..4faa9b392 100644 --- a/eval/eval/create_list_step.cc +++ b/eval/eval/create_list_step.cc @@ -212,7 +212,7 @@ class MutableListStep : public ExpressionStepBase { absl::Status MutableListStep::Evaluate(ExecutionFrame* frame) const { frame->value_stack().Push( - cel::ParsedListValue(cel::common_internal::NewMutableListValue( + cel::CustomListValue(cel::common_internal::NewMutableListValue( frame->memory_manager().arena()))); return absl::OkStatus(); } @@ -229,7 +229,7 @@ class DirectMutableListStep : public DirectExpressionStep { absl::Status DirectMutableListStep::Evaluate( ExecutionFrameBase& frame, Value& result, AttributeTrail& attribute_trail) const { - result = cel::ParsedListValue(cel::common_internal::NewMutableListValue( + result = cel::CustomListValue(cel::common_internal::NewMutableListValue( frame.value_manager().GetMemoryManager().arena())); return absl::OkStatus(); } diff --git a/eval/eval/create_map_step.cc b/eval/eval/create_map_step.cc index f205dd4b0..32efea770 100644 --- a/eval/eval/create_map_step.cc +++ b/eval/eval/create_map_step.cc @@ -237,7 +237,7 @@ class MutableMapStep final : public ExpressionStep { explicit MutableMapStep(int64_t expr_id) : ExpressionStep(expr_id) {} absl::Status Evaluate(ExecutionFrame* frame) const override { - frame->value_stack().Push(cel::ParsedMapValue( + frame->value_stack().Push(cel::CustomMapValue( NewMutableMapValue(frame->memory_manager().arena()))); return absl::OkStatus(); } @@ -250,7 +250,7 @@ class DirectMutableMapStep final : public DirectExpressionStep { absl::Status Evaluate(ExecutionFrameBase& frame, Value& result, AttributeTrail& attribute) const override { - result = cel::ParsedMapValue( + result = cel::CustomMapValue( NewMutableMapValue(frame.value_manager().GetMemoryManager().arena())); return absl::OkStatus(); } diff --git a/eval/tests/modern_benchmark_test.cc b/eval/tests/modern_benchmark_test.cc index 98ff11451..a72452a5d 100644 --- a/eval/tests/modern_benchmark_test.cc +++ b/eval/tests/modern_benchmark_test.cc @@ -363,7 +363,7 @@ void BM_PolicySymbolic(benchmark::State& state) { BENCHMARK(BM_PolicySymbolic); -class RequestMapImpl : public ParsedMapValueInterface { +class RequestMapImpl : public CustomMapValueInterface { public: size_t Size() const override { return 3; } @@ -393,8 +393,8 @@ class RequestMapImpl : public ParsedMapValueInterface { return absl::UnimplementedError("Unsupported"); } - ParsedMapValue Clone(ArenaAllocator<> allocator) const override { - return ParsedMapValue( + CustomMapValue Clone(ArenaAllocator<> allocator) const override { + return CustomMapValue( MemoryManager::Pooling(allocator.arena()).MakeShared()); } @@ -451,7 +451,7 @@ void BM_PolicySymbolicMap(benchmark::State& state) { *runtime, parsed_expr)); Activation activation; - ParsedMapValue map_value( + CustomMapValue map_value( MemoryManager::Pooling(&arena).MakeShared()); activation.InsertOrAssignValue("request", std::move(map_value));