Commit 417a1c9f authored by Erik Verbruggen's avatar Erik Verbruggen

Fixed QTCREATORBUG-745.

Fixed crash in FindUsages on a dirty file in a large project, which is saved
while the FindUsages is still running.
parent e35a1e61
......@@ -465,24 +465,14 @@ bool FindUsages::visit(SimpleDeclarationAST *ast)
bool FindUsages::visit(ObjCSelectorAST *ast)
{
#if 1
const Identifier *id = ast->name->identifier();
if (id == _id) {
LookupContext context = currentContext(ast);
const QList<Symbol *> candidates = context.resolve(ast->name);
reportResult(ast->firstToken(), candidates);
}
#else
for (ObjCSelectorArgumentListAST *iter = ast->selector_argument_list; iter;
iter = iter->next) {
const Identifier *id = identifier(iter->value->name_token);
if (ast->name) {
const Identifier *id = ast->name->identifier();
if (id == _id) {
LookupContext context = currentContext(iter->value);
LookupContext context = currentContext(ast);
const QList<Symbol *> candidates = context.resolve(ast->name);
reportResult(iter->value->name_token, candidates);
reportResult(ast->firstToken(), candidates);
}
}
#endif
return false;
}
......@@ -903,7 +903,7 @@ const Macro *CPPEditor::findCanonicalMacro(const QTextCursor &cursor,
void CPPEditor::findUsages()
{
if (Symbol *canonicalSymbol = markSymbols()) {
m_modelManager->findUsages(canonicalSymbol);
m_modelManager->findUsages(m_lastSemanticInfo.doc, canonicalSymbol);
} else if (const Macro *macro = findCanonicalMacro(textCursor(), m_lastSemanticInfo.doc)) {
m_modelManager->findMacroUsages(*macro);
}
......@@ -954,7 +954,7 @@ void CPPEditor::renameUsagesNow()
this, SLOT(hideRenameNotification()));
}
m_modelManager->renameUsages(canonicalSymbol);
m_modelManager->renameUsages(m_lastSemanticInfo.doc, canonicalSymbol);
}
}
}
......
......@@ -85,13 +85,15 @@ class ProcessFile: public std::unary_function<QString, QList<Usage> >
{
const CppTools::CppModelManagerInterface::WorkingCopy workingCopy;
const Snapshot snapshot;
Document::Ptr symbolDocument;
Symbol *symbol;
public:
ProcessFile(const CppTools::CppModelManagerInterface::WorkingCopy &workingCopy,
const Snapshot snapshot,
Document::Ptr symbolDocument,
Symbol *symbol)
: workingCopy(workingCopy), snapshot(snapshot), symbol(symbol)
: workingCopy(workingCopy), snapshot(snapshot), symbolDocument(symbolDocument), symbol(symbol)
{ }
QList<Usage> operator()(const QString &fileName)
......@@ -175,6 +177,7 @@ QList<int> CppFindReferences::references(Symbol *symbol,
static void find_helper(QFutureInterface<Usage> &future,
const CppTools::CppModelManagerInterface::WorkingCopy workingCopy,
Snapshot snapshot,
Document::Ptr symbolDocument,
Symbol *symbol)
{
QTime tm;
......@@ -204,7 +207,7 @@ static void find_helper(QFutureInterface<Usage> &future,
future.setProgressRange(0, files.size());
ProcessFile process(workingCopy, snapshot, symbol);
ProcessFile process(workingCopy, snapshot, symbolDocument, symbol);
UpdateUI reduce(&future);
QtConcurrent::blockingMappedReduced<QList<Usage> > (files, process, reduce);
......@@ -212,17 +215,17 @@ static void find_helper(QFutureInterface<Usage> &future,
future.setProgressValue(files.size());
}
void CppFindReferences::findUsages(Symbol *symbol)
void CppFindReferences::findUsages(Document::Ptr symbolDocument, Symbol *symbol)
{
Find::SearchResult *search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchOnly);
connect(search, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem)));
findAll_helper(symbol);
findAll_helper(symbolDocument, symbol);
}
void CppFindReferences::renameUsages(Symbol *symbol)
void CppFindReferences::renameUsages(Document::Ptr symbolDocument, Symbol *symbol)
{
if (const Identifier *id = symbol->identifier()) {
const QString textToReplace = QString::fromUtf8(id->chars(), id->size());
......@@ -236,11 +239,11 @@ void CppFindReferences::renameUsages(Symbol *symbol)
connect(search, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
SLOT(onReplaceButtonClicked(QString,QList<Find::SearchResultItem>)));
findAll_helper(symbol);
findAll_helper(symbolDocument, symbol);
}
}
void CppFindReferences::findAll_helper(Symbol *symbol)
void CppFindReferences::findAll_helper(Document::Ptr symbolDocument, Symbol *symbol)
{
if (! (symbol && symbol->identifier()))
return;
......@@ -254,7 +257,7 @@ void CppFindReferences::findAll_helper(Symbol *symbol)
QFuture<Usage> result;
result = QtConcurrent::run(&find_helper, workingCopy, snapshot, symbol);
result = QtConcurrent::run(&find_helper, workingCopy, snapshot, symbolDocument, symbol);
m_watcher.setFuture(result);
Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching..."),
......
......@@ -64,8 +64,8 @@ Q_SIGNALS:
void changed();
public:
void findUsages(CPlusPlus::Symbol *symbol);
void renameUsages(CPlusPlus::Symbol *symbol);
void findUsages(CPlusPlus::Document::Ptr symbolDocument,CPlusPlus::Symbol *symbol);
void renameUsages(CPlusPlus::Document::Ptr symbolDocument,CPlusPlus::Symbol *symbol);
void findMacroUses(const CPlusPlus::Macro &macro);
......@@ -76,7 +76,7 @@ private Q_SLOTS:
void onReplaceButtonClicked(const QString &text, const QList<Find::SearchResultItem> &items);
private:
void findAll_helper(CPlusPlus::Symbol *symbol);
void findAll_helper(CPlusPlus::Document::Ptr symbolDocument, CPlusPlus::Symbol *symbol);
private:
QPointer<CppModelManagerInterface> _modelManager;
......
......@@ -733,16 +733,16 @@ QList<int> CppModelManager::references(CPlusPlus::Symbol *symbol,
return m_findReferences->references(LookupContext::canonicalSymbol(symbol, glo.data()), doc, snapshot);
}
void CppModelManager::findUsages(CPlusPlus::Symbol *symbol)
void CppModelManager::findUsages(CPlusPlus::Document::Ptr symbolDocument, CPlusPlus::Symbol *symbol)
{
if (symbol->identifier())
m_findReferences->findUsages(symbol);
m_findReferences->findUsages(symbolDocument, symbol);
}
void CppModelManager::renameUsages(CPlusPlus::Symbol *symbol)
void CppModelManager::renameUsages(CPlusPlus::Document::Ptr symbolDocument, CPlusPlus::Symbol *symbol)
{
if (symbol->identifier())
m_findReferences->renameUsages(symbol);
m_findReferences->renameUsages(symbolDocument, symbol);
}
void CppModelManager::findMacroUsages(const CPlusPlus::Macro &macro)
......
......@@ -120,8 +120,8 @@ public:
CPlusPlus::Document::Ptr doc,
const CPlusPlus::Snapshot &snapshot);
virtual void findUsages(CPlusPlus::Symbol *symbol);
virtual void renameUsages(CPlusPlus::Symbol *symbol);
virtual void findUsages(CPlusPlus::Document::Ptr symbolDocument, CPlusPlus::Symbol *symbol);
virtual void renameUsages(CPlusPlus::Document::Ptr symbolDocument, CPlusPlus::Symbol *symbol);
virtual void findMacroUsages(const CPlusPlus::Macro &macro);
......
......@@ -121,8 +121,8 @@ public:
CPlusPlus::Document::Ptr doc,
const CPlusPlus::Snapshot &snapshot) = 0;
virtual void renameUsages(CPlusPlus::Symbol *symbol) = 0;
virtual void findUsages(CPlusPlus::Symbol *symbol) = 0;
virtual void renameUsages(CPlusPlus::Document::Ptr symbolDocument, CPlusPlus::Symbol *symbol) = 0;
virtual void findUsages(CPlusPlus::Document::Ptr symbolDocument, CPlusPlus::Symbol *symbol) = 0;
virtual void findMacroUsages(const CPlusPlus::Macro &macro) = 0;
......
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