aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-09-14 15:16:15 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-09-15 13:16:12 +0200
commit203e8961ecd8b94211845f4f6519788e34dd3230 (patch)
treecdcf92448141e9e17c420d5beedbdb4d495a5c1a
parent2eae75d55a693d04f8a6d2cd09394f7bb9dcb400 (diff)
shiboken6: Fix wrong argument indexes
AbstractMetaArgument::argumentIndex() was not updated in a few places when modifying function argument lists in the metabuilder. Extract a helper function to do that. Replace AbstractMetaBuilderPrivate::reverseList() in favor of std::reverse. Task-number: PYSIDE-1660 Change-Id: I585d29052e48c5d5cbe4b839cb8bd1eb7904244c Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp38
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h1
2 files changed, 17 insertions, 22 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
index f9cd7f1d4..4ef6132e1 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
@@ -67,6 +67,12 @@ static QString stripTemplateArgs(const QString &name)
return pos < 0 ? name : name.left(pos);
}
+static void fixArgumentIndexes(AbstractMetaArgumentList *list)
+{
+ for (qsizetype i = 0, size = list->size(); i < size; ++i)
+ (*list)[i].setArgumentIndex(i);
+}
+
bool AbstractMetaBuilderPrivate::m_useGlobalHeader = false;
AbstractMetaBuilderPrivate::AbstractMetaBuilderPrivate() :
@@ -266,6 +272,7 @@ void AbstractMetaBuilderPrivate::traverseOperatorFunction(const FunctionModelIte
AbstractMetaArgumentList arguments = metaFunction->arguments();
if (firstArgumentIsSelf || unaryOperator) {
AbstractMetaArgument first = arguments.takeFirst();
+ fixArgumentIndexes(&arguments);
if (!unaryOperator && first.type().indirections())
metaFunction->setPointerOperator(true);
metaFunction->setArguments(arguments);
@@ -310,11 +317,13 @@ bool AbstractMetaBuilderPrivate::traverseStreamOperator(const FunctionModelItem
return false;
// Strip first argument, since that is the containing object
- AbstractMetaArgumentList arguments = streamFunction->arguments();
- if (!streamClass->typeEntry()->generateCode())
- arguments.takeLast();
- else
- arguments.takeFirst();
+ AbstractMetaArgumentList arguments = streamFunction->arguments();
+ if (!streamClass->typeEntry()->generateCode()) {
+ arguments.takeLast();
+ } else {
+ arguments.takeFirst();
+ fixArgumentIndexes(&arguments);
+ }
streamFunction->setArguments(arguments);
@@ -324,7 +333,9 @@ bool AbstractMetaBuilderPrivate::traverseStreamOperator(const FunctionModelItem
AbstractMetaClass *funcClass;
if (!streamClass->typeEntry()->generateCode()) {
- AbstractMetaArgumentList reverseArgs = reverseList(streamFunction->arguments());
+ AbstractMetaArgumentList reverseArgs = streamFunction->arguments();
+ std::reverse(reverseArgs.begin(), reverseArgs.end());
+ fixArgumentIndexes(&reverseArgs);
streamFunction->setArguments(reverseArgs);
streamFunction->setReverseOperator(true);
funcClass = streamedClass;
@@ -3137,21 +3148,6 @@ void AbstractMetaBuilderPrivate::pushScope(const NamespaceModelItem &item)
}
}
-AbstractMetaArgumentList AbstractMetaBuilderPrivate::reverseList(const AbstractMetaArgumentList &list)
-{
- AbstractMetaArgumentList ret;
-
- int index = list.size();
- for (const AbstractMetaArgument &a : list) {
- AbstractMetaArgument arg = a;
- arg.setArgumentIndex(index);
- ret.prepend(arg);
- index--;
- }
-
- return ret;
-}
-
void AbstractMetaBuilder::setGlobalHeaders(const QFileInfoList &globalHeaders)
{
d->m_globalHeaders = globalHeaders;
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h
index bcfd7bc73..ac4e5adec 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h
+++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h
@@ -187,7 +187,6 @@ public:
static bool isEnum(const FileModelItem &dom, const QStringList &qualifiedName);
void sortLists();
- static AbstractMetaArgumentList reverseList(const AbstractMetaArgumentList &list);
void setInclude(TypeEntry *te, const QString &path) const;
static void fixArgumentNames(AbstractMetaFunction *func, const FunctionModificationList &mods);