10#include <QtCore/qmetatype.h>
11#include <QtCore/qjsondocument.h>
12#include <QtCore/qjsonobject.h>
13#include <QtCore/qjsonvalue.h>
14#include <QtCore/qjsonarray.h>
15#include <QtCore/qplugin.h>
16#include <QtCore/qstringview.h>
21#include <private/qmetaobject_p.h>
22#include <private/qplugin_p.h>
50#define RETURN_METATYPENAME_STRING(MetaTypeName, MetaTypeId, RealType) \
51 case QMetaType::MetaTypeName: return #MetaTypeName;
56#undef RETURN_METATYPENAME_STRING
63 bool requireCompleteTypes)
68 knownQObjectClasses(knownQObjectClasses),
69 knownGadgets(knownGadgets),
70 requireCompleteTypes(requireCompleteTypes)
78 if (
s.at(
i) !=
'\\' ||
i >=
s.size() - 1)
88 while (
i < startPos + 4
103 static constexpr int ColumnWidth = 72;
110 const qsizetype backSlashPos =
s.lastIndexOf(
'\\', idx + spanLen - 1);
111 if (backSlashPos >= idx) {
113 spanLen =
qBound(spanLen, backSlashPos + escapeLen - idx,
len - idx);
115 fprintf(
out,
"\n \"%.*s\"",
int(spanLen),
s.constData() + idx);
140 sum +=
int(def.arguments.size()) + 1;
144bool Generator::registerableMetaType(
const QByteArray &propertyType)
146 if (metaTypes.
contains(propertyType))
154 objectPointerType.
chop(1);
155 if (knownQObjectClasses.
contains(objectPointerType))
160#define STREAM_SMART_POINTER(SMART_POINTER) << #SMART_POINTER
162#undef STREAM_SMART_POINTER
165 for (
const QByteArray &smartPointer : smartPointers) {
168 return knownQObjectClasses.
contains(propertyType.
mid(smartPointer.size() + 1, propertyType.
size() - smartPointer.size() - 1 - 1));
172#define STREAM_1ARG_TEMPLATE(TEMPLATENAME) << #TEMPLATENAME
174#undef STREAM_1ARG_TEMPLATE
176 for (
const QByteArray &oneArgTemplateType : oneArgTemplates) {
183 - (propertyType.
at(propertyType.
size() - 2) ==
' ' ? 1 : 0 );
195 if (qualifiedName ==
name)
205 QByteArray qualifiedClassNameIdentifier = identifier;
210 qualifiedClassNameIdentifier.
replace(
"::",
"SCOPE");
215 qualifiedClassNameIdentifier =
"CLASS" + qualifiedClassNameIdentifier +
"ENDCLASS";
216 return qualifiedClassNameIdentifier;
221 bool isQObject = (cdef->
classname ==
"QObject");
231 def.enumName = def.name;
245 registerClassInfoStrings();
247 registerFunctionStrings(cdef->
slotList);
251 registerPropertyStrings();
252 registerEnumStrings();
254 const bool hasStaticMetaCall =
261 fprintf(out,
"namespace {\n");
267 fprintf(out,
"\n#ifdef QT_MOC_HAS_STRINGDATA\n"
268 "struct qt_meta_stringdata_%s_t {};\n"
269 "constexpr auto qt_meta_stringdata_%s = QtMocHelpers::stringData(",
280 fprintf(out,
"\n);\n"
281 "#else // !QT_MOC_HAS_STRINGDATA\n");
282 fprintf(out,
"#error \"qtmochelpers.h not found or too old.\"\n");
283 fprintf(out,
"#endif // !QT_MOC_HAS_STRINGDATA\n");
284 fprintf(out,
"} // unnamed namespace\n\n");
291 fprintf(out,
"Q_CONSTINIT static const uint qt_meta_data_%s[] = {\n", qualifiedClassNameIdentifier.
constData());
292 fprintf(out,
"\n // content:\n");
294 fprintf(out,
" %4d, // classname\n", stridx(cdef->
qualified));
301 parser->
error(
"internal limit exceeded: the total number of member functions"
302 " (including signals and slots) is too big.");
305 fprintf(out,
" %4" PRIdQSIZETYPE ", %4d, // methods\n", methodCount, methodCount ?
index : 0);
308 index += methodCount;
309 int paramsIndex =
index;
314 index += totalParameterCount * 2
322 int enumsIndex =
index;
326 fprintf(out,
" %4d, %4d, // constructors\n", isConstructible ?
int(cdef->
constructorList.
size()) : 0,
327 isConstructible ?
index : 0);
335 fprintf(out,
" %4d, // flags\n",
flags);
336 fprintf(out,
" %4d, // signalCount\n",
int(cdef->
signalList.
size()));
342 generateClassInfos();
348 || propEnumCount >= std::numeric_limits<int>::max()) {
349 parser->
error(
"internal limit exceeded: number of property and enum metatypes is too big.");
351 int initialMetaTypeOffset = int(propEnumCount);
361 generateFunctions(cdef->
slotList,
"slot",
MethodSlot, paramsIndex, initialMetaTypeOffset);
372 generateFunctionRevisions(cdef->
signalList,
"signal");
373 generateFunctionRevisions(cdef->
slotList,
"slot");
374 generateFunctionRevisions(cdef->
methodList,
"method");
380 generateFunctionParameters(cdef->
signalList,
"signal");
381 generateFunctionParameters(cdef->
slotList,
"slot");
382 generateFunctionParameters(cdef->
methodList,
"method");
389 generateProperties();
394 generateEnums(enumsIndex);
405 fprintf(out,
"\n 0 // eod\n};\n\n");
412 knownExtraMetaObject.
unite(knownQObjectClasses);
418 if (
p.type.contains(
'*') ||
p.type.contains(
'<') ||
p.type.contains(
'>'))
433 thisScope = thisScope.
left(
s);
434 QByteArray currentScope = thisScope.
isEmpty() ? unqualifiedScope : thisScope +
"::" + unqualifiedScope;
435 scopeIt = knownExtraMetaObject.
constFind(currentScope);
436 }
while (!thisScope.
isEmpty() && scopeIt == knownExtraMetaObject.
constEnd());
438 if (scopeIt == knownExtraMetaObject.
constEnd())
471 fprintf(out,
"Q_CONSTINIT static const QMetaObject::SuperData qt_meta_extradata_%s[] = {\n",
472 qualifiedClassNameIdentifier.
constData());
474 fprintf(out,
" QMetaObject::SuperData::link<%s::staticMetaObject>(),\n",
ba.
constData());
476 fprintf(out,
" nullptr\n};\n\n");
482 fprintf(out,
"Q_CONSTINIT const QMetaObject %s::staticMetaObject = { {\n",
486 fprintf(out,
" nullptr,\n");
488 fprintf(out,
" QMetaObject::SuperData::link<%s::staticMetaObject>(),\n", purestSuperClass.
constData());
490 fprintf(out,
" QtPrivate::MetaObjectForType<%s>::value,\n", purestSuperClass.
constData());
492 fprintf(out,
" nullptr,\n");
493 fprintf(out,
" qt_meta_stringdata_%s.offsetsAndSizes,\n"
494 " qt_meta_data_%s,\n", qualifiedClassNameIdentifier.
constData(),
495 qualifiedClassNameIdentifier.
constData());
496 if (hasStaticMetaCall)
497 fprintf(out,
" qt_static_metacall,\n");
499 fprintf(out,
" nullptr,\n");
502 fprintf(out,
" nullptr,\n");
504 fprintf(out,
" qt_meta_extradata_%s,\n", qualifiedClassNameIdentifier.
constData());
506 const char *comma =
"";
509 const char *forceCompleteType = forceComplete ?
", std::true_type>" :
", std::false_type>";
510 if (requireCompleteness)
512 return "QtPrivate::TypeAndForceComplete<" %
type % forceCompleteType;
514 if (!requireCompleteness) {
515 fprintf(out,
" qt_incomplete_metaTypeArray<qt_meta_stringdata_%s_t", qualifiedClassNameIdentifier.
constData());
518 fprintf(out,
" qt_metaTypeArray<");
522 fprintf(out,
"%s\n // property '%s'\n %s",
523 comma,
p.name.constData(), stringForType(
p.type,
true).constData());
529 fprintf(out,
"%s\n // enum '%s'\n %s",
530 comma,
e.name.constData(), stringForType(
e.qualifiedType(cdef),
true).constData());
536 fprintf(out,
"%s\n // Q_OBJECT / Q_GADGET\n %s",
537 comma, stringForType(ownType,
true).constData());
545 fprintf(out,
",\n // method '%s'\n %s",
546 fdef.name.constData(), stringForType(fdef.type.name,
false).constData());
547 for (
const auto &
argument: fdef.arguments)
548 fprintf(out,
",\n %s", stringForType(
argument.type.name,
false).constData());
554 if (fdef.arguments.isEmpty())
557 fprintf(out,
"%s\n // constructor '%s'", comma, fdef.name.constData());
559 for (
const auto &
argument: fdef.arguments) {
560 fprintf(out,
"%s\n %s", comma,
561 stringForType(
argument.type.name,
false).constData());
565 fprintf(out,
"\n >,\n");
567 fprintf(out,
" nullptr\n} };\n\n");
572 if (hasStaticMetaCall)
573 generateStaticMetacall();
578 fprintf(out,
"\nconst QMetaObject *%s::metaObject() const\n{\n return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;\n}\n",
585 fprintf(out,
"\nvoid *%s::qt_metacast(const char *_clname)\n{\n", cdef->
qualified.
constData());
586 fprintf(out,
" if (!_clname) return nullptr;\n");
587 fprintf(out,
" if (!strcmp(_clname, qt_meta_stringdata_%s.stringdata0))\n"
588 " return static_cast<void*>(this);\n",
589 qualifiedClassNameIdentifier.
constData());
599 const char *cname =
className.constData();
600 fprintf(out,
" if (!strcmp(_clname, \"%s\"))\n return static_cast< %s*>(this);\n",
607 fprintf(out,
" if (!strcmp(_clname, %s))\n return ", iface.at(
j).interfaceId.constData());
609 fprintf(out,
"static_cast< %s*>(", iface.at(k).className.constData());
610 fprintf(out,
"this%s;\n",
QByteArray(
j + 1,
')').constData());
613 if (!purestSuperClass.
isEmpty() && !isQObject) {
615 fprintf(out,
" return %s::qt_metacast(_clname);\n", superClass.
constData());
617 fprintf(out,
" return nullptr;\n");
629 for (
int signalindex = 0; signalindex < int(cdef->
signalList.
size()); ++signalindex)
630 generateSignal(&cdef->
signalList.
at(signalindex), signalindex);
635 generatePluginMetaData();
641 fprintf(out,
"// If you get a compile error in this function it can be because either\n");
642 fprintf(out,
"// a) You are using a NOTIFY signal that does not exist. Fix it.\n");
643 fprintf(out,
"// 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");
644 fprintf(out,
"[[maybe_unused]] static void checkNotifySignalValidity_%s(%s *t) {\n", qualifiedClassNameIdentifier.
constData(), cdef->
qualified.
constData());
646 fprintf(out,
" t->%s();\n", nonClassSignal.constData());
652void Generator::registerClassInfoStrings()
660void Generator::generateClassInfos()
665 fprintf(out,
"\n // classinfo: key, value\n");
668 fprintf(out,
" %4d, %4d,\n", stridx(
c.
name), stridx(
c.
value));
676 strreg(
f.normalizedType);
681 strreg(
a.normalizedType);
694 int ¶msIndex,
int &initialMetatypeOffset)
698 fprintf(out,
"\n // %ss: name, argc, parameters, tag, flags, initial metatype offsets\n", functype);
705 comment.
append(
"Private");
711 comment.
append(
"Protected");
715 comment.
append(
" | MethodCompatibility");
719 comment.
append(
" | MethodCloned");
721 if (
f.isScriptable) {
723 comment.
append(
" | isScriptable");
725 if (
f.revision > 0) {
727 comment.
append(
" | MethodRevisioned");
732 comment.
append(
" | MethodIsConst ");
735 const int argc = int(
f.arguments.size());
736 fprintf(out,
" %4d, %4d, %4d, %4d, 0x%02x, %4d /* %s */,\n",
737 stridx(
f.name), argc, paramsIndex, stridx(
f.tag),
flags, initialMetatypeOffset, comment.
constData());
739 paramsIndex += 1 + argc * 2;
741 initialMetatypeOffset += (
f.isConstructor ? 0 : 1) + argc;
748 fprintf(out,
"\n // %ss: revision\n", functype);
750 fprintf(out,
" %4d,\n",
f.revision);
757 fprintf(out,
"\n // %ss: parameters\n", functype);
762 const bool allowEmptyName =
f.isConstructor;
763 generateTypeInfo(
f.normalizedType, allowEmptyName);
767 generateTypeInfo(
arg.normalizedType, allowEmptyName);
773 fprintf(out,
" %4d,", stridx(
arg.
name));
784 const char *valueString;
787 valueString =
"QReal";
793 fprintf(out,
"QMetaType::%s", valueString);
796 fprintf(out,
"%4d",
type);
804void Generator::registerPropertyStrings()
813void Generator::generateProperties()
820 fprintf(out,
"\n // properties: name, type, flags\n");
825 if (!
p.member.isEmpty() && !
p.constant)
827 if (!
p.read.isEmpty() || !
p.member.isEmpty())
829 if (!
p.write.isEmpty()) {
835 if (!
p.reset.isEmpty())
838 if (
p.designable !=
"false")
841 if (
p.scriptable !=
"false")
844 if (
p.stored !=
"false")
847 if (
p.user !=
"false")
857 if (!
p.bind.isEmpty())
860 fprintf(out,
" %4d, ", stridx(
p.name));
861 generateTypeInfo(
p.type);
862 int notifyId =
p.notifyId;
863 if (
p.notifyId < -1) {
865 const int indexInStrings = int(
strings.indexOf(
p.notify));
868 fprintf(out,
", 0x%.8x, uint(%d), %d,\n",
flags, notifyId,
p.revision);
872void Generator::registerEnumStrings()
874 for (
const EnumDef &
e :
std::as_const(cdef->enumList)) {
876 if (!
e.enumName.isNull())
883void Generator::generateEnums(
int index)
888 fprintf(out,
"\n // enums: name, alias, flags, count, data\n");
898 fprintf(out,
" %4d, %4d, 0x%.1x, %4d, %4d,\n",
900 e.enumName.isNull() ? stridx(
e.name) : stridx(
e.enumName),
904 index +=
e.values.size() * 2;
907 fprintf(out,
"\n // enum data: key, value\n");
908 for (
const EnumDef &
e :
std::as_const(cdef->enumList)) {
912 code +=
"::" + (
e.enumName.isNull() ?
e.name :
e.enumName);
914 fprintf(out,
" %4d, uint(%s),\n",
920void Generator::generateMetacall()
922 bool isQObject = (cdef->
classname ==
"QObject");
924 fprintf(out,
"\nint %s::qt_metacall(QMetaObject::Call _c, int _id, void **_a)\n{\n",
927 if (!purestSuperClass.
isEmpty() && !isQObject) {
929 fprintf(out,
" _id = %s::qt_metacall(_c, _id, _a);\n", superClass.
constData());
933 bool needElse =
false;
943 fprintf(out,
" if (_id < 0)\n return _id;\n");
948 if (methodList.
size()) {
950 fprintf(out,
"if (_c == QMetaObject::InvokeMetaMethod) {\n");
951 fprintf(out,
" if (_id < %d)\n",
int(methodList.
size()));
952 fprintf(out,
" qt_static_metacall(this, _c, _id, _a);\n");
953 fprintf(out,
" _id -= %d;\n }",
int(methodList.
size()));
955 fprintf(out,
" else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {\n");
956 fprintf(out,
" if (_id < %d)\n",
int(methodList.
size()));
958 if (methodsWithAutomaticTypesHelper(methodList).isEmpty())
959 fprintf(out,
" *reinterpret_cast<QMetaType *>(_a[0]) = QMetaType();\n");
961 fprintf(out,
" qt_static_metacall(this, _c, _id, _a);\n");
962 fprintf(out,
" _id -= %d;\n }",
int(methodList.
size()));
968 fprintf(out,
"else ");
970 "if (_c == QMetaObject::ReadProperty || _c == QMetaObject::WriteProperty\n"
971 " || _c == QMetaObject::ResetProperty || _c == QMetaObject::BindableProperty\n"
972 " || _c == QMetaObject::RegisterPropertyMetaType) {\n"
973 " qt_static_metacall(this, _c, _id, _a);\n"
978 fprintf(out,
"return _id;\n}\n");
988 if (registerableMetaType(propertyType) && !
isBuiltinType(propertyType))
989 automaticPropertyMetaTypes.
insert(propertyType,
i);
991 return automaticPropertyMetaTypes;
998 for (
int i = 0;
i < methodList.
size(); ++
i) {
1000 for (
int j = 0;
j <
f.arguments.size(); ++
j) {
1002 if (registerableMetaType(argType) && !
isBuiltinType(argType))
1003 methodsWithAutomaticTypes[
i].
insert(argType,
j);
1006 return methodsWithAutomaticTypes;
1009void Generator::generateStaticMetacall()
1011 fprintf(out,
"void %s::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)\n{\n",
1014 bool needElse =
false;
1015 bool isUsed_a =
false;
1017 const auto generateCtorArguments = [&](
int ctorindex) {
1022 const auto begin =
f.arguments.cbegin();
1023 const auto end =
f.arguments.cend();
1028 fprintf(out,
"(*reinterpret_cast<%s>(_a[%d]))",
1029 a.typeNameForCast.constData(),
offset++);
1034 fprintf(out,
" if (_c == QMetaObject::CreateInstance) {\n");
1035 fprintf(out,
" switch (_id) {\n");
1037 for (
int ctorindex = 0; ctorindex < ctorend; ++ctorindex) {
1038 fprintf(out,
" case %d: { %s *_r = new %s(", ctorindex,
1040 generateCtorArguments(ctorindex);
1041 fprintf(out,
");\n");
1042 fprintf(out,
" if (_a[0]) *reinterpret_cast<%s**>(_a[0]) = _r; } break;\n",
1045 fprintf(out,
" default: break;\n");
1046 fprintf(out,
" }\n");
1047 fprintf(out,
" } else if (_c == QMetaObject::ConstructInPlace) {\n");
1048 fprintf(out,
" switch (_id) {\n");
1049 for (
int ctorindex = 0; ctorindex < ctorend; ++ctorindex) {
1050 fprintf(out,
" case %d: { new (_a[0]) %s(",
1052 generateCtorArguments(ctorindex);
1053 fprintf(out,
"); } break;\n");
1055 fprintf(out,
" default: break;\n");
1056 fprintf(out,
" }\n");
1069 fprintf(out,
" else ");
1072 fprintf(out,
"if (_c == QMetaObject::InvokeMetaMethod) {\n");
1075 fprintf(out,
" Q_ASSERT(staticMetaObject.cast(_o));\n");
1079 fprintf(out,
" auto *_t = reinterpret_cast<%s *>(_o);\n", cdef->
classname.
constData());
1081 fprintf(out,
" (void)_t;\n");
1082 fprintf(out,
" switch (_id) {\n");
1083 for (
int methodindex = 0; methodindex < methodList.
size(); ++methodindex) {
1086 fprintf(out,
" case %d: ", methodindex);
1087 if (
f.normalizedType !=
"void")
1089 fprintf(out,
"_t->");
1090 if (
f.inPrivateClass.size())
1091 fprintf(out,
"%s->",
f.inPrivateClass.constData());
1092 fprintf(out,
"%s(",
f.name.constData());
1096 fprintf(out,
"QMethodRawArguments{ _a }");
1098 const auto begin =
f.arguments.cbegin();
1099 const auto end =
f.arguments.cend();
1104 fprintf(out,
"(*reinterpret_cast< %s>(_a[%d]))",
a.typeNameForCast.constData(),
offset++);
1107 if (
f.isPrivateSignal) {
1108 if (!
f.arguments.isEmpty())
1110 fprintf(out,
"%s",
"QPrivateSignal()");
1114 if (
f.normalizedType !=
"void") {
1115 fprintf(out,
"\n if (_a[0]) *reinterpret_cast< %s*>(_a[0]) = std::move(_r); } ",
1119 fprintf(out,
" break;\n");
1121 fprintf(out,
" default: ;\n");
1122 fprintf(out,
" }\n");
1128 if (!methodsWithAutomaticTypes.
isEmpty()) {
1129 fprintf(out,
" else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {\n");
1130 fprintf(out,
" switch (_id) {\n");
1131 fprintf(out,
" default: *reinterpret_cast<QMetaType *>(_a[0]) = QMetaType(); break;\n");
1135 fprintf(out,
" case %d:\n",
it.key());
1136 fprintf(out,
" switch (*reinterpret_cast<int*>(_a[1])) {\n");
1137 fprintf(out,
" default: *reinterpret_cast<QMetaType *>(_a[0]) = QMetaType(); break;\n");
1139 const auto jend =
it->
end();
1140 while (jt != jend) {
1141 fprintf(out,
" case %d:\n", jt.value());
1144 if (jt == jend || jt.key() != lastKey)
1145 fprintf(out,
" *reinterpret_cast<QMetaType *>(_a[0]) = QMetaType::fromType< %s >(); break;\n", lastKey.
constData());
1147 fprintf(out,
" }\n");
1148 fprintf(out,
" break;\n");
1150 fprintf(out,
" }\n");
1158 fprintf(out,
" else if (_c == QMetaObject::IndexOfMethod) {\n");
1159 fprintf(out,
" int *result = reinterpret_cast<int *>(_a[0]);\n");
1160 bool anythingUsed =
false;
1161 for (
int methodindex = 0; methodindex < int(cdef->
signalList.
size()); ++methodindex) {
1163 if (
f.wasCloned || !
f.inPrivateClass.isEmpty() ||
f.isStatic)
1165 anythingUsed =
true;
1166 fprintf(out,
" {\n");
1167 fprintf(out,
" using _t = %s (%s::*)(",
f.type.rawName.constData() , cdef->
classname.
constData());
1169 const auto begin =
f.arguments.cbegin();
1170 const auto end =
f.arguments.cend();
1177 if (
f.isPrivateSignal) {
1178 if (!
f.arguments.isEmpty())
1180 fprintf(out,
"%s",
"QPrivateSignal");
1183 fprintf(out,
") const;\n");
1185 fprintf(out,
");\n");
1186 fprintf(out,
" if (_t _q_method = &%s::%s; *reinterpret_cast<_t *>(_a[1]) == _q_method) {\n",
1188 fprintf(out,
" *result = %d;\n", methodindex);
1189 fprintf(out,
" return;\n");
1190 fprintf(out,
" }\n }\n");
1193 fprintf(out,
" (void)result;\n");
1200 if (!automaticPropertyMetaTypes.
isEmpty()) {
1202 fprintf(out,
" else ");
1205 fprintf(out,
"if (_c == QMetaObject::RegisterPropertyMetaType) {\n");
1206 fprintf(out,
" switch (_id) {\n");
1207 fprintf(out,
" default: *reinterpret_cast<int*>(_a[0]) = -1; break;\n");
1208 auto it = automaticPropertyMetaTypes.
begin();
1209 const auto end = automaticPropertyMetaTypes.
end();
1211 fprintf(out,
" case %d:\n",
it.value());
1214 if (
it ==
end ||
it.key() != lastKey)
1215 fprintf(out,
" *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< %s >(); break;\n", lastKey.
constData());
1217 fprintf(out,
" }\n");
1218 fprintf(out,
" } ");
1224 bool needGet =
false;
1225 bool needTempVarForGet =
false;
1226 bool needSet =
false;
1227 bool needReset =
false;
1228 bool hasBindableProperties =
false;
1230 needGet |= !
p.read.isEmpty() || !
p.member.isEmpty();
1231 if (!
p.read.isEmpty() || !
p.member.isEmpty())
1235 needSet |= !
p.write.isEmpty() || (!
p.member.isEmpty() && !
p.constant);
1236 needReset |= !
p.reset.isEmpty();
1237 hasBindableProperties |= !
p.bind.isEmpty();
1240 fprintf(out,
" else ");
1241 fprintf(out,
"if (_c == QMetaObject::ReadProperty) {\n");
1243 auto setupMemberAccess = [
this]() {
1246 fprintf(out,
" Q_ASSERT(staticMetaObject.cast(_o));\n");
1250 fprintf(out,
" auto *_t = reinterpret_cast<%s *>(_o);\n", cdef->
classname.
constData());
1252 fprintf(out,
" (void)_t;\n");
1256 setupMemberAccess();
1257 if (needTempVarForGet)
1258 fprintf(out,
" void *_v = _a[0];\n");
1259 fprintf(out,
" switch (_id) {\n");
1260 for (
int propindex = 0; propindex < int(cdef->
propertyList.
size()); ++propindex) {
1262 if (
p.read.isEmpty() &&
p.member.isEmpty())
1265 if (
p.inPrivateClass.size()) {
1266 prefix +=
p.inPrivateClass +
"->";
1270 fprintf(out,
" case %d: _a[0] = const_cast<void*>(reinterpret_cast<const void*>(%s%s())); break;\n",
1271 propindex, prefix.
constData(),
p.read.constData());
1273 fprintf(out,
" case %d: _a[0] = const_cast<void*>(reinterpret_cast<const void*>(&%s%s())); break;\n",
1274 propindex, prefix.
constData(),
p.read.constData());
1276 fprintf(out,
" case %d: *reinterpret_cast<int*>(_v) = QFlag(%s%s()); break;\n",
1277 propindex, prefix.
constData(),
p.read.constData());
1278 else if (
p.read ==
"default")
1279 fprintf(out,
" case %d: *reinterpret_cast< %s*>(_v) = %s%s().value(); break;\n",
1280 propindex,
p.type.constData(), prefix.
constData(),
p.bind.constData());
1281 else if (!
p.read.isEmpty())
1282 fprintf(out,
" case %d: *reinterpret_cast< %s*>(_v) = %s%s(); break;\n",
1283 propindex,
p.type.constData(), prefix.
constData(),
p.read.constData());
1285 fprintf(out,
" case %d: *reinterpret_cast< %s*>(_v) = %s%s; break;\n",
1286 propindex,
p.type.constData(), prefix.
constData(),
p.member.constData());
1288 fprintf(out,
" default: break;\n");
1289 fprintf(out,
" }\n");
1294 fprintf(out,
" else ");
1295 fprintf(out,
"if (_c == QMetaObject::WriteProperty) {\n");
1298 setupMemberAccess();
1299 fprintf(out,
" void *_v = _a[0];\n");
1300 fprintf(out,
" switch (_id) {\n");
1301 for (
int propindex = 0; propindex < int(cdef->
propertyList.
size()); ++propindex) {
1305 if (
p.write.isEmpty() &&
p.member.isEmpty())
1308 if (
p.inPrivateClass.size()) {
1309 prefix +=
p.inPrivateClass +
"->";
1312 fprintf(out,
" case %d: %s%s(QFlag(*reinterpret_cast<int*>(_v))); break;\n",
1313 propindex, prefix.
constData(),
p.write.constData());
1314 }
else if (
p.write ==
"default") {
1315 fprintf(out,
" case %d: {\n", propindex);
1316 fprintf(out,
" %s%s().setValue(*reinterpret_cast< %s*>(_v));\n",
1317 prefix.
constData(),
p.bind.constData(),
p.type.constData());
1318 fprintf(out,
" break;\n");
1319 fprintf(out,
" }\n");
1320 }
else if (!
p.write.isEmpty()) {
1321 fprintf(out,
" case %d: %s%s(*reinterpret_cast< %s*>(_v)); break;\n",
1322 propindex, prefix.
constData(),
p.write.constData(),
p.type.constData());
1324 fprintf(out,
" case %d:\n", propindex);
1325 fprintf(out,
" if (%s%s != *reinterpret_cast< %s*>(_v)) {\n",
1326 prefix.
constData(),
p.member.constData(),
p.type.constData());
1327 fprintf(out,
" %s%s = *reinterpret_cast< %s*>(_v);\n",
1328 prefix.
constData(),
p.member.constData(),
p.type.constData());
1329 if (!
p.notify.isEmpty() &&
p.notifyId > -1) {
1331 if (
f.arguments.size() == 0)
1332 fprintf(out,
" Q_EMIT _t->%s();\n",
p.notify.constData());
1333 else if (
f.arguments.size() == 1 &&
f.arguments.at(0).normalizedType ==
p.type)
1334 fprintf(out,
" Q_EMIT _t->%s(%s%s);\n",
1335 p.notify.constData(), prefix.
constData(),
p.member.constData());
1336 }
else if (!
p.notify.isEmpty() &&
p.notifyId < -1) {
1337 fprintf(out,
" Q_EMIT _t->%s();\n",
p.notify.constData());
1339 fprintf(out,
" }\n");
1340 fprintf(out,
" break;\n");
1343 fprintf(out,
" default: break;\n");
1344 fprintf(out,
" }\n");
1349 fprintf(out,
" else ");
1350 fprintf(out,
"if (_c == QMetaObject::ResetProperty) {\n");
1352 setupMemberAccess();
1353 fprintf(out,
" switch (_id) {\n");
1354 for (
int propindex = 0; propindex < int(cdef->
propertyList.
size()); ++propindex) {
1356 if (
p.reset.isEmpty())
1359 if (
p.inPrivateClass.size()) {
1360 prefix +=
p.inPrivateClass +
"->";
1362 fprintf(out,
" case %d: %s%s(); break;\n",
1363 propindex, prefix.
constData(),
p.reset.constData());
1365 fprintf(out,
" default: break;\n");
1366 fprintf(out,
" }\n");
1370 fprintf(out,
" else ");
1371 fprintf(out,
"if (_c == QMetaObject::BindableProperty) {\n");
1372 if (hasBindableProperties) {
1373 setupMemberAccess();
1374 fprintf(out,
" switch (_id) {\n");
1375 for (
int propindex = 0; propindex < int(cdef->
propertyList.
size()); ++propindex) {
1377 if (
p.bind.isEmpty())
1380 if (
p.inPrivateClass.size()) {
1381 prefix +=
p.inPrivateClass +
"->";
1384 " case %d: *static_cast<QUntypedBindable *>(_a[0]) = %s%s(); "
1386 propindex, prefix.
constData(),
p.bind.constData());
1388 fprintf(out,
" default: break;\n");
1389 fprintf(out,
" }\n");
1399 fprintf(out,
" (void)_o;\n");
1401 fprintf(out,
" (void)_id;\n");
1402 fprintf(out,
" (void)_c;\n");
1406 fprintf(out,
" (void)_a;\n");
1408 fprintf(out,
"}\n");
1415 fprintf(out,
"\n// SIGNAL %d\n%s %s::%s(",
1419 const char *constQualifier =
"";
1422 thisPtr =
"const_cast< " + cdef->
qualified +
" *>(this)";
1423 constQualifier =
"const";
1428 fprintf(out,
")%s\n{\n"
1429 " QMetaObject::activate(%s, &staticMetaObject, %d, nullptr);\n"
1441 if (
a.type.name.size())
1442 fputs(
a.type.name.constData(), out);
1443 fprintf(out,
" _t%d",
offset++);
1444 if (
a.rightType.size())
1445 fputs(
a.rightType.constData(), out);
1450 fprintf(out,
"QPrivateSignal _t%d",
offset++);
1453 fprintf(out,
")%s\n{\n", constQualifier);
1456 fprintf(out,
" %s _t0{};\n", returnType.
constData());
1459 fprintf(out,
" void *_a[] = { ");
1461 fprintf(out,
"nullptr");
1464 fprintf(out,
"const_cast<void*>(reinterpret_cast<const volatile void*>(std::addressof(_t0)))");
1466 fprintf(out,
"const_cast<void*>(reinterpret_cast<const void*>(std::addressof(_t0)))");
1471 fprintf(out,
", const_cast<void*>(reinterpret_cast<const volatile void*>(std::addressof(_t%d)))",
i);
1473 fprintf(out,
", const_cast<void*>(reinterpret_cast<const void*>(std::addressof(_t%d)))",
i);
1474 fprintf(out,
" };\n");
1475 fprintf(out,
" QMetaObject::activate(%s, &staticMetaObject, %d, _a);\n", thisPtr.
constData(),
index);
1477 fprintf(out,
" return _t0;\n");
1478 fprintf(out,
"}\n");
1484 auto it =
o.constBegin();
1485 auto end =
o.constEnd();
1487 cbor_encoder_create_map(
parent, &
map,
o.size());
1494 return cbor_encoder_close_container(
parent, &
map);
1503 return cbor_encoder_close_container(
parent, &
array);
1511 return cbor_encode_null(
parent);
1513 return cbor_encode_boolean(
parent,
v.toBool());
1520 return cbor_encode_text_string(
parent,
s.constData(),
s.size());
1523 double d =
v.toDouble();
1524 if (
d == floor(
d) && fabs(
d) <= (
Q_INT64_C(1) << std::numeric_limits<double>::digits))
1526 return cbor_encode_double(
parent,
d);
1529 Q_UNREACHABLE_RETURN(CborUnknownError);
1532void Generator::generatePluginMetaData()
1537 auto outputCborData = [
this]() {
1543 cbor_encoder_create_map(&enc, &
map, CborIndefiniteLength);
1545 dev.nextItem(
"\"IID\"");
1549 dev.nextItem(
"\"className\"");
1555 dev.nextItem(
"\"MetaData\"");
1561 dev.nextItem(
"\"URI\"");
1577 cbor_encoder_close_container(&enc, &
map);
1585 fputs(
"\n#ifdef QT_MOC_EXPORT_PLUGIN_V2", out);
1588 fprintf(out,
"\nstatic constexpr unsigned char qt_pluginMetaDataV2_%s[] = {",
1591 fprintf(out,
"\n};\nQT_MOC_EXPORT_PLUGIN_V2(%s, %s, qt_pluginMetaDataV2_%s)\n",
1595 fprintf(out,
"#else\nQT_PLUGIN_METADATA_SECTION\n"
1596 "Q_CONSTINIT static constexpr unsigned char qt_pluginMetaData_%s[] = {\n"
1597 " 'Q', 'T', 'M', 'E', 'T', 'A', 'D', 'A', 'T', 'A', ' ', '!',\n"
1598 " // metadata version, Qt version, architectural requirements\n"
1599 " 0, QT_VERSION_MAJOR, QT_VERSION_MINOR, qPluginArchRequirements(),",
1602 fprintf(out,
"\n};\nQT_MOC_EXPORT_PLUGIN(%s, %s)\n"
1603 "#endif // QT_MOC_EXPORT_PLUGIN_V2\n",
1614#define CBOR_ENCODER_WRITER_CONTROL 1
1615#define CBOR_ENCODER_WRITE_FUNCTION CborDevice::callback
1619#include "cborencoder.c"
static CborError callback(void *self, const void *ptr, size_t len, CborEncoderAppendType t)
Generator(Moc *moc, ClassDef *classDef, const QList< QByteArray > &metaTypes, const QHash< QByteArray, QByteArray > &knownQObjectClasses, const QHash< QByteArray, QByteArray > &knownGadgets, FILE *outfile=nullptr, bool requireCompleteTypes=false)
Q_NORETURN void error(const Symbol &symbol)
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
bool endsWith(char c) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
qsizetype indexOf(char c, qsizetype from=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void chop(qsizetype n)
Removes n bytes from the end of the byte array.
bool startsWith(QByteArrayView bv) const
char at(qsizetype i) const
Returns the byte at index position i in the byte array.
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
QByteArray sliced(qsizetype pos) const
QByteArray left(qsizetype len) const
Returns a byte array that contains the first len bytes of this byte array.
qsizetype lastIndexOf(char c, qsizetype from=-1) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray mid(qsizetype index, qsizetype len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos.
QByteArray & replace(qsizetype index, qsizetype len, const char *s, qsizetype alen)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
\inmodule QtCore\reentrant
QJsonObject object() const
Returns the QJsonObject contained in the document.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
qsizetype size() const noexcept
bool isEmpty() const noexcept
bool empty() const noexcept
const_reference at(qsizetype i) const noexcept
const T & constFirst() const noexcept
const_iterator cend() const noexcept
const_iterator cbegin() const noexcept
iterator insert(const Key &key, const T &value)
T value(const Key &key, const T &defaultValue=T()) const
bool contains(const Key &key) const
const_iterator cend() const
const_iterator cbegin() const
const_iterator constBegin() const
key_iterator keyBegin() const
const_iterator constEnd() const
key_iterator keyEnd() const
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
QMultiHash & unite(const QMultiHash &other)
const_iterator constFind(const Key &key) const noexcept
iterator insert(const Key &key, const T &value)
const QChar * constData() const
Returns a pointer to the data stored in the QString.
QMap< QString, QString > map
[6]
QSet< QString >::iterator it
QList< QVariant > arguments
static QByteArray generateQualifiedClassNameIdentifier(const QByteArray &identifier)
static CborError jsonValueToCbor(CborEncoder *parent, const QJsonValue &v)
static bool qualifiedNameEquals(const QByteArray &qualifiedName, const QByteArray &name)
uint nameToBuiltinType(const QByteArray &name)
static int aggregateParameterCount(const QList< FunctionDef > &list)
#define STREAM_1ARG_TEMPLATE(TEMPLATENAME)
static CborError jsonArrayToCbor(CborEncoder *parent, const QJsonArray &a)
bool isBuiltinType(const QByteArray &type)
static const char * metaTypeEnumValueString(int type)
static void printStringWithIndentation(FILE *out, const QByteArray &s)
#define STREAM_SMART_POINTER(SMART_POINTER)
static qsizetype lengthOfEscapeSequence(const QByteArray &s, qsizetype i)
static CborError jsonObjectToCbor(CborEncoder *parent, const QJsonObject &o)
#define RETURN_METATYPENAME_STRING(MetaTypeName, MetaTypeId, RealType)
QByteArray noRef(const QByteArray &type)
Combined button and popup list for selecting options.
constexpr bool isOctalDigit(char32_t c) noexcept
constexpr bool isHexDigit(char32_t c) noexcept
#define QT_WARNING_DISABLE_MSVC(number)
#define QT_WARNING_DISABLE_GCC(text)
#define QT_WARNING_DISABLE_CLANG(text)
static QString moc(const QString &name)
static QString templateArg(const QByteArray &arg)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qBound(const T &min, const T &val, const T &max)
std::enable_if_t< std::is_unsigned_v< T >, bool > qAddOverflow(T v1, T v2, T *r)
GLenum GLsizei GLsizei GLint * values
[15]
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei const GLchar ** strings
[1]
GLenum GLuint GLintptr offset
#define Q_ASSERT_X(cond, x, msg)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
const char className[16]
[1]
QTextStream out(stdout)
[7]
QMap< QByteArray, QByteArray > flagAliases
QMap< QByteArray, bool > enumDeclarations
QList< ClassInfoDef > classInfoList
QList< EnumDef > enumList
QMap< QString, QJsonArray > metaArgs
QList< QList< Interface > > interfaceList
QList< FunctionDef > methodList
QList< PropertyDef > propertyList
QList< FunctionDef > constructorList
bool requireCompleteMethodTypes
QList< QPair< QByteArray, FunctionDef::Access > > superclassList
QList< FunctionDef > slotList
QList< FunctionDef > signalList
struct ClassDef::PluginData pluginData
QList< QByteArray > nonClassSignalList
QByteArray normalizedType
QList< ArgumentDef > arguments
bool returnTypeIsVolatile
bool contains(const AT &t) const noexcept
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent