protected override Expression VisitUnary(UnaryExpression node) { // For OpAssign nodes: if has a yield, we need to do the generator // transformation on the reduced value. if (node.CanReduce) { return(Visit(node.Reduce())); } int yields = _yields.Count; Expression o = Visit(node.Operand); if (o == node.Operand) { return(node); } // Void convert can be jumped into, no need to spill // TODO: remove when that feature goes away. if (yields == _yields.Count || (node.NodeType == ExpressionType.Convert && node.Type == typeof(void))) { return(Expression.MakeUnary(node.NodeType, o, node.Type, node.Method)); } return(Expression.Block( ToTemp(ref o), Expression.MakeUnary(node.NodeType, o, node.Type, node.Method) )); }
private Node ResolveQuery <T>(UnaryExpression unaryExpression) { var exptype = unaryExpression.NodeType; switch (exptype) { case ExpressionType.Convert: if (unaryExpression.Method != null) { return(ResolveQuery <T>(unaryExpression.Reduce() as MethodCallExpression)); } return(ResolveQuery <T>((dynamic)unaryExpression.Operand)); break; default: return(new SingleOperationNode() { Operator = unaryExpression.NodeType, Child = ResolveQuery((dynamic)unaryExpression.Operand) }); break; } //return new SingleOperationNode() //{ // Operator = unaryExpression.NodeType, // Child = ResolveQuery((dynamic)unaryExpression.Operand) //}; }
public void CannotReduceThrow() { UnaryExpression throwExp = Expression.Throw(Expression.Constant(new TestException())); Assert.False(throwExp.CanReduce); Assert.Same(throwExp, throwExp.Reduce()); Assert.Throws <ArgumentException>(() => throwExp.ReduceAndCheck()); }
protected override Expression VisitUnary(UnaryExpression node) { if (node.CanReduce) { return(this.Visit(node.Reduce())); } return(base.VisitUnary(node)); }
protected override Expression VisitUnary(UnaryExpression node) { // reduce inplace increment/decrement: if (node.CanReduce) { return(Visit(node.Reduce())); } Debug.Assert(!node.NodeType.IsReadWriteAssignment()); return(base.VisitUnary(node)); }
protected override Expression VisitUnary(UnaryExpression node) { // NB: This reduces assignment operators so that the stack spiller doesn't have to worry about it. if (node.CanReduce) { return(node.Reduce()); } return(base.VisitUnary(node)); }