]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Spurious style error with mutiple square brackets
authorJustin Squirek <squirek@adacore.com>
Thu, 9 May 2024 20:16:24 +0000 (20:16 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Fri, 21 Jun 2024 08:34:17 +0000 (10:34 +0200)
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.

gcc/ada/csets.adb
gcc/ada/csets.ads
gcc/ada/opt.adb

index 7e5af3ffa1714d72305917d4f2b3435e8bd04def..54ebdb46b6cd76a8bee4a0f0a3fb12466bc1d85a 100644 (file)
@@ -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;
 
index 9dc78ba10e87bc2050e41d0b2acffd6551c9276f..f0930df47dbe9b808b804ddc47536567497e0695 100644 (file)
@@ -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;
index 5427a95a3b68b4292ec4261a91ef6e1f5704ce1c..8598ce234cc7e16e5ec059c6e0162cc6bdedc545 100644 (file)
@@ -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.