1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 from libreoffice
.util
import printing
14 class SvArrayPrinter(object):
15 '''Prints macro-declared arrays from svl module'''
17 def __init__(self
, typename
, value
):
18 self
.typename
= typename
22 if int(self
.value
['nA']):
23 return "%s of length %d" % (self
.typename
, self
.value
['nA'])
25 return "empty " + self
.typename
28 return self
._iterator
(self
.value
['pData'], self
.value
['nA'])
30 def display_hint(self
):
33 class _iterator(object):
35 def __init__(self
, data
, count
):
39 self
._check
_invariant
()
45 if self
.pos
== self
.count
:
50 self
.pos
= self
.pos
+ 1
52 self
._check
_invariant
()
53 return (str(pos
), elem
)
55 def _check_invariant(self
):
56 assert self
.count
>= 0
60 assert self
.pos
<= self
.count
64 if type.code
== gdb
.TYPE_CODE_REF
:
66 type = type.unqualified().strip_typedefs()
71 ushort
= gdb
.lookup_type('sal_uInt16')
73 for field
in type.fields():
74 if field
.name
== 'pData':
75 conforming
= field
.type.code
== gdb
.TYPE_CODE_PTR
76 elif field
.name
== 'nFree':
77 conforming
= field
.type == ushort
78 elif field
.name
== 'nA':
79 conforming
= field
.type == ushort
86 gdb
.lookup_type('FnForEach_' + type.tag
)
94 def build_pretty_printers():
97 printer
= printing
.Printer("libreoffice/svl")
99 # macro-based arrays from svl module
100 printer
.add('SvArray', SvArrayPrinter
, SvArrayPrinter
.query
)
102 def register_pretty_printers(obj
):
103 printing
.register_pretty_printer(printer
, obj
)
105 build_pretty_printers()
107 # vim:set shiftwidth=4 softtabstop=4 expandtab: