Ctags: C : Can't parse function after macro line

Created on 21 Dec 2014  ·  8Comments  ·  Source: universal-ctags/ctags

Hello,
I found a bug in parsing C using ctags (it's in exuberant-ctags also).

The problem is the following:

#include <stdio.h>

#define PRAGMA(x) _Pragma(#x)
PRAGMA(bar)
int foo() {
    int a = 1;
    printf("a = %d\n", a);
}

void main(void) {
    foo();
}

Output of ctags file did not have a function foo() as below.

PRAGMA  f.c /^#define PRAGMA(/;"    d   file:
PRAGMA  f.c /^PRAGMA(bar)$/;"   f
main    f.c /^void main(void) {$/;" f

Thanks!!

Parser buenhancement

Most helpful comment

I don't know the trick but the new parse solves this.
I got:

PRAGMA  /tmp/enum.c /^#define PRAGMA(/;"    d   file:
foo /tmp/enum.c /^int foo() {$/;"   f
main    /tmp/enum.c /^void main(void) {$/;" f

All 8 comments

Thank you for reporting.
Important but fixing this is not easy.

Private note: We have to record the macro definition in directiveDefine of get.c
cork layer I'm working in a branch can be used. Input stream must be hacked.
I have to check geany's memory based input stream.

@masatake
Have you made progress on this?
Is your branch available somewhere?

No. I do nothing about this topic.

Perhaps you could use ctags -I 'PRAGMA+' to skip the macro expansion part.

Private note: We have to record the macro definition in directiveDefine of get.c cork layer

This will not be enough to solve all macro usage, because many can come from included headers, and expand to weird things, so without a full-blown C preprocessor it won't ever be perfect. So I wonder if it makes sense to add all the complexity required to track macro expansion if it won't ever be enough.

@b4n, I agree.

I don't know the trick but the new parse solves this.
I got:

PRAGMA  /tmp/enum.c /^#define PRAGMA(/;"    d   file:
foo /tmp/enum.c /^int foo() {$/;"   f
main    /tmp/enum.c /^void main(void) {$/;" f
Was this page helpful?
0 / 5 - 0 ratings