public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-1634] [Ada] Reuse Package_Specification in Is_Incomplete_Or_Private_Type
Date: Fri, 18 Jun 2021 08:39:37 +0000 (GMT)	[thread overview]
Message-ID: <20210618083937.2ED5839B4806@sourceware.org> (raw)

https://gcc.gnu.org/g:f86c2f9c8e5d7d02cc6b79fc80a647a9a27e23f2

commit r12-1634-gf86c2f9c8e5d7d02cc6b79fc80a647a9a27e23f2
Author: Piotr Trojanek <trojanek@adacore.com>
Date:   Mon Mar 22 15:38:34 2021 +0100

    [Ada] Reuse Package_Specification in Is_Incomplete_Or_Private_Type
    
    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.

Diff:
---
 gcc/ada/sem_aux.adb  |  4 ++++
 gcc/ada/sem_ch12.adb |  5 +++--
 gcc/ada/sem_util.adb | 18 ++++++------------
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/gcc/ada/sem_aux.adb b/gcc/ada/sem_aux.adb
index 9f3ca2f332d..ea3b59c0a1c 100644
--- a/gcc/ada/sem_aux.adb
+++ b/gcc/ada/sem_aux.adb
@@ -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;
 
diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index 06947e22878..efdc44941dc 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -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);
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index cfbbae0e2d5..eb2caa76407 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -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


                 reply	other threads:[~2021-06-18  8:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210618083937.2ED5839B4806@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).