-----------------------
when Attribute_Finalization_Size => Finalization_Size : declare
-
function Calculate_Header_Size return Node_Id;
- -- Generate a runtime call to calculate the size of the hidden
- -- header along with any added padding which would precede a
- -- heap-allocated object of the prefix type.
+ -- Generate a runtime call to calculate the size of the hidden header
+ -- along with any added padding which would precede a heap-allocated
+ -- object of the prefix type.
---------------------------
-- Calculate_Header_Size --
begin
-- Generate:
-- Universal_Integer
- -- (Header_Size_With_Padding (N'Alignment))
+ -- (Header_Size_With_Padding (Pref'Alignment))
return
Convert_To (Universal_Integer,
Make_Function_Call (Loc,
Name =>
- New_Occurrence_Of
- (RTE (RE_Header_Size_With_Padding), Loc),
+ New_Occurrence_Of (RTE (RE_Header_Size_With_Padding), Loc),
+
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
- Prefix =>
- New_Copy_Tree (Pref),
+ Prefix => New_Copy_Tree (Pref),
Attribute_Name => Name_Alignment))));
end Calculate_Header_Size;
- -- Local variables
+ -- Local variables
- Size : constant Entity_Id := Make_Temporary (Loc, 'S');
+ Size : Entity_Id;
-- Start of Finalization_Size
begin
- -- An object of a class-wide type requires a runtime check to
+ -- An object of a class-wide type first requires a runtime check to
-- determine whether it is actually controlled or not. Depending on
-- the outcome of this check, the Finalization_Size of the object
-- may be zero or some positive value.
--
- -- In this scenario, Obj'Finalization_Size is expanded into
+ -- In this scenario, Pref'Finalization_Size is expanded into
--
- -- Size : Integer := 0;
+ -- Size : Integer := 0;
--
- -- if Needs_Finalization (Pref'Tag) then
- -- Size :=
- -- Universal_Integer
- -- (Header_Size_With_Padding (Pref'Alignment));
- -- end if;
+ -- if Needs_Finalization (Pref'Tag) then
+ -- Size :=
+ -- Universal_Integer
+ -- (Header_Size_With_Padding (Pref'Alignment));
+ -- end if;
--
-- and the attribute reference is replaced with a reference to Size.
if Is_Class_Wide_Type (Ptyp) then
+ Size := Make_Temporary (Loc, 'S');
+
Insert_Actions (N, New_List (
-- Generate:
-- Generate:
-- if Needs_Finalization (Pref'Tag) then
- -- Size := Universal_Integer
- -- (Header_Size_With_Padding (Pref'Alignment));
+ -- Size :=
+ -- Universal_Integer
+ -- (Header_Size_With_Padding (Pref'Alignment));
-- end if;
Make_If_Statement (Loc,
Condition =>
Make_Function_Call (Loc,
Name =>
- New_Occurrence_Of
- (RTE (RE_Needs_Finalization), Loc),
+ New_Occurrence_Of (RTE (RE_Needs_Finalization), Loc),
+
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
- Attribute_Name => Name_Tag,
- Prefix =>
- New_Copy_Tree (Pref)))),
+ Prefix => New_Copy_Tree (Pref),
+ Attribute_Name => Name_Tag))),
+
Then_Statements => New_List (
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of (Size, Loc),
Rewrite (N, New_Occurrence_Of (Size, Loc));
- -- The the prefix is known to be controlled at compile time.
- -- Calculate its Finalization_Size by calling runtime routine
- -- Header_Size_With_Padding.
+ -- The prefix is known to be controlled at compile time. Calculate
+ -- Finalization_Size by calling function Header_Size_With_Padding.
elsif Needs_Finalization (Ptyp) then
Rewrite (N, Calculate_Header_Size);
- -- The prefix is not a controlled object, its Finalization_Size
- -- is zero.
+ -- The prefix is not an object with controlled parts, so its
+ -- Finalization_Size is zero.
else
Rewrite (N, Make_Integer_Literal (Loc, 0));
-- Here we have a static predicate (note that it could have arisen from
-- an explicitly specified Dynamic_Predicate whose expression met the
- -- rules for being predicate-static).
+ -- rules for being predicate-static). If the expression is known at
+ -- compile time and obeys the predicate, then it is static and must be
+ -- labeled as such, which matters e.g. for case statements. The original
+ -- expression may be a type conversion of a variable with a known value,
+ -- which might otherwise not be marked static.
-- Case of real static predicate
(Val => Make_Real_Literal (Sloc (Expr), Expr_Value_R (Expr)),
Typ => Typ)
then
+ Set_Is_Static_Expression (Expr);
return;
end if;
if Real_Or_String_Static_Predicate_Matches
(Val => Expr_Value_S (Expr), Typ => Typ)
then
+ Set_Is_Static_Expression (Expr);
return;
end if;
-- If static predicate matches, nothing to do
if Choices_Match (Expr, Static_Discrete_Predicate (Typ)) = Match then
+ Set_Is_Static_Expression (Expr);
return;
end if;
end if;