<div dir="ltr">Hi Nestal,<div><br></div><div>I am not sure if I understood you correctly but you want to find out the structure/hierarchy of your "Derived" class, that is all of the base classes that your derived class is inheriting from? If this is what you are asking for, then you can accomplish this by enumerating all of the `CXCursor_TypeRef`'s of corresponding `<span style="color:rgb(0,0,0);white-space:pre-wrap">CXCursor_CXXBaseSpecifier</span>`<span style="color:rgb(0,0,0);white-space:pre-wrap"> cursors which are descendants (children) of class declaration (</span>`<span style="color:rgb(0,0,0);white-space:pre-wrap">CXCursor_ClassDecl</span>`<span style="color:rgb(0,0,0);white-space:pre-wrap">) which you're interested in (i.e. "</span>Derived"<span style="color:rgb(0,0,0);white-space:pre-wrap">).</span></div><div><br></div><div>When parser is run on your example, <span style="color:rgb(0,0,0);white-space:pre-wrap">`</span><span style="color:rgb(0,0,0);white-space:pre-wrap">CXCursor_CXXBaseSpecifier</span><span style="color:rgb(0,0,0);white-space:pre-wrap">`</span><span style="color:rgb(0,0,0);white-space:pre-wrap"> cursors are `</span>RecursiveBase<class Base><span style="color:rgb(0,0,0);white-space:pre-wrap">`</span>, <span style="color:rgb(0,0,0);white-space:pre-wrap">`</span>class Base2<span style="color:rgb(0,0,0);white-space:pre-wrap">`</span> and <span style="color:rgb(0,0,0);white-space:pre-wrap">`</span>class Base3<span style="color:rgb(0,0,0);white-space:pre-wrap">`. Corresponding </span><span style="color:rgb(0,0,0);white-space:pre-wrap">`CXCursor_TypeRef</span><span style="color:rgb(0,0,0);white-space:pre-wrap">` cursors are </span><span style="color:rgb(0,0,0);white-space:pre-wrap">`</span><span style="color:rgb(0,0,0);white-space:pre-wrap">class Base</span><span style="color:rgb(0,0,0);white-space:pre-wrap">`, </span><span style="color:rgb(0,0,0);white-space:pre-wrap">`</span><span style="color:rgb(0,0,0);white-space:pre-wrap">class Base2</span><span style="color:rgb(0,0,0);white-space:pre-wrap">` and </span><span style="color:rgb(0,0,0);white-space:pre-wrap">`</span><span style="color:rgb(0,0,0);white-space:pre-wrap">class Base3</span><span style="color:rgb(0,0,0);white-space:pre-wrap">`. This is what I believe you're looking for.</span></div><div><br></div><div>For a generic and full-proof solution, you will want to do the same thing recursively for each `<span style="color:rgb(0,0,0);white-space:pre-wrap">CXCursor_CXXBaseSpecifier` found.</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"><br></span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap">Cheers,</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap">Adi<br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 14 March 2017 at 17:39, Nestal Wan <span dir="ltr"><<a href="mailto:me@nestal.net" target="_blank">me@nestal.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="im HOEnZb">Thanks Adi,<br>
<br>
Like you said, I solve the problem by fixing the errors that were<br>
indicated by the diagnostic messages.<br>
<br>
Now I have another question, if you don't mind I keep using this thread.<br>
<br>
I wish know the class hierarchy of "Derived". That means getting the<br>
base class the the instantiated RecursiveBase<Base> template. That<br>
should be "Base".<br>
<br>
When I visit "Dervied", I got a cursor to a CXCursor_CXXBaseSpecifier.<br>
I tried to get the type by:<br>
<br>
CXType recursive_base =<br>
clang_getCursorType(clang_<wbr>getCursorDefinition(cxx_base_<wbr>specifier));<br>
<br>
"recursive_base" refers to the RecursiveBase<Base> instantiation. How<br>
can I get the base type of this class? I know I can get the cursor to<br>
the template that instantiate it (i.e. template <typename BaseType><br>
RecursiveBase), and I can see it inherits "BaseType" by visiting it<br>
and look for CXCursor_CXXBaseSpecifier. But how can I know "BaseType"<br>
will become "Base" when we instantiate it? Will the CXType provides me<br>
this linkage or I need to use LibTooling instead?<br>
<br>
Thanks again.<br>
<br>
</span><span class="HOEnZb"><font color="#888888">Nestal<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Sun, Mar 12, 2017 at 9:25 PM, Jusufadis Bakamovic <<a href="mailto:jbakam@gmail.com">jbakam@gmail.com</a>> wrote:<br>
> It is hard to tell without more context why you're getting this error, but<br>
> my guess is that you're missing some command line args (i.e. include paths,<br>
> preprocessor flags, etc.) which is specific to the code you're analyzing and<br>
> which is required in order to get the parsing stage done right. Very often<br>
> this is the case and which is why you should, whenever you have doubts,<br>
> always try to come up with a small reproducible example (without<br>
> dependencies) and have it validated separately.<br>
><br>
> Additionally, you can try to extract diagnostics for the given translation<br>
> unit and see if you get any hints there. Normally, you should get hints if<br>
> clang parser was not able to fully parse the source code because it was<br>
> missing some information such as failing to find particular headers.<br>
><br>
> Cheers,<br>
> Adi<br>
><br>
> On 12 March 2017 at 10:13, Nestal Wan <<a href="mailto:me@nestal.net">me@nestal.net</a>> wrote:<br>
>><br>
>> Thanks for the reply.<br>
>><br>
>> -CXXRecordDecl 0x55e6db0f5ad8 <line:53:1, line:59:1> line:53:7 invalid<br>
>> class<br>
>> Derived definition<br>
>><br>
>> | |-public 'class Base2'<br>
>> | |-public 'class Base3'<br>
>> | |-CXXRecordDecl 0x55e6db0f5df8 <col:1, col:7> col:7 implicit referenced<br>
>><br>
>> class Derived<br>
>><br>
>> | |-AccessSpecDecl 0x55e6db0f5e88 <line:55:1, col:7> col:1 public<br>
>> | |-CXXConstructorDecl 0x55e6db0f5ef0 <line:56:2, col:20> col:2 Derived<br>
>> 'void<br>
>><br>
>> (void)' noexcept-unevaluated 0x55e6db0f5ef0<br>
>><br>
>> | `-CXXMethodDecl 0x55e6db0f5fd0 <line:58:2, col:24> col:7 Func 'void<br>
>> (void)'<br>
>> | `-CompoundStmt 0x55e6db0f6118 <col:23, col:24><br>
>><br>
>><br>
>> Sometimes I got "invalid class Derived definition", but if I extract the<br>
>> classes in another source file, the result is different:<br>
>><br>
>> |-CXXRecordDecl 0x55ccfcb583b0 <line:33:1, line:39:1> line:33:7 class<br>
>> Derived<br>
>><br>
>> definition<br>
>><br>
>> | |-public 'RecursiveBase<class Base>':'class RecursiveBase<class Base>'<br>
>> | |-public 'class Base2'<br>
>> | |-public 'class Base3'<br>
>> | |-CXXRecordDecl 0x55ccfcb58c70 <col:1, col:7> col:7 implicit referenced<br>
>><br>
>> class Derived<br>
>><br>
>> What does it mean the class definition is invalid? There is no compile<br>
>> error.<br>
>><br>
>> Nestal<br>
>><br>
>> On Sun, Mar 12, 2017 at 4:46 PM, Jusufadis Bakamovic <<a href="mailto:jbakam@gmail.com">jbakam@gmail.com</a>><br>
>> wrote:<br>
>> > You should be getting three times the `CXCursor_CXXBaseSpecifier`, one<br>
>> > for<br>
>> > each class you're inheriting from. I ran the analysis on my machine<br>
>> > (clang<br>
>> > 3.8) and that is exactly what I am getting: `RecursiveBase<class Base>`,<br>
>> > `Base2`, `Base3`. Maybe you could use `clang -Xclang -ast-dump<br>
>> > -fsyntax-only<br>
>> > <this_demo>` to see the output of Clang's built-in AST dumper. It should<br>
>> > contain these entries. Otherwise, clang version you're running might be<br>
>> > an<br>
>> > older one.<br>
>> ><br>
>> > On 12 March 2017 at 05:09, Nestal Wan via cfe-dev<br>
>> > <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>><br>
>> > wrote:<br>
>> >><br>
>> >> Hi,<br>
>> >><br>
>> >> When I use clang_visitChildren() to visit a class, I can't get a<br>
>> >> CXCursor_CXXBaseSpecifier for its base class if the base class is a<br>
>> >> template. For example:<br>
>> >><br>
>> >> template <typename BaseType><br>
>> >> class RecursiveBase : public BaseType<br>
>> >> {<br>
>> >> public:<br>
>> >>    virtual void SomeFunc()<br>
>> >>    {<br>
>> >>       // prevent optimizer to remove the function<br>
>> >>       global_var++;<br>
>> >>    }<br>
>> >> };<br>
>> >><br>
>> >> class Derived : public RecursiveBase<Base>, public Base2, public Base3<br>
>> >> {<br>
>> >> public:<br>
>> >>    Derived() = default;<br>
>> >><br>
>> >>    void Func() override {}<br>
>> >> };<br>
>> >><br>
>> >> I can get a CXCursor_CXXBaseSpecifier cursor as children of the<br>
>> >> "Derived" cursor, but not RecursiveBase. How can I find out references<br>
>> >> to all base classes including templates?<br>
>> >><br>
>> >> Thanks.<br>
>> >><br>
>> >> Nestal<br>
>> >> ______________________________<wbr>_________________<br>
>> >> cfe-dev mailing list<br>
>> >> <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
>> >> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
>> ><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br></div>