1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Nlists; use Nlists;
33 with Errout; use Errout;
35 with Namet; use Namet;
37 with Output; use Output;
39 with Sem_Ch6; use Sem_Ch6;
40 with Sem_Ch8; use Sem_Ch8;
41 with Sem_Ch12; use Sem_Ch12;
42 with Sem_Disp; use Sem_Disp;
43 with Sem_Util; use Sem_Util;
44 with Stand; use Stand;
45 with Sinfo; use Sinfo;
46 with Snames; use Snames;
48 with Uintp; use Uintp;
50 package body Sem_Type is
56 -- The following data structures establish a mapping between nodes and
57 -- their interpretations. An overloaded node has an entry in Interp_Map,
58 -- which in turn contains a pointer into the All_Interp array. The
59 -- interpretations of a given node are contiguous in All_Interp. Each
60 -- set of interpretations is terminated with the marker No_Interp.
61 -- In order to speed up the retrieval of the interpretations of an
62 -- overloaded node, the Interp_Map table is accessed by means of a simple
63 -- hashing scheme, and the entries in Interp_Map are chained. The heads
64 -- of clash lists are stored in array Headers.
66 -- Headers Interp_Map All_Interp
68 -- _ +-----+ +--------+
69 -- |_| |_____| --->|interp1 |
70 -- |_|---------->|node | | |interp2 |
71 -- |_| |index|---------| |nointerp|
76 -- This scheme does not currently reclaim interpretations. In principle,
77 -- after a unit is compiled, all overloadings have been resolved, and the
78 -- candidate interpretations should be deleted. This should be easier
79 -- now than with the previous scheme???
81 package All_Interp is new Table.Table (
82 Table_Component_Type => Interp,
83 Table_Index_Type => Int,
85 Table_Initial => Alloc.All_Interp_Initial,
86 Table_Increment => Alloc.All_Interp_Increment,
87 Table_Name => "All_Interp");
89 type Interp_Ref is record
95 Header_Size : constant Int := 2 ** 12;
96 No_Entry : constant Int := -1;
97 Headers : array (0 .. Header_Size) of Int := (others => No_Entry);
99 package Interp_Map is new Table.Table (
100 Table_Component_Type => Interp_Ref,
101 Table_Index_Type => Int,
102 Table_Low_Bound => 0,
103 Table_Initial => Alloc.Interp_Map_Initial,
104 Table_Increment => Alloc.Interp_Map_Increment,
105 Table_Name => "Interp_Map");
107 function Hash (N : Node_Id) return Int;
108 -- A trivial hashing function for nodes, used to insert an overloaded
109 -- node into the Interp_Map table.
111 -------------------------------------
112 -- Handling of Overload Resolution --
113 -------------------------------------
115 -- Overload resolution uses two passes over the syntax tree of a complete
116 -- context. In the first, bottom-up pass, the types of actuals in calls
117 -- are used to resolve possibly overloaded subprogram and operator names.
118 -- In the second top-down pass, the type of the context (for example the
119 -- condition in a while statement) is used to resolve a possibly ambiguous
120 -- call, and the unique subprogram name in turn imposes a specific context
121 -- on each of its actuals.
123 -- Most expressions are in fact unambiguous, and the bottom-up pass is
124 -- sufficient to resolve most everything. To simplify the common case,
125 -- names and expressions carry a flag Is_Overloaded to indicate whether
126 -- they have more than one interpretation. If the flag is off, then each
127 -- name has already a unique meaning and type, and the bottom-up pass is
128 -- sufficient (and much simpler).
130 --------------------------
131 -- Operator Overloading --
132 --------------------------
134 -- The visibility of operators is handled differently from that of
135 -- other entities. We do not introduce explicit versions of primitive
136 -- operators for each type definition. As a result, there is only one
137 -- entity corresponding to predefined addition on all numeric types, etc.
138 -- The back-end resolves predefined operators according to their type.
139 -- The visibility of primitive operations then reduces to the visibility
140 -- of the resulting type: (a + b) is a legal interpretation of some
141 -- primitive operator + if the type of the result (which must also be
142 -- the type of a and b) is directly visible (i.e. either immediately
143 -- visible or use-visible.)
145 -- User-defined operators are treated like other functions, but the
146 -- visibility of these user-defined operations must be special-cased
147 -- to determine whether they hide or are hidden by predefined operators.
148 -- The form P."+" (x, y) requires additional handling.
150 -- Concatenation is treated more conventionally: for every one-dimensional
151 -- array type we introduce a explicit concatenation operator. This is
152 -- necessary to handle the case of (element & element => array) which
153 -- cannot be handled conveniently if there is no explicit instance of
154 -- resulting type of the operation.
156 -----------------------
157 -- Local Subprograms --
158 -----------------------
160 procedure All_Overloads;
161 pragma Warnings (Off, All_Overloads);
162 -- Debugging procedure: list full contents of Overloads table
164 procedure New_Interps (N : Node_Id);
165 -- Initialize collection of interpretations for the given node, which is
166 -- either an overloaded entity, or an operation whose arguments have
167 -- multiple interpretations. Interpretations can be added to only one
170 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
171 -- If T1 and T2 are compatible, return the one that is not
172 -- universal or is not a "class" type (any_character, etc).
178 procedure Add_One_Interp
182 Opnd_Type : Entity_Id := Empty)
184 Vis_Type : Entity_Id;
186 procedure Add_Entry (Name : Entity_Id; Typ : Entity_Id);
187 -- Add one interpretation to node. Node is already known to be
188 -- overloaded. Add new interpretation if not hidden by previous
189 -- one, and remove previous one if hidden by new one.
191 function Is_Universal_Operation (Op : Entity_Id) return Boolean;
192 -- True if the entity is a predefined operator and the operands have
193 -- a universal Interpretation.
199 procedure Add_Entry (Name : Entity_Id; Typ : Entity_Id) is
200 Index : Interp_Index;
204 Get_First_Interp (N, Index, It);
205 while Present (It.Nam) loop
207 -- A user-defined subprogram hides another declared at an outer
208 -- level, or one that is use-visible. So return if previous
209 -- definition hides new one (which is either in an outer
210 -- scope, or use-visible). Note that for functions use-visible
211 -- is the same as potentially use-visible. If new one hides
212 -- previous one, replace entry in table of interpretations.
213 -- If this is a universal operation, retain the operator in case
214 -- preference rule applies.
216 if (((Ekind (Name) = E_Function or else Ekind (Name) = E_Procedure)
217 and then Ekind (Name) = Ekind (It.Nam))
218 or else (Ekind (Name) = E_Operator
219 and then Ekind (It.Nam) = E_Function))
221 and then Is_Immediately_Visible (It.Nam)
222 and then Type_Conformant (Name, It.Nam)
223 and then Base_Type (It.Typ) = Base_Type (T)
225 if Is_Universal_Operation (Name) then
228 -- If node is an operator symbol, we have no actuals with
229 -- which to check hiding, and this is done in full in the
230 -- caller (Analyze_Subprogram_Renaming) so we include the
231 -- predefined operator in any case.
233 elsif Nkind (N) = N_Operator_Symbol
234 or else (Nkind (N) = N_Expanded_Name
236 Nkind (Selector_Name (N)) = N_Operator_Symbol)
240 elsif not In_Open_Scopes (Scope (Name))
241 or else Scope_Depth (Scope (Name)) <=
242 Scope_Depth (Scope (It.Nam))
244 -- If ambiguity within instance, and entity is not an
245 -- implicit operation, save for later disambiguation.
247 if Scope (Name) = Scope (It.Nam)
248 and then not Is_Inherited_Operation (Name)
257 All_Interp.Table (Index).Nam := Name;
261 -- Avoid making duplicate entries in overloads
264 and then Base_Type (It.Typ) = Base_Type (T)
268 -- Otherwise keep going
271 Get_Next_Interp (Index, It);
276 -- On exit, enter new interpretation. The context, or a preference
277 -- rule, will resolve the ambiguity on the second pass.
279 All_Interp.Table (All_Interp.Last) := (Name, Typ);
280 All_Interp.Increment_Last;
281 All_Interp.Table (All_Interp.Last) := No_Interp;
284 ----------------------------
285 -- Is_Universal_Operation --
286 ----------------------------
288 function Is_Universal_Operation (Op : Entity_Id) return Boolean is
292 if Ekind (Op) /= E_Operator then
295 elsif Nkind (N) in N_Binary_Op then
296 return Present (Universal_Interpretation (Left_Opnd (N)))
297 and then Present (Universal_Interpretation (Right_Opnd (N)));
299 elsif Nkind (N) in N_Unary_Op then
300 return Present (Universal_Interpretation (Right_Opnd (N)));
302 elsif Nkind (N) = N_Function_Call then
303 Arg := First_Actual (N);
304 while Present (Arg) loop
305 if No (Universal_Interpretation (Arg)) then
317 end Is_Universal_Operation;
319 -- Start of processing for Add_One_Interp
322 -- If the interpretation is a predefined operator, verify that the
323 -- result type is visible, or that the entity has already been
324 -- resolved (case of an instantiation node that refers to a predefined
325 -- operation, or an internally generated operator node, or an operator
326 -- given as an expanded name). If the operator is a comparison or
327 -- equality, it is the type of the operand that matters to determine
328 -- whether the operator is visible. In an instance, the check is not
329 -- performed, given that the operator was visible in the generic.
331 if Ekind (E) = E_Operator then
333 if Present (Opnd_Type) then
334 Vis_Type := Opnd_Type;
336 Vis_Type := Base_Type (T);
339 if In_Open_Scopes (Scope (Vis_Type))
340 or else Is_Potentially_Use_Visible (Vis_Type)
341 or else In_Use (Vis_Type)
342 or else (In_Use (Scope (Vis_Type))
343 and then not Is_Hidden (Vis_Type))
344 or else Nkind (N) = N_Expanded_Name
345 or else (Nkind (N) in N_Op and then E = Entity (N))
350 -- If the node is given in functional notation and the prefix
351 -- is an expanded name, then the operator is visible if the
352 -- prefix is the scope of the result type as well. If the
353 -- operator is (implicitly) defined in an extension of system,
354 -- it is know to be valid (see Defined_In_Scope, sem_ch4.adb).
356 elsif Nkind (N) = N_Function_Call
357 and then Nkind (Name (N)) = N_Expanded_Name
358 and then (Entity (Prefix (Name (N))) = Scope (Base_Type (T))
359 or else Entity (Prefix (Name (N))) = Scope (Vis_Type)
360 or else Scope (Vis_Type) = System_Aux_Id)
364 -- Save type for subsequent error message, in case no other
365 -- interpretation is found.
368 Candidate_Type := Vis_Type;
372 -- In an instance, an abstract non-dispatching operation cannot
373 -- be a candidate interpretation, because it could not have been
374 -- one in the generic (it may be a spurious overloading in the
378 and then Is_Overloadable (E)
379 and then Is_Abstract_Subprogram (E)
380 and then not Is_Dispatching_Operation (E)
384 -- An inherited interface operation that is implemented by some
385 -- derived type does not participate in overload resolution, only
386 -- the implementation operation does.
389 and then Is_Subprogram (E)
390 and then Present (Abstract_Interface_Alias (E))
392 -- Ada 2005 (AI-251): If this primitive operation corresponds with
393 -- an inmediate ancestor interface there is no need to add it to the
394 -- list of interpretations; the corresponding aliased primitive is
395 -- also in this list of primitive operations and will be used instead
396 -- because otherwise we have a dummy between the two subprograms that
397 -- are in fact the same.
400 (Find_Dispatching_Type (Abstract_Interface_Alias (E)),
401 Find_Dispatching_Type (E))
403 Add_One_Interp (N, Abstract_Interface_Alias (E), T);
409 -- If this is the first interpretation of N, N has type Any_Type.
410 -- In that case place the new type on the node. If one interpretation
411 -- already exists, indicate that the node is overloaded, and store
412 -- both the previous and the new interpretation in All_Interp. If
413 -- this is a later interpretation, just add it to the set.
415 if Etype (N) = Any_Type then
420 -- Record both the operator or subprogram name, and its type
422 if Nkind (N) in N_Op or else Is_Entity_Name (N) then
429 -- Either there is no current interpretation in the table for any
430 -- node or the interpretation that is present is for a different
431 -- node. In both cases add a new interpretation to the table.
433 elsif Interp_Map.Last < 0
435 (Interp_Map.Table (Interp_Map.Last).Node /= N
436 and then not Is_Overloaded (N))
440 if (Nkind (N) in N_Op or else Is_Entity_Name (N))
441 and then Present (Entity (N))
443 Add_Entry (Entity (N), Etype (N));
445 elsif (Nkind (N) = N_Function_Call
446 or else Nkind (N) = N_Procedure_Call_Statement)
447 and then (Nkind (Name (N)) = N_Operator_Symbol
448 or else Is_Entity_Name (Name (N)))
450 Add_Entry (Entity (Name (N)), Etype (N));
452 -- If this is an indirect call there will be no name associated
453 -- with the previous entry. To make diagnostics clearer, save
454 -- Subprogram_Type of first interpretation, so that the error will
455 -- point to the anonymous access to subprogram, not to the result
456 -- type of the call itself.
458 elsif (Nkind (N)) = N_Function_Call
459 and then Nkind (Name (N)) = N_Explicit_Dereference
460 and then Is_Overloaded (Name (N))
466 Get_First_Interp (Name (N), I, It);
467 Add_Entry (It.Nam, Etype (N));
471 -- Overloaded prefix in indexed or selected component,
472 -- or call whose name is an expression or another call.
474 Add_Entry (Etype (N), Etype (N));
488 procedure All_Overloads is
490 for J in All_Interp.First .. All_Interp.Last loop
492 if Present (All_Interp.Table (J).Nam) then
493 Write_Entity_Info (All_Interp.Table (J). Nam, " ");
495 Write_Str ("No Interp");
498 Write_Str ("=================");
503 ---------------------
504 -- Collect_Interps --
505 ---------------------
507 procedure Collect_Interps (N : Node_Id) is
508 Ent : constant Entity_Id := Entity (N);
510 First_Interp : Interp_Index;
515 -- Unconditionally add the entity that was initially matched
517 First_Interp := All_Interp.Last;
518 Add_One_Interp (N, Ent, Etype (N));
520 -- For expanded name, pick up all additional entities from the
521 -- same scope, since these are obviously also visible. Note that
522 -- these are not necessarily contiguous on the homonym chain.
524 if Nkind (N) = N_Expanded_Name then
526 while Present (H) loop
527 if Scope (H) = Scope (Entity (N)) then
528 Add_One_Interp (N, H, Etype (H));
534 -- Case of direct name
537 -- First, search the homonym chain for directly visible entities
539 H := Current_Entity (Ent);
540 while Present (H) loop
541 exit when (not Is_Overloadable (H))
542 and then Is_Immediately_Visible (H);
544 if Is_Immediately_Visible (H)
547 -- Only add interpretation if not hidden by an inner
548 -- immediately visible one.
550 for J in First_Interp .. All_Interp.Last - 1 loop
552 -- Current homograph is not hidden. Add to overloads
554 if not Is_Immediately_Visible (All_Interp.Table (J).Nam) then
557 -- Homograph is hidden, unless it is a predefined operator
559 elsif Type_Conformant (H, All_Interp.Table (J).Nam) then
561 -- A homograph in the same scope can occur within an
562 -- instantiation, the resulting ambiguity has to be
565 if Scope (H) = Scope (Ent)
567 and then not Is_Inherited_Operation (H)
569 All_Interp.Table (All_Interp.Last) := (H, Etype (H));
570 All_Interp.Increment_Last;
571 All_Interp.Table (All_Interp.Last) := No_Interp;
574 elsif Scope (H) /= Standard_Standard then
580 -- On exit, we know that current homograph is not hidden
582 Add_One_Interp (N, H, Etype (H));
585 Write_Str ("Add overloaded Interpretation ");
595 -- Scan list of homographs for use-visible entities only
597 H := Current_Entity (Ent);
599 while Present (H) loop
600 if Is_Potentially_Use_Visible (H)
602 and then Is_Overloadable (H)
604 for J in First_Interp .. All_Interp.Last - 1 loop
606 if not Is_Immediately_Visible (All_Interp.Table (J).Nam) then
609 elsif Type_Conformant (H, All_Interp.Table (J).Nam) then
610 goto Next_Use_Homograph;
614 Add_One_Interp (N, H, Etype (H));
617 <<Next_Use_Homograph>>
622 if All_Interp.Last = First_Interp + 1 then
624 -- The original interpretation is in fact not overloaded
626 Set_Is_Overloaded (N, False);
634 function Covers (T1, T2 : Entity_Id) return Boolean is
639 function Full_View_Covers (Typ1, Typ2 : Entity_Id) return Boolean;
640 -- In an instance the proper view may not always be correct for
641 -- private types, but private and full view are compatible. This
642 -- removes spurious errors from nested instantiations that involve,
643 -- among other things, types derived from private types.
645 ----------------------
646 -- Full_View_Covers --
647 ----------------------
649 function Full_View_Covers (Typ1, Typ2 : Entity_Id) return Boolean is
652 Is_Private_Type (Typ1)
654 ((Present (Full_View (Typ1))
655 and then Covers (Full_View (Typ1), Typ2))
656 or else Base_Type (Typ1) = Typ2
657 or else Base_Type (Typ2) = Typ1);
658 end Full_View_Covers;
660 -- Start of processing for Covers
663 -- If either operand missing, then this is an error, but ignore it (and
664 -- pretend we have a cover) if errors already detected, since this may
665 -- simply mean we have malformed trees.
667 if No (T1) or else No (T2) then
668 if Total_Errors_Detected /= 0 then
675 BT1 := Base_Type (T1);
676 BT2 := Base_Type (T2);
679 -- Simplest case: same types are compatible, and types that have the
680 -- same base type and are not generic actuals are compatible. Generic
681 -- actuals belong to their class but are not compatible with other
682 -- types of their class, and in particular with other generic actuals.
683 -- They are however compatible with their own subtypes, and itypes
684 -- with the same base are compatible as well. Similarly, constrained
685 -- subtypes obtained from expressions of an unconstrained nominal type
686 -- are compatible with the base type (may lead to spurious ambiguities
687 -- in obscure cases ???)
689 -- Generic actuals require special treatment to avoid spurious ambi-
690 -- guities in an instance, when two formal types are instantiated with
691 -- the same actual, so that different subprograms end up with the same
692 -- signature in the instance.
701 if not Is_Generic_Actual_Type (T1) then
704 return (not Is_Generic_Actual_Type (T2)
705 or else Is_Itype (T1)
706 or else Is_Itype (T2)
707 or else Is_Constr_Subt_For_U_Nominal (T1)
708 or else Is_Constr_Subt_For_U_Nominal (T2)
709 or else Scope (T1) /= Scope (T2));
712 -- Literals are compatible with types in a given "class"
714 elsif (T2 = Universal_Integer and then Is_Integer_Type (T1))
715 or else (T2 = Universal_Real and then Is_Real_Type (T1))
716 or else (T2 = Universal_Fixed and then Is_Fixed_Point_Type (T1))
717 or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1))
718 or else (T2 = Any_String and then Is_String_Type (T1))
719 or else (T2 = Any_Character and then Is_Character_Type (T1))
720 or else (T2 = Any_Access and then Is_Access_Type (T1))
724 -- The context may be class wide
726 elsif Is_Class_Wide_Type (T1)
727 and then Is_Ancestor (Root_Type (T1), T2)
731 elsif Is_Class_Wide_Type (T1)
732 and then Is_Class_Wide_Type (T2)
733 and then Base_Type (Etype (T1)) = Base_Type (Etype (T2))
737 -- Ada 2005 (AI-345): A class-wide abstract interface type T1 covers a
738 -- task_type or protected_type implementing T1
740 elsif Ada_Version >= Ada_05
741 and then Is_Class_Wide_Type (T1)
742 and then Is_Interface (Etype (T1))
743 and then Is_Concurrent_Type (T2)
744 and then Interface_Present_In_Ancestor
745 (Typ => Base_Type (T2),
750 -- Ada 2005 (AI-251): A class-wide abstract interface type T1 covers an
751 -- object T2 implementing T1
753 elsif Ada_Version >= Ada_05
754 and then Is_Class_Wide_Type (T1)
755 and then Is_Interface (Etype (T1))
756 and then Is_Tagged_Type (T2)
758 if Interface_Present_In_Ancestor (Typ => T2,
769 if Is_Concurrent_Type (BT2) then
770 E := Corresponding_Record_Type (BT2);
775 -- Ada 2005 (AI-251): A class-wide abstract interface type T1
776 -- covers an object T2 that implements a direct derivation of T1.
777 -- Note: test for presence of E is defense against previous error.
780 and then Present (Abstract_Interfaces (E))
782 Elmt := First_Elmt (Abstract_Interfaces (E));
783 while Present (Elmt) loop
784 if Is_Ancestor (Etype (T1), Node (Elmt)) then
792 -- We should also check the case in which T1 is an ancestor of
793 -- some implemented interface???
798 -- In a dispatching call the actual may be class-wide
800 elsif Is_Class_Wide_Type (T2)
801 and then Base_Type (Root_Type (T2)) = Base_Type (T1)
805 -- Some contexts require a class of types rather than a specific type
807 elsif (T1 = Any_Integer and then Is_Integer_Type (T2))
808 or else (T1 = Any_Boolean and then Is_Boolean_Type (T2))
809 or else (T1 = Any_Real and then Is_Real_Type (T2))
810 or else (T1 = Any_Fixed and then Is_Fixed_Point_Type (T2))
811 or else (T1 = Any_Discrete and then Is_Discrete_Type (T2))
815 -- An aggregate is compatible with an array or record type
817 elsif T2 = Any_Composite
818 and then Ekind (T1) in E_Array_Type .. E_Record_Subtype
822 -- If the expected type is an anonymous access, the designated type must
823 -- cover that of the expression.
825 elsif Ekind (T1) = E_Anonymous_Access_Type
826 and then Is_Access_Type (T2)
827 and then Covers (Designated_Type (T1), Designated_Type (T2))
831 -- An Access_To_Subprogram is compatible with itself, or with an
832 -- anonymous type created for an attribute reference Access.
834 elsif (Ekind (BT1) = E_Access_Subprogram_Type
836 Ekind (BT1) = E_Access_Protected_Subprogram_Type)
837 and then Is_Access_Type (T2)
838 and then (not Comes_From_Source (T1)
839 or else not Comes_From_Source (T2))
840 and then (Is_Overloadable (Designated_Type (T2))
842 Ekind (Designated_Type (T2)) = E_Subprogram_Type)
844 Type_Conformant (Designated_Type (T1), Designated_Type (T2))
846 Mode_Conformant (Designated_Type (T1), Designated_Type (T2))
850 -- Ada 2005 (AI-254): An Anonymous_Access_To_Subprogram is compatible
851 -- with itself, or with an anonymous type created for an attribute
854 elsif (Ekind (BT1) = E_Anonymous_Access_Subprogram_Type
857 = E_Anonymous_Access_Protected_Subprogram_Type)
858 and then Is_Access_Type (T2)
859 and then (not Comes_From_Source (T1)
860 or else not Comes_From_Source (T2))
861 and then (Is_Overloadable (Designated_Type (T2))
863 Ekind (Designated_Type (T2)) = E_Subprogram_Type)
865 Type_Conformant (Designated_Type (T1), Designated_Type (T2))
867 Mode_Conformant (Designated_Type (T1), Designated_Type (T2))
871 -- The context can be a remote access type, and the expression the
872 -- corresponding source type declared in a categorized package, or
875 elsif Is_Record_Type (T1)
876 and then (Is_Remote_Call_Interface (T1)
877 or else Is_Remote_Types (T1))
878 and then Present (Corresponding_Remote_Type (T1))
880 return Covers (Corresponding_Remote_Type (T1), T2);
882 elsif Is_Record_Type (T2)
883 and then (Is_Remote_Call_Interface (T2)
884 or else Is_Remote_Types (T2))
885 and then Present (Corresponding_Remote_Type (T2))
887 return Covers (Corresponding_Remote_Type (T2), T1);
889 elsif Ekind (T2) = E_Access_Attribute_Type
890 and then (Ekind (BT1) = E_General_Access_Type
891 or else Ekind (BT1) = E_Access_Type)
892 and then Covers (Designated_Type (T1), Designated_Type (T2))
894 -- If the target type is a RACW type while the source is an access
895 -- attribute type, we are building a RACW that may be exported.
897 if Is_Remote_Access_To_Class_Wide_Type (BT1) then
898 Set_Has_RACW (Current_Sem_Unit);
903 elsif Ekind (T2) = E_Allocator_Type
904 and then Is_Access_Type (T1)
906 return Covers (Designated_Type (T1), Designated_Type (T2))
908 (From_With_Type (Designated_Type (T1))
909 and then Covers (Designated_Type (T2), Designated_Type (T1)));
911 -- A boolean operation on integer literals is compatible with modular
914 elsif T2 = Any_Modular
915 and then Is_Modular_Integer_Type (T1)
919 -- The actual type may be the result of a previous error
921 elsif Base_Type (T2) = Any_Type then
924 -- A packed array type covers its corresponding non-packed type. This is
925 -- not legitimate Ada, but allows the omission of a number of otherwise
926 -- useless unchecked conversions, and since this can only arise in
927 -- (known correct) expanded code, no harm is done
929 elsif Is_Array_Type (T2)
930 and then Is_Packed (T2)
931 and then T1 = Packed_Array_Type (T2)
935 -- Similarly an array type covers its corresponding packed array type
937 elsif Is_Array_Type (T1)
938 and then Is_Packed (T1)
939 and then T2 = Packed_Array_Type (T1)
943 -- In instances, or with types exported from instantiations, check
944 -- whether a partial and a full view match. Verify that types are
945 -- legal, to prevent cascaded errors.
949 (Full_View_Covers (T1, T2)
950 or else Full_View_Covers (T2, T1))
955 and then Is_Generic_Actual_Type (T2)
956 and then Full_View_Covers (T1, T2)
961 and then Is_Generic_Actual_Type (T1)
962 and then Full_View_Covers (T2, T1)
966 -- In the expansion of inlined bodies, types are compatible if they
967 -- are structurally equivalent.
969 elsif In_Inlined_Body
970 and then (Underlying_Type (T1) = Underlying_Type (T2)
971 or else (Is_Access_Type (T1)
972 and then Is_Access_Type (T2)
974 Designated_Type (T1) = Designated_Type (T2))
975 or else (T1 = Any_Access
976 and then Is_Access_Type (Underlying_Type (T2)))
977 or else (T2 = Any_Composite
979 Is_Composite_Type (Underlying_Type (T1))))
983 -- Ada 2005 (AI-50217): Additional branches to make the shadow entity
984 -- compatible with its real entity.
986 elsif From_With_Type (T1) then
988 -- If the expected type is the non-limited view of a type, the
989 -- expression may have the limited view.
991 if Is_Incomplete_Type (T1) then
992 return Covers (Non_Limited_View (T1), T2);
994 elsif Ekind (T1) = E_Class_Wide_Type then
996 Covers (Class_Wide_Type (Non_Limited_View (Etype (T1))), T2);
1001 elsif From_With_Type (T2) then
1003 -- If units in the context have Limited_With clauses on each other,
1004 -- either type might have a limited view. Checks performed elsewhere
1005 -- verify that the context type is the non-limited view.
1007 if Is_Incomplete_Type (T2) then
1008 return Covers (T1, Non_Limited_View (T2));
1010 elsif Ekind (T2) = E_Class_Wide_Type then
1012 Present (Non_Limited_View (Etype (T2)))
1014 Covers (T1, Class_Wide_Type (Non_Limited_View (Etype (T2))));
1019 -- Ada 2005 (AI-412): Coverage for regular incomplete subtypes
1021 elsif Ekind (T1) = E_Incomplete_Subtype then
1022 return Covers (Full_View (Etype (T1)), T2);
1024 elsif Ekind (T2) = E_Incomplete_Subtype then
1025 return Covers (T1, Full_View (Etype (T2)));
1027 -- Ada 2005 (AI-423): Coverage of formal anonymous access types
1028 -- and actual anonymous access types in the context of generic
1029 -- instantiation. We have the following situation:
1032 -- type Formal is private;
1033 -- Formal_Obj : access Formal; -- T1
1037 -- type Actual is ...
1038 -- Actual_Obj : access Actual; -- T2
1039 -- package Instance is new G (Formal => Actual,
1040 -- Formal_Obj => Actual_Obj);
1042 elsif Ada_Version >= Ada_05
1043 and then Ekind (T1) = E_Anonymous_Access_Type
1044 and then Ekind (T2) = E_Anonymous_Access_Type
1045 and then Is_Generic_Type (Directly_Designated_Type (T1))
1046 and then Get_Instance_Of (Directly_Designated_Type (T1)) =
1047 Directly_Designated_Type (T2)
1051 -- Otherwise it doesn't cover!
1062 function Disambiguate
1064 I1, I2 : Interp_Index;
1071 Nam1, Nam2 : Entity_Id;
1072 Predef_Subp : Entity_Id;
1073 User_Subp : Entity_Id;
1075 function Inherited_From_Actual (S : Entity_Id) return Boolean;
1076 -- Determine whether one of the candidates is an operation inherited by
1077 -- a type that is derived from an actual in an instantiation.
1079 function In_Generic_Actual (Exp : Node_Id) return Boolean;
1080 -- Determine whether the expression is part of a generic actual. At
1081 -- the time the actual is resolved the scope is already that of the
1082 -- instance, but conceptually the resolution of the actual takes place
1083 -- in the enclosing context, and no special disambiguation rules should
1086 function Is_Actual_Subprogram (S : Entity_Id) return Boolean;
1087 -- Determine whether a subprogram is an actual in an enclosing instance.
1088 -- An overloading between such a subprogram and one declared outside the
1089 -- instance is resolved in favor of the first, because it resolved in
1092 function Matches (Actual, Formal : Node_Id) return Boolean;
1093 -- Look for exact type match in an instance, to remove spurious
1094 -- ambiguities when two formal types have the same actual.
1096 function Standard_Operator return Boolean;
1097 -- Check whether subprogram is predefined operator declared in Standard.
1098 -- It may given by an operator name, or by an expanded name whose prefix
1101 function Remove_Conversions return Interp;
1102 -- Last chance for pathological cases involving comparisons on literals,
1103 -- and user overloadings of the same operator. Such pathologies have
1104 -- been removed from the ACVC, but still appear in two DEC tests, with
1105 -- the following notable quote from Ben Brosgol:
1107 -- [Note: I disclaim all credit/responsibility/blame for coming up with
1108 -- this example; Robert Dewar brought it to our attention, since it is
1109 -- apparently found in the ACVC 1.5. I did not attempt to find the
1110 -- reason in the Reference Manual that makes the example legal, since I
1111 -- was too nauseated by it to want to pursue it further.]
1113 -- Accordingly, this is not a fully recursive solution, but it handles
1114 -- DEC tests c460vsa, c460vsb. It also handles ai00136a, which pushes
1115 -- pathology in the other direction with calls whose multiple overloaded
1116 -- actuals make them truly unresolvable.
1118 -- The new rules concerning abstract operations create additional need
1119 -- for special handling of expressions with universal operands, see
1120 -- comments to Has_Abstract_Interpretation below.
1122 ------------------------
1123 -- In_Generic_Actual --
1124 ------------------------
1126 function In_Generic_Actual (Exp : Node_Id) return Boolean is
1127 Par : constant Node_Id := Parent (Exp);
1133 elsif Nkind (Par) in N_Declaration then
1134 if Nkind (Par) = N_Object_Declaration
1135 or else Nkind (Par) = N_Object_Renaming_Declaration
1137 return Present (Corresponding_Generic_Association (Par));
1142 elsif Nkind (Par) in N_Statement_Other_Than_Procedure_Call then
1146 return In_Generic_Actual (Parent (Par));
1148 end In_Generic_Actual;
1150 ---------------------------
1151 -- Inherited_From_Actual --
1152 ---------------------------
1154 function Inherited_From_Actual (S : Entity_Id) return Boolean is
1155 Par : constant Node_Id := Parent (S);
1157 if Nkind (Par) /= N_Full_Type_Declaration
1158 or else Nkind (Type_Definition (Par)) /= N_Derived_Type_Definition
1162 return Is_Entity_Name (Subtype_Indication (Type_Definition (Par)))
1164 Is_Generic_Actual_Type (
1165 Entity (Subtype_Indication (Type_Definition (Par))));
1167 end Inherited_From_Actual;
1169 --------------------------
1170 -- Is_Actual_Subprogram --
1171 --------------------------
1173 function Is_Actual_Subprogram (S : Entity_Id) return Boolean is
1175 return In_Open_Scopes (Scope (S))
1177 (Is_Generic_Instance (Scope (S))
1178 or else Is_Wrapper_Package (Scope (S)));
1179 end Is_Actual_Subprogram;
1185 function Matches (Actual, Formal : Node_Id) return Boolean is
1186 T1 : constant Entity_Id := Etype (Actual);
1187 T2 : constant Entity_Id := Etype (Formal);
1191 (Is_Numeric_Type (T2)
1193 (T1 = Universal_Real or else T1 = Universal_Integer));
1196 ------------------------
1197 -- Remove_Conversions --
1198 ------------------------
1200 function Remove_Conversions return Interp is
1208 function Has_Abstract_Interpretation (N : Node_Id) return Boolean;
1209 -- If an operation has universal operands the universal operation
1210 -- is present among its interpretations. If there is an abstract
1211 -- interpretation for the operator, with a numeric result, this
1212 -- interpretation was already removed in sem_ch4, but the universal
1213 -- one is still visible. We must rescan the list of operators and
1214 -- remove the universal interpretation to resolve the ambiguity.
1216 ---------------------------------
1217 -- Has_Abstract_Interpretation --
1218 ---------------------------------
1220 function Has_Abstract_Interpretation (N : Node_Id) return Boolean is
1224 if Nkind (N) not in N_Op
1225 or else Ada_Version < Ada_05
1226 or else not Is_Overloaded (N)
1227 or else No (Universal_Interpretation (N))
1232 E := Get_Name_Entity_Id (Chars (N));
1233 while Present (E) loop
1234 if Is_Overloadable (E)
1235 and then Is_Abstract_Subprogram (E)
1236 and then Is_Numeric_Type (Etype (E))
1244 -- Finally, if an operand of the binary operator is itself
1245 -- an operator, recurse to see whether its own abstract
1246 -- interpretation is responsible for the spurious ambiguity.
1248 if Nkind (N) in N_Binary_Op then
1249 return Has_Abstract_Interpretation (Left_Opnd (N))
1250 or else Has_Abstract_Interpretation (Right_Opnd (N));
1252 elsif Nkind (N) in N_Unary_Op then
1253 return Has_Abstract_Interpretation (Right_Opnd (N));
1259 end Has_Abstract_Interpretation;
1261 -- Start of processing for Remove_Conversions
1266 Get_First_Interp (N, I, It);
1267 while Present (It.Typ) loop
1268 if not Is_Overloadable (It.Nam) then
1272 F1 := First_Formal (It.Nam);
1278 if Nkind (N) = N_Function_Call
1279 or else Nkind (N) = N_Procedure_Call_Statement
1281 Act1 := First_Actual (N);
1283 if Present (Act1) then
1284 Act2 := Next_Actual (Act1);
1289 elsif Nkind (N) in N_Unary_Op then
1290 Act1 := Right_Opnd (N);
1293 elsif Nkind (N) in N_Binary_Op then
1294 Act1 := Left_Opnd (N);
1295 Act2 := Right_Opnd (N);
1297 -- Use type of second formal, so as to include
1298 -- exponentiation, where the exponent may be
1299 -- ambiguous and the result non-universal.
1307 if Nkind (Act1) in N_Op
1308 and then Is_Overloaded (Act1)
1309 and then (Nkind (Right_Opnd (Act1)) = N_Integer_Literal
1310 or else Nkind (Right_Opnd (Act1)) = N_Real_Literal)
1311 and then Has_Compatible_Type (Act1, Standard_Boolean)
1312 and then Etype (F1) = Standard_Boolean
1314 -- If the two candidates are the original ones, the
1315 -- ambiguity is real. Otherwise keep the original, further
1316 -- calls to Disambiguate will take care of others in the
1317 -- list of candidates.
1319 if It1 /= No_Interp then
1320 if It = Disambiguate.It1
1321 or else It = Disambiguate.It2
1323 if It1 = Disambiguate.It1
1324 or else It1 = Disambiguate.It2
1332 elsif Present (Act2)
1333 and then Nkind (Act2) in N_Op
1334 and then Is_Overloaded (Act2)
1335 and then (Nkind (Right_Opnd (Act1)) = N_Integer_Literal
1337 Nkind (Right_Opnd (Act1)) = N_Real_Literal)
1338 and then Has_Compatible_Type (Act2, Standard_Boolean)
1340 -- The preference rule on the first actual is not
1341 -- sufficient to disambiguate.
1349 elsif Is_Numeric_Type (Etype (F1))
1351 (Has_Abstract_Interpretation (Act1)
1352 or else Has_Abstract_Interpretation (Act2))
1354 if It = Disambiguate.It1 then
1355 return Disambiguate.It2;
1356 elsif It = Disambiguate.It2 then
1357 return Disambiguate.It1;
1363 Get_Next_Interp (I, It);
1366 -- After some error, a formal may have Any_Type and yield a spurious
1367 -- match. To avoid cascaded errors if possible, check for such a
1368 -- formal in either candidate.
1370 if Serious_Errors_Detected > 0 then
1375 Formal := First_Formal (Nam1);
1376 while Present (Formal) loop
1377 if Etype (Formal) = Any_Type then
1378 return Disambiguate.It2;
1381 Next_Formal (Formal);
1384 Formal := First_Formal (Nam2);
1385 while Present (Formal) loop
1386 if Etype (Formal) = Any_Type then
1387 return Disambiguate.It1;
1390 Next_Formal (Formal);
1396 end Remove_Conversions;
1398 -----------------------
1399 -- Standard_Operator --
1400 -----------------------
1402 function Standard_Operator return Boolean is
1406 if Nkind (N) in N_Op then
1409 elsif Nkind (N) = N_Function_Call then
1412 if Nkind (Nam) /= N_Expanded_Name then
1415 return Entity (Prefix (Nam)) = Standard_Standard;
1420 end Standard_Operator;
1422 -- Start of processing for Disambiguate
1425 -- Recover the two legal interpretations
1427 Get_First_Interp (N, I, It);
1429 Get_Next_Interp (I, It);
1435 Get_Next_Interp (I, It);
1441 if Ada_Version < Ada_05 then
1443 -- Check whether one of the entities is an Ada 2005 entity and we are
1444 -- operating in an earlier mode, in which case we discard the Ada
1445 -- 2005 entity, so that we get proper Ada 95 overload resolution.
1447 if Is_Ada_2005_Only (Nam1) then
1449 elsif Is_Ada_2005_Only (Nam2) then
1454 -- If the context is universal, the predefined operator is preferred.
1455 -- This includes bounds in numeric type declarations, and expressions
1456 -- in type conversions. If no interpretation yields a universal type,
1457 -- then we must check whether the user-defined entity hides the prede-
1460 if Chars (Nam1) in Any_Operator_Name
1461 and then Standard_Operator
1463 if Typ = Universal_Integer
1464 or else Typ = Universal_Real
1465 or else Typ = Any_Integer
1466 or else Typ = Any_Discrete
1467 or else Typ = Any_Real
1468 or else Typ = Any_Type
1470 -- Find an interpretation that yields the universal type, or else
1471 -- a predefined operator that yields a predefined numeric type.
1474 Candidate : Interp := No_Interp;
1477 Get_First_Interp (N, I, It);
1478 while Present (It.Typ) loop
1479 if (Covers (Typ, It.Typ)
1480 or else Typ = Any_Type)
1482 (It.Typ = Universal_Integer
1483 or else It.Typ = Universal_Real)
1487 elsif Covers (Typ, It.Typ)
1488 and then Scope (It.Typ) = Standard_Standard
1489 and then Scope (It.Nam) = Standard_Standard
1490 and then Is_Numeric_Type (It.Typ)
1495 Get_Next_Interp (I, It);
1498 if Candidate /= No_Interp then
1503 elsif Chars (Nam1) /= Name_Op_Not
1504 and then (Typ = Standard_Boolean or else Typ = Any_Boolean)
1506 -- Equality or comparison operation. Choose predefined operator if
1507 -- arguments are universal. The node may be an operator, name, or
1508 -- a function call, so unpack arguments accordingly.
1511 Arg1, Arg2 : Node_Id;
1514 if Nkind (N) in N_Op then
1515 Arg1 := Left_Opnd (N);
1516 Arg2 := Right_Opnd (N);
1518 elsif Is_Entity_Name (N)
1519 or else Nkind (N) = N_Operator_Symbol
1521 Arg1 := First_Entity (Entity (N));
1522 Arg2 := Next_Entity (Arg1);
1525 Arg1 := First_Actual (N);
1526 Arg2 := Next_Actual (Arg1);
1530 and then Present (Universal_Interpretation (Arg1))
1531 and then Universal_Interpretation (Arg2) =
1532 Universal_Interpretation (Arg1)
1534 Get_First_Interp (N, I, It);
1535 while Scope (It.Nam) /= Standard_Standard loop
1536 Get_Next_Interp (I, It);
1545 -- If no universal interpretation, check whether user-defined operator
1546 -- hides predefined one, as well as other special cases. If the node
1547 -- is a range, then one or both bounds are ambiguous. Each will have
1548 -- to be disambiguated w.r.t. the context type. The type of the range
1549 -- itself is imposed by the context, so we can return either legal
1552 if Ekind (Nam1) = E_Operator then
1553 Predef_Subp := Nam1;
1556 elsif Ekind (Nam2) = E_Operator then
1557 Predef_Subp := Nam2;
1560 elsif Nkind (N) = N_Range then
1563 -- If two user defined-subprograms are visible, it is a true ambiguity,
1564 -- unless one of them is an entry and the context is a conditional or
1565 -- timed entry call, or unless we are within an instance and this is
1566 -- results from two formals types with the same actual.
1569 if Nkind (N) = N_Procedure_Call_Statement
1570 and then Nkind (Parent (N)) = N_Entry_Call_Alternative
1571 and then N = Entry_Call_Statement (Parent (N))
1573 if Ekind (Nam2) = E_Entry then
1575 elsif Ekind (Nam1) = E_Entry then
1581 -- If the ambiguity occurs within an instance, it is due to several
1582 -- formal types with the same actual. Look for an exact match between
1583 -- the types of the formals of the overloadable entities, and the
1584 -- actuals in the call, to recover the unambiguous match in the
1585 -- original generic.
1587 -- The ambiguity can also be due to an overloading between a formal
1588 -- subprogram and a subprogram declared outside the generic. If the
1589 -- node is overloaded, it did not resolve to the global entity in
1590 -- the generic, and we choose the formal subprogram.
1592 -- Finally, the ambiguity can be between an explicit subprogram and
1593 -- one inherited (with different defaults) from an actual. In this
1594 -- case the resolution was to the explicit declaration in the
1595 -- generic, and remains so in the instance.
1598 and then not In_Generic_Actual (N)
1600 if Nkind (N) = N_Function_Call
1601 or else Nkind (N) = N_Procedure_Call_Statement
1606 Is_Act1 : constant Boolean := Is_Actual_Subprogram (Nam1);
1607 Is_Act2 : constant Boolean := Is_Actual_Subprogram (Nam2);
1610 if Is_Act1 and then not Is_Act2 then
1613 elsif Is_Act2 and then not Is_Act1 then
1616 elsif Inherited_From_Actual (Nam1)
1617 and then Comes_From_Source (Nam2)
1621 elsif Inherited_From_Actual (Nam2)
1622 and then Comes_From_Source (Nam1)
1627 Actual := First_Actual (N);
1628 Formal := First_Formal (Nam1);
1629 while Present (Actual) loop
1630 if Etype (Actual) /= Etype (Formal) then
1634 Next_Actual (Actual);
1635 Next_Formal (Formal);
1641 elsif Nkind (N) in N_Binary_Op then
1642 if Matches (Left_Opnd (N), First_Formal (Nam1))
1644 Matches (Right_Opnd (N), Next_Formal (First_Formal (Nam1)))
1651 elsif Nkind (N) in N_Unary_Op then
1652 if Etype (Right_Opnd (N)) = Etype (First_Formal (Nam1)) then
1659 return Remove_Conversions;
1662 return Remove_Conversions;
1666 -- an implicit concatenation operator on a string type cannot be
1667 -- disambiguated from the predefined concatenation. This can only
1668 -- happen with concatenation of string literals.
1670 if Chars (User_Subp) = Name_Op_Concat
1671 and then Ekind (User_Subp) = E_Operator
1672 and then Is_String_Type (Etype (First_Formal (User_Subp)))
1676 -- If the user-defined operator is in an open scope, or in the scope
1677 -- of the resulting type, or given by an expanded name that names its
1678 -- scope, it hides the predefined operator for the type. Exponentiation
1679 -- has to be special-cased because the implicit operator does not have
1680 -- a symmetric signature, and may not be hidden by the explicit one.
1682 elsif (Nkind (N) = N_Function_Call
1683 and then Nkind (Name (N)) = N_Expanded_Name
1684 and then (Chars (Predef_Subp) /= Name_Op_Expon
1685 or else Hides_Op (User_Subp, Predef_Subp))
1686 and then Scope (User_Subp) = Entity (Prefix (Name (N))))
1687 or else Hides_Op (User_Subp, Predef_Subp)
1689 if It1.Nam = User_Subp then
1695 -- Otherwise, the predefined operator has precedence, or if the user-
1696 -- defined operation is directly visible we have a true ambiguity. If
1697 -- this is a fixed-point multiplication and division in Ada83 mode,
1698 -- exclude the universal_fixed operator, which often causes ambiguities
1702 if (In_Open_Scopes (Scope (User_Subp))
1703 or else Is_Potentially_Use_Visible (User_Subp))
1704 and then not In_Instance
1706 if Is_Fixed_Point_Type (Typ)
1707 and then (Chars (Nam1) = Name_Op_Multiply
1708 or else Chars (Nam1) = Name_Op_Divide)
1709 and then Ada_Version = Ada_83
1711 if It2.Nam = Predef_Subp then
1717 -- Ada 2005, AI-420: preference rule for "=" on Universal_Access
1718 -- states that the operator defined in Standard is not available
1719 -- if there is a user-defined equality with the proper signature,
1720 -- declared in the same declarative list as the type. The node
1721 -- may be an operator or a function call.
1723 elsif (Chars (Nam1) = Name_Op_Eq
1725 Chars (Nam1) = Name_Op_Ne)
1726 and then Ada_Version >= Ada_05
1727 and then Etype (User_Subp) = Standard_Boolean
1732 if Nkind (N) = N_Function_Call then
1733 Opnd := First_Actual (N);
1735 Opnd := Left_Opnd (N);
1738 if Ekind (Etype (Opnd)) = E_Anonymous_Access_Type
1740 List_Containing (Parent (Designated_Type (Etype (Opnd))))
1741 = List_Containing (Unit_Declaration_Node (User_Subp))
1743 if It2.Nam = Predef_Subp then
1749 return Remove_Conversions;
1757 elsif It1.Nam = Predef_Subp then
1766 ---------------------
1767 -- End_Interp_List --
1768 ---------------------
1770 procedure End_Interp_List is
1772 All_Interp.Table (All_Interp.Last) := No_Interp;
1773 All_Interp.Increment_Last;
1774 end End_Interp_List;
1776 -------------------------
1777 -- Entity_Matches_Spec --
1778 -------------------------
1780 function Entity_Matches_Spec (Old_S, New_S : Entity_Id) return Boolean is
1782 -- Simple case: same entity kinds, type conformance is required. A
1783 -- parameterless function can also rename a literal.
1785 if Ekind (Old_S) = Ekind (New_S)
1786 or else (Ekind (New_S) = E_Function
1787 and then Ekind (Old_S) = E_Enumeration_Literal)
1789 return Type_Conformant (New_S, Old_S);
1791 elsif Ekind (New_S) = E_Function
1792 and then Ekind (Old_S) = E_Operator
1794 return Operator_Matches_Spec (Old_S, New_S);
1796 elsif Ekind (New_S) = E_Procedure
1797 and then Is_Entry (Old_S)
1799 return Type_Conformant (New_S, Old_S);
1804 end Entity_Matches_Spec;
1806 ----------------------
1807 -- Find_Unique_Type --
1808 ----------------------
1810 function Find_Unique_Type (L : Node_Id; R : Node_Id) return Entity_Id is
1811 T : constant Entity_Id := Etype (L);
1814 TR : Entity_Id := Any_Type;
1817 if Is_Overloaded (R) then
1818 Get_First_Interp (R, I, It);
1819 while Present (It.Typ) loop
1820 if Covers (T, It.Typ) or else Covers (It.Typ, T) then
1822 -- If several interpretations are possible and L is universal,
1823 -- apply preference rule.
1825 if TR /= Any_Type then
1827 if (T = Universal_Integer or else T = Universal_Real)
1838 Get_Next_Interp (I, It);
1843 -- In the non-overloaded case, the Etype of R is already set correctly
1849 -- If one of the operands is Universal_Fixed, the type of the other
1850 -- operand provides the context.
1852 if Etype (R) = Universal_Fixed then
1855 elsif T = Universal_Fixed then
1858 -- Ada 2005 (AI-230): Support the following operators:
1860 -- function "=" (L, R : universal_access) return Boolean;
1861 -- function "/=" (L, R : universal_access) return Boolean;
1863 -- Pool specific access types (E_Access_Type) are not covered by these
1864 -- operators because of the legality rule of 4.5.2(9.2): "The operands
1865 -- of the equality operators for universal_access shall be convertible
1866 -- to one another (see 4.6)". For example, considering the type decla-
1867 -- ration "type P is access Integer" and an anonymous access to Integer,
1868 -- P is convertible to "access Integer" by 4.6 (24.11-24.15), but there
1869 -- is no rule in 4.6 that allows "access Integer" to be converted to P.
1871 elsif Ada_Version >= Ada_05
1872 and then Ekind (Etype (L)) = E_Anonymous_Access_Type
1873 and then Is_Access_Type (Etype (R))
1874 and then Ekind (Etype (R)) /= E_Access_Type
1878 elsif Ada_Version >= Ada_05
1879 and then Ekind (Etype (R)) = E_Anonymous_Access_Type
1880 and then Is_Access_Type (Etype (L))
1881 and then Ekind (Etype (L)) /= E_Access_Type
1886 return Specific_Type (T, Etype (R));
1889 end Find_Unique_Type;
1891 ----------------------
1892 -- Get_First_Interp --
1893 ----------------------
1895 procedure Get_First_Interp
1897 I : out Interp_Index;
1901 Int_Ind : Interp_Index;
1905 -- If a selected component is overloaded because the selector has
1906 -- multiple interpretations, the node is a call to a protected
1907 -- operation or an indirect call. Retrieve the interpretation from
1908 -- the selector name. The selected component may be overloaded as well
1909 -- if the prefix is overloaded. That case is unchanged.
1911 if Nkind (N) = N_Selected_Component
1912 and then Is_Overloaded (Selector_Name (N))
1914 O_N := Selector_Name (N);
1919 Map_Ptr := Headers (Hash (O_N));
1920 while Present (Interp_Map.Table (Map_Ptr).Node) loop
1921 if Interp_Map.Table (Map_Ptr).Node = O_N then
1922 Int_Ind := Interp_Map.Table (Map_Ptr).Index;
1923 It := All_Interp.Table (Int_Ind);
1927 Map_Ptr := Interp_Map.Table (Map_Ptr).Next;
1931 -- Procedure should never be called if the node has no interpretations
1933 raise Program_Error;
1934 end Get_First_Interp;
1936 ---------------------
1937 -- Get_Next_Interp --
1938 ---------------------
1940 procedure Get_Next_Interp (I : in out Interp_Index; It : out Interp) is
1943 It := All_Interp.Table (I);
1944 end Get_Next_Interp;
1946 -------------------------
1947 -- Has_Compatible_Type --
1948 -------------------------
1950 function Has_Compatible_Type
1963 if Nkind (N) = N_Subtype_Indication
1964 or else not Is_Overloaded (N)
1967 Covers (Typ, Etype (N))
1969 -- Ada 2005 (AI-345) The context may be a synchronized interface.
1970 -- If the type is already frozen use the corresponding_record
1971 -- to check whether it is a proper descendant.
1974 (Is_Concurrent_Type (Etype (N))
1975 and then Present (Corresponding_Record_Type (Etype (N)))
1976 and then Covers (Typ, Corresponding_Record_Type (Etype (N))))
1979 (not Is_Tagged_Type (Typ)
1980 and then Ekind (Typ) /= E_Anonymous_Access_Type
1981 and then Covers (Etype (N), Typ));
1984 Get_First_Interp (N, I, It);
1985 while Present (It.Typ) loop
1986 if (Covers (Typ, It.Typ)
1988 (Scope (It.Nam) /= Standard_Standard
1989 or else not Is_Invisible_Operator (N, Base_Type (Typ))))
1991 -- Ada 2005 (AI-345)
1994 (Is_Concurrent_Type (It.Typ)
1995 and then Present (Corresponding_Record_Type
1997 and then Covers (Typ, Corresponding_Record_Type
2000 or else (not Is_Tagged_Type (Typ)
2001 and then Ekind (Typ) /= E_Anonymous_Access_Type
2002 and then Covers (It.Typ, Typ))
2007 Get_Next_Interp (I, It);
2012 end Has_Compatible_Type;
2018 function Hash (N : Node_Id) return Int is
2020 -- Nodes have a size that is power of two, so to select significant
2021 -- bits only we remove the low-order bits.
2023 return ((Int (N) / 2 ** 5) mod Header_Size);
2030 function Hides_Op (F : Entity_Id; Op : Entity_Id) return Boolean is
2031 Btyp : constant Entity_Id := Base_Type (Etype (First_Formal (F)));
2033 return Operator_Matches_Spec (Op, F)
2034 and then (In_Open_Scopes (Scope (F))
2035 or else Scope (F) = Scope (Btyp)
2036 or else (not In_Open_Scopes (Scope (Btyp))
2037 and then not In_Use (Btyp)
2038 and then not In_Use (Scope (Btyp))));
2041 ------------------------
2042 -- Init_Interp_Tables --
2043 ------------------------
2045 procedure Init_Interp_Tables is
2049 Headers := (others => No_Entry);
2050 end Init_Interp_Tables;
2052 -----------------------------------
2053 -- Interface_Present_In_Ancestor --
2054 -----------------------------------
2056 function Interface_Present_In_Ancestor
2058 Iface : Entity_Id) return Boolean
2060 Target_Typ : Entity_Id;
2062 function Iface_Present_In_Ancestor (Typ : Entity_Id) return Boolean;
2063 -- Returns True if Typ or some ancestor of Typ implements Iface
2065 function Iface_Present_In_Ancestor (Typ : Entity_Id) return Boolean is
2075 -- Handle private types
2077 if Present (Full_View (Typ))
2078 and then not Is_Concurrent_Type (Full_View (Typ))
2080 E := Full_View (Typ);
2086 if Present (Abstract_Interfaces (E))
2087 and then Present (Abstract_Interfaces (E))
2088 and then not Is_Empty_Elmt_List (Abstract_Interfaces (E))
2090 Elmt := First_Elmt (Abstract_Interfaces (E));
2091 while Present (Elmt) loop
2094 if AI = Iface or else Is_Ancestor (Iface, AI) then
2102 exit when Etype (E) = E
2104 -- Handle private types
2106 or else (Present (Full_View (Etype (E)))
2107 and then Full_View (Etype (E)) = E);
2109 -- Check if the current type is a direct derivation of the
2112 if Etype (E) = Iface then
2116 -- Climb to the immediate ancestor handling private types
2118 if Present (Full_View (Etype (E))) then
2119 E := Full_View (Etype (E));
2126 end Iface_Present_In_Ancestor;
2128 -- Start of processing for Interface_Present_In_Ancestor
2131 if Is_Access_Type (Typ) then
2132 Target_Typ := Etype (Directly_Designated_Type (Typ));
2137 if Is_Concurrent_Record_Type (Target_Typ) then
2138 Target_Typ := Corresponding_Concurrent_Type (Target_Typ);
2141 -- In case of concurrent types we can't use the Corresponding Record_Typ
2142 -- to look for the interface because it is built by the expander (and
2143 -- hence it is not always available). For this reason we traverse the
2144 -- list of interfaces (available in the parent of the concurrent type)
2146 if Is_Concurrent_Type (Target_Typ) then
2147 if Present (Interface_List (Parent (Base_Type (Target_Typ)))) then
2152 AI := First (Interface_List (Parent (Base_Type (Target_Typ))));
2153 while Present (AI) loop
2154 if Etype (AI) = Iface then
2157 elsif Present (Abstract_Interfaces (Etype (AI)))
2158 and then Iface_Present_In_Ancestor (Etype (AI))
2171 if Is_Class_Wide_Type (Target_Typ) then
2172 Target_Typ := Etype (Target_Typ);
2175 if Ekind (Target_Typ) = E_Incomplete_Type then
2176 pragma Assert (Present (Non_Limited_View (Target_Typ)));
2177 Target_Typ := Non_Limited_View (Target_Typ);
2179 -- Protect the frontend against previously detected errors
2181 if Ekind (Target_Typ) = E_Incomplete_Type then
2186 return Iface_Present_In_Ancestor (Target_Typ);
2187 end Interface_Present_In_Ancestor;
2189 ---------------------
2190 -- Intersect_Types --
2191 ---------------------
2193 function Intersect_Types (L, R : Node_Id) return Entity_Id is
2194 Index : Interp_Index;
2198 function Check_Right_Argument (T : Entity_Id) return Entity_Id;
2199 -- Find interpretation of right arg that has type compatible with T
2201 --------------------------
2202 -- Check_Right_Argument --
2203 --------------------------
2205 function Check_Right_Argument (T : Entity_Id) return Entity_Id is
2206 Index : Interp_Index;
2211 if not Is_Overloaded (R) then
2212 return Specific_Type (T, Etype (R));
2215 Get_First_Interp (R, Index, It);
2217 T2 := Specific_Type (T, It.Typ);
2219 if T2 /= Any_Type then
2223 Get_Next_Interp (Index, It);
2224 exit when No (It.Typ);
2229 end Check_Right_Argument;
2231 -- Start processing for Intersect_Types
2234 if Etype (L) = Any_Type or else Etype (R) = Any_Type then
2238 if not Is_Overloaded (L) then
2239 Typ := Check_Right_Argument (Etype (L));
2243 Get_First_Interp (L, Index, It);
2244 while Present (It.Typ) loop
2245 Typ := Check_Right_Argument (It.Typ);
2246 exit when Typ /= Any_Type;
2247 Get_Next_Interp (Index, It);
2252 -- If Typ is Any_Type, it means no compatible pair of types was found
2254 if Typ = Any_Type then
2255 if Nkind (Parent (L)) in N_Op then
2256 Error_Msg_N ("incompatible types for operator", Parent (L));
2258 elsif Nkind (Parent (L)) = N_Range then
2259 Error_Msg_N ("incompatible types given in constraint", Parent (L));
2261 -- Ada 2005 (AI-251): Complete the error notification
2263 elsif Is_Class_Wide_Type (Etype (R))
2264 and then Is_Interface (Etype (Class_Wide_Type (Etype (R))))
2266 Error_Msg_NE ("(Ada 2005) does not implement interface }",
2267 L, Etype (Class_Wide_Type (Etype (R))));
2270 Error_Msg_N ("incompatible types", Parent (L));
2275 end Intersect_Types;
2281 function Is_Ancestor (T1, T2 : Entity_Id) return Boolean is
2285 if Base_Type (T1) = Base_Type (T2) then
2288 elsif Is_Private_Type (T1)
2289 and then Present (Full_View (T1))
2290 and then Base_Type (T2) = Base_Type (Full_View (T1))
2298 -- If there was a error on the type declaration, do not recurse
2300 if Error_Posted (Par) then
2303 elsif Base_Type (T1) = Base_Type (Par)
2304 or else (Is_Private_Type (T1)
2305 and then Present (Full_View (T1))
2306 and then Base_Type (Par) = Base_Type (Full_View (T1)))
2310 elsif Is_Private_Type (Par)
2311 and then Present (Full_View (Par))
2312 and then Full_View (Par) = Base_Type (T1)
2316 elsif Etype (Par) /= Par then
2325 ---------------------------
2326 -- Is_Invisible_Operator --
2327 ---------------------------
2329 function Is_Invisible_Operator
2334 Orig_Node : constant Node_Id := Original_Node (N);
2337 if Nkind (N) not in N_Op then
2340 elsif not Comes_From_Source (N) then
2343 elsif No (Universal_Interpretation (Right_Opnd (N))) then
2346 elsif Nkind (N) in N_Binary_Op
2347 and then No (Universal_Interpretation (Left_Opnd (N)))
2353 and then not In_Open_Scopes (Scope (T))
2354 and then not Is_Potentially_Use_Visible (T)
2355 and then not In_Use (T)
2356 and then not In_Use (Scope (T))
2358 (Nkind (Orig_Node) /= N_Function_Call
2359 or else Nkind (Name (Orig_Node)) /= N_Expanded_Name
2360 or else Entity (Prefix (Name (Orig_Node))) /= Scope (T))
2362 and then not In_Instance;
2364 end Is_Invisible_Operator;
2370 function Is_Subtype_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
2374 S := Ancestor_Subtype (T1);
2375 while Present (S) loop
2379 S := Ancestor_Subtype (S);
2390 procedure List_Interps (Nam : Node_Id; Err : Node_Id) is
2391 Index : Interp_Index;
2395 Get_First_Interp (Nam, Index, It);
2396 while Present (It.Nam) loop
2397 if Scope (It.Nam) = Standard_Standard
2398 and then Scope (It.Typ) /= Standard_Standard
2400 Error_Msg_Sloc := Sloc (Parent (It.Typ));
2401 Error_Msg_NE ("\\& (inherited) declared#!", Err, It.Nam);
2404 Error_Msg_Sloc := Sloc (It.Nam);
2405 Error_Msg_NE ("\\& declared#!", Err, It.Nam);
2408 Get_Next_Interp (Index, It);
2416 procedure New_Interps (N : Node_Id) is
2420 All_Interp.Increment_Last;
2421 All_Interp.Table (All_Interp.Last) := No_Interp;
2423 Map_Ptr := Headers (Hash (N));
2425 if Map_Ptr = No_Entry then
2427 -- Place new node at end of table
2429 Interp_Map.Increment_Last;
2430 Headers (Hash (N)) := Interp_Map.Last;
2433 -- Place node at end of chain, or locate its previous entry
2436 if Interp_Map.Table (Map_Ptr).Node = N then
2438 -- Node is already in the table, and is being rewritten.
2439 -- Start a new interp section, retain hash link.
2441 Interp_Map.Table (Map_Ptr).Node := N;
2442 Interp_Map.Table (Map_Ptr).Index := All_Interp.Last;
2443 Set_Is_Overloaded (N, True);
2447 exit when Interp_Map.Table (Map_Ptr).Next = No_Entry;
2448 Map_Ptr := Interp_Map.Table (Map_Ptr).Next;
2452 -- Chain the new node
2454 Interp_Map.Increment_Last;
2455 Interp_Map.Table (Map_Ptr).Next := Interp_Map.Last;
2458 Interp_Map.Table (Interp_Map.Last) := (N, All_Interp.Last, No_Entry);
2459 Set_Is_Overloaded (N, True);
2462 ---------------------------
2463 -- Operator_Matches_Spec --
2464 ---------------------------
2466 function Operator_Matches_Spec (Op, New_S : Entity_Id) return Boolean is
2467 Op_Name : constant Name_Id := Chars (Op);
2468 T : constant Entity_Id := Etype (New_S);
2476 -- To verify that a predefined operator matches a given signature,
2477 -- do a case analysis of the operator classes. Function can have one
2478 -- or two formals and must have the proper result type.
2480 New_F := First_Formal (New_S);
2481 Old_F := First_Formal (Op);
2483 while Present (New_F) and then Present (Old_F) loop
2485 Next_Formal (New_F);
2486 Next_Formal (Old_F);
2489 -- Definite mismatch if different number of parameters
2491 if Present (Old_F) or else Present (New_F) then
2497 T1 := Etype (First_Formal (New_S));
2499 if Op_Name = Name_Op_Subtract
2500 or else Op_Name = Name_Op_Add
2501 or else Op_Name = Name_Op_Abs
2503 return Base_Type (T1) = Base_Type (T)
2504 and then Is_Numeric_Type (T);
2506 elsif Op_Name = Name_Op_Not then
2507 return Base_Type (T1) = Base_Type (T)
2508 and then Valid_Boolean_Arg (Base_Type (T));
2517 T1 := Etype (First_Formal (New_S));
2518 T2 := Etype (Next_Formal (First_Formal (New_S)));
2520 if Op_Name = Name_Op_And or else Op_Name = Name_Op_Or
2521 or else Op_Name = Name_Op_Xor
2523 return Base_Type (T1) = Base_Type (T2)
2524 and then Base_Type (T1) = Base_Type (T)
2525 and then Valid_Boolean_Arg (Base_Type (T));
2527 elsif Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne then
2528 return Base_Type (T1) = Base_Type (T2)
2529 and then not Is_Limited_Type (T1)
2530 and then Is_Boolean_Type (T);
2532 elsif Op_Name = Name_Op_Lt or else Op_Name = Name_Op_Le
2533 or else Op_Name = Name_Op_Gt or else Op_Name = Name_Op_Ge
2535 return Base_Type (T1) = Base_Type (T2)
2536 and then Valid_Comparison_Arg (T1)
2537 and then Is_Boolean_Type (T);
2539 elsif Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
2540 return Base_Type (T1) = Base_Type (T2)
2541 and then Base_Type (T1) = Base_Type (T)
2542 and then Is_Numeric_Type (T);
2544 -- for division and multiplication, a user-defined function does
2545 -- not match the predefined universal_fixed operation, except in
2548 elsif Op_Name = Name_Op_Divide then
2549 return (Base_Type (T1) = Base_Type (T2)
2550 and then Base_Type (T1) = Base_Type (T)
2551 and then Is_Numeric_Type (T)
2552 and then (not Is_Fixed_Point_Type (T)
2553 or else Ada_Version = Ada_83))
2555 -- Mixed_Mode operations on fixed-point types
2557 or else (Base_Type (T1) = Base_Type (T)
2558 and then Base_Type (T2) = Base_Type (Standard_Integer)
2559 and then Is_Fixed_Point_Type (T))
2561 -- A user defined operator can also match (and hide) a mixed
2562 -- operation on universal literals.
2564 or else (Is_Integer_Type (T2)
2565 and then Is_Floating_Point_Type (T1)
2566 and then Base_Type (T1) = Base_Type (T));
2568 elsif Op_Name = Name_Op_Multiply then
2569 return (Base_Type (T1) = Base_Type (T2)
2570 and then Base_Type (T1) = Base_Type (T)
2571 and then Is_Numeric_Type (T)
2572 and then (not Is_Fixed_Point_Type (T)
2573 or else Ada_Version = Ada_83))
2575 -- Mixed_Mode operations on fixed-point types
2577 or else (Base_Type (T1) = Base_Type (T)
2578 and then Base_Type (T2) = Base_Type (Standard_Integer)
2579 and then Is_Fixed_Point_Type (T))
2581 or else (Base_Type (T2) = Base_Type (T)
2582 and then Base_Type (T1) = Base_Type (Standard_Integer)
2583 and then Is_Fixed_Point_Type (T))
2585 or else (Is_Integer_Type (T2)
2586 and then Is_Floating_Point_Type (T1)
2587 and then Base_Type (T1) = Base_Type (T))
2589 or else (Is_Integer_Type (T1)
2590 and then Is_Floating_Point_Type (T2)
2591 and then Base_Type (T2) = Base_Type (T));
2593 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
2594 return Base_Type (T1) = Base_Type (T2)
2595 and then Base_Type (T1) = Base_Type (T)
2596 and then Is_Integer_Type (T);
2598 elsif Op_Name = Name_Op_Expon then
2599 return Base_Type (T1) = Base_Type (T)
2600 and then Is_Numeric_Type (T)
2601 and then Base_Type (T2) = Base_Type (Standard_Integer);
2603 elsif Op_Name = Name_Op_Concat then
2604 return Is_Array_Type (T)
2605 and then (Base_Type (T) = Base_Type (Etype (Op)))
2606 and then (Base_Type (T1) = Base_Type (T)
2608 Base_Type (T1) = Base_Type (Component_Type (T)))
2609 and then (Base_Type (T2) = Base_Type (T)
2611 Base_Type (T2) = Base_Type (Component_Type (T)));
2617 end Operator_Matches_Spec;
2623 procedure Remove_Interp (I : in out Interp_Index) is
2627 -- Find end of Interp list and copy downward to erase the discarded one
2630 while Present (All_Interp.Table (II).Typ) loop
2634 for J in I + 1 .. II loop
2635 All_Interp.Table (J - 1) := All_Interp.Table (J);
2638 -- Back up interp. index to insure that iterator will pick up next
2639 -- available interpretation.
2648 procedure Save_Interps (Old_N : Node_Id; New_N : Node_Id) is
2650 O_N : Node_Id := Old_N;
2653 if Is_Overloaded (Old_N) then
2654 if Nkind (Old_N) = N_Selected_Component
2655 and then Is_Overloaded (Selector_Name (Old_N))
2657 O_N := Selector_Name (Old_N);
2660 Map_Ptr := Headers (Hash (O_N));
2662 while Interp_Map.Table (Map_Ptr).Node /= O_N loop
2663 Map_Ptr := Interp_Map.Table (Map_Ptr).Next;
2664 pragma Assert (Map_Ptr /= No_Entry);
2667 New_Interps (New_N);
2668 Interp_Map.Table (Interp_Map.Last).Index :=
2669 Interp_Map.Table (Map_Ptr).Index;
2677 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
2678 B1 : constant Entity_Id := Base_Type (T1);
2679 B2 : constant Entity_Id := Base_Type (T2);
2681 function Is_Remote_Access (T : Entity_Id) return Boolean;
2682 -- Check whether T is the equivalent type of a remote access type.
2683 -- If distribution is enabled, T is a legal context for Null.
2685 ----------------------
2686 -- Is_Remote_Access --
2687 ----------------------
2689 function Is_Remote_Access (T : Entity_Id) return Boolean is
2691 return Is_Record_Type (T)
2692 and then (Is_Remote_Call_Interface (T)
2693 or else Is_Remote_Types (T))
2694 and then Present (Corresponding_Remote_Type (T))
2695 and then Is_Access_Type (Corresponding_Remote_Type (T));
2696 end Is_Remote_Access;
2698 -- Start of processing for Specific_Type
2701 if T1 = Any_Type or else T2 = Any_Type then
2708 elsif (T1 = Universal_Integer and then Is_Integer_Type (T2))
2709 or else (T1 = Universal_Real and then Is_Real_Type (T2))
2710 or else (T1 = Universal_Fixed and then Is_Fixed_Point_Type (T2))
2711 or else (T1 = Any_Fixed and then Is_Fixed_Point_Type (T2))
2715 elsif (T2 = Universal_Integer and then Is_Integer_Type (T1))
2716 or else (T2 = Universal_Real and then Is_Real_Type (T1))
2717 or else (T2 = Universal_Fixed and then Is_Fixed_Point_Type (T1))
2718 or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1))
2722 elsif T2 = Any_String and then Is_String_Type (T1) then
2725 elsif T1 = Any_String and then Is_String_Type (T2) then
2728 elsif T2 = Any_Character and then Is_Character_Type (T1) then
2731 elsif T1 = Any_Character and then Is_Character_Type (T2) then
2734 elsif T1 = Any_Access
2735 and then (Is_Access_Type (T2) or else Is_Remote_Access (T2))
2739 elsif T2 = Any_Access
2740 and then (Is_Access_Type (T1) or else Is_Remote_Access (T1))
2744 elsif T2 = Any_Composite
2745 and then Ekind (T1) in E_Array_Type .. E_Record_Subtype
2749 elsif T1 = Any_Composite
2750 and then Ekind (T2) in E_Array_Type .. E_Record_Subtype
2754 elsif T1 = Any_Modular and then Is_Modular_Integer_Type (T2) then
2757 elsif T2 = Any_Modular and then Is_Modular_Integer_Type (T1) then
2760 -- ----------------------------------------------------------
2761 -- Special cases for equality operators (all other predefined
2762 -- operators can never apply to tagged types)
2763 -- ----------------------------------------------------------
2765 -- Ada 2005 (AI-251): T1 and T2 are class-wide types, and T2 is an
2768 elsif Is_Class_Wide_Type (T1)
2769 and then Is_Class_Wide_Type (T2)
2770 and then Is_Interface (Etype (T2))
2774 -- Ada 2005 (AI-251): T1 is a concrete type that implements the
2775 -- class-wide interface T2
2777 elsif Is_Class_Wide_Type (T2)
2778 and then Is_Interface (Etype (T2))
2779 and then Interface_Present_In_Ancestor (Typ => T1,
2780 Iface => Etype (T2))
2784 elsif Is_Class_Wide_Type (T1)
2785 and then Is_Ancestor (Root_Type (T1), T2)
2789 elsif Is_Class_Wide_Type (T2)
2790 and then Is_Ancestor (Root_Type (T2), T1)
2794 elsif (Ekind (B1) = E_Access_Subprogram_Type
2796 Ekind (B1) = E_Access_Protected_Subprogram_Type)
2797 and then Ekind (Designated_Type (B1)) /= E_Subprogram_Type
2798 and then Is_Access_Type (T2)
2802 elsif (Ekind (B2) = E_Access_Subprogram_Type
2804 Ekind (B2) = E_Access_Protected_Subprogram_Type)
2805 and then Ekind (Designated_Type (B2)) /= E_Subprogram_Type
2806 and then Is_Access_Type (T1)
2810 elsif (Ekind (T1) = E_Allocator_Type
2811 or else Ekind (T1) = E_Access_Attribute_Type
2812 or else Ekind (T1) = E_Anonymous_Access_Type)
2813 and then Is_Access_Type (T2)
2817 elsif (Ekind (T2) = E_Allocator_Type
2818 or else Ekind (T2) = E_Access_Attribute_Type
2819 or else Ekind (T2) = E_Anonymous_Access_Type)
2820 and then Is_Access_Type (T1)
2824 -- If none of the above cases applies, types are not compatible
2831 -----------------------
2832 -- Valid_Boolean_Arg --
2833 -----------------------
2835 -- In addition to booleans and arrays of booleans, we must include
2836 -- aggregates as valid boolean arguments, because in the first pass of
2837 -- resolution their components are not examined. If it turns out not to be
2838 -- an aggregate of booleans, this will be diagnosed in Resolve.
2839 -- Any_Composite must be checked for prior to the array type checks because
2840 -- Any_Composite does not have any associated indexes.
2842 function Valid_Boolean_Arg (T : Entity_Id) return Boolean is
2844 return Is_Boolean_Type (T)
2845 or else T = Any_Composite
2846 or else (Is_Array_Type (T)
2847 and then T /= Any_String
2848 and then Number_Dimensions (T) = 1
2849 and then Is_Boolean_Type (Component_Type (T))
2850 and then (not Is_Private_Composite (T)
2851 or else In_Instance)
2852 and then (not Is_Limited_Composite (T)
2853 or else In_Instance))
2854 or else Is_Modular_Integer_Type (T)
2855 or else T = Universal_Integer;
2856 end Valid_Boolean_Arg;
2858 --------------------------
2859 -- Valid_Comparison_Arg --
2860 --------------------------
2862 function Valid_Comparison_Arg (T : Entity_Id) return Boolean is
2865 if T = Any_Composite then
2867 elsif Is_Discrete_Type (T)
2868 or else Is_Real_Type (T)
2871 elsif Is_Array_Type (T)
2872 and then Number_Dimensions (T) = 1
2873 and then Is_Discrete_Type (Component_Type (T))
2874 and then (not Is_Private_Composite (T)
2875 or else In_Instance)
2876 and then (not Is_Limited_Composite (T)
2877 or else In_Instance)
2880 elsif Is_String_Type (T) then
2885 end Valid_Comparison_Arg;
2887 ----------------------
2888 -- Write_Interp_Ref --
2889 ----------------------
2891 procedure Write_Interp_Ref (Map_Ptr : Int) is
2893 Write_Str (" Node: ");
2894 Write_Int (Int (Interp_Map.Table (Map_Ptr).Node));
2895 Write_Str (" Index: ");
2896 Write_Int (Int (Interp_Map.Table (Map_Ptr).Index));
2897 Write_Str (" Next: ");
2898 Write_Int (Int (Interp_Map.Table (Map_Ptr).Next));
2900 end Write_Interp_Ref;
2902 ---------------------
2903 -- Write_Overloads --
2904 ---------------------
2906 procedure Write_Overloads (N : Node_Id) is
2912 if not Is_Overloaded (N) then
2913 Write_Str ("Non-overloaded entity ");
2915 Write_Entity_Info (Entity (N), " ");
2918 Get_First_Interp (N, I, It);
2919 Write_Str ("Overloaded entity ");
2921 Write_Str (" Name Type");
2923 Write_Str ("===============================");
2927 while Present (Nam) loop
2928 Write_Int (Int (Nam));
2930 Write_Name (Chars (Nam));
2932 Write_Int (Int (It.Typ));
2934 Write_Name (Chars (It.Typ));
2936 Get_Next_Interp (I, It);
2940 end Write_Overloads;