Author: Christian Kandeler Date: 2022-07-01T04:45:20-04:00 New Revision: ac511fd4392d0f1fad3852378adf3c80738016b7
URL: https://github.com/llvm/llvm-project/commit/ac511fd4392d0f1fad3852378adf3c80738016b7 DIFF: https://github.com/llvm/llvm-project/commit/ac511fd4392d0f1fad3852378adf3c80738016b7.diff LOG: [clangd] Also mark output arguments of array subscript expressions ... 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. Reviewed By: nridge Differential Revision: https://reviews.llvm.org/D128892 Added: Modified: clang-tools-extra/clangd/SemanticHighlighting.cpp clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index aafff0ae285fc..5e0e3b2cc7dc8 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -543,9 +543,14 @@ class CollectExtraHighlightings // 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( diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp index db183d648b5b5..a40a0f92e4a6f 100644 --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -742,6 +742,8 @@ sizeof...($TemplateParameter[[Elements]]); 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 @@ sizeof...($TemplateParameter[[Elements]]); [](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&) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits