aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/python
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-10-18 21:20:06 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-11-13 01:10:44 +0000
commit1d9454aba615eadd0d85c93713dd848227345f67 (patch)
treef2b2f1e038a1fe90ea5b4058dec236d47c26c991 /libstdc++-v3/python
parentd4ba3b369cbe9bce0a1212670825ecfb99762520 (diff)
downloadgcc-1d9454aba615eadd0d85c93713dd848227345f67.zip
gcc-1d9454aba615eadd0d85c93713dd848227345f67.tar.gz
gcc-1d9454aba615eadd0d85c93713dd848227345f67.tar.bz2
libstdc++: Implement C++20 <format> [PR104166]
This doesn't add the newer C++23 features like formatting ranges and escaped string prsentation types. However, C++23 extended floating-point types are supported, as are 128-bit integers. It could do with more tests. libstdc++-v3/ChangeLog: PR libstdc++/104166 * include/Makefile.am (std_headers): Add <format>. * include/Makefile.in: Regenerate. * include/precompiled/stdc++.h: Add <format>. * include/std/format: New file. * python/libstdcxx/v6/printers.py (StdFormatArgsPrinter): New printer for std::format_args. * testsuite/std/format/arguments/args.cc: New test. * testsuite/std/format/error.cc: New test. * testsuite/std/format/formatter.cc: New test. * testsuite/std/format/functions/format.cc: New test. * testsuite/std/format/functions/format_to_n.cc: New test. * testsuite/std/format/functions/size.cc: New test. * testsuite/std/format/functions/vformat_to.cc: New test. * testsuite/std/format/parse_ctx.cc: New test. * testsuite/std/format/string.cc: New test. * testsuite/std/format/string_neg.cc: New test.
Diffstat (limited to 'libstdc++-v3/python')
-rw-r--r--libstdc++-v3/python/libstdcxx/v6/printers.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 0fa7805..09dffad 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1815,6 +1815,32 @@ class StdAtomicPrinter:
val = self.val['_M_i']
return '%s<%s> = { %s }' % (self.typename, str(self.value_type), val)
+class StdFormatArgsPrinter:
+ "Print a std::basic_format_args"
+ # TODO: add printer for basic_format_arg<C> and print out children
+ # TODO: add printer for basic_format_args<C>::_Store<Args...>
+
+ def __init__(self, typename, val):
+ self.typename = strip_versioned_namespace(typename)
+ self.val = val
+
+ def to_string(self):
+ targs = get_template_arg_list(self.val.type)
+ char_type = get_template_arg_list(targs[0])[1]
+ if char_type == gdb.lookup_type('char'):
+ typ = 'std::format_args'
+ elif char_type == gdb.lookup_type('wchar_t'):
+ typ = 'std::wformat_args'
+ else:
+ typ = 'std::basic_format_args'
+
+ size = self.val['_M_packed_size']
+ if size == 1:
+ return "%s with 1 argument" % (typ)
+ if size == 0:
+ size = self.val['_M_unpacked_size']
+ return "%s with %d arguments" % (typ, size)
+
# A "regular expression" printer which conforms to the
# "SubPrettyPrinter" protocol from gdb.printing.
class RxPrinter(object):
@@ -2355,6 +2381,7 @@ def build_libstdcxx_dictionary ():
libstdcxx_printer.add_version('std::', 'weak_ordering', StdCmpCatPrinter)
libstdcxx_printer.add_version('std::', 'strong_ordering', StdCmpCatPrinter)
libstdcxx_printer.add_version('std::', 'span', StdSpanPrinter)
+ libstdcxx_printer.add_version('std::', 'basic_format_args', StdFormatArgsPrinter)
# Extensions.
libstdcxx_printer.add_version('__gnu_cxx::', 'slist', StdSlistPrinter)