[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
|
---|
[6d49ea3] | 11 | // Last Modified By : Peter A. Buhr
|
---|
| 12 | // Last Modified On : Thu Aug 17 15:32:46 2017
|
---|
| 13 | // Update Count : 11
|
---|
[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 {
|
---|
[6d49ea3] | 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 |
|
---|
[0db6fc0] | 39 | Statement *ForExprMutator::postmutate( ForStmt *forStmt ) {
|
---|
| 40 | // hoist any initializer declarations to make them C89 (rather than C99)
|
---|
| 41 | std::list<Statement *> &init = forStmt->get_initialization();
|
---|
[145f1fc] | 42 | if ( init.size() == 0 ) {
|
---|
| 43 | return forStmt;
|
---|
[a08ba92] | 44 | } // if
|
---|
[c11e31c] | 45 |
|
---|
[145f1fc] | 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();
|
---|
[6d49ea3] | 49 | stmts.splice( stmts.end(), init );
|
---|
[145f1fc] | 50 |
|
---|
| 51 | // add for to the new block
|
---|
| 52 | stmts.push_back( forStmt );
|
---|
| 53 | return block;
|
---|
[a08ba92] | 54 | }
|
---|
[51b73452] | 55 | } // namespace ControlStruct
|
---|
[a08ba92] | 56 |
|
---|
[51587aa] | 57 | // Local Variables: //
|
---|
| 58 | // tab-width: 4 //
|
---|
| 59 | // mode: c++ //
|
---|
| 60 | // compile-command: "make install" //
|
---|
| 61 | // End: //
|
---|