annotate dmd/expression/Cat.d @ 114:e28b18c23469

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