diff options
author | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2017-11-15 13:35:38 +0100 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2018-02-01 14:12:58 +0000 |
commit | 4f20c0d4edef1d20c3321d375c7083b7b481fab3 (patch) | |
tree | d707950c70070a69ac7f3c46a7a7e12fb2664aad | |
parent | 28d0a5e5374e1067ff111aa1af0e791bf4411236 (diff) |
Clang: Highlight invalid declarations as text
...instead of the corresponding declaration color.
Task-number: QTCREATORBUG-18686
Change-Id: Ice4d84816351af79efa286f49516c392bd80da86
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
-rw-r--r-- | src/tools/clangbackend/source/clangbackend_global.h | 5 | ||||
-rw-r--r-- | src/tools/clangbackend/source/cursor.cpp | 11 | ||||
-rw-r--r-- | src/tools/clangbackend/source/cursor.h | 1 | ||||
-rw-r--r-- | src/tools/clangbackend/source/tokeninfo.cpp | 3 | ||||
-rw-r--r-- | tests/unit/unittest/conditionally-disabled-tests.h | 6 | ||||
-rw-r--r-- | tests/unit/unittest/data/highlightingmarks.cpp | 2 | ||||
-rw-r--r-- | tests/unit/unittest/tokeninfos-test.cpp | 14 |
7 files changed, 42 insertions, 0 deletions
diff --git a/src/tools/clangbackend/source/clangbackend_global.h b/src/tools/clangbackend/source/clangbackend_global.h index 31425c0717..927141e01f 100644 --- a/src/tools/clangbackend/source/clangbackend_global.h +++ b/src/tools/clangbackend/source/clangbackend_global.h @@ -41,4 +41,9 @@ enum class PreferredTranslationUnit # define IS_PRETTY_DECL_SUPPORTED #endif +// CLANG-UPGRADE-CHECK: Remove IS_INVALIDDECL_SUPPORTED once we require clang >= 7.0 +#if defined(CINDEX_VERSION_HAS_ISINVALIDECL_BACKPORTED) || CINDEX_VERSION_MINOR >= 46 +# define IS_INVALIDDECL_SUPPORTED +#endif + } // namespace ClangBackEnd diff --git a/src/tools/clangbackend/source/cursor.cpp b/src/tools/clangbackend/source/cursor.cpp index 8b9b22f7cc..464ca4e9bf 100644 --- a/src/tools/clangbackend/source/cursor.cpp +++ b/src/tools/clangbackend/source/cursor.cpp @@ -29,6 +29,8 @@ #include "sourcelocation.h" #include "sourcerange.h" +#include "clangbackend_global.h" + #include <ostream> namespace ClangBackEnd { @@ -103,6 +105,15 @@ bool Cursor::isDeclaration() const return clang_isDeclaration(kind()); } +bool Cursor::isInvalidDeclaration() const +{ +#ifdef IS_INVALIDDECL_SUPPORTED + return clang_isInvalidDeclaration(cxCursor); +#else + return false; +#endif +} + bool Cursor::isLocalVariable() const { switch (semanticParent().kind()) { diff --git a/src/tools/clangbackend/source/cursor.h b/src/tools/clangbackend/source/cursor.h index bef5a006f4..a2b5107f80 100644 --- a/src/tools/clangbackend/source/cursor.h +++ b/src/tools/clangbackend/source/cursor.h @@ -61,6 +61,7 @@ public: bool isStaticMethod() const; bool isCompoundType() const; bool isDeclaration() const; + bool isInvalidDeclaration() const; bool isLocalVariable() const; bool isReference() const; bool isExpression() const; diff --git a/src/tools/clangbackend/source/tokeninfo.cpp b/src/tools/clangbackend/source/tokeninfo.cpp index a9c8431286..86b0cf3a54 100644 --- a/src/tools/clangbackend/source/tokeninfo.cpp +++ b/src/tools/clangbackend/source/tokeninfo.cpp @@ -308,6 +308,9 @@ void TokenInfo::identifierKind(const Cursor &cursor, Recursion recursion) { m_isIdentifier = (cursor.kind() != CXCursor_PreprocessingDirective); + if (cursor.isInvalidDeclaration()) + return; + switch (cursor.kind()) { case CXCursor_Destructor: case CXCursor_Constructor: diff --git a/tests/unit/unittest/conditionally-disabled-tests.h b/tests/unit/unittest/conditionally-disabled-tests.h index 8f55db10d7..3cac759135 100644 --- a/tests/unit/unittest/conditionally-disabled-tests.h +++ b/tests/unit/unittest/conditionally-disabled-tests.h @@ -39,3 +39,9 @@ #else # define DISABLED_WITHOUT_PRETTYDECL_PATCH(x) DISABLED_##x #endif + +#ifdef IS_INVALIDDECL_SUPPORTED +# define DISABLED_WITHOUT_INVALIDDECL_PATCH(x) x +#else +# define DISABLED_WITHOUT_INVALIDDECL_PATCH(x) DISABLED_##x +#endif diff --git a/tests/unit/unittest/data/highlightingmarks.cpp b/tests/unit/unittest/data/highlightingmarks.cpp index 83df72fa10..afe4d8a0f1 100644 --- a/tests/unit/unittest/data/highlightingmarks.cpp +++ b/tests/unit/unittest/data/highlightingmarks.cpp @@ -588,3 +588,5 @@ void BaseClass::VirtualFunction() {} class WithVirtualFunctionDefined { virtual void VirtualFunctionDefinition() {}; }; + +Undeclared u; diff --git a/tests/unit/unittest/tokeninfos-test.cpp b/tests/unit/unittest/tokeninfos-test.cpp index 0d9b34f4b6..d3e249c329 100644 --- a/tests/unit/unittest/tokeninfos-test.cpp +++ b/tests/unit/unittest/tokeninfos-test.cpp @@ -1246,6 +1246,20 @@ TEST_F(TokenInfos, DefineIsNotIdentifier) ASSERT_THAT(container.isIncludeDirectivePath(), false); } +TEST_F(TokenInfos, DISABLED_WITHOUT_INVALIDDECL_PATCH(TypeNameOfInvalidDeclarationIsInvalid)) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(592, 14)); + + ASSERT_THAT(infos[0], HasOnlyType(HighlightingType::Invalid)); +} + +TEST_F(TokenInfos, DISABLED_WITHOUT_INVALIDDECL_PATCH(VariableNameOfInvalidDeclarationIsInvalid)) +{ + const auto infos = translationUnit.tokenInfosInRange(sourceRange(592, 14)); + + ASSERT_THAT(infos[1], HasOnlyType(HighlightingType::Invalid)); +} + Data *TokenInfos::d; void TokenInfos::SetUpTestCase() |