Skip to content

Commit 8d92e26

Browse files
jckingkyessenov
authored andcommitted
Add missing aliases to the wrapper types
PiperOrigin-RevId: 533215268
1 parent 3e73481 commit 8d92e26

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

Diff for: base/type.cc

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ absl::Span<const absl::string_view> Type::aliases() const {
101101
return static_cast<const ListType*>(this)->aliases();
102102
case Kind::kMap:
103103
return static_cast<const MapType*>(this)->aliases();
104+
case Kind::kWrapper:
105+
return static_cast<const WrapperType*>(this)->aliases();
104106
default:
105107
// Everything else does not support aliases.
106108
return absl::Span<const absl::string_view>();

Diff for: base/types/wrapper_type.cc

+34
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "base/types/wrapper_type.h"
1616

1717
#include "absl/base/optimization.h"
18+
#include "absl/strings/string_view.h"
19+
#include "absl/types/span.h"
1820

1921
namespace cel {
2022

@@ -46,6 +48,20 @@ absl::string_view WrapperType::name() const {
4648
}
4749
}
4850

51+
absl::Span<const absl::string_view> WrapperType::aliases() const {
52+
switch (base_internal::Metadata::GetInlineVariant<Kind>(*this)) {
53+
case Kind::kDouble:
54+
return static_cast<const DoubleWrapperType*>(this)->aliases();
55+
case Kind::kInt:
56+
return static_cast<const IntWrapperType*>(this)->aliases();
57+
case Kind::kUint:
58+
return static_cast<const UintWrapperType*>(this)->aliases();
59+
default:
60+
// The other wrappers do not have aliases.
61+
return absl::Span<const absl::string_view>();
62+
}
63+
}
64+
4965
const Handle<Type>& WrapperType::wrapped() const {
5066
switch (base_internal::Metadata::GetInlineVariant<Kind>(*this)) {
5167
case Kind::kBool:
@@ -66,4 +82,22 @@ const Handle<Type>& WrapperType::wrapped() const {
6682
}
6783
}
6884

85+
absl::Span<const absl::string_view> DoubleWrapperType::aliases() const {
86+
static constexpr absl::string_view kAliases[] = {
87+
"google.protobuf.FloatValue"};
88+
return absl::MakeConstSpan(kAliases);
89+
}
90+
91+
absl::Span<const absl::string_view> IntWrapperType::aliases() const {
92+
static constexpr absl::string_view kAliases[] = {
93+
"google.protobuf.Int32Value"};
94+
return absl::MakeConstSpan(kAliases);
95+
}
96+
97+
absl::Span<const absl::string_view> UintWrapperType::aliases() const {
98+
static constexpr absl::string_view kAliases[] = {
99+
"google.protobuf.UInt32Value"};
100+
return absl::MakeConstSpan(kAliases);
101+
}
102+
69103
} // namespace cel

Diff for: base/types/wrapper_type.h

+17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "absl/base/attributes.h"
2323
#include "absl/log/absl_check.h"
2424
#include "absl/strings/string_view.h"
25+
#include "absl/types/span.h"
2526
#include "base/internal/data.h"
2627
#include "base/kind.h"
2728
#include "base/type.h"
@@ -69,13 +70,17 @@ class WrapperType : public Type, base_internal::InlineData {
6970
const Handle<Type>& wrapped() const;
7071

7172
private:
73+
friend class Type;
7274
friend class BoolWrapperType;
7375
friend class BytesWrapperType;
7476
friend class DoubleWrapperType;
7577
friend class IntWrapperType;
7678
friend class StringWrapperType;
7779
friend class UintWrapperType;
7880

81+
// See Type::aliases().
82+
absl::Span<const absl::string_view> aliases() const;
83+
7984
using Base::Base;
8085
};
8186

@@ -189,6 +194,7 @@ class DoubleWrapperType final : public WrapperType {
189194
const Handle<DoubleType>& wrapped() const { return DoubleType::Get(); }
190195

191196
private:
197+
friend class WrapperType;
192198
friend class TypeFactory;
193199
template <size_t Size, size_t Align>
194200
friend struct base_internal::AnyData;
@@ -202,6 +208,9 @@ class DoubleWrapperType final : public WrapperType {
202208
<< base_internal::kInlineVariantShift);
203209

204210
constexpr DoubleWrapperType() : WrapperType(kMetadata) {}
211+
212+
// See Type::aliases().
213+
absl::Span<const absl::string_view> aliases() const;
205214
};
206215

207216
class IntWrapperType final : public WrapperType {
@@ -226,6 +235,7 @@ class IntWrapperType final : public WrapperType {
226235
const Handle<IntType>& wrapped() const { return IntType::Get(); }
227236

228237
private:
238+
friend class WrapperType;
229239
friend class TypeFactory;
230240
template <size_t Size, size_t Align>
231241
friend struct base_internal::AnyData;
@@ -239,6 +249,9 @@ class IntWrapperType final : public WrapperType {
239249
<< base_internal::kInlineVariantShift);
240250

241251
constexpr IntWrapperType() : WrapperType(kMetadata) {}
252+
253+
// See Type::aliases().
254+
absl::Span<const absl::string_view> aliases() const;
242255
};
243256

244257
class StringWrapperType final : public WrapperType {
@@ -300,6 +313,7 @@ class UintWrapperType final : public WrapperType {
300313
const Handle<UintType>& wrapped() const { return UintType::Get(); }
301314

302315
private:
316+
friend class WrapperType;
303317
friend class TypeFactory;
304318
template <size_t Size, size_t Align>
305319
friend struct base_internal::AnyData;
@@ -313,6 +327,9 @@ class UintWrapperType final : public WrapperType {
313327
<< base_internal::kInlineVariantShift);
314328

315329
constexpr UintWrapperType() : WrapperType(kMetadata) {}
330+
331+
// See Type::aliases().
332+
absl::Span<const absl::string_view> aliases() const;
316333
};
317334

318335
extern template class Handle<WrapperType>;

0 commit comments

Comments
 (0)