Commit 0f301f86 authored by Roberto Raggi's avatar Roberto Raggi

New implementation of CPlusPlus::FindUsages

parent f72a080d
This diff is collapsed.
This diff is collapsed.
...@@ -739,12 +739,14 @@ void CPPEditor::markSymbolsNow() ...@@ -739,12 +739,14 @@ void CPPEditor::markSymbolsNow()
setExtraSelections(CodeSemanticsSelection, selections); setExtraSelections(CodeSemanticsSelection, selections);
} }
static QList<int> lazyFindReferences(Scope *scope, QString code, const LookupContext &context) static QList<int> lazyFindReferences(Scope *scope, QString code, Document::Ptr doc, Snapshot snapshot)
{ {
TypeOfExpression typeOfExpression; TypeOfExpression typeOfExpression;
typeOfExpression.init(context.thisDocument(), context.snapshot(), context.bindings()); snapshot.insert(doc);
if (Symbol *canonicalSymbol = CanonicalSymbol::canonicalSymbol(scope, code, typeOfExpression)) typeOfExpression.init(doc, snapshot);
return CppTools::CppModelManagerInterface::instance()->references(canonicalSymbol, context); if (Symbol *canonicalSymbol = CanonicalSymbol::canonicalSymbol(scope, code, typeOfExpression)) {
return CppTools::CppModelManagerInterface::instance()->references(canonicalSymbol, typeOfExpression.context());
}
return QList<int>(); return QList<int>();
} }
...@@ -758,12 +760,10 @@ void CPPEditor::markSymbols(const QTextCursor &tc, const SemanticInfo &info) ...@@ -758,12 +760,10 @@ void CPPEditor::markSymbols(const QTextCursor &tc, const SemanticInfo &info)
CanonicalSymbol cs(this, info); CanonicalSymbol cs(this, info);
QString expression; QString expression;
if (Scope *scope = cs.getScopeAndExpression(this, info, tc, &expression)) { if (Scope *scope = cs.getScopeAndExpression(this, info, tc, &expression)) {
LookupContext context(info.doc, info.snapshot);
m_references.cancel(); m_references.cancel();
m_referencesRevision = info.revision; m_referencesRevision = info.revision;
m_referencesCursorPosition = position(); m_referencesCursorPosition = position();
m_references = QtConcurrent::run(&lazyFindReferences, scope, expression, context); m_references = QtConcurrent::run(&lazyFindReferences, scope, expression, info.doc, info.snapshot);
m_referencesWatcher.setFuture(m_references); m_referencesWatcher.setFuture(m_references);
} else { } else {
const QList<QTextEdit::ExtraSelection> selections = extraSelections(CodeSemanticsSelection); const QList<QTextEdit::ExtraSelection> selections = extraSelections(CodeSemanticsSelection);
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include <cplusplus/CppDocument.h> #include <cplusplus/CppDocument.h>
#include <cplusplus/Overview.h> #include <cplusplus/Overview.h>
#include <cplusplus/FindUsages.h>
#include <QtCore/QTime> #include <QtCore/QTime>
#include <QtCore/QTimer> #include <QtCore/QTimer>
...@@ -108,18 +109,25 @@ public: ...@@ -108,18 +109,25 @@ public:
return usages; // skip this document, it's not using symbolId. return usages; // skip this document, it's not using symbolId.
} }
QByteArray source = snapshot.preprocessedCode( Document::Ptr doc;
getSource(fileName, workingCopy), fileName); QByteArray source;
Document::Ptr doc = snapshot.documentFromSource(source, fileName); if (symbolDocument && fileName == symbolDocument->fileName())
doc->tokenize(); doc = symbolDocument;
else {
source = snapshot.preprocessedCode(getSource(fileName, workingCopy), fileName);
doc = snapshot.documentFromSource(source, fileName);
doc->tokenize();
}
Control *control = doc->control(); Control *control = doc->control();
if (control->findIdentifier(symbolId->chars(), symbolId->size()) != 0) { if (control->findIdentifier(symbolId->chars(), symbolId->size()) != 0) {
doc->check(); if (doc != symbolDocument)
doc->check();
FindUsages process(doc, snapshot); FindUsages process(doc, snapshot);
process(symbol); process(symbol);
usages = process.usages(); usages = process.usages();
} }
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "TypeMatcher.h" #include "TypeMatcher.h"
#include <map> #include <map>
#include <set> #include <set>
#include <algorithm>
using namespace CPlusPlus; using namespace CPlusPlus;
...@@ -770,3 +771,8 @@ const Identifier *Control::objcCopyId() const ...@@ -770,3 +771,8 @@ const Identifier *Control::objcCopyId() const
const Identifier *Control::objcNonatomicId() const const Identifier *Control::objcNonatomicId() const
{ return d->objcNonatomicId; } { return d->objcNonatomicId; }
bool Control::hasSymbol(Symbol *symbol) const
{
return std::find(d->symbols.begin(), d->symbols.end(), symbol) != d->symbols.end();
}
...@@ -209,6 +209,8 @@ public: ...@@ -209,6 +209,8 @@ public:
const NumericLiteral *findOrInsertNumericLiteral(const char *chars, unsigned size); const NumericLiteral *findOrInsertNumericLiteral(const char *chars, unsigned size);
const NumericLiteral *findOrInsertNumericLiteral(const char *chars); const NumericLiteral *findOrInsertNumericLiteral(const char *chars);
bool hasSymbol(Symbol *symbol) const;
private: private:
class Data; class Data;
friend class Data; friend class Data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment