Mercurial > projects > ddmd
annotate dmd/VarDeclaration.d @ 53:a8b50ff7f201
ForeachStatement.syntaxCopy
SliceExp.syntaxCopy
AnonDeclaration.syntaxCopy
SwitchStatement.syntaxCopy
CaseStatement.syntaxCopy
BreakStatement.syntaxCopy
ThrowStatement.syntaxCopy
NewExp.syntaxCopy
DefaultStatement.syntaxCopy
AssertExp.syntaxCopy
ClassDeclaration.syntaxCopy
TypeTypedef.constConv
eval_builtin
ComplexExp.isConst
DVCondition.syntaxCopy
OrExp.getIntRange
AndExp.getIntRange
getMask
IntegerExp.getIntRange
Type.sizemask
CastExp.getIntRange
Expression.getIntRange
author | korDen |
---|---|
date | Sat, 21 Aug 2010 12:15:47 +0400 |
parents | 460959608115 |
children | ee3a9f34dc48 |
rev | line source |
---|---|
0 | 1 module dmd.VarDeclaration; |
2 | |
3 import dmd.Declaration; | |
4 import dmd.SliceExp; | |
5 import dmd.ClassDeclaration; | |
6 import dmd.DeleteExp; | |
7 import dmd.SymOffExp; | |
8 import dmd.DotIdExp; | |
9 import dmd.PtrExp; | |
10 import dmd.CallExp; | |
11 import dmd.DotVarExp; | |
12 import dmd.CommaExp; | |
13 import dmd.CastExp; | |
14 import dmd.WANT; | |
15 import dmd.StructDeclaration; | |
16 import dmd.DsymbolExp; | |
17 import dmd.TypeSArray; | |
18 import dmd.IntegerExp; | |
19 import dmd.VarExp; | |
20 import dmd.AssignExp; | |
21 import dmd.TypeTypedef; | |
22 import dmd.ArrayInitializer; | |
23 import dmd.StructInitializer; | |
24 import dmd.NewExp; | |
25 import dmd.TupleDeclaration; | |
26 import dmd.AggregateDeclaration; | |
27 import dmd.InterfaceDeclaration; | |
28 import dmd.TemplateInstance; | |
29 import dmd.Id; | |
30 import dmd.Initializer; | |
31 import dmd.TypeStruct; | |
32 import dmd.TypeTuple; | |
33 import dmd.Argument; | |
34 import dmd.ExpInitializer; | |
35 import dmd.ArrayTypes; | |
36 import dmd.Dsymbol; | |
37 import dmd.Expression; | |
38 import dmd.Loc; | |
39 import dmd.STC; | |
40 import dmd.TOK; | |
41 import dmd.TupleExp; | |
42 import dmd.Global; | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
16
diff
changeset
|
43 import dmd.Module; |
0 | 44 import dmd.FuncDeclaration; |
45 import dmd.Type; | |
46 import dmd.TY; | |
47 import dmd.LINK; | |
48 import dmd.Scope; | |
49 import dmd.Identifier; | |
50 import dmd.OutBuffer; | |
51 import dmd.HdrGenState; | |
52 import dmd.PROT; | |
53 | |
54 import dmd.backend.Symbol; | |
55 import dmd.backend.TYM; | |
56 import dmd.backend.FL; | |
57 import dmd.backend.DT; | |
58 import dmd.backend.mTY; | |
59 import dmd.backend.SC; | |
60 import dmd.backend.mTYman; | |
61 import dmd.backend.TYPE; | |
62 import dmd.backend.Util; | |
63 import dmd.backend.LIST; | |
64 | |
65 import std.stdio : writef; | |
66 import std.string : toStringz; | |
67 | |
68 class VarDeclaration : Declaration | |
69 { | |
70 Initializer init; | |
71 uint offset; | |
72 bool noauto; // no auto semantics | |
73 version (DMDV2) { | |
74 FuncDeclarations nestedrefs; // referenced by these lexically nested functions | |
75 } else { | |
76 int nestedref; // referenced by a lexically nested function | |
77 } | |
78 int ctorinit; // it has been initialized in a ctor | |
79 int onstack; // 1: it has been allocated on the stack | |
80 // 2: on stack, run destructor anyway | |
81 int canassign; // it can be assigned to | |
82 Dsymbol aliassym; // if redone as alias to another symbol | |
83 Expression value; // when interpreting, this is the value | |
84 // (null if value not determinable) | |
85 version (DMDV2) { | |
86 VarDeclaration rundtor; // if !null, rundtor is tested at runtime to see | |
87 // if the destructor should be run. Used to prevent | |
88 // dtor calls on postblitted vars | |
89 } | |
90 | |
91 this(Loc loc, Type type, Identifier id, Initializer init) | |
92 { | |
93 super(id); | |
94 | |
95 debug { | |
96 if (!type && !init) | |
97 { | |
98 writef("VarDeclaration('%s')\n", id.toChars()); | |
99 //*(char*)0=0; | |
100 } | |
101 } | |
102 assert(type || init); | |
103 this.type = type; | |
104 this.init = init; | |
105 this.loc = loc; | |
106 | |
107 nestedrefs = new FuncDeclarations(); | |
108 } | |
109 | |
110 Dsymbol syntaxCopy(Dsymbol s) | |
111 { | |
112 //printf("VarDeclaration.syntaxCopy(%s)\n", toChars()); | |
113 | |
114 VarDeclaration sv; | |
115 if (s) | |
116 { | |
117 sv = cast(VarDeclaration)s; | |
118 } | |
119 else | |
120 { | |
121 Initializer init = null; | |
122 if (this.init) | |
123 { | |
124 init = this.init.syntaxCopy(); | |
125 //init.isExpInitializer().exp.print(); | |
126 //init.isExpInitializer().exp.dump(0); | |
127 } | |
128 | |
129 sv = new VarDeclaration(loc, type ? type.syntaxCopy() : null, ident, init); | |
130 sv.storage_class = storage_class; | |
131 } | |
132 | |
133 version (_DH) { | |
134 // Syntax copy for header file | |
135 if (!htype) // Don't overwrite original | |
136 { | |
137 if (type) // Make copy for both old and new instances | |
138 { htype = type.syntaxCopy(); | |
139 sv.htype = type.syntaxCopy(); | |
140 } | |
141 } | |
142 else // Make copy of original for new instance | |
143 sv.htype = htype.syntaxCopy(); | |
144 if (!hinit) | |
145 { | |
146 if (init) | |
147 { | |
148 hinit = init.syntaxCopy(); | |
149 sv.hinit = init.syntaxCopy(); | |
150 } | |
151 } | |
152 else | |
153 sv.hinit = hinit.syntaxCopy(); | |
154 } | |
155 return sv; | |
156 } | |
157 | |
158 void semantic(Scope sc) | |
159 { | |
160 static if (false) { | |
161 printf("VarDeclaration.semantic('%s', parent = '%s')\n", toChars(), sc.parent.toChars()); | |
162 printf(" type = %s\n", type ? type.toChars() : "null"); | |
163 printf(" stc = x%x\n", sc.stc); | |
164 printf(" storage_class = x%x\n", storage_class); | |
165 printf("linkage = %d\n", sc.linkage); | |
166 //if (strcmp(toChars(), "mul") == 0) halt(); | |
167 } | |
168 | |
169 storage_class |= sc.stc; | |
170 if (storage_class & STC.STCextern && init) | |
171 error("extern symbols cannot have initializers"); | |
172 | |
173 /* If auto type inference, do the inference | |
174 */ | |
175 int inferred = 0; | |
176 if (!type) | |
177 { | |
178 inuse++; | |
179 type = init.inferType(sc); | |
180 inuse--; | |
181 inferred = 1; | |
182 | |
183 /* This is a kludge to support the existing syntax for RAII | |
184 * declarations. | |
185 */ | |
186 storage_class &= ~STC.STCauto; | |
187 originalType = type; | |
188 } | |
189 else | |
190 { | |
191 if (!originalType) | |
192 originalType = type; | |
193 | |
194 type = type.semantic(loc, sc); | |
195 } | |
196 //printf(" semantic type = %s\n", type ? type.toChars() : "null"); | |
197 | |
198 type.checkDeprecated(loc, sc); | |
199 linkage = sc.linkage; | |
200 this.parent = sc.parent; | |
201 //printf("this = %p, parent = %p, '%s'\n", this, parent, parent.toChars()); | |
202 protection = sc.protection; | |
203 //printf("sc.stc = %x\n", sc.stc); | |
204 //printf("storage_class = x%x\n", storage_class); | |
205 | |
206 version (DMDV2) { | |
207 if (storage_class & STC.STCgshared && global.params.safe && !sc.module_.safe) | |
208 { | |
209 error("__gshared not allowed in safe mode; use shared"); | |
210 } | |
211 } | |
212 | |
213 Dsymbol parent = toParent(); | |
214 FuncDeclaration fd = parent.isFuncDeclaration(); | |
215 | |
216 Type tb = type.toBasetype(); | |
217 if (tb.ty == TY.Tvoid && !(storage_class & STC.STClazy)) | |
218 { error("voids have no value"); | |
219 type = Type.terror; | |
220 tb = type; | |
221 } | |
222 if (tb.ty == TY.Tfunction) | |
223 { error("cannot be declared to be a function"); | |
224 type = Type.terror; | |
225 tb = type; | |
226 } | |
227 if (tb.ty == TY.Tstruct) | |
228 { TypeStruct ts = cast(TypeStruct)tb; | |
229 | |
230 if (!ts.sym.members) | |
231 { | |
232 error("no definition of struct %s", ts.toChars()); | |
233 } | |
234 } | |
235 | |
236 if (tb.ty == TY.Ttuple) | |
237 { /* Instead, declare variables for each of the tuple elements | |
238 * and add those. | |
239 */ | |
240 TypeTuple tt = cast(TypeTuple)tb; | |
241 size_t nelems = Argument.dim(tt.arguments); | |
242 Objects exps = new Objects(); | |
243 exps.setDim(nelems); | |
244 Expression ie = init ? init.toExpression() : null; | |
245 | |
246 for (size_t i = 0; i < nelems; i++) | |
247 { Argument arg = Argument.getNth(tt.arguments, i); | |
248 | |
16
5c9b78899f5d
Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
249 OutBuffer buf = new OutBuffer(); |
53 | 250 ///buf.printf("_%s_field_%zu", ident.toChars(), i); |
251 buf.printf("_%s_field_%s", ident.toChars(), i); | |
0 | 252 buf.writeByte(0); |
253 string name = buf.extractString(); | |
254 Identifier id = new Identifier(name, TOK.TOKidentifier); | |
255 | |
256 Expression einit = ie; | |
257 if (ie && ie.op == TOK.TOKtuple) | |
258 { einit = cast(Expression)(cast(TupleExp)ie).exps.data[i]; | |
259 } | |
260 Initializer ti = init; | |
261 if (einit) | |
262 { ti = new ExpInitializer(einit.loc, einit); | |
263 } | |
264 | |
265 VarDeclaration v = new VarDeclaration(loc, arg.type, id, ti); | |
266 //printf("declaring field %s of type %s\n", v.toChars(), v.type.toChars()); | |
267 v.semantic(sc); | |
268 | |
269 if (sc.scopesym) | |
270 { //printf("adding %s to %s\n", v.toChars(), sc.scopesym.toChars()); | |
271 if (sc.scopesym.members) | |
272 sc.scopesym.members.push(cast(void*)v); | |
273 } | |
274 | |
275 Expression e = new DsymbolExp(loc, v); | |
276 exps.data[i] = cast(void*)e; | |
277 } | |
278 TupleDeclaration v2 = new TupleDeclaration(loc, ident, exps); | |
279 v2.isexp = 1; | |
280 aliassym = v2; | |
281 return; | |
282 } | |
283 | |
284 Lagain: | |
285 /* Storage class can modify the type | |
286 */ | |
287 type = type.addStorageClass(storage_class); | |
288 | |
289 /* Adjust storage class to reflect type | |
290 */ | |
291 if (type.isConst()) | |
292 { storage_class |= STC.STCconst; | |
293 if (type.isShared()) | |
294 storage_class |= STC.STCshared; | |
295 } | |
296 else if (type.isInvariant()) | |
297 storage_class |= STC.STCimmutable; | |
298 else if (type.isShared()) | |
299 storage_class |= STC.STCshared; | |
300 | |
301 if (isSynchronized()) | |
302 { | |
303 error("variable %s cannot be synchronized", toChars()); | |
304 } | |
305 else if (isOverride()) | |
306 { | |
307 error("override cannot be applied to variable"); | |
308 } | |
309 else if (isAbstract()) | |
310 { | |
311 error("abstract cannot be applied to variable"); | |
312 } | |
313 else if (storage_class & STC.STCfinal) | |
314 { | |
315 error("final cannot be applied to variable"); | |
316 } | |
317 | |
318 if (storage_class & (STC.STCstatic | STC.STCextern | STC.STCmanifest | STC.STCtemplateparameter | STC.STCtls | STC.STCgshared)) | |
319 { | |
320 } | |
321 else | |
322 { | |
323 AggregateDeclaration aad = sc.anonAgg; | |
324 if (!aad) | |
325 aad = parent.isAggregateDeclaration(); | |
326 if (aad) | |
327 { | |
328 ///version (DMDV2) { | |
329 assert(!(storage_class & (STC.STCextern | STC.STCstatic | STC.STCtls | STC.STCgshared))); | |
330 | |
331 if (storage_class & (STC.STCconst | STC.STCimmutable) && init) | |
332 { | |
333 if (!type.toBasetype().isTypeBasic()) | |
334 storage_class |= STC.STCstatic; | |
335 } | |
336 else | |
337 ///} | |
338 aad.addField(sc, this); | |
339 } | |
340 | |
341 InterfaceDeclaration id = parent.isInterfaceDeclaration(); | |
342 if (id) | |
343 { | |
344 error("field not allowed in interface"); | |
345 } | |
346 | |
347 /* Templates cannot add fields to aggregates | |
348 */ | |
349 TemplateInstance ti = parent.isTemplateInstance(); | |
350 if (ti) | |
351 { | |
352 // Take care of nested templates | |
353 while (1) | |
354 { | |
355 TemplateInstance ti2 = ti.tempdecl.parent.isTemplateInstance(); | |
356 if (!ti2) | |
357 break; | |
358 ti = ti2; | |
359 } | |
360 | |
361 // If it's a member template | |
362 AggregateDeclaration ad = ti.tempdecl.isMember(); | |
363 if (ad && storage_class != STC.STCundefined) | |
364 { | |
365 error("cannot use template to add field to aggregate '%s'", ad.toChars()); | |
366 } | |
367 } | |
368 } | |
369 | |
370 version (DMDV2) { | |
371 if ((storage_class & (STC.STCref | STC.STCparameter | STC.STCforeach)) == STC.STCref && ident != Id.This) | |
372 { | |
373 error("only parameters or foreach declarations can be ref"); | |
374 } | |
375 } | |
376 | |
377 if (type.isauto() && !noauto) | |
378 { | |
379 if (storage_class & (STC.STCfield | STC.STCout | STC.STCref | STC.STCstatic | STC.STCmanifest | STC.STCtls | STC.STCgshared) || !fd) | |
380 { | |
381 error("globals, statics, fields, manifest constants, ref and out parameters cannot be scope"); | |
382 } | |
383 | |
384 if (!(storage_class & (STC.STCauto | STC.STCscope))) | |
385 { | |
386 if (!(storage_class & STC.STCparameter) && ident != Id.withSym) | |
387 error("reference to scope class must be scope"); | |
388 } | |
389 } | |
390 | |
391 if ((isConst() || isInvariant()) && !init && !fd) | |
392 { | |
393 // Initialize by constructor only | |
394 storage_class |= STC.STCctorinit; | |
395 } | |
396 | |
397 if (init) | |
398 storage_class |= STC.STCinit; // remember we had an explicit initializer | |
399 else if (storage_class & STC.STCmanifest) | |
400 error("manifest constants must have initializers"); | |
401 | |
402 TOK op = TOK.TOKconstruct; | |
403 if (!init && !sc.inunion && !isStatic() && fd && | |
404 (!(storage_class & (STC.STCfield | STC.STCin | STC.STCforeach | STC.STCparameter)) || (storage_class & STC.STCout)) && | |
405 type.size() != 0) | |
406 { | |
407 // Provide a default initializer | |
408 //printf("Providing default initializer for '%s'\n", toChars()); | |
409 if (type.ty == TY.Tstruct && | |
410 (cast(TypeStruct)type).sym.zeroInit) | |
411 { /* If a struct is all zeros, as a special case | |
412 * set it's initializer to the integer 0. | |
413 * In AssignExp.toElem(), we check for this and issue | |
414 * a memset() to initialize the struct. | |
415 * Must do same check in interpreter. | |
416 */ | |
417 Expression e = new IntegerExp(loc, 0, Type.tint32); | |
418 Expression e1; | |
419 e1 = new VarExp(loc, this); | |
420 e = new AssignExp(loc, e1, e); | |
421 e.op = TOK.TOKconstruct; | |
422 e.type = e1.type; // don't type check this, it would fail | |
423 init = new ExpInitializer(loc, e); | |
424 return; | |
425 } | |
426 else if (type.ty == TY.Ttypedef) | |
427 { TypeTypedef td = cast(TypeTypedef)type; | |
428 if (td.sym.init) | |
429 { init = td.sym.init; | |
430 ExpInitializer ie = init.isExpInitializer(); | |
431 if (ie) | |
432 // Make copy so we can modify it | |
433 init = new ExpInitializer(ie.loc, ie.exp); | |
434 } | |
435 else | |
436 init = getExpInitializer(); | |
437 } | |
438 else | |
439 { | |
440 init = getExpInitializer(); | |
441 } | |
442 // Default initializer is always a blit | |
443 op = TOK.TOKblit; | |
444 } | |
445 | |
446 if (init) | |
447 { | |
448 sc = sc.push(); | |
449 sc.stc &= ~(STC.STC_TYPECTOR | STC.STCpure | STC.STCnothrow | STC.STCref); | |
450 | |
451 ArrayInitializer ai = init.isArrayInitializer(); | |
452 if (ai && tb.ty == TY.Taarray) | |
453 { | |
454 init = ai.toAssocArrayInitializer(); | |
455 } | |
456 | |
457 StructInitializer si = init.isStructInitializer(); | |
458 ExpInitializer ei = init.isExpInitializer(); | |
459 | |
460 // See if initializer is a NewExp that can be allocated on the stack | |
461 if (ei && isScope() && ei.exp.op == TOK.TOKnew) | |
462 { NewExp ne = cast(NewExp)ei.exp; | |
463 if (!(ne.newargs && ne.newargs.dim)) | |
464 { ne.onstack = 1; | |
465 onstack = 1; | |
466 if (type.isBaseOf(ne.newtype.semantic(loc, sc), null)) | |
467 onstack = 2; | |
468 } | |
469 } | |
470 | |
471 // If inside function, there is no semantic3() call | |
472 if (sc.func) | |
473 { | |
474 // If local variable, use AssignExp to handle all the various | |
475 // possibilities. | |
476 if (fd && | |
477 !(storage_class & (STC.STCmanifest | STC.STCstatic | STC.STCtls | STC.STCgshared | STC.STCextern)) && | |
478 !init.isVoidInitializer()) | |
479 { | |
480 //printf("fd = '%s', var = '%s'\n", fd.toChars(), toChars()); | |
481 if (!ei) | |
482 { | |
483 Expression e = init.toExpression(); | |
484 if (!e) | |
485 { | |
486 init = init.semantic(sc, type); | |
487 e = init.toExpression(); | |
488 if (!e) | |
489 { error("is not a static and cannot have static initializer"); | |
490 return; | |
491 } | |
492 } | |
493 ei = new ExpInitializer(init.loc, e); | |
494 init = ei; | |
495 } | |
496 | |
497 Expression e1 = new VarExp(loc, this); | |
498 | |
499 Type t = type.toBasetype(); | |
500 if (t.ty == TY.Tsarray && !(storage_class & (STC.STCref | STC.STCout))) | |
501 { | |
502 ei.exp = ei.exp.semantic(sc); | |
503 if (!ei.exp.implicitConvTo(type)) | |
504 { | |
505 int dim = cast(int)(cast(TypeSArray)t).dim.toInteger(); /// | |
506 // If multidimensional static array, treat as one large array | |
507 while (1) | |
508 { | |
509 t = t.nextOf().toBasetype(); | |
510 if (t.ty != TY.Tsarray) | |
511 break; | |
512 dim *= (cast(TypeSArray)t).dim.toInteger(); | |
513 e1.type = new TypeSArray(t.nextOf(), new IntegerExp(Loc(0), dim, Type.tindex)); | |
514 } | |
515 } | |
516 e1 = new SliceExp(loc, e1, null, null); | |
517 } | |
518 else if (t.ty == TY.Tstruct) | |
519 { | |
520 ei.exp = ei.exp.semantic(sc); | |
521 version (DMDV2) { | |
522 /* Look to see if initializer is a call to the constructor | |
523 */ | |
524 StructDeclaration sd = (cast(TypeStruct)t).sym; | |
525 if (sd.ctor && // there are constructors | |
526 ei.exp.type.ty == TY.Tstruct && // rvalue is the same struct | |
527 (cast(TypeStruct)ei.exp.type).sym == sd && | |
528 ei.exp.op == TOK.TOKstar) | |
529 { | |
530 /* Look for form of constructor call which is: | |
531 * *__ctmp.ctor(arguments...) | |
532 */ | |
533 PtrExp pe = cast(PtrExp)ei.exp; | |
534 if (pe.e1.op == TOK.TOKcall) | |
535 { CallExp ce = cast(CallExp)pe.e1; | |
536 if (ce.e1.op == TOK.TOKdotvar) | |
537 { DotVarExp dve = cast(DotVarExp)ce.e1; | |
538 if (dve.var.isCtorDeclaration()) | |
539 { /* It's a constructor call, currently constructing | |
540 * a temporary __ctmp. | |
541 */ | |
542 /* Before calling the constructor, initialize | |
543 * variable with a bit copy of the default | |
544 * initializer | |
545 */ | |
546 Expression e = new AssignExp(loc, new VarExp(loc, this), t.defaultInit(loc)); | |
547 e.op = TOK.TOKblit; | |
548 e.type = t; | |
549 ei.exp = new CommaExp(loc, e, ei.exp); | |
550 | |
551 /* Replace __ctmp being constructed with e1 | |
552 */ | |
553 dve.e1 = e1; | |
554 return; | |
555 } | |
556 } | |
557 } | |
558 } | |
559 } | |
560 if (!ei.exp.implicitConvTo(type)) | |
561 { Type ti = ei.exp.type.toBasetype(); | |
562 // Don't cast away invariant or mutability in initializer | |
563 if (!(ti.ty == TY.Tstruct && t.toDsymbol(sc) == ti.toDsymbol(sc))) | |
564 ei.exp = new CastExp(loc, ei.exp, type); | |
565 } | |
566 } | |
567 ei.exp = new AssignExp(loc, e1, ei.exp); | |
568 ei.exp.op = op; | |
569 canassign++; | |
570 ei.exp = ei.exp.semantic(sc); | |
571 canassign--; | |
572 ei.exp.optimize(WANT.WANTvalue); | |
573 } | |
574 else | |
575 { | |
576 init = init.semantic(sc, type); | |
577 } | |
578 } | |
579 else if (storage_class & (STC.STCconst | STC.STCimmutable | STC.STCmanifest) || | |
580 type.isConst() || type.isInvariant()) | |
581 { | |
582 /* Because we may need the results of a const declaration in a | |
583 * subsequent type, such as an array dimension, before semantic2() | |
584 * gets ordinarily run, try to run semantic2() now. | |
585 * Ignore failure. | |
586 */ | |
587 | |
588 if (!global.errors && !inferred) | |
589 { | |
590 uint errors = global.errors; | |
591 global.gag++; | |
592 //printf("+gag\n"); | |
593 Expression e; | |
594 Initializer i2 = init; | |
595 inuse++; | |
596 if (ei) | |
597 { | |
598 e = ei.exp.syntaxCopy(); | |
599 e = e.semantic(sc); | |
600 e = e.implicitCastTo(sc, type); | |
601 } | |
602 else if (si || ai) | |
603 { i2 = init.syntaxCopy(); | |
604 i2 = i2.semantic(sc, type); | |
605 } | |
606 inuse--; | |
607 global.gag--; | |
608 //printf("-gag\n"); | |
609 if (errors != global.errors) // if errors happened | |
610 { | |
611 if (global.gag == 0) | |
612 global.errors = errors; // act as if nothing happened | |
613 version (DMDV2) { | |
614 /* Save scope for later use, to try again | |
615 */ | |
616 scope_ = new Scope(sc); | |
617 scope_.setNoFree(); | |
618 } | |
619 } | |
620 else if (ei) | |
621 { | |
622 if (isDataseg()) | |
623 /* static const/invariant does CTFE | |
624 */ | |
625 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
626 else | |
627 e = e.optimize(WANT.WANTvalue); | |
628 if (e.op == TOK.TOKint64 || e.op == TOK.TOKstring || e.op == TOK.TOKfloat64) | |
629 { | |
630 ei.exp = e; // no errors, keep result | |
631 } | |
632 ///version (DMDV2) { | |
633 else | |
634 { | |
635 /* Save scope for later use, to try again | |
636 */ | |
637 scope_ = new Scope(sc); | |
638 scope_.setNoFree(); | |
639 } | |
640 ///} | |
641 } | |
642 else | |
643 init = i2; // no errors, keep result | |
644 } | |
645 } | |
646 sc = sc.pop(); | |
647 } | |
648 } | |
649 | |
650 void semantic2(Scope sc) | |
651 { | |
652 //printf("VarDeclaration.semantic2('%s')\n", toChars()); | |
653 if (init && !toParent().isFuncDeclaration()) | |
654 { | |
655 inuse++; | |
656 static if (false) { | |
657 ExpInitializer ei = init.isExpInitializer(); | |
658 if (ei) | |
659 { | |
660 ei.exp.dump(0); | |
661 printf("type = %p\n", ei.exp.type); | |
662 } | |
663 } | |
664 init = init.semantic(sc, type); | |
665 inuse--; | |
666 } | |
667 } | |
668 | |
669 string kind() | |
670 { | |
671 return "variable"; | |
672 } | |
673 | |
674 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
675 { | |
676 assert(false); | |
677 } | |
678 | |
679 version (_DH) { | |
680 Type htype; | |
681 Initializer hinit; | |
682 } | |
683 bool needThis() | |
684 { | |
685 //printf("VarDeclaration.needThis(%s, x%x)\n", toChars(), storage_class); | |
686 return (storage_class & STC.STCfield) != 0; | |
687 } | |
688 | |
689 bool isImportedSymbol() | |
690 { | |
691 if (protection == PROT.PROTexport && !init && (storage_class & STC.STCstatic || parent.isModule())) | |
692 return true; | |
693 | |
694 return false; | |
695 } | |
696 | |
697 bool isDataseg() | |
698 { | |
699 static if (false) { | |
700 printf("VarDeclaration.isDataseg(%p, '%s')\n", this, toChars()); | |
701 printf("%x, %p, %p\n", storage_class & (STC.STCstatic | STC.STCconst), parent.isModule(), parent.isTemplateInstance()); | |
702 printf("parent = '%s'\n", parent.toChars()); | |
703 } | |
704 if (storage_class & STC.STCmanifest) | |
705 return false; | |
706 | |
707 Dsymbol parent = this.toParent(); | |
708 if (!parent && !(storage_class & STC.STCstatic)) | |
709 { | |
710 error("forward referenced"); | |
711 type = Type.terror; | |
712 return false; | |
713 } | |
714 | |
715 return canTakeAddressOf() && (storage_class & (STC.STCstatic | STC.STCextern | STC.STCtls | STC.STCgshared) || toParent().isModule() || toParent().isTemplateInstance()); | |
716 } | |
717 | |
718 bool isThreadlocal() | |
719 { | |
720 //printf("VarDeclaration.isThreadlocal(%p, '%s')\n", this, toChars()); | |
721 static if (false) { /// || TARGET_OSX | |
722 /* To be thread-local, must use the __thread storage class. | |
723 * BUG: OSX doesn't support thread local yet. | |
724 */ | |
725 return isDataseg() && (storage_class & (STC.STCtls | STC.STCconst | STC.STCimmutable | STC.STCshared | STC.STCgshared)) == STC.STCtls; | |
726 } else { | |
727 /* Data defaults to being thread-local. It is not thread-local | |
728 * if it is immutable, const or shared. | |
729 */ | |
730 bool i = isDataseg() && !(storage_class & (STC.STCimmutable | STC.STCconst | STC.STCshared | STC.STCgshared)); | |
731 //printf("\treturn %d\n", i); | |
732 return i; | |
733 } | |
734 } | |
735 | |
736 bool hasPointers() | |
737 { | |
738 //printf("VarDeclaration.hasPointers() %s, ty = %d\n", toChars(), type.ty); | |
739 return (!isDataseg() && type.hasPointers()); | |
740 } | |
741 | |
742 version (DMDV2) { | |
743 bool canTakeAddressOf() | |
744 { | |
745 static if (false) { | |
746 /* Global variables and struct/class fields of the form: | |
747 * const int x = 3; | |
748 * are not stored and hence cannot have their address taken. | |
749 */ | |
750 if ((isConst() || isInvariant()) && (storage_class & STC.STCinit) && (!(storage_class & (STC.STCstatic | STC.STCextern)) || (storage_class & STC.STCfield)) && | |
751 (!parent || toParent().isModule() || toParent().isTemplateInstance()) && type.toBasetype().isTypeBasic()) | |
752 { | |
753 return false; | |
754 } | |
755 } else { | |
756 if (storage_class & STC.STCmanifest) | |
757 return false; | |
758 } | |
759 return true; | |
760 } | |
761 | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
762 /****************************************** |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
763 * Return TRUE if variable needs to call the destructor. |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
764 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
765 bool needsAutoDtor() |
0 | 766 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
767 //printf("VarDeclaration.needsAutoDtor() %s\n", toChars()); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
768 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
769 if (noauto || storage_class & STCnodtor) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
770 return false; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
771 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
772 // Destructors for structs and arrays of structs |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
773 Type tv = type.toBasetype(); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
774 while (tv.ty == Tsarray) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
775 { |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
776 TypeSArray ta = cast(TypeSArray)tv; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
777 tv = tv.nextOf().toBasetype(); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
778 } |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
779 if (tv.ty == Tstruct) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
780 { |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
781 TypeStruct ts = cast(TypeStruct)tv; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
782 StructDeclaration sd = ts.sym; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
783 if (sd.dtor) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
784 return true; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
785 } |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
786 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
787 // Destructors for classes |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
788 if (storage_class & (STCauto | STCscope)) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
789 { |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
790 if (type.isClassHandle()) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
791 return true; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
792 } |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
793 return false; |
0 | 794 } |
795 } | |
796 | |
797 /****************************************** | |
798 * If a variable has an auto destructor call, return call for it. | |
799 * Otherwise, return null. | |
800 */ | |
801 Expression callAutoDtor(Scope sc) | |
802 { | |
803 Expression e = null; | |
804 | |
805 //printf("VarDeclaration.callAutoDtor() %s\n", toChars()); | |
806 | |
807 if (noauto || storage_class & STC.STCnodtor) | |
808 return null; | |
809 | |
810 // Destructors for structs and arrays of structs | |
811 bool array = false; | |
812 Type tv = type.toBasetype(); | |
813 while (tv.ty == TY.Tsarray) | |
814 { | |
815 TypeSArray ta = cast(TypeSArray)tv; | |
816 array = true; | |
817 tv = tv.nextOf().toBasetype(); | |
818 } | |
819 if (tv.ty == TY.Tstruct) | |
820 { | |
821 TypeStruct ts = cast(TypeStruct)tv; | |
822 StructDeclaration sd = ts.sym; | |
823 if (sd.dtor) | |
824 { | |
825 if (array) | |
826 { | |
827 // Typeinfo.destroy(cast(void*)&v); | |
828 Expression ea = new SymOffExp(loc, this, 0, 0); | |
829 ea = new CastExp(loc, ea, Type.tvoid.pointerTo()); | |
830 Expressions args = new Expressions(); | |
831 args.push(cast(void*)ea); | |
832 | |
833 Expression et = type.getTypeInfo(sc); | |
834 et = new DotIdExp(loc, et, Id.destroy); | |
835 | |
836 e = new CallExp(loc, et, args); | |
837 } | |
838 else | |
839 { | |
840 e = new VarExp(loc, this); | |
841 e = new DotVarExp(loc, e, sd.dtor, 0); | |
842 e = new CallExp(loc, e); | |
843 } | |
844 return e; | |
845 } | |
846 } | |
847 | |
848 // Destructors for classes | |
849 if (storage_class & (STC.STCauto | STC.STCscope)) | |
850 { | |
851 for (ClassDeclaration cd = type.isClassHandle(); cd; cd = cd.baseClass) | |
852 { | |
853 /* We can do better if there's a way with onstack | |
854 * classes to determine if there's no way the monitor | |
855 * could be set. | |
856 */ | |
857 //if (cd.isInterfaceDeclaration()) | |
858 //error("interface %s cannot be scope", cd.toChars()); | |
859 if (1 || onstack || cd.dtors.dim) // if any destructors | |
860 { | |
861 // delete this; | |
862 Expression ec = new VarExp(loc, this); | |
863 e = new DeleteExp(loc, ec); | |
864 e.type = Type.tvoid; | |
865 break; | |
866 } | |
867 } | |
868 } | |
869 return e; | |
870 } | |
871 | |
872 /**************************** | |
873 * Get ExpInitializer for a variable, if there is one. | |
874 */ | |
875 ExpInitializer getExpInitializer() | |
876 { | |
877 ExpInitializer ei; | |
878 | |
879 if (init) | |
880 ei = init.isExpInitializer(); | |
881 else | |
882 { | |
883 Expression e = type.defaultInit(loc); | |
884 if (e) | |
885 ei = new ExpInitializer(loc, e); | |
886 else | |
887 ei = null; | |
888 } | |
889 return ei; | |
890 } | |
891 | |
892 /******************************************* | |
893 * If variable has a constant expression initializer, get it. | |
894 * Otherwise, return null. | |
895 */ | |
896 Expression getConstInitializer() | |
897 { | |
898 if ((isConst() || isInvariant() || storage_class & STC.STCmanifest) && storage_class & STC.STCinit) | |
899 { | |
900 ExpInitializer ei = getExpInitializer(); | |
901 if (ei) | |
902 return ei.exp; | |
903 } | |
904 | |
905 return null; | |
906 } | |
907 | |
908 void checkCtorConstInit() | |
909 { | |
910 static if (false) { /* doesn't work if more than one static ctor */ | |
911 if (ctorinit == 0 && isCtorinit() && !(storage_class & STCfield)) | |
912 error("missing initializer in static constructor for const variable"); | |
913 } | |
914 } | |
915 | |
916 /************************************ | |
917 * Check to see if this variable is actually in an enclosing function | |
918 * rather than the current one. | |
919 */ | |
920 void checkNestedReference(Scope sc, Loc loc) | |
921 { | |
922 if (parent && !isDataseg() && parent != sc.parent && !(storage_class & STC.STCmanifest)) | |
923 { | |
924 // The function that this variable is in | |
925 FuncDeclaration fdv = toParent().isFuncDeclaration(); | |
926 // The current function | |
927 FuncDeclaration fdthis = sc.parent.isFuncDeclaration(); | |
928 | |
929 if (fdv && fdthis && fdv !is fdthis) | |
930 { | |
931 if (loc.filename) | |
932 fdthis.getLevel(loc, fdv); | |
933 | |
934 for (int i = 0; i < nestedrefs.dim; i++) | |
935 { | |
936 FuncDeclaration f = cast(FuncDeclaration)nestedrefs.data[i]; | |
937 if (f == fdthis) | |
938 goto L1; | |
939 } | |
940 nestedrefs.push(cast(void*)fdthis); | |
941 L1: ; | |
942 | |
943 for (int i = 0; i < fdv.closureVars.dim; i++) | |
944 { | |
945 Dsymbol s = cast(Dsymbol)fdv.closureVars.data[i]; | |
946 if (s == this) | |
947 goto L2; | |
948 } | |
949 | |
950 fdv.closureVars.push(cast(void*)this); | |
951 L2: ; | |
952 | |
953 //printf("fdthis is %s\n", fdthis.toChars()); | |
954 //printf("var %s in function %s is nested ref\n", toChars(), fdv.toChars()); | |
955 } | |
956 } | |
957 } | |
958 | |
959 Dsymbol toAlias() | |
960 { | |
961 //printf("VarDeclaration::toAlias('%s', this = %p, aliassym = %p)\n", toChars(), this, aliassym); | |
962 assert(this !is aliassym); | |
963 return aliassym ? aliassym.toAlias() : this; | |
964 } | |
965 | |
966 Symbol* toSymbol() | |
967 { | |
968 //printf("VarDeclaration.toSymbol(%s)\n", toChars()); | |
969 //if (needThis()) *(char*)0=0; | |
970 assert(!needThis()); | |
971 if (!csym) | |
972 { | |
973 Symbol* s; | |
974 TYPE* t; | |
975 string id; | |
976 | |
977 if (isDataseg()) | |
978 id = mangle(); | |
979 else | |
980 id = ident.toChars(); | |
981 | |
982 s = symbol_calloc(toStringz(id)); | |
983 | |
984 if (storage_class & (STC.STCout | STC.STCref)) | |
985 { | |
986 if (global.params.symdebug && storage_class & STC.STCparameter) | |
987 { | |
988 t = type_alloc(TYM.TYnptr); // should be TYref, but problems in back end | |
989 t.Tnext = type.toCtype(); | |
990 t.Tnext.Tcount++; | |
991 } | |
992 else | |
993 t = type_fake(TYM.TYnptr); | |
994 } | |
995 else if (storage_class & STC.STClazy) | |
996 t = type_fake(TYM.TYdelegate); // Tdelegate as C type | |
997 else if (isParameter()) | |
998 t = type.toCParamtype(); | |
999 else | |
1000 t = type.toCtype(); | |
1001 | |
1002 t.Tcount++; | |
1003 | |
1004 if (isDataseg()) | |
1005 { | |
1006 if (isThreadlocal()) | |
1007 { | |
1008 /* Thread local storage | |
1009 */ | |
1010 TYPE* ts = t; | |
1011 ts.Tcount++; // make sure a different t is allocated | |
1012 type_setty(&t, t.Tty | mTY.mTYthread); | |
1013 ts.Tcount--; | |
1014 | |
1015 if (global.params.vtls) | |
1016 { | |
1017 string p = loc.toChars(); | |
1018 writef("%s: %s is thread local\n", p ? p : "", toChars()); | |
1019 } | |
1020 } | |
1021 | |
1022 s.Sclass = SC.SCextern; | |
1023 s.Sfl = FL.FLextern; | |
1024 slist_add(s); | |
1025 } | |
1026 else | |
1027 { | |
1028 s.Sclass = SC.SCauto; | |
1029 s.Sfl = FL.FLauto; | |
1030 | |
1031 if (nestedrefs.dim) | |
1032 { | |
1033 /* Symbol is accessed by a nested function. Make sure | |
1034 * it is not put in a register, and that the optimizer | |
1035 * assumes it is modified across function calls and pointer | |
1036 * dereferences. | |
1037 */ | |
1038 //printf("\tnested ref, not register\n"); | |
1039 type_setcv(&t, t.Tty | mTY.mTYvolatile); | |
1040 } | |
1041 } | |
1042 | |
1043 mangle_t m = 0; | |
1044 switch (linkage) | |
1045 { | |
1046 case LINK.LINKwindows: | |
1047 m = mTYman.mTYman_std; | |
1048 break; | |
1049 | |
1050 case LINK.LINKpascal: | |
1051 m = mTYman.mTYman_pas; | |
1052 break; | |
1053 | |
1054 case LINK.LINKc: | |
1055 m = mTYman.mTYman_c; | |
1056 break; | |
1057 | |
1058 case LINK.LINKd: | |
1059 m = mTYman.mTYman_d; | |
1060 break; | |
1061 | |
1062 case LINK.LINKcpp: | |
1063 m = mTYman.mTYman_cpp; | |
1064 break; | |
1065 | |
1066 default: | |
1067 writef("linkage = %d\n", linkage); | |
1068 assert(0); | |
1069 } | |
1070 type_setmangle(&t, m); | |
1071 s.Stype = t; | |
1072 | |
1073 csym = s; | |
1074 } | |
1075 return csym; | |
1076 } | |
1077 | |
1078 void toObjFile(int multiobj) // compile to .obj file | |
1079 { | |
1080 Symbol* s; | |
1081 uint sz; | |
1082 Dsymbol parent; | |
1083 | |
1084 //printf("VarDeclaration.toObjFile(%p '%s' type=%s) protection %d\n", this, toChars(), type.toChars(), protection); | |
1085 //printf("\talign = %d\n", type.alignsize()); | |
1086 | |
1087 if (aliassym) | |
1088 { | |
1089 toAlias().toObjFile(0); | |
1090 return; | |
1091 } | |
1092 | |
1093 version (DMDV2) { | |
1094 // Do not store variables we cannot take the address of | |
1095 if (!canTakeAddressOf()) | |
1096 { | |
1097 return; | |
1098 } | |
1099 } | |
1100 | |
1101 if (isDataseg() && !(storage_class & STC.STCextern)) | |
1102 { | |
1103 s = toSymbol(); | |
1104 sz = cast(uint)type.size(); | |
1105 | |
1106 parent = this.toParent(); | |
1107 /// version (DMDV1) { /* private statics should still get a global symbol, in case | |
1108 /// * another module inlines a function that references it. | |
1109 /// */ | |
1110 /// if (/*protection == PROT.PROTprivate ||*/ | |
1111 /// !parent || parent.ident == null || parent.isFuncDeclaration()) | |
1112 /// { | |
1113 /// s.Sclass = SC.SCstatic; | |
1114 /// } | |
1115 /// else | |
1116 /// } | |
1117 { | |
1118 if (storage_class & STC.STCcomdat) | |
1119 s.Sclass = SC.SCcomdat; | |
1120 else | |
1121 s.Sclass = SC.SCglobal; | |
1122 | |
1123 do | |
1124 { | |
1125 /* Global template data members need to be in comdat's | |
1126 * in case multiple .obj files instantiate the same | |
1127 * template with the same types. | |
1128 */ | |
1129 if (parent.isTemplateInstance() && !parent.isTemplateMixin()) | |
1130 { | |
1131 version (DMDV1) { | |
1132 /* These symbol constants have already been copied, | |
1133 * so no reason to output them. | |
1134 * Note that currently there is no way to take | |
1135 * the address of such a const. | |
1136 */ | |
1137 if (isConst() && type.toBasetype().ty != TY.Tsarray && init && init.isExpInitializer()) | |
1138 return; | |
1139 } | |
1140 s.Sclass = SC.SCcomdat; | |
1141 break; | |
1142 } | |
1143 parent = parent.parent; | |
1144 } while (parent); | |
1145 } | |
1146 | |
1147 s.Sfl = FL.FLdata; | |
1148 | |
1149 if (init) | |
1150 { | |
1151 s.Sdt = init.toDt(); | |
1152 | |
1153 // Look for static array that is block initialized | |
1154 Type tb; | |
1155 ExpInitializer ie = init.isExpInitializer(); | |
1156 | |
1157 tb = type.toBasetype(); | |
1158 if (tb.ty == TY.Tsarray && ie | |
1159 && !tb.nextOf().equals(ie.exp.type.toBasetype().nextOf()) | |
1160 && ie.exp.implicitConvTo(tb.nextOf())) | |
1161 { | |
1162 int dim = cast(int)(cast(TypeSArray)tb).dim.toInteger(); | |
1163 | |
1164 // Duplicate Sdt 'dim-1' times, as we already have the first one | |
1165 while (--dim > 0) | |
1166 { | |
1167 ie.exp.toDt(&s.Sdt); | |
1168 } | |
1169 } | |
1170 } | |
1171 else if (storage_class & STC.STCextern) | |
1172 { | |
1173 s.Sclass = SC.SCextern; | |
1174 s.Sfl = FL.FLextern; | |
1175 s.Sdt = null; | |
1176 // BUG: if isExport(), shouldn't we make it dllimport? | |
1177 return; | |
1178 } | |
1179 else | |
1180 { | |
1181 type.toDt(&s.Sdt); | |
1182 } | |
1183 dt_optimize(s.Sdt); | |
1184 | |
1185 // See if we can convert a comdat to a comdef, | |
1186 // which saves on exe file space. | |
1187 if (s.Sclass == SC.SCcomdat && | |
1188 s.Sdt && | |
1189 s.Sdt.dt == DT.DT_azeros && | |
1190 s.Sdt.DTnext is null && | |
1191 !isThreadlocal()) | |
1192 { | |
1193 s.Sclass = SC.SCglobal; | |
1194 s.Sdt.dt = DT.DT_common; | |
1195 } | |
1196 | |
1197 version (ELFOBJ_OR_MACHOBJ) { // Burton | |
1198 if (s.Sdt && s.Sdt.dt == DT.DT_azeros && s.Sdt.DTnext is null) | |
1199 s.Sseg = Segment.UDATA; | |
1200 else | |
1201 s.Sseg = Segment.DATA; | |
1202 } | |
1203 if (sz) | |
1204 { | |
1205 outdata(s); | |
1206 if (isExport()) | |
1207 obj_export(s, 0); | |
1208 } | |
1209 } | |
1210 } | |
1211 | |
1212 int cvMember(ubyte* p) | |
1213 { | |
1214 assert(false); | |
1215 } | |
1216 | |
1217 // Eliminate need for dynamic_cast | |
1218 VarDeclaration isVarDeclaration() { return this; } | |
16
5c9b78899f5d
Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
1219 } |