Changeset a32b204 for translator/GenPoly/Specialize.cc
- Timestamp:
- May 17, 2015, 1:19:35 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:
- 0dd3a2f
- Parents:
- b87a5ed
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/GenPoly/Specialize.cc
rb87a5ed ra32b204 61 61 needsSpecialization( Type *formalType, Type *actualType, TypeSubstitution *env ) 62 62 { 63 if ( env ) {63 if ( env ) { 64 64 using namespace ResolvExpr; 65 65 OpenVarSet openVars, closedVars; … … 67 67 findOpenVars( formalType, openVars, closedVars, need, have, false ); 68 68 findOpenVars( actualType, openVars, closedVars, need, have, true ); 69 for ( OpenVarSet::const_iterator openVar = openVars.begin(); openVar != openVars.end(); ++openVar ) {69 for ( OpenVarSet::const_iterator openVar = openVars.begin(); openVar != openVars.end(); ++openVar ) { 70 70 Type *boundType = env->lookup( openVar->first ); 71 if ( !boundType ) continue;72 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( boundType ) ) {73 if ( closedVars.find( typeInst->get_name() ) == closedVars.end() ) {71 if ( ! boundType ) continue; 72 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( boundType ) ) { 73 if ( closedVars.find( typeInst->get_name() ) == closedVars.end() ) { 74 74 return true; 75 75 } … … 87 87 Specialize::doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams ) 88 88 { 89 if ( needsSpecialization( formalType, actual->get_results().front(), env ) ) {89 if ( needsSpecialization( formalType, actual->get_results().front(), env ) ) { 90 90 PointerType *ptrType; 91 91 FunctionType *funType; 92 if ( ( ptrType = dynamic_cast< PointerType* >( formalType ) ) && ( funType = dynamic_cast< FunctionType* >( ptrType->get_base() ) ) ) {92 if ( ( ptrType = dynamic_cast< PointerType* >( formalType ) ) && ( funType = dynamic_cast< FunctionType* >( ptrType->get_base() ) ) ) { 93 93 FunctionType *newType = funType->clone(); 94 if ( env ) {94 if ( env ) { 95 95 TypeSubstitution newEnv( *env ); 96 96 // it is important to replace only occurrences of type variables that occur free in the … … 103 103 UniqueName paramNamer( paramPrefix ); 104 104 ApplicationExpr *appExpr = new ApplicationExpr( actual ); 105 for ( std::list< DeclarationWithType* >::iterator param = thunkFunc->get_functionType()->get_parameters().begin(); param != thunkFunc->get_functionType()->get_parameters().end(); ++param ) {105 for ( std::list< DeclarationWithType* >::iterator param = thunkFunc->get_functionType()->get_parameters().begin(); param != thunkFunc->get_functionType()->get_parameters().end(); ++param ) { 106 106 (*param)->set_name( paramNamer.newName() ); 107 107 appExpr->get_args().push_back( new VariableExpr( *param ) ); 108 108 } 109 109 appExpr->set_env( maybeClone( env ) ); 110 if ( inferParams ) {110 if ( inferParams ) { 111 111 appExpr->get_inferParams() = *inferParams; 112 112 } … … 123 123 124 124 Statement *appStmt; 125 if ( funType->get_returnVals().empty() ) {125 if ( funType->get_returnVals().empty() ) { 126 126 appStmt = new ExprStmt( noLabels, appExpr ); 127 127 } else { … … 143 143 { 144 144 // create thunks for the explicit parameters 145 assert( ! appExpr->get_function()->get_results().empty() );145 assert( ! appExpr->get_function()->get_results().empty() ); 146 146 PointerType *pointer = dynamic_cast< PointerType* >( appExpr->get_function()->get_results().front() ); 147 147 assert( pointer ); … … 149 149 std::list< DeclarationWithType* >::iterator formal; 150 150 std::list< Expression* >::iterator actual; 151 for ( formal = function->get_parameters().begin(), actual = appExpr->get_args().begin(); formal != function->get_parameters().end() && actual != appExpr->get_args().end(); ++formal, ++actual ) {151 for ( formal = function->get_parameters().begin(), actual = appExpr->get_args().begin(); formal != function->get_parameters().end() && actual != appExpr->get_args().end(); ++formal, ++actual ) { 152 152 *actual = doSpecialization( (*formal)->get_type(), *actual, &appExpr->get_inferParams() ); 153 153 } … … 161 161 162 162 // create thunks for the inferred parameters 163 for ( InferredParams::iterator inferParam = appExpr->get_inferParams().begin(); inferParam != appExpr->get_inferParams().end(); ++inferParam ) {163 for ( InferredParams::iterator inferParam = appExpr->get_inferParams().begin(); inferParam != appExpr->get_inferParams().end(); ++inferParam ) { 164 164 inferParam->second.expr = doSpecialization( inferParam->second.formalType, inferParam->second.expr, &appExpr->get_inferParams() ); 165 165 }
Note: See TracChangeset
for help on using the changeset viewer.