[patch] Add libstdc++ pretty printers for Library Fundamentals TS types
Jonathan Wakely
jwakely@redhat.com
Mon Jul 14 19:31:00 GMT 2014
This is another patch for the python printers, so the diff is relative
to my patch from earlier today, but it's actually independent.
This adds printers for the types in the std::experimental namespace.
For 'any' and 'optional' the printer will say "no contained value"
when that's the case, otherwise it will display the contained value
using its own printer, so the output looks like one of:
No contained value:
std::experimental::any [no contained value]
Contained value is a single object:
std::experimental::any containing int = {[contained value] = 6}
Contained value contains other object:
std::experimental::any containing std::map with 2 elements = {[1] = 2, [3] = 4}
I'd rather not have the [contained value] part in the second one, but
the design of the printers assumes that the children() method always
returns a 2-tuple with a label and a value, so I decided that
[contained value] = x
looks better than some arbitrary index such as:
[0] = x
Printing the contained value was quite tricky to do for any, where the
type is completely erased. I'm considering using a similar trick for
shared_ptr, so that the printer can show the owned pointer as well as
the pointer that will be returned by get(), since they are not always
the same.
I had to remove the assumption that libstdc++ printers always work on
templates, because std::experimental::any is not a template (this will
also be true for std::experimental::filesystem::path and other types
in the Filesystem TS which I'm currently implementing). The relevant
part of the patch is:
@@ -865,12 +1001,12 @@ class Printer(object):
self.subprinters = []
self.lookup = {}
self.enabled = True
- self.compiled_rx = re.compile('^([a-zA-Z0-9_:]+)<.*>$')
+ self.compiled_rx = re.compile('^([a-zA-Z0-9_:]+)(<.*>)?$')
def add(self, name, function):
# A small sanity check.
# FIXME
- if not self.compiled_rx.match(name + '<>'):
+ if not self.compiled_rx.match(name):
raise ValueError('libstdc++ programming error: "%s" does not match' % name)
printer = RxPrinter(name, function)
self.subprinters.append(printer)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 10679 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20140714/c1e80f91/attachment.bin>
More information about the Libstdc++
mailing list