diff options
author | Marc Poulhiès <poulhies@adacore.com> | 2022-01-28 16:55:43 +0100 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2022-05-12 12:38:34 +0000 |
commit | 7a4892d2279066f5892a2b6a8c511689631d8f09 (patch) | |
tree | 6becd5efcffef1731fcb790743d195b61624920b | |
parent | b9cff88ca79664ade8bd1c870d01b56f8599afa4 (diff) | |
download | gcc-7a4892d2279066f5892a2b6a8c511689631d8f09.zip gcc-7a4892d2279066f5892a2b6a8c511689631d8f09.tar.gz gcc-7a4892d2279066f5892a2b6a8c511689631d8f09.tar.bz2 |
[Ada] Fix style checking rule for square brackets in Ada 2022 and above
The square bracket syntax introduced in Ada 2022 was incorrectly handled
by the style checker and incorrect spacing was enforced. The issue was
in part caused by the wide character syntax (support removed starting
from Ada 2022) that treats the square bracket as a valid identifier
character.
gcc/ada/
* csets.adb (Initialize): Only treat square bracket as valid
identifier character for Ada versions prior to Ada 2022.
* style.ads (Check_Left_Paren): Rename...
(Check_Left_Paren_Square_Bracket): ...to this.
* styleg.adb (Check_Left_Bracket): Rename...
(Check_Left_Paren_Square_Bracket): ...to this.
* styleg.ads (Check_Left_Paren): Rename...
(Check_Left_Paren_Square_Bracket): ...to this.
* scng.adb (Scan): Add check for spacing around left square
bracket and use new name for Check_Left_Paren_Square_Bracket.
* libgnat/a-szmzco.ads (Control_Ranges, Graphic_Ranges)
(Letter_Ranges, Decimal_Digit_Ranges, ISO_646_Ranges)
(Character_Ranges): Fix style (remove extra space).
* libgnat/a-swmwco.ads (Control_Ranges, Graphic_Ranges)
(Letter_Ranges, Decimal_Digit_Ranges, ISO_646_Ranges)
(Character_Ranges): Likewise.
* opt.adb (Set_Config_Switches): Remove [ from Identifier_Char
set.
-rw-r--r-- | gcc/ada/csets.adb | 11 | ||||
-rw-r--r-- | gcc/ada/libgnat/a-swmwco.ads | 24 | ||||
-rw-r--r-- | gcc/ada/libgnat/a-szmzco.ads | 24 | ||||
-rw-r--r-- | gcc/ada/opt.adb | 3 | ||||
-rw-r--r-- | gcc/ada/scng.adb | 7 | ||||
-rw-r--r-- | gcc/ada/style.ads | 7 | ||||
-rw-r--r-- | gcc/ada/styleg.adb | 11 | ||||
-rw-r--r-- | gcc/ada/styleg.ads | 5 |
8 files changed, 52 insertions, 40 deletions
diff --git a/gcc/ada/csets.adb b/gcc/ada/csets.adb index d36b815..bd2ba92 100644 --- a/gcc/ada/csets.adb +++ b/gcc/ada/csets.adb @@ -1145,12 +1145,13 @@ package body Csets is Identifier_Char (J) := (Fold_Upper (J) /= ' '); end loop; - -- Always add [ as an identifier character to deal with the brackets - -- notation for wide characters used in identifiers. Note that if - -- we are not allowing wide characters in identifiers, then any use - -- of this notation will be flagged as an error in Scan_Identifier. + -- Add [ as an identifier character to deal with the brackets notation + -- for wide characters used in identifiers for versions up to Ada 2012. + -- Note that if we are not allowing wide characters in identifiers, then + -- any use of this notation will be flagged as an error in + -- Scan_Identifier. - Identifier_Char ('[') := True; + Identifier_Char ('[') := Ada_Version < Ada_2022; -- Add entry for ESC if wide characters in use with a wide character -- encoding method active that uses the ESC code for encoding. diff --git a/gcc/ada/libgnat/a-swmwco.ads b/gcc/ada/libgnat/a-swmwco.ads index af11630..ed37718 100644 --- a/gcc/ada/libgnat/a-swmwco.ads +++ b/gcc/ada/libgnat/a-swmwco.ads @@ -66,27 +66,27 @@ private subtype WC is Wide_Character; Control_Ranges : aliased constant Wide_Character_Ranges := - [ (W.NUL, W.US), - (W.DEL, W.APC)]; + [(W.NUL, W.US), + (W.DEL, W.APC)]; Control_Set : constant Wide_Character_Set := (AF.Controlled with Control_Ranges'Unrestricted_Access); Graphic_Ranges : aliased constant Wide_Character_Ranges := - [ (W.Space, W.Tilde), - (WC'Val (256), WC'Last)]; + [(W.Space, W.Tilde), + (WC'Val (256), WC'Last)]; Graphic_Set : constant Wide_Character_Set := (AF.Controlled with Graphic_Ranges'Unrestricted_Access); Letter_Ranges : aliased constant Wide_Character_Ranges := - [ ('A', 'Z'), - (W.LC_A, W.LC_Z), - (W.UC_A_Grave, W.UC_O_Diaeresis), - (W.UC_O_Oblique_Stroke, W.LC_O_Diaeresis), - (W.LC_O_Oblique_Stroke, W.LC_Y_Diaeresis)]; + [('A', 'Z'), + (W.LC_A, W.LC_Z), + (W.UC_A_Grave, W.UC_O_Diaeresis), + (W.UC_O_Oblique_Stroke, W.LC_O_Diaeresis), + (W.LC_O_Oblique_Stroke, W.LC_Y_Diaeresis)]; Letter_Set : constant Wide_Character_Set := (AF.Controlled with @@ -126,7 +126,7 @@ private Basic_Ranges'Unrestricted_Access); Decimal_Digit_Ranges : aliased constant Wide_Character_Ranges := - [ ('0', '9')]; + [('0', '9')]; Decimal_Digit_Set : constant Wide_Character_Set := (AF.Controlled with @@ -167,14 +167,14 @@ private Special_Graphic_Ranges'Unrestricted_Access); ISO_646_Ranges : aliased constant Wide_Character_Ranges := - [ (W.NUL, W.DEL)]; + [(W.NUL, W.DEL)]; ISO_646_Set : constant Wide_Character_Set := (AF.Controlled with ISO_646_Ranges'Unrestricted_Access); Character_Ranges : aliased constant Wide_Character_Ranges := - [ (W.NUL, WC'Val (255))]; + [(W.NUL, WC'Val (255))]; Character_Set : constant Wide_Character_Set := (AF.Controlled with diff --git a/gcc/ada/libgnat/a-szmzco.ads b/gcc/ada/libgnat/a-szmzco.ads index 96d64b3..e8de549 100644 --- a/gcc/ada/libgnat/a-szmzco.ads +++ b/gcc/ada/libgnat/a-szmzco.ads @@ -66,27 +66,27 @@ private subtype WC is Wide_Wide_Character; Control_Ranges : aliased constant Wide_Wide_Character_Ranges := - [ (W.NUL, W.US), - (W.DEL, W.APC)]; + [(W.NUL, W.US), + (W.DEL, W.APC)]; Control_Set : constant Wide_Wide_Character_Set := (AF.Controlled with Control_Ranges'Unrestricted_Access); Graphic_Ranges : aliased constant Wide_Wide_Character_Ranges := - [ (W.Space, W.Tilde), - (WC'Val (256), WC'Last)]; + [(W.Space, W.Tilde), + (WC'Val (256), WC'Last)]; Graphic_Set : constant Wide_Wide_Character_Set := (AF.Controlled with Graphic_Ranges'Unrestricted_Access); Letter_Ranges : aliased constant Wide_Wide_Character_Ranges := - [ ('A', 'Z'), - (W.LC_A, W.LC_Z), - (W.UC_A_Grave, W.UC_O_Diaeresis), - (W.UC_O_Oblique_Stroke, W.LC_O_Diaeresis), - (W.LC_O_Oblique_Stroke, W.LC_Y_Diaeresis)]; + [('A', 'Z'), + (W.LC_A, W.LC_Z), + (W.UC_A_Grave, W.UC_O_Diaeresis), + (W.UC_O_Oblique_Stroke, W.LC_O_Diaeresis), + (W.LC_O_Oblique_Stroke, W.LC_Y_Diaeresis)]; Letter_Set : constant Wide_Wide_Character_Set := (AF.Controlled with @@ -126,7 +126,7 @@ private Basic_Ranges'Unrestricted_Access); Decimal_Digit_Ranges : aliased constant Wide_Wide_Character_Ranges := - [ ('0', '9')]; + [('0', '9')]; Decimal_Digit_Set : constant Wide_Wide_Character_Set := (AF.Controlled with @@ -167,14 +167,14 @@ private Special_Graphic_Ranges'Unrestricted_Access); ISO_646_Ranges : aliased constant Wide_Wide_Character_Ranges := - [ (W.NUL, W.DEL)]; + [(W.NUL, W.DEL)]; ISO_646_Set : constant Wide_Wide_Character_Set := (AF.Controlled with ISO_646_Ranges'Unrestricted_Access); Character_Ranges : aliased constant Wide_Wide_Character_Ranges := - [ (W.NUL, WC'Val (255))]; + [(W.NUL, WC'Val (255))]; Character_Set : constant Wide_Wide_Character_Set := (AF.Controlled with diff --git a/gcc/ada/opt.adb b/gcc/ada/opt.adb index 49e03b0..ae6b844 100644 --- a/gcc/ada/opt.adb +++ b/gcc/ada/opt.adb @@ -23,6 +23,8 @@ -- -- ------------------------------------------------------------------------------ +with Csets; use Csets; + package body Opt is ------------------------- @@ -210,6 +212,7 @@ package body Opt is Prefix_Exception_Messages := True; Uneval_Old := 'E'; Use_VADS_Size := False; + Identifier_Char ('[') := False; -- Note: we do not need to worry about Warnings_As_Errors_Count since -- we do not expect to get any warnings from compiling such a unit. diff --git a/gcc/ada/scng.adb b/gcc/ada/scng.adb index c50a41e..cd10d1d 100644 --- a/gcc/ada/scng.adb +++ b/gcc/ada/scng.adb @@ -1421,7 +1421,7 @@ package body Scng is Token := Tok_Left_Paren; if Style_Check then - Style.Check_Left_Paren; + Style.Check_Left_Paren_Square_Bracket; end if; return; @@ -1437,6 +1437,11 @@ package body Scng is if Ada_Version >= Ada_2022 then Scan_Ptr := Scan_Ptr + 1; Token := Tok_Left_Bracket; + + if Style_Check then + Style.Check_Left_Paren_Square_Bracket; + end if; + return; elsif Source (Scan_Ptr + 1) = '"' then diff --git a/gcc/ada/style.ads b/gcc/ada/style.ads index 814bb2b..209dff8 100644 --- a/gcc/ada/style.ads +++ b/gcc/ada/style.ads @@ -147,9 +147,10 @@ package Style is -- is that the starting column is appropriate to the indentation rules if -- Token_Ptr is the first token on the line. - procedure Check_Left_Paren - renames Style_Inst.Check_Left_Paren; - -- Called after scanning out a left parenthesis to check spacing + procedure Check_Left_Paren_Square_Bracket + renames Style_Inst.Check_Left_Paren_Square_Bracket; + -- Called after scanning out a left parenthesis to check spacing. If + -- Ada_Version >= Ada_2022 then called similarly for a left square bracket. procedure Check_Line_Terminator (Len : Int) renames Style_Inst.Check_Line_Terminator; diff --git a/gcc/ada/styleg.adb b/gcc/ada/styleg.adb index 205bad0..6a785b5 100644 --- a/gcc/ada/styleg.adb +++ b/gcc/ada/styleg.adb @@ -721,15 +721,16 @@ package body Styleg is end if; end Check_Indentation; - ---------------------- - -- Check_Left_Paren -- - ---------------------- + ------------------------------------- + -- Check_Left_Paren_Square_Bracket -- + ------------------------------------- -- In check token mode (-gnatyt), left paren must not be preceded by an -- identifier character or digit (a separating space is required) and may -- never be followed by a space. + -- Same applies for the left square bracket starting from Ada version 2022. - procedure Check_Left_Paren is + procedure Check_Left_Paren_Square_Bracket is begin if Style_Check_Tokens then if Token_Ptr > Source_First (Current_Source_File) @@ -740,7 +741,7 @@ package body Styleg is Check_No_Space_After; end if; - end Check_Left_Paren; + end Check_Left_Paren_Square_Bracket; --------------------------- -- Check_Line_Max_Length -- diff --git a/gcc/ada/styleg.ads b/gcc/ada/styleg.ads index 116d6ef..23a1ee4 100644 --- a/gcc/ada/styleg.ads +++ b/gcc/ada/styleg.ads @@ -111,8 +111,9 @@ package Styleg is -- is that the starting column is appropriate to the indentation rules if -- Token_Ptr is the first token on the line. - procedure Check_Left_Paren; - -- Called after scanning out a left parenthesis to check spacing + procedure Check_Left_Paren_Square_Bracket; + -- Called after scanning out a left parenthesis to check spacing. If + -- Ada_Version >= Ada_2022 then called similarly for a left square bracket. procedure Check_Line_Max_Length (Len : Nat); -- Called with Scan_Ptr pointing to the first line terminator character |