From b968b151d0431f44bfe6d20cc030037785f18fc1 Mon Sep 17 00:00:00 2001 From: KallDrexx Date: Wed, 10 Sep 2025 21:30:08 -0400 Subject: [PATCH] Fix nullability warnings --- NESDecompiler.CLI/Program.cs | 2 +- NESDecompiler.Core/Decompilation/Decompiler.cs | 18 +++++++++--------- NESDecompiler.Core/Disassembly/Disassembler.cs | 10 +++++----- NESDecompiler.Core/ROM/ROMInfo.cs | 2 +- NESDecompiler.Core/ROM/ROMLoader.cs | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/NESDecompiler.CLI/Program.cs b/NESDecompiler.CLI/Program.cs index 9f2c13c..214deac 100644 --- a/NESDecompiler.CLI/Program.cs +++ b/NESDecompiler.CLI/Program.cs @@ -165,7 +165,7 @@ namespace NESDecompiler.CLI writer.WriteLine(" */"); writer.WriteLine(); - string guardName = Path.GetFileNameWithoutExtension(decompiler.ROMInfo.RawData[0].ToString()).ToUpper() + "_H"; + string guardName = Path.GetFileNameWithoutExtension(decompiler.ROMInfo.RawData![0].ToString()).ToUpper() + "_H"; writer.WriteLine($"#ifndef {guardName}"); writer.WriteLine($"#define {guardName}"); writer.WriteLine(); diff --git a/NESDecompiler.Core/Decompilation/Decompiler.cs b/NESDecompiler.Core/Decompilation/Decompiler.cs index 9de2f6e..b3c1ba2 100644 --- a/NESDecompiler.Core/Decompilation/Decompiler.cs +++ b/NESDecompiler.Core/Decompilation/Decompiler.cs @@ -1026,7 +1026,7 @@ namespace NESDecompiler.Core.Decompilation { // Process LDA, LDX, LDY string register = instruction.Info.Mnemonic.Substring(2); - string variableName = GetVariableName(instruction); + string? variableName = GetVariableName(instruction); if (variableName != null) { @@ -1046,7 +1046,7 @@ namespace NESDecompiler.Core.Decompilation { // Process STA, STX, STY string register = instruction.Info.Mnemonic.Substring(2); - string variableName = GetVariableName(instruction); + string? variableName = GetVariableName(instruction); if (variableName != null) { @@ -1314,7 +1314,7 @@ namespace NESDecompiler.Core.Decompilation private void GenerateArithmeticCode(DisassembledInstruction instruction, StringBuilder sb) { // Handle arithmetic operations: ADC, SBC - string operand = GetOperandString(instruction); + string? operand = GetOperandString(instruction); if (operand == null) return; @@ -1359,7 +1359,7 @@ namespace NESDecompiler.Core.Decompilation private void GenerateIncrementCode(DisassembledInstruction instruction, StringBuilder sb) { // Handle increment operations: INC, INX, INY - string operand = GetOperandString(instruction); + string? operand = GetOperandString(instruction); switch (instruction.Info.Mnemonic) { @@ -1393,7 +1393,7 @@ namespace NESDecompiler.Core.Decompilation private void GenerateDecrementCode(DisassembledInstruction instruction, StringBuilder sb) { // Handle decrement operations: DEC, DEX, DEY - string operand = GetOperandString(instruction); + string? operand = GetOperandString(instruction); switch (instruction.Info.Mnemonic) { @@ -1427,7 +1427,7 @@ namespace NESDecompiler.Core.Decompilation private void GenerateShiftCode(DisassembledInstruction instruction, StringBuilder sb) { // Handle shift operations: ASL, LSR, ROL, ROR - string operand; + string? operand; if (instruction.Info.AddressingMode == AddressingMode.Accumulator) { @@ -1489,7 +1489,7 @@ namespace NESDecompiler.Core.Decompilation private void GenerateLogicCode(DisassembledInstruction instruction, StringBuilder sb) { // Handle logic operations: AND, ORA, EOR, BIT - string operand = GetOperandString(instruction); + string? operand = GetOperandString(instruction); if (operand == null) return; @@ -1533,7 +1533,7 @@ namespace NESDecompiler.Core.Decompilation private void GenerateCompareCode(DisassembledInstruction instruction, StringBuilder sb) { // Handle compare operations: CMP, CPX, CPY - string operand = GetOperandString(instruction); + string? operand = GetOperandString(instruction); if (operand == null) return; @@ -1710,7 +1710,7 @@ namespace NESDecompiler.Core.Decompilation } } - private string GetOperandString(DisassembledInstruction instruction) + private string? GetOperandString(DisassembledInstruction instruction) { if (instruction.Info.AddressingMode == AddressingMode.Immediate) { diff --git a/NESDecompiler.Core/Disassembly/Disassembler.cs b/NESDecompiler.Core/Disassembly/Disassembler.cs index 4e22e5d..05f9d8e 100644 --- a/NESDecompiler.Core/Disassembly/Disassembler.cs +++ b/NESDecompiler.Core/Disassembly/Disassembler.cs @@ -25,17 +25,17 @@ namespace NESDecompiler.Core.Disassembly /// /// Information about this instruction's opcode /// - public InstructionInfo Info { get; set; } + public required InstructionInfo Info { get; init; } /// /// The raw bytes of this instruction (including operands) /// - public byte[] Bytes { get; set; } + public byte[]? Bytes { get; set; } /// /// The operand bytes of this instruction /// - public byte[] Operands => Bytes.Length > 1 ? Bytes[1..] : Array.Empty(); + public byte[] Operands => Bytes!.Length > 1 ? Bytes[1..] : Array.Empty(); /// /// The target address for branch and jump instructions @@ -85,7 +85,7 @@ namespace NESDecompiler.Core.Disassembly } sb.Append($"{CPUAddress:X4} "); - foreach (var b in Bytes) + foreach (var b in Bytes!) { sb.Append($"{b:X2} "); } @@ -398,7 +398,7 @@ namespace NESDecompiler.Core.Disassembly if (instruction.TargetAddress.HasValue) { ushort target = instruction.TargetAddress.Value; - if (labels.TryGetValue(target, out string label)) + if (labels.TryGetValue(target, out string? label)) { instruction.Comment = $"-> {label}"; } diff --git a/NESDecompiler.Core/ROM/ROMInfo.cs b/NESDecompiler.Core/ROM/ROMInfo.cs index 8070747..dc243bf 100644 --- a/NESDecompiler.Core/ROM/ROMInfo.cs +++ b/NESDecompiler.Core/ROM/ROMInfo.cs @@ -76,7 +76,7 @@ namespace NESDecompiler.Core.ROM /// /// The raw ROM data for reference /// - public byte[] RawData { get; set; } + public byte[]? RawData { get; set; } /// /// List of identified entry points (including reset vector and NMI) diff --git a/NESDecompiler.Core/ROM/ROMLoader.cs b/NESDecompiler.Core/ROM/ROMLoader.cs index c62e477..2057c69 100644 --- a/NESDecompiler.Core/ROM/ROMLoader.cs +++ b/NESDecompiler.Core/ROM/ROMLoader.cs @@ -21,13 +21,13 @@ namespace NESDecompiler.Core.ROM private const int FLAGS_10_OFFSET = 10; // ROM data - private byte[] romData; - private ROMInfo romInfo; + private byte[]? romData; + private ROMInfo? romInfo; /// /// Information about the loaded ROM /// - public ROMInfo ROMInfo => romInfo; + public ROMInfo? ROMInfo => romInfo; /// /// Loads a NES ROM file from disk @@ -75,7 +75,7 @@ namespace NESDecompiler.Core.ROM private ROMInfo ParseROMHeader() { // Verify iNES header signature "NES" followed by MS-DOS EOF - if (romData.Length < HEADER_SIZE || + if (romData!.Length < HEADER_SIZE || romData[0] != 0x4E || romData[1] != 0x45 || romData[2] != 0x53 || romData[3] != 0x1A) { throw new InvalidROMFormatException("Invalid iNES ROM header");