From 3c80034b37df052d4834ef5738d3c348cf5794ac Mon Sep 17 00:00:00 2001 From: redi Date: Sun, 8 Jan 2012 12:34:00 +0000 Subject: [PATCH] * python/libstdcxx/v6/printers.py (StdForwardListPrinter): Add. * testsuite/libstdc++-prettyprinters/cxx11.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@182989 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 5 ++ libstdc++-v3/python/libstdcxx/v6/printers.py | 46 ++++++++++++ .../testsuite/libstdc++-prettyprinters/cxx11.cc | 82 ++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f2e68c5dc8f..a2d2107a05a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2012-01-08 Jonathan Wakely + + * python/libstdcxx/v6/printers.py (StdForwardListPrinter): Add. + * testsuite/libstdc++-prettyprinters/cxx11.cc: New. + 2012-01-06 Jason Merrill * testsuite/abi/demangle/regression/cw-16.cc (main): Adjust diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 4197c081d9c..81c33c733e6 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -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. diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc new file mode 100644 index 00000000000..6915526d90b --- /dev/null +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc @@ -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 } } -- 2.11.4.GIT