[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GNU GLOBAL skips indexing of inline functions in files having C++ su
From: |
Hirohito Kato |
Subject: |
Re: GNU GLOBAL skips indexing of inline functions in files having C++ support macros |
Date: |
Thu, 6 Nov 2008 03:26:49 -0800 (PST) |
Dear all,
I have written a patch for ignoring 'extern "C" {...}' block and
treating functions inside the block as a function(not symbol).
>>>>>>>>>>>>>>
% diff -ru global-5.7.3 global-5.7.3_externc
diff -ru global-5.7.3/gtags-parser/C.c global-5.7.3_externc/gtags-parser/C.c
--- global-5.7.3/gtags-parser/C.c 2008-10-29 19:09:47.000000000 +0900
+++ global-5.7.3_externc/gtags-parser/C.c 2008-11-06 20:11:18.000000000
+0900
@@ -70,6 +70,7 @@
} stack[MAXPIFSTACK], *cur;
static int piflevel; /* condition macro level */
static int level; /* brace level */
+static int externclevel; /* extern "C" block level */
/*
* yacc: read yacc file and pickup tag entries.
@@ -113,7 +114,7 @@
int yaccstatus = (type == TYPE_YACC) ? DECLARATIONS : PROGRAMS;
int inC = (type == TYPE_YACC) ? 0 : 1; /* 1 while C source */
- level = piflevel = 0;
+ level = piflevel = externclevel = 0;
savelevel = -1;
target = (sflag) ? SYM : (rflag) ? REF : DEF;
startmacro = startsharp = 0;
@@ -197,7 +198,9 @@
/* { */
case '}':
if (--level < 0) {
- if (wflag)
+ if (externclevel > 0)
+ externclevel--;
+ else if (wflag)
warning("missing left '{' [+%d %s].",
lineno, curfile); /* } */
level = 0;
}
@@ -304,6 +307,23 @@
case SHARP_SHARP: /* ## */
(void)nexttoken(interested, c_reserved_word);
break;
+ case C_EXTERN: /* for 'extern "C" {...}' only */
+ if (peekc(0) != '"') /* " */
+ continue; /* If does not start with '"',
continue. */
+ while ((c = nexttoken(interested, c_reserved_word)) ==
'\n')
+ ;
+ /*
+ * 'extern "C" {...}' block is a kind of C++ namespace
block.
+ * (It shouldn't have any influence on level.)
+ */
+ if (c == '{') /* } */
+ externclevel++;
+ else if (c == SYMBOL)
+ pushbacktoken();
+ else
+ if (wflag)
+ warning("missing 'extern \"C\"' block.
[+%d %s](0x%x).", lineno,
curfile, c);
+ break;
case C_STRUCT:
case C_ENUM:
case C_UNION:
diff -ru global-5.7.3/gtags-parser/Cpp.c
global-5.7.3_externc/gtags-parser/Cpp.c
--- global-5.7.3/gtags-parser/Cpp.c 2008-10-29 19:09:47.000000000 +0900
+++ global-5.7.3_externc/gtags-parser/Cpp.c 2008-11-06 20:10:37.000000000
+0900
@@ -181,6 +181,23 @@
warning("missing namespace block. [+%d
%s](0x%x).", lineno, curfile,
c);
}
break;
+ case CPP_EXTERN: /* for 'extern "C" {...}' only */
+ if (peekc(0) != '"') /* " */
+ continue; /* If does not start with '"',
continue. */
+ while ((c = nexttoken(interested, cpp_reserved_word))
== '\n')
+ ;
+ /*
+ * 'extern "C" {...}' block is a kind of namespace
block.
+ * (It shouldn't have any influence on level.)
+ */
+ if (c == '{') /* } */
+ namespacelevel++;
+ else if (c == SYMBOL)
+ pushbacktoken();
+ else
+ if (wflag)
+ warning("missing 'extern \"C\"' block.
[+%d %s](0x%x).", lineno,
curfile, c);
+ break;
case CPP_CLASS:
DBG_PRINT(level, "class");
if ((c = nexttoken(interested, cpp_reserved_word)) ==
SYMBOL) {
<<<<<<<<<<<<<<
After patching, gtags-parser treats fuga() as a function, and
errno variable as a symbol against the following cpp code.
(I also checked the c code by renaming the suffix of filename to '.c')
===================
#include <stdio.h>
#include <errno.h>
extern int errno;
int hoge() { return 0; }
#ifdef __cplusplus
extern "C" {
#endif
int fuga() { return 0; }
#ifdef __cplusplus
}
#endif
int main() { hoge(); fuga(); return 0; }
----------------------
% gtags
% global fuga
externcpp.cpp
% global hoge
externcpp.cpp
% global errno
% global -s errno
externcpp.cpp
%
===================
I hope this helps GNU GLOBAL's improvement.
Best regards,
Shigio YAMAGUCHI-2 wrote:
>
> On Wed, 5 Nov 2008 16:23:04 -0800 (PST)
> Hirohito Kato <> wrote:
>
>> Now I try to modify the source code in order to ignore 'extern "C"'
>> sentence like namespace token.
>> If I do it, can I send a patch of it to you
>
> It is very welcome!
> It is a big help for other C++ users.
> Thank you.
>
>
> _______________________________________________
> Bug-global mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/bug-global
>
>
--
View this message in context:
http://www.nabble.com/GNU-GLOBAL-skips-indexing-of-inline-functions-in-files-having-C%2B%2B-support-macros-tp11539370p20359386.html
Sent from the Gnu - Global - Bugs mailing list archive at Nabble.com.
- Re: GNU GLOBAL skips indexing of inline functions in files having C++ support macros, Hirohito Kato, 2008/11/06
- Re: GNU GLOBAL skips indexing of inline functions in files having C++ support macros, Shigio YAMAGUCHI, 2008/11/06
- Re: GNU GLOBAL skips indexing of inline functions in files having C++ support macros,
Hirohito Kato <=
- Re: GNU GLOBAL skips indexing of inline functions in files having C++ support macros, Hideki IWAMOTO, 2008/11/06
- Re: GNU GLOBAL skips indexing of inline functions in files having C++ support macros, Hirohito Kato, 2008/11/06
- Re: GNU GLOBAL skips indexing of inline functions in files having C++ support macros, Hirohito Kato, 2008/11/07
- Re: GNU GLOBAL skips indexing of inline functions in files having C++ support macros, Hirohito Kato, 2008/11/11
- Re: GNU GLOBAL skips indexing of inline functions in files having C++ support macros, Shigio YAMAGUCHI, 2008/11/11
Re: GNU GLOBAL skips indexing of inline functions in files having C++ support macros, Shigio YAMAGUCHI, 2008/11/06