diff options
Diffstat (limited to 'gcc/ada/exp_imgv.adb')
-rw-r--r-- | gcc/ada/exp_imgv.adb | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb index 6dc59f2..e5d84cc 100644 --- a/gcc/ada/exp_imgv.adb +++ b/gcc/ada/exp_imgv.adb @@ -2294,7 +2294,7 @@ package body Exp_Imgv is -- in the range of the subtype + 1 for the space at the start. We -- build: - -- Tnn : constant Integer := Rtyp'Pos (Ptyp'Last) + -- Tnn : constant Integer := Rtyp'Pos (Ptyp'Last); -- and replace the expression by @@ -2320,9 +2320,15 @@ package body Exp_Imgv is declare Tnn : constant Entity_Id := Make_Temporary (Loc, 'T'); Cexpr : Node_Id; - P : Int; - M : Int; - K : Int; + + P : constant Nat := + UI_To_Int (Enumeration_Pos (Entity (Type_High_Bound (Rtyp)))); + -- The largest value that might need to be represented + + K : Pos; + M : Pos; + -- K is the number of chars that will fit the image of 0..M-1; + -- M is the smallest number that won't fit in K chars. begin Insert_Action (N, @@ -2342,14 +2348,13 @@ package body Exp_Imgv is Attribute_Name => Name_Last)))))); -- OK, now we need to build the if expression. First get the - -- value of M, the largest possible value needed. + -- values of K and M for the largest possible value P. - P := UI_To_Int - (Enumeration_Pos (Entity (Type_High_Bound (Rtyp)))); + K := 2; + M := 10; + -- With 2 characters we can represent values in 0..9 - K := 1; - M := 1; - while M < P loop + while P >= M loop M := M * 10; K := K + 1; end loop; |