Skip to content

Commit

Permalink
fix nullability merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
krwq committed Aug 7, 2020
1 parent b0c22fe commit 9dba56c
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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))
{
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -613,7 +613,7 @@ public virtual QilNode Function(string prefix, string name, IList<QilNode> args)
private QilNode LocalNameOfFirstNode(QilNode arg)
{
_f.CheckNodeSet(arg);
if (arg.XmlType.IsSingleton)
if (arg.XmlType!.IsSingleton)
{
return _f.LocalNameOf(arg);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -897,7 +897,7 @@ protected override QilNode VisitUnknown(QilNode unknown)
{
if (_environment != null)
{
unknown = _environment.GetCurrent();
unknown = _environment.GetCurrent()!;
}
else if (_current != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand All @@ -38,65 +38,65 @@ 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;
}

[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)
{
Expand Down Expand Up @@ -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)
Expand All @@ -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 (
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,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
{
Expand All @@ -34,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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2329,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ QilNode IXPathEnvironment.ResolveFunction(string prefix, string name, IList<QilN
throw new XslLoadException(SR.Xslt_CurrentNotAllowed);
}
// NOTE: This is the only place where the current node (and not the context node) must be used
return ((IXPathEnvironment)this).GetCurrent();
return ((IXPathEnvironment)this).GetCurrent()!;
case FuncId.Key:
if (!_allowKey)
{
Expand All @@ -124,7 +124,7 @@ QilNode IXPathEnvironment.ResolveFunction(string prefix, string name, IList<QilN
case FuncId.Document: return CompileFnDocument(args[0], args.Count > 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]);
Expand Down Expand Up @@ -182,7 +182,7 @@ QilNode IXPathEnvironment.ResolveFunction(string prefix, string name, IList<QilN
else if (name == "namespace-uri")
{
FunctionInfo.CheckArity(/*minArg:*/1, /*maxArg:*/1, name, args.Count);
return _f.InvokeMsNamespaceUri(_f.ConvertToString(args[0]), env.GetCurrent());
return _f.InvokeMsNamespaceUri(_f.ConvertToString(args[0]), env.GetCurrent()!);
}
else if (name == "number")
{
Expand Down Expand Up @@ -429,7 +429,7 @@ private QilNode CompileSingleKey(QilNode name, QilNode key, IFocus env)
}
QilIterator i = _f.Let(name);
QilNode resolvedName = ResolveQNameDynamic(/*ignoreDefaultNs:*/true, i);
result = _f.Invoke(_generalKey, _f.ActualParameterList(i, resolvedName, key, env.GetCurrent()));
result = _f.Invoke(_generalKey, _f.ActualParameterList(i, resolvedName, key, env.GetCurrent()!));
result = _f.Loop(i, result);
}
return result;
Expand All @@ -440,14 +440,14 @@ private QilNode CompileSingleKey(List<Key> 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);
}
Expand Down
Loading

0 comments on commit 9dba56c

Please sign in to comment.