1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtScript module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** 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 are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QSCRIPTXMLGENERATOR_P_H
|
---|
43 | #define QSCRIPTXMLGENERATOR_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include <QtCore/qobjectdefs.h>
|
---|
57 |
|
---|
58 | #ifndef QT_NO_SCRIPT
|
---|
59 |
|
---|
60 | #include "qscriptastvisitor_p.h"
|
---|
61 |
|
---|
62 | QT_BEGIN_NAMESPACE
|
---|
63 |
|
---|
64 | class QTextStream;
|
---|
65 |
|
---|
66 | namespace QScript {
|
---|
67 |
|
---|
68 | class XmlGenerator: protected AST::Visitor
|
---|
69 | {
|
---|
70 | public:
|
---|
71 | XmlGenerator(QTextStream &out);
|
---|
72 | virtual ~XmlGenerator();
|
---|
73 |
|
---|
74 | QTextStream &operator()(const QString &program, int lineNumber = 1);
|
---|
75 |
|
---|
76 | protected:
|
---|
77 | void accept(AST::Node *node);
|
---|
78 |
|
---|
79 | virtual bool preVisit(AST::Node *node);
|
---|
80 |
|
---|
81 | virtual bool visit(AST::ThisExpression *node);
|
---|
82 | virtual void endVisit(AST::ThisExpression *node);
|
---|
83 |
|
---|
84 | virtual bool visit(AST::IdentifierExpression *node);
|
---|
85 | virtual void endVisit(AST::IdentifierExpression *node);
|
---|
86 |
|
---|
87 | virtual bool visit(AST::NullExpression *node);
|
---|
88 | virtual void endVisit(AST::NullExpression *node);
|
---|
89 |
|
---|
90 | virtual bool visit(AST::TrueLiteral *node);
|
---|
91 | virtual void endVisit(AST::TrueLiteral *node);
|
---|
92 |
|
---|
93 | virtual bool visit(AST::FalseLiteral *node);
|
---|
94 | virtual void endVisit(AST::FalseLiteral *node);
|
---|
95 |
|
---|
96 | virtual bool visit(AST::StringLiteral *node);
|
---|
97 | virtual void endVisit(AST::StringLiteral *node);
|
---|
98 |
|
---|
99 | virtual bool visit(AST::NumericLiteral *node);
|
---|
100 | virtual void endVisit(AST::NumericLiteral *node);
|
---|
101 |
|
---|
102 | virtual bool visit(AST::RegExpLiteral *node);
|
---|
103 | virtual void endVisit(AST::RegExpLiteral *node);
|
---|
104 |
|
---|
105 | virtual bool visit(AST::ArrayLiteral *node);
|
---|
106 | virtual void endVisit(AST::ArrayLiteral *node);
|
---|
107 |
|
---|
108 | virtual bool visit(AST::ObjectLiteral *node);
|
---|
109 | virtual void endVisit(AST::ObjectLiteral *node);
|
---|
110 |
|
---|
111 | virtual bool visit(AST::ElementList *node);
|
---|
112 | virtual void endVisit(AST::ElementList *node);
|
---|
113 |
|
---|
114 | virtual bool visit(AST::Elision *node);
|
---|
115 | virtual void endVisit(AST::Elision *node);
|
---|
116 |
|
---|
117 | virtual bool visit(AST::PropertyNameAndValueList *node);
|
---|
118 | virtual void endVisit(AST::PropertyNameAndValueList *node);
|
---|
119 |
|
---|
120 | virtual bool visit(AST::IdentifierPropertyName *node);
|
---|
121 | virtual void endVisit(AST::IdentifierPropertyName *node);
|
---|
122 |
|
---|
123 | virtual bool visit(AST::StringLiteralPropertyName *node);
|
---|
124 | virtual void endVisit(AST::StringLiteralPropertyName *node);
|
---|
125 |
|
---|
126 | virtual bool visit(AST::NumericLiteralPropertyName *node);
|
---|
127 | virtual void endVisit(AST::NumericLiteralPropertyName *node);
|
---|
128 |
|
---|
129 | virtual bool visit(AST::ArrayMemberExpression *node);
|
---|
130 | virtual void endVisit(AST::ArrayMemberExpression *node);
|
---|
131 |
|
---|
132 | virtual bool visit(AST::FieldMemberExpression *node);
|
---|
133 | virtual void endVisit(AST::FieldMemberExpression *node);
|
---|
134 |
|
---|
135 | virtual bool visit(AST::NewMemberExpression *node);
|
---|
136 | virtual void endVisit(AST::NewMemberExpression *node);
|
---|
137 |
|
---|
138 | virtual bool visit(AST::NewExpression *node);
|
---|
139 | virtual void endVisit(AST::NewExpression *node);
|
---|
140 |
|
---|
141 | virtual bool visit(AST::CallExpression *node);
|
---|
142 | virtual void endVisit(AST::CallExpression *node);
|
---|
143 |
|
---|
144 | virtual bool visit(AST::ArgumentList *node);
|
---|
145 | virtual void endVisit(AST::ArgumentList *node);
|
---|
146 |
|
---|
147 | virtual bool visit(AST::PostIncrementExpression *node);
|
---|
148 | virtual void endVisit(AST::PostIncrementExpression *node);
|
---|
149 |
|
---|
150 | virtual bool visit(AST::PostDecrementExpression *node);
|
---|
151 | virtual void endVisit(AST::PostDecrementExpression *node);
|
---|
152 |
|
---|
153 | virtual bool visit(AST::DeleteExpression *node);
|
---|
154 | virtual void endVisit(AST::DeleteExpression *node);
|
---|
155 |
|
---|
156 | virtual bool visit(AST::VoidExpression *node);
|
---|
157 | virtual void endVisit(AST::VoidExpression *node);
|
---|
158 |
|
---|
159 | virtual bool visit(AST::TypeOfExpression *node);
|
---|
160 | virtual void endVisit(AST::TypeOfExpression *node);
|
---|
161 |
|
---|
162 | virtual bool visit(AST::PreIncrementExpression *node);
|
---|
163 | virtual void endVisit(AST::PreIncrementExpression *node);
|
---|
164 |
|
---|
165 | virtual bool visit(AST::PreDecrementExpression *node);
|
---|
166 | virtual void endVisit(AST::PreDecrementExpression *node);
|
---|
167 |
|
---|
168 | virtual bool visit(AST::UnaryPlusExpression *node);
|
---|
169 | virtual void endVisit(AST::UnaryPlusExpression *node);
|
---|
170 |
|
---|
171 | virtual bool visit(AST::UnaryMinusExpression *node);
|
---|
172 | virtual void endVisit(AST::UnaryMinusExpression *node);
|
---|
173 |
|
---|
174 | virtual bool visit(AST::TildeExpression *node);
|
---|
175 | virtual void endVisit(AST::TildeExpression *node);
|
---|
176 |
|
---|
177 | virtual bool visit(AST::NotExpression *node);
|
---|
178 | virtual void endVisit(AST::NotExpression *node);
|
---|
179 |
|
---|
180 | virtual bool visit(AST::BinaryExpression *node);
|
---|
181 | virtual void endVisit(AST::BinaryExpression *node);
|
---|
182 |
|
---|
183 | virtual bool visit(AST::ConditionalExpression *node);
|
---|
184 | virtual void endVisit(AST::ConditionalExpression *node);
|
---|
185 |
|
---|
186 | virtual bool visit(AST::Expression *node);
|
---|
187 | virtual void endVisit(AST::Expression *node);
|
---|
188 |
|
---|
189 | virtual bool visit(AST::Block *node);
|
---|
190 | virtual void endVisit(AST::Block *node);
|
---|
191 |
|
---|
192 | virtual bool visit(AST::StatementList *node);
|
---|
193 | virtual void endVisit(AST::StatementList *node);
|
---|
194 |
|
---|
195 | virtual bool visit(AST::VariableStatement *node);
|
---|
196 | virtual void endVisit(AST::VariableStatement *node);
|
---|
197 |
|
---|
198 | virtual bool visit(AST::VariableDeclarationList *node);
|
---|
199 | virtual void endVisit(AST::VariableDeclarationList *node);
|
---|
200 |
|
---|
201 | virtual bool visit(AST::VariableDeclaration *node);
|
---|
202 | virtual void endVisit(AST::VariableDeclaration *node);
|
---|
203 |
|
---|
204 | virtual bool visit(AST::EmptyStatement *node);
|
---|
205 | virtual void endVisit(AST::EmptyStatement *node);
|
---|
206 |
|
---|
207 | virtual bool visit(AST::ExpressionStatement *node);
|
---|
208 | virtual void endVisit(AST::ExpressionStatement *node);
|
---|
209 |
|
---|
210 | virtual bool visit(AST::IfStatement *node);
|
---|
211 | virtual void endVisit(AST::IfStatement *node);
|
---|
212 |
|
---|
213 | virtual bool visit(AST::DoWhileStatement *node);
|
---|
214 | virtual void endVisit(AST::DoWhileStatement *node);
|
---|
215 |
|
---|
216 | virtual bool visit(AST::WhileStatement *node);
|
---|
217 | virtual void endVisit(AST::WhileStatement *node);
|
---|
218 |
|
---|
219 | virtual bool visit(AST::ForStatement *node);
|
---|
220 | virtual void endVisit(AST::ForStatement *node);
|
---|
221 |
|
---|
222 | virtual bool visit(AST::LocalForStatement *node);
|
---|
223 | virtual void endVisit(AST::LocalForStatement *node);
|
---|
224 |
|
---|
225 | virtual bool visit(AST::ForEachStatement *node);
|
---|
226 | virtual void endVisit(AST::ForEachStatement *node);
|
---|
227 |
|
---|
228 | virtual bool visit(AST::LocalForEachStatement *node);
|
---|
229 | virtual void endVisit(AST::LocalForEachStatement *node);
|
---|
230 |
|
---|
231 | virtual bool visit(AST::ContinueStatement *node);
|
---|
232 | virtual void endVisit(AST::ContinueStatement *node);
|
---|
233 |
|
---|
234 | virtual bool visit(AST::BreakStatement *node);
|
---|
235 | virtual void endVisit(AST::BreakStatement *node);
|
---|
236 |
|
---|
237 | virtual bool visit(AST::ReturnStatement *node);
|
---|
238 | virtual void endVisit(AST::ReturnStatement *node);
|
---|
239 |
|
---|
240 | virtual bool visit(AST::WithStatement *node);
|
---|
241 | virtual void endVisit(AST::WithStatement *node);
|
---|
242 |
|
---|
243 | virtual bool visit(AST::SwitchStatement *node);
|
---|
244 | virtual void endVisit(AST::SwitchStatement *node);
|
---|
245 |
|
---|
246 | virtual bool visit(AST::CaseBlock *node);
|
---|
247 | virtual void endVisit(AST::CaseBlock *node);
|
---|
248 |
|
---|
249 | virtual bool visit(AST::CaseClauses *node);
|
---|
250 | virtual void endVisit(AST::CaseClauses *node);
|
---|
251 |
|
---|
252 | virtual bool visit(AST::CaseClause *node);
|
---|
253 | virtual void endVisit(AST::CaseClause *node);
|
---|
254 |
|
---|
255 | virtual bool visit(AST::DefaultClause *node);
|
---|
256 | virtual void endVisit(AST::DefaultClause *node);
|
---|
257 |
|
---|
258 | virtual bool visit(AST::LabelledStatement *node);
|
---|
259 | virtual void endVisit(AST::LabelledStatement *node);
|
---|
260 |
|
---|
261 | virtual bool visit(AST::ThrowStatement *node);
|
---|
262 | virtual void endVisit(AST::ThrowStatement *node);
|
---|
263 |
|
---|
264 | virtual bool visit(AST::TryStatement *node);
|
---|
265 | virtual void endVisit(AST::TryStatement *node);
|
---|
266 |
|
---|
267 | virtual bool visit(AST::Catch *node);
|
---|
268 | virtual void endVisit(AST::Catch *node);
|
---|
269 |
|
---|
270 | virtual bool visit(AST::Finally *node);
|
---|
271 | virtual void endVisit(AST::Finally *node);
|
---|
272 |
|
---|
273 | virtual bool visit(AST::FunctionDeclaration *node);
|
---|
274 | virtual void endVisit(AST::FunctionDeclaration *node);
|
---|
275 |
|
---|
276 | virtual bool visit(AST::FunctionExpression *node);
|
---|
277 | virtual void endVisit(AST::FunctionExpression *node);
|
---|
278 |
|
---|
279 | virtual bool visit(AST::FormalParameterList *node);
|
---|
280 | virtual void endVisit(AST::FormalParameterList *node);
|
---|
281 |
|
---|
282 | virtual bool visit(AST::FunctionBody *node);
|
---|
283 | virtual void endVisit(AST::FunctionBody *node);
|
---|
284 |
|
---|
285 | virtual bool visit(AST::Program *node);
|
---|
286 | virtual void endVisit(AST::Program *node);
|
---|
287 |
|
---|
288 | virtual bool visit(AST::SourceElements *node);
|
---|
289 | virtual void endVisit(AST::SourceElements *node);
|
---|
290 |
|
---|
291 | virtual bool visit(AST::FunctionSourceElement *node);
|
---|
292 | virtual void endVisit(AST::FunctionSourceElement *node);
|
---|
293 |
|
---|
294 | virtual bool visit(AST::StatementSourceElement *node);
|
---|
295 | virtual void endVisit(AST::StatementSourceElement *node);
|
---|
296 |
|
---|
297 | virtual bool visit(AST::DebuggerStatement *node);
|
---|
298 | virtual void endVisit(AST::DebuggerStatement *node);
|
---|
299 |
|
---|
300 | private:
|
---|
301 | int indentLevel(int level)
|
---|
302 | {
|
---|
303 | int was = m_indentLevel;
|
---|
304 | m_indentLevel = level;
|
---|
305 | return was;
|
---|
306 | }
|
---|
307 |
|
---|
308 | void pushIndentLevel()
|
---|
309 | { ++m_indentLevel; }
|
---|
310 |
|
---|
311 | void popIndentLevel()
|
---|
312 | { --m_indentLevel; }
|
---|
313 |
|
---|
314 | QTextStream &newlineAndIndent();
|
---|
315 | QTextStream &startTag(const QString &name, AST::Node *locationNode = 0);
|
---|
316 | QTextStream &endTag(const QString &name);
|
---|
317 |
|
---|
318 | private:
|
---|
319 | QTextStream &out;
|
---|
320 | int m_indentLevel;
|
---|
321 | bool m_formatOutput;
|
---|
322 | };
|
---|
323 |
|
---|
324 | } // namespace QScript
|
---|
325 |
|
---|
326 | #endif // QT_NO_SCRIPT
|
---|
327 |
|
---|
328 | QT_END_NAMESPACE
|
---|
329 |
|
---|
330 | #endif
|
---|