Mercurial > projects > ddmd
annotate dmd/DsymbolExp.d @ 178:e3afd1303184
Many small bugs fixed
Made all classes derive from TObject to detect memory leaks (functionality is disabled for now)
Began work on overriding backend memory allocations (to avoid memory leaks)
author | korDen |
---|---|
date | Sun, 17 Oct 2010 07:42:00 +0400 |
parents | 60bb0fe4563e |
children | cd48cb899aee |
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 |
0 | 39 class DsymbolExp : Expression |
40 { | |
41 Dsymbol s; | |
73 | 42 bool hasOverloads; |
0 | 43 |
73 | 44 this(Loc loc, Dsymbol s, bool hasOverloads = false) |
0 | 45 { |
178 | 46 register(); |
72 | 47 super(loc, TOK.TOKdsymbol, DsymbolExp.sizeof); |
48 this.s = s; | |
0 | 49 this.hasOverloads = hasOverloads; |
50 } | |
51 | |
72 | 52 override Expression semantic(Scope sc) |
0 | 53 { |
79 | 54 version (LOGSEMANTIC) |
55 { | |
72 | 56 printf("DsymbolExp.semantic('%s')\n", s.toChars()); |
57 } | |
58 | |
59 Lagain: | |
60 EnumMember em; | |
61 Expression e; | |
62 VarDeclaration v; | |
63 FuncDeclaration f; | |
64 FuncLiteralDeclaration fld; | |
65 OverloadSet o; | |
66 Declaration d; | |
67 ClassDeclaration cd; | |
68 ClassDeclaration thiscd = null; | |
69 Import imp; | |
70 Package pkg; | |
71 Type t; | |
72 | |
73 //printf("DsymbolExp. %p '%s' is a symbol\n", this, toChars()); | |
74 //printf("s = '%s', s.kind = '%s'\n", s.toChars(), s.kind()); | |
75 if (type) | |
76 return this; | |
77 | |
78 if (!s.isFuncDeclaration()) // functions are checked after overloading | |
79 checkDeprecated(sc, s); | |
80 | |
81 s = s.toAlias(); | |
82 //printf("s = '%s', s.kind = '%s', s.needThis() = %p\n", s.toChars(), s.kind(), s.needThis()); | |
83 if (!s.isFuncDeclaration()) | |
84 checkDeprecated(sc, s); | |
85 | |
86 if (sc.func) | |
87 thiscd = sc.func.parent.isClassDeclaration(); | |
88 | |
89 // BUG: This should happen after overload resolution for functions, not before | |
90 if (s.needThis()) | |
91 { | |
92 version (DMDV2) { | |
93 bool cond = !s.isFuncDeclaration(); | |
94 } else { | |
95 bool cond = true; | |
96 } | |
97 if (hasThis(sc) && cond) | |
98 { | |
99 // Supply an implicit 'this', as in | |
100 // this.ident | |
101 DotVarExp de = new DotVarExp(loc, new ThisExp(loc), s.isDeclaration()); | |
102 return de.semantic(sc); | |
103 } | |
104 } | |
105 | |
106 em = s.isEnumMember(); | |
107 if (em) | |
108 { | |
109 e = em.value; | |
110 e = e.semantic(sc); | |
111 return e; | |
112 } | |
113 v = s.isVarDeclaration(); | |
114 if (v) | |
115 { | |
116 //printf("Identifier '%s' is a variable, type '%s'\n", toChars(), v.type.toChars()); | |
117 if (!type) | |
118 { | |
119 type = v.type; | |
120 if (!v.type) | |
121 { | |
122 error("forward reference of %s %s", v.kind(), v.toChars()); | |
123 type = Type.terror; | |
124 } | |
125 } | |
126 | |
79 | 127 if ((v.storage_class & STC.STCmanifest) && v.init) |
128 { | |
129 e = v.init.toExpression(); | |
130 e.semantic(sc); | |
131 return e; | |
132 } | |
133 | |
72 | 134 e = new VarExp(loc, v); |
135 e.type = type; | |
136 e = e.semantic(sc); | |
137 return e.deref(); | |
138 } | |
139 | |
140 fld = s.isFuncLiteralDeclaration(); | |
141 if (fld) | |
142 { | |
143 //printf("'%s' is a function literal\n", fld.toChars()); | |
144 e = new FuncExp(loc, fld); | |
145 return e.semantic(sc); | |
146 } | |
147 f = s.isFuncDeclaration(); | |
148 if (f) | |
149 { | |
150 //printf("'%s' is a function\n", f.toChars()); | |
151 | |
152 if (!f.type.deco) | |
153 { | |
154 error("forward reference to %s", toChars()); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
155 return new ErrorExp(); |
72 | 156 } |
157 return new VarExp(loc, f, hasOverloads); | |
158 } | |
159 o = s.isOverloadSet(); | |
160 if (o) | |
161 { | |
162 //printf("'%s' is an overload set\n", o.toChars()); | |
163 return new OverExp(o); | |
164 } | |
165 cd = s.isClassDeclaration(); | |
166 if (cd && thiscd && cd.isBaseOf(thiscd, null) && sc.func.needThis()) | |
167 { | |
168 // We need to add an implicit 'this' if cd is this class or a base class. | |
169 DotTypeExp dte = new DotTypeExp(loc, new ThisExp(loc), s); | |
170 return dte.semantic(sc); | |
171 } | |
172 imp = s.isImport(); | |
173 if (imp) | |
174 { | |
175 if (!imp.pkg) | |
176 { | |
177 error("forward reference of import %s", imp.toChars()); | |
178 return this; | |
179 } | |
180 ScopeExp ie = new ScopeExp(loc, imp.pkg); | |
181 return ie.semantic(sc); | |
182 } | |
183 pkg = s.isPackage(); | |
184 if (pkg) | |
185 { | |
186 ScopeExp ie = new ScopeExp(loc, pkg); | |
187 return ie.semantic(sc); | |
188 } | |
189 Module mod = s.isModule(); | |
190 if (mod) | |
191 { | |
192 ScopeExp ie = new ScopeExp(loc, mod); | |
193 return ie.semantic(sc); | |
194 } | |
195 | |
196 t = s.getType(); | |
197 if (t) | |
198 { | |
199 return new TypeExp(loc, t); | |
200 } | |
201 | |
202 TupleDeclaration tup = s.isTupleDeclaration(); | |
203 if (tup) | |
204 { | |
205 e = new TupleExp(loc, tup); | |
206 e = e.semantic(sc); | |
207 return e; | |
208 } | |
209 | |
210 TemplateInstance ti = s.isTemplateInstance(); | |
211 if (ti && !global.errors) | |
212 { | |
213 if (!ti.semanticRun) | |
214 ti.semantic(sc); | |
215 | |
216 s = ti.inst.toAlias(); | |
217 if (!s.isTemplateInstance()) | |
218 goto Lagain; | |
219 | |
220 e = new ScopeExp(loc, ti); | |
221 e = e.semantic(sc); | |
222 return e; | |
223 } | |
224 | |
225 TemplateDeclaration td = s.isTemplateDeclaration(); | |
226 if (td) | |
227 { | |
228 e = new TemplateExp(loc, td); | |
229 e = e.semantic(sc); | |
230 return e; | |
231 } | |
232 | |
233 Lerr: | |
234 error("%s '%s' is not a variable", s.kind(), s.toChars()); | |
235 type = Type.terror; | |
0 | 236 return this; |
237 } | |
238 | |
72 | 239 override string toChars() |
0 | 240 { |
241 assert(false); | |
242 } | |
243 | |
72 | 244 override void dump(int indent) |
0 | 245 { |
246 assert(false); | |
247 } | |
248 | |
72 | 249 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 250 { |
251 assert(false); | |
252 } | |
253 | |
72 | 254 override int isLvalue() |
0 | 255 { |
256 assert(false); | |
257 } | |
258 | |
72 | 259 override Expression toLvalue(Scope sc, Expression e) |
0 | 260 { |
261 assert(false); | |
262 } | |
263 } | |
264 |