[Ada] treepr: Print value of static expression
authorBob Duff <duff@adacore.com>
Fri, 10 Dec 2021 20:53:04 +0000 (15:53 -0500)
committerPierre-Marie de Rodat <derodat@adacore.com>
Fri, 7 Jan 2022 16:24:05 +0000 (16:24 +0000)
gcc/ada/

* treepr.adb (Print_Node_Ref): Print the value if available.

gcc/ada/treepr.adb

index c1e71b1..ad2bbf0 100644 (file)
@@ -37,6 +37,7 @@ with Namet;                use Namet;
 with Nlists;               use Nlists;
 with Output;               use Output;
 with Seinfo;               use Seinfo;
+with Sem_Eval;             use Sem_Eval;
 with Sinfo;                use Sinfo;
 with Sinfo.Nodes;          use Sinfo.Nodes;
 with Sinfo.Utils;          use Sinfo.Utils;
@@ -1642,6 +1643,24 @@ package body Treepr is
             end if;
          end if;
 
+         --  If this is an integer-like expression whose value is known, print
+         --  that value.
+
+         if Nkind (N) in N_Subexpr
+           and then Compile_Time_Known_Value (N)
+           and then Present (Etype (N))
+           and then not Is_Array_Type (Etype (N))
+         then
+            if Is_Entity_Name (N) -- e.g. enumeration literal
+              or else Nkind (N) in N_Integer_Literal
+                                 | N_Character_Literal
+                                 | N_Unchecked_Type_Conversion
+            then
+               Print_Str (" val = ");
+               UI_Write (Expr_Value (N));
+            end if;
+         end if;
+
          if Nkind (N) in N_Entity then
             Write_Str (" (Entity_Id=");
          else