1 /*
2 * Copyright (c) 2024-2025 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 ES2PANDA_COMPILER_CHECKER_TYPES_ETS_OBJECT_TYPE_CONSTANTS_H
17 #define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_OBJECT_TYPE_CONSTANTS_H
18
19 #include "checker/types/type.h"
20
21 namespace ark::es2panda::checker {
22
23 using ENUMBITOPS_OPERATORS;
24
25 enum class ETSObjectFlags : std::uint64_t {
26 NO_OPTS = 0U,
27 CLASS = 1U << 0U,
28 INTERFACE = 1U << 1U,
29 INSTANCE = 1U << 2U,
30 ABSTRACT = 1U << 3U,
31 GLOBAL = 1U << 4U,
32 ENUM = 1U << 5U,
33 FUNCTIONAL = 1U << 6U,
34 RESOLVED_INTERFACES = 1U << 7U,
35 RESOLVED_SUPER = 1U << 8U,
36 RESOLVED_TYPE_PARAMS = 1U << 9U,
37 CHECKED_COMPATIBLE_ABSTRACTS = 1U << 10U,
38 STRING = 1U << 11U,
39 INCOMPLETE_INSTANTIATION = 1U << 12U,
40 INNER = 1U << 13U,
41 DYNAMIC = 1U << 14U,
42 ASYNC_FUNC_RETURN_TYPE = 1U << 15U,
43 CHECKED_INVOKE_LEGITIMACY = 1U << 16U,
44 REQUIRED = 1U << 17U,
45 READONLY = 1U << 18U,
46
47 BUILTIN_BIGINT = 1U << 22U,
48 BUILTIN_STRING = 1U << 23U,
49 BUILTIN_BOOLEAN = 1U << 24U,
50 BUILTIN_BYTE = 1U << 25U,
51 BUILTIN_CHAR = 1U << 26U,
52 BUILTIN_SHORT = 1U << 27U,
53 BUILTIN_INT = 1U << 28U,
54 BUILTIN_LONG = 1U << 29U,
55 BUILTIN_FLOAT = 1U << 30U,
56 BUILTIN_DOUBLE = 1U << 31U,
57 BUILTIN_ARRAY = 1ULL << 32U,
58
59 ENUM_OBJECT = 1ULL << 33U,
60 EXTENSION_FUNCTION = 1ULL << 34U,
61
62 FUNCTIONAL_REFERENCE = 1ULL << 35U,
63
64 BUILTIN_NUMERIC = BUILTIN_BYTE | BUILTIN_SHORT | BUILTIN_INT | BUILTIN_LONG | BUILTIN_FLOAT | BUILTIN_DOUBLE,
65 // Complete set includes null|undefined|Object
66 VALUE_TYPED = BUILTIN_BOOLEAN | BUILTIN_CHAR | BUILTIN_NUMERIC | BUILTIN_BIGINT | STRING,
67 UNBOXABLE_TYPE = BUILTIN_BOOLEAN | BUILTIN_CHAR | BUILTIN_NUMERIC,
68 BUILTIN_TYPE = BUILTIN_STRING | BUILTIN_BIGINT | UNBOXABLE_TYPE,
69
70 GLOBAL_CLASS = CLASS | GLOBAL,
71 FUNCTIONAL_INTERFACE = INTERFACE | ABSTRACT | FUNCTIONAL,
72 RESOLVED_HEADER = RESOLVED_INTERFACES | RESOLVED_SUPER | RESOLVED_TYPE_PARAMS,
73 };
74
75 // NOTE: Do not change the order of the first 7 flags (including NO_OPTS)!
76 // Because ETSChecker::ValidateResolvedProperty relies on the order of the flags.
77 enum class PropertySearchFlags : std::uint32_t {
78 NO_OPTS = 0,
79 SEARCH_INSTANCE_METHOD = 1U << 0U,
80 SEARCH_INSTANCE_FIELD = 1U << 1U,
81 SEARCH_INSTANCE_DECL = 1U << 2U,
82 SEARCH_STATIC_METHOD = 1U << 3U,
83 SEARCH_STATIC_FIELD = 1U << 4U,
84 SEARCH_STATIC_DECL = 1U << 5U,
85
86 SEARCH_IN_BASE = 1U << 6U,
87 SEARCH_IN_INTERFACES = 1U << 7U,
88 IGNORE_ABSTRACT = 1U << 8U,
89 ALLOW_FUNCTIONAL_INTERFACE = 1U << 9U,
90 DISALLOW_SYNTHETIC_METHOD_CREATION = 1U << 10U,
91 IS_SETTER = 1U << 11U,
92 IS_GETTER = 1U << 12U,
93
94 SEARCH_INSTANCE = SEARCH_INSTANCE_FIELD | SEARCH_INSTANCE_METHOD | SEARCH_INSTANCE_DECL,
95 SEARCH_STATIC = SEARCH_STATIC_FIELD | SEARCH_STATIC_METHOD | SEARCH_STATIC_DECL,
96
97 SEARCH_METHOD = SEARCH_INSTANCE_METHOD | SEARCH_STATIC_METHOD,
98 SEARCH_FIELD = SEARCH_INSTANCE_FIELD | SEARCH_STATIC_FIELD,
99 SEARCH_DECL = SEARCH_INSTANCE_DECL | SEARCH_STATIC_DECL,
100 SEARCH_ALL = SEARCH_METHOD | SEARCH_FIELD | SEARCH_DECL,
101 };
102
103 enum class PropertyType {
104 INSTANCE_METHOD,
105 INSTANCE_FIELD,
106 INSTANCE_DECL,
107 STATIC_METHOD,
108 STATIC_FIELD,
109 STATIC_DECL,
110 COUNT,
111 };
112
113 /* Invoke method name in functional interfaces */
FunctionalInterfaceInvokeName(size_t arity,bool hasRest)114 inline std::string FunctionalInterfaceInvokeName(size_t arity, bool hasRest)
115 {
116 return (hasRest ? "invokeR" : "invoke") + std::to_string(arity);
117 }
118
119 } // namespace ark::es2panda::checker
120
121 namespace enumbitops {
122
123 template <>
124 struct IsAllowedType<ark::es2panda::checker::ETSObjectFlags> : std::true_type {
125 };
126
127 template <>
128 struct IsAllowedType<ark::es2panda::checker::PropertySearchFlags> : std::true_type {
129 };
130
131 } // namespace enumbitops
132
133 #endif /* ES2PANDA_COMPILER_CHECKER_TYPES_ETS_OBJECT_TYPE_CONSTANTS_H */
134