Pretty printers for versioned namespace
Jonathan Wakely
jwakely@redhat.com
Tue Jan 10 12:39:00 GMT 2017
On 09/01/17 21:25 +0100, François Dumont wrote:
>On 04/01/2017 13:52, Jonathan Wakely wrote:
>>On 24/12/16 14:47 +0100, François Dumont wrote:
>>
>>I'd prefer not to have to use the regex matches in libstdc++.exp as
>>they complicate things.
>>
>>For the two examples above, the whatis results are bad even for the
>>non-versioned namespace. For specializations of basic_string we only
>>have type printers that recognize the standard typedefs like
>>std::u16string, but not other specializations. We really want it to
>>show std::basic_string<unsigned char> not the full name. That would
>>require a TemplateTypePrinter for basic_string. The attached patch
>>works, and should be easy to incorporate into your changes for the
>>versioned namespace.
>>
>+ add_one_template_type_printer(obj, 'basic_string<T>',
>+ 'basic_string<((un)?signed char), std::char_traits<\\1 ?>, std::allocator<\\1 ?> >',
>+ 'basic_string<{1}>')
>+
>
>I had consider a similar approach but more generic like:
>
>+ add_one_template_type_printer(obj, 'basic_string<T>',
>+ 'basic_string<(.*)?, std::char_traits<\\1 ?>, std::allocator<\\1 ?> >',
>+ 'basic_string<{1}>')
>+
>
>
>but it had bad effect on rendering of std::string type so I give up on this approach. Your version is indeed enough to cover not too exotic instantiations of std::basic_string.
Yes, I tried that first as well.
>I also updated 48362.cc test case as this test was already adapted for versioned namespace. But I had to keep one occurence of '__7' when displaying types inside a tuple. I think it is ok.
Yes, I think so too.
>Tested with versioned namespace. Is it ok to commit after I completed tests without versioned namespace ?
I've committed the attached patch, which passes the tests for the
default configuration and the versioned namespace configuration.
I added another helper function, strip_versioned_namespace, which is
more expressive than doing typename.replace(vers_nsp, '') everywhere.
I've also renamed vers_nsp to _versioned_namespace (using the naming
convention for global variables private to the module). I've added
checks so that if that variable is None then the extra printers and
special cases for the versioned namespace are skipped. That's not
currently used, but it would allow us to optimise things later if
needed.
I also needed to update the new SharedPtrMethodsMatcher to add
"(__\d+)?" to the regular expression.
>@@ -1392,47 +1406,54 @@ def register_type_printers(obj):
> add_one_type_printer(obj, 'discard_block_engine', 'ranlux48')
> add_one_type_printer(obj, 'shuffle_order_engine', 'knuth_b')
>
>+ # Consider optional versioned namespace
>+ opt_nsp = '(' + vers_nsp + ')?'
>+
> # Do not show defaulted template arguments in class templates
> add_one_template_type_printer(obj, 'unique_ptr<T>',
>- 'unique_ptr<(.*), std::default_delete<\\1 ?> >',
>- 'unique_ptr<{1}>')
>+ '{0}unique_ptr<(.*), std::{0}default_delete<\\2 ?> >'.format(opt_nsp),
>+ 'unique_ptr<{2}>')
This is ugly. Mixing python string formatting with regular expressions
makes it harder to read, and is inconsistent with how the versioned
namespace is handled elsewhere. In Printer.add_version and
add_one_type_printer we just register two names, one using std:: and
one using std::__7::. We can do the same for the template type
printers.
>@@ -1466,7 +1487,7 @@ def build_libstdcxx_dictionary ():
> libstdcxx_printer = Printer("libstdc++-v6")
>
> # For _GLIBCXX_BEGIN_NAMESPACE_VERSION.
>- vers = '(__7::)?'
>+ vers = '(' + vers_nsp + ')?'
> # For _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
> container = '(__cxx1998::' + vers + ')?'
>
These variables don't seem to be used, so can just be removed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 20052 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20170110/c450fb2e/attachment.bin>
More information about the Libstdc++
mailing list