Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XslAstRewriter.cs
Go to the documentation of this file.
4
5namespace System.Xml.Xsl.Xslt;
6
7internal sealed class XslAstRewriter
8{
10
12
14
15 [MemberNotNull("_compiler")]
17 {
21 foreach (ProtoTemplate allTemplate in compiler.AllTemplates)
22 {
23 _scope.EnterScope();
25 }
26 while (_newTemplates.Count > 0)
27 {
28 Template template = _newTemplates.Pop();
29 compiler.AllTemplates.Add(template);
30 compiler.NamedTemplates.Add(template.Name, template);
31 _scope.EnterScope();
32 CheckNodeCost(template);
33 }
34 }
35
36 private static int NodeCostForXPath(string xpath)
37 {
38 int num = 0;
39 if (xpath != null)
40 {
41 num = 2;
42 for (int i = 2; i < xpath.Length; i += 2)
43 {
44 if (xpath[i] == '/' || xpath[i - 1] == '/')
45 {
46 num += 2;
47 }
48 }
49 }
50 return num;
51 }
52
53 private static bool NodeTypeTest(XslNodeType nodetype, int flags)
54 {
55 return ((flags >> (int)nodetype) & 1) != 0;
56 }
57
59 {
60 _scope.EnterScope(node.Namespaces);
61 bool flag = false;
62 int num = 1;
63 if (NodeTypeTest(node.NodeType, -247451132))
64 {
65 num += NodeCostForXPath(node.Select);
66 }
67 IList<XslNode> content = node.Content;
68 int num2 = content.Count - 1;
69 for (int i = 0; i <= num2; i++)
70 {
71 XslNode xslNode = content[i];
73 num += num3;
74 if (flag && num > 100)
75 {
77 {
78 Refactor(node, i);
79 num -= num3;
80 num++;
81 }
82 break;
83 }
84 if (xslNode.NodeType == XslNodeType.Variable || xslNode.NodeType == XslNodeType.Param)
85 {
86 _scope.AddVariable(xslNode.Name, (VarPar)xslNode);
87 if (xslNode.NodeType == XslNodeType.Param)
88 {
89 num -= num3;
90 }
91 }
92 else if (!flag)
93 {
94 flag = NodeTypeTest(node.NodeType, -1025034872);
95 }
96 }
97 _scope.ExitScope();
98 return num;
99 }
100
101 private void Refactor(XslNode parent, int split)
102 {
105 QilName name = AstFactory.QName("generated", _compiler.CreatePhantomNamespace(), "compiler");
109 Template template = AstFactory.Template(name, null, XsltLoader.nullMode, double.NaN, xslNode.XslVersion);
110 XsltLoader.SetInfo(template, null, contextInfo);
111 _newTemplates.Push(template);
112 template.SetContent(new List<XslNode>(list.Count - split + 8));
113 foreach (CompilerScopeManager<VarPar>.ScopeRecord activeRecord in _scope.GetActiveRecords())
114 {
115 if (!activeRecord.IsVariable)
116 {
117 template.Namespaces = new NsDecl(template.Namespaces, activeRecord.ncName, activeRecord.nsUri);
118 continue;
119 }
120 VarPar value = activeRecord.value;
121 if (!_compiler.IsPhantomNamespace(value.Name.NamespaceUri))
122 {
123 QilName qilName = AstFactory.QName(value.Name.LocalName, value.Name.NamespaceUri, value.Name.Prefix);
124 VarPar varPar = AstFactory.VarPar(XslNodeType.WithParam, qilName, "$" + qilName.QualifiedName, XslVersion.Version10);
126 varPar.Namespaces = value.Namespaces;
127 xslNodeEx.AddContent(varPar);
128 VarPar varPar2 = AstFactory.VarPar(XslNodeType.Param, qilName, null, XslVersion.Version10);
130 varPar2.Namespaces = value.Namespaces;
131 template.AddContent(varPar2);
132 }
133 }
134 for (int i = split; i < list.Count; i++)
135 {
136 template.AddContent(list[i]);
137 }
139 list.RemoveRange(split + 1, list.Count - split - 1);
140 }
141}
void Add(TKey key, TValue value)
static XslNodeEx CallTemplate(QilName name, XsltInput.ContextInfo ctxInfo)
Definition AstFactory.cs:39
static QilName QName(string local, string uri, string prefix)
static VarPar VarPar(XslNodeType nt, QilName name, string select, XslVersion xslVer)
static Template Template(QilName name, string match, QilName mode, double priority, XslVersion xslVer)
bool IsPhantomNamespace(string namespaceName)
Definition Compiler.cs:291
static int NodeCostForXPath(string xpath)
void Refactor(XslNode parent, int split)
void Rewrite(Compiler compiler)
CompilerScopeManager< VarPar > _scope
static bool NodeTypeTest(XslNodeType nodetype, int flags)
IList< XslNode > Content
Definition XslNode.cs:31
static XslNode SetInfo(XslNode to, List< XslNode > content, XsltInput.ContextInfo info)