Remove import_manager.cc

This commit is contained in:
Fangrui Song 2018-04-07 21:24:21 -07:00
parent b872faa160
commit a632f97a2d
6 changed files with 30 additions and 84 deletions

View File

@ -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

View File

@ -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<Usr>(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> ClangType::get_arguments() const {
@ -104,31 +96,8 @@ std::vector<ClangType> 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> ClangCursor::get_arguments() const {

View File

@ -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;

View File

@ -1,14 +0,0 @@
#include "import_manager.h"
bool ImportManager::TryMarkDependencyImported(const std::string& path) {
std::lock_guard<std::mutex> 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);
}

View File

@ -9,18 +9,6 @@
//
// 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<std::string> querydb_processing_;
// TODO: use std::shared_mutex so we can have multiple readers.

View File

@ -167,8 +167,9 @@ 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)) {
if (!is_interactive && from) {
std::lock_guard<std::mutex> lock(import_manager->dependency_mutex_);
if (!import_manager->dependency_imported_.insert(path).second)
return ShouldParse::No;
}
@ -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);
}
}