-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtype_safe_index.py
34 lines (26 loc) · 1014 Bytes
/
type_safe_index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gdb
import re
class TypeSafeIndexPrinter:
TEMPLATE_RE = re.compile('^drake::TypeSafeIndex<[\w+:]+::(\w+)Tag>$')
def __init__(self, name, val, for_clion):
self.name = name
self.val = val
self.for_clion = for_clion
def to_string(self):
i_val = self.val['index_']
if (self.for_clion):
return 'Index(%d)' % (i_val)
else:
return 'drake::TypeSafeIndex<%sTag> (%d)' % (self.name, i_val)
def lookup_type(val, for_clion):
raw_type = val.type.unqualified().strip_typedefs()
constructor = None
match = TypeSafeIndexPrinter.TEMPLATE_RE.match(str(raw_type))
if (match):
constructor = TypeSafeIndexPrinter(match.group(1), val, for_clion)
return constructor
def register_printers(for_clion):
'''Registers id printers with gdb.
@param for_clion If True, this is being invoked by a gdb instance in CLion.
'''
gdb.pretty_printers.append(lambda val: lookup_type(val, for_clion))