1 /** 2 * Copyright (c) 2021-2023 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 21 namespace panda::es2panda::checker { 22 class ETSAnalyzer; 23 class Signature; 24 } // namespace panda::es2panda::checker 25 26 namespace panda::es2panda::compiler { 27 class ETSCompiler; 28 } // namespace panda::es2panda::compiler 29 30 namespace panda::es2panda::ir { 31 32 class ETSNewMultiDimArrayInstanceExpression : public Expression { 33 public: 34 ETSNewMultiDimArrayInstanceExpression() = delete; 35 ~ETSNewMultiDimArrayInstanceExpression() override = default; 36 37 NO_COPY_SEMANTIC(ETSNewMultiDimArrayInstanceExpression); 38 NO_MOVE_SEMANTIC(ETSNewMultiDimArrayInstanceExpression); 39 ETSNewMultiDimArrayInstanceExpression(ir::TypeNode * const typeReference,ArenaVector<ir::Expression * > && dimensions)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 // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields 48 friend class checker::ETSAnalyzer; 49 friend class compiler::ETSCompiler; 50 51 explicit ETSNewMultiDimArrayInstanceExpression(ETSNewMultiDimArrayInstanceExpression const &other, 52 ArenaAllocator *allocator); 53 TypeReference()54 ir::TypeNode *TypeReference() 55 { 56 return typeReference_; 57 } 58 TypeReference()59 ir::TypeNode const *TypeReference() const 60 { 61 return typeReference_; 62 } 63 Dimensions()64 ArenaVector<ir::Expression *> &Dimensions() 65 { 66 return dimensions_; 67 } 68 Dimension()69 ArenaVector<ir::Expression *> const &Dimension() const 70 { 71 return dimensions_; 72 } 73 Signature()74 [[nodiscard]] checker::Signature *Signature() noexcept 75 { 76 return signature_; 77 } 78 Signature()79 [[nodiscard]] const checker::Signature *Signature() const noexcept 80 { 81 return signature_; 82 } 83 84 // NOLINTNEXTLINE(google-default-arguments) 85 [[nodiscard]] ETSNewMultiDimArrayInstanceExpression *Clone(ArenaAllocator *allocator, 86 AstNode *parent = nullptr) override; 87 88 void TransformChildren(const NodeTransformer &cb) 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 Accept(ASTVisitorT * v)98 void Accept(ASTVisitorT *v) override 99 { 100 v->Accept(this); 101 } 102 103 private: 104 ir::TypeNode *typeReference_; 105 ArenaVector<ir::Expression *> dimensions_; 106 checker::Signature *signature_ {}; 107 }; 108 } // namespace panda::es2panda::ir 109 110 #endif 111