• 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 JSANY_TYPE_STRING = "JSAny";
35 static const char* const JSOBJECT_TYPE_STRING = "JSObject";
36 static const char* const SMI_TYPE_STRING = "Smi";
37 static const char* const TAGGED_TYPE_STRING = "Tagged";
38 static const char* const STRONG_TAGGED_TYPE_STRING = "StrongTagged";
39 static const char* const UNINITIALIZED_TYPE_STRING = "Uninitialized";
40 static const char* const UNINITIALIZED_HEAP_OBJECT_TYPE_STRING =
41     "UninitializedHeapObject";
42 static const char* const RAWPTR_TYPE_STRING = "RawPtr";
43 static const char* const EXTERNALPTR_TYPE_STRING = "ExternalPointer";
44 static const char* const CONST_STRING_TYPE_STRING = "constexpr string";
45 static const char* const STRING_TYPE_STRING = "String";
46 static const char* const NUMBER_TYPE_STRING = "Number";
47 static const char* const BUILTIN_POINTER_TYPE_STRING = "BuiltinPtr";
48 static const char* const INTPTR_TYPE_STRING = "intptr";
49 static const char* const UINTPTR_TYPE_STRING = "uintptr";
50 static const char* const INT64_TYPE_STRING = "int64";
51 static const char* const INT31_TYPE_STRING = "int31";
52 static const char* const INT32_TYPE_STRING = "int32";
53 static const char* const UINT31_TYPE_STRING = "uint31";
54 static const char* const UINT32_TYPE_STRING = "uint32";
55 static const char* const INT16_TYPE_STRING = "int16";
56 static const char* const UINT16_TYPE_STRING = "uint16";
57 static const char* const INT8_TYPE_STRING = "int8";
58 static const char* const UINT8_TYPE_STRING = "uint8";
59 static const char* const BINT_TYPE_STRING = "bint";
60 static const char* const CHAR8_TYPE_STRING = "char8";
61 static const char* const CHAR16_TYPE_STRING = "char16";
62 static const char* const FLOAT32_TYPE_STRING = "float32";
63 static const char* const FLOAT64_TYPE_STRING = "float64";
64 static const char* const FLOAT64_OR_HOLE_TYPE_STRING = "float64_or_hole";
65 static const char* const CONST_INT31_TYPE_STRING = "constexpr int31";
66 static const char* const CONST_INT32_TYPE_STRING = "constexpr int32";
67 static const char* const CONST_FLOAT64_TYPE_STRING = "constexpr float64";
68 static const char* const TORQUE_INTERNAL_NAMESPACE_STRING = "torque_internal";
69 static const char* const MUTABLE_REFERENCE_TYPE_STRING = "MutableReference";
70 static const char* const CONST_REFERENCE_TYPE_STRING = "ConstReference";
71 static const char* const SLICE_TYPE_STRING = "Slice";
72 static const char* const WEAK_TYPE_STRING = "Weak";
73 static const char* const SMI_TAGGED_TYPE_STRING = "SmiTagged";
74 static const char* const UNINITIALIZED_ITERATOR_TYPE_STRING =
75     "UninitializedIterator";
76 static const char* const GENERIC_TYPE_INSTANTIATION_NAMESPACE_STRING =
77     "_generic_type_instantiation_namespace";
78 static const char* const FIXED_ARRAY_BASE_TYPE_STRING = "FixedArrayBase";
79 static const char* const WEAK_HEAP_OBJECT = "WeakHeapObject";
80 static const char* const STATIC_ASSERT_MACRO_STRING = "StaticAssert";
81 
82 static const char* const ANNOTATION_GENERATE_PRINT = "@generatePrint";
83 static const char* const ANNOTATION_NO_VERIFIER = "@noVerifier";
84 static const char* const ANNOTATION_ABSTRACT = "@abstract";
85 static const char* const ANNOTATION_HAS_SAME_INSTANCE_TYPE_AS_PARENT =
86     "@hasSameInstanceTypeAsParent";
87 static const char* const ANNOTATION_GENERATE_CPP_CLASS = "@generateCppClass";
88 static const char* const ANNOTATION_CUSTOM_MAP = "@customMap";
89 static const char* const ANNOTATION_CUSTOM_CPP_CLASS = "@customCppClass";
90 static const char* const ANNOTATION_HIGHEST_INSTANCE_TYPE_WITHIN_PARENT =
91     "@highestInstanceTypeWithinParentClassRange";
92 static const char* const ANNOTATION_LOWEST_INSTANCE_TYPE_WITHIN_PARENT =
93     "@lowestInstanceTypeWithinParentClassRange";
94 static const char* const ANNOTATION_RESERVE_BITS_IN_INSTANCE_TYPE =
95     "@reserveBitsInInstanceType";
96 static const char* const ANNOTATION_INSTANCE_TYPE_VALUE =
97     "@apiExposedInstanceTypeValue";
98 static const char* const ANNOTATION_IF = "@if";
99 static const char* const ANNOTATION_IFNOT = "@ifnot";
100 static const char* const ANNOTATION_GENERATE_BODY_DESCRIPTOR =
101     "@generateBodyDescriptor";
102 static const char* const ANNOTATION_EXPORT = "@export";
103 static const char* const ANNOTATION_DO_NOT_GENERATE_CAST = "@doNotGenerateCast";
104 static const char* const ANNOTATION_USE_PARENT_TYPE_CHECKER =
105     "@useParentTypeChecker";
106 
IsConstexprName(const std::string & name)107 inline bool IsConstexprName(const std::string& name) {
108   return name.substr(0, std::strlen(CONSTEXPR_TYPE_PREFIX)) ==
109          CONSTEXPR_TYPE_PREFIX;
110 }
111 
GetNonConstexprName(const std::string & name)112 inline std::string GetNonConstexprName(const std::string& name) {
113   if (!IsConstexprName(name)) return name;
114   return name.substr(std::strlen(CONSTEXPR_TYPE_PREFIX));
115 }
116 
GetConstexprName(const std::string & name)117 inline std::string GetConstexprName(const std::string& name) {
118   if (IsConstexprName(name)) return name;
119   return CONSTEXPR_TYPE_PREFIX + name;
120 }
121 
122 enum class AbstractTypeFlag {
123   kNone = 0,
124   kTransient = 1 << 0,
125   kConstexpr = 1 << 1,
126   kUseParentTypeChecker = 1 << 2,
127 };
128 using AbstractTypeFlags = base::Flags<AbstractTypeFlag>;
129 
130 enum class ClassFlag {
131   kNone = 0,
132   kExtern = 1 << 0,
133   kGeneratePrint = 1 << 1,
134   kGenerateVerify = 1 << 2,
135   kTransient = 1 << 3,
136   kAbstract = 1 << 4,
137   kIsShape = 1 << 5,
138   kHasSameInstanceTypeAsParent = 1 << 6,
139   kGenerateCppClassDefinitions = 1 << 7,
140   kCustomCppClass = 1 << 8,
141   kHighestInstanceTypeWithinParent = 1 << 9,
142   kLowestInstanceTypeWithinParent = 1 << 10,
143   kUndefinedLayout = 1 << 11,
144   kGenerateBodyDescriptor = 1 << 12,
145   kExport = 1 << 13,
146   kDoNotGenerateCast = 1 << 14,
147   kCustomMap = 1 << 15,
148 };
149 using ClassFlags = base::Flags<ClassFlag>;
150 
151 enum class StructFlag { kNone = 0, kExport = 1 << 0 };
152 using StructFlags = base::Flags<StructFlag>;
153 
154 }  // namespace torque
155 }  // namespace internal
156 }  // namespace v8
157 
158 #endif  // V8_TORQUE_CONSTANTS_H_
159