From 93980c4c653aaaa2ad98a9a6a49d3719738f7ed6 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 18 Aug 2020 11:28:51 +0200 Subject: shiboken2: Fix formatting of operator functions In operator functions, some code would be generated for reverse shift operators and the remaining code was enclosed in if (!pyresult) without proper indentation. Generate the if (!pyresult) only when required and indent it properly by using a QScopedPointer. Change-Id: Iecffaa3d0a7b243e661b553726066d1177ab0298 Reviewed-by: Christian Tismer --- sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 9182b76e2..260607479 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -1932,6 +1932,9 @@ void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunction && !rfunc->isInplaceOperator() && !rfunc->isCallOperator() && rfunc->isOperatorOverload(); + + QScopedPointer reverseIndent; + if (callExtendedReverseOperator) { QString revOpName = ShibokenGenerator::pythonOperatorFunctionName(rfunc).insert(2, QLatin1Char('r')); // For custom classes, operations like __radd__ and __rmul__ @@ -1966,11 +1969,12 @@ void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunction } s << INDENT << "}\n"; s << INDENT << "Py_XDECREF(revOpMethod);\n\n"; - } - s << INDENT << "}\n"; - } - s << INDENT << "// Do not enter here if other object has implemented a reverse operator.\n"; - s << INDENT << "if (!" << PYTHON_RETURN_VAR << ") {\n\n"; + } // + s << INDENT << "}\n\n"; + s << INDENT << "// Do not enter here if other object has implemented a reverse operator.\n"; + s << INDENT << "if (!" << PYTHON_RETURN_VAR << ") {\n"; + reverseIndent.reset(new Indentation(INDENT)); + } // binary shift operator } if (maxArgs > 0) @@ -1978,8 +1982,10 @@ void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunction writeFunctionCalls(s, overloadData, classContext); - if (callExtendedReverseOperator) + if (!reverseIndent.isNull()) { // binary shift operator + reverseIndent.reset(); s << Qt::endl << INDENT << "} // End of \"if (!" << PYTHON_RETURN_VAR << ")\"\n"; + } s << Qt::endl; -- cgit v1.2.3