From f3faef5a1e345b02dfca0b8c682e5e36e318849f Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 11 Oct 2012 16:16:01 +0200 Subject: 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 --- src/libs/cplusplus/FastPreprocessor.cpp | 67 +++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) (limited to 'src/libs/cplusplus/FastPreprocessor.cpp') diff --git a/src/libs/cplusplus/FastPreprocessor.cpp b/src/libs/cplusplus/FastPreprocessor.cpp index d94c99beda..b95ea7493f 100644 --- a/src/libs/cplusplus/FastPreprocessor.cpp +++ b/src/libs/cplusplus/FastPreprocessor.cpp @@ -39,8 +39,10 @@ FastPreprocessor::FastPreprocessor(const Snapshot &snapshot) _preproc(this, &_env) { } -QByteArray FastPreprocessor::run(QString fileName, const QString &source) +QByteArray FastPreprocessor::run(Document::Ptr newDoc, const QString &source) { + std::swap(newDoc, _currentDoc); + const QString fileName = _currentDoc->fileName(); _preproc.setExpandFunctionlikeMacros(false); _preproc.setKeepComments(true); @@ -54,11 +56,17 @@ QByteArray FastPreprocessor::run(QString fileName, const QString &source) const QByteArray preprocessed = _preproc.run(fileName, source); // qDebug("FastPreprocessor::run for %s produced [[%s]]", fileName.toUtf8().constData(), preprocessed.constData()); + std::swap(newDoc, _currentDoc); return preprocessed; } -void FastPreprocessor::sourceNeeded(unsigned, QString &fileName, IncludeType) -{ mergeEnvironment(fileName); } +void FastPreprocessor::sourceNeeded(unsigned line, QString &fileName, IncludeType) +{ + Q_ASSERT(_currentDoc); + _currentDoc->addIncludeFile(fileName, line); + + mergeEnvironment(fileName); +} void FastPreprocessor::mergeEnvironment(const QString &fileName) { @@ -73,3 +81,56 @@ void FastPreprocessor::mergeEnvironment(const QString &fileName) } } } + +void FastPreprocessor::macroAdded(const Macro ¯o) +{ + Q_ASSERT(_currentDoc); + + _currentDoc->appendMacro(macro); +} + +static const Macro revision(const Snapshot &s, const Macro &m) +{ + if (Document::Ptr d = s.document(m.fileName())) { + Macro newMacro(m); + newMacro.setFileRevision(d->revision()); + return newMacro; + } + + return m; +} + +void FastPreprocessor::passedMacroDefinitionCheck(unsigned offset, unsigned line, const Macro ¯o) +{ + Q_ASSERT(_currentDoc); + + _currentDoc->addMacroUse(revision(_snapshot, macro), + offset, macro.name().length(), line, + QVector()); +} + +void FastPreprocessor::failedMacroDefinitionCheck(unsigned offset, const ByteArrayRef &name) +{ + Q_ASSERT(_currentDoc); + + _currentDoc->addUndefinedMacroUse(QByteArray(name.start(), name.size()), offset); +} + +void FastPreprocessor::notifyMacroReference(unsigned offset, unsigned line, const Macro ¯o) +{ + Q_ASSERT(_currentDoc); + + _currentDoc->addMacroUse(revision(_snapshot, macro), + offset, macro.name().length(), line, + QVector()); +} + +void FastPreprocessor::startExpandingMacro(unsigned offset, unsigned line, + const Macro ¯o, + const QVector &actuals) +{ + Q_ASSERT(_currentDoc); + + _currentDoc->addMacroUse(revision(_snapshot, macro), + offset, macro.name().length(), line, actuals); +} -- cgit v1.2.1