Skip to content

Commit ebf8c93

Browse files
jckingcopybara-github
authored andcommitted
Migrate Value::kind() to ValueKind
PiperOrigin-RevId: 534550418
1 parent 51d9fd4 commit ebf8c93

27 files changed

Lines changed: 256 additions & 235 deletions

base/internal/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ cc_library(
152152
"function_adapter.h",
153153
],
154154
deps = [
155+
"//base:data",
155156
"//base:handle",
156157
"//base:kind",
157-
"//base:value",
158158
"//internal:status_macros",
159159
"@com_google_absl//absl/status",
160160
"@com_google_absl//absl/status:statusor",

base/internal/data.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ class HeapData /* : public Data */ {
186186

187187
explicit HeapData(TypeKind kind) : HeapData(TypeKindToKind(kind)) {}
188188

189+
explicit HeapData(ValueKind kind) : HeapData(ValueKindToKind(kind)) {}
190+
189191
private:
190192
// Called by Arena-based memory managers to determine whether we actually need
191193
// our destructor called. Subclasses should override this if they want their

base/internal/function_adapter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ struct HandleToAdaptedVisitor {
184184
absl::Status operator()(const Handle<T>** out) {
185185
if (!input->Is<T>()) {
186186
return absl::InvalidArgumentError(
187-
absl::StrCat("expected ", KindToString(T::kKind), " value"));
187+
absl::StrCat("expected ", ValueKindToString(T::kKind), " value"));
188188
}
189189
*out = &(input.As<T>());
190190
return absl::OkStatus();
@@ -194,7 +194,7 @@ struct HandleToAdaptedVisitor {
194194
absl::Status operator()(const T** out) {
195195
if (!input->Is<T>()) {
196196
return absl::InvalidArgumentError(
197-
absl::StrCat("expected ", KindToString(T::kKind), " value"));
197+
absl::StrCat("expected ", ValueKindToString(T::kKind), " value"));
198198
}
199199
*out = &(*input.As<T>());
200200
return absl::OkStatus();

base/kind.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,22 @@ constexpr ValueKind KindToValueKind(Kind kind) {
225225
static_cast<std::underlying_type_t<Kind>>(kind));
226226
}
227227

228+
constexpr ValueKind TypeKindToValueKind(TypeKind kind) {
229+
ABSL_ASSERT(KindIsValueKind(TypeKindToKind(kind)));
230+
return static_cast<ValueKind>(
231+
static_cast<std::underlying_type_t<TypeKind>>(kind));
232+
}
233+
234+
constexpr TypeKind ValueKindToTypeKind(ValueKind kind) {
235+
ABSL_ASSERT(KindIsTypeKind(ValueKindToKind(kind)));
236+
return static_cast<TypeKind>(
237+
static_cast<std::underlying_type_t<ValueKind>>(kind));
238+
}
239+
240+
static_assert(std::is_same_v<std::underlying_type_t<TypeKind>,
241+
std::underlying_type_t<ValueKind>>,
242+
"TypeKind and ValueKind must have the same underlying type");
243+
228244
} // namespace cel
229245

230246
#endif // THIRD_PARTY_CEL_CPP_BASE_KIND_H_

0 commit comments

Comments
 (0)