示例#1
0
 private static void _determineActions(MacroContext context, [InstantHandle] Func<AstGetSet> retValue,
     out AstNode contStmt, out AstNode breakStmt)
 {
     var inv = context.Invocation;
     var bl = context.CurrentLoopBlock;
     if (bl == null)
     {
         contStmt = new AstReturn(inv.File, inv.Line, inv.Column, ReturnVariant.Continue)
             {Expression = retValue()};
         breakStmt = new AstReturn(inv.File, inv.Line, inv.Column, ReturnVariant.Break)
             {Expression = retValue()};
     }
     else
     {
         contStmt = new AstExplicitGoTo(inv.File, inv.Line, inv.Column, bl.ContinueLabel);
         breakStmt = new AstExplicitGoTo(inv.File, inv.Line, inv.Column, bl.BreakLabel);
     }
 }
示例#2
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;
        }