mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 20:12:33 +00:00
Small code cleanup in src/indexer.cc.
This commit is contained in:
parent
9b44bf7901
commit
fa240e3132
@ -472,11 +472,7 @@ bool Contains(const std::vector<T>& vec, const T& element) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int abortQuery(CXClientData client_data, void* reserved) {
|
void OnIndexDiagnostic(CXClientData client_data,
|
||||||
// 0 -> continue
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
void diagnostic(CXClientData client_data,
|
|
||||||
CXDiagnosticSet diagnostics,
|
CXDiagnosticSet diagnostics,
|
||||||
void* reserved) {
|
void* reserved) {
|
||||||
IndexParam* param = static_cast<IndexParam*>(client_data);
|
IndexParam* param = static_cast<IndexParam*>(client_data);
|
||||||
@ -505,13 +501,7 @@ void diagnostic(CXClientData client_data,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CXIdxClientFile enteredMainFile(CXClientData client_data,
|
CXIdxClientFile OnIndexIncludedFile(CXClientData client_data,
|
||||||
CXFile mainFile,
|
|
||||||
void* reserved) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
CXIdxClientFile ppIncludedFile(CXClientData client_data,
|
|
||||||
const CXIdxIncludedFileInfo* file) {
|
const CXIdxIncludedFileInfo* file) {
|
||||||
IndexParam* param = static_cast<IndexParam*>(client_data);
|
IndexParam* param = static_cast<IndexParam*>(client_data);
|
||||||
|
|
||||||
@ -534,16 +524,6 @@ CXIdxClientFile ppIncludedFile(CXClientData client_data,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CXIdxClientASTFile importedASTFile(CXClientData client_data,
|
|
||||||
const CXIdxImportedASTFileInfo*) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
CXIdxClientContainer startedTranslationUnit(CXClientData client_data,
|
|
||||||
void* reserved) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClangCursor::VisitResult DumpVisitor(ClangCursor cursor,
|
ClangCursor::VisitResult DumpVisitor(ClangCursor cursor,
|
||||||
ClangCursor parent,
|
ClangCursor parent,
|
||||||
int* level) {
|
int* level) {
|
||||||
@ -972,7 +952,7 @@ ClangCursor::VisitResult VisitMacroDefinitionAndExpansions(ClangCursor cursor,
|
|||||||
return ClangCursor::VisitResult::Continue;
|
return ClangCursor::VisitResult::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
||||||
if (!kIndexStdDeclarations &&
|
if (!kIndexStdDeclarations &&
|
||||||
clang_Location_isInSystemHeader(
|
clang_Location_isInSystemHeader(
|
||||||
clang_indexLoc_getCXSourceLocation(decl->loc)))
|
clang_indexLoc_getCXSourceLocation(decl->loc)))
|
||||||
@ -1388,8 +1368,7 @@ bool IsFunctionCallContext(CXCursorKind kind) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void indexEntityReference(CXClientData client_data,
|
void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
|
||||||
const CXIdxEntityRefInfo* ref) {
|
|
||||||
// Don't index references from or to system headers.
|
// Don't index references from or to system headers.
|
||||||
if (clang_Location_isInSystemHeader(
|
if (clang_Location_isInSystemHeader(
|
||||||
clang_indexLoc_getCXSourceLocation(ref->loc)) ||
|
clang_indexLoc_getCXSourceLocation(ref->loc)) ||
|
||||||
@ -1658,10 +1637,17 @@ std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
|
|||||||
const std::vector<CXUnsavedFile>& file_contents) {
|
const std::vector<CXUnsavedFile>& file_contents) {
|
||||||
Timer timer;
|
Timer timer;
|
||||||
|
|
||||||
IndexerCallbacks callbacks[] = {{&abortQuery, &diagnostic, &enteredMainFile,
|
IndexerCallbacks callback = {0};
|
||||||
&ppIncludedFile, &importedASTFile,
|
// Available callbacks:
|
||||||
&startedTranslationUnit, &indexDeclaration,
|
// - abortQuery
|
||||||
&indexEntityReference}};
|
// - enteredMainFile
|
||||||
|
// - ppIncludedFile
|
||||||
|
// - importedASTFile
|
||||||
|
// - startedTranslationUnit
|
||||||
|
callback.diagnostic = &OnIndexDiagnostic;
|
||||||
|
callback.ppIncludedFile = &OnIndexIncludedFile;
|
||||||
|
callback.indexDeclaration = &OnIndexDeclaration;
|
||||||
|
callback.indexEntityReference = &OnIndexReference;
|
||||||
|
|
||||||
FileConsumer file_consumer(file_consumer_shared, file);
|
FileConsumer file_consumer(file_consumer_shared, file);
|
||||||
IndexParam param(tu, &file_consumer);
|
IndexParam param(tu, &file_consumer);
|
||||||
@ -1675,11 +1661,24 @@ std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
|
|||||||
|
|
||||||
// std::cerr << "!! [START] Indexing " << file << std::endl;
|
// std::cerr << "!! [START] Indexing " << file << std::endl;
|
||||||
CXIndexAction index_action = clang_IndexAction_create(index->cx_index);
|
CXIndexAction index_action = clang_IndexAction_create(index->cx_index);
|
||||||
clang_indexTranslationUnit(index_action, ¶m, callbacks, sizeof(callbacks),
|
|
||||||
|
// NOTE: libclang re-enables crash recovery whenever a new index is created.
|
||||||
|
// To have clang crash toggle crash recovery right before calling
|
||||||
|
// clang_indexTranslationUnit.
|
||||||
|
// clang_toggleCrashRecovery(0);
|
||||||
|
|
||||||
|
// |index_result| is a CXErrorCode instance.
|
||||||
|
int index_result = clang_indexTranslationUnit(
|
||||||
|
index_action, ¶m, &callback, sizeof(IndexerCallbacks),
|
||||||
CXIndexOpt_IndexFunctionLocalSymbols |
|
CXIndexOpt_IndexFunctionLocalSymbols |
|
||||||
CXIndexOpt_SkipParsedBodiesInSession |
|
CXIndexOpt_SkipParsedBodiesInSession |
|
||||||
CXIndexOpt_IndexImplicitTemplateInstantiations,
|
CXIndexOpt_IndexImplicitTemplateInstantiations,
|
||||||
tu->cx_tu);
|
tu->cx_tu);
|
||||||
|
if (index_result != CXError_Success) {
|
||||||
|
LOG_S(WARNING) << "Indexing " << file
|
||||||
|
<< " failed with errno=" << index_result;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
clang_IndexAction_dispose(index_action);
|
clang_IndexAction_dispose(index_action);
|
||||||
// std::cerr << "!! [END] Indexing " << file << std::endl;
|
// std::cerr << "!! [END] Indexing " << file << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user