aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
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 /sources/shiboken2/ApiExtractor/parser/codemodel.cpp
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>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/parser/codemodel.cpp')
-rw-r--r--sources/shiboken2/ApiExtractor/parser/codemodel.cpp53
1 files changed, 53 insertions, 0 deletions
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,