Show call tree expand button if function has base or derived callers.

This commit is contained in:
Jacob Dufault 2017-07-19 00:17:38 -07:00
parent 79ec5a749a
commit 08fb60a675
2 changed files with 36 additions and 2 deletions

View File

@ -283,6 +283,39 @@ optional<QueryLocation> GetBaseDefinitionOrDeclarationSpelling(QueryDatabase* db
return def; return def;
} }
bool HasCallersOnSelfOrBaseOrDerived(QueryDatabase* db, QueryFunc& root) {
// Check self.
if (!root.callers.empty())
return true;
// Check for base calls.
optional<QueryFuncId> func_id = root.def.base;
while (func_id) {
optional<QueryFunc>& func = db->funcs[func_id->id];
if (!func)
break;
if (!func->callers.empty())
return true;
func_id = func->def.base;
}
// Check for derived calls.
std::queue<QueryFuncId> queue;
PushRange(&queue, root.derived);
while (!queue.empty()) {
optional<QueryFunc>& func = db->funcs[queue.front().id];
queue.pop();
if (!func)
continue;
if (!func->derived.empty())
return true;
PushRange(&queue, func->derived);
}
return false;
}
std::vector<QueryFuncRef> GetCallersForAllBaseFunctions(QueryDatabase* db, QueryFunc& root) { std::vector<QueryFuncRef> GetCallersForAllBaseFunctions(QueryDatabase* db, QueryFunc& root) {
std::vector<QueryFuncRef> callers; std::vector<QueryFuncRef> callers;
@ -654,7 +687,7 @@ NonElidedVector<Out_CqueryCallTree::CallEntry> BuildInitialCallTree(QueryDatabas
entry.name = root_func->def.short_name; entry.name = root_func->def.short_name;
entry.usr = root_func->def.usr; entry.usr = root_func->def.usr;
entry.location = *def_loc; entry.location = *def_loc;
entry.hasCallers = !root_func->callers.empty(); entry.hasCallers = HasCallersOnSelfOrBaseOrDerived(db, *root_func);
NonElidedVector<Out_CqueryCallTree::CallEntry> result; NonElidedVector<Out_CqueryCallTree::CallEntry> result;
result.push_back(entry); result.push_back(entry);
return result; return result;
@ -709,7 +742,7 @@ NonElidedVector<Out_CqueryCallTree::CallEntry> BuildExpandCallTree(QueryDatabase
call_entry.name = prefix + call_func->def.short_name + " (" + format_location(*call_location) + ")"; call_entry.name = prefix + call_func->def.short_name + " (" + format_location(*call_location) + ")";
call_entry.usr = call_func->def.usr; call_entry.usr = call_func->def.usr;
call_entry.location = *call_location; call_entry.location = *call_location;
call_entry.hasCallers = !call_func->callers.empty(); call_entry.hasCallers = HasCallersOnSelfOrBaseOrDerived(db, *call_func);
result.push_back(call_entry); result.push_back(call_entry);
} }
else { else {

View File

@ -21,6 +21,7 @@ std::vector<QueryLocation> ToQueryLocation(QueryDatabase* db, const std::vector<
std::vector<QueryLocation> GetUsesOfSymbol(QueryDatabase* db, const SymbolIdx& symbol); std::vector<QueryLocation> GetUsesOfSymbol(QueryDatabase* db, const SymbolIdx& symbol);
std::vector<QueryLocation> GetDeclarationsOfSymbolForGotoDefinition(QueryDatabase* db, const SymbolIdx& symbol); std::vector<QueryLocation> GetDeclarationsOfSymbolForGotoDefinition(QueryDatabase* db, const SymbolIdx& symbol);
optional<QueryLocation> GetBaseDefinitionOrDeclarationSpelling(QueryDatabase* db, QueryFunc& func); optional<QueryLocation> GetBaseDefinitionOrDeclarationSpelling(QueryDatabase* db, QueryFunc& func);
bool HasCallersOnSelfOrBaseOrDerived(QueryDatabase* db, QueryFunc& root);
std::vector<QueryFuncRef> GetCallersForAllBaseFunctions(QueryDatabase* db, QueryFunc& root); std::vector<QueryFuncRef> GetCallersForAllBaseFunctions(QueryDatabase* db, QueryFunc& root);
std::vector<QueryFuncRef> GetCallersForAllDerivedFunctions(QueryDatabase* db, QueryFunc& root); std::vector<QueryFuncRef> GetCallersForAllDerivedFunctions(QueryDatabase* db, QueryFunc& root);
optional<lsPosition> GetLsPosition(WorkingFile* working_file, const Position& position); optional<lsPosition> GetLsPosition(WorkingFile* working_file, const Position& position);