[cfe-dev] How to determine base class direct or not?
John McCall
rjmccall at apple.com
Mon Nov 14 13:39:50 PST 2011
On Nov 14, 2011, at 12:20 AM, r4start wrote:
> 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>
>>
>> queue.insert(mostDerived)
>> 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)
>> queue.insert(base.class)
>> return false
>>
>> John.
> 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.
Interesting, okay.
John.
More information about the cfe-dev
mailing list