diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/BooleanFunctions.cs b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/BooleanFunctions.cs index ae0e4144c36ee..2fab357bfc26f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/BooleanFunctions.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/BooleanFunctions.cs @@ -42,7 +42,7 @@ public override object Evaluate(XPathNodeIterator nodeIterator) => FT.FuncNot => Not(nodeIterator), FT.FuncTrue => true, FT.FuncFalse => false, - FT.FuncLang => Lang(nodeIterator), + FT.FuncLang => Lang(nodeIterator!), _ => false, }; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/CompiledXPathExpr.cs b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/CompiledXPathExpr.cs index e8c5556b22eab..736a8159f2194 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/CompiledXPathExpr.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/CompiledXPathExpr.cs @@ -162,7 +162,7 @@ internal sealed class XPathComparerHelper : IComparer private readonly CultureInfo _cinfo; private readonly XmlDataType _dataType; - public XPathComparerHelper(XmlSortOrder order, XmlCaseOrder caseOrder, string lang, XmlDataType dataType) + public XPathComparerHelper(XmlSortOrder order, XmlCaseOrder caseOrder, string? lang, XmlDataType dataType) { if (lang == null) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/ContextQuery.cs b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/ContextQuery.cs index 6725fea72579a..1f463a451de24 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/ContextQuery.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/ContextQuery.cs @@ -14,10 +14,12 @@ public ContextQuery() { this.count = 0; } + protected ContextQuery(ContextQuery other) : base(other) { this.contextNode = other.contextNode; // Don't need to clone here } + public override void Reset() { count = 0; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/FunctionQuery.cs b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/FunctionQuery.cs index 31a38e173321a..405319df5b63b 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/FunctionQuery.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/FunctionQuery.cs @@ -82,7 +82,7 @@ public override object Evaluate(XPathNodeIterator nodeIterator) try { Debug.Assert(_function != null); - object? retVal = ProcessResult(_function.Invoke(xsltContext, argVals, nodeIterator.Current)); + object? retVal = ProcessResult(_function.Invoke(xsltContext, argVals, nodeIterator.Current!)); // ProcessResult may return null when the input value is XmlNode and here doesn't seem to be the case. Debug.Assert(retVal != null); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/NumberFunctions.cs b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/NumberFunctions.cs index 6675f776aa35f..3cf4ae14fe122 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/NumberFunctions.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/NumberFunctions.cs @@ -59,7 +59,7 @@ private double Number(XPathNodeIterator nodeIterator) { if (_arg == null) { - Debug.Assert(nodeIterator.Current != null); + Debug.Assert(nodeIterator!.Current != null); return XmlConvert.ToXPathDouble(nodeIterator.Current.Value); } object argVal = _arg.Evaluate(nodeIterator); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/StringFunctions.cs b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/StringFunctions.cs index d2634c7084ed8..3ea556f6d736d 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/StringFunctions.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/StringFunctions.cs @@ -212,7 +212,7 @@ private double StringLength(XPathNodeIterator nodeIterator) { return _argList[0].Evaluate(nodeIterator).ToString()!.Length; } - Debug.Assert(nodeIterator.Current != null); + Debug.Assert(nodeIterator!.Current != null); return nodeIterator.Current.Value.Length; } @@ -225,7 +225,7 @@ private string Normalize(XPathNodeIterator nodeIterator) } else { - Debug.Assert(nodeIterator.Current != null); + Debug.Assert(nodeIterator!.Current != null); value = nodeIterator.Current.Value; } int modifyPos = -1; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/ISourceLineInfo.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/ISourceLineInfo.cs index bf93c639cc491..8a45cc4da4e46 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/ISourceLineInfo.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/ISourceLineInfo.cs @@ -1,11 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable namespace System.Xml.Xsl { internal interface ISourceLineInfo { - string Uri { get; } + string? Uri { get; } bool IsNoSource { get; } Location Start { get; } Location End { get; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/GenerateHelper.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/GenerateHelper.cs index fb8401058ecbb..1b770d4d5b1e0 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/GenerateHelper.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/GenerateHelper.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Globalization; using System.Xml; @@ -17,6 +18,7 @@ using System.Xml.Xsl.Qil; using System.Xml.Xsl.Runtime; using System.Runtime.Versioning; +using System.Diagnostics.CodeAnalysis; namespace System.Xml.Xsl.IlGen { @@ -26,16 +28,16 @@ namespace System.Xml.Xsl.IlGen internal class XmlILStorageMethods { // Aggregates - public MethodInfo AggAvg; - public MethodInfo AggAvgResult; - public MethodInfo AggCreate; - public MethodInfo AggIsEmpty; - public MethodInfo AggMax; - public MethodInfo AggMaxResult; - public MethodInfo AggMin; - public MethodInfo AggMinResult; - public MethodInfo AggSum; - public MethodInfo AggSumResult; + public MethodInfo? AggAvg; + public MethodInfo? AggAvgResult; + public MethodInfo? AggCreate; + public MethodInfo? AggIsEmpty; + public MethodInfo? AggMax; + public MethodInfo? AggMaxResult; + public MethodInfo? AggMin; + public MethodInfo? AggMinResult; + public MethodInfo? AggSum; + public MethodInfo? AggSumResult; // Sequences public Type SeqType; @@ -51,10 +53,10 @@ internal class XmlILStorageMethods public MethodInfo IListItem; // XPathItem - public MethodInfo ValueAs; + public MethodInfo? ValueAs; // ToAtomicValue - public MethodInfo ToAtomicValue; + public MethodInfo? ToAtomicValue; public XmlILStorageMethods(Type storageType) { @@ -62,7 +64,9 @@ public XmlILStorageMethods(Type storageType) if (storageType == typeof(int) || storageType == typeof(long) || storageType == typeof(decimal) || storageType == typeof(double)) { - Type aggType = Type.GetType("System.Xml.Xsl.Runtime." + storageType.Name + "Aggregator"); + string aggTypeName = "System.Xml.Xsl.Runtime." + storageType.Name + "Aggregator"; + Type? aggType = Type.GetType(aggTypeName); + Debug.Assert(aggType != null, $"Could not find type `{aggTypeName}`"); AggAvg = XmlILMethods.GetMethod(aggType, "Average"); AggAvgResult = XmlILMethods.GetMethod(aggType, "get_AverageResult"); AggCreate = XmlILMethods.GetMethod(aggType, "Create"); @@ -92,7 +96,9 @@ public XmlILStorageMethods(Type storageType) SeqAdd = XmlILMethods.GetMethod(SeqType, "Add"); } - SeqEmpty = SeqType.GetField("Empty"); + FieldInfo? seqEmpty = SeqType.GetField("Empty"); + Debug.Assert(seqEmpty != null, "Field `Empty` could not be found"); + SeqEmpty = seqEmpty; SeqReuse = XmlILMethods.GetMethod(SeqType, "CreateOrReuse", SeqType); SeqReuseSgl = XmlILMethods.GetMethod(SeqType, "CreateOrReuse", SeqType, storageType); SeqSortByKeys = XmlILMethods.GetMethod(SeqType, "SortByKeys"); @@ -140,14 +146,14 @@ internal static class XmlILConstructors private static ConstructorInfo GetConstructor(Type className) { - ConstructorInfo constrInfo = className.GetConstructor(Array.Empty()); + ConstructorInfo constrInfo = className.GetConstructor(Array.Empty())!; Debug.Assert(constrInfo != null, "Constructor " + className + " cannot be null."); return constrInfo; } private static ConstructorInfo GetConstructor(Type className, params Type[] args) { - ConstructorInfo constrInfo = className.GetConstructor(args); + ConstructorInfo constrInfo = className.GetConstructor(args)!; Debug.Assert(constrInfo != null, "Constructor " + className + " cannot be null."); return constrInfo; } @@ -415,14 +421,14 @@ internal static class XmlILMethods public static MethodInfo GetMethod(Type className, string methName) { - MethodInfo methInfo = className.GetMethod(methName); + MethodInfo? methInfo = className.GetMethod(methName); Debug.Assert(methInfo != null, "Method " + className.Name + "." + methName + " cannot be null."); return methInfo; } public static MethodInfo GetMethod(Type className, string methName, params Type[] args) { - MethodInfo methInfo = className.GetMethod(methName, args); + MethodInfo? methInfo = className.GetMethod(methName, args); Debug.Assert(methInfo != null, "Method " + methName + " cannot be null."); return methInfo; } @@ -448,22 +454,22 @@ internal enum GenerateNameType /// internal class GenerateHelper { - private MethodBase _methInfo; - private ILGenerator _ilgen; - private LocalBuilder _locXOut; + private MethodBase? _methInfo; + private ILGenerator? _ilgen; + private LocalBuilder? _locXOut; private readonly XmlILModule _module; private readonly bool _isDebug; private bool _initWriters; private readonly StaticDataManager _staticData; - private ISourceLineInfo _lastSourceInfo; - private MethodInfo _methSyncToNav; + private ISourceLineInfo? _lastSourceInfo; + private MethodInfo? _methSyncToNav; #if DEBUG private int _lblNum; - private Hashtable _symbols; + private Hashtable? _symbols; private int _numLocals; - private string _sourceFile; - private TextWriter _writerDump; + private string? _sourceFile; + private TextWriter? _writerDump; #endif /// @@ -490,7 +496,7 @@ public GenerateHelper(XmlILModule module, bool isDebug) // SxS note: Using hardcoded "dump.il" is an SxS issue. Since we are doing this ONLY in debug builds // and only for tracing purposes and MakeVersionSafeName does not seem to be able to handle file // extensions correctly I decided to suppress the SxS message (as advised by SxS guys). - public void MethodBegin(MethodBase methInfo, ISourceLineInfo sourceInfo, bool initWriters) + public void MethodBegin(MethodBase methInfo, ISourceLineInfo? sourceInfo, bool initWriters) { _methInfo = methInfo; _ilgen = XmlILModule.DefineMethodBody(methInfo); @@ -505,7 +511,7 @@ public void MethodBegin(MethodBase methInfo, ISourceLineInfo sourceInfo, bool in _sourceFile = null; _writerDump = XmlILTrace.GetTraceWriter("dump.il"); - _writerDump.WriteLine(".method {0}()", methInfo.Name); + _writerDump!.WriteLine(".method {0}()", methInfo.Name); _writerDump.WriteLine("{"); } #endif @@ -559,7 +565,7 @@ public void MethodEnd() #if DEBUG if (XmlILTrace.IsEnabled) { - _writerDump.WriteLine("}"); + _writerDump!.WriteLine("}"); _writerDump.WriteLine(""); _writerDump.Close(); } @@ -583,7 +589,7 @@ public void CallSyncToNavigator() if (_methSyncToNav == null) _methSyncToNav = _module.FindMethod("SyncToNavigator"); - Call(_methSyncToNav); + Call(_methSyncToNav!); } //----------------------------------------------- @@ -633,11 +639,11 @@ public void LoadType(Type clrTyp) /// public LocalBuilder DeclareLocal(string name, Type type) { - LocalBuilder locBldr = _ilgen.DeclareLocal(type); + LocalBuilder locBldr = _ilgen!.DeclareLocal(type); #if DEBUG if (XmlILTrace.IsEnabled) { - _symbols.Add(locBldr, name + _numLocals.ToString(CultureInfo.InvariantCulture)); + _symbols!.Add(locBldr, name + _numLocals.ToString(CultureInfo.InvariantCulture)); _numLocals++; } #endif @@ -663,7 +669,7 @@ public void LoadXsltLibrary() public void LoadQueryOutput() { - Emit(OpCodes.Ldloc, _locXOut); + Emit(OpCodes.Ldloc, _locXOut!); } @@ -801,7 +807,7 @@ private void TraceCall(OpCode opcode, MethodInfo meth) retType = meth.ReturnType.Name; } - _writerDump.WriteLine(" {0, -10} {1} {2}({3})", new object[] { opcode.Name, retType, meth.Name, strBldr.ToString() }); + _writerDump!.WriteLine(" {0, -10} {1} {2}({3})", new object?[] { opcode.Name, retType, meth.Name, strBldr.ToString() }); } #endif } @@ -811,7 +817,7 @@ public void Call(MethodInfo meth) OpCode opcode = meth.IsVirtual || meth.IsAbstract ? OpCodes.Callvirt : OpCodes.Call; TraceCall(opcode, meth); - _ilgen.Emit(opcode, meth); + _ilgen!.Emit(opcode, meth); if (_lastSourceInfo != null) { @@ -919,7 +925,7 @@ public void ConstructLiteralQName(string localName, string namespaceName) public void CallArithmeticOp(QilNodeType opType, XmlTypeCode code) { - MethodInfo meth = null; + MethodInfo? meth = null; switch (code) { @@ -962,7 +968,7 @@ public void CallArithmeticOp(QilNodeType opType, XmlTypeCode code) public void CallCompareEquals(XmlTypeCode code) { - MethodInfo meth = null; + MethodInfo? meth = null; switch (code) { @@ -979,7 +985,7 @@ public void CallCompareEquals(XmlTypeCode code) public void CallCompare(XmlTypeCode code) { - MethodInfo meth = null; + MethodInfo? meth = null; switch (code) { @@ -1010,7 +1016,7 @@ public void CallStartRtfConstruction(string baseUri) public void CallEndRtfConstruction() { LoadQueryRuntime(); - Emit(OpCodes.Ldloca, _locXOut); + Emit(OpCodes.Ldloca, _locXOut!); Call(XmlILMethods.EndRtfConstr); } @@ -1025,7 +1031,7 @@ public void CallStartSequenceConstruction() public void CallEndSequenceConstruction() { LoadQueryRuntime(); - Emit(OpCodes.Ldloca, _locXOut); + Emit(OpCodes.Ldloca, _locXOut!); Call(XmlILMethods.EndSeqConstr); } @@ -1092,6 +1098,7 @@ public void CallGetCollation(int idxName) Call(XmlILMethods.GetCollation); } + [MemberNotNull(nameof(_locXOut))] private void EnsureWriter() { // If write variable has not yet been initialized, do it now @@ -1100,6 +1107,8 @@ private void EnsureWriter() _locXOut = DeclareLocal("$$$xwrtChk", typeof(XmlQueryOutput)); _initWriters = true; } + + Debug.Assert(_locXOut != null); } @@ -1148,7 +1157,7 @@ public void CallWriteEndRoot() public void CallWriteStartElement(GenerateNameType nameType, bool callChk) { - MethodInfo meth = null; + MethodInfo? meth = null; // If runtime checks need to be made, if (callChk) @@ -1181,7 +1190,7 @@ public void CallWriteStartElement(GenerateNameType nameType, bool callChk) public void CallWriteEndElement(GenerateNameType nameType, bool callChk) { - MethodInfo meth = null; + MethodInfo? meth = null; // If runtime checks need to be made, if (callChk) @@ -1211,7 +1220,7 @@ public void CallStartElementContent() public void CallWriteStartAttribute(GenerateNameType nameType, bool callChk) { - MethodInfo meth = null; + MethodInfo? meth = null; // If runtime checks need to be made, if (callChk) @@ -1341,7 +1350,7 @@ public void CallCacheItem(Type itemStorageType) public void CallValueAs(Type clrType) { - MethodInfo meth; + MethodInfo? meth; meth = XmlILMethods.StorageMethods[clrType].ValueAs; if (meth == null) @@ -1366,9 +1375,9 @@ public void CallValueAs(Type clrType) // XmlSortKeyAccumulator methods //----------------------------------------------- - public void AddSortKey(XmlQueryType keyType) + public void AddSortKey(XmlQueryType? keyType) { - MethodInfo meth = null; + MethodInfo? meth = null; if (keyType == null) { @@ -1417,7 +1426,7 @@ public void AddSortKey(XmlQueryType keyType) /// public void DebugStartScope() { - _ilgen.BeginScope(); + _ilgen!.BeginScope(); } /// @@ -1425,7 +1434,7 @@ public void DebugStartScope() /// public void DebugEndScope() { - _ilgen.EndScope(); + _ilgen!.EndScope(); } /// @@ -1447,16 +1456,16 @@ public void DebugSequencePoint(ISourceLineInfo sourceInfo) MarkSequencePoint(sourceInfo); } - private string _lastUriString; - private string _lastFileName; + private string? _lastUriString; + private string? _lastFileName; // SQLBUDT 278010: debugger does not work with network paths in uri format, like file://server/share/dir/file private string GetFileName(ISourceLineInfo sourceInfo) { - string uriString = sourceInfo.Uri; - if ((object)uriString == (object)_lastUriString) + string uriString = sourceInfo.Uri!; + if ((object)uriString == (object?)_lastUriString) { - return _lastFileName; + return _lastFileName!; } _lastUriString = uriString; @@ -1480,15 +1489,15 @@ private void MarkSequencePoint(ISourceLineInfo sourceInfo) if (XmlILTrace.IsEnabled) { if (sourceInfo.IsNoSource) - _writerDump.WriteLine("//[no source]"); + _writerDump!.WriteLine("//[no source]"); else { if (sourceFile != _sourceFile) { _sourceFile = sourceFile; - _writerDump.WriteLine("// Source File '{0}'", _sourceFile); + _writerDump!.WriteLine("// Source File '{0}'", _sourceFile); } - _writerDump.WriteLine("//[{0},{1} -- {2},{3}]", sourceInfo.Start.Line, sourceInfo.Start.Pos, sourceInfo.End.Line, sourceInfo.End.Pos); + _writerDump!.WriteLine("//[{0},{1} -- {2},{3}]", sourceInfo.Start.Line, sourceInfo.Start.Pos, sourceInfo.End.Line, sourceInfo.End.Pos); } } #endif @@ -1504,11 +1513,11 @@ private void MarkSequencePoint(ISourceLineInfo sourceInfo) public Label DefineLabel() { - Label lbl = _ilgen.DefineLabel(); + Label lbl = _ilgen!.DefineLabel(); #if DEBUG if (XmlILTrace.IsEnabled) - _symbols.Add(lbl, ++_lblNum); + _symbols!.Add(lbl, ++_lblNum); #endif return lbl; @@ -1525,55 +1534,55 @@ public void MarkLabel(Label lbl) #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine("Label {0}:", _symbols[lbl]); + _writerDump!.WriteLine("Label {0}:", _symbols![lbl]); #endif - _ilgen.MarkLabel(lbl); + _ilgen!.MarkLabel(lbl); } public void Emit(OpCode opcode) { #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine(" {0}", opcode.Name); + _writerDump!.WriteLine(" {0}", opcode.Name); #endif - _ilgen.Emit(opcode); + _ilgen!.Emit(opcode); } public void Emit(OpCode opcode, byte byteVal) { #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine(" {0, -10} {1}", opcode.Name, byteVal); + _writerDump!.WriteLine(" {0, -10} {1}", opcode.Name, byteVal); #endif - _ilgen.Emit(opcode, byteVal); + _ilgen!.Emit(opcode, byteVal); } public void Emit(OpCode opcode, ConstructorInfo constrInfo) { #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine(" {0, -10} {1}", opcode.Name, constrInfo); + _writerDump!.WriteLine(" {0, -10} {1}", opcode.Name, constrInfo); #endif - _ilgen.Emit(opcode, constrInfo); + _ilgen!.Emit(opcode, constrInfo); } public void Emit(OpCode opcode, double dblVal) { #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine(" {0, -10} {1}", opcode.Name, dblVal); + _writerDump!.WriteLine(" {0, -10} {1}", opcode.Name, dblVal); #endif - _ilgen.Emit(opcode, dblVal); + _ilgen!.Emit(opcode, dblVal); } public void Emit(OpCode opcode, FieldInfo fldInfo) { #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine(" {0, -10} {1}", opcode.Name, fldInfo.Name); + _writerDump!.WriteLine(" {0, -10} {1}", opcode.Name, fldInfo.Name); #endif - _ilgen.Emit(opcode, fldInfo); + _ilgen!.Emit(opcode, fldInfo); } public void Emit(OpCode opcode, int intVal) @@ -1581,9 +1590,9 @@ public void Emit(OpCode opcode, int intVal) Debug.Assert(opcode.OperandType == OperandType.InlineI || opcode.OperandType == OperandType.InlineVar); #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine(" {0, -10} {1}", opcode.Name, intVal); + _writerDump!.WriteLine(" {0, -10} {1}", opcode.Name, intVal); #endif - _ilgen.Emit(opcode, intVal); + _ilgen!.Emit(opcode, intVal); } public void Emit(OpCode opcode, long longVal) @@ -1591,9 +1600,9 @@ public void Emit(OpCode opcode, long longVal) Debug.Assert(opcode.OperandType == OperandType.InlineI8); #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine(" {0, -10} {1}", opcode.Name, longVal); + _writerDump!.WriteLine(" {0, -10} {1}", opcode.Name, longVal); #endif - _ilgen.Emit(opcode, longVal); + _ilgen!.Emit(opcode, longVal); } public void Emit(OpCode opcode, Label lblVal) @@ -1601,9 +1610,9 @@ public void Emit(OpCode opcode, Label lblVal) Debug.Assert(!opcode.Equals(OpCodes.Br) && !opcode.Equals(OpCodes.Br_S), "Use EmitUnconditionalBranch and be careful not to emit unverifiable code."); #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine(" {0, -10} Label {1}", opcode.Name, _symbols[lblVal]); + _writerDump!.WriteLine(" {0, -10} Label {1}", opcode.Name, _symbols![lblVal]); #endif - _ilgen.Emit(opcode, lblVal); + _ilgen!.Emit(opcode, lblVal); } public void Emit(OpCode opcode, Label[] arrLabels) @@ -1611,51 +1620,51 @@ public void Emit(OpCode opcode, Label[] arrLabels) #if DEBUG if (XmlILTrace.IsEnabled) { - _writerDump.Write(" {0, -10} (Label {1}", opcode.Name, arrLabels.Length != 0 ? _symbols[arrLabels[0]].ToString() : ""); + _writerDump!.Write(" {0, -10} (Label {1}", opcode.Name, arrLabels.Length != 0 ? _symbols![arrLabels[0]]!.ToString() : ""); for (int i = 1; i < arrLabels.Length; i++) { - _writerDump.Write(", Label {0}", _symbols[arrLabels[i]]); + _writerDump.Write(", Label {0}", _symbols![arrLabels[i]]); } _writerDump.WriteLine(")"); } #endif - _ilgen.Emit(opcode, arrLabels); + _ilgen!.Emit(opcode, arrLabels); } public void Emit(OpCode opcode, LocalBuilder locBldr) { #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine(" {0, -10} {1} ({2})", opcode.Name, _symbols[locBldr], locBldr.LocalType.Name); + _writerDump!.WriteLine(" {0, -10} {1} ({2})", opcode.Name, _symbols![locBldr], locBldr.LocalType.Name); #endif - _ilgen.Emit(opcode, locBldr); + _ilgen!.Emit(opcode, locBldr); } public void Emit(OpCode opcode, sbyte sbyteVal) { #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine(" {0, -10} {1}", opcode.Name, sbyteVal); + _writerDump!.WriteLine(" {0, -10} {1}", opcode.Name, sbyteVal); #endif - _ilgen.Emit(opcode, sbyteVal); + _ilgen!.Emit(opcode, sbyteVal); } public void Emit(OpCode opcode, string strVal) { #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine(" {0, -10} \"{1}\"", opcode.Name, strVal); + _writerDump!.WriteLine(" {0, -10} \"{1}\"", opcode.Name, strVal); #endif - _ilgen.Emit(opcode, strVal); + _ilgen!.Emit(opcode, strVal); } public void Emit(OpCode opcode, Type typVal) { #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine(" {0, -10} {1}", opcode.Name, typVal); + _writerDump!.WriteLine(" {0, -10} {1}", opcode.Name, typVal); #endif - _ilgen.Emit(opcode, typVal); + _ilgen!.Emit(opcode, typVal); } /// @@ -1706,9 +1715,9 @@ public void EmitUnconditionalBranch(OpCode opcode, Label lblTarget) #if DEBUG if (XmlILTrace.IsEnabled) - _writerDump.WriteLine(" {0, -10} Label {1}", opcode.Name, _symbols[lblTarget]); + _writerDump!.WriteLine(" {0, -10} Label {1}", opcode.Name, _symbols![lblTarget]); #endif - _ilgen.Emit(opcode, lblTarget); + _ilgen!.Emit(opcode, lblTarget); if (_lastSourceInfo != null && (opcode.Equals(OpCodes.Br) || opcode.Equals(OpCodes.Br_S))) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/IteratorDescriptor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/IteratorDescriptor.cs index 99befbe03dd92..d69b9853c28d4 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/IteratorDescriptor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/IteratorDescriptor.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections; using System.Collections.Generic; @@ -12,6 +13,7 @@ using System.Reflection; using System.Reflection.Emit; using System.Xml.Xsl.Runtime; +using System.Diagnostics.CodeAnalysis; namespace System.Xml.Xsl.IlGen { @@ -107,7 +109,7 @@ public static StorageDescriptor Local(LocalBuilder loc, Type itemStorageType, bo /// public static StorageDescriptor Current(LocalBuilder locIter, Type itemStorageType) { - Debug.Assert(locIter.LocalType.GetMethod("get_Current").ReturnType == itemStorageType, + Debug.Assert(locIter.LocalType.GetMethod("get_Current")!.ReturnType == itemStorageType, "Type " + itemStorageType + " does not match type of Current property."); StorageDescriptor storage = default; @@ -184,7 +186,7 @@ public int ParameterLocation /// /// Return the LocalBuilder that stores this iterator's values. /// - public LocalBuilder LocalLocation + public LocalBuilder? LocalLocation { get { return _locationObject as LocalBuilder; } } @@ -193,7 +195,7 @@ public LocalBuilder LocalLocation /// Return the LocalBuilder that will store this iterator's helper class. The Current property /// on this iterator can be accessed to get the current iteration value. /// - public LocalBuilder CurrentLocation + public LocalBuilder? CurrentLocation { get { return _locationObject as LocalBuilder; } } @@ -201,7 +203,7 @@ public LocalBuilder CurrentLocation /// /// Return the MethodInfo for the method that computes this global value. /// - public MethodInfo GlobalLocation + public MethodInfo? GlobalLocation { get { return _locationObject as MethodInfo; } } @@ -232,12 +234,12 @@ internal class IteratorDescriptor private GenerateHelper _helper; // Related iterators - private IteratorDescriptor _iterParent; + private IteratorDescriptor? _iterParent; // Iteration private Label _lblNext; private bool _hasNext; - private LocalBuilder _locPos; + private LocalBuilder? _locPos; // Branching private BranchingContext _brctxt; @@ -270,7 +272,8 @@ public IteratorDescriptor(IteratorDescriptor iterParent) /// /// Internal helper initializor. /// - private void Init(IteratorDescriptor iterParent, GenerateHelper helper) + [MemberNotNull(nameof(_helper))] + private void Init(IteratorDescriptor? iterParent, GenerateHelper helper) { _helper = helper; _iterParent = iterParent; @@ -284,7 +287,7 @@ private void Init(IteratorDescriptor iterParent, GenerateHelper helper) /// /// Return the iterator in which this iterator is nested. /// - public IteratorDescriptor ParentIterator + public IteratorDescriptor? ParentIterator { get { return _iterParent; } } @@ -361,7 +364,7 @@ public void LoopToEnd(Label lblOnEnd) /// This location is only defined on iterators, and then only if they might be /// referenced by a PositionOf operator. /// - public LocalBuilder LocalPosition + public LocalBuilder? LocalPosition { get { return _locPos; } set { _locPos = value; } @@ -509,12 +512,12 @@ public void PushValue() break; case ItemLocation.Local: - _helper.Emit(OpCodes.Ldloc, _storage.LocalLocation); + _helper.Emit(OpCodes.Ldloc, _storage.LocalLocation!); break; case ItemLocation.Current: - _helper.Emit(OpCodes.Ldloca, _storage.CurrentLocation); - _helper.Call(_storage.CurrentLocation.LocalType.GetMethod("get_Current")); + _helper.Emit(OpCodes.Ldloca, _storage.CurrentLocation!); + _helper.Call(_storage.CurrentLocation!.LocalType.GetMethod("get_Current")!); break; default: @@ -543,7 +546,7 @@ public void EnsureStack() case ItemLocation.Global: // Call method that computes the value of this global value _helper.LoadQueryRuntime(); - _helper.Call(_storage.GlobalLocation); + _helper.Call(_storage.GlobalLocation!); break; default: @@ -702,7 +705,7 @@ public void EnsureItemStorageType(XmlQueryType xmlType, Type storageTypeDest) // Destination type must be item, so generate code to create an XmlAtomicValue _helper.LoadInteger(_helper.StaticData.DeclareXmlType(xmlType)); _helper.LoadQueryRuntime(); - _helper.Call(XmlILMethods.StorageMethods[_storage.ItemStorageType].ToAtomicValue); + _helper.Call(XmlILMethods.StorageMethods[_storage.ItemStorageType].ToAtomicValue!); SetStorageType: _storage = _storage.ToStorageType(storageTypeDest); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/OptimizerPatterns.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/OptimizerPatterns.cs index e3fd512b884aa..93904a435363a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/OptimizerPatterns.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/OptimizerPatterns.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; using System.Xml.Xsl.Qil; @@ -58,23 +59,23 @@ internal class OptimizerPatterns : IQilAnnotation private int _patterns; // Set of patterns that the annotated Qil node and its subtree matches private bool _isReadOnly; // True if setters are disabled in the case of singleton OptimizerPatterns - private object _arg0, _arg1, _arg2; // Arguments to the matching patterns + private object? _arg0, _arg1, _arg2; // Arguments to the matching patterns - private static volatile OptimizerPatterns s_zeroOrOneDefault; - private static volatile OptimizerPatterns s_maybeManyDefault; - private static volatile OptimizerPatterns s_dodDefault; + private static volatile OptimizerPatterns? s_zeroOrOneDefault; + private static volatile OptimizerPatterns? s_maybeManyDefault; + private static volatile OptimizerPatterns? s_dodDefault; /// /// Get OptimizerPatterns annotation for the specified node. Lazily create if necessary. /// public static OptimizerPatterns Read(QilNode nd) { - XmlILAnnotation ann = nd.Annotation as XmlILAnnotation; - OptimizerPatterns optPatt = (ann != null) ? ann.Patterns : null; + XmlILAnnotation? ann = nd.Annotation as XmlILAnnotation; + OptimizerPatterns? optPatt = (ann != null) ? ann.Patterns : null; if (optPatt == null) { - if (!nd.XmlType.MaybeMany) + if (!nd.XmlType!.MaybeMany) { // Expressions with ZeroOrOne cardinality should always report IsDocOrderDistinct and NoContainedNodes if (s_zeroOrOneDefault == null) @@ -131,14 +132,14 @@ public static OptimizerPatterns Read(QilNode nd) public static OptimizerPatterns Write(QilNode nd) { XmlILAnnotation ann = XmlILAnnotation.Write(nd); - OptimizerPatterns optPatt = ann.Patterns; + OptimizerPatterns? optPatt = ann.Patterns; if (optPatt == null || optPatt._isReadOnly) { optPatt = new OptimizerPatterns(); ann.Patterns = optPatt; - if (!nd.XmlType.MaybeMany) + if (!nd.XmlType!.MaybeMany) { optPatt.AddPattern(OptimizerPatternName.IsDocOrderDistinct); optPatt.AddPattern(OptimizerPatternName.SameDepth); @@ -224,7 +225,7 @@ public void AddArgument(OptimizerPatternArgument argId, object arg) /// public object GetArgument(OptimizerPatternArgument argNum) { - object arg = null; + object? arg = null; switch ((int)argNum) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/StaticDataManager.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/StaticDataManager.cs index eda928e80263c..e0d47c7007d7b 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/StaticDataManager.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/StaticDataManager.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections; using System.Collections.Generic; using System.Diagnostics; @@ -14,7 +15,7 @@ namespace System.Xml.Xsl.IlGen /// This internal class maintains a list of unique values. Each unique value is assigned a unique ID, which can /// be used to quickly access the value, since it corresponds to the value's position in the list. /// - internal class UniqueList + internal class UniqueList where T : notnull { private readonly Dictionary _lookup = new Dictionary(); private readonly List _list = new List(); @@ -60,13 +61,13 @@ public T[] ToArray() /// internal class StaticDataManager { - private UniqueList _uniqueNames; - private UniqueList _uniqueFilters; - private List _prefixMappingsList; - private List _globalNames; - private UniqueList _earlyInfo; - private UniqueList _uniqueXmlTypes; - private UniqueList _uniqueCollations; + private UniqueList? _uniqueNames; + private UniqueList? _uniqueFilters; + private List? _prefixMappingsList; + private List? _globalNames; + private UniqueList? _earlyInfo; + private UniqueList? _uniqueXmlTypes; + private UniqueList? _uniqueCollations; /// /// Add "name" to the list of unique names that are used by this query. Return the index of @@ -83,7 +84,7 @@ public int DeclareName(string name) /// /// Return an array of all names that are used by the query (null if no names). /// - public string[] Names + public string[]? Names { get { return (_uniqueNames != null) ? _uniqueNames.ToArray() : null; } } @@ -104,7 +105,7 @@ public int DeclareNameFilter(string locName, string nsUri) /// Return an array of all name filters, where each name filter is represented as a pair of integer offsets (localName, namespaceUri) /// into the Names array (null if no name filters). /// - public Int32Pair[] NameFilters + public Int32Pair[]? NameFilters { get { return (_uniqueFilters != null) ? _uniqueFilters.ToArray() : null; } } @@ -140,7 +141,7 @@ public int DeclarePrefixMappings(IList list) /// /// Return an array of all prefix mappings that are used by the query to compute names (null if no mappings). /// - public StringPair[][] PrefixMappingsList + public StringPair[][]? PrefixMappingsList { get { return (_prefixMappingsList != null) ? _prefixMappingsList.ToArray() : null; } } @@ -163,7 +164,7 @@ public int DeclareGlobalValue(string name) /// /// Return an array containing the names of all global variables and parameters. /// - public string[] GlobalNames + public string[]? GlobalNames { get { return (_globalNames != null) ? _globalNames.ToArray() : null; } } @@ -183,7 +184,7 @@ public int DeclareEarlyBound(string namespaceUri, Type ebType) /// /// Return an array of all early bound information that is used by the query (null if none is used). /// - public EarlyBoundInfo[] EarlyBound + public EarlyBoundInfo[]? EarlyBound { get { @@ -210,7 +211,7 @@ public int DeclareXmlType(XmlQueryType type) /// /// Return an array of all types that are used by the query (null if no names). /// - public XmlQueryType[] XmlTypes + public XmlQueryType[]? XmlTypes { get { return (_uniqueXmlTypes != null) ? _uniqueXmlTypes.ToArray() : null; } } @@ -230,7 +231,7 @@ public int DeclareCollation(string collation) /// /// Return an array of all collations that are used by the query (null if no names). /// - public XmlCollation[] Collations + public XmlCollation[]? Collations { get { return (_uniqueCollations != null) ? _uniqueCollations.ToArray() : null; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/TailCallAnalyzer.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/TailCallAnalyzer.cs index aa9e8ae0cd995..99cdf8f6a4898 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/TailCallAnalyzer.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/TailCallAnalyzer.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; using System.Xml.Xsl.Qil; @@ -50,7 +51,7 @@ private static void AnalyzeDefinition(QilNode nd) { // Recursively analyze Loop return value QilLoop ndLoop = (QilLoop)nd; - if (ndLoop.Variable.NodeType == QilNodeType.Let || !ndLoop.Variable.Binding.XmlType.MaybeMany) + if (ndLoop.Variable.NodeType == QilNodeType.Let || !ndLoop.Variable.Binding!.XmlType!.MaybeMany) AnalyzeDefinition(ndLoop.Body); break; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILAnnotation.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILAnnotation.cs index 0fdbb76a1c69f..b691af96ffbdb 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILAnnotation.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILAnnotation.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Reflection; using System.Xml.Xsl.Qil; @@ -10,14 +11,14 @@ namespace System.Xml.Xsl.IlGen /// /// Several annotations are created and attached to Qil nodes during the optimization and code generation phase. /// - internal class XmlILAnnotation : ListBase + internal class XmlILAnnotation : ListBase { - private readonly object _annPrev; - private MethodInfo _funcMethod; + private readonly object? _annPrev; + private MethodInfo? _funcMethod; private int _argPos; - private IteratorDescriptor _iterInfo; - private XmlILConstructInfo _constrInfo; - private OptimizerPatterns _optPatt; + private IteratorDescriptor? _iterInfo; + private XmlILConstructInfo? _constrInfo; + private OptimizerPatterns? _optPatt; //----------------------------------------------- @@ -29,7 +30,7 @@ internal class XmlILAnnotation : ListBase /// public static XmlILAnnotation Write(QilNode nd) { - XmlILAnnotation ann = nd.Annotation as XmlILAnnotation; + XmlILAnnotation? ann = nd.Annotation as XmlILAnnotation; if (ann == null) { @@ -40,7 +41,7 @@ public static XmlILAnnotation Write(QilNode nd) return ann; } - private XmlILAnnotation(object annPrev) + private XmlILAnnotation(object? annPrev) { _annPrev = annPrev; } @@ -54,7 +55,7 @@ private XmlILAnnotation(object annPrev) /// User-defined functions and global variables and parameters are bound to Clr MethodInfo objects. /// Attached to Function, global Let, and global Parameter nodes. /// - public MethodInfo FunctionBinding + public MethodInfo? FunctionBinding { get { return _funcMethod; } set { _funcMethod = value; } @@ -75,7 +76,7 @@ public int ArgumentPosition /// For/Let node is referenced. /// Attached to For and Let nodes. /// - public IteratorDescriptor CachedIteratorDescriptor + public IteratorDescriptor? CachedIteratorDescriptor { get { return _iterInfo; } set { _iterInfo = value; } @@ -85,7 +86,7 @@ public IteratorDescriptor CachedIteratorDescriptor /// Contains information about how this expression will be constructed by ILGen. /// Attached to any kind of Qil node. /// - public XmlILConstructInfo ConstructInfo + public XmlILConstructInfo? ConstructInfo { get { return _constrInfo; } set { _constrInfo = value; } @@ -95,7 +96,7 @@ public XmlILConstructInfo ConstructInfo /// Contains patterns that the subtree rooted at this node matches. /// Attached to any kind of Qil node. /// - public OptimizerPatterns Patterns + public OptimizerPatterns? Patterns { get { return _optPatt; } set { _optPatt = value; } @@ -117,7 +118,7 @@ public override int Count /// /// Return the annotation at the specified index. /// - public override object this[int index] + public override object? this[int index] { get { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILConstructAnalyzer.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILConstructAnalyzer.cs index f22db4ec2f1c0..98ac3aea46d5e 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILConstructAnalyzer.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILConstructAnalyzer.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Xml; using System.Xml.Schema; @@ -53,19 +54,19 @@ internal class XmlILConstructInfo : IQilAnnotation private PossibleXmlStates _xstatesInitial, _xstatesFinal, _xstatesBeginLoop, _xstatesEndLoop; private bool _isNmspInScope, _mightHaveNmsp, _mightHaveAttrs, _mightHaveDupAttrs, _mightHaveNmspAfterAttrs; private XmlILConstructMethod _constrMeth; - private XmlILConstructInfo _parentInfo; - private ArrayList _callersInfo; + private XmlILConstructInfo? _parentInfo; + private ArrayList? _callersInfo; private bool _isReadOnly; - private static volatile XmlILConstructInfo s_default; + private static volatile XmlILConstructInfo? s_default; /// /// Get ConstructInfo annotation for the specified node. Lazily create if necessary. /// public static XmlILConstructInfo Read(QilNode nd) { - XmlILAnnotation ann = nd.Annotation as XmlILAnnotation; - XmlILConstructInfo constrInfo = (ann != null) ? ann.ConstructInfo : null; + XmlILAnnotation? ann = nd.Annotation as XmlILAnnotation; + XmlILConstructInfo? constrInfo = (ann != null) ? ann.ConstructInfo : null; if (constrInfo == null) { @@ -91,7 +92,7 @@ public static XmlILConstructInfo Read(QilNode nd) public static XmlILConstructInfo Write(QilNode nd) { XmlILAnnotation ann = XmlILAnnotation.Write(nd); - XmlILConstructInfo constrInfo = ann.ConstructInfo; + XmlILConstructInfo? constrInfo = ann.ConstructInfo; if (constrInfo == null || constrInfo._isReadOnly) { @@ -260,7 +261,7 @@ public bool PullFromIteratorFirst /// If the annotated expression will be constructed as the content of another constructor, and this can be /// guaranteed at compile-time, then this property will be the non-null XmlILConstructInfo of that constructor. /// - public XmlILConstructInfo ParentInfo + public XmlILConstructInfo? ParentInfo { //get { return this.parentInfo; } set @@ -274,7 +275,7 @@ public XmlILConstructInfo ParentInfo /// If the annotated expression will be constructed as the content of an ElementCtor, and this can be /// guaranteed at compile-time, then this property will be the non-null XmlILConstructInfo of that constructor. /// - public XmlILConstructInfo ParentElementInfo + public XmlILConstructInfo? ParentElementInfo { get { @@ -422,7 +423,7 @@ public override string ToString() /// internal class XmlILStateAnalyzer { - protected XmlILConstructInfo parentInfo; + protected XmlILConstructInfo? parentInfo; protected QilFactory fac; protected PossibleXmlStates xstates; protected bool withinElem; @@ -439,7 +440,7 @@ public XmlILStateAnalyzer(QilFactory fac) /// Perform analysis on the specified constructor and its content. Return the ndContent that was passed in, /// or a replacement. /// - public virtual QilNode Analyze(QilNode ndConstr, QilNode ndContent) + public virtual QilNode? Analyze(QilNode? ndConstr, QilNode? ndContent) { if (ndConstr == null) { @@ -514,7 +515,7 @@ public virtual QilNode Analyze(QilNode ndConstr, QilNode ndContent) ndContent = AnalyzeContent(ndContent); if (ndConstr.NodeType == QilNodeType.Choice) - AnalyzeChoice(ndConstr as QilChoice, this.parentInfo); + AnalyzeChoice((ndConstr as QilChoice)!, this.parentInfo); // Since Function will never be another node's content, set its final states here if (ndConstr.NodeType == QilNodeType.Function) @@ -558,10 +559,10 @@ protected virtual QilNode AnalyzeContent(QilNode nd) switch (nd.NodeType) { - case QilNodeType.Loop: AnalyzeLoop(nd as QilLoop, info); break; - case QilNodeType.Sequence: AnalyzeSequence(nd as QilList, info); break; - case QilNodeType.Conditional: AnalyzeConditional(nd as QilTernary, info); break; - case QilNodeType.Choice: AnalyzeChoice(nd as QilChoice, info); break; + case QilNodeType.Loop: AnalyzeLoop((nd as QilLoop)!, info); break; + case QilNodeType.Sequence: AnalyzeSequence((nd as QilList)!, info); break; + case QilNodeType.Conditional: AnalyzeConditional((nd as QilTernary)!, info); break; + case QilNodeType.Choice: AnalyzeChoice((nd as QilChoice)!, info); break; case QilNodeType.Error: case QilNodeType.Warning: @@ -570,7 +571,7 @@ protected virtual QilNode AnalyzeContent(QilNode nd) break; case QilNodeType.Nop: - ndChild = (nd as QilUnary).Child; + ndChild = (nd as QilUnary)!.Child; switch (ndChild.NodeType) { case QilNodeType.For: @@ -604,7 +605,7 @@ protected virtual QilNode AnalyzeContent(QilNode nd) /// protected virtual void AnalyzeLoop(QilLoop ndLoop, XmlILConstructInfo info) { - XmlQueryType typ = ndLoop.XmlType; + XmlQueryType typ = ndLoop.XmlType!; // Ensure that construct method is Writer info.ConstructMethod = XmlILConstructMethod.Writer; @@ -688,7 +689,7 @@ protected virtual void AnalyzeChoice(QilChoice ndChoice, XmlILConstructInfo info /// protected virtual void AnalyzeCopy(QilNode ndCopy, XmlILConstructInfo info) { - XmlQueryType typ = ndCopy.XmlType; + XmlQueryType typ = ndCopy.XmlType!; // Copying item(s) to output involves looping if there is not exactly one item in the sequence if (!typ.IsSingleton) @@ -805,9 +806,9 @@ public XmlILElementAnalyzer(QilFactory fac) : base(fac) /// Analyze the content argument of the ElementCtor. Try to eliminate as many runtime checks as possible, /// both for the ElementCtor and for content constructors. /// - public override QilNode Analyze(QilNode ndElem, QilNode ndContent) + public override QilNode? Analyze(QilNode? ndElem, QilNode? ndContent) { - Debug.Assert(ndElem.NodeType == QilNodeType.ElementCtor); + Debug.Assert(ndElem!.NodeType == QilNodeType.ElementCtor); this.parentInfo = XmlILConstructInfo.Write(ndElem); // Start by assuming that these properties are false (they default to true, but analyzer might be able to @@ -831,7 +832,7 @@ public override QilNode Analyze(QilNode ndElem, QilNode ndContent) protected override void AnalyzeLoop(QilLoop ndLoop, XmlILConstructInfo info) { // Constructing attributes/namespaces in a loop can cause duplicates, namespaces after attributes, etc. - if (ndLoop.XmlType.MaybeMany) + if (ndLoop.XmlType!.MaybeMany) CheckAttributeNamespaceConstruct(ndLoop.XmlType); base.AnalyzeLoop(ndLoop, info); @@ -844,11 +845,13 @@ protected override void AnalyzeCopy(QilNode ndCopy, XmlILConstructInfo info) { if (ndCopy.NodeType == QilNodeType.AttributeCtor) { - AnalyzeAttributeCtor(ndCopy as QilBinary, info); + QilBinary? binaryNode = ndCopy as QilBinary; + Debug.Assert(binaryNode != null); + AnalyzeAttributeCtor(binaryNode, info); } else { - CheckAttributeNamespaceConstruct(ndCopy.XmlType); + CheckAttributeNamespaceConstruct(ndCopy.XmlType!); } base.AnalyzeCopy(ndCopy, info); @@ -861,12 +864,13 @@ private void AnalyzeAttributeCtor(QilBinary ndAttr, XmlILConstructInfo info) { if (ndAttr.Left.NodeType == QilNodeType.LiteralQName) { - QilName ndName = ndAttr.Left as QilName; + QilName? ndName = ndAttr.Left as QilName; + Debug.Assert(ndName != null); XmlQualifiedName qname; int idx; // This attribute might be constructed on the parent element - this.parentInfo.MightHaveAttributes = true; + this.parentInfo!.MightHaveAttributes = true; // Check to see whether this attribute is a duplicate of a previous attribute if (!this.parentInfo.MightHaveDuplicateAttributes) @@ -875,7 +879,7 @@ private void AnalyzeAttributeCtor(QilBinary ndAttr, XmlILConstructInfo info) for (idx = 0; idx < _dupAttrs.Count; idx++) { - XmlQualifiedName qnameDup = (XmlQualifiedName)_dupAttrs[idx]; + XmlQualifiedName qnameDup = (XmlQualifiedName)_dupAttrs[idx]!; if ((object)qnameDup.Name == (object)qname.Name && (object)qnameDup.Namespace == (object)qname.Namespace) { @@ -898,7 +902,7 @@ private void AnalyzeAttributeCtor(QilBinary ndAttr, XmlILConstructInfo info) else { // Attribute prefix and namespace are not known at compile-time - CheckAttributeNamespaceConstruct(ndAttr.XmlType); + CheckAttributeNamespaceConstruct(ndAttr.XmlType!); } } @@ -911,7 +915,7 @@ private void CheckAttributeNamespaceConstruct(XmlQueryType typ) if ((typ.NodeKinds & XmlNodeKindFlags.Attribute) != XmlNodeKindFlags.None) { // Mark element as possibly having attributes and duplicate attributes (since we don't know the names) - this.parentInfo.MightHaveAttributes = true; + this.parentInfo!.MightHaveAttributes = true; this.parentInfo.MightHaveDuplicateAttributes = true; // Attribute namespaces might be declared @@ -922,7 +926,7 @@ private void CheckAttributeNamespaceConstruct(XmlQueryType typ) if ((typ.NodeKinds & XmlNodeKindFlags.Namespace) != XmlNodeKindFlags.None) { // Then element might have namespaces, - this.parentInfo.MightHaveNamespaces = true; + this.parentInfo!.MightHaveNamespaces = true; // If attributes might already have been constructed, if (this.parentInfo.MightHaveAttributes) @@ -978,7 +982,7 @@ private void AnalyzeContent(QilNode nd) { case QilNodeType.Loop: _addInScopeNmsp = false; - AnalyzeContent((nd as QilLoop).Body); + AnalyzeContent((nd as QilLoop)!.Body); break; case QilNodeType.Sequence: @@ -988,13 +992,13 @@ private void AnalyzeContent(QilNode nd) case QilNodeType.Conditional: _addInScopeNmsp = false; - AnalyzeContent((nd as QilTernary).Center); - AnalyzeContent((nd as QilTernary).Right); + AnalyzeContent((nd as QilTernary)!.Center); + AnalyzeContent((nd as QilTernary)!.Right); break; case QilNodeType.Choice: _addInScopeNmsp = false; - QilList ndBranches = (nd as QilChoice).Branches; + QilList ndBranches = (nd as QilChoice)!.Branches; for (int idx = 0; idx < ndBranches.Count; idx++) AnalyzeContent(ndBranches[idx]); @@ -1006,8 +1010,8 @@ private void AnalyzeContent(QilNode nd) _nsmgr.PushScope(); cntNmspSave = _cntNmsp; - if (CheckNamespaceInScope(nd as QilBinary)) - AnalyzeContent((nd as QilBinary).Right); + if (CheckNamespaceInScope((nd as QilBinary)!)) + AnalyzeContent((nd as QilBinary)!.Right); _nsmgr.PopScope(); _addInScopeNmsp = false; @@ -1016,15 +1020,15 @@ private void AnalyzeContent(QilNode nd) case QilNodeType.AttributeCtor: _addInScopeNmsp = false; - CheckNamespaceInScope(nd as QilBinary); + CheckNamespaceInScope((nd as QilBinary)!); break; case QilNodeType.NamespaceDecl: - CheckNamespaceInScope(nd as QilBinary); + CheckNamespaceInScope((nd as QilBinary)!); break; case QilNodeType.Nop: - AnalyzeContent((nd as QilUnary).Child); + AnalyzeContent((nd as QilUnary)!.Child); break; default: @@ -1040,8 +1044,9 @@ private void AnalyzeContent(QilNode nd) /// private bool CheckNamespaceInScope(QilBinary nd) { - QilName ndName; - string prefix, ns, prefixExisting, nsExisting; + QilName? ndName; + string prefix, ns; + string? prefixExisting, nsExisting; XPathNodeType nodeType; switch (nd.NodeType) @@ -1081,7 +1086,7 @@ private bool CheckNamespaceInScope(QilBinary nd) return false; // Atomize names - prefix = _nsmgr.NameTable.Add(prefix); + prefix = _nsmgr.NameTable!.Add(prefix); ns = _nsmgr.NameTable.Add(ns); // Determine whether namespace is already in-scope @@ -1090,10 +1095,10 @@ private bool CheckNamespaceInScope(QilBinary nd) _nsmgr.GetNamespaceDeclaration(iNmsp, out prefixExisting, out nsExisting); // If prefix is already declared, - if ((object)prefix == (object)prefixExisting) + if ((object)prefix == (object?)prefixExisting) { // Then if the namespace is the same, this namespace is redundant - if ((object)ns == (object)nsExisting) + if ((object)ns == (object?)nsExisting) XmlILConstructInfo.Write(nd).IsNamespaceInScope = true; // Else quit searching, because any further matching prefixes will be hidden (not in-scope) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILModule.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILModule.cs index 74e0fbeb689f8..f6b43070e81bc 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILModule.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILModule.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections; using System.Diagnostics; using System.Reflection; @@ -25,7 +26,7 @@ internal class XmlILModule private static long s_assemblyId; // Unique identifier used to ensure that assembly names are unique within AppDomain private static readonly ModuleBuilder s_LREModule = CreateLREModule(); // Module used to emit dynamic lightweight-reflection-emit (LRE) methods - private TypeBuilder _typeBldr; + private TypeBuilder? _typeBldr; private Hashtable _methods; private readonly bool _useLRE, _emitSymbols; @@ -114,7 +115,7 @@ public XmlILModule(bool useLRE, bool emitSymbols) /// /// Define a method in this module with the specified name and parameters. /// - public MethodInfo DefineMethod(string name, Type returnType, Type[] paramTypes, string[] paramNames, XmlILMethodAttributes xmlAttrs) + public MethodInfo DefineMethod(string name, Type returnType, Type[] paramTypes, string?[] paramNames, XmlILMethodAttributes xmlAttrs) { MethodInfo methResult; int uniqueId = 1; @@ -141,9 +142,7 @@ public MethodInfo DefineMethod(string name, Type returnType, Type[] paramTypes, if (!_useLRE) { - MethodBuilder methBldr; - - methBldr = _typeBldr.DefineMethod( + MethodBuilder methBldr = _typeBldr!.DefineMethod( name, MethodAttributes.Private | MethodAttributes.Static, returnType, @@ -161,7 +160,7 @@ public MethodInfo DefineMethod(string name, Type returnType, Type[] paramTypes, for (int i = 0; i < paramNames.Length; i++) { - if (paramNames[i] != null && paramNames[i].Length != 0) + if (paramNames[i] != null && paramNames[i]!.Length != 0) methBldr.DefineParameter(i + (isRaw ? 1 : 2), ParameterAttributes.None, paramNames[i]); } @@ -185,11 +184,11 @@ public MethodInfo DefineMethod(string name, Type returnType, Type[] paramTypes, /// public static ILGenerator DefineMethodBody(MethodBase methInfo) { - DynamicMethod methDyn = methInfo as DynamicMethod; + DynamicMethod? methDyn = methInfo as DynamicMethod; if (methDyn != null) return methDyn.GetILGenerator(); - MethodBuilder methBldr = methInfo as MethodBuilder; + MethodBuilder? methBldr = methInfo as MethodBuilder; if (methBldr != null) return methBldr.GetILGenerator(); @@ -199,9 +198,9 @@ public static ILGenerator DefineMethodBody(MethodBase methInfo) /// /// Find a MethodInfo of the specified name and return it. Return null if no such method exists. /// - public MethodInfo FindMethod(string name) + public MethodInfo? FindMethod(string name) { - return (MethodInfo)_methods[name]; + return (MethodInfo?)_methods[name]; } /// @@ -210,7 +209,7 @@ public MethodInfo FindMethod(string name) public FieldInfo DefineInitializedData(string name, byte[] data) { Debug.Assert(!_useLRE, "Cannot create initialized data for an LRE module"); - return _typeBldr.DefineInitializedData(name, data, FieldAttributes.Private | FieldAttributes.Static); + return _typeBldr!.DefineInitializedData(name, data, FieldAttributes.Private | FieldAttributes.Static); } /// @@ -219,7 +218,7 @@ public FieldInfo DefineInitializedData(string name, byte[] data) public FieldInfo DefineField(string fieldName, Type type) { Debug.Assert(!_useLRE, "Cannot create field for an LRE module"); - return _typeBldr.DefineField(fieldName, type, FieldAttributes.Private | FieldAttributes.Static); + return _typeBldr!.DefineField(fieldName, type, FieldAttributes.Private | FieldAttributes.Static); } /// @@ -228,7 +227,7 @@ public FieldInfo DefineField(string fieldName, Type type) public ConstructorInfo DefineTypeInitializer() { Debug.Assert(!_useLRE, "Cannot create type initializer for an LRE module"); - return _typeBldr.DefineTypeInitializer(); + return _typeBldr!.DefineTypeInitializer(); } /// @@ -242,7 +241,7 @@ public void BakeMethods() if (!_useLRE) { - typBaked = _typeBldr.CreateTypeInfo().AsType(); + typBaked = _typeBldr!.CreateTypeInfo()!.AsType(); // Replace all MethodInfos in this.methods methodsBaked = new Hashtable(_methods.Count); @@ -263,9 +262,9 @@ public void BakeMethods() public Delegate CreateDelegate(string name, Type typDelegate) { if (!_useLRE) - return ((MethodInfo)_methods[name]).CreateDelegate(typDelegate); + return ((MethodInfo)_methods[name]!).CreateDelegate(typDelegate); - return ((DynamicMethod)_methods[name]).CreateDelegate(typDelegate); + return ((DynamicMethod)_methods[name]!).CreateDelegate(typDelegate); } /// diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILOptimization.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILOptimization.cs index c00eb27ab8011..d7c7c6df808ea 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILOptimization.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILOptimization.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable namespace System.Xml.Xsl.IlGen { /// diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILOptimizerVisitor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILOptimizerVisitor.cs index 2461629a0e557..fbdcd37eb2000 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILOptimizerVisitor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILOptimizerVisitor.cs @@ -1,8 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Xml.Schema; using System.Xml.XPath; using System.Xml.Xsl.Qil; @@ -114,7 +116,7 @@ protected override QilNode Visit(QilNode nd) } // Continue visitation - return base.Visit(nd); + return base.Visit(nd!); } /// @@ -122,7 +124,7 @@ protected override QilNode Visit(QilNode nd) /// protected override QilNode VisitReference(QilNode oldNode) { - QilNode newNode = _subs.FindReplacement(oldNode); + QilNode? newNode = _subs.FindReplacement(oldNode); if (newNode == null) newNode = oldNode; @@ -133,7 +135,7 @@ protected override QilNode VisitReference(QilNode oldNode) { if (newNode.NodeType == QilNodeType.Let || newNode.NodeType == QilNodeType.For) { - QilNode binding = ((QilIterator)oldNode).Binding; + QilNode binding = ((QilIterator)oldNode).Binding!; if (IsLiteral(binding)) return Replace(XmlILOptimization.EliminateLiteralVariables, newNode, binding.ShallowClone(f)); @@ -141,11 +143,11 @@ protected override QilNode VisitReference(QilNode oldNode) } if (this[XmlILOptimization.EliminateUnusedGlobals]) { - if (IsGlobalValue(newNode)) - OptimizerPatterns.Write(newNode).AddPattern(OptimizerPatternName.IsReferenced); + if (IsGlobalValue(newNode!)) + OptimizerPatterns.Write(newNode!).AddPattern(OptimizerPatternName.IsReferenced); } - return base.VisitReference(newNode); + return base.VisitReference(newNode!); } /// @@ -167,7 +169,8 @@ protected QilNode Replace(XmlILOptimization pattern, QilNode original, QilNode r /// /// Called when all replacements have already been made and all annotations are complete. /// - protected override QilNode NoReplace(QilNode node) + [return: NotNullIfNotNull("node")] + protected override QilNode? NoReplace(QilNode? node) { // Calculate MaybeSideEffects pattern. This is done here rather than using P because every node needs // to compute it and P has no good way of matching every node type. @@ -252,12 +255,12 @@ protected override QilNode VisitQilExpression(QilExpression local0) if (IsConstructedExpression(ndFunc.Definition)) { // Perform state analysis on function's content - ndFunc.Definition = _contentAnalyzer.Analyze(ndFunc, ndFunc.Definition); + ndFunc.Definition = _contentAnalyzer.Analyze(ndFunc, ndFunc.Definition)!; } } // Perform state analysis on the root expression - local0.Root = _contentAnalyzer.Analyze(null, local0.Root); + local0.Root = _contentAnalyzer.Analyze(null, local0.Root)!; // Make sure that root expression is pushed to writer XmlILConstructInfo.Write(local0.Root).PushToWriterLast = true; @@ -289,7 +292,7 @@ protected override QilNode VisitDataSource(QilDataSource local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (DataSource $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -300,7 +303,7 @@ protected override QilNode VisitDataSource(QilDataSource local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (DataSource * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -331,7 +334,7 @@ protected override QilNode VisitError(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Error $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -348,7 +351,7 @@ protected override QilNode VisitWarning(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Warning $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -366,7 +369,7 @@ protected override QilNode VisitWarning(QilUnary local0) protected override QilNode VisitLet(QilIterator local0) { QilNode local1 = local0[0]; - if (((((local0).XmlType).IsSingleton) && (!(IsGlobalVariable(local0)))) && (this[XmlILOptimization.NormalizeSingletonLet])) + if (((((local0).XmlType)!.IsSingleton) && (!(IsGlobalVariable(local0)))) && (this[XmlILOptimization.NormalizeSingletonLet])) { // PATTERN: [NormalizeSingletonLet] $iter:(Let $bind:*) ^ (Single? (TypeOf $iter)) ^ ~((GlobalVariable? $iter)) => { ... } if (AllowReplace(XmlILOptimization.NormalizeSingletonLet, local0)) @@ -405,7 +408,7 @@ protected override QilNode VisitPositionOf(QilUnary local0) if (local1.NodeType == QilNodeType.For) { QilNode local2 = local1[0]; - if (((local2).XmlType).IsSingleton) + if (((local2).XmlType)!.IsSingleton) { // PATTERN: [EliminatePositionOf] (PositionOf (For $x:* ^ (Single? (TypeOf $x)))) => (LiteralInt32 1) if (AllowReplace(XmlILOptimization.EliminatePositionOf, local0)) @@ -438,7 +441,7 @@ protected override QilNode VisitAnd(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (And $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -449,7 +452,7 @@ protected override QilNode VisitAnd(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (And * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -511,7 +514,7 @@ protected override QilNode VisitOr(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Or $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -522,7 +525,7 @@ protected override QilNode VisitOr(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Or * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -583,7 +586,7 @@ protected override QilNode VisitNot(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Not $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -627,7 +630,7 @@ protected override QilNode VisitConditional(QilTernary local0) QilNode local3 = local0[2]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Conditional $x:* ^ (None? (TypeOf $x)) * *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -740,7 +743,7 @@ protected override QilNode VisitLength(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Length $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -765,7 +768,7 @@ protected override QilNode VisitLength(QilUnary local0) } if (this[XmlILOptimization.EliminateLength]) { - if ((((local1).XmlType).IsSingleton) && (!OptimizerPatterns.Read(local1).MatchesPattern(OptimizerPatternName.MaybeSideEffects))) + if ((((local1).XmlType)!.IsSingleton) && (!OptimizerPatterns.Read(local1).MatchesPattern(OptimizerPatternName.MaybeSideEffects))) { // PATTERN: [EliminateLength] (Length $x:* ^ (Single? (TypeOf $x)) ^ (NoSideEffects? $x)) => (LiteralInt32 1) if (AllowReplace(XmlILOptimization.EliminateLength, local0)) @@ -826,7 +829,7 @@ protected override QilNode VisitUnion(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Union $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -837,7 +840,7 @@ protected override QilNode VisitUnion(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Union * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -941,7 +944,7 @@ protected override QilNode VisitIntersection(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Intersection $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -952,7 +955,7 @@ protected override QilNode VisitIntersection(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Intersection * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1042,7 +1045,7 @@ protected override QilNode VisitDifference(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Difference $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1053,7 +1056,7 @@ protected override QilNode VisitDifference(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Difference * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1142,7 +1145,7 @@ protected override QilNode VisitAverage(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Average $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1153,7 +1156,7 @@ protected override QilNode VisitAverage(QilUnary local0) } if (this[XmlILOptimization.EliminateAverage]) { - if (((local1).XmlType).Cardinality == XmlQueryCardinality.Zero) + if (((local1).XmlType)!.Cardinality == XmlQueryCardinality.Zero) { // PATTERN: [EliminateAverage] (Average $x:* ^ (Empty? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.EliminateAverage, local0)) @@ -1170,7 +1173,7 @@ protected override QilNode VisitSum(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Sum $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1181,7 +1184,7 @@ protected override QilNode VisitSum(QilUnary local0) } if (this[XmlILOptimization.EliminateSum]) { - if (((local1).XmlType).Cardinality == XmlQueryCardinality.Zero) + if (((local1).XmlType)!.Cardinality == XmlQueryCardinality.Zero) { // PATTERN: [EliminateSum] (Sum $x:* ^ (Empty? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.EliminateSum, local0)) @@ -1198,7 +1201,7 @@ protected override QilNode VisitMinimum(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Minimum $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1209,7 +1212,7 @@ protected override QilNode VisitMinimum(QilUnary local0) } if (this[XmlILOptimization.EliminateMinimum]) { - if (((local1).XmlType).Cardinality == XmlQueryCardinality.Zero) + if (((local1).XmlType)!.Cardinality == XmlQueryCardinality.Zero) { // PATTERN: [EliminateMinimum] (Minimum $x:* ^ (Empty? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.EliminateMinimum, local0)) @@ -1226,7 +1229,7 @@ protected override QilNode VisitMaximum(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Maximum $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1237,7 +1240,7 @@ protected override QilNode VisitMaximum(QilUnary local0) } if (this[XmlILOptimization.EliminateMaximum]) { - if (((local1).XmlType).Cardinality == XmlQueryCardinality.Zero) + if (((local1).XmlType)!.Cardinality == XmlQueryCardinality.Zero) { // PATTERN: [EliminateMaximum] (Maximum $x:* ^ (Empty? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.EliminateMaximum, local0)) @@ -1257,7 +1260,7 @@ protected override QilNode VisitNegate(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Negate $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1270,7 +1273,7 @@ protected override QilNode VisitNegate(QilUnary local0) { if (local1.NodeType == QilNodeType.LiteralDecimal) { - decimal local2 = (decimal)((QilLiteral)local1).Value; + decimal local2 = (decimal)((QilLiteral)local1).Value!; // PATTERN: [EliminateNegate] (Negate (LiteralDecimal $x:*)) => (LiteralDecimal { -{$x} }) if (AllowReplace(XmlILOptimization.EliminateNegate, local0)) { @@ -1282,7 +1285,7 @@ protected override QilNode VisitNegate(QilUnary local0) { if (local1.NodeType == QilNodeType.LiteralDouble) { - double local2 = (double)((QilLiteral)local1).Value; + double local2 = (double)((QilLiteral)local1).Value!; // PATTERN: [EliminateNegate] (Negate (LiteralDouble $x:*)) => (LiteralDouble { -{$x} }) if (AllowReplace(XmlILOptimization.EliminateNegate, local0)) { @@ -1294,7 +1297,7 @@ protected override QilNode VisitNegate(QilUnary local0) { if (local1.NodeType == QilNodeType.LiteralInt32) { - int local2 = (int)((QilLiteral)local1).Value; + int local2 = (int)((QilLiteral)local1).Value!; // PATTERN: [EliminateNegate] (Negate (LiteralInt32 $x:*)) => (LiteralInt32 { -{$x} }) if (AllowReplace(XmlILOptimization.EliminateNegate, local0)) { @@ -1306,7 +1309,7 @@ protected override QilNode VisitNegate(QilUnary local0) { if (local1.NodeType == QilNodeType.LiteralInt64) { - long local2 = (long)((QilLiteral)local1).Value; + long local2 = (long)((QilLiteral)local1).Value!; // PATTERN: [EliminateNegate] (Negate (LiteralInt64 $x:*)) => (LiteralInt64 { -{$x} }) if (AllowReplace(XmlILOptimization.EliminateNegate, local0)) { @@ -1323,7 +1326,7 @@ protected override QilNode VisitAdd(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Add $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1334,7 +1337,7 @@ protected override QilNode VisitAdd(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Add * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1380,7 +1383,7 @@ protected override QilNode VisitSubtract(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Subtract $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1391,7 +1394,7 @@ protected override QilNode VisitSubtract(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Subtract * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1423,7 +1426,7 @@ protected override QilNode VisitMultiply(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Multiply $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1434,7 +1437,7 @@ protected override QilNode VisitMultiply(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Multiply * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1480,7 +1483,7 @@ protected override QilNode VisitDivide(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Divide $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1491,7 +1494,7 @@ protected override QilNode VisitDivide(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Divide * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1523,7 +1526,7 @@ protected override QilNode VisitModulo(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Modulo $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1534,7 +1537,7 @@ protected override QilNode VisitModulo(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Modulo * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1568,7 +1571,7 @@ protected override QilNode VisitStrLength(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (StrLength $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1581,7 +1584,7 @@ protected override QilNode VisitStrLength(QilUnary local0) { if (local1.NodeType == QilNodeType.LiteralString) { - string local2 = (string)((QilLiteral)local1).Value; + string local2 = (string)((QilLiteral)local1).Value!; // PATTERN: [EliminateStrLength] (StrLength (LiteralString $x:*)) => (LiteralInt32 { {$x}.Length }) if (AllowReplace(XmlILOptimization.EliminateStrLength, local0)) { @@ -1598,7 +1601,7 @@ protected override QilNode VisitStrConcat(QilStrConcat local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (StrConcat $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1609,7 +1612,7 @@ protected override QilNode VisitStrConcat(QilStrConcat local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (StrConcat * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1618,7 +1621,7 @@ protected override QilNode VisitStrConcat(QilStrConcat local0) } } } - if ((((local2).XmlType).IsSingleton) && (this[XmlILOptimization.EliminateStrConcatSingle])) + if ((((local2).XmlType)!.IsSingleton) && (this[XmlILOptimization.EliminateStrConcatSingle])) { // PATTERN: [EliminateStrConcatSingle] (StrConcat * $x:*) ^ (Single? (TypeOf $x)) => (Nop $x) if (AllowReplace(XmlILOptimization.EliminateStrConcatSingle, local0)) @@ -1630,7 +1633,7 @@ protected override QilNode VisitStrConcat(QilStrConcat local0) { if (local1.NodeType == QilNodeType.LiteralString) { - string local3 = (string)((QilLiteral)local1).Value; + string local3 = (string)((QilLiteral)local1).Value!; if (local2.NodeType == QilNodeType.Sequence) { if (AreLiteralArgs(local2)) @@ -1659,7 +1662,7 @@ protected override QilNode VisitStrParseQName(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (StrParseQName $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1670,7 +1673,7 @@ protected override QilNode VisitStrParseQName(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (StrParseQName * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1691,7 +1694,7 @@ protected override QilNode VisitNe(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Ne $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1702,7 +1705,7 @@ protected override QilNode VisitNe(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Ne * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1747,15 +1750,15 @@ protected override QilNode VisitNe(QilBinary local0) QilNode local4 = local1[1]; if (local4.NodeType == QilNodeType.LiteralType) { - XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value; + XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value!; if ((IsPrimitiveNumeric((local3).XmlType)) && (IsPrimitiveNumeric(local5))) { - if ((IsLiteral((local2))) && (CanFoldXsltConvertNonLossy(local2, (local3).XmlType))) + if ((IsLiteral((local2))) && (CanFoldXsltConvertNonLossy(local2, (local3).XmlType!))) { // PATTERN: [NormalizeXsltConvertNe] (Ne (XsltConvert $expr:* (LiteralType $typ:*)) ^ (PrimitiveNumeric? (TypeOf $expr)) ^ (PrimitiveNumeric? $typ) $lit:* ^ (Literal? $lit) ^ (CanFoldXsltConvertNonLossy? $lit (TypeOf $expr))) => (Ne $expr (FoldXsltConvert $lit (TypeOf $expr))) if (AllowReplace(XmlILOptimization.NormalizeXsltConvertNe, local0)) { - return Replace(XmlILOptimization.NormalizeXsltConvertNe, local0, VisitNe(f.Ne(local3, FoldXsltConvert(local2, (local3).XmlType)))); + return Replace(XmlILOptimization.NormalizeXsltConvertNe, local0, VisitNe(f.Ne(local3, FoldXsltConvert(local2, (local3).XmlType!)))); } } } @@ -1767,12 +1770,12 @@ protected override QilNode VisitNe(QilBinary local0) if (local1.NodeType == QilNodeType.XsltGenerateId) { QilNode local3 = local1[0]; - if (((local3).XmlType).IsSingleton) + if (((local3).XmlType)!.IsSingleton) { if (local2.NodeType == QilNodeType.XsltGenerateId) { QilNode local4 = local2[0]; - if (((local4).XmlType).IsSingleton) + if (((local4).XmlType)!.IsSingleton) { // PATTERN: [NormalizeIdNe] (Ne (XsltGenerateId $arg1:*) ^ (Single? (TypeOf $arg1)) (XsltGenerateId $arg2:*) ^ (Single? (TypeOf $arg2))) => (Not (Is $arg1 $arg2)) if (AllowReplace(XmlILOptimization.NormalizeIdNe, local0)) @@ -1791,7 +1794,7 @@ protected override QilNode VisitNe(QilBinary local0) QilNode local3 = local1[0]; if (local2.NodeType == QilNodeType.LiteralInt32) { - int local4 = (int)((QilLiteral)local2).Value; + int local4 = (int)((QilLiteral)local2).Value!; if (local4 == 0) { // PATTERN: [NormalizeLengthNe] (Ne (Length $expr:*) (LiteralInt32 0)) => (Not (IsEmpty $expr)) @@ -1809,7 +1812,7 @@ protected override QilNode VisitNe(QilBinary local0) { if (local2.NodeType == QilNodeType.LiteralInt32) { - int local4 = (int)((QilLiteral)local2).Value; + int local4 = (int)((QilLiteral)local2).Value!; // PATTERN: [AnnotateMaxLengthNe] (Ne $len:(Length *) (LiteralInt32 $num:*)) => (AddPattern $len {MaxPosition}) ^ (AddArgument $len {MaxPosition} $num) ^ { } if (AllowReplace(XmlILOptimization.AnnotateMaxLengthNe, local0)) { @@ -1827,7 +1830,7 @@ protected override QilNode VisitEq(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Eq $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1838,7 +1841,7 @@ protected override QilNode VisitEq(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Eq * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -1883,15 +1886,15 @@ protected override QilNode VisitEq(QilBinary local0) QilNode local4 = local1[1]; if (local4.NodeType == QilNodeType.LiteralType) { - XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value; + XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value!; if ((IsPrimitiveNumeric((local3).XmlType)) && (IsPrimitiveNumeric(local5))) { - if ((IsLiteral((local2))) && (CanFoldXsltConvertNonLossy(local2, (local3).XmlType))) + if ((IsLiteral((local2))) && (CanFoldXsltConvertNonLossy(local2, (local3).XmlType!))) { // PATTERN: [NormalizeXsltConvertEq] (Eq (XsltConvert $expr:* (LiteralType $typ:*)) ^ (PrimitiveNumeric? (TypeOf $expr)) ^ (PrimitiveNumeric? $typ) $lit:* ^ (Literal? $lit) ^ (CanFoldXsltConvertNonLossy? $lit (TypeOf $expr))) => (Eq $expr (FoldXsltConvert $lit (TypeOf $expr))) if (AllowReplace(XmlILOptimization.NormalizeXsltConvertEq, local0)) { - return Replace(XmlILOptimization.NormalizeXsltConvertEq, local0, VisitEq(f.Eq(local3, FoldXsltConvert(local2, (local3).XmlType)))); + return Replace(XmlILOptimization.NormalizeXsltConvertEq, local0, VisitEq(f.Eq(local3, FoldXsltConvert(local2, (local3).XmlType!)))); } } } @@ -1922,12 +1925,12 @@ protected override QilNode VisitEq(QilBinary local0) if (local1.NodeType == QilNodeType.XsltGenerateId) { QilNode local3 = local1[0]; - if (((local3).XmlType).IsSingleton) + if (((local3).XmlType)!.IsSingleton) { if (local2.NodeType == QilNodeType.XsltGenerateId) { QilNode local4 = local2[0]; - if (((local4).XmlType).IsSingleton) + if (((local4).XmlType)!.IsSingleton) { // PATTERN: [NormalizeIdEq] (Eq (XsltGenerateId $arg1:*) ^ (Single? (TypeOf $arg1)) (XsltGenerateId $arg2:*) ^ (Single? (TypeOf $arg2))) => (Is $arg1 $arg2) if (AllowReplace(XmlILOptimization.NormalizeIdEq, local0)) @@ -1944,7 +1947,7 @@ protected override QilNode VisitEq(QilBinary local0) if (local1.NodeType == QilNodeType.XsltGenerateId) { QilNode local3 = local1[0]; - if (((local3).XmlType).IsSingleton) + if (((local3).XmlType)!.IsSingleton) { if (local2.NodeType == QilNodeType.StrConcat) { @@ -1956,7 +1959,7 @@ protected override QilNode VisitEq(QilBinary local0) if (local6.NodeType == QilNodeType.For) { QilNode local7 = local6[0]; - if (!((local7).XmlType).MaybeMany) + if (!((local7).XmlType)!.MaybeMany) { if (local8.NodeType == QilNodeType.XsltGenerateId) { @@ -1990,7 +1993,7 @@ protected override QilNode VisitEq(QilBinary local0) if (local5.NodeType == QilNodeType.For) { QilNode local6 = local5[0]; - if (!((local6).XmlType).MaybeMany) + if (!((local6).XmlType)!.MaybeMany) { if (local7.NodeType == QilNodeType.XsltGenerateId) { @@ -2000,7 +2003,7 @@ protected override QilNode VisitEq(QilBinary local0) if (local2.NodeType == QilNodeType.XsltGenerateId) { QilNode local9 = local2[0]; - if (((local9).XmlType).IsSingleton) + if (((local9).XmlType)!.IsSingleton) { // PATTERN: [NormalizeIdEq] (Eq (StrConcat * (Loop $iter:(For $bind:* ^ (AtMostOne? (TypeOf $bind))) (XsltGenerateId $iter))) (XsltGenerateId $arg:*) ^ (Single? (TypeOf $arg))) => (Not (IsEmpty (Filter $iterNew:(For $bind) (Is $arg $iterNew)))) if (AllowReplace(XmlILOptimization.NormalizeIdEq, local0)) @@ -2026,11 +2029,11 @@ protected override QilNode VisitEq(QilBinary local0) { QilNode local4 = local3[0]; QilNode local5 = local3[1]; - if ((((local4).XmlType).IsSingleton) && (!((local5).XmlType).MaybeMany)) + if ((((local4).XmlType)!.IsSingleton) && (!((local5).XmlType)!.MaybeMany)) { if (local2.NodeType == QilNodeType.LiteralInt32) { - int local6 = (int)((QilLiteral)local2).Value; + int local6 = (int)((QilLiteral)local2).Value!; if (local6 == 1) { // PATTERN: [NormalizeMuenchian] (Eq (Length (Union $arg1:* $arg2:*) ^ (Single? (TypeOf $arg1)) ^ (AtMostOne? (TypeOf $arg2))) (LiteralInt32 1)) => (IsEmpty (Filter $iterNew:(For $arg2) (Not (Is $arg1 $iterNew)))) @@ -2054,11 +2057,11 @@ protected override QilNode VisitEq(QilBinary local0) { QilNode local4 = local3[0]; QilNode local5 = local3[1]; - if ((!((local4).XmlType).MaybeMany) && (((local5).XmlType).IsSingleton)) + if ((!((local4).XmlType)!.MaybeMany) && (((local5).XmlType)!.IsSingleton)) { if (local2.NodeType == QilNodeType.LiteralInt32) { - int local6 = (int)((QilLiteral)local2).Value; + int local6 = (int)((QilLiteral)local2).Value!; if (local6 == 1) { // PATTERN: [NormalizeMuenchian] (Eq (Length (Union $arg1:* $arg2:*) ^ (AtMostOne? (TypeOf $arg1)) ^ (Single? (TypeOf $arg2))) (LiteralInt32 1)) => (IsEmpty (Filter $iterNew:(For $arg1) (Not (Is $iterNew $arg2)))) @@ -2079,7 +2082,7 @@ protected override QilNode VisitEq(QilBinary local0) { if (local2.NodeType == QilNodeType.LiteralInt32) { - int local4 = (int)((QilLiteral)local2).Value; + int local4 = (int)((QilLiteral)local2).Value!; // PATTERN: [AnnotateMaxLengthEq] (Eq $len:(Length *) (LiteralInt32 $num:*)) => (AddPattern $len {MaxPosition}) ^ (AddArgument $len {MaxPosition} $num) ^ { } if (AllowReplace(XmlILOptimization.AnnotateMaxLengthEq, local0)) { @@ -2097,7 +2100,7 @@ protected override QilNode VisitGt(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Gt $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2108,7 +2111,7 @@ protected override QilNode VisitGt(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Gt * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2153,15 +2156,15 @@ protected override QilNode VisitGt(QilBinary local0) QilNode local4 = local1[1]; if (local4.NodeType == QilNodeType.LiteralType) { - XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value; + XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value!; if ((IsPrimitiveNumeric((local3).XmlType)) && (IsPrimitiveNumeric(local5))) { - if ((IsLiteral((local2))) && (CanFoldXsltConvertNonLossy(local2, (local3).XmlType))) + if ((IsLiteral((local2))) && (CanFoldXsltConvertNonLossy(local2, (local3).XmlType!))) { // PATTERN: [NormalizeXsltConvertGt] (Gt (XsltConvert $expr:* (LiteralType $typ:*)) ^ (PrimitiveNumeric? (TypeOf $expr)) ^ (PrimitiveNumeric? $typ) $lit:* ^ (Literal? $lit) ^ (CanFoldXsltConvertNonLossy? $lit (TypeOf $expr))) => (Gt $expr (FoldXsltConvert $lit (TypeOf $expr))) if (AllowReplace(XmlILOptimization.NormalizeXsltConvertGt, local0)) { - return Replace(XmlILOptimization.NormalizeXsltConvertGt, local0, VisitGt(f.Gt(local3, FoldXsltConvert(local2, (local3).XmlType)))); + return Replace(XmlILOptimization.NormalizeXsltConvertGt, local0, VisitGt(f.Gt(local3, FoldXsltConvert(local2, (local3).XmlType!)))); } } } @@ -2175,7 +2178,7 @@ protected override QilNode VisitGt(QilBinary local0) QilNode local3 = local1[0]; if (local2.NodeType == QilNodeType.LiteralInt32) { - int local4 = (int)((QilLiteral)local2).Value; + int local4 = (int)((QilLiteral)local2).Value!; if (local4 == 0) { // PATTERN: [NormalizeLengthGt] (Gt (Length $expr:*) (LiteralInt32 0)) => (Not (IsEmpty $expr)) @@ -2193,7 +2196,7 @@ protected override QilNode VisitGt(QilBinary local0) { if (local2.NodeType == QilNodeType.LiteralInt32) { - int local4 = (int)((QilLiteral)local2).Value; + int local4 = (int)((QilLiteral)local2).Value!; // PATTERN: [AnnotateMaxLengthGt] (Gt $len:(Length *) (LiteralInt32 $num:*)) => (AddPattern $len {MaxPosition}) ^ (AddArgument $len {MaxPosition} $num) ^ { } if (AllowReplace(XmlILOptimization.AnnotateMaxLengthGt, local0)) { @@ -2211,7 +2214,7 @@ protected override QilNode VisitGe(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Ge $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2222,7 +2225,7 @@ protected override QilNode VisitGe(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Ge * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2267,15 +2270,15 @@ protected override QilNode VisitGe(QilBinary local0) QilNode local4 = local1[1]; if (local4.NodeType == QilNodeType.LiteralType) { - XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value; + XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value!; if ((IsPrimitiveNumeric((local3).XmlType)) && (IsPrimitiveNumeric(local5))) { - if ((IsLiteral((local2))) && (CanFoldXsltConvertNonLossy(local2, (local3).XmlType))) + if ((IsLiteral((local2))) && (CanFoldXsltConvertNonLossy(local2, (local3).XmlType!))) { // PATTERN: [NormalizeXsltConvertGe] (Ge (XsltConvert $expr:* (LiteralType $typ:*)) ^ (PrimitiveNumeric? (TypeOf $expr)) ^ (PrimitiveNumeric? $typ) $lit:* ^ (Literal? $lit) ^ (CanFoldXsltConvertNonLossy? $lit (TypeOf $expr))) => (Ge $expr (FoldXsltConvert $lit (TypeOf $expr))) if (AllowReplace(XmlILOptimization.NormalizeXsltConvertGe, local0)) { - return Replace(XmlILOptimization.NormalizeXsltConvertGe, local0, VisitGe(f.Ge(local3, FoldXsltConvert(local2, (local3).XmlType)))); + return Replace(XmlILOptimization.NormalizeXsltConvertGe, local0, VisitGe(f.Ge(local3, FoldXsltConvert(local2, (local3).XmlType!)))); } } } @@ -2288,7 +2291,7 @@ protected override QilNode VisitGe(QilBinary local0) { if (local2.NodeType == QilNodeType.LiteralInt32) { - int local4 = (int)((QilLiteral)local2).Value; + int local4 = (int)((QilLiteral)local2).Value!; // PATTERN: [AnnotateMaxLengthGe] (Ge $len:(Length *) (LiteralInt32 $num:*)) => (AddPattern $len {MaxPosition}) ^ (AddArgument $len {MaxPosition} $num) ^ { } if (AllowReplace(XmlILOptimization.AnnotateMaxLengthGe, local0)) { @@ -2306,7 +2309,7 @@ protected override QilNode VisitLt(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Lt $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2317,7 +2320,7 @@ protected override QilNode VisitLt(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Lt * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2362,15 +2365,15 @@ protected override QilNode VisitLt(QilBinary local0) QilNode local4 = local1[1]; if (local4.NodeType == QilNodeType.LiteralType) { - XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value; + XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value!; if ((IsPrimitiveNumeric((local3).XmlType)) && (IsPrimitiveNumeric(local5))) { - if ((IsLiteral((local2))) && (CanFoldXsltConvertNonLossy(local2, (local3).XmlType))) + if ((IsLiteral((local2))) && (CanFoldXsltConvertNonLossy(local2, (local3).XmlType!))) { // PATTERN: [NormalizeXsltConvertLt] (Lt (XsltConvert $expr:* (LiteralType $typ:*)) ^ (PrimitiveNumeric? (TypeOf $expr)) ^ (PrimitiveNumeric? $typ) $lit:* ^ (Literal? $lit) ^ (CanFoldXsltConvertNonLossy? $lit (TypeOf $expr))) => (Lt $expr (FoldXsltConvert $lit (TypeOf $expr))) if (AllowReplace(XmlILOptimization.NormalizeXsltConvertLt, local0)) { - return Replace(XmlILOptimization.NormalizeXsltConvertLt, local0, VisitLt(f.Lt(local3, FoldXsltConvert(local2, (local3).XmlType)))); + return Replace(XmlILOptimization.NormalizeXsltConvertLt, local0, VisitLt(f.Lt(local3, FoldXsltConvert(local2, (local3).XmlType!)))); } } } @@ -2383,7 +2386,7 @@ protected override QilNode VisitLt(QilBinary local0) { if (local2.NodeType == QilNodeType.LiteralInt32) { - int local4 = (int)((QilLiteral)local2).Value; + int local4 = (int)((QilLiteral)local2).Value!; // PATTERN: [AnnotateMaxLengthLt] (Lt $len:(Length *) (LiteralInt32 $num:*)) => (AddPattern $len {MaxPosition}) ^ (AddArgument $len {MaxPosition} $num) ^ { } if (AllowReplace(XmlILOptimization.AnnotateMaxLengthLt, local0)) { @@ -2401,7 +2404,7 @@ protected override QilNode VisitLe(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Le $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2412,7 +2415,7 @@ protected override QilNode VisitLe(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Le * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2457,15 +2460,15 @@ protected override QilNode VisitLe(QilBinary local0) QilNode local4 = local1[1]; if (local4.NodeType == QilNodeType.LiteralType) { - XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value; + XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value!; if ((IsPrimitiveNumeric((local3).XmlType)) && (IsPrimitiveNumeric(local5))) { - if ((IsLiteral((local2))) && (CanFoldXsltConvertNonLossy(local2, (local3).XmlType))) + if ((IsLiteral((local2))) && (CanFoldXsltConvertNonLossy(local2, (local3).XmlType!))) { // PATTERN: [NormalizeXsltConvertLe] (Le (XsltConvert $expr:* (LiteralType $typ:*)) ^ (PrimitiveNumeric? (TypeOf $expr)) ^ (PrimitiveNumeric? $typ) $lit:* ^ (Literal? $lit) ^ (CanFoldXsltConvertNonLossy? $lit (TypeOf $expr))) => (Le $expr (FoldXsltConvert $lit (TypeOf $expr))) if (AllowReplace(XmlILOptimization.NormalizeXsltConvertLe, local0)) { - return Replace(XmlILOptimization.NormalizeXsltConvertLe, local0, VisitLe(f.Le(local3, FoldXsltConvert(local2, (local3).XmlType)))); + return Replace(XmlILOptimization.NormalizeXsltConvertLe, local0, VisitLe(f.Le(local3, FoldXsltConvert(local2, (local3).XmlType!)))); } } } @@ -2478,7 +2481,7 @@ protected override QilNode VisitLe(QilBinary local0) { if (local2.NodeType == QilNodeType.LiteralInt32) { - int local4 = (int)((QilLiteral)local2).Value; + int local4 = (int)((QilLiteral)local2).Value!; // PATTERN: [AnnotateMaxLengthLe] (Le $len:(Length *) (LiteralInt32 $num:*)) => (AddPattern $len {MaxPosition}) ^ (AddArgument $len {MaxPosition} $num) ^ { } if (AllowReplace(XmlILOptimization.AnnotateMaxLengthLe, local0)) { @@ -2499,7 +2502,7 @@ protected override QilNode VisitIs(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Is $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2510,7 +2513,7 @@ protected override QilNode VisitIs(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Is * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2539,7 +2542,7 @@ protected override QilNode VisitAfter(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (After $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2550,7 +2553,7 @@ protected override QilNode VisitAfter(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (After * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2579,7 +2582,7 @@ protected override QilNode VisitBefore(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Before $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2590,7 +2593,7 @@ protected override QilNode VisitBefore(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Before * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2622,7 +2625,7 @@ protected override QilNode VisitLoop(QilLoop local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Loop $i:* ^ (None? (TypeOf $i)) *) => (Nop (First $i)) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2700,7 +2703,7 @@ protected override QilNode VisitLoop(QilLoop local0) if (local1.NodeType == QilNodeType.For) { QilNode local3 = local1[0]; - if (((local3).XmlType).IsSingleton) + if (((local3).XmlType!).IsSingleton) { if (local2.NodeType == QilNodeType.TextCtor) { @@ -2716,7 +2719,7 @@ protected override QilNode VisitLoop(QilLoop local0) } if (this[XmlILOptimization.EliminateIteratorUsedAtMostOnce]) { - if ((((local1).NodeType == QilNodeType.Let) || ((((QilNode)(local1)[0]).XmlType).IsSingleton)) && (!OptimizerPatterns.Read(local1).MatchesPattern(OptimizerPatternName.MaybeSideEffects))) + if ((((local1).NodeType == QilNodeType.Let) || ((((QilNode)(local1)[0]).XmlType!).IsSingleton)) && (!OptimizerPatterns.Read(local1).MatchesPattern(OptimizerPatternName.MaybeSideEffects))) { if (_nodeCounter.Count(local2, local1) <= 1) { @@ -2854,7 +2857,7 @@ protected override QilNode VisitLoop(QilLoop local0) if (local1.NodeType == QilNodeType.For) { QilNode local3 = local1[0]; - if (!((local3).XmlType).MaybeMany) + if (!((local3).XmlType!).MaybeMany) { // PATTERN: [AnnotateSingletonLoop] $outer:(Loop (For $bind:* ^ (AtMostOne? (TypeOf $bind))) $ret:*) => (InheritPattern $outer $ret {IsDocOrderDistinct}) ^ (InheritPattern $outer $ret {SameDepth}) ^ { } if (AllowReplace(XmlILOptimization.AnnotateSingletonLoop, local0)) @@ -2935,7 +2938,7 @@ protected override QilNode VisitFilter(QilLoop local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Filter $i:* ^ (None? (TypeOf $i)) *) => (Nop (First $i)) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -2946,7 +2949,7 @@ protected override QilNode VisitFilter(QilLoop local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Filter $i:* $w:* ^ (None? (TypeOf $w))) => (Loop $i $w) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -3000,7 +3003,7 @@ protected override QilNode VisitFilter(QilLoop local0) { if (local7.NodeType == QilNodeType.LiteralType) { - XmlQueryType local8 = (XmlQueryType)((QilLiteral)local7).Value; + XmlQueryType local8 = (XmlQueryType)((QilLiteral)local7).Value!; if ((local8) == (XmlQueryTypeFactory.Attribute)) { if (local9.NodeType == QilNodeType.Eq) @@ -3079,7 +3082,7 @@ protected override QilNode VisitFilter(QilLoop local0) { if (local5.NodeType == QilNodeType.LiteralInt32) { - int local6 = (int)((QilLiteral)local5).Value; + int local6 = (int)((QilLiteral)local5).Value!; // PATTERN: [AnnotateMaxPositionEq] $outer:(Filter $iter:* (Eq (PositionOf $iter) (LiteralInt32 $num:*))) => (AddPattern $iter {MaxPosition}) ^ (AddArgument $iter {MaxPosition} $num) ^ { } if (AllowReplace(XmlILOptimization.AnnotateMaxPositionEq, local0)) { @@ -3103,7 +3106,7 @@ protected override QilNode VisitFilter(QilLoop local0) { if (local5.NodeType == QilNodeType.LiteralInt32) { - int local6 = (int)((QilLiteral)local5).Value; + int local6 = (int)((QilLiteral)local5).Value!; // PATTERN: [AnnotateMaxPositionLe] $outer:(Filter $iter:* (Le (PositionOf $iter) (LiteralInt32 $num:*))) => (AddPattern $iter {MaxPosition}) ^ (AddArgument $iter {MaxPosition} $num) ^ { } if (AllowReplace(XmlILOptimization.AnnotateMaxPositionLe, local0)) { @@ -3127,7 +3130,7 @@ protected override QilNode VisitFilter(QilLoop local0) { if (local5.NodeType == QilNodeType.LiteralInt32) { - int local6 = (int)((QilLiteral)local5).Value; + int local6 = (int)((QilLiteral)local5).Value!; // PATTERN: [AnnotateMaxPositionLt] $outer:(Filter $iter:* (Lt (PositionOf $iter) (LiteralInt32 $num:*))) => (AddPattern $iter {MaxPosition}) ^ (AddArgument $iter {MaxPosition} { {$num} - 1 }) ^ { } if (AllowReplace(XmlILOptimization.AnnotateMaxPositionLt, local0)) { @@ -3169,7 +3172,7 @@ protected override QilNode VisitFilter(QilLoop local0) { if (local6.NodeType == QilNodeType.LiteralType) { - XmlQueryType local7 = (XmlQueryType)((QilLiteral)local6).Value; + XmlQueryType local7 = (XmlQueryType)((QilLiteral)local6).Value!; if ((local7) == (XmlQueryTypeFactory.Element)) { if (local8.NodeType == QilNodeType.Eq) @@ -3215,7 +3218,7 @@ protected override QilNode VisitFilter(QilLoop local0) { if (local5.NodeType == QilNodeType.LiteralType) { - XmlQueryType local6 = (XmlQueryType)((QilLiteral)local5).Value; + XmlQueryType local6 = (XmlQueryType)((QilLiteral)local5).Value!; if (MatchesContentTest(local6)) { // PATTERN: [AnnotateFilterContentKind] $outer:(Filter $iter:(For $bind:* ^ (Pattern? $bind {Axis})) (IsType $iter (LiteralType $kind:* ^ (ContentTest? $kind)))) => (AddPattern $outer {FilterContentKind}) ^ (AddArgument $outer {KindTestType} $kind) ^ { } @@ -3245,7 +3248,7 @@ protected override QilNode VisitFilter(QilLoop local0) { if (local6.NodeType == QilNodeType.LiteralType) { - XmlQueryType local7 = (XmlQueryType)((QilLiteral)local6).Value; + XmlQueryType local7 = (XmlQueryType)((QilLiteral)local6).Value!; if ((local7) == (XmlQueryTypeFactory.Attribute)) { // PATTERN: [AnnotateFilterAttributeKind] $outer:(Filter $iter:(For (Content *)) (IsType $iter (LiteralType $kind:*) ^ (Equal? $kind (ConstructType {Attribute})))) => (AddPattern $outer {FilterAttributeKind}) ^ { } @@ -3272,7 +3275,7 @@ protected override QilNode VisitSort(QilLoop local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Sort $i:* ^ (None? (TypeOf $i)) *) => (Nop (First $i)) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -3286,7 +3289,7 @@ protected override QilNode VisitSort(QilLoop local0) if (local1.NodeType == QilNodeType.For) { QilNode local3 = local1[0]; - if (((local3).XmlType).IsSingleton) + if (((local3).XmlType)!.IsSingleton) { // PATTERN: [EliminateSort] (Sort (For $bind:* ^ (Single? (TypeOf $bind))) *) => (Nop $bind) if (AllowReplace(XmlILOptimization.EliminateSort, local0)) @@ -3311,7 +3314,7 @@ protected override QilNode VisitSortKey(QilSortKey local0) QilNode local4 = local1[1]; if (local4.NodeType == QilNodeType.LiteralType) { - XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value; + XmlQueryType local5 = (XmlQueryType)((QilLiteral)local4).Value!; if ((((local3).XmlType) == (XmlQueryTypeFactory.IntX)) && ((local5) == (XmlQueryTypeFactory.DoubleX))) { // PATTERN: [NormalizeSortXsltConvert] (SortKey (XsltConvert $expr:* (LiteralType $typ:*)) ^ (Equal? (TypeOf $expr) (ConstructType {IntX})) ^ (Equal? $typ (ConstructType {DoubleX})) $coll:*) => (SortKey $expr $coll) @@ -3331,7 +3334,7 @@ protected override QilNode VisitDocOrderDistinct(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (DocOrderDistinct $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -3483,7 +3486,7 @@ protected override QilNode VisitDocOrderDistinct(QilUnary local0) QilNode local3 = local2[0]; if (!(IsDocOrderDistinct(local3))) { - if ((!OptimizerPatterns.Read(local2).MatchesPattern(OptimizerPatternName.IsPositional)) && ((local3).XmlType.IsSubtypeOf(XmlQueryTypeFactory.NodeNotRtfS))) + if ((!OptimizerPatterns.Read(local2).MatchesPattern(OptimizerPatternName.IsPositional)) && ((local3).XmlType!.IsSubtypeOf(XmlQueryTypeFactory.NodeNotRtfS))) { if (((!(OptimizerPatterns.Read((QilNode)(local1)).MatchesPattern(OptimizerPatternName.FilterElements))) && (!(OptimizerPatterns.Read((QilNode)(local1)).MatchesPattern(OptimizerPatternName.FilterContentKind)))) && (!(OptimizerPatterns.Read((QilNode)(local1)).MatchesPattern(OptimizerPatternName.FilterAttributeKind)))) { @@ -3606,10 +3609,10 @@ protected override QilNode VisitFunction(QilFunction local0) QilNode local1 = local0[0]; QilNode local2 = local0[1]; QilNode local3 = local0[2]; - XmlQueryType local4 = (XmlQueryType)((QilFunction)local0).XmlType; - if (((local0).XmlType.IsSubtypeOf(XmlQueryTypeFactory.NodeS)) && (this[XmlILOptimization.AnnotateIndex1])) + XmlQueryType? local4 = (XmlQueryType?)((QilFunction)local0).XmlType; + if (((local0).XmlType!.IsSubtypeOf(XmlQueryTypeFactory.NodeS)) && (this[XmlILOptimization.AnnotateIndex1])) { - if (((local1.Count == 2) && (((QilNode)(local1)[0]).XmlType.IsSubtypeOf(XmlQueryTypeFactory.Node))) && ((((QilNode)(local1)[1]).XmlType) == (XmlQueryTypeFactory.StringX))) + if (((local1.Count == 2) && (((QilNode)(local1)[0]).XmlType!.IsSubtypeOf(XmlQueryTypeFactory.Node))) && ((((QilNode)(local1)[1]).XmlType) == (XmlQueryTypeFactory.StringX))) { if (local2.NodeType == QilNodeType.Filter) { @@ -3778,7 +3781,7 @@ protected override QilNode VisitContent(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Content $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -3804,7 +3807,7 @@ protected override QilNode VisitAttribute(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Attribute $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -3815,7 +3818,7 @@ protected override QilNode VisitAttribute(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Attribute * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -3840,7 +3843,7 @@ protected override QilNode VisitParent(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Parent $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -3865,7 +3868,7 @@ protected override QilNode VisitRoot(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Root $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -3890,7 +3893,7 @@ protected override QilNode VisitDescendant(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Descendant $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -3915,7 +3918,7 @@ protected override QilNode VisitDescendantOrSelf(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (DescendantOrSelf $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -3940,7 +3943,7 @@ protected override QilNode VisitAncestor(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Ancestor $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -3965,7 +3968,7 @@ protected override QilNode VisitAncestorOrSelf(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (AncestorOrSelf $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -3990,7 +3993,7 @@ protected override QilNode VisitPreceding(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Preceding $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4015,7 +4018,7 @@ protected override QilNode VisitFollowingSibling(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (FollowingSibling $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4040,7 +4043,7 @@ protected override QilNode VisitPrecedingSibling(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (PrecedingSibling $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4066,7 +4069,7 @@ protected override QilNode VisitNodeRange(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (NodeRange $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4077,7 +4080,7 @@ protected override QilNode VisitNodeRange(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (NodeRange * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4103,7 +4106,7 @@ protected override QilNode VisitDeref(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Deref $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4114,7 +4117,7 @@ protected override QilNode VisitDeref(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (Deref * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4135,7 +4138,7 @@ protected override QilNode VisitElementCtor(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (ElementCtor $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4146,7 +4149,7 @@ protected override QilNode VisitElementCtor(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (ElementCtor * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4162,7 +4165,7 @@ protected override QilNode VisitElementCtor(QilBinary local0) { // The analysis occasionally makes small changes to the content of constructors, which is // why the result of Analyze is assigned to $ctor.Right. - local0.Right = _elemAnalyzer.Analyze(local0, local2); + local0.Right = _elemAnalyzer.Analyze(local0, local2)!; } } return NoReplace(local0); @@ -4174,7 +4177,7 @@ protected override QilNode VisitAttributeCtor(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (AttributeCtor $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4185,7 +4188,7 @@ protected override QilNode VisitAttributeCtor(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (AttributeCtor * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4199,7 +4202,7 @@ protected override QilNode VisitAttributeCtor(QilBinary local0) // PATTERN: [AnnotateConstruction] $ctor:(AttributeCtor * $content:*) => { ... } if (AllowReplace(XmlILOptimization.AnnotateConstruction, local0)) { - local0.Right = _contentAnalyzer.Analyze(local0, local2); + local0.Right = _contentAnalyzer.Analyze(local0, local2)!; } } return NoReplace(local0); @@ -4210,7 +4213,7 @@ protected override QilNode VisitCommentCtor(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (CommentCtor $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4224,7 +4227,7 @@ protected override QilNode VisitCommentCtor(QilUnary local0) // PATTERN: [AnnotateConstruction] $ctor:(CommentCtor $content:*) => { ... } if (AllowReplace(XmlILOptimization.AnnotateConstruction, local0)) { - local0.Child = _contentAnalyzer.Analyze(local0, local1); + local0.Child = _contentAnalyzer.Analyze(local0, local1)!; } } return NoReplace(local0); @@ -4236,7 +4239,7 @@ protected override QilNode VisitPICtor(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (PICtor $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4247,7 +4250,7 @@ protected override QilNode VisitPICtor(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (PICtor * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4261,7 +4264,7 @@ protected override QilNode VisitPICtor(QilBinary local0) // PATTERN: [AnnotateConstruction] $ctor:(PICtor * $content:*) => { ... } if (AllowReplace(XmlILOptimization.AnnotateConstruction, local0)) { - local0.Right = _contentAnalyzer.Analyze(local0, local2); + local0.Right = _contentAnalyzer.Analyze(local0, local2)!; } } return NoReplace(local0); @@ -4272,7 +4275,7 @@ protected override QilNode VisitTextCtor(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (TextCtor $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4297,7 +4300,7 @@ protected override QilNode VisitRawTextCtor(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (RawTextCtor $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4322,7 +4325,7 @@ protected override QilNode VisitDocumentCtor(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (DocumentCtor $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4336,7 +4339,7 @@ protected override QilNode VisitDocumentCtor(QilUnary local0) // PATTERN: [AnnotateConstruction] $ctor:(DocumentCtor $content:*) => { ... } if (AllowReplace(XmlILOptimization.AnnotateConstruction, local0)) { - local0.Child = _contentAnalyzer.Analyze(local0, local1); + local0.Child = _contentAnalyzer.Analyze(local0, local1)!; } } return NoReplace(local0); @@ -4348,7 +4351,7 @@ protected override QilNode VisitNamespaceDecl(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (NamespaceDecl $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4359,7 +4362,7 @@ protected override QilNode VisitNamespaceDecl(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (NamespaceDecl * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4393,7 +4396,7 @@ protected override QilNode VisitRtfCtor(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (RtfCtor $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4407,7 +4410,7 @@ protected override QilNode VisitRtfCtor(QilBinary local0) // PATTERN: [AnnotateConstruction] $ctor:(RtfCtor $content:* *) => { ... } if (AllowReplace(XmlILOptimization.AnnotateConstruction, local0)) { - local0.Left = _contentAnalyzer.Analyze(local0, local1); + local0.Left = _contentAnalyzer.Analyze(local0, local1)!; } } if (this[XmlILOptimization.AnnotateSingleTextRtf]) @@ -4435,7 +4438,7 @@ protected override QilNode VisitNameOf(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (NameOf $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4452,7 +4455,7 @@ protected override QilNode VisitLocalNameOf(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (LocalNameOf $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4469,7 +4472,7 @@ protected override QilNode VisitNamespaceUriOf(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (NamespaceUriOf $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4486,7 +4489,7 @@ protected override QilNode VisitPrefixOf(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (PrefixOf $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4507,7 +4510,7 @@ protected override QilNode VisitTypeAssert(QilTargetType local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (TypeAssert $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4520,8 +4523,8 @@ protected override QilNode VisitTypeAssert(QilTargetType local0) { if (local2.NodeType == QilNodeType.LiteralType) { - XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value; - if ((local1).XmlType.NeverSubtypeOf(local3)) + XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value!; + if ((local1).XmlType!.NeverSubtypeOf(local3)) { // PATTERN: [EliminateTypeAssert] (TypeAssert $opnd:* (LiteralType $typ:*) ^ (NeverSubtypeOf? (TypeOf $opnd) $typ)) => (Error (LiteralString "")) if (AllowReplace(XmlILOptimization.EliminateTypeAssert, local0)) @@ -4535,8 +4538,8 @@ protected override QilNode VisitTypeAssert(QilTargetType local0) { if (local2.NodeType == QilNodeType.LiteralType) { - XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value; - if ((local1).XmlType.Prime.NeverSubtypeOf(local3.Prime)) + XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value!; + if ((local1).XmlType!.Prime.NeverSubtypeOf(local3.Prime)) { // PATTERN: [EliminateTypeAssert] (TypeAssert $opnd:* (LiteralType $typ:*) ^ (NeverSubtypeOf? (Prime (TypeOf $opnd)) (Prime $typ))) => (Conditional (IsEmpty $opnd) (Sequence) (Error (LiteralString ""))) if (AllowReplace(XmlILOptimization.EliminateTypeAssert, local0)) @@ -4550,8 +4553,8 @@ protected override QilNode VisitTypeAssert(QilTargetType local0) { if (local2.NodeType == QilNodeType.LiteralType) { - XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value; - if ((local1).XmlType.IsSubtypeOf(local3)) + XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value!; + if ((local1).XmlType!.IsSubtypeOf(local3)) { // PATTERN: [EliminateTypeAssertOptional] (TypeAssert $opnd:* (LiteralType $base:*) ^ (SubtypeOf? (TypeOf $opnd) $base)) => $opnd if (AllowReplace(XmlILOptimization.EliminateTypeAssertOptional, local0)) @@ -4570,7 +4573,7 @@ protected override QilNode VisitIsType(QilTargetType local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (IsType $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4585,8 +4588,8 @@ protected override QilNode VisitIsType(QilTargetType local0) { if (local2.NodeType == QilNodeType.LiteralType) { - XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value; - if ((local1).XmlType.IsSubtypeOf(local3)) + XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value!; + if ((local1).XmlType!.IsSubtypeOf(local3)) { // PATTERN: [EliminateIsType] (IsType $opnd:* ^ (NoSideEffects? $opnd) (LiteralType $base:*) ^ (SubtypeOf? (TypeOf $opnd) $base)) => (True) if (AllowReplace(XmlILOptimization.EliminateIsType, local0)) @@ -4603,8 +4606,8 @@ protected override QilNode VisitIsType(QilTargetType local0) { if (local2.NodeType == QilNodeType.LiteralType) { - XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value; - if ((local1).XmlType.NeverSubtypeOf(local3)) + XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value!; + if ((local1).XmlType!.NeverSubtypeOf(local3)) { // PATTERN: [EliminateIsType] (IsType $opnd:* ^ (NoSideEffects? $opnd) (LiteralType $typ:*) ^ (NeverSubtypeOf? (TypeOf $opnd) $typ)) => (False) if (AllowReplace(XmlILOptimization.EliminateIsType, local0)) @@ -4619,8 +4622,8 @@ protected override QilNode VisitIsType(QilTargetType local0) { if (local2.NodeType == QilNodeType.LiteralType) { - XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value; - if ((local1).XmlType.Prime.NeverSubtypeOf(local3.Prime)) + XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value!; + if ((local1).XmlType!.Prime.NeverSubtypeOf(local3.Prime)) { // PATTERN: [EliminateIsType] (IsType $opnd:* (LiteralType $typ:*) ^ (NeverSubtypeOf? (Prime (TypeOf $opnd)) (Prime $typ))) => (IsEmpty $opnd) if (AllowReplace(XmlILOptimization.EliminateIsType, local0)) @@ -4636,8 +4639,8 @@ protected override QilNode VisitIsType(QilTargetType local0) { if (local2.NodeType == QilNodeType.LiteralType) { - XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value; - if ((local1).XmlType.IsSubtypeOf(local3)) + XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value!; + if ((local1).XmlType!.IsSubtypeOf(local3)) { // PATTERN: [EliminateIsType] (IsType $opnd:* ^ ~((NoSideEffects? $opnd)) (LiteralType $base:*) ^ (SubtypeOf? (TypeOf $opnd) $base)) => (Loop (Let $opnd) (True)) if (AllowReplace(XmlILOptimization.EliminateIsType, local0)) @@ -4654,8 +4657,8 @@ protected override QilNode VisitIsType(QilTargetType local0) { if (local2.NodeType == QilNodeType.LiteralType) { - XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value; - if ((local1).XmlType.NeverSubtypeOf(local3)) + XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value!; + if ((local1).XmlType!.NeverSubtypeOf(local3)) { // PATTERN: [EliminateIsType] (IsType $opnd:* ^ ~((NoSideEffects? $opnd)) (LiteralType $typ:*) ^ (NeverSubtypeOf? (TypeOf $opnd) $typ)) => (Loop (Let $opnd) (False)) if (AllowReplace(XmlILOptimization.EliminateIsType, local0)) @@ -4674,7 +4677,7 @@ protected override QilNode VisitIsEmpty(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (IsEmpty $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4699,7 +4702,7 @@ protected override QilNode VisitIsEmpty(QilUnary local0) } if (this[XmlILOptimization.EliminateIsEmpty]) { - if ((!((local1).XmlType).MaybeEmpty) && (!OptimizerPatterns.Read(local1).MatchesPattern(OptimizerPatternName.MaybeSideEffects))) + if ((!((local1).XmlType)!.MaybeEmpty) && (!OptimizerPatterns.Read(local1).MatchesPattern(OptimizerPatternName.MaybeSideEffects))) { // PATTERN: [EliminateIsEmpty] (IsEmpty $expr:* ^ (NonEmpty? (TypeOf $expr)) ^ (NoSideEffects? $expr)) => (False) if (AllowReplace(XmlILOptimization.EliminateIsEmpty, local0)) @@ -4710,7 +4713,7 @@ protected override QilNode VisitIsEmpty(QilUnary local0) } if (this[XmlILOptimization.EliminateIsEmpty]) { - if (!((local1).XmlType).MaybeEmpty) + if (!((local1).XmlType)!.MaybeEmpty) { // PATTERN: [EliminateIsEmpty] (IsEmpty $expr:* ^ (NonEmpty? (TypeOf $expr))) => (Loop (Let $expr) (False)) if (AllowReplace(XmlILOptimization.EliminateIsEmpty, local0)) @@ -4730,7 +4733,7 @@ protected override QilNode VisitXPathNodeValue(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (XPathNodeValue $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4747,7 +4750,7 @@ protected override QilNode VisitXPathFollowing(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (XPathFollowing $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4772,7 +4775,7 @@ protected override QilNode VisitXPathPreceding(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (XPathPreceding $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4797,7 +4800,7 @@ protected override QilNode VisitXPathNamespace(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (XPathNamespace $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4825,7 +4828,7 @@ protected override QilNode VisitXsltGenerateId(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (XsltGenerateId $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4843,7 +4846,7 @@ protected override QilNode VisitXsltCopy(QilBinary local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (XsltCopy $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4854,7 +4857,7 @@ protected override QilNode VisitXsltCopy(QilBinary local0) } if (this[XmlILOptimization.FoldNone]) { - if ((object)((local2).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local2).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (XsltCopy * $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4868,7 +4871,7 @@ protected override QilNode VisitXsltCopy(QilBinary local0) // PATTERN: [AnnotateConstruction] $ctor:(XsltCopy * $content:*) => { ... } if (AllowReplace(XmlILOptimization.AnnotateConstruction, local0)) { - local0.Right = _contentAnalyzer.Analyze(local0, local2); + local0.Right = _contentAnalyzer.Analyze(local0, local2)!; } } return NoReplace(local0); @@ -4879,7 +4882,7 @@ protected override QilNode VisitXsltCopyOf(QilUnary local0) QilNode local1 = local0[0]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (XsltCopyOf $x:* ^ (None? (TypeOf $x))) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4905,7 +4908,7 @@ protected override QilNode VisitXsltConvert(QilTargetType local0) QilNode local2 = local0[1]; if (this[XmlILOptimization.FoldNone]) { - if ((object)((local1).XmlType) == (object)XmlQueryTypeFactory.None) + if ((object?)((local1).XmlType) == (object)XmlQueryTypeFactory.None) { // PATTERN: [FoldNone] (XsltConvert $x:* ^ (None? (TypeOf $x)) *) => (Nop $x) if (AllowReplace(XmlILOptimization.FoldNone, local0)) @@ -4920,7 +4923,7 @@ protected override QilNode VisitXsltConvert(QilTargetType local0) { if (local2.NodeType == QilNodeType.LiteralType) { - XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value; + XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value!; if (CanFoldXsltConvert(local1, local3)) { // PATTERN: [FoldXsltConvertLiteral] (XsltConvert $lit:* ^ (Literal? $lit) (LiteralType $typ:*) ^ (CanFoldXsltConvert? $lit $typ)) => (FoldXsltConvert $lit $typ) @@ -4936,7 +4939,7 @@ protected override QilNode VisitXsltConvert(QilTargetType local0) { if (local2.NodeType == QilNodeType.LiteralType) { - XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value; + XmlQueryType local3 = (XmlQueryType)((QilLiteral)local2).Value!; if (((local1).XmlType) == (local3)) { // PATTERN: [EliminateXsltConvert] (XsltConvert $expr:* (LiteralType $typ:*) ^ (Equal? (TypeOf $expr) $typ)) => $expr @@ -4964,7 +4967,7 @@ private bool this[XmlILOptimization ann] private class NodeCounter : QilVisitor { - protected QilNode target; + protected QilNode? target; protected int cnt; /// @@ -4981,7 +4984,7 @@ public int Count(QilNode expr, QilNode target) protected override QilNode Visit(QilNode n) { if (n == null) - return null; + return null!; if (n == this.target) this.cnt++; @@ -5001,7 +5004,7 @@ protected override QilNode VisitReference(QilNode n) private class NodeFinder : QilVisitor { protected bool result; - protected QilNode target, parent; + protected QilNode? target, parent; /// /// Returns true if "target" node exists within the subtree of "expr". @@ -5027,7 +5030,7 @@ protected override QilNode Visit(QilNode expr) if (!this.result) { - QilNode parentOld = this.parent; + QilNode? parentOld = this.parent; this.parent = expr; VisitChildren(expr); this.parent = parentOld; @@ -5071,7 +5074,7 @@ protected override bool OnFound(QilNode expr) private class EqualityIndexVisitor : QilVisitor { protected bool result; - protected QilNode ctxt, key; + protected QilNode? ctxt, key; /// /// Returns true if the subtree of "expr" meets the following requirements: @@ -5173,7 +5176,7 @@ private bool IsGlobalValue(QilNode nd) /// /// Return true if "typ" is xs:decimal=, xs:integer=, xs:int=, xs:double=, or xs:float=. /// - private bool IsPrimitiveNumeric(XmlQueryType typ) + private bool IsPrimitiveNumeric(XmlQueryType? typ) { if (typ == XmlQueryTypeFactory.IntX) return true; if (typ == XmlQueryTypeFactory.IntegerX) return true; @@ -5212,7 +5215,7 @@ private bool IsConstructedExpression(QilNode nd) if (_qil.IsDebug) return true; - if (nd.XmlType.IsNode) + if (nd.XmlType!.IsNode) { switch (nd.NodeType) { @@ -5252,7 +5255,7 @@ private bool IsConstructedExpression(QilNode nd) case QilNodeType.Invoke: // Return true if the function might return nodes - return !((QilInvoke)nd).Function.XmlType.IsAtomicValue; + return !((QilInvoke)nd).Function.XmlType!.IsAtomicValue; } } @@ -5304,7 +5307,7 @@ private object ExtractLiteralValue(QilNode nd) return nd; Debug.Assert(nd is QilLiteral, "All literals except True, False, and QName must use QilLiteral"); - return ((QilLiteral)nd).Value; + return ((QilLiteral)nd).Value!; } /// @@ -5386,7 +5389,7 @@ private bool CanFoldXsltConvertNonLossy(QilNode ndLiteral, XmlQueryType typTarge return false; // Convert back to source type; if conversion cannot be folded, a XsltConvert node is returned - ndDest = FoldXsltConvert(ndDest, ndLiteral.XmlType); + ndDest = FoldXsltConvert(ndDest, ndLiteral.XmlType!); if (ndDest.NodeType == QilNodeType.XsltConvert) return false; @@ -5406,7 +5409,7 @@ private QilNode FoldXsltConvert(QilNode ndLiteral, XmlQueryType typTarget) if (typTarget.IsAtomicValue) { // Convert the literal to an XmlAtomicValue - XmlAtomicValue value = new XmlAtomicValue(ndLiteral.XmlType.SchemaType, ExtractLiteralValue(ndLiteral)); + XmlAtomicValue value = new XmlAtomicValue(ndLiteral.XmlType!.SchemaType, ExtractLiteralValue(ndLiteral)); value = XsltConvert.ConvertToType(value, typTarget); if (typTarget == XmlQueryTypeFactory.StringX) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILTrace.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILTrace.cs index 741140b2d1494..7a8e9819bf40a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILTrace.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILTrace.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.IO; using System.Security; @@ -24,7 +25,7 @@ internal static class XmlILTrace /// Check environment variable in order to determine whether to write out trace files. This really should be a /// check of the configuration file, but System.Xml does not yet have a good tracing story. /// - private static volatile string s_dirName; + private static volatile string? s_dirName; private static volatile bool s_alreadyCheckedEnabled; /// @@ -71,7 +72,7 @@ public static void PrepareTraceWriter(string fileName) /// If tracing is enabled, this method will open a TextWriter over "fileName" and return it. Otherwise, /// null will be returned. /// - public static TextWriter GetTraceWriter(string fileName) + public static TextWriter? GetTraceWriter(string fileName) { if (!IsEnabled) return null; @@ -165,7 +166,7 @@ private static void WriteQil(QilExpression qil, XmlWriter w) /// /// Serialize rewritten Qil tree to writer "w". /// - private static void WriteQilRewrite(QilExpression qil, XmlWriter w, string rewriteName) + private static void WriteQilRewrite(QilExpression qil, XmlWriter w, string? rewriteName) { w.WriteStartElement("Diff"); if (rewriteName != null) @@ -179,7 +180,7 @@ private static void WriteQilRewrite(QilExpression qil, XmlWriter w, string rewri /// private static string OptimizationToString(int opt) { - string s = Enum.GetName(typeof(XmlILOptimization), opt); + string s = Enum.GetName(typeof(XmlILOptimization), opt)!; if (s.StartsWith("Introduce", StringComparison.Ordinal)) { return s.Substring(9) + " introduction"; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlTypeHelper.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlTypeHelper.cs index a7ead3818658e..a3cbb3e37b454 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlTypeHelper.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlTypeHelper.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections.Generic; using System.IO; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlVisitor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlVisitor.cs index 2ac8ec71d728a..ce44e31df7c89 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlVisitor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlVisitor.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Xml; using System.Xml.XPath; @@ -14,6 +15,7 @@ using System.Xml.Xsl; using System.Xml.Xsl.Qil; using System.Xml.Xsl.Runtime; +using System.Diagnostics.CodeAnalysis; namespace System.Xml.Xsl.IlGen { @@ -28,9 +30,10 @@ namespace System.Xml.Xsl.IlGen /// internal class XmlILVisitor : QilVisitor { - private QilExpression _qil; - private GenerateHelper _helper; - private IteratorDescriptor _iterCurr, _iterNested; + private QilExpression _qil = null!; + private GenerateHelper _helper = null!; + private IteratorDescriptor _iterCurr = null!; + private IteratorDescriptor? _iterNested; private int _indexId; @@ -79,7 +82,7 @@ public void Visit(QilExpression qil, GenerateHelper helper, MethodInfo methRoot) /// private void PrepareGlobalValues(QilList globalIterators) { - MethodInfo methGlobal; + MethodInfo? methGlobal; IteratorDescriptor iterInfo; foreach (QilIterator iter in globalIterators) @@ -94,7 +97,7 @@ private void PrepareGlobalValues(QilList globalIterators) iterInfo = new IteratorDescriptor(_helper); // Iterator items will be stored in a global location - iterInfo.Storage = StorageDescriptor.Global(methGlobal, GetItemStorageType(iter), !iter.XmlType.IsSingleton); + iterInfo.Storage = StorageDescriptor.Global(methGlobal, GetItemStorageType(iter), !iter.XmlType!.IsSingleton); // Associate IteratorDescriptor with parameter XmlILAnnotation.Write(iter).CachedIteratorDescriptor = iterInfo; @@ -114,14 +117,14 @@ private void VisitGlobalValues(QilList globalIterators) foreach (QilIterator iter in globalIterators) { - QilParameter param = iter as QilParameter; + QilParameter? param = iter as QilParameter; // Get MethodInfo for method that computes the value of this global - methGlobal = XmlILAnnotation.Write(iter).CachedIteratorDescriptor.Storage.GlobalLocation; - isCached = !iter.XmlType.IsSingleton; + methGlobal = XmlILAnnotation.Write(iter).CachedIteratorDescriptor!.Storage.GlobalLocation!; + isCached = !iter.XmlType!.IsSingleton; // Notify the StaticDataManager of the new global value - idxValue = _helper.StaticData.DeclareGlobalValue(iter.DebugName); + idxValue = _helper.StaticData.DeclareGlobalValue(iter.DebugName!); // Generate code for this method _helper.MethodBegin(methGlobal, iter.SourceLine, false); @@ -145,7 +148,7 @@ private void VisitGlobalValues(QilList globalIterators) // param = runtime.ExternalContext.GetParameter(localName, namespaceUri); // if (param == null) goto LabelComputeGlobal; LocalBuilder locParam = _helper.DeclareLocal("$$$param", typeof(object)); - _helper.CallGetParameter(param.Name.LocalName, param.Name.NamespaceUri); + _helper.CallGetParameter(param.Name!.LocalName, param.Name.NamespaceUri); _helper.Emit(OpCodes.Stloc, locParam); _helper.Emit(OpCodes.Ldloc, locParam); _helper.Emit(OpCodes.Brfalse, lblComputeGlobal); @@ -186,7 +189,7 @@ private void VisitGlobalValues(QilList globalIterators) // XmlQueryRuntime.ThrowException("..."); Debug.Assert(iter.NodeType == QilNodeType.Parameter, "Only parameters may not have a default value"); _helper.LoadQueryRuntime(); - _helper.Emit(OpCodes.Ldstr, SR.Format(SR.XmlIl_UnknownParam, new string[] { param.Name.LocalName, param.Name.NamespaceUri })); + _helper.Emit(OpCodes.Ldstr, SR.Format(SR.XmlIl_UnknownParam, new string?[] { param!.Name!.LocalName, param.Name.NamespaceUri })); _helper.Call(XmlILMethods.ThrowException); } @@ -223,13 +226,13 @@ private void Function(QilFunction ndFunc) paramId = XmlILAnnotation.Write(iter).ArgumentPosition + 1; // The ParameterInfo for each argument should be set as its location - iterInfo.Storage = StorageDescriptor.Parameter(paramId, GetItemStorageType(iter), !iter.XmlType.IsSingleton); + iterInfo.Storage = StorageDescriptor.Parameter(paramId, GetItemStorageType(iter), !iter.XmlType!.IsSingleton); // Associate IteratorDescriptor with Let iterator XmlILAnnotation.Write(iter).CachedIteratorDescriptor = iterInfo; } - methFunc = XmlILAnnotation.Write(ndFunc).FunctionBinding; + methFunc = XmlILAnnotation.Write(ndFunc).FunctionBinding!; useWriter = (XmlILConstructInfo.Read(ndFunc).ConstructMethod == XmlILConstructMethod.Writer); // Generate query code from QilExpression tree @@ -245,7 +248,7 @@ private void Function(QilFunction ndFunc) if (iter.Binding != null) { Debug.Assert(iter.XmlType == TypeFactory.ItemS, "IlGen currently only supports default values in parameters of type item*."); - paramId = (iter.Annotation as XmlILAnnotation).ArgumentPosition + 1; + paramId = (iter.Annotation as XmlILAnnotation)!.ArgumentPosition + 1; // runtime.MatchesXmlType(param, XmlTypeCode.QName); Label lblLocalComputed = _helper.DefineLabel(); @@ -272,7 +275,7 @@ private void Function(QilFunction ndFunc) if (useWriter) NestedVisit(ndFunc.Definition); else - NestedVisitEnsureStack(ndFunc.Definition, GetItemStorageType(ndFunc), !ndFunc.XmlType.IsSingleton); + NestedVisitEnsureStack(ndFunc.Definition, GetItemStorageType(ndFunc), !ndFunc.XmlType!.IsSingleton); EndNestedIterator(ndFunc); @@ -289,7 +292,7 @@ private void Function(QilFunction ndFunc) protected override QilNode Visit(QilNode nd) { if (nd == null) - return null; + return null!; // DebugInfo: Sequence point just before generating code for this expression if (_qil.IsDebug && nd.SourceLine != null && !(nd is QilIterator)) @@ -309,7 +312,7 @@ protected override QilNode Visit(QilNode nd) break; case XmlILConstructMethod.Iterator: - Debug.Assert(nd.XmlType.IsSingleton || CachesResult(nd) || _iterCurr.HasLabelNext, + Debug.Assert(nd.XmlType!.IsSingleton || CachesResult(nd) || _iterCurr.HasLabelNext, "When generating code for a non-singleton expression, LabelNext must be defined."); goto default; @@ -352,7 +355,7 @@ private void NestedConstruction(QilNode nd) /// private void CopySequence(QilNode nd) { - XmlQueryType typ = nd.XmlType; + XmlQueryType typ = nd.XmlType!; bool hasOnEnd; Label lblOnEnd; @@ -365,13 +368,13 @@ private void CopySequence(QilNode nd) // Allow base internal class to dispatch to correct Visit method base.Visit(nd); - _iterCurr.EnsureItemStorageType(nd.XmlType, typeof(XPathItem)); + _iterCurr.EnsureItemStorageType(nd.XmlType!, typeof(XPathItem)); } else { // Allow base internal class to dispatch to correct Visit method base.Visit(nd); - _iterCurr.EnsureItemStorageType(nd.XmlType, typeof(XPathItem)); + _iterCurr.EnsureItemStorageType(nd.XmlType!, typeof(XPathItem)); // Save any stack values in a temporary local _iterCurr.EnsureNoStackNoCache("$$$copyTemp"); @@ -896,17 +899,17 @@ protected override QilNode VisitConditional(QilTernary ndCond) } else { - IteratorDescriptor iterInfoTrue; - LocalBuilder locBool = null, locCond = null; + IteratorDescriptor? iterInfoTrue; + LocalBuilder? locBool = null, locCond = null; Label lblFalse, lblDone, lblNext; Type itemStorageType = GetItemStorageType(ndCond); Debug.Assert(info.ConstructMethod == XmlILConstructMethod.Iterator); // Evaluate conditional test -- save boolean result in boolResult - Debug.Assert(ndCond.Left.XmlType.TypeCode == XmlTypeCode.Boolean); + Debug.Assert(ndCond.Left.XmlType!.TypeCode == XmlTypeCode.Boolean); lblFalse = _helper.DefineLabel(); - if (ndCond.XmlType.IsSingleton) + if (ndCond.XmlType!.IsSingleton) { // if (!bool-expr) goto LabelFalse; NestedVisitWithBranch(ndCond.Left, BranchingContext.OnFalse, lblFalse); @@ -940,7 +943,7 @@ protected override QilNode VisitConditional(QilTernary ndCond) // If conditional is not cardinality one, then need to iterate through all values if (!ndCond.XmlType.IsSingleton) { - Debug.Assert(!ndCond.Center.XmlType.IsSingleton || !ndCond.Right.XmlType.IsSingleton); + Debug.Assert(!ndCond.Center.XmlType!.IsSingleton || !ndCond.Right.XmlType!.IsSingleton); // IL's rules do not allow OpCodes.Br here // goto LabelDone; @@ -951,11 +954,11 @@ protected override QilNode VisitConditional(QilTernary ndCond) _helper.MarkLabel(lblNext); // if (boolResult) goto LabelNextTrue else goto LabelNextFalse; - _helper.Emit(OpCodes.Ldloc, locBool); - _helper.Emit(OpCodes.Brtrue, iterInfoTrue.GetLabelNext()); - _helper.EmitUnconditionalBranch(OpCodes.Br, _iterNested.GetLabelNext()); + _helper.Emit(OpCodes.Ldloc, locBool!); + _helper.Emit(OpCodes.Brtrue, iterInfoTrue!.GetLabelNext()); + _helper.EmitUnconditionalBranch(OpCodes.Br, _iterNested!.GetLabelNext()); - _iterCurr.SetIterator(lblNext, StorageDescriptor.Local(locCond, itemStorageType, false)); + _iterCurr.SetIterator(lblNext, StorageDescriptor.Local(locCond!, itemStorageType, false)); } // LabelDone: @@ -968,11 +971,11 @@ protected override QilNode VisitConditional(QilTernary ndCond) /// /// Generate code for one of the branches of QilNodeType.Conditional. /// - private void ConditionalBranch(QilNode ndBranch, Type itemStorageType, LocalBuilder locResult) + private void ConditionalBranch(QilNode ndBranch, Type itemStorageType, LocalBuilder? locResult) { if (locResult == null) { - Debug.Assert(ndBranch.XmlType.IsSingleton, "Conditional must produce a singleton"); + Debug.Assert(ndBranch.XmlType!.IsSingleton, "Conditional must produce a singleton"); // If in a branching context, then inherit branch target from parent context if (_iterCurr.IsBranching) @@ -989,7 +992,7 @@ private void ConditionalBranch(QilNode ndBranch, Type itemStorageType, LocalBuil { // Link nested iterator to parent conditional's iterator NestedVisit(ndBranch, _iterCurr.GetLabelNext()); - _iterCurr.EnsureItemStorageType(ndBranch.XmlType, itemStorageType); + _iterCurr.EnsureItemStorageType(ndBranch.XmlType!, itemStorageType); _iterCurr.EnsureLocalNoCache(locResult); } } @@ -1068,7 +1071,7 @@ protected override QilNode VisitLength(QilUnary ndSetLen) if (CachesResult(ndSetLen.Child)) { NestedVisitEnsureStack(ndSetLen.Child); - _helper.CallCacheCount(_iterNested.Storage.ItemStorageType); + _helper.CallCacheCount(_iterNested!.Storage.ItemStorageType); } else { @@ -1164,7 +1167,7 @@ private void Sequence(QilList ndSeq) foreach (QilNode nd in ndSeq) { // Generate nested iterator's code - if (nd.XmlType.IsSingleton) + if (nd.XmlType!.IsSingleton) { NestedVisitEnsureStack(nd); } @@ -1209,11 +1212,11 @@ private void Sequence(QilList ndSeq) NestedVisit(ndSeq[i], lblOnEnd); // Result of list should be saved to a common type and location - _iterCurr.EnsureItemStorageType(ndSeq[i].XmlType, itemStorageType); + _iterCurr.EnsureItemStorageType(ndSeq[i].XmlType!, itemStorageType); _iterCurr.EnsureLocalNoCache(locList); // Switch statement will jump to nested iterator's LabelNext - arrSwitchLabels[i] = _iterNested.GetLabelNext(); + arrSwitchLabels[i] = _iterNested!.GetLabelNext(); // IL's rules prevent OpCodes.Br here // goto LabelStart; @@ -1288,7 +1291,7 @@ private QilNode CreateSetIterator(QilBinary ndSet, string iterName, Type iterTyp // Generate left nested iterator. When it is empty, it will branch to lblNext. // goto LabelCall; NestedVisit(ndSet.Left, lblNext); - lblNextLeft = _iterNested.GetLabelNext(); + lblNextLeft = _iterNested!.GetLabelNext(); _iterCurr.EnsureLocal(locNav); _helper.EmitUnconditionalBranch(OpCodes.Brtrue, lblCall); @@ -1320,7 +1323,7 @@ private QilNode CreateSetIterator(QilBinary ndSet, string iterName, Type iterTyp // If this iterator always returns a single node, then NoMoreNodes will never be returned // Don't expose Next label if this iterator always returns a single node - if (ndSet.XmlType.IsSingleton) + if (ndSet.XmlType!.IsSingleton) { _helper.Emit(OpCodes.Switch, new Label[] { lblInitRight, lblNextLeft, lblNextRight }); _iterCurr.Storage = StorageDescriptor.Current(locIter, typeof(XPathNavigator)); @@ -1340,7 +1343,7 @@ private QilNode CreateSetIterator(QilBinary ndSet, string iterName, Type iterTyp protected override QilNode VisitAverage(QilUnary ndAvg) { XmlILStorageMethods meths = XmlILMethods.StorageMethods[GetItemStorageType(ndAvg)]; - return CreateAggregator(ndAvg, "$$$aggAvg", meths, meths.AggAvg, meths.AggAvgResult); + return CreateAggregator(ndAvg, "$$$aggAvg", meths, meths.AggAvg!, meths.AggAvgResult!); } /// @@ -1349,7 +1352,7 @@ protected override QilNode VisitAverage(QilUnary ndAvg) protected override QilNode VisitSum(QilUnary ndSum) { XmlILStorageMethods meths = XmlILMethods.StorageMethods[GetItemStorageType(ndSum)]; - return CreateAggregator(ndSum, "$$$aggSum", meths, meths.AggSum, meths.AggSumResult); + return CreateAggregator(ndSum, "$$$aggSum", meths, meths.AggSum!, meths.AggSumResult!); } /// @@ -1358,7 +1361,7 @@ protected override QilNode VisitSum(QilUnary ndSum) protected override QilNode VisitMinimum(QilUnary ndMin) { XmlILStorageMethods meths = XmlILMethods.StorageMethods[GetItemStorageType(ndMin)]; - return CreateAggregator(ndMin, "$$$aggMin", meths, meths.AggMin, meths.AggMinResult); + return CreateAggregator(ndMin, "$$$aggMin", meths, meths.AggMin!, meths.AggMinResult!); } /// @@ -1367,7 +1370,7 @@ protected override QilNode VisitMinimum(QilUnary ndMin) protected override QilNode VisitMaximum(QilUnary ndMax) { XmlILStorageMethods meths = XmlILMethods.StorageMethods[GetItemStorageType(ndMax)]; - return CreateAggregator(ndMax, "$$$aggMax", meths, meths.AggMax, meths.AggMaxResult); + return CreateAggregator(ndMax, "$$$aggMax", meths, meths.AggMax!, meths.AggMaxResult!); } /// @@ -1376,14 +1379,14 @@ protected override QilNode VisitMaximum(QilUnary ndMax) private QilNode CreateAggregator(QilUnary ndAgg, string aggName, XmlILStorageMethods methods, MethodInfo methAgg, MethodInfo methResult) { Label lblOnEnd = _helper.DefineLabel(); - Type typAgg = methAgg.DeclaringType; + Type typAgg = methAgg.DeclaringType!; LocalBuilder locAgg; // Aggregate agg; // agg.Create(); locAgg = _helper.DeclareLocal(aggName, typAgg); _helper.Emit(OpCodes.Ldloca, locAgg); - _helper.Call(methods.AggCreate); + _helper.Call(methods.AggCreate!); // foreach (num in expr) { StartNestedIterator(ndAgg.Child, lblOnEnd); @@ -1392,7 +1395,7 @@ private QilNode CreateAggregator(QilUnary ndAgg, string aggName, XmlILStorageMet // agg.Aggregate(num); _iterCurr.EnsureStackNoCache(); - _iterCurr.EnsureItemStorageType(ndAgg.XmlType, GetItemStorageType(ndAgg)); + _iterCurr.EnsureItemStorageType(ndAgg.XmlType!, GetItemStorageType(ndAgg)); _helper.Call(methAgg); _helper.Emit(OpCodes.Ldloca, locAgg); @@ -1403,10 +1406,10 @@ private QilNode CreateAggregator(QilUnary ndAgg, string aggName, XmlILStorageMet EndNestedIterator(ndAgg.Child); // If aggregate might be empty sequence, then generate code to handle this possibility - if (ndAgg.XmlType.MaybeEmpty) + if (ndAgg.XmlType!.MaybeEmpty) { // if (agg.IsEmpty) goto LabelNextCtxt; - _helper.Call(methods.AggIsEmpty); + _helper.Call(methods.AggIsEmpty!); _helper.Emit(OpCodes.Brtrue, _iterCurr.GetLabelNext()); _helper.Emit(OpCodes.Ldloca, locAgg); } @@ -1424,7 +1427,7 @@ private QilNode CreateAggregator(QilUnary ndAgg, string aggName, XmlILStorageMet protected override QilNode VisitNegate(QilUnary ndNeg) { NestedVisitEnsureStack(ndNeg.Child); - _helper.CallArithmeticOp(QilNodeType.Negate, ndNeg.XmlType.TypeCode); + _helper.CallArithmeticOp(QilNodeType.Negate, ndNeg.XmlType!.TypeCode); _iterCurr.Storage = StorageDescriptor.Stack(GetItemStorageType(ndNeg), false); return ndNeg; } @@ -1475,7 +1478,7 @@ protected override QilNode VisitModulo(QilBinary ndMod) private QilNode ArithmeticOp(QilBinary ndOp) { NestedVisitEnsureStack(ndOp.Left, ndOp.Right); - _helper.CallArithmeticOp(ndOp.NodeType, ndOp.XmlType.TypeCode); + _helper.CallArithmeticOp(ndOp.NodeType, ndOp.XmlType!.TypeCode); _iterCurr.Storage = StorageDescriptor.Stack(GetItemStorageType(ndOp), false); return ndOp; } @@ -1498,9 +1501,9 @@ protected override QilNode VisitStrConcat(QilStrConcat ndStrConcat) { LocalBuilder locStringConcat; bool fasterConcat; - QilNode delimiter; + QilNode? delimiter; QilNode listStrings; - Debug.Assert(!ndStrConcat.Values.XmlType.IsSingleton, "Optimizer should have folded StrConcat of a singleton value"); + Debug.Assert(!ndStrConcat.Values.XmlType!.IsSingleton, "Optimizer should have folded StrConcat of a singleton value"); // Get delimiter (assuming it's not the empty string) delimiter = ndStrConcat.Delimiter; @@ -1516,7 +1519,7 @@ protected override QilNode VisitStrConcat(QilStrConcat ndStrConcat) fasterConcat = true; foreach (QilNode ndStr in listStrings) { - if (!ndStr.XmlType.IsSingleton) + if (!ndStr.XmlType!.IsSingleton) fasterConcat = false; } } @@ -1583,7 +1586,7 @@ private void GenerateConcat(QilNode ndStr, LocalBuilder locStringConcat) // strcat.Concat(str); _iterCurr.EnsureStackNoCache(); - _iterCurr.EnsureItemStorageType(ndStr.XmlType, typeof(string)); + _iterCurr.EnsureItemStorageType(ndStr.XmlType!, typeof(string)); _helper.Call(XmlILMethods.StrCatCat); _helper.Emit(OpCodes.Ldloca, locStringConcat); @@ -1618,7 +1621,7 @@ private void VisitStrParseQName(QilBinary ndParsedTagName, bool preservePrefix) NestedVisitEnsureStack(ndParsedTagName.Left); // If type of second parameter is string, - if (ndParsedTagName.Right.XmlType.TypeCode == XmlTypeCode.String) + if (ndParsedTagName.Right.XmlType!.TypeCode == XmlTypeCode.String) { // Then push (possibly computed) namespace onto the stack Debug.Assert(ndParsedTagName.Right.XmlType.IsSingleton); @@ -1704,7 +1707,7 @@ private void Compare(QilBinary ndComp) { QilNodeType relOp = ndComp.NodeType; XmlTypeCode code; - Debug.Assert(ndComp.Left.XmlType.IsAtomicValue && ndComp.Right.XmlType.IsAtomicValue, "Operands to compare must be atomic values."); + Debug.Assert(ndComp.Left.XmlType!.IsAtomicValue && ndComp.Right.XmlType!.IsAtomicValue, "Operands to compare must be atomic values."); Debug.Assert(ndComp.Left.XmlType.IsSingleton && ndComp.Right.XmlType.IsSingleton, "Operands to compare must be cardinality one."); Debug.Assert(ndComp.Left.XmlType == ndComp.Right.XmlType, "Operands to compare may not be heterogenous."); @@ -1823,7 +1826,7 @@ protected override QilNode VisitFor(QilIterator ndFor) IteratorDescriptor iterInfo; // Reference saved location - iterInfo = XmlILAnnotation.Write(ndFor).CachedIteratorDescriptor; + iterInfo = XmlILAnnotation.Write(ndFor).CachedIteratorDescriptor!; _iterCurr.Storage = iterInfo.Storage; // If the iterator is a reference to a global variable or parameter, @@ -1888,11 +1891,11 @@ protected override QilNode VisitFilter(QilLoop ndFilter) StartBinding(ndFilter.Variable); // Result of filter is the sequence bound to the iterator - _iterCurr.SetIterator(_iterNested); + _iterCurr.SetIterator(_iterNested!); // If filter is false, skip the current item StartNestedIterator(ndFilter.Body); - _iterCurr.SetBranching(BranchingContext.OnFalse, _iterCurr.ParentIterator.GetLabelNext()); + _iterCurr.SetBranching(BranchingContext.OnFalse, _iterCurr.ParentIterator!.GetLabelNext()); Visit(ndFilter.Body); EndNestedIterator(ndFilter.Body); @@ -1911,7 +1914,7 @@ private bool HandleFilterPatterns(QilLoop ndFilter) OptimizerPatterns patt = OptimizerPatterns.Read(ndFilter); LocalBuilder locIter; XmlNodeKindFlags kinds; - QilName name; + QilName? name; QilNode input, step; bool isFilterElements; @@ -1945,7 +1948,7 @@ private bool HandleFilterPatterns(QilLoop ndFilter) // iter.Create(navCtxt, locName, ns); _helper.Emit(OpCodes.Ldloca, locIter); NestedVisitEnsureStack(input); - _helper.CallGetAtomizedName(_helper.StaticData.DeclareName(name.LocalName)); + _helper.CallGetAtomizedName(_helper.StaticData.DeclareName(name!.LocalName)); _helper.CallGetAtomizedName(_helper.StaticData.DeclareName(name.NamespaceUri)); _helper.Call(XmlILMethods.ElemContentCreate); @@ -2067,7 +2070,7 @@ private bool HandleFilterPatterns(QilLoop ndFilter) _iterCurr.EnsureStackNoCache(); VisitFor(nodes); _iterCurr.EnsureStackNoCache(); - _iterCurr.EnsureItemStorageType(nodes.XmlType, typeof(XPathNavigator)); + _iterCurr.EnsureItemStorageType(nodes.XmlType!, typeof(XPathNavigator)); _helper.Call(XmlILMethods.IndexAdd); _helper.Emit(OpCodes.Ldloc, locIndex); @@ -2108,7 +2111,7 @@ private void StartBinding(QilIterator ndIter) _helper.DebugSequencePoint(ndIter.SourceLine); // Treat cardinality one Let iterators as if they were For iterators (no nesting necessary) - if (ndIter.NodeType == QilNodeType.For || ndIter.XmlType.IsSingleton) + if (ndIter.NodeType == QilNodeType.For || ndIter.XmlType!.IsSingleton) { StartForBinding(ndIter, patt); } @@ -2131,8 +2134,8 @@ private void StartBinding(QilIterator ndIter) /// private void StartForBinding(QilIterator ndFor, OptimizerPatterns patt) { - LocalBuilder locPos = null; - Debug.Assert(ndFor.XmlType.IsSingleton); + LocalBuilder? locPos = null; + Debug.Assert(ndFor.XmlType!.IsSingleton); // For expression iterator will be unnested as part of parent iterator if (_iterCurr.HasLabelNext) @@ -2149,7 +2152,7 @@ private void StartForBinding(QilIterator ndFor, OptimizerPatterns patt) } // Allow base internal class to dispatch based on QilExpression node type - Visit(ndFor.Binding); + Visit(ndFor.Binding!); // DebugInfo: Open variable scope // DebugInfo: Ensure that for variable is stored in a local and tag it with the user-defined name @@ -2169,24 +2172,24 @@ private void StartForBinding(QilIterator ndFor, OptimizerPatterns patt) if (patt.MatchesPattern(OptimizerPatternName.IsPositional)) { // Increment position - _helper.Emit(OpCodes.Ldloc, locPos); + _helper.Emit(OpCodes.Ldloc, locPos!); _helper.Emit(OpCodes.Ldc_I4_1); _helper.Emit(OpCodes.Add); - _helper.Emit(OpCodes.Stloc, locPos); + _helper.Emit(OpCodes.Stloc, locPos!); if (patt.MatchesPattern(OptimizerPatternName.MaxPosition)) { // Short-circuit rest of loop if max position has already been reached - _helper.Emit(OpCodes.Ldloc, locPos); + _helper.Emit(OpCodes.Ldloc, locPos!); _helper.LoadInteger((int)patt.GetArgument(OptimizerPatternArgument.MaxPosition)); - _helper.Emit(OpCodes.Bgt, _iterCurr.ParentIterator.GetLabelNext()); + _helper.Emit(OpCodes.Bgt, _iterCurr.ParentIterator!.GetLabelNext()); } _iterCurr.LocalPosition = locPos; } - EndNestedIterator(ndFor.Binding); - _iterCurr.SetIterator(_iterNested); + EndNestedIterator(ndFor.Binding!); + _iterCurr.SetIterator(_iterNested!); } /// @@ -2194,13 +2197,13 @@ private void StartForBinding(QilIterator ndFor, OptimizerPatterns patt) /// public void StartLetBinding(QilIterator ndLet) { - Debug.Assert(!ndLet.XmlType.IsSingleton); + Debug.Assert(!ndLet.XmlType!.IsSingleton); // Construct nested iterator StartNestedIterator(ndLet); // Allow base internal class to dispatch based on QilExpression node type - NestedVisit(ndLet.Binding, GetItemStorageType(ndLet), !ndLet.XmlType.IsSingleton); + NestedVisit(ndLet.Binding!, GetItemStorageType(ndLet), !ndLet.XmlType.IsSingleton); // DebugInfo: Open variable scope // DebugInfo: Ensure that for variable is stored in a local and tag it with the user-defined name @@ -2237,11 +2240,11 @@ private void EndBinding(QilIterator ndIter) /// protected override QilNode VisitPositionOf(QilUnary ndPos) { - QilIterator ndIter = ndPos.Child as QilIterator; + QilIterator ndIter = (ndPos.Child as QilIterator)!; LocalBuilder locPos; Debug.Assert(ndIter.NodeType == QilNodeType.For); - locPos = XmlILAnnotation.Write(ndIter).CachedIteratorDescriptor.LocalPosition; + locPos = XmlILAnnotation.Write(ndIter).CachedIteratorDescriptor!.LocalPosition!; Debug.Assert(locPos != null); _iterCurr.Storage = StorageDescriptor.Local(locPos, typeof(int), false); @@ -2277,11 +2280,11 @@ protected override QilNode VisitSort(QilLoop ndSort) // foreach (item in sort-expr) { StartNestedIterator(ndSort.Variable, lblOnEndSort); StartBinding(ndSort.Variable); - Debug.Assert(!_iterNested.Storage.IsCached); + Debug.Assert(!_iterNested!.Storage.IsCached); // cache.Add(item); _iterCurr.EnsureStackNoCache(); - _iterCurr.EnsureItemStorageType(ndSort.Variable.XmlType, GetItemStorageType(ndSort.Variable)); + _iterCurr.EnsureItemStorageType(ndSort.Variable.XmlType!, GetItemStorageType(ndSort.Variable)); _helper.Call(methods.SeqAdd); _helper.Emit(OpCodes.Ldloca, locKeys); @@ -2321,7 +2324,7 @@ protected override QilNode VisitSort(QilLoop ndSort) private void VisitSortKey(QilSortKey ndKey, LocalBuilder locKeys) { Label lblOnEndKey; - Debug.Assert(ndKey.Key.XmlType.IsAtomicValue, "Sort key must be an atomic value."); + Debug.Assert(ndKey.Key.XmlType!.IsAtomicValue, "Sort key must be an atomic value."); // Push collation onto the stack _helper.Emit(OpCodes.Ldloca, locKeys); @@ -2338,7 +2341,7 @@ private void VisitSortKey(QilSortKey ndKey, LocalBuilder locKeys) _helper.Call(XmlILMethods.CreateCollation); } - if (ndKey.XmlType.IsSingleton) + if (ndKey.XmlType!.IsSingleton) { NestedVisitEnsureStack(ndKey.Key); @@ -2379,7 +2382,7 @@ private void VisitSortKey(QilSortKey ndKey, LocalBuilder locKeys) protected override QilNode VisitDocOrderDistinct(QilUnary ndDod) { // DocOrderDistinct applied to a singleton is a no-op - if (ndDod.XmlType.IsSingleton) + if (ndDod.XmlType!.IsSingleton) return Visit(ndDod.Child); // Handle any special-case patterns that are rooted at DocOrderDistinct @@ -2404,7 +2407,7 @@ private bool HandleDodPatterns(QilUnary ndDod) { OptimizerPatterns pattDod = OptimizerPatterns.Read(ndDod); XmlNodeKindFlags kinds; - QilName name; + QilName? name; QilNode input, step; bool isJoinAndDod; @@ -2429,7 +2432,7 @@ private bool HandleDodPatterns(QilUnary ndDod) else { Debug.Assert(pattStep.MatchesPattern(OptimizerPatternName.Axis), "Dod patterns should only match if step is FilterElements or FilterKindTest or Axis"); - kinds = ((ndDod.XmlType.NodeKinds & XmlNodeKindFlags.Attribute) != 0) ? XmlNodeKindFlags.Any : XmlNodeKindFlags.Content; + kinds = ((ndDod.XmlType!.NodeKinds & XmlNodeKindFlags.Attribute) != 0) ? XmlNodeKindFlags.Any : XmlNodeKindFlags.Content; name = null; } @@ -2541,7 +2544,7 @@ private bool HandleDodPatterns(QilUnary ndDod) protected override QilNode VisitInvoke(QilInvoke ndInvoke) { QilFunction ndFunc = ndInvoke.Function; - MethodInfo methInfo = XmlILAnnotation.Write(ndFunc).FunctionBinding; + MethodInfo methInfo = XmlILAnnotation.Write(ndFunc).FunctionBinding!; bool useWriter = (XmlILConstructInfo.Read(ndFunc).ConstructMethod == XmlILConstructMethod.Writer); Debug.Assert(!XmlILConstructInfo.Read(ndInvoke).PushToWriterFirst || useWriter); @@ -2553,7 +2556,7 @@ protected override QilNode VisitInvoke(QilInvoke ndInvoke) { QilNode ndActualArg = ndInvoke.Arguments[iArg]; QilNode ndFormalArg = ndInvoke.Function.Arguments[iArg]; - NestedVisitEnsureStack(ndActualArg, GetItemStorageType(ndFormalArg), !ndFormalArg.XmlType.IsSingleton); + NestedVisitEnsureStack(ndActualArg, GetItemStorageType(ndFormalArg), !ndFormalArg.XmlType!.IsSingleton); } // Check whether this call should compiled using the .tailcall instruction @@ -2566,7 +2569,7 @@ protected override QilNode VisitInvoke(QilInvoke ndInvoke) if (!useWriter) { // Return value is on the stack; ensure it has the correct storage type - _iterCurr.Storage = StorageDescriptor.Stack(GetItemStorageType(ndInvoke), !ndInvoke.XmlType.IsSingleton); + _iterCurr.Storage = StorageDescriptor.Stack(GetItemStorageType(ndInvoke), !ndInvoke.XmlType!.IsSingleton); } else { @@ -2590,7 +2593,7 @@ protected override QilNode VisitContent(QilUnary ndContent) /// protected override QilNode VisitAttribute(QilBinary ndAttr) { - QilName ndName = ndAttr.Right as QilName; + QilName? ndName = ndAttr.Right as QilName; Debug.Assert(ndName != null, "Attribute node must have a literal QName as its second argument"); // XPathNavigator navAttr; @@ -3140,7 +3143,7 @@ private QilNode VisitNodeProperty(QilUnary ndProp) /// protected override QilNode VisitTypeAssert(QilTargetType ndTypeAssert) { - if (!ndTypeAssert.Source.XmlType.IsSingleton && ndTypeAssert.XmlType.IsSingleton && !_iterCurr.HasLabelNext) + if (!ndTypeAssert.Source.XmlType!.IsSingleton && ndTypeAssert.XmlType!.IsSingleton && !_iterCurr.HasLabelNext) { // This case occurs when a non-singleton expression is treated as cardinality One. // The trouble is that the expression will branch to an end label when it's done iterating, so @@ -3170,9 +3173,9 @@ protected override QilNode VisitIsType(QilTargetType ndIsType) XmlQueryType typDerived, typBase; XmlTypeCode codeBase; - typDerived = ndIsType.Source.XmlType; + typDerived = ndIsType.Source.XmlType!; typBase = ndIsType.TargetType; - Debug.Assert(!typDerived.NeverSubtypeOf(typBase), "Normalizer should have eliminated IsType where source can never be a subtype of destination type."); + Debug.Assert(!typDerived!.NeverSubtypeOf(typBase), "Normalizer should have eliminated IsType where source can never be a subtype of destination type."); // Special Case: Test whether singleton item is a Node if (typDerived.IsSingleton && (object)typBase == (object)TypeFactory.Node) @@ -3351,7 +3354,7 @@ protected override QilNode VisitIsEmpty(QilUnary ndIsEmpty) { // Then get the count directly from the cache NestedVisitEnsureStack(ndIsEmpty.Child); - _helper.CallCacheCount(_iterNested.Storage.ItemStorageType); + _helper.CallCacheCount(_iterNested!.Storage.ItemStorageType); switch (_iterCurr.CurrentBranchingContext) { @@ -3430,7 +3433,7 @@ protected override QilNode VisitIsEmpty(QilUnary ndIsEmpty) protected override QilNode VisitXPathNodeValue(QilUnary ndVal) { Label lblOnEnd, lblDone; - Debug.Assert(ndVal.Child.XmlType.IsNode, "XPathNodeValue node may only be applied to a sequence of Nodes."); + Debug.Assert(ndVal.Child.XmlType!.IsNode, "XPathNodeValue node may only be applied to a sequence of Nodes."); // If the expression is a singleton, if (ndVal.Child.XmlType.IsSingleton) @@ -3508,7 +3511,7 @@ protected override QilNode VisitXsltGenerateId(QilUnary ndGenId) _helper.LoadQueryRuntime(); // If the expression is a singleton, - if (ndGenId.Child.XmlType.IsSingleton) + if (ndGenId.Child.XmlType!.IsSingleton) { // Then generate code to push expresion result onto the stack NestedVisitEnsureStack(ndGenId.Child, typeof(XPathNavigator), false); @@ -3607,7 +3610,7 @@ protected override QilNode VisitXsltInvokeEarlyBound(QilInvokeEarlyBound ndInvok clrTypeRetDst = GetStorageType(ndInvoke); // Prepare to call runtime.ChangeTypeXsltResult - if (clrTypeRetSrc != clrTypeRetDst && !ndInvoke.XmlType.IsEmpty) + if (clrTypeRetSrc != clrTypeRetDst && !ndInvoke.XmlType!.IsEmpty) { _helper.LoadQueryRuntime(); _helper.LoadInteger(_helper.StaticData.DeclareXmlType(ndInvoke.XmlType)); @@ -3620,7 +3623,7 @@ protected override QilNode VisitXsltInvokeEarlyBound(QilInvokeEarlyBound ndInvok if (ndName.NamespaceUri.Length == 0) _helper.LoadXsltLibrary(); else - _helper.CallGetEarlyBoundObject(_helper.StaticData.DeclareEarlyBound(ndName.NamespaceUri, extFunc.Method.DeclaringType), extFunc.Method.DeclaringType); + _helper.CallGetEarlyBoundObject(_helper.StaticData.DeclareEarlyBound(ndName.NamespaceUri, extFunc.Method.DeclaringType!), extFunc.Method.DeclaringType!); } // Generate code to push each Invoke argument onto the stack @@ -3636,7 +3639,7 @@ protected override QilNode VisitXsltInvokeEarlyBound(QilInvokeEarlyBound ndInvok xmlTypeFormalArg = extFunc.GetXmlArgumentType(iArg); clrTypeFormalArg = extFunc.GetClrArgumentType(iArg); - Debug.Assert(ndActualArg.XmlType.IsSubtypeOf(xmlTypeFormalArg), "Xml type of actual arg must be a subtype of the Xml type of the formal arg"); + Debug.Assert(ndActualArg.XmlType!.IsSubtypeOf(xmlTypeFormalArg), "Xml type of actual arg must be a subtype of the Xml type of the formal arg"); // Use different conversion rules for internal Xslt libraries. If the actual argument is // stored using Clr type T, then library must use type T, XPathItem, IList, or IList. @@ -3698,7 +3701,7 @@ protected override QilNode VisitXsltInvokeEarlyBound(QilInvokeEarlyBound ndInvok _helper.Call(extFunc.Method); // Return value is on the stack; convert it to canonical ILGen storage type - if (ndInvoke.XmlType.IsEmpty) + if (ndInvoke.XmlType!.IsEmpty) { _helper.Emit(OpCodes.Ldsfld, XmlILMethods.StorageMethods[typeof(XPathItem)].SeqEmpty); } @@ -3738,7 +3741,7 @@ protected override QilNode VisitXsltCopy(QilBinary ndCopy) _helper.LoadQueryOutput(); NestedVisitEnsureStack(ndCopy.Left); - Debug.Assert(ndCopy.Left.XmlType.IsNode); + Debug.Assert(ndCopy.Left.XmlType!.IsNode); _helper.Call(XmlILMethods.StartCopy); _helper.Emit(OpCodes.Brfalse, lblSkipContent); @@ -3784,9 +3787,9 @@ protected override QilNode VisitXsltCopyOf(QilUnary ndCopyOf) protected override QilNode VisitXsltConvert(QilTargetType ndConv) { XmlQueryType typSrc, typDst; - MethodInfo meth; + MethodInfo? meth; - typSrc = ndConv.Source.XmlType; + typSrc = ndConv.Source.XmlType!; typDst = ndConv.TargetType; if (GetXsltConvertMethod(typSrc, typDst, out meth)) @@ -3813,7 +3816,7 @@ protected override QilNode VisitXsltConvert(QilTargetType ndConv) /// Get the XsltConvert method that converts from "typSrc" to "typDst". Return false if no /// such method exists. This conversion matrix should match the one in XsltConvert.ExternalValueToExternalValue. /// - private bool GetXsltConvertMethod(XmlQueryType typSrc, XmlQueryType typDst, out MethodInfo meth) + private bool GetXsltConvertMethod(XmlQueryType typSrc, XmlQueryType typDst, out MethodInfo? meth) { meth = null; @@ -3933,7 +3936,7 @@ private void CreateSimpleIterator(QilNode ndCtxt, string iterName, Type iterType /// goto LabelNextCtxt; /// private void CreateFilteredIterator(QilNode ndCtxt, string iterName, Type iterType, MethodInfo methCreate, MethodInfo methNext, - XmlNodeKindFlags kinds, QilName ndName, TriState orSelf, QilNode ndEnd) + XmlNodeKindFlags kinds, QilName? ndName, TriState orSelf, QilNode? ndEnd) { // Iterator iter; LocalBuilder locIter = _helper.DeclareLocal(iterName, iterType); @@ -3969,7 +3972,7 @@ private void CreateFilteredIterator(QilNode ndCtxt, string iterName, Type iterTy /// } /// private void CreateContainerIterator(QilUnary ndDod, string iterName, Type iterType, MethodInfo methCreate, MethodInfo methNext, - XmlNodeKindFlags kinds, QilName ndName, TriState orSelf) + XmlNodeKindFlags kinds, QilName? ndName, TriState orSelf) { // Iterator iter; LocalBuilder locIter = _helper.DeclareLocal(iterName, iterType); @@ -3990,7 +3993,7 @@ private void CreateContainerIterator(QilUnary ndDod, string iterName, Type iterT StartBinding(ndLoop.Variable); EndBinding(ndLoop.Variable); EndNestedIterator(ndLoop.Variable); - _iterCurr.Storage = _iterNested.Storage; + _iterCurr.Storage = _iterNested!.Storage; GenerateContainerIterator(ndDod, locIter, lblOnEndNested, methNext, typeof(XPathNavigator)); } @@ -4046,7 +4049,7 @@ private void GenerateContainerIterator(QilNode nd, LocalBuilder locIter, Label l // iter.MoveNext(input); // goto LabelCall; - _iterCurr.EnsureNoStackNoCache(nd.XmlType.IsNode ? "$$$navInput" : "$$$itemInput"); + _iterCurr.EnsureNoStackNoCache(nd.XmlType!.IsNode ? "$$$navInput" : "$$$itemInput"); _helper.Emit(OpCodes.Ldloca, locIter); _iterCurr.PushValue(); _helper.EmitUnconditionalBranch(OpCodes.Br, lblCall); @@ -4067,7 +4070,7 @@ private void GenerateContainerIterator(QilNode nd, LocalBuilder locIter, Label l { // if (result == IteratorResult.NeedInputNode) goto LabelNextInput; _helper.LoadInteger((int)IteratorResult.NeedInputNode); - _helper.Emit(OpCodes.Beq, _iterNested.GetLabelNext()); + _helper.Emit(OpCodes.Beq, _iterNested!.GetLabelNext()); _iterCurr.Storage = StorageDescriptor.Current(locIter, itemStorageType); } @@ -4077,7 +4080,7 @@ private void GenerateContainerIterator(QilNode nd, LocalBuilder locIter, Label l // case IteratorResult.NoMoreNodes: goto LabelNextCtxt; // case IteratorResult.NeedInputNode: goto LabelNextInput; // } - _helper.Emit(OpCodes.Switch, new Label[] { _iterCurr.GetLabelNext(), _iterNested.GetLabelNext() }); + _helper.Emit(OpCodes.Switch, new Label[] { _iterCurr.GetLabelNext(), _iterNested!.GetLabelNext() }); _iterCurr.SetIterator(lblOnEndNested, StorageDescriptor.Current(locIter, itemStorageType)); } @@ -4092,7 +4095,7 @@ private GenerateNameType LoadNameAndType(XPathNodeType nodeType, QilNode ndName, QilName ndLiteralName; string prefix, localName, ns; GenerateNameType nameType; - Debug.Assert(ndName.XmlType.TypeCode == XmlTypeCode.QName, "Element or attribute name must have QName type."); + Debug.Assert(ndName.XmlType!.TypeCode == XmlTypeCode.QName, "Element or attribute name must have QName type."); _helper.LoadQueryOutput(); @@ -4105,7 +4108,7 @@ private GenerateNameType LoadNameAndType(XPathNodeType nodeType, QilNode ndName, // If checks need to be made on End construction, then always pop names from stack if (isStart || !callChk) { - ndLiteralName = ndName as QilName; + ndLiteralName = (ndName as QilName)!; prefix = ndLiteralName.Prefix; localName = ndLiteralName.LocalName; ns = ndLiteralName.NamespaceUri; @@ -4153,17 +4156,17 @@ private GenerateNameType LoadNameAndType(XPathNodeType nodeType, QilNode ndName, if (ndName.NodeType == QilNodeType.NameOf) { // Preserve prefix of source node, so just push navigator onto stack - NestedVisitEnsureStack((ndName as QilUnary).Child); + NestedVisitEnsureStack((ndName as QilUnary)!.Child); nameType = GenerateNameType.CopiedName; } // 3. Parsed tag names (foo:bar) else if (ndName.NodeType == QilNodeType.StrParseQName) { // Preserve prefix from parsed tag name - VisitStrParseQName(ndName as QilBinary, true); + VisitStrParseQName((ndName as QilBinary)!, true); // Type of name depends upon data-type of name argument - if ((ndName as QilBinary).Right.XmlType.TypeCode == XmlTypeCode.String) + if ((ndName as QilBinary)!.Right.XmlType!.TypeCode == XmlTypeCode.String) nameType = GenerateNameType.TagNameAndNamespace; else nameType = GenerateNameType.TagNameAndMappings; @@ -4216,7 +4219,7 @@ private bool TryZeroCompare(QilNodeType relOp, QilNode ndFirst, QilNode ndSecond NestedVisitEnsureStack(ndSecond); // Generate comparison code -- op == 0 or op != 0 - ZeroCompare(relOp, ndSecond.XmlType.TypeCode == XmlTypeCode.Boolean); + ZeroCompare(relOp, ndSecond.XmlType!.TypeCode == XmlTypeCode.Boolean); return true; } @@ -4239,12 +4242,12 @@ private bool TryNameCompare(QilNodeType relOp, QilNode ndFirst, QilNode ndSecond _helper.LoadQueryRuntime(); // Push left navigator onto the stack - NestedVisitEnsureStack((ndFirst as QilUnary).Child); + NestedVisitEnsureStack((ndFirst as QilUnary)!.Child); // Push the local name and namespace uri of the right argument onto the stack if (ndSecond.NodeType == QilNodeType.LiteralQName) { - QilName ndName = ndSecond as QilName; + QilName ndName = (ndSecond as QilName)!; _helper.LoadInteger(_helper.StaticData.DeclareName(ndName.LocalName)); _helper.LoadInteger(_helper.StaticData.DeclareName(ndName.NamespaceUri)); @@ -4415,7 +4418,7 @@ private void StartWriterLoop(QilNode nd, out bool hasOnEnd, out Label lblOnEnd) lblOnEnd = default; // If loop is not involved in Xml construction, or if loop returns exactly one value, then do nothing - if (!info.PushToWriterLast || nd.XmlType.IsSingleton) + if (!info.PushToWriterLast || nd.XmlType!.IsSingleton) return; if (!_iterCurr.HasLabelNext) @@ -4443,7 +4446,7 @@ private void EndWriterLoop(QilNode nd, bool hasOnEnd, Label lblOnEnd) _iterCurr.Storage = StorageDescriptor.None(); // If loop returns exactly one value, then do nothing further - if (nd.XmlType.IsSingleton) + if (nd.XmlType!.IsSingleton) return; if (hasOnEnd) @@ -4457,7 +4460,7 @@ private void EndWriterLoop(QilNode nd, bool hasOnEnd, Label lblOnEnd) /// Returns true if the specified node's owner element might have local namespaces added to it /// after attributes have already been added. /// - private bool MightHaveNamespacesAfterAttributes(XmlILConstructInfo info) + private bool MightHaveNamespacesAfterAttributes(XmlILConstructInfo? info) { // Get parent element if (info != null) @@ -4598,7 +4601,7 @@ private XPathNodeType QilConstructorToNodeType(QilNodeType typ) /// /// Load an XmlNavigatorFilter that matches only the specified name and types onto the stack. /// - private void LoadSelectFilter(XmlNodeKindFlags xmlTypes, QilName ndName) + private void LoadSelectFilter(XmlNodeKindFlags xmlTypes, QilName? ndName) { if (ndName != null) { @@ -4646,9 +4649,10 @@ private static bool IsNodeTypeUnion(XmlNodeKindFlags xmlTypes) /// is a top-level, or root iterator. Otherwise, the new iterator will be nested within the /// current iterator. /// - private void StartNestedIterator(QilNode nd) + [MemberNotNull(nameof(_iterCurr))] + private void StartNestedIterator(QilNode? nd) { - IteratorDescriptor iterParent = _iterCurr; + IteratorDescriptor? iterParent = _iterCurr; // Create a new, nested iterator if (iterParent == null) @@ -4669,7 +4673,7 @@ private void StartNestedIterator(QilNode nd) /// Calls StartNestedIterator(nd) and also sets up the nested iterator to branch to "lblOnEnd" when iteration /// is complete. /// - private void StartNestedIterator(QilNode nd, Label lblOnEnd) + private void StartNestedIterator(QilNode? nd, Label lblOnEnd) { StartNestedIterator(nd); _iterCurr.SetIterator(lblOnEnd, StorageDescriptor.None()); @@ -4683,7 +4687,7 @@ private void EndNestedIterator(QilNode nd) Debug.Assert(_iterCurr.Storage.Location == ItemLocation.None || _iterCurr.Storage.ItemStorageType == GetItemStorageType(nd) || _iterCurr.Storage.ItemStorageType == typeof(XPathItem) || - nd.XmlType.TypeCode == XmlTypeCode.None, + nd.XmlType!.TypeCode == XmlTypeCode.None, "QilNodeType " + nd.NodeType + " cannot be stored using type " + _iterCurr.Storage.ItemStorageType + "."); // If the nested iterator was constructed in branching mode, @@ -4692,7 +4696,7 @@ private void EndNestedIterator(QilNode nd) // Then if branching hasn't already taken place, do so now if (_iterCurr.Storage.Location != ItemLocation.None) { - _iterCurr.EnsureItemStorageType(nd.XmlType, typeof(bool)); + _iterCurr.EnsureItemStorageType(nd.XmlType!, typeof(bool)); _iterCurr.EnsureStackNoCache(); if (_iterCurr.CurrentBranchingContext == BranchingContext.OnTrue) @@ -4708,7 +4712,7 @@ private void EndNestedIterator(QilNode nd) _iterNested = _iterCurr; // Update current iterator to be parent iterator - _iterCurr = _iterCurr.ParentIterator; + _iterCurr = _iterCurr.ParentIterator!; } /// @@ -4727,7 +4731,7 @@ private void NestedVisit(QilNode nd, Type itemStorageType, bool isCached) EndNestedIterator(nd); _iterCurr.Storage = StorageDescriptor.None(); } - else if (!isCached && nd.XmlType.IsSingleton) + else if (!isCached && nd.XmlType!.IsSingleton) { // Storage of result will be a non-cached singleton StartNestedIterator(nd); @@ -4735,7 +4739,7 @@ private void NestedVisit(QilNode nd, Type itemStorageType, bool isCached) _iterCurr.EnsureNoCache(); _iterCurr.EnsureItemStorageType(nd.XmlType, itemStorageType); EndNestedIterator(nd); - _iterCurr.Storage = _iterNested.Storage; + _iterCurr.Storage = _iterNested!.Storage; } else { @@ -4748,7 +4752,7 @@ private void NestedVisit(QilNode nd, Type itemStorageType, bool isCached) /// private void NestedVisit(QilNode nd) { - NestedVisit(nd, GetItemStorageType(nd), !nd.XmlType.IsSingleton); + NestedVisit(nd, GetItemStorageType(nd), !nd.XmlType!.IsSingleton); } /// @@ -4761,9 +4765,9 @@ private void NestedVisit(QilNode nd, Label lblOnEnd) StartNestedIterator(nd, lblOnEnd); Visit(nd); _iterCurr.EnsureNoCache(); - _iterCurr.EnsureItemStorageType(nd.XmlType, GetItemStorageType(nd)); + _iterCurr.EnsureItemStorageType(nd.XmlType!, GetItemStorageType(nd)); EndNestedIterator(nd); - _iterCurr.Storage = _iterNested.Storage; + _iterCurr.Storage = _iterNested!.Storage; } /// @@ -4810,7 +4814,7 @@ private void NestedVisitEnsureLocal(QilNode nd, LocalBuilder loc) /// private void NestedVisitWithBranch(QilNode nd, BranchingContext brctxt, Label lblBranch) { - Debug.Assert(nd.XmlType.IsSingleton && !XmlILConstructInfo.Read(nd).PushToWriterLast); + Debug.Assert(nd.XmlType!.IsSingleton && !XmlILConstructInfo.Read(nd).PushToWriterLast); StartNestedIterator(nd); _iterCurr.SetBranching(brctxt, lblBranch); Visit(nd); @@ -4837,7 +4841,7 @@ private void NestedVisitEnsureCache(QilNode nd, Type itemStorageType) StartNestedIterator(nd); Visit(nd); EndNestedIterator(nd); - _iterCurr.Storage = _iterNested.Storage; + _iterCurr.Storage = _iterNested!.Storage; Debug.Assert(_iterCurr.Storage.IsCached, "Expression result should be cached. CachesResult() might have a bug in it."); // If type of items in the cache matches "itemStorageType", then done @@ -4848,7 +4852,7 @@ private void NestedVisitEnsureCache(QilNode nd, Type itemStorageType) // can directly convert without needing to create a new cache. if (_iterCurr.Storage.ItemStorageType == typeof(XPathNavigator) || itemStorageType == typeof(XPathNavigator)) { - _iterCurr.EnsureItemStorageType(nd.XmlType, itemStorageType); + _iterCurr.EnsureItemStorageType(nd.XmlType!, itemStorageType); return; } @@ -4864,7 +4868,7 @@ private void NestedVisitEnsureCache(QilNode nd, Type itemStorageType) _helper.Emit(OpCodes.Ldloc, locCache); // Special case non-navigator singletons to use overload of CreateOrReuse - if (nd.XmlType.IsSingleton) + if (nd.XmlType!.IsSingleton) { // cache = XmlQuerySequence.CreateOrReuse(cache, item); NestedVisitEnsureStack(nd, cacheType, false); @@ -4882,7 +4886,7 @@ private void NestedVisitEnsureCache(QilNode nd, Type itemStorageType) StartNestedIterator(nd, lblOnEnd); if (cachesResult) - _iterCurr.Storage = _iterCurr.ParentIterator.Storage; + _iterCurr.Storage = _iterCurr.ParentIterator!.Storage; else Visit(nd); @@ -4919,7 +4923,7 @@ private bool CachesResult(QilNode nd) case QilNodeType.Invoke: case QilNodeType.XsltInvokeLateBound: case QilNodeType.XsltInvokeEarlyBound: - return !nd.XmlType.IsSingleton; + return !nd.XmlType!.IsSingleton; case QilNodeType.Filter: // EqualityIndex pattern caches results @@ -4927,7 +4931,7 @@ private bool CachesResult(QilNode nd) return patt.MatchesPattern(OptimizerPatternName.EqualityIndex); case QilNodeType.DocOrderDistinct: - if (nd.XmlType.IsSingleton) + if (nd.XmlType!.IsSingleton) return false; // JoinAndDod and DodReverse patterns don't cache results @@ -4948,7 +4952,7 @@ private bool CachesResult(QilNode nd) /// private Type GetStorageType(QilNode nd) { - return XmlILTypeHelper.GetStorageType(nd.XmlType); + return XmlILTypeHelper.GetStorageType(nd.XmlType!); } /// @@ -4964,7 +4968,7 @@ private Type GetStorageType(XmlQueryType typ) /// private Type GetItemStorageType(QilNode nd) { - return XmlILTypeHelper.GetStorageType(nd.XmlType.Prime); + return XmlILTypeHelper.GetStorageType(nd.XmlType!.Prime); } /// diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/ListBase.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/ListBase.cs index 6d43e7c04d791..e9e85c1d8e6a1 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/ListBase.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/ListBase.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Xml; using System.Xml.Schema; @@ -8,6 +9,7 @@ using System.Diagnostics; using System.Text; using System.Reflection; +using System.Diagnostics.CodeAnalysis; namespace System.Xml.Xsl { @@ -37,7 +39,7 @@ public virtual bool Contains(T value) public virtual int IndexOf(T value) { for (int i = 0; i < Count; i++) - if (value.Equals(this[i])) + if (value!.Equals(this[i])) return i; return -1; @@ -127,21 +129,21 @@ void System.Collections.ICollection.CopyTo(Array array, int index) array.SetValue(this[i], index); } - object System.Collections.IList.this[int index] + object? System.Collections.IList.this[int index] { get { return this[index]; } set { - if (!IsCompatibleType(value.GetType())) + if (!IsCompatibleType(value!.GetType())) throw new ArgumentException(SR.Arg_IncompatibleParamType, nameof(value)); this[index] = (T)value; } } - int System.Collections.IList.Add(object value) + int System.Collections.IList.Add(object? value) { - if (!IsCompatibleType(value.GetType())) + if (!IsCompatibleType(value!.GetType())) throw new ArgumentException(SR.Arg_IncompatibleParamType, nameof(value)); Add((T)value); @@ -153,33 +155,33 @@ void System.Collections.IList.Clear() Clear(); } - bool System.Collections.IList.Contains(object value) + bool System.Collections.IList.Contains(object? value) { - if (!IsCompatibleType(value.GetType())) + if (!IsCompatibleType(value!.GetType())) return false; return Contains((T)value); } - int System.Collections.IList.IndexOf(object value) + int System.Collections.IList.IndexOf(object? value) { - if (!IsCompatibleType(value.GetType())) + if (!IsCompatibleType(value!.GetType())) return -1; return IndexOf((T)value); } - void System.Collections.IList.Insert(int index, object value) + void System.Collections.IList.Insert(int index, object? value) { - if (!IsCompatibleType(value.GetType())) + if (!IsCompatibleType(value!.GetType())) throw new ArgumentException(SR.Arg_IncompatibleParamType, nameof(value)); Insert(index, (T)value); } - void System.Collections.IList.Remove(object value) + void System.Collections.IList.Remove(object? value) { - if (IsCompatibleType(value.GetType())) + if (IsCompatibleType(value!.GetType())) { Remove((T)value); } @@ -190,7 +192,7 @@ void System.Collections.IList.Remove(object value) // Helper methods and classes //----------------------------------------------- - private static bool IsCompatibleType(object value) + private static bool IsCompatibleType(object? value) { if ((value == null && !typeof(T).IsValueType) || (value is T)) return true; @@ -215,7 +217,7 @@ public IListEnumerator(IList sequence) { _sequence = sequence; _index = 0; - _current = default(T); + _current = default(T)!; } /// @@ -246,7 +248,7 @@ object System.Collections.IEnumerator.Current if (_index > _sequence.Count) throw new InvalidOperationException(SR.Format(SR.Sch_EnumFinished, string.Empty)); - return _current; + return _current!; } } @@ -262,7 +264,7 @@ public bool MoveNext() return true; } - _current = default(T); + _current = default(T)!; return false; } @@ -272,7 +274,7 @@ public bool MoveNext() void System.Collections.IEnumerator.Reset() { _index = 0; - _current = default(T); + _current = default(T)!; } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Pair.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Pair.cs index 478b5a78d9e80..893ec61b7b9e5 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Pair.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Pair.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; @@ -20,7 +21,7 @@ public Int32Pair(int left, int right) public int Left { get { return _left; } } public int Right { get { return _right; } } - public override bool Equals(object other) + public override bool Equals(object? other) { if (other is Int32Pair) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilBinary.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilBinary.cs index 47765658b99ff..a71c32a6e8dd9 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilBinary.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilBinary.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilChoice.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilChoice.cs index daff0690f6d2b..2a3a6ec1dfddb 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilChoice.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilChoice.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections; using System.Diagnostics; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilCloneVisitor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilCloneVisitor.cs index 8a253a29fd899..2865ecc906b31 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilCloneVisitor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilCloneVisitor.cs @@ -1,9 +1,11 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Xml; using System.Xml.Xsl; @@ -52,10 +54,10 @@ public QilNode Clone(QilNode node) /// protected override QilNode Visit(QilNode oldNode) { - QilNode newNode = null; + QilNode? newNode = null; if (oldNode == null) - return null; + return null!; // ShallowClone any nodes which have not yet been cloned if (oldNode is QilReference) @@ -93,7 +95,7 @@ protected override QilNode VisitChildren(QilNode parent) else { // Otherwise, visit the node and substitute its copy - parent[i] = Visit(child); + parent[i] = Visit(child)!; } } @@ -105,7 +107,7 @@ protected override QilNode VisitChildren(QilNode parent) /// protected override QilNode VisitReference(QilNode oldNode) { - QilNode newNode = FindClonedReference(oldNode); + QilNode? newNode = FindClonedReference(oldNode); return base.VisitReference(newNode == null ? oldNode : newNode); } @@ -138,7 +140,7 @@ protected override void EndScope(QilNode node) /// /// Find the clone of an in-scope reference. /// - protected QilNode FindClonedReference(QilNode node) + protected QilNode? FindClonedReference(QilNode node) { return _subs.FindReplacement(node); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilDataSource.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilDataSource.cs index 99ad88b9a45a2..cca511141a674 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilDataSource.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilDataSource.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections.Generic; using System.Xml.Schema; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilExpression.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilExpression.cs index d24583ff88d4a..74378ec7f6435 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilExpression.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilExpression.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections.Generic; using System.Xml.Xsl.Runtime; @@ -119,7 +120,7 @@ public bool IsDebug /// public XmlWriterSettings DefaultWriterSettings { - get { return (XmlWriterSettings)((QilLiteral)_defWSet).Value; } + get { return (XmlWriterSettings)((QilLiteral)_defWSet).Value!; } set { value.ReadOnly = true; @@ -132,7 +133,7 @@ public XmlWriterSettings DefaultWriterSettings /// public IList WhitespaceRules { - get { return (IList)((QilLiteral)_wsRules).Value; } + get { return (IList)((QilLiteral)_wsRules).Value!; } set { ((QilLiteral)_wsRules).Value = value; } } @@ -159,7 +160,7 @@ public QilList GlobalVariableList /// public IList EarlyBoundTypes { - get { return (IList)((QilLiteral)_earlBnd).Value; } + get { return (IList)((QilLiteral)_earlBnd).Value!; } set { ((QilLiteral)_earlBnd).Value = value; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilFactory.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilFactory.cs index d052c40f55c88..695fc459e78b9 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilFactory.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilFactory.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections.Generic; namespace System.Xml.Xsl.Qil @@ -236,7 +237,7 @@ public QilIterator Let(QilNode binding) return n; } - public QilParameter Parameter(QilNode defaultValue, QilNode name, XmlQueryType xmlType) + public QilParameter Parameter(QilNode? defaultValue, QilNode? name, XmlQueryType xmlType) { QilParameter n = new QilParameter(QilNodeType.Parameter, defaultValue, name, xmlType); n.XmlType = _typeCheck.CheckParameter(n); @@ -274,7 +275,7 @@ public QilNode False() return n; } - public QilLiteral LiteralString(string value) + public QilLiteral LiteralString(string? value) { QilLiteral n = new QilLiteral(QilNodeType.LiteralString, value); n.XmlType = _typeCheck.CheckLiteralString(n); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilFunction.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilFunction.cs index b6dd25a1c8da8..d00e2262c141e 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilFunction.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilFunction.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilInvoke.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilInvoke.cs index 0530d062e2c9a..48326db762dc9 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilInvoke.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilInvoke.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; using System.Xml.Schema; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilInvokeEarlyBound.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilInvokeEarlyBound.cs index 7f775dbb455e8..b8e07b16e937d 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilInvokeEarlyBound.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilInvokeEarlyBound.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; using System.Reflection; @@ -38,7 +39,7 @@ public QilName Name public MethodInfo ClrMethod { - get { return (MethodInfo)((QilLiteral)Center).Value; } + get { return (MethodInfo)((QilLiteral)Center).Value!; } set { ((QilLiteral)Center).Value = value; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilInvokeLateBound.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilInvokeLateBound.cs index dfa095333190e..a558cc2f65f2f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilInvokeLateBound.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilInvokeLateBound.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilIterator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilIterator.cs index 6d3c464128f5b..3a9247e91347c 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilIterator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilIterator.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; @@ -11,7 +12,7 @@ namespace System.Xml.Xsl.Qil /// internal class QilIterator : QilReference { - private QilNode _binding; + private QilNode? _binding; //----------------------------------------------- // Constructor @@ -20,7 +21,7 @@ internal class QilIterator : QilReference /// /// Construct an iterator /// - public QilIterator(QilNodeType nodeType, QilNode binding) : base(nodeType) + public QilIterator(QilNodeType nodeType, QilNode? binding) : base(nodeType) { Binding = binding; } @@ -37,7 +38,7 @@ public override int Count public override QilNode this[int index] { - get { if (index != 0) throw new IndexOutOfRangeException(); return _binding; } + get { if (index != 0) throw new IndexOutOfRangeException(); return _binding!; } set { if (index != 0) throw new IndexOutOfRangeException(); _binding = value; } } @@ -49,7 +50,7 @@ public override QilNode this[int index] /// /// Expression which is bound to the iterator. /// - public QilNode Binding + public QilNode? Binding { get { return _binding; } set { _binding = value; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilList.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilList.cs index 9061249c03ecd..171fde25f79ec 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilList.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilList.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; @@ -53,15 +54,15 @@ public override XmlQueryType XmlType if (this.nodeType == QilNodeType.Sequence) { for (int i = 0; i < _count; i++) - xt = XmlQueryTypeFactory.Sequence(xt, _members[i].XmlType); + xt = XmlQueryTypeFactory.Sequence(xt, _members[i].XmlType!); Debug.Assert(!xt.IsDod, "Sequences do not preserve DocOrderDistinct"); } else if (this.nodeType == QilNodeType.BranchList) { - xt = _members[0].XmlType; + xt = _members[0].XmlType!; for (int i = 1; i < _count; i++) - xt = XmlQueryTypeFactory.Choice(xt, _members[i].XmlType); + xt = XmlQueryTypeFactory.Choice(xt, _members[i].XmlType!); } } @@ -145,7 +146,7 @@ public override void RemoveAt(int index) if (index < _count) Array.Copy(_members, index + 1, _members, index, _count - index); - _members[_count] = null; + _members[_count] = null!; // Invalidate XmlType this.xmlType = null; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilLiteral.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilLiteral.cs index b40a74482f47e..c86dbb2712ff9 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilLiteral.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilLiteral.cs @@ -1,8 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Xml.Xsl.Qil { @@ -14,7 +16,7 @@ namespace System.Xml.Xsl.Qil /// internal class QilLiteral : QilNode { - private object _value; + private object? _value; //----------------------------------------------- @@ -24,7 +26,7 @@ internal class QilLiteral : QilNode /// /// Construct a new node /// - public QilLiteral(QilNodeType nodeType, object value) : base(nodeType) + public QilLiteral(QilNodeType nodeType, object? value) : base(nodeType) { Value = value; } @@ -33,8 +35,7 @@ public QilLiteral(QilNodeType nodeType, object value) : base(nodeType) //----------------------------------------------- // QilLiteral methods //----------------------------------------------- - - public object Value + public object? Value { get { return _value; } set { _value = value; } @@ -42,32 +43,32 @@ public object Value public static implicit operator string(QilLiteral literal) { - return (string)literal._value; + return (string)literal._value!; } public static implicit operator int(QilLiteral literal) { - return (int)literal._value; + return (int)literal._value!; } public static implicit operator long(QilLiteral literal) { - return (long)literal._value; + return (long)literal._value!; } public static implicit operator double(QilLiteral literal) { - return (double)literal._value; + return (double)literal._value!; } public static implicit operator decimal(QilLiteral literal) { - return (decimal)literal._value; + return (decimal)literal._value!; } public static implicit operator XmlQueryType(QilLiteral literal) { - return (XmlQueryType)literal._value; + return (XmlQueryType)literal._value!; } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilLoop.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilLoop.cs index b3f2f29898563..cfe90c421faff 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilLoop.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilLoop.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections; using System.Diagnostics; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs index 6526eac1ef6c0..a51f7597c50d6 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs @@ -1,8 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Xml.Xsl.Qil { @@ -42,18 +44,21 @@ public QilName(QilNodeType nodeType, string local, string uri, string prefix) : public string LocalName { get { return _local; } + [MemberNotNull(nameof(_local))] set { _local = value; } } public string NamespaceUri { get { return _uri; } + [MemberNotNull(nameof(_uri))] set { _uri = value; } } public string Prefix { get { return _prefix; } + [MemberNotNull(nameof(_prefix))] set { _prefix = value; } } @@ -88,9 +93,9 @@ public override int GetHashCode() /// Override Equals() so that the QilName can be used as a key in the hashtable. /// /// Does not compare their prefixes (if any). - public override bool Equals(object other) + public override bool Equals(object? other) { - QilName name = other as QilName; + QilName? name = other as QilName; if (name == null) return false; @@ -101,13 +106,13 @@ public override bool Equals(object other) /// Implement operator == to prevent accidental referential comparison /// /// Does not compare their prefixes (if any). - public static bool operator ==(QilName a, QilName b) + public static bool operator ==(QilName? a, QilName? b) { - if ((object)a == (object)b) + if ((object?)a == (object?)b) { return true; } - if ((object)a == null || (object)b == null) + if ((object?)a == null || (object?)b == null) { return false; } @@ -118,7 +123,7 @@ public override bool Equals(object other) /// Implement operator != to prevent accidental referential comparison /// /// Does not compare their prefixes (if any). - public static bool operator !=(QilName a, QilName b) + public static bool operator !=(QilName? a, QilName? b) { return !(a == b); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilNode.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilNode.cs index 9c1f146beaa3e..cd2cca2f7a0c5 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilNode.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilNode.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections; using System.Collections.Generic; @@ -22,9 +23,9 @@ namespace System.Xml.Xsl.Qil internal class QilNode : IList { protected QilNodeType nodeType; - protected XmlQueryType xmlType; - protected ISourceLineInfo sourceLine; - protected object annotation; + protected XmlQueryType? xmlType; + protected ISourceLineInfo? sourceLine; + protected object? annotation; //----------------------------------------------- // Constructor @@ -64,7 +65,7 @@ public QilNodeType NodeType /// /// Access the QIL type. /// - public virtual XmlQueryType XmlType + public virtual XmlQueryType? XmlType { get { return this.xmlType; } set { this.xmlType = value; } @@ -73,7 +74,7 @@ public virtual XmlQueryType XmlType /// /// Line info information for tools support. /// - public ISourceLineInfo SourceLine + public ISourceLineInfo? SourceLine { get { return this.sourceLine; } set { this.sourceLine = value; } @@ -82,7 +83,7 @@ public ISourceLineInfo SourceLine /// /// Access an annotation which may have been attached to this node. /// - public object Annotation + public object? Annotation { get { return this.annotation; } set { this.annotation = value; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilNodeType.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilNodeType.cs index c9973ae9a2443..387544491a6cb 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilNodeType.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilNodeType.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable namespace System.Xml.Xsl.Qil { /// An enumeration of all the possible QilExpression node types. diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilParameter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilParameter.cs index c2e5add838c33..085962bbbbbd3 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilParameter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilParameter.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; @@ -11,7 +12,7 @@ namespace System.Xml.Xsl.Qil /// internal class QilParameter : QilIterator { - private QilNode _name; + private QilNode? _name; //----------------------------------------------- // Constructor @@ -20,7 +21,7 @@ internal class QilParameter : QilIterator /// /// Construct a parameter /// - public QilParameter(QilNodeType nodeType, QilNode defaultValue, QilNode name, XmlQueryType xmlType) : base(nodeType, defaultValue) + public QilParameter(QilNodeType nodeType, QilNode? defaultValue, QilNode? name, XmlQueryType xmlType) : base(nodeType, defaultValue) { _name = name; this.xmlType = xmlType; @@ -42,8 +43,8 @@ public override QilNode this[int index] { return index switch { - 0 => Binding, - 1 => _name, + 0 => Binding!, + 1 => _name!, _ => throw new IndexOutOfRangeException(), }; } @@ -66,7 +67,7 @@ public override QilNode this[int index] /// /// Default value expression of this parameter (may be null). /// - public QilNode DefaultValue + public QilNode? DefaultValue { get { return Binding; } set { Binding = value; } @@ -75,9 +76,9 @@ public QilNode DefaultValue /// /// Name of this parameter (may be null). /// - public QilName Name + public QilName? Name { - get { return (QilName)_name; } + get { return (QilName?)_name; } set { _name = value; } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilPatternFactory.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilPatternFactory.cs index 5a3bfb047fb86..5d655c188d023 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilPatternFactory.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilPatternFactory.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.Reflection; @@ -33,7 +34,7 @@ public QilPatternFactory(QilFactory f, bool debug) #region Convenience methods - public QilLiteral String(string val) + public QilLiteral String(string? val) { return _f.LiteralString(val); } @@ -186,7 +187,7 @@ public QilParameter Parameter(XmlQueryType t) return _f.Parameter(t); } - public QilParameter Parameter(QilNode defaultValue, QilName name, XmlQueryType t) + public QilParameter Parameter(QilNode? defaultValue, QilName? name, XmlQueryType t) { return _f.Parameter(defaultValue, name, t); } @@ -226,7 +227,7 @@ public QilNode Boolean(bool b) private static void CheckLogicArg(QilNode arg) { Debug.Assert(arg != null, "Argument shouldn't be null"); - Debug.Assert(arg.XmlType.TypeCode == XmlTypeCode.Boolean && arg.XmlType.IsSingleton, + Debug.Assert(arg.XmlType!.TypeCode == XmlTypeCode.Boolean && arg.XmlType.IsSingleton, "The operand must be boolean-typed" ); } @@ -443,7 +444,7 @@ public QilNode StrConcat(QilNode values) { if (!_debug) { - if (values.XmlType.IsSingleton) + if (values.XmlType!.IsSingleton) return values; } return _f.StrConcat(values); @@ -551,7 +552,7 @@ public QilNode Filter(QilIterator variable, QilNode expr) //((Filter (For $Binding) (True ) ) => ($binding)) if (expr.NodeType == QilNodeType.True) { - return variable.Binding; + return variable.Binding!; } // The following optimization is not safe if the iterator has side effects //((Filter (For $Binding) (False) ) => (Sequence)) @@ -598,7 +599,7 @@ public QilFunction Function(QilList args, QilNode sideEffects, XmlQueryType resu public QilFunction Function(QilList args, QilNode defn, QilNode sideEffects) { Debug.Assert(args.NodeType == QilNodeType.FormalParameterList); - return _f.Function(args, defn, sideEffects, defn.XmlType); + return _f.Function(args, defn, sideEffects, defn.XmlType!); } public QilNode Invoke(QilFunction func, QilList args) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilPatternVisitor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilPatternVisitor.cs index d77d8bcc8d273..8e82891582d0b 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilPatternVisitor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilPatternVisitor.cs @@ -1,7 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections; +using System.Diagnostics.CodeAnalysis; namespace System.Xml.Xsl.Qil { @@ -63,7 +65,8 @@ protected virtual QilNode Replace(int pattern, QilNode original, QilNode replace /// /// Called when all replacements have already been made and all annotations are complete. /// - protected virtual QilNode NoReplace(QilNode node) + [return: NotNullIfNotNull("node")] + protected virtual QilNode? NoReplace(QilNode? node) { return node; } @@ -79,7 +82,7 @@ protected virtual QilNode NoReplace(QilNode node) protected override QilNode Visit(QilNode node) { if (node == null) - return VisitNull(); + return VisitNull()!; node = VisitChildren(node); return base.Visit(node); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilReference.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilReference.cs index 973086fde8448..107a645db29c3 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilReference.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilReference.cs @@ -1,8 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Xml.Xsl.Qil { @@ -17,7 +19,7 @@ internal class QilReference : QilNode // the truncation. private const int MaxDebugNameLength = 1000; - private string _debugName; + private string? _debugName; //----------------------------------------------- // Constructor @@ -38,7 +40,8 @@ public QilReference(QilNodeType nodeType) : base(nodeType) /// /// Name of this reference, preserved for debugging (may be null). /// - public string DebugName + [DisallowNull] + public string? DebugName { get { return _debugName; } set diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilReplaceVisitor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilReplaceVisitor.cs index f03325553d319..a7799c4e2a1df 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilReplaceVisitor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilReplaceVisitor.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections; using System.Collections.Generic; @@ -31,23 +32,23 @@ public QilReplaceVisitor(QilFactory f) /// protected override QilNode VisitChildren(QilNode parent) { - XmlQueryType oldParentType = parent.XmlType; + XmlQueryType oldParentType = parent.XmlType!; bool recalcType = false; // Visit children for (int i = 0; i < parent.Count; i++) { QilNode oldChild = parent[i], newChild; - XmlQueryType oldChildType = oldChild != null ? oldChild.XmlType : null; + XmlQueryType? oldChildType = oldChild != null ? oldChild.XmlType : null; // Visit child if (IsReference(parent, i)) - newChild = VisitReference(oldChild); + newChild = VisitReference(oldChild!); else - newChild = Visit(oldChild); + newChild = Visit(oldChild!); // Only replace child and recalculate type if oldChild != newChild or oldChild.XmlType != newChild.XmlType - if ((object)oldChild != (object)newChild || (newChild != null && (object)oldChildType != (object)newChild.XmlType)) + if ((object?)oldChild != (object)newChild || (newChild != null && (object?)oldChildType != (object?)newChild.XmlType)) { recalcType = true; parent[i] = newChild; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilScopedVisitor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilScopedVisitor.cs index 84b4cba516826..01519661151b8 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilScopedVisitor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilScopedVisitor.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections.Generic; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilSortKey.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilSortKey.cs index 073e8a291fd67..cab41ac94651f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilSortKey.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilSortKey.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilStrConcat.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilStrConcat.cs index 8dafd52113c44..49761767eed57 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilStrConcat.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilStrConcat.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTargetType.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTargetType.cs index dc159addb54b7..e5c77760b5385 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTargetType.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTargetType.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections.Generic; using System.Xml.Schema; @@ -40,7 +41,7 @@ public QilNode Source public XmlQueryType TargetType { - get { return (XmlQueryType)((QilLiteral)Right).Value; } + get { return (XmlQueryType)((QilLiteral)Right).Value!; } set { ((QilLiteral)Right).Value = value; } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTernary.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTernary.cs index 787937751c414..86ddd1fe85a34 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTernary.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTernary.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTypeChecker.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTypeChecker.cs index d560c09507e6d..ac947b5a9ed9f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTypeChecker.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTypeChecker.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections; using System.Collections.Generic; @@ -227,12 +228,12 @@ public XmlQueryType CheckBranchList(QilList node) public XmlQueryType CheckOptimizeBarrier(QilUnary node) { - return node.Child.XmlType; + return node.Child.XmlType!; } public XmlQueryType CheckUnknown(QilNode node) { - return node.XmlType; + return node.XmlType!; } #endregion // meta @@ -250,7 +251,7 @@ public XmlQueryType CheckDataSource(QilDataSource node) public XmlQueryType CheckNop(QilUnary node) { - return node.Child.XmlType; + return node.Child.XmlType!; } public XmlQueryType CheckError(QilUnary node) @@ -273,18 +274,18 @@ public XmlQueryType CheckWarning(QilUnary node) //----------------------------------------------- public XmlQueryType CheckFor(QilIterator node) { - return node.Binding.XmlType.Prime; + return node.Binding!.XmlType!.Prime; } public XmlQueryType CheckLet(QilIterator node) { - return node.Binding.XmlType; + return node.Binding!.XmlType!; } public XmlQueryType CheckParameter(QilParameter node) { - Check(node.Binding == null || node.Binding.XmlType.IsSubtypeOf(node.XmlType), node, "Parameter binding's xml type must be a subtype of the parameter's type"); - return node.XmlType; + Check(node.Binding == null || node.Binding.XmlType!.IsSubtypeOf(node.XmlType!), node, "Parameter binding's xml type must be a subtype of the parameter's type"); + return node.XmlType!; } public XmlQueryType CheckPositionOf(QilUnary node) @@ -391,7 +392,7 @@ public XmlQueryType CheckNot(QilUnary node) public XmlQueryType CheckConditional(QilTernary node) { CheckXmlType(node.Left, XmlQueryTypeFactory.BooleanX); - return XmlQueryTypeFactory.Choice(node.Center.XmlType, node.Right.XmlType); + return XmlQueryTypeFactory.Choice(node.Center.XmlType!, node.Right.XmlType!); } public XmlQueryType CheckChoice(QilChoice node) @@ -422,7 +423,7 @@ public XmlQueryType CheckUnion(QilBinary node) { CheckXmlType(node.Left, XmlQueryTypeFactory.NodeNotRtfS); CheckXmlType(node.Right, XmlQueryTypeFactory.NodeNotRtfS); - return DistinctType(XmlQueryTypeFactory.Sequence(node.Left.XmlType, node.Right.XmlType)); + return DistinctType(XmlQueryTypeFactory.Sequence(node.Left.XmlType!, node.Right.XmlType!)); } public XmlQueryType CheckIntersection(QilBinary node) @@ -434,12 +435,12 @@ public XmlQueryType CheckDifference(QilBinary node) { CheckXmlType(node.Left, XmlQueryTypeFactory.NodeNotRtfS); CheckXmlType(node.Right, XmlQueryTypeFactory.NodeNotRtfS); - return XmlQueryTypeFactory.AtMost(node.Left.XmlType, node.Left.XmlType.Cardinality); + return XmlQueryTypeFactory.AtMost(node.Left.XmlType!, node.Left.XmlType!.Cardinality); } public XmlQueryType CheckAverage(QilUnary node) { - XmlQueryType xmlType = node.Child.XmlType; + XmlQueryType xmlType = node.Child.XmlType!; CheckNumericXS(node.Child); return XmlQueryTypeFactory.PrimeProduct(xmlType, xmlType.MaybeEmpty ? XmlQueryCardinality.ZeroOrOne : XmlQueryCardinality.One); } @@ -468,7 +469,7 @@ public XmlQueryType CheckMaximum(QilUnary node) public XmlQueryType CheckNegate(QilUnary node) { CheckNumericX(node.Child); - return node.Child.XmlType; + return node.Child.XmlType!; } public XmlQueryType CheckAdd(QilBinary node) @@ -476,7 +477,7 @@ public XmlQueryType CheckAdd(QilBinary node) CheckNumericX(node.Left); CheckNumericX(node.Right); CheckNotDisjoint(node); - return node.Left.XmlType.TypeCode == XmlTypeCode.None ? node.Right.XmlType : node.Left.XmlType; + return node.Left.XmlType!.TypeCode == XmlTypeCode.None ? node.Right.XmlType! : node.Left.XmlType!; } public XmlQueryType CheckSubtract(QilBinary node) @@ -521,7 +522,7 @@ public XmlQueryType CheckStrConcat(QilStrConcat node) public XmlQueryType CheckStrParseQName(QilBinary node) { CheckXmlType(node.Left, XmlQueryTypeFactory.StringX); - Check(node.Right.XmlType.IsSubtypeOf(XmlQueryTypeFactory.StringX) || node.Right.XmlType.IsSubtypeOf(XmlQueryTypeFactory.NamespaceS), + Check(node.Right.XmlType!.IsSubtypeOf(XmlQueryTypeFactory.StringX) || node.Right.XmlType.IsSubtypeOf(XmlQueryTypeFactory.NamespaceS), node, "StrParseQName must take either a string or a list of namespace as its second argument"); return XmlQueryTypeFactory.QNameX; } @@ -599,8 +600,8 @@ public XmlQueryType CheckLoop(QilLoop node) CheckClass(node[0], typeof(QilIterator)); Check(node.Variable.NodeType == QilNodeType.For || node.Variable.NodeType == QilNodeType.Let, node, "Loop variable must be a For or Let iterator"); - XmlQueryType bodyType = node.Body.XmlType; - XmlQueryCardinality variableCard = node.Variable.NodeType == QilNodeType.Let ? XmlQueryCardinality.One : node.Variable.Binding.XmlType.Cardinality; + XmlQueryType bodyType = node.Body.XmlType!; + XmlQueryCardinality variableCard = node.Variable.NodeType == QilNodeType.Let ? XmlQueryCardinality.One : node.Variable.Binding!.XmlType!.Cardinality; // Loops do not preserve DocOrderDistinct return XmlQueryTypeFactory.PrimeProduct(bodyType, variableCard * bodyType.Cardinality); @@ -613,11 +614,11 @@ public XmlQueryType CheckFilter(QilLoop node) CheckXmlType(node.Body, XmlQueryTypeFactory.BooleanX); // Attempt to restrict filter's type by checking condition - XmlQueryType filterType = FindFilterType(node.Variable, node.Body); + XmlQueryType? filterType = FindFilterType(node.Variable, node.Body); if (filterType != null) return filterType; - return XmlQueryTypeFactory.AtMost(node.Variable.Binding.XmlType, node.Variable.Binding.XmlType.Cardinality); + return XmlQueryTypeFactory.AtMost(node.Variable.Binding!.XmlType!, node.Variable.Binding.XmlType!.Cardinality); } #endregion // loops @@ -628,7 +629,7 @@ public XmlQueryType CheckFilter(QilLoop node) //----------------------------------------------- public XmlQueryType CheckSort(QilLoop node) { - XmlQueryType varType = node.Variable.Binding.XmlType; + XmlQueryType varType = node.Variable.Binding!.XmlType!; CheckClassAndNodeType(node[0], typeof(QilIterator), QilNodeType.For); CheckClassAndNodeType(node[1], typeof(QilList), QilNodeType.SortKeyList); @@ -641,13 +642,13 @@ public XmlQueryType CheckSortKey(QilSortKey node) { CheckAtomicX(node.Key); CheckXmlType(node.Collation, XmlQueryTypeFactory.StringX); - return node.Key.XmlType; + return node.Key.XmlType!; } public XmlQueryType CheckDocOrderDistinct(QilUnary node) { CheckXmlType(node.Child, XmlQueryTypeFactory.NodeNotRtfS); - return DistinctType(node.Child.XmlType); + return DistinctType(node.Child.XmlType!); } #endregion // sorting @@ -660,8 +661,8 @@ public XmlQueryType CheckFunction(QilFunction node) { CheckClassAndNodeType(node[0], typeof(QilList), QilNodeType.FormalParameterList); Check(node[2].NodeType == QilNodeType.False || node[2].NodeType == QilNodeType.True, node, "SideEffects must either be True or False"); - Check(node.Definition.XmlType.IsSubtypeOf(node.XmlType), node, "Function definition's xml type must be a subtype of the function's return type"); - return node.XmlType; + Check(node.Definition.XmlType!.IsSubtypeOf(node.XmlType!), node, "Function definition's xml type must be a subtype of the function's return type"); + return node.XmlType!; } public XmlQueryType CheckInvoke(QilInvoke node) @@ -674,10 +675,10 @@ public XmlQueryType CheckInvoke(QilInvoke node) Check(actualArgs.Count == formalArgs.Count, actualArgs, "Invoke argument count must match function's argument count"); for (int i = 0; i < actualArgs.Count; i++) - Check(actualArgs[i].XmlType.IsSubtypeOf(formalArgs[i].XmlType), actualArgs[i], "Invoke argument must be a subtype of the invoked function's argument"); + Check(actualArgs[i].XmlType!.IsSubtypeOf(formalArgs[i].XmlType!), actualArgs[i], "Invoke argument must be a subtype of the invoked function's argument"); #endif - return node.Function.XmlType; + return node.Function.XmlType!; } #endregion // function definition and invocation @@ -725,7 +726,7 @@ public XmlQueryType CheckDescendant(QilUnary node) public XmlQueryType CheckDescendantOrSelf(QilUnary node) { CheckXmlType(node.Child, XmlQueryTypeFactory.NodeNotRtf); - return XmlQueryTypeFactory.Choice(node.Child.XmlType, XmlQueryTypeFactory.ContentS); + return XmlQueryTypeFactory.Choice(node.Child.XmlType!, XmlQueryTypeFactory.ContentS); } public XmlQueryType CheckAncestor(QilUnary node) @@ -737,7 +738,7 @@ public XmlQueryType CheckAncestor(QilUnary node) public XmlQueryType CheckAncestorOrSelf(QilUnary node) { CheckXmlType(node.Child, XmlQueryTypeFactory.NodeNotRtf); - return XmlQueryTypeFactory.Choice(node.Child.XmlType, XmlQueryTypeFactory.DocumentOrElementS); + return XmlQueryTypeFactory.Choice(node.Child.XmlType!, XmlQueryTypeFactory.DocumentOrElementS); } public XmlQueryType CheckPreceding(QilUnary node) @@ -762,7 +763,7 @@ public XmlQueryType CheckNodeRange(QilBinary node) { CheckXmlType(node.Left, XmlQueryTypeFactory.NodeNotRtf); CheckXmlType(node.Right, XmlQueryTypeFactory.NodeNotRtf); - return XmlQueryTypeFactory.Choice(node.Left.XmlType, XmlQueryTypeFactory.ContentS, node.Right.XmlType); + return XmlQueryTypeFactory.Choice(node.Left.XmlType!, XmlQueryTypeFactory.ContentS, node.Right.XmlType!); } public XmlQueryType CheckDeref(QilBinary node) @@ -955,25 +956,25 @@ public XmlQueryType CheckXsltInvokeEarlyBound(QilInvokeEarlyBound node) for (int i = 0; i < actualArgs.Count; i++) { - Check(actualArgs[i].XmlType.IsSubtypeOf(extFunc.GetXmlArgumentType(i)), actualArgs[i], "InvokeEarlyBound argument must be a subtype of the invoked function's argument type"); + Check(actualArgs[i].XmlType!.IsSubtypeOf(extFunc.GetXmlArgumentType(i)), actualArgs[i], "InvokeEarlyBound argument must be a subtype of the invoked function's argument type"); } #endif - return node.XmlType; + return node.XmlType!; } public XmlQueryType CheckXsltCopy(QilBinary node) { CheckXmlType(node.Left, XmlQueryTypeFactory.NodeNotRtf); CheckXmlType(node.Right, XmlQueryTypeFactory.NodeS); - return XmlQueryTypeFactory.Choice(node.Left.XmlType, node.Right.XmlType); + return XmlQueryTypeFactory.Choice(node.Left.XmlType!, node.Right.XmlType!); } public XmlQueryType CheckXsltCopyOf(QilUnary node) { CheckXmlType(node.Child, XmlQueryTypeFactory.Node); - if ((node.Child.XmlType.NodeKinds & XmlNodeKindFlags.Document) != 0) + if ((node.Child.XmlType!.NodeKinds & XmlNodeKindFlags.Document) != 0) return XmlQueryTypeFactory.NodeNotRtfS; return node.Child.XmlType; @@ -1003,7 +1004,7 @@ private void CheckLiteralValue(QilNode node, Type clrTypeValue) { Check(node is QilLiteral, node, "Node must be instance of QilLiteral"); - Type clrType = ((QilLiteral)node).Value.GetType(); + Type clrType = ((QilLiteral)node).Value!.GetType(); Check(clrTypeValue.IsAssignableFrom(clrType), node, "Literal value must be of type " + clrTypeValue.Name); } @@ -1023,31 +1024,31 @@ private void CheckClassAndNodeType(QilNode node, Type clrTypeClass, QilNodeType [Conditional("DEBUG")] private void CheckXmlType(QilNode node, XmlQueryType xmlType) { - Check(node.XmlType.IsSubtypeOf(xmlType), node, "Node's type " + node.XmlType + " is not a subtype of " + xmlType); + Check(node.XmlType!.IsSubtypeOf(xmlType), node, "Node's type " + node.XmlType + " is not a subtype of " + xmlType); } [Conditional("DEBUG")] private void CheckNumericX(QilNode node) { - Check(node.XmlType.IsNumeric && node.XmlType.IsSingleton && node.XmlType.IsStrict, node, "Node's type " + node.XmlType + " must be a strict singleton numeric type"); + Check(node.XmlType!.IsNumeric && node.XmlType.IsSingleton && node.XmlType.IsStrict, node, "Node's type " + node.XmlType + " must be a strict singleton numeric type"); } [Conditional("DEBUG")] private void CheckNumericXS(QilNode node) { - Check(node.XmlType.IsNumeric && node.XmlType.IsStrict, node, "Node's type " + node.XmlType + " must be a strict numeric type"); + Check(node.XmlType!.IsNumeric && node.XmlType.IsStrict, node, "Node's type " + node.XmlType + " must be a strict numeric type"); } [Conditional("DEBUG")] private void CheckAtomicX(QilNode node) { - Check(node.XmlType.IsAtomicValue && node.XmlType.IsStrict, node, "Node's type " + node.XmlType + " must be a strict atomic value type"); + Check(node.XmlType!.IsAtomicValue && node.XmlType.IsStrict, node, "Node's type " + node.XmlType + " must be a strict atomic value type"); } [Conditional("DEBUG")] private void CheckNotDisjoint(QilBinary node) { - Check(node.Left.XmlType.IsSubtypeOf(node.Right.XmlType) || node.Right.XmlType.IsSubtypeOf(node.Left.XmlType), node, + Check(node.Left.XmlType!.IsSubtypeOf(node.Right.XmlType!) || node.Right.XmlType!.IsSubtypeOf(node.Left.XmlType), node, "Node must not have arguments with disjoint types " + node.Left.XmlType + " and " + node.Right.XmlType); } @@ -1062,12 +1063,12 @@ private XmlQueryType DistinctType(XmlQueryType type) return type; } - private XmlQueryType FindFilterType(QilIterator variable, QilNode body) + private XmlQueryType? FindFilterType(QilIterator variable, QilNode body) { - XmlQueryType leftType; + XmlQueryType? leftType; QilBinary binary; - if (body.XmlType.TypeCode == XmlTypeCode.None) + if (body.XmlType!.TypeCode == XmlTypeCode.None) return XmlQueryTypeFactory.None; switch (body.NodeType) @@ -1078,7 +1079,7 @@ private XmlQueryType FindFilterType(QilIterator variable, QilNode body) case QilNodeType.IsType: // If testing the type of "variable", then filter type can be restricted if ((object)((QilTargetType)body).Source == (object)variable) - return XmlQueryTypeFactory.AtMost(((QilTargetType)body).TargetType, variable.Binding.XmlType.Cardinality); + return XmlQueryTypeFactory.AtMost(((QilTargetType)body).TargetType, variable.Binding!.XmlType!.Cardinality); break; case QilNodeType.And: @@ -1095,7 +1096,7 @@ private XmlQueryType FindFilterType(QilIterator variable, QilNode body) if (binary.Left.NodeType == QilNodeType.PositionOf) { if ((object)((QilUnary)binary.Left).Child == (object)variable) - return XmlQueryTypeFactory.AtMost(variable.Binding.XmlType, XmlQueryCardinality.ZeroOrOne); + return XmlQueryTypeFactory.AtMost(variable.Binding!.XmlType!, XmlQueryCardinality.ZeroOrOne); } break; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilUnary.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilUnary.cs index 112cf60971487..151ab3fa5cb92 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilUnary.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilUnary.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilValidationVisitor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilValidationVisitor.cs index d6ae6606999e9..8134de7f5ca40 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilValidationVisitor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilValidationVisitor.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections; using System.Diagnostics; @@ -152,7 +153,7 @@ protected override void EndScope(QilNode node) private class ObjectHashtable : Hashtable { - protected override bool KeyEquals(object item, object key) + protected override bool KeyEquals(object? item, object key) { return item == key; } @@ -182,7 +183,7 @@ internal static void SetError(QilNode n, string message) message += " ["+ n.NodeId + " (" + n.NodeType.ToString("G") + ")]"; #endif - string s = n.Annotation as string; + string? s = n.Annotation as string; if (s != null) { message = s + "\n" + message; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilVisitor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilVisitor.cs index 60fdfad6a3a8c..88ac380bd6f50 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilVisitor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilVisitor.cs @@ -1,8 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace System.Xml.Xsl.Qil { @@ -103,7 +105,7 @@ protected virtual bool IsReference(QilNode parent, int childNum) protected virtual QilNode Visit(QilNode n) { if (n == null) - return VisitNull(); + return VisitNull()!; return n.NodeType switch { @@ -241,7 +243,7 @@ protected virtual QilNode Visit(QilNode n) protected virtual QilNode VisitReference(QilNode n) { if (n == null) - return VisitNull(); + return VisitNull()!; return n.NodeType switch { @@ -255,7 +257,7 @@ protected virtual QilNode VisitReference(QilNode n) }; } - protected virtual QilNode VisitNull() { return null; } + protected virtual QilNode? VisitNull() { return null; } #region meta protected virtual QilNode VisitQilExpression(QilExpression n) { return VisitChildren(n); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilXmlWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilXmlWriter.cs index efd9af44d872e..9188c3e8866fe 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilXmlWriter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilXmlWriter.cs @@ -1,10 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Text; using System.Xml; @@ -89,9 +91,9 @@ public void ToXml(QilNode node) /// 3. IList{object} -- recursively call WriteAnnotations for each object in list /// 4. otherwise, do not write the annotation /// - protected virtual void WriteAnnotations(object ann) + protected virtual void WriteAnnotations(object? ann) { - string s = null, name = null; + string? s = null, name = null; if (ann == null) { @@ -101,17 +103,13 @@ protected virtual void WriteAnnotations(object ann) { s = ann as string; } - else if (ann is IQilAnnotation) + else if (ann is IQilAnnotation qilann) { - // Get annotation's name and string value - IQilAnnotation qilann = ann as IQilAnnotation; name = qilann.Name; s = ann.ToString(); } - else if (ann is IList) + else if (ann is IList list) { - IList list = (IList)ann; - foreach (object annItem in list) WriteAnnotations(annItem); return; @@ -127,7 +125,7 @@ protected virtual void WriteAnnotations(object ann) protected virtual void WriteLineInfo(QilNode node) { this.writer.WriteAttributeString("lineInfo", string.Format(CultureInfo.InvariantCulture, "[{0},{1} -- {2},{3}]", - node.SourceLine.Start.Line, node.SourceLine.Start.Pos, + node.SourceLine!.Start.Line, node.SourceLine.Start.Pos, node.SourceLine.End.Line, node.SourceLine.End.Pos )); } @@ -137,7 +135,7 @@ protected virtual void WriteLineInfo(QilNode node) /// protected virtual void WriteXmlType(QilNode node) { - this.writer.WriteAttributeString("xmlType", node.XmlType.ToString((this.options & Options.RoundTripTypeInfo) != 0 ? "S" : "G")); + this.writer.WriteAttributeString("xmlType", node.XmlType!.ToString((this.options & Options.RoundTripTypeInfo) != 0 ? "S" : "G")); } @@ -213,7 +211,7 @@ protected override QilNode VisitQilExpression(QilExpression qil) foreach (QilNode n in fdecls) { // i.e. - this.writer.WriteStartElement(Enum.GetName(typeof(QilNodeType), n.NodeType)); + this.writer.WriteStartElement(Enum.GetName(typeof(QilNodeType), n.NodeType)!); this.writer.WriteAttributeString("id", _ngen.NameOf(n)); WriteXmlType(n); @@ -284,7 +282,7 @@ protected override void BeforeVisit(QilNode node) WriteAnnotations(node.Annotation); // Call WriteStartElement - this.writer.WriteStartElement("", Enum.GetName(typeof(QilNodeType), node.NodeType), ""); + this.writer.WriteStartElement("", Enum.GetName(typeof(QilNodeType), node.NodeType)!, ""); // Write common attributes #if QIL_TRACE_NODE_CREATION @@ -413,10 +411,10 @@ public string NextName() /// the node name (unique across nodes) public string NameOf(QilNode n) { - string name = null; + string? name = null; - object old = n.Annotation; - NameAnnotation a = old as NameAnnotation; + object? old = n.Annotation; + NameAnnotation? a = old as NameAnnotation; if (a == null) { name = NextName(); @@ -442,12 +440,12 @@ public void ClearName(QilNode n) /// /// Class used to hold our annotations on the graph /// - private class NameAnnotation : ListBase + private class NameAnnotation : ListBase { public string Name; - public object PriorAnnotation; + public object? PriorAnnotation; - public NameAnnotation(string s, object a) + public NameAnnotation(string s, object? a) { Name = s; PriorAnnotation = a; @@ -458,7 +456,7 @@ public override int Count get { return 1; } } - public override object this[int index] + public override object? this[int index] { get { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/SerializationHints.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/SerializationHints.cs index fc9635c2033b5..952080b25513f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/SerializationHints.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/SerializationHints.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; namespace System.Xml.Xsl.Qil diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/SubstitutionList.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/SubstitutionList.cs index db12c8e2be134..54c03eae52cb5 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/SubstitutionList.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/SubstitutionList.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Collections; using System.Diagnostics; @@ -46,12 +47,12 @@ public void RemoveLastSubstitutionPair() /// /// the node to replace /// null if no replacement is found - public QilNode FindReplacement(QilNode n) + public QilNode? FindReplacement(QilNode n) { Debug.Assert(_s.Count % 2 == 0); for (int i = _s.Count - 2; i >= 0; i -= 2) if (_s[i] == n) - return (QilNode)_s[i + 1]; + return (QilNode)_s[i + 1]!; return null; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/WhitespaceRule.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/WhitespaceRule.cs index 1e88fcd68fb24..18bf7065770ee 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/WhitespaceRule.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/WhitespaceRule.cs @@ -1,7 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Xml.Xsl.Runtime; @@ -12,8 +14,8 @@ namespace System.Xml.Xsl.Qil /// internal class WhitespaceRule { - private string _localName; - private string _namespaceName; + private string? _localName; + private string? _namespaceName; private bool _preserveSpace; /// @@ -26,7 +28,7 @@ protected WhitespaceRule() /// /// Construct new whitespace rule. /// - public WhitespaceRule(string localName, string namespaceName, bool preserveSpace) + public WhitespaceRule(string? localName, string? namespaceName, bool preserveSpace) { Init(localName, namespaceName, preserveSpace); } @@ -34,7 +36,7 @@ public WhitespaceRule(string localName, string namespaceName, bool preserveSpace /// /// Initialize whitespace rule after it's been constructed. /// - protected void Init(string localName, string namespaceName, bool preserveSpace) + protected void Init(string? localName, string? namespaceName, bool preserveSpace) { _localName = localName; _namespaceName = namespaceName; @@ -44,7 +46,7 @@ protected void Init(string localName, string namespaceName, bool preserveSpace) /// /// Local name of the element. /// - public string LocalName + public string? LocalName { get { return _localName; } set { _localName = value; } @@ -53,7 +55,7 @@ public string LocalName /// /// Namespace name (uri) of the element. /// - public string NamespaceName + public string? NamespaceName { get { return _namespaceName; } set { _namespaceName = value; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QueryReaderSettings.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QueryReaderSettings.cs index d1b63c6212c90..d95ef698a6f22 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QueryReaderSettings.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QueryReaderSettings.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections; using System.Collections.Generic; using System.Diagnostics; @@ -12,14 +13,14 @@ namespace System.Xml.Xsl internal class QueryReaderSettings { private readonly bool _validatingReader; - private readonly XmlReaderSettings _xmlReaderSettings; - private readonly XmlNameTable _xmlNameTable; + private readonly XmlReaderSettings? _xmlReaderSettings; + private readonly XmlNameTable? _xmlNameTable; private readonly EntityHandling _entityHandling; private readonly bool _namespaces; private readonly bool _normalization; private readonly bool _prohibitDtd; private readonly WhitespaceHandling _whitespaceHandling; - private readonly XmlResolver _xmlResolver; + private readonly XmlResolver? _xmlResolver; public QueryReaderSettings(XmlNameTable xmlNameTable) { @@ -35,7 +36,7 @@ public QueryReaderSettings(XmlNameTable xmlNameTable) public QueryReaderSettings(XmlReader reader) { #pragma warning disable 618 - XmlValidatingReader valReader = reader as XmlValidatingReader; + XmlValidatingReader? valReader = reader as XmlValidatingReader; #pragma warning restore 618 if (valReader != null) { @@ -43,6 +44,7 @@ public QueryReaderSettings(XmlReader reader) _validatingReader = true; reader = valReader.Impl.Reader; } + _xmlReaderSettings = reader.Settings; if (_xmlReaderSettings != null) { @@ -51,7 +53,7 @@ public QueryReaderSettings(XmlReader reader) _xmlReaderSettings.CloseInput = true; _xmlReaderSettings.LineNumberOffset = 0; _xmlReaderSettings.LinePositionOffset = 0; - XmlTextReaderImpl impl = reader as XmlTextReaderImpl; + XmlTextReaderImpl? impl = reader as XmlTextReaderImpl; if (impl != null) { _xmlReaderSettings.XmlResolver = impl.GetResolver(); @@ -60,7 +62,7 @@ public QueryReaderSettings(XmlReader reader) else { _xmlNameTable = reader.NameTable; - XmlTextReader xmlTextReader = reader as XmlTextReader; + XmlTextReader? xmlTextReader = reader as XmlTextReader; if (xmlTextReader != null) { XmlTextReaderImpl impl = xmlTextReader.Impl; @@ -92,7 +94,7 @@ public XmlReader CreateReader(Stream stream, string baseUri) } else { - XmlTextReaderImpl readerImpl = new XmlTextReaderImpl(baseUri, stream, _xmlNameTable); + XmlTextReaderImpl readerImpl = new XmlTextReaderImpl(baseUri, stream, _xmlNameTable!); readerImpl.EntityHandling = _entityHandling; readerImpl.Namespaces = _namespaces; readerImpl.Normalization = _normalization; @@ -112,7 +114,7 @@ public XmlReader CreateReader(Stream stream, string baseUri) public XmlNameTable NameTable { - get { return _xmlReaderSettings != null ? _xmlReaderSettings.NameTable : _xmlNameTable; } + get { return _xmlReaderSettings != null ? _xmlReaderSettings.NameTable! : _xmlNameTable!; } } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/SourceLineInfo.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/SourceLineInfo.cs index 1542b08aa18c4..d979a4c12a8f9 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/SourceLineInfo.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/SourceLineInfo.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Diagnostics; namespace System.Xml.Xsl @@ -27,15 +28,15 @@ public bool LessOrEqual(Location that) [DebuggerDisplay("{Uri} [{StartLine},{StartPos} -- {EndLine},{EndPos}]")] internal class SourceLineInfo : ISourceLineInfo { - protected string uriString; + protected string? uriString; protected Location start; protected Location end; - public SourceLineInfo(string uriString, int startLine, int startPos, int endLine, int endPos) + public SourceLineInfo(string? uriString, int startLine, int startPos, int endLine, int endPos) : this(uriString, new Location(startLine, startPos), new Location(endLine, endPos)) { } - public SourceLineInfo(string uriString, Location start, Location end) + public SourceLineInfo(string? uriString, Location start, Location end) { this.uriString = uriString; this.start = start; @@ -43,7 +44,7 @@ public SourceLineInfo(string uriString, Location start, Location end) Validate(this); } - public string Uri { get { return this.uriString; } } + public string? Uri { get { return this.uriString; } } public int StartLine { get { return this.start.Line; } } public Location End { get { return this.end; } } public Location Start { get { return this.start; } } @@ -82,7 +83,7 @@ public static void Validate(ISourceLineInfo lineInfo) public static string GetFileName(string uriString) { Debug.Assert(uriString != null); - Uri uri; + Uri? uri; if (uriString.Length != 0 && System.Uri.TryCreate(uriString, UriKind.Absolute, out uri) && diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/IXPathEnvironment.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/IXPathEnvironment.cs index 077c176e64184..201217f13c92b 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/IXPathEnvironment.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/IXPathEnvironment.cs @@ -11,7 +11,7 @@ namespace System.Xml.Xsl.XPath internal interface IFocus { // The context item: the item currently being processed - QilNode GetCurrent(); + QilNode? GetCurrent(); // The context position: the position of the context item within the sequence of items // currently being processed diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathBuilder.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathBuilder.cs index 43631e67c32dd..dff13ae08889d 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathBuilder.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathBuilder.cs @@ -80,7 +80,7 @@ public virtual void StartBuild() return result; } Debug.Assert(_inTheBuild, "StartBuild() wasn't called"); - if (result.XmlType.MaybeMany && result.XmlType.IsNode && result.XmlType.IsNotRtf) + if (result.XmlType!.MaybeMany && result.XmlType.IsNode && result.XmlType.IsNotRtf) { result = _f.DocOrderDistinct(result); } @@ -147,7 +147,7 @@ private QilNode LogicalOperator(XPathOperator op, QilNode left, QilNode right) private QilNode CompareValues(XPathOperator op, QilNode left, QilNode right, XmlTypeCode compType) { Debug.Assert(compType == XmlTypeCode.Boolean || compType == XmlTypeCode.Double || compType == XmlTypeCode.String); - Debug.Assert(compType == XmlTypeCode.Boolean || left.XmlType.IsSingleton && right.XmlType.IsSingleton, "Both comparison operands must be singletons"); + Debug.Assert(compType == XmlTypeCode.Boolean || left.XmlType!.IsSingleton && right.XmlType!.IsSingleton, "Both comparison operands must be singletons"); left = _f.ConvertToType(compType, left); right = _f.ConvertToType(compType, right); @@ -168,9 +168,9 @@ private QilNode CompareValues(XPathOperator op, QilNode left, QilNode right, Xml private QilNode CompareNodeSetAndValue(XPathOperator op, QilNode nodeset, QilNode val, XmlTypeCode compType) { _f.CheckNodeSet(nodeset); - Debug.Assert(val.XmlType.IsSingleton); + Debug.Assert(val.XmlType!.IsSingleton); Debug.Assert(compType == XmlTypeCode.Boolean || compType == XmlTypeCode.Double || compType == XmlTypeCode.String, "I don't know what to do with RTF here"); - if (compType == XmlTypeCode.Boolean || nodeset.XmlType.IsSingleton) + if (compType == XmlTypeCode.Boolean || nodeset.XmlType!.IsSingleton) { return CompareValues(op, nodeset, val, compType); } @@ -197,11 +197,11 @@ private QilNode CompareNodeSetAndNodeSet(XPathOperator op, QilNode left, QilNode { _f.CheckNodeSet(left); _f.CheckNodeSet(right); - if (right.XmlType.IsSingleton) + if (right.XmlType!.IsSingleton) { return CompareNodeSetAndValue(op, /*nodeset:*/left, /*value:*/right, compType); } - if (left.XmlType.IsSingleton) + if (left.XmlType!.IsSingleton) { op = InvertOp(op); return CompareNodeSetAndValue(op, /*nodeset:*/right, /*value:*/left, compType); @@ -214,8 +214,8 @@ private QilNode CompareNodeSetAndNodeSet(XPathOperator op, QilNode left, QilNode private QilNode EqualityOperator(XPathOperator op, QilNode left, QilNode right) { Debug.Assert(op == XPathOperator.Eq || op == XPathOperator.Ne); - XmlQueryType leftType = left.XmlType; - XmlQueryType rightType = right.XmlType; + XmlQueryType leftType = left.XmlType!; + XmlQueryType rightType = right.XmlType!; if (_f.IsAnyType(left) || _f.IsAnyType(right)) { @@ -247,8 +247,8 @@ private QilNode EqualityOperator(XPathOperator op, QilNode left, QilNode right) private QilNode RelationalOperator(XPathOperator op, QilNode left, QilNode right) { Debug.Assert(op == XPathOperator.Lt || op == XPathOperator.Le || op == XPathOperator.Gt || op == XPathOperator.Ge); - XmlQueryType leftType = left.XmlType; - XmlQueryType rightType = right.XmlType; + XmlQueryType leftType = left.XmlType!; + XmlQueryType rightType = right.XmlType!; if (_f.IsAnyType(left) || _f.IsAnyType(right)) { @@ -329,7 +329,7 @@ public static XmlNodeKindFlags AxisTypeMask(XmlNodeKindFlags inputTypeMask, XPat private QilNode BuildAxisFilter(QilNode qilAxis, XPathAxis xpathAxis, XPathNodeType nodeType, string? name, string? nsUri) { - XmlNodeKindFlags original = qilAxis.XmlType.NodeKinds; + XmlNodeKindFlags original = qilAxis.XmlType!.NodeKinds; XmlNodeKindFlags required = AxisTypeMask(original, nodeType, xpathAxis); QilIterator itr; @@ -344,7 +344,7 @@ private QilNode BuildAxisFilter(QilNode qilAxis, XPathAxis xpathAxis, XPathNodeT else { qilAxis = _f.Filter(itr = _f.For(qilAxis), _f.IsType(itr, T.NodeChoice(required))); - qilAxis.XmlType = T.PrimeProduct(T.NodeChoice(required), qilAxis.XmlType.Cardinality); + qilAxis.XmlType = T.PrimeProduct(T.NodeChoice(required), qilAxis.XmlType!.Cardinality); // Without code bellow IlGeneragion gives stack overflow exception for the following passage. @@ -476,7 +476,7 @@ public static QilNode PredicateToBoolean(QilNode predicate, XPathQilFactory f, I // Prepocess predicate: if (predicate is number) then predicate := (position() == predicate) if (!f.IsAnyType(predicate)) { - if (predicate.XmlType.TypeCode == XmlTypeCode.Double) + if (predicate.XmlType!.TypeCode == XmlTypeCode.Double) { predicate = f.Eq(env.GetPosition(), predicate); } @@ -613,7 +613,7 @@ public virtual QilNode Function(string prefix, string name, IList args) private QilNode LocalNameOfFirstNode(QilNode arg) { _f.CheckNodeSet(arg); - if (arg.XmlType.IsSingleton) + if (arg.XmlType!.IsSingleton) { return _f.LocalNameOf(arg); } @@ -627,7 +627,7 @@ private QilNode LocalNameOfFirstNode(QilNode arg) private QilNode NamespaceOfFirstNode(QilNode arg) { _f.CheckNodeSet(arg); - if (arg.XmlType.IsSingleton) + if (arg.XmlType!.IsSingleton) { return _f.NamespaceUriOf(arg); } @@ -659,7 +659,7 @@ private QilNode NameOf(QilNode arg) private QilNode NameOfFirstNode(QilNode arg) { _f.CheckNodeSet(arg); - if (arg.XmlType.IsSingleton) + if (arg.XmlType!.IsSingleton) { return NameOf(arg); } @@ -897,7 +897,7 @@ protected override QilNode VisitUnknown(QilNode unknown) { if (_environment != null) { - unknown = _environment.GetCurrent(); + unknown = _environment.GetCurrent()!; } else if (_current != null) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathCompileException.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathCompileException.cs index cc10b5257d90b..42470c834f8a5 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathCompileException.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathCompileException.cs @@ -14,7 +14,7 @@ internal class XPathCompileException : XslLoadException public int startChar; public int endChar; - internal XPathCompileException(string queryString, int startChar, int endChar, string resId, params string[] args) + internal XPathCompileException(string queryString, int startChar, int endChar, string resId, params string?[]? args) : base(resId, args) { this.queryString = queryString; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathQilFactory.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathQilFactory.cs index f92d203ff81eb..09e635a6d30a9 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathQilFactory.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathQilFactory.cs @@ -24,7 +24,7 @@ public QilNode Error(string res, QilNode args) return Error(InvokeFormatMessage(String(res), args)); } - public QilNode Error(ISourceLineInfo lineInfo, string res, params string[] args) + public QilNode Error(ISourceLineInfo? lineInfo, string res, params string[] args) { return Error(String(XslLoadException.CreateMessage(lineInfo, res, args))); } @@ -38,8 +38,8 @@ public QilIterator FirstNode(QilNode n) public bool IsAnyType(QilNode n) { - XmlQueryType xt = n.XmlType; - bool result = !(xt.IsStrict || xt.IsNode); + XmlQueryType? xt = n.XmlType; + bool result = !(xt!.IsStrict || xt.IsNode); Debug.Assert(result == (xt.TypeCode == XmlTypeCode.Item || xt.TypeCode == XmlTypeCode.AnyAtomicType), "What else can it be?"); return result; } @@ -47,56 +47,56 @@ public bool IsAnyType(QilNode n) [Conditional("DEBUG")] public void CheckNode(QilNode n) { - Debug.Assert(n != null && n.XmlType.IsSingleton && n.XmlType.IsNode, "Must be a singleton node"); + Debug.Assert(n != null && n.XmlType!.IsSingleton && n.XmlType.IsNode, "Must be a singleton node"); } [Conditional("DEBUG")] public void CheckNodeSet(QilNode n) { - Debug.Assert(n != null && n.XmlType.IsNode, "Must be a node-set"); + Debug.Assert(n != null && n.XmlType!.IsNode, "Must be a node-set"); } [Conditional("DEBUG")] public void CheckNodeNotRtf(QilNode n) { - Debug.Assert(n != null && n.XmlType.IsSingleton && n.XmlType.IsNode && n.XmlType.IsNotRtf, "Must be a singleton node and not an Rtf"); + Debug.Assert(n != null && n.XmlType!.IsSingleton && n.XmlType.IsNode && n.XmlType.IsNotRtf, "Must be a singleton node and not an Rtf"); } [Conditional("DEBUG")] public void CheckString(QilNode n) { - Debug.Assert(n != null && n.XmlType.IsSubtypeOf(T.StringX), "Must be a singleton string"); + Debug.Assert(n != null && n.XmlType!.IsSubtypeOf(T.StringX), "Must be a singleton string"); } [Conditional("DEBUG")] public void CheckStringS(QilNode n) { - Debug.Assert(n != null && n.XmlType.IsSubtypeOf(T.StringXS), "Must be a sequence of strings"); + Debug.Assert(n != null && n.XmlType!.IsSubtypeOf(T.StringXS), "Must be a sequence of strings"); } [Conditional("DEBUG")] public void CheckDouble(QilNode n) { - Debug.Assert(n != null && n.XmlType.IsSubtypeOf(T.DoubleX), "Must be a singleton Double"); + Debug.Assert(n != null && n.XmlType!.IsSubtypeOf(T.DoubleX), "Must be a singleton Double"); } [Conditional("DEBUG")] public void CheckBool(QilNode n) { - Debug.Assert(n != null && n.XmlType.IsSubtypeOf(T.BooleanX), "Must be a singleton Bool"); + Debug.Assert(n != null && n.XmlType!.IsSubtypeOf(T.BooleanX), "Must be a singleton Bool"); } // Return true if inferred type of the given expression is never a subtype of T.NodeS public bool CannotBeNodeSet(QilNode n) { - XmlQueryType xt = n.XmlType; + XmlQueryType xt = n.XmlType!; // Do not report compile error if n is a VarPar, whose inferred type forbids nodes (SQLBUDT 339398) return xt.IsAtomicValue && !xt.IsEmpty && !(n is QilIterator); } public QilNode SafeDocOrderDistinct(QilNode n) { - XmlQueryType xt = n.XmlType; + XmlQueryType xt = n.XmlType!; if (xt.MaybeMany) { @@ -169,7 +169,7 @@ public QilNode InvokeRelationalOperator(QilNodeType op, QilNode left, QilNode ri [Conditional("DEBUG")] private void ExpectAny(QilNode n) { - Debug.Assert(IsAnyType(n), "Unexpected expression type: " + n.XmlType.ToString()); + Debug.Assert(IsAnyType(n), "Unexpected expression type: " + n.XmlType!.ToString()); } public QilNode ConvertToType(XmlTypeCode requiredType, QilNode n) @@ -188,7 +188,7 @@ public QilNode ConvertToType(XmlTypeCode requiredType, QilNode n) // XPath spec $4.2, string() public QilNode ConvertToString(QilNode n) { - switch (n.XmlType.TypeCode) + switch (n.XmlType!.TypeCode) { case XmlTypeCode.Boolean: return ( @@ -217,7 +217,7 @@ public QilNode ConvertToString(QilNode n) // XPath spec $4.3, boolean() public QilNode ConvertToBoolean(QilNode n) { - switch (n.XmlType.TypeCode) + switch (n.XmlType!.TypeCode) { case XmlTypeCode.Boolean: return n; @@ -247,7 +247,7 @@ public QilNode ConvertToBoolean(QilNode n) // XPath spec $4.4, number() public QilNode ConvertToNumber(QilNode n) { - switch (n.XmlType.TypeCode) + switch (n.XmlType!.TypeCode) { case XmlTypeCode.Boolean: return ( @@ -272,7 +272,7 @@ public QilNode ConvertToNumber(QilNode n) public QilNode ConvertToNode(QilNode n) { - if (n.XmlType.IsNode && n.XmlType.IsNotRtf && n.XmlType.IsSingleton) + if (n.XmlType!.IsNode && n.XmlType.IsNotRtf && n.XmlType.IsSingleton) { return n; } @@ -281,7 +281,7 @@ public QilNode ConvertToNode(QilNode n) public QilNode ConvertToNodeSet(QilNode n) { - if (n.XmlType.IsNode && n.XmlType.IsNotRtf) + if (n.XmlType!.IsNode && n.XmlType.IsNotRtf) { return n; } @@ -292,7 +292,7 @@ public QilNode ConvertToNodeSet(QilNode n) // Returns null if the given expression is never a node-set public QilNode? TryEnsureNodeSet(QilNode n) { - if (n.XmlType.IsNode && n.XmlType.IsNotRtf) + if (n.XmlType!.IsNode && n.XmlType.IsNotRtf) { return n; } @@ -329,7 +329,7 @@ public QilNode Id(QilNode context, QilNode id) { CheckNodeNotRtf(context); - if (id.XmlType.IsSingleton) + if (id.XmlType!.IsSingleton) { return Deref(context, ConvertToString(id)); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlILCommand.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlILCommand.cs index 75aec68b045ad..6649cbbe55446 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlILCommand.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlILCommand.cs @@ -4,6 +4,7 @@ // http://webdata/xml/specs/querylowlevel.xml //------------------------------------------------------------------------------ +#nullable enable using System.Collections; using System.Diagnostics; using System.IO; @@ -92,7 +93,7 @@ public override IList Evaluate(XmlReader contextDocument, XmlResolver dataSource /// /// Execute the dynamic assembly generated by the XmlILGenerator. /// - public void Execute(object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer) + public void Execute(object defaultDocument, XmlResolver? dataSources, XsltArgumentList? argumentList, XmlWriter writer) { try { @@ -102,7 +103,7 @@ public void Execute(object defaultDocument, XmlResolver dataSources, XsltArgumen } // Try to extract a RawWriter - XmlWellFormedWriter wellFormedWriter = writer as XmlWellFormedWriter; + XmlWellFormedWriter? wellFormedWriter = writer as XmlWellFormedWriter; if (wellFormedWriter != null && wellFormedWriter.RawWriter != null && @@ -127,7 +128,7 @@ public void Execute(object defaultDocument, XmlResolver dataSources, XsltArgumen /// /// Execute the dynamic assembly generated by the XmlILGenerator. /// - private void Execute(object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) + private void Execute(object defaultDocument, XmlResolver? dataSources, XsltArgumentList? argumentList, XmlSequenceWriter results) { Debug.Assert(results != null); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlIlGenerator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlIlGenerator.cs index e0ab38c610b93..e20f724312c92 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlIlGenerator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlIlGenerator.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections; using System.Collections.Generic; using System.Diagnostics; @@ -13,6 +14,7 @@ using System.Xml.Xsl.Qil; using System.Xml.Xsl.Runtime; using System.Runtime.Versioning; +using System.Diagnostics.CodeAnalysis; namespace System.Xml.Xsl { @@ -50,11 +52,11 @@ namespace System.Xml.Xsl /// internal class XmlILGenerator { - private QilExpression _qil; - private GenerateHelper _helper; - private XmlILOptimizerVisitor _optVisitor; - private XmlILVisitor _xmlIlVisitor; - private XmlILModule _module; + private QilExpression? _qil; + private GenerateHelper? _helper; + private XmlILOptimizerVisitor? _optVisitor; + private XmlILVisitor? _xmlIlVisitor; + private XmlILModule? _module; /// /// Always output debug information in debug mode. @@ -69,7 +71,8 @@ public XmlILGenerator() // SxS Note: The way the trace file names are created (hardcoded) is NOT SxS safe. However the files are // created only for internal tracing purposes. In addition XmlILTrace class is not compiled into retail // builds. As a result it is fine to suppress the FxCop SxS warning. - public XmlILCommand Generate(QilExpression query, TypeBuilder typeBldr) + // TODO-NULLABLE: missing [return: NotNullIfNull("typeBldr")] + public XmlILCommand? Generate(QilExpression query, TypeBuilder? typeBldr) { _qil = query; @@ -204,7 +207,7 @@ private void CreateFunctionMetadata(IList funcList) Debug.Assert(ndParam.NodeType == QilNodeType.Parameter); // Get the type of each argument as a Clr type - paramTypes[arg] = XmlILTypeHelper.GetStorageType(ndParam.XmlType); + paramTypes[arg] = XmlILTypeHelper.GetStorageType(ndParam.XmlType!); // Get the name of each argument if (ndParam.DebugName != null) @@ -220,12 +223,12 @@ private void CreateFunctionMetadata(IList funcList) else { // Pull mode functions have a return value - typReturn = XmlILTypeHelper.GetStorageType(ndFunc.XmlType); + typReturn = XmlILTypeHelper.GetStorageType(ndFunc.XmlType!); } // Create the method metadata methAttrs = ndFunc.SourceLine == null ? XmlILMethodAttributes.NonUser : XmlILMethodAttributes.None; - methInfo = _module.DefineMethod(ndFunc.DebugName, typReturn, paramTypes, paramNames, methAttrs); + methInfo = _module!.DefineMethod(ndFunc.DebugName!, typReturn, paramTypes, paramNames, methAttrs); for (int arg = 0; arg < ndFunc.Arguments.Count; arg++) { @@ -250,9 +253,9 @@ private void CreateGlobalValueMetadata(IList globalList) foreach (QilReference ndRef in globalList) { // public T GlobalValue() - typReturn = XmlILTypeHelper.GetStorageType(ndRef.XmlType); + typReturn = XmlILTypeHelper.GetStorageType(ndRef.XmlType!); methAttrs = ndRef.SourceLine == null ? XmlILMethodAttributes.NonUser : XmlILMethodAttributes.None; - methInfo = _module.DefineMethod(ndRef.DebugName.ToString(), typReturn, Array.Empty(), Array.Empty(), methAttrs); + methInfo = _module!.DefineMethod(ndRef.DebugName!.ToString(), typReturn, Array.Empty(), Array.Empty(), methAttrs); // Annotate function with MethodBuilder XmlILAnnotation.Write(ndRef).FunctionBinding = methInfo; @@ -264,10 +267,10 @@ private void CreateGlobalValueMetadata(IList globalList) /// private MethodInfo GenerateExecuteFunction(MethodInfo methExec, MethodInfo methRoot) { - _helper.MethodBegin(methExec, null, false); + _helper!.MethodBegin(methExec, null, false); // Force some or all global values to be evaluated at start of query - EvaluateGlobalValues(_qil.GlobalVariableList); + EvaluateGlobalValues(_qil!.GlobalVariableList); EvaluateGlobalValues(_qil.GlobalParameterList); // Root(runtime); @@ -288,14 +291,14 @@ private void CreateHelperFunctions() Label lblClone; // public static XPathNavigator SyncToNavigator(XPathNavigator, XPathNavigator); - meth = _module.DefineMethod( + meth = _module!.DefineMethod( "SyncToNavigator", typeof(XPathNavigator), new Type[] { typeof(XPathNavigator), typeof(XPathNavigator) }, - new string[] { null, null }, + new string?[] { null, null }, XmlILMethodAttributes.NonUser | XmlILMethodAttributes.Raw); - _helper.MethodBegin(meth, null, false); + _helper!.MethodBegin(meth, null, false); // if (navigatorThis != null && navigatorThis.MoveTo(navigatorThat)) // return navigatorThis; @@ -323,18 +326,18 @@ private void CreateHelperFunctions() /// private void EvaluateGlobalValues(IList iterList) { - MethodInfo methInfo; + MethodInfo? methInfo; foreach (QilIterator ndIter in iterList) { // Evaluate global if generating debug code, or if global might have side effects - if (_qil.IsDebug || OptimizerPatterns.Read(ndIter).MatchesPattern(OptimizerPatternName.MaybeSideEffects)) + if (_qil!.IsDebug || OptimizerPatterns.Read(ndIter).MatchesPattern(OptimizerPatternName.MaybeSideEffects)) { // Get MethodInfo that evaluates the global value and discard its return value methInfo = XmlILAnnotation.Write(ndIter).FunctionBinding; Debug.Assert(methInfo != null, "MethodInfo for global value should have been created previously."); - _helper.LoadQueryRuntime(); + _helper!.LoadQueryRuntime(); _helper.Call(methInfo); _helper.Emit(OpCodes.Pop); } @@ -352,12 +355,12 @@ public void CreateTypeInitializer(XmlQueryStaticData staticData) ConstructorInfo cctor; staticData.GetObjectData(out data, out ebTypes); - fldInitData = _module.DefineInitializedData("__" + XmlQueryStaticData.DataFieldName, data); + fldInitData = _module!.DefineInitializedData("__" + XmlQueryStaticData.DataFieldName, data); fldData = _module.DefineField(XmlQueryStaticData.DataFieldName, typeof(object)); fldTypes = _module.DefineField(XmlQueryStaticData.TypesFieldName, typeof(Type[])); cctor = _module.DefineTypeInitializer(); - _helper.MethodBegin(cctor, null, false); + _helper!.MethodBegin(cctor, null, false); // s_data = new byte[s_initData.Length] { s_initData }; _helper.LoadInteger(data.Length); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlNodeKindFlags.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlNodeKindFlags.cs index 4101c0fb4459b..882264228e95b 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlNodeKindFlags.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlNodeKindFlags.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; namespace System.Xml.Xsl diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQualifiedNameTest.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQualifiedNameTest.cs index 06b36f1071640..66363cf8683da 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQualifiedNameTest.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQualifiedNameTest.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Xml; using System.Xml.Schema; @@ -38,7 +39,7 @@ public static XmlQualifiedNameTest Wildcard /// /// Constructor /// - private XmlQualifiedNameTest(string name, string ns, bool exclude) : base(name, ns) + private XmlQualifiedNameTest(string? name, string? ns, bool exclude) : base(name, ns) { _exclude = exclude; } @@ -46,7 +47,7 @@ private XmlQualifiedNameTest(string name, string ns, bool exclude) : base(name, /// /// Construct new from name and namespace. Returns singleton Wildcard in case full wildcard /// - public static XmlQualifiedNameTest New(string name, string ns) + public static XmlQualifiedNameTest New(string? name, string? ns) { if (ns == null && name == null) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryCardinality.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryCardinality.cs index 6ab2d01e8d219..012b94fa9d421 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryCardinality.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryCardinality.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Diagnostics; using System.IO; @@ -119,12 +120,13 @@ public bool Equals(XmlQueryCardinality other) /// /// True if "other" is an XmlQueryCardinality, and this type is the exact same static type. /// - public override bool Equals(object other) + public override bool Equals(object? other) { if (other is XmlQueryCardinality) { return Equals((XmlQueryCardinality)other); } + return false; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs index 26b2be064e544..3005c4d7bb8cc 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -167,7 +168,7 @@ public bool NeverSubtypeOf(XmlQueryType baseType) /// /// Strongly-typed Equals that returns true if this type and "that" type are equivalent. /// - public bool Equals(XmlQueryType that) + public bool Equals(XmlQueryType? that) { if (that == null) return false; @@ -227,10 +228,10 @@ public bool Equals(XmlQueryType that) /// /// Overload == operator to call Equals rather than do reference equality. /// - public static bool operator ==(XmlQueryType left, XmlQueryType right) + public static bool operator ==(XmlQueryType? left, XmlQueryType? right) { - if ((object)left == null) - return ((object)right == null); + if ((object?)left == null) + return ((object?)right == null); return left.Equals(right); } @@ -238,10 +239,10 @@ public bool Equals(XmlQueryType that) /// /// Overload != operator to call Equals rather than do reference inequality. /// - public static bool operator !=(XmlQueryType left, XmlQueryType right) + public static bool operator !=(XmlQueryType? left, XmlQueryType? right) { - if ((object)left == null) - return ((object)right != null); + if ((object?)left == null) + return ((object?)right != null); return !left.Equals(right); } @@ -318,9 +319,9 @@ public bool IsNumeric /// /// True if "obj" is an XmlQueryType, and this type is the exact same static type. /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { - XmlQueryType that = obj as XmlQueryType; + XmlQueryType? that = obj as XmlQueryType; if (that == null) return false; @@ -336,7 +337,7 @@ public override int GetHashCode() if (_hashCode == 0) { int hash; - XmlSchemaType schemaType; + XmlSchemaType? schemaType; hash = (int)TypeCode; schemaType = SchemaType; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryTypeFactory.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryTypeFactory.cs index a5963a7d7cf49..b844184dd7f4f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryTypeFactory.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryTypeFactory.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.Globalization; @@ -41,7 +42,7 @@ public static XmlQueryType Type(XmlTypeCode code, bool isStrict) /// the atomic value type public static XmlQueryType Type(XmlSchemaSimpleType schemaType, bool isStrict) { - if (schemaType.Datatype.Variety == XmlSchemaDatatypeVariety.Atomic) + if (schemaType.Datatype!.Variety == XmlSchemaDatatypeVariety.Atomic) { // We must special-case xs:anySimpleType because it is broken in Xsd and is sometimes treated as // an atomic value and sometimes as a list value. In XQuery, it always maps to xdt:anyAtomicType*. @@ -53,16 +54,16 @@ public static XmlQueryType Type(XmlSchemaSimpleType schemaType, bool isStrict) // Skip restrictions. It is safe to do that because this is a list or union, so it's not a build in type while (schemaType.DerivedBy == XmlSchemaDerivationMethod.Restriction) - schemaType = (XmlSchemaSimpleType)schemaType.BaseXmlSchemaType; + schemaType = (XmlSchemaSimpleType)schemaType.BaseXmlSchemaType!; // Convert Xsd list if (schemaType.DerivedBy == XmlSchemaDerivationMethod.List) - return PrimeProduct(Type(((XmlSchemaSimpleTypeList)schemaType.Content).BaseItemType, isStrict), XmlQueryCardinality.ZeroOrMore); + return PrimeProduct(Type(((XmlSchemaSimpleTypeList)schemaType.Content!).BaseItemType!, isStrict), XmlQueryCardinality.ZeroOrMore); // Convert Xsd union Debug.Assert(schemaType.DerivedBy == XmlSchemaDerivationMethod.Union); - XmlSchemaSimpleType[] baseMemberTypes = ((XmlSchemaSimpleTypeUnion)schemaType.Content).BaseMemberTypes; - XmlQueryType[] queryMemberTypes = new XmlQueryType[baseMemberTypes.Length]; + XmlSchemaSimpleType[] baseMemberTypes = ((XmlSchemaSimpleTypeUnion)schemaType.Content!).BaseMemberTypes!; + XmlQueryType[] queryMemberTypes = new XmlQueryType[baseMemberTypes!.Length]; for (int i = 0; i < baseMemberTypes.Length; i++) queryMemberTypes[i] = Type(baseMemberTypes[i], isStrict); @@ -348,7 +349,7 @@ static ItemType() { #if DEBUG Array arrEnum = Enum.GetValues(typeof(XmlTypeCode)); - Debug.Assert((XmlTypeCode)arrEnum.GetValue(arrEnum.Length - 1) == XmlTypeCode.DayTimeDuration, + Debug.Assert((XmlTypeCode)arrEnum.GetValue(arrEnum.Length - 1)! == XmlTypeCode.DayTimeDuration, "DayTimeDuration is no longer the last item in XmlTypeCode. This code expects it to be."); #endif @@ -434,7 +435,7 @@ public static XmlQueryType Create(XmlTypeCode code, bool isStrict) /// public static XmlQueryType Create(XmlSchemaSimpleType schemaType, bool isStrict) { - Debug.Assert(schemaType.Datatype.Variety == XmlSchemaDatatypeVariety.Atomic, "List or Union Xsd types should have been handled by caller."); + Debug.Assert(schemaType.Datatype!.Variety == XmlSchemaDatatypeVariety.Atomic, "List or Union Xsd types should have been handled by caller."); XmlTypeCode code = schemaType.Datatype.TypeCode; // If schemaType is a built-in type, @@ -510,7 +511,7 @@ private ItemType(XmlTypeCode code, XmlQualifiedNameTest nameTest, XmlSchemaType _isStrict = isStrict; _isNotRtf = isNotRtf; - Debug.Assert(!IsAtomicValue || schemaType.Datatype.Variety == XmlSchemaDatatypeVariety.Atomic); + Debug.Assert(!IsAtomicValue || schemaType.Datatype!.Variety == XmlSchemaDatatypeVariety.Atomic); _nodeKinds = code switch { @@ -690,7 +691,7 @@ private sealed class ChoiceType : XmlQueryType public static readonly XmlQueryType None = new ChoiceType(new List()); private readonly XmlTypeCode _code; - private readonly XmlSchemaType _schemaType; + private readonly XmlSchemaType? _schemaType; private readonly XmlNodeKindFlags _nodeKinds; private readonly List _members; @@ -853,7 +854,14 @@ public override XmlQualifiedNameTest NameTest /// public override XmlSchemaType SchemaType { - get { return _schemaType; } + get + { + // TODO-NULLABLE: Per documentation of base class we should not be returning null here + // Currently we return null for some type codes (i.e. Item, Node) + // but doc says we should be returning AnyType + // which presumably means XmlSchemaComplexType.AnyType + return _schemaType!; + } } /// diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XslException.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XslException.cs index 146f6ce06dee3..a239d96c103df 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XslException.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XslException.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Diagnostics; using System.Globalization; using System.Resources; @@ -12,7 +13,7 @@ namespace System.Xml.Xsl { internal class XslTransformException : XsltException { - public XslTransformException(Exception inner, string res, params string[] args) + public XslTransformException(Exception? inner, string res, params string?[]? args) : base(CreateMessage(res, args), inner) { } @@ -25,13 +26,13 @@ public XslTransformException(string message) : base(CreateMessage(message, null), null) { } - internal XslTransformException(string res, params string[] args) + internal XslTransformException(string res, params string?[]? args) : this(null, res, args) { } - internal static string CreateMessage(string res, params string[] args) + internal static string CreateMessage(string res, params string?[]? args) { - string message = null; + string? message = null; try { @@ -66,6 +67,7 @@ internal static string CreateMessage(string res, params string[] args) } sb.Append(')'); } + return sb.ToString(); } @@ -76,7 +78,7 @@ internal virtual string FormatDetailedMessage() public override string ToString() { - string result = this.GetType().FullName; + string result = this.GetType().FullName!; string info = FormatDetailedMessage(); if (info != null && info.Length > 0) { @@ -97,13 +99,13 @@ public override string ToString() [Serializable] internal class XslLoadException : XslTransformException { - private ISourceLineInfo _lineInfo; + private ISourceLineInfo? _lineInfo; - internal XslLoadException(string res, params string[] args) + internal XslLoadException(string res, params string?[]? args) : base(null, res, args) { } - internal XslLoadException(Exception inner, ISourceLineInfo lineInfo) + internal XslLoadException(Exception? inner, ISourceLineInfo? lineInfo) : base(inner, SR.Xslt_CompileError2, null) { SetSourceLineInfo(lineInfo); @@ -112,15 +114,15 @@ internal XslLoadException(Exception inner, ISourceLineInfo lineInfo) internal XslLoadException(SerializationInfo info, StreamingContext context) : base(info, context) { - bool hasLineInfo = (bool)info.GetValue("hasLineInfo", typeof(bool)); + bool hasLineInfo = (bool)info.GetValue("hasLineInfo", typeof(bool))!; if (hasLineInfo) { - string uriString = (string)info.GetValue("Uri", typeof(string)); - int startLine = (int)info.GetValue("StartLine", typeof(int)); - int startPos = (int)info.GetValue("StartPos", typeof(int)); - int endLine = (int)info.GetValue("EndLine", typeof(int)); - int endPos = (int)info.GetValue("EndPos", typeof(int)); + string uriString = (string)info.GetValue("Uri", typeof(string))!; + int startLine = (int)info.GetValue("StartLine", typeof(int))!; + int startPos = (int)info.GetValue("StartPos", typeof(int))!; + int endLine = (int)info.GetValue("EndLine", typeof(int))!; + int endPos = (int)info.GetValue("EndPos", typeof(int))!; _lineInfo = new SourceLineInfo(uriString, startLine, startPos, endLine, endPos); } @@ -154,7 +156,7 @@ internal XslLoadException(CompilerError error) SetSourceLineInfo(new SourceLineInfo(error.FileName, errorLine, errorColumn, errorLine, errorColumn)); } - internal void SetSourceLineInfo(ISourceLineInfo lineInfo) + internal void SetSourceLineInfo(ISourceLineInfo? lineInfo) { Debug.Assert(lineInfo == null || lineInfo.Uri != null); _lineInfo = lineInfo; @@ -175,7 +177,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont } } - public override string SourceUri + public override string? SourceUri { get { return _lineInfo != null ? _lineInfo.Uri : null; } } @@ -190,11 +192,11 @@ public override int LinePosition get { return _lineInfo != null ? _lineInfo.Start.Pos : 0; } } - private static string AppendLineInfoMessage(string message, ISourceLineInfo lineInfo) + private static string AppendLineInfoMessage(string message, ISourceLineInfo? lineInfo) { if (lineInfo != null) { - string fileName = SourceLineInfo.GetFileName(lineInfo.Uri); + string fileName = SourceLineInfo.GetFileName(lineInfo.Uri!); string lineInfoMessage = CreateMessage(SR.Xml_ErrorFilePosition, fileName, lineInfo.Start.Line.ToString(CultureInfo.InvariantCulture), lineInfo.Start.Pos.ToString(CultureInfo.InvariantCulture)); if (lineInfoMessage != null && lineInfoMessage.Length > 0) { @@ -208,7 +210,7 @@ private static string AppendLineInfoMessage(string message, ISourceLineInfo line return message; } - internal static string CreateMessage(ISourceLineInfo lineInfo, string res, params string[] args) + internal static string CreateMessage(ISourceLineInfo? lineInfo, string res, params string?[]? args) { return AppendLineInfoMessage(CreateMessage(res, args), lineInfo); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Compiler.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Compiler.cs index e8e141b26291d..dcf14189c2050 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Compiler.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Compiler.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; @@ -41,14 +42,14 @@ internal class Compiler { public XsltSettings Settings; public bool IsDebug; - public string ScriptAssemblyPath; + public string? ScriptAssemblyPath; public int Version; // 0 - Auto; 1 - XSLT 1.0; 2 - XSLT 2.0 - public string inputTypeAnnotations; // null - "unspecified"; "preserve"; "strip" + public string? inputTypeAnnotations; // null - "unspecified"; "preserve"; "strip" public CompilerErrorCollection CompilerErrorColl; // Results of the compilation public int CurrentPrecedence; // Decreases by 1 with each import - public XslNode StartApplyTemplates; - public RootLevel Root; + public XslNode? StartApplyTemplates; + public RootLevel? Root; public Scripts Scripts; public Output Output = new Output(); public List ExternalPars = new List(); @@ -65,7 +66,7 @@ internal class Compiler private readonly Dictionary _moduleOrder = new Dictionary(); - public Compiler(XsltSettings settings, bool debug, string scriptAssemblyPath) + public Compiler(XsltSettings settings, bool debug, string? scriptAssemblyPath) { Debug.Assert(CompilerErrorColl == null, "Compiler cannot be reused"); @@ -77,7 +78,7 @@ public Compiler(XsltSettings settings, bool debug, string scriptAssemblyPath) Scripts = new Scripts(this); } - public CompilerErrorCollection Compile(object stylesheet, XmlResolver xmlResolver, out QilExpression qil) + public CompilerErrorCollection Compile(object stylesheet, XmlResolver? xmlResolver, out QilExpression qil) { Debug.Assert(stylesheet != null); Debug.Assert(Root == null, "Compiler cannot be reused"); @@ -106,9 +107,9 @@ public void AddModule(string baseUri) } } - public void ApplyNsAliases(ref string prefix, ref string nsUri) + public void ApplyNsAliases(ref string? prefix, ref string nsUri) { - NsAlias alias; + NsAlias? alias; if (NsAliases.TryGetValue(nsUri, out alias)) { nsUri = alias.ResultNsUri; @@ -117,9 +118,9 @@ public void ApplyNsAliases(ref string prefix, ref string nsUri) } // Returns true in case of redefinition - public bool SetNsAlias(string ssheetNsUri, string resultNsUri, string resultPrefix, int importPrecedence) + public bool SetNsAlias(string ssheetNsUri, string resultNsUri, string? resultPrefix, int importPrecedence) { - NsAlias oldNsAlias; + NsAlias? oldNsAlias; if (NsAliases.TryGetValue(ssheetNsUri, out oldNsAlias)) { // Namespace alias for this stylesheet namespace URI has already been defined @@ -149,7 +150,7 @@ private void MergeAttributeSets(Stylesheet sheet) { foreach (QilName attSetName in sheet.AttributeSets.Keys) { - AttributeSet attSet; + AttributeSet? attSet; if (!this.AttributeSets.TryGetValue(attSetName, out attSet)) { this.AttributeSets[attSetName] = sheet.AttributeSets[attSetName]; @@ -168,7 +169,7 @@ private void MergeGlobalVarPars(Stylesheet sheet) foreach (VarPar var in sheet.GlobalVarPars) { Debug.Assert(var.NodeType == XslNodeType.Variable || var.NodeType == XslNodeType.Param); - if (!AllGlobalVarPars.ContainsKey(var.Name)) + if (!AllGlobalVarPars.ContainsKey(var.Name!)) { if (var.NodeType == XslNodeType.Variable) { @@ -178,7 +179,7 @@ private void MergeGlobalVarPars(Stylesheet sheet) { ExternalPars.Add(var); } - AllGlobalVarPars[var.Name] = var; + AllGlobalVarPars[var.Name!] = var; } } sheet.GlobalVarPars = null; @@ -220,7 +221,7 @@ public bool ParseQName(string qname, out string prefix, out string localName, IE } } - public bool ParseNameTest(string nameTest, out string prefix, out string localName, IErrorHelper errorHelper) + public bool ParseNameTest(string nameTest, out string? prefix, out string? localName, IErrorHelper errorHelper) { Debug.Assert(nameTest != null); try @@ -313,22 +314,22 @@ public bool ExitForwardsCompatible(bool fwdCompat) return true; } - public CompilerError CreateError(ISourceLineInfo lineInfo, string res, params string[] args) + public CompilerError CreateError(ISourceLineInfo lineInfo, string res, params string?[]? args) { - AddModule(lineInfo.Uri); + AddModule(lineInfo.Uri!); return new CompilerError( - lineInfo.Uri, lineInfo.Start.Line, lineInfo.Start.Pos, /*errorNumber:*/string.Empty, + lineInfo.Uri!, lineInfo.Start.Line, lineInfo.Start.Pos, /*errorNumber:*/string.Empty, /*errorText:*/XslTransformException.CreateMessage(res, args) ); } - public void ReportError(ISourceLineInfo lineInfo, string res, params string[] args) + public void ReportError(ISourceLineInfo lineInfo, string res, params string?[]? args) { CompilerError error = CreateError(lineInfo, res, args); CompilerErrorColl.Add(error); } - public void ReportWarning(ISourceLineInfo lineInfo, string res, params string[] args) + public void ReportWarning(ISourceLineInfo lineInfo, string res, params string?[]? args) { int warningLevel = 1; if (0 <= Settings.WarningLevel && Settings.WarningLevel < warningLevel) @@ -371,9 +372,9 @@ public CompilerErrorComparer(Dictionary moduleOrder) _moduleOrder = moduleOrder; } - public int Compare(CompilerError x, CompilerError y) + public int Compare(CompilerError? x, CompilerError? y) { - if ((object)x == (object)y) + if ((object?)x == (object?)y) return 0; if (x == null) @@ -410,9 +411,9 @@ public int Compare(CompilerError x, CompilerError y) internal class Output { public XmlWriterSettings Settings; - public string Version; - public string Encoding; - public XmlQualifiedName Method; + public string? Version; + public string? Encoding; + public XmlQualifiedName? Method; // All the xsl:output elements occurring in a stylesheet are merged into a single effective xsl:output element. // We store the import precedence of each attribute value to catch redefinitions with the same import precedence. @@ -467,10 +468,10 @@ public DecimalFormatDecl(XmlQualifiedName name, string infinitySymbol, string na internal class NsAlias { public readonly string ResultNsUri; - public readonly string ResultPrefix; + public readonly string? ResultPrefix; public readonly int ImportPrecedence; - public NsAlias(string resultNsUri, string resultPrefix, int importPrecedence) + public NsAlias(string resultNsUri, string? resultPrefix, int importPrecedence) { this.ResultNsUri = resultNsUri; this.ResultPrefix = resultPrefix; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerError.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerError.cs index fa10fd9a2480f..4a313c993844b 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerError.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerError.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections; namespace System.Xml.Xsl.Xslt diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerScopeManager.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerScopeManager.cs index 66ce38dd6830f..315f81ad63996 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerScopeManager.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerScopeManager.cs @@ -1,7 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Xml.Xsl.Xslt { @@ -31,8 +33,9 @@ public struct ScopeRecord { public int scopeCount; public ScopeFlags flags; - public string ncName; // local-name for variable, prefix for namespace, null for extension or excluded namespace - public string nsUri; // namespace uri + public string? ncName; // local-name for variable, prefix for namespace, null for extension or excluded namespace + public string? nsUri; // namespace uri + [AllowNull] public V value; // value for variable, null for namespace // Exactly one of these three properties is true for every given record @@ -96,7 +99,7 @@ public void CheckEmpty() } // returns true if ns decls was added to scope - public bool EnterScope(NsDecl nsDecl) + public bool EnterScope(NsDecl? nsDecl) { _lastScopes++; @@ -142,7 +145,7 @@ private void AddRecord() _lastScopes = 0; } - private void AddRecord(ScopeFlags flag, string ncName, string uri, V value) + private void AddRecord(ScopeFlags flag, string? ncName, string? uri, [AllowNull] V value) { Debug.Assert(flag == (flag & ScopeFlags.ExclusiveFlags) && (flag & (flag - 1)) == 0 && flag != 0, "One exclusive flag"); Debug.Assert(uri != null || ncName == null, "null, null means exclude '#all'"); @@ -202,12 +205,12 @@ public void AddVariable(QilName varName, V value) // Since the prefix might be redefined in an inner scope, we search in descending order in [to, from] // If interval is empty (from < to), the function returns null. - private string LookupNamespace(string prefix, int from, int to) + private string? LookupNamespace(string prefix, int from, int to) { Debug.Assert(prefix != null); for (int record = from; to <= record; --record) { - string recPrefix, recNsUri; + string? recPrefix, recNsUri; ScopeFlags flags = GetName(ref _records[record], out recPrefix, out recNsUri); if ( (flags & ScopeFlags.NsDecl) != 0 && @@ -220,12 +223,12 @@ private string LookupNamespace(string prefix, int from, int to) return null; } - public string LookupNamespace(string prefix) + public string? LookupNamespace(string prefix) { return LookupNamespace(prefix, _lastRecord, 0); } - private static ScopeFlags GetName(ref ScopeRecord re, out string prefix, out string nsUri) + private static ScopeFlags GetName(ref ScopeRecord re, out string? prefix, out string? nsUri) { prefix = re.ncName; nsUri = re.nsUri; @@ -237,7 +240,7 @@ public void AddNsDeclaration(string prefix, string nsUri) AddRecord(ScopeFlags.NsDecl, prefix, nsUri, default(V)); } - public void AddExNamespace(string nsUri) + public void AddExNamespace(string? nsUri) { AddRecord(ScopeFlags.NsExcl, null, nsUri, default(V)); } @@ -248,7 +251,7 @@ public bool IsExNamespace(string nsUri) int exAll = 0; for (int record = _lastRecord; 0 <= record; record--) { - string recPrefix, recNsUri; + string? recPrefix, recNsUri; ScopeFlags flags = GetName(ref _records[record], out recPrefix, out recNsUri); if ((flags & ScopeFlags.NsExcl) != 0) { @@ -272,7 +275,7 @@ public bool IsExNamespace(string nsUri) bool undefined = false; for (int prev = record + 1; prev < exAll; prev++) { - string prevPrefix, prevNsUri; + string? prevPrefix, prevNsUri; ScopeFlags prevFlags = GetName(ref _records[prev], out prevPrefix, out prevNsUri); if ( (flags & ScopeFlags.NsDecl) != 0 && @@ -299,7 +302,7 @@ private int SearchVariable(string localName, string uri) Debug.Assert(localName != null); for (int record = _lastRecord; 0 <= record; --record) { - string recLocal, recNsUri; + string? recLocal, recNsUri; ScopeFlags flags = GetName(ref _records[record], out recLocal, out recNsUri); if ( (flags & ScopeFlags.Variable) != 0 && @@ -313,6 +316,7 @@ private int SearchVariable(string localName, string uri) return -1; } + [return: MaybeNull] public V LookupVariable(string localName, string uri) { int record = SearchVariable(localName, uri); @@ -359,7 +363,7 @@ internal System.Collections.Generic.IEnumerable GetActiveRecords() if (_records[currentRecord].IsNamespace) { // This is a namespace declaration - if (LookupNamespace(_records[currentRecord].ncName, _lastRecord, currentRecord + 1) != null) + if (LookupNamespace(_records[currentRecord].ncName!, _lastRecord, currentRecord + 1) != null) { continue; } @@ -394,7 +398,7 @@ public bool MoveNext() if (_scope._records[_currentRecord].IsNamespace) { // This is a namespace declaration - if (_scope.LookupNamespace(_scope._records[_currentRecord].ncName, _lastRecord, _currentRecord + 1) == null) + if (_scope.LookupNamespace(_scope._records[_currentRecord].ncName!, _lastRecord, _currentRecord + 1) == null) { // Its prefix has not been redefined later in [currentRecord + 1, lastRecord] return true; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Focus.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Focus.cs index a36998b2bf9ff..632349da5c319 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Focus.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Focus.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.Xml.Xsl.XPath; @@ -34,7 +35,7 @@ internal struct SingletonFocus : IFocus { private readonly XPathQilFactory _f; private SingletonFocusType _focusType; - private QilIterator _current; + private QilIterator? _current; public SingletonFocus(XPathQilFactory f) { @@ -49,7 +50,7 @@ public void SetFocus(SingletonFocusType focusType) _focusType = focusType; } - public void SetFocus(QilIterator current) + public void SetFocus(QilIterator? current) { if (current != null) { @@ -98,7 +99,7 @@ public QilNode GetLast() internal struct FunctionFocus : IFocus { private bool _isSet; - private QilParameter _current, _position, _last; + private QilParameter? _current, _position, _last; public void StartFocus(IList args, XslFlags flags) { @@ -107,17 +108,17 @@ public void StartFocus(IList args, XslFlags flags) if ((flags & XslFlags.Current) != 0) { _current = (QilParameter)args[argNum++]; - Debug.Assert(_current.Name.NamespaceUri == XmlReservedNs.NsXslDebug && _current.Name.LocalName == "current"); + Debug.Assert(_current.Name!.NamespaceUri == XmlReservedNs.NsXslDebug && _current.Name.LocalName == "current"); } if ((flags & XslFlags.Position) != 0) { _position = (QilParameter)args[argNum++]; - Debug.Assert(_position.Name.NamespaceUri == XmlReservedNs.NsXslDebug && _position.Name.LocalName == "position"); + Debug.Assert(_position.Name!.NamespaceUri == XmlReservedNs.NsXslDebug && _position.Name.LocalName == "position"); } if ((flags & XslFlags.Last) != 0) { _last = (QilParameter)args[argNum++]; - Debug.Assert(_last.Name.NamespaceUri == XmlReservedNs.NsXslDebug && _last.Name.LocalName == "last"); + Debug.Assert(_last.Name!.NamespaceUri == XmlReservedNs.NsXslDebug && _last.Name.LocalName == "last"); } _isSet = true; } @@ -154,7 +155,7 @@ public QilNode GetLast() internal struct LoopFocus : IFocus { private readonly XPathQilFactory _f; - private QilIterator _current, _cached, _last; + private QilIterator? _current, _cached, _last; public LoopFocus(XPathQilFactory f) { @@ -173,14 +174,14 @@ public bool IsFocusSet get { return _current != null; } } - public QilNode GetCurrent() + public QilNode? GetCurrent() { return _current; } public QilNode GetPosition() { - return _f.XsltConvert(_f.PositionOf(_current), T.DoubleX); + return _f.XsltConvert(_f.PositionOf(_current!), T.DoubleX); } public QilNode GetLast() @@ -197,19 +198,19 @@ public void EnsureCache() { if (_cached == null) { - _cached = _f.Let(_current.Binding); + _cached = _f.Let(_current!.Binding!); _current.Binding = _cached; } } - public void Sort(QilNode sortKeys) + public void Sort(QilNode? sortKeys) { if (sortKeys != null) { // If sorting is required, cache the input node-set to support last() within sort key expressions EnsureCache(); // The rest of the loop content must be compiled in the context of already sorted node-set - _current = _f.For(_f.Sort(_current, sortKeys)); + _current = _f.For(_f.Sort(_current!, sortKeys)); } } @@ -220,9 +221,10 @@ public QilLoop ConstructLoop(QilNode body) { // last() encountered either in the sort keys or in the body of the current loop EnsureCache(); - _last.Binding = _f.XsltConvert(_f.Length(_cached), T.DoubleX); + _last.Binding = _f.XsltConvert(_f.Length(_cached!), T.DoubleX); } - result = _f.BaseFactory.Loop(_current, body); + + result = _f.BaseFactory.Loop(_current!, body); if (_last != null) { result = _f.BaseFactory.Loop(_last, result); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/IErrorHelper.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/IErrorHelper.cs index db716fccb0562..4565dfa83b00d 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/IErrorHelper.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/IErrorHelper.cs @@ -1,12 +1,13 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable namespace System.Xml.Xsl { internal interface IErrorHelper { - void ReportError(string res, params string[] args); + void ReportError(string res, params string?[]? args); - void ReportWarning(string res, params string[] args); + void ReportWarning(string res, params string?[]? args); } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/InvokeGenerator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/InvokeGenerator.cs index f844f36e5fe91..d7d4c0234dd15 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/InvokeGenerator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/InvokeGenerator.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.Xml.Xsl.Qil; @@ -25,8 +26,8 @@ internal class InvokeGenerator : QilCloneVisitor private readonly bool _debug; private readonly Stack _iterStack; - private QilList _formalArgs; - private QilList _invokeArgs; + private QilList? _formalArgs; + private QilList? _invokeArgs; private int _curArg; // this.Clone() depends on this value private readonly XsltQilFactory _fac; @@ -49,14 +50,14 @@ public QilNode GenerateInvoke(QilFunction func, IList actualArgs) { // Find actual value for a given formal arg QilParameter formalArg = (QilParameter)_formalArgs[_curArg]; - QilNode invokeArg = FindActualArg(formalArg, actualArgs); + QilNode? invokeArg = FindActualArg(formalArg, actualArgs); // If actual value was not specified, use the default value and copy its debug comment if (invokeArg == null) { if (_debug) { - if (formalArg.Name.NamespaceUri == XmlReservedNs.NsXslDebug) + if (formalArg.Name!.NamespaceUri == XmlReservedNs.NsXslDebug) { Debug.Assert(formalArg.Name.LocalName == "namespaces", "Cur,Pos,Last don't have default values and should be always added to by caller in AddImplicitArgs()"); Debug.Assert(formalArg.DefaultValue != null, "PrecompileProtoTemplatesHeaders() set it"); @@ -69,13 +70,13 @@ public QilNode GenerateInvoke(QilFunction func, IList actualArgs) } else { - Debug.Assert(formalArg.Name.NamespaceUri != XmlReservedNs.NsXslDebug, "Cur,Pos,Last don't have default values and should be always added to by caller in AddImplicitArgs(). We don't have $namespaces in !debug."); - invokeArg = Clone(formalArg.DefaultValue); + Debug.Assert(formalArg.Name!.NamespaceUri != XmlReservedNs.NsXslDebug, "Cur,Pos,Last don't have default values and should be always added to by caller in AddImplicitArgs(). We don't have $namespaces in !debug."); + invokeArg = Clone(formalArg.DefaultValue!); } } - XmlQueryType formalType = formalArg.XmlType; - XmlQueryType invokeType = invokeArg.XmlType; + XmlQueryType formalType = formalArg.XmlType!; + XmlQueryType invokeType = invokeArg.XmlType!; // Possible arg types: anyType, node-set, string, boolean, and number _fac.CheckXsltType(formalArg); @@ -99,13 +100,13 @@ public QilNode GenerateInvoke(QilFunction func, IList actualArgs) return invoke; } - private QilNode FindActualArg(QilParameter formalArg, IList actualArgs) + private QilNode? FindActualArg(QilParameter formalArg, IList actualArgs) { - QilName argName = formalArg.Name; + QilName? argName = formalArg.Name; Debug.Assert(argName != null); foreach (XslNode actualArg in actualArgs) { - if (actualArg.Name.Equals(argName)) + if (actualArg.Name!.Equals(argName)) { return ((VarPar)actualArg).Value; } @@ -117,7 +118,7 @@ private QilNode FindActualArg(QilParameter formalArg, IList actualArgs) protected override QilNode VisitReference(QilNode n) { - QilNode replacement = FindClonedReference(n); + QilNode? replacement = FindClonedReference(n); // If the reference is internal for the subtree being cloned, return it as is if (replacement != null) @@ -130,8 +131,8 @@ protected override QilNode VisitReference(QilNode n) // xsl:param's) must be taken care of. for (int prevArg = 0; prevArg < _curArg; prevArg++) { - Debug.Assert(_formalArgs[prevArg] != null, "formalArg must be in the list"); - Debug.Assert(_invokeArgs[prevArg] != null, "This arg should be compiled already"); + Debug.Assert(_formalArgs![prevArg] != null, "formalArg must be in the list"); + Debug.Assert(_invokeArgs![prevArg] != null, "This arg should be compiled already"); // Is this a reference to prevArg? if (n == _formalArgs[prevArg]) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/KeyMatchBuilder.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/KeyMatchBuilder.cs index 70243675da70f..81cd01cc051cc 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/KeyMatchBuilder.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/KeyMatchBuilder.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; using System.Collections; @@ -10,6 +11,7 @@ using MS.Internal.Xml; using System.Xml.Xsl.XPath; using System.Xml.Xsl.Qil; +using System.Diagnostics.CodeAnalysis; namespace System.Xml.Xsl.Xslt { @@ -33,7 +35,8 @@ public override void StartBuild() _depth++; } - public override QilNode EndBuild(QilNode result) + [return: NotNullIfNotNull("result")] + public override QilNode? EndBuild(QilNode? result) { _depth--; Debug.Assert(0 <= _depth && _depth <= 1, "this shouldn't happen"); @@ -63,7 +66,7 @@ public virtual IXPathBuilder GetPredicateBuilder(QilNode ctx) internal class PathConvertor : QilReplaceVisitor { private new readonly XPathQilFactory f; - private QilNode _fixup; + private QilNode? _fixup; public PathConvertor(XPathQilFactory f) : base(f.BaseFactory) { this.f = f; @@ -96,7 +99,7 @@ protected override QilNode Visit(QilNode n) // Filter($j= ... Filter($i = Content(fixup), ...)) -> Filter($j= ... Filter($i = Loop($j = DesendentOrSelf(Root(fixup)), Content($j), ...))) protected override QilNode VisitLoop(QilLoop n) { - if (n.Variable.Binding.NodeType == QilNodeType.Root || n.Variable.Binding.NodeType == QilNodeType.Deref) + if (n.Variable.Binding!.NodeType == QilNodeType.Root || n.Variable.Binding.NodeType == QilNodeType.Deref) { // This is absolute path already. We shouldn't touch it return n; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Keywords.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Keywords.cs index 7574183e0ca17..9bcc76bda2f23 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Keywords.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Keywords.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Xml; namespace System.Xml.Xsl.Xslt diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/MatcherBuilder.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/MatcherBuilder.cs index 6d99510a74408..ca2cde344eb7f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/MatcherBuilder.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/MatcherBuilder.cs @@ -1,8 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Xml.Xsl.Qil; using System.Xml.Xsl.XPath; @@ -92,16 +94,16 @@ internal class TemplateMatch private readonly Template _template; private readonly double _priority; private XmlNodeKindFlags _nodeKind; - private QilName _qname; + private QilName? _qname; private readonly QilIterator _iterator; - private QilNode _condition; // null means f.True() + private QilNode? _condition; // null means f.True() public XmlNodeKindFlags NodeKind { get { return _nodeKind; } } - public QilName QName + public QilName? QName { get { return _qname; } } @@ -111,12 +113,12 @@ public QilIterator Iterator get { return _iterator; } } - public QilNode Condition + public QilNode? Condition { get { return _condition; } } - public QilFunction TemplateFunction + public QilFunction? TemplateFunction { get { return _template.Function; } } @@ -156,7 +158,7 @@ private void NipOffTypeNameCheck() { QilBinary[] leftPath = new QilBinary[4]; // Circular buffer for last 4 And nodes int idx = -1; // Index of last element in leftPath - QilNode node = _condition; // Walker through left path of the tree + QilNode node = _condition!; // Walker through left path of the tree _nodeKind = XmlNodeKindFlags.None; _qname = null; @@ -178,7 +180,7 @@ private void NipOffTypeNameCheck() return; } - XmlNodeKindFlags nodeKinds = isType.Right.XmlType.NodeKinds; + XmlNodeKindFlags nodeKinds = isType.Right.XmlType!.NodeKinds; if (!Bits.ExactlyOne((uint)nodeKinds)) { return; @@ -200,7 +202,7 @@ private void NipOffTypeNameCheck() { // Recognized pattern B x = lastAnd; - _qname = (QilName)((QilLiteral)eq.Right).Value; + _qname = (QilName?)((QilLiteral)eq.Right).Value; idx--; } } @@ -230,10 +232,10 @@ internal class TemplateMatchComparer : IComparer // * x's priority is equal to y's priority, and x occurs later in the stylesheet than y. // Order of TemplateMatch'es from the same xsl:template/@match attribute does not matter. - public int Compare(TemplateMatch x, TemplateMatch y) + public int Compare(TemplateMatch? x, TemplateMatch? y) { - Debug.Assert(!double.IsNaN(x._priority)); - Debug.Assert(!double.IsNaN(y._priority)); + Debug.Assert(!double.IsNaN(x!._priority)); + Debug.Assert(!double.IsNaN(y!._priority)); return ( x._priority > y._priority ? 1 : x._priority < y._priority ? -1 : @@ -272,8 +274,8 @@ public void Clear() public void Add(Pattern pattern) { - QilName qname = pattern.Match.QName; - List list; + QilName? qname = pattern.Match.QName; + List? list; if (qname == null) { @@ -361,7 +363,7 @@ private void CollectPatternsInternal(Stylesheet sheet, QilName mode) CollectPatternsInternal(import, mode); } - List matchesForMode; + List? matchesForMode; if (sheet.TemplateMatches.TryGetValue(mode, out matchesForMode)) { AddPatterns(matchesForMode); @@ -380,7 +382,7 @@ public void CollectPatterns(StylesheetLevel sheet, QilName mode) private QilNode MatchPattern(QilIterator it, TemplateMatch match) { - QilNode cond = match.Condition; + QilNode? cond = match.Condition; if (cond == null) { return _f.True(); @@ -515,7 +517,7 @@ public QilNode BuildMatcher(QilIterator it, IList actualArgs, QilNode o { foreach (TemplateMatch match in list) { - branches[++priority] = _invkGen.GenerateInvoke(match.TemplateFunction, actualArgs); + branches[++priority] = _invkGen.GenerateInvoke(match.TemplateFunction!, actualArgs); } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/OutputScopeManager.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/OutputScopeManager.cs index 3672878e2e34b..9dde09dbc401a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/OutputScopeManager.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/OutputScopeManager.cs @@ -1,11 +1,13 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System; using System.Diagnostics; using System.Xml; using System.Collections; +#nullable enable namespace System.Xml.Xsl.Xslt { internal class OutputScopeManager @@ -13,8 +15,8 @@ internal class OutputScopeManager public struct ScopeReord { public int scopeCount; - public string prefix; - public string nsUri; + public string? prefix; + public string? nsUri; } private ScopeReord[] _records = new ScopeReord[32]; private int _lastRecord; @@ -63,7 +65,7 @@ public void AddNamespace(string prefix, string uri) AddRecord(prefix, uri); } - private void AddRecord(string prefix, string uri) + private void AddRecord(string? prefix, string? uri) { _records[_lastRecord].scopeCount = _lastScopes; _lastRecord++; @@ -117,7 +119,7 @@ public void InvalidateAllPrefixes() public void InvalidateNonDefaultPrefixes() { - string defaultNs = LookupNamespace(string.Empty); + string? defaultNs = LookupNamespace(string.Empty); if (defaultNs == null) { // We don't know default NS anyway. InvalidateAllPrefixes(); @@ -125,18 +127,19 @@ public void InvalidateNonDefaultPrefixes() else { if ( - _records[_lastRecord].prefix.Length == 0 && + _records[_lastRecord].prefix!.Length == 0 && _records[_lastRecord - 1].prefix == null ) { return; // Averything was already done } + AddRecord(null, null); AddRecord(string.Empty, defaultNs); } } - public string LookupNamespace(string prefix) + public string? LookupNamespace(string prefix) { Debug.Assert(prefix != null); for ( @@ -151,6 +154,7 @@ public string LookupNamespace(string prefix) return _records[record].nsUri; } } + return null; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGenerator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGenerator.cs index bafb3f8cf059d..a799185c15876 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGenerator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGenerator.cs @@ -5,10 +5,12 @@ // http://www.w3.org/TR/xslt20/ //------------------------------------------------------------------------------ +#nullable enable using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Text; using System.Xml.Xsl.Qil; @@ -24,7 +26,7 @@ namespace System.Xml.Xsl.Xslt internal class ReferenceReplacer : QilReplaceVisitor { - private QilReference _lookFor, _replaceBy; + private QilReference? _lookFor, _replaceBy; public ReferenceReplacer(QilFactory f) : base(f) { @@ -40,7 +42,7 @@ public QilNode Replace(QilNode expr, QilReference lookFor, QilReference replaceB protected override QilNode VisitReference(QilNode n) { - return (n == _lookFor) ? _replaceBy : n; + return (n == _lookFor) ? _replaceBy! : n; } } @@ -56,23 +58,23 @@ internal partial class QilGenerator : IErrorHelper private readonly XPathPatternBuilder _ptrnBuilder; private readonly XPathPatternParser _ptrnParser; private readonly ReferenceReplacer _refReplacer; - private KeyMatchBuilder _keyMatchBuilder; + private KeyMatchBuilder? _keyMatchBuilder; private readonly InvokeGenerator _invkGen; private readonly MatcherBuilder _matcherBuilder; private readonly QilStrConcatenator _strConcat; private readonly VariableHelper _varHelper; - private Compiler _compiler; - private QilList _functions; - private QilFunction _generalKey; + private Compiler _compiler = null!; + private QilList _functions = null!; + private QilFunction? _generalKey; private bool _formatNumberDynamicUsed; - private QilList _extPars; - private QilList _gloVars; - private QilList _nsVars; + private QilList _extPars = null!; + private QilList _gloVars = null!; + private QilList _nsVars = null!; private readonly XmlQueryType _elementOrDocumentType; private readonly XmlQueryType _textOrAttributeType; - private XslNode _lastScope; + private XslNode? _lastScope; private XslVersion _xslVersion; private readonly QilName _nameCurrent; @@ -155,7 +157,7 @@ private QilExpression Compile(Compiler compiler) try { CompileKeys(); - CompileAndSortMatches(compiler.Root.Imports[0]); + CompileAndSortMatches(compiler.Root!.Imports[0]); PrecompileProtoTemplatesHeaders(); CompileGlobalVariables(); @@ -167,7 +169,7 @@ private QilExpression Compile(Compiler compiler) } catch (XslLoadException e) { - e.SetSourceLineInfo(_lastScope.SourceLine); + e.SetSourceLineInfo(_lastScope!.SourceLine); throw; } catch (Exception e) @@ -176,18 +178,18 @@ private QilExpression Compile(Compiler compiler) { throw; } - throw new XslLoadException(e, _lastScope.SourceLine); + throw new XslLoadException(e, _lastScope!.SourceLine); } CompileInitializationCode(); - QilNode root = CompileRootExpression(compiler.StartApplyTemplates); + QilNode root = CompileRootExpression(compiler.StartApplyTemplates!); // Clean default values which we calculate in caller context foreach (ProtoTemplate tmpl in compiler.AllTemplates) { - foreach (QilParameter par in tmpl.Function.Arguments) + foreach (QilParameter par in tmpl.Function!.Arguments) { - if (!IsDebug || par.Name.Equals(_nameNamespaces)) + if (!IsDebug || par.Name!.Equals(_nameNamespaces)) { par.DefaultValue = null; } @@ -195,9 +197,9 @@ private QilExpression Compile(Compiler compiler) } // Create list of all early bound objects - Dictionary scriptClasses = compiler.Scripts.ScriptClasses; + Dictionary scriptClasses = compiler.Scripts.ScriptClasses; List ebTypes = new List(scriptClasses.Count); - foreach (KeyValuePair pair in scriptClasses) + foreach (KeyValuePair pair in scriptClasses) { if (pair.Value != null) { @@ -225,7 +227,7 @@ private QilNode InvokeOnCurrentNodeChanged() { Debug.Assert(IsDebug && _curLoop.IsFocusSet); QilIterator i; - return _f.Loop(i = _f.Let(_f.InvokeOnCurrentNodeChanged(_curLoop.GetCurrent())), _f.Sequence()); + return _f.Loop(i = _f.Let(_f.InvokeOnCurrentNodeChanged(_curLoop.GetCurrent()!)), _f.Sequence()); } [Conditional("DEBUG")] @@ -289,13 +291,13 @@ private QilNode CompileRootExpression(XslNode applyTmpls) // Compile start apply-templates call CheckSingletonFocus(); _singlFocus.SetFocus(SingletonFocusType.InitialContextNode); - QilNode result = GenerateApply(_compiler.Root, applyTmpls); + QilNode result = GenerateApply(_compiler.Root!, applyTmpls); _singlFocus.SetFocus(null); return _f.DocumentCtor(result); } - private QilList EnterScope(XslNode node) + private QilList? EnterScope(XslNode node) { // This is the only place where lastScope is changed _lastScope = node; @@ -312,14 +314,14 @@ private void ExitScope() _scope.ExitScope(); } - private QilList BuildDebuggerNamespaces() + private QilList? BuildDebuggerNamespaces() { if (IsDebug) { QilList nsDecls = _f.BaseFactory.Sequence(); foreach (ScopeRecord rec in _scope) { - nsDecls.Add(_f.NamespaceDecl(_f.String(rec.ncName), _f.String(rec.nsUri))); + nsDecls.Add(_f.NamespaceDecl(_f.String(rec.ncName!), _f.String(rec.nsUri!))); } return nsDecls; } @@ -354,7 +356,7 @@ private QilNode GetCurrentNode() { if (_curLoop.IsFocusSet) { - return _curLoop.GetCurrent(); + return _curLoop.GetCurrent()!; } else if (_funcFocus.IsFocusSet) { @@ -433,7 +435,7 @@ private QilIterator GetNsVar(QilList nsList) // All global vars at this point are nsList like one we are looking now. foreach (QilIterator var in _nsVars) { - Debug.Assert(var.XmlType.IsSubtypeOf(T.NamespaceS)); + Debug.Assert(var.XmlType!.IsSubtypeOf(T.NamespaceS)); Debug.Assert(var.Binding is QilList); QilList varList = (QilList)var.Binding; if (varList.Count != nsList.Count) @@ -469,9 +471,9 @@ private QilIterator GetNsVar(QilList nsList) private void PrecompileProtoTemplatesHeaders() { // All global variables should be in scoupe here. - List paramWithCalls = null; - Dictionary paramToTemplate = null; - Dictionary paramToFunction = null; + List? paramWithCalls = null; + Dictionary? paramToTemplate = null; + Dictionary? paramToFunction = null; foreach (ProtoTemplate tmpl in _compiler.AllTemplates) { @@ -480,7 +482,7 @@ private void PrecompileProtoTemplatesHeaders() QilList args = _f.FormalParameterList(); XslFlags flags = !IsDebug ? tmpl.Flags : XslFlags.FullFocus; - QilList nsList = EnterScope(tmpl); + QilList? nsList = EnterScope(tmpl); if ((flags & XslFlags.Current) != 0) { args.Add(CreateXslParam(CloneName(_nameCurrent), T.NodeNotRtf)); @@ -502,7 +504,7 @@ private void PrecompileProtoTemplatesHeaders() args.Add(ns); } - Template template = tmpl as Template; + Template? template = tmpl as Template; if (template != null) { Debug.Assert(tmpl.NodeType == XslNodeType.Template); @@ -522,7 +524,7 @@ private void PrecompileProtoTemplatesHeaders() { VarPar xslPar = (VarPar)node; EnterScope(xslPar); - if (_scope.IsLocalVariable(xslPar.Name.LocalName, xslPar.Name.NamespaceUri)) + if (_scope.IsLocalVariable(xslPar.Name!.LocalName, xslPar.Name.NamespaceUri)) { ReportError(/*[XT0580]*/SR.Xslt_DupLocalVariable, xslPar.Name.QualifiedName); } @@ -549,10 +551,10 @@ private void PrecompileProtoTemplatesHeaders() QilList paramActual = _f.ActualParameterList(); for (int j = 0; j < args.Count; j++) { - QilParameter formal = _f.Parameter(args[j].XmlType); + QilParameter formal = _f.Parameter(args[j].XmlType!); { - formal.DebugName = ((QilParameter)args[j]).DebugName; - formal.Name = CloneName(((QilParameter)args[j]).Name); + formal.DebugName = ((QilParameter)args[j]).DebugName!; + formal.Name = CloneName(((QilParameter)args[j]).Name!); SetLineInfo(formal, args[j].SourceLine); } paramFormal.Add(formal); @@ -576,8 +578,8 @@ private void PrecompileProtoTemplatesHeaders() paramToFunction = new Dictionary(); } paramWithCalls.Add(xslPar); - paramToTemplate.Add(xslPar, template); - paramToFunction.Add(xslPar, paramFunc); + paramToTemplate!.Add(xslPar, template); + paramToFunction!.Add(xslPar, paramFunc); } } SetLineInfo(param, xslPar.SourceLine); @@ -610,15 +612,15 @@ private void PrecompileProtoTemplatesHeaders() Debug.Assert(!IsDebug, "In debug mode we don't generate parumWithCalls functions. Otherwise focus flags should be adjusted"); foreach (VarPar par in paramWithCalls) { - Template tmpl = paramToTemplate[par]; - QilFunction func = paramToFunction[par]; + Template tmpl = paramToTemplate![par]; + QilFunction func = paramToFunction![par]; CheckSingletonFocus(); _funcFocus.StartFocus(func.Arguments, par.Flags); EnterScope(tmpl); EnterScope(par); foreach (QilParameter arg in func.Arguments) { - _scope.AddVariable(arg.Name, arg); + _scope.AddVariable(arg.Name!, arg); } func.Definition = CompileVarParValue(par); SetLineInfo(func.Definition, par.SourceLine); @@ -648,14 +650,14 @@ private void CompileProtoTemplate(ProtoTemplate tmpl) _funcFocus.StartFocus(tmpl.Function.Arguments, !IsDebug ? tmpl.Flags : XslFlags.FullFocus); foreach (QilParameter arg in tmpl.Function.Arguments) { - if (arg.Name.NamespaceUri != XmlReservedNs.NsXslDebug) + if (arg.Name!.NamespaceUri != XmlReservedNs.NsXslDebug) { Debug.Assert(tmpl is Template, "Only templates can have explicit arguments"); if (IsDebug) { Debug.Assert(arg.DefaultValue == null, "Argument must not be compiled yet"); - VarPar xslParam = (VarPar)arg.Annotation; - QilList nsListParam = EnterScope(xslParam); + VarPar xslParam = (VarPar)arg.Annotation!; + QilList? nsListParam = EnterScope(xslParam); arg.DefaultValue = CompileVarParValue(xslParam); ExitScope(); arg.DefaultValue = SetDebugNs(arg.DefaultValue, nsListParam); @@ -706,7 +708,7 @@ private QilNode CompileInstructions(IList instructions, int from, QilLi { continue; // already compiled by CompileProtoTemplate() } - QilList nsList = EnterScope(node); + QilList? nsList = EnterScope(node); QilNode result; switch (nodeType) @@ -760,7 +762,7 @@ private QilNode CompileInstructions(IList instructions, int from, QilLi if (nodeType == XslNodeType.Variable) { QilIterator var = _f.Let(result); - var.DebugName = node.Name.ToString(); + var.DebugName = node.Name!.ToString(); _scope.AddVariable(node.Name, var); // Process all remaining instructions in the recursive call result = _f.Loop(var, CompileInstructions(instructions, i + 1)); @@ -808,14 +810,14 @@ private QilNode CompileLiteralElement(XslNode node) Start: _prefixesInUse.Clear(); - QilName qname = node.Name; - string prefix = qname.Prefix; + QilName qname = node.Name!; + string prefix = qname!.Prefix; string nsUri = qname.NamespaceUri; - _compiler.ApplyNsAliases(ref prefix, ref nsUri); + _compiler.ApplyNsAliases(ref prefix!, ref nsUri); if (changePrefixes) { - _prefixesInUse.Add(prefix, nsUri); + _prefixesInUse.Add(prefix!, nsUri); } else { @@ -829,16 +831,16 @@ private QilNode CompileLiteralElement(XslNode node) QilList nsList = InstructionList(); foreach (ScopeRecord rec in _scope) { - string recPrefix = rec.ncName; - string recNsUri = rec.nsUri; - if (recNsUri != XmlReservedNs.NsXslt && !_scope.IsExNamespace(recNsUri)) + string? recPrefix = rec.ncName; + string? recNsUri = rec.nsUri; + if (recNsUri != XmlReservedNs.NsXslt && !_scope.IsExNamespace(recNsUri!)) { - _compiler.ApplyNsAliases(ref recPrefix, ref recNsUri); + _compiler.ApplyNsAliases(ref recPrefix, ref recNsUri!); if (changePrefixes) { - if (_prefixesInUse.Contains(recPrefix)) + if (_prefixesInUse.Contains(recPrefix!)) { - if ((string)_prefixesInUse[recPrefix] != recNsUri) + if ((string?)_prefixesInUse[recPrefix!] != recNsUri) { // Found a prefix conflict. Start again from the beginning leaving all prefixes untouched. _outputScope.PopScope(); @@ -848,14 +850,14 @@ private QilNode CompileLiteralElement(XslNode node) } else { - _prefixesInUse.Add(recPrefix, recNsUri); + _prefixesInUse.Add(recPrefix!, recNsUri); } } else { recPrefix = rec.ncName; } - AddNsDecl(nsList, recPrefix, recNsUri); + AddNsDecl(nsList, recPrefix!, recNsUri); } } @@ -869,7 +871,7 @@ private QilNode CompileLiteralElement(XslNode node) private QilNode CompileElement(NodeCtor node) { - QilNode qilNs = CompileStringAvt(node.NsAvt); + QilNode? qilNs = CompileStringAvt(node.NsAvt); QilNode qilName = CompileStringAvt(node.NameAvt); QilNode qname; @@ -912,22 +914,22 @@ private QilNode CompileElement(NodeCtor node) private QilNode CompileLiteralAttribute(XslNode node) { - QilName qname = node.Name; + QilName qname = node.Name!; string prefix = qname.Prefix; string nsUri = qname.NamespaceUri; // The default namespace do not apply directly to attributes if (prefix.Length != 0) { - _compiler.ApplyNsAliases(ref prefix, ref nsUri); + _compiler.ApplyNsAliases(ref prefix!, ref nsUri); } qname.Prefix = prefix; qname.NamespaceUri = nsUri; - return _f.AttributeCtor(qname, CompileTextAvt(node.Select)); + return _f.AttributeCtor(qname, CompileTextAvt(node.Select!)); } private QilNode CompileAttribute(NodeCtor node) { - QilNode qilNs = CompileStringAvt(node.NsAvt); + QilNode? qilNs = CompileStringAvt(node.NsAvt); QilNode qilName = CompileStringAvt(node.NameAvt); QilNode qname; bool explicitNamespace = false; @@ -978,7 +980,7 @@ private QilNode CompileAttribute(NodeCtor node) private readonly StringBuilder _unescapedText = new StringBuilder(); - private QilNode ExtractText(string source, ref int pos) + private QilNode? ExtractText(string source, ref int pos) { Debug.Assert(pos < source.Length); int i, start = pos; @@ -1011,7 +1013,7 @@ private QilNode ExtractText(string source, ref int pos) ReportError(/*[XT0370]*/SR.Xslt_SingleRightBraceInAvt, source); return null; } - return _f.Error(_lastScope.SourceLine, SR.Xslt_SingleRightBraceInAvt, source); + return _f.Error(_lastScope!.SourceLine, SR.Xslt_SingleRightBraceInAvt, source); } } } @@ -1035,7 +1037,7 @@ private QilNode CompileAvt(string source) int pos = 0; while (pos < source.Length) { - QilNode fixedPart = ExtractText(source, ref pos); + QilNode? fixedPart = ExtractText(source, ref pos); if (fixedPart != null) { result.Add(fixedPart); @@ -1056,7 +1058,8 @@ private QilNode CompileAvt(string source) private static readonly char[] s_curlyBraces = { '{', '}' }; - private QilNode CompileStringAvt(string avt) + [return: NotNullIfNotNull("avt")] + private QilNode? CompileStringAvt(string? avt) { if (avt == null) { @@ -1095,14 +1098,14 @@ private QilNode CompileTextAvt(string avt) private QilNode CompileText(Text node) { if (node.Hints == SerializationHints.None) - return _f.TextCtor(_f.String(node.Select)); + return _f.TextCtor(_f.String(node.Select!)); - return _f.RawTextCtor(_f.String(node.Select)); + return _f.RawTextCtor(_f.String(node.Select!)); } private QilNode CompilePI(XslNode node) { - QilNode qilName = CompileStringAvt(node.Select); + QilNode qilName = CompileStringAvt(node.Select!); if (qilName.NodeType == QilNodeType.LiteralString) { string name = (string)(QilLiteral)qilName; @@ -1118,10 +1121,10 @@ private QilNode CompileComment(XslNode node) private QilNode CompileError(XslNode node) { - return _f.Error(_f.String(node.Select)); + return _f.Error(_f.String(node.Select!)); } - private QilNode WrapLoopBody(ISourceLineInfo before, QilNode expr, ISourceLineInfo after) + private QilNode WrapLoopBody(ISourceLineInfo? before, QilNode expr, ISourceLineInfo? after) { Debug.Assert(_curLoop.IsFocusSet); if (IsDebug) @@ -1142,7 +1145,7 @@ private QilNode CompileForEach(XslNodeEx node) // Push new loop frame on the stack LoopFocus curLoopSaved = _curLoop; - QilIterator it = _f.For(CompileNodeSetExpression(node.Select)); + QilIterator it = _f.For(CompileNodeSetExpression(node.Select!)); _curLoop.SetFocus(it); // Compile sort keys and body @@ -1167,23 +1170,23 @@ private QilNode CompileApplyTemplates(XslNodeEx node) // Calculate select expression int varScope = _varHelper.StartVariables(); - QilIterator select = _f.Let(CompileNodeSetExpression(node.Select)); + QilIterator select = _f.Let(CompileNodeSetExpression(node.Select!)); _varHelper.AddVariable(select); // Compile with-param's, they must be calculated outside the loop and // if they are neither constant nor reference we need to cache them in Let's for (int i = 0; i < content.Count; i++) { - VarPar withParam = content[i] as VarPar; + VarPar? withParam = content[i] as VarPar; if (withParam != null) { Debug.Assert(withParam.NodeType == XslNodeType.WithParam); CompileWithParam(withParam); - QilNode val = withParam.Value; + QilNode? val = withParam.Value; if (IsDebug || !(val is QilIterator || val is QilLiteral)) { - QilIterator let = _f.Let(val); - let.DebugName = _f.QName("with-param " + withParam.Name.QualifiedName, XmlReservedNs.NsXslDebug).ToString(); + QilIterator let = _f.Let(val!); + let.DebugName = _f.QName("with-param " + withParam.Name!.QualifiedName, XmlReservedNs.NsXslDebug).ToString(); _varHelper.AddVariable(let); withParam.Value = let; } @@ -1198,7 +1201,7 @@ private QilNode CompileApplyTemplates(XslNodeEx node) // Compile sort keys and body _curLoop.Sort(CompileSorts(content, ref curLoopSaved)); - result = GenerateApply(_compiler.Root, node); + result = GenerateApply(_compiler.Root!, node); result = WrapLoopBody(node.ElemNameLi, result, node.EndTagLi); result = AddCurrentPositionLast(result); @@ -1216,12 +1219,12 @@ private QilNode CompileApplyImports(XslNode node) Debug.Assert(node.NodeType == XslNodeType.ApplyImports); Debug.Assert(!_curLoop.IsFocusSet, "xsl:apply-imports cannot be inside of xsl:for-each"); - return GenerateApply((StylesheetLevel)node.Arg, node); + return GenerateApply((StylesheetLevel)node.Arg!, node); } private QilNode CompileCallTemplate(XslNodeEx node) { - VerifyXPathQName(node.Name); + VerifyXPathQName(node.Name!); int varScope = _varHelper.StartVariables(); IList content = node.Content; @@ -1231,9 +1234,9 @@ private QilNode CompileCallTemplate(XslNodeEx node) // In debug mode precalculate all with-param's if (IsDebug) { - QilNode val = withParam.Value; + QilNode val = withParam.Value!; QilIterator let = _f.Let(val); - let.DebugName = _f.QName("with-param " + withParam.Name.QualifiedName, XmlReservedNs.NsXslDebug).ToString(); + let.DebugName = _f.QName("with-param " + withParam.Name!.QualifiedName, XmlReservedNs.NsXslDebug).ToString(); _varHelper.AddVariable(let); withParam.Value = let; } @@ -1241,17 +1244,17 @@ private QilNode CompileCallTemplate(XslNodeEx node) QilNode result; { - Template tmpl; - if (_compiler.NamedTemplates.TryGetValue(node.Name, out tmpl)) + Template? tmpl; + if (_compiler.NamedTemplates.TryGetValue(node.Name!, out tmpl)) { Debug.Assert(tmpl.Function != null, "All templates should be already compiled"); - result = _invkGen.GenerateInvoke(tmpl.Function, AddRemoveImplicitArgs(node.Content, tmpl.Flags)); + result = _invkGen.GenerateInvoke(tmpl.Function, AddRemoveImplicitArgs(node.Content, tmpl.Flags)!); } else { - if (!_compiler.IsPhantomName(node.Name)) + if (!_compiler.IsPhantomName(node.Name!)) { - _compiler.ReportError(/*[XT0710]*/node.SourceLine, SR.Xslt_InvalidCallTemplate, node.Name.QualifiedName); + _compiler.ReportError(/*[XT0710]*/node.SourceLine!, SR.Xslt_InvalidCallTemplate, node.Name!.QualifiedName); } result = _f.Sequence(); } @@ -1272,21 +1275,21 @@ private QilNode CompileCallTemplate(XslNodeEx node) private QilNode CompileUseAttributeSet(XslNode node) { - VerifyXPathQName(node.Name); + VerifyXPathQName(node.Name!); // REVIEW: Future optimization: invalidate only if there were AVTs _outputScope.InvalidateAllPrefixes(); - AttributeSet attSet; - if (_compiler.AttributeSets.TryGetValue(node.Name, out attSet)) + AttributeSet? attSet; + if (_compiler.AttributeSets.TryGetValue(node.Name!, out attSet)) { Debug.Assert(attSet.Function != null, "All templates should be already compiled"); - return _invkGen.GenerateInvoke(attSet.Function, AddRemoveImplicitArgs(node.Content, attSet.Flags)); + return _invkGen.GenerateInvoke(attSet.Function, AddRemoveImplicitArgs(node.Content, attSet.Flags)!); } else { - if (!_compiler.IsPhantomName(node.Name)) + if (!_compiler.IsPhantomName(node.Name!)) { - _compiler.ReportError(/*[XT0710]*/node.SourceLine, SR.Xslt_NoAttributeSet, node.Name.QualifiedName); + _compiler.ReportError(/*[XT0710]*/node.SourceLine!, SR.Xslt_NoAttributeSet, node.Name!.QualifiedName); } return _f.Sequence(); } @@ -1298,7 +1301,7 @@ private QilNode CompileCopy(XslNode copy) { QilNode node = GetCurrentNode(); _f.CheckNodeNotRtf(node); - if ((node.XmlType.NodeKinds & InvalidatingNodes) != XmlNodeKindFlags.None) + if ((node.XmlType!.NodeKinds & InvalidatingNodes) != XmlNodeKindFlags.None) { _outputScope.InvalidateAllPrefixes(); } @@ -1336,7 +1339,7 @@ private QilNode CompileCopy(XslNode copy) private QilNode CompileCopyOf(XslNode node) { QilNode selectExpr = CompileXPathExpression(node.Select); - if (selectExpr.XmlType.IsNode) + if (selectExpr.XmlType!.IsNode) { if ((selectExpr.XmlType.NodeKinds & InvalidatingNodes) != XmlNodeKindFlags.None) { @@ -1409,14 +1412,14 @@ private QilNode CompileIf(XslNode ifNode) private QilNode CompileChoose(XslNode node) { IList cases = node.Content; - QilNode result = null; + QilNode? result = null; // It's easier to compile xsl:choose from bottom to top for (int i = cases.Count - 1; 0 <= i; i--) { XslNode when = cases[i]; Debug.Assert(when.NodeType == XslNodeType.If || when.NodeType == XslNodeType.Otherwise); - QilList nsList = EnterScope(when); + QilList? nsList = EnterScope(when); if (when.NodeType == XslNodeType.Otherwise) { Debug.Assert(result == null, "xsl:otherwise must be the last child of xsl:choose"); @@ -1439,14 +1442,14 @@ private QilNode CompileChoose(XslNode node) private QilNode CompileMessage(XslNode node) { - string baseUri = _lastScope.SourceLine.Uri; + string? baseUri = _lastScope!.SourceLine!.Uri; QilNode content = _f.RtfCtor(CompileInstructions(node.Content), _f.String(baseUri)); //content = f.ConvertToString(content); content = _f.InvokeOuterXml(content); // If terminate="no", then create QilNodeType.Warning - if (!(bool)node.Arg) + if (!(bool)node.Arg!) { return _f.Warning(content); } @@ -1459,7 +1462,7 @@ private QilNode CompileMessage(XslNode node) private QilNode CompileVariable(XslNode node) { Debug.Assert(node.NodeType == XslNodeType.Variable); - if (_scope.IsLocalVariable(node.Name.LocalName, node.Name.NamespaceUri)) + if (_scope.IsLocalVariable(node.Name!.LocalName, node.Name.NamespaceUri)) { ReportError(/*[XT_030]*/SR.Xslt_DupLocalVariable, node.Name.QualifiedName); } @@ -1469,11 +1472,11 @@ private QilNode CompileVariable(XslNode node) private QilNode CompileVarParValue(XslNode node) { Debug.Assert(node.NodeType == XslNodeType.Variable || node.NodeType == XslNodeType.Param || node.NodeType == XslNodeType.WithParam); - VerifyXPathQName(node.Name); + VerifyXPathQName(node.Name!); - string baseUri = _lastScope.SourceLine.Uri; + string? baseUri = _lastScope!.SourceLine!.Uri; IList content = node.Content; - string select = node.Select; + string? select = node.Select; QilNode varValue; if (select != null) @@ -1507,7 +1510,7 @@ private QilNode CompileVarParValue(XslNode node) private void CompileWithParam(VarPar withParam) { Debug.Assert(withParam.NodeType == XslNodeType.WithParam); - QilList nsList = EnterScope(withParam); + QilList? nsList = EnterScope(withParam); QilNode paramValue = CompileVarParValue(withParam); ExitScope(); SetLineInfo(paramValue, withParam.SourceLine); @@ -1517,7 +1520,7 @@ private void CompileWithParam(VarPar withParam) // REVIEW: Can we handle both sort's and with-param's in the document order? // CompileSorts() creates helper variables in varHelper - private QilNode CompileSorts(IList content, ref LoopFocus parentLoop) + private QilNode? CompileSorts(IList content, ref LoopFocus parentLoop) { QilList keyList = _f.BaseFactory.SortKeyList(); @@ -1525,7 +1528,7 @@ private QilNode CompileSorts(IList content, ref LoopFocus parentLoop) while (i < content.Count) { - Sort sort = content[i] as Sort; + Sort? sort = content[i] as Sort; if (sort != null) { CompileSort(sort, keyList, ref parentLoop); @@ -1543,9 +1546,9 @@ private QilNode CompileSorts(IList content, ref LoopFocus parentLoop) return keyList; } - private QilNode CompileLangAttribute(string attValue, bool fwdCompat) + private QilNode? CompileLangAttribute(string? attValue, bool fwdCompat) { - QilNode result = CompileStringAvt(attValue); + QilNode? result = CompileStringAvt(attValue); if (result == null) { @@ -1574,12 +1577,12 @@ private QilNode CompileLangAttribute(string attValue, bool fwdCompat) return result; } - private QilNode CompileLangAttributeToLcid(string attValue, bool fwdCompat) + private QilNode CompileLangAttributeToLcid(string? attValue, bool fwdCompat) { return CompileLangToLcid(CompileStringAvt(attValue), fwdCompat); } - private QilNode CompileLangToLcid(QilNode lang, bool fwdCompat) + private QilNode CompileLangToLcid(QilNode? lang, bool fwdCompat) { if (lang == null) { @@ -1595,11 +1598,11 @@ private QilNode CompileLangToLcid(QilNode lang, bool fwdCompat) } } - private void CompileDataTypeAttribute(string attValue, bool fwdCompat, ref QilNode select, out QilNode select2) + private void CompileDataTypeAttribute(string? attValue, bool fwdCompat, ref QilNode select, out QilNode? select2) { const string DtText = "text"; const string DtNumber = "number"; - QilNode result = CompileStringAvt(attValue); + QilNode? result = CompileStringAvt(attValue); if (result != null) { if (result.NodeType == QilNodeType.LiteralString) @@ -1644,7 +1647,7 @@ private void CompileDataTypeAttribute(string attValue, bool fwdCompat, ref QilNo _f.Conditional(_f.Eq(dt, _f.String(DtText)), _f.True(), fwdCompat ? _f.True() : _f.Loop(qname = _f.Let(ResolveQNameDynamic(/*ignoreDefaultNs:*/true, dt)), - _f.Error(_lastScope.SourceLine, + _f.Error(_lastScope!.SourceLine, SR.Xslt_BistateAttribute, "data-type", DtText, DtNumber ) ) @@ -1679,9 +1682,10 @@ private void CompileDataTypeAttribute(string attValue, bool fwdCompat, ref QilNo /// returning "1" if AVT evaluates to value1, or "0" if AVT evaluates to value0 or any other value. /// If AVT evaluates to neither value0 nor value1 and fwdCompat == false, an error is reported. /// - private QilNode CompileOrderAttribute(string attName, string attValue, string value0, string value1, bool fwdCompat) + [return: NotNullIfNotNull("attName")] + private QilNode CompileOrderAttribute(string attName, string? attValue, string value0, string value1, bool fwdCompat) { - QilNode result = CompileStringAvt(attValue); + QilNode? result = CompileStringAvt(attValue); if (result != null) { if (result.NodeType == QilNodeType.LiteralString) @@ -1707,20 +1711,22 @@ private QilNode CompileOrderAttribute(string attName, string attValue, string va _f.Conditional(_f.Eq(i, _f.String(value1)), _f.String("1"), fwdCompat ? _f.String("0") : _f.Conditional(_f.Eq(i, _f.String(value0)), _f.String("0"), - _f.Error(_lastScope.SourceLine, + _f.Error(_lastScope!.SourceLine, SR.Xslt_BistateAttribute, attName, value0, value1 ) ))); } Debug.Assert(result.XmlType == T.StringX); } - return result; + + return result!; } private void CompileSort(Sort sort, QilList keyList, ref LoopFocus parentLoop) { Debug.Assert(sort.NodeType == XslNodeType.Sort); - QilNode select, select2, lang, order, caseOrder; + QilNode select; + QilNode? select2, lang, order, caseOrder; bool fwdCompat; EnterScope(sort); @@ -1832,7 +1838,7 @@ private QilNode MatchPattern(QilNode pattern, QilIterator testNode) return result; } - private QilNode MatchCountPattern(QilNode countPattern, QilIterator testNode) + private QilNode MatchCountPattern(QilNode? countPattern, QilIterator testNode) { /* If the 'count' attribute is not specified, then it defaults to the pattern that matches any node @@ -1847,7 +1853,7 @@ the same expanded-QName as the context node. { QilNode current = GetCurrentNode(); QilNode result; - XmlNodeKindFlags nodeKinds = current.XmlType.NodeKinds; + XmlNodeKindFlags nodeKinds = current.XmlType!.NodeKinds; // If node kind is not known, invoke a runtime function if ((nodeKinds & (nodeKinds - 1)) != 0) @@ -1878,7 +1884,7 @@ the same expanded-QName as the context node. } } - private QilNode PlaceMarker(QilNode countPattern, QilNode fromPattern, bool multiple) + private QilNode PlaceMarker(QilNode? countPattern, QilNode? fromPattern, bool multiple) { /* Quotation from XSLT 2.0 spec: @@ -1900,7 +1906,8 @@ private QilNode PlaceMarker(QilNode countPattern, QilNode fromPattern, bool mult '$A[. >> $F]' if the 'from' attribute is present. */ - QilNode countPattern2, countMatches, fromMatches, A, F, AF; + QilNode? countPattern2; + QilNode countMatches, fromMatches, A, F, AF; QilIterator i, j; countPattern2 = (countPattern != null) ? countPattern.DeepClone(_f.BaseFactory) : null; @@ -1930,7 +1937,7 @@ private QilNode PlaceMarker(QilNode countPattern, QilNode fromPattern, bool mult ); } - private QilNode PlaceMarkerAny(QilNode countPattern, QilNode fromPattern) + private QilNode PlaceMarkerAny(QilNode? countPattern, QilNode? fromPattern) { /* Quotation from XSLT 2.0 spec: @@ -1979,14 +1986,14 @@ private QilNode PlaceMarkerAny(QilNode countPattern, QilNode fromPattern) } // Returns one of XsltLibrary.LetterValue enum values - private QilNode CompileLetterValueAttribute(string attValue, bool fwdCompat) + private QilNode CompileLetterValueAttribute(string? attValue, bool fwdCompat) { const string Default = "default"; const string Alphabetic = "alphabetic"; const string Traditional = "traditional"; string letterValue; - QilNode result = CompileStringAvt(attValue); + QilNode? result = CompileStringAvt(attValue); if (result != null) { @@ -2015,16 +2022,16 @@ private QilNode CompileLetterValueAttribute(string attValue, bool fwdCompat) _f.Or(_f.Eq(i, _f.String(Alphabetic)), _f.Eq(i, _f.String(Traditional))), i, fwdCompat ? _f.String(Default) : - _f.Error(_lastScope.SourceLine, SR.Xslt_BistateAttribute, "letter-value", Alphabetic, Traditional) + _f.Error(_lastScope!.SourceLine, SR.Xslt_BistateAttribute, "letter-value", Alphabetic, Traditional) )); } } return _f.String(Default); } - private QilNode CompileGroupingSeparatorAttribute(string attValue, bool fwdCompat) + private QilNode CompileGroupingSeparatorAttribute(string? attValue, bool fwdCompat) { - QilNode result = CompileStringAvt(attValue); + QilNode? result = CompileStringAvt(attValue); if (result == null) { @@ -2050,15 +2057,15 @@ private QilNode CompileGroupingSeparatorAttribute(string attValue, bool fwdCompa result = _f.Loop(i, _f.Conditional(_f.Eq(_f.StrLength(i), _f.Int32(1)), i, fwdCompat ? _f.String(string.Empty) : - _f.Error(_lastScope.SourceLine, SR.Xslt_CharAttribute, "grouping-separator") + _f.Error(_lastScope!.SourceLine, SR.Xslt_CharAttribute, "grouping-separator") )); } return result; } - private QilNode CompileGroupingSizeAttribute(string attValue, bool fwdCompat) + private QilNode CompileGroupingSizeAttribute(string? attValue, bool fwdCompat) { - QilNode result = CompileStringAvt(attValue); + QilNode? result = CompileStringAvt(attValue); if (result == null) { @@ -2103,8 +2110,8 @@ private QilNode CompileNumber(Number num) } else { - QilNode countPattern = (num.Count != null) ? CompileNumberPattern(num.Count) : null; - QilNode fromPattern = (num.From != null) ? CompileNumberPattern(num.From) : null; + QilNode? countPattern = (num.Count != null) ? CompileNumberPattern(num.Count) : null; + QilNode? fromPattern = (num.From != null) ? CompileNumberPattern(num.From) : null; switch (num.Level) { @@ -2226,7 +2233,7 @@ private void CreateGlobalVarPar(VarPar varPar) { it = _f.Parameter(null, varPar.Name, xt); } - it.DebugName = varPar.Name.ToString(); + it.DebugName = varPar.Name!.ToString(); varPar.Value = it; SetLineInfo(it, varPar.SourceLine); _scope.AddVariable(varPar.Name, it); @@ -2252,9 +2259,9 @@ private void CompileGlobalVariables() private QilIterator CompileGlobalVarPar(VarPar varPar) { Debug.Assert(varPar.NodeType == XslNodeType.Variable || varPar.NodeType == XslNodeType.Param); - QilIterator it = (QilIterator)varPar.Value; + QilIterator it = (QilIterator)varPar.Value!; - QilList nsList = EnterScope(varPar); + QilList? nsList = EnterScope(varPar); QilNode content = CompileVarParValue(varPar); SetLineInfo(content, it.SourceLine); content = AddCurrentPositionLast(content); @@ -2269,9 +2276,9 @@ private QilIterator CompileGlobalVarPar(VarPar varPar) private void ReportErrorInXPath(XslLoadException e) { - XPathCompileException ex = e as XPathCompileException; + XPathCompileException? ex = e as XPathCompileException; string errorText = (ex != null) ? ex.FormatDetailedMessage() : e.Message; - _compiler.ReportError(_lastScope.SourceLine, SR.Xml_UserException, errorText); + _compiler.ReportError(_lastScope!.SourceLine!, SR.Xml_UserException, errorText); } private QilNode PhantomXPathExpression() @@ -2286,7 +2293,7 @@ private QilNode PhantomKeyMatch() // Calls to CompileXPathExpression() can't be nested in the XSLT. So we can reuse the same instance of xpathBuilder. // The only thing we need to do before its use is adjustment of IXPathEnvironment to have correct context tuple. - private QilNode CompileXPathExpression(string expr) + private QilNode CompileXPathExpression(string? expr) { XPathScanner scanner; QilNode result; @@ -2322,7 +2329,7 @@ private QilNode CompileXPathExpression(string expr) private QilNode CompileNodeSetExpression(string expr) { - QilNode result = _f.TryEnsureNodeSet(CompileXPathExpression(expr)); + QilNode? result = _f.TryEnsureNodeSet(CompileXPathExpression(expr)); if (result == null) { // The expression is never a node-set @@ -2415,7 +2422,7 @@ private QilNode CompileNumberPattern(string pttrn) return result; } - private QilNode CompileKeyMatch(string pttrn) + private QilNode CompileKeyMatch(string? pttrn) { XPathScanner scanner; QilNode result; @@ -2450,7 +2457,7 @@ private QilNode CompileKeyMatch(string pttrn) private QilNode CompileKeyUse(Key key) { - string expr = key.Use; + string? expr = key.Use; XPathScanner scanner; QilNode result; @@ -2492,8 +2499,8 @@ private QilNode ResolveQNameDynamic(bool ignoreDefaultNs, QilNode qilName) } foreach (ScopeRecord rec in _scope) { - string recPrefix = rec.ncName; - string recNsUri = rec.nsUri; + string recPrefix = rec.ncName!; + string? recNsUri = rec.nsUri; if (ignoreDefaultNs && recPrefix.Length == 0) { @@ -2501,7 +2508,7 @@ private QilNode ResolveQNameDynamic(bool ignoreDefaultNs, QilNode qilName) } else { - nsDecls.Add(_f.NamespaceDecl(_f.String(recPrefix), _f.String(recNsUri))); + nsDecls.Add(_f.NamespaceDecl(_f.String(recPrefix), _f.String(recNsUri!))); } } return _f.StrParseQName(qilName, nsDecls); @@ -2520,7 +2527,7 @@ private QilNode GenerateApply(StylesheetLevel sheet, XslNode node) { return _f.Sequence(); } - return InvokeApplyFunction(sheet, /*mode:*/node.Name, node.Content); + return InvokeApplyFunction(sheet, /*mode:*/node.Name!, node.Content); } private void SetArg(IList args, int pos, QilName name, QilNode value) @@ -2537,7 +2544,7 @@ private void SetArg(IList args, int pos, QilName name, QilNode value) } varPar.Value = value; } - private IList AddRemoveImplicitArgs(IList args, XslFlags flags) + private IList? AddRemoveImplicitArgs(IList? args, XslFlags flags) { //We currently don't reuse the same argument list. So remove is not needed and will not work in this code if (IsDebug) @@ -2571,9 +2578,9 @@ private bool FillupInvokeArgs(IList formalArgs, IList actualAr invokeArgs.Clear(); for (int invArg = 0; invArg < formalArgs.Count; invArg++) { - QilName formalArgName = ((QilParameter)formalArgs[invArg]).Name; - XmlQueryType paramType = formalArgs[invArg].XmlType; - QilNode arg = null; + QilName formalArgName = ((QilParameter)formalArgs[invArg]).Name!; + XmlQueryType paramType = formalArgs[invArg].XmlType!; + QilNode? arg = null; { for (int actArg = 0; actArg < actualArgs.Count; actArg++) { @@ -2581,8 +2588,8 @@ private bool FillupInvokeArgs(IList formalArgs, IList actualAr VarPar withParam = (VarPar)actualArgs[actArg]; if (formalArgName.Equals(withParam.Name)) { - QilNode value = withParam.Value; - XmlQueryType valueType = value.XmlType; + QilNode value = withParam.Value!; + XmlQueryType valueType = value.XmlType!; if (valueType != paramType) { if (valueType.IsNode && paramType.IsNode && valueType.IsSubtypeOf(paramType)) @@ -2611,7 +2618,7 @@ private bool FillupInvokeArgs(IList formalArgs, IList actualAr return true; } - private QilNode InvokeApplyFunction(StylesheetLevel sheet, QilName mode, IList actualArgs) + private QilNode InvokeApplyFunction(StylesheetLevel sheet, QilName mode, IList? actualArgs) { // Here we create function that has one argument for each with-param in apply-templates // We have actualArgs -- list of xsl:with-param(name, value) @@ -2631,10 +2638,10 @@ private QilNode InvokeApplyFunction(StylesheetLevel sheet, QilName mode, IList functionsForMode; + List? functionsForMode; if (!sheet.ApplyFunctions.TryGetValue(mode, out functionsForMode)) { functionsForMode = sheet.ApplyFunctions[mode] = new List(); @@ -2642,7 +2649,7 @@ private QilNode InvokeApplyFunction(StylesheetLevel sheet, QilName mode, IList 1 ? args[1] : null); case FuncId.FormatNumber: return CompileFormatNumber(args[0], args[1], args.Count > 2 ? args[2] : null); case FuncId.UnparsedEntityUri: return CompileUnparsedEntityUri(args[0]); - case FuncId.GenerateId: return CompileGenerateId(args.Count > 0 ? args[0] : env.GetCurrent()); + case FuncId.GenerateId: return CompileGenerateId(args.Count > 0 ? args[0] : env.GetCurrent()!); case FuncId.SystemProperty: return CompileSystemProperty(args[0]); case FuncId.ElementAvailable: return CompileElementAvailable(args[0]); case FuncId.FunctionAvailable: return CompileFunctionAvailable(args[0]); @@ -181,7 +182,7 @@ QilNode IXPathEnvironment.ResolveFunction(string prefix, string name, IList defList, QilNode key, IFocus env) Debug.Assert(defList != null && defList.Count > 0); if (defList.Count == 1) { - return _f.Invoke(defList[0].Function, _f.ActualParameterList(env.GetCurrent(), key)); + return _f.Invoke(defList[0].Function!, _f.ActualParameterList(env.GetCurrent()!, key)); } QilIterator i = _f.Let(key); QilNode result = _f.Sequence(); foreach (Key keyDef in defList) { - result.Add(_f.Invoke(keyDef.Function, _f.ActualParameterList(env.GetCurrent(), i))); + result.Add(_f.Invoke(keyDef.Function!, _f.ActualParameterList(env.GetCurrent()!, i))); } return _f.Loop(i, result); } @@ -455,14 +456,14 @@ private QilNode CompileSingleKey(List defList, QilIterator key, QilIterator { Debug.Assert(defList != null && defList.Count > 0); QilList result = _f.BaseFactory.Sequence(); - QilNode keyRef = null; + QilNode? keyRef = null; foreach (Key keyDef in defList) { - keyRef = _f.Invoke(keyDef.Function, _f.ActualParameterList(context, key)); + keyRef = _f.Invoke(keyDef.Function!, _f.ActualParameterList(context, key)); result.Add(keyRef); } - return defList.Count == 1 ? keyRef : result; + return defList.Count == 1 ? keyRef! : result; } private QilFunction CreateGeneralKeyFunction() @@ -475,7 +476,7 @@ private QilFunction CreateGeneralKeyFunction() QilNode fdef = _f.Error(SR.Xslt_UndefinedKey, name); for (int idx = 0; idx < _compiler.Keys.Count; idx++) { - fdef = _f.Conditional(_f.Eq(resolvedName, _compiler.Keys[idx][0].Name.DeepClone(_f.BaseFactory)), + fdef = _f.Conditional(_f.Eq(resolvedName, _compiler.Keys[idx][0].Name!.DeepClone(_f.BaseFactory)), CompileSingleKey(_compiler.Keys[idx], key, context), fdef ); @@ -487,17 +488,18 @@ private QilFunction CreateGeneralKeyFunction() return result; } - private QilNode CompileFnDocument(QilNode uris, QilNode baseNode) + private QilNode CompileFnDocument(QilNode uris, QilNode? baseNode) { QilNode result; - QilIterator i, j, u; + QilIterator i, u; + QilIterator? j; if (!_compiler.Settings.EnableDocumentFunction) { ReportWarning(SR.Xslt_DocumentFuncProhibited); - return _f.Error(_lastScope.SourceLine, SR.Xslt_DocumentFuncProhibited); + return _f.Error(_lastScope!.SourceLine, SR.Xslt_DocumentFuncProhibited); } - if (uris.XmlType.IsNode) + if (uris.XmlType!.IsNode) { result = _f.DocOrderDistinct(_f.Loop(i = _f.For(uris), CompileSingleDocument(_f.ConvertToString(i), baseNode ?? i) @@ -517,25 +519,25 @@ private QilNode CompileFnDocument(QilNode uris, QilNode baseNode) )), CompileSingleDocument(_f.XsltConvert(u, T.StringX), j) ); - result = (baseNode != null) ? _f.Loop(j, result) : result; + result = (baseNode != null) ? _f.Loop(j!, result) : result; result = _f.Loop(u, result); } return result; } - private QilNode CompileSingleDocument(QilNode uri, QilNode baseNode) + private QilNode CompileSingleDocument(QilNode uri, QilNode? baseNode) { _f.CheckString(uri); QilNode baseUri; if (baseNode == null) { - baseUri = _f.String(_lastScope.SourceLine.Uri); + baseUri = _f.String(_lastScope!.SourceLine!.Uri); } else { _f.CheckNodeSet(baseNode); - if (baseNode.XmlType.IsSingleton) + if (baseNode.XmlType!.IsSingleton) { baseUri = _f.InvokeBaseUri(baseNode); } @@ -553,11 +555,11 @@ private QilNode CompileSingleDocument(QilNode uri, QilNode baseNode) return _f.DataSource(uri, baseUri); } - private QilNode CompileFormatNumber(QilNode value, QilNode formatPicture, QilNode formatName) + private QilNode CompileFormatNumber(QilNode value, QilNode formatPicture, QilNode? formatName) { _f.CheckDouble(value); _f.CheckString(formatPicture); - XmlQualifiedName resolvedName; + XmlQualifiedName? resolvedName; if (formatName == null) { @@ -622,13 +624,13 @@ private QilNode CompileFormatNumber(QilNode value, QilNode formatPicture, QilNod private QilNode CompileUnparsedEntityUri(QilNode n) { _f.CheckString(n); - return _f.Error(_lastScope.SourceLine, SR.Xslt_UnsupportedXsltFunction, "unparsed-entity-uri"); + return _f.Error(_lastScope!.SourceLine, SR.Xslt_UnsupportedXsltFunction, "unparsed-entity-uri"); } private QilNode CompileGenerateId(QilNode n) { _f.CheckNodeSet(n); - if (n.XmlType.IsSingleton) + if (n.XmlType!.IsSingleton) { return _f.XsltGenerateId(n); } @@ -721,7 +723,7 @@ private QilNode CompileFunctionAvailable(QilNode name) private QilNode CompileMsNodeSet(QilNode n) { - if (n.XmlType.IsNode && n.XmlType.IsNotRtf) + if (n.XmlType!.IsNode && n.XmlType.IsNotRtf) { return n; } @@ -737,7 +739,7 @@ private QilNode EXslObjectType(QilNode n) { if (EvaluateFuncCalls) { - switch (n.XmlType.TypeCode) + switch (n.XmlType!.TypeCode) { case XmlTypeCode.Boolean: return _f.String("boolean"); case XmlTypeCode.Double: return _f.String("number"); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilStrConcatenator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilStrConcatenator.cs index 80ef988abf93e..80ded330780a3 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilStrConcatenator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilStrConcatenator.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Diagnostics; using System.Xml; using System.Text; @@ -14,7 +15,7 @@ internal class QilStrConcatenator { private readonly XPathQilFactory _f; private readonly StringBuilder _builder; - private QilList _concat; + private QilList? _concat; private bool _inUse; public QilStrConcatenator(XPathQilFactory f) @@ -56,12 +57,12 @@ public void Append(char value) _builder.Append(value); } - public void Append(QilNode value) + public void Append(QilNode? value) { Debug.Assert(_inUse, "Reset() wasn't called"); if (value != null) { - Debug.Assert(value.XmlType.TypeCode == XmlTypeCode.String); + Debug.Assert(value.XmlType!.TypeCode == XmlTypeCode.String); if (value.NodeType == QilNodeType.LiteralString) { _builder.Append((string)(QilLiteral)value); @@ -69,7 +70,7 @@ public void Append(QilNode value) else { FlushBuilder(); - _concat.Add(value); + _concat!.Add(value); } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Scripts.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Scripts.cs index e117eb07a379a..479af7a79a119 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Scripts.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Scripts.cs @@ -4,6 +4,7 @@ // http://devdiv/Documents/Whidbey/CLR/CurrentSpecs/BCL/CodeDom%20Activation.doc //------------------------------------------------------------------------------ +#nullable enable using System.Collections.Generic; using System.Collections.Specialized; using System.Configuration; @@ -25,7 +26,7 @@ namespace System.Xml.Xsl.Xslt internal class Scripts { private readonly Compiler _compiler; - private readonly Dictionary _nsToType = new Dictionary(); + private readonly Dictionary _nsToType = new Dictionary(); private readonly XmlExtensionFunctionTable _extFuncs = new XmlExtensionFunctionTable(); public Scripts(Compiler compiler) @@ -33,14 +34,14 @@ public Scripts(Compiler compiler) _compiler = compiler; } - public Dictionary ScriptClasses + public Dictionary ScriptClasses { get { return _nsToType; } } - public XmlExtensionFunction ResolveFunction(string name, string ns, int numArgs, IErrorHelper errorHelper) + public XmlExtensionFunction? ResolveFunction(string name, string ns, int numArgs, IErrorHelper errorHelper) { - Type type; + Type? type; if (_nsToType.TryGetValue(ns, out type)) { try diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Stylesheet.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Stylesheet.cs index cdaa1d5226d15..26ecb7c6e148f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Stylesheet.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Stylesheet.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Xml.Xsl.Qil; namespace System.Xml.Xsl.Xslt diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XPathPatternBuilder.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XPathPatternBuilder.cs index ef4f222eace8f..52e5f32430f18 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XPathPatternBuilder.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XPathPatternBuilder.cs @@ -52,9 +52,9 @@ public virtual void StartBuild() public void AssertFilter(QilLoop filter) { Debug.Assert(filter.NodeType == QilNodeType.Filter, "XPathPatternBuilder expected to generate list of Filters on top level"); - Debug.Assert(filter.Variable.XmlType.IsSubtypeOf(T.NodeNotRtf)); - Debug.Assert(filter.Variable.Binding.NodeType == QilNodeType.Unknown); // fixupNode - Debug.Assert(filter.Body.XmlType.IsSubtypeOf(T.Boolean)); + Debug.Assert(filter.Variable.XmlType!.IsSubtypeOf(T.NodeNotRtf)); + Debug.Assert(filter.Variable.Binding!.NodeType == QilNodeType.Unknown); // fixupNode + Debug.Assert(filter.Body.XmlType!.IsSubtypeOf(T.Boolean)); } private void FixupFilterBinding(QilLoop filter, QilNode newBinding) @@ -109,7 +109,7 @@ private static QilLoop BuildAxisFilter(QilPatternFactory f, QilIterator itr, XPa /*name == nsUri == null*/ f.True() // * ); - XmlNodeKindFlags intersection = XPathBuilder.AxisTypeMask(itr.XmlType.NodeKinds, nodeType, xpathAxis); + XmlNodeKindFlags intersection = XPathBuilder.AxisTypeMask(itr.XmlType!.NodeKinds, nodeType, xpathAxis); QilNode typeTest = ( intersection == 0 ? f.False() : // input & required doesn't intersect @@ -118,7 +118,7 @@ private static QilLoop BuildAxisFilter(QilPatternFactory f, QilIterator itr, XPa ); QilLoop filter = f.BaseFactory.Filter(itr, f.And(typeTest, nameTest)); - filter.XmlType = T.PrimeProduct(T.NodeChoice(intersection), filter.XmlType.Cardinality); + filter.XmlType = T.PrimeProduct(T.NodeChoice(intersection), filter.XmlType!.Cardinality); return filter; } @@ -285,7 +285,7 @@ public QilNode BuildPredicates(QilNode nodeset, List predicates) QilNode filterCurrent = _f.Filter(matchNodeIter, _f.Is(matchNodeIter, current)); nodeFilter.Body = _f.Not(_f.IsEmpty(filterCurrent)); //for passing type check, explicit say the result is target type - nodeFilter.Body = _f.And(_f.IsType(current, nodeFilter.XmlType), nodeFilter.Body); + nodeFilter.Body = _f.And(_f.IsType(current, nodeFilter.XmlType!), nodeFilter.Body); } SetPriority(nodeset, 0.5); @@ -346,27 +346,27 @@ private class Annotation public static void SetPriority(QilNode node, double priority) { - Annotation ann = (Annotation)node.Annotation ?? new Annotation(); + Annotation ann = (Annotation?)node.Annotation ?? new Annotation(); ann.Priority = priority; node.Annotation = ann; } public static double GetPriority(QilNode node) { - return ((Annotation)node.Annotation).Priority; + return ((Annotation)node.Annotation!).Priority; } private static void SetLastParent(QilNode node, QilLoop parent) { Debug.Assert(parent.NodeType == QilNodeType.Filter); - Annotation ann = (Annotation)node.Annotation ?? new Annotation(); + Annotation ann = (Annotation?)node.Annotation ?? new Annotation(); ann.Parent = parent; node.Annotation = ann; } private static QilLoop? GetLastParent(QilNode node) { - return ((Annotation)node.Annotation).Parent; + return ((Annotation)node.Annotation!).Parent; } public static void CleanAnnotation(QilNode node) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XslAst.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XslAst.cs index 0dd73e5762c41..1e99401dab2f2 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XslAst.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XslAst.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable using System.Text; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -60,11 +61,11 @@ internal enum XslNodeType internal class NsDecl { - public readonly NsDecl Prev; - public readonly string Prefix; // Empty string denotes the default namespace, null - extension or excluded namespace - public readonly string NsUri; // null means "#all" -- all namespace defined above this one are excluded. + public readonly NsDecl? Prev; + public readonly string? Prefix; // Empty string denotes the default namespace, null - extension or excluded namespace + public readonly string? NsUri; // null means "#all" -- all namespace defined above this one are excluded. - public NsDecl(NsDecl prev, string prefix, string nsUri) + public NsDecl(NsDecl? prev, string? prefix, string? nsUri) { Debug.Assert(nsUri != null || Prefix == null); this.Prev = prev; @@ -76,15 +77,15 @@ public NsDecl(NsDecl prev, string prefix, string nsUri) internal class XslNode { public readonly XslNodeType NodeType; - public ISourceLineInfo SourceLine; - public NsDecl Namespaces; - public readonly QilName Name; // name or mode - public readonly object Arg; // select or test or terminate or stylesheet;-) + public ISourceLineInfo? SourceLine; + public NsDecl? Namespaces; + public readonly QilName? Name; // name or mode + public readonly object? Arg; // select or test or terminate or stylesheet;-) public readonly XslVersion XslVersion; public XslFlags Flags; - private List _content; + private List? _content; - public XslNode(XslNodeType nodeType, QilName name, object arg, XslVersion xslVer) + public XslNode(XslNodeType nodeType, QilName? name, object? arg, XslVersion xslVer) { this.NodeType = nodeType; this.Name = name; @@ -98,7 +99,7 @@ public XslNode(XslNodeType nodeType) this.XslVersion = XslVersion.Current; } - public string Select { get { return (string)Arg; } } + public string? Select { get { return (string?)Arg; } } public bool ForwardsCompatible { get { return XslVersion == XslVersion.ForwardsCompatible; } } // -------------------------------- Content Management -------------------------------- @@ -110,7 +111,7 @@ public IList Content get { return _content ?? s_emptyList; } } - public void SetContent(List content) + public void SetContent(List? content) { _content = content; } @@ -137,7 +138,7 @@ public void InsertContent(IEnumerable collection) } } - internal string TraceName + internal string? TraceName { get { @@ -158,7 +159,8 @@ internal string TraceName sb.Append(' '); sb.Append(Name.QualifiedName); } - ISourceLineInfo lineInfo = SourceLine; + + ISourceLineInfo? lineInfo = SourceLine; if (lineInfo == null && NodeType == XslNodeType.AttributeSet) { lineInfo = Content[0].SourceLine; @@ -166,7 +168,7 @@ internal string TraceName } if (lineInfo != null) { - string fileName = SourceLineInfo.GetFileName(lineInfo.Uri); + string fileName = SourceLineInfo.GetFileName(lineInfo.Uri!); int idx = fileName.LastIndexOf(System.IO.Path.DirectorySeparatorChar) + 1; sb.Append(" ("); sb.Append(fileName, idx, fileName.Length - idx); @@ -184,9 +186,9 @@ internal string TraceName internal abstract class ProtoTemplate : XslNode { - public QilFunction Function; // Compiled body + public QilFunction? Function; // Compiled body - public ProtoTemplate(XslNodeType nt, QilName name, XslVersion xslVer) : base(nt, name, null, xslVer) { } + public ProtoTemplate(XslNodeType nt, QilName? name, XslVersion xslVer) : base(nt, name, null, xslVer) { } public abstract string GetDebugName(); } @@ -207,7 +209,7 @@ public override string GetDebugName() { StringBuilder dbgName = new StringBuilder(); dbgName.Append(""); return dbgName.ToString(); } @@ -226,13 +228,13 @@ public void MergeContent(AttributeSet other) internal class Template : ProtoTemplate { - public readonly string Match; + public readonly string? Match; public readonly QilName Mode; public readonly double Priority; public int ImportPrecedence; public int OrderNumber; - public Template(QilName name, string match, QilName mode, double priority, XslVersion xslVer) + public Template(QilName? name, string? match, QilName mode, double priority, XslVersion xslVer) : base(XslNodeType.Template, name, xslVer) { this.Match = match; @@ -276,19 +278,19 @@ public override string GetDebugName() internal class VarPar : XslNode { public XslFlags DefValueFlags; - public QilNode Value; // Contains value for WithParams and global VarPars + public QilNode? Value; // Contains value for WithParams and global VarPars - public VarPar(XslNodeType nt, QilName name, string select, XslVersion xslVer) : base(nt, name, select, xslVer) { } + public VarPar(XslNodeType nt, QilName name, string? select, XslVersion xslVer) : base(nt, name, select, xslVer) { } } internal class Sort : XslNode { - public readonly string Lang; - public readonly string DataType; - public readonly string Order; - public readonly string CaseOrder; + public readonly string? Lang; + public readonly string? DataType; + public readonly string? Order; + public readonly string? CaseOrder; - public Sort(string select, string lang, string dataType, string order, string caseOrder, XslVersion xslVer) + public Sort(string select, string? lang, string? dataType, string? order, string? caseOrder, XslVersion xslVer) : base(XslNodeType.Sort, null, select, xslVer) { this.Lang = lang; @@ -303,17 +305,17 @@ internal class Keys : KeyedCollection> protected override QilName GetKeyForItem(List list) { Debug.Assert(list != null && list.Count > 0); - return list[0].Name; + return list[0].Name!; } } internal class Key : XslNode { - public readonly string Match; - public readonly string Use; - public QilFunction Function; + public readonly string? Match; + public readonly string? Use; + public QilFunction? Function; - public Key(QilName name, string match, string use, XslVersion xslVer) + public Key(QilName name, string? match, string? use, XslVersion xslVer) : base(XslNodeType.Key, name, null, xslVer) { // match and use can be null in case of incorrect stylesheet @@ -326,7 +328,7 @@ public string GetDebugName() { StringBuilder dbgName = new StringBuilder(); dbgName.Append(" { - private CompilerScopeManager _scope; - private Compiler _compiler; + private CompilerScopeManager? _scope; + private Compiler? _compiler; #if DEBUG // List of all variables and parameters private readonly List _allVarPars = new List(); #endif private int _forEachDepth; - private XPathAnalyzer _xpathAnalyzer; - private ProtoTemplate _currentTemplate; + private XPathAnalyzer? _xpathAnalyzer; + private ProtoTemplate? _currentTemplate; // Type donor of the last analyzed VarPar. Used for optimization of WithParam's. - private VarPar _typeDonor; + private VarPar? _typeDonor; // Template dependencies // rev/fwd - Callee-to-Coller/Coller-to-Callee // 0/1 - for-each depth - private Graph _revCall0Graph = new Graph(); - private Graph _revCall1Graph = new Graph(); - private Dictionary _fwdApplyImportsGraph = new Dictionary(); - private Dictionary> _revApplyTemplatesGraph = new Dictionary>(); + private Graph? _revCall0Graph = new Graph(); + private Graph? _revCall1Graph = new Graph(); + private Dictionary? _fwdApplyImportsGraph = new Dictionary(); + private Dictionary>? _revApplyTemplatesGraph = new Dictionary>(); // Data flow graph - private Graph _dataFlow = new Graph(); + private Graph? _dataFlow = new Graph(); // Mapping (mode, param name) -> helper vertex in data flow graph private readonly Dictionary _applyTemplatesParams = new Dictionary(); @@ -51,14 +53,14 @@ internal class XslAstAnalyzer : XslVisitor /// Represents a graph using hashtable of adjacency lists. /// /// Vertex type - internal class Graph : Dictionary> + internal class Graph : Dictionary?> where V : XslNode { private static readonly IList s_empty = (new List()).AsReadOnly(); public IEnumerable GetAdjList(V v) { - List adjList; + List? adjList; if (TryGetValue(v, out adjList) && adjList != null) { return adjList; @@ -74,7 +76,7 @@ public void AddEdge(V v1, V v2) return; } - List adjList; + List? adjList; if (!TryGetValue(v1, out adjList) || adjList == null) { adjList = this[v1] = new List(); @@ -149,11 +151,11 @@ public XslFlags Analyze(Compiler compiler) // Add global parameters and variables to the scope, they are visible everywhere foreach (VarPar par in compiler.ExternalPars) { - _scope.AddVariable(par.Name, par); + _scope.AddVariable(par.Name!, par); } foreach (VarPar var in compiler.GlobalVars) { - _scope.AddVariable(var.Name, var); + _scope.AddVariable(var.Name!, var); } // Visit global parameters and variables, but ignore calculated flags @@ -205,13 +207,13 @@ public XslFlags Analyze(Compiler compiler) // types Rtf, Nodeset, Node, Boolean, Number, String through the data flow graph. for (int flag = (int)XslFlags.Rtf; flag != 0; flag >>= 1) { - _dataFlow.PropagateFlag((XslFlags)flag); + _dataFlow!.PropagateFlag((XslFlags)flag); } _dataFlow = null; // We need to follow revCall0Graph graph to propagate focus flags. But first complete // dependency graph with fwdApplyImportsGraph - foreach (KeyValuePair pair in _fwdApplyImportsGraph) + foreach (KeyValuePair pair in _fwdApplyImportsGraph!) { foreach (Stylesheet import in pair.Value.Imports) { @@ -222,15 +224,15 @@ public XslFlags Analyze(Compiler compiler) if ((result & XslFlags.Current) != 0) { - _revCall0Graph.PropagateFlag(XslFlags.Current); + _revCall0Graph!.PropagateFlag(XslFlags.Current); } if ((result & XslFlags.Position) != 0) { - _revCall0Graph.PropagateFlag(XslFlags.Position); + _revCall0Graph!.PropagateFlag(XslFlags.Position); } if ((result & XslFlags.Last) != 0) { - _revCall0Graph.PropagateFlag(XslFlags.Last); + _revCall0Graph!.PropagateFlag(XslFlags.Last); } if ((result & XslFlags.SideEffects) != 0) { @@ -242,7 +244,7 @@ public XslFlags Analyze(Compiler compiler) // We can do this only after all flags were propagated. // Otherwise we can miss case when flag comes to template from attribute-set - FillModeFlags(compiler.Root.ModeFlags, compiler.Root.Imports[0]); + FillModeFlags(compiler.Root!.ModeFlags, compiler.Root.Imports[0]); return result; } @@ -253,7 +255,7 @@ private void AddImportDependencies(Stylesheet sheet, Template focusDonor) { if (tmpl.Mode.Equals(focusDonor.Mode)) { - _revCall0Graph.AddEdge(tmpl, focusDonor); + _revCall0Graph!.AddEdge(tmpl, focusDonor); } } foreach (Stylesheet import in sheet.Imports) @@ -299,14 +301,14 @@ private void FillModeFlags(Dictionary parentModeFlags, Styles protected override XslFlags Visit(XslNode node) { - _scope.EnterScope(node.Namespaces); + _scope!.EnterScope(node.Namespaces); XslFlags result = base.Visit(node); _scope.ExitScope(); // Local variables and parameters must be added to the outer scope if (_currentTemplate != null && (node.NodeType == XslNodeType.Variable || node.NodeType == XslNodeType.Param)) { - _scope.AddVariable(node.Name, (VarPar)node); + _scope.AddVariable(node.Name!, (VarPar)node); } Debug.Assert( (result & XslFlags.TypeFilter & ~XslFlags.Rtf) == 0, @@ -346,7 +348,7 @@ protected override XslFlags VisitApplyImports(XslNode node) { Debug.Assert(_forEachDepth == 0, "xsl:apply-imports cannot be inside of xsl:for-each"); Debug.Assert(_currentTemplate is Template, "xsl:apply-imports can only occur within xsl:template"); - _fwdApplyImportsGraph[(Template)_currentTemplate] = (Stylesheet)node.Arg; + _fwdApplyImportsGraph![(Template)_currentTemplate] = (Stylesheet)node.Arg!; // xsl:apply-imports uses context node and is not in context of any for-each so it requires current return XslFlags.HasCalls | XslFlags.Current | XslFlags.Rtf; } @@ -361,17 +363,17 @@ protected override XslFlags VisitApplyTemplates(XslNode node) result |= Visit(instr); if (instr.NodeType == XslNodeType.WithParam) { - ModeName mn = new ModeName(/*mode:*/node.Name, instr.Name); - VarPar modePar; + ModeName mn = new ModeName(/*mode:*/node.Name!, instr.Name!); + VarPar? modePar; if (!_applyTemplatesParams.TryGetValue(mn, out modePar)) { - modePar = _applyTemplatesParams[mn] = AstFactory.WithParam(instr.Name); + modePar = _applyTemplatesParams[mn] = AstFactory.WithParam(instr.Name!); } if (_typeDonor != null) { - _dataFlow.AddEdge(_typeDonor, modePar); + _dataFlow!.AddEdge(_typeDonor, modePar); } else { @@ -382,7 +384,7 @@ protected override XslFlags VisitApplyTemplates(XslNode node) if (_currentTemplate != null) { - AddApplyTemplatesEdge(/*mode:*/node.Name, _currentTemplate); + AddApplyTemplatesEdge(/*mode:*/node.Name!, _currentTemplate); } return XslFlags.HasCalls | XslFlags.Rtf | result; @@ -401,9 +403,9 @@ protected override XslFlags VisitAttribute(NodeCtor node) protected override XslFlags VisitCallTemplate(XslNode node) { XslFlags result = XslFlags.None; - Template target; + Template? target; - if (_compiler.NamedTemplates.TryGetValue(node.Name, out target)) + if (_compiler!.NamedTemplates.TryGetValue(node.Name!, out target)) { Debug.Assert(target != null); if (_currentTemplate != null) @@ -411,17 +413,17 @@ protected override XslFlags VisitCallTemplate(XslNode node) if (_forEachDepth == 0) { // Naked xsl:call-template, target would take its focus from currentTemplate - _revCall0Graph.AddEdge(target, _currentTemplate); + _revCall0Graph!.AddEdge(target, _currentTemplate); } else { // in other cases we need it as donor for side effects flag - _revCall1Graph.AddEdge(target, _currentTemplate); + _revCall1Graph!.AddEdge(target, _currentTemplate); } } } - VarPar[] typeDonors = new VarPar[node.Content.Count]; + VarPar?[] typeDonors = new VarPar[node.Content.Count]; int idx = 0; foreach (XslNode instr in node.Content) @@ -451,12 +453,12 @@ protected override XslFlags VisitCallTemplate(XslNode node) } VarPar par = (VarPar)instr; - VarPar found = null; + VarPar? found = null; idx = 0; foreach (XslNode withPar in node.Content) { - if (withPar.Name.Equals(par.Name)) + if (withPar.Name!.Equals(par.Name)) { found = (VarPar)withPar; _typeDonor = typeDonors[idx]; @@ -471,7 +473,7 @@ protected override XslFlags VisitCallTemplate(XslNode node) if (_typeDonor != null) { // add an edge from its type donor to xsl:param - _dataFlow.AddEdge(_typeDonor, par); + _dataFlow!.AddEdge(_typeDonor, par); } else { @@ -505,7 +507,7 @@ protected override XslFlags VisitCopy(XslNode node) protected override XslFlags VisitCopyOf(XslNode node) { - return XslFlags.Rtf | ProcessExpr(node.Select); + return XslFlags.Rtf | ProcessExpr(node.Select!); } protected override XslFlags VisitElement(NodeCtor node) @@ -527,7 +529,7 @@ protected override XslFlags VisitError(XslNode node) protected override XslFlags VisitForEach(XslNode node) { - XslFlags result = ProcessExpr(node.Select); + XslFlags result = ProcessExpr(node.Select!); _forEachDepth++; foreach (XslNode child in node.Content) { @@ -547,7 +549,7 @@ protected override XslFlags VisitForEach(XslNode node) protected override XslFlags VisitIf(XslNode node) { - return ProcessExpr(node.Select) | VisitChildren(node); + return ProcessExpr(node.Select!) | VisitChildren(node); } /* @@ -564,7 +566,7 @@ protected override XslFlags VisitLiteralAttribute(XslNode node) { return ( XslFlags.Rtf | - ProcessAvt(node.Select) | + ProcessAvt(node.Select!) | VisitChildren(node) ); } @@ -602,7 +604,7 @@ protected override XslFlags VisitPI(XslNode node) { return ( XslFlags.Rtf | - ProcessAvt(node.Select) | + ProcessAvt(node.Select!) | VisitChildren(node) ); } @@ -612,7 +614,7 @@ protected override XslFlags VisitSort(Sort node) return ( // @select is calculated in context of xsl:for-each or xsl:apply-templates, // so it does not affect focus flags - ProcessExpr(node.Select) & ~XslFlags.FocusFilter | + ProcessExpr(node.Select!) & ~XslFlags.FocusFilter | ProcessAvt(node.Lang) | ProcessAvt(node.DataType) | ProcessAvt(node.Order) | @@ -627,17 +629,17 @@ protected override XslFlags VisitText(Text node) protected override XslFlags VisitUseAttributeSet(XslNode node) { - if (_compiler.AttributeSets.TryGetValue(node.Name, out AttributeSet attSet) && _currentTemplate != null) + if (_compiler!.AttributeSets.TryGetValue(node.Name!, out AttributeSet? attSet) && _currentTemplate != null) { if (_forEachDepth == 0) { // Naked [xsl:]use-attribute-sets, attSet would take its focus from currentTemplate - _revCall0Graph.AddEdge(attSet, _currentTemplate); + _revCall0Graph!.AddEdge(attSet, _currentTemplate); } else { // in other cases we need it as donor for side effects flag - _revCall1Graph.AddEdge(attSet, _currentTemplate); + _revCall1Graph!.AddEdge(attSet, _currentTemplate); } } @@ -646,31 +648,31 @@ protected override XslFlags VisitUseAttributeSet(XslNode node) protected override XslFlags VisitValueOf(XslNode node) { - return XslFlags.Rtf | ProcessExpr(node.Select); + return XslFlags.Rtf | ProcessExpr(node.Select!); } protected override XslFlags VisitValueOfDoe(XslNode node) { - return XslFlags.Rtf | ProcessExpr(node.Select); + return XslFlags.Rtf | ProcessExpr(node.Select!); } protected override XslFlags VisitParam(VarPar node) { - Template tmpl = _currentTemplate as Template; + Template? tmpl = _currentTemplate as Template; if (tmpl != null && tmpl.Match != null) { // This template has 'match' attribute and might be called from built-in template rules, // all xsl:param's will be defaulted in that case node.Flags |= XslFlags.MayBeDefault; - ModeName mn = new ModeName(tmpl.Mode, node.Name); - VarPar par; + ModeName mn = new ModeName(tmpl.Mode, node.Name!); + VarPar? par; if (!_applyTemplatesParams.TryGetValue(mn, out par)) { - par = _applyTemplatesParams[mn] = AstFactory.WithParam(node.Name); + par = _applyTemplatesParams[mn] = AstFactory.WithParam(node.Name!); } - _dataFlow.AddEdge(par, node); + _dataFlow!.AddEdge(par, node); } node.DefValueFlags = ProcessVarPar(node); return node.DefValueFlags & ~XslFlags.TypeFilter; @@ -704,16 +706,16 @@ private XslFlags ProcessVarPar(VarPar node) { // In case of incorrect stylesheet, variable or parameter may have both a 'select' attribute and non-empty content // NOTE: This code must be in sync with recovery logic in QilGenerator - result = _xpathAnalyzer.Analyze(node.Select) | VisitChildren(node) | XslFlags.AnyType; + result = _xpathAnalyzer!.Analyze(node.Select) | VisitChildren(node) | XslFlags.AnyType; _typeDonor = null; } else { - result = _xpathAnalyzer.Analyze(node.Select); + result = _xpathAnalyzer!.Analyze(node.Select); _typeDonor = _xpathAnalyzer.TypeDonor; if (_typeDonor != null && node.NodeType != XslNodeType.WithParam) { - _dataFlow.AddEdge(_typeDonor, node); + _dataFlow!.AddEdge(_typeDonor, node); } } } @@ -733,26 +735,26 @@ private XslFlags ProcessVarPar(VarPar node) // Ignores XPath type flags private XslFlags ProcessExpr(string expr) { - return _xpathAnalyzer.Analyze(expr) & ~XslFlags.TypeFilter; + return _xpathAnalyzer!.Analyze(expr) & ~XslFlags.TypeFilter; } // Ignores XPath type flags - private XslFlags ProcessAvt(string avt) + private XslFlags ProcessAvt(string? avt) { - return _xpathAnalyzer.AnalyzeAvt(avt) & ~XslFlags.TypeFilter; + return _xpathAnalyzer!.AnalyzeAvt(avt) & ~XslFlags.TypeFilter; } // Ignores XPath type flags and focus flags - private XslFlags ProcessPattern(string pattern) + private XslFlags ProcessPattern(string? pattern) { // We need to analyze using of variables in the pattern - return _xpathAnalyzer.Analyze(pattern) & ~XslFlags.TypeFilter & ~XslFlags.FocusFilter; + return _xpathAnalyzer!.Analyze(pattern) & ~XslFlags.TypeFilter & ~XslFlags.FocusFilter; } private void AddApplyTemplatesEdge(QilName mode, ProtoTemplate dependentTemplate) { - List templates; - if (!_revApplyTemplatesGraph.TryGetValue(mode, out templates)) + List? templates; + if (!_revApplyTemplatesGraph!.TryGetValue(mode, out templates)) { templates = new List(); _revApplyTemplatesGraph.Add(mode, templates); @@ -771,11 +773,11 @@ private void AddApplyTemplatesEdge(QilName mode, ProtoTemplate dependentTemplate private void PropagateSideEffectsFlag() { // Clean Stop flags - foreach (ProtoTemplate t in _revCall0Graph.Keys) + foreach (ProtoTemplate t in _revCall0Graph!.Keys) { t.Flags &= ~XslFlags.Stop; } - foreach (ProtoTemplate t in _revCall1Graph.Keys) + foreach (ProtoTemplate t in _revCall1Graph!.Keys) { t.Flags &= ~XslFlags.Stop; } @@ -806,8 +808,8 @@ private void DepthFirstSearch(ProtoTemplate t) { Debug.Assert((t.Flags & XslFlags.Stop) == 0, "Already visited this vertex"); t.Flags |= (XslFlags.SideEffects | XslFlags.Stop); - List list; - foreach (ProtoTemplate u in _revCall0Graph.GetAdjList(t)) + List? list; + foreach (ProtoTemplate u in _revCall0Graph!.GetAdjList(t)) { if ((u.Flags & XslFlags.Stop) == 0) { @@ -815,7 +817,7 @@ private void DepthFirstSearch(ProtoTemplate t) } Debug.Assert((u.Flags & XslFlags.SideEffects) == XslFlags.SideEffects, "Flag was not set on an adjacent vertex"); } - foreach (ProtoTemplate u in _revCall1Graph.GetAdjList(t)) + foreach (ProtoTemplate u in _revCall1Graph!.GetAdjList(t)) { if ((u.Flags & XslFlags.Stop) == 0) { @@ -823,10 +825,10 @@ private void DepthFirstSearch(ProtoTemplate t) } Debug.Assert((u.Flags & XslFlags.SideEffects) == XslFlags.SideEffects, "Flag was not set on an adjacent vertex"); } - Template template = t as Template; + Template? template = t as Template; if ( template != null && // This ProteTemplate is Template - _revApplyTemplatesGraph.TryGetValue(template.Mode, out list) // list - ProtoTemplates that have apply-templatess mode="{template.Mode}" + _revApplyTemplatesGraph!.TryGetValue(template.Mode, out list) // list - ProtoTemplates that have apply-templatess mode="{template.Mode}" ) { _revApplyTemplatesGraph.Remove(template.Mode); // to prevent recursion remove this list from dictionary @@ -846,8 +848,8 @@ private void DepthFirstSearch(ProtoTemplate t) // Ignores all errors and warnings internal readonly struct NullErrorHelper : IErrorHelper { - public void ReportError(string res, params string[] args) { } - public void ReportWarning(string res, params string[] args) { } + public void ReportError(string res, params string?[]? args) { } + public void ReportWarning(string res, params string?[]? args) { } } internal class XPathAnalyzer : IXPathBuilder @@ -861,9 +863,9 @@ internal class XPathAnalyzer : IXPathBuilder // If the expression is just a reference to some VarPar, like "(($foo))", // then this field contains that VarPar, and null otherwise. - private VarPar _typeDonor; + private VarPar? _typeDonor; - public VarPar TypeDonor + public VarPar? TypeDonor { get { return _typeDonor; } } @@ -874,7 +876,7 @@ public XPathAnalyzer(Compiler compiler, CompilerScopeManager scope) _scope = scope; } - public XslFlags Analyze(string xpathExpr) + public XslFlags Analyze(string? xpathExpr) { _typeDonor = null; if (xpathExpr == null) @@ -899,7 +901,7 @@ public XslFlags Analyze(string xpathExpr) } } - public XslFlags AnalyzeAvt(string source) + public XslFlags AnalyzeAvt(string? source) { _typeDonor = null; if (source == null) @@ -944,9 +946,9 @@ public XslFlags AnalyzeAvt(string source) } // Returns null in case of error - private VarPar ResolveVariable(string prefix, string name) + private VarPar? ResolveVariable(string prefix, string name) { - string ns = ResolvePrefix(prefix); + string? ns = ResolvePrefix(prefix); if (ns == null) { return null; @@ -955,7 +957,7 @@ private VarPar ResolveVariable(string prefix, string name) } // Returns null in case of error - private string ResolvePrefix(string prefix) + private string? ResolvePrefix(string prefix) { // ignoreDefaultNs == true if (prefix.Length == 0) @@ -1016,7 +1018,7 @@ public virtual XslFlags Operator(XPathOperator op, XslFlags left, XslFlags right return result | s_operatorType[(int)op]; } - public virtual XslFlags Axis(XPathAxis xpathAxis, XPathNodeType nodeType, string prefix, string name) + public virtual XslFlags Axis(XPathAxis xpathAxis, XPathNodeType nodeType, string? prefix, string? name) { _typeDonor = null; if (xpathAxis == XPathAxis.Self && nodeType == XPathNodeType.All && prefix == null && name == null) @@ -1067,8 +1069,8 @@ public virtual XslFlags Function(string prefix, string name, IList arg if (prefix.Length == 0) { - XPathFunctionInfo xpathFunc; - XsltFunctionInfo xsltFunc; + XPathFunctionInfo? xpathFunc; + XsltFunctionInfo? xsltFunc; if (XPathBuilder.FunctionTable.TryGetValue(name, out xpathFunc)) { @@ -1103,7 +1105,7 @@ public virtual XslFlags Function(string prefix, string name, IList arg } else { - string ns = ResolvePrefix(prefix); + string? ns = ResolvePrefix(prefix); if (ns == XmlReservedNs.NsMsxsl) { switch (name) @@ -1133,7 +1135,7 @@ public virtual XslFlags Function(string prefix, string name, IList arg funcFlags = XslFlags.AnyType; if (_compiler.Settings.EnableScript && ns != null) { - XmlExtensionFunction scrFunc = _compiler.Scripts.ResolveFunction(name, ns, args.Count, default(NullErrorHelper)); + XmlExtensionFunction? scrFunc = _compiler.Scripts.ResolveFunction(name, ns, args.Count, default(NullErrorHelper)); if (scrFunc != null) { XmlQueryType xt = scrFunc.XmlReturnType; @@ -1230,10 +1232,11 @@ public virtual XslFlags Function(string prefix, string name, IList arg internal sealed class XslAstRewriter { - private CompilerScopeManager _scope; - private Stack