Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlQueryTypeFactory.cs
Go to the documentation of this file.
2using System.IO;
5
6namespace System.Xml.Xsl;
7
8internal static class XmlQueryTypeFactory
9{
10 private sealed class ItemType : XmlQueryType
11 {
12 public static readonly XmlQueryType UntypedDocument;
13
14 public static readonly XmlQueryType UntypedElement;
15
16 public static readonly XmlQueryType UntypedAttribute;
17
18 public static readonly XmlQueryType NodeNotRtf;
19
20 private static readonly XmlQueryType[] s_builtInItemTypes;
21
22 private static readonly XmlQueryType[] s_builtInItemTypesStrict;
23
24 private static readonly XmlQueryType[] s_specialBuiltInItemTypes;
25
26 private readonly XmlTypeCode _code;
27
29
30 private readonly XmlSchemaType _schemaType;
31
32 private readonly bool _isNillable;
33
34 private readonly XmlNodeKindFlags _nodeKinds;
35
36 private readonly bool _isStrict;
37
38 private readonly bool _isNotRtf;
39
40 public override XmlTypeCode TypeCode => _code;
41
43
45
46 public override bool IsNillable => _isNillable;
47
49
50 public override bool IsStrict => _isStrict;
51
52 public override bool IsNotRtf => _isNotRtf;
53
54 public override bool IsDod => false;
55
57
58 public override XmlQueryType Prime => this;
59
60 public override int Count => 1;
61
62 public override XmlQueryType this[int index]
63 {
64 get
65 {
66 if (index != 0)
67 {
68 throw new IndexOutOfRangeException();
69 }
70 return this;
71 }
72 set
73 {
74 throw new NotSupportedException();
75 }
76 }
77
78 static ItemType()
79 {
80 int num = 55;
83 for (int i = 0; i < num; i++)
84 {
86 switch ((XmlTypeCode)i)
87 {
88 case XmlTypeCode.None:
91 break;
92 case XmlTypeCode.Item:
93 case XmlTypeCode.Node:
96 break;
97 case XmlTypeCode.Document:
98 case XmlTypeCode.Element:
99 case XmlTypeCode.Namespace:
100 case XmlTypeCode.ProcessingInstruction:
101 case XmlTypeCode.Comment:
102 case XmlTypeCode.Text:
105 break;
106 case XmlTypeCode.Attribute:
109 break;
110 case XmlTypeCode.AnyAtomicType:
113 break;
114 case XmlTypeCode.UntypedAtomic:
117 break;
118 default:
119 {
123 break;
124 }
125 }
126 }
132 }
133
135 {
136 if (isStrict)
137 {
138 return s_builtInItemTypesStrict[(int)code];
139 }
140 return s_builtInItemTypes[(int)code];
141 }
142
143 public static XmlQueryType Create(XmlSchemaSimpleType schemaType, bool isStrict)
144 {
145 XmlTypeCode typeCode = schemaType.Datatype.TypeCode;
146 if (schemaType == XmlSchemaType.GetBuiltInSimpleType(typeCode))
147 {
148 return Create(typeCode, isStrict);
149 }
150 return new ItemType(typeCode, XmlQualifiedNameTest.Wildcard, schemaType, isNillable: false, isStrict, isNotRtf: true);
151 }
152
154 {
155 switch (code)
156 {
157 case XmlTypeCode.Document:
158 case XmlTypeCode.Element:
159 if (nameTest.IsWildcard)
160 {
162 {
163 return Create(code, isStrict: false);
164 }
166 {
167 switch (code)
168 {
169 case XmlTypeCode.Element:
170 return UntypedElement;
171 case XmlTypeCode.Document:
172 return UntypedDocument;
173 }
174 }
175 }
176 return new ItemType(code, nameTest, contentType, isNillable, isStrict: false, isNotRtf: true);
177 case XmlTypeCode.Attribute:
178 if (nameTest.IsWildcard)
179 {
181 {
182 return Create(code, isStrict: false);
183 }
185 {
186 return UntypedAttribute;
187 }
188 }
189 return new ItemType(code, nameTest, contentType, isNillable, isStrict: false, isNotRtf: true);
190 default:
191 return Create(code, isStrict: false);
192 }
193 }
194
217
218 public override void GetObjectData(BinaryWriter writer)
219 {
220 sbyte b = (sbyte)_code;
221 for (int i = 0; i < s_specialBuiltInItemTypes.Length; i++)
222 {
223 if ((object)this == s_specialBuiltInItemTypes[i])
224 {
225 b = (sbyte)(~i);
226 break;
227 }
228 }
229 writer.Write(b);
230 if (0 <= b)
231 {
232 writer.Write(_isStrict);
233 }
234 }
235
236 public static XmlQueryType Create(BinaryReader reader)
237 {
238 sbyte b = reader.ReadSByte();
239 if (0 <= b)
240 {
241 return Create((XmlTypeCode)b, reader.ReadBoolean());
242 }
244 }
245 }
246
247 private sealed class ChoiceType : XmlQueryType
248 {
249 public static readonly XmlQueryType None = new ChoiceType(new List<XmlQueryType>());
250
251 private readonly XmlTypeCode _code;
252
253 private readonly XmlSchemaType _schemaType;
254
255 private readonly XmlNodeKindFlags _nodeKinds;
256
257 private readonly List<XmlQueryType> _members;
258
259 private static readonly XmlTypeCode[] s_nodeKindToTypeCode = new XmlTypeCode[8]
260 {
261 XmlTypeCode.None,
262 XmlTypeCode.Document,
263 XmlTypeCode.Element,
264 XmlTypeCode.Attribute,
265 XmlTypeCode.Text,
266 XmlTypeCode.Comment,
267 XmlTypeCode.ProcessingInstruction,
269 };
270
271 public override XmlTypeCode TypeCode => _code;
272
274
276
277 public override bool IsNillable => false;
278
280
281 public override bool IsStrict => _members.Count == 0;
282
283 public override bool IsNotRtf
284 {
285 get
286 {
287 for (int i = 0; i < _members.Count; i++)
288 {
289 if (!_members[i].IsNotRtf)
290 {
291 return false;
292 }
293 }
294 return true;
295 }
296 }
297
298 public override bool IsDod => false;
299
301 {
302 get
303 {
304 if (TypeCode != 0)
305 {
307 }
309 }
310 }
311
312 public override XmlQueryType Prime => this;
313
314 public override int Count => _members.Count;
315
316 public override XmlQueryType this[int index]
317 {
318 get
319 {
320 return _members[index];
321 }
322 set
323 {
324 throw new NotSupportedException();
325 }
326 }
327
329 {
330 if (Bits.ExactlyOne((uint)nodeKinds))
331 {
333 }
335 while (nodeKinds != 0)
336 {
339 }
340 return Create(list);
341 }
342
344 {
345 if (members.Count == 0)
346 {
347 return None;
348 }
349 if (members.Count == 1)
350 {
351 return members[0];
352 }
353 return new ChoiceType(members);
354 }
355
357 {
359 for (int i = 0; i < members.Count; i++)
360 {
362 if (_code == XmlTypeCode.None)
363 {
364 _code = xmlQueryType.TypeCode;
365 _schemaType = xmlQueryType.SchemaType;
366 }
367 else if (base.IsNode && xmlQueryType.IsNode)
368 {
369 if (_code == xmlQueryType.TypeCode)
370 {
371 if (_code == XmlTypeCode.Element)
372 {
374 }
375 else if (_code == XmlTypeCode.Attribute)
376 {
378 }
379 }
380 else
381 {
382 _code = XmlTypeCode.Node;
383 _schemaType = null;
384 }
385 }
386 else if (base.IsAtomicValue && xmlQueryType.IsAtomicValue)
387 {
388 _code = XmlTypeCode.AnyAtomicType;
390 }
391 else
392 {
393 _code = XmlTypeCode.Item;
394 _schemaType = null;
395 }
396 _nodeKinds |= xmlQueryType.NodeKinds;
397 }
398 }
399
400 public override void GetObjectData(BinaryWriter writer)
401 {
402 writer.Write(_members.Count);
403 for (int i = 0; i < _members.Count; i++)
404 {
406 }
407 }
408
409 public static XmlQueryType Create(BinaryReader reader)
410 {
411 int num = reader.ReadInt32();
413 for (int i = 0; i < num; i++)
414 {
415 list.Add(Deserialize(reader));
416 }
417 return Create(list);
418 }
419 }
420
421 private sealed class SequenceType : XmlQueryType
422 {
424
425 private readonly XmlQueryType _prime;
426
427 private readonly XmlQueryCardinality _card;
428
430
432
434
435 public override bool IsNillable => _prime.IsNillable;
436
438
439 public override bool IsStrict => _prime.IsStrict;
440
441 public override bool IsNotRtf => _prime.IsNotRtf;
442
443 public override bool IsDod => (object)this == NodeSDod;
444
446
447 public override XmlQueryType Prime => _prime;
448
449 public override int Count => _prime.Count;
450
451 public override XmlQueryType this[int index]
452 {
453 get
454 {
455 return _prime[index];
456 }
457 set
458 {
459 throw new NotSupportedException();
460 }
461 }
462
464 {
465 if (prime.TypeCode == XmlTypeCode.None)
466 {
467 if (!(XmlQueryCardinality.Zero <= card))
468 {
469 return None;
470 }
471 return Zero;
472 }
474 {
475 return None;
476 }
478 {
479 return Zero;
480 }
482 {
483 return prime;
484 }
485 return new SequenceType(prime, card);
486 }
487
493
494 public override void GetObjectData(BinaryWriter writer)
495 {
496 writer.Write(IsDod);
497 if (!IsDod)
498 {
501 }
502 }
503
504 public static XmlQueryType Create(BinaryReader reader)
505 {
506 if (reader.ReadBoolean())
507 {
508 return NodeSDod;
509 }
512 return Create(prime, card);
513 }
514 }
515
516 public static readonly XmlQueryType None = ChoiceType.None;
517
518 public static readonly XmlQueryType Empty = SequenceType.Zero;
519
520 public static readonly XmlQueryType Item = Type(XmlTypeCode.Item, isStrict: false);
521
523
524 public static readonly XmlQueryType Node = Type(XmlTypeCode.Node, isStrict: false);
525
527
528 public static readonly XmlQueryType Element = Type(XmlTypeCode.Element, isStrict: false);
529
531
532 public static readonly XmlQueryType Document = Type(XmlTypeCode.Document, isStrict: false);
533
535
536 public static readonly XmlQueryType Attribute = Type(XmlTypeCode.Attribute, isStrict: false);
537
539
541
542 public static readonly XmlQueryType Namespace = Type(XmlTypeCode.Namespace, isStrict: false);
543
545
546 public static readonly XmlQueryType Text = Type(XmlTypeCode.Text, isStrict: false);
547
549
550 public static readonly XmlQueryType Comment = Type(XmlTypeCode.Comment, isStrict: false);
551
553
554 public static readonly XmlQueryType PI = Type(XmlTypeCode.ProcessingInstruction, isStrict: false);
555
557
559
561
563
564 public static readonly XmlQueryType Content = Choice(Element, Comment, PI, Text);
565
567
568 public static readonly XmlQueryType DocumentOrContent = Choice(Document, Content);
569
571
572 public static readonly XmlQueryType AttributeOrContent = Choice(Attribute, Content);
573
575
576 public static readonly XmlQueryType AnyAtomicType = Type(XmlTypeCode.AnyAtomicType, isStrict: false);
577
579
580 public static readonly XmlQueryType String = Type(XmlTypeCode.String, isStrict: false);
581
582 public static readonly XmlQueryType StringX = Type(XmlTypeCode.String, isStrict: true);
583
585
586 public static readonly XmlQueryType Boolean = Type(XmlTypeCode.Boolean, isStrict: false);
587
588 public static readonly XmlQueryType BooleanX = Type(XmlTypeCode.Boolean, isStrict: true);
589
590 public static readonly XmlQueryType Int = Type(XmlTypeCode.Int, isStrict: false);
591
592 public static readonly XmlQueryType IntX = Type(XmlTypeCode.Int, isStrict: true);
593
595
596 public static readonly XmlQueryType IntegerX = Type(XmlTypeCode.Integer, isStrict: true);
597
598 public static readonly XmlQueryType LongX = Type(XmlTypeCode.Long, isStrict: true);
599
600 public static readonly XmlQueryType DecimalX = Type(XmlTypeCode.Decimal, isStrict: true);
601
602 public static readonly XmlQueryType FloatX = Type(XmlTypeCode.Float, isStrict: true);
603
604 public static readonly XmlQueryType Double = Type(XmlTypeCode.Double, isStrict: false);
605
606 public static readonly XmlQueryType DoubleX = Type(XmlTypeCode.Double, isStrict: true);
607
608 public static readonly XmlQueryType DateTimeX = Type(XmlTypeCode.DateTime, isStrict: true);
609
610 public static readonly XmlQueryType QNameX = Type(XmlTypeCode.QName, isStrict: true);
611
613
615
617
619
621
622 public static readonly XmlQueryType NodeNotRtf = ItemType.NodeNotRtf;
623
625
627
629
630 private static readonly XmlTypeCode[] s_nodeKindToTypeCode = new XmlTypeCode[10]
631 {
632 XmlTypeCode.Document,
633 XmlTypeCode.Element,
634 XmlTypeCode.Attribute,
635 XmlTypeCode.Namespace,
636 XmlTypeCode.Text,
637 XmlTypeCode.Text,
638 XmlTypeCode.Text,
639 XmlTypeCode.ProcessingInstruction,
640 XmlTypeCode.Comment,
642 };
643
645 {
646 return ItemType.Create(code, isStrict);
647 }
648
649 public static XmlQueryType Type(XmlSchemaSimpleType schemaType, bool isStrict)
650 {
651 if (schemaType.Datatype.Variety == XmlSchemaDatatypeVariety.Atomic)
652 {
653 if (schemaType == DatatypeImplementation.AnySimpleType)
654 {
655 return AnyAtomicTypeS;
656 }
657 return ItemType.Create(schemaType, isStrict);
658 }
659 while (schemaType.DerivedBy == XmlSchemaDerivationMethod.Restriction)
660 {
661 schemaType = (XmlSchemaSimpleType)schemaType.BaseXmlSchemaType;
662 }
663 if (schemaType.DerivedBy == XmlSchemaDerivationMethod.List)
664 {
666 }
669 for (int i = 0; i < baseMemberTypes.Length; i++)
670 {
672 }
673 return Choice(array);
674 }
675
676 public static XmlQueryType Choice(XmlQueryType left, XmlQueryType right)
677 {
679 }
680
682 {
683 if (types.Length == 0)
684 {
685 return None;
686 }
687 if (types.Length == 1)
688 {
689 return types[0];
690 }
692 XmlQueryCardinality cardinality = types[0].Cardinality;
693 for (int i = 1; i < types.Length; i++)
694 {
696 cardinality |= types[i].Cardinality;
697 }
699 }
700
702 {
703 return ChoiceType.Create(kinds);
704 }
705
707 {
709 }
710
712 {
713 if (t.Cardinality == c && !t.IsDod)
714 {
715 return t;
716 }
717 return SequenceType.Create(t.Prime, c);
718 }
719
721 {
722 return PrimeProduct(t, c.AtMost());
723 }
724
733
735 {
736 bool flag = true;
737 for (int i = 0; i < accumulator.Count; i++)
738 {
739 if (itemType.IsSubtypeOf(accumulator[i]))
740 {
741 return;
742 }
743 if (accumulator[i].IsSubtypeOf(itemType))
744 {
745 if (flag)
746 {
747 flag = false;
749 }
750 else
751 {
752 accumulator.RemoveAt(i);
753 i--;
754 }
755 }
756 }
757 if (flag)
758 {
760 }
761 }
762
767
769 {
770 sbyte value = (sbyte)((!(type.GetType() == typeof(ItemType))) ? ((type.GetType() == typeof(ChoiceType)) ? 1 : ((!(type.GetType() == typeof(SequenceType))) ? (-1) : 2)) : 0);
771 writer.Write(value);
772 type.GetObjectData(writer);
773 }
774
776 {
777 return reader.ReadByte() switch
778 {
779 0 => ItemType.Create(reader),
780 1 => ChoiceType.Create(reader),
781 2 => SequenceType.Create(reader),
782 _ => null,
783 };
784 }
785}
SequenceType
void Add(TKey key, TValue value)
virtual bool ReadBoolean()
virtual byte ReadByte()
virtual sbyte ReadSByte()
virtual int ReadInt32()
static bool ExactlyOne(uint num)
Definition Bits.cs:15
static int LeastPosition(uint num)
Definition Bits.cs:29
static uint ClearLeast(uint num)
Definition Bits.cs:24
static XmlSchemaComplexType UntypedAnyType
virtual XmlSchemaDatatypeVariety Variety
static ? XmlSchemaSimpleType GetBuiltInSimpleType(XmlQualifiedName qualifiedName)
XmlSchemaDerivationMethod DerivedBy
static XmlQualifiedNameTest Wildcard
override void GetObjectData(BinaryWriter writer)
static XmlQueryType Create(XmlNodeKindFlags nodeKinds)
static XmlQueryType Create(List< XmlQueryType > members)
static XmlQueryType Create(BinaryReader reader)
static XmlQueryType Create(XmlSchemaSimpleType schemaType, bool isStrict)
static readonly XmlQueryType[] s_specialBuiltInItemTypes
static XmlQueryType Create(XmlTypeCode code, bool isStrict)
static readonly XmlQueryType[] s_builtInItemTypes
ItemType(XmlTypeCode code, XmlQualifiedNameTest nameTest, XmlSchemaType schemaType, bool isNillable, bool isStrict, bool isNotRtf)
static XmlQueryType Create(BinaryReader reader)
static readonly XmlQueryType[] s_builtInItemTypesStrict
override void GetObjectData(BinaryWriter writer)
static XmlQueryType Create(XmlTypeCode code, XmlQualifiedNameTest nameTest, XmlSchemaType contentType, bool isNillable)
SequenceType(XmlQueryType prime, XmlQueryCardinality card)
static XmlQueryType Create(XmlQueryType prime, XmlQueryCardinality card)
static XmlQueryType Create(BinaryReader reader)
override void GetObjectData(BinaryWriter writer)
static readonly XmlQueryType NodeSDod
static XmlQueryType Type(XmlSchemaSimpleType schemaType, bool isStrict)
static XmlQueryType Choice(XmlQueryType left, XmlQueryType right)
static readonly XmlQueryType Namespace
static readonly XmlQueryType Int
static readonly XmlQueryType AttributeOrContentS
static readonly XmlQueryType AttributeQ
static readonly XmlQueryType NamespaceS
static readonly XmlQueryType TextS
static XmlQueryType Type(XmlTypeCode code, bool isStrict)
static XmlQueryType Choice(params XmlQueryType[] types)
static void AddItemToChoice(List< XmlQueryType > accumulator, XmlQueryType itemType)
static readonly XmlQueryType CommentS
static readonly XmlQueryType DecimalX
static readonly XmlQueryType IntXS
static readonly XmlQueryType DoubleX
static readonly XmlQueryType QNameX
static readonly XmlQueryType StringX
static readonly XmlQueryType IntX
static readonly XmlQueryType LongX
static XmlQueryType Sequence(XmlQueryType left, XmlQueryType right)
static readonly XmlQueryType Node
static readonly XmlQueryType NodeNotRtfQ
static XmlQueryType AtMost(XmlQueryType t, XmlQueryCardinality c)
static readonly XmlQueryType ContentS
static readonly XmlQueryType DocumentOrContent
static XmlQueryType Type(XPathNodeType kind, XmlQualifiedNameTest nameTest, XmlSchemaType contentType, bool isNillable)
static readonly XmlQueryType Element
static readonly XmlQueryType DocumentS
static readonly XmlQueryType UntypedElement
static readonly XmlQueryType UntypedNode
static List< XmlQueryType > PrimeChoice(List< XmlQueryType > accumulator, IList< XmlQueryType > types)
static readonly XmlQueryType NodeS
static readonly XmlQueryType Comment
static readonly XmlQueryType None
static readonly XmlQueryType NodeNotRtfS
static readonly XmlQueryType FloatX
static readonly XmlQueryType DocumentOrContentS
static XmlQueryType PrimeProduct(XmlQueryType t, XmlQueryCardinality c)
static readonly XmlQueryType AnyAtomicTypeS
static readonly XmlQueryType PIS
static readonly XmlQueryType PI
static readonly XmlQueryType IntegerX
static readonly XmlQueryType ItemS
static readonly XmlQueryType DocumentOrElementS
static readonly XmlQueryType UntypedDocument
static readonly XmlQueryType AnyAtomicType
static readonly XmlQueryType DocumentOrElement
static readonly XmlQueryType AttributeOrContent
static readonly XmlQueryType BooleanX
static readonly XmlQueryType UntypedNodeS
static readonly XmlQueryType ElementS
static XmlQueryType NodeChoice(XmlNodeKindFlags kinds)
static readonly XmlQueryType AttributeS
static readonly XmlQueryType DateTimeX
static readonly XmlQueryType UntypedAttribute
static readonly XmlQueryType Document
static readonly XmlQueryType StringXS
static readonly XmlQueryType DocumentOrElementQ
static readonly XmlQueryType Item
static readonly XmlQueryType NodeNotRtf
static void Serialize(BinaryWriter writer, XmlQueryType type)
static readonly XmlTypeCode[] s_nodeKindToTypeCode
static XmlQueryType Deserialize(BinaryReader reader)
XmlQueryCardinality Cardinality
XmlQualifiedNameTest NameTest
TypeCode
Definition TypeCode.cs:4
void GetObjectData(BinaryWriter writer)
static XmlQueryCardinality ZeroOrOne
static XmlQueryCardinality ZeroOrMore