Represents an unconditional jump. This includes return statements, break and continue statements, and other jumps.
Inheritance: Expression
Esempio n. 1
0
 internal static Goto Goto(GotoExpression expression)
 {
     return new Goto()
     {
         Type = expression.Type != typeof(void)
             ? TypeRef.Serialize(expression.Type)
             : null,
         Target = LabelTarget.Serialize(expression.Target),
         Value = expression.Value.Null(e => Serialize(e)),
     }.If(n => n.Type == null, n => n.TypeHint = TypeRef.Serialize(expression.Type));
 }
        protected override Expression VisitGoto(GotoExpression node) {
            if (node.Kind == GotoExpressionKind.Break) {
                if (node.Value != null) {
                    return Expression.Goto(_break, node.Value, node.Type);
                }

                return Expression.Goto(_break, node.Type);
            }
            else if (node.Kind == GotoExpressionKind.Continue) {
                return Expression.Continue(_continue, _continue.Type);
            }

            return node;
        }
        protected override Expression VisitGoto(GotoExpression node)
        {
            var args = new List <object>
            {
                new XAttribute(nameof(node.Kind), node.Kind),
                new XElement(nameof(node.Target), Visit(node.Target))
            };

            if (node.Value != null)
            {
                args.Add(new XElement(nameof(node.Value), Visit(node.Value)));
            }

            return(Push(node, args));
        }
Esempio n. 4
0
 protected internal override Expression VisitGoto(GotoExpression node)
 {
     if (!_inBlock)
     {
         Indent();
     }
     Out(node.Kind.ToString().ToLower(CultureInfo.CurrentCulture), Flow.Space);
     DumpLabel(node.Target);
     if (node.Value != null)
     {
         Out(Flow.Space, "(");
         Visit(node.Value);
         Out(")", Flow.Space);
     }
     if (!_inBlock)
     {
         Dedent();
     }
     return(node);
 }
                protected override Expression VisitGoto(GotoExpression node)
                {
                    var value = Visit(node.Value);

                    var jumpIndex = default(int);

                    if (_leaveLabels.TryGetValue(node.Target, out jumpIndex))
                    {
                        var type = typeof(void);

                        if (node.Value != null)
                        {
                            type = node.Value.Type;
                        }

                        var res = type == typeof(void) ? (Expression)Expression.Constant(null) : Expression.Convert(value, typeof(object));
                        return(Expression.Goto(_leaveLabel, Expression.New(s_leaveCtor, Expression.Constant(jumpIndex), res)));
                    }

                    return(base.VisitGoto(node));
                }
Esempio n. 6
0
        protected internal override Expression VisitGoto(GotoExpression node)
        {
            string op;

            switch (node.Kind)
            {
            case GotoExpressionKind.Goto:
                op = "goto";
                break;

            case GotoExpressionKind.Break:
                op = "break";
                break;

            case GotoExpressionKind.Continue:
                op = "continue";
                break;

            case GotoExpressionKind.Return:
                op = "return";
                break;

            default:
                throw new InvalidOperationException();
            }

            Out(op);
            Out(' ');
            DumpLabel(node.Target);
            if (node.Value == null)
            {
                return(node);
            }

            Out(" (");
            Visit(node.Value);
            Out(")");
            return(node);
        }
Esempio n. 7
0
        protected internal override Expression VisitGoto(GotoExpression node)
        {
            string op = node.Kind switch
            {
                GotoExpressionKind.Goto => "goto",
                GotoExpressionKind.Break => "break",
                GotoExpressionKind.Continue => "continue",
                GotoExpressionKind.Return => "return",
                _ => throw new InvalidOperationException(),
            };

            Out(op);
            Out(' ');
            DumpLabel(node.Target);
            if (node.Value != null)
            {
                Out(" (");
                Visit(node.Value);
                Out(")");
            }
            return(node);
        }
		}//end static method
		internal XElement GotoExpressionToXElement(GotoExpression e)
		{
			object value;
			string xName = "GotoExpression";
			object[] XElementValues = new object[6];
			value = ((GotoExpression)e).Type;
			XElementValues[0] = GenerateXmlFromProperty(typeof(System.Type),
				"Type", value ?? string.Empty);
			value = ((GotoExpression)e).NodeType;
			XElementValues[1] = GenerateXmlFromProperty(typeof(System.Linq.Expressions.ExpressionType),
				"NodeType", value ?? string.Empty);
			value = ((GotoExpression)e).Value;
			XElementValues[2] = GenerateXmlFromProperty(typeof(System.Linq.Expressions.Expression),
				"Value", value ?? string.Empty);
			value = ((GotoExpression)e).Target;
			XElementValues[3] = GenerateXmlFromProperty(typeof(System.Linq.Expressions.LabelTarget),
				"Target", value ?? string.Empty);
			value = ((GotoExpression)e).Kind;
			XElementValues[4] = GenerateXmlFromProperty(typeof(System.Linq.Expressions.GotoExpressionKind),
				"Kind", value ?? string.Empty);
			value = ((GotoExpression)e).CanReduce;
			XElementValues[5] = GenerateXmlFromProperty(typeof(System.Boolean),
				"CanReduce", value ?? string.Empty);
			return new XElement(xName, XElementValues);
		}//end static method
        /// <summary>
        /// Makes an expression slim representing a GotoExpression with the given children.
        /// </summary>
        /// <param name="node">Original expression.</param>
        /// <param name="target">Target label slim.</param>
        /// <param name="value">Value expression slim.</param>
        /// <returns>Slim representation of the original expression.</returns>
        protected override ExpressionSlim MakeGoto(GotoExpression node, LabelTargetSlim target, ExpressionSlim value)
        {
            var type = MakeType(node.Type);

            return(_factory.MakeGoto(node.Kind, target, value, type));
        }
 public GotoExpressionProxy(GotoExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
 protected override Expression VisitGoto(GotoExpression node)
 {
     throw new NotSupportedException();
 }
Esempio n. 12
0
 /// <summary>
 /// Visits the children of the <see cref="GotoExpression"/>.
 /// </summary>
 /// <param name="node">The expression to visit.</param>
 /// <returns>The modified expression, if it or any subexpression was modified;
 /// otherwise, returns the original expression.</returns>
 protected internal virtual Expression VisitGoto(GotoExpression node)
 {
     return(node.Update(VisitLabelTarget(node.Target), Visit(node.Value)));
 }
Esempio n. 13
0
            protected override Expression VisitGoto(GotoExpression node)
            {
                var target = node.Target;

                if (!_labels.Contains(target))
                {
                    var data = default(LeaveLabelData);
                    if (!LeaveLabels.TryGetValue(target, out data))
                    {
                        var parameter = default(ParameterExpression);

                        if (target.Type != typeof(void))
                        {
                            parameter = Expression.Parameter(target.Type, FormattableString.Invariant($"__goto{LeaveLabels.Count}"));
                        }

                        data = new LeaveLabelData
                        {
                            Index = LeaveLabels.Count + 1,
                            Target = target,
                            Value = parameter
                        };

                        LeaveLabels.Add(target, data);
                    }

                    var res = default(Expression);

                    if (data.Value != null)
                    {
                        res =
                            Expression.Block(
                                Expression.Assign(_pendingBranch, Helpers.CreateConstantInt32(data.Index)),
                                Expression.Assign(data.Value, node.Value),
                                Expression.Goto(_exit, node.Type)
                            );
                    }
                    else
                    {
                        res =
                            Expression.Block(
                                Expression.Assign(_pendingBranch, Helpers.CreateConstantInt32(data.Index)),
                                Expression.Goto(_exit, node.Type)
                            );
                    }

                    return res;
                }

                return base.VisitGoto(node);
            }
 public GotoExpressionProxy(GotoExpression node) {
     _node = node;
 }
                protected override Expression VisitGoto(GotoExpression node)
                {
                    if (!_labels.Contains(node.Target))
                    {
                        if (!LeaveLabels.ContainsKey(node.Target))
                        {
                            LeaveLabels.Add(node.Target, LeaveLabels.Count + 1);
                        }
                    }

                    return base.VisitGoto(node);
                }
Esempio n. 16
0
        /// <summary>
        /// Creates a row comparer for one or more columns
        /// </summary>
        /// <param name="columns">One type for each column, with true for asc and false for desc sort order</param>
        /// <returns></returns>
        public Func <object[][], int, int, int> CreateComparer(params KeyValuePair <Type, bool>[] columns)
        {
            if (columns == null || columns.Length == 0)
            {
                throw new ArgumentNullException("columns");
            }
            var arg0          = Linq.Expression.Parameter(typeof(object[][]), "columns");
            var arg1          = Linq.Expression.Parameter(typeof(int), "firstRowIdx");
            var arg2          = Linq.Expression.Parameter(typeof(int), "secondRowIdx");
            var nullConstant  = Linq.Expression.Constant(null);
            var equalConstant = Linq.Expression.Constant(0);
            var returnLabel   = Linq.Expression.Label(typeof(int), "Result");

            var returnGreater = Linq.Expression.Return(returnLabel, Linq.Expression.Constant(1), returnLabel.Type);
            var returnLess    = Linq.Expression.Return(returnLabel, Linq.Expression.Constant(-1), returnLabel.Type);

            //Gotos to move to next comparison block on equality
            var labels = new Linq.GotoExpression[columns.Length + 1];

            for (int i = 0; i < columns.Length; i++)
            {
                labels[i] = Linq.Expression.Goto(Linq.Expression.Label("Column" + i));
            }
            //Return equality
            labels[labels.Length - 1] = Linq.Expression.Return(returnLabel, equalConstant, returnLabel.Type);

            var comparisons = new Linq.Expression[columns.Length + 1];

            for (int i = 0; i < columns.Length; i++)
            {
                var type        = columns[i].Key;
                var isAscending = columns[i].Value;

                var thisLabel      = labels[i].Target;
                var valuesAreEqual = labels[i + 1];

                var column           = Linq.Expression.ArrayAccess(arg0, Linq.Expression.Constant(i));
                var firstValue       = Linq.Expression.ArrayAccess(column, arg1);
                var secondValue      = Linq.Expression.ArrayAccess(column, arg2);
                var typedFirstValue  = type.IsValueType ? Linq.Expression.Unbox(firstValue, type) : Linq.Expression.Convert(firstValue, typeof(string));
                var typedSecondValue = type.IsValueType ? Linq.Expression.Unbox(secondValue, type) : Linq.Expression.Convert(secondValue, typeof(string));

                var firstValueIsNull          = Linq.Expression.ReferenceEqual(firstValue, nullConstant);
                var secondValueIsNull         = Linq.Expression.ReferenceEqual(secondValue, nullConstant);
                var bothValuesAreSameInstance = Linq.Expression.ReferenceEqual(firstValue, secondValue);

                var returnFirstIsLess    = isAscending ? returnLess : returnGreater;
                var returnFirstIsGreater = isAscending ? returnGreater : returnLess;

                Linq.Expression typedFinalCheck;
                if (type.IsValueType)
                {
                    //Value types have less than operator
                    typedFinalCheck = Linq.Expression.IfThenElse(
                        Linq.Expression.LessThan(typedFirstValue, typedSecondValue),
                        returnFirstIsLess,
                        returnFirstIsGreater);
                }
                else
                {
                    //Strings require one of the static string.CompareXXX() calls
                    Linq.Expression stringCompare = Linq.Expression.Call(_CompareOrdinal, typedFirstValue, typedSecondValue);
                    if (!isAscending)
                    {
                        stringCompare = Linq.Expression.Negate(stringCompare);
                    }
                    typedFinalCheck = Linq.Expression.Return(returnLabel, stringCompare);
                }

                var block = Linq.Expression.Block(
                    Linq.Expression.Label(thisLabel),
                    //if both null or same string instance then are equal so try next column (or return equal)
                    Linq.Expression.IfThen(bothValuesAreSameInstance, valuesAreEqual),
                    //if first is null then less
                    Linq.Expression.IfThen(firstValueIsNull, returnFirstIsLess),
                    //if second is null then greater
                    Linq.Expression.IfThen(secondValueIsNull, Linq.Expression.Return(returnLabel, returnFirstIsGreater)),
                    //if unboxed values are equal try next column (or return equal)
                    Linq.Expression.IfThen(Linq.Expression.Equal(typedFirstValue, typedSecondValue), valuesAreEqual),
                    //final typed check
                    typedFinalCheck
                    );

                comparisons[i] = block;
            }

            //Put in return label
            comparisons[comparisons.Length - 1] = Linq.Expression.Label(returnLabel, equalConstant);

            //And form the final expression
            var res = Linq.Expression.Lambda(Linq.Expression.Block(comparisons), arg0, arg1, arg2);

            return((Func <object[][], int, int, int>)res.Compile());
        }
                protected override Expression VisitGoto(GotoExpression node)
                {
                    var value = Visit(node.Value);

                    var jumpIndex = default(int);
                    if (_leaveLabels.TryGetValue(node.Target, out jumpIndex))
                    {
                        var type = typeof(void);

                        if (node.Value != null)
                        {
                            type = node.Value.Type;
                        }

                        var res = type == typeof(void) ? (Expression)Expression.Constant(null) : Expression.Convert(value, typeof(object));
                        return Expression.Goto(_leaveLabel, Expression.New(s_leaveCtor, Expression.Constant(jumpIndex), res));
                    }

                    return base.VisitGoto(node);
                }
 protected internal virtual new Expression VisitGoto(GotoExpression node)
 {
     return(default(Expression));
 }
 protected override Expression VisitGoto(GotoExpression node)
 {
     var val = Visit(node.Value);
     AddParameter(val);
     return null;
 }
Esempio n. 20
0
        protected internal virtual new Expression VisitGoto(GotoExpression node)
        {
            Contract.Requires(node != null);

            return(default(Expression));
        }
        protected override Expression VisitGoto(GotoExpression node)
        {
            var info = default(LabelInfo);
            if (TryGetLabelInfo(node.Target, out info))
            {
                var variable = info.Value;
                var newTarget = info.Target;

                var res =
                    Expression.Block(
                        Expression.Assign(variable, node.Value),
                        Expression.Goto(newTarget, node.Type)
                    );

                return res;
            }

            return base.VisitGoto(node);
        }
    public virtual bool IsEvaluatableGoto (GotoExpression node)
    {
      ArgumentUtility.CheckNotNull ("node", node);

      return true;
    }
Esempio n. 23
0
 protected internal override Expression VisitGoto(GotoExpression node)
 {
     Expressions.Add(node);
     return(base.VisitGoto(node));
 }
Esempio n. 24
0
 public GotoExpressionProxy(GotoExpression node)
 {
     _node = node;
 }
Esempio n. 25
0
 public GotoExpressionProxy(GotoExpression node)
 {
     ArgumentNullException.ThrowIfNull(node);
     _node = node;
 }
        protected override Expression VisitGoto(GotoExpression expression)
        {
            GotoExpression current;
            if (!TryGetCurrent(expression, out current))
            {
                return expression;
            }

            if (!(this.result &= current.Type == expression.Type))
            {
                return expression;
            }

            if (!(this.result &= current.NodeType == expression.NodeType))
            {
                return expression;
            }

            if (!(this.result &= current.Kind == expression.Kind))
            {
                return expression;
            }

            this.currentObject = current.Value;
            this.Visit(expression.Value);
            if (!this.result)
            {
                return expression;
            }

            this.currentObject = current.Target;
            this.VisitLabelTarget(expression.Target);
            if (!this.result)
            {
                return expression;
            }

            this.currentObject = current;
            return expression;
        }
Esempio n. 27
0
 protected override Expression VisitGoto(GotoExpression node) {
     if (node.Target == CallSiteBinder.UpdateLabel) {
         return Binder.Defer(Arguments).Expression;
     }
     return base.Visit(node);
 }
Esempio n. 28
0
 private Variable VisitGoto(GotoExpression node)
 {
     throw new NotSupportedException("Expression of type " + node.NodeType + " is not supported");
     //this.Out(node.Kind.ToString().ToLower(CultureInfo.CurrentCulture));
     //this.DumpLabel(node.Target);
     //if (node.Value != null)
     //{
     //    this.Out(" (");
     //    this.Visit(node.Value);
     //    this.Out(") ");
     //}
 }
Esempio n. 29
0
 public GotoExpressionProxy(GotoExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
        protected override Expression VisitGoto(GotoExpression node)
        {
            // NB: We ignore classifying by Kind to distinguish Break from Continue;
            //     after all, the user can cheat about the goto kind and still achieve
            //     the branching to take place.

            MarkLoopLabel(node.Target);

            return base.VisitGoto(node);
        }
Esempio n. 31
0
        protected override Expression VisitGoto(GotoExpression node)
        {
            if (node.Kind == GotoExpressionKind.Return)
            {
                if (node.Value == null)
                {
                    this.WriteLine("return");
                }
                else
                {
                    this.Write("return ");
                    this.Visit(node.Value);
                }
            }
            else if (node.Kind == GotoExpressionKind.Continue)
            {
                this.Write("continue");
            }

            return node;
        }
Esempio n. 32
0
 public GoToVisitor(GotoExpression node) : base(node)
 {
     this.node = node;
 }
Esempio n. 33
0
 protected virtual Expression VisitGoto(GotoExpression node)
 {
     throw new NotImplementedException();
 }
Esempio n. 34
0
 private static string VisitGoto(GotoExpression node)
 {
     throw new NotImplementedException();
 }
 protected override Expression VisitGoto(GotoExpression expression)
 {
     this.hashCode ^= expression.Target?.GetHashCode() ?? 0;
     this.hashCode ^= expression.Kind.GetHashCode();
     return base.VisitGoto(expression);
 }