Changeset 8bafacc for src/ControlStruct
- Timestamp:
- Aug 18, 2017, 2:23:02 PM (8 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ForExprMutator.cc
r274ce8c r8bafacc 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Aug 17 15:32:46201713 // Update Count : 1 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 18 10:22:00 2017 13 // Update Count : 12 14 14 // 15 15 … … 21 21 22 22 namespace ControlStruct { 23 Statement * ForExprMutator::postmutate( IfStmt *ifStmt ) {24 std::list<Statement *> &init = ifStmt->get_initialization();25 if ( init.size() == 0) {26 return ifStmt;27 } // if23 Statement *hoist( Statement *originalStmt, std::list<Statement *> &init ) { 24 // If no hoisting is needed, skip: 25 if ( 0 == init.size() ) { 26 return originalStmt; 27 } 28 28 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. 30 31 CompoundStmt *block = new CompoundStmt( std::list< Label >() ); 31 32 std::list<Statement *> &stmts = block->get_kids(); 32 33 stmts.splice( stmts.end(), init ); 33 34 34 // add for to the new block35 stmts.push_back( ifStmt );35 // Add for to the new block. 36 stmts.push_back( originalStmt ); 36 37 return block; 37 38 } 38 39 40 Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) { 41 return hoist( ifStmt, ifStmt->initialization ); 42 } 39 43 Statement *ForExprMutator::postmutate( ForStmt *forStmt ) { 40 44 // 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 ); 54 46 } 55 47 } // namespace ControlStruct
Note: See TracChangeset
for help on using the changeset viewer.