simplifyCalculations: better handling of && and || in conditions (#4931)
This commit is contained in:
parent
ac17541ca9
commit
5fabe66ff7
|
@ -1055,6 +1055,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
|
|||
Token::Match(tok->previous(), "[(=,] 1 %oror%")) {
|
||||
unsigned int par = 0;
|
||||
const Token *tok2 = tok;
|
||||
bool andAnd = (tok->next()->str() == "&&");
|
||||
for (; tok2; tok2 = tok2->next()) {
|
||||
if (tok2->str() == "(")
|
||||
++par;
|
||||
|
@ -1062,10 +1063,10 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
|
|||
if (par == 0)
|
||||
break;
|
||||
--par;
|
||||
} else if (par == 0 && (Token::Match(tok2, "[,;?]")))
|
||||
} else if (par == 0 && isLowerThanLogicalAnd(tok2) && (andAnd || tok2->str() != "||"))
|
||||
break;
|
||||
}
|
||||
if (Token::Match(tok2, "[);,?]")) {
|
||||
if (tok2) {
|
||||
Token::eraseTokens(tok, tok2);
|
||||
ret = true;
|
||||
}
|
||||
|
|
|
@ -2099,6 +2099,7 @@ private:
|
|||
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)
|
||||
ASSERT_EQUALS("x ( true )", tok("x(0&&4>0==2||4)")); // #4931
|
||||
|
||||
// don't remove these spaces..
|
||||
ASSERT_EQUALS("new ( auto ) ( 4 ) ;", tok("new (auto)(4);"));
|
||||
|
|
Loading…
Reference in New Issue