public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix inconsistent handling of character set control switches
@ 2021-05-04  9:52 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-05-04  9:52 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

[-- Attachment #1: Type: text/plain, Size: 1186 bytes --]

Switch -gnatic, where "c" denotes a character set, is described in the
GNAT User's Guide sections 4.3.11 Character Set Control and 4.3.1
Alphabetical List of All Switches, but the latter section didn't mention
'5' as an allowed value for "c".

This is implemented in csets.adb, switch-c.adb (for the frontend) and
switch-b.adb (for the binder), but the binder didn't support '9' as the
value for "c".

Now both documentation and code deals with all allowed character sets.

Found while refactoring repeated expressions in OR ELSE operands.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* csets.adb (Initialize): Refactor into CASE statement; raise
	exception on unsupported code of character set (it will be
	gently rejected earlier when scanning command line switches).
	* switch-b.adb (Scan_Binder_Switches): Refactor into a
	membership expression; add missing '9' choice; reorder as
	described by GNAT UG, section 4.3.11.
	* switch-c.adb (Scan_Front_End_Switches): Refactor into a
	membership expression and reorder as above.
	* doc/gnat_ugn/building_executable_programs_with_gnat.rst
	(gnatic): Mention '5' as an allowed value for "c".
	* gnat_ugn.texi: Regenerate.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 4525 bytes --]

diff --git a/gcc/ada/csets.adb b/gcc/ada/csets.adb
--- a/gcc/ada/csets.adb
+++ b/gcc/ada/csets.adb
@@ -1091,38 +1091,40 @@ package body Csets is
    begin
       --  Set Fold_Upper table from source code indication
 
-      if Identifier_Character_Set = '1'
-        or else Identifier_Character_Set = 'w'
-      then
-         Fold_Upper := Fold_Latin_1;
+      case Identifier_Character_Set is
+         when '1' | 'w' =>
+            Fold_Upper := Fold_Latin_1;
 
-      elsif Identifier_Character_Set = '2' then
-         Fold_Upper := Fold_Latin_2;
+         when '2' =>
+            Fold_Upper := Fold_Latin_2;
 
-      elsif Identifier_Character_Set = '3' then
-         Fold_Upper := Fold_Latin_3;
+         when '3' =>
+            Fold_Upper := Fold_Latin_3;
 
-      elsif Identifier_Character_Set = '4' then
-         Fold_Upper := Fold_Latin_4;
+         when '4' =>
+            Fold_Upper := Fold_Latin_4;
 
-      elsif Identifier_Character_Set = '5' then
-         Fold_Upper := Fold_Cyrillic;
+         when '5' =>
+            Fold_Upper := Fold_Cyrillic;
 
-      elsif Identifier_Character_Set = 'p' then
-         Fold_Upper := Fold_IBM_PC_437;
+         when '9' =>
+            Fold_Upper := Fold_Latin_9;
 
-      elsif Identifier_Character_Set = '8' then
-         Fold_Upper := Fold_IBM_PC_850;
+         when 'p' =>
+            Fold_Upper := Fold_IBM_PC_437;
 
-      elsif Identifier_Character_Set = '9' then
-         Fold_Upper := Fold_Latin_9;
+         when '8' =>
+            Fold_Upper := Fold_IBM_PC_850;
 
-      elsif Identifier_Character_Set = 'f' then
-         Fold_Upper := Fold_Full_Upper_Half;
+         when 'f' =>
+            Fold_Upper := Fold_Full_Upper_Half;
 
-      else -- Identifier_Character_Set = 'n'
-         Fold_Upper := Fold_No_Upper_Half;
-      end if;
+         when 'n' =>
+            Fold_Upper := Fold_No_Upper_Half;
+
+         when others =>
+            raise Program_Error;
+      end case;
 
       --  Use Fold_Upper table to compute Fold_Lower table
 


diff --git a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
--- a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
+++ b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
@@ -1896,7 +1896,7 @@ Alphabetical List of All Switches
 .. index:: -gnati  (gcc)
 
 :switch:`-gnati{c}`
-  Identifier character set (``c`` = 1/2/3/4/8/9/p/f/n/w).
+  Identifier character set (``c`` = 1/2/3/4/5/9/p/8/f/n/w).
   For details of the possible selections for ``c``,
   see :ref:`Character_Set_Control`.
 


diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -21,7 +21,7 @@
 
 @copying
 @quotation
-GNAT User's Guide for Native Platforms , Dec 11, 2020
+GNAT User's Guide for Native Platforms , Apr 12, 2021
 
 AdaCore
 
@@ -9462,7 +9462,7 @@ For further details see @ref{f,,Elaboration Order Handling in GNAT}.
 
 @item @code{-gnati@emph{c}}
 
-Identifier character set (@code{c} = 1/2/3/4/8/9/p/f/n/w).
+Identifier character set (@code{c} = 1/2/3/4/5/9/p/8/f/n/w).
 For details of the possible selections for @code{c},
 see @ref{31,,Character Set Control}.
 @end table


diff --git a/gcc/ada/switch-b.adb b/gcc/ada/switch-b.adb
--- a/gcc/ada/switch-b.adb
+++ b/gcc/ada/switch-b.adb
@@ -369,13 +369,7 @@ package body Switch.B is
             Ptr := Ptr + 1;
             C := Switch_Chars (Ptr);
 
-            if C in '1' .. '5'
-              or else C = '8'
-              or else C = 'p'
-              or else C = 'f'
-              or else C = 'n'
-              or else C = 'w'
-            then
+            if C in '1' .. '5' | '9' | 'p' | '8' | 'f' | 'n' | 'w' then
                Identifier_Character_Set := C;
                Ptr := Ptr + 1;
             else


diff --git a/gcc/ada/switch-c.adb b/gcc/ada/switch-c.adb
--- a/gcc/ada/switch-c.adb
+++ b/gcc/ada/switch-c.adb
@@ -929,14 +929,7 @@ package body Switch.C is
                Ptr := Ptr + 1;
                C := Switch_Chars (Ptr);
 
-               if C in '1' .. '5'
-                 or else C = '8'
-                 or else C = '9'
-                 or else C = 'p'
-                 or else C = 'f'
-                 or else C = 'n'
-                 or else C = 'w'
-               then
+               if C in '1' .. '5' | '8' | 'p' | '9' | 'f' | 'n' | 'w' then
                   Identifier_Character_Set := C;
                   Ptr := Ptr + 1;
 



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

only message in thread, other threads:[~2021-05-04  9:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-04  9:52 [Ada] Fix inconsistent handling of character set control switches 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).