Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ForExprMutator.cc

    r8bafacc r6d49ea3  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug 18 10:22:00 2017
    13 // Update Count     : 12
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Aug 17 15:32:46 2017
     13// Update Count     : 11
    1414//
    1515
     
    2121
    2222namespace ControlStruct {
    23         Statement *hoist( Statement *originalStmt, std::list<Statement *> &init ) {
    24                 // If no hoisting is needed, skip:
    25                 if ( 0 == init.size() ) {
    26                         return originalStmt;
    27                 }
     23        Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {
     24                std::list<Statement *> &init = ifStmt->get_initialization();
     25                if ( init.size() == 0 ) {
     26                        return ifStmt;
     27                } // if
    2828
    29                 // Create compound statement, move initializers outside,
    30                 // the resut of the original stays as is.
     29                // create compound statement, move initializers outside, leave _for_ as-is
    3130                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
    3231                std::list<Statement *> &stmts = block->get_kids();
    3332                stmts.splice( stmts.end(), init );
    3433
    35                 // Add for to the new block.
    36                 stmts.push_back( originalStmt );
     34                // add for to the new block
     35                stmts.push_back( ifStmt );
    3736                return block;
    3837        }
    3938
    40         Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {
    41                 return hoist( ifStmt, ifStmt->initialization );
    42         }
    4339        Statement *ForExprMutator::postmutate( ForStmt *forStmt ) {
    4440                // hoist any initializer declarations to make them C89 (rather than C99)
    45                 return hoist( forStmt, forStmt->initialization );
     41                std::list<Statement *> &init = forStmt->get_initialization();
     42                if ( init.size() == 0 ) {
     43                        return forStmt;
     44                } // if
     45
     46                // create compound statement, move initializers outside, leave _for_ as-is
     47                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
     48                std::list<Statement *> &stmts = block->get_kids();
     49                stmts.splice( stmts.end(), init );
     50
     51                // add for to the new block
     52                stmts.push_back( forStmt );
     53                return block;
    4654        }
    4755} // namespace ControlStruct
Note: See TracChangeset for help on using the changeset viewer.