1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
6 | **
|
---|
7 | ** This file is part of the QtDeclarative module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 |
|
---|
43 | //
|
---|
44 | // W A R N I N G
|
---|
45 | // -------------
|
---|
46 | //
|
---|
47 | // This file is not part of the Qt API. It exists purely as an
|
---|
48 | // implementation detail. This header file may change from version to
|
---|
49 | // version without notice, or even be removed.
|
---|
50 | //
|
---|
51 | // We mean it.
|
---|
52 | //
|
---|
53 |
|
---|
54 | //
|
---|
55 | // This file is automatically generated from qmljs.g.
|
---|
56 | // Changes will be lost.
|
---|
57 | //
|
---|
58 |
|
---|
59 | #ifndef QDECLARATIVEJSPARSER_P_H
|
---|
60 | #define QDECLARATIVEJSPARSER_P_H
|
---|
61 |
|
---|
62 | #include "private/qdeclarativejsglobal_p.h"
|
---|
63 | #include "private/qdeclarativejsgrammar_p.h"
|
---|
64 | #include "private/qdeclarativejsast_p.h"
|
---|
65 | #include "private/qdeclarativejsengine_p.h"
|
---|
66 |
|
---|
67 | #include <QtCore/QList>
|
---|
68 | #include <QtCore/QString>
|
---|
69 |
|
---|
70 | QT_QML_BEGIN_NAMESPACE
|
---|
71 |
|
---|
72 | namespace QDeclarativeJS {
|
---|
73 |
|
---|
74 | class Engine;
|
---|
75 | class NameId;
|
---|
76 |
|
---|
77 | class QML_PARSER_EXPORT Parser: protected QDeclarativeJSGrammar
|
---|
78 | {
|
---|
79 | public:
|
---|
80 | union Value {
|
---|
81 | int ival;
|
---|
82 | double dval;
|
---|
83 | NameId *sval;
|
---|
84 | AST::ArgumentList *ArgumentList;
|
---|
85 | AST::CaseBlock *CaseBlock;
|
---|
86 | AST::CaseClause *CaseClause;
|
---|
87 | AST::CaseClauses *CaseClauses;
|
---|
88 | AST::Catch *Catch;
|
---|
89 | AST::DefaultClause *DefaultClause;
|
---|
90 | AST::ElementList *ElementList;
|
---|
91 | AST::Elision *Elision;
|
---|
92 | AST::ExpressionNode *Expression;
|
---|
93 | AST::Finally *Finally;
|
---|
94 | AST::FormalParameterList *FormalParameterList;
|
---|
95 | AST::FunctionBody *FunctionBody;
|
---|
96 | AST::FunctionDeclaration *FunctionDeclaration;
|
---|
97 | AST::Node *Node;
|
---|
98 | AST::PropertyName *PropertyName;
|
---|
99 | AST::PropertyNameAndValueList *PropertyNameAndValueList;
|
---|
100 | AST::SourceElement *SourceElement;
|
---|
101 | AST::SourceElements *SourceElements;
|
---|
102 | AST::Statement *Statement;
|
---|
103 | AST::StatementList *StatementList;
|
---|
104 | AST::Block *Block;
|
---|
105 | AST::VariableDeclaration *VariableDeclaration;
|
---|
106 | AST::VariableDeclarationList *VariableDeclarationList;
|
---|
107 |
|
---|
108 | AST::UiProgram *UiProgram;
|
---|
109 | AST::UiImportList *UiImportList;
|
---|
110 | AST::UiImport *UiImport;
|
---|
111 | AST::UiParameterList *UiParameterList;
|
---|
112 | AST::UiPublicMember *UiPublicMember;
|
---|
113 | AST::UiObjectDefinition *UiObjectDefinition;
|
---|
114 | AST::UiObjectInitializer *UiObjectInitializer;
|
---|
115 | AST::UiObjectBinding *UiObjectBinding;
|
---|
116 | AST::UiScriptBinding *UiScriptBinding;
|
---|
117 | AST::UiArrayBinding *UiArrayBinding;
|
---|
118 | AST::UiObjectMember *UiObjectMember;
|
---|
119 | AST::UiObjectMemberList *UiObjectMemberList;
|
---|
120 | AST::UiArrayMemberList *UiArrayMemberList;
|
---|
121 | AST::UiQualifiedId *UiQualifiedId;
|
---|
122 | AST::UiSignature *UiSignature;
|
---|
123 | AST::UiFormalList *UiFormalList;
|
---|
124 | AST::UiFormal *UiFormal;
|
---|
125 | };
|
---|
126 |
|
---|
127 | public:
|
---|
128 | Parser(Engine *engine);
|
---|
129 | ~Parser();
|
---|
130 |
|
---|
131 | // parse a UI program
|
---|
132 | bool parse() { return parse(T_FEED_UI_PROGRAM); }
|
---|
133 | bool parseStatement() { return parse(T_FEED_JS_STATEMENT); }
|
---|
134 | bool parseExpression() { return parse(T_FEED_JS_EXPRESSION); }
|
---|
135 | bool parseSourceElement() { return parse(T_FEED_JS_SOURCE_ELEMENT); }
|
---|
136 | bool parseUiObjectMember() { return parse(T_FEED_UI_OBJECT_MEMBER); }
|
---|
137 | bool parseProgram() { return parse(T_FEED_JS_PROGRAM); }
|
---|
138 |
|
---|
139 | AST::UiProgram *ast() const
|
---|
140 | { return AST::cast<AST::UiProgram *>(program); }
|
---|
141 |
|
---|
142 | AST::Statement *statement() const
|
---|
143 | {
|
---|
144 | if (! program)
|
---|
145 | return 0;
|
---|
146 |
|
---|
147 | return program->statementCast();
|
---|
148 | }
|
---|
149 |
|
---|
150 | AST::ExpressionNode *expression() const
|
---|
151 | {
|
---|
152 | if (! program)
|
---|
153 | return 0;
|
---|
154 |
|
---|
155 | return program->expressionCast();
|
---|
156 | }
|
---|
157 |
|
---|
158 | AST::UiObjectMember *uiObjectMember() const
|
---|
159 | {
|
---|
160 | if (! program)
|
---|
161 | return 0;
|
---|
162 |
|
---|
163 | return program->uiObjectMemberCast();
|
---|
164 | }
|
---|
165 |
|
---|
166 | AST::Node *rootNode() const
|
---|
167 | { return program; }
|
---|
168 |
|
---|
169 | QList<DiagnosticMessage> diagnosticMessages() const
|
---|
170 | { return diagnostic_messages; }
|
---|
171 |
|
---|
172 | inline DiagnosticMessage diagnosticMessage() const
|
---|
173 | {
|
---|
174 | foreach (const DiagnosticMessage &d, diagnostic_messages) {
|
---|
175 | if (! d.kind == DiagnosticMessage::Warning)
|
---|
176 | return d;
|
---|
177 | }
|
---|
178 |
|
---|
179 | return DiagnosticMessage();
|
---|
180 | }
|
---|
181 |
|
---|
182 | inline QString errorMessage() const
|
---|
183 | { return diagnosticMessage().message; }
|
---|
184 |
|
---|
185 | inline int errorLineNumber() const
|
---|
186 | { return diagnosticMessage().loc.startLine; }
|
---|
187 |
|
---|
188 | inline int errorColumnNumber() const
|
---|
189 | { return diagnosticMessage().loc.startColumn; }
|
---|
190 |
|
---|
191 | protected:
|
---|
192 | bool parse(int startToken);
|
---|
193 |
|
---|
194 | void reallocateStack();
|
---|
195 |
|
---|
196 | inline Value &sym(int index)
|
---|
197 | { return sym_stack [tos + index - 1]; }
|
---|
198 |
|
---|
199 | inline AST::SourceLocation &loc(int index)
|
---|
200 | { return location_stack [tos + index - 1]; }
|
---|
201 |
|
---|
202 | AST::UiQualifiedId *reparseAsQualifiedId(AST::ExpressionNode *expr);
|
---|
203 |
|
---|
204 | protected:
|
---|
205 | Engine *driver;
|
---|
206 | int tos;
|
---|
207 | int stack_size;
|
---|
208 | Value *sym_stack;
|
---|
209 | int *state_stack;
|
---|
210 | AST::SourceLocation *location_stack;
|
---|
211 |
|
---|
212 | AST::Node *program;
|
---|
213 |
|
---|
214 | // error recovery
|
---|
215 | enum { TOKEN_BUFFER_SIZE = 3 };
|
---|
216 |
|
---|
217 | struct SavedToken {
|
---|
218 | int token;
|
---|
219 | double dval;
|
---|
220 | AST::SourceLocation loc;
|
---|
221 | };
|
---|
222 |
|
---|
223 | double yylval;
|
---|
224 | AST::SourceLocation yylloc;
|
---|
225 | AST::SourceLocation yyprevlloc;
|
---|
226 |
|
---|
227 | SavedToken token_buffer[TOKEN_BUFFER_SIZE];
|
---|
228 | SavedToken *first_token;
|
---|
229 | SavedToken *last_token;
|
---|
230 |
|
---|
231 | QList<DiagnosticMessage> diagnostic_messages;
|
---|
232 | };
|
---|
233 |
|
---|
234 | } // end of namespace QDeclarativeJS
|
---|
235 |
|
---|
236 |
|
---|
237 |
|
---|
238 | #define J_SCRIPT_REGEXPLITERAL_RULE1 78
|
---|
239 |
|
---|
240 | #define J_SCRIPT_REGEXPLITERAL_RULE2 79
|
---|
241 |
|
---|
242 | QT_QML_END_NAMESPACE
|
---|
243 |
|
---|
244 |
|
---|
245 |
|
---|
246 | #endif // QDECLARATIVEJSPARSER_P_H
|
---|