• 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_ARRAY_INSTANCE_EXPRESSION_H
17 #define ES2PANDA_IR_ETS_NEW_ARRAY_INSTANCE_EXPRESSION_H
18 
19 #include "ir/expression.h"
20 
21 namespace ark::es2panda::checker {
22 class ETSAnalyzer;
23 class Signature;
24 }  // namespace ark::es2panda::checker
25 
26 namespace ark::es2panda::compiler {
27 class ETSCompiler;
28 }  // namespace ark::es2panda::compiler
29 
30 namespace ark::es2panda::ir {
31 
32 class ETSNewArrayInstanceExpression : public Expression {
33 public:
34     ETSNewArrayInstanceExpression() = delete;
35     ~ETSNewArrayInstanceExpression() override = default;
36 
37     NO_COPY_SEMANTIC(ETSNewArrayInstanceExpression);
38     NO_MOVE_SEMANTIC(ETSNewArrayInstanceExpression);
39 
ETSNewArrayInstanceExpression(ir::TypeNode * const typeReference,ir::Expression * const dimension)40     explicit ETSNewArrayInstanceExpression(ir::TypeNode *const typeReference, ir::Expression *const dimension)
41         : Expression(AstNodeType::ETS_NEW_ARRAY_INSTANCE_EXPRESSION),
42           typeReference_(typeReference),
43           dimension_(dimension)
44     {
45     }
46 
TypeReference()47     [[nodiscard]] ir::TypeNode *TypeReference() noexcept
48     {
49         return typeReference_;
50     }
51 
TypeReference()52     [[nodiscard]] ir::TypeNode const *TypeReference() const noexcept
53     {
54         return typeReference_;
55     }
56 
Dimension()57     [[nodiscard]] ir::Expression *Dimension() noexcept
58     {
59         return dimension_;
60     }
61 
Dimension()62     [[nodiscard]] ir::Expression const *Dimension() const noexcept
63     {
64         return dimension_;
65     }
66 
Signature()67     [[nodiscard]] checker::Signature *Signature() const noexcept
68     {
69         return defaultConstructorSignature_;
70     }
71 
Signature()72     [[nodiscard]] checker::Signature *Signature() noexcept
73     {
74         return defaultConstructorSignature_;
75     }
76 
SetDimension(ir::Expression * dimension)77     void SetDimension(ir::Expression *dimension) noexcept
78     {
79         dimension_ = dimension;
80         if (dimension_ != nullptr) {
81             dimension_->SetParent(this);
82         }
83     }
84 
SetSignature(checker::Signature * signature)85     void SetSignature(checker::Signature *signature) noexcept
86     {
87         defaultConstructorSignature_ = signature;
88     }
89 
90     [[nodiscard]] ETSNewArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override;
91 
92     void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override;
93     void Iterate(const NodeTraverser &cb) const override;
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::TypeNode *typeReference_;
108     ir::Expression *dimension_;
109     checker::Signature *defaultConstructorSignature_ {};
110 };
111 }  // namespace ark::es2panda::ir
112 
113 #endif
114