1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 with Atree; use Atree;
30 with Debug; use Debug;
31 with Einfo; use Einfo;
32 with Errout; use Errout;
35 with Output; use Output;
37 with Sem_Ch6; use Sem_Ch6;
38 with Sem_Ch8; use Sem_Ch8;
39 with Sem_Util; use Sem_Util;
40 with Stand; use Stand;
41 with Sinfo; use Sinfo;
42 with Snames; use Snames;
43 with Uintp; use Uintp;
45 package body Sem_Type is
47 -------------------------------------
48 -- Handling of Overload Resolution --
49 -------------------------------------
51 -- Overload resolution uses two passes over the syntax tree of a complete
52 -- context. In the first, bottom-up pass, the types of actuals in calls
53 -- are used to resolve possibly overloaded subprogram and operator names.
54 -- In the second top-down pass, the type of the context (for example the
55 -- condition in a while statement) is used to resolve a possibly ambiguous
56 -- call, and the unique subprogram name in turn imposes a specific context
57 -- on each of its actuals.
59 -- Most expressions are in fact unambiguous, and the bottom-up pass is
60 -- sufficient to resolve most everything. To simplify the common case,
61 -- names and expressions carry a flag Is_Overloaded to indicate whether
62 -- they have more than one interpretation. If the flag is off, then each
63 -- name has already a unique meaning and type, and the bottom-up pass is
64 -- sufficient (and much simpler).
66 --------------------------
67 -- Operator Overloading --
68 --------------------------
70 -- The visibility of operators is handled differently from that of
71 -- other entities. We do not introduce explicit versions of primitive
72 -- operators for each type definition. As a result, there is only one
73 -- entity corresponding to predefined addition on all numeric types, etc.
74 -- The back-end resolves predefined operators according to their type.
75 -- The visibility of primitive operations then reduces to the visibility
76 -- of the resulting type: (a + b) is a legal interpretation of some
77 -- primitive operator + if the type of the result (which must also be
78 -- the type of a and b) is directly visible (i.e. either immediately
79 -- visible or use-visible.)
81 -- User-defined operators are treated like other functions, but the
82 -- visibility of these user-defined operations must be special-cased
83 -- to determine whether they hide or are hidden by predefined operators.
84 -- The form P."+" (x, y) requires additional handling.
86 -- Concatenation is treated more conventionally: for every one-dimensional
87 -- array type we introduce a explicit concatenation operator. This is
88 -- necessary to handle the case of (element & element => array) which
89 -- cannot be handled conveniently if there is no explicit instance of
90 -- resulting type of the operation.
92 -----------------------
93 -- Local Subprograms --
94 -----------------------
96 procedure All_Overloads;
97 pragma Warnings (Off, All_Overloads);
98 -- Debugging procedure: list full contents of Overloads table.
100 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id;
101 -- Yields universal_Integer or Universal_Real if this is a candidate.
103 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
104 -- If T1 and T2 are compatible, return the one that is not
105 -- universal or is not a "class" type (any_character, etc).
111 procedure Add_One_Interp
115 Opnd_Type : Entity_Id := Empty)
117 Vis_Type : Entity_Id;
119 procedure Add_Entry (Name : Entity_Id; Typ : Entity_Id);
120 -- Add one interpretation to node. Node is already known to be
121 -- overloaded. Add new interpretation if not hidden by previous
122 -- one, and remove previous one if hidden by new one.
124 function Is_Universal_Operation (Op : Entity_Id) return Boolean;
125 -- True if the entity is a predefined operator and the operands have
126 -- a universal Interpretation.
132 procedure Add_Entry (Name : Entity_Id; Typ : Entity_Id) is
133 Index : Interp_Index;
137 Get_First_Interp (N, Index, It);
139 while Present (It.Nam) loop
141 -- A user-defined subprogram hides another declared at an outer
142 -- level, or one that is use-visible. So return if previous
143 -- definition hides new one (which is either in an outer
144 -- scope, or use-visible). Note that for functions use-visible
145 -- is the same as potentially use-visible. If new one hides
146 -- previous one, replace entry in table of interpretations.
147 -- If this is a universal operation, retain the operator in case
148 -- preference rule applies.
150 if (((Ekind (Name) = E_Function or else Ekind (Name) = E_Procedure)
151 and then Ekind (Name) = Ekind (It.Nam))
152 or else (Ekind (Name) = E_Operator
153 and then Ekind (It.Nam) = E_Function))
155 and then Is_Immediately_Visible (It.Nam)
156 and then Type_Conformant (Name, It.Nam)
157 and then Base_Type (It.Typ) = Base_Type (T)
159 if Is_Universal_Operation (Name) then
162 -- If node is an operator symbol, we have no actuals with
163 -- which to check hiding, and this is done in full in the
164 -- caller (Analyze_Subprogram_Renaming) so we include the
165 -- predefined operator in any case.
167 elsif Nkind (N) = N_Operator_Symbol
168 or else (Nkind (N) = N_Expanded_Name
170 Nkind (Selector_Name (N)) = N_Operator_Symbol)
174 elsif not In_Open_Scopes (Scope (Name))
175 or else Scope_Depth (Scope (Name))
176 <= Scope_Depth (Scope (It.Nam))
178 -- If ambiguity within instance, and entity is not an
179 -- implicit operation, save for later disambiguation.
181 if Scope (Name) = Scope (It.Nam)
182 and then not Is_Inherited_Operation (Name)
191 All_Interp.Table (Index).Nam := Name;
195 -- Avoid making duplicate entries in overloads
198 and then Base_Type (It.Typ) = Base_Type (T)
202 -- Otherwise keep going
205 Get_Next_Interp (Index, It);
210 -- On exit, enter new interpretation. The context, or a preference
211 -- rule, will resolve the ambiguity on the second pass.
213 All_Interp.Table (All_Interp.Last) := (Name, Typ);
214 All_Interp.Increment_Last;
215 All_Interp.Table (All_Interp.Last) := No_Interp;
219 ----------------------------
220 -- Is_Universal_Operation --
221 ----------------------------
223 function Is_Universal_Operation (Op : Entity_Id) return Boolean is
227 if Ekind (Op) /= E_Operator then
230 elsif Nkind (N) in N_Binary_Op then
231 return Present (Universal_Interpretation (Left_Opnd (N)))
232 and then Present (Universal_Interpretation (Right_Opnd (N)));
234 elsif Nkind (N) in N_Unary_Op then
235 return Present (Universal_Interpretation (Right_Opnd (N)));
237 elsif Nkind (N) = N_Function_Call then
238 Arg := First_Actual (N);
240 while Present (Arg) loop
242 if No (Universal_Interpretation (Arg)) then
254 end Is_Universal_Operation;
256 -- Start of processing for Add_One_Interp
259 -- If the interpretation is a predefined operator, verify that the
260 -- result type is visible, or that the entity has already been
261 -- resolved (case of an instantiation node that refers to a predefined
262 -- operation, or an internally generated operator node, or an operator
263 -- given as an expanded name). If the operator is a comparison or
264 -- equality, it is the type of the operand that matters to determine
265 -- whether the operator is visible. In an instance, the check is not
266 -- performed, given that the operator was visible in the generic.
268 if Ekind (E) = E_Operator then
270 if Present (Opnd_Type) then
271 Vis_Type := Opnd_Type;
273 Vis_Type := Base_Type (T);
276 if In_Open_Scopes (Scope (Vis_Type))
277 or else Is_Potentially_Use_Visible (Vis_Type)
278 or else In_Use (Vis_Type)
279 or else (In_Use (Scope (Vis_Type))
280 and then not Is_Hidden (Vis_Type))
281 or else Nkind (N) = N_Expanded_Name
282 or else (Nkind (N) in N_Op and then E = Entity (N))
287 -- If the node is given in functional notation and the prefix
288 -- is an expanded name, then the operator is visible if the
289 -- prefix is the scope of the result type as well. If the
290 -- operator is (implicitly) defined in an extension of system,
291 -- it is know to be valid (see Defined_In_Scope, sem_ch4.adb).
293 elsif Nkind (N) = N_Function_Call
294 and then Nkind (Name (N)) = N_Expanded_Name
295 and then (Entity (Prefix (Name (N))) = Scope (Base_Type (T))
296 or else Entity (Prefix (Name (N))) = Scope (Vis_Type)
297 or else Scope (Vis_Type) = System_Aux_Id)
301 -- Save type for subsequent error message, in case no other
302 -- interpretation is found.
305 Candidate_Type := Vis_Type;
309 -- In an instance, an abstract non-dispatching operation cannot
310 -- be a candidate interpretation, because it could not have been
311 -- one in the generic (it may be a spurious overloading in the
315 and then Is_Abstract (E)
316 and then not Is_Dispatching_Operation (E)
321 -- If this is the first interpretation of N, N has type Any_Type.
322 -- In that case place the new type on the node. If one interpretation
323 -- already exists, indicate that the node is overloaded, and store
324 -- both the previous and the new interpretation in All_Interp. If
325 -- this is a later interpretation, just add it to the set.
327 if Etype (N) = Any_Type then
332 -- Record both the operator or subprogram name, and its type.
334 if Nkind (N) in N_Op or else Is_Entity_Name (N) then
341 -- Either there is no current interpretation in the table for any
342 -- node or the interpretation that is present is for a different
343 -- node. In both cases add a new interpretation to the table.
345 elsif Interp_Map.Last < 0
346 or else Interp_Map.Table (Interp_Map.Last).Node /= N
350 if (Nkind (N) in N_Op or else Is_Entity_Name (N))
351 and then Present (Entity (N))
353 Add_Entry (Entity (N), Etype (N));
355 elsif (Nkind (N) = N_Function_Call
356 or else Nkind (N) = N_Procedure_Call_Statement)
357 and then (Nkind (Name (N)) = N_Operator_Symbol
358 or else Is_Entity_Name (Name (N)))
360 Add_Entry (Entity (Name (N)), Etype (N));
363 -- Overloaded prefix in indexed or selected component,
364 -- or call whose name is an expression or another call.
366 Add_Entry (Etype (N), Etype (N));
380 procedure All_Overloads is
382 for J in All_Interp.First .. All_Interp.Last loop
384 if Present (All_Interp.Table (J).Nam) then
385 Write_Entity_Info (All_Interp.Table (J). Nam, " ");
387 Write_Str ("No Interp");
390 Write_Str ("=================");
395 ---------------------
396 -- Collect_Interps --
397 ---------------------
399 procedure Collect_Interps (N : Node_Id) is
400 Ent : constant Entity_Id := Entity (N);
402 First_Interp : Interp_Index;
407 -- Unconditionally add the entity that was initially matched
409 First_Interp := All_Interp.Last;
410 Add_One_Interp (N, Ent, Etype (N));
412 -- For expanded name, pick up all additional entities from the
413 -- same scope, since these are obviously also visible. Note that
414 -- these are not necessarily contiguous on the homonym chain.
416 if Nkind (N) = N_Expanded_Name then
418 while Present (H) loop
419 if Scope (H) = Scope (Entity (N)) then
420 Add_One_Interp (N, H, Etype (H));
426 -- Case of direct name
429 -- First, search the homonym chain for directly visible entities
431 H := Current_Entity (Ent);
432 while Present (H) loop
433 exit when (not Is_Overloadable (H))
434 and then Is_Immediately_Visible (H);
436 if Is_Immediately_Visible (H)
439 -- Only add interpretation if not hidden by an inner
440 -- immediately visible one.
442 for J in First_Interp .. All_Interp.Last - 1 loop
444 -- Current homograph is not hidden. Add to overloads.
446 if not Is_Immediately_Visible (All_Interp.Table (J).Nam) then
449 -- Homograph is hidden, unless it is a predefined operator.
451 elsif Type_Conformant (H, All_Interp.Table (J).Nam) then
453 -- A homograph in the same scope can occur within an
454 -- instantiation, the resulting ambiguity has to be
457 if Scope (H) = Scope (Ent)
459 and then not Is_Inherited_Operation (H)
461 All_Interp.Table (All_Interp.Last) := (H, Etype (H));
462 All_Interp.Increment_Last;
463 All_Interp.Table (All_Interp.Last) := No_Interp;
466 elsif Scope (H) /= Standard_Standard then
472 -- On exit, we know that current homograph is not hidden.
474 Add_One_Interp (N, H, Etype (H));
477 Write_Str ("Add overloaded Interpretation ");
487 -- Scan list of homographs for use-visible entities only.
489 H := Current_Entity (Ent);
491 while Present (H) loop
492 if Is_Potentially_Use_Visible (H)
494 and then Is_Overloadable (H)
496 for J in First_Interp .. All_Interp.Last - 1 loop
498 if not Is_Immediately_Visible (All_Interp.Table (J).Nam) then
501 elsif Type_Conformant (H, All_Interp.Table (J).Nam) then
502 goto Next_Use_Homograph;
506 Add_One_Interp (N, H, Etype (H));
509 <<Next_Use_Homograph>>
514 if All_Interp.Last = First_Interp + 1 then
516 -- The original interpretation is in fact not overloaded.
518 Set_Is_Overloaded (N, False);
526 function Covers (T1, T2 : Entity_Id) return Boolean is
528 pragma Assert (Present (T1) and Present (T2));
530 -- Simplest case: same types are compatible, and types that have the
531 -- same base type and are not generic actuals are compatible. Generic
532 -- actuals belong to their class but are not compatible with other
533 -- types of their class, and in particular with other generic actuals.
534 -- They are however compatible with their own subtypes, and itypes
535 -- with the same base are compatible as well. Similary, constrained
536 -- subtypes obtained from expressions of an unconstrained nominal type
537 -- are compatible with the base type (may lead to spurious ambiguities
538 -- in obscure cases ???)
540 -- Generic actuals require special treatment to avoid spurious ambi-
541 -- guities in an instance, when two formal types are instantiated with
542 -- the same actual, so that different subprograms end up with the same
543 -- signature in the instance.
548 elsif Base_Type (T1) = Base_Type (T2) then
549 if not Is_Generic_Actual_Type (T1) then
552 return (not Is_Generic_Actual_Type (T2)
553 or else Is_Itype (T1)
554 or else Is_Itype (T2)
555 or else Is_Constr_Subt_For_U_Nominal (T1)
556 or else Is_Constr_Subt_For_U_Nominal (T2)
557 or else Scope (T1) /= Scope (T2));
560 -- Literals are compatible with types in a given "class"
562 elsif (T2 = Universal_Integer and then Is_Integer_Type (T1))
563 or else (T2 = Universal_Real and then Is_Real_Type (T1))
564 or else (T2 = Universal_Fixed and then Is_Fixed_Point_Type (T1))
565 or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1))
566 or else (T2 = Any_String and then Is_String_Type (T1))
567 or else (T2 = Any_Character and then Is_Character_Type (T1))
568 or else (T2 = Any_Access and then Is_Access_Type (T1))
572 -- The context may be class wide.
574 elsif Is_Class_Wide_Type (T1)
575 and then Is_Ancestor (Root_Type (T1), T2)
579 elsif Is_Class_Wide_Type (T1)
580 and then Is_Class_Wide_Type (T2)
581 and then Base_Type (Etype (T1)) = Base_Type (Etype (T2))
585 -- In a dispatching call the actual may be class-wide
587 elsif Is_Class_Wide_Type (T2)
588 and then Base_Type (Root_Type (T2)) = Base_Type (T1)
592 -- Some contexts require a class of types rather than a specific type
594 elsif (T1 = Any_Integer and then Is_Integer_Type (T2))
595 or else (T1 = Any_Boolean and then Is_Boolean_Type (T2))
596 or else (T1 = Any_Real and then Is_Real_Type (T2))
597 or else (T1 = Any_Fixed and then Is_Fixed_Point_Type (T2))
598 or else (T1 = Any_Discrete and then Is_Discrete_Type (T2))
602 -- An aggregate is compatible with an array or record type
604 elsif T2 = Any_Composite
605 and then Ekind (T1) in E_Array_Type .. E_Record_Subtype
609 -- If the expected type is an anonymous access, the designated
610 -- type must cover that of the expression.
612 elsif Ekind (T1) = E_Anonymous_Access_Type
613 and then Is_Access_Type (T2)
614 and then Covers (Designated_Type (T1), Designated_Type (T2))
618 -- An Access_To_Subprogram is compatible with itself, or with an
619 -- anonymous type created for an attribute reference Access.
621 elsif (Ekind (Base_Type (T1)) = E_Access_Subprogram_Type
623 Ekind (Base_Type (T1)) = E_Access_Protected_Subprogram_Type)
624 and then Is_Access_Type (T2)
625 and then (not Comes_From_Source (T1)
626 or else not Comes_From_Source (T2))
627 and then (Is_Overloadable (Designated_Type (T2))
629 Ekind (Designated_Type (T2)) = E_Subprogram_Type)
631 Type_Conformant (Designated_Type (T1), Designated_Type (T2))
633 Mode_Conformant (Designated_Type (T1), Designated_Type (T2))
637 elsif Is_Record_Type (T1)
638 and then (Is_Remote_Call_Interface (T1)
639 or else Is_Remote_Types (T1))
640 and then Present (Corresponding_Remote_Type (T1))
642 return Covers (Corresponding_Remote_Type (T1), T2);
644 elsif Ekind (T2) = E_Access_Attribute_Type
645 and then (Ekind (Base_Type (T1)) = E_General_Access_Type
646 or else Ekind (Base_Type (T1)) = E_Access_Type)
647 and then Covers (Designated_Type (T1), Designated_Type (T2))
649 -- If the target type is a RACW type while the source is an access
650 -- attribute type, we are building a RACW that may be exported.
652 if Is_Remote_Access_To_Class_Wide_Type (Base_Type (T1)) then
653 Set_Has_RACW (Current_Sem_Unit);
658 elsif Ekind (T2) = E_Allocator_Type
659 and then Is_Access_Type (T1)
660 and then Covers (Designated_Type (T1), Designated_Type (T2))
664 -- A boolean operation on integer literals is compatible with a
667 elsif T2 = Any_Modular
668 and then Is_Modular_Integer_Type (T1)
672 -- The actual type may be the result of a previous error
674 elsif Base_Type (T2) = Any_Type then
677 -- A packed array type covers its corresponding non-packed type.
678 -- This is not legitimate Ada, but allows the omission of a number
679 -- of otherwise useless unchecked conversions, and since this can
680 -- only arise in (known correct) expanded code, no harm is done
682 elsif Is_Array_Type (T2)
683 and then Is_Packed (T2)
684 and then T1 = Packed_Array_Type (T2)
688 -- Similarly an array type covers its corresponding packed array type
690 elsif Is_Array_Type (T1)
691 and then Is_Packed (T1)
692 and then T2 = Packed_Array_Type (T1)
696 -- In an instance the proper view may not always be correct for
697 -- private types, but private and full view are compatible. This
698 -- removes spurious errors from nested instantiations that involve,
699 -- among other things, types derived from privated types.
702 and then Is_Private_Type (T1)
703 and then ((Present (Full_View (T1))
704 and then Covers (Full_View (T1), T2))
705 or else Base_Type (T1) = T2
706 or else Base_Type (T2) = T1)
710 -- In the expansion of inlined bodies, types are compatible if they
711 -- are structurally equivalent.
713 elsif In_Inlined_Body
714 and then (Underlying_Type (T1) = Underlying_Type (T2)
715 or else (Is_Access_Type (T1)
716 and then Is_Access_Type (T2)
718 Designated_Type (T1) = Designated_Type (T2))
719 or else (T1 = Any_Access
720 and then Is_Access_Type (Underlying_Type (T2))))
724 -- Otherwise it doesn't cover!
735 function Disambiguate
737 I1, I2 : Interp_Index;
744 Nam1, Nam2 : Entity_Id;
745 Predef_Subp : Entity_Id;
746 User_Subp : Entity_Id;
748 function Matches (Actual, Formal : Node_Id) return Boolean;
749 -- Look for exact type match in an instance, to remove spurious
750 -- ambiguities when two formal types have the same actual.
752 function Standard_Operator return Boolean;
754 function Remove_Conversions return Interp;
755 -- Last chance for pathological cases involving comparisons on
756 -- literals, and user overloadings of the same operator. Such
757 -- pathologies have been removed from the ACVC, but still appear in
758 -- two DEC tests, with the following notable quote from Ben Brosgol:
760 -- [Note: I disclaim all credit/responsibility/blame for coming up with
761 -- this example; Robert Dewar brought it to our attention, since it
762 -- is apparently found in the ACVC 1.5. I did not attempt to find
763 -- the reason in the Reference Manual that makes the example legal,
764 -- since I was too nauseated by it to want to pursue it further.]
766 -- Accordingly, this is not a fully recursive solution, but it handles
767 -- DEC tests c460vsa, c460vsb. It also handles ai00136a, which pushes
768 -- pathology in the other direction with calls whose multiple overloaded
769 -- actuals make them truly unresolvable.
775 function Matches (Actual, Formal : Node_Id) return Boolean is
776 T1 : constant Entity_Id := Etype (Actual);
777 T2 : constant Entity_Id := Etype (Formal);
782 (Is_Numeric_Type (T2)
784 (T1 = Universal_Real or else T1 = Universal_Integer));
787 ------------------------
788 -- Remove_Conversions --
789 ------------------------
791 function Remove_Conversions return Interp is
801 Get_First_Interp (N, I, It);
803 while Present (It.Typ) loop
805 if not Is_Overloadable (It.Nam) then
809 F1 := First_Formal (It.Nam);
815 if Nkind (N) = N_Function_Call
816 or else Nkind (N) = N_Procedure_Call_Statement
818 Act1 := First_Actual (N);
820 if Present (Act1) then
821 Act2 := Next_Actual (Act1);
826 elsif Nkind (N) in N_Unary_Op then
827 Act1 := Right_Opnd (N);
830 elsif Nkind (N) in N_Binary_Op then
831 Act1 := Left_Opnd (N);
832 Act2 := Right_Opnd (N);
838 if Nkind (Act1) in N_Op
839 and then Is_Overloaded (Act1)
840 and then (Nkind (Right_Opnd (Act1)) = N_Integer_Literal
841 or else Nkind (Right_Opnd (Act1)) = N_Real_Literal)
842 and then Has_Compatible_Type (Act1, Standard_Boolean)
843 and then Etype (F1) = Standard_Boolean
846 if It1 /= No_Interp then
850 and then Nkind (Act2) in N_Op
851 and then Is_Overloaded (Act2)
852 and then (Nkind (Right_Opnd (Act1)) = N_Integer_Literal
854 Nkind (Right_Opnd (Act1)) = N_Real_Literal)
855 and then Has_Compatible_Type (Act2, Standard_Boolean)
857 -- The preference rule on the first actual is not
858 -- sufficient to disambiguate.
869 Get_Next_Interp (I, It);
872 if Errors_Detected > 0 then
874 -- After some error, a formal may have Any_Type and yield
875 -- a spurious match. To avoid cascaded errors if possible,
876 -- check for such a formal in either candidate.
882 Formal := First_Formal (Nam1);
883 while Present (Formal) loop
884 if Etype (Formal) = Any_Type then
885 return Disambiguate.It2;
888 Next_Formal (Formal);
891 Formal := First_Formal (Nam2);
892 while Present (Formal) loop
893 if Etype (Formal) = Any_Type then
894 return Disambiguate.It1;
897 Next_Formal (Formal);
903 end Remove_Conversions;
905 -----------------------
906 -- Standard_Operator --
907 -----------------------
909 function Standard_Operator return Boolean is
913 if Nkind (N) in N_Op then
916 elsif Nkind (N) = N_Function_Call then
919 if Nkind (Nam) /= N_Expanded_Name then
922 return Entity (Prefix (Nam)) = Standard_Standard;
927 end Standard_Operator;
929 -- Start of processing for Disambiguate
932 -- Recover the two legal interpretations.
934 Get_First_Interp (N, I, It);
937 Get_Next_Interp (I, It);
944 Get_Next_Interp (I, It);
950 -- If the context is universal, the predefined operator is preferred.
951 -- This includes bounds in numeric type declarations, and expressions
952 -- in type conversions. If no interpretation yields a universal type,
953 -- then we must check whether the user-defined entity hides the prede-
956 if Chars (Nam1) in Any_Operator_Name
957 and then Standard_Operator
959 if Typ = Universal_Integer
960 or else Typ = Universal_Real
961 or else Typ = Any_Integer
962 or else Typ = Any_Discrete
963 or else Typ = Any_Real
964 or else Typ = Any_Type
966 -- Find an interpretation that yields the universal type, or else
967 -- a predefined operator that yields a predefined numeric type.
970 Candidate : Interp := No_Interp;
972 Get_First_Interp (N, I, It);
974 while Present (It.Typ) loop
975 if (Covers (Typ, It.Typ)
976 or else Typ = Any_Type)
978 (It.Typ = Universal_Integer
979 or else It.Typ = Universal_Real)
983 elsif Covers (Typ, It.Typ)
984 and then Scope (It.Typ) = Standard_Standard
985 and then Scope (It.Nam) = Standard_Standard
986 and then Is_Numeric_Type (It.Typ)
991 Get_Next_Interp (I, It);
994 if Candidate /= No_Interp then
999 elsif Chars (Nam1) /= Name_Op_Not
1000 and then (Typ = Standard_Boolean
1001 or else Typ = Any_Boolean)
1003 -- Equality or comparison operation. Choose predefined operator
1004 -- if arguments are universal. The node may be an operator, a
1005 -- name, or a function call, so unpack arguments accordingly.
1008 Arg1, Arg2 : Node_Id;
1011 if Nkind (N) in N_Op then
1012 Arg1 := Left_Opnd (N);
1013 Arg2 := Right_Opnd (N);
1015 elsif Is_Entity_Name (N)
1016 or else Nkind (N) = N_Operator_Symbol
1018 Arg1 := First_Entity (Entity (N));
1019 Arg2 := Next_Entity (Arg1);
1022 Arg1 := First_Actual (N);
1023 Arg2 := Next_Actual (Arg1);
1027 and then Present (Universal_Interpretation (Arg1))
1028 and then Universal_Interpretation (Arg2) =
1029 Universal_Interpretation (Arg1)
1031 Get_First_Interp (N, I, It);
1033 while Scope (It.Nam) /= Standard_Standard loop
1034 Get_Next_Interp (I, It);
1043 -- If no universal interpretation, check whether user-defined operator
1044 -- hides predefined one, as well as other special cases. If the node
1045 -- is a range, then one or both bounds are ambiguous. Each will have
1046 -- to be disambiguated w.r.t. the context type. The type of the range
1047 -- itself is imposed by the context, so we can return either legal
1050 if Ekind (Nam1) = E_Operator then
1051 Predef_Subp := Nam1;
1054 elsif Ekind (Nam2) = E_Operator then
1055 Predef_Subp := Nam2;
1058 elsif Nkind (N) = N_Range then
1061 -- If two user defined-subprograms are visible, it is a true ambiguity,
1062 -- unless one of them is an entry and the context is a conditional or
1063 -- timed entry call, or unless we are within an instance and this is
1064 -- results from two formals types with the same actual.
1067 if Nkind (N) = N_Procedure_Call_Statement
1068 and then Nkind (Parent (N)) = N_Entry_Call_Alternative
1069 and then N = Entry_Call_Statement (Parent (N))
1071 if Ekind (Nam2) = E_Entry then
1073 elsif Ekind (Nam1) = E_Entry then
1079 -- If the ambiguity occurs within an instance, it is due to several
1080 -- formal types with the same actual. Look for an exact match
1081 -- between the types of the formals of the overloadable entities,
1082 -- and the actuals in the call, to recover the unambiguous match
1083 -- in the original generic.
1085 elsif In_Instance then
1086 if (Nkind (N) = N_Function_Call
1087 or else Nkind (N) = N_Procedure_Call_Statement)
1094 Actual := First_Actual (N);
1095 Formal := First_Formal (Nam1);
1096 while Present (Actual) loop
1097 if Etype (Actual) /= Etype (Formal) then
1101 Next_Actual (Actual);
1102 Next_Formal (Formal);
1108 elsif Nkind (N) in N_Binary_Op then
1110 if Matches (Left_Opnd (N), First_Formal (Nam1))
1112 Matches (Right_Opnd (N), Next_Formal (First_Formal (Nam1)))
1119 elsif Nkind (N) in N_Unary_Op then
1121 if Etype (Right_Opnd (N)) = Etype (First_Formal (Nam1)) then
1128 return Remove_Conversions;
1131 return Remove_Conversions;
1135 -- an implicit concatenation operator on a string type cannot be
1136 -- disambiguated from the predefined concatenation. This can only
1137 -- happen with concatenation of string literals.
1139 if Chars (User_Subp) = Name_Op_Concat
1140 and then Ekind (User_Subp) = E_Operator
1141 and then Is_String_Type (Etype (First_Formal (User_Subp)))
1145 -- If the user-defined operator is in an open scope, or in the scope
1146 -- of the resulting type, or given by an expanded name that names its
1147 -- scope, it hides the predefined operator for the type. Exponentiation
1148 -- has to be special-cased because the implicit operator does not have
1149 -- a symmetric signature, and may not be hidden by the explicit one.
1151 elsif (Nkind (N) = N_Function_Call
1152 and then Nkind (Name (N)) = N_Expanded_Name
1153 and then (Chars (Predef_Subp) /= Name_Op_Expon
1154 or else Hides_Op (User_Subp, Predef_Subp))
1155 and then Scope (User_Subp) = Entity (Prefix (Name (N))))
1156 or else Hides_Op (User_Subp, Predef_Subp)
1158 if It1.Nam = User_Subp then
1164 -- Otherwise, the predefined operator has precedence, or if the
1165 -- user-defined operation is directly visible we have a true ambiguity.
1166 -- If this is a fixed-point multiplication and division in Ada83 mode,
1167 -- exclude the universal_fixed operator, which often causes ambiguities
1171 if (In_Open_Scopes (Scope (User_Subp))
1172 or else Is_Potentially_Use_Visible (User_Subp))
1173 and then not In_Instance
1175 if Is_Fixed_Point_Type (Typ)
1176 and then (Chars (Nam1) = Name_Op_Multiply
1177 or else Chars (Nam1) = Name_Op_Divide)
1180 if It2.Nam = Predef_Subp then
1190 elsif It1.Nam = Predef_Subp then
1200 ---------------------
1201 -- End_Interp_List --
1202 ---------------------
1204 procedure End_Interp_List is
1206 All_Interp.Table (All_Interp.Last) := No_Interp;
1207 All_Interp.Increment_Last;
1208 end End_Interp_List;
1210 -------------------------
1211 -- Entity_Matches_Spec --
1212 -------------------------
1214 function Entity_Matches_Spec (Old_S, New_S : Entity_Id) return Boolean is
1216 -- Simple case: same entity kinds, type conformance is required.
1217 -- A parameterless function can also rename a literal.
1219 if Ekind (Old_S) = Ekind (New_S)
1220 or else (Ekind (New_S) = E_Function
1221 and then Ekind (Old_S) = E_Enumeration_Literal)
1223 return Type_Conformant (New_S, Old_S);
1225 elsif Ekind (New_S) = E_Function
1226 and then Ekind (Old_S) = E_Operator
1228 return Operator_Matches_Spec (Old_S, New_S);
1230 elsif Ekind (New_S) = E_Procedure
1231 and then Is_Entry (Old_S)
1233 return Type_Conformant (New_S, Old_S);
1238 end Entity_Matches_Spec;
1240 ----------------------
1241 -- Find_Unique_Type --
1242 ----------------------
1244 function Find_Unique_Type (L : Node_Id; R : Node_Id) return Entity_Id is
1247 T : Entity_Id := Etype (L);
1248 TR : Entity_Id := Any_Type;
1251 if Is_Overloaded (R) then
1252 Get_First_Interp (R, I, It);
1254 while Present (It.Typ) loop
1255 if Covers (T, It.Typ) or else Covers (It.Typ, T) then
1257 -- If several interpretations are possible and L is universal,
1258 -- apply preference rule.
1260 if TR /= Any_Type then
1262 if (T = Universal_Integer or else T = Universal_Real)
1273 Get_Next_Interp (I, It);
1278 -- In the non-overloaded case, the Etype of R is already set
1285 -- If one of the operands is Universal_Fixed, the type of the
1286 -- other operand provides the context.
1288 if Etype (R) = Universal_Fixed then
1291 elsif T = Universal_Fixed then
1295 return Specific_Type (T, Etype (R));
1298 end Find_Unique_Type;
1300 ----------------------
1301 -- Get_First_Interp --
1302 ----------------------
1304 procedure Get_First_Interp
1306 I : out Interp_Index;
1309 Int_Ind : Interp_Index;
1313 -- If a selected component is overloaded because the selector has
1314 -- multiple interpretations, the node is a call to a protected
1315 -- operation or an indirect call. Retrieve the interpretation from
1316 -- the selector name. The selected component may be overloaded as well
1317 -- if the prefix is overloaded. That case is unchanged.
1319 if Nkind (N) = N_Selected_Component
1320 and then Is_Overloaded (Selector_Name (N))
1322 O_N := Selector_Name (N);
1327 for Index in 0 .. Interp_Map.Last loop
1328 if Interp_Map.Table (Index).Node = O_N then
1329 Int_Ind := Interp_Map.Table (Index).Index;
1330 It := All_Interp.Table (Int_Ind);
1336 -- Procedure should never be called if the node has no interpretations
1338 raise Program_Error;
1339 end Get_First_Interp;
1341 ----------------------
1342 -- Get_Next_Interp --
1343 ----------------------
1345 procedure Get_Next_Interp (I : in out Interp_Index; It : out Interp) is
1348 It := All_Interp.Table (I);
1349 end Get_Next_Interp;
1351 -------------------------
1352 -- Has_Compatible_Type --
1353 -------------------------
1355 function Has_Compatible_Type
1368 if Nkind (N) = N_Subtype_Indication
1369 or else not Is_Overloaded (N)
1371 return Covers (Typ, Etype (N))
1372 or else (not Is_Tagged_Type (Typ)
1373 and then Ekind (Typ) /= E_Anonymous_Access_Type
1374 and then Covers (Etype (N), Typ));
1377 Get_First_Interp (N, I, It);
1379 while Present (It.Typ) loop
1380 if Covers (Typ, It.Typ)
1381 or else (not Is_Tagged_Type (Typ)
1382 and then Ekind (Typ) /= E_Anonymous_Access_Type
1383 and then Covers (It.Typ, Typ))
1388 Get_Next_Interp (I, It);
1393 end Has_Compatible_Type;
1399 function Hides_Op (F : Entity_Id; Op : Entity_Id) return Boolean is
1400 Btyp : constant Entity_Id := Base_Type (Etype (First_Formal (F)));
1403 return Operator_Matches_Spec (Op, F)
1404 and then (In_Open_Scopes (Scope (F))
1405 or else Scope (F) = Scope (Btyp)
1406 or else (not In_Open_Scopes (Scope (Btyp))
1407 and then not In_Use (Btyp)
1408 and then not In_Use (Scope (Btyp))));
1411 ------------------------
1412 -- Init_Interp_Tables --
1413 ------------------------
1415 procedure Init_Interp_Tables is
1419 end Init_Interp_Tables;
1421 ---------------------
1422 -- Intersect_Types --
1423 ---------------------
1425 function Intersect_Types (L, R : Node_Id) return Entity_Id is
1426 Index : Interp_Index;
1430 function Check_Right_Argument (T : Entity_Id) return Entity_Id;
1431 -- Find interpretation of right arg that has type compatible with T
1433 --------------------------
1434 -- Check_Right_Argument --
1435 --------------------------
1437 function Check_Right_Argument (T : Entity_Id) return Entity_Id is
1438 Index : Interp_Index;
1443 if not Is_Overloaded (R) then
1444 return Specific_Type (T, Etype (R));
1447 Get_First_Interp (R, Index, It);
1450 T2 := Specific_Type (T, It.Typ);
1452 if T2 /= Any_Type then
1456 Get_Next_Interp (Index, It);
1457 exit when No (It.Typ);
1462 end Check_Right_Argument;
1464 -- Start processing for Intersect_Types
1467 if Etype (L) = Any_Type or else Etype (R) = Any_Type then
1471 if not Is_Overloaded (L) then
1472 Typ := Check_Right_Argument (Etype (L));
1476 Get_First_Interp (L, Index, It);
1478 while Present (It.Typ) loop
1479 Typ := Check_Right_Argument (It.Typ);
1480 exit when Typ /= Any_Type;
1481 Get_Next_Interp (Index, It);
1486 -- If Typ is Any_Type, it means no compatible pair of types was found
1488 if Typ = Any_Type then
1490 if Nkind (Parent (L)) in N_Op then
1491 Error_Msg_N ("incompatible types for operator", Parent (L));
1493 elsif Nkind (Parent (L)) = N_Range then
1494 Error_Msg_N ("incompatible types given in constraint", Parent (L));
1497 Error_Msg_N ("incompatible types", Parent (L));
1502 end Intersect_Types;
1508 function Is_Ancestor (T1, T2 : Entity_Id) return Boolean is
1512 if Base_Type (T1) = Base_Type (T2) then
1515 elsif Is_Private_Type (T1)
1516 and then Present (Full_View (T1))
1517 and then Base_Type (T2) = Base_Type (Full_View (T1))
1525 if Base_Type (T1) = Base_Type (Par)
1526 or else (Is_Private_Type (T1)
1527 and then Present (Full_View (T1))
1528 and then Base_Type (Par) = Base_Type (Full_View (T1)))
1532 elsif Is_Private_Type (Par)
1533 and then Present (Full_View (Par))
1534 and then Full_View (Par) = Base_Type (T1)
1538 elsif Etype (Par) /= Par then
1551 function Is_Subtype_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
1555 S := Ancestor_Subtype (T1);
1556 while Present (S) loop
1560 S := Ancestor_Subtype (S);
1571 procedure New_Interps (N : Node_Id) is
1573 Interp_Map.Increment_Last;
1574 All_Interp.Increment_Last;
1575 Interp_Map.Table (Interp_Map.Last) := (N, All_Interp.Last);
1576 All_Interp.Table (All_Interp.Last) := No_Interp;
1577 Set_Is_Overloaded (N, True);
1580 ---------------------------
1581 -- Operator_Matches_Spec --
1582 ---------------------------
1584 function Operator_Matches_Spec (Op, New_S : Entity_Id) return Boolean is
1585 Op_Name : constant Name_Id := Chars (Op);
1586 T : constant Entity_Id := Etype (New_S);
1594 -- To verify that a predefined operator matches a given signature,
1595 -- do a case analysis of the operator classes. Function can have one
1596 -- or two formals and must have the proper result type.
1598 New_F := First_Formal (New_S);
1599 Old_F := First_Formal (Op);
1602 while Present (New_F) and then Present (Old_F) loop
1604 Next_Formal (New_F);
1605 Next_Formal (Old_F);
1608 -- Definite mismatch if different number of parameters
1610 if Present (Old_F) or else Present (New_F) then
1616 T1 := Etype (First_Formal (New_S));
1618 if Op_Name = Name_Op_Subtract
1619 or else Op_Name = Name_Op_Add
1620 or else Op_Name = Name_Op_Abs
1622 return Base_Type (T1) = Base_Type (T)
1623 and then Is_Numeric_Type (T);
1625 elsif Op_Name = Name_Op_Not then
1626 return Base_Type (T1) = Base_Type (T)
1627 and then Valid_Boolean_Arg (Base_Type (T));
1636 T1 := Etype (First_Formal (New_S));
1637 T2 := Etype (Next_Formal (First_Formal (New_S)));
1639 if Op_Name = Name_Op_And or else Op_Name = Name_Op_Or
1640 or else Op_Name = Name_Op_Xor
1642 return Base_Type (T1) = Base_Type (T2)
1643 and then Base_Type (T1) = Base_Type (T)
1644 and then Valid_Boolean_Arg (Base_Type (T));
1646 elsif Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne then
1647 return Base_Type (T1) = Base_Type (T2)
1648 and then not Is_Limited_Type (T1)
1649 and then Is_Boolean_Type (T);
1651 elsif Op_Name = Name_Op_Lt or else Op_Name = Name_Op_Le
1652 or else Op_Name = Name_Op_Gt or else Op_Name = Name_Op_Ge
1654 return Base_Type (T1) = Base_Type (T2)
1655 and then Valid_Comparison_Arg (T1)
1656 and then Is_Boolean_Type (T);
1658 elsif Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
1659 return Base_Type (T1) = Base_Type (T2)
1660 and then Base_Type (T1) = Base_Type (T)
1661 and then Is_Numeric_Type (T);
1663 -- for division and multiplication, a user-defined function does
1664 -- not match the predefined universal_fixed operation, except in
1667 elsif Op_Name = Name_Op_Divide then
1668 return (Base_Type (T1) = Base_Type (T2)
1669 and then Base_Type (T1) = Base_Type (T)
1670 and then Is_Numeric_Type (T)
1671 and then (not Is_Fixed_Point_Type (T)
1674 -- Mixed_Mode operations on fixed-point types.
1676 or else (Base_Type (T1) = Base_Type (T)
1677 and then Base_Type (T2) = Base_Type (Standard_Integer)
1678 and then Is_Fixed_Point_Type (T))
1680 -- A user defined operator can also match (and hide) a mixed
1681 -- operation on universal literals.
1683 or else (Is_Integer_Type (T2)
1684 and then Is_Floating_Point_Type (T1)
1685 and then Base_Type (T1) = Base_Type (T));
1687 elsif Op_Name = Name_Op_Multiply then
1688 return (Base_Type (T1) = Base_Type (T2)
1689 and then Base_Type (T1) = Base_Type (T)
1690 and then Is_Numeric_Type (T)
1691 and then (not Is_Fixed_Point_Type (T)
1694 -- Mixed_Mode operations on fixed-point types.
1696 or else (Base_Type (T1) = Base_Type (T)
1697 and then Base_Type (T2) = Base_Type (Standard_Integer)
1698 and then Is_Fixed_Point_Type (T))
1700 or else (Base_Type (T2) = Base_Type (T)
1701 and then Base_Type (T1) = Base_Type (Standard_Integer)
1702 and then Is_Fixed_Point_Type (T))
1704 or else (Is_Integer_Type (T2)
1705 and then Is_Floating_Point_Type (T1)
1706 and then Base_Type (T1) = Base_Type (T))
1708 or else (Is_Integer_Type (T1)
1709 and then Is_Floating_Point_Type (T2)
1710 and then Base_Type (T2) = Base_Type (T));
1712 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
1713 return Base_Type (T1) = Base_Type (T2)
1714 and then Base_Type (T1) = Base_Type (T)
1715 and then Is_Integer_Type (T);
1717 elsif Op_Name = Name_Op_Expon then
1718 return Base_Type (T1) = Base_Type (T)
1719 and then Is_Numeric_Type (T)
1720 and then Base_Type (T2) = Base_Type (Standard_Integer);
1722 elsif Op_Name = Name_Op_Concat then
1723 return Is_Array_Type (T)
1724 and then (Base_Type (T) = Base_Type (Etype (Op)))
1725 and then (Base_Type (T1) = Base_Type (T)
1727 Base_Type (T1) = Base_Type (Component_Type (T)))
1728 and then (Base_Type (T2) = Base_Type (T)
1730 Base_Type (T2) = Base_Type (Component_Type (T)));
1736 end Operator_Matches_Spec;
1742 procedure Remove_Interp (I : in out Interp_Index) is
1746 -- Find end of Interp list and copy downward to erase the discarded one
1750 while Present (All_Interp.Table (II).Typ) loop
1754 for J in I + 1 .. II loop
1755 All_Interp.Table (J - 1) := All_Interp.Table (J);
1758 -- Back up interp. index to insure that iterator will pick up next
1759 -- available interpretation.
1768 procedure Save_Interps (Old_N : Node_Id; New_N : Node_Id) is
1770 if Is_Overloaded (Old_N) then
1771 for Index in 0 .. Interp_Map.Last loop
1772 if Interp_Map.Table (Index).Node = Old_N then
1773 Interp_Map.Table (Index).Node := New_N;
1784 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
1785 B1 : constant Entity_Id := Base_Type (T1);
1786 B2 : constant Entity_Id := Base_Type (T2);
1788 function Is_Remote_Access (T : Entity_Id) return Boolean;
1789 -- Check whether T is the equivalent type of a remote access type.
1790 -- If distribution is enabled, T is a legal context for Null.
1792 ----------------------
1793 -- Is_Remote_Access --
1794 ----------------------
1796 function Is_Remote_Access (T : Entity_Id) return Boolean is
1798 return Is_Record_Type (T)
1799 and then (Is_Remote_Call_Interface (T)
1800 or else Is_Remote_Types (T))
1801 and then Present (Corresponding_Remote_Type (T))
1802 and then Is_Access_Type (Corresponding_Remote_Type (T));
1803 end Is_Remote_Access;
1805 -- Start of processing for Specific_Type
1808 if (T1 = Any_Type or else T2 = Any_Type) then
1815 elsif (T1 = Universal_Integer and then Is_Integer_Type (T2))
1816 or else (T1 = Universal_Real and then Is_Real_Type (T2))
1817 or else (T1 = Any_Fixed and then Is_Fixed_Point_Type (T2))
1821 elsif (T2 = Universal_Integer and then Is_Integer_Type (T1))
1822 or else (T2 = Universal_Real and then Is_Real_Type (T1))
1823 or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1))
1827 elsif (T2 = Any_String and then Is_String_Type (T1)) then
1830 elsif (T1 = Any_String and then Is_String_Type (T2)) then
1833 elsif (T2 = Any_Character and then Is_Character_Type (T1)) then
1836 elsif (T1 = Any_Character and then Is_Character_Type (T2)) then
1839 elsif (T1 = Any_Access
1840 and then (Is_Access_Type (T2) or else Is_Remote_Access (T2)))
1844 elsif (T2 = Any_Access
1845 and then (Is_Access_Type (T1) or else Is_Remote_Access (T1)))
1849 elsif (T2 = Any_Composite
1850 and then Ekind (T1) in E_Array_Type .. E_Record_Subtype)
1854 elsif (T1 = Any_Composite
1855 and then Ekind (T2) in E_Array_Type .. E_Record_Subtype)
1859 elsif (T1 = Any_Modular and then Is_Modular_Integer_Type (T2)) then
1862 elsif (T2 = Any_Modular and then Is_Modular_Integer_Type (T1)) then
1865 -- Special cases for equality operators (all other predefined
1866 -- operators can never apply to tagged types)
1868 elsif Is_Class_Wide_Type (T1)
1869 and then Is_Ancestor (Root_Type (T1), T2)
1873 elsif Is_Class_Wide_Type (T2)
1874 and then Is_Ancestor (Root_Type (T2), T1)
1878 elsif (Ekind (B1) = E_Access_Subprogram_Type
1880 Ekind (B1) = E_Access_Protected_Subprogram_Type)
1881 and then Ekind (Designated_Type (B1)) /= E_Subprogram_Type
1882 and then Is_Access_Type (T2)
1886 elsif (Ekind (B2) = E_Access_Subprogram_Type
1888 Ekind (B2) = E_Access_Protected_Subprogram_Type)
1889 and then Ekind (Designated_Type (B2)) /= E_Subprogram_Type
1890 and then Is_Access_Type (T1)
1894 elsif (Ekind (T1) = E_Allocator_Type
1895 or else Ekind (T1) = E_Access_Attribute_Type
1896 or else Ekind (T1) = E_Anonymous_Access_Type)
1897 and then Is_Access_Type (T2)
1901 elsif (Ekind (T2) = E_Allocator_Type
1902 or else Ekind (T2) = E_Access_Attribute_Type
1903 or else Ekind (T2) = E_Anonymous_Access_Type)
1904 and then Is_Access_Type (T1)
1908 -- If none of the above cases applies, types are not compatible.
1915 ------------------------------
1916 -- Universal_Interpretation --
1917 ------------------------------
1919 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
1920 Index : Interp_Index;
1924 -- The argument may be a formal parameter of an operator or subprogram
1925 -- with multiple interpretations, or else an expression for an actual.
1927 if Nkind (Opnd) = N_Defining_Identifier
1928 or else not Is_Overloaded (Opnd)
1930 if Etype (Opnd) = Universal_Integer
1931 or else Etype (Opnd) = Universal_Real
1933 return Etype (Opnd);
1939 Get_First_Interp (Opnd, Index, It);
1941 while Present (It.Typ) loop
1943 if It.Typ = Universal_Integer
1944 or else It.Typ = Universal_Real
1949 Get_Next_Interp (Index, It);
1954 end Universal_Interpretation;
1956 -----------------------
1957 -- Valid_Boolean_Arg --
1958 -----------------------
1960 -- In addition to booleans and arrays of booleans, we must include
1961 -- aggregates as valid boolean arguments, because in the first pass
1962 -- of resolution their components are not examined. If it turns out not
1963 -- to be an aggregate of booleans, this will be diagnosed in Resolve.
1964 -- Any_Composite must be checked for prior to the array type checks
1965 -- because Any_Composite does not have any associated indexes.
1967 function Valid_Boolean_Arg (T : Entity_Id) return Boolean is
1969 return Is_Boolean_Type (T)
1970 or else T = Any_Composite
1971 or else (Is_Array_Type (T)
1972 and then T /= Any_String
1973 and then Number_Dimensions (T) = 1
1974 and then Is_Boolean_Type (Component_Type (T))
1975 and then (not Is_Private_Composite (T)
1976 or else In_Instance)
1977 and then (not Is_Limited_Composite (T)
1978 or else In_Instance))
1979 or else Is_Modular_Integer_Type (T)
1980 or else T = Universal_Integer;
1981 end Valid_Boolean_Arg;
1983 --------------------------
1984 -- Valid_Comparison_Arg --
1985 --------------------------
1987 function Valid_Comparison_Arg (T : Entity_Id) return Boolean is
1989 return Is_Discrete_Type (T)
1990 or else Is_Real_Type (T)
1991 or else (Is_Array_Type (T) and then Number_Dimensions (T) = 1
1992 and then Is_Discrete_Type (Component_Type (T))
1993 and then (not Is_Private_Composite (T)
1994 or else In_Instance)
1995 and then (not Is_Limited_Composite (T)
1996 or else In_Instance))
1997 or else Is_String_Type (T);
1998 end Valid_Comparison_Arg;
2000 ---------------------
2001 -- Write_Overloads --
2002 ---------------------
2004 procedure Write_Overloads (N : Node_Id) is
2010 if not Is_Overloaded (N) then
2011 Write_Str ("Non-overloaded entity ");
2013 Write_Entity_Info (Entity (N), " ");
2016 Get_First_Interp (N, I, It);
2017 Write_Str ("Overloaded entity ");
2021 while Present (Nam) loop
2022 Write_Entity_Info (Nam, " ");
2023 Write_Str ("=================");
2025 Get_Next_Interp (I, It);
2029 end Write_Overloads;