source: src/ControlStruct/ForExprMutator.cc @ c69adb7

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since c69adb7 was 145f1fc, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

modified ForStmt? to have a list of statements for the initialization portion, and reverted to hoisting the initialization

  • Property mode set to 100644
File size: 1.5 KB
Line 
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//
7// ForExprMutator.cc --
8//
9// Author           : Rodolfo G. Esteves
10// 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
14//
15
16#include "SynTree/Mutator.h"
17#include "SynTree/Statement.h"
18#include "ForExprMutator.h"
19
20namespace ControlStruct {
21        Statement *ForExprMutator::mutate( ForStmt *forStmt ) {
22                // recurse down all nest for loops to hoist any initializer declarations to make them C89 (rather than C99)
23                forStmt->set_body( forStmt->get_body()->acceptMutator( *this ) );
24
25                std::list<Statement *> &init = forStmt->get_initialization(); 
26                if ( init.size() == 0 ) {
27                        return forStmt;
28                } // if
29
30                // create compound statement, move initializers outside, leave _for_ as-is
31                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
32                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
36
37                // add for to the new block
38                stmts.push_back( forStmt );
39                forStmt->set_initialization( std::list<Statement *>() );
40                return block;
41
42                return forStmt;
43        }
44} // namespace ControlStruct
45
46// Local Variables: //
47// tab-width: 4 //
48// mode: c++ //
49// compile-command: "make install" //
50// End: //
Note: See TracBrowser for help on using the repository browser.