[clang-tools-extra] c09e533 - [clangd] Also mark output arguments of operator call expressions
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 29 17:18:03 PDT 2022
Author: Christian Kandeler
Date: 2022-06-29T20:12:37-04:00
New Revision: c09e533374139f17a040040ffdb03ea20fac2736
URL: https://github.com/llvm/llvm-project/commit/c09e533374139f17a040040ffdb03ea20fac2736
DIFF: https://github.com/llvm/llvm-project/commit/c09e533374139f17a040040ffdb03ea20fac2736.diff
LOG: [clangd] Also mark output arguments of operator call expressions
There's no reason that arguments to e.g. lambda calls should be treated
differently than those to "real" functions.
Reviewed By: nridge
Differential Revision: https://reviews.llvm.org/D128329
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 2ab7461eee9c6..aafff0ae285fc 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -539,13 +539,17 @@ class CollectExtraHighlightings
if (isa<UserDefinedLiteral>(E))
return true;
- // FIXME ...here it would make sense though.
- if (isa<CXXOperatorCallExpr>(E))
- return true;
+ // FIXME: consider highlighting parameters of some other overloaded
+ // 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)
+ return true;
+ Args = Args.drop_front(); // Drop object parameter
+ }
highlightMutableReferenceArguments(
- dyn_cast_or_null<FunctionDecl>(E->getCalleeDecl()),
- {E->getArgs(), E->getNumArgs()});
+ dyn_cast_or_null<FunctionDecl>(E->getCalleeDecl()), Args);
return true;
}
diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index b877da9755a3a..db183d648b5b5 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -738,6 +738,11 @@ sizeof...($TemplateParameter[[Elements]]);
)cpp",
// Modifier for variables passed as non-const references
R"cpp(
+ struct $Class_decl[[ClassWithOp]] {
+ void operator()(int);
+ void operator()(int, int &);
+ void operator()(int, int, const int &);
+ };
void $Function_decl[[fun]](int, const int,
int*, const int*,
int&, const int&,
@@ -759,6 +764,13 @@ sizeof...($TemplateParameter[[Elements]]);
$LocalVariable[[array]], $LocalVariable_usedAsMutableReference[[array]],
$LocalVariable[[array]]
);
+ [](int){}($LocalVariable[[val]]);
+ [](int&){}($LocalVariable_usedAsMutableReference[[val]]);
+ [](const int&){}($LocalVariable[[val]]);
+ $Class[[ClassWithOp]] $LocalVariable_decl[[c]];
+ $LocalVariable[[c]]($LocalVariable[[val]]);
+ $LocalVariable[[c]](0, $LocalVariable_usedAsMutableReference[[val]]);
+ $LocalVariable[[c]](0, 0, $LocalVariable[[val]]);
}
struct $Class_decl[[S]] {
$Class_decl[[S]](int&) {
More information about the cfe-commits
mailing list