0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2001-2004 Roberto Raggi
|
|
4 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
5 |
** All rights reserved.
|
|
6 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
7 |
**
|
|
8 |
** This file is part of the qt3to4 porting application of the Qt Toolkit.
|
|
9 |
**
|
|
10 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
11 |
** No Commercial Usage
|
|
12 |
** This file contains pre-release code and may not be distributed.
|
|
13 |
** You may use this file in accordance with the terms and conditions
|
|
14 |
** contained in the Technology Preview License Agreement accompanying
|
|
15 |
** this package.
|
|
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, 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 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
**
|
|
39 |
** $QT_END_LICENSE$
|
|
40 |
**
|
|
41 |
****************************************************************************/
|
|
42 |
|
|
43 |
#include "treewalker.h"
|
|
44 |
|
|
45 |
QT_BEGIN_NAMESPACE
|
|
46 |
|
|
47 |
/*
|
|
48 |
template <class T>
|
|
49 |
inline void parseAll(TreeWalker *w, const List<T *> *l)
|
|
50 |
{
|
|
51 |
if (!l)
|
|
52 |
return;
|
|
53 |
|
|
54 |
foreach(T *e, *l)
|
|
55 |
w->parseNode(e);
|
|
56 |
}
|
|
57 |
*/
|
|
58 |
|
|
59 |
//Workaround for ICE on MSVC, use macro instead of template.
|
|
60 |
#define PARSE_ALL(ListType, ListValueType) \
|
|
61 |
inline void parseAll(TreeWalker *w, const ListType *l) \
|
|
62 |
{ \
|
|
63 |
if (!l) \
|
|
64 |
return; \
|
|
65 |
foreach(ListValueType *e, *l) \
|
|
66 |
w->parseNode(e); \
|
|
67 |
} \
|
|
68 |
|
|
69 |
PARSE_ALL(List<AST *>, AST)
|
|
70 |
PARSE_ALL(List<ClassOrNamespaceNameAST *>, ClassOrNamespaceNameAST)
|
|
71 |
PARSE_ALL(List<BaseSpecifierAST *>, BaseSpecifierAST)
|
|
72 |
PARSE_ALL(List<DeclarationAST *>, DeclarationAST)
|
|
73 |
PARSE_ALL(List<EnumeratorAST *>, EnumeratorAST)
|
|
74 |
PARSE_ALL(List<ParameterDeclarationAST *>, ParameterDeclarationAST)
|
|
75 |
PARSE_ALL(List<InitDeclaratorAST *>, InitDeclaratorAST)
|
|
76 |
PARSE_ALL(List<TemplateParameterAST *>, TemplateParameterAST)
|
|
77 |
PARSE_ALL(List<StatementAST *>, StatementAST)
|
|
78 |
|
|
79 |
|
|
80 |
void TreeWalker::parseTemplateArgumentList(TemplateArgumentListAST *node)
|
|
81 |
{
|
|
82 |
List<AST *> *arglist = node->argumentList();
|
|
83 |
parseAll(this, arglist);
|
|
84 |
}
|
|
85 |
|
|
86 |
void TreeWalker::parseClassOrNamespaceName(ClassOrNamespaceNameAST *node)
|
|
87 |
{
|
|
88 |
parseNode(node->name());
|
|
89 |
parseNode(node->templateArgumentList());
|
|
90 |
}
|
|
91 |
|
|
92 |
void TreeWalker::parseName(NameAST *node)
|
|
93 |
{
|
|
94 |
parseAll(this, node->classOrNamespaceNameList());
|
|
95 |
parseNode(node->unqualifiedName());
|
|
96 |
}
|
|
97 |
|
|
98 |
void TreeWalker::parseTypeParameter(TypeParameterAST *node)
|
|
99 |
{
|
|
100 |
parseNode(node->templateParameterList());
|
|
101 |
parseNode(node->name());
|
|
102 |
parseNode(node->typeId());
|
|
103 |
}
|
|
104 |
|
|
105 |
void TreeWalker::parseDeclaration(DeclarationAST *node)
|
|
106 |
{
|
|
107 |
switch (node->nodeType()) {
|
|
108 |
case NodeType_AccessDeclaration:
|
|
109 |
parseAccessDeclaration(static_cast<AccessDeclarationAST*>(node));
|
|
110 |
break;
|
|
111 |
case NodeType_LinkageSpecification:
|
|
112 |
parseLinkageSpecification(static_cast<LinkageSpecificationAST*>(node));
|
|
113 |
break;
|
|
114 |
case NodeType_Namespace:
|
|
115 |
parseNamespace(static_cast<NamespaceAST*>(node));
|
|
116 |
break;
|
|
117 |
case NodeType_NamespaceAlias:
|
|
118 |
parseNamespaceAlias(static_cast<NamespaceAliasAST*>(node));
|
|
119 |
break;
|
|
120 |
case NodeType_Using:
|
|
121 |
parseUsing(static_cast<UsingAST*>(node));
|
|
122 |
break;
|
|
123 |
case NodeType_UsingDirective:
|
|
124 |
parseUsingDirective(static_cast<UsingDirectiveAST*>(node));
|
|
125 |
break;
|
|
126 |
case NodeType_Typedef:
|
|
127 |
parseTypedef(static_cast<TypedefAST*>(node));
|
|
128 |
break;
|
|
129 |
case NodeType_TemplateDeclaration:
|
|
130 |
parseTemplateDeclaration(static_cast<TemplateDeclarationAST*>(node));
|
|
131 |
break;
|
|
132 |
case NodeType_SimpleDeclaration:
|
|
133 |
parseSimpleDeclaration(static_cast<SimpleDeclarationAST*>(node));
|
|
134 |
break;
|
|
135 |
case NodeType_FunctionDefinition:
|
|
136 |
parseFunctionDefinition(static_cast<FunctionDefinitionAST*>(node));
|
|
137 |
break;
|
|
138 |
default:
|
|
139 |
break;
|
|
140 |
}
|
|
141 |
}
|
|
142 |
|
|
143 |
void TreeWalker::parseAccessDeclaration(AccessDeclarationAST *node)
|
|
144 |
{
|
|
145 |
parseAll(this, node->accessList());
|
|
146 |
}
|
|
147 |
|
|
148 |
void TreeWalker::parseTypeSpecifier(TypeSpecifierAST *node)
|
|
149 |
{
|
|
150 |
parseNode(node->name());
|
|
151 |
parseNode(node->cvQualify());
|
|
152 |
parseNode(node->cv2Qualify());
|
|
153 |
|
|
154 |
switch (node->nodeType()) {
|
|
155 |
case NodeType_ClassSpecifier:
|
|
156 |
parseClassSpecifier(static_cast<ClassSpecifierAST*>(node));
|
|
157 |
break;
|
|
158 |
case NodeType_EnumSpecifier:
|
|
159 |
parseEnumSpecifier(static_cast<EnumSpecifierAST*>(node));
|
|
160 |
break;
|
|
161 |
case NodeType_ElaboratedTypeSpecifier:
|
|
162 |
parseElaboratedTypeSpecifier(static_cast<ElaboratedTypeSpecifierAST*>(node));
|
|
163 |
break;
|
|
164 |
default:
|
|
165 |
break;
|
|
166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
void TreeWalker::parseBaseSpecifier(BaseSpecifierAST *node)
|
|
170 |
{
|
|
171 |
parseNode(node->isVirtual());
|
|
172 |
parseNode(node->access());
|
|
173 |
parseNode(node->name());
|
|
174 |
}
|
|
175 |
|
|
176 |
void TreeWalker::parseBaseClause(BaseClauseAST *node)
|
|
177 |
{
|
|
178 |
parseAll(this, node->baseSpecifierList());
|
|
179 |
}
|
|
180 |
|
|
181 |
void TreeWalker::parseClassSpecifier(ClassSpecifierAST *node)
|
|
182 |
{
|
|
183 |
parseNode(node->winDeclSpec());
|
|
184 |
parseNode(node->classKey());
|
|
185 |
parseNode(node->baseClause());
|
|
186 |
parseAll(this, node->declarationList());
|
|
187 |
}
|
|
188 |
|
|
189 |
void TreeWalker::parseEnumerator(EnumeratorAST *node)
|
|
190 |
{
|
|
191 |
parseNode(node->id());
|
|
192 |
parseNode(node->expression());
|
|
193 |
}
|
|
194 |
|
|
195 |
void TreeWalker::parseEnumSpecifier(EnumSpecifierAST *node)
|
|
196 |
{
|
|
197 |
parseAll(this, node->enumeratorList());
|
|
198 |
}
|
|
199 |
|
|
200 |
void TreeWalker::parseElaboratedTypeSpecifier(ElaboratedTypeSpecifierAST *node)
|
|
201 |
{
|
|
202 |
parseNode(node->kind());
|
|
203 |
}
|
|
204 |
|
|
205 |
void TreeWalker::parseLinkageBody(LinkageBodyAST *node)
|
|
206 |
{
|
|
207 |
parseAll(this, node->declarationList());
|
|
208 |
}
|
|
209 |
|
|
210 |
void TreeWalker::parseLinkageSpecification(LinkageSpecificationAST *node)
|
|
211 |
{
|
|
212 |
parseNode(node->externType());
|
|
213 |
parseNode(node->linkageBody());
|
|
214 |
parseNode(node->declaration());
|
|
215 |
}
|
|
216 |
|
|
217 |
void TreeWalker::parseNamespace(NamespaceAST *node)
|
|
218 |
{
|
|
219 |
parseNode(node->namespaceName());
|
|
220 |
parseNode(node->linkageBody());
|
|
221 |
}
|
|
222 |
|
|
223 |
void TreeWalker::parseNamespaceAlias(NamespaceAliasAST *node)
|
|
224 |
{
|
|
225 |
parseNode(node->namespaceName());
|
|
226 |
parseNode(node->aliasName());
|
|
227 |
}
|
|
228 |
|
|
229 |
void TreeWalker::parseUsing(UsingAST *node)
|
|
230 |
{
|
|
231 |
parseNode(node->typeName());
|
|
232 |
parseNode(node->name());
|
|
233 |
}
|
|
234 |
|
|
235 |
void TreeWalker::parseUsingDirective(UsingDirectiveAST *node)
|
|
236 |
{
|
|
237 |
parseNode(node->name());
|
|
238 |
}
|
|
239 |
|
|
240 |
void TreeWalker::parseDeclarator(DeclaratorAST *node)
|
|
241 |
{
|
|
242 |
parseAll(this, node->ptrOpList());
|
|
243 |
parseNode(node->subDeclarator());
|
|
244 |
parseNode(node->declaratorId());
|
|
245 |
parseNode(node->bitfieldInitialization());
|
|
246 |
parseAll(this, node->arrayDimensionList());
|
|
247 |
parseNode(node->parameterDeclarationClause());
|
|
248 |
parseNode(node->constant());
|
|
249 |
parseNode(node->exceptionSpecification());
|
|
250 |
}
|
|
251 |
|
|
252 |
void TreeWalker::parseParameterDeclaration(ParameterDeclarationAST *node)
|
|
253 |
{
|
|
254 |
parseNode(node->typeSpec());
|
|
255 |
parseNode(node->declarator());
|
|
256 |
parseNode(node->expression());
|
|
257 |
}
|
|
258 |
|
|
259 |
void TreeWalker::parseParameterDeclarationList(ParameterDeclarationListAST *node)
|
|
260 |
{
|
|
261 |
parseAll(this, node->parameterList());
|
|
262 |
}
|
|
263 |
|
|
264 |
void TreeWalker::parseParameterDeclarationClause(ParameterDeclarationClauseAST *node)
|
|
265 |
{
|
|
266 |
parseNode(node->parameterDeclarationList());
|
|
267 |
parseNode(node->ellipsis());
|
|
268 |
}
|
|
269 |
|
|
270 |
void TreeWalker::parseInitDeclarator(InitDeclaratorAST *node)
|
|
271 |
{
|
|
272 |
parseNode(node->declarator());
|
|
273 |
parseNode(node->initializer());
|
|
274 |
}
|
|
275 |
|
|
276 |
void TreeWalker::parseInitDeclaratorList(InitDeclaratorListAST *node)
|
|
277 |
{
|
|
278 |
parseAll(this, node->initDeclaratorList());
|
|
279 |
}
|
|
280 |
|
|
281 |
void TreeWalker::parseTypedef(TypedefAST *node)
|
|
282 |
{
|
|
283 |
parseNode(node->typeSpec());
|
|
284 |
parseNode(node->initDeclaratorList());
|
|
285 |
}
|
|
286 |
|
|
287 |
void TreeWalker::parseTemplateParameter(TemplateParameterAST *node)
|
|
288 |
{
|
|
289 |
parseNode(node->typeParameter());
|
|
290 |
parseNode(node->typeValueParameter());
|
|
291 |
}
|
|
292 |
|
|
293 |
void TreeWalker::parseTemplateParameterList(TemplateParameterListAST *node)
|
|
294 |
{
|
|
295 |
parseAll(this, node->templateParameterList());
|
|
296 |
}
|
|
297 |
|
|
298 |
void TreeWalker::parseTemplateDeclaration(TemplateDeclarationAST *node)
|
|
299 |
{
|
|
300 |
parseNode(node->exported());
|
|
301 |
parseNode(node->templateParameterList());
|
|
302 |
parseNode(node->declaration());
|
|
303 |
}
|
|
304 |
|
|
305 |
void TreeWalker::parseSimpleDeclaration(SimpleDeclarationAST *node)
|
|
306 |
{
|
|
307 |
parseNode(node->functionSpecifier());
|
|
308 |
parseNode(node->storageSpecifier());
|
|
309 |
parseNode(node->typeSpec());
|
|
310 |
parseNode(node->initDeclaratorList());
|
|
311 |
parseNode(node->winDeclSpec());
|
|
312 |
}
|
|
313 |
|
|
314 |
void TreeWalker::parseStatement(StatementAST *node)
|
|
315 |
{
|
|
316 |
switch (node->nodeType()) {
|
|
317 |
case NodeType_ExpressionStatement:
|
|
318 |
parseExpressionStatement(static_cast<ExpressionStatementAST*>(node));
|
|
319 |
break;
|
|
320 |
|
|
321 |
case NodeType_IfStatement:
|
|
322 |
parseIfStatement(static_cast<IfStatementAST*>(node));
|
|
323 |
break;
|
|
324 |
|
|
325 |
case NodeType_WhileStatement:
|
|
326 |
parseWhileStatement(static_cast<WhileStatementAST*>(node));
|
|
327 |
return;
|
|
328 |
|
|
329 |
case NodeType_DoStatement:
|
|
330 |
parseDoStatement(static_cast<DoStatementAST*>(node));
|
|
331 |
break;
|
|
332 |
|
|
333 |
case NodeType_ForStatement:
|
|
334 |
parseForStatement(static_cast<ForStatementAST*>(node));
|
|
335 |
break;
|
|
336 |
|
|
337 |
case NodeType_SwitchStatement:
|
|
338 |
parseSwitchStatement(static_cast<SwitchStatementAST*>(node));
|
|
339 |
break;
|
|
340 |
|
|
341 |
case NodeType_LabeledStatement:
|
|
342 |
parseLabeledStatement(static_cast<LabeledStatementAST*>(node));
|
|
343 |
break;
|
|
344 |
|
|
345 |
case NodeType_StatementList:
|
|
346 |
parseStatementList(static_cast<StatementListAST*>(node));
|
|
347 |
break;
|
|
348 |
|
|
349 |
case NodeType_DeclarationStatement:
|
|
350 |
parseDeclarationStatement(static_cast<DeclarationStatementAST*>(node));
|
|
351 |
break;
|
|
352 |
|
|
353 |
case NodeType_ReturnStatement:
|
|
354 |
parseReturnStatement(static_cast<ReturnStatementAST*>(node));
|
|
355 |
break;
|
|
356 |
|
|
357 |
default:
|
|
358 |
break;
|
|
359 |
}
|
|
360 |
}
|
|
361 |
|
|
362 |
void TreeWalker::parseExpressionStatement(ExpressionStatementAST *node)
|
|
363 |
{
|
|
364 |
parseNode(node->expression());
|
|
365 |
}
|
|
366 |
|
|
367 |
void TreeWalker::parseCondition(ConditionAST *node)
|
|
368 |
{
|
|
369 |
parseNode(node->typeSpec());
|
|
370 |
parseNode(node->declarator());
|
|
371 |
parseNode(node->expression());
|
|
372 |
}
|
|
373 |
|
|
374 |
void TreeWalker::parseIfStatement(IfStatementAST *node)
|
|
375 |
{
|
|
376 |
parseNode(node->condition());
|
|
377 |
parseNode(node->statement());
|
|
378 |
parseNode(node->elseStatement());
|
|
379 |
}
|
|
380 |
|
|
381 |
void TreeWalker::parseWhileStatement(WhileStatementAST *node)
|
|
382 |
{
|
|
383 |
parseNode(node->condition());
|
|
384 |
parseNode(node->statement());
|
|
385 |
}
|
|
386 |
|
|
387 |
void TreeWalker::parseDoStatement(DoStatementAST *node)
|
|
388 |
{
|
|
389 |
parseNode(node->condition());
|
|
390 |
parseNode(node->statement());
|
|
391 |
}
|
|
392 |
|
|
393 |
void TreeWalker::parseForStatement(ForStatementAST *node)
|
|
394 |
{
|
|
395 |
parseNode(node->initStatement());
|
|
396 |
parseNode(node->condition());
|
|
397 |
parseNode(node->expression());
|
|
398 |
parseNode(node->statement());
|
|
399 |
}
|
|
400 |
|
|
401 |
void TreeWalker::parseSwitchStatement(SwitchStatementAST *node)
|
|
402 |
{
|
|
403 |
parseNode(node->condition());
|
|
404 |
parseNode(node->statement());
|
|
405 |
}
|
|
406 |
|
|
407 |
void TreeWalker::parseLabeledStatement(LabeledStatementAST *node)
|
|
408 |
{
|
|
409 |
parseNode(node->expression());
|
|
410 |
parseNode(node->statement());
|
|
411 |
}
|
|
412 |
|
|
413 |
void TreeWalker::parseStatementList(StatementListAST *node)
|
|
414 |
{
|
|
415 |
parseAll(this, node->statementList());
|
|
416 |
}
|
|
417 |
|
|
418 |
void TreeWalker::parseDeclarationStatement(DeclarationStatementAST *node)
|
|
419 |
{
|
|
420 |
parseNode(node->declaration());
|
|
421 |
}
|
|
422 |
|
|
423 |
void TreeWalker::parseFunctionDefinition(FunctionDefinitionAST *node)
|
|
424 |
{
|
|
425 |
parseNode(node->functionSpecifier());
|
|
426 |
parseNode(node->storageSpecifier());
|
|
427 |
parseNode(node->typeSpec());
|
|
428 |
parseNode(node->initDeclarator());
|
|
429 |
parseNode(node->functionBody());
|
|
430 |
parseNode(node->winDeclSpec());
|
|
431 |
}
|
|
432 |
|
|
433 |
void TreeWalker::parseTranslationUnit(TranslationUnitAST *node)
|
|
434 |
{
|
|
435 |
parseAll(this, node->declarationList());
|
|
436 |
}
|
|
437 |
|
|
438 |
|
|
439 |
void TreeWalker::parseExpression(AbstractExpressionAST *node)
|
|
440 |
{
|
|
441 |
parseAll(this, node->children());
|
|
442 |
}
|
|
443 |
|
|
444 |
|
|
445 |
void TreeWalker::parseBinaryExpression(BinaryExpressionAST *node)
|
|
446 |
{
|
|
447 |
parseNode(node->op());
|
|
448 |
parseNode(node->leftExpression());
|
|
449 |
parseNode(node->rightExpression());
|
|
450 |
}
|
|
451 |
|
|
452 |
void TreeWalker::parseReturnStatement(ReturnStatementAST *node)
|
|
453 |
{
|
|
454 |
parseNode(node->expression());
|
|
455 |
}
|
|
456 |
|
|
457 |
QT_END_NAMESPACE
|