Tokenizer::simplifyCalculations: simplify division result if it's a whole number, even though it doesn't have precedence
This commit is contained in:
parent
855b01cd5a
commit
ea57e10c7f
|
@ -7377,14 +7377,13 @@ bool Tokenizer::simplifyCalculations()
|
|||
|
||||
else if (tok->next() && tok->next()->isNumber())
|
||||
{
|
||||
|
||||
// (1-2)
|
||||
while (Token::Match(tok, "[[,(=<>+-*|&^] %num% [+-*/] %num% [],);=<>+-*/|&^]") ||
|
||||
Token::Match(tok, "<< %num% [+-*/] %num% [],);=<>+-*/|&^]") ||
|
||||
Token::Match(tok, "[[,(=<>+-*|&^] %num% [+-*/] %num% <<|>>") ||
|
||||
Token::Match(tok, "<< %num% [+-*/] %num% <<") ||
|
||||
Token::Match(tok, "[(,[] %num% [|&^] %num% [];,);]") ||
|
||||
Token::Match(tok, "(|==|!=|<=|>=|<|>|+ %num% [+-*/] %num% ==|!=|<=|>=|<|>|)"))
|
||||
Token::Match(tok, "(|==|!=|<=|>=|<|>|+|-|* %num% [+-*/] %num% ==|!=|<=|>=|<|>|)"))
|
||||
{
|
||||
tok = tok->next();
|
||||
|
||||
|
@ -7415,8 +7414,14 @@ bool Tokenizer::simplifyCalculations()
|
|||
}
|
||||
}
|
||||
|
||||
// Division where result is a whole number
|
||||
if (Token::Match(tok->previous(), "* %num% /") &&
|
||||
tok->str() == MathLib::multiply(tok->strAt(2), MathLib::divide(tok->str(), tok->strAt(2))))
|
||||
{
|
||||
}
|
||||
|
||||
// + and - are calculated after * and /
|
||||
if (Token::Match(tok->next(), "[+-/]"))
|
||||
else if (Token::Match(tok->next(), "[+-/]"))
|
||||
{
|
||||
if (tok->previous()->str() == "*")
|
||||
continue;
|
||||
|
|
|
@ -2722,9 +2722,7 @@ private:
|
|||
|
||||
ASSERT_EQUALS("if ( a == 2 )", tok("if (a==1+1)"));
|
||||
ASSERT_EQUALS("if ( a + 2 != 6 )", tok("if (a+1+1!=1+2+3)"));
|
||||
|
||||
// TODO: "4/4" should be simplified
|
||||
TODO_ASSERT_EQUALS("if ( 4 < a )", "if ( 4 < a * 4 / 4 )", tok("if (14-2*5<a*4/(2*2))"));
|
||||
ASSERT_EQUALS("if ( 4 < a )", tok("if (14-2*5<a*4/(2*2))"));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue