Mercurial > hg > CbC > CbC_llvm
comparison clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp @ 221:79ff65ed7e25
LLVM12 Original
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Jun 2021 19:15:29 +0900 |
parents | 1d019706d866 |
children | c4bab56944e8 |
comparison
equal
deleted
inserted
replaced
220:42394fc6a535 | 221:79ff65ed7e25 |
---|---|
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 void RedundantControlFlowCheck::registerMatchers(MatchFinder *Finder) { | 33 void RedundantControlFlowCheck::registerMatchers(MatchFinder *Finder) { |
34 Finder->addMatcher( | 34 Finder->addMatcher( |
35 functionDecl( | 35 functionDecl(isDefinition(), returns(voidType()), |
36 isDefinition(), returns(voidType()), | 36 hasBody(compoundStmt(hasAnySubstatement( |
37 has(compoundStmt(hasAnySubstatement(returnStmt(unless(has(expr()))))) | 37 returnStmt(unless(has(expr()))))) |
38 .bind("return"))), | 38 .bind("return"))), |
39 this); | 39 this); |
40 auto CompoundContinue = | |
41 has(compoundStmt(hasAnySubstatement(continueStmt())).bind("continue")); | |
42 Finder->addMatcher( | 40 Finder->addMatcher( |
43 stmt(anyOf(forStmt(), cxxForRangeStmt(), whileStmt(), doStmt()), | 41 mapAnyOf(forStmt, cxxForRangeStmt, whileStmt, doStmt) |
44 CompoundContinue), | 42 .with(hasBody(compoundStmt(hasAnySubstatement(continueStmt())) |
43 .bind("continue"))), | |
45 this); | 44 this); |
46 } | 45 } |
47 | 46 |
48 void RedundantControlFlowCheck::check(const MatchFinder::MatchResult &Result) { | 47 void RedundantControlFlowCheck::check(const MatchFinder::MatchResult &Result) { |
49 if (const auto *Return = Result.Nodes.getNodeAs<CompoundStmt>("return")) | 48 if (const auto *Return = Result.Nodes.getNodeAs<CompoundStmt>("return")) |
53 checkRedundantContinue(Result, Continue); | 52 checkRedundantContinue(Result, Continue); |
54 } | 53 } |
55 | 54 |
56 void RedundantControlFlowCheck::checkRedundantReturn( | 55 void RedundantControlFlowCheck::checkRedundantReturn( |
57 const MatchFinder::MatchResult &Result, const CompoundStmt *Block) { | 56 const MatchFinder::MatchResult &Result, const CompoundStmt *Block) { |
58 CompoundStmt::const_reverse_body_iterator last = Block->body_rbegin(); | 57 CompoundStmt::const_reverse_body_iterator Last = Block->body_rbegin(); |
59 if (const auto *Return = dyn_cast<ReturnStmt>(*last)) | 58 if (const auto *Return = dyn_cast<ReturnStmt>(*Last)) |
60 issueDiagnostic(Result, Block, Return->getSourceRange(), | 59 issueDiagnostic(Result, Block, Return->getSourceRange(), |
61 RedundantReturnDiag); | 60 RedundantReturnDiag); |
62 } | 61 } |
63 | 62 |
64 void RedundantControlFlowCheck::checkRedundantContinue( | 63 void RedundantControlFlowCheck::checkRedundantContinue( |
65 const MatchFinder::MatchResult &Result, const CompoundStmt *Block) { | 64 const MatchFinder::MatchResult &Result, const CompoundStmt *Block) { |
66 CompoundStmt::const_reverse_body_iterator last = Block->body_rbegin(); | 65 CompoundStmt::const_reverse_body_iterator Last = Block->body_rbegin(); |
67 if (const auto *Continue = dyn_cast<ContinueStmt>(*last)) | 66 if (const auto *Continue = dyn_cast<ContinueStmt>(*Last)) |
68 issueDiagnostic(Result, Block, Continue->getSourceRange(), | 67 issueDiagnostic(Result, Block, Continue->getSourceRange(), |
69 RedundantContinueDiag); | 68 RedundantContinueDiag); |
70 } | 69 } |
71 | 70 |
72 void RedundantControlFlowCheck::issueDiagnostic( | 71 void RedundantControlFlowCheck::issueDiagnostic( |