Skip to content

Extraction of C macro usages #4200

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

Closed
IridiumXOR opened this issue Feb 22, 2025 · 2 comments
Closed

Extraction of C macro usages #4200

IridiumXOR opened this issue Feb 22, 2025 · 2 comments

Comments

@IridiumXOR
Copy link

IridiumXOR commented Feb 22, 2025

Hi,
I have a question: is it possible to extract the location of C macro used in code (for example the usage of list_for_each_head() macro in Linux kernel)? I'm able to extract their definition but not the usage locations. It seems that Cscope is able to identify them but I didn't find a flag for them in ctags (the only way that I have found is to define them using -I sintax)

Thanks

@masatake
Copy link
Member

I have tried to distinguish tags for names defining something (definition tags) and names referencing something(reference tags). You are talking about reference tags.

In my understanding, the original ctags was a tool for extracting definition tags.
I added an infrastructure for handling reference tags to the main part; the code part commonly used in parsers provides a way to emit reference tags.
Some parsers utilize the framework

$ cat g.c
#define ACONDTION 1

#if ACONDTION
/* something here */
#endif
$ ~/bin/ctags --fields=+'{extras}'  --extras=+'{reference}' --roles-C.'{macro}'=+'{condition}' -o - /tmp/g.c
ACONDTION	/tmp/g.c	/^#define ACONDTION /;"	d	file:	extras:fileScope
ACONDTION	/tmp/g.c	/^#if ACONDTION$/;"	d	extras:reference

The first ACONDITION is a definition tag; it defines a macro.
The second one is a reference tag; it is used as a part of a condition.
Please, read ctags(1) (https://docs.ctags.io/en/latest/man/ctags.1.html) if you are interested in the complicated command line.

Though I introduced the infrastructure, parsers in ctags utilize it in very limited areas.
If you are interested in the area, see the output of ctags --list-roles=all.

One of the reasons is that extracting reference tags can make too large tags (> 8G for linux kernel). I wonder if users really want such a large output.

If you are interested in extracting reference tags more aggressively in C language, see #3535 .

@IridiumXOR
Copy link
Author

Thanks a lot again :)
Sorry I started to use this fantastic tool only from some weeks and I don't understand all the options and its capabilities
Thanks again

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