aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/generator
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-09-16 09:44:05 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-10-01 11:24:55 +0200
commitee38500932bb2c4275811bcaabaaf7a831d29f4f (patch)
tree59a51e4db8f9ad9e13bb5fa5c8ef58a394d8a5f3 /sources/shiboken6/generator
parent2edf0042bb23fa8528dfb964377dae5bd35ee932 (diff)
shiboken6: Store removed modification in AbstractMetaArgument
Similar to 984559a68d57d76b49c8ed0cbaf3492521aebebd, store the "removed" modification in AbstractMetaArgument. Task-number: PYSIDE-1660 Change-Id: Id541b4dccdcf3eba708a0da5dc873fe3b20b8151 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/generator')
-rw-r--r--sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp9
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp25
-rw-r--r--sources/shiboken6/generator/shiboken/overloaddata.cpp32
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.cpp13
4 files changed, 34 insertions, 45 deletions
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)