comparison gcc/ada/sem_ch4.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 _ C H 4 -- 5 -- S E M _ C H 4 --
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- --
169 -- from object notation. In this case the first actual may have to receive 169 -- from object notation. In this case the first actual may have to receive
170 -- an explicit dereference, depending on the first formal of the operation 170 -- an explicit dereference, depending on the first formal of the operation
171 -- being called. The caller will have verified that the object is legal 171 -- being called. The caller will have verified that the object is legal
172 -- for the call. If the remaining parameters match, the first parameter 172 -- for the call. If the remaining parameters match, the first parameter
173 -- will rewritten as a dereference if needed, prior to completing analysis. 173 -- will rewritten as a dereference if needed, prior to completing analysis.
174
175 procedure Check_Misspelled_Selector 174 procedure Check_Misspelled_Selector
176 (Prefix : Entity_Id; 175 (Prefix : Entity_Id;
177 Sel : Node_Id); 176 Sel : Node_Id);
178 -- Give possible misspelling message if Sel seems likely to be a mis- 177 -- Give possible misspelling message if Sel seems likely to be a mis-
179 -- spelling of one of the selectors of the Prefix. This is called by 178 -- spelling of one of the selectors of the Prefix. This is called by
673 Rewrite (E, New_Copy_Tree (Subtype_Mark (E))); 672 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
674 Analyze_Allocator (N); 673 Analyze_Allocator (N);
675 return; 674 return;
676 end if; 675 end if;
677 676
678 if Expander_Active then 677 -- In GNATprove mode we need to preserve the link between
678 -- the original subtype indication and the anonymous subtype,
679 -- to extend proofs to constrained access types. We only do
680 -- that outside of spec expressions, otherwise the declaration
681 -- cannot be inserted and analyzed. In such a case, GNATprove
682 -- later rejects the allocator as it is not used here in
683 -- a non-interfering context (SPARK 4.8(2) and 7.1.3(12)).
684
685 if Expander_Active
686 or else (GNATprove_Mode and then not In_Spec_Expression)
687 then
679 Def_Id := Make_Temporary (Loc, 'S'); 688 Def_Id := Make_Temporary (Loc, 'S');
680 689
681 Insert_Action (E, 690 Insert_Action (E,
682 Make_Subtype_Declaration (Loc, 691 Make_Subtype_Declaration (Loc,
683 Defining_Identifier => Def_Id, 692 Defining_Identifier => Def_Id,
785 else pragma Assert (Has_Discriminants (Type_Id)); 794 else pragma Assert (Has_Discriminants (Type_Id));
786 Error_Msg_N 795 Error_Msg_N
787 ("\constraint with discriminant values required", N); 796 ("\constraint with discriminant values required", N);
788 end if; 797 end if;
789 798
790 -- Limited Ada 2005 and general nonlimited case 799 -- Limited Ada 2005 and general nonlimited case.
800 -- This is an error, except in the case of an
801 -- uninitialized allocator that is generated
802 -- for a build-in-place function return of a
803 -- discriminated but compile-time-known-size
804 -- type.
791 805
792 else 806 else
793 Error_Msg_N 807 if Original_Node (N) /= N
794 ("uninitialized unconstrained allocation not " 808 and then Nkind (Original_Node (N)) = N_Allocator
795 & "allowed", N); 809 then
796 810 declare
797 if Is_Array_Type (Type_Id) then 811 Qual : constant Node_Id :=
812 Expression (Original_Node (N));
813 pragma Assert
814 (Nkind (Qual) = N_Qualified_Expression);
815 Call : constant Node_Id := Expression (Qual);
816 pragma Assert
817 (Is_Expanded_Build_In_Place_Call (Call));
818 begin
819 null;
820 end;
821
822 else
798 Error_Msg_N 823 Error_Msg_N
799 ("\qualified expression or constraint with " 824 ("uninitialized unconstrained allocation not "
800 & "array bounds required", N); 825 & "allowed", N);
801 826
802 elsif Has_Unknown_Discriminants (Type_Id) then 827 if Is_Array_Type (Type_Id) then
803 Error_Msg_N ("\qualified expression required", N); 828 Error_Msg_N
804 829 ("\qualified expression or constraint with "
805 else pragma Assert (Has_Discriminants (Type_Id)); 830 & "array bounds required", N);
806 Error_Msg_N 831
807 ("\qualified expression or constraint with " 832 elsif Has_Unknown_Discriminants (Type_Id) then
808 & "discriminant values required", N); 833 Error_Msg_N ("\qualified expression required", N);
834
835 else pragma Assert (Has_Discriminants (Type_Id));
836 Error_Msg_N
837 ("\qualified expression or constraint with "
838 & "discriminant values required", N);
839 end if;
809 end if; 840 end if;
810 end if; 841 end if;
811 end if; 842 end if;
812 end if; 843 end if;
813 end; 844 end;
1522 1553
1523 -- If there is no completion for the type, this may be because 1554 -- If there is no completion for the type, this may be because
1524 -- there is only a limited view of it and there is nothing in 1555 -- there is only a limited view of it and there is nothing in
1525 -- the context of the current unit that has required a regular 1556 -- the context of the current unit that has required a regular
1526 -- compilation of the unit containing the type. We recognize 1557 -- compilation of the unit containing the type. We recognize
1527 -- this unusual case by the fact that that unit is not analyzed. 1558 -- this unusual case by the fact that unit is not analyzed.
1528 -- Note that the call being analyzed is in a different unit from 1559 -- Note that the call being analyzed is in a different unit from
1529 -- the function declaration, and nothing indicates that the type 1560 -- the function declaration, and nothing indicates that the type
1530 -- is a limited view. 1561 -- is a limited view.
1531 1562
1532 elsif Ekind (Scope (Etype (N))) = E_Package 1563 elsif Ekind (Scope (Etype (N))) = E_Package
1694 return; 1725 return;
1695 end if; 1726 end if;
1696 1727
1697 -- If the case expression is a formal object of mode in out, then 1728 -- If the case expression is a formal object of mode in out, then
1698 -- treat it as having a nonstatic subtype by forcing use of the base 1729 -- treat it as having a nonstatic subtype by forcing use of the base
1699 -- type (which has to get passed to Check_Case_Choices below). Also 1730 -- type (which has to get passed to Check_Case_Choices below). Also
1700 -- use base type when the case expression is parenthesized. 1731 -- use base type when the case expression is parenthesized.
1701 1732
1702 if Paren_Count (Expr) > 0 1733 if Paren_Count (Expr) > 0
1703 or else (Is_Entity_Name (Expr) 1734 or else (Is_Entity_Name (Expr)
1704 and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter) 1735 and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter)
1903 else 1934 else
1904 Op_Id := Get_Name_Entity_Id (Name_Op_Concat); 1935 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1905 while Present (Op_Id) loop 1936 while Present (Op_Id) loop
1906 if Ekind (Op_Id) = E_Operator then 1937 if Ekind (Op_Id) = E_Operator then
1907 1938
1908 -- Do not consider operators declared in dead code, they can 1939 -- Do not consider operators declared in dead code, they
1909 -- not be part of the resolution. 1940 -- cannot be part of the resolution.
1910 1941
1911 if Is_Eliminated (Op_Id) then 1942 if Is_Eliminated (Op_Id) then
1912 null; 1943 null;
1913 else 1944 else
1914 Find_Concatenation_Types (L, R, Op_Id, N); 1945 Find_Concatenation_Types (L, R, Op_Id, N);
2096 -- Normal processing for other than remote access to subprogram type 2127 -- Normal processing for other than remote access to subprogram type
2097 2128
2098 if not Is_Overloaded (P) then 2129 if not Is_Overloaded (P) then
2099 if Is_Access_Type (Etype (P)) then 2130 if Is_Access_Type (Etype (P)) then
2100 2131
2101 -- Set the Etype. We need to go through Is_For_Access_Subtypes to 2132 -- Set the Etype
2102 -- avoid other problems caused by the Private_Subtype and it is
2103 -- safe to go to the Base_Type because this is the same as
2104 -- converting the access value to its Base_Type.
2105 2133
2106 declare 2134 declare
2107 DT : Entity_Id := Designated_Type (Etype (P)); 2135 DT : constant Entity_Id := Designated_Type (Etype (P));
2108 2136
2109 begin 2137 begin
2110 if Ekind (DT) = E_Private_Subtype
2111 and then Is_For_Access_Subtype (DT)
2112 then
2113 DT := Base_Type (DT);
2114 end if;
2115
2116 -- An explicit dereference is a legal occurrence of an 2138 -- An explicit dereference is a legal occurrence of an
2117 -- incomplete type imported through a limited_with clause, if 2139 -- incomplete type imported through a limited_with clause, if
2118 -- the full view is visible, or if we are within an instance 2140 -- the full view is visible, or if we are within an instance
2119 -- body, where the enclosing body has a regular with_clause 2141 -- body, where the enclosing body has a regular with_clause
2120 -- on the unit. 2142 -- on the unit.
3225 -- a primitive operation that is a possible interpretation, and also 3247 -- a primitive operation that is a possible interpretation, and also
3226 -- after the call has been rewritten, because the corresponding actual 3248 -- after the call has been rewritten, because the corresponding actual
3227 -- is already known to be compatible, and because this may be an 3249 -- is already known to be compatible, and because this may be an
3228 -- indexing of a call with default parameters. 3250 -- indexing of a call with default parameters.
3229 3251
3252 First_Form : Entity_Id;
3230 Formal : Entity_Id; 3253 Formal : Entity_Id;
3231 Actual : Node_Id; 3254 Actual : Node_Id;
3232 Is_Indexed : Boolean := False; 3255 Is_Indexed : Boolean := False;
3233 Is_Indirect : Boolean := False; 3256 Is_Indirect : Boolean := False;
3234 Subp_Type : constant Entity_Id := Etype (Nam); 3257 Subp_Type : constant Entity_Id := Etype (Nam);
3557 3580
3558 else 3581 else
3559 -- Normalize_Actuals has chained the named associations in the 3582 -- Normalize_Actuals has chained the named associations in the
3560 -- correct order of the formals. 3583 -- correct order of the formals.
3561 3584
3562 Actual := First_Actual (N); 3585 Actual := First_Actual (N);
3563 Formal := First_Formal (Nam); 3586 Formal := First_Formal (Nam);
3587 First_Form := Formal;
3564 3588
3565 -- If we are analyzing a call rewritten from object notation, skip 3589 -- If we are analyzing a call rewritten from object notation, skip
3566 -- first actual, which may be rewritten later as an explicit 3590 -- first actual, which may be rewritten later as an explicit
3567 -- dereference. 3591 -- dereference.
3568 3592
3620 Next_Formal (Formal); 3644 Next_Formal (Formal);
3621 3645
3622 elsif Compatible_Types_In_Predicate 3646 elsif Compatible_Types_In_Predicate
3623 (Etype (Formal), Etype (Actual)) 3647 (Etype (Formal), Etype (Actual))
3624 then 3648 then
3625 Next_Actual (Actual);
3626 Next_Formal (Formal);
3627
3628 -- In a complex case where an enclosing generic and a nested
3629 -- generic package, both declared with partially parameterized
3630 -- formal subprograms with the same names, are instantiated
3631 -- with the same type, the types of the actual parameter and
3632 -- that of the formal may appear incompatible at first sight.
3633
3634 -- generic
3635 -- type Outer_T is private;
3636 -- with function Func (Formal : Outer_T)
3637 -- return ... is <>;
3638
3639 -- package Outer_Gen is
3640 -- generic
3641 -- type Inner_T is private;
3642 -- with function Func (Formal : Inner_T) -- (1)
3643 -- return ... is <>;
3644
3645 -- package Inner_Gen is
3646 -- function Inner_Func (Formal : Inner_T) -- (2)
3647 -- return ... is (Func (Formal));
3648 -- end Inner_Gen;
3649 -- end Outer_Generic;
3650
3651 -- package Outer_Inst is new Outer_Gen (Actual_T);
3652 -- package Inner_Inst is new Outer_Inst.Inner_Gen (Actual_T);
3653
3654 -- In the example above, the type of parameter
3655 -- Inner_Func.Formal at (2) is incompatible with the type of
3656 -- Func.Formal at (1) in the context of instantiations
3657 -- Outer_Inst and Inner_Inst. In reality both types are generic
3658 -- actual subtypes renaming base type Actual_T as part of the
3659 -- generic prologues for the instantiations.
3660
3661 -- Recognize this case and add a type conversion to allow this
3662 -- kind of generic actual subtype conformance. Note that this
3663 -- is done only when the call is non-overloaded because the
3664 -- resolution mechanism already has the means to disambiguate
3665 -- similar cases.
3666
3667 elsif not Is_Overloaded (Name (N))
3668 and then Is_Type (Etype (Actual))
3669 and then Is_Type (Etype (Formal))
3670 and then Is_Generic_Actual_Type (Etype (Actual))
3671 and then Is_Generic_Actual_Type (Etype (Formal))
3672 and then Base_Type (Etype (Actual)) =
3673 Base_Type (Etype (Formal))
3674 then
3675 Rewrite (Actual,
3676 Convert_To (Etype (Formal), Relocate_Node (Actual)));
3677 Analyze_And_Resolve (Actual, Etype (Formal));
3678 Next_Actual (Actual); 3649 Next_Actual (Actual);
3679 Next_Formal (Formal); 3650 Next_Formal (Formal);
3680 3651
3681 -- Handle failed type check 3652 -- Handle failed type check
3682 3653
3770 -- for this formal. Current actual names a subsequent formal. 3741 -- for this formal. Current actual names a subsequent formal.
3771 3742
3772 Next_Formal (Formal); 3743 Next_Formal (Formal);
3773 end if; 3744 end if;
3774 end loop; 3745 end loop;
3746
3747 -- Due to our current model of controlled type expansion we may
3748 -- have resolved a user call to a non-visible controlled primitive
3749 -- since these inherited subprograms may be generated in the current
3750 -- scope. This is a side effect of the need for the expander to be
3751 -- able to resolve internally generated calls.
3752
3753 -- Specifically, the issue appears when predefined controlled
3754 -- operations get called on a type extension whose parent is a
3755 -- private extension completed with a controlled extension - see
3756 -- below:
3757
3758 -- package X is
3759 -- type Par_Typ is tagged private;
3760 -- private
3761 -- type Par_Typ is new Controlled with null record;
3762 -- end;
3763 -- ...
3764 -- procedure Main is
3765 -- type Ext_Typ is new Par_Typ with null record;
3766 -- Obj : Ext_Typ;
3767 -- begin
3768 -- Finalize (Obj); -- Will improperly resolve
3769 -- end;
3770
3771 -- To avoid breaking privacy, Is_Hidden gets set elsewhere on such
3772 -- primitives, but we still need to verify that Nam is indeed a
3773 -- controlled subprogram. So, we do that here and issue the
3774 -- appropriate error.
3775
3776 if Is_Hidden (Nam)
3777 and then not In_Instance
3778 and then not Comes_From_Source (Nam)
3779 and then Comes_From_Source (N)
3780
3781 -- Verify Nam is a controlled primitive
3782
3783 and then Nam_In (Chars (Nam), Name_Adjust,
3784 Name_Finalize,
3785 Name_Initialize)
3786 and then Ekind (Nam) = E_Procedure
3787 and then Is_Controlled (Etype (First_Form))
3788 and then No (Next_Formal (First_Form))
3789 then
3790 Error_Msg_Node_2 := Etype (First_Form);
3791 Error_Msg_NE ("call to non-visible controlled primitive & on type"
3792 & " &", N, Nam);
3793 end if;
3775 3794
3776 -- On exit, all actuals match 3795 -- On exit, all actuals match
3777 3796
3778 Indicate_Name_And_Type; 3797 Indicate_Name_And_Type;
3779 end if; 3798 end if;
4030 -- If expression is overloaded, retain only interpretations that 4049 -- If expression is overloaded, retain only interpretations that
4031 -- will yield exact matches. 4050 -- will yield exact matches.
4032 4051
4033 if Is_Class_Wide_Type (T) then 4052 if Is_Class_Wide_Type (T) then
4034 if not Is_Overloaded (Expr) then 4053 if not Is_Overloaded (Expr) then
4035 if Base_Type (Etype (Expr)) /= Base_Type (T) then 4054 if Base_Type (Etype (Expr)) /= Base_Type (T)
4055 and then Etype (Expr) /= Raise_Type
4056 then
4036 if Nkind (Expr) = N_Aggregate then 4057 if Nkind (Expr) = N_Aggregate then
4037 Error_Msg_N ("type of aggregate cannot be class-wide", Expr); 4058 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
4038 else 4059 else
4039 Wrong_Type (Expr, T); 4060 Wrong_Type (Expr, T);
4040 end if; 4061 end if;
4839 4860
4840 if No (Act_Decl) then 4861 if No (Act_Decl) then
4841 Set_Etype (N, Etype (Comp)); 4862 Set_Etype (N, Etype (Comp));
4842 4863
4843 else 4864 else
4844 -- Component type depends on discriminants. Enter the 4865 -- If discriminants were present in the component
4845 -- main attributes of the subtype. 4866 -- declaration, they have been replaced by the
4867 -- actual values in the prefix object.
4846 4868
4847 declare 4869 declare
4848 Subt : constant Entity_Id := 4870 Subt : constant Entity_Id :=
4849 Defining_Identifier (Act_Decl); 4871 Defining_Identifier (Act_Decl);
4850
4851 begin 4872 begin
4852 Set_Etype (Subt, Base_Type (Etype (Comp))); 4873 Set_Etype (Subt, Base_Type (Etype (Comp)));
4853 Set_Ekind (Subt, Ekind (Etype (Comp)));
4854 Set_Etype (N, Subt); 4874 Set_Etype (N, Subt);
4855 end; 4875 end;
4856 end if; 4876 end if;
4857 4877
4858 -- If Full_Analysis not enabled, just set the Etype 4878 -- If Full_Analysis not enabled, just set the Etype
5045 5065
5046 <<Next_Comp>> 5066 <<Next_Comp>>
5047 if Comp = First_Private_Entity (Type_To_Use) then 5067 if Comp = First_Private_Entity (Type_To_Use) then
5048 if Etype (Sel) /= Any_Type then 5068 if Etype (Sel) /= Any_Type then
5049 5069
5050 -- We have a candiate 5070 -- If the first private entity's name matches, then treat
5071 -- it as a private op: needed for the error check for
5072 -- illegal selection of private entities further below.
5073
5074 if Chars (Comp) = Chars (Sel) then
5075 Is_Private_Op := True;
5076 end if;
5077
5078 -- We have a candidate, so exit the loop
5051 5079
5052 exit; 5080 exit;
5053 5081
5054 else 5082 else
5055 -- Indicate that subsequent operations are private, 5083 -- Indicate that subsequent operations are private,
6168 Get_Next_Interp (X, It); 6196 Get_Next_Interp (X, It);
6169 end loop; 6197 end loop;
6170 6198
6171 if Nkind (N) = N_Function_Call then 6199 if Nkind (N) = N_Function_Call then
6172 Get_First_Interp (Nam, X, It); 6200 Get_First_Interp (Nam, X, It);
6173 while Present (It.Nam) loop 6201
6174 if Ekind_In (It.Nam, E_Function, E_Operator) then 6202 if No (It.Typ)
6175 return; 6203 and then Ekind (Entity (Name (N))) = E_Function
6176 else 6204 and then Present (Homonym (Entity (Name (N))))
6177 Get_Next_Interp (X, It);
6178 end if;
6179 end loop;
6180
6181 -- If all interpretations are procedures, this deserves a
6182 -- more precise message. Ditto if this appears as the prefix
6183 -- of a selected component, which may be a lexical error.
6184
6185 Error_Msg_N
6186 ("\context requires function call, found procedure name", Nam);
6187
6188 if Nkind (Parent (N)) = N_Selected_Component
6189 and then N = Prefix (Parent (N))
6190 then 6205 then
6191 Error_Msg_N -- CODEFIX 6206 -- A name may appear overloaded if it has a homonym, even if that
6192 ("\period should probably be semicolon", Parent (N)); 6207 -- homonym is non-overloadable, in which case the overload list is
6208 -- in fact empty. This specialized case deserves a special message
6209 -- if the homonym is a child package.
6210
6211 declare
6212 Nam : constant Node_Id := Name (N);
6213 H : constant Entity_Id := Homonym (Entity (Nam));
6214
6215 begin
6216 if Ekind (H) = E_Package and then Is_Child_Unit (H) then
6217 Error_Msg_Qual_Level := 2;
6218 Error_Msg_NE ("if an entity in package& is meant, ", Nam, H);
6219 Error_Msg_NE ("\use a fully qualified name", Nam, H);
6220 Error_Msg_Qual_Level := 0;
6221 end if;
6222 end;
6223
6224 else
6225 while Present (It.Nam) loop
6226 if Ekind_In (It.Nam, E_Function, E_Operator) then
6227 return;
6228 else
6229 Get_Next_Interp (X, It);
6230 end if;
6231 end loop;
6232
6233 -- If all interpretations are procedures, this deserves a more
6234 -- precise message. Ditto if this appears as the prefix of a
6235 -- selected component, which may be a lexical error.
6236
6237 Error_Msg_N
6238 ("\context requires function call, found procedure name", Nam);
6239
6240 if Nkind (Parent (N)) = N_Selected_Component
6241 and then N = Prefix (Parent (N))
6242 then
6243 Error_Msg_N -- CODEFIX
6244 ("\period should probably be semicolon", Parent (N));
6245 end if;
6193 end if; 6246 end if;
6194 6247
6195 elsif Nkind (N) = N_Procedure_Call_Statement 6248 elsif Nkind (N) = N_Procedure_Call_Statement
6196 and then not Void_Interp_Seen 6249 and then not Void_Interp_Seen
6197 then 6250 then
6198 Error_Msg_N ( 6251 Error_Msg_N ("\function name found in procedure call", Nam);
6199 "\function name found in procedure call", Nam);
6200 end if; 6252 end if;
6201 6253
6202 All_Errors_Mode := Err_Mode; 6254 All_Errors_Mode := Err_Mode;
6203 end Diagnose_Call; 6255 end Diagnose_Call;
6204 6256
7370 Has_Compatible_Type 7422 Has_Compatible_Type
7371 (R, 7423 (R,
7372 Etype (Next_Formal (First_Formal (Op_Id)))) 7424 Etype (Next_Formal (First_Formal (Op_Id))))
7373 then 7425 then
7374 Error_Msg_N 7426 Error_Msg_N
7375 ("No legal interpretation for operator&", N); 7427 ("no legal interpretation for operator&", N);
7376 Error_Msg_NE 7428 Error_Msg_NE
7377 ("\use clause on& would make operation legal", 7429 ("\use clause on& would make operation legal",
7378 N, Scope (Op_Id)); 7430 N, Scope (Op_Id));
7379 exit; 7431 exit;
7380 end if; 7432 end if;
7387 Error_Msg_N ("invalid operand types for operator&", N); 7439 Error_Msg_N ("invalid operand types for operator&", N);
7388 7440
7389 if Nkind (N) /= N_Op_Concat then 7441 if Nkind (N) /= N_Op_Concat then
7390 Error_Msg_NE ("\left operand has}!", N, Etype (L)); 7442 Error_Msg_NE ("\left operand has}!", N, Etype (L));
7391 Error_Msg_NE ("\right operand has}!", N, Etype (R)); 7443 Error_Msg_NE ("\right operand has}!", N, Etype (R));
7444
7445 -- For multiplication and division operators with
7446 -- a fixed-point operand and an integer operand,
7447 -- indicate that the integer operand should be of
7448 -- type Integer.
7449
7450 if Nkind_In (N, N_Op_Multiply, N_Op_Divide)
7451 and then Is_Fixed_Point_Type (Etype (L))
7452 and then Is_Integer_Type (Etype (R))
7453 then
7454 Error_Msg_N
7455 ("\convert right operand to `Integer`", N);
7456
7457 elsif Nkind (N) = N_Op_Multiply
7458 and then Is_Fixed_Point_Type (Etype (R))
7459 and then Is_Integer_Type (Etype (L))
7460 then
7461 Error_Msg_N
7462 ("\convert left operand to `Integer`", N);
7463 end if;
7392 7464
7393 -- For concatenation operators it is more difficult to 7465 -- For concatenation operators it is more difficult to
7394 -- determine which is the wrong operand. It is worth 7466 -- determine which is the wrong operand. It is worth
7395 -- flagging explicitly an access type, for those who 7467 -- flagging explicitly an access type, for those who
7396 -- might think that a dereference happens here. 7468 -- might think that a dereference happens here.
7507 -- Start of processing for Remove_Abstract_Operations 7579 -- Start of processing for Remove_Abstract_Operations
7508 7580
7509 begin 7581 begin
7510 if Is_Overloaded (N) then 7582 if Is_Overloaded (N) then
7511 if Debug_Flag_V then 7583 if Debug_Flag_V then
7512 Write_Str ("Remove_Abstract_Operations: "); 7584 Write_Line ("Remove_Abstract_Operations: ");
7513 Write_Overloads (N); 7585 Write_Overloads (N);
7514 end if; 7586 end if;
7515 7587
7516 Get_First_Interp (N, I, It); 7588 Get_First_Interp (N, I, It);
7517 7589
7702 end loop; 7774 end loop;
7703 end if; 7775 end if;
7704 end if; 7776 end if;
7705 7777
7706 if Debug_Flag_V then 7778 if Debug_Flag_V then
7707 Write_Str ("Remove_Abstract_Operations done: "); 7779 Write_Line ("Remove_Abstract_Operations done: ");
7708 Write_Overloads (N); 7780 Write_Overloads (N);
7709 end if; 7781 end if;
7710 end if; 7782 end if;
7711 end Remove_Abstract_Operations; 7783 end Remove_Abstract_Operations;
7712 7784
7781 -- We should look for an interpretation with the proper 7853 -- We should look for an interpretation with the proper
7782 -- number of formals, and determine whether it is an 7854 -- number of formals, and determine whether it is an
7783 -- In_Parameter, but for now we examine the formal that 7855 -- In_Parameter, but for now we examine the formal that
7784 -- corresponds to the indexing, and assume that variable 7856 -- corresponds to the indexing, and assume that variable
7785 -- indexing is required if some interpretation has an 7857 -- indexing is required if some interpretation has an
7786 -- assignable formal at that position. Still does not 7858 -- assignable formal at that position. Still does not
7787 -- cover the most complex cases ??? 7859 -- cover the most complex cases ???
7788 7860
7789 if Is_Overloaded (Name (Parent (Par))) then 7861 if Is_Overloaded (Name (Parent (Par))) then
7790 declare 7862 declare
7791 Proc : constant Node_Id := Name (Parent (Par)); 7863 Proc : constant Node_Id := Name (Parent (Par));
8215 -- operations of the derived type. 8287 -- operations of the derived type.
8216 8288
8217 -- Note that predefined containers are typically all derived from one of 8289 -- Note that predefined containers are typically all derived from one of
8218 -- the Controlled types. The code below is motivated by containers that 8290 -- the Controlled types. The code below is motivated by containers that
8219 -- are derived from other types with a Reference aspect. 8291 -- are derived from other types with a Reference aspect.
8292 -- Note as well that we need to examine the base type, given that
8293 -- the container object may be a constrained subtype or itype which
8294 -- does not have an explicit declaration,
8220 8295
8221 elsif Is_Derived_Type (C_Type) 8296 elsif Is_Derived_Type (C_Type)
8222 and then Etype (First_Formal (Entity (Func_Name))) /= Pref_Typ 8297 and then Etype (First_Formal (Entity (Func_Name))) /= Pref_Typ
8223 then 8298 then
8224 Func_Name := 8299 Func_Name :=
8225 Find_Indexing_Operations 8300 Find_Indexing_Operations
8226 (T => C_Type, 8301 (T => Base_Type (C_Type),
8227 Nam => Chars (Func_Name), 8302 Nam => Chars (Func_Name),
8228 Is_Constant => Is_Constant_Indexing); 8303 Is_Constant => Is_Constant_Indexing);
8229 end if; 8304 end if;
8230 8305
8231 Assoc := New_List (Relocate_Node (Prefix)); 8306 Assoc := New_List (Relocate_Node (Prefix));
8550 -- includes an implicit dereference or an implicit 'Access. 8625 -- includes an implicit dereference or an implicit 'Access.
8551 8626
8552 procedure Transform_Object_Operation 8627 procedure Transform_Object_Operation
8553 (Call_Node : out Node_Id; 8628 (Call_Node : out Node_Id;
8554 Node_To_Replace : out Node_Id); 8629 Node_To_Replace : out Node_Id);
8555 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..) 8630 -- Transform Obj.Operation (X, Y, ...) into Operation (Obj, X, Y ...).
8556 -- Call_Node is the resulting subprogram call, Node_To_Replace is 8631 -- Call_Node is the resulting subprogram call, Node_To_Replace is
8557 -- either N or the parent of N, and Subprog is a reference to the 8632 -- either N or the parent of N, and Subprog is a reference to the
8558 -- subprogram we are trying to match. 8633 -- subprogram we are trying to match.
8559 8634
8560 function Try_Class_Wide_Operation 8635 function Try_Class_Wide_Operation
9275 9350
9276 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id; 9351 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id;
9277 -- Prefix notation can also be used on operations that are not 9352 -- Prefix notation can also be used on operations that are not
9278 -- primitives of the type, but are declared in the same immediate 9353 -- primitives of the type, but are declared in the same immediate
9279 -- declarative part, which can only mean the corresponding package 9354 -- declarative part, which can only mean the corresponding package
9280 -- body (See RM 4.1.3 (9.2/3)). If we are in that body we extend the 9355 -- body (see RM 4.1.3 (9.2/3)). If we are in that body we extend the
9281 -- list of primitives with body operations with the same name that 9356 -- list of primitives with body operations with the same name that
9282 -- may be candidates, so that Try_Primitive_Operations can examine 9357 -- may be candidates, so that Try_Primitive_Operations can examine
9283 -- them if no real primitive is found. 9358 -- them if no real primitive is found.
9284 9359
9285 function Is_Private_Overriding (Op : Entity_Id) return Boolean; 9360 function Is_Private_Overriding (Op : Entity_Id) return Boolean;
9401 -- Extended_Primitive_Ops -- 9476 -- Extended_Primitive_Ops --
9402 ---------------------------- 9477 ----------------------------
9403 9478
9404 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id is 9479 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id is
9405 Type_Scope : constant Entity_Id := Scope (T); 9480 Type_Scope : constant Entity_Id := Scope (T);
9406 9481 Op_List : Elist_Id := Primitive_Operations (T);
9407 Body_Decls : List_Id;
9408 Op_Found : Boolean;
9409 Op : Entity_Id;
9410 Op_List : Elist_Id;
9411
9412 begin 9482 begin
9413 Op_List := Primitive_Operations (T); 9483 if Ekind_In (Type_Scope, E_Package, E_Generic_Package)
9414 9484 and then ((In_Package_Body (Type_Scope)
9415 if Ekind (Type_Scope) = E_Package 9485 and then In_Open_Scopes (Type_Scope)) or else In_Instance_Body)
9416 and then In_Package_Body (Type_Scope)
9417 and then In_Open_Scopes (Type_Scope)
9418 then 9486 then
9419 -- Retrieve list of declarations of package body. 9487 -- Retrieve list of declarations of package body if possible
9420 9488
9421 Body_Decls := 9489 declare
9422 Declarations 9490 The_Body : constant Node_Id :=
9423 (Unit_Declaration_Node 9491 Corresponding_Body (Unit_Declaration_Node (Type_Scope));
9424 (Corresponding_Body 9492 begin
9425 (Unit_Declaration_Node (Type_Scope)))); 9493 if Present (The_Body) then
9426 9494 declare
9427 Op := Current_Entity (Subprog); 9495 Body_Decls : constant List_Id :=
9428 Op_Found := False; 9496 Declarations (Unit_Declaration_Node (The_Body));
9429 while Present (Op) loop 9497 Op_Found : Boolean := False;
9430 if Comes_From_Source (Op) 9498 Op : Entity_Id := Current_Entity (Subprog);
9431 and then Is_Overloadable (Op) 9499 begin
9432 9500 while Present (Op) loop
9433 -- Exclude overriding primitive operations of a type 9501 if Comes_From_Source (Op)
9434 -- extension declared in the package body, to prevent 9502 and then Is_Overloadable (Op)
9435 -- duplicates in extended list. 9503
9436 9504 -- Exclude overriding primitive operations of a
9437 and then not Is_Primitive (Op) 9505 -- type extension declared in the package body,
9438 and then Is_List_Member (Unit_Declaration_Node (Op)) 9506 -- to prevent duplicates in extended list.
9439 and then List_Containing (Unit_Declaration_Node (Op)) = 9507
9440 Body_Decls 9508 and then not Is_Primitive (Op)
9441 then 9509 and then Is_List_Member
9442 if not Op_Found then 9510 (Unit_Declaration_Node (Op))
9443 9511 and then List_Containing
9444 -- Copy list of primitives so it is not affected for 9512 (Unit_Declaration_Node (Op)) = Body_Decls
9445 -- other uses. 9513 then
9446 9514 if not Op_Found then
9447 Op_List := New_Copy_Elist (Op_List); 9515 -- Copy list of primitives so it is not
9448 Op_Found := True; 9516 -- affected for other uses.
9449 end if; 9517
9450 9518 Op_List := New_Copy_Elist (Op_List);
9451 Append_Elmt (Op, Op_List); 9519 Op_Found := True;
9520 end if;
9521
9522 Append_Elmt (Op, Op_List);
9523 end if;
9524
9525 Op := Homonym (Op);
9526 end loop;
9527 end;
9452 end if; 9528 end if;
9453 9529 end;
9454 Op := Homonym (Op);
9455 end loop;
9456 end if; 9530 end if;
9457 9531
9458 return Op_List; 9532 return Op_List;
9459 end Extended_Primitive_Ops; 9533 end Extended_Primitive_Ops;
9460 9534