Skip to content

Commit c598f3e

Browse files
committed
Fix EnumConstantDecl's kind & EnumDecl's vars
1 parent c8e57ee commit c598f3e

16 files changed

+73
-70
lines changed

index_tests/enums/enum_class_decl.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ enum class Foo : uint8_t {
3636
"bases": [],
3737
"funcs": [],
3838
"types": [],
39-
"vars": [],
39+
"vars": [{
40+
"L": 439339022761937396,
41+
"R": -1
42+
}, {
43+
"L": 15962370213938840720,
44+
"R": -1
45+
}],
4046
"alias_of": 0,
4147
"kind": 10,
4248
"parent_kind": 0,
@@ -52,7 +58,7 @@ enum class Foo : uint8_t {
5258
"short_name": "A",
5359
"hover": "Foo::A = 0",
5460
"spell": "3:3-3:4|3:3-3:4|1026|-1",
55-
"type": 0,
61+
"type": 16985894625255407295,
5662
"kind": 22,
5763
"parent_kind": 10,
5864
"storage": 0,
@@ -64,7 +70,7 @@ enum class Foo : uint8_t {
6470
"qual_name_offset": 0,
6571
"short_name": "B",
6672
"spell": "4:3-4:4|4:3-4:9|1026|-1",
67-
"type": 0,
73+
"type": 16985894625255407295,
6874
"kind": 22,
6975
"parent_kind": 10,
7076
"storage": 0,

index_tests/enums/enum_decl.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ enum Foo {
3434
"short_name": "A",
3535
"hover": "A = 0",
3636
"spell": "2:3-2:4|2:3-2:4|1026|-1",
37-
"type": 0,
37+
"type": 16985894625255407295,
3838
"kind": 22,
39-
"parent_kind": 10,
39+
"parent_kind": 0,
4040
"storage": 0,
4141
"declarations": [],
4242
"uses": []
@@ -46,9 +46,9 @@ enum Foo {
4646
"qual_name_offset": 0,
4747
"short_name": "B",
4848
"spell": "3:3-3:4|3:3-3:9|1026|-1",
49-
"type": 0,
49+
"type": 16985894625255407295,
5050
"kind": 22,
51-
"parent_kind": 10,
51+
"parent_kind": 0,
5252
"storage": 0,
5353
"declarations": [],
5454
"uses": []

index_tests/enums/enum_inherit.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ enum class E : int32_t {
2525
"bases": [],
2626
"funcs": [],
2727
"types": [],
28-
"vars": [],
28+
"vars": [{
29+
"L": 16614320383091394267,
30+
"R": -1
31+
}, {
32+
"L": 16847439761518576294,
33+
"R": -1
34+
}],
2935
"alias_of": 0,
3036
"kind": 10,
3137
"parent_kind": 0,
@@ -75,9 +81,9 @@ enum class E : int32_t {
7581
"short_name": "A",
7682
"hover": "A = 0",
7783
"spell": "2:3-2:4|2:3-2:4|1026|-1",
78-
"type": 0,
84+
"type": 16985894625255407295,
7985
"kind": 22,
80-
"parent_kind": 10,
86+
"parent_kind": 0,
8187
"storage": 0,
8288
"declarations": [],
8389
"uses": []
@@ -87,9 +93,9 @@ enum class E : int32_t {
8793
"qual_name_offset": 0,
8894
"short_name": "B",
8995
"spell": "3:3-3:4|3:3-3:9|1026|-1",
90-
"type": 0,
96+
"type": 16985894625255407295,
9197
"kind": 22,
92-
"parent_kind": 10,
98+
"parent_kind": 0,
9399
"storage": 0,
94100
"declarations": [],
95101
"uses": []
@@ -100,7 +106,7 @@ enum class E : int32_t {
100106
"short_name": "E0",
101107
"hover": "E::E0 = 0",
102108
"spell": "9:3-9:5|9:3-9:5|1026|-1",
103-
"type": 0,
109+
"type": 2986879766914123941,
104110
"kind": 22,
105111
"parent_kind": 10,
106112
"storage": 0,
@@ -112,7 +118,7 @@ enum class E : int32_t {
112118
"qual_name_offset": 0,
113119
"short_name": "E20",
114120
"spell": "10:3-10:6|10:3-10:11|1026|-1",
115-
"type": 0,
121+
"type": 2986879766914123941,
116122
"kind": 22,
117123
"parent_kind": 10,
118124
"storage": 0,

index_tests/enums/enum_usage.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ Foo x = Foo::A;
2020
"bases": [],
2121
"funcs": [],
2222
"types": [],
23-
"vars": [],
23+
"vars": [{
24+
"L": 439339022761937396,
25+
"R": -1
26+
}, {
27+
"L": 15962370213938840720,
28+
"R": -1
29+
}],
2430
"alias_of": 0,
2531
"kind": 10,
2632
"parent_kind": 0,
@@ -36,7 +42,7 @@ Foo x = Foo::A;
3642
"short_name": "A",
3743
"hover": "Foo::A = 0",
3844
"spell": "2:3-2:4|2:3-2:4|1026|-1",
39-
"type": 0,
45+
"type": 16985894625255407295,
4046
"kind": 22,
4147
"parent_kind": 10,
4248
"storage": 0,
@@ -61,7 +67,7 @@ Foo x = Foo::A;
6167
"qual_name_offset": 0,
6268
"short_name": "B",
6369
"spell": "3:3-3:4|3:3-3:9|1026|-1",
64-
"type": 0,
70+
"type": 16985894625255407295,
6571
"kind": 22,
6672
"parent_kind": 10,
6773
"storage": 0,

index_tests/macros/complex.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ FOO(make1(), make2);
2121
"detailed_name": "int a()",
2222
"qual_name_offset": 4,
2323
"short_name": "a",
24-
"spell": "12:1-12:20|12:1-12:20|2|-1",
24+
"spell": "12:1-12:20|12:1-12:4|2|-1",
2525
"bases": [],
2626
"vars": [],
2727
"callees": ["12:5-12:10|14400399977994209582|3|16420"],
2828
"kind": 12,
2929
"parent_kind": 0,
3030
"storage": 0,
31-
"declarations": ["12:1-12:20|12:1-12:20|1|-1"],
31+
"declarations": ["12:1-12:20|12:1-12:4|1|-1"],
3232
"derived": [],
3333
"uses": ["2:7-2:8|64|0", "3:7-3:8|64|0"]
3434
}, {

index_tests/macros/foo.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int x = A;
1717
"detailed_name": "Foo::Foo(Foo &&) = delete",
1818
"qual_name_offset": 0,
1919
"short_name": "Foo",
20-
"spell": "5:12-5:15|5:12-5:15|1026|-1",
20+
"spell": "5:12-5:15|5:3-5:11|1026|-1",
2121
"bases": [],
2222
"vars": [],
2323
"callees": [],
@@ -94,7 +94,7 @@ int x = A;
9494
"qual_name_offset": 4,
9595
"short_name": "x",
9696
"hover": "int x = A",
97-
"spell": "8:5-8:6|8:1-1:1|2|-1",
97+
"spell": "8:5-8:6|8:1-8:10|2|-1",
9898
"type": 53,
9999
"kind": 13,
100100
"parent_kind": 0,

index_tests/multi_file/funky_enum.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ OUTPUT: funky_enum.h
2020
"hover": "A = 0",
2121
"comments": "This file cannot be built directory. It is included in an enum definition of\nanother file.",
2222
"spell": "4:1-4:2|4:1-4:2|1026|-1",
23-
"type": 0,
23+
"type": 16985894625255407295,
2424
"kind": 22,
25-
"parent_kind": 10,
25+
"parent_kind": 0,
2626
"storage": 0,
2727
"declarations": [],
2828
"uses": []
@@ -34,9 +34,9 @@ OUTPUT: funky_enum.h
3434
"hover": "C = 2",
3535
"comments": "This file cannot be built directory. It is included in an enum definition of\nanother file.",
3636
"spell": "6:1-6:2|6:1-6:2|1026|-1",
37-
"type": 0,
37+
"type": 16985894625255407295,
3838
"kind": 22,
39-
"parent_kind": 10,
39+
"parent_kind": 0,
4040
"storage": 0,
4141
"declarations": [],
4242
"uses": []
@@ -48,9 +48,9 @@ OUTPUT: funky_enum.h
4848
"hover": "B = 1",
4949
"comments": "This file cannot be built directory. It is included in an enum definition of\nanother file.",
5050
"spell": "5:1-5:2|5:1-5:2|1026|-1",
51-
"type": 0,
51+
"type": 16985894625255407295,
5252
"kind": 22,
53-
"parent_kind": 10,
53+
"parent_kind": 0,
5454
"storage": 0,
5555
"declarations": [],
5656
"uses": []

index_tests/multi_file/impl.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ OUTPUT: header.h
146146
"short_name": "A",
147147
"hover": "A = 0",
148148
"spell": "15:13-15:14|15:13-15:14|1026|-1",
149-
"type": 0,
149+
"type": 4481210672785600703,
150150
"kind": 22,
151-
"parent_kind": 10,
151+
"parent_kind": 0,
152152
"storage": 0,
153153
"declarations": [],
154154
"uses": []
@@ -159,9 +159,9 @@ OUTPUT: header.h
159159
"short_name": "C",
160160
"hover": "C = 2",
161161
"spell": "15:19-15:20|15:19-15:20|1026|-1",
162-
"type": 0,
162+
"type": 4481210672785600703,
163163
"kind": 22,
164-
"parent_kind": 10,
164+
"parent_kind": 0,
165165
"storage": 0,
166166
"declarations": [],
167167
"uses": []
@@ -184,9 +184,9 @@ OUTPUT: header.h
184184
"short_name": "B",
185185
"hover": "B = 1",
186186
"spell": "15:16-15:17|15:16-15:17|1026|-1",
187-
"type": 0,
187+
"type": 4481210672785600703,
188188
"kind": 22,
189-
"parent_kind": 10,
189+
"parent_kind": 0,
190190
"storage": 0,
191191
"declarations": [],
192192
"uses": []

index_tests/namespaces/anonymous_function.cc

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,7 @@ void foo();
2222
"derived": [],
2323
"uses": []
2424
}],
25-
"usr2type": [{
26-
"usr": 7144845543074395457,
27-
"detailed_name": "",
28-
"qual_name_offset": 0,
29-
"short_name": "",
30-
"bases": [],
31-
"funcs": [5010253035933134245],
32-
"types": [],
33-
"vars": [],
34-
"alias_of": 0,
35-
"kind": 0,
36-
"parent_kind": 0,
37-
"declarations": [],
38-
"derived": [],
39-
"instances": [],
40-
"uses": []
41-
}],
25+
"usr2type": [],
4226
"usr2var": []
4327
}
4428
*/

index_tests/templates/specialization.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ void foo<float, 9, Enum0, kOnst + 7>(float Value);
349349
"short_name": "Enum1",
350350
"hover": "Enum1 = 1",
351351
"spell": "36:10-36:15|36:10-36:15|1026|-1",
352-
"type": 0,
352+
"type": 9201299975592934124,
353353
"kind": 22,
354-
"parent_kind": 10,
354+
"parent_kind": 0,
355355
"storage": 0,
356356
"declarations": [],
357357
"uses": []
@@ -387,9 +387,9 @@ void foo<float, 9, Enum0, kOnst + 7>(float Value);
387387
"short_name": "Enum0",
388388
"hover": "Enum0 = 0",
389389
"spell": "36:3-36:8|36:3-36:8|1026|-1",
390-
"type": 0,
390+
"type": 9201299975592934124,
391391
"kind": 22,
392-
"parent_kind": 10,
392+
"parent_kind": 0,
393393
"storage": 0,
394394
"declarations": [],
395395
"uses": ["43:20-43:25|4|-1"]

index_tests/templates/template_class_var_usage_folded_into_one.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int b = Foo<bool>::var;
6767
"hover": "static constexpr int Foo::var = 3",
6868
"type": 53,
6969
"kind": 13,
70-
"parent_kind": 0,
70+
"parent_kind": 23,
7171
"storage": 2,
7272
"declarations": ["3:24-3:27|3:3-3:31|1025|-1"],
7373
"uses": ["6:19-6:22|12|-1", "7:20-7:23|12|-1"]

index_tests/usage/var_usage_call_function.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ void caller() {
4646
"usr2type": [],
4747
"usr2var": [{
4848
"usr": 9121974011454213596,
49-
"detailed_name": "auto x",
50-
"qual_name_offset": 5,
49+
"detailed_name": "void (*)() x",
50+
"qual_name_offset": 11,
5151
"short_name": "x",
52-
"hover": "auto x = &called",
52+
"hover": "void (*)() x = &called",
5353
"spell": "4:8-4:9|4:3-4:19|2|-1",
5454
"type": 0,
5555
"kind": 13,

index_tests/usage/var_usage_class_member_static.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void foo() {
8484
"short_name": "x",
8585
"type": 53,
8686
"kind": 13,
87-
"parent_kind": 0,
87+
"parent_kind": 23,
8888
"storage": 2,
8989
"declarations": ["2:14-2:15|2:3-2:15|1025|-1"],
9090
"uses": ["8:15-8:16|12|-1"]

index_tests/vars/class_static_member_decl_only.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Foo {
4848
"short_name": "member",
4949
"type": 53,
5050
"kind": 13,
51-
"parent_kind": 0,
51+
"parent_kind": 5,
5252
"storage": 2,
5353
"declarations": ["2:14-2:20|2:3-2:20|1025|-1"],
5454
"uses": []

index_tests/vars/deduce_auto_type.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ void f() {
4545
}],
4646
"usr2var": [{
4747
"usr": 10601729374837386290,
48-
"detailed_name": "auto x",
48+
"detailed_name": "Foo *x",
4949
"qual_name_offset": 5,
5050
"short_name": "x",
51-
"hover": "auto x = new Foo()",
51+
"hover": "Foo *x = new Foo()",
5252
"spell": "3:8-3:9|3:3-3:21|2|-1",
5353
"type": 15041163540773201510,
5454
"kind": 13,

src/indexer.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -840,21 +840,21 @@ class IndexDataConsumer : public index::IndexDataConsumer {
840840
if (var->def.detailed_name[0] == '\0')
841841
SetVarName(D, info->short_name, info->qualified, var->def);
842842
QualType T;
843-
if (auto *VD = dyn_cast<VarDecl>(D))
843+
if (auto *VD = dyn_cast<ValueDecl>(D))
844844
T = VD->getType();
845-
else if (auto *FD = dyn_cast<FieldDecl>(D))
846-
T = FD->getType();
847845
if (is_def || is_decl) {
848846
const Decl *DC = cast<Decl>(SemDC);
849-
if (GetSymbolKind(DC, ls_kind) == SymbolKind::Func)
847+
SymbolKind kind = GetSymbolKind(DC, var->def.parent_kind);
848+
if (kind == SymbolKind::Func)
850849
db->ToFunc(GetUsr(DC)).def.vars.push_back(usr);
851-
else if (auto *ND = dyn_cast<NamespaceDecl>(SemDC))
852-
db->ToType(GetUsr(ND)).def.vars.emplace_back(usr, -1);
850+
else if (kind == SymbolKind::Type && !isa<RecordDecl>(SemDC))
851+
db->ToType(GetUsr(DC)).def.vars.emplace_back(usr, -1);
853852
if (!T.isNull()) {
854853
if (auto *BT = T->getAs<BuiltinType>()) {
855854
Usr usr1 = static_cast<Usr>(BT->getKind());
856855
var->def.type = usr1;
857-
db->ToType(usr1).instances.push_back(usr);
856+
if (!isa<EnumConstantDecl>(D))
857+
db->ToType(usr1).instances.push_back(usr);
858858
} else if (const Decl *D1 = GetAdjustedDecl(GetTypeDecl(T))) {
859859
if (isa<TemplateTypeParmDecl>(D1)) {
860860
// e.g. TemplateTypeParmDecl is not handled by
@@ -882,7 +882,8 @@ class IndexDataConsumer : public index::IndexDataConsumer {
882882
IndexParam::DeclInfo *info1;
883883
Usr usr1 = GetUsr(D1, &info1);
884884
var->def.type = usr1;
885-
db->ToType(usr1).instances.push_back(usr);
885+
if (!isa<EnumConstantDecl>(D))
886+
db->ToType(usr1).instances.push_back(usr);
886887
}
887888
}
888889
} else if (!var->def.spell && var->declarations.empty()) {

0 commit comments

Comments
 (0)