I am working on generating an AST for a given source code. I am using the tool Bear (https://github.com/rizsotto/Bear) to capture the make commands in order to generate the compilation database. Analyzing the database I find multiple compile commands for the same source file with different arguments. Reviewing further it uses different command arguments to compile the source file. Hence for each compile command, I get different AST. I am using ClangTool::buildASTs() method to generate the ASTs.
How can I merge these multiple ASTs generated from the same code? Is it possible to just create all the AST’s and create the final AST? or any other method to aggregate?
Any help in this regard is highly appreciated.
Analyzing the database I find multiple compile commands for the same source file with different arguments
I don't know the details of your case, but generally there are two
major cases for this:
1) build both for shared libs (-fpic) and static libs
2) build for different architectures/platforms
In the case of 1), the AST of the translation units will be the same.
Also, you could configure your project to build only one variant, e.g.
the -fpic version.
In the case of 2), the ASTs might be essentially different, so there
is no sense to merge them, you have to pick one and work with that.
Hope this helps,
Thank you for the explanation, so if I need to modify a function for a particular AST I need to build all possible AST’s and check one-by-one? no other possibility?
For example, if I need to update a function but I’m not sure in which AST it would appear, I need to create all and check?
Thank you for your help