[PATCH] D116536: [clangd] Fix selection on multi-dimensional array. (alternate version)
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 3 06:08:39 PST 2022
sammccall created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
based on D116218 <https://reviews.llvm.org/D116218>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D116536
Files:
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -318,6 +318,13 @@
{"[[st^ruct {int x;}]] y;", "CXXRecordDecl"},
{"[[struct {int x;} ^y]];", "VarDecl"},
{"struct {[[int ^x]];} y;", "FieldDecl"},
+
+ // Tricky case: nested ConstantArrayTypeLocs have the same token range.
+ {"const int x = 1, y = 2; int array[^[[x]]][10][y];", "DeclRefExpr"},
+ {"const int x = 1, y = 2; int array[x][10][^[[y]]];", "DeclRefExpr"},
+ {"const int x = 1, y = 2; int array[x][^[[10]]][y];", "IntegerLiteral"},
+ {"const int x = 1, y = 2; [[i^nt]] array[x][10][y];", "BuiltinTypeLoc"},
+
// FIXME: the AST has no location info for qualifiers.
{"const [[a^uto]] x = 42;", "AutoTypeLoc"},
{"[[co^nst auto x = 42]];", "VarDecl"},
Index: clang-tools-extra/clangd/Selection.cpp
===================================================================
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -76,6 +76,10 @@
? getSourceRange(DynTypedNode::create(*ME->getBase()))
: SourceRange();
}
+ if (const auto *TL = N.get<TypeLoc>()) {
+ if (const auto ATL = TL->getAs<ArrayTypeLoc>())
+ return ATL.getBracketsRange();
+ }
return N.getSourceRange();
}
@@ -510,6 +514,7 @@
bool TraverseTypeLoc(TypeLoc X) {
return traverseNode(&X, [&] { return Base::TraverseTypeLoc(X); });
}
+
bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &X) {
return traverseNode(&X,
[&] { return Base::TraverseTemplateArgumentLoc(X); });
@@ -661,6 +666,9 @@
// type's range.
if (auto AT = TL->getAs<AttributedTypeLoc>())
S = AT.getModifiedLoc().getSourceRange();
+
+ if (auto AT = TL->getAs<ArrayTypeLoc>())
+ S = AT.getSourceRange();
}
// SourceRange often doesn't manage to accurately cover attributes.
// Fortunately, attributes are rare.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116536.397051.patch
Type: text/x-patch
Size: 2146 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220103/99faf189/attachment.bin>
More information about the cfe-commits
mailing list