/// <summary>
 /// Gets the reduced expression.
 /// </summary>
 /// <param name="expressionRewriter">The expression rewriter.</param>
 /// <returns>
 /// A <see cref="Expression" />.
 /// </returns>
 public Expression GetReducedExpression(IExpressionRewriter expressionRewriter)
 {
     return(expressionRewriter.Rewrite(
                this.expression,
                this.reduceByBaseUnit,
                this.FlatRepresentation.GetConsumer()));
 }
 protected override void establish_context()
 {
     base.establish_context();
     expression = Expression.Constant(this);
     rewriter = MockRepository.GenerateStub<IExpressionRewriter>();
     system_under_test.AddRewriter(rewriter);
 }
Пример #3
0
 /// <summary>
 /// Gets the reduced expression.
 /// </summary>
 /// <param name="expressionRewriter">The expression rewriter.</param>
 /// <returns>
 /// A <see cref="Expression" />.
 /// </returns>
 public Expression GetReducedExpression(IExpressionRewriter expressionRewriter)
 {
     return expressionRewriter.Rewrite(
         this.expression,
         this.reduceByBaseUnit,
         this.FlatRepresentation.GetConsumer());
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnitFactory" /> class.
 /// </summary>
 /// <param name="expressionToFlatRepresentationConverter">The expression to flat representation converter.</param>
 /// <param name="expressionRewriter">The expression rewriter.</param>
 /// <param name="derivedUnitRegistry">The derived unit registry.</param>
 public UnitFactory(
     IExpressionToFlatRepresentationConverter expressionToFlatRepresentationConverter,
     IExpressionRewriter expressionRewriter,
     IDerivedUnitRegistry derivedUnitRegistry)
 {
     this.expressionToFlatRepresentationConverter = expressionToFlatRepresentationConverter;
     this.expressionRewriter  = expressionRewriter;
     this.derivedUnitRegistry = derivedUnitRegistry;
 }
Пример #5
0
        /// <summary>
        /// Rewrites the expression specified by <paramref name="expression"/>
        /// with the rewriter specified by <paramref name="rewriter"/>.
        /// </summary>
        /// <typeparam name="TType">
        /// Specifies the parameter type in the expression.
        /// </typeparam>
        /// <param name="expression">
        /// Specifies the expression.
        /// </param>
        /// <param name="rewriter">
        /// Specifies the rewriter.
        /// </param>
        /// <returns>
        /// The converted expression.
        /// </returns>
        public static Expression <Action <TType> > RewriteUsing <TType>(
            this Expression <Action <TType> > expression,
            IExpressionRewriter rewriter)
        {
            Guard.AgainstArgumentNull(expression, "expression");
            Guard.AgainstArgumentNull(rewriter, "rewriter");

            return(rewriter.Rewrite(expression) as Expression <Action <TType> >);
        }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnitFactory" /> class.
 /// </summary>
 /// <param name="expressionToFlatRepresentationConverter">The expression to flat representation converter.</param>
 /// <param name="expressionRewriter">The expression rewriter.</param>
 /// <param name="derivedUnitRegistry">The derived unit registry.</param>
 public UnitFactory(
     IExpressionToFlatRepresentationConverter expressionToFlatRepresentationConverter,
     IExpressionRewriter expressionRewriter,
     IDerivedUnitRegistry derivedUnitRegistry)
 {
     this.expressionToFlatRepresentationConverter = expressionToFlatRepresentationConverter;
     this.expressionRewriter = expressionRewriter;
     this.derivedUnitRegistry = derivedUnitRegistry;
 }
Пример #7
0
            /// <summary>
            /// Visits the children of the <see cref="MethodCallExpression"/>.
            /// </summary>
            /// <param name="methodCallExpr">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 VisitMethodCall(MethodCallExpression methodCallExpr)
            {
                RewriterMarkerMethodAttribute markerAttribute = methodCallExpr.Method
                                                                .GetCustomAttributes(typeof(RewriterMarkerMethodAttribute), false)
                                                                .Cast <RewriterMarkerMethodAttribute>()
                                                                .FirstOrDefault();

                if (markerAttribute == null)
                {
                    return(base.VisitMethodCall(methodCallExpr));
                }

                IExpressionRewriter rewriter = markerAttribute.CreateRewriter();

                return(Visit(rewriter.RewriteMethodCall(methodCallExpr)));
            }
Пример #8
0
        private Expression TransformExpression(
            Expression expression,
            ITransformationContext context,
            TransformationStepRecorder recorder)
        {
            expression = this.PreprocessExpression(expression, context);

            if (context.IsFinished)
            {
                return(expression);
            }

            // Set up the rewriter chain
            IList <IExpressionRewriter> allRewriters =
                new IExpressionRewriter[]
            {
                new DatabaseParameterRewriter(context),
                new StoredProcedureParameterRewriter(context),
            }
            .Concat(
                this.GetRewriters(expression, context))
            .Concat(new IExpressionRewriter[]
            {
                new TableScanRewriter(),
                new QueryableRewriter()
            })
            .ToList();

            // Initialize rewriters
            foreach (IDatabaseComponent databaseComponent in allRewriters)
            {
                databaseComponent.Initialize(this.database);
            }

            // Last chance to alter rewriters
            allRewriters = this.ReviewRewriters(allRewriters);

            // Record the initial state
            recorder.Record(new TransformationStep(expression));

            // Execute rewriters
            foreach (IExpressionRewriter rewriter in allRewriters)
            {
                if (rewriter == null)
                {
                    continue;
                }

                expression = rewriter.Rewrite(expression);
                recorder.Record(new TransformationStep(expression));
            }

            expression = this.PostprocessExpression(expression, context);
            recorder.Record(new TransformationStep(expression));

            // Reduce the expression
            while (expression.CanReduce)
            {
                expression = expression.Reduce();
                recorder.Record(new TransformationStep(expression));
            }

            return(expression);
        }
 public ExpressionRewriterTester(Expression expression, IExpressionRewriter transformer)
 {
     _original = expression;
     _rewritten = transformer.Rewrite(expression);
 }
        /// <summary>
        /// Creates a new instance of the <see cref="RewritingFakeEngine" /> class.
        /// </summary>
        /// <param name="rewriter">
        /// Specifies the rewriter that translates the expressions or more
        /// specific the generic inline constraints used in expressions
        /// to the inline constraints used in the target fake framework.
        /// </param>
        protected RewritingFakeEngine(IExpressionRewriter rewriter)
        {
            Guard.AgainstArgumentNull(rewriter, "rewriter");

            _rewriter = rewriter;
        }