diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2013-08-19 16:05:29 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@digia.com> | 2013-10-01 10:33:51 +0200 |
commit | ba2d7a4fa7c29ea2d62da3d6f6835a091f604656 (patch) | |
tree | 240f8484a13829478d3b7c586eec0598c45d0872 /src/plugins/cpptools/cpppreprocessor.cpp | |
parent | 447c4ed37f8904ca733d6e6253ad19bb0388f209 (diff) | |
download | qt-creator-ba2d7a4fa7c29ea2d62da3d6f6835a091f604656.tar.gz |
C++: Only parse with appropriate defines for open editors.
If two files from different (sub-)projects include the same header file,
and the defined macros differ for both files, the header file will be
parsed with only the appropriate macros for the including file.
Task-number: QTCREATORBUG-9802
Task-number: QTCREATORBUG-1249
Change-Id: I560490afa287b3bb1e863bce1bb4f57af36ad56e
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Diffstat (limited to 'src/plugins/cpptools/cpppreprocessor.cpp')
-rw-r--r-- | src/plugins/cpptools/cpppreprocessor.cpp | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/src/plugins/cpptools/cpppreprocessor.cpp b/src/plugins/cpptools/cpppreprocessor.cpp index 48cb7fc77c..1e3f5b1bf0 100644 --- a/src/plugins/cpptools/cpppreprocessor.cpp +++ b/src/plugins/cpptools/cpppreprocessor.cpp @@ -6,6 +6,7 @@ #include <utils/textfileformat.h> #include <QCoreApplication> +#include <QCryptographicHash> /*! * \class CppTools::Internal::CppPreprocessor @@ -34,6 +35,17 @@ CppPreprocessor::CppPreprocessor(QPointer<CppModelManager> modelManager, m_preprocess.setKeepComments(true); } +CppPreprocessor::CppPreprocessor(QPointer<CppModelManager> modelManager, const Snapshot &snapshot, + bool dumpFileNameWhileParsing) + : m_snapshot(snapshot), + m_modelManager(modelManager), + m_dumpFileNameWhileParsing(dumpFileNameWhileParsing), + m_preprocess(this, &m_env), + m_revision(0) +{ + m_preprocess.setKeepComments(true); +} + CppPreprocessor::~CppPreprocessor() { } @@ -129,10 +141,10 @@ public: { _doc->check(_mode); - if (_modelManager) + if (_modelManager) { _modelManager->emitDocumentUpdated(_doc); - - _doc->releaseSourceAndAST(); + _doc->releaseSourceAndAST(); + } } }; } // end of anonymous namespace @@ -398,7 +410,7 @@ void CppPreprocessor::sourceNeeded(unsigned line, const QString &fileName, Inclu if (m_dumpFileNameWhileParsing) { qDebug() << "Parsing file:" << absoluteFileName - << "contents:" << contents.size() + << "contents:" << contents.size() << "bytes"; ; } @@ -426,6 +438,33 @@ void CppPreprocessor::sourceNeeded(unsigned line, const QString &fileName, Inclu // b.constData()); // } + QCryptographicHash hash(QCryptographicHash::Sha1); + hash.addData(preprocessedCode); + foreach (const Macro ¯o, doc->definedMacros()) { + if (macro.isHidden()) { + static const QByteArray undef("#undef "); + hash.addData(undef); + hash.addData(macro.name()); + } else { + static const QByteArray def("#define "); + hash.addData(macro.name()); + hash.addData(" ", 1); + hash.addData(def); + hash.addData(macro.definitionText()); + } + hash.addData("\n", 1); + } + doc->setFingerprint(hash.result()); + + Document::Ptr anotherDoc = m_globalSnapshot.document(absoluteFileName); + if (anotherDoc && anotherDoc->fingerprint() == doc->fingerprint()) { + switchDocument(previousDoc); + mergeEnvironment(anotherDoc); + m_snapshot.insert(anotherDoc); + m_todo.remove(absoluteFileName); + return; + } + doc->setUtf8Source(preprocessedCode); doc->keepSourceAndAST(); doc->tokenize(); |