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()) {
+ bool IsRef = T->isLValueReferenceType();
+ bool IsPtr = T->isPointerType();
+ if ((!IsRef && !IsPtr) || T->getPointeeType().isConstQualified() ||
+ T->isDependentType()) {
return;
}
llvm::Optional<SourceLocation> Location;
- // FIXME Add "unwrapping" for ArraySubscriptExpr and UnaryOperator,
+ // FIXME Add "unwrapping" for ArraySubscriptExpr,
// 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))
if (Location)
H.addExtraModifier(*Location,
- HighlightingModifier::UsedAsMutableReference);
+ IsRef ? HighlightingModifier::UsedAsMutableReference
+ : HighlightingModifier::UsedAsMutablePointer);
}
void
return "defaultLibrary";
case HighlightingModifier::UsedAsMutableReference:
return "usedAsMutableReference"; // nonstandard
+ case HighlightingModifier::UsedAsMutablePointer:
+ return "usedAsMutablePointer"; // nonstandard
case HighlightingModifier::ConstructorOrDestructor:
return "constructorOrDestructor"; // nonstandard
case HighlightingModifier::FunctionScope:
# CHECK-NEXT: "dependentName",
# CHECK-NEXT: "defaultLibrary",
# CHECK-NEXT: "usedAsMutableReference",
+# CHECK-NEXT: "usedAsMutablePointer",
# CHECK-NEXT: "constructorOrDestructor",
# CHECK-NEXT: "functionScope",
# CHECK-NEXT: "classScope",
void $Function_def[[foo]]() {
$Class[[F]] $LocalVariable_def[[FF]];
$Class[[G]]<$Class[[F]], &$Class[[F]]::$Method[[f]]> $LocalVariable_def[[GG]];
- $LocalVariable[[GG]].$Method[[foo]](&$LocalVariable[[FF]]);
+ $LocalVariable[[GG]].$Method[[foo]](&$LocalVariable_usedAsMutablePointer[[FF]]);
$Class[[A]]<$Function[[foo]]> $LocalVariable_def[[AA]];
}
)cpp",
const int* $LocalVariable_def_readonly[[constPtr]];
int** $LocalVariable_def[[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]]);