1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com>
5** Copyright (C) 2018 Intel Corporation.
6** Contact: https://www.qt.io/licensing/
7**
8** This file is part of the tools applications of the Qt Toolkit.
9**
10** $QT_BEGIN_LICENSE:GPL-EXCEPT$
11** Commercial License Usage
12** Licensees holding valid commercial Qt licenses may use this file in
13** accordance with the commercial license agreement provided with the
14** Software or, alternatively, in accordance with the terms contained in
15** a written agreement between you and The Qt Company. For licensing terms
16** and conditions see https://www.qt.io/terms-conditions. For further
17** information use the contact form at https://www.qt.io/contact-us.
18**
19** GNU General Public License Usage
20** Alternatively, this file may be used under the terms of the GNU
21** General Public License version 3 as published by the Free Software
22** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
23** included in the packaging of this file. Please review the following
24** information to ensure the GNU General Public License requirements will
25** be met: https://www.gnu.org/licenses/gpl-3.0.html.
26**
27** $QT_END_LICENSE$
28**
29****************************************************************************/
30
31#include "generator.h"
32#include "cbordevice.h"
33#include "outputrevision.h"
34#include "utils.h"
35#include <QtCore/qmetatype.h>
36#include <QtCore/qjsondocument.h>
37#include <QtCore/qjsonobject.h>
38#include <QtCore/qjsonvalue.h>
39#include <QtCore/qjsonarray.h>
40#include <QtCore/qplugin.h>
41#include <QtCore/qstringview.h>
42
43#include <math.h>
44#include <stdio.h>
45
46#include <private/qmetaobject_p.h> //for the flags.
47#include <private/qplugin_p.h> //for the flags.
48
49QT_BEGIN_NAMESPACE
50
51uint nameToBuiltinType(const QByteArray &name)
52{
53 if (name.isEmpty())
54 return 0;
55
56 uint tp = QMetaType::type(typeName: name.constData());
57 return tp < uint(QMetaType::User) ? tp : uint(QMetaType::UnknownType);
58}
59
60/*
61 Returns \c true if the type is a built-in type.
62*/
63bool isBuiltinType(const QByteArray &type)
64 {
65 int id = QMetaType::type(typeName: type.constData());
66 if (id == QMetaType::UnknownType)
67 return false;
68 return (id < QMetaType::User);
69}
70
71static const char *metaTypeEnumValueString(int type)
72 {
73#define RETURN_METATYPENAME_STRING(MetaTypeName, MetaTypeId, RealType) \
74 case QMetaType::MetaTypeName: return #MetaTypeName;
75
76 switch (type) {
77QT_FOR_EACH_STATIC_TYPE(RETURN_METATYPENAME_STRING)
78 }
79#undef RETURN_METATYPENAME_STRING
80 return nullptr;
81 }
82
83Generator::Generator(ClassDef *classDef, const QVector<QByteArray> &metaTypes, const QHash<QByteArray, QByteArray> &knownQObjectClasses, const QHash<QByteArray, QByteArray> &knownGadgets, FILE *outfile)
84 : out(outfile), cdef(classDef), metaTypes(metaTypes), knownQObjectClasses(knownQObjectClasses)
85 , knownGadgets(knownGadgets)
86{
87 if (cdef->superclassList.size())
88 purestSuperClass = cdef->superclassList.constFirst().first;
89}
90
91static inline int lengthOfEscapeSequence(const QByteArray &s, int i)
92{
93 if (s.at(i) != '\\' || i >= s.length() - 1)
94 return 1;
95 const int startPos = i;
96 ++i;
97 char ch = s.at(i);
98 if (ch == 'x') {
99 ++i;
100 while (i < s.length() && is_hex_char(s: s.at(i)))
101 ++i;
102 } else if (is_octal_char(s: ch)) {
103 while (i < startPos + 4
104 && i < s.length()
105 && is_octal_char(s: s.at(i))) {
106 ++i;
107 }
108 } else { // single character escape sequence
109 i = qMin(a: i + 1, b: s.length());
110 }
111 return i - startPos;
112}
113
114void Generator::strreg(const QByteArray &s)
115{
116 if (!strings.contains(t: s))
117 strings.append(t: s);
118}
119
120int Generator::stridx(const QByteArray &s)
121{
122 int i = strings.indexOf(t: s);
123 Q_ASSERT_X(i != -1, Q_FUNC_INFO, "We forgot to register some strings");
124 return i;
125}
126
127// Returns the sum of all parameters (including return type) for the given
128// \a list of methods. This is needed for calculating the size of the methods'
129// parameter type/name meta-data.
130static int aggregateParameterCount(const QVector<FunctionDef> &list)
131{
132 int sum = 0;
133 for (int i = 0; i < list.count(); ++i)
134 sum += list.at(i).arguments.count() + 1; // +1 for return type
135 return sum;
136}
137
138bool Generator::registerableMetaType(const QByteArray &propertyType)
139{
140 if (metaTypes.contains(t: propertyType))
141 return true;
142
143 if (propertyType.endsWith(c: '*')) {
144 QByteArray objectPointerType = propertyType;
145 // The objects container stores class names, such as 'QState', 'QLabel' etc,
146 // not 'QState*', 'QLabel*'. The propertyType does contain the '*', so we need
147 // to chop it to find the class type in the known QObjects list.
148 objectPointerType.chop(n: 1);
149 if (knownQObjectClasses.contains(akey: objectPointerType))
150 return true;
151 }
152
153 static const QVector<QByteArray> smartPointers = QVector<QByteArray>()
154#define STREAM_SMART_POINTER(SMART_POINTER) << #SMART_POINTER
155 QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(STREAM_SMART_POINTER)
156#undef STREAM_SMART_POINTER
157 ;
158
159 for (const QByteArray &smartPointer : smartPointers) {
160 if (propertyType.startsWith(a: smartPointer + "<") && !propertyType.endsWith(c: "&"))
161 return knownQObjectClasses.contains(akey: propertyType.mid(index: smartPointer.size() + 1, len: propertyType.size() - smartPointer.size() - 1 - 1));
162 }
163
164 static const QVector<QByteArray> oneArgTemplates = QVector<QByteArray>()
165#define STREAM_1ARG_TEMPLATE(TEMPLATENAME) << #TEMPLATENAME
166 QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(STREAM_1ARG_TEMPLATE)
167#undef STREAM_1ARG_TEMPLATE
168 ;
169 for (const QByteArray &oneArgTemplateType : oneArgTemplates) {
170 if (propertyType.startsWith(a: oneArgTemplateType + "<") && propertyType.endsWith(c: ">")) {
171 const int argumentSize = propertyType.size() - oneArgTemplateType.size() - 1
172 // The closing '>'
173 - 1
174 // templates inside templates have an extra whitespace char to strip.
175 - (propertyType.at(i: propertyType.size() - 2) == ' ' ? 1 : 0 );
176 const QByteArray templateArg = propertyType.mid(index: oneArgTemplateType.size() + 1, len: argumentSize);
177 return isBuiltinType(type: templateArg) || registerableMetaType(propertyType: templateArg);
178 }
179 }
180 return false;
181}
182
183/* returns \c true if name and qualifiedName refers to the same name.
184 * If qualified name is "A::B::C", it returns \c true for "C", "B::C" or "A::B::C" */
185static bool qualifiedNameEquals(const QByteArray &qualifiedName, const QByteArray &name)
186{
187 if (qualifiedName == name)
188 return true;
189 int index = qualifiedName.indexOf(c: "::");
190 if (index == -1)
191 return false;
192 return qualifiedNameEquals(qualifiedName: qualifiedName.mid(index: index+2), name);
193}
194
195void Generator::generateCode()
196{
197 bool isQt = (cdef->classname == "Qt");
198 bool isQObject = (cdef->classname == "QObject");
199 bool isConstructible = !cdef->constructorList.isEmpty();
200
201 // filter out undeclared enumerators and sets
202 {
203 QVector<EnumDef> enumList;
204 for (int i = 0; i < cdef->enumList.count(); ++i) {
205 EnumDef def = cdef->enumList.at(i);
206 if (cdef->enumDeclarations.contains(akey: def.name)) {
207 enumList += def;
208 }
209 def.enumName = def.name;
210 QByteArray alias = cdef->flagAliases.value(akey: def.name);
211 if (cdef->enumDeclarations.contains(akey: alias)) {
212 def.name = alias;
213 enumList += def;
214 }
215 }
216 cdef->enumList = enumList;
217 }
218
219//
220// Register all strings used in data section
221//
222 strreg(s: cdef->qualified);
223 registerClassInfoStrings();
224 registerFunctionStrings(list: cdef->signalList);
225 registerFunctionStrings(list: cdef->slotList);
226 registerFunctionStrings(list: cdef->methodList);
227 registerFunctionStrings(list: cdef->constructorList);
228 registerByteArrayVector(list: cdef->nonClassSignalList);
229 registerPropertyStrings();
230 registerEnumStrings();
231
232 QByteArray qualifiedClassNameIdentifier = cdef->qualified;
233 qualifiedClassNameIdentifier.replace(before: ':', after: '_');
234
235//
236// Build stringdata struct
237//
238 const int constCharArraySizeLimit = 65535;
239 fprintf(stream: out, format: "struct qt_meta_stringdata_%s_t {\n", qualifiedClassNameIdentifier.constData());
240 fprintf(stream: out, format: " QByteArrayData data[%d];\n", strings.size());
241 {
242 int stringDataLength = 0;
243 int stringDataCounter = 0;
244 for (int i = 0; i < strings.size(); ++i) {
245 int thisLength = strings.at(i).length() + 1;
246 stringDataLength += thisLength;
247 if (stringDataLength / constCharArraySizeLimit) {
248 // save previous stringdata and start computing the next one.
249 fprintf(stream: out, format: " char stringdata%d[%d];\n", stringDataCounter++, stringDataLength - thisLength);
250 stringDataLength = thisLength;
251 }
252 }
253 fprintf(stream: out, format: " char stringdata%d[%d];\n", stringDataCounter, stringDataLength);
254
255 }
256 fprintf(stream: out, format: "};\n");
257
258 // Macro that expands into a QByteArrayData. The offset member is
259 // calculated from 1) the offset of the actual characters in the
260 // stringdata.stringdata member, and 2) the stringdata.data index of the
261 // QByteArrayData being defined. This calculation relies on the
262 // QByteArrayData::data() implementation returning simply "this + offset".
263 fprintf(stream: out, format: "#define QT_MOC_LITERAL(idx, ofs, len) \\\n"
264 " Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \\\n"
265 " qptrdiff(offsetof(qt_meta_stringdata_%s_t, stringdata0) + ofs \\\n"
266 " - idx * sizeof(QByteArrayData)) \\\n"
267 " )\n",
268 qualifiedClassNameIdentifier.constData());
269
270 fprintf(stream: out, format: "static const qt_meta_stringdata_%s_t qt_meta_stringdata_%s = {\n",
271 qualifiedClassNameIdentifier.constData(), qualifiedClassNameIdentifier.constData());
272 fprintf(stream: out, format: " {\n");
273 {
274 int idx = 0;
275 for (int i = 0; i < strings.size(); ++i) {
276 const QByteArray &str = strings.at(i);
277 fprintf(stream: out, format: "QT_MOC_LITERAL(%d, %d, %d)", i, idx, str.length());
278 if (i != strings.size() - 1)
279 fputc(c: ',', stream: out);
280 const QByteArray comment = str.length() > 32 ? str.left(len: 29) + "..." : str;
281 fprintf(stream: out, format: " // \"%s\"\n", comment.constData());
282 idx += str.length() + 1;
283 for (int j = 0; j < str.length(); ++j) {
284 if (str.at(i: j) == '\\') {
285 int cnt = lengthOfEscapeSequence(s: str, i: j) - 1;
286 idx -= cnt;
287 j += cnt;
288 }
289 }
290 }
291 fprintf(stream: out, format: "\n },\n");
292 }
293
294//
295// Build stringdata array
296//
297 fprintf(stream: out, format: " \"");
298 int col = 0;
299 int len = 0;
300 int stringDataLength = 0;
301 for (int i = 0; i < strings.size(); ++i) {
302 QByteArray s = strings.at(i);
303 len = s.length();
304 stringDataLength += len + 1;
305 if (stringDataLength >= constCharArraySizeLimit) {
306 fprintf(stream: out, format: "\",\n \"");
307 stringDataLength = len + 1;
308 col = 0;
309 } else if (i)
310 fputs(s: "\\0", stream: out); // add \0 at the end of each string
311
312 if (col && col + len >= 72) {
313 fprintf(stream: out, format: "\"\n \"");
314 col = 0;
315 } else if (len && s.at(i: 0) >= '0' && s.at(i: 0) <= '9') {
316 fprintf(stream: out, format: "\"\"");
317 len += 2;
318 }
319 int idx = 0;
320 while (idx < s.length()) {
321 if (idx > 0) {
322 col = 0;
323 fprintf(stream: out, format: "\"\n \"");
324 }
325 int spanLen = qMin(a: 70, b: s.length() - idx);
326 // don't cut escape sequences at the end of a line
327 int backSlashPos = s.lastIndexOf(c: '\\', from: idx + spanLen - 1);
328 if (backSlashPos >= idx) {
329 int escapeLen = lengthOfEscapeSequence(s, i: backSlashPos);
330 spanLen = qBound(min: spanLen, val: backSlashPos + escapeLen - idx, max: s.length() - idx);
331 }
332 fprintf(stream: out, format: "%.*s", spanLen, s.constData() + idx);
333 idx += spanLen;
334 col += spanLen;
335 }
336 col += len + 2;
337 }
338
339// Terminate stringdata struct
340 fprintf(stream: out, format: "\"\n};\n");
341 fprintf(stream: out, format: "#undef QT_MOC_LITERAL\n\n");
342
343//
344// build the data array
345//
346
347 int index = MetaObjectPrivateFieldCount;
348 fprintf(stream: out, format: "static const uint qt_meta_data_%s[] = {\n", qualifiedClassNameIdentifier.constData());
349 fprintf(stream: out, format: "\n // content:\n");
350 fprintf(stream: out, format: " %4d, // revision\n", int(QMetaObjectPrivate::OutputRevision));
351 fprintf(stream: out, format: " %4d, // classname\n", stridx(s: cdef->qualified));
352 fprintf(stream: out, format: " %4d, %4d, // classinfo\n", cdef->classInfoList.count(), cdef->classInfoList.count() ? index : 0);
353 index += cdef->classInfoList.count() * 2;
354
355 int methodCount = cdef->signalList.count() + cdef->slotList.count() + cdef->methodList.count();
356 fprintf(stream: out, format: " %4d, %4d, // methods\n", methodCount, methodCount ? index : 0);
357 index += methodCount * 5;
358 if (cdef->revisionedMethods)
359 index += methodCount;
360 int paramsIndex = index;
361 int totalParameterCount = aggregateParameterCount(list: cdef->signalList)
362 + aggregateParameterCount(list: cdef->slotList)
363 + aggregateParameterCount(list: cdef->methodList)
364 + aggregateParameterCount(list: cdef->constructorList);
365 index += totalParameterCount * 2 // types and parameter names
366 - methodCount // return "parameters" don't have names
367 - cdef->constructorList.count(); // "this" parameters don't have names
368
369 fprintf(stream: out, format: " %4d, %4d, // properties\n", cdef->propertyList.count(), cdef->propertyList.count() ? index : 0);
370 index += cdef->propertyList.count() * 3;
371 if(cdef->notifyableProperties)
372 index += cdef->propertyList.count();
373 if (cdef->revisionedProperties)
374 index += cdef->propertyList.count();
375 fprintf(stream: out, format: " %4d, %4d, // enums/sets\n", cdef->enumList.count(), cdef->enumList.count() ? index : 0);
376
377 int enumsIndex = index;
378 for (int i = 0; i < cdef->enumList.count(); ++i)
379 index += 5 + (cdef->enumList.at(i).values.count() * 2);
380 fprintf(stream: out, format: " %4d, %4d, // constructors\n", isConstructible ? cdef->constructorList.count() : 0,
381 isConstructible ? index : 0);
382
383 int flags = 0;
384 if (cdef->hasQGadget || cdef->hasQNamespace) {
385 // Ideally, all the classes could have that flag. But this broke classes generated
386 // by qdbusxml2cpp which generate code that require that we call qt_metacall for properties
387 flags |= PropertyAccessInStaticMetaCall;
388 }
389 fprintf(stream: out, format: " %4d, // flags\n", flags);
390 fprintf(stream: out, format: " %4d, // signalCount\n", cdef->signalList.count());
391
392
393//
394// Build classinfo array
395//
396 generateClassInfos();
397
398//
399// Build signals array first, otherwise the signal indices would be wrong
400//
401 generateFunctions(list: cdef->signalList, functype: "signal", type: MethodSignal, paramsIndex);
402
403//
404// Build slots array
405//
406 generateFunctions(list: cdef->slotList, functype: "slot", type: MethodSlot, paramsIndex);
407
408//
409// Build method array
410//
411 generateFunctions(list: cdef->methodList, functype: "method", type: MethodMethod, paramsIndex);
412
413//
414// Build method version arrays
415//
416 if (cdef->revisionedMethods) {
417 generateFunctionRevisions(list: cdef->signalList, functype: "signal");
418 generateFunctionRevisions(list: cdef->slotList, functype: "slot");
419 generateFunctionRevisions(list: cdef->methodList, functype: "method");
420 }
421
422//
423// Build method parameters array
424//
425 generateFunctionParameters(list: cdef->signalList, functype: "signal");
426 generateFunctionParameters(list: cdef->slotList, functype: "slot");
427 generateFunctionParameters(list: cdef->methodList, functype: "method");
428 if (isConstructible)
429 generateFunctionParameters(list: cdef->constructorList, functype: "constructor");
430
431//
432// Build property array
433//
434 generateProperties();
435
436//
437// Build enums array
438//
439 generateEnums(index: enumsIndex);
440
441//
442// Build constructors array
443//
444 if (isConstructible)
445 generateFunctions(list: cdef->constructorList, functype: "constructor", type: MethodConstructor, paramsIndex);
446
447//
448// Terminate data array
449//
450 fprintf(stream: out, format: "\n 0 // eod\n};\n\n");
451
452//
453// Generate internal qt_static_metacall() function
454//
455 const bool hasStaticMetaCall = !isQt &&
456 (cdef->hasQObject || !cdef->methodList.isEmpty()
457 || !cdef->propertyList.isEmpty() || !cdef->constructorList.isEmpty());
458 if (hasStaticMetaCall)
459 generateStaticMetacall();
460
461//
462// Build extra array
463//
464 QVector<QByteArray> extraList;
465 QMultiHash<QByteArray, QByteArray> knownExtraMetaObject = knownGadgets;
466 knownExtraMetaObject.unite(other: knownQObjectClasses);
467
468 for (int i = 0; i < cdef->propertyList.count(); ++i) {
469 const PropertyDef &p = cdef->propertyList.at(i);
470 if (isBuiltinType(type: p.type))
471 continue;
472
473 if (p.type.contains(c: '*') || p.type.contains(c: '<') || p.type.contains(c: '>'))
474 continue;
475
476 int s = p.type.lastIndexOf(c: "::");
477 if (s <= 0)
478 continue;
479
480 QByteArray unqualifiedScope = p.type.left(len: s);
481
482 // The scope may be a namespace for example, so it's only safe to include scopes that are known QObjects (QTBUG-2151)
483 QHash<QByteArray, QByteArray>::ConstIterator scopeIt;
484
485 QByteArray thisScope = cdef->qualified;
486 do {
487 int s = thisScope.lastIndexOf(c: "::");
488 thisScope = thisScope.left(len: s);
489 QByteArray currentScope = thisScope.isEmpty() ? unqualifiedScope : thisScope + "::" + unqualifiedScope;
490 scopeIt = knownExtraMetaObject.constFind(akey: currentScope);
491 } while (!thisScope.isEmpty() && scopeIt == knownExtraMetaObject.constEnd());
492
493 if (scopeIt == knownExtraMetaObject.constEnd())
494 continue;
495
496 const QByteArray &scope = *scopeIt;
497
498 if (scope == "Qt")
499 continue;
500 if (qualifiedNameEquals(qualifiedName: cdef->qualified, name: scope))
501 continue;
502
503 if (!extraList.contains(t: scope))
504 extraList += scope;
505 }
506
507 // QTBUG-20639 - Accept non-local enums for QML signal/slot parameters.
508 // Look for any scoped enum declarations, and add those to the list
509 // of extra/related metaobjects for this object.
510 for (auto it = cdef->enumDeclarations.keyBegin(),
511 end = cdef->enumDeclarations.keyEnd(); it != end; ++it) {
512 const QByteArray &enumKey = *it;
513 int s = enumKey.lastIndexOf(c: "::");
514 if (s > 0) {
515 QByteArray scope = enumKey.left(len: s);
516 if (scope != "Qt" && !qualifiedNameEquals(qualifiedName: cdef->qualified, name: scope) && !extraList.contains(t: scope))
517 extraList += scope;
518 }
519 }
520
521//
522// Generate meta object link to parent meta objects
523//
524
525 if (!extraList.isEmpty()) {
526 fprintf(stream: out, format: "static const QMetaObject::SuperData qt_meta_extradata_%s[] = {\n",
527 qualifiedClassNameIdentifier.constData());
528 for (int i = 0; i < extraList.count(); ++i) {
529 fprintf(stream: out, format: " QMetaObject::SuperData::link<%s::staticMetaObject>(),\n", extraList.at(i).constData());
530 }
531 fprintf(stream: out, format: " nullptr\n};\n\n");
532 }
533
534//
535// Finally create and initialize the static meta object
536//
537 if (isQt)
538 fprintf(stream: out, format: "QT_INIT_METAOBJECT const QMetaObject QObject::staticQtMetaObject = { {\n");
539 else
540 fprintf(stream: out, format: "QT_INIT_METAOBJECT const QMetaObject %s::staticMetaObject = { {\n", cdef->qualified.constData());
541
542 if (isQObject)
543 fprintf(stream: out, format: " nullptr,\n");
544 else if (cdef->superclassList.size() && !cdef->hasQGadget && !cdef->hasQNamespace) // for qobject, we know the super class must have a static metaobject
545 fprintf(stream: out, format: " QMetaObject::SuperData::link<%s::staticMetaObject>(),\n", purestSuperClass.constData());
546 else if (cdef->superclassList.size()) // for gadgets we need to query at compile time for it
547 fprintf(stream: out, format: " QtPrivate::MetaObjectForType<%s>::value(),\n", purestSuperClass.constData());
548 else
549 fprintf(stream: out, format: " nullptr,\n");
550 fprintf(stream: out, format: " qt_meta_stringdata_%s.data,\n"
551 " qt_meta_data_%s,\n", qualifiedClassNameIdentifier.constData(),
552 qualifiedClassNameIdentifier.constData());
553 if (hasStaticMetaCall)
554 fprintf(stream: out, format: " qt_static_metacall,\n");
555 else
556 fprintf(stream: out, format: " nullptr,\n");
557
558 if (extraList.isEmpty())
559 fprintf(stream: out, format: " nullptr,\n");
560 else
561 fprintf(stream: out, format: " qt_meta_extradata_%s,\n", qualifiedClassNameIdentifier.constData());
562 fprintf(stream: out, format: " nullptr\n} };\n\n");
563
564 if(isQt)
565 return;
566
567 if (!cdef->hasQObject)
568 return;
569
570 fprintf(stream: out, format: "\nconst QMetaObject *%s::metaObject() const\n{\n return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;\n}\n",
571 cdef->qualified.constData());
572
573//
574// Generate smart cast function
575//
576 fprintf(stream: out, format: "\nvoid *%s::qt_metacast(const char *_clname)\n{\n", cdef->qualified.constData());
577 fprintf(stream: out, format: " if (!_clname) return nullptr;\n");
578 fprintf(stream: out, format: " if (!strcmp(_clname, qt_meta_stringdata_%s.stringdata0))\n"
579 " return static_cast<void*>(this);\n",
580 qualifiedClassNameIdentifier.constData());
581 for (int i = 1; i < cdef->superclassList.size(); ++i) { // for all superclasses but the first one
582 if (cdef->superclassList.at(i).second == FunctionDef::Private)
583 continue;
584 const char *cname = cdef->superclassList.at(i).first.constData();
585 fprintf(stream: out, format: " if (!strcmp(_clname, \"%s\"))\n return static_cast< %s*>(this);\n",
586 cname, cname);
587 }
588 for (int i = 0; i < cdef->interfaceList.size(); ++i) {
589 const QVector<ClassDef::Interface> &iface = cdef->interfaceList.at(i);
590 for (int j = 0; j < iface.size(); ++j) {
591 fprintf(stream: out, format: " if (!strcmp(_clname, %s))\n return ", iface.at(i: j).interfaceId.constData());
592 for (int k = j; k >= 0; --k)
593 fprintf(stream: out, format: "static_cast< %s*>(", iface.at(i: k).className.constData());
594 fprintf(stream: out, format: "this%s;\n", QByteArray(j + 1, ')').constData());
595 }
596 }
597 if (!purestSuperClass.isEmpty() && !isQObject) {
598 QByteArray superClass = purestSuperClass;
599 fprintf(stream: out, format: " return %s::qt_metacast(_clname);\n", superClass.constData());
600 } else {
601 fprintf(stream: out, format: " return nullptr;\n");
602 }
603 fprintf(stream: out, format: "}\n");
604
605//
606// Generate internal qt_metacall() function
607//
608 generateMetacall();
609
610//
611// Generate internal signal functions
612//
613 for (int signalindex = 0; signalindex < cdef->signalList.size(); ++signalindex)
614 generateSignal(def: &cdef->signalList[signalindex], index: signalindex);
615
616//
617// Generate plugin meta data
618//
619 generatePluginMetaData();
620
621//
622// Generate function to make sure the non-class signals exist in the parent classes
623//
624 if (!cdef->nonClassSignalList.isEmpty()) {
625 fprintf(stream: out, format: "// If you get a compile error in this function it can be because either\n");
626 fprintf(stream: out, format: "// a) You are using a NOTIFY signal that does not exist. Fix it.\n");
627 fprintf(stream: out, format: "// b) You are using a NOTIFY signal that does exist (in a parent class) but has a non-empty parameter list. This is a moc limitation.\n");
628 fprintf(stream: out, format: "Q_DECL_UNUSED static void checkNotifySignalValidity_%s(%s *t) {\n", qualifiedClassNameIdentifier.constData(), cdef->qualified.constData());
629 for (const QByteArray &nonClassSignal : qAsConst(t&: cdef->nonClassSignalList))
630 fprintf(stream: out, format: " t->%s();\n", nonClassSignal.constData());
631 fprintf(stream: out, format: "}\n");
632 }
633}
634
635
636void Generator::registerClassInfoStrings()
637{
638 for (int i = 0; i < cdef->classInfoList.size(); ++i) {
639 const ClassInfoDef &c = cdef->classInfoList.at(i);
640 strreg(s: c.name);
641 strreg(s: c.value);
642 }
643}
644
645void Generator::generateClassInfos()
646{
647 if (cdef->classInfoList.isEmpty())
648 return;
649
650 fprintf(stream: out, format: "\n // classinfo: key, value\n");
651
652 for (int i = 0; i < cdef->classInfoList.size(); ++i) {
653 const ClassInfoDef &c = cdef->classInfoList.at(i);
654 fprintf(stream: out, format: " %4d, %4d,\n", stridx(s: c.name), stridx(s: c.value));
655 }
656}
657
658void Generator::registerFunctionStrings(const QVector<FunctionDef>& list)
659{
660 for (int i = 0; i < list.count(); ++i) {
661 const FunctionDef &f = list.at(i);
662
663 strreg(s: f.name);
664 if (!isBuiltinType(type: f.normalizedType))
665 strreg(s: f.normalizedType);
666 strreg(s: f.tag);
667
668 int argsCount = f.arguments.count();
669 for (int j = 0; j < argsCount; ++j) {
670 const ArgumentDef &a = f.arguments.at(i: j);
671 if (!isBuiltinType(type: a.normalizedType))
672 strreg(s: a.normalizedType);
673 strreg(s: a.name);
674 }
675 }
676}
677
678void Generator::registerByteArrayVector(const QVector<QByteArray> &list)
679{
680 for (const QByteArray &ba : list)
681 strreg(s: ba);
682}
683
684void Generator::generateFunctions(const QVector<FunctionDef>& list, const char *functype, int type, int &paramsIndex)
685{
686 if (list.isEmpty())
687 return;
688 fprintf(stream: out, format: "\n // %ss: name, argc, parameters, tag, flags\n", functype);
689
690 for (int i = 0; i < list.count(); ++i) {
691 const FunctionDef &f = list.at(i);
692
693 QByteArray comment;
694 unsigned char flags = type;
695 if (f.access == FunctionDef::Private) {
696 flags |= AccessPrivate;
697 comment.append(s: "Private");
698 } else if (f.access == FunctionDef::Public) {
699 flags |= AccessPublic;
700 comment.append(s: "Public");
701 } else if (f.access == FunctionDef::Protected) {
702 flags |= AccessProtected;
703 comment.append(s: "Protected");
704 }
705 if (f.isCompat) {
706 flags |= MethodCompatibility;
707 comment.append(s: " | MethodCompatibility");
708 }
709 if (f.wasCloned) {
710 flags |= MethodCloned;
711 comment.append(s: " | MethodCloned");
712 }
713 if (f.isScriptable) {
714 flags |= MethodScriptable;
715 comment.append(s: " | isScriptable");
716 }
717 if (f.revision > 0) {
718 flags |= MethodRevisioned;
719 comment.append(s: " | MethodRevisioned");
720 }
721
722 int argc = f.arguments.count();
723 fprintf(stream: out, format: " %4d, %4d, %4d, %4d, 0x%02x /* %s */,\n",
724 stridx(s: f.name), argc, paramsIndex, stridx(s: f.tag), flags, comment.constData());
725
726 paramsIndex += 1 + argc * 2;
727 }
728}
729
730void Generator::generateFunctionRevisions(const QVector<FunctionDef>& list, const char *functype)
731{
732 if (list.count())
733 fprintf(stream: out, format: "\n // %ss: revision\n", functype);
734 for (int i = 0; i < list.count(); ++i) {
735 const FunctionDef &f = list.at(i);
736 fprintf(stream: out, format: " %4d,\n", f.revision);
737 }
738}
739
740void Generator::generateFunctionParameters(const QVector<FunctionDef>& list, const char *functype)
741{
742 if (list.isEmpty())
743 return;
744 fprintf(stream: out, format: "\n // %ss: parameters\n", functype);
745 for (int i = 0; i < list.count(); ++i) {
746 const FunctionDef &f = list.at(i);
747 fprintf(stream: out, format: " ");
748
749 // Types
750 int argsCount = f.arguments.count();
751 for (int j = -1; j < argsCount; ++j) {
752 if (j > -1)
753 fputc(c: ' ', stream: out);
754 const QByteArray &typeName = (j < 0) ? f.normalizedType : f.arguments.at(i: j).normalizedType;
755 generateTypeInfo(typeName, /*allowEmptyName=*/f.isConstructor);
756 fputc(c: ',', stream: out);
757 }
758
759 // Parameter names
760 for (int j = 0; j < argsCount; ++j) {
761 const ArgumentDef &arg = f.arguments.at(i: j);
762 fprintf(stream: out, format: " %4d,", stridx(s: arg.name));
763 }
764
765 fprintf(stream: out, format: "\n");
766 }
767}
768
769void Generator::generateTypeInfo(const QByteArray &typeName, bool allowEmptyName)
770{
771 Q_UNUSED(allowEmptyName);
772 if (isBuiltinType(type: typeName)) {
773 int type;
774 const char *valueString;
775 if (typeName == "qreal") {
776 type = QMetaType::UnknownType;
777 valueString = "QReal";
778 } else {
779 type = nameToBuiltinType(name: typeName);
780 valueString = metaTypeEnumValueString(type);
781 }
782 if (valueString) {
783 fprintf(stream: out, format: "QMetaType::%s", valueString);
784 } else {
785 Q_ASSERT(type != QMetaType::UnknownType);
786 fprintf(stream: out, format: "%4d", type);
787 }
788 } else {
789 Q_ASSERT(!typeName.isEmpty() || allowEmptyName);
790 fprintf(stream: out, format: "0x%.8x | %d", IsUnresolvedType, stridx(s: typeName));
791 }
792}
793
794void Generator::registerPropertyStrings()
795{
796 for (int i = 0; i < cdef->propertyList.count(); ++i) {
797 const PropertyDef &p = cdef->propertyList.at(i);
798 strreg(s: p.name);
799 if (!isBuiltinType(type: p.type))
800 strreg(s: p.type);
801 }
802}
803
804void Generator::generateProperties()
805{
806 //
807 // Create meta data
808 //
809
810 if (cdef->propertyList.count())
811 fprintf(stream: out, format: "\n // properties: name, type, flags\n");
812 for (int i = 0; i < cdef->propertyList.count(); ++i) {
813 const PropertyDef &p = cdef->propertyList.at(i);
814 uint flags = Invalid;
815 if (!isBuiltinType(type: p.type))
816 flags |= EnumOrFlag;
817 if (!p.member.isEmpty() && !p.constant)
818 flags |= Writable;
819 if (!p.read.isEmpty() || !p.member.isEmpty())
820 flags |= Readable;
821 if (!p.write.isEmpty()) {
822 flags |= Writable;
823 if (p.stdCppSet())
824 flags |= StdCppSet;
825 }
826 if (!p.reset.isEmpty())
827 flags |= Resettable;
828
829// if (p.override)
830// flags |= Override;
831
832 if (p.designable.isEmpty())
833 flags |= ResolveDesignable;
834 else if (p.designable != "false")
835 flags |= Designable;
836
837 if (p.scriptable.isEmpty())
838 flags |= ResolveScriptable;
839 else if (p.scriptable != "false")
840 flags |= Scriptable;
841
842 if (p.stored.isEmpty())
843 flags |= ResolveStored;
844 else if (p.stored != "false")
845 flags |= Stored;
846
847 if (p.editable.isEmpty())
848 flags |= ResolveEditable;
849 else if (p.editable != "false")
850 flags |= Editable;
851
852 if (p.user.isEmpty())
853 flags |= ResolveUser;
854 else if (p.user != "false")
855 flags |= User;
856
857 if (p.notifyId != -1)
858 flags |= Notify;
859
860 if (p.revision > 0)
861 flags |= Revisioned;
862
863 if (p.constant)
864 flags |= Constant;
865 if (p.final)
866 flags |= Final;
867 if (p.required)
868 flags |= Required;
869
870 fprintf(stream: out, format: " %4d, ", stridx(s: p.name));
871 generateTypeInfo(typeName: p.type);
872 fprintf(stream: out, format: ", 0x%.8x,\n", flags);
873 }
874
875 if(cdef->notifyableProperties) {
876 fprintf(stream: out, format: "\n // properties: notify_signal_id\n");
877 for (int i = 0; i < cdef->propertyList.count(); ++i) {
878 const PropertyDef &p = cdef->propertyList.at(i);
879 if (p.notifyId == -1) {
880 fprintf(stream: out, format: " %4d,\n",
881 0);
882 } else if (p.notifyId > -1) {
883 fprintf(stream: out, format: " %4d,\n",
884 p.notifyId);
885 } else {
886 const int indexInStrings = strings.indexOf(t: p.notify);
887 fprintf(stream: out, format: " %4d,\n",
888 indexInStrings | IsUnresolvedSignal);
889 }
890 }
891 }
892 if (cdef->revisionedProperties) {
893 fprintf(stream: out, format: "\n // properties: revision\n");
894 for (int i = 0; i < cdef->propertyList.count(); ++i) {
895 const PropertyDef &p = cdef->propertyList.at(i);
896 fprintf(stream: out, format: " %4d,\n", p.revision);
897 }
898 }
899}
900
901void Generator::registerEnumStrings()
902{
903 for (int i = 0; i < cdef->enumList.count(); ++i) {
904 const EnumDef &e = cdef->enumList.at(i);
905 strreg(s: e.name);
906 if (!e.enumName.isNull())
907 strreg(s: e.enumName);
908 for (int j = 0; j < e.values.count(); ++j)
909 strreg(s: e.values.at(i: j));
910 }
911}
912
913void Generator::generateEnums(int index)
914{
915 if (cdef->enumDeclarations.isEmpty())
916 return;
917
918 fprintf(stream: out, format: "\n // enums: name, alias, flags, count, data\n");
919 index += 5 * cdef->enumList.count();
920 int i;
921 for (i = 0; i < cdef->enumList.count(); ++i) {
922 const EnumDef &e = cdef->enumList.at(i);
923 int flags = 0;
924 if (cdef->enumDeclarations.value(akey: e.name))
925 flags |= EnumIsFlag;
926 if (e.isEnumClass)
927 flags |= EnumIsScoped;
928 fprintf(stream: out, format: " %4d, %4d, 0x%.1x, %4d, %4d,\n",
929 stridx(s: e.name),
930 e.enumName.isNull() ? stridx(s: e.name) : stridx(s: e.enumName),
931 flags,
932 e.values.count(),
933 index);
934 index += e.values.count() * 2;
935 }
936
937 fprintf(stream: out, format: "\n // enum data: key, value\n");
938 for (i = 0; i < cdef->enumList.count(); ++i) {
939 const EnumDef &e = cdef->enumList.at(i);
940 for (int j = 0; j < e.values.count(); ++j) {
941 const QByteArray &val = e.values.at(i: j);
942 QByteArray code = cdef->qualified.constData();
943 if (e.isEnumClass)
944 code += "::" + (e.enumName.isNull() ? e.name : e.enumName);
945 code += "::" + val;
946 fprintf(stream: out, format: " %4d, uint(%s),\n",
947 stridx(s: val), code.constData());
948 }
949 }
950}
951
952void Generator::generateMetacall()
953{
954 bool isQObject = (cdef->classname == "QObject");
955
956 fprintf(stream: out, format: "\nint %s::qt_metacall(QMetaObject::Call _c, int _id, void **_a)\n{\n",
957 cdef->qualified.constData());
958
959 if (!purestSuperClass.isEmpty() && !isQObject) {
960 QByteArray superClass = purestSuperClass;
961 fprintf(stream: out, format: " _id = %s::qt_metacall(_c, _id, _a);\n", superClass.constData());
962 }
963
964
965 bool needElse = false;
966 QVector<FunctionDef> methodList;
967 methodList += cdef->signalList;
968 methodList += cdef->slotList;
969 methodList += cdef->methodList;
970
971 // If there are no methods or properties, we will return _id anyway, so
972 // don't emit this comparison -- it is unnecessary, and it makes coverity
973 // unhappy.
974 if (methodList.size() || cdef->propertyList.size()) {
975 fprintf(stream: out, format: " if (_id < 0)\n return _id;\n");
976 }
977
978 fprintf(stream: out, format: " ");
979
980 if (methodList.size()) {
981 needElse = true;
982 fprintf(stream: out, format: "if (_c == QMetaObject::InvokeMetaMethod) {\n");
983 fprintf(stream: out, format: " if (_id < %d)\n", methodList.size());
984 fprintf(stream: out, format: " qt_static_metacall(this, _c, _id, _a);\n");
985 fprintf(stream: out, format: " _id -= %d;\n }", methodList.size());
986
987 fprintf(stream: out, format: " else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {\n");
988 fprintf(stream: out, format: " if (_id < %d)\n", methodList.size());
989
990 if (methodsWithAutomaticTypesHelper(methodList).isEmpty())
991 fprintf(stream: out, format: " *reinterpret_cast<int*>(_a[0]) = -1;\n");
992 else
993 fprintf(stream: out, format: " qt_static_metacall(this, _c, _id, _a);\n");
994 fprintf(stream: out, format: " _id -= %d;\n }", methodList.size());
995
996 }
997
998 if (cdef->propertyList.size()) {
999 bool needDesignable = false;
1000 bool needScriptable = false;
1001 bool needStored = false;
1002 bool needEditable = false;
1003 bool needUser = false;
1004 for (int i = 0; i < cdef->propertyList.size(); ++i) {
1005 const PropertyDef &p = cdef->propertyList.at(i);
1006 needDesignable |= p.designable.endsWith(c: ')');
1007 needScriptable |= p.scriptable.endsWith(c: ')');
1008 needStored |= p.stored.endsWith(c: ')');
1009 needEditable |= p.editable.endsWith(c: ')');
1010 needUser |= p.user.endsWith(c: ')');
1011 }
1012
1013 fprintf(stream: out, format: "\n#ifndef QT_NO_PROPERTIES\n ");
1014 if (needElse)
1015 fprintf(stream: out, format: "else ");
1016 fprintf(stream: out,
1017 format: "if (_c == QMetaObject::ReadProperty || _c == QMetaObject::WriteProperty\n"
1018 " || _c == QMetaObject::ResetProperty || _c == QMetaObject::RegisterPropertyMetaType) {\n"
1019 " qt_static_metacall(this, _c, _id, _a);\n"
1020 " _id -= %d;\n }", cdef->propertyList.count());
1021
1022 fprintf(stream: out, format: " else ");
1023 fprintf(stream: out, format: "if (_c == QMetaObject::QueryPropertyDesignable) {\n");
1024 if (needDesignable) {
1025 fprintf(stream: out, format: " bool *_b = reinterpret_cast<bool*>(_a[0]);\n");
1026 fprintf(stream: out, format: " switch (_id) {\n");
1027 for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) {
1028 const PropertyDef &p = cdef->propertyList.at(i: propindex);
1029 if (!p.designable.endsWith(c: ')'))
1030 continue;
1031 fprintf(stream: out, format: " case %d: *_b = %s; break;\n",
1032 propindex, p.designable.constData());
1033 }
1034 fprintf(stream: out, format: " default: break;\n");
1035 fprintf(stream: out, format: " }\n");
1036 }
1037 fprintf(stream: out,
1038 format: " _id -= %d;\n"
1039 " }", cdef->propertyList.count());
1040
1041 fprintf(stream: out, format: " else ");
1042 fprintf(stream: out, format: "if (_c == QMetaObject::QueryPropertyScriptable) {\n");
1043 if (needScriptable) {
1044 fprintf(stream: out, format: " bool *_b = reinterpret_cast<bool*>(_a[0]);\n");
1045 fprintf(stream: out, format: " switch (_id) {\n");
1046 for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) {
1047 const PropertyDef &p = cdef->propertyList.at(i: propindex);
1048 if (!p.scriptable.endsWith(c: ')'))
1049 continue;
1050 fprintf(stream: out, format: " case %d: *_b = %s; break;\n",
1051 propindex, p.scriptable.constData());
1052 }
1053 fprintf(stream: out, format: " default: break;\n");
1054 fprintf(stream: out, format: " }\n");
1055 }
1056 fprintf(stream: out,
1057 format: " _id -= %d;\n"
1058 " }", cdef->propertyList.count());
1059
1060 fprintf(stream: out, format: " else ");
1061 fprintf(stream: out, format: "if (_c == QMetaObject::QueryPropertyStored) {\n");
1062 if (needStored) {
1063 fprintf(stream: out, format: " bool *_b = reinterpret_cast<bool*>(_a[0]);\n");
1064 fprintf(stream: out, format: " switch (_id) {\n");
1065 for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) {
1066 const PropertyDef &p = cdef->propertyList.at(i: propindex);
1067 if (!p.stored.endsWith(c: ')'))
1068 continue;
1069 fprintf(stream: out, format: " case %d: *_b = %s; break;\n",
1070 propindex, p.stored.constData());
1071 }
1072 fprintf(stream: out, format: " default: break;\n");
1073 fprintf(stream: out, format: " }\n");
1074 }
1075 fprintf(stream: out,
1076 format: " _id -= %d;\n"
1077 " }", cdef->propertyList.count());
1078
1079 fprintf(stream: out, format: " else ");
1080 fprintf(stream: out, format: "if (_c == QMetaObject::QueryPropertyEditable) {\n");
1081 if (needEditable) {
1082 fprintf(stream: out, format: " bool *_b = reinterpret_cast<bool*>(_a[0]);\n");
1083 fprintf(stream: out, format: " switch (_id) {\n");
1084 for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) {
1085 const PropertyDef &p = cdef->propertyList.at(i: propindex);
1086 if (!p.editable.endsWith(c: ')'))
1087 continue;
1088 fprintf(stream: out, format: " case %d: *_b = %s; break;\n",
1089 propindex, p.editable.constData());
1090 }
1091 fprintf(stream: out, format: " default: break;\n");
1092 fprintf(stream: out, format: " }\n");
1093 }
1094 fprintf(stream: out,
1095 format: " _id -= %d;\n"
1096 " }", cdef->propertyList.count());
1097
1098
1099 fprintf(stream: out, format: " else ");
1100 fprintf(stream: out, format: "if (_c == QMetaObject::QueryPropertyUser) {\n");
1101 if (needUser) {
1102 fprintf(stream: out, format: " bool *_b = reinterpret_cast<bool*>(_a[0]);\n");
1103 fprintf(stream: out, format: " switch (_id) {\n");
1104 for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) {
1105 const PropertyDef &p = cdef->propertyList.at(i: propindex);
1106 if (!p.user.endsWith(c: ')'))
1107 continue;
1108 fprintf(stream: out, format: " case %d: *_b = %s; break;\n",
1109 propindex, p.user.constData());
1110 }
1111 fprintf(stream: out, format: " default: break;\n");
1112 fprintf(stream: out, format: " }\n");
1113 }
1114 fprintf(stream: out,
1115 format: " _id -= %d;\n"
1116 " }", cdef->propertyList.count());
1117
1118 fprintf(stream: out, format: "\n#endif // QT_NO_PROPERTIES");
1119 }
1120 if (methodList.size() || cdef->propertyList.size())
1121 fprintf(stream: out, format: "\n ");
1122 fprintf(stream: out,format: "return _id;\n}\n");
1123}
1124
1125
1126QMultiMap<QByteArray, int> Generator::automaticPropertyMetaTypesHelper()
1127{
1128 QMultiMap<QByteArray, int> automaticPropertyMetaTypes;
1129 for (int i = 0; i < cdef->propertyList.size(); ++i) {
1130 const QByteArray propertyType = cdef->propertyList.at(i).type;
1131 if (registerableMetaType(propertyType) && !isBuiltinType(type: propertyType))
1132 automaticPropertyMetaTypes.insert(akey: propertyType, avalue: i);
1133 }
1134 return automaticPropertyMetaTypes;
1135}
1136
1137QMap<int, QMultiMap<QByteArray, int> > Generator::methodsWithAutomaticTypesHelper(const QVector<FunctionDef> &methodList)
1138{
1139 QMap<int, QMultiMap<QByteArray, int> > methodsWithAutomaticTypes;
1140 for (int i = 0; i < methodList.size(); ++i) {
1141 const FunctionDef &f = methodList.at(i);
1142 for (int j = 0; j < f.arguments.count(); ++j) {
1143 const QByteArray argType = f.arguments.at(i: j).normalizedType;
1144 if (registerableMetaType(propertyType: argType) && !isBuiltinType(type: argType))
1145 methodsWithAutomaticTypes[i].insert(akey: argType, avalue: j);
1146 }
1147 }
1148 return methodsWithAutomaticTypes;
1149}
1150
1151void Generator::generateStaticMetacall()
1152{
1153 fprintf(stream: out, format: "void %s::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)\n{\n",
1154 cdef->qualified.constData());
1155
1156 bool needElse = false;
1157 bool isUsed_a = false;
1158
1159 if (!cdef->constructorList.isEmpty()) {
1160 fprintf(stream: out, format: " if (_c == QMetaObject::CreateInstance) {\n");
1161 fprintf(stream: out, format: " switch (_id) {\n");
1162 for (int ctorindex = 0; ctorindex < cdef->constructorList.count(); ++ctorindex) {
1163 fprintf(stream: out, format: " case %d: { %s *_r = new %s(", ctorindex,
1164 cdef->classname.constData(), cdef->classname.constData());
1165 const FunctionDef &f = cdef->constructorList.at(i: ctorindex);
1166 int offset = 1;
1167
1168 int argsCount = f.arguments.count();
1169 for (int j = 0; j < argsCount; ++j) {
1170 const ArgumentDef &a = f.arguments.at(i: j);
1171 if (j)
1172 fprintf(stream: out, format: ",");
1173 fprintf(stream: out, format: "(*reinterpret_cast< %s>(_a[%d]))", a.typeNameForCast.constData(), offset++);
1174 }
1175 if (f.isPrivateSignal) {
1176 if (argsCount > 0)
1177 fprintf(stream: out, format: ", ");
1178 fprintf(stream: out, format: "%s", QByteArray("QPrivateSignal()").constData());
1179 }
1180 fprintf(stream: out, format: ");\n");
1181 fprintf(stream: out, format: " if (_a[0]) *reinterpret_cast<%s**>(_a[0]) = _r; } break;\n",
1182 (cdef->hasQGadget || cdef->hasQNamespace) ? "void" : "QObject");
1183 }
1184 fprintf(stream: out, format: " default: break;\n");
1185 fprintf(stream: out, format: " }\n");
1186 fprintf(stream: out, format: " }");
1187 needElse = true;
1188 isUsed_a = true;
1189 }
1190
1191 QVector<FunctionDef> methodList;
1192 methodList += cdef->signalList;
1193 methodList += cdef->slotList;
1194 methodList += cdef->methodList;
1195
1196 if (!methodList.isEmpty()) {
1197 if (needElse)
1198 fprintf(stream: out, format: " else ");
1199 else
1200 fprintf(stream: out, format: " ");
1201 fprintf(stream: out, format: "if (_c == QMetaObject::InvokeMetaMethod) {\n");
1202 if (cdef->hasQObject) {
1203#ifndef QT_NO_DEBUG
1204 fprintf(stream: out, format: " Q_ASSERT(staticMetaObject.cast(_o));\n");
1205#endif
1206 fprintf(stream: out, format: " auto *_t = static_cast<%s *>(_o);\n", cdef->classname.constData());
1207 } else {
1208 fprintf(stream: out, format: " auto *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData());
1209 }
1210 fprintf(stream: out, format: " (void)_t;\n");
1211 fprintf(stream: out, format: " switch (_id) {\n");
1212 for (int methodindex = 0; methodindex < methodList.size(); ++methodindex) {
1213 const FunctionDef &f = methodList.at(i: methodindex);
1214 Q_ASSERT(!f.normalizedType.isEmpty());
1215 fprintf(stream: out, format: " case %d: ", methodindex);
1216 if (f.normalizedType != "void")
1217 fprintf(stream: out, format: "{ %s _r = ", noRef(type: f.normalizedType).constData());
1218 fprintf(stream: out, format: "_t->");
1219 if (f.inPrivateClass.size())
1220 fprintf(stream: out, format: "%s->", f.inPrivateClass.constData());
1221 fprintf(stream: out, format: "%s(", f.name.constData());
1222 int offset = 1;
1223
1224 int argsCount = f.arguments.count();
1225 for (int j = 0; j < argsCount; ++j) {
1226 const ArgumentDef &a = f.arguments.at(i: j);
1227 if (j)
1228 fprintf(stream: out, format: ",");
1229 fprintf(stream: out, format: "(*reinterpret_cast< %s>(_a[%d]))",a.typeNameForCast.constData(), offset++);
1230 isUsed_a = true;
1231 }
1232 if (f.isPrivateSignal) {
1233 if (argsCount > 0)
1234 fprintf(stream: out, format: ", ");
1235 fprintf(stream: out, format: "%s", "QPrivateSignal()");
1236 }
1237 fprintf(stream: out, format: ");");
1238 if (f.normalizedType != "void") {
1239 fprintf(stream: out, format: "\n if (_a[0]) *reinterpret_cast< %s*>(_a[0]) = std::move(_r); } ",
1240 noRef(type: f.normalizedType).constData());
1241 isUsed_a = true;
1242 }
1243 fprintf(stream: out, format: " break;\n");
1244 }
1245 fprintf(stream: out, format: " default: ;\n");
1246 fprintf(stream: out, format: " }\n");
1247 fprintf(stream: out, format: " }");
1248 needElse = true;
1249
1250 QMap<int, QMultiMap<QByteArray, int> > methodsWithAutomaticTypes = methodsWithAutomaticTypesHelper(methodList);
1251
1252 if (!methodsWithAutomaticTypes.isEmpty()) {
1253 fprintf(stream: out, format: " else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {\n");
1254 fprintf(stream: out, format: " switch (_id) {\n");
1255 fprintf(stream: out, format: " default: *reinterpret_cast<int*>(_a[0]) = -1; break;\n");
1256 QMap<int, QMultiMap<QByteArray, int> >::const_iterator it = methodsWithAutomaticTypes.constBegin();
1257 const QMap<int, QMultiMap<QByteArray, int> >::const_iterator end = methodsWithAutomaticTypes.constEnd();
1258 for ( ; it != end; ++it) {
1259 fprintf(stream: out, format: " case %d:\n", it.key());
1260 fprintf(stream: out, format: " switch (*reinterpret_cast<int*>(_a[1])) {\n");
1261 fprintf(stream: out, format: " default: *reinterpret_cast<int*>(_a[0]) = -1; break;\n");
1262 auto jt = it->begin();
1263 const auto jend = it->end();
1264 while (jt != jend) {
1265 fprintf(stream: out, format: " case %d:\n", jt.value());
1266 const QByteArray &lastKey = jt.key();
1267 ++jt;
1268 if (jt == jend || jt.key() != lastKey)
1269 fprintf(stream: out, format: " *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< %s >(); break;\n", lastKey.constData());
1270 }
1271 fprintf(stream: out, format: " }\n");
1272 fprintf(stream: out, format: " break;\n");
1273 }
1274 fprintf(stream: out, format: " }\n");
1275 fprintf(stream: out, format: " }");
1276 isUsed_a = true;
1277 }
1278
1279 }
1280 if (!cdef->signalList.isEmpty()) {
1281 Q_ASSERT(needElse); // if there is signal, there was method.
1282 fprintf(stream: out, format: " else if (_c == QMetaObject::IndexOfMethod) {\n");
1283 fprintf(stream: out, format: " int *result = reinterpret_cast<int *>(_a[0]);\n");
1284 bool anythingUsed = false;
1285 for (int methodindex = 0; methodindex < cdef->signalList.size(); ++methodindex) {
1286 const FunctionDef &f = cdef->signalList.at(i: methodindex);
1287 if (f.wasCloned || !f.inPrivateClass.isEmpty() || f.isStatic)
1288 continue;
1289 anythingUsed = true;
1290 fprintf(stream: out, format: " {\n");
1291 fprintf(stream: out, format: " using _t = %s (%s::*)(",f.type.rawName.constData() , cdef->classname.constData());
1292
1293 int argsCount = f.arguments.count();
1294 for (int j = 0; j < argsCount; ++j) {
1295 const ArgumentDef &a = f.arguments.at(i: j);
1296 if (j)
1297 fprintf(stream: out, format: ", ");
1298 fprintf(stream: out, format: "%s", QByteArray(a.type.name + ' ' + a.rightType).constData());
1299 }
1300 if (f.isPrivateSignal) {
1301 if (argsCount > 0)
1302 fprintf(stream: out, format: ", ");
1303 fprintf(stream: out, format: "%s", "QPrivateSignal");
1304 }
1305 if (f.isConst)
1306 fprintf(stream: out, format: ") const;\n");
1307 else
1308 fprintf(stream: out, format: ");\n");
1309 fprintf(stream: out, format: " if (*reinterpret_cast<_t *>(_a[1]) == static_cast<_t>(&%s::%s)) {\n",
1310 cdef->classname.constData(), f.name.constData());
1311 fprintf(stream: out, format: " *result = %d;\n", methodindex);
1312 fprintf(stream: out, format: " return;\n");
1313 fprintf(stream: out, format: " }\n }\n");
1314 }
1315 if (!anythingUsed)
1316 fprintf(stream: out, format: " (void)result;\n");
1317 fprintf(stream: out, format: " }");
1318 needElse = true;
1319 }
1320
1321 const QMultiMap<QByteArray, int> automaticPropertyMetaTypes = automaticPropertyMetaTypesHelper();
1322
1323 if (!automaticPropertyMetaTypes.isEmpty()) {
1324 if (needElse)
1325 fprintf(stream: out, format: " else ");
1326 else
1327 fprintf(stream: out, format: " ");
1328 fprintf(stream: out, format: "if (_c == QMetaObject::RegisterPropertyMetaType) {\n");
1329 fprintf(stream: out, format: " switch (_id) {\n");
1330 fprintf(stream: out, format: " default: *reinterpret_cast<int*>(_a[0]) = -1; break;\n");
1331 auto it = automaticPropertyMetaTypes.begin();
1332 const auto end = automaticPropertyMetaTypes.end();
1333 while (it != end) {
1334 fprintf(stream: out, format: " case %d:\n", it.value());
1335 const QByteArray &lastKey = it.key();
1336 ++it;
1337 if (it == end || it.key() != lastKey)
1338 fprintf(stream: out, format: " *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< %s >(); break;\n", lastKey.constData());
1339 }
1340 fprintf(stream: out, format: " }\n");
1341 fprintf(stream: out, format: " }\n");
1342 isUsed_a = true;
1343 needElse = true;
1344 }
1345
1346 if (!cdef->propertyList.empty()) {
1347 bool needGet = false;
1348 bool needTempVarForGet = false;
1349 bool needSet = false;
1350 bool needReset = false;
1351 for (int i = 0; i < cdef->propertyList.size(); ++i) {
1352 const PropertyDef &p = cdef->propertyList.at(i);
1353 needGet |= !p.read.isEmpty() || !p.member.isEmpty();
1354 if (!p.read.isEmpty() || !p.member.isEmpty())
1355 needTempVarForGet |= (p.gspec != PropertyDef::PointerSpec
1356 && p.gspec != PropertyDef::ReferenceSpec);
1357
1358 needSet |= !p.write.isEmpty() || (!p.member.isEmpty() && !p.constant);
1359 needReset |= !p.reset.isEmpty();
1360 }
1361 fprintf(stream: out, format: "\n#ifndef QT_NO_PROPERTIES\n ");
1362
1363 if (needElse)
1364 fprintf(stream: out, format: "else ");
1365 fprintf(stream: out, format: "if (_c == QMetaObject::ReadProperty) {\n");
1366 if (needGet) {
1367 if (cdef->hasQObject) {
1368#ifndef QT_NO_DEBUG
1369 fprintf(stream: out, format: " Q_ASSERT(staticMetaObject.cast(_o));\n");
1370#endif
1371 fprintf(stream: out, format: " auto *_t = static_cast<%s *>(_o);\n", cdef->classname.constData());
1372 } else {
1373 fprintf(stream: out, format: " auto *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData());
1374 }
1375 fprintf(stream: out, format: " (void)_t;\n");
1376 if (needTempVarForGet)
1377 fprintf(stream: out, format: " void *_v = _a[0];\n");
1378 fprintf(stream: out, format: " switch (_id) {\n");
1379 for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) {
1380 const PropertyDef &p = cdef->propertyList.at(i: propindex);
1381 if (p.read.isEmpty() && p.member.isEmpty())
1382 continue;
1383 QByteArray prefix = "_t->";
1384 if (p.inPrivateClass.size()) {
1385 prefix += p.inPrivateClass + "->";
1386 }
1387 if (p.gspec == PropertyDef::PointerSpec)
1388 fprintf(stream: out, format: " case %d: _a[0] = const_cast<void*>(reinterpret_cast<const void*>(%s%s())); break;\n",
1389 propindex, prefix.constData(), p.read.constData());
1390 else if (p.gspec == PropertyDef::ReferenceSpec)
1391 fprintf(stream: out, format: " case %d: _a[0] = const_cast<void*>(reinterpret_cast<const void*>(&%s%s())); break;\n",
1392 propindex, prefix.constData(), p.read.constData());
1393 else if (cdef->enumDeclarations.value(akey: p.type, adefaultValue: false))
1394 fprintf(stream: out, format: " case %d: *reinterpret_cast<int*>(_v) = QFlag(%s%s()); break;\n",
1395 propindex, prefix.constData(), p.read.constData());
1396 else if (!p.read.isEmpty())
1397 fprintf(stream: out, format: " case %d: *reinterpret_cast< %s*>(_v) = %s%s(); break;\n",
1398 propindex, p.type.constData(), prefix.constData(), p.read.constData());
1399 else
1400 fprintf(stream: out, format: " case %d: *reinterpret_cast< %s*>(_v) = %s%s; break;\n",
1401 propindex, p.type.constData(), prefix.constData(), p.member.constData());
1402 }
1403 fprintf(stream: out, format: " default: break;\n");
1404 fprintf(stream: out, format: " }\n");
1405 }
1406
1407 fprintf(stream: out, format: " }");
1408
1409 fprintf(stream: out, format: " else ");
1410 fprintf(stream: out, format: "if (_c == QMetaObject::WriteProperty) {\n");
1411
1412 if (needSet) {
1413 if (cdef->hasQObject) {
1414#ifndef QT_NO_DEBUG
1415 fprintf(stream: out, format: " Q_ASSERT(staticMetaObject.cast(_o));\n");
1416#endif
1417 fprintf(stream: out, format: " auto *_t = static_cast<%s *>(_o);\n", cdef->classname.constData());
1418 } else {
1419 fprintf(stream: out, format: " auto *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData());
1420 }
1421 fprintf(stream: out, format: " (void)_t;\n");
1422 fprintf(stream: out, format: " void *_v = _a[0];\n");
1423 fprintf(stream: out, format: " switch (_id) {\n");
1424 for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) {
1425 const PropertyDef &p = cdef->propertyList.at(i: propindex);
1426 if (p.constant)
1427 continue;
1428 if (p.write.isEmpty() && p.member.isEmpty())
1429 continue;
1430 QByteArray prefix = "_t->";
1431 if (p.inPrivateClass.size()) {
1432 prefix += p.inPrivateClass + "->";
1433 }
1434 if (cdef->enumDeclarations.value(akey: p.type, adefaultValue: false)) {
1435 fprintf(stream: out, format: " case %d: %s%s(QFlag(*reinterpret_cast<int*>(_v))); break;\n",
1436 propindex, prefix.constData(), p.write.constData());
1437 } else if (!p.write.isEmpty()) {
1438 fprintf(stream: out, format: " case %d: %s%s(*reinterpret_cast< %s*>(_v)); break;\n",
1439 propindex, prefix.constData(), p.write.constData(), p.type.constData());
1440 } else {
1441 fprintf(stream: out, format: " case %d:\n", propindex);
1442 fprintf(stream: out, format: " if (%s%s != *reinterpret_cast< %s*>(_v)) {\n",
1443 prefix.constData(), p.member.constData(), p.type.constData());
1444 fprintf(stream: out, format: " %s%s = *reinterpret_cast< %s*>(_v);\n",
1445 prefix.constData(), p.member.constData(), p.type.constData());
1446 if (!p.notify.isEmpty() && p.notifyId > -1) {
1447 const FunctionDef &f = cdef->signalList.at(i: p.notifyId);
1448 if (f.arguments.size() == 0)
1449 fprintf(stream: out, format: " Q_EMIT _t->%s();\n", p.notify.constData());
1450 else if (f.arguments.size() == 1 && f.arguments.at(i: 0).normalizedType == p.type)
1451 fprintf(stream: out, format: " Q_EMIT _t->%s(%s%s);\n",
1452 p.notify.constData(), prefix.constData(), p.member.constData());
1453 } else if (!p.notify.isEmpty() && p.notifyId < -1) {
1454 fprintf(stream: out, format: " Q_EMIT _t->%s();\n", p.notify.constData());
1455 }
1456 fprintf(stream: out, format: " }\n");
1457 fprintf(stream: out, format: " break;\n");
1458 }
1459 }
1460 fprintf(stream: out, format: " default: break;\n");
1461 fprintf(stream: out, format: " }\n");
1462 }
1463
1464 fprintf(stream: out, format: " }");
1465
1466 fprintf(stream: out, format: " else ");
1467 fprintf(stream: out, format: "if (_c == QMetaObject::ResetProperty) {\n");
1468 if (needReset) {
1469 if (cdef->hasQObject) {
1470#ifndef QT_NO_DEBUG
1471 fprintf(stream: out, format: " Q_ASSERT(staticMetaObject.cast(_o));\n");
1472#endif
1473 fprintf(stream: out, format: " %s *_t = static_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData());
1474 } else {
1475 fprintf(stream: out, format: " %s *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData());
1476 }
1477 fprintf(stream: out, format: " (void)_t;\n");
1478 fprintf(stream: out, format: " switch (_id) {\n");
1479 for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) {
1480 const PropertyDef &p = cdef->propertyList.at(i: propindex);
1481 if (!p.reset.endsWith(c: ')'))
1482 continue;
1483 QByteArray prefix = "_t->";
1484 if (p.inPrivateClass.size()) {
1485 prefix += p.inPrivateClass + "->";
1486 }
1487 fprintf(stream: out, format: " case %d: %s%s; break;\n",
1488 propindex, prefix.constData(), p.reset.constData());
1489 }
1490 fprintf(stream: out, format: " default: break;\n");
1491 fprintf(stream: out, format: " }\n");
1492 }
1493 fprintf(stream: out, format: " }");
1494 fprintf(stream: out, format: "\n#endif // QT_NO_PROPERTIES");
1495 needElse = true;
1496 }
1497
1498 if (needElse)
1499 fprintf(stream: out, format: "\n");
1500
1501 if (methodList.isEmpty()) {
1502 fprintf(stream: out, format: " (void)_o;\n");
1503 if (cdef->constructorList.isEmpty() && automaticPropertyMetaTypes.isEmpty() && methodsWithAutomaticTypesHelper(methodList).isEmpty()) {
1504 fprintf(stream: out, format: " (void)_id;\n");
1505 fprintf(stream: out, format: " (void)_c;\n");
1506 }
1507 }
1508 if (!isUsed_a)
1509 fprintf(stream: out, format: " (void)_a;\n");
1510
1511 fprintf(stream: out, format: "}\n\n");
1512}
1513
1514void Generator::generateSignal(FunctionDef *def,int index)
1515{
1516 if (def->wasCloned || def->isAbstract)
1517 return;
1518 fprintf(stream: out, format: "\n// SIGNAL %d\n%s %s::%s(",
1519 index, def->type.name.constData(), cdef->qualified.constData(), def->name.constData());
1520
1521 QByteArray thisPtr = "this";
1522 const char *constQualifier = "";
1523
1524 if (def->isConst) {
1525 thisPtr = "const_cast< " + cdef->qualified + " *>(this)";
1526 constQualifier = "const";
1527 }
1528
1529 Q_ASSERT(!def->normalizedType.isEmpty());
1530 if (def->arguments.isEmpty() && def->normalizedType == "void" && !def->isPrivateSignal) {
1531 fprintf(stream: out, format: ")%s\n{\n"
1532 " QMetaObject::activate(%s, &staticMetaObject, %d, nullptr);\n"
1533 "}\n", constQualifier, thisPtr.constData(), index);
1534 return;
1535 }
1536
1537 int offset = 1;
1538 for (int j = 0; j < def->arguments.count(); ++j) {
1539 const ArgumentDef &a = def->arguments.at(i: j);
1540 if (j)
1541 fprintf(stream: out, format: ", ");
1542 fprintf(stream: out, format: "%s _t%d%s", a.type.name.constData(), offset++, a.rightType.constData());
1543 }
1544 if (def->isPrivateSignal) {
1545 if (!def->arguments.isEmpty())
1546 fprintf(stream: out, format: ", ");
1547 fprintf(stream: out, format: "QPrivateSignal _t%d", offset++);
1548 }
1549
1550 fprintf(stream: out, format: ")%s\n{\n", constQualifier);
1551 if (def->type.name.size() && def->normalizedType != "void") {
1552 QByteArray returnType = noRef(type: def->normalizedType);
1553 fprintf(stream: out, format: " %s _t0{};\n", returnType.constData());
1554 }
1555
1556 fprintf(stream: out, format: " void *_a[] = { ");
1557 if (def->normalizedType == "void") {
1558 fprintf(stream: out, format: "nullptr");
1559 } else {
1560 if (def->returnTypeIsVolatile)
1561 fprintf(stream: out, format: "const_cast<void*>(reinterpret_cast<const volatile void*>(std::addressof(_t0)))");
1562 else
1563 fprintf(stream: out, format: "const_cast<void*>(reinterpret_cast<const void*>(std::addressof(_t0)))");
1564 }
1565 int i;
1566 for (i = 1; i < offset; ++i)
1567 if (i <= def->arguments.count() && def->arguments.at(i: i - 1).type.isVolatile)
1568 fprintf(stream: out, format: ", const_cast<void*>(reinterpret_cast<const volatile void*>(std::addressof(_t%d)))", i);
1569 else
1570 fprintf(stream: out, format: ", const_cast<void*>(reinterpret_cast<const void*>(std::addressof(_t%d)))", i);
1571 fprintf(stream: out, format: " };\n");
1572 fprintf(stream: out, format: " QMetaObject::activate(%s, &staticMetaObject, %d, _a);\n", thisPtr.constData(), index);
1573 if (def->normalizedType != "void")
1574 fprintf(stream: out, format: " return _t0;\n");
1575 fprintf(stream: out, format: "}\n");
1576}
1577
1578static CborError jsonValueToCbor(CborEncoder *parent, const QJsonValue &v);
1579static CborError jsonObjectToCbor(CborEncoder *parent, const QJsonObject &o)
1580{
1581 auto it = o.constBegin();
1582 auto end = o.constEnd();
1583 CborEncoder map;
1584 cbor_encoder_create_map(encoder: parent, mapEncoder: &map, length: o.size());
1585
1586 for ( ; it != end; ++it) {
1587 QByteArray key = it.key().toUtf8();
1588 cbor_encode_text_string(encoder: &map, string: key.constData(), length: key.size());
1589 jsonValueToCbor(parent: &map, v: it.value());
1590 }
1591 return cbor_encoder_close_container(encoder: parent, containerEncoder: &map);
1592}
1593
1594static CborError jsonArrayToCbor(CborEncoder *parent, const QJsonArray &a)
1595{
1596 CborEncoder array;
1597 cbor_encoder_create_array(encoder: parent, arrayEncoder: &array, length: a.size());
1598 for (const QJsonValue &v : a)
1599 jsonValueToCbor(parent: &array, v);
1600 return cbor_encoder_close_container(encoder: parent, containerEncoder: &array);
1601}
1602
1603static CborError jsonValueToCbor(CborEncoder *parent, const QJsonValue &v)
1604{
1605 switch (v.type()) {
1606 case QJsonValue::Null:
1607 case QJsonValue::Undefined:
1608 return cbor_encode_null(encoder: parent);
1609 case QJsonValue::Bool:
1610 return cbor_encode_boolean(encoder: parent, value: v.toBool());
1611 case QJsonValue::Array:
1612 return jsonArrayToCbor(parent, a: v.toArray());
1613 case QJsonValue::Object:
1614 return jsonObjectToCbor(parent, o: v.toObject());
1615 case QJsonValue::String: {
1616 QByteArray s = v.toString().toUtf8();
1617 return cbor_encode_text_string(encoder: parent, string: s.constData(), length: s.size());
1618 }
1619 case QJsonValue::Double: {
1620 double d = v.toDouble();
1621 if (d == floor(x: d) && fabs(x: d) <= (Q_INT64_C(1) << std::numeric_limits<double>::digits))
1622 return cbor_encode_int(encoder: parent, value: qint64(d));
1623 return cbor_encode_double(encoder: parent, value: d);
1624 }
1625 }
1626 Q_UNREACHABLE();
1627 return CborUnknownError;
1628}
1629
1630void Generator::generatePluginMetaData()
1631{
1632 if (cdef->pluginData.iid.isEmpty())
1633 return;
1634
1635 fputs(s: "\nQT_PLUGIN_METADATA_SECTION\n"
1636 "static constexpr unsigned char qt_pluginMetaData[] = {\n"
1637 " 'Q', 'T', 'M', 'E', 'T', 'A', 'D', 'A', 'T', 'A', ' ', '!',\n"
1638 " // metadata version, Qt version, architectural requirements\n"
1639 " 0, QT_VERSION_MAJOR, QT_VERSION_MINOR, qPluginArchRequirements(),", stream: out);
1640
1641
1642 CborDevice dev(out);
1643 CborEncoder enc;
1644 cbor_encoder_init_writer(encoder: &enc, writer: CborDevice::callback, &dev);
1645
1646 CborEncoder map;
1647 cbor_encoder_create_map(encoder: &enc, mapEncoder: &map, length: CborIndefiniteLength);
1648
1649 dev.nextItem(comment: "\"IID\"");
1650 cbor_encode_int(encoder: &map, value: int(QtPluginMetaDataKeys::IID));
1651 cbor_encode_text_string(encoder: &map, string: cdef->pluginData.iid.constData(), length: cdef->pluginData.iid.size());
1652
1653 dev.nextItem(comment: "\"className\"");
1654 cbor_encode_int(encoder: &map, value: int(QtPluginMetaDataKeys::ClassName));
1655 cbor_encode_text_string(encoder: &map, string: cdef->classname.constData(), length: cdef->classname.size());
1656
1657 QJsonObject o = cdef->pluginData.metaData.object();
1658 if (!o.isEmpty()) {
1659 dev.nextItem(comment: "\"MetaData\"");
1660 cbor_encode_int(encoder: &map, value: int(QtPluginMetaDataKeys::MetaData));
1661 jsonObjectToCbor(parent: &map, o);
1662 }
1663
1664 if (!cdef->pluginData.uri.isEmpty()) {
1665 dev.nextItem(comment: "\"URI\"");
1666 cbor_encode_int(encoder: &map, value: int(QtPluginMetaDataKeys::URI));
1667 cbor_encode_text_string(encoder: &map, string: cdef->pluginData.uri.constData(), length: cdef->pluginData.uri.size());
1668 }
1669
1670 // Add -M args from the command line:
1671 for (auto it = cdef->pluginData.metaArgs.cbegin(), end = cdef->pluginData.metaArgs.cend(); it != end; ++it) {
1672 const QJsonArray &a = it.value();
1673 QByteArray key = it.key().toUtf8();
1674 dev.nextItem(comment: QByteArray("command-line \"" + key + "\"").constData());
1675 cbor_encode_text_string(encoder: &map, string: key.constData(), length: key.size());
1676 jsonArrayToCbor(parent: &map, a);
1677 }
1678
1679 // Close the CBOR map manually
1680 dev.nextItem();
1681 cbor_encoder_close_container(encoder: &enc, containerEncoder: &map);
1682 fputs(s: "\n};\n", stream: out);
1683
1684 // 'Use' all namespaces.
1685 int pos = cdef->qualified.indexOf(c: "::");
1686 for ( ; pos != -1 ; pos = cdef->qualified.indexOf(c: "::", from: pos + 2) )
1687 fprintf(stream: out, format: "using namespace %s;\n", cdef->qualified.left(len: pos).constData());
1688 fprintf(stream: out, format: "QT_MOC_EXPORT_PLUGIN(%s, %s)\n\n",
1689 cdef->qualified.constData(), cdef->classname.constData());
1690}
1691
1692QT_WARNING_DISABLE_GCC("-Wunused-function")
1693QT_WARNING_DISABLE_CLANG("-Wunused-function")
1694QT_WARNING_DISABLE_CLANG("-Wundefined-internal")
1695QT_WARNING_DISABLE_MSVC(4334) // '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
1696
1697#define CBOR_ENCODER_WRITER_CONTROL 1
1698#define CBOR_ENCODER_WRITE_FUNCTION CborDevice::callback
1699
1700QT_END_NAMESPACE
1701
1702#include "cborencoder.c"
1703

source code of qtbase/src/tools/moc/generator.cpp