#ast #clang #libclang #syntax-tree #tree-node #static-analysis #ctree

bin+lib c3

Complete C AST. Enables analysis and generation of code derived from C. Built using LLVM 4/Clang using some fragile C++ APIs to work around missing data and ambiguities in libclang.

13 releases (7 breaking)

0.11.2 Oct 22, 2023
0.11.0 Sep 20, 2017
0.10.0 Sep 16, 2017

#2250 in Parser implementations

48 downloads per month
Used in citrus

NCSA AND BSD-3-Clause

520KB
14K SLoC

Bitbake 9K SLoC // 0.0% comments Rust 3.5K SLoC // 0.0% comments C++ 1K SLoC // 0.1% comments C 297 SLoC

C3: A tree of C nodes

This crate parses C files and exposes them as an abstract syntax tree.

The AST is a relaxed version of C's usual structure (e.g. everything pretends to be an expression), but contains enough information to rebuild complete source code. The AST also allows for some Rust features not found in C files. This is enables Citrus to convert C to Rust.

It uses LLVM and Clang's unstable C++ API. Currently, it supports LLVM 4 or 5, and requires static linking with libclang.

The stable Clang API does not expose a real AST, but a flattened, incomplete and ambiguous view of it. This crate works around the bad parts to extract more complete view of C files from Clang.

On the Rust side it's based on bindgen.

Building

Follow these instructions.

Dependencies

~210–425KB