Browse Source

#nullable enable for typesystem and ILInstruction base class

pull/2308/head
Daniel Grunwald 4 years ago
parent
commit
f726a0b73e
  1. 54
      ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs
  2. 19
      ICSharpCode.Decompiler/IL/Transforms/IILTransform.cs
  3. 20
      ICSharpCode.Decompiler/IL/Transforms/Stepper.cs
  4. 8
      ICSharpCode.Decompiler/TypeSystem/IAssembly.cs
  5. 7
      ICSharpCode.Decompiler/TypeSystem/IAttribute.cs
  6. 3
      ICSharpCode.Decompiler/TypeSystem/ICodeContext.cs
  7. 4
      ICSharpCode.Decompiler/TypeSystem/ICompilation.cs
  8. 5
      ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs
  9. 7
      ICSharpCode.Decompiler/TypeSystem/IEntity.cs
  10. 8
      ICSharpCode.Decompiler/TypeSystem/IEvent.cs
  11. 2
      ICSharpCode.Decompiler/TypeSystem/IField.cs
  12. 2
      ICSharpCode.Decompiler/TypeSystem/IFreezable.cs
  13. 30
      ICSharpCode.Decompiler/TypeSystem/IInterningProvider.cs
  14. 7
      ICSharpCode.Decompiler/TypeSystem/IMember.cs
  15. 7
      ICSharpCode.Decompiler/TypeSystem/IMethod.cs
  16. 8
      ICSharpCode.Decompiler/TypeSystem/INamespace.cs
  17. 4
      ICSharpCode.Decompiler/TypeSystem/IParameter.cs
  18. 1
      ICSharpCode.Decompiler/TypeSystem/IParameterizedMember.cs
  19. 6
      ICSharpCode.Decompiler/TypeSystem/IProperty.cs
  20. 2
      ICSharpCode.Decompiler/TypeSystem/ISupportsInterning.cs
  21. 2
      ICSharpCode.Decompiler/TypeSystem/ISymbol.cs
  22. 26
      ICSharpCode.Decompiler/TypeSystem/IType.cs
  23. 4
      ICSharpCode.Decompiler/TypeSystem/ITypeDefinition.cs
  24. 6
      ICSharpCode.Decompiler/TypeSystem/ITypeParameter.cs
  25. 14
      ICSharpCode.Decompiler/TypeSystem/ITypeReference.cs
  26. 3
      ICSharpCode.Decompiler/TypeSystem/IVariable.cs
  27. 7
      ICSharpCode.Decompiler/TypeSystem/KnownTypeReference.cs

54
ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -94,7 +96,7 @@ namespace ICSharpCode.Decompiler.IL @@ -94,7 +96,7 @@ namespace ICSharpCode.Decompiler.IL
/// </remarks>
public bool IsDescendantOf(ILInstruction possibleAncestor)
{
for (ILInstruction ancestor = this; ancestor != null; ancestor = ancestor.Parent)
for (ILInstruction? ancestor = this; ancestor != null; ancestor = ancestor.Parent)
{
if (ancestor == possibleAncestor)
return true;
@ -102,33 +104,33 @@ namespace ICSharpCode.Decompiler.IL @@ -102,33 +104,33 @@ namespace ICSharpCode.Decompiler.IL
return false;
}
public ILInstruction GetCommonParent(ILInstruction other)
public ILInstruction? GetCommonParent(ILInstruction other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));
ILInstruction a = this;
ILInstruction b = other;
ILInstruction? a = this;
ILInstruction? b = other;
int levelA = a.CountAncestors();
int levelB = b.CountAncestors();
while (levelA > levelB)
{
a = a.Parent;
a = a!.Parent;
levelA--;
}
while (levelB > levelA)
{
b = b.Parent;
b = b!.Parent;
levelB--;
}
while (a != b)
{
a = a.Parent;
b = b.Parent;
a = a!.Parent;
b = b!.Parent;
}
return a;
@ -153,13 +155,13 @@ namespace ICSharpCode.Decompiler.IL @@ -153,13 +155,13 @@ namespace ICSharpCode.Decompiler.IL
while (levelA > levelB)
{
a = a.Parent;
a = a.Parent!;
levelA--;
}
while (levelB > levelA)
{
b = b.Parent;
b = b.Parent!;
levelB--;
}
@ -172,8 +174,8 @@ namespace ICSharpCode.Decompiler.IL @@ -172,8 +174,8 @@ namespace ICSharpCode.Decompiler.IL
while (a.Parent != b.Parent)
{
a = a.Parent;
b = b.Parent;
a = a.Parent!;
b = b.Parent!;
}
// now a and b have the same parent or are both root nodes
@ -183,7 +185,7 @@ namespace ICSharpCode.Decompiler.IL @@ -183,7 +185,7 @@ namespace ICSharpCode.Decompiler.IL
private int CountAncestors()
{
int level = 0;
for (ILInstruction ancestor = this; ancestor != null; ancestor = ancestor.Parent)
for (ILInstruction? ancestor = this; ancestor != null; ancestor = ancestor.Parent)
{
level++;
}
@ -240,7 +242,7 @@ namespace ICSharpCode.Decompiler.IL @@ -240,7 +242,7 @@ namespace ICSharpCode.Decompiler.IL
protected private void MakeDirty()
{
#if DEBUG
for (ILInstruction inst = this; inst != null && !inst.IsDirty; inst = inst.parent)
for (ILInstruction? inst = this; inst != null && !inst.IsDirty; inst = inst.parent)
{
inst.IsDirty = true;
}
@ -289,7 +291,7 @@ namespace ICSharpCode.Decompiler.IL @@ -289,7 +291,7 @@ namespace ICSharpCode.Decompiler.IL
protected void InvalidateFlags()
{
for (ILInstruction inst = this; inst != null && inst.flags != invalidFlags; inst = inst.parent)
for (ILInstruction? inst = this; inst != null && inst.flags != invalidFlags; inst = inst.parent)
inst.flags = invalidFlags;
}
@ -425,7 +427,7 @@ namespace ICSharpCode.Decompiler.IL @@ -425,7 +427,7 @@ namespace ICSharpCode.Decompiler.IL
internal ChildrenCollection(ILInstruction inst)
{
Debug.Assert(inst != null);
this.inst = inst;
this.inst = inst!;
}
public int Count {
@ -485,7 +487,7 @@ namespace ICSharpCode.Decompiler.IL @@ -485,7 +487,7 @@ namespace ICSharpCode.Decompiler.IL
/// </summary>
public struct ChildrenEnumerator : IEnumerator<ILInstruction>
{
ILInstruction inst;
ILInstruction? inst;
readonly int end;
int pos;
@ -494,7 +496,7 @@ namespace ICSharpCode.Decompiler.IL @@ -494,7 +496,7 @@ namespace ICSharpCode.Decompiler.IL
Debug.Assert(inst != null);
this.inst = inst;
this.pos = -1;
this.end = inst.GetChildCount();
this.end = inst!.GetChildCount();
#if DEBUG
inst.StartEnumerator();
#endif
@ -502,7 +504,7 @@ namespace ICSharpCode.Decompiler.IL @@ -502,7 +504,7 @@ namespace ICSharpCode.Decompiler.IL
public ILInstruction Current {
get {
return inst.GetChild(pos);
return inst!.GetChild(pos);
}
}
@ -556,7 +558,7 @@ namespace ICSharpCode.Decompiler.IL @@ -556,7 +558,7 @@ namespace ICSharpCode.Decompiler.IL
/// </remarks>
public void ReplaceWith(ILInstruction replacement)
{
Debug.Assert(parent.GetChild(ChildIndex) == this);
Debug.Assert(parent!.GetChild(ChildIndex) == this);
if (replacement == this)
return;
parent.SetChild(ChildIndex, replacement);
@ -621,7 +623,7 @@ namespace ICSharpCode.Decompiler.IL @@ -621,7 +623,7 @@ namespace ICSharpCode.Decompiler.IL
/// </summary>
public IEnumerable<ILInstruction> Ancestors {
get {
for (ILInstruction node = this; node != null; node = node.Parent)
for (ILInstruction? node = this; node != null; node = node.Parent)
{
yield return node;
}
@ -683,7 +685,7 @@ namespace ICSharpCode.Decompiler.IL @@ -683,7 +685,7 @@ namespace ICSharpCode.Decompiler.IL
child.ReleaseRef();
}
ILInstruction parent;
ILInstruction? parent;
/// <summary>
/// Gets the parent of this ILInstruction.
@ -709,7 +711,7 @@ namespace ICSharpCode.Decompiler.IL @@ -709,7 +711,7 @@ namespace ICSharpCode.Decompiler.IL
///
/// Note that is it is possible (though unusual) for a stale position to reference an orphaned node.
/// </remarks>
public ILInstruction Parent {
public ILInstruction? Parent {
get { return parent; }
}
@ -732,7 +734,7 @@ namespace ICSharpCode.Decompiler.IL @@ -732,7 +734,7 @@ namespace ICSharpCode.Decompiler.IL
///
/// Precondition: this node must not be orphaned.
/// </remarks>
public SlotInfo SlotInfo {
public SlotInfo? SlotInfo {
get {
if (parent == null)
return null;
@ -748,7 +750,7 @@ namespace ICSharpCode.Decompiler.IL @@ -748,7 +750,7 @@ namespace ICSharpCode.Decompiler.IL
/// <param name="newValue">New child</param>
/// <param name="index">Index of the field in the Children collection</param>
protected internal void SetChildInstruction<T>(ref T childPointer, T newValue, int index)
where T : ILInstruction
where T : ILInstruction?
{
T oldValue = childPointer;
Debug.Assert(oldValue == GetChild(index));
@ -861,7 +863,7 @@ namespace ICSharpCode.Decompiler.IL @@ -861,7 +863,7 @@ namespace ICSharpCode.Decompiler.IL
/// If the method returns true, it adds the capture groups (if any) to the match.
/// If the method returns false, the match object may remain in a partially-updated state and
/// needs to be restored before it can be reused.</returns>
protected internal abstract bool PerformMatch(ILInstruction other, ref Match match);
protected internal abstract bool PerformMatch(ILInstruction? other, ref Match match);
/// <summary>
/// Attempts matching this instruction against a list of other instructions (or a part of said list).

19
ICSharpCode.Decompiler/IL/Transforms/IILTransform.cs

@ -16,16 +16,15 @@ @@ -16,16 +16,15 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Threading;
using ICSharpCode.Decompiler.CSharp.TypeSystem;
using ICSharpCode.Decompiler.DebugInfo;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.Util;
namespace ICSharpCode.Decompiler.IL.Transforms
{
@ -44,16 +43,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -44,16 +43,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{
public ILFunction Function { get; }
public IDecompilerTypeSystem TypeSystem { get; }
public IDebugInfoProvider DebugInfo { get; }
public IDebugInfoProvider? DebugInfo { get; }
public DecompilerSettings Settings { get; }
public CancellationToken CancellationToken { get; set; }
public Stepper Stepper { get; set; }
public Metadata.PEFile PEFile => TypeSystem.MainModule.PEFile;
internal DecompileRun DecompileRun { get; set; }
internal ResolvedUsingScope UsingScope => DecompileRun?.UsingScope.Resolve(TypeSystem);
internal DecompileRun? DecompileRun { get; set; }
internal ResolvedUsingScope? UsingScope => DecompileRun?.UsingScope.Resolve(TypeSystem);
public ILTransformContext(ILFunction function, IDecompilerTypeSystem typeSystem, IDebugInfoProvider debugInfo, DecompilerSettings settings = null)
public ILTransformContext(ILFunction function, IDecompilerTypeSystem typeSystem, IDebugInfoProvider? debugInfo, DecompilerSettings? settings = null)
{
this.Function = function ?? throw new ArgumentNullException(nameof(function));
this.TypeSystem = typeSystem ?? throw new ArgumentNullException(nameof(typeSystem));
@ -62,7 +61,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -62,7 +61,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Stepper = new Stepper();
}
public ILTransformContext(ILTransformContext context, ILFunction function = null)
public ILTransformContext(ILTransformContext context, ILFunction? function = null)
{
this.Function = function ?? context.Function;
this.TypeSystem = context.TypeSystem;
@ -89,13 +88,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -89,13 +88,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms
/// Unlike <c>context.Stepper.Step()</c>, calls to this method are only compiled in debug builds.
/// </summary>
[Conditional("STEP")]
internal void Step(string description, ILInstruction near)
internal void Step(string description, ILInstruction? near)
{
Stepper.Step(description, near);
}
[Conditional("STEP")]
internal void StepStartGroup(string description, ILInstruction near = null)
internal void StepStartGroup(string description, ILInstruction? near = null)
{
Stepper.StartGroup(description, near);
}

20
ICSharpCode.Decompiler/IL/Transforms/Stepper.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -58,8 +60,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -58,8 +60,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
public class Node
{
public string Description { get; set; }
public ILInstruction Position { get; set; }
public string Description { get; }
public ILInstruction? Position { get; set; }
/// <summary>
/// BeginStep is inclusive.
/// </summary>
@ -70,6 +72,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -70,6 +72,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms
public int EndStep { get; set; }
public IList<Node> Children { get; } = new List<Node>();
public Node(string description)
{
Description = description;
}
}
readonly Stack<Node> groups;
@ -88,12 +95,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -88,12 +95,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms
///
/// May throw <see cref="StepLimitReachedException"/> in debug mode.
/// </summary>
public void Step(string description, ILInstruction near = null)
public void Step(string description, ILInstruction? near = null)
{
StepInternal(description, near);
}
private Node StepInternal(string description, ILInstruction near)
private Node StepInternal(string description, ILInstruction? near)
{
if (step == StepLimit)
{
@ -102,8 +109,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -102,8 +109,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
else
throw new StepLimitReachedException();
}
var stepNode = new Node {
Description = $"{step}: {description}",
var stepNode = new Node($"{step}: {description}") {
Position = near,
BeginStep = step,
EndStep = step + 1
@ -117,7 +123,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -117,7 +123,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return stepNode;
}
public void StartGroup(string description, ILInstruction near = null)
public void StartGroup(string description, ILInstruction? near = null)
{
groups.Push(StepInternal(description, near));
}

8
ICSharpCode.Decompiler/TypeSystem/IAssembly.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System.Collections.Generic;
using ICSharpCode.Decompiler.Metadata;
@ -40,7 +42,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -40,7 +42,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <summary>
/// Resolves this metadata module.
/// </summary>
IModule Resolve(ITypeResolveContext context);
IModule? Resolve(ITypeResolveContext context);
}
/// <summary>
@ -51,7 +53,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -51,7 +53,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <summary>
/// Gets the underlying metadata file. May return null, if the IAssembly was not created from a PE file.
/// </summary>
PEFile PEFile { get; }
PEFile? PEFile { get; }
/// <summary>
/// Gets whether this assembly is the main assembly of the compilation.
@ -97,7 +99,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -97,7 +99,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// Gets the type definition for a top-level type.
/// </summary>
/// <remarks>This method uses ordinal name comparison, not the compilation's name comparer.</remarks>
ITypeDefinition GetTypeDefinition(TopLevelTypeName topLevelTypeName);
ITypeDefinition? GetTypeDefinition(TopLevelTypeName topLevelTypeName);
/// <summary>
/// Gets all non-nested types in the assembly.

7
ICSharpCode.Decompiler/TypeSystem/IAttribute.cs

@ -16,12 +16,11 @@ @@ -16,12 +16,11 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System.Collections.Generic;
#nullable enable
using System.Collections.Immutable;
using System.Reflection.Metadata;
using ICSharpCode.Decompiler.Semantics;
namespace ICSharpCode.Decompiler.TypeSystem
{
/// <summary>
@ -39,7 +38,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -39,7 +38,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// Gets the constructor being used.
/// This property may return null if no matching constructor was found.
/// </summary>
IMethod Constructor { get; }
IMethod? Constructor { get; }
/// <summary>
/// Gets whether there were errors decoding the attribute.

3
ICSharpCode.Decompiler/TypeSystem/ICodeContext.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System.Collections.Generic;
namespace ICSharpCode.Decompiler.TypeSystem
@ -34,4 +36,3 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -34,4 +36,3 @@ namespace ICSharpCode.Decompiler.TypeSystem
bool IsWithinLambdaExpression { get; }
}
}

4
ICSharpCode.Decompiler/TypeSystem/ICompilation.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System;
using System.Collections.Generic;
@ -63,7 +65,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -63,7 +65,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// returns the global root namespace.
/// If no alias with the specified name exists, this method returns null.
/// </remarks>
INamespace GetNamespaceForExternAlias(string alias);
INamespace? GetNamespaceForExternAlias(string? alias);
IType FindType(KnownTypeCode typeCode);

5
ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs

@ -16,10 +16,7 @@ @@ -16,10 +16,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System.Collections.Immutable;
using System.Reflection.Metadata;
using ICSharpCode.Decompiler.Metadata;
#nullable enable
namespace ICSharpCode.Decompiler.TypeSystem
{

7
ICSharpCode.Decompiler/TypeSystem/IEntity.cs

@ -16,7 +16,8 @@ @@ -16,7 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
#nullable enable
using System.Collections.Generic;
namespace ICSharpCode.Decompiler.TypeSystem
@ -46,14 +47,14 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -46,14 +47,14 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// For members, this is the class that contains the member.
/// For nested classes, this is the outer class. For top-level entities, this property returns null.
/// </summary>
ITypeDefinition DeclaringTypeDefinition { get; }
ITypeDefinition? DeclaringTypeDefinition { get; }
/// <summary>
/// Gets/Sets the declaring type (incl. type arguments, if any).
/// This property will return null for top-level entities.
/// If this is not a specialized member, the value returned is equal to <see cref="DeclaringTypeDefinition"/>.
/// </summary>
IType DeclaringType { get; }
IType? DeclaringType { get; }
/// <summary>
/// The module in which this entity is defined.

8
ICSharpCode.Decompiler/TypeSystem/IEvent.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
namespace ICSharpCode.Decompiler.TypeSystem
{
public interface IEvent : IMember
@ -24,8 +26,8 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -24,8 +26,8 @@ namespace ICSharpCode.Decompiler.TypeSystem
bool CanRemove { get; }
bool CanInvoke { get; }
IMethod AddAccessor { get; }
IMethod RemoveAccessor { get; }
IMethod InvokeAccessor { get; }
IMethod? AddAccessor { get; }
IMethod? RemoveAccessor { get; }
IMethod? InvokeAccessor { get; }
}
}

2
ICSharpCode.Decompiler/TypeSystem/IField.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
namespace ICSharpCode.Decompiler.TypeSystem
{
/// <summary>

2
ICSharpCode.Decompiler/TypeSystem/IFreezable.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
namespace ICSharpCode.Decompiler.TypeSystem
{
public interface IFreezable

30
ICSharpCode.Decompiler/TypeSystem/IInterningProvider.cs

@ -16,7 +16,10 @@ @@ -16,7 +16,10 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace ICSharpCode.Decompiler.TypeSystem
{
@ -47,52 +50,57 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -47,52 +50,57 @@ namespace ICSharpCode.Decompiler.TypeSystem
///
/// If the object is freezable, it will be frozen.
/// </summary>
public abstract ISupportsInterning Intern(ISupportsInterning obj);
[return: NotNullIfNotNull("obj")]
public abstract ISupportsInterning? Intern(ISupportsInterning? obj);
/// <summary>
/// Interns the specified object.
///
/// If the object is freezable, it will be frozen.
/// </summary>
public T Intern<T>(T obj) where T : class, ISupportsInterning
[return: NotNullIfNotNull("obj")]
public T? Intern<T>(T? obj) where T : class, ISupportsInterning
{
ISupportsInterning input = obj;
return (T)Intern(input);
ISupportsInterning? input = obj;
return (T?)Intern(input);
}
/// <summary>
/// Interns the specified string.
/// </summary>
public abstract string Intern(string text);
[return: NotNullIfNotNull("text")]
public abstract string? Intern(string? text);
/// <summary>
/// Inters a boxed value type.
/// </summary>
public abstract object InternValue(object obj);
[return: NotNullIfNotNull("obj")]
public abstract object? InternValue(object? obj);
/// <summary>
/// Interns the given list. Uses reference equality to compare the list elements.
/// </summary>
public abstract IList<T> InternList<T>(IList<T> list) where T : class;
[return: NotNullIfNotNull("list")]
public abstract IList<T>? InternList<T>(IList<T>? list) where T : class;
sealed class DummyInterningProvider : InterningProvider
{
public override ISupportsInterning Intern(ISupportsInterning obj)
public override ISupportsInterning? Intern(ISupportsInterning? obj)
{
return obj;
}
public override string Intern(string text)
public override string? Intern(string? text)
{
return text;
}
public override object InternValue(object obj)
public override object? InternValue(object? obj)
{
return obj;
}
public override IList<T> InternList<T>(IList<T> list)
public override IList<T>? InternList<T>(IList<T>? list)
{
return list;
}

7
ICSharpCode.Decompiler/TypeSystem/IMember.cs

@ -16,7 +16,8 @@ @@ -16,7 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
#nullable enable
using System.Collections.Generic;
namespace ICSharpCode.Decompiler.TypeSystem
@ -40,7 +41,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -40,7 +41,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <returns>
/// Returns the resolved member, or <c>null</c> if the member could not be found.
/// </returns>
IMember Resolve(ITypeResolveContext context);
IMember? Resolve(ITypeResolveContext context);
}
/// <summary>
@ -119,6 +120,6 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -119,6 +120,6 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <summary>
/// Gets whether the members are considered equal when applying the specified type normalization.
/// </summary>
bool Equals(IMember obj, TypeVisitor typeNormalization);
bool Equals(IMember? obj, TypeVisitor typeNormalization);
}
}

7
ICSharpCode.Decompiler/TypeSystem/IMethod.cs

@ -16,7 +16,8 @@ @@ -16,7 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
#nullable enable
using System.Collections.Generic;
using System.Reflection;
@ -86,7 +87,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -86,7 +87,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// If this method is an accessor, returns the corresponding property/event.
/// Otherwise, returns null.
/// </summary>
IMember AccessorOwner { get; }
IMember? AccessorOwner { get; }
/// <summary>
/// Gets the kind of accessor this is.
@ -98,7 +99,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -98,7 +99,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// A reduced method doesn't contain the extension method parameter. That means that it has one parameter less than its definition.
/// A local function doesn't contain compiler-generated method parameters at the end.
/// </summary>
IMethod ReducedFrom { get; }
IMethod? ReducedFrom { get; }
/// <summary>
/// Specializes this method with the given substitution.

8
ICSharpCode.Decompiler/TypeSystem/INamespace.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System.Collections.Generic;
namespace ICSharpCode.Decompiler.TypeSystem
@ -49,7 +51,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -49,7 +51,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// Gets the parent namespace.
/// Returns null if this is the root namespace.
/// </summary>
INamespace ParentNamespace { get; }
INamespace? ParentNamespace { get; }
/// <summary>
/// Gets the child namespaces in this namespace.
@ -73,7 +75,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -73,7 +75,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <remarks>
/// This method uses the compilation's current string comparer.
/// </remarks>
INamespace GetChildNamespace(string name);
INamespace? GetChildNamespace(string name);
/// <summary>
/// Gets the type with the specified short name and type parameter count.
@ -82,6 +84,6 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -82,6 +84,6 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <remarks>
/// This method uses the compilation's current string comparer.
/// </remarks>
ITypeDefinition GetTypeDefinition(string name, int typeParameterCount);
ITypeDefinition? GetTypeDefinition(string name, int typeParameterCount);
}
}

4
ICSharpCode.Decompiler/TypeSystem/IParameter.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System.Collections.Generic;
using System.Runtime.CompilerServices;
@ -90,6 +92,6 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -90,6 +92,6 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// Gets the owner of this parameter.
/// May return null; for example when parameters belong to lambdas or anonymous methods.
/// </summary>
IParameterizedMember Owner { get; }
IParameterizedMember? Owner { get; }
}
}

1
ICSharpCode.Decompiler/TypeSystem/IParameterizedMember.cs

@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System.Collections.Generic;

6
ICSharpCode.Decompiler/TypeSystem/IProperty.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
namespace ICSharpCode.Decompiler.TypeSystem
{
/// <summary>
@ -26,8 +28,8 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -26,8 +28,8 @@ namespace ICSharpCode.Decompiler.TypeSystem
bool CanGet { get; }
bool CanSet { get; }
IMethod Getter { get; }
IMethod Setter { get; }
IMethod? Getter { get; }
IMethod? Setter { get; }
bool IsIndexer { get; }

2
ICSharpCode.Decompiler/TypeSystem/ISupportsInterning.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
namespace ICSharpCode.Decompiler.TypeSystem
{
/// <summary>

2
ICSharpCode.Decompiler/TypeSystem/ISymbol.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
namespace ICSharpCode.Decompiler.TypeSystem
{
public enum SymbolKind : byte

26
ICSharpCode.Decompiler/TypeSystem/IType.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System;
using System.Collections.Generic;
@ -83,13 +85,13 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -83,13 +85,13 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// Gets the underlying type definition.
/// Can return null for types which do not have a type definition (for example arrays, pointers, type parameters).
/// </summary>
ITypeDefinition GetDefinition();
ITypeDefinition? GetDefinition();
/// <summary>
/// Gets the parent type, if this is a nested type.
/// Returns null for top-level types.
/// </summary>
IType DeclaringType { get; }
IType? DeclaringType { get; }
/// <summary>
/// Gets the number of type parameters.
@ -168,7 +170,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -168,7 +170,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// Base.GetNestedTypes() = { Base`1+Nested`1[`0, unbound] }
/// </code>
/// </example>
IEnumerable<IType> GetNestedTypes(Predicate<ITypeDefinition> filter = null, GetMemberOptions options = GetMemberOptions.None);
IEnumerable<IType> GetNestedTypes(Predicate<ITypeDefinition>? filter = null, GetMemberOptions options = GetMemberOptions.None);
// Note that we cannot 'leak' the additional type parameter as we leak the normal type parameters, because
// the index might collide. For example,
@ -193,7 +195,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -193,7 +195,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// and thus 'leaked' to the caller in the same way the GetMembers() method does not specialize members
/// from an <see cref="ITypeDefinition"/> and 'leaks' type parameters in member signatures.
/// </remarks>
IEnumerable<IType> GetNestedTypes(IReadOnlyList<IType> typeArguments, Predicate<ITypeDefinition> filter = null, GetMemberOptions options = GetMemberOptions.None);
IEnumerable<IType> GetNestedTypes(IReadOnlyList<IType> typeArguments, Predicate<ITypeDefinition>? filter = null, GetMemberOptions options = GetMemberOptions.None);
/// <summary>
/// Gets all instance constructors for this type.
@ -209,7 +211,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -209,7 +211,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// and the appropriate <see cref="Implementation.SpecializedMethod"/> will be returned.
/// </para>
/// </remarks>
IEnumerable<IMethod> GetConstructors(Predicate<IMethod> filter = null, GetMemberOptions options = GetMemberOptions.IgnoreInheritedMembers);
IEnumerable<IMethod> GetConstructors(Predicate<IMethod>? filter = null, GetMemberOptions options = GetMemberOptions.IgnoreInheritedMembers);
/// <summary>
/// Gets all methods that can be called on this type.
@ -236,7 +238,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -236,7 +238,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// the ambiguity can be avoided.
/// </para>
/// </remarks>
IEnumerable<IMethod> GetMethods(Predicate<IMethod> filter = null, GetMemberOptions options = GetMemberOptions.None);
IEnumerable<IMethod> GetMethods(Predicate<IMethod>? filter = null, GetMemberOptions options = GetMemberOptions.None);
/// <summary>
/// Gets all generic methods that can be called on this type with the specified type arguments.
@ -257,7 +259,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -257,7 +259,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// and the other overload's remarks about ambiguous signatures apply here as well.
/// </para>
/// </remarks>
IEnumerable<IMethod> GetMethods(IReadOnlyList<IType> typeArguments, Predicate<IMethod> filter = null, GetMemberOptions options = GetMemberOptions.None);
IEnumerable<IMethod> GetMethods(IReadOnlyList<IType> typeArguments, Predicate<IMethod>? filter = null, GetMemberOptions options = GetMemberOptions.None);
/// <summary>
/// Gets all properties that can be called on this type.
@ -269,7 +271,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -269,7 +271,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// For properties on parameterized types, type substitution will be performed on the property signature,
/// and the appropriate <see cref="Implementation.SpecializedProperty"/> will be returned.
/// </remarks>
IEnumerable<IProperty> GetProperties(Predicate<IProperty> filter = null, GetMemberOptions options = GetMemberOptions.None);
IEnumerable<IProperty> GetProperties(Predicate<IProperty>? filter = null, GetMemberOptions options = GetMemberOptions.None);
/// <summary>
/// Gets all fields that can be accessed on this type.
@ -281,7 +283,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -281,7 +283,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// For fields on parameterized types, type substitution will be performed on the field's return type,
/// and the appropriate <see cref="Implementation.SpecializedField"/> will be returned.
/// </remarks>
IEnumerable<IField> GetFields(Predicate<IField> filter = null, GetMemberOptions options = GetMemberOptions.None);
IEnumerable<IField> GetFields(Predicate<IField>? filter = null, GetMemberOptions options = GetMemberOptions.None);
/// <summary>
/// Gets all events that can be accessed on this type.
@ -293,7 +295,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -293,7 +295,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// For fields on parameterized types, type substitution will be performed on the event's return type,
/// and the appropriate <see cref="Implementation.SpecializedEvent"/> will be returned.
/// </remarks>
IEnumerable<IEvent> GetEvents(Predicate<IEvent> filter = null, GetMemberOptions options = GetMemberOptions.None);
IEnumerable<IEvent> GetEvents(Predicate<IEvent>? filter = null, GetMemberOptions options = GetMemberOptions.None);
/// <summary>
/// Gets all members that can be called on this type.
@ -312,7 +314,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -312,7 +314,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <see cref="GetMethods(Predicate{IMethod}, GetMemberOptions)"/> method apply here as well.
/// </para>
/// </remarks>
IEnumerable<IMember> GetMembers(Predicate<IMember> filter = null, GetMemberOptions options = GetMemberOptions.None);
IEnumerable<IMember> GetMembers(Predicate<IMember>? filter = null, GetMemberOptions options = GetMemberOptions.None);
/// <summary>
/// Gets all accessors belonging to properties or events on this type.
@ -323,7 +325,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -323,7 +325,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <remarks>
/// Accessors are not returned by GetMembers() or GetMethods().
/// </remarks>
IEnumerable<IMethod> GetAccessors(Predicate<IMethod> filter = null, GetMemberOptions options = GetMemberOptions.None);
IEnumerable<IMethod> GetAccessors(Predicate<IMethod>? filter = null, GetMemberOptions options = GetMemberOptions.None);
}
[Flags]

4
ICSharpCode.Decompiler/TypeSystem/ITypeDefinition.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System.Collections.Generic;
namespace ICSharpCode.Decompiler.TypeSystem
@ -60,7 +62,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -60,7 +62,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// Gets/Sets the declaring type (incl. type arguments, if any).
/// This property will return null for top-level types.
/// </summary>
new IType DeclaringType { get; } // solves ambiguity between IType.DeclaringType and IEntity.DeclaringType
new IType? DeclaringType { get; } // solves ambiguity between IType.DeclaringType and IEntity.DeclaringType
/// <summary>
/// Gets whether this type contains extension methods.

6
ICSharpCode.Decompiler/TypeSystem/ITypeParameter.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System;
using System.Collections.Generic;
@ -43,7 +45,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -43,7 +45,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// inner.TypeParameters[0].Owner will be the outer class, because the same
/// ITypeParameter instance is used both on Outer`1 and Outer`1+Inner.
/// </remarks>
IEntity Owner { get; }
IEntity? Owner { get; }
/// <summary>
/// Gets the index of the type parameter in the type parameter list of the owning method/class.
@ -112,7 +114,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -112,7 +114,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public IType Type { get; }
public IReadOnlyList<IAttribute> Attributes { get; }
public TypeConstraint(IType type, IReadOnlyList<IAttribute> attributes = null)
public TypeConstraint(IType type, IReadOnlyList<IAttribute>? attributes = null)
{
this.Type = type ?? throw new ArgumentNullException(nameof(type));
this.Attributes = attributes ?? EmptyList<IAttribute>.Instance;

14
ICSharpCode.Decompiler/TypeSystem/ITypeReference.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
namespace ICSharpCode.Decompiler.TypeSystem
{
/// <summary>
@ -53,19 +55,19 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -53,19 +55,19 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// Gets the current module.
/// This property may return null if this context does not specify any module.
/// </summary>
IModule CurrentModule { get; }
IModule? CurrentModule { get; }
/// <summary>
/// Gets the current type definition.
/// </summary>
ITypeDefinition CurrentTypeDefinition { get; }
ITypeDefinition? CurrentTypeDefinition { get; }
/// <summary>
/// Gets the current member.
/// </summary>
IMember CurrentMember { get; }
IMember? CurrentMember { get; }
ITypeResolveContext WithCurrentTypeDefinition(ITypeDefinition typeDefinition);
ITypeResolveContext WithCurrentMember(IMember member);
ITypeResolveContext WithCurrentTypeDefinition(ITypeDefinition? typeDefinition);
ITypeResolveContext WithCurrentMember(IMember? member);
}
}
}

3
ICSharpCode.Decompiler/TypeSystem/IVariable.cs

@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
namespace ICSharpCode.Decompiler.TypeSystem
{
@ -42,6 +43,6 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -42,6 +43,6 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// If this field is a constant, retrieves the value.
/// For parameters, this is the default value.
/// </summary>
object GetConstantValue(bool throwOnInvalidMetadata = false);
object? GetConstantValue(bool throwOnInvalidMetadata = false);
}
}

7
ICSharpCode.Decompiler/TypeSystem/KnownTypeReference.cs

@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System;
using System.Collections.Generic;
@ -162,7 +163,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -162,7 +163,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
{
internal const int KnownTypeCodeCount = (int)KnownTypeCode.Range + 1;
static readonly KnownTypeReference[] knownTypeReferences = new KnownTypeReference[KnownTypeCodeCount] {
static readonly KnownTypeReference?[] knownTypeReferences = new KnownTypeReference?[KnownTypeCodeCount] {
null, // None
new KnownTypeReference(KnownTypeCode.Object, TypeKind.Class, "System", "Object", baseType: KnownTypeCode.None),
new KnownTypeReference(KnownTypeCode.DBNull, TypeKind.Class, "System", "DBNull"),
@ -231,7 +232,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -231,7 +232,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// Gets the known type reference for the specified type code.
/// Returns null for KnownTypeCode.None.
/// </summary>
public static KnownTypeReference Get(KnownTypeCode typeCode)
public static KnownTypeReference? Get(KnownTypeCode typeCode)
{
return knownTypeReferences[(int)typeCode];
}
@ -299,7 +300,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -299,7 +300,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// Gets the C# primitive type name from the known type code.
/// Returns null if there is no primitive name for the specified type.
/// </summary>
public static string GetCSharpNameByTypeCode(KnownTypeCode knownTypeCode)
public static string? GetCSharpNameByTypeCode(KnownTypeCode knownTypeCode)
{
switch (knownTypeCode)
{

Loading…
Cancel
Save