mirror of
https://github.com/MaskRay/ccls.git
synced 2025-04-14 21:02:14 +00:00
Handle function calls from templates. fix #174
This commit is contained in:
parent
dced34dd58
commit
2ffc068760
@ -418,7 +418,6 @@ void OnIndexReference_Function(IndexFile* db,
|
|||||||
ClangCursor caller_cursor,
|
ClangCursor caller_cursor,
|
||||||
IndexFuncId called_id,
|
IndexFuncId called_id,
|
||||||
IndexFunc* called,
|
IndexFunc* called,
|
||||||
const std::string& called_usr,
|
|
||||||
bool is_implicit) {
|
bool is_implicit) {
|
||||||
if (IsFunctionCallContext(caller_cursor.get_kind())) {
|
if (IsFunctionCallContext(caller_cursor.get_kind())) {
|
||||||
IndexFuncId caller_id = db->ToFuncId(caller_cursor.cx_cursor);
|
IndexFuncId caller_id = db->ToFuncId(caller_cursor.cx_cursor);
|
||||||
@ -1045,15 +1044,14 @@ ClangCursor::VisitResult TemplateVisitor(ClangCursor cursor,
|
|||||||
case CXCursor_ClassTemplate:
|
case CXCursor_ClassTemplate:
|
||||||
break;
|
break;
|
||||||
case CXCursor_OverloadedDeclRef: {
|
case CXCursor_OverloadedDeclRef: {
|
||||||
break; // TODO data->db seems to be incorrect and may cause deadlock
|
|
||||||
|
|
||||||
unsigned num_overloaded = clang_getNumOverloadedDecls(cursor.cx_cursor);
|
unsigned num_overloaded = clang_getNumOverloadedDecls(cursor.cx_cursor);
|
||||||
for (unsigned i = 0; i != num_overloaded; i++) {
|
for (unsigned i = 0; i != num_overloaded; i++) {
|
||||||
ClangCursor overloaded = clang_getOverloadedDecl(cursor.cx_cursor, i);
|
ClangCursor overloaded = clang_getOverloadedDecl(cursor.cx_cursor, i);
|
||||||
switch (overloaded.get_kind()) {
|
switch (overloaded.get_kind()) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
case CXCursor_FunctionDecl: {
|
case CXCursor_FunctionDecl:
|
||||||
|
case CXCursor_FunctionTemplate: {
|
||||||
std::string ref_usr = overloaded.get_usr();
|
std::string ref_usr = overloaded.get_usr();
|
||||||
IndexFuncId called_id = data->db->ToFuncId(ref_usr);
|
IndexFuncId called_id = data->db->ToFuncId(ref_usr);
|
||||||
IndexFunc* called = data->db->Resolve(called_id);
|
IndexFunc* called = data->db->Resolve(called_id);
|
||||||
@ -1062,7 +1060,6 @@ ClangCursor::VisitResult TemplateVisitor(ClangCursor cursor,
|
|||||||
data->container,
|
data->container,
|
||||||
called_id,
|
called_id,
|
||||||
called,
|
called,
|
||||||
ref_usr,
|
|
||||||
/*implicit=*/ false);
|
/*implicit=*/ false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1351,11 +1348,12 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
// OnIndexReference, thus we use TemplateVisitor to collect function
|
// OnIndexReference, thus we use TemplateVisitor to collect function
|
||||||
// references.
|
// references.
|
||||||
if (decl->entityInfo->templateKind == CXIdxEntity_Template) {
|
if (decl->entityInfo->templateKind == CXIdxEntity_Template) {
|
||||||
// TODO put db and caller into client data
|
|
||||||
TemplateVisitorData data;
|
TemplateVisitorData data;
|
||||||
data.db = db;
|
data.db = db;
|
||||||
data.container = decl_cursor;
|
data.container = decl_cursor;
|
||||||
decl_cursor.VisitChildren(&TemplateVisitor, &data);
|
decl_cursor.VisitChildren(&TemplateVisitor, &data);
|
||||||
|
// TemplateVisitor calls ToFuncId which invalidates func
|
||||||
|
func = db->Resolve(func_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add function usage information. We only want to do it once per
|
// Add function usage information. We only want to do it once per
|
||||||
@ -1650,7 +1648,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
|
|||||||
ref->container->cursor,
|
ref->container->cursor,
|
||||||
called_id,
|
called_id,
|
||||||
called,
|
called,
|
||||||
ref->referencedEntity->USR, is_implicit);
|
is_implicit);
|
||||||
|
|
||||||
// Checks if |str| starts with |start|. Ignores case.
|
// Checks if |str| starts with |start|. Ignores case.
|
||||||
auto str_begin = [](const char* start, const char* str) {
|
auto str_begin = [](const char* start, const char* str) {
|
||||||
|
Loading…
Reference in New Issue
Block a user