1 /** 2 * Copyright (c) 2021 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_EXPRESSION_ARRAY_EXPRESSION_H 17 #define ES2PANDA_IR_EXPRESSION_ARRAY_EXPRESSION_H 18 19 #include <ir/expression.h> 20 #include <ir/validationInfo.h> 21 22 namespace panda::es2panda::compiler { 23 class PandaGen; 24 class LiteralBuffer; 25 } // namespace panda::es2panda::compiler 26 27 namespace panda::es2panda::checker { 28 class Checker; 29 class Type; 30 } // namespace panda::es2panda::checker 31 32 namespace panda::es2panda::ir { 33 34 class ArrayExpression : public Expression { 35 public: ArrayExpression(AstNodeType nodeType,ArenaVector<Expression * > && elements,bool trailingComma)36 explicit ArrayExpression(AstNodeType nodeType, ArenaVector<Expression *> &&elements, bool trailingComma) 37 : Expression(nodeType), elements_(std::move(elements)), typeAnnotation_(nullptr), trailingComma_(trailingComma) 38 { 39 } 40 Elements()41 const ArenaVector<Expression *> &Elements() const 42 { 43 return elements_; 44 } 45 TypeAnnotation()46 const Expression *TypeAnnotation() const 47 { 48 return typeAnnotation_; 49 } 50 TypeAnnotation()51 Expression *TypeAnnotation() 52 { 53 return typeAnnotation_; 54 } 55 IsDeclaration()56 bool IsDeclaration() const 57 { 58 return isDeclaration_; 59 } 60 Optional()61 bool Optional() const 62 { 63 return optional_; 64 } 65 SetDeclaration()66 void SetDeclaration() 67 { 68 isDeclaration_ = true; 69 } 70 SetOptional(bool optional)71 void SetOptional(bool optional) 72 { 73 optional_ = optional; 74 } 75 76 bool ConvertibleToArrayPattern(); 77 ValidationInfo ValidateExpression(); 78 SetTsTypeAnnotation(Expression * typeAnnotation)79 void SetTsTypeAnnotation(Expression *typeAnnotation) override 80 { 81 typeAnnotation_ = typeAnnotation; 82 } 83 84 void Iterate(const NodeTraverser &cb) const override; 85 void Dump(ir::AstDumper *dumper) const override; 86 void Compile(compiler::PandaGen *pg) const override; 87 checker::Type *Check(checker::Checker *checker) const override; 88 checker::Type *CheckPattern(checker::Checker *checker) const; 89 void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; 90 91 private: 92 ArenaVector<Expression *> elements_; 93 Expression *typeAnnotation_; 94 bool isDeclaration_ {}; 95 bool trailingComma_; 96 bool optional_ {false}; 97 }; 98 99 } // namespace panda::es2panda::ir 100 101 #endif 102