From 7743480b134ea1aee326b52c285f53e0208100e3 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 26 Feb 2018 00:07:01 -0800 Subject: [PATCH] Use clang_getTypedefDeclUnderlyingType and expand alias_of in memberHierarchy --- src/indexer.cc | 7 +++- src/messages/cquery_member_hierarchy.cc | 45 +++++++++++++++++-------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/indexer.cc b/src/indexer.cc index ea248d25..e4aa5120 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1149,7 +1149,12 @@ optional AddDeclTypeUsages( param.previous_cursor.value().get_kind() == CXCursor_TemplateRef)); } - return param.initial_type; + if (param.initial_type) + return param.initial_type; + CXType cx_under = clang_getTypedefDeclUnderlyingType(decl_cursor.cx_cursor); + if (cx_under.kind == CXType_Invalid) + return nullopt; + return db->ToTypeId(ClangType(cx_under).strip_qualifiers().get_usr_hash()); } // Various versions of LLVM (ie, 4.0) will not visit inline variable references diff --git a/src/messages/cquery_member_hierarchy.cc b/src/messages/cquery_member_hierarchy.cc index f4465230..fa215bbc 100644 --- a/src/messages/cquery_member_hierarchy.cc +++ b/src/messages/cquery_member_hierarchy.cc @@ -108,44 +108,61 @@ bool Expand(MessageHandler* m, entry->name = def->detailed_name; else entry->name = def->ShortName(); + std::unordered_set seen; if (levels > 0) { - std::unordered_set seen; std::vector stack; seen.insert(type.usr); stack.push_back(&type); while (stack.size()) { - const QueryType& type = *stack.back(); + const auto* def = stack.back()->AnyDef(); stack.pop_back(); - if (const auto* def = type.AnyDef()) { + if (def) { EachDefinedEntity(m->db->types, def->bases, [&](QueryType& type1) { if (!seen.count(type1.usr)) { seen.insert(type1.usr); stack.push_back(&type1); } }); - EachDefinedEntity(m->db->vars, def->vars, [&](QueryVar& var) { - const QueryVar::Def* def1 = var.AnyDef(); + if (def->alias_of) { + const QueryType::Def* def1 = m->db->types[def->alias_of->id].AnyDef(); if (!def1) - return; + continue; Out_CqueryMemberHierarchy::Entry entry1; - entry1.id = def1->type ? *def1->type : QueryTypeId(); - if (detailed_name) - entry1.fieldName = def1->DetailedName(false); - else - entry1.fieldName = std::string(def1->ShortName()); + entry1.id = *def->alias_of; if (def1->spell) { if (optional loc = GetLsLocation(m->db, m->working_files, *def1->spell)) entry1.location = *loc; } - if (def1->type && Expand(m, &entry1, detailed_name, levels - 1)) + if (detailed_name) + entry1.fieldName = def1->detailed_name; + if (Expand(m, &entry1, detailed_name, levels - 1)) entry->children.push_back(std::move(entry1)); - }); + } else { + EachDefinedEntity(m->db->vars, def->vars, [&](QueryVar& var) { + const QueryVar::Def* def1 = var.AnyDef(); + if (!def1) + return; + Out_CqueryMemberHierarchy::Entry entry1; + entry1.id = def1->type ? *def1->type : QueryTypeId(); + if (detailed_name) + entry1.fieldName = def1->DetailedName(false); + else + entry1.fieldName = std::string(def1->ShortName()); + if (def1->spell) { + if (optional loc = + GetLsLocation(m->db, m->working_files, *def1->spell)) + entry1.location = *loc; + } + if (def1->type && Expand(m, &entry1, detailed_name, levels - 1)) + entry->children.push_back(std::move(entry1)); + }); + } } } entry->numChildren = int(entry->children.size()); } else - entry->numChildren = int(def->vars.size()); + entry->numChildren = def->alias_of ? 1 : int(def->vars.size()); return true; }