mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-22 00:19:28 +00:00
Attribute enum to its underlying type's uses
This commit is contained in:
parent
d2c4c34bc0
commit
706a3d0017
@ -48,6 +48,8 @@ std::string ClangType::get_usr() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Usr ClangType::get_usr_hash() const {
|
Usr ClangType::get_usr_hash() const {
|
||||||
|
if (is_fundamental())
|
||||||
|
return static_cast<Usr>(cx_type.kind);
|
||||||
return ClangCursor(clang_getTypeDeclaration(cx_type)).get_usr_hash();
|
return ClangCursor(clang_getTypeDeclaration(cx_type)).get_usr_hash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,8 +403,7 @@ optional<IndexTypeId> ResolveToDeclarationType(IndexFile* db,
|
|||||||
|
|
||||||
type = type.strip_qualifiers();
|
type = type.strip_qualifiers();
|
||||||
|
|
||||||
if (CXType_FirstBuiltin <= type.cx_type.kind &&
|
if (type.is_fundamental()) {
|
||||||
type.cx_type.kind <= CXType_LastBuiltin) {
|
|
||||||
// For builtin types, use type kinds as USR hash.
|
// For builtin types, use type kinds as USR hash.
|
||||||
return db->ToTypeId(type.cx_type.kind);
|
return db->ToTypeId(type.cx_type.kind);
|
||||||
}
|
}
|
||||||
@ -443,7 +442,8 @@ void SetVarDetail(IndexVar* var,
|
|||||||
: def.short_name;
|
: def.short_name;
|
||||||
|
|
||||||
if (cursor.get_kind() == CXCursor_EnumConstantDecl && semanticContainer) {
|
if (cursor.get_kind() == CXCursor_EnumConstantDecl && semanticContainer) {
|
||||||
CXType enum_type = clang_getEnumDeclIntegerType(semanticContainer->cursor);
|
CXType enum_type = clang_getCanonicalType(
|
||||||
|
clang_getEnumDeclIntegerType(semanticContainer->cursor));
|
||||||
std::string hover = qualified_name + " = ";
|
std::string hover = qualified_name + " = ";
|
||||||
if (enum_type.kind == CXType_Int || enum_type.kind == CXType_Long ||
|
if (enum_type.kind == CXType_Int || enum_type.kind == CXType_Long ||
|
||||||
enum_type.kind == CXType_LongLong)
|
enum_type.kind == CXType_LongLong)
|
||||||
@ -1376,20 +1376,6 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
|
|
||||||
// We don't need to assign declaring type multiple times if this variable
|
// We don't need to assign declaring type multiple times if this variable
|
||||||
// has already been seen.
|
// has already been seen.
|
||||||
if (!decl->isRedeclaration) {
|
|
||||||
// optional<IndexTypeId> var_type =
|
|
||||||
// ResolveToDeclarationType(db, decl_cursor);
|
|
||||||
// if (var_type.has_value()) {
|
|
||||||
// // Don't treat enum definition variables as instantiations.
|
|
||||||
// bool is_enum_member =
|
|
||||||
// decl->semanticContainer &&
|
|
||||||
// decl->semanticContainer->cursor.kind == CXCursor_EnumDecl;
|
|
||||||
// if (!is_enum_member)
|
|
||||||
// db->Resolve(var_type.value())->instances.push_back(var_id);
|
|
||||||
|
|
||||||
// var->def.variable_type = var_type.value();
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Refactor handlers so more things are under 'if
|
// TODO: Refactor handlers so more things are under 'if
|
||||||
// (!decl->isRedeclaration)'
|
// (!decl->isRedeclaration)'
|
||||||
@ -1607,7 +1593,7 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
case CXIdxEntity_Struct:
|
case CXIdxEntity_Struct:
|
||||||
case CXIdxEntity_CXXClass: {
|
case CXIdxEntity_CXXClass: {
|
||||||
ClangCursor decl_cursor = decl->cursor;
|
ClangCursor decl_cursor = decl->cursor;
|
||||||
Range decl_loc_spelling = decl_cursor.get_spelling_range();
|
Range decl_spell = decl_cursor.get_spelling_range();
|
||||||
|
|
||||||
IndexTypeId type_id = db->ToTypeId(HashUsr(decl->entityInfo->USR));
|
IndexTypeId type_id = db->ToTypeId(HashUsr(decl->entityInfo->USR));
|
||||||
IndexType* type = db->Resolve(type_id);
|
IndexType* type = db->Resolve(type_id);
|
||||||
@ -1633,10 +1619,21 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if (decl->isDefinition) {
|
if (decl->isDefinition) {
|
||||||
type->def.definition_spelling = decl_loc_spelling;
|
type->def.definition_spelling = decl_spell;
|
||||||
type->def.definition_extent = decl_cursor.get_extent();
|
type->def.definition_extent = decl_cursor.get_extent();
|
||||||
|
|
||||||
|
if (decl_cursor.get_kind() == CXCursor_EnumDecl) {
|
||||||
|
ClangType enum_type = clang_getEnumDeclIntegerType(decl->cursor);
|
||||||
|
if (!enum_type.is_fundamental()) {
|
||||||
|
IndexType* int_type =
|
||||||
|
db->Resolve(db->ToTypeId(enum_type.get_usr_hash()));
|
||||||
|
int_type->uses.push_back(decl_spell);
|
||||||
|
// type is invalidated.
|
||||||
|
type = db->Resolve(type_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
UniqueAdd(type->uses, decl_loc_spelling);
|
UniqueAdd(type->uses, decl_spell);
|
||||||
|
|
||||||
if (decl->entityInfo->templateKind == CXIdxEntity_Template) {
|
if (decl->entityInfo->templateKind == CXIdxEntity_Template) {
|
||||||
TemplateVisitorData data;
|
TemplateVisitorData data;
|
||||||
|
Loading…
Reference in New Issue
Block a user