Ignore:
Timestamp:
Nov 25, 2015, 2:53:26 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
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:
32d281d, 704c9dd
Parents:
02ec390 (diff), 5189888 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/GenPoly.cc

    r02ec390 r7e23d0a  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 07:37:46 2015
    13 // Update Count     : 1
     12// Last Modified On : Thu Nov 19 17:23:44 2015
     13// Update Count     : 10
    1414//
    1515
     
    2121
    2222namespace GenPoly {
    23         // interface functions
    24         bool isPolyVal( Type *type, const TyVarMap &tyVars ) {
    25                 return isPolyVal( type, tyVars, false );
     23        // A function needs an adapter if it returns a polymorphic value or if any of its
     24        // parameters have polymorphic type
     25        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) {
     26                if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
     27                        return true;
     28                } // if
     29                for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); innerArg != adaptee->get_parameters().end(); ++innerArg ) {
     30                        if ( isPolyVal( (*innerArg)->get_type(), tyVars ) ) {
     31                                return true;
     32                        } // if
     33                } // for
     34                return false;
    2635        }
    2736
    28         bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 
    29                 return needsAdapter( adaptee, tyVars, false );
     37        bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ) {
     38                bool doTransform = false;
     39                if ( ! function->get_returnVals().empty() ) {
     40                        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( function->get_returnVals().front()->get_type() ) ) {
     41       
     42                                // figure out if the return type is specified by a type parameter
     43                                for ( std::list< TypeDecl *>::const_iterator tyVar = function->get_forall().begin(); tyVar != function->get_forall().end(); ++tyVar ) {
     44                                        if ( (*tyVar)->get_name() == typeInst->get_name() ) {
     45                                                doTransform = true;
     46                                                name = typeInst->get_name();
     47                                                break;
     48                                        } // if
     49                                } // for
     50                                if ( ! doTransform && otherTyVars.find( typeInst->get_name() ) != otherTyVars.end() ) {
     51                                        doTransform = true;
     52                                } // if
     53                        } // if
     54                } // if
     55                return doTransform;
    3056        }
    3157
    32         bool isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars ) {
    33                 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) {
     58        bool isPolyRet( FunctionType *function, std::string &name ) {
     59                TyVarMap dummyTyVars;
     60                return isPolyRet( function, name, dummyTyVars );
     61        }
     62
     63        bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars ) {
     64                std::string dummyString;
     65                return isPolyRet( function, dummyString, otherTyVars );
     66        }
     67
     68        bool isPolyVal( Type *type, const TyVarMap &tyVars ) {
     69                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
    3470                        if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
    3571                                return true;
    3672                        } // if
    37                         return considerAllTyVars;
    3873                } // if
    3974                return false;
    40         }
    41 
    42         // A function needs an adapter if it returns a polymorphic value or if any of its
    43         // parameters have polymorphic type
    44         bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars ) {
    45                 bool needsAdapter = false;
    46                 if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars, considerAllTyVars ) ) {
    47                         needsAdapter = true;
    48                 } // if
    49                 for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); ! needsAdapter && innerArg != adaptee->get_parameters().end(); ++innerArg ) {
    50                         if ( isPolyVal( (*innerArg)->get_type(), tyVars, considerAllTyVars ) ) {
    51                                 needsAdapter = true;
    52                         } // if
    53                 } // for
    54                 return needsAdapter;
    5575        }
    5676
Note: See TracChangeset for help on using the changeset viewer.