Parsing .cpp implementation?
I'd like to parse .cpp files, mainly so I can associate declaration with implementation and add links to each in documentation.
I tried running ParseFile(myCpp), which works but basically gives me the same as parsing the header, plus free functions local to the cpp. The classes/methods' locations still point to the header declaration, which I suppose I should have seen coming.
I suppose the elements would need locations for both declaration and implementation in the same element. Is there a way to achieve this, or am I thinking about it wrong?
Is there a way to achieve this, or am I thinking about it wrong?
Unfortunately, CppAst has been designed to mainly parse headers for codegen/interop scenarios. So, it took some shortcuts that are not replicated in the model, like the re-declarations that can happen in C/C++ or the couple declarations/definiton. It could be possible to adapt it but it is likely quite some work (being additive, without breaking the existing model).
Unfortunately, the code for processing the AST tree CppModelBuilder.cs has grown organically (because it was difficult to understand the form of the libclang AST) and is a bit awful to work with, sometimes also to work around limitations of libclang C api. So, I dunno, you could try to make changes and see how it goes, but you might hit some struggles.
Thanks for your answer, interop is how we're using it as well so I get it, as I said my usecase is documentation so it's low-priority. At least your answer gives me an idea of what I'd get into if I ever try to do it :) !
So, best thing I could do at the moment was generate a regular expression from the header signature, and look for that in the .cpp. It gets ugly fast at there could be any number of subtle (text) differences between declaration and implementation, but that mostly does the job I needed it for.
Side-note: what's the state of this repo, are you accepting PRs? We have a few fixes sitting in our fork... (eg field Offset for unions)