Commit 49416fe8 authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Add a path->document list hash to Snapshot.

Also change the filename->document map to a hash.

Reviewed-by: Roberto Raggi
parent cadd9a6a
......@@ -250,8 +250,10 @@ Snapshot::~Snapshot()
void Snapshot::insert(const Document::Ptr &document)
{
if (document && (document->qmlProgram() || document->jsProgram()))
if (document && (document->qmlProgram() || document->jsProgram())) {
_documents.insert(document->fileName(), document);
_documentsByPath.insert(document->path(), document);
}
}
void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
......
......@@ -131,9 +131,10 @@ public:
class QMLJS_EXPORT Snapshot
{
typedef QMap<QString, Document::Ptr> _Base;
QMap<QString, Document::Ptr> _documents;
QMap<QString, LibraryInfo> _libraries;
typedef QHash<QString, Document::Ptr> _Base;
QHash<QString, Document::Ptr> _documents;
QMultiHash<QString, Document::Ptr> _documentsByPath;
QHash<QString, LibraryInfo> _libraries;
public:
Snapshot();
......@@ -151,6 +152,9 @@ public:
Document::Ptr document(const QString &fileName) const
{ return _documents.value(fileName); }
QList<Document::Ptr> documentsInDirectory(const QString &path) const
{ return _documentsByPath.values(path); }
LibraryInfo libraryInfo(const QString &path) const
{ return _libraries.value(path); }
......
......@@ -21,8 +21,6 @@ Link::Link(Context *context, const Document::Ptr &doc, const Snapshot &snapshot,
, _context(context)
, _importPaths(importPaths)
{
foreach (Document::Ptr doc, snapshot)
_documentByPath.insert(doc->path(), doc);
linkImports();
}
......@@ -161,7 +159,7 @@ void Link::populateImportedTypes(Interpreter::ObjectValue *typeEnv, Document::Pt
// implicit imports:
// qml files in the same directory are available without explicit imports
foreach (Document::Ptr otherDoc, _documentByPath.values(doc->path())) {
foreach (Document::Ptr otherDoc, _snapshot.documentsInDirectory(doc->path())) {
if (otherDoc == doc)
continue;
......@@ -206,13 +204,14 @@ void Link::importFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc,
ObjectValue *importNamespace = typeEnv;
// directory import
if (_documentByPath.contains(path)) {
QList<Document::Ptr> documentsInDirectory = _snapshot.documentsInDirectory(path);
if (! documentsInDirectory.isEmpty()) {
if (import->importId) {
importNamespace = engine()->newObject(/*prototype =*/0);
typeEnv->setProperty(import->importId->asString(), importNamespace);
}
foreach (Document::Ptr importedDoc, _documentByPath.values(path)) {
foreach (Document::Ptr importedDoc, documentsInDirectory) {
const QString targetName = importedDoc->componentName();
importNamespace->setProperty(targetName, importedDoc->bind()->rootObjectValue());
}
......
......@@ -56,7 +56,6 @@ private:
Document::Ptr _doc;
Snapshot _snapshot;
Interpreter::Context *_context;
QMultiHash<QString, Document::Ptr> _documentByPath;
const QStringList _importPaths;
QList<DiagnosticMessage> _diagnosticMessages;
......
Supports Markdown
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