1 /*
2 This file is part of KDevelop
3 SPDX-FileCopyrightText: 2002, 2003 Roberto Raggi <roberto@kdevelop.org>
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7 #include "ast.h"
8 #include <QStringList>
9 #if QT_VERSION >= 0x050000
10 #else
11 #include <kdebug.h>
12 #endif
13
nodeTypeToString(int type)14 QString nodeTypeToString(int type)
15 {
16 switch (type) {
17 case NodeType_Generic:
18 return QLatin1String("Generic");
19 case NodeType_TemplateArgumentList:
20 return QLatin1String("TemplateArgumentList");
21 case NodeType_ClassOrNamespaceName:
22 return QLatin1String("ClassOrNamespaceName");
23 case NodeType_Name:
24 return QLatin1String("Name");
25 case NodeType_Declaration:
26 return QLatin1String("Declaration");
27 case NodeType_TypeSpecifier:
28 return QLatin1String("TypeSpecifier");
29 case NodeType_BaseSpecifier:
30 return QLatin1String("BaseSpecifier");
31 case NodeType_BaseClause:
32 return QLatin1String("BaseClause");
33 case NodeType_ClassSpecifier:
34 return QLatin1String("ClassSpecifier");
35 case NodeType_Enumerator:
36 return QLatin1String("Enumerator");
37 case NodeType_EnumSpecifier:
38 return QLatin1String("EnumSpecifier");
39 case NodeType_ElaboratedTypeSpecifier:
40 return QLatin1String("ElaboratedTypeSpecifier");
41 case NodeType_LinkageBody:
42 return QLatin1String("LinkageBody");
43 case NodeType_LinkageSpecification:
44 return QLatin1String("LinkageSpecification");
45 case NodeType_Namespace:
46 return QLatin1String("Namespace");
47 case NodeType_NamespaceAlias:
48 return QLatin1String("NamespaceAlias");
49 case NodeType_Using:
50 return QLatin1String("Using");
51 case NodeType_UsingDirective:
52 return QLatin1String("UsingDirective");
53 case NodeType_InitDeclaratorList:
54 return QLatin1String("InitDeclaratorList");
55 case NodeType_Typedef:
56 return QLatin1String("Typedef");
57 case NodeType_Declarator:
58 return QLatin1String("Declarator");
59 case NodeType_InitDeclarator:
60 return QLatin1String("InitDeclarator");
61 case NodeType_TemplateDeclaration:
62 return QLatin1String("TemplateDeclaration");
63 case NodeType_SimpleDeclaration:
64 return QLatin1String("SimpleDeclaration");
65 case NodeType_Statement:
66 return QLatin1String("Statement");
67 case NodeType_IfStatement:
68 return QLatin1String("IfStatement");
69 case NodeType_WhileStatement:
70 return QLatin1String("WhileStatement");
71 case NodeType_DoStatement:
72 return QLatin1String("DoStatement");
73 case NodeType_ForStatement:
74 return QLatin1String("ForStatement");
75 case NodeType_ForEachStatement: // qt4 [erbsland]
76 return QLatin1String("ForEachStatement");
77 case NodeType_SwitchStatement:
78 return QLatin1String("SwitchStatement");
79 case NodeType_CatchStatement:
80 return QLatin1String("CatchStatement");
81 case NodeType_CatchStatementList:
82 return QLatin1String("CatchStatementList");
83 case NodeType_TryBlockStatement:
84 return QLatin1String("TryBlockStatement");
85 case NodeType_DeclarationStatement:
86 return QLatin1String("DeclarationStatement");
87 case NodeType_StatementList:
88 return QLatin1String("StatementList");
89 case NodeType_TranslationUnit:
90 return QLatin1String("TranslationUnit");
91 case NodeType_FunctionDefinition:
92 return QLatin1String("FunctionDefinition");
93 case NodeType_ExpressionStatement:
94 return QLatin1String("ExpressionStatement");
95 case NodeType_ParameterDeclaration:
96 return QLatin1String("ParameterDeclaration");
97 case NodeType_ParameterDeclarationList:
98 return QLatin1String("ParameterDeclarationList");
99 case NodeType_ParameterDeclarationClause:
100 return QLatin1String("ParameterDeclarationClause");
101 case NodeType_Group:
102 return QLatin1String("Group");
103 case NodeType_AccessDeclaration:
104 return QLatin1String("AccessDeclaration");
105 case NodeType_TypeParameter:
106 return QLatin1String("TypeParameter");
107 case NodeType_TemplateParameter:
108 return QLatin1String("TemplateParameter");
109 case NodeType_TemplateParameterList:
110 return QLatin1String("TemplateParameterList");
111 case NodeType_Condition:
112 return QLatin1String("Condition");
113 case NodeType_Custom:
114 return QLatin1String("Custom");
115 }
116
117 return QString();
118 }
119
120
121 // ------------------------------------------------------------------------
AST()122 AST::AST()
123 : m_nodeType(NodeType_Generic), m_parent(0),
124 m_startLine(0), m_startColumn(0),
125 m_endLine(0), m_endColumn(0)
126 {
127 }
128
~AST()129 AST::~AST()
130 {
131 #ifndef CPPPARSER_NO_CHILDREN
132 if (m_parent)
133 m_parent->removeChild(this);
134 #endif
135 }
136
setStartPosition(int line,int col)137 void AST::setStartPosition(int line, int col)
138 {
139 m_startLine = line;
140 m_startColumn = col;
141 }
142
getStartPosition(int * line,int * col) const143 void AST::getStartPosition(int* line, int* col) const
144 {
145 if (line)
146 *line = m_startLine;
147
148 if (col)
149 * col = m_startColumn;
150 }
151
setEndPosition(int line,int col)152 void AST::setEndPosition(int line, int col)
153 {
154 m_endLine = line;
155 m_endColumn = col;
156 }
157
getEndPosition(int * line,int * col) const158 void AST::getEndPosition(int* line, int* col) const
159 {
160 if (line)
161 *line = m_endLine;
162
163 if (col)
164 * col = m_endColumn;
165 }
166
setParent(AST * parent)167 void AST::setParent(AST* parent)
168 {
169 #ifndef CPPPARSER_NO_CHILDREN
170 if (m_parent)
171 m_parent->removeChild(this);
172 #endif
173
174 m_parent = parent;
175
176 #ifndef CPPPARSER_NO_CHILDREN
177 if (m_parent)
178 m_parent->appendChild(this);
179 #endif
180 }
181
182 #ifndef CPPPARSER_NO_CHILDREN
appendChild(AST * child)183 void AST::appendChild(AST* child)
184 {
185 m_children.append(child);
186 }
187
removeChild(AST * child)188 void AST::removeChild(AST* child)
189 {
190 m_children.removeOne(child);
191 }
192 #endif
193
194 // ------------------------------------------------------------------------
NameAST()195 NameAST::NameAST()
196 : m_global(false)
197 {
198 }
199
setGlobal(bool b)200 void NameAST::setGlobal(bool b)
201 {
202 m_global = b;
203 }
204
setUnqualifiedName(ClassOrNamespaceNameAST::Node & unqualifiedName)205 void NameAST::setUnqualifiedName(ClassOrNamespaceNameAST::Node& unqualifiedName)
206 {
207 m_unqualifiedName = std::move(unqualifiedName);
208 if (m_unqualifiedName.get()) m_unqualifiedName->setParent(this);
209 }
210
addClassOrNamespaceName(ClassOrNamespaceNameAST::Node & classOrNamespaceName)211 void NameAST::addClassOrNamespaceName(ClassOrNamespaceNameAST::Node& classOrNamespaceName)
212 {
213 if (!classOrNamespaceName.get())
214 return;
215
216 classOrNamespaceName->setParent(this);
217 m_classOrNamespaceNameList.append(classOrNamespaceName.release());
218 }
219
text() const220 QString NameAST::text() const
221 {
222 if (!m_unqualifiedName.get())
223 return QString();
224
225 QString str;
226
227 if (m_global)
228 str += QLatin1String("::");
229
230 for (int i = 0; i < m_classOrNamespaceNameList.size(); ++i) {
231 str += m_classOrNamespaceNameList.at(i)->text() + QLatin1String("::");
232 }
233
234 if (m_unqualifiedName.get())
235 str += m_unqualifiedName->text();
236
237 return str;
238 }
239
240 // ------------------------------------------------------------------------
DeclarationAST()241 DeclarationAST::DeclarationAST()
242 {
243 }
244
245 // ------------------------------------------------------------------------
LinkageBodyAST()246 LinkageBodyAST::LinkageBodyAST()
247 {
248 }
249
addDeclaration(DeclarationAST::Node & ast)250 void LinkageBodyAST::addDeclaration(DeclarationAST::Node& ast)
251 {
252 if (!ast.get())
253 return;
254
255 ast->setParent(this);
256 m_declarationList.append(ast.release());
257 }
258
259 // ------------------------------------------------------------------------
LinkageSpecificationAST()260 LinkageSpecificationAST::LinkageSpecificationAST()
261 {
262 }
263
setExternType(AST::Node & externType)264 void LinkageSpecificationAST::setExternType(AST::Node& externType)
265 {
266 m_externType = std::move(externType);
267 if (m_externType.get()) m_externType->setParent(this);
268 }
269
setLinkageBody(LinkageBodyAST::Node & linkageBody)270 void LinkageSpecificationAST::setLinkageBody(LinkageBodyAST::Node& linkageBody)
271 {
272 m_linkageBody = std::move(linkageBody);
273 if (m_linkageBody.get()) m_linkageBody->setParent(this);
274 }
275
setDeclaration(DeclarationAST::Node & decl)276 void LinkageSpecificationAST::setDeclaration(DeclarationAST::Node& decl)
277 {
278 m_declaration = std::move(decl);
279 if (m_declaration.get()) m_declaration->setParent(this);
280 }
281
282 // ------------------------------------------------------------------------
TranslationUnitAST()283 TranslationUnitAST::TranslationUnitAST()
284 {
285 }
286
addDeclaration(DeclarationAST::Node & ast)287 void TranslationUnitAST::addDeclaration(DeclarationAST::Node& ast)
288 {
289 if (!ast.get())
290 return;
291
292 ast->setParent(this);
293 m_declarationList.append(ast.release());
294 }
295
296 // ------------------------------------------------------------------------
NamespaceAST()297 NamespaceAST::NamespaceAST()
298 {
299 }
300
setNamespaceName(AST::Node & namespaceName)301 void NamespaceAST::setNamespaceName(AST::Node& namespaceName)
302 {
303 m_namespaceName = std::move(namespaceName);
304 if (m_namespaceName.get()) m_namespaceName->setParent(this);
305 }
306
setLinkageBody(LinkageBodyAST::Node & linkageBody)307 void NamespaceAST::setLinkageBody(LinkageBodyAST::Node& linkageBody)
308 {
309 m_linkageBody = std::move(linkageBody);
310 if (m_linkageBody.get()) m_linkageBody->setParent(this);
311 }
312
313
314 // ------------------------------------------------------------------------
NamespaceAliasAST()315 NamespaceAliasAST::NamespaceAliasAST()
316 {
317 }
318
setNamespaceName(AST::Node & namespaceName)319 void NamespaceAliasAST::setNamespaceName(AST::Node& namespaceName)
320 {
321 m_namespaceName = std::move(namespaceName);
322 if (m_namespaceName.get()) m_namespaceName->setParent(this);
323 }
324
setAliasName(NameAST::Node & name)325 void NamespaceAliasAST::setAliasName(NameAST::Node& name)
326 {
327 m_aliasName = std::move(name);
328 if (m_aliasName.get()) m_aliasName->setParent(this);
329 }
330
331 // ------------------------------------------------------------------------
UsingAST()332 UsingAST::UsingAST()
333 {
334 }
335
setTypeName(AST::Node & typeName)336 void UsingAST::setTypeName(AST::Node& typeName)
337 {
338 m_typeName = std::move(typeName);
339 if (m_typeName.get()) m_typeName->setParent(this);
340 }
341
setName(NameAST::Node & name)342 void UsingAST::setName(NameAST::Node& name)
343 {
344 m_name = std::move(name);
345 if (m_name.get()) m_name->setParent(this);
346 }
347
348 // ------------------------------------------------------------------------
UsingDirectiveAST()349 UsingDirectiveAST::UsingDirectiveAST()
350 {
351 }
352
setName(NameAST::Node & name)353 void UsingDirectiveAST::setName(NameAST::Node& name)
354 {
355 m_name = std::move(name);
356 if (m_name.get()) m_name->setParent(this);
357 }
358
TypedefAST()359 TypedefAST::TypedefAST()
360 {
361 }
362
setName(NameAST::Node & name)363 void TypeSpecifierAST::setName(NameAST::Node& name)
364 {
365 m_name = std::move(name);
366 if (m_name.get()) m_name->setParent(this);
367 }
368
setTypeSpec(TypeSpecifierAST::Node & typeSpec)369 void TypedefAST::setTypeSpec(TypeSpecifierAST::Node& typeSpec)
370 {
371 m_typeSpec = std::move(typeSpec);
372 if (m_typeSpec.get()) m_typeSpec->setParent(this);
373 }
374
setInitDeclaratorList(InitDeclaratorListAST::Node & initDeclaratorList)375 void TypedefAST::setInitDeclaratorList(InitDeclaratorListAST::Node& initDeclaratorList)
376 {
377 m_initDeclaratorList = std::move(initDeclaratorList);
378 if (m_initDeclaratorList.get()) m_initDeclaratorList->setParent(this);
379 }
380
381 // ------------------------------------------------------------------------
TemplateArgumentListAST()382 TemplateArgumentListAST::TemplateArgumentListAST()
383 {
384 }
385
addArgument(AST::Node & arg)386 void TemplateArgumentListAST::addArgument(AST::Node& arg)
387 {
388 if (!arg.get())
389 return;
390
391 arg->setParent(this);
392 m_argumentList.append(arg.release());
393 }
394
text() const395 QString TemplateArgumentListAST::text() const
396 {
397 QStringList l;
398
399 for (int i = 0; i < m_argumentList.size(); ++i) {
400 l.append(m_argumentList.at(i)->text());
401 }
402
403 return l.join(QLatin1String(", "));
404 }
405
406 // ------------------------------------------------------------------------
TemplateDeclarationAST()407 TemplateDeclarationAST::TemplateDeclarationAST()
408 {
409 }
410
setExported(AST::Node & exported)411 void TemplateDeclarationAST::setExported(AST::Node& exported)
412 {
413 m_exported = std::move(exported);
414 if (m_exported.get()) m_exported->setParent(this);
415 }
416
setTemplateParameterList(TemplateParameterListAST::Node & templateParameterList)417 void TemplateDeclarationAST::setTemplateParameterList(TemplateParameterListAST::Node& templateParameterList)
418 {
419 m_templateParameterList = std::move(templateParameterList);
420 if (m_templateParameterList.get()) m_templateParameterList->setParent(this);
421 }
422
setDeclaration(DeclarationAST::Node & declaration)423 void TemplateDeclarationAST::setDeclaration(DeclarationAST::Node& declaration)
424 {
425 m_declaration = std::move(declaration);
426 if (m_declaration.get()) m_declaration->setParent(this);
427 }
428
429 // ------------------------------------------------------------------------
ClassOrNamespaceNameAST()430 ClassOrNamespaceNameAST::ClassOrNamespaceNameAST()
431 {
432 }
433
setName(AST::Node & name)434 void ClassOrNamespaceNameAST::setName(AST::Node& name)
435 {
436 m_name = std::move(name);
437 if (m_name.get()) m_name->setParent(this);
438 }
439
setTemplateArgumentList(TemplateArgumentListAST::Node & templateArgumentList)440 void ClassOrNamespaceNameAST::setTemplateArgumentList(TemplateArgumentListAST::Node& templateArgumentList)
441 {
442 m_templateArgumentList = std::move(templateArgumentList);
443 if (m_templateArgumentList.get()) m_templateArgumentList->setParent(this);
444 }
445
text() const446 QString ClassOrNamespaceNameAST::text() const
447 {
448 if (!m_name.get())
449 return QString();
450
451 QString str = m_name->text();
452 if (m_templateArgumentList.get())
453 str += QString::fromLatin1("< ") + m_templateArgumentList->text() + QString::fromLatin1(" >");
454
455 return str;
456 }
457
458 // ------------------------------------------------------------------------
TypeSpecifierAST()459 TypeSpecifierAST::TypeSpecifierAST()
460 {
461 }
462
setCvQualify(GroupAST::Node & cvQualify)463 void TypeSpecifierAST::setCvQualify(GroupAST::Node& cvQualify)
464 {
465 m_cvQualify = std::move(cvQualify);
466 if (m_cvQualify.get()) m_cvQualify->setParent(this);
467 }
468
setCv2Qualify(GroupAST::Node & cv2Qualify)469 void TypeSpecifierAST::setCv2Qualify(GroupAST::Node& cv2Qualify)
470 {
471 m_cv2Qualify = std::move(cv2Qualify);
472 if (m_cv2Qualify.get()) m_cv2Qualify->setParent(this);
473 }
474
text() const475 QString TypeSpecifierAST::text() const
476 {
477 QString str;
478
479 if (m_cvQualify.get())
480 str += m_cvQualify->text() + QLatin1Char(' ');
481
482 if (m_name.get())
483 str += m_name->text();
484
485 if (m_cv2Qualify.get())
486 str += QString::fromLatin1(" ") + m_cv2Qualify->text();
487
488 return str;
489 }
490
491 // ------------------------------------------------------------------------
ClassSpecifierAST()492 ClassSpecifierAST::ClassSpecifierAST()
493 {
494 }
495
setClassKey(AST::Node & classKey)496 void ClassSpecifierAST::setClassKey(AST::Node& classKey)
497 {
498 m_classKey = std::move(classKey);
499 if (m_classKey.get()) m_classKey->setParent(this);
500 }
501
addDeclaration(DeclarationAST::Node & declaration)502 void ClassSpecifierAST::addDeclaration(DeclarationAST::Node& declaration)
503 {
504 if (!declaration.get())
505 return;
506
507 declaration->setParent(this);
508 m_declarationList.append(declaration.release());
509 }
510
setBaseClause(BaseClauseAST::Node & baseClause)511 void ClassSpecifierAST::setBaseClause(BaseClauseAST::Node& baseClause)
512 {
513 m_baseClause = std::move(baseClause);
514 if (m_baseClause.get()) m_baseClause->setParent(this);
515 }
516
517 // ------------------------------------------------------------------------
EnumSpecifierAST()518 EnumSpecifierAST::EnumSpecifierAST()
519 {
520 m_isClass = false;
521 }
522
setClass(bool b)523 void EnumSpecifierAST::setClass(bool b)
524 {
525 m_isClass = b;
526 }
527
setEnumBase(TypeSpecifierAST::Node & enumBase)528 void EnumSpecifierAST::setEnumBase(TypeSpecifierAST::Node& enumBase)
529 {
530 m_enumBase = std::move(enumBase);
531 if (m_enumBase.get()) m_enumBase->setParent(this);
532 }
533
addEnumerator(EnumeratorAST::Node & enumerator)534 void EnumSpecifierAST::addEnumerator(EnumeratorAST::Node& enumerator)
535 {
536 if (!enumerator.get())
537 return;
538
539 enumerator->setParent(this);
540 m_enumeratorList.append(enumerator.release());
541 }
542
543
544 // ------------------------------------------------------------------------
ElaboratedTypeSpecifierAST()545 ElaboratedTypeSpecifierAST::ElaboratedTypeSpecifierAST()
546 {
547 }
548
setKind(AST::Node & kind)549 void ElaboratedTypeSpecifierAST::setKind(AST::Node& kind)
550 {
551 m_kind = std::move(kind);
552 if (m_kind.get()) m_kind->setParent(this);
553 }
554
text() const555 QString ElaboratedTypeSpecifierAST::text() const
556 {
557 if (m_kind.get())
558 return m_kind->text() + QLatin1Char(' ') + TypeSpecifierAST::text();
559
560 return TypeSpecifierAST::text();
561 }
562
563 // ------------------------------------------------------------------------
StatementAST()564 StatementAST::StatementAST()
565 {
566 }
567
568 // ------------------------------------------------------------------------
EnumeratorAST()569 EnumeratorAST::EnumeratorAST()
570 {
571 }
572
setId(AST::Node & id)573 void EnumeratorAST::setId(AST::Node& id)
574 {
575 m_id = std::move(id);
576 if (m_id.get()) m_id->setParent(this);
577 }
578
setExpr(AST::Node & expr)579 void EnumeratorAST::setExpr(AST::Node& expr)
580 {
581 m_expr = std::move(expr);
582 if (m_expr.get()) m_expr->setParent(this);
583 }
584
585 // ------------------------------------------------------------------------
BaseClauseAST()586 BaseClauseAST::BaseClauseAST()
587 {
588 }
589
addBaseSpecifier(BaseSpecifierAST::Node & baseSpecifier)590 void BaseClauseAST::addBaseSpecifier(BaseSpecifierAST::Node& baseSpecifier)
591 {
592 if (!baseSpecifier.get())
593 return;
594
595 baseSpecifier->setParent(this);
596 m_baseSpecifierList.append(baseSpecifier.release());
597 }
598
599 // ------------------------------------------------------------------------
BaseSpecifierAST()600 BaseSpecifierAST::BaseSpecifierAST()
601 {
602 }
603
setIsVirtual(AST::Node & isVirtual)604 void BaseSpecifierAST::setIsVirtual(AST::Node& isVirtual)
605 {
606 m_isVirtual = std::move(isVirtual);
607 if (m_isVirtual.get()) m_isVirtual->setParent(this);
608 }
609
setAccess(AST::Node & access)610 void BaseSpecifierAST::setAccess(AST::Node& access)
611 {
612 m_access = std::move(access);
613 if (m_access.get()) m_access->setParent(this);
614 }
615
setName(NameAST::Node & name)616 void BaseSpecifierAST::setName(NameAST::Node& name)
617 {
618 m_name = std::move(name);
619 if (m_name.get()) m_name->setParent(this);
620 }
621
622 // ------------------------------------------------------------------------
SimpleDeclarationAST()623 SimpleDeclarationAST::SimpleDeclarationAST()
624 {
625 }
626
setFunctionSpecifier(GroupAST::Node & functionSpecifier)627 void SimpleDeclarationAST::setFunctionSpecifier(GroupAST::Node& functionSpecifier)
628 {
629 m_functionSpecifier = std::move(functionSpecifier);
630 if (m_functionSpecifier.get()) m_functionSpecifier->setParent(this);
631 }
632
setStorageSpecifier(GroupAST::Node & storageSpecifier)633 void SimpleDeclarationAST::setStorageSpecifier(GroupAST::Node& storageSpecifier)
634 {
635 m_storageSpecifier = std::move(storageSpecifier);
636 if (m_storageSpecifier.get()) m_storageSpecifier->setParent(this);
637 }
638
setTypeSpec(TypeSpecifierAST::Node & typeSpec)639 void SimpleDeclarationAST::setTypeSpec(TypeSpecifierAST::Node& typeSpec)
640 {
641 m_typeSpec = std::move(typeSpec);
642 if (m_typeSpec.get()) m_typeSpec->setParent(this);
643 }
644
setInitDeclaratorList(InitDeclaratorListAST::Node & initDeclaratorList)645 void SimpleDeclarationAST::setInitDeclaratorList(InitDeclaratorListAST::Node& initDeclaratorList)
646 {
647 m_initDeclaratorList = std::move(initDeclaratorList);
648 if (m_initDeclaratorList.get()) m_initDeclaratorList->setParent(this);
649 }
650
setWinDeclSpec(GroupAST::Node & winDeclSpec)651 void SimpleDeclarationAST::setWinDeclSpec(GroupAST::Node& winDeclSpec)
652 {
653 m_winDeclSpec = std::move(winDeclSpec);
654 if (m_winDeclSpec.get()) m_winDeclSpec->setParent(this);
655 }
656
657
658 // ------------------------------------------------------------------------
InitDeclaratorListAST()659 InitDeclaratorListAST::InitDeclaratorListAST()
660 {
661 }
662
addInitDeclarator(InitDeclaratorAST::Node & decl)663 void InitDeclaratorListAST::addInitDeclarator(InitDeclaratorAST::Node& decl)
664 {
665 if (!decl.get())
666 return;
667
668 decl->setParent(this);
669 m_initDeclaratorList.append(decl.release());
670 }
671
672 // ------------------------------------------------------------------------
DeclaratorAST()673 DeclaratorAST::DeclaratorAST()
674 {
675 }
676
setSubDeclarator(DeclaratorAST::Node & subDeclarator)677 void DeclaratorAST::setSubDeclarator(DeclaratorAST::Node& subDeclarator)
678 {
679 m_subDeclarator = std::move(subDeclarator);
680 if (m_subDeclarator.get()) m_subDeclarator->setParent(this);
681 }
682
setDeclaratorId(NameAST::Node & declaratorId)683 void DeclaratorAST::setDeclaratorId(NameAST::Node& declaratorId)
684 {
685 m_declaratorId = std::move(declaratorId);
686 if (m_declaratorId.get()) m_declaratorId->setParent(this);
687 }
688
setBitfieldInitialization(AST::Node & bitfieldInitialization)689 void DeclaratorAST::setBitfieldInitialization(AST::Node& bitfieldInitialization)
690 {
691 m_bitfieldInitialization = std::move(bitfieldInitialization);
692 if (m_bitfieldInitialization.get()) m_bitfieldInitialization->setParent(this);
693 }
694
addArrayDimension(AST::Node & arrayDimension)695 void DeclaratorAST::addArrayDimension(AST::Node& arrayDimension)
696 {
697 if (!arrayDimension.get())
698 return;
699
700 arrayDimension->setParent(this);
701 m_arrayDimensionList.append(arrayDimension.release());
702 }
703
setParameterDeclarationClause(AUTO_PTR<class ParameterDeclarationClauseAST> & parameterDeclarationClause)704 void DeclaratorAST::setParameterDeclarationClause(AUTO_PTR<class ParameterDeclarationClauseAST>& parameterDeclarationClause)
705 {
706 m_parameterDeclarationClause = std::move(parameterDeclarationClause);
707 if (m_parameterDeclarationClause.get()) m_parameterDeclarationClause->setParent(this);
708 }
709
setConstant(AST::Node & constant)710 void DeclaratorAST::setConstant(AST::Node& constant)
711 {
712 m_constant = std::move(constant);
713 if (m_constant.get()) m_constant->setParent(this);
714 }
715
setOverride(AST::Node & override)716 void DeclaratorAST::setOverride(AST::Node& override)
717 {
718 m_override = std::move(override);
719 if (m_override.get()) m_override->setParent(this);
720 }
721
setExceptionSpecification(GroupAST::Node & exceptionSpecification)722 void DeclaratorAST::setExceptionSpecification(GroupAST::Node& exceptionSpecification)
723 {
724 m_exceptionSpecification = std::move(exceptionSpecification);
725 if (m_exceptionSpecification.get()) m_exceptionSpecification->setParent(this);
726 }
727
addPtrOp(AST::Node & ptrOp)728 void DeclaratorAST::addPtrOp(AST::Node& ptrOp)
729 {
730 if (!ptrOp.get())
731 return;
732
733 ptrOp->setParent(this);
734 m_ptrOpList.append(ptrOp.release());
735 }
736
737 // --------------------------------------------------------------------------
InitDeclaratorAST()738 InitDeclaratorAST::InitDeclaratorAST()
739 {
740 }
741
setDeclarator(DeclaratorAST::Node & declarator)742 void InitDeclaratorAST::setDeclarator(DeclaratorAST::Node& declarator)
743 {
744 m_declarator = std::move(declarator);
745 if (m_declarator.get()) m_declarator->setParent(this);
746 }
747
setInitializer(AST::Node & initializer)748 void InitDeclaratorAST::setInitializer(AST::Node& initializer)
749 {
750 m_initializer = std::move(initializer);
751 if (m_initializer.get()) m_initializer->setParent(this);
752 }
753
754 // --------------------------------------------------------------------------
FunctionDefinitionAST()755 FunctionDefinitionAST::FunctionDefinitionAST()
756 {
757 }
758
setFunctionSpecifier(GroupAST::Node & functionSpecifier)759 void FunctionDefinitionAST::setFunctionSpecifier(GroupAST::Node& functionSpecifier)
760 {
761 m_functionSpecifier = std::move(functionSpecifier);
762 if (m_functionSpecifier.get()) m_functionSpecifier->setParent(this);
763 }
764
setStorageSpecifier(GroupAST::Node & storageSpecifier)765 void FunctionDefinitionAST::setStorageSpecifier(GroupAST::Node& storageSpecifier)
766 {
767 m_storageSpecifier = std::move(storageSpecifier);
768 if (m_storageSpecifier.get()) m_storageSpecifier->setParent(this);
769 }
770
setTypeSpec(TypeSpecifierAST::Node & typeSpec)771 void FunctionDefinitionAST::setTypeSpec(TypeSpecifierAST::Node& typeSpec)
772 {
773 m_typeSpec = std::move(typeSpec);
774 if (m_typeSpec.get()) m_typeSpec->setParent(this);
775 }
776
setInitDeclarator(InitDeclaratorAST::Node & initDeclarator)777 void FunctionDefinitionAST::setInitDeclarator(InitDeclaratorAST::Node& initDeclarator)
778 {
779 m_initDeclarator = std::move(initDeclarator);
780 if (m_initDeclarator.get()) m_initDeclarator->setParent(this);
781 }
782
setFunctionBody(StatementListAST::Node & functionBody)783 void FunctionDefinitionAST::setFunctionBody(StatementListAST::Node& functionBody)
784 {
785 m_functionBody = std::move(functionBody);
786 if (m_functionBody.get()) m_functionBody->setParent(this);
787 }
788
setWinDeclSpec(GroupAST::Node & winDeclSpec)789 void FunctionDefinitionAST::setWinDeclSpec(GroupAST::Node& winDeclSpec)
790 {
791 m_winDeclSpec = std::move(winDeclSpec);
792 if (m_winDeclSpec.get()) m_winDeclSpec->setParent(this);
793 }
794
795 // --------------------------------------------------------------------------
StatementListAST()796 StatementListAST::StatementListAST()
797 {
798 }
799
addStatement(StatementAST::Node & statement)800 void StatementListAST::addStatement(StatementAST::Node& statement)
801 {
802 if (!statement.get())
803 return;
804
805 statement->setParent(this);
806 m_statementList.append(statement.release());
807 }
808
809 // --------------------------------------------------------------------------
IfStatementAST()810 IfStatementAST::IfStatementAST()
811 {
812 }
813
setCondition(ConditionAST::Node & condition)814 void IfStatementAST::setCondition(ConditionAST::Node& condition)
815 {
816 m_condition = std::move(condition);
817 if (m_condition.get()) m_condition->setParent(this);
818 }
819
setStatement(StatementAST::Node & statement)820 void IfStatementAST::setStatement(StatementAST::Node& statement)
821 {
822 m_statement = std::move(statement);
823 if (m_statement.get()) m_statement->setParent(this);
824 }
825
setElseStatement(StatementAST::Node & elseStatement)826 void IfStatementAST::setElseStatement(StatementAST::Node& elseStatement)
827 {
828 m_elseStatement = std::move(elseStatement);
829 if (m_elseStatement.get()) m_elseStatement->setParent(this);
830 }
831
832 // --------------------------------------------------------------------------
WhileStatementAST()833 WhileStatementAST::WhileStatementAST()
834 {
835 }
836
setCondition(ConditionAST::Node & condition)837 void WhileStatementAST::setCondition(ConditionAST::Node& condition)
838 {
839 m_condition = std::move(condition);
840 if (m_condition.get()) m_condition->setParent(this);
841 }
842
setStatement(StatementAST::Node & statement)843 void WhileStatementAST::setStatement(StatementAST::Node& statement)
844 {
845 m_statement = std::move(statement);
846 if (m_statement.get()) m_statement->setParent(this);
847 }
848
849 // --------------------------------------------------------------------------
DoStatementAST()850 DoStatementAST::DoStatementAST()
851 {
852 }
853
setCondition(ConditionAST::Node & condition)854 void DoStatementAST::setCondition(ConditionAST::Node& condition)
855 {
856 m_condition = std::move(condition);
857 if (m_condition.get()) m_condition->setParent(this);
858 }
859
setStatement(StatementAST::Node & statement)860 void DoStatementAST::setStatement(StatementAST::Node& statement)
861 {
862 m_statement = std::move(statement);
863 if (m_statement.get()) m_statement->setParent(this);
864 }
865
866 // --------------------------------------------------------------------------
ForStatementAST()867 ForStatementAST::ForStatementAST()
868 {
869 }
870
setCondition(ConditionAST::Node & condition)871 void ForStatementAST::setCondition(ConditionAST::Node& condition)
872 {
873 m_condition = std::move(condition);
874 if (m_condition.get()) m_condition->setParent(this);
875 }
876
setExpression(AST::Node & expression)877 void ForStatementAST::setExpression(AST::Node& expression)
878 {
879 m_expression = std::move(expression);
880 if (m_expression.get()) m_expression->setParent(this);
881 }
882
setStatement(StatementAST::Node & statement)883 void ForStatementAST::setStatement(StatementAST::Node& statement)
884 {
885 m_statement = std::move(statement);
886 if (m_statement.get()) m_statement->setParent(this);
887 }
888
setInitStatement(StatementAST::Node & initStatement)889 void ForStatementAST::setInitStatement(StatementAST::Node& initStatement)
890 {
891 m_initStatement = std::move(initStatement);
892 if (m_initStatement.get()) m_initStatement->setParent(this);
893 }
894
895 // --------------------------------------------------------------------------
ForEachStatementAST()896 ForEachStatementAST::ForEachStatementAST()
897 {
898 }
899
setExpression(AST::Node & expression)900 void ForEachStatementAST::setExpression(AST::Node& expression)
901 {
902 m_expression = std::move(expression);
903 if (m_expression.get()) m_expression->setParent(this);
904 }
905
setStatement(StatementAST::Node & statement)906 void ForEachStatementAST::setStatement(StatementAST::Node& statement)
907 {
908 m_statement = std::move(statement);
909 if (m_statement.get()) m_statement->setParent(this);
910 }
911
setInitStatement(StatementAST::Node & initStatement)912 void ForEachStatementAST::setInitStatement(StatementAST::Node& initStatement)
913 {
914 m_initStatement = std::move(initStatement);
915 if (m_initStatement.get()) m_initStatement->setParent(this);
916 }
917
918 // --------------------------------------------------------------------------
SwitchStatementAST()919 SwitchStatementAST::SwitchStatementAST()
920 {
921 }
922
setCondition(ConditionAST::Node & condition)923 void SwitchStatementAST::setCondition(ConditionAST::Node& condition)
924 {
925 m_condition = std::move(condition);
926 if (m_condition.get()) m_condition->setParent(this);
927 }
928
setStatement(StatementAST::Node & statement)929 void SwitchStatementAST::setStatement(StatementAST::Node& statement)
930 {
931 m_statement = std::move(statement);
932 if (m_statement.get()) m_statement->setParent(this);
933 }
934
935 // --------------------------------------------------------------------------
CatchStatementListAST()936 CatchStatementListAST::CatchStatementListAST()
937 {
938 }
939
addStatement(CatchStatementAST::Node & statement)940 void CatchStatementListAST::addStatement(CatchStatementAST::Node& statement)
941 {
942 if (!statement.get())
943 return;
944
945 statement->setParent(this);
946 m_statementList.append(statement.release());
947 }
948
949 // --------------------------------------------------------------------------
CatchStatementAST()950 CatchStatementAST::CatchStatementAST()
951 {
952 }
953
setCondition(ConditionAST::Node & condition)954 void CatchStatementAST::setCondition(ConditionAST::Node& condition)
955 {
956 m_condition = std::move(condition);
957 if (m_condition.get()) m_condition->setParent(this);
958 }
959
setStatement(StatementAST::Node & statement)960 void CatchStatementAST::setStatement(StatementAST::Node& statement)
961 {
962 m_statement = std::move(statement);
963 if (m_statement.get()) m_statement->setParent(this);
964 }
965
966 // --------------------------------------------------------------------------
TryBlockStatementAST()967 TryBlockStatementAST::TryBlockStatementAST()
968 {
969 }
970
setStatement(StatementAST::Node & statement)971 void TryBlockStatementAST::setStatement(StatementAST::Node& statement)
972 {
973 m_statement = std::move(statement);
974 if (m_statement.get()) m_statement->setParent(this);
975 }
976
setCatchStatementList(CatchStatementListAST::Node & statementList)977 void TryBlockStatementAST::setCatchStatementList(CatchStatementListAST::Node& statementList)
978 {
979 m_catchStatementList = std::move(statementList);
980 if (m_catchStatementList.get()) m_catchStatementList->setParent(this);
981 }
982
983 // --------------------------------------------------------------------------
DeclarationStatementAST()984 DeclarationStatementAST::DeclarationStatementAST()
985 {
986 }
987
setDeclaration(DeclarationAST::Node & declaration)988 void DeclarationStatementAST::setDeclaration(DeclarationAST::Node& declaration)
989 {
990 m_declaration = std::move(declaration);
991 if (m_declaration.get()) m_declaration->setParent(this);
992 }
993
994 // --------------------------------------------------------------------------
ExpressionStatementAST()995 ExpressionStatementAST::ExpressionStatementAST()
996 {
997 }
998
setExpression(AST::Node & expression)999 void ExpressionStatementAST::setExpression(AST::Node& expression)
1000 {
1001 m_expression = std::move(expression);
1002 if (m_expression.get()) m_expression->setParent(this);
1003 }
1004
1005
1006 // --------------------------------------------------------------------------
ParameterDeclarationAST()1007 ParameterDeclarationAST::ParameterDeclarationAST()
1008 {
1009 }
1010
setTypeSpec(TypeSpecifierAST::Node & typeSpec)1011 void ParameterDeclarationAST::setTypeSpec(TypeSpecifierAST::Node& typeSpec)
1012 {
1013 m_typeSpec = std::move(typeSpec);
1014 if (m_typeSpec.get()) m_typeSpec->setParent(this);
1015 }
1016
setDeclarator(DeclaratorAST::Node & declarator)1017 void ParameterDeclarationAST::setDeclarator(DeclaratorAST::Node& declarator)
1018 {
1019 m_declarator = std::move(declarator);
1020 if (m_declarator.get()) m_declarator->setParent(this);
1021 }
1022
setExpression(AST::Node & expression)1023 void ParameterDeclarationAST::setExpression(AST::Node& expression)
1024 {
1025 m_expression = std::move(expression);
1026 if (m_expression.get()) m_expression->setParent(this);
1027 }
1028
text() const1029 QString ParameterDeclarationAST::text() const
1030 {
1031 QString str;
1032 if (m_typeSpec.get())
1033 str += m_typeSpec->text() + QLatin1Char(' ');
1034
1035 if (m_declarator.get())
1036 str += m_declarator->text();
1037
1038 if (m_expression.get())
1039 str += QString::fromLatin1(" = ") + m_expression->text();
1040
1041 return str;
1042 }
1043
1044 // --------------------------------------------------------------------------
ParameterDeclarationListAST()1045 ParameterDeclarationListAST::ParameterDeclarationListAST()
1046 {
1047 }
1048
addParameter(ParameterDeclarationAST::Node & parameter)1049 void ParameterDeclarationListAST::addParameter(ParameterDeclarationAST::Node& parameter)
1050 {
1051 if (!parameter.get())
1052 return;
1053
1054 parameter->setParent(this);
1055 m_parameterList.append(parameter.release());
1056 }
1057
text() const1058 QString ParameterDeclarationListAST::text() const
1059 {
1060 QStringList l;
1061 for (int i = 0; i < m_parameterList.size(); ++i) {
1062 l.append(m_parameterList.at(i)->text());
1063 }
1064 return l.join(QLatin1String(", "));
1065 }
1066
1067
1068 // --------------------------------------------------------------------------
ParameterDeclarationClauseAST()1069 ParameterDeclarationClauseAST::ParameterDeclarationClauseAST()
1070 {
1071 }
1072
setParameterDeclarationList(ParameterDeclarationListAST::Node & parameterDeclarationList)1073 void ParameterDeclarationClauseAST::setParameterDeclarationList(ParameterDeclarationListAST::Node& parameterDeclarationList)
1074 {
1075 m_parameterDeclarationList = std::move(parameterDeclarationList);
1076 if (m_parameterDeclarationList.get()) m_parameterDeclarationList->setParent(this);
1077 }
1078
setEllipsis(AST::Node & ellipsis)1079 void ParameterDeclarationClauseAST::setEllipsis(AST::Node& ellipsis)
1080 {
1081 m_ellipsis = std::move(ellipsis);
1082 if (m_ellipsis.get()) m_ellipsis->setParent(this);
1083 }
1084
text() const1085 QString ParameterDeclarationClauseAST::text() const
1086 {
1087 QString str;
1088
1089 if (m_parameterDeclarationList.get())
1090 str += m_parameterDeclarationList->text();
1091
1092 if (m_ellipsis.get())
1093 str += QLatin1String(" ...");
1094
1095 return str;
1096 }
1097
1098
1099 // --------------------------------------------------------------------------
GroupAST()1100 GroupAST::GroupAST()
1101 {
1102 }
1103
addNode(AST::Node & node)1104 void GroupAST::addNode(AST::Node& node)
1105 {
1106 if (!node.get())
1107 return;
1108
1109 node->setParent(this);
1110 m_nodeList.append(node.release());
1111 }
1112
text() const1113 QString GroupAST::text() const
1114 {
1115 QStringList l;
1116 for (int i = 0; i < m_nodeList.size(); ++i) {
1117 l.append(m_nodeList.at(i)->text());
1118 }
1119 return l.join(QLatin1String(" "));
1120 }
1121
1122 // --------------------------------------------------------------------------
AccessDeclarationAST()1123 AccessDeclarationAST::AccessDeclarationAST()
1124 {
1125 }
1126
addAccess(AST::Node & access)1127 void AccessDeclarationAST::addAccess(AST::Node& access)
1128 {
1129 if (!access.get())
1130 return;
1131
1132 access->setParent(this);
1133 m_accessList.append(access.release());
1134 }
1135
text() const1136 QString AccessDeclarationAST::text() const
1137 {
1138 QStringList l;
1139 for (int i = 0; i < m_accessList.size(); ++i) {
1140 l.append(m_accessList.at(i)->text());
1141 }
1142 return l.join(QLatin1String(" "));
1143 }
1144
1145 // --------------------------------------------------------------------------
TypeParameterAST()1146 TypeParameterAST::TypeParameterAST()
1147 {
1148 }
1149
setKind(AST::Node & kind)1150 void TypeParameterAST::setKind(AST::Node& kind)
1151 {
1152 m_kind = std::move(kind);
1153 if (m_kind.get()) m_kind->setParent(this);
1154 }
1155
setTemplateParameterList(AUTO_PTR<class TemplateParameterListAST> & templateParameterList)1156 void TypeParameterAST::setTemplateParameterList(AUTO_PTR<class TemplateParameterListAST>& templateParameterList)
1157 {
1158 m_templateParameterList = std::move(templateParameterList);
1159 if (m_templateParameterList.get()) m_templateParameterList->setParent(this);
1160 }
1161
setName(NameAST::Node & name)1162 void TypeParameterAST::setName(NameAST::Node& name)
1163 {
1164 m_name = std::move(name);
1165 if (m_name.get()) m_name->setParent(this);
1166 }
1167
setTypeId(AST::Node & typeId)1168 void TypeParameterAST::setTypeId(AST::Node& typeId)
1169 {
1170 m_typeId = std::move(typeId);
1171 if (m_typeId.get()) m_typeId->setParent(this);
1172 }
1173
1174 // --------------------------------------------------------------------------
TemplateParameterAST()1175 TemplateParameterAST::TemplateParameterAST()
1176 {
1177 }
1178
setTypeParameter(TypeParameterAST::Node & typeParameter)1179 void TemplateParameterAST::setTypeParameter(TypeParameterAST::Node& typeParameter)
1180 {
1181 m_typeParameter = std::move(typeParameter);
1182 if (m_typeParameter.get()) m_typeParameter->setParent(this);
1183 }
1184
setTypeValueParameter(ParameterDeclarationAST::Node & typeValueParameter)1185 void TemplateParameterAST::setTypeValueParameter(ParameterDeclarationAST::Node& typeValueParameter)
1186 {
1187 m_typeValueParameter = std::move(typeValueParameter);
1188 if (m_typeValueParameter.get()) m_typeValueParameter->setParent(this);
1189 }
1190
1191 // --------------------------------------------------------------------------
TemplateParameterListAST()1192 TemplateParameterListAST::TemplateParameterListAST()
1193 {
1194 }
1195
addTemplateParameter(TemplateParameterAST::Node & templateParameter)1196 void TemplateParameterListAST::addTemplateParameter(TemplateParameterAST::Node& templateParameter)
1197 {
1198 if (!templateParameter.get())
1199 return;
1200
1201 templateParameter->setParent(this);
1202 m_templateParameterList.append(templateParameter.release());
1203 }
1204
1205 // --------------------------------------------------------------------------
ConditionAST()1206 ConditionAST::ConditionAST()
1207 {
1208 }
1209
setTypeSpec(TypeSpecifierAST::Node & typeSpec)1210 void ConditionAST::setTypeSpec(TypeSpecifierAST::Node& typeSpec)
1211 {
1212 m_typeSpec = std::move(typeSpec);
1213 if (m_typeSpec.get()) m_typeSpec->setParent(this);
1214 }
1215
setDeclarator(DeclaratorAST::Node & declarator)1216 void ConditionAST::setDeclarator(DeclaratorAST::Node& declarator)
1217 {
1218 m_declarator = std::move(declarator);
1219 if (m_declarator.get()) m_declarator->setParent(this);
1220 }
1221
setExpression(AST::Node & expression)1222 void ConditionAST::setExpression(AST::Node& expression)
1223 {
1224 m_expression = std::move(expression);
1225 if (m_expression.get()) m_expression->setParent(this);
1226 }
1227
setWinDeclSpec(GroupAST::Node & winDeclSpec)1228 void ClassSpecifierAST::setWinDeclSpec(GroupAST::Node & winDeclSpec)
1229 {
1230 m_winDeclSpec = std::move(winDeclSpec);
1231 if (m_winDeclSpec.get()) m_winDeclSpec->setParent(this);
1232 }
1233