Tokenizer: simplify 'a[b-1]+=1' better
This commit is contained in:
parent
c29940b114
commit
fce6f11ed8
|
@ -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;
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue