1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, 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 Aspects; use Aspects;
27 with Atree; use Atree;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Util; use Exp_Util;
33 with Fname; use Fname;
34 with Itypes; use Itypes;
36 with Lib.Xref; use Lib.Xref;
37 with Namet; use Namet;
38 with Namet.Sp; use Namet.Sp;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
42 with Output; use Output;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
46 with Sem_Aux; use Sem_Aux;
47 with Sem_Case; use Sem_Case;
48 with Sem_Cat; use Sem_Cat;
49 with Sem_Ch3; use Sem_Ch3;
50 with Sem_Ch6; use Sem_Ch6;
51 with Sem_Ch8; use Sem_Ch8;
52 with Sem_Dim; use Sem_Dim;
53 with Sem_Disp; use Sem_Disp;
54 with Sem_Dist; use Sem_Dist;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Res; use Sem_Res;
57 with Sem_Type; use Sem_Type;
58 with Sem_Util; use Sem_Util;
59 with Sem_Warn; use Sem_Warn;
60 with Stand; use Stand;
61 with Sinfo; use Sinfo;
62 with Snames; use Snames;
63 with Tbuild; use Tbuild;
64 with Uintp; use Uintp;
66 package body Sem_Ch4 is
68 -----------------------
69 -- Local Subprograms --
70 -----------------------
72 procedure Analyze_Concatenation_Rest (N : Node_Id);
73 -- Does the "rest" of the work of Analyze_Concatenation, after the left
74 -- operand has been analyzed. See Analyze_Concatenation for details.
76 procedure Analyze_Expression (N : Node_Id);
77 -- For expressions that are not names, this is just a call to analyze.
78 -- If the expression is a name, it may be a call to a parameterless
79 -- function, and if so must be converted into an explicit call node
80 -- and analyzed as such. This deproceduring must be done during the first
81 -- pass of overload resolution, because otherwise a procedure call with
82 -- overloaded actuals may fail to resolve.
84 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
85 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
86 -- is an operator name or an expanded name whose selector is an operator
87 -- name, and one possible interpretation is as a predefined operator.
89 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
90 -- If the prefix of a selected_component is overloaded, the proper
91 -- interpretation that yields a record type with the proper selector
92 -- name must be selected.
94 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
95 -- Procedure to analyze a user defined binary operator, which is resolved
96 -- like a function, but instead of a list of actuals it is presented
97 -- with the left and right operands of an operator node.
99 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
100 -- Procedure to analyze a user defined unary operator, which is resolved
101 -- like a function, but instead of a list of actuals, it is presented with
102 -- the operand of the operator node.
104 procedure Ambiguous_Operands (N : Node_Id);
105 -- For equality, membership, and comparison operators with overloaded
106 -- arguments, list possible interpretations.
108 procedure Analyze_One_Call
112 Success : out Boolean;
113 Skip_First : Boolean := False);
114 -- Check one interpretation of an overloaded subprogram name for
115 -- compatibility with the types of the actuals in a call. If there is a
116 -- single interpretation which does not match, post error if Report is
119 -- Nam is the entity that provides the formals against which the actuals
120 -- are checked. Nam is either the name of a subprogram, or the internal
121 -- subprogram type constructed for an access_to_subprogram. If the actuals
122 -- are compatible with Nam, then Nam is added to the list of candidate
123 -- interpretations for N, and Success is set to True.
125 -- The flag Skip_First is used when analyzing a call that was rewritten
126 -- from object notation. In this case the first actual may have to receive
127 -- an explicit dereference, depending on the first formal of the operation
128 -- being called. The caller will have verified that the object is legal
129 -- for the call. If the remaining parameters match, the first parameter
130 -- will rewritten as a dereference if needed, prior to completing analysis.
132 procedure Check_Misspelled_Selector
135 -- Give possible misspelling diagnostic if Sel is likely to be a mis-
136 -- spelling of one of the selectors of the Prefix. This is called by
137 -- Analyze_Selected_Component after producing an invalid selector error
140 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
141 -- Verify that type T is declared in scope S. Used to find interpretations
142 -- for operators given by expanded names. This is abstracted as a separate
143 -- function to handle extensions to System, where S is System, but T is
144 -- declared in the extension.
146 procedure Find_Arithmetic_Types
150 -- L and R are the operands of an arithmetic operator. Find
151 -- consistent pairs of interpretations for L and R that have a
152 -- numeric type consistent with the semantics of the operator.
154 procedure Find_Comparison_Types
158 -- L and R are operands of a comparison operator. Find consistent
159 -- pairs of interpretations for L and R.
161 procedure Find_Concatenation_Types
165 -- For the four varieties of concatenation
167 procedure Find_Equality_Types
171 -- Ditto for equality operators
173 procedure Find_Boolean_Types
177 -- Ditto for binary logical operations
179 procedure Find_Negation_Types
183 -- Find consistent interpretation for operand of negation operator
185 procedure Find_Non_Universal_Interpretations
190 -- For equality and comparison operators, the result is always boolean,
191 -- and the legality of the operation is determined from the visibility
192 -- of the operand types. If one of the operands has a universal interpre-
193 -- tation, the legality check uses some compatible non-universal
194 -- interpretation of the other operand. N can be an operator node, or
195 -- a function call whose name is an operator designator. Any_Access, which
196 -- is the initial type of the literal NULL, is a universal type for the
197 -- purpose of this routine.
199 function Find_Primitive_Operation (N : Node_Id) return Boolean;
200 -- Find candidate interpretations for the name Obj.Proc when it appears
201 -- in a subprogram renaming declaration.
203 procedure Find_Unary_Types
207 -- Unary arithmetic types: plus, minus, abs
209 procedure Check_Arithmetic_Pair
213 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
214 -- types for left and right operand. Determine whether they constitute
215 -- a valid pair for the given operator, and record the corresponding
216 -- interpretation of the operator node. The node N may be an operator
217 -- node (the usual case) or a function call whose prefix is an operator
218 -- designator. In both cases Op_Id is the operator name itself.
220 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
221 -- Give detailed information on overloaded call where none of the
222 -- interpretations match. N is the call node, Nam the designator for
223 -- the overloaded entity being called.
225 function Junk_Operand (N : Node_Id) return Boolean;
226 -- Test for an operand that is an inappropriate entity (e.g. a package
227 -- name or a label). If so, issue an error message and return True. If
228 -- the operand is not an inappropriate entity kind, return False.
230 procedure Operator_Check (N : Node_Id);
231 -- Verify that an operator has received some valid interpretation. If none
232 -- was found, determine whether a use clause would make the operation
233 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
234 -- every type compatible with the operator, even if the operator for the
235 -- type is not directly visible. The routine uses this type to emit a more
236 -- informative message.
238 function Process_Implicit_Dereference_Prefix
240 P : Node_Id) return Entity_Id;
241 -- Called when P is the prefix of an implicit dereference, denoting an
242 -- object E. The function returns the designated type of the prefix, taking
243 -- into account that the designated type of an anonymous access type may be
244 -- a limited view, when the non-limited view is visible.
245 -- If in semantics only mode (-gnatc or generic), the function also records
246 -- that the prefix is a reference to E, if any. Normally, such a reference
247 -- is generated only when the implicit dereference is expanded into an
248 -- explicit one, but for consistency we must generate the reference when
249 -- expansion is disabled as well.
251 procedure Remove_Abstract_Operations (N : Node_Id);
252 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
253 -- operation is not a candidate interpretation.
255 function Try_Container_Indexing
258 Exprs : List_Id) return Boolean;
259 -- AI05-0139: Generalized indexing to support iterators over containers
261 function Try_Indexed_Call
265 Skip_First : Boolean) return Boolean;
266 -- If a function has defaults for all its actuals, a call to it may in fact
267 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
268 -- interpretation as an indexing, prior to analysis as a call. If both are
269 -- possible, the node is overloaded with both interpretations (same symbol
270 -- but two different types). If the call is written in prefix form, the
271 -- prefix becomes the first parameter in the call, and only the remaining
272 -- actuals must be checked for the presence of defaults.
274 function Try_Indirect_Call
277 Typ : Entity_Id) return Boolean;
278 -- Similarly, a function F that needs no actuals can return an access to a
279 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
280 -- the call may be overloaded with both interpretations.
282 function Try_Object_Operation
284 CW_Test_Only : Boolean := False) return Boolean;
285 -- Ada 2005 (AI-252): Support the object.operation notation. If node N
286 -- is a call in this notation, it is transformed into a normal subprogram
287 -- call where the prefix is a parameter, and True is returned. If node
288 -- N is not of this form, it is unchanged, and False is returned. if
289 -- CW_Test_Only is true then N is an N_Selected_Component node which
290 -- is part of a call to an entry or procedure of a tagged concurrent
291 -- type and this routine is invoked to search for class-wide subprograms
292 -- conflicting with the target entity.
294 procedure wpo (T : Entity_Id);
295 pragma Warnings (Off, wpo);
296 -- Used for debugging: obtain list of primitive operations even if
297 -- type is not frozen and dispatch table is not built yet.
299 ------------------------
300 -- Ambiguous_Operands --
301 ------------------------
303 procedure Ambiguous_Operands (N : Node_Id) is
304 procedure List_Operand_Interps (Opnd : Node_Id);
306 --------------------------
307 -- List_Operand_Interps --
308 --------------------------
310 procedure List_Operand_Interps (Opnd : Node_Id) is
315 if Is_Overloaded (Opnd) then
316 if Nkind (Opnd) in N_Op then
318 elsif Nkind (Opnd) = N_Function_Call then
320 elsif Ada_Version >= Ada_2012 then
326 Get_First_Interp (Opnd, I, It);
327 while Present (It.Nam) loop
328 if Has_Implicit_Dereference (It.Typ) then
330 ("can be interpreted as implicit dereference", Opnd);
334 Get_Next_Interp (I, It);
345 if Opnd = Left_Opnd (N) then
346 Error_Msg_N ("\left operand has the following interpretations", N);
349 ("\right operand has the following interpretations", N);
353 List_Interps (Nam, Err);
354 end List_Operand_Interps;
356 -- Start of processing for Ambiguous_Operands
359 if Nkind (N) in N_Membership_Test then
360 Error_Msg_N ("ambiguous operands for membership", N);
362 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
363 Error_Msg_N ("ambiguous operands for equality", N);
366 Error_Msg_N ("ambiguous operands for comparison", N);
369 if All_Errors_Mode then
370 List_Operand_Interps (Left_Opnd (N));
371 List_Operand_Interps (Right_Opnd (N));
373 Error_Msg_N ("\use -gnatf switch for details", N);
375 end Ambiguous_Operands;
377 -----------------------
378 -- Analyze_Aggregate --
379 -----------------------
381 -- Most of the analysis of Aggregates requires that the type be known,
382 -- and is therefore put off until resolution.
384 procedure Analyze_Aggregate (N : Node_Id) is
386 if No (Etype (N)) then
387 Set_Etype (N, Any_Composite);
389 end Analyze_Aggregate;
391 -----------------------
392 -- Analyze_Allocator --
393 -----------------------
395 procedure Analyze_Allocator (N : Node_Id) is
396 Loc : constant Source_Ptr := Sloc (N);
397 Sav_Errs : constant Nat := Serious_Errors_Detected;
398 E : Node_Id := Expression (N);
399 Acc_Type : Entity_Id;
405 Check_SPARK_Restriction ("allocator is not allowed", N);
407 -- Deal with allocator restrictions
409 -- In accordance with H.4(7), the No_Allocators restriction only applies
410 -- to user-written allocators. The same consideration applies to the
411 -- No_Allocators_Before_Elaboration restriction.
413 if Comes_From_Source (N) then
414 Check_Restriction (No_Allocators, N);
416 -- Processing for No_Allocators_After_Elaboration, loop to look at
417 -- enclosing context, checking task case and main subprogram case.
421 while Present (P) loop
423 -- In both cases we need a handled sequence of statements, where
424 -- the occurrence of the allocator is within the statements.
426 if Nkind (P) = N_Handled_Sequence_Of_Statements
427 and then Is_List_Member (C)
428 and then List_Containing (C) = Statements (P)
430 -- Check for allocator within task body, this is a definite
431 -- violation of No_Allocators_After_Elaboration we can detect.
433 if Nkind (Original_Node (Parent (P))) = N_Task_Body then
434 Check_Restriction (No_Allocators_After_Elaboration, N);
438 -- The other case is appearance in a subprogram body. This may
439 -- be a violation if this is a library level subprogram, and it
440 -- turns out to be used as the main program, but only the
441 -- binder knows that, so just record the occurrence.
443 if Nkind (Original_Node (Parent (P))) = N_Subprogram_Body
444 and then Nkind (Parent (Parent (P))) = N_Compilation_Unit
446 Set_Has_Allocator (Current_Sem_Unit);
455 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
456 -- any. The expected type for the name is any type. A non-overloading
457 -- rule then requires it to be of a type descended from
458 -- System.Storage_Pools.Subpools.Subpool_Handle.
460 -- This isn't exactly what the AI says, but it seems to be the right
461 -- rule. The AI should be fixed.???
464 Subpool : constant Node_Id := Subpool_Handle_Name (N);
467 if Present (Subpool) then
470 if Is_Overloaded (Subpool) then
471 Error_Msg_N ("ambiguous subpool handle", Subpool);
474 -- Check that Etype (Subpool) is descended from Subpool_Handle
480 -- Analyze the qualified expression or subtype indication
482 if Nkind (E) = N_Qualified_Expression then
483 Acc_Type := Create_Itype (E_Allocator_Type, N);
484 Set_Etype (Acc_Type, Acc_Type);
485 Find_Type (Subtype_Mark (E));
487 -- Analyze the qualified expression, and apply the name resolution
488 -- rule given in 4.7(3).
491 Type_Id := Etype (E);
492 Set_Directly_Designated_Type (Acc_Type, Type_Id);
494 Resolve (Expression (E), Type_Id);
496 -- Allocators generated by the build-in-place expansion mechanism
497 -- are explicitly marked as coming from source but do not need to be
498 -- checked for limited initialization. To exclude this case, ensure
499 -- that the parent of the allocator is a source node.
501 if Is_Limited_Type (Type_Id)
502 and then Comes_From_Source (N)
503 and then Comes_From_Source (Parent (N))
504 and then not In_Instance_Body
506 if not OK_For_Limited_Init (Type_Id, Expression (E)) then
507 Error_Msg_N ("initialization not allowed for limited types", N);
508 Explain_Limited_Type (Type_Id, N);
512 -- A qualified expression requires an exact match of the type,
513 -- class-wide matching is not allowed.
515 -- if Is_Class_Wide_Type (Type_Id)
516 -- and then Base_Type
517 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
519 -- Wrong_Type (Expression (E), Type_Id);
522 Check_Non_Static_Context (Expression (E));
524 -- We don't analyze the qualified expression itself because it's
525 -- part of the allocator
527 Set_Etype (E, Type_Id);
529 -- Case where allocator has a subtype indication
534 Base_Typ : Entity_Id;
537 -- If the allocator includes a N_Subtype_Indication then a
538 -- constraint is present, otherwise the node is a subtype mark.
539 -- Introduce an explicit subtype declaration into the tree
540 -- defining some anonymous subtype and rewrite the allocator to
541 -- use this subtype rather than the subtype indication.
543 -- It is important to introduce the explicit subtype declaration
544 -- so that the bounds of the subtype indication are attached to
545 -- the tree in case the allocator is inside a generic unit.
547 if Nkind (E) = N_Subtype_Indication then
549 -- A constraint is only allowed for a composite type in Ada
550 -- 95. In Ada 83, a constraint is also allowed for an
551 -- access-to-composite type, but the constraint is ignored.
553 Find_Type (Subtype_Mark (E));
554 Base_Typ := Entity (Subtype_Mark (E));
556 if Is_Elementary_Type (Base_Typ) then
557 if not (Ada_Version = Ada_83
558 and then Is_Access_Type (Base_Typ))
560 Error_Msg_N ("constraint not allowed here", E);
562 if Nkind (Constraint (E)) =
563 N_Index_Or_Discriminant_Constraint
565 Error_Msg_N -- CODEFIX
566 ("\if qualified expression was meant, " &
567 "use apostrophe", Constraint (E));
571 -- Get rid of the bogus constraint:
573 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
574 Analyze_Allocator (N);
577 -- Ada 2005, AI-363: if the designated type has a constrained
578 -- partial view, it cannot receive a discriminant constraint,
579 -- and the allocated object is unconstrained.
581 elsif Ada_Version >= Ada_2005
582 and then Effectively_Has_Constrained_Partial_View
584 Scop => Current_Scope)
587 ("constraint not allowed when type " &
588 "has a constrained partial view", Constraint (E));
591 if Expander_Active then
592 Def_Id := Make_Temporary (Loc, 'S');
595 Make_Subtype_Declaration (Loc,
596 Defining_Identifier => Def_Id,
597 Subtype_Indication => Relocate_Node (E)));
599 if Sav_Errs /= Serious_Errors_Detected
600 and then Nkind (Constraint (E)) =
601 N_Index_Or_Discriminant_Constraint
603 Error_Msg_N -- CODEFIX
604 ("if qualified expression was meant, " &
605 "use apostrophe!", Constraint (E));
608 E := New_Occurrence_Of (Def_Id, Loc);
609 Rewrite (Expression (N), E);
613 Type_Id := Process_Subtype (E, N);
614 Acc_Type := Create_Itype (E_Allocator_Type, N);
615 Set_Etype (Acc_Type, Acc_Type);
616 Set_Directly_Designated_Type (Acc_Type, Type_Id);
617 Check_Fully_Declared (Type_Id, N);
619 -- Ada 2005 (AI-231): If the designated type is itself an access
620 -- type that excludes null, its default initialization will
621 -- be a null object, and we can insert an unconditional raise
622 -- before the allocator.
624 -- Ada 2012 (AI-104): A not null indication here is altogether
627 if Can_Never_Be_Null (Type_Id) then
629 Not_Null_Check : constant Node_Id :=
630 Make_Raise_Constraint_Error (Sloc (E),
631 Reason => CE_Null_Not_Allowed);
634 if Expander_Active then
635 Insert_Action (N, Not_Null_Check);
636 Analyze (Not_Null_Check);
639 Error_Msg_N ("null value not allowed here?", E);
644 -- Check restriction against dynamically allocated protected
645 -- objects. Note that when limited aggregates are supported,
646 -- a similar test should be applied to an allocator with a
647 -- qualified expression ???
649 if Is_Protected_Type (Type_Id) then
650 Check_Restriction (No_Protected_Type_Allocators, N);
653 -- Check for missing initialization. Skip this check if we already
654 -- had errors on analyzing the allocator, since in that case these
655 -- are probably cascaded errors.
657 if Is_Indefinite_Subtype (Type_Id)
658 and then Serious_Errors_Detected = Sav_Errs
660 -- The build-in-place machinery may produce an allocator when
661 -- the designated type is indefinite but the underlying type is
662 -- not. In this case the unknown discriminants are meaningless
663 -- and should not trigger error messages. Check the parent node
664 -- because the allocator is marked as coming from source.
666 if Present (Underlying_Type (Type_Id))
667 and then not Is_Indefinite_Subtype (Underlying_Type (Type_Id))
668 and then not Comes_From_Source (Parent (N))
672 elsif Is_Class_Wide_Type (Type_Id) then
674 ("initialization required in class-wide allocation", N);
677 if Ada_Version < Ada_2005
678 and then Is_Limited_Type (Type_Id)
680 Error_Msg_N ("unconstrained allocation not allowed", N);
682 if Is_Array_Type (Type_Id) then
684 ("\constraint with array bounds required", N);
686 elsif Has_Unknown_Discriminants (Type_Id) then
689 else pragma Assert (Has_Discriminants (Type_Id));
691 ("\constraint with discriminant values required", N);
694 -- Limited Ada 2005 and general non-limited case
698 ("uninitialized unconstrained allocation not allowed",
701 if Is_Array_Type (Type_Id) then
703 ("\qualified expression or constraint with " &
704 "array bounds required", N);
706 elsif Has_Unknown_Discriminants (Type_Id) then
707 Error_Msg_N ("\qualified expression required", N);
709 else pragma Assert (Has_Discriminants (Type_Id));
711 ("\qualified expression or constraint with " &
712 "discriminant values required", N);
720 if Is_Abstract_Type (Type_Id) then
721 Error_Msg_N ("cannot allocate abstract object", E);
724 if Has_Task (Designated_Type (Acc_Type)) then
725 Check_Restriction (No_Tasking, N);
726 Check_Restriction (Max_Tasks, N);
727 Check_Restriction (No_Task_Allocators, N);
730 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
731 -- type is nested, and the designated type needs finalization. The rule
732 -- is conservative in that class-wide types need finalization.
734 if Needs_Finalization (Designated_Type (Acc_Type))
735 and then not Is_Library_Level_Entity (Acc_Type)
737 Check_Restriction (No_Nested_Finalization, N);
740 -- Check that an allocator of a nested access type doesn't create a
741 -- protected object when restriction No_Local_Protected_Objects applies.
742 -- We don't have an equivalent to Has_Task for protected types, so only
743 -- cases where the designated type itself is a protected type are
744 -- currently checked. ???
746 if Is_Protected_Type (Designated_Type (Acc_Type))
747 and then not Is_Library_Level_Entity (Acc_Type)
749 Check_Restriction (No_Local_Protected_Objects, N);
752 -- If the No_Streams restriction is set, check that the type of the
753 -- object is not, and does not contain, any subtype derived from
754 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
755 -- Has_Stream just for efficiency reasons. There is no point in
756 -- spending time on a Has_Stream check if the restriction is not set.
758 if Restriction_Check_Required (No_Streams) then
759 if Has_Stream (Designated_Type (Acc_Type)) then
760 Check_Restriction (No_Streams, N);
764 Set_Etype (N, Acc_Type);
766 if not Is_Library_Level_Entity (Acc_Type) then
767 Check_Restriction (No_Local_Allocators, N);
770 if Serious_Errors_Detected > Sav_Errs then
771 Set_Error_Posted (N);
772 Set_Etype (N, Any_Type);
774 end Analyze_Allocator;
776 ---------------------------
777 -- Analyze_Arithmetic_Op --
778 ---------------------------
780 procedure Analyze_Arithmetic_Op (N : Node_Id) is
781 L : constant Node_Id := Left_Opnd (N);
782 R : constant Node_Id := Right_Opnd (N);
786 Candidate_Type := Empty;
787 Analyze_Expression (L);
788 Analyze_Expression (R);
790 -- If the entity is already set, the node is the instantiation of a
791 -- generic node with a non-local reference, or was manufactured by a
792 -- call to Make_Op_xxx. In either case the entity is known to be valid,
793 -- and we do not need to collect interpretations, instead we just get
794 -- the single possible interpretation.
798 if Present (Op_Id) then
799 if Ekind (Op_Id) = E_Operator then
801 if Nkind_In (N, N_Op_Divide, N_Op_Mod, N_Op_Multiply, N_Op_Rem)
802 and then Treat_Fixed_As_Integer (N)
806 Set_Etype (N, Any_Type);
807 Find_Arithmetic_Types (L, R, Op_Id, N);
811 Set_Etype (N, Any_Type);
812 Add_One_Interp (N, Op_Id, Etype (Op_Id));
815 -- Entity is not already set, so we do need to collect interpretations
818 Op_Id := Get_Name_Entity_Id (Chars (N));
819 Set_Etype (N, Any_Type);
821 while Present (Op_Id) loop
822 if Ekind (Op_Id) = E_Operator
823 and then Present (Next_Entity (First_Entity (Op_Id)))
825 Find_Arithmetic_Types (L, R, Op_Id, N);
827 -- The following may seem superfluous, because an operator cannot
828 -- be generic, but this ignores the cleverness of the author of
831 elsif Is_Overloadable (Op_Id) then
832 Analyze_User_Defined_Binary_Op (N, Op_Id);
835 Op_Id := Homonym (Op_Id);
840 end Analyze_Arithmetic_Op;
846 -- Function, procedure, and entry calls are checked here. The Name in
847 -- the call may be overloaded. The actuals have been analyzed and may
848 -- themselves be overloaded. On exit from this procedure, the node N
849 -- may have zero, one or more interpretations. In the first case an
850 -- error message is produced. In the last case, the node is flagged
851 -- as overloaded and the interpretations are collected in All_Interp.
853 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
854 -- the type-checking is similar to that of other calls.
856 procedure Analyze_Call (N : Node_Id) is
857 Actuals : constant List_Id := Parameter_Associations (N);
862 Success : Boolean := False;
864 Deref : Boolean := False;
865 -- Flag indicates whether an interpretation of the prefix is a
866 -- parameterless call that returns an access_to_subprogram.
868 procedure Check_Mixed_Parameter_And_Named_Associations;
869 -- Check that parameter and named associations are not mixed. This is
870 -- a restriction in SPARK mode.
872 function Name_Denotes_Function return Boolean;
873 -- If the type of the name is an access to subprogram, this may be the
874 -- type of a name, or the return type of the function being called. If
875 -- the name is not an entity then it can denote a protected function.
876 -- Until we distinguish Etype from Return_Type, we must use this routine
877 -- to resolve the meaning of the name in the call.
879 procedure No_Interpretation;
880 -- Output error message when no valid interpretation exists
882 --------------------------------------------------
883 -- Check_Mixed_Parameter_And_Named_Associations --
884 --------------------------------------------------
886 procedure Check_Mixed_Parameter_And_Named_Associations is
888 Named_Seen : Boolean;
893 Actual := First (Actuals);
894 while Present (Actual) loop
895 case Nkind (Actual) is
896 when N_Parameter_Association =>
898 Check_SPARK_Restriction
899 ("named association cannot follow positional one",
909 end Check_Mixed_Parameter_And_Named_Associations;
911 ---------------------------
912 -- Name_Denotes_Function --
913 ---------------------------
915 function Name_Denotes_Function return Boolean is
917 if Is_Entity_Name (Nam) then
918 return Ekind (Entity (Nam)) = E_Function;
920 elsif Nkind (Nam) = N_Selected_Component then
921 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
926 end Name_Denotes_Function;
928 -----------------------
929 -- No_Interpretation --
930 -----------------------
932 procedure No_Interpretation is
933 L : constant Boolean := Is_List_Member (N);
934 K : constant Node_Kind := Nkind (Parent (N));
937 -- If the node is in a list whose parent is not an expression then it
938 -- must be an attempted procedure call.
940 if L and then K not in N_Subexpr then
941 if Ekind (Entity (Nam)) = E_Generic_Procedure then
943 ("must instantiate generic procedure& before call",
947 ("procedure or entry name expected", Nam);
950 -- Check for tasking cases where only an entry call will do
953 and then Nkind_In (K, N_Entry_Call_Alternative,
954 N_Triggering_Alternative)
956 Error_Msg_N ("entry name expected", Nam);
958 -- Otherwise give general error message
961 Error_Msg_N ("invalid prefix in call", Nam);
963 end No_Interpretation;
965 -- Start of processing for Analyze_Call
968 if Restriction_Check_Required (SPARK) then
969 Check_Mixed_Parameter_And_Named_Associations;
972 -- Initialize the type of the result of the call to the error type,
973 -- which will be reset if the type is successfully resolved.
975 Set_Etype (N, Any_Type);
979 if not Is_Overloaded (Nam) then
981 -- Only one interpretation to check
983 if Ekind (Etype (Nam)) = E_Subprogram_Type then
984 Nam_Ent := Etype (Nam);
986 -- If the prefix is an access_to_subprogram, this may be an indirect
987 -- call. This is the case if the name in the call is not an entity
988 -- name, or if it is a function name in the context of a procedure
989 -- call. In this latter case, we have a call to a parameterless
990 -- function that returns a pointer_to_procedure which is the entity
991 -- being called. Finally, F (X) may be a call to a parameterless
992 -- function that returns a pointer to a function with parameters.
994 elsif Is_Access_Type (Etype (Nam))
995 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
997 (not Name_Denotes_Function
998 or else Nkind (N) = N_Procedure_Call_Statement
1000 (Nkind (Parent (N)) /= N_Explicit_Dereference
1001 and then Is_Entity_Name (Nam)
1002 and then No (First_Formal (Entity (Nam)))
1003 and then Present (Actuals)))
1005 Nam_Ent := Designated_Type (Etype (Nam));
1006 Insert_Explicit_Dereference (Nam);
1008 -- Selected component case. Simple entry or protected operation,
1009 -- where the entry name is given by the selector name.
1011 elsif Nkind (Nam) = N_Selected_Component then
1012 Nam_Ent := Entity (Selector_Name (Nam));
1014 if not Ekind_In (Nam_Ent, E_Entry,
1019 Error_Msg_N ("name in call is not a callable entity", Nam);
1020 Set_Etype (N, Any_Type);
1024 -- If the name is an Indexed component, it can be a call to a member
1025 -- of an entry family. The prefix must be a selected component whose
1026 -- selector is the entry. Analyze_Procedure_Call normalizes several
1027 -- kinds of call into this form.
1029 elsif Nkind (Nam) = N_Indexed_Component then
1030 if Nkind (Prefix (Nam)) = N_Selected_Component then
1031 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
1033 Error_Msg_N ("name in call is not a callable entity", Nam);
1034 Set_Etype (N, Any_Type);
1038 elsif not Is_Entity_Name (Nam) then
1039 Error_Msg_N ("name in call is not a callable entity", Nam);
1040 Set_Etype (N, Any_Type);
1044 Nam_Ent := Entity (Nam);
1046 -- If no interpretations, give error message
1048 if not Is_Overloadable (Nam_Ent) then
1054 -- Operations generated for RACW stub types are called only through
1055 -- dispatching, and can never be the static interpretation of a call.
1057 if Is_RACW_Stub_Type_Operation (Nam_Ent) then
1062 Analyze_One_Call (N, Nam_Ent, True, Success);
1064 -- If this is an indirect call, the return type of the access_to
1065 -- subprogram may be an incomplete type. At the point of the call,
1066 -- use the full type if available, and at the same time update the
1067 -- return type of the access_to_subprogram.
1070 and then Nkind (Nam) = N_Explicit_Dereference
1071 and then Ekind (Etype (N)) = E_Incomplete_Type
1072 and then Present (Full_View (Etype (N)))
1074 Set_Etype (N, Full_View (Etype (N)));
1075 Set_Etype (Nam_Ent, Etype (N));
1079 -- An overloaded selected component must denote overloaded operations
1080 -- of a concurrent type. The interpretations are attached to the
1081 -- simple name of those operations.
1083 if Nkind (Nam) = N_Selected_Component then
1084 Nam := Selector_Name (Nam);
1087 Get_First_Interp (Nam, X, It);
1089 while Present (It.Nam) loop
1093 -- Name may be call that returns an access to subprogram, or more
1094 -- generally an overloaded expression one of whose interpretations
1095 -- yields an access to subprogram. If the name is an entity, we do
1096 -- not dereference, because the node is a call that returns the
1097 -- access type: note difference between f(x), where the call may
1098 -- return an access subprogram type, and f(x)(y), where the type
1099 -- returned by the call to f is implicitly dereferenced to analyze
1102 if Is_Access_Type (Nam_Ent) then
1103 Nam_Ent := Designated_Type (Nam_Ent);
1105 elsif Is_Access_Type (Etype (Nam_Ent))
1107 (not Is_Entity_Name (Nam)
1108 or else Nkind (N) = N_Procedure_Call_Statement)
1109 and then Ekind (Designated_Type (Etype (Nam_Ent)))
1112 Nam_Ent := Designated_Type (Etype (Nam_Ent));
1114 if Is_Entity_Name (Nam) then
1119 -- If the call has been rewritten from a prefixed call, the first
1120 -- parameter has been analyzed, but may need a subsequent
1121 -- dereference, so skip its analysis now.
1123 if N /= Original_Node (N)
1124 and then Nkind (Original_Node (N)) = Nkind (N)
1125 and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N)))
1126 and then Present (Parameter_Associations (N))
1127 and then Present (Etype (First (Parameter_Associations (N))))
1130 (N, Nam_Ent, False, Success, Skip_First => True);
1132 Analyze_One_Call (N, Nam_Ent, False, Success);
1135 -- If the interpretation succeeds, mark the proper type of the
1136 -- prefix (any valid candidate will do). If not, remove the
1137 -- candidate interpretation. This only needs to be done for
1138 -- overloaded protected operations, for other entities disambi-
1139 -- guation is done directly in Resolve.
1143 and then Nkind (Parent (N)) /= N_Explicit_Dereference
1145 Set_Entity (Nam, It.Nam);
1146 Insert_Explicit_Dereference (Nam);
1147 Set_Etype (Nam, Nam_Ent);
1150 Set_Etype (Nam, It.Typ);
1153 elsif Nkind_In (Name (N), N_Selected_Component,
1159 Get_Next_Interp (X, It);
1162 -- If the name is the result of a function call, it can only
1163 -- be a call to a function returning an access to subprogram.
1164 -- Insert explicit dereference.
1166 if Nkind (Nam) = N_Function_Call then
1167 Insert_Explicit_Dereference (Nam);
1170 if Etype (N) = Any_Type then
1172 -- None of the interpretations is compatible with the actuals
1174 Diagnose_Call (N, Nam);
1176 -- Special checks for uninstantiated put routines
1178 if Nkind (N) = N_Procedure_Call_Statement
1179 and then Is_Entity_Name (Nam)
1180 and then Chars (Nam) = Name_Put
1181 and then List_Length (Actuals) = 1
1184 Arg : constant Node_Id := First (Actuals);
1188 if Nkind (Arg) = N_Parameter_Association then
1189 Typ := Etype (Explicit_Actual_Parameter (Arg));
1194 if Is_Signed_Integer_Type (Typ) then
1196 ("possible missing instantiation of " &
1197 "'Text_'I'O.'Integer_'I'O!", Nam);
1199 elsif Is_Modular_Integer_Type (Typ) then
1201 ("possible missing instantiation of " &
1202 "'Text_'I'O.'Modular_'I'O!", Nam);
1204 elsif Is_Floating_Point_Type (Typ) then
1206 ("possible missing instantiation of " &
1207 "'Text_'I'O.'Float_'I'O!", Nam);
1209 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
1211 ("possible missing instantiation of " &
1212 "'Text_'I'O.'Fixed_'I'O!", Nam);
1214 elsif Is_Decimal_Fixed_Point_Type (Typ) then
1216 ("possible missing instantiation of " &
1217 "'Text_'I'O.'Decimal_'I'O!", Nam);
1219 elsif Is_Enumeration_Type (Typ) then
1221 ("possible missing instantiation of " &
1222 "'Text_'I'O.'Enumeration_'I'O!", Nam);
1227 elsif not Is_Overloaded (N)
1228 and then Is_Entity_Name (Nam)
1230 -- Resolution yields a single interpretation. Verify that the
1231 -- reference has capitalization consistent with the declaration.
1233 Set_Entity_With_Style_Check (Nam, Entity (Nam));
1234 Generate_Reference (Entity (Nam), Nam);
1236 Set_Etype (Nam, Etype (Entity (Nam)));
1238 Remove_Abstract_Operations (N);
1245 -----------------------------
1246 -- Analyze_Case_Expression --
1247 -----------------------------
1249 procedure Analyze_Case_Expression (N : Node_Id) is
1250 Expr : constant Node_Id := Expression (N);
1251 FirstX : constant Node_Id := Expression (First (Alternatives (N)));
1253 Exp_Type : Entity_Id;
1254 Exp_Btype : Entity_Id;
1256 Dont_Care : Boolean;
1257 Others_Present : Boolean;
1259 procedure Non_Static_Choice_Error (Choice : Node_Id);
1260 -- Error routine invoked by the generic instantiation below when
1261 -- the case expression has a non static choice.
1263 package Case_Choices_Processing is new
1264 Generic_Choices_Processing
1265 (Get_Alternatives => Alternatives,
1266 Get_Choices => Discrete_Choices,
1267 Process_Empty_Choice => No_OP,
1268 Process_Non_Static_Choice => Non_Static_Choice_Error,
1269 Process_Associated_Node => No_OP);
1270 use Case_Choices_Processing;
1272 -----------------------------
1273 -- Non_Static_Choice_Error --
1274 -----------------------------
1276 procedure Non_Static_Choice_Error (Choice : Node_Id) is
1278 Flag_Non_Static_Expr
1279 ("choice given in case expression is not static!", Choice);
1280 end Non_Static_Choice_Error;
1282 -- Start of processing for Analyze_Case_Expression
1285 if Comes_From_Source (N) then
1286 Check_Compiler_Unit (N);
1289 Analyze_And_Resolve (Expr, Any_Discrete);
1290 Check_Unset_Reference (Expr);
1291 Exp_Type := Etype (Expr);
1292 Exp_Btype := Base_Type (Exp_Type);
1294 Alt := First (Alternatives (N));
1295 while Present (Alt) loop
1296 Analyze (Expression (Alt));
1300 if not Is_Overloaded (FirstX) then
1301 Set_Etype (N, Etype (FirstX));
1309 Set_Etype (N, Any_Type);
1311 Get_First_Interp (FirstX, I, It);
1312 while Present (It.Nam) loop
1314 -- For each interpretation of the first expression, we only
1315 -- add the interpretation if every other expression in the
1316 -- case expression alternatives has a compatible type.
1318 Alt := Next (First (Alternatives (N)));
1319 while Present (Alt) loop
1320 exit when not Has_Compatible_Type (Expression (Alt), It.Typ);
1325 Add_One_Interp (N, It.Typ, It.Typ);
1328 Get_Next_Interp (I, It);
1333 Exp_Btype := Base_Type (Exp_Type);
1335 -- The expression must be of a discrete type which must be determinable
1336 -- independently of the context in which the expression occurs, but
1337 -- using the fact that the expression must be of a discrete type.
1338 -- Moreover, the type this expression must not be a character literal
1339 -- (which is always ambiguous).
1341 -- If error already reported by Resolve, nothing more to do
1343 if Exp_Btype = Any_Discrete
1344 or else Exp_Btype = Any_Type
1348 elsif Exp_Btype = Any_Character then
1350 ("character literal as case expression is ambiguous", Expr);
1354 -- If the case expression is a formal object of mode in out, then
1355 -- treat it as having a nonstatic subtype by forcing use of the base
1356 -- type (which has to get passed to Check_Case_Choices below). Also
1357 -- use base type when the case expression is parenthesized.
1359 if Paren_Count (Expr) > 0
1360 or else (Is_Entity_Name (Expr)
1361 and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter)
1363 Exp_Type := Exp_Btype;
1366 -- Call instantiated Analyze_Choices which does the rest of the work
1368 Analyze_Choices (N, Exp_Type, Dont_Care, Others_Present);
1370 if Exp_Type = Universal_Integer and then not Others_Present then
1372 ("case on universal integer requires OTHERS choice", Expr);
1374 end Analyze_Case_Expression;
1376 ---------------------------
1377 -- Analyze_Comparison_Op --
1378 ---------------------------
1380 procedure Analyze_Comparison_Op (N : Node_Id) is
1381 L : constant Node_Id := Left_Opnd (N);
1382 R : constant Node_Id := Right_Opnd (N);
1383 Op_Id : Entity_Id := Entity (N);
1386 Set_Etype (N, Any_Type);
1387 Candidate_Type := Empty;
1389 Analyze_Expression (L);
1390 Analyze_Expression (R);
1392 if Present (Op_Id) then
1393 if Ekind (Op_Id) = E_Operator then
1394 Find_Comparison_Types (L, R, Op_Id, N);
1396 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1399 if Is_Overloaded (L) then
1400 Set_Etype (L, Intersect_Types (L, R));
1404 Op_Id := Get_Name_Entity_Id (Chars (N));
1405 while Present (Op_Id) loop
1406 if Ekind (Op_Id) = E_Operator then
1407 Find_Comparison_Types (L, R, Op_Id, N);
1409 Analyze_User_Defined_Binary_Op (N, Op_Id);
1412 Op_Id := Homonym (Op_Id);
1417 end Analyze_Comparison_Op;
1419 ---------------------------
1420 -- Analyze_Concatenation --
1421 ---------------------------
1423 procedure Analyze_Concatenation (N : Node_Id) is
1425 -- We wish to avoid deep recursion, because concatenations are often
1426 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1427 -- operands nonrecursively until we find something that is not a
1428 -- concatenation (A in this case), or has already been analyzed. We
1429 -- analyze that, and then walk back up the tree following Parent
1430 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1431 -- work at each level. The Parent pointers allow us to avoid recursion,
1432 -- and thus avoid running out of memory.
1438 Candidate_Type := Empty;
1440 -- The following code is equivalent to:
1442 -- Set_Etype (N, Any_Type);
1443 -- Analyze_Expression (Left_Opnd (N));
1444 -- Analyze_Concatenation_Rest (N);
1446 -- where the Analyze_Expression call recurses back here if the left
1447 -- operand is a concatenation.
1449 -- Walk down left operands
1452 Set_Etype (NN, Any_Type);
1453 L := Left_Opnd (NN);
1454 exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
1458 -- Now (given the above example) NN is A&B and L is A
1460 -- First analyze L ...
1462 Analyze_Expression (L);
1464 -- ... then walk NN back up until we reach N (where we started), calling
1465 -- Analyze_Concatenation_Rest along the way.
1468 Analyze_Concatenation_Rest (NN);
1472 end Analyze_Concatenation;
1474 --------------------------------
1475 -- Analyze_Concatenation_Rest --
1476 --------------------------------
1478 -- If the only one-dimensional array type in scope is String,
1479 -- this is the resulting type of the operation. Otherwise there
1480 -- will be a concatenation operation defined for each user-defined
1481 -- one-dimensional array.
1483 procedure Analyze_Concatenation_Rest (N : Node_Id) is
1484 L : constant Node_Id := Left_Opnd (N);
1485 R : constant Node_Id := Right_Opnd (N);
1486 Op_Id : Entity_Id := Entity (N);
1491 Analyze_Expression (R);
1493 -- If the entity is present, the node appears in an instance, and
1494 -- denotes a predefined concatenation operation. The resulting type is
1495 -- obtained from the arguments when possible. If the arguments are
1496 -- aggregates, the array type and the concatenation type must be
1499 if Present (Op_Id) then
1500 if Ekind (Op_Id) = E_Operator then
1501 LT := Base_Type (Etype (L));
1502 RT := Base_Type (Etype (R));
1504 if Is_Array_Type (LT)
1505 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1507 Add_One_Interp (N, Op_Id, LT);
1509 elsif Is_Array_Type (RT)
1510 and then LT = Base_Type (Component_Type (RT))
1512 Add_One_Interp (N, Op_Id, RT);
1514 -- If one operand is a string type or a user-defined array type,
1515 -- and the other is a literal, result is of the specific type.
1518 (Root_Type (LT) = Standard_String
1519 or else Scope (LT) /= Standard_Standard)
1520 and then Etype (R) = Any_String
1522 Add_One_Interp (N, Op_Id, LT);
1525 (Root_Type (RT) = Standard_String
1526 or else Scope (RT) /= Standard_Standard)
1527 and then Etype (L) = Any_String
1529 Add_One_Interp (N, Op_Id, RT);
1531 elsif not Is_Generic_Type (Etype (Op_Id)) then
1532 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1535 -- Type and its operations must be visible
1537 Set_Entity (N, Empty);
1538 Analyze_Concatenation (N);
1542 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1546 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1547 while Present (Op_Id) loop
1548 if Ekind (Op_Id) = E_Operator then
1550 -- Do not consider operators declared in dead code, they can
1551 -- not be part of the resolution.
1553 if Is_Eliminated (Op_Id) then
1556 Find_Concatenation_Types (L, R, Op_Id, N);
1560 Analyze_User_Defined_Binary_Op (N, Op_Id);
1563 Op_Id := Homonym (Op_Id);
1568 end Analyze_Concatenation_Rest;
1570 -------------------------
1571 -- Analyze_Equality_Op --
1572 -------------------------
1574 procedure Analyze_Equality_Op (N : Node_Id) is
1575 Loc : constant Source_Ptr := Sloc (N);
1576 L : constant Node_Id := Left_Opnd (N);
1577 R : constant Node_Id := Right_Opnd (N);
1581 Set_Etype (N, Any_Type);
1582 Candidate_Type := Empty;
1584 Analyze_Expression (L);
1585 Analyze_Expression (R);
1587 -- If the entity is set, the node is a generic instance with a non-local
1588 -- reference to the predefined operator or to a user-defined function.
1589 -- It can also be an inequality that is expanded into the negation of a
1590 -- call to a user-defined equality operator.
1592 -- For the predefined case, the result is Boolean, regardless of the
1593 -- type of the operands. The operands may even be limited, if they are
1594 -- generic actuals. If they are overloaded, label the left argument with
1595 -- the common type that must be present, or with the type of the formal
1596 -- of the user-defined function.
1598 if Present (Entity (N)) then
1599 Op_Id := Entity (N);
1601 if Ekind (Op_Id) = E_Operator then
1602 Add_One_Interp (N, Op_Id, Standard_Boolean);
1604 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1607 if Is_Overloaded (L) then
1608 if Ekind (Op_Id) = E_Operator then
1609 Set_Etype (L, Intersect_Types (L, R));
1611 Set_Etype (L, Etype (First_Formal (Op_Id)));
1616 Op_Id := Get_Name_Entity_Id (Chars (N));
1617 while Present (Op_Id) loop
1618 if Ekind (Op_Id) = E_Operator then
1619 Find_Equality_Types (L, R, Op_Id, N);
1621 Analyze_User_Defined_Binary_Op (N, Op_Id);
1624 Op_Id := Homonym (Op_Id);
1628 -- If there was no match, and the operator is inequality, this may
1629 -- be a case where inequality has not been made explicit, as for
1630 -- tagged types. Analyze the node as the negation of an equality
1631 -- operation. This cannot be done earlier, because before analysis
1632 -- we cannot rule out the presence of an explicit inequality.
1634 if Etype (N) = Any_Type
1635 and then Nkind (N) = N_Op_Ne
1637 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1638 while Present (Op_Id) loop
1639 if Ekind (Op_Id) = E_Operator then
1640 Find_Equality_Types (L, R, Op_Id, N);
1642 Analyze_User_Defined_Binary_Op (N, Op_Id);
1645 Op_Id := Homonym (Op_Id);
1648 if Etype (N) /= Any_Type then
1649 Op_Id := Entity (N);
1655 Left_Opnd => Left_Opnd (N),
1656 Right_Opnd => Right_Opnd (N))));
1658 Set_Entity (Right_Opnd (N), Op_Id);
1664 end Analyze_Equality_Op;
1666 ----------------------------------
1667 -- Analyze_Explicit_Dereference --
1668 ----------------------------------
1670 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1671 Loc : constant Source_Ptr := Sloc (N);
1672 P : constant Node_Id := Prefix (N);
1678 function Is_Function_Type return Boolean;
1679 -- Check whether node may be interpreted as an implicit function call
1681 ----------------------
1682 -- Is_Function_Type --
1683 ----------------------
1685 function Is_Function_Type return Boolean is
1690 if not Is_Overloaded (N) then
1691 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1692 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1695 Get_First_Interp (N, I, It);
1696 while Present (It.Nam) loop
1697 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1698 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1703 Get_Next_Interp (I, It);
1708 end Is_Function_Type;
1710 -- Start of processing for Analyze_Explicit_Dereference
1713 -- If source node, check SPARK restriction. We guard this with the
1714 -- source node check, because ???
1716 if Comes_From_Source (N) then
1717 Check_SPARK_Restriction ("explicit dereference is not allowed", N);
1720 -- In formal verification mode, keep track of all reads and writes
1721 -- through explicit dereferences.
1724 Alfa.Generate_Dereference (N);
1728 Set_Etype (N, Any_Type);
1730 -- Test for remote access to subprogram type, and if so return
1731 -- after rewriting the original tree.
1733 if Remote_AST_E_Dereference (P) then
1737 -- Normal processing for other than remote access to subprogram type
1739 if not Is_Overloaded (P) then
1740 if Is_Access_Type (Etype (P)) then
1742 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
1743 -- avoid other problems caused by the Private_Subtype and it is
1744 -- safe to go to the Base_Type because this is the same as
1745 -- converting the access value to its Base_Type.
1748 DT : Entity_Id := Designated_Type (Etype (P));
1751 if Ekind (DT) = E_Private_Subtype
1752 and then Is_For_Access_Subtype (DT)
1754 DT := Base_Type (DT);
1757 -- An explicit dereference is a legal occurrence of an
1758 -- incomplete type imported through a limited_with clause,
1759 -- if the full view is visible.
1761 if From_With_Type (DT)
1762 and then not From_With_Type (Scope (DT))
1764 (Is_Immediately_Visible (Scope (DT))
1766 (Is_Child_Unit (Scope (DT))
1767 and then Is_Visible_Child_Unit (Scope (DT))))
1769 Set_Etype (N, Available_View (DT));
1776 elsif Etype (P) /= Any_Type then
1777 Error_Msg_N ("prefix of dereference must be an access type", N);
1782 Get_First_Interp (P, I, It);
1783 while Present (It.Nam) loop
1786 if Is_Access_Type (T) then
1787 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1790 Get_Next_Interp (I, It);
1793 -- Error if no interpretation of the prefix has an access type
1795 if Etype (N) = Any_Type then
1797 ("access type required in prefix of explicit dereference", P);
1798 Set_Etype (N, Any_Type);
1804 and then Nkind (Parent (N)) /= N_Indexed_Component
1806 and then (Nkind (Parent (N)) /= N_Function_Call
1807 or else N /= Name (Parent (N)))
1809 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1810 or else N /= Name (Parent (N)))
1812 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1813 and then (Nkind (Parent (N)) /= N_Attribute_Reference
1815 (Attribute_Name (Parent (N)) /= Name_Address
1817 Attribute_Name (Parent (N)) /= Name_Access))
1819 -- Name is a function call with no actuals, in a context that
1820 -- requires deproceduring (including as an actual in an enclosing
1821 -- function or procedure call). There are some pathological cases
1822 -- where the prefix might include functions that return access to
1823 -- subprograms and others that return a regular type. Disambiguation
1824 -- of those has to take place in Resolve.
1827 Make_Function_Call (Loc,
1828 Name => Make_Explicit_Dereference (Loc, P),
1829 Parameter_Associations => New_List);
1831 -- If the prefix is overloaded, remove operations that have formals,
1832 -- we know that this is a parameterless call.
1834 if Is_Overloaded (P) then
1835 Get_First_Interp (P, I, It);
1836 while Present (It.Nam) loop
1839 if No (First_Formal (Base_Type (Designated_Type (T)))) then
1845 Get_Next_Interp (I, It);
1852 elsif not Is_Function_Type
1853 and then Is_Overloaded (N)
1855 -- The prefix may include access to subprograms and other access
1856 -- types. If the context selects the interpretation that is a
1857 -- function call (not a procedure call) we cannot rewrite the node
1858 -- yet, but we include the result of the call interpretation.
1860 Get_First_Interp (N, I, It);
1861 while Present (It.Nam) loop
1862 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
1863 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
1864 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
1866 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
1869 Get_Next_Interp (I, It);
1873 -- A value of remote access-to-class-wide must not be dereferenced
1876 Validate_Remote_Access_To_Class_Wide_Type (N);
1877 end Analyze_Explicit_Dereference;
1879 ------------------------
1880 -- Analyze_Expression --
1881 ------------------------
1883 procedure Analyze_Expression (N : Node_Id) is
1886 Check_Parameterless_Call (N);
1887 end Analyze_Expression;
1889 -------------------------------------
1890 -- Analyze_Expression_With_Actions --
1891 -------------------------------------
1893 procedure Analyze_Expression_With_Actions (N : Node_Id) is
1897 A := First (Actions (N));
1904 Analyze_Expression (Expression (N));
1905 Set_Etype (N, Etype (Expression (N)));
1906 end Analyze_Expression_With_Actions;
1908 ---------------------------
1909 -- Analyze_If_Expression --
1910 ---------------------------
1912 procedure Analyze_If_Expression (N : Node_Id) is
1913 Condition : constant Node_Id := First (Expressions (N));
1914 Then_Expr : constant Node_Id := Next (Condition);
1915 Else_Expr : Node_Id;
1918 -- Defend against error of missing expressions from previous error
1920 if No (Then_Expr) then
1921 Check_Error_Detected;
1925 Check_SPARK_Restriction ("if expression is not allowed", N);
1927 Else_Expr := Next (Then_Expr);
1929 if Comes_From_Source (N) then
1930 Check_Compiler_Unit (N);
1933 Analyze_Expression (Condition);
1934 Analyze_Expression (Then_Expr);
1936 if Present (Else_Expr) then
1937 Analyze_Expression (Else_Expr);
1940 -- If then expression not overloaded, then that decides the type
1942 if not Is_Overloaded (Then_Expr) then
1943 Set_Etype (N, Etype (Then_Expr));
1945 -- Case where then expression is overloaded
1953 Set_Etype (N, Any_Type);
1955 -- Shouldn't the following statement be down in the ELSE of the
1956 -- following loop? ???
1958 Get_First_Interp (Then_Expr, I, It);
1960 -- if no Else_Expression the conditional must be boolean
1962 if No (Else_Expr) then
1963 Set_Etype (N, Standard_Boolean);
1965 -- Else_Expression Present. For each possible intepretation of
1966 -- the Then_Expression, add it only if the Else_Expression has
1967 -- a compatible type.
1970 while Present (It.Nam) loop
1971 if Has_Compatible_Type (Else_Expr, It.Typ) then
1972 Add_One_Interp (N, It.Typ, It.Typ);
1975 Get_Next_Interp (I, It);
1980 end Analyze_If_Expression;
1982 ------------------------------------
1983 -- Analyze_Indexed_Component_Form --
1984 ------------------------------------
1986 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
1987 P : constant Node_Id := Prefix (N);
1988 Exprs : constant List_Id := Expressions (N);
1994 procedure Process_Function_Call;
1995 -- Prefix in indexed component form is an overloadable entity,
1996 -- so the node is a function call. Reformat it as such.
1998 procedure Process_Indexed_Component;
1999 -- Prefix in indexed component form is actually an indexed component.
2000 -- This routine processes it, knowing that the prefix is already
2003 procedure Process_Indexed_Component_Or_Slice;
2004 -- An indexed component with a single index may designate a slice if
2005 -- the index is a subtype mark. This routine disambiguates these two
2006 -- cases by resolving the prefix to see if it is a subtype mark.
2008 procedure Process_Overloaded_Indexed_Component;
2009 -- If the prefix of an indexed component is overloaded, the proper
2010 -- interpretation is selected by the index types and the context.
2012 ---------------------------
2013 -- Process_Function_Call --
2014 ---------------------------
2016 procedure Process_Function_Call is
2020 Change_Node (N, N_Function_Call);
2022 Set_Parameter_Associations (N, Exprs);
2024 -- Analyze actuals prior to analyzing the call itself
2026 Actual := First (Parameter_Associations (N));
2027 while Present (Actual) loop
2029 Check_Parameterless_Call (Actual);
2031 -- Move to next actual. Note that we use Next, not Next_Actual
2032 -- here. The reason for this is a bit subtle. If a function call
2033 -- includes named associations, the parser recognizes the node as
2034 -- a call, and it is analyzed as such. If all associations are
2035 -- positional, the parser builds an indexed_component node, and
2036 -- it is only after analysis of the prefix that the construct
2037 -- is recognized as a call, in which case Process_Function_Call
2038 -- rewrites the node and analyzes the actuals. If the list of
2039 -- actuals is malformed, the parser may leave the node as an
2040 -- indexed component (despite the presence of named associations).
2041 -- The iterator Next_Actual is equivalent to Next if the list is
2042 -- positional, but follows the normalized chain of actuals when
2043 -- named associations are present. In this case normalization has
2044 -- not taken place, and actuals remain unanalyzed, which leads to
2045 -- subsequent crashes or loops if there is an attempt to continue
2046 -- analysis of the program.
2052 end Process_Function_Call;
2054 -------------------------------
2055 -- Process_Indexed_Component --
2056 -------------------------------
2058 procedure Process_Indexed_Component is
2060 Array_Type : Entity_Id;
2062 Pent : Entity_Id := Empty;
2065 Exp := First (Exprs);
2067 if Is_Overloaded (P) then
2068 Process_Overloaded_Indexed_Component;
2071 Array_Type := Etype (P);
2073 if Is_Entity_Name (P) then
2075 elsif Nkind (P) = N_Selected_Component
2076 and then Is_Entity_Name (Selector_Name (P))
2078 Pent := Entity (Selector_Name (P));
2081 -- Prefix must be appropriate for an array type, taking into
2082 -- account a possible implicit dereference.
2084 if Is_Access_Type (Array_Type) then
2085 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2086 Array_Type := Process_Implicit_Dereference_Prefix (Pent, P);
2089 if Is_Array_Type (Array_Type) then
2092 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
2094 Set_Etype (N, Any_Type);
2096 if not Has_Compatible_Type
2097 (Exp, Entry_Index_Type (Pent))
2099 Error_Msg_N ("invalid index type in entry name", N);
2101 elsif Present (Next (Exp)) then
2102 Error_Msg_N ("too many subscripts in entry reference", N);
2105 Set_Etype (N, Etype (P));
2110 elsif Is_Record_Type (Array_Type)
2111 and then Remote_AST_I_Dereference (P)
2115 elsif Try_Container_Indexing (N, P, Exprs) then
2118 elsif Array_Type = Any_Type then
2119 Set_Etype (N, Any_Type);
2121 -- In most cases the analysis of the prefix will have emitted
2122 -- an error already, but if the prefix may be interpreted as a
2123 -- call in prefixed notation, the report is left to the caller.
2124 -- To prevent cascaded errors, report only if no previous ones.
2126 if Serious_Errors_Detected = 0 then
2127 Error_Msg_N ("invalid prefix in indexed component", P);
2129 if Nkind (P) = N_Expanded_Name then
2130 Error_Msg_NE ("\& is not visible", P, Selector_Name (P));
2136 -- Here we definitely have a bad indexing
2139 if Nkind (Parent (N)) = N_Requeue_Statement
2140 and then Present (Pent) and then Ekind (Pent) = E_Entry
2143 ("REQUEUE does not permit parameters", First (Exprs));
2145 elsif Is_Entity_Name (P)
2146 and then Etype (P) = Standard_Void_Type
2148 Error_Msg_NE ("incorrect use of&", P, Entity (P));
2151 Error_Msg_N ("array type required in indexed component", P);
2154 Set_Etype (N, Any_Type);
2158 Index := First_Index (Array_Type);
2159 while Present (Index) and then Present (Exp) loop
2160 if not Has_Compatible_Type (Exp, Etype (Index)) then
2161 Wrong_Type (Exp, Etype (Index));
2162 Set_Etype (N, Any_Type);
2170 Set_Etype (N, Component_Type (Array_Type));
2171 Check_Implicit_Dereference (N, Etype (N));
2173 if Present (Index) then
2175 ("too few subscripts in array reference", First (Exprs));
2177 elsif Present (Exp) then
2178 Error_Msg_N ("too many subscripts in array reference", Exp);
2181 end Process_Indexed_Component;
2183 ----------------------------------------
2184 -- Process_Indexed_Component_Or_Slice --
2185 ----------------------------------------
2187 procedure Process_Indexed_Component_Or_Slice is
2189 Exp := First (Exprs);
2190 while Present (Exp) loop
2191 Analyze_Expression (Exp);
2195 Exp := First (Exprs);
2197 -- If one index is present, and it is a subtype name, then the
2198 -- node denotes a slice (note that the case of an explicit range
2199 -- for a slice was already built as an N_Slice node in the first
2200 -- place, so that case is not handled here).
2202 -- We use a replace rather than a rewrite here because this is one
2203 -- of the cases in which the tree built by the parser is plain wrong.
2206 and then Is_Entity_Name (Exp)
2207 and then Is_Type (Entity (Exp))
2210 Make_Slice (Sloc (N),
2212 Discrete_Range => New_Copy (Exp)));
2215 -- Otherwise (more than one index present, or single index is not
2216 -- a subtype name), then we have the indexed component case.
2219 Process_Indexed_Component;
2221 end Process_Indexed_Component_Or_Slice;
2223 ------------------------------------------
2224 -- Process_Overloaded_Indexed_Component --
2225 ------------------------------------------
2227 procedure Process_Overloaded_Indexed_Component is
2236 Set_Etype (N, Any_Type);
2238 Get_First_Interp (P, I, It);
2239 while Present (It.Nam) loop
2242 if Is_Access_Type (Typ) then
2243 Typ := Designated_Type (Typ);
2244 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2247 if Is_Array_Type (Typ) then
2249 -- Got a candidate: verify that index types are compatible
2251 Index := First_Index (Typ);
2253 Exp := First (Exprs);
2254 while Present (Index) and then Present (Exp) loop
2255 if Has_Compatible_Type (Exp, Etype (Index)) then
2267 if Found and then No (Index) and then No (Exp) then
2269 CT : constant Entity_Id :=
2270 Base_Type (Component_Type (Typ));
2272 Add_One_Interp (N, CT, CT);
2273 Check_Implicit_Dereference (N, CT);
2277 elsif Try_Container_Indexing (N, P, Exprs) then
2282 Get_Next_Interp (I, It);
2285 if Etype (N) = Any_Type then
2286 Error_Msg_N ("no legal interpretation for indexed component", N);
2287 Set_Is_Overloaded (N, False);
2291 end Process_Overloaded_Indexed_Component;
2293 -- Start of processing for Analyze_Indexed_Component_Form
2296 -- Get name of array, function or type
2300 if Nkind (N) in N_Subprogram_Call then
2302 -- If P is an explicit dereference whose prefix is of a
2303 -- remote access-to-subprogram type, then N has already
2304 -- been rewritten as a subprogram call and analyzed.
2309 pragma Assert (Nkind (N) = N_Indexed_Component);
2311 P_T := Base_Type (Etype (P));
2313 if Is_Entity_Name (P) and then Present (Entity (P)) then
2316 if Is_Type (U_N) then
2318 -- Reformat node as a type conversion
2320 E := Remove_Head (Exprs);
2322 if Present (First (Exprs)) then
2324 ("argument of type conversion must be single expression", N);
2327 Change_Node (N, N_Type_Conversion);
2328 Set_Subtype_Mark (N, P);
2330 Set_Expression (N, E);
2332 -- After changing the node, call for the specific Analysis
2333 -- routine directly, to avoid a double call to the expander.
2335 Analyze_Type_Conversion (N);
2339 if Is_Overloadable (U_N) then
2340 Process_Function_Call;
2342 elsif Ekind (Etype (P)) = E_Subprogram_Type
2343 or else (Is_Access_Type (Etype (P))
2345 Ekind (Designated_Type (Etype (P))) =
2348 -- Call to access_to-subprogram with possible implicit dereference
2350 Process_Function_Call;
2352 elsif Is_Generic_Subprogram (U_N) then
2354 -- A common beginner's (or C++ templates fan) error
2356 Error_Msg_N ("generic subprogram cannot be called", N);
2357 Set_Etype (N, Any_Type);
2361 Process_Indexed_Component_Or_Slice;
2364 -- If not an entity name, prefix is an expression that may denote
2365 -- an array or an access-to-subprogram.
2368 if Ekind (P_T) = E_Subprogram_Type
2369 or else (Is_Access_Type (P_T)
2371 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
2373 Process_Function_Call;
2375 elsif Nkind (P) = N_Selected_Component
2376 and then Is_Overloadable (Entity (Selector_Name (P)))
2378 Process_Function_Call;
2381 -- Indexed component, slice, or a call to a member of a family
2382 -- entry, which will be converted to an entry call later.
2384 Process_Indexed_Component_Or_Slice;
2388 Analyze_Dimension (N);
2389 end Analyze_Indexed_Component_Form;
2391 ------------------------
2392 -- Analyze_Logical_Op --
2393 ------------------------
2395 procedure Analyze_Logical_Op (N : Node_Id) is
2396 L : constant Node_Id := Left_Opnd (N);
2397 R : constant Node_Id := Right_Opnd (N);
2398 Op_Id : Entity_Id := Entity (N);
2401 Set_Etype (N, Any_Type);
2402 Candidate_Type := Empty;
2404 Analyze_Expression (L);
2405 Analyze_Expression (R);
2407 if Present (Op_Id) then
2409 if Ekind (Op_Id) = E_Operator then
2410 Find_Boolean_Types (L, R, Op_Id, N);
2412 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2416 Op_Id := Get_Name_Entity_Id (Chars (N));
2417 while Present (Op_Id) loop
2418 if Ekind (Op_Id) = E_Operator then
2419 Find_Boolean_Types (L, R, Op_Id, N);
2421 Analyze_User_Defined_Binary_Op (N, Op_Id);
2424 Op_Id := Homonym (Op_Id);
2429 end Analyze_Logical_Op;
2431 ---------------------------
2432 -- Analyze_Membership_Op --
2433 ---------------------------
2435 procedure Analyze_Membership_Op (N : Node_Id) is
2436 Loc : constant Source_Ptr := Sloc (N);
2437 L : constant Node_Id := Left_Opnd (N);
2438 R : constant Node_Id := Right_Opnd (N);
2440 Index : Interp_Index;
2442 Found : Boolean := False;
2446 procedure Try_One_Interp (T1 : Entity_Id);
2447 -- Routine to try one proposed interpretation. Note that the context
2448 -- of the operation plays no role in resolving the arguments, so that
2449 -- if there is more than one interpretation of the operands that is
2450 -- compatible with a membership test, the operation is ambiguous.
2452 --------------------
2453 -- Try_One_Interp --
2454 --------------------
2456 procedure Try_One_Interp (T1 : Entity_Id) is
2458 if Has_Compatible_Type (R, T1) then
2460 and then Base_Type (T1) /= Base_Type (T_F)
2462 It := Disambiguate (L, I_F, Index, Any_Type);
2464 if It = No_Interp then
2465 Ambiguous_Operands (N);
2466 Set_Etype (L, Any_Type);
2483 procedure Analyze_Set_Membership;
2484 -- If a set of alternatives is present, analyze each and find the
2485 -- common type to which they must all resolve.
2487 ----------------------------
2488 -- Analyze_Set_Membership --
2489 ----------------------------
2491 procedure Analyze_Set_Membership is
2493 Index : Interp_Index;
2495 Candidate_Interps : Node_Id;
2496 Common_Type : Entity_Id := Empty;
2500 Candidate_Interps := L;
2502 if not Is_Overloaded (L) then
2503 Common_Type := Etype (L);
2505 Alt := First (Alternatives (N));
2506 while Present (Alt) loop
2509 if not Has_Compatible_Type (Alt, Common_Type) then
2510 Wrong_Type (Alt, Common_Type);
2517 Alt := First (Alternatives (N));
2518 while Present (Alt) loop
2520 if not Is_Overloaded (Alt) then
2521 Common_Type := Etype (Alt);
2524 Get_First_Interp (Alt, Index, It);
2525 while Present (It.Typ) loop
2527 Has_Compatible_Type (Candidate_Interps, It.Typ)
2529 Remove_Interp (Index);
2532 Get_Next_Interp (Index, It);
2535 Get_First_Interp (Alt, Index, It);
2538 Error_Msg_N ("alternative has no legal type", Alt);
2542 -- If alternative is not overloaded, we have a unique type
2545 Set_Etype (Alt, It.Typ);
2546 Get_Next_Interp (Index, It);
2549 Set_Is_Overloaded (Alt, False);
2550 Common_Type := Etype (Alt);
2553 Candidate_Interps := Alt;
2560 Set_Etype (N, Standard_Boolean);
2562 if Present (Common_Type) then
2563 Set_Etype (L, Common_Type);
2564 Set_Is_Overloaded (L, False);
2567 Error_Msg_N ("cannot resolve membership operation", N);
2569 end Analyze_Set_Membership;
2571 -- Start of processing for Analyze_Membership_Op
2574 Analyze_Expression (L);
2577 and then Ada_Version >= Ada_2012
2579 Analyze_Set_Membership;
2583 if Nkind (R) = N_Range
2584 or else (Nkind (R) = N_Attribute_Reference
2585 and then Attribute_Name (R) = Name_Range)
2589 if not Is_Overloaded (L) then
2590 Try_One_Interp (Etype (L));
2593 Get_First_Interp (L, Index, It);
2594 while Present (It.Typ) loop
2595 Try_One_Interp (It.Typ);
2596 Get_Next_Interp (Index, It);
2600 -- If not a range, it can be a subtype mark, or else it is a degenerate
2601 -- membership test with a singleton value, i.e. a test for equality,
2602 -- if the types are compatible.
2607 if Is_Entity_Name (R)
2608 and then Is_Type (Entity (R))
2611 Check_Fully_Declared (Entity (R), R);
2613 elsif Ada_Version >= Ada_2012
2614 and then Has_Compatible_Type (R, Etype (L))
2616 if Nkind (N) = N_In then
2632 -- In all versions of the language, if we reach this point there
2633 -- is a previous error that will be diagnosed below.
2639 -- Compatibility between expression and subtype mark or range is
2640 -- checked during resolution. The result of the operation is Boolean
2643 Set_Etype (N, Standard_Boolean);
2645 if Comes_From_Source (N)
2646 and then Present (Right_Opnd (N))
2647 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
2649 Error_Msg_N ("membership test not applicable to cpp-class types", N);
2651 end Analyze_Membership_Op;
2657 procedure Analyze_Mod (N : Node_Id) is
2659 -- A special warning check, if we have an expression of the form:
2660 -- expr mod 2 * literal
2661 -- where literal is 64 or less, then probably what was meant was
2662 -- expr mod 2 ** literal
2663 -- so issue an appropriate warning.
2665 if Warn_On_Suspicious_Modulus_Value
2666 and then Nkind (Right_Opnd (N)) = N_Integer_Literal
2667 and then Intval (Right_Opnd (N)) = Uint_2
2668 and then Nkind (Parent (N)) = N_Op_Multiply
2669 and then Nkind (Right_Opnd (Parent (N))) = N_Integer_Literal
2670 and then Intval (Right_Opnd (Parent (N))) <= Uint_64
2673 ("suspicious MOD value, was '*'* intended'??", Parent (N));
2676 -- Remaining processing is same as for other arithmetic operators
2678 Analyze_Arithmetic_Op (N);
2681 ----------------------
2682 -- Analyze_Negation --
2683 ----------------------
2685 procedure Analyze_Negation (N : Node_Id) is
2686 R : constant Node_Id := Right_Opnd (N);
2687 Op_Id : Entity_Id := Entity (N);
2690 Set_Etype (N, Any_Type);
2691 Candidate_Type := Empty;
2693 Analyze_Expression (R);
2695 if Present (Op_Id) then
2696 if Ekind (Op_Id) = E_Operator then
2697 Find_Negation_Types (R, Op_Id, N);
2699 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2703 Op_Id := Get_Name_Entity_Id (Chars (N));
2704 while Present (Op_Id) loop
2705 if Ekind (Op_Id) = E_Operator then
2706 Find_Negation_Types (R, Op_Id, N);
2708 Analyze_User_Defined_Unary_Op (N, Op_Id);
2711 Op_Id := Homonym (Op_Id);
2716 end Analyze_Negation;
2722 procedure Analyze_Null (N : Node_Id) is
2724 Check_SPARK_Restriction ("null is not allowed", N);
2726 Set_Etype (N, Any_Access);
2729 ----------------------
2730 -- Analyze_One_Call --
2731 ----------------------
2733 procedure Analyze_One_Call
2737 Success : out Boolean;
2738 Skip_First : Boolean := False)
2740 Actuals : constant List_Id := Parameter_Associations (N);
2741 Prev_T : constant Entity_Id := Etype (N);
2743 Must_Skip : constant Boolean := Skip_First
2744 or else Nkind (Original_Node (N)) = N_Selected_Component
2746 (Nkind (Original_Node (N)) = N_Indexed_Component
2747 and then Nkind (Prefix (Original_Node (N)))
2748 = N_Selected_Component);
2749 -- The first formal must be omitted from the match when trying to find
2750 -- a primitive operation that is a possible interpretation, and also
2751 -- after the call has been rewritten, because the corresponding actual
2752 -- is already known to be compatible, and because this may be an
2753 -- indexing of a call with default parameters.
2757 Is_Indexed : Boolean := False;
2758 Is_Indirect : Boolean := False;
2759 Subp_Type : constant Entity_Id := Etype (Nam);
2762 function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
2763 -- There may be a user-defined operator that hides the current
2764 -- interpretation. We must check for this independently of the
2765 -- analysis of the call with the user-defined operation, because
2766 -- the parameter names may be wrong and yet the hiding takes place.
2767 -- This fixes a problem with ACATS test B34014O.
2769 -- When the type Address is a visible integer type, and the DEC
2770 -- system extension is visible, the predefined operator may be
2771 -- hidden as well, by one of the address operations in auxdec.
2772 -- Finally, The abstract operations on address do not hide the
2773 -- predefined operator (this is the purpose of making them abstract).
2775 procedure Indicate_Name_And_Type;
2776 -- If candidate interpretation matches, indicate name and type of
2777 -- result on call node.
2779 ----------------------------
2780 -- Indicate_Name_And_Type --
2781 ----------------------------
2783 procedure Indicate_Name_And_Type is
2785 Add_One_Interp (N, Nam, Etype (Nam));
2786 Check_Implicit_Dereference (N, Etype (Nam));
2789 -- If the prefix of the call is a name, indicate the entity
2790 -- being called. If it is not a name, it is an expression that
2791 -- denotes an access to subprogram or else an entry or family. In
2792 -- the latter case, the name is a selected component, and the entity
2793 -- being called is noted on the selector.
2795 if not Is_Type (Nam) then
2796 if Is_Entity_Name (Name (N)) then
2797 Set_Entity (Name (N), Nam);
2799 elsif Nkind (Name (N)) = N_Selected_Component then
2800 Set_Entity (Selector_Name (Name (N)), Nam);
2804 if Debug_Flag_E and not Report then
2805 Write_Str (" Overloaded call ");
2806 Write_Int (Int (N));
2807 Write_Str (" compatible with ");
2808 Write_Int (Int (Nam));
2811 end Indicate_Name_And_Type;
2813 ------------------------
2814 -- Operator_Hidden_By --
2815 ------------------------
2817 function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
2818 Act1 : constant Node_Id := First_Actual (N);
2819 Act2 : constant Node_Id := Next_Actual (Act1);
2820 Form1 : constant Entity_Id := First_Formal (Fun);
2821 Form2 : constant Entity_Id := Next_Formal (Form1);
2824 if Ekind (Fun) /= E_Function
2825 or else Is_Abstract_Subprogram (Fun)
2829 elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
2832 elsif Present (Form2) then
2834 No (Act2) or else not Has_Compatible_Type (Act2, Etype (Form2))
2839 elsif Present (Act2) then
2843 -- Now we know that the arity of the operator matches the function,
2844 -- and the function call is a valid interpretation. The function
2845 -- hides the operator if it has the right signature, or if one of
2846 -- its operands is a non-abstract operation on Address when this is
2847 -- a visible integer type.
2849 return Hides_Op (Fun, Nam)
2850 or else Is_Descendent_Of_Address (Etype (Form1))
2853 and then Is_Descendent_Of_Address (Etype (Form2)));
2854 end Operator_Hidden_By;
2856 -- Start of processing for Analyze_One_Call
2861 -- If the subprogram has no formals or if all the formals have defaults,
2862 -- and the return type is an array type, the node may denote an indexing
2863 -- of the result of a parameterless call. In Ada 2005, the subprogram
2864 -- may have one non-defaulted formal, and the call may have been written
2865 -- in prefix notation, so that the rebuilt parameter list has more than
2868 if not Is_Overloadable (Nam)
2869 and then Ekind (Nam) /= E_Subprogram_Type
2870 and then Ekind (Nam) /= E_Entry_Family
2875 -- An indexing requires at least one actual
2877 if not Is_Empty_List (Actuals)
2879 (Needs_No_Actuals (Nam)
2881 (Needs_One_Actual (Nam)
2882 and then Present (Next_Actual (First (Actuals)))))
2884 if Is_Array_Type (Subp_Type) then
2885 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
2887 elsif Is_Access_Type (Subp_Type)
2888 and then Is_Array_Type (Designated_Type (Subp_Type))
2892 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
2894 -- The prefix can also be a parameterless function that returns an
2895 -- access to subprogram, in which case this is an indirect call.
2896 -- If this succeeds, an explicit dereference is added later on,
2897 -- in Analyze_Call or Resolve_Call.
2899 elsif Is_Access_Type (Subp_Type)
2900 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
2902 Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
2907 -- If the call has been transformed into a slice, it is of the form
2908 -- F (Subtype) where F is parameterless. The node has been rewritten in
2909 -- Try_Indexed_Call and there is nothing else to do.
2912 and then Nkind (N) = N_Slice
2918 (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
2922 -- If an indirect call is a possible interpretation, indicate
2923 -- success to the caller.
2929 -- Mismatch in number or names of parameters
2931 elsif Debug_Flag_E then
2932 Write_Str (" normalization fails in call ");
2933 Write_Int (Int (N));
2934 Write_Str (" with subprogram ");
2935 Write_Int (Int (Nam));
2939 -- If the context expects a function call, discard any interpretation
2940 -- that is a procedure. If the node is not overloaded, leave as is for
2941 -- better error reporting when type mismatch is found.
2943 elsif Nkind (N) = N_Function_Call
2944 and then Is_Overloaded (Name (N))
2945 and then Ekind (Nam) = E_Procedure
2949 -- Ditto for function calls in a procedure context
2951 elsif Nkind (N) = N_Procedure_Call_Statement
2952 and then Is_Overloaded (Name (N))
2953 and then Etype (Nam) /= Standard_Void_Type
2957 elsif No (Actuals) then
2959 -- If Normalize succeeds, then there are default parameters for
2962 Indicate_Name_And_Type;
2964 elsif Ekind (Nam) = E_Operator then
2965 if Nkind (N) = N_Procedure_Call_Statement then
2969 -- This can occur when the prefix of the call is an operator
2970 -- name or an expanded name whose selector is an operator name.
2972 Analyze_Operator_Call (N, Nam);
2974 if Etype (N) /= Prev_T then
2976 -- Check that operator is not hidden by a function interpretation
2978 if Is_Overloaded (Name (N)) then
2984 Get_First_Interp (Name (N), I, It);
2985 while Present (It.Nam) loop
2986 if Operator_Hidden_By (It.Nam) then
2987 Set_Etype (N, Prev_T);
2991 Get_Next_Interp (I, It);
2996 -- If operator matches formals, record its name on the call.
2997 -- If the operator is overloaded, Resolve will select the
2998 -- correct one from the list of interpretations. The call
2999 -- node itself carries the first candidate.
3001 Set_Entity (Name (N), Nam);
3004 elsif Report and then Etype (N) = Any_Type then
3005 Error_Msg_N ("incompatible arguments for operator", N);
3009 -- Normalize_Actuals has chained the named associations in the
3010 -- correct order of the formals.
3012 Actual := First_Actual (N);
3013 Formal := First_Formal (Nam);
3015 -- If we are analyzing a call rewritten from object notation, skip
3016 -- first actual, which may be rewritten later as an explicit
3020 Next_Actual (Actual);
3021 Next_Formal (Formal);
3024 while Present (Actual) and then Present (Formal) loop
3025 if Nkind (Parent (Actual)) /= N_Parameter_Association
3026 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
3028 -- The actual can be compatible with the formal, but we must
3029 -- also check that the context is not an address type that is
3030 -- visibly an integer type, as is the case in VMS_64. In this
3031 -- case the use of literals is illegal, except in the body of
3032 -- descendents of system, where arithmetic operations on
3033 -- address are of course used.
3035 if Has_Compatible_Type (Actual, Etype (Formal))
3037 (Etype (Actual) /= Universal_Integer
3038 or else not Is_Descendent_Of_Address (Etype (Formal))
3040 Is_Predefined_File_Name
3041 (Unit_File_Name (Get_Source_Unit (N))))
3043 Next_Actual (Actual);
3044 Next_Formal (Formal);
3047 if Debug_Flag_E then
3048 Write_Str (" type checking fails in call ");
3049 Write_Int (Int (N));
3050 Write_Str (" with formal ");
3051 Write_Int (Int (Formal));
3052 Write_Str (" in subprogram ");
3053 Write_Int (Int (Nam));
3057 if Report and not Is_Indexed and not Is_Indirect then
3059 -- Ada 2005 (AI-251): Complete the error notification
3060 -- to help new Ada 2005 users.
3062 if Is_Class_Wide_Type (Etype (Formal))
3063 and then Is_Interface (Etype (Etype (Formal)))
3064 and then not Interface_Present_In_Ancestor
3065 (Typ => Etype (Actual),
3066 Iface => Etype (Etype (Formal)))
3069 ("(Ada 2005) does not implement interface }",
3070 Actual, Etype (Etype (Formal)));
3073 Wrong_Type (Actual, Etype (Formal));
3075 if Nkind (Actual) = N_Op_Eq
3076 and then Nkind (Left_Opnd (Actual)) = N_Identifier
3078 Formal := First_Formal (Nam);
3079 while Present (Formal) loop
3080 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
3081 Error_Msg_N -- CODEFIX
3082 ("possible misspelling of `='>`!", Actual);
3086 Next_Formal (Formal);
3090 if All_Errors_Mode then
3091 Error_Msg_Sloc := Sloc (Nam);
3093 if Etype (Formal) = Any_Type then
3095 ("there is no legal actual parameter", Actual);
3098 if Is_Overloadable (Nam)
3099 and then Present (Alias (Nam))
3100 and then not Comes_From_Source (Nam)
3103 ("\\ =='> in call to inherited operation & #!",
3106 elsif Ekind (Nam) = E_Subprogram_Type then
3108 Access_To_Subprogram_Typ :
3109 constant Entity_Id :=
3111 (Associated_Node_For_Itype (Nam));
3114 "\\ =='> in call to dereference of &#!",
3115 Actual, Access_To_Subprogram_Typ);
3120 ("\\ =='> in call to &#!", Actual, Nam);
3130 -- Normalize_Actuals has verified that a default value exists
3131 -- for this formal. Current actual names a subsequent formal.
3133 Next_Formal (Formal);
3137 -- On exit, all actuals match
3139 Indicate_Name_And_Type;
3141 end Analyze_One_Call;
3143 ---------------------------
3144 -- Analyze_Operator_Call --
3145 ---------------------------
3147 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
3148 Op_Name : constant Name_Id := Chars (Op_Id);
3149 Act1 : constant Node_Id := First_Actual (N);
3150 Act2 : constant Node_Id := Next_Actual (Act1);
3153 -- Binary operator case
3155 if Present (Act2) then
3157 -- If more than two operands, then not binary operator after all
3159 if Present (Next_Actual (Act2)) then
3163 -- Otherwise action depends on operator
3173 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
3178 Find_Boolean_Types (Act1, Act2, Op_Id, N);
3184 Find_Comparison_Types (Act1, Act2, Op_Id, N);
3188 Find_Equality_Types (Act1, Act2, Op_Id, N);
3190 when Name_Op_Concat =>
3191 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
3193 -- Is this when others, or should it be an abort???
3199 -- Unary operator case
3203 when Name_Op_Subtract |
3206 Find_Unary_Types (Act1, Op_Id, N);
3209 Find_Negation_Types (Act1, Op_Id, N);
3211 -- Is this when others correct, or should it be an abort???
3217 end Analyze_Operator_Call;
3219 -------------------------------------------
3220 -- Analyze_Overloaded_Selected_Component --
3221 -------------------------------------------
3223 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
3224 Nam : constant Node_Id := Prefix (N);
3225 Sel : constant Node_Id := Selector_Name (N);
3232 Set_Etype (Sel, Any_Type);
3234 Get_First_Interp (Nam, I, It);
3235 while Present (It.Typ) loop
3236 if Is_Access_Type (It.Typ) then
3237 T := Designated_Type (It.Typ);
3238 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3243 -- Locate the component. For a private prefix the selector can denote
3246 if Is_Record_Type (T) or else Is_Private_Type (T) then
3248 -- If the prefix is a class-wide type, the visible components are
3249 -- those of the base type.
3251 if Is_Class_Wide_Type (T) then
3255 Comp := First_Entity (T);
3256 while Present (Comp) loop
3257 if Chars (Comp) = Chars (Sel)
3258 and then Is_Visible_Component (Comp)
3261 -- AI05-105: if the context is an object renaming with
3262 -- an anonymous access type, the expected type of the
3263 -- object must be anonymous. This is a name resolution rule.
3265 if Nkind (Parent (N)) /= N_Object_Renaming_Declaration
3266 or else No (Access_Definition (Parent (N)))
3267 or else Ekind (Etype (Comp)) = E_Anonymous_Access_Type
3269 Ekind (Etype (Comp)) = E_Anonymous_Access_Subprogram_Type
3271 Set_Entity (Sel, Comp);
3272 Set_Etype (Sel, Etype (Comp));
3273 Add_One_Interp (N, Etype (Comp), Etype (Comp));
3274 Check_Implicit_Dereference (N, Etype (Comp));
3276 -- This also specifies a candidate to resolve the name.
3277 -- Further overloading will be resolved from context.
3278 -- The selector name itself does not carry overloading
3281 Set_Etype (Nam, It.Typ);
3284 -- Named access type in the context of a renaming
3285 -- declaration with an access definition. Remove
3286 -- inapplicable candidate.
3295 elsif Is_Concurrent_Type (T) then
3296 Comp := First_Entity (T);
3297 while Present (Comp)
3298 and then Comp /= First_Private_Entity (T)
3300 if Chars (Comp) = Chars (Sel) then
3301 if Is_Overloadable (Comp) then
3302 Add_One_Interp (Sel, Comp, Etype (Comp));
3304 Set_Entity_With_Style_Check (Sel, Comp);
3305 Generate_Reference (Comp, Sel);
3308 Set_Etype (Sel, Etype (Comp));
3309 Set_Etype (N, Etype (Comp));
3310 Set_Etype (Nam, It.Typ);
3312 -- For access type case, introduce explicit dereference for
3313 -- more uniform treatment of entry calls. Do this only once
3314 -- if several interpretations yield an access type.
3316 if Is_Access_Type (Etype (Nam))
3317 and then Nkind (Nam) /= N_Explicit_Dereference
3319 Insert_Explicit_Dereference (Nam);
3321 (Warn_On_Dereference, "?implicit dereference", N);
3328 Set_Is_Overloaded (N, Is_Overloaded (Sel));
3331 Get_Next_Interp (I, It);
3334 if Etype (N) = Any_Type
3335 and then not Try_Object_Operation (N)
3337 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
3338 Set_Entity (Sel, Any_Id);
3339 Set_Etype (Sel, Any_Type);
3341 end Analyze_Overloaded_Selected_Component;
3343 ----------------------------------
3344 -- Analyze_Qualified_Expression --
3345 ----------------------------------
3347 procedure Analyze_Qualified_Expression (N : Node_Id) is
3348 Mark : constant Entity_Id := Subtype_Mark (N);
3349 Expr : constant Node_Id := Expression (N);
3355 Analyze_Expression (Expr);
3357 Set_Etype (N, Any_Type);
3362 if T = Any_Type then
3366 Check_Fully_Declared (T, N);
3368 -- If expected type is class-wide, check for exact match before
3369 -- expansion, because if the expression is a dispatching call it
3370 -- may be rewritten as explicit dereference with class-wide result.
3371 -- If expression is overloaded, retain only interpretations that
3372 -- will yield exact matches.
3374 if Is_Class_Wide_Type (T) then
3375 if not Is_Overloaded (Expr) then
3376 if Base_Type (Etype (Expr)) /= Base_Type (T) then
3377 if Nkind (Expr) = N_Aggregate then
3378 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
3380 Wrong_Type (Expr, T);
3385 Get_First_Interp (Expr, I, It);
3387 while Present (It.Nam) loop
3388 if Base_Type (It.Typ) /= Base_Type (T) then
3392 Get_Next_Interp (I, It);
3398 end Analyze_Qualified_Expression;
3400 -----------------------------------
3401 -- Analyze_Quantified_Expression --
3402 -----------------------------------
3404 procedure Analyze_Quantified_Expression (N : Node_Id) is
3405 QE_Scop : Entity_Id;
3407 function Is_Empty_Range (Typ : Entity_Id) return Boolean;
3408 -- If the iterator is part of a quantified expression, and the range is
3409 -- known to be statically empty, emit a warning and replace expression
3410 -- with its static value. Returns True if the replacement occurs.
3412 --------------------
3413 -- Is_Empty_Range --
3414 --------------------
3416 function Is_Empty_Range (Typ : Entity_Id) return Boolean is
3417 Loc : constant Source_Ptr := Sloc (N);
3420 if Is_Array_Type (Typ)
3421 and then Compile_Time_Known_Bounds (Typ)
3423 (Expr_Value (Type_Low_Bound (Etype (First_Index (Typ)))) >
3424 Expr_Value (Type_High_Bound (Etype (First_Index (Typ)))))
3426 Preanalyze_And_Resolve (Condition (N), Standard_Boolean);
3428 if All_Present (N) then
3430 ("?quantified expression with ALL "
3431 & "over a null range has value True", N);
3432 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
3436 ("?quantified expression with SOME "
3437 & "over a null range has value False", N);
3438 Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
3449 -- Start of processing for Analyze_Quantified_Expression
3452 Check_SPARK_Restriction ("quantified expression is not allowed", N);
3454 -- Create a scope to emulate the loop-like behavior of the quantified
3455 -- expression. The scope is needed to provide proper visibility of the
3458 QE_Scop := New_Internal_Entity (E_Loop, Current_Scope, Sloc (N), 'L');
3459 Set_Etype (QE_Scop, Standard_Void_Type);
3460 Set_Scope (QE_Scop, Current_Scope);
3461 Set_Parent (QE_Scop, N);
3463 Push_Scope (QE_Scop);
3465 -- All constituents are preanalyzed and resolved to avoid untimely
3466 -- generation of various temporaries and types. Full analysis and
3467 -- expansion is carried out when the quantified expression is
3468 -- transformed into an expression with actions.
3470 if Present (Iterator_Specification (N)) then
3471 Preanalyze (Iterator_Specification (N));
3473 if Is_Entity_Name (Name (Iterator_Specification (N)))
3474 and then Is_Empty_Range (Etype (Name (Iterator_Specification (N))))
3480 Preanalyze (Loop_Parameter_Specification (N));
3483 Preanalyze_And_Resolve (Condition (N), Standard_Boolean);
3487 Set_Etype (N, Standard_Boolean);
3488 end Analyze_Quantified_Expression;
3494 procedure Analyze_Range (N : Node_Id) is
3495 L : constant Node_Id := Low_Bound (N);
3496 H : constant Node_Id := High_Bound (N);
3497 I1, I2 : Interp_Index;
3500 procedure Check_Common_Type (T1, T2 : Entity_Id);
3501 -- Verify the compatibility of two types, and choose the
3502 -- non universal one if the other is universal.
3504 procedure Check_High_Bound (T : Entity_Id);
3505 -- Test one interpretation of the low bound against all those
3506 -- of the high bound.
3508 procedure Check_Universal_Expression (N : Node_Id);
3509 -- In Ada 83, reject bounds of a universal range that are not literals
3512 -----------------------
3513 -- Check_Common_Type --
3514 -----------------------
3516 procedure Check_Common_Type (T1, T2 : Entity_Id) is
3518 if Covers (T1 => T1, T2 => T2)
3520 Covers (T1 => T2, T2 => T1)
3522 if T1 = Universal_Integer
3523 or else T1 = Universal_Real
3524 or else T1 = Any_Character
3526 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
3529 Add_One_Interp (N, T1, T1);
3532 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
3535 end Check_Common_Type;
3537 ----------------------
3538 -- Check_High_Bound --
3539 ----------------------
3541 procedure Check_High_Bound (T : Entity_Id) is
3543 if not Is_Overloaded (H) then
3544 Check_Common_Type (T, Etype (H));
3546 Get_First_Interp (H, I2, It2);
3547 while Present (It2.Typ) loop
3548 Check_Common_Type (T, It2.Typ);
3549 Get_Next_Interp (I2, It2);
3552 end Check_High_Bound;
3554 -----------------------------
3555 -- Is_Universal_Expression --
3556 -----------------------------
3558 procedure Check_Universal_Expression (N : Node_Id) is
3560 if Etype (N) = Universal_Integer
3561 and then Nkind (N) /= N_Integer_Literal
3562 and then not Is_Entity_Name (N)
3563 and then Nkind (N) /= N_Attribute_Reference
3565 Error_Msg_N ("illegal bound in discrete range", N);
3567 end Check_Universal_Expression;
3569 -- Start of processing for Analyze_Range
3572 Set_Etype (N, Any_Type);
3573 Analyze_Expression (L);
3574 Analyze_Expression (H);
3576 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
3580 if not Is_Overloaded (L) then
3581 Check_High_Bound (Etype (L));
3583 Get_First_Interp (L, I1, It1);
3584 while Present (It1.Typ) loop
3585 Check_High_Bound (It1.Typ);
3586 Get_Next_Interp (I1, It1);
3590 -- If result is Any_Type, then we did not find a compatible pair
3592 if Etype (N) = Any_Type then
3593 Error_Msg_N ("incompatible types in range ", N);
3597 if Ada_Version = Ada_83
3599 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
3600 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
3602 Check_Universal_Expression (L);
3603 Check_Universal_Expression (H);
3607 -----------------------
3608 -- Analyze_Reference --
3609 -----------------------
3611 procedure Analyze_Reference (N : Node_Id) is
3612 P : constant Node_Id := Prefix (N);
3615 Acc_Type : Entity_Id;
3620 -- An interesting error check, if we take the 'Reference of an object
3621 -- for which a pragma Atomic or Volatile has been given, and the type
3622 -- of the object is not Atomic or Volatile, then we are in trouble. The
3623 -- problem is that no trace of the atomic/volatile status will remain
3624 -- for the backend to respect when it deals with the resulting pointer,
3625 -- since the pointer type will not be marked atomic (it is a pointer to
3626 -- the base type of the object).
3628 -- It is not clear if that can ever occur, but in case it does, we will
3629 -- generate an error message. Not clear if this message can ever be
3630 -- generated, and pretty clear that it represents a bug if it is, still
3631 -- seems worth checking, except in CodePeer mode where we do not really
3632 -- care and don't want to bother the user.
3636 if Is_Entity_Name (P)
3637 and then Is_Object_Reference (P)
3638 and then not CodePeer_Mode
3643 if (Has_Atomic_Components (E)
3644 and then not Has_Atomic_Components (T))
3646 (Has_Volatile_Components (E)
3647 and then not Has_Volatile_Components (T))
3648 or else (Is_Atomic (E) and then not Is_Atomic (T))
3649 or else (Is_Volatile (E) and then not Is_Volatile (T))
3651 Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
3655 -- Carry on with normal processing
3657 Acc_Type := Create_Itype (E_Allocator_Type, N);
3658 Set_Etype (Acc_Type, Acc_Type);
3659 Set_Directly_Designated_Type (Acc_Type, Etype (P));
3660 Set_Etype (N, Acc_Type);
3661 end Analyze_Reference;
3663 --------------------------------
3664 -- Analyze_Selected_Component --
3665 --------------------------------
3667 -- Prefix is a record type or a task or protected type. In the latter case,
3668 -- the selector must denote a visible entry.
3670 procedure Analyze_Selected_Component (N : Node_Id) is
3671 Name : constant Node_Id := Prefix (N);
3672 Sel : constant Node_Id := Selector_Name (N);
3675 Has_Candidate : Boolean := False;
3678 Pent : Entity_Id := Empty;
3679 Prefix_Type : Entity_Id;
3681 Type_To_Use : Entity_Id;
3682 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
3683 -- a class-wide type, we use its root type, whose components are
3684 -- present in the class-wide type.
3686 Is_Single_Concurrent_Object : Boolean;
3687 -- Set True if the prefix is a single task or a single protected object
3689 procedure Find_Component_In_Instance (Rec : Entity_Id);
3690 -- In an instance, a component of a private extension may not be visible
3691 -- while it was visible in the generic. Search candidate scope for a
3692 -- component with the proper identifier. This is only done if all other
3693 -- searches have failed. When the match is found (it always will be),
3694 -- the Etype of both N and Sel are set from this component, and the
3695 -- entity of Sel is set to reference this component.
3697 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
3698 -- It is known that the parent of N denotes a subprogram call. Comp
3699 -- is an overloadable component of the concurrent type of the prefix.
3700 -- Determine whether all formals of the parent of N and Comp are mode
3701 -- conformant. If the parent node is not analyzed yet it may be an
3702 -- indexed component rather than a function call.
3704 --------------------------------
3705 -- Find_Component_In_Instance --
3706 --------------------------------
3708 procedure Find_Component_In_Instance (Rec : Entity_Id) is
3712 Comp := First_Component (Rec);
3713 while Present (Comp) loop
3714 if Chars (Comp) = Chars (Sel) then
3715 Set_Entity_With_Style_Check (Sel, Comp);
3716 Set_Etype (Sel, Etype (Comp));
3717 Set_Etype (N, Etype (Comp));
3721 Next_Component (Comp);
3724 -- This must succeed because code was legal in the generic
3726 raise Program_Error;
3727 end Find_Component_In_Instance;
3729 ------------------------------
3730 -- Has_Mode_Conformant_Spec --
3731 ------------------------------
3733 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
3734 Comp_Param : Entity_Id;
3736 Param_Typ : Entity_Id;
3739 Comp_Param := First_Formal (Comp);
3741 if Nkind (Parent (N)) = N_Indexed_Component then
3742 Param := First (Expressions (Parent (N)));
3744 Param := First (Parameter_Associations (Parent (N)));
3747 while Present (Comp_Param)
3748 and then Present (Param)
3750 Param_Typ := Find_Parameter_Type (Param);
3752 if Present (Param_Typ)
3754 not Conforming_Types
3755 (Etype (Comp_Param), Param_Typ, Mode_Conformant)
3760 Next_Formal (Comp_Param);
3764 -- One of the specs has additional formals
3766 if Present (Comp_Param) or else Present (Param) then
3771 end Has_Mode_Conformant_Spec;
3773 -- Start of processing for Analyze_Selected_Component
3776 Set_Etype (N, Any_Type);
3778 if Is_Overloaded (Name) then
3779 Analyze_Overloaded_Selected_Component (N);
3782 elsif Etype (Name) = Any_Type then
3783 Set_Entity (Sel, Any_Id);
3784 Set_Etype (Sel, Any_Type);
3788 Prefix_Type := Etype (Name);
3791 if Is_Access_Type (Prefix_Type) then
3793 -- A RACW object can never be used as prefix of a selected component
3794 -- since that means it is dereferenced without being a controlling
3795 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
3796 -- reporting an error, we must check whether this is actually a
3797 -- dispatching call in prefix form.
3799 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
3800 and then Comes_From_Source (N)
3802 if Try_Object_Operation (N) then
3806 ("invalid dereference of a remote access-to-class-wide value",
3810 -- Normal case of selected component applied to access type
3813 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3815 if Is_Entity_Name (Name) then
3816 Pent := Entity (Name);
3817 elsif Nkind (Name) = N_Selected_Component
3818 and then Is_Entity_Name (Selector_Name (Name))
3820 Pent := Entity (Selector_Name (Name));
3823 Prefix_Type := Process_Implicit_Dereference_Prefix (Pent, Name);
3826 -- If we have an explicit dereference of a remote access-to-class-wide
3827 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
3828 -- have to check for the case of a prefix that is a controlling operand
3829 -- of a prefixed dispatching call, as the dereference is legal in that
3830 -- case. Normally this condition is checked in Validate_Remote_Access_
3831 -- To_Class_Wide_Type, but we have to defer the checking for selected
3832 -- component prefixes because of the prefixed dispatching call case.
3833 -- Note that implicit dereferences are checked for this just above.
3835 elsif Nkind (Name) = N_Explicit_Dereference
3836 and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
3837 and then Comes_From_Source (N)
3839 if Try_Object_Operation (N) then
3843 ("invalid dereference of a remote access-to-class-wide value",
3848 -- (Ada 2005): if the prefix is the limited view of a type, and
3849 -- the context already includes the full view, use the full view
3850 -- in what follows, either to retrieve a component of to find
3851 -- a primitive operation. If the prefix is an explicit dereference,
3852 -- set the type of the prefix to reflect this transformation.
3853 -- If the non-limited view is itself an incomplete type, get the
3854 -- full view if available.
3856 if Is_Incomplete_Type (Prefix_Type)
3857 and then From_With_Type (Prefix_Type)
3858 and then Present (Non_Limited_View (Prefix_Type))
3860 Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
3862 if Nkind (N) = N_Explicit_Dereference then
3863 Set_Etype (Prefix (N), Prefix_Type);
3866 elsif Ekind (Prefix_Type) = E_Class_Wide_Type
3867 and then From_With_Type (Prefix_Type)
3868 and then Present (Non_Limited_View (Etype (Prefix_Type)))
3871 Class_Wide_Type (Non_Limited_View (Etype (Prefix_Type)));
3873 if Nkind (N) = N_Explicit_Dereference then
3874 Set_Etype (Prefix (N), Prefix_Type);
3878 if Ekind (Prefix_Type) = E_Private_Subtype then
3879 Prefix_Type := Base_Type (Prefix_Type);
3882 Type_To_Use := Prefix_Type;
3884 -- For class-wide types, use the entity list of the root type. This
3885 -- indirection is specially important for private extensions because
3886 -- only the root type get switched (not the class-wide type).
3888 if Is_Class_Wide_Type (Prefix_Type) then
3889 Type_To_Use := Root_Type (Prefix_Type);
3892 -- If the prefix is a single concurrent object, use its name in error
3893 -- messages, rather than that of its anonymous type.
3895 Is_Single_Concurrent_Object :=
3896 Is_Concurrent_Type (Prefix_Type)
3897 and then Is_Internal_Name (Chars (Prefix_Type))
3898 and then not Is_Derived_Type (Prefix_Type)
3899 and then Is_Entity_Name (Name);
3901 Comp := First_Entity (Type_To_Use);
3903 -- If the selector has an original discriminant, the node appears in
3904 -- an instance. Replace the discriminant with the corresponding one
3905 -- in the current discriminated type. For nested generics, this must
3906 -- be done transitively, so note the new original discriminant.
3908 if Nkind (Sel) = N_Identifier
3909 and then In_Instance
3910 and then Present (Original_Discriminant (Sel))
3912 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
3914 -- Mark entity before rewriting, for completeness and because
3915 -- subsequent semantic checks might examine the original node.
3917 Set_Entity (Sel, Comp);
3918 Rewrite (Selector_Name (N), New_Occurrence_Of (Comp, Sloc (N)));
3919 Set_Original_Discriminant (Selector_Name (N), Comp);
3920 Set_Etype (N, Etype (Comp));
3921 Check_Implicit_Dereference (N, Etype (Comp));
3923 if Is_Access_Type (Etype (Name)) then
3924 Insert_Explicit_Dereference (Name);
3925 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3928 elsif Is_Record_Type (Prefix_Type) then
3930 -- Find component with given name. In an instance, if the node is
3931 -- known as a prefixed call, do not examine components whose
3932 -- visibility may be accidental.
3934 while Present (Comp) and then not Is_Prefixed_Call (N) loop
3935 if Chars (Comp) = Chars (Sel)
3936 and then Is_Visible_Component (Comp, N)
3938 Set_Entity_With_Style_Check (Sel, Comp);
3939 Set_Etype (Sel, Etype (Comp));
3941 if Ekind (Comp) = E_Discriminant then
3942 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
3944 ("cannot reference discriminant of unchecked union",
3948 if Is_Generic_Type (Prefix_Type)
3950 Is_Generic_Type (Root_Type (Prefix_Type))
3952 Set_Original_Discriminant (Sel, Comp);
3956 -- Resolve the prefix early otherwise it is not possible to
3957 -- build the actual subtype of the component: it may need
3958 -- to duplicate this prefix and duplication is only allowed
3959 -- on fully resolved expressions.
3963 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
3964 -- subtypes in a package specification.
3967 -- limited with Pkg;
3969 -- type Acc_Inc is access Pkg.T;
3971 -- N : Natural := X.all.Comp; -- ERROR, limited view
3972 -- end Pkg; -- Comp is not visible
3974 if Nkind (Name) = N_Explicit_Dereference
3975 and then From_With_Type (Etype (Prefix (Name)))
3976 and then not Is_Potentially_Use_Visible (Etype (Name))
3977 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
3978 N_Package_Specification
3981 ("premature usage of incomplete}", Prefix (Name),
3982 Etype (Prefix (Name)));
3985 -- We never need an actual subtype for the case of a selection
3986 -- for a indexed component of a non-packed array, since in
3987 -- this case gigi generates all the checks and can find the
3988 -- necessary bounds information.
3990 -- We also do not need an actual subtype for the case of a
3991 -- first, last, length, or range attribute applied to a
3992 -- non-packed array, since gigi can again get the bounds in
3993 -- these cases (gigi cannot handle the packed case, since it
3994 -- has the bounds of the packed array type, not the original
3995 -- bounds of the type). However, if the prefix is itself a
3996 -- selected component, as in a.b.c (i), gigi may regard a.b.c
3997 -- as a dynamic-sized temporary, so we do generate an actual
3998 -- subtype for this case.
4000 Parent_N := Parent (N);
4002 if not Is_Packed (Etype (Comp))
4004 ((Nkind (Parent_N) = N_Indexed_Component
4005 and then Nkind (Name) /= N_Selected_Component)
4007 (Nkind (Parent_N) = N_Attribute_Reference
4008 and then (Attribute_Name (Parent_N) = Name_First
4010 Attribute_Name (Parent_N) = Name_Last
4012 Attribute_Name (Parent_N) = Name_Length
4014 Attribute_Name (Parent_N) = Name_Range)))
4016 Set_Etype (N, Etype (Comp));
4018 -- If full analysis is not enabled, we do not generate an
4019 -- actual subtype, because in the absence of expansion
4020 -- reference to a formal of a protected type, for example,
4021 -- will not be properly transformed, and will lead to
4022 -- out-of-scope references in gigi.
4024 -- In all other cases, we currently build an actual subtype.
4025 -- It seems likely that many of these cases can be avoided,
4026 -- but right now, the front end makes direct references to the
4027 -- bounds (e.g. in generating a length check), and if we do
4028 -- not make an actual subtype, we end up getting a direct
4029 -- reference to a discriminant, which will not do.
4031 elsif Full_Analysis then
4033 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
4034 Insert_Action (N, Act_Decl);
4036 if No (Act_Decl) then
4037 Set_Etype (N, Etype (Comp));
4040 -- Component type depends on discriminants. Enter the
4041 -- main attributes of the subtype.
4044 Subt : constant Entity_Id :=
4045 Defining_Identifier (Act_Decl);
4048 Set_Etype (Subt, Base_Type (Etype (Comp)));
4049 Set_Ekind (Subt, Ekind (Etype (Comp)));
4050 Set_Etype (N, Subt);
4054 -- If Full_Analysis not enabled, just set the Etype
4057 Set_Etype (N, Etype (Comp));
4060 Check_Implicit_Dereference (N, Etype (N));
4064 -- If the prefix is a private extension, check only the visible
4065 -- components of the partial view. This must include the tag,
4066 -- which can appear in expanded code in a tag check.
4068 if Ekind (Type_To_Use) = E_Record_Type_With_Private
4069 and then Chars (Selector_Name (N)) /= Name_uTag
4071 exit when Comp = Last_Entity (Type_To_Use);
4077 -- Ada 2005 (AI-252): The selected component can be interpreted as
4078 -- a prefixed view of a subprogram. Depending on the context, this is
4079 -- either a name that can appear in a renaming declaration, or part
4080 -- of an enclosing call given in prefix form.
4082 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
4083 -- selected component should resolve to a name.
4085 if Ada_Version >= Ada_2005
4086 and then Is_Tagged_Type (Prefix_Type)
4087 and then not Is_Concurrent_Type (Prefix_Type)
4089 if Nkind (Parent (N)) = N_Generic_Association
4090 or else Nkind (Parent (N)) = N_Requeue_Statement
4091 or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
4093 if Find_Primitive_Operation (N) then
4097 elsif Try_Object_Operation (N) then
4101 -- If the transformation fails, it will be necessary to redo the
4102 -- analysis with all errors enabled, to indicate candidate
4103 -- interpretations and reasons for each failure ???
4107 elsif Is_Private_Type (Prefix_Type) then
4109 -- Allow access only to discriminants of the type. If the type has
4110 -- no full view, gigi uses the parent type for the components, so we
4111 -- do the same here.
4113 if No (Full_View (Prefix_Type)) then
4114 Type_To_Use := Root_Type (Base_Type (Prefix_Type));
4115 Comp := First_Entity (Type_To_Use);
4118 while Present (Comp) loop
4119 if Chars (Comp) = Chars (Sel) then
4120 if Ekind (Comp) = E_Discriminant then
4121 Set_Entity_With_Style_Check (Sel, Comp);
4122 Generate_Reference (Comp, Sel);
4124 Set_Etype (Sel, Etype (Comp));
4125 Set_Etype (N, Etype (Comp));
4126 Check_Implicit_Dereference (N, Etype (N));
4128 if Is_Generic_Type (Prefix_Type)
4129 or else Is_Generic_Type (Root_Type (Prefix_Type))
4131 Set_Original_Discriminant (Sel, Comp);
4134 -- Before declaring an error, check whether this is tagged
4135 -- private type and a call to a primitive operation.
4137 elsif Ada_Version >= Ada_2005
4138 and then Is_Tagged_Type (Prefix_Type)
4139 and then Try_Object_Operation (N)
4144 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4145 Error_Msg_NE ("invisible selector& for }", N, Sel);
4146 Set_Entity (Sel, Any_Id);
4147 Set_Etype (N, Any_Type);
4156 elsif Is_Concurrent_Type (Prefix_Type) then
4158 -- Find visible operation with given name. For a protected type,
4159 -- the possible candidates are discriminants, entries or protected
4160 -- procedures. For a task type, the set can only include entries or
4161 -- discriminants if the task type is not an enclosing scope. If it
4162 -- is an enclosing scope (e.g. in an inner task) then all entities
4163 -- are visible, but the prefix must denote the enclosing scope, i.e.
4164 -- can only be a direct name or an expanded name.
4166 Set_Etype (Sel, Any_Type);
4167 In_Scope := In_Open_Scopes (Prefix_Type);
4169 while Present (Comp) loop
4170 if Chars (Comp) = Chars (Sel) then
4171 if Is_Overloadable (Comp) then
4172 Add_One_Interp (Sel, Comp, Etype (Comp));
4174 -- If the prefix is tagged, the correct interpretation may
4175 -- lie in the primitive or class-wide operations of the
4176 -- type. Perform a simple conformance check to determine
4177 -- whether Try_Object_Operation should be invoked even if
4178 -- a visible entity is found.
4180 if Is_Tagged_Type (Prefix_Type)
4182 Nkind_In (Parent (N), N_Procedure_Call_Statement,
4184 N_Indexed_Component)
4185 and then Has_Mode_Conformant_Spec (Comp)
4187 Has_Candidate := True;
4190 -- Note: a selected component may not denote a component of a
4191 -- protected type (4.1.3(7)).
4193 elsif Ekind_In (Comp, E_Discriminant, E_Entry_Family)
4195 and then not Is_Protected_Type (Prefix_Type)
4196 and then Is_Entity_Name (Name))
4198 Set_Entity_With_Style_Check (Sel, Comp);
4199 Generate_Reference (Comp, Sel);
4201 -- The selector is not overloadable, so we have a candidate
4204 Has_Candidate := True;
4210 Set_Etype (Sel, Etype (Comp));
4211 Set_Etype (N, Etype (Comp));
4213 if Ekind (Comp) = E_Discriminant then
4214 Set_Original_Discriminant (Sel, Comp);
4217 -- For access type case, introduce explicit dereference for
4218 -- more uniform treatment of entry calls.
4220 if Is_Access_Type (Etype (Name)) then
4221 Insert_Explicit_Dereference (Name);
4223 (Warn_On_Dereference, "?implicit dereference", N);
4229 exit when not In_Scope
4231 Comp = First_Private_Entity (Base_Type (Prefix_Type));
4234 -- If there is no visible entity with the given name or none of the
4235 -- visible entities are plausible interpretations, check whether
4236 -- there is some other primitive operation with that name.
4238 if Ada_Version >= Ada_2005
4239 and then Is_Tagged_Type (Prefix_Type)
4241 if (Etype (N) = Any_Type
4242 or else not Has_Candidate)
4243 and then Try_Object_Operation (N)
4247 -- If the context is not syntactically a procedure call, it
4248 -- may be a call to a primitive function declared outside of
4249 -- the synchronized type.
4251 -- If the context is a procedure call, there might still be
4252 -- an overloading between an entry and a primitive procedure
4253 -- declared outside of the synchronized type, called in prefix
4254 -- notation. This is harder to disambiguate because in one case
4255 -- the controlling formal is implicit ???
4257 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
4258 and then Nkind (Parent (N)) /= N_Indexed_Component
4259 and then Try_Object_Operation (N)
4264 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
4265 -- entry or procedure of a tagged concurrent type we must check
4266 -- if there are class-wide subprograms covering the primitive. If
4267 -- true then Try_Object_Operation reports the error.
4270 and then Is_Concurrent_Type (Prefix_Type)
4271 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
4273 -- Duplicate the call. This is required to avoid problems with
4274 -- the tree transformations performed by Try_Object_Operation.
4275 -- Set properly the parent of the copied call, because it is
4276 -- about to be reanalyzed.
4280 Par : constant Node_Id := New_Copy_Tree (Parent (N));
4283 Set_Parent (Par, Parent (Parent (N)));
4285 if Try_Object_Operation
4286 (Sinfo.Name (Par), CW_Test_Only => True)
4294 if Etype (N) = Any_Type and then Is_Protected_Type (Prefix_Type) then
4296 -- Case of a prefix of a protected type: selector might denote
4297 -- an invisible private component.
4299 Comp := First_Private_Entity (Base_Type (Prefix_Type));
4300 while Present (Comp) and then Chars (Comp) /= Chars (Sel) loop
4304 if Present (Comp) then
4305 if Is_Single_Concurrent_Object then
4306 Error_Msg_Node_2 := Entity (Name);
4307 Error_Msg_NE ("invisible selector& for &", N, Sel);
4310 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4311 Error_Msg_NE ("invisible selector& for }", N, Sel);
4317 Set_Is_Overloaded (N, Is_Overloaded (Sel));
4322 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
4325 -- If N still has no type, the component is not defined in the prefix
4327 if Etype (N) = Any_Type then
4329 if Is_Single_Concurrent_Object then
4330 Error_Msg_Node_2 := Entity (Name);
4331 Error_Msg_NE ("no selector& for&", N, Sel);
4333 Check_Misspelled_Selector (Type_To_Use, Sel);
4335 elsif Is_Generic_Type (Prefix_Type)
4336 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
4337 and then Prefix_Type /= Etype (Prefix_Type)
4338 and then Is_Record_Type (Etype (Prefix_Type))
4340 -- If this is a derived formal type, the parent may have
4341 -- different visibility at this point. Try for an inherited
4342 -- component before reporting an error.
4344 Set_Etype (Prefix (N), Etype (Prefix_Type));
4345 Analyze_Selected_Component (N);
4348 -- Similarly, if this is the actual for a formal derived type, the
4349 -- component inherited from the generic parent may not be visible
4350 -- in the actual, but the selected component is legal.
4352 elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
4353 and then Is_Generic_Actual_Type (Prefix_Type)
4354 and then Present (Full_View (Prefix_Type))
4357 Find_Component_In_Instance
4358 (Generic_Parent_Type (Parent (Prefix_Type)));
4361 -- Finally, the formal and the actual may be private extensions,
4362 -- but the generic is declared in a child unit of the parent, and
4363 -- an additional step is needed to retrieve the proper scope.
4366 and then Present (Parent_Subtype (Etype (Base_Type (Prefix_Type))))
4368 Find_Component_In_Instance
4369 (Parent_Subtype (Etype (Base_Type (Prefix_Type))));
4372 -- Component not found, specialize error message when appropriate
4375 if Ekind (Prefix_Type) = E_Record_Subtype then
4377 -- Check whether this is a component of the base type which
4378 -- is absent from a statically constrained subtype. This will
4379 -- raise constraint error at run time, but is not a compile-
4380 -- time error. When the selector is illegal for base type as
4381 -- well fall through and generate a compilation error anyway.
4383 Comp := First_Component (Base_Type (Prefix_Type));
4384 while Present (Comp) loop
4385 if Chars (Comp) = Chars (Sel)
4386 and then Is_Visible_Component (Comp)
4388 Set_Entity_With_Style_Check (Sel, Comp);
4389 Generate_Reference (Comp, Sel);
4390 Set_Etype (Sel, Etype (Comp));
4391 Set_Etype (N, Etype (Comp));
4393 -- Emit appropriate message. Gigi will replace the
4394 -- node subsequently with the appropriate Raise.
4396 -- In Alfa mode, this is made into an error to simplify
4397 -- the processing of the formal verification backend.
4400 Apply_Compile_Time_Constraint_Error
4401 (N, "component not present in }",
4402 CE_Discriminant_Check_Failed,
4403 Ent => Prefix_Type, Rep => False);
4405 Apply_Compile_Time_Constraint_Error
4406 (N, "component not present in }?",
4407 CE_Discriminant_Check_Failed,
4408 Ent => Prefix_Type, Rep => False);
4411 Set_Raises_Constraint_Error (N);
4415 Next_Component (Comp);
4420 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4421 Error_Msg_NE ("no selector& for}", N, Sel);
4423 -- Add information in the case of an incomplete prefix
4425 if Is_Incomplete_Type (Type_To_Use) then
4427 Inc : constant Entity_Id := First_Subtype (Type_To_Use);
4430 if From_With_Type (Scope (Type_To_Use)) then
4432 ("\limited view of& has no components", N, Inc);
4436 ("\premature usage of incomplete type&", N, Inc);
4438 if Nkind (Parent (Inc)) =
4439 N_Incomplete_Type_Declaration
4441 -- Record location of premature use in entity so that
4442 -- a continuation message is generated when the
4443 -- completion is seen.
4445 Set_Premature_Use (Parent (Inc), N);
4451 Check_Misspelled_Selector (Type_To_Use, Sel);
4454 Set_Entity (Sel, Any_Id);
4455 Set_Etype (Sel, Any_Type);
4457 end Analyze_Selected_Component;
4459 ---------------------------
4460 -- Analyze_Short_Circuit --
4461 ---------------------------
4463 procedure Analyze_Short_Circuit (N : Node_Id) is
4464 L : constant Node_Id := Left_Opnd (N);
4465 R : constant Node_Id := Right_Opnd (N);
4470 Analyze_Expression (L);
4471 Analyze_Expression (R);
4472 Set_Etype (N, Any_Type);
4474 if not Is_Overloaded (L) then
4475 if Root_Type (Etype (L)) = Standard_Boolean
4476 and then Has_Compatible_Type (R, Etype (L))
4478 Add_One_Interp (N, Etype (L), Etype (L));
4482 Get_First_Interp (L, Ind, It);
4483 while Present (It.Typ) loop
4484 if Root_Type (It.Typ) = Standard_Boolean
4485 and then Has_Compatible_Type (R, It.Typ)
4487 Add_One_Interp (N, It.Typ, It.Typ);
4490 Get_Next_Interp (Ind, It);
4494 -- Here we have failed to find an interpretation. Clearly we know that
4495 -- it is not the case that both operands can have an interpretation of
4496 -- Boolean, but this is by far the most likely intended interpretation.
4497 -- So we simply resolve both operands as Booleans, and at least one of
4498 -- these resolutions will generate an error message, and we do not need
4499 -- to give another error message on the short circuit operation itself.
4501 if Etype (N) = Any_Type then
4502 Resolve (L, Standard_Boolean);
4503 Resolve (R, Standard_Boolean);
4504 Set_Etype (N, Standard_Boolean);
4506 end Analyze_Short_Circuit;
4512 procedure Analyze_Slice (N : Node_Id) is
4513 D : constant Node_Id := Discrete_Range (N);
4514 P : constant Node_Id := Prefix (N);
4515 Array_Type : Entity_Id;
4516 Index_Type : Entity_Id;
4518 procedure Analyze_Overloaded_Slice;
4519 -- If the prefix is overloaded, select those interpretations that
4520 -- yield a one-dimensional array type.
4522 ------------------------------
4523 -- Analyze_Overloaded_Slice --
4524 ------------------------------
4526 procedure Analyze_Overloaded_Slice is
4532 Set_Etype (N, Any_Type);
4534 Get_First_Interp (P, I, It);
4535 while Present (It.Nam) loop
4538 if Is_Access_Type (Typ) then
4539 Typ := Designated_Type (Typ);
4540 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
4543 if Is_Array_Type (Typ)
4544 and then Number_Dimensions (Typ) = 1
4545 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
4547 Add_One_Interp (N, Typ, Typ);
4550 Get_Next_Interp (I, It);
4553 if Etype (N) = Any_Type then
4554 Error_Msg_N ("expect array type in prefix of slice", N);
4556 end Analyze_Overloaded_Slice;
4558 -- Start of processing for Analyze_Slice
4561 if Comes_From_Source (N) then
4562 Check_SPARK_Restriction ("slice is not allowed", N);
4568 if Is_Overloaded (P) then
4569 Analyze_Overloaded_Slice;
4572 Array_Type := Etype (P);
4573 Set_Etype (N, Any_Type);
4575 if Is_Access_Type (Array_Type) then
4576 Array_Type := Designated_Type (Array_Type);
4577 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
4580 if not Is_Array_Type (Array_Type) then
4581 Wrong_Type (P, Any_Array);
4583 elsif Number_Dimensions (Array_Type) > 1 then
4585 ("type is not one-dimensional array in slice prefix", N);
4588 if Ekind (Array_Type) = E_String_Literal_Subtype then
4589 Index_Type := Etype (String_Literal_Low_Bound (Array_Type));
4591 Index_Type := Etype (First_Index (Array_Type));
4594 if not Has_Compatible_Type (D, Index_Type) then
4595 Wrong_Type (D, Index_Type);
4597 Set_Etype (N, Array_Type);
4603 -----------------------------
4604 -- Analyze_Type_Conversion --
4605 -----------------------------
4607 procedure Analyze_Type_Conversion (N : Node_Id) is
4608 Expr : constant Node_Id := Expression (N);
4612 -- If Conversion_OK is set, then the Etype is already set, and the
4613 -- only processing required is to analyze the expression. This is
4614 -- used to construct certain "illegal" conversions which are not
4615 -- allowed by Ada semantics, but can be handled OK by Gigi, see
4616 -- Sinfo for further details.
4618 if Conversion_OK (N) then
4623 -- Otherwise full type analysis is required, as well as some semantic
4624 -- checks to make sure the argument of the conversion is appropriate.
4626 Find_Type (Subtype_Mark (N));
4627 T := Entity (Subtype_Mark (N));
4629 Check_Fully_Declared (T, N);
4630 Analyze_Expression (Expr);
4631 Validate_Remote_Type_Type_Conversion (N);
4633 -- Only remaining step is validity checks on the argument. These
4634 -- are skipped if the conversion does not come from the source.
4636 if not Comes_From_Source (N) then
4639 -- If there was an error in a generic unit, no need to replicate the
4640 -- error message. Conversely, constant-folding in the generic may
4641 -- transform the argument of a conversion into a string literal, which
4642 -- is legal. Therefore the following tests are not performed in an
4645 elsif In_Instance then
4648 elsif Nkind (Expr) = N_Null then
4649 Error_Msg_N ("argument of conversion cannot be null", N);
4650 Error_Msg_N ("\use qualified expression instead", N);
4651 Set_Etype (N, Any_Type);
4653 elsif Nkind (Expr) = N_Aggregate then
4654 Error_Msg_N ("argument of conversion cannot be aggregate", N);
4655 Error_Msg_N ("\use qualified expression instead", N);
4657 elsif Nkind (Expr) = N_Allocator then
4658 Error_Msg_N ("argument of conversion cannot be an allocator", N);
4659 Error_Msg_N ("\use qualified expression instead", N);
4661 elsif Nkind (Expr) = N_String_Literal then
4662 Error_Msg_N ("argument of conversion cannot be string literal", N);
4663 Error_Msg_N ("\use qualified expression instead", N);
4665 elsif Nkind (Expr) = N_Character_Literal then
4666 if Ada_Version = Ada_83 then
4669 Error_Msg_N ("argument of conversion cannot be character literal",
4671 Error_Msg_N ("\use qualified expression instead", N);
4674 elsif Nkind (Expr) = N_Attribute_Reference
4676 (Attribute_Name (Expr) = Name_Access or else
4677 Attribute_Name (Expr) = Name_Unchecked_Access or else
4678 Attribute_Name (Expr) = Name_Unrestricted_Access)
4680 Error_Msg_N ("argument of conversion cannot be access", N);
4681 Error_Msg_N ("\use qualified expression instead", N);
4683 end Analyze_Type_Conversion;
4685 ----------------------
4686 -- Analyze_Unary_Op --
4687 ----------------------
4689 procedure Analyze_Unary_Op (N : Node_Id) is
4690 R : constant Node_Id := Right_Opnd (N);
4691 Op_Id : Entity_Id := Entity (N);
4694 Set_Etype (N, Any_Type);
4695 Candidate_Type := Empty;
4697 Analyze_Expression (R);
4699 if Present (Op_Id) then
4700 if Ekind (Op_Id) = E_Operator then
4701 Find_Unary_Types (R, Op_Id, N);
4703 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4707 Op_Id := Get_Name_Entity_Id (Chars (N));
4708 while Present (Op_Id) loop
4709 if Ekind (Op_Id) = E_Operator then
4710 if No (Next_Entity (First_Entity (Op_Id))) then
4711 Find_Unary_Types (R, Op_Id, N);
4714 elsif Is_Overloadable (Op_Id) then
4715 Analyze_User_Defined_Unary_Op (N, Op_Id);
4718 Op_Id := Homonym (Op_Id);
4723 end Analyze_Unary_Op;
4725 ----------------------------------
4726 -- Analyze_Unchecked_Expression --
4727 ----------------------------------
4729 procedure Analyze_Unchecked_Expression (N : Node_Id) is
4731 Analyze (Expression (N), Suppress => All_Checks);
4732 Set_Etype (N, Etype (Expression (N)));
4733 Save_Interps (Expression (N), N);
4734 end Analyze_Unchecked_Expression;
4736 ---------------------------------------
4737 -- Analyze_Unchecked_Type_Conversion --
4738 ---------------------------------------
4740 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
4742 Find_Type (Subtype_Mark (N));
4743 Analyze_Expression (Expression (N));
4744 Set_Etype (N, Entity (Subtype_Mark (N)));
4745 end Analyze_Unchecked_Type_Conversion;
4747 ------------------------------------
4748 -- Analyze_User_Defined_Binary_Op --
4749 ------------------------------------
4751 procedure Analyze_User_Defined_Binary_Op
4756 -- Only do analysis if the operator Comes_From_Source, since otherwise
4757 -- the operator was generated by the expander, and all such operators
4758 -- always refer to the operators in package Standard.
4760 if Comes_From_Source (N) then
4762 F1 : constant Entity_Id := First_Formal (Op_Id);
4763 F2 : constant Entity_Id := Next_Formal (F1);
4766 -- Verify that Op_Id is a visible binary function. Note that since
4767 -- we know Op_Id is overloaded, potentially use visible means use
4768 -- visible for sure (RM 9.4(11)).
4770 if Ekind (Op_Id) = E_Function
4771 and then Present (F2)
4772 and then (Is_Immediately_Visible (Op_Id)
4773 or else Is_Potentially_Use_Visible (Op_Id))
4774 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
4775 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
4777 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4779 -- If the left operand is overloaded, indicate that the
4780 -- current type is a viable candidate. This is redundant
4781 -- in most cases, but for equality and comparison operators
4782 -- where the context does not impose a type on the operands,
4783 -- setting the proper type is necessary to avoid subsequent
4784 -- ambiguities during resolution, when both user-defined and
4785 -- predefined operators may be candidates.
4787 if Is_Overloaded (Left_Opnd (N)) then
4788 Set_Etype (Left_Opnd (N), Etype (F1));
4791 if Debug_Flag_E then
4792 Write_Str ("user defined operator ");
4793 Write_Name (Chars (Op_Id));
4794 Write_Str (" on node ");
4795 Write_Int (Int (N));
4801 end Analyze_User_Defined_Binary_Op;
4803 -----------------------------------
4804 -- Analyze_User_Defined_Unary_Op --
4805 -----------------------------------
4807 procedure Analyze_User_Defined_Unary_Op
4812 -- Only do analysis if the operator Comes_From_Source, since otherwise
4813 -- the operator was generated by the expander, and all such operators
4814 -- always refer to the operators in package Standard.
4816 if Comes_From_Source (N) then
4818 F : constant Entity_Id := First_Formal (Op_Id);
4821 -- Verify that Op_Id is a visible unary function. Note that since
4822 -- we know Op_Id is overloaded, potentially use visible means use
4823 -- visible for sure (RM 9.4(11)).
4825 if Ekind (Op_Id) = E_Function
4826 and then No (Next_Formal (F))
4827 and then (Is_Immediately_Visible (Op_Id)
4828 or else Is_Potentially_Use_Visible (Op_Id))
4829 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
4831 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4835 end Analyze_User_Defined_Unary_Op;
4837 ---------------------------
4838 -- Check_Arithmetic_Pair --
4839 ---------------------------
4841 procedure Check_Arithmetic_Pair
4842 (T1, T2 : Entity_Id;
4846 Op_Name : constant Name_Id := Chars (Op_Id);
4848 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
4849 -- Check whether the fixed-point type Typ has a user-defined operator
4850 -- (multiplication or division) that should hide the corresponding
4851 -- predefined operator. Used to implement Ada 2005 AI-264, to make
4852 -- such operators more visible and therefore useful.
4854 -- If the name of the operation is an expanded name with prefix
4855 -- Standard, the predefined universal fixed operator is available,
4856 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
4858 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
4859 -- Get specific type (i.e. non-universal type if there is one)
4865 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
4866 Bas : constant Entity_Id := Base_Type (Typ);
4872 -- If the universal_fixed operation is given explicitly the rule
4873 -- concerning primitive operations of the type do not apply.
4875 if Nkind (N) = N_Function_Call
4876 and then Nkind (Name (N)) = N_Expanded_Name
4877 and then Entity (Prefix (Name (N))) = Standard_Standard
4882 -- The operation is treated as primitive if it is declared in the
4883 -- same scope as the type, and therefore on the same entity chain.
4885 Ent := Next_Entity (Typ);
4886 while Present (Ent) loop
4887 if Chars (Ent) = Chars (Op) then
4888 F1 := First_Formal (Ent);
4889 F2 := Next_Formal (F1);
4891 -- The operation counts as primitive if either operand or
4892 -- result are of the given base type, and both operands are
4893 -- fixed point types.
4895 if (Base_Type (Etype (F1)) = Bas
4896 and then Is_Fixed_Point_Type (Etype (F2)))
4899 (Base_Type (Etype (F2)) = Bas
4900 and then Is_Fixed_Point_Type (Etype (F1)))
4903 (Base_Type (Etype (Ent)) = Bas
4904 and then Is_Fixed_Point_Type (Etype (F1))
4905 and then Is_Fixed_Point_Type (Etype (F2)))
4921 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
4923 if T1 = Universal_Integer or else T1 = Universal_Real then
4924 return Base_Type (T2);
4926 return Base_Type (T1);
4930 -- Start of processing for Check_Arithmetic_Pair
4933 if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
4935 if Is_Numeric_Type (T1)
4936 and then Is_Numeric_Type (T2)
4937 and then (Covers (T1 => T1, T2 => T2)
4939 Covers (T1 => T2, T2 => T1))
4941 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4944 elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
4946 if Is_Fixed_Point_Type (T1)
4947 and then (Is_Fixed_Point_Type (T2)
4948 or else T2 = Universal_Real)
4950 -- If Treat_Fixed_As_Integer is set then the Etype is already set
4951 -- and no further processing is required (this is the case of an
4952 -- operator constructed by Exp_Fixd for a fixed point operation)
4953 -- Otherwise add one interpretation with universal fixed result
4954 -- If the operator is given in functional notation, it comes
4955 -- from source and Fixed_As_Integer cannot apply.
4957 if (Nkind (N) not in N_Op
4958 or else not Treat_Fixed_As_Integer (N))
4960 (not Has_Fixed_Op (T1, Op_Id)
4961 or else Nkind (Parent (N)) = N_Type_Conversion)
4963 Add_One_Interp (N, Op_Id, Universal_Fixed);
4966 elsif Is_Fixed_Point_Type (T2)
4967 and then (Nkind (N) not in N_Op
4968 or else not Treat_Fixed_As_Integer (N))
4969 and then T1 = Universal_Real
4971 (not Has_Fixed_Op (T1, Op_Id)
4972 or else Nkind (Parent (N)) = N_Type_Conversion)
4974 Add_One_Interp (N, Op_Id, Universal_Fixed);
4976 elsif Is_Numeric_Type (T1)
4977 and then Is_Numeric_Type (T2)
4978 and then (Covers (T1 => T1, T2 => T2)
4980 Covers (T1 => T2, T2 => T1))
4982 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4984 elsif Is_Fixed_Point_Type (T1)
4985 and then (Base_Type (T2) = Base_Type (Standard_Integer)
4986 or else T2 = Universal_Integer)
4988 Add_One_Interp (N, Op_Id, T1);
4990 elsif T2 = Universal_Real
4991 and then Base_Type (T1) = Base_Type (Standard_Integer)
4992 and then Op_Name = Name_Op_Multiply
4994 Add_One_Interp (N, Op_Id, Any_Fixed);
4996 elsif T1 = Universal_Real
4997 and then Base_Type (T2) = Base_Type (Standard_Integer)
4999 Add_One_Interp (N, Op_Id, Any_Fixed);
5001 elsif Is_Fixed_Point_Type (T2)
5002 and then (Base_Type (T1) = Base_Type (Standard_Integer)
5003 or else T1 = Universal_Integer)
5004 and then Op_Name = Name_Op_Multiply
5006 Add_One_Interp (N, Op_Id, T2);
5008 elsif T1 = Universal_Real and then T2 = Universal_Integer then
5009 Add_One_Interp (N, Op_Id, T1);
5011 elsif T2 = Universal_Real
5012 and then T1 = Universal_Integer
5013 and then Op_Name = Name_Op_Multiply
5015 Add_One_Interp (N, Op_Id, T2);
5018 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
5020 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
5021 -- set does not require any special processing, since the Etype is
5022 -- already set (case of operation constructed by Exp_Fixed).
5024 if Is_Integer_Type (T1)
5025 and then (Covers (T1 => T1, T2 => T2)
5027 Covers (T1 => T2, T2 => T1))
5029 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5032 elsif Op_Name = Name_Op_Expon then
5033 if Is_Numeric_Type (T1)
5034 and then not Is_Fixed_Point_Type (T1)
5035 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5036 or else T2 = Universal_Integer)
5038 Add_One_Interp (N, Op_Id, Base_Type (T1));
5041 else pragma Assert (Nkind (N) in N_Op_Shift);
5043 -- If not one of the predefined operators, the node may be one
5044 -- of the intrinsic functions. Its kind is always specific, and
5045 -- we can use it directly, rather than the name of the operation.
5047 if Is_Integer_Type (T1)
5048 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5049 or else T2 = Universal_Integer)
5051 Add_One_Interp (N, Op_Id, Base_Type (T1));
5054 end Check_Arithmetic_Pair;
5056 -------------------------------
5057 -- Check_Misspelled_Selector --
5058 -------------------------------
5060 procedure Check_Misspelled_Selector
5061 (Prefix : Entity_Id;
5064 Max_Suggestions : constant := 2;
5065 Nr_Of_Suggestions : Natural := 0;
5067 Suggestion_1 : Entity_Id := Empty;
5068 Suggestion_2 : Entity_Id := Empty;
5073 -- All the components of the prefix of selector Sel are matched
5074 -- against Sel and a count is maintained of possible misspellings.
5075 -- When at the end of the analysis there are one or two (not more!)
5076 -- possible misspellings, these misspellings will be suggested as
5077 -- possible correction.
5079 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
5081 -- Concurrent types should be handled as well ???
5086 Comp := First_Entity (Prefix);
5087 while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
5088 if Is_Visible_Component (Comp) then
5089 if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
5090 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
5092 case Nr_Of_Suggestions is
5093 when 1 => Suggestion_1 := Comp;
5094 when 2 => Suggestion_2 := Comp;
5095 when others => exit;
5100 Comp := Next_Entity (Comp);
5103 -- Report at most two suggestions
5105 if Nr_Of_Suggestions = 1 then
5106 Error_Msg_NE -- CODEFIX
5107 ("\possible misspelling of&", Sel, Suggestion_1);
5109 elsif Nr_Of_Suggestions = 2 then
5110 Error_Msg_Node_2 := Suggestion_2;
5111 Error_Msg_NE -- CODEFIX
5112 ("\possible misspelling of& or&", Sel, Suggestion_1);
5114 end Check_Misspelled_Selector;
5116 ----------------------
5117 -- Defined_In_Scope --
5118 ----------------------
5120 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
5122 S1 : constant Entity_Id := Scope (Base_Type (T));
5125 or else (S1 = System_Aux_Id and then S = Scope (S1));
5126 end Defined_In_Scope;
5132 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
5138 Void_Interp_Seen : Boolean := False;
5141 pragma Warnings (Off, Boolean);
5144 if Ada_Version >= Ada_2005 then
5145 Actual := First_Actual (N);
5146 while Present (Actual) loop
5148 -- Ada 2005 (AI-50217): Post an error in case of premature
5149 -- usage of an entity from the limited view.
5151 if not Analyzed (Etype (Actual))
5152 and then From_With_Type (Etype (Actual))
5154 Error_Msg_Qual_Level := 1;
5156 ("missing with_clause for scope of imported type&",
5157 Actual, Etype (Actual));
5158 Error_Msg_Qual_Level := 0;
5161 Next_Actual (Actual);
5165 -- Analyze each candidate call again, with full error reporting
5169 ("no candidate interpretations match the actuals:!", Nam);
5170 Err_Mode := All_Errors_Mode;
5171 All_Errors_Mode := True;
5173 -- If this is a call to an operation of a concurrent type,
5174 -- the failed interpretations have been removed from the
5175 -- name. Recover them to provide full diagnostics.
5177 if Nkind (Parent (Nam)) = N_Selected_Component then
5178 Set_Entity (Nam, Empty);
5179 New_Nam := New_Copy_Tree (Parent (Nam));
5180 Set_Is_Overloaded (New_Nam, False);
5181 Set_Is_Overloaded (Selector_Name (New_Nam), False);
5182 Set_Parent (New_Nam, Parent (Parent (Nam)));
5183 Analyze_Selected_Component (New_Nam);
5184 Get_First_Interp (Selector_Name (New_Nam), X, It);
5186 Get_First_Interp (Nam, X, It);
5189 while Present (It.Nam) loop
5190 if Etype (It.Nam) = Standard_Void_Type then
5191 Void_Interp_Seen := True;
5194 Analyze_One_Call (N, It.Nam, True, Success);
5195 Get_Next_Interp (X, It);
5198 if Nkind (N) = N_Function_Call then
5199 Get_First_Interp (Nam, X, It);
5200 while Present (It.Nam) loop
5201 if Ekind_In (It.Nam, E_Function, E_Operator) then
5204 Get_Next_Interp (X, It);
5208 -- If all interpretations are procedures, this deserves a
5209 -- more precise message. Ditto if this appears as the prefix
5210 -- of a selected component, which may be a lexical error.
5213 ("\context requires function call, found procedure name", Nam);
5215 if Nkind (Parent (N)) = N_Selected_Component
5216 and then N = Prefix (Parent (N))
5218 Error_Msg_N -- CODEFIX
5219 ("\period should probably be semicolon", Parent (N));
5222 elsif Nkind (N) = N_Procedure_Call_Statement
5223 and then not Void_Interp_Seen
5226 "\function name found in procedure call", Nam);
5229 All_Errors_Mode := Err_Mode;
5232 ---------------------------
5233 -- Find_Arithmetic_Types --
5234 ---------------------------
5236 procedure Find_Arithmetic_Types
5241 Index1 : Interp_Index;
5242 Index2 : Interp_Index;
5246 procedure Check_Right_Argument (T : Entity_Id);
5247 -- Check right operand of operator
5249 --------------------------
5250 -- Check_Right_Argument --
5251 --------------------------
5253 procedure Check_Right_Argument (T : Entity_Id) is
5255 if not Is_Overloaded (R) then
5256 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
5258 Get_First_Interp (R, Index2, It2);
5259 while Present (It2.Typ) loop
5260 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
5261 Get_Next_Interp (Index2, It2);
5264 end Check_Right_Argument;
5266 -- Start of processing for Find_Arithmetic_Types
5269 if not Is_Overloaded (L) then
5270 Check_Right_Argument (Etype (L));
5273 Get_First_Interp (L, Index1, It1);
5274 while Present (It1.Typ) loop
5275 Check_Right_Argument (It1.Typ);
5276 Get_Next_Interp (Index1, It1);
5280 end Find_Arithmetic_Types;
5282 ------------------------
5283 -- Find_Boolean_Types --
5284 ------------------------
5286 procedure Find_Boolean_Types
5291 Index : Interp_Index;
5294 procedure Check_Numeric_Argument (T : Entity_Id);
5295 -- Special case for logical operations one of whose operands is an
5296 -- integer literal. If both are literal the result is any modular type.
5298 ----------------------------
5299 -- Check_Numeric_Argument --
5300 ----------------------------
5302 procedure Check_Numeric_Argument (T : Entity_Id) is
5304 if T = Universal_Integer then
5305 Add_One_Interp (N, Op_Id, Any_Modular);
5307 elsif Is_Modular_Integer_Type (T) then
5308 Add_One_Interp (N, Op_Id, T);
5310 end Check_Numeric_Argument;
5312 -- Start of processing for Find_Boolean_Types
5315 if not Is_Overloaded (L) then
5316 if Etype (L) = Universal_Integer
5317 or else Etype (L) = Any_Modular
5319 if not Is_Overloaded (R) then
5320 Check_Numeric_Argument (Etype (R));
5323 Get_First_Interp (R, Index, It);
5324 while Present (It.Typ) loop
5325 Check_Numeric_Argument (It.Typ);
5326 Get_Next_Interp (Index, It);
5330 -- If operands are aggregates, we must assume that they may be
5331 -- boolean arrays, and leave disambiguation for the second pass.
5332 -- If only one is an aggregate, verify that the other one has an
5333 -- interpretation as a boolean array
5335 elsif Nkind (L) = N_Aggregate then
5336 if Nkind (R) = N_Aggregate then
5337 Add_One_Interp (N, Op_Id, Etype (L));
5339 elsif not Is_Overloaded (R) then
5340 if Valid_Boolean_Arg (Etype (R)) then
5341 Add_One_Interp (N, Op_Id, Etype (R));
5345 Get_First_Interp (R, Index, It);
5346 while Present (It.Typ) loop
5347 if Valid_Boolean_Arg (It.Typ) then
5348 Add_One_Interp (N, Op_Id, It.Typ);
5351 Get_Next_Interp (Index, It);
5355 elsif Valid_Boolean_Arg (Etype (L))
5356 and then Has_Compatible_Type (R, Etype (L))
5358 Add_One_Interp (N, Op_Id, Etype (L));
5362 Get_First_Interp (L, Index, It);
5363 while Present (It.Typ) loop
5364 if Valid_Boolean_Arg (It.Typ)
5365 and then Has_Compatible_Type (R, It.Typ)
5367 Add_One_Interp (N, Op_Id, It.Typ);
5370 Get_Next_Interp (Index, It);
5373 end Find_Boolean_Types;
5375 ---------------------------
5376 -- Find_Comparison_Types --
5377 ---------------------------
5379 procedure Find_Comparison_Types
5384 Index : Interp_Index;
5386 Found : Boolean := False;
5389 Scop : Entity_Id := Empty;
5391 procedure Try_One_Interp (T1 : Entity_Id);
5392 -- Routine to try one proposed interpretation. Note that the context
5393 -- of the operator plays no role in resolving the arguments, so that
5394 -- if there is more than one interpretation of the operands that is
5395 -- compatible with comparison, the operation is ambiguous.
5397 --------------------
5398 -- Try_One_Interp --
5399 --------------------
5401 procedure Try_One_Interp (T1 : Entity_Id) is
5404 -- If the operator is an expanded name, then the type of the operand
5405 -- must be defined in the corresponding scope. If the type is
5406 -- universal, the context will impose the correct type.
5409 and then not Defined_In_Scope (T1, Scop)
5410 and then T1 /= Universal_Integer
5411 and then T1 /= Universal_Real
5412 and then T1 /= Any_String
5413 and then T1 /= Any_Composite
5418 if Valid_Comparison_Arg (T1)
5419 and then Has_Compatible_Type (R, T1)
5422 and then Base_Type (T1) /= Base_Type (T_F)
5424 It := Disambiguate (L, I_F, Index, Any_Type);
5426 if It = No_Interp then
5427 Ambiguous_Operands (N);
5428 Set_Etype (L, Any_Type);
5442 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
5447 -- Start of processing for Find_Comparison_Types
5450 -- If left operand is aggregate, the right operand has to
5451 -- provide a usable type for it.
5453 if Nkind (L) = N_Aggregate
5454 and then Nkind (R) /= N_Aggregate
5456 Find_Comparison_Types (L => R, R => L, Op_Id => Op_Id, N => N);
5460 if Nkind (N) = N_Function_Call
5461 and then Nkind (Name (N)) = N_Expanded_Name
5463 Scop := Entity (Prefix (Name (N)));
5465 -- The prefix may be a package renaming, and the subsequent test
5466 -- requires the original package.
5468 if Ekind (Scop) = E_Package
5469 and then Present (Renamed_Entity (Scop))
5471 Scop := Renamed_Entity (Scop);
5472 Set_Entity (Prefix (Name (N)), Scop);
5476 if not Is_Overloaded (L) then
5477 Try_One_Interp (Etype (L));
5480 Get_First_Interp (L, Index, It);
5481 while Present (It.Typ) loop
5482 Try_One_Interp (It.Typ);
5483 Get_Next_Interp (Index, It);
5486 end Find_Comparison_Types;
5488 ----------------------------------------
5489 -- Find_Non_Universal_Interpretations --
5490 ----------------------------------------
5492 procedure Find_Non_Universal_Interpretations
5498 Index : Interp_Index;
5502 if T1 = Universal_Integer
5503 or else T1 = Universal_Real
5505 -- If the left operand of an equality operator is null, the visibility
5506 -- of the operator must be determined from the interpretation of the
5507 -- right operand. This processing must be done for Any_Access, which
5508 -- is the internal representation of the type of the literal null.
5510 or else T1 = Any_Access
5512 if not Is_Overloaded (R) then
5514 (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
5516 Get_First_Interp (R, Index, It);
5517 while Present (It.Typ) loop
5518 if Covers (It.Typ, T1) then
5520 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
5523 Get_Next_Interp (Index, It);
5527 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
5529 end Find_Non_Universal_Interpretations;
5531 ------------------------------
5532 -- Find_Concatenation_Types --
5533 ------------------------------
5535 procedure Find_Concatenation_Types
5540 Op_Type : constant Entity_Id := Etype (Op_Id);
5543 if Is_Array_Type (Op_Type)
5544 and then not Is_Limited_Type (Op_Type)
5546 and then (Has_Compatible_Type (L, Op_Type)
5548 Has_Compatible_Type (L, Component_Type (Op_Type)))
5550 and then (Has_Compatible_Type (R, Op_Type)
5552 Has_Compatible_Type (R, Component_Type (Op_Type)))
5554 Add_One_Interp (N, Op_Id, Op_Type);
5556 end Find_Concatenation_Types;
5558 -------------------------
5559 -- Find_Equality_Types --
5560 -------------------------
5562 procedure Find_Equality_Types
5567 Index : Interp_Index;
5569 Found : Boolean := False;
5572 Scop : Entity_Id := Empty;
5574 procedure Try_One_Interp (T1 : Entity_Id);
5575 -- The context of the equality operator plays no role in resolving the
5576 -- arguments, so that if there is more than one interpretation of the
5577 -- operands that is compatible with equality, the construct is ambiguous
5578 -- and an error can be emitted now, after trying to disambiguate, i.e.
5579 -- applying preference rules.
5581 --------------------
5582 -- Try_One_Interp --
5583 --------------------
5585 procedure Try_One_Interp (T1 : Entity_Id) is
5586 Bas : constant Entity_Id := Base_Type (T1);
5589 -- If the operator is an expanded name, then the type of the operand
5590 -- must be defined in the corresponding scope. If the type is
5591 -- universal, the context will impose the correct type. An anonymous
5592 -- type for a 'Access reference is also universal in this sense, as
5593 -- the actual type is obtained from context.
5594 -- In Ada 2005, the equality operator for anonymous access types
5595 -- is declared in Standard, and preference rules apply to it.
5597 if Present (Scop) then
5598 if Defined_In_Scope (T1, Scop)
5599 or else T1 = Universal_Integer
5600 or else T1 = Universal_Real
5601 or else T1 = Any_Access
5602 or else T1 = Any_String
5603 or else T1 = Any_Composite
5604 or else (Ekind (T1) = E_Access_Subprogram_Type
5605 and then not Comes_From_Source (T1))
5609 elsif Ekind (T1) = E_Anonymous_Access_Type
5610 and then Scop = Standard_Standard
5615 -- The scope does not contain an operator for the type
5620 -- If we have infix notation, the operator must be usable. Within
5621 -- an instance, if the type is already established we know it is
5622 -- correct. If an operand is universal it is compatible with any
5625 -- In Ada 2005, the equality on anonymous access types is declared
5626 -- in Standard, and is always visible.
5628 elsif In_Open_Scopes (Scope (Bas))
5629 or else Is_Potentially_Use_Visible (Bas)
5630 or else In_Use (Bas)
5631 or else (In_Use (Scope (Bas)) and then not Is_Hidden (Bas))
5632 or else (In_Instance
5634 (First_Subtype (T1) = First_Subtype (Etype (R))
5636 (Is_Numeric_Type (T1)
5637 and then Is_Universal_Numeric_Type (Etype (R)))))
5638 or else Ekind (T1) = E_Anonymous_Access_Type
5643 -- Save candidate type for subsequent error message, if any
5645 if not Is_Limited_Type (T1) then
5646 Candidate_Type := T1;
5652 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
5653 -- Do not allow anonymous access types in equality operators.
5655 if Ada_Version < Ada_2005
5656 and then Ekind (T1) = E_Anonymous_Access_Type
5661 -- If the right operand has a type compatible with T1, check for an
5662 -- acceptable interpretation, unless T1 is limited (no predefined
5663 -- equality available), or this is use of a "/=" for a tagged type.
5664 -- In the latter case, possible interpretations of equality need to
5665 -- be considered, we don't want the default inequality declared in
5666 -- Standard to be chosen, and the "/=" will be rewritten as a
5667 -- negation of "=" (see the end of Analyze_Equality_Op). This ensures
5668 -- that that rewriting happens during analysis rather than being
5669 -- delayed until expansion (this is needed for ASIS, which only sees
5670 -- the unexpanded tree). Note that if the node is N_Op_Ne, but Op_Id
5671 -- is Name_Op_Eq then we still proceed with the interpretation,
5672 -- because that indicates the potential rewriting case where the
5673 -- interpretation to consider is actually "=" and the node may be
5674 -- about to be rewritten by Analyze_Equality_Op.
5676 if T1 /= Standard_Void_Type
5677 and then Has_Compatible_Type (R, T1)
5680 ((not Is_Limited_Type (T1)
5681 and then not Is_Limited_Composite (T1))
5685 and then not Is_Limited_Type (Component_Type (T1))
5686 and then Available_Full_View_Of_Component (T1)))
5689 (Nkind (N) /= N_Op_Ne
5690 or else not Is_Tagged_Type (T1)
5691 or else Chars (Op_Id) = Name_Op_Eq)
5694 and then Base_Type (T1) /= Base_Type (T_F)
5696 It := Disambiguate (L, I_F, Index, Any_Type);
5698 if It = No_Interp then
5699 Ambiguous_Operands (N);
5700 Set_Etype (L, Any_Type);
5713 if not Analyzed (L) then
5717 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
5719 -- Case of operator was not visible, Etype still set to Any_Type
5721 if Etype (N) = Any_Type then
5725 elsif Scop = Standard_Standard
5726 and then Ekind (T1) = E_Anonymous_Access_Type
5732 -- Start of processing for Find_Equality_Types
5735 -- If left operand is aggregate, the right operand has to
5736 -- provide a usable type for it.
5738 if Nkind (L) = N_Aggregate
5739 and then Nkind (R) /= N_Aggregate
5741 Find_Equality_Types (L => R, R => L, Op_Id => Op_Id, N => N);
5745 if Nkind (N) = N_Function_Call
5746 and then Nkind (Name (N)) = N_Expanded_Name
5748 Scop := Entity (Prefix (Name (N)));
5750 -- The prefix may be a package renaming, and the subsequent test
5751 -- requires the original package.
5753 if Ekind (Scop) = E_Package
5754 and then Present (Renamed_Entity (Scop))
5756 Scop := Renamed_Entity (Scop);
5757 Set_Entity (Prefix (Name (N)), Scop);
5761 if not Is_Overloaded (L) then
5762 Try_One_Interp (Etype (L));
5765 Get_First_Interp (L, Index, It);
5766 while Present (It.Typ) loop
5767 Try_One_Interp (It.Typ);
5768 Get_Next_Interp (Index, It);
5771 end Find_Equality_Types;
5773 -------------------------
5774 -- Find_Negation_Types --
5775 -------------------------
5777 procedure Find_Negation_Types
5782 Index : Interp_Index;
5786 if not Is_Overloaded (R) then
5787 if Etype (R) = Universal_Integer then
5788 Add_One_Interp (N, Op_Id, Any_Modular);
5789 elsif Valid_Boolean_Arg (Etype (R)) then
5790 Add_One_Interp (N, Op_Id, Etype (R));
5794 Get_First_Interp (R, Index, It);
5795 while Present (It.Typ) loop
5796 if Valid_Boolean_Arg (It.Typ) then
5797 Add_One_Interp (N, Op_Id, It.Typ);
5800 Get_Next_Interp (Index, It);
5803 end Find_Negation_Types;
5805 ------------------------------
5806 -- Find_Primitive_Operation --
5807 ------------------------------
5809 function Find_Primitive_Operation (N : Node_Id) return Boolean is
5810 Obj : constant Node_Id := Prefix (N);
5811 Op : constant Node_Id := Selector_Name (N);
5818 Set_Etype (Op, Any_Type);
5820 if Is_Access_Type (Etype (Obj)) then
5821 Typ := Designated_Type (Etype (Obj));
5826 if Is_Class_Wide_Type (Typ) then
5827 Typ := Root_Type (Typ);
5830 Prims := Primitive_Operations (Typ);
5832 Prim := First_Elmt (Prims);
5833 while Present (Prim) loop
5834 if Chars (Node (Prim)) = Chars (Op) then
5835 Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
5836 Set_Etype (N, Etype (Node (Prim)));
5842 -- Now look for class-wide operations of the type or any of its
5843 -- ancestors by iterating over the homonyms of the selector.
5846 Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
5850 Hom := Current_Entity (Op);
5851 while Present (Hom) loop
5852 if (Ekind (Hom) = E_Procedure
5854 Ekind (Hom) = E_Function)
5855 and then Scope (Hom) = Scope (Typ)
5856 and then Present (First_Formal (Hom))
5858 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
5860 (Is_Access_Type (Etype (First_Formal (Hom)))
5862 Ekind (Etype (First_Formal (Hom))) =
5863 E_Anonymous_Access_Type
5866 (Designated_Type (Etype (First_Formal (Hom)))) =
5869 Add_One_Interp (Op, Hom, Etype (Hom));
5870 Set_Etype (N, Etype (Hom));
5873 Hom := Homonym (Hom);
5877 return Etype (Op) /= Any_Type;
5878 end Find_Primitive_Operation;
5880 ----------------------
5881 -- Find_Unary_Types --
5882 ----------------------
5884 procedure Find_Unary_Types
5889 Index : Interp_Index;
5893 if not Is_Overloaded (R) then
5894 if Is_Numeric_Type (Etype (R)) then
5896 -- In an instance a generic actual may be a numeric type even if
5897 -- the formal in the generic unit was not. In that case, the
5898 -- predefined operator was not a possible interpretation in the
5899 -- generic, and cannot be one in the instance.
5903 not Is_Numeric_Type (Corresponding_Generic_Type (Etype (R)))
5907 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
5912 Get_First_Interp (R, Index, It);
5913 while Present (It.Typ) loop
5914 if Is_Numeric_Type (It.Typ) then
5918 (Corresponding_Generic_Type (Etype (It.Typ)))
5923 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
5927 Get_Next_Interp (Index, It);
5930 end Find_Unary_Types;
5936 function Junk_Operand (N : Node_Id) return Boolean is
5940 if Error_Posted (N) then
5944 -- Get entity to be tested
5946 if Is_Entity_Name (N)
5947 and then Present (Entity (N))
5951 -- An odd case, a procedure name gets converted to a very peculiar
5952 -- function call, and here is where we detect this happening.
5954 elsif Nkind (N) = N_Function_Call
5955 and then Is_Entity_Name (Name (N))
5956 and then Present (Entity (Name (N)))
5960 -- Another odd case, there are at least some cases of selected
5961 -- components where the selected component is not marked as having
5962 -- an entity, even though the selector does have an entity
5964 elsif Nkind (N) = N_Selected_Component
5965 and then Present (Entity (Selector_Name (N)))
5967 Enode := Selector_Name (N);
5973 -- Now test the entity we got to see if it is a bad case
5975 case Ekind (Entity (Enode)) is
5979 ("package name cannot be used as operand", Enode);
5981 when Generic_Unit_Kind =>
5983 ("generic unit name cannot be used as operand", Enode);
5987 ("subtype name cannot be used as operand", Enode);
5991 ("entry name cannot be used as operand", Enode);
5995 ("procedure name cannot be used as operand", Enode);
5999 ("exception name cannot be used as operand", Enode);
6001 when E_Block | E_Label | E_Loop =>
6003 ("label name cannot be used as operand", Enode);
6013 --------------------
6014 -- Operator_Check --
6015 --------------------
6017 procedure Operator_Check (N : Node_Id) is
6019 Remove_Abstract_Operations (N);
6021 -- Test for case of no interpretation found for operator
6023 if Etype (N) = Any_Type then
6027 Op_Id : Entity_Id := Empty;
6030 R := Right_Opnd (N);
6032 if Nkind (N) in N_Binary_Op then
6038 -- If either operand has no type, then don't complain further,
6039 -- since this simply means that we have a propagated error.
6042 or else Etype (R) = Any_Type
6043 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
6047 -- We explicitly check for the case of concatenation of component
6048 -- with component to avoid reporting spurious matching array types
6049 -- that might happen to be lurking in distant packages (such as
6050 -- run-time packages). This also prevents inconsistencies in the
6051 -- messages for certain ACVC B tests, which can vary depending on
6052 -- types declared in run-time interfaces. Another improvement when
6053 -- aggregates are present is to look for a well-typed operand.
6055 elsif Present (Candidate_Type)
6056 and then (Nkind (N) /= N_Op_Concat
6057 or else Is_Array_Type (Etype (L))
6058 or else Is_Array_Type (Etype (R)))
6060 if Nkind (N) = N_Op_Concat then
6061 if Etype (L) /= Any_Composite
6062 and then Is_Array_Type (Etype (L))
6064 Candidate_Type := Etype (L);
6066 elsif Etype (R) /= Any_Composite
6067 and then Is_Array_Type (Etype (R))
6069 Candidate_Type := Etype (R);
6073 Error_Msg_NE -- CODEFIX
6074 ("operator for} is not directly visible!",
6075 N, First_Subtype (Candidate_Type));
6078 U : constant Node_Id :=
6079 Cunit (Get_Source_Unit (Candidate_Type));
6081 if Unit_Is_Visible (U) then
6082 Error_Msg_N -- CODEFIX
6083 ("use clause would make operation legal!", N);
6085 Error_Msg_NE -- CODEFIX
6086 ("add with_clause and use_clause for&!",
6087 N, Defining_Entity (Unit (U)));
6092 -- If either operand is a junk operand (e.g. package name), then
6093 -- post appropriate error messages, but do not complain further.
6095 -- Note that the use of OR in this test instead of OR ELSE is
6096 -- quite deliberate, we may as well check both operands in the
6097 -- binary operator case.
6099 elsif Junk_Operand (R)
6100 or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
6104 -- If we have a logical operator, one of whose operands is
6105 -- Boolean, then we know that the other operand cannot resolve to
6106 -- Boolean (since we got no interpretations), but in that case we
6107 -- pretty much know that the other operand should be Boolean, so
6108 -- resolve it that way (generating an error)
6110 elsif Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor) then
6111 if Etype (L) = Standard_Boolean then
6112 Resolve (R, Standard_Boolean);
6114 elsif Etype (R) = Standard_Boolean then
6115 Resolve (L, Standard_Boolean);
6119 -- For an arithmetic operator or comparison operator, if one
6120 -- of the operands is numeric, then we know the other operand
6121 -- is not the same numeric type. If it is a non-numeric type,
6122 -- then probably it is intended to match the other operand.
6124 elsif Nkind_In (N, N_Op_Add,
6130 Nkind_In (N, N_Op_Lt,
6136 if Is_Numeric_Type (Etype (L))
6137 and then not Is_Numeric_Type (Etype (R))
6139 Resolve (R, Etype (L));
6142 elsif Is_Numeric_Type (Etype (R))
6143 and then not Is_Numeric_Type (Etype (L))
6145 Resolve (L, Etype (R));
6149 -- Comparisons on A'Access are common enough to deserve a
6152 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne)
6153 and then Ekind (Etype (L)) = E_Access_Attribute_Type
6154 and then Ekind (Etype (R)) = E_Access_Attribute_Type
6157 ("two access attributes cannot be compared directly", N);
6159 ("\use qualified expression for one of the operands",
6163 -- Another one for C programmers
6165 elsif Nkind (N) = N_Op_Concat
6166 and then Valid_Boolean_Arg (Etype (L))
6167 and then Valid_Boolean_Arg (Etype (R))
6169 Error_Msg_N ("invalid operands for concatenation", N);
6170 Error_Msg_N -- CODEFIX
6171 ("\maybe AND was meant", N);
6174 -- A special case for comparison of access parameter with null
6176 elsif Nkind (N) = N_Op_Eq
6177 and then Is_Entity_Name (L)
6178 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
6179 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
6181 and then Nkind (R) = N_Null
6183 Error_Msg_N ("access parameter is not allowed to be null", L);
6184 Error_Msg_N ("\(call would raise Constraint_Error)", L);
6187 -- Another special case for exponentiation, where the right
6188 -- operand must be Natural, independently of the base.
6190 elsif Nkind (N) = N_Op_Expon
6191 and then Is_Numeric_Type (Etype (L))
6192 and then not Is_Overloaded (R)
6194 First_Subtype (Base_Type (Etype (R))) /= Standard_Integer
6195 and then Base_Type (Etype (R)) /= Universal_Integer
6197 if Ada_Version >= Ada_2012
6198 and then Has_Dimension_System (Etype (L))
6201 ("exponent for dimensioned type must be a rational" &
6202 ", found}", R, Etype (R));
6205 ("exponent must be of type Natural, found}", R, Etype (R));
6211 -- If we fall through then just give general message. Note that in
6212 -- the following messages, if the operand is overloaded we choose
6213 -- an arbitrary type to complain about, but that is probably more
6214 -- useful than not giving a type at all.
6216 if Nkind (N) in N_Unary_Op then
6217 Error_Msg_Node_2 := Etype (R);
6218 Error_Msg_N ("operator& not defined for}", N);
6222 if Nkind (N) in N_Binary_Op then
6223 if not Is_Overloaded (L)
6224 and then not Is_Overloaded (R)
6225 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
6227 Error_Msg_Node_2 := First_Subtype (Etype (R));
6228 Error_Msg_N ("there is no applicable operator& for}", N);
6231 -- Another attempt to find a fix: one of the candidate
6232 -- interpretations may not be use-visible. This has
6233 -- already been checked for predefined operators, so
6234 -- we examine only user-defined functions.
6236 Op_Id := Get_Name_Entity_Id (Chars (N));
6238 while Present (Op_Id) loop
6239 if Ekind (Op_Id) /= E_Operator
6240 and then Is_Overloadable (Op_Id)
6242 if not Is_Immediately_Visible (Op_Id)
6243 and then not In_Use (Scope (Op_Id))
6244 and then not Is_Abstract_Subprogram (Op_Id)
6245 and then not Is_Hidden (Op_Id)
6246 and then Ekind (Scope (Op_Id)) = E_Package
6249 (L, Etype (First_Formal (Op_Id)))
6251 (Next_Formal (First_Formal (Op_Id)))
6255 Etype (Next_Formal (First_Formal (Op_Id))))
6258 ("No legal interpretation for operator&", N);
6260 ("\use clause on& would make operation legal",
6266 Op_Id := Homonym (Op_Id);
6270 Error_Msg_N ("invalid operand types for operator&", N);
6272 if Nkind (N) /= N_Op_Concat then
6273 Error_Msg_NE ("\left operand has}!", N, Etype (L));
6274 Error_Msg_NE ("\right operand has}!", N, Etype (R));
6284 -----------------------------------------
6285 -- Process_Implicit_Dereference_Prefix --
6286 -----------------------------------------
6288 function Process_Implicit_Dereference_Prefix
6290 P : Entity_Id) return Entity_Id
6293 Typ : constant Entity_Id := Designated_Type (Etype (P));
6297 and then (Operating_Mode = Check_Semantics or else not Expander_Active)
6299 -- We create a dummy reference to E to ensure that the reference
6300 -- is not considered as part of an assignment (an implicit
6301 -- dereference can never assign to its prefix). The Comes_From_Source
6302 -- attribute needs to be propagated for accurate warnings.
6304 Ref := New_Reference_To (E, Sloc (P));
6305 Set_Comes_From_Source (Ref, Comes_From_Source (P));
6306 Generate_Reference (E, Ref);
6309 -- An implicit dereference is a legal occurrence of an
6310 -- incomplete type imported through a limited_with clause,
6311 -- if the full view is visible.
6313 if From_With_Type (Typ)
6314 and then not From_With_Type (Scope (Typ))
6316 (Is_Immediately_Visible (Scope (Typ))
6318 (Is_Child_Unit (Scope (Typ))
6319 and then Is_Visible_Child_Unit (Scope (Typ))))
6321 return Available_View (Typ);
6326 end Process_Implicit_Dereference_Prefix;
6328 --------------------------------
6329 -- Remove_Abstract_Operations --
6330 --------------------------------
6332 procedure Remove_Abstract_Operations (N : Node_Id) is
6333 Abstract_Op : Entity_Id := Empty;
6334 Address_Kludge : Boolean := False;
6338 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
6339 -- activate this if either extensions are enabled, or if the abstract
6340 -- operation in question comes from a predefined file. This latter test
6341 -- allows us to use abstract to make operations invisible to users. In
6342 -- particular, if type Address is non-private and abstract subprograms
6343 -- are used to hide its operators, they will be truly hidden.
6345 type Operand_Position is (First_Op, Second_Op);
6346 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
6348 procedure Remove_Address_Interpretations (Op : Operand_Position);
6349 -- Ambiguities may arise when the operands are literal and the address
6350 -- operations in s-auxdec are visible. In that case, remove the
6351 -- interpretation of a literal as Address, to retain the semantics of
6352 -- Address as a private type.
6354 ------------------------------------
6355 -- Remove_Address_Interpretations --
6356 ------------------------------------
6358 procedure Remove_Address_Interpretations (Op : Operand_Position) is
6362 if Is_Overloaded (N) then
6363 Get_First_Interp (N, I, It);
6364 while Present (It.Nam) loop
6365 Formal := First_Entity (It.Nam);
6367 if Op = Second_Op then
6368 Formal := Next_Entity (Formal);
6371 if Is_Descendent_Of_Address (Etype (Formal)) then
6372 Address_Kludge := True;
6376 Get_Next_Interp (I, It);
6379 end Remove_Address_Interpretations;
6381 -- Start of processing for Remove_Abstract_Operations
6384 if Is_Overloaded (N) then
6385 if Debug_Flag_V then
6386 Write_Str ("Remove_Abstract_Operations: ");
6387 Write_Overloads (N);
6390 Get_First_Interp (N, I, It);
6392 while Present (It.Nam) loop
6393 if Is_Overloadable (It.Nam)
6394 and then Is_Abstract_Subprogram (It.Nam)
6395 and then not Is_Dispatching_Operation (It.Nam)
6397 Abstract_Op := It.Nam;
6399 if Is_Descendent_Of_Address (It.Typ) then
6400 Address_Kludge := True;
6404 -- In Ada 2005, this operation does not participate in overload
6405 -- resolution. If the operation is defined in a predefined
6406 -- unit, it is one of the operations declared abstract in some
6407 -- variants of System, and it must be removed as well.
6409 elsif Ada_Version >= Ada_2005
6410 or else Is_Predefined_File_Name
6411 (Unit_File_Name (Get_Source_Unit (It.Nam)))
6418 Get_Next_Interp (I, It);
6421 if No (Abstract_Op) then
6423 -- If some interpretation yields an integer type, it is still
6424 -- possible that there are address interpretations. Remove them
6425 -- if one operand is a literal, to avoid spurious ambiguities
6426 -- on systems where Address is a visible integer type.
6428 if Is_Overloaded (N)
6429 and then Nkind (N) in N_Op
6430 and then Is_Integer_Type (Etype (N))
6432 if Nkind (N) in N_Binary_Op then
6433 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
6434 Remove_Address_Interpretations (Second_Op);
6436 elsif Nkind (Right_Opnd (N)) = N_Integer_Literal then
6437 Remove_Address_Interpretations (First_Op);
6442 elsif Nkind (N) in N_Op then
6444 -- Remove interpretations that treat literals as addresses. This
6445 -- is never appropriate, even when Address is defined as a visible
6446 -- Integer type. The reason is that we would really prefer Address
6447 -- to behave as a private type, even in this case, which is there
6448 -- only to accommodate oddities of VMS address sizes. If Address
6449 -- is a visible integer type, we get lots of overload ambiguities.
6451 if Nkind (N) in N_Binary_Op then
6453 U1 : constant Boolean :=
6454 Present (Universal_Interpretation (Right_Opnd (N)));
6455 U2 : constant Boolean :=
6456 Present (Universal_Interpretation (Left_Opnd (N)));
6460 Remove_Address_Interpretations (Second_Op);
6464 Remove_Address_Interpretations (First_Op);
6467 if not (U1 and U2) then
6469 -- Remove corresponding predefined operator, which is
6470 -- always added to the overload set.
6472 Get_First_Interp (N, I, It);
6473 while Present (It.Nam) loop
6474 if Scope (It.Nam) = Standard_Standard
6475 and then Base_Type (It.Typ) =
6476 Base_Type (Etype (Abstract_Op))
6481 Get_Next_Interp (I, It);
6484 elsif Is_Overloaded (N)
6485 and then Present (Univ_Type)
6487 -- If both operands have a universal interpretation,
6488 -- it is still necessary to remove interpretations that
6489 -- yield Address. Any remaining ambiguities will be
6490 -- removed in Disambiguate.
6492 Get_First_Interp (N, I, It);
6493 while Present (It.Nam) loop
6494 if Is_Descendent_Of_Address (It.Typ) then
6497 elsif not Is_Type (It.Nam) then
6498 Set_Entity (N, It.Nam);
6501 Get_Next_Interp (I, It);
6507 elsif Nkind (N) = N_Function_Call
6509 (Nkind (Name (N)) = N_Operator_Symbol
6511 (Nkind (Name (N)) = N_Expanded_Name
6513 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
6517 Arg1 : constant Node_Id := First (Parameter_Associations (N));
6518 U1 : constant Boolean :=
6519 Present (Universal_Interpretation (Arg1));
6520 U2 : constant Boolean :=
6521 Present (Next (Arg1)) and then
6522 Present (Universal_Interpretation (Next (Arg1)));
6526 Remove_Address_Interpretations (First_Op);
6530 Remove_Address_Interpretations (Second_Op);
6533 if not (U1 and U2) then
6534 Get_First_Interp (N, I, It);
6535 while Present (It.Nam) loop
6536 if Scope (It.Nam) = Standard_Standard
6537 and then It.Typ = Base_Type (Etype (Abstract_Op))
6542 Get_Next_Interp (I, It);
6548 -- If the removal has left no valid interpretations, emit an error
6549 -- message now and label node as illegal.
6551 if Present (Abstract_Op) then
6552 Get_First_Interp (N, I, It);
6556 -- Removal of abstract operation left no viable candidate
6558 Set_Etype (N, Any_Type);
6559 Error_Msg_Sloc := Sloc (Abstract_Op);
6561 ("cannot call abstract operation& declared#", N, Abstract_Op);
6563 -- In Ada 2005, an abstract operation may disable predefined
6564 -- operators. Since the context is not yet known, we mark the
6565 -- predefined operators as potentially hidden. Do not include
6566 -- predefined operators when addresses are involved since this
6567 -- case is handled separately.
6569 elsif Ada_Version >= Ada_2005
6570 and then not Address_Kludge
6572 while Present (It.Nam) loop
6573 if Is_Numeric_Type (It.Typ)
6574 and then Scope (It.Typ) = Standard_Standard
6576 Set_Abstract_Op (I, Abstract_Op);
6579 Get_Next_Interp (I, It);
6584 if Debug_Flag_V then
6585 Write_Str ("Remove_Abstract_Operations done: ");
6586 Write_Overloads (N);
6589 end Remove_Abstract_Operations;
6591 ----------------------------
6592 -- Try_Container_Indexing --
6593 ----------------------------
6595 function Try_Container_Indexing
6598 Exprs : List_Id) return Boolean
6600 Loc : constant Source_Ptr := Sloc (N);
6604 Func_Name : Node_Id;
6609 -- Check whether type has a specified indexing aspect
6613 if Is_Variable (Prefix) then
6614 Func_Name := Find_Aspect (Etype (Prefix), Aspect_Variable_Indexing);
6617 if No (Func_Name) then
6618 Func_Name := Find_Aspect (Etype (Prefix), Aspect_Constant_Indexing);
6621 -- If aspect does not exist the expression is illegal. Error is
6622 -- diagnosed in caller.
6624 if No (Func_Name) then
6626 -- The prefix itself may be an indexing of a container
6627 -- rewrite as such and re-analyze.
6629 if Has_Implicit_Dereference (Etype (Prefix)) then
6630 Build_Explicit_Dereference
6631 (Prefix, First_Discriminant (Etype (Prefix)));
6632 return Try_Container_Indexing (N, Prefix, Exprs);
6639 Assoc := New_List (Relocate_Node (Prefix));
6641 -- A generalized iterator may have nore than one index expression, so
6642 -- transfer all of them to the argument list to be used in the call.
6647 Arg := First (Exprs);
6648 while Present (Arg) loop
6649 Append (Relocate_Node (Arg), Assoc);
6654 if not Is_Overloaded (Func_Name) then
6655 Func := Entity (Func_Name);
6657 Make_Function_Call (Loc,
6658 Name => New_Occurrence_Of (Func, Loc),
6659 Parameter_Associations => Assoc);
6660 Rewrite (N, Indexing);
6663 -- If the return type of the indexing function is a reference type,
6664 -- add the dereference as a possible interpretation. Note that the
6665 -- indexing aspect may be a function that returns the element type
6666 -- with no intervening implicit dereference.
6668 if Has_Discriminants (Etype (Func)) then
6669 Disc := First_Discriminant (Etype (Func));
6670 while Present (Disc) loop
6671 if Has_Implicit_Dereference (Disc) then
6672 Add_One_Interp (N, Disc, Designated_Type (Etype (Disc)));
6676 Next_Discriminant (Disc);
6681 Indexing := Make_Function_Call (Loc,
6682 Name => Make_Identifier (Loc, Chars (Func_Name)),
6683 Parameter_Associations => Assoc);
6685 Rewrite (N, Indexing);
6693 Get_First_Interp (Func_Name, I, It);
6694 Set_Etype (N, Any_Type);
6695 while Present (It.Nam) loop
6696 Analyze_One_Call (N, It.Nam, False, Success);
6698 Set_Etype (Name (N), It.Typ);
6699 Set_Entity (Name (N), It.Nam);
6701 -- Add implicit dereference interpretation
6703 if Has_Discriminants (Etype (It.Nam)) then
6704 Disc := First_Discriminant (Etype (It.Nam));
6705 while Present (Disc) loop
6706 if Has_Implicit_Dereference (Disc) then
6708 (N, Disc, Designated_Type (Etype (Disc)));
6712 Next_Discriminant (Disc);
6718 Get_Next_Interp (I, It);
6723 if Etype (N) = Any_Type then
6725 ("container cannot be indexed with&", N, Etype (First (Exprs)));
6726 Rewrite (N, New_Occurrence_Of (Any_Id, Loc));
6732 end Try_Container_Indexing;
6734 -----------------------
6735 -- Try_Indirect_Call --
6736 -----------------------
6738 function Try_Indirect_Call
6741 Typ : Entity_Id) return Boolean
6747 pragma Warnings (Off, Call_OK);
6750 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
6752 Actual := First_Actual (N);
6753 Formal := First_Formal (Designated_Type (Typ));
6754 while Present (Actual) and then Present (Formal) loop
6755 if not Has_Compatible_Type (Actual, Etype (Formal)) then
6760 Next_Formal (Formal);
6763 if No (Actual) and then No (Formal) then
6764 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
6766 -- Nam is a candidate interpretation for the name in the call,
6767 -- if it is not an indirect call.
6769 if not Is_Type (Nam)
6770 and then Is_Entity_Name (Name (N))
6772 Set_Entity (Name (N), Nam);
6779 end Try_Indirect_Call;
6781 ----------------------
6782 -- Try_Indexed_Call --
6783 ----------------------
6785 function Try_Indexed_Call
6789 Skip_First : Boolean) return Boolean
6791 Loc : constant Source_Ptr := Sloc (N);
6792 Actuals : constant List_Id := Parameter_Associations (N);
6797 Actual := First (Actuals);
6799 -- If the call was originally written in prefix form, skip the first
6800 -- actual, which is obviously not defaulted.
6806 Index := First_Index (Typ);
6807 while Present (Actual) and then Present (Index) loop
6809 -- If the parameter list has a named association, the expression
6810 -- is definitely a call and not an indexed component.
6812 if Nkind (Actual) = N_Parameter_Association then
6816 if Is_Entity_Name (Actual)
6817 and then Is_Type (Entity (Actual))
6818 and then No (Next (Actual))
6820 -- A single actual that is a type name indicates a slice if the
6821 -- type is discrete, and an error otherwise.
6823 if Is_Discrete_Type (Entity (Actual)) then
6827 Make_Function_Call (Loc,
6828 Name => Relocate_Node (Name (N))),
6830 New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
6835 Error_Msg_N ("invalid use of type in expression", Actual);
6836 Set_Etype (N, Any_Type);
6841 elsif not Has_Compatible_Type (Actual, Etype (Index)) then
6849 if No (Actual) and then No (Index) then
6850 Add_One_Interp (N, Nam, Component_Type (Typ));
6852 -- Nam is a candidate interpretation for the name in the call,
6853 -- if it is not an indirect call.
6855 if not Is_Type (Nam)
6856 and then Is_Entity_Name (Name (N))
6858 Set_Entity (Name (N), Nam);
6865 end Try_Indexed_Call;
6867 --------------------------
6868 -- Try_Object_Operation --
6869 --------------------------
6871 function Try_Object_Operation
6872 (N : Node_Id; CW_Test_Only : Boolean := False) return Boolean
6874 K : constant Node_Kind := Nkind (Parent (N));
6875 Is_Subprg_Call : constant Boolean := K in N_Subprogram_Call;
6876 Loc : constant Source_Ptr := Sloc (N);
6877 Obj : constant Node_Id := Prefix (N);
6879 Subprog : constant Node_Id :=
6880 Make_Identifier (Sloc (Selector_Name (N)),
6881 Chars => Chars (Selector_Name (N)));
6882 -- Identifier on which possible interpretations will be collected
6884 Report_Error : Boolean := False;
6885 -- If no candidate interpretation matches the context, redo the
6886 -- analysis with error enabled to provide additional information.
6889 Candidate : Entity_Id := Empty;
6890 New_Call_Node : Node_Id := Empty;
6891 Node_To_Replace : Node_Id;
6892 Obj_Type : Entity_Id := Etype (Obj);
6893 Success : Boolean := False;
6895 function Valid_Candidate
6898 Subp : Entity_Id) return Entity_Id;
6899 -- If the subprogram is a valid interpretation, record it, and add
6900 -- to the list of interpretations of Subprog. Otherwise return Empty.
6902 procedure Complete_Object_Operation
6903 (Call_Node : Node_Id;
6904 Node_To_Replace : Node_Id);
6905 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
6906 -- Call_Node, insert the object (or its dereference) as the first actual
6907 -- in the call, and complete the analysis of the call.
6909 procedure Report_Ambiguity (Op : Entity_Id);
6910 -- If a prefixed procedure call is ambiguous, indicate whether the
6911 -- call includes an implicit dereference or an implicit 'Access.
6913 procedure Transform_Object_Operation
6914 (Call_Node : out Node_Id;
6915 Node_To_Replace : out Node_Id);
6916 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
6917 -- Call_Node is the resulting subprogram call, Node_To_Replace is
6918 -- either N or the parent of N, and Subprog is a reference to the
6919 -- subprogram we are trying to match.
6921 function Try_Class_Wide_Operation
6922 (Call_Node : Node_Id;
6923 Node_To_Replace : Node_Id) return Boolean;
6924 -- Traverse all ancestor types looking for a class-wide subprogram
6925 -- for which the current operation is a valid non-dispatching call.
6927 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
6928 -- If prefix is overloaded, its interpretation may include different
6929 -- tagged types, and we must examine the primitive operations and
6930 -- the class-wide operations of each in order to find candidate
6931 -- interpretations for the call as a whole.
6933 function Try_Primitive_Operation
6934 (Call_Node : Node_Id;
6935 Node_To_Replace : Node_Id) return Boolean;
6936 -- Traverse the list of primitive subprograms looking for a dispatching
6937 -- operation for which the current node is a valid call .
6939 ---------------------
6940 -- Valid_Candidate --
6941 ---------------------
6943 function Valid_Candidate
6946 Subp : Entity_Id) return Entity_Id
6948 Arr_Type : Entity_Id;
6949 Comp_Type : Entity_Id;
6952 -- If the subprogram is a valid interpretation, record it in global
6953 -- variable Subprog, to collect all possible overloadings.
6956 if Subp /= Entity (Subprog) then
6957 Add_One_Interp (Subprog, Subp, Etype (Subp));
6961 -- If the call may be an indexed call, retrieve component type of
6962 -- resulting expression, and add possible interpretation.
6967 if Nkind (Call) = N_Function_Call
6968 and then Nkind (Parent (N)) = N_Indexed_Component
6969 and then Needs_One_Actual (Subp)
6971 if Is_Array_Type (Etype (Subp)) then
6972 Arr_Type := Etype (Subp);
6974 elsif Is_Access_Type (Etype (Subp))
6975 and then Is_Array_Type (Designated_Type (Etype (Subp)))
6977 Arr_Type := Designated_Type (Etype (Subp));
6981 if Present (Arr_Type) then
6983 -- Verify that the actuals (excluding the object) match the types
6991 Actual := Next (First_Actual (Call));
6992 Index := First_Index (Arr_Type);
6993 while Present (Actual) and then Present (Index) loop
6994 if not Has_Compatible_Type (Actual, Etype (Index)) then
6999 Next_Actual (Actual);
7005 and then Present (Arr_Type)
7007 Comp_Type := Component_Type (Arr_Type);
7011 if Present (Comp_Type)
7012 and then Etype (Subprog) /= Comp_Type
7014 Add_One_Interp (Subprog, Subp, Comp_Type);
7018 if Etype (Call) /= Any_Type then
7023 end Valid_Candidate;
7025 -------------------------------
7026 -- Complete_Object_Operation --
7027 -------------------------------
7029 procedure Complete_Object_Operation
7030 (Call_Node : Node_Id;
7031 Node_To_Replace : Node_Id)
7033 Control : constant Entity_Id := First_Formal (Entity (Subprog));
7034 Formal_Type : constant Entity_Id := Etype (Control);
7035 First_Actual : Node_Id;
7038 -- Place the name of the operation, with its interpretations,
7039 -- on the rewritten call.
7041 Set_Name (Call_Node, Subprog);
7043 First_Actual := First (Parameter_Associations (Call_Node));
7045 -- For cross-reference purposes, treat the new node as being in
7046 -- the source if the original one is. Set entity and type, even
7047 -- though they may be overwritten during resolution if overloaded.
7049 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
7050 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
7052 if Nkind (N) = N_Selected_Component
7053 and then not Inside_A_Generic
7055 Set_Entity (Selector_Name (N), Entity (Subprog));
7056 Set_Etype (Selector_Name (N), Etype (Entity (Subprog)));
7059 -- If need be, rewrite first actual as an explicit dereference
7060 -- If the call is overloaded, the rewriting can only be done
7061 -- once the primitive operation is identified.
7063 if Is_Overloaded (Subprog) then
7065 -- The prefix itself may be overloaded, and its interpretations
7066 -- must be propagated to the new actual in the call.
7068 if Is_Overloaded (Obj) then
7069 Save_Interps (Obj, First_Actual);
7072 Rewrite (First_Actual, Obj);
7074 elsif not Is_Access_Type (Formal_Type)
7075 and then Is_Access_Type (Etype (Obj))
7077 Rewrite (First_Actual,
7078 Make_Explicit_Dereference (Sloc (Obj), Obj));
7079 Analyze (First_Actual);
7081 -- If we need to introduce an explicit dereference, verify that
7082 -- the resulting actual is compatible with the mode of the formal.
7084 if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
7085 and then Is_Access_Constant (Etype (Obj))
7088 ("expect variable in call to&", Prefix (N), Entity (Subprog));
7091 -- Conversely, if the formal is an access parameter and the object
7092 -- is not, replace the actual with a 'Access reference. Its analysis
7093 -- will check that the object is aliased.
7095 elsif Is_Access_Type (Formal_Type)
7096 and then not Is_Access_Type (Etype (Obj))
7098 -- A special case: A.all'access is illegal if A is an access to a
7099 -- constant and the context requires an access to a variable.
7101 if not Is_Access_Constant (Formal_Type) then
7102 if (Nkind (Obj) = N_Explicit_Dereference
7103 and then Is_Access_Constant (Etype (Prefix (Obj))))
7104 or else not Is_Variable (Obj)
7107 ("actual for& must be a variable", Obj, Control);
7111 Rewrite (First_Actual,
7112 Make_Attribute_Reference (Loc,
7113 Attribute_Name => Name_Access,
7114 Prefix => Relocate_Node (Obj)));
7116 if not Is_Aliased_View (Obj) then
7118 ("object in prefixed call to& must be aliased"
7119 & " (RM-2005 4.3.1 (13))",
7120 Prefix (First_Actual), Subprog);
7123 Analyze (First_Actual);
7126 if Is_Overloaded (Obj) then
7127 Save_Interps (Obj, First_Actual);
7130 Rewrite (First_Actual, Obj);
7133 Rewrite (Node_To_Replace, Call_Node);
7135 -- Propagate the interpretations collected in subprog to the new
7136 -- function call node, to be resolved from context.
7138 if Is_Overloaded (Subprog) then
7139 Save_Interps (Subprog, Node_To_Replace);
7142 Analyze (Node_To_Replace);
7144 -- If the operation has been rewritten into a call, which may get
7145 -- subsequently an explicit dereference, preserve the type on the
7146 -- original node (selected component or indexed component) for
7147 -- subsequent legality tests, e.g. Is_Variable. which examines
7148 -- the original node.
7150 if Nkind (Node_To_Replace) = N_Function_Call then
7152 (Original_Node (Node_To_Replace), Etype (Node_To_Replace));
7155 end Complete_Object_Operation;
7157 ----------------------
7158 -- Report_Ambiguity --
7159 ----------------------
7161 procedure Report_Ambiguity (Op : Entity_Id) is
7162 Access_Actual : constant Boolean :=
7163 Is_Access_Type (Etype (Prefix (N)));
7164 Access_Formal : Boolean := False;
7167 Error_Msg_Sloc := Sloc (Op);
7169 if Present (First_Formal (Op)) then
7170 Access_Formal := Is_Access_Type (Etype (First_Formal (Op)));
7173 if Access_Formal and then not Access_Actual then
7174 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
7176 ("\possible interpretation"
7177 & " (inherited, with implicit 'Access) #", N);
7180 ("\possible interpretation (with implicit 'Access) #", N);
7183 elsif not Access_Formal and then Access_Actual then
7184 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
7186 ("\possible interpretation"
7187 & " ( inherited, with implicit dereference) #", N);
7190 ("\possible interpretation (with implicit dereference) #", N);
7194 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
7195 Error_Msg_N ("\possible interpretation (inherited)#", N);
7197 Error_Msg_N -- CODEFIX
7198 ("\possible interpretation#", N);
7201 end Report_Ambiguity;
7203 --------------------------------
7204 -- Transform_Object_Operation --
7205 --------------------------------
7207 procedure Transform_Object_Operation
7208 (Call_Node : out Node_Id;
7209 Node_To_Replace : out Node_Id)
7211 Dummy : constant Node_Id := New_Copy (Obj);
7212 -- Placeholder used as a first parameter in the call, replaced
7213 -- eventually by the proper object.
7215 Parent_Node : constant Node_Id := Parent (N);
7221 -- Common case covering 1) Call to a procedure and 2) Call to a
7222 -- function that has some additional actuals.
7224 if Nkind (Parent_Node) in N_Subprogram_Call
7226 -- N is a selected component node containing the name of the
7227 -- subprogram. If N is not the name of the parent node we must
7228 -- not replace the parent node by the new construct. This case
7229 -- occurs when N is a parameterless call to a subprogram that
7230 -- is an actual parameter of a call to another subprogram. For
7232 -- Some_Subprogram (..., Obj.Operation, ...)
7234 and then Name (Parent_Node) = N
7236 Node_To_Replace := Parent_Node;
7238 Actuals := Parameter_Associations (Parent_Node);
7240 if Present (Actuals) then
7241 Prepend (Dummy, Actuals);
7243 Actuals := New_List (Dummy);
7246 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
7248 Make_Procedure_Call_Statement (Loc,
7249 Name => New_Copy (Subprog),
7250 Parameter_Associations => Actuals);
7254 Make_Function_Call (Loc,
7255 Name => New_Copy (Subprog),
7256 Parameter_Associations => Actuals);
7260 -- Before analysis, a function call appears as an indexed component
7261 -- if there are no named associations.
7263 elsif Nkind (Parent_Node) = N_Indexed_Component
7264 and then N = Prefix (Parent_Node)
7266 Node_To_Replace := Parent_Node;
7267 Actuals := Expressions (Parent_Node);
7269 Actual := First (Actuals);
7270 while Present (Actual) loop
7275 Prepend (Dummy, Actuals);
7278 Make_Function_Call (Loc,
7279 Name => New_Copy (Subprog),
7280 Parameter_Associations => Actuals);
7282 -- Parameterless call: Obj.F is rewritten as F (Obj)
7285 Node_To_Replace := N;
7288 Make_Function_Call (Loc,
7289 Name => New_Copy (Subprog),
7290 Parameter_Associations => New_List (Dummy));
7292 end Transform_Object_Operation;
7294 ------------------------------
7295 -- Try_Class_Wide_Operation --
7296 ------------------------------
7298 function Try_Class_Wide_Operation
7299 (Call_Node : Node_Id;
7300 Node_To_Replace : Node_Id) return Boolean
7302 Anc_Type : Entity_Id;
7303 Matching_Op : Entity_Id := Empty;
7306 procedure Traverse_Homonyms
7307 (Anc_Type : Entity_Id;
7308 Error : out Boolean);
7309 -- Traverse the homonym chain of the subprogram searching for those
7310 -- homonyms whose first formal has the Anc_Type's class-wide type,
7311 -- or an anonymous access type designating the class-wide type. If
7312 -- an ambiguity is detected, then Error is set to True.
7314 procedure Traverse_Interfaces
7315 (Anc_Type : Entity_Id;
7316 Error : out Boolean);
7317 -- Traverse the list of interfaces, if any, associated with Anc_Type
7318 -- and search for acceptable class-wide homonyms associated with each
7319 -- interface. If an ambiguity is detected, then Error is set to True.
7321 -----------------------
7322 -- Traverse_Homonyms --
7323 -----------------------
7325 procedure Traverse_Homonyms
7326 (Anc_Type : Entity_Id;
7327 Error : out Boolean)
7329 Cls_Type : Entity_Id;
7337 Cls_Type := Class_Wide_Type (Anc_Type);
7339 Hom := Current_Entity (Subprog);
7341 -- Find a non-hidden operation whose first parameter is of the
7342 -- class-wide type, a subtype thereof, or an anonymous access
7343 -- to same. If in an instance, the operation can be considered
7344 -- even if hidden (it may be hidden because the instantiation is
7345 -- expanded after the containing package has been analyzed).
7347 while Present (Hom) loop
7348 if Ekind_In (Hom, E_Procedure, E_Function)
7349 and then (not Is_Hidden (Hom) or else In_Instance)
7350 and then Scope (Hom) = Scope (Anc_Type)
7351 and then Present (First_Formal (Hom))
7353 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
7355 (Is_Access_Type (Etype (First_Formal (Hom)))
7357 Ekind (Etype (First_Formal (Hom))) =
7358 E_Anonymous_Access_Type
7361 (Designated_Type (Etype (First_Formal (Hom)))) =
7364 -- If the context is a procedure call, ignore functions
7365 -- in the name of the call.
7367 if Ekind (Hom) = E_Function
7368 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
7369 and then N = Name (Parent (N))
7373 -- If the context is a function call, ignore procedures
7374 -- in the name of the call.
7376 elsif Ekind (Hom) = E_Procedure
7377 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
7382 Set_Etype (Call_Node, Any_Type);
7383 Set_Is_Overloaded (Call_Node, False);
7386 if No (Matching_Op) then
7387 Hom_Ref := New_Reference_To (Hom, Sloc (Subprog));
7388 Set_Etype (Call_Node, Any_Type);
7389 Set_Parent (Call_Node, Parent (Node_To_Replace));
7391 Set_Name (Call_Node, Hom_Ref);
7396 Report => Report_Error,
7398 Skip_First => True);
7401 Valid_Candidate (Success, Call_Node, Hom);
7407 Report => Report_Error,
7409 Skip_First => True);
7411 if Present (Valid_Candidate (Success, Call_Node, Hom))
7412 and then Nkind (Call_Node) /= N_Function_Call
7414 Error_Msg_NE ("ambiguous call to&", N, Hom);
7415 Report_Ambiguity (Matching_Op);
7416 Report_Ambiguity (Hom);
7424 Hom := Homonym (Hom);
7426 end Traverse_Homonyms;
7428 -------------------------
7429 -- Traverse_Interfaces --
7430 -------------------------
7432 procedure Traverse_Interfaces
7433 (Anc_Type : Entity_Id;
7434 Error : out Boolean)
7436 Intface_List : constant List_Id :=
7437 Abstract_Interface_List (Anc_Type);
7443 if Is_Non_Empty_List (Intface_List) then
7444 Intface := First (Intface_List);
7445 while Present (Intface) loop
7447 -- Look for acceptable class-wide homonyms associated with
7450 Traverse_Homonyms (Etype (Intface), Error);
7456 -- Continue the search by looking at each of the interface's
7457 -- associated interface ancestors.
7459 Traverse_Interfaces (Etype (Intface), Error);
7468 end Traverse_Interfaces;
7470 -- Start of processing for Try_Class_Wide_Operation
7473 -- If we are searching only for conflicting class-wide subprograms
7474 -- then initialize directly Matching_Op with the target entity.
7476 if CW_Test_Only then
7477 Matching_Op := Entity (Selector_Name (N));
7480 -- Loop through ancestor types (including interfaces), traversing
7481 -- the homonym chain of the subprogram, trying out those homonyms
7482 -- whose first formal has the class-wide type of the ancestor, or
7483 -- an anonymous access type designating the class-wide type.
7485 Anc_Type := Obj_Type;
7487 -- Look for a match among homonyms associated with the ancestor
7489 Traverse_Homonyms (Anc_Type, Error);
7495 -- Continue the search for matches among homonyms associated with
7496 -- any interfaces implemented by the ancestor.
7498 Traverse_Interfaces (Anc_Type, Error);
7504 exit when Etype (Anc_Type) = Anc_Type;
7505 Anc_Type := Etype (Anc_Type);
7508 if Present (Matching_Op) then
7509 Set_Etype (Call_Node, Etype (Matching_Op));
7512 return Present (Matching_Op);
7513 end Try_Class_Wide_Operation;
7515 -----------------------------------
7516 -- Try_One_Prefix_Interpretation --
7517 -----------------------------------
7519 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
7523 if Is_Access_Type (Obj_Type) then
7524 Obj_Type := Designated_Type (Obj_Type);
7527 if Ekind (Obj_Type) = E_Private_Subtype then
7528 Obj_Type := Base_Type (Obj_Type);
7531 if Is_Class_Wide_Type (Obj_Type) then
7532 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
7535 -- The type may have be obtained through a limited_with clause,
7536 -- in which case the primitive operations are available on its
7537 -- non-limited view. If still incomplete, retrieve full view.
7539 if Ekind (Obj_Type) = E_Incomplete_Type
7540 and then From_With_Type (Obj_Type)
7542 Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
7545 -- If the object is not tagged, or the type is still an incomplete
7546 -- type, this is not a prefixed call.
7548 if not Is_Tagged_Type (Obj_Type)
7549 or else Is_Incomplete_Type (Obj_Type)
7555 Dup_Call_Node : constant Node_Id := New_Copy (New_Call_Node);
7556 CW_Result : Boolean;
7557 Prim_Result : Boolean;
7558 pragma Unreferenced (CW_Result);
7561 if not CW_Test_Only then
7563 Try_Primitive_Operation
7564 (Call_Node => New_Call_Node,
7565 Node_To_Replace => Node_To_Replace);
7568 -- Check if there is a class-wide subprogram covering the
7569 -- primitive. This check must be done even if a candidate
7570 -- was found in order to report ambiguous calls.
7572 if not (Prim_Result) then
7574 Try_Class_Wide_Operation
7575 (Call_Node => New_Call_Node,
7576 Node_To_Replace => Node_To_Replace);
7578 -- If we found a primitive we search for class-wide subprograms
7579 -- using a duplicate of the call node (done to avoid missing its
7580 -- decoration if there is no ambiguity).
7584 Try_Class_Wide_Operation
7585 (Call_Node => Dup_Call_Node,
7586 Node_To_Replace => Node_To_Replace);
7589 end Try_One_Prefix_Interpretation;
7591 -----------------------------
7592 -- Try_Primitive_Operation --
7593 -----------------------------
7595 function Try_Primitive_Operation
7596 (Call_Node : Node_Id;
7597 Node_To_Replace : Node_Id) return Boolean
7600 Prim_Op : Entity_Id;
7601 Matching_Op : Entity_Id := Empty;
7602 Prim_Op_Ref : Node_Id := Empty;
7604 Corr_Type : Entity_Id := Empty;
7605 -- If the prefix is a synchronized type, the controlling type of
7606 -- the primitive operation is the corresponding record type, else
7607 -- this is the object type itself.
7609 Success : Boolean := False;
7611 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
7612 -- For tagged types the candidate interpretations are found in
7613 -- the list of primitive operations of the type and its ancestors.
7614 -- For formal tagged types we have to find the operations declared
7615 -- in the same scope as the type (including in the generic formal
7616 -- part) because the type itself carries no primitive operations,
7617 -- except for formal derived types that inherit the operations of
7618 -- the parent and progenitors.
7619 -- If the context is a generic subprogram body, the generic formals
7620 -- are visible by name, but are not in the entity list of the
7621 -- subprogram because that list starts with the subprogram formals.
7622 -- We retrieve the candidate operations from the generic declaration.
7624 function Is_Private_Overriding (Op : Entity_Id) return Boolean;
7625 -- An operation that overrides an inherited operation in the private
7626 -- part of its package may be hidden, but if the inherited operation
7627 -- is visible a direct call to it will dispatch to the private one,
7628 -- which is therefore a valid candidate.
7630 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
7631 -- Verify that the prefix, dereferenced if need be, is a valid
7632 -- controlling argument in a call to Op. The remaining actuals
7633 -- are checked in the subsequent call to Analyze_One_Call.
7635 ------------------------------
7636 -- Collect_Generic_Type_Ops --
7637 ------------------------------
7639 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
7640 Bas : constant Entity_Id := Base_Type (T);
7641 Candidates : constant Elist_Id := New_Elmt_List;
7645 procedure Check_Candidate;
7646 -- The operation is a candidate if its first parameter is a
7647 -- controlling operand of the desired type.
7649 -----------------------
7650 -- Check_Candidate; --
7651 -----------------------
7653 procedure Check_Candidate is
7655 Formal := First_Formal (Subp);
7658 and then Is_Controlling_Formal (Formal)
7660 (Base_Type (Etype (Formal)) = Bas
7662 (Is_Access_Type (Etype (Formal))
7663 and then Designated_Type (Etype (Formal)) = Bas))
7665 Append_Elmt (Subp, Candidates);
7667 end Check_Candidate;
7669 -- Start of processing for Collect_Generic_Type_Ops
7672 if Is_Derived_Type (T) then
7673 return Primitive_Operations (T);
7675 elsif Ekind_In (Scope (T), E_Procedure, E_Function) then
7677 -- Scan the list of generic formals to find subprograms
7678 -- that may have a first controlling formal of the type.
7680 if Nkind (Unit_Declaration_Node (Scope (T)))
7681 = N_Generic_Subprogram_Declaration
7688 First (Generic_Formal_Declarations
7689 (Unit_Declaration_Node (Scope (T))));
7690 while Present (Decl) loop
7691 if Nkind (Decl) in N_Formal_Subprogram_Declaration then
7692 Subp := Defining_Entity (Decl);
7703 -- Scan the list of entities declared in the same scope as
7704 -- the type. In general this will be an open scope, given that
7705 -- the call we are analyzing can only appear within a generic
7706 -- declaration or body (either the one that declares T, or a
7709 -- For a subtype representing a generic actual type, go to the
7712 if Is_Generic_Actual_Type (T) then
7713 Subp := First_Entity (Scope (Base_Type (T)));
7715 Subp := First_Entity (Scope (T));
7718 while Present (Subp) loop
7719 if Is_Overloadable (Subp) then
7728 end Collect_Generic_Type_Ops;
7730 ---------------------------
7731 -- Is_Private_Overriding --
7732 ---------------------------
7734 function Is_Private_Overriding (Op : Entity_Id) return Boolean is
7735 Visible_Op : constant Entity_Id := Homonym (Op);
7738 return Present (Visible_Op)
7739 and then Scope (Op) = Scope (Visible_Op)
7740 and then not Comes_From_Source (Visible_Op)
7741 and then Alias (Visible_Op) = Op
7742 and then not Is_Hidden (Visible_Op);
7743 end Is_Private_Overriding;
7745 -----------------------------
7746 -- Valid_First_Argument_Of --
7747 -----------------------------
7749 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
7750 Typ : Entity_Id := Etype (First_Formal (Op));
7753 if Is_Concurrent_Type (Typ)
7754 and then Present (Corresponding_Record_Type (Typ))
7756 Typ := Corresponding_Record_Type (Typ);
7759 -- Simple case. Object may be a subtype of the tagged type or
7760 -- may be the corresponding record of a synchronized type.
7762 return Obj_Type = Typ
7763 or else Base_Type (Obj_Type) = Typ
7764 or else Corr_Type = Typ
7766 -- Prefix can be dereferenced
7769 (Is_Access_Type (Corr_Type)
7770 and then Designated_Type (Corr_Type) = Typ)
7772 -- Formal is an access parameter, for which the object
7773 -- can provide an access.
7776 (Ekind (Typ) = E_Anonymous_Access_Type
7778 Base_Type (Designated_Type (Typ)) = Base_Type (Corr_Type));
7779 end Valid_First_Argument_Of;
7781 -- Start of processing for Try_Primitive_Operation
7784 -- Look for subprograms in the list of primitive operations. The name
7785 -- must be identical, and the kind of call indicates the expected
7786 -- kind of operation (function or procedure). If the type is a
7787 -- (tagged) synchronized type, the primitive ops are attached to the
7788 -- corresponding record (base) type.
7790 if Is_Concurrent_Type (Obj_Type) then
7791 if Present (Corresponding_Record_Type (Obj_Type)) then
7792 Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
7793 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
7795 Corr_Type := Obj_Type;
7796 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
7799 elsif not Is_Generic_Type (Obj_Type) then
7800 Corr_Type := Obj_Type;
7801 Elmt := First_Elmt (Primitive_Operations (Obj_Type));
7804 Corr_Type := Obj_Type;
7805 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
7808 while Present (Elmt) loop
7809 Prim_Op := Node (Elmt);
7811 if Chars (Prim_Op) = Chars (Subprog)
7812 and then Present (First_Formal (Prim_Op))
7813 and then Valid_First_Argument_Of (Prim_Op)
7815 (Nkind (Call_Node) = N_Function_Call)
7816 = (Ekind (Prim_Op) = E_Function)
7818 -- Ada 2005 (AI-251): If this primitive operation corresponds
7819 -- with an immediate ancestor interface there is no need to add
7820 -- it to the list of interpretations; the corresponding aliased
7821 -- primitive is also in this list of primitive operations and
7822 -- will be used instead.
7824 if (Present (Interface_Alias (Prim_Op))
7825 and then Is_Ancestor (Find_Dispatching_Type
7826 (Alias (Prim_Op)), Corr_Type))
7828 -- Do not consider hidden primitives unless the type is in an
7829 -- open scope or we are within an instance, where visibility
7830 -- is known to be correct, or else if this is an overriding
7831 -- operation in the private part for an inherited operation.
7833 or else (Is_Hidden (Prim_Op)
7834 and then not Is_Immediately_Visible (Obj_Type)
7835 and then not In_Instance
7836 and then not Is_Private_Overriding (Prim_Op))
7841 Set_Etype (Call_Node, Any_Type);
7842 Set_Is_Overloaded (Call_Node, False);
7844 if No (Matching_Op) then
7845 Prim_Op_Ref := New_Reference_To (Prim_Op, Sloc (Subprog));
7846 Candidate := Prim_Op;
7848 Set_Parent (Call_Node, Parent (Node_To_Replace));
7850 Set_Name (Call_Node, Prim_Op_Ref);
7856 Report => Report_Error,
7858 Skip_First => True);
7860 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
7862 -- More than one interpretation, collect for subsequent
7863 -- disambiguation. If this is a procedure call and there
7864 -- is another match, report ambiguity now.
7870 Report => Report_Error,
7872 Skip_First => True);
7874 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
7875 and then Nkind (Call_Node) /= N_Function_Call
7877 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
7878 Report_Ambiguity (Matching_Op);
7879 Report_Ambiguity (Prim_Op);
7889 if Present (Matching_Op) then
7890 Set_Etype (Call_Node, Etype (Matching_Op));
7893 return Present (Matching_Op);
7894 end Try_Primitive_Operation;
7896 -- Start of processing for Try_Object_Operation
7899 Analyze_Expression (Obj);
7901 -- Analyze the actuals if node is known to be a subprogram call
7903 if Is_Subprg_Call and then N = Name (Parent (N)) then
7904 Actual := First (Parameter_Associations (Parent (N)));
7905 while Present (Actual) loop
7906 Analyze_Expression (Actual);
7911 -- Build a subprogram call node, using a copy of Obj as its first
7912 -- actual. This is a placeholder, to be replaced by an explicit
7913 -- dereference when needed.
7915 Transform_Object_Operation
7916 (Call_Node => New_Call_Node,
7917 Node_To_Replace => Node_To_Replace);
7919 Set_Etype (New_Call_Node, Any_Type);
7920 Set_Etype (Subprog, Any_Type);
7921 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
7923 if not Is_Overloaded (Obj) then
7924 Try_One_Prefix_Interpretation (Obj_Type);
7931 Get_First_Interp (Obj, I, It);
7932 while Present (It.Nam) loop
7933 Try_One_Prefix_Interpretation (It.Typ);
7934 Get_Next_Interp (I, It);
7939 if Etype (New_Call_Node) /= Any_Type then
7941 -- No need to complete the tree transformations if we are only
7942 -- searching for conflicting class-wide subprograms
7944 if CW_Test_Only then
7947 Complete_Object_Operation
7948 (Call_Node => New_Call_Node,
7949 Node_To_Replace => Node_To_Replace);
7953 elsif Present (Candidate) then
7955 -- The argument list is not type correct. Re-analyze with error
7956 -- reporting enabled, and use one of the possible candidates.
7957 -- In All_Errors_Mode, re-analyze all failed interpretations.
7959 if All_Errors_Mode then
7960 Report_Error := True;
7961 if Try_Primitive_Operation
7962 (Call_Node => New_Call_Node,
7963 Node_To_Replace => Node_To_Replace)
7966 Try_Class_Wide_Operation
7967 (Call_Node => New_Call_Node,
7968 Node_To_Replace => Node_To_Replace)
7975 (N => New_Call_Node,
7979 Skip_First => True);
7982 -- No need for further errors
7987 -- There was no candidate operation, so report it as an error
7988 -- in the caller: Analyze_Selected_Component.
7992 end Try_Object_Operation;
7998 procedure wpo (T : Entity_Id) is
8003 if not Is_Tagged_Type (T) then
8007 E := First_Elmt (Primitive_Operations (Base_Type (T)));
8008 while Present (E) loop
8010 Write_Int (Int (Op));
8011 Write_Str (" === ");
8012 Write_Name (Chars (Op));
8014 Write_Name (Chars (Scope (Op)));