aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/generator/shiboken/cppgenerator.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-09-15 17:04:28 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-09-15 20:26:10 +0200
commitd6ee76c90bbdda6a4ed236953610d6e3ebfe69e0 (patch)
treeb55567afec71190dd1faddc70373fc5f6ccdc2a4 /sources/shiboken6/generator/shiboken/cppgenerator.cpp
parent393543d02ac5b8908ff80f75e0460bbb4fb901aa (diff)
shiboken6: Simplify CppGenerator::getArgumentType()
The function took an argument position where a value of 0 means return type. The return type code branch was not used; it is only ever invoked for arguments. Remove the return type code path and change the function to take the argument index. Failing to build a meta type for an argument is a hard failure; change the function to return the meta type and to throw on failure. Task-number: PYSIDE-1660 Change-Id: I0dd89ecde595c71b42df7464d03204bafe74d17c Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp')
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp43
1 files changed, 12 insertions, 31 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index d35d2a5f5..3a8f2c2a2 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -2511,41 +2511,25 @@ void CppGenerator::writeArgumentConversion(TextStream &s,
writeUnusedVariableCast(s, argName);
}
-static const QStringList &knownPythonTypes()
-{
- static const QStringList result = {
- pyBoolT(), pyIntT(), pyFloatT(), pyLongT(),
- cPyObjectT(), QLatin1String("PyString"),
- cPyBufferT(), cPySequenceT(),
- QLatin1String("PyTuple"), cPyListT(),
- QLatin1String("PyDict"), QLatin1String("PyObject*"),
- QLatin1String("PyObject *"), QLatin1String("PyTupleObject*")};
- return result;
-}
-
-std::optional<AbstractMetaType>
- CppGenerator::getArgumentType(const AbstractMetaFunctionCPtr &func, int argPos)
+AbstractMetaType
+ CppGenerator::getArgumentType(const AbstractMetaFunctionCPtr &func, int index)
{
- if (argPos < 0 || argPos > func->arguments().size()) {
+ if (index < 0 || index >= func->arguments().size()) {
qCWarning(lcShiboken).noquote().nospace()
<< "Argument index for function '" << func->signature() << "' out of range.";
return {};
}
- QString typeReplaced = func->typeReplaced(argPos);
+ QString typeReplaced = func->typeReplaced(index + 1);
if (typeReplaced.isEmpty()) {
- if (argPos == 0)
- return func->type();
- auto argType = func->arguments().at(argPos - 1).type();
+ auto argType = func->arguments().at(index).type();
return argType.viewOn() ? *argType.viewOn() : argType;
}
auto argType = AbstractMetaType::fromString(typeReplaced);
- if (!argType.has_value() && !knownPythonTypes().contains(typeReplaced)) {
- qCWarning(lcShiboken, "%s",
- qPrintable(msgUnknownTypeInArgumentTypeReplacement(typeReplaced, func.data())));
- }
- return argType;
+ if (!argType.has_value())
+ throw Exception(msgUnknownTypeInArgumentTypeReplacement(typeReplaced, func.data()));
+ return argType.value();
}
static inline QString arrayHandleType(const AbstractMetaTypeList &nestedArrayTypes)
@@ -3052,14 +3036,14 @@ void CppGenerator::writeSingleFunctionCall(TextStream &s,
}
if (hasConversionRule)
continue;
- auto argType = getArgumentType(func, argIdx + 1);
- if (!argType.has_value() || (mayHaveUnunsedArguments && !func->injectedCodeUsesArgument(argIdx)))
+ if (mayHaveUnunsedArguments && !func->injectedCodeUsesArgument(argIdx))
continue;
+ auto argType = getArgumentType(func, argIdx);
int argPos = argIdx - removedArgs;
QString argName = QLatin1String(CPP_ARG) + QString::number(argPos);
QString pyArgName = usePyArgs ? pythonArgsAt(argPos) : QLatin1String(PYTHON_ARG);
QString defaultValue = guessScopeForDefaultValue(func, arg);
- writeArgumentConversion(s, argType.value(), argName, pyArgName,
+ writeArgumentConversion(s, argType, argName, pyArgName,
func->implementingClass(), defaultValue,
func->isUserAdded());
}
@@ -4943,10 +4927,7 @@ void CppGenerator::writeRichCompareFunction(TextStream &s,
const auto func = od->referenceFunction();
if (func->isStatic())
continue;
- auto argTypeO = getArgumentType(func, 1);
- if (!argTypeO.has_value())
- continue;
- auto argType = argTypeO.value();
+ auto argType = getArgumentType(func, 0);
if (!first) {
s << " else ";
} else {