Example #1
0
        public override void OnConditionalExpression(ConditionalExpression node)
        {
            BoundSpillSequenceBuilder conditionBuilder = null;
            var condition = VisitExpression(ref conditionBuilder, node.Condition);

            BoundSpillSequenceBuilder trueBuilder = null;
            var trueValue = VisitExpression(ref trueBuilder, node.TrueValue);

            BoundSpillSequenceBuilder falseBuilder = null;
            var falseValue = VisitExpression(ref falseBuilder, node.FalseValue);

            if (trueBuilder == null && falseBuilder == null)
            {
                node.Condition  = condition;
                node.TrueValue  = trueValue;
                node.FalseValue = falseValue;
                ReplaceCurrentNode(UpdateExpression(conditionBuilder, node));
                return;
            }

            if (conditionBuilder == null)
            {
                conditionBuilder = new BoundSpillSequenceBuilder();
            }
            if (trueBuilder == null)
            {
                trueBuilder = new BoundSpillSequenceBuilder();
            }
            if (falseBuilder == null)
            {
                falseBuilder = new BoundSpillSequenceBuilder();
            }

            if (node.ExpressionType == _tss.VoidType)
            {
                conditionBuilder.AddStatement(
                    new IfStatement(
                        condition.LexicalInfo,
                        condition,
                        new Block(UpdateStatement(trueBuilder, new ExpressionStatement(trueValue))),
                        new Block(UpdateStatement(falseBuilder, new ExpressionStatement(falseValue)))));

                ReplaceCurrentNode(conditionBuilder.Update(_F.CreateDefaultInvocation(node.LexicalInfo, node.ExpressionType)));
            }
            else
            {
                var tmp = _F.DeclareTempLocal(_currentMethod, node.ExpressionType);
                tmp.Local["SynthesizedKind"] = AWAIT_SPILL_MARKER;

                conditionBuilder.AddLocal(tmp);
                var trueBlock = new Block(new ExpressionStatement(
                                              UpdateExpression(trueBuilder, _F.CreateAssignment(_F.CreateLocalReference(tmp), trueValue))));
                var falseBlock = new Block(new ExpressionStatement(
                                               UpdateExpression(falseBuilder, _F.CreateAssignment(_F.CreateLocalReference(tmp), falseValue))));
                conditionBuilder.AddStatement(new IfStatement(condition, trueBlock, falseBlock));

                ReplaceCurrentNode(conditionBuilder.Update(_F.CreateLocalReference(tmp)));
            }
        }