[cfe-dev] How to determine base class direct or not?
r4start at gmail.com
Mon Nov 14 02:20:41 CST 2011
On 11/11/2011 21:31, John McCall wrote:
> On Nov 11, 2011, at 12:09 AM, r4start wrote:
>> This information is need to implement RTTI Class Hierarchy Descriptor in MS ABI.
>> This struct has following fields:
>> struct RTTIClassHierarchyDescriptor
>> DWORD signature; //always zero?
>> DWORD attributes; //bit 0 set = multiple inheritance, bit 1 set = virtual inheritance
>> DWORD numBaseClasses; //number of classes in pBaseClassArray
>> struct RTTIBaseClassArray* pBaseClassArray;
>> Yesterday I discovered that third bit(bit 2) in attributes field set when we have class like A1.
> Aha. I would guess that this bit indicates whether the object has any public ambiguous base-class subobjects; if it does, the dynamic_cast algorithm can't just stop at the first such subobject it finds, it has to keep searching to see if the cast fails due to ambiguity. You should definitely be doing this as a walk over the class hierarchy. Pseudocode:
Yes, you are right.
> queue : list<class>
> visited : set<class>
> visitedVirtual : set<class>
> while derived = queue.pop():
> foreach base in derived.bases:
> next unless base.public
> next if base.virtual and visitedVirtual.insertAndContains(base.class)
> return true if visited.insertAndContains(base.class)
> return false
Thanks for pseudocode, it works fine. But we don`t need to check that
base is public or not. This bit sets also for private and protected bases.
More information about the cfe-dev