1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Nlists; use Nlists;
32 with Errout; use Errout;
34 with Namet; use Namet;
36 with Output; use Output;
38 with Sem_Ch6; use Sem_Ch6;
39 with Sem_Ch8; use Sem_Ch8;
40 with Sem_Ch12; use Sem_Ch12;
41 with Sem_Disp; use Sem_Disp;
42 with Sem_Util; use Sem_Util;
43 with Stand; use Stand;
44 with Sinfo; use Sinfo;
45 with Snames; use Snames;
47 with Uintp; use Uintp;
49 package body Sem_Type is
55 -- The following data structures establish a mapping between nodes and
56 -- their interpretations. An overloaded node has an entry in Interp_Map,
57 -- which in turn contains a pointer into the All_Interp array. The
58 -- interpretations of a given node are contiguous in All_Interp. Each
59 -- set of interpretations is terminated with the marker No_Interp.
60 -- In order to speed up the retrieval of the interpretations of an
61 -- overloaded node, the Interp_Map table is accessed by means of a simple
62 -- hashing scheme, and the entries in Interp_Map are chained. The heads
63 -- of clash lists are stored in array Headers.
65 -- Headers Interp_Map All_Interp
67 -- _ +-----+ +--------+
68 -- |_| |_____| --->|interp1 |
69 -- |_|---------->|node | | |interp2 |
70 -- |_| |index|---------| |nointerp|
75 -- This scheme does not currently reclaim interpretations. In principle,
76 -- after a unit is compiled, all overloadings have been resolved, and the
77 -- candidate interpretations should be deleted. This should be easier
78 -- now than with the previous scheme???
80 package All_Interp is new Table.Table (
81 Table_Component_Type => Interp,
82 Table_Index_Type => Int,
84 Table_Initial => Alloc.All_Interp_Initial,
85 Table_Increment => Alloc.All_Interp_Increment,
86 Table_Name => "All_Interp");
88 type Interp_Ref is record
94 Header_Size : constant Int := 2 ** 12;
95 No_Entry : constant Int := -1;
96 Headers : array (0 .. Header_Size) of Int := (others => No_Entry);
98 package Interp_Map is new Table.Table (
99 Table_Component_Type => Interp_Ref,
100 Table_Index_Type => Int,
101 Table_Low_Bound => 0,
102 Table_Initial => Alloc.Interp_Map_Initial,
103 Table_Increment => Alloc.Interp_Map_Increment,
104 Table_Name => "Interp_Map");
106 function Hash (N : Node_Id) return Int;
107 -- A trivial hashing function for nodes, used to insert an overloaded
108 -- node into the Interp_Map table.
110 -------------------------------------
111 -- Handling of Overload Resolution --
112 -------------------------------------
114 -- Overload resolution uses two passes over the syntax tree of a complete
115 -- context. In the first, bottom-up pass, the types of actuals in calls
116 -- are used to resolve possibly overloaded subprogram and operator names.
117 -- In the second top-down pass, the type of the context (for example the
118 -- condition in a while statement) is used to resolve a possibly ambiguous
119 -- call, and the unique subprogram name in turn imposes a specific context
120 -- on each of its actuals.
122 -- Most expressions are in fact unambiguous, and the bottom-up pass is
123 -- sufficient to resolve most everything. To simplify the common case,
124 -- names and expressions carry a flag Is_Overloaded to indicate whether
125 -- they have more than one interpretation. If the flag is off, then each
126 -- name has already a unique meaning and type, and the bottom-up pass is
127 -- sufficient (and much simpler).
129 --------------------------
130 -- Operator Overloading --
131 --------------------------
133 -- The visibility of operators is handled differently from that of
134 -- other entities. We do not introduce explicit versions of primitive
135 -- operators for each type definition. As a result, there is only one
136 -- entity corresponding to predefined addition on all numeric types, etc.
137 -- The back-end resolves predefined operators according to their type.
138 -- The visibility of primitive operations then reduces to the visibility
139 -- of the resulting type: (a + b) is a legal interpretation of some
140 -- primitive operator + if the type of the result (which must also be
141 -- the type of a and b) is directly visible (i.e. either immediately
142 -- visible or use-visible.)
144 -- User-defined operators are treated like other functions, but the
145 -- visibility of these user-defined operations must be special-cased
146 -- to determine whether they hide or are hidden by predefined operators.
147 -- The form P."+" (x, y) requires additional handling.
149 -- Concatenation is treated more conventionally: for every one-dimensional
150 -- array type we introduce a explicit concatenation operator. This is
151 -- necessary to handle the case of (element & element => array) which
152 -- cannot be handled conveniently if there is no explicit instance of
153 -- resulting type of the operation.
155 -----------------------
156 -- Local Subprograms --
157 -----------------------
159 procedure All_Overloads;
160 pragma Warnings (Off, All_Overloads);
161 -- Debugging procedure: list full contents of Overloads table
163 function Binary_Op_Interp_Has_Abstract_Op
165 E : Entity_Id) return Entity_Id;
166 -- Given the node and entity of a binary operator, determine whether the
167 -- actuals of E contain an abstract interpretation with regards to the
168 -- types of their corresponding formals. Return the abstract operation or
171 function Function_Interp_Has_Abstract_Op
173 E : Entity_Id) return Entity_Id;
174 -- Given the node and entity of a function call, determine whether the
175 -- actuals of E contain an abstract interpretation with regards to the
176 -- types of their corresponding formals. Return the abstract operation or
179 function Has_Abstract_Op
181 Typ : Entity_Id) return Entity_Id;
182 -- Subsidiary routine to Binary_Op_Interp_Has_Abstract_Op and Function_
183 -- Interp_Has_Abstract_Op. Determine whether an overloaded node has an
184 -- abstract interpretation which yields type Typ.
186 procedure New_Interps (N : Node_Id);
187 -- Initialize collection of interpretations for the given node, which is
188 -- either an overloaded entity, or an operation whose arguments have
189 -- multiple interpretations. Interpretations can be added to only one
192 function Specific_Type (Typ_1, Typ_2 : Entity_Id) return Entity_Id;
193 -- If Typ_1 and Typ_2 are compatible, return the one that is not universal
194 -- or is not a "class" type (any_character, etc).
200 procedure Add_One_Interp
204 Opnd_Type : Entity_Id := Empty)
206 Vis_Type : Entity_Id;
208 procedure Add_Entry (Name : Entity_Id; Typ : Entity_Id);
209 -- Add one interpretation to an overloaded node. Add a new entry if
210 -- not hidden by previous one, and remove previous one if hidden by
213 function Is_Universal_Operation (Op : Entity_Id) return Boolean;
214 -- True if the entity is a predefined operator and the operands have
215 -- a universal Interpretation.
221 procedure Add_Entry (Name : Entity_Id; Typ : Entity_Id) is
222 Abstr_Op : Entity_Id := Empty;
226 -- Start of processing for Add_Entry
229 -- Find out whether the new entry references interpretations that
230 -- are abstract or disabled by abstract operators.
232 if Ada_Version >= Ada_05 then
233 if Nkind (N) in N_Binary_Op then
234 Abstr_Op := Binary_Op_Interp_Has_Abstract_Op (N, Name);
235 elsif Nkind (N) = N_Function_Call then
236 Abstr_Op := Function_Interp_Has_Abstract_Op (N, Name);
240 Get_First_Interp (N, I, It);
241 while Present (It.Nam) loop
243 -- A user-defined subprogram hides another declared at an outer
244 -- level, or one that is use-visible. So return if previous
245 -- definition hides new one (which is either in an outer
246 -- scope, or use-visible). Note that for functions use-visible
247 -- is the same as potentially use-visible. If new one hides
248 -- previous one, replace entry in table of interpretations.
249 -- If this is a universal operation, retain the operator in case
250 -- preference rule applies.
252 if (((Ekind (Name) = E_Function or else Ekind (Name) = E_Procedure)
253 and then Ekind (Name) = Ekind (It.Nam))
254 or else (Ekind (Name) = E_Operator
255 and then Ekind (It.Nam) = E_Function))
257 and then Is_Immediately_Visible (It.Nam)
258 and then Type_Conformant (Name, It.Nam)
259 and then Base_Type (It.Typ) = Base_Type (T)
261 if Is_Universal_Operation (Name) then
264 -- If node is an operator symbol, we have no actuals with
265 -- which to check hiding, and this is done in full in the
266 -- caller (Analyze_Subprogram_Renaming) so we include the
267 -- predefined operator in any case.
269 elsif Nkind (N) = N_Operator_Symbol
270 or else (Nkind (N) = N_Expanded_Name
272 Nkind (Selector_Name (N)) = N_Operator_Symbol)
276 elsif not In_Open_Scopes (Scope (Name))
277 or else Scope_Depth (Scope (Name)) <=
278 Scope_Depth (Scope (It.Nam))
280 -- If ambiguity within instance, and entity is not an
281 -- implicit operation, save for later disambiguation.
283 if Scope (Name) = Scope (It.Nam)
284 and then not Is_Inherited_Operation (Name)
293 All_Interp.Table (I).Nam := Name;
297 -- Avoid making duplicate entries in overloads
300 and then Base_Type (It.Typ) = Base_Type (T)
304 -- Otherwise keep going
307 Get_Next_Interp (I, It);
312 All_Interp.Table (All_Interp.Last) := (Name, Typ, Abstr_Op);
313 All_Interp.Increment_Last;
314 All_Interp.Table (All_Interp.Last) := No_Interp;
317 ----------------------------
318 -- Is_Universal_Operation --
319 ----------------------------
321 function Is_Universal_Operation (Op : Entity_Id) return Boolean is
325 if Ekind (Op) /= E_Operator then
328 elsif Nkind (N) in N_Binary_Op then
329 return Present (Universal_Interpretation (Left_Opnd (N)))
330 and then Present (Universal_Interpretation (Right_Opnd (N)));
332 elsif Nkind (N) in N_Unary_Op then
333 return Present (Universal_Interpretation (Right_Opnd (N)));
335 elsif Nkind (N) = N_Function_Call then
336 Arg := First_Actual (N);
337 while Present (Arg) loop
338 if No (Universal_Interpretation (Arg)) then
350 end Is_Universal_Operation;
352 -- Start of processing for Add_One_Interp
355 -- If the interpretation is a predefined operator, verify that the
356 -- result type is visible, or that the entity has already been
357 -- resolved (case of an instantiation node that refers to a predefined
358 -- operation, or an internally generated operator node, or an operator
359 -- given as an expanded name). If the operator is a comparison or
360 -- equality, it is the type of the operand that matters to determine
361 -- whether the operator is visible. In an instance, the check is not
362 -- performed, given that the operator was visible in the generic.
364 if Ekind (E) = E_Operator then
366 if Present (Opnd_Type) then
367 Vis_Type := Opnd_Type;
369 Vis_Type := Base_Type (T);
372 if In_Open_Scopes (Scope (Vis_Type))
373 or else Is_Potentially_Use_Visible (Vis_Type)
374 or else In_Use (Vis_Type)
375 or else (In_Use (Scope (Vis_Type))
376 and then not Is_Hidden (Vis_Type))
377 or else Nkind (N) = N_Expanded_Name
378 or else (Nkind (N) in N_Op and then E = Entity (N))
380 or else Ekind (Vis_Type) = E_Anonymous_Access_Type
384 -- If the node is given in functional notation and the prefix
385 -- is an expanded name, then the operator is visible if the
386 -- prefix is the scope of the result type as well. If the
387 -- operator is (implicitly) defined in an extension of system,
388 -- it is know to be valid (see Defined_In_Scope, sem_ch4.adb).
390 elsif Nkind (N) = N_Function_Call
391 and then Nkind (Name (N)) = N_Expanded_Name
392 and then (Entity (Prefix (Name (N))) = Scope (Base_Type (T))
393 or else Entity (Prefix (Name (N))) = Scope (Vis_Type)
394 or else Scope (Vis_Type) = System_Aux_Id)
398 -- Save type for subsequent error message, in case no other
399 -- interpretation is found.
402 Candidate_Type := Vis_Type;
406 -- In an instance, an abstract non-dispatching operation cannot
407 -- be a candidate interpretation, because it could not have been
408 -- one in the generic (it may be a spurious overloading in the
412 and then Is_Overloadable (E)
413 and then Is_Abstract_Subprogram (E)
414 and then not Is_Dispatching_Operation (E)
418 -- An inherited interface operation that is implemented by some
419 -- derived type does not participate in overload resolution, only
420 -- the implementation operation does.
423 and then Is_Subprogram (E)
424 and then Present (Abstract_Interface_Alias (E))
426 -- Ada 2005 (AI-251): If this primitive operation corresponds with
427 -- an immediate ancestor interface there is no need to add it to the
428 -- list of interpretations. The corresponding aliased primitive is
429 -- also in this list of primitive operations and will be used instead
430 -- because otherwise we have a dummy ambiguity between the two
431 -- subprograms which are in fact the same.
434 (Find_Dispatching_Type (Abstract_Interface_Alias (E)),
435 Find_Dispatching_Type (E))
437 Add_One_Interp (N, Abstract_Interface_Alias (E), T);
443 -- If this is the first interpretation of N, N has type Any_Type.
444 -- In that case place the new type on the node. If one interpretation
445 -- already exists, indicate that the node is overloaded, and store
446 -- both the previous and the new interpretation in All_Interp. If
447 -- this is a later interpretation, just add it to the set.
449 if Etype (N) = Any_Type then
454 -- Record both the operator or subprogram name, and its type
456 if Nkind (N) in N_Op or else Is_Entity_Name (N) then
463 -- Either there is no current interpretation in the table for any
464 -- node or the interpretation that is present is for a different
465 -- node. In both cases add a new interpretation to the table.
467 elsif Interp_Map.Last < 0
469 (Interp_Map.Table (Interp_Map.Last).Node /= N
470 and then not Is_Overloaded (N))
474 if (Nkind (N) in N_Op or else Is_Entity_Name (N))
475 and then Present (Entity (N))
477 Add_Entry (Entity (N), Etype (N));
479 elsif (Nkind (N) = N_Function_Call
480 or else Nkind (N) = N_Procedure_Call_Statement)
481 and then (Nkind (Name (N)) = N_Operator_Symbol
482 or else Is_Entity_Name (Name (N)))
484 Add_Entry (Entity (Name (N)), Etype (N));
486 -- If this is an indirect call there will be no name associated
487 -- with the previous entry. To make diagnostics clearer, save
488 -- Subprogram_Type of first interpretation, so that the error will
489 -- point to the anonymous access to subprogram, not to the result
490 -- type of the call itself.
492 elsif (Nkind (N)) = N_Function_Call
493 and then Nkind (Name (N)) = N_Explicit_Dereference
494 and then Is_Overloaded (Name (N))
500 pragma Warnings (Off, Itn);
503 Get_First_Interp (Name (N), Itn, It);
504 Add_Entry (It.Nam, Etype (N));
508 -- Overloaded prefix in indexed or selected component, or call
509 -- whose name is an expression or another call.
511 Add_Entry (Etype (N), Etype (N));
525 procedure All_Overloads is
527 for J in All_Interp.First .. All_Interp.Last loop
529 if Present (All_Interp.Table (J).Nam) then
530 Write_Entity_Info (All_Interp.Table (J). Nam, " ");
532 Write_Str ("No Interp");
536 Write_Str ("=================");
541 --------------------------------------
542 -- Binary_Op_Interp_Has_Abstract_Op --
543 --------------------------------------
545 function Binary_Op_Interp_Has_Abstract_Op
547 E : Entity_Id) return Entity_Id
549 Abstr_Op : Entity_Id;
550 E_Left : constant Node_Id := First_Formal (E);
551 E_Right : constant Node_Id := Next_Formal (E_Left);
554 Abstr_Op := Has_Abstract_Op (Left_Opnd (N), Etype (E_Left));
555 if Present (Abstr_Op) then
559 return Has_Abstract_Op (Right_Opnd (N), Etype (E_Right));
560 end Binary_Op_Interp_Has_Abstract_Op;
562 ---------------------
563 -- Collect_Interps --
564 ---------------------
566 procedure Collect_Interps (N : Node_Id) is
567 Ent : constant Entity_Id := Entity (N);
569 First_Interp : Interp_Index;
574 -- Unconditionally add the entity that was initially matched
576 First_Interp := All_Interp.Last;
577 Add_One_Interp (N, Ent, Etype (N));
579 -- For expanded name, pick up all additional entities from the
580 -- same scope, since these are obviously also visible. Note that
581 -- these are not necessarily contiguous on the homonym chain.
583 if Nkind (N) = N_Expanded_Name then
585 while Present (H) loop
586 if Scope (H) = Scope (Entity (N)) then
587 Add_One_Interp (N, H, Etype (H));
593 -- Case of direct name
596 -- First, search the homonym chain for directly visible entities
598 H := Current_Entity (Ent);
599 while Present (H) loop
600 exit when (not Is_Overloadable (H))
601 and then Is_Immediately_Visible (H);
603 if Is_Immediately_Visible (H)
606 -- Only add interpretation if not hidden by an inner
607 -- immediately visible one.
609 for J in First_Interp .. All_Interp.Last - 1 loop
611 -- Current homograph is not hidden. Add to overloads
613 if not Is_Immediately_Visible (All_Interp.Table (J).Nam) then
616 -- Homograph is hidden, unless it is a predefined operator
618 elsif Type_Conformant (H, All_Interp.Table (J).Nam) then
620 -- A homograph in the same scope can occur within an
621 -- instantiation, the resulting ambiguity has to be
624 if Scope (H) = Scope (Ent)
626 and then not Is_Inherited_Operation (H)
628 All_Interp.Table (All_Interp.Last) :=
629 (H, Etype (H), Empty);
630 All_Interp.Increment_Last;
631 All_Interp.Table (All_Interp.Last) := No_Interp;
634 elsif Scope (H) /= Standard_Standard then
640 -- On exit, we know that current homograph is not hidden
642 Add_One_Interp (N, H, Etype (H));
645 Write_Str ("Add overloaded interpretation ");
655 -- Scan list of homographs for use-visible entities only
657 H := Current_Entity (Ent);
659 while Present (H) loop
660 if Is_Potentially_Use_Visible (H)
662 and then Is_Overloadable (H)
664 for J in First_Interp .. All_Interp.Last - 1 loop
666 if not Is_Immediately_Visible (All_Interp.Table (J).Nam) then
669 elsif Type_Conformant (H, All_Interp.Table (J).Nam) then
670 goto Next_Use_Homograph;
674 Add_One_Interp (N, H, Etype (H));
677 <<Next_Use_Homograph>>
682 if All_Interp.Last = First_Interp + 1 then
684 -- The original interpretation is in fact not overloaded
686 Set_Is_Overloaded (N, False);
694 function Covers (T1, T2 : Entity_Id) return Boolean is
699 function Full_View_Covers (Typ1, Typ2 : Entity_Id) return Boolean;
700 -- In an instance the proper view may not always be correct for
701 -- private types, but private and full view are compatible. This
702 -- removes spurious errors from nested instantiations that involve,
703 -- among other things, types derived from private types.
705 ----------------------
706 -- Full_View_Covers --
707 ----------------------
709 function Full_View_Covers (Typ1, Typ2 : Entity_Id) return Boolean is
712 Is_Private_Type (Typ1)
714 ((Present (Full_View (Typ1))
715 and then Covers (Full_View (Typ1), Typ2))
716 or else Base_Type (Typ1) = Typ2
717 or else Base_Type (Typ2) = Typ1);
718 end Full_View_Covers;
720 -- Start of processing for Covers
723 -- If either operand missing, then this is an error, but ignore it (and
724 -- pretend we have a cover) if errors already detected, since this may
725 -- simply mean we have malformed trees.
727 if No (T1) or else No (T2) then
728 if Total_Errors_Detected /= 0 then
735 BT1 := Base_Type (T1);
736 BT2 := Base_Type (T2);
739 -- Simplest case: same types are compatible, and types that have the
740 -- same base type and are not generic actuals are compatible. Generic
741 -- actuals belong to their class but are not compatible with other
742 -- types of their class, and in particular with other generic actuals.
743 -- They are however compatible with their own subtypes, and itypes
744 -- with the same base are compatible as well. Similarly, constrained
745 -- subtypes obtained from expressions of an unconstrained nominal type
746 -- are compatible with the base type (may lead to spurious ambiguities
747 -- in obscure cases ???)
749 -- Generic actuals require special treatment to avoid spurious ambi-
750 -- guities in an instance, when two formal types are instantiated with
751 -- the same actual, so that different subprograms end up with the same
752 -- signature in the instance.
761 if not Is_Generic_Actual_Type (T1) then
764 return (not Is_Generic_Actual_Type (T2)
765 or else Is_Itype (T1)
766 or else Is_Itype (T2)
767 or else Is_Constr_Subt_For_U_Nominal (T1)
768 or else Is_Constr_Subt_For_U_Nominal (T2)
769 or else Scope (T1) /= Scope (T2));
772 -- Literals are compatible with types in a given "class"
774 elsif (T2 = Universal_Integer and then Is_Integer_Type (T1))
775 or else (T2 = Universal_Real and then Is_Real_Type (T1))
776 or else (T2 = Universal_Fixed and then Is_Fixed_Point_Type (T1))
777 or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1))
778 or else (T2 = Any_String and then Is_String_Type (T1))
779 or else (T2 = Any_Character and then Is_Character_Type (T1))
780 or else (T2 = Any_Access and then Is_Access_Type (T1))
784 -- The context may be class wide
786 elsif Is_Class_Wide_Type (T1)
787 and then Is_Ancestor (Root_Type (T1), T2)
791 elsif Is_Class_Wide_Type (T1)
792 and then Is_Class_Wide_Type (T2)
793 and then Base_Type (Etype (T1)) = Base_Type (Etype (T2))
797 -- Ada 2005 (AI-345): A class-wide abstract interface type T1 covers a
798 -- task_type or protected_type implementing T1
800 elsif Ada_Version >= Ada_05
801 and then Is_Class_Wide_Type (T1)
802 and then Is_Interface (Etype (T1))
803 and then Is_Concurrent_Type (T2)
804 and then Interface_Present_In_Ancestor
805 (Typ => Base_Type (T2),
810 -- Ada 2005 (AI-251): A class-wide abstract interface type T1 covers an
811 -- object T2 implementing T1
813 elsif Ada_Version >= Ada_05
814 and then Is_Class_Wide_Type (T1)
815 and then Is_Interface (Etype (T1))
816 and then Is_Tagged_Type (T2)
818 if Interface_Present_In_Ancestor (Typ => T2,
829 if Is_Concurrent_Type (BT2) then
830 E := Corresponding_Record_Type (BT2);
835 -- Ada 2005 (AI-251): A class-wide abstract interface type T1
836 -- covers an object T2 that implements a direct derivation of T1.
837 -- Note: test for presence of E is defense against previous error.
840 and then Present (Abstract_Interfaces (E))
842 Elmt := First_Elmt (Abstract_Interfaces (E));
843 while Present (Elmt) loop
844 if Is_Ancestor (Etype (T1), Node (Elmt)) then
852 -- We should also check the case in which T1 is an ancestor of
853 -- some implemented interface???
858 -- In a dispatching call the actual may be class-wide
860 elsif Is_Class_Wide_Type (T2)
861 and then Base_Type (Root_Type (T2)) = Base_Type (T1)
865 -- Some contexts require a class of types rather than a specific type
867 elsif (T1 = Any_Integer and then Is_Integer_Type (T2))
868 or else (T1 = Any_Boolean and then Is_Boolean_Type (T2))
869 or else (T1 = Any_Real and then Is_Real_Type (T2))
870 or else (T1 = Any_Fixed and then Is_Fixed_Point_Type (T2))
871 or else (T1 = Any_Discrete and then Is_Discrete_Type (T2))
875 -- An aggregate is compatible with an array or record type
877 elsif T2 = Any_Composite
878 and then Ekind (T1) in E_Array_Type .. E_Record_Subtype
882 -- If the expected type is an anonymous access, the designated type must
883 -- cover that of the expression. Use the base type for this check: even
884 -- though access subtypes are rare in sources, they are generated for
885 -- actuals in instantiations.
887 elsif Ekind (BT1) = E_Anonymous_Access_Type
888 and then Is_Access_Type (T2)
889 and then Covers (Designated_Type (T1), Designated_Type (T2))
893 -- An Access_To_Subprogram is compatible with itself, or with an
894 -- anonymous type created for an attribute reference Access.
896 elsif (Ekind (BT1) = E_Access_Subprogram_Type
898 Ekind (BT1) = E_Access_Protected_Subprogram_Type)
899 and then Is_Access_Type (T2)
900 and then (not Comes_From_Source (T1)
901 or else not Comes_From_Source (T2))
902 and then (Is_Overloadable (Designated_Type (T2))
904 Ekind (Designated_Type (T2)) = E_Subprogram_Type)
906 Type_Conformant (Designated_Type (T1), Designated_Type (T2))
908 Mode_Conformant (Designated_Type (T1), Designated_Type (T2))
912 -- Ada 2005 (AI-254): An Anonymous_Access_To_Subprogram is compatible
913 -- with itself, or with an anonymous type created for an attribute
916 elsif (Ekind (BT1) = E_Anonymous_Access_Subprogram_Type
919 = E_Anonymous_Access_Protected_Subprogram_Type)
920 and then Is_Access_Type (T2)
921 and then (not Comes_From_Source (T1)
922 or else not Comes_From_Source (T2))
923 and then (Is_Overloadable (Designated_Type (T2))
925 Ekind (Designated_Type (T2)) = E_Subprogram_Type)
927 Type_Conformant (Designated_Type (T1), Designated_Type (T2))
929 Mode_Conformant (Designated_Type (T1), Designated_Type (T2))
933 -- The context can be a remote access type, and the expression the
934 -- corresponding source type declared in a categorized package, or
937 elsif Is_Record_Type (T1)
938 and then (Is_Remote_Call_Interface (T1)
939 or else Is_Remote_Types (T1))
940 and then Present (Corresponding_Remote_Type (T1))
942 return Covers (Corresponding_Remote_Type (T1), T2);
944 elsif Is_Record_Type (T2)
945 and then (Is_Remote_Call_Interface (T2)
946 or else Is_Remote_Types (T2))
947 and then Present (Corresponding_Remote_Type (T2))
949 return Covers (Corresponding_Remote_Type (T2), T1);
951 elsif Ekind (T2) = E_Access_Attribute_Type
952 and then (Ekind (BT1) = E_General_Access_Type
953 or else Ekind (BT1) = E_Access_Type)
954 and then Covers (Designated_Type (T1), Designated_Type (T2))
956 -- If the target type is a RACW type while the source is an access
957 -- attribute type, we are building a RACW that may be exported.
959 if Is_Remote_Access_To_Class_Wide_Type (BT1) then
960 Set_Has_RACW (Current_Sem_Unit);
965 elsif Ekind (T2) = E_Allocator_Type
966 and then Is_Access_Type (T1)
968 return Covers (Designated_Type (T1), Designated_Type (T2))
970 (From_With_Type (Designated_Type (T1))
971 and then Covers (Designated_Type (T2), Designated_Type (T1)));
973 -- A boolean operation on integer literals is compatible with modular
976 elsif T2 = Any_Modular
977 and then Is_Modular_Integer_Type (T1)
981 -- The actual type may be the result of a previous error
983 elsif Base_Type (T2) = Any_Type then
986 -- A packed array type covers its corresponding non-packed type. This is
987 -- not legitimate Ada, but allows the omission of a number of otherwise
988 -- useless unchecked conversions, and since this can only arise in
989 -- (known correct) expanded code, no harm is done
991 elsif Is_Array_Type (T2)
992 and then Is_Packed (T2)
993 and then T1 = Packed_Array_Type (T2)
997 -- Similarly an array type covers its corresponding packed array type
999 elsif Is_Array_Type (T1)
1000 and then Is_Packed (T1)
1001 and then T2 = Packed_Array_Type (T1)
1005 -- In instances, or with types exported from instantiations, check
1006 -- whether a partial and a full view match. Verify that types are
1007 -- legal, to prevent cascaded errors.
1011 (Full_View_Covers (T1, T2)
1012 or else Full_View_Covers (T2, T1))
1017 and then Is_Generic_Actual_Type (T2)
1018 and then Full_View_Covers (T1, T2)
1023 and then Is_Generic_Actual_Type (T1)
1024 and then Full_View_Covers (T2, T1)
1028 -- In the expansion of inlined bodies, types are compatible if they
1029 -- are structurally equivalent.
1031 elsif In_Inlined_Body
1032 and then (Underlying_Type (T1) = Underlying_Type (T2)
1033 or else (Is_Access_Type (T1)
1034 and then Is_Access_Type (T2)
1036 Designated_Type (T1) = Designated_Type (T2))
1037 or else (T1 = Any_Access
1038 and then Is_Access_Type (Underlying_Type (T2)))
1039 or else (T2 = Any_Composite
1041 Is_Composite_Type (Underlying_Type (T1))))
1045 -- Ada 2005 (AI-50217): Additional branches to make the shadow entity
1046 -- compatible with its real entity.
1048 elsif From_With_Type (T1) then
1050 -- If the expected type is the non-limited view of a type, the
1051 -- expression may have the limited view. If that one in turn is
1052 -- incomplete, get full view if available.
1054 if Is_Incomplete_Type (T1) then
1055 return Covers (Get_Full_View (Non_Limited_View (T1)), T2);
1057 elsif Ekind (T1) = E_Class_Wide_Type then
1059 Covers (Class_Wide_Type (Non_Limited_View (Etype (T1))), T2);
1064 elsif From_With_Type (T2) then
1066 -- If units in the context have Limited_With clauses on each other,
1067 -- either type might have a limited view. Checks performed elsewhere
1068 -- verify that the context type is the non-limited view.
1070 if Is_Incomplete_Type (T2) then
1071 return Covers (T1, Get_Full_View (Non_Limited_View (T2)));
1073 elsif Ekind (T2) = E_Class_Wide_Type then
1075 Present (Non_Limited_View (Etype (T2)))
1077 Covers (T1, Class_Wide_Type (Non_Limited_View (Etype (T2))));
1082 -- Ada 2005 (AI-412): Coverage for regular incomplete subtypes
1084 elsif Ekind (T1) = E_Incomplete_Subtype then
1085 return Covers (Full_View (Etype (T1)), T2);
1087 elsif Ekind (T2) = E_Incomplete_Subtype then
1088 return Covers (T1, Full_View (Etype (T2)));
1090 -- Ada 2005 (AI-423): Coverage of formal anonymous access types
1091 -- and actual anonymous access types in the context of generic
1092 -- instantiation. We have the following situation:
1095 -- type Formal is private;
1096 -- Formal_Obj : access Formal; -- T1
1100 -- type Actual is ...
1101 -- Actual_Obj : access Actual; -- T2
1102 -- package Instance is new G (Formal => Actual,
1103 -- Formal_Obj => Actual_Obj);
1105 elsif Ada_Version >= Ada_05
1106 and then Ekind (T1) = E_Anonymous_Access_Type
1107 and then Ekind (T2) = E_Anonymous_Access_Type
1108 and then Is_Generic_Type (Directly_Designated_Type (T1))
1109 and then Get_Instance_Of (Directly_Designated_Type (T1)) =
1110 Directly_Designated_Type (T2)
1114 -- Otherwise it doesn't cover!
1125 function Disambiguate
1127 I1, I2 : Interp_Index;
1134 Nam1, Nam2 : Entity_Id;
1135 Predef_Subp : Entity_Id;
1136 User_Subp : Entity_Id;
1138 function Inherited_From_Actual (S : Entity_Id) return Boolean;
1139 -- Determine whether one of the candidates is an operation inherited by
1140 -- a type that is derived from an actual in an instantiation.
1142 function In_Generic_Actual (Exp : Node_Id) return Boolean;
1143 -- Determine whether the expression is part of a generic actual. At
1144 -- the time the actual is resolved the scope is already that of the
1145 -- instance, but conceptually the resolution of the actual takes place
1146 -- in the enclosing context, and no special disambiguation rules should
1149 function Is_Actual_Subprogram (S : Entity_Id) return Boolean;
1150 -- Determine whether a subprogram is an actual in an enclosing instance.
1151 -- An overloading between such a subprogram and one declared outside the
1152 -- instance is resolved in favor of the first, because it resolved in
1155 function Matches (Actual, Formal : Node_Id) return Boolean;
1156 -- Look for exact type match in an instance, to remove spurious
1157 -- ambiguities when two formal types have the same actual.
1159 function Standard_Operator return Boolean;
1160 -- Check whether subprogram is predefined operator declared in Standard.
1161 -- It may given by an operator name, or by an expanded name whose prefix
1164 function Remove_Conversions return Interp;
1165 -- Last chance for pathological cases involving comparisons on literals,
1166 -- and user overloadings of the same operator. Such pathologies have
1167 -- been removed from the ACVC, but still appear in two DEC tests, with
1168 -- the following notable quote from Ben Brosgol:
1170 -- [Note: I disclaim all credit/responsibility/blame for coming up with
1171 -- this example; Robert Dewar brought it to our attention, since it is
1172 -- apparently found in the ACVC 1.5. I did not attempt to find the
1173 -- reason in the Reference Manual that makes the example legal, since I
1174 -- was too nauseated by it to want to pursue it further.]
1176 -- Accordingly, this is not a fully recursive solution, but it handles
1177 -- DEC tests c460vsa, c460vsb. It also handles ai00136a, which pushes
1178 -- pathology in the other direction with calls whose multiple overloaded
1179 -- actuals make them truly unresolvable.
1181 -- The new rules concerning abstract operations create additional need
1182 -- for special handling of expressions with universal operands, see
1183 -- comments to Has_Abstract_Interpretation below.
1185 ------------------------
1186 -- In_Generic_Actual --
1187 ------------------------
1189 function In_Generic_Actual (Exp : Node_Id) return Boolean is
1190 Par : constant Node_Id := Parent (Exp);
1196 elsif Nkind (Par) in N_Declaration then
1197 if Nkind (Par) = N_Object_Declaration
1198 or else Nkind (Par) = N_Object_Renaming_Declaration
1200 return Present (Corresponding_Generic_Association (Par));
1205 elsif Nkind (Par) in N_Statement_Other_Than_Procedure_Call then
1209 return In_Generic_Actual (Parent (Par));
1211 end In_Generic_Actual;
1213 ---------------------------
1214 -- Inherited_From_Actual --
1215 ---------------------------
1217 function Inherited_From_Actual (S : Entity_Id) return Boolean is
1218 Par : constant Node_Id := Parent (S);
1220 if Nkind (Par) /= N_Full_Type_Declaration
1221 or else Nkind (Type_Definition (Par)) /= N_Derived_Type_Definition
1225 return Is_Entity_Name (Subtype_Indication (Type_Definition (Par)))
1227 Is_Generic_Actual_Type (
1228 Entity (Subtype_Indication (Type_Definition (Par))));
1230 end Inherited_From_Actual;
1232 --------------------------
1233 -- Is_Actual_Subprogram --
1234 --------------------------
1236 function Is_Actual_Subprogram (S : Entity_Id) return Boolean is
1238 return In_Open_Scopes (Scope (S))
1240 (Is_Generic_Instance (Scope (S))
1241 or else Is_Wrapper_Package (Scope (S)));
1242 end Is_Actual_Subprogram;
1248 function Matches (Actual, Formal : Node_Id) return Boolean is
1249 T1 : constant Entity_Id := Etype (Actual);
1250 T2 : constant Entity_Id := Etype (Formal);
1254 (Is_Numeric_Type (T2)
1256 (T1 = Universal_Real or else T1 = Universal_Integer));
1259 ------------------------
1260 -- Remove_Conversions --
1261 ------------------------
1263 function Remove_Conversions return Interp is
1271 function Has_Abstract_Interpretation (N : Node_Id) return Boolean;
1272 -- If an operation has universal operands the universal operation
1273 -- is present among its interpretations. If there is an abstract
1274 -- interpretation for the operator, with a numeric result, this
1275 -- interpretation was already removed in sem_ch4, but the universal
1276 -- one is still visible. We must rescan the list of operators and
1277 -- remove the universal interpretation to resolve the ambiguity.
1279 ---------------------------------
1280 -- Has_Abstract_Interpretation --
1281 ---------------------------------
1283 function Has_Abstract_Interpretation (N : Node_Id) return Boolean is
1287 if Nkind (N) not in N_Op
1288 or else Ada_Version < Ada_05
1289 or else not Is_Overloaded (N)
1290 or else No (Universal_Interpretation (N))
1295 E := Get_Name_Entity_Id (Chars (N));
1296 while Present (E) loop
1297 if Is_Overloadable (E)
1298 and then Is_Abstract_Subprogram (E)
1299 and then Is_Numeric_Type (Etype (E))
1307 -- Finally, if an operand of the binary operator is itself
1308 -- an operator, recurse to see whether its own abstract
1309 -- interpretation is responsible for the spurious ambiguity.
1311 if Nkind (N) in N_Binary_Op then
1312 return Has_Abstract_Interpretation (Left_Opnd (N))
1313 or else Has_Abstract_Interpretation (Right_Opnd (N));
1315 elsif Nkind (N) in N_Unary_Op then
1316 return Has_Abstract_Interpretation (Right_Opnd (N));
1322 end Has_Abstract_Interpretation;
1324 -- Start of processing for Remove_Conversions
1329 Get_First_Interp (N, I, It);
1330 while Present (It.Typ) loop
1331 if not Is_Overloadable (It.Nam) then
1335 F1 := First_Formal (It.Nam);
1341 if Nkind (N) = N_Function_Call
1342 or else Nkind (N) = N_Procedure_Call_Statement
1344 Act1 := First_Actual (N);
1346 if Present (Act1) then
1347 Act2 := Next_Actual (Act1);
1352 elsif Nkind (N) in N_Unary_Op then
1353 Act1 := Right_Opnd (N);
1356 elsif Nkind (N) in N_Binary_Op then
1357 Act1 := Left_Opnd (N);
1358 Act2 := Right_Opnd (N);
1360 -- Use type of second formal, so as to include
1361 -- exponentiation, where the exponent may be
1362 -- ambiguous and the result non-universal.
1370 if Nkind (Act1) in N_Op
1371 and then Is_Overloaded (Act1)
1372 and then (Nkind (Right_Opnd (Act1)) = N_Integer_Literal
1373 or else Nkind (Right_Opnd (Act1)) = N_Real_Literal)
1374 and then Has_Compatible_Type (Act1, Standard_Boolean)
1375 and then Etype (F1) = Standard_Boolean
1377 -- If the two candidates are the original ones, the
1378 -- ambiguity is real. Otherwise keep the original, further
1379 -- calls to Disambiguate will take care of others in the
1380 -- list of candidates.
1382 if It1 /= No_Interp then
1383 if It = Disambiguate.It1
1384 or else It = Disambiguate.It2
1386 if It1 = Disambiguate.It1
1387 or else It1 = Disambiguate.It2
1395 elsif Present (Act2)
1396 and then Nkind (Act2) in N_Op
1397 and then Is_Overloaded (Act2)
1398 and then (Nkind (Right_Opnd (Act2)) = N_Integer_Literal
1400 Nkind (Right_Opnd (Act2)) = N_Real_Literal)
1401 and then Has_Compatible_Type (Act2, Standard_Boolean)
1403 -- The preference rule on the first actual is not
1404 -- sufficient to disambiguate.
1412 elsif Is_Numeric_Type (Etype (F1))
1414 (Has_Abstract_Interpretation (Act1)
1415 or else Has_Abstract_Interpretation (Act2))
1417 if It = Disambiguate.It1 then
1418 return Disambiguate.It2;
1419 elsif It = Disambiguate.It2 then
1420 return Disambiguate.It1;
1426 Get_Next_Interp (I, It);
1429 -- After some error, a formal may have Any_Type and yield a spurious
1430 -- match. To avoid cascaded errors if possible, check for such a
1431 -- formal in either candidate.
1433 if Serious_Errors_Detected > 0 then
1438 Formal := First_Formal (Nam1);
1439 while Present (Formal) loop
1440 if Etype (Formal) = Any_Type then
1441 return Disambiguate.It2;
1444 Next_Formal (Formal);
1447 Formal := First_Formal (Nam2);
1448 while Present (Formal) loop
1449 if Etype (Formal) = Any_Type then
1450 return Disambiguate.It1;
1453 Next_Formal (Formal);
1459 end Remove_Conversions;
1461 -----------------------
1462 -- Standard_Operator --
1463 -----------------------
1465 function Standard_Operator return Boolean is
1469 if Nkind (N) in N_Op then
1472 elsif Nkind (N) = N_Function_Call then
1475 if Nkind (Nam) /= N_Expanded_Name then
1478 return Entity (Prefix (Nam)) = Standard_Standard;
1483 end Standard_Operator;
1485 -- Start of processing for Disambiguate
1488 -- Recover the two legal interpretations
1490 Get_First_Interp (N, I, It);
1492 Get_Next_Interp (I, It);
1498 Get_Next_Interp (I, It);
1504 if Ada_Version < Ada_05 then
1506 -- Check whether one of the entities is an Ada 2005 entity and we are
1507 -- operating in an earlier mode, in which case we discard the Ada
1508 -- 2005 entity, so that we get proper Ada 95 overload resolution.
1510 if Is_Ada_2005_Only (Nam1) then
1512 elsif Is_Ada_2005_Only (Nam2) then
1517 -- Check for overloaded CIL convention stuff because the CIL libraries
1518 -- do sick things like Console.WriteLine where it matches
1519 -- two different overloads, so just pick the first ???
1521 if Convention (Nam1) = Convention_CIL
1522 and then Convention (Nam2) = Convention_CIL
1523 and then Ekind (Nam1) = Ekind (Nam2)
1524 and then (Ekind (Nam1) = E_Procedure
1525 or else Ekind (Nam1) = E_Function)
1530 -- If the context is universal, the predefined operator is preferred.
1531 -- This includes bounds in numeric type declarations, and expressions
1532 -- in type conversions. If no interpretation yields a universal type,
1533 -- then we must check whether the user-defined entity hides the prede-
1536 if Chars (Nam1) in Any_Operator_Name
1537 and then Standard_Operator
1539 if Typ = Universal_Integer
1540 or else Typ = Universal_Real
1541 or else Typ = Any_Integer
1542 or else Typ = Any_Discrete
1543 or else Typ = Any_Real
1544 or else Typ = Any_Type
1546 -- Find an interpretation that yields the universal type, or else
1547 -- a predefined operator that yields a predefined numeric type.
1550 Candidate : Interp := No_Interp;
1553 Get_First_Interp (N, I, It);
1554 while Present (It.Typ) loop
1555 if (Covers (Typ, It.Typ)
1556 or else Typ = Any_Type)
1558 (It.Typ = Universal_Integer
1559 or else It.Typ = Universal_Real)
1563 elsif Covers (Typ, It.Typ)
1564 and then Scope (It.Typ) = Standard_Standard
1565 and then Scope (It.Nam) = Standard_Standard
1566 and then Is_Numeric_Type (It.Typ)
1571 Get_Next_Interp (I, It);
1574 if Candidate /= No_Interp then
1579 elsif Chars (Nam1) /= Name_Op_Not
1580 and then (Typ = Standard_Boolean or else Typ = Any_Boolean)
1582 -- Equality or comparison operation. Choose predefined operator if
1583 -- arguments are universal. The node may be an operator, name, or
1584 -- a function call, so unpack arguments accordingly.
1587 Arg1, Arg2 : Node_Id;
1590 if Nkind (N) in N_Op then
1591 Arg1 := Left_Opnd (N);
1592 Arg2 := Right_Opnd (N);
1594 elsif Is_Entity_Name (N)
1595 or else Nkind (N) = N_Operator_Symbol
1597 Arg1 := First_Entity (Entity (N));
1598 Arg2 := Next_Entity (Arg1);
1601 Arg1 := First_Actual (N);
1602 Arg2 := Next_Actual (Arg1);
1606 and then Present (Universal_Interpretation (Arg1))
1607 and then Universal_Interpretation (Arg2) =
1608 Universal_Interpretation (Arg1)
1610 Get_First_Interp (N, I, It);
1611 while Scope (It.Nam) /= Standard_Standard loop
1612 Get_Next_Interp (I, It);
1621 -- If no universal interpretation, check whether user-defined operator
1622 -- hides predefined one, as well as other special cases. If the node
1623 -- is a range, then one or both bounds are ambiguous. Each will have
1624 -- to be disambiguated w.r.t. the context type. The type of the range
1625 -- itself is imposed by the context, so we can return either legal
1628 if Ekind (Nam1) = E_Operator then
1629 Predef_Subp := Nam1;
1632 elsif Ekind (Nam2) = E_Operator then
1633 Predef_Subp := Nam2;
1636 elsif Nkind (N) = N_Range then
1639 -- If two user defined-subprograms are visible, it is a true ambiguity,
1640 -- unless one of them is an entry and the context is a conditional or
1641 -- timed entry call, or unless we are within an instance and this is
1642 -- results from two formals types with the same actual.
1645 if Nkind (N) = N_Procedure_Call_Statement
1646 and then Nkind (Parent (N)) = N_Entry_Call_Alternative
1647 and then N = Entry_Call_Statement (Parent (N))
1649 if Ekind (Nam2) = E_Entry then
1651 elsif Ekind (Nam1) = E_Entry then
1657 -- If the ambiguity occurs within an instance, it is due to several
1658 -- formal types with the same actual. Look for an exact match between
1659 -- the types of the formals of the overloadable entities, and the
1660 -- actuals in the call, to recover the unambiguous match in the
1661 -- original generic.
1663 -- The ambiguity can also be due to an overloading between a formal
1664 -- subprogram and a subprogram declared outside the generic. If the
1665 -- node is overloaded, it did not resolve to the global entity in
1666 -- the generic, and we choose the formal subprogram.
1668 -- Finally, the ambiguity can be between an explicit subprogram and
1669 -- one inherited (with different defaults) from an actual. In this
1670 -- case the resolution was to the explicit declaration in the
1671 -- generic, and remains so in the instance.
1674 and then not In_Generic_Actual (N)
1676 if Nkind (N) = N_Function_Call
1677 or else Nkind (N) = N_Procedure_Call_Statement
1682 Is_Act1 : constant Boolean := Is_Actual_Subprogram (Nam1);
1683 Is_Act2 : constant Boolean := Is_Actual_Subprogram (Nam2);
1686 if Is_Act1 and then not Is_Act2 then
1689 elsif Is_Act2 and then not Is_Act1 then
1692 elsif Inherited_From_Actual (Nam1)
1693 and then Comes_From_Source (Nam2)
1697 elsif Inherited_From_Actual (Nam2)
1698 and then Comes_From_Source (Nam1)
1703 Actual := First_Actual (N);
1704 Formal := First_Formal (Nam1);
1705 while Present (Actual) loop
1706 if Etype (Actual) /= Etype (Formal) then
1710 Next_Actual (Actual);
1711 Next_Formal (Formal);
1717 elsif Nkind (N) in N_Binary_Op then
1718 if Matches (Left_Opnd (N), First_Formal (Nam1))
1720 Matches (Right_Opnd (N), Next_Formal (First_Formal (Nam1)))
1727 elsif Nkind (N) in N_Unary_Op then
1728 if Etype (Right_Opnd (N)) = Etype (First_Formal (Nam1)) then
1735 return Remove_Conversions;
1738 return Remove_Conversions;
1742 -- An implicit concatenation operator on a string type cannot be
1743 -- disambiguated from the predefined concatenation. This can only
1744 -- happen with concatenation of string literals.
1746 if Chars (User_Subp) = Name_Op_Concat
1747 and then Ekind (User_Subp) = E_Operator
1748 and then Is_String_Type (Etype (First_Formal (User_Subp)))
1752 -- If the user-defined operator is in an open scope, or in the scope
1753 -- of the resulting type, or given by an expanded name that names its
1754 -- scope, it hides the predefined operator for the type. Exponentiation
1755 -- has to be special-cased because the implicit operator does not have
1756 -- a symmetric signature, and may not be hidden by the explicit one.
1758 elsif (Nkind (N) = N_Function_Call
1759 and then Nkind (Name (N)) = N_Expanded_Name
1760 and then (Chars (Predef_Subp) /= Name_Op_Expon
1761 or else Hides_Op (User_Subp, Predef_Subp))
1762 and then Scope (User_Subp) = Entity (Prefix (Name (N))))
1763 or else Hides_Op (User_Subp, Predef_Subp)
1765 if It1.Nam = User_Subp then
1771 -- Otherwise, the predefined operator has precedence, or if the user-
1772 -- defined operation is directly visible we have a true ambiguity. If
1773 -- this is a fixed-point multiplication and division in Ada83 mode,
1774 -- exclude the universal_fixed operator, which often causes ambiguities
1778 if (In_Open_Scopes (Scope (User_Subp))
1779 or else Is_Potentially_Use_Visible (User_Subp))
1780 and then not In_Instance
1782 if Is_Fixed_Point_Type (Typ)
1783 and then (Chars (Nam1) = Name_Op_Multiply
1784 or else Chars (Nam1) = Name_Op_Divide)
1785 and then Ada_Version = Ada_83
1787 if It2.Nam = Predef_Subp then
1793 -- Ada 2005, AI-420: preference rule for "=" on Universal_Access
1794 -- states that the operator defined in Standard is not available
1795 -- if there is a user-defined equality with the proper signature,
1796 -- declared in the same declarative list as the type. The node
1797 -- may be an operator or a function call.
1799 elsif (Chars (Nam1) = Name_Op_Eq
1801 Chars (Nam1) = Name_Op_Ne)
1802 and then Ada_Version >= Ada_05
1803 and then Etype (User_Subp) = Standard_Boolean
1808 if Nkind (N) = N_Function_Call then
1809 Opnd := First_Actual (N);
1811 Opnd := Left_Opnd (N);
1814 if Ekind (Etype (Opnd)) = E_Anonymous_Access_Type
1816 List_Containing (Parent (Designated_Type (Etype (Opnd))))
1817 = List_Containing (Unit_Declaration_Node (User_Subp))
1819 if It2.Nam = Predef_Subp then
1825 return Remove_Conversions;
1833 elsif It1.Nam = Predef_Subp then
1842 ---------------------
1843 -- End_Interp_List --
1844 ---------------------
1846 procedure End_Interp_List is
1848 All_Interp.Table (All_Interp.Last) := No_Interp;
1849 All_Interp.Increment_Last;
1850 end End_Interp_List;
1852 -------------------------
1853 -- Entity_Matches_Spec --
1854 -------------------------
1856 function Entity_Matches_Spec (Old_S, New_S : Entity_Id) return Boolean is
1858 -- Simple case: same entity kinds, type conformance is required. A
1859 -- parameterless function can also rename a literal.
1861 if Ekind (Old_S) = Ekind (New_S)
1862 or else (Ekind (New_S) = E_Function
1863 and then Ekind (Old_S) = E_Enumeration_Literal)
1865 return Type_Conformant (New_S, Old_S);
1867 elsif Ekind (New_S) = E_Function
1868 and then Ekind (Old_S) = E_Operator
1870 return Operator_Matches_Spec (Old_S, New_S);
1872 elsif Ekind (New_S) = E_Procedure
1873 and then Is_Entry (Old_S)
1875 return Type_Conformant (New_S, Old_S);
1880 end Entity_Matches_Spec;
1882 ----------------------
1883 -- Find_Unique_Type --
1884 ----------------------
1886 function Find_Unique_Type (L : Node_Id; R : Node_Id) return Entity_Id is
1887 T : constant Entity_Id := Etype (L);
1890 TR : Entity_Id := Any_Type;
1893 if Is_Overloaded (R) then
1894 Get_First_Interp (R, I, It);
1895 while Present (It.Typ) loop
1896 if Covers (T, It.Typ) or else Covers (It.Typ, T) then
1898 -- If several interpretations are possible and L is universal,
1899 -- apply preference rule.
1901 if TR /= Any_Type then
1903 if (T = Universal_Integer or else T = Universal_Real)
1914 Get_Next_Interp (I, It);
1919 -- In the non-overloaded case, the Etype of R is already set correctly
1925 -- If one of the operands is Universal_Fixed, the type of the other
1926 -- operand provides the context.
1928 if Etype (R) = Universal_Fixed then
1931 elsif T = Universal_Fixed then
1934 -- Ada 2005 (AI-230): Support the following operators:
1936 -- function "=" (L, R : universal_access) return Boolean;
1937 -- function "/=" (L, R : universal_access) return Boolean;
1939 -- Pool specific access types (E_Access_Type) are not covered by these
1940 -- operators because of the legality rule of 4.5.2(9.2): "The operands
1941 -- of the equality operators for universal_access shall be convertible
1942 -- to one another (see 4.6)". For example, considering the type decla-
1943 -- ration "type P is access Integer" and an anonymous access to Integer,
1944 -- P is convertible to "access Integer" by 4.6 (24.11-24.15), but there
1945 -- is no rule in 4.6 that allows "access Integer" to be converted to P.
1947 elsif Ada_Version >= Ada_05
1949 (Ekind (Etype (L)) = E_Anonymous_Access_Type
1951 Ekind (Etype (L)) = E_Anonymous_Access_Subprogram_Type)
1952 and then Is_Access_Type (Etype (R))
1953 and then Ekind (Etype (R)) /= E_Access_Type
1957 elsif Ada_Version >= Ada_05
1959 (Ekind (Etype (R)) = E_Anonymous_Access_Type
1960 or else Ekind (Etype (R)) = E_Anonymous_Access_Subprogram_Type)
1961 and then Is_Access_Type (Etype (L))
1962 and then Ekind (Etype (L)) /= E_Access_Type
1967 return Specific_Type (T, Etype (R));
1969 end Find_Unique_Type;
1971 -------------------------------------
1972 -- Function_Interp_Has_Abstract_Op --
1973 -------------------------------------
1975 function Function_Interp_Has_Abstract_Op
1977 E : Entity_Id) return Entity_Id
1979 Abstr_Op : Entity_Id;
1982 Form_Parm : Node_Id;
1985 -- Why is check on E needed below ???
1986 -- In any case this para needs comments ???
1988 if Is_Overloaded (N) and then Is_Overloadable (E) then
1989 Act_Parm := First_Actual (N);
1990 Form_Parm := First_Formal (E);
1991 while Present (Act_Parm)
1992 and then Present (Form_Parm)
1996 if Nkind (Act) = N_Parameter_Association then
1997 Act := Explicit_Actual_Parameter (Act);
2000 Abstr_Op := Has_Abstract_Op (Act, Etype (Form_Parm));
2002 if Present (Abstr_Op) then
2006 Next_Actual (Act_Parm);
2007 Next_Formal (Form_Parm);
2012 end Function_Interp_Has_Abstract_Op;
2014 ----------------------
2015 -- Get_First_Interp --
2016 ----------------------
2018 procedure Get_First_Interp
2020 I : out Interp_Index;
2023 Int_Ind : Interp_Index;
2028 -- If a selected component is overloaded because the selector has
2029 -- multiple interpretations, the node is a call to a protected
2030 -- operation or an indirect call. Retrieve the interpretation from
2031 -- the selector name. The selected component may be overloaded as well
2032 -- if the prefix is overloaded. That case is unchanged.
2034 if Nkind (N) = N_Selected_Component
2035 and then Is_Overloaded (Selector_Name (N))
2037 O_N := Selector_Name (N);
2042 Map_Ptr := Headers (Hash (O_N));
2043 while Present (Interp_Map.Table (Map_Ptr).Node) loop
2044 if Interp_Map.Table (Map_Ptr).Node = O_N then
2045 Int_Ind := Interp_Map.Table (Map_Ptr).Index;
2046 It := All_Interp.Table (Int_Ind);
2050 Map_Ptr := Interp_Map.Table (Map_Ptr).Next;
2054 -- Procedure should never be called if the node has no interpretations
2056 raise Program_Error;
2057 end Get_First_Interp;
2059 ---------------------
2060 -- Get_Next_Interp --
2061 ---------------------
2063 procedure Get_Next_Interp (I : in out Interp_Index; It : out Interp) is
2066 It := All_Interp.Table (I);
2067 end Get_Next_Interp;
2069 -------------------------
2070 -- Has_Compatible_Type --
2071 -------------------------
2073 function Has_Compatible_Type
2086 if Nkind (N) = N_Subtype_Indication
2087 or else not Is_Overloaded (N)
2090 Covers (Typ, Etype (N))
2092 -- Ada 2005 (AI-345) The context may be a synchronized interface.
2093 -- If the type is already frozen use the corresponding_record
2094 -- to check whether it is a proper descendant.
2097 (Is_Concurrent_Type (Etype (N))
2098 and then Present (Corresponding_Record_Type (Etype (N)))
2099 and then Covers (Typ, Corresponding_Record_Type (Etype (N))))
2102 (not Is_Tagged_Type (Typ)
2103 and then Ekind (Typ) /= E_Anonymous_Access_Type
2104 and then Covers (Etype (N), Typ));
2107 Get_First_Interp (N, I, It);
2108 while Present (It.Typ) loop
2109 if (Covers (Typ, It.Typ)
2111 (Scope (It.Nam) /= Standard_Standard
2112 or else not Is_Invisible_Operator (N, Base_Type (Typ))))
2114 -- Ada 2005 (AI-345)
2117 (Is_Concurrent_Type (It.Typ)
2118 and then Present (Corresponding_Record_Type
2120 and then Covers (Typ, Corresponding_Record_Type
2123 or else (not Is_Tagged_Type (Typ)
2124 and then Ekind (Typ) /= E_Anonymous_Access_Type
2125 and then Covers (It.Typ, Typ))
2130 Get_Next_Interp (I, It);
2135 end Has_Compatible_Type;
2137 ---------------------
2138 -- Has_Abstract_Op --
2139 ---------------------
2141 function Has_Abstract_Op
2143 Typ : Entity_Id) return Entity_Id
2149 if Is_Overloaded (N) then
2150 Get_First_Interp (N, I, It);
2151 while Present (It.Nam) loop
2152 if Present (It.Abstract_Op)
2153 and then Etype (It.Abstract_Op) = Typ
2155 return It.Abstract_Op;
2158 Get_Next_Interp (I, It);
2163 end Has_Abstract_Op;
2169 function Hash (N : Node_Id) return Int is
2171 -- Nodes have a size that is power of two, so to select significant
2172 -- bits only we remove the low-order bits.
2174 return ((Int (N) / 2 ** 5) mod Header_Size);
2181 function Hides_Op (F : Entity_Id; Op : Entity_Id) return Boolean is
2182 Btyp : constant Entity_Id := Base_Type (Etype (First_Formal (F)));
2184 return Operator_Matches_Spec (Op, F)
2185 and then (In_Open_Scopes (Scope (F))
2186 or else Scope (F) = Scope (Btyp)
2187 or else (not In_Open_Scopes (Scope (Btyp))
2188 and then not In_Use (Btyp)
2189 and then not In_Use (Scope (Btyp))));
2192 ------------------------
2193 -- Init_Interp_Tables --
2194 ------------------------
2196 procedure Init_Interp_Tables is
2200 Headers := (others => No_Entry);
2201 end Init_Interp_Tables;
2203 -----------------------------------
2204 -- Interface_Present_In_Ancestor --
2205 -----------------------------------
2207 function Interface_Present_In_Ancestor
2209 Iface : Entity_Id) return Boolean
2211 Target_Typ : Entity_Id;
2212 Iface_Typ : Entity_Id;
2214 function Iface_Present_In_Ancestor (Typ : Entity_Id) return Boolean;
2215 -- Returns True if Typ or some ancestor of Typ implements Iface
2217 -------------------------------
2218 -- Iface_Present_In_Ancestor --
2219 -------------------------------
2221 function Iface_Present_In_Ancestor (Typ : Entity_Id) return Boolean is
2227 if Typ = Iface_Typ then
2231 -- Handle private types
2233 if Present (Full_View (Typ))
2234 and then not Is_Concurrent_Type (Full_View (Typ))
2236 E := Full_View (Typ);
2242 if Present (Abstract_Interfaces (E))
2243 and then Present (Abstract_Interfaces (E))
2244 and then not Is_Empty_Elmt_List (Abstract_Interfaces (E))
2246 Elmt := First_Elmt (Abstract_Interfaces (E));
2247 while Present (Elmt) loop
2250 if AI = Iface_Typ or else Is_Ancestor (Iface_Typ, AI) then
2258 exit when Etype (E) = E
2260 -- Handle private types
2262 or else (Present (Full_View (Etype (E)))
2263 and then Full_View (Etype (E)) = E);
2265 -- Check if the current type is a direct derivation of the
2268 if Etype (E) = Iface_Typ then
2272 -- Climb to the immediate ancestor handling private types
2274 if Present (Full_View (Etype (E))) then
2275 E := Full_View (Etype (E));
2282 end Iface_Present_In_Ancestor;
2284 -- Start of processing for Interface_Present_In_Ancestor
2287 if Is_Class_Wide_Type (Iface) then
2288 Iface_Typ := Etype (Iface);
2295 Iface_Typ := Base_Type (Iface_Typ);
2297 if Is_Access_Type (Typ) then
2298 Target_Typ := Etype (Directly_Designated_Type (Typ));
2303 if Is_Concurrent_Record_Type (Target_Typ) then
2304 Target_Typ := Corresponding_Concurrent_Type (Target_Typ);
2307 Target_Typ := Base_Type (Target_Typ);
2309 -- In case of concurrent types we can't use the Corresponding Record_Typ
2310 -- to look for the interface because it is built by the expander (and
2311 -- hence it is not always available). For this reason we traverse the
2312 -- list of interfaces (available in the parent of the concurrent type)
2314 if Is_Concurrent_Type (Target_Typ) then
2315 if Present (Interface_List (Parent (Target_Typ))) then
2320 AI := First (Interface_List (Parent (Target_Typ)));
2321 while Present (AI) loop
2322 if Etype (AI) = Iface_Typ then
2325 elsif Present (Abstract_Interfaces (Etype (AI)))
2326 and then Iface_Present_In_Ancestor (Etype (AI))
2339 if Is_Class_Wide_Type (Target_Typ) then
2340 Target_Typ := Etype (Target_Typ);
2343 if Ekind (Target_Typ) = E_Incomplete_Type then
2344 pragma Assert (Present (Non_Limited_View (Target_Typ)));
2345 Target_Typ := Non_Limited_View (Target_Typ);
2347 -- Protect the frontend against previously detected errors
2349 if Ekind (Target_Typ) = E_Incomplete_Type then
2354 return Iface_Present_In_Ancestor (Target_Typ);
2355 end Interface_Present_In_Ancestor;
2357 ---------------------
2358 -- Intersect_Types --
2359 ---------------------
2361 function Intersect_Types (L, R : Node_Id) return Entity_Id is
2362 Index : Interp_Index;
2366 function Check_Right_Argument (T : Entity_Id) return Entity_Id;
2367 -- Find interpretation of right arg that has type compatible with T
2369 --------------------------
2370 -- Check_Right_Argument --
2371 --------------------------
2373 function Check_Right_Argument (T : Entity_Id) return Entity_Id is
2374 Index : Interp_Index;
2379 if not Is_Overloaded (R) then
2380 return Specific_Type (T, Etype (R));
2383 Get_First_Interp (R, Index, It);
2385 T2 := Specific_Type (T, It.Typ);
2387 if T2 /= Any_Type then
2391 Get_Next_Interp (Index, It);
2392 exit when No (It.Typ);
2397 end Check_Right_Argument;
2399 -- Start processing for Intersect_Types
2402 if Etype (L) = Any_Type or else Etype (R) = Any_Type then
2406 if not Is_Overloaded (L) then
2407 Typ := Check_Right_Argument (Etype (L));
2411 Get_First_Interp (L, Index, It);
2412 while Present (It.Typ) loop
2413 Typ := Check_Right_Argument (It.Typ);
2414 exit when Typ /= Any_Type;
2415 Get_Next_Interp (Index, It);
2420 -- If Typ is Any_Type, it means no compatible pair of types was found
2422 if Typ = Any_Type then
2423 if Nkind (Parent (L)) in N_Op then
2424 Error_Msg_N ("incompatible types for operator", Parent (L));
2426 elsif Nkind (Parent (L)) = N_Range then
2427 Error_Msg_N ("incompatible types given in constraint", Parent (L));
2429 -- Ada 2005 (AI-251): Complete the error notification
2431 elsif Is_Class_Wide_Type (Etype (R))
2432 and then Is_Interface (Etype (Class_Wide_Type (Etype (R))))
2434 Error_Msg_NE ("(Ada 2005) does not implement interface }",
2435 L, Etype (Class_Wide_Type (Etype (R))));
2438 Error_Msg_N ("incompatible types", Parent (L));
2443 end Intersect_Types;
2449 function Is_Ancestor (T1, T2 : Entity_Id) return Boolean is
2453 if Base_Type (T1) = Base_Type (T2) then
2456 elsif Is_Private_Type (T1)
2457 and then Present (Full_View (T1))
2458 and then Base_Type (T2) = Base_Type (Full_View (T1))
2466 -- If there was a error on the type declaration, do not recurse
2468 if Error_Posted (Par) then
2471 elsif Base_Type (T1) = Base_Type (Par)
2472 or else (Is_Private_Type (T1)
2473 and then Present (Full_View (T1))
2474 and then Base_Type (Par) = Base_Type (Full_View (T1)))
2478 elsif Is_Private_Type (Par)
2479 and then Present (Full_View (Par))
2480 and then Full_View (Par) = Base_Type (T1)
2484 elsif Etype (Par) /= Par then
2493 ---------------------------
2494 -- Is_Invisible_Operator --
2495 ---------------------------
2497 function Is_Invisible_Operator
2502 Orig_Node : constant Node_Id := Original_Node (N);
2505 if Nkind (N) not in N_Op then
2508 elsif not Comes_From_Source (N) then
2511 elsif No (Universal_Interpretation (Right_Opnd (N))) then
2514 elsif Nkind (N) in N_Binary_Op
2515 and then No (Universal_Interpretation (Left_Opnd (N)))
2520 return Is_Numeric_Type (T)
2521 and then not In_Open_Scopes (Scope (T))
2522 and then not Is_Potentially_Use_Visible (T)
2523 and then not In_Use (T)
2524 and then not In_Use (Scope (T))
2526 (Nkind (Orig_Node) /= N_Function_Call
2527 or else Nkind (Name (Orig_Node)) /= N_Expanded_Name
2528 or else Entity (Prefix (Name (Orig_Node))) /= Scope (T))
2529 and then not In_Instance;
2531 end Is_Invisible_Operator;
2537 function Is_Subtype_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
2541 S := Ancestor_Subtype (T1);
2542 while Present (S) loop
2546 S := Ancestor_Subtype (S);
2557 procedure List_Interps (Nam : Node_Id; Err : Node_Id) is
2558 Index : Interp_Index;
2562 Get_First_Interp (Nam, Index, It);
2563 while Present (It.Nam) loop
2564 if Scope (It.Nam) = Standard_Standard
2565 and then Scope (It.Typ) /= Standard_Standard
2567 Error_Msg_Sloc := Sloc (Parent (It.Typ));
2568 Error_Msg_NE ("\\& (inherited) declared#!", Err, It.Nam);
2571 Error_Msg_Sloc := Sloc (It.Nam);
2572 Error_Msg_NE ("\\& declared#!", Err, It.Nam);
2575 Get_Next_Interp (Index, It);
2583 procedure New_Interps (N : Node_Id) is
2587 All_Interp.Increment_Last;
2588 All_Interp.Table (All_Interp.Last) := No_Interp;
2590 Map_Ptr := Headers (Hash (N));
2592 if Map_Ptr = No_Entry then
2594 -- Place new node at end of table
2596 Interp_Map.Increment_Last;
2597 Headers (Hash (N)) := Interp_Map.Last;
2600 -- Place node at end of chain, or locate its previous entry
2603 if Interp_Map.Table (Map_Ptr).Node = N then
2605 -- Node is already in the table, and is being rewritten.
2606 -- Start a new interp section, retain hash link.
2608 Interp_Map.Table (Map_Ptr).Node := N;
2609 Interp_Map.Table (Map_Ptr).Index := All_Interp.Last;
2610 Set_Is_Overloaded (N, True);
2614 exit when Interp_Map.Table (Map_Ptr).Next = No_Entry;
2615 Map_Ptr := Interp_Map.Table (Map_Ptr).Next;
2619 -- Chain the new node
2621 Interp_Map.Increment_Last;
2622 Interp_Map.Table (Map_Ptr).Next := Interp_Map.Last;
2625 Interp_Map.Table (Interp_Map.Last) := (N, All_Interp.Last, No_Entry);
2626 Set_Is_Overloaded (N, True);
2629 ---------------------------
2630 -- Operator_Matches_Spec --
2631 ---------------------------
2633 function Operator_Matches_Spec (Op, New_S : Entity_Id) return Boolean is
2634 Op_Name : constant Name_Id := Chars (Op);
2635 T : constant Entity_Id := Etype (New_S);
2643 -- To verify that a predefined operator matches a given signature,
2644 -- do a case analysis of the operator classes. Function can have one
2645 -- or two formals and must have the proper result type.
2647 New_F := First_Formal (New_S);
2648 Old_F := First_Formal (Op);
2650 while Present (New_F) and then Present (Old_F) loop
2652 Next_Formal (New_F);
2653 Next_Formal (Old_F);
2656 -- Definite mismatch if different number of parameters
2658 if Present (Old_F) or else Present (New_F) then
2664 T1 := Etype (First_Formal (New_S));
2666 if Op_Name = Name_Op_Subtract
2667 or else Op_Name = Name_Op_Add
2668 or else Op_Name = Name_Op_Abs
2670 return Base_Type (T1) = Base_Type (T)
2671 and then Is_Numeric_Type (T);
2673 elsif Op_Name = Name_Op_Not then
2674 return Base_Type (T1) = Base_Type (T)
2675 and then Valid_Boolean_Arg (Base_Type (T));
2684 T1 := Etype (First_Formal (New_S));
2685 T2 := Etype (Next_Formal (First_Formal (New_S)));
2687 if Op_Name = Name_Op_And or else Op_Name = Name_Op_Or
2688 or else Op_Name = Name_Op_Xor
2690 return Base_Type (T1) = Base_Type (T2)
2691 and then Base_Type (T1) = Base_Type (T)
2692 and then Valid_Boolean_Arg (Base_Type (T));
2694 elsif Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne then
2695 return Base_Type (T1) = Base_Type (T2)
2696 and then not Is_Limited_Type (T1)
2697 and then Is_Boolean_Type (T);
2699 elsif Op_Name = Name_Op_Lt or else Op_Name = Name_Op_Le
2700 or else Op_Name = Name_Op_Gt or else Op_Name = Name_Op_Ge
2702 return Base_Type (T1) = Base_Type (T2)
2703 and then Valid_Comparison_Arg (T1)
2704 and then Is_Boolean_Type (T);
2706 elsif Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
2707 return Base_Type (T1) = Base_Type (T2)
2708 and then Base_Type (T1) = Base_Type (T)
2709 and then Is_Numeric_Type (T);
2711 -- for division and multiplication, a user-defined function does
2712 -- not match the predefined universal_fixed operation, except in
2715 elsif Op_Name = Name_Op_Divide then
2716 return (Base_Type (T1) = Base_Type (T2)
2717 and then Base_Type (T1) = Base_Type (T)
2718 and then Is_Numeric_Type (T)
2719 and then (not Is_Fixed_Point_Type (T)
2720 or else Ada_Version = Ada_83))
2722 -- Mixed_Mode operations on fixed-point types
2724 or else (Base_Type (T1) = Base_Type (T)
2725 and then Base_Type (T2) = Base_Type (Standard_Integer)
2726 and then Is_Fixed_Point_Type (T))
2728 -- A user defined operator can also match (and hide) a mixed
2729 -- operation on universal literals.
2731 or else (Is_Integer_Type (T2)
2732 and then Is_Floating_Point_Type (T1)
2733 and then Base_Type (T1) = Base_Type (T));
2735 elsif Op_Name = Name_Op_Multiply then
2736 return (Base_Type (T1) = Base_Type (T2)
2737 and then Base_Type (T1) = Base_Type (T)
2738 and then Is_Numeric_Type (T)
2739 and then (not Is_Fixed_Point_Type (T)
2740 or else Ada_Version = Ada_83))
2742 -- Mixed_Mode operations on fixed-point types
2744 or else (Base_Type (T1) = Base_Type (T)
2745 and then Base_Type (T2) = Base_Type (Standard_Integer)
2746 and then Is_Fixed_Point_Type (T))
2748 or else (Base_Type (T2) = Base_Type (T)
2749 and then Base_Type (T1) = Base_Type (Standard_Integer)
2750 and then Is_Fixed_Point_Type (T))
2752 or else (Is_Integer_Type (T2)
2753 and then Is_Floating_Point_Type (T1)
2754 and then Base_Type (T1) = Base_Type (T))
2756 or else (Is_Integer_Type (T1)
2757 and then Is_Floating_Point_Type (T2)
2758 and then Base_Type (T2) = Base_Type (T));
2760 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
2761 return Base_Type (T1) = Base_Type (T2)
2762 and then Base_Type (T1) = Base_Type (T)
2763 and then Is_Integer_Type (T);
2765 elsif Op_Name = Name_Op_Expon then
2766 return Base_Type (T1) = Base_Type (T)
2767 and then Is_Numeric_Type (T)
2768 and then Base_Type (T2) = Base_Type (Standard_Integer);
2770 elsif Op_Name = Name_Op_Concat then
2771 return Is_Array_Type (T)
2772 and then (Base_Type (T) = Base_Type (Etype (Op)))
2773 and then (Base_Type (T1) = Base_Type (T)
2775 Base_Type (T1) = Base_Type (Component_Type (T)))
2776 and then (Base_Type (T2) = Base_Type (T)
2778 Base_Type (T2) = Base_Type (Component_Type (T)));
2784 end Operator_Matches_Spec;
2790 procedure Remove_Interp (I : in out Interp_Index) is
2794 -- Find end of Interp list and copy downward to erase the discarded one
2797 while Present (All_Interp.Table (II).Typ) loop
2801 for J in I + 1 .. II loop
2802 All_Interp.Table (J - 1) := All_Interp.Table (J);
2805 -- Back up interp. index to insure that iterator will pick up next
2806 -- available interpretation.
2815 procedure Save_Interps (Old_N : Node_Id; New_N : Node_Id) is
2817 O_N : Node_Id := Old_N;
2820 if Is_Overloaded (Old_N) then
2821 if Nkind (Old_N) = N_Selected_Component
2822 and then Is_Overloaded (Selector_Name (Old_N))
2824 O_N := Selector_Name (Old_N);
2827 Map_Ptr := Headers (Hash (O_N));
2829 while Interp_Map.Table (Map_Ptr).Node /= O_N loop
2830 Map_Ptr := Interp_Map.Table (Map_Ptr).Next;
2831 pragma Assert (Map_Ptr /= No_Entry);
2834 New_Interps (New_N);
2835 Interp_Map.Table (Interp_Map.Last).Index :=
2836 Interp_Map.Table (Map_Ptr).Index;
2844 function Specific_Type (Typ_1, Typ_2 : Entity_Id) return Entity_Id is
2845 T1 : constant Entity_Id := Available_View (Typ_1);
2846 T2 : constant Entity_Id := Available_View (Typ_2);
2847 B1 : constant Entity_Id := Base_Type (T1);
2848 B2 : constant Entity_Id := Base_Type (T2);
2850 function Is_Remote_Access (T : Entity_Id) return Boolean;
2851 -- Check whether T is the equivalent type of a remote access type.
2852 -- If distribution is enabled, T is a legal context for Null.
2854 ----------------------
2855 -- Is_Remote_Access --
2856 ----------------------
2858 function Is_Remote_Access (T : Entity_Id) return Boolean is
2860 return Is_Record_Type (T)
2861 and then (Is_Remote_Call_Interface (T)
2862 or else Is_Remote_Types (T))
2863 and then Present (Corresponding_Remote_Type (T))
2864 and then Is_Access_Type (Corresponding_Remote_Type (T));
2865 end Is_Remote_Access;
2867 -- Start of processing for Specific_Type
2870 if T1 = Any_Type or else T2 = Any_Type then
2877 elsif (T1 = Universal_Integer and then Is_Integer_Type (T2))
2878 or else (T1 = Universal_Real and then Is_Real_Type (T2))
2879 or else (T1 = Universal_Fixed and then Is_Fixed_Point_Type (T2))
2880 or else (T1 = Any_Fixed and then Is_Fixed_Point_Type (T2))
2884 elsif (T2 = Universal_Integer and then Is_Integer_Type (T1))
2885 or else (T2 = Universal_Real and then Is_Real_Type (T1))
2886 or else (T2 = Universal_Fixed and then Is_Fixed_Point_Type (T1))
2887 or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1))
2891 elsif T2 = Any_String and then Is_String_Type (T1) then
2894 elsif T1 = Any_String and then Is_String_Type (T2) then
2897 elsif T2 = Any_Character and then Is_Character_Type (T1) then
2900 elsif T1 = Any_Character and then Is_Character_Type (T2) then
2903 elsif T1 = Any_Access
2904 and then (Is_Access_Type (T2) or else Is_Remote_Access (T2))
2908 elsif T2 = Any_Access
2909 and then (Is_Access_Type (T1) or else Is_Remote_Access (T1))
2913 elsif T2 = Any_Composite
2914 and then Ekind (T1) in E_Array_Type .. E_Record_Subtype
2918 elsif T1 = Any_Composite
2919 and then Ekind (T2) in E_Array_Type .. E_Record_Subtype
2923 elsif T1 = Any_Modular and then Is_Modular_Integer_Type (T2) then
2926 elsif T2 = Any_Modular and then Is_Modular_Integer_Type (T1) then
2929 -- ----------------------------------------------------------
2930 -- Special cases for equality operators (all other predefined
2931 -- operators can never apply to tagged types)
2932 -- ----------------------------------------------------------
2934 -- Ada 2005 (AI-251): T1 and T2 are class-wide types, and T2 is an
2937 elsif Is_Class_Wide_Type (T1)
2938 and then Is_Class_Wide_Type (T2)
2939 and then Is_Interface (Etype (T2))
2943 -- Ada 2005 (AI-251): T1 is a concrete type that implements the
2944 -- class-wide interface T2
2946 elsif Is_Class_Wide_Type (T2)
2947 and then Is_Interface (Etype (T2))
2948 and then Interface_Present_In_Ancestor (Typ => T1,
2949 Iface => Etype (T2))
2953 elsif Is_Class_Wide_Type (T1)
2954 and then Is_Ancestor (Root_Type (T1), T2)
2958 elsif Is_Class_Wide_Type (T2)
2959 and then Is_Ancestor (Root_Type (T2), T1)
2963 elsif (Ekind (B1) = E_Access_Subprogram_Type
2965 Ekind (B1) = E_Access_Protected_Subprogram_Type)
2966 and then Ekind (Designated_Type (B1)) /= E_Subprogram_Type
2967 and then Is_Access_Type (T2)
2971 elsif (Ekind (B2) = E_Access_Subprogram_Type
2973 Ekind (B2) = E_Access_Protected_Subprogram_Type)
2974 and then Ekind (Designated_Type (B2)) /= E_Subprogram_Type
2975 and then Is_Access_Type (T1)
2979 elsif (Ekind (T1) = E_Allocator_Type
2980 or else Ekind (T1) = E_Access_Attribute_Type
2981 or else Ekind (T1) = E_Anonymous_Access_Type)
2982 and then Is_Access_Type (T2)
2986 elsif (Ekind (T2) = E_Allocator_Type
2987 or else Ekind (T2) = E_Access_Attribute_Type
2988 or else Ekind (T2) = E_Anonymous_Access_Type)
2989 and then Is_Access_Type (T1)
2993 -- If none of the above cases applies, types are not compatible
3000 ---------------------
3001 -- Set_Abstract_Op --
3002 ---------------------
3004 procedure Set_Abstract_Op (I : Interp_Index; V : Entity_Id) is
3006 All_Interp.Table (I).Abstract_Op := V;
3007 end Set_Abstract_Op;
3009 -----------------------
3010 -- Valid_Boolean_Arg --
3011 -----------------------
3013 -- In addition to booleans and arrays of booleans, we must include
3014 -- aggregates as valid boolean arguments, because in the first pass of
3015 -- resolution their components are not examined. If it turns out not to be
3016 -- an aggregate of booleans, this will be diagnosed in Resolve.
3017 -- Any_Composite must be checked for prior to the array type checks because
3018 -- Any_Composite does not have any associated indexes.
3020 function Valid_Boolean_Arg (T : Entity_Id) return Boolean is
3022 return Is_Boolean_Type (T)
3023 or else T = Any_Composite
3024 or else (Is_Array_Type (T)
3025 and then T /= Any_String
3026 and then Number_Dimensions (T) = 1
3027 and then Is_Boolean_Type (Component_Type (T))
3028 and then (not Is_Private_Composite (T)
3029 or else In_Instance)
3030 and then (not Is_Limited_Composite (T)
3031 or else In_Instance))
3032 or else Is_Modular_Integer_Type (T)
3033 or else T = Universal_Integer;
3034 end Valid_Boolean_Arg;
3036 --------------------------
3037 -- Valid_Comparison_Arg --
3038 --------------------------
3040 function Valid_Comparison_Arg (T : Entity_Id) return Boolean is
3043 if T = Any_Composite then
3045 elsif Is_Discrete_Type (T)
3046 or else Is_Real_Type (T)
3049 elsif Is_Array_Type (T)
3050 and then Number_Dimensions (T) = 1
3051 and then Is_Discrete_Type (Component_Type (T))
3052 and then (not Is_Private_Composite (T)
3053 or else In_Instance)
3054 and then (not Is_Limited_Composite (T)
3055 or else In_Instance)
3058 elsif Is_String_Type (T) then
3063 end Valid_Comparison_Arg;
3065 ----------------------
3066 -- Write_Interp_Ref --
3067 ----------------------
3069 procedure Write_Interp_Ref (Map_Ptr : Int) is
3071 Write_Str (" Node: ");
3072 Write_Int (Int (Interp_Map.Table (Map_Ptr).Node));
3073 Write_Str (" Index: ");
3074 Write_Int (Int (Interp_Map.Table (Map_Ptr).Index));
3075 Write_Str (" Next: ");
3076 Write_Int (Int (Interp_Map.Table (Map_Ptr).Next));
3078 end Write_Interp_Ref;
3080 ---------------------
3081 -- Write_Overloads --
3082 ---------------------
3084 procedure Write_Overloads (N : Node_Id) is
3090 if not Is_Overloaded (N) then
3091 Write_Str ("Non-overloaded entity ");
3093 Write_Entity_Info (Entity (N), " ");
3096 Get_First_Interp (N, I, It);
3097 Write_Str ("Overloaded entity ");
3099 Write_Str (" Name Type Abstract Op");
3101 Write_Str ("===============================================");
3105 while Present (Nam) loop
3106 Write_Int (Int (Nam));
3108 Write_Name (Chars (Nam));
3110 Write_Int (Int (It.Typ));
3112 Write_Name (Chars (It.Typ));
3114 if Present (It.Abstract_Op) then
3116 Write_Int (Int (It.Abstract_Op));
3118 Write_Name (Chars (It.Abstract_Op));
3122 Get_Next_Interp (I, It);
3126 end Write_Overloads;