It computes the size of an integer type that can accommodate the input.
gcc/ada/ChangeLog:
* uintp.ads (Type_Size_For): New function declaration.
* uintp.adb (Type_Size_For): New function body.
* exp_imgv.adb (Rewrite_Object_Image): Call Type_Size_For to get
the size of a narrower integer type.
elsif Nkind (P) = N_Integer_Literal then
declare
- Val : constant Uint := Intval (P);
- Neg : constant Boolean := Val < Uint_0;
- Bits : constant Nat := Num_Bits (Val) + Boolean'Pos (Neg);
+ Val : constant Uint := Intval (P);
+ Siz : constant Nat := Type_Size_For (Val);
begin
- if Bits <= System_Max_Integer_Size then
- Ptyp := Integer_Type_For (UI_From_Int (Bits), not Neg);
+ if Siz <= System_Max_Integer_Size then
+ Ptyp := Integer_Type_For (UI_From_Int (Siz), Val >= Uint_0);
end if;
end;
end if;
end if;
end Release_And_Save;
+ --------------------
+ -- Type_Size_For --
+ --------------------
+
+ function Type_Size_For (Input : Valid_Uint) return Nat is
+ Neg : constant Boolean := Input < Uint_0;
+
+ begin
+ -- Num_Bits is correct only for nonnegative values
+
+ return Num_Bits (Input) + Boolean'Pos (Neg);
+ end Type_Size_For;
+
-------------
-- UI_Abs --
-------------
-- function is used for capacity checks, and it can be one bit off
-- without affecting its usage.
+ function Type_Size_For (Input : Valid_Uint) return Nat;
+ -- Returns the size of an integer type that can accommodate Input
+
---------------------
-- Output Routines --
---------------------