diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-11-23 19:36:43 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-12-07 08:01:00 +0100 |
commit | 0dfdd99163c2d02e4459392a53d15b476c57979d (patch) | |
tree | 5316ce1c6d7ff179f3415bd9e1217dfdc0e0e066 /sources/shiboken6/generator/shiboken/cppgenerator.cpp | |
parent | eb048c5a634a7ec8ceb33111e208d1036ef2ca9c (diff) |
shiboken6: Split out a function to write the nbbool function
CppGenerator::generateClass() is already quite big.
Task-number: PYSIDE-454
Change-Id: I2f3991f9a41e0a987827bb15e76c6d58cc5fb8fe
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.cpp | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index f5d677bc6..e508b5855 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -695,27 +695,8 @@ void CppGenerator::generateClass(TextStream &s, const GeneratorContext &classCon writeSetattroFunction(s, attroCheck, classContext); } - const auto f = boolCast(metaClass); - if (!f.isNull()) { - s << "static int " << cpythonBaseName(metaClass) << "___nb_bool(PyObject *self)\n" - << "{\n" << indent; - writeCppSelfDefinition(s, classContext, ErrorReturn::MinusOne); - - const bool allowThread = f->allowThread(); - if (allowThread) - s << "int result;\n" << BEGIN_ALLOW_THREADS << "\nresult = "; - else - s << "return "; - - if (f->isOperatorBool()) - s << '*' << CPP_SELF_VAR << " ? 1 : 0;\n"; - else - s << CPP_SELF_VAR << "->isNull() ? 0 : 1;\n"; - - if (allowThread) - s << END_ALLOW_THREADS << "\nreturn result;\n"; - s << outdent << "}\n\n"; - } + if (const auto f = boolCast(metaClass) ; !f.isNull()) + writeNbBoolFunction(classContext, f, s); if (supportsNumberProtocol(metaClass) && !metaClass->typeEntry()->isSmartPointer()) { const QList<AbstractMetaFunctionCList> opOverloads = filterGroupedOperatorFunctions( @@ -6217,6 +6198,30 @@ PyErr_Format(PyExc_AttributeError, << "return tmp;\n" << outdent << "}\n\n"; } +void CppGenerator::writeNbBoolFunction(const GeneratorContext &context, + const AbstractMetaFunctionCPtr &f, + TextStream &s) const +{ + s << "static int " << cpythonBaseName(context.metaClass()) << "___nb_bool(PyObject *self)\n" + << "{\n" << indent; + writeCppSelfDefinition(s, context, ErrorReturn::MinusOne); + + const bool allowThread = f->allowThread(); + if (allowThread) + s << "int result;\n" << BEGIN_ALLOW_THREADS << "\nresult = "; + else + s << "return "; + + if (f->isOperatorBool()) + s << '*' << CPP_SELF_VAR << " ? 1 : 0;\n"; + else + s << CPP_SELF_VAR << "->isNull() ? 0 : 1;\n"; + + if (allowThread) + s << END_ALLOW_THREADS << "\nreturn result;\n"; + s << outdent << "}\n\n"; +} + // Write declaration and invocation of the init function for the module init // function. void CppGenerator::writeInitFunc(TextStream &declStr, TextStream &callStr, |