This patch corrects the insertion of the corresponding pragma for aspect
Abstract_State when the related construct is a nested package. The pragma
appears in the visible declarations of the package.

------------
-- Source --
------------

--  pack.ads

package Pack with Abstract_State => Pack_State is
   Pack_Var : Integer;

   package Nested with Abstract_State => Nested_State is
      Nested_Var : Integer;
   end Nested;
end Pack;

----------------------------
-- Compilation and output --
----------------------------

$ gcc -c -gnat12 -gnatd.V -gnatdg pack.ads
Source recreated from tree for Pack (spec)
------------------------------------------

pack_E : short_integer := 0;

package pack with abstract_state => pack_state is
   pragma abstract_state (pack_state);
   pack__pack_var : integer;

   package pack__nested with abstract_state => nested_state is
      pragma abstract_state (nested_state);
      pack__nested__nested_var : integer;
   end pack__nested;
end pack;

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

2013-04-12  Hristian Kirtchev  <kirtc...@adacore.com>

        * sem_ch13.adb (Analyze_Aspect_Specifications):
        Insert the corresponding pragma for aspect Abstract_State at
        the top of the visible declarations of the related package.
        Previously this was only done when the package is a compilation
        unit.

Index: sem_ch13.adb
===================================================================
--- sem_ch13.adb        (revision 197900)
+++ sem_ch13.adb        (working copy)
@@ -1968,12 +1968,27 @@
                end if;
             end if;
 
+            --  Aspect Abstract_State introduces implicit declarations for all
+            --  state abstraction entities it defines. To emulate this behavior
+            --  insert the pragma at the start of the visible declarations of
+            --  the related package.
+
+            if Nam = Name_Abstract_State
+              and then Nkind (N) = N_Package_Declaration
+            then
+               if No (Visible_Declarations (Specification (N))) then
+                  Set_Visible_Declarations (Specification (N), New_List);
+               end if;
+
+               Prepend (Aitem, Visible_Declarations (Specification (N)));
+               goto Continue;
+
             --  In the context of a compilation unit, we directly put the
             --  pragma in the Pragmas_After list of the
             --  N_Compilation_Unit_Aux node (no delay is required here)
             --  except for aspects on a subprogram body (see below).
 
-            if Nkind (Parent (N)) = N_Compilation_Unit
+            elsif Nkind (Parent (N)) = N_Compilation_Unit
               and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect))
             then
                declare
@@ -2014,20 +2029,6 @@
 
                      Prepend (Aitem, Declarations (N));
 
-                  --  Aspect Abstract_State produces implicit declarations for
-                  --  all state abstraction entities it defines. To emulate
-                  --  this behavior, insert the pragma at the start of the
-                  --  visible declarations of the related package.
-
-                  elsif Nam = Name_Abstract_State
-                    and then Nkind (N) = N_Package_Declaration
-                  then
-                     if No (Visible_Declarations (Specification (N))) then
-                        Set_Visible_Declarations (Specification (N), New_List);
-                     end if;
-
-                     Prepend (Aitem, Visible_Declarations (Specification (N)));
-
                   else
                      if No (Pragmas_After (Aux)) then
                         Set_Pragmas_After (Aux, New_List);

Reply via email to