Changeset 9c1600c for src/Common/PassVisitor.impl.h
- Timestamp:
- Jun 2, 2017, 11:23:13 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- acd738aa
- Parents:
- 676cc8c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.impl.h
r676cc8c r9c1600c 1 1 #pragma once 2 3 #define VISIT_START( node ) \ 4 call_previsit( node ); \ 5 6 #define VISIT_END( node ) \ 7 return call_postvisit( node ); \ 2 8 3 9 #define MUTATE_START( node ) \ 4 10 call_premutate( node ); \ 5 11 6 7 12 #define MUTATE_END( type, node ) \ 8 13 return call_postmutate< type * >( node ); \ … … 10 15 11 16 #define VISIT_BODY( node ) \ 12 call_previsit( node ); \17 VISIT_START( node ); \ 13 18 Visitor::visit( node ); \ 14 call_postvisit( node ); \19 VISIT_END( node ); \ 15 20 16 21 … … 39 44 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } 40 45 try { 41 *i =(*i)->accept( *this );46 (*i)->accept( *this ); 42 47 } catch ( SemanticError &e ) { 43 48 errors.append( e ); … … 78 83 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 79 84 80 Statement *newStmt = maybeVisit( stmt, *this );85 maybeAccept( stmt, *this ); 81 86 82 87 StmtList_t* beforeStmts = get_beforeStmts(); 83 88 StmtList_t* afterStmts = get_afterStmts(); 84 89 85 if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; }90 if( empty(beforeStmts) && empty(afterStmts) ) { return stmt; } 86 91 87 92 CompoundStmt *compound = new CompoundStmt( noLabels ); 88 93 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } 89 compound->get_kids().push_back( newStmt );94 compound->get_kids().push_back( stmt ); 90 95 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } 91 96 return compound; … … 187 192 } 188 193 194 //-------------------------------------------------------------------------- 195 // CompoundStmt 189 196 template< typename pass_type > 190 197 void PassVisitor< pass_type >::visit( CompoundStmt * node ) { 191 VISIT_BODY( node ); 198 VISIT_START( node ); 199 call_beginScope(); 200 201 visitStatementList( node->get_kids() ); 202 203 call_endScope(); 204 VISIT_END( node ); 192 205 } 193 206 … … 203 216 } 204 217 218 //-------------------------------------------------------------------------- 219 // ExprStmt 205 220 template< typename pass_type > 206 221 void PassVisitor< pass_type >::visit( ExprStmt * node ) { 207 VISIT_BODY( node ); 222 VISIT_START( node ); 223 call_beginScope(); 224 225 visitExpression( node->get_expr() ); 226 227 call_endScope(); 228 VISIT_END( node ); 208 229 } 209 230 … … 222 243 } 223 244 245 //-------------------------------------------------------------------------- 246 // IfStmt 224 247 template< typename pass_type > 225 248 void PassVisitor< pass_type >::visit( IfStmt * node ) { 226 VISIT_BODY( node ); 249 VISIT_START( node ); 250 251 visitExpression( node->get_condition() ); 252 node->set_thenPart ( visitStatement( node->get_thenPart() ) ); 253 node->set_elsePart ( visitStatement( node->get_elsePart() ) ); 254 255 VISIT_END( node ); 227 256 } 228 257 … … 238 267 } 239 268 269 //-------------------------------------------------------------------------- 270 // WhileStmt 240 271 template< typename pass_type > 241 272 void PassVisitor< pass_type >::visit( WhileStmt * node ) { 242 VISIT_BODY( node ); 273 VISIT_START( node ); 274 275 visitExpression( node->get_condition() ); 276 node->set_body( visitStatement( node->get_body() ) ); 277 278 VISIT_END( node ); 243 279 } 244 280 … … 253 289 } 254 290 255 291 //-------------------------------------------------------------------------- 292 // WhileStmt 256 293 template< typename pass_type > 257 294 void PassVisitor< pass_type >::visit( ForStmt * node ) { 258 VISIT_BODY( node ); 295 VISIT_START( node ); 296 297 acceptAll( node->get_initialization(), *this ); 298 visitExpression( node->get_condition() ); 299 visitExpression( node->get_increment() ); 300 node->set_body( visitStatement( node->get_body() ) ); 301 302 VISIT_END( node ); 259 303 } 260 304 … … 264 308 265 309 mutateAll( node->get_initialization(), *this ); 266 node->set_condition( 267 node->set_increment( 268 node->set_body( 310 node->set_condition( mutateExpression( node->get_condition() ) ); 311 node->set_increment( mutateExpression( node->get_increment() ) ); 312 node->set_body( mutateStatement( node->get_body() ) ); 269 313 270 314 MUTATE_END( Statement, node ); 271 315 } 272 316 317 //-------------------------------------------------------------------------- 318 // SwitchStmt 273 319 template< typename pass_type > 274 320 void PassVisitor< pass_type >::visit( SwitchStmt * node ) { 275 VISIT_BODY( node ); 321 VISIT_START( node ); 322 323 visitExpression( node->get_condition() ); 324 visitStatementList( node->get_statements() ); 325 326 VISIT_END( node ); 276 327 } 277 328 … … 286 337 } 287 338 339 //-------------------------------------------------------------------------- 340 // SwitchStmt 288 341 template< typename pass_type > 289 342 void PassVisitor< pass_type >::visit( CaseStmt * node ) { 290 VISIT_BODY( node ); 343 VISIT_START( node ); 344 345 visitExpression( node->get_condition() ); 346 visitStatementList( node->get_statements() ); 347 348 VISIT_END( node ); 291 349 } 292 350 … … 306 364 } 307 365 366 //-------------------------------------------------------------------------- 367 // ReturnStmt 308 368 template< typename pass_type > 309 369 void PassVisitor< pass_type >::visit( ReturnStmt * node ) { 310 VISIT_BODY( node ); 370 VISIT_START( node ); 371 372 visitExpression( node->get_expr() ); 373 374 VISIT_END( node ); 311 375 } 312 376 … … 320 384 } 321 385 386 //-------------------------------------------------------------------------- 387 // TryStmt 322 388 template< typename pass_type > 323 389 void PassVisitor< pass_type >::visit( TryStmt * node ) { 324 VISIT_BODY( node ); 390 VISIT_START( node ); 391 392 maybeAccept( node->get_block(), *this ); 393 acceptAll( node->get_catchers(), *this ); 394 395 VISIT_END( node ); 325 396 } 326 397 … … 335 406 } 336 407 408 //-------------------------------------------------------------------------- 409 // CatchStmt 337 410 template< typename pass_type > 338 411 void PassVisitor< pass_type >::visit( CatchStmt * node ) { 339 VISIT_BODY( node ); 412 VISIT_START( node ); 413 414 node->set_body( visitStatement( node->get_body() ) ); 415 maybeAccept( node->get_decl(), *this ); 416 417 VISIT_END( node ); 340 418 } 341 419 … … 375 453 } 376 454 455 //-------------------------------------------------------------------------- 456 // UntypedExpr 377 457 template< typename pass_type > 378 458 void PassVisitor< pass_type >::visit( UntypedExpr * node ) { 379 VISIT_BODY( node ); 459 VISIT_START( node ); 460 461 for ( auto expr : node->get_args() ) { 462 visitExpression( expr ); 463 } 464 465 VISIT_END( node ); 380 466 } 381 467 … … 536 622 } 537 623 624 //-------------------------------------------------------------------------- 625 // UntypedExpr 538 626 template< typename pass_type > 539 627 void PassVisitor< pass_type >::visit( StmtExpr * node ) { 540 VISIT_BODY( node ); 628 VISIT_START( node ); 629 630 // don't want statements from outer CompoundStmts to be added to this StmtExpr 631 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); 632 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 633 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 634 635 Visitor::visit( node ); 636 637 VISIT_END( node ); 541 638 } 542 639 … … 640 737 } 641 738 739 //-------------------------------------------------------------------------- 740 // UntypedExpr 642 741 template< typename pass_type > 643 742 void PassVisitor< pass_type >::visit( SingleInit * node ) { 644 VISIT_BODY( node ); 743 VISIT_START( node ); 744 745 visitExpression( node->get_value() ); 746 747 VISIT_END( node ); 645 748 } 646 749
Note: See TracChangeset
for help on using the changeset viewer.