universal-ctags / ctags

A maintained ctags implementation
https://ctags.io
GNU General Public License v2.0
6.57k stars 628 forks source link

can't pre-process the macro but it works with Exuberant Ctags 5.8 #2356

Open mtozjh opened 4 years ago

mtozjh commented 4 years ago

( Thank you for contacting us.

If you are reporting an issue with the parsing output, please fill the following template. As your custom CTags configuration can affect results, please always use --options=NONE as the first option when running ctags.

Otherwise, delete the template and write your issue from scratch. Examples may help developers understanding your issue better.

Use GitHub web interface and markdown notation. Using mail results broken text rendering that makes the developers go crazy. )


The name of the parser: c/c++

The command line you used to run ctags:

$ ctags --languages=C,C++,FORTRAN --recurse=no -n --fields=+iaSklnezs

The content of input file:

/* THIS IS AN EXAMPLE */

void FTNC(etmif_set_argv)(double *value, int *i)
{
  ETMIF_argv[*i] = *value;

  return;
}

The tags output you are not satisfied with:

FTNC /u/yanchen/.FAST_9995.src.c 6562;" kind:f line:6562 language:C typeref:typename:void signature:(etmif_set_argv) end:6666

The tags output you expect:

etmif_set_argv  /u/yanchen/.FAST_9995.src.c 6562;"  kind:f  line:6562   language:C  typeref:typename:void   signature:(double *value, int *i)   end:6666
...

The version of ctags:


$ ctags --version

Universal Ctags 0.0.0, Copyright (C) 2015 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Dec  2 2019, 05:44:39
  URL: https://ctags.io/
  Optional compiled features: +wildcards, +regex, +iconv, +option-directory, +packcc

How do you get ctags binary:

(
Building it locally, via GITHUB latest version
)
masatake commented 4 years ago

C parser is completely rewritten in u-ctags. Please, use -D option as shown below.

$ cat /tmp/foo.c
void FTNC(etmif_set_argv)(double *value, int *i)
{
  ETMIF_argv[*i] = *value;

  return;
}
$ ./ctags -o - -D'FTNC(n)=n' /tmp/foo.c
etmif_set_argv  /tmp/foo.c  /^void FTNC(etmif_set_argv)(double *value, int *i)$/;"  f   language:C  typeref:typename:void
mtozjh commented 4 years ago

Thanks for the quick response. I know this workaround. Actually I am looking for the behavior like Exuberant Ctas 5.8. Since there are thousands of C/CPP files, it is heavy burden for user to work around all MACRO like this.

will you deliver an enhancement?

masatake commented 4 years ago

will you deliver an enhancement?

Yes, but I will take more than 1 year to implement it.

ctags itself knows the definitions of macro.

$ cat /tmp/foo.h
#define FTNC(f) f
$./ctags -o - --fields-C++=+'{macrodef}' /tmp/foo.h
FTNC    /tmp/foo.h  /^#define FTNC(/;"  d   language:C++    macrodef:f

So ctags can prepare the arugments for -D option by itself.

I had a prototype and it worked.

However, what I have to do is written in https://github.com/universal-ctags/ctags/issues/1038 .

mtozjh commented 4 years ago

Look forward to that release.

BTY, this is really a great tool.

masatake commented 4 years ago

We added so many features, so I cannot remember them timely.

If it is acceptable to run ctags twice, you don't have to specify -D option manually.

$ cat /tmp/foo.h
#define FTNC(f) f
#define BODY(x) { return (x); }
#define R(B) int B
R(FTNC(func)(FTCN(int i))BODY(x))
$ ./ctags -o /tmp/foo.ctags --fields-C++=+'{macrodef}' --fields=+S -x --_xformat="-D%{name}%{signature}=%{C++.macrodef}" /tmp/foo.h
$ ./ctags -o - --options=/tmp/foo.ctags  /tmp/foo.h
BODY    /tmp/foo.h  /^#define BODY(/;"  d   language:C++
FTNC    /tmp/foo.h  /^#define FTNC(/;"  d   language:C++
R   /tmp/foo.h  /^#define R(/;" d   language:C++
func    /tmp/foo.h  /^R(FTNC(func)(FTCN(int i))BODY(x))$/;" f   language:C++    typeref:typename:int

@pragmaware, you may be interested in this output. I'm surprised at this works well.

masatake commented 4 years ago
./ctags -o - --languages=+OldC --language-force=OldC ...

runs old C parser inherited from Exuberant Ctags. (But we will not fix the bug for it even if we got a bug report.)

masatake commented 4 years ago

See https://github.com/universal-ctags/ctags/pull/2427. If a macro is defined in the same input file and ifdefs are not used aggressively, macros can be expanded automatically.