aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sources/shiboken6/ApiExtractor/tests/testaddfunction.cpp28
-rw-r--r--sources/shiboken6/ApiExtractor/tests/testdroptypeentries.cpp15
-rw-r--r--sources/shiboken6/ApiExtractor/tests/testimplicitconversions.cpp17
-rw-r--r--sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp13
-rw-r--r--sources/shiboken6/ApiExtractor/typesystemparser.cpp101
-rw-r--r--sources/shiboken6/ApiExtractor/typesystemparser.h10
-rw-r--r--sources/shiboken6/doc/typesystem_arguments.rst2
-rw-r--r--sources/shiboken6/doc/typesystem_modify_function.rst53
8 files changed, 62 insertions, 177 deletions
diff --git a/sources/shiboken6/ApiExtractor/tests/testaddfunction.cpp b/sources/shiboken6/ApiExtractor/tests/testaddfunction.cpp
index 7a52b9b33..0d05dfb30 100644
--- a/sources/shiboken6/ApiExtractor/tests/testaddfunction.cpp
+++ b/sources/shiboken6/ApiExtractor/tests/testaddfunction.cpp
@@ -421,20 +421,20 @@ void TestAddFunction::testAddFunctionWithApiVersion()
void TestAddFunction::testModifyAddedFunction()
{
const char cppCode[] = "class Foo { };\n";
- const char xmlCode[] = "\
- <typesystem package='Package'>\n\
- <primitive-type name='float'/>\n\
- <primitive-type name='int'/>\n\
- <value-type name='Foo'>\n\
- <add-function signature='method(float, int)'>\n\
- <inject-code class='target' position='beginning'>custom_code();</inject-code>\n\
- <modify-argument index='2'>\n\
- <replace-default-expression with='0'/>\n\
- <rename to='varName'/>\n\
- </modify-argument>\n\
- </add-function>\n\
- </value-type>\n\
- </typesystem>\n";
+ const char xmlCode[] = R"(
+<typesystem package='Package'>
+ <primitive-type name='float'/>
+ <primitive-type name='int'/>
+ <value-type name='Foo'>
+ <add-function signature='method(float, int)'>
+ <inject-code class='target' position='beginning'>custom_code();</inject-code>
+ <modify-argument index='2' rename='varName'>
+ <replace-default-expression with='0'/>
+ </modify-argument>
+ </add-function>
+ </value-type>
+</typesystem>
+)";
QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode));
QVERIFY(!builder.isNull());
AbstractMetaClassList classes = builder->classes();
diff --git a/sources/shiboken6/ApiExtractor/tests/testdroptypeentries.cpp b/sources/shiboken6/ApiExtractor/tests/testdroptypeentries.cpp
index 20b0c12e0..c47c7232f 100644
--- a/sources/shiboken6/ApiExtractor/tests/testdroptypeentries.cpp
+++ b/sources/shiboken6/ApiExtractor/tests/testdroptypeentries.cpp
@@ -121,14 +121,13 @@ static const char* cppCode2 ="\
void func();\n\
};\n";
-static const char* xmlCode2 = "\
-<typesystem package='Foo'>\n\
- <value-type name='ValueA'>\n\
- <modify-function signature='func()'>\n\
- <remove class='all'/>\n\
- </modify-function>\n\
- </value-type>\n\
-</typesystem>\n";
+static const char* xmlCode2 = R"(
+<typesystem package='Foo'>
+ <value-type name='ValueA'>
+ <modify-function signature='func()' remove='all'/>
+ </value-type>
+</typesystem>
+)";
void TestDropTypeEntries::testDropEntryWithChildTags()
{
diff --git a/sources/shiboken6/ApiExtractor/tests/testimplicitconversions.cpp b/sources/shiboken6/ApiExtractor/tests/testimplicitconversions.cpp
index 928122967..9dcdec975 100644
--- a/sources/shiboken6/ApiExtractor/tests/testimplicitconversions.cpp
+++ b/sources/shiboken6/ApiExtractor/tests/testimplicitconversions.cpp
@@ -73,15 +73,14 @@ void TestImplicitConversions::testWithModifiedVisibility()
A(const B&);\n\
};\n\
class B {};\n";
- const char* xmlCode = "\
- <typesystem package='Foo'>\n\
- <value-type name='A'>\n\
- <modify-function signature='A(const B&amp;)'>\n\
- <access modifier='private'/>\n\
- </modify-function>\n\
- </value-type>\n\
- <value-type name='B'/>\n\
- </typesystem>\n";
+ const char* xmlCode = R"(
+<typesystem package='Foo'>
+ <value-type name='A'>
+ <modify-function signature='A(const B&amp;)' access='private'/>
+ </value-type>
+ <value-type name='B'/>
+</typesystem>
+)";
QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode));
QVERIFY(!builder.isNull());
AbstractMetaClassList classes = builder->classes();
diff --git a/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp b/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp
index 0fa07b75c..ebee345a0 100644
--- a/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp
+++ b/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp
@@ -54,13 +54,12 @@ void TestModifyFunction::testRenameArgument()
<primitive-type name='int'/>\n\
<object-type name='A'>\n\
<modify-function signature='";
- const char xmlCode2[] = "'>\n\
- <modify-argument index='1'>\n\
- <rename to='otherArg'/>\n\
- </modify-argument>\n\
- </modify-function>\n\
- </object-type>\n\
- </typesystem>\n";
+ const char xmlCode2[] = R"('>
+ <modify-argument index='1' rename='otherArg'/>
+ </modify-function>
+ </object-type>
+ </typesystem>
+)";
const QByteArray xmlCode = QByteArray(xmlCode1) + pattern + QByteArray(xmlCode2);
QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode.constData(), false));
diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.cpp b/sources/shiboken6/ApiExtractor/typesystemparser.cpp
index b56fef22a..da70ec72a 100644
--- a/sources/shiboken6/ApiExtractor/typesystemparser.cpp
+++ b/sources/shiboken6/ApiExtractor/typesystemparser.cpp
@@ -342,8 +342,7 @@ ENUM_LOOKUP_LINEAR_SEARCH()
ENUM_LOOKUP_BEGIN(StackElement::ElementType, Qt::CaseInsensitive,
elementFromTag, StackElement::None)
{
- {u"access", StackElement::Access}, // sorted!
- {u"add-conversion", StackElement::AddConversion},
+ {u"add-conversion", StackElement::AddConversion}, // sorted!
{u"add-function", StackElement::AddFunction},
{u"array", StackElement::Array},
{u"container-type", StackElement::ContainerTypeEntry},
@@ -376,10 +375,9 @@ ENUM_LOOKUP_BEGIN(StackElement::ElementType, Qt::CaseInsensitive,
{u"reference-count", StackElement::ReferenceCount},
{u"reject-enum-value", StackElement::RejectEnumValue},
{u"rejection", StackElement::Rejection},
- {u"remove", StackElement::Removal},
{u"remove-argument", StackElement::RemoveArgument},
{u"remove-default-expression", StackElement::RemoveDefaultExpression},
- {u"rename", StackElement::Rename},
+ {u"rename", StackElement::Rename}, // ### fixme PySide7: remove
{u"replace", StackElement::Replace},
{u"replace-default-expression", StackElement::ReplaceDefaultExpression},
{u"replace-type", StackElement::ReplaceType},
@@ -1975,6 +1973,7 @@ bool TypeSystemParser::parseModifyArgument(const QXmlStreamReader &,
QString index;
QString replaceValue;
+ QString renameTo;
bool resetAfterUse = false;
for (int i = attributes->size() - 1; i >= 0; --i) {
const auto name = attributes->at(i).qualifiedName();
@@ -1985,6 +1984,8 @@ bool TypeSystemParser::parseModifyArgument(const QXmlStreamReader &,
} else if (name == invalidateAfterUseAttribute()) {
resetAfterUse = convertBoolean(attributes->takeAt(i).value(),
invalidateAfterUseAttribute(), false);
+ } else if (name == renameAttribute()) {
+ renameTo = attributes->takeAt(i).value().toString();
}
}
@@ -2005,6 +2006,7 @@ bool TypeSystemParser::parseModifyArgument(const QXmlStreamReader &,
ArgumentModification argumentModification = ArgumentModification(idx);
argumentModification.replace_value = replaceValue;
argumentModification.resetAfterUse = resetAfterUse;
+ argumentModification.renamed_to = renameTo;
m_contextStack.top()->functionMods.last().argument_mods().append(argumentModification);
return true;
}
@@ -2063,83 +2065,23 @@ bool TypeSystemParser::parseDefineOwnership(const QXmlStreamReader &,
return true;
}
-bool TypeSystemParser::parseRemoval(const QXmlStreamReader &,
- const StackElement &topElement,
- QXmlStreamAttributes *attributes)
-{
- if (topElement.type != StackElement::ModifyFunction) {
- m_error = QLatin1String("Function modification parent required");
- return false;
- }
-
- TypeSystem::Language lang = TypeSystem::All;
- const int classIndex = indexOfAttribute(*attributes, classAttribute());
- if (classIndex != -1) {
- const auto value = attributes->takeAt(classIndex).value();
- lang = languageFromAttribute(value);
- if (lang == TypeSystem::TargetLangCode) // "target" means TargetLangAndNativeCode here
- lang = TypeSystem::TargetLangAndNativeCode;
- if (lang != TypeSystem::TargetLangAndNativeCode && lang != TypeSystem::All) {
- m_error = QStringLiteral("unsupported class attribute: '%1'").arg(value);
- return false;
- }
- }
- m_contextStack.top()->functionMods.last().setRemoval(lang);
- return true;
-}
-
-bool TypeSystemParser::parseRename(const QXmlStreamReader &reader,
- StackElement::ElementType type,
+// ### fixme PySide7: remove (replaced by attribute).
+bool TypeSystemParser::parseRename(const QXmlStreamReader &,
const StackElement &topElement,
QXmlStreamAttributes *attributes)
{
- if (topElement.type != StackElement::ModifyField
- && topElement.type != StackElement::ModifyFunction
- && topElement.type != StackElement::ModifyArgument) {
- m_error = QLatin1String("Function, field or argument modification parent required");
+ if (topElement.type != StackElement::ModifyArgument) {
+ m_error = QLatin1String("Argument modification parent required");
return false;
}
- Modification *mod = nullptr;
- if (topElement.type == StackElement::ModifyFunction)
- mod = &m_contextStack.top()->functionMods.last();
- else if (topElement.type == StackElement::ModifyField)
- mod = &m_contextStack.top()->fieldMods.last();
-
- Modification::ModifierFlag modifierFlag = Modification::Rename;
- if (type == StackElement::Rename) {
- const int toIndex = indexOfAttribute(*attributes, toAttribute());
- if (toIndex == -1) {
- m_error = msgMissingAttribute(toAttribute());
- return false;
- }
- const QString renamed_to = attributes->takeAt(toIndex).value().toString();
- if (topElement.type == StackElement::ModifyFunction)
- mod->setRenamedToName(renamed_to);
- else if (topElement.type == StackElement::ModifyField)
- mod->setRenamedToName(renamed_to);
- else
- m_contextStack.top()->functionMods.last().argument_mods().last().renamed_to = renamed_to;
- } else {
- const int modifierIndex = indexOfAttribute(*attributes, modifierAttribute());
- if (modifierIndex == -1) {
- m_error = msgMissingAttribute(modifierAttribute());
- return false;
- }
- const auto modifier = attributes->takeAt(modifierIndex).value();
- modifierFlag = modifierFromAttribute(modifier);
- if (modifierFlag == Modification::InvalidModifier) {
- m_error = QStringLiteral("Unknown access modifier: '%1'").arg(modifier);
- return false;
- }
- if (modifierFlag == Modification::Friendly) {
- qCWarning(lcShiboken, "%s",
- qPrintable(msgUnimplementedAttributeValueWarning(reader, modifierAttribute(), modifier)));
- }
+ const int toIndex = indexOfAttribute(*attributes, toAttribute());
+ if (toIndex == -1) {
+ m_error = msgMissingAttribute(toAttribute());
+ return false;
}
-
- if (mod)
- mod->setModifierFlag(modifierFlag);
+ const QString renamed_to = attributes->takeAt(toIndex).value().toString();
+ m_contextStack.top()->functionMods.last().argument_mods().last().renamed_to = renamed_to;
return true;
}
@@ -3038,15 +2980,10 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader)
}
}
break;
- case StackElement::Removal:
- if (!parseRemoval(reader, topElement, &attributes))
- return false;
- break;
case StackElement::Rename:
- case StackElement::Access:
- if (!parseRename(reader, element->type, topElement, &attributes))
- return false;
- break;
+ if (!parseRename(reader, topElement, &attributes))
+ return false;
+ break;
case StackElement::RemoveArgument:
if (topElement.type != StackElement::ModifyArgument) {
m_error = QLatin1String("Removing argument requires argument modification as parent");
diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.h b/sources/shiboken6/ApiExtractor/typesystemparser.h
index af310d8dc..8bef9482e 100644
--- a/sources/shiboken6/ApiExtractor/typesystemparser.h
+++ b/sources/shiboken6/ApiExtractor/typesystemparser.h
@@ -99,9 +99,7 @@ class StackElement
CodeSnipMask = 0xc000,
// Function modifier tags (0x010000, 0x020000, ... , 0xf00000)
- Access = 0x010000,
- Removal = 0x020000,
- Rename = 0x040000,
+ Rename = 0x040000, // (modify-argument)
ModifyArgument = 0x080000,
Thread = 0x100000,
FunctionModifiers = 0xff0000,
@@ -226,10 +224,8 @@ private:
QXmlStreamAttributes *attributes);
bool parseDefineOwnership(const QXmlStreamReader &, const StackElement &topElement,
QXmlStreamAttributes *);
- bool parseRemoval(const QXmlStreamReader &, const StackElement &topElement,
- QXmlStreamAttributes *);
- bool parseRename(const QXmlStreamReader &, StackElement::ElementType type,
- const StackElement &topElement, QXmlStreamAttributes *);
+ bool parseRename(const QXmlStreamReader &, const StackElement &topElement,
+ QXmlStreamAttributes *);
bool parseModifyField(const QXmlStreamReader &, QXmlStreamAttributes *);
bool parseAddFunction(const QXmlStreamReader &, const StackElement &topElement,
StackElement::ElementType t, QXmlStreamAttributes *);
diff --git a/sources/shiboken6/doc/typesystem_arguments.rst b/sources/shiboken6/doc/typesystem_arguments.rst
index bce0914e3..658da4295 100644
--- a/sources/shiboken6/doc/typesystem_arguments.rst
+++ b/sources/shiboken6/doc/typesystem_arguments.rst
@@ -64,6 +64,8 @@ rename to
<rename to='...' />
</modify-argument>
+.. warning:: This tag is deprecated, use the ``rename`` attribute from :ref:`modify-argument` tag instead.
+
.. _remove-default-expression:
remove-default-expression
diff --git a/sources/shiboken6/doc/typesystem_modify_function.rst b/sources/shiboken6/doc/typesystem_modify_function.rst
index 071cea4f5..d7ed13b07 100644
--- a/sources/shiboken6/doc/typesystem_modify_function.rst
+++ b/sources/shiboken6/doc/typesystem_modify_function.rst
@@ -17,7 +17,7 @@ modify-argument
.. code-block:: xml
<modify-function>
- <modify-argument index="return | this | 1 ..." >
+ <modify-argument index="return | this | 1 ..." rename="...">
// modifications
</modify-argument>
</modify-function>
@@ -27,52 +27,5 @@ modify-argument
modify the function's return value or the object the function is called upon,
respectively.
-.. _remove:
-
-remove
-^^^^^^
-
- The remove node removes the given method from the generated target language
- API, and it is a child of the modify-function node.
-
- .. code-block:: xml
-
- <modify-function>
- <remove class="all" />
- </modify-function>
-
- .. warning:: This tag is deprecated, use the ``remove`` attribute from :ref:`modify-function` tag instead.
-
-.. _access:
-
-access
-^^^^^^
-
- The access node changes the access privileges of the given function in the
- generated target language API, and it is a child of the modify-function node.
-
- .. code-block:: xml
-
- <modify-function>
- <access modifier="public | protected | private"/>
- </modify-function>
-
- .. warning:: This tag is deprecated, use the ``access`` attribute from :ref:`modify-function` tag instead.
-
-.. _rename:
-
-rename
-^^^^^^
-
- The rename node changes the name of the given function in the generated target
- language API, and it is a child of the modify-function node.
-
- .. code-block:: xml
-
- <modify-function>
- <rename to="..." />
- </modify-function>
-
- The ``to`` attribute is the new name of the function.
-
- .. warning:: This tag is deprecated, use the ``rename`` attribute from :ref:`modify-function` tag instead.
+ The optional ``rename`` attribute is used to rename a argument and use this
+ new name in the generated code.