Mercurial > projects > ldc
comparison gen/classes.cpp @ 123:7f9a0a58394b trunk
[svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
Removed some potentially very long logging lines.
Added support for inner classes.
author | lindquist |
---|---|
date | Wed, 28 Nov 2007 03:01:51 +0100 |
parents | 9c79b61fb638 |
children | 1700239cab2e |
comparison
equal
deleted
inserted
replaced
122:36ab367572df | 123:7f9a0a58394b |
---|---|
129 if (!ts->llvmType) | 129 if (!ts->llvmType) |
130 ts->llvmType = new llvm::PATypeHolder(structtype); | 130 ts->llvmType = new llvm::PATypeHolder(structtype); |
131 else | 131 else |
132 *ts->llvmType = structtype; | 132 *ts->llvmType = structtype; |
133 | 133 |
134 if (cd->isNested()) { | 134 // name the type |
135 assert(0 && "nested classes not implemented"); | 135 gIR->module->addTypeName(cd->mangle(), ts->llvmType->get()); |
136 } | |
137 else { | |
138 gIR->module->addTypeName(cd->mangle(), ts->llvmType->get()); | |
139 } | |
140 | 136 |
141 // build interface info type | 137 // build interface info type |
142 std::vector<const llvm::Type*> infoTypes; | 138 std::vector<const llvm::Type*> infoTypes; |
143 // ClassInfo classinfo | 139 // ClassInfo classinfo |
144 ClassDeclaration* cinfod = ClassDeclaration::classinfo; | 140 ClassDeclaration* cinfod = ClassDeclaration::classinfo; |
229 | 225 |
230 gIR->structs.push_back(irstruct); | 226 gIR->structs.push_back(irstruct); |
231 gIR->classes.push_back(cd); | 227 gIR->classes.push_back(cd); |
232 | 228 |
233 bool needs_definition = false; | 229 bool needs_definition = false; |
234 if (cd->parent->isModule()) { | 230 if (cd->getModule() == gIR->dmodule) { |
235 needs_definition = (cd->getModule() == gIR->dmodule); | 231 needs_definition = true; |
236 } | 232 } |
237 | 233 |
238 // interface vtables are emitted by the class implementing them | 234 // interface vtables are emitted by the class implementing them |
239 // also interfaces have no static initializer | 235 // also interfaces have no static initializer |
240 if (!cd->isInterfaceDeclaration()) { | 236 if (!cd->isInterfaceDeclaration()) { |
317 | 313 |
318 // classinfo | 314 // classinfo |
319 DtoDeclareClassInfo(cd); | 315 DtoDeclareClassInfo(cd); |
320 | 316 |
321 // typeinfo | 317 // typeinfo |
322 if (cd->parent->isModule() && cd->getModule() == gIR->dmodule) | 318 if (needs_definition) |
323 cd->type->getTypeInfo(NULL); | 319 cd->type->getTypeInfo(NULL); |
324 } | 320 } |
325 | 321 |
326 ////////////////////////////////////////////////////////////////////////////////////////// | 322 ////////////////////////////////////////////////////////////////////////////////////////// |
327 | 323 |
518 | 514 |
519 // get the struct (class) type | 515 // get the struct (class) type |
520 assert(cd->type->ty == Tclass); | 516 assert(cd->type->ty == Tclass); |
521 TypeClass* ts = (TypeClass*)cd->type; | 517 TypeClass* ts = (TypeClass*)cd->type; |
522 | 518 |
523 bool def = false; | 519 if (cd->getModule() == gIR->dmodule) { |
524 if (cd->parent->isModule() && cd->getModule() == gIR->dmodule) { | |
525 // interfaces don't have initializers | 520 // interfaces don't have initializers |
526 if (!cd->isInterfaceDeclaration()) { | 521 if (!cd->isInterfaceDeclaration()) { |
527 cd->llvmInit->setInitializer(cd->llvmConstInit); | 522 cd->llvmInit->setInitializer(cd->llvmConstInit); |
528 cd->llvmVtbl->setInitializer(cd->llvmConstVtbl); | 523 cd->llvmVtbl->setInitializer(cd->llvmConstVtbl); |
529 | 524 |
540 if (!infoInits.empty()) { | 535 if (!infoInits.empty()) { |
541 llvm::Constant* arrInit = llvm::ConstantArray::get(irstruct->interfaceInfosTy, infoInits); | 536 llvm::Constant* arrInit = llvm::ConstantArray::get(irstruct->interfaceInfosTy, infoInits); |
542 irstruct->interfaceInfos->setInitializer(arrInit); | 537 irstruct->interfaceInfos->setInitializer(arrInit); |
543 } | 538 } |
544 } | 539 } |
545 def = true; | 540 |
546 } | 541 // generate classinfo |
547 | 542 DtoDefineClassInfo(cd); |
548 // generate classinfo | 543 } |
549 if (def) DtoDefineClassInfo(cd); | |
550 } | 544 } |
551 | 545 |
552 ////////////////////////////////////////////////////////////////////////////////////////// | 546 ////////////////////////////////////////////////////////////////////////////////////////// |
553 | 547 |
554 void DtoCallClassDtors(TypeClass* tc, llvm::Value* instance) | 548 void DtoCallClassDtors(TypeClass* tc, llvm::Value* instance) |
750 assert(vd->type->vtinfo); | 744 assert(vd->type->vtinfo); |
751 DtoForceDeclareDsymbol(vd->type->vtinfo); | 745 DtoForceDeclareDsymbol(vd->type->vtinfo); |
752 llvm::Constant* c = isaConstant(vd->type->vtinfo->llvmValue); | 746 llvm::Constant* c = isaConstant(vd->type->vtinfo->llvmValue); |
753 | 747 |
754 const llvm::Type* tiTy = llvm::PointerType::get(Type::typeinfo->type->llvmType->get()); | 748 const llvm::Type* tiTy = llvm::PointerType::get(Type::typeinfo->type->llvmType->get()); |
755 Logger::cout() << "tiTy = " << *tiTy << '\n'; | 749 //Logger::cout() << "tiTy = " << *tiTy << '\n'; |
756 | 750 |
757 types.push_back(tiTy); | 751 types.push_back(tiTy); |
758 inits.push_back(llvm::ConstantExpr::getBitCast(c, tiTy)); | 752 inits.push_back(llvm::ConstantExpr::getBitCast(c, tiTy)); |
759 | 753 |
760 const llvm::StructType* sTy = llvm::StructType::get(types); | 754 const llvm::StructType* sTy = llvm::StructType::get(types); |