Tokenizer: simplify 'case 0: x += y;'

This commit is contained in:
Daniel Marjamäki 2010-11-01 19:31:30 +01:00
parent 94fc13f0c4
commit 1b9de20f9b
2 changed files with 9 additions and 1 deletions

View File

@ -4369,8 +4369,14 @@ void Tokenizer::simplifyCompoundAssignment()
// "a+=b" => "a = a + b"
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "[;{}] %var%"))
if (Token::Match(tok, "[;{}:] %var%"))
{
if (tok->str() == ":")
{
if (tok->strAt(-2) != "case")
continue;
}
const Token * const vartok = tok->next();
const std::string str = tok->strAt(2);

View File

@ -4609,6 +4609,8 @@ private:
ASSERT_EQUALS("{ x = x ^ y ; }", tokenizeAndStringify("{ x ^= y;}"));
ASSERT_EQUALS("{ x = x << y ; }", tokenizeAndStringify("{ x <<= y;}"));
ASSERT_EQUALS("{ x = x >> y ; }", tokenizeAndStringify("{ x >>= y;}"));
ASSERT_EQUALS("case 0 : x = x + y ; break ;", tokenizeAndStringify("case 0: x += y; break;"));
}
void simplifyAssignmentInFunctionCall()