private bool ParseRelativePath(XPathExprList path) { XPathStepExpr expr = this.ParseStep(); if (expr == null) { return(false); } path.Add(expr); while (true) { if (this.NextToken(XPathTokenID.Slash) != null) { expr = this.ParseStep(); } else { if (this.NextToken(XPathTokenID.DblSlash) == null) { return(true); } expr = new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.DescendantOrSelf, NodeQName.Empty, QueryNodeType.All)); path.Add(expr); expr = this.ParseStep(); } if (expr == null) { this.ThrowError(QueryCompileError.InvalidLocationPath); } path.Add(expr); } }
private void CompileLocationPath(XPathExpr expr) { XPathStepExpr expr2 = (XPathStepExpr)expr.SubExpr[0]; this.CompileSteps(expr.SubExpr); if (1 == this.compiler.nestingLevel) { this.compiler.SetPushInitialContext(expr2.SelectDesc.Type != QueryNodeType.Root); } }
void CompileLocationPath(XPathExpr expr) { Fx.Assert(expr.SubExprCount > 0, ""); XPathStepExpr firstStep = (XPathStepExpr)expr.SubExpr[0]; this.CompileSteps(expr.SubExpr); if (1 == this.compiler.nestingLevel) { this.compiler.SetPushInitialContext(firstStep.SelectDesc.Type != QueryNodeType.Root); } }
private void CompilePath(XPathExpr expr) { if (expr.Type == XPathExprType.Filter) { this.CompileFilter(expr.SubExpr[0]); } else { this.CompileExpression(expr.SubExpr[0]); if (expr.SubExpr[0].ReturnType == ValueDataType.Sequence) { if (this.IsSpecialInternalFunction(expr.SubExpr[0])) { this.codeBlock.DetachLast(); } else { this.codeBlock.Append(new MergeOpcode()); this.codeBlock.Append(new PopSequenceToSequenceStackOpcode()); } } } if (expr.SubExprCount == 2) { this.CompileRelativePath(expr.SubExpr[1], false); } else if (expr.SubExprCount == 3) { XPathExpr expr2 = expr.SubExpr[1]; XPathStepExpr expr3 = (XPathStepExpr)expr2; if (!expr3.SelectDesc.Axis.IsSupported()) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.UnsupportedAxis)); } this.codeBlock.Append(new SelectOpcode(expr3.SelectDesc)); if (expr3.SubExprCount > 0) { this.compiler.nestingLevel++; if (this.compiler.nestingLevel > 3) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.PredicateNestingTooDeep)); } this.CompilePredicates(expr3.SubExpr); this.compiler.nestingLevel--; } this.CompileRelativePath(expr.SubExpr[2], false); } }
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--; } } }
bool ParseRelativePath(XPathExprList path) { Fx.Assert(null != path, ""); XPathStepExpr step = this.ParseStep(); if (null == step) { return(false); } path.Add(step); while (true) { if (null != this.NextToken(XPathTokenID.Slash)) { step = this.ParseStep(); } else if (null != this.NextToken(XPathTokenID.DblSlash)) { step = new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.DescendantOrSelf, NodeQName.Empty, QueryNodeType.All)); path.Add(step); step = this.ParseStep(); } else { break; } if (null == step) { this.ThrowError(QueryCompileError.InvalidLocationPath); } path.Add(step); } return(true); }
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--; } } }
bool ParseRelativePath(XPathExprList path) { Fx.Assert(null != path, ""); XPathStepExpr step = this.ParseStep(); if (null == step) { return false; } path.Add(step); while (true) { if (null != this.NextToken(XPathTokenID.Slash)) { step = this.ParseStep(); } else if (null != this.NextToken(XPathTokenID.DblSlash)) { step = new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.DescendantOrSelf, NodeQName.Empty, QueryNodeType.All)); path.Add(step); step = this.ParseStep(); } else { break; } if (null == step) { this.ThrowError(QueryCompileError.InvalidLocationPath); } path.Add(step); } return true; }
void CompilePath(XPathExpr expr) { Fx.Assert(expr.SubExprCount == 2 || expr.SubExprCount == 3, ""); if (expr.Type == XPathExprType.Filter) { this.CompileFilter(expr.SubExpr[0]); } else { this.CompileExpression(expr.SubExpr[0]); if (expr.SubExpr[0].ReturnType == ValueDataType.Sequence) { if (IsSpecialInternalFunction(expr.SubExpr[0])) { this.codeBlock.DetachLast(); } else { this.codeBlock.Append(new MergeOpcode()); this.codeBlock.Append(new PopSequenceToSequenceStackOpcode()); } } } if (expr.SubExprCount == 2) { this.CompileRelativePath(expr.SubExpr[1], false); } else if (expr.SubExprCount == 3) { // Compile the step XPathExpr e = expr.SubExpr[1]; Fx.Assert(XPathExprType.PathStep == e.Type, ""); XPathStepExpr step = (XPathStepExpr)e; Fx.Assert(QueryNodeType.Root != step.SelectDesc.Type, ""); if (!step.SelectDesc.Axis.IsSupported()) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryCompileException(QueryCompileError.UnsupportedAxis)); } this.codeBlock.Append(new SelectOpcode(step.SelectDesc)); // 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--; } // Compile the relative path this.CompileRelativePath(expr.SubExpr[2], false); } }
private bool ParseRelativePath(XPathExprList path) { XPathStepExpr expr = this.ParseStep(); if (expr == null) { return false; } path.Add(expr); while (true) { if (this.NextToken(XPathTokenID.Slash) != null) { expr = this.ParseStep(); } else { if (this.NextToken(XPathTokenID.DblSlash) == null) { return true; } expr = new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.DescendantOrSelf, NodeQName.Empty, QueryNodeType.All)); path.Add(expr); expr = this.ParseStep(); } if (expr == null) { this.ThrowError(QueryCompileError.InvalidLocationPath); } path.Add(expr); } }