Weggli fails to see call in #define in header files
Hi,
I am trying to use weggli to check of usages of an API call.
The API call is wrapped in a macro
#define wrapper_call(arg1) foo(arg1)
When I try to search for foo
weggli foo src/ --unique
It doesn't see the foo usage in that macro.
Can anyone who ran into a similar issue perhaps if this is expected behaviour ?
weggli operates on the raw sources (so before any preprocessing takes place). At this stage, a preprocessor macro is comparable to a plain search-and-replace operation. This means that foo in this context has no additional meaning (it is just text). Here, you'd search for the wrapper_call instead (as this is used as an call identifier from wegglis point of view):
#define wrapper_call(arg1) foo(arg1)
void helloworld() {
for (int i = 0; i < 10; i++) {
printf("Hello World: %d\n", wrapper_call(i));
}
}
If you really need to have the preprocessor macros resolved, you would need to run the source code through a compiler first. For example with gcc -E:
$ gcc -E /tmp/test.c
# 0 "/tmp/test.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "/tmp/test.c"
void helloworld() {
for (int i = 0; i < 10; i++) {
printf("Hello World: %d\n", foo(i));
}
}