mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-29 11:01:57 +00:00
Change symbol id from size_t to RawId (uint32_t currently)
This commit is contained in:
parent
f266cb7b2a
commit
6933870962
@ -1464,12 +1464,12 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
||||
IndexFuncId parent_func_id =
|
||||
db->ToFuncId(decl->semanticContainer->cursor);
|
||||
var->def.parent_kind = SymbolKind::Func;
|
||||
var->def.parent_id = size_t(parent_func_id);
|
||||
var->def.parent_id = Id<void>(parent_func_id);
|
||||
} else if (IsTypeDefinition(decl->semanticContainer)) {
|
||||
IndexTypeId parent_type_id =
|
||||
db->ToTypeId(decl->semanticContainer->cursor);
|
||||
var->def.parent_kind = SymbolKind::Type;
|
||||
var->def.parent_id = size_t(parent_type_id);
|
||||
var->def.parent_id = Id<void>(parent_type_id);
|
||||
db->Resolve(parent_type_id)->def.vars.push_back(var_id);
|
||||
}
|
||||
}
|
||||
|
@ -36,20 +36,22 @@ struct IndexVar;
|
||||
enum class SymbolKind : uint8_t { Invalid, File, Type, Func, Var };
|
||||
MAKE_REFLECT_TYPE_PROXY(SymbolKind);
|
||||
|
||||
using RawId = uint32_t;
|
||||
|
||||
template <typename T>
|
||||
struct Id {
|
||||
size_t id;
|
||||
RawId id;
|
||||
|
||||
// Invalid id.
|
||||
Id() : id(-1) {}
|
||||
explicit Id(size_t id) : id(id) {}
|
||||
explicit Id(RawId id) : id(id) {}
|
||||
template <typename U>
|
||||
explicit Id(Id<U> o) : id(o.id) {}
|
||||
|
||||
// Needed for google::dense_hash_map.
|
||||
explicit operator size_t() const { return id; }
|
||||
explicit operator RawId() const { return id; }
|
||||
|
||||
bool HasValue() const { return id != size_t(-1); }
|
||||
bool HasValue() const { return id != RawId(-1); }
|
||||
|
||||
bool operator==(const Id<T>& other) const { return id == other.id; }
|
||||
|
||||
@ -99,7 +101,7 @@ struct IndexFuncRef {
|
||||
IndexFuncRef(IndexFuncId id, Range loc, bool is_implicit)
|
||||
: id(id), loc(loc), is_implicit(is_implicit) {}
|
||||
IndexFuncRef(Range loc, bool is_implicit)
|
||||
: id(IndexFuncId((size_t)-1)), loc(loc), is_implicit(is_implicit) {}
|
||||
: loc(loc), is_implicit(is_implicit) {}
|
||||
|
||||
inline bool operator==(const IndexFuncRef& other) {
|
||||
return id == other.id && loc == other.loc &&
|
||||
@ -109,12 +111,11 @@ struct IndexFuncRef {
|
||||
return !(*this == other);
|
||||
}
|
||||
inline bool operator<(const IndexFuncRef& other) const {
|
||||
if (id < other.id)
|
||||
return true;
|
||||
if (id == other.id && loc < other.loc)
|
||||
return true;
|
||||
return id == other.id && loc == other.loc &&
|
||||
is_implicit < other.is_implicit;
|
||||
if (id != other.id)
|
||||
return id < other.id;
|
||||
if (loc != other.loc)
|
||||
return loc < other.loc;
|
||||
return is_implicit < other.is_implicit;
|
||||
}
|
||||
};
|
||||
|
||||
@ -144,12 +145,11 @@ inline void Reflect(Writer& visitor, IndexFuncRef& value) {
|
||||
if (value.is_implicit)
|
||||
s += "~";
|
||||
|
||||
// id.id is unsigned, special case 0 value
|
||||
if (value.id.id == static_cast<size_t>(-1)) {
|
||||
s += "-1";
|
||||
} else {
|
||||
// id.id is unsigned, special case -1 value
|
||||
if (value.id.HasValue())
|
||||
s += std::to_string(value.id.id);
|
||||
}
|
||||
else
|
||||
s += "-1";
|
||||
|
||||
s += "@" + value.loc.ToString();
|
||||
visitor.String(s.c_str());
|
||||
@ -403,7 +403,7 @@ struct VarDefDefinitionData {
|
||||
Maybe<TypeId> variable_type;
|
||||
|
||||
// Function/type which declares this one.
|
||||
size_t parent_id = size_t(-1);
|
||||
Maybe<Id<void>> parent_id;
|
||||
int16_t short_name_offset = 0;
|
||||
int16_t short_name_size = 0;
|
||||
SymbolKind parent_kind = SymbolKind::Invalid;
|
||||
|
@ -54,7 +54,7 @@ bool FindFileOrFail(QueryDatabase* db,
|
||||
}
|
||||
|
||||
if (out_file_id)
|
||||
*out_file_id = QueryFileId((size_t)-1);
|
||||
*out_file_id = QueryFileId();
|
||||
|
||||
bool indexing = project->absolute_path_to_entry_index_.find(absolute_path) !=
|
||||
project->absolute_path_to_entry_index_.end();
|
||||
|
18
src/query.cc
18
src/query.cc
@ -304,7 +304,7 @@ Maybe<QueryFileId> GetQueryFileIdFromPath(QueryDatabase* query_db,
|
||||
if (!create_if_missing)
|
||||
return {};
|
||||
|
||||
size_t idx = query_db->files.size();
|
||||
RawId idx = query_db->files.size();
|
||||
query_db->usr_to_file[normalized_path] = QueryFileId(idx);
|
||||
query_db->files.push_back(QueryFile(path));
|
||||
return QueryFileId(idx);
|
||||
@ -319,7 +319,7 @@ Maybe<QueryTypeId> GetQueryTypeIdFromUsr(QueryDatabase* query_db,
|
||||
if (!create_if_missing)
|
||||
return {};
|
||||
|
||||
size_t idx = query_db->types.size();
|
||||
RawId idx = query_db->types.size();
|
||||
query_db->usr_to_type[usr] = QueryTypeId(idx);
|
||||
query_db->types.push_back(QueryType(usr));
|
||||
return QueryTypeId(idx);
|
||||
@ -334,7 +334,7 @@ Maybe<QueryFuncId> GetQueryFuncIdFromUsr(QueryDatabase* query_db,
|
||||
if (!create_if_missing)
|
||||
return {};
|
||||
|
||||
size_t idx = query_db->funcs.size();
|
||||
RawId idx = query_db->funcs.size();
|
||||
query_db->usr_to_func[usr] = QueryFuncId(idx);
|
||||
query_db->funcs.push_back(QueryFunc(usr));
|
||||
return QueryFuncId(idx);
|
||||
@ -349,7 +349,7 @@ Maybe<QueryVarId> GetQueryVarIdFromUsr(QueryDatabase* query_db,
|
||||
if (!create_if_missing)
|
||||
return {};
|
||||
|
||||
size_t idx = query_db->vars.size();
|
||||
RawId idx = query_db->vars.size();
|
||||
query_db->usr_to_var[usr] = QueryVarId(idx);
|
||||
query_db->vars.push_back(QueryVar(usr));
|
||||
return QueryVarId(idx);
|
||||
@ -956,15 +956,15 @@ void QueryDatabase::ImportOrUpdate(
|
||||
|
||||
void QueryDatabase::UpdateSymbols(Maybe<Id<void>>* symbol_idx,
|
||||
SymbolKind kind,
|
||||
size_t idx) {
|
||||
RawId idx) {
|
||||
if (!symbol_idx->has_value()) {
|
||||
*symbol_idx = Id<void>(symbols.size());
|
||||
symbols.push_back(SymbolIdx(kind, idx));
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view QueryDatabase::GetSymbolDetailedName(size_t symbol_idx) const {
|
||||
size_t idx = symbols[symbol_idx].idx;
|
||||
std::string_view QueryDatabase::GetSymbolDetailedName(RawId symbol_idx) const {
|
||||
RawId idx = symbols[symbol_idx].idx;
|
||||
switch (symbols[symbol_idx].kind) {
|
||||
default:
|
||||
break;
|
||||
@ -988,8 +988,8 @@ std::string_view QueryDatabase::GetSymbolDetailedName(size_t symbol_idx) const {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string_view QueryDatabase::GetSymbolShortName(size_t symbol_idx) const {
|
||||
size_t idx = symbols[symbol_idx].idx;
|
||||
std::string_view QueryDatabase::GetSymbolShortName(RawId symbol_idx) const {
|
||||
RawId idx = symbols[symbol_idx].idx;
|
||||
switch (symbols[symbol_idx].kind) {
|
||||
default:
|
||||
break;
|
||||
|
12
src/query.h
12
src/query.h
@ -61,12 +61,12 @@ struct hash<::SymbolKind> {
|
||||
|
||||
struct SymbolIdx {
|
||||
SymbolKind kind;
|
||||
size_t idx;
|
||||
RawId idx;
|
||||
|
||||
SymbolIdx()
|
||||
: kind(SymbolKind::Invalid),
|
||||
idx((size_t)-1) {} // Default ctor needed by stdlib. Do not use.
|
||||
SymbolIdx(SymbolKind kind, uint64_t idx) : kind(kind), idx(idx) {}
|
||||
idx(RawId(-1)) {} // Default ctor needed by stdlib. Do not use.
|
||||
SymbolIdx(SymbolKind kind, RawId idx) : kind(kind), idx(idx) {}
|
||||
|
||||
bool operator==(const SymbolIdx& that) const {
|
||||
return kind == that.kind && idx == that.idx;
|
||||
@ -386,9 +386,9 @@ struct QueryDatabase {
|
||||
void ImportOrUpdate(const std::vector<QueryType::DefUpdate>& updates);
|
||||
void ImportOrUpdate(const std::vector<QueryFunc::DefUpdate>& updates);
|
||||
void ImportOrUpdate(const std::vector<QueryVar::DefUpdate>& updates);
|
||||
void UpdateSymbols(Maybe<Id<void>>* symbol_idx, SymbolKind kind, size_t idx);
|
||||
std::string_view GetSymbolDetailedName(size_t symbol_idx) const;
|
||||
std::string_view GetSymbolShortName(size_t symbol_idx) const;
|
||||
void UpdateSymbols(Maybe<Id<void>>* symbol_idx, SymbolKind kind, RawId idx);
|
||||
std::string_view GetSymbolDetailedName(RawId symbol_idx) const;
|
||||
std::string_view GetSymbolShortName(RawId symbol_idx) const;
|
||||
|
||||
// Query the indexing structure to look up symbol id for given Usr.
|
||||
Maybe<QueryFileId> GetQueryFileIdFromPath(const std::string& path);
|
||||
|
Loading…
Reference in New Issue
Block a user