Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Processor.cs
Go to the documentation of this file.
5using System.IO;
6using System.Text;
10
12
13internal sealed class Processor : IXsltProcessor
14{
15 internal enum ExecResult
16 {
19 Done
20 }
21
22 internal enum OutputResult
23 {
27 Error,
28 Ignore
29 }
30
31 internal sealed class DebuggerFrame
32 {
34 }
35
37
38 private readonly Stylesheet _stylesheet;
39
40 private readonly RootAction _rootAction;
41
42 private readonly Key[] _keyList;
43
44 private readonly List<TheQuery> _queryStore;
45
46 private readonly XPathNavigator _document;
47
48 private readonly HWStack _actionStack;
49
50 private readonly HWStack _debuggerStack;
51
53
54 private int _ignoreLevel;
55
56 private readonly StateMachine _xsm;
57
59
61
62 private readonly XmlNameTable _nameTable = new NameTable();
63
64 private readonly XmlResolver _resolver;
65
66 private readonly XsltArgumentList _args;
67
68 private readonly Hashtable _scriptExtensions;
69
71
73
74 private readonly IXsltDebugger _debugger;
75
76 private readonly Query[] _queryList;
77
79
81
83
85
87
89 {
90 set
91 {
93 }
94 }
95
97
99
101
102 internal Key[] KeyList => _keyList;
103
105
107
109 {
110 get
111 {
112 if (_numberList == null)
113 {
114 _numberList = new ArrayList();
115 }
116 return _numberList;
117 }
118 }
119
120 internal IXsltDebugger Debugger => _debugger;
121
123
125
126 internal bool CanContinue => _execResult == ExecResult.Continue;
127
129 {
131 if (_documentCache != null)
132 {
134 {
135 return xPathNavigator2.Clone();
136 }
137 }
138 else
139 {
141 }
142 object entity = _resolver.GetEntity(ruri, null, null);
143 if (entity is Stream)
144 {
148 }
149 else
150 {
151 if (!(entity is XPathNavigator))
152 {
154 }
156 }
158 return xPathNavigator;
159 }
160
161 internal void AddSort(Sort sortinfo)
162 {
164 }
165
166 internal void InitSortArray()
167 {
168 if (_sortArray == null)
169 {
170 _sortArray = new ArrayList();
171 }
172 else
173 {
175 }
176 }
177
179 {
180 object obj = _args.GetParam(qname.Name, qname.Namespace);
181 if (obj == null)
182 {
183 return null;
184 }
185 if (!(obj is XPathNodeIterator) && !(obj is XPathNavigator) && !(obj is bool) && !(obj is double) && !(obj is string))
186 {
187 obj = ((!(obj is short) && !(obj is ushort) && !(obj is int) && !(obj is uint) && !(obj is long) && !(obj is ulong) && !(obj is float) && !(obj is decimal)) ? obj.ToString() : ((object)XmlConvert.ToXPathDouble(obj)));
188 }
189 return obj;
190 }
191
192 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "In order for this code path to be hit, a previous call to XsltArgumentList.AddExtensionObject is required. That method is already annotated as unsafe and throwing a warning, so we can suppress here.")]
193 internal object GetExtensionObject(string nsUri)
194 {
195 return _args.GetExtensionObject(nsUri);
196 }
197
198 internal object GetScriptObject(string nsUri)
199 {
200 return _scriptExtensions[nsUri];
201 }
202
204 {
205 if (_sharedStringBuilder == null)
206 {
208 }
209 else
210 {
212 }
214 }
215
217 {
218 }
219
221 {
222 _stylesheet = stylesheet;
226 for (int i = 0; i < queryStore.Count; i++)
227 {
228 _queryList[i] = Query.Clone(queryStore[i].CompiledQuery.QueryTree);
229 }
230 _xsm = new StateMachine();
231 _document = doc;
232 _builder = null;
233 _actionStack = new HWStack(10);
236 _args = args ?? new XsltArgumentList();
238 if (_debugger != null)
239 {
240 _debuggerStack = new HWStack(10, 1000);
242 }
243 if (_rootAction.KeyList != null)
244 {
246 for (int j = 0; j < _keyList.Length; j++)
247 {
248 _keyList[j] = _rootAction.KeyList[j].Clone();
249 }
250 }
253 {
255 }
257 }
258
265
266 public void Execute(Stream stream)
267 {
268 IRecordOutput output = null;
269 switch (_output.Method)
270 {
271 case XsltOutput.OutputMethod.Text:
272 output = new TextOnlyOutput(this, stream);
273 break;
274 case XsltOutput.OutputMethod.Xml:
275 case XsltOutput.OutputMethod.Html:
276 case XsltOutput.OutputMethod.Other:
277 case XsltOutput.OutputMethod.Unknown:
278 output = new TextOutput(this, stream);
279 break;
280 }
282 Execute();
283 }
284
286 {
287 IRecordOutput output = null;
288 switch (_output.Method)
289 {
290 case XsltOutput.OutputMethod.Text:
291 output = new TextOnlyOutput(this, writer);
292 break;
293 case XsltOutput.OutputMethod.Xml:
294 case XsltOutput.OutputMethod.Html:
295 case XsltOutput.OutputMethod.Other:
296 case XsltOutput.OutputMethod.Unknown:
297 output = new TextOutput(this, writer);
298 break;
299 }
301 Execute();
302 }
303
305 {
307 Execute();
308 }
309
310 internal void Execute()
311 {
312 while (_execResult == ExecResult.Continue)
313 {
315 if (actionFrame == null)
316 {
319 break;
320 }
321 if (actionFrame.Execute(this))
322 {
324 }
325 }
326 if (_execResult == ExecResult.Interrupt)
327 {
328 _execResult = ExecResult.Continue;
329 }
330 }
331
333 {
336 if (actionFrame2 == null)
337 {
340 }
341 if (actionFrame != null)
342 {
343 actionFrame2.Inherit(actionFrame);
344 }
345 return actionFrame2;
346 }
347
353
354 internal void PushActionFrame(ActionFrame container)
355 {
356 PushActionFrame(container, container.NodeSet);
357 }
358
360 {
362 actionFrame.Init(container, nodeSet);
363 }
364
370
371 internal string GetQueryExpression(int key)
372 {
373 return _queryStore[key].CompiledQuery.Expression;
374 }
375
377 {
379 theQuery.CompiledQuery.CheckErrors();
381 query.SetXsltContext(new XsltCompileContext(theQuery._ScopeManager, this));
382 return query;
383 }
384
385 internal Query GetValueQuery(int key)
386 {
387 return GetValueQuery(key, null);
388 }
389
391 {
393 theQuery.CompiledQuery.CheckErrors();
395 if (context == null)
396 {
397 context = new XsltCompileContext(theQuery._ScopeManager, this);
398 }
399 else
400 {
401 context.Reinitialize(theQuery._ScopeManager, this);
402 }
403 query.SetXsltContext(context);
404 return query;
405 }
406
408 {
409 if (_valueOfContext == null)
410 {
412 }
413 return _valueOfContext;
414 }
415
417 {
418 if (_matchesContext == null)
419 {
421 }
422 return _matchesContext;
423 }
424
425 internal string ValueOf(ActionFrame context, int key)
426 {
428 object obj = valueQuery.Evaluate(context.NodeSet);
430 {
432 return (xPathNavigator != null) ? ValueOf(xPathNavigator) : string.Empty;
433 }
435 }
436
437 internal string ValueOf(XPathNavigator n)
438 {
439 if (_stylesheet.Whitespace && n.NodeType == XPathNodeType.Element)
440 {
444 return sharedStringBuilder.ToString();
445 }
446 return n.Value;
447 }
448
450 {
451 bool flag = Stylesheet.PreserveWhiteSpace(this, nav);
452 if (!nav.MoveToFirstChild())
453 {
454 return;
455 }
456 do
457 {
458 switch (nav.NodeType)
459 {
460 case XPathNodeType.Text:
461 case XPathNodeType.SignificantWhitespace:
462 builder.Append(nav.Value);
463 break;
464 case XPathNodeType.Whitespace:
465 if (flag)
466 {
467 builder.Append(nav.Value);
468 }
469 break;
470 case XPathNodeType.Element:
472 break;
473 }
474 }
475 while (nav.MoveToNext());
476 nav.MoveToParent();
477 }
478
480 {
482 object obj = compiledQuery.Evaluate(context);
484 {
485 return new XPathSelectionIterator(context.Current, compiledQuery);
486 }
488 }
489
490 internal object Evaluate(ActionFrame context, int key)
491 {
492 return GetValueQuery(key).Evaluate(context.NodeSet);
493 }
494
495 internal object RunQuery(ActionFrame context, int key)
496 {
498 object obj = compiledQuery.Evaluate(context.NodeSet);
500 {
502 }
503 return obj;
504 }
505
506 internal string EvaluateString(ActionFrame context, int key)
507 {
508 object obj = Evaluate(context, key);
509 string text = null;
510 if (obj != null)
511 {
513 }
514 if (text == null)
515 {
516 text = string.Empty;
517 }
518 return text;
519 }
520
521 internal bool EvaluateBoolean(ActionFrame context, int key)
522 {
523 object obj = Evaluate(context, key);
524 if (obj != null)
525 {
527 {
529 }
531 }
532 return false;
533 }
534
535 internal bool Matches(XPathNavigator context, int key)
536 {
538 try
539 {
540 return valueQuery.MatchNode(context) != null;
541 }
542 catch (XPathException)
543 {
545 }
546 }
547
548 internal void ResetOutput()
549 {
550 _builder.Reset();
551 }
552
553 internal bool BeginEvent(XPathNodeType nodeType, string prefix, string name, string nspace, bool empty)
554 {
555 return BeginEvent(nodeType, prefix, name, nspace, empty, null, search: true);
556 }
557
558 internal bool BeginEvent(XPathNodeType nodeType, string prefix, string name, string nspace, bool empty, object htmlProps, bool search)
559 {
560 int num = _xsm.BeginOutlook(nodeType);
561 if (_ignoreLevel > 0 || num == 16)
562 {
563 _ignoreLevel++;
564 return true;
565 }
566 switch (_builder.BeginEvent(num, nodeType, prefix, name, nspace, empty, htmlProps, search))
567 {
568 case OutputResult.Continue:
569 _xsm.Begin(nodeType);
570 return true;
571 case OutputResult.Interrupt:
572 _xsm.Begin(nodeType);
573 ExecutionResult = ExecResult.Interrupt;
574 return true;
575 case OutputResult.Overflow:
576 ExecutionResult = ExecResult.Interrupt;
577 return false;
578 case OutputResult.Error:
579 _ignoreLevel++;
580 return true;
581 case OutputResult.Ignore:
582 return true;
583 default:
584 return true;
585 }
586 }
587
588 internal bool TextEvent(string text)
589 {
590 return TextEvent(text, disableOutputEscaping: false);
591 }
592
593 internal bool TextEvent(string text, bool disableOutputEscaping)
594 {
595 if (_ignoreLevel > 0)
596 {
597 return true;
598 }
601 {
602 case OutputResult.Continue:
604 return true;
605 case OutputResult.Interrupt:
607 ExecutionResult = ExecResult.Interrupt;
608 return true;
609 case OutputResult.Overflow:
610 ExecutionResult = ExecResult.Interrupt;
611 return false;
612 case OutputResult.Error:
613 case OutputResult.Ignore:
614 return true;
615 default:
616 return true;
617 }
618 }
619
620 internal bool EndEvent(XPathNodeType nodeType)
621 {
622 if (_ignoreLevel > 0)
623 {
624 _ignoreLevel--;
625 return true;
626 }
627 int state = _xsm.EndOutlook(nodeType);
628 switch (_builder.EndEvent(state, nodeType))
629 {
630 case OutputResult.Continue:
631 _xsm.End(nodeType);
632 return true;
633 case OutputResult.Interrupt:
634 _xsm.End(nodeType);
635 ExecutionResult = ExecResult.Interrupt;
636 return true;
637 case OutputResult.Overflow:
638 ExecutionResult = ExecResult.Interrupt;
639 return false;
640 default:
641 return true;
642 }
643 }
644
646 {
647 switch (node.NodeType)
648 {
649 case XPathNodeType.Element:
650 case XPathNodeType.Attribute:
651 case XPathNodeType.ProcessingInstruction:
652 case XPathNodeType.Comment:
653 return BeginEvent(node.NodeType, node.Prefix, node.LocalName, node.NamespaceURI, emptyflag);
654 case XPathNodeType.Namespace:
655 return BeginEvent(XPathNodeType.Namespace, null, node.LocalName, node.Value, empty: false);
656 default:
657 return true;
658 }
659 }
660
662 {
663 switch (node.NodeType)
664 {
665 case XPathNodeType.Attribute:
666 case XPathNodeType.Text:
667 case XPathNodeType.SignificantWhitespace:
668 case XPathNodeType.Whitespace:
669 case XPathNodeType.ProcessingInstruction:
670 case XPathNodeType.Comment:
671 {
672 string value = node.Value;
673 return TextEvent(value);
674 }
675 default:
676 return true;
677 }
678 }
679
681 {
682 switch (node.NodeType)
683 {
684 case XPathNodeType.Element:
685 case XPathNodeType.Attribute:
686 case XPathNodeType.Namespace:
687 case XPathNodeType.ProcessingInstruction:
688 case XPathNodeType.Comment:
689 return EndEvent(node.NodeType);
690 default:
691 return true;
692 }
693 }
694
695 internal static bool IsRoot(XPathNavigator navigator)
696 {
697 if (navigator.NodeType == XPathNodeType.Root)
698 {
699 return true;
700 }
701 if (navigator.NodeType == XPathNodeType.Element)
702 {
704 xPathNavigator.MoveToRoot();
705 return xPathNavigator.IsSamePosition(navigator);
706 }
707 return false;
708 }
709
718
720 {
722 _builder = builder.Next;
724 builder.TheEnd();
725 return builder.Output;
726 }
727
729 {
730 if (Output.Method != method)
731 {
733 return true;
734 }
735 return false;
736 }
737
739 {
740 int varKey = variable.VarKey;
741 if (variable.IsGlobal)
742 {
744 object variable2 = actionFrame.GetVariable(varKey);
746 {
748 }
749 if (variable2 != null)
750 {
751 return variable2;
752 }
755 actionFrame2.Inherit(actionFrame);
756 actionFrame2.Init(variable, actionFrame.NodeSet);
757 do
758 {
759 if (((ActionFrame)_actionStack.Peek()).Execute(this))
760 {
762 }
763 }
764 while (length < _actionStack.Length);
765 return actionFrame.GetVariable(varKey);
766 }
767 return ((ActionFrame)_actionStack.Peek()).GetVariable(varKey);
768 }
769
770 internal void SetParameter(XmlQualifiedName name, object value)
771 {
773 actionFrame.SetParameter(name, value);
774 }
775
776 internal void ResetParams()
777 {
779 actionFrame.ResetParams();
780 }
781
782 internal object GetParameter(XmlQualifiedName name)
783 {
785 return actionFrame.GetParameter(name);
786 }
787
788 internal void PopDebuggerStack()
789 {
791 }
792
794 {
795 return ((DebuggerFrame)_debuggerStack[_debuggerStack.Length - 2]).currentMode;
796 }
797
799 {
800 ((DebuggerFrame)_debuggerStack[_debuggerStack.Length - 1]).currentMode = mode;
801 }
802}
object Evaluate(XPathNodeIterator nodeIterator)
static Query Clone(Query input)
Definition Query.cs:66
virtual int Add(object? value)
static bool ToBoolean([NotNullWhen(true)] object? value)
Definition Convert.cs:508
static CultureInfo InvariantCulture
static string XPath_NodeSetExpected
Definition SR.cs:1856
static string Xslt_CircularReference
Definition SR.cs:2122
static string Xslt_CantResolve
Definition SR.cs:2078
static string CompilingScriptsNotSupported
Definition SR.cs:2148
static string Xslt_InvalidPattern
Definition SR.cs:2134
Definition SR.cs:7
void AddToTop(object o)
Definition HWStack.cs:90
object Push()
Definition HWStack.cs:52
object Peek()
Definition HWStack.cs:81
static double ToXPathDouble(object o)
static string ToXPathString(object value)
static readonly XmlNullResolver Singleton
object? GetEntity(Uri absoluteUri, string? role, Type? ofObjectToReturn)
object? GetParam(string name, string namespaceUri)
object? GetExtensionObject(string namespaceUri)
static XsltException Create(string res, params string[] args)
static XPathDocument LoadDocument(XmlTextReaderImpl reader)
Definition Compiler.cs:447
XsltCompileContext GetMatchesContext()
Definition Processor.cs:416
object GetVariableValue(VariableAction variable)
Definition Processor.cs:738
void PushActionFrame(ActionFrame container, XPathNodeIterator nodeSet)
Definition Processor.cs:359
object GetScriptObject(string nsUri)
Definition Processor.cs:198
bool EvaluateBoolean(ActionFrame context, int key)
Definition Processor.cs:521
string GetQueryExpression(int key)
Definition Processor.cs:371
readonly TemplateLookupAction _templateLookup
Definition Processor.cs:72
readonly IXsltDebugger _debugger
Definition Processor.cs:74
readonly XsltArgumentList _args
Definition Processor.cs:66
XsltCompileContext _matchesContext
Definition Processor.cs:84
void PushActionFrame(ActionFrame container)
Definition Processor.cs:354
string EvaluateString(ActionFrame context, int key)
Definition Processor.cs:506
XmlQualifiedName GetPreviousMode()
Definition Processor.cs:793
XsltCompileContext _valueOfContext
Definition Processor.cs:82
void PushOutput(IRecordOutput output)
Definition Processor.cs:710
readonly HWStack _debuggerStack
Definition Processor.cs:50
bool CopyEndEvent(XPathNavigator node)
Definition Processor.cs:680
void PushActionFrame(Action action, XPathNodeIterator nodeSet)
Definition Processor.cs:348
readonly XmlNameTable _nameTable
Definition Processor.cs:62
Processor(XPathNavigator doc, XsltArgumentList args, XmlResolver resolver, Stylesheet stylesheet, List< TheQuery > queryStore, RootAction rootAction, IXsltDebugger debugger)
Definition Processor.cs:220
Query GetValueQuery(int key, XsltCompileContext context)
Definition Processor.cs:390
readonly XmlResolver _resolver
Definition Processor.cs:64
string ValueOf(XPathNavigator n)
Definition Processor.cs:437
void SetCurrentMode(XmlQualifiedName mode)
Definition Processor.cs:798
object Evaluate(ActionFrame context, int key)
Definition Processor.cs:490
XPathNodeIterator StartQuery(XPathNodeIterator context, int key)
Definition Processor.cs:479
void SetParameter(XmlQualifiedName name, object value)
Definition Processor.cs:770
bool CopyTextEvent(XPathNavigator node)
Definition Processor.cs:661
bool Matches(XPathNavigator context, int key)
Definition Processor.cs:535
readonly XPathNavigator _document
Definition Processor.cs:46
StringBuilder GetSharedStringBuilder()
Definition Processor.cs:203
readonly Stylesheet _stylesheet
Definition Processor.cs:38
readonly List< TheQuery > _queryStore
Definition Processor.cs:44
object GetParameter(XmlQualifiedName name)
Definition Processor.cs:782
void AddSort(Sort sortinfo)
Definition Processor.cs:161
bool SetDefaultOutput(XsltOutput.OutputMethod method)
Definition Processor.cs:728
bool TextEvent(string text, bool disableOutputEscaping)
Definition Processor.cs:593
object GetExtensionObject(string nsUri)
Definition Processor.cs:193
bool BeginEvent(XPathNodeType nodeType, string prefix, string name, string nspace, bool empty)
Definition Processor.cs:553
object RunQuery(ActionFrame context, int key)
Definition Processor.cs:495
void Execute(Stream stream)
Definition Processor.cs:266
string ValueOf(ActionFrame context, int key)
Definition Processor.cs:425
void Execute(TextWriter writer)
Definition Processor.cs:285
readonly Hashtable _scriptExtensions
Definition Processor.cs:68
readonly RootAction _rootAction
Definition Processor.cs:40
readonly StateMachine _xsm
Definition Processor.cs:56
bool EndEvent(XPathNodeType nodeType)
Definition Processor.cs:620
bool BeginEvent(XPathNodeType nodeType, string prefix, string name, string nspace, bool empty, object htmlProps, bool search)
Definition Processor.cs:558
void Execute(XmlWriter writer)
Definition Processor.cs:304
void ElementValueWithoutWS(XPathNavigator nav, StringBuilder builder)
Definition Processor.cs:449
static bool IsRoot(XPathNavigator navigator)
Definition Processor.cs:695
XsltCompileContext GetValueOfContext()
Definition Processor.cs:407
void PushTemplateLookup(XPathNodeIterator nodeSet, XmlQualifiedName mode, Stylesheet importsOf)
Definition Processor.cs:365
bool CopyBeginEvent(XPathNavigator node, bool emptyflag)
Definition Processor.cs:645
XPathNavigator GetNavigator(Uri ruri)
Definition Processor.cs:128
object GetGlobalParameter(XmlQualifiedName qname)
Definition Processor.cs:178
readonly HWStack _actionStack
Definition Processor.cs:48
Processor.OutputResult BeginEvent(int state, XPathNodeType nodeType, string prefix, string name, string nspace, bool empty, object htmlProps, bool search)
Processor.OutputResult EndEvent(int state, XPathNodeType nodeType)
Processor.OutputResult TextEvent(int state, string text, bool disableOutputEscaping)
int BeginOutlook(XPathNodeType nodeType)
int Begin(XPathNodeType nodeType)
int EndOutlook(XPathNodeType nodeType)
int End(XPathNodeType nodeType)
bool PreserveWhiteSpace(Processor proc, XPathNavigator node)
void Initialize(XmlQualifiedName mode, Stylesheet importsOf)
void Reinitialize(InputScopeManager manager, Processor processor)
XsltOutput CreateDerivedOutput(OutputMethod method)
Definition XsltOutput.cs:75