From patchwork Sun Jan 8 12:34:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 134902 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id F1934B6F70 for ; Sun, 8 Jan 2012 23:34:50 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1326630891; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=dP1pRnh 1VA2TKw17yD7ScYZhSkc=; b=jWKtZvQWlyFLNbRhcH9771cK5HAyBBwBLfKZCbn j2YxaGV414Qk74b06QB7tFpJtzGBLdmpebt0rQKML6iAQ22RpQIO4mQOS2sg75vY b3gXO15PsJOMIWYh0fuL+sV/0rm/84Z6bU1A30k1ly8HS85JhAvlkXcBOsWILEqq 1+38= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Zn7yVNZyFQXvrZ/dM6gk1d+sCSxeE82ZIRDG7MTUqMnMl5XfCNO1/qbvAb+Xdn 9lPvPza8Ce/LaPfMuYUIahUGGlc4+3/xWTpOzRSpwct8AKuCasb92zQ4aRIMcL0/ pes7m/WEuDdGphcn7JJssuxogjMJre/K8WZ0DgbY/j2XQ=; Received: (qmail 19926 invoked by alias); 8 Jan 2012 12:34:40 -0000 Received: (qmail 19748 invoked by uid 22791); 8 Jan 2012 12:34:38 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-we0-f175.google.com (HELO mail-we0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 08 Jan 2012 12:34:25 +0000 Received: by werm13 with SMTP id m13so2351945wer.20 for ; Sun, 08 Jan 2012 04:34:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.136.75 with SMTP id v53mr5656693wei.42.1326026060581; Sun, 08 Jan 2012 04:34:20 -0800 (PST) Received: by 10.216.28.194 with HTTP; Sun, 8 Jan 2012 04:34:20 -0800 (PST) Date: Sun, 8 Jan 2012 12:34:20 +0000 Message-ID: Subject: add pretty printer for std::forward_list From: Jonathan Wakely To: "libstdc++" , gcc-patches Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 2012-01-08 Jonathan Wakely * python/libstdcxx/v6/printers.py (StdForwardListPrinter): Add. * testsuite/libstdc++-prettyprinters/cxx11.cc: New. Tested 'make check RUNTESTFLAGS=prettyprinters.exp' and committed to trunk The test also checks some of the other C++11 containers' printers but could be improved to give better coverage. Index: python/libstdcxx/v6/printers.py =================================================================== --- python/libstdcxx/v6/printers.py (revision 182988) +++ python/libstdcxx/v6/printers.py (working copy) @@ -687,6 +687,49 @@ class Tr1UnorderedMapPrinter: def display_hint (self): return 'map' +class StdForwardListPrinter: + "Print a std::forward_list" + + class _iterator: + def __init__(self, nodetype, head): + self.nodetype = nodetype + self.base = head['_M_next'] + self.count = 0 + + def __iter__(self): + return self + + def next(self): + if self.base == 0: + raise StopIteration + elt = self.base.cast(self.nodetype).dereference() + self.base = elt['_M_next'] + count = self.count + self.count = self.count + 1 + return ('[%d]' % count, elt['_M_value']) + + def __init__(self, typename, val): + self.val = val + self.typename = typename + + def children(self): + itype = self.val.type.template_argument(0) + # If the inferior program is compiled with -D_GLIBCXX_DEBUG + # some of the internal implementation details change. + if self.typename == "std::forward_list": + nodetype = gdb.lookup_type('std::_Fwd_list_node<%s>' % itype).pointer() + elif self.typename == "std::__debug::list": + nodetype = gdb.lookup_type('std::__norm::_Fwd_list_node<%s>' % itype).pointer() + else: + raise ValueError, "Cannot cast forward_list node for forward_list printer." + return self._iterator(nodetype, self.val['_M_impl']['_M_head']) + + def to_string(self): + if self.val['_M_impl']['_M_head']['_M_next'] == 0: + return 'empty %s' % (self.typename) + return '%s' % (self.typename) + + # A "regular expression" printer which conforms to the # "SubPrettyPrinter" protocol from gdb.printing. class RxPrinter(object): @@ -812,6 +855,7 @@ def build_libstdcxx_dictionary (): libstdcxx_printer.add('std::unordered_set', Tr1UnorderedSetPrinter) libstdcxx_printer.add('std::unordered_multimap', Tr1UnorderedMapPrinter) libstdcxx_printer.add('std::unordered_multiset', Tr1UnorderedSetPrinter) + libstdcxx_printer.add('std::forward_list', StdForwardListPrinter) libstdcxx_printer.add('std::tr1::shared_ptr', StdPointerPrinter) libstdcxx_printer.add('std::tr1::weak_ptr', StdPointerPrinter) @@ -833,6 +877,8 @@ def build_libstdcxx_dictionary (): Tr1UnorderedMapPrinter) libstdcxx_printer.add('std::__debug::unordered_multiset', Tr1UnorderedSetPrinter) + libstdcxx_printer.add('std::__debug::forward_list', + StdForwardListPrinter) # Extensions. Index: testsuite/libstdc++-prettyprinters/cxx11.cc =================================================================== --- testsuite/libstdc++-prettyprinters/cxx11.cc (revision 0) +++ testsuite/libstdc++-prettyprinters/cxx11.cc (revision 0) @@ -0,0 +1,82 @@ +// { dg-do run } +// { dg-options "-std=gnu++11 -g" } + +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include +#include + +template +void +placeholder(const T &s) +{ + std::cout << s; +} + +template +void +placeholder(const std::pair &s) +{ + std::cout << s.first; +} + +template +void +use(const T &container) +{ + for (typename T::const_iterator i = container.begin(); + i != container.end(); + ++i) + placeholder(*i); +} + +int +main() +{ + std::forward_list efl; +// { dg-final { note-test efl "empty std::forward_list" } } + + std::forward_list fl; + fl.push_front(2); + fl.push_front(1); +// { dg-final { note-test fl {std::forward_list = {[0] = 1, [1] = 2}} } } + + std::unordered_map eum; +// { dg-final { note-test eum "std::unordered_map with 0 elements" } } + std::unordered_multimap eumm; +// { dg-final { note-test eumm "std::unordered_multimap with 0 elements" } } + std::unordered_set eus; +// { dg-final { note-test eus "std::unordered_set with 0 elements" } } + std::unordered_multiset eums; +// { dg-final { note-test eums "std::unordered_multiset with 0 elements" } } + + placeholder(""); // Mark SPOT + use(efl); + use(fl); + use(eum); + use(eumm); + use(eus); + use(eums); + + return 0; +} + +// { dg-final { gdb-test SPOT } }