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_BASE_CATCH_CLAUSE_H 17 #define ES2PANDA_IR_BASE_CATCH_CLAUSE_H 18 19 #include "varbinder/scope.h" 20 #include "ir/statement.h" 21 22 namespace panda::es2panda::ir { 23 class BlockStatement; 24 class Expression; 25 26 class CatchClause : public TypedStatement { 27 public: CatchClause(Expression * param,BlockStatement * body)28 explicit CatchClause(Expression *param, BlockStatement *body) 29 : TypedStatement(AstNodeType::CATCH_CLAUSE), param_(param), body_(body) 30 { 31 } 32 Param()33 Expression *Param() 34 { 35 return param_; 36 } 37 Param()38 const Expression *Param() const 39 { 40 return param_; 41 } 42 Body()43 BlockStatement *Body() 44 { 45 return body_; 46 } 47 Body()48 const BlockStatement *Body() const 49 { 50 return body_; 51 } 52 IsScopeBearer()53 bool IsScopeBearer() const override 54 { 55 return true; 56 } 57 Scope()58 varbinder::CatchScope *Scope() const override 59 { 60 return scope_; 61 } 62 SetScope(varbinder::CatchScope * scope)63 void SetScope(varbinder::CatchScope *scope) 64 { 65 scope_ = scope; 66 } 67 68 bool IsDefaultCatchClause() const; 69 void TransformChildren(const NodeTransformer &cb) override; 70 void Iterate(const NodeTraverser &cb) const override; 71 void Dump(ir::AstDumper *dumper) const override; 72 void Dump(ir::SrcDumper *dumper) const override; 73 void Compile(compiler::PandaGen *pg) const override; 74 void Compile(compiler::ETSGen *etsg) const override; 75 checker::Type *Check(checker::TSChecker *checker) override; 76 checker::Type *Check(checker::ETSChecker *checker) override; 77 Accept(ASTVisitorT * v)78 void Accept(ASTVisitorT *v) override 79 { 80 v->Accept(this); 81 } 82 83 private: 84 varbinder::CatchScope *scope_ {nullptr}; 85 Expression *param_; 86 BlockStatement *body_; 87 }; 88 } // namespace panda::es2panda::ir 89 90 #endif 91