Changes in / [5f6c42c:4389966]


Ignore:
Location:
src/GenPoly
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r5f6c42c r4389966  
    5555                  public:
    5656                        Pass1();
    57                         virtual Expression *mutate( ApplicationExpr *appExpr );
    58                         virtual Expression *mutate( AddressExpr *addrExpr );
    59                         virtual Expression *mutate( UntypedExpr *expr );
    60                         virtual DeclarationWithType* mutate( FunctionDecl *functionDecl );
    61                         virtual TypeDecl *mutate( TypeDecl *typeDecl );
    62                         virtual Expression *mutate( CommaExpr *commaExpr );
    63                         virtual Expression *mutate( ConditionalExpr *condExpr );
     57                        virtual Expression * mutate( ApplicationExpr *appExpr );
     58                        virtual Expression * mutate( AddressExpr *addrExpr );
     59                        virtual Expression * mutate( UntypedExpr *expr );
     60                        virtual DeclarationWithType * mutate( FunctionDecl *functionDecl );
     61                        virtual TypeDecl * mutate( TypeDecl *typeDecl );
     62                        virtual Expression * mutate( CommaExpr *commaExpr );
     63                        virtual Expression * mutate( ConditionalExpr *condExpr );
    6464                        virtual Statement * mutate( ReturnStmt *returnStmt );
    65                         virtual Type *mutate( PointerType *pointerType );
     65                        virtual Type * mutate( PointerType *pointerType );
    6666                        virtual Type * mutate( FunctionType *functionType );
    6767 
     
    155155                        // with the same mangled name, so we need to further mangle the names.
    156156                        for ( std::list< DeclarationWithType *>::iterator retval = function->get_returnVals().begin(); retval != function->get_returnVals().end(); ++retval ) {
    157                                 if ( isPolyType( (*retval)->get_type(), tyVars ) ) {
     157                                if ( isPolyVal( (*retval)->get_type(), tyVars ) ) {
    158158                                        name << "P";
    159159                                } else {
     
    164164                        std::list< DeclarationWithType *> &paramList = function->get_parameters();
    165165                        for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
    166                                 if ( isPolyType( (*arg)->get_type(), tyVars ) ) {
     166                                if ( isPolyVal( (*arg)->get_type(), tyVars ) ) {
    167167                                        name << "P";
    168168                                } else {
     
    281281
    282282                TypeDecl *Pass1::mutate( TypeDecl *typeDecl ) {
     283///     std::cerr << "add " << typeDecl->get_name() << "\n";
    283284                        scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();
    284285                        return Mutator::mutate( typeDecl );
     
    329330                }
    330331
     332                TypeInstType *isPolyType( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) {
     333                        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
     334                                if ( env ) {
     335                                        if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     336                                                return isPolyType( newType, env, tyVars );
     337                                        } // if
     338                                } // if
     339                                if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
     340                                        return typeInst;
     341                                } else {
     342                                        return 0;
     343                                } // if
     344                        } else {
     345                                return 0;
     346                        } // if
     347                }
     348
    331349                Expression *Pass1::addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg ) {
    332350                        // ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous.
     
    344362                        // If the type of the temporary is not polymorphic, box temporary by taking its address; otherwise the
    345363                        // temporary is already boxed and can be used directly.
    346                         if ( ! isPolyType( newObj->get_type(), scopeTyVars, env ) ) {
     364                        if ( ! isPolyType( newObj->get_type(), env, scopeTyVars ) ) {
    347365                                paramExpr = new AddressExpr( paramExpr );
    348366                        } // if
     
    370388                Expression *Pass1::applyAdapter( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &tyVars ) {
    371389                        Expression *ret = appExpr;
    372                         if ( ! function->get_returnVals().empty() && isPolyType( function->get_returnVals().front()->get_type(), tyVars ) ) {
     390                        if ( ! function->get_returnVals().empty() && isPolyVal( function->get_returnVals().front()->get_type(), tyVars ) ) {
    373391                                ret = addRetParam( appExpr, function, function->get_returnVals().front()->get_type(), arg );
    374392                        } // if
     
    384402                void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) {
    385403                        assert( ! arg->get_results().empty() );
    386 //   if ( ! dynamic_cast< PointerType *>( arg->get_results().front() ) ) {
     404///   if ( ! dynamic_cast< PointerType *>( arg->get_results().front() ) ) {
    387405                        TypeInstType *typeInst = dynamic_cast< TypeInstType *>( param );
    388406                        if ( typeInst && exprTyVars.find( typeInst->get_name() ) != exprTyVars.end() ) {
     
    404422                                } // if
    405423                        } // if
    406 //   }
     424///   }
    407425                }
    408426
     
    410428                        Type *newType = formal->clone();
    411429                        std::list< FunctionType *> functions;
    412                         // instead of functions needing adapters, this really ought to look for
    413                         // any function mentioning a polymorphic type
     430                        // instead of functions needing adapters, this really ought to look for any function mentioning a
     431                        // polymorphic type
    414432                        findAndReplaceFunction( newType, functions, tyVars, needsAdapter );
    415433                        if ( ! functions.empty() ) {
     
    421439
    422440                void Pass1::boxParams( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
     441///   std::cout << "function is ";
     442///   function->print( std::cout );
    423443                        for ( std::list< DeclarationWithType *>::const_iterator param = function->get_parameters().begin(); param != function->get_parameters().end(); ++param, ++arg ) {
     444///     std::cout << "parameter is ";
     445///     (*param)->print( std::fcout );
     446///     std::cout << std::endl << "argument is ";
     447///     (*arg)->print( std::cout );
    424448                                assert( arg != appExpr->get_args().end() );
    425449                                addCast( *arg, (*param)->get_type(), exprTyVars );
     
    456480                        // actually make the adapter type
    457481                        FunctionType *adapter = adaptee->clone();
    458                         if ( ! adapter->get_returnVals().empty() && isPolyType( adapter->get_returnVals().front()->get_type(), tyVars ) ) {
     482                        if ( ! adapter->get_returnVals().empty() && isPolyVal( adapter->get_returnVals().front()->get_type(), tyVars ) ) {
    459483                                makeRetParm( adapter );
    460484                        } // if
     
    466490                        assert( param );
    467491                        assert( arg );
    468                         if ( isPolyType( realParam->get_type(), tyVars ) ) {
    469 //     if ( dynamic_cast< PointerType *>( arg->get_type() ) ) {
    470 //       return new CastExpr( new VariableExpr( param ), arg->get_type()->clone() );
    471 //     } else {
     492///   std::cout << "arg type is ";
     493///   arg->get_type()->print( std::cout );
     494///   std::cout << "param type is ";
     495///   param->get_type()->print( std::cout );
     496///   std::cout << " tyVars are: ";
     497///   printTyVarMap( std::cout, tyVars );
     498                        if ( isPolyVal( realParam->get_type(), tyVars ) ) {
     499///     if ( dynamic_cast< PointerType *>( arg->get_type() ) ) {
     500///       return new CastExpr( new VariableExpr( param ), arg->get_type()->clone() );
     501///     } else {
    472502                                if ( dynamic_cast<TypeInstType *>(arg->get_type()) == NULL ) {
    473503                                        UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
     
    476506                                        return deref;
    477507                                } // if
    478 //     }
     508///     }
    479509                        } // if
    480510                        return new VariableExpr( param );
     
    523553                                addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars );
    524554                                bodyStmt = new ExprStmt( noLabels, adapteeApp );
    525                         } else if ( isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
     555                        } else if ( isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
    526556                                if ( (*param)->get_name() == "" ) {
    527557                                        (*param)->set_name( "_ret" );
     
    595625                } // passAdapters
    596626
     627                TypeInstType *isPolyPtr( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) {
     628                        if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
     629                                return isPolyType( ptr->get_base(), env, tyVars );
     630                        } else if ( env ) {
     631                                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
     632                                        if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     633                                                return isPolyPtr( newType, env, tyVars );
     634                                        } // if
     635                                } // if
     636                        } // if
     637                        return 0;
     638                }
     639
     640                TypeInstType *isPolyPtrPtr( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) {
     641                        if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
     642                                return isPolyPtr( ptr->get_base(), env, tyVars );
     643                        } else if ( env ) {
     644                                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
     645                                        if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     646                                                return isPolyPtrPtr( newType, env, tyVars );
     647                                        } // if
     648                                } // if
     649                        } // if
     650                        return 0;
     651                }
     652
    597653                Expression *makeIncrDecrExpr( ApplicationExpr *appExpr, Type *polyType, bool isIncr ) {
    598654                        NameExpr *opExpr;
     
    625681                                                assert( ! appExpr->get_results().empty() );
    626682                                                assert( appExpr->get_args().size() == 2 );
    627                                                 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env );
    628                                                 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env );
    629                                                 assert( ! baseType1 || ! baseType2 );
     683                                                TypeInstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars );
     684                                                TypeInstType *typeInst2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), env, scopeTyVars );
     685                                                assert( ! typeInst1 || ! typeInst2 );
    630686                                                UntypedExpr *ret = 0;
    631                                                 if ( baseType1 || baseType2 ) {
     687                                                if ( typeInst1 || typeInst2 ) {
    632688                                                        ret = new UntypedExpr( new NameExpr( "?+?" ) );
    633689                                                } // if
    634                                                 if ( baseType1 ) {
     690                                                if ( typeInst1 ) {
    635691                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    636692                                                        multiply->get_args().push_back( appExpr->get_args().back() );
    637                                                         multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );
     693                                                        multiply->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) );
    638694                                                        ret->get_args().push_back( appExpr->get_args().front() );
    639695                                                        ret->get_args().push_back( multiply );
    640                                                 } else if ( baseType2 ) {
     696                                                } else if ( typeInst2 ) {
    641697                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    642698                                                        multiply->get_args().push_back( appExpr->get_args().front() );
    643                                                         multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) );
     699                                                        multiply->get_args().push_back( new NameExpr( sizeofName( typeInst2 ) ) );
    644700                                                        ret->get_args().push_back( multiply );
    645701                                                        ret->get_args().push_back( appExpr->get_args().back() );
    646702                                                } // if
    647                                                 if ( baseType1 || baseType2 ) {
     703                                                if ( typeInst1 || typeInst2 ) {
    648704                                                        ret->get_results().push_front( appExpr->get_results().front()->clone() );
    649705                                                        if ( appExpr->get_env() ) {
     
    658714                                                assert( ! appExpr->get_results().empty() );
    659715                                                assert( ! appExpr->get_args().empty() );
    660                                                 if ( isPolyType( appExpr->get_results().front(), scopeTyVars, env ) ) {
     716                                                if ( isPolyType( appExpr->get_results().front(), env, scopeTyVars ) ) {
    661717                                                        Expression *ret = appExpr->get_args().front();
    662718                                                        delete ret->get_results().front();
     
    673729                                                assert( ! appExpr->get_results().empty() );
    674730                                                assert( appExpr->get_args().size() == 1 );
    675                                                 if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) {
     731                                                if ( TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ) ) {
    676732                                                        Type *tempType = appExpr->get_results().front()->clone();
    677733                                                        if ( env ) {
     
    687743                                                                assignExpr->get_args().push_back( appExpr->get_args().front()->clone() );
    688744                                                        } // if
    689                                                         CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, baseType, varExpr->get_var()->get_name() == "?++" ) );
     745                                                        CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, typeInst, varExpr->get_var()->get_name() == "?++" ) );
    690746                                                        return new CommaExpr( firstComma, tempExpr );
    691747                                                } // if
     
    693749                                                assert( ! appExpr->get_results().empty() );
    694750                                                assert( appExpr->get_args().size() == 1 );
    695                                                 if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) {
    696                                                         return makeIncrDecrExpr( appExpr, baseType, varExpr->get_var()->get_name() == "++?" );
     751                                                if ( TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ) ) {
     752                                                        return makeIncrDecrExpr( appExpr, typeInst, varExpr->get_var()->get_name() == "++?" );
    697753                                                } // if
    698754                                        } else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) {
    699755                                                assert( ! appExpr->get_results().empty() );
    700756                                                assert( appExpr->get_args().size() == 2 );
    701                                                 Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env );
    702                                                 Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env );
    703                                                 if ( baseType1 && baseType2 ) {
     757                                                TypeInstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars );
     758                                                TypeInstType *typeInst2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), env, scopeTyVars );
     759                                                if ( typeInst1 && typeInst2 ) {
    704760                                                        UntypedExpr *divide = new UntypedExpr( new NameExpr( "?/?" ) );
    705761                                                        divide->get_args().push_back( appExpr );
    706                                                         divide->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );
     762                                                        divide->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) );
    707763                                                        divide->get_results().push_front( appExpr->get_results().front()->clone() );
    708764                                                        if ( appExpr->get_env() ) {
     
    711767                                                        } // if
    712768                                                        return divide;
    713                                                 } else if ( baseType1 ) {
     769                                                } else if ( typeInst1 ) {
    714770                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    715771                                                        multiply->get_args().push_back( appExpr->get_args().back() );
    716                                                         multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );
     772                                                        multiply->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) );
    717773                                                        appExpr->get_args().back() = multiply;
    718                                                 } else if ( baseType2 ) {
     774                                                } else if ( typeInst2 ) {
    719775                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    720776                                                        multiply->get_args().push_back( appExpr->get_args().front() );
    721                                                         multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) );
     777                                                        multiply->get_args().push_back( new NameExpr( sizeofName( typeInst2 ) ) );
    722778                                                        appExpr->get_args().front() = multiply;
    723779                                                } // if
     
    725781                                                assert( ! appExpr->get_results().empty() );
    726782                                                assert( appExpr->get_args().size() == 2 );
    727                                                 Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env );
    728                                                 if ( baseType ) {
     783                                                TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars );
     784                                                if ( typeInst ) {
    729785                                                        UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
    730786                                                        multiply->get_args().push_back( appExpr->get_args().back() );
    731                                                         multiply->get_args().push_back( new NameExpr( sizeofName( baseType ) ) );
     787                                                        multiply->get_args().push_back( new NameExpr( sizeofName( typeInst ) ) );
    732788                                                        appExpr->get_args().back() = multiply;
    733789                                                } // if
     
    796852
    797853                Expression *Pass1::mutate( UntypedExpr *expr ) {
    798                         if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {
     854                        if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), env, scopeTyVars ) ) {
    799855                                if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
    800856                                        if ( name->get_name() == "*?" ) {
     
    814870                        bool needs = false;
    815871                        if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) {
    816                                 if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {
     872                                if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), env, scopeTyVars ) ) {
    817873                                        if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
    818874                                                if ( name->get_name() == "*?" ) {
     
    830886                        } // if
    831887                        addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) );
    832                         if ( isPolyType( addrExpr->get_arg()->get_results().front(), scopeTyVars, env ) || needs ) {
     888                        if ( isPolyType( addrExpr->get_arg()->get_results().front(), env, scopeTyVars ) || needs ) {
    833889                                Expression *ret = addrExpr->get_arg();
    834890                                delete ret->get_results().front();
     
    854910                                        castExpr->set_arg( 0 );
    855911                                        delete castExpr;
    856                                 } //while
     912                                } // while
    857913                                TypeInstType *typeInst = dynamic_cast< TypeInstType *>( retval->get_type() );
    858914                                assert( typeInst );
     
    868924                                stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( assignExpr ) ) );
    869925                                // } else {
     926                                //      std::cerr << "THOMAS " << std::endl;
    870927                                //      useRetval = true;
    871928                                //      stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( returnStmt->get_expr() ) ) );
     
    927984                                }
    928985                        }
    929 //  deleteAll( functions );
     986///  deleteAll( functions );
    930987                }
    931988
     
    10771134                Statement *Pass3::mutate( DeclStmt *declStmt ) {
    10781135                        if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) {
    1079                                 if ( isPolyType( objectDecl->get_type(), scopeTyVars ) ) {
    1080                                         // change initialization of a polymorphic value object
    1081                                         // to allocate storage with alloca
    1082                                         Type *declType = objectDecl->get_type();
     1136                                if ( isPolyVal( objectDecl->get_type(), scopeTyVars ) ) {
     1137                                        // change initialization of a polymorphic value object to allocate storage with alloca
     1138                                        TypeInstType *typeInst = dynamic_cast< TypeInstType *>( objectDecl->get_type() );
     1139                                        assert( typeInst );
    10831140                                        UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) );
    1084                                         alloc->get_args().push_back( new NameExpr( sizeofName( declType ) ) );
     1141                                        alloc->get_args().push_back( new NameExpr( sizeofName( typeInst ) ) );
    10851142
    10861143                                        delete objectDecl->get_init();
  • src/GenPoly/GenPoly.cc

    r5f6c42c r4389966  
    1515
    1616#include "GenPoly.h"
    17 
    18 #include "SymTab/Mangler.h"
    19 #include "SynTree/Expression.h"
    2017#include "SynTree/Type.h"
    2118
     
    2421
    2522namespace GenPoly {
     23        /// A function needs an adapter if it returns a polymorphic value or if any of its parameters have polymorphic type
    2624        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) {
    27                 if ( ! adaptee->get_returnVals().empty() && isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
     25                if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
    2826                        return true;
    2927                } // if
    3028                for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); innerArg != adaptee->get_parameters().end(); ++innerArg ) {
    31                         if ( isPolyType( (*innerArg)->get_type(), tyVars ) ) {
     29                        if ( isPolyVal( (*innerArg)->get_type(), tyVars ) ) {
    3230                                return true;
    3331                        } // if
     
    6765        }
    6866
    69         namespace {
    70                 /// Checks a parameter list for polymorphic parameters
    71                 bool hasPolyParams( std::list< Expression* >& params, const TyVarMap &tyVars, const TypeSubstitution *env ) {
    72                         for ( std::list< Expression* >::iterator param = params.begin(); param != params.end(); ++param ) {
    73                                 TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
    74                                 assert(paramType && "Aggregate parameters should be type expressions");
    75                                 if ( isPolyType( paramType->get_type(), tyVars, env ) ) return true;
    76                         }
     67        bool isPolyVal( Type *type, const TyVarMap &tyVars ) {
     68                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
     69                        if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
     70                                return true;
     71                        } // if
     72                } // if
     73                return false;
     74        }
     75
     76        bool isPolyObj( Type *type, const TyVarMap &tyVars ) {
     77                if ( isPolyVal( type, tyVars ) ) {
     78                        return true;
     79                } else if ( PointerType *pt = dynamic_cast<PointerType*>( type ) ) {
     80                        return isPolyObj( pt->get_base(), tyVars );
     81                } else {
    7782                        return false;
    7883                }
    79         }
    80        
    81         Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
    82                 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
    83                         if ( env ) {
    84                                 if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
    85                                         return isPolyType( newType, tyVars, env );
    86                         } // if
    87                 } // if
    88                         if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
    89                                 return type;
    90         }
    91                 } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) {
    92                         if ( hasPolyParams( structType->get_parameters(), tyVars, env ) ) return type;
    93                 } else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( type ) ) {
    94                         if ( hasPolyParams( unionType->get_parameters(), tyVars, env ) ) return type;
    95                 }
    96                 return 0;
    97         }
    98 
    99         Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
    100                 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    101                         return isPolyType( ptr->get_base(), tyVars, env );
    102                 } else if ( env ) {
    103                         if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
    104                                 if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
    105                                         return isPolyPtr( newType, tyVars, env );
    106                                 } // if
    107                         } // if
    108                 } // if
    109                 return 0;
    11084        }
    11185
     
    11690                os << std::endl;
    11791        }
    118 
    119         std::string sizeofName( Type *ty ) {
    120                 return std::string( "_sizeof_" ) + SymTab::Mangler::mangle( ty, false, false );
    121         }
    122 
    123         std::string alignofName( Type *ty ) {
    124                 return std::string( "_alignof_" ) + SymTab::Mangler::mangle( ty, false, false );
    125         }
    12692} // namespace GenPoly
    12793
  • src/GenPoly/GenPoly.h

    r5f6c42c r4389966  
    2020#include <string>
    2121#include <iostream>
    22 
    2322#include "SynTree/Declaration.h"
    24 #include "SynTree/TypeSubstitution.h"
    2523
    2624namespace GenPoly {
    2725        typedef std::map< std::string, TypeDecl::Kind > TyVarMap;
    2826
    29         /// A function needs an adapter if it returns a polymorphic value or if any of its
    30         /// parameters have polymorphic type
    3127        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr );
    32 
    33         /// true iff function has polymorphic return type
    3428        bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars );
    3529        bool isPolyRet( FunctionType *function, std::string &name );
    3630        bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars );
     31//      bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars );
     32        bool isPolyVal( Type *type, const TyVarMap &tyVars );
    3733
    38         /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided
    39         Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
    40 
    41         /// returns polymorphic type if is pointer to polymorphic type, NULL otherwise; will look up substitution in env if provided
    42         Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
    43 
    44         /// Prints type variable map
     34  // true if type variable or any number of pointers to type variable
     35  bool isPolyObj( Type *type, const TyVarMap &tyVars );
    4536        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
    46 
    47         /// Gets the name of the sizeof parameter for the type
    48         std::string sizeofName( Type *ty );
    49 
    50         /// Gets the name of the alignof parameter for the type
    51         std::string alignofName( Type *ty );
    5237} // namespace GenPoly
    5338
  • src/GenPoly/ScrubTyVars.cc

    r5f6c42c r4389966  
    1919#include "GenPoly.h"
    2020#include "ScrubTyVars.h"
     21
     22#include "SymTab/Mangler.h"
    2123
    2224#include "SynTree/Mutator.h"
     
    7678                return Mutator::mutate( pointer );
    7779        }
     80       
     81        std::string sizeofName( Type *ty ) {
     82                return std::string( "_sizeof_" ) + SymTab::Mangler::mangle( ty, false, false );
     83        }
     84
     85        std::string alignofName( Type *ty ) {
     86                return std::string( "_alignof_" ) + SymTab::Mangler::mangle( ty, false, false );
     87        }
    7888} // namespace GenPoly
    7989
  • src/GenPoly/ScrubTyVars.h

    r5f6c42c r4389966  
    5959                return static_cast< SynTreeClass* >( target->acceptMutator( scrubber ) );
    6060        }
     61
     62        /// Gets the name of the sizeof parameter for the type
     63        std::string sizeofName( Type *ty );
     64
     65        /// Gets the name of the alignof parameter for the type
     66        std::string alignofName( Type *ty );
    6167} // namespace GenPoly
    6268
Note: See TracChangeset for help on using the changeset viewer.