From 77e9ea1b77b8cc3fbd32f2fc987aa34fea8096b2 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 30 Dec 2017 15:33:58 -0800 Subject: [PATCH] Use cursor extents for `is_implicit` function calls cursor extents have larger ranges and less specific, thus making them overridable by more specific (with smaller range) symbols. Thus we do not need to hide them in query.cc:BuildFileDef For example, the left paren in `A a(3)` jumps to the constructor. the left paren in `A a = f()` jumps to the copy/move constructor. --- src/indexer.cc | 19 ++++++++++++------- src/query.cc | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/indexer.cc b/src/indexer.cc index d41ff58e..2327a0c8 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -355,7 +355,7 @@ bool IsFunctionCallContext(CXCursorKind kind) { } void OnIndexReference_Function(IndexFile* db, - Range loc_spelling, + Range loc, ClangCursor caller_cursor, IndexFuncId called_id, IndexFunc* called, @@ -367,11 +367,11 @@ void OnIndexReference_Function(IndexFile* db, called = db->Resolve(called_id); AddFuncRef(&caller->def.callees, - IndexFuncRef(called->id, loc_spelling, is_implicit)); + IndexFuncRef(called->id, loc, is_implicit)); AddFuncRef(&called->callers, - IndexFuncRef(caller->id, loc_spelling, is_implicit)); + IndexFuncRef(caller->id, loc, is_implicit)); } else { - AddFuncRef(&called->callers, IndexFuncRef(loc_spelling, is_implicit)); + AddFuncRef(&called->callers, IndexFuncRef(loc, is_implicit)); } } @@ -1640,7 +1640,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { // } // TODO: search full history? - Range loc_spelling = ResolveSpelling(ref->cursor); + Range loc = ResolveSpelling(ref->cursor); IndexFuncId called_id = db->ToFuncId(ref->referencedEntity->USR); IndexFunc* called = db->Resolve(called_id); @@ -1661,7 +1661,12 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { !CursorSpellingContainsString(ref->cursor, param->tu->cx_tu, called->def.short_name))); - OnIndexReference_Function(db, loc_spelling, ref->container->cursor, + // Extents have larger ranges and thus less specific, and will be overriden + // by other functions if exist. + if (is_implicit) + loc = ResolveExtent(ref->cursor); + + OnIndexReference_Function(db, loc, ref->container->cursor, called_id, called, is_implicit); // Checks if |str| starts with |start|. Ignores case. @@ -1703,7 +1708,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) { if (ctor_usr) { IndexFunc* ctor = db->Resolve(db->ToFuncId(*ctor_usr)); AddFuncRef(&ctor->callers, - IndexFuncRef(loc_spelling, true /*is_implicit*/)); + IndexFuncRef(loc, true /*is_implicit*/)); } } } diff --git a/src/query.cc b/src/query.cc index de5c46ee..146556fd 100644 --- a/src/query.cc +++ b/src/query.cc @@ -221,8 +221,8 @@ QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexFile& indexed) { add_outline(id_map.ToSymbol(func.id), decl.spelling); } for (const IndexFuncRef& caller : func.callers) { - if (caller.is_implicit) - continue; + // if (caller.is_implicit) + // continue; add_all_symbols(id_map.ToSymbol(func.id), caller.loc); } }