From 6a59236bb21bf7f19faa6ce5332d21bb9c90e14e Mon Sep 17 00:00:00 2001 From: dsmith Date: Tue, 21 Aug 2007 21:28:09 +0000 Subject: [PATCH] 2007-08-21 David Smith PR 2305 * translate.cxx (c_unparser::visit_foreach_loop): When the user requested sorting an array of aggregates by value, sort by @count. --- ChangeLog | 7 +++++++ translate.cxx | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 462c1f424..cde5dc75b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-08-21 David Smith + + PR 2305 + * translate.cxx (c_unparser::visit_foreach_loop): When the user + requested sorting an array of aggregates by value, sort by + @count. + 2007-08-20 Martin Hunt PR2424 From Lai Jiangshan diff --git a/translate.cxx b/translate.cxx index 736e380f5..4891c617c 100644 --- a/translate.cxx +++ b/translate.cxx @@ -2489,19 +2489,29 @@ c_unparser::visit_foreach_loop (foreach_loop *s) // sort array if desired if (s->sort_direction) { + int sort_column; + + // If the user wanted us to sort by value, we'll sort by + // @count instead for aggregates. '-5' tells the + // runtime to sort by count. + if (s->sort_column == 0) + sort_column = -5; + else + sort_column = s->sort_column; + o->newline() << "else"; // only sort if aggregation was ok if (s->limit) { o->newline(1) << "_stp_map_sortn (" << mv.fetch_existing_aggregate() << ", " - << *res_limit << ", " << s->sort_column << ", " + << *res_limit << ", " << sort_column << ", " << - s->sort_direction << ");"; } else { o->newline(1) << "_stp_map_sort (" << mv.fetch_existing_aggregate() << ", " - << s->sort_column << ", " + << sort_column << ", " << - s->sort_direction << ");"; } o->indent(-1); -- 2.43.5