From 7192db6e32e8ea7828ef52a50ef3d66761ac535a Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sun, 26 Feb 2017 23:32:10 -0800 Subject: [PATCH] misc cleanup --- indexer.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ indexer.h | 48 +++++------------------------------------------- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/indexer.cpp b/indexer.cpp index a588f0a6..35e96902 100644 --- a/indexer.cpp +++ b/indexer.cpp @@ -103,6 +103,48 @@ void IndexedTypeDef::AddUsage(Location loc, bool insert_if_not_present) { uses.push_back(loc); } +IdCache::IdCache() { + // Reserve id 0 for unfound. + file_path_to_file_id[""] = FileId(0); + file_id_to_file_path[FileId(0)] = ""; +} + +Location IdCache::Resolve(const CXSourceLocation& cx_loc, bool interesting) { + CXFile file; + unsigned int line, column, offset; + clang_getSpellingLocation(cx_loc, &file, &line, &column, &offset); + + FileId file_id(-1); + if (file != nullptr) { + std::string path = clang::ToString(clang_getFileName(file)); + + auto it = file_path_to_file_id.find(path); + if (it != file_path_to_file_id.end()) { + file_id = it->second; + } + else { + 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; + } + } + + return Location(interesting, file_id, line, column); +} + +Location IdCache::Resolve(const CXIdxLoc& cx_idx_loc, bool interesting) { + CXSourceLocation cx_loc = clang_indexLoc_getCXSourceLocation(cx_idx_loc); + return Resolve(cx_loc, interesting); +} + +Location IdCache::Resolve(const CXCursor& cx_cursor, bool interesting) { + return Resolve(clang_getCursorLocation(cx_cursor), interesting); +} + +Location IdCache::Resolve(const clang::Cursor& cursor, bool interesting) { + return Resolve(cursor.cx_cursor, interesting); +} + template bool Contains(const std::vector& vec, const T& element) { diff --git a/indexer.h b/indexer.h index 189b784d..bccec935 100644 --- a/indexer.h +++ b/indexer.h @@ -465,48 +465,11 @@ struct IdCache { std::unordered_map func_id_to_usr; std::unordered_map var_id_to_usr; - IdCache() { - // Reserve id 0 for unfound. - file_path_to_file_id[""] = FileId(0); - file_id_to_file_path[FileId(0)] = ""; - } - - Location Resolve(const CXSourceLocation& cx_loc, bool interesting) { - CXFile file; - unsigned int line, column, offset; - clang_getSpellingLocation(cx_loc, &file, &line, &column, &offset); - - FileId file_id(-1); - if (file != nullptr) { - std::string path = clang::ToString(clang_getFileName(file)); - - auto it = file_path_to_file_id.find(path); - if (it != file_path_to_file_id.end()) { - file_id = it->second; - } - else { - 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; - } - } - - return Location(interesting, file_id, line, column); - } - - Location Resolve(const CXIdxLoc& cx_idx_loc, bool interesting) { - CXSourceLocation cx_loc = clang_indexLoc_getCXSourceLocation(cx_idx_loc); - return Resolve(cx_loc, interesting); - } - - Location Resolve(const CXCursor& cx_cursor, bool interesting) { - return Resolve(clang_getCursorLocation(cx_cursor), interesting); - } - - Location Resolve(const clang::Cursor& cursor, bool interesting) { - return Resolve(cursor.cx_cursor, interesting); - } - + IdCache(); + Location Resolve(const CXSourceLocation& cx_loc, bool interesting); + Location Resolve(const CXIdxLoc& cx_idx_loc, bool interesting); + Location Resolve(const CXCursor& cx_cursor, bool interesting); + Location Resolve(const clang::Cursor& cursor, bool interesting); }; struct IndexedFile { @@ -526,7 +489,6 @@ struct IndexedFile { TypeId ToTypeId(const CXCursor& usr); FuncId ToFuncId(const CXCursor& usr); VarId ToVarId(const CXCursor& usr); - IndexedTypeDef* Resolve(TypeId id); IndexedFuncDef* Resolve(FuncId id); IndexedVarDef* Resolve(VarId id);