This fixes the fact that our pretty printers say ungrammatical things like "std::vector with 1 elements"
* 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. Tested x86_64-linux, committed to trunk.
commit ab2bc8739f357d95bf177d2b6f644c81b405a524 Author: Jonathan Wakely <jwak...@redhat.com> Date: Wed Dec 14 15:47:31 2016 +0000 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. diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 8ac4a37..3a111d7 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 780a4e4..e02997a 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<int> 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<int> &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<int> 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<int> &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<datum> 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 cff7113..833b557 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc @@ -66,7 +66,7 @@ main() std::map<std::string, int> 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<std::string, int>::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 65f187c..27c3bbf 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<std::string, int> 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<std::string, int>::iterator umiter = um.begin(); // { dg-final { note-test umiter->first {"zardoz"} } } std::unordered_set<std::string> 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<std::string>::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 5f98b25..fb8e0d7 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc @@ -68,7 +68,7 @@ main() std::map<std::string, int> 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<std::string, int>::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 97a57ef..9e230e3 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc @@ -68,7 +68,7 @@ main() std::map<std::string, int> 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<std::string, int>::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 52dca4d..609b1f0 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<int> 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<int> 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);