Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlQueryType.cs
Go to the documentation of this file.
2using System.IO;
3using System.Text;
5
6namespace System.Xml.Xsl;
7
8internal abstract class XmlQueryType : ListBase<XmlQueryType>
9{
10 private enum TypeFlags
11 {
12 None = 0,
13 IsNode = 1,
14 IsAtomicValue = 2,
15 IsNumeric = 4
16 }
17
18 private sealed class BitMatrix
19 {
20 private readonly ulong[] _bits;
21
22 public bool this[int index1, int index2]
23 {
24 get
25 {
26 return (_bits[index1] & (ulong)(1L << index2)) != 0;
27 }
28 set
29 {
30 if (value)
31 {
32 _bits[index1] |= (ulong)(1L << index2);
33 }
34 else
35 {
36 _bits[index1] &= (ulong)(~(1L << index2));
37 }
38 }
39 }
40
41 public bool this[XmlTypeCode index1, XmlTypeCode index2] => this[(int)index1, (int)index2];
42
43 public BitMatrix(int count)
44 {
45 _bits = new ulong[count];
46 }
47 }
48
49 private int _hashCode;
50
51 private static readonly TypeFlags[] s_typeCodeToFlags = new TypeFlags[55]
52 {
53 (TypeFlags)7,
54 TypeFlags.None,
55 TypeFlags.IsNode,
56 TypeFlags.IsNode,
57 TypeFlags.IsNode,
58 TypeFlags.IsNode,
59 TypeFlags.IsNode,
60 TypeFlags.IsNode,
61 TypeFlags.IsNode,
62 TypeFlags.IsNode,
63 TypeFlags.IsAtomicValue,
64 TypeFlags.IsAtomicValue,
65 TypeFlags.IsAtomicValue,
66 TypeFlags.IsAtomicValue,
67 (TypeFlags)6,
68 (TypeFlags)6,
69 (TypeFlags)6,
70 TypeFlags.IsAtomicValue,
71 TypeFlags.IsAtomicValue,
72 TypeFlags.IsAtomicValue,
73 TypeFlags.IsAtomicValue,
74 TypeFlags.IsAtomicValue,
75 TypeFlags.IsAtomicValue,
76 TypeFlags.IsAtomicValue,
77 TypeFlags.IsAtomicValue,
78 TypeFlags.IsAtomicValue,
79 TypeFlags.IsAtomicValue,
80 TypeFlags.IsAtomicValue,
81 TypeFlags.IsAtomicValue,
82 TypeFlags.IsAtomicValue,
83 TypeFlags.IsAtomicValue,
84 TypeFlags.IsAtomicValue,
85 TypeFlags.IsAtomicValue,
86 TypeFlags.IsAtomicValue,
87 TypeFlags.IsAtomicValue,
88 TypeFlags.IsAtomicValue,
89 TypeFlags.IsAtomicValue,
90 TypeFlags.IsAtomicValue,
91 TypeFlags.IsAtomicValue,
92 TypeFlags.IsAtomicValue,
93 (TypeFlags)6,
94 (TypeFlags)6,
95 (TypeFlags)6,
96 (TypeFlags)6,
97 (TypeFlags)6,
98 (TypeFlags)6,
99 (TypeFlags)6,
100 (TypeFlags)6,
101 (TypeFlags)6,
102 (TypeFlags)6,
103 (TypeFlags)6,
104 (TypeFlags)6,
105 (TypeFlags)6,
106 TypeFlags.IsAtomicValue,
107 TypeFlags.IsAtomicValue
108 };
109
110 private static readonly XmlTypeCode[] s_baseTypeCodes = new XmlTypeCode[55]
111 {
112 XmlTypeCode.None,
113 XmlTypeCode.Item,
114 XmlTypeCode.Item,
115 XmlTypeCode.Node,
116 XmlTypeCode.Node,
117 XmlTypeCode.Node,
118 XmlTypeCode.Node,
119 XmlTypeCode.Node,
120 XmlTypeCode.Node,
121 XmlTypeCode.Node,
122 XmlTypeCode.Item,
123 XmlTypeCode.AnyAtomicType,
124 XmlTypeCode.AnyAtomicType,
125 XmlTypeCode.AnyAtomicType,
126 XmlTypeCode.AnyAtomicType,
127 XmlTypeCode.AnyAtomicType,
128 XmlTypeCode.AnyAtomicType,
129 XmlTypeCode.AnyAtomicType,
130 XmlTypeCode.AnyAtomicType,
131 XmlTypeCode.AnyAtomicType,
132 XmlTypeCode.AnyAtomicType,
133 XmlTypeCode.AnyAtomicType,
134 XmlTypeCode.AnyAtomicType,
135 XmlTypeCode.AnyAtomicType,
136 XmlTypeCode.AnyAtomicType,
137 XmlTypeCode.AnyAtomicType,
138 XmlTypeCode.AnyAtomicType,
139 XmlTypeCode.AnyAtomicType,
140 XmlTypeCode.AnyAtomicType,
141 XmlTypeCode.AnyAtomicType,
142 XmlTypeCode.AnyAtomicType,
143 XmlTypeCode.String,
144 XmlTypeCode.NormalizedString,
145 XmlTypeCode.Token,
146 XmlTypeCode.Token,
147 XmlTypeCode.Token,
148 XmlTypeCode.Name,
149 XmlTypeCode.NCName,
150 XmlTypeCode.NCName,
151 XmlTypeCode.NCName,
152 XmlTypeCode.Decimal,
153 XmlTypeCode.Integer,
154 XmlTypeCode.NonPositiveInteger,
155 XmlTypeCode.Integer,
156 XmlTypeCode.Long,
157 XmlTypeCode.Int,
158 XmlTypeCode.Short,
159 XmlTypeCode.Integer,
160 XmlTypeCode.NonNegativeInteger,
161 XmlTypeCode.UnsignedLong,
162 XmlTypeCode.UnsignedInt,
163 XmlTypeCode.UnsignedShort,
164 XmlTypeCode.NonNegativeInteger,
165 XmlTypeCode.Duration,
167 };
168
169 private static readonly string[] s_typeNames = new string[55]
170 {
171 "none", "item", "node", "document", "element", "attribute", "namespace", "processing-instruction", "comment", "text",
172 "xdt:anyAtomicType", "xdt:untypedAtomic", "xs:string", "xs:boolean", "xs:decimal", "xs:float", "xs:double", "xs:duration", "xs:dateTime", "xs:time",
173 "xs:date", "xs:gYearMonth", "xs:gYear", "xs:gMonthDay", "xs:gDay", "xs:gMonth", "xs:hexBinary", "xs:base64Binary", "xs:anyUri", "xs:QName",
174 "xs:NOTATION", "xs:normalizedString", "xs:token", "xs:language", "xs:NMTOKEN", "xs:Name", "xs:NCName", "xs:ID", "xs:IDREF", "xs:ENTITY",
175 "xs:integer", "xs:nonPositiveInteger", "xs:negativeInteger", "xs:long", "xs:int", "xs:short", "xs:byte", "xs:nonNegativeInteger", "xs:unsignedLong", "xs:unsignedInt",
176 "xs:unsignedShort", "xs:unsignedByte", "xs:positiveInteger", "xdt:yearMonthDuration", "xdt:dayTimeDuration"
177 };
178
180
181 public abstract XmlTypeCode TypeCode { get; }
182
183 public abstract XmlQualifiedNameTest NameTest { get; }
184
185 public abstract XmlSchemaType SchemaType { get; }
186
187 public abstract bool IsNillable { get; }
188
189 public abstract XmlNodeKindFlags NodeKinds { get; }
190
191 public abstract bool IsStrict { get; }
192
193 public abstract XmlQueryCardinality Cardinality { get; }
194
195 public abstract XmlQueryType Prime { get; }
196
197 public abstract bool IsNotRtf { get; }
198
199 public abstract bool IsDod { get; }
200
202
204
206
208
209 public bool IsNode => (s_typeCodeToFlags[(int)TypeCode] & TypeFlags.IsNode) != 0;
210
211 public bool IsAtomicValue => (s_typeCodeToFlags[(int)TypeCode] & TypeFlags.IsAtomicValue) != 0;
212
214 {
215 if (!(Cardinality <= baseType.Cardinality) || (!IsDod && baseType.IsDod))
216 {
217 return false;
218 }
219 if (!IsDod && baseType.IsDod)
220 {
221 return false;
222 }
225 if ((object)prime == prime2)
226 {
227 return true;
228 }
229 if (prime.Count == 1 && prime2.Count == 1)
230 {
232 }
233 foreach (XmlQueryType item in prime)
234 {
235 bool flag = false;
236 foreach (XmlQueryType item2 in prime2)
237 {
238 if (item.IsSubtypeOfItemType(item2))
239 {
240 flag = true;
241 break;
242 }
243 }
244 if (!flag)
245 {
246 return false;
247 }
248 }
249 return true;
250 }
251
253 {
254 if (Cardinality.NeverSubset(baseType.Cardinality))
255 {
256 return true;
257 }
258 if (MaybeEmpty && baseType.MaybeEmpty)
259 {
260 return false;
261 }
262 if (Count == 0)
263 {
264 return false;
265 }
267 {
268 while (listEnumerator.MoveNext())
269 {
270 XmlQueryType current = listEnumerator.Current;
271 foreach (XmlQueryType item in baseType)
272 {
273 if (current.HasIntersectionItemType(item))
274 {
275 return false;
276 }
277 }
278 }
279 }
280 return true;
281 }
282
283 public bool Equals([NotNullWhen(true)] XmlQueryType that)
284 {
285 if (that == null)
286 {
287 return false;
288 }
289 if (Cardinality != that.Cardinality || IsDod != that.IsDod)
290 {
291 return false;
292 }
295 if ((object)prime == prime2)
296 {
297 return true;
298 }
299 if (prime.Count != prime2.Count)
300 {
301 return false;
302 }
303 if (prime.Count == 1)
304 {
305 if (prime.TypeCode == prime2.TypeCode && prime.NameTest == prime2.NameTest && prime.SchemaType == prime2.SchemaType && prime.IsStrict == prime2.IsStrict)
306 {
308 }
309 return false;
310 }
312 {
313 while (listEnumerator.MoveNext())
314 {
315 XmlQueryType current = listEnumerator.Current;
316 bool flag = false;
317 foreach (XmlQueryType item in that)
318 {
319 if (current.TypeCode == item.TypeCode && current.NameTest == item.NameTest && current.SchemaType == item.SchemaType && current.IsStrict == item.IsStrict && current.IsNotRtf == item.IsNotRtf)
320 {
321 flag = true;
322 break;
323 }
324 }
325 if (!flag)
326 {
327 return false;
328 }
329 }
330 }
331 return true;
332 }
333
334 public static bool operator ==(XmlQueryType left, XmlQueryType right)
335 {
336 return left?.Equals(right) ?? ((object)right == null);
337 }
338
339 public static bool operator !=(XmlQueryType left, XmlQueryType right)
340 {
341 if ((object)left == null)
342 {
343 return (object)right != null;
344 }
345 return !left.Equals(right);
346 }
347
348 public override bool Equals([NotNullWhen(true)] object obj)
349 {
351 if (xmlQueryType == null)
352 {
353 return false;
354 }
355 return Equals(xmlQueryType);
356 }
357
358 public override int GetHashCode()
359 {
360 if (_hashCode == 0)
361 {
362 int num = (int)TypeCode;
363 XmlSchemaType schemaType = SchemaType;
364 if (schemaType != null)
365 {
366 num += (num << 7) ^ schemaType.GetHashCode();
367 }
368 num += (int)((uint)(num << 7) ^ (uint)NodeKinds);
369 num += (num << 7) ^ Cardinality.GetHashCode();
370 num += (num << 7) ^ (IsStrict ? 1 : 0);
371 num -= num >> 17;
372 num -= num >> 11;
373 num -= num >> 5;
374 _hashCode = ((num == 0) ? 1 : num);
375 }
376 return _hashCode;
377 }
378
379 public override string ToString()
380 {
381 return ToString("G");
382 }
383
384 public string ToString(string format)
385 {
387 if (format == "S")
388 {
391 stringBuilder.Append(';');
392 for (int i = 0; i < Count; i++)
393 {
394 if (i != 0)
395 {
396 stringBuilder.Append('|');
397 }
398 stringBuilder.Append(this[i].TypeCode.ToString());
399 }
400 stringBuilder.Append(';');
401 stringBuilder.Append(IsStrict);
402 return stringBuilder.ToString();
403 }
404 bool flag = format == "X";
406 {
407 return "none";
408 }
410 {
411 return "empty";
412 }
414 switch (Count)
415 {
416 case 0:
417 stringBuilder.Append("none");
418 break;
419 case 1:
420 stringBuilder.Append(this[0].ItemTypeToString(flag));
421 break;
422 default:
423 {
424 string[] array = new string[Count];
425 for (int j = 0; j < Count; j++)
426 {
427 array[j] = this[j].ItemTypeToString(flag);
428 }
431 stringBuilder.Append('(');
432 stringBuilder.Append(array[0]);
433 for (int k = 1; k < array.Length; k++)
434 {
435 stringBuilder.Append(" | ");
436 stringBuilder.Append(array[k]);
437 }
438 stringBuilder.Append(')');
439 break;
440 }
441 }
443 if (!flag && IsDod)
444 {
445 stringBuilder.Append('#');
446 }
447 return stringBuilder.ToString();
448 }
449
450 public abstract void GetObjectData(BinaryWriter writer);
451
453 {
454 XmlSchemaType schemaType = baseType.SchemaType;
455 if (TypeCode != baseType.TypeCode)
456 {
457 if (baseType.IsStrict)
458 {
459 return false;
460 }
462 if (builtInSimpleType != null && schemaType != builtInSimpleType)
463 {
464 return false;
465 }
466 return s_typeCodeDerivation[TypeCode, baseType.TypeCode];
467 }
468 if (baseType.IsStrict)
469 {
470 if (IsStrict)
471 {
472 return SchemaType == schemaType;
473 }
474 return false;
475 }
476 if ((IsNotRtf || !baseType.IsNotRtf) && NameTest.IsSubsetOf(baseType.NameTest) && (schemaType == XmlSchemaComplexType.AnyType || XmlSchemaType.IsDerivedFrom(SchemaType, schemaType, XmlSchemaDerivationMethod.Empty)))
477 {
478 if (IsNillable)
479 {
480 return baseType.IsNillable;
481 }
482 return true;
483 }
484 return false;
485 }
486
488 {
489 if (TypeCode == other.TypeCode && (NodeKinds & (XmlNodeKindFlags.Document | XmlNodeKindFlags.Element | XmlNodeKindFlags.Attribute)) != 0)
490 {
491 if (TypeCode == XmlTypeCode.Node)
492 {
493 return true;
494 }
495 if (!NameTest.HasIntersection(other.NameTest))
496 {
497 return false;
498 }
500 {
501 return false;
502 }
503 return true;
504 }
505 if (IsSubtypeOf(other) || other.IsSubtypeOf(this))
506 {
507 return true;
508 }
509 return false;
510 }
511
512 private string ItemTypeToString(bool isXQ)
513 {
514 string text;
515 if (!IsNode)
516 {
517 text = ((SchemaType == XmlSchemaComplexType.AnyType) ? s_typeNames[(int)TypeCode] : ((!SchemaType.QualifiedName.IsEmpty) ? QNameToString(SchemaType.QualifiedName) : ("<:" + s_typeNames[(int)TypeCode])));
518 }
519 else
520 {
521 text = s_typeNames[(int)TypeCode];
522 XmlTypeCode typeCode = TypeCode;
523 if (typeCode != XmlTypeCode.Document)
524 {
525 if ((uint)(typeCode - 4) <= 1u)
526 {
527 goto IL_0048;
528 }
529 }
530 else
531 {
532 if (!isXQ)
533 {
534 goto IL_0048;
535 }
536 text = text + "{(element" + NameAndType(isXQ: true) + "?&text?&comment?&processing-instruction?)*}";
537 }
538 }
539 goto IL_00b0;
540 IL_00b0:
541 if (!isXQ && IsStrict)
542 {
543 text += "=";
544 }
545 return text;
546 IL_0048:
548 goto IL_00b0;
549 }
550
551 private string NameAndType(bool isXQ)
552 {
553 string text = NameTest.ToString();
554 string text2 = "*";
555 if (SchemaType.QualifiedName.IsEmpty)
556 {
557 text2 = "typeof(" + text + ")";
558 }
560 {
561 text2 = QNameToString(SchemaType.QualifiedName);
562 }
563 if (IsNillable)
564 {
565 text2 += " nillable";
566 }
567 if (text == "*" && text2 == "*")
568 {
569 return "";
570 }
571 return "(" + text + ", " + text2 + ")";
572 }
573
574 private static string QNameToString(XmlQualifiedName name)
575 {
576 if (name.IsEmpty)
577 {
578 return "*";
579 }
580 if (name.Namespace.Length == 0)
581 {
582 return name.Name;
583 }
584 if (name.Namespace == "http://www.w3.org/2001/XMLSchema")
585 {
586 return "xs:" + name.Name;
587 }
588 if (name.Namespace == "http://www.w3.org/2003/11/xpath-datatypes")
589 {
590 return "xdt:" + name.Name;
591 }
592 return "{" + name.Namespace + "}" + name.Name;
593 }
594
596 {
598 for (int i = 0; i < s_baseTypeCodes.Length; i++)
599 {
600 int num = i;
601 while (true)
602 {
603 bitMatrix[i, num] = true;
604 if (s_baseTypeCodes[num] == (XmlTypeCode)num)
605 {
606 break;
607 }
608 num = (int)s_baseTypeCodes[num];
609 }
610 }
611 return bitMatrix;
612 }
613}
static void Sort(Array array)
Definition Array.cs:2329
static ? XmlSchemaSimpleType GetBuiltInSimpleType(XmlQualifiedName qualifiedName)
static bool IsDerivedFrom([NotNullWhen(true)] XmlSchemaType? derivedType, [NotNullWhen(true)] XmlSchemaType? baseType, XmlSchemaDerivationMethod except)
virtual IListEnumerator< T > GetEnumerator()
Definition ListBase.cs:61
bool HasIntersection(XmlQualifiedNameTest other)
bool IsSubsetOf(XmlQualifiedNameTest other)
override string ToString()
void GetObjectData(BinaryWriter writer)
override bool Equals([NotNullWhen(true)] object obj)
static bool operator==(XmlQueryType left, XmlQueryType right)
string ToString(string format)
static readonly string[] s_typeNames
XmlQueryCardinality Cardinality
bool IsSubtypeOf(XmlQueryType baseType)
static readonly XmlTypeCode[] s_baseTypeCodes
bool NeverSubtypeOf(XmlQueryType baseType)
string NameAndType(bool isXQ)
bool Equals([NotNullWhen(true)] XmlQueryType that)
bool IsSubtypeOfItemType(XmlQueryType baseType)
static readonly BitMatrix s_typeCodeDerivation
bool HasIntersectionItemType(XmlQueryType other)
static BitMatrix CreateTypeCodeDerivation()
XmlQualifiedNameTest NameTest
string ItemTypeToString(bool isXQ)
static string QNameToString(XmlQualifiedName name)
static readonly TypeFlags[] s_typeCodeToFlags
static bool operator!=(XmlQueryType left, XmlQueryType right)
TypeCode
Definition TypeCode.cs:4
bool NeverSubset(XmlQueryCardinality other)