Пример #1
0
        private Query ProcessAxis(Axis root, Flags flags, out Props props)
        {
            Query result = null;

            if (root.Prefix.Length > 0)
            {
                needContext = true;
            }
            firstInput = null;
            Query qyInput; {
                if (root.Input != null)
                {
                    Flags inputFlags = Flags.None;
                    if ((flags & Flags.PosFilter) == 0)
                    {
                        Axis input = root.Input as Axis;
                        if (input != null)
                        {
                            if (
                                root.TypeOfAxis == Axis.AxisType.Child &&
                                input.TypeOfAxis == Axis.AxisType.DescendantOrSelf && input.NodeType == XPathNodeType.All
                                )
                            {
                                Query qyGrandInput;
                                if (input.Input != null)
                                {
                                    qyGrandInput = ProcessNode(input.Input, Flags.SmartDesc, out props);
                                }
                                else
                                {
                                    qyGrandInput = new ContextQuery();
                                    props        = Props.None;
                                }
                                result = new DescendantQuery(qyGrandInput, root.Name, root.Prefix, root.NodeType, false, input.AbbrAxis);
                                if ((props & Props.NonFlat) != 0)
                                {
                                    result = new DocumentOrderQuery(result);
                                }
                                props |= Props.NonFlat;
                                return(result);
                            }
                        }
                        if (root.TypeOfAxis == Axis.AxisType.Descendant || root.TypeOfAxis == Axis.AxisType.DescendantOrSelf)
                        {
                            inputFlags |= Flags.SmartDesc;
                        }
                    }

                    qyInput = ProcessNode(root.Input, inputFlags, out props);
                }
                else
                {
                    qyInput = new ContextQuery();
                    props   = Props.None;
                }
            }

            switch (root.TypeOfAxis)
            {
            case Axis.AxisType.Ancestor:
                result = new XPathAncestorQuery(qyInput, root.Name, root.Prefix, root.NodeType, false);
                props |= Props.NonFlat;
                break;

            case Axis.AxisType.AncestorOrSelf:
                result = new XPathAncestorQuery(qyInput, root.Name, root.Prefix, root.NodeType, true);
                props |= Props.NonFlat;
                break;

            case Axis.AxisType.Child:
                if ((props & Props.NonFlat) != 0)
                {
                    result = new CacheChildrenQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                }
                else
                {
                    result = new ChildrenQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                }
                break;

            case Axis.AxisType.Parent:
                result = new ParentQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                break;

            case Axis.AxisType.Descendant:
                if ((flags & Flags.SmartDesc) != 0)
                {
                    result = new DescendantOverDescendantQuery(qyInput, false, root.Name, root.Prefix, root.NodeType, /*abbrAxis:*/ false);
                }
                else
                {
                    result = new DescendantQuery(qyInput, root.Name, root.Prefix, root.NodeType, false, /*abbrAxis:*/ false);
                    if ((props & Props.NonFlat) != 0)
                    {
                        result = new DocumentOrderQuery(result);
                    }
                }
                props |= Props.NonFlat;
                break;

            case Axis.AxisType.DescendantOrSelf:
                if ((flags & Flags.SmartDesc) != 0)
                {
                    result = new DescendantOverDescendantQuery(qyInput, true, root.Name, root.Prefix, root.NodeType, root.AbbrAxis);
                }
                else
                {
                    result = new DescendantQuery(qyInput, root.Name, root.Prefix, root.NodeType, true, root.AbbrAxis);
                    if ((props & Props.NonFlat) != 0)
                    {
                        result = new DocumentOrderQuery(result);
                    }
                }
                props |= Props.NonFlat;
                break;

            case Axis.AxisType.Preceding:
                result = new PrecedingQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                props |= Props.NonFlat;
                break;

            case Axis.AxisType.Following:
                result = new FollowingQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                props |= Props.NonFlat;
                break;

            case Axis.AxisType.FollowingSibling:
                result = new FollSiblingQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                if ((props & Props.NonFlat) != 0)
                {
                    result = new DocumentOrderQuery(result);
                }
                break;

            case Axis.AxisType.PrecedingSibling:
                result = new PreSiblingQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                break;

            case Axis.AxisType.Attribute:
                result = new AttributeQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                break;

            case Axis.AxisType.Self:
                result = new XPathSelfQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                break;

            case Axis.AxisType.Namespace:
                if ((root.NodeType == XPathNodeType.All || root.NodeType == XPathNodeType.Element || root.NodeType == XPathNodeType.Attribute) && root.Prefix.Length == 0)
                {
                    result = new NamespaceQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                }
                else
                {
                    result = new EmptyQuery();
                }
                break;

            default:
                throw XPathException.Create(Res.Xp_NotSupported, query);
            }

            return(result);
        }
Пример #2
0
        private Query ProcessAxis(Axis root, Flags flags, out Props props)
        {
            Query qyParent = null;
            Query query2;

            if (root.Prefix.Length > 0)
            {
                this.needContext = true;
            }
            this.firstInput = null;
            if (root.Input != null)
            {
                Flags none = Flags.None;
                if ((flags & Flags.PosFilter) == Flags.None)
                {
                    Axis input = root.Input as Axis;
                    if (((input != null) && (root.TypeOfAxis == Axis.AxisType.Child)) && ((input.TypeOfAxis == Axis.AxisType.DescendantOrSelf) && (input.NodeType == XPathNodeType.All)))
                    {
                        Query query3;
                        if (input.Input != null)
                        {
                            query3 = this.ProcessNode(input.Input, Flags.SmartDesc, out props);
                        }
                        else
                        {
                            query3 = new ContextQuery();
                            props  = Props.None;
                        }
                        qyParent = new DescendantQuery(query3, root.Name, root.Prefix, root.NodeType, false, input.AbbrAxis);
                        if ((props & Props.NonFlat) != Props.None)
                        {
                            qyParent = new DocumentOrderQuery(qyParent);
                        }
                        props |= Props.NonFlat;
                        return(qyParent);
                    }
                    if ((root.TypeOfAxis == Axis.AxisType.Descendant) || (root.TypeOfAxis == Axis.AxisType.DescendantOrSelf))
                    {
                        none |= Flags.SmartDesc;
                    }
                }
                query2 = this.ProcessNode(root.Input, none, out props);
            }
            else
            {
                query2 = new ContextQuery();
                props  = Props.None;
            }
            switch (root.TypeOfAxis)
            {
            case Axis.AxisType.Ancestor:
                qyParent = new XPathAncestorQuery(query2, root.Name, root.Prefix, root.NodeType, false);
                props   |= Props.NonFlat;
                return(qyParent);

            case Axis.AxisType.AncestorOrSelf:
                qyParent = new XPathAncestorQuery(query2, root.Name, root.Prefix, root.NodeType, true);
                props   |= Props.NonFlat;
                return(qyParent);

            case Axis.AxisType.Attribute:
                return(new AttributeQuery(query2, root.Name, root.Prefix, root.NodeType));

            case Axis.AxisType.Child:
                if ((props & Props.NonFlat) == Props.None)
                {
                    return(new ChildrenQuery(query2, root.Name, root.Prefix, root.NodeType));
                }
                return(new CacheChildrenQuery(query2, root.Name, root.Prefix, root.NodeType));

            case Axis.AxisType.Descendant:
                if ((flags & Flags.SmartDesc) == Flags.None)
                {
                    qyParent = new DescendantQuery(query2, root.Name, root.Prefix, root.NodeType, false, false);
                    if ((props & Props.NonFlat) != Props.None)
                    {
                        qyParent = new DocumentOrderQuery(qyParent);
                    }
                    break;
                }
                qyParent = new DescendantOverDescendantQuery(query2, false, root.Name, root.Prefix, root.NodeType, false);
                break;

            case Axis.AxisType.DescendantOrSelf:
                if ((flags & Flags.SmartDesc) == Flags.None)
                {
                    qyParent = new DescendantQuery(query2, root.Name, root.Prefix, root.NodeType, true, root.AbbrAxis);
                    if ((props & Props.NonFlat) != Props.None)
                    {
                        qyParent = new DocumentOrderQuery(qyParent);
                    }
                }
                else
                {
                    qyParent = new DescendantOverDescendantQuery(query2, true, root.Name, root.Prefix, root.NodeType, root.AbbrAxis);
                }
                props |= Props.NonFlat;
                return(qyParent);

            case Axis.AxisType.Following:
                qyParent = new FollowingQuery(query2, root.Name, root.Prefix, root.NodeType);
                props   |= Props.NonFlat;
                return(qyParent);

            case Axis.AxisType.FollowingSibling:
                qyParent = new FollSiblingQuery(query2, root.Name, root.Prefix, root.NodeType);
                if ((props & Props.NonFlat) != Props.None)
                {
                    qyParent = new DocumentOrderQuery(qyParent);
                }
                return(qyParent);

            case Axis.AxisType.Namespace:
                if ((((root.NodeType == XPathNodeType.All) || (root.NodeType == XPathNodeType.Element)) || (root.NodeType == XPathNodeType.Attribute)) && (root.Prefix.Length == 0))
                {
                    return(new NamespaceQuery(query2, root.Name, root.Prefix, root.NodeType));
                }
                return(new EmptyQuery());

            case Axis.AxisType.Parent:
                return(new ParentQuery(query2, root.Name, root.Prefix, root.NodeType));

            case Axis.AxisType.Preceding:
                qyParent = new PrecedingQuery(query2, root.Name, root.Prefix, root.NodeType);
                props   |= Props.NonFlat;
                return(qyParent);

            case Axis.AxisType.PrecedingSibling:
                return(new PreSiblingQuery(query2, root.Name, root.Prefix, root.NodeType));

            case Axis.AxisType.Self:
                return(new XPathSelfQuery(query2, root.Name, root.Prefix, root.NodeType));

            default:
                throw XPathException.Create("Xp_NotSupported", this.query);
            }
            props |= Props.NonFlat;
            return(qyParent);
        }
Пример #3
0
        private Query ProcessAxis(Axis root, Flags flags, out Props props)
        {
            Query result = null;
            if (root.Prefix.Length > 0)
            {
                _needContext = true;
            }
            _firstInput = null;
            Query qyInput;
            {
                if (root.Input != null)
                {
                    Flags inputFlags = Flags.None;
                    if ((flags & Flags.PosFilter) == 0)
                    {
                        Axis input = root.Input as Axis;
                        if (input != null)
                        {
                            if (
                                root.TypeOfAxis == Axis.AxisType.Child &&
                                input.TypeOfAxis == Axis.AxisType.DescendantOrSelf && input.NodeType == XPathNodeType.All
                            )
                            {
                                Query qyGrandInput;
                                if (input.Input != null)
                                {
                                    qyGrandInput = ProcessNode(input.Input, Flags.SmartDesc, out props);
                                }
                                else
                                {
                                    qyGrandInput = new ContextQuery();
                                    props = Props.None;
                                }
                                result = new DescendantQuery(qyGrandInput, root.Name, root.Prefix, root.NodeType, false, input.AbbrAxis);
                                if ((props & Props.NonFlat) != 0)
                                {
                                    result = new DocumentOrderQuery(result);
                                }
                                props |= Props.NonFlat;
                                return result;
                            }
                        }
                        if (root.TypeOfAxis == Axis.AxisType.Descendant || root.TypeOfAxis == Axis.AxisType.DescendantOrSelf)
                        {
                            inputFlags |= Flags.SmartDesc;
                        }
                    }

                    qyInput = ProcessNode(root.Input, inputFlags, out props);
                }
                else
                {
                    qyInput = new ContextQuery();
                    props = Props.None;
                }
            }

            switch (root.TypeOfAxis)
            {
                case Axis.AxisType.Ancestor:
                    result = new XPathAncestorQuery(qyInput, root.Name, root.Prefix, root.NodeType, false);
                    props |= Props.NonFlat;
                    break;
                case Axis.AxisType.AncestorOrSelf:
                    result = new XPathAncestorQuery(qyInput, root.Name, root.Prefix, root.NodeType, true);
                    props |= Props.NonFlat;
                    break;
                case Axis.AxisType.Child:
                    if ((props & Props.NonFlat) != 0)
                    {
                        result = new CacheChildrenQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    }
                    else
                    {
                        result = new ChildrenQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    }
                    break;
                case Axis.AxisType.Parent:
                    result = new ParentQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    break;
                case Axis.AxisType.Descendant:
                    if ((flags & Flags.SmartDesc) != 0)
                    {
                        result = new DescendantOverDescendantQuery(qyInput, false, root.Name, root.Prefix, root.NodeType, /*abbrAxis:*/false);
                    }
                    else
                    {
                        result = new DescendantQuery(qyInput, root.Name, root.Prefix, root.NodeType, false, /*abbrAxis:*/false);
                        if ((props & Props.NonFlat) != 0)
                        {
                            result = new DocumentOrderQuery(result);
                        }
                    }
                    props |= Props.NonFlat;
                    break;
                case Axis.AxisType.DescendantOrSelf:
                    if ((flags & Flags.SmartDesc) != 0)
                    {
                        result = new DescendantOverDescendantQuery(qyInput, true, root.Name, root.Prefix, root.NodeType, root.AbbrAxis);
                    }
                    else
                    {
                        result = new DescendantQuery(qyInput, root.Name, root.Prefix, root.NodeType, true, root.AbbrAxis);
                        if ((props & Props.NonFlat) != 0)
                        {
                            result = new DocumentOrderQuery(result);
                        }
                    }
                    props |= Props.NonFlat;
                    break;
                case Axis.AxisType.Preceding:
                    result = new PrecedingQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    props |= Props.NonFlat;
                    break;
                case Axis.AxisType.Following:
                    result = new FollowingQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    props |= Props.NonFlat;
                    break;
                case Axis.AxisType.FollowingSibling:
                    result = new FollSiblingQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    if ((props & Props.NonFlat) != 0)
                    {
                        result = new DocumentOrderQuery(result);
                    }
                    break;
                case Axis.AxisType.PrecedingSibling:
                    result = new PreSiblingQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    break;
                case Axis.AxisType.Attribute:
                    result = new AttributeQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    break;
                case Axis.AxisType.Self:
                    result = new XPathSelfQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    break;
                case Axis.AxisType.Namespace:
                    if ((root.NodeType == XPathNodeType.All || root.NodeType == XPathNodeType.Element || root.NodeType == XPathNodeType.Attribute) && root.Prefix.Length == 0)
                    {
                        result = new NamespaceQuery(qyInput, root.Name, root.Prefix, root.NodeType);
                    }
                    else
                    {
                        result = new EmptyQuery();
                    }
                    break;
                default:
                    throw XPathException.Create(SR.Xp_NotSupported, _query);
            }

            return result;
        }
Пример #4
0
 protected ContextQuery(ContextQuery other) : base(other) {
     this.contextNode = other.contextNode;   // Don't need to clone here
 }
Пример #5
0
 protected ContextQuery(ContextQuery other) : base(other)
 {
     this.contextNode = other.contextNode;   // Don't need to clone here
 }
        private Query ProcessAxis(Axis root, Flags flags, out Props props)
        {
            Query qyParent = null;
            Query query2;
            if (root.Prefix.Length > 0)
            {
                this.needContext = true;
            }
            this.firstInput = null;
            if (root.Input != null)
            {
                Flags none = Flags.None;
                if ((flags & Flags.PosFilter) == Flags.None)
                {
                    Axis input = root.Input as Axis;
                    if (((input != null) && (root.TypeOfAxis == Axis.AxisType.Child)) && ((input.TypeOfAxis == Axis.AxisType.DescendantOrSelf) && (input.NodeType == XPathNodeType.All)))
                    {
                        Query query3;
                        if (input.Input != null)
                        {
                            query3 = this.ProcessNode(input.Input, Flags.SmartDesc, out props);
                        }
                        else
                        {
                            query3 = new ContextQuery();
                            props = Props.None;
                        }
                        qyParent = new DescendantQuery(query3, root.Name, root.Prefix, root.NodeType, false, input.AbbrAxis);
                        if ((props & Props.NonFlat) != Props.None)
                        {
                            qyParent = new DocumentOrderQuery(qyParent);
                        }
                        props |= Props.NonFlat;
                        return qyParent;
                    }
                    if ((root.TypeOfAxis == Axis.AxisType.Descendant) || (root.TypeOfAxis == Axis.AxisType.DescendantOrSelf))
                    {
                        none |= Flags.SmartDesc;
                    }
                }
                query2 = this.ProcessNode(root.Input, none, out props);
            }
            else
            {
                query2 = new ContextQuery();
                props = Props.None;
            }
            switch (root.TypeOfAxis)
            {
                case Axis.AxisType.Ancestor:
                    qyParent = new XPathAncestorQuery(query2, root.Name, root.Prefix, root.NodeType, false);
                    props |= Props.NonFlat;
                    return qyParent;

                case Axis.AxisType.AncestorOrSelf:
                    qyParent = new XPathAncestorQuery(query2, root.Name, root.Prefix, root.NodeType, true);
                    props |= Props.NonFlat;
                    return qyParent;

                case Axis.AxisType.Attribute:
                    return new AttributeQuery(query2, root.Name, root.Prefix, root.NodeType);

                case Axis.AxisType.Child:
                    if ((props & Props.NonFlat) == Props.None)
                    {
                        return new ChildrenQuery(query2, root.Name, root.Prefix, root.NodeType);
                    }
                    return new CacheChildrenQuery(query2, root.Name, root.Prefix, root.NodeType);

                case Axis.AxisType.Descendant:
                    if ((flags & Flags.SmartDesc) == Flags.None)
                    {
                        qyParent = new DescendantQuery(query2, root.Name, root.Prefix, root.NodeType, false, false);
                        if ((props & Props.NonFlat) != Props.None)
                        {
                            qyParent = new DocumentOrderQuery(qyParent);
                        }
                        break;
                    }
                    qyParent = new DescendantOverDescendantQuery(query2, false, root.Name, root.Prefix, root.NodeType, false);
                    break;

                case Axis.AxisType.DescendantOrSelf:
                    if ((flags & Flags.SmartDesc) == Flags.None)
                    {
                        qyParent = new DescendantQuery(query2, root.Name, root.Prefix, root.NodeType, true, root.AbbrAxis);
                        if ((props & Props.NonFlat) != Props.None)
                        {
                            qyParent = new DocumentOrderQuery(qyParent);
                        }
                    }
                    else
                    {
                        qyParent = new DescendantOverDescendantQuery(query2, true, root.Name, root.Prefix, root.NodeType, root.AbbrAxis);
                    }
                    props |= Props.NonFlat;
                    return qyParent;

                case Axis.AxisType.Following:
                    qyParent = new FollowingQuery(query2, root.Name, root.Prefix, root.NodeType);
                    props |= Props.NonFlat;
                    return qyParent;

                case Axis.AxisType.FollowingSibling:
                    qyParent = new FollSiblingQuery(query2, root.Name, root.Prefix, root.NodeType);
                    if ((props & Props.NonFlat) != Props.None)
                    {
                        qyParent = new DocumentOrderQuery(qyParent);
                    }
                    return qyParent;

                case Axis.AxisType.Namespace:
                    if ((((root.NodeType == XPathNodeType.All) || (root.NodeType == XPathNodeType.Element)) || (root.NodeType == XPathNodeType.Attribute)) && (root.Prefix.Length == 0))
                    {
                        return new NamespaceQuery(query2, root.Name, root.Prefix, root.NodeType);
                    }
                    return new EmptyQuery();

                case Axis.AxisType.Parent:
                    return new ParentQuery(query2, root.Name, root.Prefix, root.NodeType);

                case Axis.AxisType.Preceding:
                    qyParent = new PrecedingQuery(query2, root.Name, root.Prefix, root.NodeType);
                    props |= Props.NonFlat;
                    return qyParent;

                case Axis.AxisType.PrecedingSibling:
                    return new PreSiblingQuery(query2, root.Name, root.Prefix, root.NodeType);

                case Axis.AxisType.Self:
                    return new XPathSelfQuery(query2, root.Name, root.Prefix, root.NodeType);

                default:
                    throw XPathException.Create("Xp_NotSupported", this.query);
            }
            props |= Props.NonFlat;
            return qyParent;
        }
Пример #7
0
 protected ContextQuery(ContextQuery other) : base(other)
 {
     this.contextNode = other.contextNode;
 }