comparison gcc/ada/sem_aggr.adb @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
4 -- -- 4 -- --
5 -- S E M _ A G G R -- 5 -- S E M _ A G G R --
6 -- -- 6 -- --
7 -- B o d y -- 7 -- B o d y --
8 -- -- 8 -- --
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. -- 9 -- Copyright (C) 1992-2019, 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- --
600 Set_Convention (Itype, Convention (Typ)); 600 Set_Convention (Itype, Convention (Typ));
601 Set_Depends_On_Private (Itype, Has_Private_Component (Typ)); 601 Set_Depends_On_Private (Itype, Has_Private_Component (Typ));
602 Set_Etype (Itype, Base_Type (Typ)); 602 Set_Etype (Itype, Base_Type (Typ));
603 Set_Has_Alignment_Clause (Itype, Has_Alignment_Clause (Typ)); 603 Set_Has_Alignment_Clause (Itype, Has_Alignment_Clause (Typ));
604 Set_Is_Aliased (Itype, Is_Aliased (Typ)); 604 Set_Is_Aliased (Itype, Is_Aliased (Typ));
605 Set_Is_Independent (Itype, Is_Independent (Typ));
605 Set_Depends_On_Private (Itype, Depends_On_Private (Typ)); 606 Set_Depends_On_Private (Itype, Depends_On_Private (Typ));
606 607
607 Copy_Suppress_Status (Index_Check, Typ, Itype); 608 Copy_Suppress_Status (Index_Check, Typ, Itype);
608 Copy_Suppress_Status (Length_Check, Typ, Itype); 609 Copy_Suppress_Status (Length_Check, Typ, Itype);
609 610
610 Set_First_Index (Itype, First (Index_Constraints)); 611 Set_First_Index (Itype, First (Index_Constraints));
611 Set_Is_Constrained (Itype, True); 612 Set_Is_Constrained (Itype, True);
612 Set_Is_Internal (Itype, True); 613 Set_Is_Internal (Itype, True);
614
615 if Has_Predicates (Typ) then
616 Set_Has_Predicates (Itype);
617
618 -- If the base type has a predicate, capture the predicated parent
619 -- or the existing predicate function for SPARK use.
620
621 if Present (Predicate_Function (Typ)) then
622 Set_Predicate_Function (Itype, Predicate_Function (Typ));
623
624 elsif Is_Itype (Typ) then
625 Set_Predicated_Parent (Itype, Predicated_Parent (Typ));
626
627 else
628 Set_Predicated_Parent (Itype, Typ);
629 end if;
630 end if;
613 631
614 -- A simple optimization: purely positional aggregates of static 632 -- A simple optimization: purely positional aggregates of static
615 -- components should be passed to gigi unexpanded whenever possible, and 633 -- components should be passed to gigi unexpanded whenever possible, and
616 -- regardless of the staticness of the bounds themselves. Subsequent 634 -- regardless of the staticness of the bounds themselves. Subsequent
617 -- checks in exp_aggr verify that type is not packed, etc. 635 -- checks in exp_aggr verify that type is not packed, etc.
874 -- Resolve_Aggregate -- 892 -- Resolve_Aggregate --
875 ----------------------- 893 -----------------------
876 894
877 procedure Resolve_Aggregate (N : Node_Id; Typ : Entity_Id) is 895 procedure Resolve_Aggregate (N : Node_Id; Typ : Entity_Id) is
878 Loc : constant Source_Ptr := Sloc (N); 896 Loc : constant Source_Ptr := Sloc (N);
879 Pkind : constant Node_Kind := Nkind (Parent (N));
880 897
881 Aggr_Subtyp : Entity_Id; 898 Aggr_Subtyp : Entity_Id;
882 -- The actual aggregate subtype. This is not necessarily the same as Typ 899 -- The actual aggregate subtype. This is not necessarily the same as Typ
883 -- which is the subtype of the context in which the aggregate was found. 900 -- which is the subtype of the context in which the aggregate was found.
884 901
892 return; 909 return;
893 end if; 910 end if;
894 911
895 -- If the aggregate has box-initialized components, its type must be 912 -- If the aggregate has box-initialized components, its type must be
896 -- frozen so that initialization procedures can properly be called 913 -- frozen so that initialization procedures can properly be called
897 -- in the resolution that follows. The replacement of boxes with 914 -- in the resolution that follows. The replacement of boxes with
898 -- initialization calls is properly an expansion activity but it must 915 -- initialization calls is properly an expansion activity but it must
899 -- be done during resolution. 916 -- be done during resolution.
900 917
901 if Expander_Active 918 if Expander_Active
902 and then Present (Component_Associations (N)) 919 and then Present (Component_Associations (N))
1059 -- allowed inside the array aggregate. The test checks the context 1076 -- allowed inside the array aggregate. The test checks the context
1060 -- in which the array aggregate occurs. If the context does not 1077 -- in which the array aggregate occurs. If the context does not
1061 -- permit it, or the aggregate type is unconstrained, an OTHERS 1078 -- permit it, or the aggregate type is unconstrained, an OTHERS
1062 -- choice is not allowed (except that it is always allowed on the 1079 -- choice is not allowed (except that it is always allowed on the
1063 -- right-hand side of an assignment statement; in this case the 1080 -- right-hand side of an assignment statement; in this case the
1064 -- constrainedness of the type doesn't matter). 1081 -- constrainedness of the type doesn't matter, because an array
1082 -- object is always constrained).
1065 1083
1066 -- If expansion is disabled (generic context, or semantics-only 1084 -- If expansion is disabled (generic context, or semantics-only
1067 -- mode) actual subtypes cannot be constructed, and the type of an 1085 -- mode) actual subtypes cannot be constructed, and the type of an
1068 -- object may be its unconstrained nominal type. However, if the 1086 -- object may be its unconstrained nominal type. However, if the
1069 -- context is an assignment, we assume that OTHERS is allowed, 1087 -- context is an assignment statement, OTHERS is allowed, because
1070 -- because the target of the assignment will have a constrained 1088 -- the target of the assignment will have a constrained subtype
1071 -- subtype when fully compiled. Ditto if the context is an 1089 -- when fully compiled. Ditto if the context is an initialization
1072 -- initialization procedure where a component may have a predicate 1090 -- procedure where a component may have a predicate function that
1073 -- function that carries the base type. 1091 -- carries the base type.
1074 1092
1075 -- Note that there is no node for Explicit_Actual_Parameter. 1093 -- Note that there is no node for Explicit_Actual_Parameter.
1076 -- To test for this context we therefore have to test for node 1094 -- To test for this context we therefore have to test for node
1077 -- N_Parameter_Association which itself appears only if there is a 1095 -- N_Parameter_Association which itself appears only if there is a
1078 -- formal parameter. Consequently we also need to test for 1096 -- formal parameter. Consequently we also need to test for
1082 -- Legality of the others clause was established in the source, 1100 -- Legality of the others clause was established in the source,
1083 -- so the context is legal. 1101 -- so the context is legal.
1084 1102
1085 Set_Etype (N, Aggr_Typ); -- May be overridden later on 1103 Set_Etype (N, Aggr_Typ); -- May be overridden later on
1086 1104
1087 if Pkind = N_Assignment_Statement 1105 if Nkind (Parent (N)) = N_Assignment_Statement
1088 or else Inside_Init_Proc 1106 or else Inside_Init_Proc
1089 or else (Is_Constrained (Typ) 1107 or else (Is_Constrained (Typ)
1090 and then 1108 and then Nkind_In (Parent (N),
1091 (Pkind = N_Parameter_Association or else 1109 N_Parameter_Association,
1092 Pkind = N_Function_Call or else 1110 N_Function_Call,
1093 Pkind = N_Procedure_Call_Statement or else 1111 N_Procedure_Call_Statement,
1094 Pkind = N_Generic_Association or else 1112 N_Generic_Association,
1095 Pkind = N_Formal_Object_Declaration or else 1113 N_Formal_Object_Declaration,
1096 Pkind = N_Simple_Return_Statement or else 1114 N_Simple_Return_Statement,
1097 Pkind = N_Object_Declaration or else 1115 N_Object_Declaration,
1098 Pkind = N_Component_Declaration or else 1116 N_Component_Declaration,
1099 Pkind = N_Parameter_Specification or else 1117 N_Parameter_Specification,
1100 Pkind = N_Qualified_Expression or else 1118 N_Qualified_Expression,
1101 Pkind = N_Reference or else 1119 N_Reference,
1102 Pkind = N_Aggregate or else 1120 N_Aggregate,
1103 Pkind = N_Extension_Aggregate or else 1121 N_Extension_Aggregate,
1104 Pkind = N_Component_Association)) 1122 N_Component_Association,
1123 N_Case_Expression_Alternative,
1124 N_If_Expression))
1105 then 1125 then
1106 Aggr_Resolved := 1126 Aggr_Resolved :=
1107 Resolve_Array_Aggregate 1127 Resolve_Array_Aggregate
1108 (N, 1128 (N,
1109 Index => First_Index (Aggr_Typ), 1129 Index => First_Index (Aggr_Typ),
1625 -- predicate check must be applied, as for an assignment statement, 1645 -- predicate check must be applied, as for an assignment statement,
1626 -- because the aggegate might not be expanded into individual 1646 -- because the aggegate might not be expanded into individual
1627 -- component assignments. If the expression covers several components 1647 -- component assignments. If the expression covers several components
1628 -- the analysis and the predicate check take place later. 1648 -- the analysis and the predicate check take place later.
1629 1649
1630 if Present (Predicate_Function (Component_Typ)) 1650 if Has_Predicates (Component_Typ)
1631 and then Analyzed (Expr) 1651 and then Analyzed (Expr)
1632 then 1652 then
1633 Apply_Predicate_Check (Expr, Component_Typ); 1653 Apply_Predicate_Check (Expr, Component_Typ);
1634 end if; 1654 end if;
1635 1655
2787 2807
2788 procedure Resolve_Delta_Aggregate (N : Node_Id; Typ : Entity_Id) is 2808 procedure Resolve_Delta_Aggregate (N : Node_Id; Typ : Entity_Id) is
2789 Base : constant Node_Id := Expression (N); 2809 Base : constant Node_Id := Expression (N);
2790 2810
2791 begin 2811 begin
2812 if Ada_Version < Ada_2020 then
2813 Error_Msg_N ("delta_aggregate is an Ada 202x feature", N);
2814 Error_Msg_N ("\compile with -gnatX", N);
2815 end if;
2816
2792 if not Is_Composite_Type (Typ) then 2817 if not Is_Composite_Type (Typ) then
2793 Error_Msg_N ("not a composite type", N); 2818 Error_Msg_N ("not a composite type", N);
2794 end if; 2819 end if;
2795 2820
2796 Analyze_And_Resolve (Base, Typ); 2821 Analyze_And_Resolve (Base, Typ);
3141 return True; 3166 return True;
3142 3167
3143 elsif Nkind (Anc) = N_Qualified_Expression then 3168 elsif Nkind (Anc) = N_Qualified_Expression then
3144 return Valid_Limited_Ancestor (Expression (Anc)); 3169 return Valid_Limited_Ancestor (Expression (Anc));
3145 3170
3171 elsif Nkind (Anc) = N_Raise_Expression then
3172 return True;
3173
3146 else 3174 else
3147 return False; 3175 return False;
3148 end if; 3176 end if;
3149 end Valid_Limited_Ancestor; 3177 end Valid_Limited_Ancestor;
3150 3178
3180 elsif Is_Private_Type (A_Type) 3208 elsif Is_Private_Type (A_Type)
3181 and then not Is_Private_Type (Imm_Type) 3209 and then not Is_Private_Type (Imm_Type)
3182 and then Present (Full_View (A_Type)) 3210 and then Present (Full_View (A_Type))
3183 and then Base_Type (Full_View (A_Type)) = Etype (Imm_Type) 3211 and then Base_Type (Full_View (A_Type)) = Etype (Imm_Type)
3184 then 3212 then
3213 return True;
3214
3215 -- The parent type may be a raise expression (which is legal in
3216 -- any expression context).
3217
3218 elsif A_Type = Raise_Type then
3219 A_Type := Etype (Imm_Type);
3185 return True; 3220 return True;
3186 3221
3187 else 3222 else
3188 Imm_Type := Etype (Base_Type (Imm_Type)); 3223 Imm_Type := Etype (Base_Type (Imm_Type));
3189 end if; 3224 end if;
4192 -- If an aggregate component has a type with predicates, an explicit 4227 -- If an aggregate component has a type with predicates, an explicit
4193 -- predicate check must be applied, as for an assignment statement, 4228 -- predicate check must be applied, as for an assignment statement,
4194 -- because the aggegate might not be expanded into individual 4229 -- because the aggegate might not be expanded into individual
4195 -- component assignments. 4230 -- component assignments.
4196 4231
4197 if Present (Predicate_Function (Expr_Type)) 4232 if Has_Predicates (Expr_Type)
4198 and then Analyzed (Expr) 4233 and then Analyzed (Expr)
4199 then 4234 then
4200 Apply_Predicate_Check (Expr, Expr_Type); 4235 Apply_Predicate_Check (Expr, Expr_Type);
4201 end if; 4236 end if;
4202 4237
4252 (Bound : Node_Id; 4287 (Bound : Node_Id;
4253 Disc : Entity_Id; 4288 Disc : Entity_Id;
4254 Expr_Disc : Node_Id) 4289 Expr_Disc : Node_Id)
4255 is 4290 is
4256 begin 4291 begin
4257 if Nkind (Bound) = N_Identifier 4292 if Nkind (Bound) /= N_Identifier then
4258 and then Entity (Bound) = Disc 4293 return;
4294 end if;
4295
4296 -- We expect either the discriminant or the discriminal
4297
4298 if Entity (Bound) = Disc
4299 or else (Ekind (Entity (Bound)) = E_In_Parameter
4300 and then Discriminal_Link (Entity (Bound)) = Disc)
4259 then 4301 then
4260 Rewrite (Bound, New_Copy_Tree (Expr_Disc)); 4302 Rewrite (Bound, New_Copy_Tree (Expr_Disc));
4261 end if; 4303 end if;
4262 end Rewrite_Bound; 4304 end Rewrite_Bound;
4263 4305
4268 Expr_Disc : Elmt_Id; 4310 Expr_Disc : Elmt_Id;
4269 4311
4270 -- Start of processing for Rewrite_Range 4312 -- Start of processing for Rewrite_Range
4271 4313
4272 begin 4314 begin
4273 if Has_Discriminants (Root_Type) 4315 if Has_Discriminants (Root_Type) and then Nkind (Rge) = N_Range then
4274 and then Nkind (Rge) = N_Range
4275 then
4276 Low := Low_Bound (Rge); 4316 Low := Low_Bound (Rge);
4277 High := High_Bound (Rge); 4317 High := High_Bound (Rge);
4278 4318
4279 Disc := First_Discriminant (Root_Type); 4319 Disc := First_Discriminant (Root_Type);
4280 Expr_Disc := First_Elmt (Stored_Constraint (Etype (N))); 4320 Expr_Disc := First_Elmt (Stored_Constraint (Etype (N)));
4891 declare 4931 declare
4892 Rec_Typ : constant Entity_Id := Scope (Component); 4932 Rec_Typ : constant Entity_Id := Scope (Component);
4893 -- Root record type whose discriminants may be used as 4933 -- Root record type whose discriminants may be used as
4894 -- bounds in range nodes. 4934 -- bounds in range nodes.
4895 4935
4896 Index : Node_Id; 4936 Assoc : Node_Id;
4937 Choice : Node_Id;
4938 Index : Node_Id;
4897 4939
4898 begin 4940 begin
4899 -- Rewrite the range nodes occurring in the indexes 4941 -- Rewrite the range nodes occurring in the indexes
4900 -- and their types. 4942 -- and their types.
4901 4943
4907 4949
4908 Next_Index (Index); 4950 Next_Index (Index);
4909 end loop; 4951 end loop;
4910 4952
4911 -- Rewrite the range nodes occurring as aggregate 4953 -- Rewrite the range nodes occurring as aggregate
4912 -- bounds. 4954 -- bounds and component associations.
4913 4955
4914 if Nkind (Expr) = N_Aggregate 4956 if Nkind (Expr) = N_Aggregate then
4915 and then Present (Aggregate_Bounds (Expr)) 4957 if Present (Aggregate_Bounds (Expr)) then
4916 then 4958 Rewrite_Range (Rec_Typ, Aggregate_Bounds (Expr));
4917 Rewrite_Range (Rec_Typ, Aggregate_Bounds (Expr)); 4959 end if;
4960
4961 if Present (Component_Associations (Expr)) then
4962 Assoc := First (Component_Associations (Expr));
4963 while Present (Assoc) loop
4964 Choice := First (Choices (Assoc));
4965 while Present (Choice) loop
4966 Rewrite_Range (Rec_Typ, Choice);
4967
4968 Next (Choice);
4969 end loop;
4970
4971 Next (Assoc);
4972 end loop;
4973 end if;
4918 end if; 4974 end if;
4919 end; 4975 end;
4920 end if; 4976 end if;
4921 4977
4922 Add_Association 4978 Add_Association