Changeset 0f19d763 for src


Ignore:
Timestamp:
Jun 17, 2015, 4:17:37 PM (9 years ago)
Author:
Aaron Moss <a3moss@…>
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:
eb50842
Parents:
09d789c
Message:

Comments and indentation fixes

Location:
src/ResolvExpr
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r09d789c r0f19d763  
    8989                };
    9090
     91                /// Prunes a list of alternatives down to those that have the minimum conversion cost for a given return type; skips ambiguous interpretations
    9192                template< typename InputIterator, typename OutputIterator >
    9293                void pruneAlternatives( InputIterator begin, InputIterator end, OutputIterator out, const SymTab::Indexer &indexer ) {
     
    108109                                                        std::cout << "cost " << candidate->cost << " beats " << mapPlace->second.candidate->cost << std::endl;
    109110                                                        )
    110                                                         selected[ mangleName ] = current;
     111                                                selected[ mangleName ] = current;
    111112                                        } else if ( candidate->cost == mapPlace->second.candidate->cost ) {
    112113                                                PRINT(
    113114                                                        std::cout << "marking ambiguous" << std::endl;
    114115                                                        )
    115                                                         mapPlace->second.isAmbiguous = true;
     116                                                mapPlace->second.isAmbiguous = true;
    116117                                        }
    117118                                } else {
     
    124125                                )
    125126
    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;
     127                        // accept the alternatives that were unambiguous
     128                        for ( std::map< std::string, PruneStruct >::iterator target = selected.begin(); target != selected.end(); ++target ) {
     129                                if ( ! target->second.isAmbiguous ) {
     130                                        Alternative &alt = *target->second.candidate;
     131                                        for ( std::list< Type* >::iterator result = alt.expr->get_results().begin(); result != alt.expr->get_results().end(); ++result ) {
     132                                                alt.env.applyFree( *result );
    134133                                        }
     134                                        *out++ = alt;
    135135                                }
     136                        }
    136137
    137138                }
     
    184185                                printAlts( finder.alternatives, std::cout );
    185186                                )
    186                                 *out++ = finder;
     187                        *out++ = finder;
    187188                }
    188189        }
     
    206207                        printAlts( alternatives, std::cout );
    207208                        )
    208                         AltList::iterator oldBegin = alternatives.begin();
     209                AltList::iterator oldBegin = alternatives.begin();
    209210                pruneAlternatives( alternatives.begin(), alternatives.end(), front_inserter( alternatives ), indexer );
    210211                if ( alternatives.begin() == oldBegin ) {
     
    222223                        std::cout << "there are " << alternatives.size() << " alternatives after elimination" << std::endl;
    223224                        )
    224                         }
     225        }
    225226
    226227        void AlternativeFinder::findWithAdjustment( Expression *expr ) {
     
    353354
    354355        bool AlternativeFinder::instantiateFunction( std::list< DeclarationWithType* >& formals, /*const*/ AltList &actuals, bool isVarArgs, OpenVarSet& openVars, TypeEnvironment &resultEnv, AssertionSet &resultNeed, AssertionSet &resultHave ) {
    355                 std::list< TypeEnvironment > toBeDone;
    356356                simpleCombineEnvironments( actuals.begin(), actuals.end(), resultEnv );
    357357                // make sure we don't widen any existing bindings
     
    382382                                        std::cerr << std::endl;
    383383                                        )
    384                                         if ( ! unify( (*formal)->get_type(), *actual, resultEnv, resultNeed, resultHave, openVars, indexer ) ) {
    385                                                 return false;
    386                                         }
     384                                if ( ! unify( (*formal)->get_type(), *actual, resultEnv, resultNeed, resultHave, openVars, indexer ) ) {
     385                                        return false;
     386                                }
    387387                                formal++;
    388388                        }
     
    430430                                        printAssertionSet( newNeed, std::cerr, 8 );
    431431                                        )
    432                                         inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, level+1, indexer, out );
     432                                inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, level+1, indexer, out );
    433433                                return;
    434434                        }
     
    445445                        std::cerr << std::endl;
    446446                        )
    447                         std::list< DeclarationWithType* > candidates;
     447                std::list< DeclarationWithType* > candidates;
    448448                decls.lookupId( curDecl->get_name(), candidates );
    449449///   if ( candidates.empty() ) { std::cout << "no candidates!" << std::endl; }
     
    454454                                std::cout << std::endl;
    455455                                )
    456                                 AssertionSet newHave, newerNeed( newNeed );
     456                        AssertionSet newHave, newerNeed( newNeed );
    457457                        TypeEnvironment newEnv( newAlt.env );
    458458                        OpenVarSet newOpenVars( openVars );
     
    467467                                std::cerr << std::endl;
    468468                                )
    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                                 }
     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                        }
    496496                }
    497497        }
     
    510510                        decls.print( std::cout );
    511511                        )
    512                         addToIndexer( have, decls );
     512                addToIndexer( have, decls );
    513513                AssertionSet newNeed;
    514514                inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, 0, indexer, out );
     
    534534                                printAssertionSet( resultNeed, std::cout, 8 );
    535535                                )
    536                                 inferParameters( resultNeed, resultHave, newAlt, openVars, out );
     536                        inferParameters( resultNeed, resultHave, newAlt, openVars, out );
    537537                }
    538538        }
     
    542542                AlternativeFinder funcOpFinder( indexer, env );
    543543
    544                 AlternativeFinder funcFinder( indexer, env ); {
     544                AlternativeFinder funcFinder( indexer, env );
     545
     546                {
    545547                        NameExpr *fname;
    546548                        if ( ( fname = dynamic_cast<NameExpr *>( untypedExpr->get_function()))
     
    560562                Tuples::TupleAssignSpotter tassign( this );
    561563                if ( tassign.isTupleAssignment( untypedExpr, possibilities ) ) {
    562                         // take care of possible tuple assignments, or discard expression
     564                        // TODO take care of possible tuple assignments, or discard expression
    563565                        return;
    564566                } // else ...
     
    571573                                func->print( std::cout, 8 );
    572574                                )
    573                                 // check if the type is pointer to function
    574                                 PointerType *pointer;
     575                        // check if the type is pointer to function
     576                        PointerType *pointer;
    575577                        if ( func->expr->get_results().size() == 1 && ( pointer = dynamic_cast< PointerType* >( func->expr->get_results().front() ) ) ) {
    576578                                if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
     
    604606                                                printAlts( funcOpFinder.alternatives, std::cout, 8 );
    605607                                                )
    606                                                 }
     608                                }
    607609
    608610                                for ( AltList::const_iterator funcOp = funcOpFinder.alternatives.begin(); funcOp != funcOpFinder.alternatives.end(); ++funcOp ) {
     
    737739                indexer.lookupId( nameExpr->get_name(), declList );
    738740                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                                 } // if
    756                         } // for
     741                for ( std::list< DeclarationWithType* >::iterator i = declList.begin(); i != declList.end(); ++i ) {
     742                        VariableExpr newExpr( *i, nameExpr->get_argName() );
     743                        alternatives.push_back( Alternative( newExpr.clone(), env, Cost() ) );
     744                        PRINT(
     745                                std::cerr << "decl is ";
     746                                (*i)->print( std::cerr );
     747                                std::cerr << std::endl;
     748                                std::cerr << "newExpr is ";
     749                                newExpr.print( std::cerr );
     750                                std::cerr << std::endl;
     751                                )
     752                        renameTypes( alternatives.back().expr );
     753                        if ( StructInstType *structInst = dynamic_cast< StructInstType* >( (*i)->get_type() ) ) {
     754                                addAggMembers( structInst, &newExpr, Cost( 0, 0, 1 ), "" );
     755                        } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( (*i)->get_type() ) ) {
     756                                addAggMembers( unionInst, &newExpr, Cost( 0, 0, 1 ), "" );
     757                        } // if
     758                } // for
    757759        }
    758760
  • src/ResolvExpr/AlternativeFinder.h

    r09d789c r0f19d763  
    3030                AlternativeFinder( const SymTab::Indexer &indexer, const TypeEnvironment &env );
    3131                void find( Expression *expr, bool adjust = false );
     32                /// Calls find with the adjust flag set; adjustment turns array and function types into equivalent pointer types
    3233                void findWithAdjustment( Expression *expr );
    3334                AltList &get_alternatives() { return alternatives; }
  • src/ResolvExpr/RenameVars.cc

    r09d789c r0f19d763  
    118118///     type->print( std::cout );
    119119///     std::cout << std::endl;
     120                        // copies current name mapping into new mapping
    120121                        mapStack.push_front( mapStack.front() );
     122                        // renames all "forall" type names to `_${level}_${name}'
    121123                        for ( std::list< TypeDecl* >::iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
    122124                                std::ostrstream output;
     
    125127                                mapStack.front()[ (*i)->get_name() ] = newname;
    126128                                (*i)->set_name( newname );
     129                                // ditto for assertion names, the next level in
    127130                                level++;
    128131                                acceptAll( (*i)->get_assertions(), *this );
     
    132135
    133136        void RenameVars::typeAfter( Type *type ) {
     137                // clears name mapping added by typeBefore()
    134138                if ( ! type->get_forall().empty() ) {
    135139                        mapStack.pop_front();
  • src/ResolvExpr/RenameVars.h

    r09d789c r0f19d763  
    2525
    2626namespace ResolvExpr {
     27
     28        /// Provides a consistent renaming of forall type names in a hierarchy by prefixing them with a unique "level" ID
    2729        class RenameVars : public Visitor {
    2830          public:
Note: See TracChangeset for help on using the changeset viewer.