mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 07:35:08 +00:00
wip
This commit is contained in:
parent
fd1d8c8785
commit
7f6354f9c8
41
main.cpp
41
main.cpp
@ -85,7 +85,7 @@ struct TypeDef {
|
||||
std::vector<clang::SourceLocation> uses;
|
||||
|
||||
TypeDef(TypeId id, const std::string& usr) : id(id), usr(usr) {
|
||||
//assert(usr.size() > 0);
|
||||
assert(usr.size() > 0);
|
||||
//std::cout << "Creating type with usr " << usr << std::endl;
|
||||
}
|
||||
};
|
||||
@ -117,7 +117,9 @@ struct FuncDef {
|
||||
// Usages.
|
||||
std::vector<clang::SourceLocation> uses;
|
||||
|
||||
FuncDef(FuncId id, const std::string& usr) : id(id), usr(usr) {}
|
||||
FuncDef(FuncId id, const std::string& usr) : id(id), usr(usr) {
|
||||
assert(usr.size() > 0);
|
||||
}
|
||||
};
|
||||
|
||||
struct VarDef {
|
||||
@ -138,7 +140,9 @@ struct VarDef {
|
||||
// Usages.
|
||||
std::vector<clang::SourceLocation> uses;
|
||||
|
||||
VarDef(VarId id, const std::string& usr) : id(id), usr(usr) {}
|
||||
VarDef(VarId id, const std::string& usr) : id(id), usr(usr) {
|
||||
assert(usr.size() > 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -562,24 +566,33 @@ void InsertTypeUsageAtLocation(ParsingDatabase* db, clang::Type type, const clan
|
||||
void HandleVarDecl(ParsingDatabase* db, NamespaceStack* ns, clang::Cursor var, std::optional<TypeId> declaring_type) {
|
||||
//Dump(var);
|
||||
|
||||
VarId var_id = db->ToVarId(var.get_usr());
|
||||
// Add a usage to the type of the variable.
|
||||
InsertTypeUsageAtLocation(db, var.get_type(), var.get_source_location());
|
||||
|
||||
// Note: if there is no USR then there can be no declaring type, as all
|
||||
// member variables of a class must have a name. Only function parameters
|
||||
// can be nameless.
|
||||
std::string var_usr = var.get_usr();
|
||||
if (var_usr.size() == 0) {
|
||||
assert(var.get_kind() == CXCursor_ParmDecl);
|
||||
return;
|
||||
}
|
||||
|
||||
VarId var_id = db->ToVarId(var_usr);
|
||||
VarDef* var_def = db->Resolve(var_id);
|
||||
|
||||
declaring_type = ResolveDeclaringType(CXCursor_FieldDecl, db, var, declaring_type);
|
||||
|
||||
// TODO: We could use RAII to verify we don't modify db while have a *Def
|
||||
// instance alive.
|
||||
VarDef* var_def = db->Resolve(var_id);
|
||||
var_def->short_name = var.get_spelling();
|
||||
var_def->qualified_name =
|
||||
ns->ComputeQualifiedName(db, declaring_type, var_def->short_name);
|
||||
|
||||
if (declaring_type && !var_def->declaration) {
|
||||
// Note: If USR is null there can be no declaring type.
|
||||
db->Resolve(declaring_type.value())->vars.push_back(var_id);
|
||||
var_def->declaring_type = declaring_type;
|
||||
}
|
||||
|
||||
// Add a usage to the type of the variable.
|
||||
InsertTypeUsageAtLocation(db, var.get_type(), var.get_source_location());
|
||||
// TODO: We could use RAII to verify we don't modify db while have a *Def
|
||||
// instance alive.
|
||||
var_def->short_name = var.get_spelling();
|
||||
var_def->qualified_name =
|
||||
ns->ComputeQualifiedName(db, declaring_type, var_def->short_name);
|
||||
|
||||
// We don't do any additional processing for non-definitions.
|
||||
if (!var.is_definition()) {
|
||||
|
@ -37,10 +37,6 @@ OUTPUT:
|
||||
}],
|
||||
"variables": [{
|
||||
"id": 0,
|
||||
"declaration": "tests/usage/func_usage_addr_func.cc:1:19",
|
||||
"initializations": ["tests/usage/func_usage_addr_func.cc:1:19"]
|
||||
}, {
|
||||
"id": 1,
|
||||
"usr": "c:func_usage_addr_func.cc@61@F@user#@x",
|
||||
"short_name": "x",
|
||||
"qualified_name": "x",
|
||||
|
@ -18,11 +18,6 @@ OUTPUT:
|
||||
"qualified_name": "foo",
|
||||
"definition": "tests/usage/type_usage_declare_param_unnamed.cc:2:6"
|
||||
}],
|
||||
"variables": [{
|
||||
"id": 0,
|
||||
"declaration": "tests/usage/type_usage_declare_param_unnamed.cc:2:22",
|
||||
"initializations": ["tests/usage/type_usage_declare_param_unnamed.cc:2:22"],
|
||||
"variable_type": 0
|
||||
}]
|
||||
"variables": []
|
||||
}
|
||||
*/
|
@ -1,10 +1,5 @@
|
||||
void foo(int, int) {}
|
||||
/*
|
||||
// TODO: We should probably not emit variables for unnamed variables. But we
|
||||
// still need to emit reference information.
|
||||
// TODO: This test is broken. Notice how we only emit one variable because
|
||||
// unnamed vars have no usr!
|
||||
|
||||
OUTPUT:
|
||||
{
|
||||
"types": [],
|
||||
@ -15,10 +10,6 @@ OUTPUT:
|
||||
"qualified_name": "foo",
|
||||
"definition": "tests/vars/function_param_unnamed.cc:1:6"
|
||||
}],
|
||||
"variables": [{
|
||||
"id": 0,
|
||||
"declaration": "tests/vars/function_param_unnamed.cc:1:13",
|
||||
"initializations": ["tests/vars/function_param_unnamed.cc:1:13", "tests/vars/function_param_unnamed.cc:1:18"]
|
||||
}]
|
||||
"variables": []
|
||||
}
|
||||
*/
|
Loading…
Reference in New Issue
Block a user