Mercurial > projects > ddmd
annotate dmd/EnumDeclaration.d @ 191:52188e7e3fb5
Fixed deprecated features, now compiles with DMD2.058
Also changed Array allocation policy:
Now doesn't reallocate but malloc's, followed by a memcpy (no free).
(this fixes a crash while compiling druntime. Same bug in dmd)
author | korDen@korDen-pc |
---|---|
date | Sun, 25 Mar 2012 03:11:12 +0400 |
parents | b0d41ff5e0df |
children |
rev | line source |
---|---|
0 | 1 module dmd.EnumDeclaration; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.ScopeDsymbol; |
5 import dmd.AddExp; | |
6 import dmd.Type; | |
7 import dmd.CmpExp; | |
8 import dmd.IntegerExp; | |
9 import dmd.EqualExp; | |
10 import dmd.TOK; | |
11 import dmd.Id; | |
12 import dmd.TY; | |
13 import dmd.DsymbolTable; | |
14 import dmd.STC; | |
15 import dmd.Expression; | |
16 import dmd.Identifier; | |
17 import dmd.Dsymbol; | |
18 import dmd.Scope; | |
19 import dmd.OutBuffer; | |
20 import dmd.HdrGenState; | |
21 import dmd.Global; | |
22 import dmd.Loc; | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
20
diff
changeset
|
23 import dmd.Module; |
0 | 24 import dmd.TypeEnum; |
25 import dmd.EnumMember; | |
26 import dmd.DYNCAST; | |
27 import dmd.WANT; | |
28 import dmd.Id; | |
79 | 29 import dmd.Json; |
0 | 30 import dmd.Lexer; |
31 | |
32 import dmd.backend.SC; | |
33 import dmd.backend.FL; | |
34 import dmd.backend.Util; | |
35 import dmd.backend.Symbol; | |
36 import dmd.backend.Classsym; | |
37 import dmd.backend.SFL; | |
38 import dmd.backend.LIST; | |
39 import dmd.codegen.Util; | |
40 | |
41 import std.stdio : writef; | |
42 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
43 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
|
44 |
0 | 45 class EnumDeclaration : ScopeDsymbol |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
46 { |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
47 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
|
48 |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
49 /* enum ident : memtype { ... } |
0 | 50 */ |
51 Type type; // the TypeEnum | |
52 Type memtype; // type of the members | |
53 | |
79 | 54 version (DMDV1) |
55 { | |
0 | 56 ulong maxval; |
57 ulong minval; | |
58 ulong defaultval; // default initializer | |
79 | 59 } |
60 else | |
61 { | |
0 | 62 Expression maxval; |
63 Expression minval; | |
64 Expression defaultval; // default initializer | |
65 } | |
138 | 66 bool isdeprecated = false; |
67 bool isdone = false; // 0: not done | |
68 // 1: semantic() successfully completed | |
69 | |
0 | 70 this(Loc loc, Identifier id, Type memtype) |
71 { | |
178 | 72 register(); |
0 | 73 super(id); |
74 this.loc = loc; | |
75 type = new TypeEnum(this); | |
76 this.memtype = memtype; | |
77 } | |
78 | |
72 | 79 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 80 { |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
81 Type t = null; |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
82 if (memtype) |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
83 t = memtype.syntaxCopy(); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
84 |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
85 EnumDeclaration ed; |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
86 if (s) |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
87 { ed = cast(EnumDeclaration)s; |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
88 ed.memtype = t; |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
89 } |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
90 else |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
91 ed = new EnumDeclaration(loc, ident, t); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
92 ScopeDsymbol.syntaxCopy(ed); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
93 return ed; |
0 | 94 } |
95 | |
72 | 96 override void semantic(Scope sc) |
0 | 97 { |
98 Type t; | |
99 Scope sce; | |
100 | |
101 //writef("EnumDeclaration.semantic(sd = %p, '%s') %s\n", sc.scopesym, sc.scopesym.toChars(), toChars()); | |
102 //writef("EnumDeclaration.semantic() %s\n", toChars()); | |
103 if (!members) // enum ident; | |
104 return; | |
105 | |
106 if (!memtype && !isAnonymous()) | |
107 { | |
108 // Set memtype if we can to reduce fwd reference errors | |
109 memtype = Type.tint32; // case 1) enum ident { ... } | |
110 } | |
111 | |
112 if (symtab) // if already done | |
113 { | |
138 | 114 if (isdone || !scope_) |
0 | 115 return; // semantic() already completed |
116 } | |
117 else | |
118 symtab = new DsymbolTable(); | |
119 | |
120 Scope scx = null; | |
121 if (scope_) | |
122 { sc = scope_; | |
123 scx = scope_; // save so we don't make redundant copies | |
124 scope_ = null; | |
125 } | |
179 | 126 |
127 uint dprogress_save = global.dprogress; | |
0 | 128 |
129 if (sc.stc & STC.STCdeprecated) | |
130 isdeprecated = true; | |
131 | |
132 parent = sc.parent; | |
133 | |
134 /* The separate, and distinct, cases are: | |
135 * 1. enum { ... } | |
136 * 2. enum : memtype { ... } | |
137 * 3. enum ident { ... } | |
138 * 4. enum ident : memtype { ... } | |
139 */ | |
140 | |
141 if (memtype) | |
142 { | |
143 memtype = memtype.semantic(loc, sc); | |
144 | |
145 /* Check to see if memtype is forward referenced | |
146 */ | |
147 if (memtype.ty == TY.Tenum) | |
148 { EnumDeclaration sym = cast(EnumDeclaration)memtype.toDsymbol(sc); | |
149 if (!sym.memtype || !sym.members || !sym.symtab || sym.scope_) | |
150 { | |
151 // memtype is forward referenced, so try again later | |
87
b17640f0e4e8
Fixed a bug with a Scope.this(Scope enclosing) being called instead of Scope.clone() method (as a copy ctor replacement)
korDen
parents:
79
diff
changeset
|
152 scope_ = scx ? scx : sc.clone(); |
0 | 153 scope_.setNoFree(); |
154 scope_.module_.addDeferredSemantic(this); | |
179 | 155 global.dprogress = dprogress_save; |
156 //writef("\tdeferring %s\n", toChars()); | |
0 | 157 return; |
158 } | |
159 } | |
138 | 160 static if (false) |
161 { | |
0 | 162 // Decided to abandon this restriction for D 2.0 |
163 if (!memtype.isintegral()) | |
164 { error("base type must be of integral type, not %s", memtype.toChars()); | |
165 memtype = Type.tint32; | |
166 } | |
167 } | |
168 } | |
169 | |
138 | 170 isdone = true; |
179 | 171 global.dprogress++; |
138 | 172 |
0 | 173 type = type.semantic(loc, sc); |
174 if (isAnonymous()) | |
175 sce = sc; | |
176 else | |
177 { sce = sc.push(this); | |
178 sce.parent = this; | |
179 } | |
180 if (members.dim == 0) | |
181 error("enum %s must have at least one member", toChars()); | |
182 int first = 1; | |
183 Expression elast = null; | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
184 foreach (Dsymbol s; members) |
0 | 185 { |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
186 EnumMember em = s.isEnumMember(); |
0 | 187 Expression e; |
188 | |
189 if (!em) | |
190 /* The e.semantic(sce) can insert other symbols, such as | |
191 * template instances and function literals. | |
192 */ | |
193 continue; | |
194 | |
195 //printf(" Enum member '%s'\n",em.toChars()); | |
196 if (em.type) | |
197 em.type = em.type.semantic(em.loc, sce); | |
198 e = em.value; | |
199 if (e) | |
200 { | |
201 assert(e.dyncast() == DYNCAST.DYNCAST_EXPRESSION); | |
202 e = e.semantic(sce); | |
203 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
204 if (memtype) | |
205 { | |
206 e = e.implicitCastTo(sce, memtype); | |
207 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
208 if (!isAnonymous()) | |
209 e = e.castTo(sce, type); | |
210 t = memtype; | |
211 } | |
212 else if (em.type) | |
213 { | |
214 e = e.implicitCastTo(sce, em.type); | |
215 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
216 assert(isAnonymous()); | |
217 t = e.type; | |
218 } | |
219 else | |
220 t = e.type; | |
221 } | |
222 else if (first) | |
223 { | |
224 if (memtype) | |
225 t = memtype; | |
226 else if (em.type) | |
227 t = em.type; | |
228 else | |
229 t = Type.tint32; | |
230 e = new IntegerExp(em.loc, 0, Type.tint32); | |
231 e = e.implicitCastTo(sce, t); | |
232 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
233 if (!isAnonymous()) | |
234 e = e.castTo(sce, type); | |
235 } | |
236 else | |
237 { | |
238 // Set value to (elast + 1). | |
239 // But first check that (elast != t.max) | |
240 assert(elast); | |
241 e = new EqualExp(TOK.TOKequal, em.loc, elast, t.getProperty(Loc(0), Id.max)); | |
242 e = e.semantic(sce); | |
243 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
244 if (e.toInteger()) | |
245 error("overflow of enum value %s", elast.toChars()); | |
246 | |
247 // Now set e to (elast + 1) | |
248 e = new AddExp(em.loc, elast, new IntegerExp(em.loc, 1, Type.tint32)); | |
249 e = e.semantic(sce); | |
250 e = e.castTo(sce, elast.type); | |
251 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
252 } | |
253 elast = e; | |
254 em.value = e; | |
255 | |
256 // Add to symbol table only after evaluating 'value' | |
257 if (isAnonymous()) | |
258 { | |
259 /* Anonymous enum members get added to enclosing scope. | |
260 */ | |
261 for (Scope scxx = sce; scxx; scxx = scxx.enclosing) | |
262 { | |
263 if (scxx.scopesym) | |
264 { | |
265 if (!scxx.scopesym.symtab) | |
266 scxx.scopesym.symtab = new DsymbolTable(); | |
13 | 267 em.addMember(sce, scxx.scopesym, true); |
0 | 268 break; |
269 } | |
270 } | |
271 } | |
272 else | |
13 | 273 em.addMember(sc, this, true); |
0 | 274 |
275 /* Compute .min, .max and .default values. | |
276 * If enum doesn't have a name, we can never identify the enum type, | |
277 * so there is no purpose for a .min, .max or .default | |
278 */ | |
279 if (!isAnonymous()) | |
280 { | |
281 if (first) | |
282 { defaultval = e; | |
283 minval = e; | |
284 maxval = e; | |
285 } | |
286 else | |
287 { Expression ec; | |
288 | |
289 /* In order to work successfully with UDTs, | |
290 * build expressions to do the comparisons, | |
291 * and let the semantic analyzer and constant | |
292 * folder give us the result. | |
293 */ | |
294 | |
295 // Compute if(e < minval) | |
296 ec = new CmpExp(TOK.TOKlt, em.loc, e, minval); | |
297 ec = ec.semantic(sce); | |
298 ec = ec.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
299 if (ec.toInteger()) | |
300 minval = e; | |
301 | |
302 ec = new CmpExp(TOK.TOKgt, em.loc, e, maxval); | |
303 ec = ec.semantic(sce); | |
304 ec = ec.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
305 if (ec.toInteger()) | |
306 maxval = e; | |
307 } | |
308 } | |
309 first = 0; | |
310 } | |
311 //printf("defaultval = %lld\n", defaultval); | |
312 | |
313 //if (defaultval) printf("defaultval: %s %s\n", defaultval.toChars(), defaultval.type.toChars()); | |
314 if (sc != sce) | |
315 sce.pop(); | |
316 //members.print(); | |
317 } | |
318 | |
72 | 319 override bool oneMember(Dsymbol* ps) |
0 | 320 { |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
321 if (isAnonymous()) |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
322 return Dsymbol.oneMembers(members, ps); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
323 return Dsymbol.oneMember(ps); |
0 | 324 } |
325 | |
72 | 326 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 327 { |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
328 buf.writestring("enum "); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
329 if (ident) |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
330 { buf.writestring(ident.toChars()); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
331 buf.writeByte(' '); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
332 } |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
333 if (memtype) |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
334 { |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
335 buf.writestring(": "); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
336 memtype.toCBuffer(buf, null, hgs); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
337 } |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
338 if (!members) |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
339 { |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
340 buf.writeByte(';'); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
341 buf.writenl(); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
342 return; |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
343 } |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
344 buf.writenl(); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
345 buf.writeByte('{'); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
346 buf.writenl(); |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
347 foreach(Dsymbol s; members) |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
348 { |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
349 EnumMember em = s.isEnumMember(); |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
350 if (!em) |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
351 continue; |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
352 //buf.writestring(" "); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
353 em.toCBuffer(buf, hgs); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
354 buf.writeByte(','); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
355 buf.writenl(); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
356 } |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
357 buf.writeByte('}'); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
358 buf.writenl(); |
0 | 359 } |
360 | |
72 | 361 override Type getType() |
0 | 362 { |
363 return type; | |
364 } | |
365 | |
72 | 366 override string kind() |
0 | 367 { |
368 return "enum"; | |
369 } | |
370 | |
371 version (DMDV2) { | |
72 | 372 override Dsymbol search(Loc, Identifier ident, int flags) |
0 | 373 { |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
374 //printf("%s.EnumDeclaration.search('%s')\n", toChars(), ident.toChars()); |
0 | 375 if (scope_) |
376 // Try one last time to resolve this enum | |
377 semantic(scope_); | |
378 | |
379 if (!members || !symtab || scope_) | |
380 { | |
381 error("is forward referenced when looking for '%s'", ident.toChars()); | |
382 //*(char*)0=0; | |
383 return null; | |
384 } | |
385 | |
386 return ScopeDsymbol.search(loc, ident, flags); | |
387 } | |
388 } | |
72 | 389 override bool isDeprecated() // is Dsymbol deprecated? |
0 | 390 { |
391 return isdeprecated; | |
392 } | |
393 | |
72 | 394 override void emitComment(Scope sc) |
0 | 395 { |
396 assert(false); | |
397 } | |
79 | 398 |
399 override void toJsonBuffer(OutBuffer buf) | |
400 { | |
401 //writef("EnumDeclaration.toJsonBuffer()\n"); | |
402 if (isAnonymous()) | |
403 { | |
404 if (members) | |
405 { | |
406 foreach (Dsymbol s; members) | |
407 { | |
408 s.toJsonBuffer(buf); | |
409 buf.writestring(",\n"); | |
410 } | |
411 JsonRemoveComma(buf); | |
412 } | |
413 return; | |
414 } | |
0 | 415 |
79 | 416 buf.writestring("{\n"); |
417 | |
418 JsonProperty(buf, Pname, toChars()); | |
419 JsonProperty(buf, Pkind, kind()); | |
420 if (comment) | |
421 JsonProperty(buf, Pcomment, comment); | |
422 | |
423 if (loc.linnum) | |
424 JsonProperty(buf, Pline, loc.linnum); | |
425 | |
426 if (memtype) | |
427 JsonProperty(buf, "base", memtype.toChars()); | |
428 | |
429 JsonString(buf, Pmembers); | |
430 buf.writestring(" : [\n"); | |
431 size_t offset = buf.offset; | |
432 foreach (Dsymbol s; members) | |
433 { | |
434 if (offset != buf.offset) | |
435 { | |
96 | 436 buf.writestring(",\n"); |
79 | 437 offset = buf.offset; |
438 } | |
439 s.toJsonBuffer(buf); | |
440 } | |
96 | 441 JsonRemoveComma(buf); |
79 | 442 buf.writestring("]\n"); |
443 | |
444 buf.writestring("}\n"); | |
445 } | |
446 | |
72 | 447 override void toDocBuffer(OutBuffer buf) |
0 | 448 { |
449 assert(false); | |
450 } | |
451 | |
72 | 452 override EnumDeclaration isEnumDeclaration() { return this; } |
0 | 453 |
72 | 454 override void toObjFile(int multiobj) // compile to .obj file |
0 | 455 { |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
456 //printf("EnumDeclaration.toObjFile('%s')\n", toChars()); |
0 | 457 version (DMDV2) { |
458 if (isAnonymous()) | |
459 return; | |
460 } | |
461 | |
462 if (global.params.symdebug) | |
463 toDebug(); | |
464 | |
465 type.getTypeInfo(null); // generate TypeInfo | |
466 | |
467 TypeEnum tc = cast(TypeEnum)type; | |
468 if (!tc.sym.defaultval || type.isZeroInit(Loc(0))) { | |
469 ; | |
470 } else { | |
471 SC scclass = SCglobal; | |
472 if (inTemplateInstance()) | |
473 scclass = SCcomdat; | |
474 | |
475 // Generate static initializer | |
476 toInitializer(); | |
477 sinit.Sclass = scclass; | |
478 sinit.Sfl = FLdata; | |
479 version (ELFOBJ) { // Burton | |
480 sinit.Sseg = Segment.CDATA; | |
481 } | |
482 version (MACHOBJ) { | |
483 sinit.Sseg = Segment.DATA; | |
484 } | |
485 version (DMDV1) { | |
486 dtnbytes(&sinit.Sdt, tc.size(0), cast(char*)&tc.sym.defaultval); | |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
487 //sinit.Sdt = tc.sym.init.toDt(); |
0 | 488 } |
489 version (DMDV2) { | |
490 tc.sym.defaultval.toDt(&sinit.Sdt); | |
491 } | |
492 outdata(sinit); | |
493 } | |
494 } | |
495 | |
496 void toDebug() | |
497 { | |
498 assert(false); | |
499 } | |
500 | |
72 | 501 override int cvMember(ubyte* p) |
0 | 502 { |
503 assert(false); | |
504 } | |
505 | |
506 Symbol* sinit; | |
507 | |
508 Symbol* toInitializer() | |
509 { | |
510 Symbol* s; | |
511 Classsym* stag; | |
512 | |
513 if (!sinit) | |
514 { | |
515 stag = fake_classsym(Id.ClassInfo); | |
516 Identifier ident_save = ident; | |
517 if (!ident) | |
518 ident = Lexer.uniqueId("__enum"); | |
519 s = toSymbolX("__init", SCextern, stag.Stype, "Z"); | |
520 ident = ident_save; | |
521 s.Sfl = FLextern; | |
522 s.Sflags |= SFLnodebug; | |
523 slist_add(s); | |
524 sinit = s; | |
525 } | |
526 | |
527 return sinit; | |
528 } | |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
529 }; |