How to represent clang AST in JSON format?

瘦欲@ 提交于 2020-06-16 06:34:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!