diff mbox

[Ada] Fixes to -gnatyn mode (casing of standard identifiers)

Message ID 20130129141759.GA24420@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Jan. 29, 2013, 2:17 p.m. UTC
Identifiers for other than control characters and LC_? in ASCII are
not all upper case, they are mixed case. This patch corrects that
error in the handling of -gnatyn. It also removes a couple of
references to ASCII.BACK_SLASH from the run-time, since they are
now flagged, and removing the references solves any concerns about
bootstrapping.

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

2013-01-29  Robert Dewar  <dewar@adacore.com>

	* mlib-utl.adb, gnatlink.adb: Avoid reference to ASCII.Back_Slash
	because of casing issues.
	* sem_util.ads: Minor comment fix.
	* style.adb (Check_Identifier): Set proper casing for entities
	in ASCII.
	* styleg.adb: Minor comment improvement.
	* stylesw.ads (Style_Check_Standard): Fix bad comments.
diff mbox

Patch

Index: style.adb
===================================================================
--- style.adb	(revision 195533)
+++ style.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2012, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2013, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -94,7 +94,9 @@ 
    ----------------------
 
    --  In check references mode (-gnatyr), identifier uses must be cased
-   --  the same way as the corresponding identifier declaration.
+   --  the same way as the corresponding identifier declaration. If standard
+   --  references are checked (-gnatyn), then identifiers from Standard must
+   --  be cased as in the Reference Manual.
 
    procedure Check_Identifier
      (Ref : Node_Or_Entity_Id;
@@ -197,11 +199,31 @@ 
                if Entity (Ref) = Standard_ASCII then
                   Cas := All_Upper_Case;
 
-               --  Special names in ASCII are also all upper case
+               --  Special handling for names in package ASCII
 
                elsif Sdef = Standard_ASCII_Location then
-                  Cas := All_Upper_Case;
+                  declare
+                     Nam : constant String := Get_Name_String (Chars (Def));
 
+                  begin
+                     --  Bar is mixed case
+
+                     if Nam = "bar" then
+                        Cas := Mixed_Case;
+
+                     --  All names longer than 4 characters are mixed case
+
+                     elsif Nam'Length > 4 then
+                        Cas := Mixed_Case;
+
+                     --  All names shorter than 4 characters (other than Bar,
+                     --  which we already tested for specially) are Upper case.
+
+                     else
+                        Cas := All_Upper_Case;
+                     end if;
+                  end;
+
                --  All other entities are in mixed case
 
                else
Index: mlib-utl.adb
===================================================================
--- mlib-utl.adb	(revision 195533)
+++ mlib-utl.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---                     Copyright (C) 2002-2012, AdaCore                     --
+--                     Copyright (C) 2002-2013, AdaCore                     --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -396,7 +396,8 @@ 
       --------------
 
       procedure Write_RF (S : String) is
-         Success : Boolean := True;
+         Success    : Boolean            := True;
+         Back_Slash : constant Character := '\';
 
       begin
          --  If a GNU response file is used, space and backslash need to be
@@ -408,7 +409,7 @@ 
          if Using_GNU_response_file then
             for J in S'Range loop
                if S (J) = ' ' or else S (J) = '\' then
-                  if Write (Tname_FD, ASCII.BACK_SLASH'Address, 1) /= 1 then
+                  if Write (Tname_FD, Back_Slash'Address, 1) /= 1 then
                      Success := False;
                   end if;
                end if;
Index: sem_util.ads
===================================================================
--- sem_util.ads	(revision 195533)
+++ sem_util.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2012, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2013, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -1079,7 +1079,7 @@ 
    --  scope that is not a block or a package). This is used when the
    --  sequential flow-of-control assumption is violated (occurrence of a
    --  label, head of a loop, or start of an exception handler). The effect of
-   --  the call is to clear the Constant_Value field (but we do not need to
+   --  the call is to clear the Current_Value field (but we do not need to
    --  clear the Is_True_Constant flag, since that only gets reset if there
    --  really is an assignment somewhere in the entity scope). This procedure
    --  also calls Kill_All_Checks, since this is a special case of needing to
Index: gnatlink.adb
===================================================================
--- gnatlink.adb	(revision 195533)
+++ gnatlink.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1996-2012, Free Software Foundation, Inc.         --
+--          Copyright (C) 1996-2013, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -903,7 +903,8 @@ 
       --------------
 
       procedure Write_RF (S : String) is
-         Success : Boolean := True;
+         Success    : Boolean            := True;
+         Back_Slash : constant Character := '\';
 
       begin
          --  If a GNU response file is used, space and backslash need to be
@@ -915,7 +916,7 @@ 
          if Using_GNU_response_file then
             for J in S'Range loop
                if S (J) = ' ' or else S (J) = '\' then
-                  if Write (Tname_FD, ASCII.BACK_SLASH'Address, 1) /= 1 then
+                  if Write (Tname_FD, Back_Slash'Address, 1) /= 1 then
                      Success := False;
                   end if;
                end if;
Index: stylesw.ads
===================================================================
--- stylesw.ads	(revision 195533)
+++ stylesw.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2012, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2013, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -149,7 +149,7 @@ 
    --  is not allowed.
 
    Style_Check_Indentation : Column_Number range 0 .. 9 := 0;
-   --  This can be set non-zero by using the -gnatyn (n a digit) switch. If
+   --  This can be set non-zero by using the -gnaty? (? a digit) switch. If
    --  it is non-zero it activates indentation checking with the indicated
    --  indentation value. A value of zero turns off checking. The requirement
    --  is that any new statement, line comment, declaration or keyword such
@@ -217,8 +217,9 @@ 
 
    Style_Check_Standard : Boolean := False;
    --  This can be set True by using the -gnatyn switch. If it is True, then
-   --  any references to names in Standard have to be in mixed case mode (e.g.
-   --  Integer, Boolean).
+   --  any references to names in Standard have to be cased in a manner that
+   --  is consistent with the Ada RM (usually Mixed case, as in Long_Integer)
+   --  but there are some exceptions (e.g. NUL, ASCII).
 
    Style_Check_Tokens : Boolean := False;
    --  This can be set True by using the -gnatyt switch. If it is True, then
Index: styleg.adb
===================================================================
--- styleg.adb	(revision 195533)
+++ styleg.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2012, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2013, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -611,7 +611,7 @@ 
    -- Check_Indentation --
    -----------------------
 
-   --  In check indentation mode (-gnatyn for n a digit), a new statement or
+   --  In check indentation mode (-gnaty? for ? a digit), a new statement or
    --  declaration is required to start in a column that is a multiple of the
    --  indentation amount.