Technical requirements
This chapter expects that you have a build of the clang
executable. If you don't, please build it using the following command:
$ ninja clang
In addition, you can use the following command-line flag to print out the textual representation of AST:
$ clang -Xclang -ast-dump foo.c
For example, let's say foo.c
contains the following content:
int foo(int c) { return c + 1; }
By using the -Xclang -ast-dump
command-line flag, we can print out AST for foo.c
:
TranslationUnitDecl 0x560f3929f5a8 <<invalid sloc>> <invalid sloc> |… `-FunctionDecl 0x560f392e1350 <foo.c:2:1, col:30> col:5 foo 'int (int)' |-ParmVarDecl 0x560f392e1280 <col:9, col:13> col:13 used c 'int' `-CompoundStmt 0x560f392e14c8 <col:16, col:30> `-ReturnStmt 0x560f392e14b8 <col:17, col:28> `-BinaryOperator 0x560f392e1498 <...