You can also use getType()->getAsCXXRecordDecl(), which is a little more convenient and also copes with the obscure case of deriving from the injected-class-name within a class template.<br><br><div class="gmail_quote">
On Mon, May 13, 2013 at 8:20 AM, Justin Arruda <span dir="ltr"><<a href="mailto:paradoxum@gmail.com" target="_blank">paradoxum@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I want to retrieve the Decl so that I may use its isDerivedFrom<br>
method.  I know that my target class is derived from class A.  I am<br>
trying to determine which base of class is derived from class A.<br>
<br>
My main misunderstanding was not knowing how Decls and Types are<br>
related.  I believe your solution of using getAs and getDecl is<br>
precisely what I was looking for!<br>
<br>
Thanks<br>
--<br>
Justin Arruda<br>
<a href="tel:401.338.4310" value="+14013384310">401.338.4310</a><br>
<a href="http://justinarruda.com/" target="_blank">http://justinarruda.com/</a><br>
<a href="http://www.linkedin.com/in/justinarruda" target="_blank">http://www.linkedin.com/in/justinarruda</a><br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Mon, May 13, 2013 at 8:55 AM, Sebastian Redl<br>
<<a href="mailto:sebastian.redl@getdesigned.at">sebastian.redl@getdesigned.at</a>> wrote:<br>
><br>
> On 13.05.2013, at 06:15, Justin Arruda wrote:<br>
><br>
>> 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<br>
>> implies. I have a CXXRecordDecl,<br>
>> and I am trying to determine which of its bases is derived from a<br>
>> class that I know this CXXRecordDecl<br>
>> is also derived from.<br>
>><br>
>> i.e.<br>
>> class A;<br>
>> class B : public A;<br>
>> class C;<br>
>><br>
>> class D : public B, public C<br>
>> 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<br>
>> 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<br>
>> inheritance of Colossus::MyBase,<br>
>> I've tried the following strategy: Obtain the type of the base<br>
>> specifier, and using an appropriate<br>
>> DeclContext, look up the declaration.  Once I have the declaration, I<br>
>> can use its methods to determine if<br>
>> it's derived from Colossus::MyBase (or is that class).<br>
>><br>
>> // Get the qualified name of the base<br>
>> QualType type = aBaseSpecifier->getType();<br>
>> DeclarationName baseDeclName( type.getBaseTypeIdentifier() );<br>
>><br>
>> // Grab a context to look up the decl<br>
>> const DeclContext* lookupContext = theCxxRecordDecl->getLookupContext();<br>
>><br>
>> DeclContext::lookup_const_result lr = lookupContext->lookup(baseDeclName);<br>
><br>
> Looking up the name of the type is too complicated. Also, why do you want the decl? If you want to compare for equality, the type is more interesting.<br>
><br>
> In any case, the QualType returned by CXXBaseSpecifier::getType() will always (perhaps unless you're dealing with a template definition) be a RecordType underneath; just use type->getAs<RecordType>() to get the RecordType. Then you can use getDecl() on the result, which returns a RecordDecl, but in C++ every RecordDecl is a CXXRecordDecl, so you can just cast<CXXRecordDecl> it.<br>

><br>
> Sebastian<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br>