1 /** 2 * Copyright (c) 2021-2025 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_PARSER_INCLUDE_AST_SPREAD_ELEMENT_H 17 #define ES2PANDA_PARSER_INCLUDE_AST_SPREAD_ELEMENT_H 18 19 #include "ir/expression.h" 20 #include "ir/validationInfo.h" 21 22 namespace ark::es2panda::ir { 23 class SpreadElement : public AnnotatedExpression { 24 private: 25 struct Tag {}; 26 27 public: 28 SpreadElement() = delete; 29 ~SpreadElement() override = default; 30 31 NO_COPY_SEMANTIC(SpreadElement); 32 NO_MOVE_SEMANTIC(SpreadElement); 33 SpreadElement(AstNodeType const nodeType,ArenaAllocator * const allocator,Expression * const argument)34 explicit SpreadElement(AstNodeType const nodeType, ArenaAllocator *const allocator, Expression *const argument) 35 : AnnotatedExpression(nodeType), decorators_(allocator->Adapter()), argument_(argument) 36 { 37 ES2PANDA_ASSERT(argument_ != nullptr); 38 } 39 40 explicit SpreadElement(Tag tag, SpreadElement const &other, ArenaAllocator *allocator); 41 Argument()42 [[nodiscard]] const Expression *Argument() const noexcept 43 { 44 return argument_; 45 } 46 Argument()47 [[nodiscard]] Expression *Argument() noexcept 48 { 49 return argument_; 50 } 51 IsOptional()52 [[nodiscard]] bool IsOptional() const noexcept 53 { 54 return optional_; 55 } 56 Decorators()57 [[nodiscard]] const ArenaVector<Decorator *> &Decorators() const noexcept 58 { 59 return decorators_; 60 } 61 DecoratorsPtr()62 const ArenaVector<Decorator *> *DecoratorsPtr() const override 63 { 64 return &Decorators(); 65 } 66 AddDecorators(ArenaVector<Decorator * > && decorators)67 void AddDecorators(ArenaVector<Decorator *> &&decorators) override 68 { 69 decorators_ = std::move(decorators); 70 } 71 CanHaveDecorator(bool inTs)72 bool CanHaveDecorator([[maybe_unused]] bool inTs) const override 73 { 74 return true; 75 } 76 SetOptional(bool optional)77 void SetOptional(bool optional) noexcept 78 { 79 optional_ = optional; 80 } 81 82 [[nodiscard]] SpreadElement *Clone(ArenaAllocator *allocator, AstNode *parent) override; 83 84 ValidationInfo ValidateExpression(); 85 [[nodiscard]] bool ConvertibleToRest(bool isDeclaration, bool allowPattern = true); 86 87 void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; 88 void Iterate(const NodeTraverser &cb) const override; 89 void Dump(ir::AstDumper *dumper) const override; 90 void Dump(ir::SrcDumper *dumper) const override; 91 void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; 92 void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; 93 checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; 94 checker::VerifiedType Check([[maybe_unused]] checker::ETSChecker *checker) override; 95 96 std::string ToString() const override; 97 Accept(ASTVisitorT * v)98 void Accept(ASTVisitorT *v) override 99 { 100 v->Accept(this); 101 } 102 103 private: 104 ArenaVector<Decorator *> decorators_; 105 Expression *argument_ = nullptr; 106 bool optional_ {false}; 107 }; 108 } // namespace ark::es2panda::ir 109 110 #endif 111