aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-06-18 11:22:46 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-06-19 21:38:59 +0200
commitab9033719f0ee6319c5f2a4b474aac0eb1ad2ac2 (patch)
tree0ad799fb266e4c7d3db32e62c00d0c1dacf11517 /sources
parent2d174a7fa78944b094ff7056454236b4560c0092 (diff)
shiboken2: Clean up code injection attributes
Remove the unused enumeration values. Change the class of the "declaration" position from "native" to "shell" since that is where it is used and mention it in the documentation. Task-number: PYSIDE-1282 Change-Id: I547b4bab055df27ce8b0b7b41b9d382dc8f175d1 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources')
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem_enums.h19
-rw-r--r--sources/shiboken2/ApiExtractor/typesystemparser.cpp21
-rw-r--r--sources/shiboken2/doc/typesystem_codeinjection.rst133
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp3
4 files changed, 72 insertions, 104 deletions
diff --git a/sources/shiboken2/ApiExtractor/typesystem_enums.h b/sources/shiboken2/ApiExtractor/typesystem_enums.h
index 120c9417f..f6b4b6fa6 100644
--- a/sources/shiboken2/ApiExtractor/typesystem_enums.h
+++ b/sources/shiboken2/ApiExtractor/typesystem_enums.h
@@ -36,21 +36,9 @@ enum Language {
TargetLangCode = 0x0001,
NativeCode = 0x0002,
ShellCode = 0x0004,
- ShellDeclaration = 0x0008,
- PackageInitializer = 0x0010,
- DestructorFunction = 0x0020,
- Constructors = 0x0040,
- Interface = 0x0080,
// masks
- All = TargetLangCode
- | NativeCode
- | ShellCode
- | ShellDeclaration
- | PackageInitializer
- | Constructors
- | Interface
- | DestructorFunction,
+ All = TargetLangCode | NativeCode | ShellCode,
TargetLangAndNativeCode = TargetLangCode | NativeCode
};
@@ -72,12 +60,7 @@ enum Ownership {
enum CodeSnipPosition {
CodeSnipPositionBeginning,
CodeSnipPositionEnd,
- CodeSnipPositionAfterThis,
- // QtScript
CodeSnipPositionDeclaration,
- CodeSnipPositionPrototypeInitialization,
- CodeSnipPositionConstructorInitialization,
- CodeSnipPositionConstructor,
CodeSnipPositionAny,
CodeSnipPositionInvalid
};
diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.cpp b/sources/shiboken2/ApiExtractor/typesystemparser.cpp
index 0ba94d94e..0c4d43e76 100644
--- a/sources/shiboken2/ApiExtractor/typesystemparser.cpp
+++ b/sources/shiboken2/ApiExtractor/typesystemparser.cpp
@@ -207,13 +207,8 @@ ENUM_LOOKUP_BEGIN(TypeSystem::Language, Qt::CaseInsensitive,
languageFromAttribute, TypeSystem::NoLanguage)
{
{u"all", TypeSystem::All}, // sorted!
- {u"constructors", TypeSystem::Constructors},
- {u"destructor-function", TypeSystem::DestructorFunction},
- {u"interface", TypeSystem::Interface},
- {u"library-initializer", TypeSystem::PackageInitializer},
{u"native", TypeSystem::NativeCode}, // em algum lugar do cpp
{u"shell", TypeSystem::ShellCode}, // coloca no header, mas antes da declaracao da classe
- {u"shell-declaration", TypeSystem::ShellDeclaration},
{u"target", TypeSystem::TargetLangCode} // em algum lugar do cpp
};
ENUM_LOOKUP_BINARY_SEARCH()
@@ -272,10 +267,7 @@ ENUM_LOOKUP_BEGIN(TypeSystem::CodeSnipPosition, Qt::CaseInsensitive,
{
{u"beginning", TypeSystem::CodeSnipPositionBeginning},
{u"end", TypeSystem::CodeSnipPositionEnd},
- {u"declaration", TypeSystem::CodeSnipPositionDeclaration},
- {u"prototype-initialization", TypeSystem::CodeSnipPositionPrototypeInitialization},
- {u"constructor-initialization", TypeSystem::CodeSnipPositionConstructorInitialization},
- {u"constructor", TypeSystem::CodeSnipPositionConstructor}
+ {u"declaration", TypeSystem::CodeSnipPositionDeclaration}
};
ENUM_LOOKUP_LINEAR_SEARCH()
@@ -2520,19 +2512,8 @@ bool TypeSystemParser::parseInjectCode(const QXmlStreamReader &,
snip.position = position;
snip.language = lang;
- if (snip.language == TypeSystem::Interface
- && topElement.type != StackElement::InterfaceTypeEntry) {
- m_error = QLatin1String("Interface code injections must be direct child of an interface type entry");
- return false;
- }
-
if (topElement.type == StackElement::ModifyFunction
|| topElement.type == StackElement::AddFunction) {
- if (snip.language == TypeSystem::ShellDeclaration) {
- m_error = QLatin1String("no function implementation in shell declaration in which to inject code");
- return false;
- }
-
FunctionModification &mod = m_contextStack.top()->functionMods.last();
mod.snips << snip;
if (!snip.code().isEmpty())
diff --git a/sources/shiboken2/doc/typesystem_codeinjection.rst b/sources/shiboken2/doc/typesystem_codeinjection.rst
index c891fd2cd..684630dd4 100644
--- a/sources/shiboken2/doc/typesystem_codeinjection.rst
+++ b/sources/shiboken2/doc/typesystem_codeinjection.rst
@@ -47,71 +47,74 @@ inject-code tag
The following table describes the semantics of ``inject-code`` tag as used on
|project|.
- +---------------+------+---------+--------------------------------------------------------------+
- |Parent Tag |Class |Position |Meaning |
- +===============+======+=========+==============================================================+
- |value-type, |native|beginning|Write to the beginning of a class wrapper ``.cpp`` file, right|
- |object-type | | |after the ``#include`` clauses. A common use would be to write|
- | | | |prototypes for custom functions whose definitions are put on a|
- | | | |``native/end`` code injection. |
- | | +---------+--------------------------------------------------------------+
- | | |end |Write to the end of a class wrapper ``.cpp`` file. Could be |
- | | | |used to write custom/helper functions definitions for |
- | | | |prototypes declared on ``native/beginning``. |
- | +------+---------+--------------------------------------------------------------+
- | |target|beginning|Put custom code on the beginning of the wrapper initializer |
- | | | |function (``init_CLASS(PyObject *module)``). This could be |
- | | | |used to manipulate the ``PyCLASS_Type`` structure before |
- | | | |registering it on Python. |
- | | +---------+--------------------------------------------------------------+
- | | |end |Write the given custom code at the end of the class wrapper |
- | | | |initializer function (``init_CLASS(PyObject *module)``). The |
- | | | |code here will be executed after all the wrapped class |
- | | | |components have been initialized. |
- +---------------+------+---------+--------------------------------------------------------------+
- |modify-function|native|beginning|Code here is put on the virtual method override of a C++ |
- | | | |wrapper class (the one responsible for passing C++ calls to a |
- | | | |Python override, if there is any), right after the C++ |
- | | | |arguments have been converted but before the Python call. |
- | | +---------+--------------------------------------------------------------+
- | | |end |This code injection is put in a virtual method override on the|
- | | | |C++ wrapper class, after the call to Python and before |
- | | | |dereferencing the Python method and tuple of arguments. |
- | +------+---------+--------------------------------------------------------------+
- | |target|beginning|This code is injected on the Python method wrapper |
- | | | |(``PyCLASS_METHOD(...)``), right after the decisor have found |
- | | | |which signature to call and also after the conversion of the |
- | | | |arguments to be used, but before the actual call. |
- | | +---------+--------------------------------------------------------------+
- | | |end |This code is injected on the Python method wrapper |
- | | | |(``PyCLASS_METHOD(...)``), right after the C++ method call, |
- | | | |but still inside the scope created by the overload for each |
- | | | |signature. |
- | +------+---------+--------------------------------------------------------------+
- | |shell |beginning|Used only for virtual functions. The code is injected when the|
- | | | |function does not has a Python implementation, then the code |
- | | | |is inserted before c++ call |
- | | +---------+--------------------------------------------------------------+
- | | |end |Same as above, but the code is inserted after c++ call |
- +---------------+------+---------+--------------------------------------------------------------+
- |typesystem |native|beginning|Write code to the beginning of the module ``.cpp`` file, right|
- | | | |after the ``#include`` clauses. This position has a similar |
- | | | |purpose as the ``native/beginning`` position on a wrapper |
- | | | |class ``.cpp`` file, namely write function prototypes, but not|
- | | | |restricted to this use. |
- | | +---------+--------------------------------------------------------------+
- | | |end |Write code to the end of the module ``.cpp`` file. Usually |
- | | | |implementations for function prototypes inserted at the |
- | | | |beginning of the file with a ``native/beginning`` code |
- | | | |injection. |
- | +------+---------+--------------------------------------------------------------+
- | |target|beginning|Insert code at the start of the module initialization function|
- | | | |(``initMODULENAME()``), before the calling ``Py_InitModule``. |
- | | +---------+--------------------------------------------------------------+
- | | |end |Insert code at the end of the module initialization function |
- | | | |(``initMODULENAME()``), but before the checking that emits a |
- | | | |fatal error in case of problems importing the module. |
- +---------------+------+---------+--------------------------------------------------------------+
+ +---------------+------+-----------+--------------------------------------------------------------+
+ |Parent Tag |Class |Position |Meaning |
+ +===============+======+===========+==============================================================+
+ |value-type, |native|beginning |Write to the beginning of a class wrapper ``.cpp`` file, right|
+ |object-type | | |after the ``#include`` clauses. A common use would be to write|
+ | | | |prototypes for custom functions whose definitions are put on a|
+ | | | |``native/end`` code injection. |
+ | | +-----------+--------------------------------------------------------------+
+ | | |end |Write to the end of a class wrapper ``.cpp`` file. Could be |
+ | | | |used to write custom/helper functions definitions for |
+ | | | |prototypes declared on ``native/beginning``. |
+ | +------+-----------+--------------------------------------------------------------+
+ | |target|beginning |Put custom code on the beginning of the wrapper initializer |
+ | | | |function (``init_CLASS(PyObject *module)``). This could be |
+ | | | |used to manipulate the ``PyCLASS_Type`` structure before |
+ | | | |registering it on Python. |
+ | | +-----------+--------------------------------------------------------------+
+ | | |end |Write the given custom code at the end of the class wrapper |
+ | | | |initializer function (``init_CLASS(PyObject *module)``). The |
+ | | | |code here will be executed after all the wrapped class |
+ | | | |components have been initialized. |
+ +---------------+------+-----------+--------------------------------------------------------------+
+ |modify-function|native|beginning |Code here is put on the virtual method override of a C++ |
+ | | | |wrapper class (the one responsible for passing C++ calls to a |
+ | | | |Python override, if there is any), right after the C++ |
+ | | | |arguments have been converted but before the Python call. |
+ | | +-----------+--------------------------------------------------------------+
+ | | |end |This code injection is put in a virtual method override on the|
+ | | | |C++ wrapper class, after the call to Python and before |
+ | | | |dereferencing the Python method and tuple of arguments. |
+ | +------+-----------+--------------------------------------------------------------+
+ | |target|beginning |This code is injected on the Python method wrapper |
+ | | | |(``PyCLASS_METHOD(...)``), right after the decisor have found |
+ | | | |which signature to call and also after the conversion of the |
+ | | | |arguments to be used, but before the actual call. |
+ | | +-----------+--------------------------------------------------------------+
+ | | |end |This code is injected on the Python method wrapper |
+ | | | |(``PyCLASS_METHOD(...)``), right after the C++ method call, |
+ | | | |but still inside the scope created by the overload for each |
+ | | | |signature. |
+ | +------+-----------+--------------------------------------------------------------+
+ | |shell |declaration|Used only for virtual functions. This code is injected at the |
+ | | | |top. |
+ | | +-----------+--------------------------------------------------------------+
+ | | |beginning |Used only for virtual functions. The code is injected when the|
+ | | | |function does not has a Python implementation, then the code |
+ | | | |is inserted before c++ call |
+ | | +-----------+--------------------------------------------------------------+
+ | | |end |Same as above, but the code is inserted after c++ call |
+ +---------------+------+-----------+--------------------------------------------------------------+
+ |typesystem |native|beginning |Write code to the beginning of the module ``.cpp`` file, right|
+ | | | |after the ``#include`` clauses. This position has a similar |
+ | | | |purpose as the ``native/beginning`` position on a wrapper |
+ | | | |class ``.cpp`` file, namely write function prototypes, but not|
+ | | | |restricted to this use. |
+ | | +-----------+--------------------------------------------------------------+
+ | | |end |Write code to the end of the module ``.cpp`` file. Usually |
+ | | | |implementations for function prototypes inserted at the |
+ | | | |beginning of the file with a ``native/beginning`` code |
+ | | | |injection. |
+ | +------+-----------+--------------------------------------------------------------+
+ | |target|beginning |Insert code at the start of the module initialization function|
+ | | | |(``initMODULENAME()``), before the calling ``Py_InitModule``. |
+ | | +-----------+--------------------------------------------------------------+
+ | | |end |Insert code at the end of the module initialization function |
+ | | | |(``initMODULENAME()``), but before the checking that emits a |
+ | | | |fatal error in case of problems importing the module. |
+ +---------------+------+-----------+--------------------------------------------------------------+
Anatomy of Code Injection
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index 34c82f7b2..e7322be33 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -902,7 +902,8 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s,
//Write declaration/native injected code
if (!snips.isEmpty()) {
- writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionDeclaration, TypeSystem::NativeCode, func, lastArg);
+ writeCodeSnips(s, snips, TypeSystem::CodeSnipPositionDeclaration,
+ TypeSystem::ShellCode, func, lastArg);
}
if (wrapperDiagnostics()) {