summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-11-23 12:17:10 +0100
committerAlexandru Croitor <alexandru.croitor@qt.io>2018-11-28 11:44:47 +0000
commitaddfdfb1ff195e36d412dc7aa3dde2f2d474c0ed (patch)
tree8ad1dc69e459d304f2cc264ac69b90e408aaeb28
parentfce66005075ed04c99a313c243402d7bef2028ca (diff)
shiboken: Add file snippet handling to native-to-target and add-conversion
Task-number: PYSIDE-834 Change-Id: I3daad497ed32a56c05c8dc2b06271e243d579b99 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/shiboken2/ApiExtractor/doc/typesystem_conversionrule.rst3
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem.cpp25
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem_p.h2
3 files changed, 25 insertions, 5 deletions
diff --git a/sources/shiboken2/ApiExtractor/doc/typesystem_conversionrule.rst b/sources/shiboken2/ApiExtractor/doc/typesystem_conversionrule.rst
index c62d5bbf..27e7a72d 100644
--- a/sources/shiboken2/ApiExtractor/doc/typesystem_conversionrule.rst
+++ b/sources/shiboken2/ApiExtractor/doc/typesystem_conversionrule.rst
@@ -63,6 +63,7 @@ native-to-target
**%INTYPE_#**, should be replaced by the types used in the container template
(e.g. **%INTYPE_0** correspondes to **"int"** for **"list<int>"**).
+ The ``file`` and ``snippet`` attributes are also supported (see :ref:`inject-code` nodes).
.. _target-to-native:
@@ -111,3 +112,5 @@ add-conversion
**%in**, **%out**, **%INTYPE**, **%INTYPE_#**, and **%OUTTYPE**, must be provided by
the generator as in the ``native-to-target`` tag.
+ The ``file`` and ``snippet`` attributes are also supported (see :ref:`inject-code` nodes).
+
diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp
index aa4147d7..e82221a4 100644
--- a/sources/shiboken2/ApiExtractor/typesystem.cpp
+++ b/sources/shiboken2/ApiExtractor/typesystem.cpp
@@ -1632,6 +1632,21 @@ bool Handler::parseCustomConversion(const QXmlStreamReader &,
return true;
}
+bool Handler::parseNativeToTarget(const QXmlStreamReader &,
+ const StackElement &topElement,
+ QXmlStreamAttributes *attributes)
+{
+ if (topElement.type != StackElement::ConversionRule) {
+ m_error = QLatin1String("Native to Target conversion code can only be specified for custom conversion rules.");
+ return false;
+ }
+ CodeSnip snip;
+ if (!readFileSnippet(attributes, &snip))
+ return false;
+ m_contextStack.top()->codeSnips.append(snip);
+ return true;
+}
+
bool Handler::parseAddConversion(const QXmlStreamReader &,
const StackElement &topElement,
QXmlStreamAttributes *attributes)
@@ -1642,6 +1657,9 @@ bool Handler::parseAddConversion(const QXmlStreamReader &,
}
QString sourceTypeName;
QString typeCheck;
+ CodeSnip snip;
+ if (!readFileSnippet(attributes, &snip))
+ return false;
for (int i = attributes->size() - 1; i >= 0; --i) {
const QStringRef name = attributes->at(i).qualifiedName();
if (name == QLatin1String("type"))
@@ -1654,7 +1672,7 @@ bool Handler::parseAddConversion(const QXmlStreamReader &,
return false;
}
m_current->entry->customConversion()->addTargetToNativeConversion(sourceTypeName, typeCheck);
- m_contextStack.top()->codeSnips << CodeSnip();
+ m_contextStack.top()->codeSnips.append(snip);
return true;
}
@@ -2670,11 +2688,8 @@ bool Handler::startElement(const QXmlStreamReader &reader)
return false;
break;
case StackElement::NativeToTarget:
- if (topElement.type != StackElement::ConversionRule) {
- m_error = QLatin1String("Native to Target conversion code can only be specified for custom conversion rules.");
+ if (!parseNativeToTarget(reader, topElement, &attributes))
return false;
- }
- m_contextStack.top()->codeSnips << CodeSnip();
break;
case StackElement::TargetToNative: {
if (topElement.type != StackElement::ConversionRule) {
diff --git a/sources/shiboken2/ApiExtractor/typesystem_p.h b/sources/shiboken2/ApiExtractor/typesystem_p.h
index 3ebdf47d..a617110d 100644
--- a/sources/shiboken2/ApiExtractor/typesystem_p.h
+++ b/sources/shiboken2/ApiExtractor/typesystem_p.h
@@ -198,6 +198,8 @@ private:
QXmlStreamAttributes *);
bool parseAddConversion(const QXmlStreamReader &, const StackElement &topElement,
QXmlStreamAttributes *);
+ bool parseNativeToTarget(const QXmlStreamReader &, const StackElement &topElement,
+ QXmlStreamAttributes *attributes);
bool parseModifyArgument(const QXmlStreamReader &, const StackElement &topElement,
QXmlStreamAttributes *attributes);
bool parseNoNullPointer(const QXmlStreamReader &, const StackElement &topElement,