From d33c00e1ceb82fa46561ee076b9cb40ad44dc0dc Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 14 Dec 2016 16:07:29 +0000 Subject: [PATCH] Make printers use singular noun for a single element * python/libstdcxx/v6/printers.py (num_elements): New function. (StdMapPrinter.to_string, StdSetPrinter.to_string) (StdDequePrinter.to_string, Tr1UnorderedSetPrinter.to_string) (Tr1UnorderedMapPrinter.to_string): Use num_elements. * testsuite/libstdc++-prettyprinters/cxx11.cc: Adjust expected results to use singular noun when there is only one element. * testsuite/libstdc++-prettyprinters/debug.cc: Likewise. * testsuite/libstdc++-prettyprinters/debug_cxx11.cc: Likewise. * testsuite/libstdc++-prettyprinters/simple.cc: Likewise. * testsuite/libstdc++-prettyprinters/simple11.cc: Likewise. * testsuite/libstdc++-prettyprinters/tr1.cc: Likewise. From-SVN: r243652 --- libstdc++-v3/ChangeLog | 12 +++++++++++ libstdc++-v3/python/libstdcxx/v6/printers.py | 20 ++++++++++++------- .../libstdc++-prettyprinters/cxx11.cc | 8 ++++---- .../libstdc++-prettyprinters/debug.cc | 2 +- .../libstdc++-prettyprinters/debug_cxx11.cc | 4 ++-- .../libstdc++-prettyprinters/simple.cc | 2 +- .../libstdc++-prettyprinters/simple11.cc | 2 +- .../testsuite/libstdc++-prettyprinters/tr1.cc | 4 ++-- 8 files changed, 36 insertions(+), 18 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 635629b7837..5d7563f6021 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,17 @@ 2016-12-14 Jonathan Wakely + * python/libstdcxx/v6/printers.py (num_elements): New function. + (StdMapPrinter.to_string, StdSetPrinter.to_string) + (StdDequePrinter.to_string, Tr1UnorderedSetPrinter.to_string) + (Tr1UnorderedMapPrinter.to_string): Use num_elements. + * testsuite/libstdc++-prettyprinters/cxx11.cc: Adjust expected results + to use singular noun when there is only one element. + * testsuite/libstdc++-prettyprinters/debug.cc: Likewise. + * testsuite/libstdc++-prettyprinters/debug_cxx11.cc: Likewise. + * testsuite/libstdc++-prettyprinters/simple.cc: Likewise. + * testsuite/libstdc++-prettyprinters/simple11.cc: Likewise. + * testsuite/libstdc++-prettyprinters/tr1.cc: Likewise. + PR libstdc++/59170 * python/libstdcxx/v6/printers.py (StdDebugIteratorPrinter): Use _M_sequence and _M_version to detect invalid iterators. diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 8ac4a3757cb..3a111d793cb 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -508,6 +508,10 @@ class StdDebugIteratorPrinter: itype = self.val.type.template_argument(0) return self.val.cast(itype) +def num_elements(num): + """Return either "1 element" or "N elements" depending on the argument.""" + return '1 element' if num == 1 else '%d elements' % num + class StdMapPrinter: "Print a std::map or std::multimap" @@ -539,8 +543,8 @@ class StdMapPrinter: self.val = val def to_string (self): - return '%s with %d elements' % (self.typename, - len (RbtreeIterator (self.val))) + return '%s with %s' % (self.typename, + num_elements(len(RbtreeIterator (self.val)))) def children (self): rep_type = find_type(self.val.type, '_Rep_type') @@ -579,8 +583,8 @@ class StdSetPrinter: self.val = val def to_string (self): - return '%s with %d elements' % (self.typename, - len (RbtreeIterator (self.val))) + return '%s with %s' % (self.typename, + num_elements(len(RbtreeIterator (self.val)))) def children (self): rep_type = find_type(self.val.type, '_Rep_type') @@ -681,7 +685,7 @@ class StdDequePrinter: size = self.buffer_size * delta_n + delta_s + delta_e - return '%s with %d elements' % (self.typename, long (size)) + return '%s with %s' % (self.typename, num_elements(long(size))) def children(self): start = self.val['_M_impl']['_M_start'] @@ -795,7 +799,8 @@ class Tr1UnorderedSetPrinter: return self.val['_M_h'] def to_string (self): - return '%s with %d elements' % (self.typename, self.hashtable()['_M_element_count']) + count = self.hashtable()['_M_element_count'] + return '%s with %s' % (self.typename, num_elements(count)) @staticmethod def format_count (i): @@ -820,7 +825,8 @@ class Tr1UnorderedMapPrinter: return self.val['_M_h'] def to_string (self): - return '%s with %d elements' % (self.typename, self.hashtable()['_M_element_count']) + count = self.hashtable()['_M_element_count'] + return '%s with %s' % (self.typename, num_elements(count)) @staticmethod def flatten (list): diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc index 780a4e43879..e02997a5f79 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc @@ -113,15 +113,15 @@ main() std::unordered_set uos; uos.insert(5); -// { dg-final { note-test uos {std::unordered_set with 1 elements = {[0] = 5}} } } +// { dg-final { note-test uos {std::unordered_set with 1 element = {[0] = 5}} } } std::unordered_set &ruos = uos; -// { dg-final { note-test ruos {std::unordered_set with 1 elements = {[0] = 5}} } } +// { dg-final { note-test ruos {std::unordered_set with 1 element = {[0] = 5}} } } std::unordered_multiset uoms; uoms.insert(5); -// { dg-final { note-test uoms {std::unordered_multiset with 1 elements = {[0] = 5}} } } +// { dg-final { note-test uoms {std::unordered_multiset with 1 element = {[0] = 5}} } } std::unordered_multiset &ruoms = uoms; -// { dg-final { note-test ruoms {std::unordered_multiset with 1 elements = {[0] = 5}} } } +// { dg-final { note-test ruoms {std::unordered_multiset with 1 element = {[0] = 5}} } } std::unique_ptr uptr (new datum); uptr->s = "hi bob"; diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc index cff71132cec..833b557b4f1 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc @@ -66,7 +66,7 @@ main() std::map mp; mp["zardoz"] = 23; -// { dg-final { note-test mp {std::__debug::map with 1 elements = {["zardoz"] = 23}} } } +// { dg-final { note-test mp {std::__debug::map with 1 element = {["zardoz"] = 23}} } } std::map::iterator mpiter = mp.begin(); // { dg-final { note-test mpiter {{first = "zardoz", second = 23}} } } diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug_cxx11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug_cxx11.cc index 65f187c2ce3..27c3bbf56c9 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug_cxx11.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug_cxx11.cc @@ -43,13 +43,13 @@ main() // { dg-final { note-test *flstciter {"dee"}} } std::unordered_map um{ {"zardoz", 23} }; -// { dg-final { note-test um {std::__debug::unordered_map with 1 elements = {["zardoz"] = 23}} } } +// { dg-final { note-test um {std::__debug::unordered_map with 1 element = {["zardoz"] = 23}} } } std::unordered_map::iterator umiter = um.begin(); // { dg-final { note-test umiter->first {"zardoz"} } } std::unordered_set us{"barrel"}; -// { dg-final { note-test us {std::__debug::unordered_set with 1 elements = {[0] = "barrel"}} } } +// { dg-final { note-test us {std::__debug::unordered_set with 1 element = {[0] = "barrel"}} } } std::unordered_set::const_iterator usciter = us.begin(); // { dg-final { note-test *usciter {"barrel"} } } diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc index 5f98b259be1..fb8e0d754e6 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc @@ -68,7 +68,7 @@ main() std::map mp; mp["zardoz"] = 23; -// { dg-final { note-test mp {std::map with 1 elements = {["zardoz"] = 23}} } } +// { dg-final { note-test mp {std::map with 1 element = {["zardoz"] = 23}} } } std::map::iterator mpiter = mp.begin(); // { dg-final { note-test mpiter {{first = "zardoz", second = 23}} } } diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc index 97a57efba3d..9e230e3d4d9 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc @@ -68,7 +68,7 @@ main() std::map mp; mp["zardoz"] = 23; -// { dg-final { note-test mp {std::map with 1 elements = {["zardoz"] = 23}} } } +// { dg-final { note-test mp {std::map with 1 element = {["zardoz"] = 23}} } } std::map::iterator mpiter = mp.begin(); // { dg-final { note-test mpiter {{first = "zardoz", second = 23}} } } diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/tr1.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/tr1.cc index 52dca4d59f4..609b1f0c634 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/tr1.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/tr1.cc @@ -71,11 +71,11 @@ main() std::tr1::unordered_set uos; uos.insert(5); -// { dg-final { note-test uos {std::tr1::unordered_set with 1 elements = {[0] = 5}} } } +// { dg-final { note-test uos {std::tr1::unordered_set with 1 element = {[0] = 5}} } } std::tr1::unordered_multiset uoms; uoms.insert(5); -// { dg-final { note-test uoms {std::tr1::unordered_multiset with 1 elements = {[0] = 5}} } } +// { dg-final { note-test uoms {std::tr1::unordered_multiset with 1 element = {[0] = 5}} } } placeholder(""); // Mark SPOT use(eum); -- 2.30.2