From 1c21dbc44cc21d0f44cc4f819ff971f94793fdf3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 17 Oct 2016 21:43:14 +0200 Subject: [PATCH] - handle trinary conditional statement. --- src/scripting/zscript/zcc_compile.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index c55d6994a..39597c513 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2471,7 +2471,7 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast) case PEX_BitAnd: case PEX_BitOr: case PEX_BitXor: - return new FxBinaryInt(op == PEX_LeftShift ? TK_LShift : op == PEX_RightShift ? TK_RShift : op == PEX_URightShift? TK_URShift : op == PEX_BitAnd ? '&' : op == PEX_BitOr ? '|' : '^', left, right); + return new FxBinaryInt(op == PEX_LeftShift ? TK_LShift : op == PEX_RightShift ? TK_RShift : op == PEX_URightShift ? TK_URShift : op == PEX_BitAnd ? '&' : op == PEX_BitOr ? '|' : '^', left, right); case PEX_BoolOr: case PEX_BoolAnd: @@ -2485,17 +2485,17 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast) case PEX_EQEQ: case PEX_NEQ: - return new FxCompareEq(op == PEX_NEQ ? TK_Neq : TK_Eq, left, right); + return new FxCompareEq(op == PEX_NEQ ? TK_Neq : TK_Eq, left, right); - // todo: These do not have representations in DECORATE and no implementation exists yet. + // todo: These do not have representations in DECORATE and no implementation exists yet. case PEX_LTGTEQ: case PEX_Concat: case PEX_Is: // more esoteric operators case PEX_APREQ: - // vector operations will be done later. + // vector operations will be done later. case PEX_CrossProduct: case PEX_DotProduct: default: @@ -2503,6 +2503,16 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast) } break; } + + case AST_ExprTrinary: + { + auto trinary = static_cast(ast); + auto condition = ConvertNode(trinary->Test); + auto left = ConvertNode(trinary->Left); + auto right = ConvertNode(trinary->Right); + + return new FxConditional(condition, left, right); + } } // only for development. I_Error is more convenient here than a normal error.