[Ada] Fix exponentiation problem
Geert Bosch
bosch@gnat.com
Thu Oct 11 17:02:00 GMT 2001
Fix exponentiation problem with fixed-point type.
-Geert
2001-10-11 Ed Schonberg <schonber@gnat.com>
* exp_fixd.adb (Expand_Multiply_Fixed_By_Fixed_Giving_Fixed): handle
properly the case where one universal operand in a non-static
exponentiation of a real literal.
*** exp_fixd.adb 2001/04/03 20:47:58 1.54
--- exp_fixd.adb 2001/09/28 18:40:51 1.55
***************
*** 2082,2093 ****
Left : constant Node_Id := Left_Opnd (N);
Right : constant Node_Id := Right_Opnd (N);
begin
if Etype (Left) = Universal_Real then
! Do_Multiply_Fixed_Universal (N, Right, Left);
elsif Etype (Right) = Universal_Real then
! Do_Multiply_Fixed_Universal (N, Left, Right);
else
Do_Multiply_Fixed_Fixed (N);
--- 2082,2122 ----
Left : constant Node_Id := Left_Opnd (N);
Right : constant Node_Id := Right_Opnd (N);
+ procedure Rewrite_Non_Static_Universal (Opnd : Node_Id);
+ -- The operand may be a non-static universal value, such an
+ -- exponentiation with a non-static exponent. In that case, treat
+ -- as a fixed * fixed multiplication, and convert the argument to
+ -- the target fixed type.
+
+ procedure Rewrite_Non_Static_Universal (Opnd : Node_Id) is
+ Loc : constant Source_Ptr := Sloc (N);
+
+ begin
+ Rewrite (Opnd,
+ Make_Type_Conversion (Loc,
+ Subtype_Mark => New_Occurrence_Of (Etype (N), Loc),
+ Expression => Expression (Opnd)));
+ Analyze_And_Resolve (Opnd, Etype (N));
+ end Rewrite_Non_Static_Universal;
+
begin
if Etype (Left) = Universal_Real then
! if Nkind (Left) = N_Real_Literal then
! Do_Multiply_Fixed_Universal (N, Right, Left);
+ elsif Nkind (Left) = N_Type_Conversion then
+ Rewrite_Non_Static_Universal (Left);
+ Do_Multiply_Fixed_Fixed (N);
+ end if;
+
elsif Etype (Right) = Universal_Real then
! if Nkind (Right) = N_Real_Literal then
! Do_Multiply_Fixed_Universal (N, Left, Right);
!
! elsif Nkind (Right) = N_Type_Conversion then
! Rewrite_Non_Static_Universal (Right);
! Do_Multiply_Fixed_Fixed (N);
! end if;
else
Do_Multiply_Fixed_Fixed (N);
More information about the Gcc-patches
mailing list