source: src/ControlStruct/ForExprMutator.cc @ 6d49ea3

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 6d49ea3 was 6d49ea3, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

second attempt, add declarations into if conditional

  • Property mode set to 100644
File size: 1.8 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 : Peter A. Buhr
12// Last Modified On : Thu Aug 17 15:32:46 2017
13// Update Count     : 11
14//
15
16#include <list>                 // for list, _List_iterator, list<>::iterator
17
18#include "ForExprMutator.h"
19#include "SynTree/Label.h"      // for Label
20#include "SynTree/Statement.h"  // for Statement (ptr only), ForStmt, Compou...
21
22namespace 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
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();
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;
54        }
55} // namespace ControlStruct
56
57// Local Variables: //
58// tab-width: 4 //
59// mode: c++ //
60// compile-command: "make install" //
61// End: //
Note: See TracBrowser for help on using the repository browser.