diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-03-27 14:12:15 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-03-28 08:22:59 +0000 |
commit | e830fb721ad2a42ce5f3bbde2cd4cb211a508d73 (patch) | |
tree | 63cbfec33670e312062c1be5d0dad3ab9f0121af /sources/shiboken2/generator/shiboken2/cppgenerator.cpp | |
parent | cb5afdb1d9e71057f4062418703a2c1369afda58 (diff) |
shiboken: Refactor code declaring and calling the type init functions
Introduce a function for determining the init function name and
simplify the code writing the module wrapper.
Change-Id: I818f7a23902f1c9c1ce3cdad3d37dc18403006dd
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2/generator/shiboken2/cppgenerator.cpp')
-rw-r--r-- | sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index be9d426b5..b4337c2b1 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -4894,18 +4894,20 @@ void CppGenerator::writeFlagsUnaryOperator(QTextStream& s, const AbstractMetaEnu s << '}' << endl << endl; } -QString CppGenerator::getInitFunctionName(GeneratorContext &context) const +QString CppGenerator::getSimpleClassInitFunctionName(const AbstractMetaClass *metaClass) const { - QString initFunctionName; - if (!context.forSmartPointer()) { - initFunctionName = context.metaClass()->qualifiedCppName(); - initFunctionName.replace(QLatin1String("::"), QLatin1String("_")); - } else { - initFunctionName = getFilteredCppSignatureString(context.preciseType()->cppSignature()); - } + QString initFunctionName = metaClass->qualifiedCppName(); + initFunctionName.replace(QLatin1String("::"), QLatin1String("_")); return initFunctionName; } +QString CppGenerator::getInitFunctionName(GeneratorContext &context) const +{ + return !context.forSmartPointer() + ? getSimpleClassInitFunctionName(context.metaClass()) + : getFilteredCppSignatureString(context.preciseType()->cppSignature()); +} + void CppGenerator::writeClassRegister(QTextStream &s, const AbstractMetaClass *metaClass, GeneratorContext &classContext, @@ -5441,15 +5443,19 @@ bool CppGenerator::finishGeneration() if (!shouldGenerate(cls)) continue; - s_classInitDecl << "void init_" << cls->qualifiedCppName().replace(QLatin1String("::"), QLatin1String("_")) << "(PyObject* module);" << endl; + const QString initFunctionName = QLatin1String("init_") + getSimpleClassInitFunctionName(cls); - QString defineStr = QLatin1String("init_") + cls->qualifiedCppName().replace(QLatin1String("::"), QLatin1String("_")); + s_classInitDecl << "void " << initFunctionName << "(PyObject* module);" << endl; - if (cls->enclosingClass() && (cls->enclosingClass()->typeEntry()->codeGeneration() != TypeEntry::GenerateForSubclass)) - defineStr += QLatin1String("(reinterpret_cast<PyTypeObject *>(") + cpythonTypeNameExt(cls->enclosingClass()->typeEntry()) + QLatin1String(")->tp_dict);"); - else - defineStr += QLatin1String("(module);"); - s_classPythonDefines << INDENT << defineStr << endl; + s_classPythonDefines << INDENT << initFunctionName; + if (cls->enclosingClass() + && (cls->enclosingClass()->typeEntry()->codeGeneration() != TypeEntry::GenerateForSubclass)) { + s_classPythonDefines << "(reinterpret_cast<PyTypeObject *>(" + << cpythonTypeNameExt(cls->enclosingClass()->typeEntry()) << ")->tp_dict);"; + } else { + s_classPythonDefines << "(module);"; + } + s_classPythonDefines << endl; } // Initialize smart pointer types. |