source: src/InitTweak/DeclarationHoister.cc @ d5f1cfc

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since d5f1cfc was d3b7937, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

building runtime library (first attempt)

  • 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// DeclarationHoister.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 May 19 16:33:20 2015
13// Update Count     : 2
14//
15
16#include <list>
17#include <cassert>
18#include <iostream>
19#include <iterator>
20#include <algorithm>
21
22#include "Common/utility.h"
23
24#include "SynTree/Statement.h"
25#include "SynTree/Expression.h"
26#include "SynTree/Declaration.h"
27
28#include "DeclarationHoister.h"
29
30namespace InitTweak {
31        CompoundStmt* DeclarationHoister::mutate( CompoundStmt *compoundStmt ) {
32                typedef std::list<Statement *>::iterator stmt_it;
33                // 1. collect Declaration Statements  in this scope
34                std::list<Statement *> &kids = compoundStmt->get_kids();
35                std::list<Statement *>::iterator result = kids.begin();
36                std::list< stmt_it > decls;
37
38                while ( result !=  kids.end() ) {
39                        result = std::find_if (result, kids.end(), cast_ptr< Statement, DeclStmt > );
40
41                        if ( result != kids.end() ) {
42                                decls.push_back( result );
43                                std::advance( result, 1 );
44                        } // if
45                } // while
46
47                for ( std::list< stmt_it >::reverse_iterator i = decls.rbegin(); i!= decls.rend(); i++ ) {
48                        kids.push_front( **i );
49                        kids.erase( *i );
50                } // for
51
52                return compoundStmt;
53        }
54} // namespace InitTweak
55
56// Local Variables: //
57// tab-width: 4 //
58// mode: c++ //
59// compile-command: "make install" //
60// End: //
Note: See TracBrowser for help on using the repository browser.