From 1d044f467070a040713c9566a8a8de3a56c571e7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 14 Oct 2020 09:29:55 +0200 Subject: 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 --- sources/shiboken2/ApiExtractor/typesystem.h | 1 + sources/shiboken2/ApiExtractor/typesystemparser.cpp | 4 ++++ sources/shiboken2/doc/typesystem_specifying_types.rst | 12 ++++++++++++ sources/shiboken2/generator/shiboken/shibokengenerator.cpp | 5 ++++- 4 files changed, 21 insertions(+), 1 deletion(-) (limited to 'sources') 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 >. 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(); -- cgit v1.2.3