[PATCH] D128892: [clangd] Also mark output arguments of array subscript expressions
Christian Kandeler via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 30 01:41:33 PDT 2022
ckandeler created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
ckandeler requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
... with the "usedAsMutableReference" semantic token modifier.
It's quite unusual to declare the index parameter of a subscript
operator as a non-const reference type, but arguably that makes it even
more helpful to be aware of it when working with such code.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D128892
Files:
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -742,6 +742,8 @@
void operator()(int);
void operator()(int, int &);
void operator()(int, int, const int &);
+ int &operator[](int &);
+ int operator[](int) const;
};
void $Function_decl[[fun]](int, const int,
int*, const int*,
@@ -768,9 +770,12 @@
[](int&){}($LocalVariable_usedAsMutableReference[[val]]);
[](const int&){}($LocalVariable[[val]]);
$Class[[ClassWithOp]] $LocalVariable_decl[[c]];
+ const $Class[[ClassWithOp]] $LocalVariable_decl_readonly[[c2]];
$LocalVariable[[c]]($LocalVariable[[val]]);
$LocalVariable[[c]](0, $LocalVariable_usedAsMutableReference[[val]]);
$LocalVariable[[c]](0, 0, $LocalVariable[[val]]);
+ $LocalVariable[[c]][$LocalVariable_usedAsMutableReference[[val]]];
+ $LocalVariable_readonly[[c2]][$LocalVariable[[val]]];
}
struct $Class_decl[[S]] {
$Class_decl[[S]](int&) {
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -543,9 +543,14 @@
// operators as well
llvm::ArrayRef<const Expr *> Args = {E->getArgs(), E->getNumArgs()};
if (const auto callOp = dyn_cast<CXXOperatorCallExpr>(E)) {
- if (callOp->getOperator() != OO_Call)
+ switch (callOp->getOperator()) {
+ case OO_Call:
+ case OO_Subscript:
+ Args = Args.drop_front(); // Drop object parameter
+ break;
+ default:
return true;
- Args = Args.drop_front(); // Drop object parameter
+ }
}
highlightMutableReferenceArguments(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128892.441307.patch
Type: text/x-patch
Size: 2103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220630/f1459de0/attachment.bin>
More information about the cfe-commits
mailing list