Mercurial > projects > ldc
comparison gen/classes.cpp @ 816:7d16ce7ad19d
Made ClassInfo.interfaces generation consistent with DMD, fixes #134
Removed unneeded includes from dmd/attrib.c
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Mon, 01 Dec 2008 18:34:02 +0100 |
parents | 6c2ff06c4201 |
children | 8f0b24bc55f0 |
comparison
equal
deleted
inserted
replaced
815:35de5ba7d36d | 816:7d16ce7ad19d |
---|---|
49 // add to map | 49 // add to map |
50 if (overwrite) | 50 if (overwrite) |
51 irstruct->interfaceMap[b->base] = iri; | 51 irstruct->interfaceMap[b->base] = iri; |
52 else | 52 else |
53 irstruct->interfaceMap.insert(std::make_pair(b->base, iri)); | 53 irstruct->interfaceMap.insert(std::make_pair(b->base, iri)); |
54 | |
54 // add to ordered list | 55 // add to ordered list |
55 irstruct->interfaceVec.push_back(iri); | 56 irstruct->interfaceVec.push_back(iri); |
57 | |
58 // add to classinfo interfaces | |
59 if (newinstance) | |
60 irstruct->classInfoInterfaces.push_back(iri); | |
56 | 61 |
57 // assign this iri to all base interfaces of this one | 62 // assign this iri to all base interfaces of this one |
58 for (unsigned j = 0; j < b->baseInterfaces_dim; j++) | 63 for (unsigned j = 0; j < b->baseInterfaces_dim; j++) |
59 { | 64 { |
60 BaseClass *bc = &b->baseInterfaces[j]; | 65 BaseClass *bc = &b->baseInterfaces[j]; |
146 DtoResolveInterface(id); | 151 DtoResolveInterface(id); |
147 | 152 |
148 // add to interfaceInfos | 153 // add to interfaceInfos |
149 IrInterface* iri = new IrInterface(bc); | 154 IrInterface* iri = new IrInterface(bc); |
150 irstruct->interfaceVec.push_back(iri); | 155 irstruct->interfaceVec.push_back(iri); |
156 irstruct->classInfoInterfaces.push_back(iri); | |
151 } | 157 } |
152 } | 158 } |
153 | 159 |
154 // create the type | 160 // create the type |
155 const LLType* t = LLArrayType::get(getVoidPtrType(), cd->vtbl.dim); | 161 const LLType* t = LLArrayType::get(getVoidPtrType(), cd->vtbl.dim); |
376 | 382 |
377 // DMD gives abstract classes a full ClassInfo, so we do it as well | 383 // DMD gives abstract classes a full ClassInfo, so we do it as well |
378 | 384 |
379 // interface vtables | 385 // interface vtables |
380 unsigned idx = 0; | 386 unsigned idx = 0; |
381 | |
382 for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i) | 387 for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i) |
383 { | 388 { |
384 IrInterface* iri = *i; | 389 IrInterface* iri = *i; |
385 ClassDeclaration* id = iri->decl; | 390 ClassDeclaration* id = iri->decl; |
386 | 391 |
390 nam.append(id->mangle()); | 395 nam.append(id->mangle()); |
391 nam.append("6__vtblZ"); | 396 nam.append("6__vtblZ"); |
392 | 397 |
393 iri->vtbl = new llvm::GlobalVariable(iri->vtblInitTy.get(), true, _linkage, 0, nam, gIR->module); | 398 iri->vtbl = new llvm::GlobalVariable(iri->vtblInitTy.get(), true, _linkage, 0, nam, gIR->module); |
394 | 399 |
395 // always create interfaceinfos | 400 // always set the interface info as it's need as the first vtbl entry |
396 LLConstant* idxs[2] = {DtoConstUint(0), DtoConstUint(idx)}; | 401 LLConstant* idxs[2] = {DtoConstUint(0), DtoConstUint(idx)}; |
397 iri->info = llvm::ConstantExpr::getGetElementPtr(irstruct->interfaceInfos, idxs, 2); | 402 iri->info = llvm::ConstantExpr::getGetElementPtr(irstruct->interfaceInfos, idxs, 2); |
398 idx++; | 403 idx++; |
399 } | 404 } |
400 | 405 |
1504 const LLType* intersTy = DtoType(intersVar->type); | 1509 const LLType* intersTy = DtoType(intersVar->type); |
1505 if (!ir->interfaceInfos) | 1510 if (!ir->interfaceInfos) |
1506 c = LLConstant::getNullValue(intersTy); | 1511 c = LLConstant::getNullValue(intersTy); |
1507 else { | 1512 else { |
1508 const LLType* t = intersTy->getContainedType(1); // .ptr | 1513 const LLType* t = intersTy->getContainedType(1); // .ptr |
1514 // cast to Interface* | |
1509 c = DtoBitCast(ir->interfaceInfos, t); | 1515 c = DtoBitCast(ir->interfaceInfos, t); |
1510 size_t iisz = ir->interfaceVec.size(); | 1516 size_t isz = ir->interfaceVec.size(); |
1517 size_t iisz = ir->classInfoInterfaces.size(); | |
1518 assert(iisz <= isz); | |
1519 // offset - we only want the 'iisz' last ones | |
1520 LLConstant* idx = DtoConstUint(isz - iisz); | |
1521 c = llvm::ConstantExpr::getGetElementPtr(c, &idx, 1); | |
1522 // make array | |
1511 c = DtoConstSlice(DtoConstSize_t(iisz), c); | 1523 c = DtoConstSlice(DtoConstSize_t(iisz), c); |
1512 } | 1524 } |
1513 inits.push_back(c); | 1525 inits.push_back(c); |
1514 | 1526 |
1515 // base classinfo | 1527 // base classinfo |