Changeset 396037d


Ignore:
Timestamp:
Jun 10, 2019, 6:02:36 PM (2 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
arm-eh, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
6ad19fd, d57e349
Parents:
5485e10
Message:

Start stubbing CandidateFinder? in

Location:
src
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.in

    r5485e10 r396037d  
    203203        ResolvExpr/Resolver.$(OBJEXT) \
    204204        ResolvExpr/ResolveTypeof.$(OBJEXT) \
     205        ResolvExpr/SatisfyAssertions.$(OBJEXT) \
    205206        ResolvExpr/SpecCost.$(OBJEXT) \
    206207        ResolvExpr/TypeEnvironment.$(OBJEXT) \
     
    641642      ResolvExpr/Resolver.cc \
    642643      ResolvExpr/ResolveTypeof.cc \
     644      ResolvExpr/SatisfyAssertions.cpp \
    643645      ResolvExpr/SpecCost.cc \
    644646      ResolvExpr/TypeEnvironment.cc \
     
    911913ResolvExpr/ResolveTypeof.$(OBJEXT): ResolvExpr/$(am__dirstamp) \
    912914        ResolvExpr/$(DEPDIR)/$(am__dirstamp)
     915ResolvExpr/SatisfyAssertions.$(OBJEXT): ResolvExpr/$(am__dirstamp) \
     916        ResolvExpr/$(DEPDIR)/$(am__dirstamp)
    913917ResolvExpr/SpecCost.$(OBJEXT): ResolvExpr/$(am__dirstamp) \
    914918        ResolvExpr/$(DEPDIR)/$(am__dirstamp)
     
    12821286@AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/ResolveTypeof.Po@am__quote@
    12831287@AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/Resolver.Po@am__quote@
     1288@AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/SatisfyAssertions.Po@am__quote@
    12841289@AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/SpecCost.Po@am__quote@
    12851290@AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/TypeEnvironment.Po@am__quote@
  • src/ResolvExpr/AlternativeFinder.cc

    r5485e10 r396037d  
    266266                        SemanticError( expr, "No reasonable alternatives for expression " );
    267267                }
    268                 if ( mode.resolveAssns || mode.prune ) {
     268                if ( mode.satisfyAssns || mode.prune ) {
    269269                        // trim candidates just to those where the assertions resolve
    270270                        // - necessary pre-requisite to pruning
  • src/ResolvExpr/CandidateFinder.cpp

    r5485e10 r396037d  
    1616#include "CandidateFinder.hpp"
    1717
     18#include <sstream>
     19
     20#include "Candidate.hpp"
     21#include "CompilationState.h"
     22#include "SatisfyAssertions.hpp"
    1823#include "AST/Expr.hpp"
     24#include "AST/Node.hpp"
     25#include "AST/Pass.hpp"
     26
     27#define PRINT( text ) if ( resolvep ) { text }
    1928
    2029namespace ResolvExpr {
    2130
     31namespace {
     32
     33        /// Actually visits expressions to find their candidate interpretations
     34        struct Finder {
     35                CandidateFinder & candFinder;
     36                const ast::SymbolTable & symtab;
     37                CandidateList & candidates;
     38                const ast::TypeEnvironment & tenv;
     39                ast::ptr< ast::Type > & targetType;
     40
     41                Finder( CandidateFinder & f )
     42                : candFinder( f ), symtab( f.symtab ), candidates( f.candidates ), tenv( f.env ),
     43                  targetType( f.targetType ) {}
     44               
     45                #warning unimplemented
     46        };
     47
     48        /// Prunes a list of candidates down to those that have the minimum conversion cost for a given
     49        /// return type. Skips ambiguous candidates.
     50        CandidateList pruneCandidates( CandidateList & candidates ) {
     51                #warning unimplemented
     52                (void)candidates;
     53                assert(false);
     54                return {};
     55        }
     56
     57} // anonymous namespace
     58
    2259void CandidateFinder::find( const ast::Expr * expr, ResolvMode mode ) {
     60        // Find alternatives for expression
     61        ast::Pass<Finder> finder{ *this };
     62        expr->accept( finder );
     63
     64        if ( mode.failFast && candidates.empty() ) {
     65                SemanticError( expr, "No reasonable alternatives for expression " );
     66        }
     67
     68        if ( mode.satisfyAssns || mode.prune ) {
     69                // trim candidates to just those where the assertions are satisfiable
     70                // - necessary pre-requisite to pruning
     71                CandidateList satisfied;
     72                std::vector< std::string > errors;
     73                for ( auto & candidate : candidates ) {
     74                        satisfyAssertions( *candidate, symtab, satisfied, errors );
     75                }
     76
     77                // fail early if none such
     78                if ( mode.failFast && satisfied.empty() ) {
     79                        std::ostringstream stream;
     80                        stream << "No alternatives with satisfiable assertions for " << expr << "\n";
     81                        for ( const auto& err : errors ) {
     82                                stream << err;
     83                        }
     84                        SemanticError( expr->location, stream.str() );
     85                }
     86
     87                // reset candidates
     88                candidates = std::move( satisfied );
     89        }
     90
     91        if ( mode.prune ) {
     92                // trim candidates to single best one
     93                auto oldsize = candidates.size();
     94                PRINT(
     95                        std::cerr << "alternatives before prune:" << std::endl;
     96                        print( std::cerr, candidates );
     97                )
     98
     99                CandidateList pruned = pruneCandidates( candidates );
     100                if ( mode.failFast && pruned.empty() ) {
     101                        std::ostringstream stream;
     102                        CandidateList winners;
     103                       
     104                        #warning unimplemented
     105                        assert(false);
     106                }
     107        }
     108
    23109        #warning unimplemented
    24         (void)expr; (void)mode;
    25110        assert(false);
    26111}
     
    31116        std::vector< CandidateFinder > out;
    32117
    33         #warning unimplemented
    34         (void)xs;
    35         assert(false);
     118        for ( const auto & x : xs ) {
     119                out.emplace_back( symtab, env );
     120                out.back().find( x, ResolvMode::withAdjustment() );
     121               
     122                PRINT(
     123                        std::cerr << "findSubExprs" << std::endl;
     124                        print( std::cerr, out.back().candidates );
     125                )
     126        }
    36127
    37128        return out;
  • src/ResolvExpr/CandidateFinder.hpp

    r5485e10 r396037d  
    1919#include "ResolvMode.h"
    2020#include "AST/Fwd.hpp"
     21#include "AST/Node.hpp"
    2122#include "AST/SymbolTable.hpp"
    2223#include "AST/TypeEnvironment.hpp"
     
    2930        const ast::SymbolTable & symtab;         ///< Symbol table to lookup candidates
    3031        const ast::TypeEnvironment & env;        ///< Substitutions performed in this resolution
    31         const ast::Type * targetType = nullptr;  ///< Target type for resolution
     32        ast::ptr< ast::Type > targetType = nullptr;  ///< Target type for resolution
    3233
    3334        CandidateFinder( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env )
  • src/ResolvExpr/ResolvMode.h

    r5485e10 r396037d  
    2222                const bool prune;            ///< Prune alternatives to min-cost per return type? [true]
    2323                const bool failFast;         ///< Fail on no resulting alternatives? [true]
    24                 const bool resolveAssns;     ///< Resolve assertions? [false]
     24                const bool satisfyAssns;     ///< Satisfy assertions? [false]
    2525
    2626        private:
    27                 constexpr ResolvMode(bool a, bool p, bool ff, bool ra)
    28                 : adjust(a), prune(p), failFast(ff), resolveAssns(ra) {}
     27                constexpr ResolvMode(bool a, bool p, bool ff, bool sa)
     28                : adjust(a), prune(p), failFast(ff), satisfyAssns(sa) {}
    2929
    3030        public:
    3131                /// Default settings
    32                 constexpr ResolvMode() : adjust(false), prune(true), failFast(true), resolveAssns(false) {}
     32                constexpr ResolvMode() : adjust(false), prune(true), failFast(true), satisfyAssns(false) {}
    3333               
    3434                /// With adjust flag set; turns array and function types into equivalent pointers
     
    4343                static constexpr ResolvMode withoutFailFast() { return { true, true, false, false }; }
    4444
    45                 /// The same mode, but with resolveAssns turned on; for top-level calls
     45                /// The same mode, but with satisfyAssns turned on; for top-level calls
    4646                ResolvMode atTopLevel() const { return { adjust, prune, failFast, true }; }
    4747        };
  • src/ResolvExpr/module.mk

    r5485e10 r396037d  
    3535      ResolvExpr/Resolver.cc \
    3636      ResolvExpr/ResolveTypeof.cc \
     37      ResolvExpr/SatisfyAssertions.cpp \
    3738      ResolvExpr/SpecCost.cc \
    3839      ResolvExpr/TypeEnvironment.cc \
Note: See TracChangeset for help on using the changeset viewer.