Bump version to 6.4.7.2.M8
[LibreOffice.git] / solenv / gdb / libreoffice / sw.py
blobe170709fb79c566851858816490901f0823ee2ce
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']['m_pNode'].dereference();
22 block = node['m_pBlock'].dereference();
23 nodeindex = block['nStart'] + node['m_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['m_pNode'].dereference();
36 block = node['m_pBlock'].dereference();
37 nodeindex = block['nStart'] + node['m_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['m_pNext']
63 prev = self.value['m_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 # apparently the purpose of this is to suppress printing all the extra members
74 # that SwCursor and SwUnoCursor add
75 class SwUnoCursorPrinter(SwPaMPrinter):
76 '''Prints SwUnoCursor.'''
78 class SwRectPrinter(object):
79 '''Prints SwRect.'''
81 def __init__(self, typename, value):
82 self.typename = typename
83 self.value = value
85 def to_string(self):
86 return "%s" % (self.typename)
88 def children(self):
89 point = self.value['m_Point']
90 size = self.value['m_Size']
91 children = [ ( 'point', point), ( 'size', size ) ]
92 return children.__iter__()
94 class MarkBasePrinter(object):
95 '''Prints sw::mark::MarkBase.'''
97 def __init__(self, typename, value):
98 self.typename = typename
99 self.value = value
101 def to_string(self):
102 return "%s" % (self.typename)
104 def children(self):
105 m = self.value.cast(self.value.dynamic_type)
106 return [ ( v, m[ v ] )
107 for v in ( 'm_aName', 'm_pPos1', 'm_pPos2' ) ].__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 cursor = self.value['m_pUnoCursor']["m_pCursor"]["_M_ptr"]
136 registeredIn = cursor.dereference()
137 children = [('m_pUnoCursor', registeredIn)]
138 return children.__iter__()
140 class SwUnoImplPtrPrinter(object):
141 """Prints sw::UnoImplPtr"""
143 def __init__(self, typename, value):
144 self.typename = typename
145 self.value = value
147 def to_string(self):
148 if self.value['m_p']:
149 return "%s %s" % (self.typename, self.value['m_p'].dereference())
150 else:
151 return "empty %s" % (self.typename,)
153 class SwXTextRangePrinter(object):
154 '''Prints SwXTextRange.'''
156 def __init__(self, typename, value):
157 self.typename = typename
158 self.value = value
160 def to_string(self):
161 return "%s %s" % (self.typename, self.value['m_pImpl'])
163 class SwXTextCursorPrinter(object):
164 '''Prints SwXTextCursor.'''
166 def __init__(self, typename, value):
167 self.typename = typename
168 self.value = value
170 def to_string(self):
171 return "%s %s" % (self.typename, self.value['m_pImpl'])
173 class BigPtrArrayPrinter(object):
174 '''Prints BigPtrArray.'''
176 def __init__(self, typename, value):
177 self.typename = typename
178 self.value = value
180 def to_string(self):
181 length = self.value['m_nSize']
182 if length > 0:
183 return "%s of length %d" % (self.typename, length)
184 else:
185 return "empty %s" % self.typename
187 def children(self):
188 return self._iterator(self.value)
190 def display_hint(self):
191 return 'array'
194 class _iterator(six.Iterator):
196 def __init__(self, array):
197 self.blocks = array['m_ppInf']['_M_t']['_M_t']['_M_head_impl']
198 self.count = array['m_nSize']
199 self.pos = 0
200 self.block_count = array['m_nBlock']
201 self.block_pos = 0
202 self.block = None
203 self.indent = ""
204 self.max_indent = " "
205 self._next_block(False)
206 self._check_invariant()
208 def __iter__(self):
209 return self
211 def _node_value(self, node):
212 cur_indent = self.indent
213 if str(node.dynamic_type.target()) == "SwTextNode":
214 # accessing this is completely non-obvious...
215 # also, node.dynamic_cast(node.dynamic_type) is null?
216 value = " TextNode " + \
217 six.text_type(node.cast(node.dynamic_type).dereference()['m_Text'])
218 elif str(node.dynamic_type.target()) == "SwOLENode":
219 value = " OLENode "
220 elif str(node.dynamic_type.target()) == "SwGrfNode":
221 value = " GrfNode "
222 elif str(node.dynamic_type.target()) == "SwSectionNode":
223 value = " SectionNode "
224 self.indent += " "
225 elif str(node.dynamic_type.target()) == "SwTableNode":
226 value = " TableNode "
227 self.indent += " "
228 elif str(node.dynamic_type.target()) == "SwStartNode":
229 value = " StartNode "
230 self.indent += " "
231 elif str(node.dynamic_type.target()) == "SwEndNode":
232 value = " EndNode "
233 self.indent = self.indent[:-1]
234 cur_indent = self.indent
235 elif str(node.dynamic_type.target()) == "SwDummySectionNode":
236 value = "DummySctNode "
237 else: # must be currently being deleted, so has some abstract type
238 value = "~DeletedNode "
239 # return "\n[%s%4d%s] %s %s" % (cur_indent, self.pos, \
240 # self.max_indent[len(cur_indent):], node, value)
241 return "\n[%4d] %s%s%s %s" % (self.pos, cur_indent, \
242 node, self.max_indent[len(cur_indent):], value)
244 def __next__(self):
245 if self.pos == self.count:
246 raise StopIteration()
248 name = str(self.pos)
249 node = self.block['mvData']['_M_elems'][self.pos - self.block['nStart']]
250 value = self._node_value(node)
251 if self.pos == self.block['nEnd']:
252 self._next_block()
253 self.pos += 1
255 self._check_invariant()
256 return (name, value)
258 def _next_block(self, advance = True):
259 if advance:
260 self.block_pos += 1
262 if self.block_pos == self.block_count:
263 return
265 pblock = self.blocks[self.block_pos]
266 assert pblock
267 block = pblock.dereference()
268 start = block['nStart']
269 end = block['nEnd']
270 assert end - start + 1 == block['nElem']
271 if self.block:
272 assert start == self.block['nEnd'] + 1
273 assert end <= self.count
274 else:
275 assert start == 0
276 self.block = block
278 def _check_invariant(self):
279 assert self.pos <= self.count
280 assert self.block_pos <= self.block_count
281 if self.pos == 0 and self.pos < self.count:
282 assert self.block != None
284 printer = None
286 def build_pretty_printers():
287 global printer
289 printer = printing.Printer("libreoffice/sw")
290 printer.add('BigPtrArray', BigPtrArrayPrinter)
291 printer.add('SwPosition', SwPositionPrinter)
292 printer.add('SwNodeIndex', SwNodeIndexPrinter)
293 printer.add('SwIndex', SwIndexPrinter)
294 printer.add('SwPaM', SwPaMPrinter)
295 printer.add('SwUnoCursor', SwUnoCursorPrinter)
296 printer.add('SwRect', SwRectPrinter)
297 printer.add('sw::mark::Bookmark', MarkBasePrinter)
298 printer.add('sw::mark::MarkBase', MarkBasePrinter)
299 printer.add('sw::mark::UnoMark', MarkBasePrinter)
300 printer.add('sw::mark::IMark', MarkBasePrinter)
301 printer.add('SwXTextRange::Impl', SwXTextRangeImplPrinter)
302 printer.add('sw::UnoImplPtr', SwUnoImplPtrPrinter)
303 printer.add('SwXTextRange', SwXTextRangePrinter)
304 printer.add('SwXTextCursor::Impl', SwXTextCursorImplPrinter)
305 printer.add('SwXTextCursor', SwXTextCursorPrinter)
307 def register_pretty_printers(obj):
308 printing.register_pretty_printer(printer, obj)
310 build_pretty_printers()
312 # vim:set shiftwidth=4 softtabstop=4 expandtab: