1 /** 2 * Copyright (c) 2021-2024 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_UNARY_EXPRESSION_H 17 #define ES2PANDA_IR_EXPRESSION_UNARY_EXPRESSION_H 18 19 #include "checker/checkerContext.h" 20 #include "ir/expression.h" 21 22 namespace ark::es2panda::compiler { 23 class PandaGen; 24 class ETSGen; 25 } // namespace ark::es2panda::compiler 26 27 namespace ark::es2panda::checker { 28 class TSChecker; 29 class Type; 30 class ETSAnalyzer; 31 class TSAnalyzer; 32 } // namespace ark::es2panda::checker 33 34 namespace ark::es2panda::ir { 35 class UnaryExpression : public Expression { 36 public: 37 UnaryExpression() = delete; 38 ~UnaryExpression() override = default; 39 40 NO_COPY_SEMANTIC(UnaryExpression); 41 NO_MOVE_SEMANTIC(UnaryExpression); 42 UnaryExpression(Expression *const argument, lexer::TokenType const unaryOperator)43 explicit UnaryExpression(Expression *const argument, lexer::TokenType const unaryOperator) 44 : Expression(AstNodeType::UNARY_EXPRESSION), argument_(argument), operator_(unaryOperator) 45 { 46 } 47 // NOTE (somasimon): these friend relationships can be removed once there are getters for private fields 48 friend class checker::ETSAnalyzer; 49 friend class checker::TSAnalyzer; 50 51 [[nodiscard]] lexer::TokenType OperatorType() const noexcept 52 { 53 return operator_; 54 } 55 56 [[nodiscard]] Expression *Argument() noexcept 57 { 58 return argument_; 59 } 60 61 [[nodiscard]] const Expression *Argument() const noexcept 62 { 63 return argument_; 64 } 65 66 [[nodiscard]] UnaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; 67 68 void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) 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(compiler::PandaGen *pg) const override; 73 void Compile(compiler::ETSGen *etsg) const override; 74 checker::Type *Check(checker::TSChecker *checker) override; 75 checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; 76 77 void Accept(ASTVisitorT *v) override 78 { 79 v->Accept(this); 80 } 81 82 private: 83 Expression *argument_; 84 lexer::TokenType operator_; 85 }; 86 } // namespace ark::es2panda::ir 87 88 #endif 89