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
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;
......@@ -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();
QVector<QString> files(n);
const int N = size();
QVector<QString> files(N);
QHash<QString, int> fileIndex;
QHash<int, QList<int> > includes;
QVector<QBitArray> includeMap(N);
QMapIterator<QString, Document::Ptr> it(*this);
for (int i = 0; it.hasNext(); ++i) {
it.next();
files[i] = it.key();
fileIndex[it.key()] = i;
}
dependency_helper(files, fileIndex, includes, includeMap);
int index = fileIndex.value(fileName, -1);
if (index == -1) {
......@@ -517,7 +517,54 @@ QStringList Snapshot::dependsOn(const QString &fileName) const
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) {
if (Document::Ptr doc = value(files.at(i))) {
......@@ -559,19 +606,4 @@ QStringList Snapshot::dependsOn(const QString &fileName) const
}
}
} 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 @@
#include <QFileInfo>
#include <QList>
#include <QMap>
#include <QBitArray>
#include <QSharedPointer>
#include <QString>
#include <QStringList>
......@@ -338,7 +339,8 @@ public:
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);
Document::Ptr value(const QString &fileName) const;
......@@ -347,6 +349,10 @@ public:
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;
};
} // end of namespace CPlusPlus
......
......@@ -124,7 +124,7 @@ static void find_helper(QFutureInterface<Usage> &future,
files.append(doc->fileName());
}
} else {
files += snapshot.dependsOn(sourceFile);
files += snapshot.filesDependingOn(sourceFile);
}
files.removeDuplicates();
//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