Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/DeclMutator.cc

    rb0b958a rdbd8652  
    2424        }
    2525
    26         DeclMutator::DeclMutator() : Mutator(), declsToAdd(1) {}
     26        DeclMutator::DeclMutator() : Mutator(), declsToAdd(1), declsToAddAfter(1) {}
    2727
    2828        DeclMutator::~DeclMutator() {}
    2929       
    3030        void DeclMutator::mutateDeclarationList( std::list< Declaration* > &decls ) {
    31                 for ( std::list< Declaration* >::iterator decl = decls.begin(); decl != decls.end(); ++decl ) {
     31                for ( std::list< Declaration* >::iterator decl = decls.begin(); ; ++decl ) {
     32                        // splice in new declarations after previous decl
     33                        decls.splice( decl, declsToAddAfter.back() );
     34
     35                        if ( decl == decls.end() ) break;
     36                       
    3237                        // run mutator on declaration
    3338                        *decl = maybeMutate( *decl, *this );
     
    3944
    4045        void DeclMutator::doBeginScope() {
    41                 // add new decl list for inside of scope
     46                // add new decl lists for inside of scope
    4247                declsToAdd.resize( declsToAdd.size()+1 );
     48                declsToAddAfter.resize( declsToAddAfter.size()+1 );
    4349        }
    4450
     
    4955                newBack->splice( newBack->end(), *back );
    5056                declsToAdd.pop_back();
     57               
     58                back = declsToAddAfter.rbegin();
     59                newBack = back + 1;
     60                newBack->splice( newBack->end(), *back );
     61                declsToAddAfter.pop_back();
    5162        }
    5263
     
    6172                stmt = maybeMutate( stmt, *this );
    6273                // return if no declarations to add
    63                 if ( declsToAdd.back().empty() ) return stmt;
     74                if ( declsToAdd.back().empty() && declsToAddAfter.back().empty() ) {
     75                        doEndScope();
     76                        return stmt;
     77                }
    6478
    6579                // otherwise add declarations to new compound statement
     
    7185                declsToAdd.back().clear();
    7286
     87                // add mutated statement
     88                compound->get_kids().push_back( stmt );
     89
     90                // add declarations after to new compound statement
     91                for ( std::list< Declaration* >::iterator decl = declsToAddAfter.back().begin(); decl != declsToAddAfter.back().end(); ++decl ) {
     92                        DeclStmt *declStmt = new DeclStmt( noLabels, *decl );
     93                        compound->get_kids().push_back( declStmt );
     94                }
     95                declsToAddAfter.back().clear();
     96
    7397                doEndScope();
    74 
    75                 // add mutated statement and return
    76                 compound->get_kids().push_back( stmt );
    7798                return compound;
    7899        }
     
    80101        void DeclMutator::mutateStatementList( std::list< Statement* > &stmts ) {
    81102                doBeginScope();
     103
    82104               
    83                 for ( std::list< Statement* >::iterator stmt = stmts.begin(); stmt != stmts.end(); ++stmt ) {
     105                for ( std::list< Statement* >::iterator stmt = stmts.begin(); ; ++stmt ) {
     106                        // add any new declarations after the previous statement
     107                        for ( std::list< Declaration* >::iterator decl = declsToAddAfter.back().begin(); decl != declsToAddAfter.back().end(); ++decl ) {
     108                                DeclStmt *declStmt = new DeclStmt( noLabels, *decl );
     109                                stmts.insert( stmt, declStmt );
     110                        }
     111                        declsToAddAfter.back().clear();
     112
     113                        if ( stmt == stmts.end() ) break;
     114                       
    84115                        // run mutator on statement
    85116                        *stmt = maybeMutate( *stmt, *this );
     
    92123                        declsToAdd.back().clear();
    93124                }
    94 
     125               
    95126                doEndScope();
    96127        }
     
    98129        void DeclMutator::addDeclaration( Declaration *decl ) {
    99130                declsToAdd.back().push_back( decl );
     131        }
     132
     133        void DeclMutator::addDeclarationAfter( Declaration *decl ) {
     134                declsToAddAfter.back().push_back( decl );
    100135        }
    101136
Note: See TracChangeset for help on using the changeset viewer.