Mercurial > projects > ddmd
comparison dmd/AssocArrayLiteralExp.d @ 68:ee3a9f34dc48
final bits of codegen implementation to compile Phobos
author | korDen |
---|---|
date | Tue, 24 Aug 2010 16:44:34 +0400 |
parents | 4290d870944a |
children | 2e2a5c3f943a |
comparison
equal
deleted
inserted
replaced
67:f708f0452e81 | 68:ee3a9f34dc48 |
---|---|
20 import dmd.InlineScanState; | 20 import dmd.InlineScanState; |
21 import dmd.ArrayTypes; | 21 import dmd.ArrayTypes; |
22 import dmd.TOK; | 22 import dmd.TOK; |
23 import dmd.PREC; | 23 import dmd.PREC; |
24 import dmd.expression.Util; | 24 import dmd.expression.Util; |
25 import dmd.backend.Util; | |
26 import dmd.backend.TYM; | |
27 import dmd.backend.mTY; | |
28 import dmd.backend.OPER; | |
29 import dmd.backend.RTLSYM; | |
25 | 30 |
26 class AssocArrayLiteralExp : Expression | 31 class AssocArrayLiteralExp : Expression |
27 { | 32 { |
28 Expressions keys; | 33 Expressions keys; |
29 Expressions values; | 34 Expressions values; |
110 return result ? (dim != 0) : (dim == 0); | 115 return result ? (dim != 0) : (dim == 0); |
111 } | 116 } |
112 | 117 |
113 elem* toElem(IRState* irs) | 118 elem* toElem(IRState* irs) |
114 { | 119 { |
115 assert(false); | 120 elem* e; |
121 size_t dim; | |
122 | |
123 //printf("AssocArrayLiteralExp.toElem() %s\n", toChars()); | |
124 dim = keys.dim; | |
125 e = el_long(TYint, dim); | |
126 for (size_t i = 0; i < dim; i++) | |
127 { | |
128 Expression el = cast(Expression)keys.data[i]; | |
129 | |
130 for (int j = 0; j < 2; j++) | |
131 { | |
132 elem* ep = el.toElem(irs); | |
133 | |
134 if (tybasic(ep.Ety) == TYstruct || tybasic(ep.Ety) == TYarray) | |
135 { | |
136 ep = el_una(OPstrpar, TYstruct, ep); | |
137 ep.Enumbytes = cast(uint)el.type.size(); | |
138 } | |
139 //printf("[%d] %s\n", i, el.toChars()); | |
140 //elem_print(ep); | |
141 e = el_param(ep, e); | |
142 el = cast(Expression)values.data[i]; | |
143 } | |
144 } | |
145 | |
146 Type t = type.toBasetype().mutableOf(); | |
147 assert(t.ty == Taarray); | |
148 TypeAArray ta = cast(TypeAArray)t; | |
149 | |
150 /* Unfortunately, the hash function for Aa (array of chars) is custom and | |
151 * different from Axa and Aya, which get the generic hash function. | |
152 * So, rewrite the type of the AArray so that if it's key type | |
153 * is an array of const or invariant, make it an array of mutable. | |
154 */ | |
155 Type tkey = ta.index.toBasetype(); | |
156 if (tkey.ty == Tarray) | |
157 { | |
158 tkey = tkey.nextOf().mutableOf().arrayOf(); | |
159 tkey = tkey.semantic(Loc(0), null); | |
160 ta = new TypeAArray(ta.nextOf(), tkey); | |
161 ta = cast(TypeAArray)ta.merge(); | |
162 } | |
163 | |
164 e = el_param(e, ta.getTypeInfo(null).toElem(irs)); | |
165 | |
166 // call _d_assocarrayliteralT(ti, dim, ...) | |
167 e = el_bin(OPcall,TYnptr,el_var(rtlsym[RTLSYM_ASSOCARRAYLITERALT]),e); | |
168 | |
169 el_setLoc(e,loc); | |
170 return e; | |
116 } | 171 } |
117 | 172 |
118 bool checkSideEffect(int flag) | 173 bool checkSideEffect(int flag) |
119 { | 174 { |
120 bool f = false; | 175 bool f = false; |