-
Notifications
You must be signed in to change notification settings - Fork 169
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
Clang JSON parser #120
Comments
Thanks for looking into it; I plan on starting it in May.
Does it support comments?
simdjson/simdjson#8 seems to indicate that you can specify it for simdjson.
If you could do PRs that could be great. I think it would be best if I do the necessary infrastructure changes first and then we can both work on adding parsers for specific declarations? |
Yes, the following code produces this hierarchy:
// Some normal comment. Not included in the JSON AST
/// \brief Does foo
/// Some more details
void foo();
Exactly what I was thinking. |
I have implemented the basics of a Over the next weeks I will add more and more implementations; let me know what you want to tackle or if you have any questions. |
Current status:
(Checked doesn't mean "works 100%", but "mostly works"). |
Hi Jonathan,
I've been looking into the clang JSON output you mentioned in the standardese issue #195 for the last couple of days. Since I have no glue how deep your own research to this topic has gone, I just wanted to share the experiences I've made.
Limitations
Preprocessor
The clang JSON output is produced after the preprocessor has run, so we won't be able to create entities like
cpp_macro_definition
,cpp_macro_parameter
andcpp_include_directive
unfortunately. I've tried to find a tool from the LLVM ecosystem that provides more output concerning the processor, but was unable to find anything useful. Thepp-trace
looked promising, but unfortunately runningpp-trace-12 --callbacks='*' /path/to/file.hpp
did not generate anything useful.Nested Namespaces
Each namespace shows up as it's own entity in the JSON document, so we would need to match the line numbers to see if it is a nested namespace declaration.
Semantic Parent
Similar to the namespace above, we would need to track this manually. I'm not familiar enough with libclang yet to tell if this is going to be a minor or major challenge for the JSON parser.
JSON conformance
Both Boost.JSON and simdjson follow the JSON standard exactly. This means there is a nesting limit of 32 objects. Boost.JSON has parsing options to change this behavior, I haven't found those settings for simdjson yet, so I'm not sure if they can be changed. I've created a couple of test source files to see how big the resulting .json files get. When you include all STL headers and run the command:
clang++ -Xclang -ast-dump=json -std=c++17 stl_headers.hpp > test.json
the resulting file is 550mb. To successfully parse theetl/string.hpp
header that is mentioned in the standardese issues I had to up the nesting limit before parsing.Results So Far
I've successfully parsed
cpp_enum
&cpp_enum_value
entities using the Boost.JSON parser. I definitely need to do more tests before I can tell how much work the complete parser is going to be. Switching to simdjson once I really start working on pull requests should not be an issue. Both libraries seem to provide similar APIs. I used Boost for the testing, because I've been working with it the last couple of months. I think simdjson is a very valid option as well, I don't really have any preferences, but I think the selection should be based on performance metrics first, since the files that need to be parsed can get huge.Toby
The text was updated successfully, but these errors were encountered: