source: translator/InitTweak/RemoveInit.cc @ 51587aa

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

licencing: fourth 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// XXX.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By :
12// Last Modified On :
13// Update Count     : 0
14//
15#include "RemoveInit.h"
16#include "SynTree/Declaration.h"
17#include "SynTree/Type.h"
18#include "SynTree/Expression.h"
19#include "SynTree/Statement.h"
20#include "SynTree/Initializer.h"
21#include "SynTree/Mutator.h"
22
23namespace InitTweak {
24
25namespace {
26const std::list<Label> noLabels;
27}
28
29void tweak( std::list< Declaration * > translationUnit ) {
30  RemoveInit remover;
31  mutateAll( translationUnit, remover );
32}
33
34void 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    }
39    *i = (*i)->acceptMutator( *this );
40  }
41  if ( ! stmtsToAddAfter.empty() ) {
42    statements.splice( statements.end(), stmtsToAddAfter );
43  }
44}
45
46CompoundStmt *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
54ObjectDecl *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    }
62  }
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.