From: Philipp Fent Date: Mon, 25 Apr 2022 12:03:31 +0000 (+0100) Subject: libstdc++: Add pretty printer for std::initializer_list X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=71999fde2a454d1fa149e63825d8edbe0748c911;p=test_jj.git 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 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. --- diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 6d8b765..c31134b 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,9 @@ 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 4262ca8..621d13b 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include "../util/testsuite_allocator.h" // NullablePointer typedef std::tuple 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 emptyIl = {}; + // { dg-final { note-test emptyIl {std::initializer_list of length 0} } } + std::initializer_list il = {3, 4}; + // { dg-final { note-test il {std::initializer_list of length 2 = {3, 4}} } } + placeholder(""); // Mark SPOT use(efl); use(fl);