aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-03-21 21:17:57 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-03-23 17:09:54 +0100
commit84f5d3fca336730508eeb0144d4ee42feff34f0c (patch)
tree07e589a8a9f61aaf1b0a2c2c89651e9967a589a0 /sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
parentfc7f5f15292886790b45ab114d93a873564f95d6 (diff)
shiboken: Improve error messages about invalid types of added functions
Change translateType() to pass up the error instead of aborting so that the error is printed in traverseFunction() along with the name. The abort in case of failure will then occur in fillAddedFunctions(). Task-number: PYSIDE-946 Task-number: PYSIDE-1241 Change-Id: Iee9ca478b28c8f82d9c4b6c5165f3028bf1e0d08 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp')
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp65
1 files changed, 41 insertions, 24 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
index 4566ed3bc..4b62ac4a5 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
@@ -1613,9 +1613,22 @@ AbstractMetaFunction* AbstractMetaBuilderPrivate::traverseFunction(const AddedFu
AbstractMetaFunction* AbstractMetaBuilderPrivate::traverseFunction(const AddedFunctionPtr &addedFunc,
AbstractMetaClass *metaClass)
{
- auto *metaFunction = new AbstractMetaFunction(addedFunc);
- metaFunction->setType(translateType(addedFunc->returnType()));
+ QString errorMessage;
+ AbstractMetaType *returnType = nullptr;
+ if (addedFunc->returnType().name != QLatin1String("void")) {
+ returnType = translateType(addedFunc->returnType(), &errorMessage);
+ if (!returnType) {
+ qCWarning(lcShiboken, "%s",
+ qPrintable(msgAddedFunctionInvalidReturnType(addedFunc->name(),
+ addedFunc->returnType().name,
+ errorMessage)));
+ return nullptr;
+ }
+ }
+
+ auto metaFunction = new AbstractMetaFunction(addedFunc);
+ metaFunction->setType(returnType);
const auto &args = addedFunc->arguments();
AbstractMetaArgumentList metaArguments;
@@ -1623,11 +1636,12 @@ AbstractMetaFunction* AbstractMetaBuilderPrivate::traverseFunction(const AddedFu
for (int i = 0; i < args.count(); ++i) {
const AddedFunction::TypeInfo& typeInfo = args.at(i).typeInfo;
auto *metaArg = new AbstractMetaArgument;
- AbstractMetaType *type = translateType(typeInfo);
+ AbstractMetaType *type = translateType(typeInfo, &errorMessage);
if (Q_UNLIKELY(!type)) {
- qCWarning(lcShiboken,
- "Unable to translate type \"%s\" of argument %d of added function \"%s\".",
- qPrintable(typeInfo.name), i + 1, qPrintable(addedFunc->name()));
+ qCWarning(lcShiboken, "%s",
+ qPrintable(msgAddedFunctionInvalidArgType(addedFunc->name(),
+ typeInfo.name, i + 1,
+ errorMessage)));
delete metaFunction;
return nullptr;
}
@@ -2041,7 +2055,8 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio
return metaFunction;
}
-AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const AddedFunction::TypeInfo &typeInfo)
+AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const AddedFunction::TypeInfo &typeInfo,
+ QString *errorMessage)
{
Q_ASSERT(!typeInfo.name.isEmpty());
TypeDatabase* typeDb = TypeDatabase::instance();
@@ -2060,12 +2075,11 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const AddedFunction:
if (!type && typeInfo.name.contains(QLatin1Char('<'))) {
const QStringList& parsedType = parseTemplateType(typeInfo.name);
if (parsedType.isEmpty()) {
- qCWarning(lcShiboken).noquote().nospace()
- << QStringLiteral("Template type parsing failed for '%1'").arg(typeInfo.name);
- } else {
- templateArgs = parsedType.mid(1);
- isTemplate = (type = typeDb->findContainerType(parsedType[0]));
+ *errorMessage = QStringLiteral("Template type parsing failed for '%1'").arg(typeInfo.name);
+ return nullptr;
}
+ templateArgs = parsedType.mid(1);
+ isTemplate = (type = typeDb->findContainerType(parsedType[0]));
}
if (!type) {
@@ -2076,20 +2090,18 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const AddedFunction:
if (it.key().endsWith(colonColon() + typeName))
candidates.append(it.key());
}
-
- QString msg = QStringLiteral("Type '%1' wasn't found in the type database.\n").arg(typeName);
+ QTextStream str(errorMessage);
+ str << "Type '" << typeName << "' wasn't found in the type database.\n";
if (candidates.isEmpty()) {
- qFatal("%sDeclare it in the type system using the proper <*-type> tag.",
- qPrintable(msg));
- }
-
- msg += QLatin1String("Remember to inform the full qualified name for the type you want to use.\nCandidates are:\n");
- candidates.sort();
- for (const QString& candidate : qAsConst(candidates)) {
- msg += QLatin1String(" ") + candidate + QLatin1Char('\n');
+ str << "Declare it in the type system using the proper <*-type> tag.";
+ } else {
+ str << "Remember to inform the full qualified name for the type you want to use.\nCandidates are:\n";
+ candidates.sort();
+ for (const QString& candidate : qAsConst(candidates))
+ str << " " << candidate << '\n';
}
- qFatal("%s", qPrintable(msg));
+ return nullptr;
}
auto *metaType = new AbstractMetaType;
@@ -2100,7 +2112,12 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const AddedFunction:
metaType->setConstant(typeInfo.isConstant);
if (isTemplate) {
for (const QString& templateArg : qAsConst(templateArgs)) {
- AbstractMetaType *metaArgType = translateType(AddedFunction::TypeInfo::fromSignature(templateArg));
+ AbstractMetaType *metaArgType = nullptr;
+ if (templateArg != QLatin1String("void")) {
+ metaArgType = translateType(AddedFunction::TypeInfo::fromSignature(templateArg), errorMessage);
+ if (!metaArgType)
+ return nullptr;
+ }
metaType->addInstantiation(metaArgType);
}
metaType->setTypeUsagePattern(AbstractMetaType::ContainerPattern);