Changeset 8573729 for src/ResolvExpr


Ignore:
Timestamp:
Mar 12, 2018, 5:28:11 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
resolv-new
Children:
4edf753
Parents:
6171841
Message:

Start new assertion resolution branch

  • assertion resolution visitor is stubbed in
  • ignores equally-minimal deleted expressions
Location:
src/ResolvExpr
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r6171841 r8573729  
    1515
    1616#include <stddef.h>                      // for NULL
     17#include <algorithm>                     // for sort
    1718#include <cassert>                       // for strict_dynamic_cast, assert
    1819#include <memory>                        // for allocator, allocator_traits<...
     
    2930#include "InitTweak/InitTweak.h"         // for isIntrinsicSingleArgCallStmt
    3031#include "RenameVars.h"                  // for RenameVars, global_renamer
     32#include "ResolveAssertions.h"           // for resolveAssertions
    3133#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
    3234#include "ResolveTypeof.h"               // for resolveTypeof
     
    169171                        }
    170172
    171                         // xxx - if > 1 alternative with same cost, ignore deleted and pick from remaining
    172                         // choose the lowest cost expression among the candidates
     173                        // sort candidates by cost
     174                        std::sort( candidates.begin(), candidates.end(),
     175                                [](const Alternative& a, const Alternative& b) { return a.cost < b.cost; } );
     176                        // search for cheapest resolvable candidate
    173177                        AltList winners;
    174                         findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) );
     178                        for ( const Alternative& r : candidates ) {
     179                                if ( ! winners.empty() ) {
     180                                        // break if already have a cheaper candidate
     181                                        if ( winners[0].cost < r.cost ) break;
     182
     183                                        // ignore min-cost deleted alternatives if already found one alternative
     184                                        if ( findDeletedExpr( r.expr ) ) continue;
     185                                }
     186                               
     187                                // check candidate assertion resolution
     188                                if ( resolveAssertions( r.expr ) ) {
     189                                        winners.push_back( r );
     190                                }
     191                        }
     192                       
    175193                        if ( winners.size() == 0 ) {
    176194                                SemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") );
     
    281299                Type *new_type = resolveTypeof( objectDecl->get_type(), indexer );
    282300                objectDecl->set_type( new_type );
    283                 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that class-variable
    284                 // initContext is changed multiple time because the LHS is analysed twice. The second analysis changes
    285                 // initContext because of a function type can contain object declarations in the return and parameter types. So
    286                 // each value of initContext is retained, so the type on the first analysis is preserved and used for selecting
    287                 // the RHS.
     301                // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that
     302                // class-variable initContext is changed multiple time because the LHS is analysed twice.
     303                // The second analysis changes initContext because of a function type can contain object
     304                // declarations in the return and parameter types. So each value of initContext is retained,
     305                // so the type on the first analysis is preserved and used for selecting the RHS.
    288306                GuardValue( currentObject );
    289307                currentObject = CurrentObject( objectDecl->get_type() );
     
    329347
    330348                {
    331                         // resolve with-exprs with parameters in scope and add any newly generated declarations to the
    332                         // front of the function body.
    333                         auto guard = makeFuncGuard( [this]() { indexer.enterScope(); }, [this](){ indexer.leaveScope(); } );
     349                        // resolve with-exprs with parameters in scope and add any newly generated declarations
     350                        // to the front of the function body.
     351                        auto guard = makeFuncGuard(
     352                                [this]() { indexer.enterScope(); }, [this](){ indexer.leaveScope(); } );
    334353                        indexer.addFunctionType( functionDecl->type );
    335354                        std::list< Statement * > newStmts;
     
    344363
    345364        void Resolver::postvisit( FunctionDecl *functionDecl ) {
    346                 // default value expressions have an environment which shouldn't be there and trips up later passes.
    347                 // xxx - it might be necessary to somehow keep the information from this environment, but I can't currently
    348                 // see how it's useful.
     365                // default value expressions have an environment which shouldn't be there and trips up
     366                // later passes.
     367                // xxx - it might be necessary to somehow keep the information from this environment, but I
     368                // can't currently see how it's useful.
    349369                for ( Declaration * d : functionDecl->type->parameters ) {
    350370                        if ( ObjectDecl * obj = dynamic_cast< ObjectDecl * >( d ) ) {
  • src/ResolvExpr/module.mk

    r6171841 r8573729  
    3333       ResolvExpr/TypeEnvironment.cc \
    3434       ResolvExpr/CurrentObject.cc \
    35        ResolvExpr/ExplodedActual.cc
     35       ResolvExpr/ExplodedActual.cc \
     36       ResolvExpr/ResolveAssertions.cc
Note: See TracChangeset for help on using the changeset viewer.