Tweak formatting and docs for pretty printers
authorJonathan Wakely <jwakely@redhat.com>
Thu, 15 Dec 2016 12:45:47 +0000 (12:45 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 15 Dec 2016 12:45:47 +0000 (12:45 +0000)
* python/libstdcxx/v6/printers.py (UniquePointerPrinter.to_string):
Remove redundant parentheses.
(RbtreeIterator, StdRbtreeIteratorPrinter): Add docstrings.
(StdForwardListPrinter.to_string): Remove redundant parentheses.
(StdExpOptionalPrinter.to_string): Use string formatting instead of
concatenation.
(StdVariantPrinter.to_string, StdNodeHandlePrinter.to_string)
(TemplateTypePrinter): Adjust whitespace.

From-SVN: r243689

libstdc++-v3/ChangeLog
libstdc++-v3/python/libstdcxx/v6/printers.py

index a881ee6829da43ffd3e32d4c6f19ad5d233c1e49..14c0c6e0dc7b1a341dbe6da6433cdb6d97ac000d 100644 (file)
@@ -1,5 +1,14 @@
 2016-12-15  Jonathan Wakely  <jwakely@redhat.com>
 
+       * python/libstdcxx/v6/printers.py (UniquePointerPrinter.to_string):
+       Remove redundant parentheses.
+       (RbtreeIterator, StdRbtreeIteratorPrinter): Add docstrings.
+       (StdForwardListPrinter.to_string): Remove redundant parentheses.
+       (StdExpOptionalPrinter.to_string): Use string formatting instead of
+       concatenation.
+       (StdVariantPrinter.to_string, StdNodeHandlePrinter.to_string)
+       (TemplateTypePrinter): Adjust whitespace.
+
        * python/libstdcxx/v6/xmethods.py (UniquePtrGetWorker.__init__): Use
        correct element type for unique_ptr<T[]>.
        (UniquePtrGetWorker._supports, UniquePtrDerefWorker._supports): New
index 3a111d793cb40e22e8ebd5eeca90db6ce36e1cab..9d84b4f263b986755719591730e9b748225c55c6 100644 (file)
@@ -133,8 +133,8 @@ class UniquePointerPrinter:
             v = self.val['_M_t']['_M_head_impl']
         else:
             raise ValueError("Unsupported implementation for unique_ptr: %s" % self.val.type.fields()[0].type.tag)
-        return ('std::unique_ptr<%s> containing %s' % (str(v.type.target()),
-                                                       str(v)))
+        return 'std::unique_ptr<%s> containing %s' % (str(v.type.target()),
+                                                      str(v))
 
 def get_value_from_aligned_membuf(buf, valtype):
     """Returns the value held in a __gnu_cxx::__aligned_membuf."""
@@ -428,6 +428,11 @@ class StdStackOrQueuePrinter:
         return None
 
 class RbtreeIterator(Iterator):
+    """
+    Turn an RB-tree-based container (std::map, std::set etc.) into
+    a Python iterable object.
+    """
+
     def __init__(self, rbtree):
         self.size = rbtree['_M_t']['_M_impl']['_M_node_count']
         self.node = rbtree['_M_t']['_M_impl']['_M_header']['_M_left']
@@ -480,7 +485,7 @@ def get_value_from_Rb_tree_node(node):
 # std::map::iterator), and has nothing to do with the RbtreeIterator
 # class above.
 class StdRbtreeIteratorPrinter:
-    "Print std::map::iterator"
+    "Print std::map::iterator, std::set::iterator, etc."
 
     def __init__ (self, typename, val):
         self.val = val
@@ -891,8 +896,8 @@ class StdForwardListPrinter:
 
     def to_string(self):
         if self.val['_M_impl']['_M_head']['_M_next'] == 0:
-            return 'empty %s' % (self.typename)
-        return '%s' % (self.typename)
+            return 'empty %s' % self.typename
+        return '%s' % self.typename
 
 class SingleObjContainerPrinter(object):
     "Base class for printers of containers of single objects"
@@ -994,9 +999,10 @@ class StdExpOptionalPrinter(SingleObjContainerPrinter):
 
     def to_string (self):
         if self.contained_value is None:
-            return self.typename + " [no contained value]"
+            return "%s [no contained value]" % self.typename
         if hasattr (self.visualizer, 'children'):
-            return self.typename + " containing " + self.visualizer.to_string ()
+            return "%s containing %s" % (self.typename,
+                                         self.visualizer.to_string())
         return self.typename
 
 class StdVariantPrinter(SingleObjContainerPrinter):
@@ -1032,7 +1038,8 @@ class StdVariantPrinter(SingleObjContainerPrinter):
         if self.contained_value is None:
             return "%s [no contained value]" % self.typename
         if hasattr(self.visualizer, 'children'):
-            return "%s [index %d] containing %s" % (self.typename, self.index, self.visualizer.to_string())
+            return "%s [index %d] containing %s" % (self.typename, self.index,
+                                                    self.visualizer.to_string())
         return "%s [index %d]" % (self.typename, self.index)
 
 class StdNodeHandlePrinter(SingleObjContainerPrinter):
@@ -1060,7 +1067,6 @@ class StdNodeHandlePrinter(SingleObjContainerPrinter):
                                                    'array')
 
     def to_string(self):
-
         desc = 'node handle for '
         if not self.is_rb_tree_node:
             desc += 'unordered '
@@ -1230,7 +1236,8 @@ class Printer(object):
 libstdcxx_printer = None
 
 class TemplateTypePrinter(object):
-    r"""A type printer for class templates.
+    r"""
+    A type printer for class templates.
 
     Recognizes type names that match a regular expression.
     Replaces them with a formatted string which can use replacement field