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_ARRAY_INSTANCE_EXPRESSION_H 17 #define ES2PANDA_IR_ETS_NEW_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 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(ArenaAllocator * allocator,ir::TypeNode * const typeReference,ir::Expression * const dimension)40 explicit ETSNewArrayInstanceExpression(ArenaAllocator *allocator, ir::TypeNode *const typeReference, 41 ir::Expression *const dimension) 42 : Expression(AstNodeType::ETS_NEW_ARRAY_INSTANCE_EXPRESSION), 43 typeReference_(typeReference), 44 dimension_(dimension), 45 allocator_(allocator) 46 { 47 } 48 // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields 49 friend class checker::ETSAnalyzer; 50 friend class compiler::ETSCompiler; 51 TypeReference()52 ir::TypeNode *TypeReference() 53 { 54 return typeReference_; 55 } 56 TypeReference()57 ir::TypeNode const *TypeReference() const 58 { 59 return typeReference_; 60 } 61 Dimension()62 ir::Expression *Dimension() 63 { 64 return dimension_; 65 } 66 Dimension()67 ir::Expression const *Dimension() const 68 { 69 return dimension_; 70 } 71 SetDimension(ir::Expression * dimension)72 void SetDimension(ir::Expression *dimension) 73 { 74 dimension_ = dimension; 75 } 76 77 // NOLINTNEXTLINE(google-default-arguments) 78 [[nodiscard]] ETSNewArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; 79 80 void TransformChildren(const NodeTransformer &cb) override; 81 void Iterate(const NodeTraverser &cb) const override; 82 void Dump(ir::AstDumper *dumper) const override; 83 void Dump(ir::SrcDumper *dumper) const override; 84 void Compile(compiler::PandaGen *pg) const override; 85 void Compile(compiler::ETSGen *etsg) const override; 86 checker::Type *Check(checker::TSChecker *checker) override; 87 checker::Type *Check(checker::ETSChecker *checker) override; 88 Accept(ASTVisitorT * v)89 void Accept(ASTVisitorT *v) override 90 { 91 v->Accept(this); 92 } 93 94 private: 95 ir::TypeNode *typeReference_; 96 ir::Expression *dimension_; 97 checker::Signature *defaultConstructorSignature_ {}; 98 ArenaAllocator *allocator_; 99 }; 100 } // namespace panda::es2panda::ir 101 102 #endif 103