From b7ce3dd60acf0e25899c412d81af226d4a88ce95 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 28 Jan 2018 23:05:51 -0800 Subject: [PATCH] Better template specialization --- src/indexer.cc | 16 ++++++++-------- src/query_utils.cc | 5 ++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/indexer.cc b/src/indexer.cc index 87c092f3..45b737a4 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1701,14 +1701,6 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { switch (decl->entityInfo->templateKind) { default: break; - case CXIdxEntity_Template: { - TemplateVisitorData data; - data.db = db; - data.container = decl_cursor; - data.param = param; - decl_cursor.VisitChildren(&TemplateVisitor, &data); - break; - } case CXIdxEntity_TemplateSpecialization: case CXIdxEntity_TemplatePartialSpecialization: { // TODO Use a different dimension @@ -1733,6 +1725,14 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { } origin->derived.push_back(type_id); type->def.parents.push_back(origin_id); + } + // fallthrough + case CXIdxEntity_Template: { + TemplateVisitorData data; + data.db = db; + data.container = decl_cursor; + data.param = param; + decl_cursor.VisitChildren(&TemplateVisitor, &data); break; } } diff --git a/src/query_utils.cc b/src/query_utils.cc index 35a00666..883919ca 100644 --- a/src/query_utils.cc +++ b/src/query_utils.cc @@ -187,7 +187,10 @@ std::vector GetUsesOfSymbol(QueryDatabase* db, switch (symbol.kind) { case SymbolKind::Type: { QueryType& type = db->types[symbol.idx]; - return type.uses; + std::vector ret = type.uses; + if (include_decl && type.def) + ret.push_back(*type.def->definition_spelling); + return ret; } case SymbolKind::Func: { // TODO: the vector allocation could be avoided.