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())
|
||||
|
||||
Reference in New Issue
Block a user