#255 c++ namespace key word not supported

Paul Hughes

If a class is declared inside a namespace then cscope cannot find the declarations of those functions.
Also functions declared in anonymous namespace cscope does not index those functions.

Suggested fix:

x@t60>cvs diff src/fscanner.l
Index: src/fscanner.l
RCS file: /cvsroot/cscope/cscope/src/fscanner.l,v
retrieving revision 1.15
diff -r1.15 fscanner.l
< class{wsnl}+{identifier}({wsnl}|{identifier}|[():])*\{ { /* class definition */
> ("namespace"|"class"){wsnl}+{identifier}({wsnl}|{identifier}|[():])*\{ { /* class definition */
> namespace{wsnl}+\{ { /* anonymous namespace */
> classdef = YES;
> tagdef = 'c';
> yyless(9); /* eat up 'namespace', and re-scan */
> yy_set_bol(0);
> goto more;
> }

A similar change would also be required in src/scanner.l for those who use lex. I don't have a server with lex installed available to test.


  • Jud P

    Jud P - 2012-08-01

    Any chance this will get fixed? I'd love to start using cscope, but I'm running into this issue and it makes cscope fairly useless for my project.

  • Hans-Bernhard Broeker

    For this to get fixed, it would have to be broken first. I don't consider it to be. This is still cscope, not c++scope. cscope will _always_ fail to parse C++ code in some way --- the syntax of that language is just way too bizarre for that.

  • Jud P

    Jud P - 2012-08-01

    Bummer. Disappointing as I think this is the only issue holding back use in my C++ project. Well thanks for the quick response at least!

  • Paul Hughes

    Paul Hughes - 2012-08-01

    It is disappointing that you are so hostile to C++. Your project could have many more users if you made some minor changes.

    I even gave you exact code to fix the problem!

    There are 3 problems with cscope and c++

    functions with namespace specifiers eg function(std::string &arg)
    functions with template args eg function(vector<myclass> &arg)

    All of which can be fixed with minor changes to fscanner.l and scanner.l

    After that cscope works well on my very large (1,000,000+ lines) c and c++ project.

  • Hans-Bernhard Broeker

    > There are 3 problems with cscope and c++

    That's three you're aware of. Whereas I'm convinced that this is actually a bottomless pit, which I refuse to jump into.

    People are having a hell of a time getting modern full-featured C++ code to parse with a lexer and generated parser, plus lots of tacked-on extra gizmos. Expecting to do it with a lexer and just a little bit of state machine on top, like cscope does it, is doomed to disappointment.

    So, like I said before, we'll always fail at parsing C++ in some way that somebody out there will find crucially limiting. And if we managed to kinda-sorta parse it, we would be getting flack for the result lacking enough scoping information (namespaces, template hierarchies, ...) as to be virtually useless. E.g. a standard STL has members whose names a single one of, "correctly" displayed, would fill our output window all by themselves. This is a fight that cannot be won. So I won't go there.

  • progmei

    progmei - 2012-11-14

    As for the C++ is used more widely, but the C language seems no long popular. Now most project in our product uses C++, and encourge us to use the C++ and it's features, such as virtual function, namespace,template, etc...
    I don't think cscope not to completely support C++ is a good idea.


Log in to post a comment.