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.
Counterpart to "usedAsMutableReference". Just as for references, there are const and non-const pointer parameters, and it's valuable to be able to have different highlighting for the two cases at the call site. We could have re-used the existing modifier, but having a dedicated one maximizes client flexibility. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D130015 Files: clang-tools-extra/clangd/SemanticHighlighting.cpp clang-tools-extra/clangd/SemanticHighlighting.h clang-tools-extra/clangd/test/initialize-params.test clang-tools-extra/clangd/test/semantic-tokens.test 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 @@ -374,7 +374,7 @@ void $Function_decl[[foo]]() { $Class[[F]] $LocalVariable_decl[[FF]]; $Class[[G]]<$Class[[F]], &$Class[[F]]::$Method[[f]]> $LocalVariable_decl[[GG]]; - $LocalVariable[[GG]].$Method[[foo]](&$LocalVariable[[FF]]); + $LocalVariable[[GG]].$Method[[foo]](&$LocalVariable_usedAsMutablePointer[[FF]]); $Class[[A]]<$Function[[foo]]> $LocalVariable_decl[[AA]]; } )cpp", @@ -773,14 +773,14 @@ const int* $LocalVariable_decl_readonly[[constPtr]]; int** $LocalVariable_decl[[array]]; $Function[[fun]]($LocalVariable[[val]], $LocalVariable[[val]], - $LocalVariable[[ptr]], $LocalVariable_readonly[[constPtr]], + $LocalVariable_usedAsMutablePointer[[ptr]], $LocalVariable_readonly[[constPtr]], $LocalVariable_usedAsMutableReference[[val]], $LocalVariable[[val]], $LocalVariable_usedAsMutableReference[[ptr]], $LocalVariable_readonly_usedAsMutableReference[[constPtr]], $LocalVariable_readonly[[constPtr]], - $LocalVariable[[array]], $LocalVariable_usedAsMutableReference[[array]], + $LocalVariable_usedAsMutablePointer[[array]], $LocalVariable_usedAsMutableReference[[array]], $LocalVariable[[array]] ); [](int){}($LocalVariable[[val]]); Index: clang-tools-extra/clangd/test/semantic-tokens.test =================================================================== --- clang-tools-extra/clangd/test/semantic-tokens.test +++ clang-tools-extra/clangd/test/semantic-tokens.test @@ -23,7 +23,7 @@ # CHECK-NEXT: 4, # CHECK-NEXT: 1, # CHECK-NEXT: 0, -# CHECK-NEXT: 8193 +# CHECK-NEXT: 16385 # CHECK-NEXT: ], # CHECK-NEXT: "resultId": "1" # CHECK-NEXT: } @@ -49,7 +49,7 @@ # CHECK-NEXT: 4, # CHECK-NEXT: 1, # CHECK-NEXT: 0, -# CHECK-NEXT: 8193 +# CHECK-NEXT: 16385 # CHECK-NEXT: ], # Inserted at position 1 # CHECK-NEXT: "deleteCount": 0, @@ -72,12 +72,12 @@ # CHECK-NEXT: 4, # CHECK-NEXT: 1, # CHECK-NEXT: 0, -# CHECK-NEXT: 8193, +# CHECK-NEXT: 16385, # CHECK-NEXT: 1, # CHECK-NEXT: 4, # CHECK-NEXT: 1, # CHECK-NEXT: 0, -# CHECK-NEXT: 8193 +# CHECK-NEXT: 16385 # CHECK-NEXT: ], # CHECK-NEXT: "resultId": "3" # CHECK-NEXT: } Index: clang-tools-extra/clangd/test/initialize-params.test =================================================================== --- clang-tools-extra/clangd/test/initialize-params.test +++ clang-tools-extra/clangd/test/initialize-params.test @@ -66,6 +66,7 @@ # CHECK-NEXT: "dependentName", # CHECK-NEXT: "defaultLibrary", # CHECK-NEXT: "usedAsMutableReference", +# CHECK-NEXT: "usedAsMutablePointer", # CHECK-NEXT: "functionScope", # CHECK-NEXT: "classScope", # CHECK-NEXT: "fileScope", Index: clang-tools-extra/clangd/SemanticHighlighting.h =================================================================== --- clang-tools-extra/clangd/SemanticHighlighting.h +++ clang-tools-extra/clangd/SemanticHighlighting.h @@ -71,6 +71,7 @@ DependentName, DefaultLibrary, UsedAsMutableReference, + UsedAsMutablePointer, FunctionScope, ClassScope, Index: clang-tools-extra/clangd/SemanticHighlighting.cpp =================================================================== --- clang-tools-extra/clangd/SemanticHighlighting.cpp +++ clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -572,11 +572,13 @@ if (!Arg) return; - // Is this parameter passed by non-const reference? + // Is this parameter passed by non-const pointer or reference? // FIXME The condition T->idDependentType() could be relaxed a bit, // e.g. std::vector<T>& is dependent but we would want to highlight it - if (!T->isLValueReferenceType() || - T.getNonReferenceType().isConstQualified() || T->isDependentType()) { + const bool IsRef = T->isLValueReferenceType(); + const bool IsPtr = T->isPointerType(); + if ((!IsRef && !IsPtr) || T->getPointeeType().isConstQualified() || + T->isDependentType()) { return; } @@ -585,6 +587,12 @@ // FIXME Add "unwrapping" for ArraySubscriptExpr and UnaryOperator, // e.g. highlight `a` in `a[i]` // FIXME Handle dependent expression types + if (auto *IC = dyn_cast<ImplicitCastExpr>(Arg)) + Arg = IC->getSubExprAsWritten(); + if (auto *UO = dyn_cast<UnaryOperator>(Arg)) { + if (UO->getOpcode() == UO_AddrOf) + Arg = UO->getSubExpr(); + } if (auto *DR = dyn_cast<DeclRefExpr>(Arg)) Location = DR->getLocation(); else if (auto *M = dyn_cast<MemberExpr>(Arg)) @@ -592,7 +600,8 @@ if (Location) H.addExtraModifier(*Location, - HighlightingModifier::UsedAsMutableReference); + IsRef ? HighlightingModifier::UsedAsMutableReference + : HighlightingModifier::UsedAsMutablePointer); } void @@ -1075,6 +1084,8 @@ return "defaultLibrary"; case HighlightingModifier::UsedAsMutableReference: return "usedAsMutableReference"; // nonstandard + case HighlightingModifier::UsedAsMutablePointer: + return "usedAsMutablePointer"; // nonstandard case HighlightingModifier::FunctionScope: return "functionScope"; // nonstandard case HighlightingModifier::ClassScope:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits