aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/cplusplus/FindUsages.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <[email protected]>2011-01-17 14:41:19 +0100
committerErik Verbruggen <[email protected]>2011-01-17 14:47:20 +0100
commitdea74862d3d0cf7b4624bbb39069bb0fd3435644 (patch)
treef6d4da7665a71d6eb652d776798f370be381bba5 /src/libs/cplusplus/FindUsages.cpp
parent673f9871baceb9cfffc8ea199be548cd39803f53 (diff)
Fixed the line retreival for find-usages.
Instead of using the pre-processed source, the original one is used. This makes a difference when a macro is used in the line, where the pre- processed source would have a "#gen true" token. Task-number: QTCREATORBUG-3345
Diffstat (limited to 'src/libs/cplusplus/FindUsages.cpp')
-rw-r--r--src/libs/cplusplus/FindUsages.cpp28
1 files changed, 4 insertions, 24 deletions
diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp
index 38f168cebd1..f0b14d1ad63 100644
--- a/src/libs/cplusplus/FindUsages.cpp
+++ b/src/libs/cplusplus/FindUsages.cpp
@@ -45,13 +45,14 @@
using namespace CPlusPlus;
-FindUsages::FindUsages(Document::Ptr doc, const Snapshot &snapshot)
+FindUsages::FindUsages(const QByteArray &originalSource, Document::Ptr doc, const Snapshot &snapshot)
: ASTVisitor(doc->translationUnit()),
_id(0),
_declSymbol(0),
_doc(doc),
_snapshot(snapshot),
_context(doc, snapshot),
+ _originalSource(originalSource),
_source(_doc->source()),
_currentScope(0)
{
@@ -66,6 +67,7 @@ FindUsages::FindUsages(const LookupContext &context)
_doc(context.thisDocument()),
_snapshot(context.snapshot()),
_context(context),
+ _originalSource(_doc->source()),
_source(_doc->source()),
_currentScope(0)
{
@@ -101,27 +103,6 @@ void FindUsages::operator()(Symbol *symbol)
translationUnit(ast->asTranslationUnit());
}
-QString FindUsages::matchingLine(const Token &tk) const
-{
- const char *beg = _source.constData();
- const char *cp = beg + tk.offset;
- for (; cp != beg - 1; --cp) {
- if (*cp == '\n')
- break;
- }
-
- ++cp;
-
- const char *lineEnd = cp + 1;
- for (; *lineEnd; ++lineEnd) {
- if (*lineEnd == '\n')
- break;
- }
-
- const QString matchingLine = QString::fromUtf8(cp, lineEnd - cp);
- return matchingLine;
-}
-
void FindUsages::reportResult(unsigned tokenIndex, const Name *name, Scope *scope)
{
if (! (tokenIndex && name != 0))
@@ -163,10 +144,9 @@ void FindUsages::reportResult(unsigned tokenIndex)
_processed.insert(tokenIndex);
- const QString lineText = matchingLine(tk);
-
unsigned line, col;
getTokenStartPosition(tokenIndex, &line, &col);
+ const QString lineText = QString::fromUtf8(_originalSource.split('\n').at(line - 1));
if (col)
--col; // adjust the column position.