<div dir="ltr"><font face="courier new, monospace">Hello all. New to cfe-dev (and participating in mailing lists in general).<br><br>The question I'm hoping to have answered is as simple as the subject implies. I have a CXXRecordDecl,<br>
and I am trying to determine which of its bases is derived from a class that I know this CXXRecordDecl<br>is also derived from.</font><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">i.e.</font></div>
<div><font face="courier new, monospace">class A;</font></div><div><font face="courier new, monospace">class B : public A;</font></div><div><font face="courier new, monospace">class C;</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">class D : public B, public C</font></div><div><font face="courier new, monospace">Looking for which base D gets its A from.<br><br>I am also seeking general advice for my project as it pertains to my usage of clang. I am using<br>
libtooling and ASTMatchers to create Python bindings for a game engine.<br><br>This is some sample input I am using for my generator: [test-input].<br><br>When attempting to locate which base of MyBaz and MyDerived gets their inheritance of Colossus::MyBase,<br>
I've tried the following strategy: Obtain the type of the base specifier, and using an appropriate</font></div><div><font face="courier new, monospace">DeclContext, look up the declaration. Once I have the declaration, I can use its methods to determine if</font></div>
<div><font face="courier new, monospace">it's derived from Colossus::MyBase (or is that class).<br>
<br>// Get the qualified name of the base<br>QualType type = aBaseSpecifier->getType();</font><div><font face="courier new, monospace"><div>DeclarationName baseDeclName( type.getBaseTypeIdentifier() );</div></font><font face="courier new, monospace"><div>
<br></div><div>// Grab a context to look up the decl</div><div>const DeclContext* lookupContext = theCxxRecordDecl->getLookupContext();</div><div><br></div><div>DeclContext::lookup_const_result lr = lookupContext->lookup(baseDeclName);</div>
<div><br></div><div>This strategy seems somewhat valid. When I use the "LookupContext" of the derived class, the base of MyBaz</div><div>is correctly identified as MyDerived. However, MyDerived's base is not found by that context. Alternately,</div>
<div>I tried to use the ASTContext's TranslationUnitDecl as my lookup context thinking that if I start at the root</div><div>DeclContext everything should be found. In doing that however, all of my lookups failed. I fear I'm taking</div>
<div>a completely wrongheaded approach here.</div>
<div><br></div><div>[test-input] <a href="http://pastebin.com/iSCnMmsd" target="_blank">http://pastebin.com/iSCnMmsd</a></div></font><font face="courier new, monospace"><br>--<br>Justin Arruda<br><br>PS Please call out any poor etiquette on my part! Sorry in advance.</font></div>
</div></div>