Browse Source

wip

pull/2/head
Jacob Dufault 8 years ago
parent
commit
7f6354f9c8
  1. 37
      main.cpp
  2. 4
      tests/usage/func_usage_addr_func.cc
  3. 7
      tests/usage/type_usage_declare_param_unnamed.cc
  4. 11
      tests/vars/function_param_unnamed.cc

37
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());
declaring_type = ResolveDeclaringType(CXCursor_FieldDecl, db, var, declaring_type);
// 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;
}
// TODO: We could use RAII to verify we don't modify db while have a *Def
// instance alive.
VarId var_id = db->ToVarId(var_usr);
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);
declaring_type = ResolveDeclaringType(CXCursor_FieldDecl, db, var, declaring_type);
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()) {

4
tests/usage/func_usage_addr_func.cc

@ -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",

7
tests/usage/type_usage_declare_param_unnamed.cc

@ -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": []
}
*/

11
tests/vars/function_param_unnamed.cc

@ -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…
Cancel
Save