diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-10-14 09:29:55 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-10-27 11:09:08 +0000 |
commit | 1d044f467070a040713c9566a8a8de3a56c571e7 (patch) | |
tree | 0762dbf77a7192e3d8e3223c39e5893f720bd023 /sources | |
parent | 1d35b9d4070d57a801ba1ee9a99bde4d6f0de428 (diff) |
shiboken2: Add a disable-wrapper attribute for complex types
Make it possible to disable the generation of a C++ wrapper
in case that poses some problem.
Task-number: PYSIDE-1202
Change-Id: Id0d557e4d4a57cf537be8fb398161aea3a16e174
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources')
4 files changed, 21 insertions, 1 deletions
diff --git a/sources/shiboken2/ApiExtractor/typesystem.h b/sources/shiboken2/ApiExtractor/typesystem.h index d3ef2c629..2bbaabc91 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.h +++ b/sources/shiboken2/ApiExtractor/typesystem.h @@ -1209,6 +1209,7 @@ class ComplexTypeEntry : public TypeEntry { public: enum TypeFlag { + DisableWrapper = 0x1, Deprecated = 0x4 }; Q_DECLARE_FLAGS(TypeFlags, TypeFlag) diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.cpp b/sources/shiboken2/ApiExtractor/typesystemparser.cpp index 9ad9322b2..7b018cd4e 100644 --- a/sources/shiboken2/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken2/ApiExtractor/typesystemparser.cpp @@ -60,6 +60,7 @@ static inline QString untilAttribute() { return QStringLiteral("until"); } static inline QString defaultSuperclassAttribute() { return QStringLiteral("default-superclass"); } static inline QString deleteInMainThreadAttribute() { return QStringLiteral("delete-in-main-thread"); } static inline QString deprecatedAttribute() { return QStringLiteral("deprecated"); } +static inline QString disableWrapperAttribute() { return QStringLiteral("disable-wrapper"); } static inline QString exceptionHandlingAttribute() { return QStringLiteral("exception-handling"); } static inline QString extensibleAttribute() { return QStringLiteral("extensible"); } static inline QString fileNameAttribute() { return QStringLiteral("file-name"); } @@ -1569,6 +1570,9 @@ void TypeSystemParser::applyComplexTypeAttributes(const QXmlStreamReader &reader } else if (name == deprecatedAttribute()) { if (convertBoolean(attributes->takeAt(i).value(), deprecatedAttribute(), false)) ctype->setTypeFlags(ctype->typeFlags() | ComplexTypeEntry::Deprecated); + } else if (name == disableWrapperAttribute()) { + if (convertBoolean(attributes->takeAt(i).value(), disableWrapperAttribute(), false)) + ctype->setTypeFlags(ctype->typeFlags() | ComplexTypeEntry::DisableWrapper); } else if (name == deleteInMainThreadAttribute()) { if (convertBoolean(attributes->takeAt(i).value(), deleteInMainThreadAttribute(), false)) ctype->setDeleteInMainThread(true); diff --git a/sources/shiboken2/doc/typesystem_specifying_types.rst b/sources/shiboken2/doc/typesystem_specifying_types.rst index 3b40ef236..405469ea2 100644 --- a/sources/shiboken2/doc/typesystem_specifying_types.rst +++ b/sources/shiboken2/doc/typesystem_specifying_types.rst @@ -275,6 +275,7 @@ value-type <value-type name="..." since="..." copyable="yes | no" allow-thread="..." + disable-wrapper="yes | no" exception-handling="..." hash-function="..." stream="yes | no" @@ -300,6 +301,8 @@ value-type on its constructor signatures, thus **default-constructor** is used only in very odd cases. + For the *optional* **disable-wrapper** attribute, see :ref:`object-type`. + The **revision** attribute can be used to specify a revision for each type, easing the production of ABI compatible bindings. @@ -323,6 +326,7 @@ object-type since="..." copyable="yes | no" allow-thread="..." + disable-wrapper="yes | no" exception-handling="..." hash-function="..." stream="yes | no" @@ -335,6 +339,14 @@ object-type **copyable** and **hash-function** attributes are the same as described for :ref:`value-type`. + The *optional* **disable-wrapper** attribute disables the generation of a + **C++ Wrapper** (see :ref:`codegenerationterminology`). This will + effectively disable overriding virtuals methods in Python for the class. + It can be used when the class cannot be instantiated from Python and + its virtual methods pose some problem for the code generator (by returning + references, or using a default value that cannot be generated for a + parameter, or similar). + The *optional* attribute **stream** specifies whether this type will be able to use externally defined operators, like QDataStream << and >>. If equals to **yes**, these operators will be called as normal methods within the current class. diff --git a/sources/shiboken2/generator/shiboken/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken/shibokengenerator.cpp index c097f4355..5382b3a9f 100644 --- a/sources/shiboken2/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken/shibokengenerator.cpp @@ -300,8 +300,11 @@ QString ShibokenGenerator::translateTypeForWrapperMethod(const AbstractMetaType bool ShibokenGenerator::shouldGenerateCppWrapper(const AbstractMetaClass *metaClass) const { - if (metaClass->isNamespace() || (metaClass->attributes() & AbstractMetaAttributes::FinalCppClass)) + if (metaClass->isNamespace() + || metaClass->attributes().testFlag(AbstractMetaAttributes::FinalCppClass) + || metaClass->typeEntry()->typeFlags().testFlag(ComplexTypeEntry::DisableWrapper)) { return false; + } bool result = metaClass->isPolymorphic() || metaClass->hasVirtualDestructor(); if (avoidProtectedHack()) { result = result || metaClass->hasProtectedFields() || metaClass->hasProtectedDestructor(); |