CppTools: Move DependencyTable to Snapshot

It logically depends on the Snapshot and has a related lifetime.
Keeping it in the Snapshot avoids some code compelxity.

Change-Id: I24ee4483b44d9b0d7f2e4d494ae7ea624b949f9c
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
hjk
2014-09-11 13:15:44 +02:00
parent 0273757c93
commit 9a968b7417
13 changed files with 35 additions and 133 deletions

View File

@@ -187,7 +187,7 @@ void BuiltinEditorDocumentParser::update(WorkingCopy workingCopy)
newSnapshot.insert(i.value());
}
m_snapshot = newSnapshot;
m_deps.build(m_snapshot);
m_snapshot.updateDependencyTable();
emit finished(document(), m_snapshot);
}
@@ -197,7 +197,6 @@ void BuiltinEditorDocumentParser::releaseResources()
{
QMutexLocker locker(&m_mutex);
m_snapshot = Snapshot();
m_deps = DependencyTable();
m_forceSnapshotInvalidation = true;
}
@@ -237,7 +236,7 @@ void BuiltinEditorDocumentParser::addFileAndDependencies(QSet<QString> *toRemove
{
toRemove->insert(fileName);
if (fileName != filePath()) {
QStringList deps = m_deps.filesDependingOn(fileName);
QStringList deps = m_snapshot.filesDependingOn(fileName);
toRemove->unite(QSet<QString>::fromList(deps));
}
}

View File

@@ -35,7 +35,6 @@
#include "cppmodelmanager.h"
#include <cplusplus/CppDocument.h>
#include <cplusplus/DependencyTable.h>
#include <utils/qtcoverride.h>
#include <QMutex>
@@ -76,7 +75,6 @@ private:
QStringList m_precompiledHeaders;
CPlusPlus::Snapshot m_snapshot;
CPlusPlus::DependencyTable m_deps;
bool m_forceSnapshotInvalidation;
bool m_releaseSourceAndAST;
};

View File

@@ -250,7 +250,6 @@ CppFindReferences::CppFindReferences(CppModelManagerInterface *modelManager)
: QObject(modelManager),
m_modelManager(modelManager)
{
connect(modelManager, SIGNAL(globalSnapshotChanged()), this, SLOT(flushDependencyTable()));
}
CppFindReferences::~CppFindReferences()
@@ -271,7 +270,6 @@ QList<int> CppFindReferences::references(Symbol *symbol, const LookupContext &co
static void find_helper(QFutureInterface<Usage> &future,
const WorkingCopy workingCopy,
const LookupContext context,
CppFindReferences *findRefs,
Symbol *symbol)
{
const Identifier *symbolId = symbol->identifier();
@@ -297,8 +295,7 @@ static void find_helper(QFutureInterface<Usage> &future,
files.append(doc->fileName());
}
} else {
DependencyTable dependencyTable = findRefs->updateDependencyTable(snapshot);
files += dependencyTable.filesDependingOn(sourceFile);
files += snapshot.filesDependingOn(sourceFile);
}
files.removeDuplicates();
@@ -370,7 +367,7 @@ void CppFindReferences::findAll_helper(Core::SearchResult *search, CPlusPlus::Sy
Core::SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
const WorkingCopy workingCopy = m_modelManager->workingCopy();
QFuture<Usage> result;
result = QtConcurrent::run(&find_helper, workingCopy, context, this, symbol);
result = QtConcurrent::run(&find_helper, workingCopy, context, symbol);
createWatcher(result, search);
FutureProgress *progress = ProgressManager::addTask(result, tr("Searching for Usages"),
@@ -614,15 +611,11 @@ restart_search:
static void findMacroUses_helper(QFutureInterface<Usage> &future,
const WorkingCopy workingCopy,
const Snapshot snapshot,
CppFindReferences *findRefs,
const Macro macro)
{
// ensure the dependency table is updated
DependencyTable dependencies = findRefs->updateDependencyTable(snapshot);
const QString& sourceFile = macro.fileName();
QStringList files(sourceFile);
files += dependencies.filesDependingOn(sourceFile);
files += snapshot.filesDependingOn(sourceFile);
files.removeDuplicates();
future.setProgressRange(0, files.size());
@@ -677,7 +670,7 @@ void CppFindReferences::findMacroUses(const Macro &macro, const QString &replace
}
QFuture<Usage> result;
result = QtConcurrent::run(&findMacroUses_helper, workingCopy, snapshot, this, macro);
result = QtConcurrent::run(&findMacroUses_helper, workingCopy, snapshot, macro);
createWatcher(result, search);
FutureProgress *progress = ProgressManager::addTask(result, tr("Searching for Usages"),
@@ -691,39 +684,6 @@ void CppFindReferences::renameMacroUses(const Macro &macro, const QString &repla
findMacroUses(macro, textToReplace, true);
}
DependencyTable CppFindReferences::updateDependencyTable(CPlusPlus::Snapshot snapshot)
{
DependencyTable oldDeps = dependencyTable();
if (oldDeps.isValidFor(snapshot))
return oldDeps;
DependencyTable newDeps;
newDeps.build(snapshot);
setDependencyTable(newDeps);
return newDeps;
}
void CppFindReferences::flushDependencyTable()
{
QMutexLocker locker(&m_depsLock);
Q_UNUSED(locker);
m_deps = DependencyTable();
}
DependencyTable CppFindReferences::dependencyTable() const
{
QMutexLocker locker(&m_depsLock);
Q_UNUSED(locker);
return m_deps;
}
void CppFindReferences::setDependencyTable(const CPlusPlus::DependencyTable &newTable)
{
QMutexLocker locker(&m_depsLock);
Q_UNUSED(locker);
m_deps = newTable;
}
void CppFindReferences::createWatcher(const QFuture<Usage> &future, Core::SearchResult *search)
{
QFutureWatcher<Usage> *watcher = new QFutureWatcher<Usage>();

View File

@@ -30,7 +30,6 @@
#ifndef CPPFINDREFERENCES_H
#define CPPFINDREFERENCES_H
#include <cplusplus/DependencyTable.h>
#include <cplusplus/FindUsages.h>
#include <QMutex>
@@ -76,11 +75,6 @@ public:
void findMacroUses(const CPlusPlus::Macro &macro);
void renameMacroUses(const CPlusPlus::Macro &macro, const QString &replacement = QString());
CPlusPlus::DependencyTable updateDependencyTable(CPlusPlus::Snapshot snapshot);
public slots:
void flushDependencyTable();
private slots:
void displayResults(int first, int last);
void searchFinished();
@@ -97,8 +91,6 @@ private:
bool replace);
void findAll_helper(Core::SearchResult *search, CPlusPlus::Symbol *symbol,
const CPlusPlus::LookupContext &context);
CPlusPlus::DependencyTable dependencyTable() const;
void setDependencyTable(const CPlusPlus::DependencyTable &newTable);
void createWatcher(const QFuture<CPlusPlus::Usage> &future, Core::SearchResult *search);
CPlusPlus::Symbol *findSymbol(const CppFindReferencesParameters &parameters,
const CPlusPlus::Snapshot &snapshot, CPlusPlus::LookupContext *context);
@@ -106,9 +98,6 @@ private:
private:
QPointer<CppModelManagerInterface> m_modelManager;
QMap<QFutureWatcher<CPlusPlus::Usage> *, QPointer<Core::SearchResult> > m_watchers;
mutable QMutex m_depsLock;
CPlusPlus::DependencyTable m_deps;
};
} // namespace Internal

View File

@@ -222,10 +222,6 @@ CppModelManager::CppModelManager(QObject *parent)
, m_enableGC(true)
{
qRegisterMetaType<QSet<QString> >();
connect(this, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
this, SIGNAL(globalSnapshotChanged()));
connect(this, SIGNAL(aboutToRemoveFiles(QStringList)),
this, SIGNAL(globalSnapshotChanged()));
connect(this, SIGNAL(sourceFilesRefreshed(QSet<QString>)),
this, SLOT(onSourceFilesRefreshed()));
@@ -731,9 +727,7 @@ QList<ProjectPart::Ptr> CppModelManager::projectPart(const QString &fileName) co
QList<ProjectPart::Ptr> CppModelManager::projectPartFromDependencies(const QString &fileName) const
{
QSet<ProjectPart::Ptr> parts;
DependencyTable table;
table.build(snapshot());
const QStringList deps = table.filesDependingOn(fileName);
const QStringList deps = snapshot().filesDependingOn(fileName);
foreach (const QString &dep, deps)
parts.unite(QSet<ProjectPart::Ptr>::fromList(m_fileToProjectParts.value(dep)));

View File

@@ -139,8 +139,6 @@ signals:
/// Other classes can use this to get notified when the \c ProjectExplorer has updated the parts.
void projectPartsUpdated(ProjectExplorer::Project *project);
void globalSnapshotChanged();
public slots:
// Documented in source file.
virtual QFuture<void> updateSourceFiles(const QSet<QString> &sourceFiles,

View File

@@ -29,7 +29,6 @@
#include "typehierarchybuilder.h"
#include <cplusplus/DependencyTable.h>
#include <cplusplus/FindUsages.h>
using namespace CppTools;
@@ -143,9 +142,7 @@ const QList<TypeHierarchy> &TypeHierarchy::hierarchy() const
TypeHierarchyBuilder::TypeHierarchyBuilder(CPlusPlus::Symbol *symbol, const CPlusPlus::Snapshot &snapshot)
: _symbol(symbol)
, _snapshot(snapshot)
{
_dependencyTable.build(_snapshot);
}
{}
void TypeHierarchyBuilder::reset()
{
@@ -201,5 +198,5 @@ QStringList TypeHierarchyBuilder::filesDependingOn(CPlusPlus::Symbol *symbol) co
return QStringList();
const QString file = QString::fromUtf8(symbol->fileName(), symbol->fileNameLength());
return QStringList() << file << _dependencyTable.filesDependingOn(file);
return QStringList() << file << _snapshot.filesDependingOn(file);
}

View File

@@ -33,7 +33,6 @@
#include "cpptools_global.h"
#include "cppmodelmanagerinterface.h"
#include <cplusplus/DependencyTable.h>
#include <cplusplus/Overview.h>
#include <QList>
@@ -78,7 +77,6 @@ private:
QSet<CPlusPlus::Symbol *> _visited;
QHash<QString, QSet<QString> > _candidates;
CPlusPlus::Overview _overview;
CPlusPlus::DependencyTable _dependencyTable;
};
} // CppTools