[gcc r15-1275] ada: List subprogram body entities in scopes
Marc Poulhi?s
dkm@gcc.gnu.org
Thu Jun 13 13:34:55 GMT 2024
https://gcc.gnu.org/g:047135cfed8c4c3950bda207dc87d33ca4c154ea
commit r15-1275-g047135cfed8c4c3950bda207dc87d33ca4c154ea
Author: Yannick Moy <moy@adacore.com>
Date: Fri Apr 26 17:08:08 2024 +0200
ada: List subprogram body entities in scopes
Add entities of kind E_Subprogram_Body to the list of entities associated
to a given scope. This ensures that representation information is
correctly output for object and type declarations inside these subprogram
bodies. This is useful for outputing that information fron the compiler
with the switch -gnatR, as well as for getting precise representation
information inside GNATprove.
Remove ad-hoc code inside repinfo.adb that retrieved this information
in only some cases.
gcc/ada/
* exp_ch5.adb (Expand_Iterator_Loop_Over_Container): Skip entities
of kind E_Subprogram_Body.
* repinfo.adb (List_Entities): Remove special case for subprogram
bodies.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): List subprogram
body entities in the enclosing scope.
Diff:
---
gcc/ada/exp_ch5.adb | 8 +++++++-
gcc/ada/repinfo.adb | 57 +----------------------------------------------------
gcc/ada/sem_ch6.adb | 9 +++++++++
3 files changed, 17 insertions(+), 57 deletions(-)
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
index f397086d73aa..b97e3bb7eee1 100644
--- a/gcc/ada/exp_ch5.adb
+++ b/gcc/ada/exp_ch5.adb
@@ -5351,10 +5351,16 @@ package body Exp_Ch5 is
Ent := First_Entity (Cont_Type_Pack);
while Present (Ent) loop
+
+ -- Ignore subprogram bodies
+
+ if Ekind (Ent) = E_Subprogram_Body then
+ null;
+
-- Get_Element_Access function with one parameter called
-- Position.
- if Chars (Ent) = Name_Get_Element_Access
+ elsif Chars (Ent) = Name_Get_Element_Access
and then Ekind (Ent) = E_Function
and then Present (First_Formal (Ent))
and then Chars (First_Formal (Ent)) = Name_Position
diff --git a/gcc/ada/repinfo.adb b/gcc/ada/repinfo.adb
index 28e4a6427655..7dada5358f7a 100644
--- a/gcc/ada/repinfo.adb
+++ b/gcc/ada/repinfo.adb
@@ -457,34 +457,7 @@ package body Repinfo is
Bytes_Big_Endian : Boolean;
In_Subprogram : Boolean := False)
is
- Body_E : Entity_Id;
- E : Entity_Id;
-
- function Find_Declaration (E : Entity_Id) return Node_Id;
- -- Utility to retrieve declaration node for entity in the
- -- case of package bodies and subprograms.
-
- ----------------------
- -- Find_Declaration --
- ----------------------
-
- function Find_Declaration (E : Entity_Id) return Node_Id is
- Decl : Node_Id;
-
- begin
- Decl := Parent (E);
- while Present (Decl)
- and then Nkind (Decl) /= N_Package_Body
- and then Nkind (Decl) /= N_Subprogram_Declaration
- and then Nkind (Decl) /= N_Subprogram_Body
- loop
- Decl := Parent (Decl);
- end loop;
-
- return Decl;
- end Find_Declaration;
-
- -- Start of processing for List_Entities
+ E : Entity_Id;
begin
-- List entity if we have one, and it is not a renaming declaration.
@@ -609,34 +582,6 @@ package body Repinfo is
Next_Entity (E);
end loop;
-
- -- For a package body, the entities of the visible subprograms are
- -- declared in the corresponding spec. Iterate over its entities in
- -- order to handle properly the subprogram bodies. Skip bodies in
- -- subunits, which are listed independently.
-
- if Ekind (Ent) = E_Package_Body
- and then Present (Corresponding_Spec (Find_Declaration (Ent)))
- then
- E := First_Entity (Corresponding_Spec (Find_Declaration (Ent)));
- while Present (E) loop
- if Is_Subprogram (E)
- and then
- Nkind (Find_Declaration (E)) = N_Subprogram_Declaration
- then
- Body_E := Corresponding_Body (Find_Declaration (E));
-
- if Present (Body_E)
- and then
- Nkind (Parent (Find_Declaration (Body_E))) /= N_Subunit
- then
- List_Entities (Body_E, Bytes_Big_Endian);
- end if;
- end if;
-
- Next_Entity (E);
- end loop;
- end if;
end if;
end List_Entities;
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index 50dac5c4a514..3252af797484 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -4083,6 +4083,15 @@ package body Sem_Ch6 is
else
Set_Corresponding_Spec (N, Spec_Id);
+ -- The body entity is not used for semantics or code generation,
+ -- but it is attached to the entity list of the enclosing scope
+ -- to allow listing its entities when outputting representation
+ -- information.
+
+ if Scope (Spec_Id) /= Standard_Standard then
+ Append_Entity (Body_Id, Scope (Spec_Id));
+ end if;
+
-- Ada 2005 (AI-345): If the operation is a primitive operation
-- of a concurrent type, the type of the first parameter has been
-- replaced with the corresponding record, which is the proper
More information about the Gcc-cvs
mailing list