aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-08-03 14:43:41 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-08-10 10:37:35 +0200
commit3fe77abc309d160a112f82357e13d835c1479e31 (patch)
tree61b3e6403a485042376b8d258e6b3bd0a6953099
parent5d152f8369d116ecfdd8865006278d15a4237913 (diff)
Add a typesystem XML attribute for Python enum types
This is preparing the PyEnum completion of different Enum types. Task-number: PYSIDE-1735 Change-Id: I917bd62eae785b486302092c33843efceecf0568 Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit 1a71e6f87d238c72f8d2fadf976310378ae78b3d)
-rw-r--r--sources/shiboken6/ApiExtractor/typesystem.cpp15
-rw-r--r--sources/shiboken6/ApiExtractor/typesystem.h3
-rw-r--r--sources/shiboken6/ApiExtractor/typesystem_enums.h6
-rw-r--r--sources/shiboken6/ApiExtractor/typesystemparser.cpp18
-rw-r--r--sources/shiboken6/doc/typesystem_specifying_types.rst4
5 files changed, 46 insertions, 0 deletions
diff --git a/sources/shiboken6/ApiExtractor/typesystem.cpp b/sources/shiboken6/ApiExtractor/typesystem.cpp
index bb24ead0c..35521f65f 100644
--- a/sources/shiboken6/ApiExtractor/typesystem.cpp
+++ b/sources/shiboken6/ApiExtractor/typesystem.cpp
@@ -999,6 +999,7 @@ public:
const EnumValueTypeEntry *m_nullValue = nullptr;
QStringList m_rejectedEnums;
FlagsTypeEntry *m_flags = nullptr;
+ TypeSystem::PythonEnumType m_pythonEnumType = TypeSystem::PythonEnumType::Unspecified;
};
EnumTypeEntry::EnumTypeEntry(const QString &entryName,
@@ -1008,6 +1009,18 @@ EnumTypeEntry::EnumTypeEntry(const QString &entryName,
{
}
+TypeSystem::PythonEnumType EnumTypeEntry::pythonEnumType() const
+{
+ S_D(const EnumTypeEntry);
+ return d->m_pythonEnumType;
+}
+
+void EnumTypeEntry::setPythonEnumType(TypeSystem::PythonEnumType t)
+{
+ S_D(EnumTypeEntry);
+ d->m_pythonEnumType = t;
+}
+
QString EnumTypeEntry::targetLangQualifier() const
{
const QString q = qualifier();
@@ -2395,6 +2408,8 @@ void EnumTypeEntry::formatDebug(QDebug &debug) const
S_D(const EnumTypeEntry);
TypeEntry::formatDebug(debug);
+ if (d->m_pythonEnumType != TypeSystem::PythonEnumType::Unspecified)
+ debug << ", python-type=" << int(d->m_pythonEnumType);
if (d->m_flags)
debug << ", flags=(" << d->m_flags << ')';
}
diff --git a/sources/shiboken6/ApiExtractor/typesystem.h b/sources/shiboken6/ApiExtractor/typesystem.h
index 23621b7a3..2d602d37a 100644
--- a/sources/shiboken6/ApiExtractor/typesystem.h
+++ b/sources/shiboken6/ApiExtractor/typesystem.h
@@ -462,6 +462,9 @@ public:
const QVersionNumber &vr,
const TypeEntry *parent);
+ TypeSystem::PythonEnumType pythonEnumType() const;
+ void setPythonEnumType(TypeSystem::PythonEnumType t);
+
QString targetLangQualifier() const;
QString qualifier() const;
diff --git a/sources/shiboken6/ApiExtractor/typesystem_enums.h b/sources/shiboken6/ApiExtractor/typesystem_enums.h
index 47f7b7cef..fba411c2c 100644
--- a/sources/shiboken6/ApiExtractor/typesystem_enums.h
+++ b/sources/shiboken6/ApiExtractor/typesystem_enums.h
@@ -107,6 +107,12 @@ enum class CPythonType
Other
};
+enum class PythonEnumType {
+ Unspecified,
+ IntEnum,
+ IntFlag
+};
+
enum : int { OverloadNumberUnset = -1, OverloadNumberDefault = 99999 };
} // namespace TypeSystem
diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.cpp b/sources/shiboken6/ApiExtractor/typesystemparser.cpp
index 7a38ca5ae..ae929d035 100644
--- a/sources/shiboken6/ApiExtractor/typesystemparser.cpp
+++ b/sources/shiboken6/ApiExtractor/typesystemparser.cpp
@@ -95,6 +95,7 @@ static inline QString packageAttribute() { return QStringLiteral("package"); }
static inline QString positionAttribute() { return QStringLiteral("position"); }
static inline QString preferredConversionAttribute() { return QStringLiteral("preferred-conversion"); }
static inline QString preferredTargetLangTypeAttribute() { return QStringLiteral("preferred-target-lang-type"); }
+static inline QString pythonEnumTypeAttribute() { return QStringLiteral("python-type"); }
static inline QString removeAttribute() { return QStringLiteral("remove"); }
static inline QString renameAttribute() { return QStringLiteral("rename"); }
static inline QString readAttribute() { return QStringLiteral("read"); }
@@ -257,6 +258,14 @@ ENUM_LOOKUP_BEGIN(TypeSystem::BoolCast, Qt::CaseInsensitive,
};
ENUM_LOOKUP_LINEAR_SEARCH()
+ENUM_LOOKUP_BEGIN(TypeSystem::PythonEnumType, Qt::CaseSensitive,
+ pythonEnumTypeFromAttribute)
+ {
+ {u"IntEnum", TypeSystem::PythonEnumType::IntEnum},
+ {u"IntFlag", TypeSystem::PythonEnumType::IntFlag}
+ };
+ENUM_LOOKUP_LINEAR_SEARCH()
+
ENUM_LOOKUP_BEGIN(TypeSystem::Language, Qt::CaseInsensitive,
languageFromAttribute)
{
@@ -1509,6 +1518,15 @@ EnumTypeEntry *
} else if (name == forceIntegerAttribute()) {
qCWarning(lcShiboken, "%s",
qPrintable(msgUnimplementedAttributeWarning(reader, name)));
+ } else if (name == pythonEnumTypeAttribute()) {
+ const auto attribute = attributes->takeAt(i);
+ const auto typeOpt = pythonEnumTypeFromAttribute(attribute.value());
+ if (typeOpt.has_value()) {
+ entry->setPythonEnumType(typeOpt.value());
+ } else {
+ qCWarning(lcShiboken, "%s",
+ qPrintable(msgInvalidAttributeValue(attribute)));
+ }
} else if (name == extensibleAttribute()) {
qCWarning(lcShiboken, "%s",
qPrintable(msgUnimplementedAttributeWarning(reader, name)));
diff --git a/sources/shiboken6/doc/typesystem_specifying_types.rst b/sources/shiboken6/doc/typesystem_specifying_types.rst
index a8bb09039..6dda54786 100644
--- a/sources/shiboken6/doc/typesystem_specifying_types.rst
+++ b/sources/shiboken6/doc/typesystem_specifying_types.rst
@@ -249,6 +249,7 @@ enum-type
since="..."
flags="yes | no"
flags-revision="..."
+ python-type = "IntEnum | IntFlag"
lower-bound="..."
upper-bound="..."
force-integer="yes | no"
@@ -275,6 +276,9 @@ enum-type
Notice that the **enum-type** tag can either have **name** or **identified-by-value**
but not both.
+ The *optional* **python-type** attribute specifies the underlying
+ Python type.
+
The **revision** attribute can be used to specify a revision for each type, easing the
production of ABI compatible bindings.