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:
@@ -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<MacroArgumentReference>());
|
||||
}
|
||||
|
||||
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<MacroArgumentReference>());
|
||||
}
|
||||
|
||||
void FastPreprocessor::startExpandingMacro(unsigned offset, unsigned line,
|
||||
const Macro ¯o,
|
||||
const QVector<MacroArgumentReference> &actuals)
|
||||
{
|
||||
Q_ASSERT(_currentDoc);
|
||||
|
||||
_currentDoc->addMacroUse(revision(_snapshot, macro),
|
||||
offset, macro.name().length(), line, actuals);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user