summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppsnapshotupdater.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/cpptools/cppsnapshotupdater.cpp')
-rw-r--r--src/plugins/cpptools/cppsnapshotupdater.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/plugins/cpptools/cppsnapshotupdater.cpp b/src/plugins/cpptools/cppsnapshotupdater.cpp
index 473ec66b60..6d9a4d3a6f 100644
--- a/src/plugins/cpptools/cppsnapshotupdater.cpp
+++ b/src/plugins/cpptools/cppsnapshotupdater.cpp
@@ -39,6 +39,7 @@ using namespace CppTools::Internal;
SnapshotUpdater::SnapshotUpdater(const QString &fileInEditor)
: m_mutex(QMutex::Recursive)
, m_fileInEditor(fileInEditor)
+ , m_editorDefinesChangedSinceLastUpdate(false)
, m_usePrecompiledHeaders(false)
{
}
@@ -50,7 +51,7 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
if (m_fileInEditor.isEmpty())
return;
- bool invalidateSnapshot = false, invalidateConfig = false;
+ bool invalidateSnapshot = false, invalidateConfig = false, editorDefinesChanged = false;
CppModelManager *modelManager
= dynamic_cast<CppModelManager *>(CppModelManagerInterface::instance());
@@ -75,6 +76,12 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
invalidateConfig = true;
}
+ if (m_editorDefinesChangedSinceLastUpdate) {
+ invalidateSnapshot = true;
+ editorDefinesChanged = true;
+ m_editorDefinesChangedSinceLastUpdate = false;
+ }
+
if (includePaths != m_includePaths) {
m_includePaths = includePaths;
invalidateSnapshot = true;
@@ -131,6 +138,12 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
workingCopy.insert(configurationFileName, m_configFile);
m_snapshot.remove(m_fileInEditor);
+ static const QString editorDefinesFileName = QLatin1String("<per-editor-defines>");
+ if (editorDefinesChanged) {
+ m_snapshot.remove(editorDefinesFileName);
+ workingCopy.insert(editorDefinesFileName, m_editorDefines);
+ }
+
CppPreprocessor preproc(modelManager, m_snapshot);
Snapshot globalSnapshot = modelManager->snapshot();
globalSnapshot.remove(fileInEditor());
@@ -142,6 +155,8 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
if (m_usePrecompiledHeaders)
foreach (const QString &precompiledHeader, m_precompiledHeaders)
preproc.run(precompiledHeader);
+ if (!m_editorDefines.isEmpty())
+ preproc.run(editorDefinesFileName);
preproc.run(m_fileInEditor);
m_snapshot = preproc.snapshot();
@@ -178,6 +193,16 @@ void SnapshotUpdater::setUsePrecompiledHeaders(bool usePrecompiledHeaders)
m_usePrecompiledHeaders = usePrecompiledHeaders;
}
+void SnapshotUpdater::setEditorDefines(const QByteArray &editorDefines)
+{
+ QMutexLocker locker(&m_mutex);
+
+ if (editorDefines != m_editorDefines) {
+ m_editorDefines = editorDefines;
+ m_editorDefinesChangedSinceLastUpdate = true;
+ }
+}
+
void SnapshotUpdater::updateProjectPart()
{
CppModelManager *cmm = dynamic_cast<CppModelManager *>(CppModelManagerInterface::instance());