Ignore:
Timestamp:
Aug 17, 2017, 5:37:20 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
274ce8c
Parents:
936e9f4
Message:

second attempt, add declarations into if conditional

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ForExprMutator.cc

    r936e9f4 r6d49ea3  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Jul 14 12:14:44 2015
    13 // Update Count     : 10
     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 *ForExprMutator::postmutate( IfStmt *ifStmt ) {
     24                std::list<Statement *> &init = ifStmt->get_initialization();
     25                if ( init.size() == 0 ) {
     26                        return ifStmt;
     27                } // if
     28
     29                // create compound statement, move initializers outside, leave _for_ as-is
     30                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
     31                std::list<Statement *> &stmts = block->get_kids();
     32                stmts.splice( stmts.end(), init );
     33
     34                // add for to the new block
     35                stmts.push_back( ifStmt );
     36                return block;
     37        }
     38
    2339        Statement *ForExprMutator::postmutate( ForStmt *forStmt ) {
    2440                // hoist any initializer declarations to make them C89 (rather than C99)
     
    3147                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
    3248                std::list<Statement *> &stmts = block->get_kids();
    33                 for ( std::list<Statement *>::iterator it = init.begin(); it != init.end(); ++it ) {
    34                         stmts.push_back( *it );
    35                 }       // for
     49                stmts.splice( stmts.end(), init );
    3650
    3751                // add for to the new block
    3852                stmts.push_back( forStmt );
    39                 forStmt->set_initialization( std::list<Statement *>() );
    4053                return block;
    4154        }
Note: See TracChangeset for help on using the changeset viewer.