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_EXPRESSION_UPDATE_EXPRESSION_H 17 #define ES2PANDA_IR_EXPRESSION_UPDATE_EXPRESSION_H 18 19 #include "ir/expression.h" 20 #include "lexer/token/tokenType.h" 21 namespace panda::es2panda::checker { 22 class TSAnalyzer; 23 class ETSAnalyzer; 24 } // namespace panda::es2panda::checker 25 namespace panda::es2panda::ir { 26 class UpdateExpression : public Expression { 27 public: 28 UpdateExpression() = delete; 29 ~UpdateExpression() override = default; 30 31 NO_COPY_SEMANTIC(UpdateExpression); 32 NO_MOVE_SEMANTIC(UpdateExpression); 33 UpdateExpression(Expression * const argument,lexer::TokenType const updateOperator,bool const isPrefix)34 explicit UpdateExpression(Expression *const argument, lexer::TokenType const updateOperator, bool const isPrefix) 35 : Expression(AstNodeType::UPDATE_EXPRESSION), argument_(argument), operator_(updateOperator), prefix_(isPrefix) 36 { 37 ASSERT(updateOperator == lexer::TokenType::PUNCTUATOR_PLUS_PLUS || 38 updateOperator == lexer::TokenType::PUNCTUATOR_MINUS_MINUS); 39 } 40 41 // NOTE (vivienvoros): these friend relationships can be removed once there are getters for private fields 42 friend class checker::TSAnalyzer; 43 friend class checker::ETSAnalyzer; 44 OperatorType()45 [[nodiscard]] lexer::TokenType OperatorType() const noexcept 46 { 47 return operator_; 48 } 49 Argument()50 [[nodiscard]] Expression *Argument() noexcept 51 { 52 return argument_; 53 } 54 Argument()55 [[nodiscard]] const Expression *Argument() const noexcept 56 { 57 return argument_; 58 } 59 IsPrefix()60 [[nodiscard]] bool IsPrefix() const noexcept 61 { 62 return prefix_; 63 } 64 65 // NOLINTNEXTLINE(google-default-arguments) 66 [[nodiscard]] UpdateExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; 67 68 void TransformChildren(const NodeTransformer &cb) override; 69 void Iterate(const NodeTraverser &cb) const override; 70 void Dump(ir::AstDumper *dumper) const override; 71 void Dump(ir::SrcDumper *dumper) const override; 72 void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; 73 void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; 74 checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; 75 checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; 76 Accept(ASTVisitorT * v)77 void Accept(ASTVisitorT *v) override 78 { 79 v->Accept(this); 80 } 81 82 private: 83 Expression *argument_; 84 lexer::TokenType operator_; 85 bool prefix_; 86 }; 87 } // namespace panda::es2panda::ir 88 89 #endif 90