From 58639e47f2ebf1c6b058cfcdcbada52afc43908d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 6 Sep 2018 09:45:58 +0200 Subject: shiboken: Improve error messages about rejected enums Use different messages for type entry not found and conflicting types. Spell out values of anonymous enums and indicate scoped enums and associated classes. Change-Id: Id60eb70c28790019b29ebae174369e6963909587 Reviewed-by: Cristian Maureira-Fredes Reviewed-by: Christian Tismer --- .../PySide2/QtCore/typesystem_core_common.xml | 2 +- sources/pyside2/PySide2/QtQml/typesystem_qml.xml | 2 +- .../shiboken2/ApiExtractor/abstractmetabuilder.cpp | 82 ++++++++++++++++++++-- 3 files changed, 77 insertions(+), 9 deletions(-) diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml index 1744a5927..ba141a177 100644 --- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml +++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml @@ -4410,7 +4410,7 @@ s1.addTransition(button.clicked, s1h)</code> - + diff --git a/sources/pyside2/PySide2/QtQml/typesystem_qml.xml b/sources/pyside2/PySide2/QtQml/typesystem_qml.xml index 5103b9218..4a346f232 100644 --- a/sources/pyside2/PySide2/QtQml/typesystem_qml.xml +++ b/sources/pyside2/PySide2/QtQml/typesystem_qml.xml @@ -217,5 +217,5 @@ - + diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index a200a87d1..85bb1b789 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -863,6 +863,66 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseNamespace(const FileModel return metaClass; } +template +static void msgFormatEnumType(Stream &str, + const EnumModelItem &enumItem, + const QString &className) +{ + switch (enumItem->enumKind()) { + case CEnum: + str << "Enum '" << enumItem->qualifiedName().join(colonColon()) << '\''; + break; + case AnonymousEnum: { + const EnumeratorList &values = enumItem->enumerators(); + str << "Anonymous enum ("; + switch (values.size()) { + case 0: + break; + case 1: + str << values.constFirst()->name(); + break; + case 2: + str << values.at(0)->name() << ", " << values.at(1)->name(); + break; + default: + str << values.at(0)->name() << ", ... , " + << values.at(values.size() - 1)->name(); + break; + } + str << ')'; + } + break; + case EnumClass: + str << "Scoped enum '" << enumItem->qualifiedName().join(colonColon()) << '\''; + break; + } + if (!className.isEmpty()) + str << " (class: " << className << ')'; +} + +static inline QString msgNoEnumTypeEntry(const EnumModelItem &enumItem, + const QString &className) +{ + QString result; + QTextStream str(&result); + msgFormatEnumType(str, enumItem, className); + str << " does not have a type entry"; + return result; +} + +static QString msgNoEnumTypeConflict(const EnumModelItem &enumItem, + const QString &className, + const TypeEntry *t) +{ + QString result; + QDebug debug(&result); // Use the debug operator for TypeEntry::Type + debug.noquote(); + debug.nospace(); + msgFormatEnumType(debug, enumItem, className); + debug << " is not an enum (type: " << t->type() << ')'; + return result; +} + AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem &enumItem, AbstractMetaClass *enclosing, const QSet &enumsDeclarations) @@ -907,15 +967,23 @@ AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem & return 0; } - if ((!typeEntry || !typeEntry->isEnum())) { - if (!m_currentClass || - (m_currentClass->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang)) { - qCWarning(lcShiboken).noquote().nospace() - << QStringLiteral("enum '%1' does not have a type entry or is not an enum") - .arg(qualifiedName); + const bool rejectionWarning = !m_currentClass + || (m_currentClass->typeEntry()->codeGeneration() & TypeEntry::GenerateTargetLang); + + if (!typeEntry) { + if (rejectionWarning) + qCWarning(lcShiboken, "%s", qPrintable(msgNoEnumTypeEntry(enumItem, className))); + m_rejectedEnums.insert(qualifiedName, AbstractMetaBuilder::NotInTypeSystem); + return nullptr; + } + + if (!typeEntry->isEnum()) { + if (rejectionWarning) { + qCWarning(lcShiboken, "%s", + qPrintable(msgNoEnumTypeConflict(enumItem, className, typeEntry))); } m_rejectedEnums.insert(qualifiedName, AbstractMetaBuilder::NotInTypeSystem); - return 0; + return nullptr; } AbstractMetaEnum *metaEnum = new AbstractMetaEnum; -- cgit v1.2.3