Merge pull request #544 from b4n/cxx11-override
c++: Properly parse C++11 overrides, finals and noexcepts
This commit is contained in:
commit
96d5eec50f
@ -76,7 +76,7 @@ typedef enum eKeywordId
|
||||
KEYWORD_LOCAL, KEYWORD_LONG,
|
||||
KEYWORD_M_BAD_STATE, KEYWORD_M_BAD_TRANS, KEYWORD_M_STATE, KEYWORD_M_TRANS,
|
||||
KEYWORD_MODULE, KEYWORD_MUTABLE,
|
||||
KEYWORD_NAMESPACE, KEYWORD_NEW, KEYWORD_NEWCOV, KEYWORD_NATIVE,
|
||||
KEYWORD_NAMESPACE, KEYWORD_NEW, KEYWORD_NEWCOV, KEYWORD_NATIVE, KEYWORD_NOEXCEPT,
|
||||
KEYWORD_OPERATOR, KEYWORD_OUT, KEYWORD_OUTPUT, KEYWORD_OVERLOAD, KEYWORD_OVERRIDE,
|
||||
KEYWORD_PACKED, KEYWORD_PORT, KEYWORD_PACKAGE, KEYWORD_PRIVATE,
|
||||
KEYWORD_PROGRAM, KEYWORD_PROTECTED, KEYWORD_PUBLIC,
|
||||
@ -425,7 +425,7 @@ static const keywordDesc KeywordTable [] = {
|
||||
{ "extends", KEYWORD_EXTENDS, { 0, 0, 0, 1, 1, 0, 0 } },
|
||||
{ "extern", KEYWORD_EXTERN, { 1, 1, 1, 0, 1, 1, 0 } },
|
||||
{ "extern", KEYWORD_NAMESPACE, { 0, 0, 0, 0, 0, 0, 1 } }, /* parse block */
|
||||
{ "final", KEYWORD_FINAL, { 0, 1, 0, 1, 0, 0, 1 } },
|
||||
{ "final", KEYWORD_FINAL, { 0, 0, 0, 1, 0, 0, 1 } },
|
||||
{ "finally", KEYWORD_FINALLY, { 0, 0, 0, 0, 0, 1, 1 } },
|
||||
{ "float", KEYWORD_FLOAT, { 1, 1, 1, 1, 0, 1, 1 } },
|
||||
{ "for", KEYWORD_FOR, { 1, 1, 1, 1, 0, 1, 1 } },
|
||||
@ -457,6 +457,7 @@ static const keywordDesc KeywordTable [] = {
|
||||
{ "native", KEYWORD_NATIVE, { 0, 0, 0, 1, 0, 0, 0 } },
|
||||
{ "new", KEYWORD_NEW, { 0, 1, 1, 1, 0, 1, 1 } },
|
||||
{ "newcov", KEYWORD_NEWCOV, { 0, 0, 0, 0, 1, 0, 0 } },
|
||||
{ "noexcept", KEYWORD_NOEXCEPT, { 0, 1, 0, 0, 0, 0, 0 } },
|
||||
{ "operator", KEYWORD_OPERATOR, { 0, 1, 1, 0, 0, 0, 0 } },
|
||||
{ "out", KEYWORD_OUT, { 0, 0, 0, 0, 0, 1, 1 } },
|
||||
{ "output", KEYWORD_OUTPUT, { 0, 0, 0, 0, 1, 0, 0 } },
|
||||
@ -2242,6 +2243,7 @@ static boolean skipPostArgumentStuff (statementInfo *const st,
|
||||
case KEYWORD_ATTRIBUTE: skipParens (); break;
|
||||
case KEYWORD_THROW: skipParens (); break;
|
||||
case KEYWORD_CONST: break;
|
||||
case KEYWORD_NOEXCEPT: break;
|
||||
case KEYWORD_TRY: break;
|
||||
case KEYWORD_VOLATILE: break;
|
||||
|
||||
@ -2262,7 +2264,13 @@ static boolean skipPostArgumentStuff (statementInfo *const st,
|
||||
break;
|
||||
|
||||
default:
|
||||
if (isType (token, TOKEN_NONE))
|
||||
/* "override" and "final" are only keywords in the declaration of a virtual
|
||||
* member function, so need to be handled specially, not as keywords */
|
||||
if (isLanguage(Lang_cpp) && isType (token, TOKEN_NAME) &&
|
||||
(strcmp ("override", vStringValue (token->name)) == 0 ||
|
||||
strcmp ("final", vStringValue (token->name)) == 0))
|
||||
;
|
||||
else if (isType (token, TOKEN_NONE))
|
||||
;
|
||||
else if (info->isKnrParamList && info->parameterCount > 0)
|
||||
++elementCount;
|
||||
@ -2969,7 +2977,15 @@ static void tagCheck (statementInfo *const st)
|
||||
tokenInfo *name_token = (tokenInfo *)prev;
|
||||
boolean free_name_token = FALSE;
|
||||
|
||||
if (isType (name_token, TOKEN_NAME))
|
||||
/* C++ 11 allows class <name> final { ... } */
|
||||
if (isLanguage (Lang_cpp) && isType (prev, TOKEN_NAME) &&
|
||||
strcmp("final", vStringValue(prev->name)) == 0 &&
|
||||
isType(prev2, TOKEN_NAME))
|
||||
{
|
||||
name_token = (tokenInfo *)prev2;
|
||||
copyToken (st->blockName, name_token);
|
||||
}
|
||||
else if (isType (name_token, TOKEN_NAME))
|
||||
{
|
||||
if (!isLanguage (Lang_vala))
|
||||
copyToken (st->blockName, name_token);
|
||||
@ -2994,13 +3010,6 @@ static void tagCheck (statementInfo *const st)
|
||||
}
|
||||
}
|
||||
}
|
||||
/* C++ 11 allows class <name> final { ... } */
|
||||
else if (isLanguage (Lang_cpp) && isType (prev, TOKEN_KEYWORD) &&
|
||||
prev->keyword == KEYWORD_FINAL && isType(prev2, TOKEN_NAME))
|
||||
{
|
||||
name_token = (tokenInfo *)prev2;
|
||||
copyToken (st->blockName, name_token);
|
||||
}
|
||||
else if (isLanguage (Lang_csharp))
|
||||
makeTag (prev, st, FALSE, TAG_PROPERTY);
|
||||
else
|
||||
|
@ -132,6 +132,10 @@ test_sources = \
|
||||
cython_sample.pyx \
|
||||
cython_sample2.pyx \
|
||||
cxx11enum.cpp \
|
||||
cxx11-final.cpp \
|
||||
cxx11-noexcept.cpp \
|
||||
cxx11-override.cpp \
|
||||
cxx14-combined.cpp \
|
||||
db-trig.sql \
|
||||
debian_432872.f90 \
|
||||
directives.c \
|
||||
|
23
tests/ctags/cxx11-final.cpp
Normal file
23
tests/ctags/cxx11-final.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
virtual void foo() = 0;
|
||||
};
|
||||
|
||||
class Derived final : public Base
|
||||
{
|
||||
virtual void foo() final;
|
||||
virtual void final();
|
||||
};
|
||||
|
||||
void Base::foo()
|
||||
{
|
||||
}
|
||||
|
||||
void Derived::foo()
|
||||
{
|
||||
}
|
||||
|
||||
void Derived::final()
|
||||
{
|
||||
}
|
9
tests/ctags/cxx11-final.cpp.tags
Normal file
9
tests/ctags/cxx11-final.cpp.tags
Normal file
@ -0,0 +1,9 @@
|
||||
# format=tagmanager
|
||||
BaseÌ1Ö0
|
||||
DerivedÌ1Ö0
|
||||
finalÌ16Í()ÎDerivedÖ0Ïvoid
|
||||
finalÌ1024Í()ÎDerivedÖ0Ïvirtual void
|
||||
fooÌ16Í()ÎBaseÖ0Ïvoid
|
||||
fooÌ16Í()ÎDerivedÖ0Ïvoid
|
||||
fooÌ1024Í()ÎBaseÖ0Ïvirtual void
|
||||
fooÌ1024Í()ÎDerivedÖ0Ïvirtual void
|
7
tests/ctags/cxx11-noexcept.cpp
Normal file
7
tests/ctags/cxx11-noexcept.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
virtual void foo() noexcept = 0;
|
||||
virtual void bar() const noexcept = 0;
|
||||
int baz() noexcept { return 42; }
|
||||
};
|
5
tests/ctags/cxx11-noexcept.cpp.tags
Normal file
5
tests/ctags/cxx11-noexcept.cpp.tags
Normal file
@ -0,0 +1,5 @@
|
||||
# format=tagmanager
|
||||
BaseÌ1Ö0
|
||||
barÌ1024Í()ÎBaseÖ0Ïvirtual void
|
||||
bazÌ16Í()ÎBaseÖ0Ïint
|
||||
fooÌ1024Í()ÎBaseÖ0Ïvirtual void
|
23
tests/ctags/cxx11-override.cpp
Normal file
23
tests/ctags/cxx11-override.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
virtual void foo() = 0;
|
||||
};
|
||||
|
||||
class Derived : public Base
|
||||
{
|
||||
virtual void foo() override;
|
||||
virtual void override();
|
||||
};
|
||||
|
||||
void Base::foo()
|
||||
{
|
||||
}
|
||||
|
||||
void Derived::foo()
|
||||
{
|
||||
}
|
||||
|
||||
void Derived::override()
|
||||
{
|
||||
}
|
9
tests/ctags/cxx11-override.cpp.tags
Normal file
9
tests/ctags/cxx11-override.cpp.tags
Normal file
@ -0,0 +1,9 @@
|
||||
# format=tagmanager
|
||||
BaseÌ1Ö0
|
||||
DerivedÌ1Ö0
|
||||
fooÌ16Í()ÎBaseÖ0Ïvoid
|
||||
fooÌ16Í()ÎDerivedÖ0Ïvoid
|
||||
fooÌ1024Í()ÎBaseÖ0Ïvirtual void
|
||||
fooÌ1024Í()ÎDerivedÖ0Ïvirtual void
|
||||
overrideÌ16Í()ÎDerivedÖ0Ïvoid
|
||||
overrideÌ1024Í()ÎDerivedÖ0Ïvirtual void
|
8
tests/ctags/cxx14-combined.cpp
Normal file
8
tests/ctags/cxx14-combined.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
struct Base {
|
||||
virtual void baz() const throw() = 0;
|
||||
};
|
||||
|
||||
struct Foo final : public Base {
|
||||
static constexpr auto bar() noexcept { return 1; }
|
||||
virtual void baz() const throw() final override;
|
||||
};
|
6
tests/ctags/cxx14-combined.cpp.tags
Normal file
6
tests/ctags/cxx14-combined.cpp.tags
Normal file
@ -0,0 +1,6 @@
|
||||
# format=tagmanager
|
||||
BaseÌ2048Ö0
|
||||
FooÌ2048Ö0
|
||||
barÌ16Í()ÎFooÖ0Ïconstexpr
|
||||
bazÌ1024Í()ÎBaseÖ0Ïvirtual void
|
||||
bazÌ1024Í()ÎFooÖ0Ïvirtual void
|
Loading…
x
Reference in New Issue
Block a user