Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlQueryRuntime.cs
Go to the documentation of this file.
11
13
15public sealed class XmlQueryRuntime
16{
17 private readonly XmlQueryContext _ctxt;
18
20
21 private readonly EarlyBoundInfo[] _earlyInfo;
22
23 private readonly object[] _earlyObjects;
24
25 private readonly string[] _globalNames;
26
27 private readonly object[] _globalValues;
28
29 private readonly XmlNameTable _nameTableQuery;
30
31 private readonly string[] _atomizedNames;
32
33 private readonly XmlNavigatorFilter[] _filters;
34
35 private readonly StringPair[][] _prefixMappingsList;
36
37 private readonly XmlQueryType[] _types;
38
39 private readonly XmlCollation[] _collations;
40
42
44
46
48
50
52 {
53 get
54 {
55 if (_xsltLib == null)
56 {
57 _xsltLib = new XsltLibrary(this);
58 }
59 return _xsltLib;
60 }
61 }
62
64
66
68 {
69 string[] names = data.Names;
70 Int32Pair[] filters = data.Filters;
71 _ctxt = new XmlQueryContext(this, defaultDataSource, dataSources, argList, (data.WhitespaceRules != null && data.WhitespaceRules.Count != 0) ? new WhitespaceRuleLookup(data.WhitespaceRules) : null);
72 _xsltLib = null;
74 _earlyObjects = ((_earlyInfo != null) ? new object[_earlyInfo.Length] : null);
76 _globalValues = ((_globalNames != null) ? new object[_globalNames.Length] : null);
78 _atomizedNames = null;
79 if (names != null)
80 {
82 _atomizedNames = new string[names.Length];
84 {
85 for (int i = 0; i < names.Length; i++)
86 {
87 string text = defaultNameTable.Get(names[i]);
89 }
90 }
91 else
92 {
93 for (int i = 0; i < names.Length; i++)
94 {
96 }
97 }
98 }
99 _filters = null;
100 if (filters != null)
101 {
102 _filters = new XmlNavigatorFilter[filters.Length];
103 for (int i = 0; i < filters.Length; i++)
104 {
106 }
107 }
109 _types = data.Types;
110 _collations = data.Collations;
112 _indexes = null;
114 _output = new XmlQueryOutput(this, seqWrt);
115 }
116
117 public string[] DebugGetGlobalNames()
118 {
119 return _globalNames;
120 }
121
122 public IList DebugGetGlobalValue(string name)
123 {
124 for (int i = 0; i < _globalNames.Length; i++)
125 {
126 if (_globalNames[i] == name)
127 {
128 return (IList)_globalValues[i];
129 }
130 }
131 return null;
132 }
133
134 public void DebugSetGlobalValue(string name, object value)
135 {
136 for (int i = 0; i < _globalNames.Length; i++)
137 {
138 if (_globalNames[i] == name)
139 {
141 break;
142 }
143 }
144 }
145
147 {
148 if (seq != null && seq.Count == 1)
149 {
151 if (xPathItem != null && !xPathItem.IsNode)
152 {
153 return xPathItem.TypedValue;
154 }
156 {
157 return ((RtfNavigator)xPathItem).ToNavigator();
158 }
159 }
160 return seq;
161 }
162
163 public object GetEarlyBoundObject(int index)
164 {
165 object obj = _earlyObjects[index];
166 if (obj == null)
167 {
170 }
171 return obj;
172 }
173
174 [RequiresUnreferencedCode("The extension function referenced will be called from the stylesheet which cannot be statically analyzed.")]
175 public bool EarlyBoundFunctionExists(string name, string namespaceUri)
176 {
177 if (_earlyInfo == null)
178 {
179 return false;
180 }
181 for (int i = 0; i < _earlyInfo.Length; i++)
182 {
183 if (namespaceUri == _earlyInfo[i].NamespaceUri)
184 {
185 return new XmlExtensionFunction(name, namespaceUri, -1, _earlyInfo[i].EarlyBoundType, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public).CanBind();
186 }
187 }
188 return false;
189 }
190
191 public bool IsGlobalComputed(int index)
192 {
193 return _globalValues[index] != null;
194 }
195
196 public object GetGlobalValue(int index)
197 {
198 return _globalValues[index];
199 }
200
201 public void SetGlobalValue(int index, object value)
202 {
204 }
205
206 public string GetAtomizedName(int index)
207 {
208 return _atomizedNames[index];
209 }
210
212 {
213 return _filters[index];
214 }
215
217 {
218 return nodeType switch
219 {
222 _ => XmlNavTypeFilter.Create(nodeType),
223 };
224 }
225
227 {
229 return new XmlQualifiedName(localName, ns);
230 }
231
232 public XmlQualifiedName ParseTagName(string tagName, string ns)
233 {
235 return new XmlQualifiedName(localName, ns);
236 }
237
238 internal void ParseTagName(string tagName, int idxPrefixMappings, out string prefix, out string localName, out string ns)
239 {
241 ns = null;
243 for (int i = 0; i < array.Length; i++)
244 {
246 if (prefix == stringPair.Left)
247 {
248 ns = stringPair.Right;
249 break;
250 }
251 }
252 if (ns != null)
253 {
254 return;
255 }
256 if (prefix.Length == 0)
257 {
258 ns = "";
259 return;
260 }
261 if (prefix.Equals("xml"))
262 {
263 ns = "http://www.w3.org/XML/1998/namespace";
264 return;
265 }
266 if (prefix.Equals("xmlns"))
267 {
268 ns = "http://www.w3.org/2000/xmlns/";
269 return;
270 }
272 }
273
275 {
276 if (n1.NameTable == n2.NameTable)
277 {
278 if ((object)n1.LocalName == n2.LocalName)
279 {
280 return (object)n1.NamespaceURI == n2.NamespaceURI;
281 }
282 return false;
283 }
284 if (n1.LocalName == n2.LocalName)
285 {
286 return n1.NamespaceURI == n2.NamespaceURI;
287 }
288 return false;
289 }
290
292 {
293 if (navigator.NameTable == _nameTableQuery)
294 {
295 if ((object)GetAtomizedName(indexLocalName) == navigator.LocalName)
296 {
297 return (object)GetAtomizedName(indexNamespaceUri) == navigator.NamespaceURI;
298 }
299 return false;
300 }
301 if (GetAtomizedName(indexLocalName) == navigator.LocalName)
302 {
303 return GetAtomizedName(indexNamespaceUri) == navigator.NamespaceURI;
304 }
305 return false;
306 }
307
309 {
310 return _types[idxType];
311 }
312
317
319 {
320 switch (xmlType.TypeCode)
321 {
322 case XmlTypeCode.String:
324 {
326 }
327 break;
328 case XmlTypeCode.Double:
330 {
332 }
333 break;
334 case XmlTypeCode.Node:
336 {
338 }
340 {
343 for (int i = 0; i < list2.Count; i++)
344 {
345 array[i] = list2[i];
346 }
347 value = array;
348 }
349 break;
350 case XmlTypeCode.Item:
351 {
353 {
355 }
357 if (list.Count == 1)
358 {
360 value = ((!xPathItem.IsNode) ? xPathItem.TypedValue : ((!(xPathItem is RtfNavigator rtfNavigator)) ? ((ICloneable)new XPathArrayIterator((IList)value)) : ((ICloneable)rtfNavigator.ToNavigator())));
361 }
362 else
363 {
365 }
366 break;
367 }
368 }
369 return value;
370 }
371
372 public object ChangeTypeXsltResult(int indexType, object value)
373 {
375 }
376
377 internal object ChangeTypeXsltResult(XmlQueryType xmlType, object value)
378 {
379 if (value == null)
380 {
381 throw new XslTransformException(System.SR.Xslt_ItemNull, string.Empty);
382 }
383 switch (xmlType.TypeCode)
384 {
385 case XmlTypeCode.String:
386 if (value.GetType() == XsltConvert.DateTimeType)
387 {
389 }
390 break;
391 case XmlTypeCode.Double:
392 if (value.GetType() != XsltConvert.DoubleType)
393 {
394 value = ((IConvertible)value).ToDouble(null);
395 }
396 break;
397 case XmlTypeCode.Node:
398 if (xmlType.IsSingleton)
399 {
400 break;
401 }
403 {
405 }
406 else
407 {
409 if (value is IList list)
410 {
411 for (int i = 0; i < list.Count; i++)
412 {
414 }
415 }
416 else
417 {
418 foreach (object item in (IEnumerable)value)
419 {
421 }
422 }
424 }
425 value = ((XmlQueryNodeSequence)value).DocOrderDistinct(_docOrderCmp);
426 break;
427 case XmlTypeCode.Item:
428 {
430 switch (XsltConvert.InferXsltType(type).TypeCode)
431 {
432 case XmlTypeCode.Boolean:
434 break;
435 case XmlTypeCode.Double:
437 break;
438 case XmlTypeCode.String:
440 break;
441 case XmlTypeCode.Node:
443 break;
444 case XmlTypeCode.Item:
446 {
448 break;
449 }
451 {
453 }
455 break;
456 }
457 break;
458 }
459 }
460 return value;
461 }
462
463 private static XPathNavigator EnsureNavigator(object value)
464 {
465 if (!(value is XPathNavigator result))
466 {
467 throw new XslTransformException(System.SR.Xslt_ItemNull, string.Empty);
468 }
469 return result;
470 }
471
473 {
475 if (!(seq.Count switch
476 {
477 0 => XmlQueryCardinality.Zero,
478 1 => XmlQueryCardinality.One,
479 _ => XmlQueryCardinality.More,
480 } <= xmlType.Cardinality))
481 {
482 return false;
483 }
484 xmlType = xmlType.Prime;
485 for (int i = 0; i < seq.Count; i++)
486 {
487 if (!CreateXmlType(seq[0]).IsSubtypeOf(xmlType))
488 {
489 return false;
490 }
491 }
492 return true;
493 }
494
499
501 {
502 if (seq.Count != 1)
503 {
504 return false;
505 }
506 return MatchesXmlType(seq[0], code);
507 }
508
510 {
511 if (code > XmlTypeCode.AnyAtomicType)
512 {
513 if (!item.IsNode)
514 {
515 return item.XmlType.TypeCode == code;
516 }
517 return false;
518 }
519 switch (code)
520 {
521 case XmlTypeCode.AnyAtomicType:
522 return !item.IsNode;
523 case XmlTypeCode.Node:
524 return item.IsNode;
525 case XmlTypeCode.Item:
526 return true;
527 default:
528 if (!item.IsNode)
529 {
530 return false;
531 }
532 return ((XPathNavigator)item).NodeType switch
533 {
534 XPathNodeType.Root => code == XmlTypeCode.Document,
541 XPathNodeType.ProcessingInstruction => code == XmlTypeCode.ProcessingInstruction,
543 _ => false,
544 };
545 }
546 }
547
549 {
550 if (item.IsNode)
551 {
552 if (item is RtfNavigator)
553 {
555 }
557 switch (xPathNavigator.NodeType)
558 {
559 case XPathNodeType.Root:
560 case XPathNodeType.Element:
561 if (xPathNavigator.XmlType == null)
562 {
564 }
565 return XmlQueryTypeFactory.Type(xPathNavigator.NodeType, XmlQualifiedNameTest.New(xPathNavigator.LocalName, xPathNavigator.NamespaceURI), xPathNavigator.XmlType, xPathNavigator.SchemaInfo.SchemaElement.IsNillable);
566 case XPathNodeType.Attribute:
567 if (xPathNavigator.XmlType == null)
568 {
570 }
572 default:
574 }
575 }
577 }
578
580 {
581 return _collations[index];
582 }
583
585 {
587 }
588
593
607
617
619 {
621 xPathNavigator.MoveToRoot();
622 if (_indexes != null && indexId < _indexes.Length)
623 {
625 if (arrayList != null)
626 {
627 for (int i = 0; i < arrayList.Count; i += 2)
628 {
629 if (((XPathNavigator)arrayList[i]).IsSamePosition(xPathNavigator))
630 {
631 index = (XmlILIndex)arrayList[i + 1];
632 return true;
633 }
634 }
635 }
636 }
637 index = new XmlILIndex();
638 return false;
639 }
640
642 {
644 xPathNavigator.MoveToRoot();
645 if (_indexes == null)
646 {
647 _indexes = new ArrayList[indexId + 4];
648 }
649 else if (indexId >= _indexes.Length)
650 {
651 ArrayList[] array = new ArrayList[indexId + 4];
652 Array.Copy(_indexes, array, _indexes.Length);
653 _indexes = array;
654 }
656 if (arrayList == null)
657 {
658 arrayList = new ArrayList();
660 }
663 }
664
670
677
678 public void StartRtfConstruction(string baseUri, out XmlQueryOutput output)
679 {
680 _stkOutput.Push(_output);
681 output = (_output = new XmlQueryOutput(this, new XmlEventCache(baseUri, hasRootNode: true)));
682 }
683
691
692 public XPathNavigator TextRtfConstruction(string text, string baseUri)
693 {
694 return new RtfTextNavigator(text, baseUri);
695 }
696
697 public void SendMessage(string message)
698 {
700 }
701
702 public void ThrowException(string text)
703 {
704 throw new XslTransformException(text);
705 }
706
708 {
709 if (navigatorThis == null || !navigatorThis.MoveTo(navigatorThat))
710 {
711 return navigatorThat.Clone();
712 }
713 return navigatorThis;
714 }
715
716 public static int OnCurrentNodeChanged(XPathNavigator currentNode)
717 {
718 if (currentNode is IXmlLineInfo xmlLineInfo && (currentNode.NodeType != XPathNodeType.Namespace || !IsInheritedNamespace(currentNode)))
719 {
720 OnCurrentNodeChanged2(currentNode.BaseURI, xmlLineInfo.LineNumber, xmlLineInfo.LinePosition);
721 }
722 return 0;
723 }
724
726 {
728 if (xPathNavigator.MoveToParent() && xPathNavigator.MoveToFirstNamespace(XPathNamespaceScope.Local))
729 {
730 do
731 {
732 if ((object)xPathNavigator.LocalName == node.LocalName)
733 {
734 return false;
735 }
736 }
737 while (xPathNavigator.MoveToNextNamespace(XPathNamespaceScope.Local));
738 }
739 return true;
740 }
741
742 private static void OnCurrentNodeChanged2(string baseUri, int lineNumber, int linePosition)
743 {
744 }
745}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
void Add(TKey key, TValue value)
static ? object ChangeType(object? value, TypeCode typeCode)
Definition Convert.cs:229
static CultureInfo InvariantCulture
static string Xslt_InvalidPrefix
Definition SR.cs:1926
static string Xslt_UnsupportedClrType
Definition SR.cs:1992
static string Xslt_ItemNull
Definition SR.cs:1988
Definition SR.cs:7
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
static readonly XmlValueConverter ItemList
static XmlSchemaComplexType UntypedAnyType
static ? XmlSchemaSimpleType GetBuiltInSimpleType(XmlQualifiedName qualifiedName)
static int ParseQNameThrow(string s)
string Add(char[] array, int offset, int length)
int Compare(XPathNavigator navThis, XPathNavigator navThat)
static XmlCollation Create(string collationLiteral)
static XmlNavigatorFilter Create()
static XmlNavigatorFilter Create(string localName, string namespaceUri)
static XmlNavigatorFilter Create(XPathNodeType nodeType)
IList< XPathNavigator > DocOrderDistinct(IList< XPathNavigator > seq)
bool MatchesXmlType(XPathItem item, XmlTypeCode code)
XPathNavigator TextRtfConstruction(string text, string baseUri)
bool MatchesXmlType(XPathItem item, int indexType)
XmlNavigatorFilter GetNameFilter(int index)
static int OnCurrentNodeChanged(XPathNavigator currentNode)
readonly XmlNavigatorFilter[] _filters
XmlCollation CreateCollation(string collation)
void StartRtfConstruction(string baseUri, out XmlQueryOutput output)
object ChangeTypeXsltArgument(XmlQueryType xmlType, object value, Type destinationType)
XmlQueryRuntime(XmlQueryStaticData data, object defaultDataSource, XmlResolver dataSources, XsltArgumentList argList, XmlSequenceWriter seqWrt)
readonly DocumentOrderComparer _docOrderCmp
readonly Stack< XmlQueryOutput > _stkOutput
bool IsQNameEqual(XPathNavigator navigator, int indexLocalName, int indexNamespaceUri)
void DebugSetGlobalValue(string name, object value)
readonly StringPair[][] _prefixMappingsList
object ChangeTypeXsltResult(int indexType, object value)
static void OnCurrentNodeChanged2(string baseUri, int lineNumber, int linePosition)
bool MatchesXmlType(IList< XPathItem > seq, int indexType)
bool IsQNameEqual(XPathNavigator n1, XPathNavigator n2)
object ChangeTypeXsltResult(XmlQueryType xmlType, object value)
bool EarlyBoundFunctionExists(string name, string namespaceUri)
IList< XPathItem > EndSequenceConstruction(out XmlQueryOutput output)
static XPathNavigator EnsureNavigator(object value)
static XPathNavigator SyncToNavigator(XPathNavigator navigatorThis, XPathNavigator navigatorThat)
void AddNewIndex(XPathNavigator context, int indexId, XmlILIndex index)
bool FindIndex(XPathNavigator context, int indexId, out XmlILIndex index)
bool MatchesXmlType(IList< XPathItem > seq, XmlTypeCode code)
XmlNavigatorFilter GetTypeFilter(XPathNodeType nodeType)
XPathNavigator EndRtfConstruction(out XmlQueryOutput output)
object ChangeTypeXsltArgument(int indexType, object value, Type destinationType)
readonly EarlyBoundInfo[] _earlyInfo
static bool IsInheritedNamespace(XPathNavigator node)
void ParseTagName(string tagName, int idxPrefixMappings, out string prefix, out string localName, out string ns)
XmlQualifiedName ParseTagName(string tagName, int indexPrefixMappings)
string GenerateId(XPathNavigator navigator)
void SetGlobalValue(int index, object value)
void StartSequenceConstruction(out XmlQueryOutput output)
XmlQualifiedName ParseTagName(string tagName, string ns)
XmlQueryType CreateXmlType(XPathItem item)
int ComparePosition(XPathNavigator navigatorThis, XPathNavigator navigatorThat)
static readonly Type XPathNavigatorArrayType
static readonly Type ObjectType
static XmlQueryType InferXsltType(Type clrType)
static readonly Type DoubleType
static DateTime ToDateTime(string value)
static readonly Type DateTimeType
static string ToString(double value)
static readonly Type XPathNodeIteratorType
static XmlQualifiedNameTest New(string name, string ns)
static XmlQualifiedNameTest Wildcard
static XmlQueryType Type(XmlTypeCode code, bool isStrict)
static readonly XmlQueryType Node
static readonly XmlQueryType NodeS
XmlQueryCardinality Cardinality
bool IsSubtypeOf(XmlQueryType baseType)