我想要将我的C程序的AST表示成JSON格式。为此,我使用了
我只想要以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.
clang -Xclang -ast-dump=json -fSyntax-only main.cpp
不会给出 AST。对于C
程序,它可以正常工作。 - achala