Changeset 85521c7 for src/ResolvExpr


Ignore:
Timestamp:
Feb 1, 2018, 5:40:01 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, stuck-waitfor-destruct, with_gc
Children:
0188a0bc
Parents:
d0a045c7 (diff), 33c0ce8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/ResolvExpr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rd0a045c7 r85521c7  
    15631563                // find alternatives for condition
    15641564                AlternativeFinder firstFinder( indexer, env );
    1565                 firstFinder.findWithAdjustment( conditionalExpr->get_arg1() );
     1565                firstFinder.findWithAdjustment( conditionalExpr->arg1 );
    15661566                if ( firstFinder.alternatives.empty() ) return;
    15671567                // find alternatives for true expression
    15681568                AlternativeFinder secondFinder( indexer, env );
    1569                 secondFinder.findWithAdjustment( conditionalExpr->get_arg2() );
     1569                secondFinder.findWithAdjustment( conditionalExpr->arg2 );
    15701570                if ( secondFinder.alternatives.empty() ) return;
    15711571                // find alterantives for false expression
    15721572                AlternativeFinder thirdFinder( indexer, env );
    1573                 thirdFinder.findWithAdjustment( conditionalExpr->get_arg3() );
     1573                thirdFinder.findWithAdjustment( conditionalExpr->arg3 );
    15741574                if ( thirdFinder.alternatives.empty() ) return;
    1575                 for ( AltList::const_iterator first = firstFinder.alternatives.begin(); first != firstFinder.alternatives.end(); ++first ) {
    1576                         for ( AltList::const_iterator second = secondFinder.alternatives.begin(); second != secondFinder.alternatives.end(); ++second ) {
    1577                                 for ( AltList::const_iterator third = thirdFinder.alternatives.begin(); third != thirdFinder.alternatives.end(); ++third ) {
     1575                for ( const Alternative & first : firstFinder.alternatives ) {
     1576                        for ( const Alternative & second : secondFinder.alternatives ) {
     1577                                for ( const Alternative & third : thirdFinder.alternatives ) {
    15781578                                        TypeEnvironment compositeEnv;
    1579                                         compositeEnv.simpleCombine( first->env );
    1580                                         compositeEnv.simpleCombine( second->env );
    1581                                         compositeEnv.simpleCombine( third->env );
     1579                                        compositeEnv.simpleCombine( first.env );
     1580                                        compositeEnv.simpleCombine( second.env );
     1581                                        compositeEnv.simpleCombine( third.env );
    15821582
    15831583                                        // unify true and false types, then infer parameters to produce new alternatives
    15841584                                        OpenVarSet openVars;
    15851585                                        AssertionSet needAssertions, haveAssertions;
    1586                                         Alternative newAlt( 0, compositeEnv, first->cost + second->cost + third->cost );
     1586                                        Alternative newAlt( 0, compositeEnv, first.cost + second.cost + third.cost );
    15871587                                        Type* commonType = nullptr;
    1588                                         if ( unify( second->expr->get_result(), third->expr->get_result(), newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
    1589                                                 ConditionalExpr *newExpr = new ConditionalExpr( first->expr->clone(), second->expr->clone(), third->expr->clone() );
    1590                                                 newExpr->set_result( commonType ? commonType : second->expr->get_result()->clone() );
     1588                                        if ( unify( second.expr->result, third.expr->result, newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
     1589                                                ConditionalExpr *newExpr = new ConditionalExpr( first.expr->clone(), second.expr->clone(), third.expr->clone() );
     1590                                                newExpr->result = commonType ? commonType : second.expr->result->clone();
    15911591                                                // convert both options to the conditional result type
    15921592                                                newAlt.cost += computeExpressionConversionCost( newExpr->arg2, newExpr->result, indexer, newAlt.env );
  • src/ResolvExpr/Resolver.cc

    rd0a045c7 r85521c7  
    8282                void previsit( ConstructorInit *ctorInit );
    8383          private:
    84         typedef std::list< Initializer * >::iterator InitIterator;
     84                typedef std::list< Initializer * >::iterator InitIterator;
    8585
    8686                template< typename PtrType >
    8787                void handlePtrType( PtrType * type );
    8888
    89           void resolveAggrInit( ReferenceToType *, InitIterator &, InitIterator & );
    90           void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator &, TypeSubstitution sub );
    91           void fallbackInit( ConstructorInit * ctorInit );
     89                void resolveWithExprs( std::list< Expression * > & withExprs, std::list< Statement * > & newStmts );
     90                void fallbackInit( ConstructorInit * ctorInit );
    9291
    9392                Type * functionReturn = nullptr;
     
    269268                std::cerr << std::endl;
    270269#endif
    271                 Type *new_type = resolveTypeof( functionDecl->get_type(), indexer );
     270                Type *new_type = resolveTypeof( functionDecl->type, indexer );
    272271                functionDecl->set_type( new_type );
    273272                GuardValue( functionReturn );
    274                 functionReturn = ResolvExpr::extractResultType( functionDecl->get_functionType() );
     273                functionReturn = ResolvExpr::extractResultType( functionDecl->type );
     274
     275                {
     276                        // resolve with-exprs with parameters in scope and add any newly generated declarations to the
     277                        // front of the function body.
     278                        auto guard = makeFuncGuard( [this]() { indexer.enterScope(); }, [this](){ indexer.leaveScope(); } );
     279                        indexer.addFunctionType( functionDecl->type );
     280                        std::list< Statement * > newStmts;
     281                        resolveWithExprs( functionDecl->withExprs, newStmts );
     282                        functionDecl->statements->kids.splice( functionDecl->statements->kids.begin(), newStmts );
     283                }
    275284        }
    276285
     
    279288                // xxx - it might be necessary to somehow keep the information from this environment, but I can't currently
    280289                // see how it's useful.
    281                 for ( Declaration * d : functionDecl->get_functionType()->get_parameters() ) {
     290                for ( Declaration * d : functionDecl->type->parameters ) {
    282291                        if ( ObjectDecl * obj = dynamic_cast< ObjectDecl * >( d ) ) {
    283                                 if ( SingleInit * init = dynamic_cast< SingleInit * >( obj->get_init() ) ) {
    284                                         delete init->get_value()->get_env();
    285                                         init->get_value()->set_env( nullptr );
     292                                if ( SingleInit * init = dynamic_cast< SingleInit * >( obj->init ) ) {
     293                                        delete init->value->env;
     294                                        init->value->env = nullptr;
    286295                                }
    287296                        }
     
    584593        }
    585594
    586 
    587         void Resolver::previsit( WithStmt * withStmt ) {
    588                 for ( Expression *& expr : withStmt->exprs )  {
     595        void Resolver::resolveWithExprs( std::list< Expression * > & withExprs, std::list< Statement * > & newStmts ) {
     596                for ( Expression *& expr : withExprs )  {
    589597                        // only struct- and union-typed expressions are viable candidates
    590598                        findKindExpression( expr, indexer, "with statement", isStructOrUnion );
     
    595603                                ObjectDecl * tmp = ObjectDecl::newObject( tmpNamer.newName(), expr->result->clone(), new SingleInit( expr ) );
    596604                                expr = new VariableExpr( tmp );
    597                                 stmtsToAddBefore.push_back( new DeclStmt( tmp ) );
     605                                newStmts.push_back( new DeclStmt( tmp ) );
    598606                                if ( InitTweak::isConstructable( tmp->type ) ) {
    599607                                        // generate ctor/dtor and resolve them
     
    603611                        }
    604612                }
     613        }
     614
     615        void Resolver::previsit( WithStmt * withStmt ) {
     616                resolveWithExprs( withStmt->exprs, stmtsToAddBefore );
    605617        }
    606618
     
    716728                PassVisitor<Resolver> resolver( indexer );
    717729                stmtExpr->accept( resolver );
     730                stmtExpr->computeResult();
    718731        }
    719732
Note: See TracChangeset for help on using the changeset viewer.