aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-03-27 14:12:15 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-03-28 08:22:59 +0000
commite830fb721ad2a42ce5f3bbde2cd4cb211a508d73 (patch)
tree63cbfec33670e312062c1be5d0dad3ab9f0121af
parentcb5afdb1d9e71057f4062418703a2c1369afda58 (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>
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp36
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.h1
2 files changed, 22 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.
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.h b/sources/shiboken2/generator/shiboken2/cppgenerator.h
index 3035fad34..d2e04dba2 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.h
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.h
@@ -229,6 +229,7 @@ private:
GeneratorContext &context, int maxArgs = 0);
QString getInitFunctionName(GeneratorContext &context) const;
+ QString getSimpleClassInitFunctionName(const AbstractMetaClass *metaClass) const;
void writeClassRegister(QTextStream &s,
const AbstractMetaClass *metaClass,