Changes in src/Common/PassVisitor.impl.h [33a25f9:9dcb653]
- File:
-
- 1 edited
-
src/Common/PassVisitor.impl.h (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.impl.h
r33a25f9 r9dcb653 66 66 DeclList_t* beforeDecls = visitor.get_beforeDecls(); 67 67 DeclList_t* afterDecls = visitor.get_afterDecls(); 68 SemanticError errors;69 68 70 69 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { … … 74 73 if ( i == decls.end() ) break; 75 74 76 try { 77 // run visitor on declaration 78 maybeAccept( *i, visitor ); 79 } catch( SemanticError &e ) { 80 e.set_location( (*i)->location ); 81 errors.append( e ); 82 } 75 // run mutator on declaration 76 maybeAccept( *i, visitor ); 83 77 84 78 // splice in new declarations before current decl 85 79 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } 86 80 } 87 if ( ! errors.isEmpty() ) {88 throw errors;89 }90 81 } 91 82 … … 95 86 DeclList_t* beforeDecls = mutator.get_beforeDecls(); 96 87 DeclList_t* afterDecls = mutator.get_afterDecls(); 97 SemanticError errors;98 88 99 89 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { … … 102 92 103 93 if ( i == decls.end() ) break; 104 try { 105 // run mutator on declaration 106 *i = maybeMutate( *i, mutator ); 107 } catch( SemanticError &e ) { 108 e.set_location( (*i)->location ); 109 errors.append( e ); 110 } 94 95 // run mutator on declaration 96 *i = maybeMutate( *i, mutator ); 111 97 112 98 // splice in new declarations before current decl 113 99 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } 114 }115 if ( ! errors.isEmpty() ) {116 throw errors;117 100 } 118 101 } … … 183 166 184 167 } catch ( SemanticError &e ) { 185 e.set_location( (*i)->location );186 168 errors.append( e ); 187 169 } … … 293 275 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 294 276 295 // A NOTE ON THE ORDER OF TRAVERSAL296 //297 // Types and typedefs have their base types visited before they are added to the type table. This is ok, since there is298 // no such thing as a recursive type or typedef.299 //300 // typedef struct { T *x; } T; // never allowed301 //302 // for structs/unions, it is possible to have recursion, so the decl should be added as if it's incomplete to begin, the303 // members are traversed, and then the complete type should be added (assuming the type is completed by this particular304 // declaration).305 //306 // struct T { struct T *x; }; // allowed307 //308 // It is important to add the complete type to the symbol table *after* the members/base has been traversed, since that309 // traversal may modify the definition of the type and these modifications should be visible when the symbol table is310 // queried later in this pass.311 //312 // TODO: figure out whether recursive contexts are sensible/possible/reasonable.313 277 314 278 //-------------------------------------------------------------------------- … … 468 432 indexerAddEnum( node ); 469 433 470 // unlike structs, traits, and unions, enums inject their members into the global scope434 // unlike structs, contexts, and unions, enums inject their members into the global scope 471 435 maybeAccept( node->parameters, *this ); 472 436 maybeAccept( node->members , *this ); … … 481 445 indexerAddEnum( node ); 482 446 483 // unlike structs, traits, and unions, enums inject their members into the global scope447 // unlike structs, contexts, and unions, enums inject their members into the global scope 484 448 maybeMutateRef( node->parameters, *this ); 485 449 maybeMutateRef( node->members , *this ); … … 532 496 } 533 497 534 // see A NOTE ON THE ORDER OF TRAVERSAL, above535 // note that assertions come after the type is added to the symtab, since they are not part of the type proper536 // and may depend on the type itself537 498 indexerAddType( node ); 538 499 … … 545 506 546 507 template< typename pass_type > 547 Declaration* PassVisitor< pass_type >::mutate( TypeDecl * node ) {508 TypeDecl * PassVisitor< pass_type >::mutate( TypeDecl * node ) { 548 509 MUTATE_START( node ); 549 510 … … 554 515 } 555 516 556 // see A NOTE ON THE ORDER OF TRAVERSAL, above557 // note that assertions come after the type is added to the symtab, since they are not part of the type proper558 // and may depend on the type itself559 517 indexerAddType( node ); 560 518 … … 563 521 indexerScopedMutate( node->init, *this ); 564 522 565 MUTATE_END( Declaration, node );523 MUTATE_END( TypeDecl, node ); 566 524 } 567 525 … … 683 641 void PassVisitor< pass_type >::visit( IfStmt * node ) { 684 642 VISIT_START( node ); 685 { 686 // if statements introduce a level of scope (for the initialization) 643 644 visitExpression( node->condition ); 645 node->thenPart = visitStatement( node->thenPart ); 646 node->elsePart = visitStatement( node->elsePart ); 647 648 VISIT_END( node ); 649 } 650 651 template< typename pass_type > 652 Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) { 653 MUTATE_START( node ); 654 { 687 655 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 688 acceptAll( node->get_initialization(), *this );689 visitExpression( node->condition );690 node->thenPart = visitStatement( node->thenPart );691 node->elsePart = visitStatement( node->elsePart );692 }693 VISIT_END( node );694 }695 696 template< typename pass_type >697 Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {698 MUTATE_START( node );699 {700 // if statements introduce a level of scope (for the initialization)701 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );702 maybeMutateRef( node->get_initialization(), *this );703 656 node->condition = mutateExpression( node->condition ); 704 657 node->thenPart = mutateStatement ( node->thenPart ); … … 736 689 VISIT_START( node ); 737 690 { 738 // for statements introduce a level of scope (for the initialization)739 691 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 740 692 maybeAccept( node->initialization, *this ); … … 750 702 MUTATE_START( node ); 751 703 { 752 // for statements introduce a level of scope (for the initialization)753 704 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 754 705 maybeMutateRef( node->initialization, *this ); … … 879 830 VISIT_START( node ); 880 831 { 881 // catch statements introduce a level of scope (for the caught exception)882 832 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 883 833 maybeAccept( node->decl, *this ); … … 892 842 MUTATE_START( node ); 893 843 { 894 // catch statements introduce a level of scope (for the caught exception)895 844 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 896 845 maybeMutateRef( node->decl, *this );
Note:
See TracChangeset
for help on using the changeset viewer.