diff options
-rw-r--r-- | cppgenerator.cpp | 17 | ||||
-rw-r--r-- | cppgenerator.h | 1 | ||||
-rw-r--r-- | shibokengenerator.cpp | 8 | ||||
-rw-r--r-- | shibokengenerator.h | 3 |
4 files changed, 29 insertions, 0 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp index 34159f8cc..600f26325 100644 --- a/cppgenerator.cpp +++ b/cppgenerator.cpp @@ -2619,4 +2619,21 @@ void CppGenerator::writeParentChildManagement(QTextStream& s, const AbstractMeta } } + writeReturnValueHeuristics(s, func); +} + +void CppGenerator::writeReturnValueHeuristics(QTextStream& s, const AbstractMetaFunction* func) +{ + AbstractMetaType *type = func->type(); + if (!useReturnValueHeuristic() + || !func->ownerClass() + || func->ownership(func->ownerClass(), TypeSystem::TargetLangCode, 0) != TypeSystem::InvalidOwnership + || !type + || func->isStatic() + || !func->typeReplaced(0).isEmpty()) { + return; + } + + if (type->isQObject() || type->isObject() || type->isValuePointer()) + s << INDENT << "Shiboken::setParent(self, " PYTHON_RETURN_VAR ");" << endl; } diff --git a/cppgenerator.h b/cppgenerator.h index 0d7746ad6..b8dc25494 100644 --- a/cppgenerator.h +++ b/cppgenerator.h @@ -148,6 +148,7 @@ private: void writeSpecialCastFunction(QTextStream& s, const AbstractMetaClass* metaClass); void writeParentChildManagement(QTextStream& s, const AbstractMetaFunction* func); + void writeReturnValueHeuristics(QTextStream& s, const AbstractMetaFunction* func); /** * Returns the multiple inheritance initializer function for the given class. * \param metaClass the class for whom the function name must be generated. diff --git a/shibokengenerator.cpp b/shibokengenerator.cpp index 078c33938..83ccbc33c 100644 --- a/shibokengenerator.cpp +++ b/shibokengenerator.cpp @@ -31,6 +31,7 @@ #define NULL_VALUE "NULL" #define PARENT_CTOR_HEURISTIC "enable-parent-ctor-heuristic" +#define RETURN_VALUE_HEURISTIC "enable-return-value-heuristic" #define ENABLE_PYSIDE_EXTENSIONS "enable-pyside-extensions" static Indentor INDENT; @@ -1208,6 +1209,7 @@ QMap<QString, QString> ShibokenGenerator::options() const { QMap<QString, QString> opts(Generator::options()); opts.insert(PARENT_CTOR_HEURISTIC, "Enable heuristics to detect parent relationship on constructors."); + opts.insert(RETURN_VALUE_HEURISTIC, "Enable heuristics to detect parent relationship on return values (USE WITH CAUTION!)"); opts.insert(ENABLE_PYSIDE_EXTENSIONS, "Enable PySide extensions, such as support for signal/slots, use this if you are creating a binding for a Qt-based library."); return opts; } @@ -1216,6 +1218,7 @@ bool ShibokenGenerator::doSetup(const QMap<QString, QString>& args) { m_useCtorHeuristic = args.contains(PARENT_CTOR_HEURISTIC); m_usePySideExtensions = args.contains(ENABLE_PYSIDE_EXTENSIONS); + m_userReturnValueHeuristic = args.contains(RETURN_VALUE_HEURISTIC); return true; } @@ -1224,6 +1227,11 @@ bool ShibokenGenerator::useCtorHeuristic() const return m_useCtorHeuristic; } +bool ShibokenGenerator::useReturnValueHeuristic() const +{ + return m_userReturnValueHeuristic; +} + bool ShibokenGenerator::usePySideExtensions() const { return m_usePySideExtensions; diff --git a/shibokengenerator.h b/shibokengenerator.h index faf5546a7..92c78b143 100644 --- a/shibokengenerator.h +++ b/shibokengenerator.h @@ -273,6 +273,8 @@ public: /// Returns true if the user enabled the so called "parent constructor heuristic". bool useCtorHeuristic() const; + /// Returns true if the user enabled the so called "return value heuristic". + bool useReturnValueHeuristic() const; /// Returns true if the user enabled PySide extensions. bool usePySideExtensions() const; protected: @@ -300,6 +302,7 @@ protected: AbstractMetaFunctionList filterFunctions(const AbstractMetaClass* metaClass); private: bool m_useCtorHeuristic; + bool m_userReturnValueHeuristic; bool m_usePySideExtensions; }; |