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_IR_STATEMENT_EXPRESSION_STATEMENT_H 17 #define ES2PANDA_IR_STATEMENT_EXPRESSION_STATEMENT_H 18 19 #include "ir/statement.h" 20 #include "ir/expression.h" 21 22 namespace ark::es2panda::ir { 23 class Expression; 24 25 class ExpressionStatement : public Statement { 26 public: ExpressionStatement(Expression * expr)27 explicit ExpressionStatement(Expression *expr) : Statement(AstNodeType::EXPRESSION_STATEMENT), expression_(expr) {} 28 GetExpression()29 const Expression *GetExpression() const 30 { 31 return expression_; 32 } 33 GetExpression()34 Expression *GetExpression() 35 { 36 return expression_; 37 } 38 SetExpression(Expression * expr)39 void SetExpression(Expression *expr) 40 { 41 expression_ = expr; 42 if (expression_ != nullptr) { 43 expression_->SetParent(this); 44 } 45 } 46 47 void TransformChildren(const NodeTransformer &cb, std::string_view transformationName) override; 48 void Iterate(const NodeTraverser &cb) const override; 49 void Dump(ir::AstDumper *dumper) const override; 50 void Dump(ir::SrcDumper *dumper) const override; 51 void Compile(compiler::PandaGen *pg) const override; 52 void Compile(compiler::ETSGen *etsg) const override; 53 checker::Type *Check(checker::TSChecker *checker) override; 54 checker::VerifiedType Check(checker::ETSChecker *checker) override; 55 Accept(ASTVisitorT * v)56 void Accept(ASTVisitorT *v) override 57 { 58 v->Accept(this); 59 } 60 61 [[nodiscard]] ExpressionStatement *Clone(ArenaAllocator *allocator, AstNode *parent) override; 62 63 private: 64 Expression *expression_; 65 }; 66 } // namespace ark::es2panda::ir 67 68 #endif 69