• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_TORQUE_CONSTANTS_H_
6 #define V8_TORQUE_CONSTANTS_H_
7 
8 #include <cstring>
9 #include <string>
10 
11 #include "src/base/flags.h"
12 
13 namespace v8 {
14 namespace internal {
15 namespace torque {
16 
17 static const char* const CONSTEXPR_TYPE_PREFIX = "constexpr ";
18 static const char* const NEVER_TYPE_STRING = "never";
19 static const char* const CONSTEXPR_BOOL_TYPE_STRING = "constexpr bool";
20 static const char* const CONSTEXPR_STRING_TYPE_STRING = "constexpr string";
21 static const char* const CONSTEXPR_INTPTR_TYPE_STRING = "constexpr intptr";
22 static const char* const CONSTEXPR_INSTANCE_TYPE_TYPE_STRING =
23     "constexpr InstanceType";
24 static const char* const BOOL_TYPE_STRING = "bool";
25 static const char* const VOID_TYPE_STRING = "void";
26 static const char* const ARGUMENTS_TYPE_STRING = "Arguments";
27 static const char* const CONTEXT_TYPE_STRING = "Context";
28 static const char* const NO_CONTEXT_TYPE_STRING = "NoContext";
29 static const char* const NATIVE_CONTEXT_TYPE_STRING = "NativeContext";
30 static const char* const JS_FUNCTION_TYPE_STRING = "JSFunction";
31 static const char* const MAP_TYPE_STRING = "Map";
32 static const char* const OBJECT_TYPE_STRING = "Object";
33 static const char* const HEAP_OBJECT_TYPE_STRING = "HeapObject";
34 static const char* const TAGGED_ZERO_PATTERN_TYPE_STRING = "TaggedZeroPattern";
35 static const char* const JSANY_TYPE_STRING = "JSAny";
36 static const char* const JSOBJECT_TYPE_STRING = "JSObject";
37 static const char* const SMI_TYPE_STRING = "Smi";
38 static const char* const TAGGED_TYPE_STRING = "Tagged";
39 static const char* const STRONG_TAGGED_TYPE_STRING = "StrongTagged";
40 static const char* const UNINITIALIZED_TYPE_STRING = "Uninitialized";
41 static const char* const UNINITIALIZED_HEAP_OBJECT_TYPE_STRING =
42     "UninitializedHeapObject";
43 static const char* const RAWPTR_TYPE_STRING = "RawPtr";
44 static const char* const EXTERNALPTR_TYPE_STRING = "ExternalPointer";
45 static const char* const CONST_STRING_TYPE_STRING = "constexpr string";
46 static const char* const STRING_TYPE_STRING = "String";
47 static const char* const NUMBER_TYPE_STRING = "Number";
48 static const char* const BUILTIN_POINTER_TYPE_STRING = "BuiltinPtr";
49 static const char* const INTPTR_TYPE_STRING = "intptr";
50 static const char* const UINTPTR_TYPE_STRING = "uintptr";
51 static const char* const INT64_TYPE_STRING = "int64";
52 static const char* const UINT64_TYPE_STRING = "uint64";
53 static const char* const INT31_TYPE_STRING = "int31";
54 static const char* const INT32_TYPE_STRING = "int32";
55 static const char* const UINT31_TYPE_STRING = "uint31";
56 static const char* const UINT32_TYPE_STRING = "uint32";
57 static const char* const INT16_TYPE_STRING = "int16";
58 static const char* const UINT16_TYPE_STRING = "uint16";
59 static const char* const INT8_TYPE_STRING = "int8";
60 static const char* const UINT8_TYPE_STRING = "uint8";
61 static const char* const BINT_TYPE_STRING = "bint";
62 static const char* const CHAR8_TYPE_STRING = "char8";
63 static const char* const CHAR16_TYPE_STRING = "char16";
64 static const char* const FLOAT32_TYPE_STRING = "float32";
65 static const char* const FLOAT64_TYPE_STRING = "float64";
66 static const char* const FLOAT64_OR_HOLE_TYPE_STRING = "float64_or_hole";
67 static const char* const CONST_INT31_TYPE_STRING = "constexpr int31";
68 static const char* const CONST_INT32_TYPE_STRING = "constexpr int32";
69 static const char* const CONST_FLOAT64_TYPE_STRING = "constexpr float64";
70 static const char* const INTEGER_LITERAL_TYPE_STRING =
71     "constexpr IntegerLiteral";
72 static const char* const TORQUE_INTERNAL_NAMESPACE_STRING = "torque_internal";
73 static const char* const MUTABLE_REFERENCE_TYPE_STRING = "MutableReference";
74 static const char* const CONST_REFERENCE_TYPE_STRING = "ConstReference";
75 static const char* const MUTABLE_SLICE_TYPE_STRING = "MutableSlice";
76 static const char* const CONST_SLICE_TYPE_STRING = "ConstSlice";
77 static const char* const WEAK_TYPE_STRING = "Weak";
78 static const char* const SMI_TAGGED_TYPE_STRING = "SmiTagged";
79 static const char* const LAZY_TYPE_STRING = "Lazy";
80 static const char* const UNINITIALIZED_ITERATOR_TYPE_STRING =
81     "UninitializedIterator";
82 static const char* const GENERIC_TYPE_INSTANTIATION_NAMESPACE_STRING =
83     "_generic_type_instantiation_namespace";
84 static const char* const FIXED_ARRAY_BASE_TYPE_STRING = "FixedArrayBase";
85 static const char* const WEAK_HEAP_OBJECT = "WeakHeapObject";
86 static const char* const STATIC_ASSERT_MACRO_STRING = "StaticAssert";
87 
88 static const char* const ANNOTATION_ABSTRACT = "@abstract";
89 static const char* const ANNOTATION_HAS_SAME_INSTANCE_TYPE_AS_PARENT =
90     "@hasSameInstanceTypeAsParent";
91 static const char* const ANNOTATION_DO_NOT_GENERATE_CPP_CLASS =
92     "@doNotGenerateCppClass";
93 static const char* const ANNOTATION_CUSTOM_MAP = "@customMap";
94 static const char* const ANNOTATION_CUSTOM_CPP_CLASS = "@customCppClass";
95 static const char* const ANNOTATION_HIGHEST_INSTANCE_TYPE_WITHIN_PARENT =
96     "@highestInstanceTypeWithinParentClassRange";
97 static const char* const ANNOTATION_LOWEST_INSTANCE_TYPE_WITHIN_PARENT =
98     "@lowestInstanceTypeWithinParentClassRange";
99 static const char* const ANNOTATION_RESERVE_BITS_IN_INSTANCE_TYPE =
100     "@reserveBitsInInstanceType";
101 static const char* const ANNOTATION_INSTANCE_TYPE_VALUE =
102     "@apiExposedInstanceTypeValue";
103 static const char* const ANNOTATION_IF = "@if";
104 static const char* const ANNOTATION_IFNOT = "@ifnot";
105 static const char* const ANNOTATION_GENERATE_BODY_DESCRIPTOR =
106     "@generateBodyDescriptor";
107 static const char* const ANNOTATION_GENERATE_UNIQUE_MAP = "@generateUniqueMap";
108 static const char* const ANNOTATION_GENERATE_FACTORY_FUNCTION =
109     "@generateFactoryFunction";
110 static const char* const ANNOTATION_EXPORT = "@export";
111 static const char* const ANNOTATION_DO_NOT_GENERATE_CAST = "@doNotGenerateCast";
112 static const char* const ANNOTATION_USE_PARENT_TYPE_CHECKER =
113     "@useParentTypeChecker";
114 static const char* const ANNOTATION_CPP_OBJECT_DEFINITION =
115     "@cppObjectDefinition";
116 // Generate C++ accessors with relaxed store semantics.
117 // Weak<T> and MaybeObject fields always use relaxed store.
118 static const char* const ANNOTATION_CPP_RELAXED_STORE = "@cppRelaxedStore";
119 // Generate C++ accessors with relaxed load semantics.
120 static const char* const ANNOTATION_CPP_RELAXED_LOAD = "@cppRelaxedLoad";
121 // Generate C++ accessors with release store semantics.
122 static const char* const ANNOTATION_CPP_RELEASE_STORE = "@cppReleaseStore";
123 // Generate C++ accessors with acquire load semantics.
124 static const char* const ANNOTATION_CPP_ACQUIRE_LOAD = "@cppAcquireLoad";
125 // Generate BodyDescriptor using IterateCustomWeakPointers.
126 static const char* const ANNOTATION_CUSTOM_WEAK_MARKING = "@customWeakMarking";
127 
IsConstexprName(const std::string & name)128 inline bool IsConstexprName(const std::string& name) {
129   return name.substr(0, std::strlen(CONSTEXPR_TYPE_PREFIX)) ==
130          CONSTEXPR_TYPE_PREFIX;
131 }
132 
GetNonConstexprName(const std::string & name)133 inline std::string GetNonConstexprName(const std::string& name) {
134   if (!IsConstexprName(name)) return name;
135   return name.substr(std::strlen(CONSTEXPR_TYPE_PREFIX));
136 }
137 
GetConstexprName(const std::string & name)138 inline std::string GetConstexprName(const std::string& name) {
139   if (IsConstexprName(name)) return name;
140   return CONSTEXPR_TYPE_PREFIX + name;
141 }
142 
143 enum class AbstractTypeFlag {
144   kNone = 0,
145   kTransient = 1 << 0,
146   kConstexpr = 1 << 1,
147   kUseParentTypeChecker = 1 << 2,
148 };
149 using AbstractTypeFlags = base::Flags<AbstractTypeFlag>;
150 
151 enum class ClassFlag {
152   kNone = 0,
153   kExtern = 1 << 0,
154   kTransient = 1 << 1,
155   kAbstract = 1 << 2,
156   kIsShape = 1 << 3,
157   kHasSameInstanceTypeAsParent = 1 << 4,
158   kGenerateCppClassDefinitions = 1 << 5,
159   kHighestInstanceTypeWithinParent = 1 << 6,
160   kLowestInstanceTypeWithinParent = 1 << 7,
161   kUndefinedLayout = 1 << 8,
162   kGenerateBodyDescriptor = 1 << 9,
163   kExport = 1 << 10,
164   kDoNotGenerateCast = 1 << 11,
165   kGenerateUniqueMap = 1 << 12,
166   kGenerateFactoryFunction = 1 << 13,
167   kCppObjectDefinition = 1 << 14,
168 };
169 using ClassFlags = base::Flags<ClassFlag>;
170 
171 enum class StructFlag { kNone = 0, kExport = 1 << 0 };
172 using StructFlags = base::Flags<StructFlag>;
173 
174 enum class FieldSynchronization {
175   kNone,
176   kRelaxed,
177   kAcquireRelease,
178 };
179 
180 }  // namespace torque
181 }  // namespace internal
182 }  // namespace v8
183 
184 #endif  // V8_TORQUE_CONSTANTS_H_
185