Changes in / [acd738aa:49c9773]
- File:
-
- 1 edited
-
src/Common/PassVisitor.impl.h (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.impl.h
racd738aa r49c9773 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 ); \8 2 9 3 #define MUTATE_START( node ) \ 10 4 call_premutate( node ); \ 11 5 6 12 7 #define MUTATE_END( type, node ) \ 13 8 return call_postmutate< type * >( node ); \ … … 15 10 16 11 #define VISIT_BODY( node ) \ 17 VISIT_START( node ); \12 call_previsit( node ); \ 18 13 Visitor::visit( node ); \ 19 VISIT_END( node ); \14 call_postvisit( node ); \ 20 15 21 16 … … 44 39 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } 45 40 try { 46 (*i)->accept( *this );41 *i = (*i)->accept( *this ); 47 42 } catch ( SemanticError &e ) { 48 43 errors.append( e ); … … 83 78 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 84 79 85 maybeAccept( stmt, *this );80 Statement *newStmt = maybeVisit( stmt, *this ); 86 81 87 82 StmtList_t* beforeStmts = get_beforeStmts(); 88 83 StmtList_t* afterStmts = get_afterStmts(); 89 84 90 if( empty(beforeStmts) && empty(afterStmts) ) { return stmt; }85 if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; } 91 86 92 87 CompoundStmt *compound = new CompoundStmt( noLabels ); 93 88 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } 94 compound->get_kids().push_back( stmt );89 compound->get_kids().push_back( newStmt ); 95 90 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } 96 91 return compound; … … 192 187 } 193 188 194 //--------------------------------------------------------------------------195 // CompoundStmt196 189 template< typename pass_type > 197 190 void PassVisitor< pass_type >::visit( CompoundStmt * node ) { 198 VISIT_START( node ); 199 call_beginScope(); 200 201 visitStatementList( node->get_kids() ); 202 203 call_endScope(); 204 VISIT_END( node ); 191 VISIT_BODY( node ); 205 192 } 206 193 … … 216 203 } 217 204 218 //--------------------------------------------------------------------------219 // ExprStmt220 205 template< typename pass_type > 221 206 void PassVisitor< pass_type >::visit( ExprStmt * node ) { 222 VISIT_START( node ); 223 call_beginScope(); 224 225 visitExpression( node->get_expr() ); 226 227 call_endScope(); 228 VISIT_END( node ); 207 VISIT_BODY( node ); 229 208 } 230 209 … … 243 222 } 244 223 245 //--------------------------------------------------------------------------246 // IfStmt247 224 template< typename pass_type > 248 225 void PassVisitor< pass_type >::visit( IfStmt * 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 ); 226 VISIT_BODY( node ); 256 227 } 257 228 … … 267 238 } 268 239 269 //--------------------------------------------------------------------------270 // WhileStmt271 240 template< typename pass_type > 272 241 void PassVisitor< pass_type >::visit( WhileStmt * node ) { 273 VISIT_START( node ); 274 275 visitExpression( node->get_condition() ); 276 node->set_body( visitStatement( node->get_body() ) ); 277 278 VISIT_END( node ); 242 VISIT_BODY( node ); 279 243 } 280 244 … … 289 253 } 290 254 291 //-------------------------------------------------------------------------- 292 // WhileStmt 255 293 256 template< typename pass_type > 294 257 void PassVisitor< pass_type >::visit( ForStmt * 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 ); 258 VISIT_BODY( node ); 303 259 } 304 260 … … 308 264 309 265 mutateAll( node->get_initialization(), *this ); 310 node->set_condition( mutateExpression( node->get_condition() ) );311 node->set_increment( mutateExpression( node->get_increment() ) );312 node->set_body( mutateStatement( node->get_body() ) );266 node->set_condition( mutateExpression( node->get_condition() ) ); 267 node->set_increment( mutateExpression( node->get_increment() ) ); 268 node->set_body( mutateStatement( node->get_body() ) ); 313 269 314 270 MUTATE_END( Statement, node ); 315 271 } 316 272 317 //--------------------------------------------------------------------------318 // SwitchStmt319 273 template< typename pass_type > 320 274 void PassVisitor< pass_type >::visit( SwitchStmt * node ) { 321 VISIT_START( node ); 322 323 visitExpression( node->get_condition() ); 324 visitStatementList( node->get_statements() ); 325 326 VISIT_END( node ); 275 VISIT_BODY( node ); 327 276 } 328 277 … … 337 286 } 338 287 339 //--------------------------------------------------------------------------340 // SwitchStmt341 288 template< typename pass_type > 342 289 void PassVisitor< pass_type >::visit( CaseStmt * node ) { 343 VISIT_START( node ); 344 345 visitExpression( node->get_condition() ); 346 visitStatementList( node->get_statements() ); 347 348 VISIT_END( node ); 290 VISIT_BODY( node ); 349 291 } 350 292 … … 364 306 } 365 307 366 //--------------------------------------------------------------------------367 // ReturnStmt368 308 template< typename pass_type > 369 309 void PassVisitor< pass_type >::visit( ReturnStmt * node ) { 370 VISIT_START( node ); 371 372 visitExpression( node->get_expr() ); 373 374 VISIT_END( node ); 310 VISIT_BODY( node ); 375 311 } 376 312 … … 384 320 } 385 321 386 //--------------------------------------------------------------------------387 // TryStmt388 322 template< typename pass_type > 389 323 void PassVisitor< pass_type >::visit( TryStmt * node ) { 390 VISIT_START( node ); 391 392 maybeAccept( node->get_block(), *this ); 393 acceptAll( node->get_catchers(), *this ); 394 395 VISIT_END( node ); 324 VISIT_BODY( node ); 396 325 } 397 326 … … 406 335 } 407 336 408 //--------------------------------------------------------------------------409 // CatchStmt410 337 template< typename pass_type > 411 338 void PassVisitor< pass_type >::visit( CatchStmt * 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 ); 339 VISIT_BODY( node ); 418 340 } 419 341 … … 453 375 } 454 376 455 //--------------------------------------------------------------------------456 // UntypedExpr457 377 template< typename pass_type > 458 378 void PassVisitor< pass_type >::visit( UntypedExpr * node ) { 459 VISIT_START( node ); 460 461 for ( auto expr : node->get_args() ) { 462 visitExpression( expr ); 463 } 464 465 VISIT_END( node ); 379 VISIT_BODY( node ); 466 380 } 467 381 … … 622 536 } 623 537 624 //--------------------------------------------------------------------------625 // UntypedExpr626 538 template< typename pass_type > 627 539 void PassVisitor< pass_type >::visit( StmtExpr * 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 ); 540 VISIT_BODY( node ); 638 541 } 639 542 … … 737 640 } 738 641 739 //--------------------------------------------------------------------------740 // UntypedExpr741 642 template< typename pass_type > 742 643 void PassVisitor< pass_type >::visit( SingleInit * node ) { 743 VISIT_START( node ); 744 745 visitExpression( node->get_value() ); 746 747 VISIT_END( node ); 644 VISIT_BODY( node ); 748 645 } 749 646
Note:
See TracChangeset
for help on using the changeset viewer.