Mercurial > projects > ldc
comparison ir/irstruct.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 | ec1d9dc1d32a |
children | 8d501abecd24 |
comparison
equal
deleted
inserted
replaced
1269:b8a51aa44d4c | 1270:dd135ff697fa |
---|---|
17 #include <algorithm> | 17 #include <algorithm> |
18 | 18 |
19 ////////////////////////////////////////////////////////////////////////////// | 19 ////////////////////////////////////////////////////////////////////////////// |
20 | 20 |
21 IrStruct::IrStruct(AggregateDeclaration* aggr) | 21 IrStruct::IrStruct(AggregateDeclaration* aggr) |
22 : diCompositeType(NULL) | 22 : diCompositeType(NULL), |
23 init_pa(llvm::OpaqueType::get()) | |
23 { | 24 { |
24 aggrdecl = aggr; | 25 aggrdecl = aggr; |
25 | 26 |
26 type = aggr->type; | 27 type = aggr->type; |
27 | 28 |
55 initname.append("6__initZ"); | 56 initname.append("6__initZ"); |
56 | 57 |
57 llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(aggrdecl); | 58 llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(aggrdecl); |
58 | 59 |
59 init = new llvm::GlobalVariable( | 60 init = new llvm::GlobalVariable( |
60 type->irtype->getPA().get(), true, _linkage, NULL, initname, gIR->module); | 61 init_pa.get(), true, _linkage, NULL, initname, gIR->module); |
61 | 62 |
62 return init; | 63 return init; |
63 } | 64 } |
64 | 65 |
65 ////////////////////////////////////////////////////////////////////////////// | 66 ////////////////////////////////////////////////////////////////////////////// |
75 } | 76 } |
76 else | 77 else |
77 { | 78 { |
78 constInit = createClassDefaultInitializer(); | 79 constInit = createClassDefaultInitializer(); |
79 } | 80 } |
81 | |
82 llvm::OpaqueType* o = llvm::cast<llvm::OpaqueType>(init_pa.get()); | |
83 o->refineAbstractTypeTo(constInit->getType()); | |
80 | 84 |
81 return constInit; | 85 return constInit; |
82 } | 86 } |
83 | 87 |
84 ////////////////////////////////////////////////////////////////////////////// | 88 ////////////////////////////////////////////////////////////////////////////// |
155 IrTypeAggr::iterator it; | 159 IrTypeAggr::iterator it; |
156 for (it = ts->def_begin(); it != ts->def_end(); ++it) | 160 for (it = ts->def_begin(); it != ts->def_end(); ++it) |
157 { | 161 { |
158 VarDeclaration* vd = *it; | 162 VarDeclaration* vd = *it; |
159 | 163 |
160 if (vd->offset < offset) | 164 assert(vd->offset >= offset && "default fields not sorted by offset"); |
161 { | |
162 IF_LOG Logger::println("skipping field: %s %s (+%u)", vd->type->toChars(), vd->toChars(), vd->offset); | |
163 continue; | |
164 } | |
165 | 165 |
166 IF_LOG Logger::println("using field: %s %s (+%u)", vd->type->toChars(), vd->toChars(), vd->offset); | 166 IF_LOG Logger::println("using field: %s %s (+%u)", vd->type->toChars(), vd->toChars(), vd->offset); |
167 | 167 |
168 // get next aligned offset for this field | 168 // get next aligned offset for this field |
169 size_t alignedoffset = offset; | 169 size_t alignedoffset = offset; |