@@ -83,6 +83,17 @@ static const StatementMatcher incrementVarMatcher() {
83
83
return declRefExpr (to (varDecl (equalsBoundNode (InitVarName))));
84
84
}
85
85
86
+ static StatementMatcher
87
+ arrayConditionMatcher (internal::Matcher<Expr> LimitExpr) {
88
+ return binaryOperator (
89
+ anyOf (allOf (hasOperatorName (" <" ), hasLHS (integerComparisonMatcher ()),
90
+ hasRHS (LimitExpr)),
91
+ allOf (hasOperatorName (" >" ), hasLHS (LimitExpr),
92
+ hasRHS (integerComparisonMatcher ())),
93
+ allOf (hasOperatorName (" !=" ),
94
+ hasOperands (integerComparisonMatcher (), LimitExpr))));
95
+ }
96
+
86
97
// / The matcher for loops over arrays.
87
98
// / \code
88
99
// / for (int i = 0; i < 3 + 2; ++i) { ... }
@@ -99,18 +110,12 @@ StatementMatcher makeArrayLoopMatcher() {
99
110
StatementMatcher ArrayBoundMatcher =
100
111
expr (hasType (isInteger ())).bind (ConditionBoundName);
101
112
102
- return forStmt (
103
- unless (isInTemplateInstantiation ()),
104
- hasLoopInit (declStmt (hasSingleDecl (initToZeroMatcher ()))),
105
- hasCondition (anyOf (
106
- binaryOperator (hasOperatorName (" <" ),
107
- hasLHS (integerComparisonMatcher ()),
108
- hasRHS (ArrayBoundMatcher)),
109
- binaryOperator (hasOperatorName (" >" ), hasLHS (ArrayBoundMatcher),
110
- hasRHS (integerComparisonMatcher ())))),
111
- hasIncrement (
112
- unaryOperator (hasOperatorName (" ++" ),
113
- hasUnaryOperand (incrementVarMatcher ()))))
113
+ return forStmt (unless (isInTemplateInstantiation ()),
114
+ hasLoopInit (declStmt (hasSingleDecl (initToZeroMatcher ()))),
115
+ hasCondition (arrayConditionMatcher (ArrayBoundMatcher)),
116
+ hasIncrement (
117
+ unaryOperator (hasOperatorName (" ++" ),
118
+ hasUnaryOperand (incrementVarMatcher ()))))
114
119
.bind (LoopNameArray);
115
120
}
116
121
@@ -278,22 +283,16 @@ StatementMatcher makePseudoArrayLoopMatcher() {
278
283
declRefExpr (to (varDecl (equalsBoundNode (EndVarName))))),
279
284
EndInitMatcher));
280
285
281
- return forStmt (
282
- unless (isInTemplateInstantiation ()),
283
- hasLoopInit (
284
- anyOf (declStmt (declCountIs (2 ),
285
- containsDeclaration (0 , initToZeroMatcher ()),
286
- containsDeclaration (1 , EndDeclMatcher)),
287
- declStmt (hasSingleDecl (initToZeroMatcher ())))),
288
- hasCondition (anyOf (
289
- binaryOperator (hasOperatorName (" <" ),
290
- hasLHS (integerComparisonMatcher ()),
291
- hasRHS (IndexBoundMatcher)),
292
- binaryOperator (hasOperatorName (" >" ), hasLHS (IndexBoundMatcher),
293
- hasRHS (integerComparisonMatcher ())))),
294
- hasIncrement (
295
- unaryOperator (hasOperatorName (" ++" ),
296
- hasUnaryOperand (incrementVarMatcher ()))))
286
+ return forStmt (unless (isInTemplateInstantiation ()),
287
+ hasLoopInit (
288
+ anyOf (declStmt (declCountIs (2 ),
289
+ containsDeclaration (0 , initToZeroMatcher ()),
290
+ containsDeclaration (1 , EndDeclMatcher)),
291
+ declStmt (hasSingleDecl (initToZeroMatcher ())))),
292
+ hasCondition (arrayConditionMatcher (IndexBoundMatcher)),
293
+ hasIncrement (
294
+ unaryOperator (hasOperatorName (" ++" ),
295
+ hasUnaryOperand (incrementVarMatcher ()))))
297
296
.bind (LoopNamePseudoArray);
298
297
}
299
298
0 commit comments