diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-02 22:26:22 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-03 12:19:16 +0200 |
commit | 017e3480c8bfb55085c59fc996a41e70566e1501 (patch) | |
tree | ca2895941f7ac508a65041056dff090112261f9b | |
parent | d8f333e15dfa88aebd938d40ed0813ca85d75153 (diff) |
shiboken6: Move pythonFunctionWrapperUsesListOfArguments() to OverloadData
Task-number: PYSIDE-1653
Change-Id: Icf2b0772165469bf2781e67eee98f398903ff8d5
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
5 files changed, 31 insertions, 25 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index d5c9dc263..c7b9a585c 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -1884,7 +1884,7 @@ static const char *fullName = ")" << fullPythonFunctionName(rfunc, true) if (maxArgs > 0) { s << "int overloadId = -1;\n" << "PythonToCppFunc " << PYTHON_TO_CPP_VAR; - if (pythonFunctionWrapperUsesListOfArguments(overloadData)) { + if (overloadData.pythonFunctionWrapperUsesListOfArguments()) { s << "[] = { " << NULL_PTR; for (int i = 1; i < maxArgs; ++i) s << ", " << NULL_PTR; @@ -1897,10 +1897,12 @@ static const char *fullName = ")" << fullPythonFunctionName(rfunc, true) if (initPythonArguments) { s << "const Py_ssize_t numArgs = "; - if (minArgs == 0 && maxArgs == 1 && !rfunc->isConstructor() && !pythonFunctionWrapperUsesListOfArguments(overloadData)) + if (minArgs == 0 && maxArgs == 1 && !rfunc->isConstructor() + && !overloadData.pythonFunctionWrapperUsesListOfArguments()) { s << "(" << PYTHON_ARG << " == 0 ? 0 : 1);\n"; - else + } else { writeArgumentsInitializer(s, overloadData); + } } } @@ -2068,7 +2070,7 @@ void CppGenerator::writeMethodWrapper(TextStream &s, const AbstractMetaFunctionC s << "static PyObject *"; s << cpythonFunctionName(rfunc) << "(PyObject *self"; if (maxArgs > 0) { - s << ", PyObject *" << (pythonFunctionWrapperUsesListOfArguments(overloadData) ? "args" : PYTHON_ARG); + s << ", PyObject *" << (overloadData.pythonFunctionWrapperUsesListOfArguments() ? "args" : PYTHON_ARG); if (overloadData.hasArgumentWithDefaultValue() || rfunc->isCallOperator()) s << ", PyObject *kwds"; } @@ -2364,7 +2366,7 @@ void CppGenerator::writeErrorSection(TextStream &s, OverloadData &overloadData) const auto rfunc = overloadData.referenceFunction(); s << '\n' << cpythonFunctionName(rfunc) << "_TypeError:\n"; Indentation indentation(s); - QString argsVar = pythonFunctionWrapperUsesListOfArguments(overloadData) + QString argsVar = overloadData.pythonFunctionWrapperUsesListOfArguments() ? QLatin1String("args") : QLatin1String(PYTHON_ARG); s << "Shiboken::setErrorAboutWrongArguments(" << argsVar << ", fullName, errInfo);\n" << "return " << m_currentErrorCode << ";\n"; @@ -2805,7 +2807,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(TextStream &s, int maxArgs = parentOverloadData->maxArgs(); // Python constructors always receive multiple arguments. - bool usePyArgs = pythonFunctionWrapperUsesListOfArguments(*parentOverloadData); + const bool usePyArgs = parentOverloadData->pythonFunctionWrapperUsesListOfArguments(); // Functions without arguments are identified right away. if (maxArgs == 0) { @@ -2999,7 +3001,7 @@ void CppGenerator::writeSingleFunctionCall(TextStream &s, return; } - bool usePyArgs = pythonFunctionWrapperUsesListOfArguments(overloadData); + const bool usePyArgs = overloadData.pythonFunctionWrapperUsesListOfArguments(); // Handle named arguments. writeNamedArgumentResolution(s, func, usePyArgs, overloadData); @@ -4991,7 +4993,7 @@ void CppGenerator::writeRichCompareFunction(TextStream &s, QString CppGenerator::methodDefinitionParameters(const OverloadData &overloadData) const { - bool usePyArgs = pythonFunctionWrapperUsesListOfArguments(overloadData); + const bool usePyArgs = overloadData.pythonFunctionWrapperUsesListOfArguments(); const auto func = overloadData.referenceFunction(); int min = overloadData.minArgs(); int max = overloadData.maxArgs(); @@ -6451,7 +6453,8 @@ bool CppGenerator::writeParentChildManagement(TextStream &s, const AbstractMetaF const auto &groups = func->implementingClass() ? getFunctionGroups(func->implementingClass()) : getGlobalFunctionGroups(); - bool usePyArgs = pythonFunctionWrapperUsesListOfArguments(OverloadData(groups[func->name()], api())); + OverloadData od(groups.value(func->name()), api()); + const bool usePyArgs = od.pythonFunctionWrapperUsesListOfArguments(); ArgumentOwner argOwner = getArgumentOwner(func, argIndex); ArgumentOwner::Action action = argOwner.action; diff --git a/sources/shiboken6/generator/shiboken/overloaddata.cpp b/sources/shiboken6/generator/shiboken/overloaddata.cpp index 018a76b71..54631729e 100644 --- a/sources/shiboken6/generator/shiboken/overloaddata.cpp +++ b/sources/shiboken6/generator/shiboken/overloaddata.cpp @@ -960,6 +960,21 @@ OverloadData::~OverloadData() delete m_nextOverloadData.takeLast(); } +bool OverloadData::pythonFunctionWrapperUsesListOfArguments() const +{ + auto referenceFunction = m_overloads.constFirst(); + if (referenceFunction->isCallOperator()) + return true; + if (referenceFunction->isOperatorOverload()) + return false; + const int maxArgs = this->maxArgs(); + const int minArgs = this->minArgs(); + return (minArgs != maxArgs) + || (maxArgs > 1) + || referenceFunction->isConstructor() + || hasArgumentWithDefaultValue(); +} + bool OverloadData::hasArgumentTypeReplace() const { return !m_argTypeReplaced.isEmpty(); diff --git a/sources/shiboken6/generator/shiboken/overloaddata.h b/sources/shiboken6/generator/shiboken/overloaddata.h index 89e56caa4..ed0b7ca9a 100644 --- a/sources/shiboken6/generator/shiboken/overloaddata.h +++ b/sources/shiboken6/generator/shiboken/overloaddata.h @@ -120,6 +120,9 @@ public: void dumpGraph(const QString &filename) const; QString dumpGraph() const; + /// Returns true if a list of arguments is used (METH_VARARGS) + bool pythonFunctionWrapperUsesListOfArguments() const; + bool hasArgumentTypeReplace() const; QString argumentTypeReplaced() const; diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index 8ed8eba16..c443b0208 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -1661,7 +1661,7 @@ void ShibokenGenerator::writeCodeSnips(TextStream &s, ? getFunctionGroups(func->implementingClass()) : getGlobalFunctionGroups(); OverloadData od(groups[func->name()], api()); - bool usePyArgs = pythonFunctionWrapperUsesListOfArguments(od); + const bool usePyArgs = od.pythonFunctionWrapperUsesListOfArguments(); // Replace %PYARG_# variables. code.replace(QLatin1String("%PYARG_0"), QLatin1String(PYTHON_RETURN_VAR)); @@ -2611,20 +2611,6 @@ bool ShibokenGenerator::verboseErrorMessagesDisabled() const return m_verboseErrorMessagesDisabled; } -bool ShibokenGenerator::pythonFunctionWrapperUsesListOfArguments(const OverloadData &overloadData) -{ - if (overloadData.referenceFunction()->isCallOperator()) - return true; - if (overloadData.referenceFunction()->isOperatorOverload()) - return false; - int maxArgs = overloadData.maxArgs(); - int minArgs = overloadData.minArgs(); - return (minArgs != maxArgs) - || (maxArgs > 1) - || overloadData.referenceFunction()->isConstructor() - || overloadData.hasArgumentWithDefaultValue(); -} - void ShibokenGenerator::writeMinimalConstructorExpression(TextStream &s, const ApiExtractorResult &api, const AbstractMetaType &type, diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.h b/sources/shiboken6/generator/shiboken/shibokengenerator.h index 04dae6ca5..fd492842e 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.h +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.h @@ -388,7 +388,6 @@ protected: static QList<const CustomConversion *> getPrimitiveCustomConversions() ; /// Returns true if the Python wrapper for the received OverloadData must accept a list of arguments. - static bool pythonFunctionWrapperUsesListOfArguments(const OverloadData &overloadData); static const QRegularExpression &convertToCppRegEx() { return typeSystemConvRegExps()[TypeSystemToCppFunction]; } |