diff --git a/main.cpp b/main.cpp index eeb83999..e84ff07c 100644 --- a/main.cpp +++ b/main.cpp @@ -1069,6 +1069,42 @@ CXIdxClientContainer startedTranslationUnit(CXClientData client_data, void *rese + + + + + + +struct FindChildOfKindParam { + CXCursorKind target_kind; + std::optional result; + + FindChildOfKindParam(CXCursorKind target_kind) : target_kind(target_kind) {} +}; + +clang::VisiterResult FindChildOfKindVisitor(clang::Cursor cursor, clang::Cursor parent, FindChildOfKindParam* param) { + if (cursor.get_kind() == param->target_kind) { + param->result = cursor; + return clang::VisiterResult::Break; + } + + return clang::VisiterResult::Recurse; +} + +std::optional FindChildOfKind(clang::Cursor cursor, CXCursorKind kind) { + FindChildOfKindParam param(kind); + cursor.VisitChildren(&FindChildOfKindVisitor, ¶m); + return param.result; +} + + + + + + + + + struct NamespaceHelper { std::unordered_map container_usr_to_qualified_name; @@ -1138,6 +1174,15 @@ std::string GetNamespacePrefx(const CXIdxDeclInfo* decl) { // * it doesn't seem like we get any template specialization logic // * we get two decls to the same template... resolved by checking parent? maybe this will break. not sure. +// Insert a reference to |type_id| using the location of the first TypeRef under |cursor|. +void InsertInterestingTypeReference(ParsingDatabase* db, TypeId type_id, clang::Cursor cursor) { + std::optional child = FindChildOfKind(cursor, CXCursor_TypeRef); + assert(child.has_value()); // If this assert ever fails just use |cursor| loc. + + TypeDef* def = db->Resolve(type_id); + def->interesting_uses.push_back(child.value().get_source_location()); +} + bool IsTypeDefinition(const CXIdxContainerInfo* container) { if (!container) return false; @@ -1179,10 +1224,12 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { var_def->declaration = decl->loc; var_def->all_uses.push_back(decl->loc); - clang::Type var_type = clang::Cursor(decl->cursor).get_type().strip_qualifiers(); - std::string var_type_usr = var_type.get_usr(); - if (var_type_usr != "") - var_def->variable_type = db->ToTypeId(var_type_usr); + std::string var_type_usr = clang::Cursor(decl->cursor).get_type().strip_qualifiers().get_usr(); + if (var_type_usr != "") { + TypeId var_type_id = db->ToTypeId(var_type_usr); + var_def->variable_type = var_type_id; + InsertInterestingTypeReference(db, var_type_id, decl->cursor); + } if (decl->isDefinition && IsTypeDefinition(decl->semanticContainer)) { TypeId declaring_type_id = db->ToTypeId(decl->semanticContainer->cursor); @@ -1232,7 +1279,11 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { // (before visiting another declaration). If we only want to mark the // return type on the definition interesting, we could only compute this // if we're parsing the definition declaration. - func_def->needs_return_type_index = !clang::Cursor(decl->cursor).get_type().get_return_type().is_fundamental(); + //func_def->needs_return_type_index = !clang::Cursor(decl->cursor).get_type().get_return_type().is_fundamental(); + + std::string return_type_usr = clang::Cursor(decl->cursor).get_type().get_return_type().strip_qualifiers().get_usr(); + if (return_type_usr != "") + InsertInterestingTypeReference(db, db->ToTypeId(return_type_usr), decl->cursor); /* std::optional base; @@ -1324,6 +1375,7 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re break; } + case CXIdxEntity_CXXStaticMethod: case CXIdxEntity_CXXInstanceMethod: case CXIdxEntity_Function: { @@ -1334,6 +1386,7 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re // } // Don't report duplicate usages. + // TODO: search full history? clang::SourceLocation loc = ref->loc; if (param->last_func_usage_location == loc) break; param->last_func_usage_location = loc; @@ -1381,11 +1434,23 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re // } // clang::SourceLocation loc = ref->loc; - if (param->last_type_usage_location == loc) break; - param->last_type_usage_location = loc; + //if (param->last_type_usage_location == loc) break; + //param->last_type_usage_location = loc; + + // TODO: initializer list can many type refs... + bool do_break = false; + for (int i = referenced_def->all_uses.size() - 1; i >= 0; --i) { + if (referenced_def->all_uses[i] == loc) { + do_break = true; + break; + } + } + if (do_break) + break; referenced_def->all_uses.push_back(loc); + /* // // Variable declarations have an embedded TypeRef. // @@ -1416,6 +1481,7 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re referenced_def->interesting_uses.push_back(loc); } } + */ break; } @@ -1591,11 +1657,12 @@ int main(int argc, char** argv) { // TODO: Fix all existing tests. //if (path == "tests/usage/type_usage_declare_extern.cc") continue; if (path == "tests/constructors/constructor.cc") continue; + if (path != "tests/usage/type_usage_on_return_type.cc") continue; //if (path != "tests/usage/type_usage_declare_local.cc") continue; //if (path != "tests/usage/func_usage_addr_method.cc") continue; //if (path != "tests/usage/func_usage_template_func.cc") continue; //if (path != "tests/usage/func_usage_class_inline_var_def.cc") continue; - if (path != "tests/foobar.cc") continue; + //if (path != "tests/foobar.cc") continue; // Parse expected output from the test, parse it into JSON document. std::string expected_output; diff --git a/tests/foobar.cc b/tests/foobar.cc index eb2be9ec..571a7fdb 100644 --- a/tests/foobar.cc +++ b/tests/foobar.cc @@ -19,15 +19,23 @@ OUTPUT: "short_name": "Foo", "qualified_name": "Foo", "definition": "tests/foobar.cc:1:8", - "all_uses": ["tests/foobar.cc:1:8", "tests/foobar.cc:2:10", "tests/foobar.cc:6:3", "tests/foobar.cc:6:12", "tests/foobar.cc:6:3", "tests/foobar.cc:6:12"], - "interesting_uses": ["tests/foobar.cc:6:3", "tests/foobar.cc:6:12"] + "all_uses": ["tests/foobar.cc:1:8", "tests/foobar.cc:2:10", "tests/foobar.cc:6:3", "tests/foobar.cc:6:12"], + "interesting_uses": ["tests/foobar.cc:2:10", "tests/foobar.cc:6:3"] }], "functions": [{ "id": 0, + "usr": "c:@S@Foo@F@Used#S", + "short_name": "Used", + "qualified_name": "Foo::Used", + "callers": ["1@tests/foobar.cc:6:17"], + "all_uses": ["tests/foobar.cc:2:15", "tests/foobar.cc:6:17"] + }, { + "id": 1, "usr": "c:@F@user#", "short_name": "user", "qualified_name": "user", "definition": "tests/foobar.cc:5:6", + "callees": ["0@tests/foobar.cc:6:17"], "all_uses": ["tests/foobar.cc:5:6"] }], "variables": [{ diff --git a/tests/usage/func_usage_call_method.cc b/tests/usage/func_usage_call_method.cc index da0dac4f..40100057 100644 --- a/tests/usage/func_usage_call_method.cc +++ b/tests/usage/func_usage_call_method.cc @@ -16,7 +16,8 @@ OUTPUT: "short_name": "Foo", "qualified_name": "Foo", "definition": "tests/usage/func_usage_call_method.cc:1:8", - "all_uses": ["tests/usage/func_usage_call_method.cc:1:8", "tests/usage/func_usage_call_method.cc:6:3"] + "all_uses": ["tests/usage/func_usage_call_method.cc:1:8", "tests/usage/func_usage_call_method.cc:6:3"], + "interesting_uses": ["tests/usage/func_usage_call_method.cc:6:3"] }], "functions": [{ "id": 0, diff --git a/tests/usage/func_usage_forward_decl_method.cc b/tests/usage/func_usage_forward_decl_method.cc index 7e0357f9..dd6b4a74 100644 --- a/tests/usage/func_usage_forward_decl_method.cc +++ b/tests/usage/func_usage_forward_decl_method.cc @@ -15,7 +15,8 @@ OUTPUT: "short_name": "Foo", "qualified_name": "Foo", "definition": "tests/usage/func_usage_forward_decl_method.cc:1:8", - "all_uses": ["tests/usage/func_usage_forward_decl_method.cc:1:8", "tests/usage/func_usage_forward_decl_method.cc:6:3"] + "all_uses": ["tests/usage/func_usage_forward_decl_method.cc:1:8", "tests/usage/func_usage_forward_decl_method.cc:6:3"], + "interesting_uses": ["tests/usage/func_usage_forward_decl_method.cc:6:3"] }], "functions": [{ "id": 0, diff --git a/tests/usage/type_usage_declare_extern.cc b/tests/usage/type_usage_declare_extern.cc index 8df988a6..9c419737 100644 --- a/tests/usage/type_usage_declare_extern.cc +++ b/tests/usage/type_usage_declare_extern.cc @@ -10,7 +10,8 @@ OUTPUT: "short_name": "T", "qualified_name": "T", "definition": "tests/usage/type_usage_declare_extern.cc:1:8", - "all_uses": ["tests/usage/type_usage_declare_extern.cc:1:8", "tests/usage/type_usage_declare_extern.cc:3:8"] + "all_uses": ["tests/usage/type_usage_declare_extern.cc:1:8", "tests/usage/type_usage_declare_extern.cc:3:8"], + "interesting_uses": ["tests/usage/type_usage_declare_extern.cc:3:8"] }], "functions": [], "variables": [{ @@ -19,6 +20,7 @@ OUTPUT: "short_name": "t", "qualified_name": "t", "declaration": "tests/usage/type_usage_declare_extern.cc:3:10", + "variable_type": 0, "all_uses": ["tests/usage/type_usage_declare_extern.cc:3:10"] }] } diff --git a/tests/usage/type_usage_declare_field.cc b/tests/usage/type_usage_declare_field.cc index ce83b5ab..ec583bd2 100644 --- a/tests/usage/type_usage_declare_field.cc +++ b/tests/usage/type_usage_declare_field.cc @@ -12,24 +12,24 @@ OUTPUT: "types": [{ "id": 0, "usr": "c:@S@ForwardType", - "short_name": "ForwardType", - "qualified_name": "ForwardType", - "declaration": "tests/usage/type_usage_declare_field.cc:1:8", - "uses": ["tests/usage/type_usage_declare_field.cc:5:3"] + "all_uses": ["tests/usage/type_usage_declare_field.cc:1:8", "tests/usage/type_usage_declare_field.cc:5:3"], + "interesting_uses": ["tests/usage/type_usage_declare_field.cc:5:3"] }, { "id": 1, "usr": "c:@S@ImplementedType", "short_name": "ImplementedType", "qualified_name": "ImplementedType", "definition": "tests/usage/type_usage_declare_field.cc:2:8", - "uses": ["tests/usage/type_usage_declare_field.cc:6:3"] + "all_uses": ["tests/usage/type_usage_declare_field.cc:2:8", "tests/usage/type_usage_declare_field.cc:6:3"], + "interesting_uses": ["tests/usage/type_usage_declare_field.cc:6:3"] }, { "id": 2, "usr": "c:@S@Foo", "short_name": "Foo", "qualified_name": "Foo", "definition": "tests/usage/type_usage_declare_field.cc:4:8", - "vars": [0, 1] + "vars": [0, 1], + "all_uses": ["tests/usage/type_usage_declare_field.cc:4:8"] }], "functions": [], "variables": [{ @@ -38,18 +38,18 @@ OUTPUT: "short_name": "a", "qualified_name": "Foo::a", "declaration": "tests/usage/type_usage_declare_field.cc:5:16", - "initializations": ["tests/usage/type_usage_declare_field.cc:5:16"], "variable_type": 0, - "declaring_type": 2 + "declaring_type": 2, + "all_uses": ["tests/usage/type_usage_declare_field.cc:5:16"] }, { "id": 1, "usr": "c:@S@Foo@FI@b", "short_name": "b", "qualified_name": "Foo::b", "declaration": "tests/usage/type_usage_declare_field.cc:6:19", - "initializations": ["tests/usage/type_usage_declare_field.cc:6:19"], "variable_type": 1, - "declaring_type": 2 + "declaring_type": 2, + "all_uses": ["tests/usage/type_usage_declare_field.cc:6:19"] }] } */ \ No newline at end of file diff --git a/tests/usage/type_usage_declare_local.cc b/tests/usage/type_usage_declare_local.cc index c9ea581b..15b9f514 100644 --- a/tests/usage/type_usage_declare_local.cc +++ b/tests/usage/type_usage_declare_local.cc @@ -12,17 +12,16 @@ OUTPUT: "types": [{ "id": 0, "usr": "c:@S@ForwardType", - "short_name": "ForwardType", - "qualified_name": "ForwardType", - "declaration": "tests/usage/type_usage_declare_local.cc:1:8", - "uses": ["tests/usage/type_usage_declare_local.cc:5:3"] + "all_uses": ["tests/usage/type_usage_declare_local.cc:1:8", "tests/usage/type_usage_declare_local.cc:5:3"], + "interesting_uses": ["tests/usage/type_usage_declare_local.cc:5:3"] }, { "id": 1, "usr": "c:@S@ImplementedType", "short_name": "ImplementedType", "qualified_name": "ImplementedType", "definition": "tests/usage/type_usage_declare_local.cc:2:8", - "uses": ["tests/usage/type_usage_declare_local.cc:6:3"] + "all_uses": ["tests/usage/type_usage_declare_local.cc:2:8", "tests/usage/type_usage_declare_local.cc:6:3"], + "interesting_uses": ["tests/usage/type_usage_declare_local.cc:6:3"] }], "functions": [{ "id": 0, @@ -30,12 +29,7 @@ OUTPUT: "short_name": "Foo", "qualified_name": "Foo", "definition": "tests/usage/type_usage_declare_local.cc:4:6", - "callees": ["1@tests/usage/type_usage_declare_local.cc:6:19"] - }, { - "id": 1, - "usr": "c:@S@ImplementedType@F@ImplementedType#", - "callers": ["0@tests/usage/type_usage_declare_local.cc:6:19"], - "uses": ["tests/usage/type_usage_declare_local.cc:6:19"] + "all_uses": ["tests/usage/type_usage_declare_local.cc:4:6"] }], "variables": [{ "id": 0, @@ -43,16 +37,16 @@ OUTPUT: "short_name": "a", "qualified_name": "a", "declaration": "tests/usage/type_usage_declare_local.cc:5:16", - "initializations": ["tests/usage/type_usage_declare_local.cc:5:16"], - "variable_type": 0 + "variable_type": 0, + "all_uses": ["tests/usage/type_usage_declare_local.cc:5:16"] }, { "id": 1, "usr": "c:type_usage_declare_local.cc@86@F@Foo#@b", "short_name": "b", "qualified_name": "b", "declaration": "tests/usage/type_usage_declare_local.cc:6:19", - "initializations": ["tests/usage/type_usage_declare_local.cc:6:19"], - "variable_type": 1 + "variable_type": 1, + "all_uses": ["tests/usage/type_usage_declare_local.cc:6:19"] }] } */ \ No newline at end of file diff --git a/tests/usage/type_usage_declare_param.cc b/tests/usage/type_usage_declare_param.cc index 91b6f4f5..73ac8a21 100644 --- a/tests/usage/type_usage_declare_param.cc +++ b/tests/usage/type_usage_declare_param.cc @@ -9,24 +9,24 @@ OUTPUT: "types": [{ "id": 0, "usr": "c:@S@ForwardType", - "short_name": "ForwardType", - "qualified_name": "ForwardType", - "declaration": "tests/usage/type_usage_declare_param.cc:1:8", - "uses": ["tests/usage/type_usage_declare_param.cc:4:10"] + "all_uses": ["tests/usage/type_usage_declare_param.cc:1:8", "tests/usage/type_usage_declare_param.cc:4:10"], + "interesting_uses": ["tests/usage/type_usage_declare_param.cc:4:10"] }, { "id": 1, "usr": "c:@S@ImplementedType", "short_name": "ImplementedType", "qualified_name": "ImplementedType", "definition": "tests/usage/type_usage_declare_param.cc:2:8", - "uses": ["tests/usage/type_usage_declare_param.cc:4:26"] + "all_uses": ["tests/usage/type_usage_declare_param.cc:2:8", "tests/usage/type_usage_declare_param.cc:4:26"], + "interesting_uses": ["tests/usage/type_usage_declare_param.cc:4:26"] }], "functions": [{ "id": 0, "usr": "c:@F@foo#*$@S@ForwardType#$@S@ImplementedType#", "short_name": "foo", "qualified_name": "foo", - "definition": "tests/usage/type_usage_declare_param.cc:4:6" + "definition": "tests/usage/type_usage_declare_param.cc:4:6", + "all_uses": ["tests/usage/type_usage_declare_param.cc:4:6"] }], "variables": [{ "id": 0, @@ -34,16 +34,16 @@ OUTPUT: "short_name": "f", "qualified_name": "f", "declaration": "tests/usage/type_usage_declare_param.cc:4:23", - "initializations": ["tests/usage/type_usage_declare_param.cc:4:23"], - "variable_type": 0 + "variable_type": 0, + "all_uses": ["tests/usage/type_usage_declare_param.cc:4:23"] }, { "id": 1, "usr": "c:type_usage_declare_param.cc@76@F@foo#*$@S@ForwardType#$@S@ImplementedType#@a", "short_name": "a", "qualified_name": "a", "declaration": "tests/usage/type_usage_declare_param.cc:4:42", - "initializations": ["tests/usage/type_usage_declare_param.cc:4:42"], - "variable_type": 1 + "variable_type": 1, + "all_uses": ["tests/usage/type_usage_declare_param.cc:4:42"] }] } */ \ No newline at end of file diff --git a/tests/usage/type_usage_declare_param_prototype.cc b/tests/usage/type_usage_declare_param_prototype.cc index 13f17db9..7ef7c485 100644 --- a/tests/usage/type_usage_declare_param_prototype.cc +++ b/tests/usage/type_usage_declare_param_prototype.cc @@ -4,23 +4,26 @@ void foo(Foo* f, Foo*); void foo(Foo* f, Foo*) {} /* +// TODO: No interesting usage on prototype. But maybe that's ok! +// TODO: We should have the same variable declared for both prototype and +// declaration. So it should have a usage marker on both. Then we could +// rename parameters! + OUTPUT: { "types": [{ "id": 0, "usr": "c:@S@Foo", - "short_name": "Foo", - "qualified_name": "Foo", - "declaration": "tests/usage/type_usage_declare_param_prototype.cc:1:8", - "uses": ["tests/usage/type_usage_declare_param_prototype.cc:3:10", "tests/usage/type_usage_declare_param_prototype.cc:3:18", "tests/usage/type_usage_declare_param_prototype.cc:4:10", "tests/usage/type_usage_declare_param_prototype.cc:4:18"] + "all_uses": ["tests/usage/type_usage_declare_param_prototype.cc:1:8", "tests/usage/type_usage_declare_param_prototype.cc:3:10", "tests/usage/type_usage_declare_param_prototype.cc:3:18", "tests/usage/type_usage_declare_param_prototype.cc:4:10", "tests/usage/type_usage_declare_param_prototype.cc:4:18"], + "interesting_uses": ["tests/usage/type_usage_declare_param_prototype.cc:4:10"] }], "functions": [{ "id": 0, "usr": "c:@F@foo#*$@S@Foo#S0_#", "short_name": "foo", "qualified_name": "foo", - "declaration": "tests/usage/type_usage_declare_param_prototype.cc:3:6", - "definition": "tests/usage/type_usage_declare_param_prototype.cc:4:6" + "definition": "tests/usage/type_usage_declare_param_prototype.cc:4:6", + "all_uses": ["tests/usage/type_usage_declare_param_prototype.cc:3:6", "tests/usage/type_usage_declare_param_prototype.cc:4:6"] }], "variables": [{ "id": 0, @@ -28,8 +31,8 @@ OUTPUT: "short_name": "f", "qualified_name": "f", "declaration": "tests/usage/type_usage_declare_param_prototype.cc:4:15", - "initializations": ["tests/usage/type_usage_declare_param_prototype.cc:4:15"], - "variable_type": 0 + "variable_type": 0, + "all_uses": ["tests/usage/type_usage_declare_param_prototype.cc:4:15"] }] } */ \ No newline at end of file diff --git a/tests/usage/type_usage_declare_param_unnamed.cc b/tests/usage/type_usage_declare_param_unnamed.cc index 218dc360..7d70dfba 100644 --- a/tests/usage/type_usage_declare_param_unnamed.cc +++ b/tests/usage/type_usage_declare_param_unnamed.cc @@ -6,17 +6,15 @@ OUTPUT: "types": [{ "id": 0, "usr": "c:@S@ForwardType", - "short_name": "ForwardType", - "qualified_name": "ForwardType", - "declaration": "tests/usage/type_usage_declare_param_unnamed.cc:1:8", - "uses": ["tests/usage/type_usage_declare_param_unnamed.cc:2:10"] + "all_uses": ["tests/usage/type_usage_declare_param_unnamed.cc:1:8", "tests/usage/type_usage_declare_param_unnamed.cc:2:10"] }], "functions": [{ "id": 0, "usr": "c:@F@foo#*$@S@ForwardType#", "short_name": "foo", "qualified_name": "foo", - "definition": "tests/usage/type_usage_declare_param_unnamed.cc:2:6" + "definition": "tests/usage/type_usage_declare_param_unnamed.cc:2:6", + "all_uses": ["tests/usage/type_usage_declare_param_unnamed.cc:2:6"] }], "variables": [] } diff --git a/tests/usage/type_usage_declare_qualifiers.cc b/tests/usage/type_usage_declare_qualifiers.cc index 97969e6e..504275b4 100644 --- a/tests/usage/type_usage_declare_qualifiers.cc +++ b/tests/usage/type_usage_declare_qualifiers.cc @@ -15,7 +15,8 @@ OUTPUT: "short_name": "Type", "qualified_name": "Type", "definition": "tests/usage/type_usage_declare_qualifiers.cc:1:8", - "uses": ["tests/usage/type_usage_declare_qualifiers.cc:3:10", "tests/usage/type_usage_declare_qualifiers.cc:3:26", "tests/usage/type_usage_declare_qualifiers.cc:4:3", "tests/usage/type_usage_declare_qualifiers.cc:5:3", "tests/usage/type_usage_declare_qualifiers.cc:6:9", "tests/usage/type_usage_declare_qualifiers.cc:7:9"] + "all_uses": ["tests/usage/type_usage_declare_qualifiers.cc:1:8", "tests/usage/type_usage_declare_qualifiers.cc:3:10", "tests/usage/type_usage_declare_qualifiers.cc:3:26", "tests/usage/type_usage_declare_qualifiers.cc:4:3", "tests/usage/type_usage_declare_qualifiers.cc:5:3", "tests/usage/type_usage_declare_qualifiers.cc:6:9", "tests/usage/type_usage_declare_qualifiers.cc:7:9"], + "interesting_uses": ["tests/usage/type_usage_declare_qualifiers.cc:3:10", "tests/usage/type_usage_declare_qualifiers.cc:3:26", "tests/usage/type_usage_declare_qualifiers.cc:4:3", "tests/usage/type_usage_declare_qualifiers.cc:5:3", "tests/usage/type_usage_declare_qualifiers.cc:6:9", "tests/usage/type_usage_declare_qualifiers.cc:7:9"] }], "functions": [{ "id": 0, @@ -23,12 +24,7 @@ OUTPUT: "short_name": "foo", "qualified_name": "foo", "definition": "tests/usage/type_usage_declare_qualifiers.cc:3:6", - "callees": ["1@tests/usage/type_usage_declare_qualifiers.cc:4:8"] - }, { - "id": 1, - "usr": "c:@S@Type@F@Type#", - "callers": ["0@tests/usage/type_usage_declare_qualifiers.cc:4:8"], - "uses": ["tests/usage/type_usage_declare_qualifiers.cc:4:8"] + "all_uses": ["tests/usage/type_usage_declare_qualifiers.cc:3:6"] }], "variables": [{ "id": 0, @@ -36,48 +32,48 @@ OUTPUT: "short_name": "a0", "qualified_name": "a0", "declaration": "tests/usage/type_usage_declare_qualifiers.cc:3:16", - "initializations": ["tests/usage/type_usage_declare_qualifiers.cc:3:16"], - "variable_type": 0 + "variable_type": 0, + "all_uses": ["tests/usage/type_usage_declare_qualifiers.cc:3:16"] }, { "id": 1, "usr": "c:type_usage_declare_qualifiers.cc@38@F@foo#&$@S@Type#&1S1_#@a1", "short_name": "a1", "qualified_name": "a1", "declaration": "tests/usage/type_usage_declare_qualifiers.cc:3:32", - "initializations": ["tests/usage/type_usage_declare_qualifiers.cc:3:32"], - "variable_type": 0 + "variable_type": 0, + "all_uses": ["tests/usage/type_usage_declare_qualifiers.cc:3:32"] }, { "id": 2, "usr": "c:type_usage_declare_qualifiers.cc@59@F@foo#&$@S@Type#&1S1_#@a2", "short_name": "a2", "qualified_name": "a2", "declaration": "tests/usage/type_usage_declare_qualifiers.cc:4:8", - "initializations": ["tests/usage/type_usage_declare_qualifiers.cc:4:8"], - "variable_type": 0 + "variable_type": 0, + "all_uses": ["tests/usage/type_usage_declare_qualifiers.cc:4:8"] }, { "id": 3, "usr": "c:type_usage_declare_qualifiers.cc@71@F@foo#&$@S@Type#&1S1_#@a3", "short_name": "a3", "qualified_name": "a3", "declaration": "tests/usage/type_usage_declare_qualifiers.cc:5:9", - "initializations": ["tests/usage/type_usage_declare_qualifiers.cc:5:9"], - "variable_type": 0 + "variable_type": 0, + "all_uses": ["tests/usage/type_usage_declare_qualifiers.cc:5:9"] }, { "id": 4, "usr": "c:type_usage_declare_qualifiers.cc@84@F@foo#&$@S@Type#&1S1_#@a4", "short_name": "a4", "qualified_name": "a4", "declaration": "tests/usage/type_usage_declare_qualifiers.cc:6:15", - "initializations": ["tests/usage/type_usage_declare_qualifiers.cc:6:15"], - "variable_type": 0 + "variable_type": 0, + "all_uses": ["tests/usage/type_usage_declare_qualifiers.cc:6:15"] }, { "id": 5, "usr": "c:type_usage_declare_qualifiers.cc@103@F@foo#&$@S@Type#&1S1_#@a5", "short_name": "a5", "qualified_name": "a5", "declaration": "tests/usage/type_usage_declare_qualifiers.cc:7:21", - "initializations": ["tests/usage/type_usage_declare_qualifiers.cc:7:21"], - "variable_type": 0 + "variable_type": 0, + "all_uses": ["tests/usage/type_usage_declare_qualifiers.cc:7:21"] }] } diff --git a/tests/usage/type_usage_declare_static.cc b/tests/usage/type_usage_declare_static.cc index 3d59824d..b7e81cd5 100644 --- a/tests/usage/type_usage_declare_static.cc +++ b/tests/usage/type_usage_declare_static.cc @@ -6,10 +6,8 @@ OUTPUT: "types": [{ "id": 0, "usr": "c:@S@Type", - "short_name": "Type", - "qualified_name": "Type", - "declaration": "tests/usage/type_usage_declare_static.cc:1:8", - "uses": ["tests/usage/type_usage_declare_static.cc:2:8"] + "all_uses": ["tests/usage/type_usage_declare_static.cc:1:8", "tests/usage/type_usage_declare_static.cc:2:8"], + "interesting_uses": ["tests/usage/type_usage_declare_static.cc:2:8"] }], "functions": [], "variables": [{ @@ -18,8 +16,8 @@ OUTPUT: "short_name": "t", "qualified_name": "t", "declaration": "tests/usage/type_usage_declare_static.cc:2:13", - "initializations": ["tests/usage/type_usage_declare_static.cc:2:13"], - "variable_type": 0 + "variable_type": 0, + "all_uses": ["tests/usage/type_usage_declare_static.cc:2:13"] }] } */ \ No newline at end of file diff --git a/tests/usage/type_usage_on_return_type.cc b/tests/usage/type_usage_on_return_type.cc index e5427bdb..43973d9a 100644 --- a/tests/usage/type_usage_on_return_type.cc +++ b/tests/usage/type_usage_on_return_type.cc @@ -12,9 +12,10 @@ class Foo { Type* Foo::Get(int) {} void Foo::Empty() {} -// TODO: Add static -// TODO: Add extern? -// TODO: verify interesting usage is reported +extern const Type& external(); + +static Type* bar(); +static Type* bar() {} /* OUTPUT: @@ -22,41 +23,53 @@ OUTPUT: "types": [{ "id": 0, "usr": "c:@S@Type", - "short_name": "Type", - "qualified_name": "Type", - "declaration": "tests/usage/type_usage_on_return_type.cc:1:8", - "uses": ["tests/usage/type_usage_on_return_type.cc:3:1", "tests/usage/type_usage_on_return_type.cc:4:1", "tests/usage/type_usage_on_return_type.cc:5:1", "tests/usage/type_usage_on_return_type.cc:8:3", "tests/usage/type_usage_on_return_type.cc:12:1"] + "all_uses": ["tests/usage/type_usage_on_return_type.cc:1:8", "tests/usage/type_usage_on_return_type.cc:3:1", "tests/usage/type_usage_on_return_type.cc:4:1", "tests/usage/type_usage_on_return_type.cc:5:1", "tests/usage/type_usage_on_return_type.cc:8:3", "tests/usage/type_usage_on_return_type.cc:12:1", "tests/usage/type_usage_on_return_type.cc:15:14", "tests/usage/type_usage_on_return_type.cc:17:8", "tests/usage/type_usage_on_return_type.cc:18:8"], + "interesting_uses": ["tests/usage/type_usage_on_return_type.cc:3:1", "tests/usage/type_usage_on_return_type.cc:4:1", "tests/usage/type_usage_on_return_type.cc:5:1", "tests/usage/type_usage_on_return_type.cc:8:3", "tests/usage/type_usage_on_return_type.cc:12:1", "tests/usage/type_usage_on_return_type.cc:15:14", "tests/usage/type_usage_on_return_type.cc:17:8", "tests/usage/type_usage_on_return_type.cc:18:8"] }, { "id": 1, "usr": "c:@S@Foo", "short_name": "Foo", "qualified_name": "Foo", "definition": "tests/usage/type_usage_on_return_type.cc:7:7", - "funcs": [1, 2] + "funcs": [1, 2], + "all_uses": ["tests/usage/type_usage_on_return_type.cc:7:7", "tests/usage/type_usage_on_return_type.cc:12:7", "tests/usage/type_usage_on_return_type.cc:13:6"] }], "functions": [{ "id": 0, "usr": "c:@F@foo#", "short_name": "foo", "qualified_name": "foo", - "declaration": "tests/usage/type_usage_on_return_type.cc:4:7", - "definition": "tests/usage/type_usage_on_return_type.cc:5:7" + "definition": "tests/usage/type_usage_on_return_type.cc:5:7", + "all_uses": ["tests/usage/type_usage_on_return_type.cc:3:7", "tests/usage/type_usage_on_return_type.cc:4:7", "tests/usage/type_usage_on_return_type.cc:5:7"] }, { "id": 1, "usr": "c:@S@Foo@F@Get#I#", "short_name": "Get", "qualified_name": "Foo::Get", - "declaration": "tests/usage/type_usage_on_return_type.cc:8:9", "definition": "tests/usage/type_usage_on_return_type.cc:12:12", - "declaring_type": 1 + "declaring_type": 1, + "all_uses": ["tests/usage/type_usage_on_return_type.cc:8:9", "tests/usage/type_usage_on_return_type.cc:12:12"] }, { "id": 2, "usr": "c:@S@Foo@F@Empty#", "short_name": "Empty", "qualified_name": "Foo::Empty", - "declaration": "tests/usage/type_usage_on_return_type.cc:9:8", "definition": "tests/usage/type_usage_on_return_type.cc:13:11", - "declaring_type": 1 + "declaring_type": 1, + "all_uses": ["tests/usage/type_usage_on_return_type.cc:9:8", "tests/usage/type_usage_on_return_type.cc:13:11"] + }, { + "id": 3, + "usr": "c:@F@external#", + "short_name": "external", + "qualified_name": "external", + "all_uses": ["tests/usage/type_usage_on_return_type.cc:15:20"] + }, { + "id": 4, + "usr": "c:type_usage_on_return_type.cc@F@bar#", + "short_name": "bar", + "qualified_name": "bar", + "definition": "tests/usage/type_usage_on_return_type.cc:18:14", + "all_uses": ["tests/usage/type_usage_on_return_type.cc:17:14", "tests/usage/type_usage_on_return_type.cc:18:14"] }], "variables": [] }