Changeset b1e63ac5 for src/GenPoly


Ignore:
Timestamp:
Jul 4, 2017, 9:40:16 AM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
208e5be
Parents:
9c951e3 (diff), f7cb0bc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into references

Location:
src/GenPoly
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r9c951e3 rb1e63ac5  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 13 09:26:38 2017
    13 // Update Count     : 341
     12// Last Modified On : Wed Jun 21 15:49:59 2017
     13// Update Count     : 346
    1414//
    1515
     
    6262namespace GenPoly {
    6363        namespace {
    64                 const std::list<Label> noLabels;
    65 
    6664                FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars );
    6765
     
    103101                        void passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars );
    104102                        /// wraps a function application with a new temporary for the out-parameter return value
    105                         Expression *addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg );
     103                        Expression *addRetParam( ApplicationExpr *appExpr, Type *retType, std::list< Expression *>::iterator &arg );
    106104                        /// Replaces all the type parameters of a generic type with their concrete equivalents under the current environment
    107105                        void replaceParametersWithConcrete( ApplicationExpr *appExpr, std::list< Expression* >& params );
     
    110108                        Type *replaceWithConcrete( ApplicationExpr *appExpr, Type *type, bool doClone = true );
    111109                        /// wraps a function application returning a polymorphic type with a new temporary for the out-parameter return value
    112                         Expression *addDynRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *polyType, std::list< Expression *>::iterator &arg );
     110                        Expression *addDynRetParam( ApplicationExpr *appExpr, Type *polyType, std::list< Expression *>::iterator &arg );
    113111                        Expression *applyAdapter( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars );
    114112                        void boxParam( Type *formal, Expression *&arg, const TyVarMap &exprTyVars );
     
    136134                  public:
    137135                        template< typename DeclClass >
    138                         DeclClass *handleDecl( DeclClass *decl, Type *type );
     136                        DeclClass *handleDecl( DeclClass *decl );
    139137                        template< typename AggDecl >
    140138                        AggDecl * handleAggDecl( AggDecl * aggDecl );
     
    343341        Statement *makeAlignTo( Expression *lhs, Expression *rhs ) {
    344342                // check that the lhs is zeroed out to the level of rhs
    345                 Expression *ifCond = makeOp( "?&?", lhs, makeOp( "?-?", rhs, new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), "1" ) ) ) );
     343                Expression *ifCond = makeOp( "?&?", lhs, makeOp( "?-?", rhs, new ConstantExpr( Constant::from_ulong( 1 ) ) ) );
    346344                // if not aligned, increment to alignment
    347345                Expression *ifExpr = makeOp( "?+=?", lhs->clone(), makeOp( "?-?", rhs->clone(), ifCond->clone() ) );
     
    386384
    387385                // initialize size and alignment to 0 and 1 (will have at least one member to re-edit size)
    388                 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant( sizeAlignType->clone(), "0" ) ) ) );
    389                 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant( sizeAlignType->clone(), "1" ) ) ) );
     386                addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant::from_ulong( 0 ) ) ) );
     387                addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) );
    390388                unsigned long n_members = 0;
    391389                bool firstMember = true;
     
    443441
    444442                // calculate union layout in function body
    445                 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant( sizeAlignType->clone(), "1" ) ) ) );
    446                 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant( sizeAlignType->clone(), "1" ) ) ) );
     443                addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) );
     444                addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) );
    447445                for ( std::list< Declaration* >::const_iterator member = unionDecl->get_members().begin(); member != unionDecl->get_members().end(); ++member ) {
    448446                        DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member );
     
    506504                DeclarationWithType *Pass1::mutate( FunctionDecl *functionDecl ) {
    507505                        if ( functionDecl->get_statements() ) {         // empty routine body ?
     506                                // std::cerr << "mutating function: " << functionDecl->get_mangleName() << std::endl;
    508507                                doBeginScope();
    509508                                scopeTyVars.beginScope();
     
    550549                                retval = oldRetval;
    551550                                doEndScope();
     551                                // std::cerr << "end function: " << functionDecl->get_mangleName() << std::endl;
    552552                        } // if
    553553                        return functionDecl;
     
    665665                }
    666666
    667                 Expression *Pass1::addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg ) {
     667                Expression *Pass1::addRetParam( ApplicationExpr *appExpr, Type *retType, std::list< Expression *>::iterator &arg ) {
    668668                        // Create temporary to hold return value of polymorphic function and produce that temporary as a result
    669669                        // using a comma expression.
     
    728728                }
    729729
    730                 Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *dynType, std::list< Expression *>::iterator &arg ) {
     730                Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, Type *dynType, std::list< Expression *>::iterator &arg ) {
    731731                        assert( env );
    732732                        Type *concrete = replaceWithConcrete( appExpr, dynType );
    733733                        // add out-parameter for return value
    734                         return addRetParam( appExpr, function, concrete, arg );
     734                        return addRetParam( appExpr, concrete, arg );
    735735                }
    736736
     
    739739//                      if ( ! function->get_returnVals().empty() && isPolyType( function->get_returnVals().front()->get_type(), tyVars ) ) {
    740740                        if ( isDynRet( function, tyVars ) ) {
    741                                 ret = addRetParam( appExpr, function, function->get_returnVals().front()->get_type(), arg );
     741                                ret = addRetParam( appExpr, function->get_returnVals().front()->get_type(), arg );
    742742                        } // if
    743743                        std::string mangleName = mangleAdapterName( function, tyVars );
     
    11181118
    11191119                Expression *Pass1::mutate( ApplicationExpr *appExpr ) {
    1120                         // std::cerr << "mutate appExpr: ";
     1120                        // std::cerr << "mutate appExpr: " << InitTweak::getFunctionName( appExpr ) << std::endl;
    11211121                        // for ( TyVarMap::iterator i = scopeTyVars.begin(); i != scopeTyVars.end(); ++i ) {
    11221122                        //      std::cerr << i->first << " ";
     
    11431143                        ReferenceToType *dynRetType = isDynRet( function, exprTyVars );
    11441144
     1145                        // std::cerr << function << std::endl;
     1146                        // std::cerr << "scopeTyVars: ";
     1147                        // printTyVarMap( std::cerr, scopeTyVars );
     1148                        // std::cerr << "exprTyVars: ";
     1149                        // printTyVarMap( std::cerr, exprTyVars );
     1150                        // std::cerr << "env: " << *env << std::endl;
     1151                        // std::cerr << needsAdapter( function, scopeTyVars ) << ! needsAdapter( function, exprTyVars) << std::endl;
     1152
    11451153                        // NOTE: addDynRetParam needs to know the actual (generated) return type so it can make a temp variable, so pass the result type from the appExpr
    11461154                        // passTypeVars needs to know the program-text return type (i.e. the distinction between _conc_T30 and T3(int))
    11471155                        // concRetType may not be a good name in one or both of these places. A more appropriate name change is welcome.
    11481156                        if ( dynRetType ) {
     1157                                // std::cerr << "dynRetType: " << dynRetType << std::endl;
    11491158                                Type *concRetType = appExpr->get_result()->isVoid() ? nullptr : appExpr->get_result();
    1150                                 ret = addDynRetParam( appExpr, function, concRetType, arg ); // xxx - used to use dynRetType instead of concRetType
     1159                                ret = addDynRetParam( appExpr, concRetType, arg ); // xxx - used to use dynRetType instead of concRetType
    11511160                        } else if ( needsAdapter( function, scopeTyVars ) && ! needsAdapter( function, exprTyVars) ) { // xxx - exprTyVars is used above...?
    11521161                                // xxx - the ! needsAdapter check may be incorrect. It seems there is some situation where an adapter is applied where it shouldn't be, and this fixes it for some cases. More investigation is needed.
     
    12821291
    12831292                template< typename DeclClass >
    1284                 DeclClass * Pass2::handleDecl( DeclClass *decl, Type *type ) {
     1293                DeclClass * Pass2::handleDecl( DeclClass *decl ) {
    12851294                        DeclClass *ret = static_cast< DeclClass *>( Parent::mutate( decl ) );
    12861295
     
    12961305
    12971306                DeclarationWithType * Pass2::mutate( FunctionDecl *functionDecl ) {
    1298                         functionDecl = safe_dynamic_cast< FunctionDecl * > ( handleDecl( functionDecl, functionDecl->get_functionType() ) );
     1307                        functionDecl = safe_dynamic_cast< FunctionDecl * > ( handleDecl( functionDecl ) );
    12991308                        FunctionType * ftype = functionDecl->get_functionType();
    13001309                        if ( ! ftype->get_returnVals().empty() && functionDecl->get_statements() ) {
     
    13211330
    13221331                ObjectDecl * Pass2::mutate( ObjectDecl *objectDecl ) {
    1323                         return handleDecl( objectDecl, objectDecl->get_type() );
     1332                        return handleDecl( objectDecl );
    13241333                }
    13251334
     
    13441353                        addToTyVarMap( typeDecl, scopeTyVars );
    13451354                        if ( typeDecl->get_base() ) {
    1346                                 return handleDecl( typeDecl, typeDecl->get_base() );
     1355                                return handleDecl( typeDecl );
    13471356                        } else {
    13481357                                return Parent::mutate( typeDecl );
     
    13511360
    13521361                TypedefDecl * Pass2::mutate( TypedefDecl *typedefDecl ) {
    1353                         return handleDecl( typedefDecl, typedefDecl->get_base() );
     1362                        return handleDecl( typedefDecl );
    13541363                }
    13551364
     
    15661575                /// Returns an index expression into the offset array for a type
    15671576                Expression *makeOffsetIndex( Type *objectType, long i ) {
    1568                         std::stringstream offset_namer;
    1569                         offset_namer << i;
    1570                         ConstantExpr *fieldIndex = new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), offset_namer.str() ) );
     1577                        ConstantExpr *fieldIndex = new ConstantExpr( Constant::from_ulong( i ) );
    15711578                        UntypedExpr *fieldOffset = new UntypedExpr( new NameExpr( "?[?]" ) );
    15721579                        fieldOffset->get_args().push_back( new NameExpr( offsetofName( mangleType( objectType ) ) ) );
     
    17811788                                // all union members are at offset zero
    17821789                                delete offsetofExpr;
    1783                                 return new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), "0" ) );
     1790                                return new ConstantExpr( Constant::from_ulong( 0 ) );
    17841791                        } else return offsetofExpr;
    17851792                }
     
    18061813                                        std::list< Initializer* > inits;
    18071814                                        for ( std::list< Declaration* >::const_iterator member = baseMembers.begin(); member != baseMembers.end(); ++member ) {
    1808                                                 DeclarationWithType *memberDecl;
    1809                                                 if ( DeclarationWithType *origMember = dynamic_cast< DeclarationWithType* >( *member ) ) {
    1810                                                         memberDecl = origMember->clone();
     1815                                                if ( DeclarationWithType *memberDecl = dynamic_cast< DeclarationWithType* >( *member ) ) {
     1816                                                        inits.push_back( new SingleInit( new OffsetofExpr( ty->clone(), memberDecl ) ) );
    18111817                                                } else {
    1812                                                         memberDecl = new ObjectDecl( (*member)->get_name(), Type::StorageClasses(), LinkageSpec::Cforall, 0, offsetType->clone(), 0 );
     1818                                                        assertf( false, "Requesting offset of Non-DWT member: %s", toString( *member ).c_str() );
    18131819                                                }
    1814                                                 inits.push_back( new SingleInit( new OffsetofExpr( ty->clone(), memberDecl ) ) );
    18151820                                        }
    18161821
  • src/GenPoly/CopyParams.cc

    r9c951e3 rb1e63ac5  
    4545
    4646        CopyParams::CopyParams() : namer( "_cp" ) {}
    47 
    48         static const std::list< Label > noLabels;
    4947
    5048        void CopyParams::visit( FunctionDecl *funcDecl ) {
  • src/GenPoly/DeclMutator.cc

    r9c951e3 rb1e63ac5  
    99// Author           : Aaron B. Moss
    1010// Created On       : Fri Nov 27 14:44:00 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug  4 11:16:43 2016
    13 // Update Count     : 3
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Jun 22 13:49:00 2017
     13// Update Count     : 4
    1414//
    1515
     
    2020
    2121namespace GenPoly {
    22         namespace {
    23                 const std::list<Label> noLabels;
    24         }
    25 
    2622        DeclMutator::DeclMutator() : Mutator(), declsToAdd(1), declsToAddAfter(1) {}
    2723
    2824        DeclMutator::~DeclMutator() {}
    29        
     25
    3026        void DeclMutator::mutateDeclarationList( std::list< Declaration* > &decls ) {
    3127                for ( std::list< Declaration* >::iterator decl = decls.begin(); ; ++decl ) {
     
    3430
    3531                        if ( decl == decls.end() ) break;
    36                        
     32
    3733                        // run mutator on declaration
    3834                        *decl = maybeMutate( *decl, *this );
     
    5551                newBack->splice( newBack->end(), *back );
    5652                declsToAdd.pop_back();
    57                
     53
    5854                back = declsToAddAfter.rbegin();
    5955                newBack = back + 1;
     
    6662                CompoundStmt *compoundStmt = dynamic_cast< CompoundStmt* >(stmt);
    6763                if ( compoundStmt ) return mutate( compoundStmt );
    68                
     64
    6965                doBeginScope();
    70                
     66
    7167                // run mutator on statement
    7268                stmt = maybeMutate( stmt, *this );
     
    10298                doBeginScope();
    10399
    104                
     100
    105101                for ( std::list< Statement* >::iterator stmt = stmts.begin(); ; ++stmt ) {
    106102                        // add any new declarations after the previous statement
     
    112108
    113109                        if ( stmt == stmts.end() ) break;
    114                        
     110
    115111                        // run mutator on statement
    116112                        *stmt = maybeMutate( *stmt, *this );
     
    123119                        declsToAdd.back().clear();
    124120                }
    125                
     121
    126122                doEndScope();
    127123        }
     
    139135                return compoundStmt;
    140136        }
    141        
     137
    142138        Statement* DeclMutator::mutate(IfStmt *ifStmt) {
    143139                ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) );
     
    146142                return ifStmt;
    147143        }
    148        
     144
    149145        Statement* DeclMutator::mutate(WhileStmt *whileStmt) {
    150146                whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) );
     
    152148                return whileStmt;
    153149        }
    154        
     150
    155151        Statement* DeclMutator::mutate(ForStmt *forStmt) {
    156152                mutateAll( forStmt->get_initialization(), *this );
     
    160156                return forStmt;
    161157        }
    162        
     158
    163159        Statement* DeclMutator::mutate(SwitchStmt *switchStmt) {
    164160                switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
     
    166162                return switchStmt;
    167163        }
    168        
     164
    169165        Statement* DeclMutator::mutate(CaseStmt *caseStmt) {
    170166                caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) );
     
    172168                return caseStmt;
    173169        }
    174        
     170
    175171        Statement* DeclMutator::mutate(TryStmt *tryStmt) {
    176172                tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );
     
    179175                return tryStmt;
    180176        }
    181        
     177
    182178        Statement* DeclMutator::mutate(CatchStmt *catchStmt) {
    183179                catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) );
     180                catchStmt->set_cond( maybeMutate( catchStmt->get_cond(), *this ) );
    184181                catchStmt->set_body( mutateStatement( catchStmt->get_body() ) );
    185182                return catchStmt;
  • src/GenPoly/InstantiateGeneric.cc

    r9c951e3 rb1e63ac5  
    2222#include "InstantiateGeneric.h"
    2323
    24 #include "DeclMutator.h"
    2524#include "GenPoly.h"
    2625#include "ScopedSet.h"
    2726#include "ScrubTyVars.h"
    28 #include "PolyMutator.h"
     27
     28#include "Common/PassVisitor.h"
     29#include "Common/ScopedMap.h"
     30#include "Common/UniqueName.h"
     31#include "Common/utility.h"
    2932
    3033#include "ResolvExpr/typeops.h"
     
    3437#include "SynTree/Type.h"
    3538
    36 #include "Common/ScopedMap.h"
    37 #include "Common/UniqueName.h"
    38 #include "Common/utility.h"
     39
     40#include "InitTweak/InitTweak.h"
     41
    3942
    4043namespace GenPoly {
     
    153156        }
    154157
    155         // collect the environments of each TypeInstType so that type variables can be replaced
    156         // xxx - possibly temporary solution. Access to type environments is required in GenericInstantiator, but it needs to be a DeclMutator which does not provide easy access to the type environments.
    157         class EnvFinder final : public GenPoly::PolyMutator {
    158         public:
    159                 using GenPoly::PolyMutator::mutate;
    160                 virtual Type * mutate( TypeInstType * inst ) override {
    161                         if ( env ) envMap[inst] = env;
    162                         return inst;
    163                 }
    164 
    165                 // don't want to associate an environment with TypeInstTypes that occur in function types - this may actually only apply to function types belonging to DeclarationWithTypes (or even just FunctionDecl)?
    166                 virtual Type * mutate( FunctionType * ftype ) override {
    167                         return ftype;
    168                 }
    169                 std::unordered_map< ReferenceToType *, TypeSubstitution * > envMap;
    170         };
    171 
    172158        /// Mutator pass that replaces concrete instantiations of generic types with actual struct declarations, scoped appropriately
    173         class GenericInstantiator final : public DeclMutator {
     159        struct GenericInstantiator final : public WithTypeSubstitution, public WithDeclsToAdd, public WithVisitorRef<GenericInstantiator>, public WithGuards {
    174160                /// Map of (generic type, parameter list) pairs to concrete type instantiations
    175161                InstantiationMap< AggregateDecl, AggregateDecl > instantiations;
     
    178164                /// Namer for concrete types
    179165                UniqueName typeNamer;
    180                 /// Reference to mapping of environments
    181                 const std::unordered_map< ReferenceToType *, TypeSubstitution * > & envMap;
    182         public:
    183                 GenericInstantiator( const std::unordered_map< ReferenceToType *, TypeSubstitution * > & envMap ) : DeclMutator(), instantiations(), dtypeStatics(), typeNamer("_conc_"), envMap( envMap ) {}
    184 
    185                 using DeclMutator::mutate;
    186                 virtual Type* mutate( StructInstType *inst ) override;
    187                 virtual Type* mutate( UnionInstType *inst ) override;
    188 
    189                 virtual void doBeginScope() override;
    190                 virtual void doEndScope() override;
     166                /// Should not make use of type environment to replace types of function parameter and return values.
     167                bool inFunctionType = false;
     168                GenericInstantiator() : instantiations(), dtypeStatics(), typeNamer("_conc_") {}
     169
     170                Type* postmutate( StructInstType *inst );
     171                Type* postmutate( UnionInstType *inst );
     172
     173                void premutate( FunctionType * ftype ) {
     174                        GuardValue( inFunctionType );
     175                        inFunctionType = true;
     176                }
     177
     178                void beginScope();
     179                void endScope();
    191180        private:
    192181                /// Wrap instantiation lookup for structs
     
    207196
    208197        void instantiateGeneric( std::list< Declaration* > &translationUnit ) {
    209                 EnvFinder finder;
    210                 mutateAll( translationUnit, finder );
    211                 GenericInstantiator instantiator( finder.envMap );
    212                 instantiator.mutateDeclarationList( translationUnit );
     198                PassVisitor<GenericInstantiator> instantiator;
     199                mutateAll( translationUnit, instantiator );
    213200        }
    214201
     
    306293        Type *GenericInstantiator::replaceWithConcrete( Type *type, bool doClone ) {
    307294                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
    308                         if ( envMap.count( typeInst ) ) {
    309                                 TypeSubstitution * env = envMap.at( typeInst );
     295                        if ( env && ! inFunctionType ) {
    310296                                Type *concrete = env->lookup( typeInst->get_name() );
    311297                                if ( concrete ) {
     
    331317
    332318
    333         Type* GenericInstantiator::mutate( StructInstType *inst ) {
    334                 // mutate subtypes
    335                 Type *mutated = Mutator::mutate( inst );
    336                 inst = dynamic_cast< StructInstType* >( mutated );
    337                 if ( ! inst ) return mutated;
    338 
     319        Type* GenericInstantiator::postmutate( StructInstType *inst ) {
    339320                // exit early if no need for further mutation
    340321                if ( inst->get_parameters().empty() ) return inst;
     
    367348                                concDecl->set_body( inst->get_baseStruct()->has_body() );
    368349                                substituteMembers( inst->get_baseStruct()->get_members(), *inst->get_baseParameters(), typeSubs, concDecl->get_members() );
    369                                 DeclMutator::addDeclaration( concDecl );
    370                                 insert( inst, typeSubs, concDecl );
    371                                 concDecl->acceptMutator( *this ); // recursively instantiate members
     350                                insert( inst, typeSubs, concDecl ); // must insert before recursion
     351                                concDecl->acceptMutator( *visitor ); // recursively instantiate members
     352                                declsToAddBefore.push_back( concDecl ); // must occur before declaration is added so that member instantiations appear first
    372353                        }
    373354                        StructInstType *newInst = new StructInstType( inst->get_qualifiers(), concDecl->get_name() );
     
    388369        }
    389370
    390         Type* GenericInstantiator::mutate( UnionInstType *inst ) {
    391                 // mutate subtypes
    392                 Type *mutated = Mutator::mutate( inst );
    393                 inst = dynamic_cast< UnionInstType* >( mutated );
    394                 if ( ! inst ) return mutated;
    395 
     371        Type* GenericInstantiator::postmutate( UnionInstType *inst ) {
    396372                // exit early if no need for further mutation
    397373                if ( inst->get_parameters().empty() ) return inst;
     
    422398                                concDecl->set_body( inst->get_baseUnion()->has_body() );
    423399                                substituteMembers( inst->get_baseUnion()->get_members(), *inst->get_baseParameters(), typeSubs, concDecl->get_members() );
    424                                 DeclMutator::addDeclaration( concDecl );
    425                                 insert( inst, typeSubs, concDecl );
    426                                 concDecl->acceptMutator( *this ); // recursively instantiate members
     400                                insert( inst, typeSubs, concDecl ); // must insert before recursion
     401                                concDecl->acceptMutator( *visitor ); // recursively instantiate members
     402                                declsToAddBefore.push_back( concDecl ); // must occur before declaration is added so that member instantiations appear first
    427403                        }
    428404                        UnionInstType *newInst = new UnionInstType( inst->get_qualifiers(), concDecl->get_name() );
     
    442418        }
    443419
    444         void GenericInstantiator::doBeginScope() {
    445                 DeclMutator::doBeginScope();
     420        void GenericInstantiator::beginScope() {
    446421                instantiations.beginScope();
    447422                dtypeStatics.beginScope();
    448423        }
    449424
    450         void GenericInstantiator::doEndScope() {
    451                 DeclMutator::doEndScope();
     425        void GenericInstantiator::endScope() {
    452426                instantiations.endScope();
    453427                dtypeStatics.endScope();
  • src/GenPoly/Lvalue.cc

    r9c951e3 rb1e63ac5  
    3636namespace GenPoly {
    3737        namespace {
    38                 const std::list<Label> noLabels;
    39 
    4038                /// Replace uses of lvalue returns with appropriate pointers
    4139                class Pass1 : public Mutator {
  • src/GenPoly/PolyMutator.cc

    r9c951e3 rb1e63ac5  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug  4 11:26:22 2016
    13 // Update Count     : 16
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Jun 22 13:47:00 2017
     13// Update Count     : 17
    1414//
    1515
     
    123123
    124124        Statement * PolyMutator::mutate(TryStmt *tryStmt) {
    125                 tryStmt->set_block(  maybeMutate( tryStmt->get_block(), *this ) );
     125                tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );
    126126                mutateAll( tryStmt->get_catchers(), *this );
     127                tryStmt->set_finally( maybeMutate( tryStmt->get_finally(), *this ) );
    127128                return tryStmt;
    128129        }
    129130
    130131        Statement * PolyMutator::mutate(CatchStmt *cathStmt) {
    131                 cathStmt->set_body(  mutateStatement( cathStmt->get_body() ) );
    132                 cathStmt->set_decl(  maybeMutate( cathStmt->get_decl(), *this ) );
     132                cathStmt->set_body( mutateStatement( cathStmt->get_body() ) );
     133                cathStmt->set_cond( maybeMutate( cathStmt->get_cond(), *this ) );
     134                cathStmt->set_decl( maybeMutate( cathStmt->get_decl(), *this ) );
    133135                return cathStmt;
    134136        }
  • src/GenPoly/Specialize.cc

    r9c951e3 rb1e63ac5  
    9393        }
    9494
    95         bool needsTupleSpecialization( Type *formalType, Type *actualType, TypeSubstitution *env ) {
     95        bool needsTupleSpecialization( Type *formalType, Type *actualType ) {
    9696                // Needs tuple specialization if the structure of the formal type and actual type do not match.
    9797                // This is the case if the formal type has ttype polymorphism, or if the structure  of tuple types
     
    9999                if ( FunctionType * fftype = getFunctionType( formalType ) ) {
    100100                        if ( fftype->isTtype() ) return true;
     101                        // conversion of 0 (null) to function type does not require tuple specialization
     102                        if ( dynamic_cast< ZeroType * >( actualType ) ) return false;
    101103                        FunctionType * aftype = getFunctionType( actualType );
    102104                        assertf( aftype, "formal type is a function type, but actual type is not." );
     
    112114
    113115        bool needsSpecialization( Type *formalType, Type *actualType, TypeSubstitution *env ) {
    114                 return needsPolySpecialization( formalType, actualType, env ) || needsTupleSpecialization( formalType, actualType, env );
     116                return needsPolySpecialization( formalType, actualType, env ) || needsTupleSpecialization( formalType, actualType );
    115117        }
    116118
Note: See TracChangeset for help on using the changeset viewer.