]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Add entity chain debug printing subprograms
authorRonan Desplanques <desplanques@adacore.com>
Thu, 17 Apr 2025 09:50:42 +0000 (11:50 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 30 Jun 2025 13:47:19 +0000 (15:47 +0200)
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.

gcc/ada/treepr.adb
gcc/ada/treepr.ads

index 0f723ed25b24f32143d4f005ed4a15ed34ee71d1..d58f3ceb36fb520726e00394701a1a917479e328 100644 (file)
@@ -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 --
    -----------------------
index f8a17fbfd79b215379fa05b85e89b2cb59c47d8c..43e518711e6d1dbd423585165750fc0abd760d6d 100644 (file)
@@ -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;