Tokenizer: simplify 'a[b-1]+=1' better

This commit is contained in:
Daniel Marjamäki 2010-11-04 19:02:54 +01:00
parent c29940b114
commit fce6f11ed8
2 changed files with 19 additions and 5 deletions

View File

@ -4390,11 +4390,24 @@ void Tokenizer::simplifyCompoundAssignment()
// variable..
tok = tok->tokAt(2);
while (Token::Match(tok, ". %var%"))
tok = tok->tokAt(2);
while (Token::Match(tok, "[ %any% ]"))
tok = tok->tokAt(3);
while (Token::Match(tok, ". %var%") || (tok && tok->str() == "["))
{
if (tok->str() != "[")
tok = tok->tokAt(2);
else
{
// goto "]"
tok = tok->next();
while (tok && !Token::Match(tok, "++|--|(|[|]"))
tok = tok->next();
if (!tok)
break;
else if (tok->str() == "]")
tok = tok->next();
else
break;
}
}
if (!tok)
break;

View File

@ -4645,6 +4645,7 @@ private:
ASSERT_EQUALS("; x . y = x . y + 1 ;", tokenizeAndStringify("; x.y += 1;"));
ASSERT_EQUALS("; x [ 0 ] = x [ 0 ] + 1 ;", tokenizeAndStringify("; x[0] += 1;"));
ASSERT_EQUALS("; x [ y - 1 ] = x [ y - 1 ] + 1 ;", tokenizeAndStringify("; x[y-1] += 1;"));
}
void simplifyAssignmentInFunctionCall()