10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 12 #include "clang/Basic/LLVM.h" 13 #include "clang/Basic/LangOptions.h" 14 #include "clang/Basic/SourceLocation.h" 15 #include "clang/Basic/SourceManager.h" 16 #include "clang/Lex/Lexer.h" 17 #include "llvm/ADT/SmallVector.h" 18 #include "llvm/ADT/StringRef.h" 19 #include "llvm/ADT/StringSwitch.h" 20 #include "llvm/Support/Casting.h" 47 static const TypeMatcher
AnyType() {
return anything(); }
50 return expr(ignoringParenImpCasts(
51 declRefExpr(to(varDecl(hasType(isInteger())).bind(ConditionVarName)))));
56 hasInitializer(ignoringParenImpCasts(integerLiteral(equals(0)))))
61 return declRefExpr(to(varDecl(hasType(isInteger())).bind(IncrementVarName)));
83 StatementMatcher ArrayBoundMatcher =
84 expr(hasType(isInteger())).bind(ConditionBoundName);
87 unless(isInTemplateInstantiation()),
90 binaryOperator(hasOperatorName(
"<"),
92 hasRHS(ArrayBoundMatcher)),
93 binaryOperator(hasOperatorName(
">"), hasLHS(ArrayBoundMatcher),
95 hasIncrement(unaryOperator(hasOperatorName(
"++"),
128 StatementMatcher BeginCallMatcher =
131 callee(cxxMethodDecl(anyOf(hasName(
"begin"), hasName(
"cbegin")))))
132 .bind(BeginCallName);
134 DeclarationMatcher InitDeclMatcher =
135 varDecl(hasInitializer(anyOf(ignoringParenImpCasts(BeginCallMatcher),
136 materializeTemporaryExpr(
137 ignoringParenImpCasts(BeginCallMatcher)),
138 hasDescendant(BeginCallMatcher))))
141 DeclarationMatcher EndDeclMatcher =
142 varDecl(hasInitializer(anything())).bind(EndVarName);
144 StatementMatcher EndCallMatcher = cxxMemberCallExpr(
146 callee(cxxMethodDecl(anyOf(hasName(
"end"), hasName(
"cend")))));
148 StatementMatcher IteratorBoundMatcher =
149 expr(anyOf(ignoringParenImpCasts(
150 declRefExpr(to(varDecl().bind(ConditionEndVarName)))),
151 ignoringParenImpCasts(expr(EndCallMatcher).bind(EndCallName)),
152 materializeTemporaryExpr(ignoringParenImpCasts(
153 expr(EndCallMatcher).bind(EndCallName)))));
155 StatementMatcher IteratorComparisonMatcher = expr(
156 ignoringParenImpCasts(declRefExpr(to(varDecl().bind(ConditionVarName)))));
158 auto OverloadedNEQMatcher = ignoringImplicit(
159 cxxOperatorCallExpr(hasOverloadedOperatorName(
"!="), argumentCountIs(2),
160 hasArgument(0, IteratorComparisonMatcher),
161 hasArgument(1, IteratorBoundMatcher)));
166 internal::Matcher<VarDecl> TestDerefReturnsByValue =
167 hasType(hasUnqualifiedDesugaredType(
168 recordType(hasDeclaration(cxxRecordDecl(hasMethod(cxxMethodDecl(
169 hasOverloadedOperatorName(
"*"),
172 returns(qualType(unless(hasCanonicalType(referenceType())))
173 .bind(DerefByValueResultName)),
177 qualType(unless(hasCanonicalType(rValueReferenceType())))
178 .bind(DerefByRefResultName))))))))));
181 unless(isInTemplateInstantiation()),
182 hasLoopInit(anyOf(declStmt(declCountIs(2),
183 containsDeclaration(0, InitDeclMatcher),
184 containsDeclaration(1, EndDeclMatcher)),
185 declStmt(hasSingleDecl(InitDeclMatcher)))),
187 anyOf(binaryOperator(hasOperatorName(
"!="),
188 hasLHS(IteratorComparisonMatcher),
189 hasRHS(IteratorBoundMatcher)),
190 binaryOperator(hasOperatorName(
"!="),
191 hasLHS(IteratorBoundMatcher),
192 hasRHS(IteratorComparisonMatcher)),
193 OverloadedNEQMatcher)),
195 unaryOperator(hasOperatorName(
"++"),
196 hasUnaryOperand(declRefExpr(
197 to(varDecl(hasType(pointsTo(
AnyType())))
198 .bind(IncrementVarName))))),
200 hasOverloadedOperatorName(
"++"),
202 0, declRefExpr(to(varDecl(TestDerefReturnsByValue)
203 .bind(IncrementVarName))))))))
204 .bind(LoopNameIterator);
248 TypeMatcher RecordWithBeginEnd = qualType(anyOf(
251 hasUnqualifiedDesugaredType(recordType(hasDeclaration(cxxRecordDecl(
252 hasMethod(cxxMethodDecl(hasName(
"begin"), isConst())),
253 hasMethod(cxxMethodDecl(hasName(
"end"),
256 qualType(unless(isConstQualified()),
257 hasUnqualifiedDesugaredType(recordType(hasDeclaration(
258 cxxRecordDecl(hasMethod(hasName(
"begin")),
259 hasMethod(hasName(
"end")))))))
262 StatementMatcher SizeCallMatcher = cxxMemberCallExpr(
264 callee(cxxMethodDecl(anyOf(hasName(
"size"), hasName(
"length")))),
265 on(anyOf(hasType(pointsTo(RecordWithBeginEnd)),
266 hasType(RecordWithBeginEnd))));
268 StatementMatcher EndInitMatcher =
269 expr(anyOf(ignoringParenImpCasts(expr(SizeCallMatcher).bind(EndCallName)),
270 explicitCastExpr(hasSourceExpression(ignoringParenImpCasts(
271 expr(SizeCallMatcher).bind(EndCallName))))));
273 DeclarationMatcher EndDeclMatcher =
274 varDecl(hasInitializer(EndInitMatcher)).bind(EndVarName);
276 StatementMatcher IndexBoundMatcher =
277 expr(anyOf(ignoringParenImpCasts(declRefExpr(to(
278 varDecl(hasType(isInteger())).bind(ConditionEndVarName)))),
282 unless(isInTemplateInstantiation()),
284 anyOf(declStmt(declCountIs(2),
286 containsDeclaration(1, EndDeclMatcher)),
289 binaryOperator(hasOperatorName(
"<"),
291 hasRHS(IndexBoundMatcher)),
292 binaryOperator(hasOperatorName(
">"), hasLHS(IndexBoundMatcher),
294 hasIncrement(unaryOperator(hasOperatorName(
"++"),
296 .bind(LoopNamePseudoArray);
307 const auto *TheCall =
309 if (!TheCall || TheCall->getNumArgs() != 0)
312 const auto *Member = dyn_cast<MemberExpr>(TheCall->getCallee());
315 StringRef
Name = Member->getMemberDecl()->getName();
316 StringRef TargetName = IsBegin ?
"begin" :
"end";
317 StringRef ConstTargetName = IsBegin ?
"cbegin" :
"cend";
318 if (Name != TargetName && Name != ConstTargetName)
321 const Expr *SourceExpr = Member->getBase();
325 *IsArrow = Member->isArrow();
334 static const Expr *
findContainer(ASTContext *Context,
const Expr *BeginExpr,
336 bool *ContainerNeedsDereference) {
339 bool BeginIsArrow =
false;
340 bool EndIsArrow =
false;
341 const Expr *BeginContainerExpr =
343 if (!BeginContainerExpr)
346 const Expr *EndContainerExpr =
350 if (!EndContainerExpr || BeginIsArrow != EndIsArrow ||
351 !
areSameExpr(Context, EndContainerExpr, BeginContainerExpr))
354 *ContainerNeedsDereference = BeginIsArrow;
355 return BeginContainerExpr;
360 const LangOptions &LangOpts,
362 if (SourceMgr.getFileID(Range.getBegin()) !=
363 SourceMgr.getFileID(Range.getEnd())) {
367 return Lexer::getSourceText(CharSourceRange(Range,
true), SourceMgr,
375 return dyn_cast<VarDecl>(DRE->getDecl());
376 if (
const auto *Mem = dyn_cast<MemberExpr>(E->IgnoreParenImpCasts()))
377 return dyn_cast<FieldDecl>(Mem->getMemberDecl());
384 if (
const auto *Member = dyn_cast<MemberExpr>(E->IgnoreParenImpCasts()))
385 return isa<CXXThisExpr>(Member->getBase()->IgnoreParenImpCasts());
393 if (E->getType().isConstQualified())
395 auto Parents = Context->getParents(*E);
396 if (Parents.size() != 1)
398 if (
const auto *Cast = Parents[0].get<ImplicitCastExpr>()) {
399 if ((Cast->getCastKind() == CK_NoOp &&
400 Cast->getType() == E->getType().withConst()) ||
401 (Cast->getCastKind() == CK_LValueToRValue &&
402 !Cast->getType().isNull() && Cast->getType()->isFundamentalType()))
412 for (
const Usage &U : Usages) {
418 if (U.Kind != Usage::UK_CaptureByCopy && U.Kind != Usage::UK_CaptureByRef &&
428 for (
const auto &U : Usages) {
429 if (U.Expression && !U.Expression->isRValue())
438 QualType CType = VDec->getType();
440 if (!CType->isPointerType())
442 CType = CType->getPointeeType();
447 CType = CType.getNonReferenceType();
448 return CType.isConstQualified();
453 LoopConvertCheck::RangeDescriptor::RangeDescriptor()
454 : ContainerNeedsDereference(
false), DerefByConstRef(
false),
455 DerefByValue(
false) {}
459 MaxCopySize(std::stoull(Options.get(
"MaxCopySize",
"16"))),
460 MinConfidence(StringSwitch<
Confidence::Level>(
461 Options.get(
"MinConfidence",
"reasonable"))
466 Options.get(
"NamingStyle",
"CamelCase"))
473 Options.
store(Opts,
"MaxCopySize", std::to_string(MaxCopySize));
474 SmallVector<std::string, 3> Confs{
"risky",
"reasonable",
"safe"};
475 Options.
store(Opts,
"MinConfidence", Confs[static_cast<int>(MinConfidence)]);
477 SmallVector<std::string, 4> Styles{
"camelBack",
"CamelCase",
"lower_case",
479 Options.
store(Opts,
"NamingStyle", Styles[static_cast<int>(NamingStyle)]);
507 void LoopConvertCheck::getAliasRange(SourceManager &SM, SourceRange &
Range) {
508 bool Invalid =
false;
509 const char *TextAfter =
510 SM.getCharacterData(Range.getEnd().getLocWithOffset(1), &Invalid);
513 unsigned Offset = std::strspn(TextAfter,
" \t\r\n");
515 SourceRange(Range.getBegin(), Range.getEnd().getLocWithOffset(Offset));
520 void LoopConvertCheck::doConversion(
521 ASTContext *Context,
const VarDecl *IndexVar,
522 const ValueDecl *MaybeContainer,
const UsageResult &Usages,
523 const DeclStmt *AliasDecl,
bool AliasUseRequired,
bool AliasFromForInit,
524 const ForStmt *Loop, RangeDescriptor Descriptor) {
525 auto Diag =
diag(Loop->getForLoc(),
"use range-based for loop instead");
528 bool VarNameFromAlias = (Usages.size() == 1) && AliasDecl;
529 bool AliasVarIsRef =
false;
532 if (VarNameFromAlias) {
533 const auto *AliasVar = cast<VarDecl>(AliasDecl->getSingleDecl());
534 VarName = AliasVar->getName().str();
537 QualType AliasVarType = AliasVar->getType();
538 assert(!AliasVarType.isNull() &&
"Type in VarDecl is null");
539 if (AliasVarType->isReferenceType()) {
540 AliasVarType = AliasVarType.getNonReferenceType();
541 AliasVarIsRef =
true;
543 if (Descriptor.ElemType.isNull() ||
544 !Context->hasSameUnqualifiedType(AliasVarType, Descriptor.ElemType))
545 Descriptor.ElemType = AliasVarType;
548 SourceRange ReplaceRange = AliasDecl->getSourceRange();
550 std::string ReplacementText;
551 if (AliasUseRequired) {
552 ReplacementText = VarName;
553 }
else if (AliasFromForInit) {
557 ReplacementText =
";";
560 getAliasRange(Context->getSourceManager(), ReplaceRange);
563 Diag << FixItHint::CreateReplacement(
569 &TUInfo->getParentFinder().getStmtToParentStmtMap(),
570 Loop, IndexVar, MaybeContainer, Context, NamingStyle);
574 for (
const auto &
Usage : Usages) {
575 std::string ReplaceText;
583 if (Parents.size() == 1) {
584 if (
const auto *Paren = Parents[0].get<ParenExpr>()) {
588 Range = Paren->getSourceRange();
589 }
else if (
const auto *UOP = Parents[0].get<UnaryOperator>()) {
597 if (UOP->getOpcode() == UO_AddrOf)
608 TUInfo->getReplacedVars().insert(std::make_pair(Loop, IndexVar));
609 Diag << FixItHint::CreateReplacement(
615 SourceRange ParenRange(Loop->getLParenLoc(), Loop->getRParenLoc());
617 QualType
Type = Context->getAutoDeductType();
618 if (!Descriptor.ElemType.isNull() && Descriptor.ElemType->isFundamentalType())
619 Type = Descriptor.ElemType.getUnqualifiedType();
625 !Descriptor.ElemType.isNull() &&
626 Descriptor.ElemType.isTriviallyCopyableType(*Context) &&
628 Context->getTypeInfo(Descriptor.ElemType).Width <= 8 * MaxCopySize;
629 bool UseCopy = CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
630 (Descriptor.DerefByConstRef && IsCheapToCopy));
633 if (Descriptor.DerefByConstRef) {
634 Type = Context->getLValueReferenceType(Context->getConstType(Type));
635 }
else if (Descriptor.DerefByValue) {
637 Type = Context->getRValueReferenceType(Type);
639 Type = Context->getLValueReferenceType(Type);
643 StringRef MaybeDereference = Descriptor.ContainerNeedsDereference ?
"*" :
"";
644 std::string TypeString = Type.getAsString(
getLangOpts());
645 std::string Range = (
"(" + TypeString +
" " + VarName +
" : " +
646 MaybeDereference + Descriptor.ContainerString +
")")
648 Diag << FixItHint::CreateReplacement(
650 TUInfo->getGeneratedDecls().insert(make_pair(Loop, VarName));
654 StringRef LoopConvertCheck::getContainerString(ASTContext *Context,
656 const Expr *ContainerExpr) {
657 StringRef ContainerString;
658 if (isa<CXXThisExpr>(ContainerExpr->IgnoreParenImpCasts())) {
659 ContainerString =
"this";
663 ContainerExpr->getSourceRange());
666 return ContainerString;
671 void LoopConvertCheck::getArrayLoopQualifiers(ASTContext *Context,
672 const BoundNodes &Nodes,
673 const Expr *ContainerExpr,
675 RangeDescriptor &Descriptor) {
680 Descriptor.DerefByConstRef =
true;
686 Descriptor.DerefByValue =
true;
690 for (
const Usage &U : Usages) {
691 if (!U.Expression || U.Expression->getType().isNull())
693 QualType
Type = U.Expression->getType().getCanonicalType();
695 if (!Type->isPointerType()) {
698 Type = Type->getPointeeType();
700 Descriptor.ElemType =
Type;
706 void LoopConvertCheck::getIteratorLoopQualifiers(ASTContext *Context,
707 const BoundNodes &Nodes,
708 RangeDescriptor &Descriptor) {
711 const auto *InitVar = Nodes.getNodeAs<VarDecl>(
InitVarName);
712 QualType CanonicalInitVarType = InitVar->getType().getCanonicalType();
713 const auto *DerefByValueType =
715 Descriptor.DerefByValue = DerefByValueType;
717 if (Descriptor.DerefByValue) {
720 Descriptor.DerefByConstRef = CanonicalInitVarType.isConstQualified();
721 Descriptor.ElemType = *DerefByValueType;
723 if (
const auto *DerefType =
724 Nodes.getNodeAs<QualType>(DerefByRefResultName)) {
728 auto ValueType = DerefType->getNonReferenceType();
730 Descriptor.DerefByConstRef = ValueType.isConstQualified();
731 Descriptor.ElemType = ValueType;
735 assert(isa<PointerType>(CanonicalInitVarType) &&
736 "Non-class iterator type is not a pointer type");
739 Descriptor.DerefByConstRef =
740 CanonicalInitVarType->getPointeeType().isConstQualified();
741 Descriptor.ElemType = CanonicalInitVarType->getPointeeType();
747 void LoopConvertCheck::determineRangeDescriptor(
748 ASTContext *Context,
const BoundNodes &Nodes,
const ForStmt *Loop,
750 const UsageResult &Usages, RangeDescriptor &Descriptor) {
751 Descriptor.ContainerString = getContainerString(Context, Loop, ContainerExpr);
754 getIteratorLoopQualifiers(Context, Nodes, Descriptor);
756 getArrayLoopQualifiers(Context, Nodes, ContainerExpr, Usages, Descriptor);
761 bool LoopConvertCheck::isConvertible(ASTContext *Context,
762 const ast_matchers::BoundNodes &Nodes,
767 if (TUInfo->getReplacedVars().count(Loop))
773 const auto *InitVar = Nodes.getNodeAs<VarDecl>(
InitVarName);
776 const auto *EndVar = Nodes.getNodeAs<VarDecl>(
EndVarName);
783 QualType InitVarType = InitVar->getType();
784 QualType CanonicalInitVarType = InitVarType.getCanonicalType();
786 const auto *BeginCall = Nodes.getNodeAs<CXXMemberCallExpr>(
BeginCallName);
787 assert(BeginCall &&
"Bad Callback. No begin call expression");
788 QualType CanonicalBeginType =
789 BeginCall->getMethodDecl()->getReturnType().getCanonicalType();
790 if (CanonicalBeginType->isPointerType() &&
791 CanonicalInitVarType->isPointerType()) {
794 if (!Context->hasSameUnqualifiedType(
795 CanonicalBeginType->getPointeeType(),
796 CanonicalInitVarType->getPointeeType()))
801 const auto *EndCall = Nodes.getNodeAs<CXXMemberCallExpr>(
EndCallName);
802 if (!EndCall || !dyn_cast<MemberExpr>(EndCall->getCallee()))
809 const BoundNodes &Nodes = Result.Nodes;
811 ASTContext *Context = Result.Context;
815 RangeDescriptor Descriptor;
817 if ((Loop = Nodes.getNodeAs<ForStmt>(LoopNameArray))) {
819 }
else if ((Loop = Nodes.getNodeAs<ForStmt>(LoopNameIterator))) {
823 assert(Loop &&
"Bad Callback. No for statement");
827 if (!isConvertible(Context, Nodes, Loop, FixerKind))
831 const auto *EndVar = Nodes.getNodeAs<VarDecl>(
EndVarName);
840 const auto *EndCall = Nodes.getNodeAs<CXXMemberCallExpr>(
EndCallName);
847 const Expr *ContainerExpr =
nullptr;
850 EndVar ? EndVar->getInit() : EndCall,
851 &Descriptor.ContainerNeedsDereference);
853 ContainerExpr = EndCall->getImplicitObjectArgument();
854 Descriptor.ContainerNeedsDereference =
855 dyn_cast<MemberExpr>(EndCall->getCallee())->isArrow();
859 if (!ContainerExpr && !BoundExpr)
864 Descriptor.ContainerNeedsDereference);
893 determineRangeDescriptor(Context, Nodes, Loop, FixerKind, ContainerExpr,
900 TUInfo->getParentFinder().gatherAncestors(*Context);
902 &TUInfo->getParentFinder().getStmtToParentStmtMap(),
903 &TUInfo->getParentFinder().getDeclToParentStmtMap(),
904 &TUInfo->getReplacedVars(), Loop);
906 if (DependencyFinder.dependsOnInsideVariable(ContainerExpr) ||
907 Descriptor.ContainerString.empty() || Usages.empty() ||
908 ConfidenceLevel.
getLevel() < MinConfidence)
static const char DerefByRefResultName[]
static const DeclarationMatcher InitToZeroMatcher()
Confidence::Level getConfidenceLevel() const
Accessor for ConfidenceLevel.
Discover usages of expressions consisting of index or iterator access.
Some operations such as code completion produce a set of candidates.
StatementMatcher makeIteratorLoopMatcher()
The matcher used for iterator-based for loops.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
static const char ConditionVarName[]
static const Expr * getContainerFromBeginEndCall(const Expr *Init, bool IsBegin, bool *IsArrow)
Determine whether Init appears to be an initializing an iterator.
StatementMatcher makeArrayLoopMatcher()
The matcher for loops over arrays.
llvm::SmallVector< Usage, 8 > UsageResult
static const StatementMatcher IntegerComparisonMatcher()
static const char EndCallName[]
A class to encapsulate lowering of the tool's confidence level.
const Expr * getContainerIndexed() const
Get the container indexed by IndexVar, if any.
Class used to determine if an expression is dependent on a variable declared inside of the loop where...
Base class for all clang-tidy checks.
bool aliasUseRequired() const
Indicates if the alias declaration was in a place where it cannot simply be removed but rather replac...
const Expr * digThroughConstructors(const Expr *E)
Look through conversion/copy constructors to find the explicit initialization expression, returning it is found.
const LangOptions & getLangOpts() const
Returns the language options from the context.
static const Expr * findContainer(ASTContext *Context, const Expr *BeginExpr, const Expr *EndExpr, bool *ContainerNeedsDereference)
Determines the container whose begin() and end() functions are called for an iterator-based loop...
static const char InitVarName[]
static const ValueDecl * getReferencedVariable(const Expr *E)
If the given expression is actually a DeclRefExpr or a MemberExpr, find and return the underlying Val...
static const char EndVarName[]
bool aliasFromForInit() const
Indicates if the alias declaration came from the init clause of a nested for loop.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
static const TypeMatcher AnyType()
const DeclRefExpr * getDeclRef(const Expr *E)
Returns the DeclRefExpr represented by E, or NULL if there isn't one.
void findExprComponents(const clang::Expr *SourceExpr)
Find the components of an expression and place them in a ComponentVector.
std::string createIndexName()
Generate a new index name.
const ComponentVector & getComponents()
Accessor for Components.
Level getLevel() const
Return the internal confidence level.
bool areSameVariable(const ValueDecl *First, const ValueDecl *Second)
Returns true when two ValueDecls are the same variable.
static bool usagesReturnRValues(const UsageResult &Usages)
Returns true if the elements of the container are never accessed by reference.
static const char ConditionBoundName[]
Create names for generated variables within a particular statement.
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
static bool usagesAreConst(ASTContext *Context, const UsageResult &Usages)
Returns true when it can be guaranteed that the elements of the container are not being modified...
static const char IncrementVarName[]
bool areSameExpr(ASTContext *Context, const Expr *First, const Expr *Second)
Returns true when two Exprs are equivalent.
static bool canBeModified(ASTContext *Context, const Expr *E)
Given an expression that represents an usage of an element from the containter that we are iterating ...
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
static const char ConditionEndVarName[]
static const char LoopNameArray[]
llvm::Optional< Range > getTokenRange(const SourceManager &SM, const LangOptions &LangOpts, SourceLocation TokLoc)
Returns the taken range at TokLoc.
static StringRef getStringFromRange(SourceManager &SourceMgr, const LangOptions &LangOpts, SourceRange Range)
Obtain the original source code text from a SourceRange.
static const char DerefByValueResultName[]
static const StatementMatcher IncrementVarMatcher()
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
static bool isDirectMemberExpr(const Expr *E)
Returns true when the given expression is a member expression whose base is this (implicitly or not)...
static const char LoopNamePseudoArray[]
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
bool findAndVerifyUsages(const Stmt *Body)
Finds all uses of IndexVar in Body, placing all usages in Usages, and returns true if IndexVar was on...
The information needed to describe a valid convertible usage of an array index or iterator...
CharSourceRange Range
SourceRange for the file name.
void addComponents(const ComponentVector &Components)
Add a set of components that we should consider relevant to the container.
void lowerTo(Confidence::Level Level)
Lower the internal confidence level to Level, but do not raise it.
static const char BeginCallName[]
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
Class used to find the variables and member expressions on which an arbitrary expression depends...
static const char LoopNameIterator[]
static bool containerIsConst(const Expr *ContainerExpr, bool Dereference)
Returns true if the container is const-qualified.
StatementMatcher makePseudoArrayLoopMatcher()
The matcher used for array-like containers (pseudoarrays).
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
const UsageResult & getUsages() const
Accessor for Usages.
const DeclStmt * getAliasDecl() const
Returns the statement declaring the variable created as an alias for the loop element, if any.