annotate dmd/TypeAArray.d @ 114:e28b18c23469

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