Mercurial > projects > ldc
comparison gen/toobj.c @ 8:5e69b77a5c51 trunk
[svn r12] fixed accessing aggregate fields of aggregates
removed some useless branches for successive scopes ala {}{}{}
author | lindquist |
---|---|
date | Thu, 27 Sep 2007 06:03:06 +0200 |
parents | 35d93ce68cf4 |
children | dafae18f9c08 |
comparison
equal
deleted
inserted
replaced
7:7a155ba88c53 | 8:5e69b77a5c51 |
---|---|
137 } | 137 } |
138 | 138 |
139 /* ================================================================== */ | 139 /* ================================================================== */ |
140 | 140 |
141 /// Returns the LLVM style index from a DMD style offset | 141 /// Returns the LLVM style index from a DMD style offset |
142 unsigned AggregateDeclaration::offsetToIndex(unsigned os) | 142 void AggregateDeclaration::offsetToIndex(unsigned os, std::vector<unsigned>& result) |
143 { | 143 { |
144 unsigned vos = 0; | |
144 for (unsigned i=0; i<fields.dim; ++i) { | 145 for (unsigned i=0; i<fields.dim; ++i) { |
145 VarDeclaration* vd = (VarDeclaration*)fields.data[i]; | 146 VarDeclaration* vd = (VarDeclaration*)fields.data[i]; |
146 if (os == vd->offset) | 147 if (vd->type->ty == Tstruct) { |
147 return i; | 148 if (vos + vd->type->size() > os) { |
149 TypeStruct* ts = (TypeStruct*)vd->type; | |
150 StructDeclaration* sd = ts->sym; | |
151 result.push_back(i); | |
152 sd->offsetToIndex(os - vos, result); | |
153 return; | |
154 } | |
155 } | |
156 else if (os == vd->offset) { | |
157 result.push_back(i); | |
158 return; | |
159 } | |
160 vos += vd->offset; | |
148 } | 161 } |
149 assert(0 && "Offset not found in any aggregate field"); | 162 assert(0 && "Offset not found in any aggregate field"); |
150 return 0; | |
151 } | 163 } |
152 | 164 |
153 /* ================================================================== */ | 165 /* ================================================================== */ |
154 | 166 |
155 static unsigned LLVM_ClassOffsetToIndex(ClassDeclaration* cd, unsigned os, unsigned& idx) | 167 static unsigned LLVM_ClassOffsetToIndex(ClassDeclaration* cd, unsigned os, unsigned& idx) |
173 return (unsigned)-1; | 185 return (unsigned)-1; |
174 } | 186 } |
175 | 187 |
176 /// Returns the LLVM style index from a DMD style offset | 188 /// Returns the LLVM style index from a DMD style offset |
177 /// Handles class inheritance | 189 /// Handles class inheritance |
178 unsigned ClassDeclaration::offsetToIndex(unsigned os) | 190 void ClassDeclaration::offsetToIndex(unsigned os, std::vector<unsigned>& result) |
179 { | 191 { |
180 unsigned idx = 0; | 192 unsigned idx = 0; |
181 unsigned r = LLVM_ClassOffsetToIndex(this, os, idx); | 193 unsigned r = LLVM_ClassOffsetToIndex(this, os, idx); |
182 assert(r != (unsigned)-1 && "Offset not found in any aggregate field"); | 194 assert(r != (unsigned)-1 && "Offset not found in any aggregate field"); |
183 return r+1; // vtable is 0 | 195 result.push_back(r+1); // vtable is 0 |
184 } | 196 } |
185 | 197 |
186 /* ================================================================== */ | 198 /* ================================================================== */ |
187 | 199 |
188 void InterfaceDeclaration::toObjFile() | 200 void InterfaceDeclaration::toObjFile() |