AST: Handle ternary operators

This commit is contained in:
Daniel Marjamäki 2013-11-04 11:44:54 +01:00
parent de29991c11
commit dde46527f3
1 changed files with 12 additions and 2 deletions

View File

@ -566,16 +566,26 @@ static void compileLogicOr(Token *&tok, std::stack<Token*> &op)
} }
} }
static void compileAssign(Token *&tok, std::stack<Token*> &op) static void compileTernaryOp(Token *&tok, std::stack<Token*> &op)
{ {
compileLogicOr(tok,op); compileLogicOr(tok,op);
while (tok) { while (tok) {
if (tok->str() == "=") { if (Token::Match(tok, "[?:]")) {
compileBinOp(tok, compileLogicOr, op); compileBinOp(tok, compileLogicOr, op);
} else break; } else break;
} }
} }
static void compileAssign(Token *&tok, std::stack<Token*> &op)
{
compileTernaryOp(tok,op);
while (tok) {
if (tok->str() == "=") {
compileBinOp(tok, compileTernaryOp, op);
} else break;
}
}
static void compileComma(Token *&tok, std::stack<Token*> &op) static void compileComma(Token *&tok, std::stack<Token*> &op)
{ {
compileAssign(tok,op); compileAssign(tok,op);