Changeset 1e9d87b for src/InitTweak
- Timestamp:
- Jan 7, 2016, 11:43:10 AM (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:
- 974906e2
- Parents:
- 083cf31
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/RemoveInit.cc
r083cf31 r1e9d87b 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // RemoveInit.cc -- 7 // RemoveInit.cc -- 8 8 // 9 9 // Author : Rob Schluntz 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T ue Dec 15 15:37:26 201513 // Update Count : 1511 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 11:34:33 2016 13 // Update Count : 23 14 14 // 15 15 … … 21 21 #include "SynTree/Initializer.h" 22 22 #include "SynTree/Mutator.h" 23 #include "GenPoly/PolyMutator.h" 23 24 24 25 namespace InitTweak { … … 26 27 const std::list<Label> noLabels; 27 28 } 28 29 class RemoveInit : public Mutator {29 30 class RemoveInit : public GenPoly::PolyMutator { 30 31 public: 31 32 RemoveInit(); … … 34 35 35 36 virtual Statement * mutate( ReturnStmt * returnStmt ); 36 37 37 38 virtual CompoundStmt * mutate(CompoundStmt * compoundStmt); 38 39 39 40 protected: 40 std::list< Statement* > stmtsToAddBefore;41 std::list< Statement* > stmtsToAddAfter;42 void mutateStatementList( std::list< Statement* > &statements );43 44 41 std::list<DeclarationWithType*> returnVals; 45 42 UniqueName tempNamer; … … 53 50 54 51 RemoveInit::RemoveInit() : tempNamer( "_retVal" ) {} 55 56 void RemoveInit::mutateStatementList( std::list< Statement* > &statements ) {57 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {58 if ( ! stmtsToAddAfter.empty() ) {59 statements.splice( i, stmtsToAddAfter );60 } // if61 *i = (*i)->acceptMutator( *this );62 if ( ! stmtsToAddBefore.empty() ) {63 statements.splice( i, stmtsToAddBefore );64 } // if65 } // for66 if ( ! stmtsToAddAfter.empty() ) {67 statements.splice( statements.end(), stmtsToAddAfter );68 } // if69 }70 52 71 53 CompoundStmt *RemoveInit::mutate(CompoundStmt *compoundStmt) { … … 95 77 if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue() ) { 96 78 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), 0 ); 97 stmtsToAdd Before.push_back( new DeclStmt( noLabels, newObj ) );98 79 stmtsToAdd.push_back( new DeclStmt( noLabels, newObj ) ); 80 99 81 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 100 82 assign->get_args().push_back( new AddressExpr (new NameExpr( newObj->get_name() ) ) ); 101 83 assign->get_args().push_back( returnStmt->get_expr() ); 102 stmtsToAdd Before.push_back(new ExprStmt(noLabels, assign));84 stmtsToAdd.push_back(new ExprStmt(noLabels, assign)); 103 85 104 86 returnStmt->set_expr( new VariableExpr( newObj ) ); … … 110 92 std::list<DeclarationWithType*> oldReturnVals = returnVals; 111 93 std::string oldFuncName = funcName; 112 94 113 95 FunctionType * type = functionDecl->get_functionType(); 114 96 returnVals = type->get_returnVals();
Note: See TracChangeset
for help on using the changeset viewer.