| [51587aa] | 1 | //
 | 
|---|
 | 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
 | 
|---|
 | 3 | //
 | 
|---|
 | 4 | // The contents of this file are covered under the licence agreement in the
 | 
|---|
 | 5 | // file "LICENCE" distributed with Cforall.
 | 
|---|
 | 6 | //
 | 
|---|
| [0db6fc0] | 7 | // ForExprMutator.cc --
 | 
|---|
| [51587aa] | 8 | //
 | 
|---|
| [843054c2] | 9 | // Author           : Rodolfo G. Esteves
 | 
|---|
| [51587aa] | 10 | // Created On       : Mon May 18 07:44:20 2015
 | 
|---|
| [8bafacc] | 11 | // Last Modified By : Andrew Beach
 | 
|---|
 | 12 | // Last Modified On : Fri Aug 18 10:22:00 2017
 | 
|---|
 | 13 | // Update Count     : 12
 | 
|---|
| [51587aa] | 14 | //
 | 
|---|
| [a08ba92] | 15 | 
 | 
|---|
| [d180746] | 16 | #include <list>                 // for list, _List_iterator, list<>::iterator
 | 
|---|
 | 17 | 
 | 
|---|
| [51b73452] | 18 | #include "ForExprMutator.h"
 | 
|---|
| [d180746] | 19 | #include "SynTree/Label.h"      // for Label
 | 
|---|
 | 20 | #include "SynTree/Statement.h"  // for Statement (ptr only), ForStmt, Compou...
 | 
|---|
| [51b73452] | 21 | 
 | 
|---|
 | 22 | namespace ControlStruct {
 | 
|---|
| [8bafacc] | 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 |                 }
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 |                 // Create compound statement, move initializers outside,
 | 
|---|
 | 30 |                 // the resut of the original stays as is.
 | 
|---|
| [ba3706f] | 31 |                 CompoundStmt *block = new CompoundStmt();
 | 
|---|
| [6d49ea3] | 32 |                 std::list<Statement *> &stmts = block->get_kids();
 | 
|---|
 | 33 |                 stmts.splice( stmts.end(), init );
 | 
|---|
 | 34 | 
 | 
|---|
| [8bafacc] | 35 |                 // Add for to the new block.
 | 
|---|
 | 36 |                 stmts.push_back( originalStmt );
 | 
|---|
| [6d49ea3] | 37 |                 return block;
 | 
|---|
 | 38 |         }
 | 
|---|
 | 39 | 
 | 
|---|
| [8bafacc] | 40 |         Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {
 | 
|---|
 | 41 |                 return hoist( ifStmt, ifStmt->initialization );
 | 
|---|
 | 42 |         }
 | 
|---|
| [0db6fc0] | 43 |         Statement *ForExprMutator::postmutate( ForStmt *forStmt ) {
 | 
|---|
 | 44 |                 // hoist any initializer declarations to make them C89 (rather than C99)
 | 
|---|
| [8bafacc] | 45 |                 return hoist( forStmt, forStmt->initialization );
 | 
|---|
| [a08ba92] | 46 |         }
 | 
|---|
| [51b73452] | 47 | } // namespace ControlStruct
 | 
|---|
| [a08ba92] | 48 | 
 | 
|---|
| [51587aa] | 49 | // Local Variables: //
 | 
|---|
 | 50 | // tab-width: 4 //
 | 
|---|
 | 51 | // mode: c++ //
 | 
|---|
 | 52 | // compile-command: "make install" //
 | 
|---|
 | 53 | // End: //
 | 
|---|