Changes in / [c1c09285:52e2e3f]


Ignore:
Location:
src/ResolvExpr
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rc1c09285 r52e2e3f  
    1919#include <functional>
    2020#include <cassert>
     21#include <unordered_map>
     22#include <utility>
     23#include <vector>
    2124
    2225#include "AlternativeFinder.h"
     
    408411        }
    409412
    410         static const int recursionLimit = 10;
     413        /// Map of declarations (intended to be the assertions in an AssertionSet) to their parents and the number of times they've been included
     414        typedef std::unordered_map< DeclarationWithType*, std::unordered_map< DeclarationWithType*, unsigned > > AssertionParentSet;
     415       
     416        static const int recursionLimit = 10;  ///< Limit to depth of recursion satisfaction
     417        static const unsigned recursionParentLimit = 1;  ///< Limit to the number of times an assertion can recursively use itself
    411418
    412419        void addToIndexer( AssertionSet &assertSet, SymTab::Indexer &indexer ) {
     
    417424                }
    418425        }
    419 
     426       
    420427        template< typename ForwardIterator, typename OutputIterator >
    421         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 ) {
     428        void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, const AssertionParentSet &needParents,
     429                                                 int level, const SymTab::Indexer &indexer, OutputIterator out ) {
    422430                if ( begin == end ) {
    423431                        if ( newNeed.empty() ) {
     
    432440                                        printAssertionSet( newNeed, std::cerr, 8 );
    433441                                )
    434                                 inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, level+1, indexer, out );
     442                                inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, needParents, level+1, indexer, out );
    435443                                return;
    436444                        }
     
    439447                ForwardIterator cur = begin++;
    440448                if ( ! cur->second ) {
    441                         inferRecursive( begin, end, newAlt, openVars, decls, newNeed, level, indexer, out );
     449                        inferRecursive( begin, end, newAlt, openVars, decls, newNeed, needParents, level, indexer, out );
    442450                }
    443451                DeclarationWithType *curDecl = cur->first;
     
    456464                                std::cerr << std::endl;
    457465                        )
     466                        AssertionParentSet newNeedParents( needParents );
     467                        // skip repeatingly-self-recursive assertion satisfaction
     468                        if ( needParents[ curDecl ][ *candidate ]++ > recursionParentLimit ) return;
     469                       
    458470                        AssertionSet newHave, newerNeed( newNeed );
    459471                        TypeEnvironment newEnv( newAlt.env );
     
    492504                                // XXX: this is a memory leak, but adjType can't be deleted because it might contain assertions
    493505                                appExpr->get_inferParams()[ curDecl->get_uniqueId() ] = ParamEntry( (*candidate)->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr );
    494                                 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, level, indexer, out );
     506                                inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, newNeedParents, level, indexer, out );
    495507                        } else {
    496508                                delete adjType;
     
    514526                addToIndexer( have, decls );
    515527                AssertionSet newNeed;
    516                 inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, 0, indexer, out );
     528                AssertionParentSet needParents;
     529                inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, needParents, 0, indexer, out );
    517530//      PRINT(
    518531//          std::cerr << "declaration 14 is ";
  • src/ResolvExpr/RenameVars.cc

    rc1c09285 r52e2e3f  
    4545        void RenameVars::visit( PointerType *pointerType ) {
    4646                typeBefore( pointerType );
    47 ///   std::cout << "do pointer" << std::endl;
    4847                maybeAccept( pointerType->get_base(), *this );
    49 ///   std::cout << "done pointer" << std::endl;
    5048                typeAfter( pointerType );
    5149        }
     
    6058        void RenameVars::visit( FunctionType *functionType ) {
    6159                typeBefore( functionType );
    62 ///   std::cout << "return vals" << std::endl;
    6360                acceptAll( functionType->get_returnVals(), *this );
    64 ///   std::cout << functionType->get_parameters().size() << " parameters" << std::endl;
    6561                acceptAll( functionType->get_parameters(), *this );
    66 ///   std::cout << "done function" << std::endl;
    6762                typeAfter( functionType );
    6863        }
     
    9590        void RenameVars::visit( TypeInstType *instType ) {
    9691                typeBefore( instType );
    97 ///   std::cout << "instance of type " << instType->get_name() << std::endl;
    9892                std::map< std::string, std::string >::const_iterator i = mapStack.front().find( instType->get_name() );
    9993                if ( i != mapStack.front().end() ) {
    100 ///     std::cout << "found name " << i->second << std::endl;
    10194                        instType->set_name( i->second );
    10295                } else {
    103 ///     std::cout << "no name found" << std::endl;
    10496                } // if
    10597                acceptAll( instType->get_parameters(), *this );
     
    120112        void RenameVars::typeBefore( Type *type ) {
    121113                if ( ! type->get_forall().empty() ) {
    122 ///     std::cout << "type with forall: ";
    123 ///     type->print( std::cout );
    124 ///     std::cout << std::endl;
    125114                        // copies current name mapping into new mapping
    126115                        mapStack.push_front( mapStack.front() );
  • src/ResolvExpr/typeops.h

    rc1c09285 r52e2e3f  
    5454 
    5555        // in AdjustExprType.cc
     56        /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function
    5657        void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
    5758
Note: See TracChangeset for help on using the changeset viewer.