Introduced CPlusPlus::Snapshot, it contains a snap shot of the indexer's current state.

This change removes a number of wrong usages of the CppModelManager::documents()/document().
This commit is contained in:
Roberto Raggi
2008-12-12 10:07:58 +01:00
parent ce66bc3c1e
commit bab60d14b3
13 changed files with 59 additions and 48 deletions

View File

@@ -427,7 +427,9 @@ void CPPEditor::switchDeclarationDefinition()
if (!m_modelManager)
return;
Document::Ptr doc = m_modelManager->document(file()->fileName());
const Snapshot snapshot = m_modelManager->snapshot();
Document::Ptr doc = snapshot.value(file()->fileName());
if (!doc)
return;
Symbol *lastSymbol = doc->findSymbolAt(line, column);
@@ -445,7 +447,7 @@ void CPPEditor::switchDeclarationDefinition()
if (f) {
TypeOfExpression typeOfExpression;
typeOfExpression.setDocuments(m_modelManager->documents());
typeOfExpression.setSnapshot(m_modelManager->snapshot());
QList<TypeOfExpression::Result> resolvedSymbols = typeOfExpression(QString(), doc, lastSymbol);
const LookupContext &context = typeOfExpression.lookupContext();
@@ -474,10 +476,12 @@ void CPPEditor::jumpToDefinition()
if (!m_modelManager)
return;
const Snapshot snapshot = m_modelManager->snapshot();
// Find the last symbol up to the cursor position
int line = 0, column = 0;
convertPosition(position(), &line, &column);
Document::Ptr doc = m_modelManager->document(file()->fileName());
Document::Ptr doc = snapshot.value(file()->fileName());
if (!doc)
return;
@@ -503,7 +507,7 @@ void CPPEditor::jumpToDefinition()
// Evaluate the type of the expression
TypeOfExpression typeOfExpression;
typeOfExpression.setDocuments(m_modelManager->documents());
typeOfExpression.setSnapshot(m_modelManager->snapshot());
QList<TypeOfExpression::Result> resolvedSymbols =
typeOfExpression(expression, doc, lastSymbol);
@@ -572,7 +576,7 @@ Symbol *CPPEditor::findDefinition(Symbol *lastSymbol)
QualifiedNameId *q = control.qualifiedNameId(&qualifiedName[0], qualifiedName.size());
LookupContext context(&control);
const QMap<QString, Document::Ptr> documents = m_modelManager->documents();
const Snapshot documents = m_modelManager->snapshot();
foreach (Document::Ptr doc, documents) {
QList<Scope *> visibleScopes;
visibleScopes.append(doc->globalSymbols());

View File

@@ -434,10 +434,12 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
//if (! expression.isEmpty())
//qDebug() << "***** expression:" << expression;
if (Document::Ptr thisDocument = m_manager->document(fileName)) {
const Snapshot snapshot = m_manager->snapshot();
if (Document::Ptr thisDocument = snapshot.value(fileName)) {
Symbol *symbol = thisDocument->findSymbolAt(line, column);
typeOfExpression.setDocuments(m_manager->documents());
typeOfExpression.setSnapshot(m_manager->snapshot());
QList<TypeOfExpression::Result> resolvedTypes = typeOfExpression(expression, thisDocument, symbol,
TypeOfExpression::Preprocess);
@@ -1034,7 +1036,7 @@ void CppCodeCompletion::cleanup()
// Set empty map in order to avoid referencing old versions of the documents
// until the next completion
typeOfExpression.setDocuments(QMap<QString, Document::Ptr>());
typeOfExpression.setSnapshot(Snapshot());
}
int CppCodeCompletion::findStartOfName(const TextEditor::ITextEditor *editor)

View File

@@ -165,9 +165,11 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
QTextCursor tc(edit->document());
tc.setPosition(pos);
const Snapshot documents = m_manager->snapshot();
const int lineNumber = tc.block().blockNumber() + 1;
const QString fileName = editor->file()->fileName();
Document::Ptr doc = m_manager->document(fileName);
Document::Ptr doc = documents.value(fileName);
if (doc) {
foreach (Document::DiagnosticMessage m, doc->diagnosticMessages()) {
if (m.line() == lineNumber) {
@@ -212,7 +214,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
Symbol *lastSymbol = doc->findSymbolAt(line, column);
TypeOfExpression typeOfExpression;
typeOfExpression.setDocuments(m_manager->documents());
typeOfExpression.setSnapshot(documents);
QList<TypeOfExpression::Result> types = typeOfExpression(expression, doc, lastSymbol);
if (!types.isEmpty()) {

View File

@@ -143,7 +143,7 @@ protected:
private:
QPointer<CppModelManager> m_modelManager;
CppModelManager::DocumentTable m_documents;
Snapshot m_snapshot;
Environment env;
pp m_proc;
QStringList m_includePaths;
@@ -160,7 +160,7 @@ private:
CppPreprocessor::CppPreprocessor(QPointer<CppModelManager> modelManager)
: m_modelManager(modelManager),
m_documents(modelManager->documents()),
m_snapshot(modelManager->snapshot()),
m_proc(this, env)
{ }
@@ -340,7 +340,7 @@ void CppPreprocessor::mergeEnvironment(Document::Ptr doc, QSet<QString> *process
processed->insert(fn);
foreach (QString includedFile, doc->includedFiles()) {
mergeEnvironment(m_documents.value(includedFile), processed);
mergeEnvironment(m_snapshot.value(includedFile), processed);
}
foreach (const Macro macro, doc->definedMacros()) {
@@ -386,7 +386,7 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type,
}
if (! contents.isEmpty()) {
Document::Ptr cachedDoc = m_documents.value(fileName);
Document::Ptr cachedDoc = m_snapshot.value(fileName);
if (cachedDoc && m_currentDoc) {
mergeEnvironment(cachedDoc);
} else {
@@ -477,11 +477,8 @@ CppModelManager::CppModelManager(QObject *parent) :
CppModelManager::~CppModelManager()
{ }
Document::Ptr CppModelManager::document(const QString &fileName) const
{ return m_documents.value(fileName); }
CppModelManager::DocumentTable CppModelManager::documents() const
{ return m_documents; }
Snapshot CppModelManager::snapshot() const
{ return m_snapshot; }
void CppModelManager::ensureUpdated()
{
@@ -672,7 +669,7 @@ void CppModelManager::emitDocumentUpdated(Document::Ptr doc)
void CppModelManager::onDocumentUpdated(Document::Ptr doc)
{
const QString fileName = doc->fileName();
m_documents[fileName] = doc;
m_snapshot[fileName] = doc;
QList<Core::IEditor *> openedEditors = m_core->editorManager()->openedEditors();
foreach (Core::IEditor *editor, openedEditors) {
if (editor->file()->fileName() == fileName) {
@@ -837,7 +834,7 @@ void CppModelManager::parse(QFutureInterface<void> &future,
void CppModelManager::GC()
{
DocumentTable documents = m_documents;
Snapshot documents = m_snapshot;
QSet<QString> processed;
QStringList todo = projectFiles();
@@ -868,7 +865,7 @@ void CppModelManager::GC()
}
emit aboutToRemoveFiles(removedFiles);
m_documents = documents;
m_snapshot = documents;
}

View File

@@ -76,8 +76,7 @@ public:
virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const;
virtual void updateProjectInfo(const ProjectInfo &pinfo);
virtual CPlusPlus::Document::Ptr document(const QString &fileName) const;
virtual DocumentTable documents() const;
virtual CPlusPlus::Snapshot snapshot() const;
virtual void GC();
QFuture<void> refreshSourceFiles(const QStringList &sourceFiles);
@@ -146,7 +145,7 @@ private:
Core::ICore *m_core;
ProjectExplorer::ProjectExplorerPlugin *m_projectExplorer;
CppHoverHandler *m_hoverHandler;
DocumentTable m_documents;
CPlusPlus::Snapshot m_snapshot;
// cache
bool m_dirty;

View File

@@ -46,14 +46,11 @@ namespace ProjectExplorer {
namespace CppTools {
class CPPTOOLS_EXPORT CppModelManagerInterface
: public QObject
class CPPTOOLS_EXPORT CppModelManagerInterface: public QObject
{
Q_OBJECT
public:
typedef QMap<QString, CPlusPlus::Document::Ptr> DocumentTable; // ### remove me
class ProjectInfo
{
public:
@@ -89,8 +86,7 @@ public:
virtual void GC() = 0;
virtual void updateSourceFiles(const QStringList &sourceFiles) = 0;
virtual CPlusPlus::Document::Ptr document(const QString &fileName) const = 0;
virtual DocumentTable documents() const = 0;
virtual CPlusPlus::Snapshot snapshot() const = 0;
virtual QList<ProjectInfo> projectInfos() const = 0;
virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const = 0;

View File

@@ -43,6 +43,7 @@
#include <QIcon>
#include <QMetaType>
#include <QString>
#include <QSet>
#include <functional>

View File

@@ -95,7 +95,7 @@ QList<Document::Ptr> WorkbenchIntegration::findDocuments(const QString &uiFileNa
QList<Document::Ptr> docList;
// take all docs
CppTools::CppModelManagerInterface::DocumentTable docTable = cppModelManager->documents();
CPlusPlus::Snapshot docTable = cppModelManager->snapshot();
foreach (Document::Ptr doc, docTable) { // we go through all documents
QStringList includes = doc->includedFiles();
foreach (QString include, includes) {
@@ -253,7 +253,7 @@ Document::Ptr WorkbenchIntegration::findDefinition(Function *functionDeclaration
QualifiedNameId *q = control.qualifiedNameId(&qualifiedName[0], qualifiedName.size());
LookupContext context(&control);
const QMap<QString, Document::Ptr> documents = cppModelManager->documents();
const Snapshot documents = cppModelManager->snapshot();
foreach (Document::Ptr doc, documents) {
QList<Scope *> visibleScopes;
visibleScopes.append(doc->globalSymbols());