Tokenizer: simplify 'x.y += 1;'

This commit is contained in:
Daniel Marjamäki 2010-11-01 20:33:55 +01:00
parent 1b9de20f9b
commit c4452effa3
2 changed files with 20 additions and 3 deletions

View File

@ -4377,7 +4377,16 @@ void Tokenizer::simplifyCompoundAssignment()
continue;
}
const Token * const vartok = tok->next();
// variable..
std::stack<Token *> vartok;
vartok.push(tok->next());
while (Token::Match(tok->tokAt(2), ". %var%"))
{
tok = tok->tokAt(2);
vartok.push(tok->next());
}
// assignment..
const std::string str = tok->strAt(2);
// Is it a +=|-=|.. ?
@ -4393,8 +4402,14 @@ void Tokenizer::simplifyCompoundAssignment()
tok = tok->tokAt(2);
tok->str("=");
tok->insertToken(op);
tok->insertToken(vartok->str());
tok->next()->varId(vartok->varId());
while (!vartok.empty())
{
tok->insertToken(vartok.top()->str());
tok->next()->varId(vartok.top()->varId());
vartok.pop();
if (!vartok.empty())
tok->insertToken(".");
}
}
}
}

View File

@ -4611,6 +4611,8 @@ private:
ASSERT_EQUALS("{ x = x >> y ; }", tokenizeAndStringify("{ x >>= y;}"));
ASSERT_EQUALS("case 0 : x = x + y ; break ;", tokenizeAndStringify("case 0: x += y; break;"));
ASSERT_EQUALS("; x . y = x . y + 1 ;", tokenizeAndStringify("; x.y += 1;"));
}
void simplifyAssignmentInFunctionCall()