Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Compiler.cs
Go to the documentation of this file.
4
5namespace System.Xml.Xsl.Xslt;
6
7internal sealed class Compiler
8{
9 private sealed class CompilerErrorComparer : IComparer<CompilerError>
10 {
12
17
19 {
20 if (x == y)
21 {
22 return 0;
23 }
24 if (x == null)
25 {
26 return -1;
27 }
28 if (y == null)
29 {
30 return 1;
31 }
32 int num = _moduleOrder[x.FileName].CompareTo(_moduleOrder[y.FileName]);
33 if (num != 0)
34 {
35 return num;
36 }
37 num = x.Line.CompareTo(y.Line);
38 if (num != 0)
39 {
40 return num;
41 }
42 num = x.Column.CompareTo(y.Column);
43 if (num != 0)
44 {
45 return num;
46 }
47 num = x.IsWarning.CompareTo(y.IsWarning);
48 if (num != 0)
49 {
50 return num;
51 }
52 num = string.CompareOrdinal(x.ErrorNumber, y.ErrorNumber);
53 if (num != 0)
54 {
55 return num;
56 }
57 return string.CompareOrdinal(x.ErrorText, y.ErrorText);
58 }
59 }
60
62
63 public bool IsDebug;
64
65 public string ScriptAssemblyPath;
66
67 public int Version;
68
69 public string inputTypeAnnotations;
70
72
74
76
78
80
81 public Output Output = new Output();
82
84
86
88
90
91 public Keys Keys = new Keys();
92
94
96
98
100
102
104
105 public readonly string PhantomNCName = "error";
106
107 private int _phantomNsCounter;
108
109 private int _savedErrorCount = -1;
110
111 private int ErrorCount
112 {
113 get
114 {
116 }
117 set
118 {
119 for (int num = ErrorCount - 1; num >= value; num--)
120 {
122 }
123 }
124 }
125
134
136 {
137 new XsltLoader().Load(this, stylesheet, xmlResolver);
139 SortErrors();
140 return CompilerErrorColl;
141 }
142
144 {
145 Stylesheet stylesheet = new Stylesheet(this, CurrentPrecedence);
146 if (CurrentPrecedence-- == 0)
147 {
148 Root = new RootLevel(stylesheet);
149 }
150 return stylesheet;
151 }
152
153 public void AddModule(string baseUri)
154 {
155 if (!_moduleOrder.ContainsKey(baseUri))
156 {
158 }
159 }
160
161 public void ApplyNsAliases(ref string prefix, ref string nsUri)
162 {
163 if (NsAliases.TryGetValue(nsUri, out var value))
164 {
165 nsUri = value.ResultNsUri;
166 prefix = value.ResultPrefix;
167 }
168 }
169
170 public bool SetNsAlias(string ssheetNsUri, string resultNsUri, string resultPrefix, int importPrecedence)
171 {
172 if (NsAliases.TryGetValue(ssheetNsUri, out var value) && (importPrecedence < value.ImportPrecedence || resultNsUri == value.ResultNsUri))
173 {
174 return false;
175 }
177 return value != null;
178 }
179
181 {
182 for (int i = 0; i <= 2; i++)
183 {
184 sheet.WhitespaceRules[i].Reverse();
185 WhitespaceRules.AddRange(sheet.WhitespaceRules[i]);
186 }
188 }
189
191 {
192 foreach (QilName key in sheet.AttributeSets.Keys)
193 {
195 {
196 AttributeSets[key] = sheet.AttributeSets[key];
197 }
198 else
199 {
200 value.MergeContent(sheet.AttributeSets[key]);
201 }
202 }
203 sheet.AttributeSets = null;
204 }
205
207 {
208 foreach (VarPar globalVarPar in sheet.GlobalVarPars)
209 {
211 {
212 if (globalVarPar.NodeType == XslNodeType.Variable)
213 {
215 }
216 else
217 {
219 }
221 }
222 }
223 sheet.GlobalVarPars = null;
224 }
225
232
233 public static string ConstructQName(string prefix, string localName)
234 {
235 if (prefix.Length == 0)
236 {
237 return localName;
238 }
239 return prefix + ":" + localName;
240 }
241
242 public bool ParseQName(string qname, out string prefix, out string localName, IErrorHelper errorHelper)
243 {
244 try
245 {
246 ValidateNames.ParseQNameThrow(qname, out prefix, out localName);
247 return true;
248 }
249 catch (XmlException ex)
250 {
251 errorHelper.ReportError(ex.Message, (string[])null);
253 localName = PhantomNCName;
254 return false;
255 }
256 }
257
258 public bool ParseNameTest(string nameTest, out string prefix, out string localName, IErrorHelper errorHelper)
259 {
260 try
261 {
263 return true;
264 }
265 catch (XmlException ex)
266 {
267 errorHelper.ReportError(ex.Message, (string[])null);
269 localName = PhantomNCName;
270 return false;
271 }
272 }
273
274 public void ValidatePiName(string name, IErrorHelper errorHelper)
275 {
276 try
277 {
278 ValidateNames.ValidateNameThrow(string.Empty, name, string.Empty, XPathNodeType.ProcessingInstruction, ValidateNames.Flags.AllExceptPrefixMapping);
279 }
280 catch (XmlException ex)
281 {
282 errorHelper.ReportError(ex.Message, (string[])null);
283 }
284 }
285
287 {
288 return "\0namespace" + _phantomNsCounter++;
289 }
290
292 {
293 if (namespaceName.Length > 0)
294 {
295 return namespaceName[0] == '\0';
296 }
297 return false;
298 }
299
300 public bool IsPhantomName(QilName qname)
301 {
302 string namespaceUri = qname.NamespaceUri;
303 if (namespaceUri.Length > 0)
304 {
305 return namespaceUri[0] == '\0';
306 }
307 return false;
308 }
309
311 {
313 }
314
316 {
318 {
320 return false;
321 }
322 return true;
323 }
324
325 public CompilerError CreateError(ISourceLineInfo lineInfo, string res, params string[] args)
326 {
327 AddModule(lineInfo.Uri);
328 return new CompilerError(lineInfo.Uri, lineInfo.Start.Line, lineInfo.Start.Pos, string.Empty, XslTransformException.CreateMessage(res, args));
329 }
330
331 public void ReportError(ISourceLineInfo lineInfo, string res, params string[] args)
332 {
333 CompilerError value = CreateError(lineInfo, res, args);
335 }
336
337 public void ReportWarning(ISourceLineInfo lineInfo, string res, params string[] args)
338 {
339 int num = 1;
340 if (0 > Settings.WarningLevel || Settings.WarningLevel >= num)
341 {
344 {
347 }
348 else
349 {
352 }
353 }
354 }
355
368}
static void Sort(Array array)
Definition Array.cs:2329
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
void AddRange(IEnumerable< KeyValuePair< TKey, TValue > > collection)
void Add(TKey key, TValue value)
void AddRange(IEnumerable< T > collection)
Definition List.cs:275
static string Xslt_WarningAsError
Definition SR.cs:1860
Definition SR.cs:7
static void ValidateNameThrow(string prefix, string localName, string ns, XPathNodeType nodeKind, Flags flags)
static int ParseQNameThrow(string s)
static void ParseNameTestThrow(string s, out string prefix, out string localName)
static string CreateMessage(string res, params string[] args)
readonly Dictionary< string, int > _moduleOrder
Definition Compiler.cs:11
CompilerErrorComparer(Dictionary< string, int > moduleOrder)
Definition Compiler.cs:13
int Compare(CompilerError x, CompilerError y)
Definition Compiler.cs:18
Compiler(XsltSettings settings, bool debug, string scriptAssemblyPath)
Definition Compiler.cs:126
bool ParseNameTest(string nameTest, out string prefix, out string localName, IErrorHelper errorHelper)
Definition Compiler.cs:258
List< WhitespaceRule > WhitespaceRules
Definition Compiler.cs:87
CompilerErrorCollection Compile(object stylesheet, XmlResolver xmlResolver, out QilExpression qil)
Definition Compiler.cs:135
Dictionary< QilName, AttributeSet > AttributeSets
Definition Compiler.cs:99
void MergeAttributeSets(Stylesheet sheet)
Definition Compiler.cs:190
static string ConstructQName(string prefix, string localName)
Definition Compiler.cs:233
readonly Dictionary< string, int > _moduleOrder
Definition Compiler.cs:103
void MergeWhitespaceRules(Stylesheet sheet)
Definition Compiler.cs:180
bool IsPhantomNamespace(string namespaceName)
Definition Compiler.cs:291
void MergeWithStylesheet(Stylesheet sheet)
Definition Compiler.cs:226
void ValidatePiName(string name, IErrorHelper errorHelper)
Definition Compiler.cs:274
Dictionary< QilName, Template > NamedTemplates
Definition Compiler.cs:97
bool IsPhantomName(QilName qname)
Definition Compiler.cs:300
readonly string PhantomNCName
Definition Compiler.cs:105
Stylesheet CreateStylesheet()
Definition Compiler.cs:143
void ReportWarning(ISourceLineInfo lineInfo, string res, params string[] args)
Definition Compiler.cs:337
List< VarPar > GlobalVars
Definition Compiler.cs:85
Dictionary< string, NsAlias > NsAliases
Definition Compiler.cs:101
CompilerErrorCollection CompilerErrorColl
Definition Compiler.cs:71
bool ExitForwardsCompatible(bool fwdCompat)
Definition Compiler.cs:315
void ReportError(ISourceLineInfo lineInfo, string res, params string[] args)
Definition Compiler.cs:331
CompilerError CreateError(ISourceLineInfo lineInfo, string res, params string[] args)
Definition Compiler.cs:325
DecimalFormats DecimalFormats
Definition Compiler.cs:89
bool SetNsAlias(string ssheetNsUri, string resultNsUri, string resultPrefix, int importPrecedence)
Definition Compiler.cs:170
void MergeGlobalVarPars(Stylesheet sheet)
Definition Compiler.cs:206
void ApplyNsAliases(ref string prefix, ref string nsUri)
Definition Compiler.cs:161
void AddModule(string baseUri)
Definition Compiler.cs:153
Dictionary< QilName, VarPar > AllGlobalVarPars
Definition Compiler.cs:95
List< ProtoTemplate > AllTemplates
Definition Compiler.cs:93
bool ParseQName(string qname, out string prefix, out string localName, IErrorHelper errorHelper)
Definition Compiler.cs:242
List< VarPar > ExternalPars
Definition Compiler.cs:83
static QilExpression CompileStylesheet(Compiler compiler)
void Load(Compiler compiler, object stylesheet, XmlResolver xmlResolver)