annotate dmd/DeclarationExp.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children cab4c37afb89
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.DeclarationExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.InlineCostState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TupleDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.AttribDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.VoidInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 // Declaration of a symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 class DeclarationExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 Dsymbol declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 this(Loc loc, Dsymbol declaration)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 super(loc, TOK.TOKdeclaration, DeclarationExp.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 this.declaration = declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 Expression syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 return new DeclarationExp(loc, declaration.syntaxCopy(null));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 Expression semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 printf("DeclarationExp.semantic() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 /* This is here to support extern(linkage) declaration,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 * where the extern(linkage) winds up being an AttribDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 * wrapper.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 Dsymbol s = declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 AttribDeclaration ad = declaration.isAttribDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 if (ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 if (ad.decl && ad.decl.dim == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 s = cast(Dsymbol)ad.decl.data[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 if (s.isVarDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 // Do semantic() on initializer first, so:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 // int a = a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 // will be illegal.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 declaration.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 s.parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 //printf("inserting '%s' %p into sc = %p\n", s.toChars(), s, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 // Insert into both local scope and function scope.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 // Must be unique in both.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 if (s.ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 if (!sc.insert(s))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 error("declaration %s is already defined", s.toPrettyChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 else if (sc.func)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 VarDeclaration v = s.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 if (s.isFuncDeclaration() && !sc.func.localsymtab.insert(s))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 error("declaration %s is already defined in another scope in %s", s.toPrettyChars(), sc.func.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 else if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 // Disallow shadowing
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 for (Scope scx = sc.enclosing; scx && scx.func is sc.func; scx = scx.enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 Dsymbol s2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 if (scx.scopesym && scx.scopesym.symtab && (s2 = scx.scopesym.symtab.lookup(s.ident)) !is null && s !is s2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 error("shadowing declaration %s is deprecated", s.toPrettyChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 if (!s.isVarDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 declaration.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 s.parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 if (!global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 declaration.semantic2(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 if (!global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 declaration.semantic3(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 if (!global.errors && global.params.useInline)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 declaration.inlineScan();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 type = Type.tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 Expression interpret(InterState* istate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 bool checkSideEffect(int flag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 declaration.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 elem* toElem(IRState* irs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 //printf("DeclarationExp::toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 elem* e = Dsymbol_toElem(declaration, irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 void scanForNestedRef(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 bool canThrow()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 VarDeclaration v = declaration.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 if (v && v.init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 ExpInitializer ie = v.init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 return ie && ie.exp.canThrow();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 int inlineCost(InlineCostState* ics)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 int cost = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 VarDeclaration vd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 //printf("DeclarationExp.inlineCost()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 vd = declaration.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 if (vd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 TupleDeclaration td = vd.toAlias().isTupleDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 if (td)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 return COST_MAX; // finish DeclarationExp.doInline
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 for (size_t i = 0; i < td.objects.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 Object o = cast(Object)td.objects.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 Expression eo = cast(Expression)o;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 if (eo is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 return COST_MAX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 if (eo.op != TOKdsymbol)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 return COST_MAX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 return td.objects.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 if (!ics.hdrscan && vd.isDataseg())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 return COST_MAX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 cost += 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 // Scan initializer (vd.init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 if (vd.init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 ExpInitializer ie = vd.init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 if (ie)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 cost += ie.exp.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 // These can contain functions, which when copied, get output twice.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 if (declaration.isStructDeclaration() ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 declaration.isClassDeclaration() ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 declaration.isFuncDeclaration() ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 declaration.isTypedefDeclaration() ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 declaration.isTemplateMixin()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 return COST_MAX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 //printf("DeclarationExp.inlineCost('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 return cost;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 Expression doInline(InlineDoState ids)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 DeclarationExp de = cast(DeclarationExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 VarDeclaration vd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 //printf("DeclarationExp.doInline(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 vd = declaration.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 if (vd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 // Need to figure this out before inlining can work for tuples
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 TupleDeclaration td = vd.toAlias().isTupleDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 if (td)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 for (size_t i = 0; i < td.objects.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 DsymbolExp se = cast(DsymbolExp)td.objects.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 assert(se.op == TOKdsymbol);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 se.s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 return st.objects.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 if (vd.isStatic())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 VarDeclaration vto = new VarDeclaration(vd.loc, vd.type, vd.ident, vd.init);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 ///*vto = *vd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 memcpy(cast(void*)vto, cast(void*)vd, VarDeclaration.classinfo.init.length);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 vto.parent = ids.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 vto.csym = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 vto.isym = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 ids.from.push(cast(void*)vd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 ids.to.push(cast(void*)vto);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 if (vd.init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 if (vd.init.isVoidInitializer())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 vto.init = new VoidInitializer(vd.init.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 Expression e = vd.init.toExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 assert(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 vto.init = new ExpInitializer(e.loc, e.doInline(ids));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 de.declaration = vto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 /* This needs work, like DeclarationExp.toElem(), if we are
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 * to handle TemplateMixin's. For now, we just don't inline them.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 return de;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 Expression inlineScan(InlineScanState* iss)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 //printf("DeclarationExp.inlineScan()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 scanVar(declaration, iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291