From 0f5920b798af86454abbc2e466f96336920b4f1c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 22 Nov 2018 13:25:01 +0100 Subject: shiboken: Add debug output for function modifications Task-number: PYSIDE-834 Change-Id: I2530b44f704ef96b784a77512f71777d9fd492bb Reviewed-by: Cristian Maureira-Fredes --- sources/shiboken2/ApiExtractor/typedatabase.cpp | 29 ++++-- sources/shiboken2/ApiExtractor/typesystem.cpp | 116 ++++++++++++++++++++++++ sources/shiboken2/ApiExtractor/typesystem.h | 15 +++ 3 files changed, 150 insertions(+), 10 deletions(-) (limited to 'sources') diff --git a/sources/shiboken2/ApiExtractor/typedatabase.cpp b/sources/shiboken2/ApiExtractor/typedatabase.cpp index 4cb6cdd8a..c0999e7ab 100644 --- a/sources/shiboken2/ApiExtractor/typedatabase.cpp +++ b/sources/shiboken2/ApiExtractor/typedatabase.cpp @@ -746,6 +746,20 @@ bool TypeDatabase::checkApiVersion(const QString &package, if (!var.isEmpty()) \ d << ", " << var.size() << ' ' << name; +template +static void formatList(QDebug &d, const char *name, const Container &c, Separator sep) +{ + if (const int size = c.size()) { + d << ", " << name << '[' << size << "]=("; + for (int i = 0; i < size; ++i) { + if (i) + d << sep; + d << c.at(i); + } + d << ')'; + } +} + void TypeEntry::formatDebug(QDebug &d) const { const QString cppName = qualifiedCppName(); @@ -766,14 +780,7 @@ void TypeEntry::formatDebug(QDebug &d) const d << ", sbkIndex=" << m_sbkIndex; if (m_include.isValid()) d << ", include=" << m_include; - if (const int count = m_extraIncludes.size()) { - d << ", extraIncludes[" << count << "]="; - for (int i = 0; i < count; ++i) { - if (i) - d << ", "; - d << m_extraIncludes.at(i); - } - } + formatList(d, "extraIncludes", m_extraIncludes, ", "); } void ComplexTypeEntry::formatDebug(QDebug &d) const @@ -794,7 +801,7 @@ void ComplexTypeEntry::formatDebug(QDebug &d) const FORMAT_NONEMPTY_STRING("targetType", m_targetType) FORMAT_NONEMPTY_STRING("hash", m_hashFunction) FORMAT_LIST_SIZE("addedFunctions", m_addedFunctions) - FORMAT_LIST_SIZE("functionMods", m_functionMods) + formatList(d, "functionMods", m_functionMods, ", "); FORMAT_LIST_SIZE("fieldMods", m_fieldMods) } @@ -876,7 +883,9 @@ void TypeDatabase::formatDebug(QDebug &d) const } d << ")\n"; } - d <<"\nglobalUserFunctions=" << m_globalUserFunctions << ')'; + d <<"\nglobalUserFunctions=" << m_globalUserFunctions << '\n'; + formatList(d, "globalFunctionMods", m_functionMods, '\n'); + d << ')'; } QDebug operator<<(QDebug d, const TypeDatabase &db) diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp index 2c7f5eeaa..4c522be6c 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.cpp +++ b/sources/shiboken2/ApiExtractor/typesystem.cpp @@ -3208,6 +3208,122 @@ AddedFunction::AddedFunction(QString signature, const QString &returnType) : } #ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug d, const ReferenceCount &r) +{ + QDebugStateSaver saver(d); + d.noquote(); + d.nospace(); + d << "ReferenceCount(" << r.varName << ", action=" << r.action << ')'; + return d; +} + +QDebug operator<<(QDebug d, const CodeSnip &s) +{ + QDebugStateSaver saver(d); + d.noquote(); + d.nospace(); + d << "CodeSnip(language=" << s.language << ", position=" << s.position << ", \""; + for (const auto &f : s.codeList) { + const QString &code = f.code(); + const auto lines = code.splitRef(QLatin1Char('\n')); + for (int i = 0, size = lines.size(); i < size; ++i) { + if (i) + d << "\\n"; + d << lines.at(i).trimmed(); + } + } + d << '"'; + if (!s.argumentMap.isEmpty()) { + d << ", argumentMap{"; + for (auto it = s.argumentMap.cbegin(), end = s.argumentMap.cend(); it != end; ++it) + d << it.key() << "->\"" << it.value() << '"'; + d << '}'; + } + d << ')'; + return d; +} + +void Modification::formatDebug(QDebug &d) const +{ + d << "modifiers=" << hex << showbase << modifiers << noshowbase << dec; + if (removal) + d << ", removal"; + if (!renamedToName.isEmpty()) + d << ", renamedToName=\"" << renamedToName << '"'; +} + +void FunctionModification::formatDebug(QDebug &d) const +{ + if (m_signature.isEmpty()) + d << "pattern=\"" << m_signaturePattern.pattern(); + else + d << "signature=\"" << m_signature; + d << "\", "; + Modification::formatDebug(d); + if (!association.isEmpty()) + d << ", association=\"" << association << '"'; + if (m_allowThread != TypeSystem::AllowThread::Unspecified) + d << ", allowThread=" << int(m_allowThread); + if (m_thread) + d << ", thread"; + if (m_exceptionHandling != TypeSystem::ExceptionHandling::Unspecified) + d << ", exceptionHandling=" << int(m_exceptionHandling); + if (!snips.isEmpty()) + d << ", snips=(" << snips << ')'; + if (!argument_mods.isEmpty()) + d << ", argument_mods=(" << argument_mods << ')'; +} + +QDebug operator<<(QDebug d, const ArgumentOwner &a) +{ + QDebugStateSaver saver(d); + d.noquote(); + d.nospace(); + d << "ArgumentOwner(index=" << a.index << ", action=" << a.action << ')'; + return d; +} + +QDebug operator<<(QDebug d, const ArgumentModification &a) +{ + QDebugStateSaver saver(d); + d.noquote(); + d.nospace(); + d << "ArgumentModification(index=" << a.index; + if (a.removedDefaultExpression) + d << ", removedDefaultExpression"; + if (a.removed) + d << ", removed"; + if (a.noNullPointers) + d << ", noNullPointers"; + if (a.array) + d << ", array"; + if (!a.referenceCounts.isEmpty()) + d << ", referenceCounts=" << a.referenceCounts; + if (!a.modified_type.isEmpty()) + d << ", modified_type=\"" << a.modified_type << '"'; + if (!a.replace_value.isEmpty()) + d << ", replace_value=\"" << a.replace_value << '"'; + if (!a.replacedDefaultExpression.isEmpty()) + d << ", replacedDefaultExpression=\"" << a.replacedDefaultExpression << '"'; + if (!a.ownerships.isEmpty()) + d << ", ownerships=" << a.ownerships; + if (!a.renamed_to.isEmpty()) + d << ", renamed_to=\"" << a.renamed_to << '"'; + d << ", owner=" << a.owner << ')'; + return d; +} + +QDebug operator<<(QDebug d, const FunctionModification &fm) +{ + QDebugStateSaver saver(d); + d.noquote(); + d.nospace(); + d << "FunctionModification("; + fm.formatDebug(d); + d << ')'; + return d; +} + QDebug operator<<(QDebug d, const AddedFunction::TypeInfo &ti) { QDebugStateSaver saver(d); diff --git a/sources/shiboken2/ApiExtractor/typesystem.h b/sources/shiboken2/ApiExtractor/typesystem.h index 721d19f29..b0144923a 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.h +++ b/sources/shiboken2/ApiExtractor/typesystem.h @@ -308,6 +308,10 @@ struct Modification return removal != TypeSystem::NoLanguage; } +#ifndef QT_NO_DEBUG_STREAM + void formatDebug(QDebug &d) const; +#endif + QString renamedToName; uint modifiers = 0; TypeSystem::Language removal = TypeSystem::NoLanguage; @@ -351,6 +355,10 @@ struct FunctionModification: public Modification QString toString() const; +#ifndef QT_NO_DEBUG_STREAM + void formatDebug(QDebug &d) const; +#endif + QString association; CodeSnipList snips; @@ -365,6 +373,13 @@ private: TypeSystem::ExceptionHandling m_exceptionHandling = TypeSystem::ExceptionHandling::Unspecified; }; +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug d, const ReferenceCount &); +QDebug operator<<(QDebug d, const ArgumentOwner &a); +QDebug operator<<(QDebug d, const ArgumentModification &a); +QDebug operator<<(QDebug d, const FunctionModification &fm); +#endif + struct FieldModification: public Modification { bool isReadable() const -- cgit v1.2.3