Example #1
0
        private IQuery ProcessNode(AstNode root, IQuery qyInput, int parent,
                                   Axis.AxisType parentaxis, ref bool cache, ref bool position)
        {
            IQuery result = null;

            if (root == null)
            {
                return(null);
            }
            switch (root.TypeOfAst)
            {
            case AstNode.QueryType.Axis:
                filterCount = 0;
                firstInput  = null;
                Axis axis = (Axis)root;
                if (axis.TypeOfAxis == Axis.AxisType.Descendant || axis.TypeOfAxis ==
                    Axis.AxisType.DescendantOrSelf)
                {
                    if (_smart > 0)
                    {
                        result = ProcessAxis(
                            axis,
                            ProcessNode(axis.Input,
                                        qyInput, Smart_D,
                                        axis.TypeOfAxis, ref cache, ref position),
                            parent, parentaxis);
                        break;
                    }
                }
                _smart++;
                result = ProcessAxis(
                    axis,
                    ProcessNode(axis.Input,
                                qyInput, Regular_D,
                                axis.TypeOfAxis, ref cache, ref position),
                    parent, parentaxis);
                _smart--;
                break;

            case AstNode.QueryType.Operator:
                _smart = 2;
                result = ProcessOperator((Operator)root, null, ref cache, ref position);
                break;

            case AstNode.QueryType.Filter:
                _smart = 2;
                result = ProcessFilter((Filter)root, ref cache, ref position);
                break;

            case AstNode.QueryType.ConstantOperand:
                result = ProcessOperand((Operand)root);
                break;

            case AstNode.QueryType.Variable:
                result = ProcessVariable((Variable)root);
                break;

            case AstNode.QueryType.Function:
                result = ProcessFunction(
                    (System.Xml.XPath.Function)root,
                    qyInput, ref cache, ref position);
                break;

            case AstNode.QueryType.Group:
                _smart = 2;
                result = new GroupQuery(ProcessNode(
                                            ((System.Xml.XPath.Group)root).GroupNode,
                                            qyInput, Regular_D,
                                            Axis.AxisType.None,
                                            ref cache, ref position));
                break;

            case AstNode.QueryType.Root:
                result = new AbsoluteQuery();
                break;

            default:
                Debug.Assert(false, "Unknown QueryType encountered!!");
                break;
            }
            return(result);
        }
Example #2
0
 private IQuery ProcessNode(AstNode root, IQuery qyInput,int parent, 
                            Axis.AxisType parentaxis, ref bool cache, ref bool position) {
     IQuery result = null;
     if (root == null)
         return null;
     switch (root.TypeOfAst) {
         case AstNode.QueryType.Axis:
             filterCount = 0;
             firstInput = null;
             Axis axis = (Axis)root;
             if (axis.TypeOfAxis == Axis.AxisType.Descendant || axis.TypeOfAxis == 
                 Axis.AxisType.DescendantOrSelf)
                 if (_smart > 0) {
                     result = ProcessAxis(
                                         axis,
                                         ProcessNode(axis.Input, 
                                                     qyInput,Smart_D,
                                                     axis.TypeOfAxis, ref cache, ref position), 
                                                     parent, parentaxis);
                     break;
                 }
             _smart++;
             result = ProcessAxis(
                                 axis,
                                 ProcessNode(axis.Input, 
                                             qyInput,Regular_D,
                                             axis.TypeOfAxis, ref cache, ref position),
                                             parent, parentaxis);
             _smart--;
             break;
         case AstNode.QueryType.Operator:
             _smart = 2;
             result = ProcessOperator((Operator)root, null, ref cache, ref position);
             break;
         case AstNode.QueryType.Filter:
             _smart = 2;
             result = ProcessFilter((Filter)root, ref cache, ref position);
             break;
         case AstNode.QueryType.ConstantOperand:
             result = ProcessOperand((Operand)root);
             break;
         case AstNode.QueryType.Variable:
             result = ProcessVariable((Variable)root);
             break;
         case AstNode.QueryType.Function:
             result = ProcessFunction(
                                     (System.Xml.XPath.Function)root,
                                     qyInput, ref cache, ref position);
             break;
         case AstNode.QueryType.Group:
             _smart = 2;
             result = new GroupQuery(ProcessNode(
                                                ((System.Xml.XPath.Group)root).GroupNode,
                                                qyInput,Regular_D, 
                                                Axis.AxisType.None,
                                                ref cache, ref position));
             break;
         case AstNode.QueryType.Root:
             result = new AbsoluteQuery();
             break;
         default:
             Debug.Assert(false, "Unknown QueryType encountered!!");
             break;
     }
     return result;
 }
Example #3
0
        /*
         * private bool SplitQuery(BaseAxisQuery origQuery, BaseAxisQuery parent, BaseAxisQuery input) {
         *  parent = origQuery as BaseAxisQuery;
         *  if (parent == null || parent is GroupQuery || parent is PositionQuery || parent is OrQuery) {
         *      return false;
         *  }
         *  input = parent = (BaseAxisQuery)parent.Clone();
         *  parent = (BaseAxisQuery) parent.m_qyInput;
         *  while (parent != null && !parent.IsAxis) {
         *      parent = (BaseAxisQuery)parent.m_qyInput;
         *  }
         *  if (parent == null) {
         *      return false;
         *  }
         *  BaseAxisQuery temp = (BaseAxisQuery)parent.m_qyInput;
         *  if (temp == null) {
         *      return false;
         *  }
         *  parent.m_qyInput = null;
         *  parent = temp;
         *  return true;
         * }
         */
        private IQuery ProcessFilter(Filter root, ref bool cache, ref bool position)
        {
            bool _cache    = false;
            bool merge     = false;
            bool _position = false;

            _specialAxis = false;
            bool filterflag = true;
            bool first      = (filterCount == 0);

            IQuery opnd = ProcessNode(root.Condition, null, Regular_D,
                                      Axis.AxisType.None, ref _cache, ref _position);

            filterCount++;
            if (root.Condition.ReturnType == XPathResultType.Error)
            {
                _position = true;
            }
            if (root.Condition.ReturnType == XPathResultType.Number ||
                _cache || _position)
            {
                hasPosition = true;
                filterflag  = false;
                _smart      = 0;
            }
            IQuery qyInput = ProcessNode(root.Input, null, Regular_D,
                                         Axis.AxisType.None, ref cache, ref position);

            if (hasPosition && qyInput is CacheQuery)
            {
                qyInput = ((CacheQuery)qyInput).m_qyInput;
            }
            if (firstInput == null)
            {
                firstInput = qyInput as BaseAxisQuery;
            }
            _smart = 2;
            merge  = qyInput.Merge;
            if (_cache || _position)
            {
                hasPosition = true;
                if (hasReverseAxis)
                {
                    if (merge)
                    {
                        qyInput = new ReversePositionQuery(qyInput);
                    }
                    else if (_cache)
                    {
                        qyInput = new ForwardPositionQuery(qyInput);
                    }
                }
                else
                {
                    if (_cache)
                    {
                        qyInput = new ForwardPositionQuery(qyInput);
                    }
                }
            }
            else if (root.Condition.ReturnType == XPathResultType.Number)
            {
                hasPosition = true;
                if (hasReverseAxis && merge)
                {
                    qyInput = new ReversePositionQuery(qyInput);
                }
            }
            if (first && firstInput != null)
            {
                if (merge && hasPosition)
                {
                    qyInput = new FilterQuery(qyInput, opnd);
                    IQuery parent = firstInput.m_qyInput;
                    if (parent == null || !firstInput.Merge)
                    {
                        firstInput = null;
                        return(qyInput);
                    }
                    IQuery input = qyInput;
                    qyInput = qyInput.Clone();
                    firstInput.m_qyInput = null;
                    firstInput           = null;
                    return(new MergeFilterQuery(parent, input));
                }
                firstInput = null;
            }
            return(new FilterQuery(qyInput, opnd, filterflag));
        }
Example #4
0
        /*
        private bool SplitQuery(BaseAxisQuery origQuery, BaseAxisQuery parent, BaseAxisQuery input) {
            parent = origQuery as BaseAxisQuery;
            if (parent == null || parent is GroupQuery || parent is PositionQuery || parent is OrQuery) {
                return false;
            }
            input = parent = (BaseAxisQuery)parent.Clone();
            parent = (BaseAxisQuery) parent.m_qyInput;
            while (parent != null && !parent.IsAxis) {
                parent = (BaseAxisQuery)parent.m_qyInput;
            }
            if (parent == null) {
                return false;
            }
            BaseAxisQuery temp = (BaseAxisQuery)parent.m_qyInput;
            if (temp == null) {
                return false;
            }
            parent.m_qyInput = null;
            parent = temp;
            return true;
        }
        */
        private IQuery ProcessFilter(Filter root, ref bool cache, ref bool position) {
            bool _cache = false;
            bool merge = false;
            bool _position = false;
            _specialAxis = false;
            bool filterflag = true;
            bool first = (filterCount == 0);

            IQuery opnd = ProcessNode(root.Condition, null, Regular_D, 
            Axis.AxisType.None, ref _cache, ref _position);

            filterCount++;
            if (root.Condition.ReturnType == XPathResultType.Error ) {
                _position = true;
            }
            if (root.Condition.ReturnType == XPathResultType.Number || 
                _cache || _position ) {
                hasPosition = true;
                filterflag = false;
                _smart = 0;
            }
            IQuery qyInput = ProcessNode(root.Input, null, Regular_D, 
            Axis.AxisType.None, ref cache, ref position );            

            if (hasPosition && qyInput is CacheQuery) {
                qyInput = ((CacheQuery)qyInput).m_qyInput;
            }
            if (firstInput == null) {
                firstInput =  qyInput as BaseAxisQuery;
            }
            _smart = 2;
            merge = qyInput.Merge;
            if (_cache || _position) {
                hasPosition = true;
                if (hasReverseAxis) {
                    if (merge) {
                        qyInput = new ReversePositionQuery(qyInput);                
                    }
                    else if (_cache) {
                        qyInput = new ForwardPositionQuery(qyInput); 
                    }
                }
                else {
                    if (_cache) {
                        qyInput = new ForwardPositionQuery(qyInput); 

                    }
                }
            }
            else if (root.Condition.ReturnType == XPathResultType.Number ) {
                hasPosition = true;
                if (hasReverseAxis && merge) {
                    qyInput = new ReversePositionQuery(qyInput);                

                }
            }
            if (first && firstInput != null) {
                if (merge && hasPosition) {
                    qyInput = new FilterQuery(qyInput, opnd);
                    IQuery parent = firstInput.m_qyInput;
                    if (parent == null || !firstInput.Merge) {
                        firstInput = null;
                        return qyInput;
                    }
                    IQuery input = qyInput;
                    qyInput = qyInput.Clone();
                    firstInput.m_qyInput = null;
                    firstInput = null;
                    return new MergeFilterQuery(parent, input);
                }
                firstInput = null;
            }
            return new FilterQuery(qyInput, opnd, filterflag);
        }