annotate dmd/TypeSArray.d @ 114:e28b18c23469

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