Clang: Add highlighting types for ObjectiveC

Builtin code model supports ObjectiveC classes,
properties, etc. We can easily get the same
information from clang.

Change-Id: Iede5e177d4932f404e4ccb81ae356eee8faffb71
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-02-14 12:24:21 +01:00
parent 524d3ea28b
commit dacfc611c5
5 changed files with 73 additions and 16 deletions

View File

@@ -96,7 +96,14 @@ enum class HighlightingType : quint8
Union,
TypeAlias,
Typedef,
QtProperty
QtProperty,
ObjectiveCClass,
ObjectiveCCategory,
ObjectiveCProtocol,
ObjectiveCInterface,
ObjectiveCImplementation,
ObjectiveCProperty,
ObjectiveCMethod
};
enum class StorageClass : quint8

View File

@@ -60,6 +60,13 @@ static const char *highlightingTypeToCStringLiteral(HighlightingType type)
RETURN_TEXT_FOR_CASE(TypeAlias);
RETURN_TEXT_FOR_CASE(Typedef);
RETURN_TEXT_FOR_CASE(QtProperty);
RETURN_TEXT_FOR_CASE(ObjectiveCClass);
RETURN_TEXT_FOR_CASE(ObjectiveCCategory);
RETURN_TEXT_FOR_CASE(ObjectiveCProtocol);
RETURN_TEXT_FOR_CASE(ObjectiveCInterface);
RETURN_TEXT_FOR_CASE(ObjectiveCImplementation);
RETURN_TEXT_FOR_CASE(ObjectiveCProperty);
RETURN_TEXT_FOR_CASE(ObjectiveCMethod);
default: return "UnhandledHighlightingType";
}
}

View File

@@ -99,6 +99,13 @@ bool ignore(ClangBackEnd::HighlightingType type)
case HighlightingType::Union:
case HighlightingType::TypeAlias:
case HighlightingType::Typedef:
case HighlightingType::ObjectiveCClass:
case HighlightingType::ObjectiveCCategory:
case HighlightingType::ObjectiveCProtocol:
case HighlightingType::ObjectiveCInterface:
case HighlightingType::ObjectiveCImplementation:
case HighlightingType::ObjectiveCProperty:
case HighlightingType::ObjectiveCMethod:
return true;
}

View File

@@ -158,12 +158,33 @@ void TokenInfo::variableKind(const Cursor &cursor)
m_types.mixinHighlightingTypes.push_back(HighlightingType::OutputArgument);
}
void TokenInfo::fieldKind(const Cursor &)
void TokenInfo::fieldKind(const Cursor &cursor)
{
m_types.mainHighlightingType = HighlightingType::Field;
if (isOutputArgument())
m_types.mixinHighlightingTypes.push_back(HighlightingType::OutputArgument);
const CXCursorKind kind = cursor.kind();
switch (kind) {
default:
m_types.mainHighlightingType = HighlightingType::Invalid;
return;
case CXCursor_ObjCPropertyDecl:
m_types.mixinHighlightingTypes.push_back(HighlightingType::ObjectiveCProperty);
Q_FALLTHROUGH();
case CXCursor_FieldDecl:
case CXCursor_MemberRef:
if (isOutputArgument())
m_types.mixinHighlightingTypes.push_back(HighlightingType::OutputArgument);
return;
case CXCursor_ObjCClassMethodDecl:
m_types.mixinHighlightingTypes.push_back(HighlightingType::ObjectiveCMethod);
return;
case CXCursor_ObjCIvarDecl:
case CXCursor_ObjCInstanceMethodDecl:
case CXCursor_ObjCSynthesizeDecl:
case CXCursor_ObjCDynamicDecl:
return;
}
}
bool TokenInfo::isDefinition() const
@@ -312,18 +333,28 @@ void TokenInfo::typeKind(const Cursor &cursor)
case CXCursor_TypedefDecl:
m_types.mixinHighlightingTypes.push_back(HighlightingType::Typedef);
return;
case CXCursor_ObjCClassRef:
m_types.mixinHighlightingTypes.push_back(HighlightingType::ObjectiveCClass);
return;
case CXCursor_ObjCProtocolDecl:
case CXCursor_ObjCProtocolRef:
m_types.mixinHighlightingTypes.push_back(HighlightingType::ObjectiveCProtocol);
return;
case CXCursor_ObjCInterfaceDecl:
m_types.mixinHighlightingTypes.push_back(HighlightingType::ObjectiveCInterface);
return;
case CXCursor_ObjCImplementationDecl:
m_types.mixinHighlightingTypes.push_back(HighlightingType::ObjectiveCImplementation);
return;
case CXCursor_ObjCCategoryDecl:
case CXCursor_ObjCCategoryImplDecl:
m_types.mixinHighlightingTypes.push_back(HighlightingType::ObjectiveCCategory);
return;
case CXCursor_ObjCSuperClassRef:
case CXCursor_TemplateTypeParameter:
case CXCursor_TemplateTemplateParameter:
case CXCursor_CXXStaticCastExpr:
case CXCursor_CXXReinterpretCastExpr:
case CXCursor_ObjCCategoryDecl:
case CXCursor_ObjCCategoryImplDecl:
case CXCursor_ObjCImplementationDecl:
case CXCursor_ObjCInterfaceDecl:
case CXCursor_ObjCProtocolDecl:
case CXCursor_ObjCProtocolRef:
case CXCursor_ObjCClassRef:
case CXCursor_ObjCSuperClassRef:
break;
}
}
@@ -358,15 +389,13 @@ void TokenInfo::identifierKind(const Cursor &cursor, Recursion recursion)
break;
case CXCursor_FieldDecl:
case CXCursor_MemberRef:
fieldKind(cursor);
break;
case CXCursor_ObjCIvarDecl:
case CXCursor_ObjCPropertyDecl:
case CXCursor_ObjCIvarDecl:
case CXCursor_ObjCClassMethodDecl:
case CXCursor_ObjCInstanceMethodDecl:
case CXCursor_ObjCSynthesizeDecl:
case CXCursor_ObjCDynamicDecl:
m_types.mainHighlightingType = HighlightingType::Field;
fieldKind(cursor);
break;
case CXCursor_TemplateRef:
case CXCursor_NamespaceRef:

View File

@@ -501,6 +501,13 @@ static const char *highlightingTypeToCStringLiteral(HighlightingType type)
RETURN_TEXT_FOR_CASE(TypeAlias);
RETURN_TEXT_FOR_CASE(Typedef);
RETURN_TEXT_FOR_CASE(QtProperty);
RETURN_TEXT_FOR_CASE(ObjectiveCClass);
RETURN_TEXT_FOR_CASE(ObjectiveCCategory);
RETURN_TEXT_FOR_CASE(ObjectiveCProtocol);
RETURN_TEXT_FOR_CASE(ObjectiveCInterface);
RETURN_TEXT_FOR_CASE(ObjectiveCImplementation);
RETURN_TEXT_FOR_CASE(ObjectiveCProperty);
RETURN_TEXT_FOR_CASE(ObjectiveCMethod);
}
return "";