From c598f3ebbd699d45b1dcd68125bde188b654d7e5 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 1 Nov 2018 20:26:00 -0700 Subject: [PATCH] Fix EnumConstantDecl's kind & EnumDecl's vars --- index_tests/enums/enum_class_decl.cc | 12 ++++++++--- index_tests/enums/enum_decl.cc | 8 ++++---- index_tests/enums/enum_inherit.cc | 20 ++++++++++++------- index_tests/enums/enum_usage.cc | 12 ++++++++--- index_tests/macros/complex.cc | 4 ++-- index_tests/macros/foo.cc | 4 ++-- index_tests/multi_file/funky_enum.cc | 12 +++++------ index_tests/multi_file/impl.cc | 12 +++++------ index_tests/namespaces/anonymous_function.cc | 18 +---------------- index_tests/templates/specialization.cc | 8 ++++---- ...emplate_class_var_usage_folded_into_one.cc | 2 +- index_tests/usage/var_usage_call_function.cc | 6 +++--- .../usage/var_usage_class_member_static.cc | 2 +- .../vars/class_static_member_decl_only.cc | 2 +- index_tests/vars/deduce_auto_type.cc | 4 ++-- src/indexer.cc | 17 ++++++++-------- 16 files changed, 73 insertions(+), 70 deletions(-) diff --git a/index_tests/enums/enum_class_decl.cc b/index_tests/enums/enum_class_decl.cc index a49e0ed1..f1b8c10d 100644 --- a/index_tests/enums/enum_class_decl.cc +++ b/index_tests/enums/enum_class_decl.cc @@ -36,7 +36,13 @@ OUTPUT: "bases": [], "funcs": [], "types": [], - "vars": [], + "vars": [{ + "L": 439339022761937396, + "R": -1 + }, { + "L": 15962370213938840720, + "R": -1 + }], "alias_of": 0, "kind": 10, "parent_kind": 0, @@ -52,7 +58,7 @@ OUTPUT: "short_name": "A", "hover": "Foo::A = 0", "spell": "3:3-3:4|3:3-3:4|1026|-1", - "type": 0, + "type": 16985894625255407295, "kind": 22, "parent_kind": 10, "storage": 0, @@ -64,7 +70,7 @@ OUTPUT: "qual_name_offset": 0, "short_name": "B", "spell": "4:3-4:4|4:3-4:9|1026|-1", - "type": 0, + "type": 16985894625255407295, "kind": 22, "parent_kind": 10, "storage": 0, diff --git a/index_tests/enums/enum_decl.cc b/index_tests/enums/enum_decl.cc index 16697d86..fd84c0b6 100644 --- a/index_tests/enums/enum_decl.cc +++ b/index_tests/enums/enum_decl.cc @@ -34,9 +34,9 @@ OUTPUT: "short_name": "A", "hover": "A = 0", "spell": "2:3-2:4|2:3-2:4|1026|-1", - "type": 0, + "type": 16985894625255407295, "kind": 22, - "parent_kind": 10, + "parent_kind": 0, "storage": 0, "declarations": [], "uses": [] @@ -46,9 +46,9 @@ OUTPUT: "qual_name_offset": 0, "short_name": "B", "spell": "3:3-3:4|3:3-3:9|1026|-1", - "type": 0, + "type": 16985894625255407295, "kind": 22, - "parent_kind": 10, + "parent_kind": 0, "storage": 0, "declarations": [], "uses": [] diff --git a/index_tests/enums/enum_inherit.cc b/index_tests/enums/enum_inherit.cc index 3bf68d52..9459dcfe 100644 --- a/index_tests/enums/enum_inherit.cc +++ b/index_tests/enums/enum_inherit.cc @@ -25,7 +25,13 @@ OUTPUT: "bases": [], "funcs": [], "types": [], - "vars": [], + "vars": [{ + "L": 16614320383091394267, + "R": -1 + }, { + "L": 16847439761518576294, + "R": -1 + }], "alias_of": 0, "kind": 10, "parent_kind": 0, @@ -75,9 +81,9 @@ OUTPUT: "short_name": "A", "hover": "A = 0", "spell": "2:3-2:4|2:3-2:4|1026|-1", - "type": 0, + "type": 16985894625255407295, "kind": 22, - "parent_kind": 10, + "parent_kind": 0, "storage": 0, "declarations": [], "uses": [] @@ -87,9 +93,9 @@ OUTPUT: "qual_name_offset": 0, "short_name": "B", "spell": "3:3-3:4|3:3-3:9|1026|-1", - "type": 0, + "type": 16985894625255407295, "kind": 22, - "parent_kind": 10, + "parent_kind": 0, "storage": 0, "declarations": [], "uses": [] @@ -100,7 +106,7 @@ OUTPUT: "short_name": "E0", "hover": "E::E0 = 0", "spell": "9:3-9:5|9:3-9:5|1026|-1", - "type": 0, + "type": 2986879766914123941, "kind": 22, "parent_kind": 10, "storage": 0, @@ -112,7 +118,7 @@ OUTPUT: "qual_name_offset": 0, "short_name": "E20", "spell": "10:3-10:6|10:3-10:11|1026|-1", - "type": 0, + "type": 2986879766914123941, "kind": 22, "parent_kind": 10, "storage": 0, diff --git a/index_tests/enums/enum_usage.cc b/index_tests/enums/enum_usage.cc index 9d303710..c3a9a641 100644 --- a/index_tests/enums/enum_usage.cc +++ b/index_tests/enums/enum_usage.cc @@ -20,7 +20,13 @@ OUTPUT: "bases": [], "funcs": [], "types": [], - "vars": [], + "vars": [{ + "L": 439339022761937396, + "R": -1 + }, { + "L": 15962370213938840720, + "R": -1 + }], "alias_of": 0, "kind": 10, "parent_kind": 0, @@ -36,7 +42,7 @@ OUTPUT: "short_name": "A", "hover": "Foo::A = 0", "spell": "2:3-2:4|2:3-2:4|1026|-1", - "type": 0, + "type": 16985894625255407295, "kind": 22, "parent_kind": 10, "storage": 0, @@ -61,7 +67,7 @@ OUTPUT: "qual_name_offset": 0, "short_name": "B", "spell": "3:3-3:4|3:3-3:9|1026|-1", - "type": 0, + "type": 16985894625255407295, "kind": 22, "parent_kind": 10, "storage": 0, diff --git a/index_tests/macros/complex.cc b/index_tests/macros/complex.cc index 41388665..55ac9624 100644 --- a/index_tests/macros/complex.cc +++ b/index_tests/macros/complex.cc @@ -21,14 +21,14 @@ OUTPUT: "detailed_name": "int a()", "qual_name_offset": 4, "short_name": "a", - "spell": "12:1-12:20|12:1-12:20|2|-1", + "spell": "12:1-12:20|12:1-12:4|2|-1", "bases": [], "vars": [], "callees": ["12:5-12:10|14400399977994209582|3|16420"], "kind": 12, "parent_kind": 0, "storage": 0, - "declarations": ["12:1-12:20|12:1-12:20|1|-1"], + "declarations": ["12:1-12:20|12:1-12:4|1|-1"], "derived": [], "uses": ["2:7-2:8|64|0", "3:7-3:8|64|0"] }, { diff --git a/index_tests/macros/foo.cc b/index_tests/macros/foo.cc index c8744e74..a7507831 100644 --- a/index_tests/macros/foo.cc +++ b/index_tests/macros/foo.cc @@ -17,7 +17,7 @@ OUTPUT: "detailed_name": "Foo::Foo(Foo &&) = delete", "qual_name_offset": 0, "short_name": "Foo", - "spell": "5:12-5:15|5:12-5:15|1026|-1", + "spell": "5:12-5:15|5:3-5:11|1026|-1", "bases": [], "vars": [], "callees": [], @@ -94,7 +94,7 @@ OUTPUT: "qual_name_offset": 4, "short_name": "x", "hover": "int x = A", - "spell": "8:5-8:6|8:1-1:1|2|-1", + "spell": "8:5-8:6|8:1-8:10|2|-1", "type": 53, "kind": 13, "parent_kind": 0, diff --git a/index_tests/multi_file/funky_enum.cc b/index_tests/multi_file/funky_enum.cc index 7ceb5e71..b30c456d 100644 --- a/index_tests/multi_file/funky_enum.cc +++ b/index_tests/multi_file/funky_enum.cc @@ -20,9 +20,9 @@ OUTPUT: funky_enum.h "hover": "A = 0", "comments": "This file cannot be built directory. It is included in an enum definition of\nanother file.", "spell": "4:1-4:2|4:1-4:2|1026|-1", - "type": 0, + "type": 16985894625255407295, "kind": 22, - "parent_kind": 10, + "parent_kind": 0, "storage": 0, "declarations": [], "uses": [] @@ -34,9 +34,9 @@ OUTPUT: funky_enum.h "hover": "C = 2", "comments": "This file cannot be built directory. It is included in an enum definition of\nanother file.", "spell": "6:1-6:2|6:1-6:2|1026|-1", - "type": 0, + "type": 16985894625255407295, "kind": 22, - "parent_kind": 10, + "parent_kind": 0, "storage": 0, "declarations": [], "uses": [] @@ -48,9 +48,9 @@ OUTPUT: funky_enum.h "hover": "B = 1", "comments": "This file cannot be built directory. It is included in an enum definition of\nanother file.", "spell": "5:1-5:2|5:1-5:2|1026|-1", - "type": 0, + "type": 16985894625255407295, "kind": 22, - "parent_kind": 10, + "parent_kind": 0, "storage": 0, "declarations": [], "uses": [] diff --git a/index_tests/multi_file/impl.cc b/index_tests/multi_file/impl.cc index 927f871b..9e6e477a 100644 --- a/index_tests/multi_file/impl.cc +++ b/index_tests/multi_file/impl.cc @@ -146,9 +146,9 @@ OUTPUT: header.h "short_name": "A", "hover": "A = 0", "spell": "15:13-15:14|15:13-15:14|1026|-1", - "type": 0, + "type": 4481210672785600703, "kind": 22, - "parent_kind": 10, + "parent_kind": 0, "storage": 0, "declarations": [], "uses": [] @@ -159,9 +159,9 @@ OUTPUT: header.h "short_name": "C", "hover": "C = 2", "spell": "15:19-15:20|15:19-15:20|1026|-1", - "type": 0, + "type": 4481210672785600703, "kind": 22, - "parent_kind": 10, + "parent_kind": 0, "storage": 0, "declarations": [], "uses": [] @@ -184,9 +184,9 @@ OUTPUT: header.h "short_name": "B", "hover": "B = 1", "spell": "15:16-15:17|15:16-15:17|1026|-1", - "type": 0, + "type": 4481210672785600703, "kind": 22, - "parent_kind": 10, + "parent_kind": 0, "storage": 0, "declarations": [], "uses": [] diff --git a/index_tests/namespaces/anonymous_function.cc b/index_tests/namespaces/anonymous_function.cc index 7a69afce..e8bebc88 100644 --- a/index_tests/namespaces/anonymous_function.cc +++ b/index_tests/namespaces/anonymous_function.cc @@ -22,23 +22,7 @@ OUTPUT: "derived": [], "uses": [] }], - "usr2type": [{ - "usr": 7144845543074395457, - "detailed_name": "", - "qual_name_offset": 0, - "short_name": "", - "bases": [], - "funcs": [5010253035933134245], - "types": [], - "vars": [], - "alias_of": 0, - "kind": 0, - "parent_kind": 0, - "declarations": [], - "derived": [], - "instances": [], - "uses": [] - }], + "usr2type": [], "usr2var": [] } */ diff --git a/index_tests/templates/specialization.cc b/index_tests/templates/specialization.cc index 4b414b7d..b943c207 100644 --- a/index_tests/templates/specialization.cc +++ b/index_tests/templates/specialization.cc @@ -349,9 +349,9 @@ OUTPUT: "short_name": "Enum1", "hover": "Enum1 = 1", "spell": "36:10-36:15|36:10-36:15|1026|-1", - "type": 0, + "type": 9201299975592934124, "kind": 22, - "parent_kind": 10, + "parent_kind": 0, "storage": 0, "declarations": [], "uses": [] @@ -387,9 +387,9 @@ OUTPUT: "short_name": "Enum0", "hover": "Enum0 = 0", "spell": "36:3-36:8|36:3-36:8|1026|-1", - "type": 0, + "type": 9201299975592934124, "kind": 22, - "parent_kind": 10, + "parent_kind": 0, "storage": 0, "declarations": [], "uses": ["43:20-43:25|4|-1"] diff --git a/index_tests/templates/template_class_var_usage_folded_into_one.cc b/index_tests/templates/template_class_var_usage_folded_into_one.cc index 8f8f0cd4..f2c4390c 100644 --- a/index_tests/templates/template_class_var_usage_folded_into_one.cc +++ b/index_tests/templates/template_class_var_usage_folded_into_one.cc @@ -67,7 +67,7 @@ OUTPUT: "hover": "static constexpr int Foo::var = 3", "type": 53, "kind": 13, - "parent_kind": 0, + "parent_kind": 23, "storage": 2, "declarations": ["3:24-3:27|3:3-3:31|1025|-1"], "uses": ["6:19-6:22|12|-1", "7:20-7:23|12|-1"] diff --git a/index_tests/usage/var_usage_call_function.cc b/index_tests/usage/var_usage_call_function.cc index 1b867cea..0a0df74f 100644 --- a/index_tests/usage/var_usage_call_function.cc +++ b/index_tests/usage/var_usage_call_function.cc @@ -46,10 +46,10 @@ OUTPUT: "usr2type": [], "usr2var": [{ "usr": 9121974011454213596, - "detailed_name": "auto x", - "qual_name_offset": 5, + "detailed_name": "void (*)() x", + "qual_name_offset": 11, "short_name": "x", - "hover": "auto x = &called", + "hover": "void (*)() x = &called", "spell": "4:8-4:9|4:3-4:19|2|-1", "type": 0, "kind": 13, diff --git a/index_tests/usage/var_usage_class_member_static.cc b/index_tests/usage/var_usage_class_member_static.cc index 9c8e4d57..1206c2d8 100644 --- a/index_tests/usage/var_usage_class_member_static.cc +++ b/index_tests/usage/var_usage_class_member_static.cc @@ -84,7 +84,7 @@ OUTPUT: "short_name": "x", "type": 53, "kind": 13, - "parent_kind": 0, + "parent_kind": 23, "storage": 2, "declarations": ["2:14-2:15|2:3-2:15|1025|-1"], "uses": ["8:15-8:16|12|-1"] diff --git a/index_tests/vars/class_static_member_decl_only.cc b/index_tests/vars/class_static_member_decl_only.cc index c0a3172a..0cf61b2c 100644 --- a/index_tests/vars/class_static_member_decl_only.cc +++ b/index_tests/vars/class_static_member_decl_only.cc @@ -48,7 +48,7 @@ OUTPUT: "short_name": "member", "type": 53, "kind": 13, - "parent_kind": 0, + "parent_kind": 5, "storage": 2, "declarations": ["2:14-2:20|2:3-2:20|1025|-1"], "uses": [] diff --git a/index_tests/vars/deduce_auto_type.cc b/index_tests/vars/deduce_auto_type.cc index a86eb701..7e9c0cbc 100644 --- a/index_tests/vars/deduce_auto_type.cc +++ b/index_tests/vars/deduce_auto_type.cc @@ -45,10 +45,10 @@ OUTPUT: }], "usr2var": [{ "usr": 10601729374837386290, - "detailed_name": "auto x", + "detailed_name": "Foo *x", "qual_name_offset": 5, "short_name": "x", - "hover": "auto x = new Foo()", + "hover": "Foo *x = new Foo()", "spell": "3:8-3:9|3:3-3:21|2|-1", "type": 15041163540773201510, "kind": 13, diff --git a/src/indexer.cc b/src/indexer.cc index 6dc51d6b..4dc02aeb 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -840,21 +840,21 @@ public: if (var->def.detailed_name[0] == '\0') SetVarName(D, info->short_name, info->qualified, var->def); QualType T; - if (auto *VD = dyn_cast(D)) + if (auto *VD = dyn_cast(D)) T = VD->getType(); - else if (auto *FD = dyn_cast(D)) - T = FD->getType(); if (is_def || is_decl) { const Decl *DC = cast(SemDC); - if (GetSymbolKind(DC, ls_kind) == SymbolKind::Func) + SymbolKind kind = GetSymbolKind(DC, var->def.parent_kind); + if (kind == SymbolKind::Func) db->ToFunc(GetUsr(DC)).def.vars.push_back(usr); - else if (auto *ND = dyn_cast(SemDC)) - db->ToType(GetUsr(ND)).def.vars.emplace_back(usr, -1); + else if (kind == SymbolKind::Type && !isa(SemDC)) + db->ToType(GetUsr(DC)).def.vars.emplace_back(usr, -1); if (!T.isNull()) { if (auto *BT = T->getAs()) { Usr usr1 = static_cast(BT->getKind()); var->def.type = usr1; - db->ToType(usr1).instances.push_back(usr); + if (!isa(D)) + db->ToType(usr1).instances.push_back(usr); } else if (const Decl *D1 = GetAdjustedDecl(GetTypeDecl(T))) { if (isa(D1)) { // e.g. TemplateTypeParmDecl is not handled by @@ -882,7 +882,8 @@ public: IndexParam::DeclInfo *info1; Usr usr1 = GetUsr(D1, &info1); var->def.type = usr1; - db->ToType(usr1).instances.push_back(usr); + if (!isa(D)) + db->ToType(usr1).instances.push_back(usr); } } } else if (!var->def.spell && var->declarations.empty()) {