annotate dmd/TypeAArray.d @ 111:2f57c5ecd3b2

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