-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathtype.h
More file actions
121 lines (97 loc) · 4.26 KB
/
Copy pathtype.h
File metadata and controls
121 lines (97 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2022 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 "base/type.h"
#ifndef THIRD_PARTY_CEL_CPP_BASE_INTERNAL_TYPE_H_
#define THIRD_PARTY_CEL_CPP_BASE_INTERNAL_TYPE_H_
#include <cstdint>
#include "base/internal/data.h"
#include "base/kind.h"
#include "internal/rtti.h"
namespace cel {
class Value;
class EnumType;
class StructType;
namespace base_internal {
class TypeHandle;
class ListTypeImpl;
class MapTypeImpl;
class LegacyStructType;
class AbstractStructType;
class LegacyStructValue;
class AbstractStructValue;
class LegacyListType;
class ModernListType;
class LegacyMapType;
class ModernMapType;
struct FieldIdFactory;
template <Kind K>
class SimpleType;
template <typename T, typename U>
class SimpleValue;
internal::TypeInfo GetEnumTypeTypeId(const EnumType& enum_type);
internal::TypeInfo GetStructTypeTypeId(const StructType& struct_type);
struct InlineType final {
uintptr_t vptr;
union {
uintptr_t legacy;
};
};
inline constexpr size_t kTypeInlineSize = sizeof(InlineType);
inline constexpr size_t kTypeInlineAlign = alignof(InlineType);
static_assert(kTypeInlineSize <= 16,
"Size of an inline type should be less than 16 bytes.");
static_assert(kTypeInlineAlign <= alignof(std::max_align_t),
"Alignment of an inline type should not be overaligned.");
using AnyType = AnyData<kTypeInlineSize, kTypeInlineAlign>;
// Metaprogramming utility for interacting with Type.
//
// TypeTraits<T>::type is an alias for T.
// TypeTraits<T>::value_type is the corresponding Value for T.
template <typename T>
struct TypeTraits;
} // namespace base_internal
} // namespace cel
#define CEL_INTERNAL_TYPE_DECL(name) extern template class Handle<name>
#define CEL_INTERNAL_TYPE_IMPL(name) template class Handle<name>
#define CEL_INTERNAL_DECLARE_TYPE(base, derived) \
public: \
static bool Is(const ::cel::Type& type); \
\
using ::cel::base##Type::Is; \
\
static const derived& Cast(const cel::Type& type) { \
ABSL_ASSERT(Is(type)); \
return static_cast<const derived&>(type); \
} \
\
private: \
friend class ::cel::base_internal::TypeHandle; \
\
::cel::internal::TypeInfo TypeId() const override;
#define CEL_INTERNAL_IMPLEMENT_TYPE(base, derived) \
static_assert(::std::is_base_of_v<::cel::base##Type, derived>, \
#derived " must inherit from cel::" #base "Type"); \
static_assert(!::std::is_abstract_v<derived>, "this must not be abstract"); \
\
bool derived::Is(const ::cel::Type& type) { \
return type.kind() == ::cel::Kind::k##base && \
::cel::base_internal::Get##base##TypeTypeId( \
static_cast<const ::cel::base##Type&>(type)) == \
::cel::internal::TypeId<derived>(); \
} \
\
::cel::internal::TypeInfo derived::TypeId() const { \
return ::cel::internal::TypeId<derived>(); \
}
#endif // THIRD_PARTY_CEL_CPP_BASE_INTERNAL_TYPE_H_