Changeset a0fdbd5 for src/InitTweak
- Timestamp:
- Apr 28, 2016, 12:32:49 PM (8 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:
- fea7ca7
- Parents:
- 84bb4d9
- Location:
- src/InitTweak
- Files:
-
- 2 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r84bb4d9 ra0fdbd5 10 10 // Created On : Wed Jan 13 16:29:30 2016 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Apr 27 17:08:44 201612 // Last Modified On : Thu Apr 28 12:25:14 2016 13 13 // Update Count : 30 14 14 // … … 16 16 #include <stack> 17 17 #include <list> 18 #include " RemoveInit.h"18 #include "FixInit.h" 19 19 #include "ResolvExpr/Resolver.h" 20 20 #include "ResolvExpr/typeops.h" -
src/InitTweak/GenInit.cc
r84bb4d9 ra0fdbd5 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // RemoveInit.cc --7 // GenInit.cc -- 8 8 // 9 9 // Author : Rob Schluntz 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Apr 14 15:09:36201612 // Last Modified On : Thu Apr 28 12:26:47 2016 13 13 // Update Count : 166 14 14 // … … 16 16 #include <stack> 17 17 #include <list> 18 #include " RemoveInit.h"18 #include "GenInit.h" 19 19 #include "SynTree/Declaration.h" 20 20 #include "SynTree/Type.h" … … 32 32 } 33 33 34 class Re moveInit: public GenPoly::PolyMutator {34 class ReturnFixer : public GenPoly::PolyMutator { 35 35 public: 36 /// removes and replaces initialization for polymorphic value objects 37 /// with assignment (TODO: constructor) statements. 38 /// also consistently allocates a temporary variable for the return value 39 /// of a function so that anything which the resolver decides can be assigned 36 /// consistently allocates a temporary variable for the return value 37 /// of a function so that anything which the resolver decides can be constructed 40 38 /// into the return type of a function can be returned. 41 static void removeInitializers( std::list< Declaration * > &translationUnit ); 42 43 RemoveInit(); 44 45 virtual ObjectDecl * mutate( ObjectDecl *objDecl ); 39 static void makeReturnTemp( std::list< Declaration * > &translationUnit ); 40 41 ReturnFixer(); 42 46 43 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ); 47 44 … … 79 76 }; 80 77 81 void tweak( std::list< Declaration * > & translationUnit ) {82 Re moveInit::removeInitializers( translationUnit );78 void genInit( std::list< Declaration * > & translationUnit ) { 79 ReturnFixer::makeReturnTemp( translationUnit ); 83 80 CtorDtor::generateCtorDtor( translationUnit ); 84 81 } 85 82 86 void RemoveInit::removeInitializers( std::list< Declaration * > & translationUnit ) { 87 RemoveInit remover; 88 mutateAll( translationUnit, remover ); 89 } 90 91 RemoveInit::RemoveInit() : tempNamer( "_retVal" ) {} 92 93 // in the case where an object has an initializer and a polymorphic type, insert an assignment immediately after the 94 // declaration. This will (seemingly) cause the later phases to do the right thing with the assignment 95 ObjectDecl *RemoveInit::mutate( ObjectDecl *objDecl ) { 96 if (objDecl->get_init() && dynamic_cast<TypeInstType*>(objDecl->get_type())) { 97 if (SingleInit * single = dynamic_cast<SingleInit*>(objDecl->get_init())) { 98 // xxx this can be more complicated - consider ListInit 99 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?{}" ) ); 100 assign->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 101 assign->get_args().push_back( single->get_value()->clone() ); 102 stmtsToAddAfter.push_back(new ExprStmt(noLabels, assign)); 103 } // if 104 } // if 105 return objDecl; 106 } 107 108 Statement *RemoveInit::mutate( ReturnStmt *returnStmt ) { 83 void ReturnFixer::makeReturnTemp( std::list< Declaration * > & translationUnit ) { 84 ReturnFixer fixer; 85 mutateAll( translationUnit, fixer ); 86 } 87 88 ReturnFixer::ReturnFixer() : tempNamer( "_retVal" ) {} 89 90 Statement *ReturnFixer::mutate( ReturnStmt *returnStmt ) { 109 91 // update for multiple return values 110 92 assert( returnVals.size() == 0 || returnVals.size() == 1 ); … … 128 110 } 129 111 130 DeclarationWithType* Re moveInit::mutate( FunctionDecl *functionDecl ) {112 DeclarationWithType* ReturnFixer::mutate( FunctionDecl *functionDecl ) { 131 113 std::list<DeclarationWithType*> oldReturnVals = returnVals; 132 114 std::string oldFuncName = funcName; -
src/InitTweak/GenInit.h
r84bb4d9 ra0fdbd5 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Mon Jan 11 16:02:44201612 // Last Modified On : Thu Apr 28 12:22:09 2016 13 13 // Update Count : 3 14 14 // 15 15 16 #ifndef REMOVE_INIT_H17 #define REMOVE_INIT_H16 #ifndef GEN_INIT_H 17 #define GEN_INIT_H 18 18 19 19 #include <string> … … 25 25 26 26 namespace InitTweak { 27 /// Adds assignment statements for polymorphic type initializers28 void tweak( std::list< Declaration * > & translationUnit );27 /// Adds return value temporaries and wraps Initializers in ConstructorInit nodes 28 void genInit( std::list< Declaration * > & translationUnit ); 29 29 } // namespace 30 30 -
src/InitTweak/module.mk
r84bb4d9 ra0fdbd5 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 12 ## Last Modified By : Rob Schluntz 13 ## Last Modified On : Wed Jan 13 16:29:03201613 ## Last Modified On : Thu Apr 28 12:23:17 2016 14 14 ## Update Count : 3 15 15 ############################################################################### 16 16 17 SRC += InitTweak/ RemoveInit.cc \17 SRC += InitTweak/GenInit.cc \ 18 18 InitTweak/FixInit.cc
Note: See TracChangeset
for help on using the changeset viewer.