From 6f3f7d0aeeaa1ed813cbba07353312604464a92d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 4 Jul 2018 09:06:33 +0200 Subject: shiboken: Improve error messages when rejecting functions Pass up errors from translateType() to traverseFunction(). Remove the check for void type parameters since that is not needed any more after 50dd4ae202d7afb3556335c056db003f5ef50532. Task-number: PYSIDE-672 Change-Id: I82c095f027196361200b8854139b4bbc1fcc38c8 Reviewed-by: Cristian Maureira-Fredes Reviewed-by: Christian Tismer --- .../shiboken2/ApiExtractor/abstractmetabuilder.cpp | 40 +++++++--------------- 1 file changed, 12 insertions(+), 28 deletions(-) (limited to 'sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp') diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index 4c7077ae2..a4186da1a 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -1803,7 +1803,8 @@ static inline QString qualifiedFunctionSignatureWithType(const FunctionModelItem return result; } -static inline QString msgUnmatchedParameterType(const ArgumentModelItem &arg, int n) +static inline QString msgUnmatchedParameterType(const ArgumentModelItem &arg, int n, + const QString &why) { QString result; QTextStream str(&result); @@ -1811,23 +1812,16 @@ static inline QString msgUnmatchedParameterType(const ArgumentModelItem &arg, in << (n + 1); if (!arg->name().isEmpty()) str << " \"" << arg->name() << '"'; + str << ": " << why; return result; } -static inline QString msgUnmatchedReturnType(const FunctionModelItem &functionItem) +static inline QString msgUnmatchedReturnType(const FunctionModelItem &functionItem, + const QString &why) { return QLatin1String("unmatched return type '") - + functionItem->type().toString() + QLatin1Char('\''); -} - -static inline QString msgVoidParameterType(const ArgumentModelItem &arg, int n) -{ - QString result; - QTextStream str(&result); - str << "'void' encountered at parameter #" << (n + 1); - if (!arg->name().isEmpty()) - str << " \"" << arg->name() << '"'; - return result; + + functionItem->type().toString() + + QLatin1String("': ") + why; } static QString msgSkippingFunction(const FunctionModelItem &functionItem, @@ -1992,6 +1986,7 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(FunctionModel else *metaFunction += AbstractMetaAttributes::Protected; + QString errorMessage; switch (metaFunction->functionType()) { case AbstractMetaFunction::DestructorFunction: break; @@ -2010,9 +2005,9 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(FunctionModel AbstractMetaType *type = nullptr; if (!returnType.isVoid()) { - type = translateType(returnType); + type = translateType(returnType, true, &errorMessage); if (!type) { - const QString reason = msgUnmatchedReturnType(functionItem); + const QString reason = msgUnmatchedReturnType(functionItem, errorMessage); qCWarning(lcShiboken, "%s", qPrintable(msgSkippingFunction(functionItem, originalQualifiedSignatureWithReturn, reason))); m_rejectedFunctions.insert(originalQualifiedSignatureWithReturn, AbstractMetaBuilder::UnmatchedReturnType); @@ -2046,7 +2041,7 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(FunctionModel return nullptr; } - AbstractMetaType *metaType = translateType(arg->type()); + AbstractMetaType *metaType = translateType(arg->type(), true, &errorMessage); if (!metaType) { // If an invalid argument has a default value, simply remove it if (arg->defaultValue()) { @@ -2063,18 +2058,7 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(FunctionModel break; } Q_ASSERT(metaType == 0); - const QString reason = msgUnmatchedParameterType(arg, i); - qCWarning(lcShiboken, "%s", - qPrintable(msgSkippingFunction(functionItem, originalQualifiedSignatureWithReturn, reason))); - const QString rejectedFunctionSignature = originalQualifiedSignatureWithReturn - + QLatin1String(": ") + reason; - m_rejectedFunctions.insert(rejectedFunctionSignature, AbstractMetaBuilder::UnmatchedArgumentType); - delete metaFunction; - return nullptr; - } - - if (metaType == Q_NULLPTR) { - const QString reason = msgVoidParameterType(arg, i); + const QString reason = msgUnmatchedParameterType(arg, i, errorMessage); qCWarning(lcShiboken, "%s", qPrintable(msgSkippingFunction(functionItem, originalQualifiedSignatureWithReturn, reason))); const QString rejectedFunctionSignature = originalQualifiedSignatureWithReturn -- cgit v1.2.3