diff mbox

[Ada] Implement pragma Pure_12 and use it in Ada.Finalization

Message ID 20111121113612.GA16593@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Nov. 21, 2011, 11:36 a.m. UTC
Ada_Finalization is Pure in Ada 2012, but not in earlier versions.
This is in accordance with AI05-0212. This patch implements a
pragma and apsect Pure_12, which is like Pure but effective
only in Ada 2012 mode (analogous to Pure_05 in Ada 2005 mode)

The following two test programs show the effect

     1. pragma Ada_2012;
     2. with Ada.Finalization;
     3. package pure1212 is
     4.     pragma Pure;
     5. end;

the above compiles with no errors, but in Ada 95 mode, we have

     1. pragma Ada_95;
     2. with Ada.Finalization;
             |
        >>> cannot depend on "Finalization" (wrong categorization)
        >>> pure unit cannot depend on non-pure unit

     3. package pure1295 is
     4.     pragma Pure;
     5. end;

this ensures portability with other Ada 95 and Ada 2005 compilers

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

2011-11-21  Robert Dewar  <dewar@adacore.com>

	* a-finali.ads: Use pragma Pure_12 for this unit
	* aspects.adb: Add aspect Pure_12
	* aspects.ads: Add aspect Pure_12
	* opt.ads: Add note on Pure_12
	* par-prag.adb: Add dummy entry for Pure_12
	* sem_prag.adb: Implement Pure_12 pragma
	* snames.ads-tmpl: Add Entry for Pure_12
diff mbox

Patch

Index: sem_prag.adb
===================================================================
--- sem_prag.adb	(revision 181556)
+++ sem_prag.adb	(working copy)
@@ -12647,6 +12647,47 @@ 
             end if;
          end Pure_05;
 
+         -------------
+         -- Pure_12 --
+         -------------
+
+         --  pragma Pure_12 [(library_unit_NAME)];
+
+         --  This pragma is useable only in GNAT_Mode, where it is used like
+         --  pragma Pure but it is only effective in Ada 2012 mode (otherwise
+         --  it is ignored). It may be used after a pragma Preelaborate, in
+         --  which case it overrides the effect of the pragma Preelaborate.
+         --  This is used to implement AI05-0212 which recategorizes some
+         --  run-time packages in Ada 2012 mode.
+
+         when Pragma_Pure_12 => Pure_12 : declare
+            Ent : Entity_Id;
+
+         begin
+            GNAT_Pragma;
+            Check_Valid_Library_Unit_Pragma;
+
+            if not GNAT_Mode then
+               Error_Pragma ("pragma% only available in GNAT mode");
+            end if;
+
+            if Nkind (N) = N_Null_Statement then
+               return;
+            end if;
+
+            --  This is one of the few cases where we need to test the value of
+            --  Ada_Version_Explicit rather than Ada_Version (which is always
+            --  set to Ada_2012 in a predefined unit), we need to know the
+            --  explicit version set to know if this pragma is active.
+
+            if Ada_Version_Explicit >= Ada_2012 then
+               Ent := Find_Lib_Unit_Name;
+               Set_Is_Preelaborated (Ent, False);
+               Set_Is_Pure (Ent);
+               Set_Suppress_Elaboration_Warnings (Ent);
+            end if;
+         end Pure_12;
+
          -------------------
          -- Pure_Function --
          -------------------
@@ -14959,6 +15000,7 @@ 
       Pragma_Psect_Object                   => -1,
       Pragma_Pure                           => -1,
       Pragma_Pure_05                        => -1,
+      Pragma_Pure_12                        => -1,
       Pragma_Pure_Function                  => -1,
       Pragma_Queuing_Policy                 => -1,
       Pragma_Ravenscar                      => -1,
Index: aspects.adb
===================================================================
--- aspects.adb	(revision 181556)
+++ aspects.adb	(working copy)
@@ -255,6 +255,7 @@ 
     Aspect_Preelaborate_05              => Aspect_Preelaborate_05,
     Aspect_Pure                         => Aspect_Pure,
     Aspect_Pure_05                      => Aspect_Pure_05,
+    Aspect_Pure_12                      => Aspect_Pure_12,
     Aspect_Remote_Call_Interface        => Aspect_Remote_Call_Interface,
     Aspect_Remote_Types                 => Aspect_Remote_Types,
     Aspect_Shared_Passive               => Aspect_Shared_Passive,
Index: aspects.ads
===================================================================
--- aspects.ads	(revision 181556)
+++ aspects.ads	(working copy)
@@ -96,6 +96,7 @@ 
       Aspect_Preelaborate_05,               -- GNAT
       Aspect_Pure,
       Aspect_Pure_05,                       -- GNAT
+      Aspect_Pure_12,                       -- GNAT
       Aspect_Remote_Call_Interface,
       Aspect_Remote_Types,
       Aspect_Shared_Passive,
@@ -154,6 +155,7 @@ 
                              Aspect_Compiler_Unit        => True,
                              Aspect_Preelaborate_05      => True,
                              Aspect_Pure_05              => True,
+                             Aspect_Pure_12              => True,
                              Aspect_Universal_Data       => True,
                              Aspect_Ada_2005             => True,
                              Aspect_Ada_2012             => True,
@@ -324,6 +326,7 @@ 
      Aspect_Priority                     => Name_Priority,
      Aspect_Pure                         => Name_Pure,
      Aspect_Pure_05                      => Name_Pure_05,
+     Aspect_Pure_12                      => Name_Pure_12,
      Aspect_Pure_Function                => Name_Pure_Function,
      Aspect_Read                         => Name_Read,
      Aspect_Remote_Call_Interface        => Name_Remote_Call_Interface,
Index: par-prag.adb
===================================================================
--- par-prag.adb	(revision 181556)
+++ par-prag.adb	(working copy)
@@ -1216,6 +1216,7 @@ 
            Pragma_Psect_Object                   |
            Pragma_Pure                           |
            Pragma_Pure_05                        |
+           Pragma_Pure_12                        |
            Pragma_Pure_Function                  |
            Pragma_Queuing_Policy                 |
            Pragma_Relative_Deadline              |
Index: opt.ads
===================================================================
--- opt.ads	(revision 181556)
+++ opt.ads	(working copy)
@@ -140,7 +140,7 @@ 
    --  or internal units, so it reflects the Ada version explicitly set
    --  using configuration pragmas or compiler switches (or if neither
    --  appears, it remains set to Ada_Version_Default). This is used in
-   --  the rare cases (notably for pragmas Preelaborate_05 and Pure_05)
+   --  the rare cases (notably for pragmas Preelaborate_05 and Pure_05/12)
    --  where in the run-time we want the explicit version set.
 
    Ada_Version_Runtime : Ada_Version_Type := Ada_2012;
Index: a-finali.ads
===================================================================
--- a-finali.ads	(revision 181556)
+++ a-finali.ads	(working copy)
@@ -34,14 +34,16 @@ 
 ------------------------------------------------------------------------------
 
 pragma Warnings (Off);
---  System.Finalization_Root does not have category Remote_Types, but we
---  allow it anyway.
 with System.Finalization_Root;
 pragma Warnings (On);
 
 package Ada.Finalization is
+   pragma Pure_12;
+   --  Ada.Finalization is declared pure in Ada 2012 (AI05-0212)
+
    pragma Preelaborate;
    pragma Remote_Types;
+   --  The above apply in versions of Ada before Ada 2012
 
    type Controlled is abstract tagged private;
    pragma Preelaborable_Initialization (Controlled);
Index: snames.ads-tmpl
===================================================================
--- snames.ads-tmpl	(revision 181556)
+++ snames.ads-tmpl	(working copy)
@@ -524,6 +524,7 @@ 
    Name_Psect_Object                   : constant Name_Id := N + $; -- VMS
    Name_Pure                           : constant Name_Id := N + $;
    Name_Pure_05                        : constant Name_Id := N + $; -- GNAT
+   Name_Pure_12                        : constant Name_Id := N + $; -- GNAT
    Name_Pure_Function                  : constant Name_Id := N + $; -- GNAT
    Name_Relative_Deadline              : constant Name_Id := N + $; -- Ada 05
    Name_Remote_Call_Interface          : constant Name_Id := N + $;
@@ -1672,6 +1673,7 @@ 
       Pragma_Psect_Object,
       Pragma_Pure,
       Pragma_Pure_05,
+      Pragma_Pure_12,
       Pragma_Pure_Function,
       Pragma_Relative_Deadline,
       Pragma_Remote_Call_Interface,