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