Introduced revisions in CPlusPlus::Document.

Reviewed by Thorbjørn Lindeijer
This commit is contained in:
Roberto Raggi
2009-07-14 14:23:12 +02:00
parent 2e49aaf484
commit 37a146d05c
4 changed files with 40 additions and 3 deletions

View File

@@ -103,7 +103,8 @@ private:
Document::Document(const QString &fileName) Document::Document(const QString &fileName)
: _fileName(fileName), : _fileName(fileName),
_globalNamespace(0) _globalNamespace(0),
_revision(0)
{ {
_control = new Control(); _control = new Control();
@@ -130,6 +131,16 @@ Control *Document::control() const
return _control; return _control;
} }
unsigned Document::revision() const
{
return _revision;
}
void Document::setRevision(unsigned revision)
{
_revision = revision;
}
QString Document::fileName() const QString Document::fileName() const
{ {
return _fileName; return _fileName;

View File

@@ -60,6 +60,9 @@ public:
public: public:
~Document(); ~Document();
unsigned revision() const;
void setRevision(unsigned revision);
QString fileName() const; QString fileName() const;
QStringList includedFiles() const; QStringList includedFiles() const;
@@ -265,6 +268,7 @@ private:
QList<Block> _skippedBlocks; QList<Block> _skippedBlocks;
QList<MacroUse> _macroUses; QList<MacroUse> _macroUses;
QByteArray _source; QByteArray _source;
unsigned _revision;
friend class Snapshot; friend class Snapshot;
}; };

View File

@@ -174,6 +174,7 @@ public:
CppPreprocessor(QPointer<CppModelManager> modelManager); CppPreprocessor(QPointer<CppModelManager> modelManager);
virtual ~CppPreprocessor(); virtual ~CppPreprocessor();
void setRevision(unsigned revision);
void setWorkingCopy(const QMap<QString, QString> &workingCopy); void setWorkingCopy(const QMap<QString, QString> &workingCopy);
void setIncludePaths(const QStringList &includePaths); void setIncludePaths(const QStringList &includePaths);
void setFrameworkPaths(const QStringList &frameworkPaths); void setFrameworkPaths(const QStringList &frameworkPaths);
@@ -222,6 +223,7 @@ private:
Document::Ptr m_currentDoc; Document::Ptr m_currentDoc;
QSet<QString> m_todo; QSet<QString> m_todo;
QSet<QString> m_processed; QSet<QString> m_processed;
unsigned m_revision;
}; };
} // namespace Internal } // namespace Internal
@@ -230,12 +232,16 @@ private:
CppPreprocessor::CppPreprocessor(QPointer<CppModelManager> modelManager) CppPreprocessor::CppPreprocessor(QPointer<CppModelManager> modelManager)
: snapshot(modelManager->snapshot()), : snapshot(modelManager->snapshot()),
m_modelManager(modelManager), m_modelManager(modelManager),
preprocess(this, &env) preprocess(this, &env),
m_revision(0)
{ } { }
CppPreprocessor::~CppPreprocessor() CppPreprocessor::~CppPreprocessor()
{ } { }
void CppPreprocessor::setRevision(unsigned revision)
{ m_revision = revision; }
void CppPreprocessor::setWorkingCopy(const QMap<QString, QString> &workingCopy) void CppPreprocessor::setWorkingCopy(const QMap<QString, QString> &workingCopy)
{ m_workingCopy = workingCopy; } { m_workingCopy = workingCopy; }
@@ -537,6 +543,7 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type,
} }
doc = Document::create(fileName); doc = Document::create(fileName);
doc->setRevision(m_revision);
Document::Ptr previousDoc = switchDocument(doc); Document::Ptr previousDoc = switchDocument(doc);
@@ -577,6 +584,7 @@ Document::Ptr CppPreprocessor::switchDocument(Document::Ptr doc)
CppModelManager::CppModelManager(QObject *parent) CppModelManager::CppModelManager(QObject *parent)
: CppModelManagerInterface(parent) : CppModelManagerInterface(parent)
{ {
m_revision = 0;
m_synchronizer.setCancelOnWait(true); m_synchronizer.setCancelOnWait(true);
m_core = Core::ICore::instance(); // FIXME m_core = Core::ICore::instance(); // FIXME
@@ -762,6 +770,7 @@ QFuture<void> CppModelManager::refreshSourceFiles(const QStringList &sourceFiles
const QMap<QString, QString> workingCopy = buildWorkingCopyList(); const QMap<QString, QString> workingCopy = buildWorkingCopyList();
CppPreprocessor *preproc = new CppPreprocessor(this); CppPreprocessor *preproc = new CppPreprocessor(this);
preproc->setRevision(++m_revision);
preproc->setProjectFiles(projectFiles()); preproc->setProjectFiles(projectFiles());
preproc->setIncludePaths(includePaths()); preproc->setIncludePaths(includePaths());
preproc->setFrameworkPaths(frameworkPaths()); preproc->setFrameworkPaths(frameworkPaths());
@@ -839,10 +848,22 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
{ {
const QString fileName = doc->fileName(); const QString fileName = doc->fileName();
bool outdated = false;
protectSnapshot.lock(); protectSnapshot.lock();
m_snapshot.insert(doc);
Document::Ptr previous = m_snapshot.value(fileName);
if (previous && (doc->revision() != 0 && doc->revision() < previous->revision()))
outdated = true;
else
m_snapshot.insert(doc);
protectSnapshot.unlock(); protectSnapshot.unlock();
if (outdated)
return;
QList<Core::IEditor *> openedEditors = m_core->editorManager()->openedEditors(); QList<Core::IEditor *> openedEditors = m_core->editorManager()->openedEditors();
foreach (Core::IEditor *editor, openedEditors) { foreach (Core::IEditor *editor, openedEditors) {
if (editor->file()->fileName() == fileName) { if (editor->file()->fileName() == fileName) {

View File

@@ -189,6 +189,7 @@ private:
QTimer *m_updateEditorSelectionsTimer; QTimer *m_updateEditorSelectionsTimer;
QFutureSynchronizer<void> m_synchronizer; QFutureSynchronizer<void> m_synchronizer;
unsigned m_revision;
}; };
} // namespace Internal } // namespace Internal