Mercurial > projects > dil
comparison trunk/src/dil/Types.d @ 505:3bb94ba21490
Refactored a great amount of code.
Changed many declaration types from Token* to Identifier*.
Fix in parseStructInitializer(): append null to idents in else body.
Fixed class Parameter and parseParameterList().
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Wed, 12 Dec 2007 02:25:42 +0100 |
parents | b60450804b6e |
children | aa73f669c298 |
comparison
equal
deleted
inserted
replaced
504:9076c4cea2a4 | 505:3bb94ba21490 |
---|---|
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 import dil.Enums; |
10 import dil.Identifier; | |
10 | 11 |
11 class Parameter : Node | 12 class Parameter : Node |
12 { | 13 { |
13 StorageClass stc; | 14 StorageClass stc; |
14 Token* stcTok; | 15 Token* stcTok; |
15 Type type; | 16 Type type; |
16 Token* ident; | 17 Identifier* ident; |
17 Expression assignExpr; | 18 Expression assignExpr; |
18 | 19 |
19 this(Token* stcTok, Type type, Token* ident, Expression assignExpr) | 20 this(StorageClass stc, Type type, Identifier* ident, Expression assignExpr) |
20 { | 21 { |
21 super(NodeCategory.Other); | 22 super(NodeCategory.Other); |
22 mixin(set_kind); | 23 mixin(set_kind); |
23 // type can be null when param in foreach statement | 24 // type can be null when param in foreach statement |
24 addOptChild(type); | 25 addOptChild(type); |
25 addOptChild(assignExpr); | 26 addOptChild(assignExpr); |
26 | 27 |
27 StorageClass stc; | |
28 if (stcTok !is null) | |
29 { | |
30 // NB: In D 2.0 StorageClass.In means final/scope/const | |
31 switch (stcTok.type) | |
32 { | |
33 // TODO: D 2.0 invariant/const/final/scope | |
34 case TOK.In: stc = StorageClass.In; break; | |
35 case TOK.Out: stc = StorageClass.Out; break; | |
36 case TOK.Inout: | |
37 case TOK.Ref: stc = StorageClass.Ref; break; | |
38 case TOK.Lazy: stc = StorageClass.Lazy; break; | |
39 case TOK.Ellipses: | |
40 stc = StorageClass.Variadic; | |
41 default: | |
42 } | |
43 } | |
44 | |
45 this.stc = stc; | 28 this.stc = stc; |
46 this.stcTok = stcTok; | |
47 this.type = type; | 29 this.type = type; |
48 this.ident = ident; | 30 this.ident = ident; |
49 this.assignExpr = assignExpr; | 31 this.assignExpr = assignExpr; |
50 } | 32 } |
51 | 33 |
34 /// func(...) or func(int[] values ...) | |
52 bool isVariadic() | 35 bool isVariadic() |
53 { | 36 { |
54 return !!(stc & StorageClass.Variadic); | 37 return !!(stc & StorageClass.Variadic); |
55 } | 38 } |
56 | 39 |
40 /// func(...) | |
57 bool isOnlyVariadic() | 41 bool isOnlyVariadic() |
58 { | 42 { |
59 return stc == StorageClass.Variadic; | 43 return stc == StorageClass.Variadic && |
44 type is null && ident is null; | |
60 } | 45 } |
61 } | 46 } |
62 | 47 |
63 class Parameters : Node | 48 class Parameters : Node |
64 { | 49 { |
99 } | 84 } |
100 } | 85 } |
101 | 86 |
102 abstract class TemplateParameter : Node | 87 abstract class TemplateParameter : Node |
103 { | 88 { |
104 this() | 89 Identifier* ident; |
105 { | 90 this(Identifier* ident) |
106 super(NodeCategory.Other); | 91 { |
92 super(NodeCategory.Other); | |
93 this.ident = ident; | |
107 } | 94 } |
108 } | 95 } |
109 | 96 |
110 class TemplateAliasParameter : TemplateParameter | 97 class TemplateAliasParameter : TemplateParameter |
111 { | 98 { |
112 Token* ident; | |
113 Type specType, defType; | 99 Type specType, defType; |
114 this(Token* ident, Type specType, Type defType) | 100 this(Identifier* ident, Type specType, Type defType) |
115 { | 101 { |
102 super(ident); | |
116 mixin(set_kind); | 103 mixin(set_kind); |
117 addOptChild(specType); | 104 addOptChild(specType); |
118 addOptChild(defType); | 105 addOptChild(defType); |
119 this.ident = ident; | 106 this.ident = ident; |
120 this.specType = specType; | 107 this.specType = specType; |
122 } | 109 } |
123 } | 110 } |
124 | 111 |
125 class TemplateTypeParameter : TemplateParameter | 112 class TemplateTypeParameter : TemplateParameter |
126 { | 113 { |
127 Token* ident; | |
128 Type specType, defType; | 114 Type specType, defType; |
129 this(Token* ident, Type specType, Type defType) | 115 this(Identifier* ident, Type specType, Type defType) |
130 { | 116 { |
117 super(ident); | |
131 mixin(set_kind); | 118 mixin(set_kind); |
132 addOptChild(specType); | 119 addOptChild(specType); |
133 addOptChild(defType); | 120 addOptChild(defType); |
134 this.ident = ident; | 121 this.ident = ident; |
135 this.specType = specType; | 122 this.specType = specType; |
139 | 126 |
140 version(D2) | 127 version(D2) |
141 { | 128 { |
142 class TemplateThisParameter : TemplateParameter | 129 class TemplateThisParameter : TemplateParameter |
143 { | 130 { |
144 Token* ident; | |
145 Type specType, defType; | 131 Type specType, defType; |
146 this(Token* ident, Type specType, Type defType) | 132 this(Identifier* ident, Type specType, Type defType) |
147 { | 133 { |
134 super(ident); | |
148 mixin(set_kind); | 135 mixin(set_kind); |
149 addOptChild(specType); | 136 addOptChild(specType); |
150 addOptChild(defType); | 137 addOptChild(defType); |
151 this.ident = ident; | 138 this.ident = ident; |
152 this.specType = specType; | 139 this.specType = specType; |
156 } | 143 } |
157 | 144 |
158 class TemplateValueParameter : TemplateParameter | 145 class TemplateValueParameter : TemplateParameter |
159 { | 146 { |
160 Type valueType; | 147 Type valueType; |
161 Token* ident; | |
162 Expression specValue, defValue; | 148 Expression specValue, defValue; |
163 this(Type valueType, Token* ident, Expression specValue, Expression defValue) | 149 this(Type valueType, Identifier* ident, Expression specValue, Expression defValue) |
164 { | 150 { |
151 super(ident); | |
165 mixin(set_kind); | 152 mixin(set_kind); |
166 addChild(valueType); | 153 addChild(valueType); |
167 addOptChild(specValue); | 154 addOptChild(specValue); |
168 addOptChild(defValue); | 155 addOptChild(defValue); |
169 this.valueType = valueType; | 156 this.valueType = valueType; |
173 } | 160 } |
174 } | 161 } |
175 | 162 |
176 class TemplateTupleParameter : TemplateParameter | 163 class TemplateTupleParameter : TemplateParameter |
177 { | 164 { |
178 Token* ident; | 165 this(Identifier* ident) |
179 this(Token* ident) | 166 { |
180 { | 167 super(ident); |
181 mixin(set_kind); | 168 mixin(set_kind); |
182 this.ident = ident; | 169 this.ident = ident; |
183 } | 170 } |
184 } | 171 } |
185 | 172 |
305 } | 292 } |
306 } | 293 } |
307 | 294 |
308 class IdentifierType : Type | 295 class IdentifierType : Type |
309 { | 296 { |
310 Token* ident; | 297 Identifier* ident; |
311 this(Token* ident) | 298 this(Identifier* ident) |
312 { | 299 { |
313 super(TID.Identifier); | 300 super(TID.Identifier); |
314 mixin(set_kind); | 301 mixin(set_kind); |
315 this.ident = ident; | 302 this.ident = ident; |
316 } | 303 } |
347 } | 334 } |
348 } | 335 } |
349 | 336 |
350 class TemplateInstanceType : Type | 337 class TemplateInstanceType : Type |
351 { | 338 { |
352 Token* ident; | 339 Identifier* ident; |
353 TemplateArguments targs; | 340 TemplateArguments targs; |
354 this(Token* ident, TemplateArguments targs) | 341 this(Identifier* ident, TemplateArguments targs) |
355 { | 342 { |
356 super(TID.TemplateInstance); | 343 super(TID.TemplateInstance); |
357 mixin(set_kind); | 344 mixin(set_kind); |
358 addOptChild(targs); | 345 addOptChild(targs); |
359 this.ident = ident; | 346 this.ident = ident; |