internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topSequenceArg = context.TopSequenceArg;

            Value[] sequences          = context.Sequences;
            bool    sequenceStackInUse = context.SequenceStackInUse;

            context.PushSequenceFrame();
            for (int i = topSequenceArg.basePtr; i <= topSequenceArg.endPtr; i++)
            {
                NodeSequence sequence = sequences[i].Sequence;
                if (sequence.Count == 0)
                {
                    if (!sequenceStackInUse)
                    {
                        context.PushSequence(NodeSequence.Empty);
                    }
                }
                else
                {
                    NodeSequenceItem[] items = sequence.Items;
                    for (int j = 0; j < sequence.Count; j++)
                    {
                        SeekableXPathNavigator contextNode  = items[j].GetNavigator();
                        NodeSequence           destSequence = context.CreateSequence();
                        destSequence.StartNodeset();
                        base.criteria.Select(contextNode, destSequence);
                        destSequence.StopNodeset();
                        context.PushSequence(destSequence);
                    }
                }
            }
            return(base.next);
        }
Example #2
0
        internal override void InvokeInternal(ProcessingContext context, int argCount)
        {
            int iterationCount = context.IterationCount;

            context.PushSequenceFrame();
            if (iterationCount > 0)
            {
                NodeSequence seq = context.CreateSequence();
                seq.StartNodeset();
                SeekableXPathNavigator contextNode = context.Processor.ContextNode;
                long currentPosition = contextNode.CurrentPosition;
                if (XPathMessageFunction.MoveToAddressingHeader(contextNode, "ReplyTo"))
                {
                    seq.Add(contextNode);
                }
                seq.StopNodeset();
                context.PushSequence(seq);
                for (int i = 1; i < iterationCount; i++)
                {
                    seq.refCount++;
                    context.PushSequence(seq);
                }
                contextNode.CurrentPosition = currentPosition;
            }
        }
Example #3
0
        internal override Opcode Eval(ProcessingContext context)
        {
            if (!context.LoadVariable(this.expr.Variable))
            {
                context.PushSequenceFrame();
                NodeSequence seq = context.CreateSequence();
                seq.Add(context.Processor.ContextNode);
                context.PushSequence(seq);

                int marker = context.Processor.CounterMarker;
                try
                {
                    this.expr.Eval(context);
                }
                catch (XPathNavigatorException e)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(e.Process(this));
                }
                catch (NavigatorInvalidBodyAccessException e)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(e.Process(this));
                }
                context.Processor.CounterMarker = marker;
                context.PopSequenceFrame();
                context.PopSequenceFrame();

                context.LoadVariable(this.expr.Variable);
            }
            return(this.next);
        }
 internal override void InvokeInternal(ProcessingContext context, int argCount)
 {
     int iterationCount = context.IterationCount;
     context.PushSequenceFrame();
     if (iterationCount > 0)
     {
         NodeSequence seq = context.CreateSequence();
         seq.StartNodeset();
         SeekableXPathNavigator contextNode = context.Processor.ContextNode;
         long currentPosition = contextNode.CurrentPosition;
         if (XPathMessageFunction.MoveToAddressingHeader(contextNode, "RelatesTo"))
         {
             seq.Add(contextNode);
             while (XPathMessageFunction.MoveToAddressingHeaderSibling(contextNode, "RelatesTo"))
             {
                 seq.Add(contextNode);
             }
         }
         seq.StopNodeset();
         context.PushSequence(seq);
         for (int i = 1; i < iterationCount; i++)
         {
             seq.refCount++;
             context.PushSequence(seq);
         }
         contextNode.CurrentPosition = currentPosition;
     }
 }
 internal override Opcode Eval(ProcessingContext context)
 {
     StackFrame topSequenceArg = context.TopSequenceArg;
     Value[] sequences = context.Sequences;
     bool sequenceStackInUse = context.SequenceStackInUse;
     context.PushSequenceFrame();
     for (int i = topSequenceArg.basePtr; i <= topSequenceArg.endPtr; i++)
     {
         NodeSequence sequence = sequences[i].Sequence;
         if (sequence.Count == 0)
         {
             if (!sequenceStackInUse)
             {
                 context.PushSequence(NodeSequence.Empty);
             }
         }
         else
         {
             NodeSequenceItem[] items = sequence.Items;
             for (int j = 0; j < sequence.Count; j++)
             {
                 SeekableXPathNavigator contextNode = items[j].GetNavigator();
                 NodeSequence destSequence = context.CreateSequence();
                 destSequence.StartNodeset();
                 base.criteria.Select(contextNode, destSequence);
                 destSequence.StopNodeset();
                 context.PushSequence(destSequence);
             }
         }
     }
     return base.next;
 }
 internal override Opcode Eval(ProcessingContext context)
 {
     if (!context.LoadVariable(this.expr.Variable))
     {
         context.PushSequenceFrame();
         NodeSequence seq = context.CreateSequence();
         seq.Add(context.Processor.ContextNode);
         context.PushSequence(seq);
         int counterMarker = context.Processor.CounterMarker;
         try
         {
             this.expr.Eval(context);
         }
         catch (XPathNavigatorException exception)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception.Process(this));
         }
         catch (NavigatorInvalidBodyAccessException exception2)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception2.Process(this));
         }
         context.Processor.CounterMarker = counterMarker;
         context.PopSequenceFrame();
         context.PopSequenceFrame();
         context.LoadVariable(this.expr.Variable);
     }
     return base.next;
 }
Example #7
0
        internal override Opcode Eval(ProcessingContext context)
        {
            // The query processor object also serves as the query document root
            int    iterationCount = context.IterationCount;
            Opcode returnOpcode   = this.next;

            // A root is always an initial step
            context.PushSequenceFrame();
            NodeSequence seq = context.CreateSequence();

            if (this.next != null && 0 != (this.next.Flags & OpcodeFlags.CompressableSelect))
            {
                SeekableXPathNavigator node = context.Processor.ContextNode;
                node.MoveToRoot();
                returnOpcode = this.next.Eval(seq, node);
                while (returnOpcode != null && 0 != (returnOpcode.Flags & OpcodeFlags.CompressableSelect))
                {
                    returnOpcode = returnOpcode.Next;
                }
            }
            else
            {
                // Roots do not have any qnames..
                seq.StartNodeset();
                SeekableXPathNavigator node = context.Processor.ContextNode;
                node.MoveToRoot();
                seq.Add(node);
                seq.StopNodeset();
            }

            if (seq.Count == 0)
            {
                context.ReleaseSequence(seq);
                seq = NodeSequence.Empty;
            }

            for (int i = 0; i < iterationCount; ++i)
            {
                context.PushSequence(seq);
            }
            if (iterationCount > 1)
            {
                seq.refCount += iterationCount - 1;
            }

            return(returnOpcode);
        }
Example #8
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame sequences = context.TopSequenceArg;

            Value[]    values     = context.Values;
            StackFrame resultMask = context.TopArg;

            Value[] sequenceBuffer = context.Sequences;

            context.PushSequenceFrame();
            for (int seqIndex = sequences.basePtr; seqIndex <= sequences.endPtr; ++seqIndex)
            {
                NodeSequence sourceSeq = sequenceBuffer[seqIndex].Sequence;
                if (sourceSeq.Count > 0)
                {
                    NodeSequenceItem[] items  = sourceSeq.Items;
                    NodeSequence       newSeq = null;
                    // Loop over the sequence, selecting those items for which the previous expression returned a result that
                    // matches the test value. Only those items will be processed further
                    // Note that the original position and size information is retained.
                    for (int i = resultMask.basePtr, n = 0; i <= resultMask.endPtr; ++i, ++n)
                    {
                        if (this.test == values[i].Boolean)
                        {
                            if (null == newSeq)
                            {
                                newSeq = context.CreateSequence();
                            }
                            newSeq.AddCopy(ref items[n], NodeSequence.GetContextSize(sourceSeq, n));
                        }
                        else
                        {
                            if (items[n].Last && null != newSeq)
                            {
                                newSeq.Items[newSeq.Count - 1].Last = true; // maintain nodeset boundaries...
                            }
                        }
                    }
                    context.PushSequence((null == newSeq) ? NodeSequence.Empty : newSeq);
                    newSeq = null;
                }
            }

            return(this.next);
        }
Example #9
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topFrame = context.TopSequenceArg;

            Value[] sequences = context.Sequences;

            bool wasInUse = context.SequenceStackInUse;

            context.PushSequenceFrame();
            for (int i = topFrame.basePtr; i <= topFrame.endPtr; ++i)
            {
                NodeSequence sourceSeq = sequences[i].Sequence;
                int          count     = sourceSeq.Count;
                if (count == 0)
                {
                    // Empty sequence.
                    // Since there are no nodes in the sequence, we will track this sequence also
                    // using an empty sequence
                    if (!wasInUse)
                    {
                        context.PushSequence(NodeSequence.Empty);
                    }
                }
                else
                {
                    NodeSequenceItem[] items = sourceSeq.Items;
                    for (int item = 0; item < sourceSeq.Count; ++item)
                    {
                        SeekableXPathNavigator node = items[item].GetNavigator();
                        Fx.Assert(null != node, "");

                        NodeSequence newSeq = context.CreateSequence();
                        newSeq.StartNodeset();

                        this.criteria.Select(node, newSeq);

                        newSeq.StopNodeset();

                        context.PushSequence(newSeq);
                    }
                }
            }
            return(this.next);
        }
        internal bool LoadVariable(ProcessingContext context, int var)
        {
            if (this.subExprVars[var].seq == null)
            {
                return(false);
            }
            int iterationCount = context.IterationCount;

            this.counter.IncreaseBy(iterationCount * this.subExprVars[var].count);
            NodeSequence seq = this.subExprVars[var].seq;

            context.PushSequenceFrame();
            for (int i = 0; i < iterationCount; i++)
            {
                seq.refCount++;
                context.PushSequence(seq);
            }
            return(true);
        }
        internal override Opcode Eval(ProcessingContext context)
        {
            int    iterationCount = context.IterationCount;
            Opcode next           = base.next;

            context.PushSequenceFrame();
            NodeSequence empty = context.CreateSequence();

            if ((base.next != null) && ((base.next.Flags & OpcodeFlags.CompressableSelect) != OpcodeFlags.None))
            {
                SeekableXPathNavigator contextNode = context.Processor.ContextNode;
                contextNode.MoveToRoot();
                next = base.next.Eval(empty, contextNode);
                while ((next != null) && ((next.Flags & OpcodeFlags.CompressableSelect) != OpcodeFlags.None))
                {
                    next = next.Next;
                }
            }
            else
            {
                empty.StartNodeset();
                SeekableXPathNavigator node = context.Processor.ContextNode;
                node.MoveToRoot();
                empty.Add(node);
                empty.StopNodeset();
            }
            if (empty.Count == 0)
            {
                context.ReleaseSequence(empty);
                empty = NodeSequence.Empty;
            }
            for (int i = 0; i < iterationCount; i++)
            {
                context.PushSequence(empty);
            }
            if (iterationCount > 1)
            {
                empty.refCount += iterationCount - 1;
            }
            return(next);
        }
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topSequenceArg = context.TopSequenceArg;

            Value[]    values = context.Values;
            StackFrame topArg = context.TopArg;

            Value[] sequences = context.Sequences;
            context.PushSequenceFrame();
            for (int i = topSequenceArg.basePtr; i <= topSequenceArg.endPtr; i++)
            {
                NodeSequence sequence = sequences[i].Sequence;
                if (sequence.Count > 0)
                {
                    NodeSequenceItem[] items     = sequence.Items;
                    NodeSequence       sequence2 = null;
                    int basePtr = topArg.basePtr;
                    for (int j = 0; basePtr <= topArg.endPtr; j++)
                    {
                        if (this.test == values[basePtr].Boolean)
                        {
                            if (sequence2 == null)
                            {
                                sequence2 = context.CreateSequence();
                            }
                            sequence2.AddCopy(ref items[j], NodeSequence.GetContextSize(sequence, j));
                        }
                        else if (items[j].Last && (sequence2 != null))
                        {
                            sequence2.Items[sequence2.Count - 1].Last = true;
                        }
                        basePtr++;
                    }
                    context.PushSequence((sequence2 == null) ? NodeSequence.Empty : sequence2);
                    sequence2 = null;
                }
            }
            return(base.next);
        }
 internal override Opcode Eval(ProcessingContext context)
 {
     int iterationCount = context.IterationCount;
     Opcode next = base.next;
     context.PushSequenceFrame();
     NodeSequence empty = context.CreateSequence();
     if ((base.next != null) && ((base.next.Flags & OpcodeFlags.CompressableSelect) != OpcodeFlags.None))
     {
         SeekableXPathNavigator contextNode = context.Processor.ContextNode;
         contextNode.MoveToRoot();
         next = base.next.Eval(empty, contextNode);
         while ((next != null) && ((next.Flags & OpcodeFlags.CompressableSelect) != OpcodeFlags.None))
         {
             next = next.Next;
         }
     }
     else
     {
         empty.StartNodeset();
         SeekableXPathNavigator node = context.Processor.ContextNode;
         node.MoveToRoot();
         empty.Add(node);
         empty.StopNodeset();
     }
     if (empty.Count == 0)
     {
         context.ReleaseSequence(empty);
         empty = NodeSequence.Empty;
     }
     for (int i = 0; i < iterationCount; i++)
     {
         context.PushSequence(empty);
     }
     if (iterationCount > 1)
     {
         empty.refCount += iterationCount - 1;
     }
     return next;
 }
 internal override Opcode Eval(ProcessingContext context)
 {
     StackFrame topSequenceArg = context.TopSequenceArg;
     Value[] values = context.Values;
     StackFrame topArg = context.TopArg;
     Value[] sequences = context.Sequences;
     context.PushSequenceFrame();
     for (int i = topSequenceArg.basePtr; i <= topSequenceArg.endPtr; i++)
     {
         NodeSequence sequence = sequences[i].Sequence;
         if (sequence.Count > 0)
         {
             NodeSequenceItem[] items = sequence.Items;
             NodeSequence sequence2 = null;
             int basePtr = topArg.basePtr;
             for (int j = 0; basePtr <= topArg.endPtr; j++)
             {
                 if (this.test == values[basePtr].Boolean)
                 {
                     if (sequence2 == null)
                     {
                         sequence2 = context.CreateSequence();
                     }
                     sequence2.AddCopy(ref items[j], NodeSequence.GetContextSize(sequence, j));
                 }
                 else if (items[j].Last && (sequence2 != null))
                 {
                     sequence2.Items[sequence2.Count - 1].Last = true;
                 }
                 basePtr++;
             }
             context.PushSequence((sequence2 == null) ? NodeSequence.Empty : sequence2);
             sequence2 = null;
         }
     }
     return base.next;
 }
 internal bool LoadVariable(ProcessingContext context, int var)
 {
     if (this.subExprVars[var].seq == null)
     {
         return false;
     }
     int iterationCount = context.IterationCount;
     this.counter.IncreaseBy(iterationCount * this.subExprVars[var].count);
     NodeSequence seq = this.subExprVars[var].seq;
     context.PushSequenceFrame();
     for (int i = 0; i < iterationCount; i++)
     {
         seq.refCount++;
         context.PushSequence(seq);
     }
     return true;
 }
Example #16
0
        internal override void EvalSpecial(ProcessingContext context)
        {
            int marker = context.Processor.CounterMarker;

            if (!context.LoadVariable(this.var))
            {
                XPathMessageContext.HeaderFun.InvokeInternal(context, 0);
                context.SaveVariable(this.var, context.Processor.ElapsedCount(marker));
            }

            // WS, Microsoft, see if we can put this array in the processor to save
            //             an allocation.  Perhaps we can use the variables slot we're going to fill
            NodeSequence[] childSequences = new NodeSequence[this.children.Count];
            NodeSequence   seq            = context.Sequences[context.TopSequenceArg.basePtr].Sequence;

            for (int i = 0; i < this.children.Count; ++i)
            {
                childSequences[i] = context.CreateSequence();
                childSequences[i].StartNodeset();
            }

            // Perform the index
            SeekableXPathNavigator nav = seq[0].GetNavigator();

            if (nav.MoveToFirstChild())
            {
                do
                {
                    if (nav.NodeType == XPathNodeType.Element)
                    {
                        List <SubExpr> lst;
                        string         name = nav.LocalName;
                        string         ns   = nav.NamespaceURI;
                        Dictionary <string, List <SubExpr> > nextLookup;
                        if (this.nameLookup.TryGetValue(ns, out nextLookup))
                        {
                            if (nextLookup.TryGetValue(name, out lst))
                            {
                                for (int i = 0; i < lst.Count; ++i)
                                {
                                    childSequences[this.indexLookup[lst[i]].i].Add(nav);
                                }
                            }

                            if (nextLookup.TryGetValue(QueryDataModel.Wildcard, out lst))
                            {
                                for (int i = 0; i < lst.Count; ++i)
                                {
                                    childSequences[this.indexLookup[lst[i]].i].Add(nav);
                                }
                            }
                        }

                        if (this.nameLookup.TryGetValue(QueryDataModel.Wildcard, out nextLookup))
                        {
                            if (nextLookup.TryGetValue(QueryDataModel.Wildcard, out lst))
                            {
                                for (int i = 0; i < lst.Count; ++i)
                                {
                                    childSequences[this.indexLookup[lst[i]].i].Add(nav);
                                }
                            }
                        }
                    }
                } while (nav.MoveToNext());
            }

            int secondMarker = context.Processor.CounterMarker;

            for (int i = 0; i < this.children.Count; ++i)
            {
                if (this.children[i].useSpecial)
                {
                    childSequences[i].StopNodeset();
                    context.Processor.CounterMarker = secondMarker;
                    context.PushSequenceFrame();
                    context.PushSequence(childSequences[i]);
                    Opcode op = this.children[i].FirstOp.Next;
                    while (op != null)
                    {
                        op = op.Eval(context);
                    }
                    context.SaveVariable(this.children[i].var, context.Processor.ElapsedCount(marker));
                    context.PopSequenceFrame();
                }
                else
                {
                    context.ReleaseSequence(childSequences[i]);
                    //context.SetVariable(this.children[i].Variable, null, 0);
                }
            }

            context.Processor.CounterMarker = marker;
        }
 internal override void EvalSpecial(ProcessingContext context)
 {
     int counterMarker = context.Processor.CounterMarker;
     if (!context.LoadVariable(base.var))
     {
         XPathMessageContext.HeaderFun.InvokeInternal(context, 0);
         context.SaveVariable(base.var, context.Processor.ElapsedCount(counterMarker));
     }
     NodeSequence[] sequenceArray = new NodeSequence[base.children.Count];
     NodeSequence sequence = context.Sequences[context.TopSequenceArg.basePtr].Sequence;
     for (int i = 0; i < base.children.Count; i++)
     {
         sequenceArray[i] = context.CreateSequence();
         sequenceArray[i].StartNodeset();
     }
     SeekableXPathNavigator node = sequence[0].GetNavigator();
     if (node.MoveToFirstChild())
     {
         do
         {
             if (node.NodeType == XPathNodeType.Element)
             {
                 List<SubExpr> list;
                 Dictionary<string, List<SubExpr>> dictionary;
                 string localName = node.LocalName;
                 string namespaceURI = node.NamespaceURI;
                 if (this.nameLookup.TryGetValue(namespaceURI, out dictionary))
                 {
                     if (dictionary.TryGetValue(localName, out list))
                     {
                         for (int k = 0; k < list.Count; k++)
                         {
                             sequenceArray[this.indexLookup[list[k]].i].Add(node);
                         }
                     }
                     if (dictionary.TryGetValue(QueryDataModel.Wildcard, out list))
                     {
                         for (int m = 0; m < list.Count; m++)
                         {
                             sequenceArray[this.indexLookup[list[m]].i].Add(node);
                         }
                     }
                 }
                 if (this.nameLookup.TryGetValue(QueryDataModel.Wildcard, out dictionary) && dictionary.TryGetValue(QueryDataModel.Wildcard, out list))
                 {
                     for (int n = 0; n < list.Count; n++)
                     {
                         sequenceArray[this.indexLookup[list[n]].i].Add(node);
                     }
                 }
             }
         }
         while (node.MoveToNext());
     }
     int num6 = context.Processor.CounterMarker;
     for (int j = 0; j < base.children.Count; j++)
     {
         if (base.children[j].useSpecial)
         {
             sequenceArray[j].StopNodeset();
             context.Processor.CounterMarker = num6;
             context.PushSequenceFrame();
             context.PushSequence(sequenceArray[j]);
             for (Opcode opcode = base.children[j].FirstOp.Next; opcode != null; opcode = opcode.Eval(context))
             {
             }
             context.SaveVariable(base.children[j].var, context.Processor.ElapsedCount(counterMarker));
             context.PopSequenceFrame();
         }
         else
         {
             context.ReleaseSequence(sequenceArray[j]);
         }
     }
     context.Processor.CounterMarker = counterMarker;
 }
        internal override Opcode Eval(ProcessingContext context)
        {
            // The query processor object also serves as the query document root
            int iterationCount = context.IterationCount;
            Opcode returnOpcode = this.next;

            // A root is always an initial step
            context.PushSequenceFrame();
            NodeSequence seq = context.CreateSequence();
            if (this.next != null && 0 != (this.next.Flags & OpcodeFlags.CompressableSelect))
            {
                SeekableXPathNavigator node = context.Processor.ContextNode;
                node.MoveToRoot();
                returnOpcode = this.next.Eval(seq, node);
                while (returnOpcode != null && 0 != (returnOpcode.Flags & OpcodeFlags.CompressableSelect))
                {
                    returnOpcode = returnOpcode.Next;
                }
            }
            else
            {
                // Roots do not have any qnames..
                seq.StartNodeset();
                SeekableXPathNavigator node = context.Processor.ContextNode;
                node.MoveToRoot();
                seq.Add(node);
                seq.StopNodeset();
            }

            if (seq.Count == 0)
            {
                context.ReleaseSequence(seq);
                seq = NodeSequence.Empty;
            }

            for (int i = 0; i < iterationCount; ++i)
            {
                context.PushSequence(seq);
            }
            if (iterationCount > 1)
                seq.refCount += iterationCount - 1;

            return returnOpcode;
        }
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topFrame = context.TopSequenceArg;
            Value[] sequences = context.Sequences;

            bool wasInUse = context.SequenceStackInUse;
            context.PushSequenceFrame();
            for (int i = topFrame.basePtr; i <= topFrame.endPtr; ++i)
            {
                NodeSequence sourceSeq = sequences[i].Sequence;
                int count = sourceSeq.Count;
                if (count == 0)
                {
                    // Empty sequence. 
                    // Since there are no nodes in the sequence, we will track this sequence also 
                    // using an empty sequence 
                    if (!wasInUse)
                        context.PushSequence(NodeSequence.Empty);
                }
                else
                {
                    NodeSequenceItem[] items = sourceSeq.Items;
                    for (int item = 0; item < sourceSeq.Count; ++item)
                    {
                        SeekableXPathNavigator node = items[item].GetNavigator();
                        Fx.Assert(null != node, "");

                        NodeSequence newSeq = context.CreateSequence();
                        newSeq.StartNodeset();

                        this.criteria.Select(node, newSeq);

                        newSeq.StopNodeset();

                        context.PushSequence(newSeq);
                    }
                }
            }
            return this.next;
        }
        internal override void InvokeInternal(ProcessingContext context, int argCount)
        {
            int count = context.IterationCount;
            context.PushSequenceFrame();
            if (count > 0)
            {
                NodeSequence seq = context.CreateSequence();
                seq.StartNodeset();
                SeekableXPathNavigator nav = context.Processor.ContextNode;

                long p = nav.CurrentPosition;
                if (MoveToBody(nav))
                {
                    seq.Add(nav);
                }
                nav.CurrentPosition = p;

                seq.StopNodeset();
                context.PushSequence(seq);
                for (int i = 1; i < count; ++i)
                {
                    seq.refCount++;
                    context.PushSequence(seq);
                }
            }
        }
        internal override void EvalSpecial(ProcessingContext context)
        {
            int marker = context.Processor.CounterMarker;

            if (!context.LoadVariable(this.var))
            {
                XPathMessageContext.HeaderFun.InvokeInternal(context, 0);
                context.SaveVariable(this.var, context.Processor.ElapsedCount(marker));
            }

            // WS, [....], see if we can put this array in the processor to save
            //             an allocation.  Perhaps we can use the variables slot we're going to fill
            NodeSequence[] childSequences = new NodeSequence[this.children.Count];
            NodeSequence seq = context.Sequences[context.TopSequenceArg.basePtr].Sequence;
            for (int i = 0; i < this.children.Count; ++i)
            {
                childSequences[i] = context.CreateSequence();
                childSequences[i].StartNodeset();
            }

            // Perform the index
            SeekableXPathNavigator nav = seq[0].GetNavigator();
            if (nav.MoveToFirstChild())
            {
                do
                {
                    if (nav.NodeType == XPathNodeType.Element)
                    {
                        List<SubExpr> lst;
                        string name = nav.LocalName;
                        string ns = nav.NamespaceURI;
                        Dictionary<string, List<SubExpr>> nextLookup;
                        if (this.nameLookup.TryGetValue(ns, out nextLookup))
                        {
                            if (nextLookup.TryGetValue(name, out lst))
                            {
                                for (int i = 0; i < lst.Count; ++i)
                                {
                                    childSequences[this.indexLookup[lst[i]].i].Add(nav);
                                }
                            }

                            if (nextLookup.TryGetValue(QueryDataModel.Wildcard, out lst))
                            {
                                for (int i = 0; i < lst.Count; ++i)
                                {
                                    childSequences[this.indexLookup[lst[i]].i].Add(nav);
                                }
                            }
                        }

                        if (this.nameLookup.TryGetValue(QueryDataModel.Wildcard, out nextLookup))
                        {
                            if (nextLookup.TryGetValue(QueryDataModel.Wildcard, out lst))
                            {
                                for (int i = 0; i < lst.Count; ++i)
                                {
                                    childSequences[this.indexLookup[lst[i]].i].Add(nav);
                                }
                            }
                        }
                    }
                } while (nav.MoveToNext());
            }

            int secondMarker = context.Processor.CounterMarker;
            for (int i = 0; i < this.children.Count; ++i)
            {
                if (this.children[i].useSpecial)
                {
                    childSequences[i].StopNodeset();
                    context.Processor.CounterMarker = secondMarker;
                    context.PushSequenceFrame();
                    context.PushSequence(childSequences[i]);
                    Opcode op = this.children[i].FirstOp.Next;
                    while (op != null)
                    {
                        op = op.Eval(context);
                    }
                    context.SaveVariable(this.children[i].var, context.Processor.ElapsedCount(marker));
                    context.PopSequenceFrame();
                }
                else
                {
                    context.ReleaseSequence(childSequences[i]);
                    //context.SetVariable(this.children[i].Variable, null, 0);
                }
            }

            context.Processor.CounterMarker = marker;
        }
Example #22
0
        internal override void EvalSpecial(ProcessingContext context)
        {
            int counterMarker = context.Processor.CounterMarker;

            if (!context.LoadVariable(base.var))
            {
                XPathMessageContext.HeaderFun.InvokeInternal(context, 0);
                context.SaveVariable(base.var, context.Processor.ElapsedCount(counterMarker));
            }
            NodeSequence[] sequenceArray = new NodeSequence[base.children.Count];
            NodeSequence   sequence      = context.Sequences[context.TopSequenceArg.basePtr].Sequence;

            for (int i = 0; i < base.children.Count; i++)
            {
                sequenceArray[i] = context.CreateSequence();
                sequenceArray[i].StartNodeset();
            }
            SeekableXPathNavigator node = sequence[0].GetNavigator();

            if (node.MoveToFirstChild())
            {
                do
                {
                    if (node.NodeType == XPathNodeType.Element)
                    {
                        List <SubExpr> list;
                        Dictionary <string, List <SubExpr> > dictionary;
                        string localName    = node.LocalName;
                        string namespaceURI = node.NamespaceURI;
                        if (this.nameLookup.TryGetValue(namespaceURI, out dictionary))
                        {
                            if (dictionary.TryGetValue(localName, out list))
                            {
                                for (int k = 0; k < list.Count; k++)
                                {
                                    sequenceArray[this.indexLookup[list[k]].i].Add(node);
                                }
                            }
                            if (dictionary.TryGetValue(QueryDataModel.Wildcard, out list))
                            {
                                for (int m = 0; m < list.Count; m++)
                                {
                                    sequenceArray[this.indexLookup[list[m]].i].Add(node);
                                }
                            }
                        }
                        if (this.nameLookup.TryGetValue(QueryDataModel.Wildcard, out dictionary) && dictionary.TryGetValue(QueryDataModel.Wildcard, out list))
                        {
                            for (int n = 0; n < list.Count; n++)
                            {
                                sequenceArray[this.indexLookup[list[n]].i].Add(node);
                            }
                        }
                    }
                }while (node.MoveToNext());
            }
            int num6 = context.Processor.CounterMarker;

            for (int j = 0; j < base.children.Count; j++)
            {
                if (base.children[j].useSpecial)
                {
                    sequenceArray[j].StopNodeset();
                    context.Processor.CounterMarker = num6;
                    context.PushSequenceFrame();
                    context.PushSequence(sequenceArray[j]);
                    for (Opcode opcode = base.children[j].FirstOp.Next; opcode != null; opcode = opcode.Eval(context))
                    {
                    }
                    context.SaveVariable(base.children[j].var, context.Processor.ElapsedCount(counterMarker));
                    context.PopSequenceFrame();
                }
                else
                {
                    context.ReleaseSequence(sequenceArray[j]);
                }
            }
            context.Processor.CounterMarker = counterMarker;
        }