simplifyCalculations: handle '(4%1<<1&4!=1)' better. must combine '!' '=' before constant folding. fixed the operator precedence for comparison operators. (#4931)

This commit is contained in:
Daniel Marjamäki 2015-11-28 09:02:26 +01:00
parent 44305fd98e
commit c0da6c1541
3 changed files with 6 additions and 5 deletions

View File

@ -878,11 +878,11 @@ static bool isLowerThanAnd(const Token* lower)
}
static bool isLowerThanShift(const Token* lower)
{
return isLowerThanAnd(lower) || Token::Match(lower, "%comp%|&");
return isLowerThanAnd(lower) || Token::Match(lower, "&");
}
static bool isLowerThanPlusMinus(const Token* lower)
{
return isLowerThanShift(lower) || Token::Match(lower, "<<|>>");
return isLowerThanShift(lower) || Token::Match(lower, "%comp%|<<|>>");
}
static bool isLowerThanMulDiv(const Token* lower)
{

View File

@ -3413,6 +3413,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
// combine "- %num%"
concatenateNegativeNumberAndAnyPositive();
// Combine tokens..
combineOperators();
#ifndef CPPCHECK2
// simplify simple calculations
for (Token *tok = list.front() ? list.front()->next() : nullptr; tok; tok = tok->next()) {
@ -3439,9 +3442,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
if (!simplifyAddBraces())
return false;
// Combine tokens..
combineOperators();
sizeofAddParentheses();
// Simplify: 0[foo] -> *(foo)

View File

@ -2098,6 +2098,7 @@ private:
ASSERT_EQUALS("x ( 1 )", tok("x(2 && 2|5<<2%4)")); // #4931
ASSERT_EQUALS("x ( -2 << 6 | 1 )", tok("x(1-3<<6|5/3)")); // #4931
ASSERT_EQUALS("x ( 2 )", tok("x(2|0*0&2>>1+0%2*1)")); // #4931
ASSERT_EQUALS("x ( 0 & 4 != 1 )", tok("x(4%1<<1&4!=1)")); // #4931 (can be simplified further but it's not a problem)
// don't remove these spaces..
ASSERT_EQUALS("new ( auto ) ( 4 ) ;", tok("new (auto)(4);"));