diff --git a/src/libs/qmljs/qmljsbind.cpp b/src/libs/qmljs/qmljsbind.cpp index b35b566474faef67c3c760b0aa658867c6588547..8c453d0c2cb97e7e6c4d24b1c9c53cf2b0b32573 100644 --- a/src/libs/qmljs/qmljsbind.cpp +++ b/src/libs/qmljs/qmljsbind.cpp @@ -31,6 +31,9 @@ #include "qmljsbind.h" #include "qmljslink.h" #include "qmljsmetatypesystem.h" + +#include <QtCore/QDir> +#include <QtCore/QFileInfo> #include <QtCore/QDebug> using namespace QmlJS; @@ -119,8 +122,9 @@ public: } // end of anonymous namespace -Bind::Bind(Document::Ptr doc, Interpreter::Engine *interp) +Bind::Bind(Document::Ptr doc, const Snapshot &snapshot, Interpreter::Engine *interp) : _doc(doc), + _snapshot(snapshot), _interp(interp), _currentObjectValue(0), _typeEnvironment(0), @@ -164,7 +168,7 @@ ObjectValue *Bind::scopeChainAt(Document::Ptr currentDocument, const Snapshot &s 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, interp); + Bind *newBind = new Bind(doc, snapshot, interp); binds += newBind; if (doc == currentDocument) currentBind = newBind; @@ -197,22 +201,64 @@ QString Bind::toString(UiQualifiedId *qualifiedId, QChar delimiter) return result; } +ExpressionNode *Bind::expression(UiScriptBinding *ast) const +{ + if (ExpressionStatement *statement = cast<ExpressionStatement *>(ast->statement)) + return statement->expression; + + return 0; +} + +void Bind::processScript(AST::UiQualifiedId *qualifiedId, AST::UiObjectInitializer *initializer) +{ + Q_UNUSED(qualifiedId); + + if (! initializer) + return; + + for (UiObjectMemberList *it = initializer->members; it; it = it->next) { + if (UiScriptBinding *binding = cast<UiScriptBinding *>(it->member)) { + const QString bindingName = toString(binding->qualifiedId); + if (bindingName == QLatin1String("source")) { + if (StringLiteral *literal = cast<StringLiteral *>(expression(binding))) { + QFileInfo fileInfo(QDir(_doc->path()), literal->value->asString()); + Document::Ptr script = _snapshot.document(fileInfo.absoluteFilePath()); + // ### process the script + } + } + } else if (UiSourceElement *binding = cast<UiSourceElement *>(it->member)) { + if (FunctionDeclaration *decl = cast<FunctionDeclaration *>(binding->sourceElement)) { + accept(decl); // process the function declaration + } else { + // ### unexpected source element + } + } else { + // ### unexpected binding. + } + } +} + ObjectValue *Bind::bindObject(UiQualifiedId *qualifiedTypeNameId, UiObjectInitializer *initializer) { - ObjectValue *parentObjectValue; + ObjectValue *parentObjectValue = 0; + const QString typeName = toString(qualifiedTypeNameId); - if (toString(qualifiedTypeNameId) == QLatin1String("Script")) { + if (typeName == QLatin1String("Script")) { // Script blocks all contribute to the same scope parentObjectValue = switchObjectValue(_functionEnvironment); - } else { // normal component instance - ASTObjectValue *objectValue = new ASTObjectValue(qualifiedTypeNameId, initializer, _interp); - parentObjectValue = switchObjectValue(objectValue); - if (parentObjectValue) - objectValue->setProperty("parent", parentObjectValue); - else - _rootObjectValue = objectValue; + processScript(qualifiedTypeNameId, initializer); + return switchObjectValue(parentObjectValue); } + // normal component instance + ASTObjectValue *objectValue = new ASTObjectValue(qualifiedTypeNameId, initializer, _interp); + parentObjectValue = switchObjectValue(objectValue); + + if (parentObjectValue) + objectValue->setProperty(QLatin1String("parent"), parentObjectValue); + else + _rootObjectValue = objectValue; + accept(initializer); return switchObjectValue(parentObjectValue); diff --git a/src/libs/qmljs/qmljsbind.h b/src/libs/qmljs/qmljsbind.h index b147a0b5112beccff5b73d87de5371abb6ab590a..a0196640e260181327fc13a008092e32ea2e804a 100644 --- a/src/libs/qmljs/qmljsbind.h +++ b/src/libs/qmljs/qmljsbind.h @@ -44,7 +44,7 @@ class Link; class QMLJS_EXPORT Bind: protected AST::Visitor { protected: - Bind(Document::Ptr doc, Interpreter::Engine *interp); + Bind(Document::Ptr doc, const Snapshot &snapshot, Interpreter::Engine *interp); public: virtual ~Bind(); @@ -58,7 +58,9 @@ public: protected: using AST::Visitor::visit; - QString toString(AST::UiQualifiedId *qualifiedId, QChar delimiter = QChar('.')); + static QString toString(AST::UiQualifiedId *qualifiedId, QChar delimiter = QChar('.')); + AST::ExpressionNode *expression(AST::UiScriptBinding *ast) const; + void processScript(AST::UiQualifiedId *qualifiedId, AST::UiObjectInitializer *initializer); void accept(AST::Node *node); @@ -78,6 +80,7 @@ protected: private: Document::Ptr _doc; + Snapshot _snapshot; Interpreter::Engine *_interp; Interpreter::ObjectValue *_currentObjectValue; diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp index d7498c3e8a32d8585a4693ccb06ed44fb7ec7f91..197faaf2db06f846e52596077b7972fa3b4c1b69 100644 --- a/src/libs/qmljs/qmljslink.cpp +++ b/src/libs/qmljs/qmljslink.cpp @@ -147,6 +147,8 @@ void LinkImports::operator()(const QList<Bind *> &binds) ObjectValue *Link::operator()(const QList<Bind *> &binds, Bind *currentBind, UiObjectMember *currentObject) { + Q_UNUSED(binds); + ObjectValue *scopeObject; if (UiObjectDefinition *definition = cast<UiObjectDefinition *>(currentObject)) scopeObject = currentBind->_qmlObjectDefinitions.value(definition);