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_MULTI_DIM_ARRAY_INSTANCE_EXPRESSION_H 17#define ES2PANDA_IR_ETS_NEW_MULTI_DIM_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 ETSNewMultiDimArrayInstanceExpression : public Expression { 33public: 34 ETSNewMultiDimArrayInstanceExpression() = delete; 35 ~ETSNewMultiDimArrayInstanceExpression() override = default; 36 37 NO_COPY_SEMANTIC(ETSNewMultiDimArrayInstanceExpression); 38 NO_MOVE_SEMANTIC(ETSNewMultiDimArrayInstanceExpression); 39 40 explicit ETSNewMultiDimArrayInstanceExpression(ir::TypeNode *const typeReference, 41 ArenaVector<ir::Expression *> &&dimensions) 42 : Expression(AstNodeType::ETS_NEW_MULTI_DIM_ARRAY_INSTANCE_EXPRESSION), 43 typeReference_(typeReference), 44 dimensions_(std::move(dimensions)) 45 { 46 } 47 48 explicit ETSNewMultiDimArrayInstanceExpression(ETSNewMultiDimArrayInstanceExpression const &other, 49 ArenaAllocator *allocator); 50 51 [[nodiscard]] ir::TypeNode *TypeReference() noexcept 52 { 53 return typeReference_; 54 } 55 56 [[nodiscard]] ir::TypeNode const *TypeReference() const noexcept 57 { 58 return typeReference_; 59 } 60 61 [[nodiscard]] ArenaVector<ir::Expression *> &Dimensions() noexcept 62 { 63 return dimensions_; 64 } 65 66 [[nodiscard]] ArenaVector<ir::Expression *> const &Dimensions() const noexcept 67 { 68 return dimensions_; 69 } 70 71 [[nodiscard]] checker::Signature *Signature() noexcept 72 { 73 return signature_; 74 } 75 76 [[nodiscard]] const checker::Signature *Signature() const noexcept 77 { 78 return signature_; 79 } 80 81 void SetSignature(checker::Signature *signature) noexcept 82 { 83 signature_ = signature; 84 } 85 86 [[nodiscard]] ETSNewMultiDimArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; 87 88 void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; 89 void Iterate(const NodeTraverser &cb) const override; 90 91 void Dump(ir::AstDumper *dumper) const override; 92 void Dump(ir::SrcDumper *dumper) const override; 93 void Compile(compiler::PandaGen *pg) const override; 94 void Compile(compiler::ETSGen *etsg) const override; 95 checker::Type *Check(checker::TSChecker *checker) override; 96 checker::Type *Check(checker::ETSChecker *checker) override; 97 98 void Accept(ASTVisitorT *v) override 99 { 100 v->Accept(this); 101 } 102 103private: 104 ir::TypeNode *typeReference_; 105 ArenaVector<ir::Expression *> dimensions_; 106 checker::Signature *signature_ {}; 107}; 108} // namespace ark::es2panda::ir 109 110#endif 111