Add TemplateVisitor to handle CXCursor_OverloadedDeclRef in templates

This commit is contained in:
Fangrui Song 2017-12-24 00:35:38 -08:00
parent 09a23020de
commit dd4044998d

View File

@ -393,6 +393,27 @@ std::string GetDocumentContentInRange(CXTranslationUnit cx_tu,
return result;
}
ClangCursor::VisitResult TemplateVisitor(ClangCursor cursor,
ClangCursor parent,
void* client_data) {
switch (cursor.get_kind()) {
default:
cursor.VisitChildren(&TemplateVisitor, client_data);
/* fallthrough */
case CXCursor_FunctionTemplate:
case CXCursor_ClassTemplate:
return ClangCursor::VisitResult::Continue;
case CXCursor_OverloadedDeclRef: {
unsigned num_overloaded = clang_getNumOverloadedDecls(cursor.cx_cursor);
for (unsigned i = 0; i != num_overloaded; i++) {
// ClangCursor overloaded = clang_getOverloadedDecl(cursor.cx_cursor, i);
// TODO handle references
}
return ClangCursor::VisitResult::Continue;
}
}
}
} // namespace
// static
@ -1255,6 +1276,14 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
}
}
// CXCursor_OverloadedDeclRef in templates are not processed by
// OnIndexReference, thus we use TemplateVisitor to collect function
// references.
if (decl->entityInfo->templateKind == CXIdxEntity_Template) {
// TODO put db and caller into client data
decl_cursor.VisitChildren(&TemplateVisitor, (void*)0);
}
// Add function usage information. We only want to do it once per
// definition/declaration. Do it on definition since there should only
// ever be one of those in the entire program.