-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++ API gen with macros #386
Comments
Hmm, sounds like a bug in the api_parser. With libclang we had to crawl the entire AST and extract doc comments from lone comment tokens (with special considerations). Libclang's default behavior only identifies a comment as a doc comment if it directly precedes the symbol in question. We might need to strengthen the parser by differentiating between declaration token and invocation token. I haven't looked at the parser code in a while though. PS - Sphinx' C and C++ domains leave a lot to be desired (they are rather isolated from each other). The Sphinx devs that contributed those parts are rarely active in development nowadays. For example, this theme applies patches to help automatically cross-reference symbols in the C domain from signatures in the C++ domain. |
I didn't think about this issue previously, but the way that it can be made to work is to first preprocess with I don't know if libclang provides a way to access the tokens produced from preprocessing rather than just the input tokens. |
@jbms these option definitely help, and with those the documentation can be extracted. However, there is still an odd thing happening. Although the macro is expanded, its value ( |
I intentionally excluded inline since I considered it an implementation detail that doesn't belong in the documentation:
However, I suppose we could add an option to control that behavior. |
I tried to use the c++ documentation generation on a codebase that has some macros in it, but the sphinx build failed. Mostly macro usage of the form
could not be handled. I've added a similar macro to the demo here: https://github.com/MarcelKoch/sphinx-immaterial/tree/cpp-api-with-macro.
I think there are two underlying issues here. AFAIK, sphinx doesn't really support macros in function declarations. So the rst syntax
would already be invalid.
Second, the internal parsing seems to be a bit messed up, or at least the behavior of libclang is unexpected. For the modified demo I get the following error:
After playing around with the debugger, I've noticed that the tokenization of the source location of the function somehow includes the complete source code between the macro definition and the macro usage.
One solution would be to run the preprocessor on the input file, however this would also remove other macros, which I would like to document.
The text was updated successfully, but these errors were encountered: