AST: Fixed problem with decrement
This commit is contained in:
parent
d0f6f07ced
commit
e0eb000ac3
|
@ -455,15 +455,23 @@ static void compileTerm(Token *& tok, std::stack<Token*> &op)
|
|||
op.push(name->next());
|
||||
}
|
||||
} 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
|
||||
tok->astOperand1(op.top());
|
||||
op.pop();
|
||||
op.push(tok);
|
||||
tok = tok->next();
|
||||
} else {
|
||||
// pre increment/decrement
|
||||
compileUnaryOp(tok, compileDot, op);
|
||||
}
|
||||
} else if (tok->str() == "(") {
|
||||
if (iscast(tok)) {
|
||||
|
|
|
@ -10054,6 +10054,10 @@ private:
|
|||
ASSERT_EQUALS("1a--+", testAst("1 + --a"));
|
||||
ASSERT_EQUALS("1a--+", testAst("1 + a--"));
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue