annotate dmd/TypeAArray.d @ 51:b7d29f613539

StaticAssertStatement.syntaxCopy IfStatement.syntaxCopy CompoundDeclarationStatement.syntaxCopy VoidInitializer.syntaxCopy TypeAArray.syntaxCopy TypeTypeof.syntaxCopy TypeAArray.resolve TypeSArray.deduceType TypeAArray.deduceType TypeAArray.implicitConvTo TemplateDeclaration.leastAsSpecialized TemplateTypeParameter.dummyArg TypeIdentifier.deduceType TemplateTypeParameter.syntaxCopy Lexer.hexStringConstant Lexer.delimitedStringConstant GotoDefaultStatement.ctor CaseRangeStatement.ctor Type.castMod StorageClassDeclaration.syntaxCopy TemplateDeclaration.syntaxCopy
author korDen
date Sat, 21 Aug 2010 11:17:42 +0400
parents 2cc604139636
children f708f0452e81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypeAArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.TypeArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.TypeInfoDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.NullExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.backend.TF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.backend.mTYman;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import core.stdc.stdio;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 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
38 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
39 import core.memory;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 class TypeAArray : TypeArray
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 Type index; // key type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 this(Type t, Type index)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 super(Taarray, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 this.index = index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 Type syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
52 Type t = next.syntaxCopy();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
53 Type ti = index.syntaxCopy();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
54 if (t == next && ti == index)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
55 t = this;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
56 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
57 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
58 t = new TypeAArray(t, ti);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
59 t.mod = mod;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
60 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
61 return t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 version (DumbClone) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 Type clone()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 ulong size(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 return PTRSIZE /* * 2*/;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 Type semantic(Loc loc, Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 //printf("TypeAArray::semantic() %s index.ty = %d\n", toChars(), index.ty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 // Deal with the case where we thought the index was a type, but
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 // in reality it was an expression.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 if (index.ty == Tident || index.ty == Tinstance || index.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 index.resolve(loc, sc, &e, &t, &s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 { // It was an expression -
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 // Rewrite as a static array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 TypeSArray tsa = new TypeSArray(next, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 return tsa.semantic(loc,sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 else if (t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 index = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 index.error(loc, "index is not a type or an expression");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 index = index.semantic(loc,sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 if (index.nextOf() && !index.nextOf().isInvariant())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 index = index.constOf().mutableOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 printf("index is %p %s\n", index, index.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 index.check();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 printf("index.mod = x%x\n", index.mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 printf("index.ito = x%x\n", index.ito);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 if (index.ito) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 printf("index.ito.mod = x%x\n", index.ito.mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 printf("index.ito.ito = x%x\n", index.ito.ito);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 switch (index.toBasetype().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 case Tbool:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 case Tfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 case Tvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 case Tnone:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 error(loc, "can't have associative array key of %s", index.toBasetype().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 next = next.semantic(loc,sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 transitive();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 switch (next.toBasetype().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 case Tfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 case Tnone:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 error(loc, "can't have associative array of %s", next.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 if (next.isauto())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 error(loc, "cannot have array of auto %s", next.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 return merge();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
149 //printf("TypeAArray.resolve() %s\n", toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
150
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
151 // Deal with the case where we thought the index was a type, but
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
152 // in reality it was an expression.
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
153 if (index.ty == Tident || index.ty == Tinstance || index.ty == Tsarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
154 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
155 Expression e;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
156 Type t;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
157 Dsymbol s;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
158
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
159 index.resolve(loc, sc, &e, &t, &s);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
160 if (e)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
161 { // It was an expression -
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
162 // Rewrite as a static array
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
163
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
164 TypeSArray tsa = new TypeSArray(next, e);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
165 return tsa.resolve(loc, sc, pe, pt, ps);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
166 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
167 else if (t)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
168 index = t;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
169 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
170 index.error(loc, "index is not a type or an expression");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
171 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
172 Type.resolve(loc, sc, pe, pt, ps);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 void toDecoBuffer(OutBuffer buf, int flag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 Type.toDecoBuffer(buf, flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 index.toDecoBuffer(buf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 next.toDecoBuffer(buf, (flag & 0x100) ? MOD.MODundefined : mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 Expression dotExp(Scope sc, Expression e, Identifier ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 version (LOGDOTEXP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 printf("TypeAArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 if (ident == Id.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 fd = FuncDeclaration.genCfunc(Type.tsize_t, Id.aaLen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 arguments.push(cast(void*)e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 e.type = (cast(TypeFunction)fd.type).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 else if (ident == Id.keys)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 int size = cast(int)index.size(e.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 assert(size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 fd = FuncDeclaration.genCfunc(Type.tindex, Id.aaKeys);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 arguments.push(cast(void*)e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 arguments.push(cast(void*)new IntegerExp(Loc(0), size, Type.tsize_t));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 e.type = index.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 else if (ident == Id.values)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 fd = FuncDeclaration.genCfunc(Type.tindex, Id.aaValues);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 arguments.push(cast(void*)e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 size_t keysize = cast(size_t)index.size(e.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 keysize = (keysize + PTRSIZE - 1) & ~(PTRSIZE - 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 arguments.push(cast(void*)new IntegerExp(Loc(0), keysize, Type.tsize_t));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 arguments.push(cast(void*)new IntegerExp(Loc(0), next.size(e.loc), Type.tsize_t));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 else if (ident == Id.rehash)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 fd = FuncDeclaration.genCfunc(Type.tint64, Id.aaRehash);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 arguments.push(cast(void*)e.addressOf(sc));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 arguments.push(cast(void*)index.getInternalTypeInfo(sc));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 e.type = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 e = Type.dotExp(sc, e, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 Expression defaultInit(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 version (LOGDEFAULTINIT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 printf("TypeAArray.defaultInit() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 Expression e = new NullExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 e.type = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
271 static if (false) {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
272 printf("TypeAArray.deduceType()\n");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
273 printf("\tthis = %d, ", ty); print();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
274 printf("\ttparam = %d, ", tparam.ty); tparam.print();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
275 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
276
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
277 // Extra check that index type must match
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
278 if (tparam && tparam.ty == Taarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
279 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
280 TypeAArray tp = cast(TypeAArray)tparam;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
281 if (!index.deduceType(sc, tp.index, parameters, dedtypes))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
282 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
283 return MATCHnomatch;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
284 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
285 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
286 return Type.deduceType(sc, tparam, parameters, dedtypes);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 bool isZeroInit(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 bool checkBoolean()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 TypeInfoDeclaration getTypeInfoDeclaration()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 bool hasPointers()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 MATCH implicitConvTo(Type to)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
311 //printf("TypeAArray.implicitConvTo(to = %s) this = %s\n", to.toChars(), toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
312 if (equals(to))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
313 return MATCHexact;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
314
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
315 if (to.ty == Taarray)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
316 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
317 TypeAArray ta = cast(TypeAArray)to;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
318
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
319 if (!(next.mod == ta.next.mod || ta.next.mod == MODconst))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
320 return MATCHnomatch; // not const-compatible
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
321
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
322 if (!(index.mod == ta.index.mod || ta.index.mod == MODconst))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
323 return MATCHnomatch; // not const-compatible
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
324
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
325 MATCH m = next.constConv(ta.next);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
326 MATCH mi = index.constConv(ta.index);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
327 if (m != MATCHnomatch && mi != MATCHnomatch)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
328 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
329 if (m == MATCHexact && mod != to.mod)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
330 m = MATCHconst;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
331 if (mi < m)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
332 m = mi;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
333 return m;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
334 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
335 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 14
diff changeset
336 return Type.implicitConvTo(to);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 MATCH constConv(Type to)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 version (CPP_MANGLE) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 void toCppMangle(OutBuffer buf, CppMangleState* cms)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 // Back end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 /********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 * Determine the right symbol to look up
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 * an associative array element.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 * flags 0 don't add value signature
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 * 1 add value signature
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 Symbol* aaGetSymbol(const(char)* func, int flags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 assert(func);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 assert((flags & ~1) == 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 out (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 assert(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 body
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 int sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 char* id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 type* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 // Dumb linear symbol table - should use associative array!
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 static Array sarray = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 //printf("aaGetSymbol(func = '%s', flags = %d, key = %p)\n", func, flags, key);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 scope OutBuffer buf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 key.toKeyBuffer(buf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 sz = next.size(); // it's just data, so we only care about the size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 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
387 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
388 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
389 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 id = cast(char*)alloca(3 + strlen(func) + buf.offset + sizeof(sz) * 3 + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 buf.writeByte(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 if (flags & 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 sprintf(id, "_aa%s%s%d", func, buf.data, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 sprintf(id, "_aa%s%s", func, buf.data);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 } 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
397 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
398 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
399 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 id = cast(char*)alloca(3 + strlen(func) + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 sprintf(id, "_aa%s", func);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 if (!sarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 sarray = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 // See if symbol is already in sarray
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 for (i = 0; i < sarray.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 s = cast(Symbol*)sarray.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 if (strcmp(id, s.Sident.ptr) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 return s; // use existing Symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 // Create new Symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 s = symbol_calloc(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 s.Sclass = SCextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 s.Ssymnum = -1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 symbol_func(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 t = type_alloc(TYnfunc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 t.Tflags = TFprototype | TFfixed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 t.Tmangle = mTYman_c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 t.Tparamtypes = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 t.Tnext = next.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 t.Tnext.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 s.Stype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 sarray.push(s); // remember it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 type* toCtype()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 }
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
439 }