From cd4d7a89a4f70d0116aca815b3887d658c60ce36 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Wed, 1 Dec 2021 06:19:10 +1000 Subject: [PATCH] More nullability --- .../Api/Classes/EmulationApi.cs | 2 +- src/BizHawk.Client.Common/CoreFileProvider.cs | 12 +++++++----- .../BasicServiceProvider.cs | 19 +++++-------------- .../CallbackBasedTraceBuffer.cs | 10 +++++----- .../InputCallbackSystem.cs | 6 ++---- .../MemoryBasedInputCallbackSystem.cs | 9 +-------- .../Base Implementations/NullSound.cs | 4 +--- .../Base Implementations/NullVideo.cs | 4 +--- .../SimpleSyncSoundProvider.cs | 4 +--- src/BizHawk.Emulation.Common/CoreComms.cs | 4 +--- .../Interfaces/ICoreFileProvider.cs | 10 ++++------ .../Interfaces/IEmulatorServiceProvider.cs | 8 +++----- .../Interfaces/IInputCallbackSystem.cs | 4 +--- .../Interfaces/Services/IDisassemblable.cs | 13 +++---------- .../ServiceAttributes.cs | 6 ++---- .../ServiceInjector.cs | 8 +++----- src/BizHawk.Emulation.Common/SystemLookup.cs | 4 +--- .../vpads_schemata/IVirtualPadSchema.cs | 5 +---- .../vpads_schemata/PadSchema.cs | 10 ++++++---- 19 files changed, 49 insertions(+), 93 deletions(-) diff --git a/src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs b/src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs index f671c2ee15..59038831bd 100644 --- a/src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs @@ -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 ), diff --git a/src/BizHawk.Client.Common/CoreFileProvider.cs b/src/BizHawk.Client.Common/CoreFileProvider.cs index 96baf54009..a85b00a18f 100644 --- a/src/BizHawk.Client.Common/CoreFileProvider.cs +++ b/src/BizHawk.Client.Common/CoreFileProvider.cs @@ -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)); diff --git a/src/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs b/src/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs index bce7a13a55..f3427a50ba 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs @@ -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 /// The to register /// is null public void Register(T provider) - where T : IEmulatorService + where T : class, IEmulatorService { - if (provider == null) - { - throw new ArgumentNullException(nameof(provider)); - } - _services[typeof(T)] = provider; } public T GetService() 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; } diff --git a/src/BizHawk.Emulation.Common/Base Implementations/CallbackBasedTraceBuffer.cs b/src/BizHawk.Emulation.Common/Base Implementations/CallbackBasedTraceBuffer.cs index c57fbccb90..3ffc681755 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/CallbackBasedTraceBuffer.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/CallbackBasedTraceBuffer.cs @@ -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 } } diff --git a/src/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs b/src/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs index 5588be99ad..ed67e782b0 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs @@ -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) { diff --git a/src/BizHawk.Emulation.Common/Base Implementations/MemoryBasedInputCallbackSystem.cs b/src/BizHawk.Emulation.Common/Base Implementations/MemoryBasedInputCallbackSystem.cs index 068cc60b1f..df0f759844 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/MemoryBasedInputCallbackSystem.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/MemoryBasedInputCallbackSystem.cs @@ -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 addresses) { - if (addresses == null) - { - throw new ArgumentException($"{nameof(addresses)} cannot be null."); - } - if (!debuggableCore.MemoryCallbacksAvailable()) { throw new InvalidOperationException("Memory callbacks are required"); diff --git a/src/BizHawk.Emulation.Common/Base Implementations/NullSound.cs b/src/BizHawk.Emulation.Common/Base Implementations/NullSound.cs index ca2b047618..685f16358c 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/NullSound.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/NullSound.cs @@ -1,6 +1,4 @@ -#nullable disable - -using System; +using System; namespace BizHawk.Emulation.Common { diff --git a/src/BizHawk.Emulation.Common/Base Implementations/NullVideo.cs b/src/BizHawk.Emulation.Common/Base Implementations/NullVideo.cs index 33c03b1b12..309fa086cd 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/NullVideo.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/NullVideo.cs @@ -1,6 +1,4 @@ -#nullable disable - -namespace BizHawk.Emulation.Common +namespace BizHawk.Emulation.Common { /// /// A default IVideoProvider that simply returns diff --git a/src/BizHawk.Emulation.Common/Base Implementations/SimpleSyncSoundProvider.cs b/src/BizHawk.Emulation.Common/Base Implementations/SimpleSyncSoundProvider.cs index 05058925d4..9fa040d2b4 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/SimpleSyncSoundProvider.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/SimpleSyncSoundProvider.cs @@ -1,6 +1,4 @@ -#nullable disable - -using System; +using System; namespace BizHawk.Emulation.Common.Base_Implementations { diff --git a/src/BizHawk.Emulation.Common/CoreComms.cs b/src/BizHawk.Emulation.Common/CoreComms.cs index fb11ca3d08..2bdb2fb4bb 100644 --- a/src/BizHawk.Emulation.Common/CoreComms.cs +++ b/src/BizHawk.Emulation.Common/CoreComms.cs @@ -1,6 +1,4 @@ -#nullable disable - -using System; +using System; namespace BizHawk.Emulation.Common { diff --git a/src/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs b/src/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs index 8716e36ec0..32fc6c8b29 100644 --- a/src/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs +++ b/src/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs @@ -1,6 +1,4 @@ -#nullable disable - -namespace BizHawk.Emulation.Common +namespace BizHawk.Emulation.Common { /// /// 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 /// warning message to show on failure /// iff failed - byte[] GetFirmware(FirmwareID id, string msg = null); + byte[]? GetFirmware(FirmwareID id, string? msg = null); /// exception message to show on failure /// if not found - byte[] GetFirmwareOrThrow(FirmwareID id, string msg = null); + byte[] GetFirmwareOrThrow(FirmwareID id, string? msg = null); /// exception message to show on failure /// if not found /// only used in PCEHawk - (byte[] FW, GameInfo Game) GetFirmwareWithGameInfoOrThrow(FirmwareID id, string msg = null); + (byte[] FW, GameInfo Game) GetFirmwareWithGameInfoOrThrow(FirmwareID id, string? msg = null); } } diff --git a/src/BizHawk.Emulation.Common/Interfaces/IEmulatorServiceProvider.cs b/src/BizHawk.Emulation.Common/Interfaces/IEmulatorServiceProvider.cs index 18b2a12a5e..04161897cc 100644 --- a/src/BizHawk.Emulation.Common/Interfaces/IEmulatorServiceProvider.cs +++ b/src/BizHawk.Emulation.Common/Interfaces/IEmulatorServiceProvider.cs @@ -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 /// /// Returns an instance of T if T is available - /// Else returns null + /// Else throws NRE /// /// The requested T GetService() where T : IEmulatorService; @@ -38,7 +36,7 @@ namespace BizHawk.Emulation.Common /// Returns an instance of t if t is available /// Else returns null /// - object GetService(Type t); + object? GetService(Type t); /// /// Gets a list of all currently registered services available to be retrieved diff --git a/src/BizHawk.Emulation.Common/Interfaces/IInputCallbackSystem.cs b/src/BizHawk.Emulation.Common/Interfaces/IInputCallbackSystem.cs index 2ebc287991..0dba96cbb0 100644 --- a/src/BizHawk.Emulation.Common/Interfaces/IInputCallbackSystem.cs +++ b/src/BizHawk.Emulation.Common/Interfaces/IInputCallbackSystem.cs @@ -1,6 +1,4 @@ -#nullable disable - -using System; +using System; using System.Collections.Generic; namespace BizHawk.Emulation.Common diff --git a/src/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs b/src/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs index 8fea39a8d4..cc5cd83938 100644 --- a/src/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs +++ b/src/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs @@ -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 /// public abstract class VerifiedDisassembler : IDisassemblable { - private string _cpu; + private string? _cpu; /// (from setter) isn't the name of an available CPU 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(); - } } } diff --git a/src/BizHawk.Emulation.Common/ServiceAttributes.cs b/src/BizHawk.Emulation.Common/ServiceAttributes.cs index d7de7b7755..442cb9f9c0 100644 --- a/src/BizHawk.Emulation.Common/ServiceAttributes.cs +++ b/src/BizHawk.Emulation.Common/ServiceAttributes.cs @@ -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 { /// TODO neither array nor is the correct collection to be using here, try / instead - public ServiceNotApplicableAttribute(Type[] types) + public ServiceNotApplicableAttribute(Type[]? types) { NotApplicableTypes = types?.AsEnumerable() ?? Enumerable.Empty(); } diff --git a/src/BizHawk.Emulation.Common/ServiceInjector.cs b/src/BizHawk.Emulation.Common/ServiceInjector.cs index ec7ba20fca..781945c90b 100644 --- a/src/BizHawk.Emulation.Common/ServiceInjector.cs +++ b/src/BizHawk.Emulation.Common/ServiceInjector.cs @@ -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))) { diff --git a/src/BizHawk.Emulation.Common/SystemLookup.cs b/src/BizHawk.Emulation.Common/SystemLookup.cs index 78c02690e9..fc3597cde1 100644 --- a/src/BizHawk.Emulation.Common/SystemLookup.cs +++ b/src/BizHawk.Emulation.Common/SystemLookup.cs @@ -1,6 +1,4 @@ -#nullable disable - -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; namespace BizHawk.Emulation.Common diff --git a/src/BizHawk.Emulation.Common/vpads_schemata/IVirtualPadSchema.cs b/src/BizHawk.Emulation.Common/vpads_schemata/IVirtualPadSchema.cs index 7e70178b38..711b5b8d8f 100644 --- a/src/BizHawk.Emulation.Common/vpads_schemata/IVirtualPadSchema.cs +++ b/src/BizHawk.Emulation.Common/vpads_schemata/IVirtualPadSchema.cs @@ -1,8 +1,5 @@ -#nullable disable - -using System; +using System; using System.Collections.Generic; -using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Common { diff --git a/src/BizHawk.Emulation.Common/vpads_schemata/PadSchema.cs b/src/BizHawk.Emulation.Common/vpads_schemata/PadSchema.cs index c0b498ed5d..55da9ae1c2 100644 --- a/src/BizHawk.Emulation.Common/vpads_schemata/PadSchema.cs +++ b/src/BizHawk.Emulation.Common/vpads_schemata/PadSchema.cs @@ -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 Buttons { get; set; } = new List(); - public string DisplayName { get; set; } // The name of the pad itself, presumably will be displayed by the given pad time if supplied + + /// The name of the pad itself, presumably will be displayed by the given pad time if supplied + public string? DisplayName { get; set; } } public class ConsoleSchema : PadSchema