1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
36 #include <qmljs/parser/qmljsastvisitor_p.h>
37 #include <qmljs/qmljsinterpreter.h>
39 #include <QtCore/QHash>
40 #include <QtCore/QStringList>
41 #include <QtCore/QSharedPointer>
42 #include <QtCore/QCoreApplication>
49 class QMLJS_EXPORT Bind: protected AST::Visitor
52 Q_DECLARE_TR_FUNCTIONS(QmlJS::Bind)
55 Bind(Document *doc, QList<DiagnosticMessage> *messages);
58 QList<Interpreter::ImportInfo> imports() const;
60 Interpreter::ObjectValue *idEnvironment() const;
61 Interpreter::ObjectValue *rootObjectValue() const;
63 Interpreter::ObjectValue *findQmlObject(AST::Node *node) const;
64 bool usesQmlPrototype(Interpreter::ObjectValue *prototype,
65 const Interpreter::Context *context) const;
67 Interpreter::ObjectValue *findFunctionScope(AST::FunctionExpression *node) const;
68 bool isGroupedPropertyBinding(AST::Node *node) const;
70 static QString toString(AST::UiQualifiedId *qualifiedId, QChar delimiter = QChar('.'));
73 using AST::Visitor::visit;
75 void accept(AST::Node *node);
77 virtual bool visit(AST::UiProgram *ast);
78 virtual bool visit(AST::Program *ast);
81 virtual bool visit(AST::UiImport *ast);
82 virtual bool visit(AST::UiPublicMember *ast);
83 virtual bool visit(AST::UiObjectDefinition *ast);
84 virtual bool visit(AST::UiObjectBinding *ast);
85 virtual bool visit(AST::UiScriptBinding *ast);
86 virtual bool visit(AST::UiArrayBinding *ast);
89 virtual bool visit(AST::FunctionDeclaration *ast);
90 virtual bool visit(AST::FunctionExpression *ast);
91 virtual bool visit(AST::VariableDeclaration *ast);
93 Interpreter::ObjectValue *switchObjectValue(Interpreter::ObjectValue *newObjectValue);
94 Interpreter::ObjectValue *bindObject(AST::UiQualifiedId *qualifiedTypeNameId, AST::UiObjectInitializer *initializer);
98 Interpreter::Engine _engine;
100 Interpreter::ObjectValue *_currentObjectValue;
101 Interpreter::ObjectValue *_idEnvironment;
102 Interpreter::ObjectValue *_rootObjectValue;
104 QHash<AST::Node *, Interpreter::ObjectValue *> _qmlObjects;
105 QSet<AST::Node *> _groupedPropertyBindings;
106 QHash<AST::FunctionExpression *, Interpreter::ObjectValue *> _functionScopes;
107 QStringList _includedScripts;
109 QList<Interpreter::ImportInfo> _imports;
111 QList<DiagnosticMessage> *_diagnosticMessages;