]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Tune name and commend document of a ghost utility routine
authorPiotr Trojanek <trojanek@adacore.com>
Thu, 24 Apr 2025 08:53:14 +0000 (10:53 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 30 Jun 2025 13:47:21 +0000 (15:47 +0200)
Detection of ghost entities work similarly for names of objects (in assignment
statements) and for names of subprograms (in subprogram calls). Tune routine
name and its comment to match this similarity.

gcc/ada/ChangeLog:

* sem_util.ads (Get_Enclosing_Ghost_Entity): Rename spec.
* sem_util.adb (Get_Enclosing_Ghost_Object): Rename body; reorder
alphabetically; adapt recursive call.
* ghost.adb: Adapt calls to Get_Enclosing_Ghost_Object.

gcc/ada/ghost.adb
gcc/ada/sem_util.adb
gcc/ada/sem_util.ads

index ac38f3cc23917cf648043952dad8d79ef8cb1724..6f648f2af9223a46c40f5c5a7f84cd236d65f893 100644 (file)
@@ -776,7 +776,7 @@ package body Ghost is
       Formal     : Entity_Id;
       Is_Default : Boolean := False)
    is
-      Actual_Obj : constant Entity_Id := Get_Enclosing_Ghost_Object (Actual);
+      Actual_Obj : constant Entity_Id := Get_Enclosing_Ghost_Entity (Actual);
    begin
       if not Is_Ghost_Entity (Formal) then
          return;
@@ -1165,7 +1165,7 @@ package body Ghost is
       --  entity.
 
       if Nkind (N) = N_Assignment_Statement then
-         Id := Get_Enclosing_Ghost_Object (Name (N));
+         Id := Get_Enclosing_Ghost_Entity (Name (N));
 
          return Present (Id) and then Is_Ghost_Entity (Id);
       end if;
@@ -1223,7 +1223,7 @@ package body Ghost is
       --  A procedure call is Ghost when it invokes a Ghost procedure
 
       if Nkind (N) = N_Procedure_Call_Statement then
-         Id := Get_Enclosing_Ghost_Object (Name (N));
+         Id := Get_Enclosing_Ghost_Entity (Name (N));
 
          return Present (Id) and then Is_Ghost_Entity (Id);
       end if;
@@ -1460,7 +1460,7 @@ package body Ghost is
             end if;
 
             declare
-               Id : constant Entity_Id := Get_Enclosing_Ghost_Object (Lhs);
+               Id : constant Entity_Id := Get_Enclosing_Ghost_Entity (Lhs);
             begin
                if Present (Id) then
                   --  Left-hand side denotes a Checked ghost entity, so install
@@ -1744,7 +1744,7 @@ package body Ghost is
       --  A procedure call becomes Ghost when the procedure being invoked is
       --  Ghost. Install the Ghost mode of the procedure.
 
-      Id := Get_Enclosing_Ghost_Object (Name (N));
+      Id := Get_Enclosing_Ghost_Entity (Name (N));
 
       if Present (Id) then
          if Is_Checked_Ghost_Entity (Id) then
@@ -2058,7 +2058,7 @@ package body Ghost is
       --  of the target.
 
       if Nkind (N) = N_Assignment_Statement then
-         Id := Get_Enclosing_Ghost_Object (Name (N));
+         Id := Get_Enclosing_Ghost_Entity (Name (N));
 
          if Present (Id) then
             Set_Ghost_Mode_From_Entity (Id);
@@ -2097,7 +2097,7 @@ package body Ghost is
       --  procedure being invoked.
 
       elsif Nkind (N) = N_Procedure_Call_Statement then
-         Id := Get_Enclosing_Ghost_Object (Name (N));
+         Id := Get_Enclosing_Ghost_Entity (Name (N));
 
          if Present (Id) then
             Set_Ghost_Mode_From_Entity (Id);
index e1b78dce32feca04db134394f533b54f3714ff17..3c2a776ce369244a4c407c37d15541b110883c56 100644 (file)
@@ -10261,36 +10261,11 @@ package body Sem_Util is
           Strval => String_From_Name_Buffer);
    end Get_Default_External_Name;
 
-   --------------------------
-   -- Get_Enclosing_Object --
-   --------------------------
-
-   function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
-   begin
-      if Is_Entity_Name (N) then
-         return Entity (N);
-      else
-         case Nkind (N) is
-            when N_Indexed_Component
-               | N_Selected_Component
-               | N_Slice
-            =>
-               return Get_Enclosing_Object (Prefix (N));
-
-            when N_Type_Conversion =>
-               return Get_Enclosing_Object (Expression (N));
-
-            when others =>
-               return Empty;
-         end case;
-      end if;
-   end Get_Enclosing_Object;
-
    --------------------------------
-   -- Get_Enclosing_Ghost_Object --
+   -- Get_Enclosing_Ghost_Entity --
    --------------------------------
 
-   function Get_Enclosing_Ghost_Object (N : Node_Id) return Entity_Id is
+   function Get_Enclosing_Ghost_Entity (N : Node_Id) return Entity_Id is
    begin
       if Is_Entity_Name (N) then
          return Entity (N);
@@ -10302,7 +10277,7 @@ package body Sem_Util is
                | N_Selected_Component
                | N_Slice
             =>
-               return Get_Enclosing_Ghost_Object (Prefix (N));
+               return Get_Enclosing_Ghost_Entity (Prefix (N));
 
             when N_Function_Call =>
                return Get_Called_Entity (N);
@@ -10321,7 +10296,32 @@ package body Sem_Util is
                return Empty;
          end case;
       end if;
-   end Get_Enclosing_Ghost_Object;
+   end Get_Enclosing_Ghost_Entity;
+
+   --------------------------
+   -- Get_Enclosing_Object --
+   --------------------------
+
+   function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
+   begin
+      if Is_Entity_Name (N) then
+         return Entity (N);
+      else
+         case Nkind (N) is
+            when N_Indexed_Component
+               | N_Selected_Component
+               | N_Slice
+            =>
+               return Get_Enclosing_Object (Prefix (N));
+
+            when N_Type_Conversion =>
+               return Get_Enclosing_Object (Expression (N));
+
+            when others =>
+               return Empty;
+         end case;
+      end if;
+   end Get_Enclosing_Object;
 
    ---------------------------
    -- Get_Enum_Lit_From_Pos --
index c2c689abd6300bcdbead13dc9ba00e28836c2790..6e4586648644a3ddcbd55297e5baa28bc394d97d 100644 (file)
@@ -1143,12 +1143,10 @@ package Sem_Util is
    --  If expression N references a part of an object, return this object.
    --  Otherwise return Empty. Expression N should have been resolved already.
 
-   function Get_Enclosing_Ghost_Object (N : Node_Id) return Entity_Id;
-   --  If expression N references a reachable part of an object (as defined in
-   --  SPARK RM 6.9), return this object. Otherwise return Empty. It is similar
-   --  to Get_Enclosing_Object, but treats pointer dereference like component
-   --  selection. Also, it handles function results and type conversions like
-   --  objects. Expression N should have been resolved already.
+   function Get_Enclosing_Ghost_Entity (N : Node_Id) return Entity_Id;
+   --  If expression N references a name of either an object or of a
+   --  subprogram, then return its outermost entity that determines
+   --  whether this name denotes a ghost object.
 
    function Get_Generic_Entity (N : Node_Id) return Entity_Id;
    --  Returns the true generic entity in an instantiation. If the name in the