annotate dmd/TypeAArray.d @ 84:be2ab491772e

Expressions -> Vector!Expression
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Mon, 30 Aug 2010 16:12:19 +0100
parents ef02e2e203c2
children acd69f84627e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypeAArray;
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.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.TypeInfoDeclaration;
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
7 import dmd.TypeInfoAssociativeArrayDeclaration;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Loc;
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
11 import dmd.Global;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.HdrGenState;
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.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.NullExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.backend.TYPE;
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.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.backend.TF;
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
36 import dmd.backend.Classsym;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.backend.mTYman;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import core.stdc.stdio;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import core.stdc.stdlib;
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
41 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
42 import core.memory;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 class TypeAArray : TypeArray
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 Type index; // key type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 this(Type t, Type index)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 super(Taarray, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 this.index = index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
53 override Type syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
55 Type t = next.syntaxCopy();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
56 Type ti = index.syntaxCopy();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
57 if (t == next && ti == index)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
58 t = this;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
59 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
60 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
61 t = new TypeAArray(t, ti);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
62 t.mod = mod;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
63 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
64 return t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 version (DumbClone) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 Type clone()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 assert(false);
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: 68
diff changeset
74 override ulong size(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 return PTRSIZE /* * 2*/;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
79 override Type semantic(Loc loc, Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 //printf("TypeAArray::semantic() %s index.ty = %d\n", toChars(), index.ty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 // Deal with the case where we thought the index was a type, but
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 // in reality it was an expression.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 if (index.ty == Tident || index.ty == Tinstance || index.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 index.resolve(loc, sc, &e, &t, &s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 { // It was an expression -
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 // Rewrite as a static array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 TypeSArray tsa = new TypeSArray(next, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 return tsa.semantic(loc,sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 else if (t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 index = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 index.error(loc, "index is not a type or an expression");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 index = index.semantic(loc,sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 if (index.nextOf() && !index.nextOf().isInvariant())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 index = index.constOf().mutableOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 printf("index is %p %s\n", index, index.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 index.check();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 printf("index.mod = x%x\n", index.mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 printf("index.ito = x%x\n", index.ito);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 if (index.ito) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 printf("index.ito.mod = x%x\n", index.ito.mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 printf("index.ito.ito = x%x\n", index.ito.ito);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 switch (index.toBasetype().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 case Tbool:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 case Tfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 case Tvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 case Tnone:
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
127 case Ttuple:
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 error(loc, "can't have associative array key of %s", index.toBasetype().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 next = next.semantic(loc,sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 transitive();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 switch (next.toBasetype().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 case Tfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 case Tnone:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 error(loc, "can't have associative array of %s", next.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 if (next.isauto())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 error(loc, "cannot have array of auto %s", next.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 return merge();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
151 override void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
153 //printf("TypeAArray.resolve() %s\n", toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
154
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
155 // Deal with the case where we thought the index was a type, but
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
156 // in reality it was an expression.
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
157 if (index.ty == Tident || index.ty == Tinstance || index.ty == Tsarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
158 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
159 Expression e;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
160 Type t;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
161 Dsymbol s;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
162
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
163 index.resolve(loc, sc, &e, &t, &s);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
164 if (e)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
165 { // It was an expression -
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
166 // Rewrite as a static array
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
167
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
168 TypeSArray tsa = new TypeSArray(next, e);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
169 return tsa.resolve(loc, sc, pe, pt, ps);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
170 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
171 else if (t)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
172 index = t;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
173 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
174 index.error(loc, "index is not a type or an expression");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
175 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
176 Type.resolve(loc, sc, pe, pt, ps);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
179 override void toDecoBuffer(OutBuffer buf, int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 Type.toDecoBuffer(buf, flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 index.toDecoBuffer(buf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 next.toDecoBuffer(buf, (flag & 0x100) ? MOD.MODundefined : mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
186 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 {
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
188 if (mod != this.mod)
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
189 {
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
190 toCBuffer3(buf, hgs, mod);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
191 return;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
192 }
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
193 next.toCBuffer2(buf, hgs, this.mod);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
194 buf.writeByte('[');
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
195 index.toCBuffer2(buf, hgs, MODundefined);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
196 buf.writeByte(']');
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
199 override Expression dotExp(Scope sc, Expression e, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 version (LOGDOTEXP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 printf("TypeAArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 if (ident == Id.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 fd = FuncDeclaration.genCfunc(Type.tsize_t, Id.aaLen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
213 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 e.type = (cast(TypeFunction)fd.type).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 else if (ident == Id.keys)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 int size = cast(int)index.size(e.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 assert(size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 fd = FuncDeclaration.genCfunc(Type.tindex, Id.aaKeys);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
228 arguments.push(e);
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
229 arguments.push(new IntegerExp(Loc(0), size, Type.tsize_t));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 e.type = index.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 else if (ident == Id.values)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 fd = FuncDeclaration.genCfunc(Type.tindex, Id.aaValues);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
242 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 size_t keysize = cast(size_t)index.size(e.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 keysize = (keysize + PTRSIZE - 1) & ~(PTRSIZE - 1);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
245 arguments.push(new IntegerExp(Loc(0), keysize, Type.tsize_t));
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
246 arguments.push(new IntegerExp(Loc(0), next.size(e.loc), Type.tsize_t));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 else if (ident == Id.rehash)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 fd = FuncDeclaration.genCfunc(Type.tint64, Id.aaRehash);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
259 arguments.push(e.addressOf(sc));
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
260 arguments.push(index.getInternalTypeInfo(sc));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 e.type = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 e = Type.dotExp(sc, e, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
271 override Expression defaultInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 version (LOGDEFAULTINIT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 printf("TypeAArray.defaultInit() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 Expression e = new NullExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 e.type = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
281 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
283 static if (false) {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
284 printf("TypeAArray.deduceType()\n");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
285 printf("\tthis = %d, ", ty); print();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
286 printf("\ttparam = %d, ", tparam.ty); tparam.print();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
287 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
288
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
289 // Extra check that index type must match
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
290 if (tparam && tparam.ty == Taarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
291 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
292 TypeAArray tp = cast(TypeAArray)tparam;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
293 if (!index.deduceType(sc, tp.index, parameters, dedtypes))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
294 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
295 return MATCHnomatch;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
296 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
297 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
298 return Type.deduceType(sc, tparam, parameters, dedtypes);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
301 override bool isZeroInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
306 override bool checkBoolean()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
311 override TypeInfoDeclaration getTypeInfoDeclaration()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 {
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
313 return new TypeInfoAssociativeArrayDeclaration(this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
316 override bool hasPointers()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
321 override MATCH implicitConvTo(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
323 //printf("TypeAArray.implicitConvTo(to = %s) this = %s\n", to.toChars(), toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
324 if (equals(to))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
325 return MATCHexact;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
326
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
327 if (to.ty == Taarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
328 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
329 TypeAArray ta = cast(TypeAArray)to;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
330
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
331 if (!(next.mod == ta.next.mod || ta.next.mod == MODconst))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
332 return MATCHnomatch; // not const-compatible
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
333
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
334 if (!(index.mod == ta.index.mod || ta.index.mod == MODconst))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
335 return MATCHnomatch; // not const-compatible
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
336
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
337 MATCH m = next.constConv(ta.next);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
338 MATCH mi = index.constConv(ta.index);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
339 if (m != MATCHnomatch && mi != MATCHnomatch)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
340 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
341 if (m == MATCHexact && mod != to.mod)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
342 m = MATCHconst;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
343 if (mi < m)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
344 m = mi;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
345 return m;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
346 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
347 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
348 return Type.implicitConvTo(to);
0
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: 68
diff changeset
351 override MATCH constConv(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 version (CPP_MANGLE) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 void toCppMangle(OutBuffer buf, CppMangleState* cms)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 // Back end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 /********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 * Determine the right symbol to look up
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 * an associative array element.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 * flags 0 don't add value signature
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 * 1 add value signature
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 Symbol* aaGetSymbol(const(char)* func, int flags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 assert(func);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 assert((flags & ~1) == 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 out (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 assert(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 body
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 int sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 char* id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 type* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 // Dumb linear symbol table - should use associative array!
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 static Array sarray = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 //printf("aaGetSymbol(func = '%s', flags = %d, key = %p)\n", func, flags, key);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 scope OutBuffer buf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 key.toKeyBuffer(buf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 sz = next.size(); // it's just data, so we only care about the size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 sz = (sz + 3) & ~3; // reduce proliferation of library routines
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
399 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
400 id = cast(char*)GC.malloc(3 + strlen(func) + buf.offset + sizeof(sz) * 3 + 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
401 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 id = cast(char*)alloca(3 + strlen(func) + buf.offset + sizeof(sz) * 3 + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 buf.writeByte(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 if (flags & 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 sprintf(id, "_aa%s%s%d", func, buf.data, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 sprintf(id, "_aa%s%s", func, buf.data);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 } else {
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
409 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
410 id = cast(char*)GC.malloc(3 + strlen(func) + 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
411 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 id = cast(char*)alloca(3 + strlen(func) + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 sprintf(id, "_aa%s", func);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 if (!sarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 sarray = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 // See if symbol is already in sarray
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 for (i = 0; i < sarray.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 s = cast(Symbol*)sarray.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 if (strcmp(id, s.Sident.ptr) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 return s; // use existing Symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 // Create new Symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 s = symbol_calloc(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 s.Sclass = SCextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 s.Ssymnum = -1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 symbol_func(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 t = type_alloc(TYnfunc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 t.Tflags = TFprototype | TFfixed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 t.Tmangle = mTYman_c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 t.Tparamtypes = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 t.Tnext = next.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 t.Tnext.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 s.Stype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 sarray.push(s); // remember it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
447 override type* toCtype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 {
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
449 type* t;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
450
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
451 if (ctype)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
452 return ctype;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
453
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
454 if (0 && global.params.symdebug)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
455 {
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
456 /* An associative array is represented by:
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
457 * struct AArray { size_t length; void* ptr; }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
458 */
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
459
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
460 static Symbol* s;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
461
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
462 if (!s)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
463 {
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
464 s = symbol_calloc("_AArray");
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
465 s.Sclass = SCstruct;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
466 s.Sstruct = struct_calloc();
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
467 s.Sstruct.Sflags |= 0;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
468 s.Sstruct.Salignsize = alignsize();
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
469 s.Sstruct.Sstructalign = cast(ubyte)global.structalign;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
470 s.Sstruct.Sstructsize = cast(uint)size(Loc(0));
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
471 slist_add(s);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
472
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
473 Symbol* s1 = symbol_name("length", SCmember, Type.tsize_t.toCtype());
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
474 list_append(&s.Sstruct.Sfldlst, s1);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
475
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
476 Symbol* s2 = symbol_name("data", SCmember, Type.tvoidptr.toCtype());
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
477 s2.Smemoff = cast(uint)Type.tsize_t.size();
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
478 list_append(&s.Sstruct.Sfldlst, s2);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
479 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
480
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
481 t = type_alloc(TYstruct);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
482 t.Ttag = cast(Classsym*)s; // structure tag name
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
483 t.Tcount++;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
484 s.Stype = t;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
485 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
486 else
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
487 {
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
488 if (global.params.symdebug == 1)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
489 {
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
490 /* Generate D symbolic debug info, rather than C
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
491 * Tnext: element type
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
492 * Tkey: key type
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
493 */
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
494 t = type_allocn(TYaarray, next.toCtype());
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
495 t.Tkey = index.toCtype();
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
496 t.Tkey.Tcount++;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
497 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
498 else
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
499 t = type_fake(TYaarray);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
500 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
501 t.Tcount++;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
502 ctype = t;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
503 return t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 }
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
505 }