diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-08-18 11:28:51 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-08-18 11:44:11 +0200 |
commit | 93980c4c653aaaa2ad98a9a6a49d3719738f7ed6 (patch) | |
tree | eddc298f9bda764fdcfd88ef40797fd345602297 | |
parent | 5f7b909e597c9dddbc4f9979910c2b0f026755fb (diff) |
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<Indentation>.
Change-Id: Iecffaa3d0a7b243e661b553726066d1177ab0298
Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r-- | sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 18 |
1 files 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<Indentation> 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; |