Mercurial > projects > ldc
comparison gen/toobj.c @ 23:77e3d1ddae3f trunk
[svn r27] * Fixed bug in aggregate field lookup.
* Fixed structs with no fields.
* Added support for NegExp as in -x.
author | lindquist |
---|---|
date | Thu, 04 Oct 2007 09:24:15 +0200 |
parents | a6360e68134a |
children | 25bb577878e8 |
comparison
equal
deleted
inserted
replaced
22:a6360e68134a | 23:77e3d1ddae3f |
---|---|
143 /* ================================================================== */ | 143 /* ================================================================== */ |
144 | 144 |
145 /// Returns the LLVM style index from a DMD style offset | 145 /// Returns the LLVM style index from a DMD style offset |
146 void AggregateDeclaration::offsetToIndex(unsigned os, std::vector<unsigned>& result) | 146 void AggregateDeclaration::offsetToIndex(unsigned os, std::vector<unsigned>& result) |
147 { | 147 { |
148 //Logger::println("checking for offset %u :", os); | |
149 LOG_SCOPE; | |
148 unsigned vos = 0; | 150 unsigned vos = 0; |
149 for (unsigned i=0; i<fields.dim; ++i) { | 151 for (unsigned i=0; i<fields.dim; ++i) { |
150 VarDeclaration* vd = (VarDeclaration*)fields.data[i]; | 152 VarDeclaration* vd = (VarDeclaration*)fields.data[i]; |
151 if (vd->type->ty == Tstruct) { | 153 //Logger::println("found %u", vd->offset); |
154 if (os == vd->offset) { | |
155 result.push_back(i); | |
156 return; | |
157 } | |
158 else if (vd->type->ty == Tstruct) { | |
152 if (vos + vd->type->size() > os) { | 159 if (vos + vd->type->size() > os) { |
153 TypeStruct* ts = (TypeStruct*)vd->type; | 160 TypeStruct* ts = (TypeStruct*)vd->type; |
154 StructDeclaration* sd = ts->sym; | 161 StructDeclaration* sd = ts->sym; |
155 result.push_back(i); | 162 result.push_back(i); |
156 sd->offsetToIndex(os - vos, result); | 163 sd->offsetToIndex(os - vos, result); |
157 return; | 164 return; |
158 } | 165 } |
159 } | 166 } |
160 else if (os == vd->offset) { | |
161 result.push_back(i); | |
162 return; | |
163 } | |
164 vos += vd->offset; | 167 vos += vd->offset; |
165 } | 168 } |
166 assert(0 && "Offset not found in any aggregate field"); | 169 assert(0 && "Offset not found in any aggregate field"); |
167 } | 170 } |
168 | 171 |
231 mfs.push_back(fd); | 234 mfs.push_back(fd); |
232 } | 235 } |
233 else { | 236 else { |
234 dsym->toObjFile(); | 237 dsym->toObjFile(); |
235 } | 238 } |
239 } | |
240 | |
241 if (gIR->topstruct().fields.empty()) | |
242 { | |
243 gIR->topstruct().fields.push_back(llvm::Type::Int8Ty); | |
244 gIR->topstruct().inits.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); | |
236 } | 245 } |
237 | 246 |
238 llvm::StructType* structtype = llvm::StructType::get(gIR->topstruct().fields); | 247 llvm::StructType* structtype = llvm::StructType::get(gIR->topstruct().fields); |
239 | 248 |
240 // refine abstract types for stuff like: struct S{S* next;} | 249 // refine abstract types for stuff like: struct S{S* next;} |