[PATCH] D30994: Add pretty-printer for llvm::Twine type

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 15 12:39:59 PDT 2017


dblaikie added inline comments.


================
Comment at: utils/gdb-scripts/prettyprinters.py:205-219
+  def string_from_pretty_printer_lookup(self, val):
+    '''Lookup the default pretty-printer for val and use it.
+
+    If no pretty-printer is defined for the type of val, print an error and
+    return a placeholder string.'''
+
+    pp = gdb.default_visualizer(val)
----------------
This seems more complicated than I would've expected, is str(val) insufficient?


================
Comment at: utils/gdb-scripts/prettyprinters.py:224-265
+    s = ''
+
+    if kind in ('llvm::Twine::EmptyKind', 'llvm::Twine::NullKind'):
+      pass
+    elif kind == 'llvm::Twine::TwineKind':
+      s = self.string_from_twine_object(child['twine'].dereference())
+    elif kind == 'llvm::Twine::CStringKind':
----------------
Rather than a long else-if chain with various assignments to 's', perhaps a more LLVM-esque style would be to return from each condition:

  if kind == ...:
    return str(...)
  if kind == UHexKind:
    return hex(int(val))
  /* do the unsupported NodeKind thing here */


Repository:
  rL LLVM

https://reviews.llvm.org/D30994





More information about the llvm-commits mailing list