annotate dmd/TypeAArray.d @ 187:b0d41ff5e0df

Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author Abscissa
date Tue, 07 Jun 2011 23:37:34 -0400
parents cd48cb899aee
children
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;
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
13 import dmd.DotTemplateInstanceExp;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
14 import dmd.IdentifierExp;
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
15 import dmd.Global;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.TY;
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
24 import dmd.TemplateInstance;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.NullExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.backend.TF;
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
41 import dmd.backend.Classsym;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.backend.mTYman;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
44 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
45
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import core.stdc.stdio;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 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
48 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
49 import core.memory;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 class TypeAArray : TypeArray
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
52 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
53
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
54 Type index; // key type
acd69f84627e further work
Trass3r
parents: 84
diff changeset
55 Loc loc;
acd69f84627e further work
Trass3r
parents: 84
diff changeset
56 Scope sc;
acd69f84627e further work
Trass3r
parents: 84
diff changeset
57 StructDeclaration impl; // implementation
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 this(Type t, Type index)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
61 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 super(Taarray, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 this.index = index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
66 override Type syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
68 Type t = next.syntaxCopy();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
69 Type ti = index.syntaxCopy();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
70 if (t == next && ti == index)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
71 t = this;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
72 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
73 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
74 t = new TypeAArray(t, ti);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
75 t.mod = mod;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
76 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
77 return t;
0
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
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
119 if (index.nextOf() && !index.nextOf().isImmutable())
0
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 Objects tiargs = new Objects();
111
2f57c5ecd3b2 tiny fix
Trass3r
parents: 103
diff changeset
179 tiargs.push(index);
2f57c5ecd3b2 tiny fix
Trass3r
parents: 103
diff changeset
180 tiargs.push(next);
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
181
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
182 // Create .AssociativeArray!(index, next)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
183 DotTemplateInstanceExp dti = new DotTemplateInstanceExp(loc,
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
184 new IdentifierExp(loc, Id.empty),
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
185 Id.AssociativeArray,
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
186 tiargs);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
187 dti.semantic(sc);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
188 TemplateInstance ti = dti.ti;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
189
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
190 ti.semantic(sc);
acd69f84627e further work
Trass3r
parents: 84
diff changeset
191 ti.semantic2(sc);
acd69f84627e further work
Trass3r
parents: 84
diff changeset
192 ti.semantic3(sc);
acd69f84627e further work
Trass3r
parents: 84
diff changeset
193 impl = ti.toAlias().isStructDeclaration();
acd69f84627e further work
Trass3r
parents: 84
diff changeset
194 debug
acd69f84627e further work
Trass3r
parents: 84
diff changeset
195 {
acd69f84627e further work
Trass3r
parents: 84
diff changeset
196 if (!impl)
acd69f84627e further work
Trass3r
parents: 84
diff changeset
197 {
acd69f84627e further work
Trass3r
parents: 84
diff changeset
198 Dsymbol s = ti.toAlias();
acd69f84627e further work
Trass3r
parents: 84
diff changeset
199 writef("%s %s\n", s.kind(), s.toChars());
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 assert(impl);
acd69f84627e further work
Trass3r
parents: 84
diff changeset
203 }
acd69f84627e further work
Trass3r
parents: 84
diff changeset
204 }
acd69f84627e further work
Trass3r
parents: 84
diff changeset
205 return impl;
acd69f84627e further work
Trass3r
parents: 84
diff changeset
206
acd69f84627e further work
Trass3r
parents: 84
diff changeset
207 }
acd69f84627e further work
Trass3r
parents: 84
diff changeset
208
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
209 override void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
211 //printf("TypeAArray.resolve() %s\n", toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
212
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
213 // Deal with the case where we thought the index was a type, but
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
214 // in reality it was an expression.
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
215 if (index.ty == Tident || index.ty == Tinstance || index.ty == Tsarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
216 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
217 Expression e;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
218 Type t;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
219 Dsymbol s;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
220
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
221 index.resolve(loc, sc, &e, &t, &s);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
222 if (e)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
223 { // It was an expression -
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
224 // Rewrite as a static array
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
225
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
226 TypeSArray tsa = new TypeSArray(next, e);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
227 return tsa.resolve(loc, sc, pe, pt, ps);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
228 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
229 else if (t)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
230 index = t;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
231 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
232 index.error(loc, "index is not a type or an expression");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
233 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
234 Type.resolve(loc, sc, pe, pt, ps);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
237 override void toDecoBuffer(OutBuffer buf, int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 Type.toDecoBuffer(buf, flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 index.toDecoBuffer(buf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 next.toDecoBuffer(buf, (flag & 0x100) ? MOD.MODundefined : mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
244 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 {
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
246 if (mod != this.mod)
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
247 {
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
248 toCBuffer3(buf, hgs, mod);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
249 return;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
250 }
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
251 next.toCBuffer2(buf, hgs, this.mod);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
252 buf.writeByte('[');
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
253 index.toCBuffer2(buf, hgs, MODundefined);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
254 buf.writeByte(']');
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
257 override Expression dotExp(Scope sc, Expression e, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 version (LOGDOTEXP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 printf("TypeAArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 }
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
262 static if (false)
acd69f84627e further work
Trass3r
parents: 84
diff changeset
263 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 if (ident == Id.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 fd = FuncDeclaration.genCfunc(Type.tsize_t, Id.aaLen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
273 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 e.type = (cast(TypeFunction)fd.type).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 else if (ident == Id.keys)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 int size = cast(int)index.size(e.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 assert(size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 fd = FuncDeclaration.genCfunc(Type.tindex, Id.aaKeys);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
288 arguments.push(e);
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
289 arguments.push(new IntegerExp(Loc(0), size, Type.tsize_t));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 e.type = index.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 else if (ident == Id.values)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 fd = FuncDeclaration.genCfunc(Type.tindex, Id.aaValues);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
302 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 size_t keysize = cast(size_t)index.size(e.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 keysize = (keysize + PTRSIZE - 1) & ~(PTRSIZE - 1);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
305 arguments.push(new IntegerExp(Loc(0), keysize, Type.tsize_t));
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
306 arguments.push(new IntegerExp(Loc(0), next.size(e.loc), Type.tsize_t));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 else if (ident == Id.rehash)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 fd = FuncDeclaration.genCfunc(Type.tint64, Id.aaRehash);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
319 arguments.push(e.addressOf(sc));
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
320 arguments.push(index.getInternalTypeInfo(sc));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 e.type = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 }
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
324 // else
acd69f84627e further work
Trass3r
parents: 84
diff changeset
325 } // of static if (false)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 {
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
327 e.type = getImpl().type;
acd69f84627e further work
Trass3r
parents: 84
diff changeset
328 e = e.type.dotExp(sc, e, ident);
acd69f84627e further work
Trass3r
parents: 84
diff changeset
329 //e = Type.dotExp(sc, e, ident);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
334 override Expression defaultInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 version (LOGDEFAULTINIT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 printf("TypeAArray.defaultInit() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 }
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
339 return new NullExp(loc, this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
342 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
344 static if (false) {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
345 printf("TypeAArray.deduceType()\n");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
346 printf("\tthis = %d, ", ty); print();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
347 printf("\ttparam = %d, ", tparam.ty); tparam.print();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
348 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
349
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
350 // Extra check that index type must match
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
351 if (tparam && tparam.ty == Taarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
352 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
353 TypeAArray tp = cast(TypeAArray)tparam;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
354 if (!index.deduceType(sc, tp.index, parameters, dedtypes))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
355 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
356 return MATCHnomatch;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
357 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
358 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
359 return Type.deduceType(sc, tparam, parameters, dedtypes);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
362 override bool isZeroInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
364 return true;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
367 override bool checkBoolean()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
369 return true;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
372 override TypeInfoDeclaration getTypeInfoDeclaration()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 {
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
374 return new TypeInfoAssociativeArrayDeclaration(this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
377 override bool hasPointers()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
382 override MATCH implicitConvTo(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
384 //printf("TypeAArray.implicitConvTo(to = %s) this = %s\n", to.toChars(), toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
385 if (equals(to))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
386 return MATCHexact;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
387
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
388 if (to.ty == Taarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
389 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
390 TypeAArray ta = cast(TypeAArray)to;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
391
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
392 if (!MODimplicitConv(next.mod, ta.next.mod))
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
393 return MATCHnomatch; // not const-compatible
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
394
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
395 if (!MODimplicitConv(index.mod, ta.index.mod))
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
396 return MATCHnomatch; // not const-compatible
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
397
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
398 MATCH m = next.constConv(ta.next);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
399 MATCH mi = index.constConv(ta.index);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
400 if (m != MATCHnomatch && mi != MATCHnomatch)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
401 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
402 if (m == MATCHexact && mod != to.mod)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
403 m = MATCHconst;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
404 if (mi < m)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
405 m = mi;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
406 return m;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
407 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
408 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
409 return Type.implicitConvTo(to);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
412 override MATCH constConv(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 version (CPP_MANGLE) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 void toCppMangle(OutBuffer buf, CppMangleState* cms)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 // Back end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 /********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 * Determine the right symbol to look up
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 * an associative array element.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 * flags 0 don't add value signature
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 * 1 add value signature
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 Symbol* aaGetSymbol(const(char)* func, int flags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 assert(func);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 assert((flags & ~1) == 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 out (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 assert(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 body
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 int sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 char* id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 type* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 //printf("aaGetSymbol(func = '%s', flags = %d, key = %p)\n", func, flags, key);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 scope OutBuffer buf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 key.toKeyBuffer(buf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 sz = next.size(); // it's just data, so we only care about the size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 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
457 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
458 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
459 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 id = cast(char*)alloca(3 + strlen(func) + buf.offset + sizeof(sz) * 3 + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 buf.writeByte(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 if (flags & 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 sprintf(id, "_aa%s%s%d", func, buf.data, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 sprintf(id, "_aa%s%s", func, buf.data);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 } 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
467 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
468 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
469 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 id = cast(char*)alloca(3 + strlen(func) + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 sprintf(id, "_aa%s", func);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 // See if symbol is already in sarray
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
475 for (i = 0; i < global.sarray.dim; i++)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 {
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
477 s = cast(Symbol*)global.sarray.data[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 if (strcmp(id, s.Sident.ptr) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 return s; // use existing Symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 // Create new Symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 s = symbol_calloc(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 s.Sclass = SCextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 s.Ssymnum = -1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 symbol_func(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 t = type_alloc(TYnfunc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 t.Tflags = TFprototype | TFfixed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 t.Tmangle = mTYman_c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 t.Tparamtypes = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 t.Tnext = next.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 t.Tnext.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 s.Stype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
499 global.sarray.push(s); // remember it
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
503 override type* toCtype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 {
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
505 type* t;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
506
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
507 if (ctype)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
508 return ctype;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
509
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
510 if (0 && global.params.symdebug)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
511 {
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
512 /* An associative array is represented by:
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
513 * struct AArray { size_t length; void* ptr; }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
514 */
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
515
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
516 auto s = global.AArray_s;
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
517 if (!s)
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 global.AArray_s = s = symbol_calloc("_AArray");
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
520 s.Sclass = SCstruct;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
521 s.Sstruct = struct_calloc();
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
522 s.Sstruct.Sflags |= 0;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
523 s.Sstruct.Salignsize = alignsize();
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
524 s.Sstruct.Sstructalign = cast(ubyte)global.structalign;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
525 s.Sstruct.Sstructsize = cast(uint)size(Loc(0));
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
526 slist_add(s);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
527
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
528 Symbol* s1 = symbol_name("length", SCmember, Type.tsize_t.toCtype());
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
529 list_append(&s.Sstruct.Sfldlst, s1);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
530
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
531 Symbol* s2 = symbol_name("data", SCmember, global.tvoidptr.toCtype());
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
532 s2.Smemoff = cast(uint)Type.tsize_t.size();
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
533 list_append(&s.Sstruct.Sfldlst, s2);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
534 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
535
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
536 t = type_alloc(TYstruct);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
537 t.Ttag = cast(Classsym*)s; // structure tag name
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
538 t.Tcount++;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
539 s.Stype = t;
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 {
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
543 if (global.params.symdebug == 1)
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 /* Generate D symbolic debug info, rather than C
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
546 * Tnext: element type
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
547 * Tkey: key type
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
548 */
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
549 t = type_allocn(TYaarray, next.toCtype());
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
550 t.Tkey = index.toCtype();
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
551 t.Tkey.Tcount++;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
552 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
553 else
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
554 t = type_fake(TYaarray);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
555 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
556 t.Tcount++;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
557 ctype = t;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
558 return t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 }
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
560 }