fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / solenv / gdb / libreoffice / cppu.py
blob1ab2b6e6312ba627ea7e9611517743885175eb80
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/.
10 import six
12 from libreoffice.util import printing
13 from libreoffice.util.uno import TypeClass, make_uno_type, uno_cast
15 class UnoAnyPrinter(object):
16 '''Prints UNO any'''
18 def __init__(self, typename, value):
19 self.value = value
20 self.typename = typename.replace('com::sun::star::', '')
22 def to_string(self):
23 if self._is_set():
24 return ('%s %s' % (self.typename, self._make_string()))
25 else:
26 return "empty %s" % self.typename
28 def _is_set(self):
29 return self.value['pType'].dereference()['eTypeClass'] != TypeClass.VOID
31 def _make_string(self):
32 ptr = self.value['pData']
33 assert ptr
34 type_desc = self.value['pType']
35 assert type_desc
36 type = make_uno_type(type_desc.dereference())
37 assert type
38 return str(uno_cast(type, ptr).dereference())
40 class UnoReferencePrinter(object):
41 '''Prints reference to a UNO interface'''
43 def __init__(self, typename, value):
44 self.value = value
45 self.typename = typename.replace('com::sun::star::', '')
47 def to_string(self):
48 iface = self.value['_pInterface']
49 if iface:
50 try:
51 return '%s to (%s) %s' % (self.typename, str(iface.dynamic_type), str(iface))
52 except:
53 # fallback for potential problem:
54 # base class 'com::sun::star::uno::XInterface' is ambiguous
55 return '%s to (XInterface) %s' % (self.typename, str(iface))
57 else:
58 return "empty %s" % self.typename
60 class UnoSequencePrinter(object):
61 '''Prints UNO Sequence'''
63 class iterator(six.Iterator):
64 '''Sequence iterator'''
66 def __init__(self, first, size):
67 self.item = first
68 self.size = size
69 self.count = 0
71 def __iter__(self):
72 return self
74 def __next__(self):
75 if self.count == self.size:
76 raise StopIteration
77 count = self.count
78 self.count = self.count + 1
79 elem = self.item.dereference()
80 self.item = self.item + 1
81 return ('[%d]' % count, elem)
84 def __init__(self, typename, value):
85 self.value = value
86 self.typename = typename.replace('com::sun::star::', '')
88 def to_string(self):
89 pimpl = self.value['_pSequence']
90 if pimpl:
91 impl = pimpl.dereference()
92 elems = impl['nElements']
93 if elems == 0:
94 return "empty %s" % self.typename
95 else:
96 return "%s of length %d" % (self.typename, elems)
97 else:
98 return "uninitialized %s" % self.typename
100 def children(self):
101 pimpl = self.value['_pSequence']
102 if pimpl:
103 impl = pimpl.dereference()
104 elemtype = self.value.type.template_argument(0)
105 elements = impl['elements'].cast(elemtype.pointer())
106 return self.iterator(elements, int(impl['nElements']))
107 else:
108 # TODO is that the best thing to do here?
109 return None
111 def display_hint(self):
112 if self.value['_pSequence']:
113 return 'array'
114 else:
115 return None
117 class UnoTypePrinter(object):
118 '''Prints UNO Type'''
120 def __init__(self, typename, value):
121 self.value = value
122 self.typename = typename.replace('com::sun::star::', '')
124 def to_string(self):
125 uno = make_uno_type(self.value)
126 if uno:
127 return "%s %s" % (self.typename, uno.tag)
128 # return "%s %s" % (self.typename, uno.typename)
129 else:
130 return "invalid %s" % self.typename
132 class CppuThreadpoolThreadPoolPrinter(object):
133 '''Prints cppu_threadpool::ThreadPool objects (a hack to avoid infinite recursion through sal.RtlReferencePrinter when printing an rtl::Reference<cppu_threadpool::ThreadPool> whose std::list<cppu_threadpool::WaitingThread*> m_lstThreads member, via rtl::Reference<cppu_threadpool::ORequestThread> thread member, via rtl::Reference<cppu_threadpool::ThreadPool> m_aThreadPool member, has a circular reference back)'''
135 def __init__(self, typename, value):
136 self.typename = typename
137 self.value = value
139 def to_string(self):
140 return '%s@%s' % (self.typename, self.value.address)
142 printer = None
144 def build_pretty_printers():
145 global printer
147 printer = printing.Printer("libreoffice/cppu")
149 # basic UNO stuff
150 printer.add('_uno_Any', UnoAnyPrinter)
151 printer.add('com::sun::star::uno::Any', UnoAnyPrinter)
152 printer.add('com::sun::star::uno::Reference', UnoReferencePrinter)
153 printer.add('com::sun::star::uno::Sequence', UnoSequencePrinter)
154 printer.add('com::sun::star::uno::Type', UnoTypePrinter)
155 printer.add('cppu_threadpool::ThreadPool', CppuThreadpoolThreadPoolPrinter)
157 def register_pretty_printers(obj):
158 printing.register_pretty_printer(printer, obj)
160 build_pretty_printers()
162 # vim:set shiftwidth=4 softtabstop=4 expandtab: