6bb317460fda0575ed18fdf0f64f8f3ce06aa827
[profile/ivi/qtdeclarative.git] / src / declarative / qml / parser / qdeclarativejsparser_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
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 "qdeclarativejsglobal_p.h"
63 #include "qdeclarativejsgrammar_p.h"
64 #include "qdeclarativejsast_p.h"
65 #include "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
76 class QML_PARSER_EXPORT Parser: protected QDeclarativeJSGrammar
77 {
78 public:
79     union Value {
80       int ival;
81       double dval;
82       AST::ArgumentList *ArgumentList;
83       AST::CaseBlock *CaseBlock;
84       AST::CaseClause *CaseClause;
85       AST::CaseClauses *CaseClauses;
86       AST::Catch *Catch;
87       AST::DefaultClause *DefaultClause;
88       AST::ElementList *ElementList;
89       AST::Elision *Elision;
90       AST::ExpressionNode *Expression;
91       AST::Finally *Finally;
92       AST::FormalParameterList *FormalParameterList;
93       AST::FunctionBody *FunctionBody;
94       AST::FunctionDeclaration *FunctionDeclaration;
95       AST::Node *Node;
96       AST::PropertyName *PropertyName;
97       AST::PropertyNameAndValueList *PropertyNameAndValueList;
98       AST::SourceElement *SourceElement;
99       AST::SourceElements *SourceElements;
100       AST::Statement *Statement;
101       AST::StatementList *StatementList;
102       AST::Block *Block;
103       AST::VariableDeclaration *VariableDeclaration;
104       AST::VariableDeclarationList *VariableDeclarationList;
105
106       AST::UiProgram *UiProgram;
107       AST::UiImportList *UiImportList;
108       AST::UiImport *UiImport;
109       AST::UiParameterList *UiParameterList;
110       AST::UiPublicMember *UiPublicMember;
111       AST::UiObjectDefinition *UiObjectDefinition;
112       AST::UiObjectInitializer *UiObjectInitializer;
113       AST::UiObjectBinding *UiObjectBinding;
114       AST::UiScriptBinding *UiScriptBinding;
115       AST::UiArrayBinding *UiArrayBinding;
116       AST::UiObjectMember *UiObjectMember;
117       AST::UiObjectMemberList *UiObjectMemberList;
118       AST::UiArrayMemberList *UiArrayMemberList;
119       AST::UiQualifiedId *UiQualifiedId;
120     };
121
122 public:
123     Parser(Engine *engine);
124     ~Parser();
125
126     // parse a UI program
127     bool parse() { return parse(T_FEED_UI_PROGRAM); }
128     bool parseStatement() { return parse(T_FEED_JS_STATEMENT); }
129     bool parseExpression() { return parse(T_FEED_JS_EXPRESSION); }
130     bool parseSourceElement() { return parse(T_FEED_JS_SOURCE_ELEMENT); }
131     bool parseUiObjectMember() { return parse(T_FEED_UI_OBJECT_MEMBER); }
132     bool parseProgram() { return parse(T_FEED_JS_PROGRAM); }
133
134     AST::UiProgram *ast() const
135     { return AST::cast<AST::UiProgram *>(program); }
136
137     AST::Statement *statement() const
138     {
139         if (! program)
140             return 0;
141
142         return program->statementCast();
143     }
144
145     AST::ExpressionNode *expression() const
146     {
147         if (! program)
148             return 0;
149
150         return program->expressionCast();
151     }
152
153     AST::UiObjectMember *uiObjectMember() const
154     {
155         if (! program)
156             return 0;
157
158         return program->uiObjectMemberCast();
159     }
160
161     AST::Node *rootNode() const
162     { return program; }
163
164     QList<DiagnosticMessage> diagnosticMessages() const
165     { return diagnostic_messages; }
166
167     inline DiagnosticMessage diagnosticMessage() const
168     {
169         foreach (const DiagnosticMessage &d, diagnostic_messages) {
170             if (! d.kind == DiagnosticMessage::Warning)
171                 return d;
172         }
173
174         return DiagnosticMessage();
175     }
176
177     inline QString errorMessage() const
178     { return diagnosticMessage().message; }
179
180     inline int errorLineNumber() const
181     { return diagnosticMessage().loc.startLine; }
182
183     inline int errorColumnNumber() const
184     { return diagnosticMessage().loc.startColumn; }
185
186 protected:
187     bool parse(int startToken);
188
189     void reallocateStack();
190
191     inline Value &sym(int index)
192     { return sym_stack [tos + index - 1]; }
193
194     inline QStringRef &stringRef(int index)
195     { return string_stack [tos + index - 1]; }
196
197     inline AST::SourceLocation &loc(int index)
198     { return location_stack [tos + index - 1]; }
199
200     AST::UiQualifiedId *reparseAsQualifiedId(AST::ExpressionNode *expr);
201
202 protected:
203     Engine *driver;
204     MemoryPool *pool;
205     int tos;
206     int stack_size;
207     Value *sym_stack;
208     int *state_stack;
209     AST::SourceLocation *location_stack;
210     QStringRef *string_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        QStringRef spell;
222     };
223
224     double yylval;
225     QStringRef yytokenspell;
226     AST::SourceLocation yylloc;
227     AST::SourceLocation yyprevlloc;
228
229     SavedToken token_buffer[TOKEN_BUFFER_SIZE];
230     SavedToken *first_token;
231     SavedToken *last_token;
232
233     QList<DiagnosticMessage> diagnostic_messages;
234 };
235
236 } // end of namespace QDeclarativeJS
237
238
239
240 #define J_SCRIPT_REGEXPLITERAL_RULE1 79
241
242 #define J_SCRIPT_REGEXPLITERAL_RULE2 80
243
244 QT_QML_END_NAMESPACE
245
246
247
248 #endif // QDECLARATIVEJSPARSER_P_H