Mercurial > projects > ldc
diff gen/typinf.cpp @ 109:5ab8e92611f9 trunk
[svn r113] Added initial support for associative arrays (AAs).
Fixed some problems with the string runtime support functions.
Fixed initialization of array of structs.
Fixed slice assignment where LHS is slice but RHS is dynamic array.
Fixed problems with result of assignment expressions.
Fixed foreach problems with key type mismatches.
author | lindquist |
---|---|
date | Wed, 21 Nov 2007 04:13:15 +0100 |
parents | 5b5194b25f33 |
children | e8da7856a260 |
line wrap: on
line diff
--- a/gen/typinf.cpp Tue Nov 20 05:29:20 2007 +0100 +++ b/gen/typinf.cpp Wed Nov 21 04:13:15 2007 +0100 @@ -654,33 +654,69 @@ void TypeInfoAssociativeArrayDeclaration::llvmDeclare() { - assert(0 && "TypeInfoAssociativeArrayDeclaration"); + Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); + LOG_SCOPE; + + // init typeinfo class + ClassDeclaration* base = Type::typeinfoassociativearray; + DtoResolveClass(base); + + // get type of typeinfo class + const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); + + // create the symbol + llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoAssociativeArrayDeclaration::llvmDefine() { - assert(0 && "TypeInfoAssociativeArrayDeclaration"); + Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); + LOG_SCOPE; + + // init typeinfo class + ClassDeclaration* base = Type::typeinfoassociativearray; + DtoForceConstInitDsymbol(base); + + // 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); + + // get type + assert(tinfo->ty == Taarray); + TypeAArray *tc = (TypeAArray *)tinfo; + + // value typeinfo + tc->next->getTypeInfo(NULL); + + // get symbol + assert(tc->next->vtinfo); + DtoForceDeclareDsymbol(tc->next->vtinfo); + llvm::Constant* castbase = isaConstant(tc->next->vtinfo->llvmValue); + castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); + sinits.push_back(castbase); + + // key typeinfo + tc->index->getTypeInfo(NULL); + + // get symbol + assert(tc->index->vtinfo); + DtoForceDeclareDsymbol(tc->index->vtinfo); + castbase = isaConstant(tc->index->vtinfo->llvmValue); + castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); + sinits.push_back(castbase); + + // create the symbol + llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); + isaGlobalVar(llvmValue)->setInitializer(tiInit); } void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) { - assert(0 && "TypeInfoAssociativeArrayDeclaration"); - - /* - //printf("TypeInfoAssociativeArrayDeclaration::toDt()\n"); - dtxoff(pdt, Type::typeinfoassociativearray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_AssociativeArray - dtdword(pdt, 0); // monitor - - assert(tinfo->ty == Taarray); - - TypeAArray *tc = (TypeAArray *)tinfo; - - tc->next->getTypeInfo(NULL); - dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type - - tc->index->getTypeInfo(NULL); - dtxoff(pdt, tc->index->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type - */ + assert(0); } /* ========================================================================= */