1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Debug; use Debug;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Errout; use Errout;
31 with Exp_Util; use Exp_Util;
32 with Fname; use Fname;
33 with Itypes; use Itypes;
35 with Lib.Xref; use Lib.Xref;
36 with Namet; use Namet;
37 with Nlists; use Nlists;
38 with Nmake; use Nmake;
40 with Output; use Output;
41 with Restrict; use Restrict;
42 with Rident; use Rident;
44 with Sem_Cat; use Sem_Cat;
45 with Sem_Ch3; use Sem_Ch3;
46 with Sem_Ch8; use Sem_Ch8;
47 with Sem_Disp; use Sem_Disp;
48 with Sem_Dist; use Sem_Dist;
49 with Sem_Eval; use Sem_Eval;
50 with Sem_Res; use Sem_Res;
51 with Sem_Util; use Sem_Util;
52 with Sem_Type; use Sem_Type;
53 with Stand; use Stand;
54 with Sinfo; use Sinfo;
55 with Snames; use Snames;
56 with Tbuild; use Tbuild;
58 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
60 package body Sem_Ch4 is
62 -----------------------
63 -- Local Subprograms --
64 -----------------------
66 procedure Analyze_Expression (N : Node_Id);
67 -- For expressions that are not names, this is just a call to analyze.
68 -- If the expression is a name, it may be a call to a parameterless
69 -- function, and if so must be converted into an explicit call node
70 -- and analyzed as such. This deproceduring must be done during the first
71 -- pass of overload resolution, because otherwise a procedure call with
72 -- overloaded actuals may fail to resolve. See 4327-001 for an example.
74 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
75 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
76 -- is an operator name or an expanded name whose selector is an operator
77 -- name, and one possible interpretation is as a predefined operator.
79 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
80 -- If the prefix of a selected_component is overloaded, the proper
81 -- interpretation that yields a record type with the proper selector
82 -- name must be selected.
84 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
85 -- Procedure to analyze a user defined binary operator, which is resolved
86 -- like a function, but instead of a list of actuals it is presented
87 -- with the left and right operands of an operator node.
89 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
90 -- Procedure to analyze a user defined unary operator, which is resolved
91 -- like a function, but instead of a list of actuals, it is presented with
92 -- the operand of the operator node.
94 procedure Ambiguous_Operands (N : Node_Id);
95 -- for equality, membership, and comparison operators with overloaded
96 -- arguments, list possible interpretations.
98 procedure Analyze_One_Call
102 Success : out Boolean;
103 Skip_First : Boolean := False);
104 -- Check one interpretation of an overloaded subprogram name for
105 -- compatibility with the types of the actuals in a call. If there is a
106 -- single interpretation which does not match, post error if Report is
109 -- Nam is the entity that provides the formals against which the actuals
110 -- are checked. Nam is either the name of a subprogram, or the internal
111 -- subprogram type constructed for an access_to_subprogram. If the actuals
112 -- are compatible with Nam, then Nam is added to the list of candidate
113 -- interpretations for N, and Success is set to True.
115 -- The flag Skip_First is used when analyzing a call that was rewritten
116 -- from object notation. In this case the first actual may have to receive
117 -- an explicit dereference, depending on the first formal of the operation
118 -- being called. The caller will have verified that the object is legal
119 -- for the call. If the remaining parameters match, the first parameter
120 -- will rewritten as a dereference if needed, prior to completing analysis.
122 procedure Check_Misspelled_Selector
125 -- Give possible misspelling diagnostic if Sel is likely to be
126 -- a misspelling of one of the selectors of the Prefix.
127 -- This is called by Analyze_Selected_Component after producing
128 -- an invalid selector error message.
130 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
131 -- Verify that type T is declared in scope S. Used to find intepretations
132 -- for operators given by expanded names. This is abstracted as a separate
133 -- function to handle extensions to System, where S is System, but T is
134 -- declared in the extension.
136 procedure Find_Arithmetic_Types
140 -- L and R are the operands of an arithmetic operator. Find
141 -- consistent pairs of interpretations for L and R that have a
142 -- numeric type consistent with the semantics of the operator.
144 procedure Find_Comparison_Types
148 -- L and R are operands of a comparison operator. Find consistent
149 -- pairs of interpretations for L and R.
151 procedure Find_Concatenation_Types
155 -- For the four varieties of concatenation
157 procedure Find_Equality_Types
161 -- Ditto for equality operators
163 procedure Find_Boolean_Types
167 -- Ditto for binary logical operations
169 procedure Find_Negation_Types
173 -- Find consistent interpretation for operand of negation operator
175 procedure Find_Non_Universal_Interpretations
180 -- For equality and comparison operators, the result is always boolean,
181 -- and the legality of the operation is determined from the visibility
182 -- of the operand types. If one of the operands has a universal interpre-
183 -- tation, the legality check uses some compatible non-universal
184 -- interpretation of the other operand. N can be an operator node, or
185 -- a function call whose name is an operator designator.
187 procedure Find_Unary_Types
191 -- Unary arithmetic types: plus, minus, abs
193 procedure Check_Arithmetic_Pair
197 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
198 -- types for left and right operand. Determine whether they constitute
199 -- a valid pair for the given operator, and record the corresponding
200 -- interpretation of the operator node. The node N may be an operator
201 -- node (the usual case) or a function call whose prefix is an operator
202 -- designator. In both cases Op_Id is the operator name itself.
204 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
205 -- Give detailed information on overloaded call where none of the
206 -- interpretations match. N is the call node, Nam the designator for
207 -- the overloaded entity being called.
209 function Junk_Operand (N : Node_Id) return Boolean;
210 -- Test for an operand that is an inappropriate entity (e.g. a package
211 -- name or a label). If so, issue an error message and return True. If
212 -- the operand is not an inappropriate entity kind, return False.
214 procedure Operator_Check (N : Node_Id);
215 -- Verify that an operator has received some valid interpretation. If none
216 -- was found, determine whether a use clause would make the operation
217 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
218 -- every type compatible with the operator, even if the operator for the
219 -- type is not directly visible. The routine uses this type to emit a more
220 -- informative message.
222 procedure Process_Implicit_Dereference_Prefix
225 -- Called when P is the prefix of an implicit dereference, denoting an
226 -- object E. If in semantics only mode (-gnatc or generic), record that is
227 -- a reference to E. Normally, such a reference is generated only when the
228 -- implicit dereference is expanded into an explicit one. E may be empty,
229 -- in which case this procedure does nothing.
231 procedure Remove_Abstract_Operations (N : Node_Id);
232 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
233 -- operation is not a candidate interpretation.
235 function Try_Indexed_Call
239 Skip_First : Boolean) return Boolean;
240 -- If a function has defaults for all its actuals, a call to it may in fact
241 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
242 -- interpretation as an indexing, prior to analysis as a call. If both are
243 -- possible, the node is overloaded with both interpretations (same symbol
244 -- but two different types). If the call is written in prefix form, the
245 -- prefix becomes the first parameter in the call, and only the remaining
246 -- actuals must be checked for the presence of defaults.
248 function Try_Indirect_Call
251 Typ : Entity_Id) return Boolean;
252 -- Similarly, a function F that needs no actuals can return an access to a
253 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
254 -- the call may be overloaded with both interpretations.
256 function Try_Object_Operation (N : Node_Id) return Boolean;
257 -- Ada 2005 (AI-252): Support the object.operation notation
259 ------------------------
260 -- Ambiguous_Operands --
261 ------------------------
263 procedure Ambiguous_Operands (N : Node_Id) is
264 procedure List_Operand_Interps (Opnd : Node_Id);
266 --------------------------
267 -- List_Operand_Interps --
268 --------------------------
270 procedure List_Operand_Interps (Opnd : Node_Id) is
275 if Is_Overloaded (Opnd) then
276 if Nkind (Opnd) in N_Op then
278 elsif Nkind (Opnd) = N_Function_Call then
288 if Opnd = Left_Opnd (N) then
290 ("\left operand has the following interpretations", N);
293 ("\right operand has the following interpretations", N);
297 List_Interps (Nam, Err);
298 end List_Operand_Interps;
300 -- Start of processing for Ambiguous_Operands
303 if Nkind (N) in N_Membership_Test then
304 Error_Msg_N ("ambiguous operands for membership", N);
306 elsif Nkind (N) = N_Op_Eq
307 or else Nkind (N) = N_Op_Ne
309 Error_Msg_N ("ambiguous operands for equality", N);
312 Error_Msg_N ("ambiguous operands for comparison", N);
315 if All_Errors_Mode then
316 List_Operand_Interps (Left_Opnd (N));
317 List_Operand_Interps (Right_Opnd (N));
319 Error_Msg_N ("\use -gnatf switch for details", N);
321 end Ambiguous_Operands;
323 -----------------------
324 -- Analyze_Aggregate --
325 -----------------------
327 -- Most of the analysis of Aggregates requires that the type be known,
328 -- and is therefore put off until resolution.
330 procedure Analyze_Aggregate (N : Node_Id) is
332 if No (Etype (N)) then
333 Set_Etype (N, Any_Composite);
335 end Analyze_Aggregate;
337 -----------------------
338 -- Analyze_Allocator --
339 -----------------------
341 procedure Analyze_Allocator (N : Node_Id) is
342 Loc : constant Source_Ptr := Sloc (N);
343 Sav_Errs : constant Nat := Serious_Errors_Detected;
344 E : Node_Id := Expression (N);
345 Acc_Type : Entity_Id;
349 Check_Restriction (No_Allocators, N);
351 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));
358 -- Analyze the qualified expression, and apply the name resolution
359 -- rule given in 4.7 (3).
362 Type_Id := Etype (E);
363 Set_Directly_Designated_Type (Acc_Type, Type_Id);
365 Resolve (Expression (E), Type_Id);
367 if Is_Limited_Type (Type_Id)
368 and then Comes_From_Source (N)
369 and then not In_Instance_Body
371 if not OK_For_Limited_Init (Expression (E)) then
372 Error_Msg_N ("initialization not allowed for limited types", N);
373 Explain_Limited_Type (Type_Id, N);
377 -- A qualified expression requires an exact match of the type,
378 -- class-wide matching is not allowed.
380 -- if Is_Class_Wide_Type (Type_Id)
381 -- and then Base_Type
382 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
384 -- Wrong_Type (Expression (E), Type_Id);
387 Check_Non_Static_Context (Expression (E));
389 -- We don't analyze the qualified expression itself because it's
390 -- part of the allocator
392 Set_Etype (E, Type_Id);
394 -- Case where allocator has a subtype indication
399 Base_Typ : Entity_Id;
402 -- If the allocator includes a N_Subtype_Indication then a
403 -- constraint is present, otherwise the node is a subtype mark.
404 -- Introduce an explicit subtype declaration into the tree
405 -- defining some anonymous subtype and rewrite the allocator to
406 -- use this subtype rather than the subtype indication.
408 -- It is important to introduce the explicit subtype declaration
409 -- so that the bounds of the subtype indication are attached to
410 -- the tree in case the allocator is inside a generic unit.
412 if Nkind (E) = N_Subtype_Indication then
414 -- A constraint is only allowed for a composite type in Ada
415 -- 95. In Ada 83, a constraint is also allowed for an
416 -- access-to-composite type, but the constraint is ignored.
418 Find_Type (Subtype_Mark (E));
419 Base_Typ := Entity (Subtype_Mark (E));
421 if Is_Elementary_Type (Base_Typ) then
422 if not (Ada_Version = Ada_83
423 and then Is_Access_Type (Base_Typ))
425 Error_Msg_N ("constraint not allowed here", E);
427 if Nkind (Constraint (E)) =
428 N_Index_Or_Discriminant_Constraint
431 ("\if qualified expression was meant, " &
432 "use apostrophe", Constraint (E));
436 -- Get rid of the bogus constraint:
438 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
439 Analyze_Allocator (N);
442 -- Ada 2005, AI-363: if the designated type has a constrained
443 -- partial view, it cannot receive a discriminant constraint,
444 -- and the allocated object is unconstrained.
446 elsif Ada_Version >= Ada_05
447 and then Has_Constrained_Partial_View (Base_Typ)
450 ("constraint no allowed when type " &
451 "has a constrained partial view", Constraint (E));
454 if Expander_Active then
456 Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
459 Make_Subtype_Declaration (Loc,
460 Defining_Identifier => Def_Id,
461 Subtype_Indication => Relocate_Node (E)));
463 if Sav_Errs /= Serious_Errors_Detected
464 and then Nkind (Constraint (E))
465 = N_Index_Or_Discriminant_Constraint
468 ("if qualified expression was meant, " &
469 "use apostrophe!", Constraint (E));
472 E := New_Occurrence_Of (Def_Id, Loc);
473 Rewrite (Expression (N), E);
477 Type_Id := Process_Subtype (E, N);
478 Acc_Type := Create_Itype (E_Allocator_Type, N);
479 Set_Etype (Acc_Type, Acc_Type);
480 Init_Size_Align (Acc_Type);
481 Set_Directly_Designated_Type (Acc_Type, Type_Id);
482 Check_Fully_Declared (Type_Id, N);
486 if Can_Never_Be_Null (Type_Id) then
487 Error_Msg_N ("(Ada 2005) qualified expression required",
491 -- Check restriction against dynamically allocated protected
492 -- objects. Note that when limited aggregates are supported,
493 -- a similar test should be applied to an allocator with a
494 -- qualified expression ???
496 if Is_Protected_Type (Type_Id) then
497 Check_Restriction (No_Protected_Type_Allocators, N);
500 -- Check for missing initialization. Skip this check if we already
501 -- had errors on analyzing the allocator, since in that case these
502 -- are probably cascaded errors.
504 if Is_Indefinite_Subtype (Type_Id)
505 and then Serious_Errors_Detected = Sav_Errs
507 if Is_Class_Wide_Type (Type_Id) then
509 ("initialization required in class-wide allocation", N);
511 if Ada_Version < Ada_05
512 and then Is_Limited_Type (Type_Id)
514 Error_Msg_N ("unconstrained allocation not allowed", N);
516 if Is_Array_Type (Type_Id) then
518 ("\constraint with array bounds required", N);
520 elsif Has_Unknown_Discriminants (Type_Id) then
523 else pragma Assert (Has_Discriminants (Type_Id));
525 ("\constraint with discriminant values required", N);
528 -- Limited Ada 2005 and general non-limited case
532 ("uninitialized unconstrained allocation not allowed",
535 if Is_Array_Type (Type_Id) then
537 ("\qualified expression or constraint with " &
538 "array bounds required", N);
540 elsif Has_Unknown_Discriminants (Type_Id) then
541 Error_Msg_N ("\qualified expression required", N);
543 else pragma Assert (Has_Discriminants (Type_Id));
545 ("\qualified expression or constraint with " &
546 "discriminant values required", N);
554 if Is_Abstract_Type (Type_Id) then
555 Error_Msg_N ("cannot allocate abstract object", E);
558 if Has_Task (Designated_Type (Acc_Type)) then
559 Check_Restriction (No_Tasking, N);
560 Check_Restriction (Max_Tasks, N);
561 Check_Restriction (No_Task_Allocators, N);
564 -- If the No_Streams restriction is set, check that the type of the
565 -- object is not, and does not contain, any subtype derived from
566 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
567 -- Has_Stream just for efficiency reasons. There is no point in
568 -- spending time on a Has_Stream check if the restriction is not set.
570 if Restrictions.Set (No_Streams) then
571 if Has_Stream (Designated_Type (Acc_Type)) then
572 Check_Restriction (No_Streams, N);
576 Set_Etype (N, Acc_Type);
578 if not Is_Library_Level_Entity (Acc_Type) then
579 Check_Restriction (No_Local_Allocators, N);
582 if Serious_Errors_Detected > Sav_Errs then
583 Set_Error_Posted (N);
584 Set_Etype (N, Any_Type);
586 end Analyze_Allocator;
588 ---------------------------
589 -- Analyze_Arithmetic_Op --
590 ---------------------------
592 procedure Analyze_Arithmetic_Op (N : Node_Id) is
593 L : constant Node_Id := Left_Opnd (N);
594 R : constant Node_Id := Right_Opnd (N);
598 Candidate_Type := Empty;
599 Analyze_Expression (L);
600 Analyze_Expression (R);
602 -- If the entity is already set, the node is the instantiation of
603 -- a generic node with a non-local reference, or was manufactured
604 -- by a call to Make_Op_xxx. In either case the entity is known to
605 -- be valid, and we do not need to collect interpretations, instead
606 -- we just get the single possible interpretation.
610 if Present (Op_Id) then
611 if Ekind (Op_Id) = E_Operator then
613 if (Nkind (N) = N_Op_Divide or else
614 Nkind (N) = N_Op_Mod or else
615 Nkind (N) = N_Op_Multiply or else
616 Nkind (N) = N_Op_Rem)
617 and then Treat_Fixed_As_Integer (N)
621 Set_Etype (N, Any_Type);
622 Find_Arithmetic_Types (L, R, Op_Id, N);
626 Set_Etype (N, Any_Type);
627 Add_One_Interp (N, Op_Id, Etype (Op_Id));
630 -- Entity is not already set, so we do need to collect interpretations
633 Op_Id := Get_Name_Entity_Id (Chars (N));
634 Set_Etype (N, Any_Type);
636 while Present (Op_Id) loop
637 if Ekind (Op_Id) = E_Operator
638 and then Present (Next_Entity (First_Entity (Op_Id)))
640 Find_Arithmetic_Types (L, R, Op_Id, N);
642 -- The following may seem superfluous, because an operator cannot
643 -- be generic, but this ignores the cleverness of the author of
646 elsif Is_Overloadable (Op_Id) then
647 Analyze_User_Defined_Binary_Op (N, Op_Id);
650 Op_Id := Homonym (Op_Id);
655 end Analyze_Arithmetic_Op;
661 -- Function, procedure, and entry calls are checked here. The Name in
662 -- the call may be overloaded. The actuals have been analyzed and may
663 -- themselves be overloaded. On exit from this procedure, the node N
664 -- may have zero, one or more interpretations. In the first case an
665 -- error message is produced. In the last case, the node is flagged
666 -- as overloaded and the interpretations are collected in All_Interp.
668 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
669 -- the type-checking is similar to that of other calls.
671 procedure Analyze_Call (N : Node_Id) is
672 Actuals : constant List_Id := Parameter_Associations (N);
673 Nam : Node_Id := Name (N);
677 Success : Boolean := False;
679 function Name_Denotes_Function return Boolean;
680 -- If the type of the name is an access to subprogram, this may be
681 -- the type of a name, or the return type of the function being called.
682 -- If the name is not an entity then it can denote a protected function.
683 -- Until we distinguish Etype from Return_Type, we must use this
684 -- routine to resolve the meaning of the name in the call.
686 ---------------------------
687 -- Name_Denotes_Function --
688 ---------------------------
690 function Name_Denotes_Function return Boolean is
692 if Is_Entity_Name (Nam) then
693 return Ekind (Entity (Nam)) = E_Function;
695 elsif Nkind (Nam) = N_Selected_Component then
696 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
701 end Name_Denotes_Function;
703 -- Start of processing for Analyze_Call
706 -- Initialize the type of the result of the call to the error type,
707 -- which will be reset if the type is successfully resolved.
709 Set_Etype (N, Any_Type);
711 if not Is_Overloaded (Nam) then
713 -- Only one interpretation to check
715 if Ekind (Etype (Nam)) = E_Subprogram_Type then
716 Nam_Ent := Etype (Nam);
718 -- If the prefix is an access_to_subprogram, this may be an indirect
719 -- call. This is the case if the name in the call is not an entity
720 -- name, or if it is a function name in the context of a procedure
721 -- call. In this latter case, we have a call to a parameterless
722 -- function that returns a pointer_to_procedure which is the entity
725 elsif Is_Access_Type (Etype (Nam))
726 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
728 (not Name_Denotes_Function
729 or else Nkind (N) = N_Procedure_Call_Statement)
731 Nam_Ent := Designated_Type (Etype (Nam));
732 Insert_Explicit_Dereference (Nam);
734 -- Selected component case. Simple entry or protected operation,
735 -- where the entry name is given by the selector name.
737 elsif Nkind (Nam) = N_Selected_Component then
738 Nam_Ent := Entity (Selector_Name (Nam));
740 if Ekind (Nam_Ent) /= E_Entry
741 and then Ekind (Nam_Ent) /= E_Entry_Family
742 and then Ekind (Nam_Ent) /= E_Function
743 and then Ekind (Nam_Ent) /= E_Procedure
745 Error_Msg_N ("name in call is not a callable entity", Nam);
746 Set_Etype (N, Any_Type);
750 -- If the name is an Indexed component, it can be a call to a member
751 -- of an entry family. The prefix must be a selected component whose
752 -- selector is the entry. Analyze_Procedure_Call normalizes several
753 -- kinds of call into this form.
755 elsif Nkind (Nam) = N_Indexed_Component then
757 if Nkind (Prefix (Nam)) = N_Selected_Component then
758 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
760 Error_Msg_N ("name in call is not a callable entity", Nam);
761 Set_Etype (N, Any_Type);
765 elsif not Is_Entity_Name (Nam) then
766 Error_Msg_N ("name in call is not a callable entity", Nam);
767 Set_Etype (N, Any_Type);
771 Nam_Ent := Entity (Nam);
773 -- If no interpretations, give error message
775 if not Is_Overloadable (Nam_Ent) then
777 L : constant Boolean := Is_List_Member (N);
778 K : constant Node_Kind := Nkind (Parent (N));
781 -- If the node is in a list whose parent is not an
782 -- expression then it must be an attempted procedure call.
784 if L and then K not in N_Subexpr then
785 if Ekind (Entity (Nam)) = E_Generic_Procedure then
787 ("must instantiate generic procedure& before call",
791 ("procedure or entry name expected", Nam);
794 -- Check for tasking cases where only an entry call will do
797 and then (K = N_Entry_Call_Alternative
798 or else K = N_Triggering_Alternative)
800 Error_Msg_N ("entry name expected", Nam);
802 -- Otherwise give general error message
805 Error_Msg_N ("invalid prefix in call", Nam);
813 Analyze_One_Call (N, Nam_Ent, True, Success);
815 -- If this is an indirect call, the return type of the access_to
816 -- subprogram may be an incomplete type. At the point of the call,
817 -- use the full type if available, and at the same time update
818 -- the return type of the access_to_subprogram.
821 and then Nkind (Nam) = N_Explicit_Dereference
822 and then Ekind (Etype (N)) = E_Incomplete_Type
823 and then Present (Full_View (Etype (N)))
825 Set_Etype (N, Full_View (Etype (N)));
826 Set_Etype (Nam_Ent, Etype (N));
830 -- An overloaded selected component must denote overloaded
831 -- operations of a concurrent type. The interpretations are
832 -- attached to the simple name of those operations.
834 if Nkind (Nam) = N_Selected_Component then
835 Nam := Selector_Name (Nam);
838 Get_First_Interp (Nam, X, It);
840 while Present (It.Nam) loop
843 -- Name may be call that returns an access to subprogram, or more
844 -- generally an overloaded expression one of whose interpretations
845 -- yields an access to subprogram. If the name is an entity, we
846 -- do not dereference, because the node is a call that returns
847 -- the access type: note difference between f(x), where the call
848 -- may return an access subprogram type, and f(x)(y), where the
849 -- type returned by the call to f is implicitly dereferenced to
850 -- analyze the outer call.
852 if Is_Access_Type (Nam_Ent) then
853 Nam_Ent := Designated_Type (Nam_Ent);
855 elsif Is_Access_Type (Etype (Nam_Ent))
856 and then not Is_Entity_Name (Nam)
857 and then Ekind (Designated_Type (Etype (Nam_Ent)))
860 Nam_Ent := Designated_Type (Etype (Nam_Ent));
863 Analyze_One_Call (N, Nam_Ent, False, Success);
865 -- If the interpretation succeeds, mark the proper type of the
866 -- prefix (any valid candidate will do). If not, remove the
867 -- candidate interpretation. This only needs to be done for
868 -- overloaded protected operations, for other entities disambi-
869 -- guation is done directly in Resolve.
872 Set_Etype (Nam, It.Typ);
874 elsif Nkind (Name (N)) = N_Selected_Component
875 or else Nkind (Name (N)) = N_Function_Call
880 Get_Next_Interp (X, It);
883 -- If the name is the result of a function call, it can only
884 -- be a call to a function returning an access to subprogram.
885 -- Insert explicit dereference.
887 if Nkind (Nam) = N_Function_Call then
888 Insert_Explicit_Dereference (Nam);
891 if Etype (N) = Any_Type then
893 -- None of the interpretations is compatible with the actuals
895 Diagnose_Call (N, Nam);
897 -- Special checks for uninstantiated put routines
899 if Nkind (N) = N_Procedure_Call_Statement
900 and then Is_Entity_Name (Nam)
901 and then Chars (Nam) = Name_Put
902 and then List_Length (Actuals) = 1
905 Arg : constant Node_Id := First (Actuals);
909 if Nkind (Arg) = N_Parameter_Association then
910 Typ := Etype (Explicit_Actual_Parameter (Arg));
915 if Is_Signed_Integer_Type (Typ) then
917 ("possible missing instantiation of " &
918 "'Text_'I'O.'Integer_'I'O!", Nam);
920 elsif Is_Modular_Integer_Type (Typ) then
922 ("possible missing instantiation of " &
923 "'Text_'I'O.'Modular_'I'O!", Nam);
925 elsif Is_Floating_Point_Type (Typ) then
927 ("possible missing instantiation of " &
928 "'Text_'I'O.'Float_'I'O!", Nam);
930 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
932 ("possible missing instantiation of " &
933 "'Text_'I'O.'Fixed_'I'O!", Nam);
935 elsif Is_Decimal_Fixed_Point_Type (Typ) then
937 ("possible missing instantiation of " &
938 "'Text_'I'O.'Decimal_'I'O!", Nam);
940 elsif Is_Enumeration_Type (Typ) then
942 ("possible missing instantiation of " &
943 "'Text_'I'O.'Enumeration_'I'O!", Nam);
948 elsif not Is_Overloaded (N)
949 and then Is_Entity_Name (Nam)
951 -- Resolution yields a single interpretation. Verify that the
952 -- reference has capitalization consistent with the declaration.
954 Set_Entity_With_Style_Check (Nam, Entity (Nam));
955 Generate_Reference (Entity (Nam), Nam);
957 Set_Etype (Nam, Etype (Entity (Nam)));
959 Remove_Abstract_Operations (N);
965 -- Check for not-yet-implemented cases of AI-318. We only need to check
966 -- for inherently limited types, because other limited types will be
967 -- returned by copy, which works just fine.
968 -- If the context is an attribute reference 'Class, this is really a
969 -- type conversion, which is illegal, and will be caught elsewhere.
971 if Ada_Version >= Ada_05
972 and then not Debug_Flag_Dot_L
973 and then Is_Inherently_Limited_Type (Etype (N))
974 and then (Nkind (Parent (N)) = N_Selected_Component
975 or else Nkind (Parent (N)) = N_Indexed_Component
976 or else Nkind (Parent (N)) = N_Slice
978 (Nkind (Parent (N)) = N_Attribute_Reference
979 and then Attribute_Name (Parent (N)) /= Name_Class))
981 Error_Msg_N ("(Ada 2005) limited function call in this context" &
982 " is not yet implemented", N);
986 ---------------------------
987 -- Analyze_Comparison_Op --
988 ---------------------------
990 procedure Analyze_Comparison_Op (N : Node_Id) is
991 L : constant Node_Id := Left_Opnd (N);
992 R : constant Node_Id := Right_Opnd (N);
993 Op_Id : Entity_Id := Entity (N);
996 Set_Etype (N, Any_Type);
997 Candidate_Type := Empty;
999 Analyze_Expression (L);
1000 Analyze_Expression (R);
1002 if Present (Op_Id) then
1003 if Ekind (Op_Id) = E_Operator then
1004 Find_Comparison_Types (L, R, Op_Id, N);
1006 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1009 if Is_Overloaded (L) then
1010 Set_Etype (L, Intersect_Types (L, R));
1014 Op_Id := Get_Name_Entity_Id (Chars (N));
1015 while Present (Op_Id) loop
1016 if Ekind (Op_Id) = E_Operator then
1017 Find_Comparison_Types (L, R, Op_Id, N);
1019 Analyze_User_Defined_Binary_Op (N, Op_Id);
1022 Op_Id := Homonym (Op_Id);
1027 end Analyze_Comparison_Op;
1029 ---------------------------
1030 -- Analyze_Concatenation --
1031 ---------------------------
1033 -- If the only one-dimensional array type in scope is String,
1034 -- this is the resulting type of the operation. Otherwise there
1035 -- will be a concatenation operation defined for each user-defined
1036 -- one-dimensional array.
1038 procedure Analyze_Concatenation (N : Node_Id) is
1039 L : constant Node_Id := Left_Opnd (N);
1040 R : constant Node_Id := Right_Opnd (N);
1041 Op_Id : Entity_Id := Entity (N);
1046 Set_Etype (N, Any_Type);
1047 Candidate_Type := Empty;
1049 Analyze_Expression (L);
1050 Analyze_Expression (R);
1052 -- If the entity is present, the node appears in an instance, and
1053 -- denotes a predefined concatenation operation. The resulting type is
1054 -- obtained from the arguments when possible. If the arguments are
1055 -- aggregates, the array type and the concatenation type must be
1058 if Present (Op_Id) then
1059 if Ekind (Op_Id) = E_Operator then
1061 LT := Base_Type (Etype (L));
1062 RT := Base_Type (Etype (R));
1064 if Is_Array_Type (LT)
1065 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1067 Add_One_Interp (N, Op_Id, LT);
1069 elsif Is_Array_Type (RT)
1070 and then LT = Base_Type (Component_Type (RT))
1072 Add_One_Interp (N, Op_Id, RT);
1074 -- If one operand is a string type or a user-defined array type,
1075 -- and the other is a literal, result is of the specific type.
1078 (Root_Type (LT) = Standard_String
1079 or else Scope (LT) /= Standard_Standard)
1080 and then Etype (R) = Any_String
1082 Add_One_Interp (N, Op_Id, LT);
1085 (Root_Type (RT) = Standard_String
1086 or else Scope (RT) /= Standard_Standard)
1087 and then Etype (L) = Any_String
1089 Add_One_Interp (N, Op_Id, RT);
1091 elsif not Is_Generic_Type (Etype (Op_Id)) then
1092 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1095 -- Type and its operations must be visible
1097 Set_Entity (N, Empty);
1098 Analyze_Concatenation (N);
1102 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1106 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1107 while Present (Op_Id) loop
1108 if Ekind (Op_Id) = E_Operator then
1110 -- Do not consider operators declared in dead code, they can
1111 -- not be part of the resolution.
1113 if Is_Eliminated (Op_Id) then
1116 Find_Concatenation_Types (L, R, Op_Id, N);
1120 Analyze_User_Defined_Binary_Op (N, Op_Id);
1123 Op_Id := Homonym (Op_Id);
1128 end Analyze_Concatenation;
1130 ------------------------------------
1131 -- Analyze_Conditional_Expression --
1132 ------------------------------------
1134 procedure Analyze_Conditional_Expression (N : Node_Id) is
1135 Condition : constant Node_Id := First (Expressions (N));
1136 Then_Expr : constant Node_Id := Next (Condition);
1137 Else_Expr : constant Node_Id := Next (Then_Expr);
1139 Analyze_Expression (Condition);
1140 Analyze_Expression (Then_Expr);
1141 Analyze_Expression (Else_Expr);
1142 Set_Etype (N, Etype (Then_Expr));
1143 end Analyze_Conditional_Expression;
1145 -------------------------
1146 -- Analyze_Equality_Op --
1147 -------------------------
1149 procedure Analyze_Equality_Op (N : Node_Id) is
1150 Loc : constant Source_Ptr := Sloc (N);
1151 L : constant Node_Id := Left_Opnd (N);
1152 R : constant Node_Id := Right_Opnd (N);
1156 Set_Etype (N, Any_Type);
1157 Candidate_Type := Empty;
1159 Analyze_Expression (L);
1160 Analyze_Expression (R);
1162 -- If the entity is set, the node is a generic instance with a non-local
1163 -- reference to the predefined operator or to a user-defined function.
1164 -- It can also be an inequality that is expanded into the negation of a
1165 -- call to a user-defined equality operator.
1167 -- For the predefined case, the result is Boolean, regardless of the
1168 -- type of the operands. The operands may even be limited, if they are
1169 -- generic actuals. If they are overloaded, label the left argument with
1170 -- the common type that must be present, or with the type of the formal
1171 -- of the user-defined function.
1173 if Present (Entity (N)) then
1174 Op_Id := Entity (N);
1176 if Ekind (Op_Id) = E_Operator then
1177 Add_One_Interp (N, Op_Id, Standard_Boolean);
1179 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1182 if Is_Overloaded (L) then
1183 if Ekind (Op_Id) = E_Operator then
1184 Set_Etype (L, Intersect_Types (L, R));
1186 Set_Etype (L, Etype (First_Formal (Op_Id)));
1191 Op_Id := Get_Name_Entity_Id (Chars (N));
1192 while Present (Op_Id) loop
1193 if Ekind (Op_Id) = E_Operator then
1194 Find_Equality_Types (L, R, Op_Id, N);
1196 Analyze_User_Defined_Binary_Op (N, Op_Id);
1199 Op_Id := Homonym (Op_Id);
1203 -- If there was no match, and the operator is inequality, this may
1204 -- be a case where inequality has not been made explicit, as for
1205 -- tagged types. Analyze the node as the negation of an equality
1206 -- operation. This cannot be done earlier, because before analysis
1207 -- we cannot rule out the presence of an explicit inequality.
1209 if Etype (N) = Any_Type
1210 and then Nkind (N) = N_Op_Ne
1212 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1213 while Present (Op_Id) loop
1214 if Ekind (Op_Id) = E_Operator then
1215 Find_Equality_Types (L, R, Op_Id, N);
1217 Analyze_User_Defined_Binary_Op (N, Op_Id);
1220 Op_Id := Homonym (Op_Id);
1223 if Etype (N) /= Any_Type then
1224 Op_Id := Entity (N);
1230 Left_Opnd => Left_Opnd (N),
1231 Right_Opnd => Right_Opnd (N))));
1233 Set_Entity (Right_Opnd (N), Op_Id);
1239 end Analyze_Equality_Op;
1241 ----------------------------------
1242 -- Analyze_Explicit_Dereference --
1243 ----------------------------------
1245 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1246 Loc : constant Source_Ptr := Sloc (N);
1247 P : constant Node_Id := Prefix (N);
1253 function Is_Function_Type return Boolean;
1254 -- Check whether node may be interpreted as an implicit function call
1256 ----------------------
1257 -- Is_Function_Type --
1258 ----------------------
1260 function Is_Function_Type return Boolean is
1265 if not Is_Overloaded (N) then
1266 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1267 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1270 Get_First_Interp (N, I, It);
1271 while Present (It.Nam) loop
1272 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1273 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1278 Get_Next_Interp (I, It);
1283 end Is_Function_Type;
1285 -- Start of processing for Analyze_Explicit_Dereference
1289 Set_Etype (N, Any_Type);
1291 -- Test for remote access to subprogram type, and if so return
1292 -- after rewriting the original tree.
1294 if Remote_AST_E_Dereference (P) then
1298 -- Normal processing for other than remote access to subprogram type
1300 if not Is_Overloaded (P) then
1301 if Is_Access_Type (Etype (P)) then
1303 -- Set the Etype. We need to go thru Is_For_Access_Subtypes to
1304 -- avoid other problems caused by the Private_Subtype and it is
1305 -- safe to go to the Base_Type because this is the same as
1306 -- converting the access value to its Base_Type.
1309 DT : Entity_Id := Designated_Type (Etype (P));
1312 if Ekind (DT) = E_Private_Subtype
1313 and then Is_For_Access_Subtype (DT)
1315 DT := Base_Type (DT);
1318 -- An explicit dereference is a legal occurrence of an
1319 -- incomplete type imported through a limited_with clause,
1320 -- if the full view is visible.
1322 if From_With_Type (DT)
1323 and then not From_With_Type (Scope (DT))
1325 (Is_Immediately_Visible (Scope (DT))
1327 (Is_Child_Unit (Scope (DT))
1328 and then Is_Visible_Child_Unit (Scope (DT))))
1330 Set_Etype (N, Available_View (DT));
1337 elsif Etype (P) /= Any_Type then
1338 Error_Msg_N ("prefix of dereference must be an access type", N);
1343 Get_First_Interp (P, I, It);
1344 while Present (It.Nam) loop
1347 if Is_Access_Type (T) then
1348 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1351 Get_Next_Interp (I, It);
1354 -- Error if no interpretation of the prefix has an access type
1356 if Etype (N) = Any_Type then
1358 ("access type required in prefix of explicit dereference", P);
1359 Set_Etype (N, Any_Type);
1365 and then Nkind (Parent (N)) /= N_Indexed_Component
1367 and then (Nkind (Parent (N)) /= N_Function_Call
1368 or else N /= Name (Parent (N)))
1370 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1371 or else N /= Name (Parent (N)))
1373 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1374 and then (Nkind (Parent (N)) /= N_Attribute_Reference
1376 (Attribute_Name (Parent (N)) /= Name_Address
1378 Attribute_Name (Parent (N)) /= Name_Access))
1380 -- Name is a function call with no actuals, in a context that
1381 -- requires deproceduring (including as an actual in an enclosing
1382 -- function or procedure call). There are some pathological cases
1383 -- where the prefix might include functions that return access to
1384 -- subprograms and others that return a regular type. Disambiguation
1385 -- of those has to take place in Resolve.
1386 -- See e.g. 7117-014 and E317-001.
1389 Make_Function_Call (Loc,
1390 Name => Make_Explicit_Dereference (Loc, P),
1391 Parameter_Associations => New_List);
1393 -- If the prefix is overloaded, remove operations that have formals,
1394 -- we know that this is a parameterless call.
1396 if Is_Overloaded (P) then
1397 Get_First_Interp (P, I, It);
1398 while Present (It.Nam) loop
1401 if No (First_Formal (Base_Type (Designated_Type (T)))) then
1407 Get_Next_Interp (I, It);
1414 elsif not Is_Function_Type
1415 and then Is_Overloaded (N)
1417 -- The prefix may include access to subprograms and other access
1418 -- types. If the context selects the interpretation that is a call,
1419 -- we cannot rewrite the node yet, but we include the result of
1420 -- the call interpretation.
1422 Get_First_Interp (N, I, It);
1423 while Present (It.Nam) loop
1424 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
1425 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
1427 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
1430 Get_Next_Interp (I, It);
1434 -- A value of remote access-to-class-wide must not be dereferenced
1437 Validate_Remote_Access_To_Class_Wide_Type (N);
1438 end Analyze_Explicit_Dereference;
1440 ------------------------
1441 -- Analyze_Expression --
1442 ------------------------
1444 procedure Analyze_Expression (N : Node_Id) is
1447 Check_Parameterless_Call (N);
1448 end Analyze_Expression;
1450 ------------------------------------
1451 -- Analyze_Indexed_Component_Form --
1452 ------------------------------------
1454 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
1455 P : constant Node_Id := Prefix (N);
1456 Exprs : constant List_Id := Expressions (N);
1462 procedure Process_Function_Call;
1463 -- Prefix in indexed component form is an overloadable entity,
1464 -- so the node is a function call. Reformat it as such.
1466 procedure Process_Indexed_Component;
1467 -- Prefix in indexed component form is actually an indexed component.
1468 -- This routine processes it, knowing that the prefix is already
1471 procedure Process_Indexed_Component_Or_Slice;
1472 -- An indexed component with a single index may designate a slice if
1473 -- the index is a subtype mark. This routine disambiguates these two
1474 -- cases by resolving the prefix to see if it is a subtype mark.
1476 procedure Process_Overloaded_Indexed_Component;
1477 -- If the prefix of an indexed component is overloaded, the proper
1478 -- interpretation is selected by the index types and the context.
1480 ---------------------------
1481 -- Process_Function_Call --
1482 ---------------------------
1484 procedure Process_Function_Call is
1488 Change_Node (N, N_Function_Call);
1490 Set_Parameter_Associations (N, Exprs);
1492 -- Analyze actuals prior to analyzing the call itself
1494 Actual := First (Parameter_Associations (N));
1495 while Present (Actual) loop
1497 Check_Parameterless_Call (Actual);
1499 -- Move to next actual. Note that we use Next, not Next_Actual
1500 -- here. The reason for this is a bit subtle. If a function call
1501 -- includes named associations, the parser recognizes the node as
1502 -- a call, and it is analyzed as such. If all associations are
1503 -- positional, the parser builds an indexed_component node, and
1504 -- it is only after analysis of the prefix that the construct
1505 -- is recognized as a call, in which case Process_Function_Call
1506 -- rewrites the node and analyzes the actuals. If the list of
1507 -- actuals is malformed, the parser may leave the node as an
1508 -- indexed component (despite the presence of named associations).
1509 -- The iterator Next_Actual is equivalent to Next if the list is
1510 -- positional, but follows the normalized chain of actuals when
1511 -- named associations are present. In this case normalization has
1512 -- not taken place, and actuals remain unanalyzed, which leads to
1513 -- subsequent crashes or loops if there is an attempt to continue
1514 -- analysis of the program.
1520 end Process_Function_Call;
1522 -------------------------------
1523 -- Process_Indexed_Component --
1524 -------------------------------
1526 procedure Process_Indexed_Component is
1528 Array_Type : Entity_Id;
1530 Pent : Entity_Id := Empty;
1533 Exp := First (Exprs);
1535 if Is_Overloaded (P) then
1536 Process_Overloaded_Indexed_Component;
1539 Array_Type := Etype (P);
1541 if Is_Entity_Name (P) then
1543 elsif Nkind (P) = N_Selected_Component
1544 and then Is_Entity_Name (Selector_Name (P))
1546 Pent := Entity (Selector_Name (P));
1549 -- Prefix must be appropriate for an array type, taking into
1550 -- account a possible implicit dereference.
1552 if Is_Access_Type (Array_Type) then
1553 Array_Type := Designated_Type (Array_Type);
1554 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1555 Process_Implicit_Dereference_Prefix (Pent, P);
1558 if Is_Array_Type (Array_Type) then
1561 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
1563 Set_Etype (N, Any_Type);
1565 if not Has_Compatible_Type
1566 (Exp, Entry_Index_Type (Pent))
1568 Error_Msg_N ("invalid index type in entry name", N);
1570 elsif Present (Next (Exp)) then
1571 Error_Msg_N ("too many subscripts in entry reference", N);
1574 Set_Etype (N, Etype (P));
1579 elsif Is_Record_Type (Array_Type)
1580 and then Remote_AST_I_Dereference (P)
1584 elsif Array_Type = Any_Type then
1585 Set_Etype (N, Any_Type);
1588 -- Here we definitely have a bad indexing
1591 if Nkind (Parent (N)) = N_Requeue_Statement
1592 and then Present (Pent) and then Ekind (Pent) = E_Entry
1595 ("REQUEUE does not permit parameters", First (Exprs));
1597 elsif Is_Entity_Name (P)
1598 and then Etype (P) = Standard_Void_Type
1600 Error_Msg_NE ("incorrect use of&", P, Entity (P));
1603 Error_Msg_N ("array type required in indexed component", P);
1606 Set_Etype (N, Any_Type);
1610 Index := First_Index (Array_Type);
1611 while Present (Index) and then Present (Exp) loop
1612 if not Has_Compatible_Type (Exp, Etype (Index)) then
1613 Wrong_Type (Exp, Etype (Index));
1614 Set_Etype (N, Any_Type);
1622 Set_Etype (N, Component_Type (Array_Type));
1624 if Present (Index) then
1626 ("too few subscripts in array reference", First (Exprs));
1628 elsif Present (Exp) then
1629 Error_Msg_N ("too many subscripts in array reference", Exp);
1632 end Process_Indexed_Component;
1634 ----------------------------------------
1635 -- Process_Indexed_Component_Or_Slice --
1636 ----------------------------------------
1638 procedure Process_Indexed_Component_Or_Slice is
1640 Exp := First (Exprs);
1641 while Present (Exp) loop
1642 Analyze_Expression (Exp);
1646 Exp := First (Exprs);
1648 -- If one index is present, and it is a subtype name, then the
1649 -- node denotes a slice (note that the case of an explicit range
1650 -- for a slice was already built as an N_Slice node in the first
1651 -- place, so that case is not handled here).
1653 -- We use a replace rather than a rewrite here because this is one
1654 -- of the cases in which the tree built by the parser is plain wrong.
1657 and then Is_Entity_Name (Exp)
1658 and then Is_Type (Entity (Exp))
1661 Make_Slice (Sloc (N),
1663 Discrete_Range => New_Copy (Exp)));
1666 -- Otherwise (more than one index present, or single index is not
1667 -- a subtype name), then we have the indexed component case.
1670 Process_Indexed_Component;
1672 end Process_Indexed_Component_Or_Slice;
1674 ------------------------------------------
1675 -- Process_Overloaded_Indexed_Component --
1676 ------------------------------------------
1678 procedure Process_Overloaded_Indexed_Component is
1687 Set_Etype (N, Any_Type);
1689 Get_First_Interp (P, I, It);
1690 while Present (It.Nam) loop
1693 if Is_Access_Type (Typ) then
1694 Typ := Designated_Type (Typ);
1695 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1698 if Is_Array_Type (Typ) then
1700 -- Got a candidate: verify that index types are compatible
1702 Index := First_Index (Typ);
1704 Exp := First (Exprs);
1705 while Present (Index) and then Present (Exp) loop
1706 if Has_Compatible_Type (Exp, Etype (Index)) then
1718 if Found and then No (Index) and then No (Exp) then
1720 Etype (Component_Type (Typ)),
1721 Etype (Component_Type (Typ)));
1725 Get_Next_Interp (I, It);
1728 if Etype (N) = Any_Type then
1729 Error_Msg_N ("no legal interpetation for indexed component", N);
1730 Set_Is_Overloaded (N, False);
1734 end Process_Overloaded_Indexed_Component;
1736 -- Start of processing for Analyze_Indexed_Component_Form
1739 -- Get name of array, function or type
1742 if Nkind (N) = N_Function_Call
1743 or else Nkind (N) = N_Procedure_Call_Statement
1745 -- If P is an explicit dereference whose prefix is of a
1746 -- remote access-to-subprogram type, then N has already
1747 -- been rewritten as a subprogram call and analyzed.
1752 pragma Assert (Nkind (N) = N_Indexed_Component);
1754 P_T := Base_Type (Etype (P));
1756 if Is_Entity_Name (P)
1757 or else Nkind (P) = N_Operator_Symbol
1761 if Is_Type (U_N) then
1763 -- Reformat node as a type conversion
1765 E := Remove_Head (Exprs);
1767 if Present (First (Exprs)) then
1769 ("argument of type conversion must be single expression", N);
1772 Change_Node (N, N_Type_Conversion);
1773 Set_Subtype_Mark (N, P);
1775 Set_Expression (N, E);
1777 -- After changing the node, call for the specific Analysis
1778 -- routine directly, to avoid a double call to the expander.
1780 Analyze_Type_Conversion (N);
1784 if Is_Overloadable (U_N) then
1785 Process_Function_Call;
1787 elsif Ekind (Etype (P)) = E_Subprogram_Type
1788 or else (Is_Access_Type (Etype (P))
1790 Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type)
1792 -- Call to access_to-subprogram with possible implicit dereference
1794 Process_Function_Call;
1796 elsif Is_Generic_Subprogram (U_N) then
1798 -- A common beginner's (or C++ templates fan) error
1800 Error_Msg_N ("generic subprogram cannot be called", N);
1801 Set_Etype (N, Any_Type);
1805 Process_Indexed_Component_Or_Slice;
1808 -- If not an entity name, prefix is an expression that may denote
1809 -- an array or an access-to-subprogram.
1812 if Ekind (P_T) = E_Subprogram_Type
1813 or else (Is_Access_Type (P_T)
1815 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
1817 Process_Function_Call;
1819 elsif Nkind (P) = N_Selected_Component
1820 and then Is_Overloadable (Entity (Selector_Name (P)))
1822 Process_Function_Call;
1825 -- Indexed component, slice, or a call to a member of a family
1826 -- entry, which will be converted to an entry call later.
1828 Process_Indexed_Component_Or_Slice;
1831 end Analyze_Indexed_Component_Form;
1833 ------------------------
1834 -- Analyze_Logical_Op --
1835 ------------------------
1837 procedure Analyze_Logical_Op (N : Node_Id) is
1838 L : constant Node_Id := Left_Opnd (N);
1839 R : constant Node_Id := Right_Opnd (N);
1840 Op_Id : Entity_Id := Entity (N);
1843 Set_Etype (N, Any_Type);
1844 Candidate_Type := Empty;
1846 Analyze_Expression (L);
1847 Analyze_Expression (R);
1849 if Present (Op_Id) then
1851 if Ekind (Op_Id) = E_Operator then
1852 Find_Boolean_Types (L, R, Op_Id, N);
1854 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1858 Op_Id := Get_Name_Entity_Id (Chars (N));
1859 while Present (Op_Id) loop
1860 if Ekind (Op_Id) = E_Operator then
1861 Find_Boolean_Types (L, R, Op_Id, N);
1863 Analyze_User_Defined_Binary_Op (N, Op_Id);
1866 Op_Id := Homonym (Op_Id);
1871 end Analyze_Logical_Op;
1873 ---------------------------
1874 -- Analyze_Membership_Op --
1875 ---------------------------
1877 procedure Analyze_Membership_Op (N : Node_Id) is
1878 L : constant Node_Id := Left_Opnd (N);
1879 R : constant Node_Id := Right_Opnd (N);
1881 Index : Interp_Index;
1883 Found : Boolean := False;
1887 procedure Try_One_Interp (T1 : Entity_Id);
1888 -- Routine to try one proposed interpretation. Note that the context
1889 -- of the operation plays no role in resolving the arguments, so that
1890 -- if there is more than one interpretation of the operands that is
1891 -- compatible with a membership test, the operation is ambiguous.
1893 --------------------
1894 -- Try_One_Interp --
1895 --------------------
1897 procedure Try_One_Interp (T1 : Entity_Id) is
1899 if Has_Compatible_Type (R, T1) then
1901 and then Base_Type (T1) /= Base_Type (T_F)
1903 It := Disambiguate (L, I_F, Index, Any_Type);
1905 if It = No_Interp then
1906 Ambiguous_Operands (N);
1907 Set_Etype (L, Any_Type);
1925 -- Start of processing for Analyze_Membership_Op
1928 Analyze_Expression (L);
1930 if Nkind (R) = N_Range
1931 or else (Nkind (R) = N_Attribute_Reference
1932 and then Attribute_Name (R) = Name_Range)
1936 if not Is_Overloaded (L) then
1937 Try_One_Interp (Etype (L));
1940 Get_First_Interp (L, Index, It);
1941 while Present (It.Typ) loop
1942 Try_One_Interp (It.Typ);
1943 Get_Next_Interp (Index, It);
1947 -- If not a range, it can only be a subtype mark, or else there
1948 -- is a more basic error, to be diagnosed in Find_Type.
1953 if Is_Entity_Name (R) then
1954 Check_Fully_Declared (Entity (R), R);
1958 -- Compatibility between expression and subtype mark or range is
1959 -- checked during resolution. The result of the operation is Boolean
1962 Set_Etype (N, Standard_Boolean);
1964 if Comes_From_Source (N)
1965 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
1967 Error_Msg_N ("membership test not applicable to cpp-class types", N);
1969 end Analyze_Membership_Op;
1971 ----------------------
1972 -- Analyze_Negation --
1973 ----------------------
1975 procedure Analyze_Negation (N : Node_Id) is
1976 R : constant Node_Id := Right_Opnd (N);
1977 Op_Id : Entity_Id := Entity (N);
1980 Set_Etype (N, Any_Type);
1981 Candidate_Type := Empty;
1983 Analyze_Expression (R);
1985 if Present (Op_Id) then
1986 if Ekind (Op_Id) = E_Operator then
1987 Find_Negation_Types (R, Op_Id, N);
1989 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1993 Op_Id := Get_Name_Entity_Id (Chars (N));
1994 while Present (Op_Id) loop
1995 if Ekind (Op_Id) = E_Operator then
1996 Find_Negation_Types (R, Op_Id, N);
1998 Analyze_User_Defined_Unary_Op (N, Op_Id);
2001 Op_Id := Homonym (Op_Id);
2006 end Analyze_Negation;
2012 procedure Analyze_Null (N : Node_Id) is
2014 Set_Etype (N, Any_Access);
2017 ----------------------
2018 -- Analyze_One_Call --
2019 ----------------------
2021 procedure Analyze_One_Call
2025 Success : out Boolean;
2026 Skip_First : Boolean := False)
2028 Actuals : constant List_Id := Parameter_Associations (N);
2029 Prev_T : constant Entity_Id := Etype (N);
2030 Must_Skip : constant Boolean := Skip_First
2031 or else Nkind (Original_Node (N)) = N_Selected_Component
2033 (Nkind (Original_Node (N)) = N_Indexed_Component
2034 and then Nkind (Prefix (Original_Node (N)))
2035 = N_Selected_Component);
2036 -- The first formal must be omitted from the match when trying to find
2037 -- a primitive operation that is a possible interpretation, and also
2038 -- after the call has been rewritten, because the corresponding actual
2039 -- is already known to be compatible, and because this may be an
2040 -- indexing of a call with default parameters.
2044 Is_Indexed : Boolean := False;
2045 Subp_Type : constant Entity_Id := Etype (Nam);
2048 function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
2049 -- There may be a user-defined operator that hides the current
2050 -- interpretation. We must check for this independently of the
2051 -- analysis of the call with the user-defined operation, because
2052 -- the parameter names may be wrong and yet the hiding takes place.
2053 -- This fixes a problem with ACATS test B34014O.
2055 -- When the type Address is a visible integer type, and the DEC
2056 -- system extension is visible, the predefined operator may be
2057 -- hidden as well, by one of the address operations in auxdec.
2058 -- Finally, The abstract operations on address do not hide the
2059 -- predefined operator (this is the purpose of making them abstract).
2061 procedure Indicate_Name_And_Type;
2062 -- If candidate interpretation matches, indicate name and type of
2063 -- result on call node.
2065 ----------------------------
2066 -- Indicate_Name_And_Type --
2067 ----------------------------
2069 procedure Indicate_Name_And_Type is
2071 Add_One_Interp (N, Nam, Etype (Nam));
2074 -- If the prefix of the call is a name, indicate the entity
2075 -- being called. If it is not a name, it is an expression that
2076 -- denotes an access to subprogram or else an entry or family. In
2077 -- the latter case, the name is a selected component, and the entity
2078 -- being called is noted on the selector.
2080 if not Is_Type (Nam) then
2081 if Is_Entity_Name (Name (N))
2082 or else Nkind (Name (N)) = N_Operator_Symbol
2084 Set_Entity (Name (N), Nam);
2086 elsif Nkind (Name (N)) = N_Selected_Component then
2087 Set_Entity (Selector_Name (Name (N)), Nam);
2091 if Debug_Flag_E and not Report then
2092 Write_Str (" Overloaded call ");
2093 Write_Int (Int (N));
2094 Write_Str (" compatible with ");
2095 Write_Int (Int (Nam));
2098 end Indicate_Name_And_Type;
2100 ------------------------
2101 -- Operator_Hidden_By --
2102 ------------------------
2104 function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
2105 Act1 : constant Node_Id := First_Actual (N);
2106 Act2 : constant Node_Id := Next_Actual (Act1);
2107 Form1 : constant Entity_Id := First_Formal (Fun);
2108 Form2 : constant Entity_Id := Next_Formal (Form1);
2111 if Ekind (Fun) /= E_Function
2112 or else Is_Abstract_Subprogram (Fun)
2116 elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
2119 elsif Present (Form2) then
2121 No (Act2) or else not Has_Compatible_Type (Act2, Etype (Form2))
2126 elsif Present (Act2) then
2130 -- Now we know that the arity of the operator matches the function,
2131 -- and the function call is a valid interpretation. The function
2132 -- hides the operator if it has the right signature, or if one of
2133 -- its operands is a non-abstract operation on Address when this is
2134 -- a visible integer type.
2136 return Hides_Op (Fun, Nam)
2137 or else Is_Descendent_Of_Address (Etype (Form1))
2140 and then Is_Descendent_Of_Address (Etype (Form2)));
2141 end Operator_Hidden_By;
2143 -- Start of processing for Analyze_One_Call
2148 -- If the subprogram has no formals or if all the formals have defaults,
2149 -- and the return type is an array type, the node may denote an indexing
2150 -- of the result of a parameterless call. In Ada 2005, the subprogram
2151 -- may have one non-defaulted formal, and the call may have been written
2152 -- in prefix notation, so that the rebuilt parameter list has more than
2155 if Present (Actuals)
2157 (Needs_No_Actuals (Nam)
2159 (Needs_One_Actual (Nam)
2160 and then Present (Next_Actual (First (Actuals)))))
2162 if Is_Array_Type (Subp_Type) then
2163 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
2165 elsif Is_Access_Type (Subp_Type)
2166 and then Is_Array_Type (Designated_Type (Subp_Type))
2170 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
2172 -- The prefix can also be a parameterless function that returns an
2173 -- access to subprogram. in which case this is an indirect call.
2175 elsif Is_Access_Type (Subp_Type)
2176 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
2178 Is_Indexed := Try_Indirect_Call (N, Nam, Subp_Type);
2183 Normalize_Actuals (N, Nam, (Report and not Is_Indexed), Norm_OK);
2187 -- Mismatch in number or names of parameters
2189 if Debug_Flag_E then
2190 Write_Str (" normalization fails in call ");
2191 Write_Int (Int (N));
2192 Write_Str (" with subprogram ");
2193 Write_Int (Int (Nam));
2197 -- If the context expects a function call, discard any interpretation
2198 -- that is a procedure. If the node is not overloaded, leave as is for
2199 -- better error reporting when type mismatch is found.
2201 elsif Nkind (N) = N_Function_Call
2202 and then Is_Overloaded (Name (N))
2203 and then Ekind (Nam) = E_Procedure
2207 -- Ditto for function calls in a procedure context
2209 elsif Nkind (N) = N_Procedure_Call_Statement
2210 and then Is_Overloaded (Name (N))
2211 and then Etype (Nam) /= Standard_Void_Type
2215 elsif No (Actuals) then
2217 -- If Normalize succeeds, then there are default parameters for
2220 Indicate_Name_And_Type;
2222 elsif Ekind (Nam) = E_Operator then
2223 if Nkind (N) = N_Procedure_Call_Statement then
2227 -- This can occur when the prefix of the call is an operator
2228 -- name or an expanded name whose selector is an operator name.
2230 Analyze_Operator_Call (N, Nam);
2232 if Etype (N) /= Prev_T then
2234 -- Check that operator is not hidden by a function interpretation
2236 if Is_Overloaded (Name (N)) then
2242 Get_First_Interp (Name (N), I, It);
2243 while Present (It.Nam) loop
2244 if Operator_Hidden_By (It.Nam) then
2245 Set_Etype (N, Prev_T);
2249 Get_Next_Interp (I, It);
2254 -- If operator matches formals, record its name on the call.
2255 -- If the operator is overloaded, Resolve will select the
2256 -- correct one from the list of interpretations. The call
2257 -- node itself carries the first candidate.
2259 Set_Entity (Name (N), Nam);
2262 elsif Report and then Etype (N) = Any_Type then
2263 Error_Msg_N ("incompatible arguments for operator", N);
2267 -- Normalize_Actuals has chained the named associations in the
2268 -- correct order of the formals.
2270 Actual := First_Actual (N);
2271 Formal := First_Formal (Nam);
2273 -- If we are analyzing a call rewritten from object notation,
2274 -- skip first actual, which may be rewritten later as an
2275 -- explicit dereference.
2278 Next_Actual (Actual);
2279 Next_Formal (Formal);
2282 while Present (Actual) and then Present (Formal) loop
2283 if Nkind (Parent (Actual)) /= N_Parameter_Association
2284 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
2286 -- The actual can be compatible with the formal, but we must
2287 -- also check that the context is not an address type that is
2288 -- visibly an integer type, as is the case in VMS_64. In this
2289 -- case the use of literals is illegal, except in the body of
2290 -- descendents of system, where arithmetic operations on
2291 -- address are of course used.
2293 if Has_Compatible_Type (Actual, Etype (Formal))
2295 (Etype (Actual) /= Universal_Integer
2296 or else not Is_Descendent_Of_Address (Etype (Formal))
2298 Is_Predefined_File_Name
2299 (Unit_File_Name (Get_Source_Unit (N))))
2301 Next_Actual (Actual);
2302 Next_Formal (Formal);
2305 if Debug_Flag_E then
2306 Write_Str (" type checking fails in call ");
2307 Write_Int (Int (N));
2308 Write_Str (" with formal ");
2309 Write_Int (Int (Formal));
2310 Write_Str (" in subprogram ");
2311 Write_Int (Int (Nam));
2315 if Report and not Is_Indexed then
2317 -- Ada 2005 (AI-251): Complete the error notification
2318 -- to help new Ada 2005 users
2320 if Is_Class_Wide_Type (Etype (Formal))
2321 and then Is_Interface (Etype (Etype (Formal)))
2322 and then not Interface_Present_In_Ancestor
2323 (Typ => Etype (Actual),
2324 Iface => Etype (Etype (Formal)))
2327 ("(Ada 2005) does not implement interface }",
2328 Actual, Etype (Etype (Formal)));
2331 Wrong_Type (Actual, Etype (Formal));
2333 if Nkind (Actual) = N_Op_Eq
2334 and then Nkind (Left_Opnd (Actual)) = N_Identifier
2336 Formal := First_Formal (Nam);
2337 while Present (Formal) loop
2338 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
2340 ("possible misspelling of `='>`!", Actual);
2344 Next_Formal (Formal);
2348 if All_Errors_Mode then
2349 Error_Msg_Sloc := Sloc (Nam);
2351 if Is_Overloadable (Nam)
2352 and then Present (Alias (Nam))
2353 and then not Comes_From_Source (Nam)
2356 ("\\ =='> in call to inherited operation & #!",
2359 elsif Ekind (Nam) = E_Subprogram_Type then
2361 Access_To_Subprogram_Typ :
2362 constant Entity_Id :=
2364 (Associated_Node_For_Itype (Nam));
2367 "\\ =='> in call to dereference of &#!",
2368 Actual, Access_To_Subprogram_Typ);
2373 ("\\ =='> in call to &#!", Actual, Nam);
2383 -- Normalize_Actuals has verified that a default value exists
2384 -- for this formal. Current actual names a subsequent formal.
2386 Next_Formal (Formal);
2390 -- On exit, all actuals match
2392 Indicate_Name_And_Type;
2394 end Analyze_One_Call;
2396 ---------------------------
2397 -- Analyze_Operator_Call --
2398 ---------------------------
2400 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
2401 Op_Name : constant Name_Id := Chars (Op_Id);
2402 Act1 : constant Node_Id := First_Actual (N);
2403 Act2 : constant Node_Id := Next_Actual (Act1);
2406 -- Binary operator case
2408 if Present (Act2) then
2410 -- If more than two operands, then not binary operator after all
2412 if Present (Next_Actual (Act2)) then
2415 elsif Op_Name = Name_Op_Add
2416 or else Op_Name = Name_Op_Subtract
2417 or else Op_Name = Name_Op_Multiply
2418 or else Op_Name = Name_Op_Divide
2419 or else Op_Name = Name_Op_Mod
2420 or else Op_Name = Name_Op_Rem
2421 or else Op_Name = Name_Op_Expon
2423 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
2425 elsif Op_Name = Name_Op_And
2426 or else Op_Name = Name_Op_Or
2427 or else Op_Name = Name_Op_Xor
2429 Find_Boolean_Types (Act1, Act2, Op_Id, N);
2431 elsif Op_Name = Name_Op_Lt
2432 or else Op_Name = Name_Op_Le
2433 or else Op_Name = Name_Op_Gt
2434 or else Op_Name = Name_Op_Ge
2436 Find_Comparison_Types (Act1, Act2, Op_Id, N);
2438 elsif Op_Name = Name_Op_Eq
2439 or else Op_Name = Name_Op_Ne
2441 Find_Equality_Types (Act1, Act2, Op_Id, N);
2443 elsif Op_Name = Name_Op_Concat then
2444 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
2446 -- Is this else null correct, or should it be an abort???
2452 -- Unary operator case
2455 if Op_Name = Name_Op_Subtract or else
2456 Op_Name = Name_Op_Add or else
2457 Op_Name = Name_Op_Abs
2459 Find_Unary_Types (Act1, Op_Id, N);
2462 Op_Name = Name_Op_Not
2464 Find_Negation_Types (Act1, Op_Id, N);
2466 -- Is this else null correct, or should it be an abort???
2472 end Analyze_Operator_Call;
2474 -------------------------------------------
2475 -- Analyze_Overloaded_Selected_Component --
2476 -------------------------------------------
2478 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
2479 Nam : constant Node_Id := Prefix (N);
2480 Sel : constant Node_Id := Selector_Name (N);
2487 Set_Etype (Sel, Any_Type);
2489 Get_First_Interp (Nam, I, It);
2490 while Present (It.Typ) loop
2491 if Is_Access_Type (It.Typ) then
2492 T := Designated_Type (It.Typ);
2493 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2498 if Is_Record_Type (T) then
2499 Comp := First_Entity (T);
2500 while Present (Comp) loop
2501 if Chars (Comp) = Chars (Sel)
2502 and then Is_Visible_Component (Comp)
2504 Set_Entity (Sel, Comp);
2505 Set_Etype (Sel, Etype (Comp));
2506 Add_One_Interp (N, Etype (Comp), Etype (Comp));
2508 -- This also specifies a candidate to resolve the name.
2509 -- Further overloading will be resolved from context.
2511 Set_Etype (Nam, It.Typ);
2517 elsif Is_Concurrent_Type (T) then
2518 Comp := First_Entity (T);
2519 while Present (Comp)
2520 and then Comp /= First_Private_Entity (T)
2522 if Chars (Comp) = Chars (Sel) then
2523 if Is_Overloadable (Comp) then
2524 Add_One_Interp (Sel, Comp, Etype (Comp));
2526 Set_Entity_With_Style_Check (Sel, Comp);
2527 Generate_Reference (Comp, Sel);
2530 Set_Etype (Sel, Etype (Comp));
2531 Set_Etype (N, Etype (Comp));
2532 Set_Etype (Nam, It.Typ);
2534 -- For access type case, introduce explicit deference for
2535 -- more uniform treatment of entry calls.
2537 if Is_Access_Type (Etype (Nam)) then
2538 Insert_Explicit_Dereference (Nam);
2540 (Warn_On_Dereference, "?implicit dereference", N);
2547 Set_Is_Overloaded (N, Is_Overloaded (Sel));
2550 Get_Next_Interp (I, It);
2553 if Etype (N) = Any_Type
2554 and then not Try_Object_Operation (N)
2556 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
2557 Set_Entity (Sel, Any_Id);
2558 Set_Etype (Sel, Any_Type);
2560 end Analyze_Overloaded_Selected_Component;
2562 ----------------------------------
2563 -- Analyze_Qualified_Expression --
2564 ----------------------------------
2566 procedure Analyze_Qualified_Expression (N : Node_Id) is
2567 Mark : constant Entity_Id := Subtype_Mark (N);
2568 Expr : constant Node_Id := Expression (N);
2574 Analyze_Expression (Expr);
2576 Set_Etype (N, Any_Type);
2581 if T = Any_Type then
2585 Check_Fully_Declared (T, N);
2587 -- If expected type is class-wide, check for exact match before
2588 -- expansion, because if the expression is a dispatching call it
2589 -- may be rewritten as explicit dereference with class-wide result.
2590 -- If expression is overloaded, retain only interpretations that
2591 -- will yield exact matches.
2593 if Is_Class_Wide_Type (T) then
2594 if not Is_Overloaded (Expr) then
2595 if Base_Type (Etype (Expr)) /= Base_Type (T) then
2596 if Nkind (Expr) = N_Aggregate then
2597 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
2599 Wrong_Type (Expr, T);
2604 Get_First_Interp (Expr, I, It);
2606 while Present (It.Nam) loop
2607 if Base_Type (It.Typ) /= Base_Type (T) then
2611 Get_Next_Interp (I, It);
2617 end Analyze_Qualified_Expression;
2623 procedure Analyze_Range (N : Node_Id) is
2624 L : constant Node_Id := Low_Bound (N);
2625 H : constant Node_Id := High_Bound (N);
2626 I1, I2 : Interp_Index;
2629 procedure Check_Common_Type (T1, T2 : Entity_Id);
2630 -- Verify the compatibility of two types, and choose the
2631 -- non universal one if the other is universal.
2633 procedure Check_High_Bound (T : Entity_Id);
2634 -- Test one interpretation of the low bound against all those
2635 -- of the high bound.
2637 procedure Check_Universal_Expression (N : Node_Id);
2638 -- In Ada83, reject bounds of a universal range that are not
2639 -- literals or entity names.
2641 -----------------------
2642 -- Check_Common_Type --
2643 -----------------------
2645 procedure Check_Common_Type (T1, T2 : Entity_Id) is
2647 if Covers (T1, T2) or else Covers (T2, T1) then
2648 if T1 = Universal_Integer
2649 or else T1 = Universal_Real
2650 or else T1 = Any_Character
2652 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
2655 Add_One_Interp (N, T1, T1);
2658 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
2661 end Check_Common_Type;
2663 ----------------------
2664 -- Check_High_Bound --
2665 ----------------------
2667 procedure Check_High_Bound (T : Entity_Id) is
2669 if not Is_Overloaded (H) then
2670 Check_Common_Type (T, Etype (H));
2672 Get_First_Interp (H, I2, It2);
2673 while Present (It2.Typ) loop
2674 Check_Common_Type (T, It2.Typ);
2675 Get_Next_Interp (I2, It2);
2678 end Check_High_Bound;
2680 -----------------------------
2681 -- Is_Universal_Expression --
2682 -----------------------------
2684 procedure Check_Universal_Expression (N : Node_Id) is
2686 if Etype (N) = Universal_Integer
2687 and then Nkind (N) /= N_Integer_Literal
2688 and then not Is_Entity_Name (N)
2689 and then Nkind (N) /= N_Attribute_Reference
2691 Error_Msg_N ("illegal bound in discrete range", N);
2693 end Check_Universal_Expression;
2695 -- Start of processing for Analyze_Range
2698 Set_Etype (N, Any_Type);
2699 Analyze_Expression (L);
2700 Analyze_Expression (H);
2702 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
2706 if not Is_Overloaded (L) then
2707 Check_High_Bound (Etype (L));
2709 Get_First_Interp (L, I1, It1);
2710 while Present (It1.Typ) loop
2711 Check_High_Bound (It1.Typ);
2712 Get_Next_Interp (I1, It1);
2716 -- If result is Any_Type, then we did not find a compatible pair
2718 if Etype (N) = Any_Type then
2719 Error_Msg_N ("incompatible types in range ", N);
2723 if Ada_Version = Ada_83
2725 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
2726 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
2728 Check_Universal_Expression (L);
2729 Check_Universal_Expression (H);
2733 -----------------------
2734 -- Analyze_Reference --
2735 -----------------------
2737 procedure Analyze_Reference (N : Node_Id) is
2738 P : constant Node_Id := Prefix (N);
2739 Acc_Type : Entity_Id;
2742 Acc_Type := Create_Itype (E_Allocator_Type, N);
2743 Set_Etype (Acc_Type, Acc_Type);
2744 Init_Size_Align (Acc_Type);
2745 Set_Directly_Designated_Type (Acc_Type, Etype (P));
2746 Set_Etype (N, Acc_Type);
2747 end Analyze_Reference;
2749 --------------------------------
2750 -- Analyze_Selected_Component --
2751 --------------------------------
2753 -- Prefix is a record type or a task or protected type. In the
2754 -- later case, the selector must denote a visible entry.
2756 procedure Analyze_Selected_Component (N : Node_Id) is
2757 Name : constant Node_Id := Prefix (N);
2758 Sel : constant Node_Id := Selector_Name (N);
2760 Prefix_Type : Entity_Id;
2762 Type_To_Use : Entity_Id;
2763 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
2764 -- a class-wide type, we use its root type, whose components are
2765 -- present in the class-wide type.
2767 Pent : Entity_Id := Empty;
2772 -- Start of processing for Analyze_Selected_Component
2775 Set_Etype (N, Any_Type);
2777 if Is_Overloaded (Name) then
2778 Analyze_Overloaded_Selected_Component (N);
2781 elsif Etype (Name) = Any_Type then
2782 Set_Entity (Sel, Any_Id);
2783 Set_Etype (Sel, Any_Type);
2787 Prefix_Type := Etype (Name);
2790 if Is_Access_Type (Prefix_Type) then
2792 -- A RACW object can never be used as prefix of a selected
2793 -- component since that means it is dereferenced without
2794 -- being a controlling operand of a dispatching operation
2797 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
2798 and then Comes_From_Source (N)
2801 ("invalid dereference of a remote access to class-wide value",
2804 -- Normal case of selected component applied to access type
2807 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2809 if Is_Entity_Name (Name) then
2810 Pent := Entity (Name);
2811 elsif Nkind (Name) = N_Selected_Component
2812 and then Is_Entity_Name (Selector_Name (Name))
2814 Pent := Entity (Selector_Name (Name));
2817 Process_Implicit_Dereference_Prefix (Pent, Name);
2820 Prefix_Type := Designated_Type (Prefix_Type);
2824 -- (Ada 2005): if the prefix is the limited view of a type, and
2825 -- the context already includes the full view, use the full view
2826 -- in what follows, either to retrieve a component of to find
2827 -- a primitive operation. If the prefix is an explicit dereference,
2828 -- set the type of the prefix to reflect this transformation.
2829 -- If the non-limited view is itself an incomplete type, get the
2830 -- full view if available.
2832 if Is_Incomplete_Type (Prefix_Type)
2833 and then From_With_Type (Prefix_Type)
2834 and then Present (Non_Limited_View (Prefix_Type))
2836 Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
2838 if Nkind (N) = N_Explicit_Dereference then
2839 Set_Etype (Prefix (N), Prefix_Type);
2842 elsif Ekind (Prefix_Type) = E_Class_Wide_Type
2843 and then From_With_Type (Prefix_Type)
2844 and then Present (Non_Limited_View (Etype (Prefix_Type)))
2847 Class_Wide_Type (Non_Limited_View (Etype (Prefix_Type)));
2849 if Nkind (N) = N_Explicit_Dereference then
2850 Set_Etype (Prefix (N), Prefix_Type);
2854 if Ekind (Prefix_Type) = E_Private_Subtype then
2855 Prefix_Type := Base_Type (Prefix_Type);
2858 Type_To_Use := Prefix_Type;
2860 -- For class-wide types, use the entity list of the root type. This
2861 -- indirection is specially important for private extensions because
2862 -- only the root type get switched (not the class-wide type).
2864 if Is_Class_Wide_Type (Prefix_Type) then
2865 Type_To_Use := Root_Type (Prefix_Type);
2868 Comp := First_Entity (Type_To_Use);
2870 -- If the selector has an original discriminant, the node appears in
2871 -- an instance. Replace the discriminant with the corresponding one
2872 -- in the current discriminated type. For nested generics, this must
2873 -- be done transitively, so note the new original discriminant.
2875 if Nkind (Sel) = N_Identifier
2876 and then Present (Original_Discriminant (Sel))
2878 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
2880 -- Mark entity before rewriting, for completeness and because
2881 -- subsequent semantic checks might examine the original node.
2883 Set_Entity (Sel, Comp);
2884 Rewrite (Selector_Name (N),
2885 New_Occurrence_Of (Comp, Sloc (N)));
2886 Set_Original_Discriminant (Selector_Name (N), Comp);
2887 Set_Etype (N, Etype (Comp));
2889 if Is_Access_Type (Etype (Name)) then
2890 Insert_Explicit_Dereference (Name);
2891 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2894 elsif Is_Record_Type (Prefix_Type) then
2896 -- Find component with given name
2898 while Present (Comp) loop
2899 if Chars (Comp) = Chars (Sel)
2900 and then Is_Visible_Component (Comp)
2902 Set_Entity_With_Style_Check (Sel, Comp);
2903 Set_Etype (Sel, Etype (Comp));
2905 if Ekind (Comp) = E_Discriminant then
2906 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
2908 ("cannot reference discriminant of Unchecked_Union",
2912 if Is_Generic_Type (Prefix_Type)
2914 Is_Generic_Type (Root_Type (Prefix_Type))
2916 Set_Original_Discriminant (Sel, Comp);
2920 -- Resolve the prefix early otherwise it is not possible to
2921 -- build the actual subtype of the component: it may need
2922 -- to duplicate this prefix and duplication is only allowed
2923 -- on fully resolved expressions.
2927 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
2928 -- subtypes in a package specification.
2931 -- limited with Pkg;
2933 -- type Acc_Inc is access Pkg.T;
2935 -- N : Natural := X.all.Comp; -- ERROR, limited view
2936 -- end Pkg; -- Comp is not visible
2938 if Nkind (Name) = N_Explicit_Dereference
2939 and then From_With_Type (Etype (Prefix (Name)))
2940 and then not Is_Potentially_Use_Visible (Etype (Name))
2941 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
2942 N_Package_Specification
2945 ("premature usage of incomplete}", Prefix (Name),
2946 Etype (Prefix (Name)));
2949 -- We never need an actual subtype for the case of a selection
2950 -- for a indexed component of a non-packed array, since in
2951 -- this case gigi generates all the checks and can find the
2952 -- necessary bounds information.
2954 -- We also do not need an actual subtype for the case of
2955 -- a first, last, length, or range attribute applied to a
2956 -- non-packed array, since gigi can again get the bounds in
2957 -- these cases (gigi cannot handle the packed case, since it
2958 -- has the bounds of the packed array type, not the original
2959 -- bounds of the type). However, if the prefix is itself a
2960 -- selected component, as in a.b.c (i), gigi may regard a.b.c
2961 -- as a dynamic-sized temporary, so we do generate an actual
2962 -- subtype for this case.
2964 Parent_N := Parent (N);
2966 if not Is_Packed (Etype (Comp))
2968 ((Nkind (Parent_N) = N_Indexed_Component
2969 and then Nkind (Name) /= N_Selected_Component)
2971 (Nkind (Parent_N) = N_Attribute_Reference
2972 and then (Attribute_Name (Parent_N) = Name_First
2974 Attribute_Name (Parent_N) = Name_Last
2976 Attribute_Name (Parent_N) = Name_Length
2978 Attribute_Name (Parent_N) = Name_Range)))
2980 Set_Etype (N, Etype (Comp));
2982 -- If full analysis is not enabled, we do not generate an
2983 -- actual subtype, because in the absence of expansion
2984 -- reference to a formal of a protected type, for example,
2985 -- will not be properly transformed, and will lead to
2986 -- out-of-scope references in gigi.
2988 -- In all other cases, we currently build an actual subtype.
2989 -- It seems likely that many of these cases can be avoided,
2990 -- but right now, the front end makes direct references to the
2991 -- bounds (e.g. in generating a length check), and if we do
2992 -- not make an actual subtype, we end up getting a direct
2993 -- reference to a discriminant, which will not do.
2995 elsif Full_Analysis then
2997 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
2998 Insert_Action (N, Act_Decl);
3000 if No (Act_Decl) then
3001 Set_Etype (N, Etype (Comp));
3004 -- Component type depends on discriminants. Enter the
3005 -- main attributes of the subtype.
3008 Subt : constant Entity_Id :=
3009 Defining_Identifier (Act_Decl);
3012 Set_Etype (Subt, Base_Type (Etype (Comp)));
3013 Set_Ekind (Subt, Ekind (Etype (Comp)));
3014 Set_Etype (N, Subt);
3018 -- If Full_Analysis not enabled, just set the Etype
3021 Set_Etype (N, Etype (Comp));
3027 -- If the prefix is a private extension, check only the visible
3028 -- components of the partial view. This must include the tag,
3029 -- wich can appear in expanded code in a tag check.
3031 if Ekind (Type_To_Use) = E_Record_Type_With_Private
3032 and then Chars (Selector_Name (N)) /= Name_uTag
3034 exit when Comp = Last_Entity (Type_To_Use);
3040 -- Ada 2005 (AI-252)
3042 if Ada_Version >= Ada_05
3043 and then Is_Tagged_Type (Prefix_Type)
3044 and then Try_Object_Operation (N)
3048 -- If the transformation fails, it will be necessary to redo the
3049 -- analysis with all errors enabled, to indicate candidate
3050 -- interpretations and reasons for each failure ???
3054 elsif Is_Private_Type (Prefix_Type) then
3055 -- Allow access only to discriminants of the type. If the type has
3056 -- no full view, gigi uses the parent type for the components, so we
3057 -- do the same here.
3059 if No (Full_View (Prefix_Type)) then
3060 Type_To_Use := Root_Type (Base_Type (Prefix_Type));
3061 Comp := First_Entity (Type_To_Use);
3064 while Present (Comp) loop
3065 if Chars (Comp) = Chars (Sel) then
3066 if Ekind (Comp) = E_Discriminant then
3067 Set_Entity_With_Style_Check (Sel, Comp);
3068 Generate_Reference (Comp, Sel);
3070 Set_Etype (Sel, Etype (Comp));
3071 Set_Etype (N, Etype (Comp));
3073 if Is_Generic_Type (Prefix_Type)
3075 Is_Generic_Type (Root_Type (Prefix_Type))
3077 Set_Original_Discriminant (Sel, Comp);
3080 -- Before declararing an error, check whether this is tagged
3081 -- private type and a call to a primitive operation.
3083 elsif Ada_Version >= Ada_05
3084 and then Is_Tagged_Type (Prefix_Type)
3085 and then Try_Object_Operation (N)
3091 ("invisible selector for }",
3092 N, First_Subtype (Prefix_Type));
3093 Set_Entity (Sel, Any_Id);
3094 Set_Etype (N, Any_Type);
3103 elsif Is_Concurrent_Type (Prefix_Type) then
3105 -- Prefix is concurrent type. Find visible operation with given name
3106 -- For a task, this can only include entries or discriminants if the
3107 -- task type is not an enclosing scope. If it is an enclosing scope
3108 -- (e.g. in an inner task) then all entities are visible, but the
3109 -- prefix must denote the enclosing scope, i.e. can only be a direct
3110 -- name or an expanded name.
3112 Set_Etype (Sel, Any_Type);
3113 In_Scope := In_Open_Scopes (Prefix_Type);
3115 while Present (Comp) loop
3116 if Chars (Comp) = Chars (Sel) then
3117 if Is_Overloadable (Comp) then
3118 Add_One_Interp (Sel, Comp, Etype (Comp));
3120 elsif Ekind (Comp) = E_Discriminant
3121 or else Ekind (Comp) = E_Entry_Family
3123 and then Is_Entity_Name (Name))
3125 Set_Entity_With_Style_Check (Sel, Comp);
3126 Generate_Reference (Comp, Sel);
3132 Set_Etype (Sel, Etype (Comp));
3133 Set_Etype (N, Etype (Comp));
3135 if Ekind (Comp) = E_Discriminant then
3136 Set_Original_Discriminant (Sel, Comp);
3139 -- For access type case, introduce explicit deference for more
3140 -- uniform treatment of entry calls.
3142 if Is_Access_Type (Etype (Name)) then
3143 Insert_Explicit_Dereference (Name);
3145 (Warn_On_Dereference, "?implicit dereference", N);
3151 exit when not In_Scope
3153 Comp = First_Private_Entity (Base_Type (Prefix_Type));
3156 -- If there is no visible entry with the given name, and the task
3157 -- implements an interface, check whether there is some other
3158 -- primitive operation with that name.
3160 if Ada_Version >= Ada_05
3161 and then Is_Tagged_Type (Prefix_Type)
3163 if Etype (N) = Any_Type
3164 and then Try_Object_Operation (N)
3168 -- If the context is not syntactically a procedure call, it
3169 -- may be a call to a primitive function declared outside of
3170 -- the synchronized type.
3172 -- If the context is a procedure call, there might still be
3173 -- an overloading between an entry and a primitive procedure
3174 -- declared outside of the synchronized type, called in prefix
3175 -- notation. This is harder to disambiguate because in one case
3176 -- the controlling formal is implicit ???
3178 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
3179 and then Try_Object_Operation (N)
3185 Set_Is_Overloaded (N, Is_Overloaded (Sel));
3190 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
3193 -- If N still has no type, the component is not defined in the prefix
3195 if Etype (N) = Any_Type then
3197 -- If the prefix is a single concurrent object, use its name in the
3198 -- error message, rather than that of its anonymous type.
3200 if Is_Concurrent_Type (Prefix_Type)
3201 and then Is_Internal_Name (Chars (Prefix_Type))
3202 and then not Is_Derived_Type (Prefix_Type)
3203 and then Is_Entity_Name (Name)
3206 Error_Msg_Node_2 := Entity (Name);
3207 Error_Msg_NE ("no selector& for&", N, Sel);
3209 Check_Misspelled_Selector (Type_To_Use, Sel);
3211 elsif Is_Generic_Type (Prefix_Type)
3212 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
3213 and then Prefix_Type /= Etype (Prefix_Type)
3214 and then Is_Record_Type (Etype (Prefix_Type))
3216 -- If this is a derived formal type, the parent may have
3217 -- different visibility at this point. Try for an inherited
3218 -- component before reporting an error.
3220 Set_Etype (Prefix (N), Etype (Prefix_Type));
3221 Analyze_Selected_Component (N);
3224 elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
3225 and then Is_Generic_Actual_Type (Prefix_Type)
3226 and then Present (Full_View (Prefix_Type))
3228 -- Similarly, if this the actual for a formal derived type, the
3229 -- component inherited from the generic parent may not be visible
3230 -- in the actual, but the selected component is legal.
3237 First_Component (Generic_Parent_Type (Parent (Prefix_Type)));
3238 while Present (Comp) loop
3239 if Chars (Comp) = Chars (Sel) then
3240 Set_Entity_With_Style_Check (Sel, Comp);
3241 Set_Etype (Sel, Etype (Comp));
3242 Set_Etype (N, Etype (Comp));
3246 Next_Component (Comp);
3249 pragma Assert (Etype (N) /= Any_Type);
3253 if Ekind (Prefix_Type) = E_Record_Subtype then
3255 -- Check whether this is a component of the base type
3256 -- which is absent from a statically constrained subtype.
3257 -- This will raise constraint error at run-time, but is
3258 -- not a compile-time error. When the selector is illegal
3259 -- for base type as well fall through and generate a
3260 -- compilation error anyway.
3262 Comp := First_Component (Base_Type (Prefix_Type));
3263 while Present (Comp) loop
3264 if Chars (Comp) = Chars (Sel)
3265 and then Is_Visible_Component (Comp)
3267 Set_Entity_With_Style_Check (Sel, Comp);
3268 Generate_Reference (Comp, Sel);
3269 Set_Etype (Sel, Etype (Comp));
3270 Set_Etype (N, Etype (Comp));
3272 -- Emit appropriate message. Gigi will replace the
3273 -- node subsequently with the appropriate Raise.
3275 Apply_Compile_Time_Constraint_Error
3276 (N, "component not present in }?",
3277 CE_Discriminant_Check_Failed,
3278 Ent => Prefix_Type, Rep => False);
3279 Set_Raises_Constraint_Error (N);
3283 Next_Component (Comp);
3288 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
3289 Error_Msg_NE ("no selector& for}", N, Sel);
3291 Check_Misspelled_Selector (Type_To_Use, Sel);
3295 Set_Entity (Sel, Any_Id);
3296 Set_Etype (Sel, Any_Type);
3298 end Analyze_Selected_Component;
3300 ---------------------------
3301 -- Analyze_Short_Circuit --
3302 ---------------------------
3304 procedure Analyze_Short_Circuit (N : Node_Id) is
3305 L : constant Node_Id := Left_Opnd (N);
3306 R : constant Node_Id := Right_Opnd (N);
3311 Analyze_Expression (L);
3312 Analyze_Expression (R);
3313 Set_Etype (N, Any_Type);
3315 if not Is_Overloaded (L) then
3317 if Root_Type (Etype (L)) = Standard_Boolean
3318 and then Has_Compatible_Type (R, Etype (L))
3320 Add_One_Interp (N, Etype (L), Etype (L));
3324 Get_First_Interp (L, Ind, It);
3325 while Present (It.Typ) loop
3326 if Root_Type (It.Typ) = Standard_Boolean
3327 and then Has_Compatible_Type (R, It.Typ)
3329 Add_One_Interp (N, It.Typ, It.Typ);
3332 Get_Next_Interp (Ind, It);
3336 -- Here we have failed to find an interpretation. Clearly we
3337 -- know that it is not the case that both operands can have
3338 -- an interpretation of Boolean, but this is by far the most
3339 -- likely intended interpretation. So we simply resolve both
3340 -- operands as Booleans, and at least one of these resolutions
3341 -- will generate an error message, and we do not need to give
3342 -- a further error message on the short circuit operation itself.
3344 if Etype (N) = Any_Type then
3345 Resolve (L, Standard_Boolean);
3346 Resolve (R, Standard_Boolean);
3347 Set_Etype (N, Standard_Boolean);
3349 end Analyze_Short_Circuit;
3355 procedure Analyze_Slice (N : Node_Id) is
3356 P : constant Node_Id := Prefix (N);
3357 D : constant Node_Id := Discrete_Range (N);
3358 Array_Type : Entity_Id;
3360 procedure Analyze_Overloaded_Slice;
3361 -- If the prefix is overloaded, select those interpretations that
3362 -- yield a one-dimensional array type.
3364 ------------------------------
3365 -- Analyze_Overloaded_Slice --
3366 ------------------------------
3368 procedure Analyze_Overloaded_Slice is
3374 Set_Etype (N, Any_Type);
3376 Get_First_Interp (P, I, It);
3377 while Present (It.Nam) loop
3380 if Is_Access_Type (Typ) then
3381 Typ := Designated_Type (Typ);
3382 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3385 if Is_Array_Type (Typ)
3386 and then Number_Dimensions (Typ) = 1
3387 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
3389 Add_One_Interp (N, Typ, Typ);
3392 Get_Next_Interp (I, It);
3395 if Etype (N) = Any_Type then
3396 Error_Msg_N ("expect array type in prefix of slice", N);
3398 end Analyze_Overloaded_Slice;
3400 -- Start of processing for Analyze_Slice
3406 if Is_Overloaded (P) then
3407 Analyze_Overloaded_Slice;
3410 Array_Type := Etype (P);
3411 Set_Etype (N, Any_Type);
3413 if Is_Access_Type (Array_Type) then
3414 Array_Type := Designated_Type (Array_Type);
3415 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3418 if not Is_Array_Type (Array_Type) then
3419 Wrong_Type (P, Any_Array);
3421 elsif Number_Dimensions (Array_Type) > 1 then
3423 ("type is not one-dimensional array in slice prefix", N);
3426 Has_Compatible_Type (D, Etype (First_Index (Array_Type)))
3428 Wrong_Type (D, Etype (First_Index (Array_Type)));
3431 Set_Etype (N, Array_Type);
3436 -----------------------------
3437 -- Analyze_Type_Conversion --
3438 -----------------------------
3440 procedure Analyze_Type_Conversion (N : Node_Id) is
3441 Expr : constant Node_Id := Expression (N);
3445 -- If Conversion_OK is set, then the Etype is already set, and the
3446 -- only processing required is to analyze the expression. This is
3447 -- used to construct certain "illegal" conversions which are not
3448 -- allowed by Ada semantics, but can be handled OK by Gigi, see
3449 -- Sinfo for further details.
3451 if Conversion_OK (N) then
3456 -- Otherwise full type analysis is required, as well as some semantic
3457 -- checks to make sure the argument of the conversion is appropriate.
3459 Find_Type (Subtype_Mark (N));
3460 T := Entity (Subtype_Mark (N));
3462 Check_Fully_Declared (T, N);
3463 Analyze_Expression (Expr);
3464 Validate_Remote_Type_Type_Conversion (N);
3466 -- Only remaining step is validity checks on the argument. These
3467 -- are skipped if the conversion does not come from the source.
3469 if not Comes_From_Source (N) then
3472 -- If there was an error in a generic unit, no need to replicate the
3473 -- error message. Conversely, constant-folding in the generic may
3474 -- transform the argument of a conversion into a string literal, which
3475 -- is legal. Therefore the following tests are not performed in an
3478 elsif In_Instance then
3481 elsif Nkind (Expr) = N_Null then
3482 Error_Msg_N ("argument of conversion cannot be null", N);
3483 Error_Msg_N ("\use qualified expression instead", N);
3484 Set_Etype (N, Any_Type);
3486 elsif Nkind (Expr) = N_Aggregate then
3487 Error_Msg_N ("argument of conversion cannot be aggregate", N);
3488 Error_Msg_N ("\use qualified expression instead", N);
3490 elsif Nkind (Expr) = N_Allocator then
3491 Error_Msg_N ("argument of conversion cannot be an allocator", N);
3492 Error_Msg_N ("\use qualified expression instead", N);
3494 elsif Nkind (Expr) = N_String_Literal then
3495 Error_Msg_N ("argument of conversion cannot be string literal", N);
3496 Error_Msg_N ("\use qualified expression instead", N);
3498 elsif Nkind (Expr) = N_Character_Literal then
3499 if Ada_Version = Ada_83 then
3502 Error_Msg_N ("argument of conversion cannot be character literal",
3504 Error_Msg_N ("\use qualified expression instead", N);
3507 elsif Nkind (Expr) = N_Attribute_Reference
3509 (Attribute_Name (Expr) = Name_Access or else
3510 Attribute_Name (Expr) = Name_Unchecked_Access or else
3511 Attribute_Name (Expr) = Name_Unrestricted_Access)
3513 Error_Msg_N ("argument of conversion cannot be access", N);
3514 Error_Msg_N ("\use qualified expression instead", N);
3516 end Analyze_Type_Conversion;
3518 ----------------------
3519 -- Analyze_Unary_Op --
3520 ----------------------
3522 procedure Analyze_Unary_Op (N : Node_Id) is
3523 R : constant Node_Id := Right_Opnd (N);
3524 Op_Id : Entity_Id := Entity (N);
3527 Set_Etype (N, Any_Type);
3528 Candidate_Type := Empty;
3530 Analyze_Expression (R);
3532 if Present (Op_Id) then
3533 if Ekind (Op_Id) = E_Operator then
3534 Find_Unary_Types (R, Op_Id, N);
3536 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3540 Op_Id := Get_Name_Entity_Id (Chars (N));
3541 while Present (Op_Id) loop
3542 if Ekind (Op_Id) = E_Operator then
3543 if No (Next_Entity (First_Entity (Op_Id))) then
3544 Find_Unary_Types (R, Op_Id, N);
3547 elsif Is_Overloadable (Op_Id) then
3548 Analyze_User_Defined_Unary_Op (N, Op_Id);
3551 Op_Id := Homonym (Op_Id);
3556 end Analyze_Unary_Op;
3558 ----------------------------------
3559 -- Analyze_Unchecked_Expression --
3560 ----------------------------------
3562 procedure Analyze_Unchecked_Expression (N : Node_Id) is
3564 Analyze (Expression (N), Suppress => All_Checks);
3565 Set_Etype (N, Etype (Expression (N)));
3566 Save_Interps (Expression (N), N);
3567 end Analyze_Unchecked_Expression;
3569 ---------------------------------------
3570 -- Analyze_Unchecked_Type_Conversion --
3571 ---------------------------------------
3573 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
3575 Find_Type (Subtype_Mark (N));
3576 Analyze_Expression (Expression (N));
3577 Set_Etype (N, Entity (Subtype_Mark (N)));
3578 end Analyze_Unchecked_Type_Conversion;
3580 ------------------------------------
3581 -- Analyze_User_Defined_Binary_Op --
3582 ------------------------------------
3584 procedure Analyze_User_Defined_Binary_Op
3589 -- Only do analysis if the operator Comes_From_Source, since otherwise
3590 -- the operator was generated by the expander, and all such operators
3591 -- always refer to the operators in package Standard.
3593 if Comes_From_Source (N) then
3595 F1 : constant Entity_Id := First_Formal (Op_Id);
3596 F2 : constant Entity_Id := Next_Formal (F1);
3599 -- Verify that Op_Id is a visible binary function. Note that since
3600 -- we know Op_Id is overloaded, potentially use visible means use
3601 -- visible for sure (RM 9.4(11)).
3603 if Ekind (Op_Id) = E_Function
3604 and then Present (F2)
3605 and then (Is_Immediately_Visible (Op_Id)
3606 or else Is_Potentially_Use_Visible (Op_Id))
3607 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
3608 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
3610 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3612 if Debug_Flag_E then
3613 Write_Str ("user defined operator ");
3614 Write_Name (Chars (Op_Id));
3615 Write_Str (" on node ");
3616 Write_Int (Int (N));
3622 end Analyze_User_Defined_Binary_Op;
3624 -----------------------------------
3625 -- Analyze_User_Defined_Unary_Op --
3626 -----------------------------------
3628 procedure Analyze_User_Defined_Unary_Op
3633 -- Only do analysis if the operator Comes_From_Source, since otherwise
3634 -- the operator was generated by the expander, and all such operators
3635 -- always refer to the operators in package Standard.
3637 if Comes_From_Source (N) then
3639 F : constant Entity_Id := First_Formal (Op_Id);
3642 -- Verify that Op_Id is a visible unary function. Note that since
3643 -- we know Op_Id is overloaded, potentially use visible means use
3644 -- visible for sure (RM 9.4(11)).
3646 if Ekind (Op_Id) = E_Function
3647 and then No (Next_Formal (F))
3648 and then (Is_Immediately_Visible (Op_Id)
3649 or else Is_Potentially_Use_Visible (Op_Id))
3650 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
3652 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3656 end Analyze_User_Defined_Unary_Op;
3658 ---------------------------
3659 -- Check_Arithmetic_Pair --
3660 ---------------------------
3662 procedure Check_Arithmetic_Pair
3663 (T1, T2 : Entity_Id;
3667 Op_Name : constant Name_Id := Chars (Op_Id);
3669 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
3670 -- Check whether the fixed-point type Typ has a user-defined operator
3671 -- (multiplication or division) that should hide the corresponding
3672 -- predefined operator. Used to implement Ada 2005 AI-264, to make
3673 -- such operators more visible and therefore useful.
3675 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
3676 -- Get specific type (i.e. non-universal type if there is one)
3682 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
3683 Bas : constant Entity_Id := Base_Type (Typ);
3689 -- The operation is treated as primitive if it is declared in the
3690 -- same scope as the type, and therefore on the same entity chain.
3692 Ent := Next_Entity (Typ);
3693 while Present (Ent) loop
3694 if Chars (Ent) = Chars (Op) then
3695 F1 := First_Formal (Ent);
3696 F2 := Next_Formal (F1);
3698 -- The operation counts as primitive if either operand or
3699 -- result are of the given base type, and both operands are
3700 -- fixed point types.
3702 if (Base_Type (Etype (F1)) = Bas
3703 and then Is_Fixed_Point_Type (Etype (F2)))
3706 (Base_Type (Etype (F2)) = Bas
3707 and then Is_Fixed_Point_Type (Etype (F1)))
3710 (Base_Type (Etype (Ent)) = Bas
3711 and then Is_Fixed_Point_Type (Etype (F1))
3712 and then Is_Fixed_Point_Type (Etype (F2)))
3728 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
3730 if T1 = Universal_Integer or else T1 = Universal_Real then
3731 return Base_Type (T2);
3733 return Base_Type (T1);
3737 -- Start of processing for Check_Arithmetic_Pair
3740 if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
3742 if Is_Numeric_Type (T1)
3743 and then Is_Numeric_Type (T2)
3744 and then (Covers (T1, T2) or else Covers (T2, T1))
3746 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3749 elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
3751 if Is_Fixed_Point_Type (T1)
3752 and then (Is_Fixed_Point_Type (T2)
3753 or else T2 = Universal_Real)
3755 -- If Treat_Fixed_As_Integer is set then the Etype is already set
3756 -- and no further processing is required (this is the case of an
3757 -- operator constructed by Exp_Fixd for a fixed point operation)
3758 -- Otherwise add one interpretation with universal fixed result
3759 -- If the operator is given in functional notation, it comes
3760 -- from source and Fixed_As_Integer cannot apply.
3762 if (Nkind (N) not in N_Op
3763 or else not Treat_Fixed_As_Integer (N))
3765 (not Has_Fixed_Op (T1, Op_Id)
3766 or else Nkind (Parent (N)) = N_Type_Conversion)
3768 Add_One_Interp (N, Op_Id, Universal_Fixed);
3771 elsif Is_Fixed_Point_Type (T2)
3772 and then (Nkind (N) not in N_Op
3773 or else not Treat_Fixed_As_Integer (N))
3774 and then T1 = Universal_Real
3776 (not Has_Fixed_Op (T1, Op_Id)
3777 or else Nkind (Parent (N)) = N_Type_Conversion)
3779 Add_One_Interp (N, Op_Id, Universal_Fixed);
3781 elsif Is_Numeric_Type (T1)
3782 and then Is_Numeric_Type (T2)
3783 and then (Covers (T1, T2) or else Covers (T2, T1))
3785 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3787 elsif Is_Fixed_Point_Type (T1)
3788 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3789 or else T2 = Universal_Integer)
3791 Add_One_Interp (N, Op_Id, T1);
3793 elsif T2 = Universal_Real
3794 and then Base_Type (T1) = Base_Type (Standard_Integer)
3795 and then Op_Name = Name_Op_Multiply
3797 Add_One_Interp (N, Op_Id, Any_Fixed);
3799 elsif T1 = Universal_Real
3800 and then Base_Type (T2) = Base_Type (Standard_Integer)
3802 Add_One_Interp (N, Op_Id, Any_Fixed);
3804 elsif Is_Fixed_Point_Type (T2)
3805 and then (Base_Type (T1) = Base_Type (Standard_Integer)
3806 or else T1 = Universal_Integer)
3807 and then Op_Name = Name_Op_Multiply
3809 Add_One_Interp (N, Op_Id, T2);
3811 elsif T1 = Universal_Real and then T2 = Universal_Integer then
3812 Add_One_Interp (N, Op_Id, T1);
3814 elsif T2 = Universal_Real
3815 and then T1 = Universal_Integer
3816 and then Op_Name = Name_Op_Multiply
3818 Add_One_Interp (N, Op_Id, T2);
3821 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
3823 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
3824 -- set does not require any special processing, since the Etype is
3825 -- already set (case of operation constructed by Exp_Fixed).
3827 if Is_Integer_Type (T1)
3828 and then (Covers (T1, T2) or else Covers (T2, T1))
3830 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3833 elsif Op_Name = Name_Op_Expon then
3834 if Is_Numeric_Type (T1)
3835 and then not Is_Fixed_Point_Type (T1)
3836 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3837 or else T2 = Universal_Integer)
3839 Add_One_Interp (N, Op_Id, Base_Type (T1));
3842 else pragma Assert (Nkind (N) in N_Op_Shift);
3844 -- If not one of the predefined operators, the node may be one
3845 -- of the intrinsic functions. Its kind is always specific, and
3846 -- we can use it directly, rather than the name of the operation.
3848 if Is_Integer_Type (T1)
3849 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3850 or else T2 = Universal_Integer)
3852 Add_One_Interp (N, Op_Id, Base_Type (T1));
3855 end Check_Arithmetic_Pair;
3857 -------------------------------
3858 -- Check_Misspelled_Selector --
3859 -------------------------------
3861 procedure Check_Misspelled_Selector
3862 (Prefix : Entity_Id;
3865 Max_Suggestions : constant := 2;
3866 Nr_Of_Suggestions : Natural := 0;
3868 Suggestion_1 : Entity_Id := Empty;
3869 Suggestion_2 : Entity_Id := Empty;
3874 -- All the components of the prefix of selector Sel are matched
3875 -- against Sel and a count is maintained of possible misspellings.
3876 -- When at the end of the analysis there are one or two (not more!)
3877 -- possible misspellings, these misspellings will be suggested as
3878 -- possible correction.
3880 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
3882 -- Concurrent types should be handled as well ???
3887 Get_Name_String (Chars (Sel));
3890 S : constant String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
3893 Comp := First_Entity (Prefix);
3894 while Nr_Of_Suggestions <= Max_Suggestions
3895 and then Present (Comp)
3897 if Is_Visible_Component (Comp) then
3898 Get_Name_String (Chars (Comp));
3900 if Is_Bad_Spelling_Of (Name_Buffer (1 .. Name_Len), S) then
3901 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
3903 case Nr_Of_Suggestions is
3904 when 1 => Suggestion_1 := Comp;
3905 when 2 => Suggestion_2 := Comp;
3906 when others => exit;
3911 Comp := Next_Entity (Comp);
3914 -- Report at most two suggestions
3916 if Nr_Of_Suggestions = 1 then
3917 Error_Msg_NE ("\possible misspelling of&", Sel, Suggestion_1);
3919 elsif Nr_Of_Suggestions = 2 then
3920 Error_Msg_Node_2 := Suggestion_2;
3921 Error_Msg_NE ("\possible misspelling of& or&",
3925 end Check_Misspelled_Selector;
3927 ----------------------
3928 -- Defined_In_Scope --
3929 ----------------------
3931 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
3933 S1 : constant Entity_Id := Scope (Base_Type (T));
3936 or else (S1 = System_Aux_Id and then S = Scope (S1));
3937 end Defined_In_Scope;
3943 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
3949 Void_Interp_Seen : Boolean := False;
3952 pragma Warnings (Off, Boolean);
3955 if Ada_Version >= Ada_05 then
3956 Actual := First_Actual (N);
3957 while Present (Actual) loop
3959 -- Ada 2005 (AI-50217): Post an error in case of premature
3960 -- usage of an entity from the limited view.
3962 if not Analyzed (Etype (Actual))
3963 and then From_With_Type (Etype (Actual))
3965 Error_Msg_Qual_Level := 1;
3967 ("missing with_clause for scope of imported type&",
3968 Actual, Etype (Actual));
3969 Error_Msg_Qual_Level := 0;
3972 Next_Actual (Actual);
3976 -- Analyze each candidate call again, with full error reporting
3980 ("no candidate interpretations match the actuals:!", Nam);
3981 Err_Mode := All_Errors_Mode;
3982 All_Errors_Mode := True;
3984 -- If this is a call to an operation of a concurrent type,
3985 -- the failed interpretations have been removed from the
3986 -- name. Recover them to provide full diagnostics.
3988 if Nkind (Parent (Nam)) = N_Selected_Component then
3989 Set_Entity (Nam, Empty);
3990 New_Nam := New_Copy_Tree (Parent (Nam));
3991 Set_Is_Overloaded (New_Nam, False);
3992 Set_Is_Overloaded (Selector_Name (New_Nam), False);
3993 Set_Parent (New_Nam, Parent (Parent (Nam)));
3994 Analyze_Selected_Component (New_Nam);
3995 Get_First_Interp (Selector_Name (New_Nam), X, It);
3997 Get_First_Interp (Nam, X, It);
4000 while Present (It.Nam) loop
4001 if Etype (It.Nam) = Standard_Void_Type then
4002 Void_Interp_Seen := True;
4005 Analyze_One_Call (N, It.Nam, True, Success);
4006 Get_Next_Interp (X, It);
4009 if Nkind (N) = N_Function_Call then
4010 Get_First_Interp (Nam, X, It);
4011 while Present (It.Nam) loop
4012 if Ekind (It.Nam) = E_Function
4013 or else Ekind (It.Nam) = E_Operator
4017 Get_Next_Interp (X, It);
4021 -- If all interpretations are procedures, this deserves a
4022 -- more precise message. Ditto if this appears as the prefix
4023 -- of a selected component, which may be a lexical error.
4026 ("\context requires function call, found procedure name", Nam);
4028 if Nkind (Parent (N)) = N_Selected_Component
4029 and then N = Prefix (Parent (N))
4032 "\period should probably be semicolon", Parent (N));
4035 elsif Nkind (N) = N_Procedure_Call_Statement
4036 and then not Void_Interp_Seen
4039 "\function name found in procedure call", Nam);
4042 All_Errors_Mode := Err_Mode;
4045 ---------------------------
4046 -- Find_Arithmetic_Types --
4047 ---------------------------
4049 procedure Find_Arithmetic_Types
4054 Index1 : Interp_Index;
4055 Index2 : Interp_Index;
4059 procedure Check_Right_Argument (T : Entity_Id);
4060 -- Check right operand of operator
4062 --------------------------
4063 -- Check_Right_Argument --
4064 --------------------------
4066 procedure Check_Right_Argument (T : Entity_Id) is
4068 if not Is_Overloaded (R) then
4069 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
4071 Get_First_Interp (R, Index2, It2);
4072 while Present (It2.Typ) loop
4073 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
4074 Get_Next_Interp (Index2, It2);
4077 end Check_Right_Argument;
4079 -- Start processing for Find_Arithmetic_Types
4082 if not Is_Overloaded (L) then
4083 Check_Right_Argument (Etype (L));
4086 Get_First_Interp (L, Index1, It1);
4087 while Present (It1.Typ) loop
4088 Check_Right_Argument (It1.Typ);
4089 Get_Next_Interp (Index1, It1);
4093 end Find_Arithmetic_Types;
4095 ------------------------
4096 -- Find_Boolean_Types --
4097 ------------------------
4099 procedure Find_Boolean_Types
4104 Index : Interp_Index;
4107 procedure Check_Numeric_Argument (T : Entity_Id);
4108 -- Special case for logical operations one of whose operands is an
4109 -- integer literal. If both are literal the result is any modular type.
4111 ----------------------------
4112 -- Check_Numeric_Argument --
4113 ----------------------------
4115 procedure Check_Numeric_Argument (T : Entity_Id) is
4117 if T = Universal_Integer then
4118 Add_One_Interp (N, Op_Id, Any_Modular);
4120 elsif Is_Modular_Integer_Type (T) then
4121 Add_One_Interp (N, Op_Id, T);
4123 end Check_Numeric_Argument;
4125 -- Start of processing for Find_Boolean_Types
4128 if not Is_Overloaded (L) then
4129 if Etype (L) = Universal_Integer
4130 or else Etype (L) = Any_Modular
4132 if not Is_Overloaded (R) then
4133 Check_Numeric_Argument (Etype (R));
4136 Get_First_Interp (R, Index, It);
4137 while Present (It.Typ) loop
4138 Check_Numeric_Argument (It.Typ);
4139 Get_Next_Interp (Index, It);
4143 -- If operands are aggregates, we must assume that they may be
4144 -- boolean arrays, and leave disambiguation for the second pass.
4145 -- If only one is an aggregate, verify that the other one has an
4146 -- interpretation as a boolean array
4148 elsif Nkind (L) = N_Aggregate then
4149 if Nkind (R) = N_Aggregate then
4150 Add_One_Interp (N, Op_Id, Etype (L));
4152 elsif not Is_Overloaded (R) then
4153 if Valid_Boolean_Arg (Etype (R)) then
4154 Add_One_Interp (N, Op_Id, Etype (R));
4158 Get_First_Interp (R, Index, It);
4159 while Present (It.Typ) loop
4160 if Valid_Boolean_Arg (It.Typ) then
4161 Add_One_Interp (N, Op_Id, It.Typ);
4164 Get_Next_Interp (Index, It);
4168 elsif Valid_Boolean_Arg (Etype (L))
4169 and then Has_Compatible_Type (R, Etype (L))
4171 Add_One_Interp (N, Op_Id, Etype (L));
4175 Get_First_Interp (L, Index, It);
4176 while Present (It.Typ) loop
4177 if Valid_Boolean_Arg (It.Typ)
4178 and then Has_Compatible_Type (R, It.Typ)
4180 Add_One_Interp (N, Op_Id, It.Typ);
4183 Get_Next_Interp (Index, It);
4186 end Find_Boolean_Types;
4188 ---------------------------
4189 -- Find_Comparison_Types --
4190 ---------------------------
4192 procedure Find_Comparison_Types
4197 Index : Interp_Index;
4199 Found : Boolean := False;
4202 Scop : Entity_Id := Empty;
4204 procedure Try_One_Interp (T1 : Entity_Id);
4205 -- Routine to try one proposed interpretation. Note that the context
4206 -- of the operator plays no role in resolving the arguments, so that
4207 -- if there is more than one interpretation of the operands that is
4208 -- compatible with comparison, the operation is ambiguous.
4210 --------------------
4211 -- Try_One_Interp --
4212 --------------------
4214 procedure Try_One_Interp (T1 : Entity_Id) is
4217 -- If the operator is an expanded name, then the type of the operand
4218 -- must be defined in the corresponding scope. If the type is
4219 -- universal, the context will impose the correct type.
4222 and then not Defined_In_Scope (T1, Scop)
4223 and then T1 /= Universal_Integer
4224 and then T1 /= Universal_Real
4225 and then T1 /= Any_String
4226 and then T1 /= Any_Composite
4231 if Valid_Comparison_Arg (T1)
4232 and then Has_Compatible_Type (R, T1)
4235 and then Base_Type (T1) /= Base_Type (T_F)
4237 It := Disambiguate (L, I_F, Index, Any_Type);
4239 if It = No_Interp then
4240 Ambiguous_Operands (N);
4241 Set_Etype (L, Any_Type);
4255 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
4260 -- Start processing for Find_Comparison_Types
4263 -- If left operand is aggregate, the right operand has to
4264 -- provide a usable type for it.
4266 if Nkind (L) = N_Aggregate
4267 and then Nkind (R) /= N_Aggregate
4269 Find_Comparison_Types (R, L, Op_Id, N);
4273 if Nkind (N) = N_Function_Call
4274 and then Nkind (Name (N)) = N_Expanded_Name
4276 Scop := Entity (Prefix (Name (N)));
4278 -- The prefix may be a package renaming, and the subsequent test
4279 -- requires the original package.
4281 if Ekind (Scop) = E_Package
4282 and then Present (Renamed_Entity (Scop))
4284 Scop := Renamed_Entity (Scop);
4285 Set_Entity (Prefix (Name (N)), Scop);
4289 if not Is_Overloaded (L) then
4290 Try_One_Interp (Etype (L));
4293 Get_First_Interp (L, Index, It);
4294 while Present (It.Typ) loop
4295 Try_One_Interp (It.Typ);
4296 Get_Next_Interp (Index, It);
4299 end Find_Comparison_Types;
4301 ----------------------------------------
4302 -- Find_Non_Universal_Interpretations --
4303 ----------------------------------------
4305 procedure Find_Non_Universal_Interpretations
4311 Index : Interp_Index;
4315 if T1 = Universal_Integer
4316 or else T1 = Universal_Real
4318 if not Is_Overloaded (R) then
4320 (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
4322 Get_First_Interp (R, Index, It);
4323 while Present (It.Typ) loop
4324 if Covers (It.Typ, T1) then
4326 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
4329 Get_Next_Interp (Index, It);
4333 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
4335 end Find_Non_Universal_Interpretations;
4337 ------------------------------
4338 -- Find_Concatenation_Types --
4339 ------------------------------
4341 procedure Find_Concatenation_Types
4346 Op_Type : constant Entity_Id := Etype (Op_Id);
4349 if Is_Array_Type (Op_Type)
4350 and then not Is_Limited_Type (Op_Type)
4352 and then (Has_Compatible_Type (L, Op_Type)
4354 Has_Compatible_Type (L, Component_Type (Op_Type)))
4356 and then (Has_Compatible_Type (R, Op_Type)
4358 Has_Compatible_Type (R, Component_Type (Op_Type)))
4360 Add_One_Interp (N, Op_Id, Op_Type);
4362 end Find_Concatenation_Types;
4364 -------------------------
4365 -- Find_Equality_Types --
4366 -------------------------
4368 procedure Find_Equality_Types
4373 Index : Interp_Index;
4375 Found : Boolean := False;
4378 Scop : Entity_Id := Empty;
4380 procedure Try_One_Interp (T1 : Entity_Id);
4381 -- The context of the operator plays no role in resolving the
4382 -- arguments, so that if there is more than one interpretation
4383 -- of the operands that is compatible with equality, the construct
4384 -- is ambiguous and an error can be emitted now, after trying to
4385 -- disambiguate, i.e. applying preference rules.
4387 --------------------
4388 -- Try_One_Interp --
4389 --------------------
4391 procedure Try_One_Interp (T1 : Entity_Id) is
4393 -- If the operator is an expanded name, then the type of the operand
4394 -- must be defined in the corresponding scope. If the type is
4395 -- universal, the context will impose the correct type. An anonymous
4396 -- type for a 'Access reference is also universal in this sense, as
4397 -- the actual type is obtained from context.
4398 -- In Ada 2005, the equality operator for anonymous access types
4399 -- is declared in Standard, and preference rules apply to it.
4401 if Present (Scop) then
4402 if Defined_In_Scope (T1, Scop)
4403 or else T1 = Universal_Integer
4404 or else T1 = Universal_Real
4405 or else T1 = Any_Access
4406 or else T1 = Any_String
4407 or else T1 = Any_Composite
4408 or else (Ekind (T1) = E_Access_Subprogram_Type
4409 and then not Comes_From_Source (T1))
4413 elsif Ekind (T1) = E_Anonymous_Access_Type
4414 and then Scop = Standard_Standard
4419 -- The scope does not contain an operator for the type
4425 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
4426 -- Do not allow anonymous access types in equality operators.
4428 if Ada_Version < Ada_05
4429 and then Ekind (T1) = E_Anonymous_Access_Type
4434 if T1 /= Standard_Void_Type
4435 and then not Is_Limited_Type (T1)
4436 and then not Is_Limited_Composite (T1)
4437 and then Has_Compatible_Type (R, T1)
4440 and then Base_Type (T1) /= Base_Type (T_F)
4442 It := Disambiguate (L, I_F, Index, Any_Type);
4444 if It = No_Interp then
4445 Ambiguous_Operands (N);
4446 Set_Etype (L, Any_Type);
4459 if not Analyzed (L) then
4463 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
4465 -- Case of operator was not visible, Etype still set to Any_Type
4467 if Etype (N) = Any_Type then
4471 elsif Scop = Standard_Standard
4472 and then Ekind (T1) = E_Anonymous_Access_Type
4478 -- Start of processing for Find_Equality_Types
4481 -- If left operand is aggregate, the right operand has to
4482 -- provide a usable type for it.
4484 if Nkind (L) = N_Aggregate
4485 and then Nkind (R) /= N_Aggregate
4487 Find_Equality_Types (R, L, Op_Id, N);
4491 if Nkind (N) = N_Function_Call
4492 and then Nkind (Name (N)) = N_Expanded_Name
4494 Scop := Entity (Prefix (Name (N)));
4496 -- The prefix may be a package renaming, and the subsequent test
4497 -- requires the original package.
4499 if Ekind (Scop) = E_Package
4500 and then Present (Renamed_Entity (Scop))
4502 Scop := Renamed_Entity (Scop);
4503 Set_Entity (Prefix (Name (N)), Scop);
4507 if not Is_Overloaded (L) then
4508 Try_One_Interp (Etype (L));
4511 Get_First_Interp (L, Index, It);
4512 while Present (It.Typ) loop
4513 Try_One_Interp (It.Typ);
4514 Get_Next_Interp (Index, It);
4517 end Find_Equality_Types;
4519 -------------------------
4520 -- Find_Negation_Types --
4521 -------------------------
4523 procedure Find_Negation_Types
4528 Index : Interp_Index;
4532 if not Is_Overloaded (R) then
4533 if Etype (R) = Universal_Integer then
4534 Add_One_Interp (N, Op_Id, Any_Modular);
4535 elsif Valid_Boolean_Arg (Etype (R)) then
4536 Add_One_Interp (N, Op_Id, Etype (R));
4540 Get_First_Interp (R, Index, It);
4541 while Present (It.Typ) loop
4542 if Valid_Boolean_Arg (It.Typ) then
4543 Add_One_Interp (N, Op_Id, It.Typ);
4546 Get_Next_Interp (Index, It);
4549 end Find_Negation_Types;
4551 ----------------------
4552 -- Find_Unary_Types --
4553 ----------------------
4555 procedure Find_Unary_Types
4560 Index : Interp_Index;
4564 if not Is_Overloaded (R) then
4565 if Is_Numeric_Type (Etype (R)) then
4566 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
4570 Get_First_Interp (R, Index, It);
4571 while Present (It.Typ) loop
4572 if Is_Numeric_Type (It.Typ) then
4573 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
4576 Get_Next_Interp (Index, It);
4579 end Find_Unary_Types;
4585 function Junk_Operand (N : Node_Id) return Boolean is
4589 if Error_Posted (N) then
4593 -- Get entity to be tested
4595 if Is_Entity_Name (N)
4596 and then Present (Entity (N))
4600 -- An odd case, a procedure name gets converted to a very peculiar
4601 -- function call, and here is where we detect this happening.
4603 elsif Nkind (N) = N_Function_Call
4604 and then Is_Entity_Name (Name (N))
4605 and then Present (Entity (Name (N)))
4609 -- Another odd case, there are at least some cases of selected
4610 -- components where the selected component is not marked as having
4611 -- an entity, even though the selector does have an entity
4613 elsif Nkind (N) = N_Selected_Component
4614 and then Present (Entity (Selector_Name (N)))
4616 Enode := Selector_Name (N);
4622 -- Now test the entity we got to see if it is a bad case
4624 case Ekind (Entity (Enode)) is
4628 ("package name cannot be used as operand", Enode);
4630 when Generic_Unit_Kind =>
4632 ("generic unit name cannot be used as operand", Enode);
4636 ("subtype name cannot be used as operand", Enode);
4640 ("entry name cannot be used as operand", Enode);
4644 ("procedure name cannot be used as operand", Enode);
4648 ("exception name cannot be used as operand", Enode);
4650 when E_Block | E_Label | E_Loop =>
4652 ("label name cannot be used as operand", Enode);
4662 --------------------
4663 -- Operator_Check --
4664 --------------------
4666 procedure Operator_Check (N : Node_Id) is
4668 Remove_Abstract_Operations (N);
4670 -- Test for case of no interpretation found for operator
4672 if Etype (N) = Any_Type then
4676 Op_Id : Entity_Id := Empty;
4679 R := Right_Opnd (N);
4681 if Nkind (N) in N_Binary_Op then
4687 -- If either operand has no type, then don't complain further,
4688 -- since this simply means that we have a propagated error.
4691 or else Etype (R) = Any_Type
4692 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
4696 -- We explicitly check for the case of concatenation of component
4697 -- with component to avoid reporting spurious matching array types
4698 -- that might happen to be lurking in distant packages (such as
4699 -- run-time packages). This also prevents inconsistencies in the
4700 -- messages for certain ACVC B tests, which can vary depending on
4701 -- types declared in run-time interfaces. Another improvement when
4702 -- aggregates are present is to look for a well-typed operand.
4704 elsif Present (Candidate_Type)
4705 and then (Nkind (N) /= N_Op_Concat
4706 or else Is_Array_Type (Etype (L))
4707 or else Is_Array_Type (Etype (R)))
4710 if Nkind (N) = N_Op_Concat then
4711 if Etype (L) /= Any_Composite
4712 and then Is_Array_Type (Etype (L))
4714 Candidate_Type := Etype (L);
4716 elsif Etype (R) /= Any_Composite
4717 and then Is_Array_Type (Etype (R))
4719 Candidate_Type := Etype (R);
4724 ("operator for} is not directly visible!",
4725 N, First_Subtype (Candidate_Type));
4726 Error_Msg_N ("use clause would make operation legal!", N);
4729 -- If either operand is a junk operand (e.g. package name), then
4730 -- post appropriate error messages, but do not complain further.
4732 -- Note that the use of OR in this test instead of OR ELSE is
4733 -- quite deliberate, we may as well check both operands in the
4734 -- binary operator case.
4736 elsif Junk_Operand (R)
4737 or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
4741 -- If we have a logical operator, one of whose operands is
4742 -- Boolean, then we know that the other operand cannot resolve to
4743 -- Boolean (since we got no interpretations), but in that case we
4744 -- pretty much know that the other operand should be Boolean, so
4745 -- resolve it that way (generating an error)
4747 elsif Nkind (N) = N_Op_And
4751 Nkind (N) = N_Op_Xor
4753 if Etype (L) = Standard_Boolean then
4754 Resolve (R, Standard_Boolean);
4756 elsif Etype (R) = Standard_Boolean then
4757 Resolve (L, Standard_Boolean);
4761 -- For an arithmetic operator or comparison operator, if one
4762 -- of the operands is numeric, then we know the other operand
4763 -- is not the same numeric type. If it is a non-numeric type,
4764 -- then probably it is intended to match the other operand.
4766 elsif Nkind (N) = N_Op_Add or else
4767 Nkind (N) = N_Op_Divide or else
4768 Nkind (N) = N_Op_Ge or else
4769 Nkind (N) = N_Op_Gt or else
4770 Nkind (N) = N_Op_Le or else
4771 Nkind (N) = N_Op_Lt or else
4772 Nkind (N) = N_Op_Mod or else
4773 Nkind (N) = N_Op_Multiply or else
4774 Nkind (N) = N_Op_Rem or else
4775 Nkind (N) = N_Op_Subtract
4777 if Is_Numeric_Type (Etype (L))
4778 and then not Is_Numeric_Type (Etype (R))
4780 Resolve (R, Etype (L));
4783 elsif Is_Numeric_Type (Etype (R))
4784 and then not Is_Numeric_Type (Etype (L))
4786 Resolve (L, Etype (R));
4790 -- Comparisons on A'Access are common enough to deserve a
4793 elsif (Nkind (N) = N_Op_Eq or else
4794 Nkind (N) = N_Op_Ne)
4795 and then Ekind (Etype (L)) = E_Access_Attribute_Type
4796 and then Ekind (Etype (R)) = E_Access_Attribute_Type
4799 ("two access attributes cannot be compared directly", N);
4801 ("\use qualified expression for one of the operands",
4805 -- Another one for C programmers
4807 elsif Nkind (N) = N_Op_Concat
4808 and then Valid_Boolean_Arg (Etype (L))
4809 and then Valid_Boolean_Arg (Etype (R))
4811 Error_Msg_N ("invalid operands for concatenation", N);
4812 Error_Msg_N ("\maybe AND was meant", N);
4815 -- A special case for comparison of access parameter with null
4817 elsif Nkind (N) = N_Op_Eq
4818 and then Is_Entity_Name (L)
4819 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
4820 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
4822 and then Nkind (R) = N_Null
4824 Error_Msg_N ("access parameter is not allowed to be null", L);
4825 Error_Msg_N ("\(call would raise Constraint_Error)", L);
4829 -- If we fall through then just give general message. Note that in
4830 -- the following messages, if the operand is overloaded we choose
4831 -- an arbitrary type to complain about, but that is probably more
4832 -- useful than not giving a type at all.
4834 if Nkind (N) in N_Unary_Op then
4835 Error_Msg_Node_2 := Etype (R);
4836 Error_Msg_N ("operator& not defined for}", N);
4840 if Nkind (N) in N_Binary_Op then
4841 if not Is_Overloaded (L)
4842 and then not Is_Overloaded (R)
4843 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
4845 Error_Msg_Node_2 := First_Subtype (Etype (R));
4846 Error_Msg_N ("there is no applicable operator& for}", N);
4849 -- Another attempt to find a fix: one of the candidate
4850 -- interpretations may not be use-visible. This has
4851 -- already been checked for predefined operators, so
4852 -- we examine only user-defined functions.
4854 Op_Id := Get_Name_Entity_Id (Chars (N));
4856 while Present (Op_Id) loop
4857 if Ekind (Op_Id) /= E_Operator
4858 and then Is_Overloadable (Op_Id)
4860 if not Is_Immediately_Visible (Op_Id)
4861 and then not In_Use (Scope (Op_Id))
4862 and then not Is_Abstract_Subprogram (Op_Id)
4863 and then not Is_Hidden (Op_Id)
4864 and then Ekind (Scope (Op_Id)) = E_Package
4867 (L, Etype (First_Formal (Op_Id)))
4869 (Next_Formal (First_Formal (Op_Id)))
4873 Etype (Next_Formal (First_Formal (Op_Id))))
4876 ("No legal interpretation for operator&", N);
4878 ("\use clause on& would make operation legal",
4884 Op_Id := Homonym (Op_Id);
4888 Error_Msg_N ("invalid operand types for operator&", N);
4890 if Nkind (N) /= N_Op_Concat then
4891 Error_Msg_NE ("\left operand has}!", N, Etype (L));
4892 Error_Msg_NE ("\right operand has}!", N, Etype (R));
4902 -----------------------------------------
4903 -- Process_Implicit_Dereference_Prefix --
4904 -----------------------------------------
4906 procedure Process_Implicit_Dereference_Prefix
4914 and then (Operating_Mode = Check_Semantics or else not Expander_Active)
4916 -- We create a dummy reference to E to ensure that the reference
4917 -- is not considered as part of an assignment (an implicit
4918 -- dereference can never assign to its prefix). The Comes_From_Source
4919 -- attribute needs to be propagated for accurate warnings.
4921 Ref := New_Reference_To (E, Sloc (P));
4922 Set_Comes_From_Source (Ref, Comes_From_Source (P));
4923 Generate_Reference (E, Ref);
4925 end Process_Implicit_Dereference_Prefix;
4927 --------------------------------
4928 -- Remove_Abstract_Operations --
4929 --------------------------------
4931 procedure Remove_Abstract_Operations (N : Node_Id) is
4932 Abstract_Op : Entity_Id := Empty;
4933 Address_Kludge : Boolean := False;
4937 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
4938 -- activate this if either extensions are enabled, or if the abstract
4939 -- operation in question comes from a predefined file. This latter test
4940 -- allows us to use abstract to make operations invisible to users. In
4941 -- particular, if type Address is non-private and abstract subprograms
4942 -- are used to hide its operators, they will be truly hidden.
4944 type Operand_Position is (First_Op, Second_Op);
4945 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
4947 procedure Remove_Address_Interpretations (Op : Operand_Position);
4948 -- Ambiguities may arise when the operands are literal and the address
4949 -- operations in s-auxdec are visible. In that case, remove the
4950 -- interpretation of a literal as Address, to retain the semantics of
4951 -- Address as a private type.
4953 ------------------------------------
4954 -- Remove_Address_Interpretations --
4955 ------------------------------------
4957 procedure Remove_Address_Interpretations (Op : Operand_Position) is
4961 if Is_Overloaded (N) then
4962 Get_First_Interp (N, I, It);
4963 while Present (It.Nam) loop
4964 Formal := First_Entity (It.Nam);
4966 if Op = Second_Op then
4967 Formal := Next_Entity (Formal);
4970 if Is_Descendent_Of_Address (Etype (Formal)) then
4971 Address_Kludge := True;
4975 Get_Next_Interp (I, It);
4978 end Remove_Address_Interpretations;
4980 -- Start of processing for Remove_Abstract_Operations
4983 if Is_Overloaded (N) then
4984 Get_First_Interp (N, I, It);
4986 while Present (It.Nam) loop
4987 if Is_Overloadable (It.Nam)
4988 and then Is_Abstract_Subprogram (It.Nam)
4989 and then not Is_Dispatching_Operation (It.Nam)
4991 Abstract_Op := It.Nam;
4993 if Is_Descendent_Of_Address (It.Typ) then
4994 Address_Kludge := True;
4998 -- In Ada 2005, this operation does not participate in Overload
4999 -- resolution. If the operation is defined in a predefined
5000 -- unit, it is one of the operations declared abstract in some
5001 -- variants of System, and it must be removed as well.
5003 elsif Ada_Version >= Ada_05
5004 or else Is_Predefined_File_Name
5005 (Unit_File_Name (Get_Source_Unit (It.Nam)))
5012 Get_Next_Interp (I, It);
5015 if No (Abstract_Op) then
5017 -- If some interpretation yields an integer type, it is still
5018 -- possible that there are address interpretations. Remove them
5019 -- if one operand is a literal, to avoid spurious ambiguities
5020 -- on systems where Address is a visible integer type.
5022 if Is_Overloaded (N)
5023 and then Nkind (N) in N_Op
5024 and then Is_Integer_Type (Etype (N))
5026 if Nkind (N) in N_Binary_Op then
5027 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
5028 Remove_Address_Interpretations (Second_Op);
5030 elsif Nkind (Right_Opnd (N)) = N_Integer_Literal then
5031 Remove_Address_Interpretations (First_Op);
5036 elsif Nkind (N) in N_Op then
5038 -- Remove interpretations that treat literals as addresses. This
5039 -- is never appropriate, even when Address is defined as a visible
5040 -- Integer type. The reason is that we would really prefer Address
5041 -- to behave as a private type, even in this case, which is there
5042 -- only to accomodate oddities of VMS address sizes. If Address is
5043 -- a visible integer type, we get lots of overload ambiguities.
5045 if Nkind (N) in N_Binary_Op then
5047 U1 : constant Boolean :=
5048 Present (Universal_Interpretation (Right_Opnd (N)));
5049 U2 : constant Boolean :=
5050 Present (Universal_Interpretation (Left_Opnd (N)));
5054 Remove_Address_Interpretations (Second_Op);
5058 Remove_Address_Interpretations (First_Op);
5061 if not (U1 and U2) then
5063 -- Remove corresponding predefined operator, which is
5064 -- always added to the overload set.
5066 Get_First_Interp (N, I, It);
5067 while Present (It.Nam) loop
5068 if Scope (It.Nam) = Standard_Standard
5069 and then Base_Type (It.Typ) =
5070 Base_Type (Etype (Abstract_Op))
5075 Get_Next_Interp (I, It);
5078 elsif Is_Overloaded (N)
5079 and then Present (Univ_Type)
5081 -- If both operands have a universal interpretation,
5082 -- it is still necessary to remove interpretations that
5083 -- yield Address. Any remaining ambiguities will be
5084 -- removed in Disambiguate.
5086 Get_First_Interp (N, I, It);
5087 while Present (It.Nam) loop
5088 if Is_Descendent_Of_Address (It.Typ) then
5091 elsif not Is_Type (It.Nam) then
5092 Set_Entity (N, It.Nam);
5095 Get_Next_Interp (I, It);
5101 elsif Nkind (N) = N_Function_Call
5103 (Nkind (Name (N)) = N_Operator_Symbol
5105 (Nkind (Name (N)) = N_Expanded_Name
5107 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
5111 Arg1 : constant Node_Id := First (Parameter_Associations (N));
5112 U1 : constant Boolean :=
5113 Present (Universal_Interpretation (Arg1));
5114 U2 : constant Boolean :=
5115 Present (Next (Arg1)) and then
5116 Present (Universal_Interpretation (Next (Arg1)));
5120 Remove_Address_Interpretations (First_Op);
5124 Remove_Address_Interpretations (Second_Op);
5127 if not (U1 and U2) then
5128 Get_First_Interp (N, I, It);
5129 while Present (It.Nam) loop
5130 if Scope (It.Nam) = Standard_Standard
5131 and then It.Typ = Base_Type (Etype (Abstract_Op))
5136 Get_Next_Interp (I, It);
5142 -- If the removal has left no valid interpretations, emit an error
5143 -- message now and label node as illegal.
5145 if Present (Abstract_Op) then
5146 Get_First_Interp (N, I, It);
5150 -- Removal of abstract operation left no viable candidate
5152 Set_Etype (N, Any_Type);
5153 Error_Msg_Sloc := Sloc (Abstract_Op);
5155 ("cannot call abstract operation& declared#", N, Abstract_Op);
5157 -- In Ada 2005, an abstract operation may disable predefined
5158 -- operators. Since the context is not yet known, we mark the
5159 -- predefined operators as potentially hidden. Do not include
5160 -- predefined operators when addresses are involved since this
5161 -- case is handled separately.
5163 elsif Ada_Version >= Ada_05
5164 and then not Address_Kludge
5166 while Present (It.Nam) loop
5167 if Is_Numeric_Type (It.Typ)
5168 and then Scope (It.Typ) = Standard_Standard
5170 Set_Abstract_Op (I, Abstract_Op);
5173 Get_Next_Interp (I, It);
5178 end Remove_Abstract_Operations;
5180 -----------------------
5181 -- Try_Indirect_Call --
5182 -----------------------
5184 function Try_Indirect_Call
5187 Typ : Entity_Id) return Boolean
5193 pragma Warnings (Off, Call_OK);
5196 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
5198 Actual := First_Actual (N);
5199 Formal := First_Formal (Designated_Type (Typ));
5200 while Present (Actual) and then Present (Formal) loop
5201 if not Has_Compatible_Type (Actual, Etype (Formal)) then
5206 Next_Formal (Formal);
5209 if No (Actual) and then No (Formal) then
5210 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
5212 -- Nam is a candidate interpretation for the name in the call,
5213 -- if it is not an indirect call.
5215 if not Is_Type (Nam)
5216 and then Is_Entity_Name (Name (N))
5218 Set_Entity (Name (N), Nam);
5225 end Try_Indirect_Call;
5227 ----------------------
5228 -- Try_Indexed_Call --
5229 ----------------------
5231 function Try_Indexed_Call
5235 Skip_First : Boolean) return Boolean
5237 Actuals : constant List_Id := Parameter_Associations (N);
5242 Actual := First (Actuals);
5244 -- If the call was originally written in prefix form, skip the first
5245 -- actual, which is obviously not defaulted.
5251 Index := First_Index (Typ);
5252 while Present (Actual) and then Present (Index) loop
5254 -- If the parameter list has a named association, the expression
5255 -- is definitely a call and not an indexed component.
5257 if Nkind (Actual) = N_Parameter_Association then
5261 if not Has_Compatible_Type (Actual, Etype (Index)) then
5269 if No (Actual) and then No (Index) then
5270 Add_One_Interp (N, Nam, Component_Type (Typ));
5272 -- Nam is a candidate interpretation for the name in the call,
5273 -- if it is not an indirect call.
5275 if not Is_Type (Nam)
5276 and then Is_Entity_Name (Name (N))
5278 Set_Entity (Name (N), Nam);
5285 end Try_Indexed_Call;
5287 --------------------------
5288 -- Try_Object_Operation --
5289 --------------------------
5291 function Try_Object_Operation (N : Node_Id) return Boolean is
5292 K : constant Node_Kind := Nkind (Parent (N));
5293 Loc : constant Source_Ptr := Sloc (N);
5294 Candidate : Entity_Id := Empty;
5295 Is_Subprg_Call : constant Boolean := K = N_Procedure_Call_Statement
5296 or else K = N_Function_Call;
5297 Obj : constant Node_Id := Prefix (N);
5298 Subprog : constant Node_Id :=
5299 Make_Identifier (Sloc (Selector_Name (N)),
5300 Chars => Chars (Selector_Name (N)));
5301 -- Identifier on which possible interpretations will be collected
5303 Success : Boolean := False;
5305 Report_Error : Boolean := False;
5306 -- If no candidate interpretation matches the context, redo the
5307 -- analysis with error enabled to provide additional information.
5310 New_Call_Node : Node_Id := Empty;
5311 Node_To_Replace : Node_Id;
5312 Obj_Type : Entity_Id := Etype (Obj);
5314 function Valid_Candidate
5317 Subp : Entity_Id) return Entity_Id;
5318 -- If the subprogram is a valid interpretation, record it, and add
5319 -- to the list of interpretations of Subprog.
5321 procedure Complete_Object_Operation
5322 (Call_Node : Node_Id;
5323 Node_To_Replace : Node_Id);
5324 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
5325 -- Call_Node, insert the object (or its dereference) as the first actual
5326 -- in the call, and complete the analysis of the call.
5328 procedure Report_Ambiguity (Op : Entity_Id);
5329 -- If a prefixed procedure call is ambiguous, indicate whether the
5330 -- call includes an implicit dereference or an implicit 'Access.
5332 procedure Transform_Object_Operation
5333 (Call_Node : out Node_Id;
5334 Node_To_Replace : out Node_Id);
5335 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
5336 -- Call_Node is the resulting subprogram call,
5337 -- Node_To_Replace is either N or the parent of N, and Subprog
5338 -- is a reference to the subprogram we are trying to match.
5340 function Try_Class_Wide_Operation
5341 (Call_Node : Node_Id;
5342 Node_To_Replace : Node_Id) return Boolean;
5343 -- Traverse all ancestor types looking for a class-wide subprogram
5344 -- for which the current operation is a valid non-dispatching call.
5346 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
5347 -- If prefix is overloaded, its interpretation may include different
5348 -- tagged types, and we must examine the primitive operations and
5349 -- the class-wide operations of each in order to find candidate
5350 -- interpretations for the call as a whole.
5352 function Try_Primitive_Operation
5353 (Call_Node : Node_Id;
5354 Node_To_Replace : Node_Id) return Boolean;
5355 -- Traverse the list of primitive subprograms looking for a dispatching
5356 -- operation for which the current node is a valid call .
5358 ---------------------
5359 -- Valid_Candidate --
5360 ---------------------
5362 function Valid_Candidate
5365 Subp : Entity_Id) return Entity_Id
5367 Comp_Type : Entity_Id;
5370 -- If the subprogram is a valid interpretation, record it in global
5371 -- variable Subprog, to collect all possible overloadings.
5374 if Subp /= Entity (Subprog) then
5375 Add_One_Interp (Subprog, Subp, Etype (Subp));
5379 -- If the call may be an indexed call, retrieve component type
5380 -- of resulting expression, and add possible interpretation.
5384 if Nkind (Call) = N_Function_Call
5385 and then Nkind (Parent (N)) = N_Indexed_Component
5386 and then Needs_One_Actual (Subp)
5388 if Is_Array_Type (Etype (Subp)) then
5389 Comp_Type := Component_Type (Etype (Subp));
5391 elsif Is_Access_Type (Etype (Subp))
5392 and then Is_Array_Type (Designated_Type (Etype (Subp)))
5394 Comp_Type := Component_Type (Designated_Type (Etype (Subp)));
5398 if Present (Comp_Type)
5399 and then Etype (Subprog) /= Comp_Type
5401 Add_One_Interp (Subprog, Subp, Comp_Type);
5404 if Etype (Call) /= Any_Type then
5409 end Valid_Candidate;
5411 -------------------------------
5412 -- Complete_Object_Operation --
5413 -------------------------------
5415 procedure Complete_Object_Operation
5416 (Call_Node : Node_Id;
5417 Node_To_Replace : Node_Id)
5419 Formal_Type : constant Entity_Id :=
5420 Etype (First_Formal (Entity (Subprog)));
5421 First_Actual : Node_Id;
5424 -- Place the name of the operation, with its interpretations,
5425 -- on the rewritten call.
5427 Set_Name (Call_Node, Subprog);
5429 First_Actual := First (Parameter_Associations (Call_Node));
5431 -- For cross-reference purposes, treat the new node as being in
5432 -- the source if the original one is.
5434 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
5435 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
5437 if Nkind (N) = N_Selected_Component
5438 and then not Inside_A_Generic
5440 Set_Entity (Selector_Name (N), Entity (Subprog));
5443 -- If need be, rewrite first actual as an explicit dereference
5444 -- If the call is overloaded, the rewriting can only be done
5445 -- once the primitive operation is identified.
5447 if Is_Overloaded (Subprog) then
5449 -- The prefix itself may be overloaded, and its interpretations
5450 -- must be propagated to the new actual in the call.
5452 if Is_Overloaded (Obj) then
5453 Save_Interps (Obj, First_Actual);
5456 Rewrite (First_Actual, Obj);
5458 elsif not Is_Access_Type (Formal_Type)
5459 and then Is_Access_Type (Etype (Obj))
5461 Rewrite (First_Actual,
5462 Make_Explicit_Dereference (Sloc (Obj), Obj));
5463 Analyze (First_Actual);
5465 -- If we need to introduce an explicit dereference, verify that
5466 -- the resulting actual is compatible with the mode of the formal.
5468 if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
5469 and then Is_Access_Constant (Etype (Obj))
5472 ("expect variable in call to&", Prefix (N), Entity (Subprog));
5475 -- Conversely, if the formal is an access parameter and the
5476 -- object is not, replace the actual with a 'Access reference.
5477 -- Its analysis will check that the object is aliased.
5479 elsif Is_Access_Type (Formal_Type)
5480 and then not Is_Access_Type (Etype (Obj))
5482 Rewrite (First_Actual,
5483 Make_Attribute_Reference (Loc,
5484 Attribute_Name => Name_Access,
5485 Prefix => Relocate_Node (Obj)));
5487 if not Is_Aliased_View (Obj) then
5489 ("object in prefixed call to& must be aliased"
5490 & " (RM-2005 4.3.1 (13))",
5491 Prefix (First_Actual), Subprog);
5494 Analyze (First_Actual);
5497 if Is_Overloaded (Obj) then
5498 Save_Interps (Obj, First_Actual);
5501 Rewrite (First_Actual, Obj);
5504 Rewrite (Node_To_Replace, Call_Node);
5506 -- Propagate the interpretations collected in subprog to the new
5507 -- function call node, to be resolved from context.
5509 if Is_Overloaded (Subprog) then
5510 Save_Interps (Subprog, Node_To_Replace);
5512 Analyze (Node_To_Replace);
5514 end Complete_Object_Operation;
5516 ----------------------
5517 -- Report_Ambiguity --
5518 ----------------------
5520 procedure Report_Ambiguity (Op : Entity_Id) is
5521 Access_Formal : constant Boolean :=
5522 Is_Access_Type (Etype (First_Formal (Op)));
5523 Access_Actual : constant Boolean :=
5524 Is_Access_Type (Etype (Prefix (N)));
5527 Error_Msg_Sloc := Sloc (Op);
5529 if Access_Formal and then not Access_Actual then
5530 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
5532 ("\possible interpretation"
5533 & " (inherited, with implicit 'Access) #", N);
5536 ("\possible interpretation (with implicit 'Access) #", N);
5539 elsif not Access_Formal and then Access_Actual then
5540 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
5542 ("\possible interpretation"
5543 & " ( inherited, with implicit dereference) #", N);
5546 ("\possible interpretation (with implicit dereference) #", N);
5550 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
5551 Error_Msg_N ("\possible interpretation (inherited)#", N);
5553 Error_Msg_N ("\possible interpretation#", N);
5556 end Report_Ambiguity;
5558 --------------------------------
5559 -- Transform_Object_Operation --
5560 --------------------------------
5562 procedure Transform_Object_Operation
5563 (Call_Node : out Node_Id;
5564 Node_To_Replace : out Node_Id)
5566 Parent_Node : constant Node_Id := Parent (N);
5568 Dummy : constant Node_Id := New_Copy (Obj);
5569 -- Placeholder used as a first parameter in the call, replaced
5570 -- eventually by the proper object.
5576 -- Common case covering 1) Call to a procedure and 2) Call to a
5577 -- function that has some additional actuals.
5579 if (Nkind (Parent_Node) = N_Function_Call
5581 Nkind (Parent_Node) = N_Procedure_Call_Statement)
5583 -- N is a selected component node containing the name of the
5584 -- subprogram. If N is not the name of the parent node we must
5585 -- not replace the parent node by the new construct. This case
5586 -- occurs when N is a parameterless call to a subprogram that
5587 -- is an actual parameter of a call to another subprogram. For
5589 -- Some_Subprogram (..., Obj.Operation, ...)
5591 and then Name (Parent_Node) = N
5593 Node_To_Replace := Parent_Node;
5595 Actuals := Parameter_Associations (Parent_Node);
5597 if Present (Actuals) then
5598 Prepend (Dummy, Actuals);
5600 Actuals := New_List (Dummy);
5603 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
5605 Make_Procedure_Call_Statement (Loc,
5606 Name => New_Copy (Subprog),
5607 Parameter_Associations => Actuals);
5611 Make_Function_Call (Loc,
5612 Name => New_Copy (Subprog),
5613 Parameter_Associations => Actuals);
5617 -- Before analysis, the function call appears as an indexed component
5618 -- if there are no named associations.
5620 elsif Nkind (Parent_Node) = N_Indexed_Component
5621 and then N = Prefix (Parent_Node)
5623 Node_To_Replace := Parent_Node;
5625 Actuals := Expressions (Parent_Node);
5627 Actual := First (Actuals);
5628 while Present (Actual) loop
5633 Prepend (Dummy, Actuals);
5636 Make_Function_Call (Loc,
5637 Name => New_Copy (Subprog),
5638 Parameter_Associations => Actuals);
5640 -- Parameterless call: Obj.F is rewritten as F (Obj)
5643 Node_To_Replace := N;
5646 Make_Function_Call (Loc,
5647 Name => New_Copy (Subprog),
5648 Parameter_Associations => New_List (Dummy));
5650 end Transform_Object_Operation;
5652 ------------------------------
5653 -- Try_Class_Wide_Operation --
5654 ------------------------------
5656 function Try_Class_Wide_Operation
5657 (Call_Node : Node_Id;
5658 Node_To_Replace : Node_Id) return Boolean
5660 Anc_Type : Entity_Id;
5661 Matching_Op : Entity_Id := Empty;
5664 procedure Traverse_Homonyms
5665 (Anc_Type : Entity_Id;
5666 Error : out Boolean);
5667 -- Traverse the homonym chain of the subprogram searching for those
5668 -- homonyms whose first formal has the Anc_Type's class-wide type,
5669 -- or an anonymous access type designating the class-wide type. If an
5670 -- ambiguity is detected, then Error is set to True.
5672 procedure Traverse_Interfaces
5673 (Anc_Type : Entity_Id;
5674 Error : out Boolean);
5675 -- Traverse the list of interfaces, if any, associated with Anc_Type
5676 -- and search for acceptable class-wide homonyms associated with each
5677 -- interface. If an ambiguity is detected, then Error is set to True.
5679 -----------------------
5680 -- Traverse_Homonyms --
5681 -----------------------
5683 procedure Traverse_Homonyms
5684 (Anc_Type : Entity_Id;
5685 Error : out Boolean)
5687 Cls_Type : Entity_Id;
5695 Cls_Type := Class_Wide_Type (Anc_Type);
5697 Hom := Current_Entity (Subprog);
5699 -- Find operation whose first parameter is of the class-wide
5700 -- type, a subtype thereof, or an anonymous access to same.
5702 while Present (Hom) loop
5703 if (Ekind (Hom) = E_Procedure
5705 Ekind (Hom) = E_Function)
5706 and then Scope (Hom) = Scope (Anc_Type)
5707 and then Present (First_Formal (Hom))
5709 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
5711 (Is_Access_Type (Etype (First_Formal (Hom)))
5713 Ekind (Etype (First_Formal (Hom))) =
5714 E_Anonymous_Access_Type
5717 (Designated_Type (Etype (First_Formal (Hom)))) =
5720 Set_Etype (Call_Node, Any_Type);
5721 Set_Is_Overloaded (Call_Node, False);
5724 if No (Matching_Op) then
5725 Hom_Ref := New_Reference_To (Hom, Sloc (Subprog));
5726 Set_Etype (Call_Node, Any_Type);
5727 Set_Parent (Call_Node, Parent (Node_To_Replace));
5729 Set_Name (Call_Node, Hom_Ref);
5734 Report => Report_Error,
5736 Skip_First => True);
5739 Valid_Candidate (Success, Call_Node, Hom);
5745 Report => Report_Error,
5747 Skip_First => True);
5749 if Present (Valid_Candidate (Success, Call_Node, Hom))
5750 and then Nkind (Call_Node) /= N_Function_Call
5752 Error_Msg_NE ("ambiguous call to&", N, Hom);
5753 Report_Ambiguity (Matching_Op);
5754 Report_Ambiguity (Hom);
5761 Hom := Homonym (Hom);
5763 end Traverse_Homonyms;
5765 -------------------------
5766 -- Traverse_Interfaces --
5767 -------------------------
5769 procedure Traverse_Interfaces
5770 (Anc_Type : Entity_Id;
5771 Error : out Boolean)
5774 Intface_List : constant List_Id :=
5775 Abstract_Interface_List (Anc_Type);
5780 if Is_Non_Empty_List (Intface_List) then
5781 Intface := First (Intface_List);
5782 while Present (Intface) loop
5784 -- Look for acceptable class-wide homonyms associated with
5787 Traverse_Homonyms (Etype (Intface), Error);
5793 -- Continue the search by looking at each of the interface's
5794 -- associated interface ancestors.
5796 Traverse_Interfaces (Etype (Intface), Error);
5805 end Traverse_Interfaces;
5807 -- Start of processing for Try_Class_Wide_Operation
5810 -- Loop through ancestor types (including interfaces), traversing the
5811 -- homonym chain of the subprogram, and trying out those homonyms
5812 -- whose first formal has the class-wide type of the ancestor, or an
5813 -- anonymous access type designating the class-wide type.
5815 Anc_Type := Obj_Type;
5817 -- Look for a match among homonyms associated with the ancestor
5819 Traverse_Homonyms (Anc_Type, Error);
5825 -- Continue the search for matches among homonyms associated with
5826 -- any interfaces implemented by the ancestor.
5828 Traverse_Interfaces (Anc_Type, Error);
5834 exit when Etype (Anc_Type) = Anc_Type;
5835 Anc_Type := Etype (Anc_Type);
5838 if Present (Matching_Op) then
5839 Set_Etype (Call_Node, Etype (Matching_Op));
5842 return Present (Matching_Op);
5843 end Try_Class_Wide_Operation;
5845 -----------------------------------
5846 -- Try_One_Prefix_Interpretation --
5847 -----------------------------------
5849 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
5853 if Is_Access_Type (Obj_Type) then
5854 Obj_Type := Designated_Type (Obj_Type);
5857 if Ekind (Obj_Type) = E_Private_Subtype then
5858 Obj_Type := Base_Type (Obj_Type);
5861 if Is_Class_Wide_Type (Obj_Type) then
5862 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
5865 -- The type may have be obtained through a limited_with clause,
5866 -- in which case the primitive operations are available on its
5867 -- non-limited view. If still incomplete, retrieve full view.
5869 if Ekind (Obj_Type) = E_Incomplete_Type
5870 and then From_With_Type (Obj_Type)
5872 Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
5875 -- If the object is not tagged, or the type is still an incomplete
5876 -- type, this is not a prefixed call.
5878 if not Is_Tagged_Type (Obj_Type)
5879 or else Is_Incomplete_Type (Obj_Type)
5884 if Try_Primitive_Operation
5885 (Call_Node => New_Call_Node,
5886 Node_To_Replace => Node_To_Replace)
5888 Try_Class_Wide_Operation
5889 (Call_Node => New_Call_Node,
5890 Node_To_Replace => Node_To_Replace)
5894 end Try_One_Prefix_Interpretation;
5896 -----------------------------
5897 -- Try_Primitive_Operation --
5898 -----------------------------
5900 function Try_Primitive_Operation
5901 (Call_Node : Node_Id;
5902 Node_To_Replace : Node_Id) return Boolean
5905 Prim_Op : Entity_Id;
5906 Matching_Op : Entity_Id := Empty;
5907 Prim_Op_Ref : Node_Id := Empty;
5909 Corr_Type : Entity_Id := Empty;
5910 -- If the prefix is a synchronized type, the controlling type of
5911 -- the primitive operation is the corresponding record type, else
5912 -- this is the object type itself.
5914 Success : Boolean := False;
5916 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
5917 -- For tagged types the candidate interpretations are found in
5918 -- the list of primitive operations of the type and its ancestors.
5919 -- For formal tagged types we have to find the operations declared
5920 -- in the same scope as the type (including in the generic formal
5921 -- part) because the type itself carries no primitive operations,
5922 -- except for formal derived types that inherit the operations of
5923 -- the parent and progenitors.
5925 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
5926 -- Verify that the prefix, dereferenced if need be, is a valid
5927 -- controlling argument in a call to Op. The remaining actuals
5928 -- are checked in the subsequent call to Analyze_One_Call.
5930 ------------------------------
5931 -- Collect_Generic_Type_Ops --
5932 ------------------------------
5934 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
5935 Bas : constant Entity_Id := Base_Type (T);
5936 Candidates : constant Elist_Id := New_Elmt_List;
5941 if Is_Derived_Type (T) then
5942 return Primitive_Operations (T);
5945 -- Scan the list of entities declared in the same scope as
5946 -- the type. In general this will be an open scope, given that
5947 -- the call we are analyzing can only appear within a generic
5948 -- declaration or body (either the one that declares T, or a
5951 Subp := First_Entity (Scope (T));
5952 while Present (Subp) loop
5953 if Is_Overloadable (Subp) then
5954 Formal := First_Formal (Subp);
5957 and then Is_Controlling_Formal (Formal)
5959 (Base_Type (Etype (Formal)) = Bas
5961 (Is_Access_Type (Etype (Formal))
5962 and then Designated_Type (Etype (Formal)) = Bas))
5964 Append_Elmt (Subp, Candidates);
5973 end Collect_Generic_Type_Ops;
5975 -----------------------------
5976 -- Valid_First_Argument_Of --
5977 -----------------------------
5979 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
5980 Typ : constant Entity_Id := Etype (First_Formal (Op));
5983 -- Simple case. Object may be a subtype of the tagged type
5984 -- or may be the corresponding record of a synchronized type.
5986 return Obj_Type = Typ
5987 or else Base_Type (Obj_Type) = Typ
5989 or else Corr_Type = Typ
5991 -- Prefix can be dereferenced
5994 (Is_Access_Type (Corr_Type)
5995 and then Designated_Type (Corr_Type) = Typ)
5997 -- Formal is an access parameter, for which the object
5998 -- can provide an access.
6001 (Ekind (Typ) = E_Anonymous_Access_Type
6002 and then Designated_Type (Typ) = Base_Type (Corr_Type));
6003 end Valid_First_Argument_Of;
6005 -- Start of processing for Try_Primitive_Operation
6008 -- Look for subprograms in the list of primitive operations The name
6009 -- must be identical, and the kind of call indicates the expected
6010 -- kind of operation (function or procedure). If the type is a
6011 -- (tagged) synchronized type, the primitive ops are attached to
6012 -- the corresponding record type.
6014 if Is_Concurrent_Type (Obj_Type) then
6015 Corr_Type := Corresponding_Record_Type (Obj_Type);
6016 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
6018 elsif not Is_Generic_Type (Obj_Type) then
6019 Corr_Type := Obj_Type;
6020 Elmt := First_Elmt (Primitive_Operations (Obj_Type));
6023 Corr_Type := Obj_Type;
6024 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
6027 while Present (Elmt) loop
6028 Prim_Op := Node (Elmt);
6030 if Chars (Prim_Op) = Chars (Subprog)
6031 and then Present (First_Formal (Prim_Op))
6032 and then Valid_First_Argument_Of (Prim_Op)
6034 (Nkind (Call_Node) = N_Function_Call)
6035 = (Ekind (Prim_Op) = E_Function)
6037 -- Ada 2005 (AI-251): If this primitive operation corresponds
6038 -- with an immediate ancestor interface there is no need to add
6039 -- it to the list of interpretations; the corresponding aliased
6040 -- primitive is also in this list of primitive operations and
6041 -- will be used instead.
6043 if (Present (Abstract_Interface_Alias (Prim_Op))
6044 and then Is_Ancestor (Find_Dispatching_Type
6045 (Alias (Prim_Op)), Corr_Type))
6048 -- Do not consider hidden primitives unless the type is
6049 -- in an open scope or we are within an instance, where
6050 -- visibility is known to be correct.
6052 (Is_Hidden (Prim_Op)
6053 and then not Is_Immediately_Visible (Obj_Type)
6054 and then not In_Instance)
6059 Set_Etype (Call_Node, Any_Type);
6060 Set_Is_Overloaded (Call_Node, False);
6062 if No (Matching_Op) then
6063 Prim_Op_Ref := New_Reference_To (Prim_Op, Sloc (Subprog));
6064 Candidate := Prim_Op;
6066 Set_Parent (Call_Node, Parent (Node_To_Replace));
6068 Set_Name (Call_Node, Prim_Op_Ref);
6074 Report => Report_Error,
6076 Skip_First => True);
6078 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
6082 -- More than one interpretation, collect for subsequent
6083 -- disambiguation. If this is a procedure call and there
6084 -- is another match, report ambiguity now.
6089 Report => Report_Error,
6091 Skip_First => True);
6093 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
6094 and then Nkind (Call_Node) /= N_Function_Call
6096 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
6097 Report_Ambiguity (Matching_Op);
6098 Report_Ambiguity (Prim_Op);
6108 if Present (Matching_Op) then
6109 Set_Etype (Call_Node, Etype (Matching_Op));
6112 return Present (Matching_Op);
6113 end Try_Primitive_Operation;
6115 -- Start of processing for Try_Object_Operation
6118 Analyze_Expression (Obj);
6120 -- Analyze the actuals if node is known to be a subprogram call
6122 if Is_Subprg_Call and then N = Name (Parent (N)) then
6123 Actual := First (Parameter_Associations (Parent (N)));
6124 while Present (Actual) loop
6125 Analyze_Expression (Actual);
6130 -- Build a subprogram call node, using a copy of Obj as its first
6131 -- actual. This is a placeholder, to be replaced by an explicit
6132 -- dereference when needed.
6134 Transform_Object_Operation
6135 (Call_Node => New_Call_Node,
6136 Node_To_Replace => Node_To_Replace);
6138 Set_Etype (New_Call_Node, Any_Type);
6139 Set_Etype (Subprog, Any_Type);
6140 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
6142 if not Is_Overloaded (Obj) then
6143 Try_One_Prefix_Interpretation (Obj_Type);
6150 Get_First_Interp (Obj, I, It);
6151 while Present (It.Nam) loop
6152 Try_One_Prefix_Interpretation (It.Typ);
6153 Get_Next_Interp (I, It);
6158 if Etype (New_Call_Node) /= Any_Type then
6159 Complete_Object_Operation
6160 (Call_Node => New_Call_Node,
6161 Node_To_Replace => Node_To_Replace);
6164 elsif Present (Candidate) then
6166 -- The argument list is not type correct. Re-analyze with error
6167 -- reporting enabled, and use one of the possible candidates.
6168 -- In all_errors mode, re-analyze all failed interpretations.
6170 if All_Errors_Mode then
6171 Report_Error := True;
6172 if Try_Primitive_Operation
6173 (Call_Node => New_Call_Node,
6174 Node_To_Replace => Node_To_Replace)
6177 Try_Class_Wide_Operation
6178 (Call_Node => New_Call_Node,
6179 Node_To_Replace => Node_To_Replace)
6186 (N => New_Call_Node,
6190 Skip_First => True);
6193 return True; -- No need for further errors.
6196 -- There was no candidate operation, so report it as an error
6197 -- in the caller: Analyze_Selected_Component.
6201 end Try_Object_Operation;