diff options
author | Geert Bosch <bosch@gnat.com> | 2001-10-30 22:16:50 +0100 |
---|---|---|
committer | Geert Bosch <bosch@gcc.gnu.org> | 2001-10-30 22:16:50 +0100 |
commit | de4bf6cb941ee680b22e4f5f7bf3fd42023ffce9 (patch) | |
tree | c0b3deed66bc4091f9be0dbe6d916285a650cc86 /gcc/ada/layout.adb | |
parent | f5e44987a6f7e1028e5b959935fd33768548357f (diff) | |
download | gcc-de4bf6cb941ee680b22e4f5f7bf3fd42023ffce9.zip gcc-de4bf6cb941ee680b22e4f5f7bf3fd42023ffce9.tar.gz gcc-de4bf6cb941ee680b22e4f5f7bf3fd42023ffce9.tar.bz2 |
ali-util.adb (Initialize_Checksum): Use out-mode instead of in out.
* ali-util.adb (Initialize_Checksum): Use out-mode instead of in out.
Found due to GCC 3.0 warning of using uninitialized value.
* layout.adb:
(Get_Max_Size): Use variant record for tracking value/expression.
Makes logic clearer and prevents warnings for uninitialized variables.
(Layout_Array_Type): Use variant record for tracking value/expression.
Makes logic clearer and prevents warnings for uninitialized variables.
From-SVN: r46652
Diffstat (limited to 'gcc/ada/layout.adb')
-rw-r--r-- | gcc/ada/layout.adb | 158 |
1 files changed, 84 insertions, 74 deletions
diff --git a/gcc/ada/layout.adb b/gcc/ada/layout.adb index 5778ea9..f4c1754 100644 --- a/gcc/ada/layout.adb +++ b/gcc/ada/layout.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- $Revision: 1.1 $ +-- $Revision$ -- -- -- Copyright (C) 2001 Free Software Foundation, Inc. -- -- -- @@ -579,20 +579,22 @@ package body Layout is Len : Node_Id; type Val_Status_Type is (Const, Dynamic); + + type Val_Type (Status : Val_Status_Type := Const) is + record + case Status is + when Const => Val : Uint; + when Dynamic => Nod : Node_Id; + end case; + end record; -- Shows the status of the value so far. Const means that the value - -- is constant, and Sval is the current constant value. Dynamic means - -- that the value is dynamic, and in this case Snod is the Node_Id of + -- is constant, and Val is the current constant value. Dynamic means + -- that the value is dynamic, and in this case Nod is the Node_Id of -- the expression to compute the value. - Val_Status : Val_Status_Type; - -- Indicate status of value so far - - Sval : Uint := Uint_0; - -- Calculated value so far if Val_Status = Const - -- (initialized to prevent junk warning) - - Snod : Node_Id; - -- Expression value so far if Val_Status = Dynamic + Size : Val_Type; + -- Calculated value so far if Size.Status = Const, + -- or expression value so far if Size.Status = Dynamic. SU_Convert_Required : Boolean := False; -- This is set to True if the final result must be converted from @@ -644,12 +646,10 @@ package body Layout is -- Initialize status from component size if Known_Static_Component_Size (E) then - Val_Status := Const; - Sval := Component_Size (E); + Size := (Const, Component_Size (E)); else - Val_Status := Dynamic; - Snod := Expr_From_SO_Ref (Loc, Component_Size (E)); + Size := (Dynamic, Expr_From_SO_Ref (Loc, Component_Size (E))); end if; -- Loop through indices @@ -678,8 +678,8 @@ package body Layout is -- Current value is constant, evolve value - if Val_Status = Const then - Sval := Sval * S; + if Size.Status = Const then + Size.Val := Size.Val * S; -- Current value is dynamic @@ -695,9 +695,9 @@ package body Layout is SU_Convert_Required := False; end if; - Snod := + Size.Nod := Assoc_Multiply (Loc, - Left_Opnd => Snod, + Left_Opnd => Size.Nod, Right_Opnd => Make_Integer_Literal (Loc, Intval => S)); end if; @@ -712,16 +712,17 @@ package body Layout is -- we want to do the SU conversion after computing the size in -- this case. - if Val_Status = Const then - Val_Status := Dynamic; + if Size.Status = Const then -- If the current value is a multiple of the storage unit, -- then most certainly we can do the conversion now, simply -- by dividing the current value by the storage unit value. -- If this works, we set SU_Convert_Required to False. - if Sval mod SSU = 0 then - Snod := Make_Integer_Literal (Loc, Sval / SSU); + if Size.Val mod SSU = 0 then + + Size := + (Dynamic, Make_Integer_Literal (Loc, Size.Val / SSU)); SU_Convert_Required := False; -- Otherwise, we go ahead and convert the value in bits, @@ -729,7 +730,7 @@ package body Layout is -- final value is indeed properly converted. else - Snod := Make_Integer_Literal (Loc, Sval); + Size := (Dynamic, Make_Integer_Literal (Loc, Size.Val)); SU_Convert_Required := True; end if; end if; @@ -771,8 +772,8 @@ package body Layout is -- Here after processing all bounds to set sizes. If the value is -- a constant, then it is bits, and we just return the value. - if Val_Status = Const then - return Make_Integer_Literal (Loc, Sval); + if Size.Status = Const then + return Make_Integer_Literal (Loc, Size.Val); -- Case where the value is dynamic @@ -781,18 +782,18 @@ package body Layout is if SU_Convert_Required then - -- The expression required is (Snod + SU - 1) / SU + -- The expression required is (Size.Nod + SU - 1) / SU - Snod := + Size.Nod := Make_Op_Divide (Loc, Left_Opnd => Make_Op_Add (Loc, - Left_Opnd => Snod, + Left_Opnd => Size.Nod, Right_Opnd => Make_Integer_Literal (Loc, SSU - 1)), Right_Opnd => Make_Integer_Literal (Loc, SSU)); end if; - return Snod; + return Size.Nod; end if; end Get_Max_Size; @@ -838,33 +839,40 @@ package body Layout is -- question, and whose body is the expression. type Val_Status_Type is (Const, Dynamic, Discrim); - -- Shows the status of the value so far. Const means that the value - -- is constant, and Sval is the current constant value. Dynamic means - -- that the value is dynamic, and in this case Snod is the Node_Id of - -- the expression to compute the value, and Discrim means that at least - -- one bound is a discriminant, in which case Snod is the expression so - -- far (which will be the body of the function). - Val_Status : Val_Status_Type; - -- Indicate status of value so far - - Sval : Uint := Uint_0; - -- Calculated value so far if Val_Status = Const - -- Initialized to prevent junk warning - - Snod : Node_Id; - -- Expression value so far if Val_Status /= Const - - Vtyp : Entity_Id; - -- Variant record type for the formal parameter of the discriminant - -- function V if Val_Status = Discrim. + type Val_Type (Status : Val_Status_Type := Const) is + record + case Status is + when Const => + Val : Uint; + -- Calculated value so far if Val_Status = Const + + when Dynamic | Discrim => + Nod : Node_Id; + -- Expression value so far if Val_Status /= Const + + end case; + end record; + -- Records the value or expression computed so far. Const means that + -- the value is constant, and Val is the current constant value. + -- Dynamic means that the value is dynamic, and in this case Nod is + -- the Node_Id of the expression to compute the value, and Discrim + -- means that at least one bound is a discriminant, in which case Nod + -- is the expression so far (which will be the body of the function). + + Size : Val_Type; + -- Value of size computed so far. See comments above. + + Vtyp : Entity_Id := Empty; + -- Variant record type for the formal parameter of the + -- discriminant function V if Status = Discrim. SU_Convert_Required : Boolean := False; -- This is set to True if the final result must be converted from -- bits to storage units (rounding up to a storage unit boundary). procedure Discrimify (N : in out Node_Id); - -- If N represents a discriminant, then the Val_Status is set to + -- If N represents a discriminant, then the Size.Status is set to -- Discrim, and Vtyp is set. The parameter N is replaced with the -- proper expression to extract the discriminant value from V. @@ -882,9 +890,9 @@ package body Layout is then Set_Size_Depends_On_Discriminant (E); - if Val_Status /= Discrim then - Val_Status := Discrim; + if Size.Status /= Discrim then Decl := Parent (Parent (Entity (N))); + Size := (Discrim, Size.Nod); Vtyp := Defining_Identifier (Decl); end if; @@ -939,12 +947,10 @@ package body Layout is -- Initialize status from component size if Known_Static_Component_Size (E) then - Val_Status := Const; - Sval := Component_Size (E); + Size := (Const, Component_Size (E)); else - Val_Status := Dynamic; - Snod := Expr_From_SO_Ref (Loc, Component_Size (E)); + Size := (Dynamic, Expr_From_SO_Ref (Loc, Component_Size (E))); end if; -- Loop to process array indices @@ -972,8 +978,8 @@ package body Layout is -- If constant, evolve value - if Val_Status = Const then - Sval := Sval * S; + if Size.Status = Const then + Size.Val := Size.Val * S; -- Current value is dynamic @@ -991,9 +997,9 @@ package body Layout is -- Now go ahead and evolve the expression - Snod := + Size.Nod := Assoc_Multiply (Loc, - Left_Opnd => Snod, + Left_Opnd => Size.Nod, Right_Opnd => Make_Integer_Literal (Loc, Intval => S)); end if; @@ -1008,16 +1014,16 @@ package body Layout is -- we want to do the SU conversion after computing the size in -- this case. - if Val_Status = Const then - Val_Status := Dynamic; + if Size.Status = Const then -- If the current value is a multiple of the storage unit, -- then most certainly we can do the conversion now, simply -- by dividing the current value by the storage unit value. -- If this works, we set SU_Convert_Required to False. - if Sval mod SSU = 0 then - Snod := Make_Integer_Literal (Loc, Sval / SSU); + if Size.Val mod SSU = 0 then + Size := + (Dynamic, Make_Integer_Literal (Loc, Size.Val / SSU)); SU_Convert_Required := False; -- Otherwise, we go ahead and convert the value in bits, @@ -1025,7 +1031,7 @@ package body Layout is -- final value is indeed properly converted. else - Snod := Make_Integer_Literal (Loc, Sval); + Size := (Dynamic, Make_Integer_Literal (Loc, Size.Val)); SU_Convert_Required := True; end if; end if; @@ -1073,9 +1079,9 @@ package body Layout is -- At this stage, Len has the expression for the length - Snod := + Size.Nod := Assoc_Multiply (Loc, - Left_Opnd => Snod, + Left_Opnd => Size.Nod, Right_Opnd => Len); end if; @@ -1086,8 +1092,8 @@ package body Layout is -- a constant, then it is bits, and the only thing we need to do -- is to check against explicit given size and do alignment adjust. - if Val_Status = Const then - Set_And_Check_Static_Size (E, Sval, Sval); + if Size.Status = Const then + Set_And_Check_Static_Size (E, Size.Val, Size.Val); Adjust_Esize_Alignment (E); -- Case where the value is dynamic @@ -1097,13 +1103,13 @@ package body Layout is if SU_Convert_Required then - -- The expression required is (Snod + SU - 1) / SU + -- The expression required is (Size.Nod + SU - 1) / SU - Snod := + Size.Nod := Make_Op_Divide (Loc, Left_Opnd => Make_Op_Add (Loc, - Left_Opnd => Snod, + Left_Opnd => Size.Nod, Right_Opnd => Make_Integer_Literal (Loc, SSU - 1)), Right_Opnd => Make_Integer_Literal (Loc, SSU)); end if; @@ -1111,7 +1117,11 @@ package body Layout is -- Now set the dynamic size (the Value_Size is always the same -- as the Object_Size for arrays whose length is dynamic). - Set_Esize (E, SO_Ref_From_Expr (Snod, Insert_Typ, Vtyp)); + -- ??? If Size.Status = Dynamic, Vtyp will not have been set. + -- The added initialization sets it to Empty now, but is this + -- correct? + + Set_Esize (E, SO_Ref_From_Expr (Size.Nod, Insert_Typ, Vtyp)); Set_RM_Size (E, Esize (E)); end if; end Layout_Array_Type; |