Example #1
0
        public static Expression Evaluate(Expression node)
        {
            var candidates = Nominator.Nominate(node);
            var evaluator  = new PartialEvaluator(candidates);

            return(evaluator.Visit(node));
        }
Example #2
0
        public static Expression PartialEval(Expression expression)
        {
            Nominator        nominator = new Nominator();
            SubtreeEvaluator evaluator = new SubtreeEvaluator(nominator.Nominate(expression));

            return(evaluator.Eval(expression));
        }
Example #3
0
        /// <summary>
        /// Performs evaluation and replacement of independent sub-trees
        /// </summary>
        /// <param name="expression">The root of the expression tree.</param>
        /// <param name="canBeEvaluated">A function that decides whether a given expression node can be part of the local function.</param>
        /// <returns>A new tree with sub-trees evaluated and replaced.</returns>
        internal static Expression PartialEval(Expression expression, Func <Expression, bool> canBeEvaluated)
        {
            Nominator            nominator  = new Nominator(canBeEvaluated);
            HashSet <Expression> candidates = nominator.Nominate(expression);

            return(new SubtreeEvaluator(candidates).Eval(expression));
        }
Example #4
0
        /// <summary>
        ///     Performs evaluation & replacement of independent sub-trees
        /// </summary>
        /// <param name="expression"> The root of the expression tree. </param>
        /// <param name="fnCanBeEvaluated"> A function that decides whether a given expression node can be part of the local function. </param>
        /// <returns> A new tree with sub-trees evaluated and replaced. </returns>
        public static Expression PartialEval(Expression expression, Func <Expression, bool> fnCanBeEvaluated)
        {
            var nominator        = new Nominator(fnCanBeEvaluated);
            var subtreeEvaluator = new SubtreeEvaluator(nominator.Nominate(expression));

            return(subtreeEvaluator.Eval(expression));
        }
Example #5
0
 /// <summary>
 /// Performs evaluation & replacement of independent sub-trees
 /// </summary>
 /// <param name="expression">The root of the expression tree.</param>
 /// <param name="fnCanBeEvaluated">A function that decides whether a given expression node can be part of the local function.</param>
 /// <returns>A new tree with sub-trees evaluated and replaced.</returns>
 private static Expression Eval(Expression expression, Func <Expression, bool> fnCanBeEvaluated)
 {
     if (fnCanBeEvaluated == null)
     {
         fnCanBeEvaluated = PartialEvaluator.CanBeEvaluatedLocally;
     }
     return(SubtreeEvaluator.Eval(Nominator.Nominate(fnCanBeEvaluated, expression), expression));
 }
 /// <summary>
 /// Performs evaluation replacement of independent sub-trees
 /// </summary>
 /// <param name="expression">The root of the expression tree.</param>
 /// <param name="fnCanBeEvaluated">A function that decides whether a given expression node can be part of the local function.</param>
 /// <returns>A new tree with sub-trees evaluated and replaced.</returns>
 public static Expression Eval(System.Linq.Expressions.Expression expression, Func <System.Linq.Expressions.Expression, bool> fnCanBeEvaluated)
 {
     if (fnCanBeEvaluated == null)
     {
         fnCanBeEvaluated = AtkPartialEvaluator.CanBeEvaluatedLocally;
     }
     return(SubtreeEvaluator.Eval(Nominator.Nominate(fnCanBeEvaluated, expression), expression));
 }
 public static Expression Eval(Expression expression, Func <Expression, bool> fnCanBeEvaluated, Func <ConstantExpression, Expression> fnPostEval)
 {
     if (fnCanBeEvaluated == null)
     {
         fnCanBeEvaluated = PartialEvaluator.CanBeEvaluatedLocally;
     }
     return(SubtreeEvaluator.Eval(Nominator.Nominate(fnCanBeEvaluated, expression), fnPostEval, expression));
 }
 private ColumnProjector(Func <Expression, bool> fnCanBeColumn, Expression expression, string newAlias, TextWriter logger, params string[] existingAliases) : base(logger)
 {
     this.newAlias        = newAlias;
     this.existingAliases = existingAliases;
     this.map             = new Dictionary <ColumnExpression, ColumnExpression>();
     this.columns         = new List <ColumnDeclaration>();
     this.columnNames     = new HashSet <string>();
     this.candidates      = Nominator.Nominate(fnCanBeColumn, expression, logger);
 }
Example #9
0
            /// <summary>

            /// Performs evaluation & replacement of independent sub-trees

            /// </summary>

            /// <param name="expression">The root of the expression tree.</param>

            /// <param name="fnCanBeEvaluated">A function that decides whether a given expression node can be part of the local function.</param>

            /// <returns>A new tree with sub-trees evaluated and replaced.</returns>

            public static Expression PartialEval(Expression expression, Func <Expression, bool> fnCanBeEvaluated)
            {
                var nominator = new Nominator(fnCanBeEvaluated);

                var candidates = nominator.Nominate(expression);

                var subtreeEvaluator = new SubtreeEvaluator(candidates);

                var newExpression = subtreeEvaluator.Eval(expression);

                return(newExpression);
            }
Example #10
0
 private ColumnProjector(Func <Expression, bool> fnCanBeColumn, Expression expression, IEnumerable <ColumnDeclaration> existingColumns, TableAlias newAlias, IEnumerable <TableAlias> existingAliases)
 {
     this.newAlias        = newAlias;
     this.existingAliases = new HashSet <TableAlias>(existingAliases);
     this.map             = new Dictionary <ColumnExpression, ColumnExpression>();
     if (existingColumns != null)
     {
         this.columns     = new List <ColumnDeclaration>(existingColumns);
         this.columnNames = new HashSet <string>(existingColumns.Select(c => c.Name));
     }
     else
     {
         this.columns     = new List <ColumnDeclaration>();
         this.columnNames = new HashSet <string>();
     }
     this.candidates = Nominator.Nominate(fnCanBeColumn, expression);
 }
Example #11
0
 private ColumnProjector(Expression expression, IEnumerable <ColumnDeclaration> existingColumns, TableAlias newAlias, IEnumerable <TableAlias> existingAliases)
 {
     this.newAlias        = newAlias;
     this.existingAliases = new HashSet <TableAlias>(existingAliases, TableAlias.Comparer);
     this.map             = new Dictionary <ColumnExpression, ColumnExpression>();
     if (existingColumns != null)
     {
         this.columns     = new List <ColumnDeclaration>(existingColumns);
         this.columnNames = new HashSet <string>(existingColumns.Select(c => c.Name), StringComparer.Ordinal);
     }
     else
     {
         this.columns     = new List <ColumnDeclaration>();
         this.columnNames = new HashSet <string>(StringComparer.Ordinal);
     }
     this.candidates = Nominator.Nominate(expression);
 }
Example #12
0
 private ColumnProjector(QueryLanguage language, ProjectionAffinity affinity, Expression expression, IEnumerable <ColumnDeclaration> existingColumns, TableAlias newAlias, IEnumerable <TableAlias> existingAliases)
 {
     this.language        = language;
     this.newAlias        = newAlias;
     this.existingAliases = new HashSet <TableAlias>(existingAliases);
     this.map             = new Dictionary <ColumnExpression, ColumnExpression>();
     if (existingColumns != null)
     {
         this.columns     = new List <ColumnDeclaration>(existingColumns);
         this.columnNames = new HashSet <string>(existingColumns.Select(c => c.Name));
     }
     else
     {
         this.columns     = new List <ColumnDeclaration>();
         this.columnNames = new HashSet <string>();
     }
     this.candidates = Nominator.Nominate(language, affinity, expression);
 }
Example #13
0
 /// <summary>
 /// Performs evaluation & replacement of independent sub-trees
 /// </summary>
 /// <param name="expression">The root of the expression tree.</param>
 /// <param name="fnCanBeEvaluated">A function that decides whether a given expression node can be part of the local function.</param>
 /// <returns>A new tree with sub-trees evaluated and replaced.</returns>
 public static Expression PartialEval(Expression expression, IExpressionEvaluator evaluator, Func <Expression, bool> fnCanBeEvaluated)
 => new SubtreeEvaluator(evaluator, Nominator.Nominate(expression, fnCanBeEvaluated)).Eval(expression);
Example #14
0
 /// <summary>
 /// Performs evaluation and replacement of independent sub-trees
 /// </summary>
 /// <param name="expression">The root of the expression tree.</param>
 /// <param name="fnCanBeEvaluated">A function that decides whether a given expression node can be part of the local function.</param>
 /// <returns>A new tree with sub-trees evaluated and replaced.</returns>
 public static Expression Eval(Expression expression, Func <Expression, bool> fnCanBeEvaluated)
 {
     return(SubtreeEvaluator.Eval(Nominator.Nominate(fnCanBeEvaluated, expression), expression));
 }
Example #15
0
 internal static Expression PartialEval(Expression expression, Func<Expression, bool> canBeEvaluated)
 {
     Nominator nominator = new Nominator(canBeEvaluated);
     return new SubtreeEvaluator(nominator.Nominate(expression)).Eval(expression);
 }
Example #16
0
 internal ColumnProjector(Expression expression, string newAlias, IEnumerable <string> existingAliases)
 {
     _candidates = Nominator.Nominate(existingAliases, expression);
     _newAlias   = newAlias;
 }
Example #17
0
        /// <summary>
        /// Performs evaluation & replacement of independent sub-trees
        /// </summary>
        /// <param name="expression">The root of the expression tree.</param>
        /// <param name="fnCanBeEvaluated">A function that decides whether a given expression node can be part of the local function.</param>
        /// <returns>A new tree with sub-trees evaluated and replaced.</returns>

        public static Expression PartialEval(Expression expression, Func <Expression, bool> fnCanBeEvaluated, TextWriter logger)
        {
            return(SubtreeEvaluator.Eval(Nominator.Nominate(fnCanBeEvaluated, expression, logger), expression, logger));
        }
Example #18
0
 /// <summary>
 ///     Performs evaluation & replacement of independent sub-trees
 /// </summary>
 /// <param name="expression"> The root of the expression tree. </param>
 /// <param name="fnCanBeEvaluated"> A function that decides whether a given expression node can be part of the local function. </param>
 /// <returns> A new tree with sub-trees evaluated and replaced. </returns>
 public static Expression PartialEval(Expression expression, Func<Expression, bool> fnCanBeEvaluated) {
     var nominator = new Nominator(fnCanBeEvaluated);
     var subtreeEvaluator = new SubtreeEvaluator(nominator.Nominate(expression));
     return subtreeEvaluator.Eval(expression);
 }
Example #19
0
 /// <summary>
 /// Performs evaluation & replacement of independent sub-trees
 /// </summary>
 /// <param name="expression">The root of the expression tree.</param>
 /// <param name="fnCanBeEvaluated">
 /// A function that decides whether a given expression node can be part of the local
 /// function.
 /// </param>
 /// <returns>A new tree with sub-trees evaluated and replaced.</returns>
 static public Expression PartialEval(Expression expression, Func <Expression, bool> fnCanBeEvaluated)
 {
     return(SubtreeEvaluator.Eval(expression, Nominator.Nominate(fnCanBeEvaluated, expression)));
 }
Example #20
0
 public static Expression PartialEval(Expression expression)
 {
     Nominator nominator = new Nominator();
     SubtreeEvaluator evaluator = new SubtreeEvaluator(nominator.Nominate(expression));
     return evaluator.Eval(expression);
 }