moc: store the FQN in JSON superClass objects

Tooling can then use this information to find the correct base class,
even absent C++ scoping information.

Pick-to: 6.6 6.5
Task-number: QTBUG-101141
Change-Id: I5350da8d2d9aaf5ec86027357131ebac1eb50372
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 672a824639a927e7e3061e84dfa35e06eb26a7fa)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-12-13 11:45:38 +01:00 committed by Qt Cherry-pick Bot
parent aca842ceb2
commit 28a88b5986
5 changed files with 66 additions and 2 deletions

View File

@ -26,6 +26,15 @@ static QByteArray normalizeType(const QByteArray &ba)
return ba.size() ? normalizeTypeInternal(ba.constBegin(), ba.constEnd()) : ba;
}
const QByteArray &Moc::toFullyQualified(const QByteArray &name) const noexcept
{
if (auto it = knownQObjectClasses.find(name); it != knownQObjectClasses.end())
return it.value();
if (auto it = knownGadgets.find(name); it != knownGadgets.end())
return it.value();
return name;
}
bool Moc::parseClassHead(ClassDef *def)
{
// figure out whether this is a class declaration, or only a
@ -87,12 +96,12 @@ bool Moc::parseClassHead(ClassDef *def)
else
test(PUBLIC);
test(VIRTUAL);
const QByteArray type = parseType().name;
const Type type = parseType();
// ignore the 'class Foo : BAR(Baz)' case
if (test(LPAREN)) {
until(RPAREN);
} else {
def->superclassList += SuperClass{type, access};
def->superclassList.push_back({type.name, toFullyQualified(type.name), access});
}
} while (test(COMMA));
@ -2041,6 +2050,8 @@ QJsonObject ClassDef::toJson() const
for (const auto &super: std::as_const(superclassList)) {
QJsonObject superCls;
superCls["name"_L1] = QString::fromUtf8(super.classname);
if (super.classname != super.qualified)
superCls["fullyQualifiedName"_L1] = QString::fromUtf8(super.qualified);
FunctionDef::accessToJson(&superCls, super.access);
superClasses.append(superCls);
}

View File

@ -157,6 +157,7 @@ struct BaseDef {
struct SuperClass {
QByteArray classname;
QByteArray qualified;
FunctionDef::Access access;
};
Q_DECLARE_TYPEINFO(SuperClass, Q_RELOCATABLE_TYPE);
@ -240,6 +241,8 @@ public:
return index > def->begin && index < def->end - 1;
}
const QByteArray &toFullyQualified(const QByteArray &name) const noexcept;
void prependNamespaces(BaseDef &def, const QList<NamespaceDef> &namespaceList) const;
Type parseType();

View File

@ -30,6 +30,7 @@ set(JSON_HEADERS
moc_include.h
namespace.h
namespaced-flags.h
namespaced-base-class.h
no-keywords.h
non-gadget-parent-class.h
oldstyle-casts.h

View File

@ -1319,6 +1319,35 @@
"inputFile": "namespace.h",
"outputRevision": 68
},
{
"classes": [
{
"className": "Base",
"object": true,
"qualifiedClassName": "QTBUG_101141::Base",
"superClasses": [
{
"access": "public",
"name": "QObject"
}
]
},
{
"className": "Derived",
"object": true,
"qualifiedClassName": "QTBUG_101141::Derived",
"superClasses": [
{
"access": "public",
"fullyQualifiedName": "QTBUG_101141::Base",
"name": "Base"
}
]
}
],
"inputFile": "namespaced-base-class.h",
"outputRevision": 68
},
{
"classes": [
{

View File

@ -0,0 +1,20 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef TST_MOC_NAMESPACED_BASE_CLASS_H
#define TST_MOC_NAMESPACED_BASE_CLASS_H
#include <QObject>
namespace QTBUG_101141 {
class Base : public QObject {
Q_OBJECT
};
class Derived : public Base
{
Q_OBJECT
};
}
#endif // TST_MOC_NAMESPACED_BASE_CLASS_H