3 ms·
It’d be great if you wanted to try wrapping clang tools directly! Since Nim can wrap C++ code so it might take some manual effort to wrap enough clang to be use
by elcritch 5y ago
It’d be great if you wanted to try wrapping clang tools directly! Since Nim can wrap C++ code so it might take some manual effort to wrap enough clang to be useful, but for just getting an AST shouldn’t be too much work. Doesn’t clang also have an option to output JSON/XML of the C++ code?
Though I’ve had good luck with just c2nim. But as you mention it’ll break on some corner cases things, so I just tweak the C a bit (remove function attributes, etc) then retry. However, c2nim was recently updated and fixed a bunch of C99 things. I haven’t had to do that in a while.
- gavinray 5y agoClang can dump the AST to JSON but there are some headaches when it comes to things like specialization or other circumstances. If you wanted to go this route, using ClangSharp's XML output would probably be easier because it's been tailored to extract the "useful" bits and to expose some of the info that is hard to get at from a raw AST dump