From 7977013799af4f840fe68e9afffa38bc22412f57 Mon Sep 17 00:00:00 2001 From: TollyH Date: Tue, 14 May 2024 00:47:25 +0100 Subject: [PATCH] Consistent %ANALYZER behaviour with final analyzers --- AssemblerWarnings.cs | 49 ++++++++++++++++++++++++++++++-------------- Test/KitchenSink.asm | 8 +------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/AssemblerWarnings.cs b/AssemblerWarnings.cs index ade61c0..7ca38ff 100644 --- a/AssemblerWarnings.cs +++ b/AssemblerWarnings.cs @@ -60,6 +60,12 @@ public partial class AssemblerWarnings public readonly HashSet DisabledWarnings = new(); public readonly HashSet DisabledSuggestions = new(); + // Store every line where each warning has been disabled so that final warning analyzers don't return warnings + // in places that have the warning disabled when the warning was since re-enabled. + private readonly Dictionary> disabledNonFatalErrorPositions = new(); + private readonly Dictionary> disabledWarningPositions = new(); + private readonly Dictionary> disabledSuggestionPositions = new(); + // Variables updated by parameters of the NextInstruction method private byte[] newBytes = Array.Empty(); private string mnemonic = ""; @@ -171,6 +177,7 @@ public Warning[] NextInstruction(byte[] newBytes, string mnemonic, string[] oper /// The name of the current macro being expanded, or if no macro is. public void NewLabel(string labelName, FilePosition filePosition, string? macroName) { + UpdateDisabledPositions(filePosition); labelDefinitionPositions[labelName] = (filePosition, macroName); } @@ -192,27 +199,18 @@ public Warning[] Finalize(byte[] finalProgram, ulong entryPoint, HashSet foreach ((int code, FinalWarningAnalyzer finalAnalyzer) in nonFatalErrorFinalAnalyzers) { - if (DisabledNonFatalErrors.Contains(code)) - { - continue; - } - warnings.AddRange(finalAnalyzer()); + warnings.AddRange(finalAnalyzer().Where(w => + !disabledNonFatalErrorPositions.GetValueOrDefault(code)?.Contains(w.Position) ?? true)); } foreach ((int code, FinalWarningAnalyzer finalAnalyzer) in warningFinalAnalyzers) { - if (DisabledWarnings.Contains(code)) - { - continue; - } - warnings.AddRange(finalAnalyzer()); + warnings.AddRange(finalAnalyzer().Where(w => + !disabledWarningPositions.GetValueOrDefault(code)?.Contains(w.Position) ?? true)); } foreach ((int code, FinalWarningAnalyzer finalAnalyzer) in suggestionFinalAnalyzers) { - if (DisabledSuggestions.Contains(code)) - { - continue; - } - warnings.AddRange(finalAnalyzer()); + warnings.AddRange(finalAnalyzer().Where(w => + !disabledSuggestionPositions.GetValueOrDefault(code)?.Contains(w.Position) ?? true)); } return warnings.ToArray(); @@ -335,6 +333,8 @@ public AssemblerWarnings(bool usingV1Format) private void PreAnalyzeStateUpdate() { + UpdateDisabledPositions(filePosition); + if (newBytes.Length > 0) { operandStart = 0; @@ -440,6 +440,25 @@ private void PostAnalyzeStateUpdate() lastMacroLineDepth = macroLineDepth; } + private void UpdateDisabledPositions(FilePosition filePosition) + { + foreach (int code in DisabledNonFatalErrors) + { + _ = disabledNonFatalErrorPositions.TryAdd(code, new HashSet()); + disabledNonFatalErrorPositions[code].Add(filePosition); + } + foreach (int code in DisabledWarnings) + { + _ = disabledWarningPositions.TryAdd(code, new HashSet()); + disabledWarningPositions[code].Add(filePosition); + } + foreach (int code in DisabledSuggestions) + { + _ = disabledSuggestionPositions.TryAdd(code, new HashSet()); + disabledSuggestionPositions[code].Add(filePosition); + } + } + // Analyzer methods // (Rolling = runs as each instruction is processed, Final = runs after all instructions have been processed) diff --git a/Test/KitchenSink.asm b/Test/KitchenSink.asm index dbc5305..a2b0c65 100644 --- a/Test/KitchenSink.asm +++ b/Test/KitchenSink.asm @@ -7,8 +7,8 @@ ; The exact binary output that this program should produce ; is located in KitchenSink.bin -; Disable unused label suggestion %ANALYZER suggestion, 0018, 0 +%ANALYZER suggestion, 0004, 0 MVQ rg0, 69 @@ -42,8 +42,6 @@ HLT %NUM @!CURRENT_ADDRESS -%ANALYZER suggestion, 0004, 0 - %DAT "Hello, world!\nEscape test complete\"Still string\0", %DAT 0x42 %NUM 1189998819991197253 @@ -64,10 +62,6 @@ this@LineIsNowBlank() %nUm :&NOR_DOES_THIS %NuM :&NOR_THIS -; Final analyzers currently can't be re-enabled without them showing again -; This should hopefully be changed in a future version -; %ANALYZER suggestion, 0004, r - %MACRO CFL, ASMX_CLF :thisLabelRemovesTheWarning CFL