Mercurial > projects > ldc
comparison ir/irstruct.cpp @ 1262:ec1d9dc1d32a
Fixed struct default initializers.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Sat, 25 Apr 2009 18:26:54 +0200 |
parents | 747fdd9245d7 |
children | dd135ff697fa |
comparison
equal
deleted
inserted
replaced
1257:7af860e4f403 | 1262:ec1d9dc1d32a |
---|---|
140 IF_LOG Logger::println("Building default initializer for %s", aggrdecl->toPrettyChars()); | 140 IF_LOG Logger::println("Building default initializer for %s", aggrdecl->toPrettyChars()); |
141 LOG_SCOPE; | 141 LOG_SCOPE; |
142 | 142 |
143 assert(type->ty == Tstruct && "cannot build struct default initializer for non struct type"); | 143 assert(type->ty == Tstruct && "cannot build struct default initializer for non struct type"); |
144 | 144 |
145 IrTypeStruct* ts = type->irtype->isStruct(); | |
146 assert(ts); | |
147 | |
145 // start at offset zero | 148 // start at offset zero |
146 size_t offset = 0; | 149 size_t offset = 0; |
147 | 150 |
148 // vector of constants | 151 // vector of constants |
149 std::vector<llvm::Constant*> constants; | 152 std::vector<llvm::Constant*> constants; |
150 | 153 |
151 // go through fields | 154 // go through fields |
152 ArrayIter<VarDeclaration> it(aggrdecl->fields); | 155 IrTypeAggr::iterator it; |
153 for (; !it.done(); it.next()) | 156 for (it = ts->def_begin(); it != ts->def_end(); ++it) |
154 { | 157 { |
155 VarDeclaration* vd = it.get(); | 158 VarDeclaration* vd = *it; |
156 | 159 |
157 if (vd->offset < offset) | 160 if (vd->offset < offset) |
158 { | 161 { |
159 IF_LOG Logger::println("skipping field: %s %s (+%u)", vd->type->toChars(), vd->toChars(), vd->offset); | 162 IF_LOG Logger::println("skipping field: %s %s (+%u)", vd->type->toChars(), vd->toChars(), vd->offset); |
160 continue; | 163 continue; |
192 // build constant struct | 195 // build constant struct |
193 llvm::Constant* definit = llvm::ConstantStruct::get(constants, packed); | 196 llvm::Constant* definit = llvm::ConstantStruct::get(constants, packed); |
194 #if 0 | 197 #if 0 |
195 IF_LOG Logger::cout() << "final default initializer: " << *definit << std::endl; | 198 IF_LOG Logger::cout() << "final default initializer: " << *definit << std::endl; |
196 #endif | 199 #endif |
197 | |
198 // sanity check | |
199 if (definit->getType() != type->irtype->get()) | |
200 { | |
201 assert(0 && "default initializer type does not match the default struct type"); | |
202 } | |
203 | 200 |
204 return definit; | 201 return definit; |
205 } | 202 } |
206 | 203 |
207 ////////////////////////////////////////////////////////////////////////////// | 204 ////////////////////////////////////////////////////////////////////////////// |