source: src/ControlStruct/ForExprMutator.cc @ fa5e1aa5

Last change on this file since fa5e1aa5 was 3b0bc16, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

change class name WhileStmt? to WhileDoStmt?, add else clause to WhileDoStmt? and ForStmt?, change names thenPart/ElsePart to then/else_

  • Property mode set to 100644
File size: 1.7 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 : Tue Feb  1 09:26:12 2022
13// Update Count     : 16
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 * 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.
31                CompoundStmt * block = new CompoundStmt();
32                std::list<Statement *> & stmts = block->get_kids();
33                stmts.splice( stmts.end(), init );
34
35                // Add for to the new block.
36                stmts.push_back( originalStmt );
37                return block;
38        }
39
40        Statement * ForExprMutator::postmutate( IfStmt * ifStmt ) {
41                return hoist( ifStmt, ifStmt->initialization );
42        }
43        Statement * ForExprMutator::postmutate( ForStmt * forStmt ) {
44                // hoist any initializer declarations to make them C89 (rather than C99)
45                return hoist( forStmt, forStmt->initialization );
46        }
47        Statement * ForExprMutator::postmutate( WhileDoStmt * whileDoStmt ) {
48                return hoist( whileDoStmt, whileDoStmt->initialization );
49        }
50} // namespace ControlStruct
51
52// Local Variables: //
53// tab-width: 4 //
54// mode: c++ //
55// compile-command: "make install" //
56// End: //
Note: See TracBrowser for help on using the repository browser.