Ignore:
Timestamp:
Aug 8, 2016, 3:44:56 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, 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:
ce76eb9
Parents:
752dc70
Message:

Dtypes now erased on dtype-only generic types, tests pass, build produces many warnings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/GenPoly.cc

    r752dc70 r3bb195cb  
    2323
    2424namespace GenPoly {
    25         bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) {
    26                 if ( ! adaptee->get_returnVals().empty() && isPolyType( 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 ( isPolyType( (*innerArg)->get_type(), tyVars ) ) {
    31                                 return true;
    32                         } // if
    33                 } // for
    34                 return false;
    35         }
    36 
    37         ReferenceToType *isPolyRet( FunctionType *function ) {
    38                 if ( ! function->get_returnVals().empty() ) {
    39                         TyVarMap forallTypes( (TypeDecl::Kind)-1 );
    40                         makeTyVarMap( function, forallTypes );
    41                         return (ReferenceToType*)isPolyType( function->get_returnVals().front()->get_type(), forallTypes );
    42                 } // if
    43                 return 0;
    44         }
    45 
    4625        namespace {
    4726                /// Checks a parameter list for polymorphic parameters; will substitute according to env if present
     
    6443                        return false;
    6544                }
     45
     46                /// Checks a parameter list for dynamic-layout parameters from tyVars; will substitute according to env if present
     47                bool hasDynParams( std::list< Expression* >& params, const TyVarMap &tyVars, const TypeSubstitution *env ) {
     48                        for ( std::list< Expression* >::iterator param = params.begin(); param != params.end(); ++param ) {
     49                                TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
     50                                assert(paramType && "Aggregate parameters should be type expressions");
     51                                if ( isDynType( paramType->get_type(), tyVars, env ) ) return true;
     52                        }
     53                        return false;
     54                }
    6655        }
    6756
     
    10190                }
    10291                return 0;
     92        }
     93
     94        Type *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
     95                type = replaceTypeInst( type, env );
     96
     97                if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
     98                        auto var = tyVars.find( typeInst->get_name() );
     99                        if ( var != tyVars.end() && var->second == TypeDecl::Any ) {
     100                                return type;
     101                        }
     102                } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) {
     103                        if ( hasDynParams( structType->get_parameters(), tyVars, env ) ) return type;
     104                } else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( type ) ) {
     105                        if ( hasDynParams( unionType->get_parameters(), tyVars, env ) ) return type;
     106                }
     107                return 0;
     108        }
     109
     110        ReferenceToType *isDynRet( FunctionType *function, const TyVarMap &forallTypes ) {
     111                if ( function->get_returnVals().empty() ) return 0;
     112               
     113                return (ReferenceToType*)isDynType( function->get_returnVals().front()->get_type(), forallTypes );
     114        }
     115
     116        ReferenceToType *isDynRet( FunctionType *function ) {
     117                if ( function->get_returnVals().empty() ) return 0;
     118
     119                TyVarMap forallTypes( (TypeDecl::Kind)-1 );
     120                makeTyVarMap( function, forallTypes );
     121                return (ReferenceToType*)isDynType( function->get_returnVals().front()->get_type(), forallTypes );
     122        }
     123
     124        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) {
     125//              if ( ! adaptee->get_returnVals().empty() && isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
     126//                      return true;
     127//              } // if
     128                if ( isDynRet( adaptee, tyVars ) ) return true;
     129               
     130                for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); innerArg != adaptee->get_parameters().end(); ++innerArg ) {
     131//                      if ( isPolyType( (*innerArg)->get_type(), tyVars ) ) {
     132                        if ( isDynType( (*innerArg)->get_type(), tyVars ) ) {
     133                                return true;
     134                        } // if
     135                } // for
     136                return false;
    103137        }
    104138
Note: See TracChangeset for help on using the changeset viewer.