annotate dmd/SliceExp.d @ 12:832f71e6f96c

*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete) Some unittest-specific functions implemented
author korDen
date Mon, 12 Apr 2010 15:13:00 +0400
parents 10317f0c89a5
children a8b50ff7f201
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.SliceExp;
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.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.UnaExp;
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
6 import dmd.Identifier;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
7 import dmd.IdentifierExp;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
8 import dmd.ArrayExp;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
9 import dmd.STC;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.ArrayScopeSymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.TypeTuple;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.TupleExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.TypeClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.InlineCostState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.ErrorExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.TypeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.Argument;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.GlobalExpressions;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.PREC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.expression.Slice;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import core.stdc.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 class SliceExp : UnaExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 Expression upr; // null if implicit 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 Expression lwr; // null if implicit [length - 1]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 VarDeclaration lengthVar = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 this(Loc loc, Expression e1, Expression lwr, Expression upr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 super(loc, TOK.TOKslice, SliceExp.sizeof, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 this.upr = upr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 this.lwr = lwr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 Expression syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 Expression semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 AggregateDeclaration ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 //FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 ScopeDsymbol sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 printf("SliceExp.semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 UnaExp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 e1 = resolveProperties(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 Type t = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 if (t.ty == Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 if (!lwr || !upr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 error("need upper and lower bound to slice pointer");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 else if (t.ty == Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 else if (t.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 else if (t.ty == Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 ad = (cast(TypeClass)t).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 else if (t.ty == Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 ad = (cast(TypeStruct)t).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 if (search_function(ad, Id.slice))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 // Rewrite as e1.slice(lwr, upr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 e = new DotIdExp(loc, e1, Id.slice);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 if (lwr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 assert(upr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 e = new CallExp(loc, e, lwr, upr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 assert(!upr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 e = new CallExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 else if (t.ty == Ttuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 if (!lwr && !upr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 return e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 if (!lwr || !upr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 { error("need upper and lower bound to slice tuple");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 Scope sc2 = sc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 if (t.ty == Tsarray || t.ty == Tarray || t.ty == Ttuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 sym = new ArrayScopeSymbol(sc, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 sym.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 sym.parent = sc.scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 sc2 = sc.push(sym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 if (lwr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 lwr = lwr.semantic(sc2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 lwr = resolveProperties(sc2, lwr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 lwr = lwr.implicitCastTo(sc2, Type.tsize_t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 if (upr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 upr = upr.semantic(sc2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 upr = resolveProperties(sc2, upr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 upr = upr.implicitCastTo(sc2, Type.tsize_t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 if (sc2 != sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 sc2.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 if (t.ty == Ttuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 lwr = lwr.optimize(WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 upr = upr.optimize(WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 ulong i1 = lwr.toUInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 ulong i2 = upr.toUInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 size_t length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 TupleExp te;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 TypeTuple tup;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 if (e1.op == TOKtuple) // slicing an expression tuple
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 te = cast(TupleExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 length = te.exps.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 else if (e1.op == TOKtype) // slicing a type tuple
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 tup = cast(TypeTuple)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 length = Argument.dim(tup.arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 if (i1 <= i2 && i2 <= length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 size_t j1 = cast(size_t) i1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 size_t j2 = cast(size_t) i2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 if (e1.op == TOKtuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 Expressions exps = new Expressions;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 exps.setDim(j2 - j1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 for (size_t i = 0; i < j2 - j1; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 Expression e2 = cast(Expression)te.exps.data[j1 + i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 exps.data[i] = cast(void*)e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 e = new TupleExp(loc, exps);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 Arguments args = new Arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 args.reserve(j2 - j1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 for (size_t i = j1; i < j2; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 Argument arg = Argument.getNth(tup.arguments, i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 args.push(cast(void*)arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 e = new TypeExp(e1.loc, new TypeTuple(args));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 error("string slice [%ju .. %ju] is out of bounds", i1, i2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 e = new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 if (t.ty == Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 type = t.nextOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 Lerror:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 string s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 if (t.ty == Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 s = e1.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 s = t.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 error("%s cannot be sliced with []", s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 e = new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 void checkEscape()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 e1.checkEscape();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 int isLvalue()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 Expression toLvalue(Scope sc, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 Expression modifiableLvalue(Scope sc, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 error("slice expression %s is not a modifiable lvalue", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 expToCBuffer(buf, hgs, e1, precedence[op]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 buf.writeByte('[');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 if (upr || lwr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 if (lwr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 expToCBuffer(buf, hgs, lwr, PREC.PREC_assign);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 buf.writeByte('0');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 buf.writestring("..");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 if (upr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 expToCBuffer(buf, hgs, upr, PREC.PREC_assign);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 buf.writestring("length"); // BUG: should be array.length
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 buf.writeByte(']');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 Expression optimize(int result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 //printf("SliceExp::optimize(result = %d) %s\n", result, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 e1 = e1.optimize(WANTvalue | (result & WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 if (!lwr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 if (e1.op == TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 // Convert slice of string literal into dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 Type t = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 if (t.nextOf())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 e = e1.castTo(null, t.nextOf().arrayOf());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 e1 = fromConstInitializer(result, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 lwr = lwr.optimize(WANTvalue | (result & WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 upr = upr.optimize(WANTvalue | (result & WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 e = Slice(type, e1, lwr, upr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 if (e is EXP_CANT_INTERPRET)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 //printf("-SliceExp::optimize() %s\n", e->toChars());
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 Expression interpret(InterState* istate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 void dump(int indent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 elem* toElem(IRState* irs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 Type t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 //printf("SliceExp.toElem()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 e = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 if (lwr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 elem* elwr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 elem* elwr2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 elem* eupr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 elem* eptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 elem* einit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 int sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 einit = resolveLengthVar(lengthVar, &e, t1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 sz = cast(uint)t1.nextOf().size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 elwr = lwr.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 eupr = upr.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 elwr2 = el_same(&elwr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 // Create an array reference where:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 // length is (upr - lwr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 // pointer is (ptr + lwr*sz)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 // Combine as (length pair ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 if (global.params.useArrayBounds)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 // Checks (unsigned compares):
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 // upr <= array.length
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 // lwr <= upr
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 elem *c1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 elem *c2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 elem *ea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 elem *eb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 elem *eupr2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 elem *elength;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 if (t1.ty == Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 // Just do lwr <= upr check
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 eupr2 = el_same(&eupr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 eupr2.Ety = TYuint; // make sure unsigned comparison
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 c1 = el_bin(OPle, TYint, elwr2, eupr2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 c1 = el_combine(eupr, c1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 else if (t1.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 TypeSArray tsa = cast(TypeSArray)t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 ulong length = tsa.dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 elength = el_long(TYuint, length);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 else if (t1.ty == Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 if (lengthVar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 elength = el_var(lengthVar.toSymbol());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 elength = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 e = el_same(&elength);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 elength = el_una(OP64_32, TYuint, elength);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 eupr2 = el_same(&eupr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 c1 = el_bin(OPle, TYint, eupr, elength);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 eupr2.Ety = TYuint; // make sure unsigned comparison
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 c2 = el_bin(OPle, TYint, elwr2, eupr2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 c1 = el_bin(OPandand, TYint, c1, c2); // (c1 && c2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 // Construct: (c1 || ModuleArray(line))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 Symbol* sassert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 sassert = irs.blx.module_.toModuleArray();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 ea = el_bin(OPcall,TYvoid,el_var(sassert), el_long(TYint, loc.linnum));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 eb = el_bin(OPoror,TYvoid,c1,ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 elwr = el_combine(elwr, eb);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 elwr2 = el_copytree(elwr2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 eupr = el_copytree(eupr2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 eptr = array_toPtr(e1.type, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 elem *elength = el_bin(OPmin, TYint, eupr, elwr2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 eptr = el_bin(OPadd, TYnptr, eptr, el_bin(OPmul, TYint, el_copytree(elwr2), el_long(TYint, sz)));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 e = el_pair(TYullong, elength, eptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 e = el_combine(elwr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 e = el_combine(einit, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 else if (t1.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 e = sarray_toDarray(loc, t1, null, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 void scanForNestedRef(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 void buildArrayIdent(OutBuffer buf, Expressions arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 {
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
451 buf.writestring("Slice");
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
452 arguments.shift(cast(void*)this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 Expression buildArrayLoop(Arguments fparams)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 {
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
457 Identifier id = Identifier.generateId("p", fparams.dim);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
458 Argument param = new Argument(STCconst, type, id, null);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
459 fparams.shift(cast(void*)param);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
460 Expression e = new IdentifierExp(Loc(0), id);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
461 Expressions arguments = new Expressions();
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
462 Expression index = new IdentifierExp(Loc(0), Id.p);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
463 arguments.push(cast(void*)index);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
464 e = new ArrayExp(Loc(0), e, arguments);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
465 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 int inlineCost(InlineCostState* ics)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 int cost = 1 + e1.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 if (lwr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 cost += lwr.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 if (upr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 cost += upr.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 return cost;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 Expression doInline(InlineDoState ids)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 SliceExp are = cast(SliceExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 are.e1 = e1.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 if (lengthVar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 //printf("lengthVar\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 VarDeclaration vd = lengthVar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 ExpInitializer ie;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 ExpInitializer ieto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 VarDeclaration vto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 vto = new VarDeclaration(vd.loc, vd.type, vd.ident, vd.init);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 ///*vto = *vd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 memcpy(cast(void*)vto, cast(void*)vd, VarDeclaration.classinfo.init.length);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 vto.parent = ids.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 vto.csym = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 vto.isym = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 ids.from.push(cast(void*)vd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 ids.to.push(cast(void*)vto);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 if (vd.init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 ie = vd.init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 assert(ie);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 ieto = new ExpInitializer(ie.loc, ie.exp.doInline(ids));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 vto.init = ieto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 are.lengthVar = vto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 if (lwr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 are.lwr = lwr.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 if (upr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 are.upr = upr.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 return are;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 Expression inlineScan(InlineScanState* iss)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 e1 = e1.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 if (lwr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 lwr = lwr.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 if (upr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 upr = upr.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531