Changes in / [f5234f3:b81096f]


Ignore:
Location:
src/GenPoly
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    rf5234f3 rb81096f  
    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 Nov 19 17:40:51 2015
    13 // Update Count     : 133
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Nov 24 15:59:33 2015
     13// Update Count     : 169
    1414//
    1515
     
    142142
    143143        namespace {
     144                std::string makePolyMonoSuffix( FunctionType * function, const TyVarMap &tyVars ) {
     145                        std::stringstream name;
     146
     147                        // if the return type or a parameter type involved polymorphic types, then the adapter will need
     148                        // to take those polymorphic types as pointers. Therefore, there can be two different functions
     149                        // with the same mangled name, so we need to further mangle the names.
     150                        if ( isPolyRet( function, tyVars ) ) {
     151                                name << "P";
     152                        } else {
     153                                name << "M";
     154                        }
     155                        name << "_";
     156                        std::list< DeclarationWithType *> &paramList = function->get_parameters();
     157                        for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
     158                                if ( isPolyObj( (*arg)->get_type(), tyVars ) ) {
     159                                        name << "P";
     160                                } else {
     161                                        name << "M";                           
     162                                }
     163                        } // for
     164                        return name.str();
     165                }
     166
     167                std::string mangleAdapterName( FunctionType * function, const TyVarMap &tyVars ) {
     168                        return SymTab::Mangler::mangle( function ) + makePolyMonoSuffix( function, tyVars );
     169                }
     170
    144171                std::string makeAdapterName( const std::string &mangleName ) {
    145172                        return "_adapter" + mangleName;
     
    217244                                AdapterMap & adapters = Pass1::adapters.top();
    218245                                for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
    219                                         std::string mangleName = SymTab::Mangler::mangle( *funType );
    220                                         if ( isPolyRet( *funType, scopeTyVars ) ) {
    221                                                 // if the return type involved polymorphic types, then the adapter will need to take those
    222                                                 // polymorphic types as pointers. Therefore, there can be two different functions with the same
    223                                                 // mangled name, so we need the mangled names to be different.
    224                                                 mangleName += "polyret_";
    225                                         } // if
     246                                        std::string mangleName = mangleAdapterName( *funType, scopeTyVars );
    226247                                        if ( adapters.find( mangleName ) == adapters.end() ) {
    227248                                                std::string adapterName = makeAdapterName( mangleName );
     
    347368                                ret = addRetParam( appExpr, function, function->get_returnVals().front()->get_type(), arg );
    348369                        } // if
    349                         std::string mangleName = SymTab::Mangler::mangle( function );
    350                         if ( isPolyRet( function, tyVars ) ) {
    351                                 mangleName += "polyret_";
    352                         } // if
     370                        std::string mangleName = mangleAdapterName( function, tyVars );
    353371                        std::string adapterName = makeAdapterName( mangleName );
    354372
     
    565583                                        assert( env );
    566584                                        env->apply( realFunction );
    567                                         mangleName = SymTab::Mangler::mangle( realFunction );
    568 
    569                                         if ( isPolyRet( originalFunction, exprTyVars ) ) {
    570                                                 mangleName += "polyret_";
    571                                         } // if
     585                                        mangleName = SymTab::Mangler::mangle( realFunction );
     586                                        mangleName += makePolyMonoSuffix( originalFunction, exprTyVars );
    572587
    573588                                        AdapterMap & adapters = Pass1::adapters.top();
     
    900915
    901916                void Pass1::doBeginScope() {
    902                         // actually, maybe this could (should?) push
    903                         // a copy of the current map
     917                        // push a copy of the current map
    904918                        adapters.push(adapters.top());
    905919                }
     
    923937                        std::set< std::string > adaptersDone;
    924938                        for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
    925                                 std::string mangleName = SymTab::Mangler::mangle( *funType );
    926                                 if ( isPolyRet( *funType, scopeTyVars ) ) {
    927                                         mangleName += "polyret_";
    928                                 } // if
     939                                std::string mangleName = mangleAdapterName( *funType, scopeTyVars );
    929940                                if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) {
    930941                                        std::string adapterName = makeAdapterName( mangleName );
  • src/GenPoly/GenPoly.cc

    rf5234f3 rb81096f  
    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 Nov 19 17:23:44 2015
    13 // Update Count     : 10
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Nov 24 15:23:08 2015
     13// Update Count     : 11
    1414//
    1515
     
    7575        }
    7676
     77        bool isPolyObj( Type *type, const TyVarMap &tyVars ) {
     78                if ( isPolyVal( type, tyVars ) ) {
     79                        return true;
     80                } else if ( PointerType *pt = dynamic_cast<PointerType*>( type ) ) {
     81                        return isPolyObj( pt->get_base(), tyVars );
     82                } else {
     83                        return false;
     84                }
     85        }
     86
    7787        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) {
    7888                for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) {
  • src/GenPoly/GenPoly.h

    rf5234f3 rb81096f  
    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 Nov 19 17:24:03 2015
    13 // Update Count     : 4
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Nov 24 15:24:38 2015
     13// Update Count     : 6
    1414//
    1515
     
    3131//      bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars );
    3232        bool isPolyVal( Type *type, const TyVarMap &tyVars );
     33
     34  // true if type variable or any number of pointers to type variable
     35  bool isPolyObj( Type *type, const TyVarMap &tyVars );
    3336        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
    3437} // namespace GenPoly
Note: See TracChangeset for help on using the changeset viewer.