Changeset 400b8be
- Timestamp:
- Mar 28, 2022, 10:41:45 AM (18 months ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 8e819a9
- Parents:
- f5bace8
- Location:
- src
- Files:
-
- 16 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; -
src/Common/CodeLocationTools.cpp
rf5bace8 r400b8be 112 112 macro(ForStmt, Stmt) \ 113 113 macro(SwitchStmt, Stmt) \ 114 macro(Case Stmt, Stmt) \114 macro(CaseClause, CaseClause) \ 115 115 macro(BranchStmt, Stmt) \ 116 116 macro(ReturnStmt, Stmt) \ 117 117 macro(ThrowStmt, Stmt) \ 118 118 macro(TryStmt, Stmt) \ 119 macro(Catch Stmt, Stmt) \120 macro(Finally Stmt, Stmt) \119 macro(CatchClause, CatchClause) \ 120 macro(FinallyClause, FinallyClause) \ 121 121 macro(SuspendStmt, Stmt) \ 122 122 macro(WaitForStmt, Stmt) \ -
src/Concurrency/KeywordsNew.cpp
rf5bace8 r400b8be 1333 1333 1334 1334 // construct the current try 1335 currentTry = new ast::TryStmt( 1336 location, 1337 currTryBody, 1338 {}, 1339 new ast::Finally Stmt( location, currFinallyBody )1335 currentTry = new ast::TryStmt( 1336 location, 1337 currTryBody, 1338 {}, 1339 new ast::FinallyClause( location, currFinallyBody ) 1340 1340 ); 1341 1341 if ( i == 0 ) outerTry = currentTry; … … 1351 1351 lastBody->push_back( body ); 1352 1352 newBody->push_front( outerTry ); 1353 } 1353 } 1354 1354 1355 1355 // monitor_guard_t __guard = { __monitors, # }; -
src/ControlStruct/ExceptTranslateNew.cpp
rf5bace8 r400b8be 26 26 namespace { 27 27 28 typedef std::list<ast::Catch Stmt*> CatchList;28 typedef std::list<ast::CatchClause*> CatchList; 29 29 30 30 void appendDeclStmt( ast::CompoundStmt * block, ast::DeclWithType * item ) { … … 45 45 {} 46 46 47 void previsit( const ast::Catch Stmt* stmt );47 void previsit( const ast::CatchClause * stmt ); 48 48 const ast::Stmt * postvisit( const ast::ThrowStmt * stmt ); 49 49 }; … … 88 88 } 89 89 90 void TranslateThrowsCore::previsit( const ast::Catch Stmt* stmt ) {90 void TranslateThrowsCore::previsit( const ast::CatchClause * stmt ) { 91 91 // Validate the statement's form. 92 92 const ast::ObjectDecl * decl = stmt->decl.as<ast::ObjectDecl>(); … … 147 147 ast::FunctionDecl * create_terminate_catch( CatchList &handlers ); 148 148 ast::CompoundStmt * create_single_matcher( 149 const ast::DeclWithType * except_obj, ast::Catch Stmt* modded_handler );149 const ast::DeclWithType * except_obj, ast::CatchClause * modded_handler ); 150 150 ast::FunctionDecl * create_terminate_match( CatchList &handlers ); 151 151 ast::CompoundStmt * create_terminate_caller( CodeLocation loc, ast::FunctionDecl * try_wrapper, … … 338 338 ast::FunctionDecl * TryMutatorCore::create_terminate_catch( 339 339 CatchList &handlers ) { 340 std::vector<ast::ptr<ast:: Stmt>> handler_wrappers;340 std::vector<ast::ptr<ast::CaseClause>> handler_wrappers; 341 341 342 342 assert (!handlers.empty()); … … 352 352 for ( ; it != handlers.end() ; ++it ) { 353 353 ++index; 354 ast::Catch Stmt* handler = *it;354 ast::CatchClause * handler = *it; 355 355 const CodeLocation loc = handler->location; 356 356 … … 390 390 // handler->body = nullptr; 391 391 392 handler_wrappers.push_back( new ast::Case Stmt(loc,392 handler_wrappers.push_back( new ast::CaseClause(loc, 393 393 ast::ConstantExpr::from_int(loc, index) , 394 394 { block, new ast::ReturnStmt( loc, nullptr ) } … … 410 410 // except_obj is referenced, modded_handler will be freed. 411 411 ast::CompoundStmt * TryMutatorCore::create_single_matcher( 412 const ast::DeclWithType * except_obj, ast::Catch Stmt* modded_handler ) {412 const ast::DeclWithType * except_obj, ast::CatchClause * modded_handler ) { 413 413 // { 414 414 // `modded_handler.decl` … … 465 465 for ( it = handlers.begin() ; it != handlers.end() ; ++it ) { 466 466 ++index; 467 ast::Catch Stmt* handler = *it;467 ast::CatchClause * handler = *it; 468 468 469 469 // Body should have been taken by create_terminate_catch. … … 520 520 CatchList::iterator it; 521 521 for ( it = handlers.begin() ; it != handlers.end() ; ++it ) { 522 ast::Catch Stmt* handler = *it;522 ast::CatchClause * handler = *it; 523 523 const CodeLocation loc = handler->location; 524 524 // Modifiy body. … … 587 587 ast::TryStmt * tryStmt ) { 588 588 // void finally() { `finally->block` } 589 const ast::Finally Stmt* finally = tryStmt->finally;589 const ast::FinallyClause * finally = tryStmt->finally; 590 590 const ast::CompoundStmt * body = finally->body; 591 591 -
src/ControlStruct/LabelGeneratorNew.cpp
rf5bace8 r400b8be 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // LabelGenerator .cc--7 // LabelGeneratorNew.cpp -- 8 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Feb 2 09:11:17202213 // Update Count : 7 211 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Mar 28 10:03:00 2022 13 // Update Count : 73 14 14 // 15 15 … … 25 25 namespace ControlStruct { 26 26 27 Label newLabel( const string & suffix, const Stmt * stmt ) { 27 enum { size = 128 }; 28 29 static int newLabelPre( char buf[size], const string & suffix ) { 28 30 static int current = 0; 29 31 30 assertf( stmt, "CFA internal error: parameter statement cannot be null pointer" );31 32 enum { size = 128 };33 char buf[size]; // space to build label34 32 int len = snprintf( buf, size, "__L%d__%s", current++, suffix.c_str() ); 35 33 assertf( len < size, "CFA Internal error: buffer overflow creating label" ); 34 return len; 35 } 36 37 static Label newLabelPost( char buf[size], const CodeLocation & location ) { 38 Label ret_label( location, buf ); 39 ret_label.attributes.push_back( new Attribute( "unused" ) ); 40 return ret_label; 41 } 42 43 Label newLabel( const string & suffix, const Stmt * stmt ) { 44 // Buffer for string manipulation. 45 char buf[size]; 46 47 assertf( stmt, "CFA internal error: parameter statement cannot be null pointer" ); 48 int len = newLabelPre( buf, suffix ); 36 49 37 50 // What does this do? … … 41 54 } // if 42 55 43 Label ret_label( stmt->location, buf ); 44 ret_label.attributes.push_back( new Attribute( "unused" ) ); 45 return ret_label; 56 return newLabelPost( buf, stmt->location ); 57 } 58 59 Label newLabel( const string & suffix, const CodeLocation & location ) { 60 // Buffer for string manipulation. 61 char buf[size]; 62 63 newLabelPre( buf, suffix ); 64 return newLabelPost( buf, location ); 46 65 } 47 66 -
src/ControlStruct/LabelGeneratorNew.hpp
rf5bace8 r400b8be 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon Jan 31 18:03:09202213 // Update Count : 2 711 // Last Modified By : Andrew Beach 12 // Last Modified On : Fir Mar 25 15:40:00 2022 13 // Update Count : 28 14 14 // 15 15 … … 18 18 #include <string> // for string 19 19 20 class Statement;20 class CodeLocation; 21 21 22 22 namespace ast { 23 class Label; 23 24 class Stmt; 24 class Label;25 25 } // namespace ast 26 26 27 27 namespace ControlStruct { 28 28 ast::Label newLabel( const std::string &, const ast::Stmt * ); 29 ast::Label newLabel( const std::string &, const CodeLocation & ); 29 30 } // namespace ControlStruct 30 31 -
src/ControlStruct/MultiLevelExit.cpp
rf5bace8 r400b8be 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Nov 1 13:48:00 2021 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Feb 2 23:07:54202213 // Update Count : 3 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Mar 28 9:42:00 2022 13 // Update Count : 34 14 14 // 15 15 … … 40 40 41 41 enum Kind { 42 ForStmtK, WhileDoStmtK, CompoundStmtK, IfStmtK, Case StmtK, SwitchStmtK, TryStmtK42 ForStmtK, WhileDoStmtK, CompoundStmtK, IfStmtK, CaseClauseK, SwitchStmtK, TryStmtK 43 43 } kind; 44 44 … … 58 58 Entry( const IfStmt *stmt, Label breakExit ) : 59 59 stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( IfStmtK ) {} 60 Entry( const Case Stmt *stmt, Label fallExit ) :61 stmt( stmt ), firstTarget( fallExit ), secondTarget(), kind( Case StmtK ) {}60 Entry( const CaseClause *, const CompoundStmt *stmt, Label fallExit ) : 61 stmt( stmt ), firstTarget( fallExit ), secondTarget(), kind( CaseClauseK ) {} 62 62 Entry( const SwitchStmt *stmt, Label breakExit, Label fallDefaultExit ) : 63 63 stmt( stmt ), firstTarget( breakExit ), secondTarget( fallDefaultExit ), kind( SwitchStmtK ) {} … … 66 66 67 67 bool isContTarget() const { return kind <= WhileDoStmtK; } 68 bool isBreakTarget() const { return kind != Case StmtK; }69 bool isFallTarget() const { return kind == Case StmtK; }68 bool isBreakTarget() const { return kind != CaseClauseK; } 69 bool isFallTarget() const { return kind == CaseClauseK; } 70 70 bool isFallDefaultTarget() const { return kind == SwitchStmtK; } 71 71 72 72 // These routines set a target as being "used" by a BranchStmt 73 73 Label useContExit() { assert( kind <= WhileDoStmtK ); return useTarget(secondTarget); } 74 Label useBreakExit() { assert( kind != Case StmtK ); return useTarget(firstTarget); }75 Label useFallExit() { assert( kind == Case StmtK ); return useTarget(firstTarget); }74 Label useBreakExit() { assert( kind != CaseClauseK ); return useTarget(firstTarget); } 75 Label useFallExit() { assert( kind == CaseClauseK ); return useTarget(firstTarget); } 76 76 Label useFallDefaultExit() { assert( kind == SwitchStmtK ); return useTarget(secondTarget); } 77 77 78 78 // These routines check if a specific label for a statement is used by a BranchStmt 79 79 bool isContUsed() const { assert( kind <= WhileDoStmtK ); return secondTarget.used; } 80 bool isBreakUsed() const { assert( kind != Case StmtK ); return firstTarget.used; }81 bool isFallUsed() const { assert( kind == Case StmtK ); return firstTarget.used; }80 bool isBreakUsed() const { assert( kind != CaseClauseK ); return firstTarget.used; } 81 bool isFallUsed() const { assert( kind == CaseClauseK ); return firstTarget.used; } 82 82 bool isFallDefaultUsed() const { assert( kind == SwitchStmtK ); return secondTarget.used; } 83 83 void seenDefault() { fallDefaultValid = false; } … … 115 115 void previsit( const ForStmt * ); 116 116 const ForStmt * postvisit( const ForStmt * ); 117 const Case Stmt * previsit( const CaseStmt* );117 const CaseClause * previsit( const CaseClause * ); 118 118 void previsit( const IfStmt * ); 119 119 const IfStmt * postvisit( const IfStmt * ); … … 123 123 void previsit( const TryStmt * ); 124 124 void postvisit( const TryStmt * ); 125 void previsit( const Finally Stmt* );125 void previsit( const FinallyClause * ); 126 126 127 127 const Stmt * mutateLoop( const Stmt * body, Entry& ); … … 288 288 auto switchStmt = strict_dynamic_cast< const SwitchStmt * >( targetEntry->stmt ); 289 289 bool foundDefault = false; 290 for ( auto subStmt : switchStmt->stmts ) { 291 const CaseStmt * caseStmt = subStmt.strict_as<CaseStmt>(); 290 for ( auto caseStmt : switchStmt->cases ) { 292 291 if ( caseStmt->isDefault() ) { 293 292 foundDefault = true; … … 365 364 } 366 365 367 const Case Stmt * MultiLevelExitCore::previsit( const CaseStmt* stmt ) {366 const CaseClause * MultiLevelExitCore::previsit( const CaseClause * stmt ) { 368 367 visit_children = false; 369 368 … … 375 374 376 375 // The cond may not exist, but if it does update it now. 377 visitor->maybe_accept( stmt, &Case Stmt::cond );376 visitor->maybe_accept( stmt, &CaseClause::cond ); 378 377 379 378 // Just save the mutated node for simplicity. 380 Case Stmt* mutStmt = mutate( stmt );381 382 Label fallLabel = newLabel( "fallThrough", stmt );379 CaseClause * mutStmt = mutate( stmt ); 380 381 Label fallLabel = newLabel( "fallThrough", stmt->location ); 383 382 if ( ! mutStmt->stmts.empty() ) { 383 // These should already be in a block. 384 auto first = mutStmt->stmts.front().get_and_mutate(); 385 auto block = strict_dynamic_cast<CompoundStmt *>( first ); 386 384 387 // Ensure that the stack isn't corrupted by exceptions in fixBlock. 385 388 auto guard = makeFuncGuard( 386 [&](){ enclosing_control_structures.emplace_back( mutStmt, fallLabel ); },389 [&](){ enclosing_control_structures.emplace_back( mutStmt, block, fallLabel ); }, 387 390 [this](){ enclosing_control_structures.pop_back(); } 388 391 ); 389 392 390 // These should already be in a block.391 auto block = mutate( mutStmt->stmts.front().strict_as<CompoundStmt>() );392 393 block->kids = fixBlock( block->kids, true ); 393 394 … … 396 397 Entry & entry = enclosing_control_structures.back(); 397 398 if ( entry.isFallUsed() ) { 398 mutStmt->stmts.push_back( labelledNullStmt( mutStmt->location, entry.useFallExit() ) );399 mutStmt->stmts.push_back( labelledNullStmt( block->location, entry.useFallExit() ) ); 399 400 } 400 401 } … … 433 434 } 434 435 435 bool isDefaultCase( const ptr<Stmt> & stmt ) { 436 const CaseStmt * caseStmt = stmt.strict_as<CaseStmt>(); 437 return caseStmt->isDefault(); 436 static bool isDefaultCase( const ptr<CaseClause> & caseClause ) { 437 return caseClause->isDefault(); 438 438 } 439 439 440 440 void MultiLevelExitCore::previsit( const SwitchStmt * stmt ) { 441 441 Label label = newLabel( "switchBreak", stmt ); 442 auto it = find_if( stmt-> stmts.rbegin(), stmt->stmts.rend(), isDefaultCase );443 444 const Case Stmt * defaultCase = it != stmt->stmts.rend() ? (it)->strict_as<CaseStmt>() : nullptr;445 Label defaultLabel = defaultCase ? newLabel( "fallThroughDefault", defaultCase ) : Label( stmt->location, "" );442 auto it = find_if( stmt->cases.rbegin(), stmt->cases.rend(), isDefaultCase ); 443 444 const CaseClause * defaultCase = it != stmt->cases.rend() ? (*it) : nullptr; 445 Label defaultLabel = defaultCase ? newLabel( "fallThroughDefault", defaultCase->location ) : Label( stmt->location, "" ); 446 446 enclosing_control_structures.emplace_back( stmt, label, defaultLabel ); 447 447 GuardAction( [this]() { enclosing_control_structures.pop_back(); } ); … … 449 449 // Collect valid labels for fallthrough. It starts with all labels at this level, then remove as each is seen during 450 450 // traversal. 451 for ( const Stmt * stmt : stmt->stmts ) { 452 auto * caseStmt = strict_dynamic_cast< const CaseStmt * >( stmt ); 451 for ( const CaseClause * caseStmt : stmt->cases ) { 453 452 if ( caseStmt->stmts.empty() ) continue; 454 453 auto block = caseStmt->stmts.front().strict_as<CompoundStmt>(); … … 471 470 // exit label and break to the last case, create a default case if no cases. 472 471 SwitchStmt * mutStmt = mutate( stmt ); 473 if ( mutStmt-> stmts.empty() ) {474 mutStmt-> stmts.push_back( new CaseStmt( mutStmt->location, nullptr, {} ) );475 } 476 477 auto caseStmt = mutStmt-> stmts.back().strict_as<CaseStmt>();472 if ( mutStmt->cases.empty() ) { 473 mutStmt->cases.push_back( new CaseClause( mutStmt->location, nullptr, {} ) ); 474 } 475 476 auto caseStmt = mutStmt->cases.back().get(); 478 477 auto mutCase = mutate( caseStmt ); 479 mutStmt-> stmts.back() = mutCase;478 mutStmt->cases.back() = mutCase; 480 479 481 480 Label label( mutCase->location, "breakLabel" ); … … 514 513 } 515 514 516 void MultiLevelExitCore::previsit( const Finally Stmt* ) {515 void MultiLevelExitCore::previsit( const FinallyClause * ) { 517 516 GuardAction([this, old = move( enclosing_control_structures)](){ enclosing_control_structures = move(old); }); 518 517 enclosing_control_structures = vector<Entry>(); -
src/InitTweak/InitTweak.cc
rf5bace8 r400b8be 423 423 loc, targetLabel.newName(), { new ast::Attribute{ "unused" } } }; 424 424 425 std::vector< ast::ptr< ast:: Stmt> > branches;425 std::vector< ast::ptr< ast::CaseClause > > branches; 426 426 for ( const ast::Init * init : *listInit ) { 427 427 auto condition = ast::ConstantExpr::from_ulong( loc, cond ); … … 432 432 stmts.emplace_back( 433 433 new ast::BranchStmt{ loc, ast::BranchStmt::Break, switchLabel } ); 434 branches.emplace_back( new ast::Case Stmt{ loc, condition, std::move( stmts ) } );434 branches.emplace_back( new ast::CaseClause{ loc, condition, std::move( stmts ) } ); 435 435 } 436 436 out.emplace_back( new ast::SwitchStmt{ loc, index, std::move( branches ) } ); -
src/ResolvExpr/Resolver.cc
rf5bace8 r400b8be 1281 1281 const ast::ForStmt * previsit( const ast::ForStmt * ); 1282 1282 const ast::SwitchStmt * previsit( const ast::SwitchStmt * ); 1283 const ast::Case Stmt * previsit( const ast::CaseStmt* );1283 const ast::CaseClause * previsit( const ast::CaseClause * ); 1284 1284 const ast::BranchStmt * previsit( const ast::BranchStmt * ); 1285 1285 const ast::ReturnStmt * previsit( const ast::ReturnStmt * ); 1286 1286 const ast::ThrowStmt * previsit( const ast::ThrowStmt * ); 1287 const ast::Catch Stmt * previsit( const ast::CatchStmt* );1288 const ast::Catch Stmt * postvisit( const ast::CatchStmt* );1287 const ast::CatchClause * previsit( const ast::CatchClause * ); 1288 const ast::CatchClause * postvisit( const ast::CatchClause * ); 1289 1289 const ast::WaitForStmt * previsit( const ast::WaitForStmt * ); 1290 1290 const ast::WithStmt * previsit( const ast::WithStmt * ); … … 1615 1615 } 1616 1616 1617 const ast::Case Stmt * Resolver_new::previsit( const ast::CaseStmt* caseStmt ) {1617 const ast::CaseClause * Resolver_new::previsit( const ast::CaseClause * caseStmt ) { 1618 1618 if ( caseStmt->cond ) { 1619 1619 std::deque< ast::InitAlternative > initAlts = currentObject.getOptions(); … … 1631 1631 } 1632 1632 1633 caseStmt = ast::mutate_field( caseStmt, &ast::Case Stmt::cond, newExpr );1633 caseStmt = ast::mutate_field( caseStmt, &ast::CaseClause::cond, newExpr ); 1634 1634 } 1635 1635 return caseStmt; … … 1674 1674 } 1675 1675 1676 const ast::Catch Stmt * Resolver_new::previsit( const ast::CatchStmt * catchStmt) {1676 const ast::CatchClause * Resolver_new::previsit( const ast::CatchClause * catchClause ) { 1677 1677 // Until we are very sure this invarent (ifs that move between passes have then) 1678 1678 // holds, check it. This allows a check for when to decode the mangling. 1679 if ( auto ifStmt = catch Stmt->body.as<ast::IfStmt>() ) {1679 if ( auto ifStmt = catchClause->body.as<ast::IfStmt>() ) { 1680 1680 assert( ifStmt->then ); 1681 1681 } 1682 1682 // Encode the catchStmt so the condition can see the declaration. 1683 if ( catch Stmt->cond ) {1684 ast::Catch Stmt * stmt = mutate( catchStmt);1685 stmt->body = new ast::IfStmt( stmt->location, stmt->cond, nullptr, stmt->body );1686 stmt->cond = nullptr;1687 return stmt;1688 } 1689 return catch Stmt;1690 } 1691 1692 const ast::Catch Stmt * Resolver_new::postvisit( const ast::CatchStmt * catchStmt) {1683 if ( catchClause->cond ) { 1684 ast::CatchClause * clause = mutate( catchClause ); 1685 clause->body = new ast::IfStmt( clause->location, clause->cond, nullptr, clause->body ); 1686 clause->cond = nullptr; 1687 return clause; 1688 } 1689 return catchClause; 1690 } 1691 1692 const ast::CatchClause * Resolver_new::postvisit( const ast::CatchClause * catchClause ) { 1693 1693 // Decode the catchStmt so everything is stored properly. 1694 const ast::IfStmt * ifStmt = catch Stmt->body.as<ast::IfStmt>();1694 const ast::IfStmt * ifStmt = catchClause->body.as<ast::IfStmt>(); 1695 1695 if ( nullptr != ifStmt && nullptr == ifStmt->then ) { 1696 1696 assert( ifStmt->cond ); 1697 1697 assert( ifStmt->else_ ); 1698 ast::Catch Stmt * stmt = ast::mutate( catchStmt);1699 stmt->cond = ifStmt->cond;1700 stmt->body = ifStmt->else_;1698 ast::CatchClause * clause = ast::mutate( catchClause ); 1699 clause->cond = ifStmt->cond; 1700 clause->body = ifStmt->else_; 1701 1701 // ifStmt should be implicately deleted here. 1702 return stmt;1703 } 1704 return catch Stmt;1702 return clause; 1703 } 1704 return catchClause; 1705 1705 } 1706 1706
Note: See TracChangeset
for help on using the changeset viewer.