#217 Wrong parsing of variables inside namespace

closed-fixed
None
5
2008-03-29
2008-03-25
Eran Ifrah
No

Hi,

it seems like ctags is not parsing members of namespace correctly.

Assuming the following code:
namespace mud
{
std::string MajorVersion;
std::string MinorVersion;
};

running ctags file.cpp, will result in the following:
MajorVersion test.cpp /^ std::string MajorVersion;$/;" v
MinorVersion test.cpp /^ std::string MinorVersion;$/;" v
mud test.cpp /^namespace mud$/;" n file:

note that MinorVersion & MajorVersion are expected to be members (m) while they are marked as variables (v).

The following output is expected:
MajorVersion test.cpp /^ std::string MajorVersion;$/;" m namespace:mud file:
MinorVersion test.cpp /^ std::string MinorVersion;$/;" m namespace:mud file:
mud test.cpp /^namespace mud$/;" n file:

The second output is more correct, since ctags now correctly identifies MajorString & MinorString as members of namespace mud.

The above output was produced using patched ctags.
The patch (sorry I am not that good in creating patch using standard tools) was to change the function isMember to become like this:

static boolean isMember (const statementInfo *const st)
{
boolean result;
if (isType (st->context, TOKEN_NAME))
result = TRUE;
else
result = (boolean)
(st->parent != NULL && (isContextualStatement (st->parent) || st->parent->declaration == DECL_NAMESPACE));
return result;
}

Eran

Discussion

  • Elliott Hughes

    Elliott Hughes - 2008-03-29

    Logged In: YES
    user_id=1127237
    Originator: NO

    why did you change isMember rather than isContextualStatement?

     
  • Elliott Hughes

    Elliott Hughes - 2008-03-29
    • assigned_to: nobody --> elliotth
     
  • Eran Ifrah

    Eran Ifrah - 2008-03-29

    Logged In: YES
    user_id=1315032
    Originator: YES

    At first I modified the function isContextualStatement() (and it worked), however, this function is being used in several other places as well and I didn't know what are the implications of changing this function directly...
    So I took the safe path, by modifying the caller (isMember()).

    Do you think that it is safe to modify isContextualStatement() directly?

    Since member inside a namespace is indeed contextual..

    WBR,
    Eran

     
  • Elliott Hughes

    Elliott Hughes - 2008-03-29

    Logged In: YES
    user_id=1127237
    Originator: NO

    yeah, looking at the code, i think the bug is that isContextualStatement is missing DECL_NAMESPACE. compare it to isContextualKeyword, for example.

    making the change there (i.e. adding DECL_NAMESPACE) fixes your test case, an old test case from 2004, and doesn't break any of our other tests.

    one thing i'm not 100% happy with is that, being members, stuff in namespaces now get "access:public", which isn't quite right if you think about anonymous namespaces. but i'm inclined to consider that a separate bug (and wait for someone to report it if they think it's a bug).

     
  • Elliott Hughes

    Elliott Hughes - 2008-03-29

    Logged In: YES
    user_id=1127237
    Originator: NO

    playing with it in my editor too, this looks right. committed as revision 650.

     
  • Elliott Hughes

    Elliott Hughes - 2008-03-29
    • status: open --> closed-fixed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks