1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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_Standard_Allocators_After_Elaboration, loop to
417 -- look at enclosing context, checking task case and main subprogram
422 while Present (P) loop
424 -- In both cases we need a handled sequence of statements, where
425 -- the occurrence of the allocator is within the statements.
427 if Nkind (P) = N_Handled_Sequence_Of_Statements
428 and then Is_List_Member (C)
429 and then List_Containing (C) = Statements (P)
431 -- Check for allocator within task body, this is a definite
432 -- violation of No_Allocators_After_Elaboration we can detect.
434 if Nkind (Original_Node (Parent (P))) = N_Task_Body then
436 (No_Standard_Allocators_After_Elaboration, N);
440 -- The other case is appearance in a subprogram body. This may
441 -- be a violation if this is a library level subprogram, and it
442 -- turns out to be used as the main program, but only the
443 -- binder knows that, so just record the occurrence.
445 if Nkind (Original_Node (Parent (P))) = N_Subprogram_Body
446 and then Nkind (Parent (Parent (P))) = N_Compilation_Unit
448 Set_Has_Allocator (Current_Sem_Unit);
457 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
458 -- any. The expected type for the name is any type. A non-overloading
459 -- rule then requires it to be of a type descended from
460 -- System.Storage_Pools.Subpools.Subpool_Handle.
462 -- This isn't exactly what the AI says, but it seems to be the right
463 -- rule. The AI should be fixed.???
466 Subpool : constant Node_Id := Subpool_Handle_Name (N);
469 if Present (Subpool) then
472 if Is_Overloaded (Subpool) then
473 Error_Msg_N ("ambiguous subpool handle", Subpool);
476 -- Check that Etype (Subpool) is descended from Subpool_Handle
482 -- Analyze the qualified expression or subtype indication
484 if Nkind (E) = N_Qualified_Expression then
485 Acc_Type := Create_Itype (E_Allocator_Type, N);
486 Set_Etype (Acc_Type, Acc_Type);
487 Find_Type (Subtype_Mark (E));
489 -- Analyze the qualified expression, and apply the name resolution
490 -- rule given in 4.7(3).
493 Type_Id := Etype (E);
494 Set_Directly_Designated_Type (Acc_Type, Type_Id);
496 Resolve (Expression (E), Type_Id);
498 -- Allocators generated by the build-in-place expansion mechanism
499 -- are explicitly marked as coming from source but do not need to be
500 -- checked for limited initialization. To exclude this case, ensure
501 -- that the parent of the allocator is a source node.
503 if Is_Limited_Type (Type_Id)
504 and then Comes_From_Source (N)
505 and then Comes_From_Source (Parent (N))
506 and then not In_Instance_Body
508 if not OK_For_Limited_Init (Type_Id, Expression (E)) then
509 Error_Msg_N ("initialization not allowed for limited types", N);
510 Explain_Limited_Type (Type_Id, N);
514 -- A qualified expression requires an exact match of the type,
515 -- class-wide matching is not allowed.
517 -- if Is_Class_Wide_Type (Type_Id)
518 -- and then Base_Type
519 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
521 -- Wrong_Type (Expression (E), Type_Id);
524 Check_Non_Static_Context (Expression (E));
526 -- We don't analyze the qualified expression itself because it's
527 -- part of the allocator
529 Set_Etype (E, Type_Id);
531 -- Case where allocator has a subtype indication
536 Base_Typ : Entity_Id;
539 -- If the allocator includes a N_Subtype_Indication then a
540 -- constraint is present, otherwise the node is a subtype mark.
541 -- Introduce an explicit subtype declaration into the tree
542 -- defining some anonymous subtype and rewrite the allocator to
543 -- use this subtype rather than the subtype indication.
545 -- It is important to introduce the explicit subtype declaration
546 -- so that the bounds of the subtype indication are attached to
547 -- the tree in case the allocator is inside a generic unit.
549 if Nkind (E) = N_Subtype_Indication then
551 -- A constraint is only allowed for a composite type in Ada
552 -- 95. In Ada 83, a constraint is also allowed for an
553 -- access-to-composite type, but the constraint is ignored.
555 Find_Type (Subtype_Mark (E));
556 Base_Typ := Entity (Subtype_Mark (E));
558 if Is_Elementary_Type (Base_Typ) then
559 if not (Ada_Version = Ada_83
560 and then Is_Access_Type (Base_Typ))
562 Error_Msg_N ("constraint not allowed here", E);
564 if Nkind (Constraint (E)) =
565 N_Index_Or_Discriminant_Constraint
567 Error_Msg_N -- CODEFIX
568 ("\if qualified expression was meant, " &
569 "use apostrophe", Constraint (E));
573 -- Get rid of the bogus constraint:
575 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
576 Analyze_Allocator (N);
579 -- Ada 2005, AI-363: if the designated type has a constrained
580 -- partial view, it cannot receive a discriminant constraint,
581 -- and the allocated object is unconstrained.
583 elsif Ada_Version >= Ada_2005
584 and then Effectively_Has_Constrained_Partial_View
586 Scop => Current_Scope)
589 ("constraint not allowed when type " &
590 "has a constrained partial view", Constraint (E));
593 if Expander_Active then
594 Def_Id := Make_Temporary (Loc, 'S');
597 Make_Subtype_Declaration (Loc,
598 Defining_Identifier => Def_Id,
599 Subtype_Indication => Relocate_Node (E)));
601 if Sav_Errs /= Serious_Errors_Detected
602 and then Nkind (Constraint (E)) =
603 N_Index_Or_Discriminant_Constraint
605 Error_Msg_N -- CODEFIX
606 ("if qualified expression was meant, " &
607 "use apostrophe!", Constraint (E));
610 E := New_Occurrence_Of (Def_Id, Loc);
611 Rewrite (Expression (N), E);
615 Type_Id := Process_Subtype (E, N);
616 Acc_Type := Create_Itype (E_Allocator_Type, N);
617 Set_Etype (Acc_Type, Acc_Type);
618 Set_Directly_Designated_Type (Acc_Type, Type_Id);
619 Check_Fully_Declared (Type_Id, N);
621 -- Ada 2005 (AI-231): If the designated type is itself an access
622 -- type that excludes null, its default initialization will
623 -- be a null object, and we can insert an unconditional raise
624 -- before the allocator.
626 -- Ada 2012 (AI-104): A not null indication here is altogether
629 if Can_Never_Be_Null (Type_Id) then
631 Not_Null_Check : constant Node_Id :=
632 Make_Raise_Constraint_Error (Sloc (E),
633 Reason => CE_Null_Not_Allowed);
636 if Expander_Active then
637 Insert_Action (N, Not_Null_Check);
638 Analyze (Not_Null_Check);
640 elsif Warn_On_Ada_2012_Compatibility then
642 ("null value not allowed here in Ada 2012?y?", E);
647 -- Check restriction against dynamically allocated protected
648 -- objects. Note that when limited aggregates are supported,
649 -- a similar test should be applied to an allocator with a
650 -- qualified expression ???
652 if Is_Protected_Type (Type_Id) then
653 Check_Restriction (No_Protected_Type_Allocators, N);
656 -- Check for missing initialization. Skip this check if we already
657 -- had errors on analyzing the allocator, since in that case these
658 -- are probably cascaded errors.
660 if Is_Indefinite_Subtype (Type_Id)
661 and then Serious_Errors_Detected = Sav_Errs
663 -- The build-in-place machinery may produce an allocator when
664 -- the designated type is indefinite but the underlying type is
665 -- not. In this case the unknown discriminants are meaningless
666 -- and should not trigger error messages. Check the parent node
667 -- because the allocator is marked as coming from source.
669 if Present (Underlying_Type (Type_Id))
670 and then not Is_Indefinite_Subtype (Underlying_Type (Type_Id))
671 and then not Comes_From_Source (Parent (N))
675 elsif Is_Class_Wide_Type (Type_Id) then
677 ("initialization required in class-wide allocation", N);
680 if Ada_Version < Ada_2005
681 and then Is_Limited_Type (Type_Id)
683 Error_Msg_N ("unconstrained allocation not allowed", N);
685 if Is_Array_Type (Type_Id) then
687 ("\constraint with array bounds required", N);
689 elsif Has_Unknown_Discriminants (Type_Id) then
692 else pragma Assert (Has_Discriminants (Type_Id));
694 ("\constraint with discriminant values required", N);
697 -- Limited Ada 2005 and general non-limited case
701 ("uninitialized unconstrained allocation not allowed",
704 if Is_Array_Type (Type_Id) then
706 ("\qualified expression or constraint with " &
707 "array bounds required", N);
709 elsif Has_Unknown_Discriminants (Type_Id) then
710 Error_Msg_N ("\qualified expression required", N);
712 else pragma Assert (Has_Discriminants (Type_Id));
714 ("\qualified expression or constraint with " &
715 "discriminant values required", N);
723 if Is_Abstract_Type (Type_Id) then
724 Error_Msg_N ("cannot allocate abstract object", E);
727 if Has_Task (Designated_Type (Acc_Type)) then
728 Check_Restriction (No_Tasking, N);
729 Check_Restriction (Max_Tasks, N);
730 Check_Restriction (No_Task_Allocators, N);
733 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
734 -- type is nested, and the designated type needs finalization. The rule
735 -- is conservative in that class-wide types need finalization.
737 if Needs_Finalization (Designated_Type (Acc_Type))
738 and then not Is_Library_Level_Entity (Acc_Type)
740 Check_Restriction (No_Nested_Finalization, N);
743 -- Check that an allocator of a nested access type doesn't create a
744 -- protected object when restriction No_Local_Protected_Objects applies.
745 -- We don't have an equivalent to Has_Task for protected types, so only
746 -- cases where the designated type itself is a protected type are
747 -- currently checked. ???
749 if Is_Protected_Type (Designated_Type (Acc_Type))
750 and then not Is_Library_Level_Entity (Acc_Type)
752 Check_Restriction (No_Local_Protected_Objects, N);
755 -- If the No_Streams restriction is set, check that the type of the
756 -- object is not, and does not contain, any subtype derived from
757 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
758 -- Has_Stream just for efficiency reasons. There is no point in
759 -- spending time on a Has_Stream check if the restriction is not set.
761 if Restriction_Check_Required (No_Streams) then
762 if Has_Stream (Designated_Type (Acc_Type)) then
763 Check_Restriction (No_Streams, N);
767 Set_Etype (N, Acc_Type);
769 if not Is_Library_Level_Entity (Acc_Type) then
770 Check_Restriction (No_Local_Allocators, N);
773 if Serious_Errors_Detected > Sav_Errs then
774 Set_Error_Posted (N);
775 Set_Etype (N, Any_Type);
777 end Analyze_Allocator;
779 ---------------------------
780 -- Analyze_Arithmetic_Op --
781 ---------------------------
783 procedure Analyze_Arithmetic_Op (N : Node_Id) is
784 L : constant Node_Id := Left_Opnd (N);
785 R : constant Node_Id := Right_Opnd (N);
789 Candidate_Type := Empty;
790 Analyze_Expression (L);
791 Analyze_Expression (R);
793 -- If the entity is already set, the node is the instantiation of a
794 -- generic node with a non-local reference, or was manufactured by a
795 -- call to Make_Op_xxx. In either case the entity is known to be valid,
796 -- and we do not need to collect interpretations, instead we just get
797 -- the single possible interpretation.
801 if Present (Op_Id) then
802 if Ekind (Op_Id) = E_Operator then
804 if Nkind_In (N, N_Op_Divide, N_Op_Mod, N_Op_Multiply, N_Op_Rem)
805 and then Treat_Fixed_As_Integer (N)
809 Set_Etype (N, Any_Type);
810 Find_Arithmetic_Types (L, R, Op_Id, N);
814 Set_Etype (N, Any_Type);
815 Add_One_Interp (N, Op_Id, Etype (Op_Id));
818 -- Entity is not already set, so we do need to collect interpretations
821 Op_Id := Get_Name_Entity_Id (Chars (N));
822 Set_Etype (N, Any_Type);
824 while Present (Op_Id) loop
825 if Ekind (Op_Id) = E_Operator
826 and then Present (Next_Entity (First_Entity (Op_Id)))
828 Find_Arithmetic_Types (L, R, Op_Id, N);
830 -- The following may seem superfluous, because an operator cannot
831 -- be generic, but this ignores the cleverness of the author of
834 elsif Is_Overloadable (Op_Id) then
835 Analyze_User_Defined_Binary_Op (N, Op_Id);
838 Op_Id := Homonym (Op_Id);
843 end Analyze_Arithmetic_Op;
849 -- Function, procedure, and entry calls are checked here. The Name in
850 -- the call may be overloaded. The actuals have been analyzed and may
851 -- themselves be overloaded. On exit from this procedure, the node N
852 -- may have zero, one or more interpretations. In the first case an
853 -- error message is produced. In the last case, the node is flagged
854 -- as overloaded and the interpretations are collected in All_Interp.
856 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
857 -- the type-checking is similar to that of other calls.
859 procedure Analyze_Call (N : Node_Id) is
860 Actuals : constant List_Id := Parameter_Associations (N);
865 Success : Boolean := False;
867 Deref : Boolean := False;
868 -- Flag indicates whether an interpretation of the prefix is a
869 -- parameterless call that returns an access_to_subprogram.
871 procedure Check_Mixed_Parameter_And_Named_Associations;
872 -- Check that parameter and named associations are not mixed. This is
873 -- a restriction in SPARK mode.
875 function Name_Denotes_Function return Boolean;
876 -- If the type of the name is an access to subprogram, this may be the
877 -- type of a name, or the return type of the function being called. If
878 -- the name is not an entity then it can denote a protected function.
879 -- Until we distinguish Etype from Return_Type, we must use this routine
880 -- to resolve the meaning of the name in the call.
882 procedure No_Interpretation;
883 -- Output error message when no valid interpretation exists
885 --------------------------------------------------
886 -- Check_Mixed_Parameter_And_Named_Associations --
887 --------------------------------------------------
889 procedure Check_Mixed_Parameter_And_Named_Associations is
891 Named_Seen : Boolean;
896 Actual := First (Actuals);
897 while Present (Actual) loop
898 case Nkind (Actual) is
899 when N_Parameter_Association =>
901 Check_SPARK_Restriction
902 ("named association cannot follow positional one",
912 end Check_Mixed_Parameter_And_Named_Associations;
914 ---------------------------
915 -- Name_Denotes_Function --
916 ---------------------------
918 function Name_Denotes_Function return Boolean is
920 if Is_Entity_Name (Nam) then
921 return Ekind (Entity (Nam)) = E_Function;
923 elsif Nkind (Nam) = N_Selected_Component then
924 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
929 end Name_Denotes_Function;
931 -----------------------
932 -- No_Interpretation --
933 -----------------------
935 procedure No_Interpretation is
936 L : constant Boolean := Is_List_Member (N);
937 K : constant Node_Kind := Nkind (Parent (N));
940 -- If the node is in a list whose parent is not an expression then it
941 -- must be an attempted procedure call.
943 if L and then K not in N_Subexpr then
944 if Ekind (Entity (Nam)) = E_Generic_Procedure then
946 ("must instantiate generic procedure& before call",
950 ("procedure or entry name expected", Nam);
953 -- Check for tasking cases where only an entry call will do
956 and then Nkind_In (K, N_Entry_Call_Alternative,
957 N_Triggering_Alternative)
959 Error_Msg_N ("entry name expected", Nam);
961 -- Otherwise give general error message
964 Error_Msg_N ("invalid prefix in call", Nam);
966 end No_Interpretation;
968 -- Start of processing for Analyze_Call
971 if Restriction_Check_Required (SPARK) then
972 Check_Mixed_Parameter_And_Named_Associations;
975 -- Initialize the type of the result of the call to the error type,
976 -- which will be reset if the type is successfully resolved.
978 Set_Etype (N, Any_Type);
982 if not Is_Overloaded (Nam) then
984 -- Only one interpretation to check
986 if Ekind (Etype (Nam)) = E_Subprogram_Type then
987 Nam_Ent := Etype (Nam);
989 -- If the prefix is an access_to_subprogram, this may be an indirect
990 -- call. This is the case if the name in the call is not an entity
991 -- name, or if it is a function name in the context of a procedure
992 -- call. In this latter case, we have a call to a parameterless
993 -- function that returns a pointer_to_procedure which is the entity
994 -- being called. Finally, F (X) may be a call to a parameterless
995 -- function that returns a pointer to a function with parameters.
997 elsif Is_Access_Type (Etype (Nam))
998 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
1000 (not Name_Denotes_Function
1001 or else Nkind (N) = N_Procedure_Call_Statement
1003 (Nkind (Parent (N)) /= N_Explicit_Dereference
1004 and then Is_Entity_Name (Nam)
1005 and then No (First_Formal (Entity (Nam)))
1006 and then Present (Actuals)))
1008 Nam_Ent := Designated_Type (Etype (Nam));
1009 Insert_Explicit_Dereference (Nam);
1011 -- Selected component case. Simple entry or protected operation,
1012 -- where the entry name is given by the selector name.
1014 elsif Nkind (Nam) = N_Selected_Component then
1015 Nam_Ent := Entity (Selector_Name (Nam));
1017 if not Ekind_In (Nam_Ent, E_Entry,
1022 Error_Msg_N ("name in call is not a callable entity", Nam);
1023 Set_Etype (N, Any_Type);
1027 -- If the name is an Indexed component, it can be a call to a member
1028 -- of an entry family. The prefix must be a selected component whose
1029 -- selector is the entry. Analyze_Procedure_Call normalizes several
1030 -- kinds of call into this form.
1032 elsif Nkind (Nam) = N_Indexed_Component then
1033 if Nkind (Prefix (Nam)) = N_Selected_Component then
1034 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
1036 Error_Msg_N ("name in call is not a callable entity", Nam);
1037 Set_Etype (N, Any_Type);
1041 elsif not Is_Entity_Name (Nam) then
1042 Error_Msg_N ("name in call is not a callable entity", Nam);
1043 Set_Etype (N, Any_Type);
1047 Nam_Ent := Entity (Nam);
1049 -- If no interpretations, give error message
1051 if not Is_Overloadable (Nam_Ent) then
1057 -- Operations generated for RACW stub types are called only through
1058 -- dispatching, and can never be the static interpretation of a call.
1060 if Is_RACW_Stub_Type_Operation (Nam_Ent) then
1065 Analyze_One_Call (N, Nam_Ent, True, Success);
1067 -- If this is an indirect call, the return type of the access_to
1068 -- subprogram may be an incomplete type. At the point of the call,
1069 -- use the full type if available, and at the same time update the
1070 -- return type of the access_to_subprogram.
1073 and then Nkind (Nam) = N_Explicit_Dereference
1074 and then Ekind (Etype (N)) = E_Incomplete_Type
1075 and then Present (Full_View (Etype (N)))
1077 Set_Etype (N, Full_View (Etype (N)));
1078 Set_Etype (Nam_Ent, Etype (N));
1082 -- An overloaded selected component must denote overloaded operations
1083 -- of a concurrent type. The interpretations are attached to the
1084 -- simple name of those operations.
1086 if Nkind (Nam) = N_Selected_Component then
1087 Nam := Selector_Name (Nam);
1090 Get_First_Interp (Nam, X, It);
1092 while Present (It.Nam) loop
1096 -- Name may be call that returns an access to subprogram, or more
1097 -- generally an overloaded expression one of whose interpretations
1098 -- yields an access to subprogram. If the name is an entity, we do
1099 -- not dereference, because the node is a call that returns the
1100 -- access type: note difference between f(x), where the call may
1101 -- return an access subprogram type, and f(x)(y), where the type
1102 -- returned by the call to f is implicitly dereferenced to analyze
1105 if Is_Access_Type (Nam_Ent) then
1106 Nam_Ent := Designated_Type (Nam_Ent);
1108 elsif Is_Access_Type (Etype (Nam_Ent))
1110 (not Is_Entity_Name (Nam)
1111 or else Nkind (N) = N_Procedure_Call_Statement)
1112 and then Ekind (Designated_Type (Etype (Nam_Ent)))
1115 Nam_Ent := Designated_Type (Etype (Nam_Ent));
1117 if Is_Entity_Name (Nam) then
1122 -- If the call has been rewritten from a prefixed call, the first
1123 -- parameter has been analyzed, but may need a subsequent
1124 -- dereference, so skip its analysis now.
1126 if N /= Original_Node (N)
1127 and then Nkind (Original_Node (N)) = Nkind (N)
1128 and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N)))
1129 and then Present (Parameter_Associations (N))
1130 and then Present (Etype (First (Parameter_Associations (N))))
1133 (N, Nam_Ent, False, Success, Skip_First => True);
1135 Analyze_One_Call (N, Nam_Ent, False, Success);
1138 -- If the interpretation succeeds, mark the proper type of the
1139 -- prefix (any valid candidate will do). If not, remove the
1140 -- candidate interpretation. This only needs to be done for
1141 -- overloaded protected operations, for other entities disambi-
1142 -- guation is done directly in Resolve.
1146 and then Nkind (Parent (N)) /= N_Explicit_Dereference
1148 Set_Entity (Nam, It.Nam);
1149 Insert_Explicit_Dereference (Nam);
1150 Set_Etype (Nam, Nam_Ent);
1153 Set_Etype (Nam, It.Typ);
1156 elsif Nkind_In (Name (N), N_Selected_Component,
1162 Get_Next_Interp (X, It);
1165 -- If the name is the result of a function call, it can only
1166 -- be a call to a function returning an access to subprogram.
1167 -- Insert explicit dereference.
1169 if Nkind (Nam) = N_Function_Call then
1170 Insert_Explicit_Dereference (Nam);
1173 if Etype (N) = Any_Type then
1175 -- None of the interpretations is compatible with the actuals
1177 Diagnose_Call (N, Nam);
1179 -- Special checks for uninstantiated put routines
1181 if Nkind (N) = N_Procedure_Call_Statement
1182 and then Is_Entity_Name (Nam)
1183 and then Chars (Nam) = Name_Put
1184 and then List_Length (Actuals) = 1
1187 Arg : constant Node_Id := First (Actuals);
1191 if Nkind (Arg) = N_Parameter_Association then
1192 Typ := Etype (Explicit_Actual_Parameter (Arg));
1197 if Is_Signed_Integer_Type (Typ) then
1199 ("possible missing instantiation of " &
1200 "'Text_'I'O.'Integer_'I'O!", Nam);
1202 elsif Is_Modular_Integer_Type (Typ) then
1204 ("possible missing instantiation of " &
1205 "'Text_'I'O.'Modular_'I'O!", Nam);
1207 elsif Is_Floating_Point_Type (Typ) then
1209 ("possible missing instantiation of " &
1210 "'Text_'I'O.'Float_'I'O!", Nam);
1212 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
1214 ("possible missing instantiation of " &
1215 "'Text_'I'O.'Fixed_'I'O!", Nam);
1217 elsif Is_Decimal_Fixed_Point_Type (Typ) then
1219 ("possible missing instantiation of " &
1220 "'Text_'I'O.'Decimal_'I'O!", Nam);
1222 elsif Is_Enumeration_Type (Typ) then
1224 ("possible missing instantiation of " &
1225 "'Text_'I'O.'Enumeration_'I'O!", Nam);
1230 elsif not Is_Overloaded (N)
1231 and then Is_Entity_Name (Nam)
1233 -- Resolution yields a single interpretation. Verify that the
1234 -- reference has capitalization consistent with the declaration.
1236 Set_Entity_With_Style_Check (Nam, Entity (Nam));
1237 Generate_Reference (Entity (Nam), Nam);
1239 Set_Etype (Nam, Etype (Entity (Nam)));
1241 Remove_Abstract_Operations (N);
1248 -----------------------------
1249 -- Analyze_Case_Expression --
1250 -----------------------------
1252 procedure Analyze_Case_Expression (N : Node_Id) is
1253 function Has_Static_Predicate (Subtyp : Entity_Id) return Boolean;
1254 -- Determine whether subtype Subtyp has aspect Static_Predicate
1256 procedure Non_Static_Choice_Error (Choice : Node_Id);
1257 -- Error routine invoked by the generic instantiation below when
1258 -- the case expression has a non static choice.
1260 package Case_Choices_Processing is new
1261 Generic_Choices_Processing
1262 (Get_Alternatives => Alternatives,
1263 Get_Choices => Discrete_Choices,
1264 Process_Empty_Choice => No_OP,
1265 Process_Non_Static_Choice => Non_Static_Choice_Error,
1266 Process_Associated_Node => No_OP);
1267 use Case_Choices_Processing;
1269 --------------------------
1270 -- Has_Static_Predicate --
1271 --------------------------
1273 function Has_Static_Predicate (Subtyp : Entity_Id) return Boolean is
1277 Item := First_Rep_Item (Subtyp);
1278 while Present (Item) loop
1279 if Nkind (Item) = N_Aspect_Specification
1280 and then Chars (Identifier (Item)) = Name_Static_Predicate
1285 Next_Rep_Item (Item);
1289 end Has_Static_Predicate;
1291 -----------------------------
1292 -- Non_Static_Choice_Error --
1293 -----------------------------
1295 procedure Non_Static_Choice_Error (Choice : Node_Id) is
1297 Flag_Non_Static_Expr
1298 ("choice given in case expression is not static!", Choice);
1299 end Non_Static_Choice_Error;
1303 Expr : constant Node_Id := Expression (N);
1304 FirstX : constant Node_Id := Expression (First (Alternatives (N)));
1306 Exp_Type : Entity_Id;
1307 Exp_Btype : Entity_Id;
1309 Dont_Care : Boolean;
1310 Others_Present : Boolean;
1312 -- Start of processing for Analyze_Case_Expression
1315 if Comes_From_Source (N) then
1316 Check_Compiler_Unit (N);
1319 Analyze_And_Resolve (Expr, Any_Discrete);
1320 Check_Unset_Reference (Expr);
1321 Exp_Type := Etype (Expr);
1322 Exp_Btype := Base_Type (Exp_Type);
1324 Alt := First (Alternatives (N));
1325 while Present (Alt) loop
1326 Analyze (Expression (Alt));
1330 if not Is_Overloaded (FirstX) then
1331 Set_Etype (N, Etype (FirstX));
1339 Set_Etype (N, Any_Type);
1341 Get_First_Interp (FirstX, I, It);
1342 while Present (It.Nam) loop
1344 -- For each interpretation of the first expression, we only
1345 -- add the interpretation if every other expression in the
1346 -- case expression alternatives has a compatible type.
1348 Alt := Next (First (Alternatives (N)));
1349 while Present (Alt) loop
1350 exit when not Has_Compatible_Type (Expression (Alt), It.Typ);
1355 Add_One_Interp (N, It.Typ, It.Typ);
1358 Get_Next_Interp (I, It);
1363 Exp_Btype := Base_Type (Exp_Type);
1365 -- The expression must be of a discrete type which must be determinable
1366 -- independently of the context in which the expression occurs, but
1367 -- using the fact that the expression must be of a discrete type.
1368 -- Moreover, the type this expression must not be a character literal
1369 -- (which is always ambiguous).
1371 -- If error already reported by Resolve, nothing more to do
1373 if Exp_Btype = Any_Discrete
1374 or else Exp_Btype = Any_Type
1378 elsif Exp_Btype = Any_Character then
1380 ("character literal as case expression is ambiguous", Expr);
1384 -- If the case expression is a formal object of mode in out, then
1385 -- treat it as having a nonstatic subtype by forcing use of the base
1386 -- type (which has to get passed to Check_Case_Choices below). Also
1387 -- use base type when the case expression is parenthesized.
1389 if Paren_Count (Expr) > 0
1390 or else (Is_Entity_Name (Expr)
1391 and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter)
1393 Exp_Type := Exp_Btype;
1396 -- The case expression alternatives cover the range of a static subtype
1397 -- subject to aspect Static_Predicate. Do not check the choices when the
1398 -- case expression has not been fully analyzed yet because this may lead
1401 if Is_Static_Subtype (Exp_Type)
1402 and then Has_Static_Predicate (Exp_Type)
1403 and then In_Spec_Expression
1407 -- Call instantiated Analyze_Choices which does the rest of the work
1410 Analyze_Choices (N, Exp_Type, Dont_Care, Others_Present);
1413 if Exp_Type = Universal_Integer and then not Others_Present then
1415 ("case on universal integer requires OTHERS choice", Expr);
1417 end Analyze_Case_Expression;
1419 ---------------------------
1420 -- Analyze_Comparison_Op --
1421 ---------------------------
1423 procedure Analyze_Comparison_Op (N : Node_Id) is
1424 L : constant Node_Id := Left_Opnd (N);
1425 R : constant Node_Id := Right_Opnd (N);
1426 Op_Id : Entity_Id := Entity (N);
1429 Set_Etype (N, Any_Type);
1430 Candidate_Type := Empty;
1432 Analyze_Expression (L);
1433 Analyze_Expression (R);
1435 if Present (Op_Id) then
1436 if Ekind (Op_Id) = E_Operator then
1437 Find_Comparison_Types (L, R, Op_Id, N);
1439 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1442 if Is_Overloaded (L) then
1443 Set_Etype (L, Intersect_Types (L, R));
1447 Op_Id := Get_Name_Entity_Id (Chars (N));
1448 while Present (Op_Id) loop
1449 if Ekind (Op_Id) = E_Operator then
1450 Find_Comparison_Types (L, R, Op_Id, N);
1452 Analyze_User_Defined_Binary_Op (N, Op_Id);
1455 Op_Id := Homonym (Op_Id);
1460 end Analyze_Comparison_Op;
1462 ---------------------------
1463 -- Analyze_Concatenation --
1464 ---------------------------
1466 procedure Analyze_Concatenation (N : Node_Id) is
1468 -- We wish to avoid deep recursion, because concatenations are often
1469 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1470 -- operands nonrecursively until we find something that is not a
1471 -- concatenation (A in this case), or has already been analyzed. We
1472 -- analyze that, and then walk back up the tree following Parent
1473 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1474 -- work at each level. The Parent pointers allow us to avoid recursion,
1475 -- and thus avoid running out of memory.
1481 Candidate_Type := Empty;
1483 -- The following code is equivalent to:
1485 -- Set_Etype (N, Any_Type);
1486 -- Analyze_Expression (Left_Opnd (N));
1487 -- Analyze_Concatenation_Rest (N);
1489 -- where the Analyze_Expression call recurses back here if the left
1490 -- operand is a concatenation.
1492 -- Walk down left operands
1495 Set_Etype (NN, Any_Type);
1496 L := Left_Opnd (NN);
1497 exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
1501 -- Now (given the above example) NN is A&B and L is A
1503 -- First analyze L ...
1505 Analyze_Expression (L);
1507 -- ... then walk NN back up until we reach N (where we started), calling
1508 -- Analyze_Concatenation_Rest along the way.
1511 Analyze_Concatenation_Rest (NN);
1515 end Analyze_Concatenation;
1517 --------------------------------
1518 -- Analyze_Concatenation_Rest --
1519 --------------------------------
1521 -- If the only one-dimensional array type in scope is String,
1522 -- this is the resulting type of the operation. Otherwise there
1523 -- will be a concatenation operation defined for each user-defined
1524 -- one-dimensional array.
1526 procedure Analyze_Concatenation_Rest (N : Node_Id) is
1527 L : constant Node_Id := Left_Opnd (N);
1528 R : constant Node_Id := Right_Opnd (N);
1529 Op_Id : Entity_Id := Entity (N);
1534 Analyze_Expression (R);
1536 -- If the entity is present, the node appears in an instance, and
1537 -- denotes a predefined concatenation operation. The resulting type is
1538 -- obtained from the arguments when possible. If the arguments are
1539 -- aggregates, the array type and the concatenation type must be
1542 if Present (Op_Id) then
1543 if Ekind (Op_Id) = E_Operator then
1544 LT := Base_Type (Etype (L));
1545 RT := Base_Type (Etype (R));
1547 if Is_Array_Type (LT)
1548 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1550 Add_One_Interp (N, Op_Id, LT);
1552 elsif Is_Array_Type (RT)
1553 and then LT = Base_Type (Component_Type (RT))
1555 Add_One_Interp (N, Op_Id, RT);
1557 -- If one operand is a string type or a user-defined array type,
1558 -- and the other is a literal, result is of the specific type.
1561 (Root_Type (LT) = Standard_String
1562 or else Scope (LT) /= Standard_Standard)
1563 and then Etype (R) = Any_String
1565 Add_One_Interp (N, Op_Id, LT);
1568 (Root_Type (RT) = Standard_String
1569 or else Scope (RT) /= Standard_Standard)
1570 and then Etype (L) = Any_String
1572 Add_One_Interp (N, Op_Id, RT);
1574 elsif not Is_Generic_Type (Etype (Op_Id)) then
1575 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1578 -- Type and its operations must be visible
1580 Set_Entity (N, Empty);
1581 Analyze_Concatenation (N);
1585 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1589 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1590 while Present (Op_Id) loop
1591 if Ekind (Op_Id) = E_Operator then
1593 -- Do not consider operators declared in dead code, they can
1594 -- not be part of the resolution.
1596 if Is_Eliminated (Op_Id) then
1599 Find_Concatenation_Types (L, R, Op_Id, N);
1603 Analyze_User_Defined_Binary_Op (N, Op_Id);
1606 Op_Id := Homonym (Op_Id);
1611 end Analyze_Concatenation_Rest;
1613 -------------------------
1614 -- Analyze_Equality_Op --
1615 -------------------------
1617 procedure Analyze_Equality_Op (N : Node_Id) is
1618 Loc : constant Source_Ptr := Sloc (N);
1619 L : constant Node_Id := Left_Opnd (N);
1620 R : constant Node_Id := Right_Opnd (N);
1624 Set_Etype (N, Any_Type);
1625 Candidate_Type := Empty;
1627 Analyze_Expression (L);
1628 Analyze_Expression (R);
1630 -- If the entity is set, the node is a generic instance with a non-local
1631 -- reference to the predefined operator or to a user-defined function.
1632 -- It can also be an inequality that is expanded into the negation of a
1633 -- call to a user-defined equality operator.
1635 -- For the predefined case, the result is Boolean, regardless of the
1636 -- type of the operands. The operands may even be limited, if they are
1637 -- generic actuals. If they are overloaded, label the left argument with
1638 -- the common type that must be present, or with the type of the formal
1639 -- of the user-defined function.
1641 if Present (Entity (N)) then
1642 Op_Id := Entity (N);
1644 if Ekind (Op_Id) = E_Operator then
1645 Add_One_Interp (N, Op_Id, Standard_Boolean);
1647 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1650 if Is_Overloaded (L) then
1651 if Ekind (Op_Id) = E_Operator then
1652 Set_Etype (L, Intersect_Types (L, R));
1654 Set_Etype (L, Etype (First_Formal (Op_Id)));
1659 Op_Id := Get_Name_Entity_Id (Chars (N));
1660 while Present (Op_Id) loop
1661 if Ekind (Op_Id) = E_Operator then
1662 Find_Equality_Types (L, R, Op_Id, N);
1664 Analyze_User_Defined_Binary_Op (N, Op_Id);
1667 Op_Id := Homonym (Op_Id);
1671 -- If there was no match, and the operator is inequality, this may
1672 -- be a case where inequality has not been made explicit, as for
1673 -- tagged types. Analyze the node as the negation of an equality
1674 -- operation. This cannot be done earlier, because before analysis
1675 -- we cannot rule out the presence of an explicit inequality.
1677 if Etype (N) = Any_Type
1678 and then Nkind (N) = N_Op_Ne
1680 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1681 while Present (Op_Id) loop
1682 if Ekind (Op_Id) = E_Operator then
1683 Find_Equality_Types (L, R, Op_Id, N);
1685 Analyze_User_Defined_Binary_Op (N, Op_Id);
1688 Op_Id := Homonym (Op_Id);
1691 if Etype (N) /= Any_Type then
1692 Op_Id := Entity (N);
1698 Left_Opnd => Left_Opnd (N),
1699 Right_Opnd => Right_Opnd (N))));
1701 Set_Entity (Right_Opnd (N), Op_Id);
1707 end Analyze_Equality_Op;
1709 ----------------------------------
1710 -- Analyze_Explicit_Dereference --
1711 ----------------------------------
1713 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1714 Loc : constant Source_Ptr := Sloc (N);
1715 P : constant Node_Id := Prefix (N);
1721 function Is_Function_Type return Boolean;
1722 -- Check whether node may be interpreted as an implicit function call
1724 ----------------------
1725 -- Is_Function_Type --
1726 ----------------------
1728 function Is_Function_Type return Boolean is
1733 if not Is_Overloaded (N) then
1734 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1735 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1738 Get_First_Interp (N, I, It);
1739 while Present (It.Nam) loop
1740 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1741 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1746 Get_Next_Interp (I, It);
1751 end Is_Function_Type;
1753 -- Start of processing for Analyze_Explicit_Dereference
1756 -- If source node, check SPARK restriction. We guard this with the
1757 -- source node check, because ???
1759 if Comes_From_Source (N) then
1760 Check_SPARK_Restriction ("explicit dereference is not allowed", N);
1763 -- In formal verification mode, keep track of all reads and writes
1764 -- through explicit dereferences.
1767 Alfa.Generate_Dereference (N);
1771 Set_Etype (N, Any_Type);
1773 -- Test for remote access to subprogram type, and if so return
1774 -- after rewriting the original tree.
1776 if Remote_AST_E_Dereference (P) then
1780 -- Normal processing for other than remote access to subprogram type
1782 if not Is_Overloaded (P) then
1783 if Is_Access_Type (Etype (P)) then
1785 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
1786 -- avoid other problems caused by the Private_Subtype and it is
1787 -- safe to go to the Base_Type because this is the same as
1788 -- converting the access value to its Base_Type.
1791 DT : Entity_Id := Designated_Type (Etype (P));
1794 if Ekind (DT) = E_Private_Subtype
1795 and then Is_For_Access_Subtype (DT)
1797 DT := Base_Type (DT);
1800 -- An explicit dereference is a legal occurrence of an
1801 -- incomplete type imported through a limited_with clause,
1802 -- if the full view is visible.
1804 if From_With_Type (DT)
1805 and then not From_With_Type (Scope (DT))
1807 (Is_Immediately_Visible (Scope (DT))
1809 (Is_Child_Unit (Scope (DT))
1810 and then Is_Visible_Lib_Unit (Scope (DT))))
1812 Set_Etype (N, Available_View (DT));
1819 elsif Etype (P) /= Any_Type then
1820 Error_Msg_N ("prefix of dereference must be an access type", N);
1825 Get_First_Interp (P, I, It);
1826 while Present (It.Nam) loop
1829 if Is_Access_Type (T) then
1830 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1833 Get_Next_Interp (I, It);
1836 -- Error if no interpretation of the prefix has an access type
1838 if Etype (N) = Any_Type then
1840 ("access type required in prefix of explicit dereference", P);
1841 Set_Etype (N, Any_Type);
1847 and then Nkind (Parent (N)) /= N_Indexed_Component
1849 and then (Nkind (Parent (N)) /= N_Function_Call
1850 or else N /= Name (Parent (N)))
1852 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1853 or else N /= Name (Parent (N)))
1855 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1856 and then (Nkind (Parent (N)) /= N_Attribute_Reference
1858 (Attribute_Name (Parent (N)) /= Name_Address
1860 Attribute_Name (Parent (N)) /= Name_Access))
1862 -- Name is a function call with no actuals, in a context that
1863 -- requires deproceduring (including as an actual in an enclosing
1864 -- function or procedure call). There are some pathological cases
1865 -- where the prefix might include functions that return access to
1866 -- subprograms and others that return a regular type. Disambiguation
1867 -- of those has to take place in Resolve.
1870 Make_Function_Call (Loc,
1871 Name => Make_Explicit_Dereference (Loc, P),
1872 Parameter_Associations => New_List);
1874 -- If the prefix is overloaded, remove operations that have formals,
1875 -- we know that this is a parameterless call.
1877 if Is_Overloaded (P) then
1878 Get_First_Interp (P, I, It);
1879 while Present (It.Nam) loop
1882 if No (First_Formal (Base_Type (Designated_Type (T)))) then
1888 Get_Next_Interp (I, It);
1895 elsif not Is_Function_Type
1896 and then Is_Overloaded (N)
1898 -- The prefix may include access to subprograms and other access
1899 -- types. If the context selects the interpretation that is a
1900 -- function call (not a procedure call) we cannot rewrite the node
1901 -- yet, but we include the result of the call interpretation.
1903 Get_First_Interp (N, I, It);
1904 while Present (It.Nam) loop
1905 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
1906 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
1907 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
1909 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
1912 Get_Next_Interp (I, It);
1916 -- A value of remote access-to-class-wide must not be dereferenced
1919 Validate_Remote_Access_To_Class_Wide_Type (N);
1920 end Analyze_Explicit_Dereference;
1922 ------------------------
1923 -- Analyze_Expression --
1924 ------------------------
1926 procedure Analyze_Expression (N : Node_Id) is
1929 Check_Parameterless_Call (N);
1930 end Analyze_Expression;
1932 -------------------------------------
1933 -- Analyze_Expression_With_Actions --
1934 -------------------------------------
1936 procedure Analyze_Expression_With_Actions (N : Node_Id) is
1940 A := First (Actions (N));
1941 while Present (A) loop
1946 -- We currently hijack Expression_With_Actions with a VOID type and
1947 -- a NULL statement in the Expression. This will ultimately be replaced
1948 -- by a proper separate N_Compound_Statement node, at which point the
1949 -- test below can go away???
1951 if Nkind (Expression (N)) = N_Null_Statement then
1952 Set_Etype (N, Standard_Void_Type);
1954 Analyze_Expression (Expression (N));
1955 Set_Etype (N, Etype (Expression (N)));
1957 end Analyze_Expression_With_Actions;
1959 ---------------------------
1960 -- Analyze_If_Expression --
1961 ---------------------------
1963 procedure Analyze_If_Expression (N : Node_Id) is
1964 Condition : constant Node_Id := First (Expressions (N));
1965 Then_Expr : constant Node_Id := Next (Condition);
1966 Else_Expr : Node_Id;
1969 -- Defend against error of missing expressions from previous error
1971 if No (Then_Expr) then
1972 Check_Error_Detected;
1976 Check_SPARK_Restriction ("if expression is not allowed", N);
1978 Else_Expr := Next (Then_Expr);
1980 if Comes_From_Source (N) then
1981 Check_Compiler_Unit (N);
1984 Analyze_Expression (Condition);
1985 Analyze_Expression (Then_Expr);
1987 if Present (Else_Expr) then
1988 Analyze_Expression (Else_Expr);
1991 -- If then expression not overloaded, then that decides the type
1993 if not Is_Overloaded (Then_Expr) then
1994 Set_Etype (N, Etype (Then_Expr));
1996 -- Case where then expression is overloaded
2004 Set_Etype (N, Any_Type);
2006 -- Shouldn't the following statement be down in the ELSE of the
2007 -- following loop? ???
2009 Get_First_Interp (Then_Expr, I, It);
2011 -- if no Else_Expression the conditional must be boolean
2013 if No (Else_Expr) then
2014 Set_Etype (N, Standard_Boolean);
2016 -- Else_Expression Present. For each possible intepretation of
2017 -- the Then_Expression, add it only if the Else_Expression has
2018 -- a compatible type.
2021 while Present (It.Nam) loop
2022 if Has_Compatible_Type (Else_Expr, It.Typ) then
2023 Add_One_Interp (N, It.Typ, It.Typ);
2026 Get_Next_Interp (I, It);
2031 end Analyze_If_Expression;
2033 ------------------------------------
2034 -- Analyze_Indexed_Component_Form --
2035 ------------------------------------
2037 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
2038 P : constant Node_Id := Prefix (N);
2039 Exprs : constant List_Id := Expressions (N);
2045 procedure Process_Function_Call;
2046 -- Prefix in indexed component form is an overloadable entity,
2047 -- so the node is a function call. Reformat it as such.
2049 procedure Process_Indexed_Component;
2050 -- Prefix in indexed component form is actually an indexed component.
2051 -- This routine processes it, knowing that the prefix is already
2054 procedure Process_Indexed_Component_Or_Slice;
2055 -- An indexed component with a single index may designate a slice if
2056 -- the index is a subtype mark. This routine disambiguates these two
2057 -- cases by resolving the prefix to see if it is a subtype mark.
2059 procedure Process_Overloaded_Indexed_Component;
2060 -- If the prefix of an indexed component is overloaded, the proper
2061 -- interpretation is selected by the index types and the context.
2063 ---------------------------
2064 -- Process_Function_Call --
2065 ---------------------------
2067 procedure Process_Function_Call is
2071 Change_Node (N, N_Function_Call);
2073 Set_Parameter_Associations (N, Exprs);
2075 -- Analyze actuals prior to analyzing the call itself
2077 Actual := First (Parameter_Associations (N));
2078 while Present (Actual) loop
2080 Check_Parameterless_Call (Actual);
2082 -- Move to next actual. Note that we use Next, not Next_Actual
2083 -- here. The reason for this is a bit subtle. If a function call
2084 -- includes named associations, the parser recognizes the node as
2085 -- a call, and it is analyzed as such. If all associations are
2086 -- positional, the parser builds an indexed_component node, and
2087 -- it is only after analysis of the prefix that the construct
2088 -- is recognized as a call, in which case Process_Function_Call
2089 -- rewrites the node and analyzes the actuals. If the list of
2090 -- actuals is malformed, the parser may leave the node as an
2091 -- indexed component (despite the presence of named associations).
2092 -- The iterator Next_Actual is equivalent to Next if the list is
2093 -- positional, but follows the normalized chain of actuals when
2094 -- named associations are present. In this case normalization has
2095 -- not taken place, and actuals remain unanalyzed, which leads to
2096 -- subsequent crashes or loops if there is an attempt to continue
2097 -- analysis of the program.
2103 end Process_Function_Call;
2105 -------------------------------
2106 -- Process_Indexed_Component --
2107 -------------------------------
2109 procedure Process_Indexed_Component is
2111 Array_Type : Entity_Id;
2113 Pent : Entity_Id := Empty;
2116 Exp := First (Exprs);
2118 if Is_Overloaded (P) then
2119 Process_Overloaded_Indexed_Component;
2122 Array_Type := Etype (P);
2124 if Is_Entity_Name (P) then
2126 elsif Nkind (P) = N_Selected_Component
2127 and then Is_Entity_Name (Selector_Name (P))
2129 Pent := Entity (Selector_Name (P));
2132 -- Prefix must be appropriate for an array type, taking into
2133 -- account a possible implicit dereference.
2135 if Is_Access_Type (Array_Type) then
2137 (Warn_On_Dereference, "?d?implicit dereference", N);
2138 Array_Type := Process_Implicit_Dereference_Prefix (Pent, P);
2141 if Is_Array_Type (Array_Type) then
2144 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
2146 Set_Etype (N, Any_Type);
2148 if not Has_Compatible_Type
2149 (Exp, Entry_Index_Type (Pent))
2151 Error_Msg_N ("invalid index type in entry name", N);
2153 elsif Present (Next (Exp)) then
2154 Error_Msg_N ("too many subscripts in entry reference", N);
2157 Set_Etype (N, Etype (P));
2162 elsif Is_Record_Type (Array_Type)
2163 and then Remote_AST_I_Dereference (P)
2167 elsif Try_Container_Indexing (N, P, Exprs) then
2170 elsif Array_Type = Any_Type then
2171 Set_Etype (N, Any_Type);
2173 -- In most cases the analysis of the prefix will have emitted
2174 -- an error already, but if the prefix may be interpreted as a
2175 -- call in prefixed notation, the report is left to the caller.
2176 -- To prevent cascaded errors, report only if no previous ones.
2178 if Serious_Errors_Detected = 0 then
2179 Error_Msg_N ("invalid prefix in indexed component", P);
2181 if Nkind (P) = N_Expanded_Name then
2182 Error_Msg_NE ("\& is not visible", P, Selector_Name (P));
2188 -- Here we definitely have a bad indexing
2191 if Nkind (Parent (N)) = N_Requeue_Statement
2192 and then Present (Pent) and then Ekind (Pent) = E_Entry
2195 ("REQUEUE does not permit parameters", First (Exprs));
2197 elsif Is_Entity_Name (P)
2198 and then Etype (P) = Standard_Void_Type
2200 Error_Msg_NE ("incorrect use of&", P, Entity (P));
2203 Error_Msg_N ("array type required in indexed component", P);
2206 Set_Etype (N, Any_Type);
2210 Index := First_Index (Array_Type);
2211 while Present (Index) and then Present (Exp) loop
2212 if not Has_Compatible_Type (Exp, Etype (Index)) then
2213 Wrong_Type (Exp, Etype (Index));
2214 Set_Etype (N, Any_Type);
2222 Set_Etype (N, Component_Type (Array_Type));
2223 Check_Implicit_Dereference (N, Etype (N));
2225 if Present (Index) then
2227 ("too few subscripts in array reference", First (Exprs));
2229 elsif Present (Exp) then
2230 Error_Msg_N ("too many subscripts in array reference", Exp);
2233 end Process_Indexed_Component;
2235 ----------------------------------------
2236 -- Process_Indexed_Component_Or_Slice --
2237 ----------------------------------------
2239 procedure Process_Indexed_Component_Or_Slice is
2241 Exp := First (Exprs);
2242 while Present (Exp) loop
2243 Analyze_Expression (Exp);
2247 Exp := First (Exprs);
2249 -- If one index is present, and it is a subtype name, then the
2250 -- node denotes a slice (note that the case of an explicit range
2251 -- for a slice was already built as an N_Slice node in the first
2252 -- place, so that case is not handled here).
2254 -- We use a replace rather than a rewrite here because this is one
2255 -- of the cases in which the tree built by the parser is plain wrong.
2258 and then Is_Entity_Name (Exp)
2259 and then Is_Type (Entity (Exp))
2262 Make_Slice (Sloc (N),
2264 Discrete_Range => New_Copy (Exp)));
2267 -- Otherwise (more than one index present, or single index is not
2268 -- a subtype name), then we have the indexed component case.
2271 Process_Indexed_Component;
2273 end Process_Indexed_Component_Or_Slice;
2275 ------------------------------------------
2276 -- Process_Overloaded_Indexed_Component --
2277 ------------------------------------------
2279 procedure Process_Overloaded_Indexed_Component is
2288 Set_Etype (N, Any_Type);
2290 Get_First_Interp (P, I, It);
2291 while Present (It.Nam) loop
2294 if Is_Access_Type (Typ) then
2295 Typ := Designated_Type (Typ);
2297 (Warn_On_Dereference, "?d?implicit dereference", N);
2300 if Is_Array_Type (Typ) then
2302 -- Got a candidate: verify that index types are compatible
2304 Index := First_Index (Typ);
2306 Exp := First (Exprs);
2307 while Present (Index) and then Present (Exp) loop
2308 if Has_Compatible_Type (Exp, Etype (Index)) then
2320 if Found and then No (Index) and then No (Exp) then
2322 CT : constant Entity_Id :=
2323 Base_Type (Component_Type (Typ));
2325 Add_One_Interp (N, CT, CT);
2326 Check_Implicit_Dereference (N, CT);
2330 elsif Try_Container_Indexing (N, P, Exprs) then
2335 Get_Next_Interp (I, It);
2338 if Etype (N) = Any_Type then
2339 Error_Msg_N ("no legal interpretation for indexed component", N);
2340 Set_Is_Overloaded (N, False);
2344 end Process_Overloaded_Indexed_Component;
2346 -- Start of processing for Analyze_Indexed_Component_Form
2349 -- Get name of array, function or type
2353 if Nkind (N) in N_Subprogram_Call then
2355 -- If P is an explicit dereference whose prefix is of a
2356 -- remote access-to-subprogram type, then N has already
2357 -- been rewritten as a subprogram call and analyzed.
2362 pragma Assert (Nkind (N) = N_Indexed_Component);
2364 P_T := Base_Type (Etype (P));
2366 if Is_Entity_Name (P) and then Present (Entity (P)) then
2369 if Is_Type (U_N) then
2371 -- Reformat node as a type conversion
2373 E := Remove_Head (Exprs);
2375 if Present (First (Exprs)) then
2377 ("argument of type conversion must be single expression", N);
2380 Change_Node (N, N_Type_Conversion);
2381 Set_Subtype_Mark (N, P);
2383 Set_Expression (N, E);
2385 -- After changing the node, call for the specific Analysis
2386 -- routine directly, to avoid a double call to the expander.
2388 Analyze_Type_Conversion (N);
2392 if Is_Overloadable (U_N) then
2393 Process_Function_Call;
2395 elsif Ekind (Etype (P)) = E_Subprogram_Type
2396 or else (Is_Access_Type (Etype (P))
2398 Ekind (Designated_Type (Etype (P))) =
2401 -- Call to access_to-subprogram with possible implicit dereference
2403 Process_Function_Call;
2405 elsif Is_Generic_Subprogram (U_N) then
2407 -- A common beginner's (or C++ templates fan) error
2409 Error_Msg_N ("generic subprogram cannot be called", N);
2410 Set_Etype (N, Any_Type);
2414 Process_Indexed_Component_Or_Slice;
2417 -- If not an entity name, prefix is an expression that may denote
2418 -- an array or an access-to-subprogram.
2421 if Ekind (P_T) = E_Subprogram_Type
2422 or else (Is_Access_Type (P_T)
2424 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
2426 Process_Function_Call;
2428 elsif Nkind (P) = N_Selected_Component
2429 and then Is_Overloadable (Entity (Selector_Name (P)))
2431 Process_Function_Call;
2434 -- Indexed component, slice, or a call to a member of a family
2435 -- entry, which will be converted to an entry call later.
2437 Process_Indexed_Component_Or_Slice;
2441 Analyze_Dimension (N);
2442 end Analyze_Indexed_Component_Form;
2444 ------------------------
2445 -- Analyze_Logical_Op --
2446 ------------------------
2448 procedure Analyze_Logical_Op (N : Node_Id) is
2449 L : constant Node_Id := Left_Opnd (N);
2450 R : constant Node_Id := Right_Opnd (N);
2451 Op_Id : Entity_Id := Entity (N);
2454 Set_Etype (N, Any_Type);
2455 Candidate_Type := Empty;
2457 Analyze_Expression (L);
2458 Analyze_Expression (R);
2460 if Present (Op_Id) then
2462 if Ekind (Op_Id) = E_Operator then
2463 Find_Boolean_Types (L, R, Op_Id, N);
2465 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2469 Op_Id := Get_Name_Entity_Id (Chars (N));
2470 while Present (Op_Id) loop
2471 if Ekind (Op_Id) = E_Operator then
2472 Find_Boolean_Types (L, R, Op_Id, N);
2474 Analyze_User_Defined_Binary_Op (N, Op_Id);
2477 Op_Id := Homonym (Op_Id);
2482 end Analyze_Logical_Op;
2484 ---------------------------
2485 -- Analyze_Membership_Op --
2486 ---------------------------
2488 procedure Analyze_Membership_Op (N : Node_Id) is
2489 Loc : constant Source_Ptr := Sloc (N);
2490 L : constant Node_Id := Left_Opnd (N);
2491 R : constant Node_Id := Right_Opnd (N);
2493 Index : Interp_Index;
2495 Found : Boolean := False;
2499 procedure Try_One_Interp (T1 : Entity_Id);
2500 -- Routine to try one proposed interpretation. Note that the context
2501 -- of the operation plays no role in resolving the arguments, so that
2502 -- if there is more than one interpretation of the operands that is
2503 -- compatible with a membership test, the operation is ambiguous.
2505 --------------------
2506 -- Try_One_Interp --
2507 --------------------
2509 procedure Try_One_Interp (T1 : Entity_Id) is
2511 if Has_Compatible_Type (R, T1) then
2513 and then Base_Type (T1) /= Base_Type (T_F)
2515 It := Disambiguate (L, I_F, Index, Any_Type);
2517 if It = No_Interp then
2518 Ambiguous_Operands (N);
2519 Set_Etype (L, Any_Type);
2536 procedure Analyze_Set_Membership;
2537 -- If a set of alternatives is present, analyze each and find the
2538 -- common type to which they must all resolve.
2540 ----------------------------
2541 -- Analyze_Set_Membership --
2542 ----------------------------
2544 procedure Analyze_Set_Membership is
2546 Index : Interp_Index;
2548 Candidate_Interps : Node_Id;
2549 Common_Type : Entity_Id := Empty;
2553 Candidate_Interps := L;
2555 if not Is_Overloaded (L) then
2556 Common_Type := Etype (L);
2558 Alt := First (Alternatives (N));
2559 while Present (Alt) loop
2562 if not Has_Compatible_Type (Alt, Common_Type) then
2563 Wrong_Type (Alt, Common_Type);
2570 Alt := First (Alternatives (N));
2571 while Present (Alt) loop
2573 if not Is_Overloaded (Alt) then
2574 Common_Type := Etype (Alt);
2577 Get_First_Interp (Alt, Index, It);
2578 while Present (It.Typ) loop
2580 Has_Compatible_Type (Candidate_Interps, It.Typ)
2582 Remove_Interp (Index);
2585 Get_Next_Interp (Index, It);
2588 Get_First_Interp (Alt, Index, It);
2591 Error_Msg_N ("alternative has no legal type", Alt);
2595 -- If alternative is not overloaded, we have a unique type
2598 Set_Etype (Alt, It.Typ);
2599 Get_Next_Interp (Index, It);
2602 Set_Is_Overloaded (Alt, False);
2603 Common_Type := Etype (Alt);
2606 Candidate_Interps := Alt;
2613 Set_Etype (N, Standard_Boolean);
2615 if Present (Common_Type) then
2616 Set_Etype (L, Common_Type);
2617 Set_Is_Overloaded (L, False);
2620 Error_Msg_N ("cannot resolve membership operation", N);
2622 end Analyze_Set_Membership;
2624 -- Start of processing for Analyze_Membership_Op
2627 Analyze_Expression (L);
2630 and then Ada_Version >= Ada_2012
2632 Analyze_Set_Membership;
2636 if Nkind (R) = N_Range
2637 or else (Nkind (R) = N_Attribute_Reference
2638 and then Attribute_Name (R) = Name_Range)
2642 if not Is_Overloaded (L) then
2643 Try_One_Interp (Etype (L));
2646 Get_First_Interp (L, Index, It);
2647 while Present (It.Typ) loop
2648 Try_One_Interp (It.Typ);
2649 Get_Next_Interp (Index, It);
2653 -- If not a range, it can be a subtype mark, or else it is a degenerate
2654 -- membership test with a singleton value, i.e. a test for equality,
2655 -- if the types are compatible.
2660 if Is_Entity_Name (R)
2661 and then Is_Type (Entity (R))
2664 Check_Fully_Declared (Entity (R), R);
2666 elsif Ada_Version >= Ada_2012
2667 and then Has_Compatible_Type (R, Etype (L))
2669 if Nkind (N) = N_In then
2685 -- In all versions of the language, if we reach this point there
2686 -- is a previous error that will be diagnosed below.
2692 -- Compatibility between expression and subtype mark or range is
2693 -- checked during resolution. The result of the operation is Boolean
2696 Set_Etype (N, Standard_Boolean);
2698 if Comes_From_Source (N)
2699 and then Present (Right_Opnd (N))
2700 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
2702 Error_Msg_N ("membership test not applicable to cpp-class types", N);
2704 end Analyze_Membership_Op;
2710 procedure Analyze_Mod (N : Node_Id) is
2712 -- A special warning check, if we have an expression of the form:
2713 -- expr mod 2 * literal
2714 -- where literal is 64 or less, then probably what was meant was
2715 -- expr mod 2 ** literal
2716 -- so issue an appropriate warning.
2718 if Warn_On_Suspicious_Modulus_Value
2719 and then Nkind (Right_Opnd (N)) = N_Integer_Literal
2720 and then Intval (Right_Opnd (N)) = Uint_2
2721 and then Nkind (Parent (N)) = N_Op_Multiply
2722 and then Nkind (Right_Opnd (Parent (N))) = N_Integer_Literal
2723 and then Intval (Right_Opnd (Parent (N))) <= Uint_64
2726 ("suspicious MOD value, was '*'* intended'??M?", Parent (N));
2729 -- Remaining processing is same as for other arithmetic operators
2731 Analyze_Arithmetic_Op (N);
2734 ----------------------
2735 -- Analyze_Negation --
2736 ----------------------
2738 procedure Analyze_Negation (N : Node_Id) is
2739 R : constant Node_Id := Right_Opnd (N);
2740 Op_Id : Entity_Id := Entity (N);
2743 Set_Etype (N, Any_Type);
2744 Candidate_Type := Empty;
2746 Analyze_Expression (R);
2748 if Present (Op_Id) then
2749 if Ekind (Op_Id) = E_Operator then
2750 Find_Negation_Types (R, Op_Id, N);
2752 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2756 Op_Id := Get_Name_Entity_Id (Chars (N));
2757 while Present (Op_Id) loop
2758 if Ekind (Op_Id) = E_Operator then
2759 Find_Negation_Types (R, Op_Id, N);
2761 Analyze_User_Defined_Unary_Op (N, Op_Id);
2764 Op_Id := Homonym (Op_Id);
2769 end Analyze_Negation;
2775 procedure Analyze_Null (N : Node_Id) is
2777 Check_SPARK_Restriction ("null is not allowed", N);
2779 Set_Etype (N, Any_Access);
2782 ----------------------
2783 -- Analyze_One_Call --
2784 ----------------------
2786 procedure Analyze_One_Call
2790 Success : out Boolean;
2791 Skip_First : Boolean := False)
2793 Actuals : constant List_Id := Parameter_Associations (N);
2794 Prev_T : constant Entity_Id := Etype (N);
2796 Must_Skip : constant Boolean := Skip_First
2797 or else Nkind (Original_Node (N)) = N_Selected_Component
2799 (Nkind (Original_Node (N)) = N_Indexed_Component
2800 and then Nkind (Prefix (Original_Node (N)))
2801 = N_Selected_Component);
2802 -- The first formal must be omitted from the match when trying to find
2803 -- a primitive operation that is a possible interpretation, and also
2804 -- after the call has been rewritten, because the corresponding actual
2805 -- is already known to be compatible, and because this may be an
2806 -- indexing of a call with default parameters.
2810 Is_Indexed : Boolean := False;
2811 Is_Indirect : Boolean := False;
2812 Subp_Type : constant Entity_Id := Etype (Nam);
2815 function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
2816 -- There may be a user-defined operator that hides the current
2817 -- interpretation. We must check for this independently of the
2818 -- analysis of the call with the user-defined operation, because
2819 -- the parameter names may be wrong and yet the hiding takes place.
2820 -- This fixes a problem with ACATS test B34014O.
2822 -- When the type Address is a visible integer type, and the DEC
2823 -- system extension is visible, the predefined operator may be
2824 -- hidden as well, by one of the address operations in auxdec.
2825 -- Finally, The abstract operations on address do not hide the
2826 -- predefined operator (this is the purpose of making them abstract).
2828 procedure Indicate_Name_And_Type;
2829 -- If candidate interpretation matches, indicate name and type of
2830 -- result on call node.
2832 ----------------------------
2833 -- Indicate_Name_And_Type --
2834 ----------------------------
2836 procedure Indicate_Name_And_Type is
2838 Add_One_Interp (N, Nam, Etype (Nam));
2839 Check_Implicit_Dereference (N, Etype (Nam));
2842 -- If the prefix of the call is a name, indicate the entity
2843 -- being called. If it is not a name, it is an expression that
2844 -- denotes an access to subprogram or else an entry or family. In
2845 -- the latter case, the name is a selected component, and the entity
2846 -- being called is noted on the selector.
2848 if not Is_Type (Nam) then
2849 if Is_Entity_Name (Name (N)) then
2850 Set_Entity (Name (N), Nam);
2852 elsif Nkind (Name (N)) = N_Selected_Component then
2853 Set_Entity (Selector_Name (Name (N)), Nam);
2857 if Debug_Flag_E and not Report then
2858 Write_Str (" Overloaded call ");
2859 Write_Int (Int (N));
2860 Write_Str (" compatible with ");
2861 Write_Int (Int (Nam));
2864 end Indicate_Name_And_Type;
2866 ------------------------
2867 -- Operator_Hidden_By --
2868 ------------------------
2870 function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
2871 Act1 : constant Node_Id := First_Actual (N);
2872 Act2 : constant Node_Id := Next_Actual (Act1);
2873 Form1 : constant Entity_Id := First_Formal (Fun);
2874 Form2 : constant Entity_Id := Next_Formal (Form1);
2877 if Ekind (Fun) /= E_Function
2878 or else Is_Abstract_Subprogram (Fun)
2882 elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
2885 elsif Present (Form2) then
2887 No (Act2) or else not Has_Compatible_Type (Act2, Etype (Form2))
2892 elsif Present (Act2) then
2896 -- Now we know that the arity of the operator matches the function,
2897 -- and the function call is a valid interpretation. The function
2898 -- hides the operator if it has the right signature, or if one of
2899 -- its operands is a non-abstract operation on Address when this is
2900 -- a visible integer type.
2902 return Hides_Op (Fun, Nam)
2903 or else Is_Descendent_Of_Address (Etype (Form1))
2906 and then Is_Descendent_Of_Address (Etype (Form2)));
2907 end Operator_Hidden_By;
2909 -- Start of processing for Analyze_One_Call
2914 -- If the subprogram has no formals or if all the formals have defaults,
2915 -- and the return type is an array type, the node may denote an indexing
2916 -- of the result of a parameterless call. In Ada 2005, the subprogram
2917 -- may have one non-defaulted formal, and the call may have been written
2918 -- in prefix notation, so that the rebuilt parameter list has more than
2921 if not Is_Overloadable (Nam)
2922 and then Ekind (Nam) /= E_Subprogram_Type
2923 and then Ekind (Nam) /= E_Entry_Family
2928 -- An indexing requires at least one actual
2930 if not Is_Empty_List (Actuals)
2932 (Needs_No_Actuals (Nam)
2934 (Needs_One_Actual (Nam)
2935 and then Present (Next_Actual (First (Actuals)))))
2937 if Is_Array_Type (Subp_Type) then
2938 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
2940 elsif Is_Access_Type (Subp_Type)
2941 and then Is_Array_Type (Designated_Type (Subp_Type))
2945 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
2947 -- The prefix can also be a parameterless function that returns an
2948 -- access to subprogram, in which case this is an indirect call.
2949 -- If this succeeds, an explicit dereference is added later on,
2950 -- in Analyze_Call or Resolve_Call.
2952 elsif Is_Access_Type (Subp_Type)
2953 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
2955 Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
2960 -- If the call has been transformed into a slice, it is of the form
2961 -- F (Subtype) where F is parameterless. The node has been rewritten in
2962 -- Try_Indexed_Call and there is nothing else to do.
2965 and then Nkind (N) = N_Slice
2971 (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
2975 -- If an indirect call is a possible interpretation, indicate
2976 -- success to the caller.
2982 -- Mismatch in number or names of parameters
2984 elsif Debug_Flag_E then
2985 Write_Str (" normalization fails in call ");
2986 Write_Int (Int (N));
2987 Write_Str (" with subprogram ");
2988 Write_Int (Int (Nam));
2992 -- If the context expects a function call, discard any interpretation
2993 -- that is a procedure. If the node is not overloaded, leave as is for
2994 -- better error reporting when type mismatch is found.
2996 elsif Nkind (N) = N_Function_Call
2997 and then Is_Overloaded (Name (N))
2998 and then Ekind (Nam) = E_Procedure
3002 -- Ditto for function calls in a procedure context
3004 elsif Nkind (N) = N_Procedure_Call_Statement
3005 and then Is_Overloaded (Name (N))
3006 and then Etype (Nam) /= Standard_Void_Type
3010 elsif No (Actuals) then
3012 -- If Normalize succeeds, then there are default parameters for
3015 Indicate_Name_And_Type;
3017 elsif Ekind (Nam) = E_Operator then
3018 if Nkind (N) = N_Procedure_Call_Statement then
3022 -- This can occur when the prefix of the call is an operator
3023 -- name or an expanded name whose selector is an operator name.
3025 Analyze_Operator_Call (N, Nam);
3027 if Etype (N) /= Prev_T then
3029 -- Check that operator is not hidden by a function interpretation
3031 if Is_Overloaded (Name (N)) then
3037 Get_First_Interp (Name (N), I, It);
3038 while Present (It.Nam) loop
3039 if Operator_Hidden_By (It.Nam) then
3040 Set_Etype (N, Prev_T);
3044 Get_Next_Interp (I, It);
3049 -- If operator matches formals, record its name on the call.
3050 -- If the operator is overloaded, Resolve will select the
3051 -- correct one from the list of interpretations. The call
3052 -- node itself carries the first candidate.
3054 Set_Entity (Name (N), Nam);
3057 elsif Report and then Etype (N) = Any_Type then
3058 Error_Msg_N ("incompatible arguments for operator", N);
3062 -- Normalize_Actuals has chained the named associations in the
3063 -- correct order of the formals.
3065 Actual := First_Actual (N);
3066 Formal := First_Formal (Nam);
3068 -- If we are analyzing a call rewritten from object notation, skip
3069 -- first actual, which may be rewritten later as an explicit
3073 Next_Actual (Actual);
3074 Next_Formal (Formal);
3077 while Present (Actual) and then Present (Formal) loop
3078 if Nkind (Parent (Actual)) /= N_Parameter_Association
3079 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
3081 -- The actual can be compatible with the formal, but we must
3082 -- also check that the context is not an address type that is
3083 -- visibly an integer type, as is the case in VMS_64. In this
3084 -- case the use of literals is illegal, except in the body of
3085 -- descendents of system, where arithmetic operations on
3086 -- address are of course used.
3088 if Has_Compatible_Type (Actual, Etype (Formal))
3090 (Etype (Actual) /= Universal_Integer
3091 or else not Is_Descendent_Of_Address (Etype (Formal))
3093 Is_Predefined_File_Name
3094 (Unit_File_Name (Get_Source_Unit (N))))
3096 Next_Actual (Actual);
3097 Next_Formal (Formal);
3100 if Debug_Flag_E then
3101 Write_Str (" type checking fails in call ");
3102 Write_Int (Int (N));
3103 Write_Str (" with formal ");
3104 Write_Int (Int (Formal));
3105 Write_Str (" in subprogram ");
3106 Write_Int (Int (Nam));
3110 if Report and not Is_Indexed and not Is_Indirect then
3112 -- Ada 2005 (AI-251): Complete the error notification
3113 -- to help new Ada 2005 users.
3115 if Is_Class_Wide_Type (Etype (Formal))
3116 and then Is_Interface (Etype (Etype (Formal)))
3117 and then not Interface_Present_In_Ancestor
3118 (Typ => Etype (Actual),
3119 Iface => Etype (Etype (Formal)))
3122 ("(Ada 2005) does not implement interface }",
3123 Actual, Etype (Etype (Formal)));
3126 Wrong_Type (Actual, Etype (Formal));
3128 if Nkind (Actual) = N_Op_Eq
3129 and then Nkind (Left_Opnd (Actual)) = N_Identifier
3131 Formal := First_Formal (Nam);
3132 while Present (Formal) loop
3133 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
3134 Error_Msg_N -- CODEFIX
3135 ("possible misspelling of `='>`!", Actual);
3139 Next_Formal (Formal);
3143 if All_Errors_Mode then
3144 Error_Msg_Sloc := Sloc (Nam);
3146 if Etype (Formal) = Any_Type then
3148 ("there is no legal actual parameter", Actual);
3151 if Is_Overloadable (Nam)
3152 and then Present (Alias (Nam))
3153 and then not Comes_From_Source (Nam)
3156 ("\\ =='> in call to inherited operation & #!",
3159 elsif Ekind (Nam) = E_Subprogram_Type then
3161 Access_To_Subprogram_Typ :
3162 constant Entity_Id :=
3164 (Associated_Node_For_Itype (Nam));
3167 "\\ =='> in call to dereference of &#!",
3168 Actual, Access_To_Subprogram_Typ);
3173 ("\\ =='> in call to &#!", Actual, Nam);
3183 -- Normalize_Actuals has verified that a default value exists
3184 -- for this formal. Current actual names a subsequent formal.
3186 Next_Formal (Formal);
3190 -- On exit, all actuals match
3192 Indicate_Name_And_Type;
3194 end Analyze_One_Call;
3196 ---------------------------
3197 -- Analyze_Operator_Call --
3198 ---------------------------
3200 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
3201 Op_Name : constant Name_Id := Chars (Op_Id);
3202 Act1 : constant Node_Id := First_Actual (N);
3203 Act2 : constant Node_Id := Next_Actual (Act1);
3206 -- Binary operator case
3208 if Present (Act2) then
3210 -- If more than two operands, then not binary operator after all
3212 if Present (Next_Actual (Act2)) then
3216 -- Otherwise action depends on operator
3226 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
3231 Find_Boolean_Types (Act1, Act2, Op_Id, N);
3237 Find_Comparison_Types (Act1, Act2, Op_Id, N);
3241 Find_Equality_Types (Act1, Act2, Op_Id, N);
3243 when Name_Op_Concat =>
3244 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
3246 -- Is this when others, or should it be an abort???
3252 -- Unary operator case
3256 when Name_Op_Subtract |
3259 Find_Unary_Types (Act1, Op_Id, N);
3262 Find_Negation_Types (Act1, Op_Id, N);
3264 -- Is this when others correct, or should it be an abort???
3270 end Analyze_Operator_Call;
3272 -------------------------------------------
3273 -- Analyze_Overloaded_Selected_Component --
3274 -------------------------------------------
3276 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
3277 Nam : constant Node_Id := Prefix (N);
3278 Sel : constant Node_Id := Selector_Name (N);
3285 Set_Etype (Sel, Any_Type);
3287 Get_First_Interp (Nam, I, It);
3288 while Present (It.Typ) loop
3289 if Is_Access_Type (It.Typ) then
3290 T := Designated_Type (It.Typ);
3291 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
3296 -- Locate the component. For a private prefix the selector can denote
3299 if Is_Record_Type (T) or else Is_Private_Type (T) then
3301 -- If the prefix is a class-wide type, the visible components are
3302 -- those of the base type.
3304 if Is_Class_Wide_Type (T) then
3308 Comp := First_Entity (T);
3309 while Present (Comp) loop
3310 if Chars (Comp) = Chars (Sel)
3311 and then Is_Visible_Component (Comp)
3314 -- AI05-105: if the context is an object renaming with
3315 -- an anonymous access type, the expected type of the
3316 -- object must be anonymous. This is a name resolution rule.
3318 if Nkind (Parent (N)) /= N_Object_Renaming_Declaration
3319 or else No (Access_Definition (Parent (N)))
3320 or else Ekind (Etype (Comp)) = E_Anonymous_Access_Type
3322 Ekind (Etype (Comp)) = E_Anonymous_Access_Subprogram_Type
3324 Set_Entity (Sel, Comp);
3325 Set_Etype (Sel, Etype (Comp));
3326 Add_One_Interp (N, Etype (Comp), Etype (Comp));
3327 Check_Implicit_Dereference (N, Etype (Comp));
3329 -- This also specifies a candidate to resolve the name.
3330 -- Further overloading will be resolved from context.
3331 -- The selector name itself does not carry overloading
3334 Set_Etype (Nam, It.Typ);
3337 -- Named access type in the context of a renaming
3338 -- declaration with an access definition. Remove
3339 -- inapplicable candidate.
3348 elsif Is_Concurrent_Type (T) then
3349 Comp := First_Entity (T);
3350 while Present (Comp)
3351 and then Comp /= First_Private_Entity (T)
3353 if Chars (Comp) = Chars (Sel) then
3354 if Is_Overloadable (Comp) then
3355 Add_One_Interp (Sel, Comp, Etype (Comp));
3357 Set_Entity_With_Style_Check (Sel, Comp);
3358 Generate_Reference (Comp, Sel);
3361 Set_Etype (Sel, Etype (Comp));
3362 Set_Etype (N, Etype (Comp));
3363 Set_Etype (Nam, It.Typ);
3365 -- For access type case, introduce explicit dereference for
3366 -- more uniform treatment of entry calls. Do this only once
3367 -- if several interpretations yield an access type.
3369 if Is_Access_Type (Etype (Nam))
3370 and then Nkind (Nam) /= N_Explicit_Dereference
3372 Insert_Explicit_Dereference (Nam);
3374 (Warn_On_Dereference, "?d?implicit dereference", N);
3381 Set_Is_Overloaded (N, Is_Overloaded (Sel));
3384 Get_Next_Interp (I, It);
3387 if Etype (N) = Any_Type
3388 and then not Try_Object_Operation (N)
3390 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
3391 Set_Entity (Sel, Any_Id);
3392 Set_Etype (Sel, Any_Type);
3394 end Analyze_Overloaded_Selected_Component;
3396 ----------------------------------
3397 -- Analyze_Qualified_Expression --
3398 ----------------------------------
3400 procedure Analyze_Qualified_Expression (N : Node_Id) is
3401 Mark : constant Entity_Id := Subtype_Mark (N);
3402 Expr : constant Node_Id := Expression (N);
3408 Analyze_Expression (Expr);
3410 Set_Etype (N, Any_Type);
3415 if T = Any_Type then
3419 Check_Fully_Declared (T, N);
3421 -- If expected type is class-wide, check for exact match before
3422 -- expansion, because if the expression is a dispatching call it
3423 -- may be rewritten as explicit dereference with class-wide result.
3424 -- If expression is overloaded, retain only interpretations that
3425 -- will yield exact matches.
3427 if Is_Class_Wide_Type (T) then
3428 if not Is_Overloaded (Expr) then
3429 if Base_Type (Etype (Expr)) /= Base_Type (T) then
3430 if Nkind (Expr) = N_Aggregate then
3431 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
3433 Wrong_Type (Expr, T);
3438 Get_First_Interp (Expr, I, It);
3440 while Present (It.Nam) loop
3441 if Base_Type (It.Typ) /= Base_Type (T) then
3445 Get_Next_Interp (I, It);
3451 end Analyze_Qualified_Expression;
3453 -----------------------------------
3454 -- Analyze_Quantified_Expression --
3455 -----------------------------------
3457 procedure Analyze_Quantified_Expression (N : Node_Id) is
3458 QE_Scop : Entity_Id;
3460 function Is_Empty_Range (Typ : Entity_Id) return Boolean;
3461 -- If the iterator is part of a quantified expression, and the range is
3462 -- known to be statically empty, emit a warning and replace expression
3463 -- with its static value. Returns True if the replacement occurs.
3465 --------------------
3466 -- Is_Empty_Range --
3467 --------------------
3469 function Is_Empty_Range (Typ : Entity_Id) return Boolean is
3470 Loc : constant Source_Ptr := Sloc (N);
3473 if Is_Array_Type (Typ)
3474 and then Compile_Time_Known_Bounds (Typ)
3476 (Expr_Value (Type_Low_Bound (Etype (First_Index (Typ)))) >
3477 Expr_Value (Type_High_Bound (Etype (First_Index (Typ)))))
3479 Preanalyze_And_Resolve (Condition (N), Standard_Boolean);
3481 if All_Present (N) then
3483 ("??quantified expression with ALL "
3484 & "over a null range has value True", N);
3485 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
3489 ("??quantified expression with SOME "
3490 & "over a null range has value False", N);
3491 Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
3502 -- Start of processing for Analyze_Quantified_Expression
3505 Check_SPARK_Restriction ("quantified expression is not allowed", N);
3507 -- Create a scope to emulate the loop-like behavior of the quantified
3508 -- expression. The scope is needed to provide proper visibility of the
3511 QE_Scop := New_Internal_Entity (E_Loop, Current_Scope, Sloc (N), 'L');
3512 Set_Etype (QE_Scop, Standard_Void_Type);
3513 Set_Scope (QE_Scop, Current_Scope);
3514 Set_Parent (QE_Scop, N);
3516 Push_Scope (QE_Scop);
3518 -- All constituents are preanalyzed and resolved to avoid untimely
3519 -- generation of various temporaries and types. Full analysis and
3520 -- expansion is carried out when the quantified expression is
3521 -- transformed into an expression with actions.
3523 if Present (Iterator_Specification (N)) then
3524 Preanalyze (Iterator_Specification (N));
3526 if Is_Entity_Name (Name (Iterator_Specification (N)))
3527 and then Is_Empty_Range (Etype (Name (Iterator_Specification (N))))
3533 Preanalyze (Loop_Parameter_Specification (N));
3536 Preanalyze_And_Resolve (Condition (N), Standard_Boolean);
3540 Set_Etype (N, Standard_Boolean);
3541 end Analyze_Quantified_Expression;
3547 procedure Analyze_Range (N : Node_Id) is
3548 L : constant Node_Id := Low_Bound (N);
3549 H : constant Node_Id := High_Bound (N);
3550 I1, I2 : Interp_Index;
3553 procedure Check_Common_Type (T1, T2 : Entity_Id);
3554 -- Verify the compatibility of two types, and choose the
3555 -- non universal one if the other is universal.
3557 procedure Check_High_Bound (T : Entity_Id);
3558 -- Test one interpretation of the low bound against all those
3559 -- of the high bound.
3561 procedure Check_Universal_Expression (N : Node_Id);
3562 -- In Ada 83, reject bounds of a universal range that are not literals
3565 -----------------------
3566 -- Check_Common_Type --
3567 -----------------------
3569 procedure Check_Common_Type (T1, T2 : Entity_Id) is
3571 if Covers (T1 => T1, T2 => T2)
3573 Covers (T1 => T2, T2 => T1)
3575 if T1 = Universal_Integer
3576 or else T1 = Universal_Real
3577 or else T1 = Any_Character
3579 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
3582 Add_One_Interp (N, T1, T1);
3585 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
3588 end Check_Common_Type;
3590 ----------------------
3591 -- Check_High_Bound --
3592 ----------------------
3594 procedure Check_High_Bound (T : Entity_Id) is
3596 if not Is_Overloaded (H) then
3597 Check_Common_Type (T, Etype (H));
3599 Get_First_Interp (H, I2, It2);
3600 while Present (It2.Typ) loop
3601 Check_Common_Type (T, It2.Typ);
3602 Get_Next_Interp (I2, It2);
3605 end Check_High_Bound;
3607 -----------------------------
3608 -- Is_Universal_Expression --
3609 -----------------------------
3611 procedure Check_Universal_Expression (N : Node_Id) is
3613 if Etype (N) = Universal_Integer
3614 and then Nkind (N) /= N_Integer_Literal
3615 and then not Is_Entity_Name (N)
3616 and then Nkind (N) /= N_Attribute_Reference
3618 Error_Msg_N ("illegal bound in discrete range", N);
3620 end Check_Universal_Expression;
3622 -- Start of processing for Analyze_Range
3625 Set_Etype (N, Any_Type);
3626 Analyze_Expression (L);
3627 Analyze_Expression (H);
3629 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
3633 if not Is_Overloaded (L) then
3634 Check_High_Bound (Etype (L));
3636 Get_First_Interp (L, I1, It1);
3637 while Present (It1.Typ) loop
3638 Check_High_Bound (It1.Typ);
3639 Get_Next_Interp (I1, It1);
3643 -- If result is Any_Type, then we did not find a compatible pair
3645 if Etype (N) = Any_Type then
3646 Error_Msg_N ("incompatible types in range ", N);
3650 if Ada_Version = Ada_83
3652 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
3653 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
3655 Check_Universal_Expression (L);
3656 Check_Universal_Expression (H);
3659 Check_Function_Writable_Actuals (N);
3662 -----------------------
3663 -- Analyze_Reference --
3664 -----------------------
3666 procedure Analyze_Reference (N : Node_Id) is
3667 P : constant Node_Id := Prefix (N);
3670 Acc_Type : Entity_Id;
3675 -- An interesting error check, if we take the 'Reference of an object
3676 -- for which a pragma Atomic or Volatile has been given, and the type
3677 -- of the object is not Atomic or Volatile, then we are in trouble. The
3678 -- problem is that no trace of the atomic/volatile status will remain
3679 -- for the backend to respect when it deals with the resulting pointer,
3680 -- since the pointer type will not be marked atomic (it is a pointer to
3681 -- the base type of the object).
3683 -- It is not clear if that can ever occur, but in case it does, we will
3684 -- generate an error message. Not clear if this message can ever be
3685 -- generated, and pretty clear that it represents a bug if it is, still
3686 -- seems worth checking, except in CodePeer mode where we do not really
3687 -- care and don't want to bother the user.
3691 if Is_Entity_Name (P)
3692 and then Is_Object_Reference (P)
3693 and then not CodePeer_Mode
3698 if (Has_Atomic_Components (E)
3699 and then not Has_Atomic_Components (T))
3701 (Has_Volatile_Components (E)
3702 and then not Has_Volatile_Components (T))
3703 or else (Is_Atomic (E) and then not Is_Atomic (T))
3704 or else (Is_Volatile (E) and then not Is_Volatile (T))
3706 Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
3710 -- Carry on with normal processing
3712 Acc_Type := Create_Itype (E_Allocator_Type, N);
3713 Set_Etype (Acc_Type, Acc_Type);
3714 Set_Directly_Designated_Type (Acc_Type, Etype (P));
3715 Set_Etype (N, Acc_Type);
3716 end Analyze_Reference;
3718 --------------------------------
3719 -- Analyze_Selected_Component --
3720 --------------------------------
3722 -- Prefix is a record type or a task or protected type. In the latter case,
3723 -- the selector must denote a visible entry.
3725 procedure Analyze_Selected_Component (N : Node_Id) is
3726 Name : constant Node_Id := Prefix (N);
3727 Sel : constant Node_Id := Selector_Name (N);
3730 Has_Candidate : Boolean := False;
3733 Pent : Entity_Id := Empty;
3734 Prefix_Type : Entity_Id;
3736 Type_To_Use : Entity_Id;
3737 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
3738 -- a class-wide type, we use its root type, whose components are
3739 -- present in the class-wide type.
3741 Is_Single_Concurrent_Object : Boolean;
3742 -- Set True if the prefix is a single task or a single protected object
3744 procedure Find_Component_In_Instance (Rec : Entity_Id);
3745 -- In an instance, a component of a private extension may not be visible
3746 -- while it was visible in the generic. Search candidate scope for a
3747 -- component with the proper identifier. This is only done if all other
3748 -- searches have failed. When the match is found (it always will be),
3749 -- the Etype of both N and Sel are set from this component, and the
3750 -- entity of Sel is set to reference this component.
3752 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
3753 -- It is known that the parent of N denotes a subprogram call. Comp
3754 -- is an overloadable component of the concurrent type of the prefix.
3755 -- Determine whether all formals of the parent of N and Comp are mode
3756 -- conformant. If the parent node is not analyzed yet it may be an
3757 -- indexed component rather than a function call.
3759 --------------------------------
3760 -- Find_Component_In_Instance --
3761 --------------------------------
3763 procedure Find_Component_In_Instance (Rec : Entity_Id) is
3767 Comp := First_Component (Rec);
3768 while Present (Comp) loop
3769 if Chars (Comp) = Chars (Sel) then
3770 Set_Entity_With_Style_Check (Sel, Comp);
3771 Set_Etype (Sel, Etype (Comp));
3772 Set_Etype (N, Etype (Comp));
3776 Next_Component (Comp);
3779 -- This must succeed because code was legal in the generic
3781 raise Program_Error;
3782 end Find_Component_In_Instance;
3784 ------------------------------
3785 -- Has_Mode_Conformant_Spec --
3786 ------------------------------
3788 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
3789 Comp_Param : Entity_Id;
3791 Param_Typ : Entity_Id;
3794 Comp_Param := First_Formal (Comp);
3796 if Nkind (Parent (N)) = N_Indexed_Component then
3797 Param := First (Expressions (Parent (N)));
3799 Param := First (Parameter_Associations (Parent (N)));
3802 while Present (Comp_Param)
3803 and then Present (Param)
3805 Param_Typ := Find_Parameter_Type (Param);
3807 if Present (Param_Typ)
3809 not Conforming_Types
3810 (Etype (Comp_Param), Param_Typ, Mode_Conformant)
3815 Next_Formal (Comp_Param);
3819 -- One of the specs has additional formals
3821 if Present (Comp_Param) or else Present (Param) then
3826 end Has_Mode_Conformant_Spec;
3828 -- Start of processing for Analyze_Selected_Component
3831 Set_Etype (N, Any_Type);
3833 if Is_Overloaded (Name) then
3834 Analyze_Overloaded_Selected_Component (N);
3837 elsif Etype (Name) = Any_Type then
3838 Set_Entity (Sel, Any_Id);
3839 Set_Etype (Sel, Any_Type);
3843 Prefix_Type := Etype (Name);
3846 if Is_Access_Type (Prefix_Type) then
3848 -- A RACW object can never be used as prefix of a selected component
3849 -- since that means it is dereferenced without being a controlling
3850 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
3851 -- reporting an error, we must check whether this is actually a
3852 -- dispatching call in prefix form.
3854 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
3855 and then Comes_From_Source (N)
3857 if Try_Object_Operation (N) then
3861 ("invalid dereference of a remote access-to-class-wide value",
3865 -- Normal case of selected component applied to access type
3868 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
3870 if Is_Entity_Name (Name) then
3871 Pent := Entity (Name);
3872 elsif Nkind (Name) = N_Selected_Component
3873 and then Is_Entity_Name (Selector_Name (Name))
3875 Pent := Entity (Selector_Name (Name));
3878 Prefix_Type := Process_Implicit_Dereference_Prefix (Pent, Name);
3881 -- If we have an explicit dereference of a remote access-to-class-wide
3882 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
3883 -- have to check for the case of a prefix that is a controlling operand
3884 -- of a prefixed dispatching call, as the dereference is legal in that
3885 -- case. Normally this condition is checked in Validate_Remote_Access_
3886 -- To_Class_Wide_Type, but we have to defer the checking for selected
3887 -- component prefixes because of the prefixed dispatching call case.
3888 -- Note that implicit dereferences are checked for this just above.
3890 elsif Nkind (Name) = N_Explicit_Dereference
3891 and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
3892 and then Comes_From_Source (N)
3894 if Try_Object_Operation (N) then
3898 ("invalid dereference of a remote access-to-class-wide value",
3903 -- (Ada 2005): if the prefix is the limited view of a type, and
3904 -- the context already includes the full view, use the full view
3905 -- in what follows, either to retrieve a component of to find
3906 -- a primitive operation. If the prefix is an explicit dereference,
3907 -- set the type of the prefix to reflect this transformation.
3908 -- If the non-limited view is itself an incomplete type, get the
3909 -- full view if available.
3911 if Is_Incomplete_Type (Prefix_Type)
3912 and then From_With_Type (Prefix_Type)
3913 and then Present (Non_Limited_View (Prefix_Type))
3915 Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
3917 if Nkind (N) = N_Explicit_Dereference then
3918 Set_Etype (Prefix (N), Prefix_Type);
3921 elsif Ekind (Prefix_Type) = E_Class_Wide_Type
3922 and then From_With_Type (Prefix_Type)
3923 and then Present (Non_Limited_View (Etype (Prefix_Type)))
3926 Class_Wide_Type (Non_Limited_View (Etype (Prefix_Type)));
3928 if Nkind (N) = N_Explicit_Dereference then
3929 Set_Etype (Prefix (N), Prefix_Type);
3933 if Ekind (Prefix_Type) = E_Private_Subtype then
3934 Prefix_Type := Base_Type (Prefix_Type);
3937 Type_To_Use := Prefix_Type;
3939 -- For class-wide types, use the entity list of the root type. This
3940 -- indirection is specially important for private extensions because
3941 -- only the root type get switched (not the class-wide type).
3943 if Is_Class_Wide_Type (Prefix_Type) then
3944 Type_To_Use := Root_Type (Prefix_Type);
3947 -- If the prefix is a single concurrent object, use its name in error
3948 -- messages, rather than that of its anonymous type.
3950 Is_Single_Concurrent_Object :=
3951 Is_Concurrent_Type (Prefix_Type)
3952 and then Is_Internal_Name (Chars (Prefix_Type))
3953 and then not Is_Derived_Type (Prefix_Type)
3954 and then Is_Entity_Name (Name);
3956 Comp := First_Entity (Type_To_Use);
3958 -- If the selector has an original discriminant, the node appears in
3959 -- an instance. Replace the discriminant with the corresponding one
3960 -- in the current discriminated type. For nested generics, this must
3961 -- be done transitively, so note the new original discriminant.
3963 if Nkind (Sel) = N_Identifier
3964 and then In_Instance
3965 and then Present (Original_Discriminant (Sel))
3967 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
3969 -- Mark entity before rewriting, for completeness and because
3970 -- subsequent semantic checks might examine the original node.
3972 Set_Entity (Sel, Comp);
3973 Rewrite (Selector_Name (N), New_Occurrence_Of (Comp, Sloc (N)));
3974 Set_Original_Discriminant (Selector_Name (N), Comp);
3975 Set_Etype (N, Etype (Comp));
3976 Check_Implicit_Dereference (N, Etype (Comp));
3978 if Is_Access_Type (Etype (Name)) then
3979 Insert_Explicit_Dereference (Name);
3980 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
3983 elsif Is_Record_Type (Prefix_Type) then
3985 -- Find component with given name. In an instance, if the node is
3986 -- known as a prefixed call, do not examine components whose
3987 -- visibility may be accidental.
3989 while Present (Comp) and then not Is_Prefixed_Call (N) loop
3990 if Chars (Comp) = Chars (Sel)
3991 and then Is_Visible_Component (Comp, N)
3993 Set_Entity_With_Style_Check (Sel, Comp);
3994 Set_Etype (Sel, Etype (Comp));
3996 if Ekind (Comp) = E_Discriminant then
3997 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
3999 ("cannot reference discriminant of unchecked union",
4003 if Is_Generic_Type (Prefix_Type)
4005 Is_Generic_Type (Root_Type (Prefix_Type))
4007 Set_Original_Discriminant (Sel, Comp);
4011 -- Resolve the prefix early otherwise it is not possible to
4012 -- build the actual subtype of the component: it may need
4013 -- to duplicate this prefix and duplication is only allowed
4014 -- on fully resolved expressions.
4018 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
4019 -- subtypes in a package specification.
4022 -- limited with Pkg;
4024 -- type Acc_Inc is access Pkg.T;
4026 -- N : Natural := X.all.Comp; -- ERROR, limited view
4027 -- end Pkg; -- Comp is not visible
4029 if Nkind (Name) = N_Explicit_Dereference
4030 and then From_With_Type (Etype (Prefix (Name)))
4031 and then not Is_Potentially_Use_Visible (Etype (Name))
4032 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
4033 N_Package_Specification
4036 ("premature usage of incomplete}", Prefix (Name),
4037 Etype (Prefix (Name)));
4040 -- We never need an actual subtype for the case of a selection
4041 -- for a indexed component of a non-packed array, since in
4042 -- this case gigi generates all the checks and can find the
4043 -- necessary bounds information.
4045 -- We also do not need an actual subtype for the case of a
4046 -- first, last, length, or range attribute applied to a
4047 -- non-packed array, since gigi can again get the bounds in
4048 -- these cases (gigi cannot handle the packed case, since it
4049 -- has the bounds of the packed array type, not the original
4050 -- bounds of the type). However, if the prefix is itself a
4051 -- selected component, as in a.b.c (i), gigi may regard a.b.c
4052 -- as a dynamic-sized temporary, so we do generate an actual
4053 -- subtype for this case.
4055 Parent_N := Parent (N);
4057 if not Is_Packed (Etype (Comp))
4059 ((Nkind (Parent_N) = N_Indexed_Component
4060 and then Nkind (Name) /= N_Selected_Component)
4062 (Nkind (Parent_N) = N_Attribute_Reference
4063 and then (Attribute_Name (Parent_N) = Name_First
4065 Attribute_Name (Parent_N) = Name_Last
4067 Attribute_Name (Parent_N) = Name_Length
4069 Attribute_Name (Parent_N) = Name_Range)))
4071 Set_Etype (N, Etype (Comp));
4073 -- If full analysis is not enabled, we do not generate an
4074 -- actual subtype, because in the absence of expansion
4075 -- reference to a formal of a protected type, for example,
4076 -- will not be properly transformed, and will lead to
4077 -- out-of-scope references in gigi.
4079 -- In all other cases, we currently build an actual subtype.
4080 -- It seems likely that many of these cases can be avoided,
4081 -- but right now, the front end makes direct references to the
4082 -- bounds (e.g. in generating a length check), and if we do
4083 -- not make an actual subtype, we end up getting a direct
4084 -- reference to a discriminant, which will not do.
4086 elsif Full_Analysis then
4088 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
4089 Insert_Action (N, Act_Decl);
4091 if No (Act_Decl) then
4092 Set_Etype (N, Etype (Comp));
4095 -- Component type depends on discriminants. Enter the
4096 -- main attributes of the subtype.
4099 Subt : constant Entity_Id :=
4100 Defining_Identifier (Act_Decl);
4103 Set_Etype (Subt, Base_Type (Etype (Comp)));
4104 Set_Ekind (Subt, Ekind (Etype (Comp)));
4105 Set_Etype (N, Subt);
4109 -- If Full_Analysis not enabled, just set the Etype
4112 Set_Etype (N, Etype (Comp));
4115 Check_Implicit_Dereference (N, Etype (N));
4119 -- If the prefix is a private extension, check only the visible
4120 -- components of the partial view. This must include the tag,
4121 -- which can appear in expanded code in a tag check.
4123 if Ekind (Type_To_Use) = E_Record_Type_With_Private
4124 and then Chars (Selector_Name (N)) /= Name_uTag
4126 exit when Comp = Last_Entity (Type_To_Use);
4132 -- Ada 2005 (AI-252): The selected component can be interpreted as
4133 -- a prefixed view of a subprogram. Depending on the context, this is
4134 -- either a name that can appear in a renaming declaration, or part
4135 -- of an enclosing call given in prefix form.
4137 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
4138 -- selected component should resolve to a name.
4140 if Ada_Version >= Ada_2005
4141 and then Is_Tagged_Type (Prefix_Type)
4142 and then not Is_Concurrent_Type (Prefix_Type)
4144 if Nkind (Parent (N)) = N_Generic_Association
4145 or else Nkind (Parent (N)) = N_Requeue_Statement
4146 or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
4148 if Find_Primitive_Operation (N) then
4152 elsif Try_Object_Operation (N) then
4156 -- If the transformation fails, it will be necessary to redo the
4157 -- analysis with all errors enabled, to indicate candidate
4158 -- interpretations and reasons for each failure ???
4162 elsif Is_Private_Type (Prefix_Type) then
4164 -- Allow access only to discriminants of the type. If the type has
4165 -- no full view, gigi uses the parent type for the components, so we
4166 -- do the same here.
4168 if No (Full_View (Prefix_Type)) then
4169 Type_To_Use := Root_Type (Base_Type (Prefix_Type));
4170 Comp := First_Entity (Type_To_Use);
4173 while Present (Comp) loop
4174 if Chars (Comp) = Chars (Sel) then
4175 if Ekind (Comp) = E_Discriminant then
4176 Set_Entity_With_Style_Check (Sel, Comp);
4177 Generate_Reference (Comp, Sel);
4179 Set_Etype (Sel, Etype (Comp));
4180 Set_Etype (N, Etype (Comp));
4181 Check_Implicit_Dereference (N, Etype (N));
4183 if Is_Generic_Type (Prefix_Type)
4184 or else Is_Generic_Type (Root_Type (Prefix_Type))
4186 Set_Original_Discriminant (Sel, Comp);
4189 -- Before declaring an error, check whether this is tagged
4190 -- private type and a call to a primitive operation.
4192 elsif Ada_Version >= Ada_2005
4193 and then Is_Tagged_Type (Prefix_Type)
4194 and then Try_Object_Operation (N)
4199 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4200 Error_Msg_NE ("invisible selector& for }", N, Sel);
4201 Set_Entity (Sel, Any_Id);
4202 Set_Etype (N, Any_Type);
4211 elsif Is_Concurrent_Type (Prefix_Type) then
4213 -- Find visible operation with given name. For a protected type,
4214 -- the possible candidates are discriminants, entries or protected
4215 -- procedures. For a task type, the set can only include entries or
4216 -- discriminants if the task type is not an enclosing scope. If it
4217 -- is an enclosing scope (e.g. in an inner task) then all entities
4218 -- are visible, but the prefix must denote the enclosing scope, i.e.
4219 -- can only be a direct name or an expanded name.
4221 Set_Etype (Sel, Any_Type);
4222 In_Scope := In_Open_Scopes (Prefix_Type);
4224 while Present (Comp) loop
4225 if Chars (Comp) = Chars (Sel) then
4226 if Is_Overloadable (Comp) then
4227 Add_One_Interp (Sel, Comp, Etype (Comp));
4229 -- If the prefix is tagged, the correct interpretation may
4230 -- lie in the primitive or class-wide operations of the
4231 -- type. Perform a simple conformance check to determine
4232 -- whether Try_Object_Operation should be invoked even if
4233 -- a visible entity is found.
4235 if Is_Tagged_Type (Prefix_Type)
4237 Nkind_In (Parent (N), N_Procedure_Call_Statement,
4239 N_Indexed_Component)
4240 and then Has_Mode_Conformant_Spec (Comp)
4242 Has_Candidate := True;
4245 -- Note: a selected component may not denote a component of a
4246 -- protected type (4.1.3(7)).
4248 elsif Ekind_In (Comp, E_Discriminant, E_Entry_Family)
4250 and then not Is_Protected_Type (Prefix_Type)
4251 and then Is_Entity_Name (Name))
4253 Set_Entity_With_Style_Check (Sel, Comp);
4254 Generate_Reference (Comp, Sel);
4256 -- The selector is not overloadable, so we have a candidate
4259 Has_Candidate := True;
4265 Set_Etype (Sel, Etype (Comp));
4266 Set_Etype (N, Etype (Comp));
4268 if Ekind (Comp) = E_Discriminant then
4269 Set_Original_Discriminant (Sel, Comp);
4272 -- For access type case, introduce explicit dereference for
4273 -- more uniform treatment of entry calls.
4275 if Is_Access_Type (Etype (Name)) then
4276 Insert_Explicit_Dereference (Name);
4278 (Warn_On_Dereference, "?d?implicit dereference", N);
4284 exit when not In_Scope
4286 Comp = First_Private_Entity (Base_Type (Prefix_Type));
4289 -- If there is no visible entity with the given name or none of the
4290 -- visible entities are plausible interpretations, check whether
4291 -- there is some other primitive operation with that name.
4293 if Ada_Version >= Ada_2005
4294 and then Is_Tagged_Type (Prefix_Type)
4296 if (Etype (N) = Any_Type
4297 or else not Has_Candidate)
4298 and then Try_Object_Operation (N)
4302 -- If the context is not syntactically a procedure call, it
4303 -- may be a call to a primitive function declared outside of
4304 -- the synchronized type.
4306 -- If the context is a procedure call, there might still be
4307 -- an overloading between an entry and a primitive procedure
4308 -- declared outside of the synchronized type, called in prefix
4309 -- notation. This is harder to disambiguate because in one case
4310 -- the controlling formal is implicit ???
4312 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
4313 and then Nkind (Parent (N)) /= N_Indexed_Component
4314 and then Try_Object_Operation (N)
4319 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
4320 -- entry or procedure of a tagged concurrent type we must check
4321 -- if there are class-wide subprograms covering the primitive. If
4322 -- true then Try_Object_Operation reports the error.
4325 and then Is_Concurrent_Type (Prefix_Type)
4326 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
4328 -- Duplicate the call. This is required to avoid problems with
4329 -- the tree transformations performed by Try_Object_Operation.
4330 -- Set properly the parent of the copied call, because it is
4331 -- about to be reanalyzed.
4335 Par : constant Node_Id := New_Copy_Tree (Parent (N));
4338 Set_Parent (Par, Parent (Parent (N)));
4340 if Try_Object_Operation
4341 (Sinfo.Name (Par), CW_Test_Only => True)
4349 if Etype (N) = Any_Type and then Is_Protected_Type (Prefix_Type) then
4351 -- Case of a prefix of a protected type: selector might denote
4352 -- an invisible private component.
4354 Comp := First_Private_Entity (Base_Type (Prefix_Type));
4355 while Present (Comp) and then Chars (Comp) /= Chars (Sel) loop
4359 if Present (Comp) then
4360 if Is_Single_Concurrent_Object then
4361 Error_Msg_Node_2 := Entity (Name);
4362 Error_Msg_NE ("invisible selector& for &", N, Sel);
4365 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4366 Error_Msg_NE ("invisible selector& for }", N, Sel);
4372 Set_Is_Overloaded (N, Is_Overloaded (Sel));
4377 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
4380 -- If N still has no type, the component is not defined in the prefix
4382 if Etype (N) = Any_Type then
4384 if Is_Single_Concurrent_Object then
4385 Error_Msg_Node_2 := Entity (Name);
4386 Error_Msg_NE ("no selector& for&", N, Sel);
4388 Check_Misspelled_Selector (Type_To_Use, Sel);
4390 elsif Is_Generic_Type (Prefix_Type)
4391 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
4392 and then Prefix_Type /= Etype (Prefix_Type)
4393 and then Is_Record_Type (Etype (Prefix_Type))
4395 -- If this is a derived formal type, the parent may have
4396 -- different visibility at this point. Try for an inherited
4397 -- component before reporting an error.
4399 Set_Etype (Prefix (N), Etype (Prefix_Type));
4400 Analyze_Selected_Component (N);
4403 -- Similarly, if this is the actual for a formal derived type, the
4404 -- component inherited from the generic parent may not be visible
4405 -- in the actual, but the selected component is legal.
4407 elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
4408 and then Is_Generic_Actual_Type (Prefix_Type)
4409 and then Present (Full_View (Prefix_Type))
4412 Find_Component_In_Instance
4413 (Generic_Parent_Type (Parent (Prefix_Type)));
4416 -- Finally, the formal and the actual may be private extensions,
4417 -- but the generic is declared in a child unit of the parent, and
4418 -- an additional step is needed to retrieve the proper scope.
4421 and then Present (Parent_Subtype (Etype (Base_Type (Prefix_Type))))
4423 Find_Component_In_Instance
4424 (Parent_Subtype (Etype (Base_Type (Prefix_Type))));
4427 -- Component not found, specialize error message when appropriate
4430 if Ekind (Prefix_Type) = E_Record_Subtype then
4432 -- Check whether this is a component of the base type which
4433 -- is absent from a statically constrained subtype. This will
4434 -- raise constraint error at run time, but is not a compile-
4435 -- time error. When the selector is illegal for base type as
4436 -- well fall through and generate a compilation error anyway.
4438 Comp := First_Component (Base_Type (Prefix_Type));
4439 while Present (Comp) loop
4440 if Chars (Comp) = Chars (Sel)
4441 and then Is_Visible_Component (Comp)
4443 Set_Entity_With_Style_Check (Sel, Comp);
4444 Generate_Reference (Comp, Sel);
4445 Set_Etype (Sel, Etype (Comp));
4446 Set_Etype (N, Etype (Comp));
4448 -- Emit appropriate message. Gigi will replace the
4449 -- node subsequently with the appropriate Raise.
4451 -- In Alfa mode, this is made into an error to simplify
4452 -- the processing of the formal verification backend.
4455 Apply_Compile_Time_Constraint_Error
4456 (N, "component not present in }",
4457 CE_Discriminant_Check_Failed,
4458 Ent => Prefix_Type, Rep => False);
4460 Apply_Compile_Time_Constraint_Error
4461 (N, "component not present in }??",
4462 CE_Discriminant_Check_Failed,
4463 Ent => Prefix_Type, Rep => False);
4466 Set_Raises_Constraint_Error (N);
4470 Next_Component (Comp);
4475 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4476 Error_Msg_NE ("no selector& for}", N, Sel);
4478 -- Add information in the case of an incomplete prefix
4480 if Is_Incomplete_Type (Type_To_Use) then
4482 Inc : constant Entity_Id := First_Subtype (Type_To_Use);
4485 if From_With_Type (Scope (Type_To_Use)) then
4487 ("\limited view of& has no components", N, Inc);
4491 ("\premature usage of incomplete type&", N, Inc);
4493 if Nkind (Parent (Inc)) =
4494 N_Incomplete_Type_Declaration
4496 -- Record location of premature use in entity so that
4497 -- a continuation message is generated when the
4498 -- completion is seen.
4500 Set_Premature_Use (Parent (Inc), N);
4506 Check_Misspelled_Selector (Type_To_Use, Sel);
4509 Set_Entity (Sel, Any_Id);
4510 Set_Etype (Sel, Any_Type);
4512 end Analyze_Selected_Component;
4514 ---------------------------
4515 -- Analyze_Short_Circuit --
4516 ---------------------------
4518 procedure Analyze_Short_Circuit (N : Node_Id) is
4519 L : constant Node_Id := Left_Opnd (N);
4520 R : constant Node_Id := Right_Opnd (N);
4525 Analyze_Expression (L);
4526 Analyze_Expression (R);
4527 Set_Etype (N, Any_Type);
4529 if not Is_Overloaded (L) then
4530 if Root_Type (Etype (L)) = Standard_Boolean
4531 and then Has_Compatible_Type (R, Etype (L))
4533 Add_One_Interp (N, Etype (L), Etype (L));
4537 Get_First_Interp (L, Ind, It);
4538 while Present (It.Typ) loop
4539 if Root_Type (It.Typ) = Standard_Boolean
4540 and then Has_Compatible_Type (R, It.Typ)
4542 Add_One_Interp (N, It.Typ, It.Typ);
4545 Get_Next_Interp (Ind, It);
4549 -- Here we have failed to find an interpretation. Clearly we know that
4550 -- it is not the case that both operands can have an interpretation of
4551 -- Boolean, but this is by far the most likely intended interpretation.
4552 -- So we simply resolve both operands as Booleans, and at least one of
4553 -- these resolutions will generate an error message, and we do not need
4554 -- to give another error message on the short circuit operation itself.
4556 if Etype (N) = Any_Type then
4557 Resolve (L, Standard_Boolean);
4558 Resolve (R, Standard_Boolean);
4559 Set_Etype (N, Standard_Boolean);
4561 end Analyze_Short_Circuit;
4567 procedure Analyze_Slice (N : Node_Id) is
4568 D : constant Node_Id := Discrete_Range (N);
4569 P : constant Node_Id := Prefix (N);
4570 Array_Type : Entity_Id;
4571 Index_Type : Entity_Id;
4573 procedure Analyze_Overloaded_Slice;
4574 -- If the prefix is overloaded, select those interpretations that
4575 -- yield a one-dimensional array type.
4577 ------------------------------
4578 -- Analyze_Overloaded_Slice --
4579 ------------------------------
4581 procedure Analyze_Overloaded_Slice is
4587 Set_Etype (N, Any_Type);
4589 Get_First_Interp (P, I, It);
4590 while Present (It.Nam) loop
4593 if Is_Access_Type (Typ) then
4594 Typ := Designated_Type (Typ);
4596 (Warn_On_Dereference, "?d?implicit dereference", N);
4599 if Is_Array_Type (Typ)
4600 and then Number_Dimensions (Typ) = 1
4601 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
4603 Add_One_Interp (N, Typ, Typ);
4606 Get_Next_Interp (I, It);
4609 if Etype (N) = Any_Type then
4610 Error_Msg_N ("expect array type in prefix of slice", N);
4612 end Analyze_Overloaded_Slice;
4614 -- Start of processing for Analyze_Slice
4617 if Comes_From_Source (N) then
4618 Check_SPARK_Restriction ("slice is not allowed", N);
4624 if Is_Overloaded (P) then
4625 Analyze_Overloaded_Slice;
4628 Array_Type := Etype (P);
4629 Set_Etype (N, Any_Type);
4631 if Is_Access_Type (Array_Type) then
4632 Array_Type := Designated_Type (Array_Type);
4633 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
4636 if not Is_Array_Type (Array_Type) then
4637 Wrong_Type (P, Any_Array);
4639 elsif Number_Dimensions (Array_Type) > 1 then
4641 ("type is not one-dimensional array in slice prefix", N);
4644 if Ekind (Array_Type) = E_String_Literal_Subtype then
4645 Index_Type := Etype (String_Literal_Low_Bound (Array_Type));
4647 Index_Type := Etype (First_Index (Array_Type));
4650 if not Has_Compatible_Type (D, Index_Type) then
4651 Wrong_Type (D, Index_Type);
4653 Set_Etype (N, Array_Type);
4659 -----------------------------
4660 -- Analyze_Type_Conversion --
4661 -----------------------------
4663 procedure Analyze_Type_Conversion (N : Node_Id) is
4664 Expr : constant Node_Id := Expression (N);
4668 -- If Conversion_OK is set, then the Etype is already set, and the
4669 -- only processing required is to analyze the expression. This is
4670 -- used to construct certain "illegal" conversions which are not
4671 -- allowed by Ada semantics, but can be handled OK by Gigi, see
4672 -- Sinfo for further details.
4674 if Conversion_OK (N) then
4679 -- Otherwise full type analysis is required, as well as some semantic
4680 -- checks to make sure the argument of the conversion is appropriate.
4682 Find_Type (Subtype_Mark (N));
4683 T := Entity (Subtype_Mark (N));
4685 Check_Fully_Declared (T, N);
4686 Analyze_Expression (Expr);
4687 Validate_Remote_Type_Type_Conversion (N);
4689 -- Only remaining step is validity checks on the argument. These
4690 -- are skipped if the conversion does not come from the source.
4692 if not Comes_From_Source (N) then
4695 -- If there was an error in a generic unit, no need to replicate the
4696 -- error message. Conversely, constant-folding in the generic may
4697 -- transform the argument of a conversion into a string literal, which
4698 -- is legal. Therefore the following tests are not performed in an
4701 elsif In_Instance then
4704 elsif Nkind (Expr) = N_Null then
4705 Error_Msg_N ("argument of conversion cannot be null", N);
4706 Error_Msg_N ("\use qualified expression instead", N);
4707 Set_Etype (N, Any_Type);
4709 elsif Nkind (Expr) = N_Aggregate then
4710 Error_Msg_N ("argument of conversion cannot be aggregate", N);
4711 Error_Msg_N ("\use qualified expression instead", N);
4713 elsif Nkind (Expr) = N_Allocator then
4714 Error_Msg_N ("argument of conversion cannot be an allocator", N);
4715 Error_Msg_N ("\use qualified expression instead", N);
4717 elsif Nkind (Expr) = N_String_Literal then
4718 Error_Msg_N ("argument of conversion cannot be string literal", N);
4719 Error_Msg_N ("\use qualified expression instead", N);
4721 elsif Nkind (Expr) = N_Character_Literal then
4722 if Ada_Version = Ada_83 then
4725 Error_Msg_N ("argument of conversion cannot be character literal",
4727 Error_Msg_N ("\use qualified expression instead", N);
4730 elsif Nkind (Expr) = N_Attribute_Reference
4732 (Attribute_Name (Expr) = Name_Access or else
4733 Attribute_Name (Expr) = Name_Unchecked_Access or else
4734 Attribute_Name (Expr) = Name_Unrestricted_Access)
4736 Error_Msg_N ("argument of conversion cannot be access", N);
4737 Error_Msg_N ("\use qualified expression instead", N);
4739 end Analyze_Type_Conversion;
4741 ----------------------
4742 -- Analyze_Unary_Op --
4743 ----------------------
4745 procedure Analyze_Unary_Op (N : Node_Id) is
4746 R : constant Node_Id := Right_Opnd (N);
4747 Op_Id : Entity_Id := Entity (N);
4750 Set_Etype (N, Any_Type);
4751 Candidate_Type := Empty;
4753 Analyze_Expression (R);
4755 if Present (Op_Id) then
4756 if Ekind (Op_Id) = E_Operator then
4757 Find_Unary_Types (R, Op_Id, N);
4759 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4763 Op_Id := Get_Name_Entity_Id (Chars (N));
4764 while Present (Op_Id) loop
4765 if Ekind (Op_Id) = E_Operator then
4766 if No (Next_Entity (First_Entity (Op_Id))) then
4767 Find_Unary_Types (R, Op_Id, N);
4770 elsif Is_Overloadable (Op_Id) then
4771 Analyze_User_Defined_Unary_Op (N, Op_Id);
4774 Op_Id := Homonym (Op_Id);
4779 end Analyze_Unary_Op;
4781 ----------------------------------
4782 -- Analyze_Unchecked_Expression --
4783 ----------------------------------
4785 procedure Analyze_Unchecked_Expression (N : Node_Id) is
4787 Analyze (Expression (N), Suppress => All_Checks);
4788 Set_Etype (N, Etype (Expression (N)));
4789 Save_Interps (Expression (N), N);
4790 end Analyze_Unchecked_Expression;
4792 ---------------------------------------
4793 -- Analyze_Unchecked_Type_Conversion --
4794 ---------------------------------------
4796 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
4798 Find_Type (Subtype_Mark (N));
4799 Analyze_Expression (Expression (N));
4800 Set_Etype (N, Entity (Subtype_Mark (N)));
4801 end Analyze_Unchecked_Type_Conversion;
4803 ------------------------------------
4804 -- Analyze_User_Defined_Binary_Op --
4805 ------------------------------------
4807 procedure Analyze_User_Defined_Binary_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 F1 : constant Entity_Id := First_Formal (Op_Id);
4819 F2 : constant Entity_Id := Next_Formal (F1);
4822 -- Verify that Op_Id is a visible binary function. Note that since
4823 -- we know Op_Id is overloaded, potentially use visible means use
4824 -- visible for sure (RM 9.4(11)).
4826 if Ekind (Op_Id) = E_Function
4827 and then Present (F2)
4828 and then (Is_Immediately_Visible (Op_Id)
4829 or else Is_Potentially_Use_Visible (Op_Id))
4830 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
4831 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
4833 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4835 -- If the left operand is overloaded, indicate that the
4836 -- current type is a viable candidate. This is redundant
4837 -- in most cases, but for equality and comparison operators
4838 -- where the context does not impose a type on the operands,
4839 -- setting the proper type is necessary to avoid subsequent
4840 -- ambiguities during resolution, when both user-defined and
4841 -- predefined operators may be candidates.
4843 if Is_Overloaded (Left_Opnd (N)) then
4844 Set_Etype (Left_Opnd (N), Etype (F1));
4847 if Debug_Flag_E then
4848 Write_Str ("user defined operator ");
4849 Write_Name (Chars (Op_Id));
4850 Write_Str (" on node ");
4851 Write_Int (Int (N));
4857 end Analyze_User_Defined_Binary_Op;
4859 -----------------------------------
4860 -- Analyze_User_Defined_Unary_Op --
4861 -----------------------------------
4863 procedure Analyze_User_Defined_Unary_Op
4868 -- Only do analysis if the operator Comes_From_Source, since otherwise
4869 -- the operator was generated by the expander, and all such operators
4870 -- always refer to the operators in package Standard.
4872 if Comes_From_Source (N) then
4874 F : constant Entity_Id := First_Formal (Op_Id);
4877 -- Verify that Op_Id is a visible unary function. Note that since
4878 -- we know Op_Id is overloaded, potentially use visible means use
4879 -- visible for sure (RM 9.4(11)).
4881 if Ekind (Op_Id) = E_Function
4882 and then No (Next_Formal (F))
4883 and then (Is_Immediately_Visible (Op_Id)
4884 or else Is_Potentially_Use_Visible (Op_Id))
4885 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
4887 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4891 end Analyze_User_Defined_Unary_Op;
4893 ---------------------------
4894 -- Check_Arithmetic_Pair --
4895 ---------------------------
4897 procedure Check_Arithmetic_Pair
4898 (T1, T2 : Entity_Id;
4902 Op_Name : constant Name_Id := Chars (Op_Id);
4904 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
4905 -- Check whether the fixed-point type Typ has a user-defined operator
4906 -- (multiplication or division) that should hide the corresponding
4907 -- predefined operator. Used to implement Ada 2005 AI-264, to make
4908 -- such operators more visible and therefore useful.
4910 -- If the name of the operation is an expanded name with prefix
4911 -- Standard, the predefined universal fixed operator is available,
4912 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
4914 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
4915 -- Get specific type (i.e. non-universal type if there is one)
4921 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
4922 Bas : constant Entity_Id := Base_Type (Typ);
4928 -- If the universal_fixed operation is given explicitly the rule
4929 -- concerning primitive operations of the type do not apply.
4931 if Nkind (N) = N_Function_Call
4932 and then Nkind (Name (N)) = N_Expanded_Name
4933 and then Entity (Prefix (Name (N))) = Standard_Standard
4938 -- The operation is treated as primitive if it is declared in the
4939 -- same scope as the type, and therefore on the same entity chain.
4941 Ent := Next_Entity (Typ);
4942 while Present (Ent) loop
4943 if Chars (Ent) = Chars (Op) then
4944 F1 := First_Formal (Ent);
4945 F2 := Next_Formal (F1);
4947 -- The operation counts as primitive if either operand or
4948 -- result are of the given base type, and both operands are
4949 -- fixed point types.
4951 if (Base_Type (Etype (F1)) = Bas
4952 and then Is_Fixed_Point_Type (Etype (F2)))
4955 (Base_Type (Etype (F2)) = Bas
4956 and then Is_Fixed_Point_Type (Etype (F1)))
4959 (Base_Type (Etype (Ent)) = Bas
4960 and then Is_Fixed_Point_Type (Etype (F1))
4961 and then Is_Fixed_Point_Type (Etype (F2)))
4977 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
4979 if T1 = Universal_Integer or else T1 = Universal_Real then
4980 return Base_Type (T2);
4982 return Base_Type (T1);
4986 -- Start of processing for Check_Arithmetic_Pair
4989 if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
4991 if Is_Numeric_Type (T1)
4992 and then Is_Numeric_Type (T2)
4993 and then (Covers (T1 => T1, T2 => T2)
4995 Covers (T1 => T2, T2 => T1))
4997 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5000 elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
5002 if Is_Fixed_Point_Type (T1)
5003 and then (Is_Fixed_Point_Type (T2)
5004 or else T2 = Universal_Real)
5006 -- If Treat_Fixed_As_Integer is set then the Etype is already set
5007 -- and no further processing is required (this is the case of an
5008 -- operator constructed by Exp_Fixd for a fixed point operation)
5009 -- Otherwise add one interpretation with universal fixed result
5010 -- If the operator is given in functional notation, it comes
5011 -- from source and Fixed_As_Integer cannot apply.
5013 if (Nkind (N) not in N_Op
5014 or else not Treat_Fixed_As_Integer (N))
5016 (not Has_Fixed_Op (T1, Op_Id)
5017 or else Nkind (Parent (N)) = N_Type_Conversion)
5019 Add_One_Interp (N, Op_Id, Universal_Fixed);
5022 elsif Is_Fixed_Point_Type (T2)
5023 and then (Nkind (N) not in N_Op
5024 or else not Treat_Fixed_As_Integer (N))
5025 and then T1 = Universal_Real
5027 (not Has_Fixed_Op (T1, Op_Id)
5028 or else Nkind (Parent (N)) = N_Type_Conversion)
5030 Add_One_Interp (N, Op_Id, Universal_Fixed);
5032 elsif Is_Numeric_Type (T1)
5033 and then Is_Numeric_Type (T2)
5034 and then (Covers (T1 => T1, T2 => T2)
5036 Covers (T1 => T2, T2 => T1))
5038 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5040 elsif Is_Fixed_Point_Type (T1)
5041 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5042 or else T2 = Universal_Integer)
5044 Add_One_Interp (N, Op_Id, T1);
5046 elsif T2 = Universal_Real
5047 and then Base_Type (T1) = Base_Type (Standard_Integer)
5048 and then Op_Name = Name_Op_Multiply
5050 Add_One_Interp (N, Op_Id, Any_Fixed);
5052 elsif T1 = Universal_Real
5053 and then Base_Type (T2) = Base_Type (Standard_Integer)
5055 Add_One_Interp (N, Op_Id, Any_Fixed);
5057 elsif Is_Fixed_Point_Type (T2)
5058 and then (Base_Type (T1) = Base_Type (Standard_Integer)
5059 or else T1 = Universal_Integer)
5060 and then Op_Name = Name_Op_Multiply
5062 Add_One_Interp (N, Op_Id, T2);
5064 elsif T1 = Universal_Real and then T2 = Universal_Integer then
5065 Add_One_Interp (N, Op_Id, T1);
5067 elsif T2 = Universal_Real
5068 and then T1 = Universal_Integer
5069 and then Op_Name = Name_Op_Multiply
5071 Add_One_Interp (N, Op_Id, T2);
5074 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
5076 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
5077 -- set does not require any special processing, since the Etype is
5078 -- already set (case of operation constructed by Exp_Fixed).
5080 if Is_Integer_Type (T1)
5081 and then (Covers (T1 => T1, T2 => T2)
5083 Covers (T1 => T2, T2 => T1))
5085 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5088 elsif Op_Name = Name_Op_Expon then
5089 if Is_Numeric_Type (T1)
5090 and then not Is_Fixed_Point_Type (T1)
5091 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5092 or else T2 = Universal_Integer)
5094 Add_One_Interp (N, Op_Id, Base_Type (T1));
5097 else pragma Assert (Nkind (N) in N_Op_Shift);
5099 -- If not one of the predefined operators, the node may be one
5100 -- of the intrinsic functions. Its kind is always specific, and
5101 -- we can use it directly, rather than the name of the operation.
5103 if Is_Integer_Type (T1)
5104 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5105 or else T2 = Universal_Integer)
5107 Add_One_Interp (N, Op_Id, Base_Type (T1));
5110 end Check_Arithmetic_Pair;
5112 -------------------------------
5113 -- Check_Misspelled_Selector --
5114 -------------------------------
5116 procedure Check_Misspelled_Selector
5117 (Prefix : Entity_Id;
5120 Max_Suggestions : constant := 2;
5121 Nr_Of_Suggestions : Natural := 0;
5123 Suggestion_1 : Entity_Id := Empty;
5124 Suggestion_2 : Entity_Id := Empty;
5129 -- All the components of the prefix of selector Sel are matched
5130 -- against Sel and a count is maintained of possible misspellings.
5131 -- When at the end of the analysis there are one or two (not more!)
5132 -- possible misspellings, these misspellings will be suggested as
5133 -- possible correction.
5135 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
5137 -- Concurrent types should be handled as well ???
5142 Comp := First_Entity (Prefix);
5143 while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
5144 if Is_Visible_Component (Comp) then
5145 if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
5146 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
5148 case Nr_Of_Suggestions is
5149 when 1 => Suggestion_1 := Comp;
5150 when 2 => Suggestion_2 := Comp;
5151 when others => exit;
5156 Comp := Next_Entity (Comp);
5159 -- Report at most two suggestions
5161 if Nr_Of_Suggestions = 1 then
5162 Error_Msg_NE -- CODEFIX
5163 ("\possible misspelling of&", Sel, Suggestion_1);
5165 elsif Nr_Of_Suggestions = 2 then
5166 Error_Msg_Node_2 := Suggestion_2;
5167 Error_Msg_NE -- CODEFIX
5168 ("\possible misspelling of& or&", Sel, Suggestion_1);
5170 end Check_Misspelled_Selector;
5172 ----------------------
5173 -- Defined_In_Scope --
5174 ----------------------
5176 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
5178 S1 : constant Entity_Id := Scope (Base_Type (T));
5181 or else (S1 = System_Aux_Id and then S = Scope (S1));
5182 end Defined_In_Scope;
5188 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
5194 Void_Interp_Seen : Boolean := False;
5197 pragma Warnings (Off, Boolean);
5200 if Ada_Version >= Ada_2005 then
5201 Actual := First_Actual (N);
5202 while Present (Actual) loop
5204 -- Ada 2005 (AI-50217): Post an error in case of premature
5205 -- usage of an entity from the limited view.
5207 if not Analyzed (Etype (Actual))
5208 and then From_With_Type (Etype (Actual))
5210 Error_Msg_Qual_Level := 1;
5212 ("missing with_clause for scope of imported type&",
5213 Actual, Etype (Actual));
5214 Error_Msg_Qual_Level := 0;
5217 Next_Actual (Actual);
5221 -- Analyze each candidate call again, with full error reporting
5225 ("no candidate interpretations match the actuals:!", Nam);
5226 Err_Mode := All_Errors_Mode;
5227 All_Errors_Mode := True;
5229 -- If this is a call to an operation of a concurrent type,
5230 -- the failed interpretations have been removed from the
5231 -- name. Recover them to provide full diagnostics.
5233 if Nkind (Parent (Nam)) = N_Selected_Component then
5234 Set_Entity (Nam, Empty);
5235 New_Nam := New_Copy_Tree (Parent (Nam));
5236 Set_Is_Overloaded (New_Nam, False);
5237 Set_Is_Overloaded (Selector_Name (New_Nam), False);
5238 Set_Parent (New_Nam, Parent (Parent (Nam)));
5239 Analyze_Selected_Component (New_Nam);
5240 Get_First_Interp (Selector_Name (New_Nam), X, It);
5242 Get_First_Interp (Nam, X, It);
5245 while Present (It.Nam) loop
5246 if Etype (It.Nam) = Standard_Void_Type then
5247 Void_Interp_Seen := True;
5250 Analyze_One_Call (N, It.Nam, True, Success);
5251 Get_Next_Interp (X, It);
5254 if Nkind (N) = N_Function_Call then
5255 Get_First_Interp (Nam, X, It);
5256 while Present (It.Nam) loop
5257 if Ekind_In (It.Nam, E_Function, E_Operator) then
5260 Get_Next_Interp (X, It);
5264 -- If all interpretations are procedures, this deserves a
5265 -- more precise message. Ditto if this appears as the prefix
5266 -- of a selected component, which may be a lexical error.
5269 ("\context requires function call, found procedure name", Nam);
5271 if Nkind (Parent (N)) = N_Selected_Component
5272 and then N = Prefix (Parent (N))
5274 Error_Msg_N -- CODEFIX
5275 ("\period should probably be semicolon", Parent (N));
5278 elsif Nkind (N) = N_Procedure_Call_Statement
5279 and then not Void_Interp_Seen
5282 "\function name found in procedure call", Nam);
5285 All_Errors_Mode := Err_Mode;
5288 ---------------------------
5289 -- Find_Arithmetic_Types --
5290 ---------------------------
5292 procedure Find_Arithmetic_Types
5297 Index1 : Interp_Index;
5298 Index2 : Interp_Index;
5302 procedure Check_Right_Argument (T : Entity_Id);
5303 -- Check right operand of operator
5305 --------------------------
5306 -- Check_Right_Argument --
5307 --------------------------
5309 procedure Check_Right_Argument (T : Entity_Id) is
5311 if not Is_Overloaded (R) then
5312 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
5314 Get_First_Interp (R, Index2, It2);
5315 while Present (It2.Typ) loop
5316 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
5317 Get_Next_Interp (Index2, It2);
5320 end Check_Right_Argument;
5322 -- Start of processing for Find_Arithmetic_Types
5325 if not Is_Overloaded (L) then
5326 Check_Right_Argument (Etype (L));
5329 Get_First_Interp (L, Index1, It1);
5330 while Present (It1.Typ) loop
5331 Check_Right_Argument (It1.Typ);
5332 Get_Next_Interp (Index1, It1);
5336 end Find_Arithmetic_Types;
5338 ------------------------
5339 -- Find_Boolean_Types --
5340 ------------------------
5342 procedure Find_Boolean_Types
5347 Index : Interp_Index;
5350 procedure Check_Numeric_Argument (T : Entity_Id);
5351 -- Special case for logical operations one of whose operands is an
5352 -- integer literal. If both are literal the result is any modular type.
5354 ----------------------------
5355 -- Check_Numeric_Argument --
5356 ----------------------------
5358 procedure Check_Numeric_Argument (T : Entity_Id) is
5360 if T = Universal_Integer then
5361 Add_One_Interp (N, Op_Id, Any_Modular);
5363 elsif Is_Modular_Integer_Type (T) then
5364 Add_One_Interp (N, Op_Id, T);
5366 end Check_Numeric_Argument;
5368 -- Start of processing for Find_Boolean_Types
5371 if not Is_Overloaded (L) then
5372 if Etype (L) = Universal_Integer
5373 or else Etype (L) = Any_Modular
5375 if not Is_Overloaded (R) then
5376 Check_Numeric_Argument (Etype (R));
5379 Get_First_Interp (R, Index, It);
5380 while Present (It.Typ) loop
5381 Check_Numeric_Argument (It.Typ);
5382 Get_Next_Interp (Index, It);
5386 -- If operands are aggregates, we must assume that they may be
5387 -- boolean arrays, and leave disambiguation for the second pass.
5388 -- If only one is an aggregate, verify that the other one has an
5389 -- interpretation as a boolean array
5391 elsif Nkind (L) = N_Aggregate then
5392 if Nkind (R) = N_Aggregate then
5393 Add_One_Interp (N, Op_Id, Etype (L));
5395 elsif not Is_Overloaded (R) then
5396 if Valid_Boolean_Arg (Etype (R)) then
5397 Add_One_Interp (N, Op_Id, Etype (R));
5401 Get_First_Interp (R, Index, It);
5402 while Present (It.Typ) loop
5403 if Valid_Boolean_Arg (It.Typ) then
5404 Add_One_Interp (N, Op_Id, It.Typ);
5407 Get_Next_Interp (Index, It);
5411 elsif Valid_Boolean_Arg (Etype (L))
5412 and then Has_Compatible_Type (R, Etype (L))
5414 Add_One_Interp (N, Op_Id, Etype (L));
5418 Get_First_Interp (L, Index, It);
5419 while Present (It.Typ) loop
5420 if Valid_Boolean_Arg (It.Typ)
5421 and then Has_Compatible_Type (R, It.Typ)
5423 Add_One_Interp (N, Op_Id, It.Typ);
5426 Get_Next_Interp (Index, It);
5429 end Find_Boolean_Types;
5431 ---------------------------
5432 -- Find_Comparison_Types --
5433 ---------------------------
5435 procedure Find_Comparison_Types
5440 Index : Interp_Index;
5442 Found : Boolean := False;
5445 Scop : Entity_Id := Empty;
5447 procedure Try_One_Interp (T1 : Entity_Id);
5448 -- Routine to try one proposed interpretation. Note that the context
5449 -- of the operator plays no role in resolving the arguments, so that
5450 -- if there is more than one interpretation of the operands that is
5451 -- compatible with comparison, the operation is ambiguous.
5453 --------------------
5454 -- Try_One_Interp --
5455 --------------------
5457 procedure Try_One_Interp (T1 : Entity_Id) is
5460 -- If the operator is an expanded name, then the type of the operand
5461 -- must be defined in the corresponding scope. If the type is
5462 -- universal, the context will impose the correct type.
5465 and then not Defined_In_Scope (T1, Scop)
5466 and then T1 /= Universal_Integer
5467 and then T1 /= Universal_Real
5468 and then T1 /= Any_String
5469 and then T1 /= Any_Composite
5474 if Valid_Comparison_Arg (T1)
5475 and then Has_Compatible_Type (R, T1)
5478 and then Base_Type (T1) /= Base_Type (T_F)
5480 It := Disambiguate (L, I_F, Index, Any_Type);
5482 if It = No_Interp then
5483 Ambiguous_Operands (N);
5484 Set_Etype (L, Any_Type);
5498 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
5503 -- Start of processing for Find_Comparison_Types
5506 -- If left operand is aggregate, the right operand has to
5507 -- provide a usable type for it.
5509 if Nkind (L) = N_Aggregate
5510 and then Nkind (R) /= N_Aggregate
5512 Find_Comparison_Types (L => R, R => L, Op_Id => Op_Id, N => N);
5516 if Nkind (N) = N_Function_Call
5517 and then Nkind (Name (N)) = N_Expanded_Name
5519 Scop := Entity (Prefix (Name (N)));
5521 -- The prefix may be a package renaming, and the subsequent test
5522 -- requires the original package.
5524 if Ekind (Scop) = E_Package
5525 and then Present (Renamed_Entity (Scop))
5527 Scop := Renamed_Entity (Scop);
5528 Set_Entity (Prefix (Name (N)), Scop);
5532 if not Is_Overloaded (L) then
5533 Try_One_Interp (Etype (L));
5536 Get_First_Interp (L, Index, It);
5537 while Present (It.Typ) loop
5538 Try_One_Interp (It.Typ);
5539 Get_Next_Interp (Index, It);
5542 end Find_Comparison_Types;
5544 ----------------------------------------
5545 -- Find_Non_Universal_Interpretations --
5546 ----------------------------------------
5548 procedure Find_Non_Universal_Interpretations
5554 Index : Interp_Index;
5558 if T1 = Universal_Integer
5559 or else T1 = Universal_Real
5561 -- If the left operand of an equality operator is null, the visibility
5562 -- of the operator must be determined from the interpretation of the
5563 -- right operand. This processing must be done for Any_Access, which
5564 -- is the internal representation of the type of the literal null.
5566 or else T1 = Any_Access
5568 if not Is_Overloaded (R) then
5570 (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
5572 Get_First_Interp (R, Index, It);
5573 while Present (It.Typ) loop
5574 if Covers (It.Typ, T1) then
5576 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
5579 Get_Next_Interp (Index, It);
5583 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
5585 end Find_Non_Universal_Interpretations;
5587 ------------------------------
5588 -- Find_Concatenation_Types --
5589 ------------------------------
5591 procedure Find_Concatenation_Types
5596 Op_Type : constant Entity_Id := Etype (Op_Id);
5599 if Is_Array_Type (Op_Type)
5600 and then not Is_Limited_Type (Op_Type)
5602 and then (Has_Compatible_Type (L, Op_Type)
5604 Has_Compatible_Type (L, Component_Type (Op_Type)))
5606 and then (Has_Compatible_Type (R, Op_Type)
5608 Has_Compatible_Type (R, Component_Type (Op_Type)))
5610 Add_One_Interp (N, Op_Id, Op_Type);
5612 end Find_Concatenation_Types;
5614 -------------------------
5615 -- Find_Equality_Types --
5616 -------------------------
5618 procedure Find_Equality_Types
5623 Index : Interp_Index;
5625 Found : Boolean := False;
5628 Scop : Entity_Id := Empty;
5630 procedure Try_One_Interp (T1 : Entity_Id);
5631 -- The context of the equality operator plays no role in resolving the
5632 -- arguments, so that if there is more than one interpretation of the
5633 -- operands that is compatible with equality, the construct is ambiguous
5634 -- and an error can be emitted now, after trying to disambiguate, i.e.
5635 -- applying preference rules.
5637 --------------------
5638 -- Try_One_Interp --
5639 --------------------
5641 procedure Try_One_Interp (T1 : Entity_Id) is
5642 Bas : constant Entity_Id := Base_Type (T1);
5645 -- If the operator is an expanded name, then the type of the operand
5646 -- must be defined in the corresponding scope. If the type is
5647 -- universal, the context will impose the correct type. An anonymous
5648 -- type for a 'Access reference is also universal in this sense, as
5649 -- the actual type is obtained from context.
5650 -- In Ada 2005, the equality operator for anonymous access types
5651 -- is declared in Standard, and preference rules apply to it.
5653 if Present (Scop) then
5654 if Defined_In_Scope (T1, Scop)
5655 or else T1 = Universal_Integer
5656 or else T1 = Universal_Real
5657 or else T1 = Any_Access
5658 or else T1 = Any_String
5659 or else T1 = Any_Composite
5660 or else (Ekind (T1) = E_Access_Subprogram_Type
5661 and then not Comes_From_Source (T1))
5665 elsif Ekind (T1) = E_Anonymous_Access_Type
5666 and then Scop = Standard_Standard
5671 -- The scope does not contain an operator for the type
5676 -- If we have infix notation, the operator must be usable. Within
5677 -- an instance, if the type is already established we know it is
5678 -- correct. If an operand is universal it is compatible with any
5681 -- In Ada 2005, the equality on anonymous access types is declared
5682 -- in Standard, and is always visible.
5684 elsif In_Open_Scopes (Scope (Bas))
5685 or else Is_Potentially_Use_Visible (Bas)
5686 or else In_Use (Bas)
5687 or else (In_Use (Scope (Bas)) and then not Is_Hidden (Bas))
5688 or else (In_Instance
5690 (First_Subtype (T1) = First_Subtype (Etype (R))
5692 (Is_Numeric_Type (T1)
5693 and then Is_Universal_Numeric_Type (Etype (R)))))
5694 or else Ekind (T1) = E_Anonymous_Access_Type
5699 -- Save candidate type for subsequent error message, if any
5701 if not Is_Limited_Type (T1) then
5702 Candidate_Type := T1;
5708 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
5709 -- Do not allow anonymous access types in equality operators.
5711 if Ada_Version < Ada_2005
5712 and then Ekind (T1) = E_Anonymous_Access_Type
5717 -- If the right operand has a type compatible with T1, check for an
5718 -- acceptable interpretation, unless T1 is limited (no predefined
5719 -- equality available), or this is use of a "/=" for a tagged type.
5720 -- In the latter case, possible interpretations of equality need to
5721 -- be considered, we don't want the default inequality declared in
5722 -- Standard to be chosen, and the "/=" will be rewritten as a
5723 -- negation of "=" (see the end of Analyze_Equality_Op). This ensures
5724 -- that that rewriting happens during analysis rather than being
5725 -- delayed until expansion (this is needed for ASIS, which only sees
5726 -- the unexpanded tree). Note that if the node is N_Op_Ne, but Op_Id
5727 -- is Name_Op_Eq then we still proceed with the interpretation,
5728 -- because that indicates the potential rewriting case where the
5729 -- interpretation to consider is actually "=" and the node may be
5730 -- about to be rewritten by Analyze_Equality_Op.
5732 if T1 /= Standard_Void_Type
5733 and then Has_Compatible_Type (R, T1)
5736 ((not Is_Limited_Type (T1)
5737 and then not Is_Limited_Composite (T1))
5741 and then not Is_Limited_Type (Component_Type (T1))
5742 and then Available_Full_View_Of_Component (T1)))
5745 (Nkind (N) /= N_Op_Ne
5746 or else not Is_Tagged_Type (T1)
5747 or else Chars (Op_Id) = Name_Op_Eq)
5750 and then Base_Type (T1) /= Base_Type (T_F)
5752 It := Disambiguate (L, I_F, Index, Any_Type);
5754 if It = No_Interp then
5755 Ambiguous_Operands (N);
5756 Set_Etype (L, Any_Type);
5769 if not Analyzed (L) then
5773 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
5775 -- Case of operator was not visible, Etype still set to Any_Type
5777 if Etype (N) = Any_Type then
5781 elsif Scop = Standard_Standard
5782 and then Ekind (T1) = E_Anonymous_Access_Type
5788 -- Start of processing for Find_Equality_Types
5791 -- If left operand is aggregate, the right operand has to
5792 -- provide a usable type for it.
5794 if Nkind (L) = N_Aggregate
5795 and then Nkind (R) /= N_Aggregate
5797 Find_Equality_Types (L => R, R => L, Op_Id => Op_Id, N => N);
5801 if Nkind (N) = N_Function_Call
5802 and then Nkind (Name (N)) = N_Expanded_Name
5804 Scop := Entity (Prefix (Name (N)));
5806 -- The prefix may be a package renaming, and the subsequent test
5807 -- requires the original package.
5809 if Ekind (Scop) = E_Package
5810 and then Present (Renamed_Entity (Scop))
5812 Scop := Renamed_Entity (Scop);
5813 Set_Entity (Prefix (Name (N)), Scop);
5817 if not Is_Overloaded (L) then
5818 Try_One_Interp (Etype (L));
5821 Get_First_Interp (L, Index, It);
5822 while Present (It.Typ) loop
5823 Try_One_Interp (It.Typ);
5824 Get_Next_Interp (Index, It);
5827 end Find_Equality_Types;
5829 -------------------------
5830 -- Find_Negation_Types --
5831 -------------------------
5833 procedure Find_Negation_Types
5838 Index : Interp_Index;
5842 if not Is_Overloaded (R) then
5843 if Etype (R) = Universal_Integer then
5844 Add_One_Interp (N, Op_Id, Any_Modular);
5845 elsif Valid_Boolean_Arg (Etype (R)) then
5846 Add_One_Interp (N, Op_Id, Etype (R));
5850 Get_First_Interp (R, Index, It);
5851 while Present (It.Typ) loop
5852 if Valid_Boolean_Arg (It.Typ) then
5853 Add_One_Interp (N, Op_Id, It.Typ);
5856 Get_Next_Interp (Index, It);
5859 end Find_Negation_Types;
5861 ------------------------------
5862 -- Find_Primitive_Operation --
5863 ------------------------------
5865 function Find_Primitive_Operation (N : Node_Id) return Boolean is
5866 Obj : constant Node_Id := Prefix (N);
5867 Op : constant Node_Id := Selector_Name (N);
5874 Set_Etype (Op, Any_Type);
5876 if Is_Access_Type (Etype (Obj)) then
5877 Typ := Designated_Type (Etype (Obj));
5882 if Is_Class_Wide_Type (Typ) then
5883 Typ := Root_Type (Typ);
5886 Prims := Primitive_Operations (Typ);
5888 Prim := First_Elmt (Prims);
5889 while Present (Prim) loop
5890 if Chars (Node (Prim)) = Chars (Op) then
5891 Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
5892 Set_Etype (N, Etype (Node (Prim)));
5898 -- Now look for class-wide operations of the type or any of its
5899 -- ancestors by iterating over the homonyms of the selector.
5902 Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
5906 Hom := Current_Entity (Op);
5907 while Present (Hom) loop
5908 if (Ekind (Hom) = E_Procedure
5910 Ekind (Hom) = E_Function)
5911 and then Scope (Hom) = Scope (Typ)
5912 and then Present (First_Formal (Hom))
5914 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
5916 (Is_Access_Type (Etype (First_Formal (Hom)))
5918 Ekind (Etype (First_Formal (Hom))) =
5919 E_Anonymous_Access_Type
5922 (Designated_Type (Etype (First_Formal (Hom)))) =
5925 Add_One_Interp (Op, Hom, Etype (Hom));
5926 Set_Etype (N, Etype (Hom));
5929 Hom := Homonym (Hom);
5933 return Etype (Op) /= Any_Type;
5934 end Find_Primitive_Operation;
5936 ----------------------
5937 -- Find_Unary_Types --
5938 ----------------------
5940 procedure Find_Unary_Types
5945 Index : Interp_Index;
5949 if not Is_Overloaded (R) then
5950 if Is_Numeric_Type (Etype (R)) then
5952 -- In an instance a generic actual may be a numeric type even if
5953 -- the formal in the generic unit was not. In that case, the
5954 -- predefined operator was not a possible interpretation in the
5955 -- generic, and cannot be one in the instance.
5959 not Is_Numeric_Type (Corresponding_Generic_Type (Etype (R)))
5963 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
5968 Get_First_Interp (R, Index, It);
5969 while Present (It.Typ) loop
5970 if Is_Numeric_Type (It.Typ) then
5974 (Corresponding_Generic_Type (Etype (It.Typ)))
5979 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
5983 Get_Next_Interp (Index, It);
5986 end Find_Unary_Types;
5992 function Junk_Operand (N : Node_Id) return Boolean is
5996 if Error_Posted (N) then
6000 -- Get entity to be tested
6002 if Is_Entity_Name (N)
6003 and then Present (Entity (N))
6007 -- An odd case, a procedure name gets converted to a very peculiar
6008 -- function call, and here is where we detect this happening.
6010 elsif Nkind (N) = N_Function_Call
6011 and then Is_Entity_Name (Name (N))
6012 and then Present (Entity (Name (N)))
6016 -- Another odd case, there are at least some cases of selected
6017 -- components where the selected component is not marked as having
6018 -- an entity, even though the selector does have an entity
6020 elsif Nkind (N) = N_Selected_Component
6021 and then Present (Entity (Selector_Name (N)))
6023 Enode := Selector_Name (N);
6029 -- Now test the entity we got to see if it is a bad case
6031 case Ekind (Entity (Enode)) is
6035 ("package name cannot be used as operand", Enode);
6037 when Generic_Unit_Kind =>
6039 ("generic unit name cannot be used as operand", Enode);
6043 ("subtype name cannot be used as operand", Enode);
6047 ("entry name cannot be used as operand", Enode);
6051 ("procedure name cannot be used as operand", Enode);
6055 ("exception name cannot be used as operand", Enode);
6057 when E_Block | E_Label | E_Loop =>
6059 ("label name cannot be used as operand", Enode);
6069 --------------------
6070 -- Operator_Check --
6071 --------------------
6073 procedure Operator_Check (N : Node_Id) is
6075 Remove_Abstract_Operations (N);
6077 -- Test for case of no interpretation found for operator
6079 if Etype (N) = Any_Type then
6083 Op_Id : Entity_Id := Empty;
6086 R := Right_Opnd (N);
6088 if Nkind (N) in N_Binary_Op then
6094 -- If either operand has no type, then don't complain further,
6095 -- since this simply means that we have a propagated error.
6098 or else Etype (R) = Any_Type
6099 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
6103 -- We explicitly check for the case of concatenation of component
6104 -- with component to avoid reporting spurious matching array types
6105 -- that might happen to be lurking in distant packages (such as
6106 -- run-time packages). This also prevents inconsistencies in the
6107 -- messages for certain ACVC B tests, which can vary depending on
6108 -- types declared in run-time interfaces. Another improvement when
6109 -- aggregates are present is to look for a well-typed operand.
6111 elsif Present (Candidate_Type)
6112 and then (Nkind (N) /= N_Op_Concat
6113 or else Is_Array_Type (Etype (L))
6114 or else Is_Array_Type (Etype (R)))
6116 if Nkind (N) = N_Op_Concat then
6117 if Etype (L) /= Any_Composite
6118 and then Is_Array_Type (Etype (L))
6120 Candidate_Type := Etype (L);
6122 elsif Etype (R) /= Any_Composite
6123 and then Is_Array_Type (Etype (R))
6125 Candidate_Type := Etype (R);
6129 Error_Msg_NE -- CODEFIX
6130 ("operator for} is not directly visible!",
6131 N, First_Subtype (Candidate_Type));
6134 U : constant Node_Id :=
6135 Cunit (Get_Source_Unit (Candidate_Type));
6137 if Unit_Is_Visible (U) then
6138 Error_Msg_N -- CODEFIX
6139 ("use clause would make operation legal!", N);
6141 Error_Msg_NE -- CODEFIX
6142 ("add with_clause and use_clause for&!",
6143 N, Defining_Entity (Unit (U)));
6148 -- If either operand is a junk operand (e.g. package name), then
6149 -- post appropriate error messages, but do not complain further.
6151 -- Note that the use of OR in this test instead of OR ELSE is
6152 -- quite deliberate, we may as well check both operands in the
6153 -- binary operator case.
6155 elsif Junk_Operand (R)
6156 or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
6160 -- If we have a logical operator, one of whose operands is
6161 -- Boolean, then we know that the other operand cannot resolve to
6162 -- Boolean (since we got no interpretations), but in that case we
6163 -- pretty much know that the other operand should be Boolean, so
6164 -- resolve it that way (generating an error)
6166 elsif Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor) then
6167 if Etype (L) = Standard_Boolean then
6168 Resolve (R, Standard_Boolean);
6170 elsif Etype (R) = Standard_Boolean then
6171 Resolve (L, Standard_Boolean);
6175 -- For an arithmetic operator or comparison operator, if one
6176 -- of the operands is numeric, then we know the other operand
6177 -- is not the same numeric type. If it is a non-numeric type,
6178 -- then probably it is intended to match the other operand.
6180 elsif Nkind_In (N, N_Op_Add,
6186 Nkind_In (N, N_Op_Lt,
6192 if Is_Numeric_Type (Etype (L))
6193 and then not Is_Numeric_Type (Etype (R))
6195 Resolve (R, Etype (L));
6198 elsif Is_Numeric_Type (Etype (R))
6199 and then not Is_Numeric_Type (Etype (L))
6201 Resolve (L, Etype (R));
6205 -- Comparisons on A'Access are common enough to deserve a
6208 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne)
6209 and then Ekind (Etype (L)) = E_Access_Attribute_Type
6210 and then Ekind (Etype (R)) = E_Access_Attribute_Type
6213 ("two access attributes cannot be compared directly", N);
6215 ("\use qualified expression for one of the operands",
6219 -- Another one for C programmers
6221 elsif Nkind (N) = N_Op_Concat
6222 and then Valid_Boolean_Arg (Etype (L))
6223 and then Valid_Boolean_Arg (Etype (R))
6225 Error_Msg_N ("invalid operands for concatenation", N);
6226 Error_Msg_N -- CODEFIX
6227 ("\maybe AND was meant", N);
6230 -- A special case for comparison of access parameter with null
6232 elsif Nkind (N) = N_Op_Eq
6233 and then Is_Entity_Name (L)
6234 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
6235 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
6237 and then Nkind (R) = N_Null
6239 Error_Msg_N ("access parameter is not allowed to be null", L);
6240 Error_Msg_N ("\(call would raise Constraint_Error)", L);
6243 -- Another special case for exponentiation, where the right
6244 -- operand must be Natural, independently of the base.
6246 elsif Nkind (N) = N_Op_Expon
6247 and then Is_Numeric_Type (Etype (L))
6248 and then not Is_Overloaded (R)
6250 First_Subtype (Base_Type (Etype (R))) /= Standard_Integer
6251 and then Base_Type (Etype (R)) /= Universal_Integer
6253 if Ada_Version >= Ada_2012
6254 and then Has_Dimension_System (Etype (L))
6257 ("exponent for dimensioned type must be a rational" &
6258 ", found}", R, Etype (R));
6261 ("exponent must be of type Natural, found}", R, Etype (R));
6267 -- If we fall through then just give general message. Note that in
6268 -- the following messages, if the operand is overloaded we choose
6269 -- an arbitrary type to complain about, but that is probably more
6270 -- useful than not giving a type at all.
6272 if Nkind (N) in N_Unary_Op then
6273 Error_Msg_Node_2 := Etype (R);
6274 Error_Msg_N ("operator& not defined for}", N);
6278 if Nkind (N) in N_Binary_Op then
6279 if not Is_Overloaded (L)
6280 and then not Is_Overloaded (R)
6281 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
6283 Error_Msg_Node_2 := First_Subtype (Etype (R));
6284 Error_Msg_N ("there is no applicable operator& for}", N);
6287 -- Another attempt to find a fix: one of the candidate
6288 -- interpretations may not be use-visible. This has
6289 -- already been checked for predefined operators, so
6290 -- we examine only user-defined functions.
6292 Op_Id := Get_Name_Entity_Id (Chars (N));
6294 while Present (Op_Id) loop
6295 if Ekind (Op_Id) /= E_Operator
6296 and then Is_Overloadable (Op_Id)
6298 if not Is_Immediately_Visible (Op_Id)
6299 and then not In_Use (Scope (Op_Id))
6300 and then not Is_Abstract_Subprogram (Op_Id)
6301 and then not Is_Hidden (Op_Id)
6302 and then Ekind (Scope (Op_Id)) = E_Package
6305 (L, Etype (First_Formal (Op_Id)))
6307 (Next_Formal (First_Formal (Op_Id)))
6311 Etype (Next_Formal (First_Formal (Op_Id))))
6314 ("No legal interpretation for operator&", N);
6316 ("\use clause on& would make operation legal",
6322 Op_Id := Homonym (Op_Id);
6326 Error_Msg_N ("invalid operand types for operator&", N);
6328 if Nkind (N) /= N_Op_Concat then
6329 Error_Msg_NE ("\left operand has}!", N, Etype (L));
6330 Error_Msg_NE ("\right operand has}!", N, Etype (R));
6340 -----------------------------------------
6341 -- Process_Implicit_Dereference_Prefix --
6342 -----------------------------------------
6344 function Process_Implicit_Dereference_Prefix
6346 P : Entity_Id) return Entity_Id
6349 Typ : constant Entity_Id := Designated_Type (Etype (P));
6353 and then (Operating_Mode = Check_Semantics or else not Expander_Active)
6355 -- We create a dummy reference to E to ensure that the reference
6356 -- is not considered as part of an assignment (an implicit
6357 -- dereference can never assign to its prefix). The Comes_From_Source
6358 -- attribute needs to be propagated for accurate warnings.
6360 Ref := New_Reference_To (E, Sloc (P));
6361 Set_Comes_From_Source (Ref, Comes_From_Source (P));
6362 Generate_Reference (E, Ref);
6365 -- An implicit dereference is a legal occurrence of an
6366 -- incomplete type imported through a limited_with clause,
6367 -- if the full view is visible.
6369 if From_With_Type (Typ)
6370 and then not From_With_Type (Scope (Typ))
6372 (Is_Immediately_Visible (Scope (Typ))
6374 (Is_Child_Unit (Scope (Typ))
6375 and then Is_Visible_Lib_Unit (Scope (Typ))))
6377 return Available_View (Typ);
6381 end Process_Implicit_Dereference_Prefix;
6383 --------------------------------
6384 -- Remove_Abstract_Operations --
6385 --------------------------------
6387 procedure Remove_Abstract_Operations (N : Node_Id) is
6388 Abstract_Op : Entity_Id := Empty;
6389 Address_Kludge : Boolean := False;
6393 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
6394 -- activate this if either extensions are enabled, or if the abstract
6395 -- operation in question comes from a predefined file. This latter test
6396 -- allows us to use abstract to make operations invisible to users. In
6397 -- particular, if type Address is non-private and abstract subprograms
6398 -- are used to hide its operators, they will be truly hidden.
6400 type Operand_Position is (First_Op, Second_Op);
6401 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
6403 procedure Remove_Address_Interpretations (Op : Operand_Position);
6404 -- Ambiguities may arise when the operands are literal and the address
6405 -- operations in s-auxdec are visible. In that case, remove the
6406 -- interpretation of a literal as Address, to retain the semantics of
6407 -- Address as a private type.
6409 ------------------------------------
6410 -- Remove_Address_Interpretations --
6411 ------------------------------------
6413 procedure Remove_Address_Interpretations (Op : Operand_Position) is
6417 if Is_Overloaded (N) then
6418 Get_First_Interp (N, I, It);
6419 while Present (It.Nam) loop
6420 Formal := First_Entity (It.Nam);
6422 if Op = Second_Op then
6423 Formal := Next_Entity (Formal);
6426 if Is_Descendent_Of_Address (Etype (Formal)) then
6427 Address_Kludge := True;
6431 Get_Next_Interp (I, It);
6434 end Remove_Address_Interpretations;
6436 -- Start of processing for Remove_Abstract_Operations
6439 if Is_Overloaded (N) then
6440 if Debug_Flag_V then
6441 Write_Str ("Remove_Abstract_Operations: ");
6442 Write_Overloads (N);
6445 Get_First_Interp (N, I, It);
6447 while Present (It.Nam) loop
6448 if Is_Overloadable (It.Nam)
6449 and then Is_Abstract_Subprogram (It.Nam)
6450 and then not Is_Dispatching_Operation (It.Nam)
6452 Abstract_Op := It.Nam;
6454 if Is_Descendent_Of_Address (It.Typ) then
6455 Address_Kludge := True;
6459 -- In Ada 2005, this operation does not participate in overload
6460 -- resolution. If the operation is defined in a predefined
6461 -- unit, it is one of the operations declared abstract in some
6462 -- variants of System, and it must be removed as well.
6464 elsif Ada_Version >= Ada_2005
6465 or else Is_Predefined_File_Name
6466 (Unit_File_Name (Get_Source_Unit (It.Nam)))
6473 Get_Next_Interp (I, It);
6476 if No (Abstract_Op) then
6478 -- If some interpretation yields an integer type, it is still
6479 -- possible that there are address interpretations. Remove them
6480 -- if one operand is a literal, to avoid spurious ambiguities
6481 -- on systems where Address is a visible integer type.
6483 if Is_Overloaded (N)
6484 and then Nkind (N) in N_Op
6485 and then Is_Integer_Type (Etype (N))
6487 if Nkind (N) in N_Binary_Op then
6488 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
6489 Remove_Address_Interpretations (Second_Op);
6491 elsif Nkind (Right_Opnd (N)) = N_Integer_Literal then
6492 Remove_Address_Interpretations (First_Op);
6497 elsif Nkind (N) in N_Op then
6499 -- Remove interpretations that treat literals as addresses. This
6500 -- is never appropriate, even when Address is defined as a visible
6501 -- Integer type. The reason is that we would really prefer Address
6502 -- to behave as a private type, even in this case, which is there
6503 -- only to accommodate oddities of VMS address sizes. If Address
6504 -- is a visible integer type, we get lots of overload ambiguities.
6506 if Nkind (N) in N_Binary_Op then
6508 U1 : constant Boolean :=
6509 Present (Universal_Interpretation (Right_Opnd (N)));
6510 U2 : constant Boolean :=
6511 Present (Universal_Interpretation (Left_Opnd (N)));
6515 Remove_Address_Interpretations (Second_Op);
6519 Remove_Address_Interpretations (First_Op);
6522 if not (U1 and U2) then
6524 -- Remove corresponding predefined operator, which is
6525 -- always added to the overload set.
6527 Get_First_Interp (N, I, It);
6528 while Present (It.Nam) loop
6529 if Scope (It.Nam) = Standard_Standard
6530 and then Base_Type (It.Typ) =
6531 Base_Type (Etype (Abstract_Op))
6536 Get_Next_Interp (I, It);
6539 elsif Is_Overloaded (N)
6540 and then Present (Univ_Type)
6542 -- If both operands have a universal interpretation,
6543 -- it is still necessary to remove interpretations that
6544 -- yield Address. Any remaining ambiguities will be
6545 -- removed in Disambiguate.
6547 Get_First_Interp (N, I, It);
6548 while Present (It.Nam) loop
6549 if Is_Descendent_Of_Address (It.Typ) then
6552 elsif not Is_Type (It.Nam) then
6553 Set_Entity (N, It.Nam);
6556 Get_Next_Interp (I, It);
6562 elsif Nkind (N) = N_Function_Call
6564 (Nkind (Name (N)) = N_Operator_Symbol
6566 (Nkind (Name (N)) = N_Expanded_Name
6568 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
6572 Arg1 : constant Node_Id := First (Parameter_Associations (N));
6573 U1 : constant Boolean :=
6574 Present (Universal_Interpretation (Arg1));
6575 U2 : constant Boolean :=
6576 Present (Next (Arg1)) and then
6577 Present (Universal_Interpretation (Next (Arg1)));
6581 Remove_Address_Interpretations (First_Op);
6585 Remove_Address_Interpretations (Second_Op);
6588 if not (U1 and U2) then
6589 Get_First_Interp (N, I, It);
6590 while Present (It.Nam) loop
6591 if Scope (It.Nam) = Standard_Standard
6592 and then It.Typ = Base_Type (Etype (Abstract_Op))
6597 Get_Next_Interp (I, It);
6603 -- If the removal has left no valid interpretations, emit an error
6604 -- message now and label node as illegal.
6606 if Present (Abstract_Op) then
6607 Get_First_Interp (N, I, It);
6611 -- Removal of abstract operation left no viable candidate
6613 Set_Etype (N, Any_Type);
6614 Error_Msg_Sloc := Sloc (Abstract_Op);
6616 ("cannot call abstract operation& declared#", N, Abstract_Op);
6618 -- In Ada 2005, an abstract operation may disable predefined
6619 -- operators. Since the context is not yet known, we mark the
6620 -- predefined operators as potentially hidden. Do not include
6621 -- predefined operators when addresses are involved since this
6622 -- case is handled separately.
6624 elsif Ada_Version >= Ada_2005
6625 and then not Address_Kludge
6627 while Present (It.Nam) loop
6628 if Is_Numeric_Type (It.Typ)
6629 and then Scope (It.Typ) = Standard_Standard
6631 Set_Abstract_Op (I, Abstract_Op);
6634 Get_Next_Interp (I, It);
6639 if Debug_Flag_V then
6640 Write_Str ("Remove_Abstract_Operations done: ");
6641 Write_Overloads (N);
6644 end Remove_Abstract_Operations;
6646 ----------------------------
6647 -- Try_Container_Indexing --
6648 ----------------------------
6650 function Try_Container_Indexing
6653 Exprs : List_Id) return Boolean
6655 Loc : constant Source_Ptr := Sloc (N);
6659 Func_Name : Node_Id;
6664 -- Check whether type has a specified indexing aspect
6668 if Is_Variable (Prefix) then
6669 Func_Name := Find_Aspect (Etype (Prefix), Aspect_Variable_Indexing);
6672 if No (Func_Name) then
6673 Func_Name := Find_Aspect (Etype (Prefix), Aspect_Constant_Indexing);
6676 -- If aspect does not exist the expression is illegal. Error is
6677 -- diagnosed in caller.
6679 if No (Func_Name) then
6681 -- The prefix itself may be an indexing of a container
6682 -- rewrite as such and re-analyze.
6684 if Has_Implicit_Dereference (Etype (Prefix)) then
6685 Build_Explicit_Dereference
6686 (Prefix, First_Discriminant (Etype (Prefix)));
6687 return Try_Container_Indexing (N, Prefix, Exprs);
6694 Assoc := New_List (Relocate_Node (Prefix));
6696 -- A generalized iterator may have nore than one index expression, so
6697 -- transfer all of them to the argument list to be used in the call.
6702 Arg := First (Exprs);
6703 while Present (Arg) loop
6704 Append (Relocate_Node (Arg), Assoc);
6709 if not Is_Overloaded (Func_Name) then
6710 Func := Entity (Func_Name);
6712 Make_Function_Call (Loc,
6713 Name => New_Occurrence_Of (Func, Loc),
6714 Parameter_Associations => Assoc);
6715 Rewrite (N, Indexing);
6718 -- If the return type of the indexing function is a reference type,
6719 -- add the dereference as a possible interpretation. Note that the
6720 -- indexing aspect may be a function that returns the element type
6721 -- with no intervening implicit dereference.
6723 if Has_Discriminants (Etype (Func)) then
6724 Disc := First_Discriminant (Etype (Func));
6725 while Present (Disc) loop
6726 if Has_Implicit_Dereference (Disc) then
6727 Add_One_Interp (N, Disc, Designated_Type (Etype (Disc)));
6731 Next_Discriminant (Disc);
6736 Indexing := Make_Function_Call (Loc,
6737 Name => Make_Identifier (Loc, Chars (Func_Name)),
6738 Parameter_Associations => Assoc);
6740 Rewrite (N, Indexing);
6748 Get_First_Interp (Func_Name, I, It);
6749 Set_Etype (N, Any_Type);
6750 while Present (It.Nam) loop
6751 Analyze_One_Call (N, It.Nam, False, Success);
6753 Set_Etype (Name (N), It.Typ);
6754 Set_Entity (Name (N), It.Nam);
6756 -- Add implicit dereference interpretation
6758 if Has_Discriminants (Etype (It.Nam)) then
6759 Disc := First_Discriminant (Etype (It.Nam));
6760 while Present (Disc) loop
6761 if Has_Implicit_Dereference (Disc) then
6763 (N, Disc, Designated_Type (Etype (Disc)));
6767 Next_Discriminant (Disc);
6773 Get_Next_Interp (I, It);
6778 if Etype (N) = Any_Type then
6780 ("container cannot be indexed with&", N, Etype (First (Exprs)));
6781 Rewrite (N, New_Occurrence_Of (Any_Id, Loc));
6787 end Try_Container_Indexing;
6789 -----------------------
6790 -- Try_Indirect_Call --
6791 -----------------------
6793 function Try_Indirect_Call
6796 Typ : Entity_Id) return Boolean
6802 pragma Warnings (Off, Call_OK);
6805 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
6807 Actual := First_Actual (N);
6808 Formal := First_Formal (Designated_Type (Typ));
6809 while Present (Actual) and then Present (Formal) loop
6810 if not Has_Compatible_Type (Actual, Etype (Formal)) then
6815 Next_Formal (Formal);
6818 if No (Actual) and then No (Formal) then
6819 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
6821 -- Nam is a candidate interpretation for the name in the call,
6822 -- if it is not an indirect call.
6824 if not Is_Type (Nam)
6825 and then Is_Entity_Name (Name (N))
6827 Set_Entity (Name (N), Nam);
6834 end Try_Indirect_Call;
6836 ----------------------
6837 -- Try_Indexed_Call --
6838 ----------------------
6840 function Try_Indexed_Call
6844 Skip_First : Boolean) return Boolean
6846 Loc : constant Source_Ptr := Sloc (N);
6847 Actuals : constant List_Id := Parameter_Associations (N);
6852 Actual := First (Actuals);
6854 -- If the call was originally written in prefix form, skip the first
6855 -- actual, which is obviously not defaulted.
6861 Index := First_Index (Typ);
6862 while Present (Actual) and then Present (Index) loop
6864 -- If the parameter list has a named association, the expression
6865 -- is definitely a call and not an indexed component.
6867 if Nkind (Actual) = N_Parameter_Association then
6871 if Is_Entity_Name (Actual)
6872 and then Is_Type (Entity (Actual))
6873 and then No (Next (Actual))
6875 -- A single actual that is a type name indicates a slice if the
6876 -- type is discrete, and an error otherwise.
6878 if Is_Discrete_Type (Entity (Actual)) then
6882 Make_Function_Call (Loc,
6883 Name => Relocate_Node (Name (N))),
6885 New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
6890 Error_Msg_N ("invalid use of type in expression", Actual);
6891 Set_Etype (N, Any_Type);
6896 elsif not Has_Compatible_Type (Actual, Etype (Index)) then
6904 if No (Actual) and then No (Index) then
6905 Add_One_Interp (N, Nam, Component_Type (Typ));
6907 -- Nam is a candidate interpretation for the name in the call,
6908 -- if it is not an indirect call.
6910 if not Is_Type (Nam)
6911 and then Is_Entity_Name (Name (N))
6913 Set_Entity (Name (N), Nam);
6920 end Try_Indexed_Call;
6922 --------------------------
6923 -- Try_Object_Operation --
6924 --------------------------
6926 function Try_Object_Operation
6927 (N : Node_Id; CW_Test_Only : Boolean := False) return Boolean
6929 K : constant Node_Kind := Nkind (Parent (N));
6930 Is_Subprg_Call : constant Boolean := K in N_Subprogram_Call;
6931 Loc : constant Source_Ptr := Sloc (N);
6932 Obj : constant Node_Id := Prefix (N);
6934 Subprog : constant Node_Id :=
6935 Make_Identifier (Sloc (Selector_Name (N)),
6936 Chars => Chars (Selector_Name (N)));
6937 -- Identifier on which possible interpretations will be collected
6939 Report_Error : Boolean := False;
6940 -- If no candidate interpretation matches the context, redo the
6941 -- analysis with error enabled to provide additional information.
6944 Candidate : Entity_Id := Empty;
6945 New_Call_Node : Node_Id := Empty;
6946 Node_To_Replace : Node_Id;
6947 Obj_Type : Entity_Id := Etype (Obj);
6948 Success : Boolean := False;
6950 function Valid_Candidate
6953 Subp : Entity_Id) return Entity_Id;
6954 -- If the subprogram is a valid interpretation, record it, and add
6955 -- to the list of interpretations of Subprog. Otherwise return Empty.
6957 procedure Complete_Object_Operation
6958 (Call_Node : Node_Id;
6959 Node_To_Replace : Node_Id);
6960 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
6961 -- Call_Node, insert the object (or its dereference) as the first actual
6962 -- in the call, and complete the analysis of the call.
6964 procedure Report_Ambiguity (Op : Entity_Id);
6965 -- If a prefixed procedure call is ambiguous, indicate whether the
6966 -- call includes an implicit dereference or an implicit 'Access.
6968 procedure Transform_Object_Operation
6969 (Call_Node : out Node_Id;
6970 Node_To_Replace : out Node_Id);
6971 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
6972 -- Call_Node is the resulting subprogram call, Node_To_Replace is
6973 -- either N or the parent of N, and Subprog is a reference to the
6974 -- subprogram we are trying to match.
6976 function Try_Class_Wide_Operation
6977 (Call_Node : Node_Id;
6978 Node_To_Replace : Node_Id) return Boolean;
6979 -- Traverse all ancestor types looking for a class-wide subprogram
6980 -- for which the current operation is a valid non-dispatching call.
6982 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
6983 -- If prefix is overloaded, its interpretation may include different
6984 -- tagged types, and we must examine the primitive operations and
6985 -- the class-wide operations of each in order to find candidate
6986 -- interpretations for the call as a whole.
6988 function Try_Primitive_Operation
6989 (Call_Node : Node_Id;
6990 Node_To_Replace : Node_Id) return Boolean;
6991 -- Traverse the list of primitive subprograms looking for a dispatching
6992 -- operation for which the current node is a valid call .
6994 ---------------------
6995 -- Valid_Candidate --
6996 ---------------------
6998 function Valid_Candidate
7001 Subp : Entity_Id) return Entity_Id
7003 Arr_Type : Entity_Id;
7004 Comp_Type : Entity_Id;
7007 -- If the subprogram is a valid interpretation, record it in global
7008 -- variable Subprog, to collect all possible overloadings.
7011 if Subp /= Entity (Subprog) then
7012 Add_One_Interp (Subprog, Subp, Etype (Subp));
7016 -- If the call may be an indexed call, retrieve component type of
7017 -- resulting expression, and add possible interpretation.
7022 if Nkind (Call) = N_Function_Call
7023 and then Nkind (Parent (N)) = N_Indexed_Component
7024 and then Needs_One_Actual (Subp)
7026 if Is_Array_Type (Etype (Subp)) then
7027 Arr_Type := Etype (Subp);
7029 elsif Is_Access_Type (Etype (Subp))
7030 and then Is_Array_Type (Designated_Type (Etype (Subp)))
7032 Arr_Type := Designated_Type (Etype (Subp));
7036 if Present (Arr_Type) then
7038 -- Verify that the actuals (excluding the object) match the types
7046 Actual := Next (First_Actual (Call));
7047 Index := First_Index (Arr_Type);
7048 while Present (Actual) and then Present (Index) loop
7049 if not Has_Compatible_Type (Actual, Etype (Index)) then
7054 Next_Actual (Actual);
7060 and then Present (Arr_Type)
7062 Comp_Type := Component_Type (Arr_Type);
7066 if Present (Comp_Type)
7067 and then Etype (Subprog) /= Comp_Type
7069 Add_One_Interp (Subprog, Subp, Comp_Type);
7073 if Etype (Call) /= Any_Type then
7078 end Valid_Candidate;
7080 -------------------------------
7081 -- Complete_Object_Operation --
7082 -------------------------------
7084 procedure Complete_Object_Operation
7085 (Call_Node : Node_Id;
7086 Node_To_Replace : Node_Id)
7088 Control : constant Entity_Id := First_Formal (Entity (Subprog));
7089 Formal_Type : constant Entity_Id := Etype (Control);
7090 First_Actual : Node_Id;
7093 -- Place the name of the operation, with its interpretations,
7094 -- on the rewritten call.
7096 Set_Name (Call_Node, Subprog);
7098 First_Actual := First (Parameter_Associations (Call_Node));
7100 -- For cross-reference purposes, treat the new node as being in
7101 -- the source if the original one is. Set entity and type, even
7102 -- though they may be overwritten during resolution if overloaded.
7104 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
7105 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
7107 if Nkind (N) = N_Selected_Component
7108 and then not Inside_A_Generic
7110 Set_Entity (Selector_Name (N), Entity (Subprog));
7111 Set_Etype (Selector_Name (N), Etype (Entity (Subprog)));
7114 -- If need be, rewrite first actual as an explicit dereference
7115 -- If the call is overloaded, the rewriting can only be done
7116 -- once the primitive operation is identified.
7118 if Is_Overloaded (Subprog) then
7120 -- The prefix itself may be overloaded, and its interpretations
7121 -- must be propagated to the new actual in the call.
7123 if Is_Overloaded (Obj) then
7124 Save_Interps (Obj, First_Actual);
7127 Rewrite (First_Actual, Obj);
7129 elsif not Is_Access_Type (Formal_Type)
7130 and then Is_Access_Type (Etype (Obj))
7132 Rewrite (First_Actual,
7133 Make_Explicit_Dereference (Sloc (Obj), Obj));
7134 Analyze (First_Actual);
7136 -- If we need to introduce an explicit dereference, verify that
7137 -- the resulting actual is compatible with the mode of the formal.
7139 if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
7140 and then Is_Access_Constant (Etype (Obj))
7143 ("expect variable in call to&", Prefix (N), Entity (Subprog));
7146 -- Conversely, if the formal is an access parameter and the object
7147 -- is not, replace the actual with a 'Access reference. Its analysis
7148 -- will check that the object is aliased.
7150 elsif Is_Access_Type (Formal_Type)
7151 and then not Is_Access_Type (Etype (Obj))
7153 -- A special case: A.all'access is illegal if A is an access to a
7154 -- constant and the context requires an access to a variable.
7156 if not Is_Access_Constant (Formal_Type) then
7157 if (Nkind (Obj) = N_Explicit_Dereference
7158 and then Is_Access_Constant (Etype (Prefix (Obj))))
7159 or else not Is_Variable (Obj)
7162 ("actual for& must be a variable", Obj, Control);
7166 Rewrite (First_Actual,
7167 Make_Attribute_Reference (Loc,
7168 Attribute_Name => Name_Access,
7169 Prefix => Relocate_Node (Obj)));
7171 if not Is_Aliased_View (Obj) then
7173 ("object in prefixed call to& must be aliased"
7174 & " (RM-2005 4.3.1 (13))",
7175 Prefix (First_Actual), Subprog);
7178 Analyze (First_Actual);
7181 if Is_Overloaded (Obj) then
7182 Save_Interps (Obj, First_Actual);
7185 Rewrite (First_Actual, Obj);
7188 Rewrite (Node_To_Replace, Call_Node);
7190 -- Propagate the interpretations collected in subprog to the new
7191 -- function call node, to be resolved from context.
7193 if Is_Overloaded (Subprog) then
7194 Save_Interps (Subprog, Node_To_Replace);
7197 Analyze (Node_To_Replace);
7199 -- If the operation has been rewritten into a call, which may get
7200 -- subsequently an explicit dereference, preserve the type on the
7201 -- original node (selected component or indexed component) for
7202 -- subsequent legality tests, e.g. Is_Variable. which examines
7203 -- the original node.
7205 if Nkind (Node_To_Replace) = N_Function_Call then
7207 (Original_Node (Node_To_Replace), Etype (Node_To_Replace));
7210 end Complete_Object_Operation;
7212 ----------------------
7213 -- Report_Ambiguity --
7214 ----------------------
7216 procedure Report_Ambiguity (Op : Entity_Id) is
7217 Access_Actual : constant Boolean :=
7218 Is_Access_Type (Etype (Prefix (N)));
7219 Access_Formal : Boolean := False;
7222 Error_Msg_Sloc := Sloc (Op);
7224 if Present (First_Formal (Op)) then
7225 Access_Formal := Is_Access_Type (Etype (First_Formal (Op)));
7228 if Access_Formal and then not Access_Actual then
7229 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
7231 ("\possible interpretation"
7232 & " (inherited, with implicit 'Access) #", N);
7235 ("\possible interpretation (with implicit 'Access) #", N);
7238 elsif not Access_Formal and then Access_Actual then
7239 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
7241 ("\possible interpretation"
7242 & " ( inherited, with implicit dereference) #", N);
7245 ("\possible interpretation (with implicit dereference) #", N);
7249 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
7250 Error_Msg_N ("\possible interpretation (inherited)#", N);
7252 Error_Msg_N -- CODEFIX
7253 ("\possible interpretation#", N);
7256 end Report_Ambiguity;
7258 --------------------------------
7259 -- Transform_Object_Operation --
7260 --------------------------------
7262 procedure Transform_Object_Operation
7263 (Call_Node : out Node_Id;
7264 Node_To_Replace : out Node_Id)
7266 Dummy : constant Node_Id := New_Copy (Obj);
7267 -- Placeholder used as a first parameter in the call, replaced
7268 -- eventually by the proper object.
7270 Parent_Node : constant Node_Id := Parent (N);
7276 -- Common case covering 1) Call to a procedure and 2) Call to a
7277 -- function that has some additional actuals.
7279 if Nkind (Parent_Node) in N_Subprogram_Call
7281 -- N is a selected component node containing the name of the
7282 -- subprogram. If N is not the name of the parent node we must
7283 -- not replace the parent node by the new construct. This case
7284 -- occurs when N is a parameterless call to a subprogram that
7285 -- is an actual parameter of a call to another subprogram. For
7287 -- Some_Subprogram (..., Obj.Operation, ...)
7289 and then Name (Parent_Node) = N
7291 Node_To_Replace := Parent_Node;
7293 Actuals := Parameter_Associations (Parent_Node);
7295 if Present (Actuals) then
7296 Prepend (Dummy, Actuals);
7298 Actuals := New_List (Dummy);
7301 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
7303 Make_Procedure_Call_Statement (Loc,
7304 Name => New_Copy (Subprog),
7305 Parameter_Associations => Actuals);
7309 Make_Function_Call (Loc,
7310 Name => New_Copy (Subprog),
7311 Parameter_Associations => Actuals);
7315 -- Before analysis, a function call appears as an indexed component
7316 -- if there are no named associations.
7318 elsif Nkind (Parent_Node) = N_Indexed_Component
7319 and then N = Prefix (Parent_Node)
7321 Node_To_Replace := Parent_Node;
7322 Actuals := Expressions (Parent_Node);
7324 Actual := First (Actuals);
7325 while Present (Actual) loop
7330 Prepend (Dummy, Actuals);
7333 Make_Function_Call (Loc,
7334 Name => New_Copy (Subprog),
7335 Parameter_Associations => Actuals);
7337 -- Parameterless call: Obj.F is rewritten as F (Obj)
7340 Node_To_Replace := N;
7343 Make_Function_Call (Loc,
7344 Name => New_Copy (Subprog),
7345 Parameter_Associations => New_List (Dummy));
7347 end Transform_Object_Operation;
7349 ------------------------------
7350 -- Try_Class_Wide_Operation --
7351 ------------------------------
7353 function Try_Class_Wide_Operation
7354 (Call_Node : Node_Id;
7355 Node_To_Replace : Node_Id) return Boolean
7357 Anc_Type : Entity_Id;
7358 Matching_Op : Entity_Id := Empty;
7361 procedure Traverse_Homonyms
7362 (Anc_Type : Entity_Id;
7363 Error : out Boolean);
7364 -- Traverse the homonym chain of the subprogram searching for those
7365 -- homonyms whose first formal has the Anc_Type's class-wide type,
7366 -- or an anonymous access type designating the class-wide type. If
7367 -- an ambiguity is detected, then Error is set to True.
7369 procedure Traverse_Interfaces
7370 (Anc_Type : Entity_Id;
7371 Error : out Boolean);
7372 -- Traverse the list of interfaces, if any, associated with Anc_Type
7373 -- and search for acceptable class-wide homonyms associated with each
7374 -- interface. If an ambiguity is detected, then Error is set to True.
7376 -----------------------
7377 -- Traverse_Homonyms --
7378 -----------------------
7380 procedure Traverse_Homonyms
7381 (Anc_Type : Entity_Id;
7382 Error : out Boolean)
7384 Cls_Type : Entity_Id;
7392 Cls_Type := Class_Wide_Type (Anc_Type);
7394 Hom := Current_Entity (Subprog);
7396 -- Find a non-hidden operation whose first parameter is of the
7397 -- class-wide type, a subtype thereof, or an anonymous access
7398 -- to same. If in an instance, the operation can be considered
7399 -- even if hidden (it may be hidden because the instantiation is
7400 -- expanded after the containing package has been analyzed).
7402 while Present (Hom) loop
7403 if Ekind_In (Hom, E_Procedure, E_Function)
7404 and then (not Is_Hidden (Hom) or else In_Instance)
7405 and then Scope (Hom) = Scope (Anc_Type)
7406 and then Present (First_Formal (Hom))
7408 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
7410 (Is_Access_Type (Etype (First_Formal (Hom)))
7412 Ekind (Etype (First_Formal (Hom))) =
7413 E_Anonymous_Access_Type
7416 (Designated_Type (Etype (First_Formal (Hom)))) =
7419 -- If the context is a procedure call, ignore functions
7420 -- in the name of the call.
7422 if Ekind (Hom) = E_Function
7423 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
7424 and then N = Name (Parent (N))
7428 -- If the context is a function call, ignore procedures
7429 -- in the name of the call.
7431 elsif Ekind (Hom) = E_Procedure
7432 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
7437 Set_Etype (Call_Node, Any_Type);
7438 Set_Is_Overloaded (Call_Node, False);
7441 if No (Matching_Op) then
7442 Hom_Ref := New_Reference_To (Hom, Sloc (Subprog));
7443 Set_Etype (Call_Node, Any_Type);
7444 Set_Parent (Call_Node, Parent (Node_To_Replace));
7446 Set_Name (Call_Node, Hom_Ref);
7451 Report => Report_Error,
7453 Skip_First => True);
7456 Valid_Candidate (Success, Call_Node, Hom);
7462 Report => Report_Error,
7464 Skip_First => True);
7466 if Present (Valid_Candidate (Success, Call_Node, Hom))
7467 and then Nkind (Call_Node) /= N_Function_Call
7469 Error_Msg_NE ("ambiguous call to&", N, Hom);
7470 Report_Ambiguity (Matching_Op);
7471 Report_Ambiguity (Hom);
7479 Hom := Homonym (Hom);
7481 end Traverse_Homonyms;
7483 -------------------------
7484 -- Traverse_Interfaces --
7485 -------------------------
7487 procedure Traverse_Interfaces
7488 (Anc_Type : Entity_Id;
7489 Error : out Boolean)
7491 Intface_List : constant List_Id :=
7492 Abstract_Interface_List (Anc_Type);
7498 if Is_Non_Empty_List (Intface_List) then
7499 Intface := First (Intface_List);
7500 while Present (Intface) loop
7502 -- Look for acceptable class-wide homonyms associated with
7505 Traverse_Homonyms (Etype (Intface), Error);
7511 -- Continue the search by looking at each of the interface's
7512 -- associated interface ancestors.
7514 Traverse_Interfaces (Etype (Intface), Error);
7523 end Traverse_Interfaces;
7525 -- Start of processing for Try_Class_Wide_Operation
7528 -- If we are searching only for conflicting class-wide subprograms
7529 -- then initialize directly Matching_Op with the target entity.
7531 if CW_Test_Only then
7532 Matching_Op := Entity (Selector_Name (N));
7535 -- Loop through ancestor types (including interfaces), traversing
7536 -- the homonym chain of the subprogram, trying out those homonyms
7537 -- whose first formal has the class-wide type of the ancestor, or
7538 -- an anonymous access type designating the class-wide type.
7540 Anc_Type := Obj_Type;
7542 -- Look for a match among homonyms associated with the ancestor
7544 Traverse_Homonyms (Anc_Type, Error);
7550 -- Continue the search for matches among homonyms associated with
7551 -- any interfaces implemented by the ancestor.
7553 Traverse_Interfaces (Anc_Type, Error);
7559 exit when Etype (Anc_Type) = Anc_Type;
7560 Anc_Type := Etype (Anc_Type);
7563 if Present (Matching_Op) then
7564 Set_Etype (Call_Node, Etype (Matching_Op));
7567 return Present (Matching_Op);
7568 end Try_Class_Wide_Operation;
7570 -----------------------------------
7571 -- Try_One_Prefix_Interpretation --
7572 -----------------------------------
7574 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
7578 if Is_Access_Type (Obj_Type) then
7579 Obj_Type := Designated_Type (Obj_Type);
7582 if Ekind (Obj_Type) = E_Private_Subtype then
7583 Obj_Type := Base_Type (Obj_Type);
7586 if Is_Class_Wide_Type (Obj_Type) then
7587 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
7590 -- The type may have be obtained through a limited_with clause,
7591 -- in which case the primitive operations are available on its
7592 -- non-limited view. If still incomplete, retrieve full view.
7594 if Ekind (Obj_Type) = E_Incomplete_Type
7595 and then From_With_Type (Obj_Type)
7597 Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
7600 -- If the object is not tagged, or the type is still an incomplete
7601 -- type, this is not a prefixed call.
7603 if not Is_Tagged_Type (Obj_Type)
7604 or else Is_Incomplete_Type (Obj_Type)
7610 Dup_Call_Node : constant Node_Id := New_Copy (New_Call_Node);
7611 CW_Result : Boolean;
7612 Prim_Result : Boolean;
7613 pragma Unreferenced (CW_Result);
7616 if not CW_Test_Only then
7618 Try_Primitive_Operation
7619 (Call_Node => New_Call_Node,
7620 Node_To_Replace => Node_To_Replace);
7623 -- Check if there is a class-wide subprogram covering the
7624 -- primitive. This check must be done even if a candidate
7625 -- was found in order to report ambiguous calls.
7627 if not (Prim_Result) then
7629 Try_Class_Wide_Operation
7630 (Call_Node => New_Call_Node,
7631 Node_To_Replace => Node_To_Replace);
7633 -- If we found a primitive we search for class-wide subprograms
7634 -- using a duplicate of the call node (done to avoid missing its
7635 -- decoration if there is no ambiguity).
7639 Try_Class_Wide_Operation
7640 (Call_Node => Dup_Call_Node,
7641 Node_To_Replace => Node_To_Replace);
7644 end Try_One_Prefix_Interpretation;
7646 -----------------------------
7647 -- Try_Primitive_Operation --
7648 -----------------------------
7650 function Try_Primitive_Operation
7651 (Call_Node : Node_Id;
7652 Node_To_Replace : Node_Id) return Boolean
7655 Prim_Op : Entity_Id;
7656 Matching_Op : Entity_Id := Empty;
7657 Prim_Op_Ref : Node_Id := Empty;
7659 Corr_Type : Entity_Id := Empty;
7660 -- If the prefix is a synchronized type, the controlling type of
7661 -- the primitive operation is the corresponding record type, else
7662 -- this is the object type itself.
7664 Success : Boolean := False;
7666 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
7667 -- For tagged types the candidate interpretations are found in
7668 -- the list of primitive operations of the type and its ancestors.
7669 -- For formal tagged types we have to find the operations declared
7670 -- in the same scope as the type (including in the generic formal
7671 -- part) because the type itself carries no primitive operations,
7672 -- except for formal derived types that inherit the operations of
7673 -- the parent and progenitors.
7674 -- If the context is a generic subprogram body, the generic formals
7675 -- are visible by name, but are not in the entity list of the
7676 -- subprogram because that list starts with the subprogram formals.
7677 -- We retrieve the candidate operations from the generic declaration.
7679 function Is_Private_Overriding (Op : Entity_Id) return Boolean;
7680 -- An operation that overrides an inherited operation in the private
7681 -- part of its package may be hidden, but if the inherited operation
7682 -- is visible a direct call to it will dispatch to the private one,
7683 -- which is therefore a valid candidate.
7685 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
7686 -- Verify that the prefix, dereferenced if need be, is a valid
7687 -- controlling argument in a call to Op. The remaining actuals
7688 -- are checked in the subsequent call to Analyze_One_Call.
7690 ------------------------------
7691 -- Collect_Generic_Type_Ops --
7692 ------------------------------
7694 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
7695 Bas : constant Entity_Id := Base_Type (T);
7696 Candidates : constant Elist_Id := New_Elmt_List;
7700 procedure Check_Candidate;
7701 -- The operation is a candidate if its first parameter is a
7702 -- controlling operand of the desired type.
7704 -----------------------
7705 -- Check_Candidate; --
7706 -----------------------
7708 procedure Check_Candidate is
7710 Formal := First_Formal (Subp);
7713 and then Is_Controlling_Formal (Formal)
7715 (Base_Type (Etype (Formal)) = Bas
7717 (Is_Access_Type (Etype (Formal))
7718 and then Designated_Type (Etype (Formal)) = Bas))
7720 Append_Elmt (Subp, Candidates);
7722 end Check_Candidate;
7724 -- Start of processing for Collect_Generic_Type_Ops
7727 if Is_Derived_Type (T) then
7728 return Primitive_Operations (T);
7730 elsif Ekind_In (Scope (T), E_Procedure, E_Function) then
7732 -- Scan the list of generic formals to find subprograms
7733 -- that may have a first controlling formal of the type.
7735 if Nkind (Unit_Declaration_Node (Scope (T)))
7736 = N_Generic_Subprogram_Declaration
7743 First (Generic_Formal_Declarations
7744 (Unit_Declaration_Node (Scope (T))));
7745 while Present (Decl) loop
7746 if Nkind (Decl) in N_Formal_Subprogram_Declaration then
7747 Subp := Defining_Entity (Decl);
7758 -- Scan the list of entities declared in the same scope as
7759 -- the type. In general this will be an open scope, given that
7760 -- the call we are analyzing can only appear within a generic
7761 -- declaration or body (either the one that declares T, or a
7764 -- For a subtype representing a generic actual type, go to the
7767 if Is_Generic_Actual_Type (T) then
7768 Subp := First_Entity (Scope (Base_Type (T)));
7770 Subp := First_Entity (Scope (T));
7773 while Present (Subp) loop
7774 if Is_Overloadable (Subp) then
7783 end Collect_Generic_Type_Ops;
7785 ---------------------------
7786 -- Is_Private_Overriding --
7787 ---------------------------
7789 function Is_Private_Overriding (Op : Entity_Id) return Boolean is
7790 Visible_Op : constant Entity_Id := Homonym (Op);
7793 return Present (Visible_Op)
7794 and then Scope (Op) = Scope (Visible_Op)
7795 and then not Comes_From_Source (Visible_Op)
7796 and then Alias (Visible_Op) = Op
7797 and then not Is_Hidden (Visible_Op);
7798 end Is_Private_Overriding;
7800 -----------------------------
7801 -- Valid_First_Argument_Of --
7802 -----------------------------
7804 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
7805 Typ : Entity_Id := Etype (First_Formal (Op));
7808 if Is_Concurrent_Type (Typ)
7809 and then Present (Corresponding_Record_Type (Typ))
7811 Typ := Corresponding_Record_Type (Typ);
7814 -- Simple case. Object may be a subtype of the tagged type or
7815 -- may be the corresponding record of a synchronized type.
7817 return Obj_Type = Typ
7818 or else Base_Type (Obj_Type) = Typ
7819 or else Corr_Type = Typ
7821 -- Prefix can be dereferenced
7824 (Is_Access_Type (Corr_Type)
7825 and then Designated_Type (Corr_Type) = Typ)
7827 -- Formal is an access parameter, for which the object
7828 -- can provide an access.
7831 (Ekind (Typ) = E_Anonymous_Access_Type
7833 Base_Type (Designated_Type (Typ)) = Base_Type (Corr_Type));
7834 end Valid_First_Argument_Of;
7836 -- Start of processing for Try_Primitive_Operation
7839 -- Look for subprograms in the list of primitive operations. The name
7840 -- must be identical, and the kind of call indicates the expected
7841 -- kind of operation (function or procedure). If the type is a
7842 -- (tagged) synchronized type, the primitive ops are attached to the
7843 -- corresponding record (base) type.
7845 if Is_Concurrent_Type (Obj_Type) then
7846 if Present (Corresponding_Record_Type (Obj_Type)) then
7847 Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
7848 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
7850 Corr_Type := Obj_Type;
7851 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
7854 elsif not Is_Generic_Type (Obj_Type) then
7855 Corr_Type := Obj_Type;
7856 Elmt := First_Elmt (Primitive_Operations (Obj_Type));
7859 Corr_Type := Obj_Type;
7860 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
7863 while Present (Elmt) loop
7864 Prim_Op := Node (Elmt);
7866 if Chars (Prim_Op) = Chars (Subprog)
7867 and then Present (First_Formal (Prim_Op))
7868 and then Valid_First_Argument_Of (Prim_Op)
7870 (Nkind (Call_Node) = N_Function_Call)
7871 = (Ekind (Prim_Op) = E_Function)
7873 -- Ada 2005 (AI-251): If this primitive operation corresponds
7874 -- with an immediate ancestor interface there is no need to add
7875 -- it to the list of interpretations; the corresponding aliased
7876 -- primitive is also in this list of primitive operations and
7877 -- will be used instead.
7879 if (Present (Interface_Alias (Prim_Op))
7880 and then Is_Ancestor (Find_Dispatching_Type
7881 (Alias (Prim_Op)), Corr_Type))
7883 -- Do not consider hidden primitives unless the type is in an
7884 -- open scope or we are within an instance, where visibility
7885 -- is known to be correct, or else if this is an overriding
7886 -- operation in the private part for an inherited operation.
7888 or else (Is_Hidden (Prim_Op)
7889 and then not Is_Immediately_Visible (Obj_Type)
7890 and then not In_Instance
7891 and then not Is_Private_Overriding (Prim_Op))
7896 Set_Etype (Call_Node, Any_Type);
7897 Set_Is_Overloaded (Call_Node, False);
7899 if No (Matching_Op) then
7900 Prim_Op_Ref := New_Reference_To (Prim_Op, Sloc (Subprog));
7901 Candidate := Prim_Op;
7903 Set_Parent (Call_Node, Parent (Node_To_Replace));
7905 Set_Name (Call_Node, Prim_Op_Ref);
7911 Report => Report_Error,
7913 Skip_First => True);
7915 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
7917 -- More than one interpretation, collect for subsequent
7918 -- disambiguation. If this is a procedure call and there
7919 -- is another match, report ambiguity now.
7925 Report => Report_Error,
7927 Skip_First => True);
7929 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
7930 and then Nkind (Call_Node) /= N_Function_Call
7932 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
7933 Report_Ambiguity (Matching_Op);
7934 Report_Ambiguity (Prim_Op);
7944 if Present (Matching_Op) then
7945 Set_Etype (Call_Node, Etype (Matching_Op));
7948 return Present (Matching_Op);
7949 end Try_Primitive_Operation;
7951 -- Start of processing for Try_Object_Operation
7954 Analyze_Expression (Obj);
7956 -- Analyze the actuals if node is known to be a subprogram call
7958 if Is_Subprg_Call and then N = Name (Parent (N)) then
7959 Actual := First (Parameter_Associations (Parent (N)));
7960 while Present (Actual) loop
7961 Analyze_Expression (Actual);
7966 -- Build a subprogram call node, using a copy of Obj as its first
7967 -- actual. This is a placeholder, to be replaced by an explicit
7968 -- dereference when needed.
7970 Transform_Object_Operation
7971 (Call_Node => New_Call_Node,
7972 Node_To_Replace => Node_To_Replace);
7974 Set_Etype (New_Call_Node, Any_Type);
7975 Set_Etype (Subprog, Any_Type);
7976 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
7978 if not Is_Overloaded (Obj) then
7979 Try_One_Prefix_Interpretation (Obj_Type);
7986 Get_First_Interp (Obj, I, It);
7987 while Present (It.Nam) loop
7988 Try_One_Prefix_Interpretation (It.Typ);
7989 Get_Next_Interp (I, It);
7994 if Etype (New_Call_Node) /= Any_Type then
7996 -- No need to complete the tree transformations if we are only
7997 -- searching for conflicting class-wide subprograms
7999 if CW_Test_Only then
8002 Complete_Object_Operation
8003 (Call_Node => New_Call_Node,
8004 Node_To_Replace => Node_To_Replace);
8008 elsif Present (Candidate) then
8010 -- The argument list is not type correct. Re-analyze with error
8011 -- reporting enabled, and use one of the possible candidates.
8012 -- In All_Errors_Mode, re-analyze all failed interpretations.
8014 if All_Errors_Mode then
8015 Report_Error := True;
8016 if Try_Primitive_Operation
8017 (Call_Node => New_Call_Node,
8018 Node_To_Replace => Node_To_Replace)
8021 Try_Class_Wide_Operation
8022 (Call_Node => New_Call_Node,
8023 Node_To_Replace => Node_To_Replace)
8030 (N => New_Call_Node,
8034 Skip_First => True);
8037 -- No need for further errors
8042 -- There was no candidate operation, so report it as an error
8043 -- in the caller: Analyze_Selected_Component.
8047 end Try_Object_Operation;
8053 procedure wpo (T : Entity_Id) is
8058 if not Is_Tagged_Type (T) then
8062 E := First_Elmt (Primitive_Operations (Base_Type (T)));
8063 while Present (E) loop
8065 Write_Int (Int (Op));
8066 Write_Str (" === ");
8067 Write_Name (Chars (Op));
8069 Write_Name (Chars (Scope (Op)));