From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 64CF03857C42 for ; Mon, 25 Apr 2022 12:39:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 64CF03857C42 Received: from mail-yw1-f198.google.com (mail-yw1-f198.google.com [209.85.128.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-245-kV5L7aigPBGFWzIo9XYx-A-1; Mon, 25 Apr 2022 08:39:11 -0400 X-MC-Unique: kV5L7aigPBGFWzIo9XYx-A-1 Received: by mail-yw1-f198.google.com with SMTP id 00721157ae682-2f4dfd09d7fso85014567b3.0 for ; Mon, 25 Apr 2022 05:39:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vm5dPfRr9+xL5Yw64LQG3ecpfvSbFBfaHEY441h52zg=; b=sEEbciJdDOG5ZtKvomTQCwrR9FXQYY952/FmVLuk/nIG1C6sf9GIFGF39TjTmpHnCo 9JbSOmrWBvwgOqwYAQgvpjiBPaAyCadQos+8BDAAW+pa5NHpaUJBYuniN5VRZe3iTiwW f1llblS5VaJ3WMzLFBl+t5/UqOCfGftwI7yiuBHdRh+MV99BBiyzJyoVWSmCSF3/iCtS AqpYGqWF6qygBf/ieoo+yWwPXn6j6Ta1Im/OUHNkEdXIvO2RHFIZ9jTqOk/V3ZspM+rD p5+UEDEg+huBFS6+hgFcaGMRSi6+B+8dZz/p9Zl3lHYPjpaz/0bQQJ/kd8rlG9l5XeDG wspQ== X-Gm-Message-State: AOAM530hbFsP4o2HVeV8NAxx2lFVP/XWH1CxmfhhaVlFc2R/y0bE9sra xp6J+fIUP53R9zuCXYL1pv8VLUrHA+Lz/572XQK+Yz3+IUSv/iOhLntlNyjNTW6rjDwfewk59A/ FXOjpw6NZDxuPKa3APZp+t1KEUSt7xkQ= X-Received: by 2002:a25:6f55:0:b0:63e:7447:7c19 with SMTP id k82-20020a256f55000000b0063e74477c19mr15487311ybc.551.1650890350485; Mon, 25 Apr 2022 05:39:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfOrYu7L1kprF4DE+naj5hlf2mrFf7EwfnUbTPPHX3yJqm0Iqh97T0Y7H5i6jv+Iq9/JAD1O/+iVbzuB5xlRI= X-Received: by 2002:a25:6f55:0:b0:63e:7447:7c19 with SMTP id k82-20020a256f55000000b0063e74477c19mr15487016ybc.551.1650890345391; Mon, 25 Apr 2022 05:39:05 -0700 (PDT) MIME-Version: 1.0 References: <20220424155025.150437-1-fent@in.tum.de> In-Reply-To: <20220424155025.150437-1-fent@in.tum.de> From: Jonathan Wakely Date: Mon, 25 Apr 2022 13:38:54 +0100 Message-ID: Subject: Re: [PATCH] libstdc++: Add pretty printer for std::initializer_list To: Philipp Fent Cc: "libstdc++" , gcc Patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Apr 2022 12:39:13 -0000 On Sun, 24 Apr 2022 at 16:51, Philipp Fent via Libstdc++ wrote: > > Re-using the std::span printer, this now shows the contents of the > initializer list instead of the pointer and length members. Nice, I've pushed this to trunk. Thanks! > > Signed-off-by: Philipp Fent > --- > libstdc++-v3/python/libstdcxx/v6/printers.py | 23 +++++++++++++++++-- > .../libstdc++-prettyprinters/cxx11.cc | 6 +++++ > 2 files changed, 27 insertions(+), 2 deletions(-) > > diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py > index 6d8b765f2..48798b6c1 100644 > --- a/libstdc++-v3/python/libstdcxx/v6/printers.py > +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py > @@ -1657,7 +1657,7 @@ class StdRegexStatePrinter: > class StdSpanPrinter: > "Print a std::span" > > - class _iterator(Iterator): > + class iterator(Iterator): > def __init__(self, begin, size): > self.count = 0 > self.begin = begin > @@ -1686,7 +1686,24 @@ class StdSpanPrinter: > return '%s of length %d' % (self.typename, self.size) > > def children(self): > - return self._iterator(self.val['_M_ptr'], self.size) > + return self.iterator(self.val['_M_ptr'], self.size) > + > + def display_hint(self): > + return 'array' > + > +class StdInitializerListPrinter: > + "Print a std::initializer_list" > + > + def __init__(self, typename, val): > + self.typename = typename > + self.val = val > + self.size = val['_M_len'] > + > + def to_string(self): > + return '%s of length %d' % (self.typename, self.size) > + > + def children(self): > + return StdSpanPrinter.iterator(self.val['_M_array'], self.size) > > def display_hint(self): > return 'array' > @@ -2156,6 +2173,8 @@ def build_libstdcxx_dictionary (): > libstdcxx_printer.add_version('std::tr1::', 'unordered_multiset', > Tr1UnorderedSetPrinter) > > + libstdcxx_printer.add_version('std::', 'initializer_list', StdInitializerListPrinter) > + > # std::regex components > libstdcxx_printer.add_version('std::__detail::', '_State', > StdRegexStatePrinter) > diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc > index 4262ca88b..621d13bd0 100644 > --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc > +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc > @@ -25,6 +25,7 @@ > #include > #include > #include > +#include > #include "../util/testsuite_allocator.h" // NullablePointer > > typedef std::tuple ExTuple; > @@ -191,6 +192,11 @@ main() > std::error_code ecfut0 = std::make_error_code(std::future_errc{}); > // { dg-final { note-test ecfut0 {std::error_code = {"future": 0}} } } > > + std::initializer_list emptyIl = {}; > + // { dg-final { note-test emptyIl {std::initializer_list of length 0} } } > + std::initializer_list il = {3, 4}; > + // { dg-final { note-test il {std::initializer_list of length 2 = {3, 4}} } } > + > placeholder(""); // Mark SPOT > use(efl); > use(fl); > -- > 2.36.0 >