moc: port from pair<> to a struct SuperClass
... with properly-named members. This is in preparation of adding a new member in order to fix QTBUG-101141 (namespaced base classes). Pick-to: 6.6 6.5 Task-number: QTBUG-101141 Change-Id: I2309e425ac94ad275b54a898fd33a2891e5d1453 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit cbb4aea2132fc59cd1086ba42cc221d12b5ce9e8) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
debeb8878d
commit
3092406d79
@ -70,7 +70,7 @@ QT_FOR_EACH_STATIC_TYPE(RETURN_METATYPENAME_STRING)
|
|||||||
requireCompleteTypes(requireCompleteTypes)
|
requireCompleteTypes(requireCompleteTypes)
|
||||||
{
|
{
|
||||||
if (cdef->superclassList.size())
|
if (cdef->superclassList.size())
|
||||||
purestSuperClass = cdef->superclassList.constFirst().first;
|
purestSuperClass = cdef->superclassList.constFirst().classname;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline qsizetype lengthOfEscapeSequence(const QByteArray &s, qsizetype i)
|
static inline qsizetype lengthOfEscapeSequence(const QByteArray &s, qsizetype i)
|
||||||
@ -593,10 +593,9 @@ void Generator::generateCode()
|
|||||||
auto it = cdef->superclassList.cbegin() + 1;
|
auto it = cdef->superclassList.cbegin() + 1;
|
||||||
const auto end = cdef->superclassList.cend();
|
const auto end = cdef->superclassList.cend();
|
||||||
for (; it != end; ++it) {
|
for (; it != end; ++it) {
|
||||||
const auto &[className, access] = *it;
|
if (it->access == FunctionDef::Private)
|
||||||
if (access == FunctionDef::Private)
|
|
||||||
continue;
|
continue;
|
||||||
const char *cname = className.constData();
|
const char *cname = it->classname.constData();
|
||||||
fprintf(out, " if (!strcmp(_clname, \"%s\"))\n return static_cast< %s*>(this);\n",
|
fprintf(out, " if (!strcmp(_clname, \"%s\"))\n return static_cast< %s*>(this);\n",
|
||||||
cname, cname);
|
cname, cname);
|
||||||
}
|
}
|
||||||
|
@ -92,12 +92,12 @@ bool Moc::parseClassHead(ClassDef *def)
|
|||||||
if (test(LPAREN)) {
|
if (test(LPAREN)) {
|
||||||
until(RPAREN);
|
until(RPAREN);
|
||||||
} else {
|
} else {
|
||||||
def->superclassList += qMakePair(type, access);
|
def->superclassList += SuperClass{type, access};
|
||||||
}
|
}
|
||||||
} while (test(COMMA));
|
} while (test(COMMA));
|
||||||
|
|
||||||
if (!def->superclassList.isEmpty()
|
if (!def->superclassList.isEmpty()
|
||||||
&& knownGadgets.contains(def->superclassList.constFirst().first)) {
|
&& knownGadgets.contains(def->superclassList.constFirst().classname)) {
|
||||||
// Q_GADGET subclasses are treated as Q_GADGETs
|
// Q_GADGET subclasses are treated as Q_GADGETs
|
||||||
knownGadgets.insert(def->classname, def->qualified);
|
knownGadgets.insert(def->classname, def->qualified);
|
||||||
knownGadgets.insert(def->qualified, def->qualified);
|
knownGadgets.insert(def->qualified, def->qualified);
|
||||||
@ -1858,7 +1858,7 @@ bool Moc::until(Token target) {
|
|||||||
void Moc::checkSuperClasses(ClassDef *def)
|
void Moc::checkSuperClasses(ClassDef *def)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!def->superclassList.isEmpty());
|
Q_ASSERT(!def->superclassList.isEmpty());
|
||||||
const QByteArray &firstSuperclass = def->superclassList.at(0).first;
|
const QByteArray &firstSuperclass = def->superclassList.at(0).classname;
|
||||||
|
|
||||||
if (!knownQObjectClasses.contains(firstSuperclass)) {
|
if (!knownQObjectClasses.contains(firstSuperclass)) {
|
||||||
// enable once we /require/ include paths
|
// enable once we /require/ include paths
|
||||||
@ -1884,7 +1884,7 @@ void Moc::checkSuperClasses(ClassDef *def)
|
|||||||
const auto end = def->superclassList.cend();
|
const auto end = def->superclassList.cend();
|
||||||
auto it = def->superclassList.cbegin() + 1;
|
auto it = def->superclassList.cbegin() + 1;
|
||||||
for (; it != end; ++it) {
|
for (; it != end; ++it) {
|
||||||
const QByteArray &superClass = it->first;
|
const QByteArray &superClass = it->classname;
|
||||||
if (knownQObjectClasses.contains(superClass)) {
|
if (knownQObjectClasses.contains(superClass)) {
|
||||||
const QByteArray msg
|
const QByteArray msg
|
||||||
= "Class "
|
= "Class "
|
||||||
@ -2038,11 +2038,9 @@ QJsonObject ClassDef::toJson() const
|
|||||||
QJsonArray superClasses;
|
QJsonArray superClasses;
|
||||||
|
|
||||||
for (const auto &super: std::as_const(superclassList)) {
|
for (const auto &super: std::as_const(superclassList)) {
|
||||||
const auto name = super.first;
|
|
||||||
const auto access = super.second;
|
|
||||||
QJsonObject superCls;
|
QJsonObject superCls;
|
||||||
superCls["name"_L1] = QString::fromUtf8(name);
|
superCls["name"_L1] = QString::fromUtf8(super.classname);
|
||||||
FunctionDef::accessToJson(&superCls, access);
|
FunctionDef::accessToJson(&superCls, super.access);
|
||||||
superClasses.append(superCls);
|
superClasses.append(superCls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include <qstringlist.h>
|
#include <qstringlist.h>
|
||||||
#include <qmap.h>
|
#include <qmap.h>
|
||||||
#include <qpair.h>
|
|
||||||
#include <qjsondocument.h>
|
#include <qjsondocument.h>
|
||||||
#include <qjsonarray.h>
|
#include <qjsonarray.h>
|
||||||
#include <qjsonobject.h>
|
#include <qjsonobject.h>
|
||||||
@ -156,8 +155,14 @@ struct BaseDef {
|
|||||||
qsizetype end = 0;
|
qsizetype end = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SuperClass {
|
||||||
|
QByteArray classname;
|
||||||
|
FunctionDef::Access access;
|
||||||
|
};
|
||||||
|
Q_DECLARE_TYPEINFO(SuperClass, Q_RELOCATABLE_TYPE);
|
||||||
|
|
||||||
struct ClassDef : BaseDef {
|
struct ClassDef : BaseDef {
|
||||||
QList<QPair<QByteArray, FunctionDef::Access>> superclassList;
|
QList<SuperClass> superclassList;
|
||||||
|
|
||||||
struct Interface
|
struct Interface
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user