diff gen/typinf.cpp @ 105:182b41f56b7f trunk

[svn r109] Fixed support for static array TypeInfo
author lindquist
date Mon, 19 Nov 2007 03:39:46 +0100
parents 027b8d8b71ec
children 5b5194b25f33
line wrap: on
line diff
--- a/gen/typinf.cpp	Mon Nov 19 02:58:58 2007 +0100
+++ b/gen/typinf.cpp	Mon Nov 19 03:39:46 2007 +0100
@@ -510,22 +510,41 @@
 
 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt)
 {
-    assert(0 && "TypeInfoStaticArrayDeclaration");
+    Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars());
+    LOG_SCOPE;
+
+    // init typeinfo class
+    ClassDeclaration* base = Type::typeinfostaticarray;
+    DtoForceConstInitDsymbol(base);
 
-    /*
-    //printf("TypeInfoStaticArrayDeclaration::toDt()\n");
-    dtxoff(pdt, Type::typeinfostaticarray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_StaticArray
-    dtdword(pdt, 0);                // monitor
+    // get type of typeinfo class
+    const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
 
+    // initializer vector
+    std::vector<llvm::Constant*> sinits;
+    // first is always the vtable
+    sinits.push_back(base->llvmVtbl);
+
+    // value typeinfo
     assert(tinfo->ty == Tsarray);
-
     TypeSArray *tc = (TypeSArray *)tinfo;
-
     tc->next->getTypeInfo(NULL);
-    dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type
+
+    // get symbol
+    assert(tc->next->vtinfo);
+    DtoForceConstInitDsymbol(tc->next->vtinfo);
+    llvm::Constant* castbase = isaConstant(tc->next->vtinfo->llvmValue);
+    castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1));
+    sinits.push_back(castbase);
 
-    dtdword(pdt, tc->dim->toInteger());     // length
-    */
+    // length
+    sinits.push_back(DtoConstSize_t(tc->dim->toInteger()));
+
+    // create the symbol
+    llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
+    llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module);
+
+    llvmValue = gvar;
 }
 
 /* ========================================================================= */