AST: Fixed problem with decrement

This commit is contained in:
Daniel Marjamäki 2013-12-27 14:40:59 +01:00
parent d0f6f07ced
commit e0eb000ac3
2 changed files with 16 additions and 4 deletions

View File

@ -455,15 +455,23 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op)
op.push(name->next()); op.push(name->next());
} }
} else if (Token::Match(tok, "++|--")) { } else if (Token::Match(tok, "++|--")) {
if (!op.empty() && op.top()->isOp()) { bool pre = false;
if (tok->next() && tok->next()->isName())
pre = true;
else if (!op.empty() && !op.top()->isOp())
pre = false;
else
pre = true;
if (pre) {
// pre increment/decrement
compileUnaryOp(tok, compileDot, op);
} else {
// post increment/decrement // post increment/decrement
tok->astOperand1(op.top()); tok->astOperand1(op.top());
op.pop(); op.pop();
op.push(tok); op.push(tok);
tok = tok->next(); tok = tok->next();
} else {
// pre increment/decrement
compileUnaryOp(tok, compileDot, op);
} }
} else if (tok->str() == "(") { } else if (tok->str() == "(") {
if (iscast(tok)) { if (iscast(tok)) {

View File

@ -10054,6 +10054,10 @@ private:
ASSERT_EQUALS("1a--+", testAst("1 + --a")); ASSERT_EQUALS("1a--+", testAst("1 + --a"));
ASSERT_EQUALS("1a--+", testAst("1 + a--")); ASSERT_EQUALS("1a--+", testAst("1 + a--"));
ASSERT_EQUALS("ab+!", testAst("!(a+b)")); ASSERT_EQUALS("ab+!", testAst("!(a+b)"));
// how is "--" handled here:
ASSERT_EQUALS("ab4<<c--+?1:", testAst("a ? (b << 4) + --c : 1"));
ASSERT_EQUALS("ab4<<c--+?1:", testAst("a ? (b << 4) + c-- : 1"));
} }
void astfunction() const { // function calls void astfunction() const { // function calls