• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-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_IR_STATEMENT_FUNCTION_DECLARATION_H
17 #define ES2PANDA_IR_STATEMENT_FUNCTION_DECLARATION_H
18 
19 #include "ir/annotationAllowed.h"
20 #include "ir/jsDocAllowed.h"
21 #include "ir/statement.h"
22 #include "ir/statements/annotationUsage.h"
23 #include "ir/base/scriptFunction.h"
24 
25 namespace ark::es2panda::ir {
26 class ScriptFunction;
27 class AnnotationUsage;
28 
29 class FunctionDeclaration : public JsDocAllowed<AnnotationAllowed<Statement>> {
30 public:
31     explicit FunctionDeclaration(ArenaAllocator *allocator, ScriptFunction *func,
32                                  ArenaVector<AnnotationUsage *> &&annotations, bool isAnonymous = false)
33         : JsDocAllowed<AnnotationAllowed<Statement>>(allocator, AstNodeType::FUNCTION_DECLARATION,
34                                                      std::move(annotations)),
35           decorators_(allocator->Adapter()),
36           func_(func),
37           isAnonymous_(isAnonymous)
38     {
39         flags_ = func->Modifiers();
40     }
41 
42     explicit FunctionDeclaration(ArenaAllocator *allocator, ScriptFunction *func, bool isAnonymous = false)
43         : JsDocAllowed<AnnotationAllowed<Statement>>(AstNodeType::FUNCTION_DECLARATION, allocator),
44           decorators_(allocator->Adapter()),
45           func_(func),
46           isAnonymous_(isAnonymous)
47     {
48         flags_ = func->Modifiers();
49     }
50 
Function()51     ScriptFunction *Function()
52     {
53         return func_;
54     }
55 
IsAnonymous()56     bool IsAnonymous() const
57     {
58         return isAnonymous_;
59     }
60 
Function()61     const ScriptFunction *Function() const
62     {
63         return func_;
64     }
65 
AddDecorators(ArenaVector<ir::Decorator * > && decorators)66     void AddDecorators([[maybe_unused]] ArenaVector<ir::Decorator *> &&decorators) override
67     {
68         decorators_ = std::move(decorators);
69     }
70 
CanHaveDecorator(bool inTs)71     bool CanHaveDecorator([[maybe_unused]] bool inTs) const override
72     {
73         return !inTs;
74     }
75 
76     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
77     void Iterate(const NodeTraverser &cb) const override;
78     void Dump(ir::AstDumper *dumper) const override;
79     void Dump(ir::SrcDumper *dumper) const override;
80     void Compile(compiler::PandaGen *pg) const override;
81     void Compile(compiler::ETSGen *etsg) const override;
82     checker::Type *Check(checker::TSChecker *checker) override;
83     checker::VerifiedType Check(checker::ETSChecker *checker) override;
84 
Accept(ASTVisitorT * v)85     void Accept(ASTVisitorT *v) override
86     {
87         v->Accept(this);
88     }
89 
90     FunctionDeclaration *Construct(ArenaAllocator *allocator) override;
91     void CopyTo(AstNode *other) const override;
92 
93 private:
94     friend class SizeOfNodeTest;
95     ArenaVector<Decorator *> decorators_;
96     ScriptFunction *func_;
97     bool isAnonymous_;
98 };
99 }  // namespace ark::es2panda::ir
100 
101 #endif
102