1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2020, 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 Itypes; use Itypes;
35 with Lib.Xref; use Lib.Xref;
36 with Namet; use Namet;
37 with Namet.Sp; use Namet.Sp;
38 with Nlists; use Nlists;
39 with Nmake; use Nmake;
41 with Output; use Output;
42 with Restrict; use Restrict;
43 with Rident; use Rident;
45 with Sem_Aux; use Sem_Aux;
46 with Sem_Case; use Sem_Case;
47 with Sem_Cat; use Sem_Cat;
48 with Sem_Ch3; use Sem_Ch3;
49 with Sem_Ch6; use Sem_Ch6;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Dim; use Sem_Dim;
52 with Sem_Disp; use Sem_Disp;
53 with Sem_Dist; use Sem_Dist;
54 with Sem_Eval; use Sem_Eval;
55 with Sem_Res; use Sem_Res;
56 with Sem_Type; use Sem_Type;
57 with Sem_Util; use Sem_Util;
58 with Sem_Warn; use Sem_Warn;
59 with Stand; use Stand;
60 with Sinfo; use Sinfo;
61 with Snames; use Snames;
62 with Tbuild; use Tbuild;
63 with Uintp; use Uintp;
65 package body Sem_Ch4 is
67 -- Tables which speed up the identification of dangerous calls to Ada 2012
68 -- functions with writable actuals (AI05-0144).
70 -- The following table enumerates the Ada constructs which may evaluate in
71 -- arbitrary order. It does not cover all the language constructs which can
72 -- be evaluated in arbitrary order but the subset needed for AI05-0144.
74 Has_Arbitrary_Evaluation_Order : constant array (Node_Kind) of Boolean :=
76 N_Assignment_Statement => True,
77 N_Entry_Call_Statement => True,
78 N_Extension_Aggregate => True,
79 N_Full_Type_Declaration => True,
80 N_Indexed_Component => True,
81 N_Object_Declaration => True,
85 N_Array_Type_Definition => True,
86 N_Membership_Test => True,
88 N_Subprogram_Call => True,
91 -- The following table enumerates the nodes on which we stop climbing when
92 -- locating the outermost Ada construct that can be evaluated in arbitrary
95 Stop_Subtree_Climbing : constant array (Node_Kind) of Boolean :=
97 N_Assignment_Statement => True,
98 N_Entry_Call_Statement => True,
99 N_Extended_Return_Statement => True,
100 N_Extension_Aggregate => True,
101 N_Full_Type_Declaration => True,
102 N_Object_Declaration => True,
103 N_Object_Renaming_Declaration => True,
104 N_Package_Specification => True,
106 N_Procedure_Call_Statement => True,
107 N_Simple_Return_Statement => True,
108 N_Has_Condition => True,
111 -----------------------
112 -- Local Subprograms --
113 -----------------------
115 procedure Analyze_Concatenation_Rest (N : Node_Id);
116 -- Does the "rest" of the work of Analyze_Concatenation, after the left
117 -- operand has been analyzed. See Analyze_Concatenation for details.
119 procedure Analyze_Expression (N : Node_Id);
120 -- For expressions that are not names, this is just a call to analyze. If
121 -- the expression is a name, it may be a call to a parameterless function,
122 -- and if so must be converted into an explicit call node and analyzed as
123 -- such. This deproceduring must be done during the first pass of overload
124 -- resolution, because otherwise a procedure call with overloaded actuals
125 -- may fail to resolve.
127 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
128 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call is an
129 -- operator name or an expanded name whose selector is an operator name,
130 -- and one possible interpretation is as a predefined operator.
132 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
133 -- If the prefix of a selected_component is overloaded, the proper
134 -- interpretation that yields a record type with the proper selector
135 -- name must be selected.
137 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
138 -- Procedure to analyze a user defined binary operator, which is resolved
139 -- like a function, but instead of a list of actuals it is presented
140 -- with the left and right operands of an operator node.
142 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
143 -- Procedure to analyze a user defined unary operator, which is resolved
144 -- like a function, but instead of a list of actuals, it is presented with
145 -- the operand of the operator node.
147 procedure Ambiguous_Operands (N : Node_Id);
148 -- For equality, membership, and comparison operators with overloaded
149 -- arguments, list possible interpretations.
151 procedure Analyze_One_Call
155 Success : out Boolean;
156 Skip_First : Boolean := False);
157 -- Check one interpretation of an overloaded subprogram name for
158 -- compatibility with the types of the actuals in a call. If there is a
159 -- single interpretation which does not match, post error if Report is
162 -- Nam is the entity that provides the formals against which the actuals
163 -- are checked. Nam is either the name of a subprogram, or the internal
164 -- subprogram type constructed for an access_to_subprogram. If the actuals
165 -- are compatible with Nam, then Nam is added to the list of candidate
166 -- interpretations for N, and Success is set to True.
168 -- The flag Skip_First is used when analyzing a call that was rewritten
169 -- from object notation. In this case the first actual may have to receive
170 -- an explicit dereference, depending on the first formal of the operation
171 -- being called. The caller will have verified that the object is legal
172 -- for the call. If the remaining parameters match, the first parameter
173 -- will rewritten as a dereference if needed, prior to completing analysis.
174 procedure Check_Misspelled_Selector
177 -- Give possible misspelling message if Sel seems likely to be a mis-
178 -- spelling of one of the selectors of the Prefix. This is called by
179 -- Analyze_Selected_Component after producing an invalid selector error
182 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
183 -- Verify that type T is declared in scope S. Used to find interpretations
184 -- for operators given by expanded names. This is abstracted as a separate
185 -- function to handle extensions to System, where S is System, but T is
186 -- declared in the extension.
188 procedure Find_Arithmetic_Types
192 -- L and R are the operands of an arithmetic operator. Find consistent
193 -- pairs of interpretations for L and R that have a numeric type consistent
194 -- with the semantics of the operator.
196 procedure Find_Comparison_Types
200 -- L and R are operands of a comparison operator. Find consistent pairs of
201 -- interpretations for L and R.
203 procedure Find_Concatenation_Types
207 -- For the four varieties of concatenation
209 procedure Find_Equality_Types
213 -- Ditto for equality operators
215 procedure Find_Boolean_Types
219 -- Ditto for binary logical operations
221 procedure Find_Negation_Types
225 -- Find consistent interpretation for operand of negation operator
227 procedure Find_Non_Universal_Interpretations
232 -- For equality and comparison operators, the result is always boolean, and
233 -- the legality of the operation is determined from the visibility of the
234 -- operand types. If one of the operands has a universal interpretation,
235 -- the legality check uses some compatible non-universal interpretation of
236 -- the other operand. N can be an operator node, or a function call whose
237 -- name is an operator designator. Any_Access, which is the initial type of
238 -- the literal NULL, is a universal type for the purpose of this routine.
240 function Find_Primitive_Operation (N : Node_Id) return Boolean;
241 -- Find candidate interpretations for the name Obj.Proc when it appears in
242 -- a subprogram renaming declaration.
244 procedure Find_Unary_Types
248 -- Unary arithmetic types: plus, minus, abs
250 procedure Check_Arithmetic_Pair
254 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid types
255 -- for left and right operand. Determine whether they constitute a valid
256 -- pair for the given operator, and record the corresponding interpretation
257 -- of the operator node. The node N may be an operator node (the usual
258 -- case) or a function call whose prefix is an operator designator. In
259 -- both cases Op_Id is the operator name itself.
261 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
262 -- Give detailed information on overloaded call where none of the
263 -- interpretations match. N is the call node, Nam the designator for
264 -- the overloaded entity being called.
266 function Junk_Operand (N : Node_Id) return Boolean;
267 -- Test for an operand that is an inappropriate entity (e.g. a package
268 -- name or a label). If so, issue an error message and return True. If
269 -- the operand is not an inappropriate entity kind, return False.
271 procedure Operator_Check (N : Node_Id);
272 -- Verify that an operator has received some valid interpretation. If none
273 -- was found, determine whether a use clause would make the operation
274 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
275 -- every type compatible with the operator, even if the operator for the
276 -- type is not directly visible. The routine uses this type to emit a more
277 -- informative message.
279 function Process_Implicit_Dereference_Prefix
281 P : Node_Id) return Entity_Id;
282 -- Called when P is the prefix of an implicit dereference, denoting an
283 -- object E. The function returns the designated type of the prefix, taking
284 -- into account that the designated type of an anonymous access type may be
285 -- a limited view, when the nonlimited view is visible.
287 -- If in semantics only mode (-gnatc or generic), the function also records
288 -- that the prefix is a reference to E, if any. Normally, such a reference
289 -- is generated only when the implicit dereference is expanded into an
290 -- explicit one, but for consistency we must generate the reference when
291 -- expansion is disabled as well.
293 procedure Remove_Abstract_Operations (N : Node_Id);
294 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
295 -- operation is not a candidate interpretation.
297 function Try_Container_Indexing
300 Exprs : List_Id) return Boolean;
301 -- AI05-0139: Generalized indexing to support iterators over containers
303 function Try_Indexed_Call
307 Skip_First : Boolean) return Boolean;
308 -- If a function has defaults for all its actuals, a call to it may in fact
309 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
310 -- interpretation as an indexing, prior to analysis as a call. If both are
311 -- possible, the node is overloaded with both interpretations (same symbol
312 -- but two different types). If the call is written in prefix form, the
313 -- prefix becomes the first parameter in the call, and only the remaining
314 -- actuals must be checked for the presence of defaults.
316 function Try_Indirect_Call
319 Typ : Entity_Id) return Boolean;
320 -- Similarly, a function F that needs no actuals can return an access to a
321 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
322 -- the call may be overloaded with both interpretations.
324 procedure wpo (T : Entity_Id);
325 pragma Warnings (Off, wpo);
326 -- Used for debugging: obtain list of primitive operations even if
327 -- type is not frozen and dispatch table is not built yet.
329 ------------------------
330 -- Ambiguous_Operands --
331 ------------------------
333 procedure Ambiguous_Operands (N : Node_Id) is
334 procedure List_Operand_Interps (Opnd : Node_Id);
336 --------------------------
337 -- List_Operand_Interps --
338 --------------------------
340 procedure List_Operand_Interps (Opnd : Node_Id) is
341 Nam : Node_Id := Empty;
345 if Is_Overloaded (Opnd) then
346 if Nkind (Opnd) in N_Op then
349 elsif Nkind (Opnd) = N_Function_Call then
352 elsif Ada_Version >= Ada_2012 then
358 Get_First_Interp (Opnd, I, It);
359 while Present (It.Nam) loop
360 if Has_Implicit_Dereference (It.Typ) then
362 ("can be interpreted as implicit dereference", Opnd);
366 Get_Next_Interp (I, It);
377 if Opnd = Left_Opnd (N) then
379 ("\left operand has the following interpretations", N);
382 ("\right operand has the following interpretations", N);
386 List_Interps (Nam, Err);
387 end List_Operand_Interps;
389 -- Start of processing for Ambiguous_Operands
392 if Nkind (N) in N_Membership_Test then
393 Error_Msg_N ("ambiguous operands for membership", N);
395 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
396 Error_Msg_N ("ambiguous operands for equality", N);
399 Error_Msg_N ("ambiguous operands for comparison", N);
402 if All_Errors_Mode then
403 List_Operand_Interps (Left_Opnd (N));
404 List_Operand_Interps (Right_Opnd (N));
406 Error_Msg_N ("\use -gnatf switch for details", N);
408 end Ambiguous_Operands;
410 -----------------------
411 -- Analyze_Aggregate --
412 -----------------------
414 -- Most of the analysis of Aggregates requires that the type be known, and
415 -- is therefore put off until resolution of the context. Delta aggregates
416 -- have a base component that determines the enclosing aggregate type so
417 -- its type can be ascertained earlier. This also allows delta aggregates
418 -- to appear in the context of a record type with a private extension, as
419 -- per the latest update of AI12-0127.
421 procedure Analyze_Aggregate (N : Node_Id) is
423 if No (Etype (N)) then
424 if Nkind (N) = N_Delta_Aggregate then
426 Base : constant Node_Id := Expression (N);
434 -- If the base is overloaded, propagate interpretations to the
435 -- enclosing aggregate.
437 if Is_Overloaded (Base) then
438 Get_First_Interp (Base, I, It);
439 Set_Etype (N, Any_Type);
441 while Present (It.Nam) loop
442 Add_One_Interp (N, It.Typ, It.Typ);
443 Get_Next_Interp (I, It);
447 Set_Etype (N, Etype (Base));
452 Set_Etype (N, Any_Composite);
455 end Analyze_Aggregate;
457 -----------------------
458 -- Analyze_Allocator --
459 -----------------------
461 procedure Analyze_Allocator (N : Node_Id) is
462 Loc : constant Source_Ptr := Sloc (N);
463 Sav_Errs : constant Nat := Serious_Errors_Detected;
464 E : Node_Id := Expression (N);
465 Acc_Type : Entity_Id;
472 Check_SPARK_05_Restriction ("allocator is not allowed", N);
474 -- Deal with allocator restrictions
476 -- In accordance with H.4(7), the No_Allocators restriction only applies
477 -- to user-written allocators. The same consideration applies to the
478 -- No_Standard_Allocators_Before_Elaboration restriction.
480 if Comes_From_Source (N) then
481 Check_Restriction (No_Allocators, N);
483 -- Processing for No_Standard_Allocators_After_Elaboration, loop to
484 -- look at enclosing context, checking task/main subprogram case.
488 while Present (P) loop
490 -- For the task case we need a handled sequence of statements,
491 -- where the occurrence of the allocator is within the statements
492 -- and the parent is a task body
494 if Nkind (P) = N_Handled_Sequence_Of_Statements
495 and then Is_List_Member (C)
496 and then List_Containing (C) = Statements (P)
498 Onode := Original_Node (Parent (P));
500 -- Check for allocator within task body, this is a definite
501 -- violation of No_Allocators_After_Elaboration we can detect
504 if Nkind (Onode) = N_Task_Body then
506 (No_Standard_Allocators_After_Elaboration, N);
511 -- The other case is appearance in a subprogram body. This is
512 -- a violation if this is a library level subprogram with no
513 -- parameters. Note that this is now a static error even if the
514 -- subprogram is not the main program (this is a change, in an
515 -- earlier version only the main program was affected, and the
516 -- check had to be done in the binder.
518 if Nkind (P) = N_Subprogram_Body
519 and then Nkind (Parent (P)) = N_Compilation_Unit
520 and then No (Parameter_Specifications (Specification (P)))
523 (No_Standard_Allocators_After_Elaboration, N);
531 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
532 -- any. The expected type for the name is any type. A non-overloading
533 -- rule then requires it to be of a type descended from
534 -- System.Storage_Pools.Subpools.Subpool_Handle.
536 -- This isn't exactly what the AI says, but it seems to be the right
537 -- rule. The AI should be fixed.???
540 Subpool : constant Node_Id := Subpool_Handle_Name (N);
543 if Present (Subpool) then
546 if Is_Overloaded (Subpool) then
547 Error_Msg_N ("ambiguous subpool handle", Subpool);
550 -- Check that Etype (Subpool) is descended from Subpool_Handle
556 -- Analyze the qualified expression or subtype indication
558 if Nkind (E) = N_Qualified_Expression then
559 Acc_Type := Create_Itype (E_Allocator_Type, N);
560 Set_Etype (Acc_Type, Acc_Type);
561 Find_Type (Subtype_Mark (E));
563 -- Analyze the qualified expression, and apply the name resolution
564 -- rule given in 4.7(3).
567 Type_Id := Etype (E);
568 Set_Directly_Designated_Type (Acc_Type, Type_Id);
570 -- A qualified expression requires an exact match of the type,
571 -- class-wide matching is not allowed.
573 -- if Is_Class_Wide_Type (Type_Id)
574 -- and then Base_Type
575 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
577 -- Wrong_Type (Expression (E), Type_Id);
580 -- We don't analyze the qualified expression itself because it's
581 -- part of the allocator. It is fully analyzed and resolved when
582 -- the allocator is resolved with the context type.
584 Set_Etype (E, Type_Id);
586 -- Case where allocator has a subtype indication
591 Base_Typ : Entity_Id;
594 -- If the allocator includes a N_Subtype_Indication then a
595 -- constraint is present, otherwise the node is a subtype mark.
596 -- Introduce an explicit subtype declaration into the tree
597 -- defining some anonymous subtype and rewrite the allocator to
598 -- use this subtype rather than the subtype indication.
600 -- It is important to introduce the explicit subtype declaration
601 -- so that the bounds of the subtype indication are attached to
602 -- the tree in case the allocator is inside a generic unit.
604 -- Finally, if there is no subtype indication and the type is
605 -- a tagged unconstrained type with discriminants, the designated
606 -- object is constrained by their default values, and it is
607 -- simplest to introduce an explicit constraint now. In some cases
608 -- this is done during expansion, but freeze actions are certain
609 -- to be emitted in the proper order if constraint is explicit.
611 if Is_Entity_Name (E) and then Expander_Active then
613 Type_Id := Entity (E);
615 if Is_Tagged_Type (Type_Id)
616 and then Has_Discriminants (Type_Id)
617 and then not Is_Constrained (Type_Id)
620 (Discriminant_Default_Value
621 (First_Discriminant (Type_Id)))
624 Constr : constant List_Id := New_List;
625 Loc : constant Source_Ptr := Sloc (E);
626 Discr : Entity_Id := First_Discriminant (Type_Id);
629 if Present (Discriminant_Default_Value (Discr)) then
630 while Present (Discr) loop
631 Append (Discriminant_Default_Value (Discr), Constr);
632 Next_Discriminant (Discr);
636 Make_Subtype_Indication (Loc,
637 Subtype_Mark => New_Occurrence_Of (Type_Id, Loc),
639 Make_Index_Or_Discriminant_Constraint (Loc,
640 Constraints => Constr)));
646 if Nkind (E) = N_Subtype_Indication then
648 -- A constraint is only allowed for a composite type in Ada
649 -- 95. In Ada 83, a constraint is also allowed for an
650 -- access-to-composite type, but the constraint is ignored.
652 Find_Type (Subtype_Mark (E));
653 Base_Typ := Entity (Subtype_Mark (E));
655 if Is_Elementary_Type (Base_Typ) then
656 if not (Ada_Version = Ada_83
657 and then Is_Access_Type (Base_Typ))
659 Error_Msg_N ("constraint not allowed here", E);
661 if Nkind (Constraint (E)) =
662 N_Index_Or_Discriminant_Constraint
664 Error_Msg_N -- CODEFIX
665 ("\if qualified expression was meant, " &
666 "use apostrophe", Constraint (E));
670 -- Get rid of the bogus constraint:
672 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
673 Analyze_Allocator (N);
677 -- In GNATprove mode we need to preserve the link between
678 -- the original subtype indication and the anonymous subtype,
679 -- to extend proofs to constrained access types. We only do
680 -- that outside of spec expressions, otherwise the declaration
681 -- cannot be inserted and analyzed. In such a case, GNATprove
682 -- later rejects the allocator as it is not used here in
683 -- a non-interfering context (SPARK 4.8(2) and 7.1.3(12)).
686 or else (GNATprove_Mode and then not In_Spec_Expression)
688 Def_Id := Make_Temporary (Loc, 'S');
691 Make_Subtype_Declaration (Loc,
692 Defining_Identifier => Def_Id,
693 Subtype_Indication => Relocate_Node (E)));
695 if Sav_Errs /= Serious_Errors_Detected
696 and then Nkind (Constraint (E)) =
697 N_Index_Or_Discriminant_Constraint
699 Error_Msg_N -- CODEFIX
700 ("if qualified expression was meant, "
701 & "use apostrophe!", Constraint (E));
704 E := New_Occurrence_Of (Def_Id, Loc);
705 Rewrite (Expression (N), E);
709 Type_Id := Process_Subtype (E, N);
710 Acc_Type := Create_Itype (E_Allocator_Type, N);
711 Set_Etype (Acc_Type, Acc_Type);
712 Set_Directly_Designated_Type (Acc_Type, Type_Id);
713 Check_Fully_Declared (Type_Id, N);
715 -- Ada 2005 (AI-231): If the designated type is itself an access
716 -- type that excludes null, its default initialization will
717 -- be a null object, and we can insert an unconditional raise
718 -- before the allocator.
720 -- Ada 2012 (AI-104): A not null indication here is altogether
723 if Can_Never_Be_Null (Type_Id) then
725 Not_Null_Check : constant Node_Id :=
726 Make_Raise_Constraint_Error (Sloc (E),
727 Reason => CE_Null_Not_Allowed);
730 if Expander_Active then
731 Insert_Action (N, Not_Null_Check);
732 Analyze (Not_Null_Check);
734 elsif Warn_On_Ada_2012_Compatibility then
736 ("null value not allowed here in Ada 2012?y?", E);
741 -- Check for missing initialization. Skip this check if we already
742 -- had errors on analyzing the allocator, since in that case these
743 -- are probably cascaded errors.
745 if not Is_Definite_Subtype (Type_Id)
746 and then Serious_Errors_Detected = Sav_Errs
748 -- The build-in-place machinery may produce an allocator when
749 -- the designated type is indefinite but the underlying type is
750 -- not. In this case the unknown discriminants are meaningless
751 -- and should not trigger error messages. Check the parent node
752 -- because the allocator is marked as coming from source.
754 if Present (Underlying_Type (Type_Id))
755 and then Is_Definite_Subtype (Underlying_Type (Type_Id))
756 and then not Comes_From_Source (Parent (N))
760 -- An unusual case arises when the parent of a derived type is
761 -- a limited record extension with unknown discriminants, and
762 -- its full view has no discriminants.
764 -- A more general fix might be to create the proper underlying
765 -- type for such a derived type, but it is a record type with
766 -- no private attributes, so this required extending the
767 -- meaning of this attribute. ???
769 elsif Ekind (Etype (Type_Id)) = E_Record_Type_With_Private
770 and then Present (Underlying_Type (Etype (Type_Id)))
772 not Has_Discriminants (Underlying_Type (Etype (Type_Id)))
773 and then not Comes_From_Source (Parent (N))
777 elsif Is_Class_Wide_Type (Type_Id) then
779 ("initialization required in class-wide allocation", N);
782 if Ada_Version < Ada_2005
783 and then Is_Limited_Type (Type_Id)
785 Error_Msg_N ("unconstrained allocation not allowed", N);
787 if Is_Array_Type (Type_Id) then
789 ("\constraint with array bounds required", N);
791 elsif Has_Unknown_Discriminants (Type_Id) then
794 else pragma Assert (Has_Discriminants (Type_Id));
796 ("\constraint with discriminant values required", N);
799 -- Limited Ada 2005 and general nonlimited case.
800 -- This is an error, except in the case of an
801 -- uninitialized allocator that is generated
802 -- for a build-in-place function return of a
803 -- discriminated but compile-time-known-size
807 if Original_Node (N) /= N
808 and then Nkind (Original_Node (N)) = N_Allocator
811 Qual : constant Node_Id :=
812 Expression (Original_Node (N));
814 (Nkind (Qual) = N_Qualified_Expression);
815 Call : constant Node_Id := Expression (Qual);
817 (Is_Expanded_Build_In_Place_Call (Call));
824 ("uninitialized unconstrained allocation not "
827 if Is_Array_Type (Type_Id) then
829 ("\qualified expression or constraint with "
830 & "array bounds required", N);
832 elsif Has_Unknown_Discriminants (Type_Id) then
833 Error_Msg_N ("\qualified expression required", N);
835 else pragma Assert (Has_Discriminants (Type_Id));
837 ("\qualified expression or constraint with "
838 & "discriminant values required", N);
847 if Is_Abstract_Type (Type_Id) then
848 Error_Msg_N ("cannot allocate abstract object", E);
851 if Has_Task (Designated_Type (Acc_Type)) then
852 Check_Restriction (No_Tasking, N);
853 Check_Restriction (Max_Tasks, N);
854 Check_Restriction (No_Task_Allocators, N);
857 -- Check restriction against dynamically allocated protected objects
859 if Has_Protected (Designated_Type (Acc_Type)) then
860 Check_Restriction (No_Protected_Type_Allocators, N);
863 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
864 -- type is nested, and the designated type needs finalization. The rule
865 -- is conservative in that class-wide types need finalization.
867 if Needs_Finalization (Designated_Type (Acc_Type))
868 and then not Is_Library_Level_Entity (Acc_Type)
870 Check_Restriction (No_Nested_Finalization, N);
873 -- Check that an allocator of a nested access type doesn't create a
874 -- protected object when restriction No_Local_Protected_Objects applies.
876 if Has_Protected (Designated_Type (Acc_Type))
877 and then not Is_Library_Level_Entity (Acc_Type)
879 Check_Restriction (No_Local_Protected_Objects, N);
882 -- Likewise for No_Local_Timing_Events
884 if Has_Timing_Event (Designated_Type (Acc_Type))
885 and then not Is_Library_Level_Entity (Acc_Type)
887 Check_Restriction (No_Local_Timing_Events, N);
890 -- If the No_Streams restriction is set, check that the type of the
891 -- object is not, and does not contain, any subtype derived from
892 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
893 -- Has_Stream just for efficiency reasons. There is no point in
894 -- spending time on a Has_Stream check if the restriction is not set.
896 if Restriction_Check_Required (No_Streams) then
897 if Has_Stream (Designated_Type (Acc_Type)) then
898 Check_Restriction (No_Streams, N);
902 Set_Etype (N, Acc_Type);
904 if not Is_Library_Level_Entity (Acc_Type) then
905 Check_Restriction (No_Local_Allocators, N);
908 if Serious_Errors_Detected > Sav_Errs then
909 Set_Error_Posted (N);
910 Set_Etype (N, Any_Type);
912 end Analyze_Allocator;
914 ---------------------------
915 -- Analyze_Arithmetic_Op --
916 ---------------------------
918 procedure Analyze_Arithmetic_Op (N : Node_Id) is
919 L : constant Node_Id := Left_Opnd (N);
920 R : constant Node_Id := Right_Opnd (N);
924 Candidate_Type := Empty;
925 Analyze_Expression (L);
926 Analyze_Expression (R);
928 -- If the entity is already set, the node is the instantiation of a
929 -- generic node with a non-local reference, or was manufactured by a
930 -- call to Make_Op_xxx. In either case the entity is known to be valid,
931 -- and we do not need to collect interpretations, instead we just get
932 -- the single possible interpretation.
936 if Present (Op_Id) then
937 if Ekind (Op_Id) = E_Operator then
938 Set_Etype (N, Any_Type);
939 Find_Arithmetic_Types (L, R, Op_Id, N);
941 Set_Etype (N, Any_Type);
942 Add_One_Interp (N, Op_Id, Etype (Op_Id));
945 -- Entity is not already set, so we do need to collect interpretations
948 Set_Etype (N, Any_Type);
950 Op_Id := Get_Name_Entity_Id (Chars (N));
951 while Present (Op_Id) loop
952 if Ekind (Op_Id) = E_Operator
953 and then Present (Next_Entity (First_Entity (Op_Id)))
955 Find_Arithmetic_Types (L, R, Op_Id, N);
957 -- The following may seem superfluous, because an operator cannot
958 -- be generic, but this ignores the cleverness of the author of
961 elsif Is_Overloadable (Op_Id) then
962 Analyze_User_Defined_Binary_Op (N, Op_Id);
965 Op_Id := Homonym (Op_Id);
970 Check_Function_Writable_Actuals (N);
971 end Analyze_Arithmetic_Op;
977 -- Function, procedure, and entry calls are checked here. The Name in
978 -- the call may be overloaded. The actuals have been analyzed and may
979 -- themselves be overloaded. On exit from this procedure, the node N
980 -- may have zero, one or more interpretations. In the first case an
981 -- error message is produced. In the last case, the node is flagged
982 -- as overloaded and the interpretations are collected in All_Interp.
984 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
985 -- the type-checking is similar to that of other calls.
987 procedure Analyze_Call (N : Node_Id) is
988 Actuals : constant List_Id := Parameter_Associations (N);
989 Loc : constant Source_Ptr := Sloc (N);
994 Success : Boolean := False;
996 Deref : Boolean := False;
997 -- Flag indicates whether an interpretation of the prefix is a
998 -- parameterless call that returns an access_to_subprogram.
1000 procedure Check_Mixed_Parameter_And_Named_Associations;
1001 -- Check that parameter and named associations are not mixed. This is
1002 -- a restriction in SPARK mode.
1004 procedure Check_Writable_Actuals (N : Node_Id);
1005 -- If the call has out or in-out parameters then mark its outermost
1006 -- enclosing construct as a node on which the writable actuals check
1007 -- must be performed.
1009 function Name_Denotes_Function return Boolean;
1010 -- If the type of the name is an access to subprogram, this may be the
1011 -- type of a name, or the return type of the function being called. If
1012 -- the name is not an entity then it can denote a protected function.
1013 -- Until we distinguish Etype from Return_Type, we must use this routine
1014 -- to resolve the meaning of the name in the call.
1016 procedure No_Interpretation;
1017 -- Output error message when no valid interpretation exists
1019 --------------------------------------------------
1020 -- Check_Mixed_Parameter_And_Named_Associations --
1021 --------------------------------------------------
1023 procedure Check_Mixed_Parameter_And_Named_Associations is
1025 Named_Seen : Boolean;
1028 Named_Seen := False;
1030 Actual := First (Actuals);
1031 while Present (Actual) loop
1032 case Nkind (Actual) is
1033 when N_Parameter_Association =>
1035 Check_SPARK_05_Restriction
1036 ("named association cannot follow positional one",
1047 end Check_Mixed_Parameter_And_Named_Associations;
1049 ----------------------------
1050 -- Check_Writable_Actuals --
1051 ----------------------------
1053 -- The identification of conflicts in calls to functions with writable
1054 -- actuals is performed in the analysis phase of the front end to ensure
1055 -- that it reports exactly the same errors compiling with and without
1056 -- expansion enabled. It is performed in two stages:
1058 -- 1) When a call to a function with out-mode parameters is found,
1059 -- we climb to the outermost enclosing construct that can be
1060 -- evaluated in arbitrary order and we mark it with the flag
1063 -- 2) When the analysis of the marked node is complete, we traverse
1064 -- its decorated subtree searching for conflicts (see function
1065 -- Sem_Util.Check_Function_Writable_Actuals).
1067 -- The unique exception to this general rule is for aggregates, since
1068 -- their analysis is performed by the front end in the resolution
1069 -- phase. For aggregates we do not climb to their enclosing construct:
1070 -- we restrict the analysis to the subexpressions initializing the
1071 -- aggregate components.
1073 -- This implies that the analysis of expressions containing aggregates
1074 -- is not complete, since there may be conflicts on writable actuals
1075 -- involving subexpressions of the enclosing logical or arithmetic
1076 -- expressions. However, we cannot wait and perform the analysis when
1077 -- the whole subtree is resolved, since the subtrees may be transformed,
1078 -- thus adding extra complexity and computation cost to identify and
1079 -- report exactly the same errors compiling with and without expansion
1082 procedure Check_Writable_Actuals (N : Node_Id) is
1084 if Comes_From_Source (N)
1085 and then Present (Get_Subprogram_Entity (N))
1086 and then Has_Out_Or_In_Out_Parameter (Get_Subprogram_Entity (N))
1088 -- For procedures and entries there is no need to climb since
1089 -- we only need to check if the actuals of this call invoke
1090 -- functions whose out-mode parameters overlap.
1092 if Nkind (N) /= N_Function_Call then
1093 Set_Check_Actuals (N);
1095 -- For calls to functions we climb to the outermost enclosing
1096 -- construct where the out-mode actuals of this function may
1097 -- introduce conflicts.
1101 Outermost : Node_Id := Empty; -- init to avoid warning
1105 while Present (P) loop
1106 -- For object declarations we can climb to the node from
1107 -- its object definition branch or from its initializing
1108 -- expression. We prefer to mark the child node as the
1109 -- outermost construct to avoid adding further complexity
1110 -- to the routine that will later take care of
1111 -- performing the writable actuals check.
1113 if Has_Arbitrary_Evaluation_Order (Nkind (P))
1114 and then not Nkind_In (P, N_Assignment_Statement,
1115 N_Object_Declaration)
1120 -- Avoid climbing more than needed
1122 exit when Stop_Subtree_Climbing (Nkind (P))
1123 or else (Nkind (P) = N_Range
1125 Nkind_In (Parent (P), N_In, N_Not_In));
1130 Set_Check_Actuals (Outermost);
1134 end Check_Writable_Actuals;
1136 ---------------------------
1137 -- Name_Denotes_Function --
1138 ---------------------------
1140 function Name_Denotes_Function return Boolean is
1142 if Is_Entity_Name (Nam) then
1143 return Ekind (Entity (Nam)) = E_Function;
1144 elsif Nkind (Nam) = N_Selected_Component then
1145 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
1149 end Name_Denotes_Function;
1151 -----------------------
1152 -- No_Interpretation --
1153 -----------------------
1155 procedure No_Interpretation is
1156 L : constant Boolean := Is_List_Member (N);
1157 K : constant Node_Kind := Nkind (Parent (N));
1160 -- If the node is in a list whose parent is not an expression then it
1161 -- must be an attempted procedure call.
1163 if L and then K not in N_Subexpr then
1164 if Ekind (Entity (Nam)) = E_Generic_Procedure then
1166 ("must instantiate generic procedure& before call",
1169 Error_Msg_N ("procedure or entry name expected", Nam);
1172 -- Check for tasking cases where only an entry call will do
1175 and then Nkind_In (K, N_Entry_Call_Alternative,
1176 N_Triggering_Alternative)
1178 Error_Msg_N ("entry name expected", Nam);
1180 -- Otherwise give general error message
1183 Error_Msg_N ("invalid prefix in call", Nam);
1185 end No_Interpretation;
1187 -- Start of processing for Analyze_Call
1190 if Restriction_Check_Required (SPARK_05) then
1191 Check_Mixed_Parameter_And_Named_Associations;
1194 -- Initialize the type of the result of the call to the error type,
1195 -- which will be reset if the type is successfully resolved.
1197 Set_Etype (N, Any_Type);
1201 if not Is_Overloaded (Nam) then
1203 -- Only one interpretation to check
1205 if Ekind (Etype (Nam)) = E_Subprogram_Type then
1206 Nam_Ent := Etype (Nam);
1208 -- If the prefix is an access_to_subprogram, this may be an indirect
1209 -- call. This is the case if the name in the call is not an entity
1210 -- name, or if it is a function name in the context of a procedure
1211 -- call. In this latter case, we have a call to a parameterless
1212 -- function that returns a pointer_to_procedure which is the entity
1213 -- being called. Finally, F (X) may be a call to a parameterless
1214 -- function that returns a pointer to a function with parameters.
1215 -- Note that if F returns an access-to-subprogram whose designated
1216 -- type is an array, F (X) cannot be interpreted as an indirect call
1217 -- through the result of the call to F.
1219 elsif Is_Access_Type (Etype (Nam))
1220 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
1222 (not Name_Denotes_Function
1223 or else Nkind (N) = N_Procedure_Call_Statement
1225 (Nkind (Parent (N)) /= N_Explicit_Dereference
1226 and then Is_Entity_Name (Nam)
1227 and then No (First_Formal (Entity (Nam)))
1229 Is_Array_Type (Etype (Designated_Type (Etype (Nam))))
1230 and then Present (Actuals)))
1232 Nam_Ent := Designated_Type (Etype (Nam));
1233 Insert_Explicit_Dereference (Nam);
1235 -- Selected component case. Simple entry or protected operation,
1236 -- where the entry name is given by the selector name.
1238 elsif Nkind (Nam) = N_Selected_Component then
1239 Nam_Ent := Entity (Selector_Name (Nam));
1241 if not Ekind_In (Nam_Ent, E_Entry,
1246 Error_Msg_N ("name in call is not a callable entity", Nam);
1247 Set_Etype (N, Any_Type);
1251 -- If the name is an Indexed component, it can be a call to a member
1252 -- of an entry family. The prefix must be a selected component whose
1253 -- selector is the entry. Analyze_Procedure_Call normalizes several
1254 -- kinds of call into this form.
1256 elsif Nkind (Nam) = N_Indexed_Component then
1257 if Nkind (Prefix (Nam)) = N_Selected_Component then
1258 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
1260 Error_Msg_N ("name in call is not a callable entity", Nam);
1261 Set_Etype (N, Any_Type);
1265 elsif not Is_Entity_Name (Nam) then
1266 Error_Msg_N ("name in call is not a callable entity", Nam);
1267 Set_Etype (N, Any_Type);
1271 Nam_Ent := Entity (Nam);
1273 -- If not overloadable, this may be a generalized indexing
1274 -- operation with named associations. Rewrite again as an
1275 -- indexed component and analyze as container indexing.
1277 if not Is_Overloadable (Nam_Ent) then
1279 (Find_Value_Of_Aspect
1280 (Etype (Nam_Ent), Aspect_Constant_Indexing))
1283 Make_Indexed_Component (Sloc (N),
1285 Expressions => Parameter_Associations (N)));
1287 if Try_Container_Indexing (N, Nam, Expressions (N)) then
1301 -- Operations generated for RACW stub types are called only through
1302 -- dispatching, and can never be the static interpretation of a call.
1304 if Is_RACW_Stub_Type_Operation (Nam_Ent) then
1309 Analyze_One_Call (N, Nam_Ent, True, Success);
1311 -- If this is an indirect call, the return type of the access_to
1312 -- subprogram may be an incomplete type. At the point of the call,
1313 -- use the full type if available, and at the same time update the
1314 -- return type of the access_to_subprogram.
1317 and then Nkind (Nam) = N_Explicit_Dereference
1318 and then Ekind (Etype (N)) = E_Incomplete_Type
1319 and then Present (Full_View (Etype (N)))
1321 Set_Etype (N, Full_View (Etype (N)));
1322 Set_Etype (Nam_Ent, Etype (N));
1328 -- An overloaded selected component must denote overloaded operations
1329 -- of a concurrent type. The interpretations are attached to the
1330 -- simple name of those operations.
1332 if Nkind (Nam) = N_Selected_Component then
1333 Nam := Selector_Name (Nam);
1336 Get_First_Interp (Nam, X, It);
1337 while Present (It.Nam) loop
1341 -- Name may be call that returns an access to subprogram, or more
1342 -- generally an overloaded expression one of whose interpretations
1343 -- yields an access to subprogram. If the name is an entity, we do
1344 -- not dereference, because the node is a call that returns the
1345 -- access type: note difference between f(x), where the call may
1346 -- return an access subprogram type, and f(x)(y), where the type
1347 -- returned by the call to f is implicitly dereferenced to analyze
1350 if Is_Access_Type (Nam_Ent) then
1351 Nam_Ent := Designated_Type (Nam_Ent);
1353 elsif Is_Access_Type (Etype (Nam_Ent))
1355 (not Is_Entity_Name (Nam)
1356 or else Nkind (N) = N_Procedure_Call_Statement)
1357 and then Ekind (Designated_Type (Etype (Nam_Ent)))
1360 Nam_Ent := Designated_Type (Etype (Nam_Ent));
1362 if Is_Entity_Name (Nam) then
1367 -- If the call has been rewritten from a prefixed call, the first
1368 -- parameter has been analyzed, but may need a subsequent
1369 -- dereference, so skip its analysis now.
1371 if Is_Rewrite_Substitution (N)
1372 and then Nkind (Original_Node (N)) = Nkind (N)
1373 and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N)))
1374 and then Present (Parameter_Associations (N))
1375 and then Present (Etype (First (Parameter_Associations (N))))
1378 (N, Nam_Ent, False, Success, Skip_First => True);
1380 Analyze_One_Call (N, Nam_Ent, False, Success);
1383 -- If the interpretation succeeds, mark the proper type of the
1384 -- prefix (any valid candidate will do). If not, remove the
1385 -- candidate interpretation. If this is a parameterless call
1386 -- on an anonymous access to subprogram, X is a variable with
1387 -- an access discriminant D, the entity in the interpretation is
1388 -- D, so rewrite X as X.D.all.
1392 and then Nkind (Parent (N)) /= N_Explicit_Dereference
1394 if Ekind (It.Nam) = E_Discriminant
1395 and then Has_Implicit_Dereference (It.Nam)
1398 Make_Explicit_Dereference (Loc,
1400 Make_Selected_Component (Loc,
1402 New_Occurrence_Of (Entity (Nam), Loc),
1404 New_Occurrence_Of (It.Nam, Loc))));
1410 Set_Entity (Nam, It.Nam);
1411 Insert_Explicit_Dereference (Nam);
1412 Set_Etype (Nam, Nam_Ent);
1416 Set_Etype (Nam, It.Typ);
1419 elsif Nkind_In (Name (N), N_Function_Call, N_Selected_Component)
1424 Get_Next_Interp (X, It);
1427 -- If the name is the result of a function call, it can only be a
1428 -- call to a function returning an access to subprogram. Insert
1429 -- explicit dereference.
1431 if Nkind (Nam) = N_Function_Call then
1432 Insert_Explicit_Dereference (Nam);
1435 if Etype (N) = Any_Type then
1437 -- None of the interpretations is compatible with the actuals
1439 Diagnose_Call (N, Nam);
1441 -- Special checks for uninstantiated put routines
1443 if Nkind (N) = N_Procedure_Call_Statement
1444 and then Is_Entity_Name (Nam)
1445 and then Chars (Nam) = Name_Put
1446 and then List_Length (Actuals) = 1
1449 Arg : constant Node_Id := First (Actuals);
1453 if Nkind (Arg) = N_Parameter_Association then
1454 Typ := Etype (Explicit_Actual_Parameter (Arg));
1459 if Is_Signed_Integer_Type (Typ) then
1461 ("possible missing instantiation of "
1462 & "'Text_'I'O.'Integer_'I'O!", Nam);
1464 elsif Is_Modular_Integer_Type (Typ) then
1466 ("possible missing instantiation of "
1467 & "'Text_'I'O.'Modular_'I'O!", Nam);
1469 elsif Is_Floating_Point_Type (Typ) then
1471 ("possible missing instantiation of "
1472 & "'Text_'I'O.'Float_'I'O!", Nam);
1474 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
1476 ("possible missing instantiation of "
1477 & "'Text_'I'O.'Fixed_'I'O!", Nam);
1479 elsif Is_Decimal_Fixed_Point_Type (Typ) then
1481 ("possible missing instantiation of "
1482 & "'Text_'I'O.'Decimal_'I'O!", Nam);
1484 elsif Is_Enumeration_Type (Typ) then
1486 ("possible missing instantiation of "
1487 & "'Text_'I'O.'Enumeration_'I'O!", Nam);
1492 elsif not Is_Overloaded (N)
1493 and then Is_Entity_Name (Nam)
1495 -- Resolution yields a single interpretation. Verify that the
1496 -- reference has capitalization consistent with the declaration.
1498 Set_Entity_With_Checks (Nam, Entity (Nam));
1499 Generate_Reference (Entity (Nam), Nam);
1501 Set_Etype (Nam, Etype (Entity (Nam)));
1503 Remove_Abstract_Operations (N);
1509 if Ada_Version >= Ada_2012 then
1511 -- Check if the call contains a function with writable actuals
1513 Check_Writable_Actuals (N);
1515 -- If found and the outermost construct that can be evaluated in
1516 -- an arbitrary order is precisely this call, then check all its
1519 Check_Function_Writable_Actuals (N);
1521 -- The return type of the function may be incomplete. This can be
1522 -- the case if the type is a generic formal, or a limited view. It
1523 -- can also happen when the function declaration appears before the
1524 -- full view of the type (which is legal in Ada 2012) and the call
1525 -- appears in a different unit, in which case the incomplete view
1526 -- must be replaced with the full view (or the nonlimited view)
1527 -- to prevent subsequent type errors. Note that the usual install/
1528 -- removal of limited_with clauses is not sufficient to handle this
1529 -- case, because the limited view may have been captured in another
1530 -- compilation unit that defines the current function.
1532 if Is_Incomplete_Type (Etype (N)) then
1533 if Present (Full_View (Etype (N))) then
1534 if Is_Entity_Name (Nam) then
1535 Set_Etype (Nam, Full_View (Etype (N)));
1536 Set_Etype (Entity (Nam), Full_View (Etype (N)));
1539 Set_Etype (N, Full_View (Etype (N)));
1541 elsif From_Limited_With (Etype (N))
1542 and then Present (Non_Limited_View (Etype (N)))
1544 Set_Etype (N, Non_Limited_View (Etype (N)));
1546 -- If there is no completion for the type, this may be because
1547 -- there is only a limited view of it and there is nothing in
1548 -- the context of the current unit that has required a regular
1549 -- compilation of the unit containing the type. We recognize
1550 -- this unusual case by the fact that unit is not analyzed.
1551 -- Note that the call being analyzed is in a different unit from
1552 -- the function declaration, and nothing indicates that the type
1553 -- is a limited view.
1555 elsif Ekind (Scope (Etype (N))) = E_Package
1556 and then Present (Limited_View (Scope (Etype (N))))
1557 and then not Analyzed (Unit_Declaration_Node (Scope (Etype (N))))
1560 ("cannot call function that returns limited view of}",
1564 ("\there must be a regular with_clause for package & in the "
1565 & "current unit, or in some unit in its context",
1566 N, Scope (Etype (N)));
1568 Set_Etype (N, Any_Type);
1574 -----------------------------
1575 -- Analyze_Case_Expression --
1576 -----------------------------
1578 procedure Analyze_Case_Expression (N : Node_Id) is
1579 procedure Non_Static_Choice_Error (Choice : Node_Id);
1580 -- Error routine invoked by the generic instantiation below when
1581 -- the case expression has a non static choice.
1583 package Case_Choices_Analysis is new
1584 Generic_Analyze_Choices
1585 (Process_Associated_Node => No_OP);
1586 use Case_Choices_Analysis;
1588 package Case_Choices_Checking is new
1589 Generic_Check_Choices
1590 (Process_Empty_Choice => No_OP,
1591 Process_Non_Static_Choice => Non_Static_Choice_Error,
1592 Process_Associated_Node => No_OP);
1593 use Case_Choices_Checking;
1595 -----------------------------
1596 -- Non_Static_Choice_Error --
1597 -----------------------------
1599 procedure Non_Static_Choice_Error (Choice : Node_Id) is
1601 Flag_Non_Static_Expr
1602 ("choice given in case expression is not static!", Choice);
1603 end Non_Static_Choice_Error;
1607 Expr : constant Node_Id := Expression (N);
1609 Exp_Type : Entity_Id;
1610 Exp_Btype : Entity_Id;
1612 FirstX : Node_Id := Empty;
1613 -- First expression in the case for which there is some type information
1614 -- available, i.e. it is not Any_Type, which can happen because of some
1615 -- error, or from the use of e.g. raise Constraint_Error.
1617 Others_Present : Boolean;
1618 -- Indicates if Others was present
1620 Wrong_Alt : Node_Id := Empty;
1621 -- For error reporting
1623 -- Start of processing for Analyze_Case_Expression
1626 if Comes_From_Source (N) then
1627 Check_Compiler_Unit ("case expression", N);
1630 Analyze_And_Resolve (Expr, Any_Discrete);
1631 Check_Unset_Reference (Expr);
1632 Exp_Type := Etype (Expr);
1633 Exp_Btype := Base_Type (Exp_Type);
1635 Alt := First (Alternatives (N));
1636 while Present (Alt) loop
1637 if Error_Posted (Expression (Alt)) then
1641 Analyze (Expression (Alt));
1643 if No (FirstX) and then Etype (Expression (Alt)) /= Any_Type then
1644 FirstX := Expression (Alt);
1650 -- Get our initial type from the first expression for which we got some
1651 -- useful type information from the expression.
1657 if not Is_Overloaded (FirstX) then
1658 Set_Etype (N, Etype (FirstX));
1666 Set_Etype (N, Any_Type);
1668 Get_First_Interp (FirstX, I, It);
1669 while Present (It.Nam) loop
1671 -- For each interpretation of the first expression, we only
1672 -- add the interpretation if every other expression in the
1673 -- case expression alternatives has a compatible type.
1675 Alt := Next (First (Alternatives (N)));
1676 while Present (Alt) loop
1677 exit when not Has_Compatible_Type (Expression (Alt), It.Typ);
1682 Add_One_Interp (N, It.Typ, It.Typ);
1687 Get_Next_Interp (I, It);
1692 Exp_Btype := Base_Type (Exp_Type);
1694 -- The expression must be of a discrete type which must be determinable
1695 -- independently of the context in which the expression occurs, but
1696 -- using the fact that the expression must be of a discrete type.
1697 -- Moreover, the type this expression must not be a character literal
1698 -- (which is always ambiguous).
1700 -- If error already reported by Resolve, nothing more to do
1702 if Exp_Btype = Any_Discrete or else Exp_Btype = Any_Type then
1705 -- Special casee message for character literal
1707 elsif Exp_Btype = Any_Character then
1709 ("character literal as case expression is ambiguous", Expr);
1713 if Etype (N) = Any_Type and then Present (Wrong_Alt) then
1715 ("type incompatible with that of previous alternatives",
1716 Expression (Wrong_Alt));
1720 -- If the case expression is a formal object of mode in out, then
1721 -- treat it as having a nonstatic subtype by forcing use of the base
1722 -- type (which has to get passed to Check_Case_Choices below). Also
1723 -- use base type when the case expression is parenthesized.
1725 if Paren_Count (Expr) > 0
1726 or else (Is_Entity_Name (Expr)
1727 and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter)
1729 Exp_Type := Exp_Btype;
1732 -- The case expression alternatives cover the range of a static subtype
1733 -- subject to aspect Static_Predicate. Do not check the choices when the
1734 -- case expression has not been fully analyzed yet because this may lead
1737 if Is_OK_Static_Subtype (Exp_Type)
1738 and then Has_Static_Predicate_Aspect (Exp_Type)
1739 and then In_Spec_Expression
1743 -- Call Analyze_Choices and Check_Choices to do the rest of the work
1746 Analyze_Choices (Alternatives (N), Exp_Type);
1747 Check_Choices (N, Alternatives (N), Exp_Type, Others_Present);
1749 if Exp_Type = Universal_Integer and then not Others_Present then
1751 ("case on universal integer requires OTHERS choice", Expr);
1754 end Analyze_Case_Expression;
1756 ---------------------------
1757 -- Analyze_Comparison_Op --
1758 ---------------------------
1760 procedure Analyze_Comparison_Op (N : Node_Id) is
1761 L : constant Node_Id := Left_Opnd (N);
1762 R : constant Node_Id := Right_Opnd (N);
1763 Op_Id : Entity_Id := Entity (N);
1766 Set_Etype (N, Any_Type);
1767 Candidate_Type := Empty;
1769 Analyze_Expression (L);
1770 Analyze_Expression (R);
1772 if Present (Op_Id) then
1773 if Ekind (Op_Id) = E_Operator then
1774 Find_Comparison_Types (L, R, Op_Id, N);
1776 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1779 if Is_Overloaded (L) then
1780 Set_Etype (L, Intersect_Types (L, R));
1784 Op_Id := Get_Name_Entity_Id (Chars (N));
1785 while Present (Op_Id) loop
1786 if Ekind (Op_Id) = E_Operator then
1787 Find_Comparison_Types (L, R, Op_Id, N);
1789 Analyze_User_Defined_Binary_Op (N, Op_Id);
1792 Op_Id := Homonym (Op_Id);
1797 Check_Function_Writable_Actuals (N);
1798 end Analyze_Comparison_Op;
1800 ---------------------------
1801 -- Analyze_Concatenation --
1802 ---------------------------
1804 procedure Analyze_Concatenation (N : Node_Id) is
1806 -- We wish to avoid deep recursion, because concatenations are often
1807 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1808 -- operands nonrecursively until we find something that is not a
1809 -- concatenation (A in this case), or has already been analyzed. We
1810 -- analyze that, and then walk back up the tree following Parent
1811 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1812 -- work at each level. The Parent pointers allow us to avoid recursion,
1813 -- and thus avoid running out of memory.
1819 Candidate_Type := Empty;
1821 -- The following code is equivalent to:
1823 -- Set_Etype (N, Any_Type);
1824 -- Analyze_Expression (Left_Opnd (N));
1825 -- Analyze_Concatenation_Rest (N);
1827 -- where the Analyze_Expression call recurses back here if the left
1828 -- operand is a concatenation.
1830 -- Walk down left operands
1833 Set_Etype (NN, Any_Type);
1834 L := Left_Opnd (NN);
1835 exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
1839 -- Now (given the above example) NN is A&B and L is A
1841 -- First analyze L ...
1843 Analyze_Expression (L);
1845 -- ... then walk NN back up until we reach N (where we started), calling
1846 -- Analyze_Concatenation_Rest along the way.
1849 Analyze_Concatenation_Rest (NN);
1853 end Analyze_Concatenation;
1855 --------------------------------
1856 -- Analyze_Concatenation_Rest --
1857 --------------------------------
1859 -- If the only one-dimensional array type in scope is String,
1860 -- this is the resulting type of the operation. Otherwise there
1861 -- will be a concatenation operation defined for each user-defined
1862 -- one-dimensional array.
1864 procedure Analyze_Concatenation_Rest (N : Node_Id) is
1865 L : constant Node_Id := Left_Opnd (N);
1866 R : constant Node_Id := Right_Opnd (N);
1867 Op_Id : Entity_Id := Entity (N);
1872 Analyze_Expression (R);
1874 -- If the entity is present, the node appears in an instance, and
1875 -- denotes a predefined concatenation operation. The resulting type is
1876 -- obtained from the arguments when possible. If the arguments are
1877 -- aggregates, the array type and the concatenation type must be
1880 if Present (Op_Id) then
1881 if Ekind (Op_Id) = E_Operator then
1882 LT := Base_Type (Etype (L));
1883 RT := Base_Type (Etype (R));
1885 if Is_Array_Type (LT)
1886 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1888 Add_One_Interp (N, Op_Id, LT);
1890 elsif Is_Array_Type (RT)
1891 and then LT = Base_Type (Component_Type (RT))
1893 Add_One_Interp (N, Op_Id, RT);
1895 -- If one operand is a string type or a user-defined array type,
1896 -- and the other is a literal, result is of the specific type.
1899 (Root_Type (LT) = Standard_String
1900 or else Scope (LT) /= Standard_Standard)
1901 and then Etype (R) = Any_String
1903 Add_One_Interp (N, Op_Id, LT);
1906 (Root_Type (RT) = Standard_String
1907 or else Scope (RT) /= Standard_Standard)
1908 and then Etype (L) = Any_String
1910 Add_One_Interp (N, Op_Id, RT);
1912 elsif not Is_Generic_Type (Etype (Op_Id)) then
1913 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1916 -- Type and its operations must be visible
1918 Set_Entity (N, Empty);
1919 Analyze_Concatenation (N);
1923 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1927 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1928 while Present (Op_Id) loop
1929 if Ekind (Op_Id) = E_Operator then
1931 -- Do not consider operators declared in dead code, they
1932 -- cannot be part of the resolution.
1934 if Is_Eliminated (Op_Id) then
1937 Find_Concatenation_Types (L, R, Op_Id, N);
1941 Analyze_User_Defined_Binary_Op (N, Op_Id);
1944 Op_Id := Homonym (Op_Id);
1949 end Analyze_Concatenation_Rest;
1951 -------------------------
1952 -- Analyze_Equality_Op --
1953 -------------------------
1955 procedure Analyze_Equality_Op (N : Node_Id) is
1956 Loc : constant Source_Ptr := Sloc (N);
1957 L : constant Node_Id := Left_Opnd (N);
1958 R : constant Node_Id := Right_Opnd (N);
1962 Set_Etype (N, Any_Type);
1963 Candidate_Type := Empty;
1965 Analyze_Expression (L);
1966 Analyze_Expression (R);
1968 -- If the entity is set, the node is a generic instance with a non-local
1969 -- reference to the predefined operator or to a user-defined function.
1970 -- It can also be an inequality that is expanded into the negation of a
1971 -- call to a user-defined equality operator.
1973 -- For the predefined case, the result is Boolean, regardless of the
1974 -- type of the operands. The operands may even be limited, if they are
1975 -- generic actuals. If they are overloaded, label the left argument with
1976 -- the common type that must be present, or with the type of the formal
1977 -- of the user-defined function.
1979 if Present (Entity (N)) then
1980 Op_Id := Entity (N);
1982 if Ekind (Op_Id) = E_Operator then
1983 Add_One_Interp (N, Op_Id, Standard_Boolean);
1985 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1988 if Is_Overloaded (L) then
1989 if Ekind (Op_Id) = E_Operator then
1990 Set_Etype (L, Intersect_Types (L, R));
1992 Set_Etype (L, Etype (First_Formal (Op_Id)));
1997 Op_Id := Get_Name_Entity_Id (Chars (N));
1998 while Present (Op_Id) loop
1999 if Ekind (Op_Id) = E_Operator then
2000 Find_Equality_Types (L, R, Op_Id, N);
2002 Analyze_User_Defined_Binary_Op (N, Op_Id);
2005 Op_Id := Homonym (Op_Id);
2009 -- If there was no match, and the operator is inequality, this may be
2010 -- a case where inequality has not been made explicit, as for tagged
2011 -- types. Analyze the node as the negation of an equality operation.
2012 -- This cannot be done earlier, because before analysis we cannot rule
2013 -- out the presence of an explicit inequality.
2015 if Etype (N) = Any_Type
2016 and then Nkind (N) = N_Op_Ne
2018 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
2019 while Present (Op_Id) loop
2020 if Ekind (Op_Id) = E_Operator then
2021 Find_Equality_Types (L, R, Op_Id, N);
2023 Analyze_User_Defined_Binary_Op (N, Op_Id);
2026 Op_Id := Homonym (Op_Id);
2029 if Etype (N) /= Any_Type then
2030 Op_Id := Entity (N);
2036 Left_Opnd => Left_Opnd (N),
2037 Right_Opnd => Right_Opnd (N))));
2039 Set_Entity (Right_Opnd (N), Op_Id);
2045 Check_Function_Writable_Actuals (N);
2046 end Analyze_Equality_Op;
2048 ----------------------------------
2049 -- Analyze_Explicit_Dereference --
2050 ----------------------------------
2052 procedure Analyze_Explicit_Dereference (N : Node_Id) is
2053 Loc : constant Source_Ptr := Sloc (N);
2054 P : constant Node_Id := Prefix (N);
2060 function Is_Function_Type return Boolean;
2061 -- Check whether node may be interpreted as an implicit function call
2063 ----------------------
2064 -- Is_Function_Type --
2065 ----------------------
2067 function Is_Function_Type return Boolean is
2072 if not Is_Overloaded (N) then
2073 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
2074 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
2077 Get_First_Interp (N, I, It);
2078 while Present (It.Nam) loop
2079 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
2080 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
2085 Get_Next_Interp (I, It);
2090 end Is_Function_Type;
2092 -- Start of processing for Analyze_Explicit_Dereference
2095 -- If source node, check SPARK restriction. We guard this with the
2096 -- source node check, because ???
2098 if Comes_From_Source (N) then
2099 Check_SPARK_05_Restriction ("explicit dereference is not allowed", N);
2102 -- In formal verification mode, keep track of all reads and writes
2103 -- through explicit dereferences.
2105 if GNATprove_Mode then
2106 SPARK_Specific.Generate_Dereference (N);
2110 Set_Etype (N, Any_Type);
2112 -- Test for remote access to subprogram type, and if so return
2113 -- after rewriting the original tree.
2115 if Remote_AST_E_Dereference (P) then
2119 -- Normal processing for other than remote access to subprogram type
2121 if not Is_Overloaded (P) then
2122 if Is_Access_Type (Etype (P)) then
2127 DT : constant Entity_Id := Designated_Type (Etype (P));
2130 -- An explicit dereference is a legal occurrence of an
2131 -- incomplete type imported through a limited_with clause, if
2132 -- the full view is visible, or if we are within an instance
2133 -- body, where the enclosing body has a regular with_clause
2136 if From_Limited_With (DT)
2137 and then not From_Limited_With (Scope (DT))
2139 (Is_Immediately_Visible (Scope (DT))
2141 (Is_Child_Unit (Scope (DT))
2142 and then Is_Visible_Lib_Unit (Scope (DT)))
2143 or else In_Instance_Body)
2145 Set_Etype (N, Available_View (DT));
2152 elsif Etype (P) /= Any_Type then
2153 Error_Msg_N ("prefix of dereference must be an access type", N);
2158 Get_First_Interp (P, I, It);
2159 while Present (It.Nam) loop
2162 if Is_Access_Type (T) then
2163 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
2166 Get_Next_Interp (I, It);
2169 -- Error if no interpretation of the prefix has an access type
2171 if Etype (N) = Any_Type then
2173 ("access type required in prefix of explicit dereference", P);
2174 Set_Etype (N, Any_Type);
2180 and then Nkind (Parent (N)) /= N_Indexed_Component
2182 and then (Nkind (Parent (N)) /= N_Function_Call
2183 or else N /= Name (Parent (N)))
2185 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
2186 or else N /= Name (Parent (N)))
2188 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
2189 and then (Nkind (Parent (N)) /= N_Attribute_Reference
2191 (Attribute_Name (Parent (N)) /= Name_Address
2193 Attribute_Name (Parent (N)) /= Name_Access))
2195 -- Name is a function call with no actuals, in a context that
2196 -- requires deproceduring (including as an actual in an enclosing
2197 -- function or procedure call). There are some pathological cases
2198 -- where the prefix might include functions that return access to
2199 -- subprograms and others that return a regular type. Disambiguation
2200 -- of those has to take place in Resolve.
2203 Make_Function_Call (Loc,
2204 Name => Make_Explicit_Dereference (Loc, P),
2205 Parameter_Associations => New_List);
2207 -- If the prefix is overloaded, remove operations that have formals,
2208 -- we know that this is a parameterless call.
2210 if Is_Overloaded (P) then
2211 Get_First_Interp (P, I, It);
2212 while Present (It.Nam) loop
2215 if No (First_Formal (Base_Type (Designated_Type (T)))) then
2221 Get_Next_Interp (I, It);
2228 elsif not Is_Function_Type
2229 and then Is_Overloaded (N)
2231 -- The prefix may include access to subprograms and other access
2232 -- types. If the context selects the interpretation that is a
2233 -- function call (not a procedure call) we cannot rewrite the node
2234 -- yet, but we include the result of the call interpretation.
2236 Get_First_Interp (N, I, It);
2237 while Present (It.Nam) loop
2238 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
2239 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
2240 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
2242 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
2245 Get_Next_Interp (I, It);
2249 -- A value of remote access-to-class-wide must not be dereferenced
2252 Validate_Remote_Access_To_Class_Wide_Type (N);
2253 end Analyze_Explicit_Dereference;
2255 ------------------------
2256 -- Analyze_Expression --
2257 ------------------------
2259 procedure Analyze_Expression (N : Node_Id) is
2262 -- If the expression is an indexed component that will be rewritten
2263 -- as a container indexing, it has already been analyzed.
2265 if Nkind (N) = N_Indexed_Component
2266 and then Present (Generalized_Indexing (N))
2272 Check_Parameterless_Call (N);
2274 end Analyze_Expression;
2276 -------------------------------------
2277 -- Analyze_Expression_With_Actions --
2278 -------------------------------------
2280 procedure Analyze_Expression_With_Actions (N : Node_Id) is
2284 A := First (Actions (N));
2285 while Present (A) loop
2290 Analyze_Expression (Expression (N));
2291 Set_Etype (N, Etype (Expression (N)));
2292 end Analyze_Expression_With_Actions;
2294 ---------------------------
2295 -- Analyze_If_Expression --
2296 ---------------------------
2298 procedure Analyze_If_Expression (N : Node_Id) is
2299 Condition : constant Node_Id := First (Expressions (N));
2300 Then_Expr : Node_Id;
2301 Else_Expr : Node_Id;
2304 -- Defend against error of missing expressions from previous error
2306 if No (Condition) then
2307 Check_Error_Detected;
2311 Then_Expr := Next (Condition);
2313 if No (Then_Expr) then
2314 Check_Error_Detected;
2318 Else_Expr := Next (Then_Expr);
2320 if Comes_From_Source (N) then
2321 Check_SPARK_05_Restriction ("if expression is not allowed", N);
2324 if Comes_From_Source (N) then
2325 Check_Compiler_Unit ("if expression", N);
2328 -- Analyze and resolve the condition. We need to resolve this now so
2329 -- that it gets folded to True/False if possible, before we analyze
2330 -- the THEN/ELSE branches, because when analyzing these branches, we
2331 -- may call Is_Statically_Unevaluated, which expects the condition of
2332 -- an enclosing IF to have been analyze/resolved/evaluated.
2334 Analyze_Expression (Condition);
2335 Resolve (Condition, Any_Boolean);
2337 -- Analyze THEN expression and (if present) ELSE expression. For those
2338 -- we delay resolution in the normal manner, because of overloading etc.
2340 Analyze_Expression (Then_Expr);
2342 if Present (Else_Expr) then
2343 Analyze_Expression (Else_Expr);
2346 -- If then expression not overloaded, then that decides the type
2348 if not Is_Overloaded (Then_Expr) then
2349 Set_Etype (N, Etype (Then_Expr));
2351 -- Case where then expression is overloaded
2359 Set_Etype (N, Any_Type);
2361 -- Loop through interpretations of Then_Expr
2363 Get_First_Interp (Then_Expr, I, It);
2364 while Present (It.Nam) loop
2366 -- Add possible interpretation of Then_Expr if no Else_Expr, or
2367 -- Else_Expr is present and has a compatible type.
2370 or else Has_Compatible_Type (Else_Expr, It.Typ)
2372 Add_One_Interp (N, It.Typ, It.Typ);
2375 Get_Next_Interp (I, It);
2378 -- If no valid interpretation has been found, then the type of the
2379 -- ELSE expression does not match any interpretation of the THEN
2382 if Etype (N) = Any_Type then
2384 ("type incompatible with that of `THEN` expression",
2390 end Analyze_If_Expression;
2392 ------------------------------------
2393 -- Analyze_Indexed_Component_Form --
2394 ------------------------------------
2396 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
2397 P : constant Node_Id := Prefix (N);
2398 Exprs : constant List_Id := Expressions (N);
2404 procedure Process_Function_Call;
2405 -- Prefix in indexed component form is an overloadable entity, so the
2406 -- node is a function call. Reformat it as such.
2408 procedure Process_Indexed_Component;
2409 -- Prefix in indexed component form is actually an indexed component.
2410 -- This routine processes it, knowing that the prefix is already
2413 procedure Process_Indexed_Component_Or_Slice;
2414 -- An indexed component with a single index may designate a slice if
2415 -- the index is a subtype mark. This routine disambiguates these two
2416 -- cases by resolving the prefix to see if it is a subtype mark.
2418 procedure Process_Overloaded_Indexed_Component;
2419 -- If the prefix of an indexed component is overloaded, the proper
2420 -- interpretation is selected by the index types and the context.
2422 ---------------------------
2423 -- Process_Function_Call --
2424 ---------------------------
2426 procedure Process_Function_Call is
2427 Loc : constant Source_Ptr := Sloc (N);
2431 Change_Node (N, N_Function_Call);
2433 Set_Parameter_Associations (N, Exprs);
2435 -- Analyze actuals prior to analyzing the call itself
2437 Actual := First (Parameter_Associations (N));
2438 while Present (Actual) loop
2440 Check_Parameterless_Call (Actual);
2442 -- Move to next actual. Note that we use Next, not Next_Actual
2443 -- here. The reason for this is a bit subtle. If a function call
2444 -- includes named associations, the parser recognizes the node
2445 -- as a call, and it is analyzed as such. If all associations are
2446 -- positional, the parser builds an indexed_component node, and
2447 -- it is only after analysis of the prefix that the construct
2448 -- is recognized as a call, in which case Process_Function_Call
2449 -- rewrites the node and analyzes the actuals. If the list of
2450 -- actuals is malformed, the parser may leave the node as an
2451 -- indexed component (despite the presence of named associations).
2452 -- The iterator Next_Actual is equivalent to Next if the list is
2453 -- positional, but follows the normalized chain of actuals when
2454 -- named associations are present. In this case normalization has
2455 -- not taken place, and actuals remain unanalyzed, which leads to
2456 -- subsequent crashes or loops if there is an attempt to continue
2457 -- analysis of the program.
2459 -- IF there is a single actual and it is a type name, the node
2460 -- can only be interpreted as a slice of a parameterless call.
2461 -- Rebuild the node as such and analyze.
2463 if No (Next (Actual))
2464 and then Is_Entity_Name (Actual)
2465 and then Is_Type (Entity (Actual))
2466 and then Is_Discrete_Type (Entity (Actual))
2472 New_Occurrence_Of (Entity (Actual), Loc)));
2482 end Process_Function_Call;
2484 -------------------------------
2485 -- Process_Indexed_Component --
2486 -------------------------------
2488 procedure Process_Indexed_Component is
2490 Array_Type : Entity_Id;
2492 Pent : Entity_Id := Empty;
2495 Exp := First (Exprs);
2497 if Is_Overloaded (P) then
2498 Process_Overloaded_Indexed_Component;
2501 Array_Type := Etype (P);
2503 if Is_Entity_Name (P) then
2505 elsif Nkind (P) = N_Selected_Component
2506 and then Is_Entity_Name (Selector_Name (P))
2508 Pent := Entity (Selector_Name (P));
2511 -- Prefix must be appropriate for an array type, taking into
2512 -- account a possible implicit dereference.
2514 if Is_Access_Type (Array_Type) then
2516 (Warn_On_Dereference, "?d?implicit dereference", N);
2517 Array_Type := Process_Implicit_Dereference_Prefix (Pent, P);
2520 if Is_Array_Type (Array_Type) then
2522 -- In order to correctly access First_Index component later,
2523 -- replace string literal subtype by its parent type.
2525 if Ekind (Array_Type) = E_String_Literal_Subtype then
2526 Array_Type := Etype (Array_Type);
2529 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
2531 Set_Etype (N, Any_Type);
2533 if not Has_Compatible_Type (Exp, Entry_Index_Type (Pent)) then
2534 Error_Msg_N ("invalid index type in entry name", N);
2536 elsif Present (Next (Exp)) then
2537 Error_Msg_N ("too many subscripts in entry reference", N);
2540 Set_Etype (N, Etype (P));
2545 elsif Is_Record_Type (Array_Type)
2546 and then Remote_AST_I_Dereference (P)
2550 elsif Try_Container_Indexing (N, P, Exprs) then
2553 elsif Array_Type = Any_Type then
2554 Set_Etype (N, Any_Type);
2556 -- In most cases the analysis of the prefix will have emitted
2557 -- an error already, but if the prefix may be interpreted as a
2558 -- call in prefixed notation, the report is left to the caller.
2559 -- To prevent cascaded errors, report only if no previous ones.
2561 if Serious_Errors_Detected = 0 then
2562 Error_Msg_N ("invalid prefix in indexed component", P);
2564 if Nkind (P) = N_Expanded_Name then
2565 Error_Msg_NE ("\& is not visible", P, Selector_Name (P));
2571 -- Here we definitely have a bad indexing
2574 if Nkind (Parent (N)) = N_Requeue_Statement
2575 and then Present (Pent) and then Ekind (Pent) = E_Entry
2578 ("REQUEUE does not permit parameters", First (Exprs));
2580 elsif Is_Entity_Name (P)
2581 and then Etype (P) = Standard_Void_Type
2583 Error_Msg_NE ("incorrect use of &", P, Entity (P));
2586 Error_Msg_N ("array type required in indexed component", P);
2589 Set_Etype (N, Any_Type);
2593 Index := First_Index (Array_Type);
2594 while Present (Index) and then Present (Exp) loop
2595 if not Has_Compatible_Type (Exp, Etype (Index)) then
2596 Wrong_Type (Exp, Etype (Index));
2597 Set_Etype (N, Any_Type);
2605 Set_Etype (N, Component_Type (Array_Type));
2606 Check_Implicit_Dereference (N, Etype (N));
2608 if Present (Index) then
2610 ("too few subscripts in array reference", First (Exprs));
2612 elsif Present (Exp) then
2613 Error_Msg_N ("too many subscripts in array reference", Exp);
2616 end Process_Indexed_Component;
2618 ----------------------------------------
2619 -- Process_Indexed_Component_Or_Slice --
2620 ----------------------------------------
2622 procedure Process_Indexed_Component_Or_Slice is
2624 Exp := First (Exprs);
2625 while Present (Exp) loop
2626 Analyze_Expression (Exp);
2630 Exp := First (Exprs);
2632 -- If one index is present, and it is a subtype name, then the node
2633 -- denotes a slice (note that the case of an explicit range for a
2634 -- slice was already built as an N_Slice node in the first place,
2635 -- so that case is not handled here).
2637 -- We use a replace rather than a rewrite here because this is one
2638 -- of the cases in which the tree built by the parser is plain wrong.
2641 and then Is_Entity_Name (Exp)
2642 and then Is_Type (Entity (Exp))
2645 Make_Slice (Sloc (N),
2647 Discrete_Range => New_Copy (Exp)));
2650 -- Otherwise (more than one index present, or single index is not
2651 -- a subtype name), then we have the indexed component case.
2654 Process_Indexed_Component;
2656 end Process_Indexed_Component_Or_Slice;
2658 ------------------------------------------
2659 -- Process_Overloaded_Indexed_Component --
2660 ------------------------------------------
2662 procedure Process_Overloaded_Indexed_Component is
2671 Set_Etype (N, Any_Type);
2673 Get_First_Interp (P, I, It);
2674 while Present (It.Nam) loop
2677 if Is_Access_Type (Typ) then
2678 Typ := Designated_Type (Typ);
2680 (Warn_On_Dereference, "?d?implicit dereference", N);
2683 if Is_Array_Type (Typ) then
2685 -- Got a candidate: verify that index types are compatible
2687 Index := First_Index (Typ);
2689 Exp := First (Exprs);
2690 while Present (Index) and then Present (Exp) loop
2691 if Has_Compatible_Type (Exp, Etype (Index)) then
2703 if Found and then No (Index) and then No (Exp) then
2705 CT : constant Entity_Id :=
2706 Base_Type (Component_Type (Typ));
2708 Add_One_Interp (N, CT, CT);
2709 Check_Implicit_Dereference (N, CT);
2713 elsif Try_Container_Indexing (N, P, Exprs) then
2718 Get_Next_Interp (I, It);
2721 if Etype (N) = Any_Type then
2722 Error_Msg_N ("no legal interpretation for indexed component", N);
2723 Set_Is_Overloaded (N, False);
2727 end Process_Overloaded_Indexed_Component;
2729 -- Start of processing for Analyze_Indexed_Component_Form
2732 -- Get name of array, function or type
2736 -- If P is an explicit dereference whose prefix is of a remote access-
2737 -- to-subprogram type, then N has already been rewritten as a subprogram
2738 -- call and analyzed.
2740 if Nkind (N) in N_Subprogram_Call then
2743 -- When the prefix is attribute 'Loop_Entry and the sole expression of
2744 -- the indexed component denotes a loop name, the indexed form is turned
2745 -- into an attribute reference.
2747 elsif Nkind (N) = N_Attribute_Reference
2748 and then Attribute_Name (N) = Name_Loop_Entry
2753 pragma Assert (Nkind (N) = N_Indexed_Component);
2755 P_T := Base_Type (Etype (P));
2757 if Is_Entity_Name (P) and then Present (Entity (P)) then
2760 if Is_Type (U_N) then
2762 -- Reformat node as a type conversion
2764 E := Remove_Head (Exprs);
2766 if Present (First (Exprs)) then
2768 ("argument of type conversion must be single expression", N);
2771 Change_Node (N, N_Type_Conversion);
2772 Set_Subtype_Mark (N, P);
2774 Set_Expression (N, E);
2776 -- After changing the node, call for the specific Analysis
2777 -- routine directly, to avoid a double call to the expander.
2779 Analyze_Type_Conversion (N);
2783 if Is_Overloadable (U_N) then
2784 Process_Function_Call;
2786 elsif Ekind (Etype (P)) = E_Subprogram_Type
2787 or else (Is_Access_Type (Etype (P))
2789 Ekind (Designated_Type (Etype (P))) =
2792 -- Call to access_to-subprogram with possible implicit dereference
2794 Process_Function_Call;
2796 elsif Is_Generic_Subprogram (U_N) then
2798 -- A common beginner's (or C++ templates fan) error
2800 Error_Msg_N ("generic subprogram cannot be called", N);
2801 Set_Etype (N, Any_Type);
2805 Process_Indexed_Component_Or_Slice;
2808 -- If not an entity name, prefix is an expression that may denote
2809 -- an array or an access-to-subprogram.
2812 if Ekind (P_T) = E_Subprogram_Type
2813 or else (Is_Access_Type (P_T)
2815 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
2817 Process_Function_Call;
2819 elsif Nkind (P) = N_Selected_Component
2820 and then Present (Entity (Selector_Name (P)))
2821 and then Is_Overloadable (Entity (Selector_Name (P)))
2823 Process_Function_Call;
2825 -- In ASIS mode within a generic, a prefixed call is analyzed and
2826 -- partially rewritten but the original indexed component has not
2827 -- yet been rewritten as a call. Perform the replacement now.
2829 elsif Nkind (P) = N_Selected_Component
2830 and then Nkind (Parent (P)) = N_Function_Call
2833 Rewrite (N, Parent (P));
2837 -- Indexed component, slice, or a call to a member of a family
2838 -- entry, which will be converted to an entry call later.
2840 Process_Indexed_Component_Or_Slice;
2844 Analyze_Dimension (N);
2845 end Analyze_Indexed_Component_Form;
2847 ------------------------
2848 -- Analyze_Logical_Op --
2849 ------------------------
2851 procedure Analyze_Logical_Op (N : Node_Id) is
2852 L : constant Node_Id := Left_Opnd (N);
2853 R : constant Node_Id := Right_Opnd (N);
2854 Op_Id : Entity_Id := Entity (N);
2857 Set_Etype (N, Any_Type);
2858 Candidate_Type := Empty;
2860 Analyze_Expression (L);
2861 Analyze_Expression (R);
2863 if Present (Op_Id) then
2865 if Ekind (Op_Id) = E_Operator then
2866 Find_Boolean_Types (L, R, Op_Id, N);
2868 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2872 Op_Id := Get_Name_Entity_Id (Chars (N));
2873 while Present (Op_Id) loop
2874 if Ekind (Op_Id) = E_Operator then
2875 Find_Boolean_Types (L, R, Op_Id, N);
2877 Analyze_User_Defined_Binary_Op (N, Op_Id);
2880 Op_Id := Homonym (Op_Id);
2885 Check_Function_Writable_Actuals (N);
2886 end Analyze_Logical_Op;
2888 ---------------------------
2889 -- Analyze_Membership_Op --
2890 ---------------------------
2892 procedure Analyze_Membership_Op (N : Node_Id) is
2893 Loc : constant Source_Ptr := Sloc (N);
2894 L : constant Node_Id := Left_Opnd (N);
2895 R : constant Node_Id := Right_Opnd (N);
2897 Index : Interp_Index;
2899 Found : Boolean := False;
2903 procedure Try_One_Interp (T1 : Entity_Id);
2904 -- Routine to try one proposed interpretation. Note that the context
2905 -- of the operation plays no role in resolving the arguments, so that
2906 -- if there is more than one interpretation of the operands that is
2907 -- compatible with a membership test, the operation is ambiguous.
2909 --------------------
2910 -- Try_One_Interp --
2911 --------------------
2913 procedure Try_One_Interp (T1 : Entity_Id) is
2915 if Has_Compatible_Type (R, T1) then
2917 and then Base_Type (T1) /= Base_Type (T_F)
2919 It := Disambiguate (L, I_F, Index, Any_Type);
2921 if It = No_Interp then
2922 Ambiguous_Operands (N);
2923 Set_Etype (L, Any_Type);
2940 procedure Analyze_Set_Membership;
2941 -- If a set of alternatives is present, analyze each and find the
2942 -- common type to which they must all resolve.
2944 ----------------------------
2945 -- Analyze_Set_Membership --
2946 ----------------------------
2948 procedure Analyze_Set_Membership is
2950 Index : Interp_Index;
2952 Candidate_Interps : Node_Id;
2953 Common_Type : Entity_Id := Empty;
2956 if Comes_From_Source (N) then
2957 Check_Compiler_Unit ("set membership", N);
2961 Candidate_Interps := L;
2963 if not Is_Overloaded (L) then
2964 Common_Type := Etype (L);
2966 Alt := First (Alternatives (N));
2967 while Present (Alt) loop
2970 if not Has_Compatible_Type (Alt, Common_Type) then
2971 Wrong_Type (Alt, Common_Type);
2978 Alt := First (Alternatives (N));
2979 while Present (Alt) loop
2981 if not Is_Overloaded (Alt) then
2982 Common_Type := Etype (Alt);
2985 Get_First_Interp (Alt, Index, It);
2986 while Present (It.Typ) loop
2988 Has_Compatible_Type (Candidate_Interps, It.Typ)
2990 Remove_Interp (Index);
2993 Get_Next_Interp (Index, It);
2996 Get_First_Interp (Alt, Index, It);
2999 Error_Msg_N ("alternative has no legal type", Alt);
3003 -- If alternative is not overloaded, we have a unique type
3006 Set_Etype (Alt, It.Typ);
3008 -- If the alternative is an enumeration literal, use the one
3009 -- for this interpretation.
3011 if Is_Entity_Name (Alt) then
3012 Set_Entity (Alt, It.Nam);
3015 Get_Next_Interp (Index, It);
3018 Set_Is_Overloaded (Alt, False);
3019 Common_Type := Etype (Alt);
3022 Candidate_Interps := Alt;
3029 Set_Etype (N, Standard_Boolean);
3031 if Present (Common_Type) then
3032 Set_Etype (L, Common_Type);
3034 -- The left operand may still be overloaded, to be resolved using
3038 Error_Msg_N ("cannot resolve membership operation", N);
3040 end Analyze_Set_Membership;
3042 -- Start of processing for Analyze_Membership_Op
3045 Analyze_Expression (L);
3048 pragma Assert (Ada_Version >= Ada_2012);
3049 Analyze_Set_Membership;
3050 Check_Function_Writable_Actuals (N);
3054 if Nkind (R) = N_Range
3055 or else (Nkind (R) = N_Attribute_Reference
3056 and then Attribute_Name (R) = Name_Range)
3060 if not Is_Overloaded (L) then
3061 Try_One_Interp (Etype (L));
3064 Get_First_Interp (L, Index, It);
3065 while Present (It.Typ) loop
3066 Try_One_Interp (It.Typ);
3067 Get_Next_Interp (Index, It);
3071 -- If not a range, it can be a subtype mark, or else it is a degenerate
3072 -- membership test with a singleton value, i.e. a test for equality,
3073 -- if the types are compatible.
3078 if Is_Entity_Name (R)
3079 and then Is_Type (Entity (R))
3082 Check_Fully_Declared (Entity (R), R);
3084 elsif Ada_Version >= Ada_2012
3085 and then Has_Compatible_Type (R, Etype (L))
3087 if Nkind (N) = N_In then
3103 -- In all versions of the language, if we reach this point there
3104 -- is a previous error that will be diagnosed below.
3110 -- Compatibility between expression and subtype mark or range is
3111 -- checked during resolution. The result of the operation is Boolean
3114 Set_Etype (N, Standard_Boolean);
3116 if Comes_From_Source (N)
3117 and then Present (Right_Opnd (N))
3118 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
3120 Error_Msg_N ("membership test not applicable to cpp-class types", N);
3123 Check_Function_Writable_Actuals (N);
3124 end Analyze_Membership_Op;
3130 procedure Analyze_Mod (N : Node_Id) is
3132 -- A special warning check, if we have an expression of the form:
3133 -- expr mod 2 * literal
3134 -- where literal is 64 or less, then probably what was meant was
3135 -- expr mod 2 ** literal
3136 -- so issue an appropriate warning.
3138 if Warn_On_Suspicious_Modulus_Value
3139 and then Nkind (Right_Opnd (N)) = N_Integer_Literal
3140 and then Intval (Right_Opnd (N)) = Uint_2
3141 and then Nkind (Parent (N)) = N_Op_Multiply
3142 and then Nkind (Right_Opnd (Parent (N))) = N_Integer_Literal
3143 and then Intval (Right_Opnd (Parent (N))) <= Uint_64
3146 ("suspicious MOD value, was '*'* intended'??M?", Parent (N));
3149 -- Remaining processing is same as for other arithmetic operators
3151 Analyze_Arithmetic_Op (N);
3154 ----------------------
3155 -- Analyze_Negation --
3156 ----------------------
3158 procedure Analyze_Negation (N : Node_Id) is
3159 R : constant Node_Id := Right_Opnd (N);
3160 Op_Id : Entity_Id := Entity (N);
3163 Set_Etype (N, Any_Type);
3164 Candidate_Type := Empty;
3166 Analyze_Expression (R);
3168 if Present (Op_Id) then
3169 if Ekind (Op_Id) = E_Operator then
3170 Find_Negation_Types (R, Op_Id, N);
3172 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3176 Op_Id := Get_Name_Entity_Id (Chars (N));
3177 while Present (Op_Id) loop
3178 if Ekind (Op_Id) = E_Operator then
3179 Find_Negation_Types (R, Op_Id, N);
3181 Analyze_User_Defined_Unary_Op (N, Op_Id);
3184 Op_Id := Homonym (Op_Id);
3189 end Analyze_Negation;
3195 procedure Analyze_Null (N : Node_Id) is
3197 Check_SPARK_05_Restriction ("null is not allowed", N);
3199 Set_Etype (N, Any_Access);
3202 ----------------------
3203 -- Analyze_One_Call --
3204 ----------------------
3206 procedure Analyze_One_Call
3210 Success : out Boolean;
3211 Skip_First : Boolean := False)
3213 Actuals : constant List_Id := Parameter_Associations (N);
3214 Prev_T : constant Entity_Id := Etype (N);
3216 -- Recognize cases of prefixed calls that have been rewritten in
3217 -- various ways. The simplest case is a rewritten selected component,
3218 -- but it can also be an already-examined indexed component, or a
3219 -- prefix that is itself a rewritten prefixed call that is in turn
3220 -- an indexed call (the syntactic ambiguity involving the indexing of
3221 -- a function with defaulted parameters that returns an array).
3222 -- A flag Maybe_Indexed_Call might be useful here ???
3224 Must_Skip : constant Boolean := Skip_First
3225 or else Nkind (Original_Node (N)) = N_Selected_Component
3227 (Nkind (Original_Node (N)) = N_Indexed_Component
3228 and then Nkind (Prefix (Original_Node (N))) =
3229 N_Selected_Component)
3231 (Nkind (Parent (N)) = N_Function_Call
3232 and then Is_Array_Type (Etype (Name (N)))
3233 and then Etype (Original_Node (N)) =
3234 Component_Type (Etype (Name (N)))
3235 and then Nkind (Original_Node (Parent (N))) =
3236 N_Selected_Component);
3238 -- The first formal must be omitted from the match when trying to find
3239 -- a primitive operation that is a possible interpretation, and also
3240 -- after the call has been rewritten, because the corresponding actual
3241 -- is already known to be compatible, and because this may be an
3242 -- indexing of a call with default parameters.
3244 First_Form : Entity_Id;
3247 Is_Indexed : Boolean := False;
3248 Is_Indirect : Boolean := False;
3249 Subp_Type : constant Entity_Id := Etype (Nam);
3252 function Compatible_Types_In_Predicate
3254 T2 : Entity_Id) return Boolean;
3255 -- For an Ada 2012 predicate or invariant, a call may mention an
3256 -- incomplete type, while resolution of the corresponding predicate
3257 -- function may see the full view, as a consequence of the delayed
3258 -- resolution of the corresponding expressions. This may occur in
3259 -- the body of a predicate function, or in a call to such. Anomalies
3260 -- involving private and full views can also happen. In each case,
3261 -- rewrite node or add conversions to remove spurious type errors.
3263 procedure Indicate_Name_And_Type;
3264 -- If candidate interpretation matches, indicate name and type of result
3267 function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
3268 -- There may be a user-defined operator that hides the current
3269 -- interpretation. We must check for this independently of the
3270 -- analysis of the call with the user-defined operation, because
3271 -- the parameter names may be wrong and yet the hiding takes place.
3272 -- This fixes a problem with ACATS test B34014O.
3274 -- When the type Address is a visible integer type, and the DEC
3275 -- system extension is visible, the predefined operator may be
3276 -- hidden as well, by one of the address operations in auxdec.
3277 -- Finally, The abstract operations on address do not hide the
3278 -- predefined operator (this is the purpose of making them abstract).
3280 -----------------------------------
3281 -- Compatible_Types_In_Predicate --
3282 -----------------------------------
3284 function Compatible_Types_In_Predicate
3286 T2 : Entity_Id) return Boolean
3288 function Common_Type (T : Entity_Id) return Entity_Id;
3289 -- Find non-private full view if any, without going to ancestor type
3290 -- (as opposed to Underlying_Type).
3296 function Common_Type (T : Entity_Id) return Entity_Id is
3298 if Is_Private_Type (T) and then Present (Full_View (T)) then
3299 return Base_Type (Full_View (T));
3301 return Base_Type (T);
3305 -- Start of processing for Compatible_Types_In_Predicate
3308 if (Ekind (Current_Scope) = E_Function
3309 and then Is_Predicate_Function (Current_Scope))
3311 (Ekind (Nam) = E_Function
3312 and then Is_Predicate_Function (Nam))
3314 if Is_Incomplete_Type (T1)
3315 and then Present (Full_View (T1))
3316 and then Full_View (T1) = T2
3318 Set_Etype (Formal, Etype (Actual));
3321 elsif Common_Type (T1) = Common_Type (T2) then
3322 Rewrite (Actual, Unchecked_Convert_To (Etype (Formal), Actual));
3332 end Compatible_Types_In_Predicate;
3334 ----------------------------
3335 -- Indicate_Name_And_Type --
3336 ----------------------------
3338 procedure Indicate_Name_And_Type is
3340 Add_One_Interp (N, Nam, Etype (Nam));
3341 Check_Implicit_Dereference (N, Etype (Nam));
3344 -- If the prefix of the call is a name, indicate the entity
3345 -- being called. If it is not a name, it is an expression that
3346 -- denotes an access to subprogram or else an entry or family. In
3347 -- the latter case, the name is a selected component, and the entity
3348 -- being called is noted on the selector.
3350 if not Is_Type (Nam) then
3351 if Is_Entity_Name (Name (N)) then
3352 Set_Entity (Name (N), Nam);
3353 Set_Etype (Name (N), Etype (Nam));
3355 elsif Nkind (Name (N)) = N_Selected_Component then
3356 Set_Entity (Selector_Name (Name (N)), Nam);
3360 if Debug_Flag_E and not Report then
3361 Write_Str (" Overloaded call ");
3362 Write_Int (Int (N));
3363 Write_Str (" compatible with ");
3364 Write_Int (Int (Nam));
3367 end Indicate_Name_And_Type;
3369 ------------------------
3370 -- Operator_Hidden_By --
3371 ------------------------
3373 function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
3374 Act1 : constant Node_Id := First_Actual (N);
3375 Act2 : constant Node_Id := Next_Actual (Act1);
3376 Form1 : constant Entity_Id := First_Formal (Fun);
3377 Form2 : constant Entity_Id := Next_Formal (Form1);
3380 if Ekind (Fun) /= E_Function or else Is_Abstract_Subprogram (Fun) then
3383 elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
3386 elsif Present (Form2) then
3388 or else not Has_Compatible_Type (Act2, Etype (Form2))
3393 elsif Present (Act2) then
3397 -- Now we know that the arity of the operator matches the function,
3398 -- and the function call is a valid interpretation. The function
3399 -- hides the operator if it has the right signature, or if one of
3400 -- its operands is a non-abstract operation on Address when this is
3401 -- a visible integer type.
3403 return Hides_Op (Fun, Nam)
3404 or else Is_Descendant_Of_Address (Etype (Form1))
3407 and then Is_Descendant_Of_Address (Etype (Form2)));
3408 end Operator_Hidden_By;
3410 -- Start of processing for Analyze_One_Call
3415 -- If the subprogram has no formals or if all the formals have defaults,
3416 -- and the return type is an array type, the node may denote an indexing
3417 -- of the result of a parameterless call. In Ada 2005, the subprogram
3418 -- may have one non-defaulted formal, and the call may have been written
3419 -- in prefix notation, so that the rebuilt parameter list has more than
3422 if not Is_Overloadable (Nam)
3423 and then Ekind (Nam) /= E_Subprogram_Type
3424 and then Ekind (Nam) /= E_Entry_Family
3429 -- An indexing requires at least one actual. The name of the call cannot
3430 -- be an implicit indirect call, so it cannot be a generated explicit
3433 if not Is_Empty_List (Actuals)
3435 (Needs_No_Actuals (Nam)
3437 (Needs_One_Actual (Nam)
3438 and then Present (Next_Actual (First (Actuals)))))
3440 if Is_Array_Type (Subp_Type)
3442 (Nkind (Name (N)) /= N_Explicit_Dereference
3443 or else Comes_From_Source (Name (N)))
3445 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
3447 elsif Is_Access_Type (Subp_Type)
3448 and then Is_Array_Type (Designated_Type (Subp_Type))
3452 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
3454 -- The prefix can also be a parameterless function that returns an
3455 -- access to subprogram, in which case this is an indirect call.
3456 -- If this succeeds, an explicit dereference is added later on,
3457 -- in Analyze_Call or Resolve_Call.
3459 elsif Is_Access_Type (Subp_Type)
3460 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
3462 Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
3467 -- If the call has been transformed into a slice, it is of the form
3468 -- F (Subtype) where F is parameterless. The node has been rewritten in
3469 -- Try_Indexed_Call and there is nothing else to do.
3472 and then Nkind (N) = N_Slice
3478 (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
3482 -- If an indirect call is a possible interpretation, indicate
3483 -- success to the caller. This may be an indexing of an explicit
3484 -- dereference of a call that returns an access type (see above).
3488 and then Nkind (Name (N)) = N_Explicit_Dereference
3489 and then Comes_From_Source (Name (N)))
3494 -- Mismatch in number or names of parameters
3496 elsif Debug_Flag_E then
3497 Write_Str (" normalization fails in call ");
3498 Write_Int (Int (N));
3499 Write_Str (" with subprogram ");
3500 Write_Int (Int (Nam));
3504 -- If the context expects a function call, discard any interpretation
3505 -- that is a procedure. If the node is not overloaded, leave as is for
3506 -- better error reporting when type mismatch is found.
3508 elsif Nkind (N) = N_Function_Call
3509 and then Is_Overloaded (Name (N))
3510 and then Ekind (Nam) = E_Procedure
3514 -- Ditto for function calls in a procedure context
3516 elsif Nkind (N) = N_Procedure_Call_Statement
3517 and then Is_Overloaded (Name (N))
3518 and then Etype (Nam) /= Standard_Void_Type
3522 elsif No (Actuals) then
3524 -- If Normalize succeeds, then there are default parameters for
3527 Indicate_Name_And_Type;
3529 elsif Ekind (Nam) = E_Operator then
3530 if Nkind (N) = N_Procedure_Call_Statement then
3534 -- This can occur when the prefix of the call is an operator
3535 -- name or an expanded name whose selector is an operator name.
3537 Analyze_Operator_Call (N, Nam);
3539 if Etype (N) /= Prev_T then
3541 -- Check that operator is not hidden by a function interpretation
3543 if Is_Overloaded (Name (N)) then
3549 Get_First_Interp (Name (N), I, It);
3550 while Present (It.Nam) loop
3551 if Operator_Hidden_By (It.Nam) then
3552 Set_Etype (N, Prev_T);
3556 Get_Next_Interp (I, It);
3561 -- If operator matches formals, record its name on the call.
3562 -- If the operator is overloaded, Resolve will select the
3563 -- correct one from the list of interpretations. The call
3564 -- node itself carries the first candidate.
3566 Set_Entity (Name (N), Nam);
3569 elsif Report and then Etype (N) = Any_Type then
3570 Error_Msg_N ("incompatible arguments for operator", N);
3574 -- Normalize_Actuals has chained the named associations in the
3575 -- correct order of the formals.
3577 Actual := First_Actual (N);
3578 Formal := First_Formal (Nam);
3579 First_Form := Formal;
3581 -- If we are analyzing a call rewritten from object notation, skip
3582 -- first actual, which may be rewritten later as an explicit
3586 Next_Actual (Actual);
3587 Next_Formal (Formal);
3590 while Present (Actual) and then Present (Formal) loop
3591 if Nkind (Parent (Actual)) /= N_Parameter_Association
3592 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
3594 -- The actual can be compatible with the formal, but we must
3595 -- also check that the context is not an address type that is
3596 -- visibly an integer type. In this case the use of literals is
3597 -- illegal, except in the body of descendants of system, where
3598 -- arithmetic operations on address are of course used.
3600 if Has_Compatible_Type (Actual, Etype (Formal))
3602 (Etype (Actual) /= Universal_Integer
3603 or else not Is_Descendant_Of_Address (Etype (Formal))
3604 or else In_Predefined_Unit (N))
3606 Next_Actual (Actual);
3607 Next_Formal (Formal);
3609 -- In Allow_Integer_Address mode, we allow an actual integer to
3610 -- match a formal address type and vice versa. We only do this
3611 -- if we are certain that an error will otherwise be issued
3613 elsif Address_Integer_Convert_OK
3614 (Etype (Actual), Etype (Formal))
3615 and then (Report and not Is_Indexed and not Is_Indirect)
3617 -- Handle this case by introducing an unchecked conversion
3620 Unchecked_Convert_To (Etype (Formal),
3621 Relocate_Node (Actual)));
3622 Analyze_And_Resolve (Actual, Etype (Formal));
3623 Next_Actual (Actual);
3624 Next_Formal (Formal);
3626 -- Under relaxed RM semantics silently replace occurrences of
3627 -- null by System.Address_Null. We only do this if we know that
3628 -- an error will otherwise be issued.
3630 elsif Null_To_Null_Address_Convert_OK (Actual, Etype (Formal))
3631 and then (Report and not Is_Indexed and not Is_Indirect)
3633 Replace_Null_By_Null_Address (Actual);
3634 Analyze_And_Resolve (Actual, Etype (Formal));
3635 Next_Actual (Actual);
3636 Next_Formal (Formal);
3638 elsif Compatible_Types_In_Predicate
3639 (Etype (Formal), Etype (Actual))
3641 Next_Actual (Actual);
3642 Next_Formal (Formal);
3644 -- Handle failed type check
3647 if Debug_Flag_E then
3648 Write_Str (" type checking fails in call ");
3649 Write_Int (Int (N));
3650 Write_Str (" with formal ");
3651 Write_Int (Int (Formal));
3652 Write_Str (" in subprogram ");
3653 Write_Int (Int (Nam));
3657 -- Comment needed on the following test???
3659 if Report and not Is_Indexed and not Is_Indirect then
3661 -- Ada 2005 (AI-251): Complete the error notification
3662 -- to help new Ada 2005 users.
3664 if Is_Class_Wide_Type (Etype (Formal))
3665 and then Is_Interface (Etype (Etype (Formal)))
3666 and then not Interface_Present_In_Ancestor
3667 (Typ => Etype (Actual),
3668 Iface => Etype (Etype (Formal)))
3671 ("(Ada 2005) does not implement interface }",
3672 Actual, Etype (Etype (Formal)));
3675 Wrong_Type (Actual, Etype (Formal));
3677 if Nkind (Actual) = N_Op_Eq
3678 and then Nkind (Left_Opnd (Actual)) = N_Identifier
3680 Formal := First_Formal (Nam);
3681 while Present (Formal) loop
3682 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
3683 Error_Msg_N -- CODEFIX
3684 ("possible misspelling of `='>`!", Actual);
3688 Next_Formal (Formal);
3692 if All_Errors_Mode then
3693 Error_Msg_Sloc := Sloc (Nam);
3695 if Etype (Formal) = Any_Type then
3697 ("there is no legal actual parameter", Actual);
3700 if Is_Overloadable (Nam)
3701 and then Present (Alias (Nam))
3702 and then not Comes_From_Source (Nam)
3705 ("\\ =='> in call to inherited operation & #!",
3708 elsif Ekind (Nam) = E_Subprogram_Type then
3710 Access_To_Subprogram_Typ :
3711 constant Entity_Id :=
3713 (Associated_Node_For_Itype (Nam));
3716 ("\\ =='> in call to dereference of &#!",
3717 Actual, Access_To_Subprogram_Typ);
3722 ("\\ =='> in call to &#!", Actual, Nam);
3732 -- Normalize_Actuals has verified that a default value exists
3733 -- for this formal. Current actual names a subsequent formal.
3735 Next_Formal (Formal);
3739 -- Due to our current model of controlled type expansion we may
3740 -- have resolved a user call to a non-visible controlled primitive
3741 -- since these inherited subprograms may be generated in the current
3742 -- scope. This is a side effect of the need for the expander to be
3743 -- able to resolve internally generated calls.
3745 -- Specifically, the issue appears when predefined controlled
3746 -- operations get called on a type extension whose parent is a
3747 -- private extension completed with a controlled extension - see
3751 -- type Par_Typ is tagged private;
3753 -- type Par_Typ is new Controlled with null record;
3756 -- procedure Main is
3757 -- type Ext_Typ is new Par_Typ with null record;
3760 -- Finalize (Obj); -- Will improperly resolve
3763 -- To avoid breaking privacy, Is_Hidden gets set elsewhere on such
3764 -- primitives, but we still need to verify that Nam is indeed a
3765 -- controlled subprogram. So, we do that here and issue the
3766 -- appropriate error.
3769 and then not In_Instance
3770 and then not Comes_From_Source (Nam)
3771 and then Comes_From_Source (N)
3773 -- Verify Nam is a controlled primitive
3775 and then Nam_In (Chars (Nam), Name_Adjust,
3778 and then Ekind (Nam) = E_Procedure
3779 and then Is_Controlled (Etype (First_Form))
3780 and then No (Next_Formal (First_Form))
3782 Error_Msg_Node_2 := Etype (First_Form);
3783 Error_Msg_NE ("call to non-visible controlled primitive & on type"
3787 -- On exit, all actuals match
3789 Indicate_Name_And_Type;
3791 end Analyze_One_Call;
3793 ---------------------------
3794 -- Analyze_Operator_Call --
3795 ---------------------------
3797 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
3798 Op_Name : constant Name_Id := Chars (Op_Id);
3799 Act1 : constant Node_Id := First_Actual (N);
3800 Act2 : constant Node_Id := Next_Actual (Act1);
3803 -- Binary operator case
3805 if Present (Act2) then
3807 -- If more than two operands, then not binary operator after all
3809 if Present (Next_Actual (Act2)) then
3813 -- Otherwise action depends on operator
3824 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
3830 Find_Boolean_Types (Act1, Act2, Op_Id, N);
3837 Find_Comparison_Types (Act1, Act2, Op_Id, N);
3842 Find_Equality_Types (Act1, Act2, Op_Id, N);
3844 when Name_Op_Concat =>
3845 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
3847 -- Is this when others, or should it be an abort???
3853 -- Unary operator case
3861 Find_Unary_Types (Act1, Op_Id, N);
3864 Find_Negation_Types (Act1, Op_Id, N);
3866 -- Is this when others correct, or should it be an abort???
3872 end Analyze_Operator_Call;
3874 -------------------------------------------
3875 -- Analyze_Overloaded_Selected_Component --
3876 -------------------------------------------
3878 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
3879 Nam : constant Node_Id := Prefix (N);
3880 Sel : constant Node_Id := Selector_Name (N);
3887 Set_Etype (Sel, Any_Type);
3889 Get_First_Interp (Nam, I, It);
3890 while Present (It.Typ) loop
3891 if Is_Access_Type (It.Typ) then
3892 T := Designated_Type (It.Typ);
3893 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
3898 -- Locate the component. For a private prefix the selector can denote
3901 if Is_Record_Type (T) or else Is_Private_Type (T) then
3903 -- If the prefix is a class-wide type, the visible components are
3904 -- those of the base type.
3906 if Is_Class_Wide_Type (T) then
3910 Comp := First_Entity (T);
3911 while Present (Comp) loop
3912 if Chars (Comp) = Chars (Sel)
3913 and then Is_Visible_Component (Comp, Sel)
3916 -- AI05-105: if the context is an object renaming with
3917 -- an anonymous access type, the expected type of the
3918 -- object must be anonymous. This is a name resolution rule.
3920 if Nkind (Parent (N)) /= N_Object_Renaming_Declaration
3921 or else No (Access_Definition (Parent (N)))
3922 or else Ekind (Etype (Comp)) = E_Anonymous_Access_Type
3924 Ekind (Etype (Comp)) = E_Anonymous_Access_Subprogram_Type
3926 Set_Entity (Sel, Comp);
3927 Set_Etype (Sel, Etype (Comp));
3928 Add_One_Interp (N, Etype (Comp), Etype (Comp));
3929 Check_Implicit_Dereference (N, Etype (Comp));
3931 -- This also specifies a candidate to resolve the name.
3932 -- Further overloading will be resolved from context.
3933 -- The selector name itself does not carry overloading
3936 Set_Etype (Nam, It.Typ);
3939 -- Named access type in the context of a renaming
3940 -- declaration with an access definition. Remove
3941 -- inapplicable candidate.
3950 elsif Is_Concurrent_Type (T) then
3951 Comp := First_Entity (T);
3952 while Present (Comp)
3953 and then Comp /= First_Private_Entity (T)
3955 if Chars (Comp) = Chars (Sel) then
3956 if Is_Overloadable (Comp) then
3957 Add_One_Interp (Sel, Comp, Etype (Comp));
3959 Set_Entity_With_Checks (Sel, Comp);
3960 Generate_Reference (Comp, Sel);
3963 Set_Etype (Sel, Etype (Comp));
3964 Set_Etype (N, Etype (Comp));
3965 Set_Etype (Nam, It.Typ);
3967 -- For access type case, introduce explicit dereference for
3968 -- more uniform treatment of entry calls. Do this only once
3969 -- if several interpretations yield an access type.
3971 if Is_Access_Type (Etype (Nam))
3972 and then Nkind (Nam) /= N_Explicit_Dereference
3974 Insert_Explicit_Dereference (Nam);
3976 (Warn_On_Dereference, "?d?implicit dereference", N);
3983 Set_Is_Overloaded (N, Is_Overloaded (Sel));
3986 Get_Next_Interp (I, It);
3989 if Etype (N) = Any_Type
3990 and then not Try_Object_Operation (N)
3992 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
3993 Set_Entity (Sel, Any_Id);
3994 Set_Etype (Sel, Any_Type);
3996 end Analyze_Overloaded_Selected_Component;
3998 ----------------------------------
3999 -- Analyze_Qualified_Expression --
4000 ----------------------------------
4002 procedure Analyze_Qualified_Expression (N : Node_Id) is
4003 Mark : constant Entity_Id := Subtype_Mark (N);
4004 Expr : constant Node_Id := Expression (N);
4010 Analyze_Expression (Expr);
4012 Set_Etype (N, Any_Type);
4016 if Nkind_In (Enclosing_Declaration (N), N_Formal_Type_Declaration,
4017 N_Full_Type_Declaration,
4018 N_Incomplete_Type_Declaration,
4019 N_Protected_Type_Declaration,
4020 N_Private_Extension_Declaration,
4021 N_Private_Type_Declaration,
4022 N_Subtype_Declaration,
4023 N_Task_Type_Declaration)
4024 and then T = Defining_Identifier (Enclosing_Declaration (N))
4026 Error_Msg_N ("current instance not allowed", Mark);
4032 if T = Any_Type then
4036 Check_Fully_Declared (T, N);
4038 -- If expected type is class-wide, check for exact match before
4039 -- expansion, because if the expression is a dispatching call it
4040 -- may be rewritten as explicit dereference with class-wide result.
4041 -- If expression is overloaded, retain only interpretations that
4042 -- will yield exact matches.
4044 if Is_Class_Wide_Type (T) then
4045 if not Is_Overloaded (Expr) then
4046 if Base_Type (Etype (Expr)) /= Base_Type (T)
4047 and then Etype (Expr) /= Raise_Type
4049 if Nkind (Expr) = N_Aggregate then
4050 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
4052 Wrong_Type (Expr, T);
4057 Get_First_Interp (Expr, I, It);
4059 while Present (It.Nam) loop
4060 if Base_Type (It.Typ) /= Base_Type (T) then
4064 Get_Next_Interp (I, It);
4070 end Analyze_Qualified_Expression;
4072 -----------------------------------
4073 -- Analyze_Quantified_Expression --
4074 -----------------------------------
4076 procedure Analyze_Quantified_Expression (N : Node_Id) is
4077 function Is_Empty_Range (Typ : Entity_Id) return Boolean;
4078 -- If the iterator is part of a quantified expression, and the range is
4079 -- known to be statically empty, emit a warning and replace expression
4080 -- with its static value. Returns True if the replacement occurs.
4082 function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean;
4083 -- Determine whether if expression If_Expr lacks an else part or if it
4084 -- has one, it evaluates to True.
4086 --------------------
4087 -- Is_Empty_Range --
4088 --------------------
4090 function Is_Empty_Range (Typ : Entity_Id) return Boolean is
4091 Loc : constant Source_Ptr := Sloc (N);
4094 if Is_Array_Type (Typ)
4095 and then Compile_Time_Known_Bounds (Typ)
4097 (Expr_Value (Type_Low_Bound (Etype (First_Index (Typ)))) >
4098 Expr_Value (Type_High_Bound (Etype (First_Index (Typ)))))
4100 Preanalyze_And_Resolve (Condition (N), Standard_Boolean);
4102 if All_Present (N) then
4104 ("??quantified expression with ALL "
4105 & "over a null range has value True", N);
4106 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
4110 ("??quantified expression with SOME "
4111 & "over a null range has value False", N);
4112 Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
4123 -----------------------------
4124 -- No_Else_Or_Trivial_True --
4125 -----------------------------
4127 function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean is
4128 Else_Expr : constant Node_Id :=
4129 Next (Next (First (Expressions (If_Expr))));
4133 or else (Compile_Time_Known_Value (Else_Expr)
4134 and then Is_True (Expr_Value (Else_Expr)));
4135 end No_Else_Or_Trivial_True;
4139 Cond : constant Node_Id := Condition (N);
4140 Loop_Id : Entity_Id;
4141 QE_Scop : Entity_Id;
4143 -- Start of processing for Analyze_Quantified_Expression
4146 Check_SPARK_05_Restriction ("quantified expression is not allowed", N);
4148 -- Create a scope to emulate the loop-like behavior of the quantified
4149 -- expression. The scope is needed to provide proper visibility of the
4152 QE_Scop := New_Internal_Entity (E_Loop, Current_Scope, Sloc (N), 'L');
4153 Set_Etype (QE_Scop, Standard_Void_Type);
4154 Set_Scope (QE_Scop, Current_Scope);
4155 Set_Parent (QE_Scop, N);
4157 Push_Scope (QE_Scop);
4159 -- All constituents are preanalyzed and resolved to avoid untimely
4160 -- generation of various temporaries and types. Full analysis and
4161 -- expansion is carried out when the quantified expression is
4162 -- transformed into an expression with actions.
4164 if Present (Iterator_Specification (N)) then
4165 Preanalyze (Iterator_Specification (N));
4167 -- Do not proceed with the analysis when the range of iteration is
4168 -- empty. The appropriate error is issued by Is_Empty_Range.
4170 if Is_Entity_Name (Name (Iterator_Specification (N)))
4171 and then Is_Empty_Range (Etype (Name (Iterator_Specification (N))))
4176 else pragma Assert (Present (Loop_Parameter_Specification (N)));
4178 Loop_Par : constant Node_Id := Loop_Parameter_Specification (N);
4181 Preanalyze (Loop_Par);
4183 if Nkind (Discrete_Subtype_Definition (Loop_Par)) = N_Function_Call
4184 and then Parent (Loop_Par) /= N
4186 -- The parser cannot distinguish between a loop specification
4187 -- and an iterator specification. If after preanalysis the
4188 -- proper form has been recognized, rewrite the expression to
4189 -- reflect the right kind. This is needed for proper ASIS
4190 -- navigation. If expansion is enabled, the transformation is
4191 -- performed when the expression is rewritten as a loop.
4193 Set_Iterator_Specification (N,
4194 New_Copy_Tree (Iterator_Specification (Parent (Loop_Par))));
4196 Set_Defining_Identifier (Iterator_Specification (N),
4197 Relocate_Node (Defining_Identifier (Loop_Par)));
4198 Set_Name (Iterator_Specification (N),
4199 Relocate_Node (Discrete_Subtype_Definition (Loop_Par)));
4200 Set_Comes_From_Source (Iterator_Specification (N),
4201 Comes_From_Source (Loop_Parameter_Specification (N)));
4202 Set_Loop_Parameter_Specification (N, Empty);
4207 Preanalyze_And_Resolve (Cond, Standard_Boolean);
4210 Set_Etype (N, Standard_Boolean);
4212 -- Verify that the loop variable is used within the condition of the
4213 -- quantified expression.
4215 if Present (Iterator_Specification (N)) then
4216 Loop_Id := Defining_Identifier (Iterator_Specification (N));
4218 Loop_Id := Defining_Identifier (Loop_Parameter_Specification (N));
4221 if Warn_On_Suspicious_Contract
4222 and then not Referenced (Loop_Id, Cond)
4224 -- Generating C, this check causes spurious warnings on inlined
4225 -- postconditions; we can safely disable it because this check
4226 -- was previously performed when analyzing the internally built
4227 -- postconditions procedure.
4229 if Modify_Tree_For_C and then In_Inlined_Body then
4232 Error_Msg_N ("?T?unused variable &", Loop_Id);
4236 -- Diagnose a possible misuse of the SOME existential quantifier. When
4237 -- we have a quantified expression of the form:
4239 -- for some X => (if P then Q [else True])
4241 -- any value for X that makes P False results in the if expression being
4242 -- trivially True, and so also results in the quantified expression
4243 -- being trivially True.
4245 if Warn_On_Suspicious_Contract
4246 and then not All_Present (N)
4247 and then Nkind (Cond) = N_If_Expression
4248 and then No_Else_Or_Trivial_True (Cond)
4250 Error_Msg_N ("?T?suspicious expression", N);
4251 Error_Msg_N ("\\did you mean (for all X ='> (if P then Q))", N);
4252 Error_Msg_N ("\\or (for some X ='> P and then Q) instead'?", N);
4254 end Analyze_Quantified_Expression;
4260 procedure Analyze_Range (N : Node_Id) is
4261 L : constant Node_Id := Low_Bound (N);
4262 H : constant Node_Id := High_Bound (N);
4263 I1, I2 : Interp_Index;
4266 procedure Check_Common_Type (T1, T2 : Entity_Id);
4267 -- Verify the compatibility of two types, and choose the
4268 -- non universal one if the other is universal.
4270 procedure Check_High_Bound (T : Entity_Id);
4271 -- Test one interpretation of the low bound against all those
4272 -- of the high bound.
4274 procedure Check_Universal_Expression (N : Node_Id);
4275 -- In Ada 83, reject bounds of a universal range that are not literals
4278 -----------------------
4279 -- Check_Common_Type --
4280 -----------------------
4282 procedure Check_Common_Type (T1, T2 : Entity_Id) is
4284 if Covers (T1 => T1, T2 => T2)
4286 Covers (T1 => T2, T2 => T1)
4288 if T1 = Universal_Integer
4289 or else T1 = Universal_Real
4290 or else T1 = Any_Character
4292 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
4295 Add_One_Interp (N, T1, T1);
4298 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
4301 end Check_Common_Type;
4303 ----------------------
4304 -- Check_High_Bound --
4305 ----------------------
4307 procedure Check_High_Bound (T : Entity_Id) is
4309 if not Is_Overloaded (H) then
4310 Check_Common_Type (T, Etype (H));
4312 Get_First_Interp (H, I2, It2);
4313 while Present (It2.Typ) loop
4314 Check_Common_Type (T, It2.Typ);
4315 Get_Next_Interp (I2, It2);
4318 end Check_High_Bound;
4320 --------------------------------
4321 -- Check_Universal_Expression --
4322 --------------------------------
4324 procedure Check_Universal_Expression (N : Node_Id) is
4326 if Etype (N) = Universal_Integer
4327 and then Nkind (N) /= N_Integer_Literal
4328 and then not Is_Entity_Name (N)
4329 and then Nkind (N) /= N_Attribute_Reference
4331 Error_Msg_N ("illegal bound in discrete range", N);
4333 end Check_Universal_Expression;
4335 -- Start of processing for Analyze_Range
4338 Set_Etype (N, Any_Type);
4339 Analyze_Expression (L);
4340 Analyze_Expression (H);
4342 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
4346 if not Is_Overloaded (L) then
4347 Check_High_Bound (Etype (L));
4349 Get_First_Interp (L, I1, It1);
4350 while Present (It1.Typ) loop
4351 Check_High_Bound (It1.Typ);
4352 Get_Next_Interp (I1, It1);
4356 -- If result is Any_Type, then we did not find a compatible pair
4358 if Etype (N) = Any_Type then
4359 Error_Msg_N ("incompatible types in range ", N);
4363 if Ada_Version = Ada_83
4365 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
4366 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
4368 Check_Universal_Expression (L);
4369 Check_Universal_Expression (H);
4372 Check_Function_Writable_Actuals (N);
4375 -----------------------
4376 -- Analyze_Reference --
4377 -----------------------
4379 procedure Analyze_Reference (N : Node_Id) is
4380 P : constant Node_Id := Prefix (N);
4383 Acc_Type : Entity_Id;
4388 -- An interesting error check, if we take the 'Ref of an object for
4389 -- which a pragma Atomic or Volatile has been given, and the type of the
4390 -- object is not Atomic or Volatile, then we are in trouble. The problem
4391 -- is that no trace of the atomic/volatile status will remain for the
4392 -- backend to respect when it deals with the resulting pointer, since
4393 -- the pointer type will not be marked atomic (it is a pointer to the
4394 -- base type of the object).
4396 -- It is not clear if that can ever occur, but in case it does, we will
4397 -- generate an error message. Not clear if this message can ever be
4398 -- generated, and pretty clear that it represents a bug if it is, still
4399 -- seems worth checking, except in CodePeer mode where we do not really
4400 -- care and don't want to bother the user.
4404 if Is_Entity_Name (P)
4405 and then Is_Object_Reference (P)
4406 and then not CodePeer_Mode
4411 if (Has_Atomic_Components (E)
4412 and then not Has_Atomic_Components (T))
4414 (Has_Volatile_Components (E)
4415 and then not Has_Volatile_Components (T))
4416 or else (Is_Atomic (E) and then not Is_Atomic (T))
4417 or else (Is_Volatile (E) and then not Is_Volatile (T))
4419 Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
4423 -- Carry on with normal processing
4425 Acc_Type := Create_Itype (E_Allocator_Type, N);
4426 Set_Etype (Acc_Type, Acc_Type);
4427 Set_Directly_Designated_Type (Acc_Type, Etype (P));
4428 Set_Etype (N, Acc_Type);
4429 end Analyze_Reference;
4431 --------------------------------
4432 -- Analyze_Selected_Component --
4433 --------------------------------
4435 -- Prefix is a record type or a task or protected type. In the latter case,
4436 -- the selector must denote a visible entry.
4438 procedure Analyze_Selected_Component (N : Node_Id) is
4439 Name : constant Node_Id := Prefix (N);
4440 Sel : constant Node_Id := Selector_Name (N);
4443 Has_Candidate : Boolean := False;
4444 Hidden_Comp : Entity_Id;
4446 Is_Private_Op : Boolean;
4448 Pent : Entity_Id := Empty;
4449 Prefix_Type : Entity_Id;
4451 Type_To_Use : Entity_Id;
4452 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
4453 -- a class-wide type, we use its root type, whose components are
4454 -- present in the class-wide type.
4456 Is_Single_Concurrent_Object : Boolean;
4457 -- Set True if the prefix is a single task or a single protected object
4459 procedure Find_Component_In_Instance (Rec : Entity_Id);
4460 -- In an instance, a component of a private extension may not be visible
4461 -- while it was visible in the generic. Search candidate scope for a
4462 -- component with the proper identifier. This is only done if all other
4463 -- searches have failed. If a match is found, the Etype of both N and
4464 -- Sel are set from this component, and the entity of Sel is set to
4465 -- reference this component. If no match is found, Entity (Sel) remains
4466 -- unset. For a derived type that is an actual of the instance, the
4467 -- desired component may be found in any ancestor.
4469 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
4470 -- It is known that the parent of N denotes a subprogram call. Comp
4471 -- is an overloadable component of the concurrent type of the prefix.
4472 -- Determine whether all formals of the parent of N and Comp are mode
4473 -- conformant. If the parent node is not analyzed yet it may be an
4474 -- indexed component rather than a function call.
4476 function Has_Dereference (Nod : Node_Id) return Boolean;
4477 -- Check whether prefix includes a dereference at any level.
4479 --------------------------------
4480 -- Find_Component_In_Instance --
4481 --------------------------------
4483 procedure Find_Component_In_Instance (Rec : Entity_Id) is
4489 while Present (Typ) loop
4490 Comp := First_Component (Typ);
4491 while Present (Comp) loop
4492 if Chars (Comp) = Chars (Sel) then
4493 Set_Entity_With_Checks (Sel, Comp);
4494 Set_Etype (Sel, Etype (Comp));
4495 Set_Etype (N, Etype (Comp));
4499 Next_Component (Comp);
4502 -- If not found, the component may be declared in the parent
4503 -- type or its full view, if any.
4505 if Is_Derived_Type (Typ) then
4508 if Is_Private_Type (Typ) then
4509 Typ := Full_View (Typ);
4517 -- If we fall through, no match, so no changes made
4520 end Find_Component_In_Instance;
4522 ------------------------------
4523 -- Has_Mode_Conformant_Spec --
4524 ------------------------------
4526 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
4527 Comp_Param : Entity_Id;
4529 Param_Typ : Entity_Id;
4532 Comp_Param := First_Formal (Comp);
4534 if Nkind (Parent (N)) = N_Indexed_Component then
4535 Param := First (Expressions (Parent (N)));
4537 Param := First (Parameter_Associations (Parent (N)));
4540 while Present (Comp_Param)
4541 and then Present (Param)
4543 Param_Typ := Find_Parameter_Type (Param);
4545 if Present (Param_Typ)
4547 not Conforming_Types
4548 (Etype (Comp_Param), Param_Typ, Mode_Conformant)
4553 Next_Formal (Comp_Param);
4557 -- One of the specs has additional formals; there is no match, unless
4558 -- this may be an indexing of a parameterless call.
4560 -- Note that when expansion is disabled, the corresponding record
4561 -- type of synchronized types is not constructed, so that there is
4562 -- no point is attempting an interpretation as a prefixed call, as
4563 -- this is bound to fail because the primitive operations will not
4564 -- be properly located.
4566 if Present (Comp_Param) or else Present (Param) then
4567 if Needs_No_Actuals (Comp)
4568 and then Is_Array_Type (Etype (Comp))
4569 and then not Expander_Active
4578 end Has_Mode_Conformant_Spec;
4580 ---------------------
4581 -- Has_Dereference --
4582 ---------------------
4584 function Has_Dereference (Nod : Node_Id) return Boolean is
4586 if Nkind (Nod) = N_Explicit_Dereference then
4589 -- When expansion is disabled an explicit dereference may not have
4590 -- been inserted, but if this is an access type the indirection makes
4593 elsif Is_Access_Type (Etype (Nod)) then
4596 elsif Nkind_In (Nod, N_Indexed_Component, N_Selected_Component) then
4597 return Has_Dereference (Prefix (Nod));
4602 end Has_Dereference;
4604 -- Start of processing for Analyze_Selected_Component
4607 Set_Etype (N, Any_Type);
4609 if Is_Overloaded (Name) then
4610 Analyze_Overloaded_Selected_Component (N);
4613 elsif Etype (Name) = Any_Type then
4614 Set_Entity (Sel, Any_Id);
4615 Set_Etype (Sel, Any_Type);
4619 Prefix_Type := Etype (Name);
4622 if Is_Access_Type (Prefix_Type) then
4624 -- A RACW object can never be used as prefix of a selected component
4625 -- since that means it is dereferenced without being a controlling
4626 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
4627 -- reporting an error, we must check whether this is actually a
4628 -- dispatching call in prefix form.
4630 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
4631 and then Comes_From_Source (N)
4633 if Try_Object_Operation (N) then
4637 ("invalid dereference of a remote access-to-class-wide value",
4641 -- Normal case of selected component applied to access type
4644 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
4646 if Is_Entity_Name (Name) then
4647 Pent := Entity (Name);
4648 elsif Nkind (Name) = N_Selected_Component
4649 and then Is_Entity_Name (Selector_Name (Name))
4651 Pent := Entity (Selector_Name (Name));
4654 Prefix_Type := Process_Implicit_Dereference_Prefix (Pent, Name);
4657 -- If we have an explicit dereference of a remote access-to-class-wide
4658 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
4659 -- have to check for the case of a prefix that is a controlling operand
4660 -- of a prefixed dispatching call, as the dereference is legal in that
4661 -- case. Normally this condition is checked in Validate_Remote_Access_
4662 -- To_Class_Wide_Type, but we have to defer the checking for selected
4663 -- component prefixes because of the prefixed dispatching call case.
4664 -- Note that implicit dereferences are checked for this just above.
4666 elsif Nkind (Name) = N_Explicit_Dereference
4667 and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
4668 and then Comes_From_Source (N)
4670 if Try_Object_Operation (N) then
4674 ("invalid dereference of a remote access-to-class-wide value",
4679 -- (Ada 2005): if the prefix is the limited view of a type, and
4680 -- the context already includes the full view, use the full view
4681 -- in what follows, either to retrieve a component of to find
4682 -- a primitive operation. If the prefix is an explicit dereference,
4683 -- set the type of the prefix to reflect this transformation.
4684 -- If the nonlimited view is itself an incomplete type, get the
4685 -- full view if available.
4687 if From_Limited_With (Prefix_Type)
4688 and then Has_Non_Limited_View (Prefix_Type)
4690 Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
4692 if Nkind (N) = N_Explicit_Dereference then
4693 Set_Etype (Prefix (N), Prefix_Type);
4697 if Ekind (Prefix_Type) = E_Private_Subtype then
4698 Prefix_Type := Base_Type (Prefix_Type);
4701 Type_To_Use := Prefix_Type;
4703 -- For class-wide types, use the entity list of the root type. This
4704 -- indirection is specially important for private extensions because
4705 -- only the root type get switched (not the class-wide type).
4707 if Is_Class_Wide_Type (Prefix_Type) then
4708 Type_To_Use := Root_Type (Prefix_Type);
4711 -- If the prefix is a single concurrent object, use its name in error
4712 -- messages, rather than that of its anonymous type.
4714 Is_Single_Concurrent_Object :=
4715 Is_Concurrent_Type (Prefix_Type)
4716 and then Is_Internal_Name (Chars (Prefix_Type))
4717 and then not Is_Derived_Type (Prefix_Type)
4718 and then Is_Entity_Name (Name);
4720 Comp := First_Entity (Type_To_Use);
4722 -- If the selector has an original discriminant, the node appears in
4723 -- an instance. Replace the discriminant with the corresponding one
4724 -- in the current discriminated type. For nested generics, this must
4725 -- be done transitively, so note the new original discriminant.
4727 if Nkind (Sel) = N_Identifier
4728 and then In_Instance
4729 and then Present (Original_Discriminant (Sel))
4731 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
4733 -- Mark entity before rewriting, for completeness and because
4734 -- subsequent semantic checks might examine the original node.
4736 Set_Entity (Sel, Comp);
4737 Rewrite (Selector_Name (N), New_Occurrence_Of (Comp, Sloc (N)));
4738 Set_Original_Discriminant (Selector_Name (N), Comp);
4739 Set_Etype (N, Etype (Comp));
4740 Check_Implicit_Dereference (N, Etype (Comp));
4742 if Is_Access_Type (Etype (Name)) then
4743 Insert_Explicit_Dereference (Name);
4744 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
4747 elsif Is_Record_Type (Prefix_Type) then
4749 -- Find component with given name. In an instance, if the node is
4750 -- known as a prefixed call, do not examine components whose
4751 -- visibility may be accidental.
4753 while Present (Comp) and then not Is_Prefixed_Call (N) loop
4754 if Chars (Comp) = Chars (Sel)
4755 and then Is_Visible_Component (Comp, N)
4757 Set_Entity_With_Checks (Sel, Comp);
4758 Set_Etype (Sel, Etype (Comp));
4760 if Ekind (Comp) = E_Discriminant then
4761 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
4763 ("cannot reference discriminant of unchecked union",
4767 if Is_Generic_Type (Prefix_Type)
4769 Is_Generic_Type (Root_Type (Prefix_Type))
4771 Set_Original_Discriminant (Sel, Comp);
4775 -- Resolve the prefix early otherwise it is not possible to
4776 -- build the actual subtype of the component: it may need
4777 -- to duplicate this prefix and duplication is only allowed
4778 -- on fully resolved expressions.
4782 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
4783 -- subtypes in a package specification.
4786 -- limited with Pkg;
4788 -- type Acc_Inc is access Pkg.T;
4790 -- N : Natural := X.all.Comp; -- ERROR, limited view
4791 -- end Pkg; -- Comp is not visible
4793 if Nkind (Name) = N_Explicit_Dereference
4794 and then From_Limited_With (Etype (Prefix (Name)))
4795 and then not Is_Potentially_Use_Visible (Etype (Name))
4796 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
4797 N_Package_Specification
4800 ("premature usage of incomplete}", Prefix (Name),
4801 Etype (Prefix (Name)));
4804 -- We never need an actual subtype for the case of a selection
4805 -- for a indexed component of a non-packed array, since in
4806 -- this case gigi generates all the checks and can find the
4807 -- necessary bounds information.
4809 -- We also do not need an actual subtype for the case of a
4810 -- first, last, length, or range attribute applied to a
4811 -- non-packed array, since gigi can again get the bounds in
4812 -- these cases (gigi cannot handle the packed case, since it
4813 -- has the bounds of the packed array type, not the original
4814 -- bounds of the type). However, if the prefix is itself a
4815 -- selected component, as in a.b.c (i), gigi may regard a.b.c
4816 -- as a dynamic-sized temporary, so we do generate an actual
4817 -- subtype for this case.
4819 Parent_N := Parent (N);
4821 if not Is_Packed (Etype (Comp))
4823 ((Nkind (Parent_N) = N_Indexed_Component
4824 and then Nkind (Name) /= N_Selected_Component)
4826 (Nkind (Parent_N) = N_Attribute_Reference
4828 Nam_In (Attribute_Name (Parent_N), Name_First,
4833 Set_Etype (N, Etype (Comp));
4835 -- If full analysis is not enabled, we do not generate an
4836 -- actual subtype, because in the absence of expansion
4837 -- reference to a formal of a protected type, for example,
4838 -- will not be properly transformed, and will lead to
4839 -- out-of-scope references in gigi.
4841 -- In all other cases, we currently build an actual subtype.
4842 -- It seems likely that many of these cases can be avoided,
4843 -- but right now, the front end makes direct references to the
4844 -- bounds (e.g. in generating a length check), and if we do
4845 -- not make an actual subtype, we end up getting a direct
4846 -- reference to a discriminant, which will not do.
4848 elsif Full_Analysis then
4850 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
4851 Insert_Action (N, Act_Decl);
4853 if No (Act_Decl) then
4854 Set_Etype (N, Etype (Comp));
4857 -- If discriminants were present in the component
4858 -- declaration, they have been replaced by the
4859 -- actual values in the prefix object.
4862 Subt : constant Entity_Id :=
4863 Defining_Identifier (Act_Decl);
4865 Set_Etype (Subt, Base_Type (Etype (Comp)));
4866 Set_Etype (N, Subt);
4870 -- If Full_Analysis not enabled, just set the Etype
4873 Set_Etype (N, Etype (Comp));
4876 Check_Implicit_Dereference (N, Etype (N));
4880 -- If the prefix is a private extension, check only the visible
4881 -- components of the partial view. This must include the tag,
4882 -- which can appear in expanded code in a tag check.
4884 if Ekind (Type_To_Use) = E_Record_Type_With_Private
4885 and then Chars (Selector_Name (N)) /= Name_uTag
4887 exit when Comp = Last_Entity (Type_To_Use);
4893 -- Ada 2005 (AI-252): The selected component can be interpreted as
4894 -- a prefixed view of a subprogram. Depending on the context, this is
4895 -- either a name that can appear in a renaming declaration, or part
4896 -- of an enclosing call given in prefix form.
4898 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
4899 -- selected component should resolve to a name.
4901 if Ada_Version >= Ada_2005
4902 and then Is_Tagged_Type (Prefix_Type)
4903 and then not Is_Concurrent_Type (Prefix_Type)
4905 if Nkind (Parent (N)) = N_Generic_Association
4906 or else Nkind (Parent (N)) = N_Requeue_Statement
4907 or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
4909 if Find_Primitive_Operation (N) then
4913 elsif Try_Object_Operation (N) then
4917 -- If the transformation fails, it will be necessary to redo the
4918 -- analysis with all errors enabled, to indicate candidate
4919 -- interpretations and reasons for each failure ???
4923 elsif Is_Private_Type (Prefix_Type) then
4925 -- Allow access only to discriminants of the type. If the type has
4926 -- no full view, gigi uses the parent type for the components, so we
4927 -- do the same here.
4929 if No (Full_View (Prefix_Type)) then
4930 Type_To_Use := Root_Type (Base_Type (Prefix_Type));
4931 Comp := First_Entity (Type_To_Use);
4934 while Present (Comp) loop
4935 if Chars (Comp) = Chars (Sel) then
4936 if Ekind (Comp) = E_Discriminant then
4937 Set_Entity_With_Checks (Sel, Comp);
4938 Generate_Reference (Comp, Sel);
4940 Set_Etype (Sel, Etype (Comp));
4941 Set_Etype (N, Etype (Comp));
4942 Check_Implicit_Dereference (N, Etype (N));
4944 if Is_Generic_Type (Prefix_Type)
4945 or else Is_Generic_Type (Root_Type (Prefix_Type))
4947 Set_Original_Discriminant (Sel, Comp);
4950 -- Before declaring an error, check whether this is tagged
4951 -- private type and a call to a primitive operation.
4953 elsif Ada_Version >= Ada_2005
4954 and then Is_Tagged_Type (Prefix_Type)
4955 and then Try_Object_Operation (N)
4960 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4961 Error_Msg_NE ("invisible selector& for }", N, Sel);
4962 Set_Entity (Sel, Any_Id);
4963 Set_Etype (N, Any_Type);
4972 elsif Is_Concurrent_Type (Prefix_Type) then
4974 -- Find visible operation with given name. For a protected type,
4975 -- the possible candidates are discriminants, entries or protected
4976 -- subprograms. For a task type, the set can only include entries or
4977 -- discriminants if the task type is not an enclosing scope. If it
4978 -- is an enclosing scope (e.g. in an inner task) then all entities
4979 -- are visible, but the prefix must denote the enclosing scope, i.e.
4980 -- can only be a direct name or an expanded name.
4982 Set_Etype (Sel, Any_Type);
4983 Hidden_Comp := Empty;
4984 In_Scope := In_Open_Scopes (Prefix_Type);
4985 Is_Private_Op := False;
4987 while Present (Comp) loop
4989 -- Do not examine private operations of the type if not within
4992 if Chars (Comp) = Chars (Sel) then
4993 if Is_Overloadable (Comp)
4995 or else Comp /= First_Private_Entity (Type_To_Use))
4997 Add_One_Interp (Sel, Comp, Etype (Comp));
4998 if Comp = First_Private_Entity (Type_To_Use) then
4999 Is_Private_Op := True;
5002 -- If the prefix is tagged, the correct interpretation may
5003 -- lie in the primitive or class-wide operations of the
5004 -- type. Perform a simple conformance check to determine
5005 -- whether Try_Object_Operation should be invoked even if
5006 -- a visible entity is found.
5008 if Is_Tagged_Type (Prefix_Type)
5009 and then Nkind_In (Parent (N), N_Function_Call,
5010 N_Indexed_Component,
5011 N_Procedure_Call_Statement)
5012 and then Has_Mode_Conformant_Spec (Comp)
5014 Has_Candidate := True;
5017 -- Note: a selected component may not denote a component of a
5018 -- protected type (4.1.3(7)).
5020 elsif Ekind_In (Comp, E_Discriminant, E_Entry_Family)
5022 and then not Is_Protected_Type (Prefix_Type)
5023 and then Is_Entity_Name (Name))
5025 Set_Entity_With_Checks (Sel, Comp);
5026 Generate_Reference (Comp, Sel);
5028 -- The selector is not overloadable, so we have a candidate
5031 Has_Candidate := True;
5034 if Ekind (Comp) = E_Component then
5035 Hidden_Comp := Comp;
5041 Set_Etype (Sel, Etype (Comp));
5042 Set_Etype (N, Etype (Comp));
5044 if Ekind (Comp) = E_Discriminant then
5045 Set_Original_Discriminant (Sel, Comp);
5048 -- For access type case, introduce explicit dereference for
5049 -- more uniform treatment of entry calls.
5051 if Is_Access_Type (Etype (Name)) then
5052 Insert_Explicit_Dereference (Name);
5054 (Warn_On_Dereference, "?d?implicit dereference", N);
5059 if Comp = First_Private_Entity (Type_To_Use) then
5060 if Etype (Sel) /= Any_Type then
5062 -- If the first private entity's name matches, then treat
5063 -- it as a private op: needed for the error check for
5064 -- illegal selection of private entities further below.
5066 if Chars (Comp) = Chars (Sel) then
5067 Is_Private_Op := True;
5070 -- We have a candidate, so exit the loop
5075 -- Indicate that subsequent operations are private,
5076 -- for better error reporting.
5078 Is_Private_Op := True;
5082 -- Do not examine private operations if not within scope of
5083 -- the synchronized type.
5085 exit when not In_Scope
5087 Comp = First_Private_Entity (Base_Type (Prefix_Type));
5091 -- If the scope is a current instance, the prefix cannot be an
5092 -- expression of the same type, unless the selector designates a
5093 -- public operation (otherwise that would represent an attempt to
5094 -- reach an internal entity of another synchronized object).
5096 -- This is legal if prefix is an access to such type and there is
5097 -- a dereference, or is a component with a dereferenced prefix.
5098 -- It is also legal if the prefix is a component of a task type,
5099 -- and the selector is one of the task operations.
5102 and then not Is_Entity_Name (Name)
5103 and then not Has_Dereference (Name)
5105 if Is_Task_Type (Prefix_Type)
5106 and then Present (Entity (Sel))
5107 and then Ekind_In (Entity (Sel), E_Entry, E_Entry_Family)
5111 elsif Is_Protected_Type (Prefix_Type)
5112 and then Is_Overloadable (Entity (Sel))
5113 and then not Is_Private_Op
5119 ("invalid reference to internal operation of some object of "
5120 & "type &", N, Type_To_Use);
5121 Set_Entity (Sel, Any_Id);
5122 Set_Etype (Sel, Any_Type);
5126 -- Another special case: the prefix may denote an object of the type
5127 -- (but not a type) in which case this is an external call and the
5128 -- operation must be public.
5131 and then Is_Object_Reference (Original_Node (Prefix (N)))
5132 and then Comes_From_Source (N)
5133 and then Is_Private_Op
5135 if Present (Hidden_Comp) then
5137 ("invalid reference to private component of object of type "
5138 & "&", N, Type_To_Use);
5142 ("invalid reference to private operation of some object of "
5143 & "type &", N, Type_To_Use);
5146 Set_Entity (Sel, Any_Id);
5147 Set_Etype (Sel, Any_Type);
5151 -- If there is no visible entity with the given name or none of the
5152 -- visible entities are plausible interpretations, check whether
5153 -- there is some other primitive operation with that name.
5155 if Ada_Version >= Ada_2005 and then Is_Tagged_Type (Prefix_Type) then
5156 if (Etype (N) = Any_Type
5157 or else not Has_Candidate)
5158 and then Try_Object_Operation (N)
5162 -- If the context is not syntactically a procedure call, it
5163 -- may be a call to a primitive function declared outside of
5164 -- the synchronized type.
5166 -- If the context is a procedure call, there might still be
5167 -- an overloading between an entry and a primitive procedure
5168 -- declared outside of the synchronized type, called in prefix
5169 -- notation. This is harder to disambiguate because in one case
5170 -- the controlling formal is implicit ???
5172 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
5173 and then Nkind (Parent (N)) /= N_Indexed_Component
5174 and then Try_Object_Operation (N)
5179 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
5180 -- entry or procedure of a tagged concurrent type we must check
5181 -- if there are class-wide subprograms covering the primitive. If
5182 -- true then Try_Object_Operation reports the error.
5185 and then Is_Concurrent_Type (Prefix_Type)
5186 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
5188 -- Duplicate the call. This is required to avoid problems with
5189 -- the tree transformations performed by Try_Object_Operation.
5190 -- Set properly the parent of the copied call, because it is
5191 -- about to be reanalyzed.
5194 Par : constant Node_Id := New_Copy_Tree (Parent (N));
5197 Set_Parent (Par, Parent (Parent (N)));
5199 if Try_Object_Operation
5200 (Sinfo.Name (Par), CW_Test_Only => True)
5208 if Etype (N) = Any_Type and then Is_Protected_Type (Prefix_Type) then
5210 -- Case of a prefix of a protected type: selector might denote
5211 -- an invisible private component.
5213 Comp := First_Private_Entity (Base_Type (Prefix_Type));
5214 while Present (Comp) and then Chars (Comp) /= Chars (Sel) loop
5218 if Present (Comp) then
5219 if Is_Single_Concurrent_Object then
5220 Error_Msg_Node_2 := Entity (Name);
5221 Error_Msg_NE ("invisible selector& for &", N, Sel);
5224 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
5225 Error_Msg_NE ("invisible selector& for }", N, Sel);
5231 Set_Is_Overloaded (N, Is_Overloaded (Sel));
5236 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
5239 -- If N still has no type, the component is not defined in the prefix
5241 if Etype (N) = Any_Type then
5243 if Is_Single_Concurrent_Object then
5244 Error_Msg_Node_2 := Entity (Name);
5245 Error_Msg_NE ("no selector& for&", N, Sel);
5247 Check_Misspelled_Selector (Type_To_Use, Sel);
5249 -- If this is a derived formal type, the parent may have different
5250 -- visibility at this point. Try for an inherited component before
5251 -- reporting an error.
5253 elsif Is_Generic_Type (Prefix_Type)
5254 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
5255 and then Prefix_Type /= Etype (Prefix_Type)
5256 and then Is_Record_Type (Etype (Prefix_Type))
5258 Set_Etype (Prefix (N), Etype (Prefix_Type));
5259 Analyze_Selected_Component (N);
5262 -- Similarly, if this is the actual for a formal derived type, or
5263 -- a derived type thereof, the component inherited from the generic
5264 -- parent may not be visible in the actual, but the selected
5265 -- component is legal. Climb up the derivation chain of the generic
5266 -- parent type until we find the proper ancestor type.
5268 elsif In_Instance and then Is_Tagged_Type (Prefix_Type) then
5270 Par : Entity_Id := Prefix_Type;
5272 -- Climb up derivation chain to generic actual subtype
5274 while not Is_Generic_Actual_Type (Par) loop
5275 if Ekind (Par) = E_Record_Type then
5276 Par := Parent_Subtype (Par);
5279 exit when Par = Etype (Par);
5284 if Present (Par) and then Is_Generic_Actual_Type (Par) then
5286 -- Now look for component in ancestor types
5288 Par := Generic_Parent_Type (Declaration_Node (Par));
5290 Find_Component_In_Instance (Par);
5291 exit when Present (Entity (Sel))
5292 or else Par = Etype (Par);
5296 -- Another special case: the type is an extension of a private
5297 -- type T, is an actual in an instance, and we are in the body
5298 -- of the instance, so the generic body had a full view of the
5299 -- type declaration for T or of some ancestor that defines the
5300 -- component in question.
5302 elsif Is_Derived_Type (Type_To_Use)
5303 and then Used_As_Generic_Actual (Type_To_Use)
5304 and then In_Instance_Body
5306 Find_Component_In_Instance (Parent_Subtype (Type_To_Use));
5308 -- In ASIS mode the generic parent type may be absent. Examine
5309 -- the parent type directly for a component that may have been
5310 -- visible in a parent generic unit.
5312 elsif Is_Derived_Type (Prefix_Type) then
5313 Par := Etype (Prefix_Type);
5314 Find_Component_In_Instance (Par);
5318 -- The search above must have eventually succeeded, since the
5319 -- selected component was legal in the generic.
5321 if No (Entity (Sel)) then
5322 raise Program_Error;
5327 -- Component not found, specialize error message when appropriate
5330 if Ekind (Prefix_Type) = E_Record_Subtype then
5332 -- Check whether this is a component of the base type which
5333 -- is absent from a statically constrained subtype. This will
5334 -- raise constraint error at run time, but is not a compile-
5335 -- time error. When the selector is illegal for base type as
5336 -- well fall through and generate a compilation error anyway.
5338 Comp := First_Component (Base_Type (Prefix_Type));
5339 while Present (Comp) loop
5340 if Chars (Comp) = Chars (Sel)
5341 and then Is_Visible_Component (Comp, Sel)
5343 Set_Entity_With_Checks (Sel, Comp);
5344 Generate_Reference (Comp, Sel);
5345 Set_Etype (Sel, Etype (Comp));
5346 Set_Etype (N, Etype (Comp));
5348 -- Emit appropriate message. The node will be replaced
5349 -- by an appropriate raise statement.
5351 -- Note that in SPARK mode, as with all calls to apply a
5352 -- compile time constraint error, this will be made into
5353 -- an error to simplify the processing of the formal
5354 -- verification backend.
5356 Apply_Compile_Time_Constraint_Error
5357 (N, "component not present in }??",
5358 CE_Discriminant_Check_Failed,
5359 Ent => Prefix_Type, Rep => False);
5361 Set_Raises_Constraint_Error (N);
5365 Next_Component (Comp);
5370 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
5371 Error_Msg_NE ("no selector& for}", N, Sel);
5373 -- Add information in the case of an incomplete prefix
5375 if Is_Incomplete_Type (Type_To_Use) then
5377 Inc : constant Entity_Id := First_Subtype (Type_To_Use);
5380 if From_Limited_With (Scope (Type_To_Use)) then
5382 ("\limited view of& has no components", N, Inc);
5386 ("\premature usage of incomplete type&", N, Inc);
5388 if Nkind (Parent (Inc)) =
5389 N_Incomplete_Type_Declaration
5391 -- Record location of premature use in entity so that
5392 -- a continuation message is generated when the
5393 -- completion is seen.
5395 Set_Premature_Use (Parent (Inc), N);
5401 Check_Misspelled_Selector (Type_To_Use, Sel);
5404 Set_Entity (Sel, Any_Id);
5405 Set_Etype (Sel, Any_Type);
5407 end Analyze_Selected_Component;
5409 ---------------------------
5410 -- Analyze_Short_Circuit --
5411 ---------------------------
5413 procedure Analyze_Short_Circuit (N : Node_Id) is
5414 L : constant Node_Id := Left_Opnd (N);
5415 R : constant Node_Id := Right_Opnd (N);
5420 Analyze_Expression (L);
5421 Analyze_Expression (R);
5422 Set_Etype (N, Any_Type);
5424 if not Is_Overloaded (L) then
5425 if Root_Type (Etype (L)) = Standard_Boolean
5426 and then Has_Compatible_Type (R, Etype (L))
5428 Add_One_Interp (N, Etype (L), Etype (L));
5432 Get_First_Interp (L, Ind, It);
5433 while Present (It.Typ) loop
5434 if Root_Type (It.Typ) = Standard_Boolean
5435 and then Has_Compatible_Type (R, It.Typ)
5437 Add_One_Interp (N, It.Typ, It.Typ);
5440 Get_Next_Interp (Ind, It);
5444 -- Here we have failed to find an interpretation. Clearly we know that
5445 -- it is not the case that both operands can have an interpretation of
5446 -- Boolean, but this is by far the most likely intended interpretation.
5447 -- So we simply resolve both operands as Booleans, and at least one of
5448 -- these resolutions will generate an error message, and we do not need
5449 -- to give another error message on the short circuit operation itself.
5451 if Etype (N) = Any_Type then
5452 Resolve (L, Standard_Boolean);
5453 Resolve (R, Standard_Boolean);
5454 Set_Etype (N, Standard_Boolean);
5456 end Analyze_Short_Circuit;
5462 procedure Analyze_Slice (N : Node_Id) is
5463 D : constant Node_Id := Discrete_Range (N);
5464 P : constant Node_Id := Prefix (N);
5465 Array_Type : Entity_Id;
5466 Index_Type : Entity_Id;
5468 procedure Analyze_Overloaded_Slice;
5469 -- If the prefix is overloaded, select those interpretations that
5470 -- yield a one-dimensional array type.
5472 ------------------------------
5473 -- Analyze_Overloaded_Slice --
5474 ------------------------------
5476 procedure Analyze_Overloaded_Slice is
5482 Set_Etype (N, Any_Type);
5484 Get_First_Interp (P, I, It);
5485 while Present (It.Nam) loop
5488 if Is_Access_Type (Typ) then
5489 Typ := Designated_Type (Typ);
5491 (Warn_On_Dereference, "?d?implicit dereference", N);
5494 if Is_Array_Type (Typ)
5495 and then Number_Dimensions (Typ) = 1
5496 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
5498 Add_One_Interp (N, Typ, Typ);
5501 Get_Next_Interp (I, It);
5504 if Etype (N) = Any_Type then
5505 Error_Msg_N ("expect array type in prefix of slice", N);
5507 end Analyze_Overloaded_Slice;
5509 -- Start of processing for Analyze_Slice
5512 if Comes_From_Source (N) then
5513 Check_SPARK_05_Restriction ("slice is not allowed", N);
5519 if Is_Overloaded (P) then
5520 Analyze_Overloaded_Slice;
5523 Array_Type := Etype (P);
5524 Set_Etype (N, Any_Type);
5526 if Is_Access_Type (Array_Type) then
5527 Array_Type := Designated_Type (Array_Type);
5528 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
5531 if not Is_Array_Type (Array_Type) then
5532 Wrong_Type (P, Any_Array);
5534 elsif Number_Dimensions (Array_Type) > 1 then
5536 ("type is not one-dimensional array in slice prefix", N);
5539 if Ekind (Array_Type) = E_String_Literal_Subtype then
5540 Index_Type := Etype (String_Literal_Low_Bound (Array_Type));
5542 Index_Type := Etype (First_Index (Array_Type));
5545 if not Has_Compatible_Type (D, Index_Type) then
5546 Wrong_Type (D, Index_Type);
5548 Set_Etype (N, Array_Type);
5554 -----------------------------
5555 -- Analyze_Type_Conversion --
5556 -----------------------------
5558 procedure Analyze_Type_Conversion (N : Node_Id) is
5559 Expr : constant Node_Id := Expression (N);
5563 -- If Conversion_OK is set, then the Etype is already set, and the only
5564 -- processing required is to analyze the expression. This is used to
5565 -- construct certain "illegal" conversions which are not allowed by Ada
5566 -- semantics, but can be handled by Gigi, see Sinfo for further details.
5568 if Conversion_OK (N) then
5573 -- Otherwise full type analysis is required, as well as some semantic
5574 -- checks to make sure the argument of the conversion is appropriate.
5576 Find_Type (Subtype_Mark (N));
5577 Typ := Entity (Subtype_Mark (N));
5579 Check_Fully_Declared (Typ, N);
5580 Analyze_Expression (Expr);
5581 Validate_Remote_Type_Type_Conversion (N);
5583 -- Only remaining step is validity checks on the argument. These
5584 -- are skipped if the conversion does not come from the source.
5586 if not Comes_From_Source (N) then
5589 -- If there was an error in a generic unit, no need to replicate the
5590 -- error message. Conversely, constant-folding in the generic may
5591 -- transform the argument of a conversion into a string literal, which
5592 -- is legal. Therefore the following tests are not performed in an
5593 -- instance. The same applies to an inlined body.
5595 elsif In_Instance or In_Inlined_Body then
5598 elsif Nkind (Expr) = N_Null then
5599 Error_Msg_N ("argument of conversion cannot be null", N);
5600 Error_Msg_N ("\use qualified expression instead", N);
5601 Set_Etype (N, Any_Type);
5603 elsif Nkind (Expr) = N_Aggregate then
5604 Error_Msg_N ("argument of conversion cannot be aggregate", N);
5605 Error_Msg_N ("\use qualified expression instead", N);
5607 elsif Nkind (Expr) = N_Allocator then
5608 Error_Msg_N ("argument of conversion cannot be an allocator", N);
5609 Error_Msg_N ("\use qualified expression instead", N);
5611 elsif Nkind (Expr) = N_String_Literal then
5612 Error_Msg_N ("argument of conversion cannot be string literal", N);
5613 Error_Msg_N ("\use qualified expression instead", N);
5615 elsif Nkind (Expr) = N_Character_Literal then
5616 if Ada_Version = Ada_83 then
5617 Resolve (Expr, Typ);
5619 Error_Msg_N ("argument of conversion cannot be character literal",
5621 Error_Msg_N ("\use qualified expression instead", N);
5624 elsif Nkind (Expr) = N_Attribute_Reference
5625 and then Nam_In (Attribute_Name (Expr), Name_Access,
5626 Name_Unchecked_Access,
5627 Name_Unrestricted_Access)
5629 Error_Msg_N ("argument of conversion cannot be access", N);
5630 Error_Msg_N ("\use qualified expression instead", N);
5633 -- A formal parameter of a specific tagged type whose related subprogram
5634 -- is subject to pragma Extensions_Visible with value "False" cannot
5635 -- appear in a class-wide conversion (SPARK RM 6.1.7(3)). Do not check
5636 -- internally generated expressions.
5638 if Is_Class_Wide_Type (Typ)
5639 and then Comes_From_Source (Expr)
5640 and then Is_EVF_Expression (Expr)
5643 ("formal parameter cannot be converted to class-wide type when "
5644 & "Extensions_Visible is False", Expr);
5646 end Analyze_Type_Conversion;
5648 ----------------------
5649 -- Analyze_Unary_Op --
5650 ----------------------
5652 procedure Analyze_Unary_Op (N : Node_Id) is
5653 R : constant Node_Id := Right_Opnd (N);
5654 Op_Id : Entity_Id := Entity (N);
5657 Set_Etype (N, Any_Type);
5658 Candidate_Type := Empty;
5660 Analyze_Expression (R);
5662 if Present (Op_Id) then
5663 if Ekind (Op_Id) = E_Operator then
5664 Find_Unary_Types (R, Op_Id, N);
5666 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5670 Op_Id := Get_Name_Entity_Id (Chars (N));
5671 while Present (Op_Id) loop
5672 if Ekind (Op_Id) = E_Operator then
5673 if No (Next_Entity (First_Entity (Op_Id))) then
5674 Find_Unary_Types (R, Op_Id, N);
5677 elsif Is_Overloadable (Op_Id) then
5678 Analyze_User_Defined_Unary_Op (N, Op_Id);
5681 Op_Id := Homonym (Op_Id);
5686 end Analyze_Unary_Op;
5688 ----------------------------------
5689 -- Analyze_Unchecked_Expression --
5690 ----------------------------------
5692 procedure Analyze_Unchecked_Expression (N : Node_Id) is
5694 Analyze (Expression (N), Suppress => All_Checks);
5695 Set_Etype (N, Etype (Expression (N)));
5696 Save_Interps (Expression (N), N);
5697 end Analyze_Unchecked_Expression;
5699 ---------------------------------------
5700 -- Analyze_Unchecked_Type_Conversion --
5701 ---------------------------------------
5703 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
5705 Find_Type (Subtype_Mark (N));
5706 Analyze_Expression (Expression (N));
5707 Set_Etype (N, Entity (Subtype_Mark (N)));
5708 end Analyze_Unchecked_Type_Conversion;
5710 ------------------------------------
5711 -- Analyze_User_Defined_Binary_Op --
5712 ------------------------------------
5714 procedure Analyze_User_Defined_Binary_Op
5719 -- Only do analysis if the operator Comes_From_Source, since otherwise
5720 -- the operator was generated by the expander, and all such operators
5721 -- always refer to the operators in package Standard.
5723 if Comes_From_Source (N) then
5725 F1 : constant Entity_Id := First_Formal (Op_Id);
5726 F2 : constant Entity_Id := Next_Formal (F1);
5729 -- Verify that Op_Id is a visible binary function. Note that since
5730 -- we know Op_Id is overloaded, potentially use visible means use
5731 -- visible for sure (RM 9.4(11)).
5733 if Ekind (Op_Id) = E_Function
5734 and then Present (F2)
5735 and then (Is_Immediately_Visible (Op_Id)
5736 or else Is_Potentially_Use_Visible (Op_Id))
5737 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
5738 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
5740 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5742 -- If the left operand is overloaded, indicate that the current
5743 -- type is a viable candidate. This is redundant in most cases,
5744 -- but for equality and comparison operators where the context
5745 -- does not impose a type on the operands, setting the proper
5746 -- type is necessary to avoid subsequent ambiguities during
5747 -- resolution, when both user-defined and predefined operators
5748 -- may be candidates.
5750 if Is_Overloaded (Left_Opnd (N)) then
5751 Set_Etype (Left_Opnd (N), Etype (F1));
5754 if Debug_Flag_E then
5755 Write_Str ("user defined operator ");
5756 Write_Name (Chars (Op_Id));
5757 Write_Str (" on node ");
5758 Write_Int (Int (N));
5764 end Analyze_User_Defined_Binary_Op;
5766 -----------------------------------
5767 -- Analyze_User_Defined_Unary_Op --
5768 -----------------------------------
5770 procedure Analyze_User_Defined_Unary_Op
5775 -- Only do analysis if the operator Comes_From_Source, since otherwise
5776 -- the operator was generated by the expander, and all such operators
5777 -- always refer to the operators in package Standard.
5779 if Comes_From_Source (N) then
5781 F : constant Entity_Id := First_Formal (Op_Id);
5784 -- Verify that Op_Id is a visible unary function. Note that since
5785 -- we know Op_Id is overloaded, potentially use visible means use
5786 -- visible for sure (RM 9.4(11)).
5788 if Ekind (Op_Id) = E_Function
5789 and then No (Next_Formal (F))
5790 and then (Is_Immediately_Visible (Op_Id)
5791 or else Is_Potentially_Use_Visible (Op_Id))
5792 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
5794 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5798 end Analyze_User_Defined_Unary_Op;
5800 ---------------------------
5801 -- Check_Arithmetic_Pair --
5802 ---------------------------
5804 procedure Check_Arithmetic_Pair
5805 (T1, T2 : Entity_Id;
5809 Op_Name : constant Name_Id := Chars (Op_Id);
5811 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
5812 -- Check whether the fixed-point type Typ has a user-defined operator
5813 -- (multiplication or division) that should hide the corresponding
5814 -- predefined operator. Used to implement Ada 2005 AI-264, to make
5815 -- such operators more visible and therefore useful.
5817 -- If the name of the operation is an expanded name with prefix
5818 -- Standard, the predefined universal fixed operator is available,
5819 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
5821 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
5822 -- Get specific type (i.e. non-universal type if there is one)
5828 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
5829 Bas : constant Entity_Id := Base_Type (Typ);
5835 -- If the universal_fixed operation is given explicitly the rule
5836 -- concerning primitive operations of the type do not apply.
5838 if Nkind (N) = N_Function_Call
5839 and then Nkind (Name (N)) = N_Expanded_Name
5840 and then Entity (Prefix (Name (N))) = Standard_Standard
5845 -- The operation is treated as primitive if it is declared in the
5846 -- same scope as the type, and therefore on the same entity chain.
5848 Ent := Next_Entity (Typ);
5849 while Present (Ent) loop
5850 if Chars (Ent) = Chars (Op) then
5851 F1 := First_Formal (Ent);
5852 F2 := Next_Formal (F1);
5854 -- The operation counts as primitive if either operand or
5855 -- result are of the given base type, and both operands are
5856 -- fixed point types.
5858 if (Base_Type (Etype (F1)) = Bas
5859 and then Is_Fixed_Point_Type (Etype (F2)))
5862 (Base_Type (Etype (F2)) = Bas
5863 and then Is_Fixed_Point_Type (Etype (F1)))
5866 (Base_Type (Etype (Ent)) = Bas
5867 and then Is_Fixed_Point_Type (Etype (F1))
5868 and then Is_Fixed_Point_Type (Etype (F2)))
5884 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
5886 if T1 = Universal_Integer or else T1 = Universal_Real then
5887 return Base_Type (T2);
5889 return Base_Type (T1);
5893 -- Start of processing for Check_Arithmetic_Pair
5896 if Nam_In (Op_Name, Name_Op_Add, Name_Op_Subtract) then
5897 if Is_Numeric_Type (T1)
5898 and then Is_Numeric_Type (T2)
5899 and then (Covers (T1 => T1, T2 => T2)
5901 Covers (T1 => T2, T2 => T1))
5903 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5906 elsif Nam_In (Op_Name, Name_Op_Multiply, Name_Op_Divide) then
5907 if Is_Fixed_Point_Type (T1)
5908 and then (Is_Fixed_Point_Type (T2) or else T2 = Universal_Real)
5910 -- Add one interpretation with universal fixed result
5912 if not Has_Fixed_Op (T1, Op_Id)
5913 or else Nkind (Parent (N)) = N_Type_Conversion
5915 Add_One_Interp (N, Op_Id, Universal_Fixed);
5918 elsif Is_Fixed_Point_Type (T2)
5919 and then T1 = Universal_Real
5921 (not Has_Fixed_Op (T1, Op_Id)
5922 or else Nkind (Parent (N)) = N_Type_Conversion)
5924 Add_One_Interp (N, Op_Id, Universal_Fixed);
5926 elsif Is_Numeric_Type (T1)
5927 and then Is_Numeric_Type (T2)
5928 and then (Covers (T1 => T1, T2 => T2)
5930 Covers (T1 => T2, T2 => T1))
5932 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5934 elsif Is_Fixed_Point_Type (T1)
5935 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5936 or else T2 = Universal_Integer)
5938 Add_One_Interp (N, Op_Id, T1);
5940 elsif T2 = Universal_Real
5941 and then Base_Type (T1) = Base_Type (Standard_Integer)
5942 and then Op_Name = Name_Op_Multiply
5944 Add_One_Interp (N, Op_Id, Any_Fixed);
5946 elsif T1 = Universal_Real
5947 and then Base_Type (T2) = Base_Type (Standard_Integer)
5949 Add_One_Interp (N, Op_Id, Any_Fixed);
5951 elsif Is_Fixed_Point_Type (T2)
5952 and then (Base_Type (T1) = Base_Type (Standard_Integer)
5953 or else T1 = Universal_Integer)
5954 and then Op_Name = Name_Op_Multiply
5956 Add_One_Interp (N, Op_Id, T2);
5958 elsif T1 = Universal_Real and then T2 = Universal_Integer then
5959 Add_One_Interp (N, Op_Id, T1);
5961 elsif T2 = Universal_Real
5962 and then T1 = Universal_Integer
5963 and then Op_Name = Name_Op_Multiply
5965 Add_One_Interp (N, Op_Id, T2);
5968 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
5970 if Is_Integer_Type (T1)
5971 and then (Covers (T1 => T1, T2 => T2)
5973 Covers (T1 => T2, T2 => T1))
5975 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5978 elsif Op_Name = Name_Op_Expon then
5979 if Is_Numeric_Type (T1)
5980 and then not Is_Fixed_Point_Type (T1)
5981 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5982 or else T2 = Universal_Integer)
5984 Add_One_Interp (N, Op_Id, Base_Type (T1));
5987 else pragma Assert (Nkind (N) in N_Op_Shift);
5989 -- If not one of the predefined operators, the node may be one
5990 -- of the intrinsic functions. Its kind is always specific, and
5991 -- we can use it directly, rather than the name of the operation.
5993 if Is_Integer_Type (T1)
5994 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5995 or else T2 = Universal_Integer)
5997 Add_One_Interp (N, Op_Id, Base_Type (T1));
6000 end Check_Arithmetic_Pair;
6002 -------------------------------
6003 -- Check_Misspelled_Selector --
6004 -------------------------------
6006 procedure Check_Misspelled_Selector
6007 (Prefix : Entity_Id;
6010 Max_Suggestions : constant := 2;
6011 Nr_Of_Suggestions : Natural := 0;
6013 Suggestion_1 : Entity_Id := Empty;
6014 Suggestion_2 : Entity_Id := Empty;
6019 -- All the components of the prefix of selector Sel are matched against
6020 -- Sel and a count is maintained of possible misspellings. When at
6021 -- the end of the analysis there are one or two (not more) possible
6022 -- misspellings, these misspellings will be suggested as possible
6025 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
6027 -- Concurrent types should be handled as well ???
6032 Comp := First_Entity (Prefix);
6033 while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
6034 if Is_Visible_Component (Comp, Sel) then
6035 if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
6036 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
6038 case Nr_Of_Suggestions is
6039 when 1 => Suggestion_1 := Comp;
6040 when 2 => Suggestion_2 := Comp;
6041 when others => null;
6046 Comp := Next_Entity (Comp);
6049 -- Report at most two suggestions
6051 if Nr_Of_Suggestions = 1 then
6052 Error_Msg_NE -- CODEFIX
6053 ("\possible misspelling of&", Sel, Suggestion_1);
6055 elsif Nr_Of_Suggestions = 2 then
6056 Error_Msg_Node_2 := Suggestion_2;
6057 Error_Msg_NE -- CODEFIX
6058 ("\possible misspelling of& or&", Sel, Suggestion_1);
6060 end Check_Misspelled_Selector;
6062 ----------------------
6063 -- Defined_In_Scope --
6064 ----------------------
6066 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
6068 S1 : constant Entity_Id := Scope (Base_Type (T));
6071 or else (S1 = System_Aux_Id and then S = Scope (S1));
6072 end Defined_In_Scope;
6078 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
6084 Void_Interp_Seen : Boolean := False;
6087 pragma Warnings (Off, Boolean);
6090 if Ada_Version >= Ada_2005 then
6091 Actual := First_Actual (N);
6092 while Present (Actual) loop
6094 -- Ada 2005 (AI-50217): Post an error in case of premature
6095 -- usage of an entity from the limited view.
6097 if not Analyzed (Etype (Actual))
6098 and then From_Limited_With (Etype (Actual))
6100 Error_Msg_Qual_Level := 1;
6102 ("missing with_clause for scope of imported type&",
6103 Actual, Etype (Actual));
6104 Error_Msg_Qual_Level := 0;
6107 Next_Actual (Actual);
6111 -- Before listing the possible candidates, check whether this is
6112 -- a prefix of a selected component that has been rewritten as a
6113 -- parameterless function call because there is a callable candidate
6114 -- interpretation. If there is a hidden package in the list of homonyms
6115 -- of the function name (bad programming style in any case) suggest that
6116 -- this is the intended entity.
6118 if No (Parameter_Associations (N))
6119 and then Nkind (Parent (N)) = N_Selected_Component
6120 and then Nkind (Parent (Parent (N))) in N_Declaration
6121 and then Is_Overloaded (Nam)
6127 Ent := Current_Entity (Nam);
6128 while Present (Ent) loop
6129 if Ekind (Ent) = E_Package then
6131 ("no legal interpretations as function call,!", Nam);
6132 Error_Msg_NE ("\package& is not visible", N, Ent);
6134 Rewrite (Parent (N),
6135 New_Occurrence_Of (Any_Type, Sloc (N)));
6139 Ent := Homonym (Ent);
6144 -- Analyze each candidate call again, with full error reporting for
6148 ("no candidate interpretations match the actuals:!", Nam);
6149 Err_Mode := All_Errors_Mode;
6150 All_Errors_Mode := True;
6152 -- If this is a call to an operation of a concurrent type,
6153 -- the failed interpretations have been removed from the
6154 -- name. Recover them to provide full diagnostics.
6156 if Nkind (Parent (Nam)) = N_Selected_Component then
6157 Set_Entity (Nam, Empty);
6158 New_Nam := New_Copy_Tree (Parent (Nam));
6159 Set_Is_Overloaded (New_Nam, False);
6160 Set_Is_Overloaded (Selector_Name (New_Nam), False);
6161 Set_Parent (New_Nam, Parent (Parent (Nam)));
6162 Analyze_Selected_Component (New_Nam);
6163 Get_First_Interp (Selector_Name (New_Nam), X, It);
6165 Get_First_Interp (Nam, X, It);
6168 while Present (It.Nam) loop
6169 if Etype (It.Nam) = Standard_Void_Type then
6170 Void_Interp_Seen := True;
6173 Analyze_One_Call (N, It.Nam, True, Success);
6174 Get_Next_Interp (X, It);
6177 if Nkind (N) = N_Function_Call then
6178 Get_First_Interp (Nam, X, It);
6181 and then Ekind (Entity (Name (N))) = E_Function
6182 and then Present (Homonym (Entity (Name (N))))
6184 -- A name may appear overloaded if it has a homonym, even if that
6185 -- homonym is non-overloadable, in which case the overload list is
6186 -- in fact empty. This specialized case deserves a special message
6187 -- if the homonym is a child package.
6190 Nam : constant Node_Id := Name (N);
6191 H : constant Entity_Id := Homonym (Entity (Nam));
6194 if Ekind (H) = E_Package and then Is_Child_Unit (H) then
6195 Error_Msg_Qual_Level := 2;
6196 Error_Msg_NE ("if an entity in package& is meant, ", Nam, H);
6197 Error_Msg_NE ("\use a fully qualified name", Nam, H);
6198 Error_Msg_Qual_Level := 0;
6203 while Present (It.Nam) loop
6204 if Ekind_In (It.Nam, E_Function, E_Operator) then
6207 Get_Next_Interp (X, It);
6211 -- If all interpretations are procedures, this deserves a more
6212 -- precise message. Ditto if this appears as the prefix of a
6213 -- selected component, which may be a lexical error.
6216 ("\context requires function call, found procedure name", Nam);
6218 if Nkind (Parent (N)) = N_Selected_Component
6219 and then N = Prefix (Parent (N))
6221 Error_Msg_N -- CODEFIX
6222 ("\period should probably be semicolon", Parent (N));
6226 elsif Nkind (N) = N_Procedure_Call_Statement
6227 and then not Void_Interp_Seen
6229 Error_Msg_N ("\function name found in procedure call", Nam);
6232 All_Errors_Mode := Err_Mode;
6235 ---------------------------
6236 -- Find_Arithmetic_Types --
6237 ---------------------------
6239 procedure Find_Arithmetic_Types
6244 Index1 : Interp_Index;
6245 Index2 : Interp_Index;
6249 procedure Check_Right_Argument (T : Entity_Id);
6250 -- Check right operand of operator
6252 --------------------------
6253 -- Check_Right_Argument --
6254 --------------------------
6256 procedure Check_Right_Argument (T : Entity_Id) is
6258 if not Is_Overloaded (R) then
6259 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
6261 Get_First_Interp (R, Index2, It2);
6262 while Present (It2.Typ) loop
6263 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
6264 Get_Next_Interp (Index2, It2);
6267 end Check_Right_Argument;
6269 -- Start of processing for Find_Arithmetic_Types
6272 if not Is_Overloaded (L) then
6273 Check_Right_Argument (Etype (L));
6276 Get_First_Interp (L, Index1, It1);
6277 while Present (It1.Typ) loop
6278 Check_Right_Argument (It1.Typ);
6279 Get_Next_Interp (Index1, It1);
6283 end Find_Arithmetic_Types;
6285 ------------------------
6286 -- Find_Boolean_Types --
6287 ------------------------
6289 procedure Find_Boolean_Types
6294 Index : Interp_Index;
6297 procedure Check_Numeric_Argument (T : Entity_Id);
6298 -- Special case for logical operations one of whose operands is an
6299 -- integer literal. If both are literal the result is any modular type.
6301 ----------------------------
6302 -- Check_Numeric_Argument --
6303 ----------------------------
6305 procedure Check_Numeric_Argument (T : Entity_Id) is
6307 if T = Universal_Integer then
6308 Add_One_Interp (N, Op_Id, Any_Modular);
6310 elsif Is_Modular_Integer_Type (T) then
6311 Add_One_Interp (N, Op_Id, T);
6313 end Check_Numeric_Argument;
6315 -- Start of processing for Find_Boolean_Types
6318 if not Is_Overloaded (L) then
6319 if Etype (L) = Universal_Integer
6320 or else Etype (L) = Any_Modular
6322 if not Is_Overloaded (R) then
6323 Check_Numeric_Argument (Etype (R));
6326 Get_First_Interp (R, Index, It);
6327 while Present (It.Typ) loop
6328 Check_Numeric_Argument (It.Typ);
6329 Get_Next_Interp (Index, It);
6333 -- If operands are aggregates, we must assume that they may be
6334 -- boolean arrays, and leave disambiguation for the second pass.
6335 -- If only one is an aggregate, verify that the other one has an
6336 -- interpretation as a boolean array
6338 elsif Nkind (L) = N_Aggregate then
6339 if Nkind (R) = N_Aggregate then
6340 Add_One_Interp (N, Op_Id, Etype (L));
6342 elsif not Is_Overloaded (R) then
6343 if Valid_Boolean_Arg (Etype (R)) then
6344 Add_One_Interp (N, Op_Id, Etype (R));
6348 Get_First_Interp (R, Index, It);
6349 while Present (It.Typ) loop
6350 if Valid_Boolean_Arg (It.Typ) then
6351 Add_One_Interp (N, Op_Id, It.Typ);
6354 Get_Next_Interp (Index, It);
6358 elsif Valid_Boolean_Arg (Etype (L))
6359 and then Has_Compatible_Type (R, Etype (L))
6361 Add_One_Interp (N, Op_Id, Etype (L));
6365 Get_First_Interp (L, Index, It);
6366 while Present (It.Typ) loop
6367 if Valid_Boolean_Arg (It.Typ)
6368 and then Has_Compatible_Type (R, It.Typ)
6370 Add_One_Interp (N, Op_Id, It.Typ);
6373 Get_Next_Interp (Index, It);
6376 end Find_Boolean_Types;
6378 ---------------------------
6379 -- Find_Comparison_Types --
6380 ---------------------------
6382 procedure Find_Comparison_Types
6387 Index : Interp_Index;
6389 Found : Boolean := False;
6392 Scop : Entity_Id := Empty;
6394 procedure Try_One_Interp (T1 : Entity_Id);
6395 -- Routine to try one proposed interpretation. Note that the context
6396 -- of the operator plays no role in resolving the arguments, so that
6397 -- if there is more than one interpretation of the operands that is
6398 -- compatible with comparison, the operation is ambiguous.
6400 --------------------
6401 -- Try_One_Interp --
6402 --------------------
6404 procedure Try_One_Interp (T1 : Entity_Id) is
6406 -- If the operator is an expanded name, then the type of the operand
6407 -- must be defined in the corresponding scope. If the type is
6408 -- universal, the context will impose the correct type. Note that we
6409 -- also avoid returning if we are currently within a generic instance
6410 -- due to the fact that the generic package declaration has already
6411 -- been successfully analyzed and Defined_In_Scope expects the base
6412 -- type to be defined within the instance which will never be the
6416 and then not Defined_In_Scope (T1, Scop)
6417 and then not In_Instance
6418 and then T1 /= Universal_Integer
6419 and then T1 /= Universal_Real
6420 and then T1 /= Any_String
6421 and then T1 /= Any_Composite
6426 if Valid_Comparison_Arg (T1) and then Has_Compatible_Type (R, T1) then
6427 if Found and then Base_Type (T1) /= Base_Type (T_F) then
6428 It := Disambiguate (L, I_F, Index, Any_Type);
6430 if It = No_Interp then
6431 Ambiguous_Operands (N);
6432 Set_Etype (L, Any_Type);
6445 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
6449 -- Start of processing for Find_Comparison_Types
6452 -- If left operand is aggregate, the right operand has to
6453 -- provide a usable type for it.
6455 if Nkind (L) = N_Aggregate and then Nkind (R) /= N_Aggregate then
6456 Find_Comparison_Types (L => R, R => L, Op_Id => Op_Id, N => N);
6460 if Nkind (N) = N_Function_Call
6461 and then Nkind (Name (N)) = N_Expanded_Name
6463 Scop := Entity (Prefix (Name (N)));
6465 -- The prefix may be a package renaming, and the subsequent test
6466 -- requires the original package.
6468 if Ekind (Scop) = E_Package
6469 and then Present (Renamed_Entity (Scop))
6471 Scop := Renamed_Entity (Scop);
6472 Set_Entity (Prefix (Name (N)), Scop);
6476 if not Is_Overloaded (L) then
6477 Try_One_Interp (Etype (L));
6480 Get_First_Interp (L, Index, It);
6481 while Present (It.Typ) loop
6482 Try_One_Interp (It.Typ);
6483 Get_Next_Interp (Index, It);
6486 end Find_Comparison_Types;
6488 ----------------------------------------
6489 -- Find_Non_Universal_Interpretations --
6490 ----------------------------------------
6492 procedure Find_Non_Universal_Interpretations
6498 Index : Interp_Index;
6502 if T1 = Universal_Integer or else T1 = Universal_Real
6504 -- If the left operand of an equality operator is null, the visibility
6505 -- of the operator must be determined from the interpretation of the
6506 -- right operand. This processing must be done for Any_Access, which
6507 -- is the internal representation of the type of the literal null.
6509 or else T1 = Any_Access
6511 if not Is_Overloaded (R) then
6512 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
6514 Get_First_Interp (R, Index, It);
6515 while Present (It.Typ) loop
6516 if Covers (It.Typ, T1) then
6518 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
6521 Get_Next_Interp (Index, It);
6525 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
6527 end Find_Non_Universal_Interpretations;
6529 ------------------------------
6530 -- Find_Concatenation_Types --
6531 ------------------------------
6533 procedure Find_Concatenation_Types
6538 Is_String : constant Boolean := Nkind (L) = N_String_Literal
6540 Nkind (R) = N_String_Literal;
6541 Op_Type : constant Entity_Id := Etype (Op_Id);
6544 if Is_Array_Type (Op_Type)
6546 -- Small but very effective optimization: if at least one operand is a
6547 -- string literal, then the type of the operator must be either array
6548 -- of characters or array of strings.
6550 and then (not Is_String
6552 Is_Character_Type (Component_Type (Op_Type))
6554 Is_String_Type (Component_Type (Op_Type)))
6556 and then not Is_Limited_Type (Op_Type)
6558 and then (Has_Compatible_Type (L, Op_Type)
6560 Has_Compatible_Type (L, Component_Type (Op_Type)))
6562 and then (Has_Compatible_Type (R, Op_Type)
6564 Has_Compatible_Type (R, Component_Type (Op_Type)))
6566 Add_One_Interp (N, Op_Id, Op_Type);
6568 end Find_Concatenation_Types;
6570 -------------------------
6571 -- Find_Equality_Types --
6572 -------------------------
6574 procedure Find_Equality_Types
6579 Index : Interp_Index;
6581 Found : Boolean := False;
6584 Scop : Entity_Id := Empty;
6586 procedure Try_One_Interp (T1 : Entity_Id);
6587 -- The context of the equality operator plays no role in resolving the
6588 -- arguments, so that if there is more than one interpretation of the
6589 -- operands that is compatible with equality, the construct is ambiguous
6590 -- and an error can be emitted now, after trying to disambiguate, i.e.
6591 -- applying preference rules.
6593 --------------------
6594 -- Try_One_Interp --
6595 --------------------
6597 procedure Try_One_Interp (T1 : Entity_Id) is
6601 -- Perform a sanity check in case of previous errors
6607 Bas := Base_Type (T1);
6609 -- If the operator is an expanded name, then the type of the operand
6610 -- must be defined in the corresponding scope. If the type is
6611 -- universal, the context will impose the correct type. An anonymous
6612 -- type for a 'Access reference is also universal in this sense, as
6613 -- the actual type is obtained from context.
6615 -- In Ada 2005, the equality operator for anonymous access types
6616 -- is declared in Standard, and preference rules apply to it.
6618 if Present (Scop) then
6620 -- Note that we avoid returning if we are currently within a
6621 -- generic instance due to the fact that the generic package
6622 -- declaration has already been successfully analyzed and
6623 -- Defined_In_Scope expects the base type to be defined within
6624 -- the instance which will never be the case.
6626 if Defined_In_Scope (T1, Scop)
6628 or else T1 = Universal_Integer
6629 or else T1 = Universal_Real
6630 or else T1 = Any_Access
6631 or else T1 = Any_String
6632 or else T1 = Any_Composite
6633 or else (Ekind (T1) = E_Access_Subprogram_Type
6634 and then not Comes_From_Source (T1))
6638 elsif Ekind (T1) = E_Anonymous_Access_Type
6639 and then Scop = Standard_Standard
6644 -- The scope does not contain an operator for the type
6649 -- If we have infix notation, the operator must be usable. Within
6650 -- an instance, if the type is already established we know it is
6651 -- correct. If an operand is universal it is compatible with any
6654 elsif In_Open_Scopes (Scope (Bas))
6655 or else Is_Potentially_Use_Visible (Bas)
6656 or else In_Use (Bas)
6657 or else (In_Use (Scope (Bas)) and then not Is_Hidden (Bas))
6659 -- In an instance, the type may have been immediately visible.
6660 -- Either the types are compatible, or one operand is universal
6661 -- (numeric or null).
6664 ((In_Instance or else In_Inlined_Body)
6666 (First_Subtype (T1) = First_Subtype (Etype (R))
6667 or else Nkind (R) = N_Null
6669 (Is_Numeric_Type (T1)
6670 and then Is_Universal_Numeric_Type (Etype (R)))))
6672 -- In Ada 2005, the equality on anonymous access types is declared
6673 -- in Standard, and is always visible.
6675 or else Ekind (T1) = E_Anonymous_Access_Type
6680 -- Save candidate type for subsequent error message, if any
6682 if not Is_Limited_Type (T1) then
6683 Candidate_Type := T1;
6689 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
6690 -- Do not allow anonymous access types in equality operators.
6692 if Ada_Version < Ada_2005
6693 and then Ekind (T1) = E_Anonymous_Access_Type
6698 -- If the right operand has a type compatible with T1, check for an
6699 -- acceptable interpretation, unless T1 is limited (no predefined
6700 -- equality available), or this is use of a "/=" for a tagged type.
6701 -- In the latter case, possible interpretations of equality need
6702 -- to be considered, we don't want the default inequality declared
6703 -- in Standard to be chosen, and the "/=" will be rewritten as a
6704 -- negation of "=" (see the end of Analyze_Equality_Op). This ensures
6705 -- that rewriting happens during analysis rather than being
6706 -- delayed until expansion (this is needed for ASIS, which only sees
6707 -- the unexpanded tree). Note that if the node is N_Op_Ne, but Op_Id
6708 -- is Name_Op_Eq then we still proceed with the interpretation,
6709 -- because that indicates the potential rewriting case where the
6710 -- interpretation to consider is actually "=" and the node may be
6711 -- about to be rewritten by Analyze_Equality_Op.
6713 if T1 /= Standard_Void_Type
6714 and then Has_Compatible_Type (R, T1)
6717 ((not Is_Limited_Type (T1)
6718 and then not Is_Limited_Composite (T1))
6722 and then not Is_Limited_Type (Component_Type (T1))
6723 and then Available_Full_View_Of_Component (T1)))
6726 (Nkind (N) /= N_Op_Ne
6727 or else not Is_Tagged_Type (T1)
6728 or else Chars (Op_Id) = Name_Op_Eq)
6731 and then Base_Type (T1) /= Base_Type (T_F)
6733 It := Disambiguate (L, I_F, Index, Any_Type);
6735 if It = No_Interp then
6736 Ambiguous_Operands (N);
6737 Set_Etype (L, Any_Type);
6750 if not Analyzed (L) then
6754 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
6756 -- Case of operator was not visible, Etype still set to Any_Type
6758 if Etype (N) = Any_Type then
6762 elsif Scop = Standard_Standard
6763 and then Ekind (T1) = E_Anonymous_Access_Type
6769 -- Start of processing for Find_Equality_Types
6772 -- If left operand is aggregate, the right operand has to
6773 -- provide a usable type for it.
6775 if Nkind (L) = N_Aggregate
6776 and then Nkind (R) /= N_Aggregate
6778 Find_Equality_Types (L => R, R => L, Op_Id => Op_Id, N => N);
6782 if Nkind (N) = N_Function_Call
6783 and then Nkind (Name (N)) = N_Expanded_Name
6785 Scop := Entity (Prefix (Name (N)));
6787 -- The prefix may be a package renaming, and the subsequent test
6788 -- requires the original package.
6790 if Ekind (Scop) = E_Package
6791 and then Present (Renamed_Entity (Scop))
6793 Scop := Renamed_Entity (Scop);
6794 Set_Entity (Prefix (Name (N)), Scop);
6798 if not Is_Overloaded (L) then
6799 Try_One_Interp (Etype (L));
6802 Get_First_Interp (L, Index, It);
6803 while Present (It.Typ) loop
6804 Try_One_Interp (It.Typ);
6805 Get_Next_Interp (Index, It);
6808 end Find_Equality_Types;
6810 -------------------------
6811 -- Find_Negation_Types --
6812 -------------------------
6814 procedure Find_Negation_Types
6819 Index : Interp_Index;
6823 if not Is_Overloaded (R) then
6824 if Etype (R) = Universal_Integer then
6825 Add_One_Interp (N, Op_Id, Any_Modular);
6826 elsif Valid_Boolean_Arg (Etype (R)) then
6827 Add_One_Interp (N, Op_Id, Etype (R));
6831 Get_First_Interp (R, Index, It);
6832 while Present (It.Typ) loop
6833 if Valid_Boolean_Arg (It.Typ) then
6834 Add_One_Interp (N, Op_Id, It.Typ);
6837 Get_Next_Interp (Index, It);
6840 end Find_Negation_Types;
6842 ------------------------------
6843 -- Find_Primitive_Operation --
6844 ------------------------------
6846 function Find_Primitive_Operation (N : Node_Id) return Boolean is
6847 Obj : constant Node_Id := Prefix (N);
6848 Op : constant Node_Id := Selector_Name (N);
6855 Set_Etype (Op, Any_Type);
6857 if Is_Access_Type (Etype (Obj)) then
6858 Typ := Designated_Type (Etype (Obj));
6863 if Is_Class_Wide_Type (Typ) then
6864 Typ := Root_Type (Typ);
6867 Prims := Primitive_Operations (Typ);
6869 Prim := First_Elmt (Prims);
6870 while Present (Prim) loop
6871 if Chars (Node (Prim)) = Chars (Op) then
6872 Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
6873 Set_Etype (N, Etype (Node (Prim)));
6879 -- Now look for class-wide operations of the type or any of its
6880 -- ancestors by iterating over the homonyms of the selector.
6883 Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
6887 Hom := Current_Entity (Op);
6888 while Present (Hom) loop
6889 if (Ekind (Hom) = E_Procedure
6891 Ekind (Hom) = E_Function)
6892 and then Scope (Hom) = Scope (Typ)
6893 and then Present (First_Formal (Hom))
6895 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
6897 (Is_Access_Type (Etype (First_Formal (Hom)))
6899 Ekind (Etype (First_Formal (Hom))) =
6900 E_Anonymous_Access_Type
6903 (Designated_Type (Etype (First_Formal (Hom)))) =
6906 Add_One_Interp (Op, Hom, Etype (Hom));
6907 Set_Etype (N, Etype (Hom));
6910 Hom := Homonym (Hom);
6914 return Etype (Op) /= Any_Type;
6915 end Find_Primitive_Operation;
6917 ----------------------
6918 -- Find_Unary_Types --
6919 ----------------------
6921 procedure Find_Unary_Types
6926 Index : Interp_Index;
6930 if not Is_Overloaded (R) then
6931 if Is_Numeric_Type (Etype (R)) then
6933 -- In an instance a generic actual may be a numeric type even if
6934 -- the formal in the generic unit was not. In that case, the
6935 -- predefined operator was not a possible interpretation in the
6936 -- generic, and cannot be one in the instance, unless the operator
6937 -- is an actual of an instance.
6941 not Is_Numeric_Type (Corresponding_Generic_Type (Etype (R)))
6945 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
6950 Get_First_Interp (R, Index, It);
6951 while Present (It.Typ) loop
6952 if Is_Numeric_Type (It.Typ) then
6956 (Corresponding_Generic_Type (Etype (It.Typ)))
6961 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
6965 Get_Next_Interp (Index, It);
6968 end Find_Unary_Types;
6974 function Junk_Operand (N : Node_Id) return Boolean is
6978 if Error_Posted (N) then
6982 -- Get entity to be tested
6984 if Is_Entity_Name (N)
6985 and then Present (Entity (N))
6989 -- An odd case, a procedure name gets converted to a very peculiar
6990 -- function call, and here is where we detect this happening.
6992 elsif Nkind (N) = N_Function_Call
6993 and then Is_Entity_Name (Name (N))
6994 and then Present (Entity (Name (N)))
6998 -- Another odd case, there are at least some cases of selected
6999 -- components where the selected component is not marked as having
7000 -- an entity, even though the selector does have an entity
7002 elsif Nkind (N) = N_Selected_Component
7003 and then Present (Entity (Selector_Name (N)))
7005 Enode := Selector_Name (N);
7011 -- Now test the entity we got to see if it is a bad case
7013 case Ekind (Entity (Enode)) is
7016 ("package name cannot be used as operand", Enode);
7018 when Generic_Unit_Kind =>
7020 ("generic unit name cannot be used as operand", Enode);
7024 ("subtype name cannot be used as operand", Enode);
7028 ("entry name cannot be used as operand", Enode);
7032 ("procedure name cannot be used as operand", Enode);
7036 ("exception name cannot be used as operand", Enode);
7043 ("label name cannot be used as operand", Enode);
7052 --------------------
7053 -- Operator_Check --
7054 --------------------
7056 procedure Operator_Check (N : Node_Id) is
7058 Remove_Abstract_Operations (N);
7060 -- Test for case of no interpretation found for operator
7062 if Etype (N) = Any_Type then
7066 Op_Id : Entity_Id := Empty;
7069 R := Right_Opnd (N);
7071 if Nkind (N) in N_Binary_Op then
7077 -- If either operand has no type, then don't complain further,
7078 -- since this simply means that we have a propagated error.
7081 or else Etype (R) = Any_Type
7082 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
7084 -- For the rather unusual case where one of the operands is
7085 -- a Raise_Expression, whose initial type is Any_Type, use
7086 -- the type of the other operand.
7088 if Nkind (L) = N_Raise_Expression then
7089 Set_Etype (L, Etype (R));
7090 Set_Etype (N, Etype (R));
7092 elsif Nkind (R) = N_Raise_Expression then
7093 Set_Etype (R, Etype (L));
7094 Set_Etype (N, Etype (L));
7099 -- We explicitly check for the case of concatenation of component
7100 -- with component to avoid reporting spurious matching array types
7101 -- that might happen to be lurking in distant packages (such as
7102 -- run-time packages). This also prevents inconsistencies in the
7103 -- messages for certain ACVC B tests, which can vary depending on
7104 -- types declared in run-time interfaces. Another improvement when
7105 -- aggregates are present is to look for a well-typed operand.
7107 elsif Present (Candidate_Type)
7108 and then (Nkind (N) /= N_Op_Concat
7109 or else Is_Array_Type (Etype (L))
7110 or else Is_Array_Type (Etype (R)))
7112 if Nkind (N) = N_Op_Concat then
7113 if Etype (L) /= Any_Composite
7114 and then Is_Array_Type (Etype (L))
7116 Candidate_Type := Etype (L);
7118 elsif Etype (R) /= Any_Composite
7119 and then Is_Array_Type (Etype (R))
7121 Candidate_Type := Etype (R);
7125 Error_Msg_NE -- CODEFIX
7126 ("operator for} is not directly visible!",
7127 N, First_Subtype (Candidate_Type));
7130 U : constant Node_Id :=
7131 Cunit (Get_Source_Unit (Candidate_Type));
7133 if Unit_Is_Visible (U) then
7134 Error_Msg_N -- CODEFIX
7135 ("use clause would make operation legal!", N);
7137 Error_Msg_NE -- CODEFIX
7138 ("add with_clause and use_clause for&!",
7139 N, Defining_Entity (Unit (U)));
7144 -- If either operand is a junk operand (e.g. package name), then
7145 -- post appropriate error messages, but do not complain further.
7147 -- Note that the use of OR in this test instead of OR ELSE is
7148 -- quite deliberate, we may as well check both operands in the
7149 -- binary operator case.
7151 elsif Junk_Operand (R)
7152 or -- really mean OR here and not OR ELSE, see above
7153 (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
7157 -- If we have a logical operator, one of whose operands is
7158 -- Boolean, then we know that the other operand cannot resolve to
7159 -- Boolean (since we got no interpretations), but in that case we
7160 -- pretty much know that the other operand should be Boolean, so
7161 -- resolve it that way (generating an error).
7163 elsif Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor) then
7164 if Etype (L) = Standard_Boolean then
7165 Resolve (R, Standard_Boolean);
7167 elsif Etype (R) = Standard_Boolean then
7168 Resolve (L, Standard_Boolean);
7172 -- For an arithmetic operator or comparison operator, if one
7173 -- of the operands is numeric, then we know the other operand
7174 -- is not the same numeric type. If it is a non-numeric type,
7175 -- then probably it is intended to match the other operand.
7177 elsif Nkind_In (N, N_Op_Add,
7183 Nkind_In (N, N_Op_Lt,
7189 -- If Allow_Integer_Address is active, check whether the
7190 -- operation becomes legal after converting an operand.
7192 if Is_Numeric_Type (Etype (L))
7193 and then not Is_Numeric_Type (Etype (R))
7195 if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
7197 Unchecked_Convert_To (Etype (L), Relocate_Node (R)));
7199 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
7200 Analyze_Comparison_Op (N);
7202 Analyze_Arithmetic_Op (N);
7205 Resolve (R, Etype (L));
7210 elsif Is_Numeric_Type (Etype (R))
7211 and then not Is_Numeric_Type (Etype (L))
7213 if Address_Integer_Convert_OK (Etype (L), Etype (R)) then
7215 Unchecked_Convert_To (Etype (R), Relocate_Node (L)));
7217 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
7218 Analyze_Comparison_Op (N);
7220 Analyze_Arithmetic_Op (N);
7226 Resolve (L, Etype (R));
7231 elsif Allow_Integer_Address
7232 and then Is_Descendant_Of_Address (Etype (L))
7233 and then Is_Descendant_Of_Address (Etype (R))
7234 and then not Error_Posted (N)
7237 Addr_Type : constant Entity_Id := Etype (L);
7241 Unchecked_Convert_To (
7242 Standard_Integer, Relocate_Node (L)));
7244 Unchecked_Convert_To (
7245 Standard_Integer, Relocate_Node (R)));
7247 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
7248 Analyze_Comparison_Op (N);
7250 Analyze_Arithmetic_Op (N);
7253 -- If this is an operand in an enclosing arithmetic
7254 -- operation, Convert the result as an address so that
7255 -- arithmetic folding of address can continue.
7257 if Nkind (Parent (N)) in N_Op then
7259 Unchecked_Convert_To (Addr_Type, Relocate_Node (N)));
7265 -- Under relaxed RM semantics silently replace occurrences of
7266 -- null by System.Address_Null.
7268 elsif Null_To_Null_Address_Convert_OK (N) then
7269 Replace_Null_By_Null_Address (N);
7271 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
7272 Analyze_Comparison_Op (N);
7274 Analyze_Arithmetic_Op (N);
7280 -- Comparisons on A'Access are common enough to deserve a
7283 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne)
7284 and then Ekind (Etype (L)) = E_Access_Attribute_Type
7285 and then Ekind (Etype (R)) = E_Access_Attribute_Type
7288 ("two access attributes cannot be compared directly", N);
7290 ("\use qualified expression for one of the operands",
7294 -- Another one for C programmers
7296 elsif Nkind (N) = N_Op_Concat
7297 and then Valid_Boolean_Arg (Etype (L))
7298 and then Valid_Boolean_Arg (Etype (R))
7300 Error_Msg_N ("invalid operands for concatenation", N);
7301 Error_Msg_N -- CODEFIX
7302 ("\maybe AND was meant", N);
7305 -- A special case for comparison of access parameter with null
7307 elsif Nkind (N) = N_Op_Eq
7308 and then Is_Entity_Name (L)
7309 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
7310 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
7312 and then Nkind (R) = N_Null
7314 Error_Msg_N ("access parameter is not allowed to be null", L);
7315 Error_Msg_N ("\(call would raise Constraint_Error)", L);
7318 -- Another special case for exponentiation, where the right
7319 -- operand must be Natural, independently of the base.
7321 elsif Nkind (N) = N_Op_Expon
7322 and then Is_Numeric_Type (Etype (L))
7323 and then not Is_Overloaded (R)
7325 First_Subtype (Base_Type (Etype (R))) /= Standard_Integer
7326 and then Base_Type (Etype (R)) /= Universal_Integer
7328 if Ada_Version >= Ada_2012
7329 and then Has_Dimension_System (Etype (L))
7332 ("exponent for dimensioned type must be a rational" &
7333 ", found}", R, Etype (R));
7336 ("exponent must be of type Natural, found}", R, Etype (R));
7341 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
7342 if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
7344 Unchecked_Convert_To (Etype (L), Relocate_Node (R)));
7345 Analyze_Equality_Op (N);
7348 -- Under relaxed RM semantics silently replace occurrences of
7349 -- null by System.Address_Null.
7351 elsif Null_To_Null_Address_Convert_OK (N) then
7352 Replace_Null_By_Null_Address (N);
7353 Analyze_Equality_Op (N);
7358 -- If we fall through then just give general message. Note that in
7359 -- the following messages, if the operand is overloaded we choose
7360 -- an arbitrary type to complain about, but that is probably more
7361 -- useful than not giving a type at all.
7363 if Nkind (N) in N_Unary_Op then
7364 Error_Msg_Node_2 := Etype (R);
7365 Error_Msg_N ("operator& not defined for}", N);
7369 if Nkind (N) in N_Binary_Op then
7370 if not Is_Overloaded (L)
7371 and then not Is_Overloaded (R)
7372 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
7374 Error_Msg_Node_2 := First_Subtype (Etype (R));
7375 Error_Msg_N ("there is no applicable operator& for}", N);
7378 -- Another attempt to find a fix: one of the candidate
7379 -- interpretations may not be use-visible. This has
7380 -- already been checked for predefined operators, so
7381 -- we examine only user-defined functions.
7383 Op_Id := Get_Name_Entity_Id (Chars (N));
7385 while Present (Op_Id) loop
7386 if Ekind (Op_Id) /= E_Operator
7387 and then Is_Overloadable (Op_Id)
7389 if not Is_Immediately_Visible (Op_Id)
7390 and then not In_Use (Scope (Op_Id))
7391 and then not Is_Abstract_Subprogram (Op_Id)
7392 and then not Is_Hidden (Op_Id)
7393 and then Ekind (Scope (Op_Id)) = E_Package
7396 (L, Etype (First_Formal (Op_Id)))
7398 (Next_Formal (First_Formal (Op_Id)))
7402 Etype (Next_Formal (First_Formal (Op_Id))))
7405 ("no legal interpretation for operator&", N);
7407 ("\use clause on& would make operation legal",
7413 Op_Id := Homonym (Op_Id);
7417 Error_Msg_N ("invalid operand types for operator&", N);
7419 if Nkind (N) /= N_Op_Concat then
7420 Error_Msg_NE ("\left operand has}!", N, Etype (L));
7421 Error_Msg_NE ("\right operand has}!", N, Etype (R));
7423 -- For multiplication and division operators with
7424 -- a fixed-point operand and an integer operand,
7425 -- indicate that the integer operand should be of
7428 if Nkind_In (N, N_Op_Multiply, N_Op_Divide)
7429 and then Is_Fixed_Point_Type (Etype (L))
7430 and then Is_Integer_Type (Etype (R))
7433 ("\convert right operand to `Integer`", N);
7435 elsif Nkind (N) = N_Op_Multiply
7436 and then Is_Fixed_Point_Type (Etype (R))
7437 and then Is_Integer_Type (Etype (L))
7440 ("\convert left operand to `Integer`", N);
7443 -- For concatenation operators it is more difficult to
7444 -- determine which is the wrong operand. It is worth
7445 -- flagging explicitly an access type, for those who
7446 -- might think that a dereference happens here.
7448 elsif Is_Access_Type (Etype (L)) then
7449 Error_Msg_N ("\left operand is access type", N);
7451 elsif Is_Access_Type (Etype (R)) then
7452 Error_Msg_N ("\right operand is access type", N);
7462 -----------------------------------------
7463 -- Process_Implicit_Dereference_Prefix --
7464 -----------------------------------------
7466 function Process_Implicit_Dereference_Prefix
7468 P : Entity_Id) return Entity_Id
7471 Typ : constant Entity_Id := Designated_Type (Etype (P));
7475 and then (Operating_Mode = Check_Semantics or else not Expander_Active)
7477 -- We create a dummy reference to E to ensure that the reference is
7478 -- not considered as part of an assignment (an implicit dereference
7479 -- can never assign to its prefix). The Comes_From_Source attribute
7480 -- needs to be propagated for accurate warnings.
7482 Ref := New_Occurrence_Of (E, Sloc (P));
7483 Set_Comes_From_Source (Ref, Comes_From_Source (P));
7484 Generate_Reference (E, Ref);
7487 -- An implicit dereference is a legal occurrence of an incomplete type
7488 -- imported through a limited_with clause, if the full view is visible.
7490 if From_Limited_With (Typ)
7491 and then not From_Limited_With (Scope (Typ))
7493 (Is_Immediately_Visible (Scope (Typ))
7495 (Is_Child_Unit (Scope (Typ))
7496 and then Is_Visible_Lib_Unit (Scope (Typ))))
7498 return Available_View (Typ);
7502 end Process_Implicit_Dereference_Prefix;
7504 --------------------------------
7505 -- Remove_Abstract_Operations --
7506 --------------------------------
7508 procedure Remove_Abstract_Operations (N : Node_Id) is
7509 Abstract_Op : Entity_Id := Empty;
7510 Address_Descendant : Boolean := False;
7514 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
7515 -- activate this if either extensions are enabled, or if the abstract
7516 -- operation in question comes from a predefined file. This latter test
7517 -- allows us to use abstract to make operations invisible to users. In
7518 -- particular, if type Address is non-private and abstract subprograms
7519 -- are used to hide its operators, they will be truly hidden.
7521 type Operand_Position is (First_Op, Second_Op);
7522 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
7524 procedure Remove_Address_Interpretations (Op : Operand_Position);
7525 -- Ambiguities may arise when the operands are literal and the address
7526 -- operations in s-auxdec are visible. In that case, remove the
7527 -- interpretation of a literal as Address, to retain the semantics
7528 -- of Address as a private type.
7530 ------------------------------------
7531 -- Remove_Address_Interpretations --
7532 ------------------------------------
7534 procedure Remove_Address_Interpretations (Op : Operand_Position) is
7538 if Is_Overloaded (N) then
7539 Get_First_Interp (N, I, It);
7540 while Present (It.Nam) loop
7541 Formal := First_Entity (It.Nam);
7543 if Op = Second_Op then
7544 Formal := Next_Entity (Formal);
7547 if Is_Descendant_Of_Address (Etype (Formal)) then
7548 Address_Descendant := True;
7552 Get_Next_Interp (I, It);
7555 end Remove_Address_Interpretations;
7557 -- Start of processing for Remove_Abstract_Operations
7560 if Is_Overloaded (N) then
7561 if Debug_Flag_V then
7562 Write_Line ("Remove_Abstract_Operations: ");
7563 Write_Overloads (N);
7566 Get_First_Interp (N, I, It);
7568 while Present (It.Nam) loop
7569 if Is_Overloadable (It.Nam)
7570 and then Is_Abstract_Subprogram (It.Nam)
7571 and then not Is_Dispatching_Operation (It.Nam)
7573 Abstract_Op := It.Nam;
7575 if Is_Descendant_Of_Address (It.Typ) then
7576 Address_Descendant := True;
7580 -- In Ada 2005, this operation does not participate in overload
7581 -- resolution. If the operation is defined in a predefined
7582 -- unit, it is one of the operations declared abstract in some
7583 -- variants of System, and it must be removed as well.
7585 elsif Ada_Version >= Ada_2005
7586 or else In_Predefined_Unit (It.Nam)
7593 Get_Next_Interp (I, It);
7596 if No (Abstract_Op) then
7598 -- If some interpretation yields an integer type, it is still
7599 -- possible that there are address interpretations. Remove them
7600 -- if one operand is a literal, to avoid spurious ambiguities
7601 -- on systems where Address is a visible integer type.
7603 if Is_Overloaded (N)
7604 and then Nkind (N) in N_Op
7605 and then Is_Integer_Type (Etype (N))
7607 if Nkind (N) in N_Binary_Op then
7608 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
7609 Remove_Address_Interpretations (Second_Op);
7611 elsif Nkind (Left_Opnd (N)) = N_Integer_Literal then
7612 Remove_Address_Interpretations (First_Op);
7617 elsif Nkind (N) in N_Op then
7619 -- Remove interpretations that treat literals as addresses. This
7620 -- is never appropriate, even when Address is defined as a visible
7621 -- Integer type. The reason is that we would really prefer Address
7622 -- to behave as a private type, even in this case. If Address is a
7623 -- visible integer type, we get lots of overload ambiguities.
7625 if Nkind (N) in N_Binary_Op then
7627 U1 : constant Boolean :=
7628 Present (Universal_Interpretation (Right_Opnd (N)));
7629 U2 : constant Boolean :=
7630 Present (Universal_Interpretation (Left_Opnd (N)));
7634 Remove_Address_Interpretations (Second_Op);
7638 Remove_Address_Interpretations (First_Op);
7641 if not (U1 and U2) then
7643 -- Remove corresponding predefined operator, which is
7644 -- always added to the overload set.
7646 Get_First_Interp (N, I, It);
7647 while Present (It.Nam) loop
7648 if Scope (It.Nam) = Standard_Standard
7649 and then Base_Type (It.Typ) =
7650 Base_Type (Etype (Abstract_Op))
7655 Get_Next_Interp (I, It);
7658 elsif Is_Overloaded (N)
7659 and then Present (Univ_Type)
7661 -- If both operands have a universal interpretation,
7662 -- it is still necessary to remove interpretations that
7663 -- yield Address. Any remaining ambiguities will be
7664 -- removed in Disambiguate.
7666 Get_First_Interp (N, I, It);
7667 while Present (It.Nam) loop
7668 if Is_Descendant_Of_Address (It.Typ) then
7671 elsif not Is_Type (It.Nam) then
7672 Set_Entity (N, It.Nam);
7675 Get_Next_Interp (I, It);
7681 elsif Nkind (N) = N_Function_Call
7683 (Nkind (Name (N)) = N_Operator_Symbol
7685 (Nkind (Name (N)) = N_Expanded_Name
7687 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
7691 Arg1 : constant Node_Id := First (Parameter_Associations (N));
7692 U1 : constant Boolean :=
7693 Present (Universal_Interpretation (Arg1));
7694 U2 : constant Boolean :=
7695 Present (Next (Arg1)) and then
7696 Present (Universal_Interpretation (Next (Arg1)));
7700 Remove_Address_Interpretations (First_Op);
7704 Remove_Address_Interpretations (Second_Op);
7707 if not (U1 and U2) then
7708 Get_First_Interp (N, I, It);
7709 while Present (It.Nam) loop
7710 if Scope (It.Nam) = Standard_Standard
7711 and then It.Typ = Base_Type (Etype (Abstract_Op))
7716 Get_Next_Interp (I, It);
7722 -- If the removal has left no valid interpretations, emit an error
7723 -- message now and label node as illegal.
7725 if Present (Abstract_Op) then
7726 Get_First_Interp (N, I, It);
7730 -- Removal of abstract operation left no viable candidate
7732 Set_Etype (N, Any_Type);
7733 Error_Msg_Sloc := Sloc (Abstract_Op);
7735 ("cannot call abstract operation& declared#", N, Abstract_Op);
7737 -- In Ada 2005, an abstract operation may disable predefined
7738 -- operators. Since the context is not yet known, we mark the
7739 -- predefined operators as potentially hidden. Do not include
7740 -- predefined operators when addresses are involved since this
7741 -- case is handled separately.
7743 elsif Ada_Version >= Ada_2005 and then not Address_Descendant then
7744 while Present (It.Nam) loop
7745 if Is_Numeric_Type (It.Typ)
7746 and then Scope (It.Typ) = Standard_Standard
7748 Set_Abstract_Op (I, Abstract_Op);
7751 Get_Next_Interp (I, It);
7756 if Debug_Flag_V then
7757 Write_Line ("Remove_Abstract_Operations done: ");
7758 Write_Overloads (N);
7761 end Remove_Abstract_Operations;
7763 ----------------------------
7764 -- Try_Container_Indexing --
7765 ----------------------------
7767 function Try_Container_Indexing
7770 Exprs : List_Id) return Boolean
7772 Pref_Typ : constant Entity_Id := Etype (Prefix);
7774 function Constant_Indexing_OK return Boolean;
7775 -- Constant_Indexing is legal if there is no Variable_Indexing defined
7776 -- for the type, or else node not a target of assignment, or an actual
7777 -- for an IN OUT or OUT formal (RM 4.1.6 (11)).
7779 function Expr_Matches_In_Formal
7781 Par : Node_Id) return Boolean;
7782 -- Find formal corresponding to given indexed component that is an
7783 -- actual in a call. Note that the enclosing subprogram call has not
7784 -- been analyzed yet, and the parameter list is not normalized, so
7785 -- that if the argument is a parameter association we must match it
7786 -- by name and not by position.
7788 function Find_Indexing_Operations
7791 Is_Constant : Boolean) return Node_Id;
7792 -- Return a reference to the primitive operation of type T denoted by
7793 -- name Nam. If the operation is overloaded, the reference carries all
7794 -- interpretations. Flag Is_Constant should be set when the context is
7795 -- constant indexing.
7797 --------------------------
7798 -- Constant_Indexing_OK --
7799 --------------------------
7801 function Constant_Indexing_OK return Boolean is
7805 if No (Find_Value_Of_Aspect (Pref_Typ, Aspect_Variable_Indexing)) then
7808 elsif not Is_Variable (Prefix) then
7813 while Present (Par) loop
7814 if Nkind (Parent (Par)) = N_Assignment_Statement
7815 and then Par = Name (Parent (Par))
7819 -- The call may be overloaded, in which case we assume that its
7820 -- resolution does not depend on the type of the parameter that
7821 -- includes the indexing operation.
7823 elsif Nkind_In (Parent (Par), N_Function_Call,
7824 N_Procedure_Call_Statement)
7825 and then Is_Entity_Name (Name (Parent (Par)))
7831 -- We should look for an interpretation with the proper
7832 -- number of formals, and determine whether it is an
7833 -- In_Parameter, but for now we examine the formal that
7834 -- corresponds to the indexing, and assume that variable
7835 -- indexing is required if some interpretation has an
7836 -- assignable formal at that position. Still does not
7837 -- cover the most complex cases ???
7839 if Is_Overloaded (Name (Parent (Par))) then
7841 Proc : constant Node_Id := Name (Parent (Par));
7846 Get_First_Interp (Proc, I, It);
7847 while Present (It.Nam) loop
7848 if not Expr_Matches_In_Formal (It.Nam, Par) then
7852 Get_Next_Interp (I, It);
7856 -- All interpretations have a matching in-mode formal
7861 Proc := Entity (Name (Parent (Par)));
7863 -- If this is an indirect call, get formals from
7866 if Is_Access_Subprogram_Type (Etype (Proc)) then
7867 Proc := Designated_Type (Etype (Proc));
7871 return Expr_Matches_In_Formal (Proc, Par);
7874 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
7877 -- If the indexed component is a prefix it may be the first actual
7878 -- of a prefixed call. Retrieve the called entity, if any, and
7879 -- check its first formal. Determine if the context is a procedure
7880 -- or function call.
7882 elsif Nkind (Parent (Par)) = N_Selected_Component then
7884 Sel : constant Node_Id := Selector_Name (Parent (Par));
7885 Nam : constant Entity_Id := Current_Entity (Sel);
7888 if Present (Nam) and then Is_Overloadable (Nam) then
7889 if Nkind (Parent (Parent (Par))) =
7890 N_Procedure_Call_Statement
7894 elsif Ekind (Nam) = E_Function
7895 and then Present (First_Formal (Nam))
7897 return Ekind (First_Formal (Nam)) = E_In_Parameter;
7902 elsif Nkind (Par) in N_Op then
7906 Par := Parent (Par);
7909 -- In all other cases, constant indexing is legal
7912 end Constant_Indexing_OK;
7914 ----------------------------
7915 -- Expr_Matches_In_Formal --
7916 ----------------------------
7918 function Expr_Matches_In_Formal
7920 Par : Node_Id) return Boolean
7926 Formal := First_Formal (Subp);
7927 Actual := First (Parameter_Associations ((Parent (Par))));
7929 if Nkind (Par) /= N_Parameter_Association then
7931 -- Match by position
7933 while Present (Actual) and then Present (Formal) loop
7934 exit when Actual = Par;
7937 if Present (Formal) then
7938 Next_Formal (Formal);
7940 -- Otherwise this is a parameter mismatch, the error is
7941 -- reported elsewhere, or else variable indexing is implied.
7951 while Present (Formal) loop
7952 exit when Chars (Formal) = Chars (Selector_Name (Par));
7953 Next_Formal (Formal);
7961 return Present (Formal) and then Ekind (Formal) = E_In_Parameter;
7962 end Expr_Matches_In_Formal;
7964 ------------------------------
7965 -- Find_Indexing_Operations --
7966 ------------------------------
7968 function Find_Indexing_Operations
7971 Is_Constant : Boolean) return Node_Id
7973 procedure Inspect_Declarations
7975 Ref : in out Node_Id);
7976 -- Traverse the declarative list where type Typ resides and collect
7977 -- all suitable interpretations in node Ref.
7979 procedure Inspect_Primitives
7981 Ref : in out Node_Id);
7982 -- Traverse the list of primitive operations of type Typ and collect
7983 -- all suitable interpretations in node Ref.
7985 function Is_OK_Candidate
7986 (Subp_Id : Entity_Id;
7987 Typ : Entity_Id) return Boolean;
7988 -- Determine whether subprogram Subp_Id is a suitable indexing
7989 -- operation for type Typ. To qualify as such, the subprogram must
7990 -- be a function, have at least two parameters, and the type of the
7991 -- first parameter must be either Typ, or Typ'Class, or access [to
7992 -- constant] with designated type Typ or Typ'Class.
7994 procedure Record_Interp (Subp_Id : Entity_Id; Ref : in out Node_Id);
7995 -- Store subprogram Subp_Id as an interpretation in node Ref
7997 --------------------------
7998 -- Inspect_Declarations --
7999 --------------------------
8001 procedure Inspect_Declarations
8003 Ref : in out Node_Id)
8005 Typ_Decl : constant Node_Id := Declaration_Node (Typ);
8007 Subp_Id : Entity_Id;
8010 -- Ensure that the routine is not called with itypes, which lack a
8011 -- declarative node.
8013 pragma Assert (Present (Typ_Decl));
8014 pragma Assert (Is_List_Member (Typ_Decl));
8016 Decl := First (List_Containing (Typ_Decl));
8017 while Present (Decl) loop
8018 if Nkind (Decl) = N_Subprogram_Declaration then
8019 Subp_Id := Defining_Entity (Decl);
8021 if Is_OK_Candidate (Subp_Id, Typ) then
8022 Record_Interp (Subp_Id, Ref);
8028 end Inspect_Declarations;
8030 ------------------------
8031 -- Inspect_Primitives --
8032 ------------------------
8034 procedure Inspect_Primitives
8036 Ref : in out Node_Id)
8038 Prim_Elmt : Elmt_Id;
8039 Prim_Id : Entity_Id;
8042 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
8043 while Present (Prim_Elmt) loop
8044 Prim_Id := Node (Prim_Elmt);
8046 if Is_OK_Candidate (Prim_Id, Typ) then
8047 Record_Interp (Prim_Id, Ref);
8050 Next_Elmt (Prim_Elmt);
8052 end Inspect_Primitives;
8054 ---------------------
8055 -- Is_OK_Candidate --
8056 ---------------------
8058 function Is_OK_Candidate
8059 (Subp_Id : Entity_Id;
8060 Typ : Entity_Id) return Boolean
8063 Formal_Typ : Entity_Id;
8064 Param_Typ : Node_Id;
8067 -- To classify as a suitable candidate, the subprogram must be a
8068 -- function whose name matches the argument of aspect Constant or
8069 -- Variable_Indexing.
8071 if Ekind (Subp_Id) = E_Function and then Chars (Subp_Id) = Nam then
8072 Formal := First_Formal (Subp_Id);
8074 -- The candidate requires at least two parameters
8076 if Present (Formal) and then Present (Next_Formal (Formal)) then
8077 Formal_Typ := Empty;
8078 Param_Typ := Parameter_Type (Parent (Formal));
8080 -- Use the designated type when the first parameter is of an
8083 if Nkind (Param_Typ) = N_Access_Definition
8084 and then Present (Subtype_Mark (Param_Typ))
8086 -- When the context is a constant indexing, the access
8087 -- definition must be access-to-constant. This does not
8088 -- apply to variable indexing.
8091 or else Constant_Present (Param_Typ)
8093 Formal_Typ := Etype (Subtype_Mark (Param_Typ));
8096 -- Otherwise use the parameter type
8099 Formal_Typ := Etype (Param_Typ);
8102 if Present (Formal_Typ) then
8104 -- Use the specific type when the parameter type is
8107 if Is_Class_Wide_Type (Formal_Typ) then
8108 Formal_Typ := Etype (Base_Type (Formal_Typ));
8111 -- Use the full view when the parameter type is private
8114 if Is_Incomplete_Or_Private_Type (Formal_Typ)
8115 and then Present (Full_View (Formal_Typ))
8117 Formal_Typ := Full_View (Formal_Typ);
8120 -- The type of the first parameter must denote the type
8121 -- of the container or acts as its ancestor type.
8125 or else Is_Ancestor (Formal_Typ, Typ);
8131 end Is_OK_Candidate;
8137 procedure Record_Interp (Subp_Id : Entity_Id; Ref : in out Node_Id) is
8139 if Present (Ref) then
8140 Add_One_Interp (Ref, Subp_Id, Etype (Subp_Id));
8142 -- Otherwise this is the first interpretation. Create a reference
8143 -- where all remaining interpretations will be collected.
8146 Ref := New_Occurrence_Of (Subp_Id, Sloc (T));
8155 -- Start of processing for Find_Indexing_Operations
8160 -- Use the specific type when the parameter type is class-wide
8162 if Is_Class_Wide_Type (Typ) then
8163 Typ := Root_Type (Typ);
8167 Typ := Underlying_Type (Base_Type (Typ));
8169 Inspect_Primitives (Typ, Ref);
8171 -- Now look for explicit declarations of an indexing operation.
8172 -- If the type is private the operation may be declared in the
8173 -- visible part that contains the partial view.
8175 if Is_Private_Type (T) then
8176 Inspect_Declarations (T, Ref);
8179 Inspect_Declarations (Typ, Ref);
8182 end Find_Indexing_Operations;
8186 Loc : constant Source_Ptr := Sloc (N);
8190 Func_Name : Node_Id;
8193 Is_Constant_Indexing : Boolean := False;
8194 -- This flag reflects the nature of the container indexing. Note that
8195 -- the context may be suited for constant indexing, but the type may
8196 -- lack a Constant_Indexing annotation.
8198 -- Start of processing for Try_Container_Indexing
8201 -- Node may have been analyzed already when testing for a prefixed
8202 -- call, in which case do not redo analysis.
8204 if Present (Generalized_Indexing (N)) then
8210 -- If indexing a class-wide container, obtain indexing primitive from
8213 if Is_Class_Wide_Type (C_Type) then
8214 C_Type := Etype (Base_Type (C_Type));
8217 -- Check whether the type has a specified indexing aspect
8221 -- The context is suitable for constant indexing, so obtain the name of
8222 -- the indexing function from aspect Constant_Indexing.
8224 if Constant_Indexing_OK then
8226 Find_Value_Of_Aspect (Pref_Typ, Aspect_Constant_Indexing);
8229 if Present (Func_Name) then
8230 Is_Constant_Indexing := True;
8232 -- Otherwise attempt variable indexing
8236 Find_Value_Of_Aspect (Pref_Typ, Aspect_Variable_Indexing);
8239 -- The type is not subject to either form of indexing, therefore the
8240 -- indexed component does not denote container indexing. If this is a
8241 -- true error, it is diagnosed by the caller.
8243 if No (Func_Name) then
8245 -- The prefix itself may be an indexing of a container. Rewrite it
8246 -- as such and retry.
8248 if Has_Implicit_Dereference (Pref_Typ) then
8249 Build_Explicit_Dereference (Prefix, First_Discriminant (Pref_Typ));
8250 return Try_Container_Indexing (N, Prefix, Exprs);
8252 -- Otherwise this is definitely not container indexing
8258 -- If the container type is derived from another container type, the
8259 -- value of the inherited aspect is the Reference operation declared
8260 -- for the parent type.
8262 -- However, Reference is also a primitive operation of the type, and the
8263 -- inherited operation has a different signature. We retrieve the right
8264 -- ones (the function may be overloaded) from the list of primitive
8265 -- operations of the derived type.
8267 -- Note that predefined containers are typically all derived from one of
8268 -- the Controlled types. The code below is motivated by containers that
8269 -- are derived from other types with a Reference aspect.
8270 -- Note as well that we need to examine the base type, given that
8271 -- the container object may be a constrained subtype or itype that
8272 -- does not have an explicit declaration.
8274 elsif Is_Derived_Type (C_Type)
8275 and then Etype (First_Formal (Entity (Func_Name))) /= Pref_Typ
8278 Find_Indexing_Operations
8279 (T => Base_Type (C_Type),
8280 Nam => Chars (Func_Name),
8281 Is_Constant => Is_Constant_Indexing);
8284 Assoc := New_List (Relocate_Node (Prefix));
8286 -- A generalized indexing may have nore than one index expression, so
8287 -- transfer all of them to the argument list to be used in the call.
8288 -- Note that there may be named associations, in which case the node
8289 -- was rewritten earlier as a call, and has been transformed back into
8290 -- an indexed expression to share the following processing.
8292 -- The generalized indexing node is the one on which analysis and
8293 -- resolution take place. Before expansion the original node is replaced
8294 -- with the generalized indexing node, which is a call, possibly with a
8295 -- dereference operation.
8297 if Comes_From_Source (N) then
8298 Check_Compiler_Unit ("generalized indexing", N);
8301 -- Create argument list for function call that represents generalized
8302 -- indexing. Note that indices (i.e. actuals) may themselves be
8310 Arg := First (Exprs);
8311 while Present (Arg) loop
8312 New_Arg := Relocate_Node (Arg);
8314 -- The arguments can be parameter associations, in which case the
8315 -- explicit actual parameter carries the overloadings.
8317 if Nkind (New_Arg) /= N_Parameter_Association then
8318 Save_Interps (Arg, New_Arg);
8321 Append (New_Arg, Assoc);
8326 if not Is_Overloaded (Func_Name) then
8327 Func := Entity (Func_Name);
8330 Make_Function_Call (Loc,
8331 Name => New_Occurrence_Of (Func, Loc),
8332 Parameter_Associations => Assoc);
8334 Set_Parent (Indexing, Parent (N));
8335 Set_Generalized_Indexing (N, Indexing);
8337 Set_Etype (N, Etype (Indexing));
8339 -- If the return type of the indexing function is a reference type,
8340 -- add the dereference as a possible interpretation. Note that the
8341 -- indexing aspect may be a function that returns the element type
8342 -- with no intervening implicit dereference, and that the reference
8343 -- discriminant is not the first discriminant.
8345 if Has_Discriminants (Etype (Func)) then
8346 Check_Implicit_Dereference (N, Etype (Func));
8350 -- If there are multiple indexing functions, build a function call
8351 -- and analyze it for each of the possible interpretations.
8354 Make_Function_Call (Loc,
8356 Make_Identifier (Loc, Chars (Func_Name)),
8357 Parameter_Associations => Assoc);
8358 Set_Parent (Indexing, Parent (N));
8359 Set_Generalized_Indexing (N, Indexing);
8360 Set_Etype (N, Any_Type);
8361 Set_Etype (Name (Indexing), Any_Type);
8369 Get_First_Interp (Func_Name, I, It);
8370 Set_Etype (Indexing, Any_Type);
8372 -- Analyze each candidate function with the given actuals
8374 while Present (It.Nam) loop
8375 Analyze_One_Call (Indexing, It.Nam, False, Success);
8376 Get_Next_Interp (I, It);
8379 -- If there are several successful candidates, resolution will
8380 -- be by result. Mark the interpretations of the function name
8383 if Is_Overloaded (Indexing) then
8384 Get_First_Interp (Indexing, I, It);
8386 while Present (It.Nam) loop
8387 Add_One_Interp (Name (Indexing), It.Nam, It.Typ);
8388 Get_Next_Interp (I, It);
8392 Set_Etype (Name (Indexing), Etype (Indexing));
8395 -- Now add the candidate interpretations to the indexing node
8396 -- itself, to be replaced later by the function call.
8398 if Is_Overloaded (Name (Indexing)) then
8399 Get_First_Interp (Name (Indexing), I, It);
8401 while Present (It.Nam) loop
8402 Add_One_Interp (N, It.Nam, It.Typ);
8404 -- Add dereference interpretation if the result type has
8405 -- implicit reference discriminants.
8407 if Has_Discriminants (Etype (It.Nam)) then
8408 Check_Implicit_Dereference (N, Etype (It.Nam));
8411 Get_Next_Interp (I, It);
8415 Set_Etype (N, Etype (Name (Indexing)));
8416 if Has_Discriminants (Etype (N)) then
8417 Check_Implicit_Dereference (N, Etype (N));
8423 if Etype (Indexing) = Any_Type then
8425 ("container cannot be indexed with&", N, Etype (First (Exprs)));
8426 Rewrite (N, New_Occurrence_Of (Any_Id, Loc));
8430 end Try_Container_Indexing;
8432 -----------------------
8433 -- Try_Indirect_Call --
8434 -----------------------
8436 function Try_Indirect_Call
8439 Typ : Entity_Id) return Boolean
8445 pragma Warnings (Off, Call_OK);
8448 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
8450 Actual := First_Actual (N);
8451 Formal := First_Formal (Designated_Type (Typ));
8452 while Present (Actual) and then Present (Formal) loop
8453 if not Has_Compatible_Type (Actual, Etype (Formal)) then
8458 Next_Formal (Formal);
8461 if No (Actual) and then No (Formal) then
8462 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
8464 -- Nam is a candidate interpretation for the name in the call,
8465 -- if it is not an indirect call.
8467 if not Is_Type (Nam)
8468 and then Is_Entity_Name (Name (N))
8470 Set_Entity (Name (N), Nam);
8478 end Try_Indirect_Call;
8480 ----------------------
8481 -- Try_Indexed_Call --
8482 ----------------------
8484 function Try_Indexed_Call
8488 Skip_First : Boolean) return Boolean
8490 Loc : constant Source_Ptr := Sloc (N);
8491 Actuals : constant List_Id := Parameter_Associations (N);
8496 Actual := First (Actuals);
8498 -- If the call was originally written in prefix form, skip the first
8499 -- actual, which is obviously not defaulted.
8505 Index := First_Index (Typ);
8506 while Present (Actual) and then Present (Index) loop
8508 -- If the parameter list has a named association, the expression
8509 -- is definitely a call and not an indexed component.
8511 if Nkind (Actual) = N_Parameter_Association then
8515 if Is_Entity_Name (Actual)
8516 and then Is_Type (Entity (Actual))
8517 and then No (Next (Actual))
8519 -- A single actual that is a type name indicates a slice if the
8520 -- type is discrete, and an error otherwise.
8522 if Is_Discrete_Type (Entity (Actual)) then
8526 Make_Function_Call (Loc,
8527 Name => Relocate_Node (Name (N))),
8529 New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
8534 Error_Msg_N ("invalid use of type in expression", Actual);
8535 Set_Etype (N, Any_Type);
8540 elsif not Has_Compatible_Type (Actual, Etype (Index)) then
8548 if No (Actual) and then No (Index) then
8549 Add_One_Interp (N, Nam, Component_Type (Typ));
8551 -- Nam is a candidate interpretation for the name in the call,
8552 -- if it is not an indirect call.
8554 if not Is_Type (Nam)
8555 and then Is_Entity_Name (Name (N))
8557 Set_Entity (Name (N), Nam);
8564 end Try_Indexed_Call;
8566 --------------------------
8567 -- Try_Object_Operation --
8568 --------------------------
8570 function Try_Object_Operation
8571 (N : Node_Id; CW_Test_Only : Boolean := False) return Boolean
8573 K : constant Node_Kind := Nkind (Parent (N));
8574 Is_Subprg_Call : constant Boolean := K in N_Subprogram_Call;
8575 Loc : constant Source_Ptr := Sloc (N);
8576 Obj : constant Node_Id := Prefix (N);
8578 Subprog : constant Node_Id :=
8579 Make_Identifier (Sloc (Selector_Name (N)),
8580 Chars => Chars (Selector_Name (N)));
8581 -- Identifier on which possible interpretations will be collected
8583 Report_Error : Boolean := False;
8584 -- If no candidate interpretation matches the context, redo analysis
8585 -- with Report_Error True to provide additional information.
8588 Candidate : Entity_Id := Empty;
8589 New_Call_Node : Node_Id := Empty;
8590 Node_To_Replace : Node_Id;
8591 Obj_Type : Entity_Id := Etype (Obj);
8592 Success : Boolean := False;
8594 procedure Complete_Object_Operation
8595 (Call_Node : Node_Id;
8596 Node_To_Replace : Node_Id);
8597 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
8598 -- Call_Node, insert the object (or its dereference) as the first actual
8599 -- in the call, and complete the analysis of the call.
8601 procedure Report_Ambiguity (Op : Entity_Id);
8602 -- If a prefixed procedure call is ambiguous, indicate whether the call
8603 -- includes an implicit dereference or an implicit 'Access.
8605 procedure Transform_Object_Operation
8606 (Call_Node : out Node_Id;
8607 Node_To_Replace : out Node_Id);
8608 -- Transform Obj.Operation (X, Y, ...) into Operation (Obj, X, Y ...).
8609 -- Call_Node is the resulting subprogram call, Node_To_Replace is
8610 -- either N or the parent of N, and Subprog is a reference to the
8611 -- subprogram we are trying to match.
8613 function Try_Class_Wide_Operation
8614 (Call_Node : Node_Id;
8615 Node_To_Replace : Node_Id) return Boolean;
8616 -- Traverse all ancestor types looking for a class-wide subprogram for
8617 -- which the current operation is a valid non-dispatching call.
8619 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
8620 -- If prefix is overloaded, its interpretation may include different
8621 -- tagged types, and we must examine the primitive operations and the
8622 -- class-wide operations of each in order to find candidate
8623 -- interpretations for the call as a whole.
8625 function Try_Primitive_Operation
8626 (Call_Node : Node_Id;
8627 Node_To_Replace : Node_Id) return Boolean;
8628 -- Traverse the list of primitive subprograms looking for a dispatching
8629 -- operation for which the current node is a valid call.
8631 function Valid_Candidate
8634 Subp : Entity_Id) return Entity_Id;
8635 -- If the subprogram is a valid interpretation, record it, and add to
8636 -- the list of interpretations of Subprog. Otherwise return Empty.
8638 -------------------------------
8639 -- Complete_Object_Operation --
8640 -------------------------------
8642 procedure Complete_Object_Operation
8643 (Call_Node : Node_Id;
8644 Node_To_Replace : Node_Id)
8646 Control : constant Entity_Id := First_Formal (Entity (Subprog));
8647 Formal_Type : constant Entity_Id := Etype (Control);
8648 First_Actual : Node_Id;
8651 -- Place the name of the operation, with its interpretations,
8652 -- on the rewritten call.
8654 Set_Name (Call_Node, Subprog);
8656 First_Actual := First (Parameter_Associations (Call_Node));
8658 -- For cross-reference purposes, treat the new node as being in the
8659 -- source if the original one is. Set entity and type, even though
8660 -- they may be overwritten during resolution if overloaded.
8662 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
8663 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
8665 if Nkind (N) = N_Selected_Component
8666 and then not Inside_A_Generic
8668 Set_Entity (Selector_Name (N), Entity (Subprog));
8669 Set_Etype (Selector_Name (N), Etype (Entity (Subprog)));
8672 -- If need be, rewrite first actual as an explicit dereference. If
8673 -- the call is overloaded, the rewriting can only be done once the
8674 -- primitive operation is identified.
8676 if Is_Overloaded (Subprog) then
8678 -- The prefix itself may be overloaded, and its interpretations
8679 -- must be propagated to the new actual in the call.
8681 if Is_Overloaded (Obj) then
8682 Save_Interps (Obj, First_Actual);
8685 Rewrite (First_Actual, Obj);
8687 elsif not Is_Access_Type (Formal_Type)
8688 and then Is_Access_Type (Etype (Obj))
8690 Rewrite (First_Actual,
8691 Make_Explicit_Dereference (Sloc (Obj), Obj));
8692 Analyze (First_Actual);
8694 -- If we need to introduce an explicit dereference, verify that
8695 -- the resulting actual is compatible with the mode of the formal.
8697 if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
8698 and then Is_Access_Constant (Etype (Obj))
8701 ("expect variable in call to&", Prefix (N), Entity (Subprog));
8704 -- Conversely, if the formal is an access parameter and the object is
8705 -- not an access type or a reference type (i.e. a type with the
8706 -- Implicit_Dereference aspect specified), replace the actual with a
8707 -- 'Access reference. Its analysis will check that the object is
8710 elsif Is_Access_Type (Formal_Type)
8711 and then not Is_Access_Type (Etype (Obj))
8713 (not Has_Implicit_Dereference (Etype (Obj))
8715 not Is_Access_Type (Designated_Type (Etype
8716 (Get_Reference_Discriminant (Etype (Obj))))))
8718 -- A special case: A.all'Access is illegal if A is an access to a
8719 -- constant and the context requires an access to a variable.
8721 if not Is_Access_Constant (Formal_Type) then
8722 if (Nkind (Obj) = N_Explicit_Dereference
8723 and then Is_Access_Constant (Etype (Prefix (Obj))))
8724 or else not Is_Variable (Obj)
8727 ("actual for & must be a variable", Obj, Control);
8731 Rewrite (First_Actual,
8732 Make_Attribute_Reference (Loc,
8733 Attribute_Name => Name_Access,
8734 Prefix => Relocate_Node (Obj)));
8736 -- If the object is not overloaded verify that taking access of
8737 -- it is legal. Otherwise check is made during resolution.
8739 if not Is_Overloaded (Obj)
8740 and then not Is_Aliased_View (Obj)
8743 ("object in prefixed call to & must be aliased "
8744 & "(RM 4.1.3 (13 1/2))", Prefix (First_Actual), Subprog);
8747 Analyze (First_Actual);
8750 if Is_Overloaded (Obj) then
8751 Save_Interps (Obj, First_Actual);
8754 Rewrite (First_Actual, Obj);
8757 -- The operation is obtained from the dispatch table and not by
8758 -- visibility, and may be declared in a unit that is not explicitly
8759 -- referenced in the source, but is nevertheless required in the
8760 -- context of the current unit. Indicate that operation and its scope
8761 -- are referenced, to prevent spurious and misleading warnings. If
8762 -- the operation is overloaded, all primitives are in the same scope
8763 -- and we can use any of them.
8765 Set_Referenced (Entity (Subprog), True);
8766 Set_Referenced (Scope (Entity (Subprog)), True);
8768 Rewrite (Node_To_Replace, Call_Node);
8770 -- Propagate the interpretations collected in subprog to the new
8771 -- function call node, to be resolved from context.
8773 if Is_Overloaded (Subprog) then
8774 Save_Interps (Subprog, Node_To_Replace);
8777 -- The type of the subprogram may be a limited view obtained
8778 -- transitively from another unit. If full view is available,
8779 -- use it to analyze call. If there is no nonlimited view, then
8780 -- this is diagnosed when analyzing the rewritten call.
8783 T : constant Entity_Id := Etype (Subprog);
8785 if From_Limited_With (T) then
8786 Set_Etype (Entity (Subprog), Available_View (T));
8790 Analyze (Node_To_Replace);
8792 -- If the operation has been rewritten into a call, which may get
8793 -- subsequently an explicit dereference, preserve the type on the
8794 -- original node (selected component or indexed component) for
8795 -- subsequent legality tests, e.g. Is_Variable. which examines
8796 -- the original node.
8798 if Nkind (Node_To_Replace) = N_Function_Call then
8800 (Original_Node (Node_To_Replace), Etype (Node_To_Replace));
8803 end Complete_Object_Operation;
8805 ----------------------
8806 -- Report_Ambiguity --
8807 ----------------------
8809 procedure Report_Ambiguity (Op : Entity_Id) is
8810 Access_Actual : constant Boolean :=
8811 Is_Access_Type (Etype (Prefix (N)));
8812 Access_Formal : Boolean := False;
8815 Error_Msg_Sloc := Sloc (Op);
8817 if Present (First_Formal (Op)) then
8818 Access_Formal := Is_Access_Type (Etype (First_Formal (Op)));
8821 if Access_Formal and then not Access_Actual then
8822 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8824 ("\possible interpretation "
8825 & "(inherited, with implicit 'Access) #", N);
8828 ("\possible interpretation (with implicit 'Access) #", N);
8831 elsif not Access_Formal and then Access_Actual then
8832 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8834 ("\possible interpretation "
8835 & "(inherited, with implicit dereference) #", N);
8838 ("\possible interpretation (with implicit dereference) #", N);
8842 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8843 Error_Msg_N ("\possible interpretation (inherited)#", N);
8845 Error_Msg_N -- CODEFIX
8846 ("\possible interpretation#", N);
8849 end Report_Ambiguity;
8851 --------------------------------
8852 -- Transform_Object_Operation --
8853 --------------------------------
8855 procedure Transform_Object_Operation
8856 (Call_Node : out Node_Id;
8857 Node_To_Replace : out Node_Id)
8859 Dummy : constant Node_Id := New_Copy (Obj);
8860 -- Placeholder used as a first parameter in the call, replaced
8861 -- eventually by the proper object.
8863 Parent_Node : constant Node_Id := Parent (N);
8869 -- Obj may already have been rewritten if it involves an implicit
8870 -- dereference (e.g. if it is an access to a limited view). Preserve
8871 -- a link to the original node for ASIS use.
8873 if not Comes_From_Source (Obj) then
8874 Set_Original_Node (Dummy, Original_Node (Obj));
8877 -- Common case covering 1) Call to a procedure and 2) Call to a
8878 -- function that has some additional actuals.
8880 if Nkind (Parent_Node) in N_Subprogram_Call
8882 -- N is a selected component node containing the name of the
8883 -- subprogram. If N is not the name of the parent node we must
8884 -- not replace the parent node by the new construct. This case
8885 -- occurs when N is a parameterless call to a subprogram that
8886 -- is an actual parameter of a call to another subprogram. For
8888 -- Some_Subprogram (..., Obj.Operation, ...)
8890 and then Name (Parent_Node) = N
8892 Node_To_Replace := Parent_Node;
8894 Actuals := Parameter_Associations (Parent_Node);
8896 if Present (Actuals) then
8897 Prepend (Dummy, Actuals);
8899 Actuals := New_List (Dummy);
8902 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
8904 Make_Procedure_Call_Statement (Loc,
8905 Name => New_Copy (Subprog),
8906 Parameter_Associations => Actuals);
8910 Make_Function_Call (Loc,
8911 Name => New_Copy (Subprog),
8912 Parameter_Associations => Actuals);
8915 -- Before analysis, a function call appears as an indexed component
8916 -- if there are no named associations.
8918 elsif Nkind (Parent_Node) = N_Indexed_Component
8919 and then N = Prefix (Parent_Node)
8921 Node_To_Replace := Parent_Node;
8922 Actuals := Expressions (Parent_Node);
8924 Actual := First (Actuals);
8925 while Present (Actual) loop
8930 Prepend (Dummy, Actuals);
8933 Make_Function_Call (Loc,
8934 Name => New_Copy (Subprog),
8935 Parameter_Associations => Actuals);
8937 -- Parameterless call: Obj.F is rewritten as F (Obj)
8940 Node_To_Replace := N;
8943 Make_Function_Call (Loc,
8944 Name => New_Copy (Subprog),
8945 Parameter_Associations => New_List (Dummy));
8947 end Transform_Object_Operation;
8949 ------------------------------
8950 -- Try_Class_Wide_Operation --
8951 ------------------------------
8953 function Try_Class_Wide_Operation
8954 (Call_Node : Node_Id;
8955 Node_To_Replace : Node_Id) return Boolean
8957 Anc_Type : Entity_Id;
8958 Matching_Op : Entity_Id := Empty;
8961 procedure Traverse_Homonyms
8962 (Anc_Type : Entity_Id;
8963 Error : out Boolean);
8964 -- Traverse the homonym chain of the subprogram searching for those
8965 -- homonyms whose first formal has the Anc_Type's class-wide type,
8966 -- or an anonymous access type designating the class-wide type. If
8967 -- an ambiguity is detected, then Error is set to True.
8969 procedure Traverse_Interfaces
8970 (Anc_Type : Entity_Id;
8971 Error : out Boolean);
8972 -- Traverse the list of interfaces, if any, associated with Anc_Type
8973 -- and search for acceptable class-wide homonyms associated with each
8974 -- interface. If an ambiguity is detected, then Error is set to True.
8976 -----------------------
8977 -- Traverse_Homonyms --
8978 -----------------------
8980 procedure Traverse_Homonyms
8981 (Anc_Type : Entity_Id;
8982 Error : out Boolean)
8984 function First_Formal_Match
8985 (Subp_Id : Entity_Id;
8986 Typ : Entity_Id) return Boolean;
8987 -- Predicate to verify that the first foramal of class-wide
8988 -- subprogram Subp_Id matches type Typ of the prefix.
8990 ------------------------
8991 -- First_Formal_Match --
8992 ------------------------
8994 function First_Formal_Match
8995 (Subp_Id : Entity_Id;
8996 Typ : Entity_Id) return Boolean
8998 Ctrl : constant Entity_Id := First_Formal (Subp_Id);
9004 (Base_Type (Etype (Ctrl)) = Typ
9006 (Ekind (Etype (Ctrl)) = E_Anonymous_Access_Type
9008 Base_Type (Designated_Type (Etype (Ctrl))) =
9010 end First_Formal_Match;
9014 CW_Typ : constant Entity_Id := Class_Wide_Type (Anc_Type);
9016 Candidate : Entity_Id;
9017 -- If homonym is a renaming, examine the renamed program
9023 -- Start of processing for Traverse_Homonyms
9028 -- Find a non-hidden operation whose first parameter is of the
9029 -- class-wide type, a subtype thereof, or an anonymous access
9030 -- to same. If in an instance, the operation can be considered
9031 -- even if hidden (it may be hidden because the instantiation
9032 -- is expanded after the containing package has been analyzed).
9033 -- If the subprogram is a generic actual in an enclosing instance,
9034 -- it appears as a renaming that is a candidate interpretation as
9037 Hom := Current_Entity (Subprog);
9038 while Present (Hom) loop
9039 if Ekind_In (Hom, E_Procedure, E_Function)
9040 and then Present (Renamed_Entity (Hom))
9041 and then Is_Generic_Actual_Subprogram (Hom)
9042 and then In_Open_Scopes (Scope (Hom))
9044 Candidate := Renamed_Entity (Hom);
9049 if Ekind_In (Candidate, E_Function, E_Procedure)
9050 and then (not Is_Hidden (Candidate) or else In_Instance)
9051 and then Scope (Candidate) = Scope (Base_Type (Anc_Type))
9052 and then First_Formal_Match (Candidate, CW_Typ)
9054 -- If the context is a procedure call, ignore functions
9055 -- in the name of the call.
9057 if Ekind (Candidate) = E_Function
9058 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
9059 and then N = Name (Parent (N))
9063 -- If the context is a function call, ignore procedures
9064 -- in the name of the call.
9066 elsif Ekind (Candidate) = E_Procedure
9067 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
9072 Set_Etype (Call_Node, Any_Type);
9073 Set_Is_Overloaded (Call_Node, False);
9076 if No (Matching_Op) then
9077 Hom_Ref := New_Occurrence_Of (Candidate, Sloc (Subprog));
9079 Set_Etype (Call_Node, Any_Type);
9080 Set_Name (Call_Node, Hom_Ref);
9081 Set_Parent (Call_Node, Parent (Node_To_Replace));
9086 Report => Report_Error,
9088 Skip_First => True);
9091 Valid_Candidate (Success, Call_Node, Candidate);
9097 Report => Report_Error,
9099 Skip_First => True);
9101 -- The same operation may be encountered on two homonym
9102 -- traversals, before and after looking at interfaces.
9103 -- Check for this case before reporting a real ambiguity.
9106 (Valid_Candidate (Success, Call_Node, Candidate))
9107 and then Nkind (Call_Node) /= N_Function_Call
9108 and then Candidate /= Matching_Op
9110 Error_Msg_NE ("ambiguous call to&", N, Hom);
9111 Report_Ambiguity (Matching_Op);
9112 Report_Ambiguity (Hom);
9120 Hom := Homonym (Hom);
9122 end Traverse_Homonyms;
9124 -------------------------
9125 -- Traverse_Interfaces --
9126 -------------------------
9128 procedure Traverse_Interfaces
9129 (Anc_Type : Entity_Id;
9130 Error : out Boolean)
9132 Intface_List : constant List_Id :=
9133 Abstract_Interface_List (Anc_Type);
9139 if Is_Non_Empty_List (Intface_List) then
9140 Intface := First (Intface_List);
9141 while Present (Intface) loop
9143 -- Look for acceptable class-wide homonyms associated with
9146 Traverse_Homonyms (Etype (Intface), Error);
9152 -- Continue the search by looking at each of the interface's
9153 -- associated interface ancestors.
9155 Traverse_Interfaces (Etype (Intface), Error);
9164 end Traverse_Interfaces;
9166 -- Start of processing for Try_Class_Wide_Operation
9169 -- If we are searching only for conflicting class-wide subprograms
9170 -- then initialize directly Matching_Op with the target entity.
9172 if CW_Test_Only then
9173 Matching_Op := Entity (Selector_Name (N));
9176 -- Loop through ancestor types (including interfaces), traversing
9177 -- the homonym chain of the subprogram, trying out those homonyms
9178 -- whose first formal has the class-wide type of the ancestor, or
9179 -- an anonymous access type designating the class-wide type.
9181 Anc_Type := Obj_Type;
9183 -- Look for a match among homonyms associated with the ancestor
9185 Traverse_Homonyms (Anc_Type, Error);
9191 -- Continue the search for matches among homonyms associated with
9192 -- any interfaces implemented by the ancestor.
9194 Traverse_Interfaces (Anc_Type, Error);
9200 exit when Etype (Anc_Type) = Anc_Type;
9201 Anc_Type := Etype (Anc_Type);
9204 if Present (Matching_Op) then
9205 Set_Etype (Call_Node, Etype (Matching_Op));
9208 return Present (Matching_Op);
9209 end Try_Class_Wide_Operation;
9211 -----------------------------------
9212 -- Try_One_Prefix_Interpretation --
9213 -----------------------------------
9215 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
9216 Prev_Obj_Type : constant Entity_Id := Obj_Type;
9217 -- If the interpretation does not have a valid candidate type,
9218 -- preserve current value of Obj_Type for subsequent errors.
9223 if Is_Access_Type (Obj_Type) then
9224 Obj_Type := Designated_Type (Obj_Type);
9227 if Ekind_In (Obj_Type, E_Private_Subtype,
9228 E_Record_Subtype_With_Private)
9230 Obj_Type := Base_Type (Obj_Type);
9233 if Is_Class_Wide_Type (Obj_Type) then
9234 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
9237 -- The type may have be obtained through a limited_with clause,
9238 -- in which case the primitive operations are available on its
9239 -- nonlimited view. If still incomplete, retrieve full view.
9241 if Ekind (Obj_Type) = E_Incomplete_Type
9242 and then From_Limited_With (Obj_Type)
9243 and then Has_Non_Limited_View (Obj_Type)
9245 Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
9248 -- If the object is not tagged, or the type is still an incomplete
9249 -- type, this is not a prefixed call. Restore the previous type as
9250 -- the current one is not a legal candidate.
9252 if not Is_Tagged_Type (Obj_Type)
9253 or else Is_Incomplete_Type (Obj_Type)
9255 Obj_Type := Prev_Obj_Type;
9260 Dup_Call_Node : constant Node_Id := New_Copy (New_Call_Node);
9262 Prim_Result : Boolean := False;
9265 if not CW_Test_Only then
9267 Try_Primitive_Operation
9268 (Call_Node => New_Call_Node,
9269 Node_To_Replace => Node_To_Replace);
9272 -- Check if there is a class-wide subprogram covering the
9273 -- primitive. This check must be done even if a candidate
9274 -- was found in order to report ambiguous calls.
9276 if not Prim_Result then
9278 Try_Class_Wide_Operation
9279 (Call_Node => New_Call_Node,
9280 Node_To_Replace => Node_To_Replace);
9282 -- If we found a primitive we search for class-wide subprograms
9283 -- using a duplicate of the call node (done to avoid missing its
9284 -- decoration if there is no ambiguity).
9288 Try_Class_Wide_Operation
9289 (Call_Node => Dup_Call_Node,
9290 Node_To_Replace => Node_To_Replace);
9293 end Try_One_Prefix_Interpretation;
9295 -----------------------------
9296 -- Try_Primitive_Operation --
9297 -----------------------------
9299 function Try_Primitive_Operation
9300 (Call_Node : Node_Id;
9301 Node_To_Replace : Node_Id) return Boolean
9304 Prim_Op : Entity_Id;
9305 Matching_Op : Entity_Id := Empty;
9306 Prim_Op_Ref : Node_Id := Empty;
9308 Corr_Type : Entity_Id := Empty;
9309 -- If the prefix is a synchronized type, the controlling type of
9310 -- the primitive operation is the corresponding record type, else
9311 -- this is the object type itself.
9313 Success : Boolean := False;
9315 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
9316 -- For tagged types the candidate interpretations are found in
9317 -- the list of primitive operations of the type and its ancestors.
9318 -- For formal tagged types we have to find the operations declared
9319 -- in the same scope as the type (including in the generic formal
9320 -- part) because the type itself carries no primitive operations,
9321 -- except for formal derived types that inherit the operations of
9322 -- the parent and progenitors.
9324 -- If the context is a generic subprogram body, the generic formals
9325 -- are visible by name, but are not in the entity list of the
9326 -- subprogram because that list starts with the subprogram formals.
9327 -- We retrieve the candidate operations from the generic declaration.
9329 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id;
9330 -- Prefix notation can also be used on operations that are not
9331 -- primitives of the type, but are declared in the same immediate
9332 -- declarative part, which can only mean the corresponding package
9333 -- body (see RM 4.1.3 (9.2/3)). If we are in that body we extend the
9334 -- list of primitives with body operations with the same name that
9335 -- may be candidates, so that Try_Primitive_Operations can examine
9336 -- them if no real primitive is found.
9338 function Is_Private_Overriding (Op : Entity_Id) return Boolean;
9339 -- An operation that overrides an inherited operation in the private
9340 -- part of its package may be hidden, but if the inherited operation
9341 -- is visible a direct call to it will dispatch to the private one,
9342 -- which is therefore a valid candidate.
9344 function Names_Match
9345 (Obj_Type : Entity_Id;
9346 Prim_Op : Entity_Id;
9347 Subprog : Entity_Id) return Boolean;
9348 -- Return True if the names of Prim_Op and Subprog match. If Obj_Type
9349 -- is a protected type then compare also the original name of Prim_Op
9350 -- with the name of Subprog (since the expander may have added a
9351 -- prefix to its original name --see Exp_Ch9.Build_Selected_Name).
9353 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
9354 -- Verify that the prefix, dereferenced if need be, is a valid
9355 -- controlling argument in a call to Op. The remaining actuals
9356 -- are checked in the subsequent call to Analyze_One_Call.
9358 ------------------------------
9359 -- Collect_Generic_Type_Ops --
9360 ------------------------------
9362 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
9363 Bas : constant Entity_Id := Base_Type (T);
9364 Candidates : constant Elist_Id := New_Elmt_List;
9368 procedure Check_Candidate;
9369 -- The operation is a candidate if its first parameter is a
9370 -- controlling operand of the desired type.
9372 -----------------------
9373 -- Check_Candidate; --
9374 -----------------------
9376 procedure Check_Candidate is
9378 Formal := First_Formal (Subp);
9381 and then Is_Controlling_Formal (Formal)
9383 (Base_Type (Etype (Formal)) = Bas
9385 (Is_Access_Type (Etype (Formal))
9386 and then Designated_Type (Etype (Formal)) = Bas))
9388 Append_Elmt (Subp, Candidates);
9390 end Check_Candidate;
9392 -- Start of processing for Collect_Generic_Type_Ops
9395 if Is_Derived_Type (T) then
9396 return Primitive_Operations (T);
9398 elsif Ekind_In (Scope (T), E_Procedure, E_Function) then
9400 -- Scan the list of generic formals to find subprograms
9401 -- that may have a first controlling formal of the type.
9403 if Nkind (Unit_Declaration_Node (Scope (T))) =
9404 N_Generic_Subprogram_Declaration
9411 First (Generic_Formal_Declarations
9412 (Unit_Declaration_Node (Scope (T))));
9413 while Present (Decl) loop
9414 if Nkind (Decl) in N_Formal_Subprogram_Declaration then
9415 Subp := Defining_Entity (Decl);
9426 -- Scan the list of entities declared in the same scope as
9427 -- the type. In general this will be an open scope, given that
9428 -- the call we are analyzing can only appear within a generic
9429 -- declaration or body (either the one that declares T, or a
9432 -- For a subtype representing a generic actual type, go to the
9435 if Is_Generic_Actual_Type (T) then
9436 Subp := First_Entity (Scope (Base_Type (T)));
9438 Subp := First_Entity (Scope (T));
9441 while Present (Subp) loop
9442 if Is_Overloadable (Subp) then
9451 end Collect_Generic_Type_Ops;
9453 ----------------------------
9454 -- Extended_Primitive_Ops --
9455 ----------------------------
9457 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id is
9458 Type_Scope : constant Entity_Id := Scope (T);
9459 Op_List : Elist_Id := Primitive_Operations (T);
9461 if Is_Package_Or_Generic_Package (Type_Scope)
9462 and then ((In_Package_Body (Type_Scope)
9463 and then In_Open_Scopes (Type_Scope)) or else In_Instance_Body)
9465 -- Retrieve list of declarations of package body if possible
9468 The_Body : constant Node_Id :=
9469 Corresponding_Body (Unit_Declaration_Node (Type_Scope));
9471 if Present (The_Body) then
9473 Body_Decls : constant List_Id :=
9474 Declarations (Unit_Declaration_Node (The_Body));
9475 Op_Found : Boolean := False;
9476 Op : Entity_Id := Current_Entity (Subprog);
9478 while Present (Op) loop
9479 if Comes_From_Source (Op)
9480 and then Is_Overloadable (Op)
9482 -- Exclude overriding primitive operations of a
9483 -- type extension declared in the package body,
9484 -- to prevent duplicates in extended list.
9486 and then not Is_Primitive (Op)
9487 and then Is_List_Member
9488 (Unit_Declaration_Node (Op))
9489 and then List_Containing
9490 (Unit_Declaration_Node (Op)) = Body_Decls
9492 if not Op_Found then
9493 -- Copy list of primitives so it is not
9494 -- affected for other uses.
9496 Op_List := New_Copy_Elist (Op_List);
9500 Append_Elmt (Op, Op_List);
9511 end Extended_Primitive_Ops;
9513 ---------------------------
9514 -- Is_Private_Overriding --
9515 ---------------------------
9517 function Is_Private_Overriding (Op : Entity_Id) return Boolean is
9518 Visible_Op : Entity_Id;
9521 -- The subprogram may be overloaded with both visible and private
9522 -- entities with the same name. We have to scan the chain of
9523 -- homonyms to determine whether there is a previous implicit
9524 -- declaration in the same scope that is overridden by the
9525 -- private candidate.
9527 Visible_Op := Homonym (Op);
9528 while Present (Visible_Op) loop
9529 if Scope (Op) /= Scope (Visible_Op) then
9532 elsif not Comes_From_Source (Visible_Op)
9533 and then Alias (Visible_Op) = Op
9534 and then not Is_Hidden (Visible_Op)
9539 Visible_Op := Homonym (Visible_Op);
9543 end Is_Private_Overriding;
9549 function Names_Match
9550 (Obj_Type : Entity_Id;
9551 Prim_Op : Entity_Id;
9552 Subprog : Entity_Id) return Boolean is
9554 -- Common case: exact match
9556 if Chars (Prim_Op) = Chars (Subprog) then
9559 -- For protected type primitives the expander may have built the
9560 -- name of the dispatching primitive prepending the type name to
9561 -- avoid conflicts with the name of the protected subprogram (see
9562 -- Exp_Ch9.Build_Selected_Name).
9564 elsif Is_Protected_Type (Obj_Type) then
9566 Present (Original_Protected_Subprogram (Prim_Op))
9567 and then Chars (Original_Protected_Subprogram (Prim_Op)) =
9570 -- In an instance, the selector name may be a generic actual that
9571 -- renames a primitive operation of the type of the prefix.
9573 elsif In_Instance and then Present (Current_Entity (Subprog)) then
9575 Subp : constant Entity_Id := Current_Entity (Subprog);
9578 and then Is_Subprogram (Subp)
9579 and then Present (Renamed_Entity (Subp))
9580 and then Is_Generic_Actual_Subprogram (Subp)
9581 and then Chars (Renamed_Entity (Subp)) = Chars (Prim_Op)
9591 -----------------------------
9592 -- Valid_First_Argument_Of --
9593 -----------------------------
9595 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
9596 Typ : Entity_Id := Etype (First_Formal (Op));
9599 if Is_Concurrent_Type (Typ)
9600 and then Present (Corresponding_Record_Type (Typ))
9602 Typ := Corresponding_Record_Type (Typ);
9605 -- Simple case. Object may be a subtype of the tagged type or may
9606 -- be the corresponding record of a synchronized type.
9608 return Obj_Type = Typ
9609 or else Base_Type (Obj_Type) = Typ
9610 or else Corr_Type = Typ
9612 -- Object may be of a derived type whose parent has unknown
9613 -- discriminants, in which case the type matches the underlying
9614 -- record view of its base.
9617 (Has_Unknown_Discriminants (Typ)
9618 and then Typ = Underlying_Record_View (Base_Type (Obj_Type)))
9620 -- Prefix can be dereferenced
9623 (Is_Access_Type (Corr_Type)
9624 and then Designated_Type (Corr_Type) = Typ)
9626 -- Formal is an access parameter, for which the object can
9627 -- provide an access.
9630 (Ekind (Typ) = E_Anonymous_Access_Type
9632 Base_Type (Designated_Type (Typ)) = Base_Type (Corr_Type));
9633 end Valid_First_Argument_Of;
9635 -- Start of processing for Try_Primitive_Operation
9638 -- Look for subprograms in the list of primitive operations. The name
9639 -- must be identical, and the kind of call indicates the expected
9640 -- kind of operation (function or procedure). If the type is a
9641 -- (tagged) synchronized type, the primitive ops are attached to the
9642 -- corresponding record (base) type.
9644 if Is_Concurrent_Type (Obj_Type) then
9645 if Present (Corresponding_Record_Type (Obj_Type)) then
9646 Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
9647 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
9649 Corr_Type := Obj_Type;
9650 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
9653 elsif not Is_Generic_Type (Obj_Type) then
9654 Corr_Type := Obj_Type;
9655 Elmt := First_Elmt (Extended_Primitive_Ops (Obj_Type));
9658 Corr_Type := Obj_Type;
9659 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
9662 while Present (Elmt) loop
9663 Prim_Op := Node (Elmt);
9665 if Names_Match (Obj_Type, Prim_Op, Subprog)
9666 and then Present (First_Formal (Prim_Op))
9667 and then Valid_First_Argument_Of (Prim_Op)
9669 (Nkind (Call_Node) = N_Function_Call)
9671 (Ekind (Prim_Op) = E_Function)
9673 -- Ada 2005 (AI-251): If this primitive operation corresponds
9674 -- to an immediate ancestor interface there is no need to add
9675 -- it to the list of interpretations; the corresponding aliased
9676 -- primitive is also in this list of primitive operations and
9677 -- will be used instead.
9679 if (Present (Interface_Alias (Prim_Op))
9680 and then Is_Ancestor (Find_Dispatching_Type
9681 (Alias (Prim_Op)), Corr_Type))
9683 -- Do not consider hidden primitives unless the type is in an
9684 -- open scope or we are within an instance, where visibility
9685 -- is known to be correct, or else if this is an overriding
9686 -- operation in the private part for an inherited operation.
9688 or else (Is_Hidden (Prim_Op)
9689 and then not Is_Immediately_Visible (Obj_Type)
9690 and then not In_Instance
9691 and then not Is_Private_Overriding (Prim_Op))
9696 Set_Etype (Call_Node, Any_Type);
9697 Set_Is_Overloaded (Call_Node, False);
9699 if No (Matching_Op) then
9700 Prim_Op_Ref := New_Occurrence_Of (Prim_Op, Sloc (Subprog));
9701 Candidate := Prim_Op;
9703 Set_Parent (Call_Node, Parent (Node_To_Replace));
9705 Set_Name (Call_Node, Prim_Op_Ref);
9711 Report => Report_Error,
9713 Skip_First => True);
9715 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
9717 -- More than one interpretation, collect for subsequent
9718 -- disambiguation. If this is a procedure call and there
9719 -- is another match, report ambiguity now.
9725 Report => Report_Error,
9727 Skip_First => True);
9729 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
9730 and then Nkind (Call_Node) /= N_Function_Call
9732 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
9733 Report_Ambiguity (Matching_Op);
9734 Report_Ambiguity (Prim_Op);
9744 if Present (Matching_Op) then
9745 Set_Etype (Call_Node, Etype (Matching_Op));
9748 return Present (Matching_Op);
9749 end Try_Primitive_Operation;
9751 ---------------------
9752 -- Valid_Candidate --
9753 ---------------------
9755 function Valid_Candidate
9758 Subp : Entity_Id) return Entity_Id
9760 Arr_Type : Entity_Id;
9761 Comp_Type : Entity_Id;
9764 -- If the subprogram is a valid interpretation, record it in global
9765 -- variable Subprog, to collect all possible overloadings.
9768 if Subp /= Entity (Subprog) then
9769 Add_One_Interp (Subprog, Subp, Etype (Subp));
9773 -- If the call may be an indexed call, retrieve component type of
9774 -- resulting expression, and add possible interpretation.
9779 if Nkind (Call) = N_Function_Call
9780 and then Nkind (Parent (N)) = N_Indexed_Component
9781 and then Needs_One_Actual (Subp)
9783 if Is_Array_Type (Etype (Subp)) then
9784 Arr_Type := Etype (Subp);
9786 elsif Is_Access_Type (Etype (Subp))
9787 and then Is_Array_Type (Designated_Type (Etype (Subp)))
9789 Arr_Type := Designated_Type (Etype (Subp));
9793 if Present (Arr_Type) then
9795 -- Verify that the actuals (excluding the object) match the types
9803 Actual := Next (First_Actual (Call));
9804 Index := First_Index (Arr_Type);
9805 while Present (Actual) and then Present (Index) loop
9806 if not Has_Compatible_Type (Actual, Etype (Index)) then
9811 Next_Actual (Actual);
9817 and then Present (Arr_Type)
9819 Comp_Type := Component_Type (Arr_Type);
9823 if Present (Comp_Type)
9824 and then Etype (Subprog) /= Comp_Type
9826 Add_One_Interp (Subprog, Subp, Comp_Type);
9830 if Etype (Call) /= Any_Type then
9835 end Valid_Candidate;
9837 -- Start of processing for Try_Object_Operation
9840 Analyze_Expression (Obj);
9842 -- Analyze the actuals if node is known to be a subprogram call
9844 if Is_Subprg_Call and then N = Name (Parent (N)) then
9845 Actual := First (Parameter_Associations (Parent (N)));
9846 while Present (Actual) loop
9847 Analyze_Expression (Actual);
9852 -- Build a subprogram call node, using a copy of Obj as its first
9853 -- actual. This is a placeholder, to be replaced by an explicit
9854 -- dereference when needed.
9856 Transform_Object_Operation
9857 (Call_Node => New_Call_Node,
9858 Node_To_Replace => Node_To_Replace);
9860 Set_Etype (New_Call_Node, Any_Type);
9861 Set_Etype (Subprog, Any_Type);
9862 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
9864 if not Is_Overloaded (Obj) then
9865 Try_One_Prefix_Interpretation (Obj_Type);
9872 Get_First_Interp (Obj, I, It);
9873 while Present (It.Nam) loop
9874 Try_One_Prefix_Interpretation (It.Typ);
9875 Get_Next_Interp (I, It);
9880 if Etype (New_Call_Node) /= Any_Type then
9882 -- No need to complete the tree transformations if we are only
9883 -- searching for conflicting class-wide subprograms
9885 if CW_Test_Only then
9888 Complete_Object_Operation
9889 (Call_Node => New_Call_Node,
9890 Node_To_Replace => Node_To_Replace);
9894 elsif Present (Candidate) then
9896 -- The argument list is not type correct. Re-analyze with error
9897 -- reporting enabled, and use one of the possible candidates.
9898 -- In All_Errors_Mode, re-analyze all failed interpretations.
9900 if All_Errors_Mode then
9901 Report_Error := True;
9902 if Try_Primitive_Operation
9903 (Call_Node => New_Call_Node,
9904 Node_To_Replace => Node_To_Replace)
9907 Try_Class_Wide_Operation
9908 (Call_Node => New_Call_Node,
9909 Node_To_Replace => Node_To_Replace)
9916 (N => New_Call_Node,
9920 Skip_First => True);
9923 -- No need for further errors
9928 -- There was no candidate operation, so report it as an error
9929 -- in the caller: Analyze_Selected_Component.
9933 end Try_Object_Operation;
9939 procedure wpo (T : Entity_Id) is
9944 if not Is_Tagged_Type (T) then
9948 E := First_Elmt (Primitive_Operations (Base_Type (T)));
9949 while Present (E) loop
9951 Write_Int (Int (Op));
9952 Write_Str (" === ");
9953 Write_Name (Chars (Op));
9955 Write_Name (Chars (Scope (Op)));