我的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;
}
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.