public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-347] [Ada] Fix style checking rule for square brackets in Ada 2022 and above
@ 2022-05-12 12:40 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-05-12 12:40 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7a4892d2279066f5892a2b6a8c511689631d8f09

commit r13-347-g7a4892d2279066f5892a2b6a8c511689631d8f09
Author: Marc Poulhiès <poulhies@adacore.com>
Date:   Fri Jan 28 16:55:43 2022 +0100

    [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.

Diff:
---
 gcc/ada/csets.adb            | 11 ++++++-----
 gcc/ada/libgnat/a-swmwco.ads | 24 ++++++++++++------------
 gcc/ada/libgnat/a-szmzco.ads | 24 ++++++++++++------------
 gcc/ada/opt.adb              |  3 +++
 gcc/ada/scng.adb             |  7 ++++++-
 gcc/ada/style.ads            |  7 ++++---
 gcc/ada/styleg.adb           | 11 ++++++-----
 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 d36b815e527..bd2ba928661 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 af11630226c..ed377187f21 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 96d64b36058..e8de549382f 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 49e03b01826..ae6b844052e 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 c50a41e94dc..cd10d1d4497 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 814bb2bcb19..209dff851ee 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 205bad03d7c..6a785b5835a 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 116d6ef654e..23a1ee4b86f 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-12 12:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-12 12:40 [gcc r13-347] [Ada] Fix style checking rule for square brackets in Ada 2022 and above Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).