From 51cb9304647fed901f3a19849d6758a757ce2d62 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 5 May 2017 15:25:16 +0200 Subject: Generate #error when a minimal constructor could not be found The occurred in 3 places, one of which generated #error and the others used qFatal(). Change it to always generate #error with a bit of context to make it possible to detect the source of of the problem. Change-Id: Icd93b1beec908b57fa72457d6ec1e16a15e5ff14 Reviewed-by: Christian Tismer --- generator/shiboken2/cppgenerator.cpp | 6 +++++- generator/shiboken2/shibokengenerator.cpp | 27 +++++++++++++++++++++------ generator/shiboken2/shibokengenerator.h | 4 ++-- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/generator/shiboken2/cppgenerator.cpp b/generator/shiboken2/cppgenerator.cpp index b6da137..68b6247 100644 --- a/generator/shiboken2/cppgenerator.cpp +++ b/generator/shiboken2/cppgenerator.cpp @@ -688,7 +688,11 @@ void CppGenerator::writeVirtualMethodNative(QTextStream&s, const AbstractMetaFun if (defaultReturnExpr.isEmpty()) defaultReturnExpr = minimalConstructor(func->type()); if (defaultReturnExpr.isEmpty()) { - QString errorMsg = QString::fromLatin1(MIN_CTOR_ERROR_MSG).arg(func->type()->cppSignature()); + QString errorMsg = QLatin1String(__FUNCTION__) + QLatin1String(": "); + if (const AbstractMetaClass *c = func->implementingClass()) + errorMsg += c->qualifiedCppName() + QLatin1String("::"); + errorMsg += func->signature(); + errorMsg = ShibokenGenerator::msgCouldNotFindMinimalConstructor(errorMsg, func->type()->cppSignature()); qCWarning(lcShiboken).noquote().nospace() << errorMsg; s << endl << INDENT << "#error " << errorMsg << endl; } diff --git a/generator/shiboken2/shibokengenerator.cpp b/generator/shiboken2/shibokengenerator.cpp index dadc46e..7b664e1 100644 --- a/generator/shiboken2/shibokengenerator.cpp +++ b/generator/shiboken2/shibokengenerator.cpp @@ -2626,9 +2626,13 @@ void ShibokenGenerator::writeMinimalConstructorExpression(QTextStream& s, const if (defaultCtor.isEmpty() && isCppPrimitive(type)) return; QString ctor = defaultCtor.isEmpty() ? minimalConstructor(type) : defaultCtor; - if (ctor.isEmpty()) - qFatal(qPrintable(QString::fromLatin1(MIN_CTOR_ERROR_MSG).arg(type->cppSignature())), NULL); - s << " = " << ctor; + if (ctor.isEmpty()) { + const QString message = msgCouldNotFindMinimalConstructor(QLatin1String(__FUNCTION__), type->cppSignature()); + qCWarning(lcShiboken()).noquote() << message; + s << ";\n#error " << message << '\n'; + } else { + s << " = " << ctor; + } } void ShibokenGenerator::writeMinimalConstructorExpression(QTextStream& s, const TypeEntry* type, const QString& defaultCtor) @@ -2636,9 +2640,14 @@ void ShibokenGenerator::writeMinimalConstructorExpression(QTextStream& s, const if (defaultCtor.isEmpty() && isCppPrimitive(type)) return; QString ctor = defaultCtor.isEmpty() ? minimalConstructor(type) : defaultCtor; - if (ctor.isEmpty()) - qFatal(qPrintable(QString::fromLatin1(MIN_CTOR_ERROR_MSG).arg(type->qualifiedCppName())), NULL); - s << " = " << ctor; + + if (ctor.isEmpty()) { + const QString message = msgCouldNotFindMinimalConstructor(QLatin1String(__FUNCTION__), type->qualifiedCppName()); + qCWarning(lcShiboken()).noquote() << message; + s << ";\n#error " << message << endl; + } else { + s << " = " << ctor; + } } bool ShibokenGenerator::isCppIntegralPrimitive(const TypeEntry* type) @@ -2657,3 +2666,9 @@ bool ShibokenGenerator::isCppIntegralPrimitive(const AbstractMetaType* type) { return isCppIntegralPrimitive(type->typeEntry()); } + +QString ShibokenGenerator::msgCouldNotFindMinimalConstructor(const QString &where, const QString &type) +{ + return where + QLatin1String(": Could not find a minimal constructor for type '") + type + + QLatin1String("'. This will result in a compilation error."); +} diff --git a/generator/shiboken2/shibokengenerator.h b/generator/shiboken2/shibokengenerator.h index 2a75a21..837e7d6 100644 --- a/generator/shiboken2/shibokengenerator.h +++ b/generator/shiboken2/shibokengenerator.h @@ -43,8 +43,6 @@ #define THREAD_STATE_SAVER_VAR "threadStateSaver" #define BEGIN_ALLOW_THREADS "PyThreadState* _save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS" #define END_ALLOW_THREADS "PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS" -#define MIN_CTOR_ERROR_MSG "Could not find a minimal constructor for type '%1'. "\ - "This will result in a compilation error." #define PYTHON_TO_CPP_VAR "pythonToCpp" #define SMART_POINTER_GETTER "kSmartPointerGetter" @@ -535,6 +533,8 @@ protected: }; void replaceConverterTypeSystemVariable(TypeSystemConverterVariable converterVariable, QString& code); + static QString msgCouldNotFindMinimalConstructor(const QString &where, const QString &type); + private: bool m_useCtorHeuristic; bool m_userReturnValueHeuristic; -- cgit v1.2.3