Menu

#63 Does not recognize fn. defs with a function pointer arg

open
nobody
None
5
2014-12-15
2008-01-05
Tomas Heran
No

This is well known problem which even manual page acknowledges:

Nor does it recognize function definitions with a function
pointer argument

ParseTable::Recognize(int startState, char *pattern,
int finishState, void (*FinalAction)(char *))
{
...
}

The patch I'm attaching is fairly simple - just modifies the regular
expression for function definitions to allow for the function parameter
list to contain parentheses.

I'm of course aware of the comments in the file saying:

    /\* warning: "if \(...\)" must not overflow yytext, 
     \* so the content of function argument definitions 
     \* is restricted, in particular parentheses are 
     \* not allowed \*/
    /\* FIXME HBB 20001003: the above 'not allowed' may well be the
     \* reason for the parsing bug concerning function pointer usage,
     \* I suspect. --- I think my new special-case rule for 'if'
     \* could be helpful in removing that limitation \*/

My testing was limited only to using the modified version for a few
days. So far I have not seen any negative effect nor have I experienced
any cscope crash. That being said, I understand that there might be
problems with this fix. I'm of course most worried about the 'yytext
overflow', but as I'm hoping the cscope project leaders might have a
test case for it, I didn't try to come up with my own "synthetic" one.

So, I'm posting this patch mainly to start a discussion and get things
moving to be able to resolve this unfortunate deficiency in cscope. I'm
of course willing to finish the work once we have that discussion.

P.S. The patch is only against fscanner.l. For those who are not using
flex: the modification to scanner.l is very similar. I'll try attach the
patch for it later next week once I'll be able to test it on machine
with traditional lex.

Discussion

  • Tomas Heran

    Tomas Heran - 2008-01-05

    Patch for fscanner.l

     
  • Hans-Bernhard Broeker

    This patch can't work reliably. The problem is that it tries to achieve something that's known to be impossible: have a regexp match nested parentheses correctly. There's simply no way it can avoid mismatching the final closing parenthesis of a function's argument list, and thus fail to differentiate between a function declaration and its definition.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.