Mercurial > projects > ddmd
annotate dmd/TypeEnum.d @ 192:eb38fdcb3e62 default tip
updated to compile with dmd2.062
author | korDen |
---|---|
date | Sat, 02 Mar 2013 01:25:52 -0800 |
parents | b0d41ff5e0df |
children |
rev | line source |
---|---|
0 | 1 module dmd.TypeEnum; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Type; |
5 import dmd.EnumDeclaration; | |
6 import dmd.Scope; | |
7 import dmd.Loc; | |
8 import dmd.Id; | |
9 import dmd.ErrorExp; | |
10 import dmd.Dsymbol; | |
11 import dmd.EnumMember; | |
12 import dmd.OutBuffer; | |
13 import dmd.HdrGenState; | |
14 import dmd.Expression; | |
15 import dmd.Identifier; | |
16 import dmd.MATCH; | |
17 import dmd.OutBuffer; | |
18 import dmd.CppMangleState; | |
156 | 19 import dmd.StringExp; |
0 | 20 import dmd.TypeInfoDeclaration; |
21 import dmd.TypeInfoEnumDeclaration; | |
22 import dmd.ArrayTypes; | |
23 import dmd.TY; | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
24 import dmd.MOD; |
0 | 25 import dmd.Util; |
26 | |
27 import dmd.backend.TYPE; | |
28 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
29 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
30 |
0 | 31 class TypeEnum : Type |
32 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
33 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
34 |
0 | 35 EnumDeclaration sym; |
36 | |
37 this(EnumDeclaration sym) | |
38 { | |
178 | 39 register(); |
0 | 40 super(TY.Tenum); |
41 this.sym = sym; | |
42 } | |
43 | |
72 | 44 override Type syntaxCopy() |
0 | 45 { |
46 assert(false); | |
47 } | |
48 | |
72 | 49 override ulong size(Loc loc) |
0 | 50 { |
51 if (!sym.memtype) | |
52 { | |
53 error(loc, "enum %s is forward referenced", sym.toChars()); | |
54 return 4; | |
55 } | |
56 return sym.memtype.size(loc); | |
57 } | |
58 | |
156 | 59 override uint alignsize() |
0 | 60 { |
156 | 61 if (!sym.memtype) |
62 { | |
63 debug writef("1: "); | |
64 | |
65 error(Loc(0), "enum %s is forward referenced", sym.toChars()); | |
66 return 4; | |
67 } | |
68 return sym.memtype.alignsize(); | |
0 | 69 } |
156 | 70 |
71 override string toChars() | |
0 | 72 { |
156 | 73 if (mod) |
74 return super.toChars(); | |
75 return sym.toChars(); | |
0 | 76 } |
77 | |
72 | 78 override Type semantic(Loc loc, Scope sc) |
0 | 79 { |
80 //printf("TypeEnum::semantic() %s\n", toChars()); | |
81 //sym.semantic(sc); | |
82 return merge(); | |
83 } | |
84 | |
72 | 85 override Dsymbol toDsymbol(Scope sc) |
0 | 86 { |
87 return sym; | |
88 } | |
89 | |
72 | 90 override void toDecoBuffer(OutBuffer buf, int flag) |
0 | 91 { |
92 string name = sym.mangle(); | |
93 Type.toDecoBuffer(buf, flag); | |
94 buf.printf("%s", name); | |
95 } | |
96 | |
72 | 97 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 98 { |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
99 if (mod != this.mod) |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
100 { |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
101 toCBuffer3(buf, hgs, mod); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
102 return; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
103 } |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
0
diff
changeset
|
104 buf.writestring(sym.toChars()); |
0 | 105 } |
106 | |
72 | 107 override Expression dotExp(Scope sc, Expression e, Identifier ident) |
0 | 108 { |
109 version (LOGDOTEXP) { | |
110 printf("TypeEnum::dotExp(e = '%s', ident = '%s') '%s'\n", e.toChars(), ident.toChars(), toChars()); | |
111 } | |
112 Dsymbol s = sym.search(e.loc, ident, 0); | |
113 if (!s) | |
114 { | |
115 if (ident is Id.max || | |
116 ident is Id.min || | |
117 ident is Id.init_ || | |
118 ident is Id.stringof_ || | |
119 !sym.memtype | |
120 ) | |
121 { | |
122 return getProperty(e.loc, ident); | |
123 } | |
124 | |
125 return sym.memtype.dotExp(sc, e, ident); | |
126 } | |
127 | |
128 EnumMember m = s.isEnumMember(); | |
129 Expression em = m.value.copy(); | |
130 em.loc = e.loc; | |
131 return em; | |
132 } | |
133 | |
156 | 134 override Expression getProperty(Loc loc, Identifier ident) |
0 | 135 { |
156 | 136 Expression e; |
137 | |
138 if (ident is Id.max) | |
139 { | |
140 if (!sym.maxval) | |
141 goto Lfwd; | |
142 e = sym.maxval; | |
143 } | |
144 else if (ident is Id.min) | |
145 { | |
146 if (!sym.minval) | |
147 goto Lfwd; | |
148 e = sym.minval; | |
149 } | |
150 else if (ident is Id.init_) | |
151 { | |
152 e = defaultInitLiteral(loc); | |
153 } | |
154 else if (ident is Id.stringof_) | |
155 { | |
156 string s = toChars(); | |
157 e = new StringExp(loc, s, 'c'); | |
158 Scope sc; | |
159 e = e.semantic(sc); | |
160 } | |
161 else if (ident is Id.mangleof_) | |
162 { | |
163 e = Type.getProperty(loc, ident); | |
164 } | |
165 else | |
166 { | |
167 e = toBasetype().getProperty(loc, ident); | |
168 } | |
169 return e; | |
170 | |
171 Lfwd: | |
172 error(loc, "forward reference of %s.%s", toChars(), ident.toChars()); | |
173 return new ErrorExp(); | |
0 | 174 } |
175 | |
72 | 176 override bool isintegral() |
0 | 177 { |
73 | 178 return sym.memtype.isintegral(); |
0 | 179 } |
180 | |
72 | 181 override bool isfloating() |
0 | 182 { |
73 | 183 return sym.memtype.isfloating(); |
184 } | |
185 | |
79 | 186 override bool isreal() |
73 | 187 { |
188 return sym.memtype.isreal(); | |
189 } | |
190 | |
79 | 191 override bool isimaginary() |
73 | 192 { |
193 return sym.memtype.isimaginary(); | |
194 } | |
195 | |
79 | 196 override bool iscomplex() |
73 | 197 { |
198 return sym.memtype.iscomplex(); | |
199 } | |
200 | |
79 | 201 override bool checkBoolean() |
73 | 202 { |
203 return sym.memtype.checkBoolean(); | |
204 } | |
205 | |
79 | 206 override bool isAssignable() |
73 | 207 { |
208 return sym.memtype.isAssignable(); | |
0 | 209 } |
210 | |
72 | 211 override bool isscalar() |
0 | 212 { |
73 | 213 return sym.memtype.isscalar(); |
0 | 214 } |
215 | |
72 | 216 override bool isunsigned() |
0 | 217 { |
218 return sym.memtype.isunsigned(); | |
219 } | |
220 | |
72 | 221 override MATCH implicitConvTo(Type to) |
0 | 222 { |
223 MATCH m; | |
224 | |
225 //printf("TypeEnum::implicitConvTo()\n"); | |
226 if (ty == to.ty && sym == (cast(TypeEnum)to).sym) | |
227 m = (mod == to.mod) ? MATCHexact : MATCHconst; | |
228 else if (sym.memtype.implicitConvTo(to)) | |
229 m = MATCHconvert; // match with conversions | |
230 else | |
231 m = MATCHnomatch; // no match | |
232 return m; | |
233 } | |
234 | |
72 | 235 override MATCH constConv(Type to) |
0 | 236 { |
135 | 237 if (equals(to)) |
238 return MATCHexact; | |
239 if (ty == to.ty && sym == (cast(TypeEnum)to).sym && | |
240 MODimplicitConv(mod, to.mod)) | |
241 return MATCHconst; | |
242 return MATCHnomatch; | |
0 | 243 } |
244 | |
72 | 245 override Type toBasetype() |
0 | 246 { |
135 | 247 if (sym.scope_) |
248 { | |
179 | 249 // Enum is forward referenced. We don't need to resolve the whole thing, |
250 // just the base type | |
251 if (sym.memtype) | |
252 { | |
253 sym.memtype = sym.memtype.semantic(sym.loc, sym.scope_); | |
254 } | |
255 else | |
256 { | |
257 if (!sym.isAnonymous()) | |
258 sym.memtype = Type.tint32; | |
259 } | |
135 | 260 } |
0 | 261 if (!sym.memtype) |
262 { | |
263 debug writef("2: "); | |
264 error(sym.loc, "enum %s is forward referenced", sym.toChars()); | |
265 return tint32; | |
266 } | |
267 | |
268 return sym.memtype.toBasetype(); | |
269 } | |
270 | |
72 | 271 override Expression defaultInit(Loc loc) |
0 | 272 { |
273 version (LOGDEFAULTINIT) { | |
274 printf("TypeEnum::defaultInit() '%s'\n", toChars()); | |
275 } | |
276 // Initialize to first member of enum | |
277 //printf("%s\n", sym.defaultval.type.toChars()); | |
278 if (!sym.defaultval) | |
279 { | |
280 error(loc, "forward reference of %s.init", toChars()); | |
281 return new ErrorExp(); | |
282 } | |
283 return sym.defaultval; | |
284 } | |
285 | |
72 | 286 override bool isZeroInit(Loc loc) |
0 | 287 { |
288 if (!sym.defaultval) | |
289 { | |
290 debug writef("3: "); | |
291 error(loc, "enum %s is forward referenced", sym.toChars()); | |
292 return 0; | |
293 } | |
294 return sym.defaultval.isBool(false); | |
295 } | |
296 | |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
297 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) |
0 | 298 { |
93
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
299 // Extra check |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
300 if (tparam && tparam.ty == Tenum) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
301 { |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
302 TypeEnum tp = cast(TypeEnum)tparam; |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
303 |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
304 if (sym != tp.sym) |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
305 return MATCHnomatch; |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
306 } |
df6d0f967680
implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents:
79
diff
changeset
|
307 return Type.deduceType(sc, tparam, parameters, dedtypes); |
0 | 308 } |
309 | |
72 | 310 override TypeInfoDeclaration getTypeInfoDeclaration() |
0 | 311 { |
312 return new TypeInfoEnumDeclaration(this); | |
313 } | |
314 | |
72 | 315 override bool hasPointers() |
0 | 316 { |
317 return toBasetype().hasPointers(); | |
318 } | |
319 | |
320 version (CPP_MANGLE) { | |
321 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
322 { | |
323 assert(false); | |
324 } | |
325 } | |
326 | |
72 | 327 override type* toCtype() |
0 | 328 { |
329 return sym.memtype.toCtype(); | |
330 } | |
72 | 331 } |