From 844f76cf8e01377fa3de6ac8c61eb8342c0c31f1 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 2 Dec 2020 10:35:13 +0100 Subject: shiboken6: Remove deprecated typesystem tags and were deprecated in favor of attributes on the functions in PySide2. Similarly for , but it is still used as a child of . Leave this usage in place, but add parsing of the rename attribute to . Change-Id: I8e80ba13a3e4af1df0448bd0de034d242a9fdeb4 Reviewed-by: Christian Tismer --- .../ApiExtractor/tests/testaddfunction.cpp | 28 +++--- .../ApiExtractor/tests/testdroptypeentries.cpp | 15 ++- .../ApiExtractor/tests/testimplicitconversions.cpp | 17 ++-- .../ApiExtractor/tests/testmodifyfunction.cpp | 13 ++- .../shiboken6/ApiExtractor/typesystemparser.cpp | 101 ++++----------------- sources/shiboken6/ApiExtractor/typesystemparser.h | 10 +- sources/shiboken6/doc/typesystem_arguments.rst | 2 + .../shiboken6/doc/typesystem_modify_function.rst | 53 +---------- 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[] = "\ - \n\ - \n\ - \n\ - \n\ - \n\ - custom_code();\n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n"; + const char xmlCode[] = R"( + + + + + + custom_code(); + + + + + + +)"; QScopedPointer 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 = "\ -\n\ - \n\ - \n\ - \n\ - \n\ - \n\ -\n"; +static const char* xmlCode2 = R"( + + + + + +)"; 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 = "\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n"; + const char* xmlCode = R"( + + + + + + +)"; QScopedPointer 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() \n\ \n\ \n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n"; + const char xmlCode2[] = R"('> + + + + +)"; const QByteArray xmlCode = QByteArray(xmlCode1) + pattern + QByteArray(xmlCode2); QScopedPointer 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 +.. 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 - + // modifications @@ -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 - - - - - - .. 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 - - - - - - .. 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 - - - - - - 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. -- cgit v1.2.3