From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 56085 invoked by alias); 30 Oct 2017 17:13:20 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 56064 invoked by uid 89); 30 Oct 2017 17:13:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=onlinedocs, printer, basic_string, bitset X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-wr0-f180.google.com Received: from mail-wr0-f180.google.com (HELO mail-wr0-f180.google.com) (209.85.128.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Oct 2017 17:13:17 +0000 Received: by mail-wr0-f180.google.com with SMTP id w105so13397769wrc.0; Mon, 30 Oct 2017 10:13:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=IbYWEWlo/9F/73WogBkMbCnPfAOpri/gpkCTnKmc5po=; b=r+VzVti1sE769vEzGsU1THlkQ2yQcR5K7nSLDA9dZJ/of4yk500wr6eDs7N/6DhzTN eNjDWGLcEioAR4Hpdz3FBMAcp+eLhTAOi5oIvGwYEVmdwwZlhcvRSYrcHy7TVKCiyVmN lxPid6MbJnhgAaDlBbgHbsmVxWHMoYWnqDzfXmMI/HJqBRrOua1QZhIflquUPWyyAXAb K9zLvB9u1bEMPigaMOm62Nzs2Aj9G7CiUK7LYmUSblM4Bj+qhrm0+qhEwC+xbSHv++2t KdVVRzF3fcp5rFAWdFDkjkbkaOPg+uV8miqQ0au3luur68v1i/GtpeeKlyoH89M9/K7f z9bA== X-Gm-Message-State: AMCzsaVzkSLXI8q0KuZsq8+zi/vXOSBo0RCP369l8F3YkMOX+PAmN8iD wRA9tM5+9aet65UsKNWBF6CeKw== X-Google-Smtp-Source: ABhQp+QSGHOuGvHoqp5SRdLbUXAjMeZl5QhBHj0E7Yfp1MDc96v3oMZwL3lkLMmbV2lQ7rEJAdkAGA== X-Received: by 10.223.197.69 with SMTP id s5mr9010693wrf.120.1509383595222; Mon, 30 Oct 2017 10:13:15 -0700 (PDT) Received: from [10.11.8.66] ([109.190.253.11]) by smtp.googlemail.com with ESMTPSA id d4sm3763839wma.29.2017.10.30.10.13.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Oct 2017 10:13:14 -0700 (PDT) Subject: Re: Fix pretty printers for versioned namespace To: Jonathan Wakely Cc: "libstdc++@gcc.gnu.org" , gcc-patches References: <29900c34-03ae-453d-3e96-401620b4f5c8@gmail.com> <20171026203008.GL9153@redhat.com> <20171026203747.GM9153@redhat.com> <20171026204111.GN9153@redhat.com> From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= Message-ID: Date: Mon, 30 Oct 2017 17:30:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171026204111.GN9153@redhat.com> Content-Type: multipart/mixed; boundary="------------31CBB0F71E6237DF271AE82D" X-SW-Source: 2017-10/txt/msg02227.txt.bz2 This is a multi-part message in MIME format. --------------31CBB0F71E6237DF271AE82D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-length: 2192 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 --------------31CBB0F71E6237DF271AE82D Content-Type: text/x-patch; name="printers.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="printers.patch" Content-length: 4857 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. --------------31CBB0F71E6237DF271AE82D--