Changeset 9845cb6


Ignore:
Timestamp:
Jan 16, 2023, 3:41:46 PM (15 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master
Children:
e563edf
Parents:
34a1d2e
Message:

Cleaning old box pass for easier translation. Removed an unused variables, reduced cloning and reduced the indent in passAdapters.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r34a1d2e r9845cb6  
    911911
    912912                        for ( FunctionType const * const funType : functions ) {
    913                                 FunctionType *originalFunction = funType->clone();
    914                                 FunctionType *realFunction = funType->clone();
    915                                 std::string mangleName = SymTab::Mangler::mangle( realFunction );
     913                                std::string mangleName = SymTab::Mangler::mangle( funType );
    916914
    917915                                // only attempt to create an adapter or pass one as a parameter if we haven't already done so for this
    918916                                // pre-substitution parameter function type.
    919917                                // The second part of the insert result is "is the value new".
    920                                 if ( adaptersDone.insert( mangleName ).second ) {
    921 
    922                                         // apply substitution to type variables to figure out what the adapter's type should look like
    923                                         assert( env );
    924                                         env->apply( realFunction );
    925                                         mangleName = SymTab::Mangler::mangle( realFunction );
    926                                         mangleName += makePolyMonoSuffix( originalFunction, exprTyVars );
    927 
    928                                         typedef ScopedMap< std::string, DeclarationWithType* >::iterator AdapterIter;
    929                                         AdapterIter adapter = adapters.find( mangleName );
    930                                         if ( adapter == adapters.end() ) {
    931                                                 // adapter has not been created yet in the current scope, so define it
    932                                                 FunctionDecl *newAdapter = makeAdapter( funType, realFunction, mangleName, exprTyVars );
    933                                                 std::pair< AdapterIter, bool > answer = adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) );
    934                                                 adapter = answer.first;
    935                                                 stmtsToAddBefore.push_back( new DeclStmt( newAdapter ) );
    936                                         } // if
    937                                         assert( adapter != adapters.end() );
    938 
    939                                         // add the appropriate adapter as a parameter
    940                                         appExpr->get_args().push_front( new VariableExpr( adapter->second ) );
     918                                if ( !adaptersDone.insert( mangleName ).second ) continue;
     919
     920                                // Apply substitution to type variables to figure out what the adapter's type should look like.
     921                                assert( env );
     922                                FunctionType *realType = funType->clone();
     923                                env->apply( realType );
     924                                mangleName = SymTab::Mangler::mangle( realType );
     925                                mangleName += makePolyMonoSuffix( funType, exprTyVars );
     926
     927                                typedef ScopedMap< std::string, DeclarationWithType* >::iterator AdapterIter;
     928                                AdapterIter adapter = adapters.find( mangleName );
     929                                if ( adapter == adapters.end() ) {
     930                                        // Adapter has not been created yet in the current scope, so define it.
     931                                        FunctionDecl *newAdapter = makeAdapter( funType, realType, mangleName, exprTyVars );
     932                                        std::pair< AdapterIter, bool > answer = adapters.insert( mangleName, newAdapter );
     933                                        adapter = answer.first;
     934                                        stmtsToAddBefore.push_back( new DeclStmt( newAdapter ) );
    941935                                } // if
     936                                assert( adapter != adapters.end() );
     937
     938                                // Add the appropriate adapter as a parameter.
     939                                appExpr->args.push_front( new VariableExpr( adapter->second ) );
    942940                        } // for
    943941                } // passAdapters
Note: See TracChangeset for help on using the changeset viewer.