diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp index bc9175740f887f052f36bbf3a477f4b8ddafc24e..0d48bb0d7a3e995d02d7e39565663544d1a1380e 100644 --- a/src/libs/cplusplus/FindUsages.cpp +++ b/src/libs/cplusplus/FindUsages.cpp @@ -57,17 +57,23 @@ void FindUsages::setGlobalNamespaceBinding(NamespaceBindingPtr globalNamespaceBi _globalNamespaceBinding = globalNamespaceBinding; } -QList<int> FindUsages::operator()(Symbol *symbol, const Identifier *id, AST *ast) +QList<Usage> FindUsages::usages() const +{ return _usages; } + +QList<int> FindUsages::references() const +{ return _references; } + +void FindUsages::operator()(Symbol *symbol, const Identifier *id, AST *ast) { _processed.clear(); _references.clear(); + _usages.clear(); _declSymbol = symbol; _id = id; if (_declSymbol && _id) { _exprDoc = Document::create("<references>"); accept(ast); } - return _references; } QString FindUsages::matchingLine(const Token &tk) const @@ -120,9 +126,11 @@ void FindUsages::reportResult(unsigned tokenIndex) const int len = tk.f.length; - if (_future) { - _future->reportResult(Usage(_doc->fileName(), line, lineText, col, len)); - } + const Usage u(_doc->fileName(), line, lineText, col, len); + _usages.append(u); + + if (_future) + _future->reportResult(u); _references.append(tokenIndex); } diff --git a/src/libs/cplusplus/FindUsages.h b/src/libs/cplusplus/FindUsages.h index 4109a252df13333f0cd64c42a0e38f5a453da207..4b09e1502e15f6e62d27999bd5cefe3890e1dd83 100644 --- a/src/libs/cplusplus/FindUsages.h +++ b/src/libs/cplusplus/FindUsages.h @@ -47,12 +47,12 @@ public: : line(0), col(0), len(0) {} Usage(const QString &path, int line, const QString &lineText, int col, int len) - : path(path), line(line), lineText(lineText), col(col), len(len) {} + : path(path), lineText(lineText), line(line), col(col), len(len) {} public: QString path; - int line; QString lineText; + int line; int col; int len; }; @@ -64,7 +64,10 @@ public: void setGlobalNamespaceBinding(NamespaceBindingPtr globalNamespaceBinding); - QList<int> operator()(Symbol *symbol, const Identifier *id, AST *ast); + void operator()(Symbol *symbol, const Identifier *id, AST *ast); + + QList<Usage> usages() const; + QList<int> references() const; protected: using ASTVisitor::visit; @@ -112,6 +115,7 @@ private: QList<PostfixExpressionAST *> _postfixExpressionStack; QList<QualifiedNameAST *> _qualifiedNameStack; QList<int> _references; + QList<Usage> _usages; LookupContext _previousContext; int _inSimpleDeclaration; QSet<unsigned> _processed; diff --git a/src/plugins/cpptools/cppfindreferences.cpp b/src/plugins/cpptools/cppfindreferences.cpp index 6a586c9dec86d6420d84459dbc99320e62df95c5..3a83089c4d594c568c74f297ec4930485b0e4a7b 100644 --- a/src/plugins/cpptools/cppfindreferences.cpp +++ b/src/plugins/cpptools/cppfindreferences.cpp @@ -91,9 +91,10 @@ QList<int> CppFindReferences::references(Symbol *symbol, TranslationUnit *translationUnit = doc->translationUnit(); Q_ASSERT(translationUnit != 0); - FindUsages process(doc, snapshot, /*future = */ 0); - process.setGlobalNamespaceBinding(bind(doc, snapshot)); - references = process(symbol, id, translationUnit->ast()); + FindUsages findUsages(doc, snapshot, /*future = */ 0); + findUsages.setGlobalNamespaceBinding(bind(doc, snapshot)); + findUsages(symbol, id, translationUnit->ast()); + references = findUsages.references(); return references; } @@ -229,7 +230,10 @@ void CppFindReferences::findAll_helper(Symbol *symbol) const QMap<QString, QString> wl = _modelManager->workingCopy(); Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager(); - QFuture<Usage> result = QtConcurrent::run(&find_helper, wl, snapshot, symbol); + + QFuture<Usage> result; + + result = QtConcurrent::run(&find_helper, wl, snapshot, symbol); m_watcher.setFuture(result); Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching..."),