From b016f35f94e061ee296d65dbbcb2c7c9e4a988d0 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 9 Sep 2020 08:26:08 +0200 Subject: 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 Reviewed-by: Cristian Maureira-Fredes --- .../shiboken2/generator/shiboken2/overloaddata.cpp | 22 +++++++++++++++++++++- .../shiboken2/generator/shiboken2/overloaddata.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'sources/shiboken2/generator/shiboken2') diff --git a/sources/shiboken2/generator/shiboken2/overloaddata.cpp b/sources/shiboken2/generator/shiboken2/overloaddata.cpp index e70eeaea1..36725d3fc 100644 --- a/sources/shiboken2/generator/shiboken2/overloaddata.cpp +++ b/sources/shiboken2/generator/shiboken2/overloaddata.cpp @@ -38,6 +38,8 @@ #include #include +#include + static const TypeEntry *getReferencedTypeEntry(const TypeEntry *typeEntry) { if (typeEntry->isPrimitive()) { @@ -175,6 +177,24 @@ static QString msgCyclicDependency(const QString &funcName, const QString &graph return result; } +static inline int overloadNumber(const OverloadData *o) +{ + return o->referenceFunction()->overloadNumber(); +} + +bool OverloadData::sortByOverloadNumberModification() +{ + if (std::all_of(m_nextOverloadData.cbegin(), m_nextOverloadData.cend(), + [](const OverloadData *o) { return overloadNumber(o) == TypeSystem::OverloadNumberDefault; })) { + return false; + } + std::stable_sort(m_nextOverloadData.begin(), m_nextOverloadData.end(), + [] (const OverloadData *o1, const OverloadData *o2) { + return overloadNumber(o1) < overloadNumber(o2); + }); + return true; +} + /** * Topologically sort the overloads by implicit convertion order * @@ -210,7 +230,7 @@ void OverloadData::sortNextOverloads() for (OverloadData *ov : qAsConst(m_nextOverloadData)) ov->sortNextOverloads(); - if (m_nextOverloadData.size() <= 1) + if (m_nextOverloadData.size() <= 1 || sortByOverloadNumberModification()) return; // Populates the OverloadSortData object containing map and reverseMap, to map type names to ids, diff --git a/sources/shiboken2/generator/shiboken2/overloaddata.h b/sources/shiboken2/generator/shiboken2/overloaddata.h index 4fd4199e5..9ffb084ff 100644 --- a/sources/shiboken2/generator/shiboken2/overloaddata.h +++ b/sources/shiboken2/generator/shiboken2/overloaddata.h @@ -139,6 +139,7 @@ private: OverloadData *addOverloadData(const AbstractMetaFunction *func, const AbstractMetaArgument *arg); void sortNextOverloads(); + bool sortByOverloadNumberModification(); int functionNumber(const AbstractMetaFunction *func) const; OverloadDataList overloadDataOnPosition(OverloadData *overloadData, int argPos) const; -- cgit v1.2.3