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