Tokenizer: Fixed bad simplifyComma for code 'a ? b = c , d : e ;'
This commit is contained in:
parent
8d5a9893d5
commit
064844f8db
|
@ -8540,18 +8540,19 @@ void Tokenizer::simplifyComma()
|
||||||
tok->str(";");
|
tok->str(";");
|
||||||
tok->insertToken("delete");
|
tok->insertToken("delete");
|
||||||
} else {
|
} else {
|
||||||
|
bool replace = false;
|
||||||
for (Token *tok2 = tok->previous(); tok2; tok2 = tok2->previous()) {
|
for (Token *tok2 = tok->previous(); tok2; tok2 = tok2->previous()) {
|
||||||
if (tok2->str() == "=") {
|
if (tok2->str() == "=") {
|
||||||
// Handle "a = 0, b = 0;"
|
// Handle "a = 0, b = 0;"
|
||||||
tok->str(";");
|
replace = true;
|
||||||
break;
|
|
||||||
} else if (Token::Match(tok2, "delete %var%") ||
|
} else if (Token::Match(tok2, "delete %var%") ||
|
||||||
Token::Match(tok2, "delete [ ] %var%")) {
|
Token::Match(tok2, "delete [ ] %var%")) {
|
||||||
// Handle "delete a, a = 0;"
|
// Handle "delete a, a = 0;"
|
||||||
|
replace = true;
|
||||||
|
} else if (Token::Match(tok2, "[?:;,{}()]")) {
|
||||||
|
if (replace && Token::Match(tok2, "[;{}]"))
|
||||||
tok->str(";");
|
tok->str(";");
|
||||||
break;
|
break;
|
||||||
} else if (Token::Match(tok2, "[:;,{}()]")) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2894,6 +2894,11 @@ private:
|
||||||
ASSERT_EQUALS("void f ( ) { int a ; int b ; if ( a ) { a = 0 ; b = 0 ; } }", tok(code));
|
ASSERT_EQUALS("void f ( ) { int a ; int b ; if ( a ) { a = 0 ; b = 0 ; } }", tok(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const char code[] = "a ? b = c , d : e ;"; // do nothing
|
||||||
|
ASSERT_EQUALS(code, tok(code));
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const char code[] = "void f()\n"
|
const char code[] = "void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue