From b102690b006214ffda190080c4f004d45c3ac834 Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Tue, 2 Feb 2010 11:48:06 +0100 Subject: [PATCH] Bind the reachable documents. --- src/libs/qmljs/qmljsbind.cpp | 49 ++++++++++++++++++++++++++++++------ src/libs/qmljs/qmljsbind.h | 2 ++ 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/libs/qmljs/qmljsbind.cpp b/src/libs/qmljs/qmljsbind.cpp index bdc07490633..5557f6317a0 100644 --- a/src/libs/qmljs/qmljsbind.cpp +++ b/src/libs/qmljs/qmljsbind.cpp @@ -203,6 +203,11 @@ QStringList Bind::includedScripts() const return _includedScripts; } +QStringList Bind::localImports() const +{ + return _localImports; +} + ObjectValue *Bind::switchObjectValue(ObjectValue *newObjectValue) { ObjectValue *oldObjectValue = _currentObjectValue; @@ -216,13 +221,37 @@ ObjectValue *Bind::scopeChainAt(Document::Ptr currentDocument, const Snapshot &s Bind *currentBind = 0; QList<Bind *> binds; - Snapshot::const_iterator end = snapshot.end(); - for (Snapshot::const_iterator iter = snapshot.begin(); iter != end; ++iter) { - Document::Ptr doc = *iter; - Bind *newBind = new Bind(doc, snapshot, interp); - binds += newBind; - if (doc == currentDocument) - currentBind = newBind; + QSet<QString> processed; + QStringList todo; + + QMultiHash<QString, Document::Ptr> documentByPath; + foreach (Document::Ptr doc, snapshot) + documentByPath.insert(doc->path(), doc); + + todo.append(currentDocument->path()); + + // Bind the reachable documents. + while (! todo.isEmpty()) { + const QString path = todo.takeFirst(); + + if (processed.contains(path)) + continue; + + processed.insert(path); + + QStringList localImports; + foreach (Document::Ptr doc, documentByPath.values(path)) { + Bind *newBind = new Bind(doc, snapshot, interp); + binds += newBind; + + localImports += newBind->localImports(); + + if (doc == currentDocument) + currentBind = newBind; + } + + localImports.removeDuplicates(); + todo += localImports; } LinkImports linkImports; @@ -397,6 +426,12 @@ bool Bind::visit(UiImport *ast) namespaceObject->setProperty(object->qmlTypeName(), object); } #endif // NO_DECLARATIVE_BACKEND + } else if (ast->fileName) { + QString path = _doc->path(); + path += QLatin1Char('/'); + path += ast->fileName->asString(); + path = QDir::cleanPath(path); + _localImports.append(path); } return false; diff --git a/src/libs/qmljs/qmljsbind.h b/src/libs/qmljs/qmljsbind.h index ec6f1c38f8f..95dcbab1108 100644 --- a/src/libs/qmljs/qmljsbind.h +++ b/src/libs/qmljs/qmljsbind.h @@ -51,6 +51,7 @@ public: virtual ~Bind(); QStringList includedScripts() const; + QStringList localImports() const; // ### TODO: This methods should go. Bind each document after parsing, link later. static Interpreter::ObjectValue *scopeChainAt(Document::Ptr currentDocument, @@ -95,6 +96,7 @@ private: QHash<AST::UiObjectDefinition *, Interpreter::ObjectValue *> _qmlObjectDefinitions; QHash<AST::UiObjectBinding *, Interpreter::ObjectValue *> _qmlObjectBindings; QStringList _includedScripts; + QStringList _localImports; friend class LinkImports; friend class Link; -- GitLab