Changeset 2595df1


Ignore:
Timestamp:
Dec 3, 2020, 1:41:11 PM (10 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
3233b91
Parents:
cc5cc27
Message:

Now using string print to sort alternatives

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rcc5cc27 r2595df1  
    131131
    132132        void printAlts( const AltList &list, std::ostream &os, unsigned int indentAmt ) {
    133                 Indenter indent = { indentAmt };
    134 
    135                 std::vector<int> idx;
    136                 idx.reserve(list.size());
    137                 for(int i = 0; i < list.size(); i++) { idx.push_back(i); }
    138 
    139                 std::sort(idx.begin(), idx.end(), [&list](int lhs_idx, int rhs_idx) -> bool {
    140                         const auto & lhs = list.at(lhs_idx);
    141                         const auto & rhs = list.at(rhs_idx);
    142                         if(lhs.expr->location.startsBefore(rhs.expr->location)) return true;
    143                         if(rhs.expr->location.startsBefore(lhs.expr->location)) return false;
    144 
    145                         if(lhs.env.size() < rhs.env.size()) return true;
    146                         if(lhs.env.size() > rhs.env.size()) return false;
    147 
    148                         if(lhs.openVars.size() < rhs.openVars.size()) return true;
    149                         if(lhs.openVars.size() > rhs.openVars.size()) return false;
    150 
    151                         if(lhs.need.size() < rhs.need.size()) return true;
    152                         if(lhs.need.size() > rhs.need.size()) return false;
    153 
    154                         return false;
    155                 });
    156 
    157                 for ( AltList::const_iterator i = list.begin(); i != list.end(); ++i ) {
    158                         i->print( os, indent );
    159                         os << std::endl;
     133                std::vector<std::string> sorted;
     134                sorted.reserve(list.size());
     135                for(const auto & c : list) {
     136                        std::stringstream ss;
     137                        print( ss, *c, indentAmt );
     138                        sorted.push_back(ss.str());
     139                }
     140
     141                std::sort(sorted.begin(), sorted.end());
     142
     143                for ( const auto & s : sorted ) {
     144                        os << s << std::endl;
    160145                }
    161146        }
  • src/ResolvExpr/Candidate.cpp

    rcc5cc27 r2595df1  
    4141
    4242void print( std::ostream & os, const CandidateList & cands, Indenter indent ) {
    43         for ( const CandidateRef & cand : cands ) {
    44                 print( os, *cand, indent );
    45                 os << std::endl;
     43        std::vector<std::string> sorted;
     44        sorted.reserve(cands.size());
     45        for(const auto & c : cands) {
     46                std::stringstream ss;
     47                print( ss, *c, indent );
     48                sorted.push_back(ss.str());
     49        }
     50
     51        std::sort(sorted.begin(), sorted.end());
     52
     53        for ( const auto & s : sorted ) {
     54                os << s << std::endl;
    4655        }
    4756}
  • tests/.expect/castError.nast.txt

    rcc5cc27 r2595df1  
    77  char Alternatives are:
    88Cost ( 1, 0, 0, 0, 0, 0, 0 ): Explicit Cast of:
    9       Variable Expression: f: signed int
     9      Variable Expression: f: double
    1010      ... with resolved type:
    11         signed int
     11        double
    1212    ... to:
    1313      char
     
    3939
    4040Cost ( 1, 0, 0, 0, 0, 0, 0 ): Explicit Cast of:
    41       Variable Expression: f: double
     41      Variable Expression: f: signed int
    4242      ... with resolved type:
    43         double
     43        signed int
    4444    ... to:
    4545      char
  • tests/errors/.expect/completeType.nast.x64.txt

    rcc5cc27 r2595df1  
    99... with resolved type:
    1010  void Alternatives are:
     11Cost ( 0, 1, 2, 0, 1, -1, 0 ): Generated Cast of:
     12      Application of
     13        Variable Expression: *?: forall
     14          DT: data type
     15          function
     16        ... with parameters
     17          pointer to instance of type DT (not function type)
     18        ... returning
     19          reference to instance of type DT (not function type)
     20
     21        ... with resolved type:
     22          pointer to forall
     23            [unbound]:data type
     24            function
     25          ... with parameters
     26            pointer to instance of type [unbound] (not function type)
     27          ... returning
     28            reference to instance of type [unbound] (not function type)
     29
     30        ... to arguments
     31        Variable Expression: x: pointer to instance of struct A without body
     32        ... with resolved type:
     33          pointer to instance of struct A without body
     34
     35      ... with resolved type:
     36        reference to instance of struct A without body
     37    ... to: nothing
     38    ... with resolved type:
     39      void
     40  (types:
     41    void
     42  )
     43  Environment:([unbound]) -> instance of struct A without body (no widening)
     44
     45
    1146Cost ( 0, 1, 2, 0, 1, -1, 0 ): Generated Cast of:
    1247      Application of
     
    4277  )
    4378  Environment:([unbound]) -> instance of struct B with body (no widening)
    44 
    45 
    46 Cost ( 0, 1, 2, 0, 1, -1, 0 ): Generated Cast of:
    47       Application of
    48         Variable Expression: *?: forall
    49           DT: data type
    50           function
    51         ... with parameters
    52           pointer to instance of type DT (not function type)
    53         ... returning
    54           reference to instance of type DT (not function type)
    55 
    56         ... with resolved type:
    57           pointer to forall
    58             [unbound]:data type
    59             function
    60           ... with parameters
    61             pointer to instance of type [unbound] (not function type)
    62           ... returning
    63             reference to instance of type [unbound] (not function type)
    64 
    65         ... to arguments
    66         Variable Expression: x: pointer to instance of struct A without body
    67         ... with resolved type:
    68           pointer to instance of struct A without body
    69 
    70       ... with resolved type:
    71         reference to instance of struct A without body
    72     ... to: nothing
    73     ... with resolved type:
    74       void
    75   (types:
    76     void
    77   )
    78   Environment:([unbound]) -> instance of struct A without body (no widening)
    7979
    8080
  • tests/meta/.expect/archVast.nast.x64.txt

    rcc5cc27 r2595df1  
    77  char Alternatives are:
    88Cost ( 1, 0, 0, 0, 0, 0, 0 ): Explicit Cast of:
    9       Variable Expression: FX64: signed int
     9      Variable Expression: FX64: double
    1010      ... with resolved type:
    11         signed int
     11        double
    1212    ... to:
    1313      char
     
    3939
    4040Cost ( 1, 0, 0, 0, 0, 0, 0 ): Explicit Cast of:
    41       Variable Expression: FX64: double
     41      Variable Expression: FX64: signed int
    4242      ... with resolved type:
    43         double
     43        signed int
    4444    ... to:
    4545      char
Note: See TracChangeset for help on using the changeset viewer.