Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rd97c3a4 r73ac10e  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sat May 16 23:52:08 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov  1 21:00:56 2018
    13 // Update Count     : 35
     11// Last Modified By : Aaron B. Moss
     12// Last Modified On : Fri Oct -5 10:01:00 2018
     13// Update Count     : 34
    1414//
    1515
     
    500500                                needAssertions[ *assert ].isUsed = true;
    501501                        }
    502                 }
    503         }
     502///     needAssertions.insert( needAssertions.end(), (*tyvar)->get_assertions().begin(), (*tyvar)->get_assertions().end() );
     503                }
     504        }
     505
     506//      template< typename ForwardIterator, typename OutputIterator >
     507//      void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, int level, const SymTab::Indexer &indexer, OutputIterator out ) {
     508//              if ( newAlt.cost == Cost::infinity ) return; // don't proceed down this dead end
     509//              if ( begin == end ) {
     510//                      if ( newNeed.empty() ) {
     511//                              PRINT(
     512//                                      std::cerr << "all assertions satisfied, output alternative: ";
     513//                                      newAlt.print( std::cerr );
     514//                                      std::cerr << std::endl;
     515//                              );
     516//                              *out++ = newAlt;
     517//                              return;
     518//                      } else if ( level >= recursionLimit ) {
     519//                              SemanticError( newAlt.expr->location, "Too many recursive assertions" );
     520//                      } else {
     521//                              AssertionSet newerNeed;
     522//                              PRINT(
     523//                                      std::cerr << "recursing with new set:" << std::endl;
     524//                                      printAssertionSet( newNeed, std::cerr, 8 );
     525//                              )
     526//                              inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, level+1, indexer, out );
     527//                              return;
     528//                      }
     529//              }
     530
     531//              ForwardIterator cur = begin++;
     532//              if ( ! cur->second.isUsed ) {
     533//                      inferRecursive( begin, end, newAlt, openVars, decls, newNeed, level, indexer, out );
     534//                      return; // xxx - should this continue? previously this wasn't here, and it looks like it should be
     535//              }
     536//              DeclarationWithType *curDecl = cur->first;
     537
     538//              PRINT(
     539//                      std::cerr << "inferRecursive: assertion is ";
     540//                      curDecl->print( std::cerr );
     541//                      std::cerr << std::endl;
     542//              )
     543//              std::list< SymTab::Indexer::IdData > candidates;
     544//              decls.lookupId( curDecl->get_name(), candidates );
     545// ///   if ( candidates.empty() ) { std::cerr << "no candidates!" << std::endl; }
     546//              for ( const auto & data : candidates ) {
     547//                      DeclarationWithType * candidate = data.id;
     548//                      PRINT(
     549//                              std::cerr << "inferRecursive: candidate is ";
     550//                              candidate->print( std::cerr );
     551//                              std::cerr << std::endl;
     552//                      )
     553
     554//                      AssertionSet newHave, newerNeed( newNeed );
     555//                      TypeEnvironment newEnv( newAlt.env );
     556//                      OpenVarSet newOpenVars( openVars );
     557//                      Type *adjType = candidate->get_type()->clone();
     558//                      adjustExprType( adjType, newEnv, indexer );
     559//                      renameTyVars( adjType );
     560//                      PRINT(
     561//                              std::cerr << "unifying ";
     562//                              curDecl->get_type()->print( std::cerr );
     563//                              std::cerr << " with ";
     564//                              adjType->print( std::cerr );
     565//                              std::cerr << std::endl;
     566//                      )
     567//                      if ( unify( curDecl->get_type(), adjType, newEnv, newerNeed, newHave, newOpenVars, indexer ) ) {
     568//                              PRINT(
     569//                                      std::cerr << "success!" << std::endl;
     570//                              )
     571//                              SymTab::Indexer newDecls( decls );
     572//                              addToIndexer( newHave, newDecls );
     573//                              Alternative newerAlt( newAlt );
     574//                              newerAlt.env = newEnv;
     575//                              assertf( candidate->get_uniqueId(), "Assertion candidate does not have a unique ID: %s", toString( candidate ).c_str() );
     576
     577//                              // everything with an empty idChain was pulled in by the current assertion.
     578//                              // add current assertion's idChain + current assertion's ID so that the correct inferParameters can be found.
     579//                              for ( auto & a : newerNeed ) {
     580//                                      if ( a.second.idChain.empty() ) {
     581//                                              a.second.idChain = cur->second.idChain;
     582//                                              a.second.idChain.push_back( curDecl->get_uniqueId() );
     583//                                      }
     584//                              }
     585
     586//                              Expression *varExpr = data.combine( newerAlt.cvtCost );
     587//                              delete varExpr->get_result();
     588//                              varExpr->set_result( adjType->clone() );
     589//                              PRINT(
     590//                                      std::cerr << "satisfying assertion " << curDecl->get_uniqueId() << " ";
     591//                                      curDecl->print( std::cerr );
     592//                                      std::cerr << " with declaration " << candidate->get_uniqueId() << " ";
     593//                                      candidate->print( std::cerr );
     594//                                      std::cerr << std::endl;
     595//                              )
     596//                              // follow the current assertion's ID chain to find the correct set of inferred parameters to add the candidate to (i.e. the set of inferred parameters belonging to the entity which requested the assertion parameter).
     597//                              InferredParams * inferParameters = &newerAlt.expr->inferParams;
     598//                              for ( UniqueId id : cur->second.idChain ) {
     599//                                      inferParameters = (*inferParameters)[ id ].inferParams.get();
     600//                              }
     601//                              // XXX: this is a memory leak, but adjType can't be deleted because it might contain assertions
     602//                              (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( candidate->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr );
     603//                              inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, level, indexer, out );
     604//                      } else {
     605//                              delete adjType;
     606//                      }
     607//              }
     608//      }
    504609
    505610        /// Unique identifier for matching expression resolutions to their requesting expression
     
    508613        template< typename OutputIterator >
    509614        void AlternativeFinder::Finder::inferParameters( Alternative &newAlt, OutputIterator out ) {
     615                // SymTab::Indexer decls( indexer );
     616                // addToIndexer( have, decls );
     617                // AssertionSet newNeed;
     618                // PRINT(
     619                //      std::cerr << "env is: " << std::endl;
     620                //      newAlt.env.print( std::cerr, 0 );
     621                //      std::cerr << std::endl;
     622                // )
     623
     624                // inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, 0, indexer, out );
     625
    510626                // Set need bindings for any unbound assertions
    511627                UniqueId crntResnSlot = 0;  // matching ID for this expression's assertions
     
    12291345                                Alternative newAlt{
    12301346                                        restructureCast( alt.expr->clone(), toType, castExpr->isGenerated ),
    1231                                         alt.env, openVars, needAssertions, alt.cost + thisCost, thisCost };
     1347                                        alt.env, openVars, needAssertions, alt.cost, thisCost };
    12321348                                inferParameters( newAlt, back_inserter( candidates ) );
    12331349                        } // if
     
    12571373                /// Gets name from untyped member expression (member must be NameExpr)
    12581374                const std::string& get_member_name( UntypedMemberExpr *memberExpr ) {
    1259                         if ( dynamic_cast< ConstantExpr * >( memberExpr->get_member() ) ) {
    1260                                 SemanticError( memberExpr, "Indexed access to struct fields unsupported: " );
    1261                         } // if
    12621375                        NameExpr * nameExpr = dynamic_cast< NameExpr * >( memberExpr->get_member() );
    12631376                        assert( nameExpr );
Note: See TracChangeset for help on using the changeset viewer.