From 2a7f16dccfa1986bb79d08c90ed2ef56133994e8 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 22 Oct 2021 11:09:18 +0200 Subject: shiboken6: Remove ShibokenGenerator::guessScopeForDefaultValue() Move resolving of class fields and enum values as argument default values into AbstractMetaBuilder. Handling of static class field constants was spread between AbstractMetaBuilderPrivate::fixDefaultValue() and ShibokenGenerator::guessScopeForDefaultValue(). The former was handling it for arguments of non-primitive type only and not completely expanding namespaces. The latter was handling it for arguments of primitive types, too, but also added some code for non-static fields, which cannot be used as default arguments in C++. ShibokenGenerator::guessScopeForDefaultValue() was handling enum values for primitive and values, excluding macros by regex, but otherwise not checking if the term is really an enum value. Rewrite the code in AbstractMetaBuilderPrivate::fixDefaultValue() without regexes for clarity, let it check fields and enum values correctly via code model and fully expand namespaces. Add tests. Adapt the signature module to the now fully qualified signatures. [ChangeLog][shiboken6] When qualifying function argument default values for the generated code, shiboken no longer considers each identifier it cannot otherwise find as an enum value and no longer adds the class scope to it. This may require manually adding some replace-default-expression modifications. Task-number: PYSIDE-1691 Pick-to: 6.2 Change-Id: Id4cd2ca1f91db8c1663d7fc31e4b4ef72a5690f1 Reviewed-by: Qt CI Bot Reviewed-by: Christian Tismer --- sources/shiboken6/generator/shiboken/cppgenerator.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp') diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 2606f80ea..6b26ea043 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -3025,7 +3025,7 @@ void CppGenerator::writeSingleFunctionCall(TextStream &s, const QString cppArgRemoved = QLatin1String(CPP_ARG_REMOVED) + QString::number(argIdx); s << getFullTypeName(arg.type()) << ' ' << cppArgRemoved; - s << " = " << guessScopeForDefaultValue(func, arg) << ";\n"; + s << " = " << arg.defaultValueExpression() << ";\n"; writeUnusedVariableCast(s, cppArgRemoved); } else if (!injectCodeCallsFunc && !func->isUserAdded() && !hasConversionRule) { // When an argument is removed from a method signature and no other means of calling @@ -3047,9 +3047,8 @@ void CppGenerator::writeSingleFunctionCall(TextStream &s, int argPos = argIdx - removedArgs; QString argName = QLatin1String(CPP_ARG) + QString::number(argPos); QString pyArgName = usePyArgs ? pythonArgsAt(argPos) : QLatin1String(PYTHON_ARG); - QString defaultValue = guessScopeForDefaultValue(func, arg); writeArgumentConversion(s, argType, argName, pyArgName, - func->implementingClass(), defaultValue, + func->implementingClass(), arg.defaultValueExpression(), func->isUserAdded()); } -- cgit v1.2.3