Changeset 8573729


Ignore:
Timestamp:
Mar 12, 2018, 5:28:11 PM (7 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
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.in

    r6171841 r8573729  
    211211        ResolvExpr/driver_cfa_cpp-CurrentObject.$(OBJEXT) \
    212212        ResolvExpr/driver_cfa_cpp-ExplodedActual.$(OBJEXT) \
     213        ResolvExpr/driver_cfa_cpp-ResolveAssertions.$(OBJEXT) \
    213214        SymTab/driver_cfa_cpp-Indexer.$(OBJEXT) \
    214215        SymTab/driver_cfa_cpp-Mangler.$(OBJEXT) \
     
    509510        ResolvExpr/Occurs.cc ResolvExpr/TypeEnvironment.cc \
    510511        ResolvExpr/CurrentObject.cc ResolvExpr/ExplodedActual.cc \
    511         SymTab/Indexer.cc SymTab/Mangler.cc SymTab/Validate.cc \
    512         SymTab/FixFunction.cc SymTab/Autogen.cc SynTree/Type.cc \
    513         SynTree/VoidType.cc SynTree/BasicType.cc \
    514         SynTree/PointerType.cc SynTree/ArrayType.cc \
    515         SynTree/ReferenceType.cc SynTree/FunctionType.cc \
    516         SynTree/ReferenceToType.cc SynTree/TupleType.cc \
    517         SynTree/TypeofType.cc SynTree/AttrType.cc \
     512        ResolvExpr/ResolveAssertions.cc SymTab/Indexer.cc \
     513        SymTab/Mangler.cc SymTab/Validate.cc SymTab/FixFunction.cc \
     514        SymTab/Autogen.cc SynTree/Type.cc SynTree/VoidType.cc \
     515        SynTree/BasicType.cc SynTree/PointerType.cc \
     516        SynTree/ArrayType.cc SynTree/ReferenceType.cc \
     517        SynTree/FunctionType.cc SynTree/ReferenceToType.cc \
     518        SynTree/TupleType.cc SynTree/TypeofType.cc SynTree/AttrType.cc \
    518519        SynTree/VarArgsType.cc SynTree/ZeroOneType.cc \
    519520        SynTree/Constant.cc SynTree/Expression.cc SynTree/TupleExpr.cc \
     
    824825        ResolvExpr/$(am__dirstamp) \
    825826        ResolvExpr/$(DEPDIR)/$(am__dirstamp)
     827ResolvExpr/driver_cfa_cpp-ResolveAssertions.$(OBJEXT):  \
     828        ResolvExpr/$(am__dirstamp) \
     829        ResolvExpr/$(DEPDIR)/$(am__dirstamp)
    826830SymTab/$(am__dirstamp):
    827831        @$(MKDIR_P) SymTab
     
    10201024@AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-PtrsCastable.Po@am__quote@
    10211025@AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-RenameVars.Po@am__quote@
     1026@AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ResolveAssertions.Po@am__quote@
    10221027@AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ResolveTypeof.Po@am__quote@
    10231028@AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-Resolver.Po@am__quote@
     
    19661971@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o ResolvExpr/driver_cfa_cpp-ExplodedActual.obj `if test -f 'ResolvExpr/ExplodedActual.cc'; then $(CYGPATH_W) 'ResolvExpr/ExplodedActual.cc'; else $(CYGPATH_W) '$(srcdir)/ResolvExpr/ExplodedActual.cc'; fi`
    19671972
     1973ResolvExpr/driver_cfa_cpp-ResolveAssertions.o: ResolvExpr/ResolveAssertions.cc
     1974@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT ResolvExpr/driver_cfa_cpp-ResolveAssertions.o -MD -MP -MF ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ResolveAssertions.Tpo -c -o ResolvExpr/driver_cfa_cpp-ResolveAssertions.o `test -f 'ResolvExpr/ResolveAssertions.cc' || echo '$(srcdir)/'`ResolvExpr/ResolveAssertions.cc
     1975@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ResolveAssertions.Tpo ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ResolveAssertions.Po
     1976@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='ResolvExpr/ResolveAssertions.cc' object='ResolvExpr/driver_cfa_cpp-ResolveAssertions.o' libtool=no @AMDEPBACKSLASH@
     1977@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     1978@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o ResolvExpr/driver_cfa_cpp-ResolveAssertions.o `test -f 'ResolvExpr/ResolveAssertions.cc' || echo '$(srcdir)/'`ResolvExpr/ResolveAssertions.cc
     1979
     1980ResolvExpr/driver_cfa_cpp-ResolveAssertions.obj: ResolvExpr/ResolveAssertions.cc
     1981@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT ResolvExpr/driver_cfa_cpp-ResolveAssertions.obj -MD -MP -MF ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ResolveAssertions.Tpo -c -o ResolvExpr/driver_cfa_cpp-ResolveAssertions.obj `if test -f 'ResolvExpr/ResolveAssertions.cc'; then $(CYGPATH_W) 'ResolvExpr/ResolveAssertions.cc'; else $(CYGPATH_W) '$(srcdir)/ResolvExpr/ResolveAssertions.cc'; fi`
     1982@am__fastdepCXX_TRUE@   $(AM_V_at)$(am__mv) ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ResolveAssertions.Tpo ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ResolveAssertions.Po
     1983@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(AM_V_CXX)source='ResolvExpr/ResolveAssertions.cc' object='ResolvExpr/driver_cfa_cpp-ResolveAssertions.obj' libtool=no @AMDEPBACKSLASH@
     1984@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     1985@am__fastdepCXX_FALSE@  $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o ResolvExpr/driver_cfa_cpp-ResolveAssertions.obj `if test -f 'ResolvExpr/ResolveAssertions.cc'; then $(CYGPATH_W) 'ResolvExpr/ResolveAssertions.cc'; else $(CYGPATH_W) '$(srcdir)/ResolvExpr/ResolveAssertions.cc'; fi`
     1986
    19681987SymTab/driver_cfa_cpp-Indexer.o: SymTab/Indexer.cc
    19691988@am__fastdepCXX_TRUE@   $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-Indexer.o -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-Indexer.Tpo -c -o SymTab/driver_cfa_cpp-Indexer.o `test -f 'SymTab/Indexer.cc' || echo '$(srcdir)/'`SymTab/Indexer.cc
  • 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.