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));
}
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

View File

@ -108,44 +108,61 @@ bool Expand(MessageHandler* m,
entry->name = def->detailed_name;
else
entry->name = def->ShortName();
std::unordered_set<Usr> seen;
if (levels > 0) {
std::unordered_set<Usr> seen;
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);
}
});
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<lsLocation> 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<lsLocation> 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;
}