Changes in / [7bd712d:637568b]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/GenInit.cc
r7bd712d r637568b 16 16 #include <stack> 17 17 #include <list> 18 18 #include "GenInit.h" 19 19 #include "InitTweak.h" 20 #include "GenInit.h"21 22 #include "Common/PassVisitor.h"23 24 20 #include "SynTree/Declaration.h" 21 #include "SynTree/Type.h" 25 22 #include "SynTree/Expression.h" 23 #include "SynTree/Statement.h" 26 24 #include "SynTree/Initializer.h" 27 25 #include "SynTree/Mutator.h" 28 #include "SynTree/Statement.h"29 #include "SynTree/Type.h"30 31 26 #include "SymTab/Autogen.h" 32 27 #include "SymTab/Mangler.h" 33 28 #include "GenPoly/PolyMutator.h" 34 29 #include "GenPoly/DeclMutator.h" 35 #include "GenPoly/PolyMutator.h"36 30 #include "GenPoly/ScopedSet.h" 37 38 31 #include "ResolvExpr/typeops.h" 39 32 … … 44 37 } 45 38 46 class ReturnFixer {39 class ReturnFixer final : public GenPoly::PolyMutator { 47 40 public: 48 41 /// consistently allocates a temporary variable for the return value … … 51 44 static void makeReturnTemp( std::list< Declaration * > &translationUnit ); 52 45 53 void premutate( FunctionDecl *functionDecl ); 54 void premutate( ReturnStmt * returnStmt ); 55 56 at_cleanup_t at_cleanup; 57 std::list< Statement * > stmtsToAddBefore; 46 typedef GenPoly::PolyMutator Parent; 47 using Parent::mutate; 48 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ) override; 49 virtual Statement * mutate( ReturnStmt * returnStmt ) override; 58 50 59 51 protected: … … 137 129 138 130 void ReturnFixer::makeReturnTemp( std::list< Declaration * > & translationUnit ) { 139 PassVisitor<ReturnFixer>fixer;131 ReturnFixer fixer; 140 132 mutateAll( translationUnit, fixer ); 141 133 } 142 134 143 void ReturnFixer::premutate( ReturnStmt *returnStmt ) {135 Statement *ReturnFixer::mutate( ReturnStmt *returnStmt ) { 144 136 std::list< DeclarationWithType * > & returnVals = ftype->get_returnVals(); 145 137 assert( returnVals.size() == 0 || returnVals.size() == 1 ); … … 152 144 construct->get_args().push_back( new AddressExpr( new VariableExpr( returnVals.front() ) ) ); 153 145 construct->get_args().push_back( returnStmt->get_expr() ); 154 stmtsToAdd Before.push_back(new ExprStmt(noLabels, construct));146 stmtsToAdd.push_back(new ExprStmt(noLabels, construct)); 155 147 156 148 // return the retVal object 157 149 returnStmt->set_expr( new VariableExpr( returnVals.front() ) ); 158 150 } // if 159 } 160 161 void ReturnFixer::premutate( FunctionDecl *functionDecl ) { 162 GuardValue( this, ftype ); 163 GuardValue( this, funcName ); 151 return returnStmt; 152 } 153 154 DeclarationWithType* ReturnFixer::mutate( FunctionDecl *functionDecl ) { 155 ValueGuard< FunctionType * > oldFtype( ftype ); 156 ValueGuard< std::string > oldFuncName( funcName ); 164 157 165 158 ftype = functionDecl->get_functionType(); 166 159 funcName = functionDecl->get_name(); 160 return Parent::mutate( functionDecl ); 167 161 } 168 162
Note: See TracChangeset
for help on using the changeset viewer.