OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / libs / qmljs / qmljsbind.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef QMLBIND_H
35 #define QMLBIND_H
36
37 #include <qmljs/parser/qmljsastvisitor_p.h>
38 #include <qmljs/qmljsinterpreter.h>
39
40 #include <QtCore/QHash>
41 #include <QtCore/QStringList>
42 #include <QtCore/QSharedPointer>
43 #include <QtCore/QCoreApplication>
44
45 namespace QmlJS {
46
47 class Link;
48 class Document;
49
50 class QMLJS_EXPORT Bind: protected AST::Visitor
51 {
52     Q_DISABLE_COPY(Bind)
53     Q_DECLARE_TR_FUNCTIONS(QmlJS::Bind)
54
55 public:
56     Bind(Document *doc, QList<DiagnosticMessage> *messages);
57     virtual ~Bind();
58
59     QList<Interpreter::ImportInfo> imports() const;
60
61     Interpreter::ObjectValue *idEnvironment() const;
62     Interpreter::ObjectValue *rootObjectValue() const;
63
64     Interpreter::ObjectValue *findQmlObject(AST::Node *node) const;
65     bool usesQmlPrototype(Interpreter::ObjectValue *prototype,
66                           const Interpreter::Context *context) const;
67
68     Interpreter::ObjectValue *findFunctionScope(AST::FunctionExpression *node) const;
69     bool isGroupedPropertyBinding(AST::Node *node) const;
70
71     static QString toString(AST::UiQualifiedId *qualifiedId, QChar delimiter = QChar('.'));
72
73 protected:
74     using AST::Visitor::visit;
75
76     void accept(AST::Node *node);
77
78     virtual bool visit(AST::UiProgram *ast);
79     virtual bool visit(AST::Program *ast);
80
81     // Ui
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);
88
89     // QML/JS
90     virtual bool visit(AST::FunctionDeclaration *ast);
91     virtual bool visit(AST::FunctionExpression *ast);
92     virtual bool visit(AST::VariableDeclaration *ast);
93
94     Interpreter::ObjectValue *switchObjectValue(Interpreter::ObjectValue *newObjectValue);
95     Interpreter::ObjectValue *bindObject(AST::UiQualifiedId *qualifiedTypeNameId, AST::UiObjectInitializer *initializer);
96
97 private:
98     Document *_doc;
99     Interpreter::Engine _engine;
100
101     Interpreter::ObjectValue *_currentObjectValue;
102     Interpreter::ObjectValue *_idEnvironment;
103     Interpreter::ObjectValue *_rootObjectValue;
104
105     QHash<AST::Node *, Interpreter::ObjectValue *> _qmlObjects;
106     QSet<AST::Node *> _groupedPropertyBindings;
107     QHash<AST::FunctionExpression *, Interpreter::ObjectValue *> _functionScopes;
108     QStringList _includedScripts;
109
110     QList<Interpreter::ImportInfo> _imports;
111
112     QList<DiagnosticMessage> *_diagnosticMessages;
113 };
114
115 } // end of namespace Qml
116
117 #endif // QMLBIND_H