Fix EnumConstantDecl's kind & EnumDecl's vars

This commit is contained in:
Fangrui Song 2018-11-01 20:26:00 -07:00
parent c8e57ee7b3
commit c598f3ebbd
16 changed files with 73 additions and 70 deletions

View File

@ -36,7 +36,13 @@ OUTPUT:
"bases": [], "bases": [],
"funcs": [], "funcs": [],
"types": [], "types": [],
"vars": [], "vars": [{
"L": 439339022761937396,
"R": -1
}, {
"L": 15962370213938840720,
"R": -1
}],
"alias_of": 0, "alias_of": 0,
"kind": 10, "kind": 10,
"parent_kind": 0, "parent_kind": 0,
@ -52,7 +58,7 @@ OUTPUT:
"short_name": "A", "short_name": "A",
"hover": "Foo::A = 0", "hover": "Foo::A = 0",
"spell": "3:3-3:4|3:3-3:4|1026|-1", "spell": "3:3-3:4|3:3-3:4|1026|-1",
"type": 0, "type": 16985894625255407295,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 10,
"storage": 0, "storage": 0,
@ -64,7 +70,7 @@ OUTPUT:
"qual_name_offset": 0, "qual_name_offset": 0,
"short_name": "B", "short_name": "B",
"spell": "4:3-4:4|4:3-4:9|1026|-1", "spell": "4:3-4:4|4:3-4:9|1026|-1",
"type": 0, "type": 16985894625255407295,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 10,
"storage": 0, "storage": 0,

View File

@ -34,9 +34,9 @@ OUTPUT:
"short_name": "A", "short_name": "A",
"hover": "A = 0", "hover": "A = 0",
"spell": "2:3-2:4|2:3-2:4|1026|-1", "spell": "2:3-2:4|2:3-2:4|1026|-1",
"type": 0, "type": 16985894625255407295,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 0,
"storage": 0, "storage": 0,
"declarations": [], "declarations": [],
"uses": [] "uses": []
@ -46,9 +46,9 @@ OUTPUT:
"qual_name_offset": 0, "qual_name_offset": 0,
"short_name": "B", "short_name": "B",
"spell": "3:3-3:4|3:3-3:9|1026|-1", "spell": "3:3-3:4|3:3-3:9|1026|-1",
"type": 0, "type": 16985894625255407295,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 0,
"storage": 0, "storage": 0,
"declarations": [], "declarations": [],
"uses": [] "uses": []

View File

@ -25,7 +25,13 @@ OUTPUT:
"bases": [], "bases": [],
"funcs": [], "funcs": [],
"types": [], "types": [],
"vars": [], "vars": [{
"L": 16614320383091394267,
"R": -1
}, {
"L": 16847439761518576294,
"R": -1
}],
"alias_of": 0, "alias_of": 0,
"kind": 10, "kind": 10,
"parent_kind": 0, "parent_kind": 0,
@ -75,9 +81,9 @@ OUTPUT:
"short_name": "A", "short_name": "A",
"hover": "A = 0", "hover": "A = 0",
"spell": "2:3-2:4|2:3-2:4|1026|-1", "spell": "2:3-2:4|2:3-2:4|1026|-1",
"type": 0, "type": 16985894625255407295,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 0,
"storage": 0, "storage": 0,
"declarations": [], "declarations": [],
"uses": [] "uses": []
@ -87,9 +93,9 @@ OUTPUT:
"qual_name_offset": 0, "qual_name_offset": 0,
"short_name": "B", "short_name": "B",
"spell": "3:3-3:4|3:3-3:9|1026|-1", "spell": "3:3-3:4|3:3-3:9|1026|-1",
"type": 0, "type": 16985894625255407295,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 0,
"storage": 0, "storage": 0,
"declarations": [], "declarations": [],
"uses": [] "uses": []
@ -100,7 +106,7 @@ OUTPUT:
"short_name": "E0", "short_name": "E0",
"hover": "E::E0 = 0", "hover": "E::E0 = 0",
"spell": "9:3-9:5|9:3-9:5|1026|-1", "spell": "9:3-9:5|9:3-9:5|1026|-1",
"type": 0, "type": 2986879766914123941,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 10,
"storage": 0, "storage": 0,
@ -112,7 +118,7 @@ OUTPUT:
"qual_name_offset": 0, "qual_name_offset": 0,
"short_name": "E20", "short_name": "E20",
"spell": "10:3-10:6|10:3-10:11|1026|-1", "spell": "10:3-10:6|10:3-10:11|1026|-1",
"type": 0, "type": 2986879766914123941,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 10,
"storage": 0, "storage": 0,

View File

@ -20,7 +20,13 @@ OUTPUT:
"bases": [], "bases": [],
"funcs": [], "funcs": [],
"types": [], "types": [],
"vars": [], "vars": [{
"L": 439339022761937396,
"R": -1
}, {
"L": 15962370213938840720,
"R": -1
}],
"alias_of": 0, "alias_of": 0,
"kind": 10, "kind": 10,
"parent_kind": 0, "parent_kind": 0,
@ -36,7 +42,7 @@ OUTPUT:
"short_name": "A", "short_name": "A",
"hover": "Foo::A = 0", "hover": "Foo::A = 0",
"spell": "2:3-2:4|2:3-2:4|1026|-1", "spell": "2:3-2:4|2:3-2:4|1026|-1",
"type": 0, "type": 16985894625255407295,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 10,
"storage": 0, "storage": 0,
@ -61,7 +67,7 @@ OUTPUT:
"qual_name_offset": 0, "qual_name_offset": 0,
"short_name": "B", "short_name": "B",
"spell": "3:3-3:4|3:3-3:9|1026|-1", "spell": "3:3-3:4|3:3-3:9|1026|-1",
"type": 0, "type": 16985894625255407295,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 10,
"storage": 0, "storage": 0,

View File

@ -21,14 +21,14 @@ OUTPUT:
"detailed_name": "int a()", "detailed_name": "int a()",
"qual_name_offset": 4, "qual_name_offset": 4,
"short_name": "a", "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": [], "bases": [],
"vars": [], "vars": [],
"callees": ["12:5-12:10|14400399977994209582|3|16420"], "callees": ["12:5-12:10|14400399977994209582|3|16420"],
"kind": 12, "kind": 12,
"parent_kind": 0, "parent_kind": 0,
"storage": 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": [], "derived": [],
"uses": ["2:7-2:8|64|0", "3:7-3:8|64|0"] "uses": ["2:7-2:8|64|0", "3:7-3:8|64|0"]
}, { }, {

View File

@ -17,7 +17,7 @@ OUTPUT:
"detailed_name": "Foo::Foo(Foo &&) = delete", "detailed_name": "Foo::Foo(Foo &&) = delete",
"qual_name_offset": 0, "qual_name_offset": 0,
"short_name": "Foo", "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": [], "bases": [],
"vars": [], "vars": [],
"callees": [], "callees": [],
@ -94,7 +94,7 @@ OUTPUT:
"qual_name_offset": 4, "qual_name_offset": 4,
"short_name": "x", "short_name": "x",
"hover": "int x = A", "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, "type": 53,
"kind": 13, "kind": 13,
"parent_kind": 0, "parent_kind": 0,

View File

@ -20,9 +20,9 @@ OUTPUT: funky_enum.h
"hover": "A = 0", "hover": "A = 0",
"comments": "This file cannot be built directory. It is included in an enum definition of\nanother file.", "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", "spell": "4:1-4:2|4:1-4:2|1026|-1",
"type": 0, "type": 16985894625255407295,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 0,
"storage": 0, "storage": 0,
"declarations": [], "declarations": [],
"uses": [] "uses": []
@ -34,9 +34,9 @@ OUTPUT: funky_enum.h
"hover": "C = 2", "hover": "C = 2",
"comments": "This file cannot be built directory. It is included in an enum definition of\nanother file.", "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", "spell": "6:1-6:2|6:1-6:2|1026|-1",
"type": 0, "type": 16985894625255407295,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 0,
"storage": 0, "storage": 0,
"declarations": [], "declarations": [],
"uses": [] "uses": []
@ -48,9 +48,9 @@ OUTPUT: funky_enum.h
"hover": "B = 1", "hover": "B = 1",
"comments": "This file cannot be built directory. It is included in an enum definition of\nanother file.", "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", "spell": "5:1-5:2|5:1-5:2|1026|-1",
"type": 0, "type": 16985894625255407295,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 0,
"storage": 0, "storage": 0,
"declarations": [], "declarations": [],
"uses": [] "uses": []

View File

@ -146,9 +146,9 @@ OUTPUT: header.h
"short_name": "A", "short_name": "A",
"hover": "A = 0", "hover": "A = 0",
"spell": "15:13-15:14|15:13-15:14|1026|-1", "spell": "15:13-15:14|15:13-15:14|1026|-1",
"type": 0, "type": 4481210672785600703,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 0,
"storage": 0, "storage": 0,
"declarations": [], "declarations": [],
"uses": [] "uses": []
@ -159,9 +159,9 @@ OUTPUT: header.h
"short_name": "C", "short_name": "C",
"hover": "C = 2", "hover": "C = 2",
"spell": "15:19-15:20|15:19-15:20|1026|-1", "spell": "15:19-15:20|15:19-15:20|1026|-1",
"type": 0, "type": 4481210672785600703,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 0,
"storage": 0, "storage": 0,
"declarations": [], "declarations": [],
"uses": [] "uses": []
@ -184,9 +184,9 @@ OUTPUT: header.h
"short_name": "B", "short_name": "B",
"hover": "B = 1", "hover": "B = 1",
"spell": "15:16-15:17|15:16-15:17|1026|-1", "spell": "15:16-15:17|15:16-15:17|1026|-1",
"type": 0, "type": 4481210672785600703,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 0,
"storage": 0, "storage": 0,
"declarations": [], "declarations": [],
"uses": [] "uses": []

View File

@ -22,23 +22,7 @@ OUTPUT:
"derived": [], "derived": [],
"uses": [] "uses": []
}], }],
"usr2type": [{ "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": []
}],
"usr2var": [] "usr2var": []
} }
*/ */

View File

@ -349,9 +349,9 @@ OUTPUT:
"short_name": "Enum1", "short_name": "Enum1",
"hover": "Enum1 = 1", "hover": "Enum1 = 1",
"spell": "36:10-36:15|36:10-36:15|1026|-1", "spell": "36:10-36:15|36:10-36:15|1026|-1",
"type": 0, "type": 9201299975592934124,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 0,
"storage": 0, "storage": 0,
"declarations": [], "declarations": [],
"uses": [] "uses": []
@ -387,9 +387,9 @@ OUTPUT:
"short_name": "Enum0", "short_name": "Enum0",
"hover": "Enum0 = 0", "hover": "Enum0 = 0",
"spell": "36:3-36:8|36:3-36:8|1026|-1", "spell": "36:3-36:8|36:3-36:8|1026|-1",
"type": 0, "type": 9201299975592934124,
"kind": 22, "kind": 22,
"parent_kind": 10, "parent_kind": 0,
"storage": 0, "storage": 0,
"declarations": [], "declarations": [],
"uses": ["43:20-43:25|4|-1"] "uses": ["43:20-43:25|4|-1"]

View File

@ -67,7 +67,7 @@ OUTPUT:
"hover": "static constexpr int Foo::var = 3", "hover": "static constexpr int Foo::var = 3",
"type": 53, "type": 53,
"kind": 13, "kind": 13,
"parent_kind": 0, "parent_kind": 23,
"storage": 2, "storage": 2,
"declarations": ["3:24-3:27|3:3-3:31|1025|-1"], "declarations": ["3:24-3:27|3:3-3:31|1025|-1"],
"uses": ["6:19-6:22|12|-1", "7:20-7:23|12|-1"] "uses": ["6:19-6:22|12|-1", "7:20-7:23|12|-1"]

View File

@ -46,10 +46,10 @@ OUTPUT:
"usr2type": [], "usr2type": [],
"usr2var": [{ "usr2var": [{
"usr": 9121974011454213596, "usr": 9121974011454213596,
"detailed_name": "auto x", "detailed_name": "void (*)() x",
"qual_name_offset": 5, "qual_name_offset": 11,
"short_name": "x", "short_name": "x",
"hover": "auto x = &called", "hover": "void (*)() x = &called",
"spell": "4:8-4:9|4:3-4:19|2|-1", "spell": "4:8-4:9|4:3-4:19|2|-1",
"type": 0, "type": 0,
"kind": 13, "kind": 13,

View File

@ -84,7 +84,7 @@ OUTPUT:
"short_name": "x", "short_name": "x",
"type": 53, "type": 53,
"kind": 13, "kind": 13,
"parent_kind": 0, "parent_kind": 23,
"storage": 2, "storage": 2,
"declarations": ["2:14-2:15|2:3-2:15|1025|-1"], "declarations": ["2:14-2:15|2:3-2:15|1025|-1"],
"uses": ["8:15-8:16|12|-1"] "uses": ["8:15-8:16|12|-1"]

View File

@ -48,7 +48,7 @@ OUTPUT:
"short_name": "member", "short_name": "member",
"type": 53, "type": 53,
"kind": 13, "kind": 13,
"parent_kind": 0, "parent_kind": 5,
"storage": 2, "storage": 2,
"declarations": ["2:14-2:20|2:3-2:20|1025|-1"], "declarations": ["2:14-2:20|2:3-2:20|1025|-1"],
"uses": [] "uses": []

View File

@ -45,10 +45,10 @@ OUTPUT:
}], }],
"usr2var": [{ "usr2var": [{
"usr": 10601729374837386290, "usr": 10601729374837386290,
"detailed_name": "auto x", "detailed_name": "Foo *x",
"qual_name_offset": 5, "qual_name_offset": 5,
"short_name": "x", "short_name": "x",
"hover": "auto x = new Foo()", "hover": "Foo *x = new Foo()",
"spell": "3:8-3:9|3:3-3:21|2|-1", "spell": "3:8-3:9|3:3-3:21|2|-1",
"type": 15041163540773201510, "type": 15041163540773201510,
"kind": 13, "kind": 13,

View File

@ -840,21 +840,21 @@ public:
if (var->def.detailed_name[0] == '\0') if (var->def.detailed_name[0] == '\0')
SetVarName(D, info->short_name, info->qualified, var->def); SetVarName(D, info->short_name, info->qualified, var->def);
QualType T; QualType T;
if (auto *VD = dyn_cast<VarDecl>(D)) if (auto *VD = dyn_cast<ValueDecl>(D))
T = VD->getType(); T = VD->getType();
else if (auto *FD = dyn_cast<FieldDecl>(D))
T = FD->getType();
if (is_def || is_decl) { if (is_def || is_decl) {
const Decl *DC = cast<Decl>(SemDC); 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); db->ToFunc(GetUsr(DC)).def.vars.push_back(usr);
else if (auto *ND = dyn_cast<NamespaceDecl>(SemDC)) else if (kind == SymbolKind::Type && !isa<RecordDecl>(SemDC))
db->ToType(GetUsr(ND)).def.vars.emplace_back(usr, -1); db->ToType(GetUsr(DC)).def.vars.emplace_back(usr, -1);
if (!T.isNull()) { if (!T.isNull()) {
if (auto *BT = T->getAs<BuiltinType>()) { if (auto *BT = T->getAs<BuiltinType>()) {
Usr usr1 = static_cast<Usr>(BT->getKind()); Usr usr1 = static_cast<Usr>(BT->getKind());
var->def.type = usr1; 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))) { } else if (const Decl *D1 = GetAdjustedDecl(GetTypeDecl(T))) {
if (isa<TemplateTypeParmDecl>(D1)) { if (isa<TemplateTypeParmDecl>(D1)) {
// e.g. TemplateTypeParmDecl is not handled by // e.g. TemplateTypeParmDecl is not handled by
@ -882,7 +882,8 @@ public:
IndexParam::DeclInfo *info1; IndexParam::DeclInfo *info1;
Usr usr1 = GetUsr(D1, &info1); Usr usr1 = GetUsr(D1, &info1);
var->def.type = usr1; 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()) { } else if (!var->def.spell && var->declarations.empty()) {