annotate dmd/TypeSArray.d @ 135:af1bebfd96a4 dmd2037

dmd 2.038
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Mon, 13 Sep 2010 22:19:42 +0100
parents 60bb0fe4563e
children 14feb7ae01a6
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;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
8 import dmd.Parameter;
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);
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
199 auto tt = cast(TypeTuple)tbn;
0
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 }
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
207 auto arg = tt.arguments[cast(size_t)d];
0
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 }
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
336 e = e.semantic(sc);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
340 override bool isString()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 {
64
4290d870944a More fixes
korDen
parents: 51
diff changeset
342 TY nty = next.toBasetype().ty;
4290d870944a More fixes
korDen
parents: 51
diff changeset
343 return nty == Tchar || nty == Twchar || nty == Tdchar;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
346 override bool isZeroInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 return next.isZeroInit(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
351 override uint memalign(uint salign)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 return next.memalign(salign);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
356 override MATCH constConv(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
361 override MATCH implicitConvTo(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 //printf("TypeSArray.implicitConvTo(to = %s) this = %s\n", to.toChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 // Allow implicit conversion of static array to pointer or dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 if (IMPLICIT_ARRAY_TO_PTR && to.ty == Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 TypePointer tp = cast(TypePointer)to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
370 if (!MODimplicitConv(next.mod, tp.next.mod))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 if (tp.next.ty == Tvoid || next.constConv(tp.next) != MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 return MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 if (to.ty == Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 int offset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 TypeDArray ta = cast(TypeDArray)to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
384 if (!MODimplicitConv(next.mod, ta.next.mod))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 if (next.equals(ta.next) ||
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
388 // next.implicitConvTo(ta.next) >= MATCHconst ||
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
389 next.constConv(ta.next) != MATCHnomatch ||
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 (ta.next.isBaseOf(next, &offset) && offset == 0) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 ta.next.ty == Tvoid
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 return MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 if (to.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 if (this == to)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 return MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 TypeSArray tsa = cast(TypeSArray)to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 if (dim.equals(tsa.dim))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 /* Since static arrays are value types, allow
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 * conversions from const elements to non-const
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 * ones, just like we allow conversion from const int
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 * to int.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 MATCH m = next.implicitConvTo(tsa.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 if (m >= MATCHconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 if (mod != to.mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 m = MATCHconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
423 override Expression defaultInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 version (LOGDEFAULTINIT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 printf("TypeSArray.defaultInit() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 return next.defaultInit(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
431 override dt_t** toDt(dt_t** pdt)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 return toDtElem(pdt, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 dt_t** toDtElem(dt_t** pdt, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 //printf("TypeSArray::toDtElem()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 uint len = cast(uint)dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 if (len)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 while (*pdt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 pdt = &((*pdt).DTnext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 Type tnext = next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 Type tbn = tnext.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 while (tbn.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 TypeSArray tsa = cast(TypeSArray)tbn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 len *= tsa.dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 tnext = tbn.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 tbn = tnext.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 if (!e) // if not already supplied
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 e = tnext.defaultInit(Loc(0)); // use default initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 if (tbn.ty == Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 tnext.toDt(pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 e.toDt(pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 dt_optimize(*pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 if ((*pdt).dt == DT_azeros && !(*pdt).DTnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 (*pdt).DTazeros *= len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 pdt = &((*pdt).DTnext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 else if ((*pdt).dt == DT_1byte && (*pdt).DTonebyte == 0 && !(*pdt).DTnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 (*pdt).dt = DT_azeros;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 (*pdt).DTazeros = len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 pdt = &((*pdt).DTnext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 else if (e.op != TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 for (i = 1; i < len; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 if (tbn.ty == Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 pdt = tnext.toDt(pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 while (*pdt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 pdt = &((*pdt).DTnext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 pdt = e.toDt(pdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 return pdt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
492 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
494 static if (false) {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
495 printf("TypeSArray.deduceType()\n");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
496 printf("\tthis = %d, ", ty); print();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
497 printf("\ttparam = %d, ", tparam.ty); tparam.print();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
498 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
499
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
500 // Extra check that array dimensions must match
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
501 if (tparam)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
502 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
503 if (tparam.ty == Tsarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
504 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
505 TypeSArray tp = cast(TypeSArray)tparam;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
506
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
507 if (tp.dim.op == TOKvar && (cast(VarExp)tp.dim).var.storage_class & STCtemplateparameter)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
508 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
509 int i = templateIdentifierLookup((cast(VarExp)tp.dim).var.ident, parameters);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
510 // This code matches code in TypeInstance.deduceType()
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
511 if (i == -1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
512 goto Lnomatch;
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
513 auto tp2 = parameters[i];
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
514 TemplateValueParameter tvp = tp2.isTemplateValueParameter();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
515 if (!tvp)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
516 goto Lnomatch;
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
517 Expression e = cast(Expression)dedtypes[i];
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
518 if (e)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
519 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
520 if (!dim.equals(e))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
521 goto Lnomatch;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
522 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
523 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
524 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
525 Type vt = tvp.valType.semantic(Loc(0), sc);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
526 MATCH m = cast(MATCH)dim.implicitConvTo(vt);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
527 if (!m)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
528 goto Lnomatch;
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
529 dedtypes[i] = dim;
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
530 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
531 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
532 else if (dim.toInteger() != tp.dim.toInteger())
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
533 return MATCHnomatch;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
534 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
535 else if (tparam.ty == Taarray)
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 tp = cast(TypeAArray)tparam;
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
538 if (tp.index.ty == Tident)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
539 {
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
540 auto tident = cast(TypeIdentifier)tp.index;
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
541
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
542 if (tident.idents.dim == 0)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
543 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
544 Identifier id = tident.ident;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
545
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
546 for (size_t i = 0; i < parameters.dim; i++)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
547 {
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
548 auto tp2 = parameters[i];
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
549
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
550 if (tp2.ident.equals(id))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
551 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
552 // Found the corresponding template parameter
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
553 TemplateValueParameter tvp = tp2.isTemplateValueParameter();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
554 if (!tvp || !tvp.valType.isintegral())
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
555 goto Lnomatch;
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 (dedtypes[i])
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
558 {
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 110
diff changeset
559 if (!dim.equals(dedtypes[i]))
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
560 goto Lnomatch;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
561 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
562 else
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
563 { dedtypes[i] = dim;
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
564 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
565 return next.deduceType(sc, tparam.nextOf(), parameters, dedtypes);
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 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
570 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
571 else if (tparam.ty == Tarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
572 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
573 MATCH m;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
574
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
575 m = next.deduceType(sc, tparam.nextOf(), parameters, dedtypes);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
576 if (m == MATCHexact)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
577 m = MATCHconvert;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
578 return m;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
579 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
580 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
581 return Type.deduceType(sc, tparam, parameters, dedtypes);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
582
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
583 Lnomatch:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 41
diff changeset
584 return MATCHnomatch;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
587 override TypeInfoDeclaration getTypeInfoDeclaration()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 {
64
4290d870944a More fixes
korDen
parents: 51
diff changeset
589 return new TypeInfoStaticArrayDeclaration(this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
592 override Expression toExpression()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
597 override bool hasPointers()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 return next.hasPointers();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 version (CPP_MANGLE) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 void toCppMangle(OutBuffer buf, CppMangleState* cms)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
609 override type* toCtype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 if (!ctype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 type* tn = next.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 ctype = type_allocn(TYarray, tn);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 ctype.Tdim = cast(uint)dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 return ctype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
621 override type* toCParamtype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 {
96
acd69f84627e further work
Trass3r
parents: 72
diff changeset
623 version(SARRAYVALUE)
acd69f84627e further work
Trass3r
parents: 72
diff changeset
624 {
acd69f84627e further work
Trass3r
parents: 72
diff changeset
625 return toCtype();
acd69f84627e further work
Trass3r
parents: 72
diff changeset
626 }
acd69f84627e further work
Trass3r
parents: 72
diff changeset
627 else
acd69f84627e further work
Trass3r
parents: 72
diff changeset
628 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 // arrays are passed as pointers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 return next.pointerTo().toCtype();
96
acd69f84627e further work
Trass3r
parents: 72
diff changeset
631 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
633 }