• 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_ETS_NEW_CLASS_INSTANCE_EXPRESSION_H
17 #define ES2PANDA_IR_ETS_NEW_CLASS_INSTANCE_EXPRESSION_H
18 
19 #include "compiler/core/vReg.h"
20 #include "ir/expression.h"
21 
22 namespace panda::es2panda::checker {
23 class ETSAnalyzer;
24 class Signature;
25 }  // namespace panda::es2panda::checker
26 
27 namespace panda::es2panda::compiler {
28 class ETSCompiler;
29 }  // namespace panda::es2panda::compiler
30 
31 namespace panda::es2panda::ir {
32 
33 class ClassDefinition;
34 
35 class ETSNewClassInstanceExpression : public Expression {
36 public:
37     ETSNewClassInstanceExpression() = delete;
38     ~ETSNewClassInstanceExpression() override = default;
39 
40     NO_COPY_SEMANTIC(ETSNewClassInstanceExpression);
41     NO_MOVE_SEMANTIC(ETSNewClassInstanceExpression);
42 
ETSNewClassInstanceExpression(ir::Expression * const typeReference,ArenaVector<ir::Expression * > && arguments,ir::ClassDefinition * const classDefinition)43     explicit ETSNewClassInstanceExpression(ir::Expression *const typeReference,
44                                            ArenaVector<ir::Expression *> &&arguments,
45                                            ir::ClassDefinition *const classDefinition)
46         : Expression(AstNodeType::ETS_NEW_CLASS_INSTANCE_EXPRESSION),
47           typeReference_(typeReference),
48           arguments_(std::move(arguments)),
49           classDef_(classDefinition)
50     {
51     }
52     // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields
53     friend class checker::ETSAnalyzer;
54     friend class compiler::ETSCompiler;
55 
56     explicit ETSNewClassInstanceExpression(ETSNewClassInstanceExpression const &other, ArenaAllocator *allocator);
57 
ClassDefinition()58     [[nodiscard]] ir::ClassDefinition *ClassDefinition() noexcept
59     {
60         return classDef_;
61     }
62 
ClassDefinition()63     [[nodiscard]] const ir::ClassDefinition *ClassDefinition() const noexcept
64     {
65         return classDef_;
66     }
67 
GetTypeRef()68     [[nodiscard]] ir::Expression *GetTypeRef() const noexcept
69     {
70         return typeReference_;
71     }
72 
GetArguments()73     [[nodiscard]] const ArenaVector<ir::Expression *> &GetArguments() const noexcept
74     {
75         return arguments_;
76     }
77 
GetSignature()78     [[nodiscard]] checker::Signature *GetSignature() const noexcept
79     {
80         return signature_;
81     }
82 
SetSignature(checker::Signature * const signature)83     void SetSignature(checker::Signature *const signature) noexcept
84     {
85         signature_ = signature;
86     }
87 
88     // NOLINTNEXTLINE(google-default-arguments)
89     [[nodiscard]] ETSNewClassInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override;
90 
91     void TransformChildren(const NodeTransformer &cb) override;
92     void Iterate(const NodeTraverser &cb) const override;
93 
94     void Dump(ir::AstDumper *dumper) const override;
95     void Dump(ir::SrcDumper *dumper) const override;
96     void Compile(compiler::PandaGen *pg) const override;
97     void Compile(compiler::ETSGen *etsg) const override;
98     checker::Type *Check(checker::TSChecker *checker) override;
99     checker::Type *Check(checker::ETSChecker *checker) override;
100 
Accept(ASTVisitorT * v)101     void Accept(ASTVisitorT *v) override
102     {
103         v->Accept(this);
104     }
105 
106 private:
107     ir::Expression *typeReference_;
108     ArenaVector<ir::Expression *> arguments_;
109     ir::ClassDefinition *classDef_;
110     checker::Signature *signature_ {};
111 };
112 }  // namespace panda::es2panda::ir
113 
114 #endif
115