From 3ac9ba58e6ac969b420be17d5de465dbb2ce21c3 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 16 Nov 2021 11:20:25 +0100 Subject: shiboken6: Refactor Python operator handling The mapping of the function name to the Python operators was duplicated in ShibokenGenerator and QtDocGenerator. Move it to the Generator base class and use it in the QtDocGenerator as well. Add the underscores. Remove the functions retrieving the Python rich comparison operator code from ShibokenGenerator and add a comparison operator type enum to AbstractMetaFunction instead. Use that to retrieve the Python rich comparison operator code. Task-number: PYSIDE-1711 Change-Id: Ib73412b819c60c3af22bc72c6bd1cfaa7f25904a Reviewed-by: Cristian Maureira-Fredes --- sources/shiboken6/generator/shiboken/cppgenerator.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 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 6b26ea043..a9d41f1f0 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -4927,14 +4927,11 @@ void CppGenerator::writeRichCompareFunction(TextStream &s, for (const AbstractMetaFunctionCList &overloads : groupedFuncs) { const auto rfunc = overloads[0]; - QString operatorId = ShibokenGenerator::pythonRichCompareOperatorId(rfunc); - s << "case " << operatorId << ':' << '\n'; + const auto op = rfunc->comparisonOperatorType().value(); + s << "case " << AbstractMetaFunction::pythonRichCompareOpCode(op) << ':' << '\n'; Indentation indent(s); - QString op = rfunc->originalName(); - op = op.right(op.size() - QLatin1String("operator").size()); - int alternativeNumericTypes = 0; for (const auto &func : overloads) { if (!func->isStatic() && @@ -4982,7 +4979,8 @@ void CppGenerator::writeRichCompareFunction(TextStream &s, // expression if (func->isPointerOperator()) s << '&'; - s << CPP_SELF_VAR << ' ' << op << '('; + s << CPP_SELF_VAR << ' ' + << AbstractMetaFunction::cppComparisonOperator(op) << " ("; if (argType.shouldDereferenceArgument()) s << '*'; s << CPP_ARG0 << ");\n" @@ -4998,10 +4996,10 @@ void CppGenerator::writeRichCompareFunction(TextStream &s, } s << " else {\n"; - if (operatorId == QLatin1String("Py_EQ") || operatorId == QLatin1String("Py_NE")) { + if (op == AbstractMetaFunction::OperatorEqual || op == AbstractMetaFunction::OperatorNotEqual) { Indentation indent(s); s << PYTHON_RETURN_VAR << " = " - << (operatorId == QLatin1String("Py_EQ") ? "Py_False" : "Py_True") << ";\n" + << (op == AbstractMetaFunction::OperatorEqual ? "Py_False" : "Py_True") << ";\n" << "Py_INCREF(" << PYTHON_RETURN_VAR << ");\n"; } else { Indentation indent(s); -- cgit v1.2.3