Currently TypeInfo_Class implements a primitive interfaces() that returns an array of struct Interface. The vtbl and offset of the interface are magic. Should be available as __traits.
This blocks https://github.com/dlang/druntime/pull/3174.
Comment #1 by bugzilla — 2020-08-10T23:38:06Z
It is an array of:
for (size_t i = 0; i < cd.vtblInterfaces.dim; i++)
{
BaseClass *b = (*cd.vtblInterfaces)[i];
ClassDeclaration id = b.sym;
/* The layout is:
* struct Interface
* {
* ClassInfo classinfo;
* void*[] vtbl;
* size_t offset;
* }
*/
// Fill in vtbl[]
b.fillVtbl(cd, &b.vtbl, 1);
// classinfo
dtb.xoff(toSymbol(id), 0, TYnptr);
// vtbl[]
dtb.size(id.vtbl.dim);
dtb.xoff(cd.csym, offset, TYnptr);
// offset
dtb.size(b.offset);
}
The compiler doesn't emit this as a separate symbol. A toInterfacesSymbol() function would have to be written to emit it.
Comment #2 by robert.schadek — 2024-12-13T19:10:50Z