forked from qt-creator/qt-creator
C++: handle case-insensitive file names in the CPlusPlus::Snapshot
... by keying on Utils::FileName Task-number: QTCREATORBUG-12390 Change-Id: Ia98afb5a9160a7fd9225a2f9e02539ff3c35ae86 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
committed by
Erik Verbruggen
parent
a8ece5e9b0
commit
a48adcf9be
@@ -741,17 +741,17 @@ bool Snapshot::isEmpty() const
|
||||
return _documents.isEmpty();
|
||||
}
|
||||
|
||||
Snapshot::const_iterator Snapshot::find(const QString &fileName) const
|
||||
Snapshot::const_iterator Snapshot::find(const Utils::FileName &fileName) const
|
||||
{
|
||||
return _documents.find(fileName);
|
||||
}
|
||||
|
||||
void Snapshot::remove(const QString &fileName)
|
||||
void Snapshot::remove(const Utils::FileName &fileName)
|
||||
{
|
||||
_documents.remove(fileName);
|
||||
}
|
||||
|
||||
bool Snapshot::contains(const QString &fileName) const
|
||||
bool Snapshot::contains(const Utils::FileName &fileName) const
|
||||
{
|
||||
return _documents.contains(fileName);
|
||||
}
|
||||
@@ -759,15 +759,15 @@ bool Snapshot::contains(const QString &fileName) const
|
||||
void Snapshot::insert(Document::Ptr doc)
|
||||
{
|
||||
if (doc) {
|
||||
_documents.insert(doc->fileName(), doc);
|
||||
_documents.insert(Utils::FileName::fromString(doc->fileName()), doc);
|
||||
m_deps.files.clear(); // Will trigger re-build when accessed.
|
||||
}
|
||||
}
|
||||
|
||||
Document::Ptr Snapshot::preprocessedDocument(const QByteArray &source,
|
||||
const QString &fileName) const
|
||||
const Utils::FileName &fileName) const
|
||||
{
|
||||
Document::Ptr newDoc = Document::create(fileName);
|
||||
Document::Ptr newDoc = Document::create(fileName.toString());
|
||||
if (Document::Ptr thisDocument = document(fileName)) {
|
||||
newDoc->_revision = thisDocument->_revision;
|
||||
newDoc->_editorRevision = thisDocument->_editorRevision;
|
||||
@@ -821,7 +821,7 @@ QList<Snapshot::IncludeLocation> Snapshot::includeLocationsOfDocument(const QStr
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList Snapshot::filesDependingOn(const QString &fileName) const
|
||||
Utils::FileNameList Snapshot::filesDependingOn(const Utils::FileName &fileName) const
|
||||
{
|
||||
updateDependencyTable();
|
||||
return m_deps.filesDependingOn(fileName);
|
||||
@@ -850,7 +850,7 @@ void Snapshot::allIncludesForDocument_helper(const QString &fileName, QSet<QStri
|
||||
}
|
||||
}
|
||||
|
||||
Document::Ptr Snapshot::document(const QString &fileName) const
|
||||
Document::Ptr Snapshot::document(const Utils::FileName &fileName) const
|
||||
{
|
||||
return _documents.value(fileName);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#include <cplusplus/PreprocessorClient.h>
|
||||
#include <cplusplus/DependencyTable.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QSharedPointer>
|
||||
#include <QDateTime>
|
||||
#include <QHash>
|
||||
@@ -395,7 +397,7 @@ private:
|
||||
|
||||
class CPLUSPLUS_EXPORT Snapshot
|
||||
{
|
||||
typedef QHash<QString, Document::Ptr> Base;
|
||||
typedef QHash<Utils::FileName, Document::Ptr> Base;
|
||||
|
||||
public:
|
||||
Snapshot();
|
||||
@@ -409,20 +411,32 @@ public:
|
||||
bool isEmpty() const;
|
||||
|
||||
void insert(Document::Ptr doc); // ### remove
|
||||
void remove(const QString &fileName); // ### remove
|
||||
void remove(const Utils::FileName &fileName); // ### remove
|
||||
void remove(const QString &fileName)
|
||||
{ remove(Utils::FileName::fromString(fileName)); }
|
||||
|
||||
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;
|
||||
bool contains(const Utils::FileName &fileName) const;
|
||||
bool contains(const QString &fileName) const
|
||||
{ return contains(Utils::FileName::fromString(fileName)); }
|
||||
|
||||
const_iterator find(const QString &fileName) const;
|
||||
Document::Ptr document(const Utils::FileName &fileName) const;
|
||||
Document::Ptr document(const QString &fileName) const
|
||||
{ return document(Utils::FileName::fromString(fileName)); }
|
||||
|
||||
const_iterator find(const Utils::FileName &fileName) const;
|
||||
const_iterator find(const QString &fileName) const
|
||||
{ return find(Utils::FileName::fromString(fileName)); }
|
||||
|
||||
Snapshot simplified(Document::Ptr doc) const;
|
||||
|
||||
Document::Ptr preprocessedDocument(const QByteArray &source,
|
||||
const QString &fileName) const;
|
||||
const Utils::FileName &fileName) const;
|
||||
Document::Ptr preprocessedDocument(const QByteArray &source,
|
||||
const QString &fileName) const
|
||||
{ return preprocessedDocument(source, Utils::FileName::fromString(fileName)); }
|
||||
|
||||
Document::Ptr documentFromSource(const QByteArray &preprocessedDocument,
|
||||
const QString &fileName) const;
|
||||
@@ -430,7 +444,9 @@ public:
|
||||
QSet<QString> allIncludesForDocument(const QString &fileName) const;
|
||||
QList<IncludeLocation> includeLocationsOfDocument(const QString &fileName) const;
|
||||
|
||||
QStringList filesDependingOn(const QString &fileName) const;
|
||||
Utils::FileNameList filesDependingOn(const Utils::FileName &fileName) const;
|
||||
Utils::FileNameList filesDependingOn(const QString &fileName) const
|
||||
{ return filesDependingOn(Utils::FileName::fromString(fileName)); }
|
||||
void updateDependencyTable() const;
|
||||
|
||||
bool operator==(const Snapshot &other) const;
|
||||
|
||||
@@ -34,13 +34,14 @@
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
QStringList DependencyTable::filesDependingOn(const QString &fileName) const
|
||||
Utils::FileNameList DependencyTable::filesDependingOn(const Utils::FileName &fileName) const
|
||||
{
|
||||
Utils::FileNameList deps;
|
||||
|
||||
int index = fileIndex.value(fileName, -1);
|
||||
if (index == -1)
|
||||
return QStringList();
|
||||
return deps;
|
||||
|
||||
QStringList deps;
|
||||
for (int i = 0; i < files.size(); ++i) {
|
||||
const QBitArray &bits = includeMap.at(i);
|
||||
|
||||
@@ -53,7 +54,6 @@ QStringList DependencyTable::filesDependingOn(const QString &fileName) const
|
||||
|
||||
void DependencyTable::build(const Snapshot &snapshot)
|
||||
{
|
||||
includesPerFile.clear();
|
||||
files.clear();
|
||||
fileIndex.clear();
|
||||
includes.clear();
|
||||
@@ -71,15 +71,14 @@ void DependencyTable::build(const Snapshot &snapshot)
|
||||
}
|
||||
|
||||
for (int i = 0; i < files.size(); ++i) {
|
||||
const QString fileName = files.at(i);
|
||||
if (Document::Ptr doc = snapshot.document(files.at(i))) {
|
||||
const Utils::FileName &fileName = files.at(i);
|
||||
if (Document::Ptr doc = snapshot.document(fileName)) {
|
||||
QBitArray bitmap(files.size());
|
||||
QList<int> directIncludes;
|
||||
const QStringList documentIncludes = doc->includedFiles();
|
||||
includesPerFile.insert(fileName, documentIncludes);
|
||||
|
||||
foreach (const QString &includedFile, documentIncludes) {
|
||||
int index = fileIndex.value(includedFile);
|
||||
int index = fileIndex.value(Utils::FileName::fromString(includedFile));
|
||||
|
||||
if (index == -1)
|
||||
continue;
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
#include <cplusplus/CPlusPlusForwardDeclarations.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QBitArray>
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
@@ -48,11 +50,10 @@ class CPLUSPLUS_EXPORT DependencyTable
|
||||
private:
|
||||
friend class Snapshot;
|
||||
void build(const Snapshot &snapshot);
|
||||
QStringList filesDependingOn(const QString &fileName) const;
|
||||
Utils::FileNameList filesDependingOn(const Utils::FileName &fileName) const;
|
||||
|
||||
QHash<QString, QStringList> includesPerFile;
|
||||
QVector<QString> files;
|
||||
QHash<QString, int> fileIndex;
|
||||
QVector<Utils::FileName> files;
|
||||
QHash<Utils::FileName, int> fileIndex;
|
||||
QHash<int, QList<int> > includes;
|
||||
QVector<QBitArray> includeMap;
|
||||
};
|
||||
|
||||
@@ -53,8 +53,8 @@ QByteArray FastPreprocessor::run(Document::Ptr newDoc, const QByteArray &source)
|
||||
_merged.insert(fileName);
|
||||
|
||||
for (Snapshot::const_iterator i = _snapshot.begin(), ei = _snapshot.end(); i != ei; ++i) {
|
||||
if (isInjectedFile(i.key()))
|
||||
mergeEnvironment(i.key());
|
||||
if (isInjectedFile(i.key().toString()))
|
||||
mergeEnvironment(i.key().toString());
|
||||
}
|
||||
|
||||
foreach (const Document::Include &i, doc->resolvedIncludes())
|
||||
|
||||
Reference in New Issue
Block a user