diff options
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(); |