From 2e499b73d602ab619109ca31d00962906090a446 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 18 Nov 2015 19:09:38 +0100 Subject: [PATCH] Clang: Filter scope operators Scope operators are not really user defined. Change-Id: I1ab08dc3db7c39b98da02b6ef10bf78b75a6856d Reviewed-by: Nikolai Kosjar --- .../ipcsource/highlightinginformation.cpp | 14 +++++++++++++- .../unittest/data/highlightinginformations.cpp | 16 ++++++++++++++++ .../unittest/highlightinginformationstest.cpp | 14 ++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/tools/clangbackend/ipcsource/highlightinginformation.cpp b/src/tools/clangbackend/ipcsource/highlightinginformation.cpp index 808a0407d14..d91ddf26b9d 100644 --- a/src/tools/clangbackend/ipcsource/highlightinginformation.cpp +++ b/src/tools/clangbackend/ipcsource/highlightinginformation.cpp @@ -241,11 +241,23 @@ HighlightingType literalKind(const Cursor &cursor) Q_UNREACHABLE(); } +bool hasOperatorName(const char *operatorString) +{ + return std::strncmp(operatorString, "operator", 8) == 0; +} + +HighlightingType operatorKind(const Cursor &cursor) +{ + if (hasOperatorName(cursor.spelling().cString())) + return HighlightingType::Operator; + else + return HighlightingType::Invalid; +} HighlightingType punctationKind(const Cursor &cursor) { switch (cursor.kind()) { - case CXCursor_DeclRefExpr: return HighlightingType::Operator; + case CXCursor_DeclRefExpr: return operatorKind(cursor); default: return HighlightingType::Invalid; } } diff --git a/tests/unit/unittest/data/highlightinginformations.cpp b/tests/unit/unittest/data/highlightinginformations.cpp index d651fd65e1c..db5f8afde72 100644 --- a/tests/unit/unittest/data/highlightinginformations.cpp +++ b/tests/unit/unittest/data/highlightinginformations.cpp @@ -383,3 +383,19 @@ void f17() { TemplatedType TemplatedTypeDeclaration; } + +void f18() +{ + auto value = 1 + 2; +} + +class ScopeClass +{ +public: + static void ScopeOperator(); +}; + +void f19() +{ + ScopeClass::ScopeOperator(); +} diff --git a/tests/unit/unittest/highlightinginformationstest.cpp b/tests/unit/unittest/highlightinginformationstest.cpp index c09f12cc170..8e5ee4f0ee0 100644 --- a/tests/unit/unittest/highlightinginformationstest.cpp +++ b/tests/unit/unittest/highlightinginformationstest.cpp @@ -881,6 +881,20 @@ TEST_F(HighlightingInformations, TemplatedTypeDeclaration) ASSERT_THAT(infos[0], HasType(HighlightingType::Type)); } +TEST_F(HighlightingInformations, NoOperator) +{ + const auto infos = translationUnit.highlightingInformationsInRange(sourceRange(389, 24)); + + ASSERT_THAT(infos[2], HasType(HighlightingType::Invalid)); +} + +TEST_F(HighlightingInformations, ScopeOperator) +{ + const auto infos = translationUnit.highlightingInformationsInRange(sourceRange(400, 33)); + + ASSERT_THAT(infos[1], HasType(HighlightingType::Invalid)); +} + Data *HighlightingInformations::d; void HighlightingInformations::SetUpTestCase()