Skip to content

Commit

Permalink
Make CXXConversion references wider; use getTypedefNameForAnonDecl; i…
Browse files Browse the repository at this point in the history
…mprove CXXDestructor CXXConversion spell
  • Loading branch information
MaskRay committed Sep 11, 2018
1 parent 92ee7f3 commit c202dd3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion index_tests/constructors/destructor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void foo() {
"kind": 6,
"storage": 0,
"declarations": [],
"spell": "4:3-4:4|15041163540773201510|2|1026|-1",
"spell": "4:3-4:7|15041163540773201510|2|1026|-1",
"extent": "4:3-4:12|15041163540773201510|2|0|-1",
"bases": [],
"derived": [],
Expand Down
6 changes: 3 additions & 3 deletions index_tests/inheritance/multiple_base_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct Derived : Base0, Base1 {
"kind": 6,
"storage": 0,
"declarations": [],
"spell": "5:11-5:12|15826803741381445676|2|1090|-1",
"spell": "5:11-5:17|15826803741381445676|2|1090|-1",
"extent": "5:3-5:23|15826803741381445676|2|0|-1",
"bases": [],
"derived": [],
Expand All @@ -36,7 +36,7 @@ struct Derived : Base0, Base1 {
"kind": 6,
"storage": 0,
"declarations": [],
"spell": "8:3-8:4|10963370434658308541|2|5186|-1",
"spell": "8:3-8:11|10963370434658308541|2|5186|-1",
"extent": "8:3-8:26|10963370434658308541|2|0|-1",
"bases": [],
"derived": [],
Expand All @@ -51,7 +51,7 @@ struct Derived : Base0, Base1 {
"kind": 6,
"storage": 0,
"declarations": [],
"spell": "2:11-2:12|11628904180681204356|2|1090|-1",
"spell": "2:11-2:17|11628904180681204356|2|1090|-1",
"extent": "2:3-2:23|11628904180681204356|2|0|-1",
"bases": [],
"derived": [],
Expand Down
42 changes: 39 additions & 3 deletions src/indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,21 @@ class IndexDataConsumer : public index::IndexDataConsumer {
IndexParam::DeclInfo *info;
Usr usr = GetUsr(D, &info);

if (is_def)
switch (OrigD->getKind()) {
case Decl::CXXConversion: // *operator* int => *operator int*
case Decl::CXXDestructor: // *~*A => *~A*
if (Loc.isFileID()) {
SourceRange R =
cast<FunctionDecl>(OrigD)->getNameInfo().getSourceRange();
if (R.getEnd().isFileID())
loc = FromTokenRange(SM, Lang, R);
}
break;
default:
break;
}

auto do_def_decl = [&](auto *entity) {
if (is_def) {
entity->def.spell = GetUse(db, lid, loc, SemDC, role);
Expand Down Expand Up @@ -704,8 +719,10 @@ class IndexDataConsumer : public index::IndexDataConsumer {
return true;
case SymbolKind::Func:
func = &db->ToFunc(usr);
// Span one more column to the left/right if D is CXXConstructor.
if (!is_def && !is_decl && D->getKind() == Decl::CXXConstructor)
// Mark as Role::Implicit to span one more column to the left/right.
if (!is_def && !is_decl &&
(D->getKind() == Decl::CXXConstructor ||
D->getKind() == Decl::CXXConversion))
role = Role(role | Role::Implicit);
do_def_decl(func);
if (Spell != Loc)
Expand All @@ -728,7 +745,7 @@ class IndexDataConsumer : public index::IndexDataConsumer {
do_def_decl(type);
if (Spell != Loc)
AddMacroUse(db, SM, usr, SymbolKind::Type, Spell);
if (type->def.detailed_name[0] == '\0')
if (type->def.detailed_name[0] == '\0' && info->short_name.size())
SetName(OrigD, info->short_name, info->qualified, type->def);
if (is_def || is_decl) {
const Decl *DC = cast<Decl>(SemDC);
Expand Down Expand Up @@ -885,6 +902,25 @@ class IndexDataConsumer : public index::IndexDataConsumer {
// spec has no Union, use Class
type->def.kind = RD->getTagKind() == TTK_Struct ? lsSymbolKind::Struct
: lsSymbolKind::Class;
if (type->def.detailed_name[0] == '\0' && info->short_name.empty()) {
if (TypedefNameDecl *TD = RD->getTypedefNameForAnonDecl()) {
StringRef Name = TD->getName();
StringRef Tag;
switch (RD->getTagKind()) {
case TTK_Struct: Tag = "struct "; break;
case TTK_Interface: Tag = "__interface "; break;
case TTK_Union: Tag = "union "; break;
case TTK_Class: Tag = "class "; break;
case TTK_Enum: Tag = "enum "; break;
}
std::string name = ("anon " + Tag + Name).str();
type->def.detailed_name = Intern(name);
type->def.short_name_size = name.size();
} else {
// e.g. "struct {}"
SetName(OrigD, "", "", type->def);
}
}
if (is_def) {
SmallVector<std::pair<const RecordDecl *, int>, 2> Stack{{RD, 0}};
llvm::DenseSet<const RecordDecl *> Seen;
Expand Down

0 comments on commit c202dd3

Please sign in to comment.