- Timestamp:
- Mar 28, 2022, 10:41:45 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 8e819a9
- Parents:
- f5bace8
- Location:
- src/AST
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
rf5bace8 r400b8be 353 353 } 354 354 355 void clausePostamble( Statement * stmt, const ast::StmtClause * node ) { 356 stmt->location = node->location; 357 this->node = stmt; 358 } 359 355 360 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 356 361 if ( inCache( node ) ) return nullptr; … … 401 406 auto stmt = new SwitchStmt( 402 407 get<Expression>().accept1( node->cond ), 403 get<Statement>().acceptL( node-> stmts )408 get<Statement>().acceptL( node->cases ) 404 409 ); 405 410 return stmtPostamble( stmt, node ); 406 411 } 407 412 408 const ast:: Stmt * visit( const ast::CaseStmt* node ) override final {413 const ast::CaseClause * visit( const ast::CaseClause * node ) override final { 409 414 if ( inCache( node ) ) return nullptr; 410 415 auto stmt = new CaseStmt( … … 413 418 node->isDefault() 414 419 ); 415 return stmtPostamble( stmt, node ); 420 clausePostamble( stmt, node ); 421 return nullptr; 416 422 } 417 423 … … 509 515 } 510 516 511 const ast:: Stmt * visit( const ast::CatchStmt* node ) override final {517 const ast::CatchClause * visit( const ast::CatchClause * node ) override final { 512 518 if ( inCache( node ) ) return nullptr; 513 519 CatchStmt::Kind kind; … … 520 526 break; 521 527 default: 522 assertf(false, "Invalid ast:: CatchStmt::Kind: %d\n", node->kind);528 assertf(false, "Invalid ast::ExceptionKind: %d\n", node->kind); 523 529 } 524 530 auto stmt = new CatchStmt( … … 528 534 get<Statement>().accept1( node->body ) 529 535 ); 530 return stmtPostamble( stmt, node );531 } 532 533 const ast:: Stmt * visit( const ast::FinallyStmt* node ) override final {536 return clausePostamble( stmt, node ), nullptr; 537 } 538 539 const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final { 534 540 if ( inCache( node ) ) return nullptr; 535 541 auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); 536 return stmtPostamble( stmt, node );542 return clausePostamble( stmt, node ), nullptr; 537 543 } 538 544 … … 1884 1890 old->location, 1885 1891 GET_ACCEPT_1(condition, Expr), 1886 GET_ACCEPT_V(statements, Stmt),1892 GET_ACCEPT_V(statements, CaseClause), 1887 1893 GET_LABELS_V(old->labels) 1888 1894 ); … … 1892 1898 virtual void visit( const CaseStmt * old ) override final { 1893 1899 if ( inCache( old ) ) return; 1894 this->node = new ast::Case Stmt(1900 this->node = new ast::CaseClause( 1895 1901 old->location, 1896 1902 GET_ACCEPT_1(condition, Expr), 1897 GET_ACCEPT_V(stmts, Stmt), 1898 GET_LABELS_V(old->labels) 1899 ); 1903 GET_ACCEPT_V(stmts, Stmt) 1904 ); 1905 auto labels = GET_LABELS_V(old->labels); 1906 assertf(labels.empty(), "Labels found on CaseStmt."); 1900 1907 cache.emplace( old, this->node ); 1901 1908 } … … 2005 2012 old->location, 2006 2013 GET_ACCEPT_1(block, CompoundStmt), 2007 GET_ACCEPT_V(handlers, Catch Stmt),2008 GET_ACCEPT_1(finallyBlock, Finally Stmt),2014 GET_ACCEPT_V(handlers, CatchClause), 2015 GET_ACCEPT_1(finallyBlock, FinallyClause), 2009 2016 GET_LABELS_V(old->labels) 2010 2017 ); … … 2026 2033 } 2027 2034 2028 this->node = new ast::Catch Stmt(2035 this->node = new ast::CatchClause( 2029 2036 old->location, 2030 2037 kind, 2031 2038 GET_ACCEPT_1(decl, Decl), 2032 2039 GET_ACCEPT_1(cond, Expr), 2033 GET_ACCEPT_1(body, Stmt), 2034 GET_LABELS_V(old->labels) 2035 ); 2040 GET_ACCEPT_1(body, Stmt) 2041 ); 2042 auto labels = GET_LABELS_V(old->labels); 2043 assertf(labels.empty(), "Labels found on CatchStmt."); 2036 2044 cache.emplace( old, this->node ); 2037 2045 } … … 2039 2047 virtual void visit( const FinallyStmt * old ) override final { 2040 2048 if ( inCache( old ) ) return; 2041 this->node = new ast::FinallyStmt( 2042 old->location, 2043 GET_ACCEPT_1(block, CompoundStmt), 2044 GET_LABELS_V(old->labels) 2045 ); 2049 this->node = new ast::FinallyClause( 2050 old->location, 2051 GET_ACCEPT_1(block, CompoundStmt) 2052 ); 2053 auto labels = GET_LABELS_V(old->labels); 2054 assertf(labels.empty(), "Labels found on FinallyStmt."); 2046 2055 cache.emplace( old, this->node ); 2047 2056 } -
src/AST/Fwd.hpp
rf5bace8 r400b8be 47 47 class ForStmt; 48 48 class SwitchStmt; 49 class Case Stmt;49 class CaseClause; 50 50 class BranchStmt; 51 51 class ReturnStmt; 52 52 class ThrowStmt; 53 53 class TryStmt; 54 class Catch Stmt;55 class Finally Stmt;54 class CatchClause; 55 class FinallyClause; 56 56 class SuspendStmt; 57 57 class WaitForStmt; -
src/AST/Node.cpp
rf5bace8 r400b8be 160 160 template class ast::ptr_base< ast::SwitchStmt, ast::Node::ref_type::weak >; 161 161 template class ast::ptr_base< ast::SwitchStmt, ast::Node::ref_type::strong >; 162 template class ast::ptr_base< ast::Case Stmt, ast::Node::ref_type::weak >;163 template class ast::ptr_base< ast::Case Stmt, ast::Node::ref_type::strong >;162 template class ast::ptr_base< ast::CaseClause, ast::Node::ref_type::weak >; 163 template class ast::ptr_base< ast::CaseClause, ast::Node::ref_type::strong >; 164 164 template class ast::ptr_base< ast::BranchStmt, ast::Node::ref_type::weak >; 165 165 template class ast::ptr_base< ast::BranchStmt, ast::Node::ref_type::strong >; … … 170 170 template class ast::ptr_base< ast::TryStmt, ast::Node::ref_type::weak >; 171 171 template class ast::ptr_base< ast::TryStmt, ast::Node::ref_type::strong >; 172 template class ast::ptr_base< ast::Catch Stmt, ast::Node::ref_type::weak >;173 template class ast::ptr_base< ast::Catch Stmt, ast::Node::ref_type::strong >;174 template class ast::ptr_base< ast::Finally Stmt, ast::Node::ref_type::weak >;175 template class ast::ptr_base< ast::Finally Stmt, ast::Node::ref_type::strong >;172 template class ast::ptr_base< ast::CatchClause, ast::Node::ref_type::weak >; 173 template class ast::ptr_base< ast::CatchClause, ast::Node::ref_type::strong >; 174 template class ast::ptr_base< ast::FinallyClause, ast::Node::ref_type::weak >; 175 template class ast::ptr_base< ast::FinallyClause, ast::Node::ref_type::strong >; 176 176 template class ast::ptr_base< ast::WaitForStmt, ast::Node::ref_type::weak >; 177 177 template class ast::ptr_base< ast::WaitForStmt, ast::Node::ref_type::strong >; -
src/AST/Pass.hpp
rf5bace8 r400b8be 149 149 const ast::Stmt * visit( const ast::ForStmt * ) override final; 150 150 const ast::Stmt * visit( const ast::SwitchStmt * ) override final; 151 const ast:: Stmt * visit( const ast::CaseStmt* ) override final;151 const ast::CaseClause * visit( const ast::CaseClause * ) override final; 152 152 const ast::Stmt * visit( const ast::BranchStmt * ) override final; 153 153 const ast::Stmt * visit( const ast::ReturnStmt * ) override final; 154 154 const ast::Stmt * visit( const ast::ThrowStmt * ) override final; 155 155 const ast::Stmt * visit( const ast::TryStmt * ) override final; 156 const ast:: Stmt * visit( const ast::CatchStmt* ) override final;157 const ast:: Stmt * visit( const ast::FinallyStmt* ) override final;156 const ast::CatchClause * visit( const ast::CatchClause * ) override final; 157 const ast::FinallyClause * visit( const ast::FinallyClause * ) override final; 158 158 const ast::Stmt * visit( const ast::SuspendStmt * ) override final; 159 159 const ast::Stmt * visit( const ast::WaitForStmt * ) override final; -
src/AST/Pass.impl.hpp
rf5bace8 r400b8be 893 893 if ( __visit_children() ) { 894 894 maybe_accept( node, &SwitchStmt::cond ); 895 maybe_accept( node, &SwitchStmt:: stmts );895 maybe_accept( node, &SwitchStmt::cases ); 896 896 } 897 897 … … 900 900 901 901 //-------------------------------------------------------------------------- 902 // Case Stmt903 template< typename core_t > 904 const ast:: Stmt * ast::Pass< core_t >::visit( const ast::CaseStmt* node ) {905 VISIT_START( node ); 906 907 if ( __visit_children() ) { 908 maybe_accept( node, &Case Stmt::cond );909 maybe_accept( node, &Case Stmt::stmts );910 } 911 912 VISIT_END( Stmt, node );902 // CaseClause 903 template< typename core_t > 904 const ast::CaseClause * ast::Pass< core_t >::visit( const ast::CaseClause * node ) { 905 VISIT_START( node ); 906 907 if ( __visit_children() ) { 908 maybe_accept( node, &CaseClause::cond ); 909 maybe_accept( node, &CaseClause::stmts ); 910 } 911 912 VISIT_END( CaseClause, node ); 913 913 } 914 914 … … 964 964 965 965 //-------------------------------------------------------------------------- 966 // Catch Stmt967 template< typename core_t > 968 const ast:: Stmt * ast::Pass< core_t >::visit( const ast::CatchStmt* node ) {966 // CatchClause 967 template< typename core_t > 968 const ast::CatchClause * ast::Pass< core_t >::visit( const ast::CatchClause * node ) { 969 969 VISIT_START( node ); 970 970 … … 972 972 // catch statements introduce a level of scope (for the caught exception) 973 973 guard_symtab guard { *this }; 974 maybe_accept( node, &Catch Stmt::decl );975 maybe_accept( node, &Catch Stmt::cond );976 maybe_accept_as_compound( node, &Catch Stmt::body );977 } 978 979 VISIT_END( Stmt, node );980 } 981 982 //-------------------------------------------------------------------------- 983 // Finally Stmt984 template< typename core_t > 985 const ast:: Stmt * ast::Pass< core_t >::visit( const ast::FinallyStmt* node ) {986 VISIT_START( node ); 987 988 if ( __visit_children() ) { 989 maybe_accept( node, &Finally Stmt::body );990 } 991 992 VISIT_END( Stmt, node );974 maybe_accept( node, &CatchClause::decl ); 975 maybe_accept( node, &CatchClause::cond ); 976 maybe_accept_as_compound( node, &CatchClause::body ); 977 } 978 979 VISIT_END( CatchClause, node ); 980 } 981 982 //-------------------------------------------------------------------------- 983 // FinallyClause 984 template< typename core_t > 985 const ast::FinallyClause * ast::Pass< core_t >::visit( const ast::FinallyClause * node ) { 986 VISIT_START( node ); 987 988 if ( __visit_children() ) { 989 maybe_accept( node, &FinallyClause::body ); 990 } 991 992 VISIT_END( FinallyClause, node ); 993 993 } 994 994 -
src/AST/Print.cpp
rf5bace8 r400b8be 589 589 590 590 ++indent; 591 for ( const ast:: Stmt * stmt : node->stmts ) {591 for ( const ast::CaseClause * stmt : node->cases ) { 592 592 stmt->accept( *this ); 593 593 } … … 597 597 } 598 598 599 virtual const ast:: Stmt * visit( const ast::CaseStmt* node ) override final {599 virtual const ast::CaseClause * visit( const ast::CaseClause * node ) override final { 600 600 if ( node->isDefault() ) { 601 601 os << indent << "Default "; … … 679 679 680 680 os << indent-1 << "... and handlers:" << endl; 681 for ( const ast::Catch Stmt* stmt : node->handlers ) {681 for ( const ast::CatchClause * stmt : node->handlers ) { 682 682 os << indent; 683 683 stmt->accept( *this ); … … 693 693 } 694 694 695 virtual const ast:: Stmt * visit( const ast::CatchStmt* node ) override final {695 virtual const ast::CatchClause * visit( const ast::CatchClause * node ) override final { 696 696 os << "Catch "; 697 697 switch ( node->kind ) { … … 718 718 } 719 719 720 virtual const ast:: Stmt * visit( const ast::FinallyStmt* node ) override final {720 virtual const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final { 721 721 os << "Finally Statement" << endl; 722 722 os << indent << "... with block:" << endl; -
src/AST/Stmt.hpp
rf5bace8 r400b8be 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 8 13:00:00 2019 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Feb 2 20:06:41202213 // Update Count : 3 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Mar 28 9:50:00 2022 13 // Update Count : 35 14 14 // 15 15 … … 47 47 private: 48 48 Stmt * clone() const override = 0; 49 MUTATE_FRIEND 50 }; 51 52 // Base statement component node (only serves to group them). 53 class StmtClause : public ParseNode { 54 public: 55 // This is for non-statements that still belong with the statements, 56 // but are not statements, usually some sort of clause. Often these can 57 // (and should) be folded into the approprate parent node, but if they 58 // cannot be, they are sub-types of this type, for organization. 59 60 StmtClause( const CodeLocation & loc ) 61 : ParseNode(loc) {} 62 63 private: 64 StmtClause * clone() const override = 0; 49 65 MUTATE_FRIEND 50 66 }; … … 158 174 public: 159 175 ptr<Expr> cond; 176 std::vector<ptr<CaseClause>> cases; 177 178 SwitchStmt( const CodeLocation & loc, const Expr * cond, 179 const std::vector<ptr<CaseClause>> && cases, 180 const std::vector<Label> && labels = {} ) 181 : Stmt(loc, std::move(labels)), cond(cond), cases(std::move(cases)) {} 182 183 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 184 private: 185 SwitchStmt * clone() const override { return new SwitchStmt{ *this }; } 186 MUTATE_FRIEND 187 }; 188 189 // Case label: case ...: or default: 190 class CaseClause final : public StmtClause { 191 public: 192 // Null for the default label. 193 ptr<Expr> cond; 160 194 std::vector<ptr<Stmt>> stmts; 161 195 162 SwitchStmt( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts, 163 const std::vector<Label> && labels = {} ) 164 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 165 166 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 167 private: 168 SwitchStmt * clone() const override { return new SwitchStmt{ *this }; } 169 MUTATE_FRIEND 170 }; 171 172 // Case label: case ...: or default: 173 class CaseStmt final : public Stmt { 174 public: 175 // Null for the default label. 176 ptr<Expr> cond; 177 std::vector<ptr<Stmt>> stmts; 178 179 CaseStmt( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts, 180 const std::vector<Label> && labels = {} ) 181 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 196 CaseClause( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts ) 197 : StmtClause(loc), cond(cond), stmts(std::move(stmts)) {} 182 198 183 199 bool isDefault() const { return !cond; } 184 200 185 const Stmt* accept( Visitor & v ) const override { return v.visit( this ); }186 private: 187 Case Stmt * clone() const override { return new CaseStmt{ *this }; }201 const CaseClause * accept( Visitor & v ) const override { return v.visit( this ); } 202 private: 203 CaseClause * clone() const override { return new CaseClause{ *this }; } 188 204 MUTATE_FRIEND 189 205 }; … … 298 314 public: 299 315 ptr<CompoundStmt> body; 300 std::vector<ptr<Catch Stmt>> handlers;301 ptr<Finally Stmt> finally;316 std::vector<ptr<CatchClause>> handlers; 317 ptr<FinallyClause> finally; 302 318 303 319 TryStmt( const CodeLocation & loc, const CompoundStmt * body, 304 const std::vector<ptr<Catch Stmt>> && handlers, const FinallyStmt* finally,320 const std::vector<ptr<CatchClause>> && handlers, const FinallyClause * finally, 305 321 const std::vector<Label> && labels = {} ) 306 322 : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {} … … 313 329 314 330 // Catch clause of try statement 315 class Catch Stmt final : public Stmt{331 class CatchClause final : public StmtClause { 316 332 public: 317 333 ptr<Decl> decl; … … 320 336 ExceptionKind kind; 321 337 322 Catch Stmt( const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond,323 const Stmt * body , const std::vector<Label> && labels = {})324 : Stmt (loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {}325 326 const Stmt* accept( Visitor & v ) const override { return v.visit( this ); }327 private: 328 Catch Stmt * clone() const override { return new CatchStmt{ *this }; }338 CatchClause( const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond, 339 const Stmt * body ) 340 : StmtClause(loc), decl(decl), cond(cond), body(body), kind(kind) {} 341 342 const CatchClause * accept( Visitor & v ) const override { return v.visit( this ); } 343 private: 344 CatchClause * clone() const override { return new CatchClause{ *this }; } 329 345 MUTATE_FRIEND 330 346 }; 331 347 332 348 // Finally clause of try statement 333 class Finally Stmt final : public Stmt{349 class FinallyClause final : public StmtClause { 334 350 public: 335 351 ptr<CompoundStmt> body; 336 352 337 FinallyStmt( const CodeLocation & loc, const CompoundStmt * body, 338 std::vector<Label> && labels = {} ) 339 : Stmt(loc, std::move(labels)), body(body) {} 340 341 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 342 private: 343 FinallyStmt * clone() const override { return new FinallyStmt{ *this }; } 353 FinallyClause( const CodeLocation & loc, const CompoundStmt * body ) 354 : StmtClause(loc), body(body) {} 355 356 const FinallyClause * accept( Visitor & v ) const override { return v.visit( this ); } 357 private: 358 FinallyClause * clone() const override { return new FinallyClause{ *this }; } 344 359 MUTATE_FRIEND 345 360 }; -
src/AST/Visitor.hpp
rf5bace8 r400b8be 41 41 virtual const ast::Stmt * visit( const ast::ForStmt * ) = 0; 42 42 virtual const ast::Stmt * visit( const ast::SwitchStmt * ) = 0; 43 virtual const ast:: Stmt * visit( const ast::CaseStmt* ) = 0;43 virtual const ast::CaseClause * visit( const ast::CaseClause * ) = 0; 44 44 virtual const ast::Stmt * visit( const ast::BranchStmt * ) = 0; 45 45 virtual const ast::Stmt * visit( const ast::ReturnStmt * ) = 0; 46 46 virtual const ast::Stmt * visit( const ast::ThrowStmt * ) = 0; 47 47 virtual const ast::Stmt * visit( const ast::TryStmt * ) = 0; 48 virtual const ast:: Stmt * visit( const ast::CatchStmt* ) = 0;49 virtual const ast:: Stmt * visit( const ast::FinallyStmt* ) = 0;48 virtual const ast::CatchClause * visit( const ast::CatchClause * ) = 0; 49 virtual const ast::FinallyClause * visit( const ast::FinallyClause * ) = 0; 50 50 virtual const ast::Stmt * visit( const ast::SuspendStmt * ) = 0; 51 51 virtual const ast::Stmt * visit( const ast::WaitForStmt * ) = 0;
Note:
See TracChangeset
for help on using the changeset viewer.