source: src/InitTweak/RemoveInit.cc @ 0423f25

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

licencing: seventh groups of files

  • Property mode set to 100644
File size: 2.2 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// RemoveInit.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:39:32 2015
13// Update Count     : 1
14//
15
16#include "RemoveInit.h"
17#include "SynTree/Declaration.h"
18#include "SynTree/Type.h"
19#include "SynTree/Expression.h"
20#include "SynTree/Statement.h"
21#include "SynTree/Initializer.h"
22#include "SynTree/Mutator.h"
23
24namespace InitTweak {
25        namespace {
26                const std::list<Label> noLabels;
27        }
28
29        void tweak( std::list< Declaration * > translationUnit ) {
30                RemoveInit remover;
31                mutateAll( translationUnit, remover );
32        }
33
34        void RemoveInit::mutateStatementList( std::list< Statement* > &statements ) {
35                for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
36                        if ( ! stmtsToAddAfter.empty() ) {
37                                statements.splice( i, stmtsToAddAfter );
38                        } // if
39                        *i = (*i)->acceptMutator( *this );
40                } // for
41                if ( ! stmtsToAddAfter.empty() ) {
42                        statements.splice( statements.end(), stmtsToAddAfter );
43                } // if
44        }
45
46        CompoundStmt *RemoveInit::mutate(CompoundStmt *compoundStmt) {
47                mutateStatementList( compoundStmt->get_kids() );
48                return compoundStmt;
49        }
50
51// in the case where an object has an initializer and a polymorphic type, insert an assignment
52// immediately after the declaration. This will (seemingly) cause the later phases to do the right
53// thing with the assignment
54        ObjectDecl *RemoveInit::mutate( ObjectDecl *objDecl ) {
55                if (objDecl->get_init() && dynamic_cast<TypeInstType*>(objDecl->get_type())) {
56                        if (SingleInit * single = dynamic_cast<SingleInit*>(objDecl->get_init())) {
57                                UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
58                                assign->get_args().push_back( new AddressExpr (new NameExpr( objDecl->get_name() ) ) );
59                                assign->get_args().push_back( single->get_value()->clone() );
60                                stmtsToAddAfter.push_back(new ExprStmt(noLabels, assign));
61                        } // if
62                } // if
63                return objDecl;
64        }
65} // namespace InitTweak
66
67// Local Variables: //
68// tab-width: 4 //
69// mode: c++ //
70// compile-command: "make install" //
71// End: //
Note: See TracBrowser for help on using the repository browser.