annotate dmd/TypeAArray.d @ 182:b64060ab22df

Now compileable with dmd2.050
author korDen
date Sat, 30 Oct 2010 05:05:32 +0400
parents cd48cb899aee
children b0d41ff5e0df
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import core.stdc.stdio;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 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
46 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
47 import core.memory;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 class TypeAArray : TypeArray
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
50 Type index; // key type
acd69f84627e further work
Trass3r
parents: 84
diff changeset
51 Loc loc;
acd69f84627e further work
Trass3r
parents: 84
diff changeset
52 Scope sc;
acd69f84627e further work
Trass3r
parents: 84
diff changeset
53 StructDeclaration impl; // implementation
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 this(Type t, Type index)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
57 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 super(Taarray, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 this.index = index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
62 override Type syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
64 Type t = next.syntaxCopy();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
65 Type ti = index.syntaxCopy();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
66 if (t == next && ti == index)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
67 t = this;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
68 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
69 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
70 t = new TypeAArray(t, ti);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
71 t.mod = mod;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
72 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
73 return t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
76 override ulong size(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 return PTRSIZE /* * 2*/;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
81 override Type semantic(Loc loc, Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 //printf("TypeAArray::semantic() %s index.ty = %d\n", toChars(), index.ty);
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
84 this.loc = loc;
acd69f84627e further work
Trass3r
parents: 84
diff changeset
85 this.sc = sc;
acd69f84627e further work
Trass3r
parents: 84
diff changeset
86 if (sc)
acd69f84627e further work
Trass3r
parents: 84
diff changeset
87 sc.setNoFree();
acd69f84627e further work
Trass3r
parents: 84
diff changeset
88
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 // Deal with the case where we thought the index was a type, but
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 // in reality it was an expression.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 if (index.ty == Tident || index.ty == Tinstance || index.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 index.resolve(loc, sc, &e, &t, &s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 { // It was an expression -
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 // Rewrite as a static array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 TypeSArray tsa = new TypeSArray(next, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 return tsa.semantic(loc,sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 else if (t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 index = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 else
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
107 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 index.error(loc, "index is not a type or an expression");
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
109 return Type.terror;
acd69f84627e further work
Trass3r
parents: 84
diff changeset
110 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 index = index.semantic(loc,sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
115 if (index.nextOf() && !index.nextOf().isImmutable())
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 index = index.constOf().mutableOf();
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
118 static if (false)
acd69f84627e further work
Trass3r
parents: 84
diff changeset
119 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 printf("index is %p %s\n", index, index.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 index.check();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 printf("index.mod = x%x\n", index.mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 printf("index.ito = x%x\n", index.ito);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 if (index.ito) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 printf("index.ito.mod = x%x\n", index.ito.mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 printf("index.ito.ito = x%x\n", index.ito.ito);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 switch (index.toBasetype().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 case Tbool:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 case Tfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 case Tvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 case Tnone:
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
137 case Ttuple:
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 error(loc, "can't have associative array key of %s", index.toBasetype().toChars());
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
139 return Type.terror;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 next = next.semantic(loc,sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 transitive();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 switch (next.toBasetype().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 case Tfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 case Tnone:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 error(loc, "can't have associative array of %s", next.toChars());
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
151 return Type.terror;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 if (next.isauto())
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
156 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 error(loc, "cannot have array of auto %s", next.toChars());
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
158 return Type.terror;
acd69f84627e further work
Trass3r
parents: 84
diff changeset
159 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 return merge();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
163 StructDeclaration getImpl()
acd69f84627e further work
Trass3r
parents: 84
diff changeset
164 {
acd69f84627e further work
Trass3r
parents: 84
diff changeset
165 // Do it lazily
acd69f84627e further work
Trass3r
parents: 84
diff changeset
166 if (!impl)
acd69f84627e further work
Trass3r
parents: 84
diff changeset
167 {
acd69f84627e further work
Trass3r
parents: 84
diff changeset
168 if (!index.reliesOnTident() && !next.reliesOnTident())
acd69f84627e further work
Trass3r
parents: 84
diff changeset
169 {
acd69f84627e further work
Trass3r
parents: 84
diff changeset
170 /* This is really a proxy for the template instance AssocArray!(index, next)
acd69f84627e further work
Trass3r
parents: 84
diff changeset
171 * But the instantiation can fail if it is a template specialization field
acd69f84627e further work
Trass3r
parents: 84
diff changeset
172 * which has Tident's instead of real types.
acd69f84627e further work
Trass3r
parents: 84
diff changeset
173 */
acd69f84627e further work
Trass3r
parents: 84
diff changeset
174 Objects tiargs = new Objects();
111
2f57c5ecd3b2 tiny fix
Trass3r
parents: 103
diff changeset
175 tiargs.push(index);
2f57c5ecd3b2 tiny fix
Trass3r
parents: 103
diff changeset
176 tiargs.push(next);
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
177
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
178 // Create .AssociativeArray!(index, next)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
179 DotTemplateInstanceExp dti = new DotTemplateInstanceExp(loc,
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
180 new IdentifierExp(loc, Id.empty),
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
181 Id.AssociativeArray,
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
182 tiargs);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
183 dti.semantic(sc);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
184 TemplateInstance ti = dti.ti;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
185
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
186 ti.semantic(sc);
acd69f84627e further work
Trass3r
parents: 84
diff changeset
187 ti.semantic2(sc);
acd69f84627e further work
Trass3r
parents: 84
diff changeset
188 ti.semantic3(sc);
acd69f84627e further work
Trass3r
parents: 84
diff changeset
189 impl = ti.toAlias().isStructDeclaration();
acd69f84627e further work
Trass3r
parents: 84
diff changeset
190 debug
acd69f84627e further work
Trass3r
parents: 84
diff changeset
191 {
acd69f84627e further work
Trass3r
parents: 84
diff changeset
192 if (!impl)
acd69f84627e further work
Trass3r
parents: 84
diff changeset
193 {
acd69f84627e further work
Trass3r
parents: 84
diff changeset
194 Dsymbol s = ti.toAlias();
acd69f84627e further work
Trass3r
parents: 84
diff changeset
195 writef("%s %s\n", s.kind(), s.toChars());
acd69f84627e further work
Trass3r
parents: 84
diff changeset
196 }
acd69f84627e further work
Trass3r
parents: 84
diff changeset
197 }
acd69f84627e further work
Trass3r
parents: 84
diff changeset
198 assert(impl);
acd69f84627e further work
Trass3r
parents: 84
diff changeset
199 }
acd69f84627e further work
Trass3r
parents: 84
diff changeset
200 }
acd69f84627e further work
Trass3r
parents: 84
diff changeset
201 return impl;
acd69f84627e further work
Trass3r
parents: 84
diff changeset
202
acd69f84627e further work
Trass3r
parents: 84
diff changeset
203 }
acd69f84627e further work
Trass3r
parents: 84
diff changeset
204
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
205 override void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
207 //printf("TypeAArray.resolve() %s\n", toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
208
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
209 // Deal with the case where we thought the index was a type, but
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
210 // in reality it was an expression.
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
211 if (index.ty == Tident || index.ty == Tinstance || index.ty == Tsarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
212 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
213 Expression e;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
214 Type t;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
215 Dsymbol s;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
216
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
217 index.resolve(loc, sc, &e, &t, &s);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
218 if (e)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
219 { // It was an expression -
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
220 // Rewrite as a static array
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
221
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
222 TypeSArray tsa = new TypeSArray(next, e);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
223 return tsa.resolve(loc, sc, pe, pt, ps);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
224 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
225 else if (t)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
226 index = t;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
227 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
228 index.error(loc, "index is not a type or an expression");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
229 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
230 Type.resolve(loc, sc, pe, pt, ps);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
233 override void toDecoBuffer(OutBuffer buf, int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 Type.toDecoBuffer(buf, flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 index.toDecoBuffer(buf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 next.toDecoBuffer(buf, (flag & 0x100) ? MOD.MODundefined : mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
240 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 {
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
242 if (mod != this.mod)
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
243 {
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
244 toCBuffer3(buf, hgs, mod);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
245 return;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
246 }
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
247 next.toCBuffer2(buf, hgs, this.mod);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
248 buf.writeByte('[');
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
249 index.toCBuffer2(buf, hgs, MODundefined);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 67
diff changeset
250 buf.writeByte(']');
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
253 override Expression dotExp(Scope sc, Expression e, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 version (LOGDOTEXP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 printf("TypeAArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 }
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
258 static if (false)
acd69f84627e further work
Trass3r
parents: 84
diff changeset
259 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 if (ident == Id.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 fd = FuncDeclaration.genCfunc(Type.tsize_t, Id.aaLen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
269 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 e.type = (cast(TypeFunction)fd.type).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 else if (ident == Id.keys)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 int size = cast(int)index.size(e.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 assert(size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 fd = FuncDeclaration.genCfunc(Type.tindex, Id.aaKeys);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
284 arguments.push(e);
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
285 arguments.push(new IntegerExp(Loc(0), size, Type.tsize_t));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 e.type = index.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 else if (ident == Id.values)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 fd = FuncDeclaration.genCfunc(Type.tindex, Id.aaValues);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
298 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 size_t keysize = cast(size_t)index.size(e.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 keysize = (keysize + PTRSIZE - 1) & ~(PTRSIZE - 1);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
301 arguments.push(new IntegerExp(Loc(0), keysize, Type.tsize_t));
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
302 arguments.push(new IntegerExp(Loc(0), next.size(e.loc), Type.tsize_t));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 else if (ident == Id.rehash)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 fd = FuncDeclaration.genCfunc(Type.tint64, Id.aaRehash);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
315 arguments.push(e.addressOf(sc));
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
316 arguments.push(index.getInternalTypeInfo(sc));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 e.type = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 }
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
320 // else
acd69f84627e further work
Trass3r
parents: 84
diff changeset
321 } // of static if (false)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 {
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
323 e.type = getImpl().type;
acd69f84627e further work
Trass3r
parents: 84
diff changeset
324 e = e.type.dotExp(sc, e, ident);
acd69f84627e further work
Trass3r
parents: 84
diff changeset
325 //e = Type.dotExp(sc, e, ident);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
330 override Expression defaultInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 version (LOGDEFAULTINIT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 printf("TypeAArray.defaultInit() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 }
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
335 return new NullExp(loc, this);
0
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 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
360 return true;
0
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 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
365 return true;
0
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
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
388 if (!MODimplicitConv(next.mod, ta.next.mod))
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
389 return MATCHnomatch; // not const-compatible
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
390
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
391 if (!MODimplicitConv(index.mod, ta.index.mod))
51
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 //printf("aaGetSymbol(func = '%s', flags = %d, key = %p)\n", func, flags, key);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 scope OutBuffer buf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 key.toKeyBuffer(buf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 sz = next.size(); // it's just data, so we only care about the size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 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
453 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
454 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
455 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 id = cast(char*)alloca(3 + strlen(func) + buf.offset + sizeof(sz) * 3 + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 buf.writeByte(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 if (flags & 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 sprintf(id, "_aa%s%s%d", func, buf.data, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 sprintf(id, "_aa%s%s", func, buf.data);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 } 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
463 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
464 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
465 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 id = cast(char*)alloca(3 + strlen(func) + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 sprintf(id, "_aa%s", func);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 // See if symbol is already in sarray
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
471 for (i = 0; i < global.sarray.dim; i++)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 {
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
473 s = cast(Symbol*)global.sarray.data[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 if (strcmp(id, s.Sident.ptr) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 return s; // use existing Symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 // Create new Symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 s = symbol_calloc(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 s.Sclass = SCextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 s.Ssymnum = -1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 symbol_func(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 t = type_alloc(TYnfunc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 t.Tflags = TFprototype | TFfixed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 t.Tmangle = mTYman_c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 t.Tparamtypes = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 t.Tnext = next.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 t.Tnext.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 s.Stype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
495 global.sarray.push(s); // remember it
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
499 override type* toCtype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 {
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
501 type* t;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
502
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
503 if (ctype)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
504 return ctype;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
505
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
506 if (0 && global.params.symdebug)
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 /* An associative array is represented by:
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
509 * struct AArray { size_t length; void* ptr; }
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
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
512 auto s = global.AArray_s;
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
513 if (!s)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
514 {
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
515 global.AArray_s = s = symbol_calloc("_AArray");
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
516 s.Sclass = SCstruct;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
517 s.Sstruct = struct_calloc();
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
518 s.Sstruct.Sflags |= 0;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
519 s.Sstruct.Salignsize = alignsize();
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
520 s.Sstruct.Sstructalign = cast(ubyte)global.structalign;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
521 s.Sstruct.Sstructsize = cast(uint)size(Loc(0));
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
522 slist_add(s);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
523
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
524 Symbol* s1 = symbol_name("length", SCmember, Type.tsize_t.toCtype());
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
525 list_append(&s.Sstruct.Sfldlst, s1);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
526
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 174
diff changeset
527 Symbol* s2 = symbol_name("data", SCmember, global.tvoidptr.toCtype());
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
528 s2.Smemoff = cast(uint)Type.tsize_t.size();
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
529 list_append(&s.Sstruct.Sfldlst, s2);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
530 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
531
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
532 t = type_alloc(TYstruct);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
533 t.Ttag = cast(Classsym*)s; // structure tag name
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
534 t.Tcount++;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
535 s.Stype = t;
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 else
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
538 {
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
539 if (global.params.symdebug == 1)
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 /* Generate D symbolic debug info, rather than C
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
542 * Tnext: element type
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
543 * Tkey: key type
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 t = type_allocn(TYaarray, next.toCtype());
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
546 t.Tkey = index.toCtype();
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
547 t.Tkey.Tcount++;
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 else
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
550 t = type_fake(TYaarray);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
551 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
552 t.Tcount++;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
553 ctype = t;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 51
diff changeset
554 return t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 }
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
556 }