Optimize() abstract private method

abstract private Optimize ( ) : ExpressionNode
return ExpressionNode
コード例 #1
0
        /// <include file='doc\DataExpression.uex' path='docs/doc[@for="DataExpression.Bind"]/*' />
        public virtual void Bind(DataTable table)
        {
#if DEBUG
            if (CompModSwitches.DataExpression.TraceVerbose)
            {
                Debug.WriteLine("Bind current expression in the table " + (table != null ? table.TableName : "null"));
            }
#endif
            this.table = table;

            if (table == null)
            {
                return;
            }

            if (expr != null)
            {
                Debug.Assert(parsed, "Invalid calling order: Bind() before Parse()");
                ArrayList list = new ArrayList();
                expr.Bind(table, list);
                expr                = expr.Optimize();
                this.table          = table;
                optimizedExpression = null;
                Debug.Assert(list != null, "Invlid dependency list");
                bound      = true;
                dependency = new DataColumn[list.Count];
                list.CopyTo(dependency, 0);

#if DEBUG
                if (dependency == null)
                {
                    if (CompModSwitches.DataExpression.TraceVerbose)
                    {
                        Debug.WriteLine("no dependencies");
                    }
                }
                else
                {
                    if (CompModSwitches.DataExpression.TraceVerbose)
                    {
                        Debug.WriteLine("have dependencies: " + dependency.Length.ToString());
                    }
                    for (int i = 0; i < dependency.Length; i++)
                    {
                        //UNDONE : Debug.WriteLineIf("DataExpression", dependency[i].ColumnName);
                    }
                }
#endif
            }
        }
コード例 #2
0
ファイル: UnaryNode.cs プロジェクト: yangguosdxl/runtime
        internal override ExpressionNode Optimize()
        {
            _right = _right.Optimize();

            if (IsConstant())
            {
                object val = Eval();

                return(new ConstNode(table, ValueType.Object, val, false));
            }
            else
            {
                return(this);
            }
        }
コード例 #3
0
        internal void Bind(DataTable table)
        {
            _table = table;

            if (table == null)
            {
                return;
            }

            if (_expr != null)
            {
                Debug.Assert(_parsed, "Invalid calling order: Bind() before Parse()");
                List <DataColumn> list = new List <DataColumn>();
                _expr.Bind(table, list);
                _expr       = _expr.Optimize();
                _table      = table;
                _bound      = true;
                _dependency = list.ToArray();
            }
        }
コード例 #4
0
        internal override ExpressionNode Optimize()
        {
            left = left.Optimize();

            if (op == Operators.Is)
            {
                // only 'Is Null' or 'Is Not Null' are valid
                if (right is UnaryNode)
                {
                    UnaryNode un = (UnaryNode)right;
                    if (un.op != Operators.Not)
                    {
                        throw ExprException.InvalidIsSyntax();
                    }
                    op    = Operators.IsNot;
                    right = un.right;
                }
                if (right is ZeroOpNode)
                {
                    if (((ZeroOpNode)right).op != Operators.Null)
                    {
                        throw ExprException.InvalidIsSyntax();
                    }
                }
                else
                {
                    throw ExprException.InvalidIsSyntax();
                }
            }
            else
            {
                right = right.Optimize();
            }

#if DEBUG
            if (CompModSwitches.BinaryNode.TraceVerbose)
            {
                Debug.WriteLine("Optimizing " + this.ToString());
            }
#endif

            if (this.IsConstant())
            {
                object val = this.Eval();
#if DEBUG
                if (CompModSwitches.BinaryNode.TraceVerbose)
                {
                    Debug.WriteLine("the node value is " + val.ToString());
                }
#endif

                if (val == DBNull.Value)
                {
                    return(new ZeroOpNode(Operators.Null));
                }

                if (val is bool)
                {
                    if ((bool)val)
                    {
                        return(new ZeroOpNode(Operators.True));
                    }
                    else
                    {
                        return(new ZeroOpNode(Operators.False));
                    }
                }
#if DEBUG
                if (CompModSwitches.BinaryNode.TraceVerbose)
                {
                    Debug.WriteLine(val.GetType().ToString());
                }
#endif
                return(new ConstNode(ValueType.Object, val, false));
            }
            else
            {
                return(this);
            }
        }