Qt 4.8
qdeclarativejsparser_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** 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.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 "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 
71 
72 namespace QDeclarativeJS {
73 
74 class Engine;
75 class NameId;
76 
78 {
79 public:
80  union Value {
81  int ival;
82  double dval;
107 
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 
140  { return AST::cast<AST::UiProgram *>(program); }
141 
143  {
144  if (! program)
145  return 0;
146 
147  return program->statementCast();
148  }
149 
151  {
152  if (! program)
153  return 0;
154 
155  return program->expressionCast();
156  }
157 
159  {
160  if (! program)
161  return 0;
162 
163  return program->uiObjectMemberCast();
164  }
165 
167  { return program; }
168 
170  { return diagnostic_messages; }
171 
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 
200  { return location_stack [tos + index - 1]; }
201 
202  AST::UiQualifiedId *reparseAsQualifiedId(AST::ExpressionNode *expr);
203 
204 protected:
206  int tos;
211 
213 
214  // error recovery
215  enum { TOKEN_BUFFER_SIZE = 3 };
216 
217  struct SavedToken {
218  int token;
219  double dval;
221  };
222 
223  double yylval;
226 
227  SavedToken token_buffer[TOKEN_BUFFER_SIZE];
230 
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 
243 
244 
245 
246 #endif // QDECLARATIVEJSPARSER_P_H
AST::UiObjectBinding * UiObjectBinding
double d
Definition: qnumeric_p.h:62
QList< DiagnosticMessage > diagnostic_messages
AST::UiArrayMemberList * UiArrayMemberList
AST::VariableDeclarationList * VariableDeclarationList
AST::UiScriptBinding * UiScriptBinding
AST::VariableDeclaration * VariableDeclaration
AST::SourceLocation * location_stack
AST::FunctionDeclaration * FunctionDeclaration
The QString class provides a Unicode character string.
Definition: qstring.h:83
AST::Statement * statement() const
AST::UiProgram * ast() const
#define QML_PARSER_EXPORT
DiagnosticMessage diagnosticMessage() const
AST::ExpressionNode * expression() const
virtual Statement * statementCast()
AST::UiObjectInitializer * UiObjectInitializer
AST::FormalParameterList * FormalParameterList
#define QT_QML_END_NAMESPACE
#define QT_QML_BEGIN_NAMESPACE
AST::Node * rootNode() const
virtual UiObjectMember * uiObjectMemberCast()
AST::UiParameterList * UiParameterList
quint16 index
AST::UiObjectMember * uiObjectMember() const
AST::SourceLocation yyprevlloc
virtual ExpressionNode * expressionCast()
AST::UiObjectDefinition * UiObjectDefinition
AST::UiObjectMemberList * UiObjectMemberList
QList< DiagnosticMessage > diagnosticMessages() const
AST::SourceLocation & loc(int index)
AST::PropertyNameAndValueList * PropertyNameAndValueList
The QList class is a template class that provides lists.
Definition: qdatastream.h:62