Ejemplo n.º 1
0
        internal static void SubstringLimit(ProcessingContext context)
        {
            StackFrame topArg    = context.TopArg;
            StackFrame secondArg = context.SecondArg;
            StackFrame frame3    = context[2];

            while (topArg.basePtr <= topArg.endPtr)
            {
                string str2;
                string str        = context.PeekString(topArg.basePtr);
                int    startIndex = ((int)Math.Round(context.PeekDouble(secondArg.basePtr))) - 1;
                if (startIndex < 0)
                {
                    startIndex = 0;
                }
                int length = (int)Math.Round(context.PeekDouble(frame3.basePtr));
                if ((length < 1) || ((startIndex + length) >= str.Length))
                {
                    str2 = string.Empty;
                }
                else
                {
                    str2 = str.Substring(startIndex, length);
                }
                context.SetValue(context, frame3.basePtr, str2);
                secondArg.basePtr++;
                topArg.basePtr++;
                frame3.basePtr++;
            }
            context.PopFrame();
            context.PopFrame();
        }
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topArg = context.TopArg;
            int        count  = topArg.Count;

            if (count > 0)
            {
                QueryBranchResultSet resultTable = context.Processor.CreateResultSet();
                BranchMatcher        matcher     = new BranchMatcher(count, resultTable);
                for (int i = 0; i < count; i++)
                {
                    this.CollectMatches(i, ref context.Values[topArg[i]], resultTable);
                }
                context.PopFrame();
                if (resultTable.Count > 1)
                {
                    resultTable.Sort();
                }
                if ((this.alwaysBranches != null) && (this.alwaysBranches.Count > 0))
                {
                    matcher.InvokeNonMatches(context, this.alwaysBranches);
                }
                matcher.InvokeMatches(context);
                matcher.Release(context);
            }
            else
            {
                context.PopFrame();
            }
            return(base.next);
        }
Ejemplo n.º 3
0
        internal static void Translate(ProcessingContext context)
        {
            StackFrame    topArg    = context.TopArg;
            StackFrame    secondArg = context.SecondArg;
            StackFrame    frame3    = context[2];
            StringBuilder builder   = new StringBuilder();

            while (topArg.basePtr <= topArg.endPtr)
            {
                builder.Length = 0;
                string str  = context.PeekString(topArg.basePtr);
                string str2 = context.PeekString(secondArg.basePtr);
                string str3 = context.PeekString(frame3.basePtr);
                for (int i = 0; i < str.Length; i++)
                {
                    char ch    = str[i];
                    int  index = str2.IndexOf(ch);
                    if (index < 0)
                    {
                        builder.Append(ch);
                    }
                    else if (index < str3.Length)
                    {
                        builder.Append(str3[index]);
                    }
                }
                context.SetValue(context, frame3.basePtr, builder.ToString());
                topArg.basePtr++;
                secondArg.basePtr++;
                frame3.basePtr++;
            }
            context.PopFrame();
            context.PopFrame();
        }
Ejemplo n.º 4
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topFrame = context.TopArg;
            bool       match    = false;

            if (1 == topFrame.Count)
            {
                match = context.Values[topFrame.basePtr].ToBoolean();
            }
            else
            {
                context.Processor.Result = false;
                for (int i = topFrame.basePtr; i <= topFrame.endPtr; ++i)
                {
                    if (context.Values[i].ToBoolean())
                    {
                        match = true;
                        break;
                    }
                }
            }

            if (match)
            {
                ICollection <MessageFilter> matches = context.Processor.MatchSet;

                for (int i = 0, count = this.results.Count; i < count; ++i)
                {
                    matches.Add((MessageFilter)this.results[i]);
                }
            }

            context.PopFrame();
            return(this.next);
        }
Ejemplo n.º 5
0
        internal override void Eval(ProcessingContext context)
        {
            Fx.Assert(context != null, "");

            StackFrame[] args = new StackFrame[argCount];
            for (int i = 0; i < this.argCount; ++i)
            {
                args[i] = context[i];
            }

            StringBuilder builder = new StringBuilder();

            while (args[0].basePtr <= args[0].endPtr)
            {
                builder.Length = 0;

                for (int i = 0; i < this.argCount; ++i)
                {
                    builder.Append(context.PeekString(args[i].basePtr));
                }

                context.SetValue(context, args[this.argCount - 1].basePtr, builder.ToString());
                for (int i = 0; i < this.argCount; ++i)
                {
                    args[i].basePtr++;
                }
            }

            for (int i = 0; i < this.argCount - 1; ++i)
            {
                context.PopFrame();
            }
        }
        internal override Opcode Eval(ProcessingContext context)
        {
            XPathResult result;
            StackFrame topArg = context.TopArg;
            switch (context.Values[topArg.basePtr].Type)
            {
                case ValueDataType.Boolean:
                    result = new XPathResult(context.Values[topArg.basePtr].GetBoolean());
                    break;

                case ValueDataType.Double:
                    result = new XPathResult(context.Values[topArg.basePtr].GetDouble());
                    break;

                case ValueDataType.Sequence:
                {
                    SafeNodeSequenceIterator nodeSetResult = new SafeNodeSequenceIterator(context.Values[topArg.basePtr].GetSequence(), context);
                    result = new XPathResult(nodeSetResult);
                    break;
                }
                case ValueDataType.String:
                    result = new XPathResult(context.Values[topArg.basePtr].GetString());
                    break;

                default:
                    throw Fx.AssertAndThrow("Unexpected result type.");
            }
            context.Processor.ResultSet.Add(new KeyValuePair<MessageQuery, XPathResult>((MessageQuery) this.results[0], result));
            for (int i = 1; i < this.results.Count; i++)
            {
                context.Processor.ResultSet.Add(new KeyValuePair<MessageQuery, XPathResult>((MessageQuery) this.results[i], result.Copy()));
            }
            context.PopFrame();
            return base.next;
        }
Ejemplo n.º 7
0
        internal static void StringConcatThree(ProcessingContext context)
        {
            StackFrame frame  = context[0];
            StackFrame frame2 = context[1];
            StackFrame frame3 = context[2];

            while (frame.basePtr <= frame.endPtr)
            {
                context.SetValue(context, frame3.basePtr, context.PeekString(frame.basePtr) + context.PeekString(frame2.basePtr) + context.PeekString(frame3.basePtr));
                frame.basePtr++;
                frame2.basePtr++;
                frame3.basePtr++;
            }
            context.PopFrame();
            context.PopFrame();
        }
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topArg = context.TopArg;
            bool       flag   = false;

            if (1 == topArg.Count)
            {
                flag = context.Values[topArg.basePtr].ToBoolean();
            }
            else
            {
                context.Processor.Result = false;
                for (int i = topArg.basePtr; i <= topArg.endPtr; i++)
                {
                    if (context.Values[i].ToBoolean())
                    {
                        flag = true;
                        break;
                    }
                }
            }
            if (flag)
            {
                ICollection <MessageFilter> matchSet = context.Processor.MatchSet;
                int num2  = 0;
                int count = this.results.Count;
                while (num2 < count)
                {
                    matchSet.Add((MessageFilter)this.results[num2]);
                    num2++;
                }
            }
            context.PopFrame();
            return(base.next);
        }
 internal override Opcode Eval(ProcessingContext context)
 {
     StackFrame topArg = context.TopArg;
     bool flag = false;
     if (1 == topArg.Count)
     {
         flag = context.Values[topArg.basePtr].ToBoolean();
     }
     else
     {
         context.Processor.Result = false;
         for (int i = topArg.basePtr; i <= topArg.endPtr; i++)
         {
             if (context.Values[i].ToBoolean())
             {
                 flag = true;
                 break;
             }
         }
     }
     if (flag)
     {
         ICollection<MessageFilter> matchSet = context.Processor.MatchSet;
         int num2 = 0;
         int count = this.results.Count;
         while (num2 < count)
         {
             matchSet.Add((MessageFilter) this.results[num2]);
             num2++;
         }
     }
     context.PopFrame();
     return base.next;
 }
        internal override void Eval(ProcessingContext context)
        {
            StackFrame[] frameArray = new StackFrame[this.argCount];
            for (int i = 0; i < this.argCount; i++)
            {
                frameArray[i] = context[i];
            }
            StringBuilder builder = new StringBuilder();

            while (frameArray[0].basePtr <= frameArray[0].endPtr)
            {
                builder.Length = 0;
                for (int k = 0; k < this.argCount; k++)
                {
                    builder.Append(context.PeekString(frameArray[k].basePtr));
                }
                context.SetValue(context, frameArray[this.argCount - 1].basePtr, builder.ToString());
                for (int m = 0; m < this.argCount; m++)
                {
                    frameArray[m].basePtr++;
                }
            }
            for (int j = 0; j < (this.argCount - 1); j++)
            {
                context.PopFrame();
            }
        }
        internal override Opcode Eval(ProcessingContext context)
        {
            XPathResult result;
            StackFrame topArg = context.TopArg;
            switch (context.Values[topArg.basePtr].Type)
            {
                case ValueDataType.Boolean:
                    result = new XPathResult(context.Values[topArg.basePtr].GetBoolean());
                    break;

                case ValueDataType.Double:
                    result = new XPathResult(context.Values[topArg.basePtr].GetDouble());
                    break;

                case ValueDataType.Sequence:
                {
                    SafeNodeSequenceIterator nodeSetResult = new SafeNodeSequenceIterator(context.Values[topArg.basePtr].GetSequence(), context);
                    result = new XPathResult(nodeSetResult);
                    break;
                }
                case ValueDataType.String:
                    result = new XPathResult(context.Values[topArg.basePtr].GetString());
                    break;

                default:
                    throw Fx.AssertAndThrow("Unexpected result type.");
            }
            context.Processor.QueryResult = result;
            context.PopFrame();
            return base.next;
        }
 internal override void Eval(ProcessingContext context)
 {
     StackFrame[] frameArray = new StackFrame[this.argCount];
     for (int i = 0; i < this.argCount; i++)
     {
         frameArray[i] = context[i];
     }
     StringBuilder builder = new StringBuilder();
     while (frameArray[0].basePtr <= frameArray[0].endPtr)
     {
         builder.Length = 0;
         for (int k = 0; k < this.argCount; k++)
         {
             builder.Append(context.PeekString(frameArray[k].basePtr));
         }
         context.SetValue(context, frameArray[this.argCount - 1].basePtr, builder.ToString());
         for (int m = 0; m < this.argCount; m++)
         {
             frameArray[m].basePtr++;
         }
     }
     for (int j = 0; j < (this.argCount - 1); j++)
     {
         context.PopFrame();
     }
 }
 internal override Opcode Eval(ProcessingContext context)
 {
     int num = this.UpdateResultMask(context);
     context.PopFrame();
     if (num == 0)
     {
         return base.Jump;
     }
     return base.next;
 }
Ejemplo n.º 14
0
        internal static void StringConcatThree(ProcessingContext context)
        {
            StackFrame arg1 = context[0];
            StackFrame arg2 = context[1];
            StackFrame arg3 = context[2];

            while (arg1.basePtr <= arg1.endPtr)
            {
                string str1 = context.PeekString(arg1.basePtr);
                string str2 = context.PeekString(arg2.basePtr);
                string str3 = context.PeekString(arg3.basePtr);
                context.SetValue(context, arg3.basePtr, str1 + str2 + str3);
                arg1.basePtr++;
                arg2.basePtr++;
                arg3.basePtr++;
            }
            context.PopFrame();
            context.PopFrame();
        }
        internal override Opcode Eval(ProcessingContext context)
        {
            int num = this.UpdateResultMask(context);

            context.PopFrame();
            if (num == 0)
            {
                return(base.Jump);
            }
            return(base.next);
        }
Ejemplo n.º 16
0
        internal override Opcode Eval(ProcessingContext context)
        {
            int matchCount = this.UpdateResultMask(context);

            context.PopFrame();
            if (0 == matchCount)
            {
                return(this.Jump);
            }

            return(this.next);
        }
Ejemplo n.º 17
0
        internal override Opcode Eval(ProcessingContext context)
        {
            Fx.Assert(this.results.Count > 0, "QueryMultipleQueryResultOpcode in the eval tree but no query present");
            Fx.Assert(context.Processor.ResultSet != null, "QueryMultipleQueryResultOpcode should only be used in eval cases");

            StackFrame    topFrame   = context.TopArg;
            ValueDataType resultType = context.Values[topFrame.basePtr].Type;
            XPathResult   result;

            switch (resultType)
            {
            case ValueDataType.Sequence:
            {
                SafeNodeSequenceIterator value = new SafeNodeSequenceIterator(context.Values[topFrame.basePtr].GetSequence(), context);
                result = new XPathResult(value);
            }
            break;

            case ValueDataType.Boolean:
            {
                bool value = context.Values[topFrame.basePtr].GetBoolean();
                result = new XPathResult(value);
            }
            break;

            case ValueDataType.String:
            {
                string value = context.Values[topFrame.basePtr].GetString();
                result = new XPathResult(value);
            }
            break;

            case ValueDataType.Double:
            {
                double value = context.Values[topFrame.basePtr].GetDouble();
                result = new XPathResult(value);
            }
            break;

            default:
                throw Fx.AssertAndThrow("Unexpected result type.");
            }

            context.Processor.ResultSet.Add(new KeyValuePair <MessageQuery, XPathResult>((MessageQuery)this.results[0], result));

            for (int i = 1; i < this.results.Count; i++)
            {
                context.Processor.ResultSet.Add(new KeyValuePair <MessageQuery, XPathResult>((MessageQuery)this.results[i], result.Copy()));
            }

            context.PopFrame();
            return(this.next);
        }
Ejemplo n.º 18
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame arg      = context.TopArg;
            int        argCount = arg.Count;

            if (argCount > 0)
            {
                QueryBranchResultSet resultSet = context.Processor.CreateResultSet();
                BranchMatcher        matcher   = new BranchMatcher(argCount, resultSet);
                // Operate on values at the the top frame of the value stack
                // For each source value, find the branch that could be taken
                for (int i = 0; i < argCount; ++i)
                {
                    this.CollectMatches(i, ref context.Values[arg[i]], resultSet);
                }
                // Done with whatever we were testing equality against
                context.PopFrame();
                if (resultSet.Count > 1)
                {
                    // Sort results
                    resultSet.Sort();
                }

                // First, do non-true branches..
                if (null != this.alwaysBranches && this.alwaysBranches.Count > 0)
                {
                    matcher.InvokeNonMatches(context, this.alwaysBranches);
                }

                // Iterate through matches, invoking each matched branch
                matcher.InvokeMatches(context);

                matcher.Release(context);
            }
            else
            {
                context.PopFrame();
            }
            return(this.next);
        }
Ejemplo n.º 19
0
        internal static void Translate(ProcessingContext context)
        {
            StackFrame argSource = context.TopArg;
            StackFrame argKeys   = context.SecondArg;
            StackFrame argValues = context[2];

            // PERF, [....], this is really slow.
            StringBuilder builder = new StringBuilder();

            while (argSource.basePtr <= argSource.endPtr)
            {
                builder.Length = 0;

                string source = context.PeekString(argSource.basePtr);
                string keys   = context.PeekString(argKeys.basePtr);
                string values = context.PeekString(argValues.basePtr);
                for (int i = 0; i < source.Length; ++i)
                {
                    char c   = source[i];
                    int  idx = keys.IndexOf(c);
                    if (idx < 0)
                    {
                        builder.Append(c);
                    }
                    else if (idx < values.Length)
                    {
                        builder.Append(values[idx]);
                    }
                }
                context.SetValue(context, argValues.basePtr, builder.ToString());
                argSource.basePtr++;
                argKeys.basePtr++;
                argValues.basePtr++;
            }

            context.PopFrame();
            context.PopFrame();
        }
 internal override Opcode Eval(ProcessingContext context)
 {
     StackFrame topArg = context.TopArg;
     StackFrame secondArg = context.SecondArg;
     Value[] values = context.Values;
     while (topArg.basePtr <= topArg.endPtr)
     {
         values[secondArg.basePtr].Update(context, values[secondArg.basePtr].CompareTo(ref values[topArg.basePtr], this.op));
         topArg.basePtr++;
         secondArg.basePtr++;
     }
     context.PopFrame();
     return base.next;
 }
 internal override Opcode Eval(ProcessingContext context)
 {
     StackFrame topArg = context.TopArg;
     StackFrame secondArg = context.SecondArg;
     Value[] values = context.Values;
     int basePtr = topArg.basePtr;
     for (int i = secondArg.basePtr; basePtr <= topArg.endPtr; i++)
     {
         values[i].Add(values[basePtr].Double);
         basePtr++;
     }
     context.PopFrame();
     return base.next;
 }
Ejemplo n.º 22
0
        internal static void SubstringLimit(ProcessingContext context)
        {
            StackFrame argString  = context.TopArg;
            StackFrame argStartAt = context.SecondArg;
            StackFrame argLimit   = context[2];

            Fx.Assert(argString.Count == argStartAt.Count, "");
            Fx.Assert(argString.Count == argLimit.Count, "");

            while (argString.basePtr <= argString.endPtr)
            {
                string str     = context.PeekString(argString.basePtr);
                int    startAt = ((int)Math.Round(context.PeekDouble(argStartAt.basePtr))) - 1;
                if (startAt < 0)
                {
                    startAt = 0;
                }
                int length = (int)Math.Round(context.PeekDouble(argLimit.basePtr));

                string substr;
                if (length < 1 || ((startAt + length) >= str.Length))
                {
                    substr = string.Empty;
                }
                else
                {
                    substr = str.Substring(startAt, length);
                }
                context.SetValue(context, argLimit.basePtr, substr);
                argStartAt.basePtr++;
                argString.basePtr++;
                argLimit.basePtr++;
            }

            context.PopFrame();
            context.PopFrame();
        }
Ejemplo n.º 23
0
        internal static void StringStartsWith(ProcessingContext context)
        {
            StackFrame topArg    = context.TopArg;
            StackFrame secondArg = context.SecondArg;

            while (topArg.basePtr <= topArg.endPtr)
            {
                string str  = context.PeekString(topArg.basePtr);
                string str2 = context.PeekString(secondArg.basePtr);
                context.SetValue(context, secondArg.basePtr, str.StartsWith(str2, StringComparison.Ordinal));
                topArg.basePtr++;
                secondArg.basePtr++;
            }
            context.PopFrame();
        }
Ejemplo n.º 24
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topArg    = context.TopArg;
            StackFrame secondArg = context.SecondArg;

            Value[] values = context.Values;
            while (topArg.basePtr <= topArg.endPtr)
            {
                values[secondArg.basePtr].Update(context, values[secondArg.basePtr].CompareTo(ref values[topArg.basePtr], this.op));
                topArg.basePtr++;
                secondArg.basePtr++;
            }
            context.PopFrame();
            return(base.next);
        }
 internal override Opcode Eval(ProcessingContext context)
 {
     StackFrame topArg = context.TopArg;
     StackFrame secondArg = context.SecondArg;
     int basePtr = topArg.basePtr;
     for (int i = secondArg.basePtr; basePtr <= topArg.endPtr; i++)
     {
         NodeSequence otherSeq = context.Values[basePtr].Sequence;
         NodeSequence sequence = context.Values[i].Sequence;
         context.SetValue(context, i, sequence.Union(context, otherSeq));
         basePtr++;
     }
     context.PopFrame();
     return base.next;
 }
Ejemplo n.º 26
0
        internal static void StringStartsWith(ProcessingContext context)
        {
            StackFrame arg1 = context.TopArg;
            StackFrame arg2 = context.SecondArg;

            Fx.Assert(arg1.Count == arg2.Count, "");
            while (arg1.basePtr <= arg1.endPtr)
            {
                string leftString  = context.PeekString(arg1.basePtr);
                string rightString = context.PeekString(arg2.basePtr);
                context.SetValue(context, arg2.basePtr, leftString.StartsWith(rightString, StringComparison.Ordinal));
                arg1.basePtr++;
                arg2.basePtr++;
            }
            context.PopFrame();
        }
Ejemplo n.º 27
0
        internal static void SubstringBefore(ProcessingContext context)
        {
            StackFrame topArg    = context.TopArg;
            StackFrame secondArg = context.SecondArg;

            while (topArg.basePtr <= topArg.endPtr)
            {
                string str   = context.PeekString(topArg.basePtr);
                string str2  = context.PeekString(secondArg.basePtr);
                int    index = str.IndexOf(str2, StringComparison.Ordinal);
                context.SetValue(context, secondArg.basePtr, (index == -1) ? string.Empty : str.Substring(0, index));
                topArg.basePtr++;
                secondArg.basePtr++;
            }
            context.PopFrame();
        }
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topArg    = context.TopArg;
            StackFrame secondArg = context.SecondArg;

            Value[] values  = context.Values;
            int     basePtr = topArg.basePtr;

            for (int i = secondArg.basePtr; basePtr <= topArg.endPtr; i++)
            {
                values[i].Add(values[basePtr].Double);
                basePtr++;
            }
            context.PopFrame();
            return(base.next);
        }
Ejemplo n.º 29
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topArg    = context.TopArg;
            StackFrame secondArg = context.SecondArg;
            int        basePtr   = topArg.basePtr;

            for (int i = secondArg.basePtr; basePtr <= topArg.endPtr; i++)
            {
                NodeSequence otherSeq = context.Values[basePtr].Sequence;
                NodeSequence sequence = context.Values[i].Sequence;
                context.SetValue(context, i, sequence.Union(context, otherSeq));
                basePtr++;
            }
            context.PopFrame();
            return(base.next);
        }
Ejemplo n.º 30
0
        internal static void SubstringAfter(ProcessingContext context)
        {
            StackFrame arg1 = context.TopArg;
            StackFrame arg2 = context.SecondArg;

            Fx.Assert(arg1.Count == arg2.Count, "");
            while (arg1.basePtr <= arg1.endPtr)
            {
                string str1 = context.PeekString(arg1.basePtr);
                string str2 = context.PeekString(arg2.basePtr);
                int    idx  = str1.IndexOf(str2, StringComparison.Ordinal);
                context.SetValue(context, arg2.basePtr, idx == -1 ? string.Empty : str1.Substring(idx + str2.Length));
                arg1.basePtr++;
                arg2.basePtr++;
            }
            context.PopFrame();
        }
Ejemplo n.º 31
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame argX = context.TopArg;
            StackFrame argY = context.SecondArg;

            Fx.Assert(argX.Count == argY.Count, "");

            Value[] values = context.Values;
            while (argX.basePtr <= argX.endPtr)
            {
                values[argY.basePtr].Update(context, values[argY.basePtr].CompareTo(ref values[argX.basePtr], op));
                argX.basePtr++;
                argY.basePtr++;
            }

            context.PopFrame();
            return this.next;
        }
Ejemplo n.º 32
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame argX = context.TopArg;
            StackFrame argY = context.SecondArg;

            Value[] values = context.Values;

            Fx.Assert(argX.Count == argY.Count, "");
            for (int x = argX.basePtr, y = argY.basePtr; x <= argX.endPtr; ++x, ++y)
            {
                Fx.Assert(values[x].IsType(ValueDataType.Double), "");
                Fx.Assert(values[y].IsType(ValueDataType.Double), "");
                values[y].Double = values[x].Double % values[y].Double;
            }

            context.PopFrame();
            return(this.next);
        }
Ejemplo n.º 33
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame argX = context.TopArg;
            StackFrame argY = context.SecondArg;
            Fx.Assert(argX.Count == argY.Count, "");

            Value[] values = context.Values;

            for (int x = argX.basePtr, y = argY.basePtr; x <= argX.endPtr; ++x, ++y)
            {
                Fx.Assert(values[x].IsType(ValueDataType.Double), "");
                Fx.Assert(values[y].IsType(ValueDataType.Double), "");
                values[y].Add(values[x].Double);
            }

            context.PopFrame();
            return this.next;
        }
Ejemplo n.º 34
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame argX = context.TopArg;
            StackFrame argY = context.SecondArg;

            Fx.Assert(argX.Count == argY.Count, "");

            Value[] values = context.Values;
            while (argX.basePtr <= argX.endPtr)
            {
                values[argY.basePtr].Update(context, values[argY.basePtr].CompareTo(ref values[argX.basePtr], op));
                argX.basePtr++;
                argY.basePtr++;
            }

            context.PopFrame();
            return(this.next);
        }
Ejemplo n.º 35
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topArg    = context.TopArg;
            StackFrame secondArg = context.SecondArg;

            Fx.Assert(topArg.Count == secondArg.Count, "");
            for (int x = topArg.basePtr, y = secondArg.basePtr; x <= topArg.endPtr; ++x, ++y)
            {
                NodeSequence seqX = context.Values[x].Sequence;
                NodeSequence seqY = context.Values[y].Sequence;

                // Replace with a new sequence that is the union of the two
                context.SetValue(context, y, seqY.Union(context, seqX));
            }

            context.PopFrame();
            return(this.next);
        }
Ejemplo n.º 36
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame    topFrame   = context.TopArg;
            ValueDataType resultType = context.Values[topFrame.basePtr].Type;
            XPathResult   result;

            switch (resultType)
            {
            case ValueDataType.Sequence:
            {
                SafeNodeSequenceIterator value = new SafeNodeSequenceIterator(context.Values[topFrame.basePtr].GetSequence(), context);
                result = new XPathResult(value);
            }
            break;

            case ValueDataType.Boolean:
            {
                bool value = context.Values[topFrame.basePtr].GetBoolean();
                result = new XPathResult(value);
            }
            break;

            case ValueDataType.String:
            {
                string value = context.Values[topFrame.basePtr].GetString();
                result = new XPathResult(value);
            }
            break;

            case ValueDataType.Double:
            {
                double value = context.Values[topFrame.basePtr].GetDouble();
                result = new XPathResult(value);
            }
            break;

            default:
                throw Fx.AssertAndThrow("Unexpected result type.");
            }

            context.Processor.QueryResult = result;
            context.PopFrame();
            return(this.next);
        }
Ejemplo n.º 37
0
        internal static void Substring(ProcessingContext context)
        {
            StackFrame topArg    = context.TopArg;
            StackFrame secondArg = context.SecondArg;

            while (topArg.basePtr <= topArg.endPtr)
            {
                string str        = context.PeekString(topArg.basePtr);
                int    startIndex = ((int)Math.Round(context.PeekDouble(secondArg.basePtr))) - 1;
                if (startIndex < 0)
                {
                    startIndex = 0;
                }
                context.SetValue(context, secondArg.basePtr, (startIndex >= str.Length) ? string.Empty : str.Substring(startIndex));
                topArg.basePtr++;
                secondArg.basePtr++;
            }
            context.PopFrame();
        }
Ejemplo n.º 38
0
        internal static void Substring(ProcessingContext context)
        {
            StackFrame arg1 = context.TopArg;
            StackFrame arg2 = context.SecondArg;

            Fx.Assert(arg1.Count == arg2.Count, "");
            while (arg1.basePtr <= arg1.endPtr)
            {
                string str     = context.PeekString(arg1.basePtr);
                int    startAt = ((int)Math.Round(context.PeekDouble(arg2.basePtr))) - 1;
                if (startAt < 0)
                {
                    startAt = 0;
                }
                context.SetValue(context, arg2.basePtr, (startAt >= str.Length) ? string.Empty : str.Substring(startAt));
                arg1.basePtr++;
                arg2.basePtr++;
            }
            context.PopFrame();
        }
Ejemplo n.º 39
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame          topSequenceArg = context.TopSequenceArg;
            StackFrame          topArg         = context.TopArg;
            NodeSequenceBuilder builder        = new NodeSequenceBuilder(context);

            Value[] sequences = context.Sequences;
            int     basePtr   = topSequenceArg.basePtr;
            int     index     = topArg.basePtr;

            while (basePtr <= topSequenceArg.endPtr)
            {
                NodeSequence sequence = sequences[basePtr].Sequence;
                if (sequence.Count > 0)
                {
                    NodesetIterator iterator = new NodesetIterator(sequence);
                    while (iterator.NextNodeset())
                    {
                        builder.StartNodeset();
                        while (iterator.NextItem())
                        {
                            if (context.Values[index].Boolean)
                            {
                                builder.Add(ref sequence.Items[iterator.Index]);
                            }
                            index++;
                        }
                        builder.EndNodeset();
                    }
                    context.ReplaceSequenceAt(basePtr, builder.Sequence);
                    context.ReleaseSequence(sequence);
                    builder.Sequence = null;
                }
                basePtr++;
            }
            context.PopFrame();
            return(base.next);
        }
 internal override Opcode Eval(ProcessingContext context)
 {
     StackFrame topSequenceArg = context.TopSequenceArg;
     StackFrame topArg = context.TopArg;
     NodeSequenceBuilder builder = new NodeSequenceBuilder(context);
     Value[] sequences = context.Sequences;
     int basePtr = topSequenceArg.basePtr;
     int index = topArg.basePtr;
     while (basePtr <= topSequenceArg.endPtr)
     {
         NodeSequence sequence = sequences[basePtr].Sequence;
         if (sequence.Count > 0)
         {
             NodesetIterator iterator = new NodesetIterator(sequence);
             while (iterator.NextNodeset())
             {
                 builder.StartNodeset();
                 while (iterator.NextItem())
                 {
                     if (context.Values[index].Boolean)
                     {
                         builder.Add(ref sequence.Items[iterator.Index]);
                     }
                     index++;
                 }
                 builder.EndNodeset();
             }
             context.ReplaceSequenceAt(basePtr, builder.Sequence);
             context.ReleaseSequence(sequence);
             builder.Sequence = null;
         }
         basePtr++;
     }
     context.PopFrame();
     return base.next;
 }
 internal static void Substring(ProcessingContext context)
 {
     StackFrame topArg = context.TopArg;
     StackFrame secondArg = context.SecondArg;
     while (topArg.basePtr <= topArg.endPtr)
     {
         string str = context.PeekString(topArg.basePtr);
         int startIndex = ((int) Math.Round(context.PeekDouble(secondArg.basePtr))) - 1;
         if (startIndex < 0)
         {
             startIndex = 0;
         }
         context.SetValue(context, secondArg.basePtr, (startIndex >= str.Length) ? string.Empty : str.Substring(startIndex));
         topArg.basePtr++;
         secondArg.basePtr++;
     }
     context.PopFrame();
 }
Ejemplo n.º 42
0
        internal static void Translate(ProcessingContext context)
        {
            StackFrame argSource = context.TopArg;
            StackFrame argKeys = context.SecondArg;
            StackFrame argValues = context[2];

            // PERF, [....], this is really slow.
            StringBuilder builder = new StringBuilder();
            while (argSource.basePtr <= argSource.endPtr)
            {
                builder.Length = 0;

                string source = context.PeekString(argSource.basePtr);
                string keys = context.PeekString(argKeys.basePtr);
                string values = context.PeekString(argValues.basePtr);
                for (int i = 0; i < source.Length; ++i)
                {
                    char c = source[i];
                    int idx = keys.IndexOf(c);
                    if (idx < 0)
                    {
                        builder.Append(c);
                    }
                    else if (idx < values.Length)
                    {
                        builder.Append(values[idx]);
                    }
                }
                context.SetValue(context, argValues.basePtr, builder.ToString());
                argSource.basePtr++;
                argKeys.basePtr++;
                argValues.basePtr++;
            }

            context.PopFrame();
            context.PopFrame();
        }
 internal override Opcode Eval(ProcessingContext context)
 {
     context.Processor.Result = this.IsSuccess(context);
     context.PopFrame();
     return base.next;
 }
 internal static void SubstringBefore(ProcessingContext context)
 {
     StackFrame topArg = context.TopArg;
     StackFrame secondArg = context.SecondArg;
     while (topArg.basePtr <= topArg.endPtr)
     {
         string str = context.PeekString(topArg.basePtr);
         string str2 = context.PeekString(secondArg.basePtr);
         int index = str.IndexOf(str2, StringComparison.Ordinal);
         context.SetValue(context, secondArg.basePtr, (index == -1) ? string.Empty : str.Substring(0, index));
         topArg.basePtr++;
         secondArg.basePtr++;
     }
     context.PopFrame();
 }
Ejemplo n.º 45
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame sequences = context.TopSequenceArg;
            StackFrame results = context.TopArg;
            NodeSequenceBuilder sequenceBuilder = new NodeSequenceBuilder(context);
            Value[] sequenceBuffer = context.Sequences;

            for (int seqIndex = sequences.basePtr, resultIndex = results.basePtr; seqIndex <= sequences.endPtr; ++seqIndex)
            {
                NodeSequence sourceSequence = sequenceBuffer[seqIndex].Sequence;
                if (sourceSequence.Count > 0)
                {
                    NodesetIterator nodesetIterator = new NodesetIterator(sourceSequence);
                    while (nodesetIterator.NextNodeset())
                    {
                        sequenceBuilder.StartNodeset();
                        while (nodesetIterator.NextItem())
                        {
                            Fx.Assert(context.Values[resultIndex].IsType(ValueDataType.Boolean), "");
                            if (context.Values[resultIndex].Boolean)
                            {
                                sequenceBuilder.Add(ref sourceSequence.Items[nodesetIterator.Index]);
                            }
                            ++resultIndex;
                        }
                        sequenceBuilder.EndNodeset();
                    }
                    context.ReplaceSequenceAt(seqIndex, sequenceBuilder.Sequence);
                    context.ReleaseSequence(sourceSequence);
                    sequenceBuilder.Sequence = null;
                }
            }

            context.PopFrame();
            return this.next;
        }
Ejemplo n.º 46
0
 internal static void StringConcatFour(ProcessingContext context)
 {
     StackFrame arg1 = context[0];
     StackFrame arg2 = context[1];
     StackFrame arg3 = context[2];
     StackFrame arg4 = context[3];
     while (arg1.basePtr <= arg1.endPtr)
     {
         string str1 = context.PeekString(arg1.basePtr);
         string str2 = context.PeekString(arg2.basePtr);
         string str3 = context.PeekString(arg3.basePtr);
         string str4 = context.PeekString(arg4.basePtr);
         context.SetValue(context, arg4.basePtr, str1 + str2 + str3 + str4);
         arg1.basePtr++;
         arg2.basePtr++;
         arg3.basePtr++;
         arg4.basePtr++;
     }
     context.PopFrame();
     context.PopFrame();
     context.PopFrame();
 }
Ejemplo n.º 47
0
        internal static void StringStartsWith(ProcessingContext context)
        {
            StackFrame arg1 = context.TopArg;
            StackFrame arg2 = context.SecondArg;

            Fx.Assert(arg1.Count == arg2.Count, "");
            while (arg1.basePtr <= arg1.endPtr)
            {
                string leftString = context.PeekString(arg1.basePtr);
                string rightString = context.PeekString(arg2.basePtr);
                context.SetValue(context, arg2.basePtr, leftString.StartsWith(rightString, StringComparison.Ordinal));
                arg1.basePtr++;
                arg2.basePtr++;
            }
            context.PopFrame();
        }
Ejemplo n.º 48
0
        internal static void SubstringAfter(ProcessingContext context)
        {
            StackFrame arg1 = context.TopArg;
            StackFrame arg2 = context.SecondArg;

            Fx.Assert(arg1.Count == arg2.Count, "");
            while (arg1.basePtr <= arg1.endPtr)
            {
                string str1 = context.PeekString(arg1.basePtr);
                string str2 = context.PeekString(arg2.basePtr);
                int idx = str1.IndexOf(str2, StringComparison.Ordinal);
                context.SetValue(context, arg2.basePtr, idx == -1 ? string.Empty : str1.Substring(idx + str2.Length));
                arg1.basePtr++;
                arg2.basePtr++;
            }
            context.PopFrame();
        }
 internal static void StringStartsWith(ProcessingContext context)
 {
     StackFrame topArg = context.TopArg;
     StackFrame secondArg = context.SecondArg;
     while (topArg.basePtr <= topArg.endPtr)
     {
         string str = context.PeekString(topArg.basePtr);
         string str2 = context.PeekString(secondArg.basePtr);
         context.SetValue(context, secondArg.basePtr, str.StartsWith(str2, StringComparison.Ordinal));
         topArg.basePtr++;
         secondArg.basePtr++;
     }
     context.PopFrame();
 }
Ejemplo n.º 50
0
        internal static void SubstringLimit(ProcessingContext context)
        {
            StackFrame argString = context.TopArg;
            StackFrame argStartAt = context.SecondArg;
            StackFrame argLimit = context[2];

            Fx.Assert(argString.Count == argStartAt.Count, "");
            Fx.Assert(argString.Count == argLimit.Count, "");

            while (argString.basePtr <= argString.endPtr)
            {
                string str = context.PeekString(argString.basePtr);
                int startAt = ((int)Math.Round(context.PeekDouble(argStartAt.basePtr))) - 1;
                if (startAt < 0)
                {
                    startAt = 0;
                }
                int length = (int)Math.Round(context.PeekDouble(argLimit.basePtr));

                string substr;
                if (length < 1 || ((startAt + length) >= str.Length))
                {
                    substr = string.Empty;
                }
                else
                {
                    substr = str.Substring(startAt, length);
                }
                context.SetValue(context, argLimit.basePtr, substr);
                argStartAt.basePtr++;
                argString.basePtr++;
                argLimit.basePtr++;
            }

            context.PopFrame();
            context.PopFrame();
        }
Ejemplo n.º 51
0
        internal static void Substring(ProcessingContext context)
        {
            StackFrame arg1 = context.TopArg;
            StackFrame arg2 = context.SecondArg;

            Fx.Assert(arg1.Count == arg2.Count, "");
            while (arg1.basePtr <= arg1.endPtr)
            {
                string str = context.PeekString(arg1.basePtr);
                int startAt = ((int)Math.Round(context.PeekDouble(arg2.basePtr))) - 1;
                if (startAt < 0)
                {
                    startAt = 0;
                }
                context.SetValue(context, arg2.basePtr, (startAt >= str.Length) ? string.Empty : str.Substring(startAt));
                arg1.basePtr++;
                arg2.basePtr++;
            }
            context.PopFrame();
        }
 internal static void StringConcatTwo(ProcessingContext context)
 {
     StackFrame frame = context[0];
     StackFrame frame2 = context[1];
     while (frame.basePtr <= frame.endPtr)
     {
         context.SetValue(context, frame2.basePtr, context.PeekString(frame.basePtr) + context.PeekString(frame2.basePtr));
         frame.basePtr++;
         frame2.basePtr++;
     }
     context.PopFrame();
 }
Ejemplo n.º 53
0
        internal override void Eval(ProcessingContext context)
        {
            Fx.Assert(context != null, "");

            StackFrame[] args = new StackFrame[argCount];
            for (int i = 0; i < this.argCount; ++i)
            {
                args[i] = context[i];
            }

            StringBuilder builder = new StringBuilder();
            while (args[0].basePtr <= args[0].endPtr)
            {
                builder.Length = 0;

                for (int i = 0; i < this.argCount; ++i)
                {
                    builder.Append(context.PeekString(args[i].basePtr));
                }

                context.SetValue(context, args[this.argCount - 1].basePtr, builder.ToString());
                for (int i = 0; i < this.argCount; ++i)
                {
                    args[i].basePtr++;
                }
            }

            for (int i = 0; i < this.argCount - 1; ++i)
            {
                context.PopFrame();
            }
        }
 internal override Opcode Eval(ProcessingContext context)
 {
     StackFrame topArg = context.TopArg;
     int count = topArg.Count;
     if (count > 0)
     {
         QueryBranchResultSet resultTable = context.Processor.CreateResultSet();
         BranchMatcher matcher = new BranchMatcher(count, resultTable);
         for (int i = 0; i < count; i++)
         {
             this.CollectMatches(i, ref context.Values[topArg[i]], resultTable);
         }
         context.PopFrame();
         if (resultTable.Count > 1)
         {
             resultTable.Sort();
         }
         if ((this.alwaysBranches != null) && (this.alwaysBranches.Count > 0))
         {
             matcher.InvokeNonMatches(context, this.alwaysBranches);
         }
         matcher.InvokeMatches(context);
         matcher.Release(context);
     }
     else
     {
         context.PopFrame();
     }
     return base.next;
 }
Ejemplo n.º 55
0
        internal override Opcode Eval(ProcessingContext context)
        {
            XPathNavigator nav = context.Processor.ContextNode;
            if (nav != null && context.Processor.ContextMessage != null)
            {
                ((SeekableMessageNavigator)nav).Atomize();
            }

            if (this.argCount == 0)
            {
                context.PushFrame();
                int count = context.IterationCount;
                if (count > 0)
                {
                    object ret = this.function.Invoke(this.xsltContext, NullArgs, nav);
                    switch (this.function.ReturnType)
                    {
                        case XPathResultType.String:
                            context.Push((string)ret, count);
                            break;

                        case XPathResultType.Number:
                            context.Push((double)ret, count);
                            break;

                        case XPathResultType.Boolean:
                            context.Push((bool)ret, count);
                            break;

                        case XPathResultType.NodeSet:
                            NodeSequence seq = context.CreateSequence();
                            XPathNodeIterator iter = (XPathNodeIterator)ret;
                            seq.Add(iter);
                            context.Push(seq, count);
                            break;

                        default:
                            // This should never be reached
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.Unexpected, SR.GetString(SR.QueryFunctionTypeNotSupported, this.function.ReturnType.ToString())));
                    }
                }
            }
            else
            {
                // PERF, [....], see if we can cache these arrays to avoid allocations
                object[] xsltArgs = new object[this.argCount];
                int iterationCount = context.TopArg.Count;
                for (int iteration = 0; iteration < iterationCount; ++iteration)
                {
                    for (int i = 0; i < this.argCount; ++i)
                    {
                        StackFrame arg = context[i];
                        Fx.Assert(iteration < arg.Count, "");

                        switch (this.function.ArgTypes[i])
                        {
                            case XPathResultType.String:
                                xsltArgs[i] = context.PeekString(arg[iteration]);
                                break;

                            case XPathResultType.Number:
                                xsltArgs[i] = context.PeekDouble(arg[iteration]);
                                break;

                            case XPathResultType.Boolean:
                                xsltArgs[i] = context.PeekBoolean(arg[iteration]);
                                break;

                            case XPathResultType.NodeSet:
                                NodeSequenceIterator iter = new NodeSequenceIterator(context.PeekSequence(arg[iteration]));
                                xsltArgs[i] = iter;
                                this.iterList.Add(iter);
                                break;

                            default:
                                // This should never be reached
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.Unexpected, SR.GetString(SR.QueryFunctionTypeNotSupported, this.function.ArgTypes[i].ToString())));
                        }
                    }

                    object ret = this.function.Invoke(this.xsltContext, xsltArgs, nav);

                    if (this.iterList != null)
                    {
                        for (int i = 0; i < this.iterList.Count; ++i)
                        {
                            this.iterList[i].Clear();
                        }
                        this.iterList.Clear();
                    }

                    switch (this.function.ReturnType)
                    {
                        case XPathResultType.String:
                            context.SetValue(context, context[this.argCount - 1][iteration], (string)ret);
                            break;

                        case XPathResultType.Number:
                            context.SetValue(context, context[this.argCount - 1][iteration], (double)ret);
                            break;

                        case XPathResultType.Boolean:
                            context.SetValue(context, context[this.argCount - 1][iteration], (bool)ret);
                            break;

                        case XPathResultType.NodeSet:
                            NodeSequence seq = context.CreateSequence();
                            XPathNodeIterator iter = (XPathNodeIterator)ret;
                            seq.Add(iter);
                            context.SetValue(context, context[this.argCount - 1][iteration], seq);
                            break;

                        default:
                            // This should never be reached
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.Unexpected, SR.GetString(SR.QueryFunctionTypeNotSupported, this.function.ReturnType.ToString())));
                    }
                }

                for (int i = 0; i < this.argCount - 1; ++i)
                {
                    context.PopFrame();
                }
            }
            return this.next;
        }
Ejemplo n.º 56
0
        internal override Opcode Eval(ProcessingContext context)
        {
            StackFrame topArg = context.TopArg;
            StackFrame secondArg = context.SecondArg;

            Fx.Assert(topArg.Count == secondArg.Count, "");
            for (int x = topArg.basePtr, y = secondArg.basePtr; x <= topArg.endPtr; ++x, ++y)
            {
                NodeSequence seqX = context.Values[x].Sequence;
                NodeSequence seqY = context.Values[y].Sequence;

                // Replace with a new sequence that is the union of the two
                context.SetValue(context, y, seqY.Union(context, seqX));
            }

            context.PopFrame();
            return this.next;
        }
 internal static void Translate(ProcessingContext context)
 {
     StackFrame topArg = context.TopArg;
     StackFrame secondArg = context.SecondArg;
     StackFrame frame3 = context[2];
     StringBuilder builder = new StringBuilder();
     while (topArg.basePtr <= topArg.endPtr)
     {
         builder.Length = 0;
         string str = context.PeekString(topArg.basePtr);
         string str2 = context.PeekString(secondArg.basePtr);
         string str3 = context.PeekString(frame3.basePtr);
         for (int i = 0; i < str.Length; i++)
         {
             char ch = str[i];
             int index = str2.IndexOf(ch);
             if (index < 0)
             {
                 builder.Append(ch);
             }
             else if (index < str3.Length)
             {
                 builder.Append(str3[index]);
             }
         }
         context.SetValue(context, frame3.basePtr, builder.ToString());
         topArg.basePtr++;
         secondArg.basePtr++;
         frame3.basePtr++;
     }
     context.PopFrame();
     context.PopFrame();
 }
Ejemplo n.º 58
0
 internal override Opcode Eval(ProcessingContext context)
 {
     context.PopFrame();
     return this.next;
 }
 internal static void SubstringLimit(ProcessingContext context)
 {
     StackFrame topArg = context.TopArg;
     StackFrame secondArg = context.SecondArg;
     StackFrame frame3 = context[2];
     while (topArg.basePtr <= topArg.endPtr)
     {
         string str2;
         string str = context.PeekString(topArg.basePtr);
         int startIndex = ((int) Math.Round(context.PeekDouble(secondArg.basePtr))) - 1;
         if (startIndex < 0)
         {
             startIndex = 0;
         }
         int length = (int) Math.Round(context.PeekDouble(frame3.basePtr));
         if ((length < 1) || ((startIndex + length) >= str.Length))
         {
             str2 = string.Empty;
         }
         else
         {
             str2 = str.Substring(startIndex, length);
         }
         context.SetValue(context, frame3.basePtr, str2);
         secondArg.basePtr++;
         topArg.basePtr++;
         frame3.basePtr++;
     }
     context.PopFrame();
     context.PopFrame();
 }