aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-10-18 13:22:20 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-10-18 16:03:32 +0200
commita1569c142dc3a357ac6232925bfb0b4d84e29e5a (patch)
tree58daded589d28e300a71868365e4dcbea4aec497
parent3c005da473fa0b1b399e9d8aab98cfd7aa420754 (diff)
shiboken6: Handle enums without values
shiboken used to ignore enumerations without values assuming they were just forward declaration of an enum classes. It turns out that there are such cases (QCborTag). To fix this, add empty enums always and replace them by the ones with values. Task-number: PYSIDE-1691 Pick-to: 6.2 Change-Id: I5de69f86ed45bd9f239e6d6017e7dc4a554f5378 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp4
-rw-r--r--sources/shiboken6/ApiExtractor/parser/codemodel.cpp18
-rw-r--r--sources/shiboken6/ApiExtractor/parser/codemodel.h2
3 files changed, 21 insertions, 3 deletions
diff --git a/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp
index 3ef826deb..b968cf0ad 100644
--- a/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp
+++ b/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp
@@ -1240,9 +1240,7 @@ bool Builder::endToken(const CXCursor &cursor)
d->m_currentFunctionType = CodeModel::Normal;
break;
case CXCursor_EnumDecl:
- // Add enum only if values were encountered, otherwise assume it
- // is a forward declaration of an enum class.
- if (!d->m_currentEnum.isNull() && d->m_currentEnum->hasValues())
+ if (!d->m_currentEnum.isNull())
d->m_scopeStack.back()->addEnum(d->m_currentEnum);
d->m_currentEnum.clear();
break;
diff --git a/sources/shiboken6/ApiExtractor/parser/codemodel.cpp b/sources/shiboken6/ApiExtractor/parser/codemodel.cpp
index 82f5e1a2c..1ea9f45f6 100644
--- a/sources/shiboken6/ApiExtractor/parser/codemodel.cpp
+++ b/sources/shiboken6/ApiExtractor/parser/codemodel.cpp
@@ -514,8 +514,26 @@ void _ScopeModelItem::addTemplateTypeAlias(const TemplateTypeAliasModelItem &ite
m_templateTypeAliases.append(item);
}
+qsizetype _ScopeModelItem::indexOfEnum(const QString &name) const
+{
+ for (qsizetype i = 0, size = m_enums.size(); i < size; ++i) {
+ if (m_enums.at(i)->name() == name)
+ return i;
+ }
+ return -1;
+}
+
void _ScopeModelItem::addEnum(const EnumModelItem &item)
{
+ // A forward declaration of an enum ("enum class Foo;") is undistinguishable
+ // from an enum without values ("enum class QCborTag {}"), so, add all
+ // enums and replace existing ones without values by ones with values.
+ const int index = indexOfEnum(item->name());
+ if (index >= 0) {
+ if (item->hasValues() && !m_enums.at(index)->hasValues())
+ m_enums[index] = item;
+ return;
+ }
m_enums.append(item);
}
diff --git a/sources/shiboken6/ApiExtractor/parser/codemodel.h b/sources/shiboken6/ApiExtractor/parser/codemodel.h
index 75ad60aaf..76abd47cf 100644
--- a/sources/shiboken6/ApiExtractor/parser/codemodel.h
+++ b/sources/shiboken6/ApiExtractor/parser/codemodel.h
@@ -245,6 +245,8 @@ protected:
#endif
private:
+ qsizetype indexOfEnum(const QString &name) const;
+
ClassList m_classes;
EnumList m_enums;
TypeDefList m_typeDefs;