Пример #1
0
        public AstPostExpression([NotNull] ISourcePosition position, [NotNull] AstExpr expression, [NotNull] AstNode action) : base(position)
        {
            if (expression == null)
                throw new ArgumentNullException("expression");

            if (action == null)
                throw new ArgumentNullException("action");
            
            _expression = expression;
            _action = action;
        }
Пример #2
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);
     }
 }
Пример #3
0
        private static void _genChecks(MacroContext context, [InstantHandle] Func<AstGetSet> retVar,
            AstNode contStmt, AstNode breakStmt)
        {
            var inv = context.Invocation;

            //Generate check for continue
            AstCondition checkCont;
            {
                var contCond = _genCompare(context, retVar(), ReturnVariant.Continue);
                checkCont = new AstCondition(inv.Position, context.CurrentBlock, contCond);
                checkCont.IfBlock.Add(contStmt);
            }

            //Generate check for break
            AstCondition checkBreak;
            {
                var breakCond = _genCompare(context, retVar(), ReturnVariant.Break);
                checkBreak = new AstCondition(inv.Position, context.CurrentBlock, breakCond);
                checkBreak.IfBlock.Add(breakStmt);
            }

            //Connect break-check to continue check
            checkCont.ElseBlock.Add(checkBreak);
            context.Block.Add(checkCont);
        }
Пример #4
0
 public AstNode GetOptimizedNode(AstNode node)
 {
     if (node == null)
         throw new ArgumentNullException("node");
     var expr = node as AstExpr;
     if (expr == null || !expr.TryOptimize(_session.Target, out expr))
         return node;
     else
         return expr;
 }