diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-12-02 15:14:35 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-12-03 15:52:45 +0000 |
commit | 2f7295a288c76b40e74bf9cd1c87c74379bd285c (patch) | |
tree | 8421d80533608b256232f42a6333b13cdb96b859 /sources/shiboken6 | |
parent | 288fadb796ec4e11e99e3752d531ada7edf15d75 (diff) |
shiboken6: Use a QSharedDataPointer for ArgumentModification
For reasons of consistency and header hygiene.
As a drive by, remove unused argument modification replace-value.
Change-Id: I44d0a244c89f2bf10242544111d23e072df3b480
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6')
10 files changed, 323 insertions, 131 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp index efe2f5ec8..a3c2d3731 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp @@ -1497,13 +1497,13 @@ static void applyDefaultExpressionModifications(const FunctionModificationList & // use replace/remove-default-expression for set default value for (const auto &modification : functionMods) { for (const auto &argumentModification : modification.argument_mods()) { - if (argumentModification.index == i + 1) { - if (argumentModification.removedDefaultExpression) { + if (argumentModification.index() == i + 1) { + if (argumentModification.removedDefaultExpression()) { metaArg->setDefaultValueExpression(QString()); break; } - if (!argumentModification.replacedDefaultExpression.isEmpty()) { - metaArg->setDefaultValueExpression(argumentModification.replacedDefaultExpression); + if (!argumentModification.replacedDefaultExpression().isEmpty()) { + metaArg->setDefaultValueExpression(argumentModification.replacedDefaultExpression()); break; } } @@ -1646,8 +1646,8 @@ void AbstractMetaBuilderPrivate::fixArgumentNames(AbstractMetaFunction *func, co for (const FunctionModification &mod : mods) { for (const ArgumentModification &argMod : mod.argument_mods()) { - if (!argMod.renamed_to.isEmpty()) - arguments[argMod.index - 1].setName(argMod.renamed_to, false); + if (!argMod.renamedToName().isEmpty()) + arguments[argMod.index() - 1].setName(argMod.renamedToName(), false); } } @@ -1710,8 +1710,8 @@ static bool applyArrayArgumentModifications(const FunctionModificationList &func { for (const FunctionModification &mod : functionMods) { for (const ArgumentModification &argMod : mod.argument_mods()) { - if (argMod.array) { - const int i = argMod.index - 1; + if (argMod.isArray()) { + const int i = argMod.index() - 1; if (i < 0 || i >= func->arguments().size()) { *errorMessage = msgCannotSetArrayUsage(func->minimalSignature(), i, QLatin1String("Index out of range.")); diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp index 79ca961f6..e2d0fb9dc 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp @@ -431,9 +431,9 @@ QList<ReferenceCount> AbstractMetaFunction::referenceCounts(const AbstractMetaCl for (const auto &mod : modifications(cls)) { for (const ArgumentModification &argumentMod : mod.argument_mods()) { - if (argumentMod.index != idx && idx != -2) + if (argumentMod.index() != idx && idx != -2) continue; - returned += argumentMod.referenceCounts; + returned += argumentMod.referenceCounts(); } } @@ -444,9 +444,9 @@ ArgumentOwner AbstractMetaFunction::argumentOwner(const AbstractMetaClass *cls, { for (const auto &mod : modifications(cls)) { for (const ArgumentModification &argumentMod : mod.argument_mods()) { - if (argumentMod.index != idx) + if (argumentMod.index() != idx) continue; - return argumentMod.owner; + return argumentMod.owner(); } } return ArgumentOwner(); @@ -456,10 +456,10 @@ QString AbstractMetaFunction::conversionRule(TypeSystem::Language language, int { for (const auto &modification : modifications(declaringClass())) { for (const ArgumentModification &argumentModification : modification.argument_mods()) { - if (argumentModification.index != key) + if (argumentModification.index() != key) continue; - for (const CodeSnip &snip : argumentModification.conversion_rules) { + for (const CodeSnip &snip : argumentModification.conversionRules()) { if (snip.language == language && !snip.code().isEmpty()) return snip.code(); } @@ -474,8 +474,8 @@ bool AbstractMetaFunction::argumentRemoved(int key) const { for (const auto &modification : modifications(declaringClass())) { for (const ArgumentModification &argumentModification : modification.argument_mods()) { - if (argumentModification.index == key) { - if (argumentModification.removed) + if (argumentModification.index() == key) { + if (argumentModification.isRemoved()) return true; } } @@ -625,8 +625,8 @@ TypeSystem::Ownership AbstractMetaFunction::ownership(const AbstractMetaClass *c { for (const auto &modification : modifications(cls)) { for (const ArgumentModification &argumentModification : modification.argument_mods()) { - if (argumentModification.index == key) - return argumentModification.ownerships.value(language, TypeSystem::InvalidOwnership); + if (argumentModification.index() == key) + return argumentModification.ownerships().value(language, TypeSystem::InvalidOwnership); } } @@ -637,9 +637,9 @@ QString AbstractMetaFunction::typeReplaced(int key) const { for (const auto &modification : modifications(declaringClass())) { for (const ArgumentModification &argumentModification : modification.argument_mods()) { - if (argumentModification.index == key - && !argumentModification.modified_type.isEmpty()) { - return argumentModification.modified_type; + if (argumentModification.index() == key + && !argumentModification.modifiedType().isEmpty()) { + return argumentModification.modifiedType(); } } } @@ -651,7 +651,7 @@ bool AbstractMetaFunction::isModifiedToArray(int argumentIndex) const { for (const auto &modification : modifications(declaringClass())) { for (const ArgumentModification &argumentModification : modification.argument_mods()) { - if (argumentModification.index == argumentIndex && argumentModification.array != 0) + if (argumentModification.index() == argumentIndex && argumentModification.isArray()) return true; } } @@ -853,7 +853,7 @@ bool AbstractMetaFunction::hasSignatureModifications() const // since zero represents the return type and we're // interested only in checking the function arguments, // it will be ignored. - if (argmod.index > 0) + if (argmod.index() > 0) return true; } } diff --git a/sources/shiboken6/ApiExtractor/modifications.cpp b/sources/shiboken6/ApiExtractor/modifications.cpp index e70c7f7d8..eba1437dc 100644 --- a/sources/shiboken6/ApiExtractor/modifications.cpp +++ b/sources/shiboken6/ApiExtractor/modifications.cpp @@ -454,6 +454,182 @@ QDebug operator<<(QDebug d, const CodeSnip &s) return d; } +class ArgumentModificationData : public QSharedData +{ +public: + ArgumentModificationData(int idx = -1) : index(idx), + removedDefaultExpression(false), removed(false), + noNullPointers(false), resetAfterUse(false), array(false) + {} + + QList<ReferenceCount> referenceCounts; + QString modified_type; + QString replacedDefaultExpression; + QHash<TypeSystem::Language, TypeSystem::Ownership> ownerships; + CodeSnipList conversion_rules; + ArgumentOwner owner; + QString renamed_to; + int index = -1; + uint removedDefaultExpression : 1; + uint removed : 1; + uint noNullPointers : 1; + uint resetAfterUse : 1; + uint array : 1; +}; + +ArgumentModification::ArgumentModification() : d(new ArgumentModificationData) +{ +} + +ArgumentModification::ArgumentModification(int idx) : d(new ArgumentModificationData(idx)) +{ +} + +ArgumentModification::ArgumentModification(const ArgumentModification &) = default; +ArgumentModification &ArgumentModification::operator=(const ArgumentModification &) = default; +ArgumentModification::ArgumentModification(ArgumentModification &&) = default; +ArgumentModification &ArgumentModification::operator=(ArgumentModification &&) = default; +ArgumentModification::~ArgumentModification() = default; + +QString ArgumentModification::modifiedType() const +{ + return d->modified_type; +} + +void ArgumentModification::setModifiedType(const QString &value) +{ + if (d->modified_type != value) + d->modified_type = value; +} + +QString ArgumentModification::replacedDefaultExpression() const +{ + return d->replacedDefaultExpression; +} + +void ArgumentModification::setReplacedDefaultExpression(const QString &value) +{ + if (d->replacedDefaultExpression != value) + d->replacedDefaultExpression = value; +} + +const QHash<TypeSystem::Language, TypeSystem::Ownership> &ArgumentModification::ownerships() const +{ + return d->ownerships; +} + +void ArgumentModification::insertOwnership(TypeSystem::Language l, TypeSystem::Ownership o) +{ + d->ownerships.insert(l, o); +} + +const CodeSnipList &ArgumentModification::conversionRules() const +{ + return d->conversion_rules; +} + +CodeSnipList &ArgumentModification::conversionRules() +{ + return d->conversion_rules; +} + +ArgumentOwner ArgumentModification::owner() const +{ + return d->owner; +} + +void ArgumentModification::setOwner(const ArgumentOwner &value) +{ + d->owner = value; +} + +QString ArgumentModification::renamedToName() const +{ + return d->renamed_to; +} + +void ArgumentModification::setRenamedToName(const QString &value) +{ + if (d->renamed_to != value) + d->renamed_to = value; +} + +int ArgumentModification::index() const +{ + return d->index; +} + +void ArgumentModification::setIndex(int value) +{ + if (d->index != value) + d->index = value; +} + +bool ArgumentModification::removedDefaultExpression() const +{ + return d->removedDefaultExpression; +} + +void ArgumentModification::setRemovedDefaultExpression(const uint &value) +{ + if (d->removedDefaultExpression != value) + d->removedDefaultExpression = value; +} + +bool ArgumentModification::isRemoved() const +{ + return d->removed; +} + +void ArgumentModification::setRemoved(bool value) +{ + if (d->removed != value) + d->removed = value; +} + +bool ArgumentModification::noNullPointers() const +{ + return d->noNullPointers; +} + +void ArgumentModification::setNoNullPointers(bool value) +{ + if (d->noNullPointers != value) + d->noNullPointers = value; +} + +bool ArgumentModification::resetAfterUse() const +{ + return d->resetAfterUse; +} + +void ArgumentModification::setResetAfterUse(bool value) +{ + if (d->resetAfterUse != value) + d->resetAfterUse = value; +} + +bool ArgumentModification::isArray() const +{ + return d->array; +} + +void ArgumentModification::setArray(bool value) +{ + if (d->array != value) + d->array = value; +} + +const QList<ReferenceCount> &ArgumentModification::referenceCounts() const +{ + return d->referenceCounts; +} + +void ArgumentModification::addReferenceCount(const ReferenceCount &value) +{ + d->referenceCounts.append(value); +} + class ModificationData : public QSharedData { public: @@ -705,28 +881,26 @@ QDebug operator<<(QDebug d, const ArgumentModification &a) QDebugStateSaver saver(d); d.noquote(); d.nospace(); - d << "ArgumentModification(index=" << a.index; - if (a.removedDefaultExpression) + d << "ArgumentModification(index=" << a.index(); + if (a.removedDefaultExpression()) d << ", removedDefaultExpression"; - if (a.removed) + if (a.isRemoved()) d << ", removed"; - if (a.noNullPointers) + if (a.noNullPointers()) d << ", noNullPointers"; - if (a.array) + if (a.isArray()) d << ", array"; - if (!a.referenceCounts.isEmpty()) - d << ", referenceCounts=" << a.referenceCounts; - if (!a.modified_type.isEmpty()) - d << ", modified_type=\"" << a.modified_type << '"'; - if (!a.replace_value.isEmpty()) - d << ", replace_value=\"" << a.replace_value << '"'; - if (!a.replacedDefaultExpression.isEmpty()) - d << ", replacedDefaultExpression=\"" << a.replacedDefaultExpression << '"'; - if (!a.ownerships.isEmpty()) - d << ", ownerships=" << a.ownerships; - if (!a.renamed_to.isEmpty()) - d << ", renamed_to=\"" << a.renamed_to << '"'; - d << ", owner=" << a.owner << ')'; + if (!a.referenceCounts().isEmpty()) + d << ", referenceCounts=" << a.referenceCounts(); + if (!a.modifiedType().isEmpty()) + d << ", modified_type=\"" << a.modifiedType() << '"'; + if (!a.replacedDefaultExpression().isEmpty()) + d << ", replacedDefaultExpression=\"" << a.replacedDefaultExpression() << '"'; + if (!a.ownerships().isEmpty()) + d << ", ownerships=" << a.ownerships(); + if (!a.renamedToName().isEmpty()) + d << ", renamed_to=\"" << a.renamedToName() << '"'; + d << ", owner=" << a.owner() << ')'; return d; } diff --git a/sources/shiboken6/ApiExtractor/modifications.h b/sources/shiboken6/ApiExtractor/modifications.h index 1dc66cf74..1d217d0cb 100644 --- a/sources/shiboken6/ApiExtractor/modifications.h +++ b/sources/shiboken6/ApiExtractor/modifications.h @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ @@ -39,6 +39,7 @@ #include <QtCore/QSharedPointer> #include <QtCore/QString> +class ArgumentModificationData; class FunctionModificationData; class ModificationData; class FieldModificationData; @@ -174,47 +175,66 @@ public: TypeSystem::CodeSnipPosition position = TypeSystem::CodeSnipPositionAny; }; -struct ArgumentModification +class ArgumentModification { - ArgumentModification() : removedDefaultExpression(false), removed(false), - noNullPointers(false), resetAfterUse(false), array(false) {} - explicit ArgumentModification(int idx) : index(idx), removedDefaultExpression(false), removed(false), - noNullPointers(false), resetAfterUse(false), array(false) {} - - // Should the default expression be removed? - +public: + ArgumentModification(); + explicit ArgumentModification(int idx); + ArgumentModification(const ArgumentModification &); + ArgumentModification &operator=(const ArgumentModification &); + ArgumentModification(ArgumentModification &&); + ArgumentModification &operator=(ArgumentModification &&); + ~ArgumentModification(); // Reference count flags for this argument - QList<ReferenceCount> referenceCounts; + const QList<ReferenceCount> &referenceCounts() const; + void addReferenceCount(const ReferenceCount &value); // The text given for the new type of the argument - QString modified_type; - - QString replace_value; + QString modifiedType() const; + void setModifiedType(const QString &value); - // The text of the new default expression of the argument - QString replacedDefaultExpression; + // The text of the new default expression of the argument + QString replacedDefaultExpression() const; + void setReplacedDefaultExpression(const QString &value); // The new definition of ownership for a specific argument - QHash<TypeSystem::Language, TypeSystem::Ownership> ownerships; + const QHash<TypeSystem::Language, TypeSystem::Ownership> &ownerships() const; + void insertOwnership(TypeSystem::Language l, TypeSystem::Ownership o); // Different conversion rules - CodeSnipList conversion_rules; + const CodeSnipList &conversionRules() const; + CodeSnipList &conversionRules(); - //QObject parent(owner) of this argument - ArgumentOwner owner; + // QObject parent(owner) of this argument + ArgumentOwner owner() const; + void setOwner(const ArgumentOwner &value); + + // New name + QString renamedToName() const; + void setRenamedToName(const QString &value); - //New name - QString renamed_to; + int index() const; + void setIndex(int value); - // The index of this argument - int index = -1; + bool removedDefaultExpression() const; + void setRemovedDefaultExpression(const uint &value); - uint removedDefaultExpression : 1; - uint removed : 1; - uint noNullPointers : 1; - uint resetAfterUse : 1; - uint array : 1; // consider "int*" to be "int[]" + bool isRemoved() const; + void setRemoved(bool value); + + bool noNullPointers() const; + void setNoNullPointers(bool value); + + bool resetAfterUse() const; + void setResetAfterUse(bool value); + + // consider "int*" to be "int[]" + bool isArray() const; + void setArray(bool value); + +private: + QSharedDataPointer<ArgumentModificationData> d; }; class Modification diff --git a/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp b/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp index ebee345a0..7c7bb6115 100644 --- a/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp @@ -146,31 +146,31 @@ void TestModifyFunction::invalidateAfterUse() auto func = classB->findFunction(QLatin1String("call")); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); - QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse); + QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse()); const AbstractMetaClass *classC = AbstractMetaClass::findClass(classes, QLatin1String("C")); QVERIFY(classC); func = classC->findFunction(QLatin1String("call")); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); - QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse); + QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse()); func = classC->findFunction(QLatin1String("call2")); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); - QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse); + QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse()); const AbstractMetaClass *classD = AbstractMetaClass::findClass(classes, QLatin1String("D")); QVERIFY(classD); func = classD->findFunction(QLatin1String("call")); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); - QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse); + QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse()); func = classD->findFunction(QLatin1String("call2")); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); - QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse); + QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse()); const AbstractMetaClass *classE = AbstractMetaClass::findClass(classes, QLatin1String("E")); QVERIFY(classE); @@ -178,13 +178,13 @@ void TestModifyFunction::invalidateAfterUse() QVERIFY(func); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); - QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse); + QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse()); func = classE->findFunction(QLatin1String("call2")); QVERIFY(func); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); - QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse); + QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse()); } void TestModifyFunction::testWithApiVersion() @@ -308,7 +308,7 @@ void TestModifyFunction::testGlobalFunctionModification() const QList<ArgumentModification> &argMods = mods.constFirst().argument_mods(); QCOMPARE(argMods.count(), 1); ArgumentModification argMod = argMods.constFirst(); - QCOMPARE(argMod.replacedDefaultExpression, QLatin1String("A()")); + QCOMPARE(argMod.replacedDefaultExpression(), QLatin1String("A()")); QVERIFY(!builder->globalFunctions().isEmpty()); const auto func = builder->globalFunctions().constFirst(); diff --git a/sources/shiboken6/ApiExtractor/tests/testrefcounttag.cpp b/sources/shiboken6/ApiExtractor/tests/testrefcounttag.cpp index a589827e4..f3ffd0edf 100644 --- a/sources/shiboken6/ApiExtractor/tests/testrefcounttag.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testrefcounttag.cpp @@ -57,7 +57,8 @@ void TestRefCountTag::testReferenceCountTag() const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); const auto func = classB->findFunction(QLatin1String("keepObject")); QVERIFY(!func.isNull()); - ReferenceCount refCount = func->modifications().constFirst().argument_mods().constFirst().referenceCounts.constFirst(); + const auto refCount = + func->modifications().constFirst().argument_mods().constFirst().referenceCounts().constFirst(); QCOMPARE(refCount.action, ReferenceCount::Add); } @@ -90,7 +91,8 @@ void TestRefCountTag::testWithApiVersion() const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); const auto func = classB->findFunction(QLatin1String("keepObject")); QVERIFY(!func.isNull()); - ReferenceCount refCount = func->modifications().constFirst().argument_mods().constFirst().referenceCounts.constFirst(); + const auto refCount = + func->modifications().constFirst().argument_mods().constFirst().referenceCounts().constFirst(); QCOMPARE(refCount.action, ReferenceCount::Add); QCOMPARE(func->modifications().size(), 1); diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.cpp b/sources/shiboken6/ApiExtractor/typesystemparser.cpp index 1b7864e30..4c754f680 100644 --- a/sources/shiboken6/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken6/ApiExtractor/typesystemparser.cpp @@ -887,7 +887,7 @@ bool TypeSystemParser::endElement(QStringView localName) m_current->parent->value.customFunction->addTemplateInstance(m_current->value.templateInstance); break; case StackElement::ConversionRule: - m_contextStack.top()->functionMods.last().argument_mods().last().conversion_rules.last().addTemplateInstance(m_current->value.templateInstance); + m_contextStack.top()->functionMods.last().argument_mods().last().conversionRules().last().addTemplateInstance(m_current->value.templateInstance); break; case StackElement::InjectCodeInFunction: m_contextStack.top()->functionMods.last().snips().last().addTemplateInstance(m_current->value.templateInstance); @@ -940,7 +940,7 @@ bool TypeSystemParser::characters(const String &ch) if (m_current->type == StackElement::ConversionRule && m_current->parent->type == StackElement::ModifyArgument) { - m_contextStack.top()->functionMods.last().argument_mods().last().conversion_rules.last().addCode(ch); + m_contextStack.top()->functionMods.last().argument_mods().last().conversionRules().last().addCode(ch); return true; } @@ -1798,8 +1798,8 @@ bool TypeSystemParser::parseReplaceArgumentType(const QXmlStreamReader &, m_error = QLatin1String("Type replacement requires 'modified-type' attribute"); return false; } - m_contextStack.top()->functionMods.last().argument_mods().last().modified_type = - attributes->takeAt(modifiedTypeIndex).value().toString(); + m_contextStack.top()->functionMods.last().argument_mods().last().setModifiedType( + attributes->takeAt(modifiedTypeIndex).value().toString()); return true; } @@ -1838,7 +1838,7 @@ bool TypeSystemParser::parseCustomConversion(const QXmlStreamReader &, if (topElement.type == StackElement::ModifyArgument) { CodeSnip snip; snip.language = lang; - m_contextStack.top()->functionMods.last().argument_mods().last().conversion_rules.append(snip); + m_contextStack.top()->functionMods.last().argument_mods().last().conversionRules().append(snip); return true; } @@ -1954,15 +1954,12 @@ 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(); if (name == indexAttribute()) { index = attributes->takeAt(i).value().toString(); - } else if (name == QLatin1String("replace-value")) { - replaceValue = attributes->takeAt(i).value().toString(); } else if (name == invalidateAfterUseAttribute()) { resetAfterUse = convertBoolean(attributes->takeAt(i).value(), invalidateAfterUseAttribute(), false); @@ -1980,15 +1977,9 @@ bool TypeSystemParser::parseModifyArgument(const QXmlStreamReader &, if (!parseArgumentIndex(index, &idx, &m_error)) return false; - if (!replaceValue.isEmpty() && idx) { - m_error = QLatin1String("replace-value is only supported for return values (index=0)."); - return false; - } - ArgumentModification argumentModification = ArgumentModification(idx); - argumentModification.replace_value = replaceValue; - argumentModification.resetAfterUse = resetAfterUse; - argumentModification.renamed_to = renameTo; + argumentModification.setResetAfterUse(resetAfterUse); + argumentModification.setRenamedToName(renameTo); m_contextStack.top()->functionMods.last().argument_mods().append(argumentModification); return true; } @@ -2002,7 +1993,7 @@ bool TypeSystemParser::parseNoNullPointer(const QXmlStreamReader &reader, } ArgumentModification &lastArgMod = m_contextStack.top()->functionMods.last().argument_mods().last(); - lastArgMod.noNullPointers = true; + lastArgMod.setNoNullPointers(true); const int defaultValueIndex = indexOfAttribute(*attributes, u"default-value"); @@ -2043,7 +2034,7 @@ bool TypeSystemParser::parseDefineOwnership(const QXmlStreamReader &, m_error = QStringLiteral("unsupported owner attribute: '%1'").arg(ownership); return false; } - m_contextStack.top()->functionMods.last().argument_mods().last().ownerships[lang] = owner; + m_contextStack.top()->functionMods.last().argument_mods().last().insertOwnership(lang, owner); return true; } @@ -2063,7 +2054,7 @@ bool TypeSystemParser::parseRename(const QXmlStreamReader &, return false; } const QString renamed_to = attributes->takeAt(toIndex).value().toString(); - m_contextStack.top()->functionMods.last().argument_mods().last().renamed_to = renamed_to; + m_contextStack.top()->functionMods.last().argument_mods().last().setRenamedToName(renamed_to); return true; } @@ -2352,8 +2343,8 @@ bool TypeSystemParser::parseReplaceDefaultExpression(const QXmlStreamReader &, return false; } - m_contextStack.top()->functionMods.last().argument_mods().last().replacedDefaultExpression = - attributes->takeAt(withIndex).value().toString(); + m_contextStack.top()->functionMods.last().argument_mods().last().setReplacedDefaultExpression( + attributes->takeAt(withIndex).value().toString()); return true; } @@ -2413,7 +2404,7 @@ bool TypeSystemParser::parseReferenceCount(const QXmlStreamReader &reader, } } - m_contextStack.top()->functionMods.last().argument_mods().last().referenceCounts.append(rc); + m_contextStack.top()->functionMods.last().argument_mods().last().addReferenceCount(rc); return true; } @@ -2443,7 +2434,7 @@ bool TypeSystemParser::parseParentOwner(const QXmlStreamReader &, } } } - m_contextStack.top()->functionMods.last().argument_mods().last().owner = ao; + m_contextStack.top()->functionMods.last().argument_mods().last().setOwner(ao); return true; } @@ -2966,7 +2957,7 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader) return false; } - m_contextStack.top()->functionMods.last().argument_mods().last().removed = true; + m_contextStack.top()->functionMods.last().argument_mods().last().setRemoved(true); break; case StackElement::ModifyField: @@ -2991,7 +2982,7 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader) return false; break; case StackElement::RemoveDefaultExpression: - m_contextStack.top()->functionMods.last().argument_mods().last().removedDefaultExpression = true; + m_contextStack.top()->functionMods.last().argument_mods().last().setRemovedDefaultExpression(true); break; case StackElement::CustomMetaConstructor: case StackElement::CustomMetaDestructor: @@ -3011,7 +3002,7 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader) m_error = QLatin1String("array must be child of modify-argument"); return false; } - m_contextStack.top()->functionMods.last().argument_mods().last().array = true; + m_contextStack.top()->functionMods.last().argument_mods().last().setArray(true); break; case StackElement::InjectCode: if (!parseInjectCode(reader, topElement, element, &attributes)) diff --git a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp index 8aea707fa..fe5964a1f 100644 --- a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp @@ -731,8 +731,8 @@ void QtDocGenerator::writeFunctionParametersType(TextStream &s, const AbstractMe // check if the return type was modified for (const auto &mod : func->modifications()) { for (const ArgumentModification &argMod : mod.argument_mods()) { - if (argMod.index == 0) { - retType = argMod.modified_type; + if (argMod.index() == 0) { + retType = argMod.modifiedType(); break; } } diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 3ca86c3dc..0f1fe18f4 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -899,10 +899,10 @@ QString CppGenerator::virtualMethodReturn(TextStream &s, const AbstractMetaType &returnType = func->type(); for (const FunctionModification &mod : functionModifications) { for (const ArgumentModification &argMod : mod.argument_mods()) { - if (argMod.index == 0 && !argMod.replacedDefaultExpression.isEmpty()) { + if (argMod.index() == 0 && !argMod.replacedDefaultExpression().isEmpty()) { static const QRegularExpression regex(QStringLiteral("%(\\d+)")); Q_ASSERT(regex.isValid()); - QString expr = argMod.replacedDefaultExpression; + QString expr = argMod.replacedDefaultExpression(); for (int offset = 0; ; ) { const QRegularExpressionMatch match = regex.match(expr, offset); if (!match.hasMatch()) @@ -1086,12 +1086,14 @@ void CppGenerator::writeVirtualMethodNative(TextStream &s, QSet<int> invalidateArgs; for (const FunctionModification &funcMod : functionModifications) { for (const ArgumentModification &argMod : funcMod.argument_mods()) { - if (argMod.resetAfterUse && !invalidateArgs.contains(argMod.index)) { - invalidateArgs.insert(argMod.index); - s << "bool invalidateArg" << argMod.index + const int index = argMod.index(); + if (argMod.resetAfterUse() && !invalidateArgs.contains(index)) { + invalidateArgs.insert(index); + s << "bool invalidateArg" << index << " = PyTuple_GET_ITEM(" << PYTHON_ARGS << ", " - << argMod.index - 1 << ")->ob_refcnt == 1;\n"; - } else if (argMod.index == 0 && argMod.ownerships[TypeSystem::TargetLangCode] == TypeSystem::CppOwnership) { + << index - 1 << ")->ob_refcnt == 1;\n"; + } else if (index == 0 && + argMod.ownerships().value(TypeSystem::TargetLangCode) == TypeSystem::CppOwnership) { invalidateReturn = true; } } @@ -1186,8 +1188,9 @@ void CppGenerator::writeVirtualMethodNative(TextStream &s, for (const FunctionModification &funcMod : functionModifications) { for (const ArgumentModification &argMod : funcMod.argument_mods()) { - if (argMod.ownerships.contains(TypeSystem::NativeCode) - && argMod.index == 0 && argMod.ownerships[TypeSystem::NativeCode] == TypeSystem::CppOwnership) { + if (argMod.ownerships().contains(TypeSystem::NativeCode) + && argMod.index() == 0 + && argMod.ownerships().value(TypeSystem::NativeCode) == TypeSystem::CppOwnership) { s << "if (Shiboken::Object::checkType(" << PYTHON_RETURN_VAR << "))\n"; Indentation indent(s); s << "Shiboken::Object::releaseOwnership(" << PYTHON_RETURN_VAR << ");\n"; @@ -3705,9 +3708,9 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr QList<ArgumentModification> refcount_mods; for (const auto &func_mod : func->modifications()) { for (const ArgumentModification &arg_mod : func_mod.argument_mods()) { - if (!arg_mod.ownerships.isEmpty() && arg_mod.ownerships.contains(TypeSystem::TargetLangCode)) + if (arg_mod.ownerships().contains(TypeSystem::TargetLangCode)) ownership_mods.append(arg_mod); - else if (!arg_mod.referenceCounts.isEmpty()) + else if (!arg_mod.referenceCounts().isEmpty()) refcount_mods.append(arg_mod); } } @@ -3721,11 +3724,11 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr for (const ArgumentModification &arg_mod : qAsConst(ownership_mods)) { const AbstractMetaClass *wrappedClass = nullptr; QString errorMessage; - QString pyArgName = argumentNameFromIndex(func, arg_mod.index, &wrappedClass, &errorMessage); + QString pyArgName = argumentNameFromIndex(func, arg_mod.index(), &wrappedClass, &errorMessage); if (!wrappedClass) { QString message; QTextStream str(&message); - str << "Invalid ownership modification for argument " << arg_mod.index + str << "Invalid ownership modification for argument " << arg_mod.index() << " (" << pyArgName << ") of "; if (const AbstractMetaClass *declaringClass = func->declaringClass()) str << declaringClass->name() << "::"; @@ -3735,19 +3738,21 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr break; } - if (arg_mod.index == 0 || arg_mod.owner.index == 0) + if (arg_mod.index() == 0 || arg_mod.owner().index == 0) hasReturnPolicy = true; // The default ownership does nothing. This is useful to avoid automatic heuristically // based generation of code defining parenting. - if (arg_mod.ownerships[TypeSystem::TargetLangCode] == TypeSystem::DefaultOwnership) + const auto ownership = + arg_mod.ownerships().value(TypeSystem::TargetLangCode, TypeSystem::DefaultOwnership); + if (ownership == TypeSystem::DefaultOwnership) continue; s << "Shiboken::Object::"; - if (arg_mod.ownerships[TypeSystem::TargetLangCode] == TypeSystem::TargetLangOwnership) { + if (ownership == TypeSystem::TargetLangOwnership) { s << "getOwnership(" << pyArgName << ");"; } else if (wrappedClass->hasVirtualDestructor()) { - if (arg_mod.index == 0) + if (arg_mod.index() == 0) s << "releaseOwnership(" << PYTHON_RETURN_VAR << ");"; else s << "releaseOwnership(" << pyArgName << ");"; @@ -3759,7 +3764,7 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr } else if (!refcount_mods.isEmpty()) { for (const ArgumentModification &arg_mod : qAsConst(refcount_mods)) { - ReferenceCount refCount = arg_mod.referenceCounts.constFirst(); + ReferenceCount refCount = arg_mod.referenceCounts().constFirst(); if (refCount.action != ReferenceCount::Set && refCount.action != ReferenceCount::Remove && refCount.action != ReferenceCount::Add) { @@ -3773,12 +3778,12 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr pyArgName = QLatin1String("Py_None"); } else { QString errorMessage; - pyArgName = argumentNameFromIndex(func, arg_mod.index, &wrappedClass, &errorMessage); + pyArgName = argumentNameFromIndex(func, arg_mod.index(), &wrappedClass, &errorMessage); if (pyArgName.isEmpty()) { QString message; QTextStream str(&message); str << "Invalid reference count modification for argument " - << arg_mod.index << " of "; + << arg_mod.index() << " of "; if (const AbstractMetaClass *declaringClass = func->declaringClass()) str << declaringClass->name() << "::"; str << func->name() << "(): " << errorMessage; @@ -3794,15 +3799,15 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr s << "Shiboken::Object::removeReference("; s << "reinterpret_cast<SbkObject *>(self), \""; - QString varName = arg_mod.referenceCounts.constFirst().varName; + QString varName = arg_mod.referenceCounts().constFirst().varName; if (varName.isEmpty()) - varName = func->minimalSignature() + QString::number(arg_mod.index); + varName = func->minimalSignature() + QString::number(arg_mod.index()); s << varName << "\", " << pyArgName << (refCount.action == ReferenceCount::Add ? ", true" : "") << ");\n"; - if (arg_mod.index == 0) + if (arg_mod.index() == 0) hasReturnPolicy = true; } } diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index 8d8483c6b..510b20ae8 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -651,7 +651,7 @@ bool ShibokenGenerator::shouldRejectNullPointerArgument(const AbstractMetaFuncti return false; for (const auto &funcMod : func->modifications()) { for (const ArgumentModification &argMod : funcMod.argument_mods()) { - if (argMod.index == argIndex + 1 && argMod.noNullPointers) + if (argMod.index() == argIndex + 1 && argMod.noNullPointers()) return true; } } |