Mercurial > projects > ldc
comparison gen/toobj.c @ 24:25bb577878e8 trunk
[svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
author | lindquist |
---|---|
date | Thu, 04 Oct 2007 10:13:21 +0200 |
parents | 77e3d1ddae3f |
children | 99737f94abfb |
comparison
equal
deleted
inserted
replaced
23:77e3d1ddae3f | 24:25bb577878e8 |
---|---|
141 } | 141 } |
142 | 142 |
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(Type* t, unsigned os, std::vector<unsigned>& result) |
147 { | 147 { |
148 //Logger::println("checking for offset %u :", os); | 148 Logger::println("checking for offset %u type %s:", os, t->toChars()); |
149 LOG_SCOPE; | 149 LOG_SCOPE; |
150 unsigned vos = 0; | |
151 for (unsigned i=0; i<fields.dim; ++i) { | 150 for (unsigned i=0; i<fields.dim; ++i) { |
152 VarDeclaration* vd = (VarDeclaration*)fields.data[i]; | 151 VarDeclaration* vd = (VarDeclaration*)fields.data[i]; |
153 //Logger::println("found %u", vd->offset); | 152 Logger::println("found %u type %s", vd->offset, vd->type->toChars()); |
154 if (os == vd->offset) { | 153 if (os == vd->offset && vd->type == t) { |
155 result.push_back(i); | 154 result.push_back(i); |
156 return; | 155 return; |
157 } | 156 } |
158 else if (vd->type->ty == Tstruct) { | 157 else if (vd->type->ty == Tstruct && (vd->offset + vd->type->size()) > os) { |
159 if (vos + vd->type->size() > os) { | 158 TypeStruct* ts = (TypeStruct*)vd->type; |
160 TypeStruct* ts = (TypeStruct*)vd->type; | 159 StructDeclaration* sd = ts->sym; |
161 StructDeclaration* sd = ts->sym; | 160 result.push_back(i); |
162 result.push_back(i); | 161 sd->offsetToIndex(t, os - vd->offset, result); |
163 sd->offsetToIndex(os - vos, result); | 162 return; |
164 return; | 163 } |
165 } | |
166 } | |
167 vos += vd->offset; | |
168 } | 164 } |
169 assert(0 && "Offset not found in any aggregate field"); | 165 assert(0 && "Offset not found in any aggregate field"); |
170 } | 166 } |
171 | 167 |
172 /* ================================================================== */ | 168 /* ================================================================== */ |
192 return (unsigned)-1; | 188 return (unsigned)-1; |
193 } | 189 } |
194 | 190 |
195 /// Returns the LLVM style index from a DMD style offset | 191 /// Returns the LLVM style index from a DMD style offset |
196 /// Handles class inheritance | 192 /// Handles class inheritance |
197 void ClassDeclaration::offsetToIndex(unsigned os, std::vector<unsigned>& result) | 193 void ClassDeclaration::offsetToIndex(Type* t, unsigned os, std::vector<unsigned>& result) |
198 { | 194 { |
199 unsigned idx = 0; | 195 unsigned idx = 0; |
200 unsigned r = LLVM_ClassOffsetToIndex(this, os, idx); | 196 unsigned r = LLVM_ClassOffsetToIndex(this, os, idx); |
201 assert(r != (unsigned)-1 && "Offset not found in any aggregate field"); | 197 assert(r != (unsigned)-1 && "Offset not found in any aggregate field"); |
202 result.push_back(r+1); // vtable is 0 | 198 result.push_back(r+1); // vtable is 0 |