如何以 JSON 格式表示 clang AST? [英] How to represent clang AST in JSON format?
问题描述
clang-check -ast-dump -ast-dump-filter=
给出了特定代码的 AST(只是一个函数声明).
clang-check -ast-dump -ast-dump-filter=<function_name> main.c
gives a AST (only a function declaration) of the particular code.
我们如何以 JSON 格式表示生成的 AST?
How can we represent generated AST in JSON format?
PS:我只想要 AST 用于函数声明.
PS: I Want AST for function declaration only.
推荐答案
使用 -ast-dump=json
参数调用 clang
.
这是最近才实施的(2019 年 5 月),因此您需要最新版本的 Clang.
This was implemented only recently (May 2019) so you need an up-to-date version of Clang.
有关详细信息,请参阅 https://reviews.llvm.org/D60910.
See https://reviews.llvm.org/D60910 for details.
还有一个库可以通过 libTooling 在 https://github.com/facebook/facebook-clang-plugins
There's also a library to export more lower-level information available via libTooling at https://github.com/facebook/facebook-clang-plugins
这篇关于如何以 JSON 格式表示 clang AST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!