diff gen/classes.cpp @ 117:56a21f3e5d3e trunk

[svn r121] Finished ModuleInfo implementation. Static ctors/dtors now work according to spec. Changed class vtable types slightly in some cases. Overridden functions now always take the the type of the first class declaring the method as this parameter. This helps when using headers (w. implementation somewhere else)
author lindquist
date Mon, 26 Nov 2007 04:49:23 +0100
parents 5ba6d286c941
children 9c79b61fb638
line wrap: on
line diff
--- a/gen/classes.cpp	Sun Nov 25 18:55:52 2007 +0100
+++ b/gen/classes.cpp	Mon Nov 26 04:49:23 2007 +0100
@@ -167,10 +167,12 @@
 
         if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
             DtoResolveFunction(fd);
-            assert(fd->type->ty == Tfunction);
-            TypeFunction* tf = (TypeFunction*)fd->type;
-            const llvm::Type* fpty = llvm::PointerType::get(tf->llvmType->get());
-            sinits_ty.push_back(fpty);
+            //assert(fd->type->ty == Tfunction);
+            //TypeFunction* tf = (TypeFunction*)fd->type;
+            //const llvm::Type* fpty = llvm::PointerType::get(tf->llvmType->get());
+            const llvm::FunctionType* vfty = DtoBaseFunctionType(fd);
+            const llvm::Type* vfpty = llvm::PointerType::get(vfty);
+            sinits_ty.push_back(vfpty);
         }
         else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) {
             Logger::println("*** ClassDeclaration in vtable: %s", cd2->toChars());
@@ -375,6 +377,7 @@
     assert(cd->type->ty == Tclass);
     TypeClass* ts = (TypeClass*)cd->type;
     const llvm::StructType* structtype = isaStruct(ts->llvmType->get());
+    const llvm::StructType* vtbltype = isaStruct(ts->llvmVtblType->get());
 
     // generate initializer
 #if 0
@@ -406,6 +409,9 @@
             DtoForceDeclareDsymbol(fd);
             assert(fd->llvmValue);
             llvm::Constant* c = llvm::cast<llvm::Constant>(fd->llvmValue);
+            // cast if necessary (overridden method)
+            if (c->getType() != vtbltype->getElementType(k))
+                c = llvm::ConstantExpr::getBitCast(c, vtbltype->getElementType(k));
             sinits.push_back(c);
         }
         else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) {
@@ -1037,8 +1043,8 @@
     if (cd->defaultCtor && !cd->isInterfaceDeclaration()) {
         DtoForceDeclareDsymbol(cd->defaultCtor);
         c = isaConstant(cd->defaultCtor->llvmValue);
-        //const llvm::Type* toTy = cinfo->llvmInitZ->getOperand(11)->getType();
-        c = llvm::ConstantExpr::getBitCast(c, llvm::PointerType::get(llvm::Type::Int8Ty)); // toTy);
+        const llvm::Type* toTy = cinfo->llvmInitZ->getOperand(12)->getType();
+        c = llvm::ConstantExpr::getBitCast(c, toTy);
     }
     else {
         c = cinfo->llvmInitZ->getOperand(12);