Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
GenerateHelper.cs
Go to the documentation of this file.
8
10
11internal sealed class GenerateHelper
12{
14
16
18
19 private readonly XmlILModule _module;
20
21 private readonly bool _isDebug;
22
23 private bool _initWriters;
24
26
28
30
31 private string _lastUriString;
32
33 private string _lastFileName;
34
36
43
45 {
48 _lastSourceInfo = null;
49 if (_isDebug)
50 {
52 if (sourceInfo != null)
53 {
55 Emit(OpCodes.Nop);
56 }
57 }
58 else if (_module.EmitSymbols && sourceInfo != null)
59 {
61 _lastSourceInfo = null;
62 }
63 _initWriters = false;
64 if (initWriters)
65 {
69 Emit(OpCodes.Stloc, _locXOut);
70 }
71 }
72
73 public void MethodEnd()
74 {
75 Emit(OpCodes.Ret);
76 if (_isDebug)
77 {
79 }
80 }
81
82 public void CallSyncToNavigator()
83 {
84 if (_methSyncToNav == null)
85 {
86 _methSyncToNav = _module.FindMethod("SyncToNavigator");
87 }
89 }
90
91 public void LoadInteger(int intVal)
92 {
93 Emit(OpCodes.Ldc_I4, intVal);
94 }
95
96 public void LoadBoolean(bool boolVal)
97 {
98 Emit(boolVal ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);
99 }
100
101 public void LoadType(Type clrTyp)
102 {
103 Emit(OpCodes.Ldtoken, clrTyp);
105 }
106
107 public LocalBuilder DeclareLocal(string name, Type type)
108 {
109 return _ilgen.DeclareLocal(type);
110 }
111
112 public void LoadQueryRuntime()
113 {
114 Emit(OpCodes.Ldarg_0);
115 }
116
117 public void LoadQueryContext()
118 {
119 Emit(OpCodes.Ldarg_0);
121 }
122
123 public void LoadXsltLibrary()
124 {
125 Emit(OpCodes.Ldarg_0);
127 }
128
129 public void LoadQueryOutput()
130 {
131 Emit(OpCodes.Ldloc, _locXOut);
132 }
133
134 public void LoadParameter(int paramPos)
135 {
136 if (paramPos <= 65535)
137 {
138 Emit(OpCodes.Ldarg, paramPos);
139 return;
140 }
142 }
143
144 public void SetParameter(object paramId)
145 {
146 int num = (int)paramId;
147 if (num <= 65535)
148 {
149 Emit(OpCodes.Starg, num);
150 return;
151 }
153 }
154
156 {
157 if (!lblBranch.Equals(lblMark))
158 {
160 }
162 }
163
165 {
166 if (i4 != 0)
167 {
168 goto IL_0073;
169 }
170 if (opcodeBranch.Value == OpCodes.Beq.Value)
171 {
173 }
174 else if (opcodeBranch.Value == OpCodes.Beq_S.Value)
175 {
177 }
178 else if (opcodeBranch.Value == OpCodes.Bne_Un.Value)
179 {
181 }
182 else
183 {
184 if (opcodeBranch.Value != OpCodes.Bne_Un_S.Value)
185 {
186 goto IL_0073;
187 }
189 }
190 goto IL_007a;
191 IL_007a:
192 Emit(opcodeBranch, lblBranch);
193 return;
194 IL_0073:
196 goto IL_007a;
197 }
198
208
210 {
211 Emit(OpCodes.Tailcall);
212 Call(meth);
213 Emit(OpCodes.Ret);
214 }
215
216 public void Call(MethodInfo meth)
217 {
218 OpCode opcode = ((meth.IsVirtual || meth.IsAbstract) ? OpCodes.Callvirt : OpCodes.Call);
219 _ilgen.Emit(opcode, meth);
220 if (_lastSourceInfo != null)
221 {
223 }
224 }
225
227 {
228 Emit(OpCodes.Newobj, constr);
229 }
230
232 {
233 switch (cStrings)
234 {
235 case 0:
236 Emit(OpCodes.Ldstr, "");
237 break;
238 case 2:
240 break;
241 case 3:
243 break;
244 case 4:
246 break;
247 case 1:
248 break;
249 }
250 }
251
253 {
254 if (!(clrTypeSrc == clrTypeDst))
255 {
256 if (clrTypeSrc.IsValueType)
257 {
258 Emit(OpCodes.Box, clrTypeSrc);
259 }
260 else if (clrTypeDst.IsValueType)
261 {
262 Emit(OpCodes.Unbox, clrTypeDst);
263 Emit(OpCodes.Ldobj, clrTypeDst);
264 }
265 else if (clrTypeDst != typeof(object))
266 {
268 }
269 }
270 }
271
272 public void ConstructLiteralDecimal(decimal dec)
273 {
274 if (dec >= -2147483648m && dec <= 2147483647m && decimal.Truncate(dec) == dec)
275 {
276 LoadInteger((int)dec);
278 return;
279 }
280 int[] bits = decimal.GetBits(dec);
281 LoadInteger(bits[0]);
282 LoadInteger(bits[1]);
283 LoadInteger(bits[2]);
284 LoadBoolean(bits[3] < 0);
285 LoadInteger(bits[3] >> 16);
287 }
288
289 public void ConstructLiteralQName(string localName, string namespaceName)
290 {
291 Emit(OpCodes.Ldstr, localName);
294 }
295
297 {
298 MethodInfo meth = null;
299 switch (code)
300 {
301 case XmlTypeCode.Float:
302 case XmlTypeCode.Double:
303 case XmlTypeCode.Integer:
304 case XmlTypeCode.Int:
305 switch (opType)
306 {
307 case QilNodeType.Add:
308 Emit(OpCodes.Add);
309 break;
310 case QilNodeType.Subtract:
311 Emit(OpCodes.Sub);
312 break;
313 case QilNodeType.Multiply:
314 Emit(OpCodes.Mul);
315 break;
316 case QilNodeType.Divide:
317 Emit(OpCodes.Div);
318 break;
319 case QilNodeType.Modulo:
320 Emit(OpCodes.Rem);
321 break;
322 case QilNodeType.Negate:
323 Emit(OpCodes.Neg);
324 break;
325 }
326 break;
327 case XmlTypeCode.Decimal:
328 switch (opType)
329 {
330 case QilNodeType.Add:
332 break;
333 case QilNodeType.Subtract:
335 break;
336 case QilNodeType.Multiply:
338 break;
339 case QilNodeType.Divide:
341 break;
342 case QilNodeType.Modulo:
344 break;
345 case QilNodeType.Negate:
347 break;
348 }
349 Call(meth);
350 break;
351 }
352 }
353
355 {
356 MethodInfo meth = null;
357 switch (code)
358 {
359 case XmlTypeCode.String:
361 break;
362 case XmlTypeCode.QName:
364 break;
365 case XmlTypeCode.Decimal:
367 break;
368 }
369 Call(meth);
370 }
371
373 {
374 MethodInfo meth = null;
375 switch (code)
376 {
377 case XmlTypeCode.String:
379 break;
380 case XmlTypeCode.Decimal:
382 break;
383 }
384 Call(meth);
385 }
386
387 public void CallStartRtfConstruction(string baseUri)
388 {
389 EnsureWriter();
391 Emit(OpCodes.Ldstr, baseUri);
392 Emit(OpCodes.Ldloca, _locXOut);
394 }
395
402
410
417
425
432
439
440 public void CallGetTypeFilter(XPathNodeType nodeType)
441 {
443 LoadInteger((int)nodeType);
445 }
446
448 {
449 if (nameType == GenerateNameType.TagNameAndMappings)
450 {
452 }
453 else
454 {
456 }
457 }
458
466
468 {
469 TreatAs(clrType, typeof(object));
471 }
472
479
480 [MemberNotNull("_locXOut")]
481 private void EnsureWriter()
482 {
483 if (!_initWriters)
484 {
485 _locXOut = DeclareLocal("$$$xwrtChk", typeof(XmlQueryOutput));
486 _initWriters = true;
487 }
488 }
489
490 public void CallGetParameter(string localName, string namespaceUri)
491 {
493 Emit(OpCodes.Ldstr, localName);
494 Emit(OpCodes.Ldstr, namespaceUri);
496 }
497
504
505 public void CallEndTree()
506 {
509 }
510
511 public void CallWriteStartRoot()
512 {
515 }
516
517 public void CallWriteEndRoot()
518 {
521 }
522
524 {
525 MethodInfo meth = null;
526 if (callChk)
527 {
528 switch (nameType)
529 {
530 case GenerateNameType.LiteralLocalName:
532 break;
533 case GenerateNameType.LiteralName:
535 break;
536 case GenerateNameType.CopiedName:
538 break;
539 case GenerateNameType.TagNameAndMappings:
541 break;
542 case GenerateNameType.TagNameAndNamespace:
544 break;
545 case GenerateNameType.QName:
547 break;
548 }
549 }
550 else
551 {
552 switch (nameType)
553 {
554 case GenerateNameType.LiteralLocalName:
556 break;
557 case GenerateNameType.LiteralName:
559 break;
560 }
561 }
562 Call(meth);
563 }
564
566 {
567 MethodInfo meth = null;
568 if (callChk)
569 {
571 }
572 else
573 {
574 switch (nameType)
575 {
576 case GenerateNameType.LiteralLocalName:
578 break;
579 case GenerateNameType.LiteralName:
581 break;
582 }
583 }
584 Call(meth);
585 }
586
592
594 {
595 MethodInfo meth = null;
596 if (callChk)
597 {
598 switch (nameType)
599 {
600 case GenerateNameType.LiteralLocalName:
602 break;
603 case GenerateNameType.LiteralName:
605 break;
606 case GenerateNameType.CopiedName:
608 break;
609 case GenerateNameType.TagNameAndMappings:
611 break;
612 case GenerateNameType.TagNameAndNamespace:
614 break;
615 case GenerateNameType.QName:
617 break;
618 }
619 }
620 else
621 {
622 switch (nameType)
623 {
624 case GenerateNameType.LiteralLocalName:
626 break;
627 case GenerateNameType.LiteralName:
629 break;
630 }
631 }
632 Call(meth);
633 }
634
636 {
638 if (callChk)
639 {
641 }
642 else
643 {
645 }
646 }
647
649 {
650 if (callChk)
651 {
653 }
654 else
655 {
657 }
658 }
659
661 {
662 if (callChk)
663 {
665 {
667 }
668 else
669 {
671 }
672 }
673 else if (disableOutputEscaping)
674 {
676 }
677 else
678 {
680 }
681 }
682
683 public void CallWriteStartPI()
684 {
686 }
687
688 public void CallWriteEndPI()
689 {
692 }
693
699
701 {
704 }
705
711
716
718 {
720 if (valueAs == null)
721 {
723 Emit(OpCodes.Ldnull);
725 TreatAs(typeof(object), clrType);
726 }
727 else
728 {
729 Call(valueAs);
730 }
731 }
732
734 {
735 MethodInfo meth = null;
736 if (keyType == null)
737 {
739 }
740 else
741 {
742 switch (keyType.TypeCode)
743 {
744 case XmlTypeCode.String:
746 break;
747 case XmlTypeCode.Decimal:
749 break;
750 case XmlTypeCode.Integer:
752 break;
753 case XmlTypeCode.Int:
755 break;
756 case XmlTypeCode.Boolean:
758 break;
759 case XmlTypeCode.Double:
761 break;
762 case XmlTypeCode.DateTime:
764 break;
765 case XmlTypeCode.None:
766 Emit(OpCodes.Pop);
768 break;
769 case XmlTypeCode.AnyAtomicType:
770 return;
771 }
772 }
773 Call(meth);
774 }
775
776 public void DebugStartScope()
777 {
779 }
780
781 public void DebugEndScope()
782 {
784 }
785
791
793 {
794 string uri = sourceInfo.Uri;
795 if ((object)uri == _lastUriString)
796 {
797 return _lastFileName;
798 }
799 _lastUriString = uri;
801 return _lastFileName;
802 }
803
805 {
806 if (!sourceInfo.IsNoSource || _lastSourceInfo == null || !_lastSourceInfo.IsNoSource)
807 {
810 }
811 }
812
814 {
815 return _ilgen.DefineLabel();
816 }
817
818 public void MarkLabel(Label lbl)
819 {
821 {
823 }
825 }
826
827 public void Emit(OpCode opcode)
828 {
829 _ilgen.Emit(opcode);
830 }
831
833 {
834 _ilgen.Emit(opcode, constrInfo);
835 }
836
837 public void Emit(OpCode opcode, double dblVal)
838 {
839 _ilgen.Emit(opcode, dblVal);
840 }
841
842 public void Emit(OpCode opcode, FieldInfo fldInfo)
843 {
844 _ilgen.Emit(opcode, fldInfo);
845 }
846
847 public void Emit(OpCode opcode, int intVal)
848 {
849 _ilgen.Emit(opcode, intVal);
850 }
851
852 public void Emit(OpCode opcode, long longVal)
853 {
854 _ilgen.Emit(opcode, longVal);
855 }
856
857 public void Emit(OpCode opcode, Label lblVal)
858 {
859 _ilgen.Emit(opcode, lblVal);
860 }
861
862 public void Emit(OpCode opcode, Label[] arrLabels)
863 {
864 _ilgen.Emit(opcode, arrLabels);
865 }
866
867 public void Emit(OpCode opcode, LocalBuilder locBldr)
868 {
869 _ilgen.Emit(opcode, locBldr);
870 }
871
872 public void Emit(OpCode opcode, string strVal)
873 {
874 _ilgen.Emit(opcode, strVal);
875 }
876
877 public void Emit(OpCode opcode, Type typVal)
878 {
879 _ilgen.Emit(opcode, typVal);
880 }
881
883 {
884 if (!opcode.Equals(OpCodes.Br) && !opcode.Equals(OpCodes.Br_S))
885 {
886 Emit(OpCodes.Ldc_I4_1);
887 }
888 _ilgen.Emit(opcode, lblTarget);
889 if (_lastSourceInfo != null && (opcode.Equals(OpCodes.Br) || opcode.Equals(OpCodes.Br_S)))
890 {
892 }
893 }
894}
virtual LocalBuilder DeclareLocal(Type localType)
virtual void MarkLabel(Label loc)
virtual void Emit(OpCode opcode)
static readonly OpCode Castclass
Definition OpCodes.cs:235
static readonly OpCode Ldloca
Definition OpCodes.cs:427
static readonly OpCode Unbox
Definition OpCodes.cs:241
static readonly OpCode Brfalse
Definition OpCodes.cs:117
static readonly OpCode Rem
Definition OpCodes.cs:189
static readonly OpCode Tailcall
Definition OpCodes.cs:439
static readonly OpCode Callvirt
Definition OpCodes.cs:225
static readonly OpCode Mul
Definition OpCodes.cs:183
static readonly OpCode Brtrue
Definition OpCodes.cs:119
static readonly OpCode Br_S
Definition OpCodes.cs:89
static readonly OpCode Stloc
Definition OpCodes.cs:429
static readonly OpCode Bne_Un_S
Definition OpCodes.cs:105
static readonly OpCode Newobj
Definition OpCodes.cs:233
static readonly OpCode Beq_S
Definition OpCodes.cs:95
static readonly OpCode Add
Definition OpCodes.cs:179
static readonly OpCode Ldobj
Definition OpCodes.cs:229
static readonly OpCode Ldc_I4
Definition OpCodes.cs:69
static readonly OpCode Beq
Definition OpCodes.cs:121
static readonly OpCode Br
Definition OpCodes.cs:115
static readonly OpCode Bne_Un
Definition OpCodes.cs:131
static readonly OpCode Ldc_I4_1
Definition OpCodes.cs:51
static readonly OpCode Sub
Definition OpCodes.cs:181
static readonly OpCode Ldc_I4_0
Definition OpCodes.cs:49
static readonly OpCode Brtrue_S
Definition OpCodes.cs:93
static readonly OpCode Ldstr
Definition OpCodes.cs:231
static readonly OpCode Pop
Definition OpCodes.cs:79
static readonly OpCode Ldtoken
Definition OpCodes.cs:353
static readonly OpCode Call
Definition OpCodes.cs:83
static readonly OpCode Nop
Definition OpCodes.cs:5
static readonly OpCode Ret
Definition OpCodes.cs:87
static readonly OpCode Ldloc
Definition OpCodes.cs:425
static readonly OpCode Ldnull
Definition OpCodes.cs:45
static readonly OpCode Brfalse_S
Definition OpCodes.cs:91
static readonly OpCode Starg
Definition OpCodes.cs:423
static readonly OpCode Box
Definition OpCodes.cs:279
static readonly OpCode Ldarg_0
Definition OpCodes.cs:9
static readonly OpCode Neg
Definition OpCodes.cs:205
static readonly OpCode Div
Definition OpCodes.cs:185
static readonly OpCode Ldarg
Definition OpCodes.cs:419
static string XmlIl_TooManyParameters
Definition SR.cs:2028
Definition SR.cs:7
void Emit(OpCode opcode, ConstructorInfo constrInfo)
void TestAndBranch(int i4, Label lblBranch, OpCode opcodeBranch)
string GetFileName(ISourceLineInfo sourceInfo)
void TreatAs(Type clrTypeSrc, Type clrTypeDst)
void AddSortKey(XmlQueryType keyType)
void CallWriteString(bool disableOutputEscaping, bool callChk)
void ConstructLiteralQName(string localName, string namespaceName)
void CallGetParameter(string localName, string namespaceUri)
void BranchAndMark(Label lblBranch, Label lblMark)
void DebugSequencePoint(ISourceLineInfo sourceInfo)
void Construct(ConstructorInfo constr)
void Emit(OpCode opcode, long longVal)
void Emit(OpCode opcode, LocalBuilder locBldr)
void CallArithmeticOp(QilNodeType opType, XmlTypeCode code)
void Emit(OpCode opcode, string strVal)
void Emit(OpCode opcode, Type typVal)
void CallWriteStartAttribute(GenerateNameType nameType, bool callChk)
void MarkSequencePoint(ISourceLineInfo sourceInfo)
LocalBuilder DeclareLocal(string name, Type type)
void CallStartRtfConstruction(string baseUri)
void CallCacheItem(Type itemStorageType)
void CallGetEarlyBoundObject(int idxObj, Type clrType)
GenerateHelper(XmlILModule module, bool isDebug)
void CallCompareEquals(XmlTypeCode code)
void EmitUnconditionalBranch(OpCode opcode, Label lblTarget)
void ConvBranchToBool(Label lblBranch, bool isTrueBranch)
void CallWriteStartElement(GenerateNameType nameType, bool callChk)
void CallParseTagName(GenerateNameType nameType)
void CallCacheCount(Type itemStorageType)
void MethodBegin(MethodBase methInfo, ISourceLineInfo sourceInfo, bool initWriters)
void CallStartTree(XPathNodeType rootType)
readonly StaticDataManager _staticData
void Emit(OpCode opcode, int intVal)
void Emit(OpCode opcode, Label[] arrLabels)
void CallWriteEndElement(GenerateNameType nameType, bool callChk)
void Emit(OpCode opcode, double dblVal)
void CallGetTypeFilter(XPathNodeType nodeType)
void CallGetGlobalValue(int idxValue, Type clrType)
void Emit(OpCode opcode, Label lblVal)
void Emit(OpCode opcode, FieldInfo fldInfo)
static readonly ConstructorInfo DecFromInt32
static readonly ConstructorInfo DecFromParts
static readonly ConstructorInfo QName
static readonly MethodInfo StartElemCopyName
static readonly Dictionary< Type, XmlILStorageMethods > StorageMethods
static readonly MethodInfo EndComment
static readonly MethodInfo DecDiv
static readonly MethodInfo StartPI
static readonly MethodInfo SortKeyInteger
static readonly MethodInfo SortKeyDouble
static readonly MethodInfo EndSeqConstr
static readonly MethodInfo TagAndNamespace
static readonly MethodInfo EndAttr
static readonly MethodInfo XsltLib
static readonly MethodInfo StartAttrMapName
static readonly MethodInfo GetTypeFilter
static readonly MethodInfo SortKeyString
static readonly MethodInfo NamespaceDecl
static readonly MethodInfo EndTree
static readonly MethodInfo GetCollation
static readonly MethodInfo Text
static readonly MethodInfo StrCat4
static readonly MethodInfo StartComment
static readonly MethodInfo StartAttrQName
static readonly MethodInfo StartElemMapName
static readonly MethodInfo GetAtomizedName
static readonly MethodInfo StartElemLitNameUn
static readonly MethodInfo StartRtfConstr
static readonly MethodInfo StrCat3
static readonly MethodInfo StartAttrLocNameUn
static readonly MethodInfo StartAttrCopyName
static readonly MethodInfo StartRoot
static readonly MethodInfo DecEq
static readonly MethodInfo EndElemStackName
static readonly MethodInfo StartAttrLitNameUn
static readonly MethodInfo EndPI
static readonly MethodInfo NoEntText
static readonly MethodInfo DecAdd
static readonly MethodInfo EndRoot
static readonly MethodInfo SortKeyInt
static readonly MethodInfo GetTypeFromHandle
static readonly MethodInfo StrCmp
static readonly MethodInfo DecMul
static readonly MethodInfo GetParam
static readonly MethodInfo StartElemNmspName
static readonly MethodInfo StartAttrNmspName
static readonly MethodInfo SetGlobalValue
static readonly MethodInfo GetEarly
static readonly MethodInfo Context
static readonly MethodInfo GetNameFilter
static readonly MethodInfo DecCmp
static readonly MethodInfo StartElemLitName
static readonly MethodInfo StartElemQName
static readonly MethodInfo GetGlobalValue
static readonly MethodInfo NoEntTextUn
static readonly MethodInfo GetOutput
static readonly MethodInfo SortKeyDateTime
static readonly MethodInfo TextUn
static readonly MethodInfo DecRem
static readonly MethodInfo StartAttrLitName
static readonly MethodInfo EndRtfConstr
static readonly MethodInfo StrCat2
static readonly MethodInfo StrEq
static readonly MethodInfo StartAttrLocName
static readonly MethodInfo TagAndMappings
static readonly MethodInfo SortKeyEmpty
static readonly MethodInfo StartElemLocName
static readonly MethodInfo DecNeg
static readonly MethodInfo ValueAsAny
static readonly MethodInfo StartSeqConstr
static readonly MethodInfo StartContentUn
static readonly MethodInfo QNameEq
static readonly MethodInfo StartElemLocNameUn
static readonly MethodInfo EndElemLocNameUn
static readonly MethodInfo EndElemLitNameUn
static readonly MethodInfo StartTree
static readonly MethodInfo SortKeyDecimal
static readonly MethodInfo EndAttrUn
static readonly MethodInfo DecSub
static readonly MethodInfo NamespaceDeclUn
static ILGenerator DefineMethodBody(MethodBase methInfo)
MethodInfo FindMethod(string name)
static string GetFileName(string uriString)
static SourceLineInfo NoSource
override bool Equals([NotNullWhen(true)] object? obj)
Definition OpCode.cs:78