11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/Basic/LLVM.h" 14 #include "clang/Basic/LangOptions.h" 15 #include "clang/Basic/SourceLocation.h" 16 #include "clang/Basic/SourceManager.h" 17 #include "clang/Lex/Lexer.h" 18 #include "llvm/ADT/SmallVector.h" 19 #include "llvm/ADT/StringRef.h" 20 #include "llvm/ADT/StringSwitch.h" 21 #include "llvm/Support/Casting.h" 48 static const TypeMatcher
AnyType = anything();
51 expr(ignoringParenImpCasts(
52 declRefExpr(to(varDecl(hasType(isInteger())).bind(ConditionVarName)))));
55 varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral(equals(0)))))
59 declRefExpr(to(varDecl(hasType(isInteger())).bind(IncrementVarName)));
80 StatementMatcher ArrayBoundMatcher =
81 expr(hasType(isInteger())).bind(ConditionBoundName);
84 unless(isInTemplateInstantiation()),
85 hasLoopInit(declStmt(hasSingleDecl(InitToZeroMatcher))),
87 binaryOperator(hasOperatorName(
"<"),
88 hasLHS(IntegerComparisonMatcher),
89 hasRHS(ArrayBoundMatcher)),
90 binaryOperator(hasOperatorName(
">"), hasLHS(ArrayBoundMatcher),
91 hasRHS(IntegerComparisonMatcher)))),
92 hasIncrement(unaryOperator(hasOperatorName(
"++"),
93 hasUnaryOperand(IncrementVarMatcher))))
125 StatementMatcher BeginCallMatcher =
128 callee(cxxMethodDecl(anyOf(hasName(
"begin"), hasName(
"cbegin")))))
129 .bind(BeginCallName);
131 DeclarationMatcher InitDeclMatcher =
132 varDecl(hasInitializer(anyOf(ignoringParenImpCasts(BeginCallMatcher),
133 materializeTemporaryExpr(
134 ignoringParenImpCasts(BeginCallMatcher)),
135 hasDescendant(BeginCallMatcher))))
138 DeclarationMatcher EndDeclMatcher =
139 varDecl(hasInitializer(anything())).bind(EndVarName);
141 StatementMatcher EndCallMatcher = cxxMemberCallExpr(
143 callee(cxxMethodDecl(anyOf(hasName(
"end"), hasName(
"cend")))));
145 StatementMatcher IteratorBoundMatcher =
146 expr(anyOf(ignoringParenImpCasts(
147 declRefExpr(to(varDecl().bind(ConditionEndVarName)))),
148 ignoringParenImpCasts(expr(EndCallMatcher).bind(EndCallName)),
149 materializeTemporaryExpr(ignoringParenImpCasts(
150 expr(EndCallMatcher).bind(EndCallName)))));
152 StatementMatcher IteratorComparisonMatcher = expr(
153 ignoringParenImpCasts(declRefExpr(to(varDecl().bind(ConditionVarName)))));
155 auto OverloadedNEQMatcher = ignoringImplicit(
156 cxxOperatorCallExpr(hasOverloadedOperatorName(
"!="), argumentCountIs(2),
157 hasArgument(0, IteratorComparisonMatcher),
158 hasArgument(1, IteratorBoundMatcher)));
163 internal::Matcher<VarDecl> TestDerefReturnsByValue =
164 hasType(hasUnqualifiedDesugaredType(
165 recordType(hasDeclaration(cxxRecordDecl(hasMethod(allOf(
166 hasOverloadedOperatorName(
"*"),
169 returns(qualType(unless(hasCanonicalType(referenceType())))
170 .bind(DerefByValueResultName)),
174 qualType(unless(hasCanonicalType(rValueReferenceType())))
175 .bind(DerefByRefResultName))))))))));
178 unless(isInTemplateInstantiation()),
179 hasLoopInit(anyOf(declStmt(declCountIs(2),
180 containsDeclaration(0, InitDeclMatcher),
181 containsDeclaration(1, EndDeclMatcher)),
182 declStmt(hasSingleDecl(InitDeclMatcher)))),
184 anyOf(binaryOperator(hasOperatorName(
"!="),
185 hasLHS(IteratorComparisonMatcher),
186 hasRHS(IteratorBoundMatcher)),
187 binaryOperator(hasOperatorName(
"!="),
188 hasLHS(IteratorBoundMatcher),
189 hasRHS(IteratorComparisonMatcher)),
190 OverloadedNEQMatcher)),
192 unaryOperator(hasOperatorName(
"++"),
193 hasUnaryOperand(declRefExpr(
194 to(varDecl(hasType(pointsTo(AnyType)))
195 .bind(IncrementVarName))))),
197 hasOverloadedOperatorName(
"++"),
199 0, declRefExpr(to(varDecl(TestDerefReturnsByValue)
200 .bind(IncrementVarName))))))))
201 .bind(LoopNameIterator);
245 TypeMatcher RecordWithBeginEnd = qualType(anyOf(
248 hasUnqualifiedDesugaredType(recordType(hasDeclaration(cxxRecordDecl(
249 hasMethod(cxxMethodDecl(hasName(
"begin"), isConst())),
250 hasMethod(cxxMethodDecl(hasName(
"end"),
253 qualType(unless(isConstQualified()),
254 hasUnqualifiedDesugaredType(recordType(hasDeclaration(
255 cxxRecordDecl(hasMethod(hasName(
"begin")),
256 hasMethod(hasName(
"end")))))))
259 StatementMatcher SizeCallMatcher = cxxMemberCallExpr(
261 callee(cxxMethodDecl(anyOf(hasName(
"size"), hasName(
"length")))),
262 on(anyOf(hasType(pointsTo(RecordWithBeginEnd)),
263 hasType(RecordWithBeginEnd))));
265 StatementMatcher EndInitMatcher =
266 expr(anyOf(ignoringParenImpCasts(expr(SizeCallMatcher).bind(EndCallName)),
267 explicitCastExpr(hasSourceExpression(ignoringParenImpCasts(
268 expr(SizeCallMatcher).bind(EndCallName))))));
270 DeclarationMatcher EndDeclMatcher =
271 varDecl(hasInitializer(EndInitMatcher)).bind(EndVarName);
273 StatementMatcher IndexBoundMatcher =
274 expr(anyOf(ignoringParenImpCasts(declRefExpr(to(
275 varDecl(hasType(isInteger())).bind(ConditionEndVarName)))),
279 unless(isInTemplateInstantiation()),
281 anyOf(declStmt(declCountIs(2),
282 containsDeclaration(0, InitToZeroMatcher),
283 containsDeclaration(1, EndDeclMatcher)),
284 declStmt(hasSingleDecl(InitToZeroMatcher)))),
286 binaryOperator(hasOperatorName(
"<"),
287 hasLHS(IntegerComparisonMatcher),
288 hasRHS(IndexBoundMatcher)),
289 binaryOperator(hasOperatorName(
">"), hasLHS(IndexBoundMatcher),
290 hasRHS(IntegerComparisonMatcher)))),
291 hasIncrement(unaryOperator(hasOperatorName(
"++"),
292 hasUnaryOperand(IncrementVarMatcher))))
293 .bind(LoopNamePseudoArray);
304 const auto *TheCall =
306 if (!TheCall || TheCall->getNumArgs() != 0)
309 const auto *Member = dyn_cast<MemberExpr>(TheCall->getCallee());
312 StringRef
Name = Member->getMemberDecl()->getName();
313 StringRef TargetName = IsBegin ?
"begin" :
"end";
314 StringRef ConstTargetName = IsBegin ?
"cbegin" :
"cend";
315 if (Name != TargetName && Name != ConstTargetName)
318 const Expr *SourceExpr = Member->getBase();
322 *IsArrow = Member->isArrow();
331 static const Expr *
findContainer(ASTContext *Context,
const Expr *BeginExpr,
333 bool *ContainerNeedsDereference) {
336 bool BeginIsArrow =
false;
337 bool EndIsArrow =
false;
338 const Expr *BeginContainerExpr =
340 if (!BeginContainerExpr)
343 const Expr *EndContainerExpr =
347 if (!EndContainerExpr || BeginIsArrow != EndIsArrow ||
348 !
areSameExpr(Context, EndContainerExpr, BeginContainerExpr))
351 *ContainerNeedsDereference = BeginIsArrow;
352 return BeginContainerExpr;
357 const LangOptions &LangOpts,
359 if (SourceMgr.getFileID(Range.getBegin()) !=
360 SourceMgr.getFileID(Range.getEnd())) {
364 return Lexer::getSourceText(CharSourceRange(Range,
true), SourceMgr,
372 return dyn_cast<VarDecl>(DRE->getDecl());
373 if (
const auto *Mem = dyn_cast<MemberExpr>(E->IgnoreParenImpCasts()))
374 return dyn_cast<FieldDecl>(Mem->getMemberDecl());
381 if (
const auto *Member = dyn_cast<MemberExpr>(E->IgnoreParenImpCasts()))
382 return isa<CXXThisExpr>(Member->getBase()->IgnoreParenImpCasts());
390 if (E->getType().isConstQualified())
392 auto Parents = Context->getParents(*E);
393 if (Parents.size() != 1)
395 if (
const auto *Cast = Parents[0].get<ImplicitCastExpr>()) {
396 if ((Cast->getCastKind() == CK_NoOp &&
397 Cast->getType() == E->getType().withConst()) ||
398 (Cast->getCastKind() == CK_LValueToRValue &&
399 !Cast->getType().isNull() && Cast->getType()->isFundamentalType()))
409 for (
const Usage &U : Usages) {
415 if (U.Kind != Usage::UK_CaptureByCopy && U.Kind != Usage::UK_CaptureByRef &&
425 for (
const auto &U : Usages) {
426 if (U.Expression && !U.Expression->isRValue())
435 QualType CType = VDec->getType();
437 if (!CType->isPointerType())
439 CType = CType->getPointeeType();
444 CType = CType.getNonReferenceType();
445 return CType.isConstQualified();
450 LoopConvertCheck::RangeDescriptor::RangeDescriptor()
451 : ContainerNeedsDereference(
false), DerefByConstRef(
false),
452 DerefByValue(
false) {}
456 MaxCopySize(std::stoull(Options.get(
"MaxCopySize",
"16"))),
457 MinConfidence(StringSwitch<
Confidence::Level>(
458 Options.get(
"MinConfidence",
"reasonable"))
463 Options.get(
"NamingStyle",
"CamelCase"))
470 Options.
store(Opts,
"MaxCopySize", std::to_string(MaxCopySize));
471 SmallVector<std::string, 3> Confs{
"risky",
"reasonable",
"safe"};
472 Options.
store(Opts,
"MinConfidence", Confs[static_cast<int>(MinConfidence)]);
474 SmallVector<std::string, 4> Styles{
"camelBack",
"CamelCase",
"lower_case",
476 Options.
store(Opts,
"NamingStyle", Styles[static_cast<int>(NamingStyle)]);
504 void LoopConvertCheck::getAliasRange(SourceManager &SM, SourceRange &
Range) {
505 bool Invalid =
false;
506 const char *TextAfter =
507 SM.getCharacterData(Range.getEnd().getLocWithOffset(1), &Invalid);
510 unsigned Offset = std::strspn(TextAfter,
" \t\r\n");
512 SourceRange(Range.getBegin(), Range.getEnd().getLocWithOffset(Offset));
517 void LoopConvertCheck::doConversion(
518 ASTContext *Context,
const VarDecl *IndexVar,
519 const ValueDecl *MaybeContainer,
const UsageResult &Usages,
520 const DeclStmt *AliasDecl,
bool AliasUseRequired,
bool AliasFromForInit,
521 const ForStmt *Loop, RangeDescriptor Descriptor) {
522 auto Diag =
diag(Loop->getForLoc(),
"use range-based for loop instead");
525 bool VarNameFromAlias = (Usages.size() == 1) && AliasDecl;
526 bool AliasVarIsRef =
false;
529 if (VarNameFromAlias) {
530 const auto *AliasVar = cast<VarDecl>(AliasDecl->getSingleDecl());
531 VarName = AliasVar->getName().str();
534 QualType AliasVarType = AliasVar->getType();
535 assert(!AliasVarType.isNull() &&
"Type in VarDecl is null");
536 if (AliasVarType->isReferenceType()) {
537 AliasVarType = AliasVarType.getNonReferenceType();
538 AliasVarIsRef =
true;
540 if (Descriptor.ElemType.isNull() ||
541 !Context->hasSameUnqualifiedType(AliasVarType, Descriptor.ElemType))
542 Descriptor.ElemType = AliasVarType;
545 SourceRange ReplaceRange = AliasDecl->getSourceRange();
547 std::string ReplacementText;
548 if (AliasUseRequired) {
549 ReplacementText = VarName;
550 }
else if (AliasFromForInit) {
554 ReplacementText =
";";
557 getAliasRange(Context->getSourceManager(), ReplaceRange);
560 Diag << FixItHint::CreateReplacement(
561 CharSourceRange::getTokenRange(ReplaceRange), ReplacementText);
566 &TUInfo->getParentFinder().getStmtToParentStmtMap(),
567 Loop, IndexVar, MaybeContainer, Context, NamingStyle);
571 for (
const auto &
Usage : Usages) {
572 std::string ReplaceText;
580 if (Parents.size() == 1) {
581 if (
const auto *Paren = Parents[0].get<ParenExpr>()) {
585 Range = Paren->getSourceRange();
586 }
else if (
const auto *UOP = Parents[0].get<UnaryOperator>()) {
594 if (UOP->getOpcode() == UO_AddrOf)
605 TUInfo->getReplacedVars().insert(std::make_pair(Loop, IndexVar));
606 Diag << FixItHint::CreateReplacement(
607 CharSourceRange::getTokenRange(Range), ReplaceText);
612 SourceRange ParenRange(Loop->getLParenLoc(), Loop->getRParenLoc());
614 QualType Type = Context->getAutoDeductType();
615 if (!Descriptor.ElemType.isNull() && Descriptor.ElemType->isFundamentalType())
616 Type = Descriptor.ElemType.getUnqualifiedType();
622 !Descriptor.ElemType.isNull() &&
623 Descriptor.ElemType.isTriviallyCopyableType(*Context) &&
625 Context->getTypeInfo(Descriptor.ElemType).Width <= 8 * MaxCopySize;
626 bool UseCopy = CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
627 (Descriptor.DerefByConstRef && IsCheapToCopy));
630 if (Descriptor.DerefByConstRef) {
631 Type = Context->getLValueReferenceType(Context->getConstType(Type));
632 }
else if (Descriptor.DerefByValue) {
634 Type = Context->getRValueReferenceType(Type);
636 Type = Context->getLValueReferenceType(Type);
640 StringRef MaybeDereference = Descriptor.ContainerNeedsDereference ?
"*" :
"";
641 std::string TypeString = Type.getAsString(
getLangOpts());
642 std::string Range = (
"(" + TypeString +
" " + VarName +
" : " +
643 MaybeDereference + Descriptor.ContainerString +
")")
645 Diag << FixItHint::CreateReplacement(
646 CharSourceRange::getTokenRange(ParenRange), Range);
647 TUInfo->getGeneratedDecls().insert(make_pair(Loop, VarName));
651 StringRef LoopConvertCheck::getContainerString(ASTContext *Context,
653 const Expr *ContainerExpr) {
654 StringRef ContainerString;
655 if (isa<CXXThisExpr>(ContainerExpr->IgnoreParenImpCasts())) {
656 ContainerString =
"this";
660 ContainerExpr->getSourceRange());
663 return ContainerString;
668 void LoopConvertCheck::getArrayLoopQualifiers(ASTContext *Context,
669 const BoundNodes &Nodes,
670 const Expr *ContainerExpr,
672 RangeDescriptor &Descriptor) {
677 Descriptor.DerefByConstRef =
true;
683 Descriptor.DerefByValue =
true;
687 for (
const Usage &U : Usages) {
688 if (!U.Expression || U.Expression->getType().isNull())
690 QualType Type = U.Expression->getType().getCanonicalType();
692 if (!Type->isPointerType()) {
695 Type = Type->getPointeeType();
697 Descriptor.ElemType = Type;
703 void LoopConvertCheck::getIteratorLoopQualifiers(ASTContext *Context,
704 const BoundNodes &Nodes,
705 RangeDescriptor &Descriptor) {
708 const auto *InitVar = Nodes.getNodeAs<VarDecl>(
InitVarName);
709 QualType CanonicalInitVarType = InitVar->getType().getCanonicalType();
710 const auto *DerefByValueType =
712 Descriptor.DerefByValue = DerefByValueType;
714 if (Descriptor.DerefByValue) {
717 Descriptor.DerefByConstRef = CanonicalInitVarType.isConstQualified();
718 Descriptor.ElemType = *DerefByValueType;
720 if (
const auto *DerefType =
721 Nodes.getNodeAs<QualType>(DerefByRefResultName)) {
725 auto ValueType = DerefType->getNonReferenceType();
727 Descriptor.DerefByConstRef = ValueType.isConstQualified();
728 Descriptor.ElemType = ValueType;
732 assert(isa<PointerType>(CanonicalInitVarType) &&
733 "Non-class iterator type is not a pointer type");
736 Descriptor.DerefByConstRef =
737 CanonicalInitVarType->getPointeeType().isConstQualified();
738 Descriptor.ElemType = CanonicalInitVarType->getPointeeType();
744 void LoopConvertCheck::determineRangeDescriptor(
745 ASTContext *Context,
const BoundNodes &Nodes,
const ForStmt *Loop,
747 const UsageResult &Usages, RangeDescriptor &Descriptor) {
748 Descriptor.ContainerString = getContainerString(Context, Loop, ContainerExpr);
751 getIteratorLoopQualifiers(Context, Nodes, Descriptor);
753 getArrayLoopQualifiers(Context, Nodes, ContainerExpr, Usages, Descriptor);
758 bool LoopConvertCheck::isConvertible(ASTContext *Context,
759 const ast_matchers::BoundNodes &Nodes,
764 if (TUInfo->getReplacedVars().count(Loop))
770 const auto *InitVar = Nodes.getNodeAs<VarDecl>(
InitVarName);
773 const auto *EndVar = Nodes.getNodeAs<VarDecl>(
EndVarName);
780 QualType InitVarType = InitVar->getType();
781 QualType CanonicalInitVarType = InitVarType.getCanonicalType();
783 const auto *BeginCall = Nodes.getNodeAs<CXXMemberCallExpr>(
BeginCallName);
784 assert(BeginCall &&
"Bad Callback. No begin call expression");
785 QualType CanonicalBeginType =
786 BeginCall->getMethodDecl()->getReturnType().getCanonicalType();
787 if (CanonicalBeginType->isPointerType() &&
788 CanonicalInitVarType->isPointerType()) {
791 if (!Context->hasSameUnqualifiedType(
792 CanonicalBeginType->getPointeeType(),
793 CanonicalInitVarType->getPointeeType()))
795 }
else if (!Context->hasSameType(CanonicalInitVarType,
796 CanonicalBeginType)) {
803 const auto *EndCall = Nodes.getNodeAs<CXXMemberCallExpr>(
EndCallName);
804 if (!EndCall || !dyn_cast<MemberExpr>(EndCall->getCallee()))
811 const BoundNodes &Nodes = Result.Nodes;
813 ASTContext *Context = Result.Context;
817 RangeDescriptor Descriptor;
819 if ((Loop = Nodes.getNodeAs<ForStmt>(LoopNameArray))) {
821 }
else if ((Loop = Nodes.getNodeAs<ForStmt>(LoopNameIterator))) {
825 assert(Loop &&
"Bad Callback. No for statement");
829 if (!isConvertible(Context, Nodes, Loop, FixerKind))
833 const auto *EndVar = Nodes.getNodeAs<VarDecl>(
EndVarName);
842 const auto *EndCall = Nodes.getNodeAs<CXXMemberCallExpr>(
EndCallName);
849 const Expr *ContainerExpr =
nullptr;
852 EndVar ? EndVar->getInit() : EndCall,
853 &Descriptor.ContainerNeedsDereference);
855 ContainerExpr = EndCall->getImplicitObjectArgument();
856 Descriptor.ContainerNeedsDereference =
857 dyn_cast<MemberExpr>(EndCall->getCallee())->isArrow();
861 if (!ContainerExpr && !BoundExpr)
866 Descriptor.ContainerNeedsDereference);
895 determineRangeDescriptor(Context, Nodes, Loop, FixerKind, ContainerExpr,
902 TUInfo->getParentFinder().gatherAncestors(Context->getTranslationUnitDecl());
904 &TUInfo->getParentFinder().getStmtToParentStmtMap(),
905 &TUInfo->getParentFinder().getDeclToParentStmtMap(),
906 &TUInfo->getReplacedVars(), Loop);
908 if (DependencyFinder.dependsOnInsideVariable(ContainerExpr) ||
909 Descriptor.ContainerString.empty() || Usages.empty() ||
910 ConfidenceLevel.
getLevel() < MinConfidence)
static const char DerefByRefResultName[]
Confidence::Level getConfidenceLevel() const
Accessor for ConfidenceLevel.
Discover usages of expressions consisting of index or iterator access.
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.
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
LangOptions getLangOpts() const
Returns the language options from the context.
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.
static const StatementMatcher IntegerComparisonMatcher
static const DeclarationMatcher InitToZeroMatcher
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.
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.
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[]
static const StatementMatcher IncrementVarMatcher
Create names for generated variables within a particular statement.
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 ...
std::map< std::string, std::string > OptionMap
static const char ConditionEndVarName[]
static const char LoopNameArray[]
static StringRef getStringFromRange(SourceManager &SourceMgr, const LangOptions &LangOpts, SourceRange Range)
Obtain the original source code text from a SourceRange.
static const char DerefByValueResultName[]
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.
static const TypeMatcher AnyType
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.