Tokenizer: better simplification of calculations in conditions

This commit is contained in:
Daniel Marjamäki 2011-04-02 11:08:58 +02:00
parent 64fa7bf8d4
commit f34e9e6623
2 changed files with 8 additions and 1 deletions

View File

@ -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% ==|!=|<=|>=|<|>|)"))
{
tok = tok->next();

View File

@ -2719,6 +2719,12 @@ private:
ASSERT_EQUALS("; a [ 0 ] ;", tok(";a[0*(*p)];"));
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))"));
}