Changeset 4edf753


Ignore:
Timestamp:
Mar 13, 2018, 2:17:10 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
resolv-new
Parents:
8573729
Message:

Added deleted expression support to waitfor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r8573729 r4edf753  
    1919#include <memory>                        // for allocator, allocator_traits<...
    2020#include <tuple>                         // for get
     21#include <utility>                       // for move
    2122#include <vector>
    2223
     
    629630                        }
    630631
     632                        assertf(func_candidates.size() == args_candidates.size(),
     633                                "Same number of function and argument candidates");
     634                       
     635                        // remove alternatives that include deleted expressions
     636                        unsigned into = 0;
     637                        for ( unsigned from = 0; from < func_candidates.size(); ++from ) {
     638                                // skip deleted expressions
     639                                if ( findDeletedExpr( func_candidates[from].expr )
     640                                                || std::any_of( args_candidates[from].begin(), args_candidates[from].end(),
     641                                                        []( const Alternative& a ) { return findDeletedExpr( a.expr ); } ) ) {
     642                                        continue;
     643                                }
     644
     645                                // overwrite deleted candidates
     646                                if ( into < from ) {
     647                                        func_candidates[into] = std::move( func_candidates[from] );
     648                                        args_candidates[into] = std::move( args_candidates[from] );
     649                                }
     650                                ++into;
     651                        }
     652                        bool includes_deleted = into < func_candidates.size();
     653                        if ( includes_deleted ) {
     654                                func_candidates.resize( into );
     655                                args_candidates.resize( into );
     656                        }
     657
    631658                        // Make sure we got the right number of arguments
    632                         if( func_candidates.empty() )    { SemanticErrorException top( stmt->location, "No alternatives for function in call to waitfor"  ); top.append( errors ); throw top; }
    633                         if( args_candidates.empty() )    { SemanticErrorException top( stmt->location, "No alternatives for arguments in call to waitfor" ); top.append( errors ); throw top; }
    634                         if( func_candidates.size() > 1 ) { SemanticErrorException top( stmt->location, "Ambiguous function in call to waitfor"            ); top.append( errors ); throw top; }
    635                         if( args_candidates.size() > 1 ) { SemanticErrorException top( stmt->location, "Ambiguous arguments in call to waitfor"           ); top.append( errors ); throw top; }
    636                         // TODO: need to use findDeletedExpr to ensure no deleted identifiers are used.
    637 
     659                        if( func_candidates.empty() ) {
     660                                SemanticErrorException top( stmt->location, includes_deleted ?
     661                                        "No non-deleted alternatives for call to waitfor" :
     662                                        "No alternatives for call to waitfor" );
     663                                top.append( errors );
     664                                throw top;
     665                        }
     666                        if( func_candidates.size() > 1 ) {
     667                                SemanticErrorException top( stmt->location,
     668                                        "Ambiguous call to waitfor" );
     669                                top.append( errors );
     670                                throw top;
     671                        }
     672                       
    638673                        // Swap the results from the alternative with the unresolved values.
    639674                        // Alternatives will handle deletion on destruction
Note: See TracChangeset for help on using the changeset viewer.