Skip to content

dyhe83/clang-AST-cursor-traveler

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ version clang AST visitor

A simple C++ version clang AST visitor modified from screader (author: shining1984).

How to build

  1. Clang installation is necessary.

    1. You can follow Clang official document to install Clang step by step.
    2. After successfully build Clang, you must do make install to install.
  2. 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

How to use

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.

Example

$ 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

Releases

No releases published

Packages

No packages published

Languages

  • C++ 75.6%
  • CMake 21.3%
  • C 2.1%
  • Shell 1.0%