annotate dmd/TypeAArray.d @ 178:e3afd1303184

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