Fixed #4553 (Wrong calculation of known values)

This commit is contained in:
Daniel Marjamäki 2013-06-14 18:51:52 +02:00
parent eac4ebf185
commit 722bfe7197
2 changed files with 12 additions and 3 deletions

View File

@ -875,11 +875,13 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
if (par == 0)
break;
--par;
} else if (par == 0 && (Token::Match(tok2, "[,;]")))
} else if (par == 0 && (Token::Match(tok2, "[,;?]")))
break;
}
if (Token::Match(tok2, "[);,]"))
if (Token::Match(tok2, "[);,?]")) {
Token::eraseTokens(tok, tok2);
ret = true;
}
continue;
}
@ -973,7 +975,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
if (Token::Match(tok, "%num% %comp% %num%") &&
MathLib::isInt(tok->str()) &&
MathLib::isInt(tok->strAt(2))) {
if (Token::Match(tok->previous(), "(|&&|%oror%") && Token::Match(tok->tokAt(3), ")|&&|%oror%")) {
if (Token::Match(tok->previous(), "(|&&|%oror%") && Token::Match(tok->tokAt(3), ")|&&|%oror%|?")) {
const MathLib::bigint op1(MathLib::toLongNumber(tok->str()));
const std::string &cmp(tok->next()->str());
const MathLib::bigint op2(MathLib::toLongNumber(tok->strAt(2)));

View File

@ -170,6 +170,7 @@ private:
// Simplify calculations
TEST_CASE(calculations);
TEST_CASE(comparisons);
// Simplify goto..
TEST_CASE(goto1);
@ -3019,6 +3020,12 @@ private:
ASSERT_EQUALS("( 4 )", tok("(1 * 2 / 1 * 2)")); // #3722
}
void comparisons() {
ASSERT_EQUALS("( 1 )", tok("( 1 < 2 )"));
ASSERT_EQUALS("( x )", tok("( x && 1 < 2 )"));
ASSERT_EQUALS("( 5 )", tok("( 1 < 2 && 3 < 4 ? 5 : 6 )"));
ASSERT_EQUALS("( 6 )", tok("( 1 > 2 && 3 > 4 ? 5 : 6 )"));
}
void goto1() {
{