diff mbox

[Ada] Representation information for nested subprograms

Message ID 20160502092415.GA113241@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet May 2, 2016, 9:24 a.m. UTC
With this patch the representation information generated with the -gnatR
compilation switch includes information on subprograms nested within
subprogram bodies.

Executing

   gcc -c -gnatRm p.adb

must yield;

---

Representation information for unit P (body)

procedure inner declared at p.adb:9:17
  convention : Ada

procedure inner2 declared at p.adb:11:20
  convention : Ada
  f : passed by copy

function sum declared at p.adb:23:16
  convention : Ada
  vec : passed by reference
  returns by copy

Representation information for unit P (spec)

for T'Alignment use 4;
for T'Component_Size use 32;

procedure s declared at p.ads:5:14
  convention : Ada
  a : passed by reference

---
package P
is
   type T is array (Positive range <>) of Integer;
   
   procedure S (A : in out T);
end P;
---
package body P is

   -------
   -- S --
   -------

   procedure S (A : in out T) is
      X, Y : Integer;
      procedure Inner
      is
         procedure Inner2 (F : in out Integer)
	 is
	 begin
	    F := F * 45;
	 end Inner2;
	 
      begin
	 X := Y + 1;
	 Inner2 (X);
	 Y := Y - 3;
      end Inner;
      
      function Sum (Vec : T) return Integer is
         Res : Integer := 0;
      begin
         for I in Vec'range loop
            Res := Res + Vec (I);
         end loop;
         return Res;
      end Sum;

   begin
      X := A (1);
      Y := A (2);
      
      Inner;
      
      A (1) := X + 1;
      A (2) := X + 3;
      
   end S;

end P;

Tested on x86_64-pc-linux-gnu, committed on trunk

2016-05-02  Ed Schonberg  <schonberg@adacore.com>

	* repinfo.adb (List_Entities): Make procedure recursive, to
	provide representation information for subprograms declared
	within subprogram bodies.
diff mbox

Patch

Index: repinfo.adb
===================================================================
--- repinfo.adb	(revision 235710)
+++ repinfo.adb	(working copy)
@@ -135,10 +135,15 @@ 
    --  Called before outputting anything for an entity. Ensures that
    --  a blank line precedes the output for a particular entity.
 
-   procedure List_Entities (Ent : Entity_Id; Bytes_Big_Endian : Boolean);
+   procedure List_Entities
+     (Ent : Entity_Id;
+      Bytes_Big_Endian : Boolean;
+      In_Subprogram    : Boolean := False);
    --  This procedure lists the entities associated with the entity E, starting
    --  with the First_Entity and using the Next_Entity link. If a nested
    --  package is found, entities within the package are recursively processed.
+   --  When recursing within a subprogram body, Is_Subprogram suppresses
+   --  duplicate information about signature.
 
    procedure List_Name (Ent : Entity_Id);
    --  List name of entity Ent in appropriate case. The name is listed with
@@ -314,7 +319,11 @@ 
    -- List_Entities --
    -------------------
 
-   procedure List_Entities (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is
+   procedure List_Entities
+     (Ent : Entity_Id;
+      Bytes_Big_Endian : Boolean;
+      In_Subprogram    : Boolean := False)
+   is
       Body_E : Entity_Id;
       E      : Entity_Id;
 
@@ -353,12 +362,15 @@ 
         and then Nkind (Declaration_Node (Ent)) not in N_Renaming_Declaration
       then
          --  If entity is a subprogram and we are listing mechanisms,
-         --  then we need to list mechanisms for this entity.
+         --  then we need to list mechanisms for this entity. We skip this
+         --  if it is a nested subprogram, as the information has already
+         --  been produced when listing the enclosing scope.
 
          if List_Representation_Info_Mechanisms
            and then (Is_Subprogram (Ent)
                       or else Ekind (Ent) = E_Entry
                       or else Ekind (Ent) = E_Entry_Family)
+           and then not In_Subprogram
          then
             Need_Blank_Line := True;
             List_Mechanisms (Ent);
@@ -386,6 +398,13 @@ 
                      List_Mechanisms (E);
                   end if;
 
+                  --  Recurse into entities local to subprogram
+
+                  List_Entities (E, Bytes_Big_Endian, True);
+
+               elsif Ekind (E) in Formal_Kind and then In_Subprogram then
+                  null;
+
                elsif Ekind_In (E, E_Entry,
                                   E_Entry_Family,
                                   E_Subprogram_Type)