diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-05-10 15:14:40 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-05-10 17:16:44 +0200 |
| commit | 3e40f27cb539e0106511790a40327f5a03e48fab (patch) | |
| tree | 1a75c141f6984670783539602e2d84f2a0d04787 | |
| parent | 3a75dfa84129e4e034d25722fc231928fca750d9 (diff) | |
shiboken6: Fix passing static class fields as enum default values
Occurs in Qt 6.6:
class QNativeIpcKey
{
enum class Type { SystemV = 0x51, PosixRealtime = 0x100, Windows };
static constexpr Type DefaultTypeForOs = Type::Windows
...
QNativeIpcKey(Type type = DefaultTypeForOs)
};
Pick-to: 6.5
Change-Id: Icf9abdd9ebe24eb4e1d145e65b27496545e327ef
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
5 files changed, 26 insertions, 6 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp index 699bbef58..22ed7db2f 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp @@ -2847,9 +2847,10 @@ static bool isUnderQualifiedSpec(QStringView qualifiedType, QStringView candidat } QString AbstractMetaBuilder::fixEnumDefault(const AbstractMetaType &type, - const QString &expr) const + const QString &expr, + const AbstractMetaClassCPtr &klass) const { - return d->fixEnumDefault(type, expr); + return d->fixEnumDefault(type, expr, klass); } void AbstractMetaBuilder::setCodeModelTestMode(bool b) @@ -2887,7 +2888,7 @@ QString AbstractMetaBuilderPrivate::fixDefaultValue(QString expr, const Abstract return expr; if (type.isFlags() || type.isEnum()) { - expr = fixEnumDefault(type, expr); + expr = fixEnumDefault(type, expr, implementingClass); } else if (type.isContainer() && expr.contains(u'<')) { // Expand a container of a nested class, fex // "QList<FormatRange>()" -> "QList<QTextLayout::FormatRange>()" diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.h b/sources/shiboken6/ApiExtractor/abstractmetabuilder.h index a7a2623b6..940c1dd78 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.h +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.h @@ -127,7 +127,8 @@ public: // For testing purposes QString fixDefaultValue(const QString &expr, const AbstractMetaType &type, const AbstractMetaClassCPtr &) const; - QString fixEnumDefault(const AbstractMetaType &type, const QString &expr) const; + QString fixEnumDefault(const AbstractMetaType &type, const QString &expr, + const AbstractMetaClassCPtr & = {}) const; static void setCodeModelTestMode(bool b); diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp index 07cedd09e..68eef737a 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp @@ -85,12 +85,17 @@ static bool isFloatConstant(const QStringView expr) // to the default value, making it usable from Python wrapper code outside the // owner class hierarchy. See TestEnum::testEnumDefaultValues(). QString AbstractMetaBuilderPrivate::fixEnumDefault(const AbstractMetaType &type, - const QString &expr) const + const QString &expr, + const AbstractMetaClassCPtr &klass) const { // QFlags construct from integers, do not fix that if (isIntegerConstant(expr)) return expr; + const QString field = qualifyStaticField(klass, expr); + if (!field.isEmpty()) + return field; + const auto typeEntry = type.typeEntry(); EnumTypeEntryCPtr enumTypeEntry; FlagsTypeEntryCPtr flagsTypeEntry; diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h index 0616e272a..f0e667dbf 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h @@ -136,7 +136,8 @@ public: QString fixSimpleDefaultValue(QStringView expr, const AbstractMetaClassCPtr &klass) const; - QString fixEnumDefault(const AbstractMetaType &type, const QString &expr) const; + QString fixEnumDefault(const AbstractMetaType &type, const QString &expr, + const AbstractMetaClassCPtr &) const; /// Qualify a static field name for default value expressions static QString qualifyStaticField(const AbstractMetaClassCPtr &c, QStringView field); diff --git a/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp b/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp index 8251226b2..5e486ea51 100644 --- a/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp @@ -4,10 +4,12 @@ #include "testresolvetype.h" #include "testutil.h" #include <abstractmetaargument.h> +#include <abstractmetaenum.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> #include <abstractmetatype.h> #include <complextypeentry.h> +#include <enumtypeentry.h> #include <primitivetypeentry.h> #include <typedatabase.h> @@ -66,6 +68,7 @@ struct DefaultValuesFixture AbstractMetaType stringType; AbstractMetaType classType; AbstractMetaType listType; + AbstractMetaType enumType; AbstractMetaClassCPtr klass{}; }; @@ -91,6 +94,7 @@ public: static const int INT_FIELD_1 = 42; static const char *CHAR_FIELD_1; + static const Enum DefaultValue = enumValue1; }; } // Namespace )"; @@ -139,6 +143,9 @@ public: return -3; fixture->listType = listFunc->arguments().constFirst().type(); + fixture->enumType = AbstractMetaType(fixture->klass->enums().constFirst().typeEntry()); + fixture->enumType.decideUsagePattern(); + return 0; } @@ -213,6 +220,11 @@ void TestResolveType::testFixDefaultArguments_data() QTest::newRow("self from enum") << fixture << setupOk << fixture.classType << "Test(enumValue1)" << expected; + + // Don't qualify fields to "Test::Enum::DefaultValue" + QTest::newRow("enum from static field") + << fixture << setupOk << fixture.enumType + << "DefaultValue" << u"Namespace::Test::DefaultValue"_s; } void TestResolveType::testFixDefaultArguments() |
