Change declaration to declarations in IndexVar

This commit is contained in:
Fangrui Song 2018-01-26 18:20:17 -08:00
parent 6b3673a438
commit e892c23955
5 changed files with 14 additions and 14 deletions

View File

@ -561,7 +561,7 @@ void OnIndexReference_Function(IndexFile* db,
} // namespace
// static
int IndexFile::kCurrentVersion = 9;
int IndexFile::kCurrentVersion = 10;
IndexFile::IndexFile(const std::string& path,
const optional<std::string>& contents)
@ -1431,8 +1431,7 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
var->def.definition_spelling = decl_spell;
var->def.definition_extent = decl_cursor.get_extent();
} else {
var->def.declaration = decl_spell;
UniqueAdd(var->uses, decl_spell);
var->def.declarations.push_back(decl_spell);
}
AddDeclInitializerUsages(db, decl_cursor);

View File

@ -373,7 +373,7 @@ struct VarDefDefinitionData {
ClangStorageClass storage = ClangStorageClass::SC_Invalid;
optional<std::string> hover;
optional<std::string> comments;
optional<Range> declaration;
std::vector<Range> declarations;
// TODO: definitions should be a list of ranges, since there can be more
// than one - when??
optional<Range> definition_spelling;
@ -397,7 +397,7 @@ struct VarDefDefinitionData {
const VarDefDefinitionData<TypeId, FuncId, VarId, Range>& other) const {
return short_name == other.short_name &&
detailed_name == other.detailed_name && hover == other.hover &&
declaration == other.declaration &&
declarations.size() == other.declarations.size() &&
definition_spelling == other.definition_spelling &&
definition_extent == other.definition_extent &&
variable_type == other.variable_type &&

View File

@ -83,7 +83,7 @@ optional<QueryVar::Def> ToQuery(const IdMap& id_map, const IndexVar::Def& var) {
result.storage = var.storage;
result.hover = var.hover;
result.comments = var.comments;
result.declaration = id_map.ToQuery(var.declaration);
result.declarations = id_map.ToQuery(var.declarations);
result.definition_spelling = id_map.ToQuery(var.definition_spelling);
result.definition_extent = id_map.ToQuery(var.definition_extent);
result.variable_type = id_map.ToQuery(var.variable_type);

View File

@ -203,8 +203,12 @@ std::vector<QueryLocation> GetUsesOfSymbol(QueryDatabase* db,
case SymbolKind::Var: {
QueryVar& var = db->vars[symbol.idx];
std::vector<QueryLocation> ret = var.uses;
if (include_decl && var.def && var.def->definition_spelling)
ret.push_back(*var.def->definition_spelling);
if (include_decl && var.def) {
if (var.def->definition_spelling)
ret.push_back(*var.def->definition_spelling);
ret.insert(ret.end(), var.def->declarations.begin(),
var.def->declarations.end());
}
return ret;
}
case SymbolKind::File:
@ -239,11 +243,8 @@ std::vector<QueryLocation> GetDeclarationsOfSymbolForGotoDefinition(
}
case SymbolKind::Var: {
QueryVar& var = db->vars[symbol.idx];
if (var.def) {
optional<QueryLocation> declaration = var.def->declaration;
if (declaration)
return {*declaration};
}
if (var.def)
return var.def->declarations;
break;
}
default:

View File

@ -189,7 +189,7 @@ void Reflect(TVisitor& visitor, IndexVar& value) {
REFLECT_MEMBER2("storage", value.def.storage);
REFLECT_MEMBER2("hover", value.def.hover);
REFLECT_MEMBER2("comments", value.def.comments);
REFLECT_MEMBER2("declaration", value.def.declaration);
REFLECT_MEMBER2("declarations", value.def.declarations);
REFLECT_MEMBER2("definition_spelling", value.def.definition_spelling);
REFLECT_MEMBER2("definition_extent", value.def.definition_extent);
REFLECT_MEMBER2("variable_type", value.def.variable_type);