summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus/FastPreprocessor.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2012-10-11 16:16:01 +0200
committerErik Verbruggen <erik.verbruggen@digia.com>2012-10-15 10:58:07 +0200
commitf3faef5a1e345b02dfca0b8c682e5e36e318849f (patch)
tree747ecc0a7a6b9d574ceff130767f386ee80b4a76 /src/libs/cplusplus/FastPreprocessor.cpp
parent199b243bca769049095b72bf5af7e95add1ecff6 (diff)
downloadqt-creator-f3faef5a1e345b02dfca0b8c682e5e36e318849f.tar.gz
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>
Diffstat (limited to 'src/libs/cplusplus/FastPreprocessor.cpp')
-rw-r--r--src/libs/cplusplus/FastPreprocessor.cpp67
1 files changed, 64 insertions, 3 deletions
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 &macro)
+{
+ 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 &macro)
+{
+ 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 &macro)
+{
+ Q_ASSERT(_currentDoc);
+
+ _currentDoc->addMacroUse(revision(_snapshot, macro),
+ offset, macro.name().length(), line,
+ QVector<MacroArgumentReference>());
+}
+
+void FastPreprocessor::startExpandingMacro(unsigned offset, unsigned line,
+ const Macro &macro,
+ const QVector<MacroArgumentReference> &actuals)
+{
+ Q_ASSERT(_currentDoc);
+
+ _currentDoc->addMacroUse(revision(_snapshot, macro),
+ offset, macro.name().length(), line, actuals);
+}