From 8c79d5bc23e4b555625dfa368ca9f74e6d14540b Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Mon, 30 Sep 2013 14:37:50 +0200 Subject: C++: add code-model support for defines-per-editor. The UI side will come in another commit. Change-Id: I1038a438587fe4cef70408f7f627d08837fc192d Reviewed-by: Nikolai Kosjar --- src/plugins/cpptools/cppsnapshotupdater.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/plugins/cpptools/cppsnapshotupdater.cpp') 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(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(""); + 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(CppModelManagerInterface::instance()); -- cgit v1.2.1