comparison gcc/ada/exp_ch3.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
4 -- -- 4 -- --
5 -- E X P _ C H 3 -- 5 -- E X P _ C H 3 --
6 -- -- 6 -- --
7 -- B o d y -- 7 -- B o d y --
8 -- -- 8 -- --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. -- 9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
10 -- -- 10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under -- 11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- -- 12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- -- 13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
129 -- AI05-0123: Equality on untagged records composes. This procedure 129 -- AI05-0123: Equality on untagged records composes. This procedure
130 -- builds the equality routine for an untagged record that has components 130 -- builds the equality routine for an untagged record that has components
131 -- of a record type that has user-defined primitive equality operations. 131 -- of a record type that has user-defined primitive equality operations.
132 -- The resulting operation is a TSS subprogram. 132 -- The resulting operation is a TSS subprogram.
133 133
134 procedure Build_Variant_Record_Equality (Typ : Entity_Id);
135 -- Create An Equality function for the untagged variant record Typ and
136 -- attach it to the TSS list
137
138 procedure Check_Stream_Attributes (Typ : Entity_Id); 134 procedure Check_Stream_Attributes (Typ : Entity_Id);
139 -- Check that if a limited extension has a parent with user-defined stream 135 -- Check that if a limited extension has a parent with user-defined stream
140 -- attributes, and does not itself have user-defined stream-attributes, 136 -- attributes, and does not itself have user-defined stream-attributes,
141 -- then any limited component of the extension also has the corresponding 137 -- then any limited component of the extension also has the corresponding
142 -- user-defined stream attributes. 138 -- user-defined stream attributes.
203 -- Returns true if the initialization procedure of Typ should be inlined 199 -- Returns true if the initialization procedure of Typ should be inlined
204 200
205 function In_Runtime (E : Entity_Id) return Boolean; 201 function In_Runtime (E : Entity_Id) return Boolean;
206 -- Check if E is defined in the RTL (in a child of Ada or System). Used 202 -- Check if E is defined in the RTL (in a child of Ada or System). Used
207 -- to avoid to bring in the overhead of _Input, _Output for tagged types. 203 -- to avoid to bring in the overhead of _Input, _Output for tagged types.
204
205 function Is_Null_Statement_List (Stmts : List_Id) return Boolean;
206 -- Returns true if Stmts is made of null statements only, possibly wrapped
207 -- in a case statement, recursively. This latter pattern may occur for the
208 -- initialization procedure of an unchecked union.
208 209
209 function Is_User_Defined_Equality (Prim : Node_Id) return Boolean; 210 function Is_User_Defined_Equality (Prim : Node_Id) return Boolean;
210 -- Returns true if Prim is a user defined equality function 211 -- Returns true if Prim is a user defined equality function
211 212
212 function Make_Eq_Body 213 function Make_Eq_Body
518 519
519 procedure Build_Array_Init_Proc (A_Type : Entity_Id; Nod : Node_Id) is 520 procedure Build_Array_Init_Proc (A_Type : Entity_Id; Nod : Node_Id) is
520 Comp_Type : constant Entity_Id := Component_Type (A_Type); 521 Comp_Type : constant Entity_Id := Component_Type (A_Type);
521 Comp_Simple_Init : constant Boolean := 522 Comp_Simple_Init : constant Boolean :=
522 Needs_Simple_Initialization 523 Needs_Simple_Initialization
523 (T => Comp_Type, 524 (Typ => Comp_Type,
524 Consider_IS => 525 Consider_IS =>
525 not (Validity_Check_Copies and Is_Bit_Packed_Array (A_Type))); 526 not (Validity_Check_Copies and Is_Bit_Packed_Array (A_Type)));
526 -- True if the component needs simple initialization, based on its type, 527 -- True if the component needs simple initialization, based on its type,
527 -- plus the fact that we do not do simple initialization for components 528 -- plus the fact that we do not do simple initialization for components
528 -- of bit-packed arrays when validity checks are enabled, because the 529 -- of bit-packed arrays when validity checks are enabled, because the
531 532
532 Body_Stmts : List_Id; 533 Body_Stmts : List_Id;
533 Has_Default_Init : Boolean; 534 Has_Default_Init : Boolean;
534 Index_List : List_Id; 535 Index_List : List_Id;
535 Loc : Source_Ptr; 536 Loc : Source_Ptr;
537 Parameters : List_Id;
536 Proc_Id : Entity_Id; 538 Proc_Id : Entity_Id;
537 539
538 function Init_Component return List_Id; 540 function Init_Component return List_Id;
539 -- Create one statement to initialize one array component, designated 541 -- Create one statement to initialize one array component, designated
540 -- by a full set of indexes. 542 -- by a full set of indexes.
574 return New_List ( 576 return New_List (
575 Make_Assignment_Statement (Loc, 577 Make_Assignment_Statement (Loc,
576 Name => Comp, 578 Name => Comp,
577 Expression => 579 Expression =>
578 Get_Simple_Init_Val 580 Get_Simple_Init_Val
579 (Comp_Type, Nod, Component_Size (A_Type)))); 581 (Typ => Comp_Type,
582 N => Nod,
583 Size => Component_Size (A_Type))));
580 584
581 else 585 else
582 Clean_Task_Names (Comp_Type, Proc_Id); 586 Clean_Task_Names (Comp_Type, Proc_Id);
583 return 587 return
584 Build_Initialization_Call 588 Build_Initialization_Call
585 (Loc, Comp, Comp_Type, 589 (Loc => Loc,
590 Id_Ref => Comp,
591 Typ => Comp_Type,
586 In_Init_Proc => True, 592 In_Init_Proc => True,
587 Enclos_Type => A_Type); 593 Enclos_Type => A_Type);
588 end if; 594 end if;
589 end Init_Component; 595 end Init_Component;
590 596
720 726
721 return; 727 return;
722 end if; 728 end if;
723 729
724 Body_Stmts := Init_One_Dimension (1); 730 Body_Stmts := Init_One_Dimension (1);
731 Parameters := Init_Formals (A_Type);
725 732
726 Discard_Node ( 733 Discard_Node (
727 Make_Subprogram_Body (Loc, 734 Make_Subprogram_Body (Loc,
728 Specification => 735 Specification =>
729 Make_Procedure_Specification (Loc, 736 Make_Procedure_Specification (Loc,
730 Defining_Unit_Name => Proc_Id, 737 Defining_Unit_Name => Proc_Id,
731 Parameter_Specifications => Init_Formals (A_Type)), 738 Parameter_Specifications => Parameters),
732 Declarations => New_List, 739 Declarations => New_List,
733 Handled_Statement_Sequence => 740 Handled_Statement_Sequence =>
734 Make_Handled_Sequence_Of_Statements (Loc, 741 Make_Handled_Sequence_Of_Statements (Loc,
735 Statements => Body_Stmts))); 742 Statements => Body_Stmts)));
736 743
751 -- Associate Init_Proc with type, and determine if the procedure 758 -- Associate Init_Proc with type, and determine if the procedure
752 -- is null (happens because of the Initialize_Scalars pragma case, 759 -- is null (happens because of the Initialize_Scalars pragma case,
753 -- where we have to generate a null procedure in case it is called 760 -- where we have to generate a null procedure in case it is called
754 -- by a client with Initialize_Scalars set). Such procedures have 761 -- by a client with Initialize_Scalars set). Such procedures have
755 -- to be generated, but do not have to be called, so we mark them 762 -- to be generated, but do not have to be called, so we mark them
756 -- as null to suppress the call. 763 -- as null to suppress the call. Kill also warnings for the _Init
764 -- out parameter, which is left entirely uninitialized.
757 765
758 Set_Init_Proc (A_Type, Proc_Id); 766 Set_Init_Proc (A_Type, Proc_Id);
759 767
760 if List_Length (Body_Stmts) = 1 768 if Is_Null_Statement_List (Body_Stmts) then
761
762 -- We must skip SCIL nodes because they may have been added to this
763 -- list by Insert_Actions.
764
765 and then Nkind (First_Non_SCIL_Node (Body_Stmts)) = N_Null_Statement
766 then
767 Set_Is_Null_Init_Proc (Proc_Id); 769 Set_Is_Null_Init_Proc (Proc_Id);
770 Set_Warnings_Off (Defining_Identifier (First (Parameters)));
768 771
769 else 772 else
770 -- Try to build a static aggregate to statically initialize 773 -- Try to build a static aggregate to statically initialize
771 -- objects of the type. This can only be done for constrained 774 -- objects of the type. This can only be done for constrained
772 -- one-dimensional arrays with static bounds. 775 -- one-dimensional arrays with static bounds.
1546 end if; 1549 end if;
1547 1550
1548 else 1551 else
1549 Decls := No_List; 1552 Decls := No_List;
1550 Decl := Empty; 1553 Decl := Empty;
1554 end if;
1555
1556 -- Handle the optionally generated formal *_skip_null_excluding_checks
1557
1558 if Needs_Conditional_Null_Excluding_Check (Full_Init_Type) then
1559
1560 -- Look at the associated node for the object we are referencing
1561 -- and verify that we are expanding a call to an Init_Proc for an
1562 -- internally generated object declaration before passing True and
1563 -- skipping the relevant checks.
1564
1565 if Nkind (Id_Ref) in N_Has_Entity
1566 and then Comes_From_Source (Associated_Node (Id_Ref))
1567 then
1568 Append_To (Args, New_Occurrence_Of (Standard_True, Loc));
1569
1570 -- Otherwise, we pass False to perform null-excluding checks
1571
1572 else
1573 Append_To (Args, New_Occurrence_Of (Standard_False, Loc));
1574 end if;
1551 end if; 1575 end if;
1552 1576
1553 -- Add discriminant values if discriminants are present 1577 -- Add discriminant values if discriminants are present
1554 1578
1555 if Has_Discriminants (Full_Init_Type) then 1579 if Has_Discriminants (Full_Init_Type) then
2174 New_Occurrence_Of (RTE (RE_Storage_Offset), Loc)); 2198 New_Occurrence_Of (RTE (RE_Storage_Offset), Loc));
2175 2199
2176 -- Generate 2200 -- Generate
2177 -- function Fxx (O : in Rec_Typ) return Storage_Offset is 2201 -- function Fxx (O : in Rec_Typ) return Storage_Offset is
2178 -- begin 2202 -- begin
2179 -- return O.Iface_Comp'Position; 2203 -- return -O.Iface_Comp'Position;
2180 -- end Fxx; 2204 -- end Fxx;
2181 2205
2182 Body_Node := New_Node (N_Subprogram_Body, Loc); 2206 Body_Node := New_Node (N_Subprogram_Body, Loc);
2183 Set_Specification (Body_Node, Spec_Node); 2207 Set_Specification (Body_Node, Spec_Node);
2184 2208
2197 Set_Handled_Statement_Sequence (Body_Node, 2221 Set_Handled_Statement_Sequence (Body_Node,
2198 Make_Handled_Sequence_Of_Statements (Loc, 2222 Make_Handled_Sequence_Of_Statements (Loc,
2199 Statements => New_List ( 2223 Statements => New_List (
2200 Make_Simple_Return_Statement (Loc, 2224 Make_Simple_Return_Statement (Loc,
2201 Expression => 2225 Expression =>
2202 Make_Attribute_Reference (Loc, 2226 Make_Op_Minus (Loc,
2203 Prefix => 2227 Make_Attribute_Reference (Loc,
2204 Make_Selected_Component (Loc, 2228 Prefix =>
2205 Prefix => 2229 Make_Selected_Component (Loc,
2206 Unchecked_Convert_To (Acc_Type, 2230 Prefix =>
2207 Make_Identifier (Loc, Name_uO)), 2231 Unchecked_Convert_To (Acc_Type,
2208 Selector_Name => 2232 Make_Identifier (Loc, Name_uO)),
2209 New_Occurrence_Of (Iface_Comp, Loc)), 2233 Selector_Name =>
2210 Attribute_Name => Name_Position))))); 2234 New_Occurrence_Of (Iface_Comp, Loc)),
2235 Attribute_Name => Name_Position))))));
2211 2236
2212 Set_Ekind (Func_Id, E_Function); 2237 Set_Ekind (Func_Id, E_Function);
2213 Set_Mechanism (Func_Id, Default_Mechanism); 2238 Set_Mechanism (Func_Id, Default_Mechanism);
2214 Set_Is_Internal (Func_Id, True); 2239 Set_Is_Internal (Func_Id, True);
2215 2240
2542 and then not Is_Interface (Rec_Type) 2567 and then not Is_Interface (Rec_Type)
2543 and then Has_Interfaces (Rec_Type) 2568 and then Has_Interfaces (Rec_Type)
2544 then 2569 then
2545 declare 2570 declare
2546 Elab_Sec_DT_Stmts_List : constant List_Id := New_List; 2571 Elab_Sec_DT_Stmts_List : constant List_Id := New_List;
2572 Elab_List : List_Id := New_List;
2547 2573
2548 begin 2574 begin
2549 Init_Secondary_Tags 2575 Init_Secondary_Tags
2550 (Typ => Rec_Type, 2576 (Typ => Rec_Type,
2551 Target => Make_Identifier (Loc, Name_uInit), 2577 Target => Make_Identifier (Loc, Name_uInit),
2552 Init_Tags_List => Init_Tags_List, 2578 Init_Tags_List => Init_Tags_List,
2553 Stmts_List => Elab_Sec_DT_Stmts_List, 2579 Stmts_List => Elab_Sec_DT_Stmts_List,
2554 Fixed_Comps => True, 2580 Fixed_Comps => True,
2555 Variable_Comps => False); 2581 Variable_Comps => False);
2556 2582
2557 Append_To (Elab_Sec_DT_Stmts_List, 2583 Elab_List := New_List (
2558 Make_Assignment_Statement (Loc,
2559 Name =>
2560 New_Occurrence_Of
2561 (Access_Disp_Table_Elab_Flag (Rec_Type), Loc),
2562 Expression =>
2563 New_Occurrence_Of (Standard_False, Loc)));
2564
2565 Prepend_List_To (Body_Stmts, New_List (
2566 Make_If_Statement (Loc, 2584 Make_If_Statement (Loc,
2567 Condition => New_Occurrence_Of (Set_Tag, Loc), 2585 Condition => New_Occurrence_Of (Set_Tag, Loc),
2568 Then_Statements => Init_Tags_List), 2586 Then_Statements => Init_Tags_List));
2569 2587
2570 Make_If_Statement (Loc, 2588 if Elab_Flag_Needed (Rec_Type) then
2571 Condition => 2589 Append_To (Elab_Sec_DT_Stmts_List,
2572 New_Occurrence_Of 2590 Make_Assignment_Statement (Loc,
2573 (Access_Disp_Table_Elab_Flag (Rec_Type), Loc), 2591 Name =>
2574 Then_Statements => Elab_Sec_DT_Stmts_List))); 2592 New_Occurrence_Of
2593 (Access_Disp_Table_Elab_Flag (Rec_Type),
2594 Loc),
2595 Expression =>
2596 New_Occurrence_Of (Standard_False, Loc)));
2597
2598 Append_To (Elab_List,
2599 Make_If_Statement (Loc,
2600 Condition =>
2601 New_Occurrence_Of
2602 (Access_Disp_Table_Elab_Flag (Rec_Type), Loc),
2603 Then_Statements => Elab_Sec_DT_Stmts_List));
2604 end if;
2605
2606 Prepend_List_To (Body_Stmts, Elab_List);
2575 end; 2607 end;
2576 else 2608 else
2577 Prepend_To (Body_Stmts, 2609 Prepend_To (Body_Stmts,
2578 Make_If_Statement (Loc, 2610 Make_If_Statement (Loc,
2579 Condition => New_Occurrence_Of (Set_Tag, Loc), 2611 Condition => New_Occurrence_Of (Set_Tag, Loc),
2721 and then Needs_Finalization (Rec_Type) 2753 and then Needs_Finalization (Rec_Type)
2722 and then not Is_Abstract_Type (Rec_Type) 2754 and then not Is_Abstract_Type (Rec_Type)
2723 and then not Restriction_Active (No_Exception_Propagation) 2755 and then not Restriction_Active (No_Exception_Propagation)
2724 then 2756 then
2725 declare 2757 declare
2726 DF_Id : Entity_Id; 2758 DF_Call : Node_Id;
2759 DF_Id : Entity_Id;
2727 2760
2728 begin 2761 begin
2729 -- Create a local version of Deep_Finalize which has indication 2762 -- Create a local version of Deep_Finalize which has indication
2730 -- of partial initialization state. 2763 -- of partial initialization state.
2731 2764
2732 DF_Id := 2765 DF_Id :=
2733 Make_Defining_Identifier (Loc, 2766 Make_Defining_Identifier (Loc,
2734 Chars => New_External_Name (Name_uFinalizer)); 2767 Chars => New_External_Name (Name_uFinalizer));
2735 2768
2736 Append_To (Decls, Make_Local_Deep_Finalize (Rec_Type, DF_Id)); 2769 Append_To (Decls, Make_Local_Deep_Finalize (Rec_Type, DF_Id));
2770
2771 DF_Call :=
2772 Make_Procedure_Call_Statement (Loc,
2773 Name => New_Occurrence_Of (DF_Id, Loc),
2774 Parameter_Associations => New_List (
2775 Make_Identifier (Loc, Name_uInit),
2776 New_Occurrence_Of (Standard_False, Loc)));
2777
2778 -- Do not emit warnings related to the elaboration order when a
2779 -- controlled object is declared before the body of Finalize is
2780 -- seen.
2781
2782 if Legacy_Elaboration_Checks then
2783 Set_No_Elaboration_Check (DF_Call);
2784 end if;
2737 2785
2738 Set_Exception_Handlers (Handled_Stmt_Node, New_List ( 2786 Set_Exception_Handlers (Handled_Stmt_Node, New_List (
2739 Make_Exception_Handler (Loc, 2787 Make_Exception_Handler (Loc,
2740 Exception_Choices => New_List ( 2788 Exception_Choices => New_List (
2741 Make_Others_Choice (Loc)), 2789 Make_Others_Choice (Loc)),
2742 Statements => New_List ( 2790 Statements => New_List (
2743 Make_Procedure_Call_Statement (Loc, 2791 DF_Call,
2744 Name =>
2745 New_Occurrence_Of (DF_Id, Loc),
2746 Parameter_Associations => New_List (
2747 Make_Identifier (Loc, Name_uInit),
2748 New_Occurrence_Of (Standard_False, Loc))),
2749
2750 Make_Raise_Statement (Loc))))); 2792 Make_Raise_Statement (Loc)))));
2751 end; 2793 end;
2752 else 2794 else
2753 Set_Exception_Handlers (Handled_Stmt_Node, No_List); 2795 Set_Exception_Handlers (Handled_Stmt_Node, No_List);
2754 end if; 2796 end if;
2762 -- Associate Init_Proc with type, and determine if the procedure 2804 -- Associate Init_Proc with type, and determine if the procedure
2763 -- is null (happens because of the Initialize_Scalars pragma case, 2805 -- is null (happens because of the Initialize_Scalars pragma case,
2764 -- where we have to generate a null procedure in case it is called 2806 -- where we have to generate a null procedure in case it is called
2765 -- by a client with Initialize_Scalars set). Such procedures have 2807 -- by a client with Initialize_Scalars set). Such procedures have
2766 -- to be generated, but do not have to be called, so we mark them 2808 -- to be generated, but do not have to be called, so we mark them
2767 -- as null to suppress the call. 2809 -- as null to suppress the call. Kill also warnings for the _Init
2810 -- out parameter, which is left entirely uninitialized.
2768 2811
2769 Set_Init_Proc (Rec_Type, Proc_Id); 2812 Set_Init_Proc (Rec_Type, Proc_Id);
2770 2813
2771 if List_Length (Body_Stmts) = 1 2814 if Is_Null_Statement_List (Body_Stmts) then
2772
2773 -- We must skip SCIL nodes because they may have been added to this
2774 -- list by Insert_Actions.
2775
2776 and then Nkind (First_Non_SCIL_Node (Body_Stmts)) = N_Null_Statement
2777 then
2778 Set_Is_Null_Init_Proc (Proc_Id); 2815 Set_Is_Null_Init_Proc (Proc_Id);
2816 Set_Warnings_Off (Defining_Identifier (First (Parameters)));
2779 end if; 2817 end if;
2780 end Build_Init_Procedure; 2818 end Build_Init_Procedure;
2781 2819
2782 --------------------------- 2820 ---------------------------
2783 -- Build_Init_Statements -- 2821 -- Build_Init_Statements --
3086 -- Simple initialization 3124 -- Simple initialization
3087 3125
3088 elsif Component_Needs_Simple_Initialization (Typ) then 3126 elsif Component_Needs_Simple_Initialization (Typ) then
3089 Actions := 3127 Actions :=
3090 Build_Assignment 3128 Build_Assignment
3091 (Id, Get_Simple_Init_Val (Typ, N, Esize (Id))); 3129 (Id => Id,
3130 Default =>
3131 Get_Simple_Init_Val
3132 (Typ => Typ,
3133 N => N,
3134 Size => Esize (Id)));
3092 3135
3093 -- Nothing needed for this case 3136 -- Nothing needed for this case
3094 3137
3095 else 3138 else
3096 Actions := No_List; 3139 Actions := No_List;
3257 end if; 3300 end if;
3258 3301
3259 elsif Component_Needs_Simple_Initialization (Typ) then 3302 elsif Component_Needs_Simple_Initialization (Typ) then
3260 Append_List_To (Stmts, 3303 Append_List_To (Stmts,
3261 Build_Assignment 3304 Build_Assignment
3262 (Id, Get_Simple_Init_Val (Typ, N, Esize (Id)))); 3305 (Id => Id,
3306 Default =>
3307 Get_Simple_Init_Val
3308 (Typ => Typ,
3309 N => N,
3310 Size => Esize (Id))));
3263 end if; 3311 end if;
3264 end if; 3312 end if;
3265 3313
3266 Next_Non_Pragma (Decl); 3314 Next_Non_Pragma (Decl);
3267 end loop; 3315 end loop;
4201 -- Build_Variant_Record_Equality -- 4249 -- Build_Variant_Record_Equality --
4202 ----------------------------------- 4250 -----------------------------------
4203 4251
4204 -- Generates: 4252 -- Generates:
4205 4253
4206 -- function _Equality (X, Y : T) return Boolean is 4254 -- function <<Body_Id>> (Left, Right : T) return Boolean is
4255 -- [ X : T renames Left; ]
4256 -- [ Y : T renames Right; ]
4257 -- -- The above renamings are generated only if the parameters of
4258 -- -- this built function (which are passed by the caller) are not
4259 -- -- named 'X' and 'Y'; these names are required to reuse several
4260 -- -- expander routines when generating this body.
4261
4207 -- begin 4262 -- begin
4208 -- -- Compare discriminants 4263 -- -- Compare discriminants
4209 4264
4210 -- if X.D1 /= Y.D1 or else X.D2 /= Y.D2 or else ... then 4265 -- if X.D1 /= Y.D1 or else X.D2 /= Y.D2 or else ... then
4211 -- return False; 4266 -- return False;
4232 -- end case; 4287 -- end case;
4233 4288
4234 -- return True; 4289 -- return True;
4235 -- end _Equality; 4290 -- end _Equality;
4236 4291
4237 procedure Build_Variant_Record_Equality (Typ : Entity_Id) is 4292 function Build_Variant_Record_Equality
4238 Loc : constant Source_Ptr := Sloc (Typ); 4293 (Typ : Entity_Id;
4239 4294 Body_Id : Entity_Id;
4240 F : constant Entity_Id := 4295 Param_Specs : List_Id) return Node_Id
4241 Make_Defining_Identifier (Loc, 4296 is
4242 Chars => Make_TSS_Name (Typ, TSS_Composite_Equality)); 4297 Loc : constant Source_Ptr := Sloc (Typ);
4243 4298 Def : constant Node_Id := Parent (Typ);
4244 X : constant Entity_Id := Make_Defining_Identifier (Loc, Name_X); 4299 Comps : constant Node_Id := Component_List (Type_Definition (Def));
4245 Y : constant Entity_Id := Make_Defining_Identifier (Loc, Name_Y); 4300 Left : constant Entity_Id := Defining_Identifier (First (Param_Specs));
4246 4301 Right : constant Entity_Id :=
4247 Def : constant Node_Id := Parent (Typ); 4302 Defining_Identifier (Next (First (Param_Specs)));
4248 Comps : constant Node_Id := Component_List (Type_Definition (Def)); 4303 Decls : constant List_Id := New_List;
4249 Stmts : constant List_Id := New_List; 4304 Stmts : constant List_Id := New_List;
4250 Pspecs : constant List_Id := New_List; 4305
4306 Subp_Body : Node_Id;
4251 4307
4252 begin 4308 begin
4253 -- If we have a variant record with restriction No_Implicit_Conditionals 4309 pragma Assert (not Is_Tagged_Type (Typ));
4254 -- in effect, then we skip building the procedure. This is safe because 4310
4255 -- if we can see the restriction, so can any caller, calls to equality 4311 -- In order to reuse the expander routines Make_Eq_If and Make_Eq_Case
4256 -- test routines are not allowed for variant records if this restriction 4312 -- the name of the formals must be X and Y; otherwise we generate two
4257 -- is active. 4313 -- renaming declarations for such purpose.
4258 4314
4259 if Restriction_Active (No_Implicit_Conditionals) then 4315 if Chars (Left) /= Name_X then
4260 return; 4316 Append_To (Decls,
4317 Make_Object_Renaming_Declaration (Loc,
4318 Defining_Identifier => Make_Defining_Identifier (Loc, Name_X),
4319 Subtype_Mark => New_Occurrence_Of (Typ, Loc),
4320 Name => Make_Identifier (Loc, Chars (Left))));
4261 end if; 4321 end if;
4262 4322
4263 -- Derived Unchecked_Union types no longer inherit the equality function 4323 if Chars (Right) /= Name_Y then
4264 -- of their parent. 4324 Append_To (Decls,
4265 4325 Make_Object_Renaming_Declaration (Loc,
4266 if Is_Derived_Type (Typ) 4326 Defining_Identifier => Make_Defining_Identifier (Loc, Name_Y),
4267 and then not Is_Unchecked_Union (Typ) 4327 Subtype_Mark => New_Occurrence_Of (Typ, Loc),
4268 and then not Has_New_Non_Standard_Rep (Typ) 4328 Name => Make_Identifier (Loc, Chars (Right))));
4269 then
4270 declare
4271 Parent_Eq : constant Entity_Id :=
4272 TSS (Root_Type (Typ), TSS_Composite_Equality);
4273 begin
4274 if Present (Parent_Eq) then
4275 Copy_TSS (Parent_Eq, Typ);
4276 return;
4277 end if;
4278 end;
4279 end if; 4329 end if;
4280
4281 Discard_Node (
4282 Make_Subprogram_Body (Loc,
4283 Specification =>
4284 Make_Function_Specification (Loc,
4285 Defining_Unit_Name => F,
4286 Parameter_Specifications => Pspecs,
4287 Result_Definition => New_Occurrence_Of (Standard_Boolean, Loc)),
4288 Declarations => New_List,
4289 Handled_Statement_Sequence =>
4290 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts)));
4291
4292 Append_To (Pspecs,
4293 Make_Parameter_Specification (Loc,
4294 Defining_Identifier => X,
4295 Parameter_Type => New_Occurrence_Of (Typ, Loc)));
4296
4297 Append_To (Pspecs,
4298 Make_Parameter_Specification (Loc,
4299 Defining_Identifier => Y,
4300 Parameter_Type => New_Occurrence_Of (Typ, Loc)));
4301 4330
4302 -- Unchecked_Unions require additional machinery to support equality. 4331 -- Unchecked_Unions require additional machinery to support equality.
4303 -- Two extra parameters (A and B) are added to the equality function 4332 -- Two extra parameters (A and B) are added to the equality function
4304 -- parameter list for each discriminant of the type, in order to 4333 -- parameter list for each discriminant of the type, in order to
4305 -- capture the inferred values of the discriminants in equality calls. 4334 -- capture the inferred values of the discriminants in equality calls.
4306 -- The names of the parameters match the names of the corresponding 4335 -- The names of the parameters match the names of the corresponding
4307 -- discriminant, with an added suffix. 4336 -- discriminant, with an added suffix.
4308 4337
4309 if Is_Unchecked_Union (Typ) then 4338 if Is_Unchecked_Union (Typ) then
4310 declare 4339 declare
4340 A : Entity_Id;
4341 B : Entity_Id;
4311 Discr : Entity_Id; 4342 Discr : Entity_Id;
4312 Discr_Type : Entity_Id; 4343 Discr_Type : Entity_Id;
4313 A, B : Entity_Id;
4314 New_Discrs : Elist_Id; 4344 New_Discrs : Elist_Id;
4315 4345
4316 begin 4346 begin
4317 New_Discrs := New_Elmt_List; 4347 New_Discrs := New_Elmt_List;
4318 4348
4319 Discr := First_Discriminant (Typ); 4349 Discr := First_Discriminant (Typ);
4320 while Present (Discr) loop 4350 while Present (Discr) loop
4321 Discr_Type := Etype (Discr); 4351 Discr_Type := Etype (Discr);
4322 A := Make_Defining_Identifier (Loc, 4352
4323 Chars => New_External_Name (Chars (Discr), 'A')); 4353 A :=
4324 4354 Make_Defining_Identifier (Loc,
4325 B := Make_Defining_Identifier (Loc, 4355 Chars => New_External_Name (Chars (Discr), 'A'));
4326 Chars => New_External_Name (Chars (Discr), 'B')); 4356
4357 B :=
4358 Make_Defining_Identifier (Loc,
4359 Chars => New_External_Name (Chars (Discr), 'B'));
4327 4360
4328 -- Add new parameters to the parameter list 4361 -- Add new parameters to the parameter list
4329 4362
4330 Append_To (Pspecs, 4363 Append_To (Param_Specs,
4331 Make_Parameter_Specification (Loc, 4364 Make_Parameter_Specification (Loc,
4332 Defining_Identifier => A, 4365 Defining_Identifier => A,
4333 Parameter_Type => 4366 Parameter_Type =>
4334 New_Occurrence_Of (Discr_Type, Loc))); 4367 New_Occurrence_Of (Discr_Type, Loc)));
4335 4368
4336 Append_To (Pspecs, 4369 Append_To (Param_Specs,
4337 Make_Parameter_Specification (Loc, 4370 Make_Parameter_Specification (Loc,
4338 Defining_Identifier => B, 4371 Defining_Identifier => B,
4339 Parameter_Type => 4372 Parameter_Type =>
4340 New_Occurrence_Of (Discr_Type, Loc))); 4373 New_Occurrence_Of (Discr_Type, Loc)));
4341 4374
4360 New_Occurrence_Of (Standard_False, Loc))))); 4393 New_Occurrence_Of (Standard_False, Loc)))));
4361 Next_Discriminant (Discr); 4394 Next_Discriminant (Discr);
4362 end loop; 4395 end loop;
4363 4396
4364 -- Generate component-by-component comparison. Note that we must 4397 -- Generate component-by-component comparison. Note that we must
4365 -- propagate the inferred discriminants formals to act as 4398 -- propagate the inferred discriminants formals to act as the case
4366 -- the case statement switch. Their value is added when an 4399 -- statement switch. Their value is added when an equality call on
4367 -- equality call on unchecked unions is expanded. 4400 -- unchecked unions is expanded.
4368 4401
4369 Append_List_To (Stmts, Make_Eq_Case (Typ, Comps, New_Discrs)); 4402 Append_List_To (Stmts, Make_Eq_Case (Typ, Comps, New_Discrs));
4370 end; 4403 end;
4371 4404
4372 -- Normal case (not unchecked union) 4405 -- Normal case (not unchecked union)
4379 4412
4380 Append_To (Stmts, 4413 Append_To (Stmts,
4381 Make_Simple_Return_Statement (Loc, 4414 Make_Simple_Return_Statement (Loc,
4382 Expression => New_Occurrence_Of (Standard_True, Loc))); 4415 Expression => New_Occurrence_Of (Standard_True, Loc)));
4383 4416
4384 Set_TSS (Typ, F); 4417 Subp_Body :=
4385 Set_Is_Pure (F); 4418 Make_Subprogram_Body (Loc,
4386 4419 Specification =>
4387 if not Debug_Generated_Code then 4420 Make_Function_Specification (Loc,
4388 Set_Debug_Info_Off (F); 4421 Defining_Unit_Name => Body_Id,
4389 end if; 4422 Parameter_Specifications => Param_Specs,
4423 Result_Definition =>
4424 New_Occurrence_Of (Standard_Boolean, Loc)),
4425 Declarations => Decls,
4426 Handled_Statement_Sequence =>
4427 Make_Handled_Sequence_Of_Statements (Loc,
4428 Statements => Stmts));
4429
4430 return Subp_Body;
4390 end Build_Variant_Record_Equality; 4431 end Build_Variant_Record_Equality;
4391 4432
4392 ----------------------------- 4433 -----------------------------
4393 -- Check_Stream_Attributes -- 4434 -- Check_Stream_Attributes --
4394 ----------------------------- 4435 -----------------------------
4929 ------------------------------- 4970 -------------------------------
4930 -- Expand_Freeze_Record_Type -- 4971 -- Expand_Freeze_Record_Type --
4931 ------------------------------- 4972 -------------------------------
4932 4973
4933 procedure Expand_Freeze_Record_Type (N : Node_Id) is 4974 procedure Expand_Freeze_Record_Type (N : Node_Id) is
4975 procedure Build_Variant_Record_Equality (Typ : Entity_Id);
4976 -- Create An Equality function for the untagged variant record Typ and
4977 -- attach it to the TSS list.
4978
4979 -----------------------------------
4980 -- Build_Variant_Record_Equality --
4981 -----------------------------------
4982
4983 procedure Build_Variant_Record_Equality (Typ : Entity_Id) is
4984 Loc : constant Source_Ptr := Sloc (Typ);
4985 F : constant Entity_Id :=
4986 Make_Defining_Identifier (Loc,
4987 Chars => Make_TSS_Name (Typ, TSS_Composite_Equality));
4988 begin
4989 -- For a variant record with restriction No_Implicit_Conditionals
4990 -- in effect we skip building the procedure. This is safe because
4991 -- if we can see the restriction, so can any caller, and calls to
4992 -- equality test routines are not allowed for variant records if
4993 -- this restriction is active.
4994
4995 if Restriction_Active (No_Implicit_Conditionals) then
4996 return;
4997 end if;
4998
4999 -- Derived Unchecked_Union types no longer inherit the equality
5000 -- function of their parent.
5001
5002 if Is_Derived_Type (Typ)
5003 and then not Is_Unchecked_Union (Typ)
5004 and then not Has_New_Non_Standard_Rep (Typ)
5005 then
5006 declare
5007 Parent_Eq : constant Entity_Id :=
5008 TSS (Root_Type (Typ), TSS_Composite_Equality);
5009 begin
5010 if Present (Parent_Eq) then
5011 Copy_TSS (Parent_Eq, Typ);
5012 return;
5013 end if;
5014 end;
5015 end if;
5016
5017 Discard_Node (
5018 Build_Variant_Record_Equality
5019 (Typ => Typ,
5020 Body_Id => F,
5021 Param_Specs => New_List (
5022 Make_Parameter_Specification (Loc,
5023 Defining_Identifier =>
5024 Make_Defining_Identifier (Loc, Name_X),
5025 Parameter_Type => New_Occurrence_Of (Typ, Loc)),
5026
5027 Make_Parameter_Specification (Loc,
5028 Defining_Identifier =>
5029 Make_Defining_Identifier (Loc, Name_Y),
5030 Parameter_Type => New_Occurrence_Of (Typ, Loc)))));
5031
5032 Set_TSS (Typ, F);
5033 Set_Is_Pure (F);
5034
5035 if not Debug_Generated_Code then
5036 Set_Debug_Info_Off (F);
5037 end if;
5038 end Build_Variant_Record_Equality;
5039
5040 -- Local variables
5041
4934 Typ : constant Node_Id := Entity (N); 5042 Typ : constant Node_Id := Entity (N);
4935 Typ_Decl : constant Node_Id := Parent (Typ); 5043 Typ_Decl : constant Node_Id := Parent (Typ);
4936 5044
4937 Comp : Entity_Id; 5045 Comp : Entity_Id;
4938 Comp_Typ : Entity_Id; 5046 Comp_Typ : Entity_Id;
5572 function Build_Equivalent_Aggregate return Boolean; 5680 function Build_Equivalent_Aggregate return Boolean;
5573 -- If the object has a constrained discriminated type and no initial 5681 -- If the object has a constrained discriminated type and no initial
5574 -- value, it may be possible to build an equivalent aggregate instead, 5682 -- value, it may be possible to build an equivalent aggregate instead,
5575 -- and prevent an actual call to the initialization procedure. 5683 -- and prevent an actual call to the initialization procedure.
5576 5684
5577 procedure Check_Large_Modular_Array;
5578 -- Check that the size of the array can be computed without overflow,
5579 -- and generate a Storage_Error otherwise. This is only relevant for
5580 -- array types whose index in a (mod 2**64) type, where wrap-around
5581 -- arithmetic might yield a meaningless value for the length of the
5582 -- array, or its corresponding attribute.
5583
5584 procedure Count_Default_Sized_Task_Stacks 5685 procedure Count_Default_Sized_Task_Stacks
5585 (Typ : Entity_Id; 5686 (Typ : Entity_Id;
5586 Pri_Stacks : out Int; 5687 Pri_Stacks : out Int;
5587 Sec_Stacks : out Int); 5688 Sec_Stacks : out Int);
5588 -- Count the number of default-sized primary and secondary task stacks 5689 -- Count the number of default-sized primary and secondary task stacks
5725 else 5826 else
5726 return False; 5827 return False;
5727 end if; 5828 end if;
5728 end Build_Equivalent_Aggregate; 5829 end Build_Equivalent_Aggregate;
5729 5830
5730 -------------------------------
5731 -- Check_Large_Modular_Array --
5732 -------------------------------
5733
5734 procedure Check_Large_Modular_Array is
5735 Index_Typ : Entity_Id;
5736
5737 begin
5738 if Is_Array_Type (Typ)
5739 and then Is_Modular_Integer_Type (Etype (First_Index (Typ)))
5740 then
5741 -- To prevent arithmetic overflow with large values, we raise
5742 -- Storage_Error under the following guard:
5743
5744 -- (Arr'Last / 2 - Arr'First / 2) > (2 ** 30)
5745
5746 -- This takes care of the boundary case, but it is preferable to
5747 -- use a smaller limit, because even on 64-bit architectures an
5748 -- array of more than 2 ** 30 bytes is likely to raise
5749 -- Storage_Error.
5750
5751 Index_Typ := Etype (First_Index (Typ));
5752
5753 if RM_Size (Index_Typ) = RM_Size (Standard_Long_Long_Integer) then
5754 Insert_Action (N,
5755 Make_Raise_Storage_Error (Loc,
5756 Condition =>
5757 Make_Op_Ge (Loc,
5758 Left_Opnd =>
5759 Make_Op_Subtract (Loc,
5760 Left_Opnd =>
5761 Make_Op_Divide (Loc,
5762 Left_Opnd =>
5763 Make_Attribute_Reference (Loc,
5764 Prefix =>
5765 New_Occurrence_Of (Typ, Loc),
5766 Attribute_Name => Name_Last),
5767 Right_Opnd =>
5768 Make_Integer_Literal (Loc, Uint_2)),
5769 Right_Opnd =>
5770 Make_Op_Divide (Loc,
5771 Left_Opnd =>
5772 Make_Attribute_Reference (Loc,
5773 Prefix =>
5774 New_Occurrence_Of (Typ, Loc),
5775 Attribute_Name => Name_First),
5776 Right_Opnd =>
5777 Make_Integer_Literal (Loc, Uint_2))),
5778 Right_Opnd =>
5779 Make_Integer_Literal (Loc, (Uint_2 ** 30))),
5780 Reason => SE_Object_Too_Large));
5781 end if;
5782 end if;
5783 end Check_Large_Modular_Array;
5784
5785 ------------------------------------- 5831 -------------------------------------
5786 -- Count_Default_Sized_Task_Stacks -- 5832 -- Count_Default_Sized_Task_Stacks --
5787 ------------------------------------- 5833 -------------------------------------
5788 5834
5789 procedure Count_Default_Sized_Task_Stacks 5835 procedure Count_Default_Sized_Task_Stacks
5902 procedure Default_Initialize_Object (After : Node_Id) is 5948 procedure Default_Initialize_Object (After : Node_Id) is
5903 function New_Object_Reference return Node_Id; 5949 function New_Object_Reference return Node_Id;
5904 -- Return a new reference to Def_Id with attributes Assignment_OK and 5950 -- Return a new reference to Def_Id with attributes Assignment_OK and
5905 -- Must_Not_Freeze already set. 5951 -- Must_Not_Freeze already set.
5906 5952
5953 function Simple_Initialization_OK
5954 (Init_Typ : Entity_Id) return Boolean;
5955 -- Determine whether object declaration N with entity Def_Id needs
5956 -- simple initialization, assuming that it is of type Init_Typ.
5957
5907 -------------------------- 5958 --------------------------
5908 -- New_Object_Reference -- 5959 -- New_Object_Reference --
5909 -------------------------- 5960 --------------------------
5910 5961
5911 function New_Object_Reference return Node_Id is 5962 function New_Object_Reference return Node_Id is
5922 Set_Assignment_OK (Obj_Ref); 5973 Set_Assignment_OK (Obj_Ref);
5923 Set_Must_Not_Freeze (Obj_Ref); 5974 Set_Must_Not_Freeze (Obj_Ref);
5924 5975
5925 return Obj_Ref; 5976 return Obj_Ref;
5926 end New_Object_Reference; 5977 end New_Object_Reference;
5978
5979 ------------------------------
5980 -- Simple_Initialization_OK --
5981 ------------------------------
5982
5983 function Simple_Initialization_OK
5984 (Init_Typ : Entity_Id) return Boolean
5985 is
5986 begin
5987 -- Do not consider the object declaration if it comes with an
5988 -- initialization expression, or is internal in which case it
5989 -- will be assigned later.
5990
5991 return
5992 not Is_Internal (Def_Id)
5993 and then not Has_Init_Expression (N)
5994 and then Needs_Simple_Initialization
5995 (Typ => Init_Typ,
5996 Consider_IS =>
5997 Initialize_Scalars
5998 and then No (Following_Address_Clause (N)));
5999 end Simple_Initialization_OK;
5927 6000
5928 -- Local variables 6001 -- Local variables
5929 6002
5930 Exceptions_OK : constant Boolean := 6003 Exceptions_OK : constant Boolean :=
5931 not Restriction_Active (No_Exception_Propagation); 6004 not Restriction_Active (No_Exception_Propagation);
5984 if Has_Non_Null_Base_Init_Proc (Typ) 6057 if Has_Non_Null_Base_Init_Proc (Typ)
5985 and then not No_Initialization (N) 6058 and then not No_Initialization (N)
5986 and then not Initialization_Suppressed (Typ) 6059 and then not Initialization_Suppressed (Typ)
5987 then 6060 then
5988 -- Do not initialize the components if No_Default_Initialization 6061 -- Do not initialize the components if No_Default_Initialization
5989 -- applies as the actual restriction check will occur later 6062 -- applies as the actual restriction check will occur later when
5990 -- when the object is frozen as it is not known yet whether the 6063 -- the object is frozen as it is not known yet whether the object
5991 -- object is imported or not. 6064 -- is imported or not.
5992 6065
5993 if not Restriction_Active (No_Default_Initialization) then 6066 if not Restriction_Active (No_Default_Initialization) then
5994 6067
5995 -- If the values of the components are compile-time known, use 6068 -- If the values of the components are compile-time known, use
5996 -- their prebuilt aggregate form directly. 6069 -- their prebuilt aggregate form directly.
5997 6070
5998 Aggr_Init := Static_Initialization (Base_Init_Proc (Typ)); 6071 Aggr_Init := Static_Initialization (Base_Init_Proc (Typ));
5999 6072
6000 if Present (Aggr_Init) then 6073 if Present (Aggr_Init) then
6001 Set_Expression 6074 Set_Expression (N,
6002 (N, New_Copy_Tree (Aggr_Init, New_Scope => Current_Scope)); 6075 New_Copy_Tree (Aggr_Init, New_Scope => Current_Scope));
6003 6076
6004 -- If type has discriminants, try to build an equivalent 6077 -- If type has discriminants, try to build an equivalent
6005 -- aggregate using discriminant values from the declaration. 6078 -- aggregate using discriminant values from the declaration.
6006 -- This is a useful optimization, in particular if restriction 6079 -- This is a useful optimization, in particular if restriction
6007 -- No_Elaboration_Code is active. 6080 -- No_Elaboration_Code is active.
6008 6081
6009 elsif Build_Equivalent_Aggregate then 6082 elsif Build_Equivalent_Aggregate then
6010 null; 6083 null;
6011 6084
6085 -- Optimize the default initialization of an array object when
6086 -- pragma Initialize_Scalars or Normalize_Scalars is in effect.
6087 -- Construct an in-place initialization aggregate which may be
6088 -- convert into a fast memset by the backend.
6089
6090 elsif Init_Or_Norm_Scalars
6091 and then Is_Array_Type (Typ)
6092
6093 -- The array must lack atomic components because they are
6094 -- treated as non-static, and as a result the backend will
6095 -- not initialize the memory in one go.
6096
6097 and then not Has_Atomic_Components (Typ)
6098
6099 -- The array must not be packed because the invalid values
6100 -- in System.Scalar_Values are multiples of Storage_Unit.
6101
6102 and then not Is_Packed (Typ)
6103
6104 -- The array must have static non-empty ranges, otherwise
6105 -- the backend cannot initialize the memory in one go.
6106
6107 and then Has_Static_Non_Empty_Array_Bounds (Typ)
6108
6109 -- The optimization is only relevant for arrays of scalar
6110 -- types.
6111
6112 and then Is_Scalar_Type (Component_Type (Typ))
6113
6114 -- Similar to regular array initialization using a type
6115 -- init proc, predicate checks are not performed because the
6116 -- initialization values are intentionally invalid, and may
6117 -- violate the predicate.
6118
6119 and then not Has_Predicates (Component_Type (Typ))
6120
6121 -- The component type must have a single initialization value
6122
6123 and then Simple_Initialization_OK (Component_Type (Typ))
6124 then
6125 Set_No_Initialization (N, False);
6126 Set_Expression (N,
6127 Get_Simple_Init_Val
6128 (Typ => Typ,
6129 N => Obj_Def,
6130 Size => Esize (Def_Id)));
6131
6132 Analyze_And_Resolve
6133 (Expression (N), Typ, Suppress => All_Checks);
6134
6012 -- Otherwise invoke the type init proc, generate: 6135 -- Otherwise invoke the type init proc, generate:
6013 -- Type_Init_Proc (Obj); 6136 -- Type_Init_Proc (Obj);
6014 6137
6015 else 6138 else
6016 Obj_Ref := New_Object_Reference; 6139 Obj_Ref := New_Object_Reference;
6022 Comp_Init := Build_Initialization_Call (Loc, Obj_Ref, Typ); 6145 Comp_Init := Build_Initialization_Call (Loc, Obj_Ref, Typ);
6023 end if; 6146 end if;
6024 end if; 6147 end if;
6025 6148
6026 -- Provide a default value if the object needs simple initialization 6149 -- Provide a default value if the object needs simple initialization
6027 -- and does not already have an initial value. A generated temporary 6150
6028 -- does not require initialization because it will be assigned later. 6151 elsif Simple_Initialization_OK (Typ) then
6029
6030 elsif Needs_Simple_Initialization
6031 (Typ, Initialize_Scalars
6032 and then No (Following_Address_Clause (N)))
6033 and then not Is_Internal (Def_Id)
6034 and then not Has_Init_Expression (N)
6035 then
6036 Set_No_Initialization (N, False); 6152 Set_No_Initialization (N, False);
6037 Set_Expression (N, Get_Simple_Init_Val (Typ, N, Esize (Def_Id))); 6153 Set_Expression (N,
6154 Get_Simple_Init_Val
6155 (Typ => Typ,
6156 N => Obj_Def,
6157 Size => Esize (Def_Id)));
6158
6038 Analyze_And_Resolve (Expression (N), Typ); 6159 Analyze_And_Resolve (Expression (N), Typ);
6039 end if; 6160 end if;
6040 6161
6041 -- Initialize the object, generate: 6162 -- Initialize the object, generate:
6042 -- [Deep_]Initialize (Obj); 6163 -- [Deep_]Initialize (Obj);
6073 (Obj_Ref => New_Object_Reference, 6194 (Obj_Ref => New_Object_Reference,
6074 Typ => Typ, 6195 Typ => Typ,
6075 Skip_Self => True); 6196 Skip_Self => True);
6076 6197
6077 if Present (Fin_Call) then 6198 if Present (Fin_Call) then
6199
6200 -- Do not emit warnings related to the elaboration order when a
6201 -- controlled object is declared before the body of Finalize is
6202 -- seen.
6203
6204 if Legacy_Elaboration_Checks then
6205 Set_No_Elaboration_Check (Fin_Call);
6206 end if;
6207
6078 Fin_Block := 6208 Fin_Block :=
6079 Make_Block_Statement (Loc, 6209 Make_Block_Statement (Loc,
6080 Declarations => No_List, 6210 Declarations => No_List,
6081 6211
6082 Handled_Statement_Sequence => 6212 Handled_Statement_Sequence =>
6277 -- subprograms. 6407 -- subprograms.
6278 6408
6279 -- Force construction of dispatch tables of library level tagged types 6409 -- Force construction of dispatch tables of library level tagged types
6280 6410
6281 if Tagged_Type_Expansion 6411 if Tagged_Type_Expansion
6282 and then Static_Dispatch_Tables 6412 and then Building_Static_Dispatch_Tables
6283 and then Is_Library_Level_Entity (Def_Id) 6413 and then Is_Library_Level_Entity (Def_Id)
6284 and then Is_Library_Level_Tagged_Type (Base_Typ) 6414 and then Is_Library_Level_Tagged_Type (Base_Typ)
6285 and then Ekind_In (Base_Typ, E_Record_Type, 6415 and then Ekind_In (Base_Typ, E_Record_Type,
6286 E_Protected_Type, 6416 E_Protected_Type,
6287 E_Task_Type) 6417 E_Task_Type)
6316 6446
6317 if Has_Task (Typ) then 6447 if Has_Task (Typ) then
6318 Build_Activation_Chain_Entity (N); 6448 Build_Activation_Chain_Entity (N);
6319 Build_Master_Entity (Def_Id); 6449 Build_Master_Entity (Def_Id);
6320 end if; 6450 end if;
6321
6322 Check_Large_Modular_Array;
6323 6451
6324 -- If No_Implicit_Heap_Allocations or No_Implicit_Task_Allocations 6452 -- If No_Implicit_Heap_Allocations or No_Implicit_Task_Allocations
6325 -- restrictions are active then default-sized secondary stacks are 6453 -- restrictions are active then default-sized secondary stacks are
6326 -- generated by the binder and allocated by SS_Init. To provide the 6454 -- generated by the binder and allocated by SS_Init. To provide the
6327 -- binder the number of stacks to generate, the number of default-sized 6455 -- binder the number of stacks to generate, the number of default-sized
6725 -- entities are declared (they must have their own Sloc). 6853 -- entities are declared (they must have their own Sloc).
6726 6854
6727 declare 6855 declare
6728 New_Id : constant Entity_Id := Defining_Identifier (N); 6856 New_Id : constant Entity_Id := Defining_Identifier (N);
6729 Next_Temp : constant Entity_Id := Next_Entity (New_Id); 6857 Next_Temp : constant Entity_Id := Next_Entity (New_Id);
6730 S_Flag : constant Boolean := 6858 Save_CFS : constant Boolean :=
6731 Comes_From_Source (Def_Id); 6859 Comes_From_Source (Def_Id);
6860 Save_SP : constant Node_Id := SPARK_Pragma (Def_Id);
6861 Save_SPI : constant Boolean :=
6862 SPARK_Pragma_Inherited (Def_Id);
6732 6863
6733 begin 6864 begin
6734 Set_Next_Entity (New_Id, Next_Entity (Def_Id)); 6865 Link_Entities (New_Id, Next_Entity (Def_Id));
6735 Set_Next_Entity (Def_Id, Next_Temp); 6866 Link_Entities (Def_Id, Next_Temp);
6736 6867
6737 Set_Chars (Defining_Identifier (N), Chars (Def_Id)); 6868 Set_Chars (Defining_Identifier (N), Chars (Def_Id));
6738 Set_Homonym (Defining_Identifier (N), Homonym (Def_Id)); 6869 Set_Homonym (Defining_Identifier (N), Homonym (Def_Id));
6739 Set_Ekind (Defining_Identifier (N), Ekind (Def_Id)); 6870 Set_Ekind (Defining_Identifier (N), Ekind (Def_Id));
6740 Set_Sloc (Defining_Identifier (N), Sloc (Def_Id)); 6871 Set_Sloc (Defining_Identifier (N), Sloc (Def_Id));
6741 6872
6742 Set_Comes_From_Source (Def_Id, False); 6873 Set_Comes_From_Source (Def_Id, False);
6874
6875 -- ??? This is extremely dangerous!!! Exchanging entities
6876 -- is very low level, and as a result it resets flags and
6877 -- fields which belong to the original Def_Id. Several of
6878 -- these attributes are saved and restored, but there may
6879 -- be many more that need to be preserverd.
6880
6743 Exchange_Entities (Defining_Identifier (N), Def_Id); 6881 Exchange_Entities (Defining_Identifier (N), Def_Id);
6744 Set_Comes_From_Source (Def_Id, S_Flag); 6882
6883 -- Restore clobbered attributes
6884
6885 Set_Comes_From_Source (Def_Id, Save_CFS);
6886 Set_SPARK_Pragma (Def_Id, Save_SP);
6887 Set_SPARK_Pragma_Inherited (Def_Id, Save_SPI);
6745 end; 6888 end;
6746 end; 6889 end;
6747 end if; 6890 end if;
6748 6891
6749 return; 6892 return;
6884 if Is_Entity_Name (Expr_Q) then 7027 if Is_Entity_Name (Expr_Q) then
6885 Set_OK_To_Rename (Entity (Expr_Q)); 7028 Set_OK_To_Rename (Entity (Expr_Q));
6886 7029
6887 -- If we cannot convert the expression into a renaming we must 7030 -- If we cannot convert the expression into a renaming we must
6888 -- consider it an internal error because the backend does not 7031 -- consider it an internal error because the backend does not
6889 -- have support to handle it. 7032 -- have support to handle it. Also, when a raise expression is
6890 7033 -- encountered we ignore it since it doesn't return a value and
6891 else 7034 -- thus cannot trigger a copy.
7035
7036 elsif Nkind (Original_Node (Expr_Q)) /= N_Raise_Expression then
6892 pragma Assert (False); 7037 pragma Assert (False);
6893 raise Program_Error; 7038 raise Program_Error;
6894 end if; 7039 end if;
6895 7040
6896 -- For discrete types, set the Is_Known_Valid flag if the 7041 -- For discrete types, set the Is_Known_Valid flag if the
7486 7631
7487 -- Local variables 7632 -- Local variables
7488 7633
7489 Def_Id : constant Entity_Id := Entity (N); 7634 Def_Id : constant Entity_Id := Entity (N);
7490 7635
7491 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; 7636 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
7492 -- Save the Ghost mode to restore on exit 7637 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
7638 -- Save the Ghost-related attributes to restore on exit
7493 7639
7494 Result : Boolean := False; 7640 Result : Boolean := False;
7495 7641
7496 -- Start of processing for Freeze_Type 7642 -- Start of processing for Freeze_Type
7497 7643
7852 else 7998 else
7853 Build_Invariant_Procedure_Body (Def_Id); 7999 Build_Invariant_Procedure_Body (Def_Id);
7854 end if; 8000 end if;
7855 end if; 8001 end if;
7856 8002
7857 Restore_Ghost_Mode (Saved_GM); 8003 Restore_Ghost_Region (Saved_GM, Saved_IGR);
7858 8004
7859 return Result; 8005 return Result;
7860 8006
7861 exception 8007 exception
7862 when RE_Not_Available => 8008 when RE_Not_Available =>
7863 Restore_Ghost_Mode (Saved_GM); 8009 Restore_Ghost_Region (Saved_GM, Saved_IGR);
7864 8010
7865 return False; 8011 return False;
7866 end Freeze_Type; 8012 end Freeze_Type;
7867 8013
7868 ------------------------- 8014 -------------------------
7869 -- Get_Simple_Init_Val -- 8015 -- Get_Simple_Init_Val --
7870 ------------------------- 8016 -------------------------
7871 8017
7872 function Get_Simple_Init_Val 8018 function Get_Simple_Init_Val
7873 (T : Entity_Id; 8019 (Typ : Entity_Id;
7874 N : Node_Id; 8020 N : Node_Id;
7875 Size : Uint := No_Uint) return Node_Id 8021 Size : Uint := No_Uint) return Node_Id
7876 is 8022 is
7877 Loc : constant Source_Ptr := Sloc (N);
7878 Val : Node_Id;
7879 Result : Node_Id;
7880 Val_RE : RE_Id;
7881
7882 Size_To_Use : Uint;
7883 -- This is the size to be used for computation of the appropriate
7884 -- initial value for the Normalize_Scalars and Initialize_Scalars case.
7885
7886 IV_Attribute : constant Boolean := 8023 IV_Attribute : constant Boolean :=
7887 Nkind (N) = N_Attribute_Reference 8024 Nkind (N) = N_Attribute_Reference
7888 and then Attribute_Name (N) = Name_Invalid_Value; 8025 and then Attribute_Name (N) = Name_Invalid_Value;
7889 8026
7890 Lo_Bound : Uint; 8027 Loc : constant Source_Ptr := Sloc (N);
7891 Hi_Bound : Uint; 8028
7892 -- These are the values computed by the procedure Check_Subtype_Bounds 8029 procedure Extract_Subtype_Bounds
7893 8030 (Lo_Bound : out Uint;
7894 procedure Check_Subtype_Bounds; 8031 Hi_Bound : out Uint);
7895 -- This procedure examines the subtype T, and its ancestor subtypes and 8032 -- Inspect subtype Typ as well its ancestor subtypes and derived types
7896 -- derived types to determine the best known information about the 8033 -- to determine the best known information about the bounds of the type.
7897 -- bounds of the subtype. After the call Lo_Bound is set either to 8034 -- The output parameters are set as follows:
7898 -- No_Uint if no information can be determined, or to a value which 8035 --
7899 -- represents a known low bound, i.e. a valid value of the subtype can 8036 -- * Lo_Bound - Set to No_Unit when there is no information available,
7900 -- not be less than this value. Hi_Bound is similarly set to a known 8037 -- or to the known low bound.
7901 -- high bound (valid value cannot be greater than this). 8038 --
7902 8039 -- * Hi_Bound - Set to No_Unit when there is no information available,
7903 -------------------------- 8040 -- or to the known high bound.
7904 -- Check_Subtype_Bounds -- 8041
7905 -------------------------- 8042 function Simple_Init_Array_Type return Node_Id;
7906 8043 -- Build an expression to initialize array type Typ
7907 procedure Check_Subtype_Bounds is 8044
7908 ST1 : Entity_Id; 8045 function Simple_Init_Defaulted_Type return Node_Id;
7909 ST2 : Entity_Id; 8046 -- Build an expression to initialize type Typ which is subject to
7910 Lo : Node_Id; 8047 -- aspect Default_Value.
7911 Hi : Node_Id; 8048
7912 Loval : Uint; 8049 function Simple_Init_Initialize_Scalars_Type
7913 Hival : Uint; 8050 (Size_To_Use : Uint) return Node_Id;
8051 -- Build an expression to initialize scalar type Typ which is subject to
8052 -- pragma Initialize_Scalars. Size_To_Use is the size of the object.
8053
8054 function Simple_Init_Normalize_Scalars_Type
8055 (Size_To_Use : Uint) return Node_Id;
8056 -- Build an expression to initialize scalar type Typ which is subject to
8057 -- pragma Normalize_Scalars. Size_To_Use is the size of the object.
8058
8059 function Simple_Init_Private_Type return Node_Id;
8060 -- Build an expression to initialize private type Typ
8061
8062 function Simple_Init_Scalar_Type return Node_Id;
8063 -- Build an expression to initialize scalar type Typ
8064
8065 ----------------------------
8066 -- Extract_Subtype_Bounds --
8067 ----------------------------
8068
8069 procedure Extract_Subtype_Bounds
8070 (Lo_Bound : out Uint;
8071 Hi_Bound : out Uint)
8072 is
8073 ST1 : Entity_Id;
8074 ST2 : Entity_Id;
8075 Lo : Node_Id;
8076 Hi : Node_Id;
8077 Lo_Val : Uint;
8078 Hi_Val : Uint;
7914 8079
7915 begin 8080 begin
7916 Lo_Bound := No_Uint; 8081 Lo_Bound := No_Uint;
7917 Hi_Bound := No_Uint; 8082 Hi_Bound := No_Uint;
7918 8083
7919 -- Loop to climb ancestor subtypes and derived types 8084 -- Loop to climb ancestor subtypes and derived types
7920 8085
7921 ST1 := T; 8086 ST1 := Typ;
7922 loop 8087 loop
7923 if not Is_Discrete_Type (ST1) then 8088 if not Is_Discrete_Type (ST1) then
7924 return; 8089 return;
7925 end if; 8090 end if;
7926 8091
7927 Lo := Type_Low_Bound (ST1); 8092 Lo := Type_Low_Bound (ST1);
7928 Hi := Type_High_Bound (ST1); 8093 Hi := Type_High_Bound (ST1);
7929 8094
7930 if Compile_Time_Known_Value (Lo) then 8095 if Compile_Time_Known_Value (Lo) then
7931 Loval := Expr_Value (Lo); 8096 Lo_Val := Expr_Value (Lo);
7932 8097
7933 if Lo_Bound = No_Uint or else Lo_Bound < Loval then 8098 if Lo_Bound = No_Uint or else Lo_Bound < Lo_Val then
7934 Lo_Bound := Loval; 8099 Lo_Bound := Lo_Val;
7935 end if; 8100 end if;
7936 end if; 8101 end if;
7937 8102
7938 if Compile_Time_Known_Value (Hi) then 8103 if Compile_Time_Known_Value (Hi) then
7939 Hival := Expr_Value (Hi); 8104 Hi_Val := Expr_Value (Hi);
7940 8105
7941 if Hi_Bound = No_Uint or else Hi_Bound > Hival then 8106 if Hi_Bound = No_Uint or else Hi_Bound > Hi_Val then
7942 Hi_Bound := Hival; 8107 Hi_Bound := Hi_Val;
7943 end if; 8108 end if;
7944 end if; 8109 end if;
7945 8110
7946 ST2 := Ancestor_Subtype (ST1); 8111 ST2 := Ancestor_Subtype (ST1);
7947 8112
7950 end if; 8115 end if;
7951 8116
7952 exit when ST1 = ST2; 8117 exit when ST1 = ST2;
7953 ST1 := ST2; 8118 ST1 := ST2;
7954 end loop; 8119 end loop;
7955 end Check_Subtype_Bounds; 8120 end Extract_Subtype_Bounds;
7956 8121
7957 -- Start of processing for Get_Simple_Init_Val 8122 ----------------------------
7958 8123 -- Simple_Init_Array_Type --
7959 begin 8124 ----------------------------
7960 -- For a private type, we should always have an underlying type (because 8125
7961 -- this was already checked in Needs_Simple_Initialization). What we do 8126 function Simple_Init_Array_Type return Node_Id is
7962 -- is to get the value for the underlying type and then do an unchecked 8127 Comp_Typ : constant Entity_Id := Component_Type (Typ);
7963 -- conversion to the private type. 8128
7964 8129 function Simple_Init_Dimension (Index : Node_Id) return Node_Id;
7965 if Is_Private_Type (T) then 8130 -- Initialize a single array dimension with index constraint Index
7966 Val := Get_Simple_Init_Val (Underlying_Type (T), N, Size); 8131
7967 8132 --------------------
7968 -- A special case, if the underlying value is null, then qualify it 8133 -- Simple_Init_Dimension --
7969 -- with the underlying type, so that the null is properly typed. 8134 --------------------
7970 -- Similarly, if it is an aggregate it must be qualified, because an 8135
7971 -- unchecked conversion does not provide a context for it. 8136 function Simple_Init_Dimension (Index : Node_Id) return Node_Id is
7972 8137 begin
7973 if Nkind_In (Val, N_Null, N_Aggregate) then 8138 -- Process the current dimension
7974 Val := 8139
7975 Make_Qualified_Expression (Loc, 8140 if Present (Index) then
7976 Subtype_Mark => 8141
7977 New_Occurrence_Of (Underlying_Type (T), Loc), 8142 -- Build a suitable "others" aggregate for the next dimension,
7978 Expression => Val); 8143 -- or initialize the component itself. Generate:
7979 end if; 8144 --
7980 8145 -- (others => ...)
7981 Result := Unchecked_Convert_To (T, Val); 8146
7982 8147 return
7983 -- Don't truncate result (important for Initialize/Normalize_Scalars) 8148 Make_Aggregate (Loc,
7984 8149 Component_Associations => New_List (
7985 if Nkind (Result) = N_Unchecked_Type_Conversion 8150 Make_Component_Association (Loc,
7986 and then Is_Scalar_Type (Underlying_Type (T)) 8151 Choices => New_List (Make_Others_Choice (Loc)),
7987 then 8152 Expression =>
7988 Set_No_Truncation (Result); 8153 Simple_Init_Dimension (Next_Index (Index)))));
7989 end if; 8154
7990 8155 -- Otherwise all dimensions have been processed. Initialize the
7991 return Result; 8156 -- component itself.
7992 8157
7993 -- Scalars with Default_Value aspect. The first subtype may now be 8158 else
7994 -- private, so retrieve value from underlying type. 8159 return
7995 8160 Get_Simple_Init_Val
7996 elsif Is_Scalar_Type (T) and then Has_Default_Aspect (T) then 8161 (Typ => Comp_Typ,
7997 if Is_Private_Type (First_Subtype (T)) then 8162 N => N,
7998 return Unchecked_Convert_To (T, 8163 Size => Esize (Comp_Typ));
7999 Default_Aspect_Value (Full_View (First_Subtype (T)))); 8164 end if;
8165 end Simple_Init_Dimension;
8166
8167 -- Start of processing for Simple_Init_Array_Type
8168
8169 begin
8170 return Simple_Init_Dimension (First_Index (Typ));
8171 end Simple_Init_Array_Type;
8172
8173 --------------------------------
8174 -- Simple_Init_Defaulted_Type --
8175 --------------------------------
8176
8177 function Simple_Init_Defaulted_Type return Node_Id is
8178 Subtyp : constant Entity_Id := First_Subtype (Typ);
8179
8180 begin
8181 -- Use the Sloc of the context node when constructing the initial
8182 -- value because the expression of Default_Value may come from a
8183 -- different unit. Updating the Sloc will result in accurate error
8184 -- diagnostics.
8185
8186 -- When the first subtype is private, retrieve the expression of the
8187 -- Default_Value from the underlying type.
8188
8189 if Is_Private_Type (Subtyp) then
8190 return
8191 Unchecked_Convert_To
8192 (Typ => Typ,
8193 Expr =>
8194 New_Copy_Tree
8195 (Source => Default_Aspect_Value (Full_View (Subtyp)),
8196 New_Sloc => Loc));
8197
8000 else 8198 else
8001 return 8199 return
8002 Convert_To (T, Default_Aspect_Value (First_Subtype (T))); 8200 Convert_To
8003 end if; 8201 (Typ => Typ,
8004 8202 Expr =>
8005 -- Otherwise, for scalars, we must have normalize/initialize scalars 8203 New_Copy_Tree
8006 -- case, or if the node N is an 'Invalid_Value attribute node. 8204 (Source => Default_Aspect_Value (Subtyp),
8007 8205 New_Sloc => Loc));
8008 elsif Is_Scalar_Type (T) then 8206 end if;
8207 end Simple_Init_Defaulted_Type;
8208
8209 -----------------------------------------
8210 -- Simple_Init_Initialize_Scalars_Type --
8211 -----------------------------------------
8212
8213 function Simple_Init_Initialize_Scalars_Type
8214 (Size_To_Use : Uint) return Node_Id
8215 is
8216 Float_Typ : Entity_Id;
8217 Hi_Bound : Uint;
8218 Lo_Bound : Uint;
8219 Scal_Typ : Scalar_Id;
8220
8221 begin
8222 Extract_Subtype_Bounds (Lo_Bound, Hi_Bound);
8223
8224 -- Float types
8225
8226 if Is_Floating_Point_Type (Typ) then
8227 Float_Typ := Root_Type (Typ);
8228
8229 if Float_Typ = Standard_Short_Float then
8230 Scal_Typ := Name_Short_Float;
8231 elsif Float_Typ = Standard_Float then
8232 Scal_Typ := Name_Float;
8233 elsif Float_Typ = Standard_Long_Float then
8234 Scal_Typ := Name_Long_Float;
8235 else pragma Assert (Float_Typ = Standard_Long_Long_Float);
8236 Scal_Typ := Name_Long_Long_Float;
8237 end if;
8238
8239 -- If zero is invalid, it is a convenient value to use that is for
8240 -- sure an appropriate invalid value in all situations.
8241
8242 elsif Lo_Bound /= No_Uint and then Lo_Bound > Uint_0 then
8243 return Make_Integer_Literal (Loc, 0);
8244
8245 -- Unsigned types
8246
8247 elsif Is_Unsigned_Type (Typ) then
8248 if Size_To_Use <= 8 then
8249 Scal_Typ := Name_Unsigned_8;
8250 elsif Size_To_Use <= 16 then
8251 Scal_Typ := Name_Unsigned_16;
8252 elsif Size_To_Use <= 32 then
8253 Scal_Typ := Name_Unsigned_32;
8254 else
8255 Scal_Typ := Name_Unsigned_64;
8256 end if;
8257
8258 -- Signed types
8259
8260 else
8261 if Size_To_Use <= 8 then
8262 Scal_Typ := Name_Signed_8;
8263 elsif Size_To_Use <= 16 then
8264 Scal_Typ := Name_Signed_16;
8265 elsif Size_To_Use <= 32 then
8266 Scal_Typ := Name_Signed_32;
8267 else
8268 Scal_Typ := Name_Signed_64;
8269 end if;
8270 end if;
8271
8272 -- Use the values specified by pragma Initialize_Scalars or the ones
8273 -- provided by the binder. Higher precedence is given to the pragma.
8274
8275 return Invalid_Scalar_Value (Loc, Scal_Typ);
8276 end Simple_Init_Initialize_Scalars_Type;
8277
8278 ----------------------------------------
8279 -- Simple_Init_Normalize_Scalars_Type --
8280 ----------------------------------------
8281
8282 function Simple_Init_Normalize_Scalars_Type
8283 (Size_To_Use : Uint) return Node_Id
8284 is
8285 Signed_Size : constant Uint := UI_Min (Uint_63, Size_To_Use - 1);
8286
8287 Expr : Node_Id;
8288 Hi_Bound : Uint;
8289 Lo_Bound : Uint;
8290
8291 begin
8292 Extract_Subtype_Bounds (Lo_Bound, Hi_Bound);
8293
8294 -- If zero is invalid, it is a convenient value to use that is for
8295 -- sure an appropriate invalid value in all situations.
8296
8297 if Lo_Bound /= No_Uint and then Lo_Bound > Uint_0 then
8298 Expr := Make_Integer_Literal (Loc, 0);
8299
8300 -- Cases where all one bits is the appropriate invalid value
8301
8302 -- For modular types, all 1 bits is either invalid or valid. If it
8303 -- is valid, then there is nothing that can be done since there are
8304 -- no invalid values (we ruled out zero already).
8305
8306 -- For signed integer types that have no negative values, either
8307 -- there is room for negative values, or there is not. If there
8308 -- is, then all 1-bits may be interpreted as minus one, which is
8309 -- certainly invalid. Alternatively it is treated as the largest
8310 -- positive value, in which case the observation for modular types
8311 -- still applies.
8312
8313 -- For float types, all 1-bits is a NaN (not a number), which is
8314 -- certainly an appropriately invalid value.
8315
8316 elsif Is_Enumeration_Type (Typ)
8317 or else Is_Floating_Point_Type (Typ)
8318 or else Is_Unsigned_Type (Typ)
8319 then
8320 Expr := Make_Integer_Literal (Loc, 2 ** Size_To_Use - 1);
8321
8322 -- Resolve as Unsigned_64, because the largest number we can
8323 -- generate is out of range of universal integer.
8324
8325 Analyze_And_Resolve (Expr, RTE (RE_Unsigned_64));
8326
8327 -- Case of signed types
8328
8329 else
8330 -- Normally we like to use the most negative number. The one
8331 -- exception is when this number is in the known subtype range and
8332 -- the largest positive number is not in the known subtype range.
8333
8334 -- For this exceptional case, use largest positive value
8335
8336 if Lo_Bound /= No_Uint and then Hi_Bound /= No_Uint
8337 and then Lo_Bound <= (-(2 ** Signed_Size))
8338 and then Hi_Bound < 2 ** Signed_Size
8339 then
8340 Expr := Make_Integer_Literal (Loc, 2 ** Signed_Size - 1);
8341
8342 -- Normal case of largest negative value
8343
8344 else
8345 Expr := Make_Integer_Literal (Loc, -(2 ** Signed_Size));
8346 end if;
8347 end if;
8348
8349 return Expr;
8350 end Simple_Init_Normalize_Scalars_Type;
8351
8352 ------------------------------
8353 -- Simple_Init_Private_Type --
8354 ------------------------------
8355
8356 function Simple_Init_Private_Type return Node_Id is
8357 Under_Typ : constant Entity_Id := Underlying_Type (Typ);
8358 Expr : Node_Id;
8359
8360 begin
8361 -- The availability of the underlying view must be checked by routine
8362 -- Needs_Simple_Initialization.
8363
8364 pragma Assert (Present (Under_Typ));
8365
8366 Expr := Get_Simple_Init_Val (Under_Typ, N, Size);
8367
8368 -- If the initial value is null or an aggregate, qualify it with the
8369 -- underlying type in order to provide a proper context.
8370
8371 if Nkind_In (Expr, N_Aggregate, N_Null) then
8372 Expr :=
8373 Make_Qualified_Expression (Loc,
8374 Subtype_Mark => New_Occurrence_Of (Under_Typ, Loc),
8375 Expression => Expr);
8376 end if;
8377
8378 Expr := Unchecked_Convert_To (Typ, Expr);
8379
8380 -- Do not truncate the result when scalar types are involved and
8381 -- Initialize/Normalize_Scalars is in effect.
8382
8383 if Nkind (Expr) = N_Unchecked_Type_Conversion
8384 and then Is_Scalar_Type (Under_Typ)
8385 then
8386 Set_No_Truncation (Expr);
8387 end if;
8388
8389 return Expr;
8390 end Simple_Init_Private_Type;
8391
8392 -----------------------------
8393 -- Simple_Init_Scalar_Type --
8394 -----------------------------
8395
8396 function Simple_Init_Scalar_Type return Node_Id is
8397 Expr : Node_Id;
8398 Size_To_Use : Uint;
8399
8400 begin
8009 pragma Assert (Init_Or_Norm_Scalars or IV_Attribute); 8401 pragma Assert (Init_Or_Norm_Scalars or IV_Attribute);
8010 8402
8011 -- Compute size of object. If it is given by the caller, we can use 8403 -- Determine the size of the object. This is either the size provided
8012 -- it directly, otherwise we use Esize (T) as an estimate. As far as 8404 -- by the caller, or the Esize of the scalar type.
8013 -- we know this covers all cases correctly.
8014 8405
8015 if Size = No_Uint or else Size <= Uint_0 then 8406 if Size = No_Uint or else Size <= Uint_0 then
8016 Size_To_Use := UI_Max (Uint_1, Esize (T)); 8407 Size_To_Use := UI_Max (Uint_1, Esize (Typ));
8017 else 8408 else
8018 Size_To_Use := Size; 8409 Size_To_Use := Size;
8019 end if; 8410 end if;
8020 8411
8021 -- Maximum size to use is 64 bits, since we will create values of 8412 -- The maximum size to use is 64 bits. This will create values of
8022 -- type Unsigned_64 and the range must fit this type. 8413 -- type Unsigned_64 and the range must fit this type.
8023 8414
8024 if Size_To_Use /= No_Uint and then Size_To_Use > Uint_64 then 8415 if Size_To_Use /= No_Uint and then Size_To_Use > Uint_64 then
8025 Size_To_Use := Uint_64; 8416 Size_To_Use := Uint_64;
8026 end if; 8417 end if;
8027 8418
8028 -- Check known bounds of subtype
8029
8030 Check_Subtype_Bounds;
8031
8032 -- Processing for Normalize_Scalars case
8033
8034 if Normalize_Scalars and then not IV_Attribute then 8419 if Normalize_Scalars and then not IV_Attribute then
8035 8420 Expr := Simple_Init_Normalize_Scalars_Type (Size_To_Use);
8036 -- If zero is invalid, it is a convenient value to use that is
8037 -- for sure an appropriate invalid value in all situations.
8038
8039 if Lo_Bound /= No_Uint and then Lo_Bound > Uint_0 then
8040 Val := Make_Integer_Literal (Loc, 0);
8041
8042 -- Cases where all one bits is the appropriate invalid value
8043
8044 -- For modular types, all 1 bits is either invalid or valid. If
8045 -- it is valid, then there is nothing that can be done since there
8046 -- are no invalid values (we ruled out zero already).
8047
8048 -- For signed integer types that have no negative values, either
8049 -- there is room for negative values, or there is not. If there
8050 -- is, then all 1-bits may be interpreted as minus one, which is
8051 -- certainly invalid. Alternatively it is treated as the largest
8052 -- positive value, in which case the observation for modular types
8053 -- still applies.
8054
8055 -- For float types, all 1-bits is a NaN (not a number), which is
8056 -- certainly an appropriately invalid value.
8057
8058 elsif Is_Unsigned_Type (T)
8059 or else Is_Floating_Point_Type (T)
8060 or else Is_Enumeration_Type (T)
8061 then
8062 Val := Make_Integer_Literal (Loc, 2 ** Size_To_Use - 1);
8063
8064 -- Resolve as Unsigned_64, because the largest number we can
8065 -- generate is out of range of universal integer.
8066
8067 Analyze_And_Resolve (Val, RTE (RE_Unsigned_64));
8068
8069 -- Case of signed types
8070
8071 else
8072 declare
8073 Signed_Size : constant Uint :=
8074 UI_Min (Uint_63, Size_To_Use - 1);
8075
8076 begin
8077 -- Normally we like to use the most negative number. The one
8078 -- exception is when this number is in the known subtype
8079 -- range and the largest positive number is not in the known
8080 -- subtype range.
8081
8082 -- For this exceptional case, use largest positive value
8083
8084 if Lo_Bound /= No_Uint and then Hi_Bound /= No_Uint
8085 and then Lo_Bound <= (-(2 ** Signed_Size))
8086 and then Hi_Bound < 2 ** Signed_Size
8087 then
8088 Val := Make_Integer_Literal (Loc, 2 ** Signed_Size - 1);
8089
8090 -- Normal case of largest negative value
8091
8092 else
8093 Val := Make_Integer_Literal (Loc, -(2 ** Signed_Size));
8094 end if;
8095 end;
8096 end if;
8097
8098 -- Here for Initialize_Scalars case (or Invalid_Value attribute used)
8099
8100 else 8421 else
8101 -- For float types, use float values from System.Scalar_Values 8422 Expr := Simple_Init_Initialize_Scalars_Type (Size_To_Use);
8102
8103 if Is_Floating_Point_Type (T) then
8104 if Root_Type (T) = Standard_Short_Float then
8105 Val_RE := RE_IS_Isf;
8106 elsif Root_Type (T) = Standard_Float then
8107 Val_RE := RE_IS_Ifl;
8108 elsif Root_Type (T) = Standard_Long_Float then
8109 Val_RE := RE_IS_Ilf;
8110 else pragma Assert (Root_Type (T) = Standard_Long_Long_Float);
8111 Val_RE := RE_IS_Ill;
8112 end if;
8113
8114 -- If zero is invalid, use zero values from System.Scalar_Values
8115
8116 elsif Lo_Bound /= No_Uint and then Lo_Bound > Uint_0 then
8117 if Size_To_Use <= 8 then
8118 Val_RE := RE_IS_Iz1;
8119 elsif Size_To_Use <= 16 then
8120 Val_RE := RE_IS_Iz2;
8121 elsif Size_To_Use <= 32 then
8122 Val_RE := RE_IS_Iz4;
8123 else
8124 Val_RE := RE_IS_Iz8;
8125 end if;
8126
8127 -- For unsigned, use unsigned values from System.Scalar_Values
8128
8129 elsif Is_Unsigned_Type (T) then
8130 if Size_To_Use <= 8 then
8131 Val_RE := RE_IS_Iu1;
8132 elsif Size_To_Use <= 16 then
8133 Val_RE := RE_IS_Iu2;
8134 elsif Size_To_Use <= 32 then
8135 Val_RE := RE_IS_Iu4;
8136 else
8137 Val_RE := RE_IS_Iu8;
8138 end if;
8139
8140 -- For signed, use signed values from System.Scalar_Values
8141
8142 else
8143 if Size_To_Use <= 8 then
8144 Val_RE := RE_IS_Is1;
8145 elsif Size_To_Use <= 16 then
8146 Val_RE := RE_IS_Is2;
8147 elsif Size_To_Use <= 32 then
8148 Val_RE := RE_IS_Is4;
8149 else
8150 Val_RE := RE_IS_Is8;
8151 end if;
8152 end if;
8153
8154 Val := New_Occurrence_Of (RTE (Val_RE), Loc);
8155 end if; 8423 end if;
8156 8424
8157 -- The final expression is obtained by doing an unchecked conversion 8425 -- The final expression is obtained by doing an unchecked conversion
8158 -- of this result to the base type of the required subtype. Use the 8426 -- of this result to the base type of the required subtype. Use the
8159 -- base type to prevent the unchecked conversion from chopping bits, 8427 -- base type to prevent the unchecked conversion from chopping bits,
8160 -- and then we set Kill_Range_Check to preserve the "bad" value. 8428 -- and then we set Kill_Range_Check to preserve the "bad" value.
8161 8429
8162 Result := Unchecked_Convert_To (Base_Type (T), Val); 8430 Expr := Unchecked_Convert_To (Base_Type (Typ), Expr);
8163 8431
8164 -- Ensure result is not truncated, since we want the "bad" bits, and 8432 -- Ensure that the expression is not truncated since the "bad" bits
8165 -- also kill range check on result. 8433 -- are desired, and also kill the range checks.
8166 8434
8167 if Nkind (Result) = N_Unchecked_Type_Conversion then 8435 if Nkind (Expr) = N_Unchecked_Type_Conversion then
8168 Set_No_Truncation (Result); 8436 Set_Kill_Range_Check (Expr);
8169 Set_Kill_Range_Check (Result, True); 8437 Set_No_Truncation (Expr);
8170 end if; 8438 end if;
8171 8439
8172 return Result; 8440 return Expr;
8173 8441 end Simple_Init_Scalar_Type;
8174 -- String or Wide_[Wide]_String (must have Initialize_Scalars set) 8442
8175 8443 -- Start of processing for Get_Simple_Init_Val
8176 elsif Is_Standard_String_Type (T) then 8444
8445 begin
8446 if Is_Private_Type (Typ) then
8447 return Simple_Init_Private_Type;
8448
8449 elsif Is_Scalar_Type (Typ) then
8450 if Has_Default_Aspect (Typ) then
8451 return Simple_Init_Defaulted_Type;
8452 else
8453 return Simple_Init_Scalar_Type;
8454 end if;
8455
8456 -- Array type with Initialize or Normalize_Scalars
8457
8458 elsif Is_Array_Type (Typ) then
8177 pragma Assert (Init_Or_Norm_Scalars); 8459 pragma Assert (Init_Or_Norm_Scalars);
8178 8460 return Simple_Init_Array_Type;
8179 return
8180 Make_Aggregate (Loc,
8181 Component_Associations => New_List (
8182 Make_Component_Association (Loc,
8183 Choices => New_List (
8184 Make_Others_Choice (Loc)),
8185 Expression =>
8186 Get_Simple_Init_Val
8187 (Component_Type (T), N, Esize (Root_Type (T))))));
8188 8461
8189 -- Access type is initialized to null 8462 -- Access type is initialized to null
8190 8463
8191 elsif Is_Access_Type (T) then 8464 elsif Is_Access_Type (Typ) then
8192 return Make_Null (Loc); 8465 return Make_Null (Loc);
8193 8466
8194 -- No other possibilities should arise, since we should only be calling 8467 -- No other possibilities should arise, since we should only be calling
8195 -- Get_Simple_Init_Val if Needs_Simple_Initialization returned True, 8468 -- Get_Simple_Init_Val if Needs_Simple_Initialization returned True,
8196 -- indicating one of the above cases held. 8469 -- indicating one of the above cases held.
8336 ------------------ 8609 ------------------
8337 -- Init_Formals -- 8610 -- Init_Formals --
8338 ------------------ 8611 ------------------
8339 8612
8340 function Init_Formals (Typ : Entity_Id) return List_Id is 8613 function Init_Formals (Typ : Entity_Id) return List_Id is
8614 Unc_Arr : constant Boolean :=
8615 Is_Array_Type (Typ) and then not Is_Constrained (Typ);
8616 With_Prot : constant Boolean :=
8617 Has_Protected (Typ)
8618 or else (Is_Record_Type (Typ)
8619 and then Is_Protected_Record_Type (Typ));
8620 With_Task : constant Boolean :=
8621 Has_Task (Typ)
8622 or else (Is_Record_Type (Typ)
8623 and then Is_Task_Record_Type (Typ));
8341 Loc : constant Source_Ptr := Sloc (Typ); 8624 Loc : constant Source_Ptr := Sloc (Typ);
8342 Formals : List_Id; 8625 Formals : List_Id;
8343 8626
8344 begin 8627 begin
8345 -- First parameter is always _Init : in out typ. Note that we need this 8628 -- The first parameter is always _Init : [in] out Typ. Note that we need
8346 -- to be in/out because in the case of the task record value, there 8629 -- it to be in/out in the case of an unconstrained array, because of the
8347 -- are default record fields (_Priority, _Size, -Task_Info) that may 8630 -- need to have the bounds, and in the case of protected or task record
8348 -- be referenced in the generated initialization routine. 8631 -- value, because there are default record fields that may be referenced
8632 -- in the generated initialization routine.
8349 8633
8350 Formals := New_List ( 8634 Formals := New_List (
8351 Make_Parameter_Specification (Loc, 8635 Make_Parameter_Specification (Loc,
8352 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uInit), 8636 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uInit),
8353 In_Present => True, 8637 In_Present => Unc_Arr or else With_Prot or else With_Task,
8354 Out_Present => True, 8638 Out_Present => True,
8355 Parameter_Type => New_Occurrence_Of (Typ, Loc))); 8639 Parameter_Type => New_Occurrence_Of (Typ, Loc)));
8356 8640
8357 -- For task record value, or type that contains tasks, add two more 8641 -- For task record value, or type that contains tasks, add two more
8358 -- formals, _Master : Master_Id and _Chain : in out Activation_Chain 8642 -- formals, _Master : Master_Id and _Chain : in out Activation_Chain
8359 -- We also add these parameters for the task record type case. 8643 -- We also add these parameters for the task record type case.
8360 8644
8361 if Has_Task (Typ) 8645 if With_Task then
8362 or else (Is_Record_Type (Typ) and then Is_Task_Record_Type (Typ))
8363 then
8364 Append_To (Formals, 8646 Append_To (Formals,
8365 Make_Parameter_Specification (Loc, 8647 Make_Parameter_Specification (Loc,
8366 Defining_Identifier => 8648 Defining_Identifier =>
8367 Make_Defining_Identifier (Loc, Name_uMaster), 8649 Make_Defining_Identifier (Loc, Name_uMaster),
8368 Parameter_Type => 8650 Parameter_Type =>
8386 Make_Parameter_Specification (Loc, 8668 Make_Parameter_Specification (Loc,
8387 Defining_Identifier => 8669 Defining_Identifier =>
8388 Make_Defining_Identifier (Loc, Name_uTask_Name), 8670 Make_Defining_Identifier (Loc, Name_uTask_Name),
8389 In_Present => True, 8671 In_Present => True,
8390 Parameter_Type => New_Occurrence_Of (Standard_String, Loc))); 8672 Parameter_Type => New_Occurrence_Of (Standard_String, Loc)));
8673 end if;
8674
8675 -- Due to certain edge cases such as arrays with null-excluding
8676 -- components being built with the secondary stack it becomes necessary
8677 -- to add a formal to the Init_Proc which controls whether we raise
8678 -- Constraint_Errors on generated calls for internal object
8679 -- declarations.
8680
8681 if Needs_Conditional_Null_Excluding_Check (Typ) then
8682 Append_To (Formals,
8683 Make_Parameter_Specification (Loc,
8684 Defining_Identifier =>
8685 Make_Defining_Identifier (Loc,
8686 New_External_Name (Chars
8687 (Component_Type (Typ)), "_skip_null_excluding_check")),
8688 In_Present => True,
8689 Parameter_Type =>
8690 New_Occurrence_Of (Standard_Boolean, Loc)));
8391 end if; 8691 end if;
8392 8692
8393 return Formals; 8693 return Formals;
8394 8694
8395 exception 8695 exception
8499 (Node (First_Elmt (Access_Disp_Table (Iface))), 8799 (Node (First_Elmt (Access_Disp_Table (Iface))),
8500 Loc)), 8800 Loc)),
8501 8801
8502 Unchecked_Convert_To 8802 Unchecked_Convert_To
8503 (RTE (RE_Storage_Offset), 8803 (RTE (RE_Storage_Offset),
8504 Make_Attribute_Reference (Loc, 8804 Make_Op_Minus (Loc,
8505 Prefix => 8805 Make_Attribute_Reference (Loc,
8506 Make_Selected_Component (Loc, 8806 Prefix =>
8507 Prefix => New_Copy_Tree (Target), 8807 Make_Selected_Component (Loc,
8508 Selector_Name => 8808 Prefix => New_Copy_Tree (Target),
8509 New_Occurrence_Of (Tag_Comp, Loc)), 8809 Selector_Name =>
8510 Attribute_Name => Name_Position)), 8810 New_Occurrence_Of (Tag_Comp, Loc)),
8811 Attribute_Name => Name_Position))),
8511 8812
8512 Unchecked_Convert_To (RTE (RE_Offset_To_Top_Function_Ptr), 8813 Unchecked_Convert_To (RTE (RE_Offset_To_Top_Function_Ptr),
8513 Make_Attribute_Reference (Loc, 8814 Make_Attribute_Reference (Loc,
8514 Prefix => New_Occurrence_Of 8815 Prefix => New_Occurrence_Of
8515 (DT_Offset_To_Top_Func (Tag_Comp), Loc), 8816 (DT_Offset_To_Top_Func (Tag_Comp), Loc),
8528 Prefix => New_Copy_Tree (Target), 8829 Prefix => New_Copy_Tree (Target),
8529 Selector_Name => 8830 Selector_Name =>
8530 New_Occurrence_Of (Offset_To_Top_Comp, Loc)), 8831 New_Occurrence_Of (Offset_To_Top_Comp, Loc)),
8531 8832
8532 Expression => 8833 Expression =>
8533 Make_Attribute_Reference (Loc, 8834 Make_Op_Minus (Loc,
8534 Prefix => 8835 Make_Attribute_Reference (Loc,
8535 Make_Selected_Component (Loc, 8836 Prefix =>
8536 Prefix => New_Copy_Tree (Target), 8837 Make_Selected_Component (Loc,
8537 Selector_Name => New_Occurrence_Of (Tag_Comp, Loc)), 8838 Prefix => New_Copy_Tree (Target),
8538 Attribute_Name => Name_Position))); 8839 Selector_Name => New_Occurrence_Of (Tag_Comp, Loc)),
8840 Attribute_Name => Name_Position))));
8539 8841
8540 -- Normal case: No discriminants in the parent type 8842 -- Normal case: No discriminants in the parent type
8541 8843
8542 else 8844 else
8543 -- Don't need to set any value if the offset-to-top field is 8845 -- Don't need to set any value if the offset-to-top field is
8550 Append_To (Stmts_List, 8852 Append_To (Stmts_List,
8551 Build_Set_Static_Offset_To_Top (Loc, 8853 Build_Set_Static_Offset_To_Top (Loc,
8552 Iface_Tag => New_Occurrence_Of (Iface_Tag, Loc), 8854 Iface_Tag => New_Occurrence_Of (Iface_Tag, Loc),
8553 Offset_Value => 8855 Offset_Value =>
8554 Unchecked_Convert_To (RTE (RE_Storage_Offset), 8856 Unchecked_Convert_To (RTE (RE_Storage_Offset),
8555 Make_Attribute_Reference (Loc, 8857 Make_Op_Minus (Loc,
8556 Prefix => 8858 Make_Attribute_Reference (Loc,
8557 Make_Selected_Component (Loc, 8859 Prefix =>
8558 Prefix => New_Copy_Tree (Target), 8860 Make_Selected_Component (Loc,
8559 Selector_Name => 8861 Prefix => New_Copy_Tree (Target),
8560 New_Occurrence_Of (Tag_Comp, Loc)), 8862 Selector_Name =>
8561 Attribute_Name => Name_Position)))); 8863 New_Occurrence_Of (Tag_Comp, Loc)),
8864 Attribute_Name => Name_Position)))));
8562 end if; 8865 end if;
8563 8866
8564 -- Generate: 8867 -- Generate:
8565 -- Register_Interface_Offset 8868 -- Register_Interface_Offset
8566 -- (Prim_T => Typ'Tag, 8869 -- (Prim_T => Typ'Tag,
8567 -- Interface_T => Iface'Tag, 8870 -- Interface_T => Iface'Tag,
8568 -- Is_Constant => True, 8871 -- Is_Constant => True,
8569 -- Offset_Value => n, 8872 -- Offset_Value => n,
8570 -- Offset_Func => null); 8873 -- Offset_Func => null);
8571 8874
8572 if RTE_Available (RE_Register_Interface_Offset) then 8875 if not Building_Static_Secondary_DT (Typ)
8876 and then RTE_Available (RE_Register_Interface_Offset)
8877 then
8573 Append_To (Stmts_List, 8878 Append_To (Stmts_List,
8574 Make_Procedure_Call_Statement (Loc, 8879 Make_Procedure_Call_Statement (Loc,
8575 Name => 8880 Name =>
8576 New_Occurrence_Of 8881 New_Occurrence_Of
8577 (RTE (RE_Register_Interface_Offset), Loc), 8882 (RTE (RE_Register_Interface_Offset), Loc),
8585 (Node (First_Elmt (Access_Disp_Table (Iface))), Loc)), 8890 (Node (First_Elmt (Access_Disp_Table (Iface))), Loc)),
8586 8891
8587 New_Occurrence_Of (Standard_True, Loc), 8892 New_Occurrence_Of (Standard_True, Loc),
8588 8893
8589 Unchecked_Convert_To (RTE (RE_Storage_Offset), 8894 Unchecked_Convert_To (RTE (RE_Storage_Offset),
8590 Make_Attribute_Reference (Loc, 8895 Make_Op_Minus (Loc,
8591 Prefix => 8896 Make_Attribute_Reference (Loc,
8592 Make_Selected_Component (Loc, 8897 Prefix =>
8593 Prefix => New_Copy_Tree (Target), 8898 Make_Selected_Component (Loc,
8594 Selector_Name => 8899 Prefix => New_Copy_Tree (Target),
8595 New_Occurrence_Of (Tag_Comp, Loc)), 8900 Selector_Name =>
8596 Attribute_Name => Name_Position)), 8901 New_Occurrence_Of (Tag_Comp, Loc)),
8902 Attribute_Name => Name_Position))),
8597 8903
8598 Make_Null (Loc)))); 8904 Make_Null (Loc))));
8599 end if; 8905 end if;
8600 end if; 8906 end if;
8601 end Initialize_Tag; 8907 end Initialize_Tag;
8695 end; 9001 end;
8696 9002
8697 -- Initialize secondary tags 9003 -- Initialize secondary tags
8698 9004
8699 else 9005 else
8700 Append_To (Init_Tags_List, 9006 Initialize_Tag
8701 Make_Assignment_Statement (Loc, 9007 (Typ => Full_Typ,
8702 Name => 9008 Iface => Node (Iface_Elmt),
8703 Make_Selected_Component (Loc, 9009 Tag_Comp => Tag_Comp,
8704 Prefix => New_Copy_Tree (Target), 9010 Iface_Tag => Node (Iface_Tag_Elmt));
8705 Selector_Name =>
8706 New_Occurrence_Of (Node (Iface_Comp_Elmt), Loc)),
8707 Expression =>
8708 New_Occurrence_Of (Node (Iface_Tag_Elmt), Loc)));
8709 end if; 9011 end if;
8710 9012
8711 -- Otherwise generate code to initialize the tag 9013 -- Otherwise generate code to initialize the tag
8712 9014
8713 else 9015 else
8714 if (In_Variable_Pos and then Variable_Comps) 9016 if (In_Variable_Pos and then Variable_Comps)
8715 or else (not In_Variable_Pos and then Fixed_Comps) 9017 or else (not In_Variable_Pos and then Fixed_Comps)
8716 then 9018 then
8717 Initialize_Tag (Full_Typ, 9019 Initialize_Tag
8718 Iface => Node (Iface_Elmt), 9020 (Typ => Full_Typ,
8719 Tag_Comp => Tag_Comp, 9021 Iface => Node (Iface_Elmt),
8720 Iface_Tag => Node (Iface_Tag_Elmt)); 9022 Tag_Comp => Tag_Comp,
9023 Iface_Tag => Node (Iface_Tag_Elmt));
8721 end if; 9024 end if;
8722 end if; 9025 end if;
8723 9026
8724 Next_Elmt (Iface_Elmt); 9027 Next_Elmt (Iface_Elmt);
8725 Next_Elmt (Iface_Comp_Elmt); 9028 Next_Elmt (Iface_Comp_Elmt);
8726 Next_Elmt (Iface_Tag_Elmt); 9029 Next_Elmt (Iface_Tag_Elmt);
8727 end loop; 9030 end loop;
8728 end Init_Secondary_Tags; 9031 end Init_Secondary_Tags;
8729 9032
8730 ------------------------ 9033 ----------------------------
8731 -- Is_User_Defined_Eq -- 9034 -- Is_Null_Statement_List --
8732 ------------------------ 9035 ----------------------------
9036
9037 function Is_Null_Statement_List (Stmts : List_Id) return Boolean is
9038 Stmt : Node_Id;
9039
9040 begin
9041 -- We must skip SCIL nodes because they may have been added to the
9042 -- list by Insert_Actions.
9043
9044 Stmt := First_Non_SCIL_Node (Stmts);
9045 while Present (Stmt) loop
9046 if Nkind (Stmt) = N_Case_Statement then
9047 declare
9048 Alt : Node_Id;
9049 begin
9050 Alt := First (Alternatives (Stmt));
9051 while Present (Alt) loop
9052 if not Is_Null_Statement_List (Statements (Alt)) then
9053 return False;
9054 end if;
9055
9056 Next (Alt);
9057 end loop;
9058 end;
9059
9060 elsif Nkind (Stmt) /= N_Null_Statement then
9061 return False;
9062 end if;
9063
9064 Stmt := Next_Non_SCIL_Node (Stmt);
9065 end loop;
9066
9067 return True;
9068 end Is_Null_Statement_List;
9069
9070 ------------------------------
9071 -- Is_User_Defined_Equality --
9072 ------------------------------
8733 9073
8734 function Is_User_Defined_Equality (Prim : Node_Id) return Boolean is 9074 function Is_User_Defined_Equality (Prim : Node_Id) return Boolean is
8735 begin 9075 begin
8736 return Chars (Prim) = Name_Op_Eq 9076 return Chars (Prim) = Name_Op_Eq
8737 and then Etype (First_Formal (Prim)) = 9077 and then Etype (First_Formal (Prim)) =
8923 <<Next_Prim>> 9263 <<Next_Prim>>
8924 Next_Elmt (Prim_Elmt); 9264 Next_Elmt (Prim_Elmt);
8925 end loop; 9265 end loop;
8926 end Make_Controlling_Function_Wrappers; 9266 end Make_Controlling_Function_Wrappers;
8927 9267
8928 ------------------- 9268 ------------------
8929 -- Make_Eq_Body -- 9269 -- Make_Eq_Body --
8930 ------------------- 9270 ------------------
8931 9271
8932 function Make_Eq_Body 9272 function Make_Eq_Body
8933 (Typ : Entity_Id; 9273 (Typ : Entity_Id;
8934 Eq_Name : Name_Id) return Node_Id 9274 Eq_Name : Name_Id) return Node_Id
8935 is 9275 is
9832 (First_Elmt (Access_Disp_Table (Full_Typ))), Loc))); 10172 (First_Elmt (Access_Disp_Table (Full_Typ))), Loc)));
9833 else 10173 else
9834 return Empty; 10174 return Empty;
9835 end if; 10175 end if;
9836 end Make_Tag_Assignment; 10176 end Make_Tag_Assignment;
9837
9838 ---------------------------------
9839 -- Needs_Simple_Initialization --
9840 ---------------------------------
9841
9842 function Needs_Simple_Initialization
9843 (T : Entity_Id;
9844 Consider_IS : Boolean := True) return Boolean
9845 is
9846 Consider_IS_NS : constant Boolean :=
9847 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
9848
9849 begin
9850 -- Never need initialization if it is suppressed
9851
9852 if Initialization_Suppressed (T) then
9853 return False;
9854 end if;
9855
9856 -- Check for private type, in which case test applies to the underlying
9857 -- type of the private type.
9858
9859 if Is_Private_Type (T) then
9860 declare
9861 RT : constant Entity_Id := Underlying_Type (T);
9862 begin
9863 if Present (RT) then
9864 return Needs_Simple_Initialization (RT);
9865 else
9866 return False;
9867 end if;
9868 end;
9869
9870 -- Scalar type with Default_Value aspect requires initialization
9871
9872 elsif Is_Scalar_Type (T) and then Has_Default_Aspect (T) then
9873 return True;
9874
9875 -- Cases needing simple initialization are access types, and, if pragma
9876 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
9877 -- types.
9878
9879 elsif Is_Access_Type (T)
9880 or else (Consider_IS_NS and then (Is_Scalar_Type (T)))
9881 then
9882 return True;
9883
9884 -- If Initialize/Normalize_Scalars is in effect, string objects also
9885 -- need initialization, unless they are created in the course of
9886 -- expanding an aggregate (since in the latter case they will be
9887 -- filled with appropriate initializing values before they are used).
9888
9889 elsif Consider_IS_NS
9890 and then Is_Standard_String_Type (T)
9891 and then
9892 (not Is_Itype (T)
9893 or else Nkind (Associated_Node_For_Itype (T)) /= N_Aggregate)
9894 then
9895 return True;
9896
9897 else
9898 return False;
9899 end if;
9900 end Needs_Simple_Initialization;
9901 10177
9902 ---------------------- 10178 ----------------------
9903 -- Predef_Deep_Spec -- 10179 -- Predef_Deep_Spec --
9904 ---------------------- 10180 ----------------------
9905 10181