简体   繁体   中英

Using ctags or equivalent to browse code generated by stringification or other C macro tricks

I am working on a very large project which uses the usually not so elegant but useful C macro stringification tricks to generate dynamic symbol names such as:

#define FUNCTION_NAME(signal) (void Callback_ ## signal ## (void))

I use ctags with vim, or visual studio code or eclipse. But there seems to be no way to be able to browse names generated during the preprocessing stage, and i understand why. But as large as the project is, is there a way to plug ctags into the build process so that it can build an index while the build happens. Or any other way of getting around this problem.

Universal Ctags has the ability to expand macro defined in the command line. -D option can be used for this purpose.

$ cat -n /tmp/input.c
     1  FUNCTION_NAME(term)
     2  {
     3    /* Do something */
     4  }
     5  
     6  FUNCTION_NAME(hup)
     7  {
     8    /* Do something */
     9  }
    10  
    11  
$ ~/bin/ctags -D 'FUNCTION_NAME(signal)=void  Callback_ ## signal ## (void)' -o - /tmp/input.c
Callback_hup    /tmp/input.c    /^FUNCTION_NAME(hup)$/;"    f   typeref:typename:void
Callback_term   /tmp/input.c    /^FUNCTION_NAME(term)$/;"   f   typeref:typename:void

See also https://docs.ctags.io/en/latest/man/ctags.1.html#language-specific-options

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM