annotate dmd/AddrExp.d @ 135:af1bebfd96a4 dmd2037

dmd 2.038
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Mon, 13 Sep 2010 22:19:42 +0100
parents e28b18c23469
children e3afd1303184
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
1 module dmd.AddrExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 109
diff changeset
3 import dmd.common;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
4 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
5 import dmd.UnaExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
6 import dmd.MATCH;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
7 import dmd.Type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
8 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
9 import dmd.Scope;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.ErrorExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.DotVarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.DelegateExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.VarDeclaration;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
17 import dmd.ThisExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.CommaExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.PtrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.SymOffExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.IndexExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.OverExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.TY;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
29 import dmd.TypeSArray;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
30
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.backend.Util;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
33 import dmd.codegen.Util;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
34
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 class AddrExp : UnaExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 this(Loc loc, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 super(loc, TOK.TOKaddress, AddrExp.sizeof, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
42 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 printf("AddrExp.semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 UnaExp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 e1 = e1.toLvalue(sc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 if (!e1.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 error("cannot take address of %s", e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 return new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 if (!e1.type.deco)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 /* No deco means semantic() was not run on the type.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 * We have to run semantic() on the symbol to get the right type:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 * auto x = &bar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 * pure: int bar() { return 1;}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 * otherwise the 'pure' is missing from the type assigned to x.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 error("forward reference to %s", e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 return new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 type = e1.type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 // See if this should really be a delegate
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 if (e1.op == TOKdotvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 DotVarExp dve = cast(DotVarExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 FuncDeclaration f = dve.var.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 if (f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 if (!dve.hasOverloads)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 f.tookAddressOf++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 Expression e = new DelegateExp(loc, dve.e1, f, dve.hasOverloads);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 else if (e1.op == TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 VarExp ve = cast(VarExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 VarDeclaration v = ve.var.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 if (v && !v.canTakeAddressOf())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 error("cannot take address of %s", e1.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 FuncDeclaration f = ve.var.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 if (f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 if (!ve.hasOverloads ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 /* Because nested functions cannot be overloaded,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 * mark here that we took its address because castTo()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 * may not be called with an exact match.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 f.toParent2().isFuncDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 f.tookAddressOf++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 if (f.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 Expression e = new DelegateExp(loc, e1, f, ve.hasOverloads);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 if (f.needThis() && hasThis(sc))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 /* Should probably supply 'this' after overload resolution,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 * not before.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 Expression ethis = new ThisExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 Expression e = new DelegateExp(loc, ethis, f, ve.hasOverloads);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 return e;
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 return optimize(WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
129 override void checkEscape()
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
130 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
131 e1.checkEscapeRef();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
132 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
133
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
134 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 //printf("AddrExp.toElem('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 e = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 e = addressElem(e, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 e.Ety = type.totym();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
148 override MATCH implicitConvTo(Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 printf("AddrExp.implicitConvTo(this=%s, type=%s, t=%s)\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 toChars(), type.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 MATCH result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 result = type.implicitConvTo(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 //printf("\tresult = %d\n", result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 if (result == MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 // Look for pointers to functions where the functions are overloaded.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 t = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 if (e1.op == TOKoverloadset &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 (t.ty == Tpointer || t.ty == Tdelegate) && t.nextOf().ty == Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 OverExp eo = cast(OverExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 FuncDeclaration f = null;
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 77
diff changeset
170 foreach (s; eo.vars.a)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 77
diff changeset
172 auto f2 = s.isFuncDeclaration();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 assert(f2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 if (f2.overloadExactMatch(t.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 if (f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 /* Error if match in more than one overload set,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 * even if one is a 'better' match than the other.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 ScopeDsymbol.multiplyDefined(loc, f, f2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 f = f2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 result = MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 if (type.ty == Tpointer && type.nextOf().ty == Tfunction &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 t.ty == Tpointer && t.nextOf().ty == Tfunction &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 e1.op == TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 /* I don't think this can ever happen -
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 * it should have been
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 * converted to a SymOffExp.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 VarExp ve = cast(VarExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 FuncDeclaration f = ve.var.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 if (f && f.overloadExactMatch(t.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 result = MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 //printf("\tresult = %d\n", result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
208 override Expression castTo(Scope sc, Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 Type tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 printf("AddrExp.castTo(this=%s, type=%s, t=%s)\n", toChars(), type.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 Expression e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 tb = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 type = type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 if (tb != type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 // Look for pointers to functions where the functions are overloaded.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 if (e1.op == TOKoverloadset &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 (t.ty == Tpointer || t.ty == Tdelegate) && t.nextOf().ty == Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 OverExp eo = cast(OverExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 FuncDeclaration f = null;
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 77
diff changeset
228 foreach (s; eo.vars.a)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 77
diff changeset
230 auto f2 = s.isFuncDeclaration();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 assert(f2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 if (f2.overloadExactMatch(t.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 if (f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 /* Error if match in more than one overload set,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 * even if one is a 'better' match than the other.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 ScopeDsymbol.multiplyDefined(loc, f, f2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 f = f2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 if (f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 f.tookAddressOf++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 SymOffExp se = new SymOffExp(loc, f, 0, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 se.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 // Let SymOffExp.castTo() do the heavy lifting
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 return se.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 if (type.ty == Tpointer && type.nextOf().ty == Tfunction &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 tb.ty == Tpointer && tb.nextOf().ty == Tfunction &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 e1.op == TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 VarExp ve = cast(VarExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 FuncDeclaration f = ve.var.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 if (f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 assert(0); // should be SymOffExp instead
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 f = f.overloadExactMatch(tb.nextOf());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 if (f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 e = new VarExp(loc, f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 e.type = f.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 e = new AddrExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 e.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 e = Expression.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 e.type = t;
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
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
280 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 //printf("AddrExp.optimize(result = %d) %s\n", result, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 /* Rewrite &(a,b) as (a,&b)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 if (e1.op == TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 CommaExp ce = cast(CommaExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 AddrExp ae = new AddrExp(loc, ce.e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 ae.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 e = new CommaExp(ce.loc, ce.e1, ae);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 return e.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 if (e1.op == TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 VarExp ve = cast(VarExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 if (ve.var.storage_class & STCmanifest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 e1 = e1.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 e1 = e1.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 // Convert &*ex to ex
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 if (e1.op == TOKstar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 Expression ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 ex = (cast(PtrExp)e1).e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 if (type.equals(ex.type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 e = ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 e = ex.copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 if (e1.op == TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 VarExp ve = cast(VarExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 if (!ve.var.isOut() && !ve.var.isRef() &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 !ve.var.isImportedSymbol())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 SymOffExp se = new SymOffExp(loc, ve.var, 0, ve.hasOverloads);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 se.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 return se;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 if (e1.op == TOKindex)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 // Convert &array[n] to &array+n
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 IndexExp ae = cast(IndexExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 if (ae.e2.op == TOKint64 && ae.e1.op == TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 long index = ae.e2.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 VarExp ve = cast(VarExp)ae.e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 if (ve.type.ty == Tsarray
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 && !ve.var.isImportedSymbol())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 TypeSArray ts = cast(TypeSArray)ve.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 long dim = ts.dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 if (index < 0 || index >= dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 error("array index %jd is out of bounds [0..%jd]", index, dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 e = new SymOffExp(loc, ve.var, cast(uint)(index * ts.nextOf().size()));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358