• Home
  • Raw
  • Download

Lines Matching +full:branches +full:- +full:ignore

1 //===--- BranchCloneCheck.cpp - clang-tidy --------------------------------===//
8 //===----------------------------------------------------------------------===//
24 LHS->Profile(DataLHS, Context, false); in areStatementsIdentical()
25 RHS->Profile(DataRHS, Context, false); in areStatementsIdentical()
35 /// Determines if the bodies of two branches in a switch statements are Type I
47 // would casue false positives in real-world code. in areSwitchBranchesIdentical()
48 if (!areStatementsIdentical(LHS[i]->stripLabelLikeStatements(), in areSwitchBranchesIdentical()
49 RHS[i]->stripLabelLikeStatements(), Context)) { in areSwitchBranchesIdentical()
62 Finder->addMatcher( in registerMatchers()
68 Finder->addMatcher(switchStmt().bind("switch"), this); in registerMatchers()
69 Finder->addMatcher(conditionalOperator().bind("condOp"), this); in registerMatchers()
76 const Stmt *Then = IS->getThen(); in check()
84 if (areStatementsIdentical(Then->IgnoreContainers(), in check()
85 Else->IgnoreContainers(), Context)) { in check()
86 diag(IS->getBeginLoc(), "if with identical then and else branches"); in check()
87 diag(IS->getElseLoc(), "else branch starts here", DiagnosticIDs::Note); in check()
93 // To find all the duplicates, we collect all the branches into a vector. in check()
94 llvm::SmallVector<const Stmt *, 4> Branches; in check() local
98 Branches.push_back(Cur->getThen()); in check()
100 Else = Cur->getElse(); in check()
109 Branches.push_back(Else); in check()
114 size_t N = Branches.size(); in check()
118 // We have already seen Branches[i] as a clone of an earlier branch. in check()
126 !areStatementsIdentical(Branches[i]->IgnoreContainers(), in check()
127 Branches[j]->IgnoreContainers(), Context)) in check()
135 diag(Branches[i]->getBeginLoc(), in check()
138 Lexer::getLocForEndOfToken(Branches[i]->getEndLoc(), 0, in check()
145 diag(Branches[j]->getBeginLoc(), "clone %0 starts here", in check()
147 << (NumCopies - 1); in check()
155 if (areStatementsIdentical(CO->getTrueExpr(), CO->getFalseExpr(), Context)) in check()
156 diag(CO->getQuestionLoc(), in check()
163 const CompoundStmt *Body = dyn_cast_or_null<CompoundStmt>(SS->getBody()); in check()
168 // but we do not try to distinguish branches in such code. in check()
172 // We will first collect the branches of the switch statements. For the in check()
173 // sake of simplicity we say that branches are delimited by the SwitchCase in check()
174 // (`case:` or `default:`) children of Body; that is, we ignore `case:` or in check()
176 // the effects of `break` and other manipulation of the control-flow. in check()
177 llvm::SmallVector<SwitchBranch, 4> Branches; in check() local
178 for (const Stmt *S : Body->body()) { in check()
181 Branches.emplace_back(); in check()
186 // store those statements in branches. in check()
187 if (!Branches.empty()) in check()
188 Branches.back().push_back(S); in check()
191 auto End = Branches.end(); in check()
192 auto BeginCurrent = Branches.begin(); in check()
200 // complete family of consecutive identical branches. in check()
202 diag(BeginCurrent->front()->getBeginLoc(), in check()
203 "switch has %0 consecutive identical branches") in check()
206 SourceLocation EndLoc = (EndCurrent - 1)->back()->getEndLoc(); in check()
212 EndLoc = (EndCurrent - 1)->back()->getBeginLoc(); in check()