From 203e8961ecd8b94211845f4f6519788e34dd3230 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 14 Sep 2021 15:16:15 +0200 Subject: 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 --- .../shiboken6/ApiExtractor/abstractmetabuilder.cpp | 38 ++++++++++------------ .../shiboken6/ApiExtractor/abstractmetabuilder_p.h | 1 - 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); -- cgit v1.2.3