1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Debug; use Debug;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Errout; use Errout;
31 with Exp_Util; use Exp_Util;
32 with Fname; use Fname;
33 with Itypes; use Itypes;
35 with Lib.Xref; use Lib.Xref;
36 with Namet; use Namet;
37 with Namet.Sp; use Namet.Sp;
38 with Nlists; use Nlists;
39 with Nmake; use Nmake;
41 with Output; use Output;
42 with Restrict; use Restrict;
43 with Rident; use Rident;
45 with Sem_Cat; use Sem_Cat;
46 with Sem_Ch3; use Sem_Ch3;
47 with Sem_Ch6; use Sem_Ch6;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Disp; use Sem_Disp;
50 with Sem_Dist; use Sem_Dist;
51 with Sem_Eval; use Sem_Eval;
52 with Sem_Res; use Sem_Res;
53 with Sem_Util; use Sem_Util;
54 with Sem_Type; use Sem_Type;
55 with Stand; use Stand;
56 with Sinfo; use Sinfo;
57 with Snames; use Snames;
58 with Tbuild; use Tbuild;
60 package body Sem_Ch4 is
62 -----------------------
63 -- Local Subprograms --
64 -----------------------
66 procedure Analyze_Concatenation_Rest (N : Node_Id);
67 -- Does the "rest" of the work of Analyze_Concatenation, after the left
68 -- operand has been analyzed. See Analyze_Concatenation for details.
70 procedure Analyze_Expression (N : Node_Id);
71 -- For expressions that are not names, this is just a call to analyze.
72 -- If the expression is a name, it may be a call to a parameterless
73 -- function, and if so must be converted into an explicit call node
74 -- and analyzed as such. This deproceduring must be done during the first
75 -- pass of overload resolution, because otherwise a procedure call with
76 -- overloaded actuals may fail to resolve.
78 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
79 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
80 -- is an operator name or an expanded name whose selector is an operator
81 -- name, and one possible interpretation is as a predefined operator.
83 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
84 -- If the prefix of a selected_component is overloaded, the proper
85 -- interpretation that yields a record type with the proper selector
86 -- name must be selected.
88 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
89 -- Procedure to analyze a user defined binary operator, which is resolved
90 -- like a function, but instead of a list of actuals it is presented
91 -- with the left and right operands of an operator node.
93 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
94 -- Procedure to analyze a user defined unary operator, which is resolved
95 -- like a function, but instead of a list of actuals, it is presented with
96 -- the operand of the operator node.
98 procedure Ambiguous_Operands (N : Node_Id);
99 -- for equality, membership, and comparison operators with overloaded
100 -- arguments, list possible interpretations.
102 procedure Analyze_One_Call
106 Success : out Boolean;
107 Skip_First : Boolean := False);
108 -- Check one interpretation of an overloaded subprogram name for
109 -- compatibility with the types of the actuals in a call. If there is a
110 -- single interpretation which does not match, post error if Report is
113 -- Nam is the entity that provides the formals against which the actuals
114 -- are checked. Nam is either the name of a subprogram, or the internal
115 -- subprogram type constructed for an access_to_subprogram. If the actuals
116 -- are compatible with Nam, then Nam is added to the list of candidate
117 -- interpretations for N, and Success is set to True.
119 -- The flag Skip_First is used when analyzing a call that was rewritten
120 -- from object notation. In this case the first actual may have to receive
121 -- an explicit dereference, depending on the first formal of the operation
122 -- being called. The caller will have verified that the object is legal
123 -- for the call. If the remaining parameters match, the first parameter
124 -- will rewritten as a dereference if needed, prior to completing analysis.
126 procedure Check_Misspelled_Selector
129 -- Give possible misspelling diagnostic if Sel is likely to be
130 -- a misspelling of one of the selectors of the Prefix.
131 -- This is called by Analyze_Selected_Component after producing
132 -- an invalid selector error message.
134 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
135 -- Verify that type T is declared in scope S. Used to find interpretations
136 -- for operators given by expanded names. This is abstracted as a separate
137 -- function to handle extensions to System, where S is System, but T is
138 -- declared in the extension.
140 procedure Find_Arithmetic_Types
144 -- L and R are the operands of an arithmetic operator. Find
145 -- consistent pairs of interpretations for L and R that have a
146 -- numeric type consistent with the semantics of the operator.
148 procedure Find_Comparison_Types
152 -- L and R are operands of a comparison operator. Find consistent
153 -- pairs of interpretations for L and R.
155 procedure Find_Concatenation_Types
159 -- For the four varieties of concatenation
161 procedure Find_Equality_Types
165 -- Ditto for equality operators
167 procedure Find_Boolean_Types
171 -- Ditto for binary logical operations
173 procedure Find_Negation_Types
177 -- Find consistent interpretation for operand of negation operator
179 procedure Find_Non_Universal_Interpretations
184 -- For equality and comparison operators, the result is always boolean,
185 -- and the legality of the operation is determined from the visibility
186 -- of the operand types. If one of the operands has a universal interpre-
187 -- tation, the legality check uses some compatible non-universal
188 -- interpretation of the other operand. N can be an operator node, or
189 -- a function call whose name is an operator designator.
191 function Find_Primitive_Operation (N : Node_Id) return Boolean;
192 -- Find candidate interpretations for the name Obj.Proc when it appears
193 -- in a subprogram renaming declaration.
195 procedure Find_Unary_Types
199 -- Unary arithmetic types: plus, minus, abs
201 procedure Check_Arithmetic_Pair
205 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
206 -- types for left and right operand. Determine whether they constitute
207 -- a valid pair for the given operator, and record the corresponding
208 -- interpretation of the operator node. The node N may be an operator
209 -- node (the usual case) or a function call whose prefix is an operator
210 -- designator. In both cases Op_Id is the operator name itself.
212 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
213 -- Give detailed information on overloaded call where none of the
214 -- interpretations match. N is the call node, Nam the designator for
215 -- the overloaded entity being called.
217 function Junk_Operand (N : Node_Id) return Boolean;
218 -- Test for an operand that is an inappropriate entity (e.g. a package
219 -- name or a label). If so, issue an error message and return True. If
220 -- the operand is not an inappropriate entity kind, return False.
222 procedure Operator_Check (N : Node_Id);
223 -- Verify that an operator has received some valid interpretation. If none
224 -- was found, determine whether a use clause would make the operation
225 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
226 -- every type compatible with the operator, even if the operator for the
227 -- type is not directly visible. The routine uses this type to emit a more
228 -- informative message.
230 function Process_Implicit_Dereference_Prefix
232 P : Node_Id) return Entity_Id;
233 -- Called when P is the prefix of an implicit dereference, denoting an
234 -- object E. The function returns the designated type of the prefix, taking
235 -- into account that the designated type of an anonymous access type may be
236 -- a limited view, when the non-limited view is visible.
237 -- If in semantics only mode (-gnatc or generic), the function also records
238 -- that the prefix is a reference to E, if any. Normally, such a reference
239 -- is generated only when the implicit dereference is expanded into an
240 -- explicit one, but for consistency we must generate the reference when
241 -- expansion is disabled as well.
243 procedure Remove_Abstract_Operations (N : Node_Id);
244 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
245 -- operation is not a candidate interpretation.
247 function Try_Indexed_Call
251 Skip_First : Boolean) return Boolean;
252 -- If a function has defaults for all its actuals, a call to it may in fact
253 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
254 -- interpretation as an indexing, prior to analysis as a call. If both are
255 -- possible, the node is overloaded with both interpretations (same symbol
256 -- but two different types). If the call is written in prefix form, the
257 -- prefix becomes the first parameter in the call, and only the remaining
258 -- actuals must be checked for the presence of defaults.
260 function Try_Indirect_Call
263 Typ : Entity_Id) return Boolean;
264 -- Similarly, a function F that needs no actuals can return an access to a
265 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
266 -- the call may be overloaded with both interpretations.
268 function Try_Object_Operation (N : Node_Id) return Boolean;
269 -- Ada 2005 (AI-252): Support the object.operation notation
271 procedure wpo (T : Entity_Id);
272 pragma Warnings (Off, wpo);
273 -- Used for debugging: obtain list of primitive operations even if
274 -- type is not frozen and dispatch table is not built yet.
276 ------------------------
277 -- Ambiguous_Operands --
278 ------------------------
280 procedure Ambiguous_Operands (N : Node_Id) is
281 procedure List_Operand_Interps (Opnd : Node_Id);
283 --------------------------
284 -- List_Operand_Interps --
285 --------------------------
287 procedure List_Operand_Interps (Opnd : Node_Id) is
292 if Is_Overloaded (Opnd) then
293 if Nkind (Opnd) in N_Op then
295 elsif Nkind (Opnd) = N_Function_Call then
305 if Opnd = Left_Opnd (N) then
307 ("\left operand has the following interpretations", N);
310 ("\right operand has the following interpretations", N);
314 List_Interps (Nam, Err);
315 end List_Operand_Interps;
317 -- Start of processing for Ambiguous_Operands
320 if Nkind (N) in N_Membership_Test then
321 Error_Msg_N ("ambiguous operands for membership", N);
323 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
324 Error_Msg_N ("ambiguous operands for equality", N);
327 Error_Msg_N ("ambiguous operands for comparison", N);
330 if All_Errors_Mode then
331 List_Operand_Interps (Left_Opnd (N));
332 List_Operand_Interps (Right_Opnd (N));
334 Error_Msg_N ("\use -gnatf switch for details", N);
336 end Ambiguous_Operands;
338 -----------------------
339 -- Analyze_Aggregate --
340 -----------------------
342 -- Most of the analysis of Aggregates requires that the type be known,
343 -- and is therefore put off until resolution.
345 procedure Analyze_Aggregate (N : Node_Id) is
347 if No (Etype (N)) then
348 Set_Etype (N, Any_Composite);
350 end Analyze_Aggregate;
352 -----------------------
353 -- Analyze_Allocator --
354 -----------------------
356 procedure Analyze_Allocator (N : Node_Id) is
357 Loc : constant Source_Ptr := Sloc (N);
358 Sav_Errs : constant Nat := Serious_Errors_Detected;
359 E : Node_Id := Expression (N);
360 Acc_Type : Entity_Id;
364 -- In accordance with H.4(7), the No_Allocators restriction only applies
365 -- to user-written allocators.
367 if Comes_From_Source (N) then
368 Check_Restriction (No_Allocators, N);
371 if Nkind (E) = N_Qualified_Expression then
372 Acc_Type := Create_Itype (E_Allocator_Type, N);
373 Set_Etype (Acc_Type, Acc_Type);
374 Find_Type (Subtype_Mark (E));
376 -- Analyze the qualified expression, and apply the name resolution
377 -- rule given in 4.7 (3).
380 Type_Id := Etype (E);
381 Set_Directly_Designated_Type (Acc_Type, Type_Id);
383 Resolve (Expression (E), Type_Id);
385 if Is_Limited_Type (Type_Id)
386 and then Comes_From_Source (N)
387 and then not In_Instance_Body
389 if not OK_For_Limited_Init (Expression (E)) then
390 Error_Msg_N ("initialization not allowed for limited types", N);
391 Explain_Limited_Type (Type_Id, N);
395 -- A qualified expression requires an exact match of the type,
396 -- class-wide matching is not allowed.
398 -- if Is_Class_Wide_Type (Type_Id)
399 -- and then Base_Type
400 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
402 -- Wrong_Type (Expression (E), Type_Id);
405 Check_Non_Static_Context (Expression (E));
407 -- We don't analyze the qualified expression itself because it's
408 -- part of the allocator
410 Set_Etype (E, Type_Id);
412 -- Case where allocator has a subtype indication
417 Base_Typ : Entity_Id;
420 -- If the allocator includes a N_Subtype_Indication then a
421 -- constraint is present, otherwise the node is a subtype mark.
422 -- Introduce an explicit subtype declaration into the tree
423 -- defining some anonymous subtype and rewrite the allocator to
424 -- use this subtype rather than the subtype indication.
426 -- It is important to introduce the explicit subtype declaration
427 -- so that the bounds of the subtype indication are attached to
428 -- the tree in case the allocator is inside a generic unit.
430 if Nkind (E) = N_Subtype_Indication then
432 -- A constraint is only allowed for a composite type in Ada
433 -- 95. In Ada 83, a constraint is also allowed for an
434 -- access-to-composite type, but the constraint is ignored.
436 Find_Type (Subtype_Mark (E));
437 Base_Typ := Entity (Subtype_Mark (E));
439 if Is_Elementary_Type (Base_Typ) then
440 if not (Ada_Version = Ada_83
441 and then Is_Access_Type (Base_Typ))
443 Error_Msg_N ("constraint not allowed here", E);
445 if Nkind (Constraint (E)) =
446 N_Index_Or_Discriminant_Constraint
449 ("\if qualified expression was meant, " &
450 "use apostrophe", Constraint (E));
454 -- Get rid of the bogus constraint:
456 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
457 Analyze_Allocator (N);
460 -- Ada 2005, AI-363: if the designated type has a constrained
461 -- partial view, it cannot receive a discriminant constraint,
462 -- and the allocated object is unconstrained.
464 elsif Ada_Version >= Ada_05
465 and then Has_Constrained_Partial_View (Base_Typ)
468 ("constraint no allowed when type " &
469 "has a constrained partial view", Constraint (E));
472 if Expander_Active then
474 Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
477 Make_Subtype_Declaration (Loc,
478 Defining_Identifier => Def_Id,
479 Subtype_Indication => Relocate_Node (E)));
481 if Sav_Errs /= Serious_Errors_Detected
482 and then Nkind (Constraint (E)) =
483 N_Index_Or_Discriminant_Constraint
486 ("if qualified expression was meant, " &
487 "use apostrophe!", Constraint (E));
490 E := New_Occurrence_Of (Def_Id, Loc);
491 Rewrite (Expression (N), E);
495 Type_Id := Process_Subtype (E, N);
496 Acc_Type := Create_Itype (E_Allocator_Type, N);
497 Set_Etype (Acc_Type, Acc_Type);
498 Set_Directly_Designated_Type (Acc_Type, Type_Id);
499 Check_Fully_Declared (Type_Id, N);
503 if Can_Never_Be_Null (Type_Id) then
504 Error_Msg_N ("(Ada 2005) qualified expression required",
508 -- Check restriction against dynamically allocated protected
509 -- objects. Note that when limited aggregates are supported,
510 -- a similar test should be applied to an allocator with a
511 -- qualified expression ???
513 if Is_Protected_Type (Type_Id) then
514 Check_Restriction (No_Protected_Type_Allocators, N);
517 -- Check for missing initialization. Skip this check if we already
518 -- had errors on analyzing the allocator, since in that case these
519 -- are probably cascaded errors.
521 if Is_Indefinite_Subtype (Type_Id)
522 and then Serious_Errors_Detected = Sav_Errs
524 if Is_Class_Wide_Type (Type_Id) then
526 ("initialization required in class-wide allocation", N);
528 if Ada_Version < Ada_05
529 and then Is_Limited_Type (Type_Id)
531 Error_Msg_N ("unconstrained allocation not allowed", N);
533 if Is_Array_Type (Type_Id) then
535 ("\constraint with array bounds required", N);
537 elsif Has_Unknown_Discriminants (Type_Id) then
540 else pragma Assert (Has_Discriminants (Type_Id));
542 ("\constraint with discriminant values required", N);
545 -- Limited Ada 2005 and general non-limited case
549 ("uninitialized unconstrained allocation not allowed",
552 if Is_Array_Type (Type_Id) then
554 ("\qualified expression or constraint with " &
555 "array bounds required", N);
557 elsif Has_Unknown_Discriminants (Type_Id) then
558 Error_Msg_N ("\qualified expression required", N);
560 else pragma Assert (Has_Discriminants (Type_Id));
562 ("\qualified expression or constraint with " &
563 "discriminant values required", N);
571 if Is_Abstract_Type (Type_Id) then
572 Error_Msg_N ("cannot allocate abstract object", E);
575 if Has_Task (Designated_Type (Acc_Type)) then
576 Check_Restriction (No_Tasking, N);
577 Check_Restriction (Max_Tasks, N);
578 Check_Restriction (No_Task_Allocators, N);
581 -- If the No_Streams restriction is set, check that the type of the
582 -- object is not, and does not contain, any subtype derived from
583 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
584 -- Has_Stream just for efficiency reasons. There is no point in
585 -- spending time on a Has_Stream check if the restriction is not set.
587 if Restrictions.Set (No_Streams) then
588 if Has_Stream (Designated_Type (Acc_Type)) then
589 Check_Restriction (No_Streams, N);
593 Set_Etype (N, Acc_Type);
595 if not Is_Library_Level_Entity (Acc_Type) then
596 Check_Restriction (No_Local_Allocators, N);
599 if Serious_Errors_Detected > Sav_Errs then
600 Set_Error_Posted (N);
601 Set_Etype (N, Any_Type);
603 end Analyze_Allocator;
605 ---------------------------
606 -- Analyze_Arithmetic_Op --
607 ---------------------------
609 procedure Analyze_Arithmetic_Op (N : Node_Id) is
610 L : constant Node_Id := Left_Opnd (N);
611 R : constant Node_Id := Right_Opnd (N);
615 Candidate_Type := Empty;
616 Analyze_Expression (L);
617 Analyze_Expression (R);
619 -- If the entity is already set, the node is the instantiation of a
620 -- generic node with a non-local reference, or was manufactured by a
621 -- call to Make_Op_xxx. In either case the entity is known to be valid,
622 -- and we do not need to collect interpretations, instead we just get
623 -- the single possible interpretation.
627 if Present (Op_Id) then
628 if Ekind (Op_Id) = E_Operator then
630 if Nkind_In (N, N_Op_Divide, N_Op_Mod, N_Op_Multiply, N_Op_Rem)
631 and then Treat_Fixed_As_Integer (N)
635 Set_Etype (N, Any_Type);
636 Find_Arithmetic_Types (L, R, Op_Id, N);
640 Set_Etype (N, Any_Type);
641 Add_One_Interp (N, Op_Id, Etype (Op_Id));
644 -- Entity is not already set, so we do need to collect interpretations
647 Op_Id := Get_Name_Entity_Id (Chars (N));
648 Set_Etype (N, Any_Type);
650 while Present (Op_Id) loop
651 if Ekind (Op_Id) = E_Operator
652 and then Present (Next_Entity (First_Entity (Op_Id)))
654 Find_Arithmetic_Types (L, R, Op_Id, N);
656 -- The following may seem superfluous, because an operator cannot
657 -- be generic, but this ignores the cleverness of the author of
660 elsif Is_Overloadable (Op_Id) then
661 Analyze_User_Defined_Binary_Op (N, Op_Id);
664 Op_Id := Homonym (Op_Id);
669 end Analyze_Arithmetic_Op;
675 -- Function, procedure, and entry calls are checked here. The Name in
676 -- the call may be overloaded. The actuals have been analyzed and may
677 -- themselves be overloaded. On exit from this procedure, the node N
678 -- may have zero, one or more interpretations. In the first case an
679 -- error message is produced. In the last case, the node is flagged
680 -- as overloaded and the interpretations are collected in All_Interp.
682 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
683 -- the type-checking is similar to that of other calls.
685 procedure Analyze_Call (N : Node_Id) is
686 Actuals : constant List_Id := Parameter_Associations (N);
691 Success : Boolean := False;
693 Deref : Boolean := False;
694 -- Flag indicates whether an interpretation of the prefix is a
695 -- parameterless call that returns an access_to_subprogram.
697 function Name_Denotes_Function return Boolean;
698 -- If the type of the name is an access to subprogram, this may be the
699 -- type of a name, or the return type of the function being called. If
700 -- the name is not an entity then it can denote a protected function.
701 -- Until we distinguish Etype from Return_Type, we must use this routine
702 -- to resolve the meaning of the name in the call.
704 procedure No_Interpretation;
705 -- Output error message when no valid interpretation exists
707 ---------------------------
708 -- Name_Denotes_Function --
709 ---------------------------
711 function Name_Denotes_Function return Boolean is
713 if Is_Entity_Name (Nam) then
714 return Ekind (Entity (Nam)) = E_Function;
716 elsif Nkind (Nam) = N_Selected_Component then
717 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
722 end Name_Denotes_Function;
724 -----------------------
725 -- No_Interpretation --
726 -----------------------
728 procedure No_Interpretation is
729 L : constant Boolean := Is_List_Member (N);
730 K : constant Node_Kind := Nkind (Parent (N));
733 -- If the node is in a list whose parent is not an expression then it
734 -- must be an attempted procedure call.
736 if L and then K not in N_Subexpr then
737 if Ekind (Entity (Nam)) = E_Generic_Procedure then
739 ("must instantiate generic procedure& before call",
743 ("procedure or entry name expected", Nam);
746 -- Check for tasking cases where only an entry call will do
749 and then Nkind_In (K, N_Entry_Call_Alternative,
750 N_Triggering_Alternative)
752 Error_Msg_N ("entry name expected", Nam);
754 -- Otherwise give general error message
757 Error_Msg_N ("invalid prefix in call", Nam);
759 end No_Interpretation;
761 -- Start of processing for Analyze_Call
764 -- Initialize the type of the result of the call to the error type,
765 -- which will be reset if the type is successfully resolved.
767 Set_Etype (N, Any_Type);
771 if not Is_Overloaded (Nam) then
773 -- Only one interpretation to check
775 if Ekind (Etype (Nam)) = E_Subprogram_Type then
776 Nam_Ent := Etype (Nam);
778 -- If the prefix is an access_to_subprogram, this may be an indirect
779 -- call. This is the case if the name in the call is not an entity
780 -- name, or if it is a function name in the context of a procedure
781 -- call. In this latter case, we have a call to a parameterless
782 -- function that returns a pointer_to_procedure which is the entity
783 -- being called. Finally, F (X) may be a call to a parameterless
784 -- function that returns a pointer to a function with parameters.
786 elsif Is_Access_Type (Etype (Nam))
787 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
789 (not Name_Denotes_Function
790 or else Nkind (N) = N_Procedure_Call_Statement
792 (Nkind (Parent (N)) /= N_Explicit_Dereference
793 and then Is_Entity_Name (Nam)
794 and then No (First_Formal (Entity (Nam)))
795 and then Present (Actuals)))
797 Nam_Ent := Designated_Type (Etype (Nam));
798 Insert_Explicit_Dereference (Nam);
800 -- Selected component case. Simple entry or protected operation,
801 -- where the entry name is given by the selector name.
803 elsif Nkind (Nam) = N_Selected_Component then
804 Nam_Ent := Entity (Selector_Name (Nam));
806 if Ekind (Nam_Ent) /= E_Entry
807 and then Ekind (Nam_Ent) /= E_Entry_Family
808 and then Ekind (Nam_Ent) /= E_Function
809 and then Ekind (Nam_Ent) /= E_Procedure
811 Error_Msg_N ("name in call is not a callable entity", Nam);
812 Set_Etype (N, Any_Type);
816 -- If the name is an Indexed component, it can be a call to a member
817 -- of an entry family. The prefix must be a selected component whose
818 -- selector is the entry. Analyze_Procedure_Call normalizes several
819 -- kinds of call into this form.
821 elsif Nkind (Nam) = N_Indexed_Component then
822 if Nkind (Prefix (Nam)) = N_Selected_Component then
823 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
825 Error_Msg_N ("name in call is not a callable entity", Nam);
826 Set_Etype (N, Any_Type);
830 elsif not Is_Entity_Name (Nam) then
831 Error_Msg_N ("name in call is not a callable entity", Nam);
832 Set_Etype (N, Any_Type);
836 Nam_Ent := Entity (Nam);
838 -- If no interpretations, give error message
840 if not Is_Overloadable (Nam_Ent) then
846 -- Operations generated for RACW stub types are called only through
847 -- dispatching, and can never be the static interpretation of a call.
849 if Is_RACW_Stub_Type_Operation (Nam_Ent) then
854 Analyze_One_Call (N, Nam_Ent, True, Success);
856 -- If this is an indirect call, the return type of the access_to
857 -- subprogram may be an incomplete type. At the point of the call,
858 -- use the full type if available, and at the same time update
859 -- the return type of the access_to_subprogram.
862 and then Nkind (Nam) = N_Explicit_Dereference
863 and then Ekind (Etype (N)) = E_Incomplete_Type
864 and then Present (Full_View (Etype (N)))
866 Set_Etype (N, Full_View (Etype (N)));
867 Set_Etype (Nam_Ent, Etype (N));
871 -- An overloaded selected component must denote overloaded operations
872 -- of a concurrent type. The interpretations are attached to the
873 -- simple name of those operations.
875 if Nkind (Nam) = N_Selected_Component then
876 Nam := Selector_Name (Nam);
879 Get_First_Interp (Nam, X, It);
881 while Present (It.Nam) loop
885 -- Name may be call that returns an access to subprogram, or more
886 -- generally an overloaded expression one of whose interpretations
887 -- yields an access to subprogram. If the name is an entity, we
888 -- do not dereference, because the node is a call that returns
889 -- the access type: note difference between f(x), where the call
890 -- may return an access subprogram type, and f(x)(y), where the
891 -- type returned by the call to f is implicitly dereferenced to
892 -- analyze the outer call.
894 if Is_Access_Type (Nam_Ent) then
895 Nam_Ent := Designated_Type (Nam_Ent);
897 elsif Is_Access_Type (Etype (Nam_Ent))
899 (not Is_Entity_Name (Nam)
900 or else Nkind (N) = N_Procedure_Call_Statement)
901 and then Ekind (Designated_Type (Etype (Nam_Ent)))
904 Nam_Ent := Designated_Type (Etype (Nam_Ent));
906 if Is_Entity_Name (Nam) then
911 Analyze_One_Call (N, Nam_Ent, False, Success);
913 -- If the interpretation succeeds, mark the proper type of the
914 -- prefix (any valid candidate will do). If not, remove the
915 -- candidate interpretation. This only needs to be done for
916 -- overloaded protected operations, for other entities disambi-
917 -- guation is done directly in Resolve.
921 and then Nkind (Parent (N)) /= N_Explicit_Dereference
923 Set_Entity (Nam, It.Nam);
924 Insert_Explicit_Dereference (Nam);
925 Set_Etype (Nam, Nam_Ent);
928 Set_Etype (Nam, It.Typ);
931 elsif Nkind_In (Name (N), N_Selected_Component,
937 Get_Next_Interp (X, It);
940 -- If the name is the result of a function call, it can only
941 -- be a call to a function returning an access to subprogram.
942 -- Insert explicit dereference.
944 if Nkind (Nam) = N_Function_Call then
945 Insert_Explicit_Dereference (Nam);
948 if Etype (N) = Any_Type then
950 -- None of the interpretations is compatible with the actuals
952 Diagnose_Call (N, Nam);
954 -- Special checks for uninstantiated put routines
956 if Nkind (N) = N_Procedure_Call_Statement
957 and then Is_Entity_Name (Nam)
958 and then Chars (Nam) = Name_Put
959 and then List_Length (Actuals) = 1
962 Arg : constant Node_Id := First (Actuals);
966 if Nkind (Arg) = N_Parameter_Association then
967 Typ := Etype (Explicit_Actual_Parameter (Arg));
972 if Is_Signed_Integer_Type (Typ) then
974 ("possible missing instantiation of " &
975 "'Text_'I'O.'Integer_'I'O!", Nam);
977 elsif Is_Modular_Integer_Type (Typ) then
979 ("possible missing instantiation of " &
980 "'Text_'I'O.'Modular_'I'O!", Nam);
982 elsif Is_Floating_Point_Type (Typ) then
984 ("possible missing instantiation of " &
985 "'Text_'I'O.'Float_'I'O!", Nam);
987 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
989 ("possible missing instantiation of " &
990 "'Text_'I'O.'Fixed_'I'O!", Nam);
992 elsif Is_Decimal_Fixed_Point_Type (Typ) then
994 ("possible missing instantiation of " &
995 "'Text_'I'O.'Decimal_'I'O!", Nam);
997 elsif Is_Enumeration_Type (Typ) then
999 ("possible missing instantiation of " &
1000 "'Text_'I'O.'Enumeration_'I'O!", Nam);
1005 elsif not Is_Overloaded (N)
1006 and then Is_Entity_Name (Nam)
1008 -- Resolution yields a single interpretation. Verify that the
1009 -- reference has capitalization consistent with the declaration.
1011 Set_Entity_With_Style_Check (Nam, Entity (Nam));
1012 Generate_Reference (Entity (Nam), Nam);
1014 Set_Etype (Nam, Etype (Entity (Nam)));
1016 Remove_Abstract_Operations (N);
1023 ---------------------------
1024 -- Analyze_Comparison_Op --
1025 ---------------------------
1027 procedure Analyze_Comparison_Op (N : Node_Id) is
1028 L : constant Node_Id := Left_Opnd (N);
1029 R : constant Node_Id := Right_Opnd (N);
1030 Op_Id : Entity_Id := Entity (N);
1033 Set_Etype (N, Any_Type);
1034 Candidate_Type := Empty;
1036 Analyze_Expression (L);
1037 Analyze_Expression (R);
1039 if Present (Op_Id) then
1040 if Ekind (Op_Id) = E_Operator then
1041 Find_Comparison_Types (L, R, Op_Id, N);
1043 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1046 if Is_Overloaded (L) then
1047 Set_Etype (L, Intersect_Types (L, R));
1051 Op_Id := Get_Name_Entity_Id (Chars (N));
1052 while Present (Op_Id) loop
1053 if Ekind (Op_Id) = E_Operator then
1054 Find_Comparison_Types (L, R, Op_Id, N);
1056 Analyze_User_Defined_Binary_Op (N, Op_Id);
1059 Op_Id := Homonym (Op_Id);
1064 end Analyze_Comparison_Op;
1066 ---------------------------
1067 -- Analyze_Concatenation --
1068 ---------------------------
1070 procedure Analyze_Concatenation (N : Node_Id) is
1072 -- We wish to avoid deep recursion, because concatenations are often
1073 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1074 -- operands nonrecursively until we find something that is not a
1075 -- concatenation (A in this case), or has already been analyzed. We
1076 -- analyze that, and then walk back up the tree following Parent
1077 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1078 -- work at each level. The Parent pointers allow us to avoid recursion,
1079 -- and thus avoid running out of memory.
1085 Candidate_Type := Empty;
1087 -- The following code is equivalent to:
1089 -- Set_Etype (N, Any_Type);
1090 -- Analyze_Expression (Left_Opnd (N));
1091 -- Analyze_Concatenation_Rest (N);
1093 -- where the Analyze_Expression call recurses back here if the left
1094 -- operand is a concatenation.
1096 -- Walk down left operands
1099 Set_Etype (NN, Any_Type);
1100 L := Left_Opnd (NN);
1101 exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
1105 -- Now (given the above example) NN is A&B and L is A
1107 -- First analyze L ...
1109 Analyze_Expression (L);
1111 -- ... then walk NN back up until we reach N (where we started), calling
1112 -- Analyze_Concatenation_Rest along the way.
1115 Analyze_Concatenation_Rest (NN);
1119 end Analyze_Concatenation;
1121 --------------------------------
1122 -- Analyze_Concatenation_Rest --
1123 --------------------------------
1125 -- If the only one-dimensional array type in scope is String,
1126 -- this is the resulting type of the operation. Otherwise there
1127 -- will be a concatenation operation defined for each user-defined
1128 -- one-dimensional array.
1130 procedure Analyze_Concatenation_Rest (N : Node_Id) is
1131 L : constant Node_Id := Left_Opnd (N);
1132 R : constant Node_Id := Right_Opnd (N);
1133 Op_Id : Entity_Id := Entity (N);
1138 Analyze_Expression (R);
1140 -- If the entity is present, the node appears in an instance, and
1141 -- denotes a predefined concatenation operation. The resulting type is
1142 -- obtained from the arguments when possible. If the arguments are
1143 -- aggregates, the array type and the concatenation type must be
1146 if Present (Op_Id) then
1147 if Ekind (Op_Id) = E_Operator then
1149 LT := Base_Type (Etype (L));
1150 RT := Base_Type (Etype (R));
1152 if Is_Array_Type (LT)
1153 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1155 Add_One_Interp (N, Op_Id, LT);
1157 elsif Is_Array_Type (RT)
1158 and then LT = Base_Type (Component_Type (RT))
1160 Add_One_Interp (N, Op_Id, RT);
1162 -- If one operand is a string type or a user-defined array type,
1163 -- and the other is a literal, result is of the specific type.
1166 (Root_Type (LT) = Standard_String
1167 or else Scope (LT) /= Standard_Standard)
1168 and then Etype (R) = Any_String
1170 Add_One_Interp (N, Op_Id, LT);
1173 (Root_Type (RT) = Standard_String
1174 or else Scope (RT) /= Standard_Standard)
1175 and then Etype (L) = Any_String
1177 Add_One_Interp (N, Op_Id, RT);
1179 elsif not Is_Generic_Type (Etype (Op_Id)) then
1180 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1183 -- Type and its operations must be visible
1185 Set_Entity (N, Empty);
1186 Analyze_Concatenation (N);
1190 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1194 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1195 while Present (Op_Id) loop
1196 if Ekind (Op_Id) = E_Operator then
1198 -- Do not consider operators declared in dead code, they can
1199 -- not be part of the resolution.
1201 if Is_Eliminated (Op_Id) then
1204 Find_Concatenation_Types (L, R, Op_Id, N);
1208 Analyze_User_Defined_Binary_Op (N, Op_Id);
1211 Op_Id := Homonym (Op_Id);
1216 end Analyze_Concatenation_Rest;
1218 ------------------------------------
1219 -- Analyze_Conditional_Expression --
1220 ------------------------------------
1222 procedure Analyze_Conditional_Expression (N : Node_Id) is
1223 Condition : constant Node_Id := First (Expressions (N));
1224 Then_Expr : constant Node_Id := Next (Condition);
1225 Else_Expr : constant Node_Id := Next (Then_Expr);
1227 Analyze_Expression (Condition);
1228 Analyze_Expression (Then_Expr);
1229 Analyze_Expression (Else_Expr);
1230 Set_Etype (N, Etype (Then_Expr));
1231 end Analyze_Conditional_Expression;
1233 -------------------------
1234 -- Analyze_Equality_Op --
1235 -------------------------
1237 procedure Analyze_Equality_Op (N : Node_Id) is
1238 Loc : constant Source_Ptr := Sloc (N);
1239 L : constant Node_Id := Left_Opnd (N);
1240 R : constant Node_Id := Right_Opnd (N);
1244 Set_Etype (N, Any_Type);
1245 Candidate_Type := Empty;
1247 Analyze_Expression (L);
1248 Analyze_Expression (R);
1250 -- If the entity is set, the node is a generic instance with a non-local
1251 -- reference to the predefined operator or to a user-defined function.
1252 -- It can also be an inequality that is expanded into the negation of a
1253 -- call to a user-defined equality operator.
1255 -- For the predefined case, the result is Boolean, regardless of the
1256 -- type of the operands. The operands may even be limited, if they are
1257 -- generic actuals. If they are overloaded, label the left argument with
1258 -- the common type that must be present, or with the type of the formal
1259 -- of the user-defined function.
1261 if Present (Entity (N)) then
1262 Op_Id := Entity (N);
1264 if Ekind (Op_Id) = E_Operator then
1265 Add_One_Interp (N, Op_Id, Standard_Boolean);
1267 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1270 if Is_Overloaded (L) then
1271 if Ekind (Op_Id) = E_Operator then
1272 Set_Etype (L, Intersect_Types (L, R));
1274 Set_Etype (L, Etype (First_Formal (Op_Id)));
1279 Op_Id := Get_Name_Entity_Id (Chars (N));
1280 while Present (Op_Id) loop
1281 if Ekind (Op_Id) = E_Operator then
1282 Find_Equality_Types (L, R, Op_Id, N);
1284 Analyze_User_Defined_Binary_Op (N, Op_Id);
1287 Op_Id := Homonym (Op_Id);
1291 -- If there was no match, and the operator is inequality, this may
1292 -- be a case where inequality has not been made explicit, as for
1293 -- tagged types. Analyze the node as the negation of an equality
1294 -- operation. This cannot be done earlier, because before analysis
1295 -- we cannot rule out the presence of an explicit inequality.
1297 if Etype (N) = Any_Type
1298 and then Nkind (N) = N_Op_Ne
1300 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1301 while Present (Op_Id) loop
1302 if Ekind (Op_Id) = E_Operator then
1303 Find_Equality_Types (L, R, Op_Id, N);
1305 Analyze_User_Defined_Binary_Op (N, Op_Id);
1308 Op_Id := Homonym (Op_Id);
1311 if Etype (N) /= Any_Type then
1312 Op_Id := Entity (N);
1318 Left_Opnd => Left_Opnd (N),
1319 Right_Opnd => Right_Opnd (N))));
1321 Set_Entity (Right_Opnd (N), Op_Id);
1327 end Analyze_Equality_Op;
1329 ----------------------------------
1330 -- Analyze_Explicit_Dereference --
1331 ----------------------------------
1333 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1334 Loc : constant Source_Ptr := Sloc (N);
1335 P : constant Node_Id := Prefix (N);
1341 function Is_Function_Type return Boolean;
1342 -- Check whether node may be interpreted as an implicit function call
1344 ----------------------
1345 -- Is_Function_Type --
1346 ----------------------
1348 function Is_Function_Type return Boolean is
1353 if not Is_Overloaded (N) then
1354 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1355 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1358 Get_First_Interp (N, I, It);
1359 while Present (It.Nam) loop
1360 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1361 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1366 Get_Next_Interp (I, It);
1371 end Is_Function_Type;
1373 -- Start of processing for Analyze_Explicit_Dereference
1377 Set_Etype (N, Any_Type);
1379 -- Test for remote access to subprogram type, and if so return
1380 -- after rewriting the original tree.
1382 if Remote_AST_E_Dereference (P) then
1386 -- Normal processing for other than remote access to subprogram type
1388 if not Is_Overloaded (P) then
1389 if Is_Access_Type (Etype (P)) then
1391 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
1392 -- avoid other problems caused by the Private_Subtype and it is
1393 -- safe to go to the Base_Type because this is the same as
1394 -- converting the access value to its Base_Type.
1397 DT : Entity_Id := Designated_Type (Etype (P));
1400 if Ekind (DT) = E_Private_Subtype
1401 and then Is_For_Access_Subtype (DT)
1403 DT := Base_Type (DT);
1406 -- An explicit dereference is a legal occurrence of an
1407 -- incomplete type imported through a limited_with clause,
1408 -- if the full view is visible.
1410 if From_With_Type (DT)
1411 and then not From_With_Type (Scope (DT))
1413 (Is_Immediately_Visible (Scope (DT))
1415 (Is_Child_Unit (Scope (DT))
1416 and then Is_Visible_Child_Unit (Scope (DT))))
1418 Set_Etype (N, Available_View (DT));
1425 elsif Etype (P) /= Any_Type then
1426 Error_Msg_N ("prefix of dereference must be an access type", N);
1431 Get_First_Interp (P, I, It);
1432 while Present (It.Nam) loop
1435 if Is_Access_Type (T) then
1436 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1439 Get_Next_Interp (I, It);
1442 -- Error if no interpretation of the prefix has an access type
1444 if Etype (N) = Any_Type then
1446 ("access type required in prefix of explicit dereference", P);
1447 Set_Etype (N, Any_Type);
1453 and then Nkind (Parent (N)) /= N_Indexed_Component
1455 and then (Nkind (Parent (N)) /= N_Function_Call
1456 or else N /= Name (Parent (N)))
1458 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1459 or else N /= Name (Parent (N)))
1461 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1462 and then (Nkind (Parent (N)) /= N_Attribute_Reference
1464 (Attribute_Name (Parent (N)) /= Name_Address
1466 Attribute_Name (Parent (N)) /= Name_Access))
1468 -- Name is a function call with no actuals, in a context that
1469 -- requires deproceduring (including as an actual in an enclosing
1470 -- function or procedure call). There are some pathological cases
1471 -- where the prefix might include functions that return access to
1472 -- subprograms and others that return a regular type. Disambiguation
1473 -- of those has to take place in Resolve.
1476 Make_Function_Call (Loc,
1477 Name => Make_Explicit_Dereference (Loc, P),
1478 Parameter_Associations => New_List);
1480 -- If the prefix is overloaded, remove operations that have formals,
1481 -- we know that this is a parameterless call.
1483 if Is_Overloaded (P) then
1484 Get_First_Interp (P, I, It);
1485 while Present (It.Nam) loop
1488 if No (First_Formal (Base_Type (Designated_Type (T)))) then
1494 Get_Next_Interp (I, It);
1501 elsif not Is_Function_Type
1502 and then Is_Overloaded (N)
1504 -- The prefix may include access to subprograms and other access
1505 -- types. If the context selects the interpretation that is a
1506 -- function call (not a procedure call) we cannot rewrite the
1507 -- node yet, but we include the result of the call interpretation.
1509 Get_First_Interp (N, I, It);
1510 while Present (It.Nam) loop
1511 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
1512 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
1513 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
1515 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
1518 Get_Next_Interp (I, It);
1522 -- A value of remote access-to-class-wide must not be dereferenced
1525 Validate_Remote_Access_To_Class_Wide_Type (N);
1526 end Analyze_Explicit_Dereference;
1528 ------------------------
1529 -- Analyze_Expression --
1530 ------------------------
1532 procedure Analyze_Expression (N : Node_Id) is
1535 Check_Parameterless_Call (N);
1536 end Analyze_Expression;
1538 ------------------------------------
1539 -- Analyze_Indexed_Component_Form --
1540 ------------------------------------
1542 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
1543 P : constant Node_Id := Prefix (N);
1544 Exprs : constant List_Id := Expressions (N);
1550 procedure Process_Function_Call;
1551 -- Prefix in indexed component form is an overloadable entity,
1552 -- so the node is a function call. Reformat it as such.
1554 procedure Process_Indexed_Component;
1555 -- Prefix in indexed component form is actually an indexed component.
1556 -- This routine processes it, knowing that the prefix is already
1559 procedure Process_Indexed_Component_Or_Slice;
1560 -- An indexed component with a single index may designate a slice if
1561 -- the index is a subtype mark. This routine disambiguates these two
1562 -- cases by resolving the prefix to see if it is a subtype mark.
1564 procedure Process_Overloaded_Indexed_Component;
1565 -- If the prefix of an indexed component is overloaded, the proper
1566 -- interpretation is selected by the index types and the context.
1568 ---------------------------
1569 -- Process_Function_Call --
1570 ---------------------------
1572 procedure Process_Function_Call is
1576 Change_Node (N, N_Function_Call);
1578 Set_Parameter_Associations (N, Exprs);
1580 -- Analyze actuals prior to analyzing the call itself
1582 Actual := First (Parameter_Associations (N));
1583 while Present (Actual) loop
1585 Check_Parameterless_Call (Actual);
1587 -- Move to next actual. Note that we use Next, not Next_Actual
1588 -- here. The reason for this is a bit subtle. If a function call
1589 -- includes named associations, the parser recognizes the node as
1590 -- a call, and it is analyzed as such. If all associations are
1591 -- positional, the parser builds an indexed_component node, and
1592 -- it is only after analysis of the prefix that the construct
1593 -- is recognized as a call, in which case Process_Function_Call
1594 -- rewrites the node and analyzes the actuals. If the list of
1595 -- actuals is malformed, the parser may leave the node as an
1596 -- indexed component (despite the presence of named associations).
1597 -- The iterator Next_Actual is equivalent to Next if the list is
1598 -- positional, but follows the normalized chain of actuals when
1599 -- named associations are present. In this case normalization has
1600 -- not taken place, and actuals remain unanalyzed, which leads to
1601 -- subsequent crashes or loops if there is an attempt to continue
1602 -- analysis of the program.
1608 end Process_Function_Call;
1610 -------------------------------
1611 -- Process_Indexed_Component --
1612 -------------------------------
1614 procedure Process_Indexed_Component is
1616 Array_Type : Entity_Id;
1618 Pent : Entity_Id := Empty;
1621 Exp := First (Exprs);
1623 if Is_Overloaded (P) then
1624 Process_Overloaded_Indexed_Component;
1627 Array_Type := Etype (P);
1629 if Is_Entity_Name (P) then
1631 elsif Nkind (P) = N_Selected_Component
1632 and then Is_Entity_Name (Selector_Name (P))
1634 Pent := Entity (Selector_Name (P));
1637 -- Prefix must be appropriate for an array type, taking into
1638 -- account a possible implicit dereference.
1640 if Is_Access_Type (Array_Type) then
1641 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1642 Array_Type := Process_Implicit_Dereference_Prefix (Pent, P);
1645 if Is_Array_Type (Array_Type) then
1648 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
1650 Set_Etype (N, Any_Type);
1652 if not Has_Compatible_Type
1653 (Exp, Entry_Index_Type (Pent))
1655 Error_Msg_N ("invalid index type in entry name", N);
1657 elsif Present (Next (Exp)) then
1658 Error_Msg_N ("too many subscripts in entry reference", N);
1661 Set_Etype (N, Etype (P));
1666 elsif Is_Record_Type (Array_Type)
1667 and then Remote_AST_I_Dereference (P)
1671 elsif Array_Type = Any_Type then
1672 Set_Etype (N, Any_Type);
1675 -- Here we definitely have a bad indexing
1678 if Nkind (Parent (N)) = N_Requeue_Statement
1679 and then Present (Pent) and then Ekind (Pent) = E_Entry
1682 ("REQUEUE does not permit parameters", First (Exprs));
1684 elsif Is_Entity_Name (P)
1685 and then Etype (P) = Standard_Void_Type
1687 Error_Msg_NE ("incorrect use of&", P, Entity (P));
1690 Error_Msg_N ("array type required in indexed component", P);
1693 Set_Etype (N, Any_Type);
1697 Index := First_Index (Array_Type);
1698 while Present (Index) and then Present (Exp) loop
1699 if not Has_Compatible_Type (Exp, Etype (Index)) then
1700 Wrong_Type (Exp, Etype (Index));
1701 Set_Etype (N, Any_Type);
1709 Set_Etype (N, Component_Type (Array_Type));
1711 if Present (Index) then
1713 ("too few subscripts in array reference", First (Exprs));
1715 elsif Present (Exp) then
1716 Error_Msg_N ("too many subscripts in array reference", Exp);
1719 end Process_Indexed_Component;
1721 ----------------------------------------
1722 -- Process_Indexed_Component_Or_Slice --
1723 ----------------------------------------
1725 procedure Process_Indexed_Component_Or_Slice is
1727 Exp := First (Exprs);
1728 while Present (Exp) loop
1729 Analyze_Expression (Exp);
1733 Exp := First (Exprs);
1735 -- If one index is present, and it is a subtype name, then the
1736 -- node denotes a slice (note that the case of an explicit range
1737 -- for a slice was already built as an N_Slice node in the first
1738 -- place, so that case is not handled here).
1740 -- We use a replace rather than a rewrite here because this is one
1741 -- of the cases in which the tree built by the parser is plain wrong.
1744 and then Is_Entity_Name (Exp)
1745 and then Is_Type (Entity (Exp))
1748 Make_Slice (Sloc (N),
1750 Discrete_Range => New_Copy (Exp)));
1753 -- Otherwise (more than one index present, or single index is not
1754 -- a subtype name), then we have the indexed component case.
1757 Process_Indexed_Component;
1759 end Process_Indexed_Component_Or_Slice;
1761 ------------------------------------------
1762 -- Process_Overloaded_Indexed_Component --
1763 ------------------------------------------
1765 procedure Process_Overloaded_Indexed_Component is
1774 Set_Etype (N, Any_Type);
1776 Get_First_Interp (P, I, It);
1777 while Present (It.Nam) loop
1780 if Is_Access_Type (Typ) then
1781 Typ := Designated_Type (Typ);
1782 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1785 if Is_Array_Type (Typ) then
1787 -- Got a candidate: verify that index types are compatible
1789 Index := First_Index (Typ);
1791 Exp := First (Exprs);
1792 while Present (Index) and then Present (Exp) loop
1793 if Has_Compatible_Type (Exp, Etype (Index)) then
1805 if Found and then No (Index) and then No (Exp) then
1807 Etype (Component_Type (Typ)),
1808 Etype (Component_Type (Typ)));
1812 Get_Next_Interp (I, It);
1815 if Etype (N) = Any_Type then
1816 Error_Msg_N ("no legal interpretation for indexed component", N);
1817 Set_Is_Overloaded (N, False);
1821 end Process_Overloaded_Indexed_Component;
1823 -- Start of processing for Analyze_Indexed_Component_Form
1826 -- Get name of array, function or type
1830 if Nkind_In (N, N_Function_Call, N_Procedure_Call_Statement) then
1832 -- If P is an explicit dereference whose prefix is of a
1833 -- remote access-to-subprogram type, then N has already
1834 -- been rewritten as a subprogram call and analyzed.
1839 pragma Assert (Nkind (N) = N_Indexed_Component);
1841 P_T := Base_Type (Etype (P));
1843 if Is_Entity_Name (P)
1844 or else Nkind (P) = N_Operator_Symbol
1848 if Is_Type (U_N) then
1850 -- Reformat node as a type conversion
1852 E := Remove_Head (Exprs);
1854 if Present (First (Exprs)) then
1856 ("argument of type conversion must be single expression", N);
1859 Change_Node (N, N_Type_Conversion);
1860 Set_Subtype_Mark (N, P);
1862 Set_Expression (N, E);
1864 -- After changing the node, call for the specific Analysis
1865 -- routine directly, to avoid a double call to the expander.
1867 Analyze_Type_Conversion (N);
1871 if Is_Overloadable (U_N) then
1872 Process_Function_Call;
1874 elsif Ekind (Etype (P)) = E_Subprogram_Type
1875 or else (Is_Access_Type (Etype (P))
1877 Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type)
1879 -- Call to access_to-subprogram with possible implicit dereference
1881 Process_Function_Call;
1883 elsif Is_Generic_Subprogram (U_N) then
1885 -- A common beginner's (or C++ templates fan) error
1887 Error_Msg_N ("generic subprogram cannot be called", N);
1888 Set_Etype (N, Any_Type);
1892 Process_Indexed_Component_Or_Slice;
1895 -- If not an entity name, prefix is an expression that may denote
1896 -- an array or an access-to-subprogram.
1899 if Ekind (P_T) = E_Subprogram_Type
1900 or else (Is_Access_Type (P_T)
1902 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
1904 Process_Function_Call;
1906 elsif Nkind (P) = N_Selected_Component
1907 and then Is_Overloadable (Entity (Selector_Name (P)))
1909 Process_Function_Call;
1912 -- Indexed component, slice, or a call to a member of a family
1913 -- entry, which will be converted to an entry call later.
1915 Process_Indexed_Component_Or_Slice;
1918 end Analyze_Indexed_Component_Form;
1920 ------------------------
1921 -- Analyze_Logical_Op --
1922 ------------------------
1924 procedure Analyze_Logical_Op (N : Node_Id) is
1925 L : constant Node_Id := Left_Opnd (N);
1926 R : constant Node_Id := Right_Opnd (N);
1927 Op_Id : Entity_Id := Entity (N);
1930 Set_Etype (N, Any_Type);
1931 Candidate_Type := Empty;
1933 Analyze_Expression (L);
1934 Analyze_Expression (R);
1936 if Present (Op_Id) then
1938 if Ekind (Op_Id) = E_Operator then
1939 Find_Boolean_Types (L, R, Op_Id, N);
1941 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1945 Op_Id := Get_Name_Entity_Id (Chars (N));
1946 while Present (Op_Id) loop
1947 if Ekind (Op_Id) = E_Operator then
1948 Find_Boolean_Types (L, R, Op_Id, N);
1950 Analyze_User_Defined_Binary_Op (N, Op_Id);
1953 Op_Id := Homonym (Op_Id);
1958 end Analyze_Logical_Op;
1960 ---------------------------
1961 -- Analyze_Membership_Op --
1962 ---------------------------
1964 procedure Analyze_Membership_Op (N : Node_Id) is
1965 L : constant Node_Id := Left_Opnd (N);
1966 R : constant Node_Id := Right_Opnd (N);
1968 Index : Interp_Index;
1970 Found : Boolean := False;
1974 procedure Try_One_Interp (T1 : Entity_Id);
1975 -- Routine to try one proposed interpretation. Note that the context
1976 -- of the operation plays no role in resolving the arguments, so that
1977 -- if there is more than one interpretation of the operands that is
1978 -- compatible with a membership test, the operation is ambiguous.
1980 --------------------
1981 -- Try_One_Interp --
1982 --------------------
1984 procedure Try_One_Interp (T1 : Entity_Id) is
1986 if Has_Compatible_Type (R, T1) then
1988 and then Base_Type (T1) /= Base_Type (T_F)
1990 It := Disambiguate (L, I_F, Index, Any_Type);
1992 if It = No_Interp then
1993 Ambiguous_Operands (N);
1994 Set_Etype (L, Any_Type);
2012 -- Start of processing for Analyze_Membership_Op
2015 Analyze_Expression (L);
2017 if Nkind (R) = N_Range
2018 or else (Nkind (R) = N_Attribute_Reference
2019 and then Attribute_Name (R) = Name_Range)
2023 if not Is_Overloaded (L) then
2024 Try_One_Interp (Etype (L));
2027 Get_First_Interp (L, Index, It);
2028 while Present (It.Typ) loop
2029 Try_One_Interp (It.Typ);
2030 Get_Next_Interp (Index, It);
2034 -- If not a range, it can only be a subtype mark, or else there
2035 -- is a more basic error, to be diagnosed in Find_Type.
2040 if Is_Entity_Name (R) then
2041 Check_Fully_Declared (Entity (R), R);
2045 -- Compatibility between expression and subtype mark or range is
2046 -- checked during resolution. The result of the operation is Boolean
2049 Set_Etype (N, Standard_Boolean);
2051 if Comes_From_Source (N)
2052 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
2054 Error_Msg_N ("membership test not applicable to cpp-class types", N);
2056 end Analyze_Membership_Op;
2058 ----------------------
2059 -- Analyze_Negation --
2060 ----------------------
2062 procedure Analyze_Negation (N : Node_Id) is
2063 R : constant Node_Id := Right_Opnd (N);
2064 Op_Id : Entity_Id := Entity (N);
2067 Set_Etype (N, Any_Type);
2068 Candidate_Type := Empty;
2070 Analyze_Expression (R);
2072 if Present (Op_Id) then
2073 if Ekind (Op_Id) = E_Operator then
2074 Find_Negation_Types (R, Op_Id, N);
2076 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2080 Op_Id := Get_Name_Entity_Id (Chars (N));
2081 while Present (Op_Id) loop
2082 if Ekind (Op_Id) = E_Operator then
2083 Find_Negation_Types (R, Op_Id, N);
2085 Analyze_User_Defined_Unary_Op (N, Op_Id);
2088 Op_Id := Homonym (Op_Id);
2093 end Analyze_Negation;
2099 procedure Analyze_Null (N : Node_Id) is
2101 Set_Etype (N, Any_Access);
2104 ----------------------
2105 -- Analyze_One_Call --
2106 ----------------------
2108 procedure Analyze_One_Call
2112 Success : out Boolean;
2113 Skip_First : Boolean := False)
2115 Actuals : constant List_Id := Parameter_Associations (N);
2116 Prev_T : constant Entity_Id := Etype (N);
2118 Must_Skip : constant Boolean := Skip_First
2119 or else Nkind (Original_Node (N)) = N_Selected_Component
2121 (Nkind (Original_Node (N)) = N_Indexed_Component
2122 and then Nkind (Prefix (Original_Node (N)))
2123 = N_Selected_Component);
2124 -- The first formal must be omitted from the match when trying to find
2125 -- a primitive operation that is a possible interpretation, and also
2126 -- after the call has been rewritten, because the corresponding actual
2127 -- is already known to be compatible, and because this may be an
2128 -- indexing of a call with default parameters.
2132 Is_Indexed : Boolean := False;
2133 Subp_Type : constant Entity_Id := Etype (Nam);
2136 function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
2137 -- There may be a user-defined operator that hides the current
2138 -- interpretation. We must check for this independently of the
2139 -- analysis of the call with the user-defined operation, because
2140 -- the parameter names may be wrong and yet the hiding takes place.
2141 -- This fixes a problem with ACATS test B34014O.
2143 -- When the type Address is a visible integer type, and the DEC
2144 -- system extension is visible, the predefined operator may be
2145 -- hidden as well, by one of the address operations in auxdec.
2146 -- Finally, The abstract operations on address do not hide the
2147 -- predefined operator (this is the purpose of making them abstract).
2149 procedure Indicate_Name_And_Type;
2150 -- If candidate interpretation matches, indicate name and type of
2151 -- result on call node.
2153 ----------------------------
2154 -- Indicate_Name_And_Type --
2155 ----------------------------
2157 procedure Indicate_Name_And_Type is
2159 Add_One_Interp (N, Nam, Etype (Nam));
2162 -- If the prefix of the call is a name, indicate the entity
2163 -- being called. If it is not a name, it is an expression that
2164 -- denotes an access to subprogram or else an entry or family. In
2165 -- the latter case, the name is a selected component, and the entity
2166 -- being called is noted on the selector.
2168 if not Is_Type (Nam) then
2169 if Is_Entity_Name (Name (N))
2170 or else Nkind (Name (N)) = N_Operator_Symbol
2172 Set_Entity (Name (N), Nam);
2174 elsif Nkind (Name (N)) = N_Selected_Component then
2175 Set_Entity (Selector_Name (Name (N)), Nam);
2179 if Debug_Flag_E and not Report then
2180 Write_Str (" Overloaded call ");
2181 Write_Int (Int (N));
2182 Write_Str (" compatible with ");
2183 Write_Int (Int (Nam));
2186 end Indicate_Name_And_Type;
2188 ------------------------
2189 -- Operator_Hidden_By --
2190 ------------------------
2192 function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
2193 Act1 : constant Node_Id := First_Actual (N);
2194 Act2 : constant Node_Id := Next_Actual (Act1);
2195 Form1 : constant Entity_Id := First_Formal (Fun);
2196 Form2 : constant Entity_Id := Next_Formal (Form1);
2199 if Ekind (Fun) /= E_Function
2200 or else Is_Abstract_Subprogram (Fun)
2204 elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
2207 elsif Present (Form2) then
2209 No (Act2) or else not Has_Compatible_Type (Act2, Etype (Form2))
2214 elsif Present (Act2) then
2218 -- Now we know that the arity of the operator matches the function,
2219 -- and the function call is a valid interpretation. The function
2220 -- hides the operator if it has the right signature, or if one of
2221 -- its operands is a non-abstract operation on Address when this is
2222 -- a visible integer type.
2224 return Hides_Op (Fun, Nam)
2225 or else Is_Descendent_Of_Address (Etype (Form1))
2228 and then Is_Descendent_Of_Address (Etype (Form2)));
2229 end Operator_Hidden_By;
2231 -- Start of processing for Analyze_One_Call
2236 -- If the subprogram has no formals or if all the formals have defaults,
2237 -- and the return type is an array type, the node may denote an indexing
2238 -- of the result of a parameterless call. In Ada 2005, the subprogram
2239 -- may have one non-defaulted formal, and the call may have been written
2240 -- in prefix notation, so that the rebuilt parameter list has more than
2243 if Present (Actuals)
2245 (Needs_No_Actuals (Nam)
2247 (Needs_One_Actual (Nam)
2248 and then Present (Next_Actual (First (Actuals)))))
2250 if Is_Array_Type (Subp_Type) then
2251 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
2253 elsif Is_Access_Type (Subp_Type)
2254 and then Is_Array_Type (Designated_Type (Subp_Type))
2258 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
2260 -- The prefix can also be a parameterless function that returns an
2261 -- access to subprogram, in which case this is an indirect call.
2263 elsif Is_Access_Type (Subp_Type)
2264 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
2266 Is_Indexed := Try_Indirect_Call (N, Nam, Subp_Type);
2271 -- If the call has been transformed into a slice, it is of the form
2272 -- F (Subtype) where F is parameterless. The node has been rewritten in
2273 -- Try_Indexed_Call and there is nothing else to do.
2276 and then Nkind (N) = N_Slice
2281 Normalize_Actuals (N, Nam, (Report and not Is_Indexed), Norm_OK);
2285 -- Mismatch in number or names of parameters
2287 if Debug_Flag_E then
2288 Write_Str (" normalization fails in call ");
2289 Write_Int (Int (N));
2290 Write_Str (" with subprogram ");
2291 Write_Int (Int (Nam));
2295 -- If the context expects a function call, discard any interpretation
2296 -- that is a procedure. If the node is not overloaded, leave as is for
2297 -- better error reporting when type mismatch is found.
2299 elsif Nkind (N) = N_Function_Call
2300 and then Is_Overloaded (Name (N))
2301 and then Ekind (Nam) = E_Procedure
2305 -- Ditto for function calls in a procedure context
2307 elsif Nkind (N) = N_Procedure_Call_Statement
2308 and then Is_Overloaded (Name (N))
2309 and then Etype (Nam) /= Standard_Void_Type
2313 elsif No (Actuals) then
2315 -- If Normalize succeeds, then there are default parameters for
2318 Indicate_Name_And_Type;
2320 elsif Ekind (Nam) = E_Operator then
2321 if Nkind (N) = N_Procedure_Call_Statement then
2325 -- This can occur when the prefix of the call is an operator
2326 -- name or an expanded name whose selector is an operator name.
2328 Analyze_Operator_Call (N, Nam);
2330 if Etype (N) /= Prev_T then
2332 -- Check that operator is not hidden by a function interpretation
2334 if Is_Overloaded (Name (N)) then
2340 Get_First_Interp (Name (N), I, It);
2341 while Present (It.Nam) loop
2342 if Operator_Hidden_By (It.Nam) then
2343 Set_Etype (N, Prev_T);
2347 Get_Next_Interp (I, It);
2352 -- If operator matches formals, record its name on the call.
2353 -- If the operator is overloaded, Resolve will select the
2354 -- correct one from the list of interpretations. The call
2355 -- node itself carries the first candidate.
2357 Set_Entity (Name (N), Nam);
2360 elsif Report and then Etype (N) = Any_Type then
2361 Error_Msg_N ("incompatible arguments for operator", N);
2365 -- Normalize_Actuals has chained the named associations in the
2366 -- correct order of the formals.
2368 Actual := First_Actual (N);
2369 Formal := First_Formal (Nam);
2371 -- If we are analyzing a call rewritten from object notation,
2372 -- skip first actual, which may be rewritten later as an
2373 -- explicit dereference.
2376 Next_Actual (Actual);
2377 Next_Formal (Formal);
2380 while Present (Actual) and then Present (Formal) loop
2381 if Nkind (Parent (Actual)) /= N_Parameter_Association
2382 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
2384 -- The actual can be compatible with the formal, but we must
2385 -- also check that the context is not an address type that is
2386 -- visibly an integer type, as is the case in VMS_64. In this
2387 -- case the use of literals is illegal, except in the body of
2388 -- descendents of system, where arithmetic operations on
2389 -- address are of course used.
2391 if Has_Compatible_Type (Actual, Etype (Formal))
2393 (Etype (Actual) /= Universal_Integer
2394 or else not Is_Descendent_Of_Address (Etype (Formal))
2396 Is_Predefined_File_Name
2397 (Unit_File_Name (Get_Source_Unit (N))))
2399 Next_Actual (Actual);
2400 Next_Formal (Formal);
2403 if Debug_Flag_E then
2404 Write_Str (" type checking fails in call ");
2405 Write_Int (Int (N));
2406 Write_Str (" with formal ");
2407 Write_Int (Int (Formal));
2408 Write_Str (" in subprogram ");
2409 Write_Int (Int (Nam));
2413 if Report and not Is_Indexed then
2415 -- Ada 2005 (AI-251): Complete the error notification
2416 -- to help new Ada 2005 users
2418 if Is_Class_Wide_Type (Etype (Formal))
2419 and then Is_Interface (Etype (Etype (Formal)))
2420 and then not Interface_Present_In_Ancestor
2421 (Typ => Etype (Actual),
2422 Iface => Etype (Etype (Formal)))
2425 ("(Ada 2005) does not implement interface }",
2426 Actual, Etype (Etype (Formal)));
2429 Wrong_Type (Actual, Etype (Formal));
2431 if Nkind (Actual) = N_Op_Eq
2432 and then Nkind (Left_Opnd (Actual)) = N_Identifier
2434 Formal := First_Formal (Nam);
2435 while Present (Formal) loop
2436 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
2438 ("possible misspelling of `='>`!", Actual);
2442 Next_Formal (Formal);
2446 if All_Errors_Mode then
2447 Error_Msg_Sloc := Sloc (Nam);
2449 if Is_Overloadable (Nam)
2450 and then Present (Alias (Nam))
2451 and then not Comes_From_Source (Nam)
2454 ("\\ =='> in call to inherited operation & #!",
2457 elsif Ekind (Nam) = E_Subprogram_Type then
2459 Access_To_Subprogram_Typ :
2460 constant Entity_Id :=
2462 (Associated_Node_For_Itype (Nam));
2465 "\\ =='> in call to dereference of &#!",
2466 Actual, Access_To_Subprogram_Typ);
2471 ("\\ =='> in call to &#!", Actual, Nam);
2481 -- Normalize_Actuals has verified that a default value exists
2482 -- for this formal. Current actual names a subsequent formal.
2484 Next_Formal (Formal);
2488 -- On exit, all actuals match
2490 Indicate_Name_And_Type;
2492 end Analyze_One_Call;
2494 ---------------------------
2495 -- Analyze_Operator_Call --
2496 ---------------------------
2498 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
2499 Op_Name : constant Name_Id := Chars (Op_Id);
2500 Act1 : constant Node_Id := First_Actual (N);
2501 Act2 : constant Node_Id := Next_Actual (Act1);
2504 -- Binary operator case
2506 if Present (Act2) then
2508 -- If more than two operands, then not binary operator after all
2510 if Present (Next_Actual (Act2)) then
2513 elsif Op_Name = Name_Op_Add
2514 or else Op_Name = Name_Op_Subtract
2515 or else Op_Name = Name_Op_Multiply
2516 or else Op_Name = Name_Op_Divide
2517 or else Op_Name = Name_Op_Mod
2518 or else Op_Name = Name_Op_Rem
2519 or else Op_Name = Name_Op_Expon
2521 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
2523 elsif Op_Name = Name_Op_And
2524 or else Op_Name = Name_Op_Or
2525 or else Op_Name = Name_Op_Xor
2527 Find_Boolean_Types (Act1, Act2, Op_Id, N);
2529 elsif Op_Name = Name_Op_Lt
2530 or else Op_Name = Name_Op_Le
2531 or else Op_Name = Name_Op_Gt
2532 or else Op_Name = Name_Op_Ge
2534 Find_Comparison_Types (Act1, Act2, Op_Id, N);
2536 elsif Op_Name = Name_Op_Eq
2537 or else Op_Name = Name_Op_Ne
2539 Find_Equality_Types (Act1, Act2, Op_Id, N);
2541 elsif Op_Name = Name_Op_Concat then
2542 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
2544 -- Is this else null correct, or should it be an abort???
2550 -- Unary operator case
2553 if Op_Name = Name_Op_Subtract or else
2554 Op_Name = Name_Op_Add or else
2555 Op_Name = Name_Op_Abs
2557 Find_Unary_Types (Act1, Op_Id, N);
2560 Op_Name = Name_Op_Not
2562 Find_Negation_Types (Act1, Op_Id, N);
2564 -- Is this else null correct, or should it be an abort???
2570 end Analyze_Operator_Call;
2572 -------------------------------------------
2573 -- Analyze_Overloaded_Selected_Component --
2574 -------------------------------------------
2576 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
2577 Nam : constant Node_Id := Prefix (N);
2578 Sel : constant Node_Id := Selector_Name (N);
2585 Set_Etype (Sel, Any_Type);
2587 Get_First_Interp (Nam, I, It);
2588 while Present (It.Typ) loop
2589 if Is_Access_Type (It.Typ) then
2590 T := Designated_Type (It.Typ);
2591 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2596 if Is_Record_Type (T) then
2598 -- If the prefix is a class-wide type, the visible components are
2599 -- those of the base type.
2601 if Is_Class_Wide_Type (T) then
2605 Comp := First_Entity (T);
2606 while Present (Comp) loop
2607 if Chars (Comp) = Chars (Sel)
2608 and then Is_Visible_Component (Comp)
2610 Set_Entity (Sel, Comp);
2611 Set_Etype (Sel, Etype (Comp));
2612 Add_One_Interp (N, Etype (Comp), Etype (Comp));
2614 -- This also specifies a candidate to resolve the name.
2615 -- Further overloading will be resolved from context.
2617 Set_Etype (Nam, It.Typ);
2623 elsif Is_Concurrent_Type (T) then
2624 Comp := First_Entity (T);
2625 while Present (Comp)
2626 and then Comp /= First_Private_Entity (T)
2628 if Chars (Comp) = Chars (Sel) then
2629 if Is_Overloadable (Comp) then
2630 Add_One_Interp (Sel, Comp, Etype (Comp));
2632 Set_Entity_With_Style_Check (Sel, Comp);
2633 Generate_Reference (Comp, Sel);
2636 Set_Etype (Sel, Etype (Comp));
2637 Set_Etype (N, Etype (Comp));
2638 Set_Etype (Nam, It.Typ);
2640 -- For access type case, introduce explicit deference for
2641 -- more uniform treatment of entry calls. Do this only
2642 -- once if several interpretations yield an access type.
2644 if Is_Access_Type (Etype (Nam))
2645 and then Nkind (Nam) /= N_Explicit_Dereference
2647 Insert_Explicit_Dereference (Nam);
2649 (Warn_On_Dereference, "?implicit dereference", N);
2656 Set_Is_Overloaded (N, Is_Overloaded (Sel));
2659 Get_Next_Interp (I, It);
2662 if Etype (N) = Any_Type
2663 and then not Try_Object_Operation (N)
2665 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
2666 Set_Entity (Sel, Any_Id);
2667 Set_Etype (Sel, Any_Type);
2669 end Analyze_Overloaded_Selected_Component;
2671 ----------------------------------
2672 -- Analyze_Qualified_Expression --
2673 ----------------------------------
2675 procedure Analyze_Qualified_Expression (N : Node_Id) is
2676 Mark : constant Entity_Id := Subtype_Mark (N);
2677 Expr : constant Node_Id := Expression (N);
2683 Analyze_Expression (Expr);
2685 Set_Etype (N, Any_Type);
2690 if T = Any_Type then
2694 Check_Fully_Declared (T, N);
2696 -- If expected type is class-wide, check for exact match before
2697 -- expansion, because if the expression is a dispatching call it
2698 -- may be rewritten as explicit dereference with class-wide result.
2699 -- If expression is overloaded, retain only interpretations that
2700 -- will yield exact matches.
2702 if Is_Class_Wide_Type (T) then
2703 if not Is_Overloaded (Expr) then
2704 if Base_Type (Etype (Expr)) /= Base_Type (T) then
2705 if Nkind (Expr) = N_Aggregate then
2706 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
2708 Wrong_Type (Expr, T);
2713 Get_First_Interp (Expr, I, It);
2715 while Present (It.Nam) loop
2716 if Base_Type (It.Typ) /= Base_Type (T) then
2720 Get_Next_Interp (I, It);
2726 end Analyze_Qualified_Expression;
2732 procedure Analyze_Range (N : Node_Id) is
2733 L : constant Node_Id := Low_Bound (N);
2734 H : constant Node_Id := High_Bound (N);
2735 I1, I2 : Interp_Index;
2738 procedure Check_Common_Type (T1, T2 : Entity_Id);
2739 -- Verify the compatibility of two types, and choose the
2740 -- non universal one if the other is universal.
2742 procedure Check_High_Bound (T : Entity_Id);
2743 -- Test one interpretation of the low bound against all those
2744 -- of the high bound.
2746 procedure Check_Universal_Expression (N : Node_Id);
2747 -- In Ada83, reject bounds of a universal range that are not
2748 -- literals or entity names.
2750 -----------------------
2751 -- Check_Common_Type --
2752 -----------------------
2754 procedure Check_Common_Type (T1, T2 : Entity_Id) is
2756 if Covers (T1 => T1, T2 => T2)
2758 Covers (T1 => T2, T2 => T1)
2760 if T1 = Universal_Integer
2761 or else T1 = Universal_Real
2762 or else T1 = Any_Character
2764 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
2767 Add_One_Interp (N, T1, T1);
2770 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
2773 end Check_Common_Type;
2775 ----------------------
2776 -- Check_High_Bound --
2777 ----------------------
2779 procedure Check_High_Bound (T : Entity_Id) is
2781 if not Is_Overloaded (H) then
2782 Check_Common_Type (T, Etype (H));
2784 Get_First_Interp (H, I2, It2);
2785 while Present (It2.Typ) loop
2786 Check_Common_Type (T, It2.Typ);
2787 Get_Next_Interp (I2, It2);
2790 end Check_High_Bound;
2792 -----------------------------
2793 -- Is_Universal_Expression --
2794 -----------------------------
2796 procedure Check_Universal_Expression (N : Node_Id) is
2798 if Etype (N) = Universal_Integer
2799 and then Nkind (N) /= N_Integer_Literal
2800 and then not Is_Entity_Name (N)
2801 and then Nkind (N) /= N_Attribute_Reference
2803 Error_Msg_N ("illegal bound in discrete range", N);
2805 end Check_Universal_Expression;
2807 -- Start of processing for Analyze_Range
2810 Set_Etype (N, Any_Type);
2811 Analyze_Expression (L);
2812 Analyze_Expression (H);
2814 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
2818 if not Is_Overloaded (L) then
2819 Check_High_Bound (Etype (L));
2821 Get_First_Interp (L, I1, It1);
2822 while Present (It1.Typ) loop
2823 Check_High_Bound (It1.Typ);
2824 Get_Next_Interp (I1, It1);
2828 -- If result is Any_Type, then we did not find a compatible pair
2830 if Etype (N) = Any_Type then
2831 Error_Msg_N ("incompatible types in range ", N);
2835 if Ada_Version = Ada_83
2837 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
2838 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
2840 Check_Universal_Expression (L);
2841 Check_Universal_Expression (H);
2845 -----------------------
2846 -- Analyze_Reference --
2847 -----------------------
2849 procedure Analyze_Reference (N : Node_Id) is
2850 P : constant Node_Id := Prefix (N);
2853 Acc_Type : Entity_Id;
2858 -- An interesting error check, if we take the 'Reference of an object
2859 -- for which a pragma Atomic or Volatile has been given, and the type
2860 -- of the object is not Atomic or Volatile, then we are in trouble. The
2861 -- problem is that no trace of the atomic/volatile status will remain
2862 -- for the backend to respect when it deals with the resulting pointer,
2863 -- since the pointer type will not be marked atomic (it is a pointer to
2864 -- the base type of the object).
2866 -- It is not clear if that can ever occur, but in case it does, we will
2867 -- generate an error message. Not clear if this message can ever be
2868 -- generated, and pretty clear that it represents a bug if it is, still
2869 -- seems worth checking!
2873 if Is_Entity_Name (P)
2874 and then Is_Object_Reference (P)
2879 if (Has_Atomic_Components (E)
2880 and then not Has_Atomic_Components (T))
2882 (Has_Volatile_Components (E)
2883 and then not Has_Volatile_Components (T))
2884 or else (Is_Atomic (E) and then not Is_Atomic (T))
2885 or else (Is_Volatile (E) and then not Is_Volatile (T))
2887 Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
2891 -- Carry on with normal processing
2893 Acc_Type := Create_Itype (E_Allocator_Type, N);
2894 Set_Etype (Acc_Type, Acc_Type);
2895 Set_Directly_Designated_Type (Acc_Type, Etype (P));
2896 Set_Etype (N, Acc_Type);
2897 end Analyze_Reference;
2899 --------------------------------
2900 -- Analyze_Selected_Component --
2901 --------------------------------
2903 -- Prefix is a record type or a task or protected type. In the
2904 -- later case, the selector must denote a visible entry.
2906 procedure Analyze_Selected_Component (N : Node_Id) is
2907 Name : constant Node_Id := Prefix (N);
2908 Sel : constant Node_Id := Selector_Name (N);
2911 Has_Candidate : Boolean := False;
2914 Pent : Entity_Id := Empty;
2915 Prefix_Type : Entity_Id;
2917 Type_To_Use : Entity_Id;
2918 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
2919 -- a class-wide type, we use its root type, whose components are
2920 -- present in the class-wide type.
2922 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
2923 -- It is known that the parent of N denotes a subprogram call. Comp
2924 -- is an overloadable component of the concurrent type of the prefix.
2925 -- Determine whether all formals of the parent of N and Comp are mode
2926 -- conformant. If the parent node is not analyzed yet it may be an
2927 -- indexed component rather than a function call.
2929 ------------------------------
2930 -- Has_Mode_Conformant_Spec --
2931 ------------------------------
2933 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
2934 Comp_Param : Entity_Id;
2936 Param_Typ : Entity_Id;
2939 Comp_Param := First_Formal (Comp);
2941 if Nkind (Parent (N)) = N_Indexed_Component then
2942 Param := First (Expressions (Parent (N)));
2944 Param := First (Parameter_Associations (Parent (N)));
2947 while Present (Comp_Param)
2948 and then Present (Param)
2950 Param_Typ := Find_Parameter_Type (Param);
2952 if Present (Param_Typ)
2954 not Conforming_Types
2955 (Etype (Comp_Param), Param_Typ, Mode_Conformant)
2960 Next_Formal (Comp_Param);
2964 -- One of the specs has additional formals
2966 if Present (Comp_Param) or else Present (Param) then
2971 end Has_Mode_Conformant_Spec;
2973 -- Start of processing for Analyze_Selected_Component
2976 Set_Etype (N, Any_Type);
2978 if Is_Overloaded (Name) then
2979 Analyze_Overloaded_Selected_Component (N);
2982 elsif Etype (Name) = Any_Type then
2983 Set_Entity (Sel, Any_Id);
2984 Set_Etype (Sel, Any_Type);
2988 Prefix_Type := Etype (Name);
2991 if Is_Access_Type (Prefix_Type) then
2993 -- A RACW object can never be used as prefix of a selected
2994 -- component since that means it is dereferenced without
2995 -- being a controlling operand of a dispatching operation
2996 -- (RM E.2.2(16/1)). Before reporting an error, we must check
2997 -- whether this is actually a dispatching call in prefix form.
2999 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
3000 and then Comes_From_Source (N)
3002 if Try_Object_Operation (N) then
3006 ("invalid dereference of a remote access-to-class-wide value",
3010 -- Normal case of selected component applied to access type
3013 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3015 if Is_Entity_Name (Name) then
3016 Pent := Entity (Name);
3017 elsif Nkind (Name) = N_Selected_Component
3018 and then Is_Entity_Name (Selector_Name (Name))
3020 Pent := Entity (Selector_Name (Name));
3023 Prefix_Type := Process_Implicit_Dereference_Prefix (Pent, Name);
3026 -- If we have an explicit dereference of a remote access-to-class-wide
3027 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
3028 -- have to check for the case of a prefix that is a controlling operand
3029 -- of a prefixed dispatching call, as the dereference is legal in that
3030 -- case. Normally this condition is checked in Validate_Remote_Access_
3031 -- To_Class_Wide_Type, but we have to defer the checking for selected
3032 -- component prefixes because of the prefixed dispatching call case.
3033 -- Note that implicit dereferences are checked for this just above.
3035 elsif Nkind (Name) = N_Explicit_Dereference
3036 and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
3037 and then Comes_From_Source (N)
3039 if Try_Object_Operation (N) then
3043 ("invalid dereference of a remote access-to-class-wide value",
3048 -- (Ada 2005): if the prefix is the limited view of a type, and
3049 -- the context already includes the full view, use the full view
3050 -- in what follows, either to retrieve a component of to find
3051 -- a primitive operation. If the prefix is an explicit dereference,
3052 -- set the type of the prefix to reflect this transformation.
3053 -- If the non-limited view is itself an incomplete type, get the
3054 -- full view if available.
3056 if Is_Incomplete_Type (Prefix_Type)
3057 and then From_With_Type (Prefix_Type)
3058 and then Present (Non_Limited_View (Prefix_Type))
3060 Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
3062 if Nkind (N) = N_Explicit_Dereference then
3063 Set_Etype (Prefix (N), Prefix_Type);
3066 elsif Ekind (Prefix_Type) = E_Class_Wide_Type
3067 and then From_With_Type (Prefix_Type)
3068 and then Present (Non_Limited_View (Etype (Prefix_Type)))
3071 Class_Wide_Type (Non_Limited_View (Etype (Prefix_Type)));
3073 if Nkind (N) = N_Explicit_Dereference then
3074 Set_Etype (Prefix (N), Prefix_Type);
3078 if Ekind (Prefix_Type) = E_Private_Subtype then
3079 Prefix_Type := Base_Type (Prefix_Type);
3082 Type_To_Use := Prefix_Type;
3084 -- For class-wide types, use the entity list of the root type. This
3085 -- indirection is specially important for private extensions because
3086 -- only the root type get switched (not the class-wide type).
3088 if Is_Class_Wide_Type (Prefix_Type) then
3089 Type_To_Use := Root_Type (Prefix_Type);
3092 Comp := First_Entity (Type_To_Use);
3094 -- If the selector has an original discriminant, the node appears in
3095 -- an instance. Replace the discriminant with the corresponding one
3096 -- in the current discriminated type. For nested generics, this must
3097 -- be done transitively, so note the new original discriminant.
3099 if Nkind (Sel) = N_Identifier
3100 and then Present (Original_Discriminant (Sel))
3102 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
3104 -- Mark entity before rewriting, for completeness and because
3105 -- subsequent semantic checks might examine the original node.
3107 Set_Entity (Sel, Comp);
3108 Rewrite (Selector_Name (N),
3109 New_Occurrence_Of (Comp, Sloc (N)));
3110 Set_Original_Discriminant (Selector_Name (N), Comp);
3111 Set_Etype (N, Etype (Comp));
3113 if Is_Access_Type (Etype (Name)) then
3114 Insert_Explicit_Dereference (Name);
3115 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3118 elsif Is_Record_Type (Prefix_Type) then
3120 -- Find component with given name
3122 while Present (Comp) loop
3123 if Chars (Comp) = Chars (Sel)
3124 and then Is_Visible_Component (Comp)
3126 Set_Entity_With_Style_Check (Sel, Comp);
3127 Set_Etype (Sel, Etype (Comp));
3129 if Ekind (Comp) = E_Discriminant then
3130 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
3132 ("cannot reference discriminant of Unchecked_Union",
3136 if Is_Generic_Type (Prefix_Type)
3138 Is_Generic_Type (Root_Type (Prefix_Type))
3140 Set_Original_Discriminant (Sel, Comp);
3144 -- Resolve the prefix early otherwise it is not possible to
3145 -- build the actual subtype of the component: it may need
3146 -- to duplicate this prefix and duplication is only allowed
3147 -- on fully resolved expressions.
3151 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
3152 -- subtypes in a package specification.
3155 -- limited with Pkg;
3157 -- type Acc_Inc is access Pkg.T;
3159 -- N : Natural := X.all.Comp; -- ERROR, limited view
3160 -- end Pkg; -- Comp is not visible
3162 if Nkind (Name) = N_Explicit_Dereference
3163 and then From_With_Type (Etype (Prefix (Name)))
3164 and then not Is_Potentially_Use_Visible (Etype (Name))
3165 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
3166 N_Package_Specification
3169 ("premature usage of incomplete}", Prefix (Name),
3170 Etype (Prefix (Name)));
3173 -- We never need an actual subtype for the case of a selection
3174 -- for a indexed component of a non-packed array, since in
3175 -- this case gigi generates all the checks and can find the
3176 -- necessary bounds information.
3178 -- We also do not need an actual subtype for the case of
3179 -- a first, last, length, or range attribute applied to a
3180 -- non-packed array, since gigi can again get the bounds in
3181 -- these cases (gigi cannot handle the packed case, since it
3182 -- has the bounds of the packed array type, not the original
3183 -- bounds of the type). However, if the prefix is itself a
3184 -- selected component, as in a.b.c (i), gigi may regard a.b.c
3185 -- as a dynamic-sized temporary, so we do generate an actual
3186 -- subtype for this case.
3188 Parent_N := Parent (N);
3190 if not Is_Packed (Etype (Comp))
3192 ((Nkind (Parent_N) = N_Indexed_Component
3193 and then Nkind (Name) /= N_Selected_Component)
3195 (Nkind (Parent_N) = N_Attribute_Reference
3196 and then (Attribute_Name (Parent_N) = Name_First
3198 Attribute_Name (Parent_N) = Name_Last
3200 Attribute_Name (Parent_N) = Name_Length
3202 Attribute_Name (Parent_N) = Name_Range)))
3204 Set_Etype (N, Etype (Comp));
3206 -- If full analysis is not enabled, we do not generate an
3207 -- actual subtype, because in the absence of expansion
3208 -- reference to a formal of a protected type, for example,
3209 -- will not be properly transformed, and will lead to
3210 -- out-of-scope references in gigi.
3212 -- In all other cases, we currently build an actual subtype.
3213 -- It seems likely that many of these cases can be avoided,
3214 -- but right now, the front end makes direct references to the
3215 -- bounds (e.g. in generating a length check), and if we do
3216 -- not make an actual subtype, we end up getting a direct
3217 -- reference to a discriminant, which will not do.
3219 elsif Full_Analysis then
3221 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
3222 Insert_Action (N, Act_Decl);
3224 if No (Act_Decl) then
3225 Set_Etype (N, Etype (Comp));
3228 -- Component type depends on discriminants. Enter the
3229 -- main attributes of the subtype.
3232 Subt : constant Entity_Id :=
3233 Defining_Identifier (Act_Decl);
3236 Set_Etype (Subt, Base_Type (Etype (Comp)));
3237 Set_Ekind (Subt, Ekind (Etype (Comp)));
3238 Set_Etype (N, Subt);
3242 -- If Full_Analysis not enabled, just set the Etype
3245 Set_Etype (N, Etype (Comp));
3251 -- If the prefix is a private extension, check only the visible
3252 -- components of the partial view. This must include the tag,
3253 -- which can appear in expanded code in a tag check.
3255 if Ekind (Type_To_Use) = E_Record_Type_With_Private
3256 and then Chars (Selector_Name (N)) /= Name_uTag
3258 exit when Comp = Last_Entity (Type_To_Use);
3264 -- Ada 2005 (AI-252): The selected component can be interpreted as
3265 -- a prefixed view of a subprogram. Depending on the context, this is
3266 -- either a name that can appear in a renaming declaration, or part
3267 -- of an enclosing call given in prefix form.
3269 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
3270 -- selected component should resolve to a name.
3272 if Ada_Version >= Ada_05
3273 and then Is_Tagged_Type (Prefix_Type)
3274 and then not Is_Concurrent_Type (Prefix_Type)
3276 if Nkind (Parent (N)) = N_Generic_Association
3277 or else Nkind (Parent (N)) = N_Requeue_Statement
3278 or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
3280 if Find_Primitive_Operation (N) then
3284 elsif Try_Object_Operation (N) then
3288 -- If the transformation fails, it will be necessary to redo the
3289 -- analysis with all errors enabled, to indicate candidate
3290 -- interpretations and reasons for each failure ???
3294 elsif Is_Private_Type (Prefix_Type) then
3296 -- Allow access only to discriminants of the type. If the type has
3297 -- no full view, gigi uses the parent type for the components, so we
3298 -- do the same here.
3300 if No (Full_View (Prefix_Type)) then
3301 Type_To_Use := Root_Type (Base_Type (Prefix_Type));
3302 Comp := First_Entity (Type_To_Use);
3305 while Present (Comp) loop
3306 if Chars (Comp) = Chars (Sel) then
3307 if Ekind (Comp) = E_Discriminant then
3308 Set_Entity_With_Style_Check (Sel, Comp);
3309 Generate_Reference (Comp, Sel);
3311 Set_Etype (Sel, Etype (Comp));
3312 Set_Etype (N, Etype (Comp));
3314 if Is_Generic_Type (Prefix_Type)
3315 or else Is_Generic_Type (Root_Type (Prefix_Type))
3317 Set_Original_Discriminant (Sel, Comp);
3320 -- Before declaring an error, check whether this is tagged
3321 -- private type and a call to a primitive operation.
3323 elsif Ada_Version >= Ada_05
3324 and then Is_Tagged_Type (Prefix_Type)
3325 and then Try_Object_Operation (N)
3331 ("invisible selector for }",
3332 N, First_Subtype (Prefix_Type));
3333 Set_Entity (Sel, Any_Id);
3334 Set_Etype (N, Any_Type);
3343 elsif Is_Concurrent_Type (Prefix_Type) then
3345 -- Find visible operation with given name. For a protected type,
3346 -- the possible candidates are discriminants, entries or protected
3347 -- procedures. For a task type, the set can only include entries or
3348 -- discriminants if the task type is not an enclosing scope. If it
3349 -- is an enclosing scope (e.g. in an inner task) then all entities
3350 -- are visible, but the prefix must denote the enclosing scope, i.e.
3351 -- can only be a direct name or an expanded name.
3353 Set_Etype (Sel, Any_Type);
3354 In_Scope := In_Open_Scopes (Prefix_Type);
3356 while Present (Comp) loop
3357 if Chars (Comp) = Chars (Sel) then
3358 if Is_Overloadable (Comp) then
3359 Add_One_Interp (Sel, Comp, Etype (Comp));
3361 -- If the prefix is tagged, the correct interpretation may
3362 -- lie in the primitive or class-wide operations of the
3363 -- type. Perform a simple conformance check to determine
3364 -- whether Try_Object_Operation should be invoked even if
3365 -- a visible entity is found.
3367 if Is_Tagged_Type (Prefix_Type)
3369 Nkind_In (Parent (N), N_Procedure_Call_Statement,
3371 N_Indexed_Component)
3372 and then Has_Mode_Conformant_Spec (Comp)
3374 Has_Candidate := True;
3377 elsif Ekind (Comp) = E_Discriminant
3378 or else Ekind (Comp) = E_Entry_Family
3380 and then Is_Entity_Name (Name))
3382 Set_Entity_With_Style_Check (Sel, Comp);
3383 Generate_Reference (Comp, Sel);
3389 Set_Etype (Sel, Etype (Comp));
3390 Set_Etype (N, Etype (Comp));
3392 if Ekind (Comp) = E_Discriminant then
3393 Set_Original_Discriminant (Sel, Comp);
3396 -- For access type case, introduce explicit deference for more
3397 -- uniform treatment of entry calls.
3399 if Is_Access_Type (Etype (Name)) then
3400 Insert_Explicit_Dereference (Name);
3402 (Warn_On_Dereference, "?implicit dereference", N);
3408 exit when not In_Scope
3410 Comp = First_Private_Entity (Base_Type (Prefix_Type));
3413 -- If there is no visible entity with the given name or none of the
3414 -- visible entities are plausible interpretations, check whether
3415 -- there is some other primitive operation with that name.
3417 if Ada_Version >= Ada_05
3418 and then Is_Tagged_Type (Prefix_Type)
3420 if (Etype (N) = Any_Type
3421 or else not Has_Candidate)
3422 and then Try_Object_Operation (N)
3426 -- If the context is not syntactically a procedure call, it
3427 -- may be a call to a primitive function declared outside of
3428 -- the synchronized type.
3430 -- If the context is a procedure call, there might still be
3431 -- an overloading between an entry and a primitive procedure
3432 -- declared outside of the synchronized type, called in prefix
3433 -- notation. This is harder to disambiguate because in one case
3434 -- the controlling formal is implicit ???
3436 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
3437 and then Nkind (Parent (N)) /= N_Indexed_Component
3438 and then Try_Object_Operation (N)
3444 Set_Is_Overloaded (N, Is_Overloaded (Sel));
3449 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
3452 -- If N still has no type, the component is not defined in the prefix
3454 if Etype (N) = Any_Type then
3456 -- If the prefix is a single concurrent object, use its name in the
3457 -- error message, rather than that of its anonymous type.
3459 if Is_Concurrent_Type (Prefix_Type)
3460 and then Is_Internal_Name (Chars (Prefix_Type))
3461 and then not Is_Derived_Type (Prefix_Type)
3462 and then Is_Entity_Name (Name)
3465 Error_Msg_Node_2 := Entity (Name);
3466 Error_Msg_NE ("no selector& for&", N, Sel);
3468 Check_Misspelled_Selector (Type_To_Use, Sel);
3470 elsif Is_Generic_Type (Prefix_Type)
3471 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
3472 and then Prefix_Type /= Etype (Prefix_Type)
3473 and then Is_Record_Type (Etype (Prefix_Type))
3475 -- If this is a derived formal type, the parent may have
3476 -- different visibility at this point. Try for an inherited
3477 -- component before reporting an error.
3479 Set_Etype (Prefix (N), Etype (Prefix_Type));
3480 Analyze_Selected_Component (N);
3483 elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
3484 and then Is_Generic_Actual_Type (Prefix_Type)
3485 and then Present (Full_View (Prefix_Type))
3487 -- Similarly, if this the actual for a formal derived type, the
3488 -- component inherited from the generic parent may not be visible
3489 -- in the actual, but the selected component is legal.
3496 First_Component (Generic_Parent_Type (Parent (Prefix_Type)));
3497 while Present (Comp) loop
3498 if Chars (Comp) = Chars (Sel) then
3499 Set_Entity_With_Style_Check (Sel, Comp);
3500 Set_Etype (Sel, Etype (Comp));
3501 Set_Etype (N, Etype (Comp));
3505 Next_Component (Comp);
3508 pragma Assert (Etype (N) /= Any_Type);
3512 if Ekind (Prefix_Type) = E_Record_Subtype then
3514 -- Check whether this is a component of the base type
3515 -- which is absent from a statically constrained subtype.
3516 -- This will raise constraint error at run-time, but is
3517 -- not a compile-time error. When the selector is illegal
3518 -- for base type as well fall through and generate a
3519 -- compilation error anyway.
3521 Comp := First_Component (Base_Type (Prefix_Type));
3522 while Present (Comp) loop
3523 if Chars (Comp) = Chars (Sel)
3524 and then Is_Visible_Component (Comp)
3526 Set_Entity_With_Style_Check (Sel, Comp);
3527 Generate_Reference (Comp, Sel);
3528 Set_Etype (Sel, Etype (Comp));
3529 Set_Etype (N, Etype (Comp));
3531 -- Emit appropriate message. Gigi will replace the
3532 -- node subsequently with the appropriate Raise.
3534 Apply_Compile_Time_Constraint_Error
3535 (N, "component not present in }?",
3536 CE_Discriminant_Check_Failed,
3537 Ent => Prefix_Type, Rep => False);
3538 Set_Raises_Constraint_Error (N);
3542 Next_Component (Comp);
3547 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
3548 Error_Msg_NE ("no selector& for}", N, Sel);
3550 Check_Misspelled_Selector (Type_To_Use, Sel);
3553 Set_Entity (Sel, Any_Id);
3554 Set_Etype (Sel, Any_Type);
3556 end Analyze_Selected_Component;
3558 ---------------------------
3559 -- Analyze_Short_Circuit --
3560 ---------------------------
3562 procedure Analyze_Short_Circuit (N : Node_Id) is
3563 L : constant Node_Id := Left_Opnd (N);
3564 R : constant Node_Id := Right_Opnd (N);
3569 Analyze_Expression (L);
3570 Analyze_Expression (R);
3571 Set_Etype (N, Any_Type);
3573 if not Is_Overloaded (L) then
3574 if Root_Type (Etype (L)) = Standard_Boolean
3575 and then Has_Compatible_Type (R, Etype (L))
3577 Add_One_Interp (N, Etype (L), Etype (L));
3581 Get_First_Interp (L, Ind, It);
3582 while Present (It.Typ) loop
3583 if Root_Type (It.Typ) = Standard_Boolean
3584 and then Has_Compatible_Type (R, It.Typ)
3586 Add_One_Interp (N, It.Typ, It.Typ);
3589 Get_Next_Interp (Ind, It);
3593 -- Here we have failed to find an interpretation. Clearly we know that
3594 -- it is not the case that both operands can have an interpretation of
3595 -- Boolean, but this is by far the most likely intended interpretation.
3596 -- So we simply resolve both operands as Booleans, and at least one of
3597 -- these resolutions will generate an error message, and we do not need
3598 -- to give another error message on the short circuit operation itself.
3600 if Etype (N) = Any_Type then
3601 Resolve (L, Standard_Boolean);
3602 Resolve (R, Standard_Boolean);
3603 Set_Etype (N, Standard_Boolean);
3605 end Analyze_Short_Circuit;
3611 procedure Analyze_Slice (N : Node_Id) is
3612 P : constant Node_Id := Prefix (N);
3613 D : constant Node_Id := Discrete_Range (N);
3614 Array_Type : Entity_Id;
3616 procedure Analyze_Overloaded_Slice;
3617 -- If the prefix is overloaded, select those interpretations that
3618 -- yield a one-dimensional array type.
3620 ------------------------------
3621 -- Analyze_Overloaded_Slice --
3622 ------------------------------
3624 procedure Analyze_Overloaded_Slice is
3630 Set_Etype (N, Any_Type);
3632 Get_First_Interp (P, I, It);
3633 while Present (It.Nam) loop
3636 if Is_Access_Type (Typ) then
3637 Typ := Designated_Type (Typ);
3638 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3641 if Is_Array_Type (Typ)
3642 and then Number_Dimensions (Typ) = 1
3643 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
3645 Add_One_Interp (N, Typ, Typ);
3648 Get_Next_Interp (I, It);
3651 if Etype (N) = Any_Type then
3652 Error_Msg_N ("expect array type in prefix of slice", N);
3654 end Analyze_Overloaded_Slice;
3656 -- Start of processing for Analyze_Slice
3662 if Is_Overloaded (P) then
3663 Analyze_Overloaded_Slice;
3666 Array_Type := Etype (P);
3667 Set_Etype (N, Any_Type);
3669 if Is_Access_Type (Array_Type) then
3670 Array_Type := Designated_Type (Array_Type);
3671 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3674 if not Is_Array_Type (Array_Type) then
3675 Wrong_Type (P, Any_Array);
3677 elsif Number_Dimensions (Array_Type) > 1 then
3679 ("type is not one-dimensional array in slice prefix", N);
3682 Has_Compatible_Type (D, Etype (First_Index (Array_Type)))
3684 Wrong_Type (D, Etype (First_Index (Array_Type)));
3687 Set_Etype (N, Array_Type);
3692 -----------------------------
3693 -- Analyze_Type_Conversion --
3694 -----------------------------
3696 procedure Analyze_Type_Conversion (N : Node_Id) is
3697 Expr : constant Node_Id := Expression (N);
3701 -- If Conversion_OK is set, then the Etype is already set, and the
3702 -- only processing required is to analyze the expression. This is
3703 -- used to construct certain "illegal" conversions which are not
3704 -- allowed by Ada semantics, but can be handled OK by Gigi, see
3705 -- Sinfo for further details.
3707 if Conversion_OK (N) then
3712 -- Otherwise full type analysis is required, as well as some semantic
3713 -- checks to make sure the argument of the conversion is appropriate.
3715 Find_Type (Subtype_Mark (N));
3716 T := Entity (Subtype_Mark (N));
3718 Check_Fully_Declared (T, N);
3719 Analyze_Expression (Expr);
3720 Validate_Remote_Type_Type_Conversion (N);
3722 -- Only remaining step is validity checks on the argument. These
3723 -- are skipped if the conversion does not come from the source.
3725 if not Comes_From_Source (N) then
3728 -- If there was an error in a generic unit, no need to replicate the
3729 -- error message. Conversely, constant-folding in the generic may
3730 -- transform the argument of a conversion into a string literal, which
3731 -- is legal. Therefore the following tests are not performed in an
3734 elsif In_Instance then
3737 elsif Nkind (Expr) = N_Null then
3738 Error_Msg_N ("argument of conversion cannot be null", N);
3739 Error_Msg_N ("\use qualified expression instead", N);
3740 Set_Etype (N, Any_Type);
3742 elsif Nkind (Expr) = N_Aggregate then
3743 Error_Msg_N ("argument of conversion cannot be aggregate", N);
3744 Error_Msg_N ("\use qualified expression instead", N);
3746 elsif Nkind (Expr) = N_Allocator then
3747 Error_Msg_N ("argument of conversion cannot be an allocator", N);
3748 Error_Msg_N ("\use qualified expression instead", N);
3750 elsif Nkind (Expr) = N_String_Literal then
3751 Error_Msg_N ("argument of conversion cannot be string literal", N);
3752 Error_Msg_N ("\use qualified expression instead", N);
3754 elsif Nkind (Expr) = N_Character_Literal then
3755 if Ada_Version = Ada_83 then
3758 Error_Msg_N ("argument of conversion cannot be character literal",
3760 Error_Msg_N ("\use qualified expression instead", N);
3763 elsif Nkind (Expr) = N_Attribute_Reference
3765 (Attribute_Name (Expr) = Name_Access or else
3766 Attribute_Name (Expr) = Name_Unchecked_Access or else
3767 Attribute_Name (Expr) = Name_Unrestricted_Access)
3769 Error_Msg_N ("argument of conversion cannot be access", N);
3770 Error_Msg_N ("\use qualified expression instead", N);
3772 end Analyze_Type_Conversion;
3774 ----------------------
3775 -- Analyze_Unary_Op --
3776 ----------------------
3778 procedure Analyze_Unary_Op (N : Node_Id) is
3779 R : constant Node_Id := Right_Opnd (N);
3780 Op_Id : Entity_Id := Entity (N);
3783 Set_Etype (N, Any_Type);
3784 Candidate_Type := Empty;
3786 Analyze_Expression (R);
3788 if Present (Op_Id) then
3789 if Ekind (Op_Id) = E_Operator then
3790 Find_Unary_Types (R, Op_Id, N);
3792 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3796 Op_Id := Get_Name_Entity_Id (Chars (N));
3797 while Present (Op_Id) loop
3798 if Ekind (Op_Id) = E_Operator then
3799 if No (Next_Entity (First_Entity (Op_Id))) then
3800 Find_Unary_Types (R, Op_Id, N);
3803 elsif Is_Overloadable (Op_Id) then
3804 Analyze_User_Defined_Unary_Op (N, Op_Id);
3807 Op_Id := Homonym (Op_Id);
3812 end Analyze_Unary_Op;
3814 ----------------------------------
3815 -- Analyze_Unchecked_Expression --
3816 ----------------------------------
3818 procedure Analyze_Unchecked_Expression (N : Node_Id) is
3820 Analyze (Expression (N), Suppress => All_Checks);
3821 Set_Etype (N, Etype (Expression (N)));
3822 Save_Interps (Expression (N), N);
3823 end Analyze_Unchecked_Expression;
3825 ---------------------------------------
3826 -- Analyze_Unchecked_Type_Conversion --
3827 ---------------------------------------
3829 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
3831 Find_Type (Subtype_Mark (N));
3832 Analyze_Expression (Expression (N));
3833 Set_Etype (N, Entity (Subtype_Mark (N)));
3834 end Analyze_Unchecked_Type_Conversion;
3836 ------------------------------------
3837 -- Analyze_User_Defined_Binary_Op --
3838 ------------------------------------
3840 procedure Analyze_User_Defined_Binary_Op
3845 -- Only do analysis if the operator Comes_From_Source, since otherwise
3846 -- the operator was generated by the expander, and all such operators
3847 -- always refer to the operators in package Standard.
3849 if Comes_From_Source (N) then
3851 F1 : constant Entity_Id := First_Formal (Op_Id);
3852 F2 : constant Entity_Id := Next_Formal (F1);
3855 -- Verify that Op_Id is a visible binary function. Note that since
3856 -- we know Op_Id is overloaded, potentially use visible means use
3857 -- visible for sure (RM 9.4(11)).
3859 if Ekind (Op_Id) = E_Function
3860 and then Present (F2)
3861 and then (Is_Immediately_Visible (Op_Id)
3862 or else Is_Potentially_Use_Visible (Op_Id))
3863 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
3864 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
3866 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3868 if Debug_Flag_E then
3869 Write_Str ("user defined operator ");
3870 Write_Name (Chars (Op_Id));
3871 Write_Str (" on node ");
3872 Write_Int (Int (N));
3878 end Analyze_User_Defined_Binary_Op;
3880 -----------------------------------
3881 -- Analyze_User_Defined_Unary_Op --
3882 -----------------------------------
3884 procedure Analyze_User_Defined_Unary_Op
3889 -- Only do analysis if the operator Comes_From_Source, since otherwise
3890 -- the operator was generated by the expander, and all such operators
3891 -- always refer to the operators in package Standard.
3893 if Comes_From_Source (N) then
3895 F : constant Entity_Id := First_Formal (Op_Id);
3898 -- Verify that Op_Id is a visible unary function. Note that since
3899 -- we know Op_Id is overloaded, potentially use visible means use
3900 -- visible for sure (RM 9.4(11)).
3902 if Ekind (Op_Id) = E_Function
3903 and then No (Next_Formal (F))
3904 and then (Is_Immediately_Visible (Op_Id)
3905 or else Is_Potentially_Use_Visible (Op_Id))
3906 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
3908 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3912 end Analyze_User_Defined_Unary_Op;
3914 ---------------------------
3915 -- Check_Arithmetic_Pair --
3916 ---------------------------
3918 procedure Check_Arithmetic_Pair
3919 (T1, T2 : Entity_Id;
3923 Op_Name : constant Name_Id := Chars (Op_Id);
3925 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
3926 -- Check whether the fixed-point type Typ has a user-defined operator
3927 -- (multiplication or division) that should hide the corresponding
3928 -- predefined operator. Used to implement Ada 2005 AI-264, to make
3929 -- such operators more visible and therefore useful.
3931 -- If the name of the operation is an expanded name with prefix
3932 -- Standard, the predefined universal fixed operator is available,
3933 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
3935 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
3936 -- Get specific type (i.e. non-universal type if there is one)
3942 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
3943 Bas : constant Entity_Id := Base_Type (Typ);
3949 -- If the universal_fixed operation is given explicitly the rule
3950 -- concerning primitive operations of the type do not apply.
3952 if Nkind (N) = N_Function_Call
3953 and then Nkind (Name (N)) = N_Expanded_Name
3954 and then Entity (Prefix (Name (N))) = Standard_Standard
3959 -- The operation is treated as primitive if it is declared in the
3960 -- same scope as the type, and therefore on the same entity chain.
3962 Ent := Next_Entity (Typ);
3963 while Present (Ent) loop
3964 if Chars (Ent) = Chars (Op) then
3965 F1 := First_Formal (Ent);
3966 F2 := Next_Formal (F1);
3968 -- The operation counts as primitive if either operand or
3969 -- result are of the given base type, and both operands are
3970 -- fixed point types.
3972 if (Base_Type (Etype (F1)) = Bas
3973 and then Is_Fixed_Point_Type (Etype (F2)))
3976 (Base_Type (Etype (F2)) = Bas
3977 and then Is_Fixed_Point_Type (Etype (F1)))
3980 (Base_Type (Etype (Ent)) = Bas
3981 and then Is_Fixed_Point_Type (Etype (F1))
3982 and then Is_Fixed_Point_Type (Etype (F2)))
3998 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
4000 if T1 = Universal_Integer or else T1 = Universal_Real then
4001 return Base_Type (T2);
4003 return Base_Type (T1);
4007 -- Start of processing for Check_Arithmetic_Pair
4010 if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
4012 if Is_Numeric_Type (T1)
4013 and then Is_Numeric_Type (T2)
4014 and then (Covers (T1 => T1, T2 => T2)
4016 Covers (T1 => T2, T2 => T1))
4018 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4021 elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
4023 if Is_Fixed_Point_Type (T1)
4024 and then (Is_Fixed_Point_Type (T2)
4025 or else T2 = Universal_Real)
4027 -- If Treat_Fixed_As_Integer is set then the Etype is already set
4028 -- and no further processing is required (this is the case of an
4029 -- operator constructed by Exp_Fixd for a fixed point operation)
4030 -- Otherwise add one interpretation with universal fixed result
4031 -- If the operator is given in functional notation, it comes
4032 -- from source and Fixed_As_Integer cannot apply.
4034 if (Nkind (N) not in N_Op
4035 or else not Treat_Fixed_As_Integer (N))
4037 (not Has_Fixed_Op (T1, Op_Id)
4038 or else Nkind (Parent (N)) = N_Type_Conversion)
4040 Add_One_Interp (N, Op_Id, Universal_Fixed);
4043 elsif Is_Fixed_Point_Type (T2)
4044 and then (Nkind (N) not in N_Op
4045 or else not Treat_Fixed_As_Integer (N))
4046 and then T1 = Universal_Real
4048 (not Has_Fixed_Op (T1, Op_Id)
4049 or else Nkind (Parent (N)) = N_Type_Conversion)
4051 Add_One_Interp (N, Op_Id, Universal_Fixed);
4053 elsif Is_Numeric_Type (T1)
4054 and then Is_Numeric_Type (T2)
4055 and then (Covers (T1 => T1, T2 => T2)
4057 Covers (T1 => T2, T2 => T1))
4059 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4061 elsif Is_Fixed_Point_Type (T1)
4062 and then (Base_Type (T2) = Base_Type (Standard_Integer)
4063 or else T2 = Universal_Integer)
4065 Add_One_Interp (N, Op_Id, T1);
4067 elsif T2 = Universal_Real
4068 and then Base_Type (T1) = Base_Type (Standard_Integer)
4069 and then Op_Name = Name_Op_Multiply
4071 Add_One_Interp (N, Op_Id, Any_Fixed);
4073 elsif T1 = Universal_Real
4074 and then Base_Type (T2) = Base_Type (Standard_Integer)
4076 Add_One_Interp (N, Op_Id, Any_Fixed);
4078 elsif Is_Fixed_Point_Type (T2)
4079 and then (Base_Type (T1) = Base_Type (Standard_Integer)
4080 or else T1 = Universal_Integer)
4081 and then Op_Name = Name_Op_Multiply
4083 Add_One_Interp (N, Op_Id, T2);
4085 elsif T1 = Universal_Real and then T2 = Universal_Integer then
4086 Add_One_Interp (N, Op_Id, T1);
4088 elsif T2 = Universal_Real
4089 and then T1 = Universal_Integer
4090 and then Op_Name = Name_Op_Multiply
4092 Add_One_Interp (N, Op_Id, T2);
4095 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
4097 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
4098 -- set does not require any special processing, since the Etype is
4099 -- already set (case of operation constructed by Exp_Fixed).
4101 if Is_Integer_Type (T1)
4102 and then (Covers (T1 => T1, T2 => T2)
4104 Covers (T1 => T2, T2 => T1))
4106 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4109 elsif Op_Name = Name_Op_Expon then
4110 if Is_Numeric_Type (T1)
4111 and then not Is_Fixed_Point_Type (T1)
4112 and then (Base_Type (T2) = Base_Type (Standard_Integer)
4113 or else T2 = Universal_Integer)
4115 Add_One_Interp (N, Op_Id, Base_Type (T1));
4118 else pragma Assert (Nkind (N) in N_Op_Shift);
4120 -- If not one of the predefined operators, the node may be one
4121 -- of the intrinsic functions. Its kind is always specific, and
4122 -- we can use it directly, rather than the name of the operation.
4124 if Is_Integer_Type (T1)
4125 and then (Base_Type (T2) = Base_Type (Standard_Integer)
4126 or else T2 = Universal_Integer)
4128 Add_One_Interp (N, Op_Id, Base_Type (T1));
4131 end Check_Arithmetic_Pair;
4133 -------------------------------
4134 -- Check_Misspelled_Selector --
4135 -------------------------------
4137 procedure Check_Misspelled_Selector
4138 (Prefix : Entity_Id;
4141 Max_Suggestions : constant := 2;
4142 Nr_Of_Suggestions : Natural := 0;
4144 Suggestion_1 : Entity_Id := Empty;
4145 Suggestion_2 : Entity_Id := Empty;
4150 -- All the components of the prefix of selector Sel are matched
4151 -- against Sel and a count is maintained of possible misspellings.
4152 -- When at the end of the analysis there are one or two (not more!)
4153 -- possible misspellings, these misspellings will be suggested as
4154 -- possible correction.
4156 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
4158 -- Concurrent types should be handled as well ???
4163 Comp := First_Entity (Prefix);
4164 while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
4165 if Is_Visible_Component (Comp) then
4166 if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
4167 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
4169 case Nr_Of_Suggestions is
4170 when 1 => Suggestion_1 := Comp;
4171 when 2 => Suggestion_2 := Comp;
4172 when others => exit;
4177 Comp := Next_Entity (Comp);
4180 -- Report at most two suggestions
4182 if Nr_Of_Suggestions = 1 then
4184 ("\possible misspelling of&", Sel, Suggestion_1);
4186 elsif Nr_Of_Suggestions = 2 then
4187 Error_Msg_Node_2 := Suggestion_2;
4189 ("\possible misspelling of& or&", Sel, Suggestion_1);
4191 end Check_Misspelled_Selector;
4193 ----------------------
4194 -- Defined_In_Scope --
4195 ----------------------
4197 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
4199 S1 : constant Entity_Id := Scope (Base_Type (T));
4202 or else (S1 = System_Aux_Id and then S = Scope (S1));
4203 end Defined_In_Scope;
4209 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
4215 Void_Interp_Seen : Boolean := False;
4218 pragma Warnings (Off, Boolean);
4221 if Ada_Version >= Ada_05 then
4222 Actual := First_Actual (N);
4223 while Present (Actual) loop
4225 -- Ada 2005 (AI-50217): Post an error in case of premature
4226 -- usage of an entity from the limited view.
4228 if not Analyzed (Etype (Actual))
4229 and then From_With_Type (Etype (Actual))
4231 Error_Msg_Qual_Level := 1;
4233 ("missing with_clause for scope of imported type&",
4234 Actual, Etype (Actual));
4235 Error_Msg_Qual_Level := 0;
4238 Next_Actual (Actual);
4242 -- Analyze each candidate call again, with full error reporting
4246 ("no candidate interpretations match the actuals:!", Nam);
4247 Err_Mode := All_Errors_Mode;
4248 All_Errors_Mode := True;
4250 -- If this is a call to an operation of a concurrent type,
4251 -- the failed interpretations have been removed from the
4252 -- name. Recover them to provide full diagnostics.
4254 if Nkind (Parent (Nam)) = N_Selected_Component then
4255 Set_Entity (Nam, Empty);
4256 New_Nam := New_Copy_Tree (Parent (Nam));
4257 Set_Is_Overloaded (New_Nam, False);
4258 Set_Is_Overloaded (Selector_Name (New_Nam), False);
4259 Set_Parent (New_Nam, Parent (Parent (Nam)));
4260 Analyze_Selected_Component (New_Nam);
4261 Get_First_Interp (Selector_Name (New_Nam), X, It);
4263 Get_First_Interp (Nam, X, It);
4266 while Present (It.Nam) loop
4267 if Etype (It.Nam) = Standard_Void_Type then
4268 Void_Interp_Seen := True;
4271 Analyze_One_Call (N, It.Nam, True, Success);
4272 Get_Next_Interp (X, It);
4275 if Nkind (N) = N_Function_Call then
4276 Get_First_Interp (Nam, X, It);
4277 while Present (It.Nam) loop
4278 if Ekind (It.Nam) = E_Function
4279 or else Ekind (It.Nam) = E_Operator
4283 Get_Next_Interp (X, It);
4287 -- If all interpretations are procedures, this deserves a
4288 -- more precise message. Ditto if this appears as the prefix
4289 -- of a selected component, which may be a lexical error.
4292 ("\context requires function call, found procedure name", Nam);
4294 if Nkind (Parent (N)) = N_Selected_Component
4295 and then N = Prefix (Parent (N))
4298 "\period should probably be semicolon", Parent (N));
4301 elsif Nkind (N) = N_Procedure_Call_Statement
4302 and then not Void_Interp_Seen
4305 "\function name found in procedure call", Nam);
4308 All_Errors_Mode := Err_Mode;
4311 ---------------------------
4312 -- Find_Arithmetic_Types --
4313 ---------------------------
4315 procedure Find_Arithmetic_Types
4320 Index1 : Interp_Index;
4321 Index2 : Interp_Index;
4325 procedure Check_Right_Argument (T : Entity_Id);
4326 -- Check right operand of operator
4328 --------------------------
4329 -- Check_Right_Argument --
4330 --------------------------
4332 procedure Check_Right_Argument (T : Entity_Id) is
4334 if not Is_Overloaded (R) then
4335 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
4337 Get_First_Interp (R, Index2, It2);
4338 while Present (It2.Typ) loop
4339 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
4340 Get_Next_Interp (Index2, It2);
4343 end Check_Right_Argument;
4345 -- Start processing for Find_Arithmetic_Types
4348 if not Is_Overloaded (L) then
4349 Check_Right_Argument (Etype (L));
4352 Get_First_Interp (L, Index1, It1);
4353 while Present (It1.Typ) loop
4354 Check_Right_Argument (It1.Typ);
4355 Get_Next_Interp (Index1, It1);
4359 end Find_Arithmetic_Types;
4361 ------------------------
4362 -- Find_Boolean_Types --
4363 ------------------------
4365 procedure Find_Boolean_Types
4370 Index : Interp_Index;
4373 procedure Check_Numeric_Argument (T : Entity_Id);
4374 -- Special case for logical operations one of whose operands is an
4375 -- integer literal. If both are literal the result is any modular type.
4377 ----------------------------
4378 -- Check_Numeric_Argument --
4379 ----------------------------
4381 procedure Check_Numeric_Argument (T : Entity_Id) is
4383 if T = Universal_Integer then
4384 Add_One_Interp (N, Op_Id, Any_Modular);
4386 elsif Is_Modular_Integer_Type (T) then
4387 Add_One_Interp (N, Op_Id, T);
4389 end Check_Numeric_Argument;
4391 -- Start of processing for Find_Boolean_Types
4394 if not Is_Overloaded (L) then
4395 if Etype (L) = Universal_Integer
4396 or else Etype (L) = Any_Modular
4398 if not Is_Overloaded (R) then
4399 Check_Numeric_Argument (Etype (R));
4402 Get_First_Interp (R, Index, It);
4403 while Present (It.Typ) loop
4404 Check_Numeric_Argument (It.Typ);
4405 Get_Next_Interp (Index, It);
4409 -- If operands are aggregates, we must assume that they may be
4410 -- boolean arrays, and leave disambiguation for the second pass.
4411 -- If only one is an aggregate, verify that the other one has an
4412 -- interpretation as a boolean array
4414 elsif Nkind (L) = N_Aggregate then
4415 if Nkind (R) = N_Aggregate then
4416 Add_One_Interp (N, Op_Id, Etype (L));
4418 elsif not Is_Overloaded (R) then
4419 if Valid_Boolean_Arg (Etype (R)) then
4420 Add_One_Interp (N, Op_Id, Etype (R));
4424 Get_First_Interp (R, Index, It);
4425 while Present (It.Typ) loop
4426 if Valid_Boolean_Arg (It.Typ) then
4427 Add_One_Interp (N, Op_Id, It.Typ);
4430 Get_Next_Interp (Index, It);
4434 elsif Valid_Boolean_Arg (Etype (L))
4435 and then Has_Compatible_Type (R, Etype (L))
4437 Add_One_Interp (N, Op_Id, Etype (L));
4441 Get_First_Interp (L, Index, It);
4442 while Present (It.Typ) loop
4443 if Valid_Boolean_Arg (It.Typ)
4444 and then Has_Compatible_Type (R, It.Typ)
4446 Add_One_Interp (N, Op_Id, It.Typ);
4449 Get_Next_Interp (Index, It);
4452 end Find_Boolean_Types;
4454 ---------------------------
4455 -- Find_Comparison_Types --
4456 ---------------------------
4458 procedure Find_Comparison_Types
4463 Index : Interp_Index;
4465 Found : Boolean := False;
4468 Scop : Entity_Id := Empty;
4470 procedure Try_One_Interp (T1 : Entity_Id);
4471 -- Routine to try one proposed interpretation. Note that the context
4472 -- of the operator plays no role in resolving the arguments, so that
4473 -- if there is more than one interpretation of the operands that is
4474 -- compatible with comparison, the operation is ambiguous.
4476 --------------------
4477 -- Try_One_Interp --
4478 --------------------
4480 procedure Try_One_Interp (T1 : Entity_Id) is
4483 -- If the operator is an expanded name, then the type of the operand
4484 -- must be defined in the corresponding scope. If the type is
4485 -- universal, the context will impose the correct type.
4488 and then not Defined_In_Scope (T1, Scop)
4489 and then T1 /= Universal_Integer
4490 and then T1 /= Universal_Real
4491 and then T1 /= Any_String
4492 and then T1 /= Any_Composite
4497 if Valid_Comparison_Arg (T1)
4498 and then Has_Compatible_Type (R, T1)
4501 and then Base_Type (T1) /= Base_Type (T_F)
4503 It := Disambiguate (L, I_F, Index, Any_Type);
4505 if It = No_Interp then
4506 Ambiguous_Operands (N);
4507 Set_Etype (L, Any_Type);
4521 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
4526 -- Start processing for Find_Comparison_Types
4529 -- If left operand is aggregate, the right operand has to
4530 -- provide a usable type for it.
4532 if Nkind (L) = N_Aggregate
4533 and then Nkind (R) /= N_Aggregate
4535 Find_Comparison_Types (L => R, R => L, Op_Id => Op_Id, N => N);
4539 if Nkind (N) = N_Function_Call
4540 and then Nkind (Name (N)) = N_Expanded_Name
4542 Scop := Entity (Prefix (Name (N)));
4544 -- The prefix may be a package renaming, and the subsequent test
4545 -- requires the original package.
4547 if Ekind (Scop) = E_Package
4548 and then Present (Renamed_Entity (Scop))
4550 Scop := Renamed_Entity (Scop);
4551 Set_Entity (Prefix (Name (N)), Scop);
4555 if not Is_Overloaded (L) then
4556 Try_One_Interp (Etype (L));
4559 Get_First_Interp (L, Index, It);
4560 while Present (It.Typ) loop
4561 Try_One_Interp (It.Typ);
4562 Get_Next_Interp (Index, It);
4565 end Find_Comparison_Types;
4567 ----------------------------------------
4568 -- Find_Non_Universal_Interpretations --
4569 ----------------------------------------
4571 procedure Find_Non_Universal_Interpretations
4577 Index : Interp_Index;
4581 if T1 = Universal_Integer
4582 or else T1 = Universal_Real
4584 if not Is_Overloaded (R) then
4586 (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
4588 Get_First_Interp (R, Index, It);
4589 while Present (It.Typ) loop
4590 if Covers (It.Typ, T1) then
4592 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
4595 Get_Next_Interp (Index, It);
4599 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
4601 end Find_Non_Universal_Interpretations;
4603 ------------------------------
4604 -- Find_Concatenation_Types --
4605 ------------------------------
4607 procedure Find_Concatenation_Types
4612 Op_Type : constant Entity_Id := Etype (Op_Id);
4615 if Is_Array_Type (Op_Type)
4616 and then not Is_Limited_Type (Op_Type)
4618 and then (Has_Compatible_Type (L, Op_Type)
4620 Has_Compatible_Type (L, Component_Type (Op_Type)))
4622 and then (Has_Compatible_Type (R, Op_Type)
4624 Has_Compatible_Type (R, Component_Type (Op_Type)))
4626 Add_One_Interp (N, Op_Id, Op_Type);
4628 end Find_Concatenation_Types;
4630 -------------------------
4631 -- Find_Equality_Types --
4632 -------------------------
4634 procedure Find_Equality_Types
4639 Index : Interp_Index;
4641 Found : Boolean := False;
4644 Scop : Entity_Id := Empty;
4646 procedure Try_One_Interp (T1 : Entity_Id);
4647 -- The context of the operator plays no role in resolving the
4648 -- arguments, so that if there is more than one interpretation
4649 -- of the operands that is compatible with equality, the construct
4650 -- is ambiguous and an error can be emitted now, after trying to
4651 -- disambiguate, i.e. applying preference rules.
4653 --------------------
4654 -- Try_One_Interp --
4655 --------------------
4657 procedure Try_One_Interp (T1 : Entity_Id) is
4659 -- If the operator is an expanded name, then the type of the operand
4660 -- must be defined in the corresponding scope. If the type is
4661 -- universal, the context will impose the correct type. An anonymous
4662 -- type for a 'Access reference is also universal in this sense, as
4663 -- the actual type is obtained from context.
4664 -- In Ada 2005, the equality operator for anonymous access types
4665 -- is declared in Standard, and preference rules apply to it.
4667 if Present (Scop) then
4668 if Defined_In_Scope (T1, Scop)
4669 or else T1 = Universal_Integer
4670 or else T1 = Universal_Real
4671 or else T1 = Any_Access
4672 or else T1 = Any_String
4673 or else T1 = Any_Composite
4674 or else (Ekind (T1) = E_Access_Subprogram_Type
4675 and then not Comes_From_Source (T1))
4679 elsif Ekind (T1) = E_Anonymous_Access_Type
4680 and then Scop = Standard_Standard
4685 -- The scope does not contain an operator for the type
4691 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
4692 -- Do not allow anonymous access types in equality operators.
4694 if Ada_Version < Ada_05
4695 and then Ekind (T1) = E_Anonymous_Access_Type
4700 if T1 /= Standard_Void_Type
4701 and then not Is_Limited_Type (T1)
4702 and then not Is_Limited_Composite (T1)
4703 and then Has_Compatible_Type (R, T1)
4706 and then Base_Type (T1) /= Base_Type (T_F)
4708 It := Disambiguate (L, I_F, Index, Any_Type);
4710 if It = No_Interp then
4711 Ambiguous_Operands (N);
4712 Set_Etype (L, Any_Type);
4725 if not Analyzed (L) then
4729 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
4731 -- Case of operator was not visible, Etype still set to Any_Type
4733 if Etype (N) = Any_Type then
4737 elsif Scop = Standard_Standard
4738 and then Ekind (T1) = E_Anonymous_Access_Type
4744 -- Start of processing for Find_Equality_Types
4747 -- If left operand is aggregate, the right operand has to
4748 -- provide a usable type for it.
4750 if Nkind (L) = N_Aggregate
4751 and then Nkind (R) /= N_Aggregate
4753 Find_Equality_Types (L => R, R => L, Op_Id => Op_Id, N => N);
4757 if Nkind (N) = N_Function_Call
4758 and then Nkind (Name (N)) = N_Expanded_Name
4760 Scop := Entity (Prefix (Name (N)));
4762 -- The prefix may be a package renaming, and the subsequent test
4763 -- requires the original package.
4765 if Ekind (Scop) = E_Package
4766 and then Present (Renamed_Entity (Scop))
4768 Scop := Renamed_Entity (Scop);
4769 Set_Entity (Prefix (Name (N)), Scop);
4773 if not Is_Overloaded (L) then
4774 Try_One_Interp (Etype (L));
4777 Get_First_Interp (L, Index, It);
4778 while Present (It.Typ) loop
4779 Try_One_Interp (It.Typ);
4780 Get_Next_Interp (Index, It);
4783 end Find_Equality_Types;
4785 -------------------------
4786 -- Find_Negation_Types --
4787 -------------------------
4789 procedure Find_Negation_Types
4794 Index : Interp_Index;
4798 if not Is_Overloaded (R) then
4799 if Etype (R) = Universal_Integer then
4800 Add_One_Interp (N, Op_Id, Any_Modular);
4801 elsif Valid_Boolean_Arg (Etype (R)) then
4802 Add_One_Interp (N, Op_Id, Etype (R));
4806 Get_First_Interp (R, Index, It);
4807 while Present (It.Typ) loop
4808 if Valid_Boolean_Arg (It.Typ) then
4809 Add_One_Interp (N, Op_Id, It.Typ);
4812 Get_Next_Interp (Index, It);
4815 end Find_Negation_Types;
4817 ------------------------------
4818 -- Find_Primitive_Operation --
4819 ------------------------------
4821 function Find_Primitive_Operation (N : Node_Id) return Boolean is
4822 Obj : constant Node_Id := Prefix (N);
4823 Op : constant Node_Id := Selector_Name (N);
4830 Set_Etype (Op, Any_Type);
4832 if Is_Access_Type (Etype (Obj)) then
4833 Typ := Designated_Type (Etype (Obj));
4838 if Is_Class_Wide_Type (Typ) then
4839 Typ := Root_Type (Typ);
4842 Prims := Primitive_Operations (Typ);
4844 Prim := First_Elmt (Prims);
4845 while Present (Prim) loop
4846 if Chars (Node (Prim)) = Chars (Op) then
4847 Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
4848 Set_Etype (N, Etype (Node (Prim)));
4854 -- Now look for class-wide operations of the type or any of its
4855 -- ancestors by iterating over the homonyms of the selector.
4858 Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
4862 Hom := Current_Entity (Op);
4863 while Present (Hom) loop
4864 if (Ekind (Hom) = E_Procedure
4866 Ekind (Hom) = E_Function)
4867 and then Scope (Hom) = Scope (Typ)
4868 and then Present (First_Formal (Hom))
4870 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
4872 (Is_Access_Type (Etype (First_Formal (Hom)))
4874 Ekind (Etype (First_Formal (Hom))) =
4875 E_Anonymous_Access_Type
4878 (Designated_Type (Etype (First_Formal (Hom)))) =
4881 Add_One_Interp (Op, Hom, Etype (Hom));
4882 Set_Etype (N, Etype (Hom));
4885 Hom := Homonym (Hom);
4889 return Etype (Op) /= Any_Type;
4890 end Find_Primitive_Operation;
4892 ----------------------
4893 -- Find_Unary_Types --
4894 ----------------------
4896 procedure Find_Unary_Types
4901 Index : Interp_Index;
4905 if not Is_Overloaded (R) then
4906 if Is_Numeric_Type (Etype (R)) then
4907 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
4911 Get_First_Interp (R, Index, It);
4912 while Present (It.Typ) loop
4913 if Is_Numeric_Type (It.Typ) then
4914 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
4917 Get_Next_Interp (Index, It);
4920 end Find_Unary_Types;
4926 function Junk_Operand (N : Node_Id) return Boolean is
4930 if Error_Posted (N) then
4934 -- Get entity to be tested
4936 if Is_Entity_Name (N)
4937 and then Present (Entity (N))
4941 -- An odd case, a procedure name gets converted to a very peculiar
4942 -- function call, and here is where we detect this happening.
4944 elsif Nkind (N) = N_Function_Call
4945 and then Is_Entity_Name (Name (N))
4946 and then Present (Entity (Name (N)))
4950 -- Another odd case, there are at least some cases of selected
4951 -- components where the selected component is not marked as having
4952 -- an entity, even though the selector does have an entity
4954 elsif Nkind (N) = N_Selected_Component
4955 and then Present (Entity (Selector_Name (N)))
4957 Enode := Selector_Name (N);
4963 -- Now test the entity we got to see if it is a bad case
4965 case Ekind (Entity (Enode)) is
4969 ("package name cannot be used as operand", Enode);
4971 when Generic_Unit_Kind =>
4973 ("generic unit name cannot be used as operand", Enode);
4977 ("subtype name cannot be used as operand", Enode);
4981 ("entry name cannot be used as operand", Enode);
4985 ("procedure name cannot be used as operand", Enode);
4989 ("exception name cannot be used as operand", Enode);
4991 when E_Block | E_Label | E_Loop =>
4993 ("label name cannot be used as operand", Enode);
5003 --------------------
5004 -- Operator_Check --
5005 --------------------
5007 procedure Operator_Check (N : Node_Id) is
5009 Remove_Abstract_Operations (N);
5011 -- Test for case of no interpretation found for operator
5013 if Etype (N) = Any_Type then
5017 Op_Id : Entity_Id := Empty;
5020 R := Right_Opnd (N);
5022 if Nkind (N) in N_Binary_Op then
5028 -- If either operand has no type, then don't complain further,
5029 -- since this simply means that we have a propagated error.
5032 or else Etype (R) = Any_Type
5033 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
5037 -- We explicitly check for the case of concatenation of component
5038 -- with component to avoid reporting spurious matching array types
5039 -- that might happen to be lurking in distant packages (such as
5040 -- run-time packages). This also prevents inconsistencies in the
5041 -- messages for certain ACVC B tests, which can vary depending on
5042 -- types declared in run-time interfaces. Another improvement when
5043 -- aggregates are present is to look for a well-typed operand.
5045 elsif Present (Candidate_Type)
5046 and then (Nkind (N) /= N_Op_Concat
5047 or else Is_Array_Type (Etype (L))
5048 or else Is_Array_Type (Etype (R)))
5051 if Nkind (N) = N_Op_Concat then
5052 if Etype (L) /= Any_Composite
5053 and then Is_Array_Type (Etype (L))
5055 Candidate_Type := Etype (L);
5057 elsif Etype (R) /= Any_Composite
5058 and then Is_Array_Type (Etype (R))
5060 Candidate_Type := Etype (R);
5065 ("operator for} is not directly visible!",
5066 N, First_Subtype (Candidate_Type));
5067 Error_Msg_N ("use clause would make operation legal!", N);
5070 -- If either operand is a junk operand (e.g. package name), then
5071 -- post appropriate error messages, but do not complain further.
5073 -- Note that the use of OR in this test instead of OR ELSE is
5074 -- quite deliberate, we may as well check both operands in the
5075 -- binary operator case.
5077 elsif Junk_Operand (R)
5078 or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
5082 -- If we have a logical operator, one of whose operands is
5083 -- Boolean, then we know that the other operand cannot resolve to
5084 -- Boolean (since we got no interpretations), but in that case we
5085 -- pretty much know that the other operand should be Boolean, so
5086 -- resolve it that way (generating an error)
5088 elsif Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor) then
5089 if Etype (L) = Standard_Boolean then
5090 Resolve (R, Standard_Boolean);
5092 elsif Etype (R) = Standard_Boolean then
5093 Resolve (L, Standard_Boolean);
5097 -- For an arithmetic operator or comparison operator, if one
5098 -- of the operands is numeric, then we know the other operand
5099 -- is not the same numeric type. If it is a non-numeric type,
5100 -- then probably it is intended to match the other operand.
5102 elsif Nkind_In (N, N_Op_Add,
5108 Nkind_In (N, N_Op_Lt,
5114 if Is_Numeric_Type (Etype (L))
5115 and then not Is_Numeric_Type (Etype (R))
5117 Resolve (R, Etype (L));
5120 elsif Is_Numeric_Type (Etype (R))
5121 and then not Is_Numeric_Type (Etype (L))
5123 Resolve (L, Etype (R));
5127 -- Comparisons on A'Access are common enough to deserve a
5130 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne)
5131 and then Ekind (Etype (L)) = E_Access_Attribute_Type
5132 and then Ekind (Etype (R)) = E_Access_Attribute_Type
5135 ("two access attributes cannot be compared directly", N);
5137 ("\use qualified expression for one of the operands",
5141 -- Another one for C programmers
5143 elsif Nkind (N) = N_Op_Concat
5144 and then Valid_Boolean_Arg (Etype (L))
5145 and then Valid_Boolean_Arg (Etype (R))
5147 Error_Msg_N ("invalid operands for concatenation", N);
5148 Error_Msg_N ("\maybe AND was meant", N);
5151 -- A special case for comparison of access parameter with null
5153 elsif Nkind (N) = N_Op_Eq
5154 and then Is_Entity_Name (L)
5155 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
5156 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
5158 and then Nkind (R) = N_Null
5160 Error_Msg_N ("access parameter is not allowed to be null", L);
5161 Error_Msg_N ("\(call would raise Constraint_Error)", L);
5165 -- If we fall through then just give general message. Note that in
5166 -- the following messages, if the operand is overloaded we choose
5167 -- an arbitrary type to complain about, but that is probably more
5168 -- useful than not giving a type at all.
5170 if Nkind (N) in N_Unary_Op then
5171 Error_Msg_Node_2 := Etype (R);
5172 Error_Msg_N ("operator& not defined for}", N);
5176 if Nkind (N) in N_Binary_Op then
5177 if not Is_Overloaded (L)
5178 and then not Is_Overloaded (R)
5179 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
5181 Error_Msg_Node_2 := First_Subtype (Etype (R));
5182 Error_Msg_N ("there is no applicable operator& for}", N);
5185 -- Another attempt to find a fix: one of the candidate
5186 -- interpretations may not be use-visible. This has
5187 -- already been checked for predefined operators, so
5188 -- we examine only user-defined functions.
5190 Op_Id := Get_Name_Entity_Id (Chars (N));
5192 while Present (Op_Id) loop
5193 if Ekind (Op_Id) /= E_Operator
5194 and then Is_Overloadable (Op_Id)
5196 if not Is_Immediately_Visible (Op_Id)
5197 and then not In_Use (Scope (Op_Id))
5198 and then not Is_Abstract_Subprogram (Op_Id)
5199 and then not Is_Hidden (Op_Id)
5200 and then Ekind (Scope (Op_Id)) = E_Package
5203 (L, Etype (First_Formal (Op_Id)))
5205 (Next_Formal (First_Formal (Op_Id)))
5209 Etype (Next_Formal (First_Formal (Op_Id))))
5212 ("No legal interpretation for operator&", N);
5214 ("\use clause on& would make operation legal",
5220 Op_Id := Homonym (Op_Id);
5224 Error_Msg_N ("invalid operand types for operator&", N);
5226 if Nkind (N) /= N_Op_Concat then
5227 Error_Msg_NE ("\left operand has}!", N, Etype (L));
5228 Error_Msg_NE ("\right operand has}!", N, Etype (R));
5238 -----------------------------------------
5239 -- Process_Implicit_Dereference_Prefix --
5240 -----------------------------------------
5242 function Process_Implicit_Dereference_Prefix
5244 P : Entity_Id) return Entity_Id
5247 Typ : constant Entity_Id := Designated_Type (Etype (P));
5251 and then (Operating_Mode = Check_Semantics or else not Expander_Active)
5253 -- We create a dummy reference to E to ensure that the reference
5254 -- is not considered as part of an assignment (an implicit
5255 -- dereference can never assign to its prefix). The Comes_From_Source
5256 -- attribute needs to be propagated for accurate warnings.
5258 Ref := New_Reference_To (E, Sloc (P));
5259 Set_Comes_From_Source (Ref, Comes_From_Source (P));
5260 Generate_Reference (E, Ref);
5263 -- An implicit dereference is a legal occurrence of an
5264 -- incomplete type imported through a limited_with clause,
5265 -- if the full view is visible.
5267 if From_With_Type (Typ)
5268 and then not From_With_Type (Scope (Typ))
5270 (Is_Immediately_Visible (Scope (Typ))
5272 (Is_Child_Unit (Scope (Typ))
5273 and then Is_Visible_Child_Unit (Scope (Typ))))
5275 return Available_View (Typ);
5280 end Process_Implicit_Dereference_Prefix;
5282 --------------------------------
5283 -- Remove_Abstract_Operations --
5284 --------------------------------
5286 procedure Remove_Abstract_Operations (N : Node_Id) is
5287 Abstract_Op : Entity_Id := Empty;
5288 Address_Kludge : Boolean := False;
5292 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
5293 -- activate this if either extensions are enabled, or if the abstract
5294 -- operation in question comes from a predefined file. This latter test
5295 -- allows us to use abstract to make operations invisible to users. In
5296 -- particular, if type Address is non-private and abstract subprograms
5297 -- are used to hide its operators, they will be truly hidden.
5299 type Operand_Position is (First_Op, Second_Op);
5300 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
5302 procedure Remove_Address_Interpretations (Op : Operand_Position);
5303 -- Ambiguities may arise when the operands are literal and the address
5304 -- operations in s-auxdec are visible. In that case, remove the
5305 -- interpretation of a literal as Address, to retain the semantics of
5306 -- Address as a private type.
5308 ------------------------------------
5309 -- Remove_Address_Interpretations --
5310 ------------------------------------
5312 procedure Remove_Address_Interpretations (Op : Operand_Position) is
5316 if Is_Overloaded (N) then
5317 Get_First_Interp (N, I, It);
5318 while Present (It.Nam) loop
5319 Formal := First_Entity (It.Nam);
5321 if Op = Second_Op then
5322 Formal := Next_Entity (Formal);
5325 if Is_Descendent_Of_Address (Etype (Formal)) then
5326 Address_Kludge := True;
5330 Get_Next_Interp (I, It);
5333 end Remove_Address_Interpretations;
5335 -- Start of processing for Remove_Abstract_Operations
5338 if Is_Overloaded (N) then
5339 Get_First_Interp (N, I, It);
5341 while Present (It.Nam) loop
5342 if Is_Overloadable (It.Nam)
5343 and then Is_Abstract_Subprogram (It.Nam)
5344 and then not Is_Dispatching_Operation (It.Nam)
5346 Abstract_Op := It.Nam;
5348 if Is_Descendent_Of_Address (It.Typ) then
5349 Address_Kludge := True;
5353 -- In Ada 2005, this operation does not participate in Overload
5354 -- resolution. If the operation is defined in a predefined
5355 -- unit, it is one of the operations declared abstract in some
5356 -- variants of System, and it must be removed as well.
5358 elsif Ada_Version >= Ada_05
5359 or else Is_Predefined_File_Name
5360 (Unit_File_Name (Get_Source_Unit (It.Nam)))
5367 Get_Next_Interp (I, It);
5370 if No (Abstract_Op) then
5372 -- If some interpretation yields an integer type, it is still
5373 -- possible that there are address interpretations. Remove them
5374 -- if one operand is a literal, to avoid spurious ambiguities
5375 -- on systems where Address is a visible integer type.
5377 if Is_Overloaded (N)
5378 and then Nkind (N) in N_Op
5379 and then Is_Integer_Type (Etype (N))
5381 if Nkind (N) in N_Binary_Op then
5382 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
5383 Remove_Address_Interpretations (Second_Op);
5385 elsif Nkind (Right_Opnd (N)) = N_Integer_Literal then
5386 Remove_Address_Interpretations (First_Op);
5391 elsif Nkind (N) in N_Op then
5393 -- Remove interpretations that treat literals as addresses. This
5394 -- is never appropriate, even when Address is defined as a visible
5395 -- Integer type. The reason is that we would really prefer Address
5396 -- to behave as a private type, even in this case, which is there
5397 -- only to accommodate oddities of VMS address sizes. If Address
5398 -- is a visible integer type, we get lots of overload ambiguities.
5400 if Nkind (N) in N_Binary_Op then
5402 U1 : constant Boolean :=
5403 Present (Universal_Interpretation (Right_Opnd (N)));
5404 U2 : constant Boolean :=
5405 Present (Universal_Interpretation (Left_Opnd (N)));
5409 Remove_Address_Interpretations (Second_Op);
5413 Remove_Address_Interpretations (First_Op);
5416 if not (U1 and U2) then
5418 -- Remove corresponding predefined operator, which is
5419 -- always added to the overload set.
5421 Get_First_Interp (N, I, It);
5422 while Present (It.Nam) loop
5423 if Scope (It.Nam) = Standard_Standard
5424 and then Base_Type (It.Typ) =
5425 Base_Type (Etype (Abstract_Op))
5430 Get_Next_Interp (I, It);
5433 elsif Is_Overloaded (N)
5434 and then Present (Univ_Type)
5436 -- If both operands have a universal interpretation,
5437 -- it is still necessary to remove interpretations that
5438 -- yield Address. Any remaining ambiguities will be
5439 -- removed in Disambiguate.
5441 Get_First_Interp (N, I, It);
5442 while Present (It.Nam) loop
5443 if Is_Descendent_Of_Address (It.Typ) then
5446 elsif not Is_Type (It.Nam) then
5447 Set_Entity (N, It.Nam);
5450 Get_Next_Interp (I, It);
5456 elsif Nkind (N) = N_Function_Call
5458 (Nkind (Name (N)) = N_Operator_Symbol
5460 (Nkind (Name (N)) = N_Expanded_Name
5462 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
5466 Arg1 : constant Node_Id := First (Parameter_Associations (N));
5467 U1 : constant Boolean :=
5468 Present (Universal_Interpretation (Arg1));
5469 U2 : constant Boolean :=
5470 Present (Next (Arg1)) and then
5471 Present (Universal_Interpretation (Next (Arg1)));
5475 Remove_Address_Interpretations (First_Op);
5479 Remove_Address_Interpretations (Second_Op);
5482 if not (U1 and U2) then
5483 Get_First_Interp (N, I, It);
5484 while Present (It.Nam) loop
5485 if Scope (It.Nam) = Standard_Standard
5486 and then It.Typ = Base_Type (Etype (Abstract_Op))
5491 Get_Next_Interp (I, It);
5497 -- If the removal has left no valid interpretations, emit an error
5498 -- message now and label node as illegal.
5500 if Present (Abstract_Op) then
5501 Get_First_Interp (N, I, It);
5505 -- Removal of abstract operation left no viable candidate
5507 Set_Etype (N, Any_Type);
5508 Error_Msg_Sloc := Sloc (Abstract_Op);
5510 ("cannot call abstract operation& declared#", N, Abstract_Op);
5512 -- In Ada 2005, an abstract operation may disable predefined
5513 -- operators. Since the context is not yet known, we mark the
5514 -- predefined operators as potentially hidden. Do not include
5515 -- predefined operators when addresses are involved since this
5516 -- case is handled separately.
5518 elsif Ada_Version >= Ada_05
5519 and then not Address_Kludge
5521 while Present (It.Nam) loop
5522 if Is_Numeric_Type (It.Typ)
5523 and then Scope (It.Typ) = Standard_Standard
5525 Set_Abstract_Op (I, Abstract_Op);
5528 Get_Next_Interp (I, It);
5533 end Remove_Abstract_Operations;
5535 -----------------------
5536 -- Try_Indirect_Call --
5537 -----------------------
5539 function Try_Indirect_Call
5542 Typ : Entity_Id) return Boolean
5548 pragma Warnings (Off, Call_OK);
5551 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
5553 Actual := First_Actual (N);
5554 Formal := First_Formal (Designated_Type (Typ));
5555 while Present (Actual) and then Present (Formal) loop
5556 if not Has_Compatible_Type (Actual, Etype (Formal)) then
5561 Next_Formal (Formal);
5564 if No (Actual) and then No (Formal) then
5565 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
5567 -- Nam is a candidate interpretation for the name in the call,
5568 -- if it is not an indirect call.
5570 if not Is_Type (Nam)
5571 and then Is_Entity_Name (Name (N))
5573 Set_Entity (Name (N), Nam);
5580 end Try_Indirect_Call;
5582 ----------------------
5583 -- Try_Indexed_Call --
5584 ----------------------
5586 function Try_Indexed_Call
5590 Skip_First : Boolean) return Boolean
5592 Loc : constant Source_Ptr := Sloc (N);
5593 Actuals : constant List_Id := Parameter_Associations (N);
5598 Actual := First (Actuals);
5600 -- If the call was originally written in prefix form, skip the first
5601 -- actual, which is obviously not defaulted.
5607 Index := First_Index (Typ);
5608 while Present (Actual) and then Present (Index) loop
5610 -- If the parameter list has a named association, the expression
5611 -- is definitely a call and not an indexed component.
5613 if Nkind (Actual) = N_Parameter_Association then
5617 if Is_Entity_Name (Actual)
5618 and then Is_Type (Entity (Actual))
5619 and then No (Next (Actual))
5623 Prefix => Make_Function_Call (Loc,
5624 Name => Relocate_Node (Name (N))),
5626 New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
5631 elsif not Has_Compatible_Type (Actual, Etype (Index)) then
5639 if No (Actual) and then No (Index) then
5640 Add_One_Interp (N, Nam, Component_Type (Typ));
5642 -- Nam is a candidate interpretation for the name in the call,
5643 -- if it is not an indirect call.
5645 if not Is_Type (Nam)
5646 and then Is_Entity_Name (Name (N))
5648 Set_Entity (Name (N), Nam);
5655 end Try_Indexed_Call;
5657 --------------------------
5658 -- Try_Object_Operation --
5659 --------------------------
5661 function Try_Object_Operation (N : Node_Id) return Boolean is
5662 K : constant Node_Kind := Nkind (Parent (N));
5663 Is_Subprg_Call : constant Boolean := Nkind_In
5664 (K, N_Procedure_Call_Statement,
5666 Loc : constant Source_Ptr := Sloc (N);
5667 Obj : constant Node_Id := Prefix (N);
5668 Subprog : constant Node_Id :=
5669 Make_Identifier (Sloc (Selector_Name (N)),
5670 Chars => Chars (Selector_Name (N)));
5671 -- Identifier on which possible interpretations will be collected
5673 Report_Error : Boolean := False;
5674 -- If no candidate interpretation matches the context, redo the
5675 -- analysis with error enabled to provide additional information.
5678 Candidate : Entity_Id := Empty;
5679 New_Call_Node : Node_Id := Empty;
5680 Node_To_Replace : Node_Id;
5681 Obj_Type : Entity_Id := Etype (Obj);
5682 Success : Boolean := False;
5684 function Valid_Candidate
5687 Subp : Entity_Id) return Entity_Id;
5688 -- If the subprogram is a valid interpretation, record it, and add
5689 -- to the list of interpretations of Subprog.
5691 procedure Complete_Object_Operation
5692 (Call_Node : Node_Id;
5693 Node_To_Replace : Node_Id);
5694 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
5695 -- Call_Node, insert the object (or its dereference) as the first actual
5696 -- in the call, and complete the analysis of the call.
5698 procedure Report_Ambiguity (Op : Entity_Id);
5699 -- If a prefixed procedure call is ambiguous, indicate whether the
5700 -- call includes an implicit dereference or an implicit 'Access.
5702 procedure Transform_Object_Operation
5703 (Call_Node : out Node_Id;
5704 Node_To_Replace : out Node_Id);
5705 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
5706 -- Call_Node is the resulting subprogram call, Node_To_Replace is
5707 -- either N or the parent of N, and Subprog is a reference to the
5708 -- subprogram we are trying to match.
5710 function Try_Class_Wide_Operation
5711 (Call_Node : Node_Id;
5712 Node_To_Replace : Node_Id) return Boolean;
5713 -- Traverse all ancestor types looking for a class-wide subprogram
5714 -- for which the current operation is a valid non-dispatching call.
5716 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
5717 -- If prefix is overloaded, its interpretation may include different
5718 -- tagged types, and we must examine the primitive operations and
5719 -- the class-wide operations of each in order to find candidate
5720 -- interpretations for the call as a whole.
5722 function Try_Primitive_Operation
5723 (Call_Node : Node_Id;
5724 Node_To_Replace : Node_Id) return Boolean;
5725 -- Traverse the list of primitive subprograms looking for a dispatching
5726 -- operation for which the current node is a valid call .
5728 ---------------------
5729 -- Valid_Candidate --
5730 ---------------------
5732 function Valid_Candidate
5735 Subp : Entity_Id) return Entity_Id
5737 Comp_Type : Entity_Id;
5740 -- If the subprogram is a valid interpretation, record it in global
5741 -- variable Subprog, to collect all possible overloadings.
5744 if Subp /= Entity (Subprog) then
5745 Add_One_Interp (Subprog, Subp, Etype (Subp));
5749 -- If the call may be an indexed call, retrieve component type of
5750 -- resulting expression, and add possible interpretation.
5754 if Nkind (Call) = N_Function_Call
5755 and then Nkind (Parent (N)) = N_Indexed_Component
5756 and then Needs_One_Actual (Subp)
5758 if Is_Array_Type (Etype (Subp)) then
5759 Comp_Type := Component_Type (Etype (Subp));
5761 elsif Is_Access_Type (Etype (Subp))
5762 and then Is_Array_Type (Designated_Type (Etype (Subp)))
5764 Comp_Type := Component_Type (Designated_Type (Etype (Subp)));
5768 if Present (Comp_Type)
5769 and then Etype (Subprog) /= Comp_Type
5771 Add_One_Interp (Subprog, Subp, Comp_Type);
5774 if Etype (Call) /= Any_Type then
5779 end Valid_Candidate;
5781 -------------------------------
5782 -- Complete_Object_Operation --
5783 -------------------------------
5785 procedure Complete_Object_Operation
5786 (Call_Node : Node_Id;
5787 Node_To_Replace : Node_Id)
5789 Control : constant Entity_Id := First_Formal (Entity (Subprog));
5790 Formal_Type : constant Entity_Id := Etype (Control);
5791 First_Actual : Node_Id;
5794 -- Place the name of the operation, with its interpretations,
5795 -- on the rewritten call.
5797 Set_Name (Call_Node, Subprog);
5799 First_Actual := First (Parameter_Associations (Call_Node));
5801 -- For cross-reference purposes, treat the new node as being in
5802 -- the source if the original one is.
5804 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
5805 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
5807 if Nkind (N) = N_Selected_Component
5808 and then not Inside_A_Generic
5810 Set_Entity (Selector_Name (N), Entity (Subprog));
5813 -- If need be, rewrite first actual as an explicit dereference
5814 -- If the call is overloaded, the rewriting can only be done
5815 -- once the primitive operation is identified.
5817 if Is_Overloaded (Subprog) then
5819 -- The prefix itself may be overloaded, and its interpretations
5820 -- must be propagated to the new actual in the call.
5822 if Is_Overloaded (Obj) then
5823 Save_Interps (Obj, First_Actual);
5826 Rewrite (First_Actual, Obj);
5828 elsif not Is_Access_Type (Formal_Type)
5829 and then Is_Access_Type (Etype (Obj))
5831 Rewrite (First_Actual,
5832 Make_Explicit_Dereference (Sloc (Obj), Obj));
5833 Analyze (First_Actual);
5835 -- If we need to introduce an explicit dereference, verify that
5836 -- the resulting actual is compatible with the mode of the formal.
5838 if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
5839 and then Is_Access_Constant (Etype (Obj))
5842 ("expect variable in call to&", Prefix (N), Entity (Subprog));
5845 -- Conversely, if the formal is an access parameter and the object
5846 -- is not, replace the actual with a 'Access reference. Its analysis
5847 -- will check that the object is aliased.
5849 elsif Is_Access_Type (Formal_Type)
5850 and then not Is_Access_Type (Etype (Obj))
5852 -- A special case: A.all'access is illegal if A is an access to a
5853 -- constant and the context requires an access to a variable.
5855 if not Is_Access_Constant (Formal_Type) then
5856 if (Nkind (Obj) = N_Explicit_Dereference
5857 and then Is_Access_Constant (Etype (Prefix (Obj))))
5858 or else not Is_Variable (Obj)
5861 ("actual for& must be a variable", Obj, Control);
5865 Rewrite (First_Actual,
5866 Make_Attribute_Reference (Loc,
5867 Attribute_Name => Name_Access,
5868 Prefix => Relocate_Node (Obj)));
5870 if not Is_Aliased_View (Obj) then
5872 ("object in prefixed call to& must be aliased"
5873 & " (RM-2005 4.3.1 (13))",
5874 Prefix (First_Actual), Subprog);
5877 Analyze (First_Actual);
5880 if Is_Overloaded (Obj) then
5881 Save_Interps (Obj, First_Actual);
5884 Rewrite (First_Actual, Obj);
5887 Rewrite (Node_To_Replace, Call_Node);
5889 -- Propagate the interpretations collected in subprog to the new
5890 -- function call node, to be resolved from context.
5892 if Is_Overloaded (Subprog) then
5893 Save_Interps (Subprog, Node_To_Replace);
5895 Analyze (Node_To_Replace);
5897 end Complete_Object_Operation;
5899 ----------------------
5900 -- Report_Ambiguity --
5901 ----------------------
5903 procedure Report_Ambiguity (Op : Entity_Id) is
5904 Access_Formal : constant Boolean :=
5905 Is_Access_Type (Etype (First_Formal (Op)));
5906 Access_Actual : constant Boolean :=
5907 Is_Access_Type (Etype (Prefix (N)));
5910 Error_Msg_Sloc := Sloc (Op);
5912 if Access_Formal and then not Access_Actual then
5913 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
5915 ("\possible interpretation"
5916 & " (inherited, with implicit 'Access) #", N);
5919 ("\possible interpretation (with implicit 'Access) #", N);
5922 elsif not Access_Formal and then Access_Actual then
5923 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
5925 ("\possible interpretation"
5926 & " ( inherited, with implicit dereference) #", N);
5929 ("\possible interpretation (with implicit dereference) #", N);
5933 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
5934 Error_Msg_N ("\possible interpretation (inherited)#", N);
5936 Error_Msg_N ("\possible interpretation#", N);
5939 end Report_Ambiguity;
5941 --------------------------------
5942 -- Transform_Object_Operation --
5943 --------------------------------
5945 procedure Transform_Object_Operation
5946 (Call_Node : out Node_Id;
5947 Node_To_Replace : out Node_Id)
5949 Dummy : constant Node_Id := New_Copy (Obj);
5950 -- Placeholder used as a first parameter in the call, replaced
5951 -- eventually by the proper object.
5953 Parent_Node : constant Node_Id := Parent (N);
5959 -- Common case covering 1) Call to a procedure and 2) Call to a
5960 -- function that has some additional actuals.
5962 if Nkind_In (Parent_Node, N_Function_Call,
5963 N_Procedure_Call_Statement)
5965 -- N is a selected component node containing the name of the
5966 -- subprogram. If N is not the name of the parent node we must
5967 -- not replace the parent node by the new construct. This case
5968 -- occurs when N is a parameterless call to a subprogram that
5969 -- is an actual parameter of a call to another subprogram. For
5971 -- Some_Subprogram (..., Obj.Operation, ...)
5973 and then Name (Parent_Node) = N
5975 Node_To_Replace := Parent_Node;
5977 Actuals := Parameter_Associations (Parent_Node);
5979 if Present (Actuals) then
5980 Prepend (Dummy, Actuals);
5982 Actuals := New_List (Dummy);
5985 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
5987 Make_Procedure_Call_Statement (Loc,
5988 Name => New_Copy (Subprog),
5989 Parameter_Associations => Actuals);
5993 Make_Function_Call (Loc,
5994 Name => New_Copy (Subprog),
5995 Parameter_Associations => Actuals);
5999 -- Before analysis, a function call appears as an indexed component
6000 -- if there are no named associations.
6002 elsif Nkind (Parent_Node) = N_Indexed_Component
6003 and then N = Prefix (Parent_Node)
6005 Node_To_Replace := Parent_Node;
6007 Actuals := Expressions (Parent_Node);
6009 Actual := First (Actuals);
6010 while Present (Actual) loop
6015 Prepend (Dummy, Actuals);
6018 Make_Function_Call (Loc,
6019 Name => New_Copy (Subprog),
6020 Parameter_Associations => Actuals);
6022 -- Parameterless call: Obj.F is rewritten as F (Obj)
6025 Node_To_Replace := N;
6028 Make_Function_Call (Loc,
6029 Name => New_Copy (Subprog),
6030 Parameter_Associations => New_List (Dummy));
6032 end Transform_Object_Operation;
6034 ------------------------------
6035 -- Try_Class_Wide_Operation --
6036 ------------------------------
6038 function Try_Class_Wide_Operation
6039 (Call_Node : Node_Id;
6040 Node_To_Replace : Node_Id) return Boolean
6042 Anc_Type : Entity_Id;
6043 Matching_Op : Entity_Id := Empty;
6046 procedure Traverse_Homonyms
6047 (Anc_Type : Entity_Id;
6048 Error : out Boolean);
6049 -- Traverse the homonym chain of the subprogram searching for those
6050 -- homonyms whose first formal has the Anc_Type's class-wide type,
6051 -- or an anonymous access type designating the class-wide type. If
6052 -- an ambiguity is detected, then Error is set to True.
6054 procedure Traverse_Interfaces
6055 (Anc_Type : Entity_Id;
6056 Error : out Boolean);
6057 -- Traverse the list of interfaces, if any, associated with Anc_Type
6058 -- and search for acceptable class-wide homonyms associated with each
6059 -- interface. If an ambiguity is detected, then Error is set to True.
6061 -----------------------
6062 -- Traverse_Homonyms --
6063 -----------------------
6065 procedure Traverse_Homonyms
6066 (Anc_Type : Entity_Id;
6067 Error : out Boolean)
6069 Cls_Type : Entity_Id;
6077 Cls_Type := Class_Wide_Type (Anc_Type);
6079 Hom := Current_Entity (Subprog);
6081 -- Find operation whose first parameter is of the class-wide
6082 -- type, a subtype thereof, or an anonymous access to same.
6084 while Present (Hom) loop
6085 if (Ekind (Hom) = E_Procedure
6087 Ekind (Hom) = E_Function)
6088 and then Scope (Hom) = Scope (Anc_Type)
6089 and then Present (First_Formal (Hom))
6091 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
6093 (Is_Access_Type (Etype (First_Formal (Hom)))
6095 Ekind (Etype (First_Formal (Hom))) =
6096 E_Anonymous_Access_Type
6099 (Designated_Type (Etype (First_Formal (Hom)))) =
6102 Set_Etype (Call_Node, Any_Type);
6103 Set_Is_Overloaded (Call_Node, False);
6106 if No (Matching_Op) then
6107 Hom_Ref := New_Reference_To (Hom, Sloc (Subprog));
6108 Set_Etype (Call_Node, Any_Type);
6109 Set_Parent (Call_Node, Parent (Node_To_Replace));
6111 Set_Name (Call_Node, Hom_Ref);
6116 Report => Report_Error,
6118 Skip_First => True);
6121 Valid_Candidate (Success, Call_Node, Hom);
6127 Report => Report_Error,
6129 Skip_First => True);
6131 if Present (Valid_Candidate (Success, Call_Node, Hom))
6132 and then Nkind (Call_Node) /= N_Function_Call
6134 Error_Msg_NE ("ambiguous call to&", N, Hom);
6135 Report_Ambiguity (Matching_Op);
6136 Report_Ambiguity (Hom);
6143 Hom := Homonym (Hom);
6145 end Traverse_Homonyms;
6147 -------------------------
6148 -- Traverse_Interfaces --
6149 -------------------------
6151 procedure Traverse_Interfaces
6152 (Anc_Type : Entity_Id;
6153 Error : out Boolean)
6155 Intface_List : constant List_Id :=
6156 Abstract_Interface_List (Anc_Type);
6162 if Is_Non_Empty_List (Intface_List) then
6163 Intface := First (Intface_List);
6164 while Present (Intface) loop
6166 -- Look for acceptable class-wide homonyms associated with
6169 Traverse_Homonyms (Etype (Intface), Error);
6175 -- Continue the search by looking at each of the interface's
6176 -- associated interface ancestors.
6178 Traverse_Interfaces (Etype (Intface), Error);
6187 end Traverse_Interfaces;
6189 -- Start of processing for Try_Class_Wide_Operation
6192 -- Loop through ancestor types (including interfaces), traversing
6193 -- the homonym chain of the subprogram, trying out those homonyms
6194 -- whose first formal has the class-wide type of the ancestor, or
6195 -- an anonymous access type designating the class-wide type.
6197 Anc_Type := Obj_Type;
6199 -- Look for a match among homonyms associated with the ancestor
6201 Traverse_Homonyms (Anc_Type, Error);
6207 -- Continue the search for matches among homonyms associated with
6208 -- any interfaces implemented by the ancestor.
6210 Traverse_Interfaces (Anc_Type, Error);
6216 exit when Etype (Anc_Type) = Anc_Type;
6217 Anc_Type := Etype (Anc_Type);
6220 if Present (Matching_Op) then
6221 Set_Etype (Call_Node, Etype (Matching_Op));
6224 return Present (Matching_Op);
6225 end Try_Class_Wide_Operation;
6227 -----------------------------------
6228 -- Try_One_Prefix_Interpretation --
6229 -----------------------------------
6231 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
6235 if Is_Access_Type (Obj_Type) then
6236 Obj_Type := Designated_Type (Obj_Type);
6239 if Ekind (Obj_Type) = E_Private_Subtype then
6240 Obj_Type := Base_Type (Obj_Type);
6243 if Is_Class_Wide_Type (Obj_Type) then
6244 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
6247 -- The type may have be obtained through a limited_with clause,
6248 -- in which case the primitive operations are available on its
6249 -- non-limited view. If still incomplete, retrieve full view.
6251 if Ekind (Obj_Type) = E_Incomplete_Type
6252 and then From_With_Type (Obj_Type)
6254 Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
6257 -- If the object is not tagged, or the type is still an incomplete
6258 -- type, this is not a prefixed call.
6260 if not Is_Tagged_Type (Obj_Type)
6261 or else Is_Incomplete_Type (Obj_Type)
6266 if Try_Primitive_Operation
6267 (Call_Node => New_Call_Node,
6268 Node_To_Replace => Node_To_Replace)
6270 Try_Class_Wide_Operation
6271 (Call_Node => New_Call_Node,
6272 Node_To_Replace => Node_To_Replace)
6276 end Try_One_Prefix_Interpretation;
6278 -----------------------------
6279 -- Try_Primitive_Operation --
6280 -----------------------------
6282 function Try_Primitive_Operation
6283 (Call_Node : Node_Id;
6284 Node_To_Replace : Node_Id) return Boolean
6287 Prim_Op : Entity_Id;
6288 Matching_Op : Entity_Id := Empty;
6289 Prim_Op_Ref : Node_Id := Empty;
6291 Corr_Type : Entity_Id := Empty;
6292 -- If the prefix is a synchronized type, the controlling type of
6293 -- the primitive operation is the corresponding record type, else
6294 -- this is the object type itself.
6296 Success : Boolean := False;
6298 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
6299 -- For tagged types the candidate interpretations are found in
6300 -- the list of primitive operations of the type and its ancestors.
6301 -- For formal tagged types we have to find the operations declared
6302 -- in the same scope as the type (including in the generic formal
6303 -- part) because the type itself carries no primitive operations,
6304 -- except for formal derived types that inherit the operations of
6305 -- the parent and progenitors.
6306 -- If the context is a generic subprogram body, the generic formals
6307 -- are visible by name, but are not in the entity list of the
6308 -- subprogram because that list starts with the subprogram formals.
6309 -- We retrieve the candidate operations from the generic declaration.
6311 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
6312 -- Verify that the prefix, dereferenced if need be, is a valid
6313 -- controlling argument in a call to Op. The remaining actuals
6314 -- are checked in the subsequent call to Analyze_One_Call.
6316 ------------------------------
6317 -- Collect_Generic_Type_Ops --
6318 ------------------------------
6320 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
6321 Bas : constant Entity_Id := Base_Type (T);
6322 Candidates : constant Elist_Id := New_Elmt_List;
6326 procedure Check_Candidate;
6327 -- The operation is a candidate if its first parameter is a
6328 -- controlling operand of the desired type.
6330 -----------------------
6331 -- Check_Candidate; --
6332 -----------------------
6334 procedure Check_Candidate is
6336 Formal := First_Formal (Subp);
6339 and then Is_Controlling_Formal (Formal)
6341 (Base_Type (Etype (Formal)) = Bas
6343 (Is_Access_Type (Etype (Formal))
6344 and then Designated_Type (Etype (Formal)) = Bas))
6346 Append_Elmt (Subp, Candidates);
6348 end Check_Candidate;
6350 -- Start of processing for Collect_Generic_Type_Ops
6353 if Is_Derived_Type (T) then
6354 return Primitive_Operations (T);
6356 elsif Ekind (Scope (T)) = E_Procedure
6357 or else Ekind (Scope (T)) = E_Function
6359 -- Scan the list of generic formals to find subprograms
6360 -- that may have a first controlling formal of the type.
6367 First (Generic_Formal_Declarations
6368 (Unit_Declaration_Node (Scope (T))));
6369 while Present (Decl) loop
6370 if Nkind (Decl) in N_Formal_Subprogram_Declaration then
6371 Subp := Defining_Entity (Decl);
6382 -- Scan the list of entities declared in the same scope as
6383 -- the type. In general this will be an open scope, given that
6384 -- the call we are analyzing can only appear within a generic
6385 -- declaration or body (either the one that declares T, or a
6388 Subp := First_Entity (Scope (T));
6389 while Present (Subp) loop
6390 if Is_Overloadable (Subp) then
6399 end Collect_Generic_Type_Ops;
6401 -----------------------------
6402 -- Valid_First_Argument_Of --
6403 -----------------------------
6405 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
6406 Typ : Entity_Id := Etype (First_Formal (Op));
6409 if Is_Concurrent_Type (Typ)
6410 and then Present (Corresponding_Record_Type (Typ))
6412 Typ := Corresponding_Record_Type (Typ);
6415 -- Simple case. Object may be a subtype of the tagged type or
6416 -- may be the corresponding record of a synchronized type.
6418 return Obj_Type = Typ
6419 or else Base_Type (Obj_Type) = Typ
6420 or else Corr_Type = Typ
6422 -- Prefix can be dereferenced
6425 (Is_Access_Type (Corr_Type)
6426 and then Designated_Type (Corr_Type) = Typ)
6428 -- Formal is an access parameter, for which the object
6429 -- can provide an access.
6432 (Ekind (Typ) = E_Anonymous_Access_Type
6433 and then Designated_Type (Typ) = Base_Type (Corr_Type));
6434 end Valid_First_Argument_Of;
6436 -- Start of processing for Try_Primitive_Operation
6439 -- Look for subprograms in the list of primitive operations. The name
6440 -- must be identical, and the kind of call indicates the expected
6441 -- kind of operation (function or procedure). If the type is a
6442 -- (tagged) synchronized type, the primitive ops are attached to the
6443 -- corresponding record (base) type.
6445 if Is_Concurrent_Type (Obj_Type) then
6446 if not Present (Corresponding_Record_Type (Obj_Type)) then
6450 Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
6451 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
6453 elsif not Is_Generic_Type (Obj_Type) then
6454 Corr_Type := Obj_Type;
6455 Elmt := First_Elmt (Primitive_Operations (Obj_Type));
6458 Corr_Type := Obj_Type;
6459 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
6462 while Present (Elmt) loop
6463 Prim_Op := Node (Elmt);
6465 if Chars (Prim_Op) = Chars (Subprog)
6466 and then Present (First_Formal (Prim_Op))
6467 and then Valid_First_Argument_Of (Prim_Op)
6469 (Nkind (Call_Node) = N_Function_Call)
6470 = (Ekind (Prim_Op) = E_Function)
6472 -- Ada 2005 (AI-251): If this primitive operation corresponds
6473 -- with an immediate ancestor interface there is no need to add
6474 -- it to the list of interpretations; the corresponding aliased
6475 -- primitive is also in this list of primitive operations and
6476 -- will be used instead.
6478 if (Present (Interface_Alias (Prim_Op))
6479 and then Is_Ancestor (Find_Dispatching_Type
6480 (Alias (Prim_Op)), Corr_Type))
6483 -- Do not consider hidden primitives unless the type is
6484 -- in an open scope or we are within an instance, where
6485 -- visibility is known to be correct.
6487 (Is_Hidden (Prim_Op)
6488 and then not Is_Immediately_Visible (Obj_Type)
6489 and then not In_Instance)
6494 Set_Etype (Call_Node, Any_Type);
6495 Set_Is_Overloaded (Call_Node, False);
6497 if No (Matching_Op) then
6498 Prim_Op_Ref := New_Reference_To (Prim_Op, Sloc (Subprog));
6499 Candidate := Prim_Op;
6501 Set_Parent (Call_Node, Parent (Node_To_Replace));
6503 Set_Name (Call_Node, Prim_Op_Ref);
6509 Report => Report_Error,
6511 Skip_First => True);
6513 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
6515 -- More than one interpretation, collect for subsequent
6516 -- disambiguation. If this is a procedure call and there
6517 -- is another match, report ambiguity now.
6523 Report => Report_Error,
6525 Skip_First => True);
6527 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
6528 and then Nkind (Call_Node) /= N_Function_Call
6530 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
6531 Report_Ambiguity (Matching_Op);
6532 Report_Ambiguity (Prim_Op);
6542 if Present (Matching_Op) then
6543 Set_Etype (Call_Node, Etype (Matching_Op));
6546 return Present (Matching_Op);
6547 end Try_Primitive_Operation;
6549 -- Start of processing for Try_Object_Operation
6552 Analyze_Expression (Obj);
6554 -- Analyze the actuals if node is known to be a subprogram call
6556 if Is_Subprg_Call and then N = Name (Parent (N)) then
6557 Actual := First (Parameter_Associations (Parent (N)));
6558 while Present (Actual) loop
6559 Analyze_Expression (Actual);
6564 -- Build a subprogram call node, using a copy of Obj as its first
6565 -- actual. This is a placeholder, to be replaced by an explicit
6566 -- dereference when needed.
6568 Transform_Object_Operation
6569 (Call_Node => New_Call_Node,
6570 Node_To_Replace => Node_To_Replace);
6572 Set_Etype (New_Call_Node, Any_Type);
6573 Set_Etype (Subprog, Any_Type);
6574 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
6576 if not Is_Overloaded (Obj) then
6577 Try_One_Prefix_Interpretation (Obj_Type);
6584 Get_First_Interp (Obj, I, It);
6585 while Present (It.Nam) loop
6586 Try_One_Prefix_Interpretation (It.Typ);
6587 Get_Next_Interp (I, It);
6592 if Etype (New_Call_Node) /= Any_Type then
6593 Complete_Object_Operation
6594 (Call_Node => New_Call_Node,
6595 Node_To_Replace => Node_To_Replace);
6598 elsif Present (Candidate) then
6600 -- The argument list is not type correct. Re-analyze with error
6601 -- reporting enabled, and use one of the possible candidates.
6602 -- In All_Errors_Mode, re-analyze all failed interpretations.
6604 if All_Errors_Mode then
6605 Report_Error := True;
6606 if Try_Primitive_Operation
6607 (Call_Node => New_Call_Node,
6608 Node_To_Replace => Node_To_Replace)
6611 Try_Class_Wide_Operation
6612 (Call_Node => New_Call_Node,
6613 Node_To_Replace => Node_To_Replace)
6620 (N => New_Call_Node,
6624 Skip_First => True);
6627 -- No need for further errors
6632 -- There was no candidate operation, so report it as an error
6633 -- in the caller: Analyze_Selected_Component.
6637 end Try_Object_Operation;
6643 procedure wpo (T : Entity_Id) is
6648 if not Is_Tagged_Type (T) then
6652 E := First_Elmt (Primitive_Operations (Base_Type (T)));
6653 while Present (E) loop
6655 Write_Int (Int (Op));
6656 Write_Str (" === ");
6657 Write_Name (Chars (Op));
6659 Write_Name (Chars (Scope (Op)));