More nullability

This commit is contained in:
YoshiRulz 2021-12-01 06:19:10 +10:00
parent 76faa7c835
commit cd4d7a89a4
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
19 changed files with 49 additions and 93 deletions

View File

@ -83,7 +83,7 @@ namespace BizHawk.Client.Common
{
return new {
disasm = DisassemblableCore.Disassemble(
string.IsNullOrEmpty(name) ? MemoryDomains.SystemBus : MemoryDomains[name],
string.IsNullOrEmpty(name) ? MemoryDomains.SystemBus : MemoryDomains[name]!,
pc,
out var l
),

View File

@ -1,4 +1,6 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using System.IO;
using BizHawk.Common.PathExtensions;
using BizHawk.Emulation.Common;
@ -49,10 +51,10 @@ namespace BizHawk.Client.Common
return null;
}
private (byte[] FW, string Path) GetFirmwareWithPathOrThrow(FirmwareID id, string msg)
private (byte[] FW, string Path) GetFirmwareWithPathOrThrow(FirmwareID id, string? msg)
=> GetFirmwareWithPath(id) ?? throw new MissingFirmwareException($"Couldn't find required firmware {id}. This is fatal{(msg is null ? "." : $": {msg}")}");
public byte[] GetFirmware(FirmwareID id, string msg = null)
public byte[]? GetFirmware(FirmwareID id, string? msg = null)
{
var tuple = GetFirmwareWithPath(id);
if (tuple is null && msg is not null)
@ -62,10 +64,10 @@ namespace BizHawk.Client.Common
return tuple?.FW;
}
public byte[] GetFirmwareOrThrow(FirmwareID id, string msg = null)
public byte[] GetFirmwareOrThrow(FirmwareID id, string? msg = null)
=> GetFirmwareWithPathOrThrow(id, msg).FW;
public (byte[] FW, GameInfo Game) GetFirmwareWithGameInfoOrThrow(FirmwareID id, string msg = null)
public (byte[] FW, GameInfo Game) GetFirmwareWithGameInfoOrThrow(FirmwareID id, string? msg = null)
{
var (fw, path) = GetFirmwareWithPathOrThrow(id, msg);
return (fw, Database.GetGameInfo(fw, path));

View File

@ -1,6 +1,4 @@
#nullable disable
using System;
using System;
using System.Collections.Generic;
using System.Linq;
@ -41,7 +39,7 @@ namespace BizHawk.Emulation.Common
while (coreType != typeof(object))
{
_services.Add(coreType, core);
coreType = coreType.BaseType;
coreType = coreType.BaseType!;
}
}
@ -49,23 +47,16 @@ namespace BizHawk.Emulation.Common
/// <typeparam name="T">The <see cref="IEmulatorService"/> to register</typeparam>
/// <exception cref="ArgumentNullException"><paramref name="provider"/> is null</exception>
public void Register<T>(T provider)
where T : IEmulatorService
where T : class, IEmulatorService
{
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
_services[typeof(T)] = provider;
}
public T GetService<T>()
where T : IEmulatorService
{
return (T)GetService(typeof(T));
}
=> (T) GetService(typeof(T))!;
public object GetService(Type t)
public object? GetService(Type t)
{
return _services.TryGetValue(t, out var service) ? service : null;
}

View File

@ -1,6 +1,4 @@
#nullable disable
using System;
using System;
using System.Collections.Generic;
using System.Linq;
@ -48,9 +46,9 @@ namespace BizHawk.Emulation.Common
protected abstract void TraceFromCallback(uint addr, uint value, uint flags);
private ITraceSink _sink;
private ITraceSink? _sink;
public ITraceSink Sink
public ITraceSink? Sink
{
get => _sink;
set
@ -68,6 +66,7 @@ namespace BizHawk.Emulation.Common
public string Header { get; }
#nullable disable
private class TracingMemoryCallback : IMemoryCallback
{
public TracingMemoryCallback(MemoryCallbackDelegate callback, string scope)
@ -88,5 +87,6 @@ namespace BizHawk.Emulation.Common
public string Scope { get; }
}
#nullable restore
}
}

View File

@ -1,6 +1,4 @@
#nullable disable
using System;
using System;
using System.Collections.Generic;
using System.Linq;
@ -57,7 +55,7 @@ namespace BizHawk.Emulation.Common
}
public delegate void ActiveChangedEventHandler();
public event ActiveChangedEventHandler ActiveChanged;
public event ActiveChangedEventHandler? ActiveChanged;
private void Changes(bool hadAny, bool hasAny)
{

View File

@ -1,6 +1,4 @@
#nullable disable
using System;
using System;
using System.Collections;
using System.Collections.Generic;
@ -18,11 +16,6 @@ namespace BizHawk.Emulation.Common
public MemoryBasedInputCallbackSystem(IDebuggable debuggableCore, string scope, IEnumerable<uint> addresses)
{
if (addresses == null)
{
throw new ArgumentException($"{nameof(addresses)} cannot be null.");
}
if (!debuggableCore.MemoryCallbacksAvailable())
{
throw new InvalidOperationException("Memory callbacks are required");

View File

@ -1,6 +1,4 @@
#nullable disable
using System;
using System;
namespace BizHawk.Emulation.Common
{

View File

@ -1,6 +1,4 @@
#nullable disable
namespace BizHawk.Emulation.Common
namespace BizHawk.Emulation.Common
{
/// <summary>
/// A default IVideoProvider that simply returns

View File

@ -1,6 +1,4 @@
#nullable disable
using System;
using System;
namespace BizHawk.Emulation.Common.Base_Implementations
{

View File

@ -1,6 +1,4 @@
#nullable disable
using System;
using System;
namespace BizHawk.Emulation.Common
{

View File

@ -1,6 +1,4 @@
#nullable disable
namespace BizHawk.Emulation.Common
namespace BizHawk.Emulation.Common
{
/// <summary>
/// Defines the means by which firmware, bios and other necessary files are provided to a core that needs them
@ -24,15 +22,15 @@ namespace BizHawk.Emulation.Common
/// <param name="msg">warning message to show on failure</param>
/// <returns><see langword="null"/> iff failed</returns>
byte[] GetFirmware(FirmwareID id, string msg = null);
byte[]? GetFirmware(FirmwareID id, string? msg = null);
/// <param name="msg">exception message to show on failure</param>
/// <exception cref="MissingFirmwareException">if not found</exception>
byte[] GetFirmwareOrThrow(FirmwareID id, string msg = null);
byte[] GetFirmwareOrThrow(FirmwareID id, string? msg = null);
/// <param name="msg">exception message to show on failure</param>
/// <exception cref="MissingFirmwareException">if not found</exception>
/// <remarks>only used in PCEHawk</remarks>
(byte[] FW, GameInfo Game) GetFirmwareWithGameInfoOrThrow(FirmwareID id, string msg = null);
(byte[] FW, GameInfo Game) GetFirmwareWithGameInfoOrThrow(FirmwareID id, string? msg = null);
}
}

View File

@ -1,6 +1,4 @@
#nullable disable
using System;
using System;
using System.Collections.Generic;
namespace BizHawk.Emulation.Common
@ -29,7 +27,7 @@ namespace BizHawk.Emulation.Common
/// <summary>
/// Returns an instance of T if T is available
/// Else returns null
/// Else throws NRE
/// </summary>
/// <typeparam name="T">The requested <see cref="IEmulatorService"/></typeparam>
T GetService<T>() where T : IEmulatorService;
@ -38,7 +36,7 @@ namespace BizHawk.Emulation.Common
/// Returns an instance of t if t is available
/// Else returns null
/// </summary>
object GetService(Type t);
object? GetService(Type t);
/// <summary>
/// Gets a list of all currently registered services available to be retrieved

View File

@ -1,6 +1,4 @@
#nullable disable
using System;
using System;
using System.Collections.Generic;
namespace BizHawk.Emulation.Common

View File

@ -1,6 +1,4 @@
#nullable disable
using System;
using System;
using System.Linq;
using System.Collections.Generic;
@ -40,12 +38,12 @@ namespace BizHawk.Emulation.Common
/// </summary>
public abstract class VerifiedDisassembler : IDisassemblable
{
private string _cpu;
private string? _cpu;
/// <exception cref="ArgumentException">(from setter) <paramref name="value"/> isn't the name of an available CPU</exception>
public virtual string Cpu
{
get => _cpu;
get => _cpu ??= AvailableCpus.First();
set
{
if (!AvailableCpus.Contains(value))
@ -62,10 +60,5 @@ namespace BizHawk.Emulation.Common
public abstract string PCRegisterName { get; }
public abstract string Disassemble(MemoryDomain m, uint addr, out int length);
protected VerifiedDisassembler()
{
_cpu = AvailableCpus.First();
}
}
}

View File

@ -1,6 +1,4 @@
#nullable disable
using System;
using System;
using System.Collections.Generic;
using System.Linq;
@ -26,7 +24,7 @@ namespace BizHawk.Emulation.Common
public sealed class ServiceNotApplicableAttribute : Attribute
{
/// <remarks>TODO neither array nor <see cref="IEnumerable{T}"/> is the correct collection to be using here, try <see cref="IReadOnlyList{T}"/>/<see cref="IReadOnlyCollection{T}"/> instead</remarks>
public ServiceNotApplicableAttribute(Type[] types)
public ServiceNotApplicableAttribute(Type[]? types)
{
NotApplicableTypes = types?.AsEnumerable() ?? Enumerable.Empty<Type>();
}

View File

@ -1,6 +1,4 @@
#nullable disable
using System;
using System;
using System.Linq;
using BizHawk.Common.ReflectionExtensions;
@ -18,7 +16,7 @@ namespace BizHawk.Emulation.Common
public static void ClearServices(object target)
{
Type targetType = target.GetType();
object[] tmp = new object[1];
object?[] tmp = { null };
foreach (var propInfo in
targetType.GetPropertiesWithAttrib(typeof(RequiredServiceAttribute))
@ -35,7 +33,7 @@ namespace BizHawk.Emulation.Common
public static bool UpdateServices(IEmulatorServiceProvider source, object target)
{
Type targetType = target.GetType();
object[] tmp = new object[1];
object?[] tmp = new object?[1];
foreach (var propInfo in targetType.GetPropertiesWithAttrib(typeof(RequiredServiceAttribute)))
{

View File

@ -1,6 +1,4 @@
#nullable disable
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
namespace BizHawk.Emulation.Common

View File

@ -1,8 +1,5 @@
#nullable disable
using System;
using System;
using System.Collections.Generic;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Common
{

View File

@ -1,6 +1,4 @@
#nullable disable
using System.Collections.Generic;
using System.Collections.Generic;
using System.Drawing;
namespace BizHawk.Emulation.Common
@ -8,9 +6,13 @@ namespace BizHawk.Emulation.Common
public class PadSchema
{
public Size Size { get; set; }
public bool IsConsole { get; protected set; }
public IEnumerable<PadSchemaControl> Buttons { get; set; } = new List<PadSchemaControl>();
public string DisplayName { get; set; } // The name of the pad itself, presumably will be displayed by the given pad time if supplied
/// <summary>The name of the pad itself, presumably will be displayed by the given pad time if supplied</summary>
public string? DisplayName { get; set; }
}
public class ConsoleSchema : PadSchema