From: Justin Squirek <squi...@adacore.com>

This patch fixes a spurious error in the compiler when checking for style for
token separation where two square brackets are next to each other.

gcc/ada/

        * csets.ads (Identifier_Char): New function - replacing table.
        * csets.adb (Identifier_Char): Rename and move table for static values.
        (Initialize): Remove dynamic calculations.
        (Identifier_Char): New function to calculate dynamic values.
        * opt.adb (Set_Config_Switches): Remove setting of Identifier_Char.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/csets.adb | 46 ++++++++++++++++++++++++++++++++++++----------
 gcc/ada/csets.ads | 14 +++++++-------
 gcc/ada/opt.adb   |  3 ---
 3 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/gcc/ada/csets.adb b/gcc/ada/csets.adb
index 7e5af3ffa17..54ebdb46b6c 100644
--- a/gcc/ada/csets.adb
+++ b/gcc/ada/csets.adb
@@ -29,6 +29,12 @@ with System.WCh_Con; use System.WCh_Con;
 
 package body Csets is
 
+   Identifier_Char_Table : Char_Array_Flags;
+   --  This table contains all statically known characters which can appear in
+   --  identifiers, but excludes characters which need to be known dynamically,
+   --  for example like those that depend on the current Ada version which may
+   --  change from file to file.
+
    X_80 : constant Character := Character'Val (16#80#);
    X_81 : constant Character := Character'Val (16#81#);
    X_82 : constant Character := Character'Val (16#82#);
@@ -1085,6 +1091,34 @@ package body Csets is
 
       others => ' ');
 
+   ---------------------
+   -- Identifier_Char --
+   ---------------------
+
+   function Identifier_Char (Item : Character) return Boolean is
+   begin
+      --  Handle explicit dynamic cases
+
+      case Item is
+
+         --  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.
+
+         when '[' | ']' =>
+            return Ada_Version < Ada_2022;
+
+         --  Otherwise, this is a static case - use the table
+
+         when others =>
+            return Identifier_Char_Table (Item);
+      end case;
+   end Identifier_Char;
+
    ----------------
    -- Initialize --
    ----------------
@@ -1144,24 +1178,16 @@ package body Csets is
       --  Build Identifier_Char table from used entries of Fold_Upper
 
       for J in Character loop
-         Identifier_Char (J) := (Fold_Upper (J) /= ' ');
+         Identifier_Char_Table (J) := (Fold_Upper (J) /= ' ');
       end loop;
 
-      --  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 ('[') := 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.
 
       if Identifier_Character_Set = 'w'
         and then Wide_Character_Encoding_Method in WC_ESC_Encoding_Method
       then
-         Identifier_Char (ASCII.ESC) := True;
+         Identifier_Char_Table (ASCII.ESC) := True;
       end if;
    end Initialize;
 
diff --git a/gcc/ada/csets.ads b/gcc/ada/csets.ads
index 9dc78ba10e8..f0930df47db 100644
--- a/gcc/ada/csets.ads
+++ b/gcc/ada/csets.ads
@@ -80,12 +80,12 @@ package Csets is
    Fold_Lower : Translate_Table;
    --  Table to fold upper case identifier letters to lower case
 
-   Identifier_Char : Char_Array_Flags;
-   --  This table has True entries for all characters that can legally appear
-   --  in identifiers, including digits, the underline character, all letters
-   --  including upper and lower case and extended letters (as controlled by
-   --  the setting of Opt.Identifier_Character_Set), left bracket for brackets
-   --  notation wide characters and also ESC if wide characters are permitted
-   --  in identifiers using escape sequences starting with ESC.
+   function Identifier_Char (Item : Character) return Boolean;
+   --  Return True for all characters that can legally appear in identifiers,
+   --  including digits, the underline character, all letters including upper
+   --  and lower case and extended letters (as controlled by the setting of
+   --  Opt.Identifier_Character_Set), left bracket for brackets notation wide
+   --  characters and also ESC if wide characters are permitted in identifiers
+   --  using escape sequences starting with ESC.
 
 end Csets;
diff --git a/gcc/ada/opt.adb b/gcc/ada/opt.adb
index 5427a95a3b6..8598ce234cc 100644
--- a/gcc/ada/opt.adb
+++ b/gcc/ada/opt.adb
@@ -23,8 +23,6 @@
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with Csets;          use Csets;
-
 package body Opt is
 
    --------------------
@@ -188,7 +186,6 @@ 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.
-- 
2.45.1

Reply via email to