]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
printers.py (StdVectorPrinter): Added stuff to handle pretty-printing of std::vector...
authorChris Moller <cmoller@redhat.com>
Mon, 16 Aug 2010 18:48:27 +0000 (18:48 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Mon, 16 Aug 2010 18:48:27 +0000 (18:48 +0000)
2010-08-16  Chris Moller  <cmoller@redhat.com>

http://sourceware.org/bugzilla/show_bug.cgi?id=11874
* python/libstdcxx/v6/printers.py (StdVectorPrinter): Added stuff
to handle pretty-printing of std::vector<bool>.

From-SVN: r163282

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

index ca4d305e1b9f51762832aae9b2c173ab6baee015..fa90d4d7bc0912d28ec913417651adf7f416d553 100644 (file)
@@ -1,3 +1,9 @@
+2010-08-16  Chris Moller  <cmoller@redhat.com>
+
+       http://sourceware.org/bugzilla/show_bug.cgi?id=11874
+       * python/libstdcxx/v6/printers.py (StdVectorPrinter): Added stuff
+       to handle pretty-printing of std::vector<bool>.
+
 2010-08-14  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
        PR libstdc++/45283
index fe278d6dfd760c8bdd9af6cfa9aa83c3daff4664..5333c57634fab62907947dac37e2e82eab414d47 100644 (file)
@@ -153,37 +153,71 @@ class StdVectorPrinter:
     "Print a std::vector"
 
     class _iterator:
-        def __init__ (self, start, finish):
-            self.item = start
-            self.finish = finish
+        def __init__ (self, start, finish, bitvec):
+            self.bitvec = bitvec
+            if bitvec:
+                self.item   = start['_M_p']
+                self.so     = start['_M_offset']
+                self.finish = finish['_M_p']
+                self.fo     = finish['_M_offset']
+                itype = self.item.dereference().type
+                self.isize = 8 * itype.sizeof
+            else:
+                self.item = start
+                self.finish = finish
             self.count = 0
 
         def __iter__(self):
             return self
 
         def next(self):
-            if self.item == self.finish:
-                raise StopIteration
             count = self.count
             self.count = self.count + 1
-            elt = self.item.dereference()
-            self.item = self.item + 1
-            return ('[%d]' % count, elt)
+            if self.bitvec:
+                if self.item == self.finish and self.so >= self.fo:
+                    raise StopIteration
+                elt = self.item.dereference()
+                obit = 1 if elt & (1 << self.so) else 0
+                self.so = self.so + 1
+                if self.so >= self.isize:
+                    self.item = self.item + 1
+                    self.so = 0
+                return ('[%d]' % count, obit)
+            else:
+                if self.item == self.finish:
+                    raise StopIteration
+                elt = self.item.dereference()
+                self.item = self.item + 1
+                return ('[%d]' % count, elt)
 
     def __init__(self, typename, val):
         self.typename = typename
         self.val = val
+        self.is_bool = val.type.template_argument(0).code  == gdb.TYPE_CODE_BOOL
 
     def children(self):
         return self._iterator(self.val['_M_impl']['_M_start'],
-                              self.val['_M_impl']['_M_finish'])
+                              self.val['_M_impl']['_M_finish'],
+                              self.is_bool)
 
     def to_string(self):
         start = self.val['_M_impl']['_M_start']
         finish = self.val['_M_impl']['_M_finish']
         end = self.val['_M_impl']['_M_end_of_storage']
-        return ('%s of length %d, capacity %d'
-                % (self.typename, int (finish - start), int (end - start)))
+        if self.is_bool:
+            start = self.val['_M_impl']['_M_start']['_M_p']
+            so    = self.val['_M_impl']['_M_start']['_M_offset']
+            finish = self.val['_M_impl']['_M_finish']['_M_p']
+            fo     = self.val['_M_impl']['_M_finish']['_M_offset']
+            itype = start.dereference().type
+            bl = 8 * itype.sizeof
+            length   = (bl - so) + bl * ((finish - start) - 1) + fo
+            capacity = bl * (end - start)
+            return ('%s<bool> of length %d, capacity %d'
+                    % (self.typename, int (length), int (capacity)))
+        else:
+            return ('%s of length %d, capacity %d'
+                    % (self.typename, int (finish - start), int (end - start)))
 
     def display_hint(self):
         return 'array'