diff options
Diffstat (limited to 'sources/shiboken6')
9 files changed, 76 insertions, 50 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetaargument.cpp b/sources/shiboken6/ApiExtractor/abstractmetaargument.cpp index 539234249..81c6a2273 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetaargument.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetaargument.cpp @@ -45,6 +45,7 @@ public: QString m_expression; QString m_originalExpression; int m_argumentIndex = 0; + bool m_modifiedRemoved = false; }; AbstractMetaArgument::AbstractMetaArgument() : d(new AbstractMetaArgumentData) @@ -77,6 +78,17 @@ const AbstractMetaType &AbstractMetaArgument::modifiedType() const return d->m_modifiedType; } +bool AbstractMetaArgument::isModifiedRemoved() const +{ + return d->m_modifiedRemoved; +} + +void AbstractMetaArgument::setModifiedRemoved(bool v) +{ + if (d->m_modifiedRemoved != v) + d->m_modifiedRemoved = v; +} + void AbstractMetaArgument::setModifiedType(const AbstractMetaType &type) { if (d->m_modifiedType != type) diff --git a/sources/shiboken6/ApiExtractor/abstractmetaargument.h b/sources/shiboken6/ApiExtractor/abstractmetaargument.h index 93dab6f79..fb8ae0fb2 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetaargument.h +++ b/sources/shiboken6/ApiExtractor/abstractmetaargument.h @@ -58,6 +58,9 @@ public: const AbstractMetaType &modifiedType() const; bool isTypeModified() const { return modifiedType() != type(); } + bool isModifiedRemoved() const; + void setModifiedRemoved(bool v); + QString name() const; void setName(const QString &name, bool realName = true); bool hasName() const; diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp index 05b598811..d220275b6 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp @@ -533,13 +533,12 @@ bool AbstractMetaFunction::isUserDeclared() const int AbstractMetaFunction::actualMinimumArgumentCount() const { - AbstractMetaArgumentList arguments = this->arguments(); - int count = 0; - for (int i = 0; i < arguments.size(); ++i && ++count) { - if (argumentRemoved(i + 1)) + for (int i = 0, size = d->m_arguments.size(); i < size; ++i && ++count) { + const auto &arg = d->m_arguments.at(i); + if (arg.isModifiedRemoved()) --count; - else if (!arguments.at(i).defaultValueExpression().isEmpty()) + else if (!arg.defaultValueExpression().isEmpty()) break; } @@ -829,6 +828,14 @@ void AbstractMetaFunction::applyTypeModifications() && !d->applyTypeModification(this, am.modifiedType(), n, &errorMessage)) { throw Exception(errorMessage); + } else if (am.isRemoved() && n != 0) { + if (n < 1 || n > d->m_arguments.size()) { + errorMessage = + msgArgumentRemovalFailed(this, n, + msgArgumentOutOfRange(n, 1, d->m_arguments.size())); + throw Exception(errorMessage); + } + d->m_arguments[n - 1].setModifiedRemoved(true); } } } diff --git a/sources/shiboken6/ApiExtractor/messages.cpp b/sources/shiboken6/ApiExtractor/messages.cpp index b7a1e9091..8079e5851 100644 --- a/sources/shiboken6/ApiExtractor/messages.cpp +++ b/sources/shiboken6/ApiExtractor/messages.cpp @@ -104,6 +104,18 @@ QString msgArgumentOutOfRange(int number, int minValue, int maxValue) return result; } +QString msgArgumentRemovalFailed(const AbstractMetaFunction *func, int n, + const QString &why) +{ + QString result; + QTextStream str(&result); + str << "Unable to remove argument " << n << " of "; + if (auto *c = func->ownerClass()) + str << c->name() << "::"; + str << func->signature() << ": " << why; + return result; +} + template <class Stream> static void msgFormatEnumType(Stream &str, const EnumModelItem &enumItem, diff --git a/sources/shiboken6/ApiExtractor/messages.h b/sources/shiboken6/ApiExtractor/messages.h index 0accbd449..813818304 100644 --- a/sources/shiboken6/ApiExtractor/messages.h +++ b/sources/shiboken6/ApiExtractor/messages.h @@ -72,6 +72,9 @@ QString msgTypeModificationFailed(const QString &type, int n, QString msgArgumentOutOfRange(int number, int minValue, int maxValue); +QString msgArgumentRemovalFailed(const AbstractMetaFunction *func, int n, + const QString &why); + QString msgClassOfEnumNotFound(const EnumTypeEntry *entry); QString msgNoEnumTypeEntry(const EnumModelItem &enumItem, diff --git a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp index 8c768a57d..8710171ef 100644 --- a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp @@ -476,7 +476,7 @@ QString QtDocGenerator::parseArgDocStyle(const AbstractMetaClass* /* cppClass */ const AbstractMetaArgumentList &arguments = func->arguments(); for (const AbstractMetaArgument &arg : arguments) { - if (func->argumentRemoved(arg.argumentIndex() + 1)) + if (arg.isModifiedRemoved()) continue; bool thisIsoptional = !arg.defaultValueExpression().isEmpty(); @@ -702,11 +702,8 @@ void QtDocGenerator::writeFunctionParametersType(TextStream &s, const AbstractMe s << '\n'; const AbstractMetaArgumentList &funcArgs = func->arguments(); for (const AbstractMetaArgument &arg : funcArgs) { - - if (func->argumentRemoved(arg.argumentIndex() + 1)) - continue; - - writeParameterType(s, cppClass, arg); + if (!arg.isModifiedRemoved()) + writeParameterType(s, cppClass, arg); } if (!func->isConstructor() && !func->isVoid()) { diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 8aba8cd20..8f86cbaff 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -843,14 +843,9 @@ Shiboken::Object::destroy(wrapper, this); static bool allArgumentsRemoved(const AbstractMetaFunctionCPtr& func) { - if (func->arguments().isEmpty()) - return false; const AbstractMetaArgumentList &arguments = func->arguments(); - for (const AbstractMetaArgument &arg : arguments) { - if (!func->argumentRemoved(arg.argumentIndex() + 1)) - return false; - } - return true; + return std::all_of(arguments.cbegin(), arguments.cend(), + [](const AbstractMetaArgument &a) { return a.isModifiedRemoved(); }); } // Return type for error messages when getting invalid types from virtual @@ -1091,7 +1086,7 @@ void CppGenerator::writeVirtualMethodNative(TextStream &s, QStringList argConversions; const AbstractMetaArgumentList &arguments = func->arguments(); for (const AbstractMetaArgument &arg : arguments) { - if (func->argumentRemoved(arg.argumentIndex() + 1)) + if (arg.isModifiedRemoved()) continue; const auto &argType = arg.type(); @@ -2434,12 +2429,15 @@ static void checkTypeViability(const AbstractMetaFunctionCPtr &func, const bool modified = argIdx == 0 ? func->isTypeModified() : func->arguments().at(argIdx -1).isTypeModified(); + const bool isRemoved = argIdx == 0 + ? func->argumentRemoved(0) + : func->arguments().at(argIdx -1).isModifiedRemoved(); if (type.isVoid() || !type.typeEntry()->isPrimitive() || type.indirections() == 0 || (type.indirections() == 1 && type.typeUsagePattern() == AbstractMetaType::NativePointerAsArrayPattern) || type.isCString() - || func->argumentRemoved(argIdx) + || isRemoved || modified || !func->conversionRule(TypeSystem::All, argIdx).isEmpty() || func->hasInjectedCode()) @@ -3014,7 +3012,7 @@ void CppGenerator::writeSingleFunctionCall(TextStream &s, for (int argIdx = 0; argIdx < func->arguments().count(); ++argIdx) { bool hasConversionRule = !func->conversionRule(TypeSystem::NativeCode, argIdx + 1).isEmpty(); const AbstractMetaArgument &arg = func->arguments().at(argIdx); - if (func->argumentRemoved(argIdx + 1)) { + if (arg.isModifiedRemoved()) { if (!arg.defaultValueExpression().isEmpty()) { const QString cppArgRemoved = QLatin1String(CPP_ARG_REMOVED) + QString::number(argIdx); @@ -3533,8 +3531,7 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr if (maxArgs > 0 && maxArgs < func->arguments().size() - OverloadData::numberOfRemovedArguments(func)) { int removedArgs = 0; for (int i = 0; i < maxArgs + removedArgs; i++) { - lastArg = &func->arguments().at(i); - if (func->argumentRemoved(i + 1)) + if (func->arguments().at(i).isModifiedRemoved()) removedArgs++; } } else if (maxArgs != 0 && !func->arguments().isEmpty()) { @@ -3555,7 +3552,7 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr const AbstractMetaArgument &arg = func->arguments().at(i); bool hasConversionRule = !func->conversionRule(TypeSystem::NativeCode, arg.argumentIndex() + 1).isEmpty(); - if (func->argumentRemoved(i + 1)) { + if (arg.isModifiedRemoved()) { // If some argument with default value is removed from a // method signature, the said value must be explicitly // added to the method call. @@ -3596,7 +3593,7 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr if (argsClear && !defValModified && !hasConversionRule) continue; argsClear = false; - otherArgsModified |= defValModified || hasConversionRule || func->argumentRemoved(i + 1); + otherArgsModified |= defValModified || hasConversionRule || arg.isModifiedRemoved(); if (hasConversionRule) otherArgs.prepend(arg.name() + QLatin1String(CONV_RULE_OUT_VAR_SUFFIX)); else diff --git a/sources/shiboken6/generator/shiboken/overloaddata.cpp b/sources/shiboken6/generator/shiboken/overloaddata.cpp index 3f0e484e8..fe45965fa 100644 --- a/sources/shiboken6/generator/shiboken/overloaddata.cpp +++ b/sources/shiboken6/generator/shiboken/overloaddata.cpp @@ -421,8 +421,9 @@ static std::pair<int, int> getMinMaxArgs(const AbstractMetaFunctionCPtr &func) const auto &arguments = func->arguments(); int argIndex = 0; for (qsizetype i = 0, size = arguments.size(); i < size; ++i) { - if (!func->argumentRemoved(int(i + 1))) { - if (defaultValueIndex < 0 && arguments.at(i).hasDefaultValueExpression()) + const auto &arg = arguments.at(i); + if (!arg.isModifiedRemoved()) { + if (defaultValueIndex < 0 && arg.hasDefaultValueExpression()) defaultValueIndex = argIndex; ++argIndex; } @@ -467,9 +468,8 @@ OverloadData::OverloadData(const AbstractMetaFunctionCList &overloads, OverloadDataRootNode *currentOverloadData = this; const AbstractMetaArgumentList &arguments = func->arguments(); for (const AbstractMetaArgument &arg : arguments) { - if (func->argumentRemoved(arg.argumentIndex() + 1)) - continue; - currentOverloadData = currentOverloadData->addOverloadDataNode(func, arg); + if (!arg.isModifiedRemoved()) + currentOverloadData = currentOverloadData->addOverloadDataNode(func, arg); } } @@ -631,7 +631,7 @@ const AbstractMetaArgument *OverloadDataNode::overloadArgument(const AbstractMet int argPos = 0; int removed = 0; for (int i = 0; argPos <= m_argPos; i++) { - if (func->argumentRemoved(i + 1)) + if (func->arguments().at(i).isModifiedRemoved()) removed++; else argPos++; @@ -684,7 +684,7 @@ AbstractMetaFunctionCPtr OverloadDataRootNode::getFunctionWithDefaultValue() con for (const auto &func : m_overloads) { int removedArgs = 0; for (int i = 0; i <= argpos + removedArgs; i++) { - if (func->argumentRemoved(i + 1)) + if (func->arguments().at(i).isModifiedRemoved()) removedArgs++; } if (func->arguments().at(argpos + removedArgs).hasDefaultValueExpression()) @@ -701,7 +701,7 @@ QList<int> OverloadData::invalidArgumentLengths() const const AbstractMetaArgumentList args = func->arguments(); int offset = 0; for (int i = 0; i < args.size(); ++i) { - if (func->argumentRemoved(i+1)) { + if (func->arguments().at(i).isModifiedRemoved()) { offset++; } else { if (args.at(i).hasDefaultValueExpression()) @@ -722,12 +722,8 @@ QList<int> OverloadData::invalidArgumentLengths() const int OverloadData::numberOfRemovedArguments(const AbstractMetaFunctionCPtr &func) { - int removed = 0; - for (int i = 0, size = int(func->arguments().size()); i < size; ++i) { - if (func->argumentRemoved(i + 1)) - ++removed; - } - return removed; + return std::count_if(func->arguments().cbegin(), func->arguments().cend(), + [](const AbstractMetaArgument &a) { return a.isModifiedRemoved(); }); } int OverloadData::numberOfRemovedArguments(const AbstractMetaFunctionCPtr &func, int finalArgPos) @@ -736,7 +732,7 @@ int OverloadData::numberOfRemovedArguments(const AbstractMetaFunctionCPtr &func, int removed = 0; const int size = func->arguments().size(); for (int i = 0; i < qMin(size, finalArgPos + removed); ++i) { - if (func->argumentRemoved(i + 1)) + if (func->arguments().at(i).isModifiedRemoved()) ++removed; } return removed; @@ -951,9 +947,7 @@ bool OverloadData::hasArgumentWithDefaultValue(const AbstractMetaFunctionCPtr &f { const AbstractMetaArgumentList &arguments = func->arguments(); for (const AbstractMetaArgument &arg : arguments) { - if (func->argumentRemoved(arg.argumentIndex() + 1)) - continue; - if (arg.hasDefaultValueExpression()) + if (!arg.isModifiedRemoved() && arg.hasDefaultValueExpression()) return true; } return false; @@ -965,7 +959,7 @@ AbstractMetaArgumentList OverloadData::getArgumentsWithDefaultValues(const Abstr const AbstractMetaArgumentList &arguments = func->arguments(); for (const AbstractMetaArgument &arg : arguments) { if (!arg.hasDefaultValueExpression() - || func->argumentRemoved(arg.argumentIndex() + 1)) + || arg.isModifiedRemoved()) continue; args << arg; } diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index 0bf43482d..23723afee 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -622,7 +622,7 @@ bool ShibokenGenerator::shouldRejectNullPointerArgument(const AbstractMetaFuncti // necessary because the type checking would handle that already. if (!arg.type().isPointer()) return false; - if (func->argumentRemoved(argIndex + 1)) + if (arg.isModifiedRemoved()) return false; for (const auto &funcMod : func->modifications()) { for (const ArgumentModification &argMod : funcMod.argument_mods()) { @@ -639,7 +639,7 @@ QString ShibokenGenerator::getFormatUnitString(const AbstractMetaFunctionCPtr &f const char objType = (incRef ? 'O' : 'N'); const AbstractMetaArgumentList &arguments = func->arguments(); for (const AbstractMetaArgument &arg : arguments) { - if (func->argumentRemoved(arg.argumentIndex() + 1)) + if (arg.isModifiedRemoved()) continue; const auto &type = arg.type(); @@ -1276,12 +1276,13 @@ void ShibokenGenerator::writeFunctionArguments(TextStream &s, int argUsed = 0; for (int i = 0; i < arguments.size(); ++i) { - if ((options & Generator::SkipRemovedArguments) && func->argumentRemoved(i+1)) + const auto &arg = arguments.at(i); + if (options.testFlag(Generator::SkipRemovedArguments) && arg.isModifiedRemoved()) continue; if (argUsed != 0) s << ", "; - writeArgument(s, func, arguments[i], options); + writeArgument(s, func, arg, options); argUsed++; } } @@ -1342,7 +1343,7 @@ void ShibokenGenerator::writeArgumentNames(TextStream &s, int argCount = 0; for (const auto &argument : arguments) { const int index = argument.argumentIndex() + 1; - if ((options & Generator::SkipRemovedArguments) && (func->argumentRemoved(index))) + if (options.testFlag(Generator::SkipRemovedArguments) && argument.isModifiedRemoved()) continue; s << ((argCount > 0) ? ", " : "") << argument.name(); @@ -1524,7 +1525,7 @@ ShibokenGenerator::ArgumentVarReplacementList QString argValue; if (language == TypeSystem::TargetLangCode) { bool hasConversionRule = !func->conversionRule(convLang, i+1).isEmpty(); - const bool argRemoved = func->argumentRemoved(i+1); + const bool argRemoved = arg.isModifiedRemoved(); if (argRemoved) ++removed; if (argRemoved && hasConversionRule) |