comparison trunk/src/dil/ast/Node.d @ 635:b2fc028d8b55

Added class Visitor. Moved enums NodeCategory and NodeKind to new module dil.ast.NodesEnum. Commented out some version(D2) statements. Added new module dil.semantic.Pass1.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 13 Jan 2008 21:53:01 +0100
parents 07946b379006
children 15a0f37caabe
comparison
equal deleted inserted replaced
634:14e99ce74d06 635:b2fc028d8b55
5 module dil.ast.Node; 5 module dil.ast.Node;
6 6
7 import common; 7 import common;
8 8
9 public import dil.lexer.Token; 9 public import dil.lexer.Token;
10 10 public import dil.ast.NodesEnum;
11 enum NodeCategory
12 {
13 Declaration,
14 Statement,
15 Expression,
16 Type,
17 Other
18 }
19
20 enum NodeKind
21 {
22 // Declarations:
23 Declarations,
24 EmptyDeclaration,
25 IllegalDeclaration,
26 ModuleDeclaration,
27 ImportDeclaration,
28 AliasDeclaration,
29 TypedefDeclaration,
30 EnumDeclaration,
31 ClassDeclaration,
32 InterfaceDeclaration,
33 StructDeclaration,
34 UnionDeclaration,
35 ConstructorDeclaration,
36 StaticConstructorDeclaration,
37 DestructorDeclaration,
38 StaticDestructorDeclaration,
39 FunctionDeclaration,
40 VariableDeclaration,
41 InvariantDeclaration,
42 UnittestDeclaration,
43 DebugDeclaration,
44 VersionDeclaration,
45 StaticIfDeclaration,
46 StaticAssertDeclaration,
47 TemplateDeclaration,
48 NewDeclaration,
49 DeleteDeclaration,
50 AttributeDeclaration,
51 ProtectionDeclaration,
52 StorageClassDeclaration,
53 LinkageDeclaration,
54 AlignDeclaration,
55 PragmaDeclaration,
56 MixinDeclaration,
57
58 // Statements:
59 Statements,
60 IllegalStatement,
61 EmptyStatement,
62 ScopeStatement,
63 LabeledStatement,
64 ExpressionStatement,
65 DeclarationStatement,
66 IfStatement,
67 ConditionalStatement,
68 WhileStatement,
69 DoWhileStatement,
70 ForStatement,
71 ForeachStatement,
72 ForeachRangeStatement, // D2.0
73 SwitchStatement,
74 CaseStatement,
75 DefaultStatement,
76 ContinueStatement,
77 BreakStatement,
78 ReturnStatement,
79 GotoStatement,
80 WithStatement,
81 SynchronizedStatement,
82 TryStatement,
83 CatchBody,
84 FinallyBody,
85 ScopeGuardStatement,
86 ThrowStatement,
87 VolatileStatement,
88 AsmStatement,
89 AsmInstruction,
90 AsmAlignStatement,
91 IllegalAsmInstruction,
92 PragmaStatement,
93 MixinStatement,
94 StaticIfStatement,
95 StaticAssertStatement,
96 DebugStatement,
97 VersionStatement,
98
99 // Expressions:
100 EmptyExpression,
101 BinaryExpression,
102 CondExpression,
103 CommaExpression,
104 OrOrExpression,
105 AndAndExpression,
106 OrExpression,
107 XorExpression,
108 AndExpression,
109 CmpExpression,
110 EqualExpression,
111 IdentityExpression,
112 RelExpression,
113 InExpression,
114 LShiftExpression,
115 RShiftExpression,
116 URShiftExpression,
117 PlusExpression,
118 MinusExpression,
119 CatExpression,
120 MulExpression,
121 DivExpression,
122 ModExpression,
123 AssignExpression,
124 LShiftAssignExpression,
125 RShiftAssignExpression,
126 URShiftAssignExpression,
127 OrAssignExpression,
128 AndAssignExpression,
129 PlusAssignExpression,
130 MinusAssignExpression,
131 DivAssignExpression,
132 MulAssignExpression,
133 ModAssignExpression,
134 XorAssignExpression,
135 CatAssignExpression,
136 UnaryExpression,
137 AddressExpression,
138 PreIncrExpression,
139 PreDecrExpression,
140 PostIncrExpression,
141 PostDecrExpression,
142 DerefExpression,
143 SignExpression,
144 NotExpression,
145 CompExpression,
146 CallExpression,
147 NewExpression,
148 NewAnonClassExpression,
149 DeleteExpression,
150 CastExpression,
151 IndexExpression,
152 SliceExpression,
153 ModuleScopeExpression,
154 IdentifierExpression,
155 SpecialTokenExpression,
156 DotExpression,
157 TemplateInstanceExpression,
158 ThisExpression,
159 SuperExpression,
160 NullExpression,
161 DollarExpression,
162 BoolExpression,
163 IntExpression,
164 RealExpression,
165 ComplexExpression,
166 CharExpression,
167 StringExpression,
168 ArrayLiteralExpression,
169 AArrayLiteralExpression,
170 AssertExpression,
171 MixinExpression,
172 ImportExpression,
173 TypeofExpression,
174 TypeDotIdExpression,
175 TypeidExpression,
176 IsExpression,
177 FunctionLiteralExpression,
178 TraitsExpression, // D2.0
179 VoidInitializer,
180 ArrayInitializer,
181 StructInitializer,
182 AsmTypeExpression,
183 AsmOffsetExpression,
184 AsmSegExpression,
185 AsmPostBracketExpression,
186 AsmBracketExpression,
187 AsmLocalSizeExpression,
188 AsmRegisterExpression,
189
190 // Types:
191 UndefinedType,
192 IntegralType,
193 QualifiedType,
194 ModuleScopeType,
195 IdentifierType,
196 TypeofType,
197 TemplateInstanceType,
198 PointerType,
199 ArrayType,
200 FunctionType,
201 DelegateType,
202 CFuncPointerType,
203 ConstType, // D2.0
204 InvariantType, // D2.0
205
206 // Other:
207 FunctionBody,
208 Parameter,
209 Parameters,
210 BaseClass,
211 TemplateAliasParameter,
212 TemplateTypeParameter,
213 TemplateThisParameter, // D2.0
214 TemplateValueParameter,
215 TemplateTupleParameter,
216 TemplateParameters,
217 TemplateArguments,
218 EnumMember,
219 }
220 11
221 /// This string is mixed into the constructor of a class that inherits from Node. 12 /// This string is mixed into the constructor of a class that inherits from Node.
222 const string set_kind = `this.kind = mixin("NodeKind." ~ typeof(this).stringof);`; 13 const string set_kind = `this.kind = mixin("NodeKind." ~ typeof(this).stringof);`;
223 14
224 Class TryCast(Class)(Node n) 15 Class TryCast(Class)(Node n)
285 void addOptChildren(Node[] children) 76 void addOptChildren(Node[] children)
286 { 77 {
287 children is null || addChildren(children); 78 children is null || addChildren(children);
288 } 79 }
289 80
81 Class iS(Class)()
82 {
83 if (kind == mixin("NodeKind." ~ typeof(Class).stringof))
84 return cast(Class)cast(void*)this;
85 return null;
86 }
87
290 static bool isDoxygenComment(Token* token) 88 static bool isDoxygenComment(Token* token)
291 { // Doxygen: '/+!' '/*!' '//!' 89 { // Doxygen: '/+!' '/*!' '//!'
292 return token.type == TOK.Comment && token.start[2] == '!'; 90 return token.type == TOK.Comment && token.start[2] == '!';
293 } 91 }
294 92