diff options
author | Matthew Woehlke <matthew.woehlke@kitware.com> | 2013-08-28 12:18:22 -0400 |
---|---|---|
committer | John Cummings <jcummings2@users.sf.net> | 2013-09-24 19:19:38 +0200 |
commit | 22aa9ced0d6b167ee835b4b184511c5df3f79591 (patch) | |
tree | 907354d65004a7c4434a5ae2b0b88deb6d530370 | |
parent | 8287ee801965f2fbeea573e1eb652cc851920f86 (diff) |
Write inititializations in topological order
Add methods to various places in the hierarchy so that the generator can
access the topologically ordered class list (in addition to the
unordered class list). Modify CppGenerator::finishGeneration to use
this.
This fixes a failure to correctly create Python wrapper classes due to
subclass wrappers being initialized before their base class (with the
result that the looked-up type object for the base class is null,
causing the derived class to be created without referencing the base).
Also change one of the test cases to test that we correctly wrap a
typedef of a template class derived from a non-template base (which was
failing before this change for the aforementioned reason).
Change-Id: Ib4dc2626a41cb7bb905ff4a302c2613ea12d026b
Reviewed-by: John Cummings <jcummings2@users.sf.net>
-rw-r--r-- | ApiExtractor/apiextractor.cpp | 6 | ||||
-rw-r--r-- | ApiExtractor/apiextractor.h | 1 | ||||
-rw-r--r-- | generator/generator.cpp | 5 | ||||
-rw-r--r-- | generator/generator.h | 6 | ||||
-rw-r--r-- | generator/shiboken/cppgenerator.cpp | 2 | ||||
-rw-r--r-- | tests/libsample/photon.h | 16 | ||||
-rw-r--r-- | tests/samplebinding/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 1 |
8 files changed, 32 insertions, 6 deletions
diff --git a/ApiExtractor/apiextractor.cpp b/ApiExtractor/apiextractor.cpp index 7a3a4a0d0..c3c9e4a22 100644 --- a/ApiExtractor/apiextractor.cpp +++ b/ApiExtractor/apiextractor.cpp @@ -141,6 +141,12 @@ AbstractMetaClassList ApiExtractor::classes() const return m_builder->classes(); } +AbstractMetaClassList ApiExtractor::classesTopologicalSorted() const +{ + Q_ASSERT(m_builder); + return m_builder->classesTopologicalSorted(); +} + PrimitiveTypeEntryList ApiExtractor::primitiveTypes() const { return TypeDatabase::instance()->primitiveTypes(); diff --git a/ApiExtractor/apiextractor.h b/ApiExtractor/apiextractor.h index ba253274f..f43c2c591 100644 --- a/ApiExtractor/apiextractor.h +++ b/ApiExtractor/apiextractor.h @@ -55,6 +55,7 @@ public: AbstractMetaEnumList globalEnums() const; AbstractMetaFunctionList globalFunctions() const; AbstractMetaClassList classes() const; + AbstractMetaClassList classesTopologicalSorted() const; PrimitiveTypeEntryList primitiveTypes() const; ContainerTypeEntryList containerTypes() const; QSet<QString> qtMetaTypeDeclaredTypeNames() const; diff --git a/generator/generator.cpp b/generator/generator.cpp index 80399f71b..2d2456a10 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp @@ -153,6 +153,11 @@ AbstractMetaClassList Generator::classes() const return m_d->apiextractor->classes(); } +AbstractMetaClassList Generator::classesTopologicalSorted() const +{ + return m_d->apiextractor->classesTopologicalSorted(); +} + AbstractMetaFunctionList Generator::globalFunctions() const { return m_d->apiextractor->globalFunctions(); diff --git a/generator/generator.h b/generator/generator.h index 3c357675c..8435ab6f7 100644 --- a/generator/generator.h +++ b/generator/generator.h @@ -95,6 +95,12 @@ public: /// Returns the classes used to generate the binding code. AbstractMetaClassList classes() const; + /// Returns the classes, topologically ordered, used to generate the binding code. + /// + /// The classes are ordered such that derived classes appear later in the list than + /// their parent classes. + AbstractMetaClassList classesTopologicalSorted() const; + /// Returns all global functions found by APIExtractor AbstractMetaFunctionList globalFunctions() const; diff --git a/generator/shiboken/cppgenerator.cpp b/generator/shiboken/cppgenerator.cpp index a6ec5746d..04a087021 100644 --- a/generator/shiboken/cppgenerator.cpp +++ b/generator/shiboken/cppgenerator.cpp @@ -4590,7 +4590,7 @@ void CppGenerator::finishGeneration() //this is a temporary solution before new type revison implementation //We need move QMetaObject register before QObject - AbstractMetaClassList lst = classes(); + AbstractMetaClassList lst = classesTopologicalSorted(); AbstractMetaClass* klassQObject = lst.findClass("QObject"); AbstractMetaClass* klassQMetaObject = lst.findClass("QMetaObject"); if (klassQObject && klassQMetaObject) { diff --git a/tests/libsample/photon.h b/tests/libsample/photon.h index f98d32a7e..f6c97b7c7 100644 --- a/tests/libsample/photon.h +++ b/tests/libsample/photon.h @@ -37,13 +37,21 @@ enum ClassType { DuplicatorType = 2 }; -template<ClassType CLASS_TYPE> -class LIBSAMPLE_API TemplateBase +class LIBSAMPLE_API Base { public: - explicit TemplateBase(int value) : m_value(value) {} + explicit Base(int value) : m_value(value) {} inline void setValue(int value) { m_value = value; } inline int value() const { return m_value; } +protected: + int m_value; +}; + +template<ClassType CLASS_TYPE> +class LIBSAMPLE_API TemplateBase : public Base +{ +public: + explicit TemplateBase(int value) : Base(value) {} inline int multiplicator() const { return (int)CLASS_TYPE; } inline int calculate() const { return m_value * ((int)CLASS_TYPE); } static inline ClassType classType() { return CLASS_TYPE; } @@ -60,8 +68,6 @@ public: } static inline TemplateBase<CLASS_TYPE>* passPointerThrough(TemplateBase<CLASS_TYPE>* obj) { return obj; } -private: - int m_value; }; #if defined _WIN32 || defined __CYGWIN__ diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt index 78bba9da4..23ff63c3d 100644 --- a/tests/samplebinding/CMakeLists.txt +++ b/tests/samplebinding/CMakeLists.txt @@ -65,6 +65,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/pairuser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/pen_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/persistentmodelindex_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/photon_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/photon_base_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/photon_valueidentity_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/photon_valueduplicator_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/point_wrapper.cpp diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 14b4f9d0f..4e3a9245b 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -595,6 +595,7 @@ <namespace-type name="Photon"> <enum-type name="ClassType"/> + <value-type name="Base"/> <value-type name="TemplateBase" generate="no"/> <value-type name="ValueIdentity"/> <value-type name="ValueDuplicator"/> |