You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.4 KiB
2.4 KiB
Clang Front-End
This is the front-end for the clang compiler.
The main entry point is ClangWrapper
.
General structure
- Given a compilation command from the build system, sanitize it, attach
ASTExporter
clang plugin to the relevant commands and run it. - Parse the AST from Biniou format to OCaml data structure.
- (optional) Invoke translation to
SIL
viaCFrontend
. - (optional) Invoke linters via
CFrontend_checkers_main
. More on linters
Format of the AST
OCaml data structure is defined in atd
format. The clang_ast_t.atd
file is generated from comments in ASTExporter.h file.
For more information, refer to the relevant documentation in facebook-clang-plugins
:
Hacking on .atd
file
- Create a simple example (
example.cpp
) source file with construct that needs to be exported. The smaller the better. - Export extra information by changing code in
libtooling/ASTExporter.h
. For more information, refer to the ATD_GUIDELINES. - Compile Infer with the new version of
facebook-clang-plugins
. Runningmake all
from top level of Infer repository will do that. Sometimes there may be compilation errors due to.atd
file changes - they need to be fixed. - Use newly exported information information in the frontend.
Tips & Tricks:
- To view the AST in a human readable version, Infer can generate
.bdump
file:infer -g -- clang -c example.cpp && sh example.cpp.ast.sh
. Then openexample.cpp.ast.bdump
- To inspect ast dump visually:
clang -c example.cpp -Xclang -ast-dump
. It doesn't include all the information that Infer sees, but it's pretty concise - If running
bdump
is failing (it happens on huge sources sometimes), there is a way to view it in "Yojson" format. To do that, replace all occurrences ofBiniouASTExporter
withYojsonASTExporter
in.ast.sh
script.