clang-check -ast-dump -ast-dump-filter=<function_name> main.c
gives a AST (only a function declaration) of the particular code.
How can we represent generated AST in JSON format?
PS: I Want AST for function declaration only.
clang-check -ast-dump -ast-dump-filter=<function_name> main.c
gives a AST (only a function declaration) of the particular code.
How can we represent generated AST in JSON format?
PS: I Want AST for function declaration only.
Call clang
with the -ast-dump=json
argument.
This was implemented only recently (May 2019) so you need an up-to-date version of Clang.
See https://reviews.llvm.org/D60910 for details.
There's also a library to export more lower-level information available via libTooling at https://github.com/facebook/facebook-clang-plugins
Update in 2022: The full command line is now clang -Xclang -ast-dump=json -fsyntax-only <file>
since the clang
command is now a compilation driver, not just the compiler itself.
clang.exe: warning: argument unused during compilation: '-ast-dump=json' [-Wunused-command-line-argument]
–
Mclendon clang -fsyntax-only -Xclang -ast-dump=json -Xclang -ast-dump-filter=some_function some_source.cc
–
Pugilist © 2022 - 2024 — McMap. All rights reserved.
-ast-dump=json
is supported withclang
but not withclang-check
And this is working fine for C program not C++ – Pikeman