Changeset 974906e2 for src/InitTweak
- Timestamp:
- Jan 11, 2016, 2:48:05 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- a56767c
- Parents:
- 1e9d87b
- Location:
- src/InitTweak
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitModel.cc
r1e9d87b r974906e2 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // InitModel.cc -- 7 // InitModel.cc -- 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T ue May 19 16:37:08 201513 // Update Count : 111 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 13:38:46 2016 13 // Update Count : 5 14 14 // 15 15 … … 198 198 assert(init == 0 && single != 0); 199 199 std::list< Expression * > empty; 200 init = new SingleInit( single->get_expr(), empty );200 init = new SingleInit( single->get_expr(), empty, false ); // cannot be constructed 201 201 return; 202 202 } … … 214 214 } // if 215 215 216 init = new ListInit( contents ); 216 std::list< Expression * > desig; 217 init = new ListInit( contents, desig, false ); // cannot be constructed 217 218 return; 218 219 } -
src/InitTweak/RemoveInit.cc
r1e9d87b r974906e2 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 11:34:33 2016 13 // Update Count : 23 14 // 15 12 // Last Modified On : Mon Jan 11 14:41:26 2016 13 // Update Count : 118 14 // 15 16 #include <stack> 17 #include <list> 16 18 #include "RemoveInit.h" 17 19 #include "SynTree/Declaration.h" … … 31 33 public: 32 34 RemoveInit(); 33 virtual ObjectDecl * mutate( ObjectDecl *objDecl);35 virtual ObjectDecl * mutate( ObjectDecl *objDecl ); 34 36 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ); 35 37 36 38 virtual Statement * mutate( ReturnStmt * returnStmt ); 37 38 virtual CompoundStmt * mutate(CompoundStmt * compoundStmt);39 39 40 40 protected: … … 44 44 }; 45 45 46 class CtorDtor : public GenPoly::PolyMutator { 47 public: 48 // CtorDtor(); 49 50 virtual ObjectDecl * mutate( ObjectDecl * ); 51 52 virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ); 53 54 protected: 55 typedef std::map< std::string, DeclarationWithType * > MMMMAP; 56 std::stack< MMMMAP > constructedObjects; 57 58 // to be added before block ends - use push_front so order is correct 59 std::list< Statement * > destructorStmts; 60 }; 61 46 62 void tweak( std::list< Declaration * > translationUnit ) { 47 63 RemoveInit remover; 64 CtorDtor ctordtor; 48 65 mutateAll( translationUnit, remover ); 66 mutateAll( translationUnit, ctordtor ); 49 67 } 50 68 51 69 RemoveInit::RemoveInit() : tempNamer( "_retVal" ) {} 52 53 CompoundStmt *RemoveInit::mutate(CompoundStmt *compoundStmt) {54 mutateStatementList( compoundStmt->get_kids() );55 return compoundStmt;56 }57 70 58 71 // in the case where an object has an initializer and a polymorphic type, insert an assignment immediately after the … … 101 114 return decl; 102 115 } 116 117 bool tryConstruct( ObjectDecl * objDecl ) { 118 // xxx - handle designations 119 return objDecl->get_init() == NULL || 120 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() ); 121 } 122 123 ExprStmt * makeCtorDtorStmt( std::string name, ObjectDecl * objDecl, std::list< Expression * > args ) { 124 UntypedExpr * expr = new UntypedExpr( new NameExpr( name ) ); 125 expr->get_args().push_back( new VariableExpr( objDecl ) ); 126 expr->get_args().splice( expr->get_args().end(), args ); 127 return new ExprStmt( noLabels, expr ); 128 } 129 130 // InitExpander ctor/dtor being marked as weak symbols 131 // this is causing a bug - Rodolfo's InitExpander is being constructed and destructed 132 // with different fields, which causes a segfault 133 134 class InitExpander : public Visitor { 135 public: 136 InitExpander() {} 137 // ~InitExpander() {} 138 virtual void visit( SingleInit * singleInit ); 139 virtual void visit( ListInit * listInit ); 140 std::list< Expression * > argList; 141 }; 142 143 void InitExpander::visit( SingleInit * singleInit ) { 144 argList.push_back( singleInit->get_value()->clone() ); 145 } 146 147 void InitExpander::visit( ListInit * listInit ) { 148 // xxx - for now, assume no nested list inits 149 std::list<Initializer*>::iterator it = listInit->begin_initializers(); 150 for ( ; it != listInit->end_initializers(); ++it ) { 151 (*it)->accept( *this ); 152 } 153 } 154 155 std::list< Expression * > makeInitList( Initializer * init ) { 156 if ( init ) { 157 InitExpander expander; 158 // init->accept( expander ); 159 // std::list< Expression * > l = expander.argList; 160 std::list< Expression * > l; 161 return l; 162 } else { 163 std::list< Expression * > l; 164 return l; 165 } 166 } 167 168 ObjectDecl * CtorDtor::mutate( ObjectDecl * objDecl ) { 169 // hands off if designated or if @= 170 if ( tryConstruct( objDecl ) ) { 171 ExprStmt * ctor = makeCtorDtorStmt( "?{}", objDecl, makeInitList( objDecl->get_init() ) ); 172 ExprStmt * dtor = makeCtorDtorStmt( "^?{}", objDecl, std::list< Expression * >() ); 173 174 // set_ctor... 175 // need to remember init expression, in case no ctors exist 176 // if ctor does exist, want to use ctor stmt instead of init 177 objDecl->set_ctor( ctor ); 178 destructorStmts.push_front( dtor ); 179 } 180 return objDecl; 181 } 182 183 CompoundStmt * CtorDtor::mutate( CompoundStmt * compoundStmt ) { 184 CompoundStmt * ret = PolyMutator::mutate( compoundStmt ); 185 std::list< Statement * > &statements = ret->get_kids(); 186 if ( ! destructorStmts.empty() ) { 187 statements.splice( statements.end(), destructorStmts ); 188 } // if 189 return ret; 190 } 191 192 193 103 194 } // namespace InitTweak 104 195
Note: See TracChangeset
for help on using the changeset viewer.