Commit 57e5ba08 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Merge branch 'master' of git@scm.dev.nokia.troll.no:creator/mainline

parents 83e35eb9 1e7b4063
......@@ -40,9 +40,9 @@
#include <AST.h>
#include <Scope.h>
#include <QByteArray>
#include <QFile>
#include <QtDebug>
#include <QtCore/QByteArray>
#include <QtCore/QBitArray>
#include <QtCore/QtDebug>
using namespace CPlusPlus;
......@@ -419,3 +419,78 @@ void Snapshot::simplified_helper(Document::Ptr doc, Snapshot *snapshot) const
}
}
}
QStringList Snapshot::dependsOn(const QString &fileName) const
{
const int n = size();
QVector<QString> files(n);
QHash<QString, int> fileIndex;
QHash<int, QList<int> > includes;
QMapIterator<QString, Document::Ptr> it(*this);
for (int i = 0; it.hasNext(); ++i) {
it.next();
files[i] = it.key();
fileIndex[it.key()] = i;
}
int index = fileIndex.value(fileName, -1);
if (index == -1) {
qWarning() << fileName << "not in the snapshot";
return QStringList();
}
QVector<QBitArray> includeMap(files.size());
for (int i = 0; i < files.size(); ++i) {
if (Document::Ptr doc = value(files.at(i))) {
QBitArray bitmap(files.size());
QList<int> directIncludes;
foreach (const QString &includedFile, doc->includedFiles()) {
int index = fileIndex.value(includedFile);
if (index == -1)
continue;
else if (! directIncludes.contains(index))
directIncludes.append(index);
bitmap.setBit(index, true);
}
includeMap[i] = bitmap;
includes[i] = directIncludes;
}
}
bool changed;
do {
changed = false;
for (int i = 0; i < files.size(); ++i) {
QBitArray bitmap = includeMap.value(i);
QBitArray previousBitmap = bitmap;
foreach (int includedFileIndex, includes.value(i)) {
bitmap |= includeMap.value(includedFileIndex);
}
if (bitmap != previousBitmap) {
includeMap[i] = bitmap;
changed = true;
}
}
} 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;
}
......@@ -291,6 +291,8 @@ public:
QSharedPointer<NamespaceBinding> globalNamespaceBinding(Document::Ptr doc) const;
QStringList dependsOn(const QString &fileName) const;
void insert(Document::Ptr doc);
using _Base::insert;
......
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