1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 with Atree; use Atree;
30 with Debug; use Debug;
31 with Einfo; use Einfo;
32 with Errout; use Errout;
33 with Exp_Util; use Exp_Util;
34 with Hostparm; use Hostparm;
35 with Itypes; use Itypes;
36 with Lib.Xref; use Lib.Xref;
37 with Namet; use Namet;
38 with Nlists; use Nlists;
39 with Nmake; use Nmake;
41 with Output; use Output;
42 with Restrict; use Restrict;
44 with Sem_Cat; use Sem_Cat;
45 with Sem_Ch3; use Sem_Ch3;
46 with Sem_Ch8; use Sem_Ch8;
47 with Sem_Dist; use Sem_Dist;
48 with Sem_Eval; use Sem_Eval;
49 with Sem_Res; use Sem_Res;
50 with Sem_Util; use Sem_Util;
51 with Sem_Type; use Sem_Type;
52 with Stand; use Stand;
53 with Sinfo; use Sinfo;
54 with Snames; use Snames;
55 with Tbuild; use Tbuild;
57 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
59 package body Sem_Ch4 is
61 -----------------------
62 -- Local Subprograms --
63 -----------------------
65 procedure Analyze_Expression (N : Node_Id);
66 -- For expressions that are not names, this is just a call to analyze.
67 -- If the expression is a name, it may be a call to a parameterless
68 -- function, and if so must be converted into an explicit call node
69 -- and analyzed as such. This deproceduring must be done during the first
70 -- pass of overload resolution, because otherwise a procedure call with
71 -- overloaded actuals may fail to resolve. See 4327-001 for an example.
73 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
74 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
75 -- is an operator name or an expanded name whose selector is an operator
76 -- name, and one possible interpretation is as a predefined operator.
78 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
79 -- If the prefix of a selected_component is overloaded, the proper
80 -- interpretation that yields a record type with the proper selector
81 -- name must be selected.
83 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
84 -- Procedure to analyze a user defined binary operator, which is resolved
85 -- like a function, but instead of a list of actuals it is presented
86 -- with the left and right operands of an operator node.
88 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
89 -- Procedure to analyze a user defined unary operator, which is resolved
90 -- like a function, but instead of a list of actuals, it is presented with
91 -- the operand of the operator node.
93 procedure Ambiguous_Operands (N : Node_Id);
94 -- for equality, membership, and comparison operators with overloaded
95 -- arguments, list possible interpretations.
97 procedure Insert_Explicit_Dereference (N : Node_Id);
98 -- In a context that requires a composite or subprogram type and
99 -- where a prefix is an access type, insert an explicit dereference.
101 procedure Analyze_One_Call
105 Success : out Boolean);
106 -- Check one interpretation of an overloaded subprogram name for
107 -- compatibility with the types of the actuals in a call. If there is a
108 -- single interpretation which does not match, post error if Report is
111 -- Nam is the entity that provides the formals against which the actuals
112 -- are checked. Nam is either the name of a subprogram, or the internal
113 -- subprogram type constructed for an access_to_subprogram. If the actuals
114 -- are compatible with Nam, then Nam is added to the list of candidate
115 -- interpretations for N, and Success is set to True.
117 procedure Check_Misspelled_Selector
120 -- Give possible misspelling diagnostic if Sel is likely to be
121 -- a misspelling of one of the selectors of the Prefix.
122 -- This is called by Analyze_Selected_Component after producing
123 -- an invalid selector error message.
125 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
126 -- Verify that type T is declared in scope S. Used to find intepretations
127 -- for operators given by expanded names. This is abstracted as a separate
128 -- function to handle extensions to System, where S is System, but T is
129 -- declared in the extension.
131 procedure Find_Arithmetic_Types
135 -- L and R are the operands of an arithmetic operator. Find
136 -- consistent pairs of interpretations for L and R that have a
137 -- numeric type consistent with the semantics of the operator.
139 procedure Find_Comparison_Types
143 -- L and R are operands of a comparison operator. Find consistent
144 -- pairs of interpretations for L and R.
146 procedure Find_Concatenation_Types
150 -- For the four varieties of concatenation.
152 procedure Find_Equality_Types
156 -- Ditto for equality operators.
158 procedure Find_Boolean_Types
162 -- Ditto for binary logical operations.
164 procedure Find_Negation_Types
168 -- Find consistent interpretation for operand of negation operator.
170 procedure Find_Non_Universal_Interpretations
175 -- For equality and comparison operators, the result is always boolean,
176 -- and the legality of the operation is determined from the visibility
177 -- of the operand types. If one of the operands has a universal interpre-
178 -- tation, the legality check uses some compatible non-universal
179 -- interpretation of the other operand. N can be an operator node, or
180 -- a function call whose name is an operator designator.
182 procedure Find_Unary_Types
186 -- Unary arithmetic types: plus, minus, abs.
188 procedure Check_Arithmetic_Pair
192 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
193 -- types for left and right operand. Determine whether they constitute
194 -- a valid pair for the given operator, and record the corresponding
195 -- interpretation of the operator node. The node N may be an operator
196 -- node (the usual case) or a function call whose prefix is an operator
197 -- designator. In both cases Op_Id is the operator name itself.
199 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
200 -- Give detailed information on overloaded call where none of the
201 -- interpretations match. N is the call node, Nam the designator for
202 -- the overloaded entity being called.
204 function Junk_Operand (N : Node_Id) return Boolean;
205 -- Test for an operand that is an inappropriate entity (e.g. a package
206 -- name or a label). If so, issue an error message and return True. If
207 -- the operand is not an inappropriate entity kind, return False.
209 procedure Operator_Check (N : Node_Id);
210 -- Verify that an operator has received some valid interpretation.
211 -- If none was found, determine whether a use clause would make the
212 -- operation legal. The variable Candidate_Type (defined in Sem_Type) is
213 -- set for every type compatible with the operator, even if the operator
214 -- for the type is not directly visible. The routine uses this type to emit
215 -- a more informative message.
217 function Try_Indexed_Call
222 -- If a function has defaults for all its actuals, a call to it may
223 -- in fact be an indexing on the result of the call. Try_Indexed_Call
224 -- attempts the interpretation as an indexing, prior to analysis as
225 -- a call. If both are possible, the node is overloaded with both
226 -- interpretations (same symbol but two different types).
228 function Try_Indirect_Call
233 -- Similarly, a function F that needs no actuals can return an access
234 -- to a subprogram, and the call F (X) interpreted as F.all (X). In
235 -- this case the call may be overloaded with both interpretations.
237 ------------------------
238 -- Ambiguous_Operands --
239 ------------------------
241 procedure Ambiguous_Operands (N : Node_Id) is
242 procedure List_Interps (Opnd : Node_Id);
244 procedure List_Interps (Opnd : Node_Id) is
245 Index : Interp_Index;
251 if Is_Overloaded (Opnd) then
252 if Nkind (Opnd) in N_Op then
255 elsif Nkind (Opnd) = N_Function_Call then
266 if Opnd = Left_Opnd (N) then
268 ("\left operand has the following interpretations", N);
271 ("\right operand has the following interpretations", N);
275 Get_First_Interp (Nam, Index, It);
277 while Present (It.Nam) loop
279 if Scope (It.Nam) = Standard_Standard
280 and then Scope (It.Typ) /= Standard_Standard
282 Error_Msg_Sloc := Sloc (Parent (It.Typ));
283 Error_Msg_NE (" & (inherited) declared#!", Err, It.Nam);
286 Error_Msg_Sloc := Sloc (It.Nam);
287 Error_Msg_NE (" & declared#!", Err, It.Nam);
290 Get_Next_Interp (Index, It);
296 or else Nkind (N) = N_Not_In
298 Error_Msg_N ("ambiguous operands for membership", N);
300 elsif Nkind (N) = N_Op_Eq
301 or else Nkind (N) = N_Op_Ne
303 Error_Msg_N ("ambiguous operands for equality", N);
306 Error_Msg_N ("ambiguous operands for comparison", N);
309 if All_Errors_Mode then
310 List_Interps (Left_Opnd (N));
311 List_Interps (Right_Opnd (N));
316 "\use '/'R'E'P'O'R'T'_'E'R'R'O'R'S'='F'U'L'L for details",
319 Error_Msg_N ("\use -gnatf for details", N);
322 end Ambiguous_Operands;
324 -----------------------
325 -- Analyze_Aggregate --
326 -----------------------
328 -- Most of the analysis of Aggregates requires that the type be known,
329 -- and is therefore put off until resolution.
331 procedure Analyze_Aggregate (N : Node_Id) is
333 if No (Etype (N)) then
334 Set_Etype (N, Any_Composite);
336 end Analyze_Aggregate;
338 -----------------------
339 -- Analyze_Allocator --
340 -----------------------
342 procedure Analyze_Allocator (N : Node_Id) is
343 Loc : constant Source_Ptr := Sloc (N);
344 Sav_Errs : constant Nat := Errors_Detected;
345 E : Node_Id := Expression (N);
346 Acc_Type : Entity_Id;
350 Check_Restriction (No_Allocators, N);
352 if Nkind (E) = N_Qualified_Expression then
353 Acc_Type := Create_Itype (E_Allocator_Type, N);
354 Set_Etype (Acc_Type, Acc_Type);
355 Init_Size_Align (Acc_Type);
356 Find_Type (Subtype_Mark (E));
357 Type_Id := Entity (Subtype_Mark (E));
358 Check_Fully_Declared (Type_Id, N);
359 Set_Directly_Designated_Type (Acc_Type, Type_Id);
361 if Is_Protected_Type (Type_Id) then
362 Check_Restriction (No_Protected_Type_Allocators, N);
365 if Is_Limited_Type (Type_Id)
366 and then Comes_From_Source (N)
367 and then not In_Instance_Body
369 Error_Msg_N ("initialization not allowed for limited types", N);
372 Analyze_And_Resolve (Expression (E), Type_Id);
374 -- A qualified expression requires an exact match of the type,
375 -- class-wide matching is not allowed.
377 if Is_Class_Wide_Type (Type_Id)
378 and then Base_Type (Etype (Expression (E))) /= Base_Type (Type_Id)
380 Wrong_Type (Expression (E), Type_Id);
383 Check_Non_Static_Context (Expression (E));
385 -- We don't analyze the qualified expression itself because it's
386 -- part of the allocator
388 Set_Etype (E, Type_Id);
395 -- If the allocator includes a N_Subtype_Indication then a
396 -- constraint is present, otherwise the node is a subtype mark.
397 -- Introduce an explicit subtype declaration into the tree
398 -- defining some anonymous subtype and rewrite the allocator to
399 -- use this subtype rather than the subtype indication.
401 -- It is important to introduce the explicit subtype declaration
402 -- so that the bounds of the subtype indication are attached to
403 -- the tree in case the allocator is inside a generic unit.
405 if Nkind (E) = N_Subtype_Indication then
407 -- A constraint is only allowed for a composite type in Ada
408 -- 95. In Ada 83, a constraint is also allowed for an
409 -- access-to-composite type, but the constraint is ignored.
411 Find_Type (Subtype_Mark (E));
413 if Is_Elementary_Type (Entity (Subtype_Mark (E))) then
415 and then Is_Access_Type (Entity (Subtype_Mark (E))))
417 Error_Msg_N ("constraint not allowed here", E);
419 if Nkind (Constraint (E))
420 = N_Index_Or_Discriminant_Constraint
423 ("\if qualified expression was meant, " &
424 "use apostrophe", Constraint (E));
428 -- Get rid of the bogus constraint:
430 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
431 Analyze_Allocator (N);
435 if Expander_Active then
437 Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
440 Make_Subtype_Declaration (Loc,
441 Defining_Identifier => Def_Id,
442 Subtype_Indication => Relocate_Node (E)));
444 if Sav_Errs /= Errors_Detected
445 and then Nkind (Constraint (E))
446 = N_Index_Or_Discriminant_Constraint
449 ("if qualified expression was meant, " &
450 "use apostrophe!", Constraint (E));
453 E := New_Occurrence_Of (Def_Id, Loc);
454 Rewrite (Expression (N), E);
458 Type_Id := Process_Subtype (E, N);
459 Acc_Type := Create_Itype (E_Allocator_Type, N);
460 Set_Etype (Acc_Type, Acc_Type);
461 Init_Size_Align (Acc_Type);
462 Set_Directly_Designated_Type (Acc_Type, Type_Id);
463 Check_Fully_Declared (Type_Id, N);
465 -- Check for missing initialization. Skip this check if we already
466 -- had errors on analyzing the allocator, since in that case these
467 -- are probably cascaded errors
469 if Is_Indefinite_Subtype (Type_Id)
470 and then Errors_Detected = Sav_Errs
472 if Is_Class_Wide_Type (Type_Id) then
474 ("initialization required in class-wide allocation", N);
477 ("initialization required in unconstrained allocation", N);
483 if Is_Abstract (Type_Id) then
484 Error_Msg_N ("cannot allocate abstract object", E);
487 if Has_Task (Designated_Type (Acc_Type)) then
488 Check_Restriction (No_Task_Allocators, N);
491 Set_Etype (N, Acc_Type);
493 if not Is_Library_Level_Entity (Acc_Type) then
494 Check_Restriction (No_Local_Allocators, N);
497 if Errors_Detected > Sav_Errs then
498 Set_Error_Posted (N);
499 Set_Etype (N, Any_Type);
502 end Analyze_Allocator;
504 ---------------------------
505 -- Analyze_Arithmetic_Op --
506 ---------------------------
508 procedure Analyze_Arithmetic_Op (N : Node_Id) is
509 L : constant Node_Id := Left_Opnd (N);
510 R : constant Node_Id := Right_Opnd (N);
514 Candidate_Type := Empty;
515 Analyze_Expression (L);
516 Analyze_Expression (R);
518 -- If the entity is already set, the node is the instantiation of
519 -- a generic node with a non-local reference, or was manufactured
520 -- by a call to Make_Op_xxx. In either case the entity is known to
521 -- be valid, and we do not need to collect interpretations, instead
522 -- we just get the single possible interpretation.
526 if Present (Op_Id) then
527 if Ekind (Op_Id) = E_Operator then
529 if (Nkind (N) = N_Op_Divide or else
530 Nkind (N) = N_Op_Mod or else
531 Nkind (N) = N_Op_Multiply or else
532 Nkind (N) = N_Op_Rem)
533 and then Treat_Fixed_As_Integer (N)
537 Set_Etype (N, Any_Type);
538 Find_Arithmetic_Types (L, R, Op_Id, N);
542 Set_Etype (N, Any_Type);
543 Add_One_Interp (N, Op_Id, Etype (Op_Id));
546 -- Entity is not already set, so we do need to collect interpretations
549 Op_Id := Get_Name_Entity_Id (Chars (N));
550 Set_Etype (N, Any_Type);
552 while Present (Op_Id) loop
553 if Ekind (Op_Id) = E_Operator
554 and then Present (Next_Entity (First_Entity (Op_Id)))
556 Find_Arithmetic_Types (L, R, Op_Id, N);
558 -- The following may seem superfluous, because an operator cannot
559 -- be generic, but this ignores the cleverness of the author of
562 elsif Is_Overloadable (Op_Id) then
563 Analyze_User_Defined_Binary_Op (N, Op_Id);
566 Op_Id := Homonym (Op_Id);
571 end Analyze_Arithmetic_Op;
577 -- Function, procedure, and entry calls are checked here. The Name
578 -- in the call may be overloaded. The actuals have been analyzed
579 -- and may themselves be overloaded. On exit from this procedure, the node
580 -- N may have zero, one or more interpretations. In the first case an error
581 -- message is produced. In the last case, the node is flagged as overloaded
582 -- and the interpretations are collected in All_Interp.
584 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
585 -- the type-checking is similar to that of other calls.
587 procedure Analyze_Call (N : Node_Id) is
588 Actuals : constant List_Id := Parameter_Associations (N);
589 Nam : Node_Id := Name (N);
593 Success : Boolean := False;
595 function Name_Denotes_Function return Boolean;
596 -- If the type of the name is an access to subprogram, this may be
597 -- the type of a name, or the return type of the function being called.
598 -- If the name is not an entity then it can denote a protected function.
599 -- Until we distinguish Etype from Return_Type, we must use this
600 -- routine to resolve the meaning of the name in the call.
602 ---------------------------
603 -- Name_Denotes_Function --
604 ---------------------------
606 function Name_Denotes_Function return Boolean is
608 if Is_Entity_Name (Nam) then
609 return Ekind (Entity (Nam)) = E_Function;
611 elsif Nkind (Nam) = N_Selected_Component then
612 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
617 end Name_Denotes_Function;
619 -- Start of processing for Analyze_Call
622 -- Initialize the type of the result of the call to the error type,
623 -- which will be reset if the type is successfully resolved.
625 Set_Etype (N, Any_Type);
627 if not Is_Overloaded (Nam) then
629 -- Only one interpretation to check
631 if Ekind (Etype (Nam)) = E_Subprogram_Type then
632 Nam_Ent := Etype (Nam);
634 elsif Is_Access_Type (Etype (Nam))
635 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
636 and then not Name_Denotes_Function
638 Nam_Ent := Designated_Type (Etype (Nam));
639 Insert_Explicit_Dereference (Nam);
641 -- Selected component case. Simple entry or protected operation,
642 -- where the entry name is given by the selector name.
644 elsif Nkind (Nam) = N_Selected_Component then
645 Nam_Ent := Entity (Selector_Name (Nam));
647 if Ekind (Nam_Ent) /= E_Entry
648 and then Ekind (Nam_Ent) /= E_Entry_Family
649 and then Ekind (Nam_Ent) /= E_Function
650 and then Ekind (Nam_Ent) /= E_Procedure
652 Error_Msg_N ("name in call is not a callable entity", Nam);
653 Set_Etype (N, Any_Type);
657 -- If the name is an Indexed component, it can be a call to a member
658 -- of an entry family. The prefix must be a selected component whose
659 -- selector is the entry. Analyze_Procedure_Call normalizes several
660 -- kinds of call into this form.
662 elsif Nkind (Nam) = N_Indexed_Component then
664 if Nkind (Prefix (Nam)) = N_Selected_Component then
665 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
668 Error_Msg_N ("name in call is not a callable entity", Nam);
669 Set_Etype (N, Any_Type);
674 elsif not Is_Entity_Name (Nam) then
675 Error_Msg_N ("name in call is not a callable entity", Nam);
676 Set_Etype (N, Any_Type);
680 Nam_Ent := Entity (Nam);
682 -- If no interpretations, give error message
684 if not Is_Overloadable (Nam_Ent) then
686 L : constant Boolean := Is_List_Member (N);
687 K : constant Node_Kind := Nkind (Parent (N));
690 -- If the node is in a list whose parent is not an
691 -- expression then it must be an attempted procedure call.
693 if L and then K not in N_Subexpr then
694 if Ekind (Entity (Nam)) = E_Generic_Procedure then
696 ("must instantiate generic procedure& before call",
700 ("procedure or entry name expected", Nam);
703 -- Check for tasking cases where only an entry call will do
706 and then (K = N_Entry_Call_Alternative
707 or else K = N_Triggering_Alternative)
709 Error_Msg_N ("entry name expected", Nam);
711 -- Otherwise give general error message
714 Error_Msg_N ("invalid prefix in call", Nam);
722 Analyze_One_Call (N, Nam_Ent, True, Success);
725 -- An overloaded selected component must denote overloaded
726 -- operations of a concurrent type. The interpretations are
727 -- attached to the simple name of those operations.
729 if Nkind (Nam) = N_Selected_Component then
730 Nam := Selector_Name (Nam);
733 Get_First_Interp (Nam, X, It);
735 while Present (It.Nam) loop
738 -- Name may be call that returns an access to subprogram, or more
739 -- generally an overloaded expression one of whose interpretations
740 -- yields an access to subprogram. If the name is an entity, we
741 -- do not dereference, because the node is a call that returns
742 -- the access type: note difference between f(x), where the call
743 -- may return an access subprogram type, and f(x)(y), where the
744 -- type returned by the call to f is implicitly dereferenced to
745 -- analyze the outer call.
747 if Is_Access_Type (Nam_Ent) then
748 Nam_Ent := Designated_Type (Nam_Ent);
750 elsif Is_Access_Type (Etype (Nam_Ent))
751 and then not Is_Entity_Name (Nam)
752 and then Ekind (Designated_Type (Etype (Nam_Ent)))
755 Nam_Ent := Designated_Type (Etype (Nam_Ent));
758 Analyze_One_Call (N, Nam_Ent, False, Success);
760 -- If the interpretation succeeds, mark the proper type of the
761 -- prefix (any valid candidate will do). If not, remove the
762 -- candidate interpretation. This only needs to be done for
763 -- overloaded protected operations, for other entities disambi-
764 -- guation is done directly in Resolve.
767 Set_Etype (Nam, It.Typ);
769 elsif Nkind (Name (N)) = N_Selected_Component then
773 Get_Next_Interp (X, It);
776 -- If the name is the result of a function call, it can only
777 -- be a call to a function returning an access to subprogram.
778 -- Insert explicit dereference.
780 if Nkind (Nam) = N_Function_Call then
781 Insert_Explicit_Dereference (Nam);
784 if Etype (N) = Any_Type then
786 -- None of the interpretations is compatible with the actuals
788 Diagnose_Call (N, Nam);
790 -- Special checks for uninstantiated put routines
792 if Nkind (N) = N_Procedure_Call_Statement
793 and then Is_Entity_Name (Nam)
794 and then Chars (Nam) = Name_Put
795 and then List_Length (Actuals) = 1
798 Arg : constant Node_Id := First (Actuals);
802 if Nkind (Arg) = N_Parameter_Association then
803 Typ := Etype (Explicit_Actual_Parameter (Arg));
808 if Is_Signed_Integer_Type (Typ) then
810 ("possible missing instantiation of " &
811 "'Text_'I'O.'Integer_'I'O!", Nam);
813 elsif Is_Modular_Integer_Type (Typ) then
815 ("possible missing instantiation of " &
816 "'Text_'I'O.'Modular_'I'O!", Nam);
818 elsif Is_Floating_Point_Type (Typ) then
820 ("possible missing instantiation of " &
821 "'Text_'I'O.'Float_'I'O!", Nam);
823 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
825 ("possible missing instantiation of " &
826 "'Text_'I'O.'Fixed_'I'O!", Nam);
828 elsif Is_Decimal_Fixed_Point_Type (Typ) then
830 ("possible missing instantiation of " &
831 "'Text_'I'O.'Decimal_'I'O!", Nam);
833 elsif Is_Enumeration_Type (Typ) then
835 ("possible missing instantiation of " &
836 "'Text_'I'O.'Enumeration_'I'O!", Nam);
841 elsif not Is_Overloaded (N)
842 and then Is_Entity_Name (Nam)
844 -- Resolution yields a single interpretation. Verify that
845 -- is has the proper capitalization.
847 Set_Entity_With_Style_Check (Nam, Entity (Nam));
848 Generate_Reference (Entity (Nam), Nam);
850 Set_Etype (Nam, Etype (Entity (Nam)));
857 ---------------------------
858 -- Analyze_Comparison_Op --
859 ---------------------------
861 procedure Analyze_Comparison_Op (N : Node_Id) is
862 L : constant Node_Id := Left_Opnd (N);
863 R : constant Node_Id := Right_Opnd (N);
864 Op_Id : Entity_Id := Entity (N);
867 Set_Etype (N, Any_Type);
868 Candidate_Type := Empty;
870 Analyze_Expression (L);
871 Analyze_Expression (R);
873 if Present (Op_Id) then
875 if Ekind (Op_Id) = E_Operator then
876 Find_Comparison_Types (L, R, Op_Id, N);
878 Add_One_Interp (N, Op_Id, Etype (Op_Id));
881 if Is_Overloaded (L) then
882 Set_Etype (L, Intersect_Types (L, R));
886 Op_Id := Get_Name_Entity_Id (Chars (N));
888 while Present (Op_Id) loop
890 if Ekind (Op_Id) = E_Operator then
891 Find_Comparison_Types (L, R, Op_Id, N);
893 Analyze_User_Defined_Binary_Op (N, Op_Id);
896 Op_Id := Homonym (Op_Id);
901 end Analyze_Comparison_Op;
903 ---------------------------
904 -- Analyze_Concatenation --
905 ---------------------------
907 -- If the only one-dimensional array type in scope is String,
908 -- this is the resulting type of the operation. Otherwise there
909 -- will be a concatenation operation defined for each user-defined
910 -- one-dimensional array.
912 procedure Analyze_Concatenation (N : Node_Id) is
913 L : constant Node_Id := Left_Opnd (N);
914 R : constant Node_Id := Right_Opnd (N);
915 Op_Id : Entity_Id := Entity (N);
920 Set_Etype (N, Any_Type);
921 Candidate_Type := Empty;
923 Analyze_Expression (L);
924 Analyze_Expression (R);
926 -- If the entity is present, the node appears in an instance,
927 -- and denotes a predefined concatenation operation. The resulting
928 -- type is obtained from the arguments when possible.
930 if Present (Op_Id) then
931 if Ekind (Op_Id) = E_Operator then
933 LT := Base_Type (Etype (L));
934 RT := Base_Type (Etype (R));
936 if Is_Array_Type (LT)
937 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
939 Add_One_Interp (N, Op_Id, LT);
941 elsif Is_Array_Type (RT)
942 and then LT = Base_Type (Component_Type (RT))
944 Add_One_Interp (N, Op_Id, RT);
947 Add_One_Interp (N, Op_Id, Etype (Op_Id));
951 Add_One_Interp (N, Op_Id, Etype (Op_Id));
955 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
957 while Present (Op_Id) loop
958 if Ekind (Op_Id) = E_Operator then
959 Find_Concatenation_Types (L, R, Op_Id, N);
961 Analyze_User_Defined_Binary_Op (N, Op_Id);
964 Op_Id := Homonym (Op_Id);
969 end Analyze_Concatenation;
971 ------------------------------------
972 -- Analyze_Conditional_Expression --
973 ------------------------------------
975 procedure Analyze_Conditional_Expression (N : Node_Id) is
976 Condition : constant Node_Id := First (Expressions (N));
977 Then_Expr : constant Node_Id := Next (Condition);
978 Else_Expr : constant Node_Id := Next (Then_Expr);
981 Analyze_Expression (Condition);
982 Analyze_Expression (Then_Expr);
983 Analyze_Expression (Else_Expr);
984 Set_Etype (N, Etype (Then_Expr));
985 end Analyze_Conditional_Expression;
987 -------------------------
988 -- Analyze_Equality_Op --
989 -------------------------
991 procedure Analyze_Equality_Op (N : Node_Id) is
992 Loc : constant Source_Ptr := Sloc (N);
993 L : constant Node_Id := Left_Opnd (N);
994 R : constant Node_Id := Right_Opnd (N);
998 Set_Etype (N, Any_Type);
999 Candidate_Type := Empty;
1001 Analyze_Expression (L);
1002 Analyze_Expression (R);
1004 -- If the entity is set, the node is a generic instance with a non-local
1005 -- reference to the predefined operator or to a user-defined function.
1006 -- It can also be an inequality that is expanded into the negation of a
1007 -- call to a user-defined equality operator.
1009 -- For the predefined case, the result is Boolean, regardless of the
1010 -- type of the operands. The operands may even be limited, if they are
1011 -- generic actuals. If they are overloaded, label the left argument with
1012 -- the common type that must be present, or with the type of the formal
1013 -- of the user-defined function.
1015 if Present (Entity (N)) then
1017 Op_Id := Entity (N);
1019 if Ekind (Op_Id) = E_Operator then
1020 Add_One_Interp (N, Op_Id, Standard_Boolean);
1022 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1025 if Is_Overloaded (L) then
1027 if Ekind (Op_Id) = E_Operator then
1028 Set_Etype (L, Intersect_Types (L, R));
1030 Set_Etype (L, Etype (First_Formal (Op_Id)));
1035 Op_Id := Get_Name_Entity_Id (Chars (N));
1037 while Present (Op_Id) loop
1039 if Ekind (Op_Id) = E_Operator then
1040 Find_Equality_Types (L, R, Op_Id, N);
1042 Analyze_User_Defined_Binary_Op (N, Op_Id);
1045 Op_Id := Homonym (Op_Id);
1049 -- If there was no match, and the operator is inequality, this may
1050 -- be a case where inequality has not been made explicit, as for
1051 -- tagged types. Analyze the node as the negation of an equality
1052 -- operation. This cannot be done earlier, because before analysis
1053 -- we cannot rule out the presence of an explicit inequality.
1055 if Etype (N) = Any_Type
1056 and then Nkind (N) = N_Op_Ne
1058 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1060 while Present (Op_Id) loop
1062 if Ekind (Op_Id) = E_Operator then
1063 Find_Equality_Types (L, R, Op_Id, N);
1065 Analyze_User_Defined_Binary_Op (N, Op_Id);
1068 Op_Id := Homonym (Op_Id);
1071 if Etype (N) /= Any_Type then
1072 Op_Id := Entity (N);
1078 Left_Opnd => Relocate_Node (Left_Opnd (N)),
1079 Right_Opnd => Relocate_Node (Right_Opnd (N)))));
1081 Set_Entity (Right_Opnd (N), Op_Id);
1087 end Analyze_Equality_Op;
1089 ----------------------------------
1090 -- Analyze_Explicit_Dereference --
1091 ----------------------------------
1093 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1094 Loc : constant Source_Ptr := Sloc (N);
1095 P : constant Node_Id := Prefix (N);
1101 function Is_Function_Type return Boolean;
1102 -- Check whether node may be interpreted as an implicit function call.
1104 function Is_Function_Type return Boolean is
1109 if not Is_Overloaded (N) then
1110 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1111 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1114 Get_First_Interp (N, I, It);
1116 while Present (It.Nam) loop
1117 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1118 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1123 Get_Next_Interp (I, It);
1128 end Is_Function_Type;
1132 Set_Etype (N, Any_Type);
1134 -- Test for remote access to subprogram type, and if so return
1135 -- after rewriting the original tree.
1137 if Remote_AST_E_Dereference (P) then
1141 -- Normal processing for other than remote access to subprogram type
1143 if not Is_Overloaded (P) then
1144 if Is_Access_Type (Etype (P)) then
1146 -- Set the Etype. We need to go thru Is_For_Access_Subtypes
1147 -- to avoid other problems caused by the Private_Subtype
1148 -- and it is safe to go to the Base_Type because this is the
1149 -- same as converting the access value to its Base_Type.
1152 DT : Entity_Id := Designated_Type (Etype (P));
1155 if Ekind (DT) = E_Private_Subtype
1156 and then Is_For_Access_Subtype (DT)
1158 DT := Base_Type (DT);
1164 elsif Etype (P) /= Any_Type then
1165 Error_Msg_N ("prefix of dereference must be an access type", N);
1170 Get_First_Interp (P, I, It);
1172 while Present (It.Nam) loop
1175 if Is_Access_Type (T) then
1176 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1179 Get_Next_Interp (I, It);
1184 -- Error if no interpretation of the prefix has an access type.
1186 if Etype (N) = Any_Type then
1188 ("access type required in prefix of explicit dereference", P);
1189 Set_Etype (N, Any_Type);
1195 and then Nkind (Parent (N)) /= N_Indexed_Component
1197 and then (Nkind (Parent (N)) /= N_Function_Call
1198 or else N /= Name (Parent (N)))
1200 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1201 or else N /= Name (Parent (N)))
1203 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1204 and then (Nkind (Parent (N)) /= N_Attribute_Reference
1206 (Attribute_Name (Parent (N)) /= Name_Address
1208 Attribute_Name (Parent (N)) /= Name_Access))
1210 -- Name is a function call with no actuals, in a context that
1211 -- requires deproceduring (including as an actual in an enclosing
1212 -- function or procedure call). We can conceive of pathological cases
1213 -- where the prefix might include functions that return access to
1214 -- subprograms and others that return a regular type. Disambiguation
1215 -- of those will have to take place in Resolve. See e.g. 7117-014.
1218 Make_Function_Call (Loc,
1219 Name => Make_Explicit_Dereference (Loc, P),
1220 Parameter_Associations => New_List);
1222 -- If the prefix is overloaded, remove operations that have formals,
1223 -- we know that this is a parameterless call.
1225 if Is_Overloaded (P) then
1226 Get_First_Interp (P, I, It);
1228 while Present (It.Nam) loop
1231 if No (First_Formal (Base_Type (Designated_Type (T)))) then
1237 Get_Next_Interp (I, It);
1245 -- A value of remote access-to-class-wide must not be dereferenced
1248 Validate_Remote_Access_To_Class_Wide_Type (N);
1250 end Analyze_Explicit_Dereference;
1252 ------------------------
1253 -- Analyze_Expression --
1254 ------------------------
1256 procedure Analyze_Expression (N : Node_Id) is
1259 Check_Parameterless_Call (N);
1260 end Analyze_Expression;
1262 ------------------------------------
1263 -- Analyze_Indexed_Component_Form --
1264 ------------------------------------
1266 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
1267 P : constant Node_Id := Prefix (N);
1268 Exprs : List_Id := Expressions (N);
1274 procedure Process_Function_Call;
1275 -- Prefix in indexed component form is an overloadable entity,
1276 -- so the node is a function call. Reformat it as such.
1278 procedure Process_Indexed_Component;
1279 -- Prefix in indexed component form is actually an indexed component.
1280 -- This routine processes it, knowing that the prefix is already
1283 procedure Process_Indexed_Component_Or_Slice;
1284 -- An indexed component with a single index may designate a slice if
1285 -- the index is a subtype mark. This routine disambiguates these two
1286 -- cases by resolving the prefix to see if it is a subtype mark.
1288 procedure Process_Overloaded_Indexed_Component;
1289 -- If the prefix of an indexed component is overloaded, the proper
1290 -- interpretation is selected by the index types and the context.
1292 ---------------------------
1293 -- Process_Function_Call --
1294 ---------------------------
1296 procedure Process_Function_Call is
1300 Change_Node (N, N_Function_Call);
1302 Set_Parameter_Associations (N, Exprs);
1303 Actual := First (Parameter_Associations (N));
1305 while Present (Actual) loop
1307 Check_Parameterless_Call (Actual);
1308 Next_Actual (Actual);
1312 end Process_Function_Call;
1314 -------------------------------
1315 -- Process_Indexed_Component --
1316 -------------------------------
1318 procedure Process_Indexed_Component is
1320 Array_Type : Entity_Id;
1322 Entry_Family : Entity_Id;
1325 Exp := First (Exprs);
1327 if Is_Overloaded (P) then
1328 Process_Overloaded_Indexed_Component;
1331 Array_Type := Etype (P);
1333 -- Prefix must be appropriate for an array type.
1334 -- Dereference the prefix if it is an access type.
1336 if Is_Access_Type (Array_Type) then
1337 Array_Type := Designated_Type (Array_Type);
1340 if Is_Array_Type (Array_Type) then
1343 elsif (Is_Entity_Name (P)
1345 Ekind (Entity (P)) = E_Entry_Family)
1347 (Nkind (P) = N_Selected_Component
1349 Is_Entity_Name (Selector_Name (P))
1351 Ekind (Entity (Selector_Name (P))) = E_Entry_Family)
1353 if Is_Entity_Name (P) then
1354 Entry_Family := Entity (P);
1356 Entry_Family := Entity (Selector_Name (P));
1360 Set_Etype (N, Any_Type);
1362 if not Has_Compatible_Type
1363 (Exp, Entry_Index_Type (Entry_Family))
1365 Error_Msg_N ("invalid index type in entry name", N);
1367 elsif Present (Next (Exp)) then
1368 Error_Msg_N ("too many subscripts in entry reference", N);
1371 Set_Etype (N, Etype (P));
1376 elsif Is_Record_Type (Array_Type)
1377 and then Remote_AST_I_Dereference (P)
1381 elsif Array_Type = Any_Type then
1382 Set_Etype (N, Any_Type);
1385 -- Here we definitely have a bad indexing
1388 if Nkind (Parent (N)) = N_Requeue_Statement
1390 ((Is_Entity_Name (P)
1391 and then Ekind (Entity (P)) = E_Entry)
1393 (Nkind (P) = N_Selected_Component
1394 and then Is_Entity_Name (Selector_Name (P))
1395 and then Ekind (Entity (Selector_Name (P))) = E_Entry))
1398 ("REQUEUE does not permit parameters", First (Exprs));
1400 elsif Is_Entity_Name (P)
1401 and then Etype (P) = Standard_Void_Type
1403 Error_Msg_NE ("incorrect use of&", P, Entity (P));
1406 Error_Msg_N ("array type required in indexed component", P);
1409 Set_Etype (N, Any_Type);
1413 Index := First_Index (Array_Type);
1415 while Present (Index) and then Present (Exp) loop
1416 if not Has_Compatible_Type (Exp, Etype (Index)) then
1417 Wrong_Type (Exp, Etype (Index));
1418 Set_Etype (N, Any_Type);
1426 Set_Etype (N, Component_Type (Array_Type));
1428 if Present (Index) then
1430 ("too few subscripts in array reference", First (Exprs));
1432 elsif Present (Exp) then
1433 Error_Msg_N ("too many subscripts in array reference", Exp);
1437 end Process_Indexed_Component;
1439 ----------------------------------------
1440 -- Process_Indexed_Component_Or_Slice --
1441 ----------------------------------------
1443 procedure Process_Indexed_Component_Or_Slice is
1445 Exp := First (Exprs);
1447 while Present (Exp) loop
1448 Analyze_Expression (Exp);
1452 Exp := First (Exprs);
1454 -- If one index is present, and it is a subtype name, then the
1455 -- node denotes a slice (note that the case of an explicit range
1456 -- for a slice was already built as an N_Slice node in the first
1457 -- place, so that case is not handled here).
1459 -- We use a replace rather than a rewrite here because this is one
1460 -- of the cases in which the tree built by the parser is plain wrong.
1463 and then Is_Entity_Name (Exp)
1464 and then Is_Type (Entity (Exp))
1467 Make_Slice (Sloc (N),
1469 Discrete_Range => New_Copy (Exp)));
1472 -- Otherwise (more than one index present, or single index is not
1473 -- a subtype name), then we have the indexed component case.
1476 Process_Indexed_Component;
1478 end Process_Indexed_Component_Or_Slice;
1480 ------------------------------------------
1481 -- Process_Overloaded_Indexed_Component --
1482 ------------------------------------------
1484 procedure Process_Overloaded_Indexed_Component is
1493 Set_Etype (N, Any_Type);
1494 Get_First_Interp (P, I, It);
1496 while Present (It.Nam) loop
1499 if Is_Access_Type (Typ) then
1500 Typ := Designated_Type (Typ);
1503 if Is_Array_Type (Typ) then
1505 -- Got a candidate: verify that index types are compatible
1507 Index := First_Index (Typ);
1510 Exp := First (Exprs);
1512 while Present (Index) and then Present (Exp) loop
1513 if Has_Compatible_Type (Exp, Etype (Index)) then
1525 if Found and then No (Index) and then No (Exp) then
1527 Etype (Component_Type (Typ)),
1528 Etype (Component_Type (Typ)));
1532 Get_Next_Interp (I, It);
1535 if Etype (N) = Any_Type then
1536 Error_Msg_N ("no legal interpetation for indexed component", N);
1537 Set_Is_Overloaded (N, False);
1541 end Process_Overloaded_Indexed_Component;
1543 ------------------------------------
1544 -- Analyze_Indexed_Component_Form --
1545 ------------------------------------
1548 -- Get name of array, function or type
1551 P_T := Base_Type (Etype (P));
1553 if Is_Entity_Name (P)
1554 or else Nkind (P) = N_Operator_Symbol
1558 if Ekind (U_N) in Type_Kind then
1560 -- Reformat node as a type conversion.
1562 E := Remove_Head (Exprs);
1564 if Present (First (Exprs)) then
1566 ("argument of type conversion must be single expression", N);
1569 Change_Node (N, N_Type_Conversion);
1570 Set_Subtype_Mark (N, P);
1572 Set_Expression (N, E);
1574 -- After changing the node, call for the specific Analysis
1575 -- routine directly, to avoid a double call to the expander.
1577 Analyze_Type_Conversion (N);
1581 if Is_Overloadable (U_N) then
1582 Process_Function_Call;
1584 elsif Ekind (Etype (P)) = E_Subprogram_Type
1585 or else (Is_Access_Type (Etype (P))
1587 Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type)
1589 -- Call to access_to-subprogram with possible implicit dereference
1591 Process_Function_Call;
1593 elsif Ekind (U_N) = E_Generic_Function
1594 or else Ekind (U_N) = E_Generic_Procedure
1596 -- A common beginner's (or C++ templates fan) error.
1598 Error_Msg_N ("generic subprogram cannot be called", N);
1599 Set_Etype (N, Any_Type);
1603 Process_Indexed_Component_Or_Slice;
1606 -- If not an entity name, prefix is an expression that may denote
1607 -- an array or an access-to-subprogram.
1611 if (Ekind (P_T) = E_Subprogram_Type)
1612 or else (Is_Access_Type (P_T)
1614 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
1616 Process_Function_Call;
1618 elsif Nkind (P) = N_Selected_Component
1619 and then Ekind (Entity (Selector_Name (P))) = E_Function
1621 Process_Function_Call;
1624 -- Indexed component, slice, or a call to a member of a family
1625 -- entry, which will be converted to an entry call later.
1626 Process_Indexed_Component_Or_Slice;
1629 end Analyze_Indexed_Component_Form;
1631 ------------------------
1632 -- Analyze_Logical_Op --
1633 ------------------------
1635 procedure Analyze_Logical_Op (N : Node_Id) is
1636 L : constant Node_Id := Left_Opnd (N);
1637 R : constant Node_Id := Right_Opnd (N);
1638 Op_Id : Entity_Id := Entity (N);
1641 Set_Etype (N, Any_Type);
1642 Candidate_Type := Empty;
1644 Analyze_Expression (L);
1645 Analyze_Expression (R);
1647 if Present (Op_Id) then
1649 if Ekind (Op_Id) = E_Operator then
1650 Find_Boolean_Types (L, R, Op_Id, N);
1652 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1656 Op_Id := Get_Name_Entity_Id (Chars (N));
1658 while Present (Op_Id) loop
1659 if Ekind (Op_Id) = E_Operator then
1660 Find_Boolean_Types (L, R, Op_Id, N);
1662 Analyze_User_Defined_Binary_Op (N, Op_Id);
1665 Op_Id := Homonym (Op_Id);
1670 end Analyze_Logical_Op;
1672 ---------------------------
1673 -- Analyze_Membership_Op --
1674 ---------------------------
1676 procedure Analyze_Membership_Op (N : Node_Id) is
1677 L : constant Node_Id := Left_Opnd (N);
1678 R : constant Node_Id := Right_Opnd (N);
1680 Index : Interp_Index;
1682 Found : Boolean := False;
1686 procedure Try_One_Interp (T1 : Entity_Id);
1687 -- Routine to try one proposed interpretation. Note that the context
1688 -- of the operation plays no role in resolving the arguments, so that
1689 -- if there is more than one interpretation of the operands that is
1690 -- compatible with a membership test, the operation is ambiguous.
1692 procedure Try_One_Interp (T1 : Entity_Id) is
1694 if Has_Compatible_Type (R, T1) then
1696 and then Base_Type (T1) /= Base_Type (T_F)
1698 It := Disambiguate (L, I_F, Index, Any_Type);
1700 if It = No_Interp then
1701 Ambiguous_Operands (N);
1702 Set_Etype (L, Any_Type);
1720 -- Start of processing for Analyze_Membership_Op
1723 Analyze_Expression (L);
1725 if Nkind (R) = N_Range
1726 or else (Nkind (R) = N_Attribute_Reference
1727 and then Attribute_Name (R) = Name_Range)
1731 if not Is_Overloaded (L) then
1732 Try_One_Interp (Etype (L));
1735 Get_First_Interp (L, Index, It);
1737 while Present (It.Typ) loop
1738 Try_One_Interp (It.Typ);
1739 Get_Next_Interp (Index, It);
1743 -- If not a range, it can only be a subtype mark, or else there
1744 -- is a more basic error, to be diagnosed in Find_Type.
1749 if Is_Entity_Name (R) then
1750 Check_Fully_Declared (Entity (R), R);
1754 -- Compatibility between expression and subtype mark or range is
1755 -- checked during resolution. The result of the operation is Boolean
1758 Set_Etype (N, Standard_Boolean);
1759 end Analyze_Membership_Op;
1761 ----------------------
1762 -- Analyze_Negation --
1763 ----------------------
1765 procedure Analyze_Negation (N : Node_Id) is
1766 R : constant Node_Id := Right_Opnd (N);
1767 Op_Id : Entity_Id := Entity (N);
1770 Set_Etype (N, Any_Type);
1771 Candidate_Type := Empty;
1773 Analyze_Expression (R);
1775 if Present (Op_Id) then
1776 if Ekind (Op_Id) = E_Operator then
1777 Find_Negation_Types (R, Op_Id, N);
1779 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1783 Op_Id := Get_Name_Entity_Id (Chars (N));
1785 while Present (Op_Id) loop
1786 if Ekind (Op_Id) = E_Operator then
1787 Find_Negation_Types (R, Op_Id, N);
1789 Analyze_User_Defined_Unary_Op (N, Op_Id);
1792 Op_Id := Homonym (Op_Id);
1797 end Analyze_Negation;
1803 procedure Analyze_Null (N : Node_Id) is
1805 Set_Etype (N, Any_Access);
1808 ----------------------
1809 -- Analyze_One_Call --
1810 ----------------------
1812 procedure Analyze_One_Call
1816 Success : out Boolean)
1818 Actuals : constant List_Id := Parameter_Associations (N);
1819 Prev_T : constant Entity_Id := Etype (N);
1822 Is_Indexed : Boolean := False;
1823 Subp_Type : constant Entity_Id := Etype (Nam);
1827 -- If candidate interpretation matches, indicate name and type of
1828 -- result on call node.
1834 procedure Set_Name is
1836 Add_One_Interp (N, Nam, Etype (Nam));
1839 -- If the prefix of the call is a name, indicate the entity
1840 -- being called. If it is not a name, it is an expression that
1841 -- denotes an access to subprogram or else an entry or family. In
1842 -- the latter case, the name is a selected component, and the entity
1843 -- being called is noted on the selector.
1845 if not Is_Type (Nam) then
1846 if Is_Entity_Name (Name (N))
1847 or else Nkind (Name (N)) = N_Operator_Symbol
1849 Set_Entity (Name (N), Nam);
1851 elsif Nkind (Name (N)) = N_Selected_Component then
1852 Set_Entity (Selector_Name (Name (N)), Nam);
1856 if Debug_Flag_E and not Report then
1857 Write_Str (" Overloaded call ");
1858 Write_Int (Int (N));
1859 Write_Str (" compatible with ");
1860 Write_Int (Int (Nam));
1865 -- Start of processing for Analyze_One_Call
1870 -- If the subprogram has no formals, or if all the formals have
1871 -- defaults, and the return type is an array type, the node may
1872 -- denote an indexing of the result of a parameterless call.
1874 if Needs_No_Actuals (Nam)
1875 and then Present (Actuals)
1877 if Is_Array_Type (Subp_Type) then
1878 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type);
1880 elsif Is_Access_Type (Subp_Type)
1881 and then Is_Array_Type (Designated_Type (Subp_Type))
1884 Try_Indexed_Call (N, Nam, Designated_Type (Subp_Type));
1886 elsif Is_Access_Type (Subp_Type)
1887 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
1889 Is_Indexed := Try_Indirect_Call (N, Nam, Subp_Type);
1894 Normalize_Actuals (N, Nam, (Report and not Is_Indexed), Norm_OK);
1898 -- Mismatch in number or names of parameters
1900 if Debug_Flag_E then
1901 Write_Str (" normalization fails in call ");
1902 Write_Int (Int (N));
1903 Write_Str (" with subprogram ");
1904 Write_Int (Int (Nam));
1908 -- If the context expects a function call, discard any interpretation
1909 -- that is a procedure. If the node is not overloaded, leave as is for
1910 -- better error reporting when type mismatch is found.
1912 elsif Nkind (N) = N_Function_Call
1913 and then Is_Overloaded (Name (N))
1914 and then Ekind (Nam) = E_Procedure
1918 -- Ditto for function calls in a procedure context.
1920 elsif Nkind (N) = N_Procedure_Call_Statement
1921 and then Is_Overloaded (Name (N))
1922 and then Etype (Nam) /= Standard_Void_Type
1926 elsif not Present (Actuals) then
1928 -- If Normalize succeeds, then there are default parameters for
1933 elsif Ekind (Nam) = E_Operator then
1935 if Nkind (N) = N_Procedure_Call_Statement then
1939 -- This can occur when the prefix of the call is an operator
1940 -- name or an expanded name whose selector is an operator name.
1942 Analyze_Operator_Call (N, Nam);
1944 if Etype (N) /= Prev_T then
1946 -- There may be a user-defined operator that hides the
1947 -- current interpretation. We must check for this independently
1948 -- of the analysis of the call with the user-defined operation,
1949 -- because the parameter names may be wrong and yet the hiding
1950 -- takes place. Fixes b34014o.
1952 if Is_Overloaded (Name (N)) then
1958 Get_First_Interp (Name (N), I, It);
1960 while Present (It.Nam) loop
1962 if Ekind (It.Nam) /= E_Operator
1963 and then Hides_Op (It.Nam, Nam)
1966 (First_Actual (N), Etype (First_Formal (It.Nam)))
1967 and then (No (Next_Actual (First_Actual (N)))
1968 or else Has_Compatible_Type
1969 (Next_Actual (First_Actual (N)),
1970 Etype (Next_Formal (First_Formal (It.Nam)))))
1972 Set_Etype (N, Prev_T);
1976 Get_Next_Interp (I, It);
1981 -- If operator matches formals, record its name on the call.
1982 -- If the operator is overloaded, Resolve will select the
1983 -- correct one from the list of interpretations. The call
1984 -- node itself carries the first candidate.
1986 Set_Entity (Name (N), Nam);
1989 elsif Report and then Etype (N) = Any_Type then
1990 Error_Msg_N ("incompatible arguments for operator", N);
1994 -- Normalize_Actuals has chained the named associations in the
1995 -- correct order of the formals.
1997 Actual := First_Actual (N);
1998 Formal := First_Formal (Nam);
2000 while Present (Actual) and then Present (Formal) loop
2002 if (Nkind (Parent (Actual)) /= N_Parameter_Association
2003 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal))
2005 if Has_Compatible_Type (Actual, Etype (Formal)) then
2006 Next_Actual (Actual);
2007 Next_Formal (Formal);
2010 if Debug_Flag_E then
2011 Write_Str (" type checking fails in call ");
2012 Write_Int (Int (N));
2013 Write_Str (" with formal ");
2014 Write_Int (Int (Formal));
2015 Write_Str (" in subprogram ");
2016 Write_Int (Int (Nam));
2020 if Report and not Is_Indexed then
2022 Wrong_Type (Actual, Etype (Formal));
2024 if Nkind (Actual) = N_Op_Eq
2025 and then Nkind (Left_Opnd (Actual)) = N_Identifier
2027 Formal := First_Formal (Nam);
2029 while Present (Formal) loop
2031 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
2033 ("possible misspelling of `=>`!", Actual);
2037 Next_Formal (Formal);
2041 if All_Errors_Mode then
2042 Error_Msg_Sloc := Sloc (Nam);
2044 if Is_Overloadable (Nam)
2045 and then Present (Alias (Nam))
2046 and then not Comes_From_Source (Nam)
2049 (" ==> in call to &#(inherited)!", Actual, Nam);
2051 Error_Msg_NE (" ==> in call to &#!", Actual, Nam);
2060 -- Normalize_Actuals has verified that a default value exists
2061 -- for this formal. Current actual names a subsequent formal.
2063 Next_Formal (Formal);
2067 -- On exit, all actuals match.
2071 end Analyze_One_Call;
2073 ----------------------------
2074 -- Analyze_Operator_Call --
2075 ----------------------------
2077 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
2078 Op_Name : constant Name_Id := Chars (Op_Id);
2079 Act1 : constant Node_Id := First_Actual (N);
2080 Act2 : constant Node_Id := Next_Actual (Act1);
2083 if Present (Act2) then
2085 -- Maybe binary operators
2087 if Present (Next_Actual (Act2)) then
2089 -- Too many actuals for an operator
2093 elsif Op_Name = Name_Op_Add
2094 or else Op_Name = Name_Op_Subtract
2095 or else Op_Name = Name_Op_Multiply
2096 or else Op_Name = Name_Op_Divide
2097 or else Op_Name = Name_Op_Mod
2098 or else Op_Name = Name_Op_Rem
2099 or else Op_Name = Name_Op_Expon
2101 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
2103 elsif Op_Name = Name_Op_And
2104 or else Op_Name = Name_Op_Or
2105 or else Op_Name = Name_Op_Xor
2107 Find_Boolean_Types (Act1, Act2, Op_Id, N);
2109 elsif Op_Name = Name_Op_Lt
2110 or else Op_Name = Name_Op_Le
2111 or else Op_Name = Name_Op_Gt
2112 or else Op_Name = Name_Op_Ge
2114 Find_Comparison_Types (Act1, Act2, Op_Id, N);
2116 elsif Op_Name = Name_Op_Eq
2117 or else Op_Name = Name_Op_Ne
2119 Find_Equality_Types (Act1, Act2, Op_Id, N);
2121 elsif Op_Name = Name_Op_Concat then
2122 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
2124 -- Is this else null correct, or should it be an abort???
2133 if Op_Name = Name_Op_Subtract or else
2134 Op_Name = Name_Op_Add or else
2135 Op_Name = Name_Op_Abs
2137 Find_Unary_Types (Act1, Op_Id, N);
2140 Op_Name = Name_Op_Not
2142 Find_Negation_Types (Act1, Op_Id, N);
2144 -- Is this else null correct, or should it be an abort???
2150 end Analyze_Operator_Call;
2152 -------------------------------------------
2153 -- Analyze_Overloaded_Selected_Component --
2154 -------------------------------------------
2156 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
2158 Nam : Node_Id := Prefix (N);
2159 Sel : Node_Id := Selector_Name (N);
2165 Get_First_Interp (Nam, I, It);
2167 Set_Etype (Sel, Any_Type);
2169 while Present (It.Typ) loop
2170 if Is_Access_Type (It.Typ) then
2171 T := Designated_Type (It.Typ);
2176 if Is_Record_Type (T) then
2177 Comp := First_Entity (T);
2179 while Present (Comp) loop
2181 if Chars (Comp) = Chars (Sel)
2182 and then Is_Visible_Component (Comp)
2184 Set_Entity_With_Style_Check (Sel, Comp);
2185 Generate_Reference (Comp, Sel);
2187 Set_Etype (Sel, Etype (Comp));
2188 Add_One_Interp (N, Etype (Comp), Etype (Comp));
2190 -- This also specifies a candidate to resolve the name.
2191 -- Further overloading will be resolved from context.
2193 Set_Etype (Nam, It.Typ);
2199 elsif Is_Concurrent_Type (T) then
2200 Comp := First_Entity (T);
2202 while Present (Comp)
2203 and then Comp /= First_Private_Entity (T)
2205 if Chars (Comp) = Chars (Sel) then
2206 if Is_Overloadable (Comp) then
2207 Add_One_Interp (Sel, Comp, Etype (Comp));
2209 Set_Entity_With_Style_Check (Sel, Comp);
2210 Generate_Reference (Comp, Sel);
2213 Set_Etype (Sel, Etype (Comp));
2214 Set_Etype (N, Etype (Comp));
2215 Set_Etype (Nam, It.Typ);
2217 -- For access type case, introduce explicit deference for
2218 -- more uniform treatment of entry calls.
2220 if Is_Access_Type (Etype (Nam)) then
2221 Insert_Explicit_Dereference (Nam);
2228 Set_Is_Overloaded (N, Is_Overloaded (Sel));
2232 Get_Next_Interp (I, It);
2235 if Etype (N) = Any_Type then
2236 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
2237 Set_Entity (Sel, Any_Id);
2238 Set_Etype (Sel, Any_Type);
2241 end Analyze_Overloaded_Selected_Component;
2243 ----------------------------------
2244 -- Analyze_Qualified_Expression --
2245 ----------------------------------
2247 procedure Analyze_Qualified_Expression (N : Node_Id) is
2248 Mark : constant Entity_Id := Subtype_Mark (N);
2252 Set_Etype (N, Any_Type);
2256 if T = Any_Type then
2259 Check_Fully_Declared (T, N);
2261 Analyze_Expression (Expression (N));
2263 end Analyze_Qualified_Expression;
2269 procedure Analyze_Range (N : Node_Id) is
2270 L : constant Node_Id := Low_Bound (N);
2271 H : constant Node_Id := High_Bound (N);
2272 I1, I2 : Interp_Index;
2275 procedure Check_Common_Type (T1, T2 : Entity_Id);
2276 -- Verify the compatibility of two types, and choose the
2277 -- non universal one if the other is universal.
2279 procedure Check_High_Bound (T : Entity_Id);
2280 -- Test one interpretation of the low bound against all those
2281 -- of the high bound.
2283 -----------------------
2284 -- Check_Common_Type --
2285 -----------------------
2287 procedure Check_Common_Type (T1, T2 : Entity_Id) is
2289 if Covers (T1, T2) or else Covers (T2, T1) then
2290 if T1 = Universal_Integer
2291 or else T1 = Universal_Real
2292 or else T1 = Any_Character
2294 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
2296 elsif (T1 = T2) then
2297 Add_One_Interp (N, T1, T1);
2300 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
2303 end Check_Common_Type;
2305 ----------------------
2306 -- Check_High_Bound --
2307 ----------------------
2309 procedure Check_High_Bound (T : Entity_Id) is
2311 if not Is_Overloaded (H) then
2312 Check_Common_Type (T, Etype (H));
2314 Get_First_Interp (H, I2, It2);
2316 while Present (It2.Typ) loop
2317 Check_Common_Type (T, It2.Typ);
2318 Get_Next_Interp (I2, It2);
2321 end Check_High_Bound;
2323 -- Start of processing for Analyze_Range
2326 Set_Etype (N, Any_Type);
2327 Analyze_Expression (L);
2328 Analyze_Expression (H);
2330 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
2334 if not Is_Overloaded (L) then
2335 Check_High_Bound (Etype (L));
2337 Get_First_Interp (L, I1, It1);
2339 while Present (It1.Typ) loop
2340 Check_High_Bound (It1.Typ);
2341 Get_Next_Interp (I1, It1);
2345 -- If result is Any_Type, then we did not find a compatible pair
2347 if Etype (N) = Any_Type then
2348 Error_Msg_N ("incompatible types in range ", N);
2353 -----------------------
2354 -- Analyze_Reference --
2355 -----------------------
2357 procedure Analyze_Reference (N : Node_Id) is
2358 P : constant Node_Id := Prefix (N);
2359 Acc_Type : Entity_Id;
2363 Acc_Type := Create_Itype (E_Allocator_Type, N);
2364 Set_Etype (Acc_Type, Acc_Type);
2365 Init_Size_Align (Acc_Type);
2366 Set_Directly_Designated_Type (Acc_Type, Etype (P));
2367 Set_Etype (N, Acc_Type);
2368 end Analyze_Reference;
2370 --------------------------------
2371 -- Analyze_Selected_Component --
2372 --------------------------------
2374 -- Prefix is a record type or a task or protected type. In the
2375 -- later case, the selector must denote a visible entry.
2377 procedure Analyze_Selected_Component (N : Node_Id) is
2378 Name : constant Node_Id := Prefix (N);
2379 Sel : constant Node_Id := Selector_Name (N);
2381 Entity_List : Entity_Id;
2382 Prefix_Type : Entity_Id;
2387 -- Start of processing for Analyze_Selected_Component
2390 Set_Etype (N, Any_Type);
2392 if Is_Overloaded (Name) then
2393 Analyze_Overloaded_Selected_Component (N);
2396 elsif Etype (Name) = Any_Type then
2397 Set_Entity (Sel, Any_Id);
2398 Set_Etype (Sel, Any_Type);
2402 -- Function calls that are prefixes of selected components must be
2403 -- fully resolved in case we need to build an actual subtype, or
2404 -- do some other operation requiring a fully resolved prefix.
2406 -- Note: Resolving all Nkinds of nodes here doesn't work.
2407 -- (Breaks 2129-008) ???.
2409 if Nkind (Name) = N_Function_Call then
2410 Resolve (Name, Etype (Name));
2413 Prefix_Type := Etype (Name);
2416 if Is_Access_Type (Prefix_Type) then
2417 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
2418 and then Comes_From_Source (N)
2420 -- A RACW object can never be used as prefix of a selected
2421 -- component since that means it is dereferenced without
2422 -- being a controlling operand of a dispatching operation
2426 ("invalid dereference of a remote access to class-wide value",
2429 Prefix_Type := Designated_Type (Prefix_Type);
2432 if Ekind (Prefix_Type) = E_Private_Subtype then
2433 Prefix_Type := Base_Type (Prefix_Type);
2436 Entity_List := Prefix_Type;
2438 -- For class-wide types, use the entity list of the root type. This
2439 -- indirection is specially important for private extensions because
2440 -- only the root type get switched (not the class-wide type).
2442 if Is_Class_Wide_Type (Prefix_Type) then
2443 Entity_List := Root_Type (Prefix_Type);
2446 Comp := First_Entity (Entity_List);
2448 -- If the selector has an original discriminant, the node appears in
2449 -- an instance. Replace the discriminant with the corresponding one
2450 -- in the current discriminated type. For nested generics, this must
2451 -- be done transitively, so note the new original discriminant.
2453 if Nkind (Sel) = N_Identifier
2454 and then Present (Original_Discriminant (Sel))
2456 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
2458 -- Mark entity before rewriting, for completeness and because
2459 -- subsequent semantic checks might examine the original node.
2461 Set_Entity (Sel, Comp);
2462 Rewrite (Selector_Name (N),
2463 New_Occurrence_Of (Comp, Sloc (N)));
2464 Set_Original_Discriminant (Selector_Name (N), Comp);
2465 Set_Etype (N, Etype (Comp));
2467 if Is_Access_Type (Etype (Name)) then
2468 Insert_Explicit_Dereference (Name);
2471 elsif Is_Record_Type (Prefix_Type) then
2473 -- Find component with given name
2475 while Present (Comp) loop
2477 if Chars (Comp) = Chars (Sel)
2478 and then Is_Visible_Component (Comp)
2480 Set_Entity_With_Style_Check (Sel, Comp);
2481 Generate_Reference (Comp, Sel);
2483 Set_Etype (Sel, Etype (Comp));
2485 if Ekind (Comp) = E_Discriminant then
2486 if Is_Unchecked_Union (Prefix_Type) then
2488 ("cannot reference discriminant of Unchecked_Union",
2492 if Is_Generic_Type (Prefix_Type)
2494 Is_Generic_Type (Root_Type (Prefix_Type))
2496 Set_Original_Discriminant (Sel, Comp);
2500 -- Resolve the prefix early otherwise it is not possible to
2501 -- build the actual subtype of the component: it may need
2502 -- to duplicate this prefix and duplication is only allowed
2503 -- on fully resolved expressions.
2505 Resolve (Name, Etype (Name));
2507 -- We never need an actual subtype for the case of a selection
2508 -- for a indexed component of a non-packed array, since in
2509 -- this case gigi generates all the checks and can find the
2510 -- necessary bounds information.
2512 -- We also do not need an actual subtype for the case of
2513 -- a first, last, length, or range attribute applied to a
2514 -- non-packed array, since gigi can again get the bounds in
2515 -- these cases (gigi cannot handle the packed case, since it
2516 -- has the bounds of the packed array type, not the original
2517 -- bounds of the type). However, if the prefix is itself a
2518 -- selected component, as in a.b.c (i), gigi may regard a.b.c
2519 -- as a dynamic-sized temporary, so we do generate an actual
2520 -- subtype for this case.
2522 Parent_N := Parent (N);
2524 if not Is_Packed (Etype (Comp))
2526 ((Nkind (Parent_N) = N_Indexed_Component
2527 and then Nkind (Name) /= N_Selected_Component)
2529 (Nkind (Parent_N) = N_Attribute_Reference
2530 and then (Attribute_Name (Parent_N) = Name_First
2532 Attribute_Name (Parent_N) = Name_Last
2534 Attribute_Name (Parent_N) = Name_Length
2536 Attribute_Name (Parent_N) = Name_Range)))
2538 Set_Etype (N, Etype (Comp));
2540 -- In all other cases, we currently build an actual subtype. It
2541 -- seems likely that many of these cases can be avoided, but
2542 -- right now, the front end makes direct references to the
2543 -- bounds (e.g. in egnerating a length check), and if we do
2544 -- not make an actual subtype, we end up getting a direct
2545 -- reference to a discriminant which will not do.
2549 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
2550 Insert_Action (N, Act_Decl);
2552 if No (Act_Decl) then
2553 Set_Etype (N, Etype (Comp));
2556 -- Component type depends on discriminants. Enter the
2557 -- main attributes of the subtype.
2560 Subt : Entity_Id := Defining_Identifier (Act_Decl);
2563 Set_Etype (Subt, Base_Type (Etype (Comp)));
2564 Set_Ekind (Subt, Ekind (Etype (Comp)));
2565 Set_Etype (N, Subt);
2576 elsif Is_Private_Type (Prefix_Type) then
2578 -- Allow access only to discriminants of the type. If the
2579 -- type has no full view, gigi uses the parent type for
2580 -- the components, so we do the same here.
2582 if No (Full_View (Prefix_Type)) then
2583 Entity_List := Root_Type (Base_Type (Prefix_Type));
2584 Comp := First_Entity (Entity_List);
2587 while Present (Comp) loop
2589 if Chars (Comp) = Chars (Sel) then
2590 if Ekind (Comp) = E_Discriminant then
2591 Set_Entity_With_Style_Check (Sel, Comp);
2592 Generate_Reference (Comp, Sel);
2594 Set_Etype (Sel, Etype (Comp));
2595 Set_Etype (N, Etype (Comp));
2597 if Is_Generic_Type (Prefix_Type)
2599 Is_Generic_Type (Root_Type (Prefix_Type))
2601 Set_Original_Discriminant (Sel, Comp);
2606 ("invisible selector for }",
2607 N, First_Subtype (Prefix_Type));
2608 Set_Entity (Sel, Any_Id);
2609 Set_Etype (N, Any_Type);
2618 elsif Is_Concurrent_Type (Prefix_Type) then
2620 -- Prefix is concurrent type. Find visible operation with given name
2621 -- For a task, this can only include entries or discriminants if
2622 -- the task type is not an enclosing scope. If it is an enclosing
2623 -- scope (e.g. in an inner task) then all entities are visible, but
2624 -- the prefix must denote the enclosing scope, i.e. can only be
2625 -- a direct name or an expanded name.
2627 Set_Etype (Sel, Any_Type);
2628 In_Scope := In_Open_Scopes (Prefix_Type);
2630 while Present (Comp) loop
2631 if Chars (Comp) = Chars (Sel) then
2632 if Is_Overloadable (Comp) then
2633 Add_One_Interp (Sel, Comp, Etype (Comp));
2635 elsif Ekind (Comp) = E_Discriminant
2636 or else Ekind (Comp) = E_Entry_Family
2638 and then Is_Entity_Name (Name))
2640 Set_Entity_With_Style_Check (Sel, Comp);
2641 Generate_Reference (Comp, Sel);
2647 Set_Etype (Sel, Etype (Comp));
2648 Set_Etype (N, Etype (Comp));
2650 if Ekind (Comp) = E_Discriminant then
2651 Set_Original_Discriminant (Sel, Comp);
2654 -- For access type case, introduce explicit deference for
2655 -- more uniform treatment of entry calls.
2657 if Is_Access_Type (Etype (Name)) then
2658 Insert_Explicit_Dereference (Name);
2664 exit when not In_Scope
2665 and then Comp = First_Private_Entity (Prefix_Type);
2668 Set_Is_Overloaded (N, Is_Overloaded (Sel));
2673 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
2676 -- If N still has no type, the component is not defined in the prefix.
2678 if Etype (N) = Any_Type then
2680 -- If the prefix is a single concurrent object, use its name in
2681 -- the error message, rather than that of its anonymous type.
2683 if Is_Concurrent_Type (Prefix_Type)
2684 and then Is_Internal_Name (Chars (Prefix_Type))
2685 and then not Is_Derived_Type (Prefix_Type)
2686 and then Is_Entity_Name (Name)
2689 Error_Msg_Node_2 := Entity (Name);
2690 Error_Msg_NE ("no selector& for&", N, Sel);
2692 Check_Misspelled_Selector (Entity_List, Sel);
2695 if Ekind (Prefix_Type) = E_Record_Subtype then
2697 -- Check whether this is a component of the base type
2698 -- which is absent from a statically constrained subtype.
2699 -- This will raise constraint error at run-time, but is
2700 -- not a compile-time error. When the selector is illegal
2701 -- for base type as well fall through and generate a
2702 -- compilation error anyway.
2704 Comp := First_Component (Base_Type (Prefix_Type));
2706 while Present (Comp) loop
2708 if Chars (Comp) = Chars (Sel)
2709 and then Is_Visible_Component (Comp)
2711 Set_Entity_With_Style_Check (Sel, Comp);
2712 Generate_Reference (Comp, Sel);
2713 Set_Etype (Sel, Etype (Comp));
2714 Set_Etype (N, Etype (Comp));
2716 -- Emit appropriate message. Gigi will replace the
2717 -- node subsequently with the appropriate Raise.
2719 Apply_Compile_Time_Constraint_Error
2720 (N, "component not present in }?",
2721 Ent => Prefix_Type, Rep => False);
2722 Set_Raises_Constraint_Error (N);
2726 Next_Component (Comp);
2731 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
2732 Error_Msg_NE ("no selector& for}", N, Sel);
2734 Check_Misspelled_Selector (Entity_List, Sel);
2738 Set_Entity (Sel, Any_Id);
2739 Set_Etype (Sel, Any_Type);
2741 end Analyze_Selected_Component;
2743 ---------------------------
2744 -- Analyze_Short_Circuit --
2745 ---------------------------
2747 procedure Analyze_Short_Circuit (N : Node_Id) is
2748 L : constant Node_Id := Left_Opnd (N);
2749 R : constant Node_Id := Right_Opnd (N);
2754 Analyze_Expression (L);
2755 Analyze_Expression (R);
2756 Set_Etype (N, Any_Type);
2758 if not Is_Overloaded (L) then
2760 if Root_Type (Etype (L)) = Standard_Boolean
2761 and then Has_Compatible_Type (R, Etype (L))
2763 Add_One_Interp (N, Etype (L), Etype (L));
2767 Get_First_Interp (L, Ind, It);
2769 while Present (It.Typ) loop
2770 if Root_Type (It.Typ) = Standard_Boolean
2771 and then Has_Compatible_Type (R, It.Typ)
2773 Add_One_Interp (N, It.Typ, It.Typ);
2776 Get_Next_Interp (Ind, It);
2780 -- Here we have failed to find an interpretation. Clearly we
2781 -- know that it is not the case that both operands can have
2782 -- an interpretation of Boolean, but this is by far the most
2783 -- likely intended interpretation. So we simply resolve both
2784 -- operands as Booleans, and at least one of these resolutions
2785 -- will generate an error message, and we do not need to give
2786 -- a further error message on the short circuit operation itself.
2788 if Etype (N) = Any_Type then
2789 Resolve (L, Standard_Boolean);
2790 Resolve (R, Standard_Boolean);
2791 Set_Etype (N, Standard_Boolean);
2793 end Analyze_Short_Circuit;
2799 procedure Analyze_Slice (N : Node_Id) is
2800 P : constant Node_Id := Prefix (N);
2801 D : constant Node_Id := Discrete_Range (N);
2802 Array_Type : Entity_Id;
2804 procedure Analyze_Overloaded_Slice;
2805 -- If the prefix is overloaded, select those interpretations that
2806 -- yield a one-dimensional array type.
2808 procedure Analyze_Overloaded_Slice is
2814 Set_Etype (N, Any_Type);
2815 Get_First_Interp (P, I, It);
2817 while Present (It.Nam) loop
2820 if Is_Access_Type (Typ) then
2821 Typ := Designated_Type (Typ);
2824 if Is_Array_Type (Typ)
2825 and then Number_Dimensions (Typ) = 1
2826 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
2828 Add_One_Interp (N, Typ, Typ);
2831 Get_Next_Interp (I, It);
2834 if Etype (N) = Any_Type then
2835 Error_Msg_N ("expect array type in prefix of slice", N);
2837 end Analyze_Overloaded_Slice;
2839 -- Start of processing for Analyze_Slice
2842 -- Analyze the prefix if not done already
2844 if No (Etype (P)) then
2850 if Is_Overloaded (P) then
2851 Analyze_Overloaded_Slice;
2854 Array_Type := Etype (P);
2855 Set_Etype (N, Any_Type);
2857 if Is_Access_Type (Array_Type) then
2858 Array_Type := Designated_Type (Array_Type);
2861 if not Is_Array_Type (Array_Type) then
2862 Wrong_Type (P, Any_Array);
2864 elsif Number_Dimensions (Array_Type) > 1 then
2866 ("type is not one-dimensional array in slice prefix", N);
2869 Has_Compatible_Type (D, Etype (First_Index (Array_Type)))
2871 Wrong_Type (D, Etype (First_Index (Array_Type)));
2874 Set_Etype (N, Array_Type);
2879 -----------------------------
2880 -- Analyze_Type_Conversion --
2881 -----------------------------
2883 procedure Analyze_Type_Conversion (N : Node_Id) is
2884 Expr : constant Node_Id := Expression (N);
2888 -- If Conversion_OK is set, then the Etype is already set, and the
2889 -- only processing required is to analyze the expression. This is
2890 -- used to construct certain "illegal" conversions which are not
2891 -- allowed by Ada semantics, but can be handled OK by Gigi, see
2892 -- Sinfo for further details.
2894 if Conversion_OK (N) then
2899 -- Otherwise full type analysis is required, as well as some semantic
2900 -- checks to make sure the argument of the conversion is appropriate.
2902 Find_Type (Subtype_Mark (N));
2903 T := Entity (Subtype_Mark (N));
2905 Check_Fully_Declared (T, N);
2906 Analyze_Expression (Expr);
2907 Validate_Remote_Type_Type_Conversion (N);
2909 -- Only remaining step is validity checks on the argument. These
2910 -- are skipped if the conversion does not come from the source.
2912 if not Comes_From_Source (N) then
2915 elsif Nkind (Expr) = N_Null then
2916 Error_Msg_N ("argument of conversion cannot be null", N);
2917 Error_Msg_N ("\use qualified expression instead", N);
2918 Set_Etype (N, Any_Type);
2920 elsif Nkind (Expr) = N_Aggregate then
2921 Error_Msg_N ("argument of conversion cannot be aggregate", N);
2922 Error_Msg_N ("\use qualified expression instead", N);
2924 elsif Nkind (Expr) = N_Allocator then
2925 Error_Msg_N ("argument of conversion cannot be an allocator", N);
2926 Error_Msg_N ("\use qualified expression instead", N);
2928 elsif Nkind (Expr) = N_String_Literal then
2929 Error_Msg_N ("argument of conversion cannot be string literal", N);
2930 Error_Msg_N ("\use qualified expression instead", N);
2932 elsif Nkind (Expr) = N_Character_Literal then
2936 Error_Msg_N ("argument of conversion cannot be character literal",
2938 Error_Msg_N ("\use qualified expression instead", N);
2941 elsif Nkind (Expr) = N_Attribute_Reference
2943 (Attribute_Name (Expr) = Name_Access or else
2944 Attribute_Name (Expr) = Name_Unchecked_Access or else
2945 Attribute_Name (Expr) = Name_Unrestricted_Access)
2947 Error_Msg_N ("argument of conversion cannot be access", N);
2948 Error_Msg_N ("\use qualified expression instead", N);
2951 end Analyze_Type_Conversion;
2953 ----------------------
2954 -- Analyze_Unary_Op --
2955 ----------------------
2957 procedure Analyze_Unary_Op (N : Node_Id) is
2958 R : constant Node_Id := Right_Opnd (N);
2959 Op_Id : Entity_Id := Entity (N);
2962 Set_Etype (N, Any_Type);
2963 Candidate_Type := Empty;
2965 Analyze_Expression (R);
2967 if Present (Op_Id) then
2968 if Ekind (Op_Id) = E_Operator then
2969 Find_Unary_Types (R, Op_Id, N);
2971 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2975 Op_Id := Get_Name_Entity_Id (Chars (N));
2977 while Present (Op_Id) loop
2979 if Ekind (Op_Id) = E_Operator then
2980 if No (Next_Entity (First_Entity (Op_Id))) then
2981 Find_Unary_Types (R, Op_Id, N);
2984 elsif Is_Overloadable (Op_Id) then
2985 Analyze_User_Defined_Unary_Op (N, Op_Id);
2988 Op_Id := Homonym (Op_Id);
2993 end Analyze_Unary_Op;
2995 ----------------------------------
2996 -- Analyze_Unchecked_Expression --
2997 ----------------------------------
2999 procedure Analyze_Unchecked_Expression (N : Node_Id) is
3001 Analyze (Expression (N), Suppress => All_Checks);
3002 Set_Etype (N, Etype (Expression (N)));
3003 Save_Interps (Expression (N), N);
3004 end Analyze_Unchecked_Expression;
3006 ---------------------------------------
3007 -- Analyze_Unchecked_Type_Conversion --
3008 ---------------------------------------
3010 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
3012 Find_Type (Subtype_Mark (N));
3013 Analyze_Expression (Expression (N));
3014 Set_Etype (N, Entity (Subtype_Mark (N)));
3015 end Analyze_Unchecked_Type_Conversion;
3017 ------------------------------------
3018 -- Analyze_User_Defined_Binary_Op --
3019 ------------------------------------
3021 procedure Analyze_User_Defined_Binary_Op
3026 -- Only do analysis if the operator Comes_From_Source, since otherwise
3027 -- the operator was generated by the expander, and all such operators
3028 -- always refer to the operators in package Standard.
3030 if Comes_From_Source (N) then
3032 F1 : constant Entity_Id := First_Formal (Op_Id);
3033 F2 : constant Entity_Id := Next_Formal (F1);
3036 -- Verify that Op_Id is a visible binary function. Note that since
3037 -- we know Op_Id is overloaded, potentially use visible means use
3038 -- visible for sure (RM 9.4(11)).
3040 if Ekind (Op_Id) = E_Function
3041 and then Present (F2)
3042 and then (Is_Immediately_Visible (Op_Id)
3043 or else Is_Potentially_Use_Visible (Op_Id))
3044 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
3045 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
3047 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3049 if Debug_Flag_E then
3050 Write_Str ("user defined operator ");
3051 Write_Name (Chars (Op_Id));
3052 Write_Str (" on node ");
3053 Write_Int (Int (N));
3059 end Analyze_User_Defined_Binary_Op;
3061 -----------------------------------
3062 -- Analyze_User_Defined_Unary_Op --
3063 -----------------------------------
3065 procedure Analyze_User_Defined_Unary_Op
3070 -- Only do analysis if the operator Comes_From_Source, since otherwise
3071 -- the operator was generated by the expander, and all such operators
3072 -- always refer to the operators in package Standard.
3074 if Comes_From_Source (N) then
3076 F : constant Entity_Id := First_Formal (Op_Id);
3079 -- Verify that Op_Id is a visible unary function. Note that since
3080 -- we know Op_Id is overloaded, potentially use visible means use
3081 -- visible for sure (RM 9.4(11)).
3083 if Ekind (Op_Id) = E_Function
3084 and then No (Next_Formal (F))
3085 and then (Is_Immediately_Visible (Op_Id)
3086 or else Is_Potentially_Use_Visible (Op_Id))
3087 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
3089 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3093 end Analyze_User_Defined_Unary_Op;
3095 ---------------------------
3096 -- Check_Arithmetic_Pair --
3097 ---------------------------
3099 procedure Check_Arithmetic_Pair
3100 (T1, T2 : Entity_Id;
3104 Op_Name : constant Name_Id := Chars (Op_Id);
3106 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
3107 -- Get specific type (i.e. non-universal type if there is one)
3109 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
3111 if T1 = Universal_Integer or else T1 = Universal_Real then
3112 return Base_Type (T2);
3114 return Base_Type (T1);
3118 -- Start of processing for Check_Arithmetic_Pair
3121 if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
3123 if Is_Numeric_Type (T1)
3124 and then Is_Numeric_Type (T2)
3125 and then (Covers (T1, T2) or else Covers (T2, T1))
3127 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3130 elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
3132 if Is_Fixed_Point_Type (T1)
3133 and then (Is_Fixed_Point_Type (T2)
3134 or else T2 = Universal_Real)
3136 -- If Treat_Fixed_As_Integer is set then the Etype is already set
3137 -- and no further processing is required (this is the case of an
3138 -- operator constructed by Exp_Fixd for a fixed point operation)
3139 -- Otherwise add one interpretation with universal fixed result
3140 -- If the operator is given in functional notation, it comes
3141 -- from source and Fixed_As_Integer cannot apply.
3143 if Nkind (N) not in N_Op
3144 or else not Treat_Fixed_As_Integer (N) then
3145 Add_One_Interp (N, Op_Id, Universal_Fixed);
3148 elsif Is_Fixed_Point_Type (T2)
3149 and then (Nkind (N) not in N_Op
3150 or else not Treat_Fixed_As_Integer (N))
3151 and then T1 = Universal_Real
3153 Add_One_Interp (N, Op_Id, Universal_Fixed);
3155 elsif Is_Numeric_Type (T1)
3156 and then Is_Numeric_Type (T2)
3157 and then (Covers (T1, T2) or else Covers (T2, T1))
3159 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3161 elsif Is_Fixed_Point_Type (T1)
3162 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3163 or else T2 = Universal_Integer)
3165 Add_One_Interp (N, Op_Id, T1);
3167 elsif T2 = Universal_Real
3168 and then Base_Type (T1) = Base_Type (Standard_Integer)
3169 and then Op_Name = Name_Op_Multiply
3171 Add_One_Interp (N, Op_Id, Any_Fixed);
3173 elsif T1 = Universal_Real
3174 and then Base_Type (T2) = Base_Type (Standard_Integer)
3176 Add_One_Interp (N, Op_Id, Any_Fixed);
3178 elsif Is_Fixed_Point_Type (T2)
3179 and then (Base_Type (T1) = Base_Type (Standard_Integer)
3180 or else T1 = Universal_Integer)
3181 and then Op_Name = Name_Op_Multiply
3183 Add_One_Interp (N, Op_Id, T2);
3185 elsif T1 = Universal_Real and then T2 = Universal_Integer then
3186 Add_One_Interp (N, Op_Id, T1);
3188 elsif T2 = Universal_Real
3189 and then T1 = Universal_Integer
3190 and then Op_Name = Name_Op_Multiply
3192 Add_One_Interp (N, Op_Id, T2);
3195 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
3197 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
3198 -- set does not require any special processing, since the Etype is
3199 -- already set (case of operation constructed by Exp_Fixed).
3201 if Is_Integer_Type (T1)
3202 and then (Covers (T1, T2) or else Covers (T2, T1))
3204 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3207 elsif Op_Name = Name_Op_Expon then
3209 if Is_Numeric_Type (T1)
3210 and then not Is_Fixed_Point_Type (T1)
3211 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3212 or else T2 = Universal_Integer)
3214 Add_One_Interp (N, Op_Id, Base_Type (T1));
3217 else pragma Assert (Nkind (N) in N_Op_Shift);
3219 -- If not one of the predefined operators, the node may be one
3220 -- of the intrinsic functions. Its kind is always specific, and
3221 -- we can use it directly, rather than the name of the operation.
3223 if Is_Integer_Type (T1)
3224 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3225 or else T2 = Universal_Integer)
3227 Add_One_Interp (N, Op_Id, Base_Type (T1));
3230 end Check_Arithmetic_Pair;
3232 -------------------------------
3233 -- Check_Misspelled_Selector --
3234 -------------------------------
3236 procedure Check_Misspelled_Selector
3237 (Prefix : Entity_Id;
3240 Max_Suggestions : constant := 2;
3241 Nr_Of_Suggestions : Natural := 0;
3243 Suggestion_1 : Entity_Id := Empty;
3244 Suggestion_2 : Entity_Id := Empty;
3249 -- All the components of the prefix of selector Sel are matched
3250 -- against Sel and a count is maintained of possible misspellings.
3251 -- When at the end of the analysis there are one or two (not more!)
3252 -- possible misspellings, these misspellings will be suggested as
3253 -- possible correction.
3255 if not (Is_Private_Type (Prefix) or Is_Record_Type (Prefix)) then
3256 -- Concurrent types should be handled as well ???
3260 Get_Name_String (Chars (Sel));
3263 S : constant String (1 .. Name_Len) :=
3264 Name_Buffer (1 .. Name_Len);
3267 Comp := First_Entity (Prefix);
3269 while Nr_Of_Suggestions <= Max_Suggestions
3270 and then Present (Comp)
3273 if Is_Visible_Component (Comp) then
3274 Get_Name_String (Chars (Comp));
3276 if Is_Bad_Spelling_Of (Name_Buffer (1 .. Name_Len), S) then
3277 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
3279 case Nr_Of_Suggestions is
3280 when 1 => Suggestion_1 := Comp;
3281 when 2 => Suggestion_2 := Comp;
3282 when others => exit;
3287 Comp := Next_Entity (Comp);
3290 -- Report at most two suggestions
3292 if Nr_Of_Suggestions = 1 then
3293 Error_Msg_NE ("\possible misspelling of&", Sel, Suggestion_1);
3295 elsif Nr_Of_Suggestions = 2 then
3296 Error_Msg_Node_2 := Suggestion_2;
3297 Error_Msg_NE ("\possible misspelling of& or&",
3301 end Check_Misspelled_Selector;
3303 ----------------------
3304 -- Defined_In_Scope --
3305 ----------------------
3307 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
3309 S1 : constant Entity_Id := Scope (Base_Type (T));
3313 or else (S1 = System_Aux_Id and then S = Scope (S1));
3314 end Defined_In_Scope;
3320 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
3327 if Extensions_Allowed then
3328 Actual := First_Actual (N);
3330 while Present (Actual) loop
3331 if not Analyzed (Etype (Actual))
3332 and then From_With_Type (Etype (Actual))
3334 Error_Msg_Qual_Level := 1;
3336 ("missing with_clause for scope of imported type&",
3337 Actual, Etype (Actual));
3338 Error_Msg_Qual_Level := 0;
3341 Next_Actual (Actual);
3345 if All_Errors_Mode then
3347 -- Analyze each candidate call again, with full error reporting
3350 Error_Msg_N ("\no candidate interpretations "
3351 & "match the actuals:!", Nam);
3353 Get_First_Interp (Nam, X, It);
3355 while Present (It.Nam) loop
3356 Analyze_One_Call (N, It.Nam, True, Success);
3357 Get_Next_Interp (X, It);
3363 ("invalid parameter list in call " &
3364 "('/'R'E'P'O'R'T'_'E'R'R'O'R'S'='F'U'L'L for details)!",
3368 ("invalid parameter list in call (use -gnatf for details)!",
3373 if Nkind (N) = N_Function_Call then
3374 Get_First_Interp (Nam, X, It);
3376 while Present (It.Nam) loop
3377 if Ekind (It.Nam) = E_Function
3378 or else Ekind (It.Nam) = E_Operator
3382 Get_Next_Interp (X, It);
3386 -- If all interpretations are procedures, this deserves a
3387 -- more precise message. Ditto if this appears as the prefix
3388 -- of a selected component, which may be a lexical error.
3391 "\context requires function call, found procedure name", Nam);
3393 if Nkind (Parent (N)) = N_Selected_Component
3394 and then N = Prefix (Parent (N))
3397 "\period should probably be semicolon", Parent (N));
3402 ---------------------------
3403 -- Find_Arithmetic_Types --
3404 ---------------------------
3406 procedure Find_Arithmetic_Types
3411 Index1, Index2 : Interp_Index;
3414 procedure Check_Right_Argument (T : Entity_Id);
3415 -- Check right operand of operator
3417 procedure Check_Right_Argument (T : Entity_Id) is
3419 if not Is_Overloaded (R) then
3420 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
3422 Get_First_Interp (R, Index2, It2);
3424 while Present (It2.Typ) loop
3425 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
3426 Get_Next_Interp (Index2, It2);
3429 end Check_Right_Argument;
3431 -- Start processing for Find_Arithmetic_Types
3434 if not Is_Overloaded (L) then
3435 Check_Right_Argument (Etype (L));
3438 Get_First_Interp (L, Index1, It1);
3440 while Present (It1.Typ) loop
3441 Check_Right_Argument (It1.Typ);
3442 Get_Next_Interp (Index1, It1);
3446 end Find_Arithmetic_Types;
3448 ------------------------
3449 -- Find_Boolean_Types --
3450 ------------------------
3452 procedure Find_Boolean_Types
3457 Index : Interp_Index;
3460 procedure Check_Numeric_Argument (T : Entity_Id);
3461 -- Special case for logical operations one of whose operands is an
3462 -- integer literal. If both are literal the result is any modular type.
3464 procedure Check_Numeric_Argument (T : Entity_Id) is
3466 if T = Universal_Integer then
3467 Add_One_Interp (N, Op_Id, Any_Modular);
3469 elsif Is_Modular_Integer_Type (T) then
3470 Add_One_Interp (N, Op_Id, T);
3472 end Check_Numeric_Argument;
3474 -- Start of processing for Find_Boolean_Types
3477 if not Is_Overloaded (L) then
3479 if Etype (L) = Universal_Integer
3480 or else Etype (L) = Any_Modular
3482 if not Is_Overloaded (R) then
3483 Check_Numeric_Argument (Etype (R));
3486 Get_First_Interp (R, Index, It);
3488 while Present (It.Typ) loop
3489 Check_Numeric_Argument (It.Typ);
3491 Get_Next_Interp (Index, It);
3495 elsif Valid_Boolean_Arg (Etype (L))
3496 and then Has_Compatible_Type (R, Etype (L))
3498 Add_One_Interp (N, Op_Id, Etype (L));
3502 Get_First_Interp (L, Index, It);
3504 while Present (It.Typ) loop
3505 if Valid_Boolean_Arg (It.Typ)
3506 and then Has_Compatible_Type (R, It.Typ)
3508 Add_One_Interp (N, Op_Id, It.Typ);
3511 Get_Next_Interp (Index, It);
3514 end Find_Boolean_Types;
3516 ---------------------------
3517 -- Find_Comparison_Types --
3518 ---------------------------
3520 procedure Find_Comparison_Types
3525 Index : Interp_Index;
3527 Found : Boolean := False;
3530 Scop : Entity_Id := Empty;
3532 procedure Try_One_Interp (T1 : Entity_Id);
3533 -- Routine to try one proposed interpretation. Note that the context
3534 -- of the operator plays no role in resolving the arguments, so that
3535 -- if there is more than one interpretation of the operands that is
3536 -- compatible with comparison, the operation is ambiguous.
3538 procedure Try_One_Interp (T1 : Entity_Id) is
3541 -- If the operator is an expanded name, then the type of the operand
3542 -- must be defined in the corresponding scope. If the type is
3543 -- universal, the context will impose the correct type.
3546 and then not Defined_In_Scope (T1, Scop)
3547 and then T1 /= Universal_Integer
3548 and then T1 /= Universal_Real
3549 and then T1 /= Any_String
3550 and then T1 /= Any_Composite
3555 if Valid_Comparison_Arg (T1)
3556 and then Has_Compatible_Type (R, T1)
3559 and then Base_Type (T1) /= Base_Type (T_F)
3561 It := Disambiguate (L, I_F, Index, Any_Type);
3563 if It = No_Interp then
3564 Ambiguous_Operands (N);
3565 Set_Etype (L, Any_Type);
3579 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
3584 -- Start processing for Find_Comparison_Types
3588 if Nkind (N) = N_Function_Call
3589 and then Nkind (Name (N)) = N_Expanded_Name
3591 Scop := Entity (Prefix (Name (N)));
3593 -- The prefix may be a package renaming, and the subsequent test
3594 -- requires the original package.
3596 if Ekind (Scop) = E_Package
3597 and then Present (Renamed_Entity (Scop))
3599 Scop := Renamed_Entity (Scop);
3600 Set_Entity (Prefix (Name (N)), Scop);
3604 if not Is_Overloaded (L) then
3605 Try_One_Interp (Etype (L));
3608 Get_First_Interp (L, Index, It);
3610 while Present (It.Typ) loop
3611 Try_One_Interp (It.Typ);
3612 Get_Next_Interp (Index, It);
3615 end Find_Comparison_Types;
3617 ----------------------------------------
3618 -- Find_Non_Universal_Interpretations --
3619 ----------------------------------------
3621 procedure Find_Non_Universal_Interpretations
3627 Index : Interp_Index;
3631 if T1 = Universal_Integer
3632 or else T1 = Universal_Real
3634 if not Is_Overloaded (R) then
3636 (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
3638 Get_First_Interp (R, Index, It);
3640 while Present (It.Typ) loop
3641 if Covers (It.Typ, T1) then
3643 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
3646 Get_Next_Interp (Index, It);
3650 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
3652 end Find_Non_Universal_Interpretations;
3654 ------------------------------
3655 -- Find_Concatenation_Types --
3656 ------------------------------
3658 procedure Find_Concatenation_Types
3663 Op_Type : constant Entity_Id := Etype (Op_Id);
3666 if Is_Array_Type (Op_Type)
3667 and then not Is_Limited_Type (Op_Type)
3669 and then (Has_Compatible_Type (L, Op_Type)
3671 Has_Compatible_Type (L, Component_Type (Op_Type)))
3673 and then (Has_Compatible_Type (R, Op_Type)
3675 Has_Compatible_Type (R, Component_Type (Op_Type)))
3677 Add_One_Interp (N, Op_Id, Op_Type);
3679 end Find_Concatenation_Types;
3681 -------------------------
3682 -- Find_Equality_Types --
3683 -------------------------
3685 procedure Find_Equality_Types
3690 Index : Interp_Index;
3692 Found : Boolean := False;
3695 Scop : Entity_Id := Empty;
3697 procedure Try_One_Interp (T1 : Entity_Id);
3698 -- The context of the operator plays no role in resolving the
3699 -- arguments, so that if there is more than one interpretation
3700 -- of the operands that is compatible with equality, the construct
3701 -- is ambiguous and an error can be emitted now, after trying to
3702 -- disambiguate, i.e. applying preference rules.
3704 procedure Try_One_Interp (T1 : Entity_Id) is
3707 -- If the operator is an expanded name, then the type of the operand
3708 -- must be defined in the corresponding scope. If the type is
3709 -- universal, the context will impose the correct type. An anonymous
3710 -- type for a 'Access reference is also universal in this sense, as
3711 -- the actual type is obtained from context.
3714 and then not Defined_In_Scope (T1, Scop)
3715 and then T1 /= Universal_Integer
3716 and then T1 /= Universal_Real
3717 and then T1 /= Any_Access
3718 and then T1 /= Any_String
3719 and then T1 /= Any_Composite
3720 and then (Ekind (T1) /= E_Access_Subprogram_Type
3721 or else Comes_From_Source (T1))
3726 if T1 /= Standard_Void_Type
3727 and then not Is_Limited_Type (T1)
3728 and then not Is_Limited_Composite (T1)
3729 and then Ekind (T1) /= E_Anonymous_Access_Type
3730 and then Has_Compatible_Type (R, T1)
3733 and then Base_Type (T1) /= Base_Type (T_F)
3735 It := Disambiguate (L, I_F, Index, Any_Type);
3737 if It = No_Interp then
3738 Ambiguous_Operands (N);
3739 Set_Etype (L, Any_Type);
3752 if not Analyzed (L) then
3756 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
3758 if Etype (N) = Any_Type then
3760 -- Operator was not visible.
3767 -- Start of processing for Find_Equality_Types
3771 if Nkind (N) = N_Function_Call
3772 and then Nkind (Name (N)) = N_Expanded_Name
3774 Scop := Entity (Prefix (Name (N)));
3776 -- The prefix may be a package renaming, and the subsequent test
3777 -- requires the original package.
3779 if Ekind (Scop) = E_Package
3780 and then Present (Renamed_Entity (Scop))
3782 Scop := Renamed_Entity (Scop);
3783 Set_Entity (Prefix (Name (N)), Scop);
3787 if not Is_Overloaded (L) then
3788 Try_One_Interp (Etype (L));
3791 Get_First_Interp (L, Index, It);
3793 while Present (It.Typ) loop
3794 Try_One_Interp (It.Typ);
3795 Get_Next_Interp (Index, It);
3798 end Find_Equality_Types;
3800 -------------------------
3801 -- Find_Negation_Types --
3802 -------------------------
3804 procedure Find_Negation_Types
3809 Index : Interp_Index;
3813 if not Is_Overloaded (R) then
3815 if Etype (R) = Universal_Integer then
3816 Add_One_Interp (N, Op_Id, Any_Modular);
3818 elsif Valid_Boolean_Arg (Etype (R)) then
3819 Add_One_Interp (N, Op_Id, Etype (R));
3823 Get_First_Interp (R, Index, It);
3825 while Present (It.Typ) loop
3826 if Valid_Boolean_Arg (It.Typ) then
3827 Add_One_Interp (N, Op_Id, It.Typ);
3830 Get_Next_Interp (Index, It);
3833 end Find_Negation_Types;
3835 ----------------------
3836 -- Find_Unary_Types --
3837 ----------------------
3839 procedure Find_Unary_Types
3844 Index : Interp_Index;
3848 if not Is_Overloaded (R) then
3849 if Is_Numeric_Type (Etype (R)) then
3850 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
3854 Get_First_Interp (R, Index, It);
3856 while Present (It.Typ) loop
3857 if Is_Numeric_Type (It.Typ) then
3858 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
3861 Get_Next_Interp (Index, It);
3864 end Find_Unary_Types;
3866 ---------------------------------
3867 -- Insert_Explicit_Dereference --
3868 ---------------------------------
3870 procedure Insert_Explicit_Dereference (N : Node_Id) is
3871 New_Prefix : Node_Id := Relocate_Node (N);
3877 Save_Interps (N, New_Prefix);
3879 Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
3881 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
3883 if Is_Overloaded (New_Prefix) then
3885 -- The deference is also overloaded, and its interpretations are the
3886 -- designated types of the interpretations of the original node.
3888 Set_Is_Overloaded (N);
3889 Get_First_Interp (New_Prefix, I, It);
3891 while Present (It.Nam) loop
3894 if Is_Access_Type (T) then
3895 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
3898 Get_Next_Interp (I, It);
3904 end Insert_Explicit_Dereference;
3910 function Junk_Operand (N : Node_Id) return Boolean is
3914 if Error_Posted (N) then
3918 -- Get entity to be tested
3920 if Is_Entity_Name (N)
3921 and then Present (Entity (N))
3925 -- An odd case, a procedure name gets converted to a very peculiar
3926 -- function call, and here is where we detect this happening.
3928 elsif Nkind (N) = N_Function_Call
3929 and then Is_Entity_Name (Name (N))
3930 and then Present (Entity (Name (N)))
3934 -- Another odd case, there are at least some cases of selected
3935 -- components where the selected component is not marked as having
3936 -- an entity, even though the selector does have an entity
3938 elsif Nkind (N) = N_Selected_Component
3939 and then Present (Entity (Selector_Name (N)))
3941 Enode := Selector_Name (N);
3947 -- Now test the entity we got to see if it a bad case
3949 case Ekind (Entity (Enode)) is
3953 ("package name cannot be used as operand", Enode);
3955 when Generic_Unit_Kind =>
3957 ("generic unit name cannot be used as operand", Enode);
3961 ("subtype name cannot be used as operand", Enode);
3965 ("entry name cannot be used as operand", Enode);
3969 ("procedure name cannot be used as operand", Enode);
3973 ("exception name cannot be used as operand", Enode);
3975 when E_Block | E_Label | E_Loop =>
3977 ("label name cannot be used as operand", Enode);
3987 --------------------
3988 -- Operator_Check --
3989 --------------------
3991 procedure Operator_Check (N : Node_Id) is
3993 -- Test for case of no interpretation found for operator
3995 if Etype (N) = Any_Type then
4001 R := Right_Opnd (N);
4003 if Nkind (N) in N_Binary_Op then
4009 -- If either operand has no type, then don't complain further,
4010 -- since this simply means that we have a propragated error.
4013 or else Etype (R) = Any_Type
4014 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
4018 -- We explicitly check for the case of concatenation of
4019 -- component with component to avoid reporting spurious
4020 -- matching array types that might happen to be lurking
4021 -- in distant packages (such as run-time packages). This
4022 -- also prevents inconsistencies in the messages for certain
4023 -- ACVC B tests, which can vary depending on types declared
4024 -- in run-time interfaces. A further improvement, when
4025 -- aggregates are present, is to look for a well-typed operand.
4027 elsif Present (Candidate_Type)
4028 and then (Nkind (N) /= N_Op_Concat
4029 or else Is_Array_Type (Etype (L))
4030 or else Is_Array_Type (Etype (R)))
4033 if Nkind (N) = N_Op_Concat then
4034 if Etype (L) /= Any_Composite
4035 and then Is_Array_Type (Etype (L))
4037 Candidate_Type := Etype (L);
4039 elsif Etype (R) /= Any_Composite
4040 and then Is_Array_Type (Etype (R))
4042 Candidate_Type := Etype (R);
4047 ("operator for} is not directly visible!",
4048 N, First_Subtype (Candidate_Type));
4049 Error_Msg_N ("use clause would make operation legal!", N);
4052 -- If either operand is a junk operand (e.g. package name), then
4053 -- post appropriate error messages, but do not complain further.
4055 -- Note that the use of OR in this test instead of OR ELSE
4056 -- is quite deliberate, we may as well check both operands
4057 -- in the binary operator case.
4059 elsif Junk_Operand (R)
4060 or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
4064 -- If we have a logical operator, one of whose operands is
4065 -- Boolean, then we know that the other operand cannot resolve
4066 -- to Boolean (since we got no interpretations), but in that
4067 -- case we pretty much know that the other operand should be
4068 -- Boolean, so resolve it that way (generating an error)
4070 elsif Nkind (N) = N_Op_And
4074 Nkind (N) = N_Op_Xor
4076 if Etype (L) = Standard_Boolean then
4077 Resolve (R, Standard_Boolean);
4079 elsif Etype (R) = Standard_Boolean then
4080 Resolve (L, Standard_Boolean);
4084 -- For an arithmetic operator or comparison operator, if one
4085 -- of the operands is numeric, then we know the other operand
4086 -- is not the same numeric type. If it is a non-numeric type,
4087 -- then probably it is intended to match the other operand.
4089 elsif Nkind (N) = N_Op_Add or else
4090 Nkind (N) = N_Op_Divide or else
4091 Nkind (N) = N_Op_Ge or else
4092 Nkind (N) = N_Op_Gt or else
4093 Nkind (N) = N_Op_Le or else
4094 Nkind (N) = N_Op_Lt or else
4095 Nkind (N) = N_Op_Mod or else
4096 Nkind (N) = N_Op_Multiply or else
4097 Nkind (N) = N_Op_Rem or else
4098 Nkind (N) = N_Op_Subtract
4100 if Is_Numeric_Type (Etype (L))
4101 and then not Is_Numeric_Type (Etype (R))
4103 Resolve (R, Etype (L));
4106 elsif Is_Numeric_Type (Etype (R))
4107 and then not Is_Numeric_Type (Etype (L))
4109 Resolve (L, Etype (R));
4113 -- Comparisons on A'Access are common enough to deserve a
4116 elsif (Nkind (N) = N_Op_Eq or else
4117 Nkind (N) = N_Op_Ne)
4118 and then Ekind (Etype (L)) = E_Access_Attribute_Type
4119 and then Ekind (Etype (R)) = E_Access_Attribute_Type
4122 ("two access attributes cannot be compared directly", N);
4124 ("\they must be converted to an explicit type for comparison",
4128 -- Another one for C programmers
4130 elsif Nkind (N) = N_Op_Concat
4131 and then Valid_Boolean_Arg (Etype (L))
4132 and then Valid_Boolean_Arg (Etype (R))
4134 Error_Msg_N ("invalid operands for concatenation", N);
4135 Error_Msg_N ("\maybe AND was meant", N);
4138 -- A special case for comparison of access parameter with null
4140 elsif Nkind (N) = N_Op_Eq
4141 and then Is_Entity_Name (L)
4142 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
4143 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
4145 and then Nkind (R) = N_Null
4147 Error_Msg_N ("access parameter is not allowed to be null", L);
4148 Error_Msg_N ("\(call would raise Constraint_Error)", L);
4152 -- If we fall through then just give general message. Note
4153 -- that in the following messages, if the operand is overloaded
4154 -- we choose an arbitrary type to complain about, but that is
4155 -- probably more useful than not giving a type at all.
4157 if Nkind (N) in N_Unary_Op then
4158 Error_Msg_Node_2 := Etype (R);
4159 Error_Msg_N ("operator& not defined for}", N);
4163 Error_Msg_N ("invalid operand types for operator&", N);
4165 if Nkind (N) in N_Binary_Op
4166 and then Nkind (N) /= N_Op_Concat
4168 Error_Msg_NE ("\left operand has}!", N, Etype (L));
4169 Error_Msg_NE ("\right operand has}!", N, Etype (R));
4176 -----------------------
4177 -- Try_Indirect_Call --
4178 -----------------------
4180 function Try_Indirect_Call
4186 Actuals : List_Id := Parameter_Associations (N);
4187 Actual : Node_Id := First (Actuals);
4188 Formal : Entity_Id := First_Formal (Designated_Type (Typ));
4191 while Present (Actual)
4192 and then Present (Formal)
4194 if not Has_Compatible_Type (Actual, Etype (Formal)) then
4199 Next_Formal (Formal);
4202 if No (Actual) and then No (Formal) then
4203 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
4205 -- Nam is a candidate interpretation for the name in the call,
4206 -- if it is not an indirect call.
4208 if not Is_Type (Nam)
4209 and then Is_Entity_Name (Name (N))
4211 Set_Entity (Name (N), Nam);
4218 end Try_Indirect_Call;
4220 ----------------------
4221 -- Try_Indexed_Call --
4222 ----------------------
4224 function Try_Indexed_Call
4230 Actuals : List_Id := Parameter_Associations (N);
4231 Actual : Node_Id := First (Actuals);
4232 Index : Entity_Id := First_Index (Typ);
4235 while Present (Actual)
4236 and then Present (Index)
4238 -- If the parameter list has a named association, the expression
4239 -- is definitely a call and not an indexed component.
4241 if Nkind (Actual) = N_Parameter_Association then
4245 if not Has_Compatible_Type (Actual, Etype (Index)) then
4253 if No (Actual) and then No (Index) then
4254 Add_One_Interp (N, Nam, Component_Type (Typ));
4256 -- Nam is a candidate interpretation for the name in the call,
4257 -- if it is not an indirect call.
4259 if not Is_Type (Nam)
4260 and then Is_Entity_Name (Name (N))
4262 Set_Entity (Name (N), Nam);
4270 end Try_Indexed_Call;