annotate dmd/DotIdExp.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children 2e2a5c3f943a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.ScopeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.StringExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.PtrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.TypePointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.EnumMember;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.ThisExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.DotVarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.CommaExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.OverloadSet;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.OverExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.TypeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.TupleDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.Import;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.TupleExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.UnaExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.DotExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.IdentifierExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.PREC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 class DotIdExp : UnaExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 this(Loc loc, Expression e, Identifier ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 super(loc, TOK.TOKdot, DotIdExp.sizeof, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 this.ident = ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 Expression semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 Expression eleft;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 Expression eright;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 printf("DotIdExp.semantic(this = %p, '%s')\n", this, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 //printf("e1.op = %d, '%s'\n", e1.op, Token.toChars(e1.op));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 //{ static int z; fflush(stdout); if (++z == 10) *(char*)0=0; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 /* Don't do semantic analysis if we'll be converting
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 * it to a string.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 if (ident == Id.stringof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 char *s = e1.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 e = new StringExp(loc, s, strlen(s), 'c');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 /* Special case: rewrite this.id and super.id
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 * to be classtype.id and baseclasstype.id
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 * if we have no this pointer.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 if ((e1.op == TOK.TOKthis || e1.op == TOK.TOKsuper) && !hasThis(sc))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 ClassDeclaration cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 StructDeclaration sd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 AggregateDeclaration ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 ad = sc.getStructClassScope();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 if (ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 cd = ad.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 if (cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 if (e1.op == TOK.TOKthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 e = typeDotIdExp(loc, cd.type, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 return e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 else if (cd.baseClass && e1.op == TOK.TOKsuper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 e = typeDotIdExp(loc, cd.baseClass.type, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 return e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 sd = ad.isStructDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 if (sd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 if (e1.op == TOK.TOKthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 e = typeDotIdExp(loc, sd.type, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 return e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 UnaExp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 if (e1.op == TOK.TOKdotexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 DotExp de = cast(DotExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 eleft = de.e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 eright = de.e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 e1 = resolveProperties(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 eleft = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 eright = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 if (e1.op == TOK.TOKtuple && ident == Id.offsetof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 /* 'distribute' the .offsetof to each of the tuple elements.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 TupleExp te = cast(TupleExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 Expressions exps = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 exps.setDim(te.exps.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 for (int i = 0; i < exps.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 Expression ee = cast(Expression)te.exps.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 ee = ee.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 ee = new DotIdExp(e.loc, ee, Id.offsetof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 exps.data[i] = cast(void*)ee;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 e = new TupleExp(loc, exps);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 if (e1.op == TOK.TOKtuple && ident == Id.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 TupleExp te = cast(TupleExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 e = new IntegerExp(loc, te.exps.dim, Type.tsize_t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 if (e1.op == TOK.TOKdottd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 error("template %s does not have property %s", e1.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 return e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 if (!e1.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 error("expression %s does not have property %s", e1.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 return e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 Type t1b = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 if (eright.op == TOK.TOKimport) // also used for template alias's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 ScopeExp ie = cast(ScopeExp)eright;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 /* Disable access to another module's private imports.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 * The check for 'is sds our current module' is because
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 * the current module should have access to its own imports.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 Dsymbol s = ie.sds.search(loc, ident,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 (ie.sds.isModule() && ie.sds != sc.module_) ? 1 : 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 s = s.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 checkDeprecated(sc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 EnumMember em = s.isEnumMember();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 if (em)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 e = em.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 VarDeclaration v = s.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 if (v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 //printf("DotIdExp. Identifier '%s' is a variable, type '%s'\n", toChars(), v.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 if (v.inuse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 error("circular reference to '%s'", v.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 type = Type.tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 type = v.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 if (v.needThis())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 if (!eleft)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 eleft = new ThisExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 e = new DotVarExp(loc, eleft, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 e = new VarExp(loc, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 if (eleft)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 e = new CommaExp(loc, eleft, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 e.type = v.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 return e.deref();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 FuncDeclaration f = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 if (f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 //printf("it's a function\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 if (f.needThis())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 if (!eleft)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 eleft = new ThisExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 e = new DotVarExp(loc, eleft, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 e = new VarExp(loc, f, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 if (eleft)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 { e = new CommaExp(loc, eleft, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 e.type = f.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 OverloadSet o = s.isOverloadSet();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 if (o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 //printf("'%s' is an overload set\n", o.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 return new OverExp(o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 Type t = s.getType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 if (t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 return new TypeExp(loc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 TupleDeclaration tup = s.isTupleDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 if (tup)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 if (eleft)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 error("cannot have e.tuple");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 e = new TupleExp(loc, tup);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 ScopeDsymbol sds = s.isScopeDsymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 if (sds)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 //printf("it's a ScopeDsymbol\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 e = new ScopeExp(loc, sds);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 if (eleft)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 e = new DotExp(loc, eleft, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 Import imp = s.isImport();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 if (imp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 ScopeExp iee = new ScopeExp(loc, imp.pkg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 return iee.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 // BUG: handle other cases like in IdentifierExp.semantic()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 version (DEBUG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 printf("s = '%s', kind = '%s'\n", s.toChars(), s.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 else if (ident is Id.stringof_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 string ss = ie.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 e = new StringExp(loc, ss, 'c');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 error("undefined identifier %s", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 type = Type.tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 else if (t1b.ty == TY.Tpointer &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 ident !is Id.init_ && ident !is Id.__sizeof &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 ident !is Id.alignof_ && ident !is Id.offsetof &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 ident !is Id.mangleof_ && ident !is Id.stringof_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 { /* Rewrite:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 * p.ident
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 * as:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 * (*p).ident
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 e = new PtrExp(loc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 e.type = (cast(TypePointer)t1b).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 return e.type.dotExp(sc, e, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 else if (t1b.ty == TY.Tarray ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 t1b.ty == TY.Tsarray ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 t1b.ty == TY.Taarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 /* If ident is not a valid property, rewrite:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 * e1.ident
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 * as:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 * .ident(e1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 uint errors = global.errors;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 global.gag++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 e = e1.type.dotExp(sc, e1, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 global.gag--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 if (errors != global.errors) // if failed to find the property
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 global.errors = errors;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 e = new DotIdExp(loc, new IdentifierExp(loc, Id.empty), ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 e = new CallExp(loc, e, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 e = e1.type.dotExp(sc, e1, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 //printf("DotIdExp.toCBuffer()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 expToCBuffer(buf, hgs, e1, PREC.PREC_primary);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 buf.writeByte('.');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 buf.writestring(ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 void dump(int i)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373