问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/59102944/how-to-represent-clang-ast-in-json-format