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