support for creating template instance classes
[lqt/mk.git] / cpptoxml / parser / ast.h
blobc213b216e6396ccc1261289e707f34aa526aec1f
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 ** Copyright (C) 2002-2005 Roberto Raggi <roberto@kdevelop.org>
5 **
6 ** This file is part of the Qt Script Generator project on Trolltech Labs.
7 **
8 ** This file may be used under the terms of the GNU General Public
9 ** License version 2.0 as published by the Free Software Foundation
10 ** and appearing in the file LICENSE.GPL included in the packaging of
11 ** this file. Please review the following information to ensure GNU
12 ** General Public Licensing requirements will be met:
13 ** http://www.trolltech.com/products/qt/opensource.html
15 ** If you are unsure which license is appropriate for your use, please
16 ** review the following information:
17 ** http://www.trolltech.com/products/qt/licensing.html or contact the
18 ** sales department at sales@trolltech.com.
20 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 ****************************************************************************/
26 #ifndef AST_H
27 #define AST_H
29 #include "smallobject.h"
30 #include "list.h"
32 class QString;
34 #define DECLARE_AST_NODE(k) \
35 enum { __node_kind = Kind_##k };
37 class TokenStream;
39 struct AccessSpecifierAST;
40 struct AsmDefinitionAST;
41 struct BaseClauseAST;
42 struct BaseSpecifierAST;
43 struct BinaryExpressionAST;
44 struct CastExpressionAST;
45 struct ClassMemberAccessAST;
46 struct ClassSpecifierAST;
47 struct CompoundStatementAST;
48 struct ConditionAST;
49 struct ConditionalExpressionAST;
50 struct CppCastExpressionAST;
51 struct CtorInitializerAST;
52 struct DeclarationAST;
53 struct DeclarationStatementAST;
54 struct DeclaratorAST;
55 struct DeleteExpressionAST;
56 struct DoStatementAST;
57 struct ElaboratedTypeSpecifierAST;
58 struct EnumSpecifierAST;
59 struct EnumeratorAST;
60 struct ExceptionSpecificationAST;
61 struct ExpressionAST;
62 struct ExpressionOrDeclarationStatementAST;
63 struct ExpressionStatementAST;
64 struct ForStatementAST;
65 struct FunctionCallAST;
66 struct FunctionDefinitionAST;
67 struct IfStatementAST;
68 struct IncrDecrExpressionAST;
69 struct InitDeclaratorAST;
70 struct InitializerAST;
71 struct InitializerClauseAST;
72 struct LabeledStatementAST;
73 struct LinkageBodyAST;
74 struct LinkageSpecificationAST;
75 struct MemInitializerAST;
76 struct NameAST;
77 struct NamespaceAST;
78 struct NamespaceAliasDefinitionAST;
79 struct NewDeclaratorAST;
80 struct NewExpressionAST;
81 struct NewInitializerAST;
82 struct NewTypeIdAST;
83 struct OperatorAST;
84 struct OperatorFunctionIdAST;
85 struct ParameterDeclarationAST;
86 struct ParameterDeclarationClauseAST;
87 struct PostfixExpressionAST;
88 struct PrimaryExpressionAST;
89 struct PtrOperatorAST;
90 struct PtrToMemberAST;
91 struct ReturnStatementAST;
92 struct SimpleDeclarationAST;
93 struct SimpleTypeSpecifierAST;
94 struct SizeofExpressionAST;
95 struct StatementAST;
96 struct StringLiteralAST;
97 struct SubscriptExpressionAST;
98 struct SwitchStatementAST;
99 struct TemplateArgumentAST;
100 struct TemplateDeclarationAST;
101 struct TemplateParameterAST;
102 struct ThrowExpressionAST;
103 struct TranslationUnitAST;
104 struct TryBlockStatementAST;
105 struct TypeIdAST;
106 struct TypeIdentificationAST;
107 struct TypeParameterAST;
108 struct TypeSpecifierAST;
109 struct TypedefAST;
110 struct UnaryExpressionAST;
111 struct UnqualifiedNameAST;
112 struct UsingAST;
113 struct UsingDirectiveAST;
114 struct WhileStatementAST;
115 struct WinDeclSpecAST;
116 struct QPropertyAST;
117 struct QEnumsAST;
119 struct AST
121 enum NODE_KIND
123 Kind_UNKNOWN = 0,
125 Kind_AccessSpecifier,
126 Kind_AsmDefinition,
127 Kind_BaseClause,
128 Kind_BaseSpecifier,
129 Kind_BinaryExpression,
130 Kind_CastExpression,
131 Kind_ClassMemberAccess,
132 Kind_ClassSpecifier,
133 Kind_CompoundStatement,
134 Kind_Condition,
135 Kind_ConditionalExpression,
136 Kind_CppCastExpression,
137 Kind_CtorInitializer,
138 Kind_DeclarationStatement,
139 Kind_Declarator,
140 Kind_DeleteExpression,
141 Kind_DoStatement,
142 Kind_ElaboratedTypeSpecifier,
143 Kind_EnumSpecifier,
144 Kind_Enumerator,
145 Kind_ExceptionSpecification,
146 Kind_ExpressionOrDeclarationStatement,
147 Kind_ExpressionStatement,
148 Kind_ForStatement,
149 Kind_FunctionCall,
150 Kind_FunctionDefinition,
151 Kind_IfStatement,
152 Kind_IncrDecrExpression,
153 Kind_InitDeclarator,
154 Kind_Initializer,
155 Kind_InitializerClause,
156 Kind_LabeledStatement,
157 Kind_LinkageBody,
158 Kind_LinkageSpecification,
159 Kind_MemInitializer,
160 Kind_Name,
161 Kind_Namespace,
162 Kind_NamespaceAliasDefinition,
163 Kind_NewDeclarator,
164 Kind_NewExpression,
165 Kind_NewInitializer,
166 Kind_NewTypeId,
167 Kind_Operator,
168 Kind_OperatorFunctionId,
169 Kind_ParameterDeclaration,
170 Kind_ParameterDeclarationClause,
171 Kind_PostfixExpression,
172 Kind_PrimaryExpression,
173 Kind_PtrOperator,
174 Kind_PtrToMember,
175 Kind_ReturnStatement,
176 Kind_SimpleDeclaration,
177 Kind_SimpleTypeSpecifier,
178 Kind_SizeofExpression,
179 Kind_StringLiteral,
180 Kind_SubscriptExpression,
181 Kind_SwitchStatement,
182 Kind_TemplateArgument,
183 Kind_TemplateDeclaration,
184 Kind_TemplateParameter,
185 Kind_ThrowExpression,
186 Kind_TranslationUnit,
187 Kind_TryBlockStatement,
188 Kind_TypeId,
189 Kind_TypeIdentification,
190 Kind_TypeParameter,
191 Kind_Typedef,
192 Kind_UnaryExpression,
193 Kind_UnqualifiedName,
194 Kind_Using,
195 Kind_UsingDirective,
196 Kind_WhileStatement,
197 Kind_WinDeclSpec,
198 Kind_QPropertyAST,
199 Kind_ForwardDeclarationSpecifier,
200 Kind_QEnumsAST,
202 NODE_KIND_COUNT
205 QString toString(TokenStream *stream) const;
207 int kind;
209 std::size_t start_token;
210 std::size_t end_token;
213 struct TypeSpecifierAST: public AST
215 const ListNode<std::size_t> *cv;
218 struct StatementAST: public AST
222 struct ExpressionAST: public AST
226 struct DeclarationAST: public AST
230 struct AccessSpecifierAST: public DeclarationAST
232 DECLARE_AST_NODE(AccessSpecifier)
234 const ListNode<std::size_t> *specs;
237 struct AsmDefinitionAST: public DeclarationAST
239 DECLARE_AST_NODE(AsmDefinition)
241 const ListNode<std::size_t> *cv;
244 struct BaseClauseAST: public AST // ### kill me
246 DECLARE_AST_NODE(BaseClause)
248 const ListNode<BaseSpecifierAST*> *base_specifiers;
251 struct BaseSpecifierAST: public AST
253 DECLARE_AST_NODE(BaseSpecifier)
255 std::size_t virt;
256 std::size_t access_specifier;
257 NameAST *name;
260 struct BinaryExpressionAST: public ExpressionAST
262 DECLARE_AST_NODE(BinaryExpression)
264 std::size_t op;
265 ExpressionAST *left_expression;
266 ExpressionAST *right_expression;
269 struct CastExpressionAST: public ExpressionAST
271 DECLARE_AST_NODE(CastExpression)
273 TypeIdAST *type_id;
274 ExpressionAST *expression;
277 struct ClassMemberAccessAST: public ExpressionAST
279 DECLARE_AST_NODE(ClassMemberAccess)
281 std::size_t op;
282 NameAST *name;
285 struct ClassSpecifierAST: public TypeSpecifierAST
287 DECLARE_AST_NODE(ClassSpecifier)
289 WinDeclSpecAST *win_decl_specifiers;
290 std::size_t class_key;
291 NameAST *name;
292 BaseClauseAST *base_clause;
293 const ListNode<DeclarationAST*> *member_specs;
296 struct ForwardDeclarationSpecifierAST: public TypeSpecifierAST
298 DECLARE_AST_NODE(ForwardDeclarationSpecifier)
300 std::size_t class_key;
301 NameAST *name;
302 BaseClauseAST *base_clause;
305 struct CompoundStatementAST: public StatementAST
307 DECLARE_AST_NODE(CompoundStatement)
309 const ListNode<StatementAST*> *statements;
312 struct ConditionAST: public AST
314 DECLARE_AST_NODE(Condition)
316 TypeSpecifierAST *type_specifier;
317 DeclaratorAST *declarator;
318 ExpressionAST *expression;
321 struct ConditionalExpressionAST: public ExpressionAST
323 DECLARE_AST_NODE(ConditionalExpression)
325 ExpressionAST *condition;
326 ExpressionAST *left_expression;
327 ExpressionAST *right_expression;
330 struct CppCastExpressionAST: public ExpressionAST
332 DECLARE_AST_NODE(CppCastExpression)
334 std::size_t op;
335 TypeIdAST *type_id;
336 ExpressionAST *expression;
337 const ListNode<ExpressionAST*> *sub_expressions;
340 struct CtorInitializerAST: public AST
342 DECLARE_AST_NODE(CtorInitializer)
344 std::size_t colon;
345 const ListNode<MemInitializerAST*> *member_initializers;
348 struct DeclarationStatementAST: public StatementAST
350 DECLARE_AST_NODE(DeclarationStatement)
352 DeclarationAST *declaration;
355 struct DeclaratorAST: public AST
357 DECLARE_AST_NODE(Declarator)
359 const ListNode<PtrOperatorAST*> *ptr_ops;
360 DeclaratorAST *sub_declarator;
361 NameAST *id;
362 ExpressionAST *bit_expression;
363 const ListNode<ExpressionAST*> *array_dimensions;
364 ParameterDeclarationClauseAST *parameter_declaration_clause;
365 const ListNode<std::size_t> *fun_cv;
366 ExceptionSpecificationAST *exception_spec;
369 struct DeleteExpressionAST: public ExpressionAST
371 DECLARE_AST_NODE(DeleteExpression)
373 std::size_t scope_token;
374 std::size_t delete_token;
375 std::size_t lbracket_token;
376 std::size_t rbracket_token;
377 ExpressionAST *expression;
380 struct DoStatementAST: public StatementAST
382 DECLARE_AST_NODE(DoStatement)
384 StatementAST *statement;
385 ExpressionAST *expression;
388 struct ElaboratedTypeSpecifierAST: public TypeSpecifierAST
390 DECLARE_AST_NODE(ElaboratedTypeSpecifier)
392 std::size_t type;
393 NameAST *name;
396 struct EnumSpecifierAST: public TypeSpecifierAST
398 DECLARE_AST_NODE(EnumSpecifier)
400 NameAST *name;
401 const ListNode<EnumeratorAST*> *enumerators;
404 struct EnumeratorAST: public AST
406 DECLARE_AST_NODE(Enumerator)
408 std::size_t id;
409 ExpressionAST *expression;
412 struct ExceptionSpecificationAST: public AST
414 DECLARE_AST_NODE(ExceptionSpecification)
416 std::size_t ellipsis;
417 const ListNode<TypeIdAST*> *type_ids;
420 struct ExpressionOrDeclarationStatementAST: public StatementAST
422 DECLARE_AST_NODE(ExpressionOrDeclarationStatement)
424 StatementAST *expression;
425 StatementAST *declaration;
428 struct ExpressionStatementAST: public StatementAST
430 DECLARE_AST_NODE(ExpressionStatement)
432 ExpressionAST *expression;
435 struct FunctionCallAST: public ExpressionAST
437 DECLARE_AST_NODE(FunctionCall)
439 ExpressionAST *arguments;
442 struct FunctionDefinitionAST: public DeclarationAST
444 DECLARE_AST_NODE(FunctionDefinition)
446 const ListNode<std::size_t> *storage_specifiers;
447 const ListNode<std::size_t> *function_specifiers;
448 TypeSpecifierAST *type_specifier;
449 InitDeclaratorAST *init_declarator;
450 StatementAST *function_body;
451 WinDeclSpecAST *win_decl_specifiers;
454 struct ForStatementAST: public StatementAST
456 DECLARE_AST_NODE(ForStatement)
458 StatementAST *init_statement;
459 ConditionAST *condition;
460 ExpressionAST *expression;
461 StatementAST *statement;
464 struct IfStatementAST: public StatementAST
466 DECLARE_AST_NODE(IfStatement)
468 ConditionAST *condition;
469 StatementAST *statement;
470 StatementAST *else_statement;
473 struct IncrDecrExpressionAST: public ExpressionAST
475 DECLARE_AST_NODE(IncrDecrExpression)
477 std::size_t op;
480 struct InitDeclaratorAST: public AST
482 DECLARE_AST_NODE(InitDeclarator)
484 DeclaratorAST *declarator;
485 InitializerAST *initializer;
488 struct InitializerAST: public AST
490 DECLARE_AST_NODE(Initializer)
492 InitializerClauseAST *initializer_clause;
493 ExpressionAST *expression;
496 struct InitializerClauseAST: public AST
498 DECLARE_AST_NODE(InitializerClause)
500 ExpressionAST *expression;
503 struct LabeledStatementAST: public StatementAST
505 DECLARE_AST_NODE(LabeledStatement)
508 struct LinkageBodyAST: public AST
510 DECLARE_AST_NODE(LinkageBody)
512 const ListNode<DeclarationAST*> *declarations;
515 struct LinkageSpecificationAST: public DeclarationAST
517 DECLARE_AST_NODE(LinkageSpecification)
519 std::size_t extern_type;
520 LinkageBodyAST *linkage_body;
521 DeclarationAST *declaration;
524 struct MemInitializerAST: public AST
526 DECLARE_AST_NODE(MemInitializer)
528 NameAST *initializer_id;
529 ExpressionAST *expression;
532 struct NameAST: public AST
534 DECLARE_AST_NODE(Name)
536 bool global;
537 const ListNode<UnqualifiedNameAST*> *qualified_names;
538 UnqualifiedNameAST *unqualified_name;
541 struct NamespaceAST: public DeclarationAST
543 DECLARE_AST_NODE(Namespace)
545 std::size_t namespace_name;
546 LinkageBodyAST *linkage_body;
549 struct NamespaceAliasDefinitionAST: public DeclarationAST
551 DECLARE_AST_NODE(NamespaceAliasDefinition)
553 std::size_t namespace_name;
554 NameAST *alias_name;
557 struct NewDeclaratorAST: public AST
559 DECLARE_AST_NODE(NewDeclarator)
561 PtrOperatorAST *ptr_op;
562 NewDeclaratorAST *sub_declarator;
563 const ListNode<ExpressionAST*> *expressions;
566 struct NewExpressionAST: public ExpressionAST
568 DECLARE_AST_NODE(NewExpression)
570 std::size_t scope_token;
571 std::size_t new_token;
572 ExpressionAST *expression;
573 TypeIdAST *type_id;
574 NewTypeIdAST *new_type_id;
575 NewInitializerAST *new_initializer;
578 struct NewInitializerAST: public AST
580 DECLARE_AST_NODE(NewInitializer)
582 ExpressionAST *expression;
585 struct NewTypeIdAST: public AST
587 DECLARE_AST_NODE(NewTypeId)
589 TypeSpecifierAST *type_specifier;
590 NewInitializerAST *new_initializer;
591 NewDeclaratorAST *new_declarator;
594 struct OperatorAST: public AST
596 DECLARE_AST_NODE(Operator)
598 std::size_t op;
599 std::size_t open;
600 std::size_t close;
603 struct OperatorFunctionIdAST: public AST
605 DECLARE_AST_NODE(OperatorFunctionId)
607 OperatorAST *op;
608 TypeSpecifierAST *type_specifier;
609 const ListNode<PtrOperatorAST*> *ptr_ops;
612 struct ParameterDeclarationAST: public AST
614 DECLARE_AST_NODE(ParameterDeclaration)
616 TypeSpecifierAST *type_specifier;
617 DeclaratorAST *declarator;
618 ExpressionAST *expression;
621 struct ParameterDeclarationClauseAST: public AST
623 DECLARE_AST_NODE(ParameterDeclarationClause)
625 const ListNode<ParameterDeclarationAST*> *parameter_declarations;
626 std::size_t ellipsis;
629 struct PostfixExpressionAST: public ExpressionAST
631 DECLARE_AST_NODE(PostfixExpression)
633 TypeSpecifierAST *type_specifier;
634 ExpressionAST *expression;
635 const ListNode<ExpressionAST*> *sub_expressions;
638 struct PrimaryExpressionAST: public ExpressionAST
640 DECLARE_AST_NODE(PrimaryExpression)
642 StringLiteralAST *literal;
643 std::size_t token;
644 StatementAST *expression_statement;
645 ExpressionAST *sub_expression;
646 NameAST *name;
649 struct PtrOperatorAST: public AST
651 DECLARE_AST_NODE(PtrOperator)
653 const ListNode<std::size_t> *cv;
654 std::size_t op;
655 PtrToMemberAST *mem_ptr;
658 struct PtrToMemberAST: public AST
660 DECLARE_AST_NODE(PtrToMember)
663 struct ReturnStatementAST: public StatementAST
665 DECLARE_AST_NODE(ReturnStatement)
667 ExpressionAST *expression;
670 struct SimpleDeclarationAST: public DeclarationAST
672 DECLARE_AST_NODE(SimpleDeclaration)
674 const ListNode<std::size_t> *storage_specifiers;
675 const ListNode<std::size_t> *function_specifiers;
676 TypeSpecifierAST *type_specifier;
677 const ListNode<InitDeclaratorAST*> *init_declarators;
678 WinDeclSpecAST *win_decl_specifiers;
681 struct SimpleTypeSpecifierAST: public TypeSpecifierAST
683 DECLARE_AST_NODE(SimpleTypeSpecifier)
685 const ListNode<std::size_t> *integrals;
686 std::size_t type_of;
687 TypeIdAST *type_id;
688 ExpressionAST *expression;
689 NameAST *name;
692 struct SizeofExpressionAST: public ExpressionAST
694 DECLARE_AST_NODE(SizeofExpression)
696 std::size_t sizeof_token;
697 TypeIdAST *type_id;
698 ExpressionAST *expression;
701 struct StringLiteralAST: public AST
703 DECLARE_AST_NODE(StringLiteral)
705 const ListNode<std::size_t> *literals;
708 struct SubscriptExpressionAST: public ExpressionAST
710 DECLARE_AST_NODE(SubscriptExpression)
712 ExpressionAST *subscript;
715 struct SwitchStatementAST: public StatementAST
717 DECLARE_AST_NODE(SwitchStatement)
719 ConditionAST *condition;
720 StatementAST *statement;
723 struct TemplateArgumentAST: public AST
725 DECLARE_AST_NODE(TemplateArgument)
727 TypeIdAST *type_id;
728 ExpressionAST *expression;
731 struct TemplateDeclarationAST: public DeclarationAST
733 DECLARE_AST_NODE(TemplateDeclaration)
735 std::size_t exported;
736 const ListNode<TemplateParameterAST*> *template_parameters;
737 DeclarationAST* declaration;
740 struct TemplateParameterAST: public AST
742 DECLARE_AST_NODE(TemplateParameter)
744 TypeParameterAST *type_parameter;
745 ParameterDeclarationAST *parameter_declaration;
748 struct ThrowExpressionAST: public ExpressionAST
750 DECLARE_AST_NODE(ThrowExpression)
752 std::size_t throw_token;
753 ExpressionAST *expression;
756 struct TranslationUnitAST: public AST
758 DECLARE_AST_NODE(TranslationUnit)
760 const ListNode<DeclarationAST*> *declarations;
763 struct TryBlockStatementAST: public StatementAST
765 DECLARE_AST_NODE(TryBlockStatement)
768 struct TypeIdAST: public AST
770 DECLARE_AST_NODE(TypeId)
772 TypeSpecifierAST *type_specifier;
773 DeclaratorAST *declarator;
776 struct TypeIdentificationAST: public ExpressionAST
778 DECLARE_AST_NODE(TypeIdentification)
780 std::size_t typename_token;
781 NameAST *name;
782 ExpressionAST *expression;
785 struct TypeParameterAST: public AST
787 DECLARE_AST_NODE(TypeParameter)
789 std::size_t type;
790 NameAST *name;
791 TypeIdAST *type_id;
792 const ListNode<TemplateParameterAST*> *template_parameters;
793 NameAST *template_name;
796 struct TypedefAST: public DeclarationAST
798 DECLARE_AST_NODE(Typedef)
800 TypeSpecifierAST *type_specifier;
801 const ListNode<InitDeclaratorAST*> *init_declarators;
804 struct UnaryExpressionAST: public ExpressionAST
806 DECLARE_AST_NODE(UnaryExpression)
808 std::size_t op;
809 ExpressionAST *expression;
812 struct UnqualifiedNameAST: public AST
814 DECLARE_AST_NODE(UnqualifiedName)
816 std::size_t tilde;
817 std::size_t id;
818 OperatorFunctionIdAST *operator_id;
819 const ListNode<TemplateArgumentAST*> *template_arguments;
822 struct UsingAST: public DeclarationAST
824 DECLARE_AST_NODE(Using)
826 std::size_t type_name;
827 NameAST *name;
830 struct UsingDirectiveAST: public DeclarationAST
832 DECLARE_AST_NODE(UsingDirective)
834 NameAST *name;
837 struct WhileStatementAST: public StatementAST
839 DECLARE_AST_NODE(WhileStatement)
841 ConditionAST *condition;
842 StatementAST *statement;
845 struct WinDeclSpecAST: public AST
847 DECLARE_AST_NODE(WinDeclSpec)
849 std::size_t specifier;
850 std::size_t modifier;
853 struct QPropertyAST : public DeclarationAST
855 DECLARE_AST_NODE(QPropertyAST)
858 struct QEnumsAST : public DeclarationAST
860 DECLARE_AST_NODE(QEnumsAST)
863 template <class _Tp>
864 _Tp *CreateNode(pool *memory_pool)
866 _Tp *node = reinterpret_cast<_Tp*>(memory_pool->allocate(sizeof(_Tp)));
867 node->kind = _Tp::__node_kind;
868 return node;
871 template <class _Tp>
872 _Tp ast_cast(AST *item)
874 if (item && static_cast<_Tp>(0)->__node_kind == item->kind)
875 return static_cast<_Tp>(item);
877 return 0;
880 #endif // AST_H
882 // kate: space-indent on; indent-width 2; replace-tabs on;