[Ada] Reuse Package_Specification in Is_Incomplete_Or_Private_Type
authorPiotr Trojanek <trojanek@adacore.com>
Mon, 22 Mar 2021 14:38:34 +0000 (15:38 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Fri, 18 Jun 2021 08:36:53 +0000 (04:36 -0400)
gcc/ada/

* sem_aux.adb (Package_Specification): Add assertions to confirm
the kind of the of parameter and returned node.
* sem_ch12.adb (Remove_Parent): Reorder conditions; this change
appears to be semantically neutral, but is enough to avoid the
problematic call to Package_Specification.
* sem_util.adb (Is_Incomplete_Or_Private_Type): Replace loop
with a call to Package_Specification.

gcc/ada/sem_aux.adb
gcc/ada/sem_ch12.adb
gcc/ada/sem_util.adb

index 9f3ca2f332d0054443f272f636f2b5110a13dcbc..ea3b59c0a1c4cdf6d522edbd377ca5a665ccfcf5 100644 (file)
@@ -1421,12 +1421,16 @@ package body Sem_Aux is
       N : Node_Id;
 
    begin
+      pragma Assert (Is_Package_Or_Generic_Package (E));
+
       N := Parent (E);
 
       if Nkind (N) = N_Defining_Program_Unit_Name then
          N := Parent (N);
       end if;
 
+      pragma Assert (Nkind (N) = N_Package_Specification);
+
       return N;
    end Package_Specification;
 
index 06947e22878f45526a79df84835dc772392a6bd8..efdc44941dc74d86ec0c3d9e78df2da10d0db777 100644 (file)
@@ -15222,14 +15222,15 @@ package body Sem_Ch12 is
             --  subunit of a generic contains an instance of a child unit of
             --  its generic parent unit.
 
-            elsif S = Current_Scope and then Is_Generic_Instance (S) then
+            elsif S = Current_Scope and then Is_Generic_Instance (S)
+              and then (In_Package_Body (S) or else In_Private_Part (S))
+            then
                declare
                   Par : constant Entity_Id :=
                           Generic_Parent (Package_Specification (S));
                begin
                   if Present (Par)
                     and then P = Scope (Par)
-                    and then (In_Package_Body (S) or else In_Private_Part (S))
                   then
                      Set_In_Private_Part (P);
                      Install_Private_Declarations (P);
index cfbbae0e2d5479979fddc653611f39b49296e3f7..eb2caa76407cfe5925aecc2a17208360dc967b78 100644 (file)
@@ -14751,17 +14751,11 @@ package body Sem_Util is
 
       --  Private or Taft amendment type case
 
-      declare
-         Pkg_Decl : Node_Id;
-
-      begin
-         if Present (S) and then Is_Package_Or_Generic_Package (S) then
-            Pkg_Decl := S;
-
-            while Nkind (Pkg_Decl) /= N_Package_Specification loop
-               Pkg_Decl := Parent (Pkg_Decl);
-            end loop;
+      if Present (S) and then Is_Package_Or_Generic_Package (S) then
+         declare
+            Pkg_Decl : constant Node_Id := Package_Specification (S);
 
+         begin
             --  It is knows that Typ has a private view, look for it in the
             --  visible declarations of the enclosing scope. A special case
             --  of this is when the two views have been exchanged - the full
@@ -14785,8 +14779,8 @@ package body Sem_Util is
             elsif In_Package_Body (S) then
                return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
             end if;
-         end if;
-      end;
+         end;
+      end if;
 
       --  The type has no incomplete or private view