Beispiel #1
0
        internal void AddTemplate(TemplateAction template) {
            Debug.Assert(template != null);
            Debug.Assert(
                ((object) this.mode == (object) template.Mode) ||
                (template.Mode == null && this.mode.Equals(XmlQualifiedName.Empty)) ||
                this.mode.Equals(template.Mode)
            );

            if (this.templates == null) {
                this.templates = new ArrayList();
            }

            Debug.Assert(this.templates != null);
            Debug.WriteLine("Adding Template #" + this.templates.Count + ", mode==\"" + template.Mode + "\" match=\"" + template.Match + "\"");

            this.templates.Add(template);
        }
Beispiel #2
0
            public int Compare(object x, object y)
            {
                Debug.Assert(x != null && x is TemplateAction);
                Debug.Assert(y != null && y is TemplateAction);

                TemplateAction tx = (TemplateAction)x;
                TemplateAction ty = (TemplateAction)y;

                Debug.Assert(!Double.IsNaN(tx.Priority));
                Debug.Assert(!Double.IsNaN(ty.Priority));

                if (tx.Priority == ty.Priority)
                {
                    Debug.Assert(tx.TemplateId != ty.TemplateId || tx == ty);
                    return(tx.TemplateId - ty.TemplateId);
                }
                else
                {
                    return(tx.Priority > ty.Priority ? 1 : -1);
                }
            }
Beispiel #3
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;
            }
        }
Beispiel #4
0
 internal void ReplaceNamespaceAlias(Compiler compiler)
 {
     if (this.modeManagers != null)
     {
         IDictionaryEnumerator enumerator = this.modeManagers.GetEnumerator();
         while (enumerator.MoveNext())
         {
             TemplateManager manager = (TemplateManager)enumerator.Value;
             if (manager.templates != null)
             {
                 for (int i = 0; i < manager.templates.Count; i++)
                 {
                     TemplateAction template = (TemplateAction)manager.templates[i];
                     template.ReplaceNamespaceAlias(compiler);
                 }
             }
         }
     }
     if (this.templateNameTable != null)
     {
         IDictionaryEnumerator enumerator = this.templateNameTable.GetEnumerator();
         while (enumerator.MoveNext())
         {
             TemplateAction template = (TemplateAction)enumerator.Value;
             template.ReplaceNamespaceAlias(compiler);
         }
     }
     if (this.imports != null)
     {
         for (int importIndex = this.imports.Count - 1; importIndex >= 0; importIndex--)
         {
             Stylesheet stylesheet = (Stylesheet)this.imports[importIndex];
             stylesheet.ReplaceNamespaceAlias(compiler);
         }
     }
 }
Beispiel #5
0
 internal void BeginTemplate(TemplateAction template) {
     Debug.Assert(this.currentTemplate != null);
     this.currentTemplate = template;
     this.currentMode     = template.Mode;
     this.CanHaveApplyImports = template.MatchKey != Compiler.InvalidQueryKey;
 }
Beispiel #6
0
        //
        // Template management
        //

        internal void AddTemplate(TemplateAction template) {
            Debug.Assert(this.stylesheet == this.stylesheets.Peek());
            this.stylesheet.AddTemplate(template);
        }
Beispiel #7
0
 public virtual TemplateAction CreateSingleTemplateAction() {
     TemplateAction action = new TemplateAction();
     action.CompileSingle(this);
     return action;
 }
Beispiel #8
0
        //
        // Template management
        //

        internal void AddTemplate(TemplateAction template)
        {
            Debug.Assert(this.stylesheet == this.stylesheets.Peek());
            this.stylesheet.AddTemplate(template);
        }
Beispiel #9
0
//TRy Changing the algorthim to simplify

        private static bool CalculatePriorities(Compiler compiler, AstNode node, TemplateAction right) {
            switch (node.TypeOfAst) {
            case AstNode.QueryType.Operator:
                Operator op = (Operator) node;
                if (op.OperatorType == Operator.Op.UNION) {
                    TemplateAction left = right.Clone();
                    if (CalculatePriorities(compiler, op.Operand1, left)) {
                        left.FinishClone(compiler, op.Operand1);
                    }
                    compiler.AddTemplate(left);
                    if (CalculatePriorities(compiler, op.Operand2, right)) {
                        right.FinishClone(compiler, op.Operand2);
                    }

                    return false;
                }
                break;
            //case AstNode.QueryType.Group:
            //    return CalculatePriorities(compiler, ((Group)node).GroupNode, right);
            }
            return true;
        }
Beispiel #10
0
        //
        // Priority calculation plus template splitting
        //

        private TemplateAction Clone() {
            TemplateAction clone    = new TemplateAction(); {
                clone.containedActions = this.containedActions;
                clone.name             = this.name;
                clone.mode             = this.mode;
                clone.variableCount    = this.variableCount;
            }
            return clone;
        }
Beispiel #11
0
        internal void AddTemplate(TemplateAction template) {
            XmlQualifiedName mode = template.Mode;

            //
            // Ensure template has a unique name
            //

            Debug.Assert(this.templateNameTable != null);

            if (template.Name != null) {
                if (this.templateNameTable.ContainsKey(template.Name) == false) {
                    this.templateNameTable[template.Name] = template;
                }
                else {
                    throw new XsltException(Res.Xslt_DupTemplateName, template.Name.ToString());
                }
            }


            if (template.Match != null) {
                if (this.modeManagers == null) {
                    this.modeManagers = new Hashtable();
                }
                Debug.Assert(this.modeManagers != null);

                if (mode == null) {
                    mode = XmlQualifiedName.Empty;
                }

                TemplateManager manager = (TemplateManager) this.modeManagers[mode];

                if (manager == null) {
                    manager = new TemplateManager(this, mode);

                    this.modeManagers[mode] = manager;

                    if (mode.IsEmpty) {
                        Debug.Assert(this.templates == null);
                        this.templates = manager;
                    }
                }
                Debug.Assert(manager != null);

                template.TemplateId = ++ this.templateCount;
                manager.AddTemplate(template);
            }
        }