mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 20:12:33 +00:00
Indexer spelling lookup cannot fail
This commit is contained in:
parent
121336c976
commit
2e8e3d29c5
@ -756,9 +756,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
case CXIdxEntity_Field:
|
case CXIdxEntity_Field:
|
||||||
case CXIdxEntity_Variable:
|
case CXIdxEntity_Variable:
|
||||||
case CXIdxEntity_CXXStaticVariable: {
|
case CXIdxEntity_CXXStaticVariable: {
|
||||||
optional<Range> decl_loc_spelling = db->id_cache.ResolveSpelling(decl->cursor, false /*interesting*/);
|
Range decl_loc_spelling = db->id_cache.ResolveSpelling(decl->cursor, false /*interesting*/);
|
||||||
if (!decl_loc_spelling)
|
|
||||||
break;
|
|
||||||
|
|
||||||
clang::Cursor decl_cursor = decl->cursor;
|
clang::Cursor decl_cursor = decl->cursor;
|
||||||
|
|
||||||
@ -789,7 +787,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
else {
|
else {
|
||||||
var_def->def.declaration = db->id_cache.ResolveSpelling(decl->cursor, false /*interesting*/);
|
var_def->def.declaration = db->id_cache.ResolveSpelling(decl->cursor, false /*interesting*/);
|
||||||
}
|
}
|
||||||
UniqueAdd(var_def->uses, decl_loc_spelling.value());
|
UniqueAdd(var_def->uses, decl_loc_spelling);
|
||||||
|
|
||||||
// std::cerr << std::endl << "Visiting declaration" << std::endl;
|
// std::cerr << std::endl << "Visiting declaration" << std::endl;
|
||||||
// Dump(decl_cursor);
|
// Dump(decl_cursor);
|
||||||
@ -838,9 +836,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
case CXIdxEntity_CXXInstanceMethod:
|
case CXIdxEntity_CXXInstanceMethod:
|
||||||
case CXIdxEntity_CXXStaticMethod:
|
case CXIdxEntity_CXXStaticMethod:
|
||||||
case CXIdxEntity_CXXConversionFunction: {
|
case CXIdxEntity_CXXConversionFunction: {
|
||||||
optional<Range> decl_loc_spelling = db->id_cache.ResolveSpelling(decl->cursor, false /*interesting*/);
|
Range decl_loc_spelling = db->id_cache.ResolveSpelling(decl->cursor, false /*interesting*/);
|
||||||
if (!decl_loc_spelling)
|
|
||||||
break;
|
|
||||||
|
|
||||||
clang::Cursor decl_cursor = decl->cursor;
|
clang::Cursor decl_cursor = decl->cursor;
|
||||||
clang::Cursor resolved =
|
clang::Cursor resolved =
|
||||||
@ -913,7 +909,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
// Mark a type reference at the ctor/dtor location.
|
// Mark a type reference at the ctor/dtor location.
|
||||||
// TODO: Should it be interesting?
|
// TODO: Should it be interesting?
|
||||||
if (is_ctor_or_dtor) {
|
if (is_ctor_or_dtor) {
|
||||||
Range type_usage_loc = decl_loc_spelling.value();
|
Range type_usage_loc = decl_loc_spelling;
|
||||||
UniqueAdd(declaring_type_def->uses, type_usage_loc);
|
UniqueAdd(declaring_type_def->uses, type_usage_loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1003,9 +999,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
|
|
||||||
case CXIdxEntity_Typedef:
|
case CXIdxEntity_Typedef:
|
||||||
case CXIdxEntity_CXXTypeAlias: {
|
case CXIdxEntity_CXXTypeAlias: {
|
||||||
optional<Range> decl_loc_spelling = db->id_cache.ResolveSpelling(decl->cursor, true /*interesting*/);
|
Range decl_loc_spelling = db->id_cache.ResolveSpelling(decl->cursor, true /*interesting*/);
|
||||||
if (!decl_loc_spelling)
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Note we want to fetch the first TypeRef. Running
|
// Note we want to fetch the first TypeRef. Running
|
||||||
// ResolveCursorType(decl->cursor) would return
|
// ResolveCursorType(decl->cursor) would return
|
||||||
@ -1026,7 +1020,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
|
|
||||||
type_def->def.definition_spelling = db->id_cache.ResolveSpelling(decl->cursor, false /*interesting*/);
|
type_def->def.definition_spelling = db->id_cache.ResolveSpelling(decl->cursor, false /*interesting*/);
|
||||||
type_def->def.definition_extent = db->id_cache.ResolveExtent(decl->cursor, false /*interesting*/);
|
type_def->def.definition_extent = db->id_cache.ResolveExtent(decl->cursor, false /*interesting*/);
|
||||||
UniqueAdd(type_def->uses, decl_loc_spelling.value());
|
UniqueAdd(type_def->uses, decl_loc_spelling);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1034,9 +1028,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
case CXIdxEntity_Union:
|
case CXIdxEntity_Union:
|
||||||
case CXIdxEntity_Struct:
|
case CXIdxEntity_Struct:
|
||||||
case CXIdxEntity_CXXClass: {
|
case CXIdxEntity_CXXClass: {
|
||||||
optional<Range> decl_loc_spelling = db->id_cache.ResolveSpelling(decl->cursor, true /*interesting*/);
|
Range decl_loc_spelling = db->id_cache.ResolveSpelling(decl->cursor, true /*interesting*/);
|
||||||
if (!decl_loc_spelling)
|
|
||||||
break;
|
|
||||||
|
|
||||||
IndexTypeId type_id = db->ToTypeId(decl->entityInfo->USR);
|
IndexTypeId type_id = db->ToTypeId(decl->entityInfo->USR);
|
||||||
IndexedTypeDef* type_def = db->Resolve(type_id);
|
IndexedTypeDef* type_def = db->Resolve(type_id);
|
||||||
@ -1065,7 +1057,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
|||||||
assert(decl->isDefinition);
|
assert(decl->isDefinition);
|
||||||
type_def->def.definition_spelling = db->id_cache.ResolveSpelling(decl->cursor, false /*interesting*/);
|
type_def->def.definition_spelling = db->id_cache.ResolveSpelling(decl->cursor, false /*interesting*/);
|
||||||
type_def->def.definition_extent = db->id_cache.ResolveExtent(decl->cursor, false /*interesting*/);
|
type_def->def.definition_extent = db->id_cache.ResolveExtent(decl->cursor, false /*interesting*/);
|
||||||
UniqueAdd(type_def->uses, decl_loc_spelling.value());
|
UniqueAdd(type_def->uses, decl_loc_spelling);
|
||||||
|
|
||||||
// type_def->alias_of
|
// type_def->alias_of
|
||||||
// type_def->funcs
|
// type_def->funcs
|
||||||
@ -1244,16 +1236,14 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
case CXIdxEntity_CXXStaticVariable:
|
case CXIdxEntity_CXXStaticVariable:
|
||||||
case CXIdxEntity_Variable:
|
case CXIdxEntity_Variable:
|
||||||
case CXIdxEntity_Field: {
|
case CXIdxEntity_Field: {
|
||||||
optional<Range> loc_spelling = db->id_cache.ResolveSpelling(ref->cursor, false /*interesting*/);
|
Range loc_spelling = db->id_cache.ResolveSpelling(ref->cursor, false /*interesting*/);
|
||||||
if (!loc_spelling)
|
|
||||||
break;
|
|
||||||
|
|
||||||
clang::Cursor referenced = ref->referencedEntity->cursor;
|
clang::Cursor referenced = ref->referencedEntity->cursor;
|
||||||
referenced = referenced.template_specialization_to_template_definition();
|
referenced = referenced.template_specialization_to_template_definition();
|
||||||
|
|
||||||
IndexVarId var_id = db->ToVarId(referenced.get_usr());
|
IndexVarId var_id = db->ToVarId(referenced.get_usr());
|
||||||
IndexedVarDef* var_def = db->Resolve(var_id);
|
IndexedVarDef* var_def = db->Resolve(var_id);
|
||||||
UniqueAdd(var_def->uses, loc_spelling.value());
|
UniqueAdd(var_def->uses, loc_spelling);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1273,9 +1263,7 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// TODO: search full history?
|
// TODO: search full history?
|
||||||
optional<Range> loc_spelling = db->id_cache.ResolveSpelling(ref->cursor, false /*interesting*/);
|
Range loc_spelling = db->id_cache.ResolveSpelling(ref->cursor, false /*interesting*/);
|
||||||
if (!loc_spelling)
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Note: be careful, calling db->ToFuncId invalidates the FuncDef* ptrs.
|
// Note: be careful, calling db->ToFuncId invalidates the FuncDef* ptrs.
|
||||||
IndexFuncId called_id = db->ToFuncId(ref->referencedEntity->USR);
|
IndexFuncId called_id = db->ToFuncId(ref->referencedEntity->USR);
|
||||||
@ -1284,11 +1272,11 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
IndexedFuncDef* caller_def = db->Resolve(caller_id);
|
IndexedFuncDef* caller_def = db->Resolve(caller_id);
|
||||||
IndexedFuncDef* called_def = db->Resolve(called_id);
|
IndexedFuncDef* called_def = db->Resolve(called_id);
|
||||||
|
|
||||||
AddFuncRef(&caller_def->def.callees, IndexFuncRef(called_id, loc_spelling.value()));
|
AddFuncRef(&caller_def->def.callees, IndexFuncRef(called_id, loc_spelling));
|
||||||
AddFuncRef(&called_def->callers, IndexFuncRef(caller_id, loc_spelling.value()));
|
AddFuncRef(&called_def->callers, IndexFuncRef(caller_id, loc_spelling));
|
||||||
} else {
|
} else {
|
||||||
IndexedFuncDef* called_def = db->Resolve(called_id);
|
IndexedFuncDef* called_def = db->Resolve(called_id);
|
||||||
AddFuncRef(&called_def->callers, IndexFuncRef(loc_spelling.value()));
|
AddFuncRef(&called_def->callers, IndexFuncRef(loc_spelling));
|
||||||
}
|
}
|
||||||
|
|
||||||
// For constructor/destructor, also add a usage against the type. Clang
|
// For constructor/destructor, also add a usage against the type. Clang
|
||||||
@ -1305,7 +1293,7 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
//clang_getSpellingLocation(clang_indexLoc_getCXSourceLocation(ref->loc), &file, &line, &column, &offset);
|
//clang_getSpellingLocation(clang_indexLoc_getCXSourceLocation(ref->loc), &file, &line, &column, &offset);
|
||||||
|
|
||||||
Range parent_loc = db->id_cache.ResolveSpelling(ref->parentEntity->cursor, true /*interesting*/);
|
Range parent_loc = db->id_cache.ResolveSpelling(ref->parentEntity->cursor, true /*interesting*/);
|
||||||
if (parent_loc.start != loc_spelling->start) {
|
if (parent_loc.start != loc_spelling.start) {
|
||||||
IndexedFuncDef* called_def = db->Resolve(called_id);
|
IndexedFuncDef* called_def = db->Resolve(called_id);
|
||||||
// I suspect it is possible for the declaring type to be null
|
// I suspect it is possible for the declaring type to be null
|
||||||
// when the class is invalid.
|
// when the class is invalid.
|
||||||
@ -1313,7 +1301,7 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
// assert(called_def->def.declaring_type.has_value());
|
// assert(called_def->def.declaring_type.has_value());
|
||||||
IndexedTypeDef* type_def =
|
IndexedTypeDef* type_def =
|
||||||
db->Resolve(called_def->def.declaring_type.value());
|
db->Resolve(called_def->def.declaring_type.value());
|
||||||
UniqueAdd(type_def->uses, loc_spelling.value().WithInteresting(true), false /*insert_if_not_present*/);
|
UniqueAdd(type_def->uses, loc_spelling.WithInteresting(true), false /*insert_if_not_present*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1326,9 +1314,7 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
case CXIdxEntity_Union:
|
case CXIdxEntity_Union:
|
||||||
case CXIdxEntity_Struct:
|
case CXIdxEntity_Struct:
|
||||||
case CXIdxEntity_CXXClass: {
|
case CXIdxEntity_CXXClass: {
|
||||||
optional<Range> loc_spelling = db->id_cache.ResolveSpelling(ref->cursor, false /*interesting*/);
|
Range loc_spelling = db->id_cache.ResolveSpelling(ref->cursor, false /*interesting*/);
|
||||||
if (!loc_spelling)
|
|
||||||
break;
|
|
||||||
|
|
||||||
clang::Cursor referenced = ref->referencedEntity->cursor;
|
clang::Cursor referenced = ref->referencedEntity->cursor;
|
||||||
referenced = referenced.template_specialization_to_template_definition();
|
referenced = referenced.template_specialization_to_template_definition();
|
||||||
@ -1352,7 +1338,7 @@ void indexEntityReference(CXClientData client_data,
|
|||||||
// Foo f;
|
// Foo f;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
UniqueAdd(referenced_def->uses, loc_spelling.value());
|
UniqueAdd(referenced_def->uses, loc_spelling);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,10 @@ optional<int> WorkingFile::GetBufferLineFromDiskLine(int index_line) const {
|
|||||||
|
|
||||||
// Note: |index_line| and |buffer_line| are 1-based.
|
// Note: |index_line| and |buffer_line| are 1-based.
|
||||||
|
|
||||||
assert(index_line >= 1 && index_line <= index_lines.size());
|
// TODO: reenable this assert once we are using the real indexed file.
|
||||||
|
//assert(index_line >= 1 && index_line <= index_lines.size());
|
||||||
|
if (index_line < 1 || index_line > index_lines.size())
|
||||||
|
return nullopt;
|
||||||
|
|
||||||
// Find the line in the cached index file. We'll try to find the most similar line
|
// Find the line in the cached index file. We'll try to find the most similar line
|
||||||
// in the buffer and return the index for that.
|
// in the buffer and return the index for that.
|
||||||
|
Loading…
Reference in New Issue
Block a user