From 60c02674320325dafa218a196a6468fa08290212 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 26 Feb 2018 17:23:45 -0800 Subject: [PATCH] Var DetailedName --- src/indexer.h | 13 +++++++-- src/messages/cquery_member_hierarchy.cc | 38 ++++++++++++++----------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/indexer.h b/src/indexer.h index 75a1c40e..c671fca3 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -390,9 +390,16 @@ struct VarDefDefinitionData { if (qualified) return detailed_name; int i = short_name_offset; - while (i && (isalnum(detailed_name[i - 1]) || detailed_name[i - 1] == '_' || - detailed_name[i - 1] == ':')) - i--; + for (int paren = 0; i; i--) { + // Skip parentheses in "(anon struct)::name" + if (detailed_name[i - 1] == ')') + paren++; + else if (detailed_name[i - 1] == '(') + paren--; + else if (!(paren > 0 || isalnum(detailed_name[i - 1]) || + detailed_name[i - 1] == '_' || detailed_name[i - 1] == ':')) + break; + } return detailed_name.substr(0, i) + detailed_name.substr(short_name_offset); } }; diff --git a/src/messages/cquery_member_hierarchy.cc b/src/messages/cquery_member_hierarchy.cc index c6e1d8d0..d6aeb2cf 100644 --- a/src/messages/cquery_member_hierarchy.cc +++ b/src/messages/cquery_member_hierarchy.cc @@ -46,7 +46,7 @@ struct Out_CqueryMemberHierarchy lsLocation location; // For unexpanded nodes, this is an upper bound because some entities may be // undefined. If it is 0, there are no members. - int numChildren; + int numChildren = 0; // Empty if the |levels| limit is reached. std::vector children; }; @@ -71,13 +71,10 @@ bool Expand(MessageHandler* m, // builtin types have no declaration and empty |detailed_name|. if (CXType_FirstBuiltin <= type.usr && type.usr <= CXType_LastBuiltin) { entry->name = ClangBuiltinTypeName(CXTypeKind(type.usr)); - entry->numChildren = 0; return true; } - if (!def) { - entry->numChildren = 0; + if (!def) return false; - } if (detailed_name) entry->name = def->detailed_name; else @@ -99,26 +96,29 @@ bool Expand(MessageHandler* m, }); 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 loc = - GetLsLocation(m->db, m->working_files, *def1->spell)) - entry1.location = *loc; + if (def1) { + if (def1->spell) { + if (optional loc = + GetLsLocation(m->db, m->working_files, *def1->spell)) + entry1.location = *loc; + } + if (detailed_name) + entry1.fieldName = def1->detailed_name; } - if (detailed_name) - entry1.fieldName = def1->detailed_name; - if (Expand(m, &entry1, detailed_name, levels - 1)) + if (Expand(m, &entry1, detailed_name, levels - 1)) { + // For builtin types |name| is set. + if (detailed_name && entry1.fieldName.empty()) + entry1.fieldName = std::string(entry1.name); 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 @@ -128,8 +128,14 @@ bool Expand(MessageHandler* m, GetLsLocation(m->db, m->working_files, *def1->spell)) entry1.location = *loc; } - if (def1->type && Expand(m, &entry1, detailed_name, levels - 1)) + if (def1->type) { + entry1.id = *def1->type; + if (Expand(m, &entry1, detailed_name, levels - 1)) + entry->children.push_back(std::move(entry1)); + } else { + entry1.id = QueryTypeId(); entry->children.push_back(std::move(entry1)); + } }); } }