• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_TS_TYPES_BUILTIN_TYPE_ID_H
17 #define ECMASCRIPT_TS_TYPES_BUILTIN_TYPE_ID_H
18 
19 #include <cstdint>
20 #include <string_view>
21 
22 #define TS_BUILTIN_TYPE_LIST(V)     \
23     V(FUNCTION)                     \
24     V(RANGE_ERROR)                  \
25     V(ERROR)                        \
26     V(OBJECT)                       \
27     V(SYNTAX_ERROR)                 \
28     V(TYPE_ERROR)                   \
29     V(REFERENCE_ERROR)              \
30     V(URI_ERROR)                    \
31     V(SYMBOL)                       \
32     V(EVAL_ERROR)                   \
33     V(NUMBER)                       \
34     V(PARSE_FLOAT)                  \
35     V(DATE)                         \
36     V(BOOLEAN)                      \
37     V(BIG_INT)                      \
38     V(PARSE_INT)                    \
39     V(WEAK_MAP)                     \
40     V(REG_EXP)                      \
41     V(SET)                          \
42     V(MAP)                          \
43     V(WEAK_REF)                     \
44     V(WEAK_SET)                     \
45     V(FINALIZATION_REGISTRY)        \
46     V(ARRAY)                        \
47     V(UINT8_CLAMPED_ARRAY)          \
48     V(UINT8_ARRAY)                  \
49     V(TYPED_ARRAY)                  \
50     V(INT8_ARRAY)                   \
51     V(UINT16_ARRAY)                 \
52     V(UINT32_ARRAY)                 \
53     V(INT16_ARRAY)                  \
54     V(INT32_ARRAY)                  \
55     V(FLOAT32_ARRAY)                \
56     V(FLOAT64_ARRAY)                \
57     V(BIGINT64_ARRAY)               \
58     V(BIGUINT64_ARRAY)              \
59     V(SHARED_ARRAY_BUFFER)          \
60     V(DATA_VIEW)                    \
61     V(STRING)                       \
62     V(ARRAY_BUFFER)                 \
63     V(EVAL)                         \
64     V(IS_FINITE)                    \
65     V(ARK_PRIVATE)                  \
66     V(PRINT)                        \
67     V(DECODE_URI)                   \
68     V(DECODE_URI_COMPONENT)         \
69     V(IS_NAN)                       \
70     V(ENCODE_URI)                   \
71     V(JS_NAN)                       \
72     V(GLOBAL_THIS)                  \
73     V(ENCODE_URI_COMPONENT)         \
74     V(JS_INFINITY)                  \
75     V(MATH)                         \
76     V(JSON)                         \
77     V(ATOMICS)                      \
78     V(UNDEFINED)                    \
79     V(REFLECT)                      \
80     V(PROMISE)                      \
81     V(PROXY)                        \
82     V(GENERATOR_FUNCTION)           \
83     V(INTL)
84 
85 namespace panda::ecmascript {
86 #define TS_BUILTIN_TYPE_ENUM_ITEM(TYPE) TYPE,
87 
88 /* Since AOT allows loading lib_ark_builtins.d.ts optionally, the localId of the GlobalTSTypeRef
89  * (abbreviated as GT) of one builtin object will be different in different cases.
90  *
91  * In case where AOT does not load lib_ark_builtins.d.ts, builtin objects will be assigned localIds
92  * according to the following enum order. For example, the GT of FUNCTION will be (1, 21), where 1
93  * is the index of builtin TSTypeTable. Note that in this case, it is prohibited to get TSType from
94  * builtin TSTypeTable.
95  *
96  * In case where AOT has loaded lib_ark_builtins.d.ts, builtin objects will be assigned localIds in
97  * the order in which they appear in bytecodes. To identify types of builtin objects, the following
98  * enum is required as a parameter to the TSManager::GetBuiltinOffset to help to get the GT of some
99  * builtin object.
100  */
101 enum class BuiltinTypeId : uint8_t {  // keep the same with enum BuiltinType in ets_frontend
102     NUM_INDEX_IN_SUMMARY = 0,
103     BUILTIN_OFFSET = 20,
104     TS_BUILTIN_TYPE_LIST(TS_BUILTIN_TYPE_ENUM_ITEM)
105     NUM_OF_BUILTIN_TYPES = INTL - BUILTIN_OFFSET,
106     TYPED_ARRAY_FIRST = UINT8_CLAMPED_ARRAY,
107     TYPED_ARRAY_LAST = BIGUINT64_ARRAY,
108 };
109 #undef TS_BUILTIN_TYPE_ENUM_ITEM
110 
ToString(BuiltinTypeId type)111 inline constexpr std::string_view ToString(BuiltinTypeId type)
112 {
113 #define TS_BUILTIN_TYPE_SWITCH_CASE(TYPE)   \
114     case BuiltinTypeId::TYPE:               \
115         return #TYPE;
116 
117     switch (type) {
118         TS_BUILTIN_TYPE_LIST(TS_BUILTIN_TYPE_SWITCH_CASE)
119         default:
120             return "(Invalid BuiltinTypeId)";
121     }
122 }
123 
IsTypedArrayType(BuiltinTypeId type)124 inline constexpr bool IsTypedArrayType(BuiltinTypeId type)
125 {
126     size_t index = static_cast<size_t>(type);
127     size_t first = static_cast<size_t>(BuiltinTypeId::TYPED_ARRAY_FIRST);
128     size_t last  = static_cast<size_t>(BuiltinTypeId::TYPED_ARRAY_LAST);
129     return first <= index && index <= last;
130 }
131 } // namespace panda::ecmascript
132 #endif // ECMASCRIPT_TS_TYPES_BUILTIN_TYPE_ID_H
133