Esempio n. 1
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);
            Debug.Assert(this.copyEvents != null && this.copyEvents.Count > 0);

            switch (frame.State) {
            case Initialized:
                frame.Counter = 0;
                frame.State   = Outputting;
                goto case Outputting;

            case Outputting:
                Debug.Assert(frame.State == Outputting);

                while (processor.CanContinue) {
                    Debug.Assert(frame.Counter < this.copyEvents.Count);
                    Event copyEvent = (Event) this.copyEvents[frame.Counter];

                    if (copyEvent.Output(processor, frame) == false) {
                        // This event wasn't processed
                        break;
                    }

                    if (frame.IncrementCounter() >= this.copyEvents.Count) {
                        frame.Finished();
                        break;
                    }
                }
                break;
            default:
                Debug.Fail("Invalid CopyCodeAction execution state");
                break;
            }
        }
Esempio n. 2
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State) {
            case Initialized:
                Debug.Assert(frame != null);
                Debug.Assert(frame.NodeSet != null);

                if (this.selectKey == Compiler.InvalidQueryKey) {
                    throw new XsltException(Res.Xslt_InvalidXPath,  new string[] { select });
                }

                string value = processor.ValueOf(frame, this.selectKey);

                if (processor.TextEvent(value, disableOutputEscaping)) {
                    frame.Finished();
                }
                else {
                    frame.StoredOutput = value;
                    frame.State        = ResultStored;
                }
                break;

            case ResultStored:
                Debug.Assert(frame.StoredOutput != null);
                processor.TextEvent(frame.StoredOutput);
                frame.Finished();
                break;

            default:
                Debug.Fail("Invalid ValueOfAction execution state");
                break;
            }
        }
Esempio n. 3
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State) {
            case Initialized:
                if (processor.BeginEvent(XPathNodeType.Comment, string.Empty, string.Empty, string.Empty, false) == false) {
                    // Come back later
                    break;
                }

                processor.PushActionFrame(frame);
                frame.State = ProcessingChildren;
                break;                              // Allow children to run

            case ProcessingChildren:
                if (processor.EndEvent(XPathNodeType.Comment) == false) {
                    Debug.WriteLine("Cannot end event, breaking, will restart");
                    break;
                }

                frame.Finished();
                break;

            default:
                Debug.Fail("Invalid IfAction execution state");
    		    break;
            }
        }
Esempio n. 4
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);
            Debug.Assert(frame.State == Initialized);

            Action action = null;

            if (this.mode != null) {
                action = importsOf == null 
                    ? processor.Stylesheet.FindTemplate(processor, frame.Node, this.mode)
                    : importsOf.FindTemplateImports(processor, frame.Node, this.mode);
            }
            else {
                action = importsOf == null 
                    ? processor.Stylesheet.FindTemplate(processor, frame.Node)
                    : importsOf.FindTemplateImports(processor, frame.Node);
            }

            // Built-int template rules
            if (action == null) {
                action = BuiltInTemplate(frame.Node);
            }

            // Jump
            if (action != null) {
                frame.SetAction(action);
            }
            else {
                frame.Finished();
            }
        }
Esempio n. 5
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);
            switch (frame.State) {
            case Initialized:
                TextOnlyOutput output = new TextOnlyOutput(processor, new StringWriter());
                processor.PushOutput(output);
                processor.PushActionFrame(frame);
                frame.State = ProcessingChildren;
                break;

            case ProcessingChildren:
                TextOnlyOutput recOutput = processor.PopOutput() as TextOnlyOutput;
                Debug.Assert(recOutput != null);
                Console.WriteLine(recOutput.Writer.ToString());

                if (_Terminate) {
                    throw new XsltException(Res.Xslt_Terminate, recOutput.Writer.ToString());
                }
                frame.Finished();
                break;
            
            default:
                Debug.Fail("Invalid MessageAction execution state");
                break;
            }
        }
Esempio n. 6
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State) {
            case Initialized:
                if (this.type == ConditionType.ConditionIf || this.type == ConditionType.ConditionWhen) {
                    Debug.Assert(this.testKey != Compiler.InvalidQueryKey);
                    bool value = processor.EvaluateBoolean(frame, this.testKey);
                    if (value == false) {
                        frame.Finished();
                        break;
                    }
                }

                processor.PushActionFrame(frame);
                frame.State = ProcessingChildren;
                break;                              // Allow children to run

            case ProcessingChildren:
                if (this.type == ConditionType.ConditionWhen ||this.type == ConditionType.ConditionOtherwise) {
                    Debug.Assert(frame.Container != null);
                    frame.Exit();
                }

                frame.Finished();
                break;

            default:
                Debug.Fail("Invalid IfAction execution state");
        		break;
            }
        }
Esempio n. 7
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);
            object ParamValue;
            switch(frame.State) {
            case Initialized:           
                if (this.selectKey != Compiler.InvalidQueryKey) {
                    ParamValue = processor.RunQuery(frame, this.selectKey);
                    processor.SetParameter(this.name, ParamValue);
                    frame.Finished();
                }
                else {
                    if (this.containedActions == null) {
                        processor.SetParameter(this.name, String.Empty);
                        frame.Finished();
                        break;
                    }
                    NavigatorOutput output = new NavigatorOutput();
                    processor.PushOutput(output);
                    processor.PushActionFrame(frame);
                    frame.State = ProcessingChildren;
                }
                break;
            case ProcessingChildren:
                RecordOutput recOutput = processor.PopOutput();
                Debug.Assert(recOutput is NavigatorOutput);
                processor.SetParameter(this.name,((NavigatorOutput)recOutput).Navigator);
                frame.Finished();
                break;
            default:
                Debug.Fail("Invalid execution state inside VariableAction.Execute");
		    break;
            }
        }
Esempio n. 8
0
 public override bool Output(Processor processor, ActionFrame frame) {
     bool res;
     res = processor.BeginEvent(XPathNodeType.Namespace, /*prefix:*/null, this.name, this.namespaceUri, /*empty:*/false);
     Debug.Assert(res); // Namespace node as any other attribute can't fail because it doesn't signal record change
     res = processor.TextEvent(this.namespaceUri);
     Debug.Assert(res);
     res = processor.EndEvent(XPathNodeType.Namespace);
     Debug.Assert(res);
     return true;
 }
Esempio n. 9
0
 internal override void Execute(Processor processor, ActionFrame frame) {
     Debug.Assert(processor != null && frame != null);
     switch (frame.State) {
     case Initialized:
         processor.PushTemplateLookup(frame.NodeSet, this.mode, /*importsOf:*/this.stylesheet);
         frame.State = TemplateProcessed;
         break;
     case TemplateProcessed:
         frame.Finished();
         break;
     }
 }
Esempio n. 10
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State) {
            case Initialized:
                if (sort) {
                    processor.InitSortArray();
                    processor.PushActionFrame(sortContainer, frame.NodeSet);
                    frame.State = ProcessedSort;
                    break;
                }
                goto case ProcessedSort; 
            case ProcessedSort:
                if (this.selectKey == Compiler.InvalidQueryKey) {
                    throw new XsltException(Res.Xslt_InvalidXPath,  new string[] { select });
                }
                if (sort) {
                    frame.InitNewNodeSet(processor.StartQuery(frame.Node, this.selectKey, processor.SortArray));
                }
                else {
                    frame.InitNewNodeSet(processor.StartQuery(frame.Node, this.selectKey));
                }
                frame.State = ProcessNextNode;
                goto case ProcessNextNode;

            case ProcessNextNode:
                Debug.Assert(frame.State == ProcessNextNode);
                Debug.Assert(frame.NewNodeSet != null);

                Debug.WriteLine("Processing next Node");

                if (frame.NewNextNode(processor)) {
                    Debug.WriteLine("Node found");
                    frame.State = PositionAdvanced;
                    goto case PositionAdvanced;
                }
                else {
                    Debug.WriteLine("Node not found, finished ");

                    frame.Finished();
                    break;
                }

            case PositionAdvanced:
                processor.PushActionFrame(frame, frame.NewNodeSet);
                frame.State = ContentsProcessed;
                break;

            case ContentsProcessed:
                frame.State = ProcessNextNode;
                goto case ProcessNextNode;
            }
        }
Esempio n. 11
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            while (processor.CanContinue) {
                switch (frame.State) {
                case Initialized:
                    if (frame.Node.MoveToFirstNamespace(XPathNamespaceScope.ExcludeXml) == false) {
                        frame.Finished();
                        break;
                    }

                    frame.State   = BeginEvent;
                    goto case BeginEvent;

                case BeginEvent:
                    Debug.Assert(frame.State == BeginEvent);
                    Debug.Assert(frame.Node.NodeType == XPathNodeType.Namespace);

                    if (processor.BeginEvent(XPathNodeType.Namespace, null, frame.Node.LocalName, frame.Node.Value, false) == false) {
                        // This one wasn't output
                        break;
                    }
                    frame.State = EndEvent;
                    continue;

                case EndEvent:
                    Debug.Assert(frame.State == EndEvent);
                    Debug.Assert(frame.Node.NodeType == XPathNodeType.Namespace);

                    if (processor.EndEvent(XPathNodeType.Namespace) == false) {
                        // This one wasn't output
                        break;
                    }
                    frame.State = Advance;
                    continue;

                case Advance:
                    Debug.Assert(frame.State == Advance);
                    Debug.Assert(frame.Node.NodeType == XPathNodeType.Namespace);

                    if (frame.Node.MoveToNextNamespace(XPathNamespaceScope.ExcludeXml)) {
                        frame.State = BeginEvent;
                        continue;
                    }
                    else {
                        frame.Node.MoveToParent();
                        frame.Finished();
                        break;
                    }
                }
                break;
            }// while
        }
Esempio n. 12
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State) {
            case Initialized:
                if (processor.TextEvent(this.text, disableOutputEscaping)) {
                    frame.Finished();
                }
                break;

            default:
                Debug.Fail("Invalid execution state in TextAction");
                break;
            }
        }
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State) {
            case Initialized:
                if(this.nameAvt == null) {
                    frame.StoredOutput = this.name;
                    if(this.name == null) {
                        // name was static but was bad;
                        frame.Finished();
                        break;
                    }
                }
                else {
                    frame.StoredOutput = this.nameAvt.Evaluate(processor, frame);
                    if (! IsProcessingInstructionName(frame.StoredOutput)) {
                        Debug.WriteLine("Invalid Processing instruction naame: \"" + name + "\"");
                        frame.Finished();
                        break;
                    }
                }
                goto case NameReady;

            case NameReady:
                Debug.Assert(frame.StoredOutput != null);
                if (processor.BeginEvent(XPathNodeType.ProcessingInstruction, string.Empty, frame.StoredOutput, string.Empty, false) == false) {
                    // Come back later
                    frame.State = NameReady;
                    break;
                }
                processor.PushActionFrame(frame);
                frame.State = ProcessingChildren;
                break;                              // Allow children to run

            case ProcessingChildren:
                if (processor.EndEvent(XPathNodeType.ProcessingInstruction) == false) {
                    Debug.WriteLine("Cannot end event, breaking, will restart");
                    frame.State = ProcessingChildren;
                    break;
                }
                frame.Finished();
                break;
            default:
                Debug.Fail("Invalid ElementAction execution state");
                frame.Finished();
                break;
            }
        }
Esempio n. 14
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State) {
            case Initialized:
                Debug.Assert(frame.NodeSet != null);
                Debug.Assert(this.selectKey != Compiler.InvalidQueryKey);
                XPathExpression expr = processor.GetValueQuery(this.selectKey);
                object result = frame.Node.Evaluate(expr);

                XPathNodeIterator nodeSet = result as XPathNodeIterator;
                if (nodeSet != null) {
                    processor.PushActionFrame(CopyNodeSetAction.GetAction(), nodeSet);
                    frame.State = NodeSetCopied;
                    break;
                }

                XPathNavigator nav = result as XPathNavigator;
                if (nav != null) {
                    processor.PushActionFrame(CopyNodeSetAction.GetAction(), new XPathSingletonIterator(nav));
                    frame.State = NodeSetCopied;
                    break; 
                }

                string value = XmlConvert.ToXPathString(result);
                if (processor.TextEvent(value)) {
                    frame.Finished();
                }
                else {
                    frame.StoredOutput = value;
                    frame.State        = ResultStored;
                }
                break;

            case ResultStored:
                Debug.Assert(frame.StoredOutput != null);
                processor.TextEvent(frame.StoredOutput);
                frame.Finished();
                break;

            case NodeSetCopied:
                Debug.Assert(frame.State == NodeSetCopied);
                frame.Finished();
                break;
            }
        }
Esempio n. 15
0
        internal string Evaluate(Processor processor, ActionFrame frame) {
            if (IsConstant) {
                Debug.Assert(constAvt != null);
                return constAvt;
            }
            else {
                Debug.Assert(processor != null && frame != null);

                StringBuilder builder = processor.GetSharedStringBuilder();

                for(int i = 0; i < events.Length; i ++) {
                    builder.Append(events[i].Evaluate(processor, frame));
                }
                processor.ReleaseSharedStringBuilder();
                return builder.ToString();
            }
        }
Esempio n. 16
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);
            object ParamValue;

            switch (frame.State)
            {
            case Initialized:
                if (this.selectKey != Compiler.InvalidQueryKey)
                {
                    ParamValue = processor.RunQuery(frame, this.selectKey);
                    processor.SetParameter(this.name, ParamValue);
                    frame.Finished();
                }
                else
                {
                    if (this.containedActions == null)
                    {
                        processor.SetParameter(this.name, String.Empty);
                        frame.Finished();
                        break;
                    }
                    NavigatorOutput output = new NavigatorOutput();
                    processor.PushOutput(output);
                    processor.PushActionFrame(frame);
                    frame.State = ProcessingChildren;
                }
                break;

            case ProcessingChildren:
                RecordOutput recOutput = processor.PopOutput();
                Debug.Assert(recOutput is NavigatorOutput);
                processor.SetParameter(this.name, ((NavigatorOutput)recOutput).Navigator);
                frame.Finished();
                break;

            default:
                Debug.Fail("Invalid execution state inside VariableAction.Execute");
                break;
            }
        }
Esempio n. 17
0
File: avt.cs Progetto: ydunk/masters
        internal string Evaluate(Processor processor, ActionFrame frame)
        {
            if (IsConstant)
            {
                Debug.Assert(constAvt != null);
                return(constAvt);
            }
            else
            {
                Debug.Assert(processor != null && frame != null);

                StringBuilder builder = processor.GetSharedStringBuilder();

                for (int i = 0; i < events.Length; i++)
                {
                    builder.Append(events[i].Evaluate(processor, frame));
                }
                processor.ReleaseSharedStringBuilder();
                return(builder.ToString());
            }
        }
Esempio n. 18
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);
            Debug.Assert(this.copyEvents != null && this.copyEvents.Count > 0);

            switch (frame.State)
            {
            case Initialized:
                frame.Counter = 0;
                frame.State   = Outputting;
                goto case Outputting;

            case Outputting:
                Debug.Assert(frame.State == Outputting);

                while (processor.CanContinue)
                {
                    Debug.Assert(frame.Counter < this.copyEvents.Count);
                    Event copyEvent = (Event)this.copyEvents[frame.Counter];

                    if (copyEvent.Output(processor, frame) == false)
                    {
                        // This event wasn't processed
                        break;
                    }

                    if (frame.IncrementCounter() >= this.copyEvents.Count)
                    {
                        frame.Finished();
                        break;
                    }
                }
                break;

            default:
                Debug.Fail("Invalid CopyCodeAction execution state");
                break;
            }
        }
Esempio n. 19
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State)
            {
            case Initialized:
                Debug.Assert(frame != null);
                Debug.Assert(frame.NodeSet != null);

                if (this.selectKey == Compiler.InvalidQueryKey)
                {
                    throw new XsltException(Res.Xslt_InvalidXPath, new string[] { select });
                }

                string value = processor.ValueOf(frame, this.selectKey);

                if (processor.TextEvent(value, disableOutputEscaping))
                {
                    frame.Finished();
                }
                else
                {
                    frame.StoredOutput = value;
                    frame.State        = ResultStored;
                }
                break;

            case ResultStored:
                Debug.Assert(frame.StoredOutput != null);
                processor.TextEvent(frame.StoredOutput);
                frame.Finished();
                break;

            default:
                Debug.Fail("Invalid ValueOfAction execution state");
                break;
            }
        }
Esempio n. 20
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            switch(frame.State) {
            case Initialized:
                frame.Counter = 0;
                frame.State = ProcessingSets;
                goto case ProcessingSets;

            case ProcessingSets:
                if (frame.Counter < this.useAttributeSets.Length) {
                    AttributeSetAction action = processor.RootAction.GetAttributeSet(this.useAttributeSets[frame.Counter]);
                    frame.IncrementCounter();
                    processor.PushActionFrame(action, frame.NodeSet);
                }
                else {
                    frame.Finished();
                }
                break;

            default:
                Debug.Fail("Invalid Container action execution state");
		        break;
            }
        }
Esempio n. 21
0
       internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State) {
            case Initialized:
                if (!fallback) {
                    throw XsltException.UnexpectedKeyword(this.name, this.parent);
                }
                if (this.containedActions != null && this.containedActions.Count > 0) {
                    processor.PushActionFrame(frame);
                    frame.State = ProcessingChildren;
                    break;
                }
                else goto case ProcessingChildren;
            case ProcessingChildren:
                frame.Finished();
                break;

            default:
                Debug.Fail("Invalid Container action execution state");
                break;
            }
        }
Esempio n. 22
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);
            switch (frame.State)
            {
            case Initialized:
                processor.ResetParams();
                if (this.containedActions != null && this.containedActions.Count > 0)
                {
                    processor.PushActionFrame(frame);
                    frame.State = ProcessedChildren;
                    break;
                }
                goto case ProcessedChildren;

            case ProcessedChildren:
                TemplateAction action = processor.Stylesheet.FindTemplate(this.name);
                if (action != null)
                {
                    frame.State = ProcessedTemplate;
                    processor.PushActionFrame(action, frame.NodeSet);
                    break;
                }
                else
                {
                    throw new XsltException(Res.Xslt_InvalidCallTemplate, this.name.ToString());
                }

            case ProcessedTemplate:
                frame.Finished();
                break;

            default:
                Debug.Fail("Invalid CallTemplateAction execution state");
                break;
            }
        }
Esempio n. 23
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State)
            {
            case Initialized:
                if (this.type == ConditionType.ConditionIf || this.type == ConditionType.ConditionWhen)
                {
                    Debug.Assert(this.testKey != Compiler.InvalidQueryKey);
                    bool value = processor.EvaluateBoolean(frame, this.testKey);
                    if (value == false)
                    {
                        frame.Finished();
                        break;
                    }
                }

                processor.PushActionFrame(frame);
                frame.State = ProcessingChildren;
                break;                              // Allow children to run

            case ProcessingChildren:
                if (this.type == ConditionType.ConditionWhen || this.type == ConditionType.ConditionOtherwise)
                {
                    Debug.Assert(frame.Container != null);
                    frame.Exit();
                }

                frame.Finished();
                break;

            default:
                Debug.Fail("Invalid IfAction execution state");
                break;
            }
        }
Esempio n. 24
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);
            Debug.Assert(frame.State == Initialized);

            Action action = null;

            if (this.mode != null)
            {
                action = importsOf == null
                    ? processor.Stylesheet.FindTemplate(processor, frame.Node, this.mode)
                    : importsOf.FindTemplateImports(processor, frame.Node, this.mode);
            }
            else
            {
                action = importsOf == null
                    ? processor.Stylesheet.FindTemplate(processor, frame.Node)
                    : importsOf.FindTemplateImports(processor, frame.Node);
            }

            // Built-int template rules
            if (action == null)
            {
                action = BuiltInTemplate(frame.Node);
            }

            // Jump
            if (action != null)
            {
                frame.SetAction(action);
            }
            else
            {
                frame.Finished();
            }
        }
Esempio n. 25
0
        private int numberAny(Processor processor, ActionFrame frame) {
            int result = 0;
            // Our current point will be our end point in this search
            XPathNavigator endNode = frame.Node;
            if(endNode.NodeType == XPathNodeType.Attribute) {
                endNode = endNode.Clone();
                endNode.MoveToParent();
            }
            XPathNavigator startNode = endNode.Clone(); 
        
            if(this.fromKey != Compiler.InvalidQueryKey) {
                bool hitFrom = false;
                // First try to find start by traversing up. This gives the best candidate or we hit root
                do{
                    if(processor.Matches(startNode, this.fromKey)) {
                        hitFrom = true;
                        break;
                    }
                }while(startNode.MoveToParent());

                Debug.Assert(
                    processor.Matches(startNode, this.fromKey) ||   // we hit 'from' or
                    startNode.NodeType == XPathNodeType.Root        // we are at root
                );
                
                // from this point (matched parent | root) create descendent quiery:
                // we have to reset 'result' on each 'from' node, because this point can' be not last from point;
                XPathNodeIterator  sel = processor.StartQuery(startNode, Compiler.DescendantKey);
                do {
                    if(processor.Matches(sel.Current, this.fromKey)) {
                        hitFrom = true;
                        result = 0;
                    }
                    else if(MatchCountKey(processor, frame.Node, sel.Current)) {
                        result ++;
                    }
                    if(sel.Current.IsSamePosition(endNode)) {
                        break;
                    }
                }while (sel.MoveNext());
                if(! hitFrom) {
                    result = 0;
                }
            }
            else {
                // without 'from' we startting from the root 
                startNode.MoveToRoot();      
                XPathNodeIterator  sel = processor.StartQuery(startNode, Compiler.DescendantKey);
                // and count root node by itself
                do {
                    if (MatchCountKey(processor, frame.Node, sel.Current)) {
                        result ++;
                    }
                    if (sel.Current.IsSamePosition(endNode)) {
                        break;
                    }
                }while (sel.MoveNext()); 
            }
            return result;
        }
Esempio n. 26
0
 public override string Evaluate(Processor processor, ActionFrame frame)
 {
     return(processor.EvaluateString(frame, this.key));
 }
Esempio n. 27
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            while (processor.CanContinue) {
                switch (frame.State) {
                case Initialized:
                    if (Processor.IsRoot(frame.Node)) {
                        processor.PushActionFrame(frame);
                        frame.State = ChildrenOnly;
                        break;
                    }

                    if (processor.CopyBeginEvent(frame.Node, this.empty) == false) {
                        // This event wasn't processed
                        break;
                    }
                    frame.State = NamespaceCopy;
                 
                    continue;
                case NamespaceCopy:
                    frame.State = ContentsCopy;
                    if ( frame.Node.NodeType == XPathNodeType.Element ) {
                        processor.PushActionFrame(CopyNamespacesAction.GetAction(), frame.NodeSet);
                        break;
                    }
                    continue;
                case ContentsCopy:
                    if (frame.Node.NodeType == XPathNodeType.Element && !this.empty) {
                        //Debug.Assert(frame.Node.HasValue == false);
                        processor.PushActionFrame(frame);
                        frame.State = ProcessChildren;
                        break;
                    }
                    else {
                        if (processor.CopyTextEvent(frame.Node)) {
                            frame.State = ProcessChildren;
                            continue;
                        }
                        else {
                            // This event wasn't processed
                            break;
                        }
                    }

                case ProcessChildren:
                    if (processor.CopyEndEvent(frame.Node)) {
                        frame.Finished();
                    }
                    break;

                case ChildrenOnly:
                    frame.Finished();
                    break;

                default:
                    Debug.Fail("Invalid CopyAction execution state");
			        break;
                }

                break;
            }
        }
Esempio n. 28
0
 public abstract bool Output(Processor processor, ActionFrame frame);
Esempio n. 29
0
 internal override void Execute(Processor processor, ActionFrame frame) {
     if(frame.State == Initialized) {
         processor.OnInstructionExecute();
     }
     base.Execute(processor, frame);
 }
Esempio n. 30
0
        internal void PushActionFrame(ActionFrame container, XPathNodeIterator nodeSet)
        {
            ActionFrame frame = PushNewFrame();

            frame.Init(container, nodeSet);
        }
Esempio n. 31
0
        internal void PushActionFrame(Action action, XPathNodeIterator nodeSet)
        {
            ActionFrame frame = PushNewFrame();

            frame.Init(action, nodeSet);
        }
Esempio n. 32
0
 internal override void Execute(Processor processor, ActionFrame frame) {
     Debug.Assert(processor != null && frame != null);
     Debug.Assert(frame.State == Initialized);
     
     processor.AddSort(this.sort != null ? 
         this.sort : 
         new Sort(
             this.selectKey,
             this.langAvt      == null ? this.lang      : ParseLang(     this.langAvt     .Evaluate(processor, frame)),
             this.dataTypeAvt  == null ? this.dataType  : ParseDataType( this.dataTypeAvt .Evaluate(processor, frame), manager),
             this.orderAvt     == null ? this.order     : ParseOrder(    this.orderAvt    .Evaluate(processor, frame)),
             this.caseOrderAvt == null ? this.caseOrder : ParseCaseOrder(this.caseOrderAvt.Evaluate(processor, frame))
         )
     );
     frame.Finished();
 }
Esempio n. 33
0
 public abstract bool Output(Processor processor, ActionFrame frame);
Esempio n. 34
0
        // -------------- Debugger related stuff ---------
        // BadBad: We have to pass ActionFrame to GetNavigator and GetVariables
        // bacause CopyCodeAction can't implement them without frame.count

        internal virtual DbgData GetDbgData(ActionFrame frame)
        {
            return(DbgData.Empty);
        }
Esempio n. 35
0
 internal abstract void Execute(Processor processor, ActionFrame frame);
Esempio n. 36
0
 internal override DbgData GetDbgData(ActionFrame frame)
 {
     Debug.Assert(frame.Counter < this.copyEvents.Count);
     return(((Event)this.copyEvents[frame.Counter]).DbgData);
 }
Esempio n. 37
0
 internal override DbgData GetDbgData(ActionFrame frame) { return this.dbgData; }
Esempio n. 38
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);
            ArrayList list = processor.NumberList;

            switch (frame.State)
            {
            case Initialized:
                Debug.Assert(frame != null);
                Debug.Assert(frame.NodeSet != null);
                list.Clear();
                if (this.value != null)
                {
                    object valueObject = SimplifyValue(processor.Evaluate(frame, this.valueKey));
                    double valueDouble = 0;
                    try {
                        valueDouble = XmlConvert.ToXPathDouble(valueObject);
                    }
                    catch (FormatException) {}
                    if (0.5 <= valueDouble && valueDouble < double.PositiveInfinity)
                    {
                        Debug.Assert(!double.IsNaN(valueDouble), "I belive it should be filtered by if condition");
                        list.Add(Math.Floor(valueDouble + 0.5));   // See XPath round for detailes on the trick with Floor()
                    }
                    else
                    {
                        // It is an error if the number is NaN, infinite or less than 0.5; an XSLT processor may signal the error;
                        // if it does not signal the error, it must recover by converting the number to a string as if by a call
                        // to the string function and inserting the resulting string into the result tree.
                        frame.StoredOutput = XmlConvert.ToXPathString(valueObject);
                        goto case OutputNumber;
                    }
                }
                else if (this.level == "any")
                {
                    int number = numberAny(processor, frame);
                    if (number != 0)
                    {
                        list.Add((double)number);
                    }
                }
                else
                {
                    bool           multiple    = (this.level == "multiple");
                    XPathNavigator contextNode = frame.Node;         // context of xsl:number element. We using this node in MatchCountKey()
                    XPathNavigator countNode   = frame.Node.Clone(); // node we count for
                    if (countNode.NodeType == XPathNodeType.Attribute)
                    {
                        countNode.MoveToParent();
                    }
                    while (moveToCount(countNode, processor, contextNode))
                    {
                        list.Insert(0, (double)numberCount(countNode, processor, contextNode));
                        if (!multiple || !countNode.MoveToParent())
                        {
                            break;
                        }
                    }
                    if (!checkFrom(processor, countNode))
                    {
                        list.Clear();
                    }
                }

                /*CalculatingFormat:*/
                frame.StoredOutput = Format(list,
                                            this.formatAvt == null ? this.formatList   : ParseFormat(this.formatAvt.Evaluate(processor, frame)),
                                            this.langAvt == null ? this.lang         : this.langAvt.Evaluate(processor, frame),
                                            this.letterAvt == null ? this.letter       : ParseLetter(this.letterAvt.Evaluate(processor, frame)),
                                            this.groupingSepAvt == null ? this.groupingSep  : this.groupingSepAvt.Evaluate(processor, frame),
                                            this.groupingSizeAvt == null ? this.groupingSize : this.groupingSizeAvt.Evaluate(processor, frame)
                                            );
                goto case OutputNumber;

            case OutputNumber:
                Debug.Assert(frame.StoredOutput != null);
                if (!processor.TextEvent(frame.StoredOutput))
                {
                    frame.State = OutputNumber;
                    break;
                }
                frame.Finished();
                break;

            default:
                Debug.Fail("Invalid Number Action execution state");
                break;
            }
        }
Esempio n. 39
0
 public override bool Output(Processor processor, ActionFrame frame) {
     this.OnInstructionExecute(processor);
     return base.Output(processor, frame);
 }
Esempio n. 40
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);

            while (processor.CanContinue)
            {
                switch (frame.State)
                {
                case Initialized:
                    if (!frame.Node.HasAttributes || frame.Node.MoveToFirstAttribute() == false)
                    {
                        frame.Finished();
                        break;
                    }

                    frame.State = BeginEvent;
                    goto case BeginEvent;

                case BeginEvent:
                    Debug.Assert(frame.State == BeginEvent);
                    Debug.Assert(frame.Node.NodeType == XPathNodeType.Attribute);

                    if (SendBeginEvent(processor, frame.Node) == false)
                    {
                        // This one wasn't output
                        break;
                    }
                    frame.State = TextEvent;
                    continue;

                case TextEvent:
                    Debug.Assert(frame.State == TextEvent);
                    Debug.Assert(frame.Node.NodeType == XPathNodeType.Attribute);

                    if (SendTextEvent(processor, frame.Node) == false)
                    {
                        // This one wasn't output
                        break;
                    }
                    frame.State = EndEvent;
                    continue;

                case EndEvent:
                    Debug.Assert(frame.State == EndEvent);
                    Debug.Assert(frame.Node.NodeType == XPathNodeType.Attribute);

                    if (SendEndEvent(processor, frame.Node) == false)
                    {
                        // This one wasn't output
                        break;
                    }
                    frame.State = Advance;
                    continue;

                case Advance:
                    Debug.Assert(frame.State == Advance);
                    Debug.Assert(frame.Node.NodeType == XPathNodeType.Attribute);

                    if (frame.Node.MoveToNextAttribute())
                    {
                        frame.State = BeginEvent;
                        continue;
                    }
                    else
                    {
                        frame.Node.MoveToParent();
                        frame.Finished();
                        break;
                    }
                }
                break;
            }// while (processor.CanContinue)
        }
Esempio n. 41
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State) {
            case Initialized:
		        processor.ResetParams();
		        processor.InitSortArray();
                if (this.containedActions != null && this.containedActions.Count > 0) {
                    processor.PushActionFrame(frame);
                    frame.State = ProcessedChildren;
                    break;
                }
                goto case ProcessedChildren;
	        case ProcessedChildren:
                if (this.selectKey == Compiler.InvalidQueryKey) {
                    Debug.Assert(this.select == null);

                    if (frame.Node.HasChildren) {
                        frame.InitNewNodeSet(frame.Node.SelectChildren(XPathNodeType.All));
                    }
                    else {
                        frame.Finished();
                        break;
                    }
                }
                else {
                    if (this.sort) {
                        frame.InitNewNodeSet(processor.StartQuery(frame.Node, this.selectKey, processor.SortArray));
                    }
                    else {
                        frame.InitNewNodeSet(processor.StartQuery(frame.Node, this.selectKey));
                    }
                }
                frame.State = ProcessNextNode;
                goto case ProcessNextNode;

            case ProcessNextNode:
                Debug.Assert(frame.State == ProcessNextNode);
                Debug.Assert(frame.NewNodeSet != null);

                if (frame.NewNextNode(processor)) {
                    frame.State = PositionAdvanced;
                    goto case PositionAdvanced;
                }
                else {
                    frame.Finished();
                    break;
                }

            case PositionAdvanced:
                Debug.Assert(frame.State == PositionAdvanced);

                processor.PushTemplateLookup(frame.NewNodeSet, this.mode, /*importsOf:*/null);

                frame.State = TemplateProcessed;
                break;

            case TemplateProcessed:
                frame.State = ProcessNextNode;
                goto case ProcessNextNode;

            default:
                Debug.Fail("Invalid ApplyTemplatesAction execution state");
                break;
            }
        }
Esempio n. 42
0
 public override bool Output(Processor processor, ActionFrame frame)
 {
     this.OnInstructionExecute(processor);
     return(base.Output(processor, frame));
 }
Esempio n. 43
0
 public virtual string Evaluate(Processor processor, ActionFrame frame)
 {
     return(this.text);
 }
Esempio n. 44
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State)
            {
            case Initialized:
                if (sort)
                {
                    processor.InitSortArray();
                    processor.PushActionFrame(sortContainer, frame.NodeSet);
                    frame.State = ProcessedSort;
                    break;
                }
                goto case ProcessedSort;

            case ProcessedSort:
                if (this.selectKey == Compiler.InvalidQueryKey)
                {
                    throw new XsltException(Res.Xslt_InvalidXPath, new string[] { select });
                }
                if (sort)
                {
                    frame.InitNewNodeSet(processor.StartQuery(frame.Node, this.selectKey, processor.SortArray));
                }
                else
                {
                    frame.InitNewNodeSet(processor.StartQuery(frame.Node, this.selectKey));
                }
                frame.State = ProcessNextNode;
                goto case ProcessNextNode;

            case ProcessNextNode:
                Debug.Assert(frame.State == ProcessNextNode);
                Debug.Assert(frame.NewNodeSet != null);

                Debug.WriteLine("Processing next Node");

                if (frame.NewNextNode(processor))
                {
                    Debug.WriteLine("Node found");
                    frame.State = PositionAdvanced;
                    goto case PositionAdvanced;
                }
                else
                {
                    Debug.WriteLine("Node not found, finished ");

                    frame.Finished();
                    break;
                }

            case PositionAdvanced:
                processor.PushActionFrame(frame, frame.NewNodeSet);
                frame.State = ContentsProcessed;
                break;

            case ContentsProcessed:
                frame.State = ProcessNextNode;
                goto case ProcessNextNode;
            }
        }
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State)
            {
            case Initialized:
                processor.ResetParams();
                processor.InitSortArray();
                if (this.containedActions != null && this.containedActions.Count > 0)
                {
                    processor.PushActionFrame(frame);
                    frame.State = ProcessedChildren;
                    break;
                }
                goto case ProcessedChildren;

            case ProcessedChildren:
                if (this.selectKey == Compiler.InvalidQueryKey)
                {
                    Debug.Assert(this.select == null);

                    if (!frame.Node.HasChildren)
                    {
                        frame.Finished();
                        break;
                    }
                    frame.InitNewNodeSet(frame.Node.SelectChildren(XPathNodeType.All));
                }
                else
                {
                    frame.InitNewNodeSet(processor.StartQuery(frame.Node, this.selectKey));
                }
                if (processor.SortArray.Count != 0)
                {
                    frame.SortNewNodeSet(processor, processor.SortArray);
                }
                frame.State = ProcessNextNode;
                goto case ProcessNextNode;

            case ProcessNextNode:
                Debug.Assert(frame.State == ProcessNextNode);
                Debug.Assert(frame.NewNodeSet != null);

                if (frame.NewNextNode(processor))
                {
                    frame.State = PositionAdvanced;
                    goto case PositionAdvanced;
                }
                else
                {
                    frame.Finished();
                    break;
                }

            case PositionAdvanced:
                Debug.Assert(frame.State == PositionAdvanced);

                processor.PushTemplateLookup(frame.NewNodeSet, this.mode, /*importsOf:*/ null);

                frame.State = TemplateProcessed;
                break;

            case TemplateProcessed:
                frame.State = ProcessNextNode;
                goto case ProcessNextNode;

            default:
                Debug.Fail("Invalid ApplyTemplatesAction execution state");
                break;
            }
        }
Esempio n. 46
0
 internal void Inherit(ActionFrame parent)
 {
     Debug.Assert(parent != null);
     this.variables = parent.variables;
 }
Esempio n. 47
0
 public override bool Output(Processor processor, ActionFrame frame)
 {
     Debug.Assert(key != Compiler.InvalidQueryKey);
     return(processor.TextEvent(processor.EvaluateString(frame, this.key)));
 }
Esempio n. 48
0
 internal void Init(ActionFrame containerFrame, XPathNodeIterator nodeSet)
 {
     Init(containerFrame.GetAction(0), containerFrame, nodeSet);
 }
Esempio n. 49
0
 internal void Exit()
 {
     Finished();
     this.container = null;
 }
Esempio n. 50
0
 internal override void Execute(Processor processor, ActionFrame frame) {
     if(frame.State == Initialized) {
         processor.PushDebuggerStack();
         processor.OnInstructionExecute();
     }
     base.Execute(processor, frame);
     if (frame.State == Finished) {
         processor.PopDebuggerStack();
     }
 }
Esempio n. 51
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);
            ArrayList list = processor.NumberList;
            switch (frame.State) {
            case Initialized:
                Debug.Assert(frame != null);
                Debug.Assert(frame.NodeSet != null);
                list.Clear();
                if (this.value != null) {
                    object valueObject = processor.Evaluate(frame, this.valueKey);
                    double valueDouble = 0;
                    try {
                        valueDouble = Processor.ToDouble(valueObject);
                    }
                    catch (FormatException) {}
                    if (0.5 <= valueDouble && valueDouble < double.PositiveInfinity) {
                        Debug.Assert(! double.IsNaN(valueDouble), "I belive it should be filtered by if condition");
                        list.Add(Math.Floor(valueDouble + 0.5));   // See XPath round for detailes on the trick with Floor()
                    }
                    else {
                        // It is an error if the number is NaN, infinite or less than 0.5; an XSLT processor may signal the error; 
                        // if it does not signal the error, it must recover by converting the number to a string as if by a call 
                        // to the string function and inserting the resulting string into the result tree.
                        frame.StoredOutput = XmlConvert.ToXPathString(valueObject);
                        goto case OutputNumber;
                    }
                }
                else if (this.level == "any") {
                    int number = numberAny(processor, frame);
                    if (number != 0) {
                        list.Add(number);
                    }
                }
                else {
                    bool multiple = (this.level == "multiple");
                    XPathNavigator contextNode = frame.Node;         // context of xsl:number element. We using this node in MatchCountKey()
                    XPathNavigator countNode   = frame.Node.Clone(); // node we count for
                    if(countNode.NodeType == XPathNodeType.Attribute) {
                        countNode.MoveToParent();
                    }
                    while(moveToCount(countNode, processor, contextNode)) {
                        list.Insert(0, numberCount(countNode, processor, contextNode));
                        if(! multiple || ! countNode.MoveToParent()) {
                            break;
                        }
                    }
                    if(! checkFrom(processor, countNode)) {
                        list.Clear();
                    }
                }

                /*CalculatingFormat:*/
                frame.StoredOutput = Format(list, 
                    this.formatAvt       == null ? this.formatList   : ParseFormat(this.formatAvt.Evaluate(processor, frame)), 
                    this.langAvt         == null ? this.lang         : this.langAvt        .Evaluate(processor, frame), 
                    this.letterAvt       == null ? this.letter       : ParseLetter(this.letterAvt.Evaluate(processor, frame)), 
                    this.groupingSepAvt  == null ? this.groupingSep  : this.groupingSepAvt .Evaluate(processor, frame), 
                    this.groupingSizeAvt == null ? this.groupingSize : this.groupingSizeAvt.Evaluate(processor, frame)
                );
                goto case OutputNumber;
            case OutputNumber :
                Debug.Assert(frame.StoredOutput != null);
                if (! processor.TextEvent(frame.StoredOutput)) {
                    frame.State        = OutputNumber;
                    break;
                }
                frame.Finished();
                break;
            default:
                Debug.Fail("Invalid Number Action execution state");
                break;
            }            
        }
Esempio n. 52
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);
            while (processor.CanContinue)
            {
                switch (frame.State)
                {
                case Initialized:
                    if (frame.NextNode(processor))
                    {
                        Debug.WriteLine("Next node to copy found");
                        Debug.WriteLine(frame.Node.Name);
                        frame.State = BeginEvent;
                        goto case BeginEvent;
                    }
                    else
                    {
                        frame.Finished();
                        break;
                    }

                case BeginEvent:
                    Debug.Assert(frame.State == BeginEvent);

                    if (SendBeginEvent(processor, frame.Node) == false)
                    {
                        // This one wasn't output
                        break;
                    }
                    frame.State = Contents;
                    continue;

                case Contents:
                    Debug.Assert(frame.State == Contents);
                    XPathNodeType nodeType = frame.Node.NodeType;

                    if (nodeType == XPathNodeType.Element || nodeType == XPathNodeType.Root)
                    {
                        processor.PushActionFrame(CopyAttributesAction.GetAction(), frame.NodeSet);
                        frame.State = Attributes;
                        break;
                    }

                    if (SendTextEvent(processor, frame.Node) == false)
                    {
                        // This one wasn't output
                        break;
                    }
                    frame.State = EndEvent;
                    continue;

                case Attributes:
                    processor.PushActionFrame(CopyNamespacesAction.GetAction(), frame.NodeSet);
                    frame.State = Namespaces;
                    break;

                case Namespaces:
                    if (frame.Node.HasChildren)
                    {
                        processor.PushActionFrame(GetAction(), frame.Node.SelectChildren(XPathNodeType.All));
                        frame.State = Subtree;
                        break;
                    }
                    frame.State = EndEvent;
                    goto case EndEvent;

                case Subtree:
                    //frame.Node.MoveToParent();
                    frame.State = EndEvent;
                    continue;

                case EndEvent:
                    Debug.Assert(frame.State == EndEvent);

                    if (SendEndEvent(processor, frame.Node) == false)
                    {
                        // This one wasn't output
                        break;
                    }

                    frame.State = Initialized;
                    continue;
                }

                break;
            }
        }
Esempio n. 53
0
        internal void ResetParams()
        {
            ActionFrame frame = (ActionFrame)this.actionStack[actionStack.Length - 1];

            frame.ResetParams();
        }
Esempio n. 54
0
        internal object RunQuery(ActionFrame context, int key) {
            Debug.WriteLine("Evaluating expression: \"" + GetStringQuery(key) + "\"");

            object    value = null;
            XPathExpression expr;

            expr = GetCompiledQuery(key);
            if (expr.ReturnType == XPathResultType.NodeSet){
                return context.Node.Select(expr);
            }
            
            value = context.Node.Evaluate(expr, context.NodeSet);

            return value;
        }
Esempio n. 55
0
 internal void PushActionFrame(ActionFrame container)
 {
     this.PushActionFrame(container, container.NodeSet);
 }
Esempio n. 56
0
 internal string EvaluateString(ActionFrame context, int key) {
     object objValue = Evaluate(context, key);
     string value = null;
     if (objValue != null)
         value = XmlConvert.ToXPathString(objValue);
     if (value == null)
         value = String.Empty;
     return value;
 }
Esempio n. 57
0
        private int numberAny(Processor processor, ActionFrame frame)
        {
            int result = 0;
            // Our current point will be our end point in this search
            XPathNavigator endNode = frame.Node;

            if (endNode.NodeType == XPathNodeType.Attribute)
            {
                endNode = endNode.Clone();
                endNode.MoveToParent();
            }
            XPathNavigator startNode = endNode.Clone();

            if (this.fromKey != Compiler.InvalidQueryKey)
            {
                bool hitFrom = false;
                // First try to find start by traversing up. This gives the best candidate or we hit root
                do
                {
                    if (processor.Matches(startNode, this.fromKey))
                    {
                        hitFrom = true;
                        break;
                    }
                }while(startNode.MoveToParent());

                Debug.Assert(
                    processor.Matches(startNode, this.fromKey) ||   // we hit 'from' or
                    startNode.NodeType == XPathNodeType.Root        // we are at root
                    );

                // from this point (matched parent | root) create descendent quiery:
                // we have to reset 'result' on each 'from' node, because this point can' be not last from point;
                XPathNodeIterator sel = processor.StartQuery(startNode, Compiler.DescendantKey);
                do
                {
                    if (processor.Matches(sel.Current, this.fromKey))
                    {
                        hitFrom = true;
                        result  = 0;
                    }
                    else if (MatchCountKey(processor, frame.Node, sel.Current))
                    {
                        result++;
                    }
                    if (sel.Current.IsSamePosition(endNode))
                    {
                        break;
                    }
                }while (sel.MoveNext());
                if (!hitFrom)
                {
                    result = 0;
                }
            }
            else
            {
                // without 'from' we startting from the root
                startNode.MoveToRoot();
                XPathNodeIterator sel = processor.StartQuery(startNode, Compiler.DescendantKey);
                // and count root node by itself
                do
                {
                    if (MatchCountKey(processor, frame.Node, sel.Current))
                    {
                        result++;
                    }
                    if (sel.Current.IsSamePosition(endNode))
                    {
                        break;
                    }
                }while (sel.MoveNext());
            }
            return(result);
        }
Esempio n. 58
0
        internal bool EvaluateBoolean(ActionFrame context, int key) {
            object objValue = Evaluate(context, key);

            if (objValue != null)
                return ToBoolean(objValue);
            else
                return false;
        }
Esempio n. 59
0
 public override bool Output(Processor processor, ActionFrame frame)
 {
     return(processor.EndEvent(this.nodeType));
 }
Esempio n. 60
0
 internal override DbgData GetDbgData(ActionFrame frame)
 {
     return(this.dbgData);
 }