This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] improve handling of streams and floats


Tested on i686-linux, committed on trunk

The selection of the right routine in System.Stream_Attributes in
the floating-point case was done only by size. This meant that on
a machine with Long_Float'Size = Long_Long_Float'Size (most cases
except x86), the Long_Float routines could be used instead of the
Long_Long_Float routines even for Long_Long_Float types. This was
relatively harmless, since the code is identical. However, in
specialized applications where the Stream_Attribute package was
customized to aid in inter-target portability, this caused some
difficulty.

The patch now ensures that the type correct routine is chosen, as
long as there are no strange Size or Stream_Size choices that force
another choice.

When the following program is compiled using -gnatG

with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
with Ada.Text_IO; use Ada.Text_IO;
procedure g is
   LLF : Long_Long_Float;
   FLT : Float;
   FCB : Ada.Streams.Stream_IO.File_Type;

begin
   Create (FCB, Out_File, "tmp");
   LLF := 1.2345;
   FLT := 3.1416;
   Long_Long_Float'Output (Stream (FCB), LLF);
   Float'Output (Stream (FCB), FLT);
   Close (FCB);
   Open (FCB, In_File, "tmp");
   LLF := Long_Long_Float'Input (Stream (FCB));
   Put_Line (Long_Float (LLF)'Img);
   FLT := Float'Input (Stream (FCB));
   Put_Line (FLT'Img);
end;

and the output put into a file log, doing a grep command:

grep system__stream_attributes log

should generate five lines:

with system.system__stream_attributes;
   $system__stream_attributes__w_llf (R2b, llf);
   $system__stream_attributes__w_f (R3b, flt);
   llf := long_long_float!($system__stream_attributes__i_llf (R5b));
   flt := float!($system__stream_attributes__i_f (R7b));

Without the patch w_sf and i_sf were used, and on non-x86 targets
w_lf and i_lf.

2007-06-06  Robert Dewar  <dewar@adacore.com>

	* exp_strm.adb (Make_Field_Attributes): Avoid _Parent components that
	are interface type.
	(Build_Elementary_Input_Call): For floating-point use right type in the
	absence of strange size or stream size clauses.
	(Build_Elementary_Write_Call): Same fix
	(Has_Stream_Standard_Rep): Returns False if Stream_Size attribute
	set to value that does not match base type size.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]