Changeset aadc9a4


Ignore:
Timestamp:
Jan 12, 2016, 6:12:10 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:
4d7e8f5
Parents:
ebe9b3a
Message:

Refactor isPolyRet to include generic return types

Location:
src/GenPoly
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    rebe9b3a raadc9a4  
    231231                                // process polymorphic return value
    232232                                retval = 0;
    233                                 std::string typeName;
    234                                 if ( isPolyRet( functionDecl->get_functionType(), typeName ) && functionDecl->get_linkage() == LinkageSpec::Cforall ) {
     233                                if ( isPolyRet( functionDecl->get_functionType() ) && functionDecl->get_linkage() == LinkageSpec::Cforall ) {
    235234                                        retval = functionDecl->get_functionType()->get_returnVals().front();
    236235
     
    787786                        std::list< Expression *>::iterator paramBegin = appExpr->get_args().begin();
    788787
    789                         std::string typeName;
    790                         if ( isPolyRet( function, typeName ) ) {
    791                                 ret = addPolyRetParam( appExpr, function, typeName, arg );
     788                        if ( ReferenceToType *polyType = isPolyRet( function ) ) {
     789                                ret = addPolyRetParam( appExpr, function, polyType->get_name(), arg );
    792790                        } else if ( needsAdapter( function, scopeTyVars ) ) {
    793791                                // std::cerr << "needs adapter: ";
     
    994992
    995993                        // move polymorphic return type to parameter list
    996                         std::string typeName;
    997                         if ( isPolyRet( funcType, typeName ) ) {
     994                        if ( isPolyRet( funcType ) ) {
    998995                                DeclarationWithType *ret = funcType->get_returnVals().front();
    999996                                ret->set_type( new PointerType( Type::Qualifiers(), ret->get_type() ) );
  • src/GenPoly/GenPoly.cc

    rebe9b3a raadc9a4  
    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
     40                        TyVarMap forallTypes;
     41                        makeTyVarMap( function, forallTypes );
     42                        return (ReferenceToType*)isPolyType( function->get_returnVals().front()->get_type(), forallTypes );
    5543                } // 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 );
     44                return 0;
    6745        }
    6846
     
    158136        }
    159137
     138        void makeTyVarMap( Type *type, TyVarMap &tyVarMap ) {
     139                for ( std::list< TypeDecl* >::const_iterator tyVar = type->get_forall().begin(); tyVar != type->get_forall().end(); ++tyVar ) {
     140                        assert( *tyVar );
     141                        tyVarMap[ (*tyVar)->get_name() ] = (*tyVar)->get_kind();
     142                }
     143                if ( PointerType *pointer = dynamic_cast< PointerType* >( type ) ) {
     144                        makeTyVarMap( pointer->get_base(), tyVarMap );
     145                }
     146        }
     147       
    160148        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) {
    161149                for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) {
  • src/GenPoly/GenPoly.h

    rebe9b3a raadc9a4  
    2222
    2323#include "SynTree/Declaration.h"
     24#include "SynTree/Type.h"
    2425#include "SynTree/TypeSubstitution.h"
    2526
     
    3233
    3334        /// true iff function has polymorphic return type
    34         bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars );
    35         bool isPolyRet( FunctionType *function, std::string &name );
    36         bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars );
     35        ReferenceToType *isPolyRet( FunctionType *function );
    3736
    3837        /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided
     
    5150        FunctionType * getFunctionType( Type *ty );
    5251
     52        /// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `tyVarMap`
     53        void makeTyVarMap( Type *type, TyVarMap &tyVarMap );
     54       
    5355        /// Prints type variable map
    5456        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
  • src/GenPoly/PolyMutator.cc

    rebe9b3a raadc9a4  
    152152        }
    153153
    154 
    155         /* static class method */
    156         void PolyMutator::makeTyVarMap( Type *type, TyVarMap &tyVarMap ) {
    157                 for ( std::list< TypeDecl* >::const_iterator tyVar = type->get_forall().begin(); tyVar != type->get_forall().end(); ++tyVar ) {
    158                         assert( *tyVar );
    159                         tyVarMap[ (*tyVar)->get_name() ] = (*tyVar)->get_kind();
    160                 }
    161                 if ( PointerType *pointer = dynamic_cast< PointerType* >( type ) ) {
    162                         makeTyVarMap( pointer->get_base(), tyVarMap );
    163                 }
    164         }
    165154} // namespace GenPoly
    166155
  • src/GenPoly/PolyMutator.h

    rebe9b3a raadc9a4  
    5151                virtual void doBeginScope() {}
    5252                virtual void doEndScope() {}
    53                
    54                 static void makeTyVarMap( Type *type, TyVarMap &tyVarMap );
    5553          protected:
    5654                void mutateStatementList( std::list< Statement* > &statements );
Note: See TracChangeset for help on using the changeset viewer.