bump product version to 5.0.4.1
[LibreOffice.git] / solenv / gdb / libreoffice / sw.py
blob19c1a75cda45563580f008bfe9793beb084f763e
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
11 from libreoffice.util import printing
13 class SwPositionPrinter(object):
14 '''Prints SwPosition.'''
16 def __init__(self, typename, value):
17 self.typename = typename
18 self.value = value
20 def to_string(self):
21 node = self.value['nNode']['pNd'].dereference();
22 block = node['pBlock'].dereference();
23 nodeindex = block['nStart'] + node['nOffset']
24 offset = self.value['nContent']['m_nIndex']
25 return "%s (node %d, offset %d)" % (self.typename, nodeindex, offset)
27 class SwNodeIndexPrinter(object):
28 '''Prints SwNodeIndex.'''
30 def __init__(self, typename, value):
31 self.typename = typename
32 self.value = value
34 def to_string(self):
35 node = self.value['pNd'].dereference();
36 block = node['pBlock'].dereference();
37 nodeindex = block['nStart'] + node['nOffset']
38 return "%s (node %d)" % (self.typename, nodeindex)
40 class SwIndexPrinter(object):
41 '''Prints SwIndex.'''
43 def __init__(self, typename, value):
44 self.typename = typename
45 self.value = value
47 def to_string(self):
48 offset = self.value['m_nIndex']
49 return "%s (offset %d)" % (self.typename, offset)
51 class SwPaMPrinter(object):
52 '''Prints SwPaM.'''
54 def __init__(self, typename, value):
55 self.typename = typename
56 self.value = value
58 def to_string(self):
59 return "%s" % (self.typename)
61 def children(self):
62 next_ = self.value['pNext']
63 prev = self.value['pPrev']
64 point = self.value['m_pPoint'].dereference()
65 mark = self.value['m_pMark'].dereference()
66 children = [ ( 'point', point), ( 'mark', mark ) ]
67 if next_ != self.value.address:
68 children.append(("next", next_))
69 if prev != self.value.address:
70 children.append(("prev", prev))
71 return children.__iter__()
73 class SwUnoCrsrPrinter(SwPaMPrinter):
74 '''Prints SwUnoCrsr.'''
76 class SwRectPrinter(object):
77 '''Prints SwRect.'''
79 def __init__(self, typename, value):
80 self.typename = typename
81 self.value = value
83 def to_string(self):
84 return "%s" % (self.typename)
86 def children(self):
87 point = self.value['m_Point']
88 size = self.value['m_Size']
89 children = [ ( 'point', point), ( 'size', size ) ]
90 return children.__iter__()
92 class SwUnoMarkPrinter(object):
93 '''Prints sw::mark::UnoMark.'''
95 def __init__(self, typename, value):
96 self.typename = typename
97 self.value = value
99 def to_string(self):
100 return "%s" % (self.typename)
102 def children(self):
103 unoMark = self.value.cast(self.value.dynamic_type)
104 pos1 = unoMark['m_pPos1']
105 pos2 = unoMark['m_pPos2']
106 children = [ ( 'pos1', pos1), ( 'pos2', pos2 ) ]
107 return children.__iter__()
109 class SwXTextRangeImplPrinter(object):
110 '''Prints SwXTextRange::Impl.'''
112 def __init__(self, typename, value):
113 self.typename = typename
114 self.value = value
116 def to_string(self):
117 return "%s" % (self.typename)
119 def children(self):
120 mark = self.value['m_pMark'].dereference()
121 children = [('mark', mark)]
122 return children.__iter__()
124 class SwXTextCursorImplPrinter(object):
125 '''Prints SwXTextCursor::Impl.'''
127 def __init__(self, typename, value):
128 self.typename = typename
129 self.value = value
131 def to_string(self):
132 return "%s" % (self.typename)
134 def children(self):
135 registeredIn = self.value['pRegisteredIn'].dereference()
136 children = [('registeredIn', registeredIn)]
137 return children.__iter__()
139 class SwUnoImplPtrPrinter(object):
140 """Prints sw::UnoImplPtr"""
142 def __init__(self, typename, value):
143 self.typename = typename
144 self.value = value
146 def to_string(self):
147 if self.value['m_p']:
148 return "%s %s" % (self.typename, self.value['m_p'].dereference())
149 else:
150 return "empty %s" % (self.typename,)
152 class SwXTextRangePrinter(object):
153 '''Prints SwXTextRange.'''
155 def __init__(self, typename, value):
156 self.typename = typename
157 self.value = value
159 def to_string(self):
160 return "%s %s" % (self.typename, self.value['m_pImpl'])
162 class SwXTextCursorPrinter(object):
163 '''Prints SwXTextCursor.'''
165 def __init__(self, typename, value):
166 self.typename = typename
167 self.value = value
169 def to_string(self):
170 return "%s %s" % (self.typename, self.value['m_pImpl'])
172 class BigPtrArrayPrinter(object):
173 '''Prints BigPtrArray.'''
175 def __init__(self, typename, value):
176 self.typename = typename
177 self.value = value
179 def to_string(self):
180 length = self.value['nSize']
181 if length > 0:
182 return "%s of length %d" % (self.typename, length)
183 else:
184 return "empty %s" % self.typename
186 def children(self):
187 return self._iterator(self.value)
189 def display_hint(self):
190 return 'array'
193 class _iterator(six.Iterator):
195 def __init__(self, array):
196 self.blocks = array['ppInf']
197 self.count = array['nSize']
198 self.pos = 0
199 self.block_count = array['nBlock']
200 self.block_pos = 0
201 self.block = None
202 self.indent = ""
203 self.max_indent = " "
204 self._next_block(False)
205 self._check_invariant()
207 def __iter__(self):
208 return self
210 def _node_value(self, node):
211 cur_indent = self.indent
212 if str(node.dynamic_type.target()) == "SwTextNode":
213 # accessing this is completely non-obvious...
214 # also, node.dynamic_cast(node.dynamic_type) is null?
215 value = " TextNode " + \
216 six.text_type(node.cast(node.dynamic_type).dereference()['m_Text'])
217 elif str(node.dynamic_type.target()) == "SwOLENode":
218 value = " OLENode "
219 elif str(node.dynamic_type.target()) == "SwGrfNode":
220 value = " GrfNode "
221 elif str(node.dynamic_type.target()) == "SwSectionNode":
222 value = " SectionNode "
223 self.indent += " "
224 elif str(node.dynamic_type.target()) == "SwTableNode":
225 value = " TableNode "
226 self.indent += " "
227 elif str(node.dynamic_type.target()) == "SwStartNode":
228 value = " StartNode "
229 self.indent += " "
230 elif str(node.dynamic_type.target()) == "SwEndNode":
231 value = " EndNode "
232 self.indent = self.indent[:-1]
233 cur_indent = self.indent
234 elif str(node.dynamic_type.target()) == "SwDummySectionNode":
235 value = "DummySctNode "
236 else: # must be currently being deleted, so has some abstract type
237 value = "~DeletedNode "
238 # return "\n[%s%4d%s] %s %s" % (cur_indent, self.pos, \
239 # self.max_indent[len(cur_indent):], node, value)
240 return "\n[%4d] %s%s%s %s" % (self.pos, cur_indent, \
241 node, self.max_indent[len(cur_indent):], value)
243 def __next__(self):
244 if self.pos == self.count:
245 raise StopIteration()
247 name = str(self.pos)
248 node = self.block['pData'][self.pos - self.block['nStart']]
249 value = self._node_value(node)
250 if self.pos == self.block['nEnd']:
251 self._next_block()
252 self.pos += 1
254 self._check_invariant()
255 return (name, value)
257 def _next_block(self, advance = True):
258 if advance:
259 self.block_pos += 1
261 if self.block_pos == self.block_count:
262 return
264 pblock = self.blocks[self.block_pos]
265 assert pblock
266 block = pblock.dereference()
267 start = block['nStart']
268 end = block['nEnd']
269 assert end - start + 1 == block['nElem']
270 if self.block:
271 assert start == self.block['nEnd'] + 1
272 assert end <= self.count
273 else:
274 assert start == 0
275 self.block = block
277 def _check_invariant(self):
278 assert self.pos <= self.count
279 assert self.block_pos <= self.block_count
280 if self.pos == 0 and self.pos < self.count:
281 assert self.block != None
283 printer = None
285 def build_pretty_printers():
286 global printer
288 printer = printing.Printer("libreoffice/sw")
289 printer.add('BigPtrArray', BigPtrArrayPrinter)
290 printer.add('SwPosition', SwPositionPrinter)
291 printer.add('SwNodeIndex', SwNodeIndexPrinter)
292 printer.add('SwIndex', SwIndexPrinter)
293 printer.add('SwPaM', SwPaMPrinter)
294 printer.add('SwUnoCrsr', SwUnoCrsrPrinter)
295 printer.add('SwRect', SwRectPrinter)
296 printer.add('sw::mark::UnoMark', SwUnoMarkPrinter)
297 printer.add('SwXTextRange::Impl', SwXTextRangeImplPrinter)
298 printer.add('sw::UnoImplPtr', SwUnoImplPtrPrinter)
299 printer.add('SwXTextRange', SwXTextRangePrinter)
300 printer.add('SwXTextCursor::Impl', SwXTextCursorImplPrinter)
301 printer.add('SwXTextCursor', SwXTextCursorPrinter)
303 def register_pretty_printers(obj):
304 printing.register_pretty_printer(printer, obj)
306 build_pretty_printers()
308 # vim:set shiftwidth=4 softtabstop=4 expandtab: