aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/generator/shiboken/cppgenerator.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-16 11:20:25 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-16 19:03:28 +0100
commit3ac9ba58e6ac969b420be17d5de465dbb2ce21c3 (patch)
treebf51182ead18c14dfceb23951a210382e6675dba /sources/shiboken6/generator/shiboken/cppgenerator.cpp
parent15763626e56fb7d495f56e77e4c8f730f560e2f5 (diff)
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 <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp')
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp14
1 files changed, 6 insertions, 8 deletions
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);