Mercurial > projects > dil
annotate trunk/src/Types.d @ 154:0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
- parseDotListExpression() parses NewExpression items as well.
- Commented out code in parsePostExpression().
- Commented out code in parsePrimaryExpression() and replaced with a call to parseDotListExpression().
- Fix: parseArguments() was called with T.LParen instead of T.RParen.
- Removed unused class DotExpression.
- Added class DotListExpression.
author | aziz |
---|---|
date | Fri, 13 Jul 2007 09:43:00 +0000 |
parents | 66790fc2c0a2 |
children | 759f437313f9 |
rev | line source |
---|---|
94 | 1 /++ |
2 Author: Aziz Köksal | |
3 License: GPL2 | |
4 +/ | |
5 module Types; | |
6 import Token; | |
7 import Expressions; | |
8 | |
95 | 9 enum StorageClass |
10 { | |
11 None = 0, | |
12 Abstract = 1, | |
13 Auto = 1<<2, | |
14 Const = 1<<3, | |
15 Deprecated = 1<<4, | |
16 Extern = 1<<5, | |
17 Final = 1<<6, | |
18 Invariant = 1<<7, | |
19 Override = 1<<8, | |
20 Scope = 1<<9, | |
21 Static = 1<<10, | |
22 Synchronized = 1<<11, | |
23 In = 1<<12, | |
24 Out = 1<<13, | |
25 Ref = 1<<14, | |
26 Lazy = 1<<15, | |
27 Variadic = 1<<16, | |
28 } | |
29 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
30 class Parameter |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
31 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
32 StorageClass stc; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
33 Type type; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
34 string ident; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
35 Expression assignExpr; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
36 |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
37 this(StorageClass stc, Type type, string ident, Expression assignExpr) |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
38 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
39 this.stc = stc; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
40 this.type = type; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
41 this.ident = ident; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
42 this.assignExpr = assignExpr; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
43 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
44 |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
45 bool isVariadic() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
46 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
47 return !!(stc & StorageClass.Variadic); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
48 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
49 |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
50 bool isOnlyVariadic() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
51 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
52 return stc == StorageClass.Variadic; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
53 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
54 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
55 |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
56 struct Parameters |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
57 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
58 Parameter[] items; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
59 |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
60 bool hasVariadic() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
61 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
62 if (items.length != 0) |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
63 return items[$-1].isVariadic(); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
64 return false; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
65 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
66 |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
67 void opCatAssign(Parameter param) |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
68 { items ~= param; } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
69 |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
70 size_t length() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
71 { return items.length; } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
72 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
106
diff
changeset
|
73 |
137 | 74 enum TP |
75 { | |
76 Type, | |
77 Value, | |
78 Alias, | |
79 Tuple | |
80 } | |
81 | |
82 class TemplateParameter | |
83 { | |
84 TP tp; | |
85 Type valueType; | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
137
diff
changeset
|
86 string ident; |
137 | 87 Type specType, defType; |
88 Expression specValue, defValue; | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
137
diff
changeset
|
89 this(TP tp, Type valueType, string ident, Type specType, Type defType, Expression specValue, Expression defValue) |
137 | 90 { |
91 this.tp = tp; | |
92 this.valueType = valueType; | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
137
diff
changeset
|
93 this.ident = ident; |
137 | 94 this.specType = specType; |
95 this.defType = defType; | |
96 this.specValue = specValue; | |
97 this.defValue = defValue; | |
98 } | |
99 } | |
100 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
137
diff
changeset
|
101 typedef Object[] TemplateArguments; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
137
diff
changeset
|
102 |
135 | 103 enum TID |
104 { | |
105 Void = TOK.Void, | |
106 Char = TOK.Char, | |
107 Wchar = TOK.Wchar, | |
108 Dchar = TOK.Dchar, | |
109 Bool = TOK.Bool, | |
110 Byte = TOK.Byte, | |
111 Ubyte = TOK.Ubyte, | |
112 Short = TOK.Short, | |
113 Ushort = TOK.Ushort, | |
114 Int = TOK.Int, | |
115 Uint = TOK.Uint, | |
116 Long = TOK.Long, | |
117 Ulong = TOK.Ulong, | |
118 Float = TOK.Float, | |
119 Double = TOK.Double, | |
120 Real = TOK.Real, | |
121 Ifloat = TOK.Ifloat, | |
122 Idouble = TOK.Idouble, | |
123 Ireal = TOK.Ireal, | |
124 Cfloat = TOK.Cfloat, | |
125 Cdouble = TOK.Cdouble, | |
126 Creal = TOK.Creal, | |
127 | |
128 Undefined, | |
129 Function, | |
130 Delegate, | |
131 Pointer, | |
132 Array, | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
133 DotList, |
135 | 134 Identifier, |
135 Typeof, | |
153 | 136 TemplateInstance, |
135 | 137 Specialization, |
138 } | |
139 | |
94 | 140 class Type |
141 { | |
135 | 142 TID tid; |
95 | 143 Type next; |
144 | |
135 | 145 this(TOK tok) |
146 { | |
147 this.tid = cast(TID)tok; | |
148 } | |
95 | 149 |
135 | 150 this(TID tid) |
151 { this(tid, null); } | |
152 | |
153 this(TID tid, Type next) | |
94 | 154 { |
135 | 155 this.tid = tid; |
95 | 156 this.next = next; |
94 | 157 } |
158 } | |
159 | |
134
a31aa0d6dd5e
- Added class UndefinedType. Returning it in parseBasicType() when no token matched the basic type list.
aziz
parents:
130
diff
changeset
|
160 class UndefinedType : Type |
a31aa0d6dd5e
- Added class UndefinedType. Returning it in parseBasicType() when no token matched the basic type list.
aziz
parents:
130
diff
changeset
|
161 { |
a31aa0d6dd5e
- Added class UndefinedType. Returning it in parseBasicType() when no token matched the basic type list.
aziz
parents:
130
diff
changeset
|
162 this() |
a31aa0d6dd5e
- Added class UndefinedType. Returning it in parseBasicType() when no token matched the basic type list.
aziz
parents:
130
diff
changeset
|
163 { |
135 | 164 super(TID.Undefined, null); |
134
a31aa0d6dd5e
- Added class UndefinedType. Returning it in parseBasicType() when no token matched the basic type list.
aziz
parents:
130
diff
changeset
|
165 } |
a31aa0d6dd5e
- Added class UndefinedType. Returning it in parseBasicType() when no token matched the basic type list.
aziz
parents:
130
diff
changeset
|
166 } |
a31aa0d6dd5e
- Added class UndefinedType. Returning it in parseBasicType() when no token matched the basic type list.
aziz
parents:
130
diff
changeset
|
167 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
168 class DotListType : Type |
153 | 169 { |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
170 Type[] dotList; |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
171 this(Type[] dotList) |
153 | 172 { |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
173 super(TID.DotList, null); |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
174 this.dotList = dotList; |
153 | 175 } |
176 } | |
177 | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
178 /+ |
94 | 179 class IdentifierType : Type |
180 { | |
181 string[] idents; | |
182 | |
183 this(string[] idents) | |
184 { | |
135 | 185 super(TID.Identifier, null); |
94 | 186 this.idents = idents; |
187 } | |
188 | |
153 | 189 this(string ident) |
190 { | |
191 super(TID.Identifier, null); | |
192 } | |
193 | |
135 | 194 this(TID tid) |
94 | 195 { |
135 | 196 super(tid); |
94 | 197 } |
198 | |
199 void opCatAssign(string ident) | |
200 { | |
201 this.idents ~= ident; | |
202 } | |
203 } | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
204 +/ |
94 | 205 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
206 class IdentifierType : Type |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
207 { |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
208 string ident; |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
209 this(string ident) |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
210 { |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
211 super(TID.Identifier, null); |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
212 this.ident = ident; |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
213 } |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
214 } |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
215 /+ |
94 | 216 class TypeofType : IdentifierType |
217 { | |
218 Expression e; | |
219 this(Expression e) | |
220 { | |
135 | 221 super(TID.Typeof); |
94 | 222 this.e = e; |
223 } | |
224 } | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
225 +/ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
226 |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
227 class TypeofType : Type |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
228 { |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
229 Expression e; |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
230 this(Expression e) |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
231 { |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
232 super(TID.Typeof, null); |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
233 this.e = e; |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
234 } |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
235 } |
95 | 236 |
153 | 237 class TemplateInstanceType : Type |
238 { | |
239 string ident; | |
240 TemplateArguments targs; | |
241 this(string ident, TemplateArguments targs) | |
242 { | |
243 super(TID.TemplateInstance, null); | |
244 this.ident = ident; | |
245 this.targs = targs; | |
246 } | |
247 } | |
248 | |
95 | 249 class PointerType : Type |
250 { | |
251 this(Type t) | |
252 { | |
135 | 253 super(TID.Pointer, t); |
95 | 254 } |
255 } | |
256 | |
257 class ArrayType : Type | |
258 { | |
106 | 259 Expression e, e2; |
260 Type assocType; | |
261 this(Type t) | |
95 | 262 { |
135 | 263 super(TID.Array, t); |
106 | 264 } |
265 this(Type t, Expression e, Expression e2) | |
266 { | |
267 this(t); | |
95 | 268 this.e = e; |
106 | 269 this.e2 = e2; |
270 } | |
271 this(Type t, Type assocType) | |
272 { | |
273 this(t); | |
274 this.assocType = assocType; | |
95 | 275 } |
276 } | |
100 | 277 |
278 class SpecializationType : Type | |
279 { | |
106 | 280 TOK specTok; // Colon|Equal |
100 | 281 Type type; |
106 | 282 TOK tokType; // Typedef|Struct|Union|Class|Interface| |
283 // Enum|Function|Delegate|Super|Return | |
100 | 284 |
285 this(TOK specTok, TOK tokType) | |
286 { | |
135 | 287 super(TID.Specialization, null); |
100 | 288 this.specTok = specTok; |
289 this.tokType = tokType; | |
290 } | |
291 | |
292 this(TOK specTok, Type type) | |
293 { | |
135 | 294 super(TID.Specialization, null); |
100 | 295 this.specTok = specTok; |
296 this.type = type; | |
297 } | |
298 } | |
130 | 299 |
300 class FunctionType : Type | |
301 { | |
302 Type returnType; | |
303 Parameters parameters; | |
304 this(Type returnType, Parameters parameters) | |
305 { | |
135 | 306 super(TID.Function, null); |
130 | 307 this.returnType = returnType; |
308 this.parameters = parameters; | |
309 } | |
310 } | |
135 | 311 |
312 class DelegateType : Type | |
313 { | |
314 this(Type func) | |
315 { | |
316 super(TID.Delegate, func); | |
317 } | |
318 } |