예제 #1
0
        public void UpdateNotSameReturnsNotSame()
        {
            Expression           expression = Expression.Constant(0);
            TypeBinaryExpression typeExp    = Expression.TypeEqual(expression, typeof(int));

            Assert.NotSame(typeExp, typeExp.Update(Expression.Constant(0)));
        }
예제 #2
0
        public void UpdateSameReturnsSame()
        {
            Expression           expression = Expression.Constant(0);
            TypeBinaryExpression typeExp    = Expression.TypeIs(expression, typeof(int));

            Assert.Same(typeExp, typeExp.Update(expression));
        }
예제 #3
0
        public void UpdateSameReturnsSame()
        {
            Expression           expression = Expression.Constant(0);
            TypeBinaryExpression typeExp    = Expression.TypeEqual(expression, typeof(int));

            Assert.Same(typeExp, typeExp.Update(expression));
            Assert.Same(typeExp, NoOpVisitor.Instance.Visit(typeExp));
        }
        protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExpression)
        {
            // This is for "x is y"
            var visitedExpression = Visit(typeBinaryExpression.Expression);
            var visitedTypeBinary = typeBinaryExpression.Update(Unwrap(visitedExpression));

            return(visitedExpression is EntityReferenceExpression entityWrapper
                ? entityWrapper.Update(visitedTypeBinary)
                : (Expression)visitedTypeBinary);
        }
예제 #5
0
        protected override Expression VisitTypeBinary(TypeBinaryExpression node)
        {
            var exp = Visit(node.Expression);

            if (exp != node.Expression)
            {
                return(node.Update(exp));
            }
            return(node);
        }
예제 #6
0
        protected override Expression VisitTypeBinary(TypeBinaryExpression node)
        {
            var visitedExpression = Visit(node.Expression);

            if (visitedExpression is ConstantExpression || visitedExpression is ParameterExpression)
            {
                if (node.TypeOperand.IsAssignableFrom(visitedExpression.Type))
                {
                    return(Expression.Constant(true));
                }
                else if (!visitedExpression.Type.IsAssignableFrom(node.TypeOperand))
                {
                    return(Expression.Constant(false));
                }
            }

            return(node.Update(visitedExpression));
        }
            protected override Expression VisitTypeBinary(TypeBinaryExpression node)
            {
                var e = Visit(node.Expression);

                var es = _tilingState.Pop();

                if (es)
                {
                    _tilingState.Push(true);
                }
                else
                {
                    _tilingState.Push(false);

                    EvaluateIf(es, ref e);
                }

                return(node.Update(e));
            }
        public T?Simplify <T>(T?expression) where T : Expression
        {
            if (expression is null)
            {
                return(null);
            }
            Expression expr = expression.Reduce() switch
            {
                UnaryExpression unaryExpr => unaryExpr.Update(Simplify(unaryExpr.Operand)),
                BinaryExpression binaryExpr => binaryExpr.Update(Simplify(binaryExpr.Left), binaryExpr.Conversion, Simplify(binaryExpr.Right)),
                LambdaExpression lambdaExpr => Expression.Lambda(Simplify(lambdaExpr.Body), lambdaExpr.Name, lambdaExpr.TailCall, Simplify(lambdaExpr.Parameters)),
                TryExpression tryExpr => tryExpr.Update(Simplify(tryExpr.Body), Simplify(tryExpr.Handlers), Simplify(tryExpr.Finally), Simplify(tryExpr.Fault)),
                NewExpression newExpr => newExpr.Update(Simplify(newExpr.Arguments)),
                GotoExpression gotoExpr => gotoExpr.Update(gotoExpr.Target, Simplify(gotoExpr.Value)),
                LoopExpression loopExpr => loopExpr.Update(loopExpr.BreakLabel, loopExpr.ContinueLabel, Simplify(loopExpr.Body)),
                BlockExpression blockExpr => blockExpr.Update(Simplify(blockExpr.Variables), Simplify(blockExpr.Expressions)),
                IndexExpression indexExpr => indexExpr.Update(Simplify(indexExpr.Object) !, Simplify(indexExpr.Arguments)),
                LabelExpression labelExpr => labelExpr.Update(labelExpr.Target, Simplify(labelExpr.DefaultValue)),
                MemberExpression memberExpr => memberExpr.Update(Simplify(memberExpr.Expression)),
                SwitchExpression switchExpr => switchExpr.Update(Simplify(switchExpr.SwitchValue), Simplify(switchExpr.Cases), Simplify(switchExpr.DefaultBody)),
                DynamicExpression dynamicExpr => dynamicExpr.Update(Simplify(dynamicExpr.Arguments)),
                ListInitExpression listInitExpr => listInitExpr.Update(Simplify(listInitExpr.NewExpression), Simplify(listInitExpr.Initializers)),
                NewArrayExpression newArrayExpr => newArrayExpr.Update(Simplify(newArrayExpr.Expressions)),
                InvocationExpression invokeExpr => invokeExpr.Update(Simplify(invokeExpr.Expression), Simplify(invokeExpr.Arguments)),
                MemberInitExpression memberInitExpr => memberInitExpr.Update(Simplify(memberInitExpr.NewExpression), memberInitExpr.Bindings),
                MethodCallExpression methodCallExpr => methodCallExpr.Update(Simplify(methodCallExpr.Object), Simplify(methodCallExpr.Arguments)),
                TypeBinaryExpression typeBinaryExpr => typeBinaryExpr.Update(Simplify(typeBinaryExpr.Expression)),
                ConditionalExpression condExpr => condExpr.Update(Simplify(condExpr.Test), Simplify(condExpr.IfTrue), Simplify(condExpr.IfFalse)),
                RuntimeVariablesExpression runtimeVarExpr => runtimeVarExpr.Update(Simplify(runtimeVarExpr.Variables)),
                _ => expression
            };

            foreach (var transform in transformers)
            {
                expr = transform.Transform(expr, this);
            }

            return((T)expr);
        }
예제 #9
0
 /// <summary>
 /// Visits the children of the <see cref="TypeBinaryExpression" />.
 /// </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 VisitTypeBinary(TypeBinaryExpression node)
 {
     return(node.Update(Visit(node.Expression)));
 }
예제 #10
0
 static TypeBinaryExpression MutateTypeBinary(TypeBinaryExpression node, IList <Expression> operands)
 {
     return(node.Update(operands[0]));
 }
예제 #11
0
        /// <summary>
        /// 访问 <see cref="TypeBinaryExpression"/>。
        /// </summary>
        /// <param name="typeBinExp">要访问的表达式。</param>
        /// <returns></returns>
        protected virtual Expression VisitTypeBinary(TypeBinaryExpression typeBinExp)
        {
            var exp = Visit(typeBinExp.Expression);

            return(typeBinExp.Update(exp, typeBinExp.TypeOperand));
        }
예제 #12
0
 protected virtual Expression VisitTypeBinary(TypeBinaryExpression expr)
 {
     return(expr.Update(Visit(expr.Expression)));
 }
예제 #13
0
 /// <summary>
 /// Visits the children of the <see cref="TypeBinaryExpression"/>.
 /// </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 override Expression VisitTypeBinary(TypeBinaryExpression node)
 {
     return(node.Update(Visit(node.Expression)));
 }
 private static Expression SetChildren(ReadOnlySpan <Expression> newChildren, TypeBinaryExpression t)
 => t.Update(newChildren[0]);
예제 #15
0
 TypeBinaryExpression Convert(TypeBinaryExpression expr)
 {
     return(expr.Update(Process(expr.Expression))); // TypeOperand
 }
 protected virtual Expression VisitTypeBinary(TypeBinaryExpression node, Type expectedType)
 => node.Update(Visit(node.Expression, null));