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 21namespace ark::es2panda::checker { 22class ETSAnalyzer; 23class Signature; 24} // namespace ark::es2panda::checker 25 26namespace ark::es2panda::compiler { 27class ETSCompiler; 28} // namespace ark::es2panda::compiler 29 30namespace ark::es2panda::ir { 31 32class ETSNewArrayInstanceExpression : public Expression { 33public: 34 ETSNewArrayInstanceExpression() = delete; 35 ~ETSNewArrayInstanceExpression() override = default; 36 37 NO_COPY_SEMANTIC(ETSNewArrayInstanceExpression); 38 NO_MOVE_SEMANTIC(ETSNewArrayInstanceExpression); 39 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 47 [[nodiscard]] ir::TypeNode *TypeReference() noexcept 48 { 49 return typeReference_; 50 } 51 52 [[nodiscard]] ir::TypeNode const *TypeReference() const noexcept 53 { 54 return typeReference_; 55 } 56 57 [[nodiscard]] ir::Expression *Dimension() noexcept 58 { 59 return dimension_; 60 } 61 62 [[nodiscard]] ir::Expression const *Dimension() const noexcept 63 { 64 return dimension_; 65 } 66 67 [[nodiscard]] checker::Signature *Signature() const noexcept 68 { 69 return defaultConstructorSignature_; 70 } 71 72 [[nodiscard]] checker::Signature *Signature() noexcept 73 { 74 return defaultConstructorSignature_; 75 } 76 77 void SetDimension(ir::Expression *dimension) noexcept 78 { 79 dimension_ = dimension; 80 if (dimension_ != nullptr) { 81 dimension_->SetParent(this); 82 } 83 } 84 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 101 void Accept(ASTVisitorT *v) override 102 { 103 v->Accept(this); 104 } 105 106private: 107 ir::TypeNode *typeReference_; 108 ir::Expression *dimension_; 109 checker::Signature *defaultConstructorSignature_ {}; 110}; 111} // namespace ark::es2panda::ir 112 113#endif 114