-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathtypeinfo.py
375 lines (352 loc) · 9.85 KB
/
typeinfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#############################################################################
##
## Copyright (C) 2014 Alex Merry <[email protected]>
## Contact: http://www.qt-project.org/legal
##
## This file is part of the GDB pretty printers for the Qt Toolkit.
##
## $QT_BEGIN_LICENSE:LGPL$
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and Digia. For licensing terms and
## conditions see http://qt.digia.com/licensing. For further information
## use the contact form at http://qt.digia.com/contact-us.
##
## GNU Lesser General Public License Usage
## Alternatively, this file may be used under the terms of the GNU Lesser
## General Public License version 2.1 as published by the Free Software
## Foundation and appearing in the file LICENSE.LGPL included in the
## packaging of this file. Please review the following information to
## ensure the GNU Lesser General Public License version 2.1 requirements
## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
##
## In addition, as a special exception, Digia gives you certain additional
## rights. These rights are described in the Digia Qt LGPL Exception
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
##
## GNU General Public License Usage
## Alternatively, this file may be used under the terms of the GNU
## General Public License version 3.0 as published by the Free Software
## Foundation and appearing in the file LICENSE.GPL included in the
## packaging of this file. Please review the following information to
## ensure the GNU General Public License version 3.0 requirements will be
## met: http://www.gnu.org/copyleft/gpl.html.
##
##
## $QT_END_LICENSE$
##
#############################################################################
import gdb.printing
"""Qt5 Type Information
Since the QTypeInfo information is not necessarily available at debug time, this
module contains useful type information about standard and Qt types (such as
whether a type is movable) that is necessary for the operation of the printers.
This information allows the QList printer, for example, to determine how the
elements are stored in the list.
"""
primitive_types = set([
'HB_FixedPoint',
'HB_GlyphAttributes',
'QCharAttributes',
'QFlag',
'QIncompatibleFlag',
'QRegExpAnchorAlternation',
'QRegExpAtom',
'QRegExpCharClassRange',
'QStaticPlugin',
'QStringRef',
'QTzType',
'QUuid'
])
"""Primitive (non-template) types.
This does not need to include compiler-primitive types (like int).
If you use the Q_DECLARE_TYPEINFO macro with Q_PRIMITIVE_TYPE flag, you
should add the type to this set. This is particularly important for
types that are the same size as a pointer or smaller.
"""
primitive_tpl_types = set(['QFlags'])
"""Primitive template types.
If you use the Q_DECLARE_TYPEINFO_BODY macro with Q_PRIMITIVE_TYPE flag
on a type with template parameters, you should add the type to this
set. This is particularly important for types that are the same size as
a pointer or smaller.
Entries should just be the base typename, without any template
parameters (eg: "QFlags", rather than "QFlags<T>").
"""
movable_types = set([
'QBasicTimer',
'QBitArray',
'QByteArray',
'QChar',
'QCharRef',
'QCustomTypeInfo',
'QDate',
'QDateTime',
'QFileInfo',
'QEasingCurve',
'QFileSystemWatcherPathKey',
'QHashDummyValue',
'QItemSelectionRange',
'QLatin1String',
'QLine',
'QLineF',
'QLocale',
'QLoggingRule',
'QMargins',
'QMarginsF',
'QMetaClassInfo',
'QMetaEnum',
'QMetaMethod',
'QMimeMagicRule',
'QModelIndex',
'QPersistentModelIndex',
'QObjectPrivate::Connection',
'QObjectPrivate::Sender',
'QPoint',
'QPointF',
'QPostEvent',
'QProcEnvKey',
'QProcEnvValue',
'QRect',
'QRectF',
'QRegExp',
'QRegExpAutomatonState',
'QRegExpCharClass',
'QResourceRoot',
'QSize',
'QSizeF',
'QString',
'QStringList',
'QTime',
'QTimeZone::OffsetData',
'QUrl',
'QVariant',
'QXmlStreamAttribute',
'QXmlStreamEntityDeclaration',
'QXmlStreamNamespaceDeclaration',
'QXmlStreamNotationDeclaration'
])
"""Movable (non-template) types.
If you use the Q_DECLARE_TYPEINFO macro with Q_MOVABLE_TYPE flag, you
should add the type to this set. This is particularly important for
types that are the same size as a pointer or smaller.
"""
movable_tpl_types = set([
'QExplicitlySharedDataPointer',
'QLinkedList',
'QList',
'QPointer',
'QQueue',
'QSet',
'QSharedDataPointer',
'QSharedPointer',
'QStack',
'QVector',
'QWeakPointer'
])
"""Movable template types.
If you use the Q_DECLARE_TYPEINFO_BODY macro with Q_MOVABLE_TYPE flag
on a type with template parameters, you should add the type to this
set. This is particularly important for types that are the same size as
a pointer or smaller.
Entries should just be the base typename, without any template
parameters (eg: "QFlags", rather than "QFlags<T>").
"""
static_types = set()
"""Static (non-template) types.
If you define a custom type that is neither primitive nor movable, you
can add the type to this set to indicate this. This is particularly
important for types that are the same size as a pointer or smaller.
"""
static_tpl_types = set()
"""Static template types.
If you define a custom type with template parameters that is neither
primitive nor movable, you can add the type to this set to indicate
this. This is particularly important for types that are the same size as
a pointer or smaller.
Entries should just be the base typename, without any template
parameters (eg: "QFlags", rather than "QFlags<T>").
"""
def type_is_known_primitive(typ):
"""Returns True if the given gdb type is known to be primitive."""
if typ.code == gdb.TYPE_CODE_PTR or typ.code == gdb.TYPE_CODE_INT or typ.code == gdb.TYPE_CODE_FLT or typ.code == gdb.TYPE_CODE_CHAR or typ.code == gdb.TYPE_CODE_BOOL:
return True
pos = typ.name.find('<')
if pos > 0:
return typ.name[0:pos] in primitive_tpl_types
else:
return typ.name in primitive_types
def type_is_known_movable(typ):
"""Returns True if the given gdb type is known to be movable."""
if not typ.name:
return False
pos = typ.name.find('<')
if pos > 0:
return typ.name[0:pos] in movable_tpl_types
else:
return typ.name in movable_types
def type_is_known_static(typ):
"""Returns True if the given gdb type is known to be neither primitive nor movable."""
if not typ.name:
return False
pos = typ.name.find('<')
if pos > 0:
return typ.name[0:pos] in static_tpl_types
else:
return typ.name in static_types
meta_type_unknown = 0
"""The unknown/invalid meta type ID."""
meta_type_user = 1024
"""The starting value for custom type IDs."""
meta_type_ids = {
'bool': 1,
'int': 2,
'uint': 3,
'qlonglong': 4,
'qulonglong': 5,
'double': 6,
'QChar': 7,
'QVariantMap': 8,
'QVariantList': 9,
'QString': 10,
'QStringList': 11,
'QByteArray': 12,
'QBitArray': 13,
'QDate': 14,
'QTime': 15,
'QDateTime': 16,
'QUrl': 17,
'QLocale': 18,
'QRect': 19,
'QRectF': 20,
'QSize': 21,
'QSizeF': 22,
'QLine': 23,
'QLineF': 24,
'QPoint': 25,
'QPointF': 26,
'QRegExp': 27,
'QVariantHash': 28,
'QEasingCurve': 29,
'QUuid': 30,
'void*': 31,
'long': 32,
'short': 33,
'char': 34,
'ulong': 35,
'ushort': 36,
'uchar': 37,
'float': 38,
'QObject*': 39,
'signed char': 40,
'QVariant': 41,
'QModelIndex': 42,
'void': 43,
'QRegularExpression': 44,
'QJsonValue': 45,
'QJsonObject': 46,
'QJsonArray': 47,
'QJsonDocument': 48,
'QFont': 64,
'QPixmap': 65,
'QBrush': 66,
'QColor': 67,
'QPalette': 68,
'QIcon': 69,
'QImage': 70,
'QPolygon': 71,
'QRegion': 72,
'QBitmap': 73,
'QCursor': 74,
'QKeySequence': 75,
'QPen': 76,
'QTextLength': 77,
'QTextFormat': 78,
'QMatrix': 79,
'QTransform': 80,
'QMatrix4x4': 81,
'QVector2D': 82,
'QVector3D': 83,
'QVector4D': 84,
'QQuaternion': 85,
'QPolygonF': 86,
'QSizePolicy': 121
}
"""Map from type names to meta type IDs."""
meta_type_names = {
1: 'bool',
2: 'int',
3: 'uint',
4: 'qlonglong',
5: 'qulonglong',
6: 'double',
7: 'QChar',
8: 'QVariantMap',
9: 'QVariantList',
10: 'QString',
11: 'QStringList',
12: 'QByteArray',
13: 'QBitArray',
14: 'QDate',
15: 'QTime',
16: 'QDateTime',
17: 'QUrl',
18: 'QLocale',
19: 'QRect',
20: 'QRectF',
21: 'QSize',
22: 'QSizeF',
23: 'QLine',
24: 'QLineF',
25: 'QPoint',
26: 'QPointF',
27: 'QRegExp',
28: 'QVariantHash',
29: 'QEasingCurve',
30: 'QUuid',
31: 'void*',
32: 'long',
33: 'short',
34: 'char',
35: 'ulong',
36: 'ushort',
37: 'uchar',
38: 'float',
39: 'QObject*',
40: 'signed char',
41: 'QVariant',
42: 'QModelIndex',
43: 'void',
44: 'QRegularExpression',
45: 'QJsonValue',
46: 'QJsonObject',
47: 'QJsonArray',
48: 'QJsonDocument',
64: 'QFont',
65: 'QPixmap',
66: 'QBrush',
67: 'QColor',
68: 'QPalette',
69: 'QIcon',
70: 'QImage',
71: 'QPolygon',
72: 'QRegion',
73: 'QBitmap',
74: 'QCursor',
75: 'QKeySequence',
76: 'QPen',
77: 'QTextLength',
78: 'QTextFormat',
79: 'QMatrix',
80: 'QTransform',
81: 'QMatrix4x4',
82: 'QVector2D',
83: 'QVector3D',
84: 'QVector4D',
85: 'QQuaternion',
86: 'QPolygonF',
121: 'QSizePolicy'
}
"""Map from meta type IDs to type names."""