Refactoring of CheckOther::checkModuloAlwaysTrueFalse using AST
This commit is contained in:
parent
8cc1f664d8
commit
827cfac91e
|
@ -3004,11 +3004,22 @@ void CheckOther::checkModuloAlwaysTrueFalse()
|
|||
for (std::size_t i = 0; i < functions; ++i) {
|
||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||
if ((Token::Match(tok, "% %num% %comp% %num%")) &&
|
||||
(!tok->tokAt(4) || !tok->tokAt(4)->isArithmeticalOp()) && (!tok->astParent() || !tok->astParent()->isArithmeticalOp())) {
|
||||
if (MathLib::isLessEqual(tok->strAt(1), tok->strAt(3)))
|
||||
moduloAlwaysTrueFalseError(tok, tok->strAt(1));
|
||||
if (!tok->isComparisonOp())
|
||||
continue;
|
||||
const Token *num,*modulo;
|
||||
if (Token::simpleMatch(tok->astOperand1(),"%") && Token::Match(tok->astOperand2(),"%num%")) {
|
||||
modulo = tok->astOperand1();
|
||||
num = tok->astOperand2();
|
||||
} else if (Token::Match(tok->astOperand1(),"%num%") && Token::simpleMatch(tok->astOperand2(),"%")) {
|
||||
num = tok->astOperand1();
|
||||
modulo = tok->astOperand2();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Token::Match(modulo->astOperand2(), "%num%") &&
|
||||
MathLib::isLessEqual(modulo->astOperand2()->str(),num->str()))
|
||||
moduloAlwaysTrueFalseError(tok, modulo->astOperand2()->str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue