void CompileSteps(XPathExprList steps, bool start) { for (int i = 0; i < steps.Count; ++i) { Fx.Assert(XPathExprType.PathStep == steps[i].Type, ""); XPathStepExpr step = (XPathStepExpr)steps[i]; if (!step.SelectDesc.Axis.IsSupported()) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.UnsupportedAxis)); } Opcode stepOpcode = null; if (start && 0 == i) { // First steps // Is this an absolute path? We have an absolute path if the first step selects the root if (QueryNodeType.Root == step.SelectDesc.Type) { stepOpcode = new SelectRootOpcode(); } else { stepOpcode = new InitialSelectOpcode(step.SelectDesc); } } else { Fx.Assert(QueryNodeType.Root != step.SelectDesc.Type, ""); stepOpcode = new SelectOpcode(step.SelectDesc); } this.codeBlock.Append(stepOpcode); // The step may have predicates.. if (step.SubExprCount > 0) { this.compiler.nestingLevel++; if (this.compiler.nestingLevel > 3) // throw if we find something deepter than [ [ ] ] { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.PredicateNestingTooDeep)); } this.CompilePredicates(step.SubExpr); this.compiler.nestingLevel--; } } }
private void CompileSteps(XPathExprList steps, bool start) { for (int i = 0; i < steps.Count; i++) { XPathStepExpr expr = (XPathStepExpr)steps[i]; if (!expr.SelectDesc.Axis.IsSupported()) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.UnsupportedAxis)); } Opcode opcode = null; if (start && (i == 0)) { if (QueryNodeType.Root == expr.SelectDesc.Type) { opcode = new SelectRootOpcode(); } else { opcode = new InitialSelectOpcode(expr.SelectDesc); } } else { opcode = new SelectOpcode(expr.SelectDesc); } this.codeBlock.Append(opcode); if (expr.SubExprCount > 0) { this.compiler.nestingLevel++; if (this.compiler.nestingLevel > 3) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.PredicateNestingTooDeep)); } this.CompilePredicates(expr.SubExpr); this.compiler.nestingLevel--; } } }
internal Opcode Select(SeekableXPathNavigator contextNode, NodeSequence destSequence, SelectOpcode next) { Opcode returnOpcode = next.Next; switch (this.type) { default: if (QueryAxisType.Self == this.axis.Type) { if (this.MatchType(contextNode) && this.MatchQName(contextNode)) { long position = contextNode.CurrentPosition; returnOpcode = next.Eval(destSequence, contextNode); contextNode.CurrentPosition = position; } } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.Unexpected)); } break; case QueryNodeType.ChildNodes: // Select children of arbitrary type off the context node if (contextNode.MoveToFirstChild()) { do { // Select the node if its type and qname matches if (this.MatchType(contextNode) && this.MatchQName(contextNode)) { destSequence.Add(contextNode); } } while (contextNode.MoveToNext()); } break; case QueryNodeType.Element: // Select child elements if (contextNode.MoveToFirstChild()) { do { // Children could have non element nodes in line // Select the node if it is an element and the qname matches if (XPathNodeType.Element == contextNode.NodeType && this.MatchQName(contextNode)) { long position = contextNode.CurrentPosition; returnOpcode = next.Eval(destSequence, contextNode); contextNode.CurrentPosition = position; } } while (contextNode.MoveToNext()); } break; case QueryNodeType.Root: contextNode.MoveToRoot(); returnOpcode = next.Eval(destSequence, contextNode); break; } return returnOpcode; }
internal Opcode Select(SeekableXPathNavigator contextNode, NodeSequence destSequence, SelectOpcode next) { Opcode returnOpcode = next.Next; switch (this.type) { default: if (QueryAxisType.Self == this.axis.Type) { if (this.MatchType(contextNode) && this.MatchQName(contextNode)) { long position = contextNode.CurrentPosition; returnOpcode = next.Eval(destSequence, contextNode); contextNode.CurrentPosition = position; } } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.Unexpected)); } break; case QueryNodeType.ChildNodes: // Select children of arbitrary type off the context node if (contextNode.MoveToFirstChild()) { do { // Select the node if its type and qname matches if (this.MatchType(contextNode) && this.MatchQName(contextNode)) { destSequence.Add(contextNode); } }while (contextNode.MoveToNext()); } break; case QueryNodeType.Element: // Select child elements if (contextNode.MoveToFirstChild()) { do { // Children could have non element nodes in line // Select the node if it is an element and the qname matches if (XPathNodeType.Element == contextNode.NodeType && this.MatchQName(contextNode)) { long position = contextNode.CurrentPosition; returnOpcode = next.Eval(destSequence, contextNode); contextNode.CurrentPosition = position; } } while (contextNode.MoveToNext()); } break; case QueryNodeType.Root: contextNode.MoveToRoot(); returnOpcode = next.Eval(destSequence, contextNode); break; } return(returnOpcode); }
internal Opcode Select(SeekableXPathNavigator contextNode, NodeSequence destSequence, SelectOpcode next) { Opcode opcode = next.Next; switch (this.type) { case QueryNodeType.Root: contextNode.MoveToRoot(); return next.Eval(destSequence, contextNode); case QueryNodeType.Element: if (contextNode.MoveToFirstChild()) { do { if ((XPathNodeType.Element == contextNode.NodeType) && this.MatchQName(contextNode)) { long currentPosition = contextNode.CurrentPosition; opcode = next.Eval(destSequence, contextNode); contextNode.CurrentPosition = currentPosition; } } while (contextNode.MoveToNext()); } return opcode; case QueryNodeType.ChildNodes: if (contextNode.MoveToFirstChild()) { do { if (this.MatchType(contextNode) && this.MatchQName(contextNode)) { destSequence.Add(contextNode); } } while (contextNode.MoveToNext()); } return opcode; } if (QueryAxisType.Self != this.axis.Type) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.Unexpected)); } if (this.MatchType(contextNode) && this.MatchQName(contextNode)) { long num = contextNode.CurrentPosition; opcode = next.Eval(destSequence, contextNode); contextNode.CurrentPosition = num; } return opcode; }
private void CompileSteps(XPathExprList steps, bool start) { for (int i = 0; i < steps.Count; i++) { XPathStepExpr expr = (XPathStepExpr) steps[i]; if (!expr.SelectDesc.Axis.IsSupported()) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.UnsupportedAxis)); } Opcode opcode = null; if (start && (i == 0)) { if (QueryNodeType.Root == expr.SelectDesc.Type) { opcode = new SelectRootOpcode(); } else { opcode = new InitialSelectOpcode(expr.SelectDesc); } } else { opcode = new SelectOpcode(expr.SelectDesc); } this.codeBlock.Append(opcode); if (expr.SubExprCount > 0) { this.compiler.nestingLevel++; if (this.compiler.nestingLevel > 3) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.PredicateNestingTooDeep)); } this.CompilePredicates(expr.SubExpr); this.compiler.nestingLevel--; } } }
internal Opcode Select(SeekableXPathNavigator contextNode, NodeSequence destSequence, SelectOpcode next) { Opcode opcode = next.Next; switch (this.type) { case QueryNodeType.Root: contextNode.MoveToRoot(); return(next.Eval(destSequence, contextNode)); case QueryNodeType.Element: if (contextNode.MoveToFirstChild()) { do { if ((XPathNodeType.Element == contextNode.NodeType) && this.MatchQName(contextNode)) { long currentPosition = contextNode.CurrentPosition; opcode = next.Eval(destSequence, contextNode); contextNode.CurrentPosition = currentPosition; } }while (contextNode.MoveToNext()); } return(opcode); case QueryNodeType.ChildNodes: if (contextNode.MoveToFirstChild()) { do { if (this.MatchType(contextNode) && this.MatchQName(contextNode)) { destSequence.Add(contextNode); } }while (contextNode.MoveToNext()); } return(opcode); } if (QueryAxisType.Self != this.axis.Type) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.Unexpected)); } if (this.MatchType(contextNode) && this.MatchQName(contextNode)) { long num = contextNode.CurrentPosition; opcode = next.Eval(destSequence, contextNode); contextNode.CurrentPosition = num; } return(opcode); }