changeset 105:182b41f56b7f trunk

[svn r109] Fixed support for static array TypeInfo
author lindquist
date Mon, 19 Nov 2007 03:39:46 +0100
parents 4d1e9eb001e0
children 5b5194b25f33
files gen/typinf.cpp llvmdc.kdevelop.filelist test/typeinfo11.d
diffstat 3 files changed, 40 insertions(+), 10 deletions(-) [+]
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;
 }
 
 /* ========================================================================= */
--- a/llvmdc.kdevelop.filelist	Mon Nov 19 02:58:58 2007 +0100
+++ b/llvmdc.kdevelop.filelist	Mon Nov 19 03:39:46 2007 +0100
@@ -404,6 +404,7 @@
 test/tuple1.d
 test/typeinfo.d
 test/typeinfo10.d
+test/typeinfo11.d
 test/typeinfo2.d
 test/typeinfo3.d
 test/typeinfo4.d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/typeinfo11.d	Mon Nov 19 03:39:46 2007 +0100
@@ -0,0 +1,10 @@
+module typeinfo11;
+
+void main()
+{
+    int[4] a;
+    TypeInfo ti;
+    ti = typeid(typeof(a));
+    assert(ti.next() is typeid(int));
+    assert(ti.tsize() == 16);
+}