aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/generator
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-09-09 08:26:08 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-09-21 14:15:37 +0200
commitb016f35f94e061ee296d65dbbcb2c7c9e4a988d0 (patch)
treeca13fb7067268070cc0c723d067d02b7ad351554 /sources/shiboken2/generator
parent58d3ac8842d36a6ce615188079e82598efa85b7e (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/generator')
-rw-r--r--sources/shiboken2/generator/shiboken2/overloaddata.cpp22
-rw-r--r--sources/shiboken2/generator/shiboken2/overloaddata.h1
2 files changed, 22 insertions, 1 deletions
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 <QtCore/QFile>
#include <QtCore/QTemporaryFile>
+#include <algorithm>
+
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;