aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-03-03 08:42:04 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2017-03-03 08:48:18 +0000
commit77eefb7a42c4a96f69ac4f5af464ea3520ae4de7 (patch)
tree446ca670a308209b7488176aabccf6eb51f85a5f
parent8d77d61eef45ccb3200f54e24c057da255edfc63 (diff)
CodeModel/MetaBuilder: Improve debug formatting
Output the code model item class directly, output the line number in addition, add line breaks to some sequences. Output templates and scopes of the MetaBuilder. Task-number: PYSIDE-323 Change-Id: I523afdcce09e5756f6ad37c09239bae528654642 Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--ApiExtractor/abstractmetabuilder.cpp25
-rw-r--r--ApiExtractor/parser/codemodel.cpp119
2 files changed, 94 insertions, 50 deletions
diff --git a/ApiExtractor/abstractmetabuilder.cpp b/ApiExtractor/abstractmetabuilder.cpp
index a21faf90f..789712da3 100644
--- a/ApiExtractor/abstractmetabuilder.cpp
+++ b/ApiExtractor/abstractmetabuilder.cpp
@@ -3256,7 +3256,8 @@ void AbstractMetaBuilderPrivate::setInclude(TypeEntry *te, const QString &fileNa
#ifndef QT_NO_DEBUG_STREAM
template <class Container>
-static void debugFormatSequence(QDebug &d, const char *key, const Container& c)
+static void debugFormatSequence(QDebug &d, const char *key, const Container& c,
+ const char *separator = ", ")
{
typedef typename Container::const_iterator ConstIt;
if (c.isEmpty())
@@ -3266,7 +3267,7 @@ static void debugFormatSequence(QDebug &d, const char *key, const Container& c)
d << "\n " << key << '[' << c.size() << "]=(";
for (ConstIt it = begin; it != end; ++it) {
if (it != begin)
- d << ", ";
+ d << separator;
d << *it;
}
d << ')';
@@ -3274,12 +3275,22 @@ static void debugFormatSequence(QDebug &d, const char *key, const Container& c)
void AbstractMetaBuilder::formatDebug(QDebug &debug) const
{
- debug << "classCount=" << d->m_metaClasses.size()
- << ", m_globalHeader=" << d->m_globalHeader.absoluteFilePath();
+ debug << "m_globalHeader=" << d->m_globalHeader.absoluteFilePath();
debugFormatSequence(debug, "qtMetaTypeDeclaredTypeNames", d->m_qmetatypeDeclaredTypenames);
- debugFormatSequence(debug, "globalEnums", d->m_globalEnums);
- debugFormatSequence(debug, "globalFunctions", d->m_globalFunctions);
- debugFormatSequence(debug, "classes", d->m_metaClasses);
+ debugFormatSequence(debug, "globalEnums", d->m_globalEnums, "\n");
+ debugFormatSequence(debug, "globalFunctions", d->m_globalFunctions, "\n");
+ if (const int scopeCount = d->m_scopes.size()) {
+ debug << "\n scopes[" << scopeCount << "]=(";
+ for (int i = 0; i < scopeCount; ++i) {
+ if (i)
+ debug << ", ";
+ _CodeModelItem::formatKind(debug, d->m_scopes.at(i)->kind());
+ debug << " \"" << d->m_scopes.at(i)->name() << '"';
+ }
+ debug << ')';
+ }
+ debugFormatSequence(debug, "classes", d->m_metaClasses, "\n");
+ debugFormatSequence(debug, "templates", d->m_templates, "\n");
}
QDebug operator<<(QDebug d, const AbstractMetaBuilder &ab)
diff --git a/ApiExtractor/parser/codemodel.cpp b/ApiExtractor/parser/codemodel.cpp
index f803e9c7e..87cb6bd06 100644
--- a/ApiExtractor/parser/codemodel.cpp
+++ b/ApiExtractor/parser/codemodel.cpp
@@ -384,50 +384,65 @@ static void formatPtrSequence(QDebug &d, It i1, It i2, const char *separator=",
void _CodeModelItem::formatKind(QDebug &d, int k)
{
- if ((k & Kind_Variable) == Kind_Variable)
- d << "Variable";
- else if ((k & Kind_TypeDef) == Kind_TypeDef)
- d << "TypeAlias";
- else if ((k & Kind_TemplateParameter) == Kind_TemplateParameter)
- d << "TemplateParameter";
- else if ((k & Kind_FunctionDefinition) == Kind_FunctionDefinition)
- d << "FunctionDefinition";
- else if ((k & Kind_File) == Kind_File)
- d << "File";
- else if ((k & Kind_Enumerator) == Kind_Enumerator)
- d << "Enumerator";
- else if ((k & Kind_Enum) == Kind_Enum)
- d << "Enum";
- else if ((k & Kind_Class) == Kind_Class)
- d << "Class";
- else if ((k & Kind_Argument) == Kind_Argument)
- d << "Argument";
- switch (k & KindMask) {
+ switch (k) {
+ case Kind_Argument:
+ d << "ArgumentModelItem";
+ break;
+ case Kind_Class:
+ d << "ClassModelItem";
+ break;
+ case Kind_Enum:
+ d << "EnumModelItem";
+ break;
+ case Kind_Enumerator:
+ d << "EnumeratorModelItem";
+ break;
+ case Kind_File:
+ d << "FileModelItem";
+ break;
case Kind_Function:
- d << "/Function";
+ d << "FunctionModelItem";
+ break;
+ case Kind_FunctionDefinition:
+ d << "FunctionDefinitionModelItem";
break;
case Kind_Member:
- d << "/Member";
+ d << "MemberModelItem";
break;
case Kind_Namespace:
- d << "/Namespace";
+ d << "NamespaceModelItem";
+ break;
+ case Kind_Variable:
+ d << "ScopeModelItem";
break;
case Kind_Scope:
- d << "/Scope";
+ d << "ScopeModelItem";
+ break;
+ case Kind_TemplateParameter:
+ d << "TemplateParameter";
+ break;
+ case Kind_TypeDef:
+ d << "TypeDefModelItem";
+ break;
+ default:
+ d << "CodeModelItem";
break;
}
}
void _CodeModelItem::formatDebug(QDebug &d) const
{
- _CodeModelItem::formatKind(d, kind());
- d << ", \"" << name() << '"';
+ d << "(\"" << name() << '"';
if (!m_scope.isEmpty()) {
d << ", scope=";
formatSequence(d, m_scope.cbegin(), m_scope.cend(), "::");
}
- if (!m_fileName.isEmpty())
- d << ", file=\"" << QDir::toNativeSeparators(m_fileName) << '"';
+ if (!m_fileName.isEmpty()) {
+ d << ", file=\"" << QDir::toNativeSeparators(m_fileName);
+ if (m_startLine > 0)
+ d << ':' << m_startLine;
+ d << '"';
+ }
}
QDebug operator<<(QDebug d, const _CodeModelItem *t)
@@ -435,11 +450,20 @@ QDebug operator<<(QDebug d, const _CodeModelItem *t)
QDebugStateSaver s(d);
d.noquote();
d.nospace();
- d << "CodeModelItem(";
- if (t)
- t->formatDebug(d);
- else
- d << '0';
+ if (!t) {
+ d << "CodeModelItem(0)";
+ return d;
+ }
+ _CodeModelItem::formatKind(d, t->kind());
+ t->formatDebug(d);
+ switch (t->kind()) {
+ case _CodeModelItem::Kind_Class:
+ d << " /* class " << t->name() << " */";
+ break;
+ case _CodeModelItem::Kind_Namespace:
+ d << " /* namespace " << t->name() << " */";
+ break;
+ }
d << ')';
return d;
}
@@ -497,13 +521,14 @@ void _ClassModelItem::addPropertyDeclaration(const QString &propertyDeclaration)
#ifndef QT_NO_DEBUG_STREAM
template <class List>
-static void formatModelItemList(QDebug &d, const char *prefix, const List &l)
+static void formatModelItemList(QDebug &d, const char *prefix, const List &l,
+ const char *separator = ", ")
{
if (const int size = l.size()) {
d << prefix << '[' << size << "](";
for (int i = 0; i < size; ++i) {
if (i)
- d << ", ";
+ d << separator;
l.at(i)->formatDebug(d);
}
d << ')';
@@ -584,7 +609,9 @@ void _ScopeModelItem::addEnum(EnumModelItem item)
#ifndef QT_NO_DEBUG_STREAM
template <class Hash>
-static void formatScopeHash(QDebug &d, const char *prefix, const Hash &h)
+static void formatScopeHash(QDebug &d, const char *prefix, const Hash &h,
+ const char *separator = ", ",
+ bool trailingNewLine = false)
{
typedef typename Hash::ConstIterator HashIterator;
if (!h.isEmpty()) {
@@ -593,30 +620,36 @@ static void formatScopeHash(QDebug &d, const char *prefix, const Hash &h)
const HashIterator end = h.end();
for (HashIterator it = begin; it != end; ++it) { // Omit the names as they are repeated
if (it != begin)
- d << ", ";
+ d << separator;
d << it.value().data();
}
d << ')';
+ if (trailingNewLine)
+ d << '\n';
}
}
template <class List>
-static void formatScopeList(QDebug &d, const char *prefix, const List &l)
+static void formatScopeList(QDebug &d, const char *prefix, const List &l,
+ const char *separator = ", ",
+ bool trailingNewLine = false)
{
if (!l.isEmpty()) {
d << prefix << '[' << l.size() << "](";
- formatPtrSequence(d, l.begin(), l.end());
+ formatPtrSequence(d, l.begin(), l.end(), separator);
d << ')';
+ if (trailingNewLine)
+ d << '\n';
}
}
void _ScopeModelItem::formatScopeItemsDebug(QDebug &d) const
{
- formatScopeList(d, ", classes=", m_classes);
- formatScopeList(d, ", enums=", m_enums);
- formatScopeList(d, ", aliases=", m_typeDefs);
- formatScopeHash(d, ", functionDefs=", m_functionDefinitions);
- formatScopeHash(d, ", functions=", m_functions);
+ formatScopeList(d, ", classes=", m_classes, "\n", true);
+ formatScopeList(d, ", enums=", m_enums, "\n", true);
+ formatScopeList(d, ", aliases=", m_typeDefs, "\n", true);
+ formatScopeHash(d, ", functionDefs=", m_functionDefinitions, "\n", true);
+ formatScopeHash(d, ", functions=", m_functions, "\n", true);
formatScopeList(d, ", variables=", m_variables);
}