## Library infer

These are the modules used by infer that are not packaged into sub-libraries.

The entry point of this library is the module: InferModules.

The modules are split into several directories in the source tree of infer.

### absint/

Code + utilities for the Infer.AI abstract interpretation framework. Start at InferModules.AbstractInterpreter.

### backend/

The backend is responsible for the analysis of a project starting from an intermediate representation stored in the results directory, typically `infer-out`.

The entry point for the analysis is the module InferModules.InferAnalyze.

The module InferModules.InferPrint is used to export the analysis results.

### checkers/

Transfer functions, abstract domains, and checker configuration.

### clang/

This is the frontend for the clang compiler. The main entry point is InferModules.ClangWrapper.

#### General structure

1. Given a compilation command from the build system, sanitize it, attach `ASTExporter` clang plugin to the relevant commands and run it.
2. Parse the AST (Abstract Syntax Tree) from the Biniou format into an OCaml data structure.
3. If enabled, invoke translation to `SIL` via InferModules.CFrontend.
4. If enabled, invoke linters via InferModules.CFrontend_checkers_main. More on linters here: http://fbinfer.com/docs/linters.html.

#### Format of the AST

The OCaml data type is defined in `atd` format. The `clang_ast_t.atd` file is generated from the comments in the `ASTExporter.h` file.

For more information, refer to the relevant documentation in `facebook-clang-plugins`:

- `libtooling/ATD_GUIDELINES.md`
- `clang-ocaml/README.md`

#### Hacking on the `.atd` file

1. Create a simple example (`example.cpp`) source file with construct that needs to be exported. The smaller the better.
2. Export the extra information by changing the code in `libtooling/ASTExporter.h`. For more information, refer to the `ATD_GUIDELINES`.
3. Compile Infer with the new version of `facebook-clang-plugins`. Running `make` 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.
4. 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 open `example.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 of `BiniouASTExporter` with `YojsonASTExporter` in the `.ast.sh` script.

### eradicate/

Eradicate `@Nullable` Checker

Eradicate is a type checker for `@Nullable` annotations for Java. The goal is to eradicate null pointer exceptions. See the online docs at http://fbinfer.com/docs/eradicate.html.

The main entry point is module InferModules.Eradicate.

### java/

Java Frontend; this is the frontend for Java compilers.

The main entry point is InferModules.JMain.

### infer executable

You'll find the infer binary in infer.ml. It is not part of this library.