mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 09:05:10 +00:00
Rename FuncDefDefinitionData::locals to vars, remove constants from EnumDecl's vars
This commit is contained in:
parent
7743480b13
commit
09dd20226f
@ -29,13 +29,6 @@ bool ClangType::operator==(const ClangType& rhs) const {
|
||||
return clang_equalTypes(cx_type, rhs.cx_type);
|
||||
}
|
||||
|
||||
bool ClangType::is_fundamental() const {
|
||||
// NOTE: This will return false for pointed types. Should we call
|
||||
// strip_qualifiers for the user?
|
||||
return cx_type.kind >= CXType_FirstBuiltin &&
|
||||
cx_type.kind <= CXType_LastBuiltin;
|
||||
}
|
||||
|
||||
ClangCursor ClangType::get_declaration() const {
|
||||
return clang_getTypeDeclaration(cx_type);
|
||||
}
|
||||
@ -45,7 +38,7 @@ std::string ClangType::get_usr() const {
|
||||
}
|
||||
|
||||
Usr ClangType::get_usr_hash() const {
|
||||
if (is_fundamental())
|
||||
if (is_builtin())
|
||||
return static_cast<Usr>(cx_type.kind);
|
||||
return ClangCursor(clang_getTypeDeclaration(cx_type)).get_usr_hash();
|
||||
}
|
||||
|
@ -25,7 +25,12 @@ class ClangType {
|
||||
bool operator==(const ClangType& rhs) const;
|
||||
|
||||
// Returns true if this is a fundamental type like int.
|
||||
bool is_fundamental() const;
|
||||
bool is_builtin() const {
|
||||
// NOTE: This will return false for pointed types. Should we call
|
||||
// strip_qualifiers for the user?
|
||||
return cx_type.kind >= CXType_FirstBuiltin &&
|
||||
cx_type.kind <= CXType_LastBuiltin;
|
||||
}
|
||||
|
||||
ClangCursor get_declaration() const;
|
||||
std::string get_usr() const;
|
||||
|
@ -150,6 +150,37 @@ std::string ToString(CXCursorKind kind) {
|
||||
return ToString(clang_getCursorKindSpelling(kind));
|
||||
}
|
||||
|
||||
const char* ClangBuiltinTypeName(CXTypeKind kind) {
|
||||
switch (kind) {
|
||||
// clang-format off
|
||||
case CXType_Bool: return "bool";
|
||||
case CXType_Char_U: return "char";
|
||||
case CXType_UChar: return "unsigned char";
|
||||
case CXType_UShort: return "unsigned short";
|
||||
case CXType_UInt: return "unsigned int";
|
||||
case CXType_ULong: return "unsigned long";
|
||||
case CXType_ULongLong: return "unsigned long long";
|
||||
case CXType_UInt128: return "unsigned __int128";
|
||||
case CXType_Char_S: return "char";
|
||||
case CXType_SChar: return "signed char";
|
||||
case CXType_WChar: return "wchar_t";
|
||||
case CXType_Int: return "int";
|
||||
case CXType_Long: return "long";
|
||||
case CXType_LongLong: return "long long";
|
||||
case CXType_Int128: return "__int128";
|
||||
case CXType_Float: return "float";
|
||||
case CXType_Double: return "double";
|
||||
case CXType_LongDouble: return "long double";
|
||||
case CXType_Float128: return "__float128";
|
||||
#if CINDEX_VERSION_MINOR >= 43
|
||||
case CXType_Half: return "_Float16";
|
||||
#endif
|
||||
case CXType_NullPtr: return "nullptr";
|
||||
default: return "";
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_CLANG_CXX
|
||||
TEST_SUITE("ClangUtils") {
|
||||
TEST_CASE("replacements") {
|
||||
|
@ -20,6 +20,8 @@ std::string ToString(CXString cx_string);
|
||||
|
||||
std::string ToString(CXCursorKind cursor_kind);
|
||||
|
||||
const char* ClangBuiltinTypeName(CXTypeKind);
|
||||
|
||||
// Converts Clang formatting replacement operations into LSP text edits.
|
||||
#if USE_CLANG_CXX
|
||||
std::vector<lsTextEdit> ConvertClangReplacementsIntoTextEdits(
|
||||
|
@ -539,7 +539,7 @@ optional<IndexTypeId> ResolveToDeclarationType(IndexFile* db,
|
||||
|
||||
type = type.strip_qualifiers();
|
||||
|
||||
if (type.is_fundamental()) {
|
||||
if (type.is_builtin()) {
|
||||
// For builtin types, use type kinds as USR hash.
|
||||
return db->ToTypeId(type.cx_type.kind);
|
||||
}
|
||||
@ -1602,14 +1602,19 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
||||
|
||||
if (decl->isDefinition && decl->semanticContainer) {
|
||||
switch (GetSymbolKind(decl->semanticContainer->cursor.kind)) {
|
||||
default:
|
||||
break;
|
||||
case SymbolKind::Type: {
|
||||
IndexTypeId parent_type_id =
|
||||
db->ToTypeId(decl->semanticContainer->cursor);
|
||||
db->Resolve(parent_type_id)->def.vars.push_back(var_id);
|
||||
case SymbolKind::Func: {
|
||||
db->Resolve(db->ToFuncId(decl->semanticContainer->cursor))
|
||||
->def.vars.push_back(var_id);
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Type:
|
||||
if (decl->semanticContainer->cursor.kind != CXCursor_EnumDecl) {
|
||||
db->Resolve(db->ToTypeId(decl->semanticContainer->cursor))
|
||||
->def.vars.push_back(var_id);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1842,7 +1847,7 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
||||
|
||||
if (decl_cursor.get_kind() == CXCursor_EnumDecl) {
|
||||
ClangType enum_type = clang_getEnumDeclIntegerType(decl->cursor);
|
||||
if (!enum_type.is_fundamental()) {
|
||||
if (!enum_type.is_builtin()) {
|
||||
IndexType* int_type =
|
||||
db->Resolve(db->ToTypeId(enum_type.get_usr_hash()));
|
||||
AddUse(db, int_type->uses, spell,
|
||||
|
@ -256,8 +256,8 @@ struct FuncDefDefinitionData {
|
||||
// Method this method overrides.
|
||||
std::vector<typename F::FuncId> bases;
|
||||
|
||||
// Local variables defined in this function.
|
||||
std::vector<typename F::VarId> locals;
|
||||
// Local variables or parameters.
|
||||
std::vector<typename F::VarId> vars;
|
||||
|
||||
// Functions that this function calls.
|
||||
std::vector<SymbolRef> callees;
|
||||
@ -273,7 +273,7 @@ struct FuncDefDefinitionData {
|
||||
bool operator==(const FuncDefDefinitionData& o) const {
|
||||
return detailed_name == o.detailed_name && spell == o.spell &&
|
||||
extent == o.extent && declaring_type == o.declaring_type &&
|
||||
bases == o.bases && locals == o.locals && callees == o.callees &&
|
||||
bases == o.bases && vars == o.vars && callees == o.callees &&
|
||||
kind == o.kind && storage == o.storage && hover == o.hover &&
|
||||
comments == o.comments;
|
||||
}
|
||||
@ -308,7 +308,7 @@ void Reflect(TVisitor& visitor, FuncDefDefinitionData<Family>& value) {
|
||||
REFLECT_MEMBER(file);
|
||||
REFLECT_MEMBER(declaring_type);
|
||||
REFLECT_MEMBER(bases);
|
||||
REFLECT_MEMBER(locals);
|
||||
REFLECT_MEMBER(vars);
|
||||
REFLECT_MEMBER(callees);
|
||||
REFLECT_MEMBER_END();
|
||||
}
|
||||
|
@ -118,6 +118,7 @@ bool Expand(MessageHandler* m,
|
||||
};
|
||||
|
||||
std::unordered_set<Usr> seen;
|
||||
seen.insert(func.usr);
|
||||
std::vector<const QueryFunc*> stack;
|
||||
if (detailed_name)
|
||||
entry->name = def->detailed_name;
|
||||
@ -132,7 +133,6 @@ bool Expand(MessageHandler* m,
|
||||
|
||||
// Callers/callees of base functions.
|
||||
if (call_type & CallType::Base) {
|
||||
seen.insert(func.usr);
|
||||
stack.push_back(&func);
|
||||
while (stack.size()) {
|
||||
const QueryFunc& func1 = *stack.back();
|
||||
|
@ -70,33 +70,7 @@ bool Expand(MessageHandler* m,
|
||||
const QueryType::Def* def = type.AnyDef();
|
||||
// builtin types have no declaration and empty |detailed_name|.
|
||||
if (CXType_FirstBuiltin <= type.usr && type.usr <= CXType_LastBuiltin) {
|
||||
switch (type.usr) {
|
||||
// clang-format off
|
||||
case CXType_Bool: entry->name = "bool"; break;
|
||||
case CXType_Char_U: entry->name = "char"; break;
|
||||
case CXType_UChar: entry->name = "unsigned char"; break;
|
||||
case CXType_UShort: entry->name = "unsigned short"; break;
|
||||
case CXType_UInt: entry->name = "unsigned int"; break;
|
||||
case CXType_ULong: entry->name = "unsigned long"; break;
|
||||
case CXType_ULongLong: entry->name = "unsigned long long"; break;
|
||||
case CXType_UInt128: entry->name = "unsigned __int128"; break;
|
||||
case CXType_Char_S: entry->name = "char"; break;
|
||||
case CXType_SChar: entry->name = "signed char"; break;
|
||||
case CXType_WChar: entry->name = "wchar_t"; break;
|
||||
case CXType_Int: entry->name = "int"; break;
|
||||
case CXType_Long: entry->name = "long"; break;
|
||||
case CXType_LongLong: entry->name = "long long"; break;
|
||||
case CXType_Int128: entry->name = "__int128"; break;
|
||||
case CXType_Float: entry->name = "float"; break;
|
||||
case CXType_Double: entry->name = "double"; break;
|
||||
case CXType_LongDouble: entry->name = "long double"; break;
|
||||
case CXType_Float128: entry->name = "__float128"; break;
|
||||
#if CINDEX_VERSION_MINOR >= 43
|
||||
case CXType_Half: entry->name = "_Float16"; break;
|
||||
#endif
|
||||
case CXType_NullPtr: entry->name = "nullptr"; break;
|
||||
// clang-format on
|
||||
}
|
||||
entry->name = ClangBuiltinTypeName(CXTypeKind(type.usr));
|
||||
entry->numChildren = 0;
|
||||
return true;
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ optional<QueryFunc::Def> ToQuery(const IdMap& id_map,
|
||||
result.extent = id_map.ToQuery(func.extent);
|
||||
result.declaring_type = id_map.ToQuery(func.declaring_type);
|
||||
result.bases = id_map.ToQuery(func.bases);
|
||||
result.locals = id_map.ToQuery(func.locals);
|
||||
result.vars = id_map.ToQuery(func.vars);
|
||||
result.callees = id_map.ToQuery(func.callees);
|
||||
return result;
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ void Reflect(TVisitor& visitor, IndexFunc& value) {
|
||||
REFLECT_MEMBER2("declaring_type", value.def.declaring_type);
|
||||
REFLECT_MEMBER2("bases", value.def.bases);
|
||||
REFLECT_MEMBER2("derived", value.derived);
|
||||
REFLECT_MEMBER2("locals", value.def.locals);
|
||||
REFLECT_MEMBER2("vars", value.def.vars);
|
||||
REFLECT_MEMBER2("uses", value.uses);
|
||||
REFLECT_MEMBER2("callees", value.def.callees);
|
||||
REFLECT_MEMBER_END();
|
||||
|
Loading…
Reference in New Issue
Block a user