1 /**
2  * Copyright (c) 2021-2024 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 // original_header.h
17 #ifndef FORWARD_DECL_FOR_PARSERIMPL_H
18 #define FORWARD_DECL_FOR_PARSERIMPL_H
19 
20 #include "ir/base/scriptFunctionSignature.h"
21 #include "parser/context/parserContext.h"
22 #include "varbinder/scope.h"
23 
24 namespace ark::es2panda::lexer {
25 enum class TokenFlags : uint32_t;
26 class LexerPosition;
27 class Token;
28 class Lexer;
29 }  // namespace ark::es2panda::lexer
30 
31 namespace ark::es2panda::ir {
32 class ArrowFunctionExpression;
33 class AstNode;
34 class BlockStatement;
35 class BreakStatement;
36 class CallExpression;
37 class ClassDeclaration;
38 class ClassDefinition;
39 class ContinueStatement;
40 class DoWhileStatement;
41 class ExportAllDeclaration;
42 class ExportDefaultDeclaration;
43 class ExportNamedDeclaration;
44 class ExportNamedDeclaration;
45 class Expression;
46 class FunctionDeclaration;
47 class FunctionExpression;
48 class Identifier;
49 class IfStatement;
50 class ImportSource;
51 class ImportDeclaration;
52 class LabelledStatement;
53 class NewExpression;
54 class ObjectExpression;
55 class ReturnStatement;
56 class ScriptFunction;
57 class SequenceExpression;
58 class SpreadElement;
59 class Statement;
60 class StringLiteral;
61 class SwitchCaseStatement;
62 class SwitchStatement;
63 class TemplateLiteral;
64 class ThrowStatement;
65 class TryStatement;
66 class VariableDeclaration;
67 class WhileStatement;
68 class WithStatement;
69 class MemberExpression;
70 class MethodDefinition;
71 class Property;
72 class YieldExpression;
73 class MetaProperty;
74 class EmptyStatement;
75 class DebuggerStatement;
76 class CatchClause;
77 class VariableDeclarator;
78 class ClassElement;
79 
80 enum class PropertyKind;
81 enum class MethodDefinitionKind;
82 enum class ModifierFlags : uint32_t;
83 enum class Primitives;
84 enum class ClassDefinitionModifiers : uint32_t;
85 enum class CatchClauseType;
86 enum class VariableDeclaratorFlag;
87 }  // namespace ark::es2panda::ir
88 
89 namespace ark::es2panda::parser {
90 
91 class ETSParser;
92 
93 using FunctionSignature = std::tuple<ir::FunctionSignature, ark::es2panda::ir::ScriptFunctionFlags>;
94 
95 // NOLINTBEGIN(modernize-avoid-c-arrays)
96 inline constexpr char const ARRAY_FORMAT_NODE = '[';
97 inline constexpr char const EXPRESSION_FORMAT_NODE = 'E';
98 inline constexpr char const STATEMENT_FORMAT_NODE = 'S';
99 // NOLINTEND(modernize-avoid-c-arrays)
100 
101 class ClassElementDescriptor {
102 public:
ClassElementDescriptor(ArenaAllocator *allocator)103     explicit ClassElementDescriptor(ArenaAllocator *allocator) : decorators(allocator->Adapter()) {}
104 
105     // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
106     ArenaVector<ir::Decorator *> decorators;
107     ir::MethodDefinitionKind methodKind {};
108     ParserStatus newStatus {};
109     ir::ModifierFlags modifiers {};
110     lexer::SourcePosition methodStart {};
111     lexer::SourcePosition propStart {};
112     bool isPrivateIdent {};
113     bool hasSuperClass {};
114     bool isGenerator {};
115     bool invalidComputedProperty {};
116     bool isComputed {};
117     bool isIndexSignature {};
118     bool classMethod {};
119     bool classField {};
120     varbinder::LocalScope *staticFieldScope {};
121     varbinder::LocalScope *staticMethodScope {};
122     varbinder::LocalScope *instanceFieldScope {};
123     varbinder::LocalScope *instanceMethodScope {};
124     // NOLINTEND(misc-non-private-member-variables-in-classes)
125 };
126 
127 class ArrowFunctionDescriptor {
128 public:
ArrowFunctionDescriptor(ArenaVector<ir::Expression *> &&p, lexer::SourcePosition sl, ParserStatus ns)129     explicit ArrowFunctionDescriptor(ArenaVector<ir::Expression *> &&p, lexer::SourcePosition sl, ParserStatus ns)
130         : params(p), startLoc(sl), newStatus(ns)
131     {
132     }
133 
134     // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
135     ArenaVector<ir::Expression *> params;
136     lexer::SourcePosition startLoc;
137     ParserStatus newStatus;
138     // NOLINTEND(misc-non-private-member-variables-in-classes)
139 };
140 
141 class ArrowFunctionContext;
142 }  // namespace ark::es2panda::parser
143 #endif
144