From be1cde6ed5dcd6876eef078101699410667de2c1 Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Wed, 11 Aug 2010 14:35:58 +0200 Subject: [PATCH] Pretty print templates. --- src/libs/cplusplus/Overview.cpp | 13 +++++++++- src/libs/cplusplus/Overview.h | 4 ++++ src/libs/cplusplus/TypePrettyPrinter.cpp | 30 ++++++++++++------------ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/libs/cplusplus/Overview.cpp b/src/libs/cplusplus/Overview.cpp index b1856adba09..31160aa17d0 100644 --- a/src/libs/cplusplus/Overview.cpp +++ b/src/libs/cplusplus/Overview.cpp @@ -44,7 +44,8 @@ Overview::Overview() _showArgumentNames(false), _showReturnTypes(false), _showFunctionSignatures(true), - _showDefaultArguments(true) + _showDefaultArguments(true), + _showTemplateParameters(false) { } Overview::~Overview() @@ -120,6 +121,16 @@ void Overview::setShowDefaultArguments(bool showDefaultArguments) _showDefaultArguments = showDefaultArguments; } +bool Overview::showTemplateParameters() const +{ + return _showTemplateParameters; +} + +void Overview::setShowTemplateParameters(bool showTemplateParameters) +{ + _showTemplateParameters = showTemplateParameters; +} + QString Overview::prettyName(const Name *name) const { NamePrettyPrinter pp(this); diff --git a/src/libs/cplusplus/Overview.h b/src/libs/cplusplus/Overview.h index 785a4536670..ec3825fe9a0 100644 --- a/src/libs/cplusplus/Overview.h +++ b/src/libs/cplusplus/Overview.h @@ -56,6 +56,9 @@ public: bool showDefaultArguments() const; void setShowDefaultArguments(bool showDefaultArguments); + bool showTemplateParameters() const; + void setShowTemplateParameters(bool showTemplateParameters); + // argument index that you want to mark unsigned markedArgument() const; void setMarkedArgument(unsigned position); @@ -88,6 +91,7 @@ private: bool _showReturnTypes: 1; bool _showFunctionSignatures: 1; bool _showDefaultArguments: 1; + bool _showTemplateParameters: 1; }; } // end of namespace CPlusPlus diff --git a/src/libs/cplusplus/TypePrettyPrinter.cpp b/src/libs/cplusplus/TypePrettyPrinter.cpp index 30b9e040cba..30dc3ecaf80 100644 --- a/src/libs/cplusplus/TypePrettyPrinter.cpp +++ b/src/libs/cplusplus/TypePrettyPrinter.cpp @@ -142,23 +142,23 @@ void TypePrettyPrinter::visit(Namespace *type) void TypePrettyPrinter::visit(Template *type) { - const unsigned argc = type->templateParameterCount(); - QString decl; - decl += QLatin1String("template <"); - for (unsigned i = 0; i < argc; ++i) { - if (i != 0) - decl += QLatin1String(", "); - - decl += QLatin1String("T"); - decl += QString::number(i + 1); - } - decl += QLatin1Char('<'); if (Symbol *d = type->declaration()) { - decl += QLatin1Char(' '); - decl += overview()->prettyType(d->type(), d->name()); + if (overview()->showTemplateParameters() && ! _name.isEmpty()) { + _name += QLatin1Char('<'); + for (unsigned index = 0; index < type->templateParameterCount(); ++index) { + if (index) + _name += QLatin1String(", "); + QString arg = overview()->prettyName(type->templateParameterAt(index)->name()); + if (arg.isEmpty()) { + arg += QLatin1Char('T'); + arg += QString::number(index + 1); + } + _name += arg; + } + _name += QLatin1Char('>'); + } + acceptType(d->type()); } - _text.prepend(decl); - qWarning() << "here:" << decl; prependCv(_fullySpecifiedType); } -- GitLab