Ignore:
Timestamp:
Feb 8, 2016, 10:07:42 AM (10 years ago)
Author:
Thierry Delisle <tdelisle@…>
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, with_gc
Children:
c44e622
Parents:
00ede9e (diff), bd85400 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into gc_noraii

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/GenPoly.cc

    r00ede9e rd41280e  
    3636        }
    3737
    38         bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ) {
    39                 bool doTransform = false;
     38        ReferenceToType *isPolyRet( FunctionType *function ) {
    4039                if ( ! function->get_returnVals().empty() ) {
    41                         if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( function->get_returnVals().front()->get_type() ) ) {
    42        
    43                                 // figure out if the return type is specified by a type parameter
    44                                 for ( std::list< TypeDecl *>::const_iterator tyVar = function->get_forall().begin(); tyVar != function->get_forall().end(); ++tyVar ) {
    45                                         if ( (*tyVar)->get_name() == typeInst->get_name() ) {
    46                                                 doTransform = true;
    47                                                 name = typeInst->get_name();
    48                                                 break;
    49                                         } // if
    50                                 } // for
    51                                 if ( ! doTransform && otherTyVars.find( typeInst->get_name() ) != otherTyVars.end() ) {
    52                                         doTransform = true;
    53                                 } // if
    54                         } // if
    55                 } // if
    56                 return doTransform;
    57         }
    58 
    59         bool isPolyRet( FunctionType *function, std::string &name ) {
    60                 TyVarMap dummyTyVars;
    61                 return isPolyRet( function, name, dummyTyVars );
    62         }
    63 
    64         bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars ) {
    65                 std::string dummyString;
    66                 return isPolyRet( function, dummyString, otherTyVars );
     40                        TyVarMap forallTypes;
     41                        makeTyVarMap( function, forallTypes );
     42                        return (ReferenceToType*)isPolyType( function->get_returnVals().front()->get_type(), forallTypes );
     43                } // if
     44                return 0;
    6745        }
    6846
     
    149127        }
    150128
     129        Type * hasPolyBase( Type *type, int *levels, const TypeSubstitution *env ) {
     130                int dummy;
     131                if ( ! levels ) { levels = &dummy; }
     132                *levels = 0;
     133
     134                while ( true ) {
     135                        if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
     136                                type = ptr->get_base();
     137                                ++(*levels);
     138                        } else if ( env ) {
     139                                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
     140                                        if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     141                                                type = newType;
     142                                        } else break;
     143                                } else break;
     144                        } else break;
     145                }
     146
     147                return isPolyType( type, env );
     148        }
     149       
     150        Type * hasPolyBase( Type *type, const TyVarMap &tyVars, int *levels, const TypeSubstitution *env ) {
     151                int dummy;
     152                if ( ! levels ) { levels = &dummy; }
     153                *levels = 0;
     154
     155                while ( true ) {
     156                        if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
     157                                type = ptr->get_base();
     158                                ++(*levels);
     159                        } else if ( env ) {
     160                                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
     161                                        if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     162                                                type = newType;
     163                                        } else break;
     164                                } else break;
     165                        } else break;
     166                }
     167
     168                return isPolyType( type, tyVars, env );
     169        }
     170
    151171        FunctionType * getFunctionType( Type *ty ) {
    152172                PointerType *ptrType;
     
    158178        }
    159179
     180        VariableExpr * getBaseVar( Expression *expr, int *levels ) {
     181                int dummy;
     182                if ( ! levels ) { levels = &dummy; }
     183                *levels = 0;
     184
     185                while ( true ) {
     186                        if ( VariableExpr *varExpr = dynamic_cast< VariableExpr* >( expr ) ) {
     187                                return varExpr;
     188                        } else if ( AddressExpr *addressExpr = dynamic_cast< AddressExpr* >( expr ) ) {
     189                                expr = addressExpr->get_arg();
     190                        } else if ( UntypedExpr *untypedExpr = dynamic_cast< UntypedExpr* >( expr ) ) {
     191                                // look for compiler-inserted dereference operator
     192                                NameExpr *fn = dynamic_cast< NameExpr* >( untypedExpr->get_function() );
     193                                if ( ! fn || fn->get_name() != std::string("*?") ) return 0;
     194                                expr = *untypedExpr->begin_args();
     195                        } else break;
     196
     197                        ++(*levels);
     198                }
     199
     200                return 0;
     201        }
     202
     203        void makeTyVarMap( Type *type, TyVarMap &tyVarMap ) {
     204                for ( std::list< TypeDecl* >::const_iterator tyVar = type->get_forall().begin(); tyVar != type->get_forall().end(); ++tyVar ) {
     205                        assert( *tyVar );
     206                        tyVarMap[ (*tyVar)->get_name() ] = (*tyVar)->get_kind();
     207                }
     208                if ( PointerType *pointer = dynamic_cast< PointerType* >( type ) ) {
     209                        makeTyVarMap( pointer->get_base(), tyVarMap );
     210                }
     211        }
     212       
    160213        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) {
    161214                for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) {
     
    172225                return std::string( "_alignof_" ) + SymTab::Mangler::mangleType( ty );
    173226        }
     227
     228        std::string offsetofName( Type* ty ) {
     229                return std::string( "_offsetof_" ) + SymTab::Mangler::mangleType( ty );
     230        }
     231
    174232} // namespace GenPoly
    175233
Note: See TracChangeset for help on using the changeset viewer.