Refactoring of CheckOther::checkModuloAlwaysTrueFalse using AST

This commit is contained in:
Daniel Marjamäki 2014-05-10 20:49:29 +02:00
parent 8cc1f664d8
commit 827cfac91e
1 changed files with 15 additions and 4 deletions

View File

@ -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());
}
}
}