annotate dmd/TypeSArray.d @ 113:3482c73a991b

More cleanup for arrays
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Tue, 31 Aug 2010 23:57:32 +0100
parents 12c0c84d13fd
children e28b18c23469
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;
64
4290d870944a More fixes
korDen
parents: 51
diff changeset
4 import dmd.TypeInfoStaticArrayDeclaration;
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
5 import dmd.TypeAArray;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Argument;
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
8 import dmd.TypeIdentifier;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
9 import dmd.TemplateParameter;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
10 import dmd.TemplateValueParameter;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.TypeTuple;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.TupleDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.TypeDArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.TypePointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.TypeInfoDeclaration;
41
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
32 import dmd.ScopeDsymbol;
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
33 import dmd.ArrayScopeSymbol;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.Id;
41
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
37 import dmd.IndexExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.type.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.backend.dt_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.backend.DT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 // Static array, one with a fixed dimension
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 class TypeSArray : TypeArray
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 Expression dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 this(Type t, Expression dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 super(TY.Tsarray, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 //printf("TypeSArray(%s)\n", dim.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 this.dim = dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 version (DumbClone) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 Type clone()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
67 override Type syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 {
41
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
69 Type t = next.syntaxCopy();
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
70 Expression e = dim.syntaxCopy();
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
71 t = new TypeSArray(t, e);
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
72 t.mod = mod;
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
73 return t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
76 override ulong size(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 if (!dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 return Type.size(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 long sz = dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 long n, n2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 n = next.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 n2 = n * sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 if (n && (n2 / n) != sz)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 goto Loverflow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 sz = n2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 return sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 Loverflow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 error(loc, "index %jd overflow for static array", sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
99 override uint alignsize()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 return next.alignsize();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
104 override Type semantic(Loc loc, Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 //printf("TypeSArray.semantic() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 next.resolve(loc, sc, &e, &t, &s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 if (dim && s && s.isTupleDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 TupleDeclaration sd = s.isTupleDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 dim = semanticLength(sc, sd, dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 dim = dim.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 ulong d = dim.toUInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 if (d >= sd.objects.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 { error(loc, "tuple index %ju exceeds %u", d, sd.objects.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 return Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 ///Object o = cast(Object)sd.objects.data[(size_t)d];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 ///if (o.dyncast() != DYNCAST_TYPE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 ///{
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 /// error(loc, "%s is not a type", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 /// return Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 ///t = cast(Type)o;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
132 t = cast(Type)sd.objects[cast(size_t)d];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 if (t is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 error(loc, "%s is not a type", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 return Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 next = next.semantic(loc,sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 transitive();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 Type tbn = next.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 if (dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 long n, n2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 dim = semanticLength(sc, tbn, dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 dim = dim.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 if (sc && sc.parameterSpecialization && dim.op == TOK.TOKvar &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 (cast(VarExp)dim).var.storage_class & STC.STCtemplateparameter)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 /* It could be a template parameter N which has no value yet:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 * template Foo(T : T[N], size_t N);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 long d1 = dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 dim = dim.castTo(sc, tsize_t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 dim = dim.optimize(WANT.WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 long d2 = dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 if (d1 != d2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 goto Loverflow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 if (tbn.isintegral() ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 tbn.isfloating() ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 tbn.ty == TY.Tpointer ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 tbn.ty == TY.Tarray ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 tbn.ty == TY.Tsarray ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 tbn.ty == TY.Taarray ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 tbn.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 /* Only do this for types that don't need to have semantic()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 * run on them for the size, since they may be forward referenced.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 n = tbn.size(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 n2 = n * d2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 if (cast(int)n2 < 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 goto Loverflow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 if (n2 >= 0x1000000) // put a 'reasonable' limit on it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 goto Loverflow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 if (n && n2 / n != d2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 Loverflow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 error(loc, "index %jd overflow for static array", d1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 dim = new IntegerExp(Loc(0), 1, tsize_t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 switch (tbn.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 case TY.Ttuple:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 { // Index the tuple to get the type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 assert(dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 TypeTuple tt = cast(TypeTuple)tbn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 ulong d = dim.toUInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 if (d >= tt.arguments.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 error(loc, "tuple index %ju exceeds %u", d, tt.arguments.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 return Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 Argument arg = cast(Argument)tt.arguments.data[cast(size_t)d];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 return arg.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 case TY.Tstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 { TypeStruct ts = cast(TypeStruct)tbn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 if (ts.sym.isnested)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 error(loc, "cannot have array of inner structs %s", ts.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 case TY.Tfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 case TY.Tnone:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 error(loc, "can't have array of %s", tbn.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 tbn = next = tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 default: ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 if (tbn.isauto())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 error(loc, "cannot have array of auto %s", tbn.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 return merge();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
228 override void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 {
41
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
230 //printf("TypeSArray.resolve() %s\n", toChars());
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
231 next.resolve(loc, sc, pe, pt, ps);
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
232 //printf("s = %p, e = %p, t = %p\n", *ps, *pe, *pt);
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
233 if (*pe)
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
234 {
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
235 // It's really an index expression
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
236 Expression e = new IndexExp(loc, *pe, dim);
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
237 *pe = e;
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
238 }
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
239 else if (*ps)
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
240 {
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
241 Dsymbol s = *ps;
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
242 TupleDeclaration td = s.isTupleDeclaration();
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
243 if (td)
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
244 {
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
245 ScopeDsymbol sym = new ArrayScopeSymbol(sc, td);
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
246 sym.parent = sc.scopesym;
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
247 sc = sc.push(sym);
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
248
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
249 dim = dim.semantic(sc);
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
250 dim = dim.optimize(WANTvalue | WANTinterpret);
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
251 ulong d = dim.toUInteger();
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
252
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
253 sc = sc.pop();
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
254
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
255 if (d >= td.objects.dim)
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
256 {
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
257 error(loc, "tuple index %ju exceeds %u", d, td.objects.dim);
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
258 goto Ldefault;
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
259 }
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
260 Object o = td.objects[cast(size_t)d];
41
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
261 if ((*ps = isDsymbol(o)) !is null) /// !
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
262 {
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
263 return;
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
264 }
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
265 if ((*pe = isExpression(o)) !is null) /// !
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
266 {
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
267 return;
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
268 }
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
269
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
270 /* Create a new TupleDeclaration which
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
271 * is a slice [d..d+1] out of the old one.
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
272 * Do it this way because TemplateInstance.semanticTiargs()
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
273 * can handle unresolved Objects this way.
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
274 */
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
275 auto objects = new Objects;
41
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
276 objects.setDim(1);
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
277 objects[0] = o;
41
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
278
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
279 auto tds = new TupleDeclaration(loc, td.ident, objects);
41
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
280 *ps = tds;
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
281 }
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
282 else
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
283 goto Ldefault;
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
284 }
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
285 else
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
286 {
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
287 Ldefault:
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
288 Type.resolve(loc, sc, pe, pt, ps);
f23312cb6f2e TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents: 12
diff changeset
289 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
292 override void toDecoBuffer(OutBuffer buf, int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 Type.toDecoBuffer(buf, flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 if (dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 //buf.printf("%ju", dim.toInteger()); ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 buf.printf("%s", dim.toInteger());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 if (next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 /* Note that static arrays are value types, so
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 * for a parameter, propagate the 0x100 to the next
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 * level, since for T[4][3], any const should apply to the T,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 * not the [4].
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 next.toDecoBuffer(buf, (flag & 0x100) ? flag : mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
307 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 {
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 64
diff changeset
309 if (mod != this.mod)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 64
diff changeset
310 {
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 64
diff changeset
311 toCBuffer3(buf, hgs, mod);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 64
diff changeset
312 return;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 64
diff changeset
313 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 64
diff changeset
314 next.toCBuffer2(buf, hgs, this.mod);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 64
diff changeset
315 buf.printf("[%s]", dim.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
318 override Expression dotExp(Scope sc, Expression e, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 version (LOGDOTEXP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 printf("TypeSArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 if (ident == Id.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 e = dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 else if (ident == Id.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 e = e.castTo(sc, next.pointerTo());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 e = TypeArray.dotExp(sc, e, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
338 override bool isString()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 {
64
4290d870944a More fixes
korDen
parents: 51
diff changeset
340 TY nty = next.toBasetype().ty;
4290d870944a More fixes
korDen
parents: 51
diff changeset
341 return nty == Tchar || nty == Twchar || nty == Tdchar;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
344 override bool isZeroInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 return next.isZeroInit(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
349 override uint memalign(uint salign)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 return next.memalign(salign);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
354 override MATCH constConv(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
359 override MATCH implicitConvTo(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 //printf("TypeSArray.implicitConvTo(to = %s) this = %s\n", to.toChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 // Allow implicit conversion of static array to pointer or dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 if (IMPLICIT_ARRAY_TO_PTR && to.ty == Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 TypePointer tp = cast(TypePointer)to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 if (next.mod != tp.next.mod && tp.next.mod != MODconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 if (tp.next.ty == Tvoid || next.constConv(tp.next) != MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 return MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 if (to.ty == Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 int offset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 TypeDArray ta = cast(TypeDArray)to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 if (next.mod != ta.next.mod && ta.next.mod != MODconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 if (next.equals(ta.next) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 next.implicitConvTo(ta.next) >= MATCHconst ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 (ta.next.isBaseOf(next, &offset) && offset == 0) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 ta.next.ty == Tvoid
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 return MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 if (to.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 if (this == to)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 return MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 TypeSArray tsa = cast(TypeSArray)to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 if (dim.equals(tsa.dim))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 /* Since static arrays are value types, allow
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 * conversions from const elements to non-const
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 * ones, just like we allow conversion from const int
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 * to int.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 MATCH m = next.implicitConvTo(tsa.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 if (m >= MATCHconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 if (mod != to.mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 m = MATCHconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
420 override Expression defaultInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 version (LOGDEFAULTINIT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 printf("TypeSArray.defaultInit() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 return next.defaultInit(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
428 override dt_t** toDt(dt_t** pdt)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 return toDtElem(pdt, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 dt_t** toDtElem(dt_t** pdt, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 //printf("TypeSArray::toDtElem()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 uint len = cast(uint)dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 if (len)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 while (*pdt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 pdt = &((*pdt).DTnext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 Type tnext = next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 Type tbn = tnext.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 while (tbn.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 TypeSArray tsa = cast(TypeSArray)tbn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 len *= tsa.dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 tnext = tbn.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 tbn = tnext.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 if (!e) // if not already supplied
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 e = tnext.defaultInit(Loc(0)); // use default initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 if (tbn.ty == Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 tnext.toDt(pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 e.toDt(pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 dt_optimize(*pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 if ((*pdt).dt == DT_azeros && !(*pdt).DTnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 (*pdt).DTazeros *= len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 pdt = &((*pdt).DTnext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 else if ((*pdt).dt == DT_1byte && (*pdt).DTonebyte == 0 && !(*pdt).DTnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 (*pdt).dt = DT_azeros;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 (*pdt).DTazeros = len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 pdt = &((*pdt).DTnext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 else if (e.op != TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 for (i = 1; i < len; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 if (tbn.ty == Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 pdt = tnext.toDt(pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 while (*pdt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 pdt = &((*pdt).DTnext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 pdt = e.toDt(pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 return pdt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
489 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
491 static if (false) {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
492 printf("TypeSArray.deduceType()\n");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
493 printf("\tthis = %d, ", ty); print();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
494 printf("\ttparam = %d, ", tparam.ty); tparam.print();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
495 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
496
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
497 // Extra check that array dimensions must match
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
498 if (tparam)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
499 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
500 if (tparam.ty == Tsarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
501 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
502 TypeSArray tp = cast(TypeSArray)tparam;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
503
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
504 if (tp.dim.op == TOKvar && (cast(VarExp)tp.dim).var.storage_class & STCtemplateparameter)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
505 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
506 int i = templateIdentifierLookup((cast(VarExp)tp.dim).var.ident, parameters);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
507 // This code matches code in TypeInstance.deduceType()
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
508 if (i == -1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
509 goto Lnomatch;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
510 TemplateParameter tp2 = cast(TemplateParameter)parameters.data[i];
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
511 TemplateValueParameter tvp = tp2.isTemplateValueParameter();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
512 if (!tvp)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
513 goto Lnomatch;
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
514 Expression e = cast(Expression)dedtypes[i];
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
515 if (e)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
516 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
517 if (!dim.equals(e))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
518 goto Lnomatch;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
519 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
520 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
521 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
522 Type vt = tvp.valType.semantic(Loc(0), sc);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
523 MATCH m = cast(MATCH)dim.implicitConvTo(vt);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
524 if (!m)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
525 goto Lnomatch;
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
526 dedtypes[i] = dim;
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
527 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
528 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
529 else if (dim.toInteger() != tp.dim.toInteger())
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
530 return MATCHnomatch;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
531 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
532 else if (tparam.ty == Taarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
533 {
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
534 auto tp = cast(TypeAArray)tparam;
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
535 if (tp.index.ty == Tident)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
536 {
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
537 auto tident = cast(TypeIdentifier)tp.index;
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
538
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
539 if (tident.idents.dim == 0)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
540 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
541 Identifier id = tident.ident;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
542
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
543 for (size_t i = 0; i < parameters.dim; i++)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
544 {
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
545 auto tp2 = cast(TemplateParameter)parameters.data[i];
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
546
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
547 if (tp2.ident.equals(id))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
548 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
549 // Found the corresponding template parameter
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
550 TemplateValueParameter tvp = tp2.isTemplateValueParameter();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
551 if (!tvp || !tvp.valType.isintegral())
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
552 goto Lnomatch;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
553
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
554 if (dedtypes[i])
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
555 {
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
556 if (!dim.equals(dedtypes[i]))
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
557 goto Lnomatch;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
558 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
559 else
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
560 { dedtypes[i] = dim;
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
561 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
562 return next.deduceType(sc, tparam.nextOf(), parameters, dedtypes);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
563 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
564 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
565 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
566 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
567 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
568 else if (tparam.ty == Tarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
569 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
570 MATCH m;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
571
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
572 m = next.deduceType(sc, tparam.nextOf(), parameters, dedtypes);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
573 if (m == MATCHexact)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
574 m = MATCHconvert;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
575 return m;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
576 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
577 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
578 return Type.deduceType(sc, tparam, parameters, dedtypes);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
579
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
580 Lnomatch:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
581 return MATCHnomatch;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
584 override TypeInfoDeclaration getTypeInfoDeclaration()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 {
64
4290d870944a More fixes
korDen
parents: 51
diff changeset
586 return new TypeInfoStaticArrayDeclaration(this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
589 override Expression toExpression()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
594 override bool hasPointers()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 return next.hasPointers();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 version (CPP_MANGLE) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 void toCppMangle(OutBuffer buf, CppMangleState* cms)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
606 override type* toCtype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 if (!ctype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 type* tn = next.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 ctype = type_allocn(TYarray, tn);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 ctype.Tdim = cast(uint)dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 return ctype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
618 override type* toCParamtype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 {
96
acd69f84627e further work
Trass3r
parents: 72
diff changeset
620 version(SARRAYVALUE)
acd69f84627e further work
Trass3r
parents: 72
diff changeset
621 {
acd69f84627e further work
Trass3r
parents: 72
diff changeset
622 return toCtype();
acd69f84627e further work
Trass3r
parents: 72
diff changeset
623 }
acd69f84627e further work
Trass3r
parents: 72
diff changeset
624 else
acd69f84627e further work
Trass3r
parents: 72
diff changeset
625 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 // arrays are passed as pointers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 return next.pointerTo().toCtype();
96
acd69f84627e further work
Trass3r
parents: 72
diff changeset
628 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
630 }