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