diff --git a/src/tools/clangbackend/ipcsource/cursor.cpp b/src/tools/clangbackend/ipcsource/cursor.cpp index 56dfd9e610d2c6e294ba6430048d31b5fa8a0c8c..1bc494ec71f10a6eb8c102a51cd88fc118ab4ac7 100644 --- a/src/tools/clangbackend/ipcsource/cursor.cpp +++ b/src/tools/clangbackend/ipcsource/cursor.cpp @@ -296,6 +296,16 @@ Cursor Cursor::argument(int index) const return clang_Cursor_getArgument(cxCursor, index); } +unsigned Cursor::overloadedDeclarationsCount() const +{ + return clang_getNumOverloadedDecls(cxCursor); +} + +Cursor Cursor::overloadedDeclaration(unsigned index) const +{ + return clang_getOverloadedDecl(cxCursor, index); +} + namespace { bool isNotUnexposedLValueReference(const Cursor &argument, const Type &argumentType) diff --git a/src/tools/clangbackend/ipcsource/cursor.h b/src/tools/clangbackend/ipcsource/cursor.h index 8f294c7e26c63c75af9c1c13b2b343fdcbd5e7de..8b5e72df3d1b2b23710c38fcd3a1b8204f03333c 100644 --- a/src/tools/clangbackend/ipcsource/cursor.h +++ b/src/tools/clangbackend/ipcsource/cursor.h @@ -93,6 +93,9 @@ public: Cursor functionBaseDeclaration() const; Cursor functionBase() const; Cursor argument(int index) const; + unsigned overloadedDeclarationsCount() const; + Cursor overloadedDeclaration(unsigned index) const; + void collectOutputArgumentRangesTo( std::vector<CXSourceRange> &outputArgumentRanges) const; std::vector<CXSourceRange> outputArgumentRanges() const; diff --git a/src/tools/clangbackend/ipcsource/highlightingmark.cpp b/src/tools/clangbackend/ipcsource/highlightingmark.cpp index 7a4537e9d79c220916fb7656031567e8e79bb637..b448b45f11f765ba9a5a24605a9e31a5e6a6ec37 100644 --- a/src/tools/clangbackend/ipcsource/highlightingmark.cpp +++ b/src/tools/clangbackend/ipcsource/highlightingmark.cpp @@ -157,6 +157,18 @@ void HighlightingMark::referencedTypeKind(const Cursor &cursor) } } +void HighlightingMark::overloadedDeclRefKind(const Cursor &cursor) +{ + types.mainHighlightingType = HighlightingType::Function; + + // Workaround https://bugs.llvm.org//show_bug.cgi?id=33256 - SomeType in + // "using N::SomeType" is mistakenly considered as a CXCursor_OverloadedDeclRef. + if (cursor.overloadedDeclarationsCount() >= 1 + && cursor.overloadedDeclaration(0).kind() != CXCursor_FunctionDecl) { + types.mainHighlightingType = HighlightingType::Type; + } +} + void HighlightingMark::variableKind(const Cursor &cursor) { if (cursor.isLocalVariable()) @@ -298,7 +310,6 @@ void HighlightingMark::identifierKind(const Cursor &cursor, Recursion recursion) case CXCursor_TemplateTemplateParameter: case CXCursor_UnionDecl: case CXCursor_StructDecl: - case CXCursor_OverloadedDeclRef: case CXCursor_TemplateRef: case CXCursor_Namespace: case CXCursor_NamespaceRef: @@ -317,6 +328,7 @@ void HighlightingMark::identifierKind(const Cursor &cursor, Recursion recursion) case CXCursor_ObjCProtocolRef: case CXCursor_ObjCClassRef: case CXCursor_ObjCSuperClassRef: types.mainHighlightingType = HighlightingType::Type; break; + case CXCursor_OverloadedDeclRef: overloadedDeclRefKind(cursor); break; case CXCursor_FunctionTemplate: types.mainHighlightingType = HighlightingType::Function; break; case CXCursor_EnumConstantDecl: types.mainHighlightingType = HighlightingType::Enumeration; break; case CXCursor_PreprocessingDirective: types.mainHighlightingType = HighlightingType::Preprocessor; break; diff --git a/src/tools/clangbackend/ipcsource/highlightingmark.h b/src/tools/clangbackend/ipcsource/highlightingmark.h index b2c05f4d553afe88e0086b110b14abb36fde9acd..f678e0954c806f1bb631c0319c04faac6246d677 100644 --- a/src/tools/clangbackend/ipcsource/highlightingmark.h +++ b/src/tools/clangbackend/ipcsource/highlightingmark.h @@ -63,6 +63,7 @@ public: private: void identifierKind(const Cursor &cursor, Recursion recursion); void referencedTypeKind(const Cursor &cursor); + void overloadedDeclRefKind(const Cursor &cursor); void variableKind(const Cursor &cursor); void fieldKind(const Cursor &cursor); bool isVirtualMethodDeclarationOrDefinition(const Cursor &cursor) const; diff --git a/tests/unit/unittest/data/highlightingmarks.cpp b/tests/unit/unittest/data/highlightingmarks.cpp index ce2312d1446d01a5e5644d276863268e0b8e4d3b..2880a1fc70d51320d1e42becf03fdffecdfc71ee 100644 --- a/tests/unit/unittest/data/highlightingmarks.cpp +++ b/tests/unit/unittest/data/highlightingmarks.cpp @@ -551,3 +551,6 @@ struct NonConstReferenceMemberInitialization template<class T> class Coo; template<class T> class Coo<T*>; + +namespace N { void goo(); } +using N::goo; diff --git a/tests/unit/unittest/highlightingmarks-test.cpp b/tests/unit/unittest/highlightingmarks-test.cpp index 3b67d037bea09c7c48aa2fe4f146114f45237968..4cecb620fc80222a376ea290bf9cb73459f15b86 100644 --- a/tests/unit/unittest/highlightingmarks-test.cpp +++ b/tests/unit/unittest/highlightingmarks-test.cpp @@ -1112,6 +1112,13 @@ TEST_F(HighlightingMarks, ClassTemplateParticalSpecialization) ASSERT_THAT(infos[6], HasOnlyType(HighlightingType::Type)); } +TEST_F(HighlightingMarks, UsingFunction) +{ + const auto infos = translationUnit.highlightingMarksInRange(sourceRange(556, 27)); + + ASSERT_THAT(infos[3], HasOnlyType(HighlightingType::Function)); +} + Data *HighlightingMarks::d; void HighlightingMarks::SetUpTestCase()