• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021 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_SCOPES_VARIABLE_FLAGS_H
17 #define ES2PANDA_COMPILER_SCOPES_VARIABLE_FLAGS_H
18 
19 #include <cstdlib>
20 #include <util/enumbitops.h>
21 
22 namespace panda::es2panda::binder {
23 
24 #define DECLARATION_KINDS(_)             \
25     _(VAR, VarDecl)                      \
26     _(LET, LetDecl)                      \
27     _(CONST, ConstDecl)                  \
28     _(CLASS, ClassDecl)                  \
29     _(FUNC, FunctionDecl)                \
30     _(PARAM, ParameterDecl)              \
31     /* TS */                             \
32     _(TYPE_ALIAS, TypeAliasDecl)         \
33     _(NAMESPACE, NamespaceDecl)          \
34     _(INTERFACE, InterfaceDecl)          \
35     _(ENUM_LITERAL, EnumLiteralDecl)     \
36     _(TYPE_PARAMETER, TypeParameterDecl) \
37     _(PROPERTY, PropertyDecl)            \
38     _(METHOD, MethodDecl)                \
39     _(ENUM, EnumDecl)                    \
40     _(IMPORT_EQUALS, ImportEqualsDecl)
41 
42 enum class DeclType {
43     NONE,
44 #define DECLARE_TYPES(decl_kind, class_name) decl_kind,
45     DECLARATION_KINDS(DECLARE_TYPES)
46 #undef DECLARE_TYPES
47 };
48 
49 #define SCOPE_TYPES(_)                    \
50     _(PARAM, ParamScope)                  \
51     _(CATCH_PARAM, CatchParamScope)       \
52     _(FUNCTION_PARAM, FunctionParamScope) \
53     _(CATCH, CatchScope)                  \
54     _(LOCAL, LocalScope)                  \
55     /* Variable Scopes */                 \
56     _(LOOP, LoopScope)                    \
57     _(FUNCTION, FunctionScope)            \
58     _(GLOBAL, GlobalScope)                \
59     _(MODULE, ModuleScope)                \
60     _(TSMODULE, TSModuleScope)            \
61     _(TSENUM, TSEnumScope)
62 
63 
64 enum class ScopeType {
65 #define GEN_SCOPE_TYPES(type, class_name) type,
66     SCOPE_TYPES(GEN_SCOPE_TYPES)
67 #undef GEN_SCOPE_TYPES
68 };
69 
70 enum class ResolveBindingOptions {
71     BINDINGS = 1U << 0U,
72     INTERFACES = 1U << 1U,
73 
74     ALL = BINDINGS | INTERFACES,
75 };
76 
77 DEFINE_BITOPS(ResolveBindingOptions)
78 
79 enum class ResolveBindingFlags {
80     ALL = 1U << 0U,
81     TS_BEFORE_TRANSFORM = 1U << 1U,
82 };
83 
84 DEFINE_BITOPS(ResolveBindingFlags)
85 
86 #define VARIABLE_TYPES(_)                  \
87     _(LOCAL, LocalVariable)                \
88     _(GLOBAL, GlobalVariable)              \
89     _(MODULE, ModuleVariable)              \
90     _(ENUM, EnumVariable)                  \
91     _(NAMESPACE, NamespaceVariable)        \
92     _(IMPORT_EQUALS, ImportEqualsVariable) \
93     _(ENUMLITERAL, EnumLiteralVariable)
94 
95 enum class VariableType {
96 #define GEN_VARIABLE_TYPES(type, class_name) type,
97     VARIABLE_TYPES(GEN_VARIABLE_TYPES)
98 #undef GEN_VARIABLE_TYPES
99 };
100 
101 enum class VariableKind {
102     NONE,
103     VAR,
104     LEXICAL,
105     FUNCTION,
106     MODULE,
107 };
108 
109 enum class VariableFlags {
110     NONE = 0,
111     OPTIONAL = 1 << 0,
112     PROPERTY = 1 << 1,
113     METHOD = 1 << 2,
114     TYPE_ALIAS = 1 << 3,
115     INTERFACE = 1 << 4,
116     ENUM_LITERAL = 1 << 5,
117     READONLY = 1 << 6,
118     COMPUTED = 1 << 7,
119     COMPUTED_IDENT = 1 << 8,
120     COMPUTED_INDEX = 1 << 9,
121     INDEX_NAME = 1 << 10,
122     IMPORT = 1 << 11,
123     LOCAL_EXPORT = 1 << 12,
124     INFERED_IN_PATTERN = 1 << 13,
125     REST_ARG = 1 << 14,
126     NUMERIC_NAME = 1 << 15,
127     TYPE = 1 << 16,
128     NAMESPACE = 1 << 17,
129     IMPORT_EQUALS = 1 << 18,
130 
131     INDEX_LIKE = COMPUTED_INDEX | INDEX_NAME,
132 
133     LOOP_DECL = 1 << 25,
134     PER_ITERATION = 1 << 26,
135     HOIST = 1 << 27,
136     VAR = 1 << 28,
137     INITIALIZED = 1 << 29,
138     LEXICAL_BOUND = 1 << 30,
139 
140     HOIST_VAR = HOIST | VAR,
141 };
142 
143 DEFINE_BITOPS(VariableFlags)
144 
145 enum class LetOrConstStatus {
146     INITIALIZED,
147     UNINITIALIZED,
148 };
149 
150 enum class VariableScopeFlags {
151     NONE = 0,
152     SET_LEXICAL_FUNCTION = 1U << 0U,
153     USE_ARGS = 1U << 2U,
154     USE_SUPER = 1U << 3U,
155     INNER_ARROW = 1U << 4U,
156 };
157 
158 DEFINE_BITOPS(VariableScopeFlags)
159 
160 enum class DeclarationFlags {
161     NONE = 0,
162     IMPORT = 1 << 0,
163     EXPORT = 1 << 1,
164     NAMESPACE_IMPORT = 1 << 2,
165     EXPORT_IN_TSMODULE = 1 << 3,
166 };
167 
168 DEFINE_BITOPS(DeclarationFlags)
169 
170 enum class TSBindingType : size_t {
171     NAMESPACE = 0,
172     ENUMLITERAL,
173     INTERFACE,
174     IMPORT_EQUALS,
175     COUNT,
176 };
177 
178 }  // namespace panda::es2panda::binder
179 
180 #endif
181