Skip to content

Commit

Permalink
Fix EnumConstantDecl's kind & EnumDecl's vars
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Jan 9, 2019
1 parent 90a94cb commit 334557e
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 70 deletions.
12 changes: 9 additions & 3 deletions index_tests/enums/enum_class_decl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ enum class Foo : uint8_t {
"bases": [],
"funcs": [],
"types": [],
"vars": [],
"vars": [{
"L": 439339022761937396,
"R": -1
}, {
"L": 15962370213938840720,
"R": -1
}],
"alias_of": 0,
"kind": 10,
"parent_kind": 0,
Expand All @@ -52,7 +58,7 @@ enum class Foo : uint8_t {
"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,
Expand All @@ -64,7 +70,7 @@ enum class Foo : uint8_t {
"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,
Expand Down
8 changes: 4 additions & 4 deletions index_tests/enums/enum_decl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ enum Foo {
"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": []
Expand All @@ -46,9 +46,9 @@ enum Foo {
"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": []
Expand Down
20 changes: 13 additions & 7 deletions index_tests/enums/enum_inherit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ enum class E : int32_t {
"bases": [],
"funcs": [],
"types": [],
"vars": [],
"vars": [{
"L": 16614320383091394267,
"R": -1
}, {
"L": 16847439761518576294,
"R": -1
}],
"alias_of": 0,
"kind": 10,
"parent_kind": 0,
Expand Down Expand Up @@ -75,9 +81,9 @@ enum class E : int32_t {
"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": []
Expand All @@ -87,9 +93,9 @@ enum class E : int32_t {
"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": []
Expand All @@ -100,7 +106,7 @@ enum class E : int32_t {
"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,
Expand All @@ -112,7 +118,7 @@ enum class E : int32_t {
"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,
Expand Down
12 changes: 9 additions & 3 deletions index_tests/enums/enum_usage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ Foo x = Foo::A;
"bases": [],
"funcs": [],
"types": [],
"vars": [],
"vars": [{
"L": 439339022761937396,
"R": -1
}, {
"L": 15962370213938840720,
"R": -1
}],
"alias_of": 0,
"kind": 10,
"parent_kind": 0,
Expand All @@ -36,7 +42,7 @@ Foo x = Foo::A;
"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,
Expand All @@ -61,7 +67,7 @@ Foo x = Foo::A;
"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,
Expand Down
4 changes: 2 additions & 2 deletions index_tests/macros/complex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ FOO(make1(), make2);
"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"]
}, {
Expand Down
4 changes: 2 additions & 2 deletions index_tests/macros/foo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int x = A;
"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": [],
Expand Down Expand Up @@ -94,7 +94,7 @@ int x = A;
"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,
Expand Down
12 changes: 6 additions & 6 deletions index_tests/multi_file/funky_enum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
Expand All @@ -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": []
Expand All @@ -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": []
Expand Down
12 changes: 6 additions & 6 deletions index_tests/multi_file/impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
Expand All @@ -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": []
Expand All @@ -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": []
Expand Down
18 changes: 1 addition & 17 deletions index_tests/namespaces/anonymous_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,7 @@ void foo();
"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": []
}
*/
8 changes: 4 additions & 4 deletions index_tests/templates/specialization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ void foo<float, 9, Enum0, kOnst + 7>(float Value);
"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": []
Expand Down Expand Up @@ -387,9 +387,9 @@ void foo<float, 9, Enum0, kOnst + 7>(float Value);
"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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int b = Foo<bool>::var;
"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"]
Expand Down
6 changes: 3 additions & 3 deletions index_tests/usage/var_usage_call_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ void caller() {
"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,
Expand Down
2 changes: 1 addition & 1 deletion index_tests/usage/var_usage_class_member_static.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void foo() {
"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"]
Expand Down
2 changes: 1 addition & 1 deletion index_tests/vars/class_static_member_decl_only.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Foo {
"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": []
Expand Down
4 changes: 2 additions & 2 deletions index_tests/vars/deduce_auto_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ void f() {
}],
"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,
Expand Down
17 changes: 9 additions & 8 deletions src/indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -854,21 +854,21 @@ class IndexDataConsumer : public index::IndexDataConsumer {
if (var->def.detailed_name[0] == '\0')
SetVarName(D, info->short_name, info->qualified, var->def);
QualType T;
if (auto *VD = dyn_cast<VarDecl>(D))
if (auto *VD = dyn_cast<ValueDecl>(D))
T = VD->getType();
else if (auto *FD = dyn_cast<FieldDecl>(D))
T = FD->getType();
if (is_def || is_decl) {
const Decl *DC = cast<Decl>(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<NamespaceDecl>(SemDC))
db->ToType(GetUsr(ND)).def.vars.emplace_back(usr, -1);
else if (kind == SymbolKind::Type && !isa<RecordDecl>(SemDC))
db->ToType(GetUsr(DC)).def.vars.emplace_back(usr, -1);
if (!T.isNull()) {
if (auto *BT = T->getAs<BuiltinType>()) {
Usr usr1 = static_cast<Usr>(BT->getKind());
var->def.type = usr1;
db->ToType(usr1).instances.push_back(usr);
if (!isa<EnumConstantDecl>(D))
db->ToType(usr1).instances.push_back(usr);
} else if (const Decl *D1 = GetAdjustedDecl(GetTypeDecl(T))) {
if (isa<TemplateTypeParmDecl>(D1)) {
// e.g. TemplateTypeParmDecl is not handled by
Expand Down Expand Up @@ -896,7 +896,8 @@ class IndexDataConsumer : public index::IndexDataConsumer {
IndexParam::DeclInfo *info1;
Usr usr1 = GetUsr(D1, &info1);
var->def.type = usr1;
db->ToType(usr1).instances.push_back(usr);
if (!isa<EnumConstantDecl>(D))
db->ToType(usr1).instances.push_back(usr);
}
}
} else if (!var->def.spell && var->declarations.empty()) {
Expand Down

0 comments on commit 334557e

Please sign in to comment.