Commit 8741494f authored by Roberto Raggi's avatar Roberto Raggi

Rename dependsOn() in filesDepedingOn() and introduced Snapshot::dependencyTable().

parent b6bd021a
...@@ -474,6 +474,11 @@ QSharedPointer<NamespaceBinding> Snapshot::globalNamespaceBinding(Document::Ptr ...@@ -474,6 +474,11 @@ QSharedPointer<NamespaceBinding> Snapshot::globalNamespaceBinding(Document::Ptr
return CPlusPlus::bind(doc, *this); return CPlusPlus::bind(doc, *this);
} }
Document::Ptr Snapshot::value(const QString &fileName) const
{
return QMap<QString, Document::Ptr>::value(QDir::cleanPath(fileName));
}
Snapshot Snapshot::simplified(Document::Ptr doc) const Snapshot Snapshot::simplified(Document::Ptr doc) const
{ {
Snapshot snapshot; Snapshot snapshot;
...@@ -496,20 +501,15 @@ void Snapshot::simplified_helper(Document::Ptr doc, Snapshot *snapshot) const ...@@ -496,20 +501,15 @@ void Snapshot::simplified_helper(Document::Ptr doc, Snapshot *snapshot) const
} }
} }
QStringList Snapshot::dependsOn(const QString &fileName) const QStringList Snapshot::filesDependingOn(const QString &fileName) const
{ {
const int n = size(); const int N = size();
QVector<QString> files(N);
QVector<QString> files(n);
QHash<QString, int> fileIndex; QHash<QString, int> fileIndex;
QHash<int, QList<int> > includes; QHash<int, QList<int> > includes;
QVector<QBitArray> includeMap(N);
QMapIterator<QString, Document::Ptr> it(*this); dependency_helper(files, fileIndex, includes, includeMap);
for (int i = 0; it.hasNext(); ++i) {
it.next();
files[i] = it.key();
fileIndex[it.key()] = i;
}
int index = fileIndex.value(fileName, -1); int index = fileIndex.value(fileName, -1);
if (index == -1) { if (index == -1) {
...@@ -517,7 +517,54 @@ QStringList Snapshot::dependsOn(const QString &fileName) const ...@@ -517,7 +517,54 @@ QStringList Snapshot::dependsOn(const QString &fileName) const
return QStringList(); return QStringList();
} }
QVector<QBitArray> includeMap(files.size()); QStringList deps;
for (int i = 0; i < files.size(); ++i) {
const QBitArray &bits = includeMap.at(i);
if (bits.testBit(index))
deps.append(files.at(i));
}
return deps;
}
QMap<QString, QStringList> Snapshot::dependencyTable() const
{
const int N = size();
QVector<QString> files(N);
QHash<QString, int> fileIndex;
QHash<int, QList<int> > includes;
QVector<QBitArray> includeMap(N);
dependency_helper(files, fileIndex, includes, includeMap);
QMap<QString, QStringList> depMap;
for (int index = 0; index < files.size(); ++index) {
QStringList deps;
for (int i = 0; i < files.size(); ++i) {
const QBitArray &bits = includeMap.at(i);
if (bits.testBit(index))
deps.append(files.at(i));
}
depMap[files.at(index)] = deps;
}
return depMap;
}
void Snapshot::dependency_helper(QVector<QString> &files,
QHash<QString, int> &fileIndex,
QHash<int, QList<int> > &includes,
QVector<QBitArray> &includeMap) const
{
QMapIterator<QString, Document::Ptr> it(*this);
for (int i = 0; it.hasNext(); ++i) {
it.next();
files[i] = it.key();
fileIndex[it.key()] = i;
}
for (int i = 0; i < files.size(); ++i) { for (int i = 0; i < files.size(); ++i) {
if (Document::Ptr doc = value(files.at(i))) { if (Document::Ptr doc = value(files.at(i))) {
...@@ -559,19 +606,4 @@ QStringList Snapshot::dependsOn(const QString &fileName) const ...@@ -559,19 +606,4 @@ QStringList Snapshot::dependsOn(const QString &fileName) const
} }
} }
} while (changed); } while (changed);
QStringList deps;
for (int i = 0; i < files.size(); ++i) {
const QBitArray &bits = includeMap.at(i);
if (bits.testBit(index))
deps.append(files.at(i));
}
return deps;
}
Document::Ptr Snapshot::value(const QString &fileName) const
{
return QMap<QString, Document::Ptr>::value(QDir::cleanPath(fileName));
} }
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QList> #include <QList>
#include <QMap> #include <QMap>
#include <QBitArray>
#include <QSharedPointer> #include <QSharedPointer>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
...@@ -338,7 +339,8 @@ public: ...@@ -338,7 +339,8 @@ public:
QSharedPointer<NamespaceBinding> globalNamespaceBinding(Document::Ptr doc) const; QSharedPointer<NamespaceBinding> globalNamespaceBinding(Document::Ptr doc) const;
QStringList dependsOn(const QString &fileName) const; QStringList filesDependingOn(const QString &fileName) const;
QMap<QString, QStringList> dependencyTable() const;
void insert(Document::Ptr doc); void insert(Document::Ptr doc);
Document::Ptr value(const QString &fileName) const; Document::Ptr value(const QString &fileName) const;
...@@ -347,6 +349,10 @@ public: ...@@ -347,6 +349,10 @@ public:
private: private:
void simplified_helper(Document::Ptr doc, Snapshot *snapshot) const; 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;
}; };
} // end of namespace CPlusPlus } // end of namespace CPlusPlus
......
...@@ -124,7 +124,7 @@ static void find_helper(QFutureInterface<Usage> &future, ...@@ -124,7 +124,7 @@ static void find_helper(QFutureInterface<Usage> &future,
files.append(doc->fileName()); files.append(doc->fileName());
} }
} else { } else {
files += snapshot.dependsOn(sourceFile); files += snapshot.filesDependingOn(sourceFile);
} }
files.removeDuplicates(); files.removeDuplicates();
//qDebug() << "done in:" << tm.elapsed() << "number of files to parse:" << files.size(); //qDebug() << "done in:" << tm.elapsed() << "number of files to parse:" << files.size();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment