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_NEW_EXPRESSION_H
17 #define ES2PANDA_IR_EXPRESSION_NEW_EXPRESSION_H
18 
19 #include "ir/expression.h"
20 
21 namespace ark::es2panda::checker {
22 class TSAnalyzer;
23 }  // namespace ark::es2panda::checker
24 
25 namespace ark::es2panda::ir {
26 class NewExpression : public Expression {
27 private:
28     struct Tag {};
29 
30 public:
31     NewExpression() = delete;
32     ~NewExpression() override = default;
33 
34     NO_COPY_SEMANTIC(NewExpression);
35     NO_MOVE_SEMANTIC(NewExpression);
36 
NewExpression(Expression *const callee, ArenaVector<Expression *> &&arguments)37     explicit NewExpression(Expression *const callee, ArenaVector<Expression *> &&arguments)
38         : Expression(AstNodeType::NEW_EXPRESSION), callee_(callee), arguments_(std::move(arguments))
39     {
40     }
41     explicit NewExpression(Tag tag, NewExpression const &other, ArenaAllocator *allocator);
42 
43     // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields
44     friend class checker::TSAnalyzer;
45 
46     [[nodiscard]] const Expression *Callee() const noexcept
47     {
48         return callee_;
49     }
50 
51     [[nodiscard]] const ArenaVector<Expression *> &Arguments() const noexcept
52     {
53         return arguments_;
54     }
55 
56     [[nodiscard]] NewExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override;
57 
58     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
59     void Iterate(const NodeTraverser &cb) const override;
60     void Dump(ir::AstDumper *dumper) const override;
61     void Dump(ir::SrcDumper *dumper) const override;
62     void Compile(compiler::PandaGen *pg) const override;
63     void Compile(compiler::ETSGen *etsg) const override;
64     checker::Type *Check(checker::TSChecker *checker) override;
65     checker::Type *Check(checker::ETSChecker *checker) override;
66 
67     void Accept(ASTVisitorT *v) override
68     {
69         v->Accept(this);
70     }
71 
72 private:
73     Expression *callee_ = nullptr;
74     ArenaVector<Expression *> arguments_;
75 };
76 }  // namespace ark::es2panda::ir
77 
78 #endif
79