diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-18 10:09:16 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-18 15:04:46 +0200 |
commit | d1fb46645309780437743052159468f743e28d68 (patch) | |
tree | 465ca79619068b82d099bed2c3c5d5332428ba89 /sources/shiboken2 | |
parent | dc7acd1f2dc750c3c8602203ae1558b0e60a3c17 (diff) |
shiboken2: Add attribute for generating "using namespace"
Make it possible to turn off the generation of
using namespace. This is required in Qt 6 to avoid
a clash between Qt3DCore::QBuffer and QBuffer used
in __repr__.
Task-number: PYSIDE-1339
Task-number: PYSIDE-904
Change-Id: Iaaf3e67f0ffaae86e2de82b9a1b8fe7d00c74e6b
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2')
4 files changed, 18 insertions, 2 deletions
diff --git a/sources/shiboken2/ApiExtractor/typesystem.h b/sources/shiboken2/ApiExtractor/typesystem.h index 9d97f5c93..b31cee9cd 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.h +++ b/sources/shiboken2/ApiExtractor/typesystem.h @@ -1527,6 +1527,9 @@ public: void formatDebug(QDebug &d) const override; #endif + bool generateUsing() const { return m_generateUsing; } + void setGenerateUsing(bool generateUsing) { m_generateUsing = generateUsing; } + protected: NamespaceTypeEntry(const NamespaceTypeEntry &); @@ -1536,6 +1539,7 @@ private: TypeSystem::Visibility m_visibility = TypeSystem::Visibility::Auto; bool m_hasPattern = false; bool m_inlineNamespace = false; + bool m_generateUsing = true; // Whether to generate "using namespace" into wrapper }; class ValueTypeEntry : public ComplexTypeEntry diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.cpp b/sources/shiboken2/ApiExtractor/typesystemparser.cpp index 207c99c7a..a56c5c698 100644 --- a/sources/shiboken2/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken2/ApiExtractor/typesystemparser.cpp @@ -67,6 +67,7 @@ static inline QString flagsAttribute() { return QStringLiteral("flags"); } static inline QString forceAbstractAttribute() { return QStringLiteral("force-abstract"); } static inline QString forceIntegerAttribute() { return QStringLiteral("force-integer"); } static inline QString formatAttribute() { return QStringLiteral("format"); } +static inline QString generateUsingAttribute() { return QStringLiteral("generate-using"); } static inline QString classAttribute() { return QStringLiteral("class"); } static inline QString generateAttribute() { return QStringLiteral("generate"); } static inline QString genericClassAttribute() { return QStringLiteral("generic-class"); } @@ -1374,6 +1375,8 @@ NamespaceTypeEntry * } else if (attributeName == generateAttribute()) { if (!convertBoolean(attributes->takeAt(i).value(), generateAttribute(), true)) visibility = TypeSystem::Visibility::Invisible; + } else if (attributeName == generateUsingAttribute()) { + result->setGenerateUsing(convertBoolean(attributes->takeAt(i).value(), generateUsingAttribute(), true)); } } diff --git a/sources/shiboken2/doc/typesystem_specifying_types.rst b/sources/shiboken2/doc/typesystem_specifying_types.rst index 27267faab..221519541 100644 --- a/sources/shiboken2/doc/typesystem_specifying_types.rst +++ b/sources/shiboken2/doc/typesystem_specifying_types.rst @@ -155,6 +155,7 @@ namespace-type <namespace-type name="..." visible="true | auto | false" generate="yes | no" + generate-using="yes | no" package="..." since="..." revision="..." /> @@ -173,6 +174,13 @@ namespace-type The *optional* **generate** is a legacy attribute. Specifying **no** is equivalent to **visible="false"**. + The *optional* **generate-using** attribute specifies whether + ``using namespace`` is generated into the wrapper code for classes within + the namespace (default: **yes**). This ensures for example that not fully + qualified enumeration values of default argument values compile. + However, in rare cases, it might cause ambiguities and can then be turned + off. + The **package** attribute can be used to override the package of the type system. The *optional* **since** value is used to specify the API version of this type. diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index d38463e2c..7a4f59cf3 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -404,8 +404,9 @@ void CppGenerator::generateClass(QTextStream &s, const GeneratorContext &classCo { const AbstractMetaClass *context = metaClass->enclosingClass(); while (context) { - if (context->isNamespace() && !context->enclosingClass()) { - s << "using namespace " << context->qualifiedCppName() << ";\n"; + if (context->isNamespace() && !context->enclosingClass() + && static_cast<const NamespaceTypeEntry *>(context->typeEntry())->generateUsing()) { + s << "\nusing namespace " << context->qualifiedCppName() << ";\n"; break; } context = context->enclosingClass(); |