llvm.org GIT mirror llvm / 4bdcc32
GDB pretty printer for llvm::Optional (some other implementations of an optional pretty printer print the full name of the optional type (including template parameter) - but seems if the template parameter isn't printed for std::vector, not sure why it would be printed for optional, so erring on the side of consistency in that direction here - compact, etc, as well) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289976 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 3 years ago
1 changed file(s) with 29 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
102102 def display_hint (self):
103103 return 'array'
104104
105 class OptionalPrinter:
106 """Print an llvm::Optional object."""
107
108 def __init__(self, value):
109 self.value = value
110
111 class _iterator:
112 def __init__(self, member, empty):
113 self.member = member
114 self.done = empty
115
116 def __iter__(self):
117 return self
118
119 def next(self):
120 if self.done:
121 raise StopIteration
122 self.done = True
123 return ('value', self.member.dereference())
124
125 def children(self):
126 if not self.value['hasVal']:
127 return self._iterator('', True)
128 return self._iterator(self.value['storage']['buffer'].address.cast(self.value.type.template_argument(0).pointer()), False)
129
130 def to_string(self):
131 return 'llvm::Optional is %sinitialized' % ('' if self.value['hasVal'] else 'not ')
132
105133 pp = gdb.printing.RegexpCollectionPrettyPrinter("LLVMSupport")
106134 pp.add_printer('llvm::SmallString', '^llvm::SmallString<.*>$', SmallStringPrinter)
107135 pp.add_printer('llvm::StringRef', '^llvm::StringRef$', StringRefPrinter)
108136 pp.add_printer('llvm::SmallVectorImpl', '^llvm::SmallVector(Impl)?<.*>$', SmallVectorPrinter)
109137 pp.add_printer('llvm::ArrayRef', '^llvm::(Const)?ArrayRef<.*>$', ArrayRefPrinter)
138 pp.add_printer('llvm::Optional', '^llvm::Optional<.*>$', OptionalPrinter)
110139 gdb.printing.register_pretty_printer(gdb.current_objfile(), pp)