public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r11-10663] libstdc++: Add pretty printer for std::initializer_list
Date: Thu, 27 Apr 2023 22:01:37 +0000 (GMT)	[thread overview]
Message-ID: <20230427220137.950B4385AC29@sourceware.org> (raw)

https://gcc.gnu.org/g:bbe24ab6baeb021834636af58d251c7d683a845d

commit r11-10663-gbbe24ab6baeb021834636af58d251c7d683a845d
Author: Philipp Fent <fent@in.tum.de>
Date:   Mon Apr 25 13:03:31 2022 +0100

    libstdc++: Add pretty printer for std::initializer_list
    
    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/ChangeLog:
    
            * python/libstdcxx/v6/printers.py (StdSpanPrinter._iterator):
            Rename as iterator.
            (StdInitializerListPrinter): Define new printer.
            (build_libstdcxx_dictionary): Register new printer.
            * testsuite/libstdc++-prettyprinters/cxx11.cc: Check printer for
            initializer_list.
    
    (cherry picked from commit 71999fde2a454d1fa149e63825d8edbe0748c911)

Diff:
---
 libstdc++-v3/python/libstdcxx/v6/printers.py       | 25 ++++++++++++++++++++--
 .../testsuite/libstdc++-prettyprinters/cxx11.cc    |  6 ++++++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 16bdfac8f5a..2eb1397ee2a 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1629,7 +1629,7 @@ class StdErrorCodePrinter:
 class StdSpanPrinter:
     "Print a std::span"
 
-    class _iterator(Iterator):
+    class iterator(Iterator):
         def __init__(self, begin, size):
             self.count = 0
             self.begin = begin
@@ -1658,7 +1658,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'
@@ -2128,6 +2145,10 @@ def build_libstdcxx_dictionary ():
     libstdcxx_printer.add_version('std::tr1::', 'unordered_multiset',
                                   Tr1UnorderedSetPrinter)
 
+    libstdcxx_printer.add_version('std::', 'initializer_list',
+                                  StdInitializerListPrinter)
+
+
     # These are the C++11 printer registrations for -D_GLIBCXX_DEBUG cases.
     # The tr1 namespace containers do not have any debug equivalents,
     # so do not register printers for them.
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
index 7b5d9795df7..0545076fb6f 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);

                 reply	other threads:[~2023-04-27 22:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230427220137.950B4385AC29@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).