[cfe-dev] accessing template arguments from libclang

Geoffrey Irving irving at naml.us
Tue Aug 13 12:26:45 PDT 2013


I am trying to parse the following code with the Python interface to
libclang (full listing attached):

    class Toaster : Base<int,7> { ... };

Unfortunately, traversing cursors via getChildren gives me the following
tree (see clang_dump() in autodescribe.py for the code that generated this
tree):

CLASS_DECL Toaster
  CXX_BASE_SPECIFIER None : Base<int,7>
    TEMPLATE_REF None : Base
    INTEGER_LITERAL None : 7
  CXX_ACCESS_SPEC_DECL  PUBLIC : public:
  ...

The base specifier only seems to mention "Base" and "7", not "int".  Should
I be able to fully inspect Base<int,7> using cursors?

I also tried traversing the Type object corresponding to Base<int,7>, but I
don't see any methods for accessing template parameters either in
libclang's Python bindings or in the original C.  If I'm correct that the
functionality is missing from the C layer, what's the easiest way to add
it?  The C++ structure of template references seems quite complicated (I
imagine by necessity :)).

Background: I'm working on a clang-based front end for the xdress Python
binding generator project.  I've already made a couple minor improvements
to the libclang Python bindings (exposing formatDiagnostic and the details
of access specifiers), and am happy to contribute these back once I'm done.

Thanks for any suggestions!
Geoffrey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130813/cdf0d406/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: toaster.h
Type: text/x-chdr
Size: 781 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130813/cdf0d406/attachment.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: autodescribe.py
Type: application/octet-stream
Size: 78604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130813/cdf0d406/attachment.obj>


More information about the cfe-dev mailing list