Changeset 24d6572 for src/GenPoly/Box.cc


Ignore:
Timestamp:
Jun 12, 2023, 2:45:32 PM (2 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ast-experimental, master
Children:
62d62db
Parents:
34b4268 (diff), 251ce80 (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 ast-experimental

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r34b4268 r24d6572  
    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 : Fri Dec 13 23:40:34 2019
    13 // Update Count     : 347
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Dec 19 16:36:00 2022
     13// Update Count     : 348
    1414//
     15
     16#include "Box.h"
    1517
    1618#include <algorithm>                     // for mismatch
     
    2426#include <utility>                       // for pair
    2527
    26 #include "Box.h"
    27 
    2828#include "CodeGen/OperatorTable.h"
    2929#include "Common/PassVisitor.h"          // for PassVisitor
     
    3131#include "Common/SemanticError.h"        // for SemanticError
    3232#include "Common/UniqueName.h"           // for UniqueName
    33 #include "Common/utility.h"              // for toString
     33#include "Common/ToString.hpp"           // for toCString
    3434#include "FindFunction.h"                // for findFunction, findAndReplace...
    3535#include "GenPoly/ErasableScopedMap.h"   // for ErasableScopedMap<>::const_i...
     
    3737#include "InitTweak/InitTweak.h"         // for getFunctionName, isAssignment
    3838#include "Lvalue.h"                      // for generalizedLvalue
    39 #include "ResolvExpr/typeops.h"          // for typesCompatible
     39#include "ResolvExpr/Unify.h"            // for typesCompatible
    4040#include "ScopedSet.h"                   // for ScopedSet, ScopedSet<>::iter...
    4141#include "ScrubTyVars.h"                 // for ScrubTyVars
     
    7272                };
    7373
     74                /// Updates the call sites of polymorphic functions.
    7475                /// Replaces polymorphic return types with out-parameters,
    7576                /// replaces calls to polymorphic functions with adapter calls,
    7677                /// and adds appropriate type variables to the function call.
    77                 class Pass1 final : public BoxPass, public WithConstTypeSubstitution, public WithStmtsToAdd, public WithGuards, public WithVisitorRef<Pass1>, public WithShortCircuiting {
     78                class CallAdapter final : public BoxPass, public WithConstTypeSubstitution, public WithStmtsToAdd, public WithGuards, public WithVisitorRef<CallAdapter>, public WithShortCircuiting {
    7879                  public:
    79                         Pass1();
    80 
     80                        CallAdapter();
     81
     82                        void premutate( Declaration * declaration );
    8183                        void premutate( FunctionDecl * functionDecl );
    8284                        void premutate( TypeDecl * typeDecl );
     
    138140                };
    139141
     142                /// Updates declarations (and types) that require adapters.
    140143                /// * Moves polymorphic returns in function types to pointer-type parameters
    141144                /// * adds type size and assertion parameters to parameter lists
    142                 struct Pass2 final : public BoxPass, public WithGuards {
     145                struct DeclAdapter final : public BoxPass, public WithGuards {
    143146                        void handleAggDecl();
    144147
     
    210213                };
    211214
     215                /// Erases unneeded/unwanted polymorphic information.
    212216                /// Replaces initialization of polymorphic values with alloca,
    213217                /// declaration of dtype/ftype with appropriate void expression,
    214218                /// sizeof expressions of polymorphic types with the proper variable,
    215219                /// and strips fields from generic struct declarations.
    216                 struct Pass3 final : public BoxPass, public WithGuards {
    217                         template< typename DeclClass >
    218                         void handleDecl( DeclClass * decl, Type * type );
    219 
     220                struct Eraser final {
    220221                        void premutate( ObjectDecl * objectDecl );
    221222                        void premutate( FunctionDecl * functionDecl );
     
    223224                        void premutate( StructDecl * structDecl );
    224225                        void premutate( UnionDecl * unionDecl );
    225                         void premutate( TypeDecl * typeDecl );
    226                         void premutate( PointerType * pointerType );
    227                         void premutate( FunctionType * funcType );
    228226                };
    229227        } // anonymous namespace
     
    231229        void box( std::list< Declaration *>& translationUnit ) {
    232230                PassVisitor<LayoutFunctionBuilder> layoutBuilder;
    233                 PassVisitor<Pass1> pass1;
    234                 PassVisitor<Pass2> pass2;
     231                PassVisitor<CallAdapter> callAdapter;
     232                PassVisitor<DeclAdapter> declAdapter;
    235233                PassVisitor<PolyGenericCalculator> polyCalculator;
    236                 PassVisitor<Pass3> pass3;
     234                PassVisitor<Eraser> eraser;
    237235
    238236                acceptAll( translationUnit, layoutBuilder );
    239                 mutateAll( translationUnit, pass1 );
    240                 mutateAll( translationUnit, pass2 );
     237                mutateAll( translationUnit, callAdapter );
     238                mutateAll( translationUnit, declAdapter );
    241239                mutateAll( translationUnit, polyCalculator );
    242                 mutateAll( translationUnit, pass3 );
     240                mutateAll( translationUnit, eraser );
    243241        }
    244242
    245         ////////////////////////////////// LayoutFunctionBuilder ////////////////////////////////////////////
     243////////////////////////////////// LayoutFunctionBuilder ////////////////////////////////////////
    246244
    247245        /// Get a list of type declarations that will affect a layout function
     
    423421        }
    424422
    425         ////////////////////////////////////////// Pass1 ////////////////////////////////////////////////////
     423////////////////////////////////////////////// CallAdapter //////////////////////////////////////
    426424
    427425        namespace {
    428426                std::string makePolyMonoSuffix( FunctionType const * function, const TyVarMap &tyVars ) {
    429                         std::stringstream name;
    430 
    431427                        // NOTE: this function previously used isPolyObj, which failed to produce
    432428                        // the correct thing in some situations. It's not clear to me why this wasn't working.
     
    435431                        // to take those polymorphic types as pointers. Therefore, there can be two different functions
    436432                        // with the same mangled name, so we need to further mangle the names.
     433                        std::stringstream name;
    437434                        for ( DeclarationWithType const * const ret : function->returnVals ) {
    438                                 if ( isPolyType( ret->get_type(), tyVars ) ) {
    439                                         name << "P";
    440                                 } else {
    441                                         name << "M";
    442                                 }
    443                         }
    444                         name << "_";
     435                                name << ( isPolyType( ret->get_type(), tyVars ) ? 'P' : 'M' );
     436                        }
     437                        name << '_';
    445438                        for ( DeclarationWithType const * const arg : function->parameters ) {
    446                                 if ( isPolyType( arg->get_type(), tyVars ) ) {
    447                                         name << "P";
    448                                 } else {
    449                                         name << "M";
    450                                 }
    451                         } // for
     439                                name << ( isPolyType( arg->get_type(), tyVars ) ? 'P' : 'M' );
     440                        }
    452441                        return name.str();
    453442                }
     
    465454                Type *replaceWithConcrete( Type *type, TypeSubstitution const * env, bool doClone = true );
    466455
    467                 Pass1::Pass1() : tempNamer( "_temp" ) {}
    468 
    469                 void Pass1::premutate( FunctionDecl *functionDecl ) {
     456                CallAdapter::CallAdapter() : tempNamer( "_temp" ) {}
     457
     458                void CallAdapter::premutate( Declaration * ) {
     459                        // Prevent type declaration information from leaking out.
     460                        GuardScope( scopeTyVars );
     461                }
     462
     463                void CallAdapter::premutate( FunctionDecl *functionDecl ) {
    470464                        if ( functionDecl->get_statements() ) {         // empty routine body ?
    471465                                // std::cerr << "mutating function: " << functionDecl->get_mangleName() << std::endl;
     
    500494                                for ( FunctionType const * const funType : functions ) {
    501495                                        std::string mangleName = mangleAdapterName( funType, scopeTyVars );
    502                                         if ( adapters.find( mangleName ) == adapters.end() ) {
     496                                        if ( !adapters.contains( mangleName ) ) {
    503497                                                std::string adapterName = makeAdapterName( mangleName );
    504498                                                adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, nullptr, new PointerType( Type::Qualifiers(), makeAdapterType( funType, scopeTyVars ) ), nullptr ) ) );
     
    509503                }
    510504
    511                 void Pass1::premutate( TypeDecl *typeDecl ) {
     505                void CallAdapter::premutate( TypeDecl *typeDecl ) {
    512506                        addToTyVarMap( typeDecl, scopeTyVars );
    513507                }
    514508
    515                 void Pass1::premutate( CommaExpr *commaExpr ) {
     509                void CallAdapter::premutate( CommaExpr *commaExpr ) {
    516510                        // Attempting to find application expressions that were mutated by the copy constructor passes
    517511                        // to use an explicit return variable, so that the variable can be reused as a parameter to the
     
    531525                }
    532526
    533                 std::list< Expression *>::iterator Pass1::passArgTypeVars( ApplicationExpr *appExpr, Type *parmType, Type *argBaseType, std::list< Expression *>::iterator arg, const TyVarMap &exprTyVars, std::set< std::string > &seenTypes ) {
     527                std::list< Expression *>::iterator CallAdapter::passArgTypeVars( ApplicationExpr *appExpr, Type *parmType, Type *argBaseType, std::list< Expression *>::iterator arg, const TyVarMap &exprTyVars, std::set< std::string > &seenTypes ) {
    534528                        Type *polyType = isPolyType( parmType, exprTyVars );
    535529                        if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) {
     
    558552                }
    559553
    560                 std::list< Expression *>::iterator Pass1::passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, const TyVarMap &exprTyVars ) {
     554                std::list< Expression *>::iterator CallAdapter::passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, const TyVarMap &exprTyVars ) {
    561555                        assert( env );
    562556                        std::list< Expression *>::iterator arg = appExpr->args.begin();
     
    568562                        // even when converted to strings, sort in the original order.
    569563                        // (At least, that is the best explination I have.)
    570                         for ( std::pair<std::string, TypeDecl::Data> const & tyParam : exprTyVars ) {
     564                        for ( std::pair<const std::string, TypeDecl::Data> const & tyParam : exprTyVars ) {
    571565                                if ( !tyParam.second.isComplete ) continue;
    572566                                Type *concrete = env->lookup( tyParam.first );
     
    611605                }
    612606
    613                 ObjectDecl *Pass1::makeTemporary( Type *type ) {
     607                ObjectDecl *CallAdapter::makeTemporary( Type *type ) {
    614608                        ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), Type::StorageClasses(), LinkageSpec::C, 0, type, 0 );
    615609                        stmtsToAddBefore.push_back( new DeclStmt( newObj ) );
     
    617611                }
    618612
    619                 Expression *Pass1::addRetParam( ApplicationExpr *appExpr, Type *retType ) {
     613                Expression *CallAdapter::addRetParam( ApplicationExpr *appExpr, Type *retType ) {
    620614                        // Create temporary to hold return value of polymorphic function and produce that temporary as a result
    621615                        // using a comma expression.
     
    680674                }
    681675
    682                 Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, Type *dynType ) {
     676                Expression *CallAdapter::addDynRetParam( ApplicationExpr *appExpr, Type *dynType ) {
    683677                        Type *concrete = replaceWithConcrete( dynType, env );
    684678                        // add out-parameter for return value
     
    686680                }
    687681
    688                 Expression *Pass1::applyAdapter( ApplicationExpr *appExpr, FunctionType *function ) {
     682                Expression *CallAdapter::applyAdapter( ApplicationExpr *appExpr, FunctionType *function ) {
    689683                        Expression *ret = appExpr;
    690684                        if ( isDynRet( function, scopeTyVars ) ) {
     
    735729                }
    736730
    737                 void Pass1::boxParam( Expression *&arg, Type *param, const TyVarMap &exprTyVars ) {
     731                void CallAdapter::boxParam( Expression *&arg, Type *param, const TyVarMap &exprTyVars ) {
    738732                        assertf( arg->result, "arg does not have result: %s", toString( arg ).c_str() );
    739733                        addCast( arg, param, exprTyVars );
     
    770764                }
    771765
    772                 void Pass1::boxParams( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, FunctionType *function, const TyVarMap &exprTyVars ) {
     766                void CallAdapter::boxParams( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, FunctionType *function, const TyVarMap &exprTyVars ) {
    773767                        for ( DeclarationWithType * param : function->parameters ) {
    774768                                assertf( arg != appExpr->args.end(), "boxParams: missing argument for param %s to %s in %s", toString( param ).c_str(), toString( function ).c_str(), toString( appExpr ).c_str() );
     
    778772                }
    779773
    780                 void Pass1::addInferredParams( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, FunctionType *functionType, const TyVarMap &tyVars ) {
     774                void CallAdapter::addInferredParams( ApplicationExpr *appExpr, std::list< Expression *>::iterator arg, FunctionType *functionType, const TyVarMap &tyVars ) {
    781775                        for ( TypeDecl * const tyVar : functionType->forall ) {
    782776                                for ( DeclarationWithType * const assert : tyVar->assertions ) {
     
    846840                }
    847841
    848                 FunctionDecl *Pass1::makeAdapter( FunctionType const *adaptee, FunctionType *realType, const std::string &mangleName, const TyVarMap &tyVars ) {
     842                FunctionDecl *CallAdapter::makeAdapter( FunctionType const *adaptee, FunctionType *realType, const std::string &mangleName, const TyVarMap &tyVars ) {
    849843                        FunctionType *adapterType = makeAdapterType( adaptee, tyVars );
    850844                        adapterType = ScrubTyVars::scrub( adapterType, tyVars );
     
    906900                }
    907901
    908                 void Pass1::passAdapters( ApplicationExpr * appExpr, FunctionType * functionType, const TyVarMap & exprTyVars ) {
     902                void CallAdapter::passAdapters( ApplicationExpr * appExpr, FunctionType * functionType, const TyVarMap & exprTyVars ) {
    909903                        // collect a list of function types passed as parameters or implicit parameters (assertions)
    910904                        std::list<FunctionType const *> functions;
     
    923917
    924918                        for ( FunctionType const * const funType : functions ) {
    925                                 FunctionType *originalFunction = funType->clone();
    926                                 FunctionType *realFunction = funType->clone();
    927                                 std::string mangleName = SymTab::Mangler::mangle( realFunction );
     919                                std::string mangleName = SymTab::Mangler::mangle( funType );
    928920
    929921                                // only attempt to create an adapter or pass one as a parameter if we haven't already done so for this
    930922                                // pre-substitution parameter function type.
    931923                                // The second part of the insert result is "is the value new".
    932                                 if ( adaptersDone.insert( mangleName ).second ) {
    933 
    934                                         // apply substitution to type variables to figure out what the adapter's type should look like
    935                                         assert( env );
    936                                         env->apply( realFunction );
    937                                         mangleName = SymTab::Mangler::mangle( realFunction );
    938                                         mangleName += makePolyMonoSuffix( originalFunction, exprTyVars );
    939 
    940                                         typedef ScopedMap< std::string, DeclarationWithType* >::iterator AdapterIter;
    941                                         AdapterIter adapter = adapters.find( mangleName );
    942                                         if ( adapter == adapters.end() ) {
    943                                                 // adapter has not been created yet in the current scope, so define it
    944                                                 FunctionDecl *newAdapter = makeAdapter( funType, realFunction, mangleName, exprTyVars );
    945                                                 std::pair< AdapterIter, bool > answer = adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) );
    946                                                 adapter = answer.first;
    947                                                 stmtsToAddBefore.push_back( new DeclStmt( newAdapter ) );
    948                                         } // if
    949                                         assert( adapter != adapters.end() );
    950 
    951                                         // add the appropriate adapter as a parameter
    952                                         appExpr->get_args().push_front( new VariableExpr( adapter->second ) );
     924                                if ( !adaptersDone.insert( mangleName ).second ) continue;
     925
     926                                // Apply substitution to type variables to figure out what the adapter's type should look like.
     927                                assert( env );
     928                                FunctionType *realType = funType->clone();
     929                                env->apply( realType );
     930                                mangleName = SymTab::Mangler::mangle( realType );
     931                                mangleName += makePolyMonoSuffix( funType, exprTyVars );
     932
     933                                typedef ScopedMap< std::string, DeclarationWithType* >::iterator AdapterIter;
     934                                AdapterIter adapter = adapters.find( mangleName );
     935                                if ( adapter == adapters.end() ) {
     936                                        // Adapter has not been created yet in the current scope, so define it.
     937                                        FunctionDecl *newAdapter = makeAdapter( funType, realType, mangleName, exprTyVars );
     938                                        std::pair< AdapterIter, bool > answer = adapters.insert( mangleName, newAdapter );
     939                                        adapter = answer.first;
     940                                        stmtsToAddBefore.push_back( new DeclStmt( newAdapter ) );
    953941                                } // if
     942                                assert( adapter != adapters.end() );
     943
     944                                // Add the appropriate adapter as a parameter.
     945                                appExpr->args.push_front( new VariableExpr( adapter->second ) );
    954946                        } // for
    955947                } // passAdapters
     
    974966                }
    975967
    976                 Expression *Pass1::handleIntrinsics( ApplicationExpr *appExpr ) {
     968                Expression *CallAdapter::handleIntrinsics( ApplicationExpr *appExpr ) {
    977969                        if ( VariableExpr *varExpr = dynamic_cast< VariableExpr *>( appExpr->function ) ) {
    978970                                if ( varExpr->var->linkage == LinkageSpec::Intrinsic ) {
     
    10971089                }
    10981090
    1099                 Expression *Pass1::postmutate( ApplicationExpr *appExpr ) {
     1091                Expression *CallAdapter::postmutate( ApplicationExpr *appExpr ) {
    11001092                        // std::cerr << "mutate appExpr: " << InitTweak::getFunctionName( appExpr ) << std::endl;
    11011093                        // for ( auto tyVar : scopeTyVars ) {
     
    11691161                }
    11701162
    1171                 Expression * Pass1::postmutate( UntypedExpr *expr ) {
     1163                Expression * CallAdapter::postmutate( UntypedExpr *expr ) {
    11721164                        if ( isPolyDeref( expr, scopeTyVars, env ) ) {
    11731165                                Expression *ret = expr->args.front();
     
    11791171                }
    11801172
    1181                 void Pass1::premutate( AddressExpr * ) { visit_children = false; }
    1182 
    1183                 Expression * Pass1::postmutate( AddressExpr * addrExpr ) {
     1173                void CallAdapter::premutate( AddressExpr * ) { visit_children = false; }
     1174
     1175                Expression * CallAdapter::postmutate( AddressExpr * addrExpr ) {
    11841176                        assert( addrExpr->arg->result && ! addrExpr->arg->result->isVoid() );
    11851177
     
    12121204                }
    12131205
    1214                 void Pass1::premutate( ReturnStmt *returnStmt ) {
     1206                void CallAdapter::premutate( ReturnStmt *returnStmt ) {
    12151207                        if ( retval && returnStmt->expr ) {
    12161208                                assert( returnStmt->expr->result && ! returnStmt->expr->result->isVoid() );
     
    12201212                }
    12211213
    1222                 void Pass1::premutate( PointerType *pointerType ) {
     1214                void CallAdapter::premutate( PointerType *pointerType ) {
    12231215                        GuardScope( scopeTyVars );
    12241216                        makeTyVarMap( pointerType, scopeTyVars );
    12251217                }
    12261218
    1227                 void Pass1::premutate( FunctionType *functionType ) {
     1219                void CallAdapter::premutate( FunctionType *functionType ) {
    12281220                        GuardScope( scopeTyVars );
    12291221                        makeTyVarMap( functionType, scopeTyVars );
    12301222                }
    12311223
    1232                 void Pass1::beginScope() {
     1224                void CallAdapter::beginScope() {
    12331225                        adapters.beginScope();
    12341226                }
    12351227
    1236                 void Pass1::endScope() {
     1228                void CallAdapter::endScope() {
    12371229                        adapters.endScope();
    12381230                }
    12391231
    1240 ////////////////////////////////////////// Pass2 ////////////////////////////////////////////////////
    1241 
    1242                 void Pass2::addAdapters( FunctionType *functionType ) {
     1232////////////////////////////////////////// DeclAdapter //////////////////////////////////////////
     1233
     1234                void DeclAdapter::addAdapters( FunctionType *functionType ) {
    12431235                        std::list< FunctionType const *> functions;
    12441236                        for ( DeclarationWithType * const arg : functionType->parameters ) {
     
    12601252                }
    12611253
    1262                 DeclarationWithType * Pass2::postmutate( FunctionDecl *functionDecl ) {
     1254                DeclarationWithType * DeclAdapter::postmutate( FunctionDecl *functionDecl ) {
    12631255                        FunctionType * ftype = functionDecl->type;
    12641256                        if ( ! ftype->returnVals.empty() && functionDecl->statements ) {
     
    12851277                }
    12861278
    1287                 void Pass2::premutate( StructDecl * ) {
     1279                void DeclAdapter::premutate( StructDecl * ) {
    12881280                        // prevent tyVars from leaking into containing scope
    12891281                        GuardScope( scopeTyVars );
    12901282                }
    12911283
    1292                 void Pass2::premutate( UnionDecl * ) {
     1284                void DeclAdapter::premutate( UnionDecl * ) {
    12931285                        // prevent tyVars from leaking into containing scope
    12941286                        GuardScope( scopeTyVars );
    12951287                }
    12961288
    1297                 void Pass2::premutate( TraitDecl * ) {
     1289                void DeclAdapter::premutate( TraitDecl * ) {
    12981290                        // prevent tyVars from leaking into containing scope
    12991291                        GuardScope( scopeTyVars );
    13001292                }
    13011293
    1302                 void Pass2::premutate( TypeDecl *typeDecl ) {
     1294                void DeclAdapter::premutate( TypeDecl *typeDecl ) {
    13031295                        addToTyVarMap( typeDecl, scopeTyVars );
    13041296                }
    13051297
    1306                 void Pass2::premutate( PointerType *pointerType ) {
     1298                void DeclAdapter::premutate( PointerType *pointerType ) {
    13071299                        GuardScope( scopeTyVars );
    13081300                        makeTyVarMap( pointerType, scopeTyVars );
    13091301                }
    13101302
    1311                 void Pass2::premutate( FunctionType *funcType ) {
     1303                void DeclAdapter::premutate( FunctionType *funcType ) {
    13121304                        GuardScope( scopeTyVars );
    13131305                        makeTyVarMap( funcType, scopeTyVars );
     
    13931385                }
    13941386
    1395 ////////////////////////////////////////// PolyGenericCalculator ////////////////////////////////////////////////////
     1387////////////////////////////////////////// PolyGenericCalculator ////////////////////////////////
    13961388
    13971389                PolyGenericCalculator::PolyGenericCalculator()
     
    14741466                        // make sure that any type information passed into the function is accounted for
    14751467                        for ( DeclarationWithType * const fnParam : funcType->get_parameters() ) {
    1476                                 // condition here duplicates that in Pass2::mutate( FunctionType* )
     1468                                // condition here duplicates that in DeclAdapter::mutate( FunctionType* )
    14771469                                Type *polyType = isPolyType( fnParam->get_type(), scopeTyVars );
    14781470                                if ( polyType && ! dynamic_cast< TypeInstType* >( polyType ) ) {
     
    15011493                                        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( ty ) ) {
    15021494                                                // do not try to monomorphize generic parameters
    1503                                                 if ( scopeTyVars.find( typeInst->get_name() ) != scopeTyVars.end() && ! genericParams.count( typeInst->name ) ) {
     1495                                                if ( scopeTyVars.contains( typeInst->get_name() ) && ! genericParams.count( typeInst->name ) ) {
    15041496                                                        // polymorphic aggregate members should be converted into monomorphic members.
    15051497                                                        // Using char[size_T] here respects the expected sizing rules of an aggregate type.
     
    17101702
    17111703                        if ( auto typeInst = dynamic_cast< TypeInstType const * >( ty ) ) {
    1712                                 if ( scopeTyVars.find( typeInst->get_name() ) != scopeTyVars.end() ) {
     1704                                if ( scopeTyVars.contains( typeInst->get_name() ) ) {
    17131705                                        // NOTE assumes here that getting put in the scopeTyVars included having the layout variables set
    17141706                                        return true;
     
    17181710                                // check if this type already has a layout generated for it
    17191711                                std::string typeName = mangleType( ty );
    1720                                 if ( knownLayouts.find( typeName ) != knownLayouts.end() ) return true;
     1712                                if ( knownLayouts.contains( typeName ) ) return true;
    17211713
    17221714                                // check if any of the type parameters have dynamic layout; if none do, this type is (or will be) monomorphized
     
    17551747                                // check if this type already has a layout generated for it
    17561748                                std::string typeName = mangleType( ty );
    1757                                 if ( knownLayouts.find( typeName ) != knownLayouts.end() ) return true;
     1749                                if ( knownLayouts.contains( typeName ) ) return true;
    17581750
    17591751                                // check if any of the type parameters have dynamic layout; if none do, this type is (or will be) monomorphized
     
    18461838                        } else {
    18471839                                std::string offsetName = offsetofName( mangleType( ty ) );
    1848                                 if ( knownOffsets.find( offsetName ) != knownOffsets.end() ) {
     1840                                if ( knownOffsets.contains( offsetName ) ) {
    18491841                                        // use the already-generated offsets for this type
    18501842                                        ret = new NameExpr( offsetName );
     
    18841876                }
    18851877
    1886 ////////////////////////////////////////// Pass3 ////////////////////////////////////////////////////
    1887 
    1888                 template< typename DeclClass >
    1889                 void Pass3::handleDecl( DeclClass * decl, Type * type ) {
    1890                         GuardScope( scopeTyVars );
    1891                         makeTyVarMap( type, scopeTyVars );
    1892                         ScrubTyVars::scrubAll( decl );
    1893                 }
    1894 
    1895                 void Pass3::premutate( ObjectDecl * objectDecl ) {
    1896                         handleDecl( objectDecl, objectDecl->type );
    1897                 }
    1898 
    1899                 void Pass3::premutate( FunctionDecl * functionDecl ) {
    1900                         handleDecl( functionDecl, functionDecl->type );
    1901                 }
    1902 
    1903                 void Pass3::premutate( TypedefDecl * typedefDecl ) {
    1904                         handleDecl( typedefDecl, typedefDecl->base );
     1878////////////////////////////////////////// Eraser ///////////////////////////////////////////////
     1879
     1880                void Eraser::premutate( ObjectDecl * objectDecl ) {
     1881                        ScrubTyVars::scrubAll( objectDecl );
     1882                }
     1883
     1884                void Eraser::premutate( FunctionDecl * functionDecl ) {
     1885                        ScrubTyVars::scrubAll( functionDecl );
     1886                }
     1887
     1888                void Eraser::premutate( TypedefDecl * typedefDecl ) {
     1889                        ScrubTyVars::scrubAll( typedefDecl );
    19051890                }
    19061891
    19071892                /// Strips the members from a generic aggregate
    1908                 void stripGenericMembers(AggregateDecl * decl) {
     1893                static void stripGenericMembers( AggregateDecl * decl ) {
    19091894                        if ( ! decl->parameters.empty() ) decl->members.clear();
    19101895                }
    19111896
    1912                 void Pass3::premutate( StructDecl * structDecl ) {
     1897                void Eraser::premutate( StructDecl * structDecl ) {
    19131898                        stripGenericMembers( structDecl );
    19141899                }
    19151900
    1916                 void Pass3::premutate( UnionDecl * unionDecl ) {
     1901                void Eraser::premutate( UnionDecl * unionDecl ) {
    19171902                        stripGenericMembers( unionDecl );
    1918                 }
    1919 
    1920                 void Pass3::premutate( TypeDecl * typeDecl ) {
    1921                         addToTyVarMap( typeDecl, scopeTyVars );
    1922                 }
    1923 
    1924                 void Pass3::premutate( PointerType * pointerType ) {
    1925                         GuardScope( scopeTyVars );
    1926                         makeTyVarMap( pointerType, scopeTyVars );
    1927                 }
    1928 
    1929                 void Pass3::premutate( FunctionType * functionType ) {
    1930                         GuardScope( scopeTyVars );
    1931                         makeTyVarMap( functionType, scopeTyVars );
    19321903                }
    19331904        } // anonymous namespace
     
    19391910// compile-command: "make install" //
    19401911// End: //
    1941 
Note: See TracChangeset for help on using the changeset viewer.