* [PATCH] libstdc++: Add pretty printer for std::initializer_list
@ 2022-04-24 15:50 Philipp Fent
2022-04-25 12:38 ` Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: Philipp Fent @ 2022-04-24 15:50 UTC (permalink / raw)
To: libstdc++, gcc-patches; +Cc: Philipp Fent
Re-using the std::span printer, this now shows the contents of the
initializer list instead of the pointer and length members.
Signed-off-by: Philipp Fent <fent@in.tum.de>
---
libstdc++-v3/python/libstdcxx/v6/printers.py | 23 +++++++++++++++++--
.../libstdc++-prettyprinters/cxx11.cc | 6 +++++
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 6d8b765f2..48798b6c1 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1657,7 +1657,7 @@ class StdRegexStatePrinter:
class StdSpanPrinter:
"Print a std::span"
- class _iterator(Iterator):
+ class iterator(Iterator):
def __init__(self, begin, size):
self.count = 0
self.begin = begin
@@ -1686,7 +1686,24 @@ class StdSpanPrinter:
return '%s of length %d' % (self.typename, self.size)
def children(self):
- return self._iterator(self.val['_M_ptr'], self.size)
+ return self.iterator(self.val['_M_ptr'], self.size)
+
+ def display_hint(self):
+ return 'array'
+
+class StdInitializerListPrinter:
+ "Print a std::initializer_list"
+
+ def __init__(self, typename, val):
+ self.typename = typename
+ self.val = val
+ self.size = val['_M_len']
+
+ def to_string(self):
+ return '%s of length %d' % (self.typename, self.size)
+
+ def children(self):
+ return StdSpanPrinter.iterator(self.val['_M_array'], self.size)
def display_hint(self):
return 'array'
@@ -2156,6 +2173,8 @@ def build_libstdcxx_dictionary ():
libstdcxx_printer.add_version('std::tr1::', 'unordered_multiset',
Tr1UnorderedSetPrinter)
+ libstdcxx_printer.add_version('std::', 'initializer_list', StdInitializerListPrinter)
+
# std::regex components
libstdcxx_printer.add_version('std::__detail::', '_State',
StdRegexStatePrinter)
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
index 4262ca88b..621d13bd0 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
@@ -25,6 +25,7 @@
#include <memory>
#include <iostream>
#include <future>
+#include <initializer_list>
#include "../util/testsuite_allocator.h" // NullablePointer
typedef std::tuple<int, int> ExTuple;
@@ -191,6 +192,11 @@ main()
std::error_code ecfut0 = std::make_error_code(std::future_errc{});
// { dg-final { note-test ecfut0 {std::error_code = {"future": 0}} } }
+ std::initializer_list<int> emptyIl = {};
+ // { dg-final { note-test emptyIl {std::initializer_list of length 0} } }
+ std::initializer_list<int> il = {3, 4};
+ // { dg-final { note-test il {std::initializer_list of length 2 = {3, 4}} } }
+
placeholder(""); // Mark SPOT
use(efl);
use(fl);
--
2.36.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] libstdc++: Add pretty printer for std::initializer_list
2022-04-24 15:50 [PATCH] libstdc++: Add pretty printer for std::initializer_list Philipp Fent
@ 2022-04-25 12:38 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2022-04-25 12:38 UTC (permalink / raw)
To: Philipp Fent; +Cc: libstdc++, gcc Patches
On Sun, 24 Apr 2022 at 16:51, Philipp Fent via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> Re-using the std::span printer, this now shows the contents of the
> initializer list instead of the pointer and length members.
Nice, I've pushed this to trunk. Thanks!
>
> Signed-off-by: Philipp Fent <fent@in.tum.de>
> ---
> libstdc++-v3/python/libstdcxx/v6/printers.py | 23 +++++++++++++++++--
> .../libstdc++-prettyprinters/cxx11.cc | 6 +++++
> 2 files changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
> index 6d8b765f2..48798b6c1 100644
> --- a/libstdc++-v3/python/libstdcxx/v6/printers.py
> +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
> @@ -1657,7 +1657,7 @@ class StdRegexStatePrinter:
> class StdSpanPrinter:
> "Print a std::span"
>
> - class _iterator(Iterator):
> + class iterator(Iterator):
> def __init__(self, begin, size):
> self.count = 0
> self.begin = begin
> @@ -1686,7 +1686,24 @@ class StdSpanPrinter:
> return '%s of length %d' % (self.typename, self.size)
>
> def children(self):
> - return self._iterator(self.val['_M_ptr'], self.size)
> + return self.iterator(self.val['_M_ptr'], self.size)
> +
> + def display_hint(self):
> + return 'array'
> +
> +class StdInitializerListPrinter:
> + "Print a std::initializer_list"
> +
> + def __init__(self, typename, val):
> + self.typename = typename
> + self.val = val
> + self.size = val['_M_len']
> +
> + def to_string(self):
> + return '%s of length %d' % (self.typename, self.size)
> +
> + def children(self):
> + return StdSpanPrinter.iterator(self.val['_M_array'], self.size)
>
> def display_hint(self):
> return 'array'
> @@ -2156,6 +2173,8 @@ def build_libstdcxx_dictionary ():
> libstdcxx_printer.add_version('std::tr1::', 'unordered_multiset',
> Tr1UnorderedSetPrinter)
>
> + libstdcxx_printer.add_version('std::', 'initializer_list', StdInitializerListPrinter)
> +
> # std::regex components
> libstdcxx_printer.add_version('std::__detail::', '_State',
> StdRegexStatePrinter)
> diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
> index 4262ca88b..621d13bd0 100644
> --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
> +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
> @@ -25,6 +25,7 @@
> #include <memory>
> #include <iostream>
> #include <future>
> +#include <initializer_list>
> #include "../util/testsuite_allocator.h" // NullablePointer
>
> typedef std::tuple<int, int> ExTuple;
> @@ -191,6 +192,11 @@ main()
> std::error_code ecfut0 = std::make_error_code(std::future_errc{});
> // { dg-final { note-test ecfut0 {std::error_code = {"future": 0}} } }
>
> + std::initializer_list<int> emptyIl = {};
> + // { dg-final { note-test emptyIl {std::initializer_list of length 0} } }
> + std::initializer_list<int> il = {3, 4};
> + // { dg-final { note-test il {std::initializer_list of length 2 = {3, 4}} } }
> +
> placeholder(""); // Mark SPOT
> use(efl);
> use(fl);
> --
> 2.36.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-25 12:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-24 15:50 [PATCH] libstdc++: Add pretty printer for std::initializer_list Philipp Fent
2022-04-25 12:38 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).