annotate dmd/ArrayLiteralExp.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 ee3a9f34dc48
children be2ab491772e
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: 68
diff changeset
1 module dmd.ArrayLiteralExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
2
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
3 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
4 import dmd.backend.elem;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
5 import dmd.InterState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
6 import dmd.MATCH;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
7 import dmd.Type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
8 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
9 import dmd.Loc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.WANT;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
11 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
12 import dmd.InlineCostState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
13 import dmd.IRState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
14 import dmd.InlineDoState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
15 import dmd.HdrGenState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
16 import dmd.backend.dt_t;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
17 import dmd.InlineScanState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
18 import dmd.ArrayTypes;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.StringExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.backend.RTLSYM;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
28 import dmd.backend.OPER;
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 63
diff changeset
29 import dmd.backend.Symbol;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.backend.TYM;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
31 import dmd.backend.mTY;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
32 import dmd.codegen.Util;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
33
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 class ArrayLiteralExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 Expressions elements;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 this(Loc loc, Expressions elements)
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
39 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 super(loc, TOK.TOKarrayliteral, ArrayLiteralExp.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 this.elements = elements;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 this(Loc loc, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 super(loc, TOK.TOKarrayliteral, ArrayLiteralExp.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 elements = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 elements.push(cast(void*)e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
51 override Expression syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 return new ArrayLiteralExp(loc, arraySyntaxCopy(elements));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
56 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 Type t0 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 printf("ArrayLiteralExp.semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 // Run semantic() on each element
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 for (int i = 0; i < elements.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 e = cast(Expression)elements.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 assert(e.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 elements.data[i] = cast(void*)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 expandTuples(elements);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 for (int i = 0; i < elements.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 e = cast(Expression)elements.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 if (!e.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 error("%s has no value", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 e = resolveProperties(sc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 ubyte committed = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 if (e.op == TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 committed = (cast(StringExp)e).committed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 if (!t0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 t0 = e.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 // Convert any static arrays to dynamic arrays
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 if (t0.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 t0 = (cast(TypeSArray)t0).next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 e = e.implicitCastTo(sc, t0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 e = e.implicitCastTo(sc, t0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 if (!committed && e.op == TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 StringExp se = cast(StringExp)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 se.committed = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 elements.data[i] = cast(void*)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 if (!t0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 t0 = Type.tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 type = new TypeSArray(t0, new IntegerExp(elements.dim));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
119 override bool isBool(bool result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 size_t dim = elements ? elements.dim : 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 return result ? (dim != 0) : (dim == 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
125 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 size_t dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 //printf("ArrayLiteralExp.toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 if (elements)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 scope Expressions args = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 dim = elements.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 args.setDim(dim + 1); // +1 for number of args parameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 e = el_long(TYint, dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 args.data[dim] = cast(void*)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 for (size_t i = 0; i < dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 Expression el = cast(Expression)elements.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 elem* ep = el.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 if (tybasic(ep.Ety) == TYstruct || tybasic(ep.Ety) == TYarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 ep = el_una(OPstrpar, TYstruct, ep);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 ep.Enumbytes = cast(uint)el.type.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 args.data[dim - (i + 1)] = cast(void *)ep;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 /* Because the number of parameters can get very large, produce
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 * a balanced binary tree so we don't blow up the stack in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 * the subsequent tree walking code.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 e = el_params(args.data, dim + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 dim = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 e = el_long(TYint, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 Type tb = type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 e = el_param(e, type.getTypeInfo(null).toElem(irs));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 // call _d_arrayliteralT(ti, dim, ...)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 e = el_bin(OPcall,TYnptr,el_var(rtlsym[RTLSYM_ARRAYLITERALT]),e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 e = el_param(e, el_long(TYint, tb.next.size()));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 // call _d_arrayliteral(size, dim, ...)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 e = el_bin(OPcall,TYnptr,el_var(rtlsym[RTLSYM_ARRAYLITERAL]),e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 if (tb.ty == Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 e = el_pair(TYullong, el_long(TYint, dim), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 else if (tb.ty == Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 e = el_una(OPind,TYstruct,e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 e.Enumbytes = cast(uint)type.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
191 override bool checkSideEffect(int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 bool f = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 for (size_t i = 0; i < elements.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 Expression e = cast(Expression)elements.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 f |= e.checkSideEffect(2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 if (flag == 0 && f == false)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 Expression.checkSideEffect(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
206 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 buf.writeByte('[');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 argsToCBuffer(buf, elements, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 buf.writeByte(']');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
213 override void toMangleBuffer(OutBuffer buf)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 size_t dim = elements ? elements.dim : 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 buf.printf("A%u", dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 for (size_t i = 0; i < dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 Expression e = cast(Expression)elements.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 e.toMangleBuffer(buf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
224 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
229 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 if (elements)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 for (size_t i = 0; i < elements.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 Expression e = cast(Expression)elements.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 e = e.optimize(WANTvalue | (result & WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 elements.data[i] = cast(void*)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 return this;
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: 68
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: 68
diff changeset
250 override MATCH implicitConvTo(Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 MATCH result = MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 printf("ArrayLiteralExp.implicitConvTo(this=%s, type=%s, t=%s)\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 toChars(), type.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 Type typeb = type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 Type tb = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 if ((tb.ty == Tarray || tb.ty == Tsarray) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 (typeb.ty == Tarray || typeb.ty == Tsarray))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 if (tb.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 TypeSArray tsa = cast(TypeSArray)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 if (elements.dim != tsa.dim.toInteger())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 result = MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 for (int i = 0; i < elements.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 Expression e = cast(Expression)elements.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 MATCH m = cast(MATCH)e.implicitConvTo(tb.nextOf());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 if (m < result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 result = m; // remember worst match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 if (result == MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 break; // no need to check for worse
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 return Expression.implicitConvTo(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
285 override Expression castTo(Scope sc, Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 printf("ArrayLiteralExp.castTo(this=%s, type=%s, => %s)\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 toChars(), type.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 if (type == t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 ArrayLiteralExp e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 Type typeb = type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 Type tb = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 if ((tb.ty == Tarray || tb.ty == Tsarray) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 (typeb.ty == Tarray || typeb.ty == Tsarray) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 // Not trying to convert non-void[] to void[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 !(tb.nextOf().toBasetype().ty == Tvoid && typeb.nextOf().toBasetype().ty != Tvoid))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 if (tb.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 TypeSArray tsa = cast(TypeSArray)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 if (elements.dim != tsa.dim.toInteger())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 e = cast(ArrayLiteralExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 e.elements = cast(Expressions)elements.copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 for (int i = 0; i < elements.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 Expression ex = cast(Expression)elements.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 ex = ex.castTo(sc, tb.nextOf());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 e.elements.data[i] = cast(void*)ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 e.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 if (tb.ty == Tpointer && typeb.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 Type tp = typeb.nextOf().pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 if (!tp.equals(e.type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 e = cast(ArrayLiteralExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 e.type = tp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 return e.Expression.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
332 override dt_t** toDt(dt_t** pdt)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
334 //printf("ArrayLiteralExp.toDt() '%s', type = %s\n", toChars(), type.toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
335
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
336 dt_t *d;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
337 dt_t **pdtend;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
338
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
339 d = null;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
340 pdtend = &d;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
341 for (int i = 0; i < elements.dim; i++)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
342 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
343 Expression e = cast(Expression)elements.data[i];
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
344
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
345 pdtend = e.toDt(pdtend);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
346 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
347 Type t = type.toBasetype();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
348
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
349 switch (t.ty)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
350 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
351 case Tsarray:
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
352 pdt = dtcat(pdt, d);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
353 break;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
354
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
355 case Tpointer:
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
356 case Tarray:
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
357 if (t.ty == Tarray)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
358 dtdword(pdt, elements.dim);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
359 if (d)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
360 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
361 // Create symbol, and then refer to it
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
362 Symbol* s;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
363 s = static_sym();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
364 s.Sdt = d;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
365 outdata(s);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
366
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
367 dtxoff(pdt, s, 0, TYnptr);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
368 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
369 else
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
370 dtdword(pdt, 0);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
371
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
372 break;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
373
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
374 default:
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
375 assert(0);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
376 }
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 63
diff changeset
377 return pdt;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 version (DMDV2) {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
381 override bool canThrow()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 return 1; // because it can fail allocating memory
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
386 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 return 1 + arrayInlineCost(ics, elements);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
391 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 ArrayLiteralExp ce = cast(ArrayLiteralExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 ce.elements = arrayExpressiondoInline(elements, ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 return ce;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
398 override Expression inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 Expression e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 //printf("ArrayLiteralExp.inlineScan()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 arrayInlineScan(iss, elements);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408