Changeset 0f889a77
- Timestamp:
- Dec 16, 2015, 3:21:05 PM (9 years ago)
- 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:
- 7754cde
- Parents:
- 8360977
- Location:
- src/GenPoly
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/GenPoly.cc
r8360977 r0f889a77 68 68 69 69 namespace { 70 /// Checks a parameter list for polymorphic parameters 70 /// Checks a parameter list for polymorphic parameters; will substitute according to env if present 71 bool hasPolyParams( std::list< Expression* >& params, const TypeSubstitution *env ) { 72 for ( std::list< Expression* >::iterator param = params.begin(); param != params.end(); ++param ) { 73 TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param ); 74 assert(paramType && "Aggregate parameters should be type expressions"); 75 if ( isPolyType( paramType->get_type(), env ) ) return true; 76 } 77 return false; 78 } 79 80 /// Checks a parameter list for polymorphic parameters from tyVars; will substitute according to env if present 71 81 bool hasPolyParams( std::list< Expression* >& params, const TyVarMap &tyVars, const TypeSubstitution *env ) { 72 82 for ( std::list< Expression* >::iterator param = params.begin(); param != params.end(); ++param ) { … … 78 88 } 79 89 } 90 91 Type *isPolyType( Type *type, const TypeSubstitution *env ) { 92 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) { 93 if ( env ) { 94 if ( Type *newType = env->lookup( typeInst->get_name() ) ) { 95 return isPolyType( newType, env ); 96 } // if 97 } // if 98 return type; 99 } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) { 100 if ( hasPolyParams( structType->get_parameters(), env ) ) return type; 101 } else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( type ) ) { 102 if ( hasPolyParams( unionType->get_parameters(), env ) ) return type; 103 } 104 return 0; 105 } 80 106 81 107 Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) { … … 84 110 if ( Type *newType = env->lookup( typeInst->get_name() ) ) { 85 111 return isPolyType( newType, tyVars, env ); 112 } // if 86 113 } // if 87 } // if88 114 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 89 115 return type; 90 }116 } 91 117 } else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) { 92 118 if ( hasPolyParams( structType->get_parameters(), tyVars, env ) ) return type; … … 97 123 } 98 124 125 Type *isPolyPtr( Type *type, const TypeSubstitution *env ) { 126 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { 127 return isPolyType( ptr->get_base(), env ); 128 } else if ( env ) { 129 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) { 130 if ( Type *newType = env->lookup( typeInst->get_name() ) ) { 131 return isPolyPtr( newType, env ); 132 } // if 133 } // if 134 } // if 135 return 0; 136 } 137 99 138 Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) { 100 139 if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) { -
src/GenPoly/GenPoly.h
r8360977 r0f889a77 37 37 38 38 /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided 39 Type *isPolyType( Type *type, const TypeSubstitution *env = 0 ); 40 41 /// returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided 39 42 Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 ); 40 43 41 44 /// returns polymorphic type if is pointer to polymorphic type, NULL otherwise; will look up substitution in env if provided 45 Type *isPolyPtr( Type *type, const TypeSubstitution *env = 0 ); 46 47 /// returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided 42 48 Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 ); 43 49
Note: See TracChangeset
for help on using the changeset viewer.