1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Exp_Util; use Exp_Util;
34 with Fname; use Fname;
35 with Itypes; use Itypes;
37 with Lib.Xref; use Lib.Xref;
38 with Namet; use Namet;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
42 with Output; use Output;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
46 with Sem_Cat; use Sem_Cat;
47 with Sem_Ch3; use Sem_Ch3;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Dist; use Sem_Dist;
50 with Sem_Eval; use Sem_Eval;
51 with Sem_Res; use Sem_Res;
52 with Sem_Util; use Sem_Util;
53 with Sem_Type; use Sem_Type;
54 with Stand; use Stand;
55 with Sinfo; use Sinfo;
56 with Snames; use Snames;
57 with Tbuild; use Tbuild;
59 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
61 package body Sem_Ch4 is
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 procedure Analyze_Expression (N : Node_Id);
68 -- For expressions that are not names, this is just a call to analyze.
69 -- If the expression is a name, it may be a call to a parameterless
70 -- function, and if so must be converted into an explicit call node
71 -- and analyzed as such. This deproceduring must be done during the first
72 -- pass of overload resolution, because otherwise a procedure call with
73 -- overloaded actuals may fail to resolve. See 4327-001 for an example.
75 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
76 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
77 -- is an operator name or an expanded name whose selector is an operator
78 -- name, and one possible interpretation is as a predefined operator.
80 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
81 -- If the prefix of a selected_component is overloaded, the proper
82 -- interpretation that yields a record type with the proper selector
83 -- name must be selected.
85 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
86 -- Procedure to analyze a user defined binary operator, which is resolved
87 -- like a function, but instead of a list of actuals it is presented
88 -- with the left and right operands of an operator node.
90 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
91 -- Procedure to analyze a user defined unary operator, which is resolved
92 -- like a function, but instead of a list of actuals, it is presented with
93 -- the operand of the operator node.
95 procedure Ambiguous_Operands (N : Node_Id);
96 -- for equality, membership, and comparison operators with overloaded
97 -- arguments, list possible interpretations.
99 procedure Analyze_One_Call
103 Success : out Boolean);
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 procedure Check_Misspelled_Selector
118 -- Give possible misspelling diagnostic if Sel is likely to be
119 -- a misspelling of one of the selectors of the Prefix.
120 -- This is called by Analyze_Selected_Component after producing
121 -- an invalid selector error message.
123 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
124 -- Verify that type T is declared in scope S. Used to find intepretations
125 -- for operators given by expanded names. This is abstracted as a separate
126 -- function to handle extensions to System, where S is System, but T is
127 -- declared in the extension.
129 procedure Find_Arithmetic_Types
133 -- L and R are the operands of an arithmetic operator. Find
134 -- consistent pairs of interpretations for L and R that have a
135 -- numeric type consistent with the semantics of the operator.
137 procedure Find_Comparison_Types
141 -- L and R are operands of a comparison operator. Find consistent
142 -- pairs of interpretations for L and R.
144 procedure Find_Concatenation_Types
148 -- For the four varieties of concatenation.
150 procedure Find_Equality_Types
154 -- Ditto for equality operators.
156 procedure Find_Boolean_Types
160 -- Ditto for binary logical operations.
162 procedure Find_Negation_Types
166 -- Find consistent interpretation for operand of negation operator.
168 procedure Find_Non_Universal_Interpretations
173 -- For equality and comparison operators, the result is always boolean,
174 -- and the legality of the operation is determined from the visibility
175 -- of the operand types. If one of the operands has a universal interpre-
176 -- tation, the legality check uses some compatible non-universal
177 -- interpretation of the other operand. N can be an operator node, or
178 -- a function call whose name is an operator designator.
180 procedure Find_Unary_Types
184 -- Unary arithmetic types: plus, minus, abs.
186 procedure Check_Arithmetic_Pair
190 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
191 -- types for left and right operand. Determine whether they constitute
192 -- a valid pair for the given operator, and record the corresponding
193 -- interpretation of the operator node. The node N may be an operator
194 -- node (the usual case) or a function call whose prefix is an operator
195 -- designator. In both cases Op_Id is the operator name itself.
197 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
198 -- Give detailed information on overloaded call where none of the
199 -- interpretations match. N is the call node, Nam the designator for
200 -- the overloaded entity being called.
202 function Junk_Operand (N : Node_Id) return Boolean;
203 -- Test for an operand that is an inappropriate entity (e.g. a package
204 -- name or a label). If so, issue an error message and return True. If
205 -- the operand is not an inappropriate entity kind, return False.
207 procedure Operator_Check (N : Node_Id);
208 -- Verify that an operator has received some valid interpretation.
209 -- If none was found, determine whether a use clause would make the
210 -- operation legal. The variable Candidate_Type (defined in Sem_Type) is
211 -- set for every type compatible with the operator, even if the operator
212 -- for the type is not directly visible. The routine uses this type to emit
213 -- a more informative message.
215 procedure Remove_Abstract_Operations (N : Node_Id);
216 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
217 -- operation is not a candidate interpretation.
219 function Try_Indexed_Call
222 Typ : Entity_Id) return Boolean;
223 -- If a function has defaults for all its actuals, a call to it may
224 -- in fact be an indexing on the result of the call. Try_Indexed_Call
225 -- attempts the interpretation as an indexing, prior to analysis as
226 -- a call. If both are possible, the node is overloaded with both
227 -- interpretations (same symbol but two different types).
229 function Try_Indirect_Call
232 Typ : Entity_Id) return Boolean;
233 -- Similarly, a function F that needs no actuals can return an access
234 -- to a subprogram, and the call F (X) interpreted as F.all (X). In
235 -- this case the call may be overloaded with both interpretations.
237 function Try_Object_Operation (N : Node_Id) return Boolean;
238 -- Ada 2005 (AI-252): Give support to the object operation notation
240 ------------------------
241 -- Ambiguous_Operands --
242 ------------------------
244 procedure Ambiguous_Operands (N : Node_Id) is
245 procedure List_Operand_Interps (Opnd : Node_Id);
247 procedure List_Operand_Interps (Opnd : Node_Id) is
252 if Is_Overloaded (Opnd) then
253 if Nkind (Opnd) in N_Op then
256 elsif Nkind (Opnd) = N_Function_Call then
267 if Opnd = Left_Opnd (N) then
269 ("\left operand has the following interpretations", N);
272 ("\right operand has the following interpretations", N);
276 List_Interps (Nam, Err);
277 end List_Operand_Interps;
281 or else Nkind (N) = N_Not_In
283 Error_Msg_N ("ambiguous operands for membership", N);
285 elsif Nkind (N) = N_Op_Eq
286 or else Nkind (N) = N_Op_Ne
288 Error_Msg_N ("ambiguous operands for equality", N);
291 Error_Msg_N ("ambiguous operands for comparison", N);
294 if All_Errors_Mode then
295 List_Operand_Interps (Left_Opnd (N));
296 List_Operand_Interps (Right_Opnd (N));
298 Error_Msg_N ("\use -gnatf switch for details", N);
300 end Ambiguous_Operands;
302 -----------------------
303 -- Analyze_Aggregate --
304 -----------------------
306 -- Most of the analysis of Aggregates requires that the type be known,
307 -- and is therefore put off until resolution.
309 procedure Analyze_Aggregate (N : Node_Id) is
311 if No (Etype (N)) then
312 Set_Etype (N, Any_Composite);
314 end Analyze_Aggregate;
316 -----------------------
317 -- Analyze_Allocator --
318 -----------------------
320 procedure Analyze_Allocator (N : Node_Id) is
321 Loc : constant Source_Ptr := Sloc (N);
322 Sav_Errs : constant Nat := Serious_Errors_Detected;
323 E : Node_Id := Expression (N);
324 Acc_Type : Entity_Id;
328 Check_Restriction (No_Allocators, N);
330 if Nkind (E) = N_Qualified_Expression then
331 Acc_Type := Create_Itype (E_Allocator_Type, N);
332 Set_Etype (Acc_Type, Acc_Type);
333 Init_Size_Align (Acc_Type);
334 Find_Type (Subtype_Mark (E));
335 Type_Id := Entity (Subtype_Mark (E));
336 Check_Fully_Declared (Type_Id, N);
337 Set_Directly_Designated_Type (Acc_Type, Type_Id);
339 if Is_Limited_Type (Type_Id)
340 and then Comes_From_Source (N)
341 and then not In_Instance_Body
343 -- Ada 2005 (AI-287): Do not post an error if the expression
344 -- corresponds to a limited aggregate. Limited aggregates
345 -- are checked in sem_aggr in a per-component manner
346 -- (compare with handling of Get_Value subprogram).
348 if Ada_Version >= Ada_05
349 and then Nkind (Expression (E)) = N_Aggregate
353 Error_Msg_N ("initialization not allowed for limited types", N);
354 Explain_Limited_Type (Type_Id, N);
358 Analyze_And_Resolve (Expression (E), Type_Id);
360 -- A qualified expression requires an exact match of the type,
361 -- class-wide matching is not allowed.
363 if Is_Class_Wide_Type (Type_Id)
364 and then Base_Type (Etype (Expression (E))) /= Base_Type (Type_Id)
366 Wrong_Type (Expression (E), Type_Id);
369 Check_Non_Static_Context (Expression (E));
371 -- We don't analyze the qualified expression itself because it's
372 -- part of the allocator
374 Set_Etype (E, Type_Id);
381 -- If the allocator includes a N_Subtype_Indication then a
382 -- constraint is present, otherwise the node is a subtype mark.
383 -- Introduce an explicit subtype declaration into the tree
384 -- defining some anonymous subtype and rewrite the allocator to
385 -- use this subtype rather than the subtype indication.
387 -- It is important to introduce the explicit subtype declaration
388 -- so that the bounds of the subtype indication are attached to
389 -- the tree in case the allocator is inside a generic unit.
391 if Nkind (E) = N_Subtype_Indication then
393 -- A constraint is only allowed for a composite type in Ada
394 -- 95. In Ada 83, a constraint is also allowed for an
395 -- access-to-composite type, but the constraint is ignored.
397 Find_Type (Subtype_Mark (E));
399 if Is_Elementary_Type (Entity (Subtype_Mark (E))) then
400 if not (Ada_Version = Ada_83
401 and then Is_Access_Type (Entity (Subtype_Mark (E))))
403 Error_Msg_N ("constraint not allowed here", E);
405 if Nkind (Constraint (E))
406 = N_Index_Or_Discriminant_Constraint
409 ("\if qualified expression was meant, " &
410 "use apostrophe", Constraint (E));
414 -- Get rid of the bogus constraint:
416 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
417 Analyze_Allocator (N);
421 if Expander_Active then
423 Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
426 Make_Subtype_Declaration (Loc,
427 Defining_Identifier => Def_Id,
428 Subtype_Indication => Relocate_Node (E)));
430 if Sav_Errs /= Serious_Errors_Detected
431 and then Nkind (Constraint (E))
432 = N_Index_Or_Discriminant_Constraint
435 ("if qualified expression was meant, " &
436 "use apostrophe!", Constraint (E));
439 E := New_Occurrence_Of (Def_Id, Loc);
440 Rewrite (Expression (N), E);
444 Type_Id := Process_Subtype (E, N);
445 Acc_Type := Create_Itype (E_Allocator_Type, N);
446 Set_Etype (Acc_Type, Acc_Type);
447 Init_Size_Align (Acc_Type);
448 Set_Directly_Designated_Type (Acc_Type, Type_Id);
449 Check_Fully_Declared (Type_Id, N);
453 if Can_Never_Be_Null (Type_Id) then
454 Error_Msg_N ("(Ada 2005) qualified expression required",
458 -- Check restriction against dynamically allocated protected
459 -- objects. Note that when limited aggregates are supported,
460 -- a similar test should be applied to an allocator with a
461 -- qualified expression ???
463 if Is_Protected_Type (Type_Id) then
464 Check_Restriction (No_Protected_Type_Allocators, N);
467 -- Check for missing initialization. Skip this check if we already
468 -- had errors on analyzing the allocator, since in that case these
469 -- are probably cascaded errors
471 if Is_Indefinite_Subtype (Type_Id)
472 and then Serious_Errors_Detected = Sav_Errs
474 if Is_Class_Wide_Type (Type_Id) then
476 ("initialization required in class-wide allocation", N);
479 ("initialization required in unconstrained allocation", N);
485 if Is_Abstract (Type_Id) then
486 Error_Msg_N ("cannot allocate abstract object", E);
489 if Has_Task (Designated_Type (Acc_Type)) then
490 Check_Restriction (No_Tasking, N);
491 Check_Restriction (Max_Tasks, N);
492 Check_Restriction (No_Task_Allocators, N);
495 Set_Etype (N, Acc_Type);
497 if not Is_Library_Level_Entity (Acc_Type) then
498 Check_Restriction (No_Local_Allocators, N);
501 -- Ada 2005 (AI-231): Static checks
503 if Ada_Version >= Ada_05
504 and then (Null_Exclusion_Present (N)
505 or else Can_Never_Be_Null (Etype (N)))
507 Null_Exclusion_Static_Checks (N);
510 if Serious_Errors_Detected > Sav_Errs then
511 Set_Error_Posted (N);
512 Set_Etype (N, Any_Type);
514 end Analyze_Allocator;
516 ---------------------------
517 -- Analyze_Arithmetic_Op --
518 ---------------------------
520 procedure Analyze_Arithmetic_Op (N : Node_Id) is
521 L : constant Node_Id := Left_Opnd (N);
522 R : constant Node_Id := Right_Opnd (N);
526 Candidate_Type := Empty;
527 Analyze_Expression (L);
528 Analyze_Expression (R);
530 -- If the entity is already set, the node is the instantiation of
531 -- a generic node with a non-local reference, or was manufactured
532 -- by a call to Make_Op_xxx. In either case the entity is known to
533 -- be valid, and we do not need to collect interpretations, instead
534 -- we just get the single possible interpretation.
538 if Present (Op_Id) then
539 if Ekind (Op_Id) = E_Operator then
541 if (Nkind (N) = N_Op_Divide or else
542 Nkind (N) = N_Op_Mod or else
543 Nkind (N) = N_Op_Multiply or else
544 Nkind (N) = N_Op_Rem)
545 and then Treat_Fixed_As_Integer (N)
549 Set_Etype (N, Any_Type);
550 Find_Arithmetic_Types (L, R, Op_Id, N);
554 Set_Etype (N, Any_Type);
555 Add_One_Interp (N, Op_Id, Etype (Op_Id));
558 -- Entity is not already set, so we do need to collect interpretations
561 Op_Id := Get_Name_Entity_Id (Chars (N));
562 Set_Etype (N, Any_Type);
564 while Present (Op_Id) loop
565 if Ekind (Op_Id) = E_Operator
566 and then Present (Next_Entity (First_Entity (Op_Id)))
568 Find_Arithmetic_Types (L, R, Op_Id, N);
570 -- The following may seem superfluous, because an operator cannot
571 -- be generic, but this ignores the cleverness of the author of
574 elsif Is_Overloadable (Op_Id) then
575 Analyze_User_Defined_Binary_Op (N, Op_Id);
578 Op_Id := Homonym (Op_Id);
583 end Analyze_Arithmetic_Op;
589 -- Function, procedure, and entry calls are checked here. The Name
590 -- in the call may be overloaded. The actuals have been analyzed
591 -- and may themselves be overloaded. On exit from this procedure, the node
592 -- N may have zero, one or more interpretations. In the first case an error
593 -- message is produced. In the last case, the node is flagged as overloaded
594 -- and the interpretations are collected in All_Interp.
596 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
597 -- the type-checking is similar to that of other calls.
599 procedure Analyze_Call (N : Node_Id) is
600 Actuals : constant List_Id := Parameter_Associations (N);
601 Nam : Node_Id := Name (N);
605 Success : Boolean := False;
607 function Name_Denotes_Function return Boolean;
608 -- If the type of the name is an access to subprogram, this may be
609 -- the type of a name, or the return type of the function being called.
610 -- If the name is not an entity then it can denote a protected function.
611 -- Until we distinguish Etype from Return_Type, we must use this
612 -- routine to resolve the meaning of the name in the call.
614 ---------------------------
615 -- Name_Denotes_Function --
616 ---------------------------
618 function Name_Denotes_Function return Boolean is
620 if Is_Entity_Name (Nam) then
621 return Ekind (Entity (Nam)) = E_Function;
623 elsif Nkind (Nam) = N_Selected_Component then
624 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
629 end Name_Denotes_Function;
631 -- Start of processing for Analyze_Call
634 -- Initialize the type of the result of the call to the error type,
635 -- which will be reset if the type is successfully resolved.
637 Set_Etype (N, Any_Type);
639 if not Is_Overloaded (Nam) then
641 -- Only one interpretation to check
643 if Ekind (Etype (Nam)) = E_Subprogram_Type then
644 Nam_Ent := Etype (Nam);
646 elsif Is_Access_Type (Etype (Nam))
647 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
648 and then not Name_Denotes_Function
650 Nam_Ent := Designated_Type (Etype (Nam));
651 Insert_Explicit_Dereference (Nam);
653 -- Selected component case. Simple entry or protected operation,
654 -- where the entry name is given by the selector name.
656 elsif Nkind (Nam) = N_Selected_Component then
657 Nam_Ent := Entity (Selector_Name (Nam));
659 if Ekind (Nam_Ent) /= E_Entry
660 and then Ekind (Nam_Ent) /= E_Entry_Family
661 and then Ekind (Nam_Ent) /= E_Function
662 and then Ekind (Nam_Ent) /= E_Procedure
664 Error_Msg_N ("name in call is not a callable entity", Nam);
665 Set_Etype (N, Any_Type);
669 -- If the name is an Indexed component, it can be a call to a member
670 -- of an entry family. The prefix must be a selected component whose
671 -- selector is the entry. Analyze_Procedure_Call normalizes several
672 -- kinds of call into this form.
674 elsif Nkind (Nam) = N_Indexed_Component then
676 if Nkind (Prefix (Nam)) = N_Selected_Component then
677 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
680 Error_Msg_N ("name in call is not a callable entity", Nam);
681 Set_Etype (N, Any_Type);
686 elsif not Is_Entity_Name (Nam) then
687 Error_Msg_N ("name in call is not a callable entity", Nam);
688 Set_Etype (N, Any_Type);
692 Nam_Ent := Entity (Nam);
694 -- If no interpretations, give error message
696 if not Is_Overloadable (Nam_Ent) then
698 L : constant Boolean := Is_List_Member (N);
699 K : constant Node_Kind := Nkind (Parent (N));
702 -- If the node is in a list whose parent is not an
703 -- expression then it must be an attempted procedure call.
705 if L and then K not in N_Subexpr then
706 if Ekind (Entity (Nam)) = E_Generic_Procedure then
708 ("must instantiate generic procedure& before call",
712 ("procedure or entry name expected", Nam);
715 -- Check for tasking cases where only an entry call will do
718 and then (K = N_Entry_Call_Alternative
719 or else K = N_Triggering_Alternative)
721 Error_Msg_N ("entry name expected", Nam);
723 -- Otherwise give general error message
726 Error_Msg_N ("invalid prefix in call", Nam);
734 Analyze_One_Call (N, Nam_Ent, True, Success);
737 -- An overloaded selected component must denote overloaded
738 -- operations of a concurrent type. The interpretations are
739 -- attached to the simple name of those operations.
741 if Nkind (Nam) = N_Selected_Component then
742 Nam := Selector_Name (Nam);
745 Get_First_Interp (Nam, X, It);
747 while Present (It.Nam) loop
750 -- Name may be call that returns an access to subprogram, or more
751 -- generally an overloaded expression one of whose interpretations
752 -- yields an access to subprogram. If the name is an entity, we
753 -- do not dereference, because the node is a call that returns
754 -- the access type: note difference between f(x), where the call
755 -- may return an access subprogram type, and f(x)(y), where the
756 -- type returned by the call to f is implicitly dereferenced to
757 -- analyze the outer call.
759 if Is_Access_Type (Nam_Ent) then
760 Nam_Ent := Designated_Type (Nam_Ent);
762 elsif Is_Access_Type (Etype (Nam_Ent))
763 and then not Is_Entity_Name (Nam)
764 and then Ekind (Designated_Type (Etype (Nam_Ent)))
767 Nam_Ent := Designated_Type (Etype (Nam_Ent));
770 Analyze_One_Call (N, Nam_Ent, False, Success);
772 -- If the interpretation succeeds, mark the proper type of the
773 -- prefix (any valid candidate will do). If not, remove the
774 -- candidate interpretation. This only needs to be done for
775 -- overloaded protected operations, for other entities disambi-
776 -- guation is done directly in Resolve.
779 Set_Etype (Nam, It.Typ);
781 elsif Nkind (Name (N)) = N_Selected_Component
782 or else Nkind (Name (N)) = N_Function_Call
787 Get_Next_Interp (X, It);
790 -- If the name is the result of a function call, it can only
791 -- be a call to a function returning an access to subprogram.
792 -- Insert explicit dereference.
794 if Nkind (Nam) = N_Function_Call then
795 Insert_Explicit_Dereference (Nam);
798 if Etype (N) = Any_Type then
800 -- None of the interpretations is compatible with the actuals
802 Diagnose_Call (N, Nam);
804 -- Special checks for uninstantiated put routines
806 if Nkind (N) = N_Procedure_Call_Statement
807 and then Is_Entity_Name (Nam)
808 and then Chars (Nam) = Name_Put
809 and then List_Length (Actuals) = 1
812 Arg : constant Node_Id := First (Actuals);
816 if Nkind (Arg) = N_Parameter_Association then
817 Typ := Etype (Explicit_Actual_Parameter (Arg));
822 if Is_Signed_Integer_Type (Typ) then
824 ("possible missing instantiation of " &
825 "'Text_'I'O.'Integer_'I'O!", Nam);
827 elsif Is_Modular_Integer_Type (Typ) then
829 ("possible missing instantiation of " &
830 "'Text_'I'O.'Modular_'I'O!", Nam);
832 elsif Is_Floating_Point_Type (Typ) then
834 ("possible missing instantiation of " &
835 "'Text_'I'O.'Float_'I'O!", Nam);
837 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
839 ("possible missing instantiation of " &
840 "'Text_'I'O.'Fixed_'I'O!", Nam);
842 elsif Is_Decimal_Fixed_Point_Type (Typ) then
844 ("possible missing instantiation of " &
845 "'Text_'I'O.'Decimal_'I'O!", Nam);
847 elsif Is_Enumeration_Type (Typ) then
849 ("possible missing instantiation of " &
850 "'Text_'I'O.'Enumeration_'I'O!", Nam);
855 elsif not Is_Overloaded (N)
856 and then Is_Entity_Name (Nam)
858 -- Resolution yields a single interpretation. Verify that
859 -- is has the proper capitalization.
861 Set_Entity_With_Style_Check (Nam, Entity (Nam));
862 Generate_Reference (Entity (Nam), Nam);
864 Set_Etype (Nam, Etype (Entity (Nam)));
866 Remove_Abstract_Operations (N);
873 ---------------------------
874 -- Analyze_Comparison_Op --
875 ---------------------------
877 procedure Analyze_Comparison_Op (N : Node_Id) is
878 L : constant Node_Id := Left_Opnd (N);
879 R : constant Node_Id := Right_Opnd (N);
880 Op_Id : Entity_Id := Entity (N);
883 Set_Etype (N, Any_Type);
884 Candidate_Type := Empty;
886 Analyze_Expression (L);
887 Analyze_Expression (R);
889 if Present (Op_Id) then
891 if Ekind (Op_Id) = E_Operator then
892 Find_Comparison_Types (L, R, Op_Id, N);
894 Add_One_Interp (N, Op_Id, Etype (Op_Id));
897 if Is_Overloaded (L) then
898 Set_Etype (L, Intersect_Types (L, R));
902 Op_Id := Get_Name_Entity_Id (Chars (N));
904 while Present (Op_Id) loop
906 if Ekind (Op_Id) = E_Operator then
907 Find_Comparison_Types (L, R, Op_Id, N);
909 Analyze_User_Defined_Binary_Op (N, Op_Id);
912 Op_Id := Homonym (Op_Id);
917 end Analyze_Comparison_Op;
919 ---------------------------
920 -- Analyze_Concatenation --
921 ---------------------------
923 -- If the only one-dimensional array type in scope is String,
924 -- this is the resulting type of the operation. Otherwise there
925 -- will be a concatenation operation defined for each user-defined
926 -- one-dimensional array.
928 procedure Analyze_Concatenation (N : Node_Id) is
929 L : constant Node_Id := Left_Opnd (N);
930 R : constant Node_Id := Right_Opnd (N);
931 Op_Id : Entity_Id := Entity (N);
936 Set_Etype (N, Any_Type);
937 Candidate_Type := Empty;
939 Analyze_Expression (L);
940 Analyze_Expression (R);
942 -- If the entity is present, the node appears in an instance,
943 -- and denotes a predefined concatenation operation. The resulting
944 -- type is obtained from the arguments when possible. If the arguments
945 -- are aggregates, the array type and the concatenation type must be
948 if Present (Op_Id) then
949 if Ekind (Op_Id) = E_Operator then
951 LT := Base_Type (Etype (L));
952 RT := Base_Type (Etype (R));
954 if Is_Array_Type (LT)
955 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
957 Add_One_Interp (N, Op_Id, LT);
959 elsif Is_Array_Type (RT)
960 and then LT = Base_Type (Component_Type (RT))
962 Add_One_Interp (N, Op_Id, RT);
964 -- If one operand is a string type or a user-defined array type,
965 -- and the other is a literal, result is of the specific type.
968 (Root_Type (LT) = Standard_String
969 or else Scope (LT) /= Standard_Standard)
970 and then Etype (R) = Any_String
972 Add_One_Interp (N, Op_Id, LT);
975 (Root_Type (RT) = Standard_String
976 or else Scope (RT) /= Standard_Standard)
977 and then Etype (L) = Any_String
979 Add_One_Interp (N, Op_Id, RT);
981 elsif not Is_Generic_Type (Etype (Op_Id)) then
982 Add_One_Interp (N, Op_Id, Etype (Op_Id));
985 -- Type and its operations must be visible.
987 Set_Entity (N, Empty);
988 Analyze_Concatenation (N);
993 Add_One_Interp (N, Op_Id, Etype (Op_Id));
997 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
999 while Present (Op_Id) loop
1000 if Ekind (Op_Id) = E_Operator then
1001 Find_Concatenation_Types (L, R, Op_Id, N);
1003 Analyze_User_Defined_Binary_Op (N, Op_Id);
1006 Op_Id := Homonym (Op_Id);
1011 end Analyze_Concatenation;
1013 ------------------------------------
1014 -- Analyze_Conditional_Expression --
1015 ------------------------------------
1017 procedure Analyze_Conditional_Expression (N : Node_Id) is
1018 Condition : constant Node_Id := First (Expressions (N));
1019 Then_Expr : constant Node_Id := Next (Condition);
1020 Else_Expr : constant Node_Id := Next (Then_Expr);
1023 Analyze_Expression (Condition);
1024 Analyze_Expression (Then_Expr);
1025 Analyze_Expression (Else_Expr);
1026 Set_Etype (N, Etype (Then_Expr));
1027 end Analyze_Conditional_Expression;
1029 -------------------------
1030 -- Analyze_Equality_Op --
1031 -------------------------
1033 procedure Analyze_Equality_Op (N : Node_Id) is
1034 Loc : constant Source_Ptr := Sloc (N);
1035 L : constant Node_Id := Left_Opnd (N);
1036 R : constant Node_Id := Right_Opnd (N);
1040 Set_Etype (N, Any_Type);
1041 Candidate_Type := Empty;
1043 Analyze_Expression (L);
1044 Analyze_Expression (R);
1046 -- If the entity is set, the node is a generic instance with a non-local
1047 -- reference to the predefined operator or to a user-defined function.
1048 -- It can also be an inequality that is expanded into the negation of a
1049 -- call to a user-defined equality operator.
1051 -- For the predefined case, the result is Boolean, regardless of the
1052 -- type of the operands. The operands may even be limited, if they are
1053 -- generic actuals. If they are overloaded, label the left argument with
1054 -- the common type that must be present, or with the type of the formal
1055 -- of the user-defined function.
1057 if Present (Entity (N)) then
1059 Op_Id := Entity (N);
1061 if Ekind (Op_Id) = E_Operator then
1062 Add_One_Interp (N, Op_Id, Standard_Boolean);
1064 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1067 if Is_Overloaded (L) then
1069 if Ekind (Op_Id) = E_Operator then
1070 Set_Etype (L, Intersect_Types (L, R));
1072 Set_Etype (L, Etype (First_Formal (Op_Id)));
1077 Op_Id := Get_Name_Entity_Id (Chars (N));
1079 while Present (Op_Id) loop
1081 if Ekind (Op_Id) = E_Operator then
1082 Find_Equality_Types (L, R, Op_Id, N);
1084 Analyze_User_Defined_Binary_Op (N, Op_Id);
1087 Op_Id := Homonym (Op_Id);
1091 -- If there was no match, and the operator is inequality, this may
1092 -- be a case where inequality has not been made explicit, as for
1093 -- tagged types. Analyze the node as the negation of an equality
1094 -- operation. This cannot be done earlier, because before analysis
1095 -- we cannot rule out the presence of an explicit inequality.
1097 if Etype (N) = Any_Type
1098 and then Nkind (N) = N_Op_Ne
1100 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1102 while Present (Op_Id) loop
1104 if Ekind (Op_Id) = E_Operator then
1105 Find_Equality_Types (L, R, Op_Id, N);
1107 Analyze_User_Defined_Binary_Op (N, Op_Id);
1110 Op_Id := Homonym (Op_Id);
1113 if Etype (N) /= Any_Type then
1114 Op_Id := Entity (N);
1120 Left_Opnd => Relocate_Node (Left_Opnd (N)),
1121 Right_Opnd => Relocate_Node (Right_Opnd (N)))));
1123 Set_Entity (Right_Opnd (N), Op_Id);
1129 end Analyze_Equality_Op;
1131 ----------------------------------
1132 -- Analyze_Explicit_Dereference --
1133 ----------------------------------
1135 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1136 Loc : constant Source_Ptr := Sloc (N);
1137 P : constant Node_Id := Prefix (N);
1143 function Is_Function_Type return Boolean;
1144 -- Check whether node may be interpreted as an implicit function call.
1146 function Is_Function_Type return Boolean is
1151 if not Is_Overloaded (N) then
1152 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1153 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1156 Get_First_Interp (N, I, It);
1158 while Present (It.Nam) loop
1159 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1160 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1165 Get_Next_Interp (I, It);
1170 end Is_Function_Type;
1174 Set_Etype (N, Any_Type);
1176 -- Test for remote access to subprogram type, and if so return
1177 -- after rewriting the original tree.
1179 if Remote_AST_E_Dereference (P) then
1183 -- Normal processing for other than remote access to subprogram type
1185 if not Is_Overloaded (P) then
1186 if Is_Access_Type (Etype (P)) then
1188 -- Set the Etype. We need to go thru Is_For_Access_Subtypes
1189 -- to avoid other problems caused by the Private_Subtype
1190 -- and it is safe to go to the Base_Type because this is the
1191 -- same as converting the access value to its Base_Type.
1194 DT : Entity_Id := Designated_Type (Etype (P));
1197 if Ekind (DT) = E_Private_Subtype
1198 and then Is_For_Access_Subtype (DT)
1200 DT := Base_Type (DT);
1206 elsif Etype (P) /= Any_Type then
1207 Error_Msg_N ("prefix of dereference must be an access type", N);
1212 Get_First_Interp (P, I, It);
1214 while Present (It.Nam) loop
1217 if Is_Access_Type (T) then
1218 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1221 Get_Next_Interp (I, It);
1226 -- Error if no interpretation of the prefix has an access type.
1228 if Etype (N) = Any_Type then
1230 ("access type required in prefix of explicit dereference", P);
1231 Set_Etype (N, Any_Type);
1237 and then Nkind (Parent (N)) /= N_Indexed_Component
1239 and then (Nkind (Parent (N)) /= N_Function_Call
1240 or else N /= Name (Parent (N)))
1242 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1243 or else N /= Name (Parent (N)))
1245 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1246 and then (Nkind (Parent (N)) /= N_Attribute_Reference
1248 (Attribute_Name (Parent (N)) /= Name_Address
1250 Attribute_Name (Parent (N)) /= Name_Access))
1252 -- Name is a function call with no actuals, in a context that
1253 -- requires deproceduring (including as an actual in an enclosing
1254 -- function or procedure call). We can conceive of pathological cases
1255 -- where the prefix might include functions that return access to
1256 -- subprograms and others that return a regular type. Disambiguation
1257 -- of those will have to take place in Resolve. See e.g. 7117-014.
1260 Make_Function_Call (Loc,
1261 Name => Make_Explicit_Dereference (Loc, P),
1262 Parameter_Associations => New_List);
1264 -- If the prefix is overloaded, remove operations that have formals,
1265 -- we know that this is a parameterless call.
1267 if Is_Overloaded (P) then
1268 Get_First_Interp (P, I, It);
1270 while Present (It.Nam) loop
1273 if No (First_Formal (Base_Type (Designated_Type (T)))) then
1279 Get_Next_Interp (I, It);
1287 -- A value of remote access-to-class-wide must not be dereferenced
1290 Validate_Remote_Access_To_Class_Wide_Type (N);
1292 end Analyze_Explicit_Dereference;
1294 ------------------------
1295 -- Analyze_Expression --
1296 ------------------------
1298 procedure Analyze_Expression (N : Node_Id) is
1301 Check_Parameterless_Call (N);
1302 end Analyze_Expression;
1304 ------------------------------------
1305 -- Analyze_Indexed_Component_Form --
1306 ------------------------------------
1308 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
1309 P : constant Node_Id := Prefix (N);
1310 Exprs : constant List_Id := Expressions (N);
1316 procedure Process_Function_Call;
1317 -- Prefix in indexed component form is an overloadable entity,
1318 -- so the node is a function call. Reformat it as such.
1320 procedure Process_Indexed_Component;
1321 -- Prefix in indexed component form is actually an indexed component.
1322 -- This routine processes it, knowing that the prefix is already
1325 procedure Process_Indexed_Component_Or_Slice;
1326 -- An indexed component with a single index may designate a slice if
1327 -- the index is a subtype mark. This routine disambiguates these two
1328 -- cases by resolving the prefix to see if it is a subtype mark.
1330 procedure Process_Overloaded_Indexed_Component;
1331 -- If the prefix of an indexed component is overloaded, the proper
1332 -- interpretation is selected by the index types and the context.
1334 ---------------------------
1335 -- Process_Function_Call --
1336 ---------------------------
1338 procedure Process_Function_Call is
1342 Change_Node (N, N_Function_Call);
1344 Set_Parameter_Associations (N, Exprs);
1345 Actual := First (Parameter_Associations (N));
1347 while Present (Actual) loop
1349 Check_Parameterless_Call (Actual);
1350 Next_Actual (Actual);
1354 end Process_Function_Call;
1356 -------------------------------
1357 -- Process_Indexed_Component --
1358 -------------------------------
1360 procedure Process_Indexed_Component is
1362 Array_Type : Entity_Id;
1364 Entry_Family : Entity_Id;
1367 Exp := First (Exprs);
1369 if Is_Overloaded (P) then
1370 Process_Overloaded_Indexed_Component;
1373 Array_Type := Etype (P);
1375 -- Prefix must be appropriate for an array type.
1376 -- Dereference the prefix if it is an access type.
1378 if Is_Access_Type (Array_Type) then
1379 Array_Type := Designated_Type (Array_Type);
1380 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1383 if Is_Array_Type (Array_Type) then
1386 elsif (Is_Entity_Name (P)
1388 Ekind (Entity (P)) = E_Entry_Family)
1390 (Nkind (P) = N_Selected_Component
1392 Is_Entity_Name (Selector_Name (P))
1394 Ekind (Entity (Selector_Name (P))) = E_Entry_Family)
1396 if Is_Entity_Name (P) then
1397 Entry_Family := Entity (P);
1399 Entry_Family := Entity (Selector_Name (P));
1403 Set_Etype (N, Any_Type);
1405 if not Has_Compatible_Type
1406 (Exp, Entry_Index_Type (Entry_Family))
1408 Error_Msg_N ("invalid index type in entry name", N);
1410 elsif Present (Next (Exp)) then
1411 Error_Msg_N ("too many subscripts in entry reference", N);
1414 Set_Etype (N, Etype (P));
1419 elsif Is_Record_Type (Array_Type)
1420 and then Remote_AST_I_Dereference (P)
1424 elsif Array_Type = Any_Type then
1425 Set_Etype (N, Any_Type);
1428 -- Here we definitely have a bad indexing
1431 if Nkind (Parent (N)) = N_Requeue_Statement
1433 ((Is_Entity_Name (P)
1434 and then Ekind (Entity (P)) = E_Entry)
1436 (Nkind (P) = N_Selected_Component
1437 and then Is_Entity_Name (Selector_Name (P))
1438 and then Ekind (Entity (Selector_Name (P))) = E_Entry))
1441 ("REQUEUE does not permit parameters", First (Exprs));
1443 elsif Is_Entity_Name (P)
1444 and then Etype (P) = Standard_Void_Type
1446 Error_Msg_NE ("incorrect use of&", P, Entity (P));
1449 Error_Msg_N ("array type required in indexed component", P);
1452 Set_Etype (N, Any_Type);
1456 Index := First_Index (Array_Type);
1458 while Present (Index) and then Present (Exp) loop
1459 if not Has_Compatible_Type (Exp, Etype (Index)) then
1460 Wrong_Type (Exp, Etype (Index));
1461 Set_Etype (N, Any_Type);
1469 Set_Etype (N, Component_Type (Array_Type));
1471 if Present (Index) then
1473 ("too few subscripts in array reference", First (Exprs));
1475 elsif Present (Exp) then
1476 Error_Msg_N ("too many subscripts in array reference", Exp);
1480 end Process_Indexed_Component;
1482 ----------------------------------------
1483 -- Process_Indexed_Component_Or_Slice --
1484 ----------------------------------------
1486 procedure Process_Indexed_Component_Or_Slice is
1488 Exp := First (Exprs);
1490 while Present (Exp) loop
1491 Analyze_Expression (Exp);
1495 Exp := First (Exprs);
1497 -- If one index is present, and it is a subtype name, then the
1498 -- node denotes a slice (note that the case of an explicit range
1499 -- for a slice was already built as an N_Slice node in the first
1500 -- place, so that case is not handled here).
1502 -- We use a replace rather than a rewrite here because this is one
1503 -- of the cases in which the tree built by the parser is plain wrong.
1506 and then Is_Entity_Name (Exp)
1507 and then Is_Type (Entity (Exp))
1510 Make_Slice (Sloc (N),
1512 Discrete_Range => New_Copy (Exp)));
1515 -- Otherwise (more than one index present, or single index is not
1516 -- a subtype name), then we have the indexed component case.
1519 Process_Indexed_Component;
1521 end Process_Indexed_Component_Or_Slice;
1523 ------------------------------------------
1524 -- Process_Overloaded_Indexed_Component --
1525 ------------------------------------------
1527 procedure Process_Overloaded_Indexed_Component is
1536 Set_Etype (N, Any_Type);
1537 Get_First_Interp (P, I, It);
1539 while Present (It.Nam) loop
1542 if Is_Access_Type (Typ) then
1543 Typ := Designated_Type (Typ);
1544 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1547 if Is_Array_Type (Typ) then
1549 -- Got a candidate: verify that index types are compatible
1551 Index := First_Index (Typ);
1554 Exp := First (Exprs);
1556 while Present (Index) and then Present (Exp) loop
1557 if Has_Compatible_Type (Exp, Etype (Index)) then
1569 if Found and then No (Index) and then No (Exp) then
1571 Etype (Component_Type (Typ)),
1572 Etype (Component_Type (Typ)));
1576 Get_Next_Interp (I, It);
1579 if Etype (N) = Any_Type then
1580 Error_Msg_N ("no legal interpetation for indexed component", N);
1581 Set_Is_Overloaded (N, False);
1585 end Process_Overloaded_Indexed_Component;
1587 ------------------------------------
1588 -- Analyze_Indexed_Component_Form --
1589 ------------------------------------
1592 -- Get name of array, function or type
1595 if Nkind (N) = N_Function_Call
1596 or else Nkind (N) = N_Procedure_Call_Statement
1598 -- If P is an explicit dereference whose prefix is of a
1599 -- remote access-to-subprogram type, then N has already
1600 -- been rewritten as a subprogram call and analyzed.
1605 pragma Assert (Nkind (N) = N_Indexed_Component);
1607 P_T := Base_Type (Etype (P));
1609 if Is_Entity_Name (P)
1610 or else Nkind (P) = N_Operator_Symbol
1614 if Ekind (U_N) in Type_Kind then
1616 -- Reformat node as a type conversion.
1618 E := Remove_Head (Exprs);
1620 if Present (First (Exprs)) then
1622 ("argument of type conversion must be single expression", N);
1625 Change_Node (N, N_Type_Conversion);
1626 Set_Subtype_Mark (N, P);
1628 Set_Expression (N, E);
1630 -- After changing the node, call for the specific Analysis
1631 -- routine directly, to avoid a double call to the expander.
1633 Analyze_Type_Conversion (N);
1637 if Is_Overloadable (U_N) then
1638 Process_Function_Call;
1640 elsif Ekind (Etype (P)) = E_Subprogram_Type
1641 or else (Is_Access_Type (Etype (P))
1643 Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type)
1645 -- Call to access_to-subprogram with possible implicit dereference
1647 Process_Function_Call;
1649 elsif Is_Generic_Subprogram (U_N) then
1651 -- A common beginner's (or C++ templates fan) error.
1653 Error_Msg_N ("generic subprogram cannot be called", N);
1654 Set_Etype (N, Any_Type);
1658 Process_Indexed_Component_Or_Slice;
1661 -- If not an entity name, prefix is an expression that may denote
1662 -- an array or an access-to-subprogram.
1665 if Ekind (P_T) = E_Subprogram_Type
1666 or else (Is_Access_Type (P_T)
1668 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
1670 Process_Function_Call;
1672 elsif Nkind (P) = N_Selected_Component
1673 and then Ekind (Entity (Selector_Name (P))) = E_Function
1675 Process_Function_Call;
1678 -- Indexed component, slice, or a call to a member of a family
1679 -- entry, which will be converted to an entry call later.
1681 Process_Indexed_Component_Or_Slice;
1684 end Analyze_Indexed_Component_Form;
1686 ------------------------
1687 -- Analyze_Logical_Op --
1688 ------------------------
1690 procedure Analyze_Logical_Op (N : Node_Id) is
1691 L : constant Node_Id := Left_Opnd (N);
1692 R : constant Node_Id := Right_Opnd (N);
1693 Op_Id : Entity_Id := Entity (N);
1696 Set_Etype (N, Any_Type);
1697 Candidate_Type := Empty;
1699 Analyze_Expression (L);
1700 Analyze_Expression (R);
1702 if Present (Op_Id) then
1704 if Ekind (Op_Id) = E_Operator then
1705 Find_Boolean_Types (L, R, Op_Id, N);
1707 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1711 Op_Id := Get_Name_Entity_Id (Chars (N));
1713 while Present (Op_Id) loop
1714 if Ekind (Op_Id) = E_Operator then
1715 Find_Boolean_Types (L, R, Op_Id, N);
1717 Analyze_User_Defined_Binary_Op (N, Op_Id);
1720 Op_Id := Homonym (Op_Id);
1725 end Analyze_Logical_Op;
1727 ---------------------------
1728 -- Analyze_Membership_Op --
1729 ---------------------------
1731 procedure Analyze_Membership_Op (N : Node_Id) is
1732 L : constant Node_Id := Left_Opnd (N);
1733 R : constant Node_Id := Right_Opnd (N);
1735 Index : Interp_Index;
1737 Found : Boolean := False;
1741 procedure Try_One_Interp (T1 : Entity_Id);
1742 -- Routine to try one proposed interpretation. Note that the context
1743 -- of the operation plays no role in resolving the arguments, so that
1744 -- if there is more than one interpretation of the operands that is
1745 -- compatible with a membership test, the operation is ambiguous.
1747 procedure Try_One_Interp (T1 : Entity_Id) is
1749 if Has_Compatible_Type (R, T1) then
1751 and then Base_Type (T1) /= Base_Type (T_F)
1753 It := Disambiguate (L, I_F, Index, Any_Type);
1755 if It = No_Interp then
1756 Ambiguous_Operands (N);
1757 Set_Etype (L, Any_Type);
1775 -- Start of processing for Analyze_Membership_Op
1778 Analyze_Expression (L);
1780 if Nkind (R) = N_Range
1781 or else (Nkind (R) = N_Attribute_Reference
1782 and then Attribute_Name (R) = Name_Range)
1786 if not Is_Overloaded (L) then
1787 Try_One_Interp (Etype (L));
1790 Get_First_Interp (L, Index, It);
1792 while Present (It.Typ) loop
1793 Try_One_Interp (It.Typ);
1794 Get_Next_Interp (Index, It);
1798 -- If not a range, it can only be a subtype mark, or else there
1799 -- is a more basic error, to be diagnosed in Find_Type.
1804 if Is_Entity_Name (R) then
1805 Check_Fully_Declared (Entity (R), R);
1809 -- Compatibility between expression and subtype mark or range is
1810 -- checked during resolution. The result of the operation is Boolean
1813 Set_Etype (N, Standard_Boolean);
1814 end Analyze_Membership_Op;
1816 ----------------------
1817 -- Analyze_Negation --
1818 ----------------------
1820 procedure Analyze_Negation (N : Node_Id) is
1821 R : constant Node_Id := Right_Opnd (N);
1822 Op_Id : Entity_Id := Entity (N);
1825 Set_Etype (N, Any_Type);
1826 Candidate_Type := Empty;
1828 Analyze_Expression (R);
1830 if Present (Op_Id) then
1831 if Ekind (Op_Id) = E_Operator then
1832 Find_Negation_Types (R, Op_Id, N);
1834 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1838 Op_Id := Get_Name_Entity_Id (Chars (N));
1840 while Present (Op_Id) loop
1841 if Ekind (Op_Id) = E_Operator then
1842 Find_Negation_Types (R, Op_Id, N);
1844 Analyze_User_Defined_Unary_Op (N, Op_Id);
1847 Op_Id := Homonym (Op_Id);
1852 end Analyze_Negation;
1858 procedure Analyze_Null (N : Node_Id) is
1860 Set_Etype (N, Any_Access);
1863 ----------------------
1864 -- Analyze_One_Call --
1865 ----------------------
1867 procedure Analyze_One_Call
1871 Success : out Boolean)
1873 Actuals : constant List_Id := Parameter_Associations (N);
1874 Prev_T : constant Entity_Id := Etype (N);
1877 Is_Indexed : Boolean := False;
1878 Subp_Type : constant Entity_Id := Etype (Nam);
1881 procedure Indicate_Name_And_Type;
1882 -- If candidate interpretation matches, indicate name and type of
1883 -- result on call node.
1885 ----------------------------
1886 -- Indicate_Name_And_Type --
1887 ----------------------------
1889 procedure Indicate_Name_And_Type is
1891 Add_One_Interp (N, Nam, Etype (Nam));
1894 -- If the prefix of the call is a name, indicate the entity
1895 -- being called. If it is not a name, it is an expression that
1896 -- denotes an access to subprogram or else an entry or family. In
1897 -- the latter case, the name is a selected component, and the entity
1898 -- being called is noted on the selector.
1900 if not Is_Type (Nam) then
1901 if Is_Entity_Name (Name (N))
1902 or else Nkind (Name (N)) = N_Operator_Symbol
1904 Set_Entity (Name (N), Nam);
1906 elsif Nkind (Name (N)) = N_Selected_Component then
1907 Set_Entity (Selector_Name (Name (N)), Nam);
1911 if Debug_Flag_E and not Report then
1912 Write_Str (" Overloaded call ");
1913 Write_Int (Int (N));
1914 Write_Str (" compatible with ");
1915 Write_Int (Int (Nam));
1918 end Indicate_Name_And_Type;
1920 -- Start of processing for Analyze_One_Call
1925 -- If the subprogram has no formals, or if all the formals have
1926 -- defaults, and the return type is an array type, the node may
1927 -- denote an indexing of the result of a parameterless call.
1929 if Needs_No_Actuals (Nam)
1930 and then Present (Actuals)
1932 if Is_Array_Type (Subp_Type) then
1933 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type);
1935 elsif Is_Access_Type (Subp_Type)
1936 and then Is_Array_Type (Designated_Type (Subp_Type))
1939 Try_Indexed_Call (N, Nam, Designated_Type (Subp_Type));
1941 elsif Is_Access_Type (Subp_Type)
1942 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
1944 Is_Indexed := Try_Indirect_Call (N, Nam, Subp_Type);
1949 Normalize_Actuals (N, Nam, (Report and not Is_Indexed), Norm_OK);
1953 -- Mismatch in number or names of parameters
1955 if Debug_Flag_E then
1956 Write_Str (" normalization fails in call ");
1957 Write_Int (Int (N));
1958 Write_Str (" with subprogram ");
1959 Write_Int (Int (Nam));
1963 -- If the context expects a function call, discard any interpretation
1964 -- that is a procedure. If the node is not overloaded, leave as is for
1965 -- better error reporting when type mismatch is found.
1967 elsif Nkind (N) = N_Function_Call
1968 and then Is_Overloaded (Name (N))
1969 and then Ekind (Nam) = E_Procedure
1973 -- Ditto for function calls in a procedure context.
1975 elsif Nkind (N) = N_Procedure_Call_Statement
1976 and then Is_Overloaded (Name (N))
1977 and then Etype (Nam) /= Standard_Void_Type
1981 elsif not Present (Actuals) then
1983 -- If Normalize succeeds, then there are default parameters for
1986 Indicate_Name_And_Type;
1988 elsif Ekind (Nam) = E_Operator then
1989 if Nkind (N) = N_Procedure_Call_Statement then
1993 -- This can occur when the prefix of the call is an operator
1994 -- name or an expanded name whose selector is an operator name.
1996 Analyze_Operator_Call (N, Nam);
1998 if Etype (N) /= Prev_T then
2000 -- There may be a user-defined operator that hides the
2001 -- current interpretation. We must check for this independently
2002 -- of the analysis of the call with the user-defined operation,
2003 -- because the parameter names may be wrong and yet the hiding
2004 -- takes place. Fixes b34014o.
2006 if Is_Overloaded (Name (N)) then
2012 Get_First_Interp (Name (N), I, It);
2014 while Present (It.Nam) loop
2016 if Ekind (It.Nam) /= E_Operator
2017 and then Hides_Op (It.Nam, Nam)
2020 (First_Actual (N), Etype (First_Formal (It.Nam)))
2021 and then (No (Next_Actual (First_Actual (N)))
2022 or else Has_Compatible_Type
2023 (Next_Actual (First_Actual (N)),
2024 Etype (Next_Formal (First_Formal (It.Nam)))))
2026 Set_Etype (N, Prev_T);
2030 Get_Next_Interp (I, It);
2035 -- If operator matches formals, record its name on the call.
2036 -- If the operator is overloaded, Resolve will select the
2037 -- correct one from the list of interpretations. The call
2038 -- node itself carries the first candidate.
2040 Set_Entity (Name (N), Nam);
2043 elsif Report and then Etype (N) = Any_Type then
2044 Error_Msg_N ("incompatible arguments for operator", N);
2048 -- Normalize_Actuals has chained the named associations in the
2049 -- correct order of the formals.
2051 Actual := First_Actual (N);
2052 Formal := First_Formal (Nam);
2054 while Present (Actual) and then Present (Formal) loop
2056 if Nkind (Parent (Actual)) /= N_Parameter_Association
2057 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
2059 if Has_Compatible_Type (Actual, Etype (Formal)) then
2060 Next_Actual (Actual);
2061 Next_Formal (Formal);
2064 if Debug_Flag_E then
2065 Write_Str (" type checking fails in call ");
2066 Write_Int (Int (N));
2067 Write_Str (" with formal ");
2068 Write_Int (Int (Formal));
2069 Write_Str (" in subprogram ");
2070 Write_Int (Int (Nam));
2074 if Report and not Is_Indexed then
2076 Wrong_Type (Actual, Etype (Formal));
2078 if Nkind (Actual) = N_Op_Eq
2079 and then Nkind (Left_Opnd (Actual)) = N_Identifier
2081 Formal := First_Formal (Nam);
2083 while Present (Formal) loop
2085 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
2087 ("possible misspelling of `='>`!", Actual);
2091 Next_Formal (Formal);
2095 if All_Errors_Mode then
2096 Error_Msg_Sloc := Sloc (Nam);
2098 if Is_Overloadable (Nam)
2099 and then Present (Alias (Nam))
2100 and then not Comes_From_Source (Nam)
2103 (" =='> in call to &#(inherited)!", Actual, Nam);
2105 elsif Ekind (Nam) = E_Subprogram_Type then
2107 Access_To_Subprogram_Typ :
2108 constant Entity_Id :=
2110 (Associated_Node_For_Itype (Nam));
2113 " =='> in call to dereference of &#!",
2114 Actual, Access_To_Subprogram_Typ);
2118 Error_Msg_NE (" =='> in call to &#!", Actual, Nam);
2128 -- Normalize_Actuals has verified that a default value exists
2129 -- for this formal. Current actual names a subsequent formal.
2131 Next_Formal (Formal);
2135 -- On exit, all actuals match.
2137 Indicate_Name_And_Type;
2139 end Analyze_One_Call;
2141 ---------------------------
2142 -- Analyze_Operator_Call --
2143 ---------------------------
2145 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
2146 Op_Name : constant Name_Id := Chars (Op_Id);
2147 Act1 : constant Node_Id := First_Actual (N);
2148 Act2 : constant Node_Id := Next_Actual (Act1);
2151 if Present (Act2) then
2153 -- Maybe binary operators
2155 if Present (Next_Actual (Act2)) then
2157 -- Too many actuals for an operator
2161 elsif Op_Name = Name_Op_Add
2162 or else Op_Name = Name_Op_Subtract
2163 or else Op_Name = Name_Op_Multiply
2164 or else Op_Name = Name_Op_Divide
2165 or else Op_Name = Name_Op_Mod
2166 or else Op_Name = Name_Op_Rem
2167 or else Op_Name = Name_Op_Expon
2169 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
2171 elsif Op_Name = Name_Op_And
2172 or else Op_Name = Name_Op_Or
2173 or else Op_Name = Name_Op_Xor
2175 Find_Boolean_Types (Act1, Act2, Op_Id, N);
2177 elsif Op_Name = Name_Op_Lt
2178 or else Op_Name = Name_Op_Le
2179 or else Op_Name = Name_Op_Gt
2180 or else Op_Name = Name_Op_Ge
2182 Find_Comparison_Types (Act1, Act2, Op_Id, N);
2184 elsif Op_Name = Name_Op_Eq
2185 or else Op_Name = Name_Op_Ne
2187 Find_Equality_Types (Act1, Act2, Op_Id, N);
2189 elsif Op_Name = Name_Op_Concat then
2190 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
2192 -- Is this else null correct, or should it be an abort???
2201 if Op_Name = Name_Op_Subtract or else
2202 Op_Name = Name_Op_Add or else
2203 Op_Name = Name_Op_Abs
2205 Find_Unary_Types (Act1, Op_Id, N);
2208 Op_Name = Name_Op_Not
2210 Find_Negation_Types (Act1, Op_Id, N);
2212 -- Is this else null correct, or should it be an abort???
2218 end Analyze_Operator_Call;
2220 -------------------------------------------
2221 -- Analyze_Overloaded_Selected_Component --
2222 -------------------------------------------
2224 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
2225 Nam : constant Node_Id := Prefix (N);
2226 Sel : constant Node_Id := Selector_Name (N);
2233 Get_First_Interp (Nam, I, It);
2235 Set_Etype (Sel, Any_Type);
2237 while Present (It.Typ) loop
2238 if Is_Access_Type (It.Typ) then
2239 T := Designated_Type (It.Typ);
2240 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2246 if Is_Record_Type (T) then
2247 Comp := First_Entity (T);
2249 while Present (Comp) loop
2251 if Chars (Comp) = Chars (Sel)
2252 and then Is_Visible_Component (Comp)
2254 Set_Entity_With_Style_Check (Sel, Comp);
2255 Generate_Reference (Comp, Sel);
2257 Set_Etype (Sel, Etype (Comp));
2258 Add_One_Interp (N, Etype (Comp), Etype (Comp));
2260 -- This also specifies a candidate to resolve the name.
2261 -- Further overloading will be resolved from context.
2263 Set_Etype (Nam, It.Typ);
2269 elsif Is_Concurrent_Type (T) then
2270 Comp := First_Entity (T);
2272 while Present (Comp)
2273 and then Comp /= First_Private_Entity (T)
2275 if Chars (Comp) = Chars (Sel) then
2276 if Is_Overloadable (Comp) then
2277 Add_One_Interp (Sel, Comp, Etype (Comp));
2279 Set_Entity_With_Style_Check (Sel, Comp);
2280 Generate_Reference (Comp, Sel);
2283 Set_Etype (Sel, Etype (Comp));
2284 Set_Etype (N, Etype (Comp));
2285 Set_Etype (Nam, It.Typ);
2287 -- For access type case, introduce explicit deference for
2288 -- more uniform treatment of entry calls.
2290 if Is_Access_Type (Etype (Nam)) then
2291 Insert_Explicit_Dereference (Nam);
2293 (Warn_On_Dereference, "?implicit dereference", N);
2300 Set_Is_Overloaded (N, Is_Overloaded (Sel));
2303 Get_Next_Interp (I, It);
2306 if Etype (N) = Any_Type then
2307 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
2308 Set_Entity (Sel, Any_Id);
2309 Set_Etype (Sel, Any_Type);
2312 end Analyze_Overloaded_Selected_Component;
2314 ----------------------------------
2315 -- Analyze_Qualified_Expression --
2316 ----------------------------------
2318 procedure Analyze_Qualified_Expression (N : Node_Id) is
2319 Mark : constant Entity_Id := Subtype_Mark (N);
2323 Set_Etype (N, Any_Type);
2327 if T = Any_Type then
2330 Check_Fully_Declared (T, N);
2332 Analyze_Expression (Expression (N));
2334 end Analyze_Qualified_Expression;
2340 procedure Analyze_Range (N : Node_Id) is
2341 L : constant Node_Id := Low_Bound (N);
2342 H : constant Node_Id := High_Bound (N);
2343 I1, I2 : Interp_Index;
2346 procedure Check_Common_Type (T1, T2 : Entity_Id);
2347 -- Verify the compatibility of two types, and choose the
2348 -- non universal one if the other is universal.
2350 procedure Check_High_Bound (T : Entity_Id);
2351 -- Test one interpretation of the low bound against all those
2352 -- of the high bound.
2354 procedure Check_Universal_Expression (N : Node_Id);
2355 -- In Ada83, reject bounds of a universal range that are not
2356 -- literals or entity names.
2358 -----------------------
2359 -- Check_Common_Type --
2360 -----------------------
2362 procedure Check_Common_Type (T1, T2 : Entity_Id) is
2364 if Covers (T1, T2) or else Covers (T2, T1) then
2365 if T1 = Universal_Integer
2366 or else T1 = Universal_Real
2367 or else T1 = Any_Character
2369 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
2372 Add_One_Interp (N, T1, T1);
2375 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
2378 end Check_Common_Type;
2380 ----------------------
2381 -- Check_High_Bound --
2382 ----------------------
2384 procedure Check_High_Bound (T : Entity_Id) is
2386 if not Is_Overloaded (H) then
2387 Check_Common_Type (T, Etype (H));
2389 Get_First_Interp (H, I2, It2);
2391 while Present (It2.Typ) loop
2392 Check_Common_Type (T, It2.Typ);
2393 Get_Next_Interp (I2, It2);
2396 end Check_High_Bound;
2398 -----------------------------
2399 -- Is_Universal_Expression --
2400 -----------------------------
2402 procedure Check_Universal_Expression (N : Node_Id) is
2404 if Etype (N) = Universal_Integer
2405 and then Nkind (N) /= N_Integer_Literal
2406 and then not Is_Entity_Name (N)
2407 and then Nkind (N) /= N_Attribute_Reference
2409 Error_Msg_N ("illegal bound in discrete range", N);
2411 end Check_Universal_Expression;
2413 -- Start of processing for Analyze_Range
2416 Set_Etype (N, Any_Type);
2417 Analyze_Expression (L);
2418 Analyze_Expression (H);
2420 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
2424 if not Is_Overloaded (L) then
2425 Check_High_Bound (Etype (L));
2427 Get_First_Interp (L, I1, It1);
2429 while Present (It1.Typ) loop
2430 Check_High_Bound (It1.Typ);
2431 Get_Next_Interp (I1, It1);
2435 -- If result is Any_Type, then we did not find a compatible pair
2437 if Etype (N) = Any_Type then
2438 Error_Msg_N ("incompatible types in range ", N);
2442 if Ada_Version = Ada_83
2444 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
2445 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
2447 Check_Universal_Expression (L);
2448 Check_Universal_Expression (H);
2452 -----------------------
2453 -- Analyze_Reference --
2454 -----------------------
2456 procedure Analyze_Reference (N : Node_Id) is
2457 P : constant Node_Id := Prefix (N);
2458 Acc_Type : Entity_Id;
2462 Acc_Type := Create_Itype (E_Allocator_Type, N);
2463 Set_Etype (Acc_Type, Acc_Type);
2464 Init_Size_Align (Acc_Type);
2465 Set_Directly_Designated_Type (Acc_Type, Etype (P));
2466 Set_Etype (N, Acc_Type);
2467 end Analyze_Reference;
2469 --------------------------------
2470 -- Analyze_Selected_Component --
2471 --------------------------------
2473 -- Prefix is a record type or a task or protected type. In the
2474 -- later case, the selector must denote a visible entry.
2476 procedure Analyze_Selected_Component (N : Node_Id) is
2477 Name : constant Node_Id := Prefix (N);
2478 Sel : constant Node_Id := Selector_Name (N);
2480 Entity_List : Entity_Id;
2481 Prefix_Type : Entity_Id;
2486 -- Start of processing for Analyze_Selected_Component
2489 Set_Etype (N, Any_Type);
2491 if Is_Overloaded (Name) then
2492 Analyze_Overloaded_Selected_Component (N);
2495 elsif Etype (Name) = Any_Type then
2496 Set_Entity (Sel, Any_Id);
2497 Set_Etype (Sel, Any_Type);
2501 -- Function calls that are prefixes of selected components must be
2502 -- fully resolved in case we need to build an actual subtype, or
2503 -- do some other operation requiring a fully resolved prefix.
2505 -- Note: Resolving all Nkinds of nodes here doesn't work.
2506 -- (Breaks 2129-008) ???.
2508 if Nkind (Name) = N_Function_Call then
2512 Prefix_Type := Etype (Name);
2515 if Is_Access_Type (Prefix_Type) then
2517 -- A RACW object can never be used as prefix of a selected
2518 -- component since that means it is dereferenced without
2519 -- being a controlling operand of a dispatching operation
2522 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
2523 and then Comes_From_Source (N)
2526 ("invalid dereference of a remote access to class-wide value",
2529 -- Normal case of selected component applied to access type
2532 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2535 Prefix_Type := Designated_Type (Prefix_Type);
2538 if Ekind (Prefix_Type) = E_Private_Subtype then
2539 Prefix_Type := Base_Type (Prefix_Type);
2542 Entity_List := Prefix_Type;
2544 -- For class-wide types, use the entity list of the root type. This
2545 -- indirection is specially important for private extensions because
2546 -- only the root type get switched (not the class-wide type).
2548 if Is_Class_Wide_Type (Prefix_Type) then
2549 Entity_List := Root_Type (Prefix_Type);
2552 Comp := First_Entity (Entity_List);
2554 -- If the selector has an original discriminant, the node appears in
2555 -- an instance. Replace the discriminant with the corresponding one
2556 -- in the current discriminated type. For nested generics, this must
2557 -- be done transitively, so note the new original discriminant.
2559 if Nkind (Sel) = N_Identifier
2560 and then Present (Original_Discriminant (Sel))
2562 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
2564 -- Mark entity before rewriting, for completeness and because
2565 -- subsequent semantic checks might examine the original node.
2567 Set_Entity (Sel, Comp);
2568 Rewrite (Selector_Name (N),
2569 New_Occurrence_Of (Comp, Sloc (N)));
2570 Set_Original_Discriminant (Selector_Name (N), Comp);
2571 Set_Etype (N, Etype (Comp));
2573 if Is_Access_Type (Etype (Name)) then
2574 Insert_Explicit_Dereference (Name);
2575 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2578 elsif Is_Record_Type (Prefix_Type) then
2580 -- Find component with given name
2582 while Present (Comp) loop
2584 if Chars (Comp) = Chars (Sel)
2585 and then Is_Visible_Component (Comp)
2587 Set_Entity_With_Style_Check (Sel, Comp);
2588 Generate_Reference (Comp, Sel);
2590 Set_Etype (Sel, Etype (Comp));
2592 if Ekind (Comp) = E_Discriminant then
2593 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
2595 ("cannot reference discriminant of Unchecked_Union",
2599 if Is_Generic_Type (Prefix_Type)
2601 Is_Generic_Type (Root_Type (Prefix_Type))
2603 Set_Original_Discriminant (Sel, Comp);
2607 -- Resolve the prefix early otherwise it is not possible to
2608 -- build the actual subtype of the component: it may need
2609 -- to duplicate this prefix and duplication is only allowed
2610 -- on fully resolved expressions.
2614 -- We never need an actual subtype for the case of a selection
2615 -- for a indexed component of a non-packed array, since in
2616 -- this case gigi generates all the checks and can find the
2617 -- necessary bounds information.
2619 -- We also do not need an actual subtype for the case of
2620 -- a first, last, length, or range attribute applied to a
2621 -- non-packed array, since gigi can again get the bounds in
2622 -- these cases (gigi cannot handle the packed case, since it
2623 -- has the bounds of the packed array type, not the original
2624 -- bounds of the type). However, if the prefix is itself a
2625 -- selected component, as in a.b.c (i), gigi may regard a.b.c
2626 -- as a dynamic-sized temporary, so we do generate an actual
2627 -- subtype for this case.
2629 Parent_N := Parent (N);
2631 if not Is_Packed (Etype (Comp))
2633 ((Nkind (Parent_N) = N_Indexed_Component
2634 and then Nkind (Name) /= N_Selected_Component)
2636 (Nkind (Parent_N) = N_Attribute_Reference
2637 and then (Attribute_Name (Parent_N) = Name_First
2639 Attribute_Name (Parent_N) = Name_Last
2641 Attribute_Name (Parent_N) = Name_Length
2643 Attribute_Name (Parent_N) = Name_Range)))
2645 Set_Etype (N, Etype (Comp));
2647 -- In all other cases, we currently build an actual subtype. It
2648 -- seems likely that many of these cases can be avoided, but
2649 -- right now, the front end makes direct references to the
2650 -- bounds (e.g. in generating a length check), and if we do
2651 -- not make an actual subtype, we end up getting a direct
2652 -- reference to a discriminant which will not do.
2656 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
2657 Insert_Action (N, Act_Decl);
2659 if No (Act_Decl) then
2660 Set_Etype (N, Etype (Comp));
2663 -- Component type depends on discriminants. Enter the
2664 -- main attributes of the subtype.
2667 Subt : constant Entity_Id :=
2668 Defining_Identifier (Act_Decl);
2671 Set_Etype (Subt, Base_Type (Etype (Comp)));
2672 Set_Ekind (Subt, Ekind (Etype (Comp)));
2673 Set_Etype (N, Subt);
2684 -- Ada 2005 (AI-252)
2686 if Ada_Version >= Ada_05
2687 and then Is_Tagged_Type (Prefix_Type)
2688 and then Try_Object_Operation (N)
2693 elsif Is_Private_Type (Prefix_Type) then
2695 -- Allow access only to discriminants of the type. If the
2696 -- type has no full view, gigi uses the parent type for
2697 -- the components, so we do the same here.
2699 if No (Full_View (Prefix_Type)) then
2700 Entity_List := Root_Type (Base_Type (Prefix_Type));
2701 Comp := First_Entity (Entity_List);
2704 while Present (Comp) loop
2706 if Chars (Comp) = Chars (Sel) then
2707 if Ekind (Comp) = E_Discriminant then
2708 Set_Entity_With_Style_Check (Sel, Comp);
2709 Generate_Reference (Comp, Sel);
2711 Set_Etype (Sel, Etype (Comp));
2712 Set_Etype (N, Etype (Comp));
2714 if Is_Generic_Type (Prefix_Type)
2716 Is_Generic_Type (Root_Type (Prefix_Type))
2718 Set_Original_Discriminant (Sel, Comp);
2723 ("invisible selector for }",
2724 N, First_Subtype (Prefix_Type));
2725 Set_Entity (Sel, Any_Id);
2726 Set_Etype (N, Any_Type);
2735 elsif Is_Concurrent_Type (Prefix_Type) then
2737 -- Prefix is concurrent type. Find visible operation with given name
2738 -- For a task, this can only include entries or discriminants if
2739 -- the task type is not an enclosing scope. If it is an enclosing
2740 -- scope (e.g. in an inner task) then all entities are visible, but
2741 -- the prefix must denote the enclosing scope, i.e. can only be
2742 -- a direct name or an expanded name.
2744 Set_Etype (Sel, Any_Type);
2745 In_Scope := In_Open_Scopes (Prefix_Type);
2747 while Present (Comp) loop
2748 if Chars (Comp) = Chars (Sel) then
2749 if Is_Overloadable (Comp) then
2750 Add_One_Interp (Sel, Comp, Etype (Comp));
2752 elsif Ekind (Comp) = E_Discriminant
2753 or else Ekind (Comp) = E_Entry_Family
2755 and then Is_Entity_Name (Name))
2757 Set_Entity_With_Style_Check (Sel, Comp);
2758 Generate_Reference (Comp, Sel);
2764 Set_Etype (Sel, Etype (Comp));
2765 Set_Etype (N, Etype (Comp));
2767 if Ekind (Comp) = E_Discriminant then
2768 Set_Original_Discriminant (Sel, Comp);
2771 -- For access type case, introduce explicit deference for
2772 -- more uniform treatment of entry calls.
2774 if Is_Access_Type (Etype (Name)) then
2775 Insert_Explicit_Dereference (Name);
2777 (Warn_On_Dereference, "?implicit dereference", N);
2783 exit when not In_Scope
2785 Comp = First_Private_Entity (Base_Type (Prefix_Type));
2788 Set_Is_Overloaded (N, Is_Overloaded (Sel));
2793 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
2796 -- If N still has no type, the component is not defined in the prefix.
2798 if Etype (N) = Any_Type then
2800 -- If the prefix is a single concurrent object, use its name in
2801 -- the error message, rather than that of its anonymous type.
2803 if Is_Concurrent_Type (Prefix_Type)
2804 and then Is_Internal_Name (Chars (Prefix_Type))
2805 and then not Is_Derived_Type (Prefix_Type)
2806 and then Is_Entity_Name (Name)
2809 Error_Msg_Node_2 := Entity (Name);
2810 Error_Msg_NE ("no selector& for&", N, Sel);
2812 Check_Misspelled_Selector (Entity_List, Sel);
2814 elsif Is_Generic_Type (Prefix_Type)
2815 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
2816 and then Prefix_Type /= Etype (Prefix_Type)
2817 and then Is_Record_Type (Etype (Prefix_Type))
2819 -- If this is a derived formal type, the parent may have a
2820 -- different visibility at this point. Try for an inherited
2821 -- component before reporting an error.
2823 Set_Etype (Prefix (N), Etype (Prefix_Type));
2824 Analyze_Selected_Component (N);
2827 elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
2828 and then Is_Generic_Actual_Type (Prefix_Type)
2829 and then Present (Full_View (Prefix_Type))
2831 -- Similarly, if this the actual for a formal derived type,
2832 -- the component inherited from the generic parent may not
2833 -- be visible in the actual, but the selected component is
2840 First_Component (Generic_Parent_Type (Parent (Prefix_Type)));
2842 while Present (Comp) loop
2843 if Chars (Comp) = Chars (Sel) then
2844 Set_Entity_With_Style_Check (Sel, Comp);
2845 Set_Etype (Sel, Etype (Comp));
2846 Set_Etype (N, Etype (Comp));
2850 Next_Component (Comp);
2853 pragma Assert (Etype (N) /= Any_Type);
2857 if Ekind (Prefix_Type) = E_Record_Subtype then
2859 -- Check whether this is a component of the base type
2860 -- which is absent from a statically constrained subtype.
2861 -- This will raise constraint error at run-time, but is
2862 -- not a compile-time error. When the selector is illegal
2863 -- for base type as well fall through and generate a
2864 -- compilation error anyway.
2866 Comp := First_Component (Base_Type (Prefix_Type));
2868 while Present (Comp) loop
2870 if Chars (Comp) = Chars (Sel)
2871 and then Is_Visible_Component (Comp)
2873 Set_Entity_With_Style_Check (Sel, Comp);
2874 Generate_Reference (Comp, Sel);
2875 Set_Etype (Sel, Etype (Comp));
2876 Set_Etype (N, Etype (Comp));
2878 -- Emit appropriate message. Gigi will replace the
2879 -- node subsequently with the appropriate Raise.
2881 Apply_Compile_Time_Constraint_Error
2882 (N, "component not present in }?",
2883 CE_Discriminant_Check_Failed,
2884 Ent => Prefix_Type, Rep => False);
2885 Set_Raises_Constraint_Error (N);
2889 Next_Component (Comp);
2894 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
2895 Error_Msg_NE ("no selector& for}", N, Sel);
2897 Check_Misspelled_Selector (Entity_List, Sel);
2901 Set_Entity (Sel, Any_Id);
2902 Set_Etype (Sel, Any_Type);
2904 end Analyze_Selected_Component;
2906 ---------------------------
2907 -- Analyze_Short_Circuit --
2908 ---------------------------
2910 procedure Analyze_Short_Circuit (N : Node_Id) is
2911 L : constant Node_Id := Left_Opnd (N);
2912 R : constant Node_Id := Right_Opnd (N);
2917 Analyze_Expression (L);
2918 Analyze_Expression (R);
2919 Set_Etype (N, Any_Type);
2921 if not Is_Overloaded (L) then
2923 if Root_Type (Etype (L)) = Standard_Boolean
2924 and then Has_Compatible_Type (R, Etype (L))
2926 Add_One_Interp (N, Etype (L), Etype (L));
2930 Get_First_Interp (L, Ind, It);
2932 while Present (It.Typ) loop
2933 if Root_Type (It.Typ) = Standard_Boolean
2934 and then Has_Compatible_Type (R, It.Typ)
2936 Add_One_Interp (N, It.Typ, It.Typ);
2939 Get_Next_Interp (Ind, It);
2943 -- Here we have failed to find an interpretation. Clearly we
2944 -- know that it is not the case that both operands can have
2945 -- an interpretation of Boolean, but this is by far the most
2946 -- likely intended interpretation. So we simply resolve both
2947 -- operands as Booleans, and at least one of these resolutions
2948 -- will generate an error message, and we do not need to give
2949 -- a further error message on the short circuit operation itself.
2951 if Etype (N) = Any_Type then
2952 Resolve (L, Standard_Boolean);
2953 Resolve (R, Standard_Boolean);
2954 Set_Etype (N, Standard_Boolean);
2956 end Analyze_Short_Circuit;
2962 procedure Analyze_Slice (N : Node_Id) is
2963 P : constant Node_Id := Prefix (N);
2964 D : constant Node_Id := Discrete_Range (N);
2965 Array_Type : Entity_Id;
2967 procedure Analyze_Overloaded_Slice;
2968 -- If the prefix is overloaded, select those interpretations that
2969 -- yield a one-dimensional array type.
2971 procedure Analyze_Overloaded_Slice is
2977 Set_Etype (N, Any_Type);
2978 Get_First_Interp (P, I, It);
2980 while Present (It.Nam) loop
2983 if Is_Access_Type (Typ) then
2984 Typ := Designated_Type (Typ);
2985 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2988 if Is_Array_Type (Typ)
2989 and then Number_Dimensions (Typ) = 1
2990 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
2992 Add_One_Interp (N, Typ, Typ);
2995 Get_Next_Interp (I, It);
2998 if Etype (N) = Any_Type then
2999 Error_Msg_N ("expect array type in prefix of slice", N);
3001 end Analyze_Overloaded_Slice;
3003 -- Start of processing for Analyze_Slice
3010 if Is_Overloaded (P) then
3011 Analyze_Overloaded_Slice;
3014 Array_Type := Etype (P);
3015 Set_Etype (N, Any_Type);
3017 if Is_Access_Type (Array_Type) then
3018 Array_Type := Designated_Type (Array_Type);
3019 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3022 if not Is_Array_Type (Array_Type) then
3023 Wrong_Type (P, Any_Array);
3025 elsif Number_Dimensions (Array_Type) > 1 then
3027 ("type is not one-dimensional array in slice prefix", N);
3030 Has_Compatible_Type (D, Etype (First_Index (Array_Type)))
3032 Wrong_Type (D, Etype (First_Index (Array_Type)));
3035 Set_Etype (N, Array_Type);
3040 -----------------------------
3041 -- Analyze_Type_Conversion --
3042 -----------------------------
3044 procedure Analyze_Type_Conversion (N : Node_Id) is
3045 Expr : constant Node_Id := Expression (N);
3049 -- If Conversion_OK is set, then the Etype is already set, and the
3050 -- only processing required is to analyze the expression. This is
3051 -- used to construct certain "illegal" conversions which are not
3052 -- allowed by Ada semantics, but can be handled OK by Gigi, see
3053 -- Sinfo for further details.
3055 if Conversion_OK (N) then
3060 -- Otherwise full type analysis is required, as well as some semantic
3061 -- checks to make sure the argument of the conversion is appropriate.
3063 Find_Type (Subtype_Mark (N));
3064 T := Entity (Subtype_Mark (N));
3066 Check_Fully_Declared (T, N);
3067 Analyze_Expression (Expr);
3068 Validate_Remote_Type_Type_Conversion (N);
3070 -- Only remaining step is validity checks on the argument. These
3071 -- are skipped if the conversion does not come from the source.
3073 if not Comes_From_Source (N) then
3076 elsif Nkind (Expr) = N_Null then
3077 Error_Msg_N ("argument of conversion cannot be null", N);
3078 Error_Msg_N ("\use qualified expression instead", N);
3079 Set_Etype (N, Any_Type);
3081 elsif Nkind (Expr) = N_Aggregate then
3082 Error_Msg_N ("argument of conversion cannot be aggregate", N);
3083 Error_Msg_N ("\use qualified expression instead", N);
3085 elsif Nkind (Expr) = N_Allocator then
3086 Error_Msg_N ("argument of conversion cannot be an allocator", N);
3087 Error_Msg_N ("\use qualified expression instead", N);
3089 elsif Nkind (Expr) = N_String_Literal then
3090 Error_Msg_N ("argument of conversion cannot be string literal", N);
3091 Error_Msg_N ("\use qualified expression instead", N);
3093 elsif Nkind (Expr) = N_Character_Literal then
3094 if Ada_Version = Ada_83 then
3097 Error_Msg_N ("argument of conversion cannot be character literal",
3099 Error_Msg_N ("\use qualified expression instead", N);
3102 elsif Nkind (Expr) = N_Attribute_Reference
3104 (Attribute_Name (Expr) = Name_Access or else
3105 Attribute_Name (Expr) = Name_Unchecked_Access or else
3106 Attribute_Name (Expr) = Name_Unrestricted_Access)
3108 Error_Msg_N ("argument of conversion cannot be access", N);
3109 Error_Msg_N ("\use qualified expression instead", N);
3112 end Analyze_Type_Conversion;
3114 ----------------------
3115 -- Analyze_Unary_Op --
3116 ----------------------
3118 procedure Analyze_Unary_Op (N : Node_Id) is
3119 R : constant Node_Id := Right_Opnd (N);
3120 Op_Id : Entity_Id := Entity (N);
3123 Set_Etype (N, Any_Type);
3124 Candidate_Type := Empty;
3126 Analyze_Expression (R);
3128 if Present (Op_Id) then
3129 if Ekind (Op_Id) = E_Operator then
3130 Find_Unary_Types (R, Op_Id, N);
3132 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3136 Op_Id := Get_Name_Entity_Id (Chars (N));
3138 while Present (Op_Id) loop
3140 if Ekind (Op_Id) = E_Operator then
3141 if No (Next_Entity (First_Entity (Op_Id))) then
3142 Find_Unary_Types (R, Op_Id, N);
3145 elsif Is_Overloadable (Op_Id) then
3146 Analyze_User_Defined_Unary_Op (N, Op_Id);
3149 Op_Id := Homonym (Op_Id);
3154 end Analyze_Unary_Op;
3156 ----------------------------------
3157 -- Analyze_Unchecked_Expression --
3158 ----------------------------------
3160 procedure Analyze_Unchecked_Expression (N : Node_Id) is
3162 Analyze (Expression (N), Suppress => All_Checks);
3163 Set_Etype (N, Etype (Expression (N)));
3164 Save_Interps (Expression (N), N);
3165 end Analyze_Unchecked_Expression;
3167 ---------------------------------------
3168 -- Analyze_Unchecked_Type_Conversion --
3169 ---------------------------------------
3171 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
3173 Find_Type (Subtype_Mark (N));
3174 Analyze_Expression (Expression (N));
3175 Set_Etype (N, Entity (Subtype_Mark (N)));
3176 end Analyze_Unchecked_Type_Conversion;
3178 ------------------------------------
3179 -- Analyze_User_Defined_Binary_Op --
3180 ------------------------------------
3182 procedure Analyze_User_Defined_Binary_Op
3187 -- Only do analysis if the operator Comes_From_Source, since otherwise
3188 -- the operator was generated by the expander, and all such operators
3189 -- always refer to the operators in package Standard.
3191 if Comes_From_Source (N) then
3193 F1 : constant Entity_Id := First_Formal (Op_Id);
3194 F2 : constant Entity_Id := Next_Formal (F1);
3197 -- Verify that Op_Id is a visible binary function. Note that since
3198 -- we know Op_Id is overloaded, potentially use visible means use
3199 -- visible for sure (RM 9.4(11)).
3201 if Ekind (Op_Id) = E_Function
3202 and then Present (F2)
3203 and then (Is_Immediately_Visible (Op_Id)
3204 or else Is_Potentially_Use_Visible (Op_Id))
3205 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
3206 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
3208 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3210 if Debug_Flag_E then
3211 Write_Str ("user defined operator ");
3212 Write_Name (Chars (Op_Id));
3213 Write_Str (" on node ");
3214 Write_Int (Int (N));
3220 end Analyze_User_Defined_Binary_Op;
3222 -----------------------------------
3223 -- Analyze_User_Defined_Unary_Op --
3224 -----------------------------------
3226 procedure Analyze_User_Defined_Unary_Op
3231 -- Only do analysis if the operator Comes_From_Source, since otherwise
3232 -- the operator was generated by the expander, and all such operators
3233 -- always refer to the operators in package Standard.
3235 if Comes_From_Source (N) then
3237 F : constant Entity_Id := First_Formal (Op_Id);
3240 -- Verify that Op_Id is a visible unary function. Note that since
3241 -- we know Op_Id is overloaded, potentially use visible means use
3242 -- visible for sure (RM 9.4(11)).
3244 if Ekind (Op_Id) = E_Function
3245 and then No (Next_Formal (F))
3246 and then (Is_Immediately_Visible (Op_Id)
3247 or else Is_Potentially_Use_Visible (Op_Id))
3248 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
3250 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3254 end Analyze_User_Defined_Unary_Op;
3256 ---------------------------
3257 -- Check_Arithmetic_Pair --
3258 ---------------------------
3260 procedure Check_Arithmetic_Pair
3261 (T1, T2 : Entity_Id;
3265 Op_Name : constant Name_Id := Chars (Op_Id);
3267 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
3268 -- Get specific type (i.e. non-universal type if there is one)
3270 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
3272 if T1 = Universal_Integer or else T1 = Universal_Real then
3273 return Base_Type (T2);
3275 return Base_Type (T1);
3279 -- Start of processing for Check_Arithmetic_Pair
3282 if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
3284 if Is_Numeric_Type (T1)
3285 and then Is_Numeric_Type (T2)
3286 and then (Covers (T1, T2) or else Covers (T2, T1))
3288 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3291 elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
3293 if Is_Fixed_Point_Type (T1)
3294 and then (Is_Fixed_Point_Type (T2)
3295 or else T2 = Universal_Real)
3297 -- If Treat_Fixed_As_Integer is set then the Etype is already set
3298 -- and no further processing is required (this is the case of an
3299 -- operator constructed by Exp_Fixd for a fixed point operation)
3300 -- Otherwise add one interpretation with universal fixed result
3301 -- If the operator is given in functional notation, it comes
3302 -- from source and Fixed_As_Integer cannot apply.
3304 if Nkind (N) not in N_Op
3305 or else not Treat_Fixed_As_Integer (N)
3307 Add_One_Interp (N, Op_Id, Universal_Fixed);
3310 elsif Is_Fixed_Point_Type (T2)
3311 and then (Nkind (N) not in N_Op
3312 or else not Treat_Fixed_As_Integer (N))
3313 and then T1 = Universal_Real
3315 Add_One_Interp (N, Op_Id, Universal_Fixed);
3317 elsif Is_Numeric_Type (T1)
3318 and then Is_Numeric_Type (T2)
3319 and then (Covers (T1, T2) or else Covers (T2, T1))
3321 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3323 elsif Is_Fixed_Point_Type (T1)
3324 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3325 or else T2 = Universal_Integer)
3327 Add_One_Interp (N, Op_Id, T1);
3329 elsif T2 = Universal_Real
3330 and then Base_Type (T1) = Base_Type (Standard_Integer)
3331 and then Op_Name = Name_Op_Multiply
3333 Add_One_Interp (N, Op_Id, Any_Fixed);
3335 elsif T1 = Universal_Real
3336 and then Base_Type (T2) = Base_Type (Standard_Integer)
3338 Add_One_Interp (N, Op_Id, Any_Fixed);
3340 elsif Is_Fixed_Point_Type (T2)
3341 and then (Base_Type (T1) = Base_Type (Standard_Integer)
3342 or else T1 = Universal_Integer)
3343 and then Op_Name = Name_Op_Multiply
3345 Add_One_Interp (N, Op_Id, T2);
3347 elsif T1 = Universal_Real and then T2 = Universal_Integer then
3348 Add_One_Interp (N, Op_Id, T1);
3350 elsif T2 = Universal_Real
3351 and then T1 = Universal_Integer
3352 and then Op_Name = Name_Op_Multiply
3354 Add_One_Interp (N, Op_Id, T2);
3357 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
3359 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
3360 -- set does not require any special processing, since the Etype is
3361 -- already set (case of operation constructed by Exp_Fixed).
3363 if Is_Integer_Type (T1)
3364 and then (Covers (T1, T2) or else Covers (T2, T1))
3366 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3369 elsif Op_Name = Name_Op_Expon then
3371 if Is_Numeric_Type (T1)
3372 and then not Is_Fixed_Point_Type (T1)
3373 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3374 or else T2 = Universal_Integer)
3376 Add_One_Interp (N, Op_Id, Base_Type (T1));
3379 else pragma Assert (Nkind (N) in N_Op_Shift);
3381 -- If not one of the predefined operators, the node may be one
3382 -- of the intrinsic functions. Its kind is always specific, and
3383 -- we can use it directly, rather than the name of the operation.
3385 if Is_Integer_Type (T1)
3386 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3387 or else T2 = Universal_Integer)
3389 Add_One_Interp (N, Op_Id, Base_Type (T1));
3392 end Check_Arithmetic_Pair;
3394 -------------------------------
3395 -- Check_Misspelled_Selector --
3396 -------------------------------
3398 procedure Check_Misspelled_Selector
3399 (Prefix : Entity_Id;
3402 Max_Suggestions : constant := 2;
3403 Nr_Of_Suggestions : Natural := 0;
3405 Suggestion_1 : Entity_Id := Empty;
3406 Suggestion_2 : Entity_Id := Empty;
3411 -- All the components of the prefix of selector Sel are matched
3412 -- against Sel and a count is maintained of possible misspellings.
3413 -- When at the end of the analysis there are one or two (not more!)
3414 -- possible misspellings, these misspellings will be suggested as
3415 -- possible correction.
3417 if not (Is_Private_Type (Prefix) or Is_Record_Type (Prefix)) then
3418 -- Concurrent types should be handled as well ???
3422 Get_Name_String (Chars (Sel));
3425 S : constant String (1 .. Name_Len) :=
3426 Name_Buffer (1 .. Name_Len);
3429 Comp := First_Entity (Prefix);
3431 while Nr_Of_Suggestions <= Max_Suggestions
3432 and then Present (Comp)
3435 if Is_Visible_Component (Comp) then
3436 Get_Name_String (Chars (Comp));
3438 if Is_Bad_Spelling_Of (Name_Buffer (1 .. Name_Len), S) then
3439 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
3441 case Nr_Of_Suggestions is
3442 when 1 => Suggestion_1 := Comp;
3443 when 2 => Suggestion_2 := Comp;
3444 when others => exit;
3449 Comp := Next_Entity (Comp);
3452 -- Report at most two suggestions
3454 if Nr_Of_Suggestions = 1 then
3455 Error_Msg_NE ("\possible misspelling of&", Sel, Suggestion_1);
3457 elsif Nr_Of_Suggestions = 2 then
3458 Error_Msg_Node_2 := Suggestion_2;
3459 Error_Msg_NE ("\possible misspelling of& or&",
3463 end Check_Misspelled_Selector;
3465 ----------------------
3466 -- Defined_In_Scope --
3467 ----------------------
3469 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
3471 S1 : constant Entity_Id := Scope (Base_Type (T));
3475 or else (S1 = System_Aux_Id and then S = Scope (S1));
3476 end Defined_In_Scope;
3482 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
3489 Void_Interp_Seen : Boolean := False;
3492 if Ada_Version >= Ada_05 then
3493 Actual := First_Actual (N);
3494 while Present (Actual) loop
3496 -- Ada 2005 (AI-50217): Post an error in case of premature
3497 -- usage of an entity from the limited view.
3499 if not Analyzed (Etype (Actual))
3500 and then From_With_Type (Etype (Actual))
3502 Error_Msg_Qual_Level := 1;
3504 ("missing with_clause for scope of imported type&",
3505 Actual, Etype (Actual));
3506 Error_Msg_Qual_Level := 0;
3509 Next_Actual (Actual);
3513 -- Analyze each candidate call again, with full error reporting
3517 ("no candidate interpretations match the actuals:!", Nam);
3518 Err_Mode := All_Errors_Mode;
3519 All_Errors_Mode := True;
3521 -- If this is a call to an operation of a concurrent type,
3522 -- the failed interpretations have been removed from the
3523 -- name. Recover them to provide full diagnostics.
3525 if Nkind (Parent (Nam)) = N_Selected_Component then
3526 Set_Entity (Nam, Empty);
3527 New_Nam := New_Copy_Tree (Parent (Nam));
3528 Set_Is_Overloaded (New_Nam, False);
3529 Set_Is_Overloaded (Selector_Name (New_Nam), False);
3530 Set_Parent (New_Nam, Parent (Parent (Nam)));
3531 Analyze_Selected_Component (New_Nam);
3532 Get_First_Interp (Selector_Name (New_Nam), X, It);
3534 Get_First_Interp (Nam, X, It);
3537 while Present (It.Nam) loop
3538 if Etype (It.Nam) = Standard_Void_Type then
3539 Void_Interp_Seen := True;
3542 Analyze_One_Call (N, It.Nam, True, Success);
3543 Get_Next_Interp (X, It);
3546 if Nkind (N) = N_Function_Call then
3547 Get_First_Interp (Nam, X, It);
3549 while Present (It.Nam) loop
3550 if Ekind (It.Nam) = E_Function
3551 or else Ekind (It.Nam) = E_Operator
3555 Get_Next_Interp (X, It);
3559 -- If all interpretations are procedures, this deserves a
3560 -- more precise message. Ditto if this appears as the prefix
3561 -- of a selected component, which may be a lexical error.
3564 "\context requires function call, found procedure name", Nam);
3566 if Nkind (Parent (N)) = N_Selected_Component
3567 and then N = Prefix (Parent (N))
3570 "\period should probably be semicolon", Parent (N));
3573 elsif Nkind (N) = N_Procedure_Call_Statement
3574 and then not Void_Interp_Seen
3577 "\function name found in procedure call", Nam);
3580 All_Errors_Mode := Err_Mode;
3583 ---------------------------
3584 -- Find_Arithmetic_Types --
3585 ---------------------------
3587 procedure Find_Arithmetic_Types
3592 Index1, Index2 : Interp_Index;
3595 procedure Check_Right_Argument (T : Entity_Id);
3596 -- Check right operand of operator
3598 procedure Check_Right_Argument (T : Entity_Id) is
3600 if not Is_Overloaded (R) then
3601 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
3603 Get_First_Interp (R, Index2, It2);
3605 while Present (It2.Typ) loop
3606 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
3607 Get_Next_Interp (Index2, It2);
3610 end Check_Right_Argument;
3612 -- Start processing for Find_Arithmetic_Types
3615 if not Is_Overloaded (L) then
3616 Check_Right_Argument (Etype (L));
3619 Get_First_Interp (L, Index1, It1);
3621 while Present (It1.Typ) loop
3622 Check_Right_Argument (It1.Typ);
3623 Get_Next_Interp (Index1, It1);
3627 end Find_Arithmetic_Types;
3629 ------------------------
3630 -- Find_Boolean_Types --
3631 ------------------------
3633 procedure Find_Boolean_Types
3638 Index : Interp_Index;
3641 procedure Check_Numeric_Argument (T : Entity_Id);
3642 -- Special case for logical operations one of whose operands is an
3643 -- integer literal. If both are literal the result is any modular type.
3645 procedure Check_Numeric_Argument (T : Entity_Id) is
3647 if T = Universal_Integer then
3648 Add_One_Interp (N, Op_Id, Any_Modular);
3650 elsif Is_Modular_Integer_Type (T) then
3651 Add_One_Interp (N, Op_Id, T);
3653 end Check_Numeric_Argument;
3655 -- Start of processing for Find_Boolean_Types
3658 if not Is_Overloaded (L) then
3660 if Etype (L) = Universal_Integer
3661 or else Etype (L) = Any_Modular
3663 if not Is_Overloaded (R) then
3664 Check_Numeric_Argument (Etype (R));
3667 Get_First_Interp (R, Index, It);
3669 while Present (It.Typ) loop
3670 Check_Numeric_Argument (It.Typ);
3672 Get_Next_Interp (Index, It);
3676 elsif Valid_Boolean_Arg (Etype (L))
3677 and then Has_Compatible_Type (R, Etype (L))
3679 Add_One_Interp (N, Op_Id, Etype (L));
3683 Get_First_Interp (L, Index, It);
3685 while Present (It.Typ) loop
3686 if Valid_Boolean_Arg (It.Typ)
3687 and then Has_Compatible_Type (R, It.Typ)
3689 Add_One_Interp (N, Op_Id, It.Typ);
3692 Get_Next_Interp (Index, It);
3695 end Find_Boolean_Types;
3697 ---------------------------
3698 -- Find_Comparison_Types --
3699 ---------------------------
3701 procedure Find_Comparison_Types
3706 Index : Interp_Index;
3708 Found : Boolean := False;
3711 Scop : Entity_Id := Empty;
3713 procedure Try_One_Interp (T1 : Entity_Id);
3714 -- Routine to try one proposed interpretation. Note that the context
3715 -- of the operator plays no role in resolving the arguments, so that
3716 -- if there is more than one interpretation of the operands that is
3717 -- compatible with comparison, the operation is ambiguous.
3719 procedure Try_One_Interp (T1 : Entity_Id) is
3722 -- If the operator is an expanded name, then the type of the operand
3723 -- must be defined in the corresponding scope. If the type is
3724 -- universal, the context will impose the correct type.
3727 and then not Defined_In_Scope (T1, Scop)
3728 and then T1 /= Universal_Integer
3729 and then T1 /= Universal_Real
3730 and then T1 /= Any_String
3731 and then T1 /= Any_Composite
3736 if Valid_Comparison_Arg (T1)
3737 and then Has_Compatible_Type (R, T1)
3740 and then Base_Type (T1) /= Base_Type (T_F)
3742 It := Disambiguate (L, I_F, Index, Any_Type);
3744 if It = No_Interp then
3745 Ambiguous_Operands (N);
3746 Set_Etype (L, Any_Type);
3760 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
3765 -- Start processing for Find_Comparison_Types
3768 -- If left operand is aggregate, the right operand has to
3769 -- provide a usable type for it.
3771 if Nkind (L) = N_Aggregate
3772 and then Nkind (R) /= N_Aggregate
3774 Find_Comparison_Types (R, L, Op_Id, N);
3778 if Nkind (N) = N_Function_Call
3779 and then Nkind (Name (N)) = N_Expanded_Name
3781 Scop := Entity (Prefix (Name (N)));
3783 -- The prefix may be a package renaming, and the subsequent test
3784 -- requires the original package.
3786 if Ekind (Scop) = E_Package
3787 and then Present (Renamed_Entity (Scop))
3789 Scop := Renamed_Entity (Scop);
3790 Set_Entity (Prefix (Name (N)), Scop);
3794 if not Is_Overloaded (L) then
3795 Try_One_Interp (Etype (L));
3798 Get_First_Interp (L, Index, It);
3800 while Present (It.Typ) loop
3801 Try_One_Interp (It.Typ);
3802 Get_Next_Interp (Index, It);
3805 end Find_Comparison_Types;
3807 ----------------------------------------
3808 -- Find_Non_Universal_Interpretations --
3809 ----------------------------------------
3811 procedure Find_Non_Universal_Interpretations
3817 Index : Interp_Index;
3821 if T1 = Universal_Integer
3822 or else T1 = Universal_Real
3824 if not Is_Overloaded (R) then
3826 (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
3828 Get_First_Interp (R, Index, It);
3830 while Present (It.Typ) loop
3831 if Covers (It.Typ, T1) then
3833 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
3836 Get_Next_Interp (Index, It);
3840 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
3842 end Find_Non_Universal_Interpretations;
3844 ------------------------------
3845 -- Find_Concatenation_Types --
3846 ------------------------------
3848 procedure Find_Concatenation_Types
3853 Op_Type : constant Entity_Id := Etype (Op_Id);
3856 if Is_Array_Type (Op_Type)
3857 and then not Is_Limited_Type (Op_Type)
3859 and then (Has_Compatible_Type (L, Op_Type)
3861 Has_Compatible_Type (L, Component_Type (Op_Type)))
3863 and then (Has_Compatible_Type (R, Op_Type)
3865 Has_Compatible_Type (R, Component_Type (Op_Type)))
3867 Add_One_Interp (N, Op_Id, Op_Type);
3869 end Find_Concatenation_Types;
3871 -------------------------
3872 -- Find_Equality_Types --
3873 -------------------------
3875 procedure Find_Equality_Types
3880 Index : Interp_Index;
3882 Found : Boolean := False;
3885 Scop : Entity_Id := Empty;
3887 procedure Try_One_Interp (T1 : Entity_Id);
3888 -- The context of the operator plays no role in resolving the
3889 -- arguments, so that if there is more than one interpretation
3890 -- of the operands that is compatible with equality, the construct
3891 -- is ambiguous and an error can be emitted now, after trying to
3892 -- disambiguate, i.e. applying preference rules.
3894 procedure Try_One_Interp (T1 : Entity_Id) is
3897 -- If the operator is an expanded name, then the type of the operand
3898 -- must be defined in the corresponding scope. If the type is
3899 -- universal, the context will impose the correct type. An anonymous
3900 -- type for a 'Access reference is also universal in this sense, as
3901 -- the actual type is obtained from context.
3904 and then not Defined_In_Scope (T1, Scop)
3905 and then T1 /= Universal_Integer
3906 and then T1 /= Universal_Real
3907 and then T1 /= Any_Access
3908 and then T1 /= Any_String
3909 and then T1 /= Any_Composite
3910 and then (Ekind (T1) /= E_Access_Subprogram_Type
3911 or else Comes_From_Source (T1))
3916 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
3917 -- Do not allow anonymous access types in equality operators.
3919 if Ada_Version < Ada_05
3920 and then Ekind (T1) = E_Anonymous_Access_Type
3925 if T1 /= Standard_Void_Type
3926 and then not Is_Limited_Type (T1)
3927 and then not Is_Limited_Composite (T1)
3928 and then Has_Compatible_Type (R, T1)
3931 and then Base_Type (T1) /= Base_Type (T_F)
3933 It := Disambiguate (L, I_F, Index, Any_Type);
3935 if It = No_Interp then
3936 Ambiguous_Operands (N);
3937 Set_Etype (L, Any_Type);
3950 if not Analyzed (L) then
3954 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
3956 if Etype (N) = Any_Type then
3958 -- Operator was not visible.
3965 -- Start of processing for Find_Equality_Types
3968 -- If left operand is aggregate, the right operand has to
3969 -- provide a usable type for it.
3971 if Nkind (L) = N_Aggregate
3972 and then Nkind (R) /= N_Aggregate
3974 Find_Equality_Types (R, L, Op_Id, N);
3978 if Nkind (N) = N_Function_Call
3979 and then Nkind (Name (N)) = N_Expanded_Name
3981 Scop := Entity (Prefix (Name (N)));
3983 -- The prefix may be a package renaming, and the subsequent test
3984 -- requires the original package.
3986 if Ekind (Scop) = E_Package
3987 and then Present (Renamed_Entity (Scop))
3989 Scop := Renamed_Entity (Scop);
3990 Set_Entity (Prefix (Name (N)), Scop);
3994 if not Is_Overloaded (L) then
3995 Try_One_Interp (Etype (L));
3998 Get_First_Interp (L, Index, It);
4000 while Present (It.Typ) loop
4001 Try_One_Interp (It.Typ);
4002 Get_Next_Interp (Index, It);
4005 end Find_Equality_Types;
4007 -------------------------
4008 -- Find_Negation_Types --
4009 -------------------------
4011 procedure Find_Negation_Types
4016 Index : Interp_Index;
4020 if not Is_Overloaded (R) then
4022 if Etype (R) = Universal_Integer then
4023 Add_One_Interp (N, Op_Id, Any_Modular);
4025 elsif Valid_Boolean_Arg (Etype (R)) then
4026 Add_One_Interp (N, Op_Id, Etype (R));
4030 Get_First_Interp (R, Index, It);
4032 while Present (It.Typ) loop
4033 if Valid_Boolean_Arg (It.Typ) then
4034 Add_One_Interp (N, Op_Id, It.Typ);
4037 Get_Next_Interp (Index, It);
4040 end Find_Negation_Types;
4042 ----------------------
4043 -- Find_Unary_Types --
4044 ----------------------
4046 procedure Find_Unary_Types
4051 Index : Interp_Index;
4055 if not Is_Overloaded (R) then
4056 if Is_Numeric_Type (Etype (R)) then
4057 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
4061 Get_First_Interp (R, Index, It);
4063 while Present (It.Typ) loop
4064 if Is_Numeric_Type (It.Typ) then
4065 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
4068 Get_Next_Interp (Index, It);
4071 end Find_Unary_Types;
4077 function Junk_Operand (N : Node_Id) return Boolean is
4081 if Error_Posted (N) then
4085 -- Get entity to be tested
4087 if Is_Entity_Name (N)
4088 and then Present (Entity (N))
4092 -- An odd case, a procedure name gets converted to a very peculiar
4093 -- function call, and here is where we detect this happening.
4095 elsif Nkind (N) = N_Function_Call
4096 and then Is_Entity_Name (Name (N))
4097 and then Present (Entity (Name (N)))
4101 -- Another odd case, there are at least some cases of selected
4102 -- components where the selected component is not marked as having
4103 -- an entity, even though the selector does have an entity
4105 elsif Nkind (N) = N_Selected_Component
4106 and then Present (Entity (Selector_Name (N)))
4108 Enode := Selector_Name (N);
4114 -- Now test the entity we got to see if it a bad case
4116 case Ekind (Entity (Enode)) is
4120 ("package name cannot be used as operand", Enode);
4122 when Generic_Unit_Kind =>
4124 ("generic unit name cannot be used as operand", Enode);
4128 ("subtype name cannot be used as operand", Enode);
4132 ("entry name cannot be used as operand", Enode);
4136 ("procedure name cannot be used as operand", Enode);
4140 ("exception name cannot be used as operand", Enode);
4142 when E_Block | E_Label | E_Loop =>
4144 ("label name cannot be used as operand", Enode);
4154 --------------------
4155 -- Operator_Check --
4156 --------------------
4158 procedure Operator_Check (N : Node_Id) is
4160 Remove_Abstract_Operations (N);
4162 -- Test for case of no interpretation found for operator
4164 if Etype (N) = Any_Type then
4170 R := Right_Opnd (N);
4172 if Nkind (N) in N_Binary_Op then
4178 -- If either operand has no type, then don't complain further,
4179 -- since this simply means that we have a propragated error.
4182 or else Etype (R) = Any_Type
4183 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
4187 -- We explicitly check for the case of concatenation of
4188 -- component with component to avoid reporting spurious
4189 -- matching array types that might happen to be lurking
4190 -- in distant packages (such as run-time packages). This
4191 -- also prevents inconsistencies in the messages for certain
4192 -- ACVC B tests, which can vary depending on types declared
4193 -- in run-time interfaces. A further improvement, when
4194 -- aggregates are present, is to look for a well-typed operand.
4196 elsif Present (Candidate_Type)
4197 and then (Nkind (N) /= N_Op_Concat
4198 or else Is_Array_Type (Etype (L))
4199 or else Is_Array_Type (Etype (R)))
4202 if Nkind (N) = N_Op_Concat then
4203 if Etype (L) /= Any_Composite
4204 and then Is_Array_Type (Etype (L))
4206 Candidate_Type := Etype (L);
4208 elsif Etype (R) /= Any_Composite
4209 and then Is_Array_Type (Etype (R))
4211 Candidate_Type := Etype (R);
4216 ("operator for} is not directly visible!",
4217 N, First_Subtype (Candidate_Type));
4218 Error_Msg_N ("use clause would make operation legal!", N);
4221 -- If either operand is a junk operand (e.g. package name), then
4222 -- post appropriate error messages, but do not complain further.
4224 -- Note that the use of OR in this test instead of OR ELSE
4225 -- is quite deliberate, we may as well check both operands
4226 -- in the binary operator case.
4228 elsif Junk_Operand (R)
4229 or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
4233 -- If we have a logical operator, one of whose operands is
4234 -- Boolean, then we know that the other operand cannot resolve
4235 -- to Boolean (since we got no interpretations), but in that
4236 -- case we pretty much know that the other operand should be
4237 -- Boolean, so resolve it that way (generating an error)
4239 elsif Nkind (N) = N_Op_And
4243 Nkind (N) = N_Op_Xor
4245 if Etype (L) = Standard_Boolean then
4246 Resolve (R, Standard_Boolean);
4248 elsif Etype (R) = Standard_Boolean then
4249 Resolve (L, Standard_Boolean);
4253 -- For an arithmetic operator or comparison operator, if one
4254 -- of the operands is numeric, then we know the other operand
4255 -- is not the same numeric type. If it is a non-numeric type,
4256 -- then probably it is intended to match the other operand.
4258 elsif Nkind (N) = N_Op_Add or else
4259 Nkind (N) = N_Op_Divide or else
4260 Nkind (N) = N_Op_Ge or else
4261 Nkind (N) = N_Op_Gt or else
4262 Nkind (N) = N_Op_Le or else
4263 Nkind (N) = N_Op_Lt or else
4264 Nkind (N) = N_Op_Mod or else
4265 Nkind (N) = N_Op_Multiply or else
4266 Nkind (N) = N_Op_Rem or else
4267 Nkind (N) = N_Op_Subtract
4269 if Is_Numeric_Type (Etype (L))
4270 and then not Is_Numeric_Type (Etype (R))
4272 Resolve (R, Etype (L));
4275 elsif Is_Numeric_Type (Etype (R))
4276 and then not Is_Numeric_Type (Etype (L))
4278 Resolve (L, Etype (R));
4282 -- Comparisons on A'Access are common enough to deserve a
4285 elsif (Nkind (N) = N_Op_Eq or else
4286 Nkind (N) = N_Op_Ne)
4287 and then Ekind (Etype (L)) = E_Access_Attribute_Type
4288 and then Ekind (Etype (R)) = E_Access_Attribute_Type
4291 ("two access attributes cannot be compared directly", N);
4293 ("\they must be converted to an explicit type for comparison",
4297 -- Another one for C programmers
4299 elsif Nkind (N) = N_Op_Concat
4300 and then Valid_Boolean_Arg (Etype (L))
4301 and then Valid_Boolean_Arg (Etype (R))
4303 Error_Msg_N ("invalid operands for concatenation", N);
4304 Error_Msg_N ("\maybe AND was meant", N);
4307 -- A special case for comparison of access parameter with null
4309 elsif Nkind (N) = N_Op_Eq
4310 and then Is_Entity_Name (L)
4311 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
4312 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
4314 and then Nkind (R) = N_Null
4316 Error_Msg_N ("access parameter is not allowed to be null", L);
4317 Error_Msg_N ("\(call would raise Constraint_Error)", L);
4321 -- If we fall through then just give general message. Note
4322 -- that in the following messages, if the operand is overloaded
4323 -- we choose an arbitrary type to complain about, but that is
4324 -- probably more useful than not giving a type at all.
4326 if Nkind (N) in N_Unary_Op then
4327 Error_Msg_Node_2 := Etype (R);
4328 Error_Msg_N ("operator& not defined for}", N);
4332 if Nkind (N) in N_Binary_Op then
4333 if not Is_Overloaded (L)
4334 and then not Is_Overloaded (R)
4335 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
4337 Error_Msg_Node_2 := Etype (R);
4338 Error_Msg_N ("there is no applicable operator& for}", N);
4341 Error_Msg_N ("invalid operand types for operator&", N);
4343 if Nkind (N) /= N_Op_Concat then
4344 Error_Msg_NE ("\left operand has}!", N, Etype (L));
4345 Error_Msg_NE ("\right operand has}!", N, Etype (R));
4354 --------------------------------
4355 -- Remove_Abstract_Operations --
4356 --------------------------------
4358 procedure Remove_Abstract_Operations (N : Node_Id) is
4361 Abstract_Op : Entity_Id := Empty;
4363 -- AI-310: If overloaded, remove abstract non-dispatching
4364 -- operations. We activate this if either extensions are
4365 -- enabled, or if the abstract operation in question comes
4366 -- from a predefined file. This latter test allows us to
4367 -- use abstract to make operations invisible to users. In
4368 -- particular, if type Address is non-private and abstract
4369 -- subprograms are used to hide its operators, they will be
4372 type Operand_Position is (First_Op, Second_Op);
4373 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
4375 procedure Remove_Address_Interpretations (Op : Operand_Position);
4376 -- Ambiguities may arise when the operands are literal and the
4377 -- address operations in s-auxdec are visible. In that case, remove
4378 -- the interpretation of a literal as Address, to retain the semantics
4379 -- of Address as a private type.
4381 ------------------------------------
4382 -- Remove_Address_Interpretations --
4383 ------------------------------------
4385 procedure Remove_Address_Interpretations (Op : Operand_Position) is
4389 if Is_Overloaded (N) then
4390 Get_First_Interp (N, I, It);
4391 while Present (It.Nam) loop
4392 Formal := First_Entity (It.Nam);
4394 if Op = Second_Op then
4395 Formal := Next_Entity (Formal);
4398 if Is_Descendent_Of_Address (Etype (Formal)) then
4402 Get_Next_Interp (I, It);
4405 end Remove_Address_Interpretations;
4407 -- Start of processing for Remove_Abstract_Operations
4410 if Is_Overloaded (N) then
4411 Get_First_Interp (N, I, It);
4413 while Present (It.Nam) loop
4414 if not Is_Type (It.Nam)
4415 and then Is_Abstract (It.Nam)
4416 and then not Is_Dispatching_Operation (It.Nam)
4418 (Ada_Version >= Ada_05
4419 or else Is_Predefined_File_Name
4420 (Unit_File_Name (Get_Source_Unit (It.Nam))))
4423 Abstract_Op := It.Nam;
4428 Get_Next_Interp (I, It);
4431 if No (Abstract_Op) then
4434 elsif Nkind (N) in N_Op then
4435 -- Remove interpretations that treat literals as addresses.
4436 -- This is never appropriate.
4438 if Nkind (N) in N_Binary_Op then
4440 U1 : constant Boolean :=
4441 Present (Universal_Interpretation (Right_Opnd (N)));
4442 U2 : constant Boolean :=
4443 Present (Universal_Interpretation (Left_Opnd (N)));
4446 if U1 and then not U2 then
4447 Remove_Address_Interpretations (Second_Op);
4449 elsif U2 and then not U1 then
4450 Remove_Address_Interpretations (First_Op);
4453 if not (U1 and U2) then
4455 -- Remove corresponding predefined operator, which is
4456 -- always added to the overload set.
4458 Get_First_Interp (N, I, It);
4459 while Present (It.Nam) loop
4460 if Scope (It.Nam) = Standard_Standard
4461 and then Base_Type (It.Typ) =
4462 Base_Type (Etype (Abstract_Op))
4467 Get_Next_Interp (I, It);
4470 elsif Is_Overloaded (N)
4471 and then Present (Univ_Type)
4473 -- If both operands have a universal interpretation,
4474 -- select the predefined operator and discard others.
4476 Get_First_Interp (N, I, It);
4478 while Present (It.Nam) loop
4479 if Scope (It.Nam) = Standard_Standard then
4480 Set_Etype (N, Univ_Type);
4481 Set_Entity (N, It.Nam);
4482 Set_Is_Overloaded (N, False);
4486 Get_Next_Interp (I, It);
4492 elsif Nkind (N) = N_Function_Call
4494 (Nkind (Name (N)) = N_Operator_Symbol
4496 (Nkind (Name (N)) = N_Expanded_Name
4498 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
4502 Arg1 : constant Node_Id := First (Parameter_Associations (N));
4503 U1 : constant Boolean :=
4504 Present (Universal_Interpretation (Arg1));
4505 U2 : constant Boolean :=
4506 Present (Next (Arg1)) and then
4507 Present (Universal_Interpretation (Next (Arg1)));
4510 if U1 and then not U2 then
4511 Remove_Address_Interpretations (First_Op);
4513 elsif U2 and then not U1 then
4514 Remove_Address_Interpretations (Second_Op);
4517 if not (U1 and U2) then
4518 Get_First_Interp (N, I, It);
4519 while Present (It.Nam) loop
4520 if Scope (It.Nam) = Standard_Standard
4521 and then It.Typ = Base_Type (Etype (Abstract_Op))
4526 Get_Next_Interp (I, It);
4532 -- If the removal has left no valid interpretations, emit
4533 -- error message now and label node as illegal.
4535 if Present (Abstract_Op) then
4536 Get_First_Interp (N, I, It);
4540 -- Removal of abstract operation left no viable candidate.
4542 Set_Etype (N, Any_Type);
4543 Error_Msg_Sloc := Sloc (Abstract_Op);
4545 ("cannot call abstract operation& declared#", N, Abstract_Op);
4549 end Remove_Abstract_Operations;
4551 -----------------------
4552 -- Try_Indirect_Call --
4553 -----------------------
4555 function Try_Indirect_Call
4558 Typ : Entity_Id) return Boolean
4565 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
4566 Actual := First_Actual (N);
4567 Formal := First_Formal (Designated_Type (Typ));
4569 while Present (Actual)
4570 and then Present (Formal)
4572 if not Has_Compatible_Type (Actual, Etype (Formal)) then
4577 Next_Formal (Formal);
4580 if No (Actual) and then No (Formal) then
4581 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
4583 -- Nam is a candidate interpretation for the name in the call,
4584 -- if it is not an indirect call.
4586 if not Is_Type (Nam)
4587 and then Is_Entity_Name (Name (N))
4589 Set_Entity (Name (N), Nam);
4596 end Try_Indirect_Call;
4598 ----------------------
4599 -- Try_Indexed_Call --
4600 ----------------------
4602 function Try_Indexed_Call
4605 Typ : Entity_Id) return Boolean
4607 Actuals : constant List_Id := Parameter_Associations (N);
4612 Actual := First (Actuals);
4613 Index := First_Index (Typ);
4614 while Present (Actual)
4615 and then Present (Index)
4617 -- If the parameter list has a named association, the expression
4618 -- is definitely a call and not an indexed component.
4620 if Nkind (Actual) = N_Parameter_Association then
4624 if not Has_Compatible_Type (Actual, Etype (Index)) then
4632 if No (Actual) and then No (Index) then
4633 Add_One_Interp (N, Nam, Component_Type (Typ));
4635 -- Nam is a candidate interpretation for the name in the call,
4636 -- if it is not an indirect call.
4638 if not Is_Type (Nam)
4639 and then Is_Entity_Name (Name (N))
4641 Set_Entity (Name (N), Nam);
4649 end Try_Indexed_Call;
4651 --------------------------
4652 -- Try_Object_Operation --
4653 --------------------------
4655 function Try_Object_Operation (N : Node_Id) return Boolean is
4656 Obj : constant Node_Id := Prefix (N);
4657 Obj_Type : Entity_Id;
4660 Last_Node : Node_Id;
4661 -- Used to free all the nodes generated while trying the alternatives.
4662 -- To me removed later, too low level ???
4664 use Atree_Private_Part;
4666 function Try_Replacement
4667 (New_Prefix : Entity_Id;
4668 New_Subprg : Node_Id;
4669 New_Formal : Node_Id;
4670 Nam_Ent : Entity_Id) return Boolean;
4671 -- Replace the node with the Object.Operation notation by the
4672 -- equivalent node with the Package.Operation (Object, ...) notation
4674 -- Nam_Ent is the entity that provides the formals against which
4675 -- the actuals are checked. If the actuals are compatible with
4676 -- Ent_Nam, this function returns true.
4677 -- Document other parameters, also what is Ent_Nam???
4679 function Try_Primitive_Operations
4680 (New_Prefix : Entity_Id;
4681 New_Subprg : Node_Id;
4683 Obj_Type : Entity_Id) return Boolean;
4684 -- Traverse list of primitive subprograms to look for the subprogram
4685 -- Parameters should be documented ???
4688 function Try_Class_Wide_Operation
4689 (New_Subprg : Node_Id;
4691 Obj_Type : Entity_Id) return Boolean;
4692 -- Traverse all the ancestor types to look for a class-wide subprogram
4693 -- Parameters should be documented ???
4695 ------------------------------
4696 -- Try_Primitive_Operations --
4697 ------------------------------
4699 function Try_Primitive_Operations
4700 (New_Prefix : Entity_Id;
4701 New_Subprg : Node_Id;
4703 Obj_Type : Entity_Id) return Boolean
4707 Prim_Op : Entity_Id;
4710 -- Look for the subprogram in the list of primitive operations.
4711 -- This case is simple because all the primitive operations are
4712 -- implicitly inherited and thus we have a candidate as soon as
4713 -- we find a primitive subprogram with the same name. The latter
4714 -- analysis after the node replacement will resolve it.
4716 Elmt := First_Elmt (Primitive_Operations (Obj_Type));
4717 while Present (Elmt) loop
4718 Prim_Op := Node (Elmt);
4720 if Chars (Prim_Op) = Chars (New_Subprg) then
4721 if Try_Replacement (New_Prefix => New_Prefix,
4722 New_Subprg => New_Subprg,
4728 -- Try the implicit dereference in case of access type
4730 elsif Is_Access_Type (Etype (Obj)) then
4731 Deref := Make_Explicit_Dereference (Sloc (Obj), Obj);
4732 Set_Etype (Deref, Obj_Type);
4734 if Try_Replacement (New_Prefix => New_Prefix,
4735 New_Subprg => New_Subprg,
4736 New_Formal => Deref,
4748 end Try_Primitive_Operations;
4750 ------------------------------
4751 -- Try_Class_Wide_Operation --
4752 ------------------------------
4754 function Try_Class_Wide_Operation
4755 (New_Subprg : Node_Id;
4757 Obj_Type : Entity_Id) return Boolean
4764 -- Loop through ancestor types
4768 -- For each parent subtype we traverse all the homonym chain
4769 -- looking for a candidate class-wide subprogram
4771 Hom := Current_Entity (New_Subprg);
4772 while Present (Hom) loop
4773 if (Ekind (Hom) = E_Procedure
4774 or else Ekind (Hom) = E_Function)
4775 and then Present (First_Entity (Hom))
4776 and then Etype (First_Entity (Hom)) = Class_Wide_Type (Typ)
4779 (New_Prefix => Scope (Hom),
4780 New_Subprg => Make_Identifier (Sloc (N), Chars (Hom)),
4786 -- Try the implicit dereference in case of access type
4788 elsif Is_Access_Type (Etype (Obj)) then
4789 Deref := Make_Explicit_Dereference (Sloc (Obj), Obj);
4790 Set_Etype (Deref, Obj_Type);
4793 (New_Prefix => Scope (Hom),
4794 New_Subprg => Make_Identifier (Sloc (N), Chars (Hom)),
4795 New_Formal => Deref,
4803 Hom := Homonym (Hom);
4806 -- Climb to ancestor type if there is one
4808 exit when Etype (Typ) = Typ;
4813 end Try_Class_Wide_Operation;
4815 ---------------------
4816 -- Try_Replacement --
4817 ---------------------
4819 function Try_Replacement
4820 (New_Prefix : Entity_Id;
4821 New_Subprg : Node_Id;
4822 New_Formal : Node_Id;
4823 Nam_Ent : Entity_Id) return Boolean
4825 Loc : constant Source_Ptr := Sloc (N);
4826 Call_Node : Node_Id;
4828 New_Actuals : List_Id;
4829 Node_To_Replace : Node_Id;
4833 -- Step 1. Build the replacement node: a subprogram call node
4834 -- with the object as its first actual parameter
4836 New_Name := Make_Selected_Component (Loc,
4837 Prefix => New_Reference_To (New_Prefix, Loc),
4838 Selector_Name => New_Copy_Tree (New_Subprg));
4840 New_Actuals := New_List (New_Copy_Tree (New_Formal));
4842 if (Nkind (Parent (N)) = N_Procedure_Call_Statement
4843 or else Nkind (Parent (N)) = N_Function_Call)
4845 -- Protect against recursive call; It occurs in "..:= F (O.P)"
4847 and then N /= First (Parameter_Associations (Parent (N)))
4850 Node_To_Replace := Parent (N);
4854 New_Copy_List (Parameter_Associations (Node_To_Replace)));
4856 if Nkind (Node_To_Replace) = N_Procedure_Call_Statement then
4858 Make_Procedure_Call_Statement (Loc, New_Name, New_Actuals);
4860 else pragma Assert (Nkind (Node_To_Replace) = N_Function_Call);
4862 Make_Function_Call (Loc, New_Name, New_Actuals);
4865 -- Case of a function without parameters
4868 Node_To_Replace := N;
4871 Make_Function_Call (Loc, New_Name, New_Actuals);
4874 -- Step 2. Analyze the candidate replacement node. If it was
4875 -- successfully analyzed then replace the original node and
4876 -- carry out the full analysis to verify that there is no
4877 -- conflict with overloaded subprograms.
4879 -- To properly analyze the candidate we must initialize the type
4880 -- of the result node of the call to the error type; it will be
4881 -- reset if the type is successfully resolved.
4883 Set_Etype (Call_Node, Any_Type);
4888 Report => False, -- do not post errors
4889 Success => Success);
4892 -- Previous analysis transformed the node with the name
4893 -- and we have to reset it to properly re-analyze it.
4896 Make_Selected_Component (Loc,
4897 Prefix => New_Reference_To (New_Prefix, Loc),
4898 Selector_Name => New_Copy_Tree (New_Subprg));
4899 Set_Name (Call_Node, New_Name);
4901 Set_Analyzed (Call_Node, False);
4902 Set_Parent (Call_Node, Parent (Node_To_Replace));
4903 Replace (Node_To_Replace, Call_Node);
4904 Analyze (Node_To_Replace);
4907 -- Free all the nodes used for this test and return
4910 Nodes.Set_Last (Last_Node);
4913 end Try_Replacement;
4915 -- Start of processing for Try_Object_Operation
4918 -- Find the type of the object
4920 Obj_Type := Etype (Obj);
4922 if Is_Access_Type (Obj_Type) then
4923 Obj_Type := Designated_Type (Obj_Type);
4926 if Ekind (Obj_Type) = E_Private_Subtype then
4927 Obj_Type := Base_Type (Obj_Type);
4930 if Is_Class_Wide_Type (Obj_Type) then
4931 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
4934 -- Analyze the actuals
4936 if (Nkind (Parent (N)) = N_Procedure_Call_Statement
4937 or else Nkind (Parent (N)) = N_Function_Call)
4939 -- Protects against recursive call in case of "..:= F (O.Proc)"
4941 and then N /= First (Parameter_Associations (Parent (N)))
4943 Actual := First (Parameter_Associations (Parent (N)));
4945 while Present (Actual) loop
4947 Check_Parameterless_Call (Actual);
4948 Next_Actual (Actual);
4952 Last_Node := Last_Node_Id;
4954 return Try_Primitive_Operations
4955 (New_Prefix => Scope (Obj_Type),
4956 New_Subprg => Selector_Name (N),
4958 Obj_Type => Obj_Type)
4960 Try_Class_Wide_Operation
4961 (New_Subprg => Selector_Name (N),
4963 Obj_Type => Obj_Type);
4964 end Try_Object_Operation;