From d91c218d540e3b4753f1fba98fa4c72c27cf39f8 Mon Sep 17 00:00:00 2001 From: Leandro Melo Date: Tue, 6 Sep 2011 11:50:58 +0200 Subject: C++: More flexibility for string representation of macros It's now possible to get the macro definition with the actual line breaks used on the code. This is particularly useful for tooltips in order for them to look nice. The preprocessor is changed so the macro also stores the breaks positions. This doesn't seem to have any impact on performance. In my machine, for example, the total time for parsing Creator's source code is approx. 18100ms with or without the patch. Change-Id: Ic7487236315c3567d26496315accdb2adfea894a Reviewed-on: http://codereview.qt.nokia.com/4253 Reviewed-by: Christian Kamm --- src/libs/cplusplus/Macro.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/libs/cplusplus/Macro.cpp') diff --git a/src/libs/cplusplus/Macro.cpp b/src/libs/cplusplus/Macro.cpp index 402ce4ae9c..8247e26adc 100644 --- a/src/libs/cplusplus/Macro.cpp +++ b/src/libs/cplusplus/Macro.cpp @@ -62,7 +62,7 @@ Macro::Macro() _state(0) { } -QString Macro::toString() const +QString Macro::decoratedName() const { QString text; if (f._hidden) @@ -85,6 +85,25 @@ QString Macro::toString() const text += QLatin1Char(')'); } text += QLatin1Char(' '); - text += QString::fromUtf8(_definition.constData(), _definition.size()); + return text; +} + +QString Macro::toString() const +{ + QString text = decoratedName(); + text.append(QString::fromUtf8(_definition.constData(), _definition.size())); + return text; +} + +QString Macro::toStringWithLineBreaks() const +{ + if (_lineBreaks.isEmpty()) + return toString(); + + QString text = decoratedName(); + QString definitionWithBreaks = QString::fromUtf8(_definition.constData(), _definition.size()); + foreach (unsigned pos, _lineBreaks) + definitionWithBreaks[pos] = '\n'; + text.append(definitionWithBreaks); return text; } -- cgit v1.2.1