Changeset 1e9d87b


Ignore:
Timestamp:
Jan 7, 2016, 11:43:10 AM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
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
Message:

made RemoveInit? a PolyMutator?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/RemoveInit.cc

    r083cf31 r1e9d87b  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // RemoveInit.cc -- 
     7// RemoveInit.cc --
    88//
    99// Author           : Rob Schluntz
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 15 15:37:26 2015
    13 // Update Count     : 15
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Thu Jan 07 11:34:33 2016
     13// Update Count     : 23
    1414//
    1515
     
    2121#include "SynTree/Initializer.h"
    2222#include "SynTree/Mutator.h"
     23#include "GenPoly/PolyMutator.h"
    2324
    2425namespace InitTweak {
     
    2627                const std::list<Label> noLabels;
    2728        }
    28        
    29         class RemoveInit : public Mutator {
     29
     30        class RemoveInit : public GenPoly::PolyMutator {
    3031          public:
    3132                RemoveInit();
     
    3435
    3536                virtual Statement * mutate( ReturnStmt * returnStmt );
    36                
     37
    3738                virtual CompoundStmt * mutate(CompoundStmt * compoundStmt);
    38                
     39
    3940          protected:
    40                 std::list< Statement* > stmtsToAddBefore;
    41                 std::list< Statement* > stmtsToAddAfter;
    42                 void mutateStatementList( std::list< Statement* > &statements );
    43 
    4441                std::list<DeclarationWithType*> returnVals;
    4542                UniqueName tempNamer;
     
    5350
    5451        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                         } // if
    61                         *i = (*i)->acceptMutator( *this );
    62                         if ( ! stmtsToAddBefore.empty() ) {
    63                                 statements.splice( i, stmtsToAddBefore );
    64                         } // if
    65                 } // for
    66                 if ( ! stmtsToAddAfter.empty() ) {
    67                         statements.splice( statements.end(), stmtsToAddAfter );
    68                 } // if
    69         }
    7052
    7153        CompoundStmt *RemoveInit::mutate(CompoundStmt *compoundStmt) {
     
    9577                if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue()  ) {
    9678                        ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), 0 );
    97                         stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) );
    98                        
     79                        stmtsToAdd.push_back( new DeclStmt( noLabels, newObj ) );
     80
    9981                        UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
    10082                        assign->get_args().push_back( new AddressExpr (new NameExpr( newObj->get_name() ) ) );
    10183                        assign->get_args().push_back( returnStmt->get_expr() );
    102                         stmtsToAddBefore.push_back(new ExprStmt(noLabels, assign));
     84                        stmtsToAdd.push_back(new ExprStmt(noLabels, assign));
    10385
    10486                        returnStmt->set_expr( new VariableExpr( newObj ) );
     
    11092                std::list<DeclarationWithType*> oldReturnVals = returnVals;
    11193                std::string oldFuncName = funcName;
    112                
     94
    11395                FunctionType * type = functionDecl->get_functionType();
    11496                returnVals = type->get_returnVals();
Note: See TracChangeset for help on using the changeset viewer.