forked from qt-creator/qt-creator
		
	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
This commit is contained in:
		@@ -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.
 | 
			
		||||
 
 | 
			
		||||
@@ -62,7 +62,7 @@ public:
 | 
			
		||||
class CPLUSPLUS_EXPORT FindUsages: protected ASTVisitor
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FindUsages(Document::Ptr doc, const Snapshot &snapshot);
 | 
			
		||||
    FindUsages(const QByteArray &originalSource, Document::Ptr doc, const Snapshot &snapshot);
 | 
			
		||||
    FindUsages(const LookupContext &context);
 | 
			
		||||
 | 
			
		||||
    void operator()(Symbol *symbol);
 | 
			
		||||
@@ -75,8 +75,6 @@ protected:
 | 
			
		||||
 | 
			
		||||
    Scope *switchScope(Scope *scope);
 | 
			
		||||
 | 
			
		||||
    QString matchingLine(const Token &tk) const;
 | 
			
		||||
 | 
			
		||||
    void reportResult(unsigned tokenIndex, const Name *name, Scope *scope = 0);
 | 
			
		||||
    void reportResult(unsigned tokenIndex, const Identifier *id, Scope *scope = 0);
 | 
			
		||||
    void reportResult(unsigned tokenIndex, const QList<LookupItem> &candidates);
 | 
			
		||||
@@ -295,6 +293,7 @@ private:
 | 
			
		||||
    Document::Ptr _doc;
 | 
			
		||||
    Snapshot _snapshot;
 | 
			
		||||
    LookupContext _context;
 | 
			
		||||
    QByteArray _originalSource;
 | 
			
		||||
    QByteArray _source;
 | 
			
		||||
    QList<int> _references;
 | 
			
		||||
    QList<Usage> _usages;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user