1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
37 #include <qmljs/parser/qmljsastvisitor_p.h>
38 #include <qmljs/qmljsinterpreter.h>
40 #include <QtCore/QHash>
41 #include <QtCore/QStringList>
42 #include <QtCore/QSharedPointer>
43 #include <QtCore/QCoreApplication>
50 class QMLJS_EXPORT Bind: protected AST::Visitor
53 Q_DECLARE_TR_FUNCTIONS(QmlJS::Bind)
56 Bind(Document *doc, QList<DiagnosticMessage> *messages);
59 QList<Interpreter::ImportInfo> imports() const;
61 Interpreter::ObjectValue *idEnvironment() const;
62 Interpreter::ObjectValue *rootObjectValue() const;
64 Interpreter::ObjectValue *findQmlObject(AST::Node *node) const;
65 bool usesQmlPrototype(Interpreter::ObjectValue *prototype,
66 const Interpreter::Context *context) const;
68 Interpreter::ObjectValue *findFunctionScope(AST::FunctionExpression *node) const;
69 bool isGroupedPropertyBinding(AST::Node *node) const;
71 static QString toString(AST::UiQualifiedId *qualifiedId, QChar delimiter = QChar('.'));
74 using AST::Visitor::visit;
76 void accept(AST::Node *node);
78 virtual bool visit(AST::UiProgram *ast);
79 virtual bool visit(AST::Program *ast);
82 virtual bool visit(AST::UiImport *ast);
83 virtual bool visit(AST::UiPublicMember *ast);
84 virtual bool visit(AST::UiObjectDefinition *ast);
85 virtual bool visit(AST::UiObjectBinding *ast);
86 virtual bool visit(AST::UiScriptBinding *ast);
87 virtual bool visit(AST::UiArrayBinding *ast);
90 virtual bool visit(AST::FunctionDeclaration *ast);
91 virtual bool visit(AST::FunctionExpression *ast);
92 virtual bool visit(AST::VariableDeclaration *ast);
94 Interpreter::ObjectValue *switchObjectValue(Interpreter::ObjectValue *newObjectValue);
95 Interpreter::ObjectValue *bindObject(AST::UiQualifiedId *qualifiedTypeNameId, AST::UiObjectInitializer *initializer);
99 Interpreter::Engine _engine;
101 Interpreter::ObjectValue *_currentObjectValue;
102 Interpreter::ObjectValue *_idEnvironment;
103 Interpreter::ObjectValue *_rootObjectValue;
105 QHash<AST::Node *, Interpreter::ObjectValue *> _qmlObjects;
106 QSet<AST::Node *> _groupedPropertyBindings;
107 QHash<AST::FunctionExpression *, Interpreter::ObjectValue *> _functionScopes;
108 QStringList _includedScripts;
110 QList<Interpreter::ImportInfo> _imports;
112 QList<DiagnosticMessage> *_diagnosticMessages;
115 } // end of namespace Qml