Inheritance: ValueQuery
Example #1
0
        private Query ProcessNode(AstNode root, Flags flags, out Props props)
        {
            if (++parseDepth > MaxParseDepth)
            {
                throw XPathException.Create(Res.Xp_QueryTooComplex);
            }

            Debug.Assert(root != null, "root != null");
            Query result = null;

            props = Props.None;
            switch (root.Type)
            {
            case AstNode.AstType.Axis:
                result = ProcessAxis((Axis)root, flags, out props);
                break;

            case AstNode.AstType.Operator:
                result = ProcessOperator((Operator)root, out props);
                break;

            case AstNode.AstType.Filter:
                result = ProcessFilter((Filter)root, flags, out props);
                break;

            case AstNode.AstType.ConstantOperand:
                result = new OperandQuery(((Operand)root).OperandValue);
                break;

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

            case AstNode.AstType.Function:
                result = ProcessFunction((Function)root, out props);
                break;

            case AstNode.AstType.Group:
                result = new GroupQuery(ProcessNode(((Group)root).GroupNode, Flags.None, out props));
                break;

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

            default:
                Debug.Assert(false, "Unknown QueryType encountered!!");
                break;
            }
            --parseDepth;
            return(result);
        }
Example #2
0
        public override XPathNavigator MatchNode(XPathNavigator current)
        {
            XPathNavigator context;

            if (current == null)
            {
                return(null);
            }
            context = qyInput.MatchNode(current);

            if (context != null)
            {
                // In this switch we process some special case in wich we can calculate predicate faster then in generic case
                switch (_cond.StaticType)
                {
                case XPathResultType.Number:
                    OperandQuery operand = _cond as OperandQuery;
                    if (operand != null)
                    {
                        double        val           = (double)operand.val;
                        ChildrenQuery childrenQuery = qyInput as ChildrenQuery;
                        if (childrenQuery != null)
                        {     // foo[2], but not foo[expr][2]
                            XPathNavigator result = current.Clone();
                            result.MoveToParent();
                            int i = 0;
                            result.MoveToFirstChild();
                            do
                            {
                                if (childrenQuery.matches(result))
                                {
                                    i++;
                                    if (current.IsSamePosition(result))
                                    {
                                        return(val == i ? context : null);
                                    }
                                }
                            } while (result.MoveToNext());
                            return(null);
                        }
                        AttributeQuery attributeQuery = qyInput as AttributeQuery;
                        if (attributeQuery != null)
                        {    // @foo[3], but not @foo[expr][2]
                            XPathNavigator result = current.Clone();
                            result.MoveToParent();
                            int i = 0;
                            result.MoveToFirstAttribute();
                            do
                            {
                                if (attributeQuery.matches(result))
                                {
                                    i++;
                                    if (current.IsSamePosition(result))
                                    {
                                        return(val == i ? context : null);
                                    }
                                }
                            } while (result.MoveToNextAttribute());
                            return(null);
                        }
                    }
                    break;

                case XPathResultType.NodeSet:
                    _cond.Evaluate(new XPathSingletonIterator(current, /*moved:*/ true));
                    return((_cond.Advance() != null) ? context : null);

                case XPathResultType.Boolean:
                    if (_noPosition)
                    {
                        return(((bool)_cond.Evaluate(new XPathSingletonIterator(current, /*moved:*/ true))) ? context : null);
                    }
                    break;

                case XPathResultType.String:
                    if (_noPosition)
                    {
                        return((((string)_cond.Evaluate(new XPathSingletonIterator(current, /*moved:*/ true))).Length != 0) ? context : null);
                    }
                    break;

                case XPathResultType_Navigator:
                    return(context);

                default:
                    return(null);
                }
                /* Generic case */
                {
                    Evaluate(new XPathSingletonIterator(context, /*moved:*/ true));
                    XPathNavigator result;
                    while ((result = Advance()) != null)
                    {
                        if (result.IsSamePosition(current))
                        {
                            return(context);
                        }
                    }
                }
            }
            return(null);
        }
Example #3
0
        public override XPathNavigator MatchNode(XPathNavigator current)
        {
            XPathNavigator navigator;
            XPathNavigator navigator4;

            if (current != null)
            {
                navigator = base.qyInput.MatchNode(current);
                if (navigator == null)
                {
                    goto Label_01B9;
                }
                switch (this.cond.StaticType)
                {
                case XPathResultType.Number:
                {
                    OperandQuery cond = this.cond as OperandQuery;
                    if (cond != null)
                    {
                        double        val     = (double)cond.val;
                        ChildrenQuery qyInput = base.qyInput as ChildrenQuery;
                        if (qyInput != null)
                        {
                            XPathNavigator e = current.Clone();
                            e.MoveToParent();
                            int num2 = 0;
                            e.MoveToFirstChild();
                            do
                            {
                                if (qyInput.matches(e))
                                {
                                    num2++;
                                    if (current.IsSamePosition(e))
                                    {
                                        if (val != num2)
                                        {
                                            return(null);
                                        }
                                        return(navigator);
                                    }
                                }
                            }while (e.MoveToNext());
                            return(null);
                        }
                        AttributeQuery query3 = base.qyInput as AttributeQuery;
                        if (query3 != null)
                        {
                            XPathNavigator navigator3 = current.Clone();
                            navigator3.MoveToParent();
                            int num3 = 0;
                            navigator3.MoveToFirstAttribute();
                            do
                            {
                                if (query3.matches(navigator3))
                                {
                                    num3++;
                                    if (current.IsSamePosition(navigator3))
                                    {
                                        if (val != num3)
                                        {
                                            return(null);
                                        }
                                        return(navigator);
                                    }
                                }
                            }while (navigator3.MoveToNextAttribute());
                            return(null);
                        }
                    }
                    goto Label_0192;
                }

                case XPathResultType.String:
                    if (!this.noPosition)
                    {
                        goto Label_0192;
                    }
                    if (((string)this.cond.Evaluate(new XPathSingletonIterator(current, true))).Length != 0)
                    {
                        return(navigator);
                    }
                    return(null);

                case XPathResultType.Boolean:
                    if (!this.noPosition)
                    {
                        goto Label_0192;
                    }
                    if ((bool)this.cond.Evaluate(new XPathSingletonIterator(current, true)))
                    {
                        return(navigator);
                    }
                    return(null);

                case XPathResultType.NodeSet:
                    this.cond.Evaluate(new XPathSingletonIterator(current, true));
                    if (this.cond.Advance() != null)
                    {
                        return(navigator);
                    }
                    return(null);

                case ((XPathResultType)4):
                    return(navigator);
                }
            }
            return(null);

Label_0192:
            this.Evaluate(new XPathSingletonIterator(navigator, true));
            while ((navigator4 = this.Advance()) != null)
            {
                if (navigator4.IsSamePosition(current))
                {
                    return(navigator);
                }
            }
Label_01B9:
            return(null);
        }