https://gcc.gnu.org/g:c76e68d30c1ffc31ad3afd2a659ff5eba490a1c2
commit r16-1806-gc76e68d30c1ffc31ad3afd2a659ff5eba490a1c2 Author: Piotr Trojanek <troja...@adacore.com> Date: Thu Apr 24 10:53:14 2025 +0200 ada: Tune name and commend document of a ghost utility routine 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. Diff: --- gcc/ada/ghost.adb | 14 ++++++------- gcc/ada/sem_util.adb | 58 ++++++++++++++++++++++++++-------------------------- gcc/ada/sem_util.ads | 10 ++++----- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb index ac38f3cc2391..6f648f2af922 100644 --- a/gcc/ada/ghost.adb +++ b/gcc/ada/ghost.adb @@ -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); diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index e1b78dce32fe..3c2a776ce369 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -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 -- diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index c2c689abd630..6e4586648644 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -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