Support lambdas in "else if" simplification (#6860)

This commit is contained in:
Frank Zingsheim 2015-07-23 09:41:35 +02:00 committed by PKEuS
parent 8d8c03dad8
commit 6485339d66
2 changed files with 18 additions and 4 deletions

View File

@ -6899,12 +6899,9 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
void Tokenizer::elseif()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "(|[") ||
(tok->str() == "{" && tok->previous() && tok->previous()->str() == "="))
tok = tok->link();
if (!Token::simpleMatch(tok, "else if"))
continue;
for (Token *tok2 = tok; tok2; tok2 = tok2->next()) {
if (Token::Match(tok2, "(|{|["))
tok2 = tok2->link();

View File

@ -833,6 +833,23 @@ private:
"}";
ASSERT_EQUALS(tok(expected), tok(src));
}
// Ticket #6860 - lambdas
{
const char src[] = "( []{if (ab) {cd}else if(ef) { gh } else { ij }kl}() )";
const char expected[] = "\n\n##file 0\n1: ( [ ] { if ( ab ) { cd } else { if ( ef ) { gh } else { ij } } kl } ( ) )\n";
ASSERT_EQUALS(expected, elseif(src));
}
{
const char src[] = "[ []{if (ab) {cd}else if(ef) { gh } else { ij }kl}() ]";
const char expected[] = "\n\n##file 0\n1: [ [ ] { if ( ab ) { cd } else { if ( ef ) { gh } else { ij } } kl } ( ) ]\n";
ASSERT_EQUALS(expected, elseif(src));
}
{
const char src[] = "= { []{if (ab) {cd}else if(ef) { gh } else { ij }kl}() }";
const char expected[] = "\n\n##file 0\n1: = { [ ] { if ( ab ) { cd } else { if ( ef ) { gh } else { ij } } kl } ( ) }\n";
ASSERT_EQUALS(expected, elseif(src));
}
}