Changeset c29d9ce for src


Ignore:
Timestamp:
Aug 11, 2015, 4:37:32 PM (9 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, string, with_gc
Children:
a3a17ba
Parents:
ae4c85a
Message:

fix issues where incorrect number of adapters can be passed as parameters and where the wrong adapter is passed based on whether the adaptee has a polymorphic return type

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    rae4c85a rc29d9ce  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jul 30 14:35:40 2015
    13 // Update Count     : 54
     12// Last Modified On : Tue Aug 11 16:22:35 2015
     13// Update Count     : 89
    1414//
    1515
     
    7777                        Expression *handleIntrinsics( ApplicationExpr *appExpr );
    7878                        ObjectDecl *makeTemporary( Type *type );
    79  
     79
     80                        typedef std::map< std::string, FunctionDecl *> AdapterMap;
    8081                        std::map< std::string, DeclarationWithType *> assignOps;
    81                         typedef std::map< std::string, FunctionDecl *> AdapterMap;
    8282                        std::stack< AdapterMap > adapters;
    8383                        DeclarationWithType *retval;
     
    168168                        TyVarMap dummyTyVars;
    169169                        return isPolyRet( function, name, dummyTyVars );
     170                }
     171
     172                bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars ) {
     173                        std::string dummyString;
     174                        return isPolyRet( function, dummyString, otherTyVars );
    170175                }
    171176
     
    526531                }
    527532
    528                 void Pass1::passAdapters( ApplicationExpr *appExpr, FunctionType *functionType, const TyVarMap &exprTyVars ) {
     533                void Pass1::passAdapters( ApplicationExpr * appExpr, FunctionType * functionType, const TyVarMap & exprTyVars ) {
    529534                        // collect a list of function types passed as parameters or implicit parameters (assertions)
    530535                        std::list< DeclarationWithType *> &paramList = functionType->get_parameters();
     
    545550
    546551                        for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
     552                                FunctionType *originalFunction = (*funType)->clone();
    547553                                FunctionType *realFunction = (*funType)->clone();
    548554                                std::string mangleName = SymTab::Mangler::mangle( realFunction );
     
    559565                                        env->apply( realFunction );
    560566                                        mangleName = SymTab::Mangler::mangle( realFunction );
    561                                         AdapterMap & adapters = Pass1::adapters.top();
    562                                         AdapterMap::iterator adapter = adapters.find( mangleName );
    563567
    564568                                        if ( needsAdapter( realFunction, exprTyVars, true ) ) {
     
    567571                                                // create a new adapter.
    568572                                                appExpr->get_args().push_front( new NameExpr( makeAdapterName ( mangleName ) ) );
    569                                                 continue;
    570                                         } else if ( adapter == adapters.end() ) {
    571                                                 // adapter has not been created yet in the current scope, so define it
    572                                                 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars );
    573                                                 adapter = adapters.insert( adapters.begin(), std::pair< std::string, FunctionDecl *>( mangleName, newAdapter ) );
    574                                                 stmtsToAdd.push_back( new DeclStmt( noLabels, newAdapter ) );
     573                                        } else {
     574                                                if ( isPolyRet( originalFunction, exprTyVars ) ) {
     575                                                        // if the return type involved polymorphic types, then
     576                                                        // the adapter will need to take those polymorphic types
     577                                                        // as pointers. Therefore, there can be two different
     578                                                        // functions with the same mangled name, so we need two adapter map
     579                                                        // stacks and also we need the mangled names to be different.
     580                                                        mangleName += "polyret_";
     581                                                }
     582
     583                                                AdapterMap & adapters = Pass1::adapters.top();
     584                                                AdapterMap::iterator adapter = adapters.find( mangleName );
     585                                                if ( adapter == adapters.end() ) {
     586                                                        // adapter has not been created yet in the current scope, so define it
     587                                                        FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars );
     588                                                        adapter = adapters.insert( adapters.begin(), std::pair< std::string, FunctionDecl *>( mangleName, newAdapter ) );
     589                                                        stmtsToAdd.push_back( new DeclStmt( noLabels, newAdapter ) );
     590                                                } // if
     591                                                assert( adapter != adapters.end() );
     592
     593                                                // add the appropriate adapter as a parameter
     594                                                appExpr->get_args().push_front( new VariableExpr( adapter->second ) );
    575595                                        } // if
    576                                         assert( adapter != adapters.end() );
    577 
    578                                         // add the appropriate adapter as a parameter
    579                                         appExpr->get_args().push_front( new VariableExpr( adapter->second ) );
    580596                                } // if
    581597                        } // for
Note: See TracChangeset for help on using the changeset viewer.