From a632f97a2d6b8d5fe5b934cc443ca7e49b2f1c72 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 7 Apr 2018 21:24:21 -0700 Subject: [PATCH] Remove import_manager.cc --- CMakeLists.txt | 1 - src/clang_cursor.cc | 49 ++++++++---------------------------------- src/clang_cursor.h | 24 +++++++++++---------- src/import_manager.cc | 14 ------------ src/import_manager.h | 14 +----------- src/import_pipeline.cc | 12 ++++++----- 6 files changed, 30 insertions(+), 84 deletions(-) delete mode 100644 src/import_manager.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 97d13160..818eb71c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -214,7 +214,6 @@ target_sources(ccls PRIVATE src/filesystem.cc src/fuzzy_match.cc src/iindexer.cc - src/import_manager.cc src/import_pipeline.cc src/include_complete.cc src/method.cc diff --git a/src/clang_cursor.cc b/src/clang_cursor.cc index 35197f72..efb297c4 100644 --- a/src/clang_cursor.cc +++ b/src/clang_cursor.cc @@ -21,26 +21,18 @@ Range ResolveCXSourceRange(const CXSourceRange& range, CXFile* cx_file) { Position((int16_t)end_line - 1, (int16_t)end_column - 1)); } -ClangType::ClangType() : cx_type() {} - -ClangType::ClangType(const CXType& other) : cx_type(other) {} - -bool ClangType::operator==(const ClangType& rhs) const { - return clang_equalTypes(cx_type, rhs.cx_type); -} - ClangCursor ClangType::get_declaration() const { return clang_getTypeDeclaration(cx_type); } std::string ClangType::get_usr() const { - return ClangCursor(clang_getTypeDeclaration(cx_type)).get_usr(); + return ClangCursor{clang_getTypeDeclaration(cx_type)}.get_usr(); } Usr ClangType::get_usr_hash() const { if (is_builtin()) return static_cast(cx_type.kind); - return ClangCursor(clang_getTypeDeclaration(cx_type)).get_usr_hash(); + return ClangCursor{clang_getTypeDeclaration(cx_type)}.get_usr_hash(); } ClangType ClangType::get_canonical() const { @@ -79,7 +71,7 @@ std::string ClangType::get_spell_name() const { } ClangType ClangType::get_return_type() const { - return ClangType(clang_getResultType(cx_type)); + return clang_getResultType(cx_type); } std::vector ClangType::get_arguments() const { @@ -104,31 +96,8 @@ std::vector ClangType::get_template_arguments() const { return types; } -static_assert(sizeof(ClangCursor) == sizeof(CXCursor), - "Cursor must be the same size as CXCursor"); - -ClangCursor::ClangCursor() : cx_cursor(clang_getNullCursor()) {} - -ClangCursor::ClangCursor(const CXCursor& other) : cx_cursor(other) {} - -ClangCursor::operator bool() const { - return !clang_Cursor_isNull(cx_cursor); -} - -bool ClangCursor::operator==(const ClangCursor& rhs) const { - return clang_equalCursors(cx_cursor, rhs.cx_cursor); -} - -bool ClangCursor::operator!=(const ClangCursor& rhs) const { - return !(*this == rhs); -} - -CXCursorKind ClangCursor::get_kind() const { - return cx_cursor.kind; -} - ClangType ClangCursor::get_type() const { - return ClangType(clang_getCursorType(cx_cursor)); + return {clang_getCursorType(cx_cursor)}; } std::string ClangCursor::get_spell_name() const { @@ -175,23 +144,23 @@ ClangCursor ClangCursor::template_specialization_to_template_definition() } ClangCursor ClangCursor::get_referenced() const { - return ClangCursor(clang_getCursorReferenced(cx_cursor)); + return {clang_getCursorReferenced(cx_cursor)}; } ClangCursor ClangCursor::get_canonical() const { - return ClangCursor(clang_getCanonicalCursor(cx_cursor)); + return {clang_getCanonicalCursor(cx_cursor)}; } ClangCursor ClangCursor::get_definition() const { - return ClangCursor(clang_getCursorDefinition(cx_cursor)); + return {clang_getCursorDefinition(cx_cursor)}; } ClangCursor ClangCursor::get_lexical_parent() const { - return ClangCursor(clang_getCursorLexicalParent(cx_cursor)); + return {clang_getCursorLexicalParent(cx_cursor)}; } ClangCursor ClangCursor::get_semantic_parent() const { - return ClangCursor(clang_getCursorSemanticParent(cx_cursor)); + return {clang_getCursorSemanticParent(cx_cursor)}; } std::vector ClangCursor::get_arguments() const { diff --git a/src/clang_cursor.h b/src/clang_cursor.h index 6084408d..d0a1eed6 100644 --- a/src/clang_cursor.h +++ b/src/clang_cursor.h @@ -19,10 +19,8 @@ class ClangCursor; class ClangType { public: - ClangType(); - ClangType(const CXType& other); - - bool operator==(const ClangType& rhs) const; + ClangType() = default; + ClangType(const CXType& cx) : cx_type(cx) {} // Returns true if this is a fundamental type like int. bool is_builtin() const { @@ -50,14 +48,18 @@ class ClangType { class ClangCursor { public: - ClangCursor(); - ClangCursor(const CXCursor& other); + ClangCursor() = default; + ClangCursor(CXCursor cx) : cx_cursor(cx) {} + bool operator==(const ClangCursor& o) const { + return clang_equalCursors(cx_cursor, o.cx_cursor); + } + bool operator!=(const ClangCursor& o) const { + return !(*this == o); + } - explicit operator bool() const; - bool operator==(const ClangCursor& rhs) const; - bool operator!=(const ClangCursor& rhs) const; - - CXCursorKind get_kind() const; + CXCursorKind get_kind() const { + return cx_cursor.kind; + } ClangType get_type() const; std::string get_spell_name() const; Range get_spell(CXFile* cx_file = nullptr) const; diff --git a/src/import_manager.cc b/src/import_manager.cc deleted file mode 100644 index 11b13f29..00000000 --- a/src/import_manager.cc +++ /dev/null @@ -1,14 +0,0 @@ -#include "import_manager.h" - -bool ImportManager::TryMarkDependencyImported(const std::string& path) { - std::lock_guard lock(dependency_mutex_); - return dependency_imported_.insert(path).second; -} - -bool ImportManager::StartQueryDbImport(const std::string& path) { - return querydb_processing_.insert(path).second; -} - -void ImportManager::DoneQueryDbImport(const std::string& path) { - querydb_processing_.erase(path); -} diff --git a/src/import_manager.h b/src/import_manager.h index 57dc7ffe..7740aec1 100644 --- a/src/import_manager.h +++ b/src/import_manager.h @@ -9,21 +9,9 @@ // // NOTE: This is not thread safe and should only be used on the querydb thread. struct ImportManager { - // Try to mark the given dependency as imported. A dependency can only ever be - // imported once. - bool TryMarkDependencyImported(const std::string& path); - - // Try to import the given file into querydb. We should only ever be - // importing a file into querydb once per file. Returns true if the file - // can be imported. - bool StartQueryDbImport(const std::string& path); - - // The file has been fully imported and can be imported again later on. - void DoneQueryDbImport(const std::string& path); - std::unordered_set querydb_processing_; // TODO: use std::shared_mutex so we can have multiple readers. std::mutex dependency_mutex_; std::unordered_set dependency_imported_; -}; \ No newline at end of file +}; diff --git a/src/import_pipeline.cc b/src/import_pipeline.cc index 334b0e72..89bc4d38 100644 --- a/src/import_pipeline.cc +++ b/src/import_pipeline.cc @@ -167,9 +167,10 @@ ShouldParse FileNeedsParse( // If the file is a dependency but another file as already imported it, // don't bother. - if (!is_interactive && from && - !import_manager->TryMarkDependencyImported(path)) { - return ShouldParse::No; + if (!is_interactive && from) { + std::lock_guard lock(import_manager->dependency_mutex_); + if (!import_manager->dependency_imported_.insert(path).second) + return ShouldParse::No; } std::optional modification_timestamp = @@ -651,7 +652,8 @@ void QueryDb_DoIdMap(QueueManager* queue, // // Note, we must do this *after* we have checked for the previous index, // otherwise we will never actually generate the IdMap. - if (!import_manager->StartQueryDbImport(request->current->path)) { + if (!import_manager->querydb_processing_.insert(request->current->path) + .second) { LOG_S(INFO) << "Dropping index as it is already being imported for " << request->current->path; return; @@ -712,7 +714,7 @@ void QueryDb_OnIndexed(QueueManager* queue, // Mark the files as being done in querydb stage after we apply the index // update. - import_manager->DoneQueryDbImport(updated_file.value.path); + import_manager->querydb_processing_.erase(updated_file.value.path); } }