Mercurial > projects > ldc
comparison 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 |
comparison
equal
deleted
inserted
replaced
108:288fe1029e1f | 109:5ab8e92611f9 |
---|---|
652 | 652 |
653 /* ========================================================================= */ | 653 /* ========================================================================= */ |
654 | 654 |
655 void TypeInfoAssociativeArrayDeclaration::llvmDeclare() | 655 void TypeInfoAssociativeArrayDeclaration::llvmDeclare() |
656 { | 656 { |
657 assert(0 && "TypeInfoAssociativeArrayDeclaration"); | 657 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); |
658 LOG_SCOPE; | |
659 | |
660 // init typeinfo class | |
661 ClassDeclaration* base = Type::typeinfoassociativearray; | |
662 DtoResolveClass(base); | |
663 | |
664 // get type of typeinfo class | |
665 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
666 | |
667 // create the symbol | |
668 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
658 } | 669 } |
659 | 670 |
660 void TypeInfoAssociativeArrayDeclaration::llvmDefine() | 671 void TypeInfoAssociativeArrayDeclaration::llvmDefine() |
661 { | 672 { |
662 assert(0 && "TypeInfoAssociativeArrayDeclaration"); | 673 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); |
674 LOG_SCOPE; | |
675 | |
676 // init typeinfo class | |
677 ClassDeclaration* base = Type::typeinfoassociativearray; | |
678 DtoForceConstInitDsymbol(base); | |
679 | |
680 // get type of typeinfo class | |
681 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
682 | |
683 // initializer vector | |
684 std::vector<llvm::Constant*> sinits; | |
685 // first is always the vtable | |
686 sinits.push_back(base->llvmVtbl); | |
687 | |
688 // get type | |
689 assert(tinfo->ty == Taarray); | |
690 TypeAArray *tc = (TypeAArray *)tinfo; | |
691 | |
692 // value typeinfo | |
693 tc->next->getTypeInfo(NULL); | |
694 | |
695 // get symbol | |
696 assert(tc->next->vtinfo); | |
697 DtoForceDeclareDsymbol(tc->next->vtinfo); | |
698 llvm::Constant* castbase = isaConstant(tc->next->vtinfo->llvmValue); | |
699 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); | |
700 sinits.push_back(castbase); | |
701 | |
702 // key typeinfo | |
703 tc->index->getTypeInfo(NULL); | |
704 | |
705 // get symbol | |
706 assert(tc->index->vtinfo); | |
707 DtoForceDeclareDsymbol(tc->index->vtinfo); | |
708 castbase = isaConstant(tc->index->vtinfo->llvmValue); | |
709 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); | |
710 sinits.push_back(castbase); | |
711 | |
712 // create the symbol | |
713 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | |
714 isaGlobalVar(llvmValue)->setInitializer(tiInit); | |
663 } | 715 } |
664 | 716 |
665 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) | 717 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) |
666 { | 718 { |
667 assert(0 && "TypeInfoAssociativeArrayDeclaration"); | 719 assert(0); |
668 | |
669 /* | |
670 //printf("TypeInfoAssociativeArrayDeclaration::toDt()\n"); | |
671 dtxoff(pdt, Type::typeinfoassociativearray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_AssociativeArray | |
672 dtdword(pdt, 0); // monitor | |
673 | |
674 assert(tinfo->ty == Taarray); | |
675 | |
676 TypeAArray *tc = (TypeAArray *)tinfo; | |
677 | |
678 tc->next->getTypeInfo(NULL); | |
679 dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type | |
680 | |
681 tc->index->getTypeInfo(NULL); | |
682 dtxoff(pdt, tc->index->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type | |
683 */ | |
684 } | 720 } |
685 | 721 |
686 /* ========================================================================= */ | 722 /* ========================================================================= */ |
687 | 723 |
688 void TypeInfoFunctionDeclaration::llvmDeclare() | 724 void TypeInfoFunctionDeclaration::llvmDeclare() |