annotate dmd/TypeDArray.d @ 23:460959608115

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