annotate dmd/expression/Cat.d @ 0:10317f0c89a5

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