Mercurial > projects > ddmd
annotate dmd/DsymbolExp.d @ 191:52188e7e3fb5
Fixed deprecated features, now compiles with DMD2.058
Also changed Array allocation policy:
Now doesn't reallocate but malloc's, followed by a memcpy (no free).
(this fixes a crash while compiling druntime. Same bug in dmd)
author | korDen@korDen-pc |
---|---|
date | Sun, 25 Mar 2012 03:11:12 +0400 |
parents | b0d41ff5e0df |
children |
rev | line source |
---|---|
72 | 1 module dmd.DsymbolExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.OutBuffer; | |
6 import dmd.EnumMember; | |
7 import dmd.VarDeclaration; | |
8 import dmd.FuncDeclaration; | |
9 import dmd.FuncLiteralDeclaration; | |
10 import dmd.OverloadSet; | |
11 import dmd.Declaration; | |
12 import dmd.ClassDeclaration; | |
13 import dmd.Import; | |
14 import dmd.Package; | |
15 import dmd.Type; | |
16 import dmd.DotVarExp; | |
17 import dmd.ThisExp; | |
18 import dmd.VarExp; | |
19 import dmd.FuncExp; | |
20 import dmd.OverExp; | |
21 import dmd.DotTypeExp; | |
79 | 22 import dmd.STC; |
72 | 23 import dmd.ScopeExp; |
24 import dmd.Module; | |
25 import dmd.TypeExp; | |
26 import dmd.TupleDeclaration; | |
27 import dmd.TupleExp; | |
28 import dmd.TemplateInstance; | |
29 import dmd.Global; | |
30 import dmd.TemplateDeclaration; | |
31 import dmd.TemplateExp; | |
32 import dmd.Loc; | |
33 import dmd.Scope; | |
34 import dmd.HdrGenState; | |
35 import dmd.Dsymbol; | |
36 import dmd.TOK; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
37 import dmd.ErrorExp; |
72 | 38 |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
39 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
40 |
0 | 41 class DsymbolExp : Expression |
42 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
43 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
44 |
0 | 45 Dsymbol s; |
73 | 46 bool hasOverloads; |
0 | 47 |
73 | 48 this(Loc loc, Dsymbol s, bool hasOverloads = false) |
0 | 49 { |
178 | 50 register(); |
72 | 51 super(loc, TOK.TOKdsymbol, DsymbolExp.sizeof); |
52 this.s = s; | |
0 | 53 this.hasOverloads = hasOverloads; |
54 } | |
55 | |
72 | 56 override Expression semantic(Scope sc) |
0 | 57 { |
79 | 58 version (LOGSEMANTIC) |
59 { | |
72 | 60 printf("DsymbolExp.semantic('%s')\n", s.toChars()); |
61 } | |
62 | |
63 Lagain: | |
64 EnumMember em; | |
65 Expression e; | |
66 VarDeclaration v; | |
67 FuncDeclaration f; | |
68 FuncLiteralDeclaration fld; | |
69 OverloadSet o; | |
70 Declaration d; | |
71 ClassDeclaration cd; | |
72 ClassDeclaration thiscd = null; | |
73 Import imp; | |
74 Package pkg; | |
75 Type t; | |
76 | |
77 //printf("DsymbolExp. %p '%s' is a symbol\n", this, toChars()); | |
78 //printf("s = '%s', s.kind = '%s'\n", s.toChars(), s.kind()); | |
79 if (type) | |
80 return this; | |
81 | |
82 if (!s.isFuncDeclaration()) // functions are checked after overloading | |
83 checkDeprecated(sc, s); | |
84 | |
85 s = s.toAlias(); | |
86 //printf("s = '%s', s.kind = '%s', s.needThis() = %p\n", s.toChars(), s.kind(), s.needThis()); | |
87 if (!s.isFuncDeclaration()) | |
88 checkDeprecated(sc, s); | |
89 | |
90 if (sc.func) | |
91 thiscd = sc.func.parent.isClassDeclaration(); | |
92 | |
93 // BUG: This should happen after overload resolution for functions, not before | |
94 if (s.needThis()) | |
95 { | |
96 version (DMDV2) { | |
97 bool cond = !s.isFuncDeclaration(); | |
98 } else { | |
99 bool cond = true; | |
100 } | |
101 if (hasThis(sc) && cond) | |
102 { | |
103 // Supply an implicit 'this', as in | |
104 // this.ident | |
105 DotVarExp de = new DotVarExp(loc, new ThisExp(loc), s.isDeclaration()); | |
106 return de.semantic(sc); | |
107 } | |
108 } | |
109 | |
110 em = s.isEnumMember(); | |
111 if (em) | |
112 { | |
113 e = em.value; | |
114 e = e.semantic(sc); | |
115 return e; | |
116 } | |
117 v = s.isVarDeclaration(); | |
118 if (v) | |
119 { | |
120 //printf("Identifier '%s' is a variable, type '%s'\n", toChars(), v.type.toChars()); | |
121 if (!type) | |
122 { | |
123 type = v.type; | |
124 if (!v.type) | |
125 { | |
126 error("forward reference of %s %s", v.kind(), v.toChars()); | |
127 type = Type.terror; | |
128 } | |
129 } | |
130 | |
79 | 131 if ((v.storage_class & STC.STCmanifest) && v.init) |
132 { | |
133 e = v.init.toExpression(); | |
179 | 134 if (!e) |
135 { | |
136 error("cannot make expression out of initializer for %s", v.toChars()); | |
137 e = new ErrorExp(); | |
138 } | |
139 e = e.semantic(sc); | |
79 | 140 return e; |
141 } | |
142 | |
72 | 143 e = new VarExp(loc, v); |
144 e.type = type; | |
145 e = e.semantic(sc); | |
146 return e.deref(); | |
147 } | |
148 | |
149 fld = s.isFuncLiteralDeclaration(); | |
150 if (fld) | |
151 { | |
152 //printf("'%s' is a function literal\n", fld.toChars()); | |
153 e = new FuncExp(loc, fld); | |
154 return e.semantic(sc); | |
155 } | |
156 f = s.isFuncDeclaration(); | |
157 if (f) | |
158 { | |
159 //printf("'%s' is a function\n", f.toChars()); | |
160 | |
161 if (!f.type.deco) | |
162 { | |
163 error("forward reference to %s", toChars()); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
164 return new ErrorExp(); |
72 | 165 } |
166 return new VarExp(loc, f, hasOverloads); | |
167 } | |
168 o = s.isOverloadSet(); | |
169 if (o) | |
170 { | |
171 //printf("'%s' is an overload set\n", o.toChars()); | |
172 return new OverExp(o); | |
173 } | |
174 cd = s.isClassDeclaration(); | |
175 if (cd && thiscd && cd.isBaseOf(thiscd, null) && sc.func.needThis()) | |
176 { | |
177 // We need to add an implicit 'this' if cd is this class or a base class. | |
178 DotTypeExp dte = new DotTypeExp(loc, new ThisExp(loc), s); | |
179 return dte.semantic(sc); | |
180 } | |
181 imp = s.isImport(); | |
182 if (imp) | |
183 { | |
184 if (!imp.pkg) | |
185 { | |
186 error("forward reference of import %s", imp.toChars()); | |
187 return this; | |
188 } | |
189 ScopeExp ie = new ScopeExp(loc, imp.pkg); | |
190 return ie.semantic(sc); | |
191 } | |
192 pkg = s.isPackage(); | |
193 if (pkg) | |
194 { | |
195 ScopeExp ie = new ScopeExp(loc, pkg); | |
196 return ie.semantic(sc); | |
197 } | |
198 Module mod = s.isModule(); | |
199 if (mod) | |
200 { | |
201 ScopeExp ie = new ScopeExp(loc, mod); | |
202 return ie.semantic(sc); | |
203 } | |
204 | |
205 t = s.getType(); | |
206 if (t) | |
207 { | |
208 return new TypeExp(loc, t); | |
209 } | |
210 | |
211 TupleDeclaration tup = s.isTupleDeclaration(); | |
212 if (tup) | |
213 { | |
214 e = new TupleExp(loc, tup); | |
215 e = e.semantic(sc); | |
216 return e; | |
217 } | |
218 | |
219 TemplateInstance ti = s.isTemplateInstance(); | |
220 if (ti && !global.errors) | |
221 { | |
222 if (!ti.semanticRun) | |
223 ti.semantic(sc); | |
224 | |
225 s = ti.inst.toAlias(); | |
226 if (!s.isTemplateInstance()) | |
227 goto Lagain; | |
228 | |
229 e = new ScopeExp(loc, ti); | |
230 e = e.semantic(sc); | |
231 return e; | |
232 } | |
233 | |
234 TemplateDeclaration td = s.isTemplateDeclaration(); | |
235 if (td) | |
236 { | |
237 e = new TemplateExp(loc, td); | |
238 e = e.semantic(sc); | |
239 return e; | |
240 } | |
241 | |
242 Lerr: | |
243 error("%s '%s' is not a variable", s.kind(), s.toChars()); | |
244 type = Type.terror; | |
0 | 245 return this; |
246 } | |
247 | |
72 | 248 override string toChars() |
0 | 249 { |
250 assert(false); | |
251 } | |
252 | |
72 | 253 override void dump(int indent) |
0 | 254 { |
255 assert(false); | |
256 } | |
257 | |
72 | 258 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 259 { |
260 assert(false); | |
261 } | |
262 | |
191
52188e7e3fb5
Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents:
187
diff
changeset
|
263 override bool isLvalue() |
0 | 264 { |
265 assert(false); | |
266 } | |
267 | |
72 | 268 override Expression toLvalue(Scope sc, Expression e) |
0 | 269 { |
270 assert(false); | |
271 } | |
272 } | |
273 |