annotate dmd/VarDeclaration.d @ 72:2e2a5c3f943a

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