forked from qt-creator/qt-creator
Initial work on the new CPlusPlus::Snapshot.
Encapsulate the details.
This commit is contained in:
@@ -606,7 +606,7 @@ protected:
|
||||
processed->insert(doc->fileName());
|
||||
|
||||
foreach (const Document::Include &i, doc->includes()) {
|
||||
if (Document::Ptr includedDoc = _snapshot.value(i.fileName())) {
|
||||
if (Document::Ptr includedDoc = _snapshot.document(i.fileName())) {
|
||||
/*NamepaceBinding *binding = */ bind(includedDoc, processed);
|
||||
}
|
||||
}
|
||||
|
@@ -440,10 +440,40 @@ Snapshot::~Snapshot()
|
||||
{
|
||||
}
|
||||
|
||||
int Snapshot::size() const
|
||||
{
|
||||
return _documents.size();
|
||||
}
|
||||
|
||||
bool Snapshot::isEmpty() const
|
||||
{
|
||||
return _documents.isEmpty();
|
||||
}
|
||||
|
||||
Document::Ptr Snapshot::operator[](const QString &fileName) const
|
||||
{
|
||||
return _documents.value(fileName, Document::Ptr());
|
||||
}
|
||||
|
||||
Snapshot::const_iterator Snapshot::find(const QString &fileName) const
|
||||
{
|
||||
return _documents.find(fileName);
|
||||
}
|
||||
|
||||
void Snapshot::remove(const QString &fileName)
|
||||
{
|
||||
_documents.remove(fileName);
|
||||
}
|
||||
|
||||
bool Snapshot::contains(const QString &fileName) const
|
||||
{
|
||||
return _documents.contains(fileName);
|
||||
}
|
||||
|
||||
void Snapshot::insert(Document::Ptr doc)
|
||||
{
|
||||
if (doc)
|
||||
insert(doc->fileName(), doc);
|
||||
_documents.insert(doc->fileName(), doc);
|
||||
}
|
||||
|
||||
QByteArray Snapshot::preprocessedCode(const QString &source, const QString &fileName) const
|
||||
@@ -457,7 +487,7 @@ Document::Ptr Snapshot::documentFromSource(const QByteArray &preprocessedCode,
|
||||
{
|
||||
Document::Ptr newDoc = Document::create(fileName);
|
||||
|
||||
if (Document::Ptr thisDocument = value(fileName)) {
|
||||
if (Document::Ptr thisDocument = document(fileName)) {
|
||||
newDoc->_revision = thisDocument->_revision;
|
||||
newDoc->_lastModified = thisDocument->_lastModified;
|
||||
newDoc->_includes = thisDocument->_includes;
|
||||
@@ -474,9 +504,9 @@ QSharedPointer<NamespaceBinding> Snapshot::globalNamespaceBinding(Document::Ptr
|
||||
return CPlusPlus::bind(doc, *this);
|
||||
}
|
||||
|
||||
Document::Ptr Snapshot::value(const QString &fileName) const
|
||||
Document::Ptr Snapshot::document(const QString &fileName) const
|
||||
{
|
||||
return QMap<QString, Document::Ptr>::value(QDir::cleanPath(fileName));
|
||||
return _documents.value(QDir::cleanPath(fileName));
|
||||
}
|
||||
|
||||
Snapshot Snapshot::simplified(Document::Ptr doc) const
|
||||
@@ -495,7 +525,7 @@ void Snapshot::simplified_helper(Document::Ptr doc, Snapshot *snapshot) const
|
||||
snapshot->insert(doc);
|
||||
|
||||
foreach (const Document::Include &incl, doc->includes()) {
|
||||
Document::Ptr includedDoc = value(incl.fileName());
|
||||
Document::Ptr includedDoc = document(incl.fileName());
|
||||
simplified_helper(includedDoc, snapshot);
|
||||
}
|
||||
}
|
||||
@@ -559,15 +589,14 @@ void Snapshot::dependency_helper(QVector<QString> &files,
|
||||
QHash<int, QList<int> > &includes,
|
||||
QVector<QBitArray> &includeMap) const
|
||||
{
|
||||
QMapIterator<QString, Document::Ptr> it(*this);
|
||||
for (int i = 0; it.hasNext(); ++i) {
|
||||
it.next();
|
||||
int i = 0;
|
||||
for (const_iterator it = begin(); it != end(); ++it, ++i) {
|
||||
files[i] = it.key();
|
||||
fileIndex[it.key()] = i;
|
||||
}
|
||||
|
||||
for (int i = 0; i < files.size(); ++i) {
|
||||
if (Document::Ptr doc = value(files.at(i))) {
|
||||
if (Document::Ptr doc = document(files.at(i))) {
|
||||
QBitArray bitmap(files.size());
|
||||
QList<int> directIncludes;
|
||||
|
||||
|
@@ -321,7 +321,7 @@ private:
|
||||
friend class Snapshot;
|
||||
};
|
||||
|
||||
class CPLUSPLUS_EXPORT Snapshot: public QMap<QString, Document::Ptr>
|
||||
class CPLUSPLUS_EXPORT Snapshot
|
||||
{
|
||||
typedef QMap<QString, Document::Ptr> _Base;
|
||||
|
||||
@@ -329,6 +329,24 @@ public:
|
||||
Snapshot();
|
||||
~Snapshot();
|
||||
|
||||
typedef _Base::const_iterator iterator;
|
||||
typedef _Base::const_iterator const_iterator;
|
||||
|
||||
int size() const; // ### remove
|
||||
bool isEmpty() const;
|
||||
|
||||
void insert(Document::Ptr doc); // ### remove
|
||||
void remove(const QString &fileName); // ### remove
|
||||
|
||||
const_iterator begin() const { return _documents.begin(); }
|
||||
const_iterator end() const { return _documents.end(); }
|
||||
|
||||
bool contains(const QString &fileName) const;
|
||||
Document::Ptr document(const QString &fileName) const;
|
||||
Document::Ptr operator[](const QString &fileName) const;
|
||||
|
||||
const_iterator find(const QString &fileName) const;
|
||||
|
||||
Snapshot simplified(Document::Ptr doc) const;
|
||||
|
||||
QByteArray preprocessedCode(const QString &source,
|
||||
@@ -342,17 +360,15 @@ public:
|
||||
QStringList filesDependingOn(const QString &fileName) const;
|
||||
QMap<QString, QStringList> dependencyTable() const;
|
||||
|
||||
void insert(Document::Ptr doc);
|
||||
Document::Ptr value(const QString &fileName) const;
|
||||
|
||||
using _Base::insert;
|
||||
|
||||
private:
|
||||
void simplified_helper(Document::Ptr doc, Snapshot *snapshot) const;
|
||||
void dependency_helper(QVector<QString> &files,
|
||||
QHash<QString, int> &fileIndex,
|
||||
QHash<int, QList<int> > &includes,
|
||||
QVector<QBitArray> &includeMap) const;
|
||||
|
||||
private:
|
||||
_Base _documents;
|
||||
};
|
||||
|
||||
} // end of namespace CPlusPlus
|
||||
|
@@ -43,7 +43,7 @@ QByteArray FastPreprocessor::run(QString fileName, const QString &source)
|
||||
{
|
||||
_preproc.setExpandMacros(false);
|
||||
|
||||
if (Document::Ptr doc = _snapshot.value(fileName)) {
|
||||
if (Document::Ptr doc = _snapshot.document(fileName)) {
|
||||
_merged.insert(fileName);
|
||||
|
||||
foreach (const Document::Include &i, doc->includes())
|
||||
@@ -62,7 +62,7 @@ void FastPreprocessor::mergeEnvironment(const QString &fileName)
|
||||
if (! _merged.contains(fileName)) {
|
||||
_merged.insert(fileName);
|
||||
|
||||
if (Document::Ptr doc = _snapshot.value(fileName)) {
|
||||
if (Document::Ptr doc = _snapshot.document(fileName)) {
|
||||
foreach (const Document::Include &i, doc->includes())
|
||||
mergeEnvironment(i.fileName());
|
||||
|
||||
|
@@ -89,7 +89,7 @@ Document::Ptr LookupContext::thisDocument() const
|
||||
{ return _thisDocument; }
|
||||
|
||||
Document::Ptr LookupContext::document(const QString &fileName) const
|
||||
{ return _snapshot.value(fileName); }
|
||||
{ return _snapshot.document(fileName); }
|
||||
|
||||
Snapshot LookupContext::snapshot() const
|
||||
{ return _snapshot; }
|
||||
@@ -317,7 +317,7 @@ void LookupContext::buildVisibleScopes_helper(Document::Ptr doc, QList<Scope *>
|
||||
scopes->append(doc->globalSymbols());
|
||||
|
||||
foreach (const Document::Include &incl, doc->includes()) {
|
||||
buildVisibleScopes_helper(_snapshot.value(incl.fileName()),
|
||||
buildVisibleScopes_helper(_snapshot.document(incl.fileName()),
|
||||
scopes, processed);
|
||||
}
|
||||
}
|
||||
|
@@ -123,7 +123,7 @@ void TypeOfExpression::processEnvironment(Snapshot documents,
|
||||
processed->insert(doc->fileName());
|
||||
foreach (const Document::Include &incl, doc->includes()) {
|
||||
processEnvironment(documents,
|
||||
documents.value(incl.fileName()),
|
||||
documents.document(incl.fileName()),
|
||||
env, processed);
|
||||
}
|
||||
foreach (const Macro ¯o, doc->definedMacros())
|
||||
|
@@ -1162,7 +1162,7 @@ void CPPEditor::switchDeclarationDefinition()
|
||||
|
||||
const Snapshot snapshot = m_modelManager->snapshot();
|
||||
|
||||
Document::Ptr doc = snapshot.value(file()->fileName());
|
||||
Document::Ptr doc = snapshot.document(file()->fileName());
|
||||
if (!doc)
|
||||
return;
|
||||
Symbol *lastSymbol = doc->findSymbolAt(line, column);
|
||||
@@ -1215,7 +1215,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
|
||||
const Snapshot snapshot = m_modelManager->snapshot();
|
||||
int line = 0, column = 0;
|
||||
convertPosition(cursor.position(), &line, &column);
|
||||
Document::Ptr doc = snapshot.value(file()->fileName());
|
||||
Document::Ptr doc = snapshot.document(file()->fileName());
|
||||
if (!doc)
|
||||
return link;
|
||||
|
||||
@@ -1391,7 +1391,7 @@ Symbol *CPPEditor::findDefinition(Symbol *symbol)
|
||||
it.next();
|
||||
|
||||
// get the instance of the document.
|
||||
Document::Ptr thisDocument = snapshot.value(it.key());
|
||||
Document::Ptr thisDocument = snapshot.document(it.key());
|
||||
|
||||
foreach (Function *f, it.value()) {
|
||||
// create a lookup context
|
||||
|
@@ -126,7 +126,7 @@ public:
|
||||
|
||||
void clear()
|
||||
{
|
||||
snapshot.clear();
|
||||
snapshot = CPlusPlus::Snapshot();
|
||||
fileName.clear();
|
||||
code.clear();
|
||||
line = 0;
|
||||
|
@@ -268,7 +268,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
|
||||
|
||||
const Snapshot documents = m_modelManager->snapshot();
|
||||
const QString fileName = editor->file()->fileName();
|
||||
Document::Ptr doc = documents.value(fileName);
|
||||
Document::Ptr doc = documents.document(fileName);
|
||||
if (!doc)
|
||||
return; // nothing to do
|
||||
|
||||
|
@@ -62,7 +62,7 @@ QString AbstractEditorSupport::functionAt(const CppModelManagerInterface *modelM
|
||||
int line, int column)
|
||||
{
|
||||
const CPlusPlus::Snapshot snapshot = modelManager->snapshot();
|
||||
const CPlusPlus::Document::Ptr document = snapshot.value(fileName);
|
||||
const CPlusPlus::Document::Ptr document = snapshot.document(fileName);
|
||||
if (!document)
|
||||
return QString();
|
||||
if (const CPlusPlus::Symbol *symbol = document->findSymbolAt(line, column))
|
||||
|
@@ -793,7 +793,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
||||
|
||||
const Snapshot snapshot = m_manager->snapshot();
|
||||
|
||||
if (Document::Ptr thisDocument = snapshot.value(fileName)) {
|
||||
if (Document::Ptr thisDocument = snapshot.document(fileName)) {
|
||||
Symbol *lastVisibleSymbol = thisDocument->findSymbolAt(line, column);
|
||||
typeOfExpression.setSnapshot(m_manager->snapshot());
|
||||
|
||||
|
@@ -74,7 +74,7 @@ QList<Locator::FilterEntry> CppCurrentDocumentFilter::matchesFor(const QString &
|
||||
|
||||
if (m_itemsOfCurrentDoc.isEmpty()) {
|
||||
Snapshot snapshot = m_modelManager->snapshot();
|
||||
Document::Ptr thisDocument = snapshot.value(m_currentFileName);
|
||||
Document::Ptr thisDocument = snapshot.document(m_currentFileName);
|
||||
if (thisDocument)
|
||||
m_itemsOfCurrentDoc = search(thisDocument);
|
||||
}
|
||||
|
@@ -110,7 +110,7 @@ public:
|
||||
QList<Usage> usages;
|
||||
const Identifier *symbolId = symbol->identifier();
|
||||
|
||||
if (Document::Ptr previousDoc = snapshot.value(fileName)) {
|
||||
if (Document::Ptr previousDoc = snapshot.document(fileName)) {
|
||||
Control *control = previousDoc->control();
|
||||
if (! control->findIdentifier(symbolId->chars(), symbolId->size()))
|
||||
return usages; // skip this document, it's not using symbolId.
|
||||
|
@@ -502,7 +502,7 @@ void CppPreprocessor::mergeEnvironment(Document::Ptr doc)
|
||||
foreach (const Document::Include &incl, doc->includes()) {
|
||||
QString includedFile = incl.fileName();
|
||||
|
||||
if (Document::Ptr includedDoc = snapshot.value(includedFile))
|
||||
if (Document::Ptr includedDoc = snapshot.document(includedFile))
|
||||
mergeEnvironment(includedDoc);
|
||||
else
|
||||
run(includedFile);
|
||||
@@ -553,7 +553,7 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type,
|
||||
|
||||
//qDebug() << "parse file:" << fileName << "contents:" << contents.size();
|
||||
|
||||
Document::Ptr doc = snapshot.value(fileName);
|
||||
Document::Ptr doc = snapshot.document(fileName);
|
||||
if (doc) {
|
||||
mergeEnvironment(doc);
|
||||
return;
|
||||
@@ -574,7 +574,7 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type,
|
||||
doc->tokenize();
|
||||
doc->releaseSource();
|
||||
|
||||
snapshot.insert(doc->fileName(), doc);
|
||||
snapshot.insert(doc);
|
||||
m_todo.remove(fileName);
|
||||
|
||||
Process process(m_modelManager, snapshot, m_workingCopy);
|
||||
@@ -955,7 +955,7 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
|
||||
|
||||
protectSnapshot.lock();
|
||||
|
||||
Document::Ptr previous = m_snapshot.value(fileName);
|
||||
Document::Ptr previous = m_snapshot.document(fileName);
|
||||
|
||||
if (previous && (doc->revision() != 0 && doc->revision() < previous->revision()))
|
||||
outdated = true;
|
||||
@@ -1351,7 +1351,7 @@ void CppModelManager::parse(QFutureInterface<void> &future,
|
||||
void CppModelManager::GC()
|
||||
{
|
||||
protectSnapshot.lock();
|
||||
Snapshot documents = m_snapshot;
|
||||
Snapshot currentSnapshot = m_snapshot;
|
||||
protectSnapshot.unlock();
|
||||
|
||||
QSet<QString> processed;
|
||||
@@ -1366,26 +1366,27 @@ void CppModelManager::GC()
|
||||
|
||||
processed.insert(fn);
|
||||
|
||||
if (Document::Ptr doc = documents.value(fn)) {
|
||||
if (Document::Ptr doc = currentSnapshot.document(fn)) {
|
||||
todo += doc->includedFiles();
|
||||
}
|
||||
}
|
||||
|
||||
QStringList removedFiles;
|
||||
QMutableMapIterator<QString, Document::Ptr> it(documents);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
const QString fn = it.key();
|
||||
if (! processed.contains(fn)) {
|
||||
removedFiles.append(fn);
|
||||
it.remove();
|
||||
}
|
||||
|
||||
Snapshot newSnapshot;
|
||||
for (Snapshot::const_iterator it = currentSnapshot.begin(); it != currentSnapshot.end(); ++it) {
|
||||
const QString fileName = it.key();
|
||||
|
||||
if (processed.contains(fileName))
|
||||
newSnapshot.insert(it.value());
|
||||
else
|
||||
removedFiles.append(fileName);
|
||||
}
|
||||
|
||||
emit aboutToRemoveFiles(removedFiles);
|
||||
|
||||
protectSnapshot.lock();
|
||||
m_snapshot = documents;
|
||||
m_snapshot = newSnapshot;
|
||||
protectSnapshot.unlock();
|
||||
}
|
||||
|
||||
|
@@ -619,7 +619,7 @@ const CPlusPlus::Snapshot &DebuggerManager::cppCodeModelSnapshot() const
|
||||
|
||||
void DebuggerManager::clearCppCodeModelSnapshot()
|
||||
{
|
||||
d->m_codeModelSnapshot.clear();
|
||||
d->m_codeModelSnapshot = CPlusPlus::Snapshot();
|
||||
}
|
||||
|
||||
SourceFilesWindow *DebuggerManager::sourceFileWindow() const
|
||||
@@ -1027,7 +1027,7 @@ void DebuggerManager::exitDebugger()
|
||||
// in turn will handle the cleanup.
|
||||
if (d->m_engine && state() != DebuggerNotReady)
|
||||
d->m_engine->exitDebugger();
|
||||
d->m_codeModelSnapshot.clear();
|
||||
d->m_codeModelSnapshot = CPlusPlus::Snapshot();
|
||||
}
|
||||
|
||||
DebuggerStartParametersPtr DebuggerManager::startParameters() const
|
||||
|
@@ -354,10 +354,10 @@ int getUninitializedVariablesI(const CPlusPlus::Snapshot &snapshot,
|
||||
{
|
||||
uninitializedVariables->clear();
|
||||
// Find document
|
||||
if (snapshot.empty() || functionName.isEmpty() || file.isEmpty() || line < 1)
|
||||
if (snapshot.isEmpty() || functionName.isEmpty() || file.isEmpty() || line < 1)
|
||||
return 1;
|
||||
const CPlusPlus::Snapshot::ConstIterator docIt = snapshot.constFind(file);
|
||||
if (docIt == snapshot.constEnd())
|
||||
const CPlusPlus::Snapshot::const_iterator docIt = snapshot.find(file);
|
||||
if (docIt == snapshot.end())
|
||||
return 2;
|
||||
const CPlusPlus::Document::Ptr doc = docIt.value();
|
||||
// Look at symbol at line and find its function. Either it is the
|
||||
@@ -416,7 +416,7 @@ bool getUninitializedVariables(const CPlusPlus::Snapshot &snapshot,
|
||||
<< " returns (int) " << rc << " '"
|
||||
<< uninitializedVariables->join(QString(QLatin1Char(','))) << '\'';
|
||||
if (rc)
|
||||
str << " of " << snapshot.keys().size() << " documents";
|
||||
str << " of " << snapshot.size() << " documents";
|
||||
qDebug() << msg;
|
||||
}
|
||||
return rc == 0;
|
||||
|
@@ -130,7 +130,7 @@ bool navigateToSlot(const QString &uiFileName,
|
||||
return false;
|
||||
}
|
||||
const CPlusPlus::Snapshot snapshot = CppTools::CppModelManagerInterface::instance()->snapshot();
|
||||
const DocumentPtr generatedHeaderDoc = snapshot.value(generatedHeaderFile);
|
||||
const DocumentPtr generatedHeaderDoc = snapshot.document(generatedHeaderFile);
|
||||
if (!generatedHeaderDoc) {
|
||||
*errorMessage = QCoreApplication::translate("Designer", "The generated header '%1' could not be found in the code model.\nRebuilding the project might help.").arg(generatedHeaderFile);
|
||||
return false;
|
||||
|
@@ -530,8 +530,8 @@ static ClassDocumentPtrPair
|
||||
// Check the includes
|
||||
const unsigned recursionMaxIncludeDepth = maxIncludeDepth - 1u;
|
||||
foreach (const QString &include, doc->includedFiles()) {
|
||||
const CPlusPlus::Snapshot::const_iterator it = docTable.constFind(include);
|
||||
if (it != docTable.constEnd()) {
|
||||
const CPlusPlus::Snapshot::const_iterator it = docTable.find(include);
|
||||
if (it != docTable.end()) {
|
||||
const Document::Ptr includeDoc = it.value();
|
||||
const ClassDocumentPtrPair irc = findClassRecursively(docTable, it.value(), className, recursionMaxIncludeDepth, namespaceName);
|
||||
if (irc.first)
|
||||
@@ -589,14 +589,16 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
|
||||
return false;
|
||||
}
|
||||
CPlusPlus::Snapshot docTable = cppModelManagerInstance()->snapshot();
|
||||
for (CPlusPlus::Snapshot::iterator it = docTable.begin(); it != docTable.end(); ) {
|
||||
CPlusPlus::Snapshot newDocTable;
|
||||
|
||||
for (CPlusPlus::Snapshot::iterator it = docTable.begin(); it != docTable.end(); ++it) {
|
||||
const ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projectForFile(it.key());
|
||||
if (project == uiProject) {
|
||||
++it;
|
||||
} else {
|
||||
it = docTable.erase(it);
|
||||
}
|
||||
if (project == uiProject)
|
||||
newDocTable.insert(it.value());
|
||||
}
|
||||
|
||||
docTable = newDocTable;
|
||||
|
||||
// take all docs, find the ones that include the ui_xx.h.
|
||||
QList<Document::Ptr> docList = findDocumentsIncluding(docTable, uicedName, true); // change to false when we know the absolute path to generated ui_<>.h file
|
||||
|
||||
|
Reference in New Issue
Block a user