Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weggli fails to see call in #define in header files #91

Open
pengwinsurf opened this issue Jan 23, 2024 · 1 comment
Open

Weggli fails to see call in #define in header files #91

pengwinsurf opened this issue Jan 23, 2024 · 1 comment

Comments

@pengwinsurf
Copy link

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 ?

@pengwinsurf pengwinsurf changed the title Weggli fails to see call in #defines in header files Weggli fails to see call in #define in header files Jan 23, 2024
@bluec0re
Copy link
Contributor

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));
  }
}

image

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));
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants