diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2013-09-30 14:37:50 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@digia.com> | 2013-10-01 13:03:47 +0200 |
commit | 8c79d5bc23e4b555625dfa368ca9f74e6d14540b (patch) | |
tree | 3941cb912ba455d01a31f7ff4746481d9999a2d4 /src/plugins/cpptools/cppsnapshotupdater.cpp | |
parent | 02072109bc46ca2a285b109521a14739eb2185ea (diff) | |
download | qt-creator-8c79d5bc23e4b555625dfa368ca9f74e6d14540b.tar.gz |
C++: add code-model support for defines-per-editor.
The UI side will come in another commit.
Change-Id: I1038a438587fe4cef70408f7f627d08837fc192d
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Diffstat (limited to 'src/plugins/cpptools/cppsnapshotupdater.cpp')
-rw-r--r-- | src/plugins/cpptools/cppsnapshotupdater.cpp | 27 |
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()); |