bug-global
[Top][All Lists]
Advanced

[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: Mon, 10 Nov 2008 18:34:17 -0800 (PST)

Hello,

About this issue, I have a request.

I think that a 'peekc(int)' function, defined in libutil/token.c, should
 ignore the comment part of codes.
Because, my patch doesn't work well under the following code:

>>>
  extern /* comment */ "C" ...
<<<

The reason why it doesn't do is peekc(0) returns '/'.
If the peekc() ignores the comment block, not only my patch but also

"Re: gtags missing functions with comments before their parameters"
  --- On Thu, 28 Feb 2008 08:13:17

problem will be fixed.

I know the current most important task is rewriting parser by flex,
 but I hope you will apply patches for peekc() and extern "C/C++" issue
 for othe global user.

I would like to know your opinion.

Thank you very much,


Hirohito Kato wrote:
> 
> Hi,
> 
> Now I have fixed my patch.
> 
> First of all, Iwamoto-san's code:
> 
> | extern "C" void foo(void);
> | extern "C++" void bar(void);
> 
> is just a prototype declaration. Therefore, original gtags and
>  my patched gtags command also don't treat them as neither function nor
> symbol.
> 
> To include them as function, the code should be as follows:
> 
> ---------------
> $ cat externC.cc
> extern "C" void foo(void){return;}
> extern "C++" void bar(void){return;}
> 
> int main(void){ foo(); bar(); return 0;}
> ---------------
> 
> In the C(PP)_EXTERN block, gtags can wait not only '{' but also something.
>  Furthermore, if next token is '{', gtags should treat it as if it is a
> kind of
>  namespace.
> 
> Anyway, the following patch is the fixed code that solves the above
> problem.
> 
>>>>>>>>>>>>>>>>>>>>>>>
> diff -ru global-5.7.3/gtags-parser/C.c global-5.7.3_new/gtags-parser/C.c
> --- global-5.7.3/gtags-parser/C.c     2008-10-29 19:09:47.000000000 +0900
> +++ global-5.7.3_new/gtags-parser/C.c 2008-11-07 16:43:05.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,20 @@
>               case SHARP_SHARP:               /* ## */
>                       (void)nexttoken(interested, c_reserved_word);
>                       break;
> +             case C_EXTERN: /* for 'extern "C"/"C++"' */
> +                     if (peekc(0) != '"') /* " */
> +                             continue; /* If does not start with '"', 
> continue. */
> +                     while ((c = nexttoken(interested, c_reserved_word)) == 
> '\n')
> +                             ;
> +                     /*
> +                      * 'extern "C"/"C++"' block is a kind of namespace 
> block.
> +                      * (It doesn't have any influence on level.)
> +                      */
> +                     if (c == '{') /* } */
> +                             externclevel++;
> +                     else
> +                             pushbacktoken();
> +                     break;
>               case C_STRUCT:
>               case C_ENUM:
>               case C_UNION:
> diff -ru global-5.7.3/gtags-parser/Cpp.c
> global-5.7.3_new/gtags-parser/Cpp.c
> --- global-5.7.3/gtags-parser/Cpp.c   2008-10-29 19:09:47.000000000 +0900
> +++ global-5.7.3_new/gtags-parser/Cpp.c       2008-11-07 16:44:08.000000000
> +0900
> @@ -181,6 +181,20 @@
>                                       warning("missing namespace block. [+%d 
> %s](0x%x).", lineno, curfile,
> c);
>                       }
>                       break;
> +             case CPP_EXTERN: /* for 'extern "C"/"C++"' */
> +                     if (peekc(0) != '"') /* " */
> +                             continue; /* If does not start with '"', 
> continue. */
> +                     while ((c = nexttoken(interested, cpp_reserved_word)) 
> == '\n')
> +                             ;
> +                     /*
> +                      * 'extern "C"/"C++"' block is a kind of namespace 
> block.
> +                      * (It doesn't have any influence on level.)
> +                      */
> +                     if (c == '{') /* } */
> +                             namespacelevel++;
> +                     else
> +                             pushbacktoken();
> +                     break;
>               case CPP_CLASS:
>                       DBG_PRINT(level, "class");
>                       if ((c = nexttoken(interested, cpp_reserved_word)) == 
> SYMBOL) {
> <<<<<<<<<<<<<<<<<<<<<<
> 
> Of cource, this works well on Iwamoto-san's code (though the foo/bar
> declarations
> are ignored).
> 
> I hope this patch will be applied future global sources.
> 
> Thank you.
> 
> Hirohito Kato wrote:
>> 
>> Hello, thank you for confirmation.
>> 
>> This is my mistake. I believed that 'extern "{C,C++}"'  must be
>>  used with '{' and '}' braces.
>> 
>> Therefore, the patch can only recognize 'extern "*" {...}' expression,
>> not one like your code.
>> 
>> Now I have to think about this rule again.
>> Thank you for telling me a valuable information.
>> 
>> If someone find problems in my code, please let me know.
>> 
>> Regards,
>> 
>> 
>> Hideki IWAMOTO wrote:
>>> 
>>> Hi.
>>> 
>>> On Thu, 6 Nov 2008 03:26:49 -0800 (PST), Hirohito Kato wrote...
>>>> +                                  warning("missing 'extern \"C\"' block. 
>>>> [+%d %s](0x%x).", lineno,
>>>> curfile, c);
>>> 
>>> I can not understand the meaning of this warning message. 
>>> Is there any problem in the following source code?
>>> 
>>> ===================
>>> $ cat externC.cc
>>> extern "C" void foo(void);
>>> extern "C++" void bar(void);
>>> 
>>> int main(void){ foo(); bar(); return 0;}
>>> $ gtags -w
>>> Warning: missing 'extern "C"' block. [+1 ./externC.cc](0x812).
>>> Warning: missing 'extern "C"' block. [+2 ./externC.cc](0x812).
>>> Warning: missing 'extern "C"' block. [+1 ./externC.cc](0x812).
>>> Warning: missing 'extern "C"' block. [+2 ./externC.cc](0x812).
>>> Warning: missing 'extern "C"' block. [+1 ./externC.cc](0x812).
>>> Warning: missing 'extern "C"' block. [+2 ./externC.cc](0x812).
>>> ===================
>>> 
>>> ----
>>> Hideki IWAMOTO  address@hidden
>>> 
>>> 
>>> _______________________________________________
>>> 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-tp11539370p20432461.html
Sent from the Gnu - Global - Bugs mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]