Mercurial > hg > CbC > CbC_gcc
comparison gcc/ada/sem_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 -- S E M _ C H 3 -- | 5 -- S E M _ 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- -- |
59 with Sem_Ch8; use Sem_Ch8; | 59 with Sem_Ch8; use Sem_Ch8; |
60 with Sem_Ch13; use Sem_Ch13; | 60 with Sem_Ch13; use Sem_Ch13; |
61 with Sem_Dim; use Sem_Dim; | 61 with Sem_Dim; use Sem_Dim; |
62 with Sem_Disp; use Sem_Disp; | 62 with Sem_Disp; use Sem_Disp; |
63 with Sem_Dist; use Sem_Dist; | 63 with Sem_Dist; use Sem_Dist; |
64 with Sem_Elab; use Sem_Elab; | |
64 with Sem_Elim; use Sem_Elim; | 65 with Sem_Elim; use Sem_Elim; |
65 with Sem_Eval; use Sem_Eval; | 66 with Sem_Eval; use Sem_Eval; |
66 with Sem_Mech; use Sem_Mech; | 67 with Sem_Mech; use Sem_Mech; |
67 with Sem_Res; use Sem_Res; | 68 with Sem_Res; use Sem_Res; |
68 with Sem_Smem; use Sem_Smem; | 69 with Sem_Smem; use Sem_Smem; |
602 (T : Entity_Id; | 603 (T : Entity_Id; |
603 Def : Node_Id); | 604 Def : Node_Id); |
604 -- Create a new ordinary fixed point type, and apply the constraint to | 605 -- Create a new ordinary fixed point type, and apply the constraint to |
605 -- obtain subtype of it. | 606 -- obtain subtype of it. |
606 | 607 |
608 procedure Preanalyze_Default_Expression (N : Node_Id; T : Entity_Id); | |
609 -- Wrapper on Preanalyze_Spec_Expression for default expressions, so that | |
610 -- In_Default_Expr can be properly adjusted. | |
611 | |
607 procedure Prepare_Private_Subtype_Completion | 612 procedure Prepare_Private_Subtype_Completion |
608 (Id : Entity_Id; | 613 (Id : Entity_Id; |
609 Related_Nod : Node_Id); | 614 Related_Nod : Node_Id); |
610 -- Id is a subtype of some private type. Creates the full declaration | 615 -- Id is a subtype of some private type. Creates the full declaration |
611 -- associated with Id whenever possible, i.e. when the full declaration | 616 -- associated with Id whenever possible, i.e. when the full declaration |
1296 Set_Convention (Desig_Type, Convention_Protected); | 1301 Set_Convention (Desig_Type, Convention_Protected); |
1297 else | 1302 else |
1298 Set_Ekind (T_Name, E_Access_Subprogram_Type); | 1303 Set_Ekind (T_Name, E_Access_Subprogram_Type); |
1299 end if; | 1304 end if; |
1300 | 1305 |
1301 Set_Can_Use_Internal_Rep (T_Name, not Always_Compatible_Rep_On_Target); | 1306 Set_Can_Use_Internal_Rep (T_Name, |
1302 | 1307 not Always_Compatible_Rep_On_Target); |
1303 Set_Etype (T_Name, T_Name); | 1308 Set_Etype (T_Name, T_Name); |
1304 Init_Size_Align (T_Name); | 1309 Init_Size_Align (T_Name); |
1305 Set_Directly_Designated_Type (T_Name, Desig_Type); | 1310 Set_Directly_Designated_Type (T_Name, Desig_Type); |
1311 | |
1312 -- If the access_to_subprogram is not declared at the library level, | |
1313 -- it can only point to subprograms that are at the same or deeper | |
1314 -- accessibility level. The corresponding subprogram type might | |
1315 -- require an activation record when compiling for C. | |
1316 | |
1317 Set_Needs_Activation_Record (Desig_Type, | |
1318 not Is_Library_Level_Entity (T_Name)); | |
1306 | 1319 |
1307 Generate_Reference_To_Formals (T_Name); | 1320 Generate_Reference_To_Formals (T_Name); |
1308 | 1321 |
1309 -- Ada 2005 (AI-231): Propagate the null-excluding attribute | 1322 -- Ada 2005 (AI-231): Propagate the null-excluding attribute |
1310 | 1323 |
1729 | 1742 |
1730 -- Apply legality checks in RM 6.1.1 (10-13) concerning | 1743 -- Apply legality checks in RM 6.1.1 (10-13) concerning |
1731 -- nonconforming preconditions in both an ancestor and | 1744 -- nonconforming preconditions in both an ancestor and |
1732 -- a progenitor operation. | 1745 -- a progenitor operation. |
1733 | 1746 |
1747 -- If the operation is a primitive wrapper it is an explicit | |
1748 -- (overriding) operqtion and all is fine. | |
1749 | |
1734 if Present (Anc) | 1750 if Present (Anc) |
1735 and then Has_Non_Trivial_Precondition (Anc) | 1751 and then Has_Non_Trivial_Precondition (Anc) |
1736 and then Has_Non_Trivial_Precondition (Iface_Prim) | 1752 and then Has_Non_Trivial_Precondition (Iface_Prim) |
1737 then | 1753 then |
1738 if Is_Abstract_Subprogram (Prim) | 1754 if Is_Abstract_Subprogram (Prim) |
1739 or else | 1755 or else |
1740 (Ekind (Prim) = E_Procedure | 1756 (Ekind (Prim) = E_Procedure |
1741 and then Nkind (Parent (Prim)) = | 1757 and then Nkind (Parent (Prim)) = |
1742 N_Procedure_Specification | 1758 N_Procedure_Specification |
1743 and then Null_Present (Parent (Prim))) | 1759 and then Null_Present (Parent (Prim))) |
1760 or else Is_Primitive_Wrapper (Prim) | |
1744 then | 1761 then |
1745 null; | 1762 null; |
1746 | 1763 |
1747 -- The inherited operation must be overridden | 1764 -- The operation is inherited and must be overridden |
1748 | 1765 |
1749 elsif not Comes_From_Source (Prim) then | 1766 elsif not Comes_From_Source (Prim) then |
1750 Error_Msg_NE | 1767 Error_Msg_NE |
1751 ("&inherits non-conforming preconditions and must " | 1768 ("&inherits non-conforming preconditions and must " |
1752 & "be overridden (RM 6.1.1 (10-16)", | 1769 & "be overridden (RM 6.1.1 (10-16)", |
1900 | 1917 |
1901 begin | 1918 begin |
1902 if Is_Limited_Record (Typ) then | 1919 if Is_Limited_Record (Typ) then |
1903 return True; | 1920 return True; |
1904 | 1921 |
1905 -- If the root type is limited (and not a limited interface) | 1922 -- If the root type is limited (and not a limited interface) so is |
1906 -- so is the current type | 1923 -- the current type. |
1907 | 1924 |
1908 elsif Is_Limited_Record (R) | 1925 elsif Is_Limited_Record (R) |
1909 and then (not Is_Interface (R) or else not Is_Limited_Interface (R)) | 1926 and then (not Is_Interface (R) or else not Is_Limited_Interface (R)) |
1910 then | 1927 then |
1911 return True; | 1928 return True; |
1912 | 1929 |
1913 -- Else the type may have a limited interface progenitor, but a | 1930 -- Else the type may have a limited interface progenitor, but a |
1914 -- limited record parent. | 1931 -- limited record parent that is not an interface. |
1915 | 1932 |
1916 elsif R /= P and then Is_Limited_Record (P) then | 1933 elsif R /= P |
1934 and then Is_Limited_Record (P) | |
1935 and then not Is_Interface (P) | |
1936 then | |
1917 return True; | 1937 return True; |
1918 | 1938 |
1919 else | 1939 else |
1920 return False; | 1940 return False; |
1921 end if; | 1941 end if; |
2203 -- Type_Invariant | 2223 -- Type_Invariant |
2204 -- | 2224 -- |
2205 -- Context denotes the owner of the declarative list. | 2225 -- Context denotes the owner of the declarative list. |
2206 | 2226 |
2207 procedure Check_Entry_Contracts; | 2227 procedure Check_Entry_Contracts; |
2208 -- Perform a pre-analysis of the pre- and postconditions of an entry | 2228 -- Perform a preanalysis of the pre- and postconditions of an entry |
2209 -- declaration. This must be done before full resolution and creation | 2229 -- declaration. This must be done before full resolution and creation |
2210 -- of the parameter block, etc. to catch illegal uses within the | 2230 -- of the parameter block, etc. to catch illegal uses within the |
2211 -- contract expression. Full analysis of the expression is done when | 2231 -- contract expression. Full analysis of the expression is done when |
2212 -- the contract is processed. | 2232 -- the contract is processed. |
2213 | 2233 |
2816 -- Post-freezing actions | 2836 -- Post-freezing actions |
2817 | 2837 |
2818 if Present (L) then | 2838 if Present (L) then |
2819 Context := Parent (L); | 2839 Context := Parent (L); |
2820 | 2840 |
2821 -- Analyze the contracts of packages and their bodies | 2841 -- Certain contract annocations have forward visibility semantics and |
2822 | 2842 -- must be analyzed after all declarative items have been processed. |
2823 if Nkind (Context) = N_Package_Specification | 2843 -- This timing ensures that entities referenced by such contracts are |
2824 and then L = Visible_Declarations (Context) | 2844 -- visible. |
2825 then | 2845 |
2846 -- Analyze the contract of an immediately enclosing package spec or | |
2847 -- body first because other contracts may depend on its information. | |
2848 | |
2849 if Nkind (Context) = N_Package_Body then | |
2850 Analyze_Package_Body_Contract (Defining_Entity (Context)); | |
2851 | |
2852 elsif Nkind (Context) = N_Package_Specification then | |
2826 Analyze_Package_Contract (Defining_Entity (Context)); | 2853 Analyze_Package_Contract (Defining_Entity (Context)); |
2827 | 2854 end if; |
2828 elsif Nkind (Context) = N_Package_Body then | 2855 |
2829 Analyze_Package_Body_Contract (Defining_Entity (Context)); | 2856 -- Analyze the contracts of various constructs in the declarative |
2830 end if; | 2857 -- list. |
2831 | |
2832 -- Analyze the contracts of various constructs now due to the delayed | |
2833 -- visibility needs of their aspects and pragmas. | |
2834 | 2858 |
2835 Analyze_Contracts (L); | 2859 Analyze_Contracts (L); |
2836 | 2860 |
2837 if Nkind (Context) = N_Package_Body then | 2861 if Nkind (Context) = N_Package_Body then |
2838 | 2862 |
2846 -- restore the original state conditions. | 2870 -- restore the original state conditions. |
2847 | 2871 |
2848 Remove_Visible_Refinements (Corresponding_Spec (Context)); | 2872 Remove_Visible_Refinements (Corresponding_Spec (Context)); |
2849 Remove_Partial_Visible_Refinements (Corresponding_Spec (Context)); | 2873 Remove_Partial_Visible_Refinements (Corresponding_Spec (Context)); |
2850 | 2874 |
2851 elsif Nkind (Context) = N_Package_Declaration then | 2875 elsif Nkind (Context) = N_Package_Specification then |
2852 | 2876 |
2853 -- Partial state refinements are visible up to the end of the | 2877 -- Partial state refinements are visible up to the end of the |
2854 -- package spec declarations. Hide the partial state refinements | 2878 -- package spec declarations. Hide the partial state refinements |
2855 -- from visibility to restore the original state conditions. | 2879 -- from visibility to restore the original state conditions. |
2856 | 2880 |
2857 Remove_Partial_Visible_Refinements (Corresponding_Spec (Context)); | 2881 Remove_Partial_Visible_Refinements (Defining_Entity (Context)); |
2858 end if; | 2882 end if; |
2859 | 2883 |
2860 -- Verify that all abstract states found in any package declared in | 2884 -- Verify that all abstract states found in any package declared in |
2861 -- the input declarative list have proper refinements. The check is | 2885 -- the input declarative list have proper refinements. The check is |
2862 -- performed only when the context denotes a block, entry, package, | 2886 -- performed only when the context denotes a block, entry, package, |
3114 -- to the high level optimizer). | 3138 -- to the high level optimizer). |
3115 | 3139 |
3116 if not Analyzed (T) then | 3140 if not Analyzed (T) then |
3117 Set_Analyzed (T); | 3141 Set_Analyzed (T); |
3118 | 3142 |
3143 -- Set the SPARK mode from the current context | |
3144 | |
3145 Set_SPARK_Pragma (T, SPARK_Mode_Pragma); | |
3146 Set_SPARK_Pragma_Inherited (T); | |
3147 | |
3119 case Nkind (Def) is | 3148 case Nkind (Def) is |
3120 when N_Access_To_Subprogram_Definition => | 3149 when N_Access_To_Subprogram_Definition => |
3121 Access_Subprogram_Declaration (T, Def); | 3150 Access_Subprogram_Declaration (T, Def); |
3122 | 3151 |
3123 -- If this is a remote access to subprogram, we must create the | 3152 -- If this is a remote access to subprogram, we must create the |
3160 -- derivations. | 3189 -- derivations. |
3161 | 3190 |
3162 if Is_Type (T) and then Has_Predicates (T) then | 3191 if Is_Type (T) and then Has_Predicates (T) then |
3163 Set_Has_Predicates (Def_Id); | 3192 Set_Has_Predicates (Def_Id); |
3164 end if; | 3193 end if; |
3194 | |
3195 -- Save the scenario for examination by the ABE Processing | |
3196 -- phase. | |
3197 | |
3198 Record_Elaboration_Scenario (N); | |
3165 | 3199 |
3166 when N_Enumeration_Type_Definition => | 3200 when N_Enumeration_Type_Definition => |
3167 Enumeration_Type_Declaration (T, Def); | 3201 Enumeration_Type_Declaration (T, Def); |
3168 | 3202 |
3169 when N_Floating_Point_Definition => | 3203 when N_Floating_Point_Definition => |
3356 | 3390 |
3357 -- In this case, the discriminants (if any) must match | 3391 -- In this case, the discriminants (if any) must match |
3358 | 3392 |
3359 T := Find_Type_Name (N); | 3393 T := Find_Type_Name (N); |
3360 | 3394 |
3361 Set_Ekind (T, E_Incomplete_Type); | 3395 Set_Ekind (T, E_Incomplete_Type); |
3362 Init_Size_Align (T); | 3396 Set_Etype (T, T); |
3363 Set_Is_First_Subtype (T, True); | 3397 Set_Is_First_Subtype (T); |
3364 Set_Etype (T, T); | 3398 Init_Size_Align (T); |
3399 | |
3400 -- Set the SPARK mode from the current context | |
3401 | |
3402 Set_SPARK_Pragma (T, SPARK_Mode_Pragma); | |
3403 Set_SPARK_Pragma_Inherited (T); | |
3365 | 3404 |
3366 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged | 3405 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged |
3367 -- incomplete types. | 3406 -- incomplete types. |
3368 | 3407 |
3369 if Tagged_Present (N) then | 3408 if Tagged_Present (N) then |
3638 -- indicating the count is unknown. | 3677 -- indicating the count is unknown. |
3639 | 3678 |
3640 function Delayed_Aspect_Present return Boolean; | 3679 function Delayed_Aspect_Present return Boolean; |
3641 -- If the declaration has an expression that is an aggregate, and it | 3680 -- If the declaration has an expression that is an aggregate, and it |
3642 -- has aspects that require delayed analysis, the resolution of the | 3681 -- has aspects that require delayed analysis, the resolution of the |
3643 -- aggregate must be deferred to the freeze point of the objet. This | 3682 -- aggregate must be deferred to the freeze point of the object. This |
3644 -- special processing was created for address clauses, but it must | 3683 -- special processing was created for address clauses, but it must |
3645 -- also apply to Alignment. This must be done before the aspect | 3684 -- also apply to Alignment. This must be done before the aspect |
3646 -- specifications are analyzed because we must handle the aggregate | 3685 -- specifications are analyzed because we must handle the aggregate |
3647 -- before the analysis of the object declaration is complete. | 3686 -- before the analysis of the object declaration is complete. |
3648 | 3687 |
3879 return False; | 3918 return False; |
3880 end Delayed_Aspect_Present; | 3919 end Delayed_Aspect_Present; |
3881 | 3920 |
3882 -- Local variables | 3921 -- Local variables |
3883 | 3922 |
3884 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; | 3923 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
3885 -- Save the Ghost mode to restore on exit | 3924 Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
3925 -- Save the Ghost-related attributes to restore on exit | |
3886 | 3926 |
3887 Related_Id : Entity_Id; | 3927 Related_Id : Entity_Id; |
3888 | 3928 |
3889 -- Start of processing for Analyze_Object_Declaration | 3929 -- Start of processing for Analyze_Object_Declaration |
3890 | 3930 |
4242 or else Delayed_Aspect_Present) | 4282 or else Delayed_Aspect_Present) |
4243 then | 4283 then |
4244 Set_Etype (E, T); | 4284 Set_Etype (E, T); |
4245 | 4285 |
4246 else | 4286 else |
4287 | |
4288 -- If the expression is a formal that is a "subprogram pointer" | |
4289 -- this is illegal in accessibility terms (see RM 3.10.2 (13.1/2) | |
4290 -- and AARM 3.10.2 (13.b/2)). Add an explicit conversion to force | |
4291 -- the corresponding check, as is done for assignments. | |
4292 | |
4293 if Is_Entity_Name (E) | |
4294 and then Present (Entity (E)) | |
4295 and then Is_Formal (Entity (E)) | |
4296 and then | |
4297 Ekind (Etype (Entity (E))) = E_Anonymous_Access_Subprogram_Type | |
4298 and then Ekind (T) /= E_Anonymous_Access_Subprogram_Type | |
4299 then | |
4300 Rewrite (E, Convert_To (T, Relocate_Node (E))); | |
4301 end if; | |
4302 | |
4247 Resolve (E, T); | 4303 Resolve (E, T); |
4248 end if; | 4304 end if; |
4249 | 4305 |
4250 -- No further action needed if E is a call to an inlined function | 4306 -- No further action needed if E is a call to an inlined function |
4251 -- which returns an unconstrained type and it has been expanded into | 4307 -- which returns an unconstrained type and it has been expanded into |
4715 -- Preserve relevant elaboration-related attributes of the context which | 4771 -- Preserve relevant elaboration-related attributes of the context which |
4716 -- are no longer available or very expensive to recompute once analysis, | 4772 -- are no longer available or very expensive to recompute once analysis, |
4717 -- resolution, and expansion are over. | 4773 -- resolution, and expansion are over. |
4718 | 4774 |
4719 Mark_Elaboration_Attributes | 4775 Mark_Elaboration_Attributes |
4720 (N_Id => Id, | 4776 (N_Id => Id, |
4721 Checks => True); | 4777 Checks => True, |
4778 Warnings => True); | |
4722 | 4779 |
4723 -- Initialize alignment and size and capture alignment setting | 4780 -- Initialize alignment and size and capture alignment setting |
4724 | 4781 |
4725 Init_Alignment (Id); | 4782 Init_Alignment (Id); |
4726 Init_Esize (Id); | 4783 Init_Esize (Id); |
4926 | 4983 |
4927 if Ekind (Id) = E_Variable then | 4984 if Ekind (Id) = E_Variable then |
4928 Check_No_Hidden_State (Id); | 4985 Check_No_Hidden_State (Id); |
4929 end if; | 4986 end if; |
4930 | 4987 |
4931 Restore_Ghost_Mode (Saved_GM); | 4988 Restore_Ghost_Region (Saved_GM, Saved_IGR); |
4932 end Analyze_Object_Declaration; | 4989 end Analyze_Object_Declaration; |
4933 | 4990 |
4934 --------------------------- | 4991 --------------------------- |
4935 -- Analyze_Others_Choice -- | 4992 -- Analyze_Others_Choice -- |
4936 --------------------------- | 4993 --------------------------- |
5058 | 5115 |
5059 Set_Convention (T, Convention (Parent_Type)); | 5116 Set_Convention (T, Convention (Parent_Type)); |
5060 Set_First_Rep_Item (T, First_Rep_Item (Parent_Type)); | 5117 Set_First_Rep_Item (T, First_Rep_Item (Parent_Type)); |
5061 Set_Is_First_Subtype (T); | 5118 Set_Is_First_Subtype (T); |
5062 Make_Class_Wide_Type (T); | 5119 Make_Class_Wide_Type (T); |
5120 | |
5121 -- Set the SPARK mode from the current context | |
5122 | |
5123 Set_SPARK_Pragma (T, SPARK_Mode_Pragma); | |
5124 Set_SPARK_Pragma_Inherited (T); | |
5063 | 5125 |
5064 if Unknown_Discriminants_Present (N) then | 5126 if Unknown_Discriminants_Present (N) then |
5065 Set_Discriminant_Constraint (T, No_Elist); | 5127 Set_Discriminant_Constraint (T, No_Elist); |
5066 end if; | 5128 end if; |
5067 | 5129 |
5228 -- type with constraints. In this case the entity has been introduced | 5290 -- type with constraints. In this case the entity has been introduced |
5229 -- in the private declaration. | 5291 -- in the private declaration. |
5230 | 5292 |
5231 -- Finally this happens in some complex cases when validity checks are | 5293 -- Finally this happens in some complex cases when validity checks are |
5232 -- enabled, where the same subtype declaration may be analyzed twice. | 5294 -- enabled, where the same subtype declaration may be analyzed twice. |
5233 -- This can happen if the subtype is created by the pre-analysis of | 5295 -- This can happen if the subtype is created by the preanalysis of |
5234 -- an attribute tht gives the range of a loop statement, and the loop | 5296 -- an attribute tht gives the range of a loop statement, and the loop |
5235 -- itself appears within an if_statement that will be rewritten during | 5297 -- itself appears within an if_statement that will be rewritten during |
5236 -- expansion. | 5298 -- expansion. |
5237 | 5299 |
5238 if Skip | 5300 if Skip |
5289 -- (no aspects to examine on the generated declaration). | 5351 -- (no aspects to examine on the generated declaration). |
5290 | 5352 |
5291 if not Comes_From_Source (N) then | 5353 if not Comes_From_Source (N) then |
5292 Set_Ekind (Id, Ekind (T)); | 5354 Set_Ekind (Id, Ekind (T)); |
5293 | 5355 |
5294 if Present (Predicate_Function (T)) then | 5356 if Present (Predicate_Function (Id)) then |
5357 null; | |
5358 | |
5359 elsif Present (Predicate_Function (T)) then | |
5295 Set_Predicate_Function (Id, Predicate_Function (T)); | 5360 Set_Predicate_Function (Id, Predicate_Function (T)); |
5296 | 5361 |
5297 elsif Present (Ancestor_Subtype (T)) | 5362 elsif Present (Ancestor_Subtype (T)) |
5298 and then Has_Predicates (Ancestor_Subtype (T)) | |
5299 and then Present (Predicate_Function (Ancestor_Subtype (T))) | 5363 and then Present (Predicate_Function (Ancestor_Subtype (T))) |
5300 then | 5364 then |
5301 Set_Predicate_Function (Id, | 5365 Set_Predicate_Function (Id, |
5302 Predicate_Function (Ancestor_Subtype (T))); | 5366 Predicate_Function (Ancestor_Subtype (T))); |
5303 end if; | 5367 end if; |
5394 Set_Scalar_Range (Id, Scalar_Range (T)); | 5458 Set_Scalar_Range (Id, Scalar_Range (T)); |
5395 Set_Is_Character_Type (Id, Is_Character_Type (T)); | 5459 Set_Is_Character_Type (Id, Is_Character_Type (T)); |
5396 Set_Is_Constrained (Id, Is_Constrained (T)); | 5460 Set_Is_Constrained (Id, Is_Constrained (T)); |
5397 Set_Is_Known_Valid (Id, Is_Known_Valid (T)); | 5461 Set_Is_Known_Valid (Id, Is_Known_Valid (T)); |
5398 Set_RM_Size (Id, RM_Size (T)); | 5462 Set_RM_Size (Id, RM_Size (T)); |
5399 Inherit_Predicate_Flags (Id, T); | |
5400 | 5463 |
5401 when Ordinary_Fixed_Point_Kind => | 5464 when Ordinary_Fixed_Point_Kind => |
5402 Set_Ekind (Id, E_Ordinary_Fixed_Point_Subtype); | 5465 Set_Ekind (Id, E_Ordinary_Fixed_Point_Subtype); |
5403 Set_Scalar_Range (Id, Scalar_Range (T)); | 5466 Set_Scalar_Range (Id, Scalar_Range (T)); |
5404 Set_Small_Value (Id, Small_Value (T)); | 5467 Set_Small_Value (Id, Small_Value (T)); |
5420 Set_Ekind (Id, E_Signed_Integer_Subtype); | 5483 Set_Ekind (Id, E_Signed_Integer_Subtype); |
5421 Set_Scalar_Range (Id, Scalar_Range (T)); | 5484 Set_Scalar_Range (Id, Scalar_Range (T)); |
5422 Set_Is_Constrained (Id, Is_Constrained (T)); | 5485 Set_Is_Constrained (Id, Is_Constrained (T)); |
5423 Set_Is_Known_Valid (Id, Is_Known_Valid (T)); | 5486 Set_Is_Known_Valid (Id, Is_Known_Valid (T)); |
5424 Set_RM_Size (Id, RM_Size (T)); | 5487 Set_RM_Size (Id, RM_Size (T)); |
5425 Inherit_Predicate_Flags (Id, T); | |
5426 | 5488 |
5427 when Modular_Integer_Kind => | 5489 when Modular_Integer_Kind => |
5428 Set_Ekind (Id, E_Modular_Integer_Subtype); | 5490 Set_Ekind (Id, E_Modular_Integer_Subtype); |
5429 Set_Scalar_Range (Id, Scalar_Range (T)); | 5491 Set_Scalar_Range (Id, Scalar_Range (T)); |
5430 Set_Is_Constrained (Id, Is_Constrained (T)); | 5492 Set_Is_Constrained (Id, Is_Constrained (T)); |
5431 Set_Is_Known_Valid (Id, Is_Known_Valid (T)); | 5493 Set_Is_Known_Valid (Id, Is_Known_Valid (T)); |
5432 Set_RM_Size (Id, RM_Size (T)); | 5494 Set_RM_Size (Id, RM_Size (T)); |
5433 Inherit_Predicate_Flags (Id, T); | |
5434 | 5495 |
5435 when Class_Wide_Kind => | 5496 when Class_Wide_Kind => |
5436 Set_Ekind (Id, E_Class_Wide_Subtype); | 5497 Set_Ekind (Id, E_Class_Wide_Subtype); |
5437 Set_Class_Wide_Type (Id, Class_Wide_Type (T)); | 5498 Set_Class_Wide_Type (Id, Class_Wide_Type (T)); |
5438 Set_Cloned_Subtype (Id, T); | 5499 Set_Cloned_Subtype (Id, T); |
5645 end if; | 5706 end if; |
5646 | 5707 |
5647 when others => | 5708 when others => |
5648 raise Program_Error; | 5709 raise Program_Error; |
5649 end case; | 5710 end case; |
5711 | |
5712 -- If there is no constraint in the subtype indication, the | |
5713 -- declared entity inherits predicates from the parent. | |
5714 | |
5715 Inherit_Predicate_Flags (Id, T); | |
5650 end if; | 5716 end if; |
5651 | 5717 |
5652 if Etype (Id) = Any_Type then | 5718 if Etype (Id) = Any_Type then |
5653 goto Leave; | 5719 goto Leave; |
5654 end if; | 5720 end if; |
6555 Pbase : constant Entity_Id := Base_Type (Parent_Type); | 6621 Pbase : constant Entity_Id := Base_Type (Parent_Type); |
6556 Ibase : constant Entity_Id := | 6622 Ibase : constant Entity_Id := |
6557 Create_Itype (Ekind (Pbase), N, Derived_Type, 'B'); | 6623 Create_Itype (Ekind (Pbase), N, Derived_Type, 'B'); |
6558 Svg_Chars : constant Name_Id := Chars (Ibase); | 6624 Svg_Chars : constant Name_Id := Chars (Ibase); |
6559 Svg_Next_E : constant Entity_Id := Next_Entity (Ibase); | 6625 Svg_Next_E : constant Entity_Id := Next_Entity (Ibase); |
6626 Svg_Prev_E : constant Entity_Id := Prev_Entity (Ibase); | |
6560 | 6627 |
6561 begin | 6628 begin |
6562 Copy_Node (Pbase, Ibase); | 6629 Copy_Node (Pbase, Ibase); |
6563 | 6630 |
6564 -- Restore Itype status after Copy_Node | 6631 -- Restore Itype status after Copy_Node |
6565 | 6632 |
6566 Set_Is_Itype (Ibase); | 6633 Set_Is_Itype (Ibase); |
6567 Set_Associated_Node_For_Itype (Ibase, N); | 6634 Set_Associated_Node_For_Itype (Ibase, N); |
6568 | 6635 |
6569 Set_Chars (Ibase, Svg_Chars); | 6636 Set_Chars (Ibase, Svg_Chars); |
6637 Set_Prev_Entity (Ibase, Svg_Prev_E); | |
6570 Set_Next_Entity (Ibase, Svg_Next_E); | 6638 Set_Next_Entity (Ibase, Svg_Next_E); |
6571 Set_Sloc (Ibase, Sloc (Derived_Type)); | 6639 Set_Sloc (Ibase, Sloc (Derived_Type)); |
6572 Set_Scope (Ibase, Scope (Derived_Type)); | 6640 Set_Scope (Ibase, Scope (Derived_Type)); |
6573 Set_Freeze_Node (Ibase, Empty); | 6641 Set_Freeze_Node (Ibase, Empty); |
6574 Set_Is_Frozen (Ibase, False); | 6642 Set_Is_Frozen (Ibase, False); |
6637 is | 6705 is |
6638 Loc : constant Source_Ptr := Sloc (N); | 6706 Loc : constant Source_Ptr := Sloc (N); |
6639 Tdef : constant Node_Id := Type_Definition (N); | 6707 Tdef : constant Node_Id := Type_Definition (N); |
6640 Indic : constant Node_Id := Subtype_Indication (Tdef); | 6708 Indic : constant Node_Id := Subtype_Indication (Tdef); |
6641 Parent_Base : constant Entity_Id := Base_Type (Parent_Type); | 6709 Parent_Base : constant Entity_Id := Base_Type (Parent_Type); |
6642 Implicit_Base : Entity_Id; | 6710 Implicit_Base : Entity_Id := Empty; |
6643 New_Indic : Node_Id; | 6711 New_Indic : Node_Id; |
6644 | 6712 |
6645 procedure Make_Implicit_Base; | 6713 procedure Make_Implicit_Base; |
6646 -- If the parent subtype is constrained, the derived type is a subtype | 6714 -- If the parent subtype is constrained, the derived type is a subtype |
6647 -- of an implicit base type derived from the parent base. | 6715 -- of an implicit base type derived from the parent base. |
6749 Constraint_Present : constant Boolean := | 6817 Constraint_Present : constant Boolean := |
6750 Nkind (Subtype_Indication (Type_Definition (N))) = | 6818 Nkind (Subtype_Indication (Type_Definition (N))) = |
6751 N_Subtype_Indication; | 6819 N_Subtype_Indication; |
6752 | 6820 |
6753 D_Constraint : Node_Id; | 6821 D_Constraint : Node_Id; |
6754 New_Constraint : Elist_Id; | 6822 New_Constraint : Elist_Id := No_Elist; |
6755 Old_Disc : Entity_Id; | 6823 Old_Disc : Entity_Id; |
6756 New_Disc : Entity_Id; | 6824 New_Disc : Entity_Id; |
6757 New_N : Node_Id; | 6825 New_N : Node_Id; |
6758 | 6826 |
6759 begin | 6827 begin |
6988 Old_Disc := First_Discriminant (Parent_Type); | 7056 Old_Disc := First_Discriminant (Parent_Type); |
6989 while Present (Old_Disc) loop | 7057 while Present (Old_Disc) loop |
6990 if No (Next_Entity (Old_Disc)) | 7058 if No (Next_Entity (Old_Disc)) |
6991 or else Ekind (Next_Entity (Old_Disc)) /= E_Discriminant | 7059 or else Ekind (Next_Entity (Old_Disc)) /= E_Discriminant |
6992 then | 7060 then |
6993 Set_Next_Entity | 7061 Link_Entities |
6994 (Last_Entity (Derived_Type), Next_Entity (Old_Disc)); | 7062 (Last_Entity (Derived_Type), Next_Entity (Old_Disc)); |
6995 exit; | 7063 exit; |
6996 end if; | 7064 end if; |
6997 | 7065 |
6998 Next_Discriminant (Old_Disc); | 7066 Next_Discriminant (Old_Disc); |
7803 (N, Parent_Type, Derived_Type, Derive_Subps); | 7871 (N, Parent_Type, Derived_Type, Derive_Subps); |
7804 | 7872 |
7805 -- Build the full derivation if this is not the anonymous derived | 7873 -- Build the full derivation if this is not the anonymous derived |
7806 -- base type created by Build_Derived_Record_Type in the constrained | 7874 -- base type created by Build_Derived_Record_Type in the constrained |
7807 -- case (see point 5. of its head comment) since we build it for the | 7875 -- case (see point 5. of its head comment) since we build it for the |
7808 -- derived subtype. And skip it for protected types altogether, as | 7876 -- derived subtype. And skip it for synchronized types altogether, as |
7809 -- gigi does not use these types directly. | 7877 -- gigi does not use these types directly. |
7810 | 7878 |
7811 if Present (Full_View (Parent_Type)) | 7879 if Present (Full_View (Parent_Type)) |
7812 and then not Is_Itype (Derived_Type) | 7880 and then not Is_Itype (Derived_Type) |
7813 and then not (Ekind (Full_View (Parent_Type)) in Protected_Kind) | 7881 and then not Is_Concurrent_Type (Full_View (Parent_Type)) |
7814 then | 7882 then |
7815 declare | 7883 declare |
7816 Der_Base : constant Entity_Id := Base_Type (Derived_Type); | 7884 Der_Base : constant Entity_Id := Base_Type (Derived_Type); |
7817 Discr : Entity_Id; | 7885 Discr : Entity_Id; |
7818 Last_Discr : Entity_Id; | 7886 Last_Discr : Entity_Id; |
8487 Parent_Base := Base_Type (Full_View (Parent_Type)); | 8555 Parent_Base := Base_Type (Full_View (Parent_Type)); |
8488 else | 8556 else |
8489 Parent_Base := Base_Type (Parent_Type); | 8557 Parent_Base := Base_Type (Parent_Type); |
8490 end if; | 8558 end if; |
8491 | 8559 |
8492 -- AI05-0115 : if this is a derivation from a private type in some | 8560 -- AI05-0115: if this is a derivation from a private type in some |
8493 -- other scope that may lead to invisible components for the derived | 8561 -- other scope that may lead to invisible components for the derived |
8494 -- type, mark it accordingly. | 8562 -- type, mark it accordingly. |
8495 | 8563 |
8496 if Is_Private_Type (Parent_Type) then | 8564 if Is_Private_Type (Parent_Type) then |
8497 if Scope (Parent_Type) = Scope (Derived_Type) then | 8565 if Scope (Parent_Base) = Scope (Derived_Type) then |
8498 null; | 8566 null; |
8499 | 8567 |
8500 elsif In_Open_Scopes (Scope (Parent_Type)) | 8568 elsif In_Open_Scopes (Scope (Parent_Base)) |
8501 and then In_Private_Part (Scope (Parent_Type)) | 8569 and then In_Private_Part (Scope (Parent_Base)) |
8502 then | 8570 then |
8503 null; | 8571 null; |
8504 | 8572 |
8505 else | 8573 else |
8506 Set_Has_Private_Ancestor (Derived_Type); | 8574 Set_Has_Private_Ancestor (Derived_Type); |
9099 -- in scope they must be inherited. | 9167 -- in scope they must be inherited. |
9100 | 9168 |
9101 elsif Has_Unknown_Discriminants (Parent_Type) | 9169 elsif Has_Unknown_Discriminants (Parent_Type) |
9102 and then | 9170 and then |
9103 (not Has_Discriminants (Parent_Type) | 9171 (not Has_Discriminants (Parent_Type) |
9104 or else not In_Open_Scopes (Scope (Parent_Type))) | 9172 or else not In_Open_Scopes (Scope (Parent_Base))) |
9105 then | 9173 then |
9106 Set_Has_Unknown_Discriminants (Derived_Type); | 9174 Set_Has_Unknown_Discriminants (Derived_Type); |
9107 end if; | 9175 end if; |
9108 | 9176 |
9109 if not Has_Unknown_Discriminants (Derived_Type) | 9177 if not Has_Unknown_Discriminants (Derived_Type) |
9377 Copy_Dimensions_Of_Components (Derived_Type); | 9445 Copy_Dimensions_Of_Components (Derived_Type); |
9378 | 9446 |
9379 -- Restore the fields saved prior to the New_Copy_Tree call | 9447 -- Restore the fields saved prior to the New_Copy_Tree call |
9380 -- and compute the stored constraint. | 9448 -- and compute the stored constraint. |
9381 | 9449 |
9382 Set_Etype (Derived_Type, Save_Etype); | 9450 Set_Etype (Derived_Type, Save_Etype); |
9383 Set_Next_Entity (Derived_Type, Save_Next_Entity); | 9451 Link_Entities (Derived_Type, Save_Next_Entity); |
9384 | 9452 |
9385 if Has_Discriminants (Derived_Type) then | 9453 if Has_Discriminants (Derived_Type) then |
9386 Set_Discriminant_Constraint | 9454 Set_Discriminant_Constraint |
9387 (Derived_Type, Save_Discr_Constr); | 9455 (Derived_Type, Save_Discr_Constr); |
9388 Set_Stored_Constraint | 9456 Set_Stored_Constraint |
9389 (Derived_Type, Expand_To_Stored_Constraint (Parent_Type, Discs)); | 9457 (Derived_Type, Expand_To_Stored_Constraint (Parent_Type, Discs)); |
9458 | |
9390 Replace_Components (Derived_Type, New_Decl); | 9459 Replace_Components (Derived_Type, New_Decl); |
9391 end if; | 9460 end if; |
9392 | 9461 |
9393 -- Insert the new derived type declaration | 9462 -- Insert the new derived type declaration |
9394 | 9463 |
9844 or else (Nkind (Constr) = N_Attribute_Reference | 9913 or else (Nkind (Constr) = N_Attribute_Reference |
9845 and then Attribute_Name (Constr) = Name_Range) | 9914 and then Attribute_Name (Constr) = Name_Range) |
9846 then | 9915 then |
9847 Error_Msg_N | 9916 Error_Msg_N |
9848 ("a range is not a valid discriminant constraint", Constr); | 9917 ("a range is not a valid discriminant constraint", Constr); |
9918 Discr_Expr (D) := Error; | |
9919 | |
9920 elsif Nkind (Constr) = N_Subtype_Indication then | |
9921 Error_Msg_N | |
9922 ("a subtype indication is not a valid discriminant constraint", | |
9923 Constr); | |
9849 Discr_Expr (D) := Error; | 9924 Discr_Expr (D) := Error; |
9850 | 9925 |
9851 else | 9926 else |
9852 Process_Discriminant_Expression (Constr, Discr); | 9927 Process_Discriminant_Expression (Constr, Discr); |
9853 Discr_Expr (D) := Constr; | 9928 Discr_Expr (D) := Constr; |
12264 Set_Chars (Full, Chars (Priv)); | 12339 Set_Chars (Full, Chars (Priv)); |
12265 Conditional_Delay (Full, Priv); | 12340 Conditional_Delay (Full, Priv); |
12266 Set_Sloc (Full, Sloc (Priv)); | 12341 Set_Sloc (Full, Sloc (Priv)); |
12267 end case; | 12342 end case; |
12268 | 12343 |
12269 Set_Next_Entity (Full, Save_Next_Entity); | 12344 Link_Entities (Full, Save_Next_Entity); |
12270 Set_Homonym (Full, Save_Homonym); | 12345 Set_Homonym (Full, Save_Homonym); |
12271 Set_Associated_Node_For_Itype (Full, Related_Nod); | 12346 Set_Associated_Node_For_Itype (Full, Related_Nod); |
12272 | 12347 |
12273 -- Set common attributes for all subtypes: kind, convention, etc. | 12348 -- Set common attributes for all subtypes: kind, convention, etc. |
12274 | 12349 |
12289 Set_Is_First_Subtype (Full, False); | 12364 Set_Is_First_Subtype (Full, False); |
12290 Set_Scope (Full, Scope (Priv)); | 12365 Set_Scope (Full, Scope (Priv)); |
12291 Set_Size_Info (Full, Full_Base); | 12366 Set_Size_Info (Full, Full_Base); |
12292 Set_RM_Size (Full, RM_Size (Full_Base)); | 12367 Set_RM_Size (Full, RM_Size (Full_Base)); |
12293 Set_Is_Itype (Full); | 12368 Set_Is_Itype (Full); |
12369 | |
12370 -- For the unusual case of a type with unknown discriminants whose | |
12371 -- completion is an array, use the proper full base. | |
12372 | |
12373 if Is_Array_Type (Full_Base) | |
12374 and then Has_Unknown_Discriminants (Priv) | |
12375 then | |
12376 Set_Etype (Full, Full_Base); | |
12377 end if; | |
12294 | 12378 |
12295 -- A subtype of a private-type-without-discriminants, whose full-view | 12379 -- A subtype of a private-type-without-discriminants, whose full-view |
12296 -- has discriminants with default expressions, is not constrained. | 12380 -- has discriminants with default expressions, is not constrained. |
12297 | 12381 |
12298 if not Has_Discriminants (Priv) then | 12382 if not Has_Discriminants (Priv) then |
13372 | 13456 |
13373 -- Itypes must be analyzed with checks off (see package Itypes) | 13457 -- Itypes must be analyzed with checks off (see package Itypes) |
13374 | 13458 |
13375 Analyze (Subtyp_Decl, Suppress => All_Checks); | 13459 Analyze (Subtyp_Decl, Suppress => All_Checks); |
13376 | 13460 |
13461 if Is_Itype (Def_Id) and then Has_Predicates (T) then | |
13462 Inherit_Predicate_Flags (Def_Id, T); | |
13463 | |
13464 -- Indicate where the predicate function may be found | |
13465 | |
13466 if Is_Itype (T) then | |
13467 if Present (Predicate_Function (Def_Id)) then | |
13468 null; | |
13469 | |
13470 elsif Present (Predicate_Function (T)) then | |
13471 Set_Predicate_Function (Def_Id, Predicate_Function (T)); | |
13472 | |
13473 else | |
13474 Set_Predicated_Parent (Def_Id, Predicated_Parent (T)); | |
13475 end if; | |
13476 | |
13477 elsif No (Predicate_Function (Def_Id)) then | |
13478 Set_Predicated_Parent (Def_Id, T); | |
13479 end if; | |
13480 end if; | |
13481 | |
13377 return Def_Id; | 13482 return Def_Id; |
13378 end Build_Subtype; | 13483 end Build_Subtype; |
13379 | 13484 |
13380 --------------------- | 13485 --------------------- |
13381 -- Get_Discr_Value -- | 13486 -- Get_Discr_Value -- |
13588 (Prot_Subt : Entity_Id; | 13693 (Prot_Subt : Entity_Id; |
13589 Corr_Rec : Entity_Id; | 13694 Corr_Rec : Entity_Id; |
13590 Related_Nod : Node_Id) return Entity_Id | 13695 Related_Nod : Node_Id) return Entity_Id |
13591 is | 13696 is |
13592 T_Sub : constant Entity_Id := | 13697 T_Sub : constant Entity_Id := |
13593 Create_Itype (E_Record_Subtype, Related_Nod, Corr_Rec, 'C'); | 13698 Create_Itype |
13699 (Ekind => E_Record_Subtype, | |
13700 Related_Nod => Related_Nod, | |
13701 Related_Id => Corr_Rec, | |
13702 Suffix => 'C', | |
13703 Suffix_Index => -1); | |
13594 | 13704 |
13595 begin | 13705 begin |
13596 Set_Etype (T_Sub, Corr_Rec); | 13706 Set_Etype (T_Sub, Corr_Rec); |
13597 Set_Has_Discriminants (T_Sub, Has_Discriminants (Prot_Subt)); | 13707 Set_Has_Discriminants (T_Sub, Has_Discriminants (Prot_Subt)); |
13598 Set_Is_Constrained (T_Sub, True); | 13708 Set_Is_Constrained (T_Sub, True); |
14334 end if; | 14444 end if; |
14335 | 14445 |
14336 Set_Is_Volatile (Full, Is_Volatile (Priv)); | 14446 Set_Is_Volatile (Full, Is_Volatile (Priv)); |
14337 Set_Treat_As_Volatile (Full, Treat_As_Volatile (Priv)); | 14447 Set_Treat_As_Volatile (Full, Treat_As_Volatile (Priv)); |
14338 Set_Scope (Full, Scope (Priv)); | 14448 Set_Scope (Full, Scope (Priv)); |
14449 Set_Prev_Entity (Full, Prev_Entity (Priv)); | |
14339 Set_Next_Entity (Full, Next_Entity (Priv)); | 14450 Set_Next_Entity (Full, Next_Entity (Priv)); |
14340 Set_First_Entity (Full, First_Entity (Priv)); | 14451 Set_First_Entity (Full, First_Entity (Priv)); |
14341 Set_Last_Entity (Full, Last_Entity (Priv)); | 14452 Set_Last_Entity (Full, Last_Entity (Priv)); |
14342 | 14453 |
14343 -- If access types have been recorded for later handling, keep them in | 14454 -- If access types have been recorded for later handling, keep them in |
14527 -- rate such recognition. | 14638 -- rate such recognition. |
14528 | 14639 |
14529 Set_Comes_From_Source (New_Compon, False); | 14640 Set_Comes_From_Source (New_Compon, False); |
14530 | 14641 |
14531 -- But it is a real entity, and a birth certificate must be properly | 14642 -- But it is a real entity, and a birth certificate must be properly |
14532 -- registered by entering it into the entity list. | 14643 -- registered by entering it into the entity list, and setting its |
14644 -- scope to the given subtype. This turns out to be useful for the | |
14645 -- LLVM code generator, but that scope is not used otherwise. | |
14533 | 14646 |
14534 Enter_Name (New_Compon); | 14647 Enter_Name (New_Compon); |
14648 Set_Scope (New_Compon, Subt); | |
14535 | 14649 |
14536 return New_Compon; | 14650 return New_Compon; |
14537 end Create_Component; | 14651 end Create_Component; |
14538 | 14652 |
14539 ----------------------- | 14653 ----------------------- |
14914 | 15028 |
14915 procedure Derive_Progenitor_Subprograms | 15029 procedure Derive_Progenitor_Subprograms |
14916 (Parent_Type : Entity_Id; | 15030 (Parent_Type : Entity_Id; |
14917 Tagged_Type : Entity_Id) | 15031 Tagged_Type : Entity_Id) |
14918 is | 15032 is |
14919 E : Entity_Id; | 15033 E : Entity_Id; |
14920 Elmt : Elmt_Id; | 15034 Elmt : Elmt_Id; |
14921 Iface : Entity_Id; | 15035 Iface : Entity_Id; |
14922 Iface_Elmt : Elmt_Id; | 15036 Iface_Alias : Entity_Id; |
14923 Iface_Subp : Entity_Id; | 15037 Iface_Elmt : Elmt_Id; |
14924 New_Subp : Entity_Id := Empty; | 15038 Iface_Subp : Entity_Id; |
14925 Prim_Elmt : Elmt_Id; | 15039 New_Subp : Entity_Id := Empty; |
14926 Subp : Entity_Id; | 15040 Prim_Elmt : Elmt_Id; |
14927 Typ : Entity_Id; | 15041 Subp : Entity_Id; |
15042 Typ : Entity_Id; | |
14928 | 15043 |
14929 begin | 15044 begin |
14930 pragma Assert (Ada_Version >= Ada_2005 | 15045 pragma Assert (Ada_Version >= Ada_2005 |
14931 and then Is_Record_Type (Tagged_Type) | 15046 and then Is_Record_Type (Tagged_Type) |
14932 and then Is_Tagged_Type (Tagged_Type) | 15047 and then Is_Tagged_Type (Tagged_Type) |
14993 while Present (Iface_Elmt) loop | 15108 while Present (Iface_Elmt) loop |
14994 Iface := Node (Iface_Elmt); | 15109 Iface := Node (Iface_Elmt); |
14995 | 15110 |
14996 Prim_Elmt := First_Elmt (Primitive_Operations (Iface)); | 15111 Prim_Elmt := First_Elmt (Primitive_Operations (Iface)); |
14997 while Present (Prim_Elmt) loop | 15112 while Present (Prim_Elmt) loop |
14998 Iface_Subp := Node (Prim_Elmt); | 15113 Iface_Subp := Node (Prim_Elmt); |
15114 Iface_Alias := Ultimate_Alias (Iface_Subp); | |
14999 | 15115 |
15000 -- Exclude derivation of predefined primitives except those | 15116 -- Exclude derivation of predefined primitives except those |
15001 -- that come from source, or are inherited from one that comes | 15117 -- that come from source, or are inherited from one that comes |
15002 -- from source. Required to catch declarations of equality | 15118 -- from source. Required to catch declarations of equality |
15003 -- operators of interfaces. For example: | 15119 -- operators of interfaces. For example: |
15004 | 15120 |
15005 -- type Iface is interface; | 15121 -- type Iface is interface; |
15006 -- function "=" (Left, Right : Iface) return Boolean; | 15122 -- function "=" (Left, Right : Iface) return Boolean; |
15007 | 15123 |
15008 if not Is_Predefined_Dispatching_Operation (Iface_Subp) | 15124 if not Is_Predefined_Dispatching_Operation (Iface_Subp) |
15009 or else Comes_From_Source (Ultimate_Alias (Iface_Subp)) | 15125 or else Comes_From_Source (Iface_Alias) |
15010 then | 15126 then |
15011 E := Find_Primitive_Covering_Interface | 15127 E := |
15012 (Tagged_Type => Tagged_Type, | 15128 Find_Primitive_Covering_Interface |
15013 Iface_Prim => Iface_Subp); | 15129 (Tagged_Type => Tagged_Type, |
15130 Iface_Prim => Iface_Subp); | |
15014 | 15131 |
15015 -- If not found we derive a new primitive leaving its alias | 15132 -- If not found we derive a new primitive leaving its alias |
15016 -- attribute referencing the interface primitive. | 15133 -- attribute referencing the interface primitive. |
15017 | 15134 |
15018 if No (E) then | 15135 if No (E) then |
16633 and then not Error_Posted (N) | 16750 and then not Error_Posted (N) |
16634 then | 16751 then |
16635 Error_Msg_N | 16752 Error_Msg_N |
16636 ("elementary or array type cannot have discriminants", | 16753 ("elementary or array type cannot have discriminants", |
16637 Defining_Identifier (First (Discriminant_Specifications (N)))); | 16754 Defining_Identifier (First (Discriminant_Specifications (N)))); |
16638 Set_Has_Discriminants (T, False); | 16755 |
16756 -- Unset Has_Discriminants flag to prevent cascaded errors, but | |
16757 -- only if we are not already processing a malformed syntax tree. | |
16758 | |
16759 if Is_Type (T) then | |
16760 Set_Has_Discriminants (T, False); | |
16761 end if; | |
16639 | 16762 |
16640 -- The type is allowed to have discriminants | 16763 -- The type is allowed to have discriminants |
16641 | 16764 |
16642 else | 16765 else |
16643 Check_SPARK_05_Restriction ("discriminant type is not allowed", N); | 16766 Check_SPARK_05_Restriction ("discriminant type is not allowed", N); |
17938 and then Present (Stored_Constraint (Ti)) | 18061 and then Present (Stored_Constraint (Ti)) |
17939 and then not Is_Tagged_Type (Ti) | 18062 and then not Is_Tagged_Type (Ti) |
17940 then | 18063 then |
17941 Result := | 18064 Result := |
17942 Search_Derivation_Levels (Ti, Stored_Constraint (Ti), True); | 18065 Search_Derivation_Levels (Ti, Stored_Constraint (Ti), True); |
18066 | |
17943 else | 18067 else |
17944 declare | 18068 declare |
17945 Td : constant Entity_Id := Etype (Ti); | 18069 Td : Entity_Id := Etype (Ti); |
17946 | 18070 |
17947 begin | 18071 begin |
18072 -- If the parent type is private, the full view may include | |
18073 -- renamed discriminants, and it is those stored values that | |
18074 -- may be needed (the partial view never has more information | |
18075 -- than the full view). | |
18076 | |
18077 if Is_Private_Type (Td) and then Present (Full_View (Td)) then | |
18078 Td := Full_View (Td); | |
18079 end if; | |
18080 | |
17948 if Td = Ti then | 18081 if Td = Ti then |
17949 Result := Discriminant; | 18082 Result := Discriminant; |
17950 | 18083 |
17951 else | 18084 else |
17952 if Present (Stored_Constraint (Ti)) then | 18085 if Present (Stored_Constraint (Ti)) then |
18479 -- Inherit_Predicate_Flags -- | 18612 -- Inherit_Predicate_Flags -- |
18480 ----------------------------- | 18613 ----------------------------- |
18481 | 18614 |
18482 procedure Inherit_Predicate_Flags (Subt, Par : Entity_Id) is | 18615 procedure Inherit_Predicate_Flags (Subt, Par : Entity_Id) is |
18483 begin | 18616 begin |
18617 if Present (Predicate_Function (Subt)) then | |
18618 return; | |
18619 end if; | |
18620 | |
18484 Set_Has_Predicates (Subt, Has_Predicates (Par)); | 18621 Set_Has_Predicates (Subt, Has_Predicates (Par)); |
18485 Set_Has_Static_Predicate_Aspect | 18622 Set_Has_Static_Predicate_Aspect |
18486 (Subt, Has_Static_Predicate_Aspect (Par)); | 18623 (Subt, Has_Static_Predicate_Aspect (Par)); |
18487 Set_Has_Dynamic_Predicate_Aspect | 18624 Set_Has_Dynamic_Predicate_Aspect |
18488 (Subt, Has_Dynamic_Predicate_Aspect (Par)); | 18625 (Subt, Has_Dynamic_Predicate_Aspect (Par)); |
18489 | 18626 |
18490 -- A named subtype does not inherit the predicate function of its | 18627 -- A named subtype does not inherit the predicate function of its |
18491 -- parent but an itype declared for a loop index needs the discrete | 18628 -- parent but an itype declared for a loop index needs the discrete |
18492 -- predicate information of its parent to execute the loop properly. | 18629 -- predicate information of its parent to execute the loop properly. |
18630 -- A non-discrete type may has a static predicate (for example True) | |
18631 -- but has no static_discrete_predicate. | |
18493 | 18632 |
18494 if Is_Itype (Subt) and then Present (Predicate_Function (Par)) then | 18633 if Is_Itype (Subt) and then Present (Predicate_Function (Par)) then |
18495 Set_Subprograms_For_Type (Subt, Subprograms_For_Type (Par)); | 18634 Set_Subprograms_For_Type (Subt, Subprograms_For_Type (Par)); |
18496 | 18635 |
18497 if Has_Static_Predicate (Par) then | 18636 if Has_Static_Predicate (Par) and then Is_Discrete_Type (Par) then |
18498 Set_Static_Discrete_Predicate | 18637 Set_Static_Discrete_Predicate |
18499 (Subt, Static_Discrete_Predicate (Par)); | 18638 (Subt, Static_Discrete_Predicate (Par)); |
18500 end if; | 18639 end if; |
18501 end if; | 18640 end if; |
18502 end Inherit_Predicate_Flags; | 18641 end Inherit_Predicate_Flags; |
18681 end if; | 18820 end if; |
18682 | 18821 |
18683 -- This test only concerns tagged types | 18822 -- This test only concerns tagged types |
18684 | 18823 |
18685 if not Is_Tagged_Type (Original_Type) then | 18824 if not Is_Tagged_Type (Original_Type) then |
18686 return True; | 18825 |
18826 -- Check if this is a renamed discriminant (hidden either by the | |
18827 -- derived type or by some ancestor), unless we are analyzing code | |
18828 -- generated by the expander since it may reference such components | |
18829 -- (for example see the expansion of Deep_Adjust). | |
18830 | |
18831 if Ekind (C) = E_Discriminant and then Present (N) then | |
18832 return | |
18833 not Comes_From_Source (N) | |
18834 or else not Is_Completely_Hidden (C); | |
18835 else | |
18836 return True; | |
18837 end if; | |
18687 | 18838 |
18688 -- If it is _Parent or _Tag, there is no visibility issue | 18839 -- If it is _Parent or _Tag, there is no visibility issue |
18689 | 18840 |
18690 elsif not Comes_From_Source (Original_Comp) then | 18841 elsif not Comes_From_Source (Original_Comp) then |
18691 return True; | 18842 return True; |
18829 | 18980 |
18830 procedure Make_Class_Wide_Type (T : Entity_Id) is | 18981 procedure Make_Class_Wide_Type (T : Entity_Id) is |
18831 CW_Type : Entity_Id; | 18982 CW_Type : Entity_Id; |
18832 CW_Name : Name_Id; | 18983 CW_Name : Name_Id; |
18833 Next_E : Entity_Id; | 18984 Next_E : Entity_Id; |
18985 Prev_E : Entity_Id; | |
18834 | 18986 |
18835 begin | 18987 begin |
18836 if Present (Class_Wide_Type (T)) then | 18988 if Present (Class_Wide_Type (T)) then |
18837 | 18989 |
18838 -- The class-wide type is a partially decorated entity created for a | 18990 -- The class-wide type is a partially decorated entity created for a |
18861 | 19013 |
18862 -- Inherit root type characteristics | 19014 -- Inherit root type characteristics |
18863 | 19015 |
18864 CW_Name := Chars (CW_Type); | 19016 CW_Name := Chars (CW_Type); |
18865 Next_E := Next_Entity (CW_Type); | 19017 Next_E := Next_Entity (CW_Type); |
19018 Prev_E := Prev_Entity (CW_Type); | |
18866 Copy_Node (T, CW_Type); | 19019 Copy_Node (T, CW_Type); |
18867 Set_Comes_From_Source (CW_Type, False); | 19020 Set_Comes_From_Source (CW_Type, False); |
18868 Set_Chars (CW_Type, CW_Name); | 19021 Set_Chars (CW_Type, CW_Name); |
18869 Set_Parent (CW_Type, Parent (T)); | 19022 Set_Parent (CW_Type, Parent (T)); |
19023 Set_Prev_Entity (CW_Type, Prev_E); | |
18870 Set_Next_Entity (CW_Type, Next_E); | 19024 Set_Next_Entity (CW_Type, Next_E); |
18871 | 19025 |
18872 -- Ensure we have a new freeze node for the class-wide type. The partial | 19026 -- Ensure we have a new freeze node for the class-wide type. The partial |
18873 -- view may have freeze action of its own, requiring a proper freeze | 19027 -- view may have freeze action of its own, requiring a proper freeze |
18874 -- node, and the same freeze node cannot be shared between the two | 19028 -- node, and the same freeze node cannot be shared between the two |
19674 ----------------------------------- | 19828 ----------------------------------- |
19675 -- Preanalyze_Default_Expression -- | 19829 -- Preanalyze_Default_Expression -- |
19676 ----------------------------------- | 19830 ----------------------------------- |
19677 | 19831 |
19678 procedure Preanalyze_Default_Expression (N : Node_Id; T : Entity_Id) is | 19832 procedure Preanalyze_Default_Expression (N : Node_Id; T : Entity_Id) is |
19679 Save_In_Default_Expr : constant Boolean := In_Default_Expr; | 19833 Save_In_Default_Expr : constant Boolean := In_Default_Expr; |
19834 Save_In_Spec_Expression : constant Boolean := In_Spec_Expression; | |
19835 | |
19680 begin | 19836 begin |
19681 In_Default_Expr := True; | 19837 In_Default_Expr := True; |
19682 Preanalyze_Spec_Expression (N, T); | 19838 In_Spec_Expression := True; |
19683 In_Default_Expr := Save_In_Default_Expr; | 19839 |
19840 Preanalyze_With_Freezing_And_Resolve (N, T); | |
19841 | |
19842 In_Default_Expr := Save_In_Default_Expr; | |
19843 In_Spec_Expression := Save_In_Spec_Expression; | |
19684 end Preanalyze_Default_Expression; | 19844 end Preanalyze_Default_Expression; |
19685 | 19845 |
19686 -------------------------------- | 19846 -------------------------------- |
19687 -- Preanalyze_Spec_Expression -- | 19847 -- Preanalyze_Spec_Expression -- |
19688 -------------------------------- | 19848 -------------------------------- |
19983 & "cannot have defaults", Expression (Discr)); | 20143 & "cannot have defaults", Expression (Discr)); |
19984 end if; | 20144 end if; |
19985 end if; | 20145 end if; |
19986 end if; | 20146 end if; |
19987 | 20147 |
19988 -- A discriminant cannot be effectively volatile (SPARK RM 7.1.3(6)). | 20148 -- A discriminant cannot be effectively volatile (SPARK RM 7.1.3(4)). |
19989 -- This check is relevant only when SPARK_Mode is on as it is not a | 20149 -- This check is relevant only when SPARK_Mode is on as it is not a |
19990 -- standard Ada legality rule. | 20150 -- standard Ada legality rule. |
19991 | 20151 |
19992 if SPARK_Mode = On | 20152 if SPARK_Mode = On |
19993 and then Is_Effectively_Volatile (Defining_Identifier (Discr)) | 20153 and then Is_Effectively_Volatile (Defining_Identifier (Discr)) |
20156 end if; | 20316 end if; |
20157 end Collect_Implemented_Interfaces; | 20317 end Collect_Implemented_Interfaces; |
20158 | 20318 |
20159 -- Local variables | 20319 -- Local variables |
20160 | 20320 |
20161 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; | 20321 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
20322 Saved_IGR : constant Node_Id := Ignored_Ghost_Region; | |
20323 -- Save the Ghost-related attributes to restore on exit | |
20162 | 20324 |
20163 Full_Indic : Node_Id; | 20325 Full_Indic : Node_Id; |
20164 Full_Parent : Entity_Id; | 20326 Full_Parent : Entity_Id; |
20165 Priv_Parent : Entity_Id; | 20327 Priv_Parent : Entity_Id; |
20166 | 20328 |
20640 -- omit those inherited from the parent of the private view | 20802 -- omit those inherited from the parent of the private view |
20641 -- since they will be re-inherited later on. | 20803 -- since they will be re-inherited later on. |
20642 | 20804 |
20643 else | 20805 else |
20644 Full_List := Primitive_Operations (Full_T); | 20806 Full_List := Primitive_Operations (Full_T); |
20645 | |
20646 while Present (Prim_Elmt) loop | 20807 while Present (Prim_Elmt) loop |
20647 Prim := Node (Prim_Elmt); | 20808 Prim := Node (Prim_Elmt); |
20648 | 20809 |
20649 if Comes_From_Source (Prim) | 20810 if Comes_From_Source (Prim) |
20650 and then not Contains (Prim, Full_List) | 20811 and then not Contains (Prim, Full_List) |
20682 and then (Chars (Prim) /= Name_Op_Ne | 20843 and then (Chars (Prim) /= Name_Op_Ne |
20683 or else Comes_From_Source (Prim)) | 20844 or else Comes_From_Source (Prim)) |
20684 then | 20845 then |
20685 Check_Controlling_Formals (Full_T, Prim); | 20846 Check_Controlling_Formals (Full_T, Prim); |
20686 | 20847 |
20687 if not Is_Dispatching_Operation (Prim) then | 20848 if Is_Suitable_Primitive (Prim) |
20849 and then not Is_Dispatching_Operation (Prim) | |
20850 then | |
20688 Append_Elmt (Prim, Full_List); | 20851 Append_Elmt (Prim, Full_List); |
20689 Set_Is_Dispatching_Operation (Prim, True); | 20852 Set_Is_Dispatching_Operation (Prim); |
20690 Set_DT_Position_Value (Prim, No_Uint); | 20853 Set_DT_Position_Value (Prim, No_Uint); |
20691 end if; | 20854 end if; |
20692 | 20855 |
20693 elsif Is_Dispatching_Operation (Prim) | 20856 elsif Is_Dispatching_Operation (Prim) |
20694 and then Disp_Typ /= Full_T | 20857 and then Disp_Typ /= Full_T |
20695 then | 20858 then |
20696 | |
20697 -- Verify that it is not otherwise controlled by a | 20859 -- Verify that it is not otherwise controlled by a |
20698 -- formal or a return value of type T. | 20860 -- formal or a return value of type T. |
20699 | 20861 |
20700 Check_Controlling_Formals (Disp_Typ, Prim); | 20862 Check_Controlling_Formals (Disp_Typ, Prim); |
20701 end if; | 20863 end if; |
20818 Set_Predicate_Function (Full_T, Predicate_Function (Priv_T)); | 20980 Set_Predicate_Function (Full_T, Predicate_Function (Priv_T)); |
20819 end if; | 20981 end if; |
20820 end if; | 20982 end if; |
20821 | 20983 |
20822 <<Leave>> | 20984 <<Leave>> |
20823 Restore_Ghost_Mode (Saved_GM); | 20985 Restore_Ghost_Region (Saved_GM, Saved_IGR); |
20824 end Process_Full_View; | 20986 end Process_Full_View; |
20825 | 20987 |
20826 ----------------------------------- | 20988 ----------------------------------- |
20827 -- Process_Incomplete_Dependents -- | 20989 -- Process_Incomplete_Dependents -- |
20828 ----------------------------------- | 20990 ----------------------------------- |
21311 begin | 21473 begin |
21312 -- Case of no constraints present | 21474 -- Case of no constraints present |
21313 | 21475 |
21314 if Nkind (S) /= N_Subtype_Indication then | 21476 if Nkind (S) /= N_Subtype_Indication then |
21315 Find_Type (S); | 21477 Find_Type (S); |
21478 | |
21479 -- No way to proceed if the subtype indication is malformed. This | |
21480 -- will happen for example when the subtype indication in an object | |
21481 -- declaration is missing altogether and the expression is analyzed | |
21482 -- as if it were that indication. | |
21483 | |
21484 if not Is_Entity_Name (S) then | |
21485 return Any_Type; | |
21486 end if; | |
21487 | |
21316 Check_Incomplete (S); | 21488 Check_Incomplete (S); |
21317 P := Parent (S); | 21489 P := Parent (S); |
21318 | 21490 |
21319 -- Ada 2005 (AI-231): Static check | 21491 -- Ada 2005 (AI-231): Static check |
21320 | 21492 |
21525 when Decimal_Fixed_Point_Kind => | 21697 when Decimal_Fixed_Point_Kind => |
21526 Constrain_Decimal (Def_Id, S); | 21698 Constrain_Decimal (Def_Id, S); |
21527 | 21699 |
21528 when Enumeration_Kind => | 21700 when Enumeration_Kind => |
21529 Constrain_Enumeration (Def_Id, S); | 21701 Constrain_Enumeration (Def_Id, S); |
21530 Inherit_Predicate_Flags (Def_Id, Subtype_Mark_Id); | |
21531 | 21702 |
21532 when Ordinary_Fixed_Point_Kind => | 21703 when Ordinary_Fixed_Point_Kind => |
21533 Constrain_Ordinary_Fixed (Def_Id, S); | 21704 Constrain_Ordinary_Fixed (Def_Id, S); |
21534 | 21705 |
21535 when Float_Kind => | 21706 when Float_Kind => |
21536 Constrain_Float (Def_Id, S); | 21707 Constrain_Float (Def_Id, S); |
21537 | 21708 |
21538 when Integer_Kind => | 21709 when Integer_Kind => |
21539 Constrain_Integer (Def_Id, S); | 21710 Constrain_Integer (Def_Id, S); |
21540 Inherit_Predicate_Flags (Def_Id, Subtype_Mark_Id); | |
21541 | 21711 |
21542 when Class_Wide_Kind | 21712 when Class_Wide_Kind |
21543 | E_Incomplete_Type | 21713 | E_Incomplete_Type |
21544 | E_Record_Subtype | 21714 | E_Record_Subtype |
21545 | E_Record_Type | 21715 | E_Record_Type |
21549 if Ekind (Def_Id) = E_Incomplete_Type then | 21719 if Ekind (Def_Id) = E_Incomplete_Type then |
21550 Set_Private_Dependents (Def_Id, New_Elmt_List); | 21720 Set_Private_Dependents (Def_Id, New_Elmt_List); |
21551 end if; | 21721 end if; |
21552 | 21722 |
21553 when Private_Kind => | 21723 when Private_Kind => |
21554 Constrain_Discriminated_Type (Def_Id, S, Related_Nod); | 21724 |
21725 -- A private type with unknown discriminants may be completed | |
21726 -- by an unconstrained array type. | |
21727 | |
21728 if Has_Unknown_Discriminants (Subtype_Mark_Id) | |
21729 and then Present (Full_View (Subtype_Mark_Id)) | |
21730 and then Is_Array_Type (Full_View (Subtype_Mark_Id)) | |
21731 then | |
21732 Constrain_Array (Def_Id, S, Related_Nod, Related_Id, Suffix); | |
21733 | |
21734 -- ... but more commonly is completed by a discriminated record | |
21735 -- type. | |
21736 | |
21737 else | |
21738 Constrain_Discriminated_Type (Def_Id, S, Related_Nod); | |
21739 end if; | |
21555 | 21740 |
21556 -- The base type may be private but Def_Id may be a full view | 21741 -- The base type may be private but Def_Id may be a full view |
21557 -- in an instance. | 21742 -- in an instance. |
21558 | 21743 |
21559 if Is_Private_Type (Def_Id) then | 21744 if Is_Private_Type (Def_Id) then |
21614 -- inherited from the base type. | 21799 -- inherited from the base type. |
21615 | 21800 |
21616 Set_Size_Info (Def_Id, (Subtype_Mark_Id)); | 21801 Set_Size_Info (Def_Id, (Subtype_Mark_Id)); |
21617 Set_Rep_Info (Def_Id, (Subtype_Mark_Id)); | 21802 Set_Rep_Info (Def_Id, (Subtype_Mark_Id)); |
21618 Set_Convention (Def_Id, Convention (Subtype_Mark_Id)); | 21803 Set_Convention (Def_Id, Convention (Subtype_Mark_Id)); |
21804 | |
21805 -- The anonymous subtype created for the subtype indication | |
21806 -- inherits the predicates of the parent. | |
21807 | |
21808 if Has_Predicates (Subtype_Mark_Id) then | |
21809 Inherit_Predicate_Flags (Def_Id, Subtype_Mark_Id); | |
21810 | |
21811 -- Indicate where the predicate function may be found | |
21812 | |
21813 if No (Predicate_Function (Def_Id)) and then Is_Itype (Def_Id) then | |
21814 Set_Predicated_Parent (Def_Id, Subtype_Mark_Id); | |
21815 end if; | |
21816 end if; | |
21619 | 21817 |
21620 return Def_Id; | 21818 return Def_Id; |
21621 end if; | 21819 end if; |
21622 end Process_Subtype; | 21820 end Process_Subtype; |
21623 | 21821 |