Commit a3a62e78 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Fix highlighting of function in using declaration

Change-Id: I0f646ce22cdc95e5932650a3fb2fe34b8d4a89a3
Reviewed-by: Ivan Donchevskii's avatarIvan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent e6c8fbfd
......@@ -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)
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -551,3 +551,6 @@ struct NonConstReferenceMemberInitialization
template<class T> class Coo;
template<class T> class Coo<T*>;
namespace N { void goo(); }
using N::goo;
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment