1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Debug; use Debug;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Errout; use Errout;
31 with Exp_Util; use Exp_Util;
32 with Fname; use Fname;
33 with Itypes; use Itypes;
35 with Lib.Xref; use Lib.Xref;
36 with Namet; use Namet;
37 with Namet.Sp; use Namet.Sp;
38 with Nlists; use Nlists;
39 with Nmake; use Nmake;
41 with Output; use Output;
42 with Restrict; use Restrict;
43 with Rident; use Rident;
45 with Sem_Aux; use Sem_Aux;
46 with Sem_Case; use Sem_Case;
47 with Sem_Cat; use Sem_Cat;
48 with Sem_Ch3; use Sem_Ch3;
49 with Sem_Ch6; use Sem_Ch6;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Disp; use Sem_Disp;
52 with Sem_Dist; use Sem_Dist;
53 with Sem_Eval; use Sem_Eval;
54 with Sem_Res; use Sem_Res;
55 with Sem_Type; use Sem_Type;
56 with Sem_Util; use Sem_Util;
57 with Sem_Warn; use Sem_Warn;
58 with Stand; use Stand;
59 with Sinfo; use Sinfo;
60 with Snames; use Snames;
61 with Tbuild; use Tbuild;
63 package body Sem_Ch4 is
65 -----------------------
66 -- Local Subprograms --
67 -----------------------
69 procedure Analyze_Concatenation_Rest (N : Node_Id);
70 -- Does the "rest" of the work of Analyze_Concatenation, after the left
71 -- operand has been analyzed. See Analyze_Concatenation for details.
73 procedure Analyze_Expression (N : Node_Id);
74 -- For expressions that are not names, this is just a call to analyze.
75 -- If the expression is a name, it may be a call to a parameterless
76 -- function, and if so must be converted into an explicit call node
77 -- and analyzed as such. This deproceduring must be done during the first
78 -- pass of overload resolution, because otherwise a procedure call with
79 -- overloaded actuals may fail to resolve.
81 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
82 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
83 -- is an operator name or an expanded name whose selector is an operator
84 -- name, and one possible interpretation is as a predefined operator.
86 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
87 -- If the prefix of a selected_component is overloaded, the proper
88 -- interpretation that yields a record type with the proper selector
89 -- name must be selected.
91 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
92 -- Procedure to analyze a user defined binary operator, which is resolved
93 -- like a function, but instead of a list of actuals it is presented
94 -- with the left and right operands of an operator node.
96 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
97 -- Procedure to analyze a user defined unary operator, which is resolved
98 -- like a function, but instead of a list of actuals, it is presented with
99 -- the operand of the operator node.
101 procedure Ambiguous_Operands (N : Node_Id);
102 -- for equality, membership, and comparison operators with overloaded
103 -- arguments, list possible interpretations.
105 procedure Analyze_One_Call
109 Success : out Boolean;
110 Skip_First : Boolean := False);
111 -- Check one interpretation of an overloaded subprogram name for
112 -- compatibility with the types of the actuals in a call. If there is a
113 -- single interpretation which does not match, post error if Report is
116 -- Nam is the entity that provides the formals against which the actuals
117 -- are checked. Nam is either the name of a subprogram, or the internal
118 -- subprogram type constructed for an access_to_subprogram. If the actuals
119 -- are compatible with Nam, then Nam is added to the list of candidate
120 -- interpretations for N, and Success is set to True.
122 -- The flag Skip_First is used when analyzing a call that was rewritten
123 -- from object notation. In this case the first actual may have to receive
124 -- an explicit dereference, depending on the first formal of the operation
125 -- being called. The caller will have verified that the object is legal
126 -- for the call. If the remaining parameters match, the first parameter
127 -- will rewritten as a dereference if needed, prior to completing analysis.
129 procedure Check_Misspelled_Selector
132 -- Give possible misspelling diagnostic if Sel is likely to be a mis-
133 -- spelling of one of the selectors of the Prefix. This is called by
134 -- Analyze_Selected_Component after producing an invalid selector error
137 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
138 -- Verify that type T is declared in scope S. Used to find interpretations
139 -- for operators given by expanded names. This is abstracted as a separate
140 -- function to handle extensions to System, where S is System, but T is
141 -- declared in the extension.
143 procedure Find_Arithmetic_Types
147 -- L and R are the operands of an arithmetic operator. Find
148 -- consistent pairs of interpretations for L and R that have a
149 -- numeric type consistent with the semantics of the operator.
151 procedure Find_Comparison_Types
155 -- L and R are operands of a comparison operator. Find consistent
156 -- pairs of interpretations for L and R.
158 procedure Find_Concatenation_Types
162 -- For the four varieties of concatenation
164 procedure Find_Equality_Types
168 -- Ditto for equality operators
170 procedure Find_Boolean_Types
174 -- Ditto for binary logical operations
176 procedure Find_Negation_Types
180 -- Find consistent interpretation for operand of negation operator
182 procedure Find_Non_Universal_Interpretations
187 -- For equality and comparison operators, the result is always boolean,
188 -- and the legality of the operation is determined from the visibility
189 -- of the operand types. If one of the operands has a universal interpre-
190 -- tation, the legality check uses some compatible non-universal
191 -- interpretation of the other operand. N can be an operator node, or
192 -- a function call whose name is an operator designator.
194 function Find_Primitive_Operation (N : Node_Id) return Boolean;
195 -- Find candidate interpretations for the name Obj.Proc when it appears
196 -- in a subprogram renaming declaration.
198 procedure Find_Unary_Types
202 -- Unary arithmetic types: plus, minus, abs
204 procedure Check_Arithmetic_Pair
208 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
209 -- types for left and right operand. Determine whether they constitute
210 -- a valid pair for the given operator, and record the corresponding
211 -- interpretation of the operator node. The node N may be an operator
212 -- node (the usual case) or a function call whose prefix is an operator
213 -- designator. In both cases Op_Id is the operator name itself.
215 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
216 -- Give detailed information on overloaded call where none of the
217 -- interpretations match. N is the call node, Nam the designator for
218 -- the overloaded entity being called.
220 function Junk_Operand (N : Node_Id) return Boolean;
221 -- Test for an operand that is an inappropriate entity (e.g. a package
222 -- name or a label). If so, issue an error message and return True. If
223 -- the operand is not an inappropriate entity kind, return False.
225 procedure Operator_Check (N : Node_Id);
226 -- Verify that an operator has received some valid interpretation. If none
227 -- was found, determine whether a use clause would make the operation
228 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
229 -- every type compatible with the operator, even if the operator for the
230 -- type is not directly visible. The routine uses this type to emit a more
231 -- informative message.
233 function Process_Implicit_Dereference_Prefix
235 P : Node_Id) return Entity_Id;
236 -- Called when P is the prefix of an implicit dereference, denoting an
237 -- object E. The function returns the designated type of the prefix, taking
238 -- into account that the designated type of an anonymous access type may be
239 -- a limited view, when the non-limited view is visible.
240 -- If in semantics only mode (-gnatc or generic), the function also records
241 -- that the prefix is a reference to E, if any. Normally, such a reference
242 -- is generated only when the implicit dereference is expanded into an
243 -- explicit one, but for consistency we must generate the reference when
244 -- expansion is disabled as well.
246 procedure Remove_Abstract_Operations (N : Node_Id);
247 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
248 -- operation is not a candidate interpretation.
250 function Try_Indexed_Call
254 Skip_First : Boolean) return Boolean;
255 -- If a function has defaults for all its actuals, a call to it may in fact
256 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
257 -- interpretation as an indexing, prior to analysis as a call. If both are
258 -- possible, the node is overloaded with both interpretations (same symbol
259 -- but two different types). If the call is written in prefix form, the
260 -- prefix becomes the first parameter in the call, and only the remaining
261 -- actuals must be checked for the presence of defaults.
263 function Try_Indirect_Call
266 Typ : Entity_Id) return Boolean;
267 -- Similarly, a function F that needs no actuals can return an access to a
268 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
269 -- the call may be overloaded with both interpretations.
271 function Try_Object_Operation (N : Node_Id) return Boolean;
272 -- Ada 2005 (AI-252): Support the object.operation notation. If node N
273 -- is a call in this notation, it is transformed into a normal subprogram
274 -- call where the prefix is a parameter, and True is returned. If node
275 -- N is not of this form, it is unchanged, and False is returned.
277 procedure wpo (T : Entity_Id);
278 pragma Warnings (Off, wpo);
279 -- Used for debugging: obtain list of primitive operations even if
280 -- type is not frozen and dispatch table is not built yet.
282 ------------------------
283 -- Ambiguous_Operands --
284 ------------------------
286 procedure Ambiguous_Operands (N : Node_Id) is
287 procedure List_Operand_Interps (Opnd : Node_Id);
289 --------------------------
290 -- List_Operand_Interps --
291 --------------------------
293 procedure List_Operand_Interps (Opnd : Node_Id) is
298 if Is_Overloaded (Opnd) then
299 if Nkind (Opnd) in N_Op then
301 elsif Nkind (Opnd) = N_Function_Call then
311 if Opnd = Left_Opnd (N) then
312 Error_Msg_N ("\left operand has the following interpretations", N);
315 ("\right operand has the following interpretations", N);
319 List_Interps (Nam, Err);
320 end List_Operand_Interps;
322 -- Start of processing for Ambiguous_Operands
325 if Nkind (N) in N_Membership_Test then
326 Error_Msg_N ("ambiguous operands for membership", N);
328 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
329 Error_Msg_N ("ambiguous operands for equality", N);
332 Error_Msg_N ("ambiguous operands for comparison", N);
335 if All_Errors_Mode then
336 List_Operand_Interps (Left_Opnd (N));
337 List_Operand_Interps (Right_Opnd (N));
339 Error_Msg_N ("\use -gnatf switch for details", N);
341 end Ambiguous_Operands;
343 -----------------------
344 -- Analyze_Aggregate --
345 -----------------------
347 -- Most of the analysis of Aggregates requires that the type be known,
348 -- and is therefore put off until resolution.
350 procedure Analyze_Aggregate (N : Node_Id) is
352 if No (Etype (N)) then
353 Set_Etype (N, Any_Composite);
355 end Analyze_Aggregate;
357 -----------------------
358 -- Analyze_Allocator --
359 -----------------------
361 procedure Analyze_Allocator (N : Node_Id) is
362 Loc : constant Source_Ptr := Sloc (N);
363 Sav_Errs : constant Nat := Serious_Errors_Detected;
364 E : Node_Id := Expression (N);
365 Acc_Type : Entity_Id;
369 -- In accordance with H.4(7), the No_Allocators restriction only applies
370 -- to user-written allocators.
372 if Comes_From_Source (N) then
373 Check_Restriction (No_Allocators, N);
376 if Nkind (E) = N_Qualified_Expression then
377 Acc_Type := Create_Itype (E_Allocator_Type, N);
378 Set_Etype (Acc_Type, Acc_Type);
379 Find_Type (Subtype_Mark (E));
381 -- Analyze the qualified expression, and apply the name resolution
382 -- rule given in 4.7 (3).
385 Type_Id := Etype (E);
386 Set_Directly_Designated_Type (Acc_Type, Type_Id);
388 Resolve (Expression (E), Type_Id);
390 if Is_Limited_Type (Type_Id)
391 and then Comes_From_Source (N)
392 and then not In_Instance_Body
394 if not OK_For_Limited_Init (Type_Id, Expression (E)) then
395 Error_Msg_N ("initialization not allowed for limited types", N);
396 Explain_Limited_Type (Type_Id, N);
400 -- A qualified expression requires an exact match of the type,
401 -- class-wide matching is not allowed.
403 -- if Is_Class_Wide_Type (Type_Id)
404 -- and then Base_Type
405 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
407 -- Wrong_Type (Expression (E), Type_Id);
410 Check_Non_Static_Context (Expression (E));
412 -- We don't analyze the qualified expression itself because it's
413 -- part of the allocator
415 Set_Etype (E, Type_Id);
417 -- Case where allocator has a subtype indication
422 Base_Typ : Entity_Id;
425 -- If the allocator includes a N_Subtype_Indication then a
426 -- constraint is present, otherwise the node is a subtype mark.
427 -- Introduce an explicit subtype declaration into the tree
428 -- defining some anonymous subtype and rewrite the allocator to
429 -- use this subtype rather than the subtype indication.
431 -- It is important to introduce the explicit subtype declaration
432 -- so that the bounds of the subtype indication are attached to
433 -- the tree in case the allocator is inside a generic unit.
435 if Nkind (E) = N_Subtype_Indication then
437 -- A constraint is only allowed for a composite type in Ada
438 -- 95. In Ada 83, a constraint is also allowed for an
439 -- access-to-composite type, but the constraint is ignored.
441 Find_Type (Subtype_Mark (E));
442 Base_Typ := Entity (Subtype_Mark (E));
444 if Is_Elementary_Type (Base_Typ) then
445 if not (Ada_Version = Ada_83
446 and then Is_Access_Type (Base_Typ))
448 Error_Msg_N ("constraint not allowed here", E);
450 if Nkind (Constraint (E)) =
451 N_Index_Or_Discriminant_Constraint
453 Error_Msg_N -- CODEFIX
454 ("\if qualified expression was meant, " &
455 "use apostrophe", Constraint (E));
459 -- Get rid of the bogus constraint:
461 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
462 Analyze_Allocator (N);
465 -- Ada 2005, AI-363: if the designated type has a constrained
466 -- partial view, it cannot receive a discriminant constraint,
467 -- and the allocated object is unconstrained.
469 elsif Ada_Version >= Ada_05
470 and then Has_Constrained_Partial_View (Base_Typ)
473 ("constraint no allowed when type " &
474 "has a constrained partial view", Constraint (E));
477 if Expander_Active then
478 Def_Id := Make_Temporary (Loc, 'S');
481 Make_Subtype_Declaration (Loc,
482 Defining_Identifier => Def_Id,
483 Subtype_Indication => Relocate_Node (E)));
485 if Sav_Errs /= Serious_Errors_Detected
486 and then Nkind (Constraint (E)) =
487 N_Index_Or_Discriminant_Constraint
489 Error_Msg_N -- CODEFIX
490 ("if qualified expression was meant, " &
491 "use apostrophe!", Constraint (E));
494 E := New_Occurrence_Of (Def_Id, Loc);
495 Rewrite (Expression (N), E);
499 Type_Id := Process_Subtype (E, N);
500 Acc_Type := Create_Itype (E_Allocator_Type, N);
501 Set_Etype (Acc_Type, Acc_Type);
502 Set_Directly_Designated_Type (Acc_Type, Type_Id);
503 Check_Fully_Declared (Type_Id, N);
505 -- Ada 2005 (AI-231): If the designated type is itself an access
506 -- type that excludes null, its default initialization will
507 -- be a null object, and we can insert an unconditional raise
508 -- before the allocator.
510 -- Ada2012 (AI-104): a not null indication here is altogether
513 if Can_Never_Be_Null (Type_Id) then
515 Not_Null_Check : constant Node_Id :=
516 Make_Raise_Constraint_Error (Sloc (E),
517 Reason => CE_Null_Not_Allowed);
520 if Ada_Version >= Ada_12 then
522 ("an uninitialized allocator cannot have"
523 & " a null exclusion", N);
525 elsif Expander_Active then
526 Insert_Action (N, Not_Null_Check);
527 Analyze (Not_Null_Check);
530 Error_Msg_N ("null value not allowed here?", E);
535 -- Check restriction against dynamically allocated protected
536 -- objects. Note that when limited aggregates are supported,
537 -- a similar test should be applied to an allocator with a
538 -- qualified expression ???
540 if Is_Protected_Type (Type_Id) then
541 Check_Restriction (No_Protected_Type_Allocators, N);
544 -- Check for missing initialization. Skip this check if we already
545 -- had errors on analyzing the allocator, since in that case these
546 -- are probably cascaded errors.
548 if Is_Indefinite_Subtype (Type_Id)
549 and then Serious_Errors_Detected = Sav_Errs
551 if Is_Class_Wide_Type (Type_Id) then
553 ("initialization required in class-wide allocation", N);
555 if Ada_Version < Ada_05
556 and then Is_Limited_Type (Type_Id)
558 Error_Msg_N ("unconstrained allocation not allowed", N);
560 if Is_Array_Type (Type_Id) then
562 ("\constraint with array bounds required", N);
564 elsif Has_Unknown_Discriminants (Type_Id) then
567 else pragma Assert (Has_Discriminants (Type_Id));
569 ("\constraint with discriminant values required", N);
572 -- Limited Ada 2005 and general non-limited case
576 ("uninitialized unconstrained allocation not allowed",
579 if Is_Array_Type (Type_Id) then
581 ("\qualified expression or constraint with " &
582 "array bounds required", N);
584 elsif Has_Unknown_Discriminants (Type_Id) then
585 Error_Msg_N ("\qualified expression required", N);
587 else pragma Assert (Has_Discriminants (Type_Id));
589 ("\qualified expression or constraint with " &
590 "discriminant values required", N);
598 if Is_Abstract_Type (Type_Id) then
599 Error_Msg_N ("cannot allocate abstract object", E);
602 if Has_Task (Designated_Type (Acc_Type)) then
603 Check_Restriction (No_Tasking, N);
604 Check_Restriction (Max_Tasks, N);
605 Check_Restriction (No_Task_Allocators, N);
607 -- Check that an allocator with task parts isn't for a nested access
608 -- type when restriction No_Task_Hierarchy applies.
610 if not Is_Library_Level_Entity (Acc_Type) then
611 Check_Restriction (No_Task_Hierarchy, N);
615 -- Check that an allocator of a nested access type doesn't create a
616 -- protected object when restriction No_Local_Protected_Objects applies.
617 -- We don't have an equivalent to Has_Task for protected types, so only
618 -- cases where the designated type itself is a protected type are
619 -- currently checked. ???
621 if Is_Protected_Type (Designated_Type (Acc_Type))
622 and then not Is_Library_Level_Entity (Acc_Type)
624 Check_Restriction (No_Local_Protected_Objects, N);
627 -- If the No_Streams restriction is set, check that the type of the
628 -- object is not, and does not contain, any subtype derived from
629 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
630 -- Has_Stream just for efficiency reasons. There is no point in
631 -- spending time on a Has_Stream check if the restriction is not set.
633 if Restriction_Check_Required (No_Streams) then
634 if Has_Stream (Designated_Type (Acc_Type)) then
635 Check_Restriction (No_Streams, N);
639 Set_Etype (N, Acc_Type);
641 if not Is_Library_Level_Entity (Acc_Type) then
642 Check_Restriction (No_Local_Allocators, N);
645 if Serious_Errors_Detected > Sav_Errs then
646 Set_Error_Posted (N);
647 Set_Etype (N, Any_Type);
649 end Analyze_Allocator;
651 ---------------------------
652 -- Analyze_Arithmetic_Op --
653 ---------------------------
655 procedure Analyze_Arithmetic_Op (N : Node_Id) is
656 L : constant Node_Id := Left_Opnd (N);
657 R : constant Node_Id := Right_Opnd (N);
661 Candidate_Type := Empty;
662 Analyze_Expression (L);
663 Analyze_Expression (R);
665 -- If the entity is already set, the node is the instantiation of a
666 -- generic node with a non-local reference, or was manufactured by a
667 -- call to Make_Op_xxx. In either case the entity is known to be valid,
668 -- and we do not need to collect interpretations, instead we just get
669 -- the single possible interpretation.
673 if Present (Op_Id) then
674 if Ekind (Op_Id) = E_Operator then
676 if Nkind_In (N, N_Op_Divide, N_Op_Mod, N_Op_Multiply, N_Op_Rem)
677 and then Treat_Fixed_As_Integer (N)
681 Set_Etype (N, Any_Type);
682 Find_Arithmetic_Types (L, R, Op_Id, N);
686 Set_Etype (N, Any_Type);
687 Add_One_Interp (N, Op_Id, Etype (Op_Id));
690 -- Entity is not already set, so we do need to collect interpretations
693 Op_Id := Get_Name_Entity_Id (Chars (N));
694 Set_Etype (N, Any_Type);
696 while Present (Op_Id) loop
697 if Ekind (Op_Id) = E_Operator
698 and then Present (Next_Entity (First_Entity (Op_Id)))
700 Find_Arithmetic_Types (L, R, Op_Id, N);
702 -- The following may seem superfluous, because an operator cannot
703 -- be generic, but this ignores the cleverness of the author of
706 elsif Is_Overloadable (Op_Id) then
707 Analyze_User_Defined_Binary_Op (N, Op_Id);
710 Op_Id := Homonym (Op_Id);
715 end Analyze_Arithmetic_Op;
721 -- Function, procedure, and entry calls are checked here. The Name in
722 -- the call may be overloaded. The actuals have been analyzed and may
723 -- themselves be overloaded. On exit from this procedure, the node N
724 -- may have zero, one or more interpretations. In the first case an
725 -- error message is produced. In the last case, the node is flagged
726 -- as overloaded and the interpretations are collected in All_Interp.
728 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
729 -- the type-checking is similar to that of other calls.
731 procedure Analyze_Call (N : Node_Id) is
732 Actuals : constant List_Id := Parameter_Associations (N);
737 Success : Boolean := False;
739 Deref : Boolean := False;
740 -- Flag indicates whether an interpretation of the prefix is a
741 -- parameterless call that returns an access_to_subprogram.
743 function Name_Denotes_Function return Boolean;
744 -- If the type of the name is an access to subprogram, this may be the
745 -- type of a name, or the return type of the function being called. If
746 -- the name is not an entity then it can denote a protected function.
747 -- Until we distinguish Etype from Return_Type, we must use this routine
748 -- to resolve the meaning of the name in the call.
750 procedure No_Interpretation;
751 -- Output error message when no valid interpretation exists
753 ---------------------------
754 -- Name_Denotes_Function --
755 ---------------------------
757 function Name_Denotes_Function return Boolean is
759 if Is_Entity_Name (Nam) then
760 return Ekind (Entity (Nam)) = E_Function;
762 elsif Nkind (Nam) = N_Selected_Component then
763 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
768 end Name_Denotes_Function;
770 -----------------------
771 -- No_Interpretation --
772 -----------------------
774 procedure No_Interpretation is
775 L : constant Boolean := Is_List_Member (N);
776 K : constant Node_Kind := Nkind (Parent (N));
779 -- If the node is in a list whose parent is not an expression then it
780 -- must be an attempted procedure call.
782 if L and then K not in N_Subexpr then
783 if Ekind (Entity (Nam)) = E_Generic_Procedure then
785 ("must instantiate generic procedure& before call",
789 ("procedure or entry name expected", Nam);
792 -- Check for tasking cases where only an entry call will do
795 and then Nkind_In (K, N_Entry_Call_Alternative,
796 N_Triggering_Alternative)
798 Error_Msg_N ("entry name expected", Nam);
800 -- Otherwise give general error message
803 Error_Msg_N ("invalid prefix in call", Nam);
805 end No_Interpretation;
807 -- Start of processing for Analyze_Call
810 -- Initialize the type of the result of the call to the error type,
811 -- which will be reset if the type is successfully resolved.
813 Set_Etype (N, Any_Type);
817 if not Is_Overloaded (Nam) then
819 -- Only one interpretation to check
821 if Ekind (Etype (Nam)) = E_Subprogram_Type then
822 Nam_Ent := Etype (Nam);
824 -- If the prefix is an access_to_subprogram, this may be an indirect
825 -- call. This is the case if the name in the call is not an entity
826 -- name, or if it is a function name in the context of a procedure
827 -- call. In this latter case, we have a call to a parameterless
828 -- function that returns a pointer_to_procedure which is the entity
829 -- being called. Finally, F (X) may be a call to a parameterless
830 -- function that returns a pointer to a function with parameters.
832 elsif Is_Access_Type (Etype (Nam))
833 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
835 (not Name_Denotes_Function
836 or else Nkind (N) = N_Procedure_Call_Statement
838 (Nkind (Parent (N)) /= N_Explicit_Dereference
839 and then Is_Entity_Name (Nam)
840 and then No (First_Formal (Entity (Nam)))
841 and then Present (Actuals)))
843 Nam_Ent := Designated_Type (Etype (Nam));
844 Insert_Explicit_Dereference (Nam);
846 -- Selected component case. Simple entry or protected operation,
847 -- where the entry name is given by the selector name.
849 elsif Nkind (Nam) = N_Selected_Component then
850 Nam_Ent := Entity (Selector_Name (Nam));
852 if not Ekind_In (Nam_Ent, E_Entry,
857 Error_Msg_N ("name in call is not a callable entity", Nam);
858 Set_Etype (N, Any_Type);
862 -- If the name is an Indexed component, it can be a call to a member
863 -- of an entry family. The prefix must be a selected component whose
864 -- selector is the entry. Analyze_Procedure_Call normalizes several
865 -- kinds of call into this form.
867 elsif Nkind (Nam) = N_Indexed_Component then
868 if Nkind (Prefix (Nam)) = N_Selected_Component then
869 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
871 Error_Msg_N ("name in call is not a callable entity", Nam);
872 Set_Etype (N, Any_Type);
876 elsif not Is_Entity_Name (Nam) then
877 Error_Msg_N ("name in call is not a callable entity", Nam);
878 Set_Etype (N, Any_Type);
882 Nam_Ent := Entity (Nam);
884 -- If no interpretations, give error message
886 if not Is_Overloadable (Nam_Ent) then
892 -- Operations generated for RACW stub types are called only through
893 -- dispatching, and can never be the static interpretation of a call.
895 if Is_RACW_Stub_Type_Operation (Nam_Ent) then
900 Analyze_One_Call (N, Nam_Ent, True, Success);
902 -- If this is an indirect call, the return type of the access_to
903 -- subprogram may be an incomplete type. At the point of the call,
904 -- use the full type if available, and at the same time update the
905 -- return type of the access_to_subprogram.
908 and then Nkind (Nam) = N_Explicit_Dereference
909 and then Ekind (Etype (N)) = E_Incomplete_Type
910 and then Present (Full_View (Etype (N)))
912 Set_Etype (N, Full_View (Etype (N)));
913 Set_Etype (Nam_Ent, Etype (N));
917 -- An overloaded selected component must denote overloaded operations
918 -- of a concurrent type. The interpretations are attached to the
919 -- simple name of those operations.
921 if Nkind (Nam) = N_Selected_Component then
922 Nam := Selector_Name (Nam);
925 Get_First_Interp (Nam, X, It);
927 while Present (It.Nam) loop
931 -- Name may be call that returns an access to subprogram, or more
932 -- generally an overloaded expression one of whose interpretations
933 -- yields an access to subprogram. If the name is an entity, we do
934 -- not dereference, because the node is a call that returns the
935 -- access type: note difference between f(x), where the call may
936 -- return an access subprogram type, and f(x)(y), where the type
937 -- returned by the call to f is implicitly dereferenced to analyze
940 if Is_Access_Type (Nam_Ent) then
941 Nam_Ent := Designated_Type (Nam_Ent);
943 elsif Is_Access_Type (Etype (Nam_Ent))
945 (not Is_Entity_Name (Nam)
946 or else Nkind (N) = N_Procedure_Call_Statement)
947 and then Ekind (Designated_Type (Etype (Nam_Ent)))
950 Nam_Ent := Designated_Type (Etype (Nam_Ent));
952 if Is_Entity_Name (Nam) then
957 -- If the call has been rewritten from a prefixed call, the first
958 -- parameter has been analyzed, but may need a subsequent
959 -- dereference, so skip its analysis now.
961 if N /= Original_Node (N)
962 and then Nkind (Original_Node (N)) = Nkind (N)
963 and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N)))
964 and then Present (Parameter_Associations (N))
965 and then Present (Etype (First (Parameter_Associations (N))))
968 (N, Nam_Ent, False, Success, Skip_First => True);
970 Analyze_One_Call (N, Nam_Ent, False, Success);
973 -- If the interpretation succeeds, mark the proper type of the
974 -- prefix (any valid candidate will do). If not, remove the
975 -- candidate interpretation. This only needs to be done for
976 -- overloaded protected operations, for other entities disambi-
977 -- guation is done directly in Resolve.
981 and then Nkind (Parent (N)) /= N_Explicit_Dereference
983 Set_Entity (Nam, It.Nam);
984 Insert_Explicit_Dereference (Nam);
985 Set_Etype (Nam, Nam_Ent);
988 Set_Etype (Nam, It.Typ);
991 elsif Nkind_In (Name (N), N_Selected_Component,
997 Get_Next_Interp (X, It);
1000 -- If the name is the result of a function call, it can only
1001 -- be a call to a function returning an access to subprogram.
1002 -- Insert explicit dereference.
1004 if Nkind (Nam) = N_Function_Call then
1005 Insert_Explicit_Dereference (Nam);
1008 if Etype (N) = Any_Type then
1010 -- None of the interpretations is compatible with the actuals
1012 Diagnose_Call (N, Nam);
1014 -- Special checks for uninstantiated put routines
1016 if Nkind (N) = N_Procedure_Call_Statement
1017 and then Is_Entity_Name (Nam)
1018 and then Chars (Nam) = Name_Put
1019 and then List_Length (Actuals) = 1
1022 Arg : constant Node_Id := First (Actuals);
1026 if Nkind (Arg) = N_Parameter_Association then
1027 Typ := Etype (Explicit_Actual_Parameter (Arg));
1032 if Is_Signed_Integer_Type (Typ) then
1034 ("possible missing instantiation of " &
1035 "'Text_'I'O.'Integer_'I'O!", Nam);
1037 elsif Is_Modular_Integer_Type (Typ) then
1039 ("possible missing instantiation of " &
1040 "'Text_'I'O.'Modular_'I'O!", Nam);
1042 elsif Is_Floating_Point_Type (Typ) then
1044 ("possible missing instantiation of " &
1045 "'Text_'I'O.'Float_'I'O!", Nam);
1047 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
1049 ("possible missing instantiation of " &
1050 "'Text_'I'O.'Fixed_'I'O!", Nam);
1052 elsif Is_Decimal_Fixed_Point_Type (Typ) then
1054 ("possible missing instantiation of " &
1055 "'Text_'I'O.'Decimal_'I'O!", Nam);
1057 elsif Is_Enumeration_Type (Typ) then
1059 ("possible missing instantiation of " &
1060 "'Text_'I'O.'Enumeration_'I'O!", Nam);
1065 elsif not Is_Overloaded (N)
1066 and then Is_Entity_Name (Nam)
1068 -- Resolution yields a single interpretation. Verify that the
1069 -- reference has capitalization consistent with the declaration.
1071 Set_Entity_With_Style_Check (Nam, Entity (Nam));
1072 Generate_Reference (Entity (Nam), Nam);
1074 Set_Etype (Nam, Etype (Entity (Nam)));
1076 Remove_Abstract_Operations (N);
1083 -----------------------------
1084 -- Analyze_Case_Expression --
1085 -----------------------------
1087 procedure Analyze_Case_Expression (N : Node_Id) is
1088 Expr : constant Node_Id := Expression (N);
1089 FirstX : constant Node_Id := Expression (First (Alternatives (N)));
1091 Exp_Type : Entity_Id;
1092 Exp_Btype : Entity_Id;
1095 Dont_Care : Boolean;
1096 Others_Present : Boolean;
1098 procedure Non_Static_Choice_Error (Choice : Node_Id);
1099 -- Error routine invoked by the generic instantiation below when
1100 -- the case expression has a non static choice.
1102 package Case_Choices_Processing is new
1103 Generic_Choices_Processing
1104 (Get_Alternatives => Alternatives,
1105 Get_Choices => Discrete_Choices,
1106 Process_Empty_Choice => No_OP,
1107 Process_Non_Static_Choice => Non_Static_Choice_Error,
1108 Process_Associated_Node => No_OP);
1109 use Case_Choices_Processing;
1111 Case_Table : Choice_Table_Type (1 .. Number_Of_Choices (N));
1113 -----------------------------
1114 -- Non_Static_Choice_Error --
1115 -----------------------------
1117 procedure Non_Static_Choice_Error (Choice : Node_Id) is
1119 Flag_Non_Static_Expr
1120 ("choice given in case expression is not static!", Choice);
1121 end Non_Static_Choice_Error;
1123 -- Start of processing for Analyze_Case_Expression
1126 if Comes_From_Source (N) then
1127 Check_Compiler_Unit (N);
1130 Analyze_And_Resolve (Expr, Any_Discrete);
1131 Check_Unset_Reference (Expr);
1132 Exp_Type := Etype (Expr);
1133 Exp_Btype := Base_Type (Exp_Type);
1135 Alt := First (Alternatives (N));
1136 while Present (Alt) loop
1137 Analyze (Expression (Alt));
1141 if not Is_Overloaded (FirstX) then
1142 Set_Etype (N, Etype (FirstX));
1150 Set_Etype (N, Any_Type);
1152 Get_First_Interp (FirstX, I, It);
1153 while Present (It.Nam) loop
1155 -- For each intepretation of the first expression, we only
1156 -- add the intepretation if every other expression in the
1157 -- case expression alternatives has a compatible type.
1159 Alt := Next (First (Alternatives (N)));
1160 while Present (Alt) loop
1161 exit when not Has_Compatible_Type (Expression (Alt), It.Typ);
1166 Add_One_Interp (N, It.Typ, It.Typ);
1169 Get_Next_Interp (I, It);
1174 Exp_Btype := Base_Type (Exp_Type);
1176 -- The expression must be of a discrete type which must be determinable
1177 -- independently of the context in which the expression occurs, but
1178 -- using the fact that the expression must be of a discrete type.
1179 -- Moreover, the type this expression must not be a character literal
1180 -- (which is always ambiguous).
1182 -- If error already reported by Resolve, nothing more to do
1184 if Exp_Btype = Any_Discrete
1185 or else Exp_Btype = Any_Type
1189 elsif Exp_Btype = Any_Character then
1191 ("character literal as case expression is ambiguous", Expr);
1195 -- If the case expression is a formal object of mode in out, then
1196 -- treat it as having a nonstatic subtype by forcing use of the base
1197 -- type (which has to get passed to Check_Case_Choices below). Also
1198 -- use base type when the case expression is parenthesized.
1200 if Paren_Count (Expr) > 0
1201 or else (Is_Entity_Name (Expr)
1202 and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter)
1204 Exp_Type := Exp_Btype;
1207 -- Call instantiated Analyze_Choices which does the rest of the work
1210 (N, Exp_Type, Case_Table, Last_Choice, Dont_Care, Others_Present);
1212 if Exp_Type = Universal_Integer and then not Others_Present then
1214 ("case on universal integer requires OTHERS choice", Expr);
1216 end Analyze_Case_Expression;
1218 ---------------------------
1219 -- Analyze_Comparison_Op --
1220 ---------------------------
1222 procedure Analyze_Comparison_Op (N : Node_Id) is
1223 L : constant Node_Id := Left_Opnd (N);
1224 R : constant Node_Id := Right_Opnd (N);
1225 Op_Id : Entity_Id := Entity (N);
1228 Set_Etype (N, Any_Type);
1229 Candidate_Type := Empty;
1231 Analyze_Expression (L);
1232 Analyze_Expression (R);
1234 if Present (Op_Id) then
1235 if Ekind (Op_Id) = E_Operator then
1236 Find_Comparison_Types (L, R, Op_Id, N);
1238 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1241 if Is_Overloaded (L) then
1242 Set_Etype (L, Intersect_Types (L, R));
1246 Op_Id := Get_Name_Entity_Id (Chars (N));
1247 while Present (Op_Id) loop
1248 if Ekind (Op_Id) = E_Operator then
1249 Find_Comparison_Types (L, R, Op_Id, N);
1251 Analyze_User_Defined_Binary_Op (N, Op_Id);
1254 Op_Id := Homonym (Op_Id);
1259 end Analyze_Comparison_Op;
1261 ---------------------------
1262 -- Analyze_Concatenation --
1263 ---------------------------
1265 procedure Analyze_Concatenation (N : Node_Id) is
1267 -- We wish to avoid deep recursion, because concatenations are often
1268 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1269 -- operands nonrecursively until we find something that is not a
1270 -- concatenation (A in this case), or has already been analyzed. We
1271 -- analyze that, and then walk back up the tree following Parent
1272 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1273 -- work at each level. The Parent pointers allow us to avoid recursion,
1274 -- and thus avoid running out of memory.
1280 Candidate_Type := Empty;
1282 -- The following code is equivalent to:
1284 -- Set_Etype (N, Any_Type);
1285 -- Analyze_Expression (Left_Opnd (N));
1286 -- Analyze_Concatenation_Rest (N);
1288 -- where the Analyze_Expression call recurses back here if the left
1289 -- operand is a concatenation.
1291 -- Walk down left operands
1294 Set_Etype (NN, Any_Type);
1295 L := Left_Opnd (NN);
1296 exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
1300 -- Now (given the above example) NN is A&B and L is A
1302 -- First analyze L ...
1304 Analyze_Expression (L);
1306 -- ... then walk NN back up until we reach N (where we started), calling
1307 -- Analyze_Concatenation_Rest along the way.
1310 Analyze_Concatenation_Rest (NN);
1314 end Analyze_Concatenation;
1316 --------------------------------
1317 -- Analyze_Concatenation_Rest --
1318 --------------------------------
1320 -- If the only one-dimensional array type in scope is String,
1321 -- this is the resulting type of the operation. Otherwise there
1322 -- will be a concatenation operation defined for each user-defined
1323 -- one-dimensional array.
1325 procedure Analyze_Concatenation_Rest (N : Node_Id) is
1326 L : constant Node_Id := Left_Opnd (N);
1327 R : constant Node_Id := Right_Opnd (N);
1328 Op_Id : Entity_Id := Entity (N);
1333 Analyze_Expression (R);
1335 -- If the entity is present, the node appears in an instance, and
1336 -- denotes a predefined concatenation operation. The resulting type is
1337 -- obtained from the arguments when possible. If the arguments are
1338 -- aggregates, the array type and the concatenation type must be
1341 if Present (Op_Id) then
1342 if Ekind (Op_Id) = E_Operator then
1343 LT := Base_Type (Etype (L));
1344 RT := Base_Type (Etype (R));
1346 if Is_Array_Type (LT)
1347 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1349 Add_One_Interp (N, Op_Id, LT);
1351 elsif Is_Array_Type (RT)
1352 and then LT = Base_Type (Component_Type (RT))
1354 Add_One_Interp (N, Op_Id, RT);
1356 -- If one operand is a string type or a user-defined array type,
1357 -- and the other is a literal, result is of the specific type.
1360 (Root_Type (LT) = Standard_String
1361 or else Scope (LT) /= Standard_Standard)
1362 and then Etype (R) = Any_String
1364 Add_One_Interp (N, Op_Id, LT);
1367 (Root_Type (RT) = Standard_String
1368 or else Scope (RT) /= Standard_Standard)
1369 and then Etype (L) = Any_String
1371 Add_One_Interp (N, Op_Id, RT);
1373 elsif not Is_Generic_Type (Etype (Op_Id)) then
1374 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1377 -- Type and its operations must be visible
1379 Set_Entity (N, Empty);
1380 Analyze_Concatenation (N);
1384 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1388 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1389 while Present (Op_Id) loop
1390 if Ekind (Op_Id) = E_Operator then
1392 -- Do not consider operators declared in dead code, they can
1393 -- not be part of the resolution.
1395 if Is_Eliminated (Op_Id) then
1398 Find_Concatenation_Types (L, R, Op_Id, N);
1402 Analyze_User_Defined_Binary_Op (N, Op_Id);
1405 Op_Id := Homonym (Op_Id);
1410 end Analyze_Concatenation_Rest;
1412 ------------------------------------
1413 -- Analyze_Conditional_Expression --
1414 ------------------------------------
1416 procedure Analyze_Conditional_Expression (N : Node_Id) is
1417 Condition : constant Node_Id := First (Expressions (N));
1418 Then_Expr : constant Node_Id := Next (Condition);
1419 Else_Expr : Node_Id;
1422 -- Defend against error of missing expressions from previous error
1424 if No (Then_Expr) then
1428 Else_Expr := Next (Then_Expr);
1430 if Comes_From_Source (N) then
1431 Check_Compiler_Unit (N);
1434 Analyze_Expression (Condition);
1435 Analyze_Expression (Then_Expr);
1437 if Present (Else_Expr) then
1438 Analyze_Expression (Else_Expr);
1441 -- If then expression not overloaded, then that decides the type
1443 if not Is_Overloaded (Then_Expr) then
1444 Set_Etype (N, Etype (Then_Expr));
1446 -- Case where then expression is overloaded
1454 Set_Etype (N, Any_Type);
1455 Get_First_Interp (Then_Expr, I, It);
1456 while Present (It.Nam) loop
1458 -- For each possible intepretation of the Then Expression,
1459 -- add it only if the else expression has a compatible type.
1461 -- Is this right if Else_Expr is empty?
1463 if Has_Compatible_Type (Else_Expr, It.Typ) then
1464 Add_One_Interp (N, It.Typ, It.Typ);
1467 Get_Next_Interp (I, It);
1471 end Analyze_Conditional_Expression;
1473 -------------------------
1474 -- Analyze_Equality_Op --
1475 -------------------------
1477 procedure Analyze_Equality_Op (N : Node_Id) is
1478 Loc : constant Source_Ptr := Sloc (N);
1479 L : constant Node_Id := Left_Opnd (N);
1480 R : constant Node_Id := Right_Opnd (N);
1484 Set_Etype (N, Any_Type);
1485 Candidate_Type := Empty;
1487 Analyze_Expression (L);
1488 Analyze_Expression (R);
1490 -- If the entity is set, the node is a generic instance with a non-local
1491 -- reference to the predefined operator or to a user-defined function.
1492 -- It can also be an inequality that is expanded into the negation of a
1493 -- call to a user-defined equality operator.
1495 -- For the predefined case, the result is Boolean, regardless of the
1496 -- type of the operands. The operands may even be limited, if they are
1497 -- generic actuals. If they are overloaded, label the left argument with
1498 -- the common type that must be present, or with the type of the formal
1499 -- of the user-defined function.
1501 if Present (Entity (N)) then
1502 Op_Id := Entity (N);
1504 if Ekind (Op_Id) = E_Operator then
1505 Add_One_Interp (N, Op_Id, Standard_Boolean);
1507 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1510 if Is_Overloaded (L) then
1511 if Ekind (Op_Id) = E_Operator then
1512 Set_Etype (L, Intersect_Types (L, R));
1514 Set_Etype (L, Etype (First_Formal (Op_Id)));
1519 Op_Id := Get_Name_Entity_Id (Chars (N));
1520 while Present (Op_Id) loop
1521 if Ekind (Op_Id) = E_Operator then
1522 Find_Equality_Types (L, R, Op_Id, N);
1524 Analyze_User_Defined_Binary_Op (N, Op_Id);
1527 Op_Id := Homonym (Op_Id);
1531 -- If there was no match, and the operator is inequality, this may
1532 -- be a case where inequality has not been made explicit, as for
1533 -- tagged types. Analyze the node as the negation of an equality
1534 -- operation. This cannot be done earlier, because before analysis
1535 -- we cannot rule out the presence of an explicit inequality.
1537 if Etype (N) = Any_Type
1538 and then Nkind (N) = N_Op_Ne
1540 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1541 while Present (Op_Id) loop
1542 if Ekind (Op_Id) = E_Operator then
1543 Find_Equality_Types (L, R, Op_Id, N);
1545 Analyze_User_Defined_Binary_Op (N, Op_Id);
1548 Op_Id := Homonym (Op_Id);
1551 if Etype (N) /= Any_Type then
1552 Op_Id := Entity (N);
1558 Left_Opnd => Left_Opnd (N),
1559 Right_Opnd => Right_Opnd (N))));
1561 Set_Entity (Right_Opnd (N), Op_Id);
1567 end Analyze_Equality_Op;
1569 ----------------------------------
1570 -- Analyze_Explicit_Dereference --
1571 ----------------------------------
1573 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1574 Loc : constant Source_Ptr := Sloc (N);
1575 P : constant Node_Id := Prefix (N);
1581 function Is_Function_Type return Boolean;
1582 -- Check whether node may be interpreted as an implicit function call
1584 ----------------------
1585 -- Is_Function_Type --
1586 ----------------------
1588 function Is_Function_Type return Boolean is
1593 if not Is_Overloaded (N) then
1594 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1595 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1598 Get_First_Interp (N, I, It);
1599 while Present (It.Nam) loop
1600 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1601 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1606 Get_Next_Interp (I, It);
1611 end Is_Function_Type;
1613 -- Start of processing for Analyze_Explicit_Dereference
1617 Set_Etype (N, Any_Type);
1619 -- Test for remote access to subprogram type, and if so return
1620 -- after rewriting the original tree.
1622 if Remote_AST_E_Dereference (P) then
1626 -- Normal processing for other than remote access to subprogram type
1628 if not Is_Overloaded (P) then
1629 if Is_Access_Type (Etype (P)) then
1631 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
1632 -- avoid other problems caused by the Private_Subtype and it is
1633 -- safe to go to the Base_Type because this is the same as
1634 -- converting the access value to its Base_Type.
1637 DT : Entity_Id := Designated_Type (Etype (P));
1640 if Ekind (DT) = E_Private_Subtype
1641 and then Is_For_Access_Subtype (DT)
1643 DT := Base_Type (DT);
1646 -- An explicit dereference is a legal occurrence of an
1647 -- incomplete type imported through a limited_with clause,
1648 -- if the full view is visible.
1650 if From_With_Type (DT)
1651 and then not From_With_Type (Scope (DT))
1653 (Is_Immediately_Visible (Scope (DT))
1655 (Is_Child_Unit (Scope (DT))
1656 and then Is_Visible_Child_Unit (Scope (DT))))
1658 Set_Etype (N, Available_View (DT));
1665 elsif Etype (P) /= Any_Type then
1666 Error_Msg_N ("prefix of dereference must be an access type", N);
1671 Get_First_Interp (P, I, It);
1672 while Present (It.Nam) loop
1675 if Is_Access_Type (T) then
1676 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1679 Get_Next_Interp (I, It);
1682 -- Error if no interpretation of the prefix has an access type
1684 if Etype (N) = Any_Type then
1686 ("access type required in prefix of explicit dereference", P);
1687 Set_Etype (N, Any_Type);
1693 and then Nkind (Parent (N)) /= N_Indexed_Component
1695 and then (Nkind (Parent (N)) /= N_Function_Call
1696 or else N /= Name (Parent (N)))
1698 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1699 or else N /= Name (Parent (N)))
1701 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1702 and then (Nkind (Parent (N)) /= N_Attribute_Reference
1704 (Attribute_Name (Parent (N)) /= Name_Address
1706 Attribute_Name (Parent (N)) /= Name_Access))
1708 -- Name is a function call with no actuals, in a context that
1709 -- requires deproceduring (including as an actual in an enclosing
1710 -- function or procedure call). There are some pathological cases
1711 -- where the prefix might include functions that return access to
1712 -- subprograms and others that return a regular type. Disambiguation
1713 -- of those has to take place in Resolve.
1716 Make_Function_Call (Loc,
1717 Name => Make_Explicit_Dereference (Loc, P),
1718 Parameter_Associations => New_List);
1720 -- If the prefix is overloaded, remove operations that have formals,
1721 -- we know that this is a parameterless call.
1723 if Is_Overloaded (P) then
1724 Get_First_Interp (P, I, It);
1725 while Present (It.Nam) loop
1728 if No (First_Formal (Base_Type (Designated_Type (T)))) then
1734 Get_Next_Interp (I, It);
1741 elsif not Is_Function_Type
1742 and then Is_Overloaded (N)
1744 -- The prefix may include access to subprograms and other access
1745 -- types. If the context selects the interpretation that is a
1746 -- function call (not a procedure call) we cannot rewrite the node
1747 -- yet, but we include the result of the call interpretation.
1749 Get_First_Interp (N, I, It);
1750 while Present (It.Nam) loop
1751 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
1752 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
1753 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
1755 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
1758 Get_Next_Interp (I, It);
1762 -- A value of remote access-to-class-wide must not be dereferenced
1765 Validate_Remote_Access_To_Class_Wide_Type (N);
1766 end Analyze_Explicit_Dereference;
1768 ------------------------
1769 -- Analyze_Expression --
1770 ------------------------
1772 procedure Analyze_Expression (N : Node_Id) is
1775 Check_Parameterless_Call (N);
1776 end Analyze_Expression;
1778 -------------------------------------
1779 -- Analyze_Expression_With_Actions --
1780 -------------------------------------
1782 procedure Analyze_Expression_With_Actions (N : Node_Id) is
1786 A := First (Actions (N));
1793 Analyze_Expression (Expression (N));
1794 Set_Etype (N, Etype (Expression (N)));
1795 end Analyze_Expression_With_Actions;
1797 ------------------------------------
1798 -- Analyze_Indexed_Component_Form --
1799 ------------------------------------
1801 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
1802 P : constant Node_Id := Prefix (N);
1803 Exprs : constant List_Id := Expressions (N);
1809 procedure Process_Function_Call;
1810 -- Prefix in indexed component form is an overloadable entity,
1811 -- so the node is a function call. Reformat it as such.
1813 procedure Process_Indexed_Component;
1814 -- Prefix in indexed component form is actually an indexed component.
1815 -- This routine processes it, knowing that the prefix is already
1818 procedure Process_Indexed_Component_Or_Slice;
1819 -- An indexed component with a single index may designate a slice if
1820 -- the index is a subtype mark. This routine disambiguates these two
1821 -- cases by resolving the prefix to see if it is a subtype mark.
1823 procedure Process_Overloaded_Indexed_Component;
1824 -- If the prefix of an indexed component is overloaded, the proper
1825 -- interpretation is selected by the index types and the context.
1827 ---------------------------
1828 -- Process_Function_Call --
1829 ---------------------------
1831 procedure Process_Function_Call is
1835 Change_Node (N, N_Function_Call);
1837 Set_Parameter_Associations (N, Exprs);
1839 -- Analyze actuals prior to analyzing the call itself
1841 Actual := First (Parameter_Associations (N));
1842 while Present (Actual) loop
1844 Check_Parameterless_Call (Actual);
1846 -- Move to next actual. Note that we use Next, not Next_Actual
1847 -- here. The reason for this is a bit subtle. If a function call
1848 -- includes named associations, the parser recognizes the node as
1849 -- a call, and it is analyzed as such. If all associations are
1850 -- positional, the parser builds an indexed_component node, and
1851 -- it is only after analysis of the prefix that the construct
1852 -- is recognized as a call, in which case Process_Function_Call
1853 -- rewrites the node and analyzes the actuals. If the list of
1854 -- actuals is malformed, the parser may leave the node as an
1855 -- indexed component (despite the presence of named associations).
1856 -- The iterator Next_Actual is equivalent to Next if the list is
1857 -- positional, but follows the normalized chain of actuals when
1858 -- named associations are present. In this case normalization has
1859 -- not taken place, and actuals remain unanalyzed, which leads to
1860 -- subsequent crashes or loops if there is an attempt to continue
1861 -- analysis of the program.
1867 end Process_Function_Call;
1869 -------------------------------
1870 -- Process_Indexed_Component --
1871 -------------------------------
1873 procedure Process_Indexed_Component is
1875 Array_Type : Entity_Id;
1877 Pent : Entity_Id := Empty;
1880 Exp := First (Exprs);
1882 if Is_Overloaded (P) then
1883 Process_Overloaded_Indexed_Component;
1886 Array_Type := Etype (P);
1888 if Is_Entity_Name (P) then
1890 elsif Nkind (P) = N_Selected_Component
1891 and then Is_Entity_Name (Selector_Name (P))
1893 Pent := Entity (Selector_Name (P));
1896 -- Prefix must be appropriate for an array type, taking into
1897 -- account a possible implicit dereference.
1899 if Is_Access_Type (Array_Type) then
1900 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1901 Array_Type := Process_Implicit_Dereference_Prefix (Pent, P);
1904 if Is_Array_Type (Array_Type) then
1907 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
1909 Set_Etype (N, Any_Type);
1911 if not Has_Compatible_Type
1912 (Exp, Entry_Index_Type (Pent))
1914 Error_Msg_N ("invalid index type in entry name", N);
1916 elsif Present (Next (Exp)) then
1917 Error_Msg_N ("too many subscripts in entry reference", N);
1920 Set_Etype (N, Etype (P));
1925 elsif Is_Record_Type (Array_Type)
1926 and then Remote_AST_I_Dereference (P)
1930 elsif Array_Type = Any_Type then
1931 Set_Etype (N, Any_Type);
1933 -- In most cases the analysis of the prefix will have emitted
1934 -- an error already, but if the prefix may be interpreted as a
1935 -- call in prefixed notation, the report is left to the caller.
1936 -- To prevent cascaded errors, report only if no previous ones.
1938 if Serious_Errors_Detected = 0 then
1939 Error_Msg_N ("invalid prefix in indexed component", P);
1941 if Nkind (P) = N_Expanded_Name then
1942 Error_Msg_NE ("\& is not visible", P, Selector_Name (P));
1948 -- Here we definitely have a bad indexing
1951 if Nkind (Parent (N)) = N_Requeue_Statement
1952 and then Present (Pent) and then Ekind (Pent) = E_Entry
1955 ("REQUEUE does not permit parameters", First (Exprs));
1957 elsif Is_Entity_Name (P)
1958 and then Etype (P) = Standard_Void_Type
1960 Error_Msg_NE ("incorrect use of&", P, Entity (P));
1963 Error_Msg_N ("array type required in indexed component", P);
1966 Set_Etype (N, Any_Type);
1970 Index := First_Index (Array_Type);
1971 while Present (Index) and then Present (Exp) loop
1972 if not Has_Compatible_Type (Exp, Etype (Index)) then
1973 Wrong_Type (Exp, Etype (Index));
1974 Set_Etype (N, Any_Type);
1982 Set_Etype (N, Component_Type (Array_Type));
1984 if Present (Index) then
1986 ("too few subscripts in array reference", First (Exprs));
1988 elsif Present (Exp) then
1989 Error_Msg_N ("too many subscripts in array reference", Exp);
1992 end Process_Indexed_Component;
1994 ----------------------------------------
1995 -- Process_Indexed_Component_Or_Slice --
1996 ----------------------------------------
1998 procedure Process_Indexed_Component_Or_Slice is
2000 Exp := First (Exprs);
2001 while Present (Exp) loop
2002 Analyze_Expression (Exp);
2006 Exp := First (Exprs);
2008 -- If one index is present, and it is a subtype name, then the
2009 -- node denotes a slice (note that the case of an explicit range
2010 -- for a slice was already built as an N_Slice node in the first
2011 -- place, so that case is not handled here).
2013 -- We use a replace rather than a rewrite here because this is one
2014 -- of the cases in which the tree built by the parser is plain wrong.
2017 and then Is_Entity_Name (Exp)
2018 and then Is_Type (Entity (Exp))
2021 Make_Slice (Sloc (N),
2023 Discrete_Range => New_Copy (Exp)));
2026 -- Otherwise (more than one index present, or single index is not
2027 -- a subtype name), then we have the indexed component case.
2030 Process_Indexed_Component;
2032 end Process_Indexed_Component_Or_Slice;
2034 ------------------------------------------
2035 -- Process_Overloaded_Indexed_Component --
2036 ------------------------------------------
2038 procedure Process_Overloaded_Indexed_Component is
2047 Set_Etype (N, Any_Type);
2049 Get_First_Interp (P, I, It);
2050 while Present (It.Nam) loop
2053 if Is_Access_Type (Typ) then
2054 Typ := Designated_Type (Typ);
2055 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2058 if Is_Array_Type (Typ) then
2060 -- Got a candidate: verify that index types are compatible
2062 Index := First_Index (Typ);
2064 Exp := First (Exprs);
2065 while Present (Index) and then Present (Exp) loop
2066 if Has_Compatible_Type (Exp, Etype (Index)) then
2078 if Found and then No (Index) and then No (Exp) then
2080 Etype (Component_Type (Typ)),
2081 Etype (Component_Type (Typ)));
2085 Get_Next_Interp (I, It);
2088 if Etype (N) = Any_Type then
2089 Error_Msg_N ("no legal interpretation for indexed component", N);
2090 Set_Is_Overloaded (N, False);
2094 end Process_Overloaded_Indexed_Component;
2096 -- Start of processing for Analyze_Indexed_Component_Form
2099 -- Get name of array, function or type
2103 if Nkind_In (N, N_Function_Call, N_Procedure_Call_Statement) then
2105 -- If P is an explicit dereference whose prefix is of a
2106 -- remote access-to-subprogram type, then N has already
2107 -- been rewritten as a subprogram call and analyzed.
2112 pragma Assert (Nkind (N) = N_Indexed_Component);
2114 P_T := Base_Type (Etype (P));
2116 if Is_Entity_Name (P) then
2119 if Is_Type (U_N) then
2121 -- Reformat node as a type conversion
2123 E := Remove_Head (Exprs);
2125 if Present (First (Exprs)) then
2127 ("argument of type conversion must be single expression", N);
2130 Change_Node (N, N_Type_Conversion);
2131 Set_Subtype_Mark (N, P);
2133 Set_Expression (N, E);
2135 -- After changing the node, call for the specific Analysis
2136 -- routine directly, to avoid a double call to the expander.
2138 Analyze_Type_Conversion (N);
2142 if Is_Overloadable (U_N) then
2143 Process_Function_Call;
2145 elsif Ekind (Etype (P)) = E_Subprogram_Type
2146 or else (Is_Access_Type (Etype (P))
2148 Ekind (Designated_Type (Etype (P))) =
2151 -- Call to access_to-subprogram with possible implicit dereference
2153 Process_Function_Call;
2155 elsif Is_Generic_Subprogram (U_N) then
2157 -- A common beginner's (or C++ templates fan) error
2159 Error_Msg_N ("generic subprogram cannot be called", N);
2160 Set_Etype (N, Any_Type);
2164 Process_Indexed_Component_Or_Slice;
2167 -- If not an entity name, prefix is an expression that may denote
2168 -- an array or an access-to-subprogram.
2171 if Ekind (P_T) = E_Subprogram_Type
2172 or else (Is_Access_Type (P_T)
2174 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
2176 Process_Function_Call;
2178 elsif Nkind (P) = N_Selected_Component
2179 and then Is_Overloadable (Entity (Selector_Name (P)))
2181 Process_Function_Call;
2184 -- Indexed component, slice, or a call to a member of a family
2185 -- entry, which will be converted to an entry call later.
2187 Process_Indexed_Component_Or_Slice;
2190 end Analyze_Indexed_Component_Form;
2192 ------------------------
2193 -- Analyze_Logical_Op --
2194 ------------------------
2196 procedure Analyze_Logical_Op (N : Node_Id) is
2197 L : constant Node_Id := Left_Opnd (N);
2198 R : constant Node_Id := Right_Opnd (N);
2199 Op_Id : Entity_Id := Entity (N);
2202 Set_Etype (N, Any_Type);
2203 Candidate_Type := Empty;
2205 Analyze_Expression (L);
2206 Analyze_Expression (R);
2208 if Present (Op_Id) then
2210 if Ekind (Op_Id) = E_Operator then
2211 Find_Boolean_Types (L, R, Op_Id, N);
2213 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2217 Op_Id := Get_Name_Entity_Id (Chars (N));
2218 while Present (Op_Id) loop
2219 if Ekind (Op_Id) = E_Operator then
2220 Find_Boolean_Types (L, R, Op_Id, N);
2222 Analyze_User_Defined_Binary_Op (N, Op_Id);
2225 Op_Id := Homonym (Op_Id);
2230 end Analyze_Logical_Op;
2232 ---------------------------
2233 -- Analyze_Membership_Op --
2234 ---------------------------
2236 procedure Analyze_Membership_Op (N : Node_Id) is
2237 L : constant Node_Id := Left_Opnd (N);
2238 R : constant Node_Id := Right_Opnd (N);
2240 Index : Interp_Index;
2242 Found : Boolean := False;
2246 procedure Try_One_Interp (T1 : Entity_Id);
2247 -- Routine to try one proposed interpretation. Note that the context
2248 -- of the operation plays no role in resolving the arguments, so that
2249 -- if there is more than one interpretation of the operands that is
2250 -- compatible with a membership test, the operation is ambiguous.
2252 --------------------
2253 -- Try_One_Interp --
2254 --------------------
2256 procedure Try_One_Interp (T1 : Entity_Id) is
2258 if Has_Compatible_Type (R, T1) then
2260 and then Base_Type (T1) /= Base_Type (T_F)
2262 It := Disambiguate (L, I_F, Index, Any_Type);
2264 if It = No_Interp then
2265 Ambiguous_Operands (N);
2266 Set_Etype (L, Any_Type);
2283 procedure Analyze_Set_Membership;
2284 -- If a set of alternatives is present, analyze each and find the
2285 -- common type to which they must all resolve.
2287 ----------------------------
2288 -- Analyze_Set_Membership --
2289 ----------------------------
2291 procedure Analyze_Set_Membership is
2293 Index : Interp_Index;
2295 Candidate_Interps : Node_Id;
2296 Common_Type : Entity_Id := Empty;
2300 Candidate_Interps := L;
2302 if not Is_Overloaded (L) then
2303 Common_Type := Etype (L);
2305 Alt := First (Alternatives (N));
2306 while Present (Alt) loop
2309 if not Has_Compatible_Type (Alt, Common_Type) then
2310 Wrong_Type (Alt, Common_Type);
2317 Alt := First (Alternatives (N));
2318 while Present (Alt) loop
2320 if not Is_Overloaded (Alt) then
2321 Common_Type := Etype (Alt);
2324 Get_First_Interp (Alt, Index, It);
2325 while Present (It.Typ) loop
2327 Has_Compatible_Type (Candidate_Interps, It.Typ)
2329 Remove_Interp (Index);
2332 Get_Next_Interp (Index, It);
2335 Get_First_Interp (Alt, Index, It);
2338 Error_Msg_N ("alternative has no legal type", Alt);
2342 -- If alternative is not overloaded, we have a unique type
2345 Set_Etype (Alt, It.Typ);
2346 Get_Next_Interp (Index, It);
2349 Set_Is_Overloaded (Alt, False);
2350 Common_Type := Etype (Alt);
2353 Candidate_Interps := Alt;
2360 Set_Etype (N, Standard_Boolean);
2362 if Present (Common_Type) then
2363 Set_Etype (L, Common_Type);
2364 Set_Is_Overloaded (L, False);
2367 Error_Msg_N ("cannot resolve membership operation", N);
2369 end Analyze_Set_Membership;
2371 -- Start of processing for Analyze_Membership_Op
2374 Analyze_Expression (L);
2377 and then Ada_Version >= Ada_12
2379 Analyze_Set_Membership;
2383 if Nkind (R) = N_Range
2384 or else (Nkind (R) = N_Attribute_Reference
2385 and then Attribute_Name (R) = Name_Range)
2389 if not Is_Overloaded (L) then
2390 Try_One_Interp (Etype (L));
2393 Get_First_Interp (L, Index, It);
2394 while Present (It.Typ) loop
2395 Try_One_Interp (It.Typ);
2396 Get_Next_Interp (Index, It);
2400 -- If not a range, it can only be a subtype mark, or else there
2401 -- is a more basic error, to be diagnosed in Find_Type.
2406 if Is_Entity_Name (R) then
2407 Check_Fully_Declared (Entity (R), R);
2411 -- Compatibility between expression and subtype mark or range is
2412 -- checked during resolution. The result of the operation is Boolean
2415 Set_Etype (N, Standard_Boolean);
2417 if Comes_From_Source (N)
2418 and then Present (Right_Opnd (N))
2419 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
2421 Error_Msg_N ("membership test not applicable to cpp-class types", N);
2423 end Analyze_Membership_Op;
2425 ----------------------
2426 -- Analyze_Negation --
2427 ----------------------
2429 procedure Analyze_Negation (N : Node_Id) is
2430 R : constant Node_Id := Right_Opnd (N);
2431 Op_Id : Entity_Id := Entity (N);
2434 Set_Etype (N, Any_Type);
2435 Candidate_Type := Empty;
2437 Analyze_Expression (R);
2439 if Present (Op_Id) then
2440 if Ekind (Op_Id) = E_Operator then
2441 Find_Negation_Types (R, Op_Id, N);
2443 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2447 Op_Id := Get_Name_Entity_Id (Chars (N));
2448 while Present (Op_Id) loop
2449 if Ekind (Op_Id) = E_Operator then
2450 Find_Negation_Types (R, Op_Id, N);
2452 Analyze_User_Defined_Unary_Op (N, Op_Id);
2455 Op_Id := Homonym (Op_Id);
2460 end Analyze_Negation;
2466 procedure Analyze_Null (N : Node_Id) is
2468 Set_Etype (N, Any_Access);
2471 ----------------------
2472 -- Analyze_One_Call --
2473 ----------------------
2475 procedure Analyze_One_Call
2479 Success : out Boolean;
2480 Skip_First : Boolean := False)
2482 Actuals : constant List_Id := Parameter_Associations (N);
2483 Prev_T : constant Entity_Id := Etype (N);
2485 Must_Skip : constant Boolean := Skip_First
2486 or else Nkind (Original_Node (N)) = N_Selected_Component
2488 (Nkind (Original_Node (N)) = N_Indexed_Component
2489 and then Nkind (Prefix (Original_Node (N)))
2490 = N_Selected_Component);
2491 -- The first formal must be omitted from the match when trying to find
2492 -- a primitive operation that is a possible interpretation, and also
2493 -- after the call has been rewritten, because the corresponding actual
2494 -- is already known to be compatible, and because this may be an
2495 -- indexing of a call with default parameters.
2499 Is_Indexed : Boolean := False;
2500 Is_Indirect : Boolean := False;
2501 Subp_Type : constant Entity_Id := Etype (Nam);
2504 function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
2505 -- There may be a user-defined operator that hides the current
2506 -- interpretation. We must check for this independently of the
2507 -- analysis of the call with the user-defined operation, because
2508 -- the parameter names may be wrong and yet the hiding takes place.
2509 -- This fixes a problem with ACATS test B34014O.
2511 -- When the type Address is a visible integer type, and the DEC
2512 -- system extension is visible, the predefined operator may be
2513 -- hidden as well, by one of the address operations in auxdec.
2514 -- Finally, The abstract operations on address do not hide the
2515 -- predefined operator (this is the purpose of making them abstract).
2517 procedure Indicate_Name_And_Type;
2518 -- If candidate interpretation matches, indicate name and type of
2519 -- result on call node.
2521 ----------------------------
2522 -- Indicate_Name_And_Type --
2523 ----------------------------
2525 procedure Indicate_Name_And_Type is
2527 Add_One_Interp (N, Nam, Etype (Nam));
2530 -- If the prefix of the call is a name, indicate the entity
2531 -- being called. If it is not a name, it is an expression that
2532 -- denotes an access to subprogram or else an entry or family. In
2533 -- the latter case, the name is a selected component, and the entity
2534 -- being called is noted on the selector.
2536 if not Is_Type (Nam) then
2537 if Is_Entity_Name (Name (N)) then
2538 Set_Entity (Name (N), Nam);
2540 elsif Nkind (Name (N)) = N_Selected_Component then
2541 Set_Entity (Selector_Name (Name (N)), Nam);
2545 if Debug_Flag_E and not Report then
2546 Write_Str (" Overloaded call ");
2547 Write_Int (Int (N));
2548 Write_Str (" compatible with ");
2549 Write_Int (Int (Nam));
2552 end Indicate_Name_And_Type;
2554 ------------------------
2555 -- Operator_Hidden_By --
2556 ------------------------
2558 function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
2559 Act1 : constant Node_Id := First_Actual (N);
2560 Act2 : constant Node_Id := Next_Actual (Act1);
2561 Form1 : constant Entity_Id := First_Formal (Fun);
2562 Form2 : constant Entity_Id := Next_Formal (Form1);
2565 if Ekind (Fun) /= E_Function
2566 or else Is_Abstract_Subprogram (Fun)
2570 elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
2573 elsif Present (Form2) then
2575 No (Act2) or else not Has_Compatible_Type (Act2, Etype (Form2))
2580 elsif Present (Act2) then
2584 -- Now we know that the arity of the operator matches the function,
2585 -- and the function call is a valid interpretation. The function
2586 -- hides the operator if it has the right signature, or if one of
2587 -- its operands is a non-abstract operation on Address when this is
2588 -- a visible integer type.
2590 return Hides_Op (Fun, Nam)
2591 or else Is_Descendent_Of_Address (Etype (Form1))
2594 and then Is_Descendent_Of_Address (Etype (Form2)));
2595 end Operator_Hidden_By;
2597 -- Start of processing for Analyze_One_Call
2602 -- If the subprogram has no formals or if all the formals have defaults,
2603 -- and the return type is an array type, the node may denote an indexing
2604 -- of the result of a parameterless call. In Ada 2005, the subprogram
2605 -- may have one non-defaulted formal, and the call may have been written
2606 -- in prefix notation, so that the rebuilt parameter list has more than
2609 if not Is_Overloadable (Nam)
2610 and then Ekind (Nam) /= E_Subprogram_Type
2611 and then Ekind (Nam) /= E_Entry_Family
2616 -- An indexing requires at least one actual
2618 if not Is_Empty_List (Actuals)
2620 (Needs_No_Actuals (Nam)
2622 (Needs_One_Actual (Nam)
2623 and then Present (Next_Actual (First (Actuals)))))
2625 if Is_Array_Type (Subp_Type) then
2626 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
2628 elsif Is_Access_Type (Subp_Type)
2629 and then Is_Array_Type (Designated_Type (Subp_Type))
2633 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
2635 -- The prefix can also be a parameterless function that returns an
2636 -- access to subprogram, in which case this is an indirect call.
2637 -- If this succeeds, an explicit dereference is added later on,
2638 -- in Analyze_Call or Resolve_Call.
2640 elsif Is_Access_Type (Subp_Type)
2641 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
2643 Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
2648 -- If the call has been transformed into a slice, it is of the form
2649 -- F (Subtype) where F is parameterless. The node has been rewritten in
2650 -- Try_Indexed_Call and there is nothing else to do.
2653 and then Nkind (N) = N_Slice
2659 (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
2663 -- If an indirect call is a possible interpretation, indicate
2664 -- success to the caller.
2670 -- Mismatch in number or names of parameters
2672 elsif Debug_Flag_E then
2673 Write_Str (" normalization fails in call ");
2674 Write_Int (Int (N));
2675 Write_Str (" with subprogram ");
2676 Write_Int (Int (Nam));
2680 -- If the context expects a function call, discard any interpretation
2681 -- that is a procedure. If the node is not overloaded, leave as is for
2682 -- better error reporting when type mismatch is found.
2684 elsif Nkind (N) = N_Function_Call
2685 and then Is_Overloaded (Name (N))
2686 and then Ekind (Nam) = E_Procedure
2690 -- Ditto for function calls in a procedure context
2692 elsif Nkind (N) = N_Procedure_Call_Statement
2693 and then Is_Overloaded (Name (N))
2694 and then Etype (Nam) /= Standard_Void_Type
2698 elsif No (Actuals) then
2700 -- If Normalize succeeds, then there are default parameters for
2703 Indicate_Name_And_Type;
2705 elsif Ekind (Nam) = E_Operator then
2706 if Nkind (N) = N_Procedure_Call_Statement then
2710 -- This can occur when the prefix of the call is an operator
2711 -- name or an expanded name whose selector is an operator name.
2713 Analyze_Operator_Call (N, Nam);
2715 if Etype (N) /= Prev_T then
2717 -- Check that operator is not hidden by a function interpretation
2719 if Is_Overloaded (Name (N)) then
2725 Get_First_Interp (Name (N), I, It);
2726 while Present (It.Nam) loop
2727 if Operator_Hidden_By (It.Nam) then
2728 Set_Etype (N, Prev_T);
2732 Get_Next_Interp (I, It);
2737 -- If operator matches formals, record its name on the call.
2738 -- If the operator is overloaded, Resolve will select the
2739 -- correct one from the list of interpretations. The call
2740 -- node itself carries the first candidate.
2742 Set_Entity (Name (N), Nam);
2745 elsif Report and then Etype (N) = Any_Type then
2746 Error_Msg_N ("incompatible arguments for operator", N);
2750 -- Normalize_Actuals has chained the named associations in the
2751 -- correct order of the formals.
2753 Actual := First_Actual (N);
2754 Formal := First_Formal (Nam);
2756 -- If we are analyzing a call rewritten from object notation,
2757 -- skip first actual, which may be rewritten later as an
2758 -- explicit dereference.
2761 Next_Actual (Actual);
2762 Next_Formal (Formal);
2765 while Present (Actual) and then Present (Formal) loop
2766 if Nkind (Parent (Actual)) /= N_Parameter_Association
2767 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
2769 -- The actual can be compatible with the formal, but we must
2770 -- also check that the context is not an address type that is
2771 -- visibly an integer type, as is the case in VMS_64. In this
2772 -- case the use of literals is illegal, except in the body of
2773 -- descendents of system, where arithmetic operations on
2774 -- address are of course used.
2776 if Has_Compatible_Type (Actual, Etype (Formal))
2778 (Etype (Actual) /= Universal_Integer
2779 or else not Is_Descendent_Of_Address (Etype (Formal))
2781 Is_Predefined_File_Name
2782 (Unit_File_Name (Get_Source_Unit (N))))
2784 Next_Actual (Actual);
2785 Next_Formal (Formal);
2788 if Debug_Flag_E then
2789 Write_Str (" type checking fails in call ");
2790 Write_Int (Int (N));
2791 Write_Str (" with formal ");
2792 Write_Int (Int (Formal));
2793 Write_Str (" in subprogram ");
2794 Write_Int (Int (Nam));
2798 if Report and not Is_Indexed and not Is_Indirect then
2800 -- Ada 2005 (AI-251): Complete the error notification
2801 -- to help new Ada 2005 users.
2803 if Is_Class_Wide_Type (Etype (Formal))
2804 and then Is_Interface (Etype (Etype (Formal)))
2805 and then not Interface_Present_In_Ancestor
2806 (Typ => Etype (Actual),
2807 Iface => Etype (Etype (Formal)))
2810 ("(Ada 2005) does not implement interface }",
2811 Actual, Etype (Etype (Formal)));
2814 Wrong_Type (Actual, Etype (Formal));
2816 if Nkind (Actual) = N_Op_Eq
2817 and then Nkind (Left_Opnd (Actual)) = N_Identifier
2819 Formal := First_Formal (Nam);
2820 while Present (Formal) loop
2821 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
2822 Error_Msg_N -- CODEFIX
2823 ("possible misspelling of `='>`!", Actual);
2827 Next_Formal (Formal);
2831 if All_Errors_Mode then
2832 Error_Msg_Sloc := Sloc (Nam);
2834 if Is_Overloadable (Nam)
2835 and then Present (Alias (Nam))
2836 and then not Comes_From_Source (Nam)
2839 ("\\ =='> in call to inherited operation & #!",
2842 elsif Ekind (Nam) = E_Subprogram_Type then
2844 Access_To_Subprogram_Typ :
2845 constant Entity_Id :=
2847 (Associated_Node_For_Itype (Nam));
2850 "\\ =='> in call to dereference of &#!",
2851 Actual, Access_To_Subprogram_Typ);
2856 ("\\ =='> in call to &#!", Actual, Nam);
2866 -- Normalize_Actuals has verified that a default value exists
2867 -- for this formal. Current actual names a subsequent formal.
2869 Next_Formal (Formal);
2873 -- On exit, all actuals match
2875 Indicate_Name_And_Type;
2877 end Analyze_One_Call;
2879 ---------------------------
2880 -- Analyze_Operator_Call --
2881 ---------------------------
2883 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
2884 Op_Name : constant Name_Id := Chars (Op_Id);
2885 Act1 : constant Node_Id := First_Actual (N);
2886 Act2 : constant Node_Id := Next_Actual (Act1);
2889 -- Binary operator case
2891 if Present (Act2) then
2893 -- If more than two operands, then not binary operator after all
2895 if Present (Next_Actual (Act2)) then
2898 elsif Op_Name = Name_Op_Add
2899 or else Op_Name = Name_Op_Subtract
2900 or else Op_Name = Name_Op_Multiply
2901 or else Op_Name = Name_Op_Divide
2902 or else Op_Name = Name_Op_Mod
2903 or else Op_Name = Name_Op_Rem
2904 or else Op_Name = Name_Op_Expon
2906 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
2908 elsif Op_Name = Name_Op_And
2909 or else Op_Name = Name_Op_Or
2910 or else Op_Name = Name_Op_Xor
2912 Find_Boolean_Types (Act1, Act2, Op_Id, N);
2914 elsif Op_Name = Name_Op_Lt
2915 or else Op_Name = Name_Op_Le
2916 or else Op_Name = Name_Op_Gt
2917 or else Op_Name = Name_Op_Ge
2919 Find_Comparison_Types (Act1, Act2, Op_Id, N);
2921 elsif Op_Name = Name_Op_Eq
2922 or else Op_Name = Name_Op_Ne
2924 Find_Equality_Types (Act1, Act2, Op_Id, N);
2926 elsif Op_Name = Name_Op_Concat then
2927 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
2929 -- Is this else null correct, or should it be an abort???
2935 -- Unary operator case
2938 if Op_Name = Name_Op_Subtract or else
2939 Op_Name = Name_Op_Add or else
2940 Op_Name = Name_Op_Abs
2942 Find_Unary_Types (Act1, Op_Id, N);
2945 Op_Name = Name_Op_Not
2947 Find_Negation_Types (Act1, Op_Id, N);
2949 -- Is this else null correct, or should it be an abort???
2955 end Analyze_Operator_Call;
2957 -------------------------------------------
2958 -- Analyze_Overloaded_Selected_Component --
2959 -------------------------------------------
2961 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
2962 Nam : constant Node_Id := Prefix (N);
2963 Sel : constant Node_Id := Selector_Name (N);
2970 Set_Etype (Sel, Any_Type);
2972 Get_First_Interp (Nam, I, It);
2973 while Present (It.Typ) loop
2974 if Is_Access_Type (It.Typ) then
2975 T := Designated_Type (It.Typ);
2976 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2981 if Is_Record_Type (T) then
2983 -- If the prefix is a class-wide type, the visible components are
2984 -- those of the base type.
2986 if Is_Class_Wide_Type (T) then
2990 Comp := First_Entity (T);
2991 while Present (Comp) loop
2992 if Chars (Comp) = Chars (Sel)
2993 and then Is_Visible_Component (Comp)
2996 -- AI05-105: if the context is an object renaming with
2997 -- an anonymous access type, the expected type of the
2998 -- object must be anonymous. This is a name resolution rule.
3000 if Nkind (Parent (N)) /= N_Object_Renaming_Declaration
3001 or else No (Access_Definition (Parent (N)))
3002 or else Ekind (Etype (Comp)) = E_Anonymous_Access_Type
3004 Ekind (Etype (Comp)) = E_Anonymous_Access_Subprogram_Type
3006 Set_Entity (Sel, Comp);
3007 Set_Etype (Sel, Etype (Comp));
3008 Add_One_Interp (N, Etype (Comp), Etype (Comp));
3010 -- This also specifies a candidate to resolve the name.
3011 -- Further overloading will be resolved from context.
3012 -- The selector name itself does not carry overloading
3015 Set_Etype (Nam, It.Typ);
3018 -- Named access type in the context of a renaming
3019 -- declaration with an access definition. Remove
3020 -- inapplicable candidate.
3029 elsif Is_Concurrent_Type (T) then
3030 Comp := First_Entity (T);
3031 while Present (Comp)
3032 and then Comp /= First_Private_Entity (T)
3034 if Chars (Comp) = Chars (Sel) then
3035 if Is_Overloadable (Comp) then
3036 Add_One_Interp (Sel, Comp, Etype (Comp));
3038 Set_Entity_With_Style_Check (Sel, Comp);
3039 Generate_Reference (Comp, Sel);
3042 Set_Etype (Sel, Etype (Comp));
3043 Set_Etype (N, Etype (Comp));
3044 Set_Etype (Nam, It.Typ);
3046 -- For access type case, introduce explicit dereference for
3047 -- more uniform treatment of entry calls. Do this only once
3048 -- if several interpretations yield an access type.
3050 if Is_Access_Type (Etype (Nam))
3051 and then Nkind (Nam) /= N_Explicit_Dereference
3053 Insert_Explicit_Dereference (Nam);
3055 (Warn_On_Dereference, "?implicit dereference", N);
3062 Set_Is_Overloaded (N, Is_Overloaded (Sel));
3065 Get_Next_Interp (I, It);
3068 if Etype (N) = Any_Type
3069 and then not Try_Object_Operation (N)
3071 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
3072 Set_Entity (Sel, Any_Id);
3073 Set_Etype (Sel, Any_Type);
3075 end Analyze_Overloaded_Selected_Component;
3077 ----------------------------------
3078 -- Analyze_Qualified_Expression --
3079 ----------------------------------
3081 procedure Analyze_Qualified_Expression (N : Node_Id) is
3082 Mark : constant Entity_Id := Subtype_Mark (N);
3083 Expr : constant Node_Id := Expression (N);
3089 Analyze_Expression (Expr);
3091 Set_Etype (N, Any_Type);
3096 if T = Any_Type then
3100 Check_Fully_Declared (T, N);
3102 -- If expected type is class-wide, check for exact match before
3103 -- expansion, because if the expression is a dispatching call it
3104 -- may be rewritten as explicit dereference with class-wide result.
3105 -- If expression is overloaded, retain only interpretations that
3106 -- will yield exact matches.
3108 if Is_Class_Wide_Type (T) then
3109 if not Is_Overloaded (Expr) then
3110 if Base_Type (Etype (Expr)) /= Base_Type (T) then
3111 if Nkind (Expr) = N_Aggregate then
3112 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
3114 Wrong_Type (Expr, T);
3119 Get_First_Interp (Expr, I, It);
3121 while Present (It.Nam) loop
3122 if Base_Type (It.Typ) /= Base_Type (T) then
3126 Get_Next_Interp (I, It);
3132 end Analyze_Qualified_Expression;
3138 procedure Analyze_Range (N : Node_Id) is
3139 L : constant Node_Id := Low_Bound (N);
3140 H : constant Node_Id := High_Bound (N);
3141 I1, I2 : Interp_Index;
3144 procedure Check_Common_Type (T1, T2 : Entity_Id);
3145 -- Verify the compatibility of two types, and choose the
3146 -- non universal one if the other is universal.
3148 procedure Check_High_Bound (T : Entity_Id);
3149 -- Test one interpretation of the low bound against all those
3150 -- of the high bound.
3152 procedure Check_Universal_Expression (N : Node_Id);
3153 -- In Ada83, reject bounds of a universal range that are not
3154 -- literals or entity names.
3156 -----------------------
3157 -- Check_Common_Type --
3158 -----------------------
3160 procedure Check_Common_Type (T1, T2 : Entity_Id) is
3162 if Covers (T1 => T1, T2 => T2)
3164 Covers (T1 => T2, T2 => T1)
3166 if T1 = Universal_Integer
3167 or else T1 = Universal_Real
3168 or else T1 = Any_Character
3170 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
3173 Add_One_Interp (N, T1, T1);
3176 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
3179 end Check_Common_Type;
3181 ----------------------
3182 -- Check_High_Bound --
3183 ----------------------
3185 procedure Check_High_Bound (T : Entity_Id) is
3187 if not Is_Overloaded (H) then
3188 Check_Common_Type (T, Etype (H));
3190 Get_First_Interp (H, I2, It2);
3191 while Present (It2.Typ) loop
3192 Check_Common_Type (T, It2.Typ);
3193 Get_Next_Interp (I2, It2);
3196 end Check_High_Bound;
3198 -----------------------------
3199 -- Is_Universal_Expression --
3200 -----------------------------
3202 procedure Check_Universal_Expression (N : Node_Id) is
3204 if Etype (N) = Universal_Integer
3205 and then Nkind (N) /= N_Integer_Literal
3206 and then not Is_Entity_Name (N)
3207 and then Nkind (N) /= N_Attribute_Reference
3209 Error_Msg_N ("illegal bound in discrete range", N);
3211 end Check_Universal_Expression;
3213 -- Start of processing for Analyze_Range
3216 Set_Etype (N, Any_Type);
3217 Analyze_Expression (L);
3218 Analyze_Expression (H);
3220 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
3224 if not Is_Overloaded (L) then
3225 Check_High_Bound (Etype (L));
3227 Get_First_Interp (L, I1, It1);
3228 while Present (It1.Typ) loop
3229 Check_High_Bound (It1.Typ);
3230 Get_Next_Interp (I1, It1);
3234 -- If result is Any_Type, then we did not find a compatible pair
3236 if Etype (N) = Any_Type then
3237 Error_Msg_N ("incompatible types in range ", N);
3241 if Ada_Version = Ada_83
3243 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
3244 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
3246 Check_Universal_Expression (L);
3247 Check_Universal_Expression (H);
3251 -----------------------
3252 -- Analyze_Reference --
3253 -----------------------
3255 procedure Analyze_Reference (N : Node_Id) is
3256 P : constant Node_Id := Prefix (N);
3259 Acc_Type : Entity_Id;
3264 -- An interesting error check, if we take the 'Reference of an object
3265 -- for which a pragma Atomic or Volatile has been given, and the type
3266 -- of the object is not Atomic or Volatile, then we are in trouble. The
3267 -- problem is that no trace of the atomic/volatile status will remain
3268 -- for the backend to respect when it deals with the resulting pointer,
3269 -- since the pointer type will not be marked atomic (it is a pointer to
3270 -- the base type of the object).
3272 -- It is not clear if that can ever occur, but in case it does, we will
3273 -- generate an error message. Not clear if this message can ever be
3274 -- generated, and pretty clear that it represents a bug if it is, still
3275 -- seems worth checking, except in CodePeer mode where we do not really
3276 -- care and don't want to bother the user.
3280 if Is_Entity_Name (P)
3281 and then Is_Object_Reference (P)
3282 and then not CodePeer_Mode
3287 if (Has_Atomic_Components (E)
3288 and then not Has_Atomic_Components (T))
3290 (Has_Volatile_Components (E)
3291 and then not Has_Volatile_Components (T))
3292 or else (Is_Atomic (E) and then not Is_Atomic (T))
3293 or else (Is_Volatile (E) and then not Is_Volatile (T))
3295 Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
3299 -- Carry on with normal processing
3301 Acc_Type := Create_Itype (E_Allocator_Type, N);
3302 Set_Etype (Acc_Type, Acc_Type);
3303 Set_Directly_Designated_Type (Acc_Type, Etype (P));
3304 Set_Etype (N, Acc_Type);
3305 end Analyze_Reference;
3307 --------------------------------
3308 -- Analyze_Selected_Component --
3309 --------------------------------
3311 -- Prefix is a record type or a task or protected type. In the latter case,
3312 -- the selector must denote a visible entry.
3314 procedure Analyze_Selected_Component (N : Node_Id) is
3315 Name : constant Node_Id := Prefix (N);
3316 Sel : constant Node_Id := Selector_Name (N);
3319 Has_Candidate : Boolean := False;
3322 Pent : Entity_Id := Empty;
3323 Prefix_Type : Entity_Id;
3325 Type_To_Use : Entity_Id;
3326 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
3327 -- a class-wide type, we use its root type, whose components are
3328 -- present in the class-wide type.
3330 Is_Single_Concurrent_Object : Boolean;
3331 -- Set True if the prefix is a single task or a single protected object
3333 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
3334 -- It is known that the parent of N denotes a subprogram call. Comp
3335 -- is an overloadable component of the concurrent type of the prefix.
3336 -- Determine whether all formals of the parent of N and Comp are mode
3337 -- conformant. If the parent node is not analyzed yet it may be an
3338 -- indexed component rather than a function call.
3340 ------------------------------
3341 -- Has_Mode_Conformant_Spec --
3342 ------------------------------
3344 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
3345 Comp_Param : Entity_Id;
3347 Param_Typ : Entity_Id;
3350 Comp_Param := First_Formal (Comp);
3352 if Nkind (Parent (N)) = N_Indexed_Component then
3353 Param := First (Expressions (Parent (N)));
3355 Param := First (Parameter_Associations (Parent (N)));
3358 while Present (Comp_Param)
3359 and then Present (Param)
3361 Param_Typ := Find_Parameter_Type (Param);
3363 if Present (Param_Typ)
3365 not Conforming_Types
3366 (Etype (Comp_Param), Param_Typ, Mode_Conformant)
3371 Next_Formal (Comp_Param);
3375 -- One of the specs has additional formals
3377 if Present (Comp_Param) or else Present (Param) then
3382 end Has_Mode_Conformant_Spec;
3384 -- Start of processing for Analyze_Selected_Component
3387 Set_Etype (N, Any_Type);
3389 if Is_Overloaded (Name) then
3390 Analyze_Overloaded_Selected_Component (N);
3393 elsif Etype (Name) = Any_Type then
3394 Set_Entity (Sel, Any_Id);
3395 Set_Etype (Sel, Any_Type);
3399 Prefix_Type := Etype (Name);
3402 if Is_Access_Type (Prefix_Type) then
3404 -- A RACW object can never be used as prefix of a selected component
3405 -- since that means it is dereferenced without being a controlling
3406 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
3407 -- reporting an error, we must check whether this is actually a
3408 -- dispatching call in prefix form.
3410 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
3411 and then Comes_From_Source (N)
3413 if Try_Object_Operation (N) then
3417 ("invalid dereference of a remote access-to-class-wide value",
3421 -- Normal case of selected component applied to access type
3424 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3426 if Is_Entity_Name (Name) then
3427 Pent := Entity (Name);
3428 elsif Nkind (Name) = N_Selected_Component
3429 and then Is_Entity_Name (Selector_Name (Name))
3431 Pent := Entity (Selector_Name (Name));
3434 Prefix_Type := Process_Implicit_Dereference_Prefix (Pent, Name);
3437 -- If we have an explicit dereference of a remote access-to-class-wide
3438 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
3439 -- have to check for the case of a prefix that is a controlling operand
3440 -- of a prefixed dispatching call, as the dereference is legal in that
3441 -- case. Normally this condition is checked in Validate_Remote_Access_
3442 -- To_Class_Wide_Type, but we have to defer the checking for selected
3443 -- component prefixes because of the prefixed dispatching call case.
3444 -- Note that implicit dereferences are checked for this just above.
3446 elsif Nkind (Name) = N_Explicit_Dereference
3447 and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
3448 and then Comes_From_Source (N)
3450 if Try_Object_Operation (N) then
3454 ("invalid dereference of a remote access-to-class-wide value",
3459 -- (Ada 2005): if the prefix is the limited view of a type, and
3460 -- the context already includes the full view, use the full view
3461 -- in what follows, either to retrieve a component of to find
3462 -- a primitive operation. If the prefix is an explicit dereference,
3463 -- set the type of the prefix to reflect this transformation.
3464 -- If the non-limited view is itself an incomplete type, get the
3465 -- full view if available.
3467 if Is_Incomplete_Type (Prefix_Type)
3468 and then From_With_Type (Prefix_Type)
3469 and then Present (Non_Limited_View (Prefix_Type))
3471 Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
3473 if Nkind (N) = N_Explicit_Dereference then
3474 Set_Etype (Prefix (N), Prefix_Type);
3477 elsif Ekind (Prefix_Type) = E_Class_Wide_Type
3478 and then From_With_Type (Prefix_Type)
3479 and then Present (Non_Limited_View (Etype (Prefix_Type)))
3482 Class_Wide_Type (Non_Limited_View (Etype (Prefix_Type)));
3484 if Nkind (N) = N_Explicit_Dereference then
3485 Set_Etype (Prefix (N), Prefix_Type);
3489 if Ekind (Prefix_Type) = E_Private_Subtype then
3490 Prefix_Type := Base_Type (Prefix_Type);
3493 Type_To_Use := Prefix_Type;
3495 -- For class-wide types, use the entity list of the root type. This
3496 -- indirection is specially important for private extensions because
3497 -- only the root type get switched (not the class-wide type).
3499 if Is_Class_Wide_Type (Prefix_Type) then
3500 Type_To_Use := Root_Type (Prefix_Type);
3503 -- If the prefix is a single concurrent object, use its name in error
3504 -- messages, rather than that of its anonymous type.
3506 Is_Single_Concurrent_Object :=
3507 Is_Concurrent_Type (Prefix_Type)
3508 and then Is_Internal_Name (Chars (Prefix_Type))
3509 and then not Is_Derived_Type (Prefix_Type)
3510 and then Is_Entity_Name (Name);
3512 Comp := First_Entity (Type_To_Use);
3514 -- If the selector has an original discriminant, the node appears in
3515 -- an instance. Replace the discriminant with the corresponding one
3516 -- in the current discriminated type. For nested generics, this must
3517 -- be done transitively, so note the new original discriminant.
3519 if Nkind (Sel) = N_Identifier
3520 and then Present (Original_Discriminant (Sel))
3522 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
3524 -- Mark entity before rewriting, for completeness and because
3525 -- subsequent semantic checks might examine the original node.
3527 Set_Entity (Sel, Comp);
3528 Rewrite (Selector_Name (N),
3529 New_Occurrence_Of (Comp, Sloc (N)));
3530 Set_Original_Discriminant (Selector_Name (N), Comp);
3531 Set_Etype (N, Etype (Comp));
3533 if Is_Access_Type (Etype (Name)) then
3534 Insert_Explicit_Dereference (Name);
3535 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3538 elsif Is_Record_Type (Prefix_Type) then
3540 -- Find component with given name
3542 while Present (Comp) loop
3543 if Chars (Comp) = Chars (Sel)
3544 and then Is_Visible_Component (Comp)
3546 Set_Entity_With_Style_Check (Sel, Comp);
3547 Set_Etype (Sel, Etype (Comp));
3549 if Ekind (Comp) = E_Discriminant then
3550 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
3552 ("cannot reference discriminant of Unchecked_Union",
3556 if Is_Generic_Type (Prefix_Type)
3558 Is_Generic_Type (Root_Type (Prefix_Type))
3560 Set_Original_Discriminant (Sel, Comp);
3564 -- Resolve the prefix early otherwise it is not possible to
3565 -- build the actual subtype of the component: it may need
3566 -- to duplicate this prefix and duplication is only allowed
3567 -- on fully resolved expressions.
3571 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
3572 -- subtypes in a package specification.
3575 -- limited with Pkg;
3577 -- type Acc_Inc is access Pkg.T;
3579 -- N : Natural := X.all.Comp; -- ERROR, limited view
3580 -- end Pkg; -- Comp is not visible
3582 if Nkind (Name) = N_Explicit_Dereference
3583 and then From_With_Type (Etype (Prefix (Name)))
3584 and then not Is_Potentially_Use_Visible (Etype (Name))
3585 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
3586 N_Package_Specification
3589 ("premature usage of incomplete}", Prefix (Name),
3590 Etype (Prefix (Name)));
3593 -- We never need an actual subtype for the case of a selection
3594 -- for a indexed component of a non-packed array, since in
3595 -- this case gigi generates all the checks and can find the
3596 -- necessary bounds information.
3598 -- We also do not need an actual subtype for the case of a
3599 -- first, last, length, or range attribute applied to a
3600 -- non-packed array, since gigi can again get the bounds in
3601 -- these cases (gigi cannot handle the packed case, since it
3602 -- has the bounds of the packed array type, not the original
3603 -- bounds of the type). However, if the prefix is itself a
3604 -- selected component, as in a.b.c (i), gigi may regard a.b.c
3605 -- as a dynamic-sized temporary, so we do generate an actual
3606 -- subtype for this case.
3608 Parent_N := Parent (N);
3610 if not Is_Packed (Etype (Comp))
3612 ((Nkind (Parent_N) = N_Indexed_Component
3613 and then Nkind (Name) /= N_Selected_Component)
3615 (Nkind (Parent_N) = N_Attribute_Reference
3616 and then (Attribute_Name (Parent_N) = Name_First
3618 Attribute_Name (Parent_N) = Name_Last
3620 Attribute_Name (Parent_N) = Name_Length
3622 Attribute_Name (Parent_N) = Name_Range)))
3624 Set_Etype (N, Etype (Comp));
3626 -- If full analysis is not enabled, we do not generate an
3627 -- actual subtype, because in the absence of expansion
3628 -- reference to a formal of a protected type, for example,
3629 -- will not be properly transformed, and will lead to
3630 -- out-of-scope references in gigi.
3632 -- In all other cases, we currently build an actual subtype.
3633 -- It seems likely that many of these cases can be avoided,
3634 -- but right now, the front end makes direct references to the
3635 -- bounds (e.g. in generating a length check), and if we do
3636 -- not make an actual subtype, we end up getting a direct
3637 -- reference to a discriminant, which will not do.
3639 elsif Full_Analysis then
3641 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
3642 Insert_Action (N, Act_Decl);
3644 if No (Act_Decl) then
3645 Set_Etype (N, Etype (Comp));
3648 -- Component type depends on discriminants. Enter the
3649 -- main attributes of the subtype.
3652 Subt : constant Entity_Id :=
3653 Defining_Identifier (Act_Decl);
3656 Set_Etype (Subt, Base_Type (Etype (Comp)));
3657 Set_Ekind (Subt, Ekind (Etype (Comp)));
3658 Set_Etype (N, Subt);
3662 -- If Full_Analysis not enabled, just set the Etype
3665 Set_Etype (N, Etype (Comp));
3671 -- If the prefix is a private extension, check only the visible
3672 -- components of the partial view. This must include the tag,
3673 -- which can appear in expanded code in a tag check.
3675 if Ekind (Type_To_Use) = E_Record_Type_With_Private
3676 and then Chars (Selector_Name (N)) /= Name_uTag
3678 exit when Comp = Last_Entity (Type_To_Use);
3684 -- Ada 2005 (AI-252): The selected component can be interpreted as
3685 -- a prefixed view of a subprogram. Depending on the context, this is
3686 -- either a name that can appear in a renaming declaration, or part
3687 -- of an enclosing call given in prefix form.
3689 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
3690 -- selected component should resolve to a name.
3692 if Ada_Version >= Ada_05
3693 and then Is_Tagged_Type (Prefix_Type)
3694 and then not Is_Concurrent_Type (Prefix_Type)
3696 if Nkind (Parent (N)) = N_Generic_Association
3697 or else Nkind (Parent (N)) = N_Requeue_Statement
3698 or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
3700 if Find_Primitive_Operation (N) then
3704 elsif Try_Object_Operation (N) then
3708 -- If the transformation fails, it will be necessary to redo the
3709 -- analysis with all errors enabled, to indicate candidate
3710 -- interpretations and reasons for each failure ???
3714 elsif Is_Private_Type (Prefix_Type) then
3716 -- Allow access only to discriminants of the type. If the type has
3717 -- no full view, gigi uses the parent type for the components, so we
3718 -- do the same here.
3720 if No (Full_View (Prefix_Type)) then
3721 Type_To_Use := Root_Type (Base_Type (Prefix_Type));
3722 Comp := First_Entity (Type_To_Use);
3725 while Present (Comp) loop
3726 if Chars (Comp) = Chars (Sel) then
3727 if Ekind (Comp) = E_Discriminant then
3728 Set_Entity_With_Style_Check (Sel, Comp);
3729 Generate_Reference (Comp, Sel);
3731 Set_Etype (Sel, Etype (Comp));
3732 Set_Etype (N, Etype (Comp));
3734 if Is_Generic_Type (Prefix_Type)
3735 or else Is_Generic_Type (Root_Type (Prefix_Type))
3737 Set_Original_Discriminant (Sel, Comp);
3740 -- Before declaring an error, check whether this is tagged
3741 -- private type and a call to a primitive operation.
3743 elsif Ada_Version >= Ada_05
3744 and then Is_Tagged_Type (Prefix_Type)
3745 and then Try_Object_Operation (N)
3750 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
3751 Error_Msg_NE ("invisible selector& for }", N, Sel);
3752 Set_Entity (Sel, Any_Id);
3753 Set_Etype (N, Any_Type);
3762 elsif Is_Concurrent_Type (Prefix_Type) then
3764 -- Find visible operation with given name. For a protected type,
3765 -- the possible candidates are discriminants, entries or protected
3766 -- procedures. For a task type, the set can only include entries or
3767 -- discriminants if the task type is not an enclosing scope. If it
3768 -- is an enclosing scope (e.g. in an inner task) then all entities
3769 -- are visible, but the prefix must denote the enclosing scope, i.e.
3770 -- can only be a direct name or an expanded name.
3772 Set_Etype (Sel, Any_Type);
3773 In_Scope := In_Open_Scopes (Prefix_Type);
3775 while Present (Comp) loop
3776 if Chars (Comp) = Chars (Sel) then
3777 if Is_Overloadable (Comp) then
3778 Add_One_Interp (Sel, Comp, Etype (Comp));
3780 -- If the prefix is tagged, the correct interpretation may
3781 -- lie in the primitive or class-wide operations of the
3782 -- type. Perform a simple conformance check to determine
3783 -- whether Try_Object_Operation should be invoked even if
3784 -- a visible entity is found.
3786 if Is_Tagged_Type (Prefix_Type)
3788 Nkind_In (Parent (N), N_Procedure_Call_Statement,
3790 N_Indexed_Component)
3791 and then Has_Mode_Conformant_Spec (Comp)
3793 Has_Candidate := True;
3796 -- Note: a selected component may not denote a component of a
3797 -- protected type (4.1.3(7)).
3799 elsif Ekind_In (Comp, E_Discriminant, E_Entry_Family)
3801 and then not Is_Protected_Type (Prefix_Type)
3802 and then Is_Entity_Name (Name))
3804 Set_Entity_With_Style_Check (Sel, Comp);
3805 Generate_Reference (Comp, Sel);
3811 Set_Etype (Sel, Etype (Comp));
3812 Set_Etype (N, Etype (Comp));
3814 if Ekind (Comp) = E_Discriminant then
3815 Set_Original_Discriminant (Sel, Comp);
3818 -- For access type case, introduce explicit dereference for
3819 -- more uniform treatment of entry calls.
3821 if Is_Access_Type (Etype (Name)) then
3822 Insert_Explicit_Dereference (Name);
3824 (Warn_On_Dereference, "?implicit dereference", N);
3830 exit when not In_Scope
3832 Comp = First_Private_Entity (Base_Type (Prefix_Type));
3835 -- If there is no visible entity with the given name or none of the
3836 -- visible entities are plausible interpretations, check whether
3837 -- there is some other primitive operation with that name.
3839 if Ada_Version >= Ada_05
3840 and then Is_Tagged_Type (Prefix_Type)
3842 if (Etype (N) = Any_Type
3843 or else not Has_Candidate)
3844 and then Try_Object_Operation (N)
3848 -- If the context is not syntactically a procedure call, it
3849 -- may be a call to a primitive function declared outside of
3850 -- the synchronized type.
3852 -- If the context is a procedure call, there might still be
3853 -- an overloading between an entry and a primitive procedure
3854 -- declared outside of the synchronized type, called in prefix
3855 -- notation. This is harder to disambiguate because in one case
3856 -- the controlling formal is implicit ???
3858 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
3859 and then Nkind (Parent (N)) /= N_Indexed_Component
3860 and then Try_Object_Operation (N)
3866 if Etype (N) = Any_Type and then Is_Protected_Type (Prefix_Type) then
3867 -- Case of a prefix of a protected type: selector might denote
3868 -- an invisible private component.
3870 Comp := First_Private_Entity (Base_Type (Prefix_Type));
3871 while Present (Comp) and then Chars (Comp) /= Chars (Sel) loop
3875 if Present (Comp) then
3876 if Is_Single_Concurrent_Object then
3877 Error_Msg_Node_2 := Entity (Name);
3878 Error_Msg_NE ("invisible selector& for &", N, Sel);
3881 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
3882 Error_Msg_NE ("invisible selector& for }", N, Sel);
3888 Set_Is_Overloaded (N, Is_Overloaded (Sel));
3893 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
3896 -- If N still has no type, the component is not defined in the prefix
3898 if Etype (N) = Any_Type then
3900 if Is_Single_Concurrent_Object then
3901 Error_Msg_Node_2 := Entity (Name);
3902 Error_Msg_NE ("no selector& for&", N, Sel);
3904 Check_Misspelled_Selector (Type_To_Use, Sel);
3906 elsif Is_Generic_Type (Prefix_Type)
3907 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
3908 and then Prefix_Type /= Etype (Prefix_Type)
3909 and then Is_Record_Type (Etype (Prefix_Type))
3911 -- If this is a derived formal type, the parent may have
3912 -- different visibility at this point. Try for an inherited
3913 -- component before reporting an error.
3915 Set_Etype (Prefix (N), Etype (Prefix_Type));
3916 Analyze_Selected_Component (N);
3919 elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
3920 and then Is_Generic_Actual_Type (Prefix_Type)
3921 and then Present (Full_View (Prefix_Type))
3923 -- Similarly, if this the actual for a formal derived type, the
3924 -- component inherited from the generic parent may not be visible
3925 -- in the actual, but the selected component is legal.
3932 First_Component (Generic_Parent_Type (Parent (Prefix_Type)));
3933 while Present (Comp) loop
3934 if Chars (Comp) = Chars (Sel) then
3935 Set_Entity_With_Style_Check (Sel, Comp);
3936 Set_Etype (Sel, Etype (Comp));
3937 Set_Etype (N, Etype (Comp));
3941 Next_Component (Comp);
3944 pragma Assert (Etype (N) /= Any_Type);
3948 if Ekind (Prefix_Type) = E_Record_Subtype then
3950 -- Check whether this is a component of the base type which
3951 -- is absent from a statically constrained subtype. This will
3952 -- raise constraint error at run time, but is not a compile-
3953 -- time error. When the selector is illegal for base type as
3954 -- well fall through and generate a compilation error anyway.
3956 Comp := First_Component (Base_Type (Prefix_Type));
3957 while Present (Comp) loop
3958 if Chars (Comp) = Chars (Sel)
3959 and then Is_Visible_Component (Comp)
3961 Set_Entity_With_Style_Check (Sel, Comp);
3962 Generate_Reference (Comp, Sel);
3963 Set_Etype (Sel, Etype (Comp));
3964 Set_Etype (N, Etype (Comp));
3966 -- Emit appropriate message. Gigi will replace the
3967 -- node subsequently with the appropriate Raise.
3969 Apply_Compile_Time_Constraint_Error
3970 (N, "component not present in }?",
3971 CE_Discriminant_Check_Failed,
3972 Ent => Prefix_Type, Rep => False);
3973 Set_Raises_Constraint_Error (N);
3977 Next_Component (Comp);
3982 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
3983 Error_Msg_NE ("no selector& for}", N, Sel);
3985 Check_Misspelled_Selector (Type_To_Use, Sel);
3988 Set_Entity (Sel, Any_Id);
3989 Set_Etype (Sel, Any_Type);
3991 end Analyze_Selected_Component;
3993 ---------------------------
3994 -- Analyze_Short_Circuit --
3995 ---------------------------
3997 procedure Analyze_Short_Circuit (N : Node_Id) is
3998 L : constant Node_Id := Left_Opnd (N);
3999 R : constant Node_Id := Right_Opnd (N);
4004 Analyze_Expression (L);
4005 Analyze_Expression (R);
4006 Set_Etype (N, Any_Type);
4008 if not Is_Overloaded (L) then
4009 if Root_Type (Etype (L)) = Standard_Boolean
4010 and then Has_Compatible_Type (R, Etype (L))
4012 Add_One_Interp (N, Etype (L), Etype (L));
4016 Get_First_Interp (L, Ind, It);
4017 while Present (It.Typ) loop
4018 if Root_Type (It.Typ) = Standard_Boolean
4019 and then Has_Compatible_Type (R, It.Typ)
4021 Add_One_Interp (N, It.Typ, It.Typ);
4024 Get_Next_Interp (Ind, It);
4028 -- Here we have failed to find an interpretation. Clearly we know that
4029 -- it is not the case that both operands can have an interpretation of
4030 -- Boolean, but this is by far the most likely intended interpretation.
4031 -- So we simply resolve both operands as Booleans, and at least one of
4032 -- these resolutions will generate an error message, and we do not need
4033 -- to give another error message on the short circuit operation itself.
4035 if Etype (N) = Any_Type then
4036 Resolve (L, Standard_Boolean);
4037 Resolve (R, Standard_Boolean);
4038 Set_Etype (N, Standard_Boolean);
4040 end Analyze_Short_Circuit;
4046 procedure Analyze_Slice (N : Node_Id) is
4047 P : constant Node_Id := Prefix (N);
4048 D : constant Node_Id := Discrete_Range (N);
4049 Array_Type : Entity_Id;
4051 procedure Analyze_Overloaded_Slice;
4052 -- If the prefix is overloaded, select those interpretations that
4053 -- yield a one-dimensional array type.
4055 ------------------------------
4056 -- Analyze_Overloaded_Slice --
4057 ------------------------------
4059 procedure Analyze_Overloaded_Slice is
4065 Set_Etype (N, Any_Type);
4067 Get_First_Interp (P, I, It);
4068 while Present (It.Nam) loop
4071 if Is_Access_Type (Typ) then
4072 Typ := Designated_Type (Typ);
4073 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
4076 if Is_Array_Type (Typ)
4077 and then Number_Dimensions (Typ) = 1
4078 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
4080 Add_One_Interp (N, Typ, Typ);
4083 Get_Next_Interp (I, It);
4086 if Etype (N) = Any_Type then
4087 Error_Msg_N ("expect array type in prefix of slice", N);
4089 end Analyze_Overloaded_Slice;
4091 -- Start of processing for Analyze_Slice
4097 if Is_Overloaded (P) then
4098 Analyze_Overloaded_Slice;
4101 Array_Type := Etype (P);
4102 Set_Etype (N, Any_Type);
4104 if Is_Access_Type (Array_Type) then
4105 Array_Type := Designated_Type (Array_Type);
4106 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
4109 if not Is_Array_Type (Array_Type) then
4110 Wrong_Type (P, Any_Array);
4112 elsif Number_Dimensions (Array_Type) > 1 then
4114 ("type is not one-dimensional array in slice prefix", N);
4117 Has_Compatible_Type (D, Etype (First_Index (Array_Type)))
4119 Wrong_Type (D, Etype (First_Index (Array_Type)));
4122 Set_Etype (N, Array_Type);
4127 -----------------------------
4128 -- Analyze_Type_Conversion --
4129 -----------------------------
4131 procedure Analyze_Type_Conversion (N : Node_Id) is
4132 Expr : constant Node_Id := Expression (N);
4136 -- If Conversion_OK is set, then the Etype is already set, and the
4137 -- only processing required is to analyze the expression. This is
4138 -- used to construct certain "illegal" conversions which are not
4139 -- allowed by Ada semantics, but can be handled OK by Gigi, see
4140 -- Sinfo for further details.
4142 if Conversion_OK (N) then
4147 -- Otherwise full type analysis is required, as well as some semantic
4148 -- checks to make sure the argument of the conversion is appropriate.
4150 Find_Type (Subtype_Mark (N));
4151 T := Entity (Subtype_Mark (N));
4153 Check_Fully_Declared (T, N);
4154 Analyze_Expression (Expr);
4155 Validate_Remote_Type_Type_Conversion (N);
4157 -- Only remaining step is validity checks on the argument. These
4158 -- are skipped if the conversion does not come from the source.
4160 if not Comes_From_Source (N) then
4163 -- If there was an error in a generic unit, no need to replicate the
4164 -- error message. Conversely, constant-folding in the generic may
4165 -- transform the argument of a conversion into a string literal, which
4166 -- is legal. Therefore the following tests are not performed in an
4169 elsif In_Instance then
4172 elsif Nkind (Expr) = N_Null then
4173 Error_Msg_N ("argument of conversion cannot be null", N);
4174 Error_Msg_N ("\use qualified expression instead", N);
4175 Set_Etype (N, Any_Type);
4177 elsif Nkind (Expr) = N_Aggregate then
4178 Error_Msg_N ("argument of conversion cannot be aggregate", N);
4179 Error_Msg_N ("\use qualified expression instead", N);
4181 elsif Nkind (Expr) = N_Allocator then
4182 Error_Msg_N ("argument of conversion cannot be an allocator", N);
4183 Error_Msg_N ("\use qualified expression instead", N);
4185 elsif Nkind (Expr) = N_String_Literal then
4186 Error_Msg_N ("argument of conversion cannot be string literal", N);
4187 Error_Msg_N ("\use qualified expression instead", N);
4189 elsif Nkind (Expr) = N_Character_Literal then
4190 if Ada_Version = Ada_83 then
4193 Error_Msg_N ("argument of conversion cannot be character literal",
4195 Error_Msg_N ("\use qualified expression instead", N);
4198 elsif Nkind (Expr) = N_Attribute_Reference
4200 (Attribute_Name (Expr) = Name_Access or else
4201 Attribute_Name (Expr) = Name_Unchecked_Access or else
4202 Attribute_Name (Expr) = Name_Unrestricted_Access)
4204 Error_Msg_N ("argument of conversion cannot be access", N);
4205 Error_Msg_N ("\use qualified expression instead", N);
4207 end Analyze_Type_Conversion;
4209 ----------------------
4210 -- Analyze_Unary_Op --
4211 ----------------------
4213 procedure Analyze_Unary_Op (N : Node_Id) is
4214 R : constant Node_Id := Right_Opnd (N);
4215 Op_Id : Entity_Id := Entity (N);
4218 Set_Etype (N, Any_Type);
4219 Candidate_Type := Empty;
4221 Analyze_Expression (R);
4223 if Present (Op_Id) then
4224 if Ekind (Op_Id) = E_Operator then
4225 Find_Unary_Types (R, Op_Id, N);
4227 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4231 Op_Id := Get_Name_Entity_Id (Chars (N));
4232 while Present (Op_Id) loop
4233 if Ekind (Op_Id) = E_Operator then
4234 if No (Next_Entity (First_Entity (Op_Id))) then
4235 Find_Unary_Types (R, Op_Id, N);
4238 elsif Is_Overloadable (Op_Id) then
4239 Analyze_User_Defined_Unary_Op (N, Op_Id);
4242 Op_Id := Homonym (Op_Id);
4247 end Analyze_Unary_Op;
4249 ----------------------------------
4250 -- Analyze_Unchecked_Expression --
4251 ----------------------------------
4253 procedure Analyze_Unchecked_Expression (N : Node_Id) is
4255 Analyze (Expression (N), Suppress => All_Checks);
4256 Set_Etype (N, Etype (Expression (N)));
4257 Save_Interps (Expression (N), N);
4258 end Analyze_Unchecked_Expression;
4260 ---------------------------------------
4261 -- Analyze_Unchecked_Type_Conversion --
4262 ---------------------------------------
4264 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
4266 Find_Type (Subtype_Mark (N));
4267 Analyze_Expression (Expression (N));
4268 Set_Etype (N, Entity (Subtype_Mark (N)));
4269 end Analyze_Unchecked_Type_Conversion;
4271 ------------------------------------
4272 -- Analyze_User_Defined_Binary_Op --
4273 ------------------------------------
4275 procedure Analyze_User_Defined_Binary_Op
4280 -- Only do analysis if the operator Comes_From_Source, since otherwise
4281 -- the operator was generated by the expander, and all such operators
4282 -- always refer to the operators in package Standard.
4284 if Comes_From_Source (N) then
4286 F1 : constant Entity_Id := First_Formal (Op_Id);
4287 F2 : constant Entity_Id := Next_Formal (F1);
4290 -- Verify that Op_Id is a visible binary function. Note that since
4291 -- we know Op_Id is overloaded, potentially use visible means use
4292 -- visible for sure (RM 9.4(11)).
4294 if Ekind (Op_Id) = E_Function
4295 and then Present (F2)
4296 and then (Is_Immediately_Visible (Op_Id)
4297 or else Is_Potentially_Use_Visible (Op_Id))
4298 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
4299 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
4301 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4303 -- If the left operand is overloaded, indicate that the
4304 -- current type is a viable candidate. This is redundant
4305 -- in most cases, but for equality and comparison operators
4306 -- where the context does not impose a type on the operands,
4307 -- setting the proper type is necessary to avoid subsequent
4308 -- ambiguities during resolution, when both user-defined and
4309 -- predefined operators may be candidates.
4311 if Is_Overloaded (Left_Opnd (N)) then
4312 Set_Etype (Left_Opnd (N), Etype (F1));
4315 if Debug_Flag_E then
4316 Write_Str ("user defined operator ");
4317 Write_Name (Chars (Op_Id));
4318 Write_Str (" on node ");
4319 Write_Int (Int (N));
4325 end Analyze_User_Defined_Binary_Op;
4327 -----------------------------------
4328 -- Analyze_User_Defined_Unary_Op --
4329 -----------------------------------
4331 procedure Analyze_User_Defined_Unary_Op
4336 -- Only do analysis if the operator Comes_From_Source, since otherwise
4337 -- the operator was generated by the expander, and all such operators
4338 -- always refer to the operators in package Standard.
4340 if Comes_From_Source (N) then
4342 F : constant Entity_Id := First_Formal (Op_Id);
4345 -- Verify that Op_Id is a visible unary function. Note that since
4346 -- we know Op_Id is overloaded, potentially use visible means use
4347 -- visible for sure (RM 9.4(11)).
4349 if Ekind (Op_Id) = E_Function
4350 and then No (Next_Formal (F))
4351 and then (Is_Immediately_Visible (Op_Id)
4352 or else Is_Potentially_Use_Visible (Op_Id))
4353 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
4355 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4359 end Analyze_User_Defined_Unary_Op;
4361 ---------------------------
4362 -- Check_Arithmetic_Pair --
4363 ---------------------------
4365 procedure Check_Arithmetic_Pair
4366 (T1, T2 : Entity_Id;
4370 Op_Name : constant Name_Id := Chars (Op_Id);
4372 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
4373 -- Check whether the fixed-point type Typ has a user-defined operator
4374 -- (multiplication or division) that should hide the corresponding
4375 -- predefined operator. Used to implement Ada 2005 AI-264, to make
4376 -- such operators more visible and therefore useful.
4378 -- If the name of the operation is an expanded name with prefix
4379 -- Standard, the predefined universal fixed operator is available,
4380 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
4382 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
4383 -- Get specific type (i.e. non-universal type if there is one)
4389 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
4390 Bas : constant Entity_Id := Base_Type (Typ);
4396 -- If the universal_fixed operation is given explicitly the rule
4397 -- concerning primitive operations of the type do not apply.
4399 if Nkind (N) = N_Function_Call
4400 and then Nkind (Name (N)) = N_Expanded_Name
4401 and then Entity (Prefix (Name (N))) = Standard_Standard
4406 -- The operation is treated as primitive if it is declared in the
4407 -- same scope as the type, and therefore on the same entity chain.
4409 Ent := Next_Entity (Typ);
4410 while Present (Ent) loop
4411 if Chars (Ent) = Chars (Op) then
4412 F1 := First_Formal (Ent);
4413 F2 := Next_Formal (F1);
4415 -- The operation counts as primitive if either operand or
4416 -- result are of the given base type, and both operands are
4417 -- fixed point types.
4419 if (Base_Type (Etype (F1)) = Bas
4420 and then Is_Fixed_Point_Type (Etype (F2)))
4423 (Base_Type (Etype (F2)) = Bas
4424 and then Is_Fixed_Point_Type (Etype (F1)))
4427 (Base_Type (Etype (Ent)) = Bas
4428 and then Is_Fixed_Point_Type (Etype (F1))
4429 and then Is_Fixed_Point_Type (Etype (F2)))
4445 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
4447 if T1 = Universal_Integer or else T1 = Universal_Real then
4448 return Base_Type (T2);
4450 return Base_Type (T1);
4454 -- Start of processing for Check_Arithmetic_Pair
4457 if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
4459 if Is_Numeric_Type (T1)
4460 and then Is_Numeric_Type (T2)
4461 and then (Covers (T1 => T1, T2 => T2)
4463 Covers (T1 => T2, T2 => T1))
4465 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4468 elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
4470 if Is_Fixed_Point_Type (T1)
4471 and then (Is_Fixed_Point_Type (T2)
4472 or else T2 = Universal_Real)
4474 -- If Treat_Fixed_As_Integer is set then the Etype is already set
4475 -- and no further processing is required (this is the case of an
4476 -- operator constructed by Exp_Fixd for a fixed point operation)
4477 -- Otherwise add one interpretation with universal fixed result
4478 -- If the operator is given in functional notation, it comes
4479 -- from source and Fixed_As_Integer cannot apply.
4481 if (Nkind (N) not in N_Op
4482 or else not Treat_Fixed_As_Integer (N))
4484 (not Has_Fixed_Op (T1, Op_Id)
4485 or else Nkind (Parent (N)) = N_Type_Conversion)
4487 Add_One_Interp (N, Op_Id, Universal_Fixed);
4490 elsif Is_Fixed_Point_Type (T2)
4491 and then (Nkind (N) not in N_Op
4492 or else not Treat_Fixed_As_Integer (N))
4493 and then T1 = Universal_Real
4495 (not Has_Fixed_Op (T1, Op_Id)
4496 or else Nkind (Parent (N)) = N_Type_Conversion)
4498 Add_One_Interp (N, Op_Id, Universal_Fixed);
4500 elsif Is_Numeric_Type (T1)
4501 and then Is_Numeric_Type (T2)
4502 and then (Covers (T1 => T1, T2 => T2)
4504 Covers (T1 => T2, T2 => T1))
4506 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4508 elsif Is_Fixed_Point_Type (T1)
4509 and then (Base_Type (T2) = Base_Type (Standard_Integer)
4510 or else T2 = Universal_Integer)
4512 Add_One_Interp (N, Op_Id, T1);
4514 elsif T2 = Universal_Real
4515 and then Base_Type (T1) = Base_Type (Standard_Integer)
4516 and then Op_Name = Name_Op_Multiply
4518 Add_One_Interp (N, Op_Id, Any_Fixed);
4520 elsif T1 = Universal_Real
4521 and then Base_Type (T2) = Base_Type (Standard_Integer)
4523 Add_One_Interp (N, Op_Id, Any_Fixed);
4525 elsif Is_Fixed_Point_Type (T2)
4526 and then (Base_Type (T1) = Base_Type (Standard_Integer)
4527 or else T1 = Universal_Integer)
4528 and then Op_Name = Name_Op_Multiply
4530 Add_One_Interp (N, Op_Id, T2);
4532 elsif T1 = Universal_Real and then T2 = Universal_Integer then
4533 Add_One_Interp (N, Op_Id, T1);
4535 elsif T2 = Universal_Real
4536 and then T1 = Universal_Integer
4537 and then Op_Name = Name_Op_Multiply
4539 Add_One_Interp (N, Op_Id, T2);
4542 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
4544 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
4545 -- set does not require any special processing, since the Etype is
4546 -- already set (case of operation constructed by Exp_Fixed).
4548 if Is_Integer_Type (T1)
4549 and then (Covers (T1 => T1, T2 => T2)
4551 Covers (T1 => T2, T2 => T1))
4553 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4556 elsif Op_Name = Name_Op_Expon then
4557 if Is_Numeric_Type (T1)
4558 and then not Is_Fixed_Point_Type (T1)
4559 and then (Base_Type (T2) = Base_Type (Standard_Integer)
4560 or else T2 = Universal_Integer)
4562 Add_One_Interp (N, Op_Id, Base_Type (T1));
4565 else pragma Assert (Nkind (N) in N_Op_Shift);
4567 -- If not one of the predefined operators, the node may be one
4568 -- of the intrinsic functions. Its kind is always specific, and
4569 -- we can use it directly, rather than the name of the operation.
4571 if Is_Integer_Type (T1)
4572 and then (Base_Type (T2) = Base_Type (Standard_Integer)
4573 or else T2 = Universal_Integer)
4575 Add_One_Interp (N, Op_Id, Base_Type (T1));
4578 end Check_Arithmetic_Pair;
4580 -------------------------------
4581 -- Check_Misspelled_Selector --
4582 -------------------------------
4584 procedure Check_Misspelled_Selector
4585 (Prefix : Entity_Id;
4588 Max_Suggestions : constant := 2;
4589 Nr_Of_Suggestions : Natural := 0;
4591 Suggestion_1 : Entity_Id := Empty;
4592 Suggestion_2 : Entity_Id := Empty;
4597 -- All the components of the prefix of selector Sel are matched
4598 -- against Sel and a count is maintained of possible misspellings.
4599 -- When at the end of the analysis there are one or two (not more!)
4600 -- possible misspellings, these misspellings will be suggested as
4601 -- possible correction.
4603 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
4605 -- Concurrent types should be handled as well ???
4610 Comp := First_Entity (Prefix);
4611 while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
4612 if Is_Visible_Component (Comp) then
4613 if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
4614 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
4616 case Nr_Of_Suggestions is
4617 when 1 => Suggestion_1 := Comp;
4618 when 2 => Suggestion_2 := Comp;
4619 when others => exit;
4624 Comp := Next_Entity (Comp);
4627 -- Report at most two suggestions
4629 if Nr_Of_Suggestions = 1 then
4630 Error_Msg_NE -- CODEFIX
4631 ("\possible misspelling of&", Sel, Suggestion_1);
4633 elsif Nr_Of_Suggestions = 2 then
4634 Error_Msg_Node_2 := Suggestion_2;
4635 Error_Msg_NE -- CODEFIX
4636 ("\possible misspelling of& or&", Sel, Suggestion_1);
4638 end Check_Misspelled_Selector;
4640 ----------------------
4641 -- Defined_In_Scope --
4642 ----------------------
4644 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
4646 S1 : constant Entity_Id := Scope (Base_Type (T));
4649 or else (S1 = System_Aux_Id and then S = Scope (S1));
4650 end Defined_In_Scope;
4656 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
4662 Void_Interp_Seen : Boolean := False;
4665 pragma Warnings (Off, Boolean);
4668 if Ada_Version >= Ada_05 then
4669 Actual := First_Actual (N);
4670 while Present (Actual) loop
4672 -- Ada 2005 (AI-50217): Post an error in case of premature
4673 -- usage of an entity from the limited view.
4675 if not Analyzed (Etype (Actual))
4676 and then From_With_Type (Etype (Actual))
4678 Error_Msg_Qual_Level := 1;
4680 ("missing with_clause for scope of imported type&",
4681 Actual, Etype (Actual));
4682 Error_Msg_Qual_Level := 0;
4685 Next_Actual (Actual);
4689 -- Analyze each candidate call again, with full error reporting
4693 ("no candidate interpretations match the actuals:!", Nam);
4694 Err_Mode := All_Errors_Mode;
4695 All_Errors_Mode := True;
4697 -- If this is a call to an operation of a concurrent type,
4698 -- the failed interpretations have been removed from the
4699 -- name. Recover them to provide full diagnostics.
4701 if Nkind (Parent (Nam)) = N_Selected_Component then
4702 Set_Entity (Nam, Empty);
4703 New_Nam := New_Copy_Tree (Parent (Nam));
4704 Set_Is_Overloaded (New_Nam, False);
4705 Set_Is_Overloaded (Selector_Name (New_Nam), False);
4706 Set_Parent (New_Nam, Parent (Parent (Nam)));
4707 Analyze_Selected_Component (New_Nam);
4708 Get_First_Interp (Selector_Name (New_Nam), X, It);
4710 Get_First_Interp (Nam, X, It);
4713 while Present (It.Nam) loop
4714 if Etype (It.Nam) = Standard_Void_Type then
4715 Void_Interp_Seen := True;
4718 Analyze_One_Call (N, It.Nam, True, Success);
4719 Get_Next_Interp (X, It);
4722 if Nkind (N) = N_Function_Call then
4723 Get_First_Interp (Nam, X, It);
4724 while Present (It.Nam) loop
4725 if Ekind_In (It.Nam, E_Function, E_Operator) then
4728 Get_Next_Interp (X, It);
4732 -- If all interpretations are procedures, this deserves a
4733 -- more precise message. Ditto if this appears as the prefix
4734 -- of a selected component, which may be a lexical error.
4737 ("\context requires function call, found procedure name", Nam);
4739 if Nkind (Parent (N)) = N_Selected_Component
4740 and then N = Prefix (Parent (N))
4742 Error_Msg_N -- CODEFIX
4743 ("\period should probably be semicolon", Parent (N));
4746 elsif Nkind (N) = N_Procedure_Call_Statement
4747 and then not Void_Interp_Seen
4750 "\function name found in procedure call", Nam);
4753 All_Errors_Mode := Err_Mode;
4756 ---------------------------
4757 -- Find_Arithmetic_Types --
4758 ---------------------------
4760 procedure Find_Arithmetic_Types
4765 Index1 : Interp_Index;
4766 Index2 : Interp_Index;
4770 procedure Check_Right_Argument (T : Entity_Id);
4771 -- Check right operand of operator
4773 --------------------------
4774 -- Check_Right_Argument --
4775 --------------------------
4777 procedure Check_Right_Argument (T : Entity_Id) is
4779 if not Is_Overloaded (R) then
4780 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
4782 Get_First_Interp (R, Index2, It2);
4783 while Present (It2.Typ) loop
4784 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
4785 Get_Next_Interp (Index2, It2);
4788 end Check_Right_Argument;
4790 -- Start of processing for Find_Arithmetic_Types
4793 if not Is_Overloaded (L) then
4794 Check_Right_Argument (Etype (L));
4797 Get_First_Interp (L, Index1, It1);
4798 while Present (It1.Typ) loop
4799 Check_Right_Argument (It1.Typ);
4800 Get_Next_Interp (Index1, It1);
4804 end Find_Arithmetic_Types;
4806 ------------------------
4807 -- Find_Boolean_Types --
4808 ------------------------
4810 procedure Find_Boolean_Types
4815 Index : Interp_Index;
4818 procedure Check_Numeric_Argument (T : Entity_Id);
4819 -- Special case for logical operations one of whose operands is an
4820 -- integer literal. If both are literal the result is any modular type.
4822 ----------------------------
4823 -- Check_Numeric_Argument --
4824 ----------------------------
4826 procedure Check_Numeric_Argument (T : Entity_Id) is
4828 if T = Universal_Integer then
4829 Add_One_Interp (N, Op_Id, Any_Modular);
4831 elsif Is_Modular_Integer_Type (T) then
4832 Add_One_Interp (N, Op_Id, T);
4834 end Check_Numeric_Argument;
4836 -- Start of processing for Find_Boolean_Types
4839 if not Is_Overloaded (L) then
4840 if Etype (L) = Universal_Integer
4841 or else Etype (L) = Any_Modular
4843 if not Is_Overloaded (R) then
4844 Check_Numeric_Argument (Etype (R));
4847 Get_First_Interp (R, Index, It);
4848 while Present (It.Typ) loop
4849 Check_Numeric_Argument (It.Typ);
4850 Get_Next_Interp (Index, It);
4854 -- If operands are aggregates, we must assume that they may be
4855 -- boolean arrays, and leave disambiguation for the second pass.
4856 -- If only one is an aggregate, verify that the other one has an
4857 -- interpretation as a boolean array
4859 elsif Nkind (L) = N_Aggregate then
4860 if Nkind (R) = N_Aggregate then
4861 Add_One_Interp (N, Op_Id, Etype (L));
4863 elsif not Is_Overloaded (R) then
4864 if Valid_Boolean_Arg (Etype (R)) then
4865 Add_One_Interp (N, Op_Id, Etype (R));
4869 Get_First_Interp (R, Index, It);
4870 while Present (It.Typ) loop
4871 if Valid_Boolean_Arg (It.Typ) then
4872 Add_One_Interp (N, Op_Id, It.Typ);
4875 Get_Next_Interp (Index, It);
4879 elsif Valid_Boolean_Arg (Etype (L))
4880 and then Has_Compatible_Type (R, Etype (L))
4882 Add_One_Interp (N, Op_Id, Etype (L));
4886 Get_First_Interp (L, Index, It);
4887 while Present (It.Typ) loop
4888 if Valid_Boolean_Arg (It.Typ)
4889 and then Has_Compatible_Type (R, It.Typ)
4891 Add_One_Interp (N, Op_Id, It.Typ);
4894 Get_Next_Interp (Index, It);
4897 end Find_Boolean_Types;
4899 ---------------------------
4900 -- Find_Comparison_Types --
4901 ---------------------------
4903 procedure Find_Comparison_Types
4908 Index : Interp_Index;
4910 Found : Boolean := False;
4913 Scop : Entity_Id := Empty;
4915 procedure Try_One_Interp (T1 : Entity_Id);
4916 -- Routine to try one proposed interpretation. Note that the context
4917 -- of the operator plays no role in resolving the arguments, so that
4918 -- if there is more than one interpretation of the operands that is
4919 -- compatible with comparison, the operation is ambiguous.
4921 --------------------
4922 -- Try_One_Interp --
4923 --------------------
4925 procedure Try_One_Interp (T1 : Entity_Id) is
4928 -- If the operator is an expanded name, then the type of the operand
4929 -- must be defined in the corresponding scope. If the type is
4930 -- universal, the context will impose the correct type.
4933 and then not Defined_In_Scope (T1, Scop)
4934 and then T1 /= Universal_Integer
4935 and then T1 /= Universal_Real
4936 and then T1 /= Any_String
4937 and then T1 /= Any_Composite
4942 if Valid_Comparison_Arg (T1)
4943 and then Has_Compatible_Type (R, T1)
4946 and then Base_Type (T1) /= Base_Type (T_F)
4948 It := Disambiguate (L, I_F, Index, Any_Type);
4950 if It = No_Interp then
4951 Ambiguous_Operands (N);
4952 Set_Etype (L, Any_Type);
4966 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
4971 -- Start of processing for Find_Comparison_Types
4974 -- If left operand is aggregate, the right operand has to
4975 -- provide a usable type for it.
4977 if Nkind (L) = N_Aggregate
4978 and then Nkind (R) /= N_Aggregate
4980 Find_Comparison_Types (L => R, R => L, Op_Id => Op_Id, N => N);
4984 if Nkind (N) = N_Function_Call
4985 and then Nkind (Name (N)) = N_Expanded_Name
4987 Scop := Entity (Prefix (Name (N)));
4989 -- The prefix may be a package renaming, and the subsequent test
4990 -- requires the original package.
4992 if Ekind (Scop) = E_Package
4993 and then Present (Renamed_Entity (Scop))
4995 Scop := Renamed_Entity (Scop);
4996 Set_Entity (Prefix (Name (N)), Scop);
5000 if not Is_Overloaded (L) then
5001 Try_One_Interp (Etype (L));
5004 Get_First_Interp (L, Index, It);
5005 while Present (It.Typ) loop
5006 Try_One_Interp (It.Typ);
5007 Get_Next_Interp (Index, It);
5010 end Find_Comparison_Types;
5012 ----------------------------------------
5013 -- Find_Non_Universal_Interpretations --
5014 ----------------------------------------
5016 procedure Find_Non_Universal_Interpretations
5022 Index : Interp_Index;
5026 if T1 = Universal_Integer
5027 or else T1 = Universal_Real
5029 if not Is_Overloaded (R) then
5031 (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
5033 Get_First_Interp (R, Index, It);
5034 while Present (It.Typ) loop
5035 if Covers (It.Typ, T1) then
5037 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
5040 Get_Next_Interp (Index, It);
5044 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
5046 end Find_Non_Universal_Interpretations;
5048 ------------------------------
5049 -- Find_Concatenation_Types --
5050 ------------------------------
5052 procedure Find_Concatenation_Types
5057 Op_Type : constant Entity_Id := Etype (Op_Id);
5060 if Is_Array_Type (Op_Type)
5061 and then not Is_Limited_Type (Op_Type)
5063 and then (Has_Compatible_Type (L, Op_Type)
5065 Has_Compatible_Type (L, Component_Type (Op_Type)))
5067 and then (Has_Compatible_Type (R, Op_Type)
5069 Has_Compatible_Type (R, Component_Type (Op_Type)))
5071 Add_One_Interp (N, Op_Id, Op_Type);
5073 end Find_Concatenation_Types;
5075 -------------------------
5076 -- Find_Equality_Types --
5077 -------------------------
5079 procedure Find_Equality_Types
5084 Index : Interp_Index;
5086 Found : Boolean := False;
5089 Scop : Entity_Id := Empty;
5091 procedure Try_One_Interp (T1 : Entity_Id);
5092 -- The context of the equality operator plays no role in resolving the
5093 -- arguments, so that if there is more than one interpretation of the
5094 -- operands that is compatible with equality, the construct is ambiguous
5095 -- and an error can be emitted now, after trying to disambiguate, i.e.
5096 -- applying preference rules.
5098 --------------------
5099 -- Try_One_Interp --
5100 --------------------
5102 procedure Try_One_Interp (T1 : Entity_Id) is
5103 Bas : constant Entity_Id := Base_Type (T1);
5106 -- If the operator is an expanded name, then the type of the operand
5107 -- must be defined in the corresponding scope. If the type is
5108 -- universal, the context will impose the correct type. An anonymous
5109 -- type for a 'Access reference is also universal in this sense, as
5110 -- the actual type is obtained from context.
5111 -- In Ada 2005, the equality operator for anonymous access types
5112 -- is declared in Standard, and preference rules apply to it.
5114 if Present (Scop) then
5115 if Defined_In_Scope (T1, Scop)
5116 or else T1 = Universal_Integer
5117 or else T1 = Universal_Real
5118 or else T1 = Any_Access
5119 or else T1 = Any_String
5120 or else T1 = Any_Composite
5121 or else (Ekind (T1) = E_Access_Subprogram_Type
5122 and then not Comes_From_Source (T1))
5126 elsif Ekind (T1) = E_Anonymous_Access_Type
5127 and then Scop = Standard_Standard
5132 -- The scope does not contain an operator for the type
5137 -- If we have infix notation, the operator must be usable.
5138 -- Within an instance, if the type is already established we
5139 -- know it is correct.
5140 -- In Ada 2005, the equality on anonymous access types is declared
5141 -- in Standard, and is always visible.
5143 elsif In_Open_Scopes (Scope (Bas))
5144 or else Is_Potentially_Use_Visible (Bas)
5145 or else In_Use (Bas)
5146 or else (In_Use (Scope (Bas))
5147 and then not Is_Hidden (Bas))
5148 or else (In_Instance
5149 and then First_Subtype (T1) = First_Subtype (Etype (R)))
5150 or else Ekind (T1) = E_Anonymous_Access_Type
5155 -- Save candidate type for subsquent error message, if any
5157 if not Is_Limited_Type (T1) then
5158 Candidate_Type := T1;
5164 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
5165 -- Do not allow anonymous access types in equality operators.
5167 if Ada_Version < Ada_05
5168 and then Ekind (T1) = E_Anonymous_Access_Type
5173 if T1 /= Standard_Void_Type
5174 and then not Is_Limited_Type (T1)
5175 and then not Is_Limited_Composite (T1)
5176 and then Has_Compatible_Type (R, T1)
5179 and then Base_Type (T1) /= Base_Type (T_F)
5181 It := Disambiguate (L, I_F, Index, Any_Type);
5183 if It = No_Interp then
5184 Ambiguous_Operands (N);
5185 Set_Etype (L, Any_Type);
5198 if not Analyzed (L) then
5202 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
5204 -- Case of operator was not visible, Etype still set to Any_Type
5206 if Etype (N) = Any_Type then
5210 elsif Scop = Standard_Standard
5211 and then Ekind (T1) = E_Anonymous_Access_Type
5217 -- Start of processing for Find_Equality_Types
5220 -- If left operand is aggregate, the right operand has to
5221 -- provide a usable type for it.
5223 if Nkind (L) = N_Aggregate
5224 and then Nkind (R) /= N_Aggregate
5226 Find_Equality_Types (L => R, R => L, Op_Id => Op_Id, N => N);
5230 if Nkind (N) = N_Function_Call
5231 and then Nkind (Name (N)) = N_Expanded_Name
5233 Scop := Entity (Prefix (Name (N)));
5235 -- The prefix may be a package renaming, and the subsequent test
5236 -- requires the original package.
5238 if Ekind (Scop) = E_Package
5239 and then Present (Renamed_Entity (Scop))
5241 Scop := Renamed_Entity (Scop);
5242 Set_Entity (Prefix (Name (N)), Scop);
5246 if not Is_Overloaded (L) then
5247 Try_One_Interp (Etype (L));
5250 Get_First_Interp (L, Index, It);
5251 while Present (It.Typ) loop
5252 Try_One_Interp (It.Typ);
5253 Get_Next_Interp (Index, It);
5256 end Find_Equality_Types;
5258 -------------------------
5259 -- Find_Negation_Types --
5260 -------------------------
5262 procedure Find_Negation_Types
5267 Index : Interp_Index;
5271 if not Is_Overloaded (R) then
5272 if Etype (R) = Universal_Integer then
5273 Add_One_Interp (N, Op_Id, Any_Modular);
5274 elsif Valid_Boolean_Arg (Etype (R)) then
5275 Add_One_Interp (N, Op_Id, Etype (R));
5279 Get_First_Interp (R, Index, It);
5280 while Present (It.Typ) loop
5281 if Valid_Boolean_Arg (It.Typ) then
5282 Add_One_Interp (N, Op_Id, It.Typ);
5285 Get_Next_Interp (Index, It);
5288 end Find_Negation_Types;
5290 ------------------------------
5291 -- Find_Primitive_Operation --
5292 ------------------------------
5294 function Find_Primitive_Operation (N : Node_Id) return Boolean is
5295 Obj : constant Node_Id := Prefix (N);
5296 Op : constant Node_Id := Selector_Name (N);
5303 Set_Etype (Op, Any_Type);
5305 if Is_Access_Type (Etype (Obj)) then
5306 Typ := Designated_Type (Etype (Obj));
5311 if Is_Class_Wide_Type (Typ) then
5312 Typ := Root_Type (Typ);
5315 Prims := Primitive_Operations (Typ);
5317 Prim := First_Elmt (Prims);
5318 while Present (Prim) loop
5319 if Chars (Node (Prim)) = Chars (Op) then
5320 Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
5321 Set_Etype (N, Etype (Node (Prim)));
5327 -- Now look for class-wide operations of the type or any of its
5328 -- ancestors by iterating over the homonyms of the selector.
5331 Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
5335 Hom := Current_Entity (Op);
5336 while Present (Hom) loop
5337 if (Ekind (Hom) = E_Procedure
5339 Ekind (Hom) = E_Function)
5340 and then Scope (Hom) = Scope (Typ)
5341 and then Present (First_Formal (Hom))
5343 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
5345 (Is_Access_Type (Etype (First_Formal (Hom)))
5347 Ekind (Etype (First_Formal (Hom))) =
5348 E_Anonymous_Access_Type
5351 (Designated_Type (Etype (First_Formal (Hom)))) =
5354 Add_One_Interp (Op, Hom, Etype (Hom));
5355 Set_Etype (N, Etype (Hom));
5358 Hom := Homonym (Hom);
5362 return Etype (Op) /= Any_Type;
5363 end Find_Primitive_Operation;
5365 ----------------------
5366 -- Find_Unary_Types --
5367 ----------------------
5369 procedure Find_Unary_Types
5374 Index : Interp_Index;
5378 if not Is_Overloaded (R) then
5379 if Is_Numeric_Type (Etype (R)) then
5380 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
5384 Get_First_Interp (R, Index, It);
5385 while Present (It.Typ) loop
5386 if Is_Numeric_Type (It.Typ) then
5387 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
5390 Get_Next_Interp (Index, It);
5393 end Find_Unary_Types;
5399 function Junk_Operand (N : Node_Id) return Boolean is
5403 if Error_Posted (N) then
5407 -- Get entity to be tested
5409 if Is_Entity_Name (N)
5410 and then Present (Entity (N))
5414 -- An odd case, a procedure name gets converted to a very peculiar
5415 -- function call, and here is where we detect this happening.
5417 elsif Nkind (N) = N_Function_Call
5418 and then Is_Entity_Name (Name (N))
5419 and then Present (Entity (Name (N)))
5423 -- Another odd case, there are at least some cases of selected
5424 -- components where the selected component is not marked as having
5425 -- an entity, even though the selector does have an entity
5427 elsif Nkind (N) = N_Selected_Component
5428 and then Present (Entity (Selector_Name (N)))
5430 Enode := Selector_Name (N);
5436 -- Now test the entity we got to see if it is a bad case
5438 case Ekind (Entity (Enode)) is
5442 ("package name cannot be used as operand", Enode);
5444 when Generic_Unit_Kind =>
5446 ("generic unit name cannot be used as operand", Enode);
5450 ("subtype name cannot be used as operand", Enode);
5454 ("entry name cannot be used as operand", Enode);
5458 ("procedure name cannot be used as operand", Enode);
5462 ("exception name cannot be used as operand", Enode);
5464 when E_Block | E_Label | E_Loop =>
5466 ("label name cannot be used as operand", Enode);
5476 --------------------
5477 -- Operator_Check --
5478 --------------------
5480 procedure Operator_Check (N : Node_Id) is
5482 Remove_Abstract_Operations (N);
5484 -- Test for case of no interpretation found for operator
5486 if Etype (N) = Any_Type then
5490 Op_Id : Entity_Id := Empty;
5493 R := Right_Opnd (N);
5495 if Nkind (N) in N_Binary_Op then
5501 -- If either operand has no type, then don't complain further,
5502 -- since this simply means that we have a propagated error.
5505 or else Etype (R) = Any_Type
5506 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
5510 -- We explicitly check for the case of concatenation of component
5511 -- with component to avoid reporting spurious matching array types
5512 -- that might happen to be lurking in distant packages (such as
5513 -- run-time packages). This also prevents inconsistencies in the
5514 -- messages for certain ACVC B tests, which can vary depending on
5515 -- types declared in run-time interfaces. Another improvement when
5516 -- aggregates are present is to look for a well-typed operand.
5518 elsif Present (Candidate_Type)
5519 and then (Nkind (N) /= N_Op_Concat
5520 or else Is_Array_Type (Etype (L))
5521 or else Is_Array_Type (Etype (R)))
5524 if Nkind (N) = N_Op_Concat then
5525 if Etype (L) /= Any_Composite
5526 and then Is_Array_Type (Etype (L))
5528 Candidate_Type := Etype (L);
5530 elsif Etype (R) /= Any_Composite
5531 and then Is_Array_Type (Etype (R))
5533 Candidate_Type := Etype (R);
5537 Error_Msg_NE -- CODEFIX
5538 ("operator for} is not directly visible!",
5539 N, First_Subtype (Candidate_Type));
5540 Error_Msg_N -- CODEFIX
5541 ("use clause would make operation legal!", N);
5544 -- If either operand is a junk operand (e.g. package name), then
5545 -- post appropriate error messages, but do not complain further.
5547 -- Note that the use of OR in this test instead of OR ELSE is
5548 -- quite deliberate, we may as well check both operands in the
5549 -- binary operator case.
5551 elsif Junk_Operand (R)
5552 or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
5556 -- If we have a logical operator, one of whose operands is
5557 -- Boolean, then we know that the other operand cannot resolve to
5558 -- Boolean (since we got no interpretations), but in that case we
5559 -- pretty much know that the other operand should be Boolean, so
5560 -- resolve it that way (generating an error)
5562 elsif Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor) then
5563 if Etype (L) = Standard_Boolean then
5564 Resolve (R, Standard_Boolean);
5566 elsif Etype (R) = Standard_Boolean then
5567 Resolve (L, Standard_Boolean);
5571 -- For an arithmetic operator or comparison operator, if one
5572 -- of the operands is numeric, then we know the other operand
5573 -- is not the same numeric type. If it is a non-numeric type,
5574 -- then probably it is intended to match the other operand.
5576 elsif Nkind_In (N, N_Op_Add,
5582 Nkind_In (N, N_Op_Lt,
5588 if Is_Numeric_Type (Etype (L))
5589 and then not Is_Numeric_Type (Etype (R))
5591 Resolve (R, Etype (L));
5594 elsif Is_Numeric_Type (Etype (R))
5595 and then not Is_Numeric_Type (Etype (L))
5597 Resolve (L, Etype (R));
5601 -- Comparisons on A'Access are common enough to deserve a
5604 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne)
5605 and then Ekind (Etype (L)) = E_Access_Attribute_Type
5606 and then Ekind (Etype (R)) = E_Access_Attribute_Type
5609 ("two access attributes cannot be compared directly", N);
5611 ("\use qualified expression for one of the operands",
5615 -- Another one for C programmers
5617 elsif Nkind (N) = N_Op_Concat
5618 and then Valid_Boolean_Arg (Etype (L))
5619 and then Valid_Boolean_Arg (Etype (R))
5621 Error_Msg_N ("invalid operands for concatenation", N);
5622 Error_Msg_N -- CODEFIX
5623 ("\maybe AND was meant", N);
5626 -- A special case for comparison of access parameter with null
5628 elsif Nkind (N) = N_Op_Eq
5629 and then Is_Entity_Name (L)
5630 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
5631 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
5633 and then Nkind (R) = N_Null
5635 Error_Msg_N ("access parameter is not allowed to be null", L);
5636 Error_Msg_N ("\(call would raise Constraint_Error)", L);
5639 -- Another special case for exponentiation, where the right
5640 -- operand must be Natural, independently of the base.
5642 elsif Nkind (N) = N_Op_Expon
5643 and then Is_Numeric_Type (Etype (L))
5644 and then not Is_Overloaded (R)
5646 First_Subtype (Base_Type (Etype (R))) /= Standard_Integer
5647 and then Base_Type (Etype (R)) /= Universal_Integer
5650 ("exponent must be of type Natural, found}", R, Etype (R));
5654 -- If we fall through then just give general message. Note that in
5655 -- the following messages, if the operand is overloaded we choose
5656 -- an arbitrary type to complain about, but that is probably more
5657 -- useful than not giving a type at all.
5659 if Nkind (N) in N_Unary_Op then
5660 Error_Msg_Node_2 := Etype (R);
5661 Error_Msg_N ("operator& not defined for}", N);
5665 if Nkind (N) in N_Binary_Op then
5666 if not Is_Overloaded (L)
5667 and then not Is_Overloaded (R)
5668 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
5670 Error_Msg_Node_2 := First_Subtype (Etype (R));
5671 Error_Msg_N ("there is no applicable operator& for}", N);
5674 -- Another attempt to find a fix: one of the candidate
5675 -- interpretations may not be use-visible. This has
5676 -- already been checked for predefined operators, so
5677 -- we examine only user-defined functions.
5679 Op_Id := Get_Name_Entity_Id (Chars (N));
5681 while Present (Op_Id) loop
5682 if Ekind (Op_Id) /= E_Operator
5683 and then Is_Overloadable (Op_Id)
5685 if not Is_Immediately_Visible (Op_Id)
5686 and then not In_Use (Scope (Op_Id))
5687 and then not Is_Abstract_Subprogram (Op_Id)
5688 and then not Is_Hidden (Op_Id)
5689 and then Ekind (Scope (Op_Id)) = E_Package
5692 (L, Etype (First_Formal (Op_Id)))
5694 (Next_Formal (First_Formal (Op_Id)))
5698 Etype (Next_Formal (First_Formal (Op_Id))))
5701 ("No legal interpretation for operator&", N);
5703 ("\use clause on& would make operation legal",
5709 Op_Id := Homonym (Op_Id);
5713 Error_Msg_N ("invalid operand types for operator&", N);
5715 if Nkind (N) /= N_Op_Concat then
5716 Error_Msg_NE ("\left operand has}!", N, Etype (L));
5717 Error_Msg_NE ("\right operand has}!", N, Etype (R));
5727 -----------------------------------------
5728 -- Process_Implicit_Dereference_Prefix --
5729 -----------------------------------------
5731 function Process_Implicit_Dereference_Prefix
5733 P : Entity_Id) return Entity_Id
5736 Typ : constant Entity_Id := Designated_Type (Etype (P));
5740 and then (Operating_Mode = Check_Semantics or else not Expander_Active)
5742 -- We create a dummy reference to E to ensure that the reference
5743 -- is not considered as part of an assignment (an implicit
5744 -- dereference can never assign to its prefix). The Comes_From_Source
5745 -- attribute needs to be propagated for accurate warnings.
5747 Ref := New_Reference_To (E, Sloc (P));
5748 Set_Comes_From_Source (Ref, Comes_From_Source (P));
5749 Generate_Reference (E, Ref);
5752 -- An implicit dereference is a legal occurrence of an
5753 -- incomplete type imported through a limited_with clause,
5754 -- if the full view is visible.
5756 if From_With_Type (Typ)
5757 and then not From_With_Type (Scope (Typ))
5759 (Is_Immediately_Visible (Scope (Typ))
5761 (Is_Child_Unit (Scope (Typ))
5762 and then Is_Visible_Child_Unit (Scope (Typ))))
5764 return Available_View (Typ);
5769 end Process_Implicit_Dereference_Prefix;
5771 --------------------------------
5772 -- Remove_Abstract_Operations --
5773 --------------------------------
5775 procedure Remove_Abstract_Operations (N : Node_Id) is
5776 Abstract_Op : Entity_Id := Empty;
5777 Address_Kludge : Boolean := False;
5781 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
5782 -- activate this if either extensions are enabled, or if the abstract
5783 -- operation in question comes from a predefined file. This latter test
5784 -- allows us to use abstract to make operations invisible to users. In
5785 -- particular, if type Address is non-private and abstract subprograms
5786 -- are used to hide its operators, they will be truly hidden.
5788 type Operand_Position is (First_Op, Second_Op);
5789 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
5791 procedure Remove_Address_Interpretations (Op : Operand_Position);
5792 -- Ambiguities may arise when the operands are literal and the address
5793 -- operations in s-auxdec are visible. In that case, remove the
5794 -- interpretation of a literal as Address, to retain the semantics of
5795 -- Address as a private type.
5797 ------------------------------------
5798 -- Remove_Address_Interpretations --
5799 ------------------------------------
5801 procedure Remove_Address_Interpretations (Op : Operand_Position) is
5805 if Is_Overloaded (N) then
5806 Get_First_Interp (N, I, It);
5807 while Present (It.Nam) loop
5808 Formal := First_Entity (It.Nam);
5810 if Op = Second_Op then
5811 Formal := Next_Entity (Formal);
5814 if Is_Descendent_Of_Address (Etype (Formal)) then
5815 Address_Kludge := True;
5819 Get_Next_Interp (I, It);
5822 end Remove_Address_Interpretations;
5824 -- Start of processing for Remove_Abstract_Operations
5827 if Is_Overloaded (N) then
5828 Get_First_Interp (N, I, It);
5830 while Present (It.Nam) loop
5831 if Is_Overloadable (It.Nam)
5832 and then Is_Abstract_Subprogram (It.Nam)
5833 and then not Is_Dispatching_Operation (It.Nam)
5835 Abstract_Op := It.Nam;
5837 if Is_Descendent_Of_Address (It.Typ) then
5838 Address_Kludge := True;
5842 -- In Ada 2005, this operation does not participate in Overload
5843 -- resolution. If the operation is defined in a predefined
5844 -- unit, it is one of the operations declared abstract in some
5845 -- variants of System, and it must be removed as well.
5847 elsif Ada_Version >= Ada_05
5848 or else Is_Predefined_File_Name
5849 (Unit_File_Name (Get_Source_Unit (It.Nam)))
5856 Get_Next_Interp (I, It);
5859 if No (Abstract_Op) then
5861 -- If some interpretation yields an integer type, it is still
5862 -- possible that there are address interpretations. Remove them
5863 -- if one operand is a literal, to avoid spurious ambiguities
5864 -- on systems where Address is a visible integer type.
5866 if Is_Overloaded (N)
5867 and then Nkind (N) in N_Op
5868 and then Is_Integer_Type (Etype (N))
5870 if Nkind (N) in N_Binary_Op then
5871 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
5872 Remove_Address_Interpretations (Second_Op);
5874 elsif Nkind (Right_Opnd (N)) = N_Integer_Literal then
5875 Remove_Address_Interpretations (First_Op);
5880 elsif Nkind (N) in N_Op then
5882 -- Remove interpretations that treat literals as addresses. This
5883 -- is never appropriate, even when Address is defined as a visible
5884 -- Integer type. The reason is that we would really prefer Address
5885 -- to behave as a private type, even in this case, which is there
5886 -- only to accommodate oddities of VMS address sizes. If Address
5887 -- is a visible integer type, we get lots of overload ambiguities.
5889 if Nkind (N) in N_Binary_Op then
5891 U1 : constant Boolean :=
5892 Present (Universal_Interpretation (Right_Opnd (N)));
5893 U2 : constant Boolean :=
5894 Present (Universal_Interpretation (Left_Opnd (N)));
5898 Remove_Address_Interpretations (Second_Op);
5902 Remove_Address_Interpretations (First_Op);
5905 if not (U1 and U2) then
5907 -- Remove corresponding predefined operator, which is
5908 -- always added to the overload set.
5910 Get_First_Interp (N, I, It);
5911 while Present (It.Nam) loop
5912 if Scope (It.Nam) = Standard_Standard
5913 and then Base_Type (It.Typ) =
5914 Base_Type (Etype (Abstract_Op))
5919 Get_Next_Interp (I, It);
5922 elsif Is_Overloaded (N)
5923 and then Present (Univ_Type)
5925 -- If both operands have a universal interpretation,
5926 -- it is still necessary to remove interpretations that
5927 -- yield Address. Any remaining ambiguities will be
5928 -- removed in Disambiguate.
5930 Get_First_Interp (N, I, It);
5931 while Present (It.Nam) loop
5932 if Is_Descendent_Of_Address (It.Typ) then
5935 elsif not Is_Type (It.Nam) then
5936 Set_Entity (N, It.Nam);
5939 Get_Next_Interp (I, It);
5945 elsif Nkind (N) = N_Function_Call
5947 (Nkind (Name (N)) = N_Operator_Symbol
5949 (Nkind (Name (N)) = N_Expanded_Name
5951 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
5955 Arg1 : constant Node_Id := First (Parameter_Associations (N));
5956 U1 : constant Boolean :=
5957 Present (Universal_Interpretation (Arg1));
5958 U2 : constant Boolean :=
5959 Present (Next (Arg1)) and then
5960 Present (Universal_Interpretation (Next (Arg1)));
5964 Remove_Address_Interpretations (First_Op);
5968 Remove_Address_Interpretations (Second_Op);
5971 if not (U1 and U2) then
5972 Get_First_Interp (N, I, It);
5973 while Present (It.Nam) loop
5974 if Scope (It.Nam) = Standard_Standard
5975 and then It.Typ = Base_Type (Etype (Abstract_Op))
5980 Get_Next_Interp (I, It);
5986 -- If the removal has left no valid interpretations, emit an error
5987 -- message now and label node as illegal.
5989 if Present (Abstract_Op) then
5990 Get_First_Interp (N, I, It);
5994 -- Removal of abstract operation left no viable candidate
5996 Set_Etype (N, Any_Type);
5997 Error_Msg_Sloc := Sloc (Abstract_Op);
5999 ("cannot call abstract operation& declared#", N, Abstract_Op);
6001 -- In Ada 2005, an abstract operation may disable predefined
6002 -- operators. Since the context is not yet known, we mark the
6003 -- predefined operators as potentially hidden. Do not include
6004 -- predefined operators when addresses are involved since this
6005 -- case is handled separately.
6007 elsif Ada_Version >= Ada_05
6008 and then not Address_Kludge
6010 while Present (It.Nam) loop
6011 if Is_Numeric_Type (It.Typ)
6012 and then Scope (It.Typ) = Standard_Standard
6014 Set_Abstract_Op (I, Abstract_Op);
6017 Get_Next_Interp (I, It);
6022 end Remove_Abstract_Operations;
6024 -----------------------
6025 -- Try_Indirect_Call --
6026 -----------------------
6028 function Try_Indirect_Call
6031 Typ : Entity_Id) return Boolean
6037 pragma Warnings (Off, Call_OK);
6040 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
6042 Actual := First_Actual (N);
6043 Formal := First_Formal (Designated_Type (Typ));
6044 while Present (Actual) and then Present (Formal) loop
6045 if not Has_Compatible_Type (Actual, Etype (Formal)) then
6050 Next_Formal (Formal);
6053 if No (Actual) and then No (Formal) then
6054 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
6056 -- Nam is a candidate interpretation for the name in the call,
6057 -- if it is not an indirect call.
6059 if not Is_Type (Nam)
6060 and then Is_Entity_Name (Name (N))
6062 Set_Entity (Name (N), Nam);
6069 end Try_Indirect_Call;
6071 ----------------------
6072 -- Try_Indexed_Call --
6073 ----------------------
6075 function Try_Indexed_Call
6079 Skip_First : Boolean) return Boolean
6081 Loc : constant Source_Ptr := Sloc (N);
6082 Actuals : constant List_Id := Parameter_Associations (N);
6087 Actual := First (Actuals);
6089 -- If the call was originally written in prefix form, skip the first
6090 -- actual, which is obviously not defaulted.
6096 Index := First_Index (Typ);
6097 while Present (Actual) and then Present (Index) loop
6099 -- If the parameter list has a named association, the expression
6100 -- is definitely a call and not an indexed component.
6102 if Nkind (Actual) = N_Parameter_Association then
6106 if Is_Entity_Name (Actual)
6107 and then Is_Type (Entity (Actual))
6108 and then No (Next (Actual))
6110 -- A single actual that is a type name indicates a slice if the
6111 -- type is discrete, and an error otherwise.
6113 if Is_Discrete_Type (Entity (Actual)) then
6117 Make_Function_Call (Loc,
6118 Name => Relocate_Node (Name (N))),
6120 New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
6125 Error_Msg_N ("invalid use of type in expression", Actual);
6126 Set_Etype (N, Any_Type);
6131 elsif not Has_Compatible_Type (Actual, Etype (Index)) then
6139 if No (Actual) and then No (Index) then
6140 Add_One_Interp (N, Nam, Component_Type (Typ));
6142 -- Nam is a candidate interpretation for the name in the call,
6143 -- if it is not an indirect call.
6145 if not Is_Type (Nam)
6146 and then Is_Entity_Name (Name (N))
6148 Set_Entity (Name (N), Nam);
6155 end Try_Indexed_Call;
6157 --------------------------
6158 -- Try_Object_Operation --
6159 --------------------------
6161 function Try_Object_Operation (N : Node_Id) return Boolean is
6162 K : constant Node_Kind := Nkind (Parent (N));
6163 Is_Subprg_Call : constant Boolean := Nkind_In
6164 (K, N_Procedure_Call_Statement,
6166 Loc : constant Source_Ptr := Sloc (N);
6167 Obj : constant Node_Id := Prefix (N);
6169 Subprog : constant Node_Id :=
6170 Make_Identifier (Sloc (Selector_Name (N)),
6171 Chars => Chars (Selector_Name (N)));
6172 -- Identifier on which possible interpretations will be collected
6174 Report_Error : Boolean := False;
6175 -- If no candidate interpretation matches the context, redo the
6176 -- analysis with error enabled to provide additional information.
6179 Candidate : Entity_Id := Empty;
6180 New_Call_Node : Node_Id := Empty;
6181 Node_To_Replace : Node_Id;
6182 Obj_Type : Entity_Id := Etype (Obj);
6183 Success : Boolean := False;
6185 function Valid_Candidate
6188 Subp : Entity_Id) return Entity_Id;
6189 -- If the subprogram is a valid interpretation, record it, and add
6190 -- to the list of interpretations of Subprog.
6192 procedure Complete_Object_Operation
6193 (Call_Node : Node_Id;
6194 Node_To_Replace : Node_Id);
6195 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
6196 -- Call_Node, insert the object (or its dereference) as the first actual
6197 -- in the call, and complete the analysis of the call.
6199 procedure Report_Ambiguity (Op : Entity_Id);
6200 -- If a prefixed procedure call is ambiguous, indicate whether the
6201 -- call includes an implicit dereference or an implicit 'Access.
6203 procedure Transform_Object_Operation
6204 (Call_Node : out Node_Id;
6205 Node_To_Replace : out Node_Id);
6206 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
6207 -- Call_Node is the resulting subprogram call, Node_To_Replace is
6208 -- either N or the parent of N, and Subprog is a reference to the
6209 -- subprogram we are trying to match.
6211 function Try_Class_Wide_Operation
6212 (Call_Node : Node_Id;
6213 Node_To_Replace : Node_Id) return Boolean;
6214 -- Traverse all ancestor types looking for a class-wide subprogram
6215 -- for which the current operation is a valid non-dispatching call.
6217 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
6218 -- If prefix is overloaded, its interpretation may include different
6219 -- tagged types, and we must examine the primitive operations and
6220 -- the class-wide operations of each in order to find candidate
6221 -- interpretations for the call as a whole.
6223 function Try_Primitive_Operation
6224 (Call_Node : Node_Id;
6225 Node_To_Replace : Node_Id) return Boolean;
6226 -- Traverse the list of primitive subprograms looking for a dispatching
6227 -- operation for which the current node is a valid call .
6229 ---------------------
6230 -- Valid_Candidate --
6231 ---------------------
6233 function Valid_Candidate
6236 Subp : Entity_Id) return Entity_Id
6238 Arr_Type : Entity_Id;
6239 Comp_Type : Entity_Id;
6242 -- If the subprogram is a valid interpretation, record it in global
6243 -- variable Subprog, to collect all possible overloadings.
6246 if Subp /= Entity (Subprog) then
6247 Add_One_Interp (Subprog, Subp, Etype (Subp));
6251 -- If the call may be an indexed call, retrieve component type of
6252 -- resulting expression, and add possible interpretation.
6257 if Nkind (Call) = N_Function_Call
6258 and then Nkind (Parent (N)) = N_Indexed_Component
6259 and then Needs_One_Actual (Subp)
6261 if Is_Array_Type (Etype (Subp)) then
6262 Arr_Type := Etype (Subp);
6264 elsif Is_Access_Type (Etype (Subp))
6265 and then Is_Array_Type (Designated_Type (Etype (Subp)))
6267 Arr_Type := Designated_Type (Etype (Subp));
6271 if Present (Arr_Type) then
6273 -- Verify that the actuals (excluding the object)
6274 -- match the types of the indices.
6281 Actual := Next (First_Actual (Call));
6282 Index := First_Index (Arr_Type);
6283 while Present (Actual) and then Present (Index) loop
6284 if not Has_Compatible_Type (Actual, Etype (Index)) then
6289 Next_Actual (Actual);
6295 and then Present (Arr_Type)
6297 Comp_Type := Component_Type (Arr_Type);
6301 if Present (Comp_Type)
6302 and then Etype (Subprog) /= Comp_Type
6304 Add_One_Interp (Subprog, Subp, Comp_Type);
6308 if Etype (Call) /= Any_Type then
6313 end Valid_Candidate;
6315 -------------------------------
6316 -- Complete_Object_Operation --
6317 -------------------------------
6319 procedure Complete_Object_Operation
6320 (Call_Node : Node_Id;
6321 Node_To_Replace : Node_Id)
6323 Control : constant Entity_Id := First_Formal (Entity (Subprog));
6324 Formal_Type : constant Entity_Id := Etype (Control);
6325 First_Actual : Node_Id;
6328 -- Place the name of the operation, with its interpretations,
6329 -- on the rewritten call.
6331 Set_Name (Call_Node, Subprog);
6333 First_Actual := First (Parameter_Associations (Call_Node));
6335 -- For cross-reference purposes, treat the new node as being in
6336 -- the source if the original one is.
6338 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
6339 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
6341 if Nkind (N) = N_Selected_Component
6342 and then not Inside_A_Generic
6344 Set_Entity (Selector_Name (N), Entity (Subprog));
6347 -- If need be, rewrite first actual as an explicit dereference
6348 -- If the call is overloaded, the rewriting can only be done
6349 -- once the primitive operation is identified.
6351 if Is_Overloaded (Subprog) then
6353 -- The prefix itself may be overloaded, and its interpretations
6354 -- must be propagated to the new actual in the call.
6356 if Is_Overloaded (Obj) then
6357 Save_Interps (Obj, First_Actual);
6360 Rewrite (First_Actual, Obj);
6362 elsif not Is_Access_Type (Formal_Type)
6363 and then Is_Access_Type (Etype (Obj))
6365 Rewrite (First_Actual,
6366 Make_Explicit_Dereference (Sloc (Obj), Obj));
6367 Analyze (First_Actual);
6369 -- If we need to introduce an explicit dereference, verify that
6370 -- the resulting actual is compatible with the mode of the formal.
6372 if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
6373 and then Is_Access_Constant (Etype (Obj))
6376 ("expect variable in call to&", Prefix (N), Entity (Subprog));
6379 -- Conversely, if the formal is an access parameter and the object
6380 -- is not, replace the actual with a 'Access reference. Its analysis
6381 -- will check that the object is aliased.
6383 elsif Is_Access_Type (Formal_Type)
6384 and then not Is_Access_Type (Etype (Obj))
6386 -- A special case: A.all'access is illegal if A is an access to a
6387 -- constant and the context requires an access to a variable.
6389 if not Is_Access_Constant (Formal_Type) then
6390 if (Nkind (Obj) = N_Explicit_Dereference
6391 and then Is_Access_Constant (Etype (Prefix (Obj))))
6392 or else not Is_Variable (Obj)
6395 ("actual for& must be a variable", Obj, Control);
6399 Rewrite (First_Actual,
6400 Make_Attribute_Reference (Loc,
6401 Attribute_Name => Name_Access,
6402 Prefix => Relocate_Node (Obj)));
6404 if not Is_Aliased_View (Obj) then
6406 ("object in prefixed call to& must be aliased"
6407 & " (RM-2005 4.3.1 (13))",
6408 Prefix (First_Actual), Subprog);
6411 Analyze (First_Actual);
6414 if Is_Overloaded (Obj) then
6415 Save_Interps (Obj, First_Actual);
6418 Rewrite (First_Actual, Obj);
6421 Rewrite (Node_To_Replace, Call_Node);
6423 -- Propagate the interpretations collected in subprog to the new
6424 -- function call node, to be resolved from context.
6426 if Is_Overloaded (Subprog) then
6427 Save_Interps (Subprog, Node_To_Replace);
6430 Analyze (Node_To_Replace);
6432 -- If the operation has been rewritten into a call, which may get
6433 -- subsequently an explicit dereference, preserve the type on the
6434 -- original node (selected component or indexed component) for
6435 -- subsequent legality tests, e.g. Is_Variable. which examines
6436 -- the original node.
6438 if Nkind (Node_To_Replace) = N_Function_Call then
6440 (Original_Node (Node_To_Replace), Etype (Node_To_Replace));
6443 end Complete_Object_Operation;
6445 ----------------------
6446 -- Report_Ambiguity --
6447 ----------------------
6449 procedure Report_Ambiguity (Op : Entity_Id) is
6450 Access_Formal : constant Boolean :=
6451 Is_Access_Type (Etype (First_Formal (Op)));
6452 Access_Actual : constant Boolean :=
6453 Is_Access_Type (Etype (Prefix (N)));
6456 Error_Msg_Sloc := Sloc (Op);
6458 if Access_Formal and then not Access_Actual then
6459 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
6461 ("\possible interpretation"
6462 & " (inherited, with implicit 'Access) #", N);
6465 ("\possible interpretation (with implicit 'Access) #", N);
6468 elsif not Access_Formal and then Access_Actual then
6469 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
6471 ("\possible interpretation"
6472 & " ( inherited, with implicit dereference) #", N);
6475 ("\possible interpretation (with implicit dereference) #", N);
6479 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
6480 Error_Msg_N ("\possible interpretation (inherited)#", N);
6482 Error_Msg_N -- CODEFIX
6483 ("\possible interpretation#", N);
6486 end Report_Ambiguity;
6488 --------------------------------
6489 -- Transform_Object_Operation --
6490 --------------------------------
6492 procedure Transform_Object_Operation
6493 (Call_Node : out Node_Id;
6494 Node_To_Replace : out Node_Id)
6496 Dummy : constant Node_Id := New_Copy (Obj);
6497 -- Placeholder used as a first parameter in the call, replaced
6498 -- eventually by the proper object.
6500 Parent_Node : constant Node_Id := Parent (N);
6506 -- Common case covering 1) Call to a procedure and 2) Call to a
6507 -- function that has some additional actuals.
6509 if Nkind_In (Parent_Node, N_Function_Call,
6510 N_Procedure_Call_Statement)
6512 -- N is a selected component node containing the name of the
6513 -- subprogram. If N is not the name of the parent node we must
6514 -- not replace the parent node by the new construct. This case
6515 -- occurs when N is a parameterless call to a subprogram that
6516 -- is an actual parameter of a call to another subprogram. For
6518 -- Some_Subprogram (..., Obj.Operation, ...)
6520 and then Name (Parent_Node) = N
6522 Node_To_Replace := Parent_Node;
6524 Actuals := Parameter_Associations (Parent_Node);
6526 if Present (Actuals) then
6527 Prepend (Dummy, Actuals);
6529 Actuals := New_List (Dummy);
6532 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
6534 Make_Procedure_Call_Statement (Loc,
6535 Name => New_Copy (Subprog),
6536 Parameter_Associations => Actuals);
6540 Make_Function_Call (Loc,
6541 Name => New_Copy (Subprog),
6542 Parameter_Associations => Actuals);
6546 -- Before analysis, a function call appears as an indexed component
6547 -- if there are no named associations.
6549 elsif Nkind (Parent_Node) = N_Indexed_Component
6550 and then N = Prefix (Parent_Node)
6552 Node_To_Replace := Parent_Node;
6553 Actuals := Expressions (Parent_Node);
6555 Actual := First (Actuals);
6556 while Present (Actual) loop
6561 Prepend (Dummy, Actuals);
6564 Make_Function_Call (Loc,
6565 Name => New_Copy (Subprog),
6566 Parameter_Associations => Actuals);
6568 -- Parameterless call: Obj.F is rewritten as F (Obj)
6571 Node_To_Replace := N;
6574 Make_Function_Call (Loc,
6575 Name => New_Copy (Subprog),
6576 Parameter_Associations => New_List (Dummy));
6578 end Transform_Object_Operation;
6580 ------------------------------
6581 -- Try_Class_Wide_Operation --
6582 ------------------------------
6584 function Try_Class_Wide_Operation
6585 (Call_Node : Node_Id;
6586 Node_To_Replace : Node_Id) return Boolean
6588 Anc_Type : Entity_Id;
6589 Matching_Op : Entity_Id := Empty;
6592 procedure Traverse_Homonyms
6593 (Anc_Type : Entity_Id;
6594 Error : out Boolean);
6595 -- Traverse the homonym chain of the subprogram searching for those
6596 -- homonyms whose first formal has the Anc_Type's class-wide type,
6597 -- or an anonymous access type designating the class-wide type. If
6598 -- an ambiguity is detected, then Error is set to True.
6600 procedure Traverse_Interfaces
6601 (Anc_Type : Entity_Id;
6602 Error : out Boolean);
6603 -- Traverse the list of interfaces, if any, associated with Anc_Type
6604 -- and search for acceptable class-wide homonyms associated with each
6605 -- interface. If an ambiguity is detected, then Error is set to True.
6607 -----------------------
6608 -- Traverse_Homonyms --
6609 -----------------------
6611 procedure Traverse_Homonyms
6612 (Anc_Type : Entity_Id;
6613 Error : out Boolean)
6615 Cls_Type : Entity_Id;
6623 Cls_Type := Class_Wide_Type (Anc_Type);
6625 Hom := Current_Entity (Subprog);
6627 -- Find operation whose first parameter is of the class-wide
6628 -- type, a subtype thereof, or an anonymous access to same.
6630 while Present (Hom) loop
6631 if (Ekind (Hom) = E_Procedure
6633 Ekind (Hom) = E_Function)
6634 and then Scope (Hom) = Scope (Anc_Type)
6635 and then Present (First_Formal (Hom))
6637 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
6639 (Is_Access_Type (Etype (First_Formal (Hom)))
6641 Ekind (Etype (First_Formal (Hom))) =
6642 E_Anonymous_Access_Type
6645 (Designated_Type (Etype (First_Formal (Hom)))) =
6648 Set_Etype (Call_Node, Any_Type);
6649 Set_Is_Overloaded (Call_Node, False);
6652 if No (Matching_Op) then
6653 Hom_Ref := New_Reference_To (Hom, Sloc (Subprog));
6654 Set_Etype (Call_Node, Any_Type);
6655 Set_Parent (Call_Node, Parent (Node_To_Replace));
6657 Set_Name (Call_Node, Hom_Ref);
6662 Report => Report_Error,
6664 Skip_First => True);
6667 Valid_Candidate (Success, Call_Node, Hom);
6673 Report => Report_Error,
6675 Skip_First => True);
6677 if Present (Valid_Candidate (Success, Call_Node, Hom))
6678 and then Nkind (Call_Node) /= N_Function_Call
6680 Error_Msg_NE ("ambiguous call to&", N, Hom);
6681 Report_Ambiguity (Matching_Op);
6682 Report_Ambiguity (Hom);
6689 Hom := Homonym (Hom);
6691 end Traverse_Homonyms;
6693 -------------------------
6694 -- Traverse_Interfaces --
6695 -------------------------
6697 procedure Traverse_Interfaces
6698 (Anc_Type : Entity_Id;
6699 Error : out Boolean)
6701 Intface_List : constant List_Id :=
6702 Abstract_Interface_List (Anc_Type);
6708 if Is_Non_Empty_List (Intface_List) then
6709 Intface := First (Intface_List);
6710 while Present (Intface) loop
6712 -- Look for acceptable class-wide homonyms associated with
6715 Traverse_Homonyms (Etype (Intface), Error);
6721 -- Continue the search by looking at each of the interface's
6722 -- associated interface ancestors.
6724 Traverse_Interfaces (Etype (Intface), Error);
6733 end Traverse_Interfaces;
6735 -- Start of processing for Try_Class_Wide_Operation
6738 -- Loop through ancestor types (including interfaces), traversing
6739 -- the homonym chain of the subprogram, trying out those homonyms
6740 -- whose first formal has the class-wide type of the ancestor, or
6741 -- an anonymous access type designating the class-wide type.
6743 Anc_Type := Obj_Type;
6745 -- Look for a match among homonyms associated with the ancestor
6747 Traverse_Homonyms (Anc_Type, Error);
6753 -- Continue the search for matches among homonyms associated with
6754 -- any interfaces implemented by the ancestor.
6756 Traverse_Interfaces (Anc_Type, Error);
6762 exit when Etype (Anc_Type) = Anc_Type;
6763 Anc_Type := Etype (Anc_Type);
6766 if Present (Matching_Op) then
6767 Set_Etype (Call_Node, Etype (Matching_Op));
6770 return Present (Matching_Op);
6771 end Try_Class_Wide_Operation;
6773 -----------------------------------
6774 -- Try_One_Prefix_Interpretation --
6775 -----------------------------------
6777 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
6781 if Is_Access_Type (Obj_Type) then
6782 Obj_Type := Designated_Type (Obj_Type);
6785 if Ekind (Obj_Type) = E_Private_Subtype then
6786 Obj_Type := Base_Type (Obj_Type);
6789 if Is_Class_Wide_Type (Obj_Type) then
6790 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
6793 -- The type may have be obtained through a limited_with clause,
6794 -- in which case the primitive operations are available on its
6795 -- non-limited view. If still incomplete, retrieve full view.
6797 if Ekind (Obj_Type) = E_Incomplete_Type
6798 and then From_With_Type (Obj_Type)
6800 Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
6803 -- If the object is not tagged, or the type is still an incomplete
6804 -- type, this is not a prefixed call.
6806 if not Is_Tagged_Type (Obj_Type)
6807 or else Is_Incomplete_Type (Obj_Type)
6812 if Try_Primitive_Operation
6813 (Call_Node => New_Call_Node,
6814 Node_To_Replace => Node_To_Replace)
6816 Try_Class_Wide_Operation
6817 (Call_Node => New_Call_Node,
6818 Node_To_Replace => Node_To_Replace)
6822 end Try_One_Prefix_Interpretation;
6824 -----------------------------
6825 -- Try_Primitive_Operation --
6826 -----------------------------
6828 function Try_Primitive_Operation
6829 (Call_Node : Node_Id;
6830 Node_To_Replace : Node_Id) return Boolean
6833 Prim_Op : Entity_Id;
6834 Matching_Op : Entity_Id := Empty;
6835 Prim_Op_Ref : Node_Id := Empty;
6837 Corr_Type : Entity_Id := Empty;
6838 -- If the prefix is a synchronized type, the controlling type of
6839 -- the primitive operation is the corresponding record type, else
6840 -- this is the object type itself.
6842 Success : Boolean := False;
6844 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
6845 -- For tagged types the candidate interpretations are found in
6846 -- the list of primitive operations of the type and its ancestors.
6847 -- For formal tagged types we have to find the operations declared
6848 -- in the same scope as the type (including in the generic formal
6849 -- part) because the type itself carries no primitive operations,
6850 -- except for formal derived types that inherit the operations of
6851 -- the parent and progenitors.
6852 -- If the context is a generic subprogram body, the generic formals
6853 -- are visible by name, but are not in the entity list of the
6854 -- subprogram because that list starts with the subprogram formals.
6855 -- We retrieve the candidate operations from the generic declaration.
6857 function Is_Private_Overriding (Op : Entity_Id) return Boolean;
6858 -- An operation that overrides an inherited operation in the private
6859 -- part of its package may be hidden, but if the inherited operation
6860 -- is visible a direct call to it will dispatch to the private one,
6861 -- which is therefore a valid candidate.
6863 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
6864 -- Verify that the prefix, dereferenced if need be, is a valid
6865 -- controlling argument in a call to Op. The remaining actuals
6866 -- are checked in the subsequent call to Analyze_One_Call.
6868 ------------------------------
6869 -- Collect_Generic_Type_Ops --
6870 ------------------------------
6872 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
6873 Bas : constant Entity_Id := Base_Type (T);
6874 Candidates : constant Elist_Id := New_Elmt_List;
6878 procedure Check_Candidate;
6879 -- The operation is a candidate if its first parameter is a
6880 -- controlling operand of the desired type.
6882 -----------------------
6883 -- Check_Candidate; --
6884 -----------------------
6886 procedure Check_Candidate is
6888 Formal := First_Formal (Subp);
6891 and then Is_Controlling_Formal (Formal)
6893 (Base_Type (Etype (Formal)) = Bas
6895 (Is_Access_Type (Etype (Formal))
6896 and then Designated_Type (Etype (Formal)) = Bas))
6898 Append_Elmt (Subp, Candidates);
6900 end Check_Candidate;
6902 -- Start of processing for Collect_Generic_Type_Ops
6905 if Is_Derived_Type (T) then
6906 return Primitive_Operations (T);
6908 elsif Ekind_In (Scope (T), E_Procedure, E_Function) then
6910 -- Scan the list of generic formals to find subprograms
6911 -- that may have a first controlling formal of the type.
6913 if Nkind (Unit_Declaration_Node (Scope (T)))
6914 = N_Generic_Subprogram_Declaration
6921 First (Generic_Formal_Declarations
6922 (Unit_Declaration_Node (Scope (T))));
6923 while Present (Decl) loop
6924 if Nkind (Decl) in N_Formal_Subprogram_Declaration then
6925 Subp := Defining_Entity (Decl);
6936 -- Scan the list of entities declared in the same scope as
6937 -- the type. In general this will be an open scope, given that
6938 -- the call we are analyzing can only appear within a generic
6939 -- declaration or body (either the one that declares T, or a
6942 -- For a subtype representing a generic actual type, go to the
6945 if Is_Generic_Actual_Type (T) then
6946 Subp := First_Entity (Scope (Base_Type (T)));
6948 Subp := First_Entity (Scope (T));
6951 while Present (Subp) loop
6952 if Is_Overloadable (Subp) then
6961 end Collect_Generic_Type_Ops;
6963 ---------------------------
6964 -- Is_Private_Overriding --
6965 ---------------------------
6967 function Is_Private_Overriding (Op : Entity_Id) return Boolean is
6968 Visible_Op : constant Entity_Id := Homonym (Op);
6971 return Present (Visible_Op)
6972 and then Scope (Op) = Scope (Visible_Op)
6973 and then not Comes_From_Source (Visible_Op)
6974 and then Alias (Visible_Op) = Op
6975 and then not Is_Hidden (Visible_Op);
6976 end Is_Private_Overriding;
6978 -----------------------------
6979 -- Valid_First_Argument_Of --
6980 -----------------------------
6982 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
6983 Typ : Entity_Id := Etype (First_Formal (Op));
6986 if Is_Concurrent_Type (Typ)
6987 and then Present (Corresponding_Record_Type (Typ))
6989 Typ := Corresponding_Record_Type (Typ);
6992 -- Simple case. Object may be a subtype of the tagged type or
6993 -- may be the corresponding record of a synchronized type.
6995 return Obj_Type = Typ
6996 or else Base_Type (Obj_Type) = Typ
6997 or else Corr_Type = Typ
6999 -- Prefix can be dereferenced
7002 (Is_Access_Type (Corr_Type)
7003 and then Designated_Type (Corr_Type) = Typ)
7005 -- Formal is an access parameter, for which the object
7006 -- can provide an access.
7009 (Ekind (Typ) = E_Anonymous_Access_Type
7010 and then Designated_Type (Typ) = Base_Type (Corr_Type));
7011 end Valid_First_Argument_Of;
7013 -- Start of processing for Try_Primitive_Operation
7016 -- Look for subprograms in the list of primitive operations. The name
7017 -- must be identical, and the kind of call indicates the expected
7018 -- kind of operation (function or procedure). If the type is a
7019 -- (tagged) synchronized type, the primitive ops are attached to the
7020 -- corresponding record (base) type.
7022 if Is_Concurrent_Type (Obj_Type) then
7023 if Present (Corresponding_Record_Type (Obj_Type)) then
7024 Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
7025 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
7027 Corr_Type := Obj_Type;
7028 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
7031 elsif not Is_Generic_Type (Obj_Type) then
7032 Corr_Type := Obj_Type;
7033 Elmt := First_Elmt (Primitive_Operations (Obj_Type));
7036 Corr_Type := Obj_Type;
7037 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
7040 while Present (Elmt) loop
7041 Prim_Op := Node (Elmt);
7043 if Chars (Prim_Op) = Chars (Subprog)
7044 and then Present (First_Formal (Prim_Op))
7045 and then Valid_First_Argument_Of (Prim_Op)
7047 (Nkind (Call_Node) = N_Function_Call)
7048 = (Ekind (Prim_Op) = E_Function)
7050 -- Ada 2005 (AI-251): If this primitive operation corresponds
7051 -- with an immediate ancestor interface there is no need to add
7052 -- it to the list of interpretations; the corresponding aliased
7053 -- primitive is also in this list of primitive operations and
7054 -- will be used instead.
7056 if (Present (Interface_Alias (Prim_Op))
7057 and then Is_Ancestor (Find_Dispatching_Type
7058 (Alias (Prim_Op)), Corr_Type))
7060 -- Do not consider hidden primitives unless the type is in an
7061 -- open scope or we are within an instance, where visibility
7062 -- is known to be correct, or else if this is an overriding
7063 -- operation in the private part for an inherited operation.
7065 or else (Is_Hidden (Prim_Op)
7066 and then not Is_Immediately_Visible (Obj_Type)
7067 and then not In_Instance
7068 and then not Is_Private_Overriding (Prim_Op))
7073 Set_Etype (Call_Node, Any_Type);
7074 Set_Is_Overloaded (Call_Node, False);
7076 if No (Matching_Op) then
7077 Prim_Op_Ref := New_Reference_To (Prim_Op, Sloc (Subprog));
7078 Candidate := Prim_Op;
7080 Set_Parent (Call_Node, Parent (Node_To_Replace));
7082 Set_Name (Call_Node, Prim_Op_Ref);
7088 Report => Report_Error,
7090 Skip_First => True);
7092 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
7094 -- More than one interpretation, collect for subsequent
7095 -- disambiguation. If this is a procedure call and there
7096 -- is another match, report ambiguity now.
7102 Report => Report_Error,
7104 Skip_First => True);
7106 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
7107 and then Nkind (Call_Node) /= N_Function_Call
7109 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
7110 Report_Ambiguity (Matching_Op);
7111 Report_Ambiguity (Prim_Op);
7121 if Present (Matching_Op) then
7122 Set_Etype (Call_Node, Etype (Matching_Op));
7125 return Present (Matching_Op);
7126 end Try_Primitive_Operation;
7128 -- Start of processing for Try_Object_Operation
7131 Analyze_Expression (Obj);
7133 -- Analyze the actuals if node is known to be a subprogram call
7135 if Is_Subprg_Call and then N = Name (Parent (N)) then
7136 Actual := First (Parameter_Associations (Parent (N)));
7137 while Present (Actual) loop
7138 Analyze_Expression (Actual);
7143 -- Build a subprogram call node, using a copy of Obj as its first
7144 -- actual. This is a placeholder, to be replaced by an explicit
7145 -- dereference when needed.
7147 Transform_Object_Operation
7148 (Call_Node => New_Call_Node,
7149 Node_To_Replace => Node_To_Replace);
7151 Set_Etype (New_Call_Node, Any_Type);
7152 Set_Etype (Subprog, Any_Type);
7153 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
7155 if not Is_Overloaded (Obj) then
7156 Try_One_Prefix_Interpretation (Obj_Type);
7163 Get_First_Interp (Obj, I, It);
7164 while Present (It.Nam) loop
7165 Try_One_Prefix_Interpretation (It.Typ);
7166 Get_Next_Interp (I, It);
7171 if Etype (New_Call_Node) /= Any_Type then
7172 Complete_Object_Operation
7173 (Call_Node => New_Call_Node,
7174 Node_To_Replace => Node_To_Replace);
7177 elsif Present (Candidate) then
7179 -- The argument list is not type correct. Re-analyze with error
7180 -- reporting enabled, and use one of the possible candidates.
7181 -- In All_Errors_Mode, re-analyze all failed interpretations.
7183 if All_Errors_Mode then
7184 Report_Error := True;
7185 if Try_Primitive_Operation
7186 (Call_Node => New_Call_Node,
7187 Node_To_Replace => Node_To_Replace)
7190 Try_Class_Wide_Operation
7191 (Call_Node => New_Call_Node,
7192 Node_To_Replace => Node_To_Replace)
7199 (N => New_Call_Node,
7203 Skip_First => True);
7206 -- No need for further errors
7211 -- There was no candidate operation, so report it as an error
7212 -- in the caller: Analyze_Selected_Component.
7216 end Try_Object_Operation;
7222 procedure wpo (T : Entity_Id) is
7227 if not Is_Tagged_Type (T) then
7231 E := First_Elmt (Primitive_Operations (Base_Type (T)));
7232 while Present (E) loop
7234 Write_Int (Int (Op));
7235 Write_Str (" === ");
7236 Write_Name (Chars (Op));
7238 Write_Name (Chars (Scope (Op)));