ach*_*ala 5 c clang abstract-syntax-tree
我想为我的 C 程序使用 AST,并希望以 json 格式表示。为此,我使用了clang -Xclang -ast-dump=json -fSyntax-only main.c命令。它给了一个AST。但是 AST 包含typeDecl, Value declaration等以及function declaration.
我只想要一个函数声明,以 JSON 形式从我的代码中形成。怎样才能做到这一点?
这是一种替代方法,clang-check -ast-dump -ast-dump-filter=main main.c但这不能以 JSON 形式给出结果。当我执行这个时得到了一些错误消息以及这个简单代码的输出
#include <stdio.h>
int main() {
printf("Hello from C!");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "main.c"
No compilation database found in /home/..../src or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
Run Code Online (Sandbox Code Playgroud)