[cfe-dev] Access to template parameters via libclang
Vinay Sajip
vinay_sajip at yahoo.co.uk
Sun Nov 24 11:07:17 PST 2013
I'm having some trouble trying to access template parameter types using
libclang. Given the source:
template <typename T>
class List {
public:
T at(int i);
};
class Client {
public:
List<Client> childList();
List<int> intList();
};
Navigating the AST with libclang gives the following tree, with each node
annotated with spelling, kind, type and result type:
<TU>
List:ClassTemplate:Invalid:Invalid
T:TemplateTypeParameter:TemplateTypeParm:Invalid
<empty>:CXXAccessSpecifier:Invalid:Invalid
at:CXXMethod:FunctionProto:TemplateTypeParm
T:TypeRef:TemplateTypeParm:Invalid
i:ParmDecl:Int:Invalid
Client:ClassDecl:Record:Invalid
<empty>:CXXAccessSpecifier:Invalid:Invalid
childList:CXXMethod:FunctionProto:TemplateSpecialization
List:TemplateRef:Invalid:Invalid
class Client:TypeRef:Record:Invalid
intList:CXXMethod:FunctionProto:TemplateSpecialization
List:TemplateRef:Invalid:Invalid
count:CXXMethod:FunctionProto:Int
Note that the subtree for the childList method helpfully has a TypeRef child
which tells us the return type is List<Client>, but the subtree for intList,
while it tells us that the return type is List<>, has no TypeRef node to
indicate exactly how List is specialized. What is the way to get the
specialization type when it is not a class?
Regards,
Vinay Sajip
More information about the cfe-dev
mailing list