annotate dmd/TypeSArray.d @ 12:832f71e6f96c

*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete) Some unittest-specific functions implemented
author korDen
date Mon, 12 Apr 2010 15:13:00 +0400
parents 10317f0c89a5
children f23312cb6f2e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.TypeArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Argument;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.TypeTuple;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.TupleDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.TypeDArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.TypePointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.TypeInfoDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.type.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.backend.dt_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.backend.DT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 // Static array, one with a fixed dimension
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 class TypeSArray : TypeArray
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 Expression dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 this(Type t, Expression dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 super(TY.Tsarray, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 //printf("TypeSArray(%s)\n", dim.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 this.dim = dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 version (DumbClone) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 Type clone()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 Type syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 ulong size(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 if (!dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 return Type.size(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 long sz = dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 long n, n2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 n = next.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 n2 = n * sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 if (n && (n2 / n) != sz)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 goto Loverflow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 sz = n2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 return sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 Loverflow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 error(loc, "index %jd overflow for static array", sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 uint alignsize()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 return next.alignsize();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 Type semantic(Loc loc, Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 //printf("TypeSArray.semantic() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 next.resolve(loc, sc, &e, &t, &s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 if (dim && s && s.isTupleDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 TupleDeclaration sd = s.isTupleDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 dim = semanticLength(sc, sd, dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 dim = dim.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 ulong d = dim.toUInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 if (d >= sd.objects.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 { error(loc, "tuple index %ju exceeds %u", d, sd.objects.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 return Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 ///Object o = cast(Object)sd.objects.data[(size_t)d];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 ///if (o.dyncast() != DYNCAST_TYPE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 ///{
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 /// error(loc, "%s is not a type", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 /// return Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 ///t = cast(Type)o;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 t = cast(Type)sd.objects.data[cast(size_t)d];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 if (t is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 error(loc, "%s is not a type", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 return Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 next = next.semantic(loc,sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 transitive();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 Type tbn = next.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 if (dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 long n, n2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 dim = semanticLength(sc, tbn, dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 dim = dim.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 if (sc && sc.parameterSpecialization && dim.op == TOK.TOKvar &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 (cast(VarExp)dim).var.storage_class & STC.STCtemplateparameter)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 /* It could be a template parameter N which has no value yet:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 * template Foo(T : T[N], size_t N);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 long d1 = dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 dim = dim.castTo(sc, tsize_t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 dim = dim.optimize(WANT.WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 long d2 = dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 if (d1 != d2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 goto Loverflow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 if (tbn.isintegral() ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 tbn.isfloating() ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 tbn.ty == TY.Tpointer ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 tbn.ty == TY.Tarray ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 tbn.ty == TY.Tsarray ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 tbn.ty == TY.Taarray ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 tbn.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 /* Only do this for types that don't need to have semantic()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 * run on them for the size, since they may be forward referenced.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 n = tbn.size(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 n2 = n * d2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 if (cast(int)n2 < 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 goto Loverflow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 if (n2 >= 0x1000000) // put a 'reasonable' limit on it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 goto Loverflow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 if (n && n2 / n != d2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 Loverflow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 error(loc, "index %jd overflow for static array", d1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 dim = new IntegerExp(Loc(0), 1, tsize_t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 switch (tbn.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 case TY.Ttuple:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 { // Index the tuple to get the type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 assert(dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 TypeTuple tt = cast(TypeTuple)tbn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 ulong d = dim.toUInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 if (d >= tt.arguments.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 error(loc, "tuple index %ju exceeds %u", d, tt.arguments.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 return Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 Argument arg = cast(Argument)tt.arguments.data[cast(size_t)d];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 return arg.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 case TY.Tstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 { TypeStruct ts = cast(TypeStruct)tbn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 if (ts.sym.isnested)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 error(loc, "cannot have array of inner structs %s", ts.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 case TY.Tfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 case TY.Tnone:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 error(loc, "can't have array of %s", tbn.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 tbn = next = tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 default: ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 if (tbn.isauto())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 error(loc, "cannot have array of auto %s", tbn.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 return merge();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 void toDecoBuffer(OutBuffer buf, int flag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 Type.toDecoBuffer(buf, flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 if (dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 //buf.printf("%ju", dim.toInteger()); ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 buf.printf("%s", dim.toInteger());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 if (next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 /* Note that static arrays are value types, so
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 * for a parameter, propagate the 0x100 to the next
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 * level, since for T[4][3], any const should apply to the T,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 * not the [4].
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 next.toDecoBuffer(buf, (flag & 0x100) ? flag : mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 Expression dotExp(Scope sc, Expression e, Identifier ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 version (LOGDOTEXP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 printf("TypeSArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 if (ident == Id.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 e = dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 else if (ident == Id.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 e = e.castTo(sc, next.pointerTo());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 e = TypeArray.dotExp(sc, e, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
261 bool isString()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 bool isZeroInit(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 return next.isZeroInit(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 uint memalign(uint salign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 return next.memalign(salign);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 MATCH constConv(Type to)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 MATCH implicitConvTo(Type to)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 //printf("TypeSArray.implicitConvTo(to = %s) this = %s\n", to.toChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 // Allow implicit conversion of static array to pointer or dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 if (IMPLICIT_ARRAY_TO_PTR && to.ty == Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 TypePointer tp = cast(TypePointer)to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 if (next.mod != tp.next.mod && tp.next.mod != MODconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 if (tp.next.ty == Tvoid || next.constConv(tp.next) != MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 return MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 if (to.ty == Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 int offset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 TypeDArray ta = cast(TypeDArray)to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 if (next.mod != ta.next.mod && ta.next.mod != MODconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 if (next.equals(ta.next) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 next.implicitConvTo(ta.next) >= MATCHconst ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 (ta.next.isBaseOf(next, &offset) && offset == 0) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 ta.next.ty == Tvoid
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 return MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 if (to.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 if (this == to)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 return MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 TypeSArray tsa = cast(TypeSArray)to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 if (dim.equals(tsa.dim))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 /* Since static arrays are value types, allow
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 * conversions from const elements to non-const
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 * ones, just like we allow conversion from const int
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 * to int.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 MATCH m = next.implicitConvTo(tsa.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 if (m >= MATCHconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 if (mod != to.mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 m = MATCHconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 Expression defaultInit(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 version (LOGDEFAULTINIT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 printf("TypeSArray.defaultInit() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 return next.defaultInit(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 dt_t** toDt(dt_t** pdt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 return toDtElem(pdt, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 dt_t** toDtElem(dt_t** pdt, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 //printf("TypeSArray::toDtElem()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 uint len = cast(uint)dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 if (len)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 while (*pdt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 pdt = &((*pdt).DTnext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 Type tnext = next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 Type tbn = tnext.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 while (tbn.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 TypeSArray tsa = cast(TypeSArray)tbn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 len *= tsa.dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 tnext = tbn.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 tbn = tnext.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 if (!e) // if not already supplied
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 e = tnext.defaultInit(Loc(0)); // use default initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 if (tbn.ty == Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 tnext.toDt(pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 e.toDt(pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 dt_optimize(*pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 if ((*pdt).dt == DT_azeros && !(*pdt).DTnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 (*pdt).DTazeros *= len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 pdt = &((*pdt).DTnext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 else if ((*pdt).dt == DT_1byte && (*pdt).DTonebyte == 0 && !(*pdt).DTnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 (*pdt).dt = DT_azeros;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 (*pdt).DTazeros = len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 pdt = &((*pdt).DTnext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 else if (e.op != TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 for (i = 1; i < len; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 if (tbn.ty == Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 pdt = tnext.toDt(pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 while (*pdt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 pdt = &((*pdt).DTnext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 pdt = e.toDt(pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 return pdt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 TypeInfoDeclaration getTypeInfoDeclaration()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 Expression toExpression()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 bool hasPointers()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 return next.hasPointers();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 version (CPP_MANGLE) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 void toCppMangle(OutBuffer buf, CppMangleState* cms)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 type* toCtype()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 if (!ctype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 type* tn = next.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 ctype = type_allocn(TYarray, tn);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 ctype.Tdim = cast(uint)dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 return ctype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 type* toCParamtype()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 // arrays are passed as pointers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 return next.pointerTo().toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 }