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#ifndef ES2PANDA_IR_STATEMENT_FUNCTION_DECLARATION_H
17#define ES2PANDA_IR_STATEMENT_FUNCTION_DECLARATION_H
18
19#include "ir/statement.h"
20
21namespace ark::es2panda::ir {
22class ScriptFunction;
23
24class FunctionDeclaration : public Statement {
25public:
26    explicit FunctionDeclaration(ArenaAllocator *allocator, ScriptFunction *func, bool isAnonymous = false)
27        : Statement(AstNodeType::FUNCTION_DECLARATION),
28          decorators_(allocator->Adapter()),
29          func_(func),
30          isAnonymous_(isAnonymous)
31    {
32    }
33
34    ScriptFunction *Function()
35    {
36        return func_;
37    }
38
39    bool IsAnonymous() const
40    {
41        return isAnonymous_;
42    }
43
44    const ScriptFunction *Function() const
45    {
46        return func_;
47    }
48
49    void AddDecorators([[maybe_unused]] ArenaVector<ir::Decorator *> &&decorators) override
50    {
51        decorators_ = std::move(decorators);
52    }
53
54    bool CanHaveDecorator([[maybe_unused]] bool inTs) const override
55    {
56        return !inTs;
57    }
58
59    void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
60    void Iterate(const NodeTraverser &cb) const override;
61    void Dump(ir::AstDumper *dumper) const override;
62    void Dump(ir::SrcDumper *dumper) const override;
63    void Compile(compiler::PandaGen *pg) const override;
64    void Compile(compiler::ETSGen *etsg) const override;
65    checker::Type *Check(checker::TSChecker *checker) override;
66    checker::Type *Check(checker::ETSChecker *checker) override;
67
68    void Accept(ASTVisitorT *v) override
69    {
70        v->Accept(this);
71    }
72
73private:
74    ArenaVector<Decorator *> decorators_;
75    ScriptFunction *func_;
76    const bool isAnonymous_;
77};
78}  // namespace ark::es2panda::ir
79
80#endif
81