• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_EXPRESSION_ARROW_FUNCTION_EXPRESSION_H
17 #define ES2PANDA_IR_EXPRESSION_ARROW_FUNCTION_EXPRESSION_H
18 
19 #include "ir/expression.h"
20 
21 namespace ark::es2panda::compiler {
22 class ETSCompiler;
23 }  // namespace ark::es2panda::compiler
24 
25 namespace ark::es2panda::ir {
26 class ScriptFunction;
27 
28 class ArrowFunctionExpression : public Expression {
29 public:
30     ArrowFunctionExpression() = delete;
31     ~ArrowFunctionExpression() override = default;
32 
33     NO_COPY_SEMANTIC(ArrowFunctionExpression);
34     NO_MOVE_SEMANTIC(ArrowFunctionExpression);
35 
ArrowFunctionExpression(ScriptFunction * const func)36     explicit ArrowFunctionExpression(ScriptFunction *const func)
37         : Expression(AstNodeType::ARROW_FUNCTION_EXPRESSION), func_(func)
38     {
39     }
40 
41     explicit ArrowFunctionExpression(ArrowFunctionExpression const &other, ArenaAllocator *allocator);
42 
Function()43     [[nodiscard]] const ScriptFunction *Function() const noexcept
44     {
45         return func_;
46     }
47 
Function()48     [[nodiscard]] ScriptFunction *Function() noexcept
49     {
50         return func_;
51     }
52 
53     [[nodiscard]] ArrowFunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override;
54 
55     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
56     void Iterate(const NodeTraverser &cb) const override;
57     void Dump(ir::AstDumper *dumper) const override;
58     void Dump(ir::SrcDumper *dumper) const override;
59     void Compile(compiler::PandaGen *pg) const override;
60     void Compile(compiler::ETSGen *etsg) const override;
61     checker::Type *Check(checker::TSChecker *checker) override;
62     checker::Type *Check(checker::ETSChecker *checker) override;
63     ir::TypeNode *CreateTypeAnnotation(checker::ETSChecker *checker);
64     ir::TypeNode *CreateReturnNodeFromType(checker::ETSChecker *checker, checker::Type *returnType);
65     void AddChildLambda(ArrowFunctionExpression *childLambda);
66     bool IsVarFromSubscope(const varbinder::Variable *var) const;
67 
Accept(ASTVisitorT * v)68     void Accept(ASTVisitorT *v) override
69     {
70         v->Accept(this);
71     }
72 
73 private:
74     ScriptFunction *func_;
75 };
76 }  // namespace ark::es2panda::ir
77 
78 #endif
79