diff --git a/main.cpp b/main.cpp index 1b8ec90e..48efbdc3 100644 --- a/main.cpp +++ b/main.cpp @@ -1411,6 +1411,7 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re // TODO: Index entity call/ctor creation, like Foo().x = 3 switch (ref->referencedEntity->kind) { + case CXIdxEntity_CXXStaticVariable: case CXIdxEntity_Variable: case CXIdxEntity_Field: { @@ -1704,7 +1705,7 @@ 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/usage_inside_of_call.cc") continue; + //if (path != "tests/usage/usage_inside_of_call.cc") continue; //if (path != "tests/usage/type_usage_typedef_and_using.cc") continue; //if (path != "tests/usage/type_usage_declare_local.cc") continue; //if (path != "tests/usage/func_usage_addr_method.cc") continue; diff --git a/tests/foobar.cc b/tests/foobar.cc index 571a7fdb..2bcb7922 100644 --- a/tests/foobar.cc +++ b/tests/foobar.cc @@ -1,51 +1,39 @@ -struct Foo { - static Foo* Used(); -}; +void called(int a); -void user() { - Foo* x = Foo::Used(); +int gen() { return 1; } + +void foo() { + called(gen() * gen()); } /* - -// TODO: Maybe only interesting usage of type is for function return type + variable declaration? -// TODO: Checking last location doesn't work for type usage all_uses... - OUTPUT: { - "types": [{ - "id": 0, - "usr": "c:@S@Foo", - "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"], - "interesting_uses": ["tests/foobar.cc:2:10", "tests/foobar.cc:6:3"] - }], + "types": [], "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"] + "usr": "c:@F@called#I#", + "short_name": "called", + "qualified_name": "called", + "callers": ["2@tests/foobar.cc:6:3"], + "all_uses": ["tests/foobar.cc:1:6", "tests/foobar.cc:6:3"] }, { "id": 1, - "usr": "c:@F@user#", - "short_name": "user", - "qualified_name": "user", + "usr": "c:@F@gen#", + "short_name": "gen", + "qualified_name": "gen", + "definition": "tests/foobar.cc:3:5", + "callers": ["2@tests/foobar.cc:6:10", "2@tests/foobar.cc:6:18"], + "all_uses": ["tests/foobar.cc:3:5", "tests/foobar.cc:6:10", "tests/foobar.cc:6:18"] + }, { + "id": 2, + "usr": "c:@F@foo#", + "short_name": "foo", + "qualified_name": "foo", "definition": "tests/foobar.cc:5:6", - "callees": ["0@tests/foobar.cc:6:17"], + "callees": ["0@tests/foobar.cc:6:3", "1@tests/foobar.cc:6:10", "1@tests/foobar.cc:6:18"], "all_uses": ["tests/foobar.cc:5:6"] }], - "variables": [{ - "id": 0, - "usr": "c:foobar.cc@60@F@user#@x", - "short_name": "x", - "qualified_name": "x", - "declaration": "tests/foobar.cc:6:8", - "variable_type": 0, - "all_uses": ["tests/foobar.cc:6:8"] - }] + "variables": [] } */ \ No newline at end of file diff --git a/tests/usage/usage_inside_of_call.cc b/tests/usage/usage_inside_of_call.cc index 78c8ff34..28347e63 100644 --- a/tests/usage/usage_inside_of_call.cc +++ b/tests/usage/usage_inside_of_call.cc @@ -38,7 +38,6 @@ OUTPUT: "usr": "c:@F@gen#", "short_name": "gen", "qualified_name": "gen", - "declaration": "tests/usage/usage_inside_of_call.cc:3:5", "callers": ["2@tests/usage/usage_inside_of_call.cc:14:14"], "all_uses": ["tests/usage/usage_inside_of_call.cc:3:5", "tests/usage/usage_inside_of_call.cc:14:14"] }, { @@ -46,42 +45,33 @@ OUTPUT: "usr": "c:@F@foo#", "short_name": "foo", "qualified_name": "foo", - "definition": "tests/usage/usage_inside_of_call.cc:10:6", - "callees": ["0@tests/usage/usage_inside_of_call.cc:12:3", "1@tests/usage/usage_inside_of_call.cc:12:14", "3@tests/usage/usage_inside_of_call.cc:12:22"] - }, { - "id": 3, - "usr": "c:@S@Foo@F@Foo#", - "callers": ["2@tests/usage/usage_inside_of_call.cc:12:22"], - "uses": ["tests/usage/usage_inside_of_call.cc:12:22"] + "definition": "tests/usage/usage_inside_of_call.cc:12:6", + "callees": ["0@tests/usage/usage_inside_of_call.cc:14:3", "1@tests/usage/usage_inside_of_call.cc:14:14"], + "all_uses": ["tests/usage/usage_inside_of_call.cc:12:6"] }], - - - "variables": [{ "id": 0, "usr": "c:@S@Foo@static_var", "short_name": "static_var", "qualified_name": "Foo::static_var", - "declaration": "tests/usage/usage_inside_of_call.cc:6:14", + "declaration": "tests/usage/usage_inside_of_call.cc:10:10", "declaring_type": 0, - "uses": ["tests/usage/usage_inside_of_call.cc:12:45"] + "all_uses": ["tests/usage/usage_inside_of_call.cc:6:14", "tests/usage/usage_inside_of_call.cc:10:10", "tests/usage/usage_inside_of_call.cc:14:45"] }, { "id": 1, "usr": "c:@S@Foo@FI@field_var", "short_name": "field_var", "qualified_name": "Foo::field_var", "declaration": "tests/usage/usage_inside_of_call.cc:7:7", - "initializations": ["tests/usage/usage_inside_of_call.cc:7:7"], "declaring_type": 0, - "uses": ["tests/usage/usage_inside_of_call.cc:12:28"] + "all_uses": ["tests/usage/usage_inside_of_call.cc:7:7", "tests/usage/usage_inside_of_call.cc:14:28"] }, { "id": 2, - "usr": "c:usage_inside_of_call.cc@117@F@foo#@a", + "usr": "c:usage_inside_of_call.cc@145@F@foo#@a", "short_name": "a", "qualified_name": "a", - "declaration": "tests/usage/usage_inside_of_call.cc:11:7", - "initializations": ["tests/usage/usage_inside_of_call.cc:11:7"], - "uses": ["tests/usage/usage_inside_of_call.cc:12:10"] + "declaration": "tests/usage/usage_inside_of_call.cc:13:7", + "all_uses": ["tests/usage/usage_inside_of_call.cc:13:7", "tests/usage/usage_inside_of_call.cc:14:10"] }] } */ \ No newline at end of file diff --git a/tests/usage/usage_inside_of_call_simple.cc b/tests/usage/usage_inside_of_call_simple.cc new file mode 100644 index 00000000..7b25c97d --- /dev/null +++ b/tests/usage/usage_inside_of_call_simple.cc @@ -0,0 +1,39 @@ +void called(int a); + +int gen() { return 1; } + +void foo() { + called(gen() * gen()); +} + +/* +OUTPUT: +{ + "types": [], + "functions": [{ + "id": 0, + "usr": "c:@F@called#I#", + "short_name": "called", + "qualified_name": "called", + "callers": ["2@tests/usage/usage_inside_of_call_simple.cc:6:3"], + "all_uses": ["tests/usage/usage_inside_of_call_simple.cc:1:6", "tests/usage/usage_inside_of_call_simple.cc:6:3"] + }, { + "id": 1, + "usr": "c:@F@gen#", + "short_name": "gen", + "qualified_name": "gen", + "definition": "tests/usage/usage_inside_of_call_simple.cc:3:5", + "callers": ["2@tests/usage/usage_inside_of_call_simple.cc:6:10", "2@tests/usage/usage_inside_of_call_simple.cc:6:18"], + "all_uses": ["tests/usage/usage_inside_of_call_simple.cc:3:5", "tests/usage/usage_inside_of_call_simple.cc:6:10", "tests/usage/usage_inside_of_call_simple.cc:6:18"] + }, { + "id": 2, + "usr": "c:@F@foo#", + "short_name": "foo", + "qualified_name": "foo", + "definition": "tests/usage/usage_inside_of_call_simple.cc:5:6", + "callees": ["0@tests/usage/usage_inside_of_call_simple.cc:6:3", "1@tests/usage/usage_inside_of_call_simple.cc:6:10", "1@tests/usage/usage_inside_of_call_simple.cc:6:18"], + "all_uses": ["tests/usage/usage_inside_of_call_simple.cc:5:6"] + }], + "variables": [] +} +*/ \ No newline at end of file diff --git a/tests/usage/var_usage_class_member_static.cc b/tests/usage/var_usage_class_member_static.cc new file mode 100644 index 00000000..9bb95595 --- /dev/null +++ b/tests/usage/var_usage_class_member_static.cc @@ -0,0 +1,47 @@ +struct Foo { + static int x; +}; + +void accept(int); + +void foo() { + accept(Foo::x); +} + +/* +OUTPUT: +{ + "types": [{ + "id": 0, + "usr": "c:@S@Foo", + "short_name": "Foo", + "qualified_name": "Foo", + "definition": "tests/usage/var_usage_class_member_static.cc:1:8", + "all_uses": ["tests/usage/var_usage_class_member_static.cc:1:8", "tests/usage/var_usage_class_member_static.cc:8:10"] + }], + "functions": [{ + "id": 0, + "usr": "c:@F@accept#I#", + "short_name": "accept", + "qualified_name": "accept", + "callers": ["1@tests/usage/var_usage_class_member_static.cc:8:3"], + "all_uses": ["tests/usage/var_usage_class_member_static.cc:5:6", "tests/usage/var_usage_class_member_static.cc:8:3"] + }, { + "id": 1, + "usr": "c:@F@foo#", + "short_name": "foo", + "qualified_name": "foo", + "definition": "tests/usage/var_usage_class_member_static.cc:7:6", + "callees": ["0@tests/usage/var_usage_class_member_static.cc:8:3"], + "all_uses": ["tests/usage/var_usage_class_member_static.cc:7:6"] + }], + "variables": [{ + "id": 0, + "usr": "c:@S@Foo@x", + "short_name": "x", + "qualified_name": "Foo::x", + "declaration": "tests/usage/var_usage_class_member_static.cc:2:14", + "all_uses": ["tests/usage/var_usage_class_member_static.cc:2:14", "tests/usage/var_usage_class_member_static.cc:8:15"] + }] +} +*/ \ No newline at end of file