Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/GenPoly.cc

    rc2ad3c9 rbfae637  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // GenPoly.cc --
     7// GenPoly.cc -- 
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed May 25 13:39:21 2016
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Dec 15 16:11:18 2015
    1313// Update Count     : 13
    1414//
     
    6666        }
    6767
    68         Type* replaceTypeInst( Type* type, const TypeSubstitution* env ) {
    69                 if ( ! env ) return type;
    70                 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) {
    71                         Type *newType = env->lookup( typeInst->get_name() );
    72                         if ( newType ) return newType;
    73                 }
    74                 return type;
    75         }
    76 
    7768        Type *isPolyType( Type *type, const TypeSubstitution *env ) {
    78                 type = replaceTypeInst( type, env );
    79 
    8069                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
     70                        if ( env ) {
     71                                if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     72                                        return isPolyType( newType, env );
     73                                } // if
     74                        } // if
    8175                        return type;
    8276                } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) {
     
    8781                return 0;
    8882        }
    89 
     83       
    9084        Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
    91                 type = replaceTypeInst( type, env );
    92 
    9385                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
     86                        if ( env ) {
     87                                if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     88                                        return isPolyType( newType, tyVars, env );
     89                                } // if
     90                        } // if
    9491                        if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
    9592                                return type;
     
    104101
    105102        Type *isPolyPtr( Type *type, const TypeSubstitution *env ) {
    106                 type = replaceTypeInst( type, env );
    107 
    108103                if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    109104                        return isPolyType( ptr->get_base(), env );
    110                 }
    111                 return 0;
    112         }
    113 
     105                } else if ( env ) {
     106                        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
     107                                if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     108                                        return isPolyPtr( newType, env );
     109                                } // if
     110                        } // if
     111                } // if
     112                return 0;
     113        }
     114       
    114115        Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
    115                 type = replaceTypeInst( type, env );
    116 
    117116                if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    118117                        return isPolyType( ptr->get_base(), tyVars, env );
    119                 }
     118                } else if ( env ) {
     119                        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
     120                                if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     121                                        return isPolyPtr( newType, tyVars, env );
     122                                } // if
     123                        } // if
     124                } // if
    120125                return 0;
    121126        }
     
    127132
    128133                while ( true ) {
    129                         type = replaceTypeInst( type, env );
    130 
    131134                        if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    132135                                type = ptr->get_base();
    133136                                ++(*levels);
     137                        } else if ( env ) {
     138                                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
     139                                        if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     140                                                type = newType;
     141                                        } else break;
     142                                } else break;
    134143                        } else break;
    135144                }
     
    137146                return isPolyType( type, env );
    138147        }
    139 
     148       
    140149        Type * hasPolyBase( Type *type, const TyVarMap &tyVars, int *levels, const TypeSubstitution *env ) {
    141150                int dummy;
     
    144153
    145154                while ( true ) {
    146                         type = replaceTypeInst( type, env );
    147 
    148155                        if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
    149156                                type = ptr->get_base();
    150157                                ++(*levels);
     158                        } else if ( env ) {
     159                                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
     160                                        if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     161                                                type = newType;
     162                                        } else break;
     163                                } else break;
    151164                        } else break;
    152165                }
     
    172185                        if ( VariableExpr *varExpr = dynamic_cast< VariableExpr* >( expr ) ) {
    173186                                return varExpr;
    174                         } else if ( MemberExpr *memberExpr = dynamic_cast< MemberExpr* >( expr ) ) {
    175                                 expr = memberExpr->get_aggregate();
    176187                        } else if ( AddressExpr *addressExpr = dynamic_cast< AddressExpr* >( expr ) ) {
    177188                                expr = addressExpr->get_arg();
     
    181192                                if ( ! fn || fn->get_name() != std::string("*?") ) return 0;
    182193                                expr = *untypedExpr->begin_args();
    183                         } else if ( CommaExpr *commaExpr = dynamic_cast< CommaExpr* >( expr ) ) {
    184                                 // copy constructors insert comma exprs, look at second argument which contains the variable
    185                                 expr = commaExpr->get_arg2();
    186                                 continue;
    187194                        } else break;
    188195
     
    202209                }
    203210        }
    204 
     211       
    205212        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) {
    206213                for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) {
Note: See TracChangeset for help on using the changeset viewer.