From: Ronan Desplanques <desplanq...@adacore.com>

This patchs adds two pn-like subprograms that print entity chains.

gcc/ada/ChangeLog:

        * treepr.ads (Print_Entity_Chain, pec, rpec): New subprograms.
        * treepr.adb (Print_Entity_Chain, pec, rpec): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/treepr.adb | 58 ++++++++++++++++++++++++++++++++++++++++++++++
 gcc/ada/treepr.ads | 14 +++++++++++
 2 files changed, 72 insertions(+)

diff --git a/gcc/ada/treepr.adb b/gcc/ada/treepr.adb
index 0f723ed25b2..d58f3ceb36f 100644
--- a/gcc/ada/treepr.adb
+++ b/gcc/ada/treepr.adb
@@ -412,6 +412,34 @@ package body Treepr is
 
    procedure pe (N : Union_Id) renames pn;
 
+   ---------
+   -- pec --
+   ---------
+
+   procedure pec (From : Entity_Id) is
+   begin
+      Push_Output;
+      Set_Standard_Output;
+
+      Print_Entity_Chain (From);
+
+      Pop_Output;
+   end pec;
+
+   ----------
+   -- rpec --
+   ----------
+
+   procedure rpec (From : Entity_Id) is
+   begin
+      Push_Output;
+      Set_Standard_Output;
+
+      Print_Entity_Chain (From, Rev => True);
+
+      Pop_Output;
+   end rpec;
+
    --------
    -- pl --
    --------
@@ -589,6 +617,36 @@ package body Treepr is
       end if;
    end Print_End_Span;
 
+   ------------------------
+   -- Print_Entity_Chain --
+   ------------------------
+
+   procedure Print_Entity_Chain (From : Entity_Id; Rev : Boolean := False) is
+      Ent : Entity_Id := From;
+   begin
+      Printing_Descendants := False;
+      Phase := Printing;
+
+      loop
+         declare
+            Next_Ent : constant Entity_Id :=
+              (if Rev then Prev_Entity (Ent) else Next_Entity (Ent));
+
+            Prefix_Char : constant Character :=
+              (if Present (Next_Ent) then '|' else ' ');
+         begin
+            Print_Node (Ent, "", Prefix_Char);
+
+            exit when No (Next_Ent);
+
+            Ent := Next_Ent;
+
+            Print_Char ('|');
+            Print_Eol;
+         end;
+      end loop;
+   end Print_Entity_Chain;
+
    -----------------------
    -- Print_Entity_Info --
    -----------------------
diff --git a/gcc/ada/treepr.ads b/gcc/ada/treepr.ads
index f8a17fbfd79..43e518711e6 100644
--- a/gcc/ada/treepr.ads
+++ b/gcc/ada/treepr.ads
@@ -60,6 +60,12 @@ package Treepr is
    --  Prints the subtree consisting of the given element list and all its
    --  referenced descendants.
 
+   procedure Print_Entity_Chain (From : Entity_Id; Rev : Boolean := False);
+   --  Prints the entity chain From is on, starting from From. In other words,
+   --  prints From and then recursively follow the Next_Entity field. If Rev is
+   --  True, prints the chain backwards, i.e. follow the Last_Entity field
+   --  instead of Next_Entity.
+
    --  The following debugging procedures are intended to be called from gdb.
    --  Note that in several cases there are synonyms which represent historical
    --  development, and we keep them because some people are used to them!
@@ -103,4 +109,12 @@ package Treepr is
    --  on the left and add a minus sign. This just saves some typing in the
    --  debugger.
 
+   procedure pec (From : Entity_Id);
+   pragma Export (Ada, pec);
+   --  Print From and the entities that follow it on its entity chain
+
+   procedure rpec (From : Entity_Id);
+   pragma Export (Ada, rpec);
+   --  Like pec, but walk the entity chain backwards. The 'r' stands for
+   --  "reverse".
 end Treepr;
-- 
2.43.0

Reply via email to