annotate dmd/expression/Cat.d @ 34:544b922227c7

update to work with dmd 2.048
author korDen
date Sat, 21 Aug 2010 05:46:08 +0400
parents d706d958e4e8
children be2ab491772e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.expression.Cat;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.StringExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.ArrayLiteralExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.GlobalExpressions;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
17 import core.memory;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
18
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import core.stdc.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import core.stdc.stdlib;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
34
544b922227c7 update to work with dmd 2.048
korDen
parents: 4
diff changeset
22 import std.exception;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 /* Also return EXP_CANT_INTERPRET if this fails
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 Expression Cat(Type type, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 Expression e = EXP_CANT_INTERPRET;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 Loc loc = e1.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 Type t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 Type t2 = e2.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 //printf("Cat(e1 = %s, e2 = %s)\n", e1.toChars(), e2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 //printf("\tt1 = %s, t2 = %s\n", t1.toChars(), t2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 if (e1.op == TOKnull && (e2.op == TOKint64 || e2.op == TOKstructliteral))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 e = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 else if ((e1.op == TOKint64 || e1.op == TOKstructliteral) && e2.op == TOKnull)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 e = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 Type tn = e.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 if (tn.ty == Tchar || tn.ty == Twchar || tn.ty == Tdchar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 // Create a StringExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 size_t len = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 int sz = cast(int)tn.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 ulong v = e.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
56 char* s = cast(char*)GC.malloc((len + 1) * sz);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 memcpy(s, &v, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 // Add terminating 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 memset(s + len * sz, 0, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 StringExp es = new StringExp(loc, assumeUnique(s[0..len]));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 es.sz = cast(ubyte)sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 es.committed = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 e = es;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 // Create an ArrayLiteralExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 Expressions elements = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 elements.push(cast(void*)e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 e = new ArrayLiteralExp(e.loc, elements);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 else if (e1.op == TOKstring && e2.op == TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 // Concatenate the strings
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 StringExp es1 = cast(StringExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 StringExp es2 = cast(StringExp)e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 size_t len = es1.len + es2.len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 int sz = es1.sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 if (sz != es2.sz)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 /* Can happen with:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 * auto s = "foo"d ~ "bar"c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 assert(global.errors);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
95 char* s = cast(char*)GC.malloc((len + 1) * sz);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 memcpy(s, es1.string_, es1.len * sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 memcpy(s + es1.len * sz, es2.string_, es2.len * sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 // Add terminating 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 memset(s + len * sz, 0, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 StringExp es = new StringExp(loc, assumeUnique(s[0..len]));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 es.sz = cast(ubyte)sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 es.committed = es1.committed | es2.committed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 Type tt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 if (es1.committed)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 tt = es1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 tt = es2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 es.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 e = es;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 else if (e1.op == TOKstring && e2.op == TOKint64)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 // Concatenate the strings
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 StringExp es1 = cast(StringExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 size_t len = es1.len + 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 int sz = es1.sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 ulong v = e2.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
123 char* s = cast(char*)GC.malloc((len + 1) * sz);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 memcpy(s, es1.string_, es1.len * sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 memcpy(s + es1.len * sz, &v, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 // Add terminating 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 memset(s + len * sz, 0, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 StringExp es = new StringExp(loc, assumeUnique(s[0..len]));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 es.sz = cast(ubyte)sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 es.committed = es1.committed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 Type tt = es1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 es.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 e = es;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 else if (e1.op == TOKint64 && e2.op == TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 // Concatenate the strings
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 StringExp es2 = cast(StringExp)e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 size_t len = 1 + es2.len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 int sz = es2.sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 ulong v = e1.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
145 char* s = cast(char*)GC.malloc((len + 1) * sz);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 memcpy(s, &v, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 memcpy(s + sz, es2.string_, es2.len * sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 // Add terminating 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 memset(s + len * sz, 0, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 StringExp es = new StringExp(loc, assumeUnique(s[0..len]));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 es.sz = cast(ubyte)sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 es.committed = es2.committed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 Type tt = es2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 es.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 e = es;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 else if (e1.op == TOKarrayliteral && e2.op == TOKarrayliteral &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 t1.nextOf().equals(t2.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 // Concatenate the arrays
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 ArrayLiteralExp es1 = cast(ArrayLiteralExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 ArrayLiteralExp es2 = cast(ArrayLiteralExp)e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 es1 = new ArrayLiteralExp(es1.loc, cast(Expressions)es1.elements.copy());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 es1.elements.insert(es1.elements.dim, es2.elements);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 e = es1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 if (type.toBasetype().ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 e.type = new TypeSArray(t1.nextOf(), new IntegerExp(loc, es1.elements.dim, Type.tindex));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 e.type = e.type.semantic(loc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 else if (e1.op == TOKarrayliteral && e2.op == TOKnull &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 t1.nextOf().equals(t2.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 e = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 else if (e1.op == TOKnull && e2.op == TOKarrayliteral &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 t1.nextOf().equals(t2.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 e = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 L3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 // Concatenate the array with null
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 ArrayLiteralExp es = cast(ArrayLiteralExp)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 es = new ArrayLiteralExp(es.loc, cast(Expressions)es.elements.copy());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 e = es;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 if (type.toBasetype().ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 e.type = new TypeSArray(t1.nextOf(), new IntegerExp(loc, es.elements.dim, Type.tindex));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 e.type = e.type.semantic(loc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 else if ((e1.op == TOKarrayliteral || e1.op == TOKnull) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 e1.type.toBasetype().nextOf().equals(e2.type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 ArrayLiteralExp es1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 if (e1.op == TOKarrayliteral)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 { es1 = cast(ArrayLiteralExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 es1 = new ArrayLiteralExp(es1.loc, cast(Expressions)es1.elements.copy());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 es1.elements.push(cast(void*)e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 es1 = new ArrayLiteralExp(e1.loc, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 e = es1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 if (type.toBasetype().ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 e.type = new TypeSArray(e2.type, new IntegerExp(loc, es1.elements.dim, Type.tindex));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 e.type = e.type.semantic(loc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 else if (e2.op == TOKarrayliteral &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 e2.type.toBasetype().nextOf().equals(e1.type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 ArrayLiteralExp es2 = cast(ArrayLiteralExp)e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 es2 = new ArrayLiteralExp(es2.loc, cast(Expressions)es2.elements.copy());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 es2.elements.shift(cast(void*)e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 e = es2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 if (type.toBasetype().ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 e.type = new TypeSArray(e1.type, new IntegerExp(loc, es2.elements.dim, Type.tindex));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 e.type = e.type.semantic(loc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 else if (e1.op == TOKnull && e2.op == TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 t = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 e = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 else if (e1.op == TOKstring && e2.op == TOKnull)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 e = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 t = e2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 Type tb = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 if (tb.ty == Tarray && tb.nextOf().equals(e.type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 Expressions expressions = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 expressions.push(cast(void*)e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 e = new ArrayLiteralExp(loc, expressions);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 e.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 if (!e.type.equals(type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 StringExp se = cast(StringExp)e.copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 e = se.castTo(null, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 }