1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Util; use Exp_Util;
33 with Fname; use Fname;
34 with Itypes; use Itypes;
36 with Lib.Xref; use Lib.Xref;
37 with Namet; use Namet;
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_Ch8; use Sem_Ch8;
48 with Sem_Disp; use Sem_Disp;
49 with Sem_Dist; use Sem_Dist;
50 with Sem_Eval; use Sem_Eval;
51 with Sem_Res; use Sem_Res;
52 with Sem_Util; use Sem_Util;
53 with Sem_Type; use Sem_Type;
54 with Stand; use Stand;
55 with Sinfo; use Sinfo;
56 with Snames; use Snames;
57 with Tbuild; use Tbuild;
59 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
61 package body Sem_Ch4 is
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 procedure Analyze_Expression (N : Node_Id);
68 -- For expressions that are not names, this is just a call to analyze.
69 -- If the expression is a name, it may be a call to a parameterless
70 -- function, and if so must be converted into an explicit call node
71 -- and analyzed as such. This deproceduring must be done during the first
72 -- pass of overload resolution, because otherwise a procedure call with
73 -- overloaded actuals may fail to resolve. See 4327-001 for an example.
75 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
76 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
77 -- is an operator name or an expanded name whose selector is an operator
78 -- name, and one possible interpretation is as a predefined operator.
80 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
81 -- If the prefix of a selected_component is overloaded, the proper
82 -- interpretation that yields a record type with the proper selector
83 -- name must be selected.
85 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
86 -- Procedure to analyze a user defined binary operator, which is resolved
87 -- like a function, but instead of a list of actuals it is presented
88 -- with the left and right operands of an operator node.
90 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
91 -- Procedure to analyze a user defined unary operator, which is resolved
92 -- like a function, but instead of a list of actuals, it is presented with
93 -- the operand of the operator node.
95 procedure Ambiguous_Operands (N : Node_Id);
96 -- for equality, membership, and comparison operators with overloaded
97 -- arguments, list possible interpretations.
99 procedure Analyze_One_Call
103 Success : out Boolean;
104 Skip_First : Boolean := False);
105 -- Check one interpretation of an overloaded subprogram name for
106 -- compatibility with the types of the actuals in a call. If there is a
107 -- single interpretation which does not match, post error if Report is
110 -- Nam is the entity that provides the formals against which the actuals
111 -- are checked. Nam is either the name of a subprogram, or the internal
112 -- subprogram type constructed for an access_to_subprogram. If the actuals
113 -- are compatible with Nam, then Nam is added to the list of candidate
114 -- interpretations for N, and Success is set to True.
116 -- The flag Skip_First is used when analyzing a call that was rewritten
117 -- from object notation. In this case the first actual may have to receive
118 -- an explicit dereference, depending on the first formal of the operation
119 -- being called. The caller will have verified that the object is legal
120 -- for the call. If the remaining parameters match, the first parameter
121 -- will rewritten as a dereference if needed, prior to completing analysis.
123 procedure Check_Misspelled_Selector
126 -- Give possible misspelling diagnostic if Sel is likely to be
127 -- a misspelling of one of the selectors of the Prefix.
128 -- This is called by Analyze_Selected_Component after producing
129 -- an invalid selector error message.
131 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
132 -- Verify that type T is declared in scope S. Used to find intepretations
133 -- for operators given by expanded names. This is abstracted as a separate
134 -- function to handle extensions to System, where S is System, but T is
135 -- declared in the extension.
137 procedure Find_Arithmetic_Types
141 -- L and R are the operands of an arithmetic operator. Find
142 -- consistent pairs of interpretations for L and R that have a
143 -- numeric type consistent with the semantics of the operator.
145 procedure Find_Comparison_Types
149 -- L and R are operands of a comparison operator. Find consistent
150 -- pairs of interpretations for L and R.
152 procedure Find_Concatenation_Types
156 -- For the four varieties of concatenation
158 procedure Find_Equality_Types
162 -- Ditto for equality operators
164 procedure Find_Boolean_Types
168 -- Ditto for binary logical operations
170 procedure Find_Negation_Types
174 -- Find consistent interpretation for operand of negation operator
176 procedure Find_Non_Universal_Interpretations
181 -- For equality and comparison operators, the result is always boolean,
182 -- and the legality of the operation is determined from the visibility
183 -- of the operand types. If one of the operands has a universal interpre-
184 -- tation, the legality check uses some compatible non-universal
185 -- interpretation of the other operand. N can be an operator node, or
186 -- a function call whose name is an operator designator.
188 procedure Find_Unary_Types
192 -- Unary arithmetic types: plus, minus, abs
194 procedure Check_Arithmetic_Pair
198 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
199 -- types for left and right operand. Determine whether they constitute
200 -- a valid pair for the given operator, and record the corresponding
201 -- interpretation of the operator node. The node N may be an operator
202 -- node (the usual case) or a function call whose prefix is an operator
203 -- designator. In both cases Op_Id is the operator name itself.
205 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
206 -- Give detailed information on overloaded call where none of the
207 -- interpretations match. N is the call node, Nam the designator for
208 -- the overloaded entity being called.
210 function Junk_Operand (N : Node_Id) return Boolean;
211 -- Test for an operand that is an inappropriate entity (e.g. a package
212 -- name or a label). If so, issue an error message and return True. If
213 -- the operand is not an inappropriate entity kind, return False.
215 procedure Operator_Check (N : Node_Id);
216 -- Verify that an operator has received some valid interpretation. If none
217 -- was found, determine whether a use clause would make the operation
218 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
219 -- every type compatible with the operator, even if the operator for the
220 -- type is not directly visible. The routine uses this type to emit a more
221 -- informative message.
223 procedure Process_Implicit_Dereference_Prefix
226 -- Called when P is the prefix of an implicit dereference, denoting an
227 -- object E. If in semantics only mode (-gnatc or generic), record that is
228 -- a reference to E. Normally, such a reference is generated only when the
229 -- implicit dereference is expanded into an explicit one. E may be empty,
230 -- in which case this procedure does nothing.
232 procedure Remove_Abstract_Operations (N : Node_Id);
233 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
234 -- operation is not a candidate interpretation.
236 function Try_Indexed_Call
240 Skip_First : Boolean) return Boolean;
241 -- If a function has defaults for all its actuals, a call to it may in fact
242 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
243 -- interpretation as an indexing, prior to analysis as a call. If both are
244 -- possible, the node is overloaded with both interpretations (same symbol
245 -- but two different types). If the call is written in prefix form, the
246 -- prefix becomes the first parameter in the call, and only the remaining
247 -- actuals must be checked for the presence of defaults.
249 function Try_Indirect_Call
252 Typ : Entity_Id) return Boolean;
253 -- Similarly, a function F that needs no actuals can return an access to a
254 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
255 -- the call may be overloaded with both interpretations.
257 function Try_Object_Operation (N : Node_Id) return Boolean;
258 -- Ada 2005 (AI-252): Support the object.operation notation
260 ------------------------
261 -- Ambiguous_Operands --
262 ------------------------
264 procedure Ambiguous_Operands (N : Node_Id) is
265 procedure List_Operand_Interps (Opnd : Node_Id);
267 --------------------------
268 -- List_Operand_Interps --
269 --------------------------
271 procedure List_Operand_Interps (Opnd : Node_Id) is
276 if Is_Overloaded (Opnd) then
277 if Nkind (Opnd) in N_Op then
279 elsif Nkind (Opnd) = N_Function_Call then
289 if Opnd = Left_Opnd (N) then
291 ("\left operand has the following interpretations", N);
294 ("\right operand has the following interpretations", N);
298 List_Interps (Nam, Err);
299 end List_Operand_Interps;
301 -- Start of processing for Ambiguous_Operands
304 if Nkind (N) in N_Membership_Test then
305 Error_Msg_N ("ambiguous operands for membership", N);
307 elsif Nkind (N) = N_Op_Eq
308 or else Nkind (N) = N_Op_Ne
310 Error_Msg_N ("ambiguous operands for equality", N);
313 Error_Msg_N ("ambiguous operands for comparison", N);
316 if All_Errors_Mode then
317 List_Operand_Interps (Left_Opnd (N));
318 List_Operand_Interps (Right_Opnd (N));
320 Error_Msg_N ("\use -gnatf switch for details", N);
322 end Ambiguous_Operands;
324 -----------------------
325 -- Analyze_Aggregate --
326 -----------------------
328 -- Most of the analysis of Aggregates requires that the type be known,
329 -- and is therefore put off until resolution.
331 procedure Analyze_Aggregate (N : Node_Id) is
333 if No (Etype (N)) then
334 Set_Etype (N, Any_Composite);
336 end Analyze_Aggregate;
338 -----------------------
339 -- Analyze_Allocator --
340 -----------------------
342 procedure Analyze_Allocator (N : Node_Id) is
343 Loc : constant Source_Ptr := Sloc (N);
344 Sav_Errs : constant Nat := Serious_Errors_Detected;
345 E : Node_Id := Expression (N);
346 Acc_Type : Entity_Id;
350 Check_Restriction (No_Allocators, N);
352 if Nkind (E) = N_Qualified_Expression then
354 Acc_Type := Create_Itype (E_Allocator_Type, N);
355 Set_Etype (Acc_Type, Acc_Type);
356 Init_Size_Align (Acc_Type);
357 Find_Type (Subtype_Mark (E));
358 Type_Id := Entity (Subtype_Mark (E));
359 Check_Fully_Declared (Type_Id, N);
360 Set_Directly_Designated_Type (Acc_Type, Type_Id);
362 Analyze_And_Resolve (Expression (E), Type_Id);
364 if Is_Limited_Type (Type_Id)
365 and then Comes_From_Source (N)
366 and then not In_Instance_Body
368 if not OK_For_Limited_Init (Expression (E)) then
369 Error_Msg_N ("initialization not allowed for limited types", N);
370 Explain_Limited_Type (Type_Id, N);
374 -- A qualified expression requires an exact match of the type,
375 -- class-wide matching is not allowed.
377 if Is_Class_Wide_Type (Type_Id)
378 and then Base_Type (Etype (Expression (E))) /= Base_Type (Type_Id)
380 Wrong_Type (Expression (E), Type_Id);
383 Check_Non_Static_Context (Expression (E));
385 -- We don't analyze the qualified expression itself because it's
386 -- part of the allocator
388 Set_Etype (E, Type_Id);
390 -- Case where allocator has a subtype indication
395 Base_Typ : Entity_Id;
398 -- If the allocator includes a N_Subtype_Indication then a
399 -- constraint is present, otherwise the node is a subtype mark.
400 -- Introduce an explicit subtype declaration into the tree
401 -- defining some anonymous subtype and rewrite the allocator to
402 -- use this subtype rather than the subtype indication.
404 -- It is important to introduce the explicit subtype declaration
405 -- so that the bounds of the subtype indication are attached to
406 -- the tree in case the allocator is inside a generic unit.
408 if Nkind (E) = N_Subtype_Indication then
410 -- A constraint is only allowed for a composite type in Ada
411 -- 95. In Ada 83, a constraint is also allowed for an
412 -- access-to-composite type, but the constraint is ignored.
414 Find_Type (Subtype_Mark (E));
415 Base_Typ := Entity (Subtype_Mark (E));
417 if Is_Elementary_Type (Base_Typ) then
418 if not (Ada_Version = Ada_83
419 and then Is_Access_Type (Base_Typ))
421 Error_Msg_N ("constraint not allowed here", E);
423 if Nkind (Constraint (E))
424 = N_Index_Or_Discriminant_Constraint
427 ("\if qualified expression was meant, " &
428 "use apostrophe", Constraint (E));
432 -- Get rid of the bogus constraint:
434 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
435 Analyze_Allocator (N);
438 -- Ada 2005, AI-363: if the designated type has a constrained
439 -- partial view, it cannot receive a discriminant constraint,
440 -- and the allocated object is unconstrained.
442 elsif Ada_Version >= Ada_05
443 and then Has_Constrained_Partial_View (Base_Typ)
446 ("constraint no allowed when type " &
447 "has a constrained partial view", Constraint (E));
450 if Expander_Active then
452 Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
455 Make_Subtype_Declaration (Loc,
456 Defining_Identifier => Def_Id,
457 Subtype_Indication => Relocate_Node (E)));
459 if Sav_Errs /= Serious_Errors_Detected
460 and then Nkind (Constraint (E))
461 = N_Index_Or_Discriminant_Constraint
464 ("if qualified expression was meant, " &
465 "use apostrophe!", Constraint (E));
468 E := New_Occurrence_Of (Def_Id, Loc);
469 Rewrite (Expression (N), E);
473 Type_Id := Process_Subtype (E, N);
474 Acc_Type := Create_Itype (E_Allocator_Type, N);
475 Set_Etype (Acc_Type, Acc_Type);
476 Init_Size_Align (Acc_Type);
477 Set_Directly_Designated_Type (Acc_Type, Type_Id);
478 Check_Fully_Declared (Type_Id, N);
482 if Can_Never_Be_Null (Type_Id) then
483 Error_Msg_N ("(Ada 2005) qualified expression required",
487 -- Check restriction against dynamically allocated protected
488 -- objects. Note that when limited aggregates are supported,
489 -- a similar test should be applied to an allocator with a
490 -- qualified expression ???
492 if Is_Protected_Type (Type_Id) then
493 Check_Restriction (No_Protected_Type_Allocators, N);
496 -- Check for missing initialization. Skip this check if we already
497 -- had errors on analyzing the allocator, since in that case these
498 -- are probably cascaded errors
500 if Is_Indefinite_Subtype (Type_Id)
501 and then Serious_Errors_Detected = Sav_Errs
503 if Is_Class_Wide_Type (Type_Id) then
505 ("initialization required in class-wide allocation", N);
508 ("initialization required in unconstrained allocation", N);
514 if Is_Abstract_Type (Type_Id) then
515 Error_Msg_N ("cannot allocate abstract object", E);
518 if Has_Task (Designated_Type (Acc_Type)) then
519 Check_Restriction (No_Tasking, N);
520 Check_Restriction (Max_Tasks, N);
521 Check_Restriction (No_Task_Allocators, N);
524 -- If the No_Streams restriction is set, check that the type of the
525 -- object is not, and does not contain, any subtype derived from
526 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
527 -- Has_Stream just for efficiency reasons. There is no point in
528 -- spending time on a Has_Stream check if the restriction is not set.
530 if Restrictions.Set (No_Streams) then
531 if Has_Stream (Designated_Type (Acc_Type)) then
532 Check_Restriction (No_Streams, N);
536 Set_Etype (N, Acc_Type);
538 if not Is_Library_Level_Entity (Acc_Type) then
539 Check_Restriction (No_Local_Allocators, N);
542 if Serious_Errors_Detected > Sav_Errs then
543 Set_Error_Posted (N);
544 Set_Etype (N, Any_Type);
546 end Analyze_Allocator;
548 ---------------------------
549 -- Analyze_Arithmetic_Op --
550 ---------------------------
552 procedure Analyze_Arithmetic_Op (N : Node_Id) is
553 L : constant Node_Id := Left_Opnd (N);
554 R : constant Node_Id := Right_Opnd (N);
558 Candidate_Type := Empty;
559 Analyze_Expression (L);
560 Analyze_Expression (R);
562 -- If the entity is already set, the node is the instantiation of
563 -- a generic node with a non-local reference, or was manufactured
564 -- by a call to Make_Op_xxx. In either case the entity is known to
565 -- be valid, and we do not need to collect interpretations, instead
566 -- we just get the single possible interpretation.
570 if Present (Op_Id) then
571 if Ekind (Op_Id) = E_Operator then
573 if (Nkind (N) = N_Op_Divide or else
574 Nkind (N) = N_Op_Mod or else
575 Nkind (N) = N_Op_Multiply or else
576 Nkind (N) = N_Op_Rem)
577 and then Treat_Fixed_As_Integer (N)
581 Set_Etype (N, Any_Type);
582 Find_Arithmetic_Types (L, R, Op_Id, N);
586 Set_Etype (N, Any_Type);
587 Add_One_Interp (N, Op_Id, Etype (Op_Id));
590 -- Entity is not already set, so we do need to collect interpretations
593 Op_Id := Get_Name_Entity_Id (Chars (N));
594 Set_Etype (N, Any_Type);
596 while Present (Op_Id) loop
597 if Ekind (Op_Id) = E_Operator
598 and then Present (Next_Entity (First_Entity (Op_Id)))
600 Find_Arithmetic_Types (L, R, Op_Id, N);
602 -- The following may seem superfluous, because an operator cannot
603 -- be generic, but this ignores the cleverness of the author of
606 elsif Is_Overloadable (Op_Id) then
607 Analyze_User_Defined_Binary_Op (N, Op_Id);
610 Op_Id := Homonym (Op_Id);
615 end Analyze_Arithmetic_Op;
621 -- Function, procedure, and entry calls are checked here. The Name in
622 -- the call may be overloaded. The actuals have been analyzed and may
623 -- themselves be overloaded. On exit from this procedure, the node N
624 -- may have zero, one or more interpretations. In the first case an
625 -- error message is produced. In the last case, the node is flagged
626 -- as overloaded and the interpretations are collected in All_Interp.
628 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
629 -- the type-checking is similar to that of other calls.
631 procedure Analyze_Call (N : Node_Id) is
632 Actuals : constant List_Id := Parameter_Associations (N);
633 Nam : Node_Id := Name (N);
637 Success : Boolean := False;
639 function Name_Denotes_Function return Boolean;
640 -- If the type of the name is an access to subprogram, this may be
641 -- the type of a name, or the return type of the function being called.
642 -- If the name is not an entity then it can denote a protected function.
643 -- Until we distinguish Etype from Return_Type, we must use this
644 -- routine to resolve the meaning of the name in the call.
646 ---------------------------
647 -- Name_Denotes_Function --
648 ---------------------------
650 function Name_Denotes_Function return Boolean is
652 if Is_Entity_Name (Nam) then
653 return Ekind (Entity (Nam)) = E_Function;
655 elsif Nkind (Nam) = N_Selected_Component then
656 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
661 end Name_Denotes_Function;
663 -- Start of processing for Analyze_Call
666 -- Initialize the type of the result of the call to the error type,
667 -- which will be reset if the type is successfully resolved.
669 Set_Etype (N, Any_Type);
671 if not Is_Overloaded (Nam) then
673 -- Only one interpretation to check
675 if Ekind (Etype (Nam)) = E_Subprogram_Type then
676 Nam_Ent := Etype (Nam);
678 -- If the prefix is an access_to_subprogram, this may be an indirect
679 -- call. This is the case if the name in the call is not an entity
680 -- name, or if it is a function name in the context of a procedure
681 -- call. In this latter case, we have a call to a parameterless
682 -- function that returns a pointer_to_procedure which is the entity
685 elsif Is_Access_Type (Etype (Nam))
686 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
688 (not Name_Denotes_Function
689 or else Nkind (N) = N_Procedure_Call_Statement)
691 Nam_Ent := Designated_Type (Etype (Nam));
692 Insert_Explicit_Dereference (Nam);
694 -- Selected component case. Simple entry or protected operation,
695 -- where the entry name is given by the selector name.
697 elsif Nkind (Nam) = N_Selected_Component then
698 Nam_Ent := Entity (Selector_Name (Nam));
700 if Ekind (Nam_Ent) /= E_Entry
701 and then Ekind (Nam_Ent) /= E_Entry_Family
702 and then Ekind (Nam_Ent) /= E_Function
703 and then Ekind (Nam_Ent) /= E_Procedure
705 Error_Msg_N ("name in call is not a callable entity", Nam);
706 Set_Etype (N, Any_Type);
710 -- If the name is an Indexed component, it can be a call to a member
711 -- of an entry family. The prefix must be a selected component whose
712 -- selector is the entry. Analyze_Procedure_Call normalizes several
713 -- kinds of call into this form.
715 elsif Nkind (Nam) = N_Indexed_Component then
717 if Nkind (Prefix (Nam)) = N_Selected_Component then
718 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
720 Error_Msg_N ("name in call is not a callable entity", Nam);
721 Set_Etype (N, Any_Type);
725 elsif not Is_Entity_Name (Nam) then
726 Error_Msg_N ("name in call is not a callable entity", Nam);
727 Set_Etype (N, Any_Type);
731 Nam_Ent := Entity (Nam);
733 -- If no interpretations, give error message
735 if not Is_Overloadable (Nam_Ent) then
737 L : constant Boolean := Is_List_Member (N);
738 K : constant Node_Kind := Nkind (Parent (N));
741 -- If the node is in a list whose parent is not an
742 -- expression then it must be an attempted procedure call.
744 if L and then K not in N_Subexpr then
745 if Ekind (Entity (Nam)) = E_Generic_Procedure then
747 ("must instantiate generic procedure& before call",
751 ("procedure or entry name expected", Nam);
754 -- Check for tasking cases where only an entry call will do
757 and then (K = N_Entry_Call_Alternative
758 or else K = N_Triggering_Alternative)
760 Error_Msg_N ("entry name expected", Nam);
762 -- Otherwise give general error message
765 Error_Msg_N ("invalid prefix in call", Nam);
773 Analyze_One_Call (N, Nam_Ent, True, Success);
775 -- If this is an indirect call, the return type of the access_to
776 -- subprogram may be an incomplete type. At the point of the call,
777 -- use the full type if available, and at the same time update
778 -- the return type of the access_to_subprogram.
781 and then Nkind (Nam) = N_Explicit_Dereference
782 and then Ekind (Etype (N)) = E_Incomplete_Type
783 and then Present (Full_View (Etype (N)))
785 Set_Etype (N, Full_View (Etype (N)));
786 Set_Etype (Nam_Ent, Etype (N));
790 -- An overloaded selected component must denote overloaded
791 -- operations of a concurrent type. The interpretations are
792 -- attached to the simple name of those operations.
794 if Nkind (Nam) = N_Selected_Component then
795 Nam := Selector_Name (Nam);
798 Get_First_Interp (Nam, X, It);
800 while Present (It.Nam) loop
803 -- Name may be call that returns an access to subprogram, or more
804 -- generally an overloaded expression one of whose interpretations
805 -- yields an access to subprogram. If the name is an entity, we
806 -- do not dereference, because the node is a call that returns
807 -- the access type: note difference between f(x), where the call
808 -- may return an access subprogram type, and f(x)(y), where the
809 -- type returned by the call to f is implicitly dereferenced to
810 -- analyze the outer call.
812 if Is_Access_Type (Nam_Ent) then
813 Nam_Ent := Designated_Type (Nam_Ent);
815 elsif Is_Access_Type (Etype (Nam_Ent))
816 and then not Is_Entity_Name (Nam)
817 and then Ekind (Designated_Type (Etype (Nam_Ent)))
820 Nam_Ent := Designated_Type (Etype (Nam_Ent));
823 Analyze_One_Call (N, Nam_Ent, False, Success);
825 -- If the interpretation succeeds, mark the proper type of the
826 -- prefix (any valid candidate will do). If not, remove the
827 -- candidate interpretation. This only needs to be done for
828 -- overloaded protected operations, for other entities disambi-
829 -- guation is done directly in Resolve.
832 Set_Etype (Nam, It.Typ);
834 elsif Nkind (Name (N)) = N_Selected_Component
835 or else Nkind (Name (N)) = N_Function_Call
840 Get_Next_Interp (X, It);
843 -- If the name is the result of a function call, it can only
844 -- be a call to a function returning an access to subprogram.
845 -- Insert explicit dereference.
847 if Nkind (Nam) = N_Function_Call then
848 Insert_Explicit_Dereference (Nam);
851 if Etype (N) = Any_Type then
853 -- None of the interpretations is compatible with the actuals
855 Diagnose_Call (N, Nam);
857 -- Special checks for uninstantiated put routines
859 if Nkind (N) = N_Procedure_Call_Statement
860 and then Is_Entity_Name (Nam)
861 and then Chars (Nam) = Name_Put
862 and then List_Length (Actuals) = 1
865 Arg : constant Node_Id := First (Actuals);
869 if Nkind (Arg) = N_Parameter_Association then
870 Typ := Etype (Explicit_Actual_Parameter (Arg));
875 if Is_Signed_Integer_Type (Typ) then
877 ("possible missing instantiation of " &
878 "'Text_'I'O.'Integer_'I'O!", Nam);
880 elsif Is_Modular_Integer_Type (Typ) then
882 ("possible missing instantiation of " &
883 "'Text_'I'O.'Modular_'I'O!", Nam);
885 elsif Is_Floating_Point_Type (Typ) then
887 ("possible missing instantiation of " &
888 "'Text_'I'O.'Float_'I'O!", Nam);
890 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
892 ("possible missing instantiation of " &
893 "'Text_'I'O.'Fixed_'I'O!", Nam);
895 elsif Is_Decimal_Fixed_Point_Type (Typ) then
897 ("possible missing instantiation of " &
898 "'Text_'I'O.'Decimal_'I'O!", Nam);
900 elsif Is_Enumeration_Type (Typ) then
902 ("possible missing instantiation of " &
903 "'Text_'I'O.'Enumeration_'I'O!", Nam);
908 elsif not Is_Overloaded (N)
909 and then Is_Entity_Name (Nam)
911 -- Resolution yields a single interpretation. Verify that the
912 -- reference has capitalization consistent with the declaration.
914 Set_Entity_With_Style_Check (Nam, Entity (Nam));
915 Generate_Reference (Entity (Nam), Nam);
917 Set_Etype (Nam, Etype (Entity (Nam)));
919 Remove_Abstract_Operations (N);
925 -- Check for not-yet-implemented cases of AI-318. We only need to check
926 -- for inherently limited types, because other limited types will be
927 -- returned by copy, which works just fine.
929 if Ada_Version >= Ada_05
930 and then not Debug_Flag_Dot_L
931 and then Is_Inherently_Limited_Type (Etype (N))
932 and then (Nkind (Parent (N)) = N_Selected_Component
933 or else Nkind (Parent (N)) = N_Indexed_Component
934 or else Nkind (Parent (N)) = N_Slice
935 or else Nkind (Parent (N)) = N_Attribute_Reference)
937 Error_Msg_N ("(Ada 2005) limited function call in this context" &
938 " is not yet implemented", N);
942 ---------------------------
943 -- Analyze_Comparison_Op --
944 ---------------------------
946 procedure Analyze_Comparison_Op (N : Node_Id) is
947 L : constant Node_Id := Left_Opnd (N);
948 R : constant Node_Id := Right_Opnd (N);
949 Op_Id : Entity_Id := Entity (N);
952 Set_Etype (N, Any_Type);
953 Candidate_Type := Empty;
955 Analyze_Expression (L);
956 Analyze_Expression (R);
958 if Present (Op_Id) then
959 if Ekind (Op_Id) = E_Operator then
960 Find_Comparison_Types (L, R, Op_Id, N);
962 Add_One_Interp (N, Op_Id, Etype (Op_Id));
965 if Is_Overloaded (L) then
966 Set_Etype (L, Intersect_Types (L, R));
970 Op_Id := Get_Name_Entity_Id (Chars (N));
971 while Present (Op_Id) loop
972 if Ekind (Op_Id) = E_Operator then
973 Find_Comparison_Types (L, R, Op_Id, N);
975 Analyze_User_Defined_Binary_Op (N, Op_Id);
978 Op_Id := Homonym (Op_Id);
983 end Analyze_Comparison_Op;
985 ---------------------------
986 -- Analyze_Concatenation --
987 ---------------------------
989 -- If the only one-dimensional array type in scope is String,
990 -- this is the resulting type of the operation. Otherwise there
991 -- will be a concatenation operation defined for each user-defined
992 -- one-dimensional array.
994 procedure Analyze_Concatenation (N : Node_Id) is
995 L : constant Node_Id := Left_Opnd (N);
996 R : constant Node_Id := Right_Opnd (N);
997 Op_Id : Entity_Id := Entity (N);
1002 Set_Etype (N, Any_Type);
1003 Candidate_Type := Empty;
1005 Analyze_Expression (L);
1006 Analyze_Expression (R);
1008 -- If the entity is present, the node appears in an instance,
1009 -- and denotes a predefined concatenation operation. The resulting
1010 -- type is obtained from the arguments when possible. If the arguments
1011 -- are aggregates, the array type and the concatenation type must be
1014 if Present (Op_Id) then
1015 if Ekind (Op_Id) = E_Operator then
1017 LT := Base_Type (Etype (L));
1018 RT := Base_Type (Etype (R));
1020 if Is_Array_Type (LT)
1021 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1023 Add_One_Interp (N, Op_Id, LT);
1025 elsif Is_Array_Type (RT)
1026 and then LT = Base_Type (Component_Type (RT))
1028 Add_One_Interp (N, Op_Id, RT);
1030 -- If one operand is a string type or a user-defined array type,
1031 -- and the other is a literal, result is of the specific type.
1034 (Root_Type (LT) = Standard_String
1035 or else Scope (LT) /= Standard_Standard)
1036 and then Etype (R) = Any_String
1038 Add_One_Interp (N, Op_Id, LT);
1041 (Root_Type (RT) = Standard_String
1042 or else Scope (RT) /= Standard_Standard)
1043 and then Etype (L) = Any_String
1045 Add_One_Interp (N, Op_Id, RT);
1047 elsif not Is_Generic_Type (Etype (Op_Id)) then
1048 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1051 -- Type and its operations must be visible
1053 Set_Entity (N, Empty);
1054 Analyze_Concatenation (N);
1058 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1062 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1063 while Present (Op_Id) loop
1064 if Ekind (Op_Id) = E_Operator then
1066 -- Do not consider operators declared in dead code, they can
1067 -- not be part of the resolution.
1069 if Is_Eliminated (Op_Id) then
1072 Find_Concatenation_Types (L, R, Op_Id, N);
1076 Analyze_User_Defined_Binary_Op (N, Op_Id);
1079 Op_Id := Homonym (Op_Id);
1084 end Analyze_Concatenation;
1086 ------------------------------------
1087 -- Analyze_Conditional_Expression --
1088 ------------------------------------
1090 procedure Analyze_Conditional_Expression (N : Node_Id) is
1091 Condition : constant Node_Id := First (Expressions (N));
1092 Then_Expr : constant Node_Id := Next (Condition);
1093 Else_Expr : constant Node_Id := Next (Then_Expr);
1095 Analyze_Expression (Condition);
1096 Analyze_Expression (Then_Expr);
1097 Analyze_Expression (Else_Expr);
1098 Set_Etype (N, Etype (Then_Expr));
1099 end Analyze_Conditional_Expression;
1101 -------------------------
1102 -- Analyze_Equality_Op --
1103 -------------------------
1105 procedure Analyze_Equality_Op (N : Node_Id) is
1106 Loc : constant Source_Ptr := Sloc (N);
1107 L : constant Node_Id := Left_Opnd (N);
1108 R : constant Node_Id := Right_Opnd (N);
1112 Set_Etype (N, Any_Type);
1113 Candidate_Type := Empty;
1115 Analyze_Expression (L);
1116 Analyze_Expression (R);
1118 -- If the entity is set, the node is a generic instance with a non-local
1119 -- reference to the predefined operator or to a user-defined function.
1120 -- It can also be an inequality that is expanded into the negation of a
1121 -- call to a user-defined equality operator.
1123 -- For the predefined case, the result is Boolean, regardless of the
1124 -- type of the operands. The operands may even be limited, if they are
1125 -- generic actuals. If they are overloaded, label the left argument with
1126 -- the common type that must be present, or with the type of the formal
1127 -- of the user-defined function.
1129 if Present (Entity (N)) then
1130 Op_Id := Entity (N);
1132 if Ekind (Op_Id) = E_Operator then
1133 Add_One_Interp (N, Op_Id, Standard_Boolean);
1135 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1138 if Is_Overloaded (L) then
1139 if Ekind (Op_Id) = E_Operator then
1140 Set_Etype (L, Intersect_Types (L, R));
1142 Set_Etype (L, Etype (First_Formal (Op_Id)));
1147 Op_Id := Get_Name_Entity_Id (Chars (N));
1148 while Present (Op_Id) loop
1149 if Ekind (Op_Id) = E_Operator then
1150 Find_Equality_Types (L, R, Op_Id, N);
1152 Analyze_User_Defined_Binary_Op (N, Op_Id);
1155 Op_Id := Homonym (Op_Id);
1159 -- If there was no match, and the operator is inequality, this may
1160 -- be a case where inequality has not been made explicit, as for
1161 -- tagged types. Analyze the node as the negation of an equality
1162 -- operation. This cannot be done earlier, because before analysis
1163 -- we cannot rule out the presence of an explicit inequality.
1165 if Etype (N) = Any_Type
1166 and then Nkind (N) = N_Op_Ne
1168 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1169 while Present (Op_Id) loop
1170 if Ekind (Op_Id) = E_Operator then
1171 Find_Equality_Types (L, R, Op_Id, N);
1173 Analyze_User_Defined_Binary_Op (N, Op_Id);
1176 Op_Id := Homonym (Op_Id);
1179 if Etype (N) /= Any_Type then
1180 Op_Id := Entity (N);
1186 Left_Opnd => Left_Opnd (N),
1187 Right_Opnd => Right_Opnd (N))));
1189 Set_Entity (Right_Opnd (N), Op_Id);
1195 end Analyze_Equality_Op;
1197 ----------------------------------
1198 -- Analyze_Explicit_Dereference --
1199 ----------------------------------
1201 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1202 Loc : constant Source_Ptr := Sloc (N);
1203 P : constant Node_Id := Prefix (N);
1209 function Is_Function_Type return Boolean;
1210 -- Check whether node may be interpreted as an implicit function call
1212 ----------------------
1213 -- Is_Function_Type --
1214 ----------------------
1216 function Is_Function_Type return Boolean is
1221 if not Is_Overloaded (N) then
1222 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1223 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1226 Get_First_Interp (N, I, It);
1227 while Present (It.Nam) loop
1228 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1229 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1234 Get_Next_Interp (I, It);
1239 end Is_Function_Type;
1241 -- Start of processing for Analyze_Explicit_Dereference
1245 Set_Etype (N, Any_Type);
1247 -- Test for remote access to subprogram type, and if so return
1248 -- after rewriting the original tree.
1250 if Remote_AST_E_Dereference (P) then
1254 -- Normal processing for other than remote access to subprogram type
1256 if not Is_Overloaded (P) then
1257 if Is_Access_Type (Etype (P)) then
1259 -- Set the Etype. We need to go thru Is_For_Access_Subtypes to
1260 -- avoid other problems caused by the Private_Subtype and it is
1261 -- safe to go to the Base_Type because this is the same as
1262 -- converting the access value to its Base_Type.
1265 DT : Entity_Id := Designated_Type (Etype (P));
1268 if Ekind (DT) = E_Private_Subtype
1269 and then Is_For_Access_Subtype (DT)
1271 DT := Base_Type (DT);
1274 -- An explicit dereference is a legal occurrence of an
1275 -- incomplete type imported through a limited_with clause,
1276 -- if the full view is visible.
1278 if From_With_Type (DT)
1279 and then not From_With_Type (Scope (DT))
1281 (Is_Immediately_Visible (Scope (DT))
1283 (Is_Child_Unit (Scope (DT))
1284 and then Is_Visible_Child_Unit (Scope (DT))))
1286 Set_Etype (N, Available_View (DT));
1293 elsif Etype (P) /= Any_Type then
1294 Error_Msg_N ("prefix of dereference must be an access type", N);
1299 Get_First_Interp (P, I, It);
1300 while Present (It.Nam) loop
1303 if Is_Access_Type (T) then
1304 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1307 Get_Next_Interp (I, It);
1310 -- Error if no interpretation of the prefix has an access type
1312 if Etype (N) = Any_Type then
1314 ("access type required in prefix of explicit dereference", P);
1315 Set_Etype (N, Any_Type);
1321 and then Nkind (Parent (N)) /= N_Indexed_Component
1323 and then (Nkind (Parent (N)) /= N_Function_Call
1324 or else N /= Name (Parent (N)))
1326 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1327 or else N /= Name (Parent (N)))
1329 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1330 and then (Nkind (Parent (N)) /= N_Attribute_Reference
1332 (Attribute_Name (Parent (N)) /= Name_Address
1334 Attribute_Name (Parent (N)) /= Name_Access))
1336 -- Name is a function call with no actuals, in a context that
1337 -- requires deproceduring (including as an actual in an enclosing
1338 -- function or procedure call). There are some pathological cases
1339 -- where the prefix might include functions that return access to
1340 -- subprograms and others that return a regular type. Disambiguation
1341 -- of those has to take place in Resolve.
1342 -- See e.g. 7117-014 and E317-001.
1345 Make_Function_Call (Loc,
1346 Name => Make_Explicit_Dereference (Loc, P),
1347 Parameter_Associations => New_List);
1349 -- If the prefix is overloaded, remove operations that have formals,
1350 -- we know that this is a parameterless call.
1352 if Is_Overloaded (P) then
1353 Get_First_Interp (P, I, It);
1354 while Present (It.Nam) loop
1357 if No (First_Formal (Base_Type (Designated_Type (T)))) then
1363 Get_Next_Interp (I, It);
1370 elsif not Is_Function_Type
1371 and then Is_Overloaded (N)
1373 -- The prefix may include access to subprograms and other access
1374 -- types. If the context selects the interpretation that is a call,
1375 -- we cannot rewrite the node yet, but we include the result of
1376 -- the call interpretation.
1378 Get_First_Interp (N, I, It);
1379 while Present (It.Nam) loop
1380 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
1381 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
1383 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
1386 Get_Next_Interp (I, It);
1390 -- A value of remote access-to-class-wide must not be dereferenced
1393 Validate_Remote_Access_To_Class_Wide_Type (N);
1394 end Analyze_Explicit_Dereference;
1396 ------------------------
1397 -- Analyze_Expression --
1398 ------------------------
1400 procedure Analyze_Expression (N : Node_Id) is
1403 Check_Parameterless_Call (N);
1404 end Analyze_Expression;
1406 ------------------------------------
1407 -- Analyze_Indexed_Component_Form --
1408 ------------------------------------
1410 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
1411 P : constant Node_Id := Prefix (N);
1412 Exprs : constant List_Id := Expressions (N);
1418 procedure Process_Function_Call;
1419 -- Prefix in indexed component form is an overloadable entity,
1420 -- so the node is a function call. Reformat it as such.
1422 procedure Process_Indexed_Component;
1423 -- Prefix in indexed component form is actually an indexed component.
1424 -- This routine processes it, knowing that the prefix is already
1427 procedure Process_Indexed_Component_Or_Slice;
1428 -- An indexed component with a single index may designate a slice if
1429 -- the index is a subtype mark. This routine disambiguates these two
1430 -- cases by resolving the prefix to see if it is a subtype mark.
1432 procedure Process_Overloaded_Indexed_Component;
1433 -- If the prefix of an indexed component is overloaded, the proper
1434 -- interpretation is selected by the index types and the context.
1436 ---------------------------
1437 -- Process_Function_Call --
1438 ---------------------------
1440 procedure Process_Function_Call is
1444 Change_Node (N, N_Function_Call);
1446 Set_Parameter_Associations (N, Exprs);
1448 -- Analyze actuals prior to analyzing the call itself.
1450 Actual := First (Parameter_Associations (N));
1451 while Present (Actual) loop
1453 Check_Parameterless_Call (Actual);
1455 -- Move to next actual. Note that we use Next, not Next_Actual
1456 -- here. The reason for this is a bit subtle. If a function call
1457 -- includes named associations, the parser recognizes the node as
1458 -- a call, and it is analyzed as such. If all associations are
1459 -- positional, the parser builds an indexed_component node, and
1460 -- it is only after analysis of the prefix that the construct
1461 -- is recognized as a call, in which case Process_Function_Call
1462 -- rewrites the node and analyzes the actuals. If the list of
1463 -- actuals is malformed, the parser may leave the node as an
1464 -- indexed component (despite the presence of named associations).
1465 -- The iterator Next_Actual is equivalent to Next if the list is
1466 -- positional, but follows the normalized chain of actuals when
1467 -- named associations are present. In this case normalization has
1468 -- not taken place, and actuals remain unanalyzed, which leads to
1469 -- subsequent crashes or loops if there is an attempt to continue
1470 -- analysis of the program.
1476 end Process_Function_Call;
1478 -------------------------------
1479 -- Process_Indexed_Component --
1480 -------------------------------
1482 procedure Process_Indexed_Component is
1484 Array_Type : Entity_Id;
1486 Pent : Entity_Id := Empty;
1489 Exp := First (Exprs);
1491 if Is_Overloaded (P) then
1492 Process_Overloaded_Indexed_Component;
1495 Array_Type := Etype (P);
1497 if Is_Entity_Name (P) then
1499 elsif Nkind (P) = N_Selected_Component
1500 and then Is_Entity_Name (Selector_Name (P))
1502 Pent := Entity (Selector_Name (P));
1505 -- Prefix must be appropriate for an array type, taking into
1506 -- account a possible implicit dereference.
1508 if Is_Access_Type (Array_Type) then
1509 Array_Type := Designated_Type (Array_Type);
1510 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1511 Process_Implicit_Dereference_Prefix (Pent, P);
1514 if Is_Array_Type (Array_Type) then
1517 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
1519 Set_Etype (N, Any_Type);
1521 if not Has_Compatible_Type
1522 (Exp, Entry_Index_Type (Pent))
1524 Error_Msg_N ("invalid index type in entry name", N);
1526 elsif Present (Next (Exp)) then
1527 Error_Msg_N ("too many subscripts in entry reference", N);
1530 Set_Etype (N, Etype (P));
1535 elsif Is_Record_Type (Array_Type)
1536 and then Remote_AST_I_Dereference (P)
1540 elsif Array_Type = Any_Type then
1541 Set_Etype (N, Any_Type);
1544 -- Here we definitely have a bad indexing
1547 if Nkind (Parent (N)) = N_Requeue_Statement
1548 and then Present (Pent) and then Ekind (Pent) = E_Entry
1551 ("REQUEUE does not permit parameters", First (Exprs));
1553 elsif Is_Entity_Name (P)
1554 and then Etype (P) = Standard_Void_Type
1556 Error_Msg_NE ("incorrect use of&", P, Entity (P));
1559 Error_Msg_N ("array type required in indexed component", P);
1562 Set_Etype (N, Any_Type);
1566 Index := First_Index (Array_Type);
1567 while Present (Index) and then Present (Exp) loop
1568 if not Has_Compatible_Type (Exp, Etype (Index)) then
1569 Wrong_Type (Exp, Etype (Index));
1570 Set_Etype (N, Any_Type);
1578 Set_Etype (N, Component_Type (Array_Type));
1580 if Present (Index) then
1582 ("too few subscripts in array reference", First (Exprs));
1584 elsif Present (Exp) then
1585 Error_Msg_N ("too many subscripts in array reference", Exp);
1588 end Process_Indexed_Component;
1590 ----------------------------------------
1591 -- Process_Indexed_Component_Or_Slice --
1592 ----------------------------------------
1594 procedure Process_Indexed_Component_Or_Slice is
1596 Exp := First (Exprs);
1597 while Present (Exp) loop
1598 Analyze_Expression (Exp);
1602 Exp := First (Exprs);
1604 -- If one index is present, and it is a subtype name, then the
1605 -- node denotes a slice (note that the case of an explicit range
1606 -- for a slice was already built as an N_Slice node in the first
1607 -- place, so that case is not handled here).
1609 -- We use a replace rather than a rewrite here because this is one
1610 -- of the cases in which the tree built by the parser is plain wrong.
1613 and then Is_Entity_Name (Exp)
1614 and then Is_Type (Entity (Exp))
1617 Make_Slice (Sloc (N),
1619 Discrete_Range => New_Copy (Exp)));
1622 -- Otherwise (more than one index present, or single index is not
1623 -- a subtype name), then we have the indexed component case.
1626 Process_Indexed_Component;
1628 end Process_Indexed_Component_Or_Slice;
1630 ------------------------------------------
1631 -- Process_Overloaded_Indexed_Component --
1632 ------------------------------------------
1634 procedure Process_Overloaded_Indexed_Component is
1643 Set_Etype (N, Any_Type);
1645 Get_First_Interp (P, I, It);
1646 while Present (It.Nam) loop
1649 if Is_Access_Type (Typ) then
1650 Typ := Designated_Type (Typ);
1651 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1654 if Is_Array_Type (Typ) then
1656 -- Got a candidate: verify that index types are compatible
1658 Index := First_Index (Typ);
1660 Exp := First (Exprs);
1661 while Present (Index) and then Present (Exp) loop
1662 if Has_Compatible_Type (Exp, Etype (Index)) then
1674 if Found and then No (Index) and then No (Exp) then
1676 Etype (Component_Type (Typ)),
1677 Etype (Component_Type (Typ)));
1681 Get_Next_Interp (I, It);
1684 if Etype (N) = Any_Type then
1685 Error_Msg_N ("no legal interpetation for indexed component", N);
1686 Set_Is_Overloaded (N, False);
1690 end Process_Overloaded_Indexed_Component;
1692 -- Start of processing for Analyze_Indexed_Component_Form
1695 -- Get name of array, function or type
1698 if Nkind (N) = N_Function_Call
1699 or else Nkind (N) = N_Procedure_Call_Statement
1701 -- If P is an explicit dereference whose prefix is of a
1702 -- remote access-to-subprogram type, then N has already
1703 -- been rewritten as a subprogram call and analyzed.
1708 pragma Assert (Nkind (N) = N_Indexed_Component);
1710 P_T := Base_Type (Etype (P));
1712 if Is_Entity_Name (P)
1713 or else Nkind (P) = N_Operator_Symbol
1717 if Is_Type (U_N) then
1719 -- Reformat node as a type conversion
1721 E := Remove_Head (Exprs);
1723 if Present (First (Exprs)) then
1725 ("argument of type conversion must be single expression", N);
1728 Change_Node (N, N_Type_Conversion);
1729 Set_Subtype_Mark (N, P);
1731 Set_Expression (N, E);
1733 -- After changing the node, call for the specific Analysis
1734 -- routine directly, to avoid a double call to the expander.
1736 Analyze_Type_Conversion (N);
1740 if Is_Overloadable (U_N) then
1741 Process_Function_Call;
1743 elsif Ekind (Etype (P)) = E_Subprogram_Type
1744 or else (Is_Access_Type (Etype (P))
1746 Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type)
1748 -- Call to access_to-subprogram with possible implicit dereference
1750 Process_Function_Call;
1752 elsif Is_Generic_Subprogram (U_N) then
1754 -- A common beginner's (or C++ templates fan) error
1756 Error_Msg_N ("generic subprogram cannot be called", N);
1757 Set_Etype (N, Any_Type);
1761 Process_Indexed_Component_Or_Slice;
1764 -- If not an entity name, prefix is an expression that may denote
1765 -- an array or an access-to-subprogram.
1768 if Ekind (P_T) = E_Subprogram_Type
1769 or else (Is_Access_Type (P_T)
1771 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
1773 Process_Function_Call;
1775 elsif Nkind (P) = N_Selected_Component
1776 and then Is_Overloadable (Entity (Selector_Name (P)))
1778 Process_Function_Call;
1781 -- Indexed component, slice, or a call to a member of a family
1782 -- entry, which will be converted to an entry call later.
1784 Process_Indexed_Component_Or_Slice;
1787 end Analyze_Indexed_Component_Form;
1789 ------------------------
1790 -- Analyze_Logical_Op --
1791 ------------------------
1793 procedure Analyze_Logical_Op (N : Node_Id) is
1794 L : constant Node_Id := Left_Opnd (N);
1795 R : constant Node_Id := Right_Opnd (N);
1796 Op_Id : Entity_Id := Entity (N);
1799 Set_Etype (N, Any_Type);
1800 Candidate_Type := Empty;
1802 Analyze_Expression (L);
1803 Analyze_Expression (R);
1805 if Present (Op_Id) then
1807 if Ekind (Op_Id) = E_Operator then
1808 Find_Boolean_Types (L, R, Op_Id, N);
1810 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1814 Op_Id := Get_Name_Entity_Id (Chars (N));
1815 while Present (Op_Id) loop
1816 if Ekind (Op_Id) = E_Operator then
1817 Find_Boolean_Types (L, R, Op_Id, N);
1819 Analyze_User_Defined_Binary_Op (N, Op_Id);
1822 Op_Id := Homonym (Op_Id);
1827 end Analyze_Logical_Op;
1829 ---------------------------
1830 -- Analyze_Membership_Op --
1831 ---------------------------
1833 procedure Analyze_Membership_Op (N : Node_Id) is
1834 L : constant Node_Id := Left_Opnd (N);
1835 R : constant Node_Id := Right_Opnd (N);
1837 Index : Interp_Index;
1839 Found : Boolean := False;
1843 procedure Try_One_Interp (T1 : Entity_Id);
1844 -- Routine to try one proposed interpretation. Note that the context
1845 -- of the operation plays no role in resolving the arguments, so that
1846 -- if there is more than one interpretation of the operands that is
1847 -- compatible with a membership test, the operation is ambiguous.
1849 --------------------
1850 -- Try_One_Interp --
1851 --------------------
1853 procedure Try_One_Interp (T1 : Entity_Id) is
1855 if Has_Compatible_Type (R, T1) then
1857 and then Base_Type (T1) /= Base_Type (T_F)
1859 It := Disambiguate (L, I_F, Index, Any_Type);
1861 if It = No_Interp then
1862 Ambiguous_Operands (N);
1863 Set_Etype (L, Any_Type);
1881 -- Start of processing for Analyze_Membership_Op
1884 Analyze_Expression (L);
1886 if Nkind (R) = N_Range
1887 or else (Nkind (R) = N_Attribute_Reference
1888 and then Attribute_Name (R) = Name_Range)
1892 if not Is_Overloaded (L) then
1893 Try_One_Interp (Etype (L));
1896 Get_First_Interp (L, Index, It);
1897 while Present (It.Typ) loop
1898 Try_One_Interp (It.Typ);
1899 Get_Next_Interp (Index, It);
1903 -- If not a range, it can only be a subtype mark, or else there
1904 -- is a more basic error, to be diagnosed in Find_Type.
1909 if Is_Entity_Name (R) then
1910 Check_Fully_Declared (Entity (R), R);
1914 -- Compatibility between expression and subtype mark or range is
1915 -- checked during resolution. The result of the operation is Boolean
1918 Set_Etype (N, Standard_Boolean);
1920 if Comes_From_Source (N)
1921 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
1923 Error_Msg_N ("membership test not applicable to cpp-class types", N);
1925 end Analyze_Membership_Op;
1927 ----------------------
1928 -- Analyze_Negation --
1929 ----------------------
1931 procedure Analyze_Negation (N : Node_Id) is
1932 R : constant Node_Id := Right_Opnd (N);
1933 Op_Id : Entity_Id := Entity (N);
1936 Set_Etype (N, Any_Type);
1937 Candidate_Type := Empty;
1939 Analyze_Expression (R);
1941 if Present (Op_Id) then
1942 if Ekind (Op_Id) = E_Operator then
1943 Find_Negation_Types (R, Op_Id, N);
1945 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1949 Op_Id := Get_Name_Entity_Id (Chars (N));
1950 while Present (Op_Id) loop
1951 if Ekind (Op_Id) = E_Operator then
1952 Find_Negation_Types (R, Op_Id, N);
1954 Analyze_User_Defined_Unary_Op (N, Op_Id);
1957 Op_Id := Homonym (Op_Id);
1962 end Analyze_Negation;
1968 procedure Analyze_Null (N : Node_Id) is
1970 Set_Etype (N, Any_Access);
1973 ----------------------
1974 -- Analyze_One_Call --
1975 ----------------------
1977 procedure Analyze_One_Call
1981 Success : out Boolean;
1982 Skip_First : Boolean := False)
1984 Actuals : constant List_Id := Parameter_Associations (N);
1985 Prev_T : constant Entity_Id := Etype (N);
1986 Must_Skip : constant Boolean := Skip_First
1987 or else Nkind (Original_Node (N)) = N_Selected_Component
1989 (Nkind (Original_Node (N)) = N_Indexed_Component
1990 and then Nkind (Prefix (Original_Node (N)))
1991 = N_Selected_Component);
1992 -- The first formal must be omitted from the match when trying to find
1993 -- a primitive operation that is a possible interpretation, and also
1994 -- after the call has been rewritten, because the corresponding actual
1995 -- is already known to be compatible, and because this may be an
1996 -- indexing of a call with default parameters.
2000 Is_Indexed : Boolean := False;
2001 Subp_Type : constant Entity_Id := Etype (Nam);
2004 procedure Indicate_Name_And_Type;
2005 -- If candidate interpretation matches, indicate name and type of
2006 -- result on call node.
2008 ----------------------------
2009 -- Indicate_Name_And_Type --
2010 ----------------------------
2012 procedure Indicate_Name_And_Type is
2014 Add_One_Interp (N, Nam, Etype (Nam));
2017 -- If the prefix of the call is a name, indicate the entity
2018 -- being called. If it is not a name, it is an expression that
2019 -- denotes an access to subprogram or else an entry or family. In
2020 -- the latter case, the name is a selected component, and the entity
2021 -- being called is noted on the selector.
2023 if not Is_Type (Nam) then
2024 if Is_Entity_Name (Name (N))
2025 or else Nkind (Name (N)) = N_Operator_Symbol
2027 Set_Entity (Name (N), Nam);
2029 elsif Nkind (Name (N)) = N_Selected_Component then
2030 Set_Entity (Selector_Name (Name (N)), Nam);
2034 if Debug_Flag_E and not Report then
2035 Write_Str (" Overloaded call ");
2036 Write_Int (Int (N));
2037 Write_Str (" compatible with ");
2038 Write_Int (Int (Nam));
2041 end Indicate_Name_And_Type;
2043 -- Start of processing for Analyze_One_Call
2048 -- If the subprogram has no formals, or if all the formals have
2049 -- defaults, and the return type is an array type, the node may
2050 -- denote an indexing of the result of a parameterless call.
2051 -- In Ada 2005, the subprogram may have one non-defaulted formal,
2052 -- and the call may have been written in prefix notation, so that
2053 -- the rebuilt parameter list has more than one actual.
2055 if Present (Actuals)
2057 (Needs_No_Actuals (Nam)
2059 (Needs_One_Actual (Nam)
2060 and then Present (Next_Actual (First (Actuals)))))
2062 if Is_Array_Type (Subp_Type) then
2063 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
2065 elsif Is_Access_Type (Subp_Type)
2066 and then Is_Array_Type (Designated_Type (Subp_Type))
2070 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
2072 -- The prefix can also be a parameterless function that returns an
2073 -- access to subprogram. in which case this is an indirect call.
2075 elsif Is_Access_Type (Subp_Type)
2076 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
2078 Is_Indexed := Try_Indirect_Call (N, Nam, Subp_Type);
2083 Normalize_Actuals (N, Nam, (Report and not Is_Indexed), Norm_OK);
2087 -- Mismatch in number or names of parameters
2089 if Debug_Flag_E then
2090 Write_Str (" normalization fails in call ");
2091 Write_Int (Int (N));
2092 Write_Str (" with subprogram ");
2093 Write_Int (Int (Nam));
2097 -- If the context expects a function call, discard any interpretation
2098 -- that is a procedure. If the node is not overloaded, leave as is for
2099 -- better error reporting when type mismatch is found.
2101 elsif Nkind (N) = N_Function_Call
2102 and then Is_Overloaded (Name (N))
2103 and then Ekind (Nam) = E_Procedure
2107 -- Ditto for function calls in a procedure context
2109 elsif Nkind (N) = N_Procedure_Call_Statement
2110 and then Is_Overloaded (Name (N))
2111 and then Etype (Nam) /= Standard_Void_Type
2115 elsif No (Actuals) then
2117 -- If Normalize succeeds, then there are default parameters for
2120 Indicate_Name_And_Type;
2122 elsif Ekind (Nam) = E_Operator then
2123 if Nkind (N) = N_Procedure_Call_Statement then
2127 -- This can occur when the prefix of the call is an operator
2128 -- name or an expanded name whose selector is an operator name.
2130 Analyze_Operator_Call (N, Nam);
2132 if Etype (N) /= Prev_T then
2134 -- There may be a user-defined operator that hides the
2135 -- current interpretation. We must check for this independently
2136 -- of the analysis of the call with the user-defined operation,
2137 -- because the parameter names may be wrong and yet the hiding
2138 -- takes place. Fixes b34014o.
2140 if Is_Overloaded (Name (N)) then
2146 Get_First_Interp (Name (N), I, It);
2147 while Present (It.Nam) loop
2148 if Ekind (It.Nam) /= E_Operator
2149 and then Hides_Op (It.Nam, Nam)
2152 (First_Actual (N), Etype (First_Formal (It.Nam)))
2153 and then (No (Next_Actual (First_Actual (N)))
2154 or else Has_Compatible_Type
2155 (Next_Actual (First_Actual (N)),
2156 Etype (Next_Formal (First_Formal (It.Nam)))))
2158 Set_Etype (N, Prev_T);
2162 Get_Next_Interp (I, It);
2167 -- If operator matches formals, record its name on the call.
2168 -- If the operator is overloaded, Resolve will select the
2169 -- correct one from the list of interpretations. The call
2170 -- node itself carries the first candidate.
2172 Set_Entity (Name (N), Nam);
2175 elsif Report and then Etype (N) = Any_Type then
2176 Error_Msg_N ("incompatible arguments for operator", N);
2180 -- Normalize_Actuals has chained the named associations in the
2181 -- correct order of the formals.
2183 Actual := First_Actual (N);
2184 Formal := First_Formal (Nam);
2186 -- If we are analyzing a call rewritten from object notation,
2187 -- skip first actual, which may be rewritten later as an
2188 -- explicit dereference.
2191 Next_Actual (Actual);
2192 Next_Formal (Formal);
2195 while Present (Actual) and then Present (Formal) loop
2196 if Nkind (Parent (Actual)) /= N_Parameter_Association
2197 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
2199 if Has_Compatible_Type (Actual, Etype (Formal)) then
2200 Next_Actual (Actual);
2201 Next_Formal (Formal);
2204 if Debug_Flag_E then
2205 Write_Str (" type checking fails in call ");
2206 Write_Int (Int (N));
2207 Write_Str (" with formal ");
2208 Write_Int (Int (Formal));
2209 Write_Str (" in subprogram ");
2210 Write_Int (Int (Nam));
2214 if Report and not Is_Indexed then
2216 -- Ada 2005 (AI-251): Complete the error notification
2217 -- to help new Ada 2005 users
2219 if Is_Class_Wide_Type (Etype (Formal))
2220 and then Is_Interface (Etype (Etype (Formal)))
2221 and then not Interface_Present_In_Ancestor
2222 (Typ => Etype (Actual),
2223 Iface => Etype (Etype (Formal)))
2226 ("(Ada 2005) does not implement interface }",
2227 Actual, Etype (Etype (Formal)));
2230 Wrong_Type (Actual, Etype (Formal));
2232 if Nkind (Actual) = N_Op_Eq
2233 and then Nkind (Left_Opnd (Actual)) = N_Identifier
2235 Formal := First_Formal (Nam);
2236 while Present (Formal) loop
2237 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
2239 ("possible misspelling of `='>`!", Actual);
2243 Next_Formal (Formal);
2247 if All_Errors_Mode then
2248 Error_Msg_Sloc := Sloc (Nam);
2250 if Is_Overloadable (Nam)
2251 and then Present (Alias (Nam))
2252 and then not Comes_From_Source (Nam)
2255 (" =='> in call to &#(inherited)!", Actual, Nam);
2257 elsif Ekind (Nam) = E_Subprogram_Type then
2259 Access_To_Subprogram_Typ :
2260 constant Entity_Id :=
2262 (Associated_Node_For_Itype (Nam));
2265 " =='> in call to dereference of &#!",
2266 Actual, Access_To_Subprogram_Typ);
2270 Error_Msg_NE (" =='> in call to &#!", Actual, Nam);
2280 -- Normalize_Actuals has verified that a default value exists
2281 -- for this formal. Current actual names a subsequent formal.
2283 Next_Formal (Formal);
2287 -- On exit, all actuals match
2289 Indicate_Name_And_Type;
2291 end Analyze_One_Call;
2293 ---------------------------
2294 -- Analyze_Operator_Call --
2295 ---------------------------
2297 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
2298 Op_Name : constant Name_Id := Chars (Op_Id);
2299 Act1 : constant Node_Id := First_Actual (N);
2300 Act2 : constant Node_Id := Next_Actual (Act1);
2303 -- Binary operator case
2305 if Present (Act2) then
2307 -- If more than two operands, then not binary operator after all
2309 if Present (Next_Actual (Act2)) then
2312 elsif Op_Name = Name_Op_Add
2313 or else Op_Name = Name_Op_Subtract
2314 or else Op_Name = Name_Op_Multiply
2315 or else Op_Name = Name_Op_Divide
2316 or else Op_Name = Name_Op_Mod
2317 or else Op_Name = Name_Op_Rem
2318 or else Op_Name = Name_Op_Expon
2320 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
2322 elsif Op_Name = Name_Op_And
2323 or else Op_Name = Name_Op_Or
2324 or else Op_Name = Name_Op_Xor
2326 Find_Boolean_Types (Act1, Act2, Op_Id, N);
2328 elsif Op_Name = Name_Op_Lt
2329 or else Op_Name = Name_Op_Le
2330 or else Op_Name = Name_Op_Gt
2331 or else Op_Name = Name_Op_Ge
2333 Find_Comparison_Types (Act1, Act2, Op_Id, N);
2335 elsif Op_Name = Name_Op_Eq
2336 or else Op_Name = Name_Op_Ne
2338 Find_Equality_Types (Act1, Act2, Op_Id, N);
2340 elsif Op_Name = Name_Op_Concat then
2341 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
2343 -- Is this else null correct, or should it be an abort???
2349 -- Unary operator case
2352 if Op_Name = Name_Op_Subtract or else
2353 Op_Name = Name_Op_Add or else
2354 Op_Name = Name_Op_Abs
2356 Find_Unary_Types (Act1, Op_Id, N);
2359 Op_Name = Name_Op_Not
2361 Find_Negation_Types (Act1, Op_Id, N);
2363 -- Is this else null correct, or should it be an abort???
2369 end Analyze_Operator_Call;
2371 -------------------------------------------
2372 -- Analyze_Overloaded_Selected_Component --
2373 -------------------------------------------
2375 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
2376 Nam : constant Node_Id := Prefix (N);
2377 Sel : constant Node_Id := Selector_Name (N);
2384 Set_Etype (Sel, Any_Type);
2386 Get_First_Interp (Nam, I, It);
2387 while Present (It.Typ) loop
2388 if Is_Access_Type (It.Typ) then
2389 T := Designated_Type (It.Typ);
2390 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2395 if Is_Record_Type (T) then
2396 Comp := First_Entity (T);
2397 while Present (Comp) loop
2398 if Chars (Comp) = Chars (Sel)
2399 and then Is_Visible_Component (Comp)
2401 Set_Entity (Sel, Comp);
2402 Set_Etype (Sel, Etype (Comp));
2403 Add_One_Interp (N, Etype (Comp), Etype (Comp));
2405 -- This also specifies a candidate to resolve the name.
2406 -- Further overloading will be resolved from context.
2408 Set_Etype (Nam, It.Typ);
2414 elsif Is_Concurrent_Type (T) then
2415 Comp := First_Entity (T);
2416 while Present (Comp)
2417 and then Comp /= First_Private_Entity (T)
2419 if Chars (Comp) = Chars (Sel) then
2420 if Is_Overloadable (Comp) then
2421 Add_One_Interp (Sel, Comp, Etype (Comp));
2423 Set_Entity_With_Style_Check (Sel, Comp);
2424 Generate_Reference (Comp, Sel);
2427 Set_Etype (Sel, Etype (Comp));
2428 Set_Etype (N, Etype (Comp));
2429 Set_Etype (Nam, It.Typ);
2431 -- For access type case, introduce explicit deference for
2432 -- more uniform treatment of entry calls.
2434 if Is_Access_Type (Etype (Nam)) then
2435 Insert_Explicit_Dereference (Nam);
2437 (Warn_On_Dereference, "?implicit dereference", N);
2444 Set_Is_Overloaded (N, Is_Overloaded (Sel));
2447 Get_Next_Interp (I, It);
2450 if Etype (N) = Any_Type
2451 and then not Try_Object_Operation (N)
2453 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
2454 Set_Entity (Sel, Any_Id);
2455 Set_Etype (Sel, Any_Type);
2457 end Analyze_Overloaded_Selected_Component;
2459 ----------------------------------
2460 -- Analyze_Qualified_Expression --
2461 ----------------------------------
2463 procedure Analyze_Qualified_Expression (N : Node_Id) is
2464 Mark : constant Entity_Id := Subtype_Mark (N);
2468 Set_Etype (N, Any_Type);
2472 if T = Any_Type then
2476 Check_Fully_Declared (T, N);
2477 Analyze_Expression (Expression (N));
2479 end Analyze_Qualified_Expression;
2485 procedure Analyze_Range (N : Node_Id) is
2486 L : constant Node_Id := Low_Bound (N);
2487 H : constant Node_Id := High_Bound (N);
2488 I1, I2 : Interp_Index;
2491 procedure Check_Common_Type (T1, T2 : Entity_Id);
2492 -- Verify the compatibility of two types, and choose the
2493 -- non universal one if the other is universal.
2495 procedure Check_High_Bound (T : Entity_Id);
2496 -- Test one interpretation of the low bound against all those
2497 -- of the high bound.
2499 procedure Check_Universal_Expression (N : Node_Id);
2500 -- In Ada83, reject bounds of a universal range that are not
2501 -- literals or entity names.
2503 -----------------------
2504 -- Check_Common_Type --
2505 -----------------------
2507 procedure Check_Common_Type (T1, T2 : Entity_Id) is
2509 if Covers (T1, T2) or else Covers (T2, T1) then
2510 if T1 = Universal_Integer
2511 or else T1 = Universal_Real
2512 or else T1 = Any_Character
2514 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
2517 Add_One_Interp (N, T1, T1);
2520 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
2523 end Check_Common_Type;
2525 ----------------------
2526 -- Check_High_Bound --
2527 ----------------------
2529 procedure Check_High_Bound (T : Entity_Id) is
2531 if not Is_Overloaded (H) then
2532 Check_Common_Type (T, Etype (H));
2534 Get_First_Interp (H, I2, It2);
2535 while Present (It2.Typ) loop
2536 Check_Common_Type (T, It2.Typ);
2537 Get_Next_Interp (I2, It2);
2540 end Check_High_Bound;
2542 -----------------------------
2543 -- Is_Universal_Expression --
2544 -----------------------------
2546 procedure Check_Universal_Expression (N : Node_Id) is
2548 if Etype (N) = Universal_Integer
2549 and then Nkind (N) /= N_Integer_Literal
2550 and then not Is_Entity_Name (N)
2551 and then Nkind (N) /= N_Attribute_Reference
2553 Error_Msg_N ("illegal bound in discrete range", N);
2555 end Check_Universal_Expression;
2557 -- Start of processing for Analyze_Range
2560 Set_Etype (N, Any_Type);
2561 Analyze_Expression (L);
2562 Analyze_Expression (H);
2564 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
2568 if not Is_Overloaded (L) then
2569 Check_High_Bound (Etype (L));
2571 Get_First_Interp (L, I1, It1);
2572 while Present (It1.Typ) loop
2573 Check_High_Bound (It1.Typ);
2574 Get_Next_Interp (I1, It1);
2578 -- If result is Any_Type, then we did not find a compatible pair
2580 if Etype (N) = Any_Type then
2581 Error_Msg_N ("incompatible types in range ", N);
2585 if Ada_Version = Ada_83
2587 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
2588 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
2590 Check_Universal_Expression (L);
2591 Check_Universal_Expression (H);
2595 -----------------------
2596 -- Analyze_Reference --
2597 -----------------------
2599 procedure Analyze_Reference (N : Node_Id) is
2600 P : constant Node_Id := Prefix (N);
2601 Acc_Type : Entity_Id;
2604 Acc_Type := Create_Itype (E_Allocator_Type, N);
2605 Set_Etype (Acc_Type, Acc_Type);
2606 Init_Size_Align (Acc_Type);
2607 Set_Directly_Designated_Type (Acc_Type, Etype (P));
2608 Set_Etype (N, Acc_Type);
2609 end Analyze_Reference;
2611 --------------------------------
2612 -- Analyze_Selected_Component --
2613 --------------------------------
2615 -- Prefix is a record type or a task or protected type. In the
2616 -- later case, the selector must denote a visible entry.
2618 procedure Analyze_Selected_Component (N : Node_Id) is
2619 Name : constant Node_Id := Prefix (N);
2620 Sel : constant Node_Id := Selector_Name (N);
2622 Entity_List : Entity_Id;
2623 Prefix_Type : Entity_Id;
2624 Pent : Entity_Id := Empty;
2629 -- Start of processing for Analyze_Selected_Component
2632 Set_Etype (N, Any_Type);
2634 if Is_Overloaded (Name) then
2635 Analyze_Overloaded_Selected_Component (N);
2638 elsif Etype (Name) = Any_Type then
2639 Set_Entity (Sel, Any_Id);
2640 Set_Etype (Sel, Any_Type);
2644 Prefix_Type := Etype (Name);
2647 if Is_Access_Type (Prefix_Type) then
2649 -- A RACW object can never be used as prefix of a selected
2650 -- component since that means it is dereferenced without
2651 -- being a controlling operand of a dispatching operation
2654 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
2655 and then Comes_From_Source (N)
2658 ("invalid dereference of a remote access to class-wide value",
2661 -- Normal case of selected component applied to access type
2664 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2666 if Is_Entity_Name (Name) then
2667 Pent := Entity (Name);
2668 elsif Nkind (Name) = N_Selected_Component
2669 and then Is_Entity_Name (Selector_Name (Name))
2671 Pent := Entity (Selector_Name (Name));
2674 Process_Implicit_Dereference_Prefix (Pent, Name);
2677 Prefix_Type := Designated_Type (Prefix_Type);
2681 -- (Ada 2005): if the prefix is the limited view of a type, and
2682 -- the context already includes the full view, use the full view
2683 -- in what follows, either to retrieve a component of to find
2684 -- a primitive operation. If the prefix is an explicit dereference,
2685 -- set the type of the prefix to reflect this transformation.
2687 if Is_Incomplete_Type (Prefix_Type)
2688 and then From_With_Type (Prefix_Type)
2689 and then Present (Non_Limited_View (Prefix_Type))
2691 Prefix_Type := Non_Limited_View (Prefix_Type);
2693 if Nkind (N) = N_Explicit_Dereference then
2694 Set_Etype (Prefix (N), Prefix_Type);
2697 elsif Ekind (Prefix_Type) = E_Class_Wide_Type
2698 and then From_With_Type (Prefix_Type)
2699 and then Present (Non_Limited_View (Etype (Prefix_Type)))
2702 Class_Wide_Type (Non_Limited_View (Etype (Prefix_Type)));
2704 if Nkind (N) = N_Explicit_Dereference then
2705 Set_Etype (Prefix (N), Prefix_Type);
2709 if Ekind (Prefix_Type) = E_Private_Subtype then
2710 Prefix_Type := Base_Type (Prefix_Type);
2713 Entity_List := Prefix_Type;
2715 -- For class-wide types, use the entity list of the root type. This
2716 -- indirection is specially important for private extensions because
2717 -- only the root type get switched (not the class-wide type).
2719 if Is_Class_Wide_Type (Prefix_Type) then
2720 Entity_List := Root_Type (Prefix_Type);
2723 Comp := First_Entity (Entity_List);
2725 -- If the selector has an original discriminant, the node appears in
2726 -- an instance. Replace the discriminant with the corresponding one
2727 -- in the current discriminated type. For nested generics, this must
2728 -- be done transitively, so note the new original discriminant.
2730 if Nkind (Sel) = N_Identifier
2731 and then Present (Original_Discriminant (Sel))
2733 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
2735 -- Mark entity before rewriting, for completeness and because
2736 -- subsequent semantic checks might examine the original node.
2738 Set_Entity (Sel, Comp);
2739 Rewrite (Selector_Name (N),
2740 New_Occurrence_Of (Comp, Sloc (N)));
2741 Set_Original_Discriminant (Selector_Name (N), Comp);
2742 Set_Etype (N, Etype (Comp));
2744 if Is_Access_Type (Etype (Name)) then
2745 Insert_Explicit_Dereference (Name);
2746 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2749 elsif Is_Record_Type (Prefix_Type) then
2751 -- Find component with given name
2753 while Present (Comp) loop
2754 if Chars (Comp) = Chars (Sel)
2755 and then Is_Visible_Component (Comp)
2757 Set_Entity_With_Style_Check (Sel, Comp);
2758 Set_Etype (Sel, Etype (Comp));
2760 if Ekind (Comp) = E_Discriminant then
2761 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
2763 ("cannot reference discriminant of Unchecked_Union",
2767 if Is_Generic_Type (Prefix_Type)
2769 Is_Generic_Type (Root_Type (Prefix_Type))
2771 Set_Original_Discriminant (Sel, Comp);
2775 -- Resolve the prefix early otherwise it is not possible to
2776 -- build the actual subtype of the component: it may need
2777 -- to duplicate this prefix and duplication is only allowed
2778 -- on fully resolved expressions.
2782 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
2783 -- subtypes in a package specification.
2786 -- limited with Pkg;
2788 -- type Acc_Inc is access Pkg.T;
2790 -- N : Natural := X.all.Comp; -- ERROR, limited view
2791 -- end Pkg; -- Comp is not visible
2793 if Nkind (Name) = N_Explicit_Dereference
2794 and then From_With_Type (Etype (Prefix (Name)))
2795 and then not Is_Potentially_Use_Visible (Etype (Name))
2796 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
2797 N_Package_Specification
2800 ("premature usage of incomplete}", Prefix (Name),
2801 Etype (Prefix (Name)));
2804 -- We never need an actual subtype for the case of a selection
2805 -- for a indexed component of a non-packed array, since in
2806 -- this case gigi generates all the checks and can find the
2807 -- necessary bounds information.
2809 -- We also do not need an actual subtype for the case of
2810 -- a first, last, length, or range attribute applied to a
2811 -- non-packed array, since gigi can again get the bounds in
2812 -- these cases (gigi cannot handle the packed case, since it
2813 -- has the bounds of the packed array type, not the original
2814 -- bounds of the type). However, if the prefix is itself a
2815 -- selected component, as in a.b.c (i), gigi may regard a.b.c
2816 -- as a dynamic-sized temporary, so we do generate an actual
2817 -- subtype for this case.
2819 Parent_N := Parent (N);
2821 if not Is_Packed (Etype (Comp))
2823 ((Nkind (Parent_N) = N_Indexed_Component
2824 and then Nkind (Name) /= N_Selected_Component)
2826 (Nkind (Parent_N) = N_Attribute_Reference
2827 and then (Attribute_Name (Parent_N) = Name_First
2829 Attribute_Name (Parent_N) = Name_Last
2831 Attribute_Name (Parent_N) = Name_Length
2833 Attribute_Name (Parent_N) = Name_Range)))
2835 Set_Etype (N, Etype (Comp));
2837 -- If full analysis is not enabled, we do not generate an
2838 -- actual subtype, because in the absence of expansion
2839 -- reference to a formal of a protected type, for example,
2840 -- will not be properly transformed, and will lead to
2841 -- out-of-scope references in gigi.
2843 -- In all other cases, we currently build an actual subtype.
2844 -- It seems likely that many of these cases can be avoided,
2845 -- but right now, the front end makes direct references to the
2846 -- bounds (e.g. in generating a length check), and if we do
2847 -- not make an actual subtype, we end up getting a direct
2848 -- reference to a discriminant, which will not do.
2850 elsif Full_Analysis then
2852 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
2853 Insert_Action (N, Act_Decl);
2855 if No (Act_Decl) then
2856 Set_Etype (N, Etype (Comp));
2859 -- Component type depends on discriminants. Enter the
2860 -- main attributes of the subtype.
2863 Subt : constant Entity_Id :=
2864 Defining_Identifier (Act_Decl);
2867 Set_Etype (Subt, Base_Type (Etype (Comp)));
2868 Set_Ekind (Subt, Ekind (Etype (Comp)));
2869 Set_Etype (N, Subt);
2873 -- If Full_Analysis not enabled, just set the Etype
2876 Set_Etype (N, Etype (Comp));
2882 -- If the prefix is a private extension, check only the visible
2883 -- components of the partial view.
2885 if Ekind (Prefix_Type) = E_Record_Type_With_Private then
2886 exit when Comp = Last_Entity (Prefix_Type);
2892 -- Ada 2005 (AI-252)
2894 if Ada_Version >= Ada_05
2895 and then Is_Tagged_Type (Prefix_Type)
2896 and then Try_Object_Operation (N)
2900 -- If the transformation fails, it will be necessary to redo the
2901 -- analysis with all errors enabled, to indicate candidate
2902 -- interpretations and reasons for each failure ???
2906 elsif Is_Private_Type (Prefix_Type) then
2907 -- Allow access only to discriminants of the type. If the type has
2908 -- no full view, gigi uses the parent type for the components, so we
2909 -- do the same here.
2911 if No (Full_View (Prefix_Type)) then
2912 Entity_List := Root_Type (Base_Type (Prefix_Type));
2913 Comp := First_Entity (Entity_List);
2916 while Present (Comp) loop
2917 if Chars (Comp) = Chars (Sel) then
2918 if Ekind (Comp) = E_Discriminant then
2919 Set_Entity_With_Style_Check (Sel, Comp);
2920 Generate_Reference (Comp, Sel);
2922 Set_Etype (Sel, Etype (Comp));
2923 Set_Etype (N, Etype (Comp));
2925 if Is_Generic_Type (Prefix_Type)
2927 Is_Generic_Type (Root_Type (Prefix_Type))
2929 Set_Original_Discriminant (Sel, Comp);
2932 -- Before declararing an error, check whether this is tagged
2933 -- private type and a call to a primitive operation.
2935 elsif Ada_Version >= Ada_05
2936 and then Is_Tagged_Type (Prefix_Type)
2937 and then Try_Object_Operation (N)
2943 ("invisible selector for }",
2944 N, First_Subtype (Prefix_Type));
2945 Set_Entity (Sel, Any_Id);
2946 Set_Etype (N, Any_Type);
2955 elsif Is_Concurrent_Type (Prefix_Type) then
2957 -- Prefix is concurrent type. Find visible operation with given name
2958 -- For a task, this can only include entries or discriminants if the
2959 -- task type is not an enclosing scope. If it is an enclosing scope
2960 -- (e.g. in an inner task) then all entities are visible, but the
2961 -- prefix must denote the enclosing scope, i.e. can only be a direct
2962 -- name or an expanded name.
2964 Set_Etype (Sel, Any_Type);
2965 In_Scope := In_Open_Scopes (Prefix_Type);
2967 while Present (Comp) loop
2968 if Chars (Comp) = Chars (Sel) then
2969 if Is_Overloadable (Comp) then
2970 Add_One_Interp (Sel, Comp, Etype (Comp));
2972 elsif Ekind (Comp) = E_Discriminant
2973 or else Ekind (Comp) = E_Entry_Family
2975 and then Is_Entity_Name (Name))
2977 Set_Entity_With_Style_Check (Sel, Comp);
2978 Generate_Reference (Comp, Sel);
2984 Set_Etype (Sel, Etype (Comp));
2985 Set_Etype (N, Etype (Comp));
2987 if Ekind (Comp) = E_Discriminant then
2988 Set_Original_Discriminant (Sel, Comp);
2991 -- For access type case, introduce explicit deference for more
2992 -- uniform treatment of entry calls.
2994 if Is_Access_Type (Etype (Name)) then
2995 Insert_Explicit_Dereference (Name);
2997 (Warn_On_Dereference, "?implicit dereference", N);
3003 exit when not In_Scope
3005 Comp = First_Private_Entity (Base_Type (Prefix_Type));
3008 -- If there is no visible entry with the given name, and the task
3009 -- implements an interface, check whether there is some other
3010 -- primitive operation with that name.
3012 if Ada_Version >= Ada_05
3013 and then Is_Tagged_Type (Prefix_Type)
3015 if Etype (N) = Any_Type
3016 and then Try_Object_Operation (N)
3020 -- If the context is not syntactically a procedure call, it
3021 -- may be a call to a primitive function declared outside of
3022 -- the synchronized type.
3024 -- If the context is a procedure call, there might still be
3025 -- an overloading between an entry and a primitive procedure
3026 -- declared outside of the synchronized type, called in prefix
3027 -- notation. This is harder to disambiguate because in one case
3028 -- the controlling formal is implicit ???
3030 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
3031 and then Try_Object_Operation (N)
3037 Set_Is_Overloaded (N, Is_Overloaded (Sel));
3042 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
3045 -- If N still has no type, the component is not defined in the prefix
3047 if Etype (N) = Any_Type then
3049 -- If the prefix is a single concurrent object, use its name in the
3050 -- error message, rather than that of its anonymous type.
3052 if Is_Concurrent_Type (Prefix_Type)
3053 and then Is_Internal_Name (Chars (Prefix_Type))
3054 and then not Is_Derived_Type (Prefix_Type)
3055 and then Is_Entity_Name (Name)
3058 Error_Msg_Node_2 := Entity (Name);
3059 Error_Msg_NE ("no selector& for&", N, Sel);
3061 Check_Misspelled_Selector (Entity_List, Sel);
3063 elsif Is_Generic_Type (Prefix_Type)
3064 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
3065 and then Prefix_Type /= Etype (Prefix_Type)
3066 and then Is_Record_Type (Etype (Prefix_Type))
3068 -- If this is a derived formal type, the parent may have
3069 -- different visibility at this point. Try for an inherited
3070 -- component before reporting an error.
3072 Set_Etype (Prefix (N), Etype (Prefix_Type));
3073 Analyze_Selected_Component (N);
3076 elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
3077 and then Is_Generic_Actual_Type (Prefix_Type)
3078 and then Present (Full_View (Prefix_Type))
3080 -- Similarly, if this the actual for a formal derived type, the
3081 -- component inherited from the generic parent may not be visible
3082 -- in the actual, but the selected component is legal.
3089 First_Component (Generic_Parent_Type (Parent (Prefix_Type)));
3090 while Present (Comp) loop
3091 if Chars (Comp) = Chars (Sel) then
3092 Set_Entity_With_Style_Check (Sel, Comp);
3093 Set_Etype (Sel, Etype (Comp));
3094 Set_Etype (N, Etype (Comp));
3098 Next_Component (Comp);
3101 pragma Assert (Etype (N) /= Any_Type);
3105 if Ekind (Prefix_Type) = E_Record_Subtype then
3107 -- Check whether this is a component of the base type
3108 -- which is absent from a statically constrained subtype.
3109 -- This will raise constraint error at run-time, but is
3110 -- not a compile-time error. When the selector is illegal
3111 -- for base type as well fall through and generate a
3112 -- compilation error anyway.
3114 Comp := First_Component (Base_Type (Prefix_Type));
3115 while Present (Comp) loop
3116 if Chars (Comp) = Chars (Sel)
3117 and then Is_Visible_Component (Comp)
3119 Set_Entity_With_Style_Check (Sel, Comp);
3120 Generate_Reference (Comp, Sel);
3121 Set_Etype (Sel, Etype (Comp));
3122 Set_Etype (N, Etype (Comp));
3124 -- Emit appropriate message. Gigi will replace the
3125 -- node subsequently with the appropriate Raise.
3127 Apply_Compile_Time_Constraint_Error
3128 (N, "component not present in }?",
3129 CE_Discriminant_Check_Failed,
3130 Ent => Prefix_Type, Rep => False);
3131 Set_Raises_Constraint_Error (N);
3135 Next_Component (Comp);
3140 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
3141 Error_Msg_NE ("no selector& for}", N, Sel);
3143 Check_Misspelled_Selector (Entity_List, Sel);
3147 Set_Entity (Sel, Any_Id);
3148 Set_Etype (Sel, Any_Type);
3150 end Analyze_Selected_Component;
3152 ---------------------------
3153 -- Analyze_Short_Circuit --
3154 ---------------------------
3156 procedure Analyze_Short_Circuit (N : Node_Id) is
3157 L : constant Node_Id := Left_Opnd (N);
3158 R : constant Node_Id := Right_Opnd (N);
3163 Analyze_Expression (L);
3164 Analyze_Expression (R);
3165 Set_Etype (N, Any_Type);
3167 if not Is_Overloaded (L) then
3169 if Root_Type (Etype (L)) = Standard_Boolean
3170 and then Has_Compatible_Type (R, Etype (L))
3172 Add_One_Interp (N, Etype (L), Etype (L));
3176 Get_First_Interp (L, Ind, It);
3177 while Present (It.Typ) loop
3178 if Root_Type (It.Typ) = Standard_Boolean
3179 and then Has_Compatible_Type (R, It.Typ)
3181 Add_One_Interp (N, It.Typ, It.Typ);
3184 Get_Next_Interp (Ind, It);
3188 -- Here we have failed to find an interpretation. Clearly we
3189 -- know that it is not the case that both operands can have
3190 -- an interpretation of Boolean, but this is by far the most
3191 -- likely intended interpretation. So we simply resolve both
3192 -- operands as Booleans, and at least one of these resolutions
3193 -- will generate an error message, and we do not need to give
3194 -- a further error message on the short circuit operation itself.
3196 if Etype (N) = Any_Type then
3197 Resolve (L, Standard_Boolean);
3198 Resolve (R, Standard_Boolean);
3199 Set_Etype (N, Standard_Boolean);
3201 end Analyze_Short_Circuit;
3207 procedure Analyze_Slice (N : Node_Id) is
3208 P : constant Node_Id := Prefix (N);
3209 D : constant Node_Id := Discrete_Range (N);
3210 Array_Type : Entity_Id;
3212 procedure Analyze_Overloaded_Slice;
3213 -- If the prefix is overloaded, select those interpretations that
3214 -- yield a one-dimensional array type.
3216 ------------------------------
3217 -- Analyze_Overloaded_Slice --
3218 ------------------------------
3220 procedure Analyze_Overloaded_Slice is
3226 Set_Etype (N, Any_Type);
3228 Get_First_Interp (P, I, It);
3229 while Present (It.Nam) loop
3232 if Is_Access_Type (Typ) then
3233 Typ := Designated_Type (Typ);
3234 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3237 if Is_Array_Type (Typ)
3238 and then Number_Dimensions (Typ) = 1
3239 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
3241 Add_One_Interp (N, Typ, Typ);
3244 Get_Next_Interp (I, It);
3247 if Etype (N) = Any_Type then
3248 Error_Msg_N ("expect array type in prefix of slice", N);
3250 end Analyze_Overloaded_Slice;
3252 -- Start of processing for Analyze_Slice
3258 if Is_Overloaded (P) then
3259 Analyze_Overloaded_Slice;
3262 Array_Type := Etype (P);
3263 Set_Etype (N, Any_Type);
3265 if Is_Access_Type (Array_Type) then
3266 Array_Type := Designated_Type (Array_Type);
3267 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3270 if not Is_Array_Type (Array_Type) then
3271 Wrong_Type (P, Any_Array);
3273 elsif Number_Dimensions (Array_Type) > 1 then
3275 ("type is not one-dimensional array in slice prefix", N);
3278 Has_Compatible_Type (D, Etype (First_Index (Array_Type)))
3280 Wrong_Type (D, Etype (First_Index (Array_Type)));
3283 Set_Etype (N, Array_Type);
3288 -----------------------------
3289 -- Analyze_Type_Conversion --
3290 -----------------------------
3292 procedure Analyze_Type_Conversion (N : Node_Id) is
3293 Expr : constant Node_Id := Expression (N);
3297 -- If Conversion_OK is set, then the Etype is already set, and the
3298 -- only processing required is to analyze the expression. This is
3299 -- used to construct certain "illegal" conversions which are not
3300 -- allowed by Ada semantics, but can be handled OK by Gigi, see
3301 -- Sinfo for further details.
3303 if Conversion_OK (N) then
3308 -- Otherwise full type analysis is required, as well as some semantic
3309 -- checks to make sure the argument of the conversion is appropriate.
3311 Find_Type (Subtype_Mark (N));
3312 T := Entity (Subtype_Mark (N));
3314 Check_Fully_Declared (T, N);
3315 Analyze_Expression (Expr);
3316 Validate_Remote_Type_Type_Conversion (N);
3318 -- Only remaining step is validity checks on the argument. These
3319 -- are skipped if the conversion does not come from the source.
3321 if not Comes_From_Source (N) then
3324 -- If there was an error in a generic unit, no need to replicate the
3325 -- error message. Conversely, constant-folding in the generic may
3326 -- transform the argument of a conversion into a string literal, which
3327 -- is legal. Therefore the following tests are not performed in an
3330 elsif In_Instance then
3333 elsif Nkind (Expr) = N_Null then
3334 Error_Msg_N ("argument of conversion cannot be null", N);
3335 Error_Msg_N ("\use qualified expression instead", N);
3336 Set_Etype (N, Any_Type);
3338 elsif Nkind (Expr) = N_Aggregate then
3339 Error_Msg_N ("argument of conversion cannot be aggregate", N);
3340 Error_Msg_N ("\use qualified expression instead", N);
3342 elsif Nkind (Expr) = N_Allocator then
3343 Error_Msg_N ("argument of conversion cannot be an allocator", N);
3344 Error_Msg_N ("\use qualified expression instead", N);
3346 elsif Nkind (Expr) = N_String_Literal then
3347 Error_Msg_N ("argument of conversion cannot be string literal", N);
3348 Error_Msg_N ("\use qualified expression instead", N);
3350 elsif Nkind (Expr) = N_Character_Literal then
3351 if Ada_Version = Ada_83 then
3354 Error_Msg_N ("argument of conversion cannot be character literal",
3356 Error_Msg_N ("\use qualified expression instead", N);
3359 elsif Nkind (Expr) = N_Attribute_Reference
3361 (Attribute_Name (Expr) = Name_Access or else
3362 Attribute_Name (Expr) = Name_Unchecked_Access or else
3363 Attribute_Name (Expr) = Name_Unrestricted_Access)
3365 Error_Msg_N ("argument of conversion cannot be access", N);
3366 Error_Msg_N ("\use qualified expression instead", N);
3368 end Analyze_Type_Conversion;
3370 ----------------------
3371 -- Analyze_Unary_Op --
3372 ----------------------
3374 procedure Analyze_Unary_Op (N : Node_Id) is
3375 R : constant Node_Id := Right_Opnd (N);
3376 Op_Id : Entity_Id := Entity (N);
3379 Set_Etype (N, Any_Type);
3380 Candidate_Type := Empty;
3382 Analyze_Expression (R);
3384 if Present (Op_Id) then
3385 if Ekind (Op_Id) = E_Operator then
3386 Find_Unary_Types (R, Op_Id, N);
3388 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3392 Op_Id := Get_Name_Entity_Id (Chars (N));
3393 while Present (Op_Id) loop
3394 if Ekind (Op_Id) = E_Operator then
3395 if No (Next_Entity (First_Entity (Op_Id))) then
3396 Find_Unary_Types (R, Op_Id, N);
3399 elsif Is_Overloadable (Op_Id) then
3400 Analyze_User_Defined_Unary_Op (N, Op_Id);
3403 Op_Id := Homonym (Op_Id);
3408 end Analyze_Unary_Op;
3410 ----------------------------------
3411 -- Analyze_Unchecked_Expression --
3412 ----------------------------------
3414 procedure Analyze_Unchecked_Expression (N : Node_Id) is
3416 Analyze (Expression (N), Suppress => All_Checks);
3417 Set_Etype (N, Etype (Expression (N)));
3418 Save_Interps (Expression (N), N);
3419 end Analyze_Unchecked_Expression;
3421 ---------------------------------------
3422 -- Analyze_Unchecked_Type_Conversion --
3423 ---------------------------------------
3425 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
3427 Find_Type (Subtype_Mark (N));
3428 Analyze_Expression (Expression (N));
3429 Set_Etype (N, Entity (Subtype_Mark (N)));
3430 end Analyze_Unchecked_Type_Conversion;
3432 ------------------------------------
3433 -- Analyze_User_Defined_Binary_Op --
3434 ------------------------------------
3436 procedure Analyze_User_Defined_Binary_Op
3441 -- Only do analysis if the operator Comes_From_Source, since otherwise
3442 -- the operator was generated by the expander, and all such operators
3443 -- always refer to the operators in package Standard.
3445 if Comes_From_Source (N) then
3447 F1 : constant Entity_Id := First_Formal (Op_Id);
3448 F2 : constant Entity_Id := Next_Formal (F1);
3451 -- Verify that Op_Id is a visible binary function. Note that since
3452 -- we know Op_Id is overloaded, potentially use visible means use
3453 -- visible for sure (RM 9.4(11)).
3455 if Ekind (Op_Id) = E_Function
3456 and then Present (F2)
3457 and then (Is_Immediately_Visible (Op_Id)
3458 or else Is_Potentially_Use_Visible (Op_Id))
3459 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
3460 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
3462 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3464 if Debug_Flag_E then
3465 Write_Str ("user defined operator ");
3466 Write_Name (Chars (Op_Id));
3467 Write_Str (" on node ");
3468 Write_Int (Int (N));
3474 end Analyze_User_Defined_Binary_Op;
3476 -----------------------------------
3477 -- Analyze_User_Defined_Unary_Op --
3478 -----------------------------------
3480 procedure Analyze_User_Defined_Unary_Op
3485 -- Only do analysis if the operator Comes_From_Source, since otherwise
3486 -- the operator was generated by the expander, and all such operators
3487 -- always refer to the operators in package Standard.
3489 if Comes_From_Source (N) then
3491 F : constant Entity_Id := First_Formal (Op_Id);
3494 -- Verify that Op_Id is a visible unary function. Note that since
3495 -- we know Op_Id is overloaded, potentially use visible means use
3496 -- visible for sure (RM 9.4(11)).
3498 if Ekind (Op_Id) = E_Function
3499 and then No (Next_Formal (F))
3500 and then (Is_Immediately_Visible (Op_Id)
3501 or else Is_Potentially_Use_Visible (Op_Id))
3502 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
3504 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3508 end Analyze_User_Defined_Unary_Op;
3510 ---------------------------
3511 -- Check_Arithmetic_Pair --
3512 ---------------------------
3514 procedure Check_Arithmetic_Pair
3515 (T1, T2 : Entity_Id;
3519 Op_Name : constant Name_Id := Chars (Op_Id);
3521 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
3522 -- Check whether the fixed-point type Typ has a user-defined operator
3523 -- (multiplication or division) that should hide the corresponding
3524 -- predefined operator. Used to implement Ada 2005 AI-264, to make
3525 -- such operators more visible and therefore useful.
3527 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
3528 -- Get specific type (i.e. non-universal type if there is one)
3534 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
3540 -- The operation is treated as primitive if it is declared in the
3541 -- same scope as the type, and therefore on the same entity chain.
3543 Ent := Next_Entity (Typ);
3544 while Present (Ent) loop
3545 if Chars (Ent) = Chars (Op) then
3546 F1 := First_Formal (Ent);
3547 F2 := Next_Formal (F1);
3549 -- The operation counts as primitive if either operand or
3550 -- result are of the given type, and both operands are fixed
3553 if (Etype (F1) = Typ
3554 and then Is_Fixed_Point_Type (Etype (F2)))
3558 and then Is_Fixed_Point_Type (Etype (F1)))
3562 and then Is_Fixed_Point_Type (Etype (F1))
3563 and then Is_Fixed_Point_Type (Etype (F2)))
3579 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
3581 if T1 = Universal_Integer or else T1 = Universal_Real then
3582 return Base_Type (T2);
3584 return Base_Type (T1);
3588 -- Start of processing for Check_Arithmetic_Pair
3591 if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
3593 if Is_Numeric_Type (T1)
3594 and then Is_Numeric_Type (T2)
3595 and then (Covers (T1, T2) or else Covers (T2, T1))
3597 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3600 elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
3602 if Is_Fixed_Point_Type (T1)
3603 and then (Is_Fixed_Point_Type (T2)
3604 or else T2 = Universal_Real)
3606 -- If Treat_Fixed_As_Integer is set then the Etype is already set
3607 -- and no further processing is required (this is the case of an
3608 -- operator constructed by Exp_Fixd for a fixed point operation)
3609 -- Otherwise add one interpretation with universal fixed result
3610 -- If the operator is given in functional notation, it comes
3611 -- from source and Fixed_As_Integer cannot apply.
3613 if (Nkind (N) not in N_Op
3614 or else not Treat_Fixed_As_Integer (N))
3616 (not (Ada_Version >= Ada_05 and then Has_Fixed_Op (T1, Op_Id))
3617 or else Nkind (Parent (N)) = N_Type_Conversion)
3619 Add_One_Interp (N, Op_Id, Universal_Fixed);
3622 elsif Is_Fixed_Point_Type (T2)
3623 and then (Nkind (N) not in N_Op
3624 or else not Treat_Fixed_As_Integer (N))
3625 and then T1 = Universal_Real
3627 (not (Ada_Version >= Ada_05 and then Has_Fixed_Op (T1, Op_Id))
3628 or else Nkind (Parent (N)) = N_Type_Conversion)
3630 Add_One_Interp (N, Op_Id, Universal_Fixed);
3632 elsif Is_Numeric_Type (T1)
3633 and then Is_Numeric_Type (T2)
3634 and then (Covers (T1, T2) or else Covers (T2, T1))
3636 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3638 elsif Is_Fixed_Point_Type (T1)
3639 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3640 or else T2 = Universal_Integer)
3642 Add_One_Interp (N, Op_Id, T1);
3644 elsif T2 = Universal_Real
3645 and then Base_Type (T1) = Base_Type (Standard_Integer)
3646 and then Op_Name = Name_Op_Multiply
3648 Add_One_Interp (N, Op_Id, Any_Fixed);
3650 elsif T1 = Universal_Real
3651 and then Base_Type (T2) = Base_Type (Standard_Integer)
3653 Add_One_Interp (N, Op_Id, Any_Fixed);
3655 elsif Is_Fixed_Point_Type (T2)
3656 and then (Base_Type (T1) = Base_Type (Standard_Integer)
3657 or else T1 = Universal_Integer)
3658 and then Op_Name = Name_Op_Multiply
3660 Add_One_Interp (N, Op_Id, T2);
3662 elsif T1 = Universal_Real and then T2 = Universal_Integer then
3663 Add_One_Interp (N, Op_Id, T1);
3665 elsif T2 = Universal_Real
3666 and then T1 = Universal_Integer
3667 and then Op_Name = Name_Op_Multiply
3669 Add_One_Interp (N, Op_Id, T2);
3672 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
3674 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
3675 -- set does not require any special processing, since the Etype is
3676 -- already set (case of operation constructed by Exp_Fixed).
3678 if Is_Integer_Type (T1)
3679 and then (Covers (T1, T2) or else Covers (T2, T1))
3681 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3684 elsif Op_Name = Name_Op_Expon then
3685 if Is_Numeric_Type (T1)
3686 and then not Is_Fixed_Point_Type (T1)
3687 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3688 or else T2 = Universal_Integer)
3690 Add_One_Interp (N, Op_Id, Base_Type (T1));
3693 else pragma Assert (Nkind (N) in N_Op_Shift);
3695 -- If not one of the predefined operators, the node may be one
3696 -- of the intrinsic functions. Its kind is always specific, and
3697 -- we can use it directly, rather than the name of the operation.
3699 if Is_Integer_Type (T1)
3700 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3701 or else T2 = Universal_Integer)
3703 Add_One_Interp (N, Op_Id, Base_Type (T1));
3706 end Check_Arithmetic_Pair;
3708 -------------------------------
3709 -- Check_Misspelled_Selector --
3710 -------------------------------
3712 procedure Check_Misspelled_Selector
3713 (Prefix : Entity_Id;
3716 Max_Suggestions : constant := 2;
3717 Nr_Of_Suggestions : Natural := 0;
3719 Suggestion_1 : Entity_Id := Empty;
3720 Suggestion_2 : Entity_Id := Empty;
3725 -- All the components of the prefix of selector Sel are matched
3726 -- against Sel and a count is maintained of possible misspellings.
3727 -- When at the end of the analysis there are one or two (not more!)
3728 -- possible misspellings, these misspellings will be suggested as
3729 -- possible correction.
3731 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
3733 -- Concurrent types should be handled as well ???
3738 Get_Name_String (Chars (Sel));
3741 S : constant String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
3744 Comp := First_Entity (Prefix);
3745 while Nr_Of_Suggestions <= Max_Suggestions
3746 and then Present (Comp)
3748 if Is_Visible_Component (Comp) then
3749 Get_Name_String (Chars (Comp));
3751 if Is_Bad_Spelling_Of (Name_Buffer (1 .. Name_Len), S) then
3752 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
3754 case Nr_Of_Suggestions is
3755 when 1 => Suggestion_1 := Comp;
3756 when 2 => Suggestion_2 := Comp;
3757 when others => exit;
3762 Comp := Next_Entity (Comp);
3765 -- Report at most two suggestions
3767 if Nr_Of_Suggestions = 1 then
3768 Error_Msg_NE ("\possible misspelling of&", Sel, Suggestion_1);
3770 elsif Nr_Of_Suggestions = 2 then
3771 Error_Msg_Node_2 := Suggestion_2;
3772 Error_Msg_NE ("\possible misspelling of& or&",
3776 end Check_Misspelled_Selector;
3778 ----------------------
3779 -- Defined_In_Scope --
3780 ----------------------
3782 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
3784 S1 : constant Entity_Id := Scope (Base_Type (T));
3787 or else (S1 = System_Aux_Id and then S = Scope (S1));
3788 end Defined_In_Scope;
3794 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
3801 Void_Interp_Seen : Boolean := False;
3804 if Ada_Version >= Ada_05 then
3805 Actual := First_Actual (N);
3806 while Present (Actual) loop
3808 -- Ada 2005 (AI-50217): Post an error in case of premature
3809 -- usage of an entity from the limited view.
3811 if not Analyzed (Etype (Actual))
3812 and then From_With_Type (Etype (Actual))
3814 Error_Msg_Qual_Level := 1;
3816 ("missing with_clause for scope of imported type&",
3817 Actual, Etype (Actual));
3818 Error_Msg_Qual_Level := 0;
3821 Next_Actual (Actual);
3825 -- Analyze each candidate call again, with full error reporting
3829 ("no candidate interpretations match the actuals:!", Nam);
3830 Err_Mode := All_Errors_Mode;
3831 All_Errors_Mode := True;
3833 -- If this is a call to an operation of a concurrent type,
3834 -- the failed interpretations have been removed from the
3835 -- name. Recover them to provide full diagnostics.
3837 if Nkind (Parent (Nam)) = N_Selected_Component then
3838 Set_Entity (Nam, Empty);
3839 New_Nam := New_Copy_Tree (Parent (Nam));
3840 Set_Is_Overloaded (New_Nam, False);
3841 Set_Is_Overloaded (Selector_Name (New_Nam), False);
3842 Set_Parent (New_Nam, Parent (Parent (Nam)));
3843 Analyze_Selected_Component (New_Nam);
3844 Get_First_Interp (Selector_Name (New_Nam), X, It);
3846 Get_First_Interp (Nam, X, It);
3849 while Present (It.Nam) loop
3850 if Etype (It.Nam) = Standard_Void_Type then
3851 Void_Interp_Seen := True;
3854 Analyze_One_Call (N, It.Nam, True, Success);
3855 Get_Next_Interp (X, It);
3858 if Nkind (N) = N_Function_Call then
3859 Get_First_Interp (Nam, X, It);
3860 while Present (It.Nam) loop
3861 if Ekind (It.Nam) = E_Function
3862 or else Ekind (It.Nam) = E_Operator
3866 Get_Next_Interp (X, It);
3870 -- If all interpretations are procedures, this deserves a
3871 -- more precise message. Ditto if this appears as the prefix
3872 -- of a selected component, which may be a lexical error.
3875 ("\context requires function call, found procedure name", Nam);
3877 if Nkind (Parent (N)) = N_Selected_Component
3878 and then N = Prefix (Parent (N))
3881 "\period should probably be semicolon", Parent (N));
3884 elsif Nkind (N) = N_Procedure_Call_Statement
3885 and then not Void_Interp_Seen
3888 "\function name found in procedure call", Nam);
3891 All_Errors_Mode := Err_Mode;
3894 ---------------------------
3895 -- Find_Arithmetic_Types --
3896 ---------------------------
3898 procedure Find_Arithmetic_Types
3903 Index1 : Interp_Index;
3904 Index2 : Interp_Index;
3908 procedure Check_Right_Argument (T : Entity_Id);
3909 -- Check right operand of operator
3911 --------------------------
3912 -- Check_Right_Argument --
3913 --------------------------
3915 procedure Check_Right_Argument (T : Entity_Id) is
3917 if not Is_Overloaded (R) then
3918 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
3920 Get_First_Interp (R, Index2, It2);
3921 while Present (It2.Typ) loop
3922 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
3923 Get_Next_Interp (Index2, It2);
3926 end Check_Right_Argument;
3928 -- Start processing for Find_Arithmetic_Types
3931 if not Is_Overloaded (L) then
3932 Check_Right_Argument (Etype (L));
3935 Get_First_Interp (L, Index1, It1);
3936 while Present (It1.Typ) loop
3937 Check_Right_Argument (It1.Typ);
3938 Get_Next_Interp (Index1, It1);
3942 end Find_Arithmetic_Types;
3944 ------------------------
3945 -- Find_Boolean_Types --
3946 ------------------------
3948 procedure Find_Boolean_Types
3953 Index : Interp_Index;
3956 procedure Check_Numeric_Argument (T : Entity_Id);
3957 -- Special case for logical operations one of whose operands is an
3958 -- integer literal. If both are literal the result is any modular type.
3960 ----------------------------
3961 -- Check_Numeric_Argument --
3962 ----------------------------
3964 procedure Check_Numeric_Argument (T : Entity_Id) is
3966 if T = Universal_Integer then
3967 Add_One_Interp (N, Op_Id, Any_Modular);
3969 elsif Is_Modular_Integer_Type (T) then
3970 Add_One_Interp (N, Op_Id, T);
3972 end Check_Numeric_Argument;
3974 -- Start of processing for Find_Boolean_Types
3977 if not Is_Overloaded (L) then
3978 if Etype (L) = Universal_Integer
3979 or else Etype (L) = Any_Modular
3981 if not Is_Overloaded (R) then
3982 Check_Numeric_Argument (Etype (R));
3985 Get_First_Interp (R, Index, It);
3986 while Present (It.Typ) loop
3987 Check_Numeric_Argument (It.Typ);
3988 Get_Next_Interp (Index, It);
3992 -- If operands are aggregates, we must assume that they may be
3993 -- boolean arrays, and leave disambiguation for the second pass.
3994 -- If only one is an aggregate, verify that the other one has an
3995 -- interpretation as a boolean array
3997 elsif Nkind (L) = N_Aggregate then
3998 if Nkind (R) = N_Aggregate then
3999 Add_One_Interp (N, Op_Id, Etype (L));
4001 elsif not Is_Overloaded (R) then
4002 if Valid_Boolean_Arg (Etype (R)) then
4003 Add_One_Interp (N, Op_Id, Etype (R));
4007 Get_First_Interp (R, Index, It);
4008 while Present (It.Typ) loop
4009 if Valid_Boolean_Arg (It.Typ) then
4010 Add_One_Interp (N, Op_Id, It.Typ);
4013 Get_Next_Interp (Index, It);
4017 elsif Valid_Boolean_Arg (Etype (L))
4018 and then Has_Compatible_Type (R, Etype (L))
4020 Add_One_Interp (N, Op_Id, Etype (L));
4024 Get_First_Interp (L, Index, It);
4025 while Present (It.Typ) loop
4026 if Valid_Boolean_Arg (It.Typ)
4027 and then Has_Compatible_Type (R, It.Typ)
4029 Add_One_Interp (N, Op_Id, It.Typ);
4032 Get_Next_Interp (Index, It);
4035 end Find_Boolean_Types;
4037 ---------------------------
4038 -- Find_Comparison_Types --
4039 ---------------------------
4041 procedure Find_Comparison_Types
4046 Index : Interp_Index;
4048 Found : Boolean := False;
4051 Scop : Entity_Id := Empty;
4053 procedure Try_One_Interp (T1 : Entity_Id);
4054 -- Routine to try one proposed interpretation. Note that the context
4055 -- of the operator plays no role in resolving the arguments, so that
4056 -- if there is more than one interpretation of the operands that is
4057 -- compatible with comparison, the operation is ambiguous.
4059 --------------------
4060 -- Try_One_Interp --
4061 --------------------
4063 procedure Try_One_Interp (T1 : Entity_Id) is
4066 -- If the operator is an expanded name, then the type of the operand
4067 -- must be defined in the corresponding scope. If the type is
4068 -- universal, the context will impose the correct type.
4071 and then not Defined_In_Scope (T1, Scop)
4072 and then T1 /= Universal_Integer
4073 and then T1 /= Universal_Real
4074 and then T1 /= Any_String
4075 and then T1 /= Any_Composite
4080 if Valid_Comparison_Arg (T1)
4081 and then Has_Compatible_Type (R, T1)
4084 and then Base_Type (T1) /= Base_Type (T_F)
4086 It := Disambiguate (L, I_F, Index, Any_Type);
4088 if It = No_Interp then
4089 Ambiguous_Operands (N);
4090 Set_Etype (L, Any_Type);
4104 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
4109 -- Start processing for Find_Comparison_Types
4112 -- If left operand is aggregate, the right operand has to
4113 -- provide a usable type for it.
4115 if Nkind (L) = N_Aggregate
4116 and then Nkind (R) /= N_Aggregate
4118 Find_Comparison_Types (R, L, Op_Id, N);
4122 if Nkind (N) = N_Function_Call
4123 and then Nkind (Name (N)) = N_Expanded_Name
4125 Scop := Entity (Prefix (Name (N)));
4127 -- The prefix may be a package renaming, and the subsequent test
4128 -- requires the original package.
4130 if Ekind (Scop) = E_Package
4131 and then Present (Renamed_Entity (Scop))
4133 Scop := Renamed_Entity (Scop);
4134 Set_Entity (Prefix (Name (N)), Scop);
4138 if not Is_Overloaded (L) then
4139 Try_One_Interp (Etype (L));
4142 Get_First_Interp (L, Index, It);
4143 while Present (It.Typ) loop
4144 Try_One_Interp (It.Typ);
4145 Get_Next_Interp (Index, It);
4148 end Find_Comparison_Types;
4150 ----------------------------------------
4151 -- Find_Non_Universal_Interpretations --
4152 ----------------------------------------
4154 procedure Find_Non_Universal_Interpretations
4160 Index : Interp_Index;
4164 if T1 = Universal_Integer
4165 or else T1 = Universal_Real
4167 if not Is_Overloaded (R) then
4169 (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
4171 Get_First_Interp (R, Index, It);
4172 while Present (It.Typ) loop
4173 if Covers (It.Typ, T1) then
4175 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
4178 Get_Next_Interp (Index, It);
4182 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
4184 end Find_Non_Universal_Interpretations;
4186 ------------------------------
4187 -- Find_Concatenation_Types --
4188 ------------------------------
4190 procedure Find_Concatenation_Types
4195 Op_Type : constant Entity_Id := Etype (Op_Id);
4198 if Is_Array_Type (Op_Type)
4199 and then not Is_Limited_Type (Op_Type)
4201 and then (Has_Compatible_Type (L, Op_Type)
4203 Has_Compatible_Type (L, Component_Type (Op_Type)))
4205 and then (Has_Compatible_Type (R, Op_Type)
4207 Has_Compatible_Type (R, Component_Type (Op_Type)))
4209 Add_One_Interp (N, Op_Id, Op_Type);
4211 end Find_Concatenation_Types;
4213 -------------------------
4214 -- Find_Equality_Types --
4215 -------------------------
4217 procedure Find_Equality_Types
4222 Index : Interp_Index;
4224 Found : Boolean := False;
4227 Scop : Entity_Id := Empty;
4229 procedure Try_One_Interp (T1 : Entity_Id);
4230 -- The context of the operator plays no role in resolving the
4231 -- arguments, so that if there is more than one interpretation
4232 -- of the operands that is compatible with equality, the construct
4233 -- is ambiguous and an error can be emitted now, after trying to
4234 -- disambiguate, i.e. applying preference rules.
4236 --------------------
4237 -- Try_One_Interp --
4238 --------------------
4240 procedure Try_One_Interp (T1 : Entity_Id) is
4242 -- If the operator is an expanded name, then the type of the operand
4243 -- must be defined in the corresponding scope. If the type is
4244 -- universal, the context will impose the correct type. An anonymous
4245 -- type for a 'Access reference is also universal in this sense, as
4246 -- the actual type is obtained from context.
4247 -- In Ada 2005, the equality operator for anonymous access types
4248 -- is declared in Standard, and preference rules apply to it.
4250 if Present (Scop) then
4251 if Defined_In_Scope (T1, Scop)
4252 or else T1 = Universal_Integer
4253 or else T1 = Universal_Real
4254 or else T1 = Any_Access
4255 or else T1 = Any_String
4256 or else T1 = Any_Composite
4257 or else (Ekind (T1) = E_Access_Subprogram_Type
4258 and then not Comes_From_Source (T1))
4262 elsif Ekind (T1) = E_Anonymous_Access_Type
4263 and then Scop = Standard_Standard
4268 -- The scope does not contain an operator for the type
4274 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
4275 -- Do not allow anonymous access types in equality operators.
4277 if Ada_Version < Ada_05
4278 and then Ekind (T1) = E_Anonymous_Access_Type
4283 if T1 /= Standard_Void_Type
4284 and then not Is_Limited_Type (T1)
4285 and then not Is_Limited_Composite (T1)
4286 and then Has_Compatible_Type (R, T1)
4289 and then Base_Type (T1) /= Base_Type (T_F)
4291 It := Disambiguate (L, I_F, Index, Any_Type);
4293 if It = No_Interp then
4294 Ambiguous_Operands (N);
4295 Set_Etype (L, Any_Type);
4308 if not Analyzed (L) then
4312 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
4314 -- Case of operator was not visible, Etype still set to Any_Type
4316 if Etype (N) = Any_Type then
4320 elsif Scop = Standard_Standard
4321 and then Ekind (T1) = E_Anonymous_Access_Type
4327 -- Start of processing for Find_Equality_Types
4330 -- If left operand is aggregate, the right operand has to
4331 -- provide a usable type for it.
4333 if Nkind (L) = N_Aggregate
4334 and then Nkind (R) /= N_Aggregate
4336 Find_Equality_Types (R, L, Op_Id, N);
4340 if Nkind (N) = N_Function_Call
4341 and then Nkind (Name (N)) = N_Expanded_Name
4343 Scop := Entity (Prefix (Name (N)));
4345 -- The prefix may be a package renaming, and the subsequent test
4346 -- requires the original package.
4348 if Ekind (Scop) = E_Package
4349 and then Present (Renamed_Entity (Scop))
4351 Scop := Renamed_Entity (Scop);
4352 Set_Entity (Prefix (Name (N)), Scop);
4356 if not Is_Overloaded (L) then
4357 Try_One_Interp (Etype (L));
4360 Get_First_Interp (L, Index, It);
4361 while Present (It.Typ) loop
4362 Try_One_Interp (It.Typ);
4363 Get_Next_Interp (Index, It);
4366 end Find_Equality_Types;
4368 -------------------------
4369 -- Find_Negation_Types --
4370 -------------------------
4372 procedure Find_Negation_Types
4377 Index : Interp_Index;
4381 if not Is_Overloaded (R) then
4382 if Etype (R) = Universal_Integer then
4383 Add_One_Interp (N, Op_Id, Any_Modular);
4384 elsif Valid_Boolean_Arg (Etype (R)) then
4385 Add_One_Interp (N, Op_Id, Etype (R));
4389 Get_First_Interp (R, Index, It);
4390 while Present (It.Typ) loop
4391 if Valid_Boolean_Arg (It.Typ) then
4392 Add_One_Interp (N, Op_Id, It.Typ);
4395 Get_Next_Interp (Index, It);
4398 end Find_Negation_Types;
4400 ----------------------
4401 -- Find_Unary_Types --
4402 ----------------------
4404 procedure Find_Unary_Types
4409 Index : Interp_Index;
4413 if not Is_Overloaded (R) then
4414 if Is_Numeric_Type (Etype (R)) then
4415 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
4419 Get_First_Interp (R, Index, It);
4420 while Present (It.Typ) loop
4421 if Is_Numeric_Type (It.Typ) then
4422 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
4425 Get_Next_Interp (Index, It);
4428 end Find_Unary_Types;
4434 function Junk_Operand (N : Node_Id) return Boolean is
4438 if Error_Posted (N) then
4442 -- Get entity to be tested
4444 if Is_Entity_Name (N)
4445 and then Present (Entity (N))
4449 -- An odd case, a procedure name gets converted to a very peculiar
4450 -- function call, and here is where we detect this happening.
4452 elsif Nkind (N) = N_Function_Call
4453 and then Is_Entity_Name (Name (N))
4454 and then Present (Entity (Name (N)))
4458 -- Another odd case, there are at least some cases of selected
4459 -- components where the selected component is not marked as having
4460 -- an entity, even though the selector does have an entity
4462 elsif Nkind (N) = N_Selected_Component
4463 and then Present (Entity (Selector_Name (N)))
4465 Enode := Selector_Name (N);
4471 -- Now test the entity we got to see if it is a bad case
4473 case Ekind (Entity (Enode)) is
4477 ("package name cannot be used as operand", Enode);
4479 when Generic_Unit_Kind =>
4481 ("generic unit name cannot be used as operand", Enode);
4485 ("subtype name cannot be used as operand", Enode);
4489 ("entry name cannot be used as operand", Enode);
4493 ("procedure name cannot be used as operand", Enode);
4497 ("exception name cannot be used as operand", Enode);
4499 when E_Block | E_Label | E_Loop =>
4501 ("label name cannot be used as operand", Enode);
4511 --------------------
4512 -- Operator_Check --
4513 --------------------
4515 procedure Operator_Check (N : Node_Id) is
4517 Remove_Abstract_Operations (N);
4519 -- Test for case of no interpretation found for operator
4521 if Etype (N) = Any_Type then
4525 Op_Id : Entity_Id := Empty;
4528 R := Right_Opnd (N);
4530 if Nkind (N) in N_Binary_Op then
4536 -- If either operand has no type, then don't complain further,
4537 -- since this simply means that we have a propagated error.
4540 or else Etype (R) = Any_Type
4541 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
4545 -- We explicitly check for the case of concatenation of component
4546 -- with component to avoid reporting spurious matching array types
4547 -- that might happen to be lurking in distant packages (such as
4548 -- run-time packages). This also prevents inconsistencies in the
4549 -- messages for certain ACVC B tests, which can vary depending on
4550 -- types declared in run-time interfaces. Another improvement when
4551 -- aggregates are present is to look for a well-typed operand.
4553 elsif Present (Candidate_Type)
4554 and then (Nkind (N) /= N_Op_Concat
4555 or else Is_Array_Type (Etype (L))
4556 or else Is_Array_Type (Etype (R)))
4559 if Nkind (N) = N_Op_Concat then
4560 if Etype (L) /= Any_Composite
4561 and then Is_Array_Type (Etype (L))
4563 Candidate_Type := Etype (L);
4565 elsif Etype (R) /= Any_Composite
4566 and then Is_Array_Type (Etype (R))
4568 Candidate_Type := Etype (R);
4573 ("operator for} is not directly visible!",
4574 N, First_Subtype (Candidate_Type));
4575 Error_Msg_N ("use clause would make operation legal!", N);
4578 -- If either operand is a junk operand (e.g. package name), then
4579 -- post appropriate error messages, but do not complain further.
4581 -- Note that the use of OR in this test instead of OR ELSE is
4582 -- quite deliberate, we may as well check both operands in the
4583 -- binary operator case.
4585 elsif Junk_Operand (R)
4586 or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
4590 -- If we have a logical operator, one of whose operands is
4591 -- Boolean, then we know that the other operand cannot resolve to
4592 -- Boolean (since we got no interpretations), but in that case we
4593 -- pretty much know that the other operand should be Boolean, so
4594 -- resolve it that way (generating an error)
4596 elsif Nkind (N) = N_Op_And
4600 Nkind (N) = N_Op_Xor
4602 if Etype (L) = Standard_Boolean then
4603 Resolve (R, Standard_Boolean);
4605 elsif Etype (R) = Standard_Boolean then
4606 Resolve (L, Standard_Boolean);
4610 -- For an arithmetic operator or comparison operator, if one
4611 -- of the operands is numeric, then we know the other operand
4612 -- is not the same numeric type. If it is a non-numeric type,
4613 -- then probably it is intended to match the other operand.
4615 elsif Nkind (N) = N_Op_Add or else
4616 Nkind (N) = N_Op_Divide or else
4617 Nkind (N) = N_Op_Ge or else
4618 Nkind (N) = N_Op_Gt or else
4619 Nkind (N) = N_Op_Le or else
4620 Nkind (N) = N_Op_Lt or else
4621 Nkind (N) = N_Op_Mod or else
4622 Nkind (N) = N_Op_Multiply or else
4623 Nkind (N) = N_Op_Rem or else
4624 Nkind (N) = N_Op_Subtract
4626 if Is_Numeric_Type (Etype (L))
4627 and then not Is_Numeric_Type (Etype (R))
4629 Resolve (R, Etype (L));
4632 elsif Is_Numeric_Type (Etype (R))
4633 and then not Is_Numeric_Type (Etype (L))
4635 Resolve (L, Etype (R));
4639 -- Comparisons on A'Access are common enough to deserve a
4642 elsif (Nkind (N) = N_Op_Eq or else
4643 Nkind (N) = N_Op_Ne)
4644 and then Ekind (Etype (L)) = E_Access_Attribute_Type
4645 and then Ekind (Etype (R)) = E_Access_Attribute_Type
4648 ("two access attributes cannot be compared directly", N);
4650 ("\use qualified expression for one of the operands",
4654 -- Another one for C programmers
4656 elsif Nkind (N) = N_Op_Concat
4657 and then Valid_Boolean_Arg (Etype (L))
4658 and then Valid_Boolean_Arg (Etype (R))
4660 Error_Msg_N ("invalid operands for concatenation", N);
4661 Error_Msg_N ("\maybe AND was meant", N);
4664 -- A special case for comparison of access parameter with null
4666 elsif Nkind (N) = N_Op_Eq
4667 and then Is_Entity_Name (L)
4668 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
4669 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
4671 and then Nkind (R) = N_Null
4673 Error_Msg_N ("access parameter is not allowed to be null", L);
4674 Error_Msg_N ("\(call would raise Constraint_Error)", L);
4678 -- If we fall through then just give general message. Note that in
4679 -- the following messages, if the operand is overloaded we choose
4680 -- an arbitrary type to complain about, but that is probably more
4681 -- useful than not giving a type at all.
4683 if Nkind (N) in N_Unary_Op then
4684 Error_Msg_Node_2 := Etype (R);
4685 Error_Msg_N ("operator& not defined for}", N);
4689 if Nkind (N) in N_Binary_Op then
4690 if not Is_Overloaded (L)
4691 and then not Is_Overloaded (R)
4692 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
4694 Error_Msg_Node_2 := First_Subtype (Etype (R));
4695 Error_Msg_N ("there is no applicable operator& for}", N);
4698 -- Another attempt to find a fix: one of the candidate
4699 -- interpretations may not be use-visible. This has
4700 -- already been checked for predefined operators, so
4701 -- we examine only user-defined functions.
4703 Op_Id := Get_Name_Entity_Id (Chars (N));
4705 while Present (Op_Id) loop
4706 if Ekind (Op_Id) /= E_Operator
4707 and then Is_Overloadable (Op_Id)
4709 if not Is_Immediately_Visible (Op_Id)
4710 and then not In_Use (Scope (Op_Id))
4711 and then not Is_Abstract_Subprogram (Op_Id)
4712 and then not Is_Hidden (Op_Id)
4713 and then Ekind (Scope (Op_Id)) = E_Package
4716 (L, Etype (First_Formal (Op_Id)))
4718 (Next_Formal (First_Formal (Op_Id)))
4722 Etype (Next_Formal (First_Formal (Op_Id))))
4725 ("No legal interpretation for operator&", N);
4727 ("\use clause on& would make operation legal",
4733 Op_Id := Homonym (Op_Id);
4737 Error_Msg_N ("invalid operand types for operator&", N);
4739 if Nkind (N) /= N_Op_Concat then
4740 Error_Msg_NE ("\left operand has}!", N, Etype (L));
4741 Error_Msg_NE ("\right operand has}!", N, Etype (R));
4751 -----------------------------------------
4752 -- Process_Implicit_Dereference_Prefix --
4753 -----------------------------------------
4755 procedure Process_Implicit_Dereference_Prefix
4763 and then (Operating_Mode = Check_Semantics or else not Expander_Active)
4765 -- We create a dummy reference to E to ensure that the reference
4766 -- is not considered as part of an assignment (an implicit
4767 -- dereference can never assign to its prefix). The Comes_From_Source
4768 -- attribute needs to be propagated for accurate warnings.
4770 Ref := New_Reference_To (E, Sloc (P));
4771 Set_Comes_From_Source (Ref, Comes_From_Source (P));
4772 Generate_Reference (E, Ref);
4774 end Process_Implicit_Dereference_Prefix;
4776 --------------------------------
4777 -- Remove_Abstract_Operations --
4778 --------------------------------
4780 procedure Remove_Abstract_Operations (N : Node_Id) is
4783 Abstract_Op : Entity_Id := Empty;
4785 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
4786 -- activate this if either extensions are enabled, or if the abstract
4787 -- operation in question comes from a predefined file. This latter test
4788 -- allows us to use abstract to make operations invisible to users. In
4789 -- particular, if type Address is non-private and abstract subprograms
4790 -- are used to hide its operators, they will be truly hidden.
4792 type Operand_Position is (First_Op, Second_Op);
4793 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
4795 procedure Remove_Address_Interpretations (Op : Operand_Position);
4796 -- Ambiguities may arise when the operands are literal and the address
4797 -- operations in s-auxdec are visible. In that case, remove the
4798 -- interpretation of a literal as Address, to retain the semantics of
4799 -- Address as a private type.
4801 ------------------------------------
4802 -- Remove_Address_Interpretations --
4803 ------------------------------------
4805 procedure Remove_Address_Interpretations (Op : Operand_Position) is
4809 if Is_Overloaded (N) then
4810 Get_First_Interp (N, I, It);
4811 while Present (It.Nam) loop
4812 Formal := First_Entity (It.Nam);
4814 if Op = Second_Op then
4815 Formal := Next_Entity (Formal);
4818 if Is_Descendent_Of_Address (Etype (Formal)) then
4822 Get_Next_Interp (I, It);
4825 end Remove_Address_Interpretations;
4827 -- Start of processing for Remove_Abstract_Operations
4830 if Is_Overloaded (N) then
4831 Get_First_Interp (N, I, It);
4833 while Present (It.Nam) loop
4834 if Is_Overloadable (It.Nam)
4835 and then Is_Abstract_Subprogram (It.Nam)
4836 and then not Is_Dispatching_Operation (It.Nam)
4838 Abstract_Op := It.Nam;
4840 -- In Ada 2005, this operation does not participate in Overload
4841 -- resolution. If the operation is defined in in a predefined
4842 -- unit, it is one of the operations declared abstract in some
4843 -- variants of System, and it must be removed as well.
4845 if Ada_Version >= Ada_05
4846 or else Is_Predefined_File_Name
4847 (Unit_File_Name (Get_Source_Unit (It.Nam)))
4848 or else Is_Descendent_Of_Address (It.Typ)
4855 Get_Next_Interp (I, It);
4858 if No (Abstract_Op) then
4860 -- If some interpretation yields an integer type, it is still
4861 -- possible that there are address interpretations. Remove them
4862 -- if one operand is a literal, to avoid spurious ambiguities
4863 -- on systems where Address is a visible integer type.
4865 if Is_Overloaded (N)
4866 and then Nkind (N) in N_Op
4867 and then Is_Integer_Type (Etype (N))
4869 if Nkind (N) in N_Binary_Op then
4870 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
4871 Remove_Address_Interpretations (Second_Op);
4873 elsif Nkind (Right_Opnd (N)) = N_Integer_Literal then
4874 Remove_Address_Interpretations (First_Op);
4879 elsif Nkind (N) in N_Op then
4881 -- Remove interpretations that treat literals as addresses. This
4882 -- is never appropriate, even when Address is defined as a visible
4883 -- Integer type. The reason is that we would really prefer Address
4884 -- to behave as a private type, even in this case, which is there
4885 -- only to accomodate oddities of VMS address sizes. If Address is
4886 -- a visible integer type, we get lots of overload ambiguities.
4888 if Nkind (N) in N_Binary_Op then
4890 U1 : constant Boolean :=
4891 Present (Universal_Interpretation (Right_Opnd (N)));
4892 U2 : constant Boolean :=
4893 Present (Universal_Interpretation (Left_Opnd (N)));
4897 Remove_Address_Interpretations (Second_Op);
4901 Remove_Address_Interpretations (First_Op);
4904 if not (U1 and U2) then
4906 -- Remove corresponding predefined operator, which is
4907 -- always added to the overload set.
4909 Get_First_Interp (N, I, It);
4910 while Present (It.Nam) loop
4911 if Scope (It.Nam) = Standard_Standard
4912 and then Base_Type (It.Typ) =
4913 Base_Type (Etype (Abstract_Op))
4918 Get_Next_Interp (I, It);
4921 elsif Is_Overloaded (N)
4922 and then Present (Univ_Type)
4924 -- If both operands have a universal interpretation,
4925 -- it is still necessary to remove interpretations that
4926 -- yield Address. Any remaining ambiguities will be
4927 -- removed in Disambiguate.
4929 Get_First_Interp (N, I, It);
4930 while Present (It.Nam) loop
4931 if Is_Descendent_Of_Address (It.Typ) then
4934 elsif not Is_Type (It.Nam) then
4935 Set_Entity (N, It.Nam);
4938 Get_Next_Interp (I, It);
4944 elsif Nkind (N) = N_Function_Call
4946 (Nkind (Name (N)) = N_Operator_Symbol
4948 (Nkind (Name (N)) = N_Expanded_Name
4950 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
4954 Arg1 : constant Node_Id := First (Parameter_Associations (N));
4955 U1 : constant Boolean :=
4956 Present (Universal_Interpretation (Arg1));
4957 U2 : constant Boolean :=
4958 Present (Next (Arg1)) and then
4959 Present (Universal_Interpretation (Next (Arg1)));
4963 Remove_Address_Interpretations (First_Op);
4967 Remove_Address_Interpretations (Second_Op);
4970 if not (U1 and U2) then
4971 Get_First_Interp (N, I, It);
4972 while Present (It.Nam) loop
4973 if Scope (It.Nam) = Standard_Standard
4974 and then It.Typ = Base_Type (Etype (Abstract_Op))
4979 Get_Next_Interp (I, It);
4985 -- If the removal has left no valid interpretations, emit
4986 -- error message now and label node as illegal.
4988 if Present (Abstract_Op) then
4989 Get_First_Interp (N, I, It);
4993 -- Removal of abstract operation left no viable candidate
4995 Set_Etype (N, Any_Type);
4996 Error_Msg_Sloc := Sloc (Abstract_Op);
4998 ("cannot call abstract operation& declared#", N, Abstract_Op);
5002 end Remove_Abstract_Operations;
5004 -----------------------
5005 -- Try_Indirect_Call --
5006 -----------------------
5008 function Try_Indirect_Call
5011 Typ : Entity_Id) return Boolean
5018 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
5020 Actual := First_Actual (N);
5021 Formal := First_Formal (Designated_Type (Typ));
5022 while Present (Actual) and then Present (Formal) loop
5023 if not Has_Compatible_Type (Actual, Etype (Formal)) then
5028 Next_Formal (Formal);
5031 if No (Actual) and then No (Formal) then
5032 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
5034 -- Nam is a candidate interpretation for the name in the call,
5035 -- if it is not an indirect call.
5037 if not Is_Type (Nam)
5038 and then Is_Entity_Name (Name (N))
5040 Set_Entity (Name (N), Nam);
5047 end Try_Indirect_Call;
5049 ----------------------
5050 -- Try_Indexed_Call --
5051 ----------------------
5053 function Try_Indexed_Call
5057 Skip_First : Boolean) return Boolean
5059 Actuals : constant List_Id := Parameter_Associations (N);
5064 Actual := First (Actuals);
5066 -- If the call was originally written in prefix form, skip the first
5067 -- actual, which is obviously not defaulted.
5073 Index := First_Index (Typ);
5074 while Present (Actual) and then Present (Index) loop
5076 -- If the parameter list has a named association, the expression
5077 -- is definitely a call and not an indexed component.
5079 if Nkind (Actual) = N_Parameter_Association then
5083 if not Has_Compatible_Type (Actual, Etype (Index)) then
5091 if No (Actual) and then No (Index) then
5092 Add_One_Interp (N, Nam, Component_Type (Typ));
5094 -- Nam is a candidate interpretation for the name in the call,
5095 -- if it is not an indirect call.
5097 if not Is_Type (Nam)
5098 and then Is_Entity_Name (Name (N))
5100 Set_Entity (Name (N), Nam);
5107 end Try_Indexed_Call;
5109 --------------------------
5110 -- Try_Object_Operation --
5111 --------------------------
5113 function Try_Object_Operation (N : Node_Id) return Boolean is
5114 K : constant Node_Kind := Nkind (Parent (N));
5115 Loc : constant Source_Ptr := Sloc (N);
5116 Candidate : Entity_Id := Empty;
5117 Is_Subprg_Call : constant Boolean := K = N_Procedure_Call_Statement
5118 or else K = N_Function_Call;
5119 Obj : constant Node_Id := Prefix (N);
5120 Subprog : constant Node_Id :=
5121 Make_Identifier (Sloc (Selector_Name (N)),
5122 Chars => Chars (Selector_Name (N)));
5123 -- Identifier on which possible interpretations will be collected.
5125 Success : Boolean := False;
5127 Report_Error : Boolean := False;
5128 -- If no candidate interpretation matches the context, redo the
5129 -- analysis with error enabled to provide additional information.
5132 New_Call_Node : Node_Id := Empty;
5133 Node_To_Replace : Node_Id;
5134 Obj_Type : Entity_Id := Etype (Obj);
5136 function Valid_Candidate
5139 Subp : Entity_Id) return Entity_Id;
5140 -- If the subprogram is a valid interpretation, record it, and add
5141 -- to the list of interpretations of Subprog.
5143 procedure Complete_Object_Operation
5144 (Call_Node : Node_Id;
5145 Node_To_Replace : Node_Id);
5146 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
5147 -- Call_Node, insert the object (or its dereference) as the first actual
5148 -- in the call, and complete the analysis of the call.
5150 procedure Report_Ambiguity (Op : Entity_Id);
5151 -- If a prefixed procedure call is ambiguous, indicate whether the
5152 -- call includes an implicit dereference or an implicit 'Access.
5154 procedure Transform_Object_Operation
5155 (Call_Node : out Node_Id;
5156 Node_To_Replace : out Node_Id);
5157 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
5158 -- Call_Node is the resulting subprogram call,
5159 -- Node_To_Replace is either N or the parent of N, and Subprog
5160 -- is a reference to the subprogram we are trying to match.
5162 function Try_Class_Wide_Operation
5163 (Call_Node : Node_Id;
5164 Node_To_Replace : Node_Id) return Boolean;
5165 -- Traverse all ancestor types looking for a class-wide subprogram
5166 -- for which the current operation is a valid non-dispatching call.
5168 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
5169 -- If prefix is overloaded, its interpretation may include different
5170 -- tagged types, and we must examine the primitive operations and
5171 -- the class-wide operations of each in order to find candidate
5172 -- interpretations for the call as a whole.
5174 function Try_Primitive_Operation
5175 (Call_Node : Node_Id;
5176 Node_To_Replace : Node_Id) return Boolean;
5177 -- Traverse the list of primitive subprograms looking for a dispatching
5178 -- operation for which the current node is a valid call .
5180 ---------------------
5181 -- Valid_Candidate --
5182 ---------------------
5184 function Valid_Candidate
5187 Subp : Entity_Id) return Entity_Id
5189 Comp_Type : Entity_Id;
5192 -- If the subprogram is a valid interpretation, record it in global
5193 -- variable Subprog, to collect all possible overloadings.
5196 if Subp /= Entity (Subprog) then
5197 Add_One_Interp (Subprog, Subp, Etype (Subp));
5201 -- If the call may be an indexed call, retrieve component type
5202 -- of resulting expression, and add possible interpretation.
5206 if Nkind (Call) = N_Function_Call
5207 and then Nkind (Parent (N)) = N_Indexed_Component
5208 and then Needs_One_Actual (Subp)
5210 if Is_Array_Type (Etype (Subp)) then
5211 Comp_Type := Component_Type (Etype (Subp));
5213 elsif Is_Access_Type (Etype (Subp))
5214 and then Is_Array_Type (Designated_Type (Etype (Subp)))
5216 Comp_Type := Component_Type (Designated_Type (Etype (Subp)));
5220 if Present (Comp_Type)
5221 and then Etype (Subprog) /= Comp_Type
5223 Add_One_Interp (Subprog, Subp, Comp_Type);
5226 if Etype (Call) /= Any_Type then
5231 end Valid_Candidate;
5233 -------------------------------
5234 -- Complete_Object_Operation --
5235 -------------------------------
5237 procedure Complete_Object_Operation
5238 (Call_Node : Node_Id;
5239 Node_To_Replace : Node_Id)
5241 Formal_Type : constant Entity_Id :=
5242 Etype (First_Formal (Entity (Subprog)));
5243 First_Actual : Node_Id;
5246 -- Place the name of the operation, with its interpretations,
5247 -- on the rewritten call.
5249 Set_Name (Call_Node, Subprog);
5251 First_Actual := First (Parameter_Associations (Call_Node));
5253 -- For cross-reference purposes, treat the new node as being in
5254 -- the source if the original one is.
5256 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
5257 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
5259 if Nkind (N) = N_Selected_Component
5260 and then not Inside_A_Generic
5262 Set_Entity (Selector_Name (N), Entity (Subprog));
5265 -- If need be, rewrite first actual as an explicit dereference
5266 -- If the call is overloaded, the rewriting can only be done
5267 -- once the primitive operation is identified.
5269 if Is_Overloaded (Subprog) then
5271 -- The prefix itself may be overloaded, and its interpretations
5272 -- must be propagated to the new actual in the call.
5274 if Is_Overloaded (Obj) then
5275 Save_Interps (Obj, First_Actual);
5278 Rewrite (First_Actual, Obj);
5280 elsif not Is_Access_Type (Formal_Type)
5281 and then Is_Access_Type (Etype (Obj))
5283 Rewrite (First_Actual,
5284 Make_Explicit_Dereference (Sloc (Obj), Obj));
5285 Analyze (First_Actual);
5287 -- Conversely, if the formal is an access parameter and the
5288 -- object is not, replace the actual with a 'Access reference.
5289 -- Its analysis will check that the object is aliased.
5291 elsif Is_Access_Type (Formal_Type)
5292 and then not Is_Access_Type (Etype (Obj))
5294 Rewrite (First_Actual,
5295 Make_Attribute_Reference (Loc,
5296 Attribute_Name => Name_Access,
5297 Prefix => Relocate_Node (Obj)));
5299 if not Is_Aliased_View (Obj) then
5301 ("object in prefixed call to& must be aliased"
5302 & " ('R'M'-2005 4.3.1 (13))",
5303 Prefix (First_Actual), Subprog);
5306 Analyze (First_Actual);
5309 if Is_Overloaded (Obj) then
5310 Save_Interps (Obj, First_Actual);
5313 Rewrite (First_Actual, Obj);
5316 Rewrite (Node_To_Replace, Call_Node);
5318 -- Propagate the interpretations collected in subprog to the new
5319 -- function call node, to be resolved from context.
5321 if Is_Overloaded (Subprog) then
5322 Save_Interps (Subprog, Node_To_Replace);
5324 Analyze (Node_To_Replace);
5326 end Complete_Object_Operation;
5328 ----------------------
5329 -- Report_Ambiguity --
5330 ----------------------
5332 procedure Report_Ambiguity (Op : Entity_Id) is
5333 Access_Formal : constant Boolean :=
5334 Is_Access_Type (Etype (First_Formal (Op)));
5335 Access_Actual : constant Boolean :=
5336 Is_Access_Type (Etype (Prefix (N)));
5339 Error_Msg_Sloc := Sloc (Op);
5341 if Access_Formal and then not Access_Actual then
5342 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
5344 ("\possible interpretation"
5345 & " (inherited, with implicit 'Access) #", N);
5348 ("\possible interpretation (with implicit 'Access) #", N);
5351 elsif not Access_Formal and then Access_Actual then
5352 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
5354 ("\possible interpretation"
5355 & " ( inherited, with implicit dereference) #", N);
5358 ("\possible interpretation (with implicit dereference) #", N);
5362 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
5363 Error_Msg_N ("\possible interpretation (inherited)#", N);
5365 Error_Msg_N ("\possible interpretation#", N);
5368 end Report_Ambiguity;
5370 --------------------------------
5371 -- Transform_Object_Operation --
5372 --------------------------------
5374 procedure Transform_Object_Operation
5375 (Call_Node : out Node_Id;
5376 Node_To_Replace : out Node_Id)
5378 Parent_Node : constant Node_Id := Parent (N);
5380 Dummy : constant Node_Id := New_Copy (Obj);
5381 -- Placeholder used as a first parameter in the call, replaced
5382 -- eventually by the proper object.
5388 -- Common case covering 1) Call to a procedure and 2) Call to a
5389 -- function that has some additional actuals.
5391 if (Nkind (Parent_Node) = N_Function_Call
5393 Nkind (Parent_Node) = N_Procedure_Call_Statement)
5395 -- N is a selected component node containing the name of the
5396 -- subprogram. If N is not the name of the parent node we must
5397 -- not replace the parent node by the new construct. This case
5398 -- occurs when N is a parameterless call to a subprogram that
5399 -- is an actual parameter of a call to another subprogram. For
5401 -- Some_Subprogram (..., Obj.Operation, ...)
5403 and then Name (Parent_Node) = N
5405 Node_To_Replace := Parent_Node;
5407 Actuals := Parameter_Associations (Parent_Node);
5409 if Present (Actuals) then
5410 Prepend (Dummy, Actuals);
5412 Actuals := New_List (Dummy);
5415 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
5417 Make_Procedure_Call_Statement (Loc,
5418 Name => New_Copy (Subprog),
5419 Parameter_Associations => Actuals);
5423 Make_Function_Call (Loc,
5424 Name => New_Copy (Subprog),
5425 Parameter_Associations => Actuals);
5429 -- Before analysis, the function call appears as an indexed component
5430 -- if there are no named associations.
5432 elsif Nkind (Parent_Node) = N_Indexed_Component
5433 and then N = Prefix (Parent_Node)
5435 Node_To_Replace := Parent_Node;
5437 Actuals := Expressions (Parent_Node);
5439 Actual := First (Actuals);
5440 while Present (Actual) loop
5445 Prepend (Dummy, Actuals);
5448 Make_Function_Call (Loc,
5449 Name => New_Copy (Subprog),
5450 Parameter_Associations => Actuals);
5452 -- Parameterless call: Obj.F is rewritten as F (Obj)
5455 Node_To_Replace := N;
5458 Make_Function_Call (Loc,
5459 Name => New_Copy (Subprog),
5460 Parameter_Associations => New_List (Dummy));
5462 end Transform_Object_Operation;
5464 ------------------------------
5465 -- Try_Class_Wide_Operation --
5466 ------------------------------
5468 function Try_Class_Wide_Operation
5469 (Call_Node : Node_Id;
5470 Node_To_Replace : Node_Id) return Boolean
5472 Anc_Type : Entity_Id;
5473 Matching_Op : Entity_Id := Empty;
5476 procedure Traverse_Homonyms
5477 (Anc_Type : Entity_Id;
5478 Error : out Boolean);
5479 -- Traverse the homonym chain of the subprogram searching for those
5480 -- homonyms whose first formal has the Anc_Type's class-wide type,
5481 -- or an anonymous access type designating the class-wide type. If an
5482 -- ambiguity is detected, then Error is set to True.
5484 procedure Traverse_Interfaces
5485 (Anc_Type : Entity_Id;
5486 Error : out Boolean);
5487 -- Traverse the list of interfaces, if any, associated with Anc_Type
5488 -- and search for acceptable class-wide homonyms associated with each
5489 -- interface. If an ambiguity is detected, then Error is set to True.
5491 -----------------------
5492 -- Traverse_Homonyms --
5493 -----------------------
5495 procedure Traverse_Homonyms
5496 (Anc_Type : Entity_Id;
5497 Error : out Boolean)
5499 Cls_Type : Entity_Id;
5507 Cls_Type := Class_Wide_Type (Anc_Type);
5509 Hom := Current_Entity (Subprog);
5510 while Present (Hom) loop
5511 if (Ekind (Hom) = E_Procedure
5513 Ekind (Hom) = E_Function)
5514 and then Scope (Hom) = Scope (Anc_Type)
5515 and then Present (First_Formal (Hom))
5517 (Etype (First_Formal (Hom)) = Cls_Type
5519 (Is_Access_Type (Etype (First_Formal (Hom)))
5521 Ekind (Etype (First_Formal (Hom))) =
5522 E_Anonymous_Access_Type
5524 Designated_Type (Etype (First_Formal (Hom))) =
5527 Set_Etype (Call_Node, Any_Type);
5528 Set_Is_Overloaded (Call_Node, False);
5531 if No (Matching_Op) then
5532 Hom_Ref := New_Reference_To (Hom, Sloc (Subprog));
5533 Set_Etype (Call_Node, Any_Type);
5534 Set_Parent (Call_Node, Parent (Node_To_Replace));
5536 Set_Name (Call_Node, Hom_Ref);
5541 Report => Report_Error,
5543 Skip_First => True);
5546 Valid_Candidate (Success, Call_Node, Hom);
5552 Report => Report_Error,
5554 Skip_First => True);
5556 if Present (Valid_Candidate (Success, Call_Node, Hom))
5557 and then Nkind (Call_Node) /= N_Function_Call
5559 Error_Msg_NE ("ambiguous call to&", N, Hom);
5560 Report_Ambiguity (Matching_Op);
5561 Report_Ambiguity (Hom);
5568 Hom := Homonym (Hom);
5570 end Traverse_Homonyms;
5572 -------------------------
5573 -- Traverse_Interfaces --
5574 -------------------------
5576 procedure Traverse_Interfaces
5577 (Anc_Type : Entity_Id;
5578 Error : out Boolean)
5581 Intface_List : constant List_Id :=
5582 Abstract_Interface_List (Anc_Type);
5587 if Is_Non_Empty_List (Intface_List) then
5588 Intface := First (Intface_List);
5589 while Present (Intface) loop
5591 -- Look for acceptable class-wide homonyms associated with
5594 Traverse_Homonyms (Etype (Intface), Error);
5600 -- Continue the search by looking at each of the interface's
5601 -- associated interface ancestors.
5603 Traverse_Interfaces (Etype (Intface), Error);
5612 end Traverse_Interfaces;
5614 -- Start of processing for Try_Class_Wide_Operation
5617 -- Loop through ancestor types (including interfaces), traversing the
5618 -- homonym chain of the subprogram, and trying out those homonyms
5619 -- whose first formal has the class-wide type of the ancestor, or an
5620 -- anonymous access type designating the class-wide type.
5622 Anc_Type := Obj_Type;
5624 -- Look for a match among homonyms associated with the ancestor
5626 Traverse_Homonyms (Anc_Type, Error);
5632 -- Continue the search for matches among homonyms associated with
5633 -- any interfaces implemented by the ancestor.
5635 Traverse_Interfaces (Anc_Type, Error);
5641 exit when Etype (Anc_Type) = Anc_Type;
5642 Anc_Type := Etype (Anc_Type);
5645 if Present (Matching_Op) then
5646 Set_Etype (Call_Node, Etype (Matching_Op));
5649 return Present (Matching_Op);
5650 end Try_Class_Wide_Operation;
5652 -----------------------------------
5653 -- Try_One_Prefix_Interpretation --
5654 -----------------------------------
5656 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
5660 if Is_Access_Type (Obj_Type) then
5661 Obj_Type := Designated_Type (Obj_Type);
5664 if Ekind (Obj_Type) = E_Private_Subtype then
5665 Obj_Type := Base_Type (Obj_Type);
5668 if Is_Class_Wide_Type (Obj_Type) then
5669 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
5672 -- The type may have be obtained through a limited_with clause,
5673 -- in which case the primitive operations are available on its
5674 -- non-limited view.
5676 if Ekind (Obj_Type) = E_Incomplete_Type
5677 and then From_With_Type (Obj_Type)
5679 Obj_Type := Non_Limited_View (Obj_Type);
5682 -- If the object is not tagged, or the type is still an incomplete
5683 -- type, this is not a prefixed call.
5685 if not Is_Tagged_Type (Obj_Type)
5686 or else Is_Incomplete_Type (Obj_Type)
5691 if Try_Primitive_Operation
5692 (Call_Node => New_Call_Node,
5693 Node_To_Replace => Node_To_Replace)
5695 Try_Class_Wide_Operation
5696 (Call_Node => New_Call_Node,
5697 Node_To_Replace => Node_To_Replace)
5701 end Try_One_Prefix_Interpretation;
5703 -----------------------------
5704 -- Try_Primitive_Operation --
5705 -----------------------------
5707 function Try_Primitive_Operation
5708 (Call_Node : Node_Id;
5709 Node_To_Replace : Node_Id) return Boolean
5712 Prim_Op : Entity_Id;
5713 Matching_Op : Entity_Id := Empty;
5714 Prim_Op_Ref : Node_Id := Empty;
5716 Corr_Type : Entity_Id := Empty;
5717 -- If the prefix is a synchronized type, the controlling type of
5718 -- the primitive operation is the corresponding record type, else
5719 -- this is the object type itself.
5721 Success : Boolean := False;
5723 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
5724 -- Verify that the prefix, dereferenced if need be, is a valid
5725 -- controlling argument in a call to Op. The remaining actuals
5726 -- are checked in the subsequent call to Analyze_One_Call.
5728 -----------------------------
5729 -- Valid_First_Argument_Of --
5730 -----------------------------
5732 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
5733 Typ : constant Entity_Id := Etype (First_Formal (Op));
5736 -- Simple case. Object may be a subtype of the tagged type
5737 -- or may be the corresponding record of a synchronized type.
5739 return Obj_Type = Typ
5740 or else Base_Type (Obj_Type) = Typ
5742 or else Corr_Type = Typ
5744 -- Prefix can be dereferenced
5747 (Is_Access_Type (Corr_Type)
5748 and then Designated_Type (Corr_Type) = Typ)
5750 -- Formal is an access parameter, for which the object
5751 -- can provide an access.
5754 (Ekind (Typ) = E_Anonymous_Access_Type
5755 and then Designated_Type (Typ) = Base_Type (Corr_Type));
5756 end Valid_First_Argument_Of;
5758 -- Start of processing for Try_Primitive_Operation
5761 -- Look for subprograms in the list of primitive operations The name
5762 -- must be identical, and the kind of call indicates the expected
5763 -- kind of operation (function or procedure). If the type is a
5764 -- (tagged) synchronized type, the primitive ops are attached to
5765 -- the corresponding record type.
5767 if Is_Concurrent_Type (Obj_Type) then
5768 Corr_Type := Corresponding_Record_Type (Obj_Type);
5769 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
5771 Corr_Type := Obj_Type;
5772 Elmt := First_Elmt (Primitive_Operations (Obj_Type));
5775 while Present (Elmt) loop
5776 Prim_Op := Node (Elmt);
5778 if Chars (Prim_Op) = Chars (Subprog)
5779 and then Present (First_Formal (Prim_Op))
5780 and then Valid_First_Argument_Of (Prim_Op)
5782 (Nkind (Call_Node) = N_Function_Call)
5783 = (Ekind (Prim_Op) = E_Function)
5785 -- Ada 2005 (AI-251): If this primitive operation corresponds
5786 -- with an immediate ancestor interface there is no need to add
5787 -- it to the list of interpretations; the corresponding aliased
5788 -- primitive is also in this list of primitive operations and
5789 -- will be used instead.
5791 if (Present (Abstract_Interface_Alias (Prim_Op))
5792 and then Is_Ancestor (Find_Dispatching_Type
5793 (Alias (Prim_Op)), Corr_Type))
5796 -- Do not consider hidden primitives unless they belong to a
5797 -- generic private type with a tagged parent.
5799 (Is_Hidden (Prim_Op)
5800 and then not Is_Immediately_Visible (Obj_Type))
5805 Set_Etype (Call_Node, Any_Type);
5806 Set_Is_Overloaded (Call_Node, False);
5808 if No (Matching_Op) then
5809 Prim_Op_Ref := New_Reference_To (Prim_Op, Sloc (Subprog));
5810 Candidate := Prim_Op;
5812 Set_Parent (Call_Node, Parent (Node_To_Replace));
5814 Set_Name (Call_Node, Prim_Op_Ref);
5820 Report => Report_Error,
5822 Skip_First => True);
5824 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
5828 -- More than one interpretation, collect for subsequent
5829 -- disambiguation. If this is a procedure call and there
5830 -- is another match, report ambiguity now.
5835 Report => Report_Error,
5837 Skip_First => True);
5839 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
5840 and then Nkind (Call_Node) /= N_Function_Call
5842 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
5843 Report_Ambiguity (Matching_Op);
5844 Report_Ambiguity (Prim_Op);
5854 if Present (Matching_Op) then
5855 Set_Etype (Call_Node, Etype (Matching_Op));
5858 return Present (Matching_Op);
5859 end Try_Primitive_Operation;
5861 -- Start of processing for Try_Object_Operation
5864 Analyze_Expression (Obj);
5866 -- Analyze the actuals if node is known to be a subprogram call
5868 if Is_Subprg_Call and then N = Name (Parent (N)) then
5869 Actual := First (Parameter_Associations (Parent (N)));
5870 while Present (Actual) loop
5871 Analyze_Expression (Actual);
5876 -- Build a subprogram call node, using a copy of Obj as its first
5877 -- actual. This is a placeholder, to be replaced by an explicit
5878 -- dereference when needed.
5880 Transform_Object_Operation
5881 (Call_Node => New_Call_Node,
5882 Node_To_Replace => Node_To_Replace);
5884 Set_Etype (New_Call_Node, Any_Type);
5885 Set_Etype (Subprog, Any_Type);
5886 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
5888 if not Is_Overloaded (Obj) then
5889 Try_One_Prefix_Interpretation (Obj_Type);
5896 Get_First_Interp (Obj, I, It);
5897 while Present (It.Nam) loop
5898 Try_One_Prefix_Interpretation (It.Typ);
5899 Get_Next_Interp (I, It);
5904 if Etype (New_Call_Node) /= Any_Type then
5905 Complete_Object_Operation
5906 (Call_Node => New_Call_Node,
5907 Node_To_Replace => Node_To_Replace);
5910 elsif Present (Candidate) then
5912 -- The argument list is not type correct. Re-analyze with error
5913 -- reporting enabled, and use one of the possible candidates.
5914 -- In all_errors mode, re-analyze all failed interpretations.
5916 if All_Errors_Mode then
5917 Report_Error := True;
5918 if Try_Primitive_Operation
5919 (Call_Node => New_Call_Node,
5920 Node_To_Replace => Node_To_Replace)
5923 Try_Class_Wide_Operation
5924 (Call_Node => New_Call_Node,
5925 Node_To_Replace => Node_To_Replace)
5932 (N => New_Call_Node,
5936 Skip_First => True);
5939 return True; -- No need for further errors.
5942 -- There was no candidate operation, so report it as an error
5943 -- in the caller: Analyze_Selected_Component.
5947 end Try_Object_Operation;