diff ir/irclass.cpp @ 1270:dd135ff697fa

Fixed class default initializers and type generation. Bug #260 is fixed.
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Mon, 27 Apr 2009 03:40:40 +0200
parents 4fc43e173a0f
children 8fb39f7f1a7c
line wrap: on
line diff
--- a/ir/irclass.cpp	Mon Apr 27 01:43:29 2009 +0200
+++ b/ir/irclass.cpp	Mon Apr 27 03:40:40 2009 +0200
@@ -183,21 +183,20 @@
         addBaseClassInits(constants, base->baseClass, offset, field_index);
     }
 
-    ArrayIter<VarDeclaration> it(base->fields);
-    for (; !it.done(); it.next())
-    {
-        VarDeclaration* vd = it.get();
+    IrTypeClass* tc = base->type->irtype->isClass();
+    assert(tc);
 
-        // skip if offset moved backwards
-        if (vd->offset < offset)
-        {
-            IF_LOG Logger::println("Skipping field %s %s (+%u) for default", vd->type->toChars(), vd->toChars(), vd->offset);
-            continue;
-        }
+    // go through fields
+    IrTypeAggr::iterator it;
+    for (it = tc->def_begin(); it != tc->def_end(); ++it)
+    {
+        VarDeclaration* vd = *it;
 
         IF_LOG Logger::println("Adding default field %s %s (+%u)", vd->type->toChars(), vd->toChars(), vd->offset);
         LOG_SCOPE;
 
+        assert(vd->offset >= offset && "default fields not sorted by offset");
+
         // get next aligned offset for this type
         size_t alignsize = vd->type->alignsize();
         size_t alignedoffset = (offset + alignsize - 1) & ~(alignsize - 1);
@@ -216,13 +215,15 @@
     }
 
     // has interface vtbls?
-    if (base->vtblInterfaces)
+    if (base->vtblInterfaces && base->vtblInterfaces->dim > 0)
     {
         // false when it's not okay to use functions from super classes
         bool newinsts = (base == aggrdecl->isClassDeclaration());
 
         size_t inter_idx = interfacesWithVtbls.size();
 
+        offset = (offset + PTRSIZE - 1) & ~(PTRSIZE - 1);
+
         ArrayIter<BaseClass> it2(*base->vtblInterfaces);
         for (; !it2.done(); it2.next())
         {