A simple C++ version clang AST visitor modified from screader (author: shining1984).
-
Clang
installation is necessary.- You can follow Clang official document to install
Clang
step by step. - After successfully build
Clang
, you must domake install
to install.
- You can follow Clang official document to install
-
And then you can build
clang-AST-cursor-traveler
.
git clone https://github.com/dyhe83/clang-AST-cursor-traveler.git --depth=1
cd clang-AST-cursor-traveler
sh build.sh
cd build
./traveler <filename> The traveler will output all the AST nodes' information.
./traveler <filename> <keyword> The traveler will output the AST nodes' matched the keyword.
$ cd build
$ cat ../test/HelloWorld.c
#include <stdio.h>
int main() {
printf("Hello world.\n");
return 0;
}
$ ./traveler ../test/HelloWorld.c printf
The AST node kind spelling is: FunctionDecl
The AST node spelling is: printf
Start Line: 318 Column: 1 Offset: 9869
End Line: 318 Column: 57 Offset: 9925
The AST node kind spelling is: CallExpr
The AST node spelling is: printf
Start Line: 4 Column: 5 Offset: 40
End Line: 4 Column: 29 Offset: 64
The AST node kind spelling is: UnexposedExpr
The AST node spelling is: printf
Start Line: 4 Column: 5 Offset: 40
End Line: 4 Column: 11 Offset: 46
The AST node kind spelling is: DeclRefExpr
The AST node spelling is: printf
Start Line: 4 Column: 5 Offset: 40
End Line: 4 Column: 11 Offset: 46