diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-11-03 14:33:48 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-11-07 13:39:06 +0100 |
commit | dde88192d992ad076a21b68c54273b8122416623 (patch) | |
tree | dc4677d79485c2a4922a98c287c7a9d9061ef092 | |
parent | 00049968191cc5f76ff6c9cec6a2f800fa185dd2 (diff) |
shiboken6: Fix forward declarations for private classes
Write forward declarations to the private header as
well. As a drive-by, handle nested namespaces like
QNativeInterface::Private correctly when writing out the
forward declarations.
Amends 3597752f58a237dfb8fec897822bb78e46905955.
Task-number: PYSIDE-2099
Task-number: PYSIDE-1568
Change-Id: Ia82af401ceab1e5ca64abe6e811ea4041a8fe148
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
(cherry picked from commit 349c8188894a3f93df2aaba9289c0c03bf65a148)
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r-- | sources/shiboken6/generator/shiboken/headergenerator.cpp | 22 | ||||
-rw-r--r-- | sources/shiboken6/generator/shiboken/headergenerator.h | 1 |
2 files changed, 19 insertions, 4 deletions
diff --git a/sources/shiboken6/generator/shiboken/headergenerator.cpp b/sources/shiboken6/generator/shiboken/headergenerator.cpp index e73f80eb0..be71def6d 100644 --- a/sources/shiboken6/generator/shiboken/headergenerator.cpp +++ b/sources/shiboken6/generator/shiboken/headergenerator.cpp @@ -493,10 +493,17 @@ static void writeForwardDeclarations(TextStream &s, if (auto *encl = c->enclosingClass()) { Q_ASSERT(encl->isNamespace()); auto idx = indexOf(nameSpaces, encl); - if (idx != -1) + if (idx != -1) { nameSpaces[idx].classes.append(c); - else + } else { nameSpaces.append(NameSpace{encl, {c}}); + for (auto *enclNsp = encl->enclosingClass(); enclNsp != nullptr; + enclNsp = enclNsp->enclosingClass()) { + idx = indexOf(nameSpaces, enclNsp); + if (idx == -1) + nameSpaces.append(NameSpace{enclNsp, {}}); + } + } } else { writeForwardDeclaration(s, c); } @@ -518,6 +525,7 @@ bool HeaderGenerator::finishGeneration() // This header should be included by binding modules // extendind on top of this one. AbstractMetaClassCList forwardDeclarations; + AbstractMetaClassCList privateForwardDeclarations; QSet<Include> includes; QSet<Include> privateIncludes; StringStream macrosStream(TextStream::Language::Cpp); @@ -630,8 +638,9 @@ bool HeaderGenerator::finishGeneration() //Includes const bool isPrivate = classType->isPrivate(); auto &includeList = isPrivate ? privateIncludes : includes; + auto &forwardList = isPrivate ? privateForwardDeclarations : forwardDeclarations; if (leanHeaders() && canForwardDeclare(metaClass)) - forwardDeclarations.append(metaClass); + forwardList.append(metaClass); else includeList << classType->include(); @@ -730,7 +739,8 @@ bool HeaderGenerator::finishGeneration() if (hasPrivateClasses()) { writePrivateHeader(moduleHeaderDir, includeShield, - privateIncludes, privateTypeFunctions.toString()); + privateIncludes, privateForwardDeclarations, + privateTypeFunctions.toString()); } return true; } @@ -738,6 +748,7 @@ bool HeaderGenerator::finishGeneration() void HeaderGenerator::writePrivateHeader(const QString &moduleHeaderDir, const QString &publicIncludeShield, const QSet<Include> &privateIncludes, + const AbstractMetaClassCList &forwardDeclarations, const QString &privateTypeFunctions) { // Write includes and type functions of private classes @@ -758,6 +769,9 @@ void HeaderGenerator::writePrivateHeader(const QString &moduleHeaderDir, ps << include; ps << '\n'; + if (leanHeaders()) + writeForwardDeclarations(ps, forwardDeclarations); + if (usePySideExtensions()) ps << "QT_WARNING_PUSH\nQT_WARNING_DISABLE_DEPRECATED\n"; diff --git a/sources/shiboken6/generator/shiboken/headergenerator.h b/sources/shiboken6/generator/shiboken/headergenerator.h index a02cc5235..4f988c349 100644 --- a/sources/shiboken6/generator/shiboken/headergenerator.h +++ b/sources/shiboken6/generator/shiboken/headergenerator.h @@ -46,6 +46,7 @@ private: void writePrivateHeader(const QString &moduleHeaderDir, const QString &publicIncludeShield, const QSet<Include> &privateIncludes, + const AbstractMetaClassCList &forwardDeclarations, const QString &privateTypeFunctions); QSet<AbstractMetaFunctionCPtr> m_inheritedOverloads; |