Mercurial > projects > ddmd
annotate dmd/DsymbolExp.d @ 179:cd48cb899aee
Updated to dmd2.040
author | korDen |
---|---|
date | Sun, 17 Oct 2010 20:56:07 +0400 |
parents | e3afd1303184 |
children | b0d41ff5e0df |
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(); | |
179 | 130 if (!e) |
131 { | |
132 error("cannot make expression out of initializer for %s", v.toChars()); | |
133 e = new ErrorExp(); | |
134 } | |
135 e = e.semantic(sc); | |
79 | 136 return e; |
137 } | |
138 | |
72 | 139 e = new VarExp(loc, v); |
140 e.type = type; | |
141 e = e.semantic(sc); | |
142 return e.deref(); | |
143 } | |
144 | |
145 fld = s.isFuncLiteralDeclaration(); | |
146 if (fld) | |
147 { | |
148 //printf("'%s' is a function literal\n", fld.toChars()); | |
149 e = new FuncExp(loc, fld); | |
150 return e.semantic(sc); | |
151 } | |
152 f = s.isFuncDeclaration(); | |
153 if (f) | |
154 { | |
155 //printf("'%s' is a function\n", f.toChars()); | |
156 | |
157 if (!f.type.deco) | |
158 { | |
159 error("forward reference to %s", toChars()); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
160 return new ErrorExp(); |
72 | 161 } |
162 return new VarExp(loc, f, hasOverloads); | |
163 } | |
164 o = s.isOverloadSet(); | |
165 if (o) | |
166 { | |
167 //printf("'%s' is an overload set\n", o.toChars()); | |
168 return new OverExp(o); | |
169 } | |
170 cd = s.isClassDeclaration(); | |
171 if (cd && thiscd && cd.isBaseOf(thiscd, null) && sc.func.needThis()) | |
172 { | |
173 // We need to add an implicit 'this' if cd is this class or a base class. | |
174 DotTypeExp dte = new DotTypeExp(loc, new ThisExp(loc), s); | |
175 return dte.semantic(sc); | |
176 } | |
177 imp = s.isImport(); | |
178 if (imp) | |
179 { | |
180 if (!imp.pkg) | |
181 { | |
182 error("forward reference of import %s", imp.toChars()); | |
183 return this; | |
184 } | |
185 ScopeExp ie = new ScopeExp(loc, imp.pkg); | |
186 return ie.semantic(sc); | |
187 } | |
188 pkg = s.isPackage(); | |
189 if (pkg) | |
190 { | |
191 ScopeExp ie = new ScopeExp(loc, pkg); | |
192 return ie.semantic(sc); | |
193 } | |
194 Module mod = s.isModule(); | |
195 if (mod) | |
196 { | |
197 ScopeExp ie = new ScopeExp(loc, mod); | |
198 return ie.semantic(sc); | |
199 } | |
200 | |
201 t = s.getType(); | |
202 if (t) | |
203 { | |
204 return new TypeExp(loc, t); | |
205 } | |
206 | |
207 TupleDeclaration tup = s.isTupleDeclaration(); | |
208 if (tup) | |
209 { | |
210 e = new TupleExp(loc, tup); | |
211 e = e.semantic(sc); | |
212 return e; | |
213 } | |
214 | |
215 TemplateInstance ti = s.isTemplateInstance(); | |
216 if (ti && !global.errors) | |
217 { | |
218 if (!ti.semanticRun) | |
219 ti.semantic(sc); | |
220 | |
221 s = ti.inst.toAlias(); | |
222 if (!s.isTemplateInstance()) | |
223 goto Lagain; | |
224 | |
225 e = new ScopeExp(loc, ti); | |
226 e = e.semantic(sc); | |
227 return e; | |
228 } | |
229 | |
230 TemplateDeclaration td = s.isTemplateDeclaration(); | |
231 if (td) | |
232 { | |
233 e = new TemplateExp(loc, td); | |
234 e = e.semantic(sc); | |
235 return e; | |
236 } | |
237 | |
238 Lerr: | |
239 error("%s '%s' is not a variable", s.kind(), s.toChars()); | |
240 type = Type.terror; | |
0 | 241 return this; |
242 } | |
243 | |
72 | 244 override string toChars() |
0 | 245 { |
246 assert(false); | |
247 } | |
248 | |
72 | 249 override void dump(int indent) |
0 | 250 { |
251 assert(false); | |
252 } | |
253 | |
72 | 254 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 255 { |
256 assert(false); | |
257 } | |
258 | |
72 | 259 override int isLvalue() |
0 | 260 { |
261 assert(false); | |
262 } | |
263 | |
72 | 264 override Expression toLvalue(Scope sc, Expression e) |
0 | 265 { |
266 assert(false); | |
267 } | |
268 } | |
269 |