Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Conveniently explore the Clang abstract syntax tree

License

NotificationsYou must be signed in to change notification settings

ahueck/astprinter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

astprinter is a command-line tool for exploring the Clang abstract syntax tree (AST). It is designed to simplify retrieving specific AST nodes by specifying line numbers from C/C++ source code.

Features

  • Retrieve AST nodes corresponding to specific lines of C/C++ source code.
  • Use regular expressions to match function names and display the AST nodes for their declarations or definitions.

Usage

Seemain.cpp for all possible command-line arguments.

Example of usingastprinter

Assumetest.c contains the code:

1intfoo () {2return2;3  }4intmain() {5intval;6val=foo();7return0;8  }

Using astprinter on test.c

In this example we

  1. loadtest.c with standard Clang flags,
  2. list all function declarations intest.c,
  3. print the AST definition of foo, and finally,
  4. print the AST of the return statement in line 2.
ahueck@sys:~/astprint/install$./bin/astprinter ../test.c --ast-printer> lfoo:~/astprint/install/../test.c:1:3->3:4main:~/astprint/install/../test.c:4:3->8:4ast-printer> p fooFunctionDecl 0x3977120 <test.c:1:3, line:3:3> line:1:7 used foo 'int ()'`-CompoundStmt 0x3977238 <col:14, line:3:3>  `-ReturnStmt 0x3977220 <line:2:7, col:14>    `-IntegerLiteral 0x3977200 <col:14> 'int' 2~/astprint/install/../test.c:1:3->3:4ast-printer> 2ReturnStmt 0x1ba3220 <test.c:2:7, col:14>`-IntegerLiteral 0x1ba3200 <col:14> 'int' 2~/astprint/install/../test.c:2:7->2:15

How to build

Requirements
Build steps

In the root project folder, execute the following commands (see alsoCI workflow)

cmake -B build -DCMAKE_INSTALL_PREFIX=*your path*cmake --build build --target install --parallel

[8]ページ先頭

©2009-2025 Movatter.jp