aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-10-18 13:22:20 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-10-18 16:40:32 +0000
commit328d41b6f40cc52de031621318cc36e8100af135 (patch)
treee9d4816786f6449c13e074580f05796140471542
parentdeb23ae3f4edf011a94d3c09b0db51863889dd60 (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 Change-Id: I5de69f86ed45bd9f239e6d6017e7dc4a554f5378 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> (cherry picked from commit a1569c142dc3a357ac6232925bfb0b4d84e29e5a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-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 9e902a311..31adbb898 100644
--- a/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp
+++ b/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp
@@ -1236,9 +1236,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;