mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 09:05:10 +00:00
Move usr out of *Def and into Query*/Index* types.
I'd like to make the *Def structures optional in the future, and usr is always non-optional.
This commit is contained in:
parent
2751f51956
commit
9b909b3a13
@ -443,7 +443,7 @@ std::string IndexFile::ToString() {
|
||||
}
|
||||
|
||||
IndexType::IndexType(IndexTypeId id, const std::string& usr)
|
||||
: def(usr), id(id) {
|
||||
: usr(usr), id(id) {
|
||||
assert(usr.size() > 0);
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,6 @@ inline void Reflect(Writer& visitor, IndexFuncRef& value) {
|
||||
template <typename TypeId, typename FuncId, typename VarId, typename Range>
|
||||
struct TypeDefDefinitionData {
|
||||
// General metadata.
|
||||
std::string usr;
|
||||
std::string short_name;
|
||||
std::string detailed_name;
|
||||
|
||||
@ -175,12 +174,9 @@ struct TypeDefDefinitionData {
|
||||
std::vector<FuncId> funcs;
|
||||
std::vector<VarId> vars;
|
||||
|
||||
TypeDefDefinitionData() {} // For reflection.
|
||||
TypeDefDefinitionData(const std::string& usr) : usr(usr) {}
|
||||
|
||||
bool operator==(
|
||||
const TypeDefDefinitionData<TypeId, FuncId, VarId, Range>& other) const {
|
||||
return usr == other.usr && short_name == other.short_name &&
|
||||
return short_name == other.short_name &&
|
||||
detailed_name == other.detailed_name &&
|
||||
definition_spelling == other.definition_spelling &&
|
||||
definition_extent == other.definition_extent &&
|
||||
@ -201,7 +197,6 @@ template <typename TVisitor,
|
||||
void Reflect(TVisitor& visitor,
|
||||
TypeDefDefinitionData<TypeId, FuncId, VarId, Range>& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
REFLECT_MEMBER(usr);
|
||||
REFLECT_MEMBER(short_name);
|
||||
REFLECT_MEMBER(detailed_name);
|
||||
REFLECT_MEMBER(definition_spelling);
|
||||
@ -217,10 +212,12 @@ void Reflect(TVisitor& visitor,
|
||||
struct IndexType {
|
||||
using Def =
|
||||
TypeDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, Range>;
|
||||
Def def;
|
||||
|
||||
std::string usr;
|
||||
IndexTypeId id;
|
||||
|
||||
Def def;
|
||||
|
||||
// Immediate derived types.
|
||||
std::vector<IndexTypeId> derived;
|
||||
|
||||
@ -231,16 +228,12 @@ struct IndexType {
|
||||
// NOTE: Do not insert directly! Use AddUsage instead.
|
||||
std::vector<Range> uses;
|
||||
|
||||
IndexType() : def("") {} // For serialization
|
||||
|
||||
IndexType() {} // For serialization.
|
||||
IndexType(IndexTypeId id, const std::string& usr);
|
||||
|
||||
bool operator<(const IndexType& other) const {
|
||||
return def.usr < other.def.usr;
|
||||
}
|
||||
bool operator<(const IndexType& other) const { return id < other.id; }
|
||||
};
|
||||
|
||||
MAKE_HASHABLE(IndexType, t.def.usr);
|
||||
MAKE_HASHABLE(IndexType, t.id);
|
||||
|
||||
template <typename TypeId,
|
||||
typename FuncId,
|
||||
@ -249,7 +242,6 @@ template <typename TypeId,
|
||||
typename Range>
|
||||
struct FuncDefDefinitionData {
|
||||
// General metadata.
|
||||
std::string usr;
|
||||
std::string short_name;
|
||||
std::string detailed_name;
|
||||
optional<Range> definition_spelling;
|
||||
@ -270,15 +262,10 @@ struct FuncDefDefinitionData {
|
||||
// Used for semantic highlighting
|
||||
bool is_operator = false;
|
||||
|
||||
FuncDefDefinitionData() {} // For reflection.
|
||||
FuncDefDefinitionData(const std::string& usr) : usr(usr) {
|
||||
// assert(usr.size() > 0);
|
||||
}
|
||||
|
||||
bool operator==(
|
||||
const FuncDefDefinitionData<TypeId, FuncId, VarId, FuncRef, Range>& other)
|
||||
const {
|
||||
return usr == other.usr && short_name == other.short_name &&
|
||||
return short_name == other.short_name &&
|
||||
detailed_name == other.detailed_name &&
|
||||
definition_spelling == other.definition_spelling &&
|
||||
definition_extent == other.definition_extent &&
|
||||
@ -302,7 +289,6 @@ void Reflect(
|
||||
TVisitor& visitor,
|
||||
FuncDefDefinitionData<TypeId, FuncId, VarId, FuncRef, Range>& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
REFLECT_MEMBER(usr);
|
||||
REFLECT_MEMBER(short_name);
|
||||
REFLECT_MEMBER(detailed_name);
|
||||
REFLECT_MEMBER(definition_spelling);
|
||||
@ -321,10 +307,12 @@ struct IndexFunc {
|
||||
IndexVarId,
|
||||
IndexFuncRef,
|
||||
Range>;
|
||||
Def def;
|
||||
|
||||
std::string usr;
|
||||
IndexFuncId id;
|
||||
|
||||
Def def;
|
||||
|
||||
struct Declaration {
|
||||
// Range of only the function name.
|
||||
Range spelling;
|
||||
@ -349,16 +337,14 @@ struct IndexFunc {
|
||||
// def.definition_spelling.
|
||||
std::vector<IndexFuncRef> callers;
|
||||
|
||||
IndexFunc() {} // For reflection.
|
||||
IndexFunc(IndexFuncId id, const std::string& usr) : def(usr), id(id) {
|
||||
IndexFunc() {} // For serialization.
|
||||
IndexFunc(IndexFuncId id, const std::string& usr) : usr(usr), id(id) {
|
||||
// assert(usr.size() > 0);
|
||||
}
|
||||
|
||||
bool operator<(const IndexFunc& other) const {
|
||||
return def.usr < other.def.usr;
|
||||
}
|
||||
bool operator<(const IndexFunc& other) const { return id < other.id; }
|
||||
};
|
||||
MAKE_HASHABLE(IndexFunc, t.def.usr);
|
||||
MAKE_HASHABLE(IndexFunc, t.id);
|
||||
MAKE_REFLECT_STRUCT(IndexFunc::Declaration,
|
||||
spelling,
|
||||
extent,
|
||||
@ -368,7 +354,6 @@ MAKE_REFLECT_STRUCT(IndexFunc::Declaration,
|
||||
template <typename TypeId, typename FuncId, typename VarId, typename Range>
|
||||
struct VarDefDefinitionData {
|
||||
// General metadata.
|
||||
std::string usr;
|
||||
std::string short_name;
|
||||
std::string detailed_name;
|
||||
optional<Range> declaration;
|
||||
@ -388,12 +373,9 @@ struct VarDefDefinitionData {
|
||||
// Is this a macro, ie, #define FOO?
|
||||
bool is_macro = false;
|
||||
|
||||
VarDefDefinitionData() {} // For reflection.
|
||||
VarDefDefinitionData(const std::string& usr) : usr(usr) {}
|
||||
|
||||
bool operator==(
|
||||
const VarDefDefinitionData<TypeId, FuncId, VarId, Range>& other) const {
|
||||
return usr == other.usr && short_name == other.short_name &&
|
||||
return short_name == other.short_name &&
|
||||
detailed_name == other.detailed_name &&
|
||||
declaration == other.declaration &&
|
||||
definition_spelling == other.definition_spelling &&
|
||||
@ -415,7 +397,6 @@ template <typename TVisitor,
|
||||
void Reflect(TVisitor& visitor,
|
||||
VarDefDefinitionData<TypeId, FuncId, VarId, Range>& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
REFLECT_MEMBER(usr);
|
||||
REFLECT_MEMBER(short_name);
|
||||
REFLECT_MEMBER(detailed_name);
|
||||
REFLECT_MEMBER(definition_spelling);
|
||||
@ -429,24 +410,23 @@ void Reflect(TVisitor& visitor,
|
||||
|
||||
struct IndexVar {
|
||||
using Def = VarDefDefinitionData<IndexTypeId, IndexFuncId, IndexVarId, Range>;
|
||||
Def def;
|
||||
|
||||
std::string usr;
|
||||
IndexVarId id;
|
||||
|
||||
Def def;
|
||||
|
||||
// Usages.
|
||||
std::vector<Range> uses;
|
||||
|
||||
IndexVar() : def("") {} // For serialization
|
||||
|
||||
IndexVar(IndexVarId id, const std::string& usr) : def(usr), id(id) {
|
||||
IndexVar() {} // For serialization.
|
||||
IndexVar(IndexVarId id, const std::string& usr) : usr(usr), id(id) {
|
||||
// assert(usr.size() > 0);
|
||||
}
|
||||
|
||||
bool operator<(const IndexVar& other) const {
|
||||
return def.usr < other.def.usr;
|
||||
}
|
||||
bool operator<(const IndexVar& other) const { return id < other.id; }
|
||||
};
|
||||
MAKE_HASHABLE(IndexVar, t.def.usr);
|
||||
MAKE_HASHABLE(IndexVar, t.id);
|
||||
|
||||
struct IdCache {
|
||||
std::string primary_file;
|
||||
|
@ -59,7 +59,7 @@ std::vector<Out_CqueryCallTree::CallEntry> BuildInitialCallTree(
|
||||
|
||||
Out_CqueryCallTree::CallEntry entry;
|
||||
entry.name = root_func.def->short_name;
|
||||
entry.usr = root_func.def->usr;
|
||||
entry.usr = root_func.usr;
|
||||
entry.location = *def_loc;
|
||||
entry.hasCallers = HasCallersOnSelfOrBaseOrDerived(db, root_func);
|
||||
std::vector<Out_CqueryCallTree::CallEntry> result;
|
||||
@ -133,7 +133,7 @@ std::vector<Out_CqueryCallTree::CallEntry> BuildExpandCallTree(
|
||||
call_entry.name =
|
||||
call_func.def->short_name + " (" +
|
||||
format_location(*call_location, call_func.def->declaring_type) + ")";
|
||||
call_entry.usr = call_func.def->usr;
|
||||
call_entry.usr = call_func.usr;
|
||||
call_entry.location = *call_location;
|
||||
call_entry.hasCallers = HasCallersOnSelfOrBaseOrDerived(db, call_func);
|
||||
call_entry.callType = call_type;
|
||||
|
128
src/query.cc
128
src/query.cc
@ -18,12 +18,12 @@
|
||||
|
||||
namespace {
|
||||
|
||||
optional<QueryType::DefUpdate> ToQuery(const IdMap& id_map,
|
||||
optional<QueryType::Def> ToQuery(const IdMap& id_map,
|
||||
const IndexType::Def& type) {
|
||||
if (type.detailed_name.empty())
|
||||
return nullopt;
|
||||
|
||||
QueryType::DefUpdate result(type.usr);
|
||||
QueryType::Def result;
|
||||
result.short_name = type.short_name;
|
||||
result.detailed_name = type.detailed_name;
|
||||
result.definition_spelling = id_map.ToQuery(type.definition_spelling);
|
||||
@ -36,12 +36,12 @@ optional<QueryType::DefUpdate> ToQuery(const IdMap& id_map,
|
||||
return result;
|
||||
}
|
||||
|
||||
optional<QueryFunc::DefUpdate> ToQuery(const IdMap& id_map,
|
||||
optional<QueryFunc::Def> ToQuery(const IdMap& id_map,
|
||||
const IndexFunc::Def& func) {
|
||||
if (func.detailed_name.empty())
|
||||
return nullopt;
|
||||
|
||||
QueryFunc::DefUpdate result(func.usr);
|
||||
QueryFunc::Def result;
|
||||
result.short_name = func.short_name;
|
||||
result.detailed_name = func.detailed_name;
|
||||
result.definition_spelling = id_map.ToQuery(func.definition_spelling);
|
||||
@ -54,12 +54,11 @@ optional<QueryFunc::DefUpdate> ToQuery(const IdMap& id_map,
|
||||
return result;
|
||||
}
|
||||
|
||||
optional<QueryVar::DefUpdate> ToQuery(const IdMap& id_map,
|
||||
const IndexVar::Def& var) {
|
||||
optional<QueryVar::Def> ToQuery(const IdMap& id_map, const IndexVar::Def& var) {
|
||||
if (var.detailed_name.empty())
|
||||
return nullopt;
|
||||
|
||||
QueryVar::DefUpdate result(var.usr);
|
||||
QueryVar::Def result;
|
||||
result.short_name = var.short_name;
|
||||
result.detailed_name = var.detailed_name;
|
||||
result.declaration = id_map.ToQuery(var.declaration);
|
||||
@ -137,14 +136,14 @@ void CompareGroups(std::vector<T>& previous_data,
|
||||
auto curr_it = current_data.begin();
|
||||
while (prev_it != previous_data.end() && curr_it != current_data.end()) {
|
||||
// same id
|
||||
if (prev_it->def.usr == curr_it->def.usr) {
|
||||
if (prev_it->usr == curr_it->usr) {
|
||||
on_found(&*prev_it, &*curr_it);
|
||||
++prev_it;
|
||||
++curr_it;
|
||||
}
|
||||
|
||||
// prev_id is smaller - prev_it has data curr_it does not have.
|
||||
else if (prev_it->def.usr < curr_it->def.usr) {
|
||||
else if (prev_it->usr < curr_it->usr) {
|
||||
on_removed(&*prev_it);
|
||||
++prev_it;
|
||||
}
|
||||
@ -439,13 +438,13 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
|
||||
{ \
|
||||
/* Check for changes. */ \
|
||||
std::vector<type> removed, added; \
|
||||
auto previous = previous_id_map.ToQuery(previous_def->index_name); \
|
||||
auto current = current_id_map.ToQuery(current_def->index_name); \
|
||||
bool did_add = \
|
||||
ComputeDifferenceForUpdate(previous, current, &removed, &added); \
|
||||
auto query_previous = previous_id_map.ToQuery(previous->index_name); \
|
||||
auto query_current = current_id_map.ToQuery(current->index_name); \
|
||||
bool did_add = ComputeDifferenceForUpdate(query_previous, query_current, \
|
||||
&removed, &added); \
|
||||
if (did_add) { \
|
||||
query_name.push_back(MergeableUpdate<type_id, type>( \
|
||||
current_id_map.ToQuery(current_def->id), added, removed)); \
|
||||
current_id_map.ToQuery(current->id), added, removed)); \
|
||||
} \
|
||||
}
|
||||
// File
|
||||
@ -462,7 +461,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
|
||||
/*onRemoved:*/
|
||||
[this, &previous_id_map](IndexType* type) {
|
||||
if (type->def.definition_spelling)
|
||||
types_removed.push_back(type->def.usr);
|
||||
types_removed.push_back(type->usr);
|
||||
else {
|
||||
if (!type->derived.empty())
|
||||
types_derived.push_back(QueryType::DerivedUpdate(
|
||||
@ -480,10 +479,11 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
|
||||
},
|
||||
/*onAdded:*/
|
||||
[this, ¤t_id_map](IndexType* type) {
|
||||
optional<QueryType::DefUpdate> def_update =
|
||||
optional<QueryType::Def> def_update =
|
||||
ToQuery(current_id_map, type->def);
|
||||
if (def_update)
|
||||
types_def_update.push_back(*def_update);
|
||||
types_def_update.push_back(
|
||||
QueryType::DefUpdate(type->usr, *def_update));
|
||||
if (!type->derived.empty())
|
||||
types_derived.push_back(
|
||||
QueryType::DerivedUpdate(current_id_map.ToQuery(type->id),
|
||||
@ -498,16 +498,18 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
|
||||
current_id_map.ToQuery(type->uses)));
|
||||
},
|
||||
/*onFound:*/
|
||||
[this, &previous_id_map, ¤t_id_map](IndexType* previous_def,
|
||||
IndexType* current_def) {
|
||||
optional<QueryType::DefUpdate> previous_remapped_def =
|
||||
ToQuery(previous_id_map, previous_def->def);
|
||||
optional<QueryType::DefUpdate> current_remapped_def =
|
||||
ToQuery(current_id_map, current_def->def);
|
||||
[this, &previous_id_map, ¤t_id_map](IndexType* previous,
|
||||
IndexType* current) {
|
||||
optional<QueryType::Def> previous_remapped_def =
|
||||
ToQuery(previous_id_map, previous->def);
|
||||
optional<QueryType::Def> current_remapped_def =
|
||||
ToQuery(current_id_map, current->def);
|
||||
if (current_remapped_def &&
|
||||
previous_remapped_def != current_remapped_def &&
|
||||
!current_remapped_def->detailed_name.empty())
|
||||
types_def_update.push_back(*current_remapped_def);
|
||||
!current_remapped_def->detailed_name.empty()) {
|
||||
types_def_update.push_back(
|
||||
QueryType::DefUpdate(current->usr, *current_remapped_def));
|
||||
}
|
||||
|
||||
PROCESS_UPDATE_DIFF(QueryTypeId, types_derived, derived, QueryTypeId);
|
||||
PROCESS_UPDATE_DIFF(QueryTypeId, types_instances, instances,
|
||||
@ -521,7 +523,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
|
||||
/*onRemoved:*/
|
||||
[this, &previous_id_map](IndexFunc* func) {
|
||||
if (func->def.definition_spelling) {
|
||||
funcs_removed.push_back(func->def.usr);
|
||||
funcs_removed.push_back(func->usr);
|
||||
} else {
|
||||
if (!func->declarations.empty())
|
||||
funcs_declarations.push_back(QueryFunc::DeclarationsUpdate(
|
||||
@ -539,10 +541,11 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
|
||||
},
|
||||
/*onAdded:*/
|
||||
[this, ¤t_id_map](IndexFunc* func) {
|
||||
optional<QueryFunc::DefUpdate> def_update =
|
||||
optional<QueryFunc::Def> def_update =
|
||||
ToQuery(current_id_map, func->def);
|
||||
if (def_update)
|
||||
funcs_def_update.push_back(*def_update);
|
||||
funcs_def_update.push_back(
|
||||
QueryFunc::DefUpdate(func->usr, *def_update));
|
||||
if (!func->declarations.empty())
|
||||
funcs_declarations.push_back(QueryFunc::DeclarationsUpdate(
|
||||
current_id_map.ToQuery(func->id),
|
||||
@ -557,16 +560,18 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
|
||||
current_id_map.ToQuery(func->callers)));
|
||||
},
|
||||
/*onFound:*/
|
||||
[this, &previous_id_map, ¤t_id_map](IndexFunc* previous_def,
|
||||
IndexFunc* current_def) {
|
||||
optional<QueryFunc::DefUpdate> previous_remapped_def =
|
||||
ToQuery(previous_id_map, previous_def->def);
|
||||
optional<QueryFunc::DefUpdate> current_remapped_def =
|
||||
ToQuery(current_id_map, current_def->def);
|
||||
[this, &previous_id_map, ¤t_id_map](IndexFunc* previous,
|
||||
IndexFunc* current) {
|
||||
optional<QueryFunc::Def> previous_remapped_def =
|
||||
ToQuery(previous_id_map, previous->def);
|
||||
optional<QueryFunc::Def> current_remapped_def =
|
||||
ToQuery(current_id_map, current->def);
|
||||
if (current_remapped_def &&
|
||||
previous_remapped_def != current_remapped_def &&
|
||||
!current_remapped_def->detailed_name.empty())
|
||||
funcs_def_update.push_back(*current_remapped_def);
|
||||
!current_remapped_def->detailed_name.empty()) {
|
||||
funcs_def_update.push_back(
|
||||
QueryFunc::DefUpdate(current->usr, *current_remapped_def));
|
||||
}
|
||||
|
||||
PROCESS_UPDATE_DIFF(QueryFuncId, funcs_declarations, declarations,
|
||||
QueryLocation);
|
||||
@ -580,7 +585,7 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
|
||||
/*onRemoved:*/
|
||||
[this, &previous_id_map](IndexVar* var) {
|
||||
if (var->def.definition_spelling) {
|
||||
vars_removed.push_back(var->def.usr);
|
||||
vars_removed.push_back(var->usr);
|
||||
} else {
|
||||
if (!var->uses.empty())
|
||||
vars_uses.push_back(
|
||||
@ -590,26 +595,26 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
|
||||
},
|
||||
/*onAdded:*/
|
||||
[this, ¤t_id_map](IndexVar* var) {
|
||||
optional<QueryVar::DefUpdate> def_update =
|
||||
ToQuery(current_id_map, var->def);
|
||||
optional<QueryVar::Def> def_update = ToQuery(current_id_map, var->def);
|
||||
if (def_update)
|
||||
vars_def_update.push_back(*def_update);
|
||||
vars_def_update.push_back(QueryVar::DefUpdate(var->usr, *def_update));
|
||||
if (!var->uses.empty())
|
||||
vars_uses.push_back(
|
||||
QueryVar::UsesUpdate(current_id_map.ToQuery(var->id),
|
||||
current_id_map.ToQuery(var->uses)));
|
||||
},
|
||||
/*onFound:*/
|
||||
[this, &previous_id_map, ¤t_id_map](IndexVar* previous_def,
|
||||
IndexVar* current_def) {
|
||||
optional<QueryVar::DefUpdate> previous_remapped_def =
|
||||
ToQuery(previous_id_map, previous_def->def);
|
||||
optional<QueryVar::DefUpdate> current_remapped_def =
|
||||
ToQuery(current_id_map, current_def->def);
|
||||
[this, &previous_id_map, ¤t_id_map](IndexVar* previous,
|
||||
IndexVar* current) {
|
||||
optional<QueryVar::Def> previous_remapped_def =
|
||||
ToQuery(previous_id_map, previous->def);
|
||||
optional<QueryVar::Def> current_remapped_def =
|
||||
ToQuery(current_id_map, current->def);
|
||||
if (current_remapped_def &&
|
||||
previous_remapped_def != current_remapped_def &&
|
||||
!current_remapped_def->detailed_name.empty())
|
||||
vars_def_update.push_back(*current_remapped_def);
|
||||
vars_def_update.push_back(
|
||||
QueryVar::DefUpdate(current->usr, *current_remapped_def));
|
||||
|
||||
PROCESS_UPDATE_DIFF(QueryVarId, vars_uses, uses, QueryLocation);
|
||||
});
|
||||
@ -619,7 +624,6 @@ IndexUpdate::IndexUpdate(const IdMap& previous_id_map,
|
||||
|
||||
// This function runs on an indexer thread.
|
||||
void IndexUpdate::Merge(const IndexUpdate& update) {
|
||||
|
||||
#define INDEX_UPDATE_APPEND(name) AddRange(&name, update.name);
|
||||
#define INDEX_UPDATE_MERGE(name) AddMergeableRange(&name, update.name);
|
||||
|
||||
@ -757,7 +761,7 @@ void QueryDatabase::ImportOrUpdate(
|
||||
// This function runs on the querydb thread.
|
||||
|
||||
for (auto& def : updates) {
|
||||
assert(!def.detailed_name.empty());
|
||||
assert(!def.value.detailed_name.empty());
|
||||
|
||||
auto it = usr_to_type.find(def.usr);
|
||||
assert(it != usr_to_type.end());
|
||||
@ -767,12 +771,12 @@ void QueryDatabase::ImportOrUpdate(
|
||||
|
||||
// Keep the existing definition if it is higher quality.
|
||||
if (existing.def && existing.def->definition_spelling &&
|
||||
!def.definition_spelling)
|
||||
!def.value.definition_spelling)
|
||||
continue;
|
||||
|
||||
existing.def = def;
|
||||
existing.def = def.value;
|
||||
UpdateDetailedNames(&existing.detailed_name_idx, SymbolKind::Type,
|
||||
it->second.id, def.detailed_name);
|
||||
it->second.id, def.value.detailed_name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -781,7 +785,7 @@ void QueryDatabase::ImportOrUpdate(
|
||||
// This function runs on the querydb thread.
|
||||
|
||||
for (auto& def : updates) {
|
||||
assert(!def.detailed_name.empty());
|
||||
assert(!def.value.detailed_name.empty());
|
||||
|
||||
auto it = usr_to_func.find(def.usr);
|
||||
assert(it != usr_to_func.end());
|
||||
@ -791,12 +795,12 @@ void QueryDatabase::ImportOrUpdate(
|
||||
|
||||
// Keep the existing definition if it is higher quality.
|
||||
if (existing.def && existing.def->definition_spelling &&
|
||||
!def.definition_spelling)
|
||||
!def.value.definition_spelling)
|
||||
continue;
|
||||
|
||||
existing.def = def;
|
||||
existing.def = def.value;
|
||||
UpdateDetailedNames(&existing.detailed_name_idx, SymbolKind::Func,
|
||||
it->second.id, def.detailed_name);
|
||||
it->second.id, def.value.detailed_name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -805,7 +809,7 @@ void QueryDatabase::ImportOrUpdate(
|
||||
// This function runs on the querydb thread.
|
||||
|
||||
for (auto& def : updates) {
|
||||
assert(!def.detailed_name.empty());
|
||||
assert(!def.value.detailed_name.empty());
|
||||
|
||||
auto it = usr_to_var.find(def.usr);
|
||||
assert(it != usr_to_var.end());
|
||||
@ -815,13 +819,13 @@ void QueryDatabase::ImportOrUpdate(
|
||||
|
||||
// Keep the existing definition if it is higher quality.
|
||||
if (existing.def && existing.def->definition_spelling &&
|
||||
!def.definition_spelling)
|
||||
!def.value.definition_spelling)
|
||||
continue;
|
||||
|
||||
existing.def = def;
|
||||
if (!def.is_local)
|
||||
existing.def = def.value;
|
||||
if (!def.value.is_local)
|
||||
UpdateDetailedNames(&existing.detailed_name_idx, SymbolKind::Var,
|
||||
it->second.id, def.detailed_name);
|
||||
it->second.id, def.value.detailed_name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -922,7 +926,7 @@ TEST_SUITE("query") {
|
||||
IndexUpdate update = GetDelta(previous, current);
|
||||
|
||||
REQUIRE(update.types_removed == std::vector<Usr>{});
|
||||
REQUIRE(update.types_def_update == std::vector<QueryType::DefUpdate>{});
|
||||
REQUIRE(update.types_def_update.empty());
|
||||
REQUIRE(update.types_uses.size() == 1);
|
||||
REQUIRE(update.types_uses[0].to_remove.size() == 1);
|
||||
REQUIRE(update.types_uses[0].to_remove[0].range == Range(Position(1, 0)));
|
||||
|
41
src/query.h
41
src/query.h
@ -166,6 +166,21 @@ void Reflect(TVisitor& visitor, MergeableUpdate<TId, TValue>& value) {
|
||||
REFLECT_MEMBER_END();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct WithUsr {
|
||||
Usr usr;
|
||||
T value;
|
||||
|
||||
WithUsr(const Usr& usr, const T& value) : usr(usr), value(value) {}
|
||||
};
|
||||
template <typename TVisitor, typename T>
|
||||
void Reflect(TVisitor& visitor, WithUsr<T>& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
REFLECT_MEMBER(usr);
|
||||
REFLECT_MEMBER(value);
|
||||
REFLECT_MEMBER_END();
|
||||
}
|
||||
|
||||
struct QueryFile {
|
||||
struct Def {
|
||||
std::string path;
|
||||
@ -186,7 +201,7 @@ struct QueryFile {
|
||||
optional<DefUpdate> def;
|
||||
size_t detailed_name_idx = (size_t)-1;
|
||||
|
||||
QueryFile(const std::string& path) {
|
||||
explicit QueryFile(const std::string& path) {
|
||||
def = DefUpdate();
|
||||
def->path = path;
|
||||
}
|
||||
@ -199,52 +214,58 @@ MAKE_REFLECT_STRUCT(QueryFile::Def,
|
||||
inactive_regions);
|
||||
|
||||
struct QueryType {
|
||||
using DefUpdate = TypeDefDefinitionData<QueryTypeId,
|
||||
using Def = TypeDefDefinitionData<QueryTypeId,
|
||||
QueryFuncId,
|
||||
QueryVarId,
|
||||
QueryLocation>;
|
||||
using DefUpdate = WithUsr<Def>;
|
||||
using DerivedUpdate = MergeableUpdate<QueryTypeId, QueryTypeId>;
|
||||
using InstancesUpdate = MergeableUpdate<QueryTypeId, QueryVarId>;
|
||||
using UsesUpdate = MergeableUpdate<QueryTypeId, QueryLocation>;
|
||||
|
||||
optional<DefUpdate> def;
|
||||
Usr usr;
|
||||
optional<Def> def;
|
||||
std::vector<QueryTypeId> derived;
|
||||
std::vector<QueryVarId> instances;
|
||||
std::vector<QueryLocation> uses;
|
||||
size_t detailed_name_idx = (size_t)-1;
|
||||
|
||||
QueryType(const Usr& usr) : def(usr) {}
|
||||
explicit QueryType(const Usr& usr) : usr(usr) {}
|
||||
};
|
||||
|
||||
struct QueryFunc {
|
||||
using DefUpdate = FuncDefDefinitionData<QueryTypeId,
|
||||
using Def = FuncDefDefinitionData<QueryTypeId,
|
||||
QueryFuncId,
|
||||
QueryVarId,
|
||||
QueryFuncRef,
|
||||
QueryLocation>;
|
||||
using DefUpdate = WithUsr<Def>;
|
||||
using DeclarationsUpdate = MergeableUpdate<QueryFuncId, QueryLocation>;
|
||||
using DerivedUpdate = MergeableUpdate<QueryFuncId, QueryFuncId>;
|
||||
using CallersUpdate = MergeableUpdate<QueryFuncId, QueryFuncRef>;
|
||||
|
||||
optional<DefUpdate> def;
|
||||
Usr usr;
|
||||
optional<Def> def;
|
||||
std::vector<QueryLocation> declarations;
|
||||
std::vector<QueryFuncId> derived;
|
||||
std::vector<QueryFuncRef> callers;
|
||||
size_t detailed_name_idx = (size_t)-1;
|
||||
|
||||
QueryFunc(const Usr& usr) : def(usr) {}
|
||||
explicit QueryFunc(const Usr& usr) : usr(usr) {}
|
||||
};
|
||||
|
||||
struct QueryVar {
|
||||
using DefUpdate =
|
||||
using Def =
|
||||
VarDefDefinitionData<QueryTypeId, QueryFuncId, QueryVarId, QueryLocation>;
|
||||
using DefUpdate = WithUsr<Def>;
|
||||
using UsesUpdate = MergeableUpdate<QueryVarId, QueryLocation>;
|
||||
|
||||
optional<DefUpdate> def;
|
||||
Usr usr;
|
||||
optional<Def> def;
|
||||
std::vector<QueryLocation> uses;
|
||||
size_t detailed_name_idx = (size_t)-1;
|
||||
|
||||
QueryVar(const Usr& usr) : def(usr) {}
|
||||
explicit QueryVar(const Usr& usr) : usr(usr) {}
|
||||
};
|
||||
|
||||
struct IndexUpdate {
|
||||
|
@ -96,7 +96,7 @@ template <typename TVisitor>
|
||||
void Reflect(TVisitor& visitor, IndexType& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
REFLECT_MEMBER2("id", value.id);
|
||||
REFLECT_MEMBER2("usr", value.def.usr);
|
||||
REFLECT_MEMBER2("usr", value.usr);
|
||||
REFLECT_MEMBER2("short_name", value.def.short_name);
|
||||
REFLECT_MEMBER2("detailed_name", value.def.detailed_name);
|
||||
REFLECT_MEMBER2("definition_spelling", value.def.definition_spelling);
|
||||
@ -117,7 +117,7 @@ void Reflect(TVisitor& visitor, IndexFunc& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
REFLECT_MEMBER2("id", value.id);
|
||||
REFLECT_MEMBER2("is_operator", value.def.is_operator);
|
||||
REFLECT_MEMBER2("usr", value.def.usr);
|
||||
REFLECT_MEMBER2("usr", value.usr);
|
||||
REFLECT_MEMBER2("short_name", value.def.short_name);
|
||||
REFLECT_MEMBER2("detailed_name", value.def.detailed_name);
|
||||
REFLECT_MEMBER2("declarations", value.declarations);
|
||||
@ -136,7 +136,7 @@ template <typename TVisitor>
|
||||
void Reflect(TVisitor& visitor, IndexVar& value) {
|
||||
REFLECT_MEMBER_START();
|
||||
REFLECT_MEMBER2("id", value.id);
|
||||
REFLECT_MEMBER2("usr", value.def.usr);
|
||||
REFLECT_MEMBER2("usr", value.usr);
|
||||
REFLECT_MEMBER2("short_name", value.def.short_name);
|
||||
REFLECT_MEMBER2("detailed_name", value.def.detailed_name);
|
||||
REFLECT_MEMBER2("declaration", value.def.declaration);
|
||||
@ -220,16 +220,16 @@ std::unique_ptr<IndexFile> Deserialize(std::string path,
|
||||
file->path = path;
|
||||
file->id_cache.primary_file = file->path;
|
||||
for (const auto& type : file->types) {
|
||||
file->id_cache.type_id_to_usr[type.id] = type.def.usr;
|
||||
file->id_cache.usr_to_type_id[type.def.usr] = type.id;
|
||||
file->id_cache.type_id_to_usr[type.id] = type.usr;
|
||||
file->id_cache.usr_to_type_id[type.usr] = type.id;
|
||||
}
|
||||
for (const auto& func : file->funcs) {
|
||||
file->id_cache.func_id_to_usr[func.id] = func.def.usr;
|
||||
file->id_cache.usr_to_func_id[func.def.usr] = func.id;
|
||||
file->id_cache.func_id_to_usr[func.id] = func.usr;
|
||||
file->id_cache.usr_to_func_id[func.usr] = func.id;
|
||||
}
|
||||
for (const auto& var : file->vars) {
|
||||
file->id_cache.var_id_to_usr[var.id] = var.def.usr;
|
||||
file->id_cache.usr_to_var_id[var.def.usr] = var.id;
|
||||
file->id_cache.var_id_to_usr[var.id] = var.usr;
|
||||
file->id_cache.usr_to_var_id[var.usr] = var.id;
|
||||
}
|
||||
|
||||
return file;
|
||||
|
Loading…
Reference in New Issue
Block a user