public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix pretty printers for versioned namespace
@ 2017-10-26 20:26 François Dumont
  2017-10-26 20:37 ` Jonathan Wakely
  0 siblings, 1 reply; 8+ messages in thread
From: François Dumont @ 2017-10-26 20:26 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 271 bytes --]

Hi

     When restoring versioned namespace feature I forgot to check for 
the pretty printer tests which are now broken.

     Here is the patch to fix those. Tested under Linux x86_64 normal 
and versioned namepace modes, ok to commit ?

François


[-- Attachment #2: printers.patch --]
[-- Type: text/x-patch, Size: 6571 bytes --]

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index b7b2a0f..0a168fe 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -973,8 +973,8 @@ class StdExpAnyPrinter(SingleObjContainerPrinter):
     "Print a std::any or std::experimental::any"
 
     def __init__ (self, typename, val):
-        self.typename = re.sub('^std::experimental::fundamentals_v\d::', 'std::experimental::', typename, 1)
-        self.typename = strip_versioned_namespace(self.typename)
+        self.typename = strip_versioned_namespace(typename)
+        self.typename = re.sub('^std::experimental::fundamentals_v\d::', 'std::experimental::', self.typename, 1)
         self.val = val
         self.contained_type = None
         contained_value = None
@@ -1021,8 +1021,8 @@ class StdExpOptionalPrinter(SingleObjContainerPrinter):
 
     def __init__ (self, typename, val):
         valtype = self._recognize (val.type.template_argument(0))
-        self.typename = re.sub('^std::(experimental::|)(fundamentals_v\d::|)(.*)', r'std::\1\3<%s>' % valtype, typename, 1)
-        self.typename = strip_versioned_namespace(self.typename)
+        self.typename = strip_versioned_namespace(typename)
+        self.typename = re.sub('^std::(experimental::|)(fundamentals_v\d::|)(.*)', r'std::\1\3<%s>' % valtype, self.typename, 1)
         if not self.typename.startswith('std::experimental'):
             val = val['_M_payload']
         self.val = val
@@ -1043,8 +1043,8 @@ class StdVariantPrinter(SingleObjContainerPrinter):
 
     def __init__(self, typename, val):
         alternatives = self._template_args(val)
-        self.typename = "%s<%s>" % (typename, ', '.join([self._recognize(alt) for alt in alternatives]))
-        self.typename = strip_versioned_namespace(self.typename)
+        self.typename = strip_versioned_namespace(typename)
+        self.typename = "%s<%s>" % (self.typename, ', '.join([self._recognize(alt) for alt in alternatives]))
         self.index = val['_M_index']
         if self.index >= len(alternatives):
             self.contained_type = None
@@ -1232,7 +1232,7 @@ class Printer(object):
     # Add a name using _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
     def add_container(self, base, name, function):
         self.add_version(base, name, function)
-        self.add_version(base + '__cxx1998::', name, function)
+        self.add_version(base, '__cxx1998::' + name, function)
 
     @staticmethod
     def get_basic_type(type):
@@ -1511,7 +1511,7 @@ def build_libstdcxx_dictionary ():
     libstdcxx_printer.add_container('std::', 'bitset', StdBitsetPrinter)
     libstdcxx_printer.add_container('std::', 'deque', StdDequePrinter)
     libstdcxx_printer.add_container('std::', 'list', StdListPrinter)
-    libstdcxx_printer.add_container('std::__cxx11::', 'list', StdListPrinter)
+    libstdcxx_printer.add_container('std::', '__cxx11::list', StdListPrinter)
     libstdcxx_printer.add_container('std::', 'map', StdMapPrinter)
     libstdcxx_printer.add_container('std::', 'multimap', StdMapPrinter)
     libstdcxx_printer.add_container('std::', 'multiset', StdSetPrinter)
@@ -1581,33 +1581,33 @@ def build_libstdcxx_dictionary ():
                           StdForwardListPrinter)
 
     # Library Fundamentals TS components
-    libstdcxx_printer.add_version('std::experimental::fundamentals_v1::',
-                                  'any', StdExpAnyPrinter)
-    libstdcxx_printer.add_version('std::experimental::fundamentals_v1::',
-                                  'optional', StdExpOptionalPrinter)
-    libstdcxx_printer.add_version('std::experimental::fundamentals_v1::',
-                                  'basic_string_view', StdExpStringViewPrinter)
+    libstdcxx_printer.add_version('std::', 'experimental::fundamentals_v1::any',
+                                  StdExpAnyPrinter)
+    libstdcxx_printer.add_version('std::', 'experimental::fundamentals_v1::optional',
+                                  StdExpOptionalPrinter)
+    libstdcxx_printer.add_version('std::', 'experimental::fundamentals_v1::basic_string_view',
+                                  StdExpStringViewPrinter)
     # Filesystem TS components
-    libstdcxx_printer.add_version('std::experimental::filesystem::v1::',
-                                  'path', StdExpPathPrinter)
-    libstdcxx_printer.add_version('std::experimental::filesystem::v1::__cxx11::',
-                                  'path', StdExpPathPrinter)
-    libstdcxx_printer.add_version('std::filesystem::',
-                                  'path', StdExpPathPrinter)
-    libstdcxx_printer.add_version('std::filesystem::__cxx11::',
-                                  'path', StdExpPathPrinter)
+    libstdcxx_printer.add_version('std::', 'experimental::filesystem::v1::path',
+                                  StdExpPathPrinter)
+    libstdcxx_printer.add_version('std::', 'experimental::filesystem::v1::__cxx11::path',
+                                  StdExpPathPrinter)
+    libstdcxx_printer.add_version('std::', 'filesystem::path',
+                                  StdExpPathPrinter)
+    libstdcxx_printer.add_version('std::', 'filesystem::__cxx11::path',
+                                  StdExpPathPrinter)
 
     # C++17 components
-    libstdcxx_printer.add_version('std::',
-                                  'any', StdExpAnyPrinter)
-    libstdcxx_printer.add_version('std::',
-                                  'optional', StdExpOptionalPrinter)
-    libstdcxx_printer.add_version('std::',
-                                  'basic_string_view', StdExpStringViewPrinter)
-    libstdcxx_printer.add_version('std::',
-                                  'variant', StdVariantPrinter)
-    libstdcxx_printer.add_version('std::',
-                                  '_Node_handle', StdNodeHandlePrinter)
+    libstdcxx_printer.add_version('std::', 'any',
+                                  StdExpAnyPrinter)
+    libstdcxx_printer.add_version('std::', 'optional',
+                                  StdExpOptionalPrinter)
+    libstdcxx_printer.add_version('std::', 'basic_string_view',
+                                  StdExpStringViewPrinter)
+    libstdcxx_printer.add_version('std::', 'variant',
+                                  StdVariantPrinter)
+    libstdcxx_printer.add_version('std::', '_Node_handle',
+                                  StdNodeHandlePrinter)
 
     # Extensions.
     libstdcxx_printer.add_version('__gnu_cxx::', 'slist', StdSlistPrinter)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fix pretty printers for versioned namespace
  2017-10-26 20:26 Fix pretty printers for versioned namespace François Dumont
@ 2017-10-26 20:37 ` Jonathan Wakely
  2017-10-26 20:41   ` Jonathan Wakely
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2017-10-26 20:37 UTC (permalink / raw)
  To: François Dumont; +Cc: libstdc++, gcc-patches

On 26/10/17 22:19 +0200, François Dumont wrote:
>@@ -1232,7 +1232,7 @@ class Printer(object):
>     # Add a name using _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
>     def add_container(self, base, name, function):
>         self.add_version(base, name, function)
>-        self.add_version(base + '__cxx1998::', name, function)
>+        self.add_version(base, '__cxx1998::' + name, function)

I don't like this change.

Previously the arguments were the namespace(s) and the type. That's
nice and simple.

Now it's the first namespace, and then all the other namespaces and
the type. That's not very clean.

There must be a way to keep the add_version and add_container calls
the same, and have it transparently handle the case where the
namespace is 'std::__8::foo' not 'std::foo'.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fix pretty printers for versioned namespace
  2017-10-26 20:37 ` Jonathan Wakely
@ 2017-10-26 20:41   ` Jonathan Wakely
  2017-10-26 20:55     ` Jonathan Wakely
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2017-10-26 20:41 UTC (permalink / raw)
  To: François Dumont; +Cc: libstdc++, gcc-patches

On 26/10/17 21:30 +0100, Jonathan Wakely wrote:
>On 26/10/17 22:19 +0200, François Dumont wrote:
>>@@ -1232,7 +1232,7 @@ class Printer(object):
>>    # Add a name using _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
>>    def add_container(self, base, name, function):
>>        self.add_version(base, name, function)
>>-        self.add_version(base + '__cxx1998::', name, function)
>>+        self.add_version(base, '__cxx1998::' + name, function)
>
>I don't like this change.
>
>Previously the arguments were the namespace(s) and the type. That's
>nice and simple.
>
>Now it's the first namespace, and then all the other namespaces and
>the type. That's not very clean.
>
>There must be a way to keep the add_version and add_container calls
>the same, and have it transparently handle the case where the
>namespace is 'std::__8::foo' not 'std::foo'.

e.g. in add_version instead of:

        if _versioned_namespace:
            self.add(base + _versioned_namespace + name, function)

We should replace "std::" in base with "std::" + _versioned_namespace

That means we only have to change that function, not every call to it.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fix pretty printers for versioned namespace
  2017-10-26 20:41   ` Jonathan Wakely
@ 2017-10-26 20:55     ` Jonathan Wakely
  2017-10-30 17:30       ` François Dumont
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2017-10-26 20:55 UTC (permalink / raw)
  To: François Dumont; +Cc: libstdc++, gcc-patches

On 26/10/17 21:37 +0100, Jonathan Wakely wrote:
>On 26/10/17 21:30 +0100, Jonathan Wakely wrote:
>>On 26/10/17 22:19 +0200, François Dumont wrote:
>>>@@ -1232,7 +1232,7 @@ class Printer(object):
>>>   # Add a name using _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
>>>   def add_container(self, base, name, function):
>>>       self.add_version(base, name, function)
>>>-        self.add_version(base + '__cxx1998::', name, function)
>>>+        self.add_version(base, '__cxx1998::' + name, function)
>>
>>I don't like this change.
>>
>>Previously the arguments were the namespace(s) and the type. That's
>>nice and simple.
>>
>>Now it's the first namespace, and then all the other namespaces and
>>the type. That's not very clean.
>>
>>There must be a way to keep the add_version and add_container calls
>>the same, and have it transparently handle the case where the
>>namespace is 'std::__8::foo' not 'std::foo'.
>
>e.g. in add_version instead of:
>
>       if _versioned_namespace:
>           self.add(base + _versioned_namespace + name, function)
>
>We should replace "std::" in base with "std::" + _versioned_namespace
>
>That means we only have to change that function, not every call to it.

Something like this:

--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1227,7 +1227,8 @@ class Printer(object):
     def add_version(self, base, name, function):
         self.add(base + name, function)
         if _versioned_namespace:
-            self.add(base + _versioned_namespace + name, function)
+            vbase = re.sub('^std::', 'std::%s::' % _versioned_namespace, base)
+            self.add(vbase + name, function)
 
     # Add a name using _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
     def add_container(self, base, name, function):


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fix pretty printers for versioned namespace
  2017-10-26 20:55     ` Jonathan Wakely
@ 2017-10-30 17:30       ` François Dumont
  2017-10-30 18:05         ` Jonathan Wakely
  0 siblings, 1 reply; 8+ messages in thread
From: François Dumont @ 2017-10-30 17:30 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2378 bytes --]

On 26/10/2017 22:41, Jonathan Wakely wrote:
> On 26/10/17 21:37 +0100, Jonathan Wakely wrote:
>> On 26/10/17 21:30 +0100, Jonathan Wakely wrote:
>>> On 26/10/17 22:19 +0200, François Dumont wrote:
>>>> @@ -1232,7 +1232,7 @@ class Printer(object):
>>>>   # Add a name using _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
>>>>   def add_container(self, base, name, function):
>>>>       self.add_version(base, name, function)
>>>> -        self.add_version(base + '__cxx1998::', name, function)
>>>> +        self.add_version(base, '__cxx1998::' + name, function)
>>>
>>> I don't like this change.
>>>
>>> Previously the arguments were the namespace(s) and the type. That's
>>> nice and simple.

Not always, see updated patch.

>>>
>>> Now it's the first namespace, and then all the other namespaces and
>>> the type. That's not very clean.
>>>
>>> There must be a way to keep the add_version and add_container calls
>>> the same, and have it transparently handle the case where the
>>> namespace is 'std::__8::foo' not 'std::foo'.
>>
>> e.g. in add_version instead of:
>>
>>       if _versioned_namespace:
>>           self.add(base + _versioned_namespace + name, function)
>>
>> We should replace "std::" in base with "std::" + _versioned_namespace
>>
>> That means we only have to change that function, not every call to it.
>
> Something like this:
>
> --- a/libstdc++-v3/python/libstdcxx/v6/printers.py
> +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
> @@ -1227,7 +1227,8 @@ class Printer(object):
>     def add_version(self, base, name, function):
>         self.add(base + name, function)
>         if _versioned_namespace:
> -            self.add(base + _versioned_namespace + name, function)
> +            vbase = re.sub('^std::', 'std::%s::' % 
> _versioned_namespace, base)
> +            self.add(vbase + name, function)
>
>     # Add a name using _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
>     def add_container(self, base, name, function)

Ok, I have adapted and generalized this approache to all symbols.

Tested under Linux x86_64 normal and versioned namespace modes.

Ok to commit ?

François

[-- Attachment #2: printers.patch --]
[-- Type: text/x-patch, Size: 4857 bytes --]

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index b7b2a0f..2bbe458 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -973,8 +973,8 @@ class StdExpAnyPrinter(SingleObjContainerPrinter):
     "Print a std::any or std::experimental::any"
 
     def __init__ (self, typename, val):
-        self.typename = re.sub('^std::experimental::fundamentals_v\d::', 'std::experimental::', typename, 1)
-        self.typename = strip_versioned_namespace(self.typename)
+        self.typename = strip_versioned_namespace(typename)
+        self.typename = re.sub('^std::experimental::fundamentals_v\d::', 'std::experimental::', self.typename, 1)
         self.val = val
         self.contained_type = None
         contained_value = None
@@ -1021,8 +1021,8 @@ class StdExpOptionalPrinter(SingleObjContainerPrinter):
 
     def __init__ (self, typename, val):
         valtype = self._recognize (val.type.template_argument(0))
-        self.typename = re.sub('^std::(experimental::|)(fundamentals_v\d::|)(.*)', r'std::\1\3<%s>' % valtype, typename, 1)
-        self.typename = strip_versioned_namespace(self.typename)
+        self.typename = strip_versioned_namespace(typename)
+        self.typename = re.sub('^std::(experimental::|)(fundamentals_v\d::|)(.*)', r'std::\1\3<%s>' % valtype, self.typename, 1)
         if not self.typename.startswith('std::experimental'):
             val = val['_M_payload']
         self.val = val
@@ -1043,8 +1043,8 @@ class StdVariantPrinter(SingleObjContainerPrinter):
 
     def __init__(self, typename, val):
         alternatives = self._template_args(val)
-        self.typename = "%s<%s>" % (typename, ', '.join([self._recognize(alt) for alt in alternatives]))
-        self.typename = strip_versioned_namespace(self.typename)
+        self.typename = strip_versioned_namespace(typename)
+        self.typename = "%s<%s>" % (self.typename, ', '.join([self._recognize(alt) for alt in alternatives]))
         self.index = val['_M_index']
         if self.index >= len(alternatives):
             self.contained_type = None
@@ -1227,7 +1227,12 @@ class Printer(object):
     def add_version(self, base, name, function):
         self.add(base + name, function)
         if _versioned_namespace:
-            self.add(base + _versioned_namespace + name, function)
+            vbase = re.sub('^std::', 'std::%s' % _versioned_namespace, base)
+            if vbase != base:
+                self.add(vbase + name, function)
+            vbase = re.sub('^__gnu_cxx::', '__gnu_cxx::%s' % _versioned_namespace, base)
+            if vbase != base:
+                self.add(vbase + name, function)
 
     # Add a name using _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
     def add_container(self, base, name, function):
@@ -1507,7 +1512,7 @@ def build_libstdcxx_dictionary ():
     # In order from:
     # http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01847.html
     libstdcxx_printer.add_version('std::', 'basic_string', StdStringPrinter)
-    libstdcxx_printer.add_version('std::', '__cxx11::basic_string', StdStringPrinter)
+    libstdcxx_printer.add_version('std::__cxx11::', 'basic_string', StdStringPrinter)
     libstdcxx_printer.add_container('std::', 'bitset', StdBitsetPrinter)
     libstdcxx_printer.add_container('std::', 'deque', StdDequePrinter)
     libstdcxx_printer.add_container('std::', 'list', StdListPrinter)
@@ -1555,15 +1560,15 @@ def build_libstdcxx_dictionary ():
     libstdcxx_printer.add_container('std::', 'forward_list',
                                     StdForwardListPrinter)
 
-    libstdcxx_printer.add_version('std::', 'tr1::shared_ptr', SharedPointerPrinter)
-    libstdcxx_printer.add_version('std::', 'tr1::weak_ptr', SharedPointerPrinter)
-    libstdcxx_printer.add_version('std::', 'tr1::unordered_map',
+    libstdcxx_printer.add_version('std::tr1::', 'shared_ptr', SharedPointerPrinter)
+    libstdcxx_printer.add_version('std::tr1::', 'weak_ptr', SharedPointerPrinter)
+    libstdcxx_printer.add_version('std::tr1::', 'unordered_map',
                                   Tr1UnorderedMapPrinter)
-    libstdcxx_printer.add_version('std::', 'tr1::unordered_set',
+    libstdcxx_printer.add_version('std::tr1::', 'unordered_set',
                                   Tr1UnorderedSetPrinter)
-    libstdcxx_printer.add_version('std::', 'tr1::unordered_multimap',
+    libstdcxx_printer.add_version('std::tr1::', 'unordered_multimap',
                                   Tr1UnorderedMapPrinter)
-    libstdcxx_printer.add_version('std::', 'tr1::unordered_multiset',
+    libstdcxx_printer.add_version('std::tr1::', 'unordered_multiset',
                                   Tr1UnorderedSetPrinter)
 
     # These are the C++11 printer registrations for -D_GLIBCXX_DEBUG cases.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fix pretty printers for versioned namespace
  2017-10-30 17:30       ` François Dumont
@ 2017-10-30 18:05         ` Jonathan Wakely
  2017-10-30 18:21           ` Jonathan Wakely
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2017-10-30 18:05 UTC (permalink / raw)
  To: François Dumont; +Cc: libstdc++, gcc-patches

On 30/10/17 18:13 +0100, François Dumont wrote:
>On 26/10/2017 22:41, Jonathan Wakely wrote:
>>On 26/10/17 21:37 +0100, Jonathan Wakely wrote:
>>>On 26/10/17 21:30 +0100, Jonathan Wakely wrote:
>>>>On 26/10/17 22:19 +0200, François Dumont wrote:
>>>>>@@ -1232,7 +1232,7 @@ class Printer(object):
>>>>>  # Add a name using _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
>>>>>  def add_container(self, base, name, function):
>>>>>      self.add_version(base, name, function)
>>>>>-        self.add_version(base + '__cxx1998::', name, function)
>>>>>+        self.add_version(base, '__cxx1998::' + name, function)
>>>>
>>>>I don't like this change.
>>>>
>>>>Previously the arguments were the namespace(s) and the type. That's
>>>>nice and simple.
>
>Not always, see updated patch.

Ah yes. Well it's nice to fix those cases then :-)

>@@ -1227,7 +1227,12 @@ class Printer(object):
>     def add_version(self, base, name, function):
>         self.add(base + name, function)
>         if _versioned_namespace:
>-            self.add(base + _versioned_namespace + name, function)
>+            vbase = re.sub('^std::', 'std::%s' % _versioned_namespace, base)
>+            if vbase != base:
>+                self.add(vbase + name, function)
>+            vbase = re.sub('^__gnu_cxx::', '__gnu_cxx::%s' % _versioned_namespace, base)
>+            if vbase != base:
>+                self.add(vbase + name, function)

Only one re.sub is needed:

vbase = re.sub('^(std|__gnu_cxx)::', r'\1::%s' % _versioned_namespace, base)

OK for trunk with that change, assuming it works. Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fix pretty printers for versioned namespace
  2017-10-30 18:05         ` Jonathan Wakely
@ 2017-10-30 18:21           ` Jonathan Wakely
  2017-11-01 18:04             ` François Dumont
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2017-10-30 18:21 UTC (permalink / raw)
  To: François Dumont; +Cc: libstdc++, gcc-patches

On 30/10/17 17:59 +0000, Jonathan Wakely wrote:
>On 30/10/17 18:13 +0100, François Dumont wrote:
>>On 26/10/2017 22:41, Jonathan Wakely wrote:
>>>On 26/10/17 21:37 +0100, Jonathan Wakely wrote:
>>>>On 26/10/17 21:30 +0100, Jonathan Wakely wrote:
>>>>>On 26/10/17 22:19 +0200, François Dumont wrote:
>>>>>>@@ -1232,7 +1232,7 @@ class Printer(object):
>>>>>>  # Add a name using _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
>>>>>>  def add_container(self, base, name, function):
>>>>>>      self.add_version(base, name, function)
>>>>>>-        self.add_version(base + '__cxx1998::', name, function)
>>>>>>+        self.add_version(base, '__cxx1998::' + name, function)
>>>>>
>>>>>I don't like this change.
>>>>>
>>>>>Previously the arguments were the namespace(s) and the type. That's
>>>>>nice and simple.
>>
>>Not always, see updated patch.
>
>Ah yes. Well it's nice to fix those cases then :-)
>
>>@@ -1227,7 +1227,12 @@ class Printer(object):
>>    def add_version(self, base, name, function):
>>        self.add(base + name, function)
>>        if _versioned_namespace:
>>-            self.add(base + _versioned_namespace + name, function)
>>+            vbase = re.sub('^std::', 'std::%s' % _versioned_namespace, base)
>>+            if vbase != base:
>>+                self.add(vbase + name, function)
>>+            vbase = re.sub('^__gnu_cxx::', '__gnu_cxx::%s' % _versioned_namespace, base)
>>+            if vbase != base:
>>+                self.add(vbase + name, function)
>
>Only one re.sub is needed:
>
>vbase = re.sub('^(std|__gnu_cxx)::', r'\1::%s' % _versioned_namespace, base)

Or using \g<0> to refer to the whole match:

vbase = re.sub('^(std|__gnu_cxx)::', r'\g<0>%s' % _versioned_namespace, base)

>OK for trunk with that change, assuming it works. Thanks.
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fix pretty printers for versioned namespace
  2017-10-30 18:21           ` Jonathan Wakely
@ 2017-11-01 18:04             ` François Dumont
  0 siblings, 0 replies; 8+ messages in thread
From: François Dumont @ 2017-11-01 18:04 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1325 bytes --]

On 30/10/2017 19:15, Jonathan Wakely wrote:
>
>>> @@ -1227,7 +1227,12 @@ class Printer(object):
>>>    def add_version(self, base, name, function):
>>>        self.add(base + name, function)
>>>        if _versioned_namespace:
>>> -            self.add(base + _versioned_namespace + name, function)
>>> +            vbase = re.sub('^std::', 'std::%s' % 
>>> _versioned_namespace, base)
>>> +            if vbase != base:
>>> +                self.add(vbase + name, function)
>>> +            vbase = re.sub('^__gnu_cxx::', '__gnu_cxx::%s' % 
>>> _versioned_namespace, base)
>>> +            if vbase != base:
>>> +                self.add(vbase + name, function)
>>
>> Only one re.sub is needed:
>>
>> vbase = re.sub('^(std|__gnu_cxx)::', r'\1::%s' % 
>> _versioned_namespace, base)
>
> Or using \g<0> to refer to the whole match:
>
> vbase = re.sub('^(std|__gnu_cxx)::', r'\g<0>%s' % 
> _versioned_namespace, base)
>
>> OK for trunk with that change, assuming it works. Thanks.
It worked, attached patch applied.

François


[-- Attachment #2: printers.patch --]
[-- Type: text/x-patch, Size: 4663 bytes --]

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index b7b2a0f..2b54065 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -973,8 +973,8 @@ class StdExpAnyPrinter(SingleObjContainerPrinter):
     "Print a std::any or std::experimental::any"
 
     def __init__ (self, typename, val):
-        self.typename = re.sub('^std::experimental::fundamentals_v\d::', 'std::experimental::', typename, 1)
-        self.typename = strip_versioned_namespace(self.typename)
+        self.typename = strip_versioned_namespace(typename)
+        self.typename = re.sub('^std::experimental::fundamentals_v\d::', 'std::experimental::', self.typename, 1)
         self.val = val
         self.contained_type = None
         contained_value = None
@@ -1021,8 +1021,8 @@ class StdExpOptionalPrinter(SingleObjContainerPrinter):
 
     def __init__ (self, typename, val):
         valtype = self._recognize (val.type.template_argument(0))
-        self.typename = re.sub('^std::(experimental::|)(fundamentals_v\d::|)(.*)', r'std::\1\3<%s>' % valtype, typename, 1)
-        self.typename = strip_versioned_namespace(self.typename)
+        self.typename = strip_versioned_namespace(typename)
+        self.typename = re.sub('^std::(experimental::|)(fundamentals_v\d::|)(.*)', r'std::\1\3<%s>' % valtype, self.typename, 1)
         if not self.typename.startswith('std::experimental'):
             val = val['_M_payload']
         self.val = val
@@ -1043,8 +1043,8 @@ class StdVariantPrinter(SingleObjContainerPrinter):
 
     def __init__(self, typename, val):
         alternatives = self._template_args(val)
-        self.typename = "%s<%s>" % (typename, ', '.join([self._recognize(alt) for alt in alternatives]))
-        self.typename = strip_versioned_namespace(self.typename)
+        self.typename = strip_versioned_namespace(typename)
+        self.typename = "%s<%s>" % (self.typename, ', '.join([self._recognize(alt) for alt in alternatives]))
         self.index = val['_M_index']
         if self.index >= len(alternatives):
             self.contained_type = None
@@ -1227,7 +1227,8 @@ class Printer(object):
     def add_version(self, base, name, function):
         self.add(base + name, function)
         if _versioned_namespace:
-            self.add(base + _versioned_namespace + name, function)
+            vbase = re.sub('^(std|__gnu_cxx)::', r'\g<0>%s' % _versioned_namespace, base)
+            self.add(vbase + name, function)
 
     # Add a name using _GLIBCXX_BEGIN_NAMESPACE_CONTAINER.
     def add_container(self, base, name, function):
@@ -1507,7 +1508,7 @@ def build_libstdcxx_dictionary ():
     # In order from:
     # http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01847.html
     libstdcxx_printer.add_version('std::', 'basic_string', StdStringPrinter)
-    libstdcxx_printer.add_version('std::', '__cxx11::basic_string', StdStringPrinter)
+    libstdcxx_printer.add_version('std::__cxx11::', 'basic_string', StdStringPrinter)
     libstdcxx_printer.add_container('std::', 'bitset', StdBitsetPrinter)
     libstdcxx_printer.add_container('std::', 'deque', StdDequePrinter)
     libstdcxx_printer.add_container('std::', 'list', StdListPrinter)
@@ -1555,15 +1556,15 @@ def build_libstdcxx_dictionary ():
     libstdcxx_printer.add_container('std::', 'forward_list',
                                     StdForwardListPrinter)
 
-    libstdcxx_printer.add_version('std::', 'tr1::shared_ptr', SharedPointerPrinter)
-    libstdcxx_printer.add_version('std::', 'tr1::weak_ptr', SharedPointerPrinter)
-    libstdcxx_printer.add_version('std::', 'tr1::unordered_map',
+    libstdcxx_printer.add_version('std::tr1::', 'shared_ptr', SharedPointerPrinter)
+    libstdcxx_printer.add_version('std::tr1::', 'weak_ptr', SharedPointerPrinter)
+    libstdcxx_printer.add_version('std::tr1::', 'unordered_map',
                                   Tr1UnorderedMapPrinter)
-    libstdcxx_printer.add_version('std::', 'tr1::unordered_set',
+    libstdcxx_printer.add_version('std::tr1::', 'unordered_set',
                                   Tr1UnorderedSetPrinter)
-    libstdcxx_printer.add_version('std::', 'tr1::unordered_multimap',
+    libstdcxx_printer.add_version('std::tr1::', 'unordered_multimap',
                                   Tr1UnorderedMapPrinter)
-    libstdcxx_printer.add_version('std::', 'tr1::unordered_multiset',
+    libstdcxx_printer.add_version('std::tr1::', 'unordered_multiset',
                                   Tr1UnorderedSetPrinter)
 
     # These are the C++11 printer registrations for -D_GLIBCXX_DEBUG cases.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-11-01 18:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-26 20:26 Fix pretty printers for versioned namespace François Dumont
2017-10-26 20:37 ` Jonathan Wakely
2017-10-26 20:41   ` Jonathan Wakely
2017-10-26 20:55     ` Jonathan Wakely
2017-10-30 17:30       ` François Dumont
2017-10-30 18:05         ` Jonathan Wakely
2017-10-30 18:21           ` Jonathan Wakely
2017-11-01 18:04             ` François Dumont

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).