Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.impl.h

    r33a25f9 r9dcb653  
    6666        DeclList_t* beforeDecls = visitor.get_beforeDecls();
    6767        DeclList_t* afterDecls  = visitor.get_afterDecls();
    68         SemanticError errors;
    6968
    7069        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
     
    7473                if ( i == decls.end() ) break;
    7574
    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 );
    8377
    8478                // splice in new declarations before current decl
    8579                if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
    8680        }
    87         if ( ! errors.isEmpty() ) {
    88                 throw errors;
    89         }
    9081}
    9182
     
    9586        DeclList_t* beforeDecls = mutator.get_beforeDecls();
    9687        DeclList_t* afterDecls  = mutator.get_afterDecls();
    97         SemanticError errors;
    9888
    9989        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
     
    10292
    10393                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 );
    11197
    11298                // splice in new declarations before current decl
    11399                if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
    114         }
    115         if ( ! errors.isEmpty() ) {
    116                 throw errors;
    117100        }
    118101}
     
    183166
    184167                } catch ( SemanticError &e ) {
    185                         e.set_location( (*i)->location );
    186168                        errors.append( e );
    187169                }
     
    293275//------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    294276
    295 // A NOTE ON THE ORDER OF TRAVERSAL
    296 //
    297 // Types and typedefs have their base types visited before they are added to the type table.  This is ok, since there is
    298 // no such thing as a recursive type or typedef.
    299 //
    300 //             typedef struct { T *x; } T; // never allowed
    301 //
    302 // for structs/unions, it is possible to have recursion, so the decl should be added as if it's incomplete to begin, the
    303 // members are traversed, and then the complete type should be added (assuming the type is completed by this particular
    304 // declaration).
    305 //
    306 //             struct T { struct T *x; }; // allowed
    307 //
    308 // It is important to add the complete type to the symbol table *after* the members/base has been traversed, since that
    309 // traversal may modify the definition of the type and these modifications should be visible when the symbol table is
    310 // queried later in this pass.
    311 //
    312 // TODO: figure out whether recursive contexts are sensible/possible/reasonable.
    313277
    314278//--------------------------------------------------------------------------
     
    468432        indexerAddEnum( node );
    469433
    470         // unlike structs, traits, and unions, enums inject their members into the global scope
     434        // unlike structs, contexts, and unions, enums inject their members into the global scope
    471435        maybeAccept( node->parameters, *this );
    472436        maybeAccept( node->members   , *this );
     
    481445        indexerAddEnum( node );
    482446
    483         // unlike structs, traits, and unions, enums inject their members into the global scope
     447        // unlike structs, contexts, and unions, enums inject their members into the global scope
    484448        maybeMutateRef( node->parameters, *this );
    485449        maybeMutateRef( node->members   , *this );
     
    532496        }
    533497
    534         // see A NOTE ON THE ORDER OF TRAVERSAL, above
    535         // note that assertions come after the type is added to the symtab, since they are not part of the type proper
    536         // and may depend on the type itself
    537498        indexerAddType( node );
    538499
     
    545506
    546507template< typename pass_type >
    547 Declaration * PassVisitor< pass_type >::mutate( TypeDecl * node ) {
     508TypeDecl * PassVisitor< pass_type >::mutate( TypeDecl * node ) {
    548509        MUTATE_START( node );
    549510
     
    554515        }
    555516
    556         // see A NOTE ON THE ORDER OF TRAVERSAL, above
    557         // note that assertions come after the type is added to the symtab, since they are not part of the type proper
    558         // and may depend on the type itself
    559517        indexerAddType( node );
    560518
     
    563521        indexerScopedMutate( node->init, *this );
    564522
    565         MUTATE_END( Declaration, node );
     523        MUTATE_END( TypeDecl, node );
    566524}
    567525
     
    683641void PassVisitor< pass_type >::visit( IfStmt * node ) {
    684642        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
     651template< typename pass_type >
     652Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) {
     653        MUTATE_START( node );
     654        {
    687655                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 );
    703656                node->condition = mutateExpression( node->condition );
    704657                node->thenPart  = mutateStatement ( node->thenPart  );
     
    736689        VISIT_START( node );
    737690        {
    738                 // for statements introduce a level of scope (for the initialization)
    739691                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    740692                maybeAccept( node->initialization, *this );
     
    750702        MUTATE_START( node );
    751703        {
    752                 // for statements introduce a level of scope (for the initialization)
    753704                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    754705                maybeMutateRef( node->initialization, *this );
     
    879830        VISIT_START( node );
    880831        {
    881                 // catch statements introduce a level of scope (for the caught exception)
    882832                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    883833                maybeAccept( node->decl, *this );
     
    892842        MUTATE_START( node );
    893843        {
    894                 // catch statements introduce a level of scope (for the caught exception)
    895844                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    896845                maybeMutateRef( node->decl, *this );
Note: See TracChangeset for help on using the changeset viewer.