[cfe-dev] CXCursor_CXXBaseSpecifier for template instantiated base class

Michael via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 16 14:14:31 PDT 2017


> On 16 Mar 2017, at 21:05, Jusufadis Bakamovic <jbakam at gmail.com> wrote:
> 
> How come? This is the AST representation of that piece of code (reads as CursorKind : CursorSpelling)

Well, yes, and no. In this particular case you can do the mapping. One could also use clang_Type_getTemplateArgumentAsType. But you loose this relation if you go a bit further, like: 

template <typename BaseType>
class BaseTemplate : public BaseType
{
 void bar(BaseType arg1);
}

template <typename BaseType>
class RecursiveBase : public BaseTemplate<BaseType>
{
 void foo(BaseType arg2);
}

You also want to know that the specialised parameter of “BaseTemplate" is “Base”
And you also want to know that arg1 and arg2 of the specialised “RecursiveBase” are of type “Base”
The methods are only accessible through the referenced raw template (ClassTemplate?), where you only have the raw template parameters.
It’s still possible to figure out the types in this case, yes, but it gets more and more cumbersome in the more general cases.

With a cursor directly at the specialised version of the template everything would already be resolved, readily usable. As you can see when dumping the tree with commandline clang. It seems just that libclang does not expose that information.

I was able to get this information with clang_getSpecializedCursorTemplate for partially specialised templates. But not for any other kind of specialisation. In those cases the function returns just a null cursor.

I might be missing something, though...

Michael

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170316/859820dd/attachment.html>


More information about the cfe-dev mailing list