[PATCH] D128329: [clangd] Also mark output arguments of operator call expressions

Christian Kandeler via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 28 09:09:08 PDT 2022


ckandeler updated this revision to Diff 440650.
ckandeler marked 2 inline comments as done.
ckandeler added a comment.

Improvements as per review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128329/new/

https://reviews.llvm.org/D128329

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
@@ -738,6 +738,11 @@
       )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 @@
                            $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&) {
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -537,13 +537,17 @@
     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;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128329.440650.patch
Type: text/x-patch
Size: 2480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220628/acc861e0/attachment.bin>


More information about the cfe-commits mailing list