Things to note about Clang dump AST

Clang dump AST essentially compiles an OC/C/C++ source file compilation unit, that is, the configuration related to compilation should pay attention to relevant parameters, such as the path of the dependent header file, and other dependencies that the specially compiled source file depends on. The header files under the path, as well as the support for C++ new feature syntax, etc.
The following is an example of the use of Clang dump AST that is easy to search on the Internet

 clang -Xclang -ast-dump -fsyntax-only  源文件路径

The premise that the above default parameters can work normally is that the source files to be processed are relatively simple, and no special header files and new C++ syntax features are used.

Let's take a look at the use of C++11's bind syntax, such error messages appear during ast dump (after the ast dump process fails, the entire AST will be incomplete!!!)

 warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
 error: no member named 'bind' in namespace 'std'

The solution to this type of error is to specify the C++11 language standard, specified by the -std parameter

clang -v -std=c++11 -Xclang -ast-dump -fsyntax-only 源文件路径

Note: Adding -v mainly checks the header files of the current clang include
insert image description here

After ast-dump error, ast tree is incomplete!
insert image description here

Dependencies on header files can be specified using the -I parameter

clang -v -std=c++11 -Xclang -ast-dump -fsyntax-only 源文件路径 -I 依赖的头文件路径

-std parameter description

insert image description here

-I parameter description

insert image description here

Guidance documents for each parameter of clagn
https://clang.llvm.org/docs/ClangCommandLineReference.html

Guess you like

Origin blog.csdn.net/SCHOLAR_II/article/details/129661942