static members

This commit is contained in:
Jacob Dufault 2017-02-19 22:24:05 -08:00
parent d3b57ac301
commit d01eb6b86f
5 changed files with 121 additions and 56 deletions

View File

@ -1411,6 +1411,7 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re
// TODO: Index entity call/ctor creation, like Foo().x = 3 // TODO: Index entity call/ctor creation, like Foo().x = 3
switch (ref->referencedEntity->kind) { switch (ref->referencedEntity->kind) {
case CXIdxEntity_CXXStaticVariable:
case CXIdxEntity_Variable: case CXIdxEntity_Variable:
case CXIdxEntity_Field: case CXIdxEntity_Field:
{ {
@ -1704,7 +1705,7 @@ int main(int argc, char** argv) {
// TODO: Fix all existing tests. // TODO: Fix all existing tests.
//if (path == "tests/usage/type_usage_declare_extern.cc") continue; //if (path == "tests/usage/type_usage_declare_extern.cc") continue;
if (path == "tests/constructors/constructor.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_typedef_and_using.cc") continue;
//if (path != "tests/usage/type_usage_declare_local.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_addr_method.cc") continue;

View File

@ -1,51 +1,39 @@
struct Foo { void called(int a);
static Foo* Used();
};
void user() { int gen() { return 1; }
Foo* x = Foo::Used();
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: OUTPUT:
{ {
"types": [{ "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"]
}],
"functions": [{ "functions": [{
"id": 0, "id": 0,
"usr": "c:@S@Foo@F@Used#S", "usr": "c:@F@called#I#",
"short_name": "Used", "short_name": "called",
"qualified_name": "Foo::Used", "qualified_name": "called",
"callers": ["1@tests/foobar.cc:6:17"], "callers": ["2@tests/foobar.cc:6:3"],
"all_uses": ["tests/foobar.cc:2:15", "tests/foobar.cc:6:17"] "all_uses": ["tests/foobar.cc:1:6", "tests/foobar.cc:6:3"]
}, { }, {
"id": 1, "id": 1,
"usr": "c:@F@user#", "usr": "c:@F@gen#",
"short_name": "user", "short_name": "gen",
"qualified_name": "user", "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", "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"] "all_uses": ["tests/foobar.cc:5:6"]
}], }],
"variables": [{ "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"]
}]
} }
*/ */

View File

@ -38,7 +38,6 @@ OUTPUT:
"usr": "c:@F@gen#", "usr": "c:@F@gen#",
"short_name": "gen", "short_name": "gen",
"qualified_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"], "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"] "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#", "usr": "c:@F@foo#",
"short_name": "foo", "short_name": "foo",
"qualified_name": "foo", "qualified_name": "foo",
"definition": "tests/usage/usage_inside_of_call.cc:10:6", "definition": "tests/usage/usage_inside_of_call.cc:12: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"] "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"]
"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"]
}], }],
"variables": [{ "variables": [{
"id": 0, "id": 0,
"usr": "c:@S@Foo@static_var", "usr": "c:@S@Foo@static_var",
"short_name": "static_var", "short_name": "static_var",
"qualified_name": "Foo::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, "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, "id": 1,
"usr": "c:@S@Foo@FI@field_var", "usr": "c:@S@Foo@FI@field_var",
"short_name": "field_var", "short_name": "field_var",
"qualified_name": "Foo::field_var", "qualified_name": "Foo::field_var",
"declaration": "tests/usage/usage_inside_of_call.cc:7:7", "declaration": "tests/usage/usage_inside_of_call.cc:7:7",
"initializations": ["tests/usage/usage_inside_of_call.cc:7:7"],
"declaring_type": 0, "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, "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", "short_name": "a",
"qualified_name": "a", "qualified_name": "a",
"declaration": "tests/usage/usage_inside_of_call.cc:11:7", "declaration": "tests/usage/usage_inside_of_call.cc:13:7",
"initializations": ["tests/usage/usage_inside_of_call.cc:11:7"], "all_uses": ["tests/usage/usage_inside_of_call.cc:13:7", "tests/usage/usage_inside_of_call.cc:14:10"]
"uses": ["tests/usage/usage_inside_of_call.cc:12:10"]
}] }]
} }
*/ */

View File

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

View File

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