diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-10-13 13:16:34 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-10-13 14:03:46 -0700 |
commit | 780a0d771edbe21dcfa3405163ffbdf7f7fa4604 (patch) | |
tree | ac202254d015d2a2a28ab5bca60c3f5474d168ba /src/compat/option.py | |
parent | a5e0fe8204a8b3299507a645f3479e9ead6c6110 (diff) | |
download | tmwa-780a0d771edbe21dcfa3405163ffbdf7f7fa4604.tar.gz tmwa-780a0d771edbe21dcfa3405163ffbdf7f7fa4604.tar.bz2 tmwa-780a0d771edbe21dcfa3405163ffbdf7f7fa4604.tar.xz tmwa-780a0d771edbe21dcfa3405163ffbdf7f7fa4604.zip |
Convert container lookups to use Option<Borrowed<T>>
Diffstat (limited to 'src/compat/option.py')
-rw-r--r-- | src/compat/option.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/compat/option.py b/src/compat/option.py new file mode 100644 index 0000000..a410ac8 --- /dev/null +++ b/src/compat/option.py @@ -0,0 +1,37 @@ +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 = ''' + 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))', 'regex:Some<tmwa::Borrowed<int>>\(0x[0-9a-f]* <option_borrow_thingy>\)'), + ] |