From dde46527f35622ce2c1642cf0a26b517b8ea0f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 4 Nov 2013 11:44:54 +0100 Subject: [PATCH] AST: Handle ternary operators --- lib/tokenlist.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index a014fa565..3894f5a7c 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -566,16 +566,26 @@ static void compileLogicOr(Token *&tok, std::stack &op) } } -static void compileAssign(Token *&tok, std::stack &op) +static void compileTernaryOp(Token *&tok, std::stack &op) { compileLogicOr(tok,op); while (tok) { - if (tok->str() == "=") { + if (Token::Match(tok, "[?:]")) { compileBinOp(tok, compileLogicOr, op); } else break; } } +static void compileAssign(Token *&tok, std::stack &op) +{ + compileTernaryOp(tok,op); + while (tok) { + if (tok->str() == "=") { + compileBinOp(tok, compileTernaryOp, op); + } else break; + } +} + static void compileComma(Token *&tok, std::stack &op) { compileAssign(tok,op);