Changes in / [7bd712d:637568b]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/GenInit.cc

    r7bd712d r637568b  
    1616#include <stack>
    1717#include <list>
    18 
     18#include "GenInit.h"
    1919#include "InitTweak.h"
    20 #include "GenInit.h"
    21 
    22 #include "Common/PassVisitor.h"
    23 
    2420#include "SynTree/Declaration.h"
     21#include "SynTree/Type.h"
    2522#include "SynTree/Expression.h"
     23#include "SynTree/Statement.h"
    2624#include "SynTree/Initializer.h"
    2725#include "SynTree/Mutator.h"
    28 #include "SynTree/Statement.h"
    29 #include "SynTree/Type.h"
    30 
    3126#include "SymTab/Autogen.h"
    3227#include "SymTab/Mangler.h"
    33 
     28#include "GenPoly/PolyMutator.h"
    3429#include "GenPoly/DeclMutator.h"
    35 #include "GenPoly/PolyMutator.h"
    3630#include "GenPoly/ScopedSet.h"
    37 
    3831#include "ResolvExpr/typeops.h"
    3932
     
    4437        }
    4538
    46         class ReturnFixer {
     39        class ReturnFixer final : public GenPoly::PolyMutator {
    4740          public:
    4841                /// consistently allocates a temporary variable for the return value
     
    5144                static void makeReturnTemp( std::list< Declaration * > &translationUnit );
    5245
    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;
    5850
    5951          protected:
     
    137129
    138130        void ReturnFixer::makeReturnTemp( std::list< Declaration * > & translationUnit ) {
    139                 PassVisitor<ReturnFixer> fixer;
     131                ReturnFixer fixer;
    140132                mutateAll( translationUnit, fixer );
    141133        }
    142134
    143         void ReturnFixer::premutate( ReturnStmt *returnStmt ) {
     135        Statement *ReturnFixer::mutate( ReturnStmt *returnStmt ) {
    144136                std::list< DeclarationWithType * > & returnVals = ftype->get_returnVals();
    145137                assert( returnVals.size() == 0 || returnVals.size() == 1 );
     
    152144                        construct->get_args().push_back( new AddressExpr( new VariableExpr( returnVals.front() ) ) );
    153145                        construct->get_args().push_back( returnStmt->get_expr() );
    154                         stmtsToAddBefore.push_back(new ExprStmt(noLabels, construct));
     146                        stmtsToAdd.push_back(new ExprStmt(noLabels, construct));
    155147
    156148                        // return the retVal object
    157149                        returnStmt->set_expr( new VariableExpr( returnVals.front() ) );
    158150                } // 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 );
    164157
    165158                ftype = functionDecl->get_functionType();
    166159                funcName = functionDecl->get_name();
     160                return Parent::mutate( functionDecl );
    167161        }
    168162
Note: See TracChangeset for help on using the changeset viewer.