diff 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
line wrap: on
line diff
--- a/gen/toobj.c	Wed Sep 26 19:17:54 2007 +0200
+++ b/gen/toobj.c	Thu Sep 27 06:03:06 2007 +0200
@@ -139,15 +139,27 @@
 /* ================================================================== */
 
 /// Returns the LLVM style index from a DMD style offset
-unsigned AggregateDeclaration::offsetToIndex(unsigned os)
+void AggregateDeclaration::offsetToIndex(unsigned os, std::vector<unsigned>& result)
 {
+    unsigned vos = 0;
     for (unsigned i=0; i<fields.dim; ++i) {
         VarDeclaration* vd = (VarDeclaration*)fields.data[i];
-        if (os == vd->offset)
-            return i;
+        if (vd->type->ty == Tstruct) {
+            if (vos + vd->type->size() > os) {
+                TypeStruct* ts = (TypeStruct*)vd->type;
+                StructDeclaration* sd = ts->sym;
+                result.push_back(i);
+                sd->offsetToIndex(os - vos, result);
+                return;
+            }
+        }
+        else if (os == vd->offset) {
+            result.push_back(i);
+            return;
+        }
+        vos += vd->offset;
     }
     assert(0 && "Offset not found in any aggregate field");
-    return 0;
 }
 
 /* ================================================================== */
@@ -175,12 +187,12 @@
 
 /// Returns the LLVM style index from a DMD style offset
 /// Handles class inheritance
-unsigned ClassDeclaration::offsetToIndex(unsigned os)
+void ClassDeclaration::offsetToIndex(unsigned os, std::vector<unsigned>& result)
 {
     unsigned idx = 0;
     unsigned r = LLVM_ClassOffsetToIndex(this, os, idx);
     assert(r != (unsigned)-1 && "Offset not found in any aggregate field");
-    return r+1; // vtable is 0
+    result.push_back(r+1); // vtable is 0
 }
 
 /* ================================================================== */