aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-20 09:20:28 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-07-20 17:52:07 +0200
commit14023079a9c082fa85592858698810e997af418e (patch)
tree6c573a155abfbc2e90a02b46f06b85777fe9a66f
parent9a9c65d289fbb80c4868760ed7a9e7a117eca7b6 (diff)
Fix libsample/photon test for Qt 6 / Windows
The code model was seeing photon.h:93: template class LIBSAMPLE_API TemplateBase<IdentityType>; as complete class definitions, shadowing the previous template definition. Add some processing removing them. Task-number: PYSIDE-1339 Task-number: PYSIDE-904 Change-Id: If0f28feeb6e3ff8c064e8853784240695f79e0b4 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp5
-rw-r--r--sources/shiboken2/ApiExtractor/parser/codemodel.cpp53
-rw-r--r--sources/shiboken2/ApiExtractor/parser/codemodel.h6
3 files changed, 63 insertions, 1 deletions
diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
index d08720934..6eb7e7b0c 100644
--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
@@ -162,6 +162,7 @@ public:
void popScope()
{
+ m_scopeStack.back()->purgeClassDeclarations();
m_scopeStack.pop();
updateScope();
}
@@ -841,7 +842,9 @@ void Builder::setSystemIncludes(const QByteArrayList &systemIncludes)
FileModelItem Builder::dom() const
{
Q_ASSERT(!d->m_scopeStack.isEmpty());
- return qSharedPointerDynamicCast<_FileModelItem>(d->m_scopeStack.constFirst());
+ auto rootScope = d->m_scopeStack.constFirst();
+ rootScope->purgeClassDeclarations();
+ return qSharedPointerDynamicCast<_FileModelItem>(rootScope);
}
static QString msgOutOfOrder(const CXCursor &cursor, const char *expectedScope)
diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
index 3b9521e82..9995fc71a 100644
--- a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
+++ b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
@@ -757,6 +757,16 @@ void _ClassModelItem::addPropertyDeclaration(const QString &propertyDeclaration)
m_propertyDeclarations << propertyDeclaration;
}
+bool _ClassModelItem::isEmpty() const
+{
+ return _ScopeModelItem::isEmpty() && m_propertyDeclarations.isEmpty();
+}
+
+bool _ClassModelItem::isTemplate() const
+{
+ return !m_templateParameters.isEmpty();
+}
+
#ifndef QT_NO_DEBUG_STREAM
template <class List>
static void formatModelItemList(QDebug &d, const char *prefix, const List &l,
@@ -853,6 +863,49 @@ void _ScopeModelItem::appendScope(const _ScopeModelItem &other)
m_enumsDeclarations += other.m_enumsDeclarations;
}
+bool _ScopeModelItem::isEmpty() const
+{
+ return m_classes.isEmpty() && m_enums.isEmpty()
+ && m_typeDefs.isEmpty() && m_templateTypeAliases.isEmpty()
+ && m_variables.isEmpty() && m_functions.isEmpty()
+ && m_enumsDeclarations.isEmpty();
+}
+
+/* This function removes MSVC export declarations of non-type template
+ * specializations (see below code from photon.h) for which
+ * clang_isCursorDefinition() returns true, causing them to be added as
+ * definitions of empty classes shadowing the template definition depending
+ * on QHash seed values.
+
+template <int N> class Tpl
+{
+public:
+...
+};
+
+#ifdef WIN32
+template class LIBSAMPLE_EXPORT Tpl<54>;
+*/
+void _ScopeModelItem::purgeClassDeclarations()
+{
+ for (int i = m_classes.size() - 1; i >= 0; --i) {
+ auto klass = m_classes.at(i);
+ // For an empty class, check if there is a matching template
+ // definition, and remove it if this is the case.
+ if (!klass->isTemplate() && klass->isEmpty()) {
+ const QString definitionPrefix = klass->name() + QLatin1Char('<');
+ const bool definitionFound =
+ std::any_of(m_classes.cbegin(), m_classes.cend(),
+ [definitionPrefix] (const ClassModelItem &c) {
+ return c->isTemplate() && !c->isEmpty()
+ && c->name().startsWith(definitionPrefix);
+ });
+ if (definitionFound)
+ m_classes.removeAt(i);
+ }
+ }
+}
+
#ifndef QT_NO_DEBUG_STREAM
template <class Hash>
static void formatScopeHash(QDebug &d, const char *prefix, const Hash &h,
diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.h b/sources/shiboken2/ApiExtractor/parser/codemodel.h
index ea9cdc30d..13bc7cf36 100644
--- a/sources/shiboken2/ApiExtractor/parser/codemodel.h
+++ b/sources/shiboken2/ApiExtractor/parser/codemodel.h
@@ -360,6 +360,9 @@ public:
FunctionModelItem declaredFunction(const FunctionModelItem &item);
+ bool isEmpty() const;
+ void purgeClassDeclarations();
+
#ifndef QT_NO_DEBUG_STREAM
void formatDebug(QDebug &d) const override;
#endif
@@ -423,6 +426,9 @@ public:
bool isFinal() const { return m_final; }
void setFinal(bool f) { m_final = f; }
+ bool isEmpty() const;
+ bool isTemplate() const;
+
#ifndef QT_NO_DEBUG_STREAM
void formatDebug(QDebug &d) const override;
#endif