Пример #1
0
        private bool _optimizeConditionalReturnExpression(CompilerTarget target)
        {
            var cond = Expression as AstConditionalExpression;
            if (cond == null)
                return false;

            //  return  if( cond )
            //              expr1
            //          else
            //              expr2
            var retif = new AstCondition(Position, target.CurrentBlock, cond.Condition, cond.IsNegative);

            var ret1 = new AstReturn(File, Line, Column, ReturnVariant)
                {
                    Expression = cond.IfExpression
                };
            retif.IfBlock.Add(ret1);

            var ret2 = new AstReturn(File, Line, Column, ReturnVariant)
                {
                    Expression = cond.ElseExpression
                };
            //not added to the condition

            retif.EmitEffectCode(target); //  if( cond )
            //      return expr1
            ret2.EmitEffectCode(target); //  return expr2

            //ret1 and ret2 will continue optimizing
            return true;
        }