Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Wed, 08 Jul 2015 16:04:05 UTC Commit: 96d5eec50f35b9daeb7da882ed6b98ff47edaf17 https://github.com/geany/geany/commit/96d5eec50f35b9daeb7da882ed6b98ff47edaf...
Log Message: ----------- Merge pull request #544 from b4n/cxx11-override
c++: Properly parse C++11 overrides, finals and noexcepts
Modified Paths: -------------- tagmanager/ctags/c.c tests/ctags/Makefile.am tests/ctags/cxx11-final.cpp tests/ctags/cxx11-final.cpp.tags tests/ctags/cxx11-noexcept.cpp tests/ctags/cxx11-noexcept.cpp.tags tests/ctags/cxx11-override.cpp tests/ctags/cxx11-override.cpp.tags tests/ctags/cxx14-combined.cpp tests/ctags/cxx14-combined.cpp.tags
Modified: tagmanager/ctags/c.c 31 lines changed, 20 insertions(+), 11 deletions(-) =================================================================== @@ -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
Modified: tests/ctags/Makefile.am 4 lines changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -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 \
Modified: tests/ctags/cxx11-final.cpp 23 lines changed, 23 insertions(+), 0 deletions(-) =================================================================== @@ -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() +{ +}
Modified: tests/ctags/cxx11-final.cpp.tags 9 lines changed, 9 insertions(+), 0 deletions(-) =================================================================== @@ -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
Modified: tests/ctags/cxx11-noexcept.cpp 7 lines changed, 7 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,7 @@ +class Base +{ +public: + virtual void foo() noexcept = 0; + virtual void bar() const noexcept = 0; + int baz() noexcept { return 42; } +};
Modified: tests/ctags/cxx11-noexcept.cpp.tags 5 lines changed, 5 insertions(+), 0 deletions(-) =================================================================== @@ -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
Modified: tests/ctags/cxx11-override.cpp 23 lines changed, 23 insertions(+), 0 deletions(-) =================================================================== @@ -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() +{ +}
Modified: tests/ctags/cxx11-override.cpp.tags 9 lines changed, 9 insertions(+), 0 deletions(-) =================================================================== @@ -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
Modified: tests/ctags/cxx14-combined.cpp 8 lines changed, 8 insertions(+), 0 deletions(-) =================================================================== @@ -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; +};
Modified: tests/ctags/cxx14-combined.cpp.tags 6 lines changed, 6 insertions(+), 0 deletions(-) =================================================================== @@ -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
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).