public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED 01/22] ada: Spurious style error with mutiple square brackets
@ 2024-06-21  8:57 Marc Poulhiès
  2024-06-21  8:57 ` [COMMITTED 02/22] ada: Fix for Default_Component_Value with declare expressions Marc Poulhiès
                   ` (20 more replies)
  0 siblings, 21 replies; 22+ messages in thread
From: Marc Poulhiès @ 2024-06-21  8:57 UTC (permalink / raw)
  To: gcc-patches; +Cc: Justin Squirek

From: Justin Squirek <squirek@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


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2024-06-21  8:58 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-21  8:57 [COMMITTED 01/22] ada: Spurious style error with mutiple square brackets Marc Poulhiès
2024-06-21  8:57 ` [COMMITTED 02/22] ada: Fix for Default_Component_Value with declare expressions Marc Poulhiès
2024-06-21  8:57 ` [COMMITTED 03/22] ada: Fix assertion failure on predicate involving access parameter Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 04/22] ada: Predefined arithmetic operators incorrectly treated as directly visible Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 05/22] ada: Fix gnatcheck violation reported after a recent cleanup Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 06/22] ada: Generic formal/actual matching -- misc cleanup Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 07/22] ada: Fix incorrect handling of packed array with aliased composite components Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 08/22] ada: Fix internal error on case expression used as index of array component Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 09/22] ada: Fix missing index check with declare expression Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 10/22] ada: Cannot override inherited function with controlling result Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 11/22] ada: Revert conditional installation of signal handlers on VxWorks Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 12/22] ada: Small cleanup in processing of primitive operations Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 13/22] ada: Change error message on invalid RTS path Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 14/22] ada: Crash when using user defined string literals Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 15/22] ada: Fix crash in GNATbind during error reporting Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 16/22] ada: Apply fixes to Examine_Array_Bounds Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 17/22] ada: Reject ambiguous function calls in interpolated string expressions Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 18/22] ada: Implement fast modulo reduction for nonbinary modular multiplication Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 19/22] " Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 20/22] ada: Fix bogus Address Sanitizer stack-buffer-overflow on packed record equality Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 21/22] ada: Fix bogus Address Sanitizer stack-buffer-overflow on packed array copy Marc Poulhiès
2024-06-21  8:58 ` [COMMITTED 22/22] ada: Fix internal error on protected type with -gnatc -gnatR Marc Poulhiès

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