annotate dmd/IndexExp.d @ 72:2e2a5c3f943a

reduced warnings by adding override to the methods think this also normalizes different line endings used all over the place
author Trass3r
date Sat, 28 Aug 2010 16:19:48 +0200
parents cab4c37afb89
children ef02e2e203c2
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: 63
diff changeset
1 module dmd.IndexExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
2
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
3 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
4 import dmd.backend.elem;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
5 import dmd.InterState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
6 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
7 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
8 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
9 import dmd.VarDeclaration;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.ArrayScopeSymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TypeNext;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.TypeAArray;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
18 import dmd.UnaExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
19 import dmd.IRState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
20 import dmd.BinExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
21 import dmd.HdrGenState;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.TupleExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.TypeTuple;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Argument;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.TypeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.GlobalExpressions;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.expression.util.arrayTypeCompatible;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.expression.Index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.backend.mTY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
45 import core.stdc.string;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
46
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 class IndexExp : BinExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 VarDeclaration lengthVar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 int modifiable = 0; // assume it is an rvalue
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 this(Loc loc, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 super(loc, TOK.TOKindex, IndexExp.sizeof, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 //printf("IndexExp.IndexExp('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
58 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 BinExp b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 UnaExp u;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 Type t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 ScopeDsymbol sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 printf("IndexExp.semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 if (!e1.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 assert(e1.type); // semantic() should already be run on it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 // Note that unlike C we do not implement the int[ptr]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 if (t1.ty == Tsarray || t1.ty == Tarray || t1.ty == Ttuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 // Create scope for 'length' variable
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 sym = new ArrayScopeSymbol(sc, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 sym.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 sym.parent = sc.scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 sc = sc.push(sym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 e2 = e2.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 if (!e2.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 error("%s has no value", e2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 e2.type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 e2 = resolveProperties(sc, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 if (t1.ty == Tsarray || t1.ty == Tarray || t1.ty == Ttuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 sc = sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 switch (t1.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 case Tpointer:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 case Tarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 e2 = e2.implicitCastTo(sc, Type.tsize_t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 e.type = (cast(TypeNext)t1).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 case Tsarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 e2 = e2.implicitCastTo(sc, Type.tsize_t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 TypeSArray tsa = cast(TypeSArray)t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 // Don't do now, because it might be short-circuit evaluated
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 // Do compile time array bounds checking if possible
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 e2 = e2.optimize(WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 if (e2.op == TOKint64)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 ulong index = e2.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 ulong length = tsa.dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 if (index < 0 || index >= length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 error("array index [%lld] is outside array bounds [0 .. %lld]", index, length);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 e.type = t1.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 case Taarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 TypeAArray taa = cast(TypeAArray)t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 if (!arrayTypeCompatible(e2.loc, e2.type, taa.index))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 e2 = e2.implicitCastTo(sc, taa.index); // type checking
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 type = taa.next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 case Ttuple:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 e2 = e2.implicitCastTo(sc, Type.tsize_t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 e2 = e2.optimize(WANTvalue | WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 ulong index = e2.toUInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 size_t length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 TupleExp te;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 TypeTuple tup;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 if (e1.op == TOKtuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 te = cast(TupleExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 length = te.exps.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 else if (e1.op == TOKtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 tup = cast(TypeTuple)t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 length = Argument.dim(tup.arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 if (index < length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 if (e1.op == TOKtuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 e = cast(Expression)te.exps.data[cast(size_t)index];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 e = new TypeExp(e1.loc, Argument.getNth(tup.arguments, cast(size_t)index).type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 error("array index [%ju] is outside array bounds [0 .. %zu]", index, length);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 e = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 error("%s must be an array or pointer type, not %s", e1.toChars(), e1.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 type = Type.tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
187 override int isLvalue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
192 override Expression toLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 // if (type && type.toBasetype().ty == Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 // error("voids have no value");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
199 override Expression modifiableLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 //printf("IndexExp::modifiableLvalue(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 modifiable = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 if (e1.op == TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 error("string literals are immutable");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 if (type && !type.isMutable())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 error("%s isn't mutable", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 if (e1.type.toBasetype().ty == Taarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 e1 = e1.modifiableLvalue(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 return toLvalue(sc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
212 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
217 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 //printf("IndexExp::optimize(result = %d) %s\n", result, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 Expression e1 = this.e1.optimize(WANTvalue | (result & WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 e1 = fromConstInitializer(result, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 if (this.e1.op == TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 VarExp ve = cast(VarExp)this.e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 if (ve.var.storage_class & STCmanifest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 /* We generally don't want to have more than one copy of an
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 * array literal, but if it's an enum we have to because the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 * enum isn't stored elsewhere. See Bugzilla 2559
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 this.e1 = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 e2 = e2.optimize(WANTvalue | (result & WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 e = Index(type, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 if (e is EXP_CANT_INTERPRET)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
245 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
250 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 IndexExp are = cast(IndexExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 are.e1 = e1.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 if (lengthVar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 { //printf("lengthVar\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 VarDeclaration vd = lengthVar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 ExpInitializer ie;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 ExpInitializer ieto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 VarDeclaration vto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 vto = new VarDeclaration(vd.loc, vd.type, vd.ident, vd.init);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 ///*vto = *vd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 memcpy(cast(void*)vto, cast(void*)vd, VarDeclaration.classinfo.init.length);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 vto.parent = ids.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 vto.csym = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 vto.isym = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 ids.from.push(cast(void*)vd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 ids.to.push(cast(void*)vto);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 if (vd.init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 ie = vd.init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 assert(ie);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 ieto = new ExpInitializer(ie.loc, ie.exp.doInline(ids));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 vto.init = ieto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 are.lengthVar = vto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 are.e2 = e2.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 return are;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
287 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
292 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 elem* n1 = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 elem* n2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 elem* eb = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 Type t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 //printf("IndexExp.toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 if (t1.ty == Taarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 // set to:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 // *aaGet(aa, keyti, valuesize, index);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 TypeAArray taa = cast(TypeAArray)t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 elem* keyti;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 elem* ep;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 int vsize = cast(int)taa.next.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 elem* valuesize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 // n2 becomes the index, also known as the key
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 n2 = e2.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 if (tybasic(n2.Ety) == TYstruct || tybasic(n2.Ety) == TYarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 n2 = el_una(OPstrpar, TYstruct, n2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 n2.Enumbytes = n2.E1.Enumbytes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 //printf("numbytes = %d\n", n2.Enumbytes);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 assert(n2.Enumbytes);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 valuesize = el_long(TYuint, vsize); // BUG: should be TYsize_t
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 //printf("valuesize: "); elem_print(valuesize);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 if (modifiable)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 n1 = el_una(OPaddr, TYnptr, n1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 s = taa.aaGetSymbol("Get", 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 s = taa.aaGetSymbol("GetRvalue", 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 //printf("taa.index = %s\n", taa.index.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 keyti = taa.index.getInternalTypeInfo(null).toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 //keyti = taa.index.getTypeInfo(null).toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 //printf("keyti:\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 //elem_print(keyti);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 ep = el_params(n2, valuesize, keyti, n1, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 e = el_bin(OPcall, TYnptr, el_var(s), ep);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 if (global.params.useArrayBounds)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 elem* n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 elem* ea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 n = el_same(&e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 // Construct: ((e || ModuleAssert(line)),n)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 Symbol* sassert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 sassert = irs.blx.module_.toModuleArray();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 ea = el_bin(OPcall,TYvoid,el_var(sassert),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 el_long(TYint, loc.linnum));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 e = el_bin(OPoror,TYvoid,e,ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 e = el_bin(OPcomma, TYnptr, e, n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 e = el_una(OPind, type.totym(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 if (tybasic(e.Ety) == TYstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 e.Enumbytes = cast(uint)type.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 elem* einit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 einit = resolveLengthVar(lengthVar, &n1, t1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 n2 = e2.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 if (global.params.useArrayBounds)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 elem* elength;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 elem* n2x;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 elem* ea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 if (t1.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 TypeSArray tsa = cast(TypeSArray)t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 ulong length = tsa.dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 elength = el_long(TYuint, length);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 else if (t1.ty == Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 elength = n1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 n1 = el_same(&elength);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 elength = el_una(OP64_32, TYuint, elength);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 n2x = n2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 n2 = el_same(&n2x);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 n2x = el_bin(OPlt, TYint, n2x, elength);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 // Construct: (n2x || ModuleAssert(line))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 Symbol* sassert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 sassert = irs.blx.module_.toModuleArray();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 ea = el_bin(OPcall,TYvoid,el_var(sassert),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 el_long(TYint, loc.linnum));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 eb = el_bin(OPoror,TYvoid,n2x,ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 n1 = array_toPtr(t1, n1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 elem* escale;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 escale = el_long(TYint, t1.nextOf().size());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 n2 = el_bin(OPmul, TYint, n2, escale);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 e = el_bin(OPadd, TYnptr, n1, n2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 e = el_una(OPind, type.totym(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 if (tybasic(e.Ety) == TYstruct || tybasic(e.Ety) == TYarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 e.Ety = TYstruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 e.Enumbytes = cast(uint)type.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 eb = el_combine(einit, eb);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 e = el_combine(eb, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427