From b347fd8a50a24eb68c72ef459b6c5eddbf007f46 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Mon, 19 Nov 2007 03:39:46 +0100 Subject: [PATCH] [svn r109] Fixed support for static array TypeInfo --- gen/typinf.cpp | 39 +++++++++++++++++++++++++++++---------- llvmdc.kdevelop.filelist | 1 + test/typeinfo11.d | 10 ++++++++++ 3 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 test/typeinfo11.d diff --git a/gen/typinf.cpp b/gen/typinf.cpp index 1c6f2200..cba611d6 100644 --- a/gen/typinf.cpp +++ b/gen/typinf.cpp @@ -510,22 +510,41 @@ void TypeInfoArrayDeclaration::toDt(dt_t **pdt) void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) { - assert(0 && "TypeInfoStaticArrayDeclaration"); + Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); + LOG_SCOPE; - /* - //printf("TypeInfoStaticArrayDeclaration::toDt()\n"); - dtxoff(pdt, Type::typeinfostaticarray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_StaticArray - dtdword(pdt, 0); // monitor + // init typeinfo class + ClassDeclaration* base = Type::typeinfostaticarray; + DtoForceConstInitDsymbol(base); + // get type of typeinfo class + const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); + + // initializer vector + std::vector 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 - dtdword(pdt, tc->dim->toInteger()); // length - */ + // 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); + + // 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; } /* ========================================================================= */ diff --git a/llvmdc.kdevelop.filelist b/llvmdc.kdevelop.filelist index ca1ee886..444070d2 100644 --- a/llvmdc.kdevelop.filelist +++ b/llvmdc.kdevelop.filelist @@ -404,6 +404,7 @@ test/throw1.d test/tuple1.d test/typeinfo.d test/typeinfo10.d +test/typeinfo11.d test/typeinfo2.d test/typeinfo3.d test/typeinfo4.d diff --git a/test/typeinfo11.d b/test/typeinfo11.d new file mode 100644 index 00000000..adb71770 --- /dev/null +++ b/test/typeinfo11.d @@ -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); +}