AST for multiple source files with clang

I am doing interprocedural data flow analysis using clang. I am currently using libtooling to parse the source files and invoke the visitor AST. The question is how to create one AST for multiple .c files?

I tried using the ASTImport class, but does not support importing some AST nodes. Moreover, I am doing something wrong when I create and process CompilerIstance, and it crashes in the destructor.

A very similar option was ASTImportAction, but it is not entirely clear to me which command-line options should be passed to ClangTool in this case.

The third option is to create ASTUnits for each .c file and look for definitions in each of them, it is unclear how to find a correspondence between the types of user definitions, for example. records. At ASTImport, they use the IsStructurallyEquivalent () function, but are declared in an anonymous namespace, so I can copy all this code into my program. Again, it does not support all AST nodes.

From the Internet, this link http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-August/023865.html seems most appropriate, but for me the technical details of the solution are not clear.

Any suggestions are welcome. Many thanks.

+8
c clang static-analysis abstract-syntax-tree
source share
1 answer

I tried to do something like this. However, I did not try to create a single AST. I parsed several ASTs and tried to display the functions myself. I use AST to get function calls, and then test them in other ASTs.

I am using the compile_commands.json file to provide a list of source files. OptionsParser.getCompilations (). GetAllFiles () can get all the source files specified in the compile_commands.json file.

When we create clangTool and run frontendAction on the tool with our helper, it looks for a match in all the source files.

There may be a better way to do this. If anyone knows about this, indicate this.

0
source share

All Articles