Use clang_getTypedefDeclUnderlyingType and expand alias_of in memberHierarchy

This commit is contained in:
Fangrui Song 2018-02-26 00:07:01 -08:00
parent eee785569f
commit 7743480b13
2 changed files with 37 additions and 15 deletions

View File

@ -1149,7 +1149,12 @@ optional<IndexTypeId> AddDeclTypeUsages(
param.previous_cursor.value().get_kind() == CXCursor_TemplateRef));
}
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

View File

@ -108,21 +108,37 @@ bool Expand(MessageHandler* m,
entry->name = def->detailed_name;
else
entry->name = def->ShortName();
if (levels > 0) {
std::unordered_set<Usr> seen;
if (levels > 0) {
std::vector<const QueryType*> 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);
}
});
if (def->alias_of) {
const QueryType::Def* def1 = m->db->types[def->alias_of->id].AnyDef();
if (!def1)
continue;
Out_CqueryMemberHierarchy::Entry entry1;
entry1.id = *def->alias_of;
if (def1->spell) {
if (optional<lsLocation> loc =
GetLsLocation(m->db, m->working_files, *def1->spell))
entry1.location = *loc;
}
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)
@ -143,9 +159,10 @@ bool Expand(MessageHandler* m,
});
}
}
}
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;
}