I want AST for my C program and want represent in json format. To do so I used clang -Xclang -ast-dump=json -fSyntax-only main.c
command. It gave a AST. but the AST contains typeDecl, Value declaration
etc. along with function declaration
.
I want only a function declaration form my code in JSON form. How can achieve this?
Here is an alternative clang-check -ast-dump -ast-dump-filter=main main.c
but this cant give the result in JSON form. and when I execute this got some error messages along with output for this simple code
#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.