blob: 7704174d8c59c6f5f8d7e52619fd13376730a5ce (
plain) (
blame)
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
35
36
37
38
39
|
class Option(object):
__slots__ = ('_value')
name = 'tmwa::option::Option'
enabled = True
def __init__(self, value):
self._value = value['repr']
def to_string(self):
value = self._value
ty = value.type.template_argument(0)
try:
some = bool(value['_some'])
except gdb.error:
stupider = value['stupider']
if stupider:
return 'Some<%s>(%s)' % (ty, stupider)
else:
return 'None<%s>' % ty
else:
if some:
data = value['_data']
data = data.address.cast(ty.pointer()).dereference()
return 'Some<%s>(%s)' % (ty, data)
else:
return 'None<%s>' % ty
test_extra = '''
#include "../compat/borrow.hpp"
static int option_borrow_thingy;
'''
tests = [
('tmwa::None<int>()', 'None<int>'),
('tmwa::Some(1)', 'Some<int>(1)'),
('tmwa::Option<tmwa::Borrowed<int>>(tmwa::None)', 'None<tmwa::Borrowed<int>>'),
('tmwa::Some(tmwa::borrow(option_borrow_thingy))', 'Some<tmwa::Borrowed<int>>(<option_borrow_thingy>)'),
]
|