comparison trunk/src/dil/Types.d @ 489:a7291d3ee9d7

Refactored classes that inherit from Node. Added methods addChild(), addOptChild(), addChildren(), addOptChildren() to class Node. Refactored subclasses to use the new methods instead of appending directly to the array Node.children. Moved enums StorageClass and Protection to new module dil.Enums. Added members stc, prot, isStatic() and isPulic() to Declaration.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Mon, 03 Dec 2007 22:44:27 +0100
parents cfb3805768b6
children 9c208925a3d4
comparison
equal deleted inserted replaced
488:cfb3805768b6 489:a7291d3ee9d7
4 +/ 4 +/
5 module dil.Types; 5 module dil.Types;
6 import dil.SyntaxTree; 6 import dil.SyntaxTree;
7 import dil.Token; 7 import dil.Token;
8 import dil.Expressions; 8 import dil.Expressions;
9 import dil.Enums;
9 10
10 class Linkage : Node 11 class Linkage : Node
11 { 12 {
12 enum Type 13 enum Type
13 { 14 {
47 else 48 else
48 return Category.MangleSymbol; 49 return Category.MangleSymbol;
49 } 50 }
50 } 51 }
51 52
52 enum StorageClass
53 {
54 None = 0,
55 Abstract = 1,
56 Auto = 1<<2,
57 Const = 1<<3,
58 Deprecated = 1<<4,
59 Extern = 1<<5,
60 Final = 1<<6,
61 Invariant = 1<<7,
62 Override = 1<<8,
63 Scope = 1<<9,
64 Static = 1<<10,
65 Synchronized = 1<<11,
66 In = 1<<12,
67 Out = 1<<13,
68 Ref = 1<<14,
69 Lazy = 1<<15,
70 Variadic = 1<<16,
71 }
72
73 class Parameter : Node 53 class Parameter : Node
74 { 54 {
75 StorageClass stc; 55 StorageClass stc;
76 Token* stcTok; 56 Token* stcTok;
77 Type type; 57 Type type;
80 60
81 this(Token* stcTok, Type type, Token* ident, Expression assignExpr) 61 this(Token* stcTok, Type type, Token* ident, Expression assignExpr)
82 { 62 {
83 super(NodeCategory.Other); 63 super(NodeCategory.Other);
84 mixin(set_kind); 64 mixin(set_kind);
85 if (type) // type can be null when param in foreach statement 65 // type can be null when param in foreach statement
86 this.children = [type]; 66 addOptChild(type);
87 if (assignExpr) 67 addOptChild(assignExpr);
88 this.children ~= assignExpr;
89 68
90 StorageClass stc; 69 StorageClass stc;
91 if (stcTok !is null) 70 if (stcTok !is null)
92 { 71 {
93 // NB: In D 2.0 StorageClass.In means final/scope/const 72 // NB: In D 2.0 StorageClass.In means final/scope/const
137 return items[$-1].isVariadic(); 116 return items[$-1].isVariadic();
138 return false; 117 return false;
139 } 118 }
140 119
141 void opCatAssign(Parameter param) 120 void opCatAssign(Parameter param)
142 { children ~= param; } 121 { addChild(param); }
143 122
144 Parameter[] items() 123 Parameter[] items()
145 { return cast(Parameter[])children; } 124 { return cast(Parameter[])children; }
146 125
147 size_t length() 126 size_t length()
148 { return children.length; } 127 { return children.length; }
149 }
150
151
152 enum Protection
153 {
154 None,
155 Private = 1,
156 Protected = 1<<1,
157 Package = 1<<2,
158 Public = 1<<3,
159 Export = 1<<4
160 } 128 }
161 129
162 class BaseClass : Node 130 class BaseClass : Node
163 { 131 {
164 Protection prot; 132 Protection prot;
165 Type type; 133 Type type;
166 this(Protection prot, Type type) 134 this(Protection prot, Type type)
167 { 135 {
168 super(NodeCategory.Other); 136 super(NodeCategory.Other);
169 mixin(set_kind); 137 mixin(set_kind);
170 this.children = [type]; 138 addChild(type);
171 this.prot = prot; 139 this.prot = prot;
172 this.type = type; 140 this.type = type;
173 } 141 }
174 } 142 }
175 143
186 Token* ident; 154 Token* ident;
187 Type specType, defType; 155 Type specType, defType;
188 this(Token* ident, Type specType, Type defType) 156 this(Token* ident, Type specType, Type defType)
189 { 157 {
190 mixin(set_kind); 158 mixin(set_kind);
191 if (specType) 159 addOptChild(specType);
192 this.children ~= specType; 160 addOptChild(defType);
193 if (defType)
194 this.children ~= defType;
195 this.ident = ident; 161 this.ident = ident;
196 this.specType = specType; 162 this.specType = specType;
197 this.defType = defType; 163 this.defType = defType;
198 } 164 }
199 } 165 }
203 Token* ident; 169 Token* ident;
204 Type specType, defType; 170 Type specType, defType;
205 this(Token* ident, Type specType, Type defType) 171 this(Token* ident, Type specType, Type defType)
206 { 172 {
207 mixin(set_kind); 173 mixin(set_kind);
208 if (specType) 174 addOptChild(specType);
209 this.children ~= specType; 175 addOptChild(defType);
210 if (defType)
211 this.children ~= defType;
212 this.ident = ident; 176 this.ident = ident;
213 this.specType = specType; 177 this.specType = specType;
214 this.defType = defType; 178 this.defType = defType;
215 } 179 }
216 } 180 }
221 Token* ident; 185 Token* ident;
222 Expression specValue, defValue; 186 Expression specValue, defValue;
223 this(Type valueType, Token* ident, Expression specValue, Expression defValue) 187 this(Type valueType, Token* ident, Expression specValue, Expression defValue)
224 { 188 {
225 mixin(set_kind); 189 mixin(set_kind);
226 this.children ~= valueType; 190 addChild(valueType);
227 if (specValue) 191 addOptChild(specValue);
228 this.children ~= specValue; 192 addOptChild(defValue);
229 if (defValue)
230 this.children ~= defValue;
231 this.valueType = valueType; 193 this.valueType = valueType;
232 this.ident = ident; 194 this.ident = ident;
233 this.specValue = specValue; 195 this.specValue = specValue;
234 this.defValue = defValue; 196 this.defValue = defValue;
235 } 197 }
253 mixin(set_kind); 215 mixin(set_kind);
254 } 216 }
255 217
256 void opCatAssign(TemplateParameter parameter) 218 void opCatAssign(TemplateParameter parameter)
257 { 219 {
258 this.children ~= parameter; 220 addChild(parameter);
259 } 221 }
260 222
261 TemplateParameter[] items() 223 TemplateParameter[] items()
262 { 224 {
263 return cast(TemplateParameter[])children; 225 return cast(TemplateParameter[])children;
272 mixin(set_kind); 234 mixin(set_kind);
273 } 235 }
274 236
275 void opCatAssign(Node argument) 237 void opCatAssign(Node argument)
276 { 238 {
277 this.children ~= argument; 239 addChild(argument);
278 } 240 }
279 } 241 }
280 242
281 enum TID 243 enum TID
282 { 244 {
329 } 291 }
330 292
331 this(TID tid, Type next) 293 this(TID tid, Type next)
332 { 294 {
333 super(NodeCategory.Type); 295 super(NodeCategory.Type);
334 if (next) 296 addOptChild(next);
335 this.children ~= next;
336 this.tid = tid; 297 this.tid = tid;
337 this.next = next; 298 this.next = next;
338 } 299 }
339 } 300 }
340 301
361 Type[] dotList; 322 Type[] dotList;
362 this(Type[] dotList) 323 this(Type[] dotList)
363 { 324 {
364 super(TID.DotList); 325 super(TID.DotList);
365 mixin(set_kind); 326 mixin(set_kind);
366 this.children ~= dotList; 327 addChildren(dotList);
367 this.dotList = dotList; 328 this.dotList = dotList;
368 } 329 }
369 } 330 }
370 331
371 class IdentifierType : Type 332 class IdentifierType : Type
393 Expression e; 354 Expression e;
394 this(Expression e) 355 this(Expression e)
395 { 356 {
396 super(TID.Typeof); 357 super(TID.Typeof);
397 mixin(set_kind); 358 mixin(set_kind);
398 this.children ~= e; 359 addChild(e);
399 this.e = e; 360 this.e = e;
400 } 361 }
401 } 362 }
402 363
403 class TemplateInstanceType : Type 364 class TemplateInstanceType : Type
406 TemplateArguments targs; 367 TemplateArguments targs;
407 this(Token* ident, TemplateArguments targs) 368 this(Token* ident, TemplateArguments targs)
408 { 369 {
409 super(TID.TemplateInstance); 370 super(TID.TemplateInstance);
410 mixin(set_kind); 371 mixin(set_kind);
411 if (targs) 372 addOptChild(targs);
412 this.children ~= targs;
413 this.ident = ident; 373 this.ident = ident;
414 this.targs = targs; 374 this.targs = targs;
415 } 375 }
416 } 376 }
417 377
426 386
427 class ArrayType : Type 387 class ArrayType : Type
428 { 388 {
429 Expression e, e2; 389 Expression e, e2;
430 Type assocType; 390 Type assocType;
391
431 this(Type t) 392 this(Type t)
432 { 393 {
433 super(TID.Array, t); 394 super(TID.Array, t);
434 mixin(set_kind); 395 mixin(set_kind);
435 } 396 }
397
436 this(Type t, Expression e, Expression e2) 398 this(Type t, Expression e, Expression e2)
437 { 399 {
438 this.children = [e]; 400 addChild(e);
439 if (e2) 401 addOptChild(e2);
440 this.children ~= e2;
441 this.e = e; 402 this.e = e;
442 this.e2 = e2; 403 this.e2 = e2;
443 this(t); 404 this(t);
444 } 405 }
406
445 this(Type t, Type assocType) 407 this(Type t, Type assocType)
446 { 408 {
447 this.children = [assocType]; 409 addChild(assocType);
448 this.assocType = assocType; 410 this.assocType = assocType;
449 this(t); 411 this(t);
450 } 412 }
451 } 413 }
452 414
456 Parameters parameters; 418 Parameters parameters;
457 this(Type returnType, Parameters parameters) 419 this(Type returnType, Parameters parameters)
458 { 420 {
459 super(TID.Function); 421 super(TID.Function);
460 mixin(set_kind); 422 mixin(set_kind);
461 this.children = [cast(Node)returnType, parameters]; 423 addChild(returnType);
424 addChild(parameters);
462 this.returnType = returnType; 425 this.returnType = returnType;
463 this.parameters = parameters; 426 this.parameters = parameters;
464 } 427 }
465 } 428 }
466 429
470 Parameters parameters; 433 Parameters parameters;
471 this(Type returnType, Parameters parameters) 434 this(Type returnType, Parameters parameters)
472 { 435 {
473 super(TID.Delegate); 436 super(TID.Delegate);
474 mixin(set_kind); 437 mixin(set_kind);
475 this.children = [cast(Node)returnType, parameters]; 438 addChild(returnType);
439 addChild(parameters);
476 this.returnType = returnType; 440 this.returnType = returnType;
477 this.parameters = parameters; 441 this.parameters = parameters;
478 } 442 }
479 } 443 }
480 444
483 Parameters params; 447 Parameters params;
484 this(Type type, Parameters params) 448 this(Type type, Parameters params)
485 { 449 {
486 super(TID.CFuncPointer, type); 450 super(TID.CFuncPointer, type);
487 mixin(set_kind); 451 mixin(set_kind);
488 if (params) 452 addOptChild(params);
489 this.children ~= params;
490 } 453 }
491 } 454 }
492 455
493 version(D2) 456 version(D2)
494 { 457 {