forked from OSchip/llvm-project
[clangd] findExplicitReferences supports goto labels
Summary: This means they're renamable and textDocument/highlight works This fell out of D78454 Reviewers: adamcz Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D80170
This commit is contained in:
parent
1f820e3559
commit
b0d94964da
|
@ -643,7 +643,7 @@ llvm::SmallVector<ReferenceLoc, 2> refInDecl(const Decl *D) {
|
||||||
return V.Refs;
|
return V.Refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::SmallVector<ReferenceLoc, 2> refInExpr(const Expr *E) {
|
llvm::SmallVector<ReferenceLoc, 2> refInStmt(const Stmt *S) {
|
||||||
struct Visitor : ConstStmtVisitor<Visitor> {
|
struct Visitor : ConstStmtVisitor<Visitor> {
|
||||||
// FIXME: handle more complicated cases: more ObjC, designated initializers.
|
// FIXME: handle more complicated cases: more ObjC, designated initializers.
|
||||||
llvm::SmallVector<ReferenceLoc, 2> Refs;
|
llvm::SmallVector<ReferenceLoc, 2> Refs;
|
||||||
|
@ -722,10 +722,25 @@ llvm::SmallVector<ReferenceLoc, 2> refInExpr(const Expr *E) {
|
||||||
/*IsDecl=*/false, std::move(Targets)});
|
/*IsDecl=*/false, std::move(Targets)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VisitGotoStmt(const GotoStmt *GS) {
|
||||||
|
llvm::SmallVector<const NamedDecl *, 1> Targets;
|
||||||
|
if (const auto *L = GS->getLabel())
|
||||||
|
Targets.push_back(L);
|
||||||
|
Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(), GS->getLabelLoc(),
|
||||||
|
/*IsDecl=*/false, std::move(Targets)});
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisitLabelStmt(const LabelStmt *LS) {
|
||||||
|
Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
|
||||||
|
LS->getIdentLoc(),
|
||||||
|
/*IsDecl=*/true,
|
||||||
|
{LS->getDecl()}});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Visitor V;
|
Visitor V;
|
||||||
V.Visit(E);
|
V.Visit(S);
|
||||||
return V.Refs;
|
return V.Refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -837,8 +852,8 @@ public:
|
||||||
return RecursiveASTVisitor::TraverseElaboratedTypeLoc(L);
|
return RecursiveASTVisitor::TraverseElaboratedTypeLoc(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VisitExpr(Expr *E) {
|
bool VisitStmt(Stmt *S) {
|
||||||
visitNode(DynTypedNode::create(*E));
|
visitNode(DynTypedNode::create(*S));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -926,8 +941,8 @@ private:
|
||||||
llvm::SmallVector<ReferenceLoc, 2> explicitReference(DynTypedNode N) {
|
llvm::SmallVector<ReferenceLoc, 2> explicitReference(DynTypedNode N) {
|
||||||
if (auto *D = N.get<Decl>())
|
if (auto *D = N.get<Decl>())
|
||||||
return refInDecl(D);
|
return refInDecl(D);
|
||||||
if (auto *E = N.get<Expr>())
|
if (auto *S = N.get<Stmt>())
|
||||||
return refInExpr(E);
|
return refInStmt(S);
|
||||||
if (auto *NNSL = N.get<NestedNameSpecifierLoc>()) {
|
if (auto *NNSL = N.get<NestedNameSpecifierLoc>()) {
|
||||||
// (!) 'DeclRelation::Alias' ensures we do not loose namespace aliases.
|
// (!) 'DeclRelation::Alias' ensures we do not loose namespace aliases.
|
||||||
return {ReferenceLoc{
|
return {ReferenceLoc{
|
||||||
|
|
|
@ -786,6 +786,14 @@ TEST_F(FindExplicitReferencesTest, All) {
|
||||||
"6: targets = {a::b::S}\n"
|
"6: targets = {a::b::S}\n"
|
||||||
"7: targets = {a::b::S::type}, qualifier = 'struct S::'\n"
|
"7: targets = {a::b::S::type}, qualifier = 'struct S::'\n"
|
||||||
"8: targets = {y}, decl\n"},
|
"8: targets = {y}, decl\n"},
|
||||||
|
{R"cpp(
|
||||||
|
void foo() {
|
||||||
|
$0^ten: // PRINT "HELLO WORLD!"
|
||||||
|
goto $1^ten;
|
||||||
|
}
|
||||||
|
)cpp",
|
||||||
|
"0: targets = {ten}, decl\n"
|
||||||
|
"1: targets = {ten}\n"},
|
||||||
// Simple templates.
|
// Simple templates.
|
||||||
{R"cpp(
|
{R"cpp(
|
||||||
template <class T> struct vector { using value_type = T; };
|
template <class T> struct vector { using value_type = T; };
|
||||||
|
|
Loading…
Reference in New Issue