annotate dmd/TypeDArray.d @ 187:b0d41ff5e0df

Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author Abscissa
date Tue, 07 Jun 2011 23:37:34 -0400
parents 190ba98276b3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypeDArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 96
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.TypeArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.StringExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.ArrayLengthExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.TypeInfoDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.TypeInfoArrayDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.NullExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.TypePointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.backend.Classsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import core.stdc.stdlib;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import core.stdc.stdio;
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
39 version (Bug4054) import core.memory;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 183
diff changeset
41 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 183
diff changeset
42
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 // Dynamic array, no dimension
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 class TypeDArray : TypeArray
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 183
diff changeset
46 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 183
diff changeset
47
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 this(Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
50 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 super(TY.Tarray, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 //printf("TypeDArray(t = %p)\n", t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
55 override Type syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 Type t = next.syntaxCopy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 if (t == next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 t = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 t = new TypeDArray(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 t.mod = mod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 return t;
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: 23
diff changeset
68 override ulong size(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 //printf("TypeDArray.size()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 return PTRSIZE * 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
74 override uint alignsize()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 // A DArray consists of two ptr-sized values, so align it on pointer size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 // boundary
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 return PTRSIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
81 override Type semantic(Loc loc, Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 Type tn = next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 tn = next.semantic(loc,sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 Type tbn = tn.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 switch (tbn.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 case TY.Tfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 case TY.Tnone:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 case TY.Ttuple:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 error(loc, "can't have array of %s", tbn.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 tn = next = tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 case TY.Tstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 TypeStruct ts = cast(TypeStruct)tbn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 if (ts.sym.isnested)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 error(loc, "cannot have array of inner structs %s", ts.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 if (tn.isauto())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 error(loc, "cannot have array of auto %s", tn.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 next = tn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 transitive();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 return merge();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
114 override void toDecoBuffer(OutBuffer buf, int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 Type.toDecoBuffer(buf, flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 if (next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 next.toDecoBuffer(buf, (flag & 0x100) ? 0 : mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120
96
acd69f84627e further work
Trass3r
parents: 72
diff changeset
121 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 if (mod != this.mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 toCBuffer3(buf, hgs, mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 }
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 135
diff changeset
128 if (equals(global.tstring))
96
acd69f84627e further work
Trass3r
parents: 72
diff changeset
129 buf.writestring("string");
acd69f84627e further work
Trass3r
parents: 72
diff changeset
130 else
acd69f84627e further work
Trass3r
parents: 72
diff changeset
131 {
acd69f84627e further work
Trass3r
parents: 72
diff changeset
132 next.toCBuffer2(buf, hgs, this.mod);
acd69f84627e further work
Trass3r
parents: 72
diff changeset
133 buf.writestring("[]");
acd69f84627e further work
Trass3r
parents: 72
diff changeset
134 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
137 override Expression dotExp(Scope sc, Expression e, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 version (LOGDOTEXP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 printf("TypeDArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 if (ident is Id.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 if (e.op == TOK.TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 StringExp se = cast(StringExp)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 return new IntegerExp(se.loc, se.len, Type.tindex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 e = new ArrayLengthExp(e.loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 e.type = Type.tsize_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 else if (ident is Id.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 e = e.castTo(sc, next.pointerTo());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 e = TypeArray.dotExp(sc, e, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
166 override bool isString()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 {
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
168 TY nty = next.toBasetype().ty;
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 0
diff changeset
169 return nty == Tchar || nty == Twchar || nty == Tdchar;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
172 override bool isZeroInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
177 override bool checkBoolean()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
182 override MATCH implicitConvTo(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 //printf("TypeDArray.implicitConvTo(to = %s) this = %s\n", to.toChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 if (equals(to))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 return MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 // Allow implicit conversion of array to pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 if (IMPLICIT_ARRAY_TO_PTR && to.ty == Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 TypePointer tp = cast(TypePointer)to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 /* Allow conversion to void*
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 if (tp.next.ty == Tvoid &&
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
196 MODimplicitConv(next.mod, tp.next.mod))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 return MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 return next.constConv(to);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 if (to.ty == Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 int offset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 TypeDArray ta = cast(TypeDArray)to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
209 if (!MODimplicitConv(next.mod, ta.next.mod))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 return MATCHnomatch; // not const-compatible
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 /* Allow conversion to void[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 if (next.ty != Tvoid && ta.next.ty == Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 return MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 MATCH m = next.constConv(ta.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 if (m != MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 if (m == MATCHexact && mod != to.mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 m = MATCHconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
227 static if(false) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 /* Allow conversions of T[][] to const(T)[][]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 if (mod == ta.mod && next.ty == Tarray && ta.next.ty == Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 m = next.implicitConvTo(ta.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 if (m == MATCHconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 }
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
236 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 /* Conversion of array of derived to array of base
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 if (ta.next.isBaseOf(next, &offset) && offset == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 return MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 return Type.implicitConvTo(to);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
245 override Expression defaultInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 version (LOGDEFAULTINIT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 printf("TypeDArray.defaultInit() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 }
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
250 return new NullExp(loc, this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
253 override bool builtinTypeInfo()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 return !mod && (next.isTypeBasic() !is null && !next.mod ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 // strings are so common, make them builtin
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
258 next.ty == Tchar && next.mod == MODimmutable);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 return next.isTypeBasic() !is null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 version (DMDV2) {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
264 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 printf("TypeDArray.deduceType()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 printf("\tthis = %d, ", ty); print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 printf("\ttparam = %d, ", tparam.ty); tparam.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 return Type.deduceType(sc, tparam, parameters, dedtypes);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 Lnomatch:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 return MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
277 override TypeInfoDeclaration getTypeInfoDeclaration()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 return new TypeInfoArrayDeclaration(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
282 override bool hasPointers()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 version (CPP_MANGLE) {
183
190ba98276b3 Several changes to make it build on posix systems.
Jacob Carlborg <doob@me.com>
parents: 178
diff changeset
288 void toCppMangle(OutBuffer buf, CppMangleState* cms)
190ba98276b3 Several changes to make it build on posix systems.
Jacob Carlborg <doob@me.com>
parents: 178
diff changeset
289 {
190ba98276b3 Several changes to make it build on posix systems.
Jacob Carlborg <doob@me.com>
parents: 178
diff changeset
290 assert(false);
190ba98276b3 Several changes to make it build on posix systems.
Jacob Carlborg <doob@me.com>
parents: 178
diff changeset
291 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
294 override type* toCtype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 type *t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 if (ctype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 return ctype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 if (0 && global.params.symdebug)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 /* Create a C type out of:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 * struct _Array_T { size_t length; T* data; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 char *id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 assert(next.deco);
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
310 version (Bug4054)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
311 id = cast(char*) GC.malloc(7 + next.deco.length + 1);
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
312 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 id = cast(char*) alloca(7 + next.deco.length + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 sprintf(id, "_Array_%.*s", next.deco);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 s = symbol_calloc(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 s.Sclass = SC.SCstruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 s.Sstruct = struct_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 s.Sstruct.Sflags |= 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 s.Sstruct.Salignsize = alignsize();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 s.Sstruct.Sstructalign = cast(ubyte)global.structalign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 s.Sstruct.Sstructsize = cast(uint)size(Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 Symbol* s1 = symbol_name("length", SC.SCmember, Type.tsize_t.toCtype());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 list_append(&s.Sstruct.Sfldlst, s1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 Symbol* s2 = symbol_name("data", SC.SCmember, next.pointerTo().toCtype());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 s2.Smemoff = cast(uint)Type.tsize_t.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 list_append(&s.Sstruct.Sfldlst, s2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 t = type_alloc(TYM.TYstruct);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 t.Ttag = cast(Classsym*)s; // structure tag name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 s.Stype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 if (global.params.symdebug == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 // Generate D symbolic debug info, rather than C
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 t = type_allocn(TYM.TYdarray, next.toCtype());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 t = type_fake(TYM.TYdarray);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 ctype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 }
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
350 }