This patch causes more cases of inconsistent use of pragma Long_Float to
be caught at compile time. This gives better messages earlier, and also
avoids some blowups due to inconsistent usage.
The following is pkg1.adb compiled with -gnatdm -gnatld7 -gnatj60
Compiling: pkg1.adb
1. package body Pkg1 is
2. procedure Sep is separate;
3. end Pkg1;
Compiling: pkg1.ads
1. package Pkg1 is
2. F1 : Float := 12.5;
3.
4. procedure Sep;
5. end Pkg1;
Compiling: pkg1-sep.adb
1. with Ada.Text_IO; use Ada.Text_IO;
2. with T1;
3.
4. separate (Pkg1)
5. procedure Sep is
6. begin
7. Put_Line (Float'Image (T1.F2));
8. end Sep;
9.
==============Error messages for source file: t1.ads
1. pragma Long_Float(G_Float);
|
>>> main unit not compiled with pragma Long_Float
(G_Float), pragma "Long_Float" must be used
consistently for whole partition
The source file t1.ads is:
1. pragma Long_Float(G_Float);
2.
3. package T1 is
4. subtype F is Float;
5.
6. F2 : F := 4.5;
7. end T1;
Tested on x86_64-pc-linux-gnu, committed on trunk
2011-11-04 Robert Dewar <[email protected]>
* sem_prag.adb: Detect more cases of Long_Float inconsistencies at
compile time.
Index: sem_prag.adb
===================================================================
--- sem_prag.adb (revision 180929)
+++ sem_prag.adb (working copy)
@@ -10952,7 +10952,8 @@
-- pragma Long_Float (D_Float | G_Float);
- when Pragma_Long_Float =>
+ when Pragma_Long_Float => Long_Float : declare
+ begin
GNAT_Pragma;
Check_Valid_Configuration_Pragma;
Check_Arg_Count (1);
@@ -10967,22 +10968,42 @@
if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
if Opt.Float_Format_Long = 'G' then
- Error_Pragma ("G_Float previously specified");
+ Error_Pragma_Arg
+ ("G_Float previously specified", Arg1);
+
+ elsif Current_Sem_Unit /= Main_Unit
+ and then Opt.Float_Format_Long /= 'D'
+ then
+ Error_Pragma_Arg
+ ("main unit not compiled with pragma Long_Float (D_Float)",
+ "\pragma% must be used consistently for whole partition",
+ Arg1);
+
+ else
+ Opt.Float_Format_Long := 'D';
end if;
- Opt.Float_Format_Long := 'D';
-
-- G_Float case (this is the default, does not need overriding)
else
if Opt.Float_Format_Long = 'D' then
Error_Pragma ("D_Float previously specified");
+
+ elsif Current_Sem_Unit /= Main_Unit
+ and then Opt.Float_Format_Long /= 'G'
+ then
+ Error_Pragma_Arg
+ ("main unit not compiled with pragma Long_Float (G_Float)",
+ "\pragma% must be used consistently for whole partition",
+ Arg1);
+
+ else
+ Opt.Float_Format_Long := 'G';
end if;
-
- Opt.Float_Format_Long := 'G';
end if;
Set_Standard_Fpt_Formats;
+ end Long_Float;
-----------------------
-- Machine_Attribute --