From 0c2bca29f1f042d10ca8e731b9fee6b4b142536f Mon Sep 17 00:00:00 2001 From: Eathox Date: Sat, 9 Nov 2024 22:28:12 +0100 Subject: [PATCH 1/3] Fix pw3_padded_arg_duplicates --- libs/preprocessor/src/processor/defines.rs | 12 +++++++++--- libs/preprocessor/tests/warnings.rs | 9 ++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libs/preprocessor/src/processor/defines.rs b/libs/preprocessor/src/processor/defines.rs index 6dfdd0d0..528c5e4b 100644 --- a/libs/preprocessor/src/processor/defines.rs +++ b/libs/preprocessor/src/processor/defines.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, sync::Arc}; use hemtt_workspace::{ position::Position, - reporting::{Output, Symbol, Token}, + reporting::{Code, Output, Symbol, Token}, }; use peekmore::{PeekMore, PeekMoreIterator}; @@ -238,12 +238,18 @@ impl Processor { { for token in [value.first(), value.last()] { if token.map_or(false, |t| t.symbol().is_whitespace()) { - self.warnings.push(Arc::new(PaddedArg::new( + let warning = PaddedArg::new( Box::new( (**token.expect("token exists from map_or check")).clone(), ), ident_string.clone(), - ))); + ); + + if !self.warnings.iter().any(|w| { + w.ident() == warning.ident() && w.token() == warning.token() + }) { + self.warnings.push(Arc::new(warning)); + } } } } diff --git a/libs/preprocessor/tests/warnings.rs b/libs/preprocessor/tests/warnings.rs index 300eadee..872ffdfa 100644 --- a/libs/preprocessor/tests/warnings.rs +++ b/libs/preprocessor/tests/warnings.rs @@ -35,11 +35,9 @@ fn check(dir: &str) { .unwrap(); let warning = config .warnings() - .first() - .unwrap() - .diagnostic() - .unwrap() - .to_string(&WorkspaceFiles::new()); + .iter() + .map(|w| w.diagnostic().unwrap().to_string(&WorkspaceFiles::new())) + .collect::(); if expected.is_empty() { std::fs::write(folder.join("stderr.ansi"), warning.replace('\r', "")).unwrap(); } @@ -66,3 +64,4 @@ bootstrap!(pw1_redefine); bootstrap!(pw1_redefine_stack); bootstrap!(pw3_padded_arg); bootstrap!(pw3_padded_arg_duplicates); +bootstrap!(pw3_padded_arg_inner); From b6e9a4a82f58634b48bce248acb6c215d523f686 Mon Sep 17 00:00:00 2001 From: Eathox Date: Sat, 9 Nov 2024 22:28:25 +0100 Subject: [PATCH 2/3] Add test for padded inner macros --- .../warnings/pw3_padded_arg_inner/source.hpp | 6 +++++ .../warnings/pw3_padded_arg_inner/stderr.ansi | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 libs/preprocessor/tests/warnings/pw3_padded_arg_inner/source.hpp create mode 100644 libs/preprocessor/tests/warnings/pw3_padded_arg_inner/stderr.ansi diff --git a/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/source.hpp b/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/source.hpp new file mode 100644 index 00000000..661f2eb9 --- /dev/null +++ b/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/source.hpp @@ -0,0 +1,6 @@ +#define HELLO(var1, var2) INNER(Hello, var1##var2) +#define GREET(var1, var2) INNER(Greetings, var1##var2) +#define INNER(var1, var2) var1 var2 + +value1 = HELLO(John,Smith); // Only inner +value2 = GREET(John, Smith); // Both call and inner diff --git a/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/stderr.ansi b/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/stderr.ansi new file mode 100644 index 00000000..89a3bb51 --- /dev/null +++ b/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/stderr.ansi @@ -0,0 +1,27 @@ +warning[PW3]: padding a macro argument + ┌─ source.hpp:1:39 + │ +1 │ #define HELLO(var1, var2) INNER(Hello, var1##var2) + │ ^ padding a macro argument + │ + = note: padding a macro argument is likely unintended + = note: occured in: `INNER` + +warning[PW3]: padding a macro argument + ┌─ source.hpp:6:21 + │ +6 │ value2 = GREET(John, Smith); // Both call and inner + │ ^ padding a macro argument + │ + = note: padding a macro argument is likely unintended + = note: occured in: `GREET` + +warning[PW3]: padding a macro argument + ┌─ source.hpp:2:43 + │ +2 │ #define GREET(var1, var2) INNER(Greetings, var1##var2) + │ ^ padding a macro argument + │ + = note: padding a macro argument is likely unintended + = note: occured in: `INNER` + From 8cbe9ffee1b38255183c5899a3601f1372e77abe Mon Sep 17 00:00:00 2001 From: Eathox Date: Sun, 10 Nov 2024 05:16:11 +0100 Subject: [PATCH 3/3] Attempt to clarify pw3_padded_arg_inner test I saw your comment Brett, before you deleted it, hopefully this makes it slightly clearer at what my intention was and with this test and why there are two identical macros defined. --- .../warnings/pw3_padded_arg_inner/source.hpp | 8 ++++---- .../warnings/pw3_padded_arg_inner/stderr.ansi | 20 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/source.hpp b/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/source.hpp index 661f2eb9..f6f9eae8 100644 --- a/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/source.hpp +++ b/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/source.hpp @@ -1,6 +1,6 @@ -#define HELLO(var1, var2) INNER(Hello, var1##var2) -#define GREET(var1, var2) INNER(Greetings, var1##var2) +#define TEST1(var1, var2) INNER(var1, var2) +#define TEST2(var1, var2) INNER(var1, var2) // Separate macro to trigger unique warning for INNER padding #define INNER(var1, var2) var1 var2 -value1 = HELLO(John,Smith); // Only inner -value2 = GREET(John, Smith); // Both call and inner +TEST1(John,Smith); // Only inner +TEST2(John, Smith); // Both call and inner diff --git a/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/stderr.ansi b/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/stderr.ansi index 89a3bb51..feb57506 100644 --- a/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/stderr.ansi +++ b/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/stderr.ansi @@ -1,26 +1,26 @@ warning[PW3]: padding a macro argument - ┌─ source.hpp:1:39 + ┌─ source.hpp:1:38 │ -1 │ #define HELLO(var1, var2) INNER(Hello, var1##var2) - │ ^ padding a macro argument +1 │ #define TEST1(var1, var2) INNER(var1, var2) + │ ^ padding a macro argument │ = note: padding a macro argument is likely unintended = note: occured in: `INNER` warning[PW3]: padding a macro argument - ┌─ source.hpp:6:21 + ┌─ source.hpp:6:12 │ -6 │ value2 = GREET(John, Smith); // Both call and inner - │ ^ padding a macro argument +6 │ TEST2(John, Smith); // Both call and inner + │ ^ padding a macro argument │ = note: padding a macro argument is likely unintended - = note: occured in: `GREET` + = note: occured in: `TEST2` warning[PW3]: padding a macro argument - ┌─ source.hpp:2:43 + ┌─ source.hpp:2:38 │ -2 │ #define GREET(var1, var2) INNER(Greetings, var1##var2) - │ ^ padding a macro argument +2 │ #define TEST2(var1, var2) INNER(var1, var2) // Separate macro to trigger unique warning for INNER padding + │ ^ padding a macro argument │ = note: padding a macro argument is likely unintended = note: occured in: `INNER`