Changes in / [49205cf:448f9b2]
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r49205cf r448f9b2 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sat May 16 23:52:08 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu May 21 16:21:09201513 // Update Count : 1211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat May 16 23:55:30 2015 13 // Update Count : 3 14 14 // 15 15 … … 107 107 PRINT( 108 108 std::cout << "cost " << candidate->cost << " beats " << mapPlace->second.candidate->cost << std::endl; 109 )110 selected[ mangleName ] = current;109 ) 110 selected[ mangleName ] = current; 111 111 } else if ( candidate->cost == mapPlace->second.candidate->cost ) { 112 112 PRINT( 113 113 std::cout << "marking ambiguous" << std::endl; 114 )115 mapPlace->second.isAmbiguous = true;114 ) 115 mapPlace->second.isAmbiguous = true; 116 116 } 117 117 } else { … … 122 122 PRINT( 123 123 std::cout << "there are " << selected.size() << " alternatives before elimination" << std::endl; 124 ) 125 126 // accept the alternatives that were unambiguous 127 for ( std::map< std::string, PruneStruct >::iterator target = selected.begin(); target != selected.end(); ++target ) { 128 if ( ! target->second.isAmbiguous ) { 129 Alternative &alt = *target->second.candidate; 130 for ( std::list< Type* >::iterator result = alt.expr->get_results().begin(); result != alt.expr->get_results().end(); ++result ) { 131 alt.env.applyFree( *result ); 124 ) 125 126 // accept the alternatives that were unambiguous 127 for ( std::map< std::string, PruneStruct >::iterator target = selected.begin(); target != selected.end(); ++target ) { 128 if ( ! target->second.isAmbiguous ) { 129 Alternative &alt = *target->second.candidate; 130 for ( std::list< Type* >::iterator result = alt.expr->get_results().begin(); result != alt.expr->get_results().end(); ++result ) { 131 alt.env.applyFree( *result ); 132 } 133 *out++ = alt; 132 134 } 133 *out++ = alt;134 135 } 135 }136 136 137 137 } … … 183 183 std::cout << "findSubExprs" << std::endl; 184 184 printAlts( finder.alternatives, std::cout ); 185 )186 *out++ = finder;185 ) 186 *out++ = finder; 187 187 } 188 188 } … … 205 205 std::cout << "alternatives before prune:" << std::endl; 206 206 printAlts( alternatives, std::cout ); 207 )208 AltList::iterator oldBegin = alternatives.begin();207 ) 208 AltList::iterator oldBegin = alternatives.begin(); 209 209 pruneAlternatives( alternatives.begin(), alternatives.end(), front_inserter( alternatives ), indexer ); 210 210 if ( alternatives.begin() == oldBegin ) { … … 221 221 PRINT( 222 222 std::cout << "there are " << alternatives.size() << " alternatives after elimination" << std::endl; 223 )224 }223 ) 224 } 225 225 226 226 void AlternativeFinder::findWithAdjustment( Expression *expr ) { … … 264 264 std::cout << "--- results are" << std::endl; 265 265 printAll( (*actualExpr)->get_results(), std::cout, 8 ); 266 )267 std::list< DeclarationWithType* >::iterator startFormal = formal;266 ) 267 std::list< DeclarationWithType* >::iterator startFormal = formal; 268 268 Cost actualCost; 269 269 for ( std::list< Type* >::iterator actual = (*actualExpr)->get_results().begin(); actual != (*actualExpr)->get_results().end(); ++actual ) { … … 281 281 std::cout << std::endl << " to "; 282 282 (*formal)->get_type()->print( std::cout, 8 ); 283 )284 Cost newCost = conversionCost( *actual, (*formal)->get_type(), indexer, alt.env );283 ) 284 Cost newCost = conversionCost( *actual, (*formal)->get_type(), indexer, alt.env ); 285 285 PRINT( 286 286 std::cout << std::endl << "cost is" << newCost << std::endl; 287 )288 289 if ( newCost == Cost::infinity ) {290 return newCost;291 }287 ) 288 289 if ( newCost == Cost::infinity ) { 290 return newCost; 291 } 292 292 convCost += newCost; 293 293 actualCost += newCost; … … 381 381 (*actual)->print( std::cerr ); 382 382 std::cerr << std::endl; 383 )384 if ( ! unify( (*formal)->get_type(), *actual, resultEnv, resultNeed, resultHave, openVars, indexer ) ) {385 return false;386 }383 ) 384 if ( ! unify( (*formal)->get_type(), *actual, resultEnv, resultNeed, resultHave, openVars, indexer ) ) { 385 return false; 386 } 387 387 formal++; 388 388 } … … 429 429 std::cerr << "recursing with new set:" << std::endl; 430 430 printAssertionSet( newNeed, std::cerr, 8 ); 431 )432 inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, level+1, indexer, out );431 ) 432 inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, level+1, indexer, out ); 433 433 return; 434 434 } … … 444 444 curDecl->print( std::cerr ); 445 445 std::cerr << std::endl; 446 )447 std::list< DeclarationWithType* > candidates;446 ) 447 std::list< DeclarationWithType* > candidates; 448 448 decls.lookupId( curDecl->get_name(), candidates ); 449 449 /// if ( candidates.empty() ) { std::cout << "no candidates!" << std::endl; } … … 453 453 (*candidate)->print( std::cout ); 454 454 std::cout << std::endl; 455 )456 AssertionSet newHave, newerNeed( newNeed );455 ) 456 AssertionSet newHave, newerNeed( newNeed ); 457 457 TypeEnvironment newEnv( newAlt.env ); 458 458 OpenVarSet newOpenVars( openVars ); … … 466 466 adjType->print( std::cerr ); 467 467 std::cerr << std::endl; 468 )469 if ( unify( curDecl->get_type(), adjType, newEnv, newerNeed, newHave, newOpenVars, indexer ) ) {470 PRINT(471 std::cerr << "success!" << std::endl;472 468 ) 473 SymTab::Indexer newDecls( decls ); 474 addToIndexer( newHave, newDecls ); 475 Alternative newerAlt( newAlt ); 476 newerAlt.env = newEnv; 477 assert( (*candidate)->get_uniqueId() ); 478 Expression *varExpr = new VariableExpr( static_cast< DeclarationWithType* >( Declaration::declFromId( (*candidate)->get_uniqueId() ) ) ); 479 deleteAll( varExpr->get_results() ); 480 varExpr->get_results().clear(); 481 varExpr->get_results().push_front( adjType->clone() ); 482 PRINT( 483 std::cout << "satisfying assertion " << curDecl->get_uniqueId() << " "; 484 curDecl->print( std::cout ); 485 std::cout << " with declaration " << (*candidate)->get_uniqueId() << " "; 486 (*candidate)->print( std::cout ); 487 std::cout << std::endl; 488 ) 489 ApplicationExpr *appExpr = static_cast< ApplicationExpr* >( newerAlt.expr ); 490 // XXX: this is a memory leak, but adjType can't be deleted because it might contain assertions 491 appExpr->get_inferParams()[ curDecl->get_uniqueId() ] = ParamEntry( (*candidate)->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr ); 492 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, level, indexer, out ); 493 } else { 494 delete adjType; 495 } 469 if ( unify( curDecl->get_type(), adjType, newEnv, newerNeed, newHave, newOpenVars, indexer ) ) { 470 PRINT( 471 std::cerr << "success!" << std::endl; 472 ) 473 SymTab::Indexer newDecls( decls ); 474 addToIndexer( newHave, newDecls ); 475 Alternative newerAlt( newAlt ); 476 newerAlt.env = newEnv; 477 assert( (*candidate)->get_uniqueId() ); 478 Expression *varExpr = new VariableExpr( static_cast< DeclarationWithType* >( Declaration::declFromId( (*candidate)->get_uniqueId() ) ) ); 479 deleteAll( varExpr->get_results() ); 480 varExpr->get_results().clear(); 481 varExpr->get_results().push_front( adjType->clone() ); 482 PRINT( 483 std::cout << "satisfying assertion " << curDecl->get_uniqueId() << " "; 484 curDecl->print( std::cout ); 485 std::cout << " with declaration " << (*candidate)->get_uniqueId() << " "; 486 (*candidate)->print( std::cout ); 487 std::cout << std::endl; 488 ) 489 ApplicationExpr *appExpr = static_cast< ApplicationExpr* >( newerAlt.expr ); 490 // XXX: this is a memory leak, but adjType can't be deleted because it might contain assertions 491 appExpr->get_inferParams()[ curDecl->get_uniqueId() ] = ParamEntry( (*candidate)->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr ); 492 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, level, indexer, out ); 493 } else { 494 delete adjType; 495 } 496 496 } 497 497 } … … 509 509 std::cout << "============= new indexer" << std::endl; 510 510 decls.print( std::cout ); 511 )512 addToIndexer( have, decls );511 ) 512 addToIndexer( have, decls ); 513 513 AssertionSet newNeed; 514 514 inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, 0, indexer, out ); … … 533 533 std::cout << "need assertions:" << std::endl; 534 534 printAssertionSet( resultNeed, std::cout, 8 ); 535 )536 inferParameters( resultNeed, resultHave, newAlt, openVars, out );535 ) 536 inferParameters( resultNeed, resultHave, newAlt, openVars, out ); 537 537 } 538 538 } … … 570 570 std::cout << "working on alternative: " << std::endl; 571 571 func->print( std::cout, 8 ); 572 )573 // check if the type is pointer to function574 PointerType *pointer;572 ) 573 // check if the type is pointer to function 574 PointerType *pointer; 575 575 if ( func->expr->get_results().size() == 1 && ( pointer = dynamic_cast< PointerType* >( func->expr->get_results().front() ) ) ) { 576 576 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) { … … 603 603 std::cout << "known function ops:" << std::endl; 604 604 printAlts( funcOpFinder.alternatives, std::cout, 8 ); 605 )606 }605 ) 606 } 607 607 608 608 for ( AltList::const_iterator funcOp = funcOpFinder.alternatives.begin(); funcOp != funcOpFinder.alternatives.end(); ++funcOp ) { … … 642 642 withFunc->env.print( std::cout, 8 ); 643 643 std::cout << "cost of conversion is:" << cvtCost << std::endl; 644 )645 if ( cvtCost != Cost::infinity ) {646 withFunc->cvtCost = cvtCost;647 alternatives.push_back( *withFunc );648 } // if644 ) 645 if ( cvtCost != Cost::infinity ) { 646 withFunc->cvtCost = cvtCost; 647 alternatives.push_back( *withFunc ); 648 } // if 649 649 } // for 650 650 candidates.clear(); … … 737 737 indexer.lookupId( nameExpr->get_name(), declList ); 738 738 PRINT( std::cerr << "nameExpr is " << nameExpr->get_name() << std::endl; ) 739 for ( std::list< DeclarationWithType* >::iterator i = declList.begin(); i != declList.end(); ++i ) {740 VariableExpr newExpr( *i, nameExpr->get_argName() );741 alternatives.push_back( Alternative( newExpr.clone(), env, Cost() ) );742 PRINT(743 std::cerr << "decl is ";744 (*i)->print( std::cerr );745 std::cerr << std::endl;746 std::cerr << "newExpr is ";747 newExpr.print( std::cerr );748 std::cerr << std::endl;749 )750 renameTypes( alternatives.back().expr );751 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( (*i)->get_type() ) ) {752 addAggMembers( structInst, &newExpr, Cost( 0, 0, 1 ), "" );753 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( (*i)->get_type() ) ) {754 addAggMembers( unionInst, &newExpr, Cost( 0, 0, 1 ), "" );755 } // if756 } // for739 for ( std::list< DeclarationWithType* >::iterator i = declList.begin(); i != declList.end(); ++i ) { 740 VariableExpr newExpr( *i, nameExpr->get_argName() ); 741 alternatives.push_back( Alternative( newExpr.clone(), env, Cost() ) ); 742 PRINT( 743 std::cerr << "decl is "; 744 (*i)->print( std::cerr ); 745 std::cerr << std::endl; 746 std::cerr << "newExpr is "; 747 newExpr.print( std::cerr ); 748 std::cerr << std::endl; 749 ) 750 renameTypes( alternatives.back().expr ); 751 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( (*i)->get_type() ) ) { 752 addAggMembers( structInst, &newExpr, Cost( 0, 0, 1 ), "" ); 753 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( (*i)->get_type() ) ) { 754 addAggMembers( unionInst, &newExpr, Cost( 0, 0, 1 ), "" ); 755 } // if 756 } // for 757 757 } 758 758 … … 794 794 argType->print( std::cout ); 795 795 std::cout << std::endl; 796 )797 if ( typesCompatibleIgnoreQualifiers( argType, function->get_parameters().front()->get_type(), indexer, env ) ) {798 alternatives.push_back( Alternative( new AttrExpr( new VariableExpr( funcDecl ), argType->clone() ), env, Cost::zero ) );799 for ( std::list< DeclarationWithType* >::iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) {800 alternatives.back().expr->get_results().push_back( (*i)->get_type()->clone() );801 } // for802 } // if796 ) 797 if ( typesCompatibleIgnoreQualifiers( argType, function->get_parameters().front()->get_type(), indexer, env ) ) { 798 alternatives.push_back( Alternative( new AttrExpr( new VariableExpr( funcDecl ), argType->clone() ), env, Cost::zero ) ); 799 for ( std::list< DeclarationWithType* >::iterator i = function->get_returnVals().begin(); i != function->get_returnVals().end(); ++i ) { 800 alternatives.back().expr->get_results().push_back( (*i)->get_type()->clone() ); 801 } // for 802 } // if 803 803 } 804 804 -
src/SymTab/Validate.cc
r49205cf r448f9b2 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:50:04 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon May 25 14:27:15201513 // Update Count : 2111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:50:09 2015 13 // Update Count : 3 14 14 // 15 15 … … 560 560 for ( std::list< Declaration * >::const_iterator member = aggregateDecl->get_members().begin(); member != aggregateDecl->get_members().end(); ++member ) { 561 561 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member ) ) { 562 // query the type qualifiers of this field and skip assigning it if it is marked const.563 // If it is an array type, we need to strip off the array layers to find its qualifiers.564 Type * type = dwt->get_type();565 while ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) {566 type = at->get_base();567 }568 569 if ( type->get_qualifiers().isConst ) {570 // don't assign const members571 continue;572 }573 574 562 if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) { 575 563 makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) ); -
src/SynTree/Declaration.h
r49205cf r448f9b2 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon May 25 14:08:10201513 // Update Count : 611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu May 21 23:43:43 2015 13 // Update Count : 3 14 14 // 15 15 … … 123 123 CompoundStmt *get_statements() const { return statements; } 124 124 void set_statements( CompoundStmt *newValue ) { statements = newValue; } 125 126 // 125 bool get_isInline() const { return isInline; } 126 // void set_isInline( bool newValue ) { isInline = newValue; } 127 127 std::list< std::string >& get_oldIdents() { return oldIdents; } 128 128 std::list< Declaration* >& get_oldDecls() { return oldDecls; }
Note: See TracChangeset
for help on using the changeset viewer.