• 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_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 ark::es2panda::checker {
23 class ETSAnalyzer;
24 class Signature;
25 }  // namespace ark::es2panda::checker
26 
27 namespace ark::es2panda::compiler {
28 class ETSCompiler;
29 }  // namespace ark::es2panda::compiler
30 
31 namespace ark::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)43     explicit ETSNewClassInstanceExpression(ir::Expression *const typeReference,
44                                            ArenaVector<ir::Expression *> &&arguments)
45         : Expression(AstNodeType::ETS_NEW_CLASS_INSTANCE_EXPRESSION),
46           typeReference_(typeReference),
47           arguments_(std::move(arguments))
48     {
49     }
50     // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields
51     friend class checker::ETSAnalyzer;
52     friend class compiler::ETSCompiler;
53 
54     explicit ETSNewClassInstanceExpression(ETSNewClassInstanceExpression const &other, ArenaAllocator *allocator);
55 
GetTypeRef()56     [[nodiscard]] ir::Expression *GetTypeRef() const noexcept
57     {
58         return typeReference_;
59     }
60 
GetArguments()61     [[nodiscard]] ArenaVector<ir::Expression *> &GetArguments() noexcept
62     {
63         return arguments_;
64     }
65 
GetArguments()66     [[nodiscard]] const ArenaVector<ir::Expression *> &GetArguments() const noexcept
67     {
68         return arguments_;
69     }
70 
SetArguments(ArenaVector<ir::Expression * > && arguments)71     void SetArguments(ArenaVector<ir::Expression *> &&arguments)
72     {
73         arguments_ = std::move(arguments);
74     }
75 
GetSignature()76     [[nodiscard]] checker::Signature *GetSignature() const noexcept
77     {
78         return signature_;
79     }
80 
SetSignature(checker::Signature * const signature)81     void SetSignature(checker::Signature *const signature) noexcept
82     {
83         signature_ = signature;
84     }
85 
AddToArgumentsFront(ir::Expression * expr)86     void AddToArgumentsFront(ir::Expression *expr)
87     {
88         arguments_.insert(arguments_.begin(), expr);
89     }
90 
91     [[nodiscard]] ETSNewClassInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override;
92 
93     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
94     void Iterate(const NodeTraverser &cb) const override;
95 
96     void Dump(ir::AstDumper *dumper) const override;
97     void Dump(ir::SrcDumper *dumper) const override;
98     void Compile(compiler::PandaGen *pg) const override;
99     void Compile(compiler::ETSGen *etsg) const override;
100     checker::Type *Check(checker::TSChecker *checker) override;
101     checker::VerifiedType Check(checker::ETSChecker *checker) override;
102     static bool TypeIsAllowedForInstantiation(checker::Type *type);
103 
Accept(ASTVisitorT * v)104     void Accept(ASTVisitorT *v) override
105     {
106         v->Accept(this);
107     }
108 
CleanUp()109     void CleanUp() override
110     {
111         AstNode::CleanUp();
112         signature_ = nullptr;
113     }
114 
115 private:
116     ir::Expression *typeReference_;
117     ArenaVector<ir::Expression *> arguments_;
118     checker::Signature *signature_ {};
119 };
120 }  // namespace ark::es2panda::ir
121 
122 #endif
123