如何以 JSON 格式表示 clang AST? [英] How to represent clang AST in JSON format?

查看:58
本文介绍了如何以 JSON 格式表示 clang AST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

clang-check -ast-dump -ast-dump-filter=main.c 给出了特定代码的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆