Mercurial > projects > ldc
comparison ir/irclass.cpp @ 1270:dd135ff697fa
Fixed class default initializers and type generation. Bug #260 is fixed.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Mon, 27 Apr 2009 03:40:40 +0200 |
parents | 4fc43e173a0f |
children | 8fb39f7f1a7c |
comparison
equal
deleted
inserted
replaced
1269:b8a51aa44d4c | 1270:dd135ff697fa |
---|---|
181 if (base->baseClass) | 181 if (base->baseClass) |
182 { | 182 { |
183 addBaseClassInits(constants, base->baseClass, offset, field_index); | 183 addBaseClassInits(constants, base->baseClass, offset, field_index); |
184 } | 184 } |
185 | 185 |
186 ArrayIter<VarDeclaration> it(base->fields); | 186 IrTypeClass* tc = base->type->irtype->isClass(); |
187 for (; !it.done(); it.next()) | 187 assert(tc); |
188 { | 188 |
189 VarDeclaration* vd = it.get(); | 189 // go through fields |
190 | 190 IrTypeAggr::iterator it; |
191 // skip if offset moved backwards | 191 for (it = tc->def_begin(); it != tc->def_end(); ++it) |
192 if (vd->offset < offset) | 192 { |
193 { | 193 VarDeclaration* vd = *it; |
194 IF_LOG Logger::println("Skipping field %s %s (+%u) for default", vd->type->toChars(), vd->toChars(), vd->offset); | |
195 continue; | |
196 } | |
197 | 194 |
198 IF_LOG Logger::println("Adding default field %s %s (+%u)", vd->type->toChars(), vd->toChars(), vd->offset); | 195 IF_LOG Logger::println("Adding default field %s %s (+%u)", vd->type->toChars(), vd->toChars(), vd->offset); |
199 LOG_SCOPE; | 196 LOG_SCOPE; |
197 | |
198 assert(vd->offset >= offset && "default fields not sorted by offset"); | |
200 | 199 |
201 // get next aligned offset for this type | 200 // get next aligned offset for this type |
202 size_t alignsize = vd->type->alignsize(); | 201 size_t alignsize = vd->type->alignsize(); |
203 size_t alignedoffset = (offset + alignsize - 1) & ~(alignsize - 1); | 202 size_t alignedoffset = (offset + alignsize - 1) & ~(alignsize - 1); |
204 | 203 |
214 // advance offset to right past this field | 213 // advance offset to right past this field |
215 offset = vd->offset + vd->type->size(); | 214 offset = vd->offset + vd->type->size(); |
216 } | 215 } |
217 | 216 |
218 // has interface vtbls? | 217 // has interface vtbls? |
219 if (base->vtblInterfaces) | 218 if (base->vtblInterfaces && base->vtblInterfaces->dim > 0) |
220 { | 219 { |
221 // false when it's not okay to use functions from super classes | 220 // false when it's not okay to use functions from super classes |
222 bool newinsts = (base == aggrdecl->isClassDeclaration()); | 221 bool newinsts = (base == aggrdecl->isClassDeclaration()); |
223 | 222 |
224 size_t inter_idx = interfacesWithVtbls.size(); | 223 size_t inter_idx = interfacesWithVtbls.size(); |
224 | |
225 offset = (offset + PTRSIZE - 1) & ~(PTRSIZE - 1); | |
225 | 226 |
226 ArrayIter<BaseClass> it2(*base->vtblInterfaces); | 227 ArrayIter<BaseClass> it2(*base->vtblInterfaces); |
227 for (; !it2.done(); it2.next()) | 228 for (; !it2.done(); it2.next()) |
228 { | 229 { |
229 BaseClass* b = it2.get(); | 230 BaseClass* b = it2.get(); |