diff options
author | Marc Mutz <[email protected]> | 2023-12-13 11:45:38 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <[email protected]> | 2024-01-30 03:17:03 +0000 |
commit | b5266a1f238e428c5f83a7d06896d1071544da67 (patch) | |
tree | e67874380ac0755c3892ca68c990473a507d77d1 | |
parent | 9e6dbdb4fc586d3e381408fa340046cf49e74e7d (diff) |
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.
Task-number: QTBUG-101141
Change-Id: I5350da8d2d9aaf5ec86027357131ebac1eb50372
Reviewed-by: Fabian Kosmale <[email protected]>
Reviewed-by: Qt CI Bot <[email protected]>
(cherry picked from commit 672a824639a927e7e3061e84dfa35e06eb26a7fa)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
(cherry picked from commit 28a88b5986e8a1d1b2f8968cc9f9d7af9b381656)
(cherry picked from commit bdb4663eec6a34757ddf83d12e510840d4297de5)
-rw-r--r-- | src/tools/moc/moc.cpp | 15 | ||||
-rw-r--r-- | src/tools/moc/moc.h | 3 | ||||
-rw-r--r-- | tests/auto/tools/moc/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/tools/moc/allmocs_baseline_in.json | 29 | ||||
-rw-r--r-- | tests/auto/tools/moc/namespaced-base-class.h | 20 |
5 files changed, 66 insertions, 2 deletions
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 4f4c3ea7acb..de136d6c43b 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -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)); @@ -1998,6 +2007,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); } diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h index 80d177adfbc..d05416a089f 100644 --- a/src/tools/moc/moc.h +++ b/src/tools/moc/moc.h @@ -153,6 +153,7 @@ struct BaseDef { struct SuperClass { QByteArray classname; + QByteArray qualified; FunctionDef::Access access; }; Q_DECLARE_TYPEINFO(SuperClass, Q_RELOCATABLE_TYPE); @@ -234,6 +235,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(); diff --git a/tests/auto/tools/moc/CMakeLists.txt b/tests/auto/tools/moc/CMakeLists.txt index 5250bdc8e13..54e6cb82605 100644 --- a/tests/auto/tools/moc/CMakeLists.txt +++ b/tests/auto/tools/moc/CMakeLists.txt @@ -25,6 +25,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 diff --git a/tests/auto/tools/moc/allmocs_baseline_in.json b/tests/auto/tools/moc/allmocs_baseline_in.json index 46f643d09b0..c45b3b0db2f 100644 --- a/tests/auto/tools/moc/allmocs_baseline_in.json +++ b/tests/auto/tools/moc/allmocs_baseline_in.json @@ -1258,6 +1258,35 @@ { "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": [ + { "className": "Bar", "enums": [ { diff --git a/tests/auto/tools/moc/namespaced-base-class.h b/tests/auto/tools/moc/namespaced-base-class.h new file mode 100644 index 00000000000..6d76db9b542 --- /dev/null +++ b/tests/auto/tools/moc/namespaced-base-class.h @@ -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 |