Commit 13d2d499 authored by Erik Verbruggen's avatar Erik Verbruggen

C++: move post-sourceprocessing action into callback.

Change-Id: Iac6c9fe1ada27ac0d96417e490cc5723e6969541
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 528fa525
......@@ -84,7 +84,7 @@ static void parse(QFutureInterface<void> &future,
}
future.setProgressValue(files.size());
sourceProcessor->modelManager()->finishedRefreshingSourceFiles(files);
cmm->finishedRefreshingSourceFiles(files);
delete sourceProcessor;
}
......@@ -184,7 +184,8 @@ QFuture<void> BuiltinIndexingSupport::refreshSourceFiles(const QStringList &sour
CppModelManager *mgr = CppModelManager::instance();
const WorkingCopy workingCopy = mgr->workingCopy();
CppSourceProcessor *preproc = new CppSourceProcessor(mgr, m_dumpFileNameWhileParsing);
CppSourceProcessor *preproc = CppModelManager::createSourceProcessor();
preproc->setDumpFileNameWhileParsing(m_dumpFileNameWhileParsing);
preproc->setRevision(++m_revision);
preproc->setIncludePaths(mgr->includePaths());
preproc->setFrameworkPaths(mgr->frameworkPaths());
......
......@@ -160,6 +160,24 @@ QStringList CppModelManager::timeStampModifiedFiles(const QList<Document::Ptr> &
return sourceFiles;
}
/*!
* \brief createSourceProcessor Create a new source processor, which will signal the
* model manager when a document has been processed.
*
* Indexed file is truncated version of fully parsed document: copy of source
* code and full AST will be dropped when indexing is done.
*
* \return a new source processor object, which the caller needs to delete when finished.
*/
CppSourceProcessor *CppModelManager::createSourceProcessor()
{
CppModelManager *that = instance();
return new CppSourceProcessor(that->snapshot(), [=](const Document::Ptr &doc) {
that->emitDocumentUpdated(doc);
doc->releaseSourceAndAST();
});
}
void CppModelManager::updateModifiedSourceFiles()
{
const Snapshot snapshot = this->snapshot();
......
......@@ -49,6 +49,7 @@ class CppEditorSupport;
namespace Internal {
class CppFindReferences;
class CppSourceProcessor;
class CppModelManager : public CppTools::CppModelManagerInterface
{
......@@ -155,6 +156,8 @@ public:
static QStringList timeStampModifiedFiles(const QList<Document::Ptr> &documentsToCheck);
static CppSourceProcessor *createSourceProcessor();
signals:
void gcFinished(); // Needed for tests.
......
......@@ -159,7 +159,17 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
workingCopy.insert(editorDefinesFileName, m_editorDefines);
}
CppSourceProcessor sourceProcessor(modelManager, m_snapshot);
CppSourceProcessor sourceProcessor(m_snapshot, [&](const Document::Ptr &doc) {
const QString fileName = doc->fileName();
const bool isInEditor = fileName == fileInEditor();
Document::Ptr otherDoc = modelManager->document(fileName);
unsigned newRev = otherDoc.isNull() ? 1U : otherDoc->revision() + 1;
if (isInEditor)
newRev = qMax(rev + 1, newRev);
doc->setRevision(newRev);
modelManager->emitDocumentUpdated(doc);
doc->releaseSourceAndAST();
});
Snapshot globalSnapshot = modelManager->snapshot();
globalSnapshot.remove(fileInEditor());
sourceProcessor.setGlobalSnapshot(globalSnapshot);
......@@ -185,20 +195,6 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
}
m_snapshot = newSnapshot;
m_deps.build(m_snapshot);
foreach (Document::Ptr doc, m_snapshot) {
QString fileName = doc->fileName();
if (doc->revision() == 0) {
Document::Ptr otherDoc = globalSnapshot.document(fileName);
doc->setRevision(otherDoc.isNull() ? 0 : otherDoc->revision());
}
if (fileName != fileInEditor())
doc->releaseSourceAndAST();
}
QTC_CHECK(document());
if (Document::Ptr doc = document())
doc->setRevision(rev + 1);
}
}
......
......@@ -17,9 +17,8 @@
* \class CppTools::Internal::CppSourceProcessor
* \brief The CppSourceProcessor class updates set of indexed C++ files.
*
* Indexed file is truncated version of fully parsed document: copy of source
* code and full AST will be dropped when indexing is done. Working copy ensures
* that documents with most recent copy placed in memory will be parsed correctly.
* Working copy ensures that documents with most recent copy placed in memory will be parsed
* correctly.
*
* \sa CPlusPlus::Document
* \sa CppTools::CppModelManagerInterface::WorkingCopy
......@@ -79,24 +78,10 @@ inline const Macro revision(const CppModelManagerInterface::WorkingCopy &working
} // anonymous namespace
CppSourceProcessor::CppSourceProcessor(QPointer<CppModelManager> modelManager,
bool dumpFileNameWhileParsing)
: m_snapshot(modelManager->snapshot()),
m_modelManager(modelManager),
m_dumpFileNameWhileParsing(dumpFileNameWhileParsing),
m_preprocess(this, &m_env),
m_revision(0),
m_defaultCodec(Core::EditorManager::defaultTextCodec())
{
m_preprocess.setKeepComments(true);
}
CppSourceProcessor::CppSourceProcessor(QPointer<CppModelManager> modelManager,
const Snapshot &snapshot,
bool dumpFileNameWhileParsing)
CppSourceProcessor::CppSourceProcessor(const Snapshot &snapshot, DocumentCallback documentFinished)
: m_snapshot(snapshot),
m_modelManager(modelManager),
m_dumpFileNameWhileParsing(dumpFileNameWhileParsing),
m_documentFinished(documentFinished),
m_dumpFileNameWhileParsing(false),
m_preprocess(this, &m_env),
m_revision(0),
m_defaultCodec(Core::EditorManager::defaultTextCodec())
......@@ -417,7 +402,7 @@ void CppSourceProcessor::sourceNeeded(unsigned line, const QString &fileName, In
}
if (m_included.contains(absoluteFileName))
return; // We've already seen this file.
if (absoluteFileName != modelManager()->configurationFileName())
if (!isInjectedFile(absoluteFileName))
m_included.insert(absoluteFileName);
// Already in snapshot? Use it!
......@@ -470,10 +455,7 @@ void CppSourceProcessor::sourceNeeded(unsigned line, const QString &fileName, In
document->check(m_workingCopy.contains(document->fileName()) ? Document::FullCheck
: Document::FastCheck);
if (m_modelManager) {
m_modelManager->emitDocumentUpdated(document);
document->releaseSourceAndAST();
}
m_documentFinished(document);
m_snapshot.insert(document);
m_todo.remove(absoluteFileName);
......
......@@ -5,6 +5,7 @@
#include <cplusplus/PreprocessorEnvironment.h>
#include <cplusplus/pp-engine.h>
#include <utils/function.h>
#include <utils/qtcoverride.h>
#include <QHash>
......@@ -19,21 +20,23 @@ QT_END_NAMESPACE
namespace CppTools {
namespace Internal {
class CppModelManager;
// Documentation inside.
class CppSourceProcessor: public CPlusPlus::Client
{
Q_DISABLE_COPY(CppSourceProcessor)
public:
typedef std::function<void (const CPlusPlus::Document::Ptr &)> DocumentCallback;
public:
static QString cleanPath(const QString &path);
CppSourceProcessor(QPointer<CppModelManager> modelManager, bool dumpFileNameWhileParsing = false);
CppSourceProcessor(QPointer<CppModelManager> modelManager, const CPlusPlus::Snapshot &snapshot,
bool dumpFileNameWhileParsing = false);
CppSourceProcessor(const CPlusPlus::Snapshot &snapshot, DocumentCallback documentFinished);
~CppSourceProcessor();
void setDumpFileNameWhileParsing(bool onoff)
{ m_dumpFileNameWhileParsing = onoff; }
void setRevision(unsigned revision);
void setWorkingCopy(const CppTools::CppModelManagerInterface::WorkingCopy &workingCopy);
void setIncludePaths(const QStringList &includePaths);
......@@ -46,12 +49,10 @@ public:
CPlusPlus::Snapshot snapshot() const { return m_snapshot; }
const QSet<QString> &todo() const { return m_todo; }
CppModelManager *modelManager() const { return m_modelManager.data(); }
void setGlobalSnapshot(const CPlusPlus::Snapshot &snapshot) { m_globalSnapshot = snapshot; }
private:
CppSourceProcessor();
void addFrameworkPath(const QString &frameworkPath);
CPlusPlus::Document::Ptr switchCurrentDocument(CPlusPlus::Document::Ptr doc);
......@@ -84,7 +85,7 @@ private:
private:
CPlusPlus::Snapshot m_snapshot;
CPlusPlus::Snapshot m_globalSnapshot;
QPointer<CppModelManager> m_modelManager;
DocumentCallback m_documentFinished;
bool m_dumpFileNameWhileParsing;
CPlusPlus::Environment m_env;
CPlusPlus::Preprocessor m_preprocess;
......
......@@ -69,9 +69,10 @@ public:
if (!scopedFile.writtenSuccessfully())
return Document::Ptr();
CppSourceProcessor sourceProcessor((QPointer<CppModelManager>(m_cmm)));
sourceProcessor.setIncludePaths(QStringList(TestIncludePaths::directoryOfTestFile()));
sourceProcessor.run(fileName);
QScopedPointer<CppSourceProcessor> sourceProcessor(
CppModelManager::createSourceProcessor());
sourceProcessor->setIncludePaths(QStringList(TestIncludePaths::directoryOfTestFile()));
sourceProcessor->run(fileName);
Document::Ptr document = m_cmm->document(fileName);
return document;
......
......@@ -517,9 +517,9 @@ static QList<Include> includesForSource(const QByteArray &source)
using namespace CppTools::Internal;
CppModelManager *cmm = CppModelManager::instance();
cmm->GC();
CppSourceProcessor sourceProcessor((QPointer<CppModelManager>(cmm)));
sourceProcessor.setIncludePaths(QStringList(TestIncludePaths::globalIncludePath()));
sourceProcessor.run(fileName);
QScopedPointer<CppSourceProcessor> sourceProcessor(CppModelManager::createSourceProcessor());
sourceProcessor->setIncludePaths(QStringList(TestIncludePaths::globalIncludePath()));
sourceProcessor->run(fileName);
Document::Ptr document = cmm->document(fileName);
return document->resolvedIncludes();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment