Ignore:
Timestamp:
Aug 18, 2017, 2:23:02 PM (7 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
0dd18fd
Parents:
274ce8c
Message:

New system for formating generated code in CodeGenerator?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ForExprMutator.cc

    r274ce8c r8bafacc  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 15:32:46 2017
    13 // Update Count     : 11
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Aug 18 10:22:00 2017
     13// Update Count     : 12
    1414//
    1515
     
    2121
    2222namespace ControlStruct {
    23         Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {
    24                 std::list<Statement *> &init = ifStmt->get_initialization();
    25                 if ( init.size() == 0 ) {
    26                         return ifStmt;
    27                 } // if
     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                }
    2828
    29                 // create compound statement, move initializers outside, leave _for_ as-is
     29                // Create compound statement, move initializers outside,
     30                // the resut of the original stays as is.
    3031                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
    3132                std::list<Statement *> &stmts = block->get_kids();
    3233                stmts.splice( stmts.end(), init );
    3334
    34                 // add for to the new block
    35                 stmts.push_back( ifStmt );
     35                // Add for to the new block.
     36                stmts.push_back( originalStmt );
    3637                return block;
    3738        }
    3839
     40        Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {
     41                return hoist( ifStmt, ifStmt->initialization );
     42        }
    3943        Statement *ForExprMutator::postmutate( ForStmt *forStmt ) {
    4044                // hoist any initializer declarations to make them C89 (rather than C99)
    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;
     45                return hoist( forStmt, forStmt->initialization );
    5446        }
    5547} // namespace ControlStruct
Note: See TracChangeset for help on using the changeset viewer.