Tokenizer: simplify GCC '({ %var%|%num% ; })' to '%var%|%num%'.

Remove useless brace around condition in simplifyFlowControl.
This commit is contained in:
Edoardo Prezioso 2012-10-13 13:24:41 +02:00
parent 0f8db28d30
commit 64b4960acc
2 changed files with 9 additions and 8 deletions

View File

@ -2185,6 +2185,12 @@ void Tokenizer::simplifyRoundCurlyParenthesis()
tok->linkAt(2)->previous()->deleteNext(3);
tok->deleteNext(2);
}
if (Token::Match(tok, "( { %any% ; } )") &&
(tok->tokAt(2)->isNumber() || tok->tokAt(2)->isName())) {
tok->deleteNext();
tok->deleteThis();
tok->deleteNext(3);
}
}
}
@ -2370,11 +2376,6 @@ static Token *skipTernaryOp(Token *tok)
break;
}
}
//allow GCC '({ %var%|%num% ; })' statement expression extension
if (Token::Match(tok, "( { %any% ; } )") &&
(tok->tokAt(2)->isNumber() || tok->tokAt(2)->isName())) {
tok = tok->link();
}
if (Token::Match(tok->next(), "[{};]"))
break;
}
@ -3674,7 +3675,7 @@ void Tokenizer::simplifyFlowControl()
eraseDeadCode(tok, 0);
} else if (Token::Match(tok,"return|goto") ||
(Token::Match(tok,"exit|abort")) ||
Token::Match(tok,"exit|abort") ||
(tok->str() == "throw" && !isC())) {
//TODO: ensure that we exclude user-defined 'exit|abort|throw', except for 'noreturn'
//catch the first ';'

View File

@ -6795,8 +6795,8 @@ private:
}
void simplifyAssignmentBlock() {
ASSERT_EQUALS("; { x = 123 ; } ;", tokenizeAndStringify(";x=({123;});"));
ASSERT_EQUALS("; { x = y ; } ;", tokenizeAndStringify(";x=({y;});"));
ASSERT_EQUALS("; x = 123 ;", tokenizeAndStringify(";x=({123;});"));
ASSERT_EQUALS("; x = y ;", tokenizeAndStringify(";x=({y;});"));
}
void simplifyOperatorName1() {