diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-09 08:26:08 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-21 14:15:37 +0200 |
commit | b016f35f94e061ee296d65dbbcb2c7c9e4a988d0 (patch) | |
tree | ca13fb7067268070cc0c723d067d02b7ad351554 /sources/shiboken2/ApiExtractor | |
parent | 58d3ac8842d36a6ce615188079e82598efa85b7e (diff) |
shiboken2: Allow specifying the sequence of overloads
Add an attribute to specify a number by which the functions
will be sorted. This deactivates the default sorting
which tries to avoid implicit conversions.
Fixes: PYSIDE-1366
Change-Id: I9a891e21f86152b2fdfda9a48d685f19aa936508
Reviewed-by: Christian Tismer <tismer@stackless.com>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2/ApiExtractor')
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetalang.cpp | 15 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetalang.h | 3 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/typesystem.h | 4 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/typesystem_enums.h | 2 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/typesystemparser.cpp | 23 |
5 files changed, 47 insertions, 0 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp index d20caacf1..e93108be1 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp @@ -1283,6 +1283,21 @@ AbstractMetaFunction::find(const AbstractMetaFunctionList &haystack, return findByName(haystack, needle); } +int AbstractMetaFunction::overloadNumber() const +{ + if (m_cachedOverloadNumber == TypeSystem::OverloadNumberUnset) { + m_cachedOverloadNumber = TypeSystem::OverloadNumberDefault; + const FunctionModificationList &mods = modifications(implementingClass()); + for (const FunctionModification &mod : mods) { + if (mod.overloadNumber() != TypeSystem::OverloadNumberUnset) { + m_cachedOverloadNumber = mod.overloadNumber(); + break; + } + } + } + return m_cachedOverloadNumber; +} + #ifndef QT_NO_DEBUG_STREAM static inline void formatMetaFunctionBrief(QDebug &d, const AbstractMetaFunction *af) { diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.h b/sources/shiboken2/ApiExtractor/abstractmetalang.h index 9ceae14df..2fe114de4 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.h +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.h @@ -1084,6 +1084,8 @@ public: void setExceptionHandlingModification(TypeSystem::ExceptionHandling em) { m_exceptionHandlingModification = em; } + int overloadNumber() const; + #ifndef QT_NO_DEBUG_STREAM void formatDebugVerbose(QDebug &d) const; #endif @@ -1115,6 +1117,7 @@ private: uint m_explicit : 1; uint m_pointerOperator : 1; uint m_isCallOperator : 1; + mutable int m_cachedOverloadNumber = TypeSystem::OverloadNumberUnset; ExceptionSpecification m_exceptionSpecification = ExceptionSpecification::Unknown; TypeSystem::AllowThread m_allowThreadModification = TypeSystem::AllowThread::Unspecified; TypeSystem::ExceptionHandling m_exceptionHandlingModification = TypeSystem::ExceptionHandling::Unspecified; diff --git a/sources/shiboken2/ApiExtractor/typesystem.h b/sources/shiboken2/ApiExtractor/typesystem.h index b31cee9cd..f351699d8 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.h +++ b/sources/shiboken2/ApiExtractor/typesystem.h @@ -356,6 +356,9 @@ struct FunctionModification: public Modification TypeSystem::ExceptionHandling exceptionHandling() const { return m_exceptionHandling; } void setExceptionHandling(TypeSystem::ExceptionHandling e) { m_exceptionHandling = e; } + int overloadNumber() const { return m_overloadNumber; } + void setOverloadNumber(int overloadNumber) { m_overloadNumber = overloadNumber; } + QString toString() const; #ifndef QT_NO_DEBUG_STREAM @@ -371,6 +374,7 @@ private: QString m_signature; QString m_originalSignature; QRegularExpression m_signaturePattern; + int m_overloadNumber = TypeSystem::OverloadNumberUnset; bool m_thread = false; AllowThread m_allowThread = AllowThread::Unspecified; TypeSystem::ExceptionHandling m_exceptionHandling = TypeSystem::ExceptionHandling::Unspecified; diff --git a/sources/shiboken2/ApiExtractor/typesystem_enums.h b/sources/shiboken2/ApiExtractor/typesystem_enums.h index f6b4b6fa6..0d7f279c4 100644 --- a/sources/shiboken2/ApiExtractor/typesystem_enums.h +++ b/sources/shiboken2/ApiExtractor/typesystem_enums.h @@ -88,6 +88,8 @@ enum Visibility { // For namespaces Auto }; +enum : int { OverloadNumberUnset = -1, OverloadNumberDefault = 99999 }; + } // namespace TypeSystem #endif // TYPESYSTEM_ENUMS_H diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.cpp b/sources/shiboken2/ApiExtractor/typesystemparser.cpp index 6979a7a4e..44616da0a 100644 --- a/sources/shiboken2/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken2/ApiExtractor/typesystemparser.cpp @@ -76,6 +76,7 @@ static inline QString invalidateAfterUseAttribute() { return QStringLiteral("inv static inline QString locationAttribute() { return QStringLiteral("location"); } static inline QString modifiedTypeAttribute() { return QStringLiteral("modified-type"); } static inline QString modifierAttribute() { return QStringLiteral("modifier"); } +static inline QString overloadNumberAttribute() { return QStringLiteral("overload-number"); } static inline QString ownershipAttribute() { return QStringLiteral("owner"); } static inline QString packageAttribute() { return QStringLiteral("package"); } static inline QString positionAttribute() { return QStringLiteral("position"); } @@ -2151,6 +2152,18 @@ bool TypeSystemParser::parseModifyField(const QXmlStreamReader &reader, return true; } +static bool parseOverloadNumber(const QXmlStreamAttribute &attribute, int *overloadNumber, + QString *errorMessage) +{ + bool ok; + *overloadNumber = attribute.value().toInt(&ok); + if (!ok || *overloadNumber < 0) { + *errorMessage = msgInvalidAttributeValue(attribute); + return false; + } + return true; +} + bool TypeSystemParser::parseAddFunction(const QXmlStreamReader &, const StackElement &topElement, QXmlStreamAttributes *attributes) @@ -2164,6 +2177,7 @@ bool TypeSystemParser::parseAddFunction(const QXmlStreamReader &, QString returnType = QLatin1String("void"); bool staticFunction = false; QString access; + int overloadNumber = TypeSystem::OverloadNumberUnset; for (int i = attributes->size() - 1; i >= 0; --i) { const QStringRef name = attributes->at(i).qualifiedName(); if (name == QLatin1String("signature")) { @@ -2175,6 +2189,9 @@ bool TypeSystemParser::parseAddFunction(const QXmlStreamReader &, staticAttribute(), false); } else if (name == accessAttribute()) { access = attributes->takeAt(i).value().toString(); + } else if (name == overloadNumberAttribute()) { + if (!parseOverloadNumber(attributes->takeAt(i), &overloadNumber, &m_error)) + return false; } } @@ -2210,6 +2227,7 @@ bool TypeSystemParser::parseAddFunction(const QXmlStreamReader &, m_contextStack.top()->functionMods.size(); FunctionModification mod; + mod.setOverloadNumber(overloadNumber); if (!mod.setSignature(m_currentSignature, &m_error)) return false; mod.setOriginalSignature(originalSignature); @@ -2234,6 +2252,7 @@ bool TypeSystemParser::parseModifyFunction(const QXmlStreamReader &reader, QString association; bool deprecated = false; bool isThread = false; + int overloadNumber = TypeSystem::OverloadNumberUnset; TypeSystem::ExceptionHandling exceptionHandling = TypeSystem::ExceptionHandling::Unspecified; TypeSystem::AllowThread allowThread = TypeSystem::AllowThread::Unspecified; for (int i = attributes->size() - 1; i >= 0; --i) { @@ -2270,6 +2289,9 @@ bool TypeSystemParser::parseModifyFunction(const QXmlStreamReader &reader, qCWarning(lcShiboken, "%s", qPrintable(msgInvalidAttributeValue(attribute))); } + } else if (name == overloadNumberAttribute()) { + if (!parseOverloadNumber(attributes->takeAt(i), &overloadNumber, &m_error)) + return false; } else if (name == virtualSlotAttribute()) { qCWarning(lcShiboken, "%s", qPrintable(msgUnimplementedAttributeWarning(reader, name))); @@ -2293,6 +2315,7 @@ bool TypeSystemParser::parseModifyFunction(const QXmlStreamReader &reader, return false; mod.setOriginalSignature(originalSignature); mod.setExceptionHandling(exceptionHandling); + mod.setOverloadNumber(overloadNumber); m_currentSignature = signature; if (!access.isEmpty()) { |