aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-09-01 13:17:01 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2023-12-08 10:31:48 +0100
commit07c06735e8974feb8c88fc7bd58cfe2a3439066c (patch)
tree42e22421b54c2d96c2094efded3fca1b59d36869
parentd65c62812ef956dc315dacd89903a7c8012f3b29 (diff)
Add a submodule attribute to the typesystem
Add an attribute and let it generate the AddObject() call. As a drive-by, remove documentation of the (unimplemented) default-superclass attribute. [ChangeLog][shiboken6] An attribute to generate submodules has been added to the typesystem. Fixes: PYSIDE-2447 Change-Id: Ibecdb96a7c2cf02e42fff81b034ce15c6a516098 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
-rw-r--r--sources/shiboken6/ApiExtractor/typesystem.cpp13
-rw-r--r--sources/shiboken6/ApiExtractor/typesystemparser.cpp5
-rw-r--r--sources/shiboken6/ApiExtractor/typesystemtypeentry.h4
-rw-r--r--sources/shiboken6/doc/typesystem_specifying_types.rst8
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp22
5 files changed, 47 insertions, 5 deletions
diff --git a/sources/shiboken6/ApiExtractor/typesystem.cpp b/sources/shiboken6/ApiExtractor/typesystem.cpp
index e5b3b63a9..0ee70e683 100644
--- a/sources/shiboken6/ApiExtractor/typesystem.cpp
+++ b/sources/shiboken6/ApiExtractor/typesystem.cpp
@@ -666,6 +666,7 @@ public:
CodeSnipList m_codeSnips;
TypeSystem::SnakeCase m_snakeCase = TypeSystem::SnakeCase::Disabled;
+ QString m_subModuleOf;
};
TypeSystemTypeEntry::TypeSystemTypeEntry(const QString &entryName, const QVersionNumber &vr,
@@ -703,6 +704,18 @@ void TypeSystemTypeEntry::addCodeSnip(const CodeSnip &codeSnip)
d->m_codeSnips.append(codeSnip);
}
+QString TypeSystemTypeEntry::subModuleOf() const
+{
+ S_D(const TypeSystemTypeEntry);
+ return d->m_subModuleOf;
+}
+
+void TypeSystemTypeEntry::setSubModule(const QString &s)
+{
+ S_D(TypeSystemTypeEntry);
+ d->m_subModuleOf = s;
+}
+
TypeSystem::SnakeCase TypeSystemTypeEntry::snakeCase() const
{
S_D(const TypeSystemTypeEntry);
diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.cpp b/sources/shiboken6/ApiExtractor/typesystemparser.cpp
index cf1b70332..129aefc82 100644
--- a/sources/shiboken6/ApiExtractor/typesystemparser.cpp
+++ b/sources/shiboken6/ApiExtractor/typesystemparser.cpp
@@ -114,6 +114,7 @@ constexpr auto xPathAttribute = "xpath"_L1;
constexpr auto virtualSlotAttribute = "virtual-slot"_L1;
constexpr auto visibleAttribute = "visible"_L1;
constexpr auto enumIdentifiedByValueAttribute = "identified-by-value"_L1;
+constexpr auto subModuleOfAttribute = "submodule-of"_L1;
constexpr auto noAttributeValue = "no"_L1;
constexpr auto yesAttributeValue = "yes"_L1;
@@ -2088,6 +2089,7 @@ TypeSystemTypeEntryPtr TypeSystemParser::parseRootElement(const ConditionalStrea
QXmlStreamAttributes *attributes)
{
TypeSystem::SnakeCase snakeCase = TypeSystem::SnakeCase::Unspecified;
+ QString subModuleOf;
for (auto i = attributes->size() - 1; i >= 0; --i) {
const auto name = attributes->at(i).qualifiedName();
@@ -2122,6 +2124,8 @@ TypeSystemTypeEntryPtr TypeSystemParser::parseRootElement(const ConditionalStrea
qCWarning(lcShiboken, "%s",
qPrintable(msgInvalidAttributeValue(attribute)));
}
+ } else if (name == subModuleOfAttribute) {
+ subModuleOf = attributes->takeAt(i).value().toString();
}
}
@@ -2138,6 +2142,7 @@ TypeSystemTypeEntryPtr TypeSystemParser::parseRootElement(const ConditionalStrea
if (add) {
moduleEntry.reset(new TypeSystemTypeEntry(m_defaultPackage, since,
currentParentTypeEntry()));
+ moduleEntry->setSubModule(subModuleOf);
}
moduleEntry->setCodeGeneration(m_generate);
moduleEntry->setSnakeCase(snakeCase);
diff --git a/sources/shiboken6/ApiExtractor/typesystemtypeentry.h b/sources/shiboken6/ApiExtractor/typesystemtypeentry.h
index bd69058d2..f5df1bb7c 100644
--- a/sources/shiboken6/ApiExtractor/typesystemtypeentry.h
+++ b/sources/shiboken6/ApiExtractor/typesystemtypeentry.h
@@ -5,6 +5,7 @@
#define TYPESYSTEMTYPEENTRY_H
#include "typesystem.h"
+#include "modifications_typedefs.h"
#include "typesystem_enums.h"
#include "typesystem_typedefs.h"
@@ -23,6 +24,9 @@ public:
CodeSnipList &codeSnips();
void addCodeSnip(const CodeSnip &codeSnip);
+ QString subModuleOf() const;
+ void setSubModule(const QString &);
+
protected:
explicit TypeSystemTypeEntry(TypeEntryPrivate *d);
};
diff --git a/sources/shiboken6/doc/typesystem_specifying_types.rst b/sources/shiboken6/doc/typesystem_specifying_types.rst
index 7152c70af..86c6149d9 100644
--- a/sources/shiboken6/doc/typesystem_specifying_types.rst
+++ b/sources/shiboken6/doc/typesystem_specifying_types.rst
@@ -43,14 +43,16 @@ It can have a number of attributes, described below.
.. code-block:: xml
- <typesystem package="..." default-superclass="..." allow-thread="..."
+ <typesystem package="..." submodule-of="..." allow-thread="..."
exception-handling="..." snake-case="yes | no | both" >
</typesystem>
The **package** attribute is a string describing the package to be used,
e.g. "QtCore".
-The *optional* **default-superclass** attribute is the canonical C++ base class
-name of all objects, e.g., "object".
+
+The *optional* **submodule-of** attribute specifies the name of a module to
+which the module is added as a sub-module. This requires adapting the
+installation directory of the module accordingly.
The *optional* attributes **allow-thread** and **exception-handling**
specify the default handling for the corresponding function modification
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 6e26e565a..b1b29d4d4 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -5846,6 +5846,19 @@ void CppGenerator::writeInitFunc(TextStream &declStr, TextStream &callStr,
}
}
+static void writeSubModuleHandling(TextStream &s, const QString &moduleName,
+ const QString &subModuleOf)
+{
+ s << "{\n" << indent
+ << "Shiboken::AutoDecRef parentModule(Shiboken::Module::import(\""
+ << subModuleOf << "\"));\n"
+ << "if (parentModule.isNull())\n" << indent
+ << "return nullptr;\n" << outdent
+ << "if (PyModule_AddObject(parentModule.object(), \"" << moduleName
+ << "\", module) < 0)\n"
+ << indent << "return nullptr;\n" << outdent << outdent << "}\n";
+}
+
bool CppGenerator::finishGeneration()
{
//Generate CPython wrapper file
@@ -6164,8 +6177,13 @@ bool CppGenerator::finishGeneration()
<< "PyObject *module = Shiboken::Module::create(\"" << moduleName()
<< "\", &moduledef);\n\n"
<< "// Make module available from global scope\n"
- << globalModuleVar << " = module;\n\n"
- << "// Initialize classes in the type system\n"
+ << globalModuleVar << " = module;\n\n";
+
+ const QString subModuleOf = typeDb->defaultTypeSystemType()->subModuleOf();
+ if (!subModuleOf.isEmpty())
+ writeSubModuleHandling(s, moduleName(), subModuleOf);
+
+ s << "// Initialize classes in the type system\n"
<< s_classPythonDefines.toString();
if (!typeConversions.isEmpty()) {