[Ada] Improvements to pragma Obsolescent

Arnaud Charlet charlet@adacore.com
Wed Apr 8 14:54:00 GMT 2009


This patch does two things, first it makes the old "obsolete" form
official (where the Entity argument is omitted) official and fully
supported. Second it removes the requirement for pragma argument
identifiers to be present (whether or not the Entity argument is
present). The following test, compiled with -gnatwa -gnatj60
shows the new capabilities:

     1. package obsid is
     2.    X : Integer;
     3.    pragma Obsolescent (X, "x no good");
     4.    type Y is (Z);
     5.    pragma Obsolescent (Entity => Z, Message => "bad enum");
     6.    A : Integer;
     7.    pragma Obsolescent;
     8.    B : Integer;
     9.    pragma Obsolescent ("B is junk");
    10. end obsid;

    1. with obsid; use obsid;
    2. package useobs is
    3.    W : Integer := X;
                         |
       >>> warning: reference to obsolescent variable "X"
           declared at obsid.ads:2
           x no good

    4.    V : Y := Z;
                   |
       >>> warning: reference to obsolescent enumeration
           literal "Z" declared at obsid.ads:4
           bad enum

    5.    M : Integer := A;
                         |
       >>> warning: reference to obsolescent variable "A"
           declared at obsid.ads:6

    6.    N : Integer := B;
                         |
       >>> warning: reference to obsolescent variable "B"
           declared at obsid.ads:8
           B is junk

    7. end useobs;

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

2009-04-08  Robert Dewar  <dewar@adacore.com>

	* gnat_rm.texi: Update documentation of pragma Obsolescent
	
	* sem_prag.adb (Analyze_Pragma, case Obsolescent): Allow identifiers to
	be omitted, and allow Entity parameter to be omitted.

-------------- next part --------------
Index: gnat_rm.texi
===================================================================
--- gnat_rm.texi	(revision 145744)
+++ gnat_rm.texi	(working copy)
@@ -3463,19 +3463,26 @@ will always generate an invalid value if
 Syntax:
 
 @smallexample @c ada
-pragma Obsolescent
-  [([Entity  =>] NAME
-  [,[Message =>] static_string_EXPRESSION
-  [,[Version =>] Ada_05]])];
+pragma Obsolescent;
+
+pragma Obsolescent (
+  [Message =>] static_string_EXPRESSION
+[,[Version =>] Ada_05]]);
+
+pragma Obsolescent (
+  [Entity  =>] NAME
+[,[Message =>] static_string_EXPRESSION
+[,[Version =>] Ada_05]] );
 @end smallexample
 
 @noindent
 This pragma can occur immediately following a declaration of an entity,
-including the case of a record component, and usually the Entity name
-must match the name of the entity declared by this declaration.
-Alternatively, the pragma can immediately follow an
-enumeration type declaration, where the entity argument names one of the
-enumeration literals.
+including the case of a record component. If no Entity argument is present,
+then this declaration is the one to which the pragma applies. If an Entity
+parameter is present, it must either match the name of the entity in this
+declaration, or alternatively, the pragma can immediately follow an enumeration
+type declaration, where the Entity argument names one of the enumeration
+literals.
 
 This pragma is used to indicate that the named entity
 is considered obsolescent and should not be used. Typically this is
@@ -3484,13 +3491,12 @@ existing subprograms or other entities. 
 intermediate stage when the entity is still present, but will be
 removed later.
 
-The effect of this pragma is to output a warning message on
-a call to a program thus marked that the
-subprogram is obsolescent if the appropriate warning option in the
-compiler is activated. If the string parameter is present, then a second
-warning message is given containing this text.
-In addition, a call to such a program is considered a violation of
-pragma Restrictions (No_Obsolescent_Features).
+The effect of this pragma is to output a warning message on a reference to
+an entity thus marked that the subprogram is obsolescent if the appropriate
+warning option in the compiler is activated. If the Message parameter is
+present, then a second warning message is given containing this text. In
+addition, a reference to the eneity is considered to be a violation of pragma
+Restrictions (No_Obsolescent_Features).
 
 This pragma can also be used as a program unit pragma for a package,
 in which case the entity name is the name of the package, and the
@@ -3499,7 +3505,7 @@ obsolescent. In this case a client @code
 violates the restriction, and the @code{with} statement is
 flagged with warnings if the warning option is set.
 
-If the optional third parameter is present (which must be exactly
+If the Version parameter is present (which must be exactly
 the identifier Ada_05, no other argument is allowed), then the
 indication of obsolescence applies only when compiling in Ada 2005
 mode. This is primarily intended for dealing with the situations
@@ -3511,15 +3517,12 @@ The following examples show typical uses
 
 @smallexample @c ada
 package p is
-   pragma Obsolescent
-     (Entity => p, Message => "use pp instead of p");
+   pragma Obsolescent (p, Message => "use pp instead of p");
 end p;
 
 package q is
    procedure q2;
-   pragma Obsolescent
-     (Entity  => q2,
-      Message => "use q2new instead");
+   pragma Obsolescent ("use q2new instead");
 
    type R is new integer;
    pragma Obsolescent
@@ -3530,7 +3533,7 @@ package q is
    type M is record
       F1 : Integer;
       F2 : Integer;
-      pragma Obsolescent (Entity => F2);
+      pragma Obsolescent;
       F3 : Integer;
    end record;
 
@@ -3545,11 +3548,10 @@ end;
 @end smallexample
 
 @noindent
-In an earlier version of GNAT, the Entity parameter was not required,
-and this form is still accepted for compatibility purposes. If the
-Entity parameter is omitted, then the pragma applies to the declaration
-immediately preceding the pragma (this form cannot be used for the
-enumeration literal case).
+Note that, as for all pragmas, if you use a pragma argument identifier,
+then all subsequent parameters must also use a pragma argument identifier.
+So if you specify "Entity =>" for the Entity argument, and a Message
+argument is present, it must be preceded by "Message =>".
 
 @node Pragma Optimize_Alignment
 @unnumberedsec Pragma Optimize_Alignment
Index: sem_prag.adb
===================================================================
--- sem_prag.adb	(revision 145744)
+++ sem_prag.adb	(working copy)
@@ -9058,10 +9058,16 @@ package body Sem_Prag is
          -- Obsolescent --
          -----------------
 
-         --  pragma Obsolescent [(
-         --    [Entity  => NAME,]
-         --    [Message => static_string_EXPRESSION
-         --  [,[Version => Ada_05]] )];
+         --  pragma Obsolescent;
+
+         --  pragma Obsolescent (
+         --    [Message =>] static_string_EXPRESSION
+         --  [,[Version =>] Ada_05]]);
+
+         --  pragma Obsolescent (
+         --    [Entity  =>] NAME
+         --  [,[Message =>] static_string_EXPRESSION
+         --  [,[Version =>] Ada_05]] );
 
          when Pragma_Obsolescent => Obsolescent : declare
             Ename : Node_Id;
@@ -9186,19 +9192,15 @@ package body Sem_Prag is
             --  See if first argument specifies an entity name
 
             if Arg_Count >= 1
-              and then Chars (Arg1) = Name_Entity
+              and then
+                (Chars (Arg1) = Name_Entity
+                   or else
+                     Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
+                                                      N_Identifier,
+                                                      N_Operator_Symbol))
             then
                Ename := Get_Pragma_Arg (Arg1);
 
-               if Nkind (Ename) /= N_Character_Literal
-                    and then
-                  Nkind (Ename) /= N_Identifier
-                    and then
-                  Nkind (Ename) /= N_Operator_Symbol
-               then
-                  Error_Pragma_Arg ("entity name expected for pragma%", Arg1);
-               end if;
-
                --  Eliminate first argument, so we can share processing
 
                Arg1 := Arg2;


More information about the Gcc-patches mailing list