Tokenizer: better simplification of calculations in conditions
This commit is contained in:
parent
64fa7bf8d4
commit
f34e9e6623
|
@ -7383,7 +7383,8 @@ bool Tokenizer::simplifyCalculations()
|
||||||
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% [];,);]"))
|
Token::Match(tok, "[(,[] %num% [|&^] %num% [];,);]") ||
|
||||||
|
Token::Match(tok, "(|==|!=|<=|>=|<|>|+ %num% [+-*/] %num% ==|!=|<=|>=|<|>|)"))
|
||||||
{
|
{
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
|
|
|
@ -2719,6 +2719,12 @@ private:
|
||||||
ASSERT_EQUALS("; a [ 0 ] ;", tok(";a[0*(*p)];"));
|
ASSERT_EQUALS("; a [ 0 ] ;", tok(";a[0*(*p)];"));
|
||||||
|
|
||||||
ASSERT_EQUALS(";", tok("; x = x + 0;"));
|
ASSERT_EQUALS(";", tok("; x = x + 0;"));
|
||||||
|
|
||||||
|
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))"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue