* tree-ssa-pre.c (grand_bitmap_obstack): New.
[official-gcc.git] / gcc / ada / sem_type.adb
blob8f2ccad23506ba0f93b24deefe7cc2b56817fa79
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ T Y P E --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2004 Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Alloc;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Errout; use Errout;
32 with Lib; use Lib;
33 with Opt; use Opt;
34 with Output; use Output;
35 with Sem; use Sem;
36 with Sem_Ch6; use Sem_Ch6;
37 with Sem_Ch8; use Sem_Ch8;
38 with Sem_Util; use Sem_Util;
39 with Stand; use Stand;
40 with Sinfo; use Sinfo;
41 with Snames; use Snames;
42 with Table;
43 with Uintp; use Uintp;
45 package body Sem_Type is
47 ---------------------
48 -- Data Structures --
49 ---------------------
51 -- The following data structures establish a mapping between nodes and
52 -- their interpretations. An overloaded node has an entry in Interp_Map,
53 -- which in turn contains a pointer into the All_Interp array. The
54 -- interpretations of a given node are contiguous in All_Interp. Each
55 -- set of interpretations is terminated with the marker No_Interp.
56 -- In order to speed up the retrieval of the interpretations of an
57 -- overloaded node, the Interp_Map table is accessed by means of a simple
58 -- hashing scheme, and the entries in Interp_Map are chained. The heads
59 -- of clash lists are stored in array Headers.
61 -- Headers Interp_Map All_Interp
63 -- _ +-----+ +--------+
64 -- |_| |_____| --->|interp1 |
65 -- |_|---------->|node | | |interp2 |
66 -- |_| |index|---------| |nointerp|
67 -- |_| |next | | |
68 -- |-----| | |
69 -- +-----+ +--------+
71 -- This scheme does not currently reclaim interpretations. In principle,
72 -- after a unit is compiled, all overloadings have been resolved, and the
73 -- candidate interpretations should be deleted. This should be easier
74 -- now than with the previous scheme???
76 package All_Interp is new Table.Table (
77 Table_Component_Type => Interp,
78 Table_Index_Type => Int,
79 Table_Low_Bound => 0,
80 Table_Initial => Alloc.All_Interp_Initial,
81 Table_Increment => Alloc.All_Interp_Increment,
82 Table_Name => "All_Interp");
84 type Interp_Ref is record
85 Node : Node_Id;
86 Index : Interp_Index;
87 Next : Int;
88 end record;
90 Header_Size : constant Int := 2 ** 12;
91 No_Entry : constant Int := -1;
92 Headers : array (0 .. Header_Size) of Int := (others => No_Entry);
94 package Interp_Map is new Table.Table (
95 Table_Component_Type => Interp_Ref,
96 Table_Index_Type => Int,
97 Table_Low_Bound => 0,
98 Table_Initial => Alloc.Interp_Map_Initial,
99 Table_Increment => Alloc.Interp_Map_Increment,
100 Table_Name => "Interp_Map");
102 function Hash (N : Node_Id) return Int;
103 -- A trivial hashing function for nodes, used to insert an overloaded
104 -- node into the Interp_Map table.
106 -------------------------------------
107 -- Handling of Overload Resolution --
108 -------------------------------------
110 -- Overload resolution uses two passes over the syntax tree of a complete
111 -- context. In the first, bottom-up pass, the types of actuals in calls
112 -- are used to resolve possibly overloaded subprogram and operator names.
113 -- In the second top-down pass, the type of the context (for example the
114 -- condition in a while statement) is used to resolve a possibly ambiguous
115 -- call, and the unique subprogram name in turn imposes a specific context
116 -- on each of its actuals.
118 -- Most expressions are in fact unambiguous, and the bottom-up pass is
119 -- sufficient to resolve most everything. To simplify the common case,
120 -- names and expressions carry a flag Is_Overloaded to indicate whether
121 -- they have more than one interpretation. If the flag is off, then each
122 -- name has already a unique meaning and type, and the bottom-up pass is
123 -- sufficient (and much simpler).
125 --------------------------
126 -- Operator Overloading --
127 --------------------------
129 -- The visibility of operators is handled differently from that of
130 -- other entities. We do not introduce explicit versions of primitive
131 -- operators for each type definition. As a result, there is only one
132 -- entity corresponding to predefined addition on all numeric types, etc.
133 -- The back-end resolves predefined operators according to their type.
134 -- The visibility of primitive operations then reduces to the visibility
135 -- of the resulting type: (a + b) is a legal interpretation of some
136 -- primitive operator + if the type of the result (which must also be
137 -- the type of a and b) is directly visible (i.e. either immediately
138 -- visible or use-visible.)
140 -- User-defined operators are treated like other functions, but the
141 -- visibility of these user-defined operations must be special-cased
142 -- to determine whether they hide or are hidden by predefined operators.
143 -- The form P."+" (x, y) requires additional handling.
145 -- Concatenation is treated more conventionally: for every one-dimensional
146 -- array type we introduce a explicit concatenation operator. This is
147 -- necessary to handle the case of (element & element => array) which
148 -- cannot be handled conveniently if there is no explicit instance of
149 -- resulting type of the operation.
151 -----------------------
152 -- Local Subprograms --
153 -----------------------
155 procedure All_Overloads;
156 pragma Warnings (Off, All_Overloads);
157 -- Debugging procedure: list full contents of Overloads table.
159 procedure New_Interps (N : Node_Id);
160 -- Initialize collection of interpretations for the given node, which is
161 -- either an overloaded entity, or an operation whose arguments have
162 -- multiple intepretations. Interpretations can be added to only one
163 -- node at a time.
165 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
166 -- If T1 and T2 are compatible, return the one that is not
167 -- universal or is not a "class" type (any_character, etc).
169 --------------------
170 -- Add_One_Interp --
171 --------------------
173 procedure Add_One_Interp
174 (N : Node_Id;
175 E : Entity_Id;
176 T : Entity_Id;
177 Opnd_Type : Entity_Id := Empty)
179 Vis_Type : Entity_Id;
181 procedure Add_Entry (Name : Entity_Id; Typ : Entity_Id);
182 -- Add one interpretation to node. Node is already known to be
183 -- overloaded. Add new interpretation if not hidden by previous
184 -- one, and remove previous one if hidden by new one.
186 function Is_Universal_Operation (Op : Entity_Id) return Boolean;
187 -- True if the entity is a predefined operator and the operands have
188 -- a universal Interpretation.
190 ---------------
191 -- Add_Entry --
192 ---------------
194 procedure Add_Entry (Name : Entity_Id; Typ : Entity_Id) is
195 Index : Interp_Index;
196 It : Interp;
198 begin
199 Get_First_Interp (N, Index, It);
201 while Present (It.Nam) loop
203 -- A user-defined subprogram hides another declared at an outer
204 -- level, or one that is use-visible. So return if previous
205 -- definition hides new one (which is either in an outer
206 -- scope, or use-visible). Note that for functions use-visible
207 -- is the same as potentially use-visible. If new one hides
208 -- previous one, replace entry in table of interpretations.
209 -- If this is a universal operation, retain the operator in case
210 -- preference rule applies.
212 if (((Ekind (Name) = E_Function or else Ekind (Name) = E_Procedure)
213 and then Ekind (Name) = Ekind (It.Nam))
214 or else (Ekind (Name) = E_Operator
215 and then Ekind (It.Nam) = E_Function))
217 and then Is_Immediately_Visible (It.Nam)
218 and then Type_Conformant (Name, It.Nam)
219 and then Base_Type (It.Typ) = Base_Type (T)
220 then
221 if Is_Universal_Operation (Name) then
222 exit;
224 -- If node is an operator symbol, we have no actuals with
225 -- which to check hiding, and this is done in full in the
226 -- caller (Analyze_Subprogram_Renaming) so we include the
227 -- predefined operator in any case.
229 elsif Nkind (N) = N_Operator_Symbol
230 or else (Nkind (N) = N_Expanded_Name
231 and then
232 Nkind (Selector_Name (N)) = N_Operator_Symbol)
233 then
234 exit;
236 elsif not In_Open_Scopes (Scope (Name))
237 or else Scope_Depth (Scope (Name))
238 <= Scope_Depth (Scope (It.Nam))
239 then
240 -- If ambiguity within instance, and entity is not an
241 -- implicit operation, save for later disambiguation.
243 if Scope (Name) = Scope (It.Nam)
244 and then not Is_Inherited_Operation (Name)
245 and then In_Instance
246 then
247 exit;
248 else
249 return;
250 end if;
252 else
253 All_Interp.Table (Index).Nam := Name;
254 return;
255 end if;
257 -- Avoid making duplicate entries in overloads
259 elsif Name = It.Nam
260 and then Base_Type (It.Typ) = Base_Type (T)
261 then
262 return;
264 -- Otherwise keep going
266 else
267 Get_Next_Interp (Index, It);
268 end if;
270 end loop;
272 -- On exit, enter new interpretation. The context, or a preference
273 -- rule, will resolve the ambiguity on the second pass.
275 All_Interp.Table (All_Interp.Last) := (Name, Typ);
276 All_Interp.Increment_Last;
277 All_Interp.Table (All_Interp.Last) := No_Interp;
278 end Add_Entry;
280 ----------------------------
281 -- Is_Universal_Operation --
282 ----------------------------
284 function Is_Universal_Operation (Op : Entity_Id) return Boolean is
285 Arg : Node_Id;
287 begin
288 if Ekind (Op) /= E_Operator then
289 return False;
291 elsif Nkind (N) in N_Binary_Op then
292 return Present (Universal_Interpretation (Left_Opnd (N)))
293 and then Present (Universal_Interpretation (Right_Opnd (N)));
295 elsif Nkind (N) in N_Unary_Op then
296 return Present (Universal_Interpretation (Right_Opnd (N)));
298 elsif Nkind (N) = N_Function_Call then
299 Arg := First_Actual (N);
301 while Present (Arg) loop
303 if No (Universal_Interpretation (Arg)) then
304 return False;
305 end if;
307 Next_Actual (Arg);
308 end loop;
310 return True;
312 else
313 return False;
314 end if;
315 end Is_Universal_Operation;
317 -- Start of processing for Add_One_Interp
319 begin
320 -- If the interpretation is a predefined operator, verify that the
321 -- result type is visible, or that the entity has already been
322 -- resolved (case of an instantiation node that refers to a predefined
323 -- operation, or an internally generated operator node, or an operator
324 -- given as an expanded name). If the operator is a comparison or
325 -- equality, it is the type of the operand that matters to determine
326 -- whether the operator is visible. In an instance, the check is not
327 -- performed, given that the operator was visible in the generic.
329 if Ekind (E) = E_Operator then
331 if Present (Opnd_Type) then
332 Vis_Type := Opnd_Type;
333 else
334 Vis_Type := Base_Type (T);
335 end if;
337 if In_Open_Scopes (Scope (Vis_Type))
338 or else Is_Potentially_Use_Visible (Vis_Type)
339 or else In_Use (Vis_Type)
340 or else (In_Use (Scope (Vis_Type))
341 and then not Is_Hidden (Vis_Type))
342 or else Nkind (N) = N_Expanded_Name
343 or else (Nkind (N) in N_Op and then E = Entity (N))
344 or else In_Instance
345 then
346 null;
348 -- If the node is given in functional notation and the prefix
349 -- is an expanded name, then the operator is visible if the
350 -- prefix is the scope of the result type as well. If the
351 -- operator is (implicitly) defined in an extension of system,
352 -- it is know to be valid (see Defined_In_Scope, sem_ch4.adb).
354 elsif Nkind (N) = N_Function_Call
355 and then Nkind (Name (N)) = N_Expanded_Name
356 and then (Entity (Prefix (Name (N))) = Scope (Base_Type (T))
357 or else Entity (Prefix (Name (N))) = Scope (Vis_Type)
358 or else Scope (Vis_Type) = System_Aux_Id)
359 then
360 null;
362 -- Save type for subsequent error message, in case no other
363 -- interpretation is found.
365 else
366 Candidate_Type := Vis_Type;
367 return;
368 end if;
370 -- In an instance, an abstract non-dispatching operation cannot
371 -- be a candidate interpretation, because it could not have been
372 -- one in the generic (it may be a spurious overloading in the
373 -- instance).
375 elsif In_Instance
376 and then Is_Abstract (E)
377 and then not Is_Dispatching_Operation (E)
378 then
379 return;
380 end if;
382 -- If this is the first interpretation of N, N has type Any_Type.
383 -- In that case place the new type on the node. If one interpretation
384 -- already exists, indicate that the node is overloaded, and store
385 -- both the previous and the new interpretation in All_Interp. If
386 -- this is a later interpretation, just add it to the set.
388 if Etype (N) = Any_Type then
389 if Is_Type (E) then
390 Set_Etype (N, T);
392 else
393 -- Record both the operator or subprogram name, and its type.
395 if Nkind (N) in N_Op or else Is_Entity_Name (N) then
396 Set_Entity (N, E);
397 end if;
399 Set_Etype (N, T);
400 end if;
402 -- Either there is no current interpretation in the table for any
403 -- node or the interpretation that is present is for a different
404 -- node. In both cases add a new interpretation to the table.
406 elsif Interp_Map.Last < 0
407 or else
408 (Interp_Map.Table (Interp_Map.Last).Node /= N
409 and then not Is_Overloaded (N))
410 then
411 New_Interps (N);
413 if (Nkind (N) in N_Op or else Is_Entity_Name (N))
414 and then Present (Entity (N))
415 then
416 Add_Entry (Entity (N), Etype (N));
418 elsif (Nkind (N) = N_Function_Call
419 or else Nkind (N) = N_Procedure_Call_Statement)
420 and then (Nkind (Name (N)) = N_Operator_Symbol
421 or else Is_Entity_Name (Name (N)))
422 then
423 Add_Entry (Entity (Name (N)), Etype (N));
425 else
426 -- Overloaded prefix in indexed or selected component,
427 -- or call whose name is an expresion or another call.
429 Add_Entry (Etype (N), Etype (N));
430 end if;
432 Add_Entry (E, T);
434 else
435 Add_Entry (E, T);
436 end if;
437 end Add_One_Interp;
439 -------------------
440 -- All_Overloads --
441 -------------------
443 procedure All_Overloads is
444 begin
445 for J in All_Interp.First .. All_Interp.Last loop
447 if Present (All_Interp.Table (J).Nam) then
448 Write_Entity_Info (All_Interp.Table (J). Nam, " ");
449 else
450 Write_Str ("No Interp");
451 end if;
453 Write_Str ("=================");
454 Write_Eol;
455 end loop;
456 end All_Overloads;
458 ---------------------
459 -- Collect_Interps --
460 ---------------------
462 procedure Collect_Interps (N : Node_Id) is
463 Ent : constant Entity_Id := Entity (N);
464 H : Entity_Id;
465 First_Interp : Interp_Index;
467 begin
468 New_Interps (N);
470 -- Unconditionally add the entity that was initially matched
472 First_Interp := All_Interp.Last;
473 Add_One_Interp (N, Ent, Etype (N));
475 -- For expanded name, pick up all additional entities from the
476 -- same scope, since these are obviously also visible. Note that
477 -- these are not necessarily contiguous on the homonym chain.
479 if Nkind (N) = N_Expanded_Name then
480 H := Homonym (Ent);
481 while Present (H) loop
482 if Scope (H) = Scope (Entity (N)) then
483 Add_One_Interp (N, H, Etype (H));
484 end if;
486 H := Homonym (H);
487 end loop;
489 -- Case of direct name
491 else
492 -- First, search the homonym chain for directly visible entities
494 H := Current_Entity (Ent);
495 while Present (H) loop
496 exit when (not Is_Overloadable (H))
497 and then Is_Immediately_Visible (H);
499 if Is_Immediately_Visible (H)
500 and then H /= Ent
501 then
502 -- Only add interpretation if not hidden by an inner
503 -- immediately visible one.
505 for J in First_Interp .. All_Interp.Last - 1 loop
507 -- Current homograph is not hidden. Add to overloads.
509 if not Is_Immediately_Visible (All_Interp.Table (J).Nam) then
510 exit;
512 -- Homograph is hidden, unless it is a predefined operator.
514 elsif Type_Conformant (H, All_Interp.Table (J).Nam) then
516 -- A homograph in the same scope can occur within an
517 -- instantiation, the resulting ambiguity has to be
518 -- resolved later.
520 if Scope (H) = Scope (Ent)
521 and then In_Instance
522 and then not Is_Inherited_Operation (H)
523 then
524 All_Interp.Table (All_Interp.Last) := (H, Etype (H));
525 All_Interp.Increment_Last;
526 All_Interp.Table (All_Interp.Last) := No_Interp;
527 goto Next_Homograph;
529 elsif Scope (H) /= Standard_Standard then
530 goto Next_Homograph;
531 end if;
532 end if;
533 end loop;
535 -- On exit, we know that current homograph is not hidden.
537 Add_One_Interp (N, H, Etype (H));
539 if Debug_Flag_E then
540 Write_Str ("Add overloaded Interpretation ");
541 Write_Int (Int (H));
542 Write_Eol;
543 end if;
544 end if;
546 <<Next_Homograph>>
547 H := Homonym (H);
548 end loop;
550 -- Scan list of homographs for use-visible entities only.
552 H := Current_Entity (Ent);
554 while Present (H) loop
555 if Is_Potentially_Use_Visible (H)
556 and then H /= Ent
557 and then Is_Overloadable (H)
558 then
559 for J in First_Interp .. All_Interp.Last - 1 loop
561 if not Is_Immediately_Visible (All_Interp.Table (J).Nam) then
562 exit;
564 elsif Type_Conformant (H, All_Interp.Table (J).Nam) then
565 goto Next_Use_Homograph;
566 end if;
567 end loop;
569 Add_One_Interp (N, H, Etype (H));
570 end if;
572 <<Next_Use_Homograph>>
573 H := Homonym (H);
574 end loop;
575 end if;
577 if All_Interp.Last = First_Interp + 1 then
579 -- The original interpretation is in fact not overloaded.
581 Set_Is_Overloaded (N, False);
582 end if;
583 end Collect_Interps;
585 ------------
586 -- Covers --
587 ------------
589 function Covers (T1, T2 : Entity_Id) return Boolean is
591 function Full_View_Covers (Typ1, Typ2 : Entity_Id) return Boolean;
592 -- In an instance the proper view may not always be correct for
593 -- private types, but private and full view are compatible. This
594 -- removes spurious errors from nested instantiations that involve,
595 -- among other things, types derived from private types.
597 ----------------------
598 -- Full_View_Covers --
599 ----------------------
601 function Full_View_Covers (Typ1, Typ2 : Entity_Id) return Boolean is
602 begin
603 return
604 Is_Private_Type (Typ1)
605 and then
606 ((Present (Full_View (Typ1))
607 and then Covers (Full_View (Typ1), Typ2))
608 or else Base_Type (Typ1) = Typ2
609 or else Base_Type (Typ2) = Typ1);
610 end Full_View_Covers;
612 -- Start of processing for Covers
614 begin
615 -- If either operand missing, then this is an error, but ignore
616 -- it (and pretend we have a cover) if errors already detected,
617 -- since this may simply mean we have malformed trees.
619 if No (T1) or else No (T2) then
620 if Total_Errors_Detected /= 0 then
621 return True;
622 else
623 raise Program_Error;
624 end if;
625 end if;
627 -- Simplest case: same types are compatible, and types that have the
628 -- same base type and are not generic actuals are compatible. Generic
629 -- actuals belong to their class but are not compatible with other
630 -- types of their class, and in particular with other generic actuals.
631 -- They are however compatible with their own subtypes, and itypes
632 -- with the same base are compatible as well. Similary, constrained
633 -- subtypes obtained from expressions of an unconstrained nominal type
634 -- are compatible with the base type (may lead to spurious ambiguities
635 -- in obscure cases ???)
637 -- Generic actuals require special treatment to avoid spurious ambi-
638 -- guities in an instance, when two formal types are instantiated with
639 -- the same actual, so that different subprograms end up with the same
640 -- signature in the instance.
642 if T1 = T2 then
643 return True;
645 elsif Base_Type (T1) = Base_Type (T2) then
646 if not Is_Generic_Actual_Type (T1) then
647 return True;
648 else
649 return (not Is_Generic_Actual_Type (T2)
650 or else Is_Itype (T1)
651 or else Is_Itype (T2)
652 or else Is_Constr_Subt_For_U_Nominal (T1)
653 or else Is_Constr_Subt_For_U_Nominal (T2)
654 or else Scope (T1) /= Scope (T2));
655 end if;
657 -- Literals are compatible with types in a given "class"
659 elsif (T2 = Universal_Integer and then Is_Integer_Type (T1))
660 or else (T2 = Universal_Real and then Is_Real_Type (T1))
661 or else (T2 = Universal_Fixed and then Is_Fixed_Point_Type (T1))
662 or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1))
663 or else (T2 = Any_String and then Is_String_Type (T1))
664 or else (T2 = Any_Character and then Is_Character_Type (T1))
665 or else (T2 = Any_Access and then Is_Access_Type (T1))
666 then
667 return True;
669 -- The context may be class wide.
671 elsif Is_Class_Wide_Type (T1)
672 and then Is_Ancestor (Root_Type (T1), T2)
673 then
674 return True;
676 elsif Is_Class_Wide_Type (T1)
677 and then Is_Class_Wide_Type (T2)
678 and then Base_Type (Etype (T1)) = Base_Type (Etype (T2))
679 then
680 return True;
682 -- In a dispatching call the actual may be class-wide
684 elsif Is_Class_Wide_Type (T2)
685 and then Base_Type (Root_Type (T2)) = Base_Type (T1)
686 then
687 return True;
689 -- Some contexts require a class of types rather than a specific type
691 elsif (T1 = Any_Integer and then Is_Integer_Type (T2))
692 or else (T1 = Any_Boolean and then Is_Boolean_Type (T2))
693 or else (T1 = Any_Real and then Is_Real_Type (T2))
694 or else (T1 = Any_Fixed and then Is_Fixed_Point_Type (T2))
695 or else (T1 = Any_Discrete and then Is_Discrete_Type (T2))
696 then
697 return True;
699 -- An aggregate is compatible with an array or record type
701 elsif T2 = Any_Composite
702 and then Ekind (T1) in E_Array_Type .. E_Record_Subtype
703 then
704 return True;
706 -- If the expected type is an anonymous access, the designated
707 -- type must cover that of the expression.
709 elsif Ekind (T1) = E_Anonymous_Access_Type
710 and then Is_Access_Type (T2)
711 and then Covers (Designated_Type (T1), Designated_Type (T2))
712 then
713 return True;
715 -- An Access_To_Subprogram is compatible with itself, or with an
716 -- anonymous type created for an attribute reference Access.
718 elsif (Ekind (Base_Type (T1)) = E_Access_Subprogram_Type
719 or else
720 Ekind (Base_Type (T1)) = E_Access_Protected_Subprogram_Type)
721 and then Is_Access_Type (T2)
722 and then (not Comes_From_Source (T1)
723 or else not Comes_From_Source (T2))
724 and then (Is_Overloadable (Designated_Type (T2))
725 or else
726 Ekind (Designated_Type (T2)) = E_Subprogram_Type)
727 and then
728 Type_Conformant (Designated_Type (T1), Designated_Type (T2))
729 and then
730 Mode_Conformant (Designated_Type (T1), Designated_Type (T2))
731 then
732 return True;
734 -- Ada 2005 (AI-254): An Anonymous_Access_To_Subprogram is compatible
735 -- with itself, or with an anonymous type created for an attribute
736 -- reference Access.
738 elsif (Ekind (Base_Type (T1)) = E_Anonymous_Access_Subprogram_Type
739 or else
740 Ekind (Base_Type (T1))
741 = E_Anonymous_Access_Protected_Subprogram_Type)
742 and then Is_Access_Type (T2)
743 and then (not Comes_From_Source (T1)
744 or else not Comes_From_Source (T2))
745 and then (Is_Overloadable (Designated_Type (T2))
746 or else
747 Ekind (Designated_Type (T2)) = E_Subprogram_Type)
748 and then
749 Type_Conformant (Designated_Type (T1), Designated_Type (T2))
750 and then
751 Mode_Conformant (Designated_Type (T1), Designated_Type (T2))
752 then
753 return True;
755 -- The context can be a remote access type, and the expression the
756 -- corresponding source type declared in a categorized package, or
757 -- viceversa.
759 elsif Is_Record_Type (T1)
760 and then (Is_Remote_Call_Interface (T1)
761 or else Is_Remote_Types (T1))
762 and then Present (Corresponding_Remote_Type (T1))
763 then
764 return Covers (Corresponding_Remote_Type (T1), T2);
766 elsif Is_Record_Type (T2)
767 and then (Is_Remote_Call_Interface (T2)
768 or else Is_Remote_Types (T2))
769 and then Present (Corresponding_Remote_Type (T2))
770 then
771 return Covers (Corresponding_Remote_Type (T2), T1);
773 elsif Ekind (T2) = E_Access_Attribute_Type
774 and then (Ekind (Base_Type (T1)) = E_General_Access_Type
775 or else Ekind (Base_Type (T1)) = E_Access_Type)
776 and then Covers (Designated_Type (T1), Designated_Type (T2))
777 then
778 -- If the target type is a RACW type while the source is an access
779 -- attribute type, we are building a RACW that may be exported.
781 if Is_Remote_Access_To_Class_Wide_Type (Base_Type (T1)) then
782 Set_Has_RACW (Current_Sem_Unit);
783 end if;
785 return True;
787 elsif Ekind (T2) = E_Allocator_Type
788 and then Is_Access_Type (T1)
789 then
790 return Covers (Designated_Type (T1), Designated_Type (T2))
791 or else
792 (From_With_Type (Designated_Type (T1))
793 and then Covers (Designated_Type (T2), Designated_Type (T1)));
795 -- A boolean operation on integer literals is compatible with a
796 -- modular context.
798 elsif T2 = Any_Modular
799 and then Is_Modular_Integer_Type (T1)
800 then
801 return True;
803 -- The actual type may be the result of a previous error
805 elsif Base_Type (T2) = Any_Type then
806 return True;
808 -- A packed array type covers its corresponding non-packed type.
809 -- This is not legitimate Ada, but allows the omission of a number
810 -- of otherwise useless unchecked conversions, and since this can
811 -- only arise in (known correct) expanded code, no harm is done
813 elsif Is_Array_Type (T2)
814 and then Is_Packed (T2)
815 and then T1 = Packed_Array_Type (T2)
816 then
817 return True;
819 -- Similarly an array type covers its corresponding packed array type
821 elsif Is_Array_Type (T1)
822 and then Is_Packed (T1)
823 and then T2 = Packed_Array_Type (T1)
824 then
825 return True;
827 elsif In_Instance
828 and then
829 (Full_View_Covers (T1, T2)
830 or else Full_View_Covers (T2, T1))
831 then
832 return True;
834 -- In the expansion of inlined bodies, types are compatible if they
835 -- are structurally equivalent.
837 elsif In_Inlined_Body
838 and then (Underlying_Type (T1) = Underlying_Type (T2)
839 or else (Is_Access_Type (T1)
840 and then Is_Access_Type (T2)
841 and then
842 Designated_Type (T1) = Designated_Type (T2))
843 or else (T1 = Any_Access
844 and then Is_Access_Type (Underlying_Type (T2))))
845 then
846 return True;
848 -- Ada 2005 (AI-50217): Additional branches to make the shadow entity
849 -- compatible with its real entity.
851 elsif From_With_Type (T1) then
853 -- If the expected type is the non-limited view of a type, the
854 -- expression may have the limited view.
856 if Ekind (T1) = E_Incomplete_Type then
857 return Covers (Non_Limited_View (T1), T2);
859 elsif Ekind (T1) = E_Class_Wide_Type then
860 return
861 Covers (Class_Wide_Type (Non_Limited_View (Etype (T1))), T2);
862 else
863 return False;
864 end if;
866 elsif From_With_Type (T2) then
868 -- If units in the context have Limited_With clauses on each other,
869 -- either type might have a limited view. Checks performed elsewhere
870 -- verify that the context type is the non-limited view.
872 if Ekind (T2) = E_Incomplete_Type then
873 return Covers (T1, Non_Limited_View (T2));
875 elsif Ekind (T2) = E_Class_Wide_Type then
876 return
877 Covers (T1, Class_Wide_Type (Non_Limited_View (Etype (T2))));
878 else
879 return False;
880 end if;
882 -- Otherwise it doesn't cover!
884 else
885 return False;
886 end if;
887 end Covers;
889 ------------------
890 -- Disambiguate --
891 ------------------
893 function Disambiguate
894 (N : Node_Id;
895 I1, I2 : Interp_Index;
896 Typ : Entity_Id)
897 return Interp
899 I : Interp_Index;
900 It : Interp;
901 It1, It2 : Interp;
902 Nam1, Nam2 : Entity_Id;
903 Predef_Subp : Entity_Id;
904 User_Subp : Entity_Id;
906 function Is_Actual_Subprogram (S : Entity_Id) return Boolean;
907 -- Determine whether a subprogram is an actual in an enclosing
908 -- instance. An overloading between such a subprogram and one
909 -- declared outside the instance is resolved in favor of the first,
910 -- because it resolved in the generic.
912 function Matches (Actual, Formal : Node_Id) return Boolean;
913 -- Look for exact type match in an instance, to remove spurious
914 -- ambiguities when two formal types have the same actual.
916 function Standard_Operator return Boolean;
918 function Remove_Conversions return Interp;
919 -- Last chance for pathological cases involving comparisons on
920 -- literals, and user overloadings of the same operator. Such
921 -- pathologies have been removed from the ACVC, but still appear in
922 -- two DEC tests, with the following notable quote from Ben Brosgol:
924 -- [Note: I disclaim all credit/responsibility/blame for coming up with
925 -- this example; Robert Dewar brought it to our attention, since it
926 -- is apparently found in the ACVC 1.5. I did not attempt to find
927 -- the reason in the Reference Manual that makes the example legal,
928 -- since I was too nauseated by it to want to pursue it further.]
930 -- Accordingly, this is not a fully recursive solution, but it handles
931 -- DEC tests c460vsa, c460vsb. It also handles ai00136a, which pushes
932 -- pathology in the other direction with calls whose multiple overloaded
933 -- actuals make them truly unresolvable.
935 function Is_Actual_Subprogram (S : Entity_Id) return Boolean is
936 begin
937 return In_Open_Scopes (Scope (S))
938 and then
939 (Is_Generic_Instance (Scope (S))
940 or else Is_Wrapper_Package (Scope (S)));
941 end Is_Actual_Subprogram;
943 -------------
944 -- Matches --
945 -------------
947 function Matches (Actual, Formal : Node_Id) return Boolean is
948 T1 : constant Entity_Id := Etype (Actual);
949 T2 : constant Entity_Id := Etype (Formal);
951 begin
952 return T1 = T2
953 or else
954 (Is_Numeric_Type (T2)
955 and then
956 (T1 = Universal_Real or else T1 = Universal_Integer));
957 end Matches;
959 ------------------------
960 -- Remove_Conversions --
961 ------------------------
963 function Remove_Conversions return Interp is
964 I : Interp_Index;
965 It : Interp;
966 It1 : Interp;
967 F1 : Entity_Id;
968 Act1 : Node_Id;
969 Act2 : Node_Id;
971 begin
972 It1 := No_Interp;
973 Get_First_Interp (N, I, It);
975 while Present (It.Typ) loop
977 if not Is_Overloadable (It.Nam) then
978 return No_Interp;
979 end if;
981 F1 := First_Formal (It.Nam);
983 if No (F1) then
984 return It1;
986 else
987 if Nkind (N) = N_Function_Call
988 or else Nkind (N) = N_Procedure_Call_Statement
989 then
990 Act1 := First_Actual (N);
992 if Present (Act1) then
993 Act2 := Next_Actual (Act1);
994 else
995 Act2 := Empty;
996 end if;
998 elsif Nkind (N) in N_Unary_Op then
999 Act1 := Right_Opnd (N);
1000 Act2 := Empty;
1002 elsif Nkind (N) in N_Binary_Op then
1003 Act1 := Left_Opnd (N);
1004 Act2 := Right_Opnd (N);
1006 else
1007 return It1;
1008 end if;
1010 if Nkind (Act1) in N_Op
1011 and then Is_Overloaded (Act1)
1012 and then (Nkind (Right_Opnd (Act1)) = N_Integer_Literal
1013 or else Nkind (Right_Opnd (Act1)) = N_Real_Literal)
1014 and then Has_Compatible_Type (Act1, Standard_Boolean)
1015 and then Etype (F1) = Standard_Boolean
1016 then
1017 -- If the two candidates are the original ones, the
1018 -- ambiguity is real. Otherwise keep the original,
1019 -- further calls to Disambiguate will take care of
1020 -- others in the list of candidates.
1022 if It1 /= No_Interp then
1023 if It = Disambiguate.It1
1024 or else It = Disambiguate.It2
1025 then
1026 if It1 = Disambiguate.It1
1027 or else It1 = Disambiguate.It2
1028 then
1029 return No_Interp;
1030 else
1031 It1 := It;
1032 end if;
1033 end if;
1035 elsif Present (Act2)
1036 and then Nkind (Act2) in N_Op
1037 and then Is_Overloaded (Act2)
1038 and then (Nkind (Right_Opnd (Act1)) = N_Integer_Literal
1039 or else
1040 Nkind (Right_Opnd (Act1)) = N_Real_Literal)
1041 and then Has_Compatible_Type (Act2, Standard_Boolean)
1042 then
1043 -- The preference rule on the first actual is not
1044 -- sufficient to disambiguate.
1046 goto Next_Interp;
1048 else
1049 It1 := It;
1050 end if;
1051 end if;
1052 end if;
1054 <<Next_Interp>>
1055 Get_Next_Interp (I, It);
1056 end loop;
1058 if Serious_Errors_Detected > 0 then
1060 -- After some error, a formal may have Any_Type and yield
1061 -- a spurious match. To avoid cascaded errors if possible,
1062 -- check for such a formal in either candidate.
1064 declare
1065 Formal : Entity_Id;
1067 begin
1068 Formal := First_Formal (Nam1);
1069 while Present (Formal) loop
1070 if Etype (Formal) = Any_Type then
1071 return Disambiguate.It2;
1072 end if;
1074 Next_Formal (Formal);
1075 end loop;
1077 Formal := First_Formal (Nam2);
1078 while Present (Formal) loop
1079 if Etype (Formal) = Any_Type then
1080 return Disambiguate.It1;
1081 end if;
1083 Next_Formal (Formal);
1084 end loop;
1085 end;
1086 end if;
1088 return It1;
1089 end Remove_Conversions;
1091 -----------------------
1092 -- Standard_Operator --
1093 -----------------------
1095 function Standard_Operator return Boolean is
1096 Nam : Node_Id;
1098 begin
1099 if Nkind (N) in N_Op then
1100 return True;
1102 elsif Nkind (N) = N_Function_Call then
1103 Nam := Name (N);
1105 if Nkind (Nam) /= N_Expanded_Name then
1106 return True;
1107 else
1108 return Entity (Prefix (Nam)) = Standard_Standard;
1109 end if;
1110 else
1111 return False;
1112 end if;
1113 end Standard_Operator;
1115 -- Start of processing for Disambiguate
1117 begin
1118 -- Recover the two legal interpretations.
1120 Get_First_Interp (N, I, It);
1122 while I /= I1 loop
1123 Get_Next_Interp (I, It);
1124 end loop;
1126 It1 := It;
1127 Nam1 := It.Nam;
1129 while I /= I2 loop
1130 Get_Next_Interp (I, It);
1131 end loop;
1133 It2 := It;
1134 Nam2 := It.Nam;
1136 -- If the context is universal, the predefined operator is preferred.
1137 -- This includes bounds in numeric type declarations, and expressions
1138 -- in type conversions. If no interpretation yields a universal type,
1139 -- then we must check whether the user-defined entity hides the prede-
1140 -- fined one.
1142 if Chars (Nam1) in Any_Operator_Name
1143 and then Standard_Operator
1144 then
1145 if Typ = Universal_Integer
1146 or else Typ = Universal_Real
1147 or else Typ = Any_Integer
1148 or else Typ = Any_Discrete
1149 or else Typ = Any_Real
1150 or else Typ = Any_Type
1151 then
1152 -- Find an interpretation that yields the universal type, or else
1153 -- a predefined operator that yields a predefined numeric type.
1155 declare
1156 Candidate : Interp := No_Interp;
1157 begin
1158 Get_First_Interp (N, I, It);
1160 while Present (It.Typ) loop
1161 if (Covers (Typ, It.Typ)
1162 or else Typ = Any_Type)
1163 and then
1164 (It.Typ = Universal_Integer
1165 or else It.Typ = Universal_Real)
1166 then
1167 return It;
1169 elsif Covers (Typ, It.Typ)
1170 and then Scope (It.Typ) = Standard_Standard
1171 and then Scope (It.Nam) = Standard_Standard
1172 and then Is_Numeric_Type (It.Typ)
1173 then
1174 Candidate := It;
1175 end if;
1177 Get_Next_Interp (I, It);
1178 end loop;
1180 if Candidate /= No_Interp then
1181 return Candidate;
1182 end if;
1183 end;
1185 elsif Chars (Nam1) /= Name_Op_Not
1186 and then (Typ = Standard_Boolean
1187 or else Typ = Any_Boolean)
1188 then
1189 -- Equality or comparison operation. Choose predefined operator
1190 -- if arguments are universal. The node may be an operator, a
1191 -- name, or a function call, so unpack arguments accordingly.
1193 declare
1194 Arg1, Arg2 : Node_Id;
1196 begin
1197 if Nkind (N) in N_Op then
1198 Arg1 := Left_Opnd (N);
1199 Arg2 := Right_Opnd (N);
1201 elsif Is_Entity_Name (N)
1202 or else Nkind (N) = N_Operator_Symbol
1203 then
1204 Arg1 := First_Entity (Entity (N));
1205 Arg2 := Next_Entity (Arg1);
1207 else
1208 Arg1 := First_Actual (N);
1209 Arg2 := Next_Actual (Arg1);
1210 end if;
1212 if Present (Arg2)
1213 and then Present (Universal_Interpretation (Arg1))
1214 and then Universal_Interpretation (Arg2) =
1215 Universal_Interpretation (Arg1)
1216 then
1217 Get_First_Interp (N, I, It);
1219 while Scope (It.Nam) /= Standard_Standard loop
1220 Get_Next_Interp (I, It);
1221 end loop;
1223 return It;
1224 end if;
1225 end;
1226 end if;
1227 end if;
1229 -- If no universal interpretation, check whether user-defined operator
1230 -- hides predefined one, as well as other special cases. If the node
1231 -- is a range, then one or both bounds are ambiguous. Each will have
1232 -- to be disambiguated w.r.t. the context type. The type of the range
1233 -- itself is imposed by the context, so we can return either legal
1234 -- interpretation.
1236 if Ekind (Nam1) = E_Operator then
1237 Predef_Subp := Nam1;
1238 User_Subp := Nam2;
1240 elsif Ekind (Nam2) = E_Operator then
1241 Predef_Subp := Nam2;
1242 User_Subp := Nam1;
1244 elsif Nkind (N) = N_Range then
1245 return It1;
1247 -- If two user defined-subprograms are visible, it is a true ambiguity,
1248 -- unless one of them is an entry and the context is a conditional or
1249 -- timed entry call, or unless we are within an instance and this is
1250 -- results from two formals types with the same actual.
1252 else
1253 if Nkind (N) = N_Procedure_Call_Statement
1254 and then Nkind (Parent (N)) = N_Entry_Call_Alternative
1255 and then N = Entry_Call_Statement (Parent (N))
1256 then
1257 if Ekind (Nam2) = E_Entry then
1258 return It2;
1259 elsif Ekind (Nam1) = E_Entry then
1260 return It1;
1261 else
1262 return No_Interp;
1263 end if;
1265 -- If the ambiguity occurs within an instance, it is due to several
1266 -- formal types with the same actual. Look for an exact match
1267 -- between the types of the formals of the overloadable entities,
1268 -- and the actuals in the call, to recover the unambiguous match
1269 -- in the original generic.
1271 -- The ambiguity can also be due to an overloading between a formal
1272 -- subprogram and a subprogram declared outside the generic. If the
1273 -- node is overloaded, it did not resolve to the global entity in
1274 -- the generic, and we choose the formal subprogram.
1276 elsif In_Instance then
1277 if Nkind (N) = N_Function_Call
1278 or else Nkind (N) = N_Procedure_Call_Statement
1279 then
1280 declare
1281 Actual : Node_Id;
1282 Formal : Entity_Id;
1283 Is_Act1 : constant Boolean := Is_Actual_Subprogram (Nam1);
1284 Is_Act2 : constant Boolean := Is_Actual_Subprogram (Nam2);
1286 begin
1287 if Is_Act1 and then not Is_Act2 then
1288 return It1;
1290 elsif Is_Act2 and then not Is_Act1 then
1291 return It2;
1292 end if;
1294 Actual := First_Actual (N);
1295 Formal := First_Formal (Nam1);
1296 while Present (Actual) loop
1297 if Etype (Actual) /= Etype (Formal) then
1298 return It2;
1299 end if;
1301 Next_Actual (Actual);
1302 Next_Formal (Formal);
1303 end loop;
1305 return It1;
1306 end;
1308 elsif Nkind (N) in N_Binary_Op then
1310 if Matches (Left_Opnd (N), First_Formal (Nam1))
1311 and then
1312 Matches (Right_Opnd (N), Next_Formal (First_Formal (Nam1)))
1313 then
1314 return It1;
1315 else
1316 return It2;
1317 end if;
1319 elsif Nkind (N) in N_Unary_Op then
1321 if Etype (Right_Opnd (N)) = Etype (First_Formal (Nam1)) then
1322 return It1;
1323 else
1324 return It2;
1325 end if;
1327 else
1328 return Remove_Conversions;
1329 end if;
1330 else
1331 return Remove_Conversions;
1332 end if;
1333 end if;
1335 -- an implicit concatenation operator on a string type cannot be
1336 -- disambiguated from the predefined concatenation. This can only
1337 -- happen with concatenation of string literals.
1339 if Chars (User_Subp) = Name_Op_Concat
1340 and then Ekind (User_Subp) = E_Operator
1341 and then Is_String_Type (Etype (First_Formal (User_Subp)))
1342 then
1343 return No_Interp;
1345 -- If the user-defined operator is in an open scope, or in the scope
1346 -- of the resulting type, or given by an expanded name that names its
1347 -- scope, it hides the predefined operator for the type. Exponentiation
1348 -- has to be special-cased because the implicit operator does not have
1349 -- a symmetric signature, and may not be hidden by the explicit one.
1351 elsif (Nkind (N) = N_Function_Call
1352 and then Nkind (Name (N)) = N_Expanded_Name
1353 and then (Chars (Predef_Subp) /= Name_Op_Expon
1354 or else Hides_Op (User_Subp, Predef_Subp))
1355 and then Scope (User_Subp) = Entity (Prefix (Name (N))))
1356 or else Hides_Op (User_Subp, Predef_Subp)
1357 then
1358 if It1.Nam = User_Subp then
1359 return It1;
1360 else
1361 return It2;
1362 end if;
1364 -- Otherwise, the predefined operator has precedence, or if the
1365 -- user-defined operation is directly visible we have a true ambiguity.
1366 -- If this is a fixed-point multiplication and division in Ada83 mode,
1367 -- exclude the universal_fixed operator, which often causes ambiguities
1368 -- in legacy code.
1370 else
1371 if (In_Open_Scopes (Scope (User_Subp))
1372 or else Is_Potentially_Use_Visible (User_Subp))
1373 and then not In_Instance
1374 then
1375 if Is_Fixed_Point_Type (Typ)
1376 and then (Chars (Nam1) = Name_Op_Multiply
1377 or else Chars (Nam1) = Name_Op_Divide)
1378 and then Ada_Version = Ada_83
1379 then
1380 if It2.Nam = Predef_Subp then
1381 return It1;
1382 else
1383 return It2;
1384 end if;
1385 else
1386 return No_Interp;
1387 end if;
1389 elsif It1.Nam = Predef_Subp then
1390 return It1;
1392 else
1393 return It2;
1394 end if;
1395 end if;
1397 end Disambiguate;
1399 ---------------------
1400 -- End_Interp_List --
1401 ---------------------
1403 procedure End_Interp_List is
1404 begin
1405 All_Interp.Table (All_Interp.Last) := No_Interp;
1406 All_Interp.Increment_Last;
1407 end End_Interp_List;
1409 -------------------------
1410 -- Entity_Matches_Spec --
1411 -------------------------
1413 function Entity_Matches_Spec (Old_S, New_S : Entity_Id) return Boolean is
1414 begin
1415 -- Simple case: same entity kinds, type conformance is required.
1416 -- A parameterless function can also rename a literal.
1418 if Ekind (Old_S) = Ekind (New_S)
1419 or else (Ekind (New_S) = E_Function
1420 and then Ekind (Old_S) = E_Enumeration_Literal)
1421 then
1422 return Type_Conformant (New_S, Old_S);
1424 elsif Ekind (New_S) = E_Function
1425 and then Ekind (Old_S) = E_Operator
1426 then
1427 return Operator_Matches_Spec (Old_S, New_S);
1429 elsif Ekind (New_S) = E_Procedure
1430 and then Is_Entry (Old_S)
1431 then
1432 return Type_Conformant (New_S, Old_S);
1434 else
1435 return False;
1436 end if;
1437 end Entity_Matches_Spec;
1439 ----------------------
1440 -- Find_Unique_Type --
1441 ----------------------
1443 function Find_Unique_Type (L : Node_Id; R : Node_Id) return Entity_Id is
1444 T : constant Entity_Id := Etype (L);
1445 I : Interp_Index;
1446 It : Interp;
1447 TR : Entity_Id := Any_Type;
1449 begin
1450 if Is_Overloaded (R) then
1451 Get_First_Interp (R, I, It);
1453 while Present (It.Typ) loop
1454 if Covers (T, It.Typ) or else Covers (It.Typ, T) then
1456 -- If several interpretations are possible and L is universal,
1457 -- apply preference rule.
1459 if TR /= Any_Type then
1461 if (T = Universal_Integer or else T = Universal_Real)
1462 and then It.Typ = T
1463 then
1464 TR := It.Typ;
1465 end if;
1467 else
1468 TR := It.Typ;
1469 end if;
1470 end if;
1472 Get_Next_Interp (I, It);
1473 end loop;
1475 Set_Etype (R, TR);
1477 -- In the non-overloaded case, the Etype of R is already set
1478 -- correctly.
1480 else
1481 null;
1482 end if;
1484 -- If one of the operands is Universal_Fixed, the type of the
1485 -- other operand provides the context.
1487 if Etype (R) = Universal_Fixed then
1488 return T;
1490 elsif T = Universal_Fixed then
1491 return Etype (R);
1493 -- Ada 2005 (AI-230): Support the following operators:
1495 -- function "=" (L, R : universal_access) return Boolean;
1496 -- function "/=" (L, R : universal_access) return Boolean;
1498 elsif Ada_Version >= Ada_05
1499 and then Ekind (Etype (L)) = E_Anonymous_Access_Type
1500 and then Is_Access_Type (Etype (R))
1501 then
1502 return Etype (L);
1504 elsif Ada_Version >= Ada_05
1505 and then Ekind (Etype (R)) = E_Anonymous_Access_Type
1506 and then Is_Access_Type (Etype (L))
1507 then
1508 return Etype (R);
1510 else
1511 return Specific_Type (T, Etype (R));
1512 end if;
1514 end Find_Unique_Type;
1516 ----------------------
1517 -- Get_First_Interp --
1518 ----------------------
1520 procedure Get_First_Interp
1521 (N : Node_Id;
1522 I : out Interp_Index;
1523 It : out Interp)
1525 Map_Ptr : Int;
1526 Int_Ind : Interp_Index;
1527 O_N : Node_Id;
1529 begin
1530 -- If a selected component is overloaded because the selector has
1531 -- multiple interpretations, the node is a call to a protected
1532 -- operation or an indirect call. Retrieve the interpretation from
1533 -- the selector name. The selected component may be overloaded as well
1534 -- if the prefix is overloaded. That case is unchanged.
1536 if Nkind (N) = N_Selected_Component
1537 and then Is_Overloaded (Selector_Name (N))
1538 then
1539 O_N := Selector_Name (N);
1540 else
1541 O_N := N;
1542 end if;
1544 Map_Ptr := Headers (Hash (O_N));
1546 while Present (Interp_Map.Table (Map_Ptr).Node) loop
1547 if Interp_Map.Table (Map_Ptr).Node = O_N then
1548 Int_Ind := Interp_Map.Table (Map_Ptr).Index;
1549 It := All_Interp.Table (Int_Ind);
1550 I := Int_Ind;
1551 return;
1552 else
1553 Map_Ptr := Interp_Map.Table (Map_Ptr).Next;
1554 end if;
1555 end loop;
1557 -- Procedure should never be called if the node has no interpretations
1559 raise Program_Error;
1560 end Get_First_Interp;
1562 ---------------------
1563 -- Get_Next_Interp --
1564 ---------------------
1566 procedure Get_Next_Interp (I : in out Interp_Index; It : out Interp) is
1567 begin
1568 I := I + 1;
1569 It := All_Interp.Table (I);
1570 end Get_Next_Interp;
1572 -------------------------
1573 -- Has_Compatible_Type --
1574 -------------------------
1576 function Has_Compatible_Type
1577 (N : Node_Id;
1578 Typ : Entity_Id)
1579 return Boolean
1581 I : Interp_Index;
1582 It : Interp;
1584 begin
1585 if N = Error then
1586 return False;
1587 end if;
1589 if Nkind (N) = N_Subtype_Indication
1590 or else not Is_Overloaded (N)
1591 then
1592 return
1593 Covers (Typ, Etype (N))
1594 or else
1595 (not Is_Tagged_Type (Typ)
1596 and then Ekind (Typ) /= E_Anonymous_Access_Type
1597 and then Covers (Etype (N), Typ));
1599 else
1600 Get_First_Interp (N, I, It);
1602 while Present (It.Typ) loop
1603 if (Covers (Typ, It.Typ)
1604 and then
1605 (Scope (It.Nam) /= Standard_Standard
1606 or else not Is_Invisible_Operator (N, Base_Type (Typ))))
1608 or else (not Is_Tagged_Type (Typ)
1609 and then Ekind (Typ) /= E_Anonymous_Access_Type
1610 and then Covers (It.Typ, Typ))
1611 then
1612 return True;
1613 end if;
1615 Get_Next_Interp (I, It);
1616 end loop;
1618 return False;
1619 end if;
1620 end Has_Compatible_Type;
1622 ----------
1623 -- Hash --
1624 ----------
1626 function Hash (N : Node_Id) return Int is
1627 begin
1628 -- Nodes have a size that is power of two, so to select significant
1629 -- bits only we remove the low-order bits.
1631 return ((Int (N) / 2 ** 5) mod Header_Size);
1632 end Hash;
1634 --------------
1635 -- Hides_Op --
1636 --------------
1638 function Hides_Op (F : Entity_Id; Op : Entity_Id) return Boolean is
1639 Btyp : constant Entity_Id := Base_Type (Etype (First_Formal (F)));
1641 begin
1642 return Operator_Matches_Spec (Op, F)
1643 and then (In_Open_Scopes (Scope (F))
1644 or else Scope (F) = Scope (Btyp)
1645 or else (not In_Open_Scopes (Scope (Btyp))
1646 and then not In_Use (Btyp)
1647 and then not In_Use (Scope (Btyp))));
1648 end Hides_Op;
1650 ------------------------
1651 -- Init_Interp_Tables --
1652 ------------------------
1654 procedure Init_Interp_Tables is
1655 begin
1656 All_Interp.Init;
1657 Interp_Map.Init;
1658 Headers := (others => No_Entry);
1659 end Init_Interp_Tables;
1661 ---------------------
1662 -- Intersect_Types --
1663 ---------------------
1665 function Intersect_Types (L, R : Node_Id) return Entity_Id is
1666 Index : Interp_Index;
1667 It : Interp;
1668 Typ : Entity_Id;
1670 function Check_Right_Argument (T : Entity_Id) return Entity_Id;
1671 -- Find interpretation of right arg that has type compatible with T
1673 --------------------------
1674 -- Check_Right_Argument --
1675 --------------------------
1677 function Check_Right_Argument (T : Entity_Id) return Entity_Id is
1678 Index : Interp_Index;
1679 It : Interp;
1680 T2 : Entity_Id;
1682 begin
1683 if not Is_Overloaded (R) then
1684 return Specific_Type (T, Etype (R));
1686 else
1687 Get_First_Interp (R, Index, It);
1689 loop
1690 T2 := Specific_Type (T, It.Typ);
1692 if T2 /= Any_Type then
1693 return T2;
1694 end if;
1696 Get_Next_Interp (Index, It);
1697 exit when No (It.Typ);
1698 end loop;
1700 return Any_Type;
1701 end if;
1702 end Check_Right_Argument;
1704 -- Start processing for Intersect_Types
1706 begin
1707 if Etype (L) = Any_Type or else Etype (R) = Any_Type then
1708 return Any_Type;
1709 end if;
1711 if not Is_Overloaded (L) then
1712 Typ := Check_Right_Argument (Etype (L));
1714 else
1715 Typ := Any_Type;
1716 Get_First_Interp (L, Index, It);
1718 while Present (It.Typ) loop
1719 Typ := Check_Right_Argument (It.Typ);
1720 exit when Typ /= Any_Type;
1721 Get_Next_Interp (Index, It);
1722 end loop;
1724 end if;
1726 -- If Typ is Any_Type, it means no compatible pair of types was found
1728 if Typ = Any_Type then
1730 if Nkind (Parent (L)) in N_Op then
1731 Error_Msg_N ("incompatible types for operator", Parent (L));
1733 elsif Nkind (Parent (L)) = N_Range then
1734 Error_Msg_N ("incompatible types given in constraint", Parent (L));
1736 else
1737 Error_Msg_N ("incompatible types", Parent (L));
1738 end if;
1739 end if;
1741 return Typ;
1742 end Intersect_Types;
1744 -----------------
1745 -- Is_Ancestor --
1746 -----------------
1748 function Is_Ancestor (T1, T2 : Entity_Id) return Boolean is
1749 Par : Entity_Id;
1751 begin
1752 if Base_Type (T1) = Base_Type (T2) then
1753 return True;
1755 elsif Is_Private_Type (T1)
1756 and then Present (Full_View (T1))
1757 and then Base_Type (T2) = Base_Type (Full_View (T1))
1758 then
1759 return True;
1761 else
1762 Par := Etype (T2);
1764 loop
1765 -- If there was a error on the type declaration, do not recurse
1767 if Error_Posted (Par) then
1768 return False;
1770 elsif Base_Type (T1) = Base_Type (Par)
1771 or else (Is_Private_Type (T1)
1772 and then Present (Full_View (T1))
1773 and then Base_Type (Par) = Base_Type (Full_View (T1)))
1774 then
1775 return True;
1777 elsif Is_Private_Type (Par)
1778 and then Present (Full_View (Par))
1779 and then Full_View (Par) = Base_Type (T1)
1780 then
1781 return True;
1783 elsif Etype (Par) /= Par then
1784 Par := Etype (Par);
1785 else
1786 return False;
1787 end if;
1788 end loop;
1789 end if;
1790 end Is_Ancestor;
1792 ---------------------------
1793 -- Is_Invisible_Operator --
1794 ---------------------------
1796 function Is_Invisible_Operator
1797 (N : Node_Id;
1798 T : Entity_Id)
1799 return Boolean
1801 Orig_Node : constant Node_Id := Original_Node (N);
1803 begin
1804 if Nkind (N) not in N_Op then
1805 return False;
1807 elsif not Comes_From_Source (N) then
1808 return False;
1810 elsif No (Universal_Interpretation (Right_Opnd (N))) then
1811 return False;
1813 elsif Nkind (N) in N_Binary_Op
1814 and then No (Universal_Interpretation (Left_Opnd (N)))
1815 then
1816 return False;
1818 else return
1819 Is_Numeric_Type (T)
1820 and then not In_Open_Scopes (Scope (T))
1821 and then not Is_Potentially_Use_Visible (T)
1822 and then not In_Use (T)
1823 and then not In_Use (Scope (T))
1824 and then
1825 (Nkind (Orig_Node) /= N_Function_Call
1826 or else Nkind (Name (Orig_Node)) /= N_Expanded_Name
1827 or else Entity (Prefix (Name (Orig_Node))) /= Scope (T))
1829 and then not In_Instance;
1830 end if;
1831 end Is_Invisible_Operator;
1833 -------------------
1834 -- Is_Subtype_Of --
1835 -------------------
1837 function Is_Subtype_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
1838 S : Entity_Id;
1840 begin
1841 S := Ancestor_Subtype (T1);
1842 while Present (S) loop
1843 if S = T2 then
1844 return True;
1845 else
1846 S := Ancestor_Subtype (S);
1847 end if;
1848 end loop;
1850 return False;
1851 end Is_Subtype_Of;
1853 ------------------
1854 -- List_Interps --
1855 ------------------
1857 procedure List_Interps (Nam : Node_Id; Err : Node_Id) is
1858 Index : Interp_Index;
1859 It : Interp;
1861 begin
1862 Get_First_Interp (Nam, Index, It);
1863 while Present (It.Nam) loop
1864 if Scope (It.Nam) = Standard_Standard
1865 and then Scope (It.Typ) /= Standard_Standard
1866 then
1867 Error_Msg_Sloc := Sloc (Parent (It.Typ));
1868 Error_Msg_NE (" & (inherited) declared#!", Err, It.Nam);
1870 else
1871 Error_Msg_Sloc := Sloc (It.Nam);
1872 Error_Msg_NE (" & declared#!", Err, It.Nam);
1873 end if;
1875 Get_Next_Interp (Index, It);
1876 end loop;
1877 end List_Interps;
1879 -----------------
1880 -- New_Interps --
1881 -----------------
1883 procedure New_Interps (N : Node_Id) is
1884 Map_Ptr : Int;
1886 begin
1887 All_Interp.Increment_Last;
1888 All_Interp.Table (All_Interp.Last) := No_Interp;
1890 Map_Ptr := Headers (Hash (N));
1892 if Map_Ptr = No_Entry then
1894 -- Place new node at end of table
1896 Interp_Map.Increment_Last;
1897 Headers (Hash (N)) := Interp_Map.Last;
1899 else
1900 -- Place node at end of chain, or locate its previous entry.
1902 loop
1903 if Interp_Map.Table (Map_Ptr).Node = N then
1905 -- Node is already in the table, and is being rewritten.
1906 -- Start a new interp section, retain hash link.
1908 Interp_Map.Table (Map_Ptr).Node := N;
1909 Interp_Map.Table (Map_Ptr).Index := All_Interp.Last;
1910 Set_Is_Overloaded (N, True);
1911 return;
1913 else
1914 exit when Interp_Map.Table (Map_Ptr).Next = No_Entry;
1915 Map_Ptr := Interp_Map.Table (Map_Ptr).Next;
1916 end if;
1917 end loop;
1919 -- Chain the new node.
1921 Interp_Map.Increment_Last;
1922 Interp_Map.Table (Map_Ptr).Next := Interp_Map.Last;
1923 end if;
1925 Interp_Map.Table (Interp_Map.Last) := (N, All_Interp.Last, No_Entry);
1926 Set_Is_Overloaded (N, True);
1927 end New_Interps;
1929 ---------------------------
1930 -- Operator_Matches_Spec --
1931 ---------------------------
1933 function Operator_Matches_Spec (Op, New_S : Entity_Id) return Boolean is
1934 Op_Name : constant Name_Id := Chars (Op);
1935 T : constant Entity_Id := Etype (New_S);
1936 New_F : Entity_Id;
1937 Old_F : Entity_Id;
1938 Num : Int;
1939 T1 : Entity_Id;
1940 T2 : Entity_Id;
1942 begin
1943 -- To verify that a predefined operator matches a given signature,
1944 -- do a case analysis of the operator classes. Function can have one
1945 -- or two formals and must have the proper result type.
1947 New_F := First_Formal (New_S);
1948 Old_F := First_Formal (Op);
1949 Num := 0;
1951 while Present (New_F) and then Present (Old_F) loop
1952 Num := Num + 1;
1953 Next_Formal (New_F);
1954 Next_Formal (Old_F);
1955 end loop;
1957 -- Definite mismatch if different number of parameters
1959 if Present (Old_F) or else Present (New_F) then
1960 return False;
1962 -- Unary operators
1964 elsif Num = 1 then
1965 T1 := Etype (First_Formal (New_S));
1967 if Op_Name = Name_Op_Subtract
1968 or else Op_Name = Name_Op_Add
1969 or else Op_Name = Name_Op_Abs
1970 then
1971 return Base_Type (T1) = Base_Type (T)
1972 and then Is_Numeric_Type (T);
1974 elsif Op_Name = Name_Op_Not then
1975 return Base_Type (T1) = Base_Type (T)
1976 and then Valid_Boolean_Arg (Base_Type (T));
1978 else
1979 return False;
1980 end if;
1982 -- Binary operators
1984 else
1985 T1 := Etype (First_Formal (New_S));
1986 T2 := Etype (Next_Formal (First_Formal (New_S)));
1988 if Op_Name = Name_Op_And or else Op_Name = Name_Op_Or
1989 or else Op_Name = Name_Op_Xor
1990 then
1991 return Base_Type (T1) = Base_Type (T2)
1992 and then Base_Type (T1) = Base_Type (T)
1993 and then Valid_Boolean_Arg (Base_Type (T));
1995 elsif Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne then
1996 return Base_Type (T1) = Base_Type (T2)
1997 and then not Is_Limited_Type (T1)
1998 and then Is_Boolean_Type (T);
2000 elsif Op_Name = Name_Op_Lt or else Op_Name = Name_Op_Le
2001 or else Op_Name = Name_Op_Gt or else Op_Name = Name_Op_Ge
2002 then
2003 return Base_Type (T1) = Base_Type (T2)
2004 and then Valid_Comparison_Arg (T1)
2005 and then Is_Boolean_Type (T);
2007 elsif Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
2008 return Base_Type (T1) = Base_Type (T2)
2009 and then Base_Type (T1) = Base_Type (T)
2010 and then Is_Numeric_Type (T);
2012 -- for division and multiplication, a user-defined function does
2013 -- not match the predefined universal_fixed operation, except in
2014 -- Ada83 mode.
2016 elsif Op_Name = Name_Op_Divide then
2017 return (Base_Type (T1) = Base_Type (T2)
2018 and then Base_Type (T1) = Base_Type (T)
2019 and then Is_Numeric_Type (T)
2020 and then (not Is_Fixed_Point_Type (T)
2021 or else Ada_Version = Ada_83))
2023 -- Mixed_Mode operations on fixed-point types
2025 or else (Base_Type (T1) = Base_Type (T)
2026 and then Base_Type (T2) = Base_Type (Standard_Integer)
2027 and then Is_Fixed_Point_Type (T))
2029 -- A user defined operator can also match (and hide) a mixed
2030 -- operation on universal literals.
2032 or else (Is_Integer_Type (T2)
2033 and then Is_Floating_Point_Type (T1)
2034 and then Base_Type (T1) = Base_Type (T));
2036 elsif Op_Name = Name_Op_Multiply then
2037 return (Base_Type (T1) = Base_Type (T2)
2038 and then Base_Type (T1) = Base_Type (T)
2039 and then Is_Numeric_Type (T)
2040 and then (not Is_Fixed_Point_Type (T)
2041 or else Ada_Version = Ada_83))
2043 -- Mixed_Mode operations on fixed-point types
2045 or else (Base_Type (T1) = Base_Type (T)
2046 and then Base_Type (T2) = Base_Type (Standard_Integer)
2047 and then Is_Fixed_Point_Type (T))
2049 or else (Base_Type (T2) = Base_Type (T)
2050 and then Base_Type (T1) = Base_Type (Standard_Integer)
2051 and then Is_Fixed_Point_Type (T))
2053 or else (Is_Integer_Type (T2)
2054 and then Is_Floating_Point_Type (T1)
2055 and then Base_Type (T1) = Base_Type (T))
2057 or else (Is_Integer_Type (T1)
2058 and then Is_Floating_Point_Type (T2)
2059 and then Base_Type (T2) = Base_Type (T));
2061 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
2062 return Base_Type (T1) = Base_Type (T2)
2063 and then Base_Type (T1) = Base_Type (T)
2064 and then Is_Integer_Type (T);
2066 elsif Op_Name = Name_Op_Expon then
2067 return Base_Type (T1) = Base_Type (T)
2068 and then Is_Numeric_Type (T)
2069 and then Base_Type (T2) = Base_Type (Standard_Integer);
2071 elsif Op_Name = Name_Op_Concat then
2072 return Is_Array_Type (T)
2073 and then (Base_Type (T) = Base_Type (Etype (Op)))
2074 and then (Base_Type (T1) = Base_Type (T)
2075 or else
2076 Base_Type (T1) = Base_Type (Component_Type (T)))
2077 and then (Base_Type (T2) = Base_Type (T)
2078 or else
2079 Base_Type (T2) = Base_Type (Component_Type (T)));
2081 else
2082 return False;
2083 end if;
2084 end if;
2085 end Operator_Matches_Spec;
2087 -------------------
2088 -- Remove_Interp --
2089 -------------------
2091 procedure Remove_Interp (I : in out Interp_Index) is
2092 II : Interp_Index;
2094 begin
2095 -- Find end of Interp list and copy downward to erase the discarded one
2097 II := I + 1;
2099 while Present (All_Interp.Table (II).Typ) loop
2100 II := II + 1;
2101 end loop;
2103 for J in I + 1 .. II loop
2104 All_Interp.Table (J - 1) := All_Interp.Table (J);
2105 end loop;
2107 -- Back up interp. index to insure that iterator will pick up next
2108 -- available interpretation.
2110 I := I - 1;
2111 end Remove_Interp;
2113 ------------------
2114 -- Save_Interps --
2115 ------------------
2117 procedure Save_Interps (Old_N : Node_Id; New_N : Node_Id) is
2118 Map_Ptr : Int;
2119 O_N : Node_Id := Old_N;
2121 begin
2122 if Is_Overloaded (Old_N) then
2123 if Nkind (Old_N) = N_Selected_Component
2124 and then Is_Overloaded (Selector_Name (Old_N))
2125 then
2126 O_N := Selector_Name (Old_N);
2127 end if;
2129 Map_Ptr := Headers (Hash (O_N));
2131 while Interp_Map.Table (Map_Ptr).Node /= O_N loop
2132 Map_Ptr := Interp_Map.Table (Map_Ptr).Next;
2133 pragma Assert (Map_Ptr /= No_Entry);
2134 end loop;
2136 New_Interps (New_N);
2137 Interp_Map.Table (Interp_Map.Last).Index :=
2138 Interp_Map.Table (Map_Ptr).Index;
2139 end if;
2140 end Save_Interps;
2142 -------------------
2143 -- Specific_Type --
2144 -------------------
2146 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
2147 B1 : constant Entity_Id := Base_Type (T1);
2148 B2 : constant Entity_Id := Base_Type (T2);
2150 function Is_Remote_Access (T : Entity_Id) return Boolean;
2151 -- Check whether T is the equivalent type of a remote access type.
2152 -- If distribution is enabled, T is a legal context for Null.
2154 ----------------------
2155 -- Is_Remote_Access --
2156 ----------------------
2158 function Is_Remote_Access (T : Entity_Id) return Boolean is
2159 begin
2160 return Is_Record_Type (T)
2161 and then (Is_Remote_Call_Interface (T)
2162 or else Is_Remote_Types (T))
2163 and then Present (Corresponding_Remote_Type (T))
2164 and then Is_Access_Type (Corresponding_Remote_Type (T));
2165 end Is_Remote_Access;
2167 -- Start of processing for Specific_Type
2169 begin
2170 if T1 = Any_Type or else T2 = Any_Type then
2171 return Any_Type;
2172 end if;
2174 if B1 = B2 then
2175 return B1;
2177 elsif False
2178 or else (T1 = Universal_Integer and then Is_Integer_Type (T2))
2179 or else (T1 = Universal_Real and then Is_Real_Type (T2))
2180 or else (T1 = Universal_Fixed and then Is_Fixed_Point_Type (T2))
2181 or else (T1 = Any_Fixed and then Is_Fixed_Point_Type (T2))
2182 then
2183 return B2;
2185 elsif False
2186 or else (T2 = Universal_Integer and then Is_Integer_Type (T1))
2187 or else (T2 = Universal_Real and then Is_Real_Type (T1))
2188 or else (T2 = Universal_Fixed and then Is_Fixed_Point_Type (T1))
2189 or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1))
2190 then
2191 return B1;
2193 elsif T2 = Any_String and then Is_String_Type (T1) then
2194 return B1;
2196 elsif T1 = Any_String and then Is_String_Type (T2) then
2197 return B2;
2199 elsif T2 = Any_Character and then Is_Character_Type (T1) then
2200 return B1;
2202 elsif T1 = Any_Character and then Is_Character_Type (T2) then
2203 return B2;
2205 elsif T1 = Any_Access
2206 and then (Is_Access_Type (T2) or else Is_Remote_Access (T2))
2207 then
2208 return T2;
2210 elsif T2 = Any_Access
2211 and then (Is_Access_Type (T1) or else Is_Remote_Access (T1))
2212 then
2213 return T1;
2215 elsif T2 = Any_Composite
2216 and then Ekind (T1) in E_Array_Type .. E_Record_Subtype
2217 then
2218 return T1;
2220 elsif T1 = Any_Composite
2221 and then Ekind (T2) in E_Array_Type .. E_Record_Subtype
2222 then
2223 return T2;
2225 elsif T1 = Any_Modular and then Is_Modular_Integer_Type (T2) then
2226 return T2;
2228 elsif T2 = Any_Modular and then Is_Modular_Integer_Type (T1) then
2229 return T1;
2231 -- Special cases for equality operators (all other predefined
2232 -- operators can never apply to tagged types)
2234 elsif Is_Class_Wide_Type (T1)
2235 and then Is_Ancestor (Root_Type (T1), T2)
2236 then
2237 return T1;
2239 elsif Is_Class_Wide_Type (T2)
2240 and then Is_Ancestor (Root_Type (T2), T1)
2241 then
2242 return T2;
2244 elsif (Ekind (B1) = E_Access_Subprogram_Type
2245 or else
2246 Ekind (B1) = E_Access_Protected_Subprogram_Type)
2247 and then Ekind (Designated_Type (B1)) /= E_Subprogram_Type
2248 and then Is_Access_Type (T2)
2249 then
2250 return T2;
2252 elsif (Ekind (B2) = E_Access_Subprogram_Type
2253 or else
2254 Ekind (B2) = E_Access_Protected_Subprogram_Type)
2255 and then Ekind (Designated_Type (B2)) /= E_Subprogram_Type
2256 and then Is_Access_Type (T1)
2257 then
2258 return T1;
2260 elsif (Ekind (T1) = E_Allocator_Type
2261 or else Ekind (T1) = E_Access_Attribute_Type
2262 or else Ekind (T1) = E_Anonymous_Access_Type)
2263 and then Is_Access_Type (T2)
2264 then
2265 return T2;
2267 elsif (Ekind (T2) = E_Allocator_Type
2268 or else Ekind (T2) = E_Access_Attribute_Type
2269 or else Ekind (T2) = E_Anonymous_Access_Type)
2270 and then Is_Access_Type (T1)
2271 then
2272 return T1;
2274 -- If none of the above cases applies, types are not compatible.
2276 else
2277 return Any_Type;
2278 end if;
2279 end Specific_Type;
2281 -----------------------
2282 -- Valid_Boolean_Arg --
2283 -----------------------
2285 -- In addition to booleans and arrays of booleans, we must include
2286 -- aggregates as valid boolean arguments, because in the first pass
2287 -- of resolution their components are not examined. If it turns out not
2288 -- to be an aggregate of booleans, this will be diagnosed in Resolve.
2289 -- Any_Composite must be checked for prior to the array type checks
2290 -- because Any_Composite does not have any associated indexes.
2292 function Valid_Boolean_Arg (T : Entity_Id) return Boolean is
2293 begin
2294 return Is_Boolean_Type (T)
2295 or else T = Any_Composite
2296 or else (Is_Array_Type (T)
2297 and then T /= Any_String
2298 and then Number_Dimensions (T) = 1
2299 and then Is_Boolean_Type (Component_Type (T))
2300 and then (not Is_Private_Composite (T)
2301 or else In_Instance)
2302 and then (not Is_Limited_Composite (T)
2303 or else In_Instance))
2304 or else Is_Modular_Integer_Type (T)
2305 or else T = Universal_Integer;
2306 end Valid_Boolean_Arg;
2308 --------------------------
2309 -- Valid_Comparison_Arg --
2310 --------------------------
2312 function Valid_Comparison_Arg (T : Entity_Id) return Boolean is
2313 begin
2315 if T = Any_Composite then
2316 return False;
2317 elsif Is_Discrete_Type (T)
2318 or else Is_Real_Type (T)
2319 then
2320 return True;
2321 elsif Is_Array_Type (T)
2322 and then Number_Dimensions (T) = 1
2323 and then Is_Discrete_Type (Component_Type (T))
2324 and then (not Is_Private_Composite (T)
2325 or else In_Instance)
2326 and then (not Is_Limited_Composite (T)
2327 or else In_Instance)
2328 then
2329 return True;
2330 elsif Is_String_Type (T) then
2331 return True;
2332 else
2333 return False;
2334 end if;
2335 end Valid_Comparison_Arg;
2337 ---------------------
2338 -- Write_Overloads --
2339 ---------------------
2341 procedure Write_Overloads (N : Node_Id) is
2342 I : Interp_Index;
2343 It : Interp;
2344 Nam : Entity_Id;
2346 begin
2347 if not Is_Overloaded (N) then
2348 Write_Str ("Non-overloaded entity ");
2349 Write_Eol;
2350 Write_Entity_Info (Entity (N), " ");
2352 else
2353 Get_First_Interp (N, I, It);
2354 Write_Str ("Overloaded entity ");
2355 Write_Eol;
2356 Nam := It.Nam;
2358 while Present (Nam) loop
2359 Write_Entity_Info (Nam, " ");
2360 Write_Str ("=================");
2361 Write_Eol;
2362 Get_Next_Interp (I, It);
2363 Nam := It.Nam;
2364 end loop;
2365 end if;
2366 end Write_Overloads;
2368 ----------------------
2369 -- Write_Interp_Ref --
2370 ----------------------
2372 procedure Write_Interp_Ref (Map_Ptr : Int) is
2373 begin
2374 Write_Str (" Node: ");
2375 Write_Int (Int (Interp_Map.Table (Map_Ptr).Node));
2376 Write_Str (" Index: ");
2377 Write_Int (Int (Interp_Map.Table (Map_Ptr).Index));
2378 Write_Str (" Next: ");
2379 Write_Int (Int (Interp_Map.Table (Map_Ptr).Next));
2380 Write_Eol;
2381 end Write_Interp_Ref;
2383 end Sem_Type;