From 430b9ef61bc4a106dba0e6b685b1891d351f17f3 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sun, 26 Feb 2017 23:25:59 -0800 Subject: [PATCH] remove groupid --- indexer.cpp | 8 ++++---- indexer.h | 29 ++++++++--------------------- query.cc | 3 +-- 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/indexer.cpp b/indexer.cpp index 1fe67348..fa2132e1 100644 --- a/indexer.cpp +++ b/indexer.cpp @@ -21,7 +21,7 @@ TypeId IndexedFile::ToTypeId(const std::string& usr) { if (it != id_cache->usr_to_type_id.end()) return it->second; - TypeId id(id_cache->group, types.size()); + TypeId id(types.size()); types.push_back(IndexedTypeDef(id, usr)); id_cache->usr_to_type_id[usr] = id; id_cache->type_id_to_usr[id] = usr; @@ -32,7 +32,7 @@ FuncId IndexedFile::ToFuncId(const std::string& usr) { if (it != id_cache->usr_to_func_id.end()) return it->second; - FuncId id(id_cache->group, funcs.size()); + FuncId id(funcs.size()); funcs.push_back(IndexedFuncDef(id, usr)); id_cache->usr_to_func_id[usr] = id; id_cache->func_id_to_usr[id] = usr; @@ -43,7 +43,7 @@ VarId IndexedFile::ToVarId(const std::string& usr) { if (it != id_cache->usr_to_var_id.end()) return it->second; - VarId id(id_cache->group, vars.size()); + VarId id(vars.size()); vars.push_back(IndexedVarDef(id, usr)); id_cache->usr_to_var_id[usr] = id; id_cache->var_id_to_usr[id] = usr; @@ -990,7 +990,7 @@ int main(int argc, char** argv) { // Run test. std::cout << "[START] " << path << std::endl; - IdCache id_cache(1); + IdCache id_cache; IndexedFile db = Parse(&id_cache, path, {}); std::string actual_output = db.ToString(); diff --git a/indexer.h b/indexer.h index cf1d514f..04fae638 100644 --- a/indexer.h +++ b/indexer.h @@ -26,23 +26,18 @@ struct IndexedVarDef; using namespace std::experimental; -using GroupId = int; - template struct Id { - GroupId group; uint64_t id; Id() : id(0) {} // Needed for containers. Do not use directly. - Id(GroupId group, uint64_t id) : group(group), id(id) {} + Id(uint64_t id) : id(id) {} bool operator==(const Id& other) const { - assert(group == other.group && "Cannot compare Ids from different groups"); return id == other.id; } bool operator<(const Id& other) const { - assert(group == other.group); return id < other.id; } }; @@ -51,7 +46,7 @@ namespace std { template struct hash> { size_t operator()(const Id& k) const { - return ((hash()(k.id) ^ (hash()(k.group) << 1)) >> 1); + return hash()(k.id); } }; } @@ -71,14 +66,12 @@ using VarId = Id; struct Location { bool interesting; - int raw_file_group; int raw_file_id; int line; int column; Location() { interesting = false; - raw_file_group = -1; raw_file_id = -1; line = -1; column = -1; @@ -86,14 +79,13 @@ struct Location { Location(bool interesting, FileId file, uint32_t line, uint32_t column) { this->interesting = interesting; - this->raw_file_group = file.group; this->raw_file_id = file.id; this->line = line; this->column = column; } FileId file_id() const { - return FileId(raw_file_id, raw_file_group); + return FileId(raw_file_id); } std::string ToString() { @@ -123,7 +115,6 @@ struct Location { bool IsEqualTo(const Location& o) const { // When comparing, ignore the value of |interesting|. return - raw_file_group == o.raw_file_group && raw_file_id == o.raw_file_id && line == o.line && column == o.column; @@ -135,7 +126,6 @@ struct Location { bool operator<(const Location& o) const { return interesting < o.interesting && - raw_file_group < o.raw_file_group && raw_file_id < o.raw_file_id && line < o.line && column < o.column; @@ -466,9 +456,6 @@ namespace std { } struct IdCache { - // NOTE: Every Id is resolved to a file_id of 0. The correct file_id needs - // to get fixed up when inserting into the real db. - GroupId group; std::unordered_map file_path_to_file_id; std::unordered_map usr_to_type_id; std::unordered_map usr_to_func_id; @@ -478,10 +465,10 @@ struct IdCache { std::unordered_map func_id_to_usr; std::unordered_map var_id_to_usr; - IdCache(GroupId group) : group(group) { + IdCache() { // Reserve id 0 for unfound. - file_path_to_file_id[""] = FileId(group, 0); - file_id_to_file_path[FileId(group, 0)] = ""; + file_path_to_file_id[""] = FileId(0); + file_id_to_file_path[FileId(0)] = ""; } Location Resolve(const CXSourceLocation& cx_loc, bool interesting) { @@ -489,7 +476,7 @@ struct IdCache { unsigned int line, column, offset; clang_getSpellingLocation(cx_loc, &file, &line, &column, &offset); - FileId file_id(-1, -1); + FileId file_id(-1); if (file != nullptr) { std::string path = clang::ToString(clang_getFileName(file)); @@ -498,7 +485,7 @@ struct IdCache { file_id = it->second; } else { - file_id = FileId(group, file_path_to_file_id.size()); + file_id = FileId(file_path_to_file_id.size()); file_path_to_file_id[path] = file_id; file_id_to_file_path[file_id] = path; } diff --git a/query.cc b/query.cc index 69ca2561..ec7378a0 100644 --- a/query.cc +++ b/query.cc @@ -620,8 +620,7 @@ void QueryableDatabase::ApplyIndexUpdate(IndexUpdate* update) { int main233(int argc, char** argv) { - // TODO: Unify UserToIdResolver and FileDb - IdCache id_cache(1); + IdCache id_cache; IndexedFile indexed_file_a = Parse(&id_cache, "full_tests/index_delta/a_v0.cc", {}); std::cout << indexed_file_a.ToString() << std::endl;