CastXML / pygccxml

pygccxml is a specialized XML reader that reads the output from CastXML or GCCXML. It provides a simple framework to navigate C++ declarations, using Python classes.
Boost Software License 1.0
131 stars 45 forks source link

templates: Allow accessing parsed template declarations (classes / functions) w/o instantiations? #121

Closed EricCousineau-TRI closed 4 years ago

EricCousineau-TRI commented 4 years ago

TL;DR

What's necessary to extend pygccxml to recognize template classes / functions? Does CastXML already recognize them, and is just a matter of parsing API?


Background

In https://github.com/RobotLocomotion/drake/pull/13671 (issue https://github.com/RobotLocomotion/drake/pull/13670), I'm spike testing replacing our usage of libclang with pygccxml.

This is my way of spike-testing the ability of pygccxml to either bootstrap our current bindings in Drake, or completely automate them, and minimize the amount of enumeration needed (https://github.com/RobotLocomotion/drake/issues/7889)

With libclang, we were able to let libclang discover template declarations for us. As an example, sample input file: https://github.com/RobotLocomotion/drake/blob/0d219dbc2642ce6f9c8120cb5839ac87a5bc637d/tools/workspace/pybind11/test/sample_header.h#L201-L238 Sample output of mkdoc.py: https://github.com/RobotLocomotion/drake/blob/0d219dbc2642ce6f9c8120cb5839ac87a5bc637d/tools/workspace/pybind11/test/sample_header_documentation.expected.h#L261-L277

However, for our use case, we really want the generic template declaration information, not inf

With pygccxml

In this case, it's clear that we don't get the documentation for the specialization. From this comment: https://github.com/RobotLocomotion/drake/pull/13671#issuecomment-657138688 We get this output: https://gist.github.com/EricCousineau-TRI/8da1ad7963fa58315db5852488e18922#file-drake_issue13670_pygccxml_mkdoc_output-txt-L805-L874

And of course, that's mentioned in the pygccxml docs: https://pygccxml.readthedocs.io/en/master/examples/templates/example.html

\cc @jamiesnape @josephsnyder

EricCousineau-TRI commented 4 years ago

From current CastXML source, seems like it doesn't emit the generic template info at present? https://github.com/CastXML/CastXML/blob/8625aed52c8e2e0b94cfd65767a7564a36ce4c96/test/input/Class-template.cxx https://github.com/CastXML/CastXML/blob/8625aed52c8e2e0b94cfd65767a7564a36ce4c96/test/expect/castxml1.any.Class-template.xml.txt

EricCousineau-TRI commented 4 years ago

Filed upstream issue: https://github.com/CastXML/CastXML/issues/171

iMichka commented 4 years ago

As discussed in https://github.com/CastXML/CastXML/issues/171, we do not provide this right now. I'll close this issue, as the first step would be to add this capability to castxml. Once this is done, we can think about how to add it to pygccxml.