forked from qt-creator/qt-creator
C++: Fix outdated macro usage info in documents.
Record revisions of documents in macro definitions and usages. Then, when searching for usages, check the revision of the documents against the revision of the macros. If they are out-of-sync, repreprocess the documents to get up-to-date info. Task-number: QTCREATORBUG-7872 Change-Id: I846bb52ec660024728ab117a9fb7e43382a50e63 Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -128,14 +128,12 @@ public:
|
||||
return usages; // skip this document, it's not using symbolId.
|
||||
}
|
||||
Document::Ptr doc;
|
||||
QByteArray source;
|
||||
const QString unpreprocessedSource = getSource(fileName, workingCopy);
|
||||
|
||||
if (symbolDocument && fileName == symbolDocument->fileName()) {
|
||||
doc = symbolDocument;
|
||||
} else {
|
||||
source = snapshot.preprocessedCode(unpreprocessedSource, fileName);
|
||||
doc = snapshot.documentFromSource(source, fileName);
|
||||
doc = snapshot.preprocessedDocument(unpreprocessedSource, fileName);
|
||||
doc->tokenize();
|
||||
}
|
||||
|
||||
@@ -458,10 +456,8 @@ bool CppFindReferences::findSymbol(CppFindReferencesParameters *parameters,
|
||||
Document::Ptr newSymbolDocument = snapshot.document(symbolFile);
|
||||
// document is not parsed and has no bindings yet, do it
|
||||
QString source = getSource(newSymbolDocument->fileName(), _modelManager->workingCopy());
|
||||
const QByteArray &preprocessedCode =
|
||||
snapshot.preprocessedCode(source, newSymbolDocument->fileName());
|
||||
Document::Ptr doc =
|
||||
snapshot.documentFromSource(preprocessedCode, newSymbolDocument->fileName());
|
||||
snapshot.preprocessedDocument(source, newSymbolDocument->fileName());
|
||||
doc->check();
|
||||
|
||||
// construct id of old symbol
|
||||
@@ -563,19 +559,29 @@ public:
|
||||
QList<Usage> operator()(const QString &fileName)
|
||||
{
|
||||
QList<Usage> usages;
|
||||
Document::Ptr doc = snapshot.document(fileName);
|
||||
QString source;
|
||||
|
||||
_Lrestart:
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
if (future->isCanceled())
|
||||
return usages;
|
||||
|
||||
const Document::Ptr &doc = snapshot.document(fileName);
|
||||
QString source;
|
||||
|
||||
usages.clear();
|
||||
foreach (const Document::MacroUse &use, doc->macroUses()) {
|
||||
const Macro &useMacro = use.macro();
|
||||
if (useMacro.line() == macro.line()
|
||||
&& useMacro.fileName() == macro.fileName())
|
||||
{
|
||||
|
||||
if (useMacro.fileName() == macro.fileName()) { // Check if this is a match, but possibly against an outdated document.
|
||||
if (macro.fileRevision() > useMacro.fileRevision()) {
|
||||
// yes, it is outdated, so re-preprocess and start from scratch for this file.
|
||||
source = getSource(fileName, workingCopy).toLatin1();
|
||||
doc = snapshot.preprocessedDocument(source, fileName);
|
||||
goto _Lrestart;
|
||||
}
|
||||
}
|
||||
|
||||
if (useMacro.fileName() == macro.fileName() && macro.name() == useMacro.name()) {
|
||||
if (source.isEmpty())
|
||||
source = getSource(fileName, workingCopy);
|
||||
|
||||
@@ -625,7 +631,6 @@ static void findMacroUses_helper(QFutureInterface<Usage> &future,
|
||||
files.removeDuplicates();
|
||||
|
||||
future.setProgressRange(0, files.size());
|
||||
|
||||
FindMacroUsesInFile process(workingCopy, snapshot, macro, &future);
|
||||
UpdateUI reduce(&future);
|
||||
// This thread waits for blockingMappedReduced to finish, so reduce the pool's used thread count
|
||||
|
||||
@@ -498,12 +498,19 @@ void CppPreprocessor::macroAdded(const Macro ¯o)
|
||||
m_currentDoc->appendMacro(macro);
|
||||
}
|
||||
|
||||
static inline const Macro revision(const CppModelManagerInterface::WorkingCopy &s, const Macro ¯o)
|
||||
{
|
||||
Macro newMacro(macro);
|
||||
newMacro.setFileRevision(s.get(macro.fileName()).second);
|
||||
return newMacro;
|
||||
}
|
||||
|
||||
void CppPreprocessor::passedMacroDefinitionCheck(unsigned offset, unsigned line, const Macro ¯o)
|
||||
{
|
||||
if (! m_currentDoc)
|
||||
return;
|
||||
|
||||
m_currentDoc->addMacroUse(macro, offset, macro.name().length(), line,
|
||||
m_currentDoc->addMacroUse(revision(m_workingCopy, macro), offset, macro.name().length(), line,
|
||||
QVector<MacroArgumentReference>());
|
||||
}
|
||||
|
||||
@@ -520,7 +527,7 @@ void CppPreprocessor::notifyMacroReference(unsigned offset, unsigned line, const
|
||||
if (! m_currentDoc)
|
||||
return;
|
||||
|
||||
m_currentDoc->addMacroUse(macro, offset, macro.name().length(), line,
|
||||
m_currentDoc->addMacroUse(revision(m_workingCopy, macro), offset, macro.name().length(), line,
|
||||
QVector<MacroArgumentReference>());
|
||||
}
|
||||
|
||||
@@ -531,7 +538,7 @@ void CppPreprocessor::startExpandingMacro(unsigned offset, unsigned line,
|
||||
if (! m_currentDoc)
|
||||
return;
|
||||
|
||||
m_currentDoc->addMacroUse(macro, offset, macro.name().length(), line, actuals);
|
||||
m_currentDoc->addMacroUse(revision(m_workingCopy, macro), offset, macro.name().length(), line, actuals);
|
||||
}
|
||||
|
||||
void CppPreprocessor::stopExpandingMacro(unsigned, const Macro &)
|
||||
|
||||
@@ -156,8 +156,7 @@ Document::Ptr CppRefactoringFile::cppDocument() const
|
||||
const QString name = fileName();
|
||||
const Snapshot &snapshot = data()->m_snapshot;
|
||||
|
||||
const QByteArray contents = snapshot.preprocessedCode(source, name);
|
||||
m_cppDocument = snapshot.documentFromSource(contents, name);
|
||||
m_cppDocument = snapshot.preprocessedDocument(source, name);
|
||||
m_cppDocument->check();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user