Reputation: 773
Using pycparser to parse a slew of .c source files, but the parser can't handle many things in the #included libraries, and I really don't need them for my purposes. I don't need to have it compile, just need to generate the AST from the specific .c I'm processing. The cpp args i'm passing it right now are:
cpp_args=["-D__attribute__=","-D__extension__=","-D__builtin_va_list=void*"]
Any ideas?
Thanks!
Upvotes: 1
Views: 1759
Reputation: 311506
Try specifying the -nostdinc
option to the preprocessor (and make sure you're not passing any -I
options). Given this input in foo.c
:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv) {
return 0;
}
Running:
cpp -nostdinc foo.c
Gives me:
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "foo.c"
int main(int argc, char **argv) {
return 0;
}
And the following errors:
foo.c:1:19: error: no include path in which to search for stdio.h
foo.c:2:20: error: no include path in which to search for stdlib.h
foo.c:3:20: error: no include path in which to search for unistd.h
Upvotes: 4
Reputation: 96109
One solution would be to use the #include guards
If you have the traditional wrapper in each header, eg.
#ifndef THIS_FILE_H
#define THIS_FILE_H
// stuff
#endif
Then you could simply #define
all the header guard tags you want to ignore
Upvotes: 0