Fixed #5675 (wrong AST generated for 'a>>=b')

This commit is contained in:
Daniel Marjamäki 2014-04-21 13:05:34 +02:00
parent a202956471
commit c98beafb6d
2 changed files with 21 additions and 1 deletions

View File

@ -696,7 +696,8 @@ static void compileAssign(Token *&tok, std::stack<Token*> &op, unsigned int dept
{ {
compileTernaryOp(tok,op, depth); compileTernaryOp(tok,op, depth);
while (tok) { while (tok) {
if (tok->str() == "=") { if (tok->str() == "=" || tok->str() == "<<=" || tok->str() == ">>=" ||
(tok->str().size() == 2U && tok->str()[1] == '=' && std::strchr("+-*/%&|^",tok->str()[0]))) {
compileBinOp(tok, compileTernaryOp, op, depth); compileBinOp(tok, compileTernaryOp, op, depth);
} else break; } else break;
} }

View File

@ -10219,6 +10219,13 @@ private:
if (!tokenList.createTokens(istr,"test.cpp")) if (!tokenList.createTokens(istr,"test.cpp"))
return "ERROR"; return "ERROR";
for (Token *tok = tokenList.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "%or%|<<|>>|+|-|*|/|%|&|^ =")) {
tok->str(tok->str() + "=");
tok->deleteNext();
}
}
// Set links.. // Set links..
std::stack<Token *> links; std::stack<Token *> links;
for (Token *tok = tokenList.front(); tok; tok = tok->next()) { for (Token *tok = tokenList.front(); tok; tok = tok->next()) {
@ -10265,6 +10272,18 @@ private:
ASSERT_EQUALS("a-1+", testAst("-a+1")); ASSERT_EQUALS("a-1+", testAst("-a+1"));
ASSERT_EQUALS("ab++-c-", testAst("a-b++-c")); ASSERT_EQUALS("ab++-c-", testAst("a-b++-c"));
// assignment operators
ASSERT_EQUALS("ab>>=", testAst("a>>=b;"));
ASSERT_EQUALS("ab<<=", testAst("a<<=b;"));
ASSERT_EQUALS("ab+=", testAst("a+=b;"));
ASSERT_EQUALS("ab-=", testAst("a-=b;"));
ASSERT_EQUALS("ab*=", testAst("a*=b;"));
ASSERT_EQUALS("ab/=", testAst("a/=b;"));
ASSERT_EQUALS("ab%=", testAst("a%=b;"));
ASSERT_EQUALS("ab&=", testAst("a&=b;"));
ASSERT_EQUALS("ab|=", testAst("a|=b;"));
ASSERT_EQUALS("ab^=", testAst("a^=b;"));
ASSERT_EQUALS("a\"\"=", testAst("a=\"\"")); ASSERT_EQUALS("a\"\"=", testAst("a=\"\""));
ASSERT_EQUALS("a\'\'=", testAst("a=\'\'")); ASSERT_EQUALS("a\'\'=", testAst("a=\'\'"));
testAst("char a[1]=\"\";"); // don't crash testAst("char a[1]=\"\";"); // don't crash