コード例 #1
0
 internal override void RemoveChild(SubExpr expr)
 {
     base.RemoveChild(expr);
     this.RebuildIndex();
     if (expr.useSpecial)
     {
         Dictionary <string, List <SubExpr> > dictionary;
         NodeQName qName = ((SelectOpcode)expr.FirstOp).Criteria.QName;
         string    key   = qName.Namespace;
         if (this.nameLookup.TryGetValue(key, out dictionary))
         {
             List <SubExpr> list;
             string         name = qName.Name;
             if (dictionary.TryGetValue(name, out list))
             {
                 list.Remove(expr);
                 if (list.Count == 0)
                 {
                     dictionary.Remove(name);
                 }
             }
             if (dictionary.Count == 0)
             {
                 this.nameLookup.Remove(key);
             }
         }
     }
 }
コード例 #2
0
        internal override void RemoveChild(SubExpr expr)
        {
            base.RemoveChild(expr);
            RebuildIndex();

            if (expr.useSpecial)
            {
                NodeQName qname = ((SelectOpcode)(expr.FirstOp)).Criteria.QName;
                string    ns    = qname.Namespace;
                Dictionary <string, List <SubExpr> > nextLookup;
                if (this.nameLookup.TryGetValue(ns, out nextLookup))
                {
                    string         name = qname.Name;
                    List <SubExpr> exprs;
                    if (nextLookup.TryGetValue(name, out exprs))
                    {
                        exprs.Remove(expr);
                        if (exprs.Count == 0)
                        {
                            nextLookup.Remove(name);
                        }
                    }

                    if (nextLookup.Count == 0)
                    {
                        this.nameLookup.Remove(ns);
                    }
                }
            }
        }
コード例 #3
0
 internal NodeSelectCriteria(QueryAxisType axis, NodeQName qname, QueryNodeType nodeType)
 {
     this.axis = QueryDataModel.GetAxis(axis);
     this.qname = qname;
     this.qnameType = qname.GetQNameType();
     this.type = nodeType;
 }
コード例 #4
0
 internal NodeSelectCriteria(QueryAxisType axis, NodeQName qname, QueryNodeType nodeType)
 {
     this.axis      = QueryDataModel.GetAxis(axis);
     this.qname     = qname;
     this.qnameType = qname.GetQNameType();
     this.type      = nodeType;
 }
コード例 #5
0
        internal override void AddChild(SubExpr expr)
        {
            base.AddChild(expr);
            RebuildIndex();

            if (expr.useSpecial)
            {
                NodeQName qname = ((SelectOpcode)(expr.FirstOp)).Criteria.QName;
                string    ns    = qname.Namespace;
                Dictionary <string, List <SubExpr> > nextLookup;
                if (!this.nameLookup.TryGetValue(ns, out nextLookup))
                {
                    nextLookup = new Dictionary <string, List <SubExpr> >();
                    this.nameLookup.Add(ns, nextLookup);
                }

                string         name  = qname.Name;
                List <SubExpr> exprs = new List <SubExpr>();
                if (!nextLookup.TryGetValue(name, out exprs))
                {
                    exprs = new List <SubExpr>();
                    nextLookup.Add(name, exprs);
                }

                exprs.Add(expr);
            }
        }
コード例 #6
0
 internal bool Equals(NodeQName qname)
 {
     if ((qname.name.Length != this.name.Length) || !(qname.name == this.name))
     {
         return(false);
     }
     return((qname.ns.Length == this.ns.Length) && (qname.ns == this.ns));
 }
コード例 #7
0
        private XPathExpr ParseFunctionExpression()
        {
            XPathExpr  expr;
            XPathToken token = this.NextToken(XPathTokenID.Function);

            if (token == null)
            {
                return(null);
            }
            NodeQName name = this.QualifyName(token.Prefix, token.Name);

            this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidFunction);
            XPathExprList args = new XPathExprList();

            while ((expr = this.ParseExpression()) != null)
            {
                args.Add(expr);
                if (this.NextToken(XPathTokenID.Comma) == null)
                {
                    break;
                }
            }
            XPathExpr expr2 = null;

            if (this.functionLibraries != null)
            {
                QueryFunction function = null;
                for (int i = 0; i < this.functionLibraries.Length; i++)
                {
                    function = this.functionLibraries[i].Bind(name.Name, name.Namespace, args);
                    if (function != null)
                    {
                        expr2 = new XPathFunctionExpr(function, args);
                        break;
                    }
                }
            }
            if ((expr2 == null) && (this.context != null))
            {
                XPathResultType[] argTypes = new XPathResultType[args.Count];
                for (int j = 0; j < args.Count; j++)
                {
                    argTypes[j] = XPathXsltFunctionExpr.ConvertTypeToXslt(args[j].ReturnType);
                }
                string prefix = this.context.LookupPrefix(name.Namespace);
                IXsltContextFunction function2 = this.context.ResolveFunction(prefix, name.Name, argTypes);
                if (function2 != null)
                {
                    expr2 = new XPathXsltFunctionExpr(this.context, function2, args);
                }
            }
            if (expr2 == null)
            {
                this.ThrowError(QueryCompileError.UnsupportedFunction);
            }
            this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidFunction);
            return(expr2);
        }
コード例 #8
0
        internal XPathExpr ParseVariableExpression()
        {
            XPathExpr expr = null;

            if (this.context != null)
            {
                XPathToken token = this.NextToken(XPathTokenID.Variable);
                if (token != null)
                {
                    NodeQName            name     = this.QualifyName(token.Prefix, token.Name);
                    string               prefix   = this.context.LookupPrefix(name.Namespace);
                    IXsltContextVariable variable = this.context.ResolveVariable(prefix, name.Name);
                    if (variable != null)
                    {
                        expr = new XPathXsltVariableExpr(this.context, variable);
                    }
                }
            }
            return(expr);
        }
コード例 #9
0
 internal override void AddChild(SubExpr expr)
 {
     base.AddChild(expr);
     this.RebuildIndex();
     if (expr.useSpecial)
     {
         Dictionary <string, List <SubExpr> > dictionary;
         NodeQName qName = ((SelectOpcode)expr.FirstOp).Criteria.QName;
         string    key   = qName.Namespace;
         if (!this.nameLookup.TryGetValue(key, out dictionary))
         {
             dictionary = new Dictionary <string, List <SubExpr> >();
             this.nameLookup.Add(key, dictionary);
         }
         string         name = qName.Name;
         List <SubExpr> list = new List <SubExpr>();
         if (!dictionary.TryGetValue(name, out list))
         {
             list = new List <SubExpr>();
             dictionary.Add(name, list);
         }
         list.Add(expr);
     }
 }
コード例 #10
0
 internal static NodeSelectCriteria Create(QueryAxisType axis, NodeQName qname, QueryNodeType nodeType)
 {
     return new NodeSelectCriteria(axis, qname, nodeType);
 }
コード例 #11
0
 internal bool EqualsReference(NodeQName qname)
 {
     return (object.ReferenceEquals(qname.name, this.name) && object.ReferenceEquals(qname.ns, this.ns));
 }
コード例 #12
0
 internal bool Equals(NodeQName qname)
 {
     return ((qname.name.Length == this.name.Length && qname.name == this.name) && (qname.ns.Length == this.ns.Length && qname.ns == this.ns));
 }
コード例 #13
0
 internal static NodeSelectCriteria Create(QueryAxisType axis, NodeQName qname, QueryNodeType nodeType)
 {
     return(new NodeSelectCriteria(axis, qname, nodeType));
 }
コード例 #14
0
ファイル: XPathParser.cs プロジェクト: dox0/DotNet471RS3
        XPathExpr ParseFunctionExpression()
        {
            XPathToken functionToken = this.NextToken(XPathTokenID.Function);

            if (null == functionToken)
            {
                return(null);
            }

            NodeQName functionName = this.QualifyName(functionToken.Prefix, functionToken.Name);

            this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidFunction);

            XPathExprList args = new XPathExprList();

            // Read in arguments
            XPathExpr arg;

            while (null != (arg = this.ParseExpression()))
            {
                args.Add(arg);
                if (null == this.NextToken(XPathTokenID.Comma))
                {
                    break;
                }
            }

            // Bind to the function
            // Try each library until we can bind the function
            XPathExpr functionImpl = null;

            if (null != this.functionLibraries)
            {
                QueryFunction fun = null;
                for (int i = 0; i < this.functionLibraries.Length; ++i)
                {
                    if (null != (fun = this.functionLibraries[i].Bind(functionName.Name, functionName.Namespace, args)))
                    {
                        functionImpl = new XPathFunctionExpr(fun, args);
                        break;
                    }
                }
            }

            // Try to bind using the XsltContext
            if (null == functionImpl && this.context != null)
            {
                XPathResultType[] argTypes = new XPathResultType[args.Count];
                for (int i = 0; i < args.Count; ++i)
                {
                    argTypes[i] = XPathXsltFunctionExpr.ConvertTypeToXslt(args[i].ReturnType);
                }
                string prefix = this.context.LookupPrefix(functionName.Namespace);
                IXsltContextFunction xsltFun = this.context.ResolveFunction(prefix, functionName.Name, argTypes);
                if (xsltFun != null)
                {
                    functionImpl = new XPathXsltFunctionExpr(this.context, xsltFun, args);
                }
            }

            if (null == functionImpl)
            {
                this.ThrowError(QueryCompileError.UnsupportedFunction);
            }

            this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidFunction);
            return(functionImpl);
        }
コード例 #15
0
 static NodeQName()
 {
     Empty = new NodeQName(string.Empty, string.Empty);
 }
コード例 #16
0
        NodeSelectCriteria ParseNodeTest(QueryAxisType axisType)
        {
            Fx.Assert(QueryAxisType.None != axisType, "");

            QueryAxis axis = QueryDataModel.GetAxis(axisType);
            XPathToken token;
            NodeQName qname = NodeQName.Empty;

            if (null != (token = this.NextTokenClass(XPathTokenID.NameTest)))
            {
                switch (token.TokenID)
                {
                    default:
                        this.ThrowError(QueryCompileError.UnexpectedToken);
                        break;

                    case XPathTokenID.Wildcard:
                        qname = new NodeQName(QueryDataModel.Wildcard, QueryDataModel.Wildcard);
                        break;

                    case XPathTokenID.NameTest:
                        qname = this.QualifyName(token.Prefix, token.Name);
                        break;

                    case XPathTokenID.NameWildcard:
                        qname = this.QualifyName(token.Prefix, QueryDataModel.Wildcard);
                        break;
                }
            }

            QueryNodeType nodeType = QueryNodeType.Any;

            if (qname.IsEmpty)
            {
                // Check for nodeTests
                if (null == (token = this.NextTokenClass(XPathTokenID.NodeType)))
                {
                    // Not a NodeTest either.
                    return null;
                }

                switch (token.TokenID)
                {
                    default:
                        this.ThrowError(QueryCompileError.UnsupportedNodeTest);
                        break;

                    case XPathTokenID.Comment:
                        nodeType = QueryNodeType.Comment;
                        break;

                    case XPathTokenID.Text:
                        nodeType = QueryNodeType.Text;
                        break;

                    case XPathTokenID.Processing:
                        nodeType = QueryNodeType.Processing;
                        break;

                    case XPathTokenID.Node:
                        nodeType = QueryNodeType.All;
                        break;
                }

                // Make sure the nodes being selected CAN actually be selected from this axis
                if (0 == (axis.ValidNodeTypes & nodeType))
                {
                    this.ThrowError(QueryCompileError.InvalidNodeType);
                }

                // Eat ()
                this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidNodeTest);
                this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidNodeTest);
            }
            else
            {
                nodeType = axis.PrincipalNodeType;
            }

            return new NodeSelectCriteria(axisType, qname, nodeType);
        }
コード例 #17
0
        private NodeSelectCriteria ParseNodeTest(QueryAxisType axisType)
        {
            QueryNodeType principalNodeType;
            QueryAxis     axis  = QueryDataModel.GetAxis(axisType);
            NodeQName     empty = NodeQName.Empty;
            XPathToken    token = this.NextTokenClass(XPathTokenID.NameTest);

            if (token != null)
            {
                switch (token.TokenID)
                {
                case XPathTokenID.Wildcard:
                    empty = new NodeQName(QueryDataModel.Wildcard, QueryDataModel.Wildcard);
                    goto Label_0085;

                case XPathTokenID.NameWildcard:
                    empty = this.QualifyName(token.Prefix, QueryDataModel.Wildcard);
                    goto Label_0085;

                case XPathTokenID.NameTest:
                    empty = this.QualifyName(token.Prefix, token.Name);
                    goto Label_0085;
                }
                this.ThrowError(QueryCompileError.UnexpectedToken);
            }
Label_0085:
            principalNodeType = QueryNodeType.Any;
            if (!empty.IsEmpty)
            {
                principalNodeType = axis.PrincipalNodeType;
            }
            else
            {
                token = this.NextTokenClass(XPathTokenID.NodeType);
                if (token == null)
                {
                    return(null);
                }
                switch (token.TokenID)
                {
                case XPathTokenID.Comment:
                    principalNodeType = QueryNodeType.Comment;
                    break;

                case XPathTokenID.Text:
                    principalNodeType = QueryNodeType.Text;
                    break;

                case XPathTokenID.Processing:
                    principalNodeType = QueryNodeType.Processing;
                    break;

                case XPathTokenID.Node:
                    principalNodeType = QueryNodeType.All;
                    break;

                default:
                    this.ThrowError(QueryCompileError.UnsupportedNodeTest);
                    break;
                }
                if (((byte)(axis.ValidNodeTypes & principalNodeType)) == 0)
                {
                    this.ThrowError(QueryCompileError.InvalidNodeType);
                }
                this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidNodeTest);
                this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidNodeTest);
            }
            return(new NodeSelectCriteria(axisType, empty, principalNodeType));
        }
コード例 #18
0
 internal bool EqualsReference(NodeQName qname)
 {
     return(object.ReferenceEquals(qname.name, this.name) && object.ReferenceEquals(qname.ns, this.ns));
 }
コード例 #19
0
        private NodeSelectCriteria ParseNodeTest(QueryAxisType axisType)
        {
            QueryNodeType principalNodeType;
            QueryAxis axis = QueryDataModel.GetAxis(axisType);
            NodeQName empty = NodeQName.Empty;
            XPathToken token = this.NextTokenClass(XPathTokenID.NameTest);
            if (token != null)
            {
                switch (token.TokenID)
                {
                    case XPathTokenID.Wildcard:
                        empty = new NodeQName(QueryDataModel.Wildcard, QueryDataModel.Wildcard);
                        goto Label_0085;

                    case XPathTokenID.NameWildcard:
                        empty = this.QualifyName(token.Prefix, QueryDataModel.Wildcard);
                        goto Label_0085;

                    case XPathTokenID.NameTest:
                        empty = this.QualifyName(token.Prefix, token.Name);
                        goto Label_0085;
                }
                this.ThrowError(QueryCompileError.UnexpectedToken);
            }
        Label_0085:
            principalNodeType = QueryNodeType.Any;
            if (!empty.IsEmpty)
            {
                principalNodeType = axis.PrincipalNodeType;
            }
            else
            {
                token = this.NextTokenClass(XPathTokenID.NodeType);
                if (token == null)
                {
                    return null;
                }
                switch (token.TokenID)
                {
                    case XPathTokenID.Comment:
                        principalNodeType = QueryNodeType.Comment;
                        break;

                    case XPathTokenID.Text:
                        principalNodeType = QueryNodeType.Text;
                        break;

                    case XPathTokenID.Processing:
                        principalNodeType = QueryNodeType.Processing;
                        break;

                    case XPathTokenID.Node:
                        principalNodeType = QueryNodeType.All;
                        break;

                    default:
                        this.ThrowError(QueryCompileError.UnsupportedNodeTest);
                        break;
                }
                if (((byte) (axis.ValidNodeTypes & principalNodeType)) == 0)
                {
                    this.ThrowError(QueryCompileError.InvalidNodeType);
                }
                this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidNodeTest);
                this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidNodeTest);
            }
            return new NodeSelectCriteria(axisType, empty, principalNodeType);
        }
コード例 #20
0
ファイル: XPathParser.cs プロジェクト: dox0/DotNet471RS3
        NodeSelectCriteria ParseNodeTest(QueryAxisType axisType)
        {
            Fx.Assert(QueryAxisType.None != axisType, "");

            QueryAxis  axis = QueryDataModel.GetAxis(axisType);
            XPathToken token;
            NodeQName  qname = NodeQName.Empty;

            if (null != (token = this.NextTokenClass(XPathTokenID.NameTest)))
            {
                switch (token.TokenID)
                {
                default:
                    this.ThrowError(QueryCompileError.UnexpectedToken);
                    break;

                case XPathTokenID.Wildcard:
                    qname = new NodeQName(QueryDataModel.Wildcard, QueryDataModel.Wildcard);
                    break;

                case XPathTokenID.NameTest:
                    qname = this.QualifyName(token.Prefix, token.Name);
                    break;

                case XPathTokenID.NameWildcard:
                    qname = this.QualifyName(token.Prefix, QueryDataModel.Wildcard);
                    break;
                }
            }

            QueryNodeType nodeType = QueryNodeType.Any;

            if (qname.IsEmpty)
            {
                // Check for nodeTests
                if (null == (token = this.NextTokenClass(XPathTokenID.NodeType)))
                {
                    // Not a NodeTest either.
                    return(null);
                }

                switch (token.TokenID)
                {
                default:
                    this.ThrowError(QueryCompileError.UnsupportedNodeTest);
                    break;

                case XPathTokenID.Comment:
                    nodeType = QueryNodeType.Comment;
                    break;

                case XPathTokenID.Text:
                    nodeType = QueryNodeType.Text;
                    break;

                case XPathTokenID.Processing:
                    nodeType = QueryNodeType.Processing;
                    break;

                case XPathTokenID.Node:
                    nodeType = QueryNodeType.All;
                    break;
                }

                // Make sure the nodes being selected CAN actually be selected from this axis
                if (0 == (axis.ValidNodeTypes & nodeType))
                {
                    this.ThrowError(QueryCompileError.InvalidNodeType);
                }

                // Eat ()
                this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidNodeTest);
                this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidNodeTest);
            }
            else
            {
                nodeType = axis.PrincipalNodeType;
            }

            return(new NodeSelectCriteria(axisType, qname, nodeType));
        }
コード例 #21
0
 internal bool Equals(NodeQName qname)
 {
     return((qname.name.Length == this.name.Length && qname.name == this.name) && (qname.ns.Length == this.ns.Length && qname.ns == this.ns));
 }