Changes in src/GenPoly/Box.cc [c29d9ce:f6d7e0f]
- File:
-
- 1 edited
-
src/GenPoly/Box.cc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
rc29d9ce rf6d7e0f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Aug 11 16:22:35201513 // Update Count : 8912 // Last Modified On : Wed Jun 24 16:19:07 2015 13 // Update Count : 10 14 14 // 15 15 … … 77 77 Expression *handleIntrinsics( ApplicationExpr *appExpr ); 78 78 ObjectDecl *makeTemporary( Type *type ); 79 79 80 std::map< std::string, DeclarationWithType *> assignOps; 80 81 typedef std::map< std::string, FunctionDecl *> AdapterMap; 81 std::map< std::string, DeclarationWithType *> assignOps;82 82 std::stack< AdapterMap > adapters; 83 83 DeclarationWithType *retval; … … 170 170 } 171 171 172 bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars ) {173 std::string dummyString;174 return isPolyRet( function, dummyString, otherTyVars );175 }176 177 172 Pass1::Pass1() 178 173 : useRetval( false ), tempNamer( "_temp" ) { … … 209 204 } 210 205 211 DeclarationWithType *Pass1::mutate( FunctionDecl *functionDecl ) { 206 DeclarationWithType * 207 Pass1::mutate( FunctionDecl *functionDecl ) { 212 208 if ( functionDecl->get_statements() ) { 213 209 TyVarMap oldtyVars = scopeTyVars; … … 531 527 } 532 528 533 void Pass1::passAdapters( ApplicationExpr * appExpr, FunctionType * functionType, const TyVarMap & exprTyVars ) { 534 // collect a list of function types passed as parameters or implicit parameters (assertions) 529 void Pass1::passAdapters( ApplicationExpr *appExpr, FunctionType *functionType, const TyVarMap &exprTyVars ) { 535 530 std::list< DeclarationWithType *> ¶mList = functionType->get_parameters(); 536 531 std::list< FunctionType *> functions; … … 543 538 findFunction( (*arg)->get_type(), functions, exprTyVars, needsAdapter ); 544 539 } // for 545 546 // parameter function types for which an appropriate adapter has been generated.547 // we cannot use the types after applying substitutions, since two different548 // parameter types may be unified to the same type549 540 std::set< std::string > adaptersDone; 550 551 541 for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) { 552 FunctionType *originalFunction = (*funType)->clone();553 542 FunctionType *realFunction = (*funType)->clone(); 543 assert( env ); 544 env->apply( realFunction ); 545 554 546 std::string mangleName = SymTab::Mangler::mangle( realFunction ); 555 556 // only attempt to create an adapter or pass one as a parameter if we haven't557 // already done so for this pre-substitution parameter function type.558 547 if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) { 559 std::string mangleName = SymTab::Mangler::mangle( realFunction ); 560 adaptersDone.insert( adaptersDone.begin(), mangleName ); 561 562 // apply substitution to type variables to figure out what the 563 // adapter's type should look like 564 assert( env ); 565 env->apply( realFunction ); 566 mangleName = SymTab::Mangler::mangle( realFunction ); 548 AdapterMap & adapters = Pass1::adapters.top(); 549 AdapterMap::iterator adapter = adapters.find( mangleName ); 567 550 568 551 if ( needsAdapter( realFunction, exprTyVars, true ) ) { … … 571 554 // create a new adapter. 572 555 appExpr->get_args().push_front( new NameExpr( makeAdapterName ( mangleName ) ) ); 573 } else { 574 if ( isPolyRet( originalFunction, exprTyVars ) ) { 575 // if the return type involved polymorphic types, then 576 // the adapter will need to take those polymorphic types 577 // as pointers. Therefore, there can be two different 578 // functions with the same mangled name, so we need two adapter map 579 // stacks and also we need the mangled names to be different. 580 mangleName += "polyret_"; 581 } 582 583 AdapterMap & adapters = Pass1::adapters.top(); 584 AdapterMap::iterator adapter = adapters.find( mangleName ); 585 if ( adapter == adapters.end() ) { 586 // adapter has not been created yet in the current scope, so define it 587 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars ); 588 adapter = adapters.insert( adapters.begin(), std::pair< std::string, FunctionDecl *>( mangleName, newAdapter ) ); 589 stmtsToAdd.push_back( new DeclStmt( noLabels, newAdapter ) ); 590 } // if 591 assert( adapter != adapters.end() ); 592 593 // add the appropriate adapter as a parameter 594 appExpr->get_args().push_front( new VariableExpr( adapter->second ) ); 595 } // if 556 continue; 557 } else if ( adapter == adapters.end() ) { 558 FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars ); 559 adapter = adapters.insert( adapters.begin(), std::pair< std::string, FunctionDecl *>( mangleName, newAdapter ) ); 560 stmtsToAdd.push_back( new DeclStmt( noLabels, newAdapter ) ); 561 } // if 562 assert( adapter != adapters.end() ); 563 appExpr->get_args().push_front( new VariableExpr( adapter->second ) ); 564 // appExpr->get_args().push_front( new NameExpr( makeAdapterName ( mangleName ) ) ); 565 adaptersDone.insert( adaptersDone.begin(), mangleName ); 596 566 } // if 597 567 } // for … … 911 881 912 882 void Pass1::doBeginScope() { 913 // actually, maybe this could (should?) push914 // a copy of the current map915 883 adapters.push(AdapterMap()); 916 884 } … … 1084 1052 if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) { 1085 1053 if ( isPolyVal( objectDecl->get_type(), scopeTyVars ) ) { 1086 // change initialization of a polymorphic value object1087 // to allocate storage with alloca1088 1054 TypeInstType *typeInst = dynamic_cast< TypeInstType *>( objectDecl->get_type() ); 1089 1055 assert( typeInst ); 1090 1056 UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) ); 1091 1057 alloc->get_args().push_back( new NameExpr( typeInst->get_name() ) ); 1092 1093 delete objectDecl->get_init(); 1094 1095 std::list<Expression*> designators; 1096 objectDecl->set_init( new SingleInit( alloc, designators ) ); 1058 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 1059 assign->get_args().push_back( new VariableExpr( objectDecl ) ); 1060 assign->get_args().push_back( alloc ); 1061 stmtsToAddAfter.push_back( new ExprStmt( noLabels, assign ) ); 1097 1062 } 1098 1063 }
Note:
See TracChangeset
for help on using the changeset viewer.