1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2019, 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 acccess types.
681 if Expander_Active or else GNATprove_Mode then
682 Def_Id := Make_Temporary (Loc, 'S');
685 Make_Subtype_Declaration (Loc,
686 Defining_Identifier => Def_Id,
687 Subtype_Indication => Relocate_Node (E)));
689 if Sav_Errs /= Serious_Errors_Detected
690 and then Nkind (Constraint (E)) =
691 N_Index_Or_Discriminant_Constraint
693 Error_Msg_N -- CODEFIX
694 ("if qualified expression was meant, "
695 & "use apostrophe!", Constraint (E));
698 E := New_Occurrence_Of (Def_Id, Loc);
699 Rewrite (Expression (N), E);
703 Type_Id := Process_Subtype (E, N);
704 Acc_Type := Create_Itype (E_Allocator_Type, N);
705 Set_Etype (Acc_Type, Acc_Type);
706 Set_Directly_Designated_Type (Acc_Type, Type_Id);
707 Check_Fully_Declared (Type_Id, N);
709 -- Ada 2005 (AI-231): If the designated type is itself an access
710 -- type that excludes null, its default initialization will
711 -- be a null object, and we can insert an unconditional raise
712 -- before the allocator.
714 -- Ada 2012 (AI-104): A not null indication here is altogether
717 if Can_Never_Be_Null (Type_Id) then
719 Not_Null_Check : constant Node_Id :=
720 Make_Raise_Constraint_Error (Sloc (E),
721 Reason => CE_Null_Not_Allowed);
724 if Expander_Active then
725 Insert_Action (N, Not_Null_Check);
726 Analyze (Not_Null_Check);
728 elsif Warn_On_Ada_2012_Compatibility then
730 ("null value not allowed here in Ada 2012?y?", E);
735 -- Check for missing initialization. Skip this check if we already
736 -- had errors on analyzing the allocator, since in that case these
737 -- are probably cascaded errors.
739 if not Is_Definite_Subtype (Type_Id)
740 and then Serious_Errors_Detected = Sav_Errs
742 -- The build-in-place machinery may produce an allocator when
743 -- the designated type is indefinite but the underlying type is
744 -- not. In this case the unknown discriminants are meaningless
745 -- and should not trigger error messages. Check the parent node
746 -- because the allocator is marked as coming from source.
748 if Present (Underlying_Type (Type_Id))
749 and then Is_Definite_Subtype (Underlying_Type (Type_Id))
750 and then not Comes_From_Source (Parent (N))
754 -- An unusual case arises when the parent of a derived type is
755 -- a limited record extension with unknown discriminants, and
756 -- its full view has no discriminants.
758 -- A more general fix might be to create the proper underlying
759 -- type for such a derived type, but it is a record type with
760 -- no private attributes, so this required extending the
761 -- meaning of this attribute. ???
763 elsif Ekind (Etype (Type_Id)) = E_Record_Type_With_Private
764 and then Present (Underlying_Type (Etype (Type_Id)))
766 not Has_Discriminants (Underlying_Type (Etype (Type_Id)))
767 and then not Comes_From_Source (Parent (N))
771 elsif Is_Class_Wide_Type (Type_Id) then
773 ("initialization required in class-wide allocation", N);
776 if Ada_Version < Ada_2005
777 and then Is_Limited_Type (Type_Id)
779 Error_Msg_N ("unconstrained allocation not allowed", N);
781 if Is_Array_Type (Type_Id) then
783 ("\constraint with array bounds required", N);
785 elsif Has_Unknown_Discriminants (Type_Id) then
788 else pragma Assert (Has_Discriminants (Type_Id));
790 ("\constraint with discriminant values required", N);
793 -- Limited Ada 2005 and general nonlimited case
797 ("uninitialized unconstrained allocation not "
800 if Is_Array_Type (Type_Id) then
802 ("\qualified expression or constraint with "
803 & "array bounds required", N);
805 elsif Has_Unknown_Discriminants (Type_Id) then
806 Error_Msg_N ("\qualified expression required", N);
808 else pragma Assert (Has_Discriminants (Type_Id));
810 ("\qualified expression or constraint with "
811 & "discriminant values required", N);
819 if Is_Abstract_Type (Type_Id) then
820 Error_Msg_N ("cannot allocate abstract object", E);
823 if Has_Task (Designated_Type (Acc_Type)) then
824 Check_Restriction (No_Tasking, N);
825 Check_Restriction (Max_Tasks, N);
826 Check_Restriction (No_Task_Allocators, N);
829 -- Check restriction against dynamically allocated protected objects
831 if Has_Protected (Designated_Type (Acc_Type)) then
832 Check_Restriction (No_Protected_Type_Allocators, N);
835 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
836 -- type is nested, and the designated type needs finalization. The rule
837 -- is conservative in that class-wide types need finalization.
839 if Needs_Finalization (Designated_Type (Acc_Type))
840 and then not Is_Library_Level_Entity (Acc_Type)
842 Check_Restriction (No_Nested_Finalization, N);
845 -- Check that an allocator of a nested access type doesn't create a
846 -- protected object when restriction No_Local_Protected_Objects applies.
848 if Has_Protected (Designated_Type (Acc_Type))
849 and then not Is_Library_Level_Entity (Acc_Type)
851 Check_Restriction (No_Local_Protected_Objects, N);
854 -- Likewise for No_Local_Timing_Events
856 if Has_Timing_Event (Designated_Type (Acc_Type))
857 and then not Is_Library_Level_Entity (Acc_Type)
859 Check_Restriction (No_Local_Timing_Events, N);
862 -- If the No_Streams restriction is set, check that the type of the
863 -- object is not, and does not contain, any subtype derived from
864 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
865 -- Has_Stream just for efficiency reasons. There is no point in
866 -- spending time on a Has_Stream check if the restriction is not set.
868 if Restriction_Check_Required (No_Streams) then
869 if Has_Stream (Designated_Type (Acc_Type)) then
870 Check_Restriction (No_Streams, N);
874 Set_Etype (N, Acc_Type);
876 if not Is_Library_Level_Entity (Acc_Type) then
877 Check_Restriction (No_Local_Allocators, N);
880 if Serious_Errors_Detected > Sav_Errs then
881 Set_Error_Posted (N);
882 Set_Etype (N, Any_Type);
884 end Analyze_Allocator;
886 ---------------------------
887 -- Analyze_Arithmetic_Op --
888 ---------------------------
890 procedure Analyze_Arithmetic_Op (N : Node_Id) is
891 L : constant Node_Id := Left_Opnd (N);
892 R : constant Node_Id := Right_Opnd (N);
896 Candidate_Type := Empty;
897 Analyze_Expression (L);
898 Analyze_Expression (R);
900 -- If the entity is already set, the node is the instantiation of a
901 -- generic node with a non-local reference, or was manufactured by a
902 -- call to Make_Op_xxx. In either case the entity is known to be valid,
903 -- and we do not need to collect interpretations, instead we just get
904 -- the single possible interpretation.
908 if Present (Op_Id) then
909 if Ekind (Op_Id) = E_Operator then
911 if Nkind_In (N, N_Op_Divide, N_Op_Mod, N_Op_Multiply, N_Op_Rem)
912 and then Treat_Fixed_As_Integer (N)
916 Set_Etype (N, Any_Type);
917 Find_Arithmetic_Types (L, R, Op_Id, N);
921 Set_Etype (N, Any_Type);
922 Add_One_Interp (N, Op_Id, Etype (Op_Id));
925 -- Entity is not already set, so we do need to collect interpretations
928 Set_Etype (N, Any_Type);
930 Op_Id := Get_Name_Entity_Id (Chars (N));
931 while Present (Op_Id) loop
932 if Ekind (Op_Id) = E_Operator
933 and then Present (Next_Entity (First_Entity (Op_Id)))
935 Find_Arithmetic_Types (L, R, Op_Id, N);
937 -- The following may seem superfluous, because an operator cannot
938 -- be generic, but this ignores the cleverness of the author of
941 elsif Is_Overloadable (Op_Id) then
942 Analyze_User_Defined_Binary_Op (N, Op_Id);
945 Op_Id := Homonym (Op_Id);
950 Check_Function_Writable_Actuals (N);
951 end Analyze_Arithmetic_Op;
957 -- Function, procedure, and entry calls are checked here. The Name in
958 -- the call may be overloaded. The actuals have been analyzed and may
959 -- themselves be overloaded. On exit from this procedure, the node N
960 -- may have zero, one or more interpretations. In the first case an
961 -- error message is produced. In the last case, the node is flagged
962 -- as overloaded and the interpretations are collected in All_Interp.
964 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
965 -- the type-checking is similar to that of other calls.
967 procedure Analyze_Call (N : Node_Id) is
968 Actuals : constant List_Id := Parameter_Associations (N);
969 Loc : constant Source_Ptr := Sloc (N);
974 Success : Boolean := False;
976 Deref : Boolean := False;
977 -- Flag indicates whether an interpretation of the prefix is a
978 -- parameterless call that returns an access_to_subprogram.
980 procedure Check_Mixed_Parameter_And_Named_Associations;
981 -- Check that parameter and named associations are not mixed. This is
982 -- a restriction in SPARK mode.
984 procedure Check_Writable_Actuals (N : Node_Id);
985 -- If the call has out or in-out parameters then mark its outermost
986 -- enclosing construct as a node on which the writable actuals check
987 -- must be performed.
989 function Name_Denotes_Function return Boolean;
990 -- If the type of the name is an access to subprogram, this may be the
991 -- type of a name, or the return type of the function being called. If
992 -- the name is not an entity then it can denote a protected function.
993 -- Until we distinguish Etype from Return_Type, we must use this routine
994 -- to resolve the meaning of the name in the call.
996 procedure No_Interpretation;
997 -- Output error message when no valid interpretation exists
999 --------------------------------------------------
1000 -- Check_Mixed_Parameter_And_Named_Associations --
1001 --------------------------------------------------
1003 procedure Check_Mixed_Parameter_And_Named_Associations is
1005 Named_Seen : Boolean;
1008 Named_Seen := False;
1010 Actual := First (Actuals);
1011 while Present (Actual) loop
1012 case Nkind (Actual) is
1013 when N_Parameter_Association =>
1015 Check_SPARK_05_Restriction
1016 ("named association cannot follow positional one",
1027 end Check_Mixed_Parameter_And_Named_Associations;
1029 ----------------------------
1030 -- Check_Writable_Actuals --
1031 ----------------------------
1033 -- The identification of conflicts in calls to functions with writable
1034 -- actuals is performed in the analysis phase of the front end to ensure
1035 -- that it reports exactly the same errors compiling with and without
1036 -- expansion enabled. It is performed in two stages:
1038 -- 1) When a call to a function with out-mode parameters is found,
1039 -- we climb to the outermost enclosing construct that can be
1040 -- evaluated in arbitrary order and we mark it with the flag
1043 -- 2) When the analysis of the marked node is complete, we traverse
1044 -- its decorated subtree searching for conflicts (see function
1045 -- Sem_Util.Check_Function_Writable_Actuals).
1047 -- The unique exception to this general rule is for aggregates, since
1048 -- their analysis is performed by the front end in the resolution
1049 -- phase. For aggregates we do not climb to their enclosing construct:
1050 -- we restrict the analysis to the subexpressions initializing the
1051 -- aggregate components.
1053 -- This implies that the analysis of expressions containing aggregates
1054 -- is not complete, since there may be conflicts on writable actuals
1055 -- involving subexpressions of the enclosing logical or arithmetic
1056 -- expressions. However, we cannot wait and perform the analysis when
1057 -- the whole subtree is resolved, since the subtrees may be transformed,
1058 -- thus adding extra complexity and computation cost to identify and
1059 -- report exactly the same errors compiling with and without expansion
1062 procedure Check_Writable_Actuals (N : Node_Id) is
1064 if Comes_From_Source (N)
1065 and then Present (Get_Subprogram_Entity (N))
1066 and then Has_Out_Or_In_Out_Parameter (Get_Subprogram_Entity (N))
1068 -- For procedures and entries there is no need to climb since
1069 -- we only need to check if the actuals of this call invoke
1070 -- functions whose out-mode parameters overlap.
1072 if Nkind (N) /= N_Function_Call then
1073 Set_Check_Actuals (N);
1075 -- For calls to functions we climb to the outermost enclosing
1076 -- construct where the out-mode actuals of this function may
1077 -- introduce conflicts.
1081 Outermost : Node_Id := Empty; -- init to avoid warning
1085 while Present (P) loop
1086 -- For object declarations we can climb to the node from
1087 -- its object definition branch or from its initializing
1088 -- expression. We prefer to mark the child node as the
1089 -- outermost construct to avoid adding further complexity
1090 -- to the routine that will later take care of
1091 -- performing the writable actuals check.
1093 if Has_Arbitrary_Evaluation_Order (Nkind (P))
1094 and then not Nkind_In (P, N_Assignment_Statement,
1095 N_Object_Declaration)
1100 -- Avoid climbing more than needed
1102 exit when Stop_Subtree_Climbing (Nkind (P))
1103 or else (Nkind (P) = N_Range
1105 Nkind_In (Parent (P), N_In, N_Not_In));
1110 Set_Check_Actuals (Outermost);
1114 end Check_Writable_Actuals;
1116 ---------------------------
1117 -- Name_Denotes_Function --
1118 ---------------------------
1120 function Name_Denotes_Function return Boolean is
1122 if Is_Entity_Name (Nam) then
1123 return Ekind (Entity (Nam)) = E_Function;
1124 elsif Nkind (Nam) = N_Selected_Component then
1125 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
1129 end Name_Denotes_Function;
1131 -----------------------
1132 -- No_Interpretation --
1133 -----------------------
1135 procedure No_Interpretation is
1136 L : constant Boolean := Is_List_Member (N);
1137 K : constant Node_Kind := Nkind (Parent (N));
1140 -- If the node is in a list whose parent is not an expression then it
1141 -- must be an attempted procedure call.
1143 if L and then K not in N_Subexpr then
1144 if Ekind (Entity (Nam)) = E_Generic_Procedure then
1146 ("must instantiate generic procedure& before call",
1149 Error_Msg_N ("procedure or entry name expected", Nam);
1152 -- Check for tasking cases where only an entry call will do
1155 and then Nkind_In (K, N_Entry_Call_Alternative,
1156 N_Triggering_Alternative)
1158 Error_Msg_N ("entry name expected", Nam);
1160 -- Otherwise give general error message
1163 Error_Msg_N ("invalid prefix in call", Nam);
1165 end No_Interpretation;
1167 -- Start of processing for Analyze_Call
1170 if Restriction_Check_Required (SPARK_05) then
1171 Check_Mixed_Parameter_And_Named_Associations;
1174 -- Initialize the type of the result of the call to the error type,
1175 -- which will be reset if the type is successfully resolved.
1177 Set_Etype (N, Any_Type);
1181 if not Is_Overloaded (Nam) then
1183 -- Only one interpretation to check
1185 if Ekind (Etype (Nam)) = E_Subprogram_Type then
1186 Nam_Ent := Etype (Nam);
1188 -- If the prefix is an access_to_subprogram, this may be an indirect
1189 -- call. This is the case if the name in the call is not an entity
1190 -- name, or if it is a function name in the context of a procedure
1191 -- call. In this latter case, we have a call to a parameterless
1192 -- function that returns a pointer_to_procedure which is the entity
1193 -- being called. Finally, F (X) may be a call to a parameterless
1194 -- function that returns a pointer to a function with parameters.
1195 -- Note that if F returns an access-to-subprogram whose designated
1196 -- type is an array, F (X) cannot be interpreted as an indirect call
1197 -- through the result of the call to F.
1199 elsif Is_Access_Type (Etype (Nam))
1200 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
1202 (not Name_Denotes_Function
1203 or else Nkind (N) = N_Procedure_Call_Statement
1205 (Nkind (Parent (N)) /= N_Explicit_Dereference
1206 and then Is_Entity_Name (Nam)
1207 and then No (First_Formal (Entity (Nam)))
1209 Is_Array_Type (Etype (Designated_Type (Etype (Nam))))
1210 and then Present (Actuals)))
1212 Nam_Ent := Designated_Type (Etype (Nam));
1213 Insert_Explicit_Dereference (Nam);
1215 -- Selected component case. Simple entry or protected operation,
1216 -- where the entry name is given by the selector name.
1218 elsif Nkind (Nam) = N_Selected_Component then
1219 Nam_Ent := Entity (Selector_Name (Nam));
1221 if not Ekind_In (Nam_Ent, E_Entry,
1226 Error_Msg_N ("name in call is not a callable entity", Nam);
1227 Set_Etype (N, Any_Type);
1231 -- If the name is an Indexed component, it can be a call to a member
1232 -- of an entry family. The prefix must be a selected component whose
1233 -- selector is the entry. Analyze_Procedure_Call normalizes several
1234 -- kinds of call into this form.
1236 elsif Nkind (Nam) = N_Indexed_Component then
1237 if Nkind (Prefix (Nam)) = N_Selected_Component then
1238 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
1240 Error_Msg_N ("name in call is not a callable entity", Nam);
1241 Set_Etype (N, Any_Type);
1245 elsif not Is_Entity_Name (Nam) then
1246 Error_Msg_N ("name in call is not a callable entity", Nam);
1247 Set_Etype (N, Any_Type);
1251 Nam_Ent := Entity (Nam);
1253 -- If not overloadable, this may be a generalized indexing
1254 -- operation with named associations. Rewrite again as an
1255 -- indexed component and analyze as container indexing.
1257 if not Is_Overloadable (Nam_Ent) then
1259 (Find_Value_Of_Aspect
1260 (Etype (Nam_Ent), Aspect_Constant_Indexing))
1263 Make_Indexed_Component (Sloc (N),
1265 Expressions => Parameter_Associations (N)));
1267 if Try_Container_Indexing (N, Nam, Expressions (N)) then
1281 -- Operations generated for RACW stub types are called only through
1282 -- dispatching, and can never be the static interpretation of a call.
1284 if Is_RACW_Stub_Type_Operation (Nam_Ent) then
1289 Analyze_One_Call (N, Nam_Ent, True, Success);
1291 -- If this is an indirect call, the return type of the access_to
1292 -- subprogram may be an incomplete type. At the point of the call,
1293 -- use the full type if available, and at the same time update the
1294 -- return type of the access_to_subprogram.
1297 and then Nkind (Nam) = N_Explicit_Dereference
1298 and then Ekind (Etype (N)) = E_Incomplete_Type
1299 and then Present (Full_View (Etype (N)))
1301 Set_Etype (N, Full_View (Etype (N)));
1302 Set_Etype (Nam_Ent, Etype (N));
1308 -- An overloaded selected component must denote overloaded operations
1309 -- of a concurrent type. The interpretations are attached to the
1310 -- simple name of those operations.
1312 if Nkind (Nam) = N_Selected_Component then
1313 Nam := Selector_Name (Nam);
1316 Get_First_Interp (Nam, X, It);
1317 while Present (It.Nam) loop
1321 -- Name may be call that returns an access to subprogram, or more
1322 -- generally an overloaded expression one of whose interpretations
1323 -- yields an access to subprogram. If the name is an entity, we do
1324 -- not dereference, because the node is a call that returns the
1325 -- access type: note difference between f(x), where the call may
1326 -- return an access subprogram type, and f(x)(y), where the type
1327 -- returned by the call to f is implicitly dereferenced to analyze
1330 if Is_Access_Type (Nam_Ent) then
1331 Nam_Ent := Designated_Type (Nam_Ent);
1333 elsif Is_Access_Type (Etype (Nam_Ent))
1335 (not Is_Entity_Name (Nam)
1336 or else Nkind (N) = N_Procedure_Call_Statement)
1337 and then Ekind (Designated_Type (Etype (Nam_Ent)))
1340 Nam_Ent := Designated_Type (Etype (Nam_Ent));
1342 if Is_Entity_Name (Nam) then
1347 -- If the call has been rewritten from a prefixed call, the first
1348 -- parameter has been analyzed, but may need a subsequent
1349 -- dereference, so skip its analysis now.
1351 if Is_Rewrite_Substitution (N)
1352 and then Nkind (Original_Node (N)) = Nkind (N)
1353 and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N)))
1354 and then Present (Parameter_Associations (N))
1355 and then Present (Etype (First (Parameter_Associations (N))))
1358 (N, Nam_Ent, False, Success, Skip_First => True);
1360 Analyze_One_Call (N, Nam_Ent, False, Success);
1363 -- If the interpretation succeeds, mark the proper type of the
1364 -- prefix (any valid candidate will do). If not, remove the
1365 -- candidate interpretation. If this is a parameterless call
1366 -- on an anonymous access to subprogram, X is a variable with
1367 -- an access discriminant D, the entity in the interpretation is
1368 -- D, so rewrite X as X.D.all.
1372 and then Nkind (Parent (N)) /= N_Explicit_Dereference
1374 if Ekind (It.Nam) = E_Discriminant
1375 and then Has_Implicit_Dereference (It.Nam)
1378 Make_Explicit_Dereference (Loc,
1380 Make_Selected_Component (Loc,
1382 New_Occurrence_Of (Entity (Nam), Loc),
1384 New_Occurrence_Of (It.Nam, Loc))));
1390 Set_Entity (Nam, It.Nam);
1391 Insert_Explicit_Dereference (Nam);
1392 Set_Etype (Nam, Nam_Ent);
1396 Set_Etype (Nam, It.Typ);
1399 elsif Nkind_In (Name (N), N_Function_Call, N_Selected_Component)
1404 Get_Next_Interp (X, It);
1407 -- If the name is the result of a function call, it can only be a
1408 -- call to a function returning an access to subprogram. Insert
1409 -- explicit dereference.
1411 if Nkind (Nam) = N_Function_Call then
1412 Insert_Explicit_Dereference (Nam);
1415 if Etype (N) = Any_Type then
1417 -- None of the interpretations is compatible with the actuals
1419 Diagnose_Call (N, Nam);
1421 -- Special checks for uninstantiated put routines
1423 if Nkind (N) = N_Procedure_Call_Statement
1424 and then Is_Entity_Name (Nam)
1425 and then Chars (Nam) = Name_Put
1426 and then List_Length (Actuals) = 1
1429 Arg : constant Node_Id := First (Actuals);
1433 if Nkind (Arg) = N_Parameter_Association then
1434 Typ := Etype (Explicit_Actual_Parameter (Arg));
1439 if Is_Signed_Integer_Type (Typ) then
1441 ("possible missing instantiation of "
1442 & "'Text_'I'O.'Integer_'I'O!", Nam);
1444 elsif Is_Modular_Integer_Type (Typ) then
1446 ("possible missing instantiation of "
1447 & "'Text_'I'O.'Modular_'I'O!", Nam);
1449 elsif Is_Floating_Point_Type (Typ) then
1451 ("possible missing instantiation of "
1452 & "'Text_'I'O.'Float_'I'O!", Nam);
1454 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
1456 ("possible missing instantiation of "
1457 & "'Text_'I'O.'Fixed_'I'O!", Nam);
1459 elsif Is_Decimal_Fixed_Point_Type (Typ) then
1461 ("possible missing instantiation of "
1462 & "'Text_'I'O.'Decimal_'I'O!", Nam);
1464 elsif Is_Enumeration_Type (Typ) then
1466 ("possible missing instantiation of "
1467 & "'Text_'I'O.'Enumeration_'I'O!", Nam);
1472 elsif not Is_Overloaded (N)
1473 and then Is_Entity_Name (Nam)
1475 -- Resolution yields a single interpretation. Verify that the
1476 -- reference has capitalization consistent with the declaration.
1478 Set_Entity_With_Checks (Nam, Entity (Nam));
1479 Generate_Reference (Entity (Nam), Nam);
1481 Set_Etype (Nam, Etype (Entity (Nam)));
1483 Remove_Abstract_Operations (N);
1489 if Ada_Version >= Ada_2012 then
1491 -- Check if the call contains a function with writable actuals
1493 Check_Writable_Actuals (N);
1495 -- If found and the outermost construct that can be evaluated in
1496 -- an arbitrary order is precisely this call, then check all its
1499 Check_Function_Writable_Actuals (N);
1501 -- The return type of the function may be incomplete. This can be
1502 -- the case if the type is a generic formal, or a limited view. It
1503 -- can also happen when the function declaration appears before the
1504 -- full view of the type (which is legal in Ada 2012) and the call
1505 -- appears in a different unit, in which case the incomplete view
1506 -- must be replaced with the full view (or the nonlimited view)
1507 -- to prevent subsequent type errors. Note that the usual install/
1508 -- removal of limited_with clauses is not sufficient to handle this
1509 -- case, because the limited view may have been captured in another
1510 -- compilation unit that defines the current function.
1512 if Is_Incomplete_Type (Etype (N)) then
1513 if Present (Full_View (Etype (N))) then
1514 if Is_Entity_Name (Nam) then
1515 Set_Etype (Nam, Full_View (Etype (N)));
1516 Set_Etype (Entity (Nam), Full_View (Etype (N)));
1519 Set_Etype (N, Full_View (Etype (N)));
1521 elsif From_Limited_With (Etype (N))
1522 and then Present (Non_Limited_View (Etype (N)))
1524 Set_Etype (N, Non_Limited_View (Etype (N)));
1526 -- If there is no completion for the type, this may be because
1527 -- there is only a limited view of it and there is nothing in
1528 -- the context of the current unit that has required a regular
1529 -- compilation of the unit containing the type. We recognize
1530 -- this unusual case by the fact that that unit is not analyzed.
1531 -- Note that the call being analyzed is in a different unit from
1532 -- the function declaration, and nothing indicates that the type
1533 -- is a limited view.
1535 elsif Ekind (Scope (Etype (N))) = E_Package
1536 and then Present (Limited_View (Scope (Etype (N))))
1537 and then not Analyzed (Unit_Declaration_Node (Scope (Etype (N))))
1540 ("cannot call function that returns limited view of}",
1544 ("\there must be a regular with_clause for package & in the "
1545 & "current unit, or in some unit in its context",
1546 N, Scope (Etype (N)));
1548 Set_Etype (N, Any_Type);
1554 -----------------------------
1555 -- Analyze_Case_Expression --
1556 -----------------------------
1558 procedure Analyze_Case_Expression (N : Node_Id) is
1559 procedure Non_Static_Choice_Error (Choice : Node_Id);
1560 -- Error routine invoked by the generic instantiation below when
1561 -- the case expression has a non static choice.
1563 package Case_Choices_Analysis is new
1564 Generic_Analyze_Choices
1565 (Process_Associated_Node => No_OP);
1566 use Case_Choices_Analysis;
1568 package Case_Choices_Checking is new
1569 Generic_Check_Choices
1570 (Process_Empty_Choice => No_OP,
1571 Process_Non_Static_Choice => Non_Static_Choice_Error,
1572 Process_Associated_Node => No_OP);
1573 use Case_Choices_Checking;
1575 -----------------------------
1576 -- Non_Static_Choice_Error --
1577 -----------------------------
1579 procedure Non_Static_Choice_Error (Choice : Node_Id) is
1581 Flag_Non_Static_Expr
1582 ("choice given in case expression is not static!", Choice);
1583 end Non_Static_Choice_Error;
1587 Expr : constant Node_Id := Expression (N);
1589 Exp_Type : Entity_Id;
1590 Exp_Btype : Entity_Id;
1592 FirstX : Node_Id := Empty;
1593 -- First expression in the case for which there is some type information
1594 -- available, i.e. it is not Any_Type, which can happen because of some
1595 -- error, or from the use of e.g. raise Constraint_Error.
1597 Others_Present : Boolean;
1598 -- Indicates if Others was present
1600 Wrong_Alt : Node_Id := Empty;
1601 -- For error reporting
1603 -- Start of processing for Analyze_Case_Expression
1606 if Comes_From_Source (N) then
1607 Check_Compiler_Unit ("case expression", N);
1610 Analyze_And_Resolve (Expr, Any_Discrete);
1611 Check_Unset_Reference (Expr);
1612 Exp_Type := Etype (Expr);
1613 Exp_Btype := Base_Type (Exp_Type);
1615 Alt := First (Alternatives (N));
1616 while Present (Alt) loop
1617 if Error_Posted (Expression (Alt)) then
1621 Analyze (Expression (Alt));
1623 if No (FirstX) and then Etype (Expression (Alt)) /= Any_Type then
1624 FirstX := Expression (Alt);
1630 -- Get our initial type from the first expression for which we got some
1631 -- useful type information from the expression.
1637 if not Is_Overloaded (FirstX) then
1638 Set_Etype (N, Etype (FirstX));
1646 Set_Etype (N, Any_Type);
1648 Get_First_Interp (FirstX, I, It);
1649 while Present (It.Nam) loop
1651 -- For each interpretation of the first expression, we only
1652 -- add the interpretation if every other expression in the
1653 -- case expression alternatives has a compatible type.
1655 Alt := Next (First (Alternatives (N)));
1656 while Present (Alt) loop
1657 exit when not Has_Compatible_Type (Expression (Alt), It.Typ);
1662 Add_One_Interp (N, It.Typ, It.Typ);
1667 Get_Next_Interp (I, It);
1672 Exp_Btype := Base_Type (Exp_Type);
1674 -- The expression must be of a discrete type which must be determinable
1675 -- independently of the context in which the expression occurs, but
1676 -- using the fact that the expression must be of a discrete type.
1677 -- Moreover, the type this expression must not be a character literal
1678 -- (which is always ambiguous).
1680 -- If error already reported by Resolve, nothing more to do
1682 if Exp_Btype = Any_Discrete or else Exp_Btype = Any_Type then
1685 -- Special casee message for character literal
1687 elsif Exp_Btype = Any_Character then
1689 ("character literal as case expression is ambiguous", Expr);
1693 if Etype (N) = Any_Type and then Present (Wrong_Alt) then
1695 ("type incompatible with that of previous alternatives",
1696 Expression (Wrong_Alt));
1700 -- If the case expression is a formal object of mode in out, then
1701 -- treat it as having a nonstatic subtype by forcing use of the base
1702 -- type (which has to get passed to Check_Case_Choices below). Also
1703 -- use base type when the case expression is parenthesized.
1705 if Paren_Count (Expr) > 0
1706 or else (Is_Entity_Name (Expr)
1707 and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter)
1709 Exp_Type := Exp_Btype;
1712 -- The case expression alternatives cover the range of a static subtype
1713 -- subject to aspect Static_Predicate. Do not check the choices when the
1714 -- case expression has not been fully analyzed yet because this may lead
1717 if Is_OK_Static_Subtype (Exp_Type)
1718 and then Has_Static_Predicate_Aspect (Exp_Type)
1719 and then In_Spec_Expression
1723 -- Call Analyze_Choices and Check_Choices to do the rest of the work
1726 Analyze_Choices (Alternatives (N), Exp_Type);
1727 Check_Choices (N, Alternatives (N), Exp_Type, Others_Present);
1729 if Exp_Type = Universal_Integer and then not Others_Present then
1731 ("case on universal integer requires OTHERS choice", Expr);
1734 end Analyze_Case_Expression;
1736 ---------------------------
1737 -- Analyze_Comparison_Op --
1738 ---------------------------
1740 procedure Analyze_Comparison_Op (N : Node_Id) is
1741 L : constant Node_Id := Left_Opnd (N);
1742 R : constant Node_Id := Right_Opnd (N);
1743 Op_Id : Entity_Id := Entity (N);
1746 Set_Etype (N, Any_Type);
1747 Candidate_Type := Empty;
1749 Analyze_Expression (L);
1750 Analyze_Expression (R);
1752 if Present (Op_Id) then
1753 if Ekind (Op_Id) = E_Operator then
1754 Find_Comparison_Types (L, R, Op_Id, N);
1756 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1759 if Is_Overloaded (L) then
1760 Set_Etype (L, Intersect_Types (L, R));
1764 Op_Id := Get_Name_Entity_Id (Chars (N));
1765 while Present (Op_Id) loop
1766 if Ekind (Op_Id) = E_Operator then
1767 Find_Comparison_Types (L, R, Op_Id, N);
1769 Analyze_User_Defined_Binary_Op (N, Op_Id);
1772 Op_Id := Homonym (Op_Id);
1777 Check_Function_Writable_Actuals (N);
1778 end Analyze_Comparison_Op;
1780 ---------------------------
1781 -- Analyze_Concatenation --
1782 ---------------------------
1784 procedure Analyze_Concatenation (N : Node_Id) is
1786 -- We wish to avoid deep recursion, because concatenations are often
1787 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1788 -- operands nonrecursively until we find something that is not a
1789 -- concatenation (A in this case), or has already been analyzed. We
1790 -- analyze that, and then walk back up the tree following Parent
1791 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1792 -- work at each level. The Parent pointers allow us to avoid recursion,
1793 -- and thus avoid running out of memory.
1799 Candidate_Type := Empty;
1801 -- The following code is equivalent to:
1803 -- Set_Etype (N, Any_Type);
1804 -- Analyze_Expression (Left_Opnd (N));
1805 -- Analyze_Concatenation_Rest (N);
1807 -- where the Analyze_Expression call recurses back here if the left
1808 -- operand is a concatenation.
1810 -- Walk down left operands
1813 Set_Etype (NN, Any_Type);
1814 L := Left_Opnd (NN);
1815 exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
1819 -- Now (given the above example) NN is A&B and L is A
1821 -- First analyze L ...
1823 Analyze_Expression (L);
1825 -- ... then walk NN back up until we reach N (where we started), calling
1826 -- Analyze_Concatenation_Rest along the way.
1829 Analyze_Concatenation_Rest (NN);
1833 end Analyze_Concatenation;
1835 --------------------------------
1836 -- Analyze_Concatenation_Rest --
1837 --------------------------------
1839 -- If the only one-dimensional array type in scope is String,
1840 -- this is the resulting type of the operation. Otherwise there
1841 -- will be a concatenation operation defined for each user-defined
1842 -- one-dimensional array.
1844 procedure Analyze_Concatenation_Rest (N : Node_Id) is
1845 L : constant Node_Id := Left_Opnd (N);
1846 R : constant Node_Id := Right_Opnd (N);
1847 Op_Id : Entity_Id := Entity (N);
1852 Analyze_Expression (R);
1854 -- If the entity is present, the node appears in an instance, and
1855 -- denotes a predefined concatenation operation. The resulting type is
1856 -- obtained from the arguments when possible. If the arguments are
1857 -- aggregates, the array type and the concatenation type must be
1860 if Present (Op_Id) then
1861 if Ekind (Op_Id) = E_Operator then
1862 LT := Base_Type (Etype (L));
1863 RT := Base_Type (Etype (R));
1865 if Is_Array_Type (LT)
1866 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1868 Add_One_Interp (N, Op_Id, LT);
1870 elsif Is_Array_Type (RT)
1871 and then LT = Base_Type (Component_Type (RT))
1873 Add_One_Interp (N, Op_Id, RT);
1875 -- If one operand is a string type or a user-defined array type,
1876 -- and the other is a literal, result is of the specific type.
1879 (Root_Type (LT) = Standard_String
1880 or else Scope (LT) /= Standard_Standard)
1881 and then Etype (R) = Any_String
1883 Add_One_Interp (N, Op_Id, LT);
1886 (Root_Type (RT) = Standard_String
1887 or else Scope (RT) /= Standard_Standard)
1888 and then Etype (L) = Any_String
1890 Add_One_Interp (N, Op_Id, RT);
1892 elsif not Is_Generic_Type (Etype (Op_Id)) then
1893 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1896 -- Type and its operations must be visible
1898 Set_Entity (N, Empty);
1899 Analyze_Concatenation (N);
1903 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1907 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1908 while Present (Op_Id) loop
1909 if Ekind (Op_Id) = E_Operator then
1911 -- Do not consider operators declared in dead code, they
1912 -- cannot be part of the resolution.
1914 if Is_Eliminated (Op_Id) then
1917 Find_Concatenation_Types (L, R, Op_Id, N);
1921 Analyze_User_Defined_Binary_Op (N, Op_Id);
1924 Op_Id := Homonym (Op_Id);
1929 end Analyze_Concatenation_Rest;
1931 -------------------------
1932 -- Analyze_Equality_Op --
1933 -------------------------
1935 procedure Analyze_Equality_Op (N : Node_Id) is
1936 Loc : constant Source_Ptr := Sloc (N);
1937 L : constant Node_Id := Left_Opnd (N);
1938 R : constant Node_Id := Right_Opnd (N);
1942 Set_Etype (N, Any_Type);
1943 Candidate_Type := Empty;
1945 Analyze_Expression (L);
1946 Analyze_Expression (R);
1948 -- If the entity is set, the node is a generic instance with a non-local
1949 -- reference to the predefined operator or to a user-defined function.
1950 -- It can also be an inequality that is expanded into the negation of a
1951 -- call to a user-defined equality operator.
1953 -- For the predefined case, the result is Boolean, regardless of the
1954 -- type of the operands. The operands may even be limited, if they are
1955 -- generic actuals. If they are overloaded, label the left argument with
1956 -- the common type that must be present, or with the type of the formal
1957 -- of the user-defined function.
1959 if Present (Entity (N)) then
1960 Op_Id := Entity (N);
1962 if Ekind (Op_Id) = E_Operator then
1963 Add_One_Interp (N, Op_Id, Standard_Boolean);
1965 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1968 if Is_Overloaded (L) then
1969 if Ekind (Op_Id) = E_Operator then
1970 Set_Etype (L, Intersect_Types (L, R));
1972 Set_Etype (L, Etype (First_Formal (Op_Id)));
1977 Op_Id := Get_Name_Entity_Id (Chars (N));
1978 while Present (Op_Id) loop
1979 if Ekind (Op_Id) = E_Operator then
1980 Find_Equality_Types (L, R, Op_Id, N);
1982 Analyze_User_Defined_Binary_Op (N, Op_Id);
1985 Op_Id := Homonym (Op_Id);
1989 -- If there was no match, and the operator is inequality, this may be
1990 -- a case where inequality has not been made explicit, as for tagged
1991 -- types. Analyze the node as the negation of an equality operation.
1992 -- This cannot be done earlier, because before analysis we cannot rule
1993 -- out the presence of an explicit inequality.
1995 if Etype (N) = Any_Type
1996 and then Nkind (N) = N_Op_Ne
1998 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1999 while Present (Op_Id) loop
2000 if Ekind (Op_Id) = E_Operator then
2001 Find_Equality_Types (L, R, Op_Id, N);
2003 Analyze_User_Defined_Binary_Op (N, Op_Id);
2006 Op_Id := Homonym (Op_Id);
2009 if Etype (N) /= Any_Type then
2010 Op_Id := Entity (N);
2016 Left_Opnd => Left_Opnd (N),
2017 Right_Opnd => Right_Opnd (N))));
2019 Set_Entity (Right_Opnd (N), Op_Id);
2025 Check_Function_Writable_Actuals (N);
2026 end Analyze_Equality_Op;
2028 ----------------------------------
2029 -- Analyze_Explicit_Dereference --
2030 ----------------------------------
2032 procedure Analyze_Explicit_Dereference (N : Node_Id) is
2033 Loc : constant Source_Ptr := Sloc (N);
2034 P : constant Node_Id := Prefix (N);
2040 function Is_Function_Type return Boolean;
2041 -- Check whether node may be interpreted as an implicit function call
2043 ----------------------
2044 -- Is_Function_Type --
2045 ----------------------
2047 function Is_Function_Type return Boolean is
2052 if not Is_Overloaded (N) then
2053 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
2054 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
2057 Get_First_Interp (N, I, It);
2058 while Present (It.Nam) loop
2059 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
2060 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
2065 Get_Next_Interp (I, It);
2070 end Is_Function_Type;
2072 -- Start of processing for Analyze_Explicit_Dereference
2075 -- If source node, check SPARK restriction. We guard this with the
2076 -- source node check, because ???
2078 if Comes_From_Source (N) then
2079 Check_SPARK_05_Restriction ("explicit dereference is not allowed", N);
2082 -- In formal verification mode, keep track of all reads and writes
2083 -- through explicit dereferences.
2085 if GNATprove_Mode then
2086 SPARK_Specific.Generate_Dereference (N);
2090 Set_Etype (N, Any_Type);
2092 -- Test for remote access to subprogram type, and if so return
2093 -- after rewriting the original tree.
2095 if Remote_AST_E_Dereference (P) then
2099 -- Normal processing for other than remote access to subprogram type
2101 if not Is_Overloaded (P) then
2102 if Is_Access_Type (Etype (P)) then
2104 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
2105 -- avoid other problems caused by the Private_Subtype and it is
2106 -- safe to go to the Base_Type because this is the same as
2107 -- converting the access value to its Base_Type.
2110 DT : Entity_Id := Designated_Type (Etype (P));
2113 if Ekind (DT) = E_Private_Subtype
2114 and then Is_For_Access_Subtype (DT)
2116 DT := Base_Type (DT);
2119 -- An explicit dereference is a legal occurrence of an
2120 -- incomplete type imported through a limited_with clause, if
2121 -- the full view is visible, or if we are within an instance
2122 -- body, where the enclosing body has a regular with_clause
2125 if From_Limited_With (DT)
2126 and then not From_Limited_With (Scope (DT))
2128 (Is_Immediately_Visible (Scope (DT))
2130 (Is_Child_Unit (Scope (DT))
2131 and then Is_Visible_Lib_Unit (Scope (DT)))
2132 or else In_Instance_Body)
2134 Set_Etype (N, Available_View (DT));
2141 elsif Etype (P) /= Any_Type then
2142 Error_Msg_N ("prefix of dereference must be an access type", N);
2147 Get_First_Interp (P, I, It);
2148 while Present (It.Nam) loop
2151 if Is_Access_Type (T) then
2152 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
2155 Get_Next_Interp (I, It);
2158 -- Error if no interpretation of the prefix has an access type
2160 if Etype (N) = Any_Type then
2162 ("access type required in prefix of explicit dereference", P);
2163 Set_Etype (N, Any_Type);
2169 and then Nkind (Parent (N)) /= N_Indexed_Component
2171 and then (Nkind (Parent (N)) /= N_Function_Call
2172 or else N /= Name (Parent (N)))
2174 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
2175 or else N /= Name (Parent (N)))
2177 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
2178 and then (Nkind (Parent (N)) /= N_Attribute_Reference
2180 (Attribute_Name (Parent (N)) /= Name_Address
2182 Attribute_Name (Parent (N)) /= Name_Access))
2184 -- Name is a function call with no actuals, in a context that
2185 -- requires deproceduring (including as an actual in an enclosing
2186 -- function or procedure call). There are some pathological cases
2187 -- where the prefix might include functions that return access to
2188 -- subprograms and others that return a regular type. Disambiguation
2189 -- of those has to take place in Resolve.
2192 Make_Function_Call (Loc,
2193 Name => Make_Explicit_Dereference (Loc, P),
2194 Parameter_Associations => New_List);
2196 -- If the prefix is overloaded, remove operations that have formals,
2197 -- we know that this is a parameterless call.
2199 if Is_Overloaded (P) then
2200 Get_First_Interp (P, I, It);
2201 while Present (It.Nam) loop
2204 if No (First_Formal (Base_Type (Designated_Type (T)))) then
2210 Get_Next_Interp (I, It);
2217 elsif not Is_Function_Type
2218 and then Is_Overloaded (N)
2220 -- The prefix may include access to subprograms and other access
2221 -- types. If the context selects the interpretation that is a
2222 -- function call (not a procedure call) we cannot rewrite the node
2223 -- yet, but we include the result of the call interpretation.
2225 Get_First_Interp (N, I, It);
2226 while Present (It.Nam) loop
2227 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
2228 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
2229 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
2231 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
2234 Get_Next_Interp (I, It);
2238 -- A value of remote access-to-class-wide must not be dereferenced
2241 Validate_Remote_Access_To_Class_Wide_Type (N);
2242 end Analyze_Explicit_Dereference;
2244 ------------------------
2245 -- Analyze_Expression --
2246 ------------------------
2248 procedure Analyze_Expression (N : Node_Id) is
2251 -- If the expression is an indexed component that will be rewritten
2252 -- as a container indexing, it has already been analyzed.
2254 if Nkind (N) = N_Indexed_Component
2255 and then Present (Generalized_Indexing (N))
2261 Check_Parameterless_Call (N);
2263 end Analyze_Expression;
2265 -------------------------------------
2266 -- Analyze_Expression_With_Actions --
2267 -------------------------------------
2269 procedure Analyze_Expression_With_Actions (N : Node_Id) is
2273 A := First (Actions (N));
2274 while Present (A) loop
2279 Analyze_Expression (Expression (N));
2280 Set_Etype (N, Etype (Expression (N)));
2281 end Analyze_Expression_With_Actions;
2283 ---------------------------
2284 -- Analyze_If_Expression --
2285 ---------------------------
2287 procedure Analyze_If_Expression (N : Node_Id) is
2288 Condition : constant Node_Id := First (Expressions (N));
2289 Then_Expr : Node_Id;
2290 Else_Expr : Node_Id;
2293 -- Defend against error of missing expressions from previous error
2295 if No (Condition) then
2296 Check_Error_Detected;
2300 Then_Expr := Next (Condition);
2302 if No (Then_Expr) then
2303 Check_Error_Detected;
2307 Else_Expr := Next (Then_Expr);
2309 if Comes_From_Source (N) then
2310 Check_SPARK_05_Restriction ("if expression is not allowed", N);
2313 if Comes_From_Source (N) then
2314 Check_Compiler_Unit ("if expression", N);
2317 -- Analyze and resolve the condition. We need to resolve this now so
2318 -- that it gets folded to True/False if possible, before we analyze
2319 -- the THEN/ELSE branches, because when analyzing these branches, we
2320 -- may call Is_Statically_Unevaluated, which expects the condition of
2321 -- an enclosing IF to have been analyze/resolved/evaluated.
2323 Analyze_Expression (Condition);
2324 Resolve (Condition, Any_Boolean);
2326 -- Analyze THEN expression and (if present) ELSE expression. For those
2327 -- we delay resolution in the normal manner, because of overloading etc.
2329 Analyze_Expression (Then_Expr);
2331 if Present (Else_Expr) then
2332 Analyze_Expression (Else_Expr);
2335 -- If then expression not overloaded, then that decides the type
2337 if not Is_Overloaded (Then_Expr) then
2338 Set_Etype (N, Etype (Then_Expr));
2340 -- Case where then expression is overloaded
2348 Set_Etype (N, Any_Type);
2350 -- Loop through interpretations of Then_Expr
2352 Get_First_Interp (Then_Expr, I, It);
2353 while Present (It.Nam) loop
2355 -- Add possible interpretation of Then_Expr if no Else_Expr, or
2356 -- Else_Expr is present and has a compatible type.
2359 or else Has_Compatible_Type (Else_Expr, It.Typ)
2361 Add_One_Interp (N, It.Typ, It.Typ);
2364 Get_Next_Interp (I, It);
2367 -- If no valid interpretation has been found, then the type of the
2368 -- ELSE expression does not match any interpretation of the THEN
2371 if Etype (N) = Any_Type then
2373 ("type incompatible with that of `THEN` expression",
2379 end Analyze_If_Expression;
2381 ------------------------------------
2382 -- Analyze_Indexed_Component_Form --
2383 ------------------------------------
2385 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
2386 P : constant Node_Id := Prefix (N);
2387 Exprs : constant List_Id := Expressions (N);
2393 procedure Process_Function_Call;
2394 -- Prefix in indexed component form is an overloadable entity, so the
2395 -- node is a function call. Reformat it as such.
2397 procedure Process_Indexed_Component;
2398 -- Prefix in indexed component form is actually an indexed component.
2399 -- This routine processes it, knowing that the prefix is already
2402 procedure Process_Indexed_Component_Or_Slice;
2403 -- An indexed component with a single index may designate a slice if
2404 -- the index is a subtype mark. This routine disambiguates these two
2405 -- cases by resolving the prefix to see if it is a subtype mark.
2407 procedure Process_Overloaded_Indexed_Component;
2408 -- If the prefix of an indexed component is overloaded, the proper
2409 -- interpretation is selected by the index types and the context.
2411 ---------------------------
2412 -- Process_Function_Call --
2413 ---------------------------
2415 procedure Process_Function_Call is
2416 Loc : constant Source_Ptr := Sloc (N);
2420 Change_Node (N, N_Function_Call);
2422 Set_Parameter_Associations (N, Exprs);
2424 -- Analyze actuals prior to analyzing the call itself
2426 Actual := First (Parameter_Associations (N));
2427 while Present (Actual) loop
2429 Check_Parameterless_Call (Actual);
2431 -- Move to next actual. Note that we use Next, not Next_Actual
2432 -- here. The reason for this is a bit subtle. If a function call
2433 -- includes named associations, the parser recognizes the node
2434 -- as a call, and it is analyzed as such. If all associations are
2435 -- positional, the parser builds an indexed_component node, and
2436 -- it is only after analysis of the prefix that the construct
2437 -- is recognized as a call, in which case Process_Function_Call
2438 -- rewrites the node and analyzes the actuals. If the list of
2439 -- actuals is malformed, the parser may leave the node as an
2440 -- indexed component (despite the presence of named associations).
2441 -- The iterator Next_Actual is equivalent to Next if the list is
2442 -- positional, but follows the normalized chain of actuals when
2443 -- named associations are present. In this case normalization has
2444 -- not taken place, and actuals remain unanalyzed, which leads to
2445 -- subsequent crashes or loops if there is an attempt to continue
2446 -- analysis of the program.
2448 -- IF there is a single actual and it is a type name, the node
2449 -- can only be interpreted as a slice of a parameterless call.
2450 -- Rebuild the node as such and analyze.
2452 if No (Next (Actual))
2453 and then Is_Entity_Name (Actual)
2454 and then Is_Type (Entity (Actual))
2455 and then Is_Discrete_Type (Entity (Actual))
2461 New_Occurrence_Of (Entity (Actual), Loc)));
2471 end Process_Function_Call;
2473 -------------------------------
2474 -- Process_Indexed_Component --
2475 -------------------------------
2477 procedure Process_Indexed_Component is
2479 Array_Type : Entity_Id;
2481 Pent : Entity_Id := Empty;
2484 Exp := First (Exprs);
2486 if Is_Overloaded (P) then
2487 Process_Overloaded_Indexed_Component;
2490 Array_Type := Etype (P);
2492 if Is_Entity_Name (P) then
2494 elsif Nkind (P) = N_Selected_Component
2495 and then Is_Entity_Name (Selector_Name (P))
2497 Pent := Entity (Selector_Name (P));
2500 -- Prefix must be appropriate for an array type, taking into
2501 -- account a possible implicit dereference.
2503 if Is_Access_Type (Array_Type) then
2505 (Warn_On_Dereference, "?d?implicit dereference", N);
2506 Array_Type := Process_Implicit_Dereference_Prefix (Pent, P);
2509 if Is_Array_Type (Array_Type) then
2511 -- In order to correctly access First_Index component later,
2512 -- replace string literal subtype by its parent type.
2514 if Ekind (Array_Type) = E_String_Literal_Subtype then
2515 Array_Type := Etype (Array_Type);
2518 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
2520 Set_Etype (N, Any_Type);
2522 if not Has_Compatible_Type (Exp, Entry_Index_Type (Pent)) then
2523 Error_Msg_N ("invalid index type in entry name", N);
2525 elsif Present (Next (Exp)) then
2526 Error_Msg_N ("too many subscripts in entry reference", N);
2529 Set_Etype (N, Etype (P));
2534 elsif Is_Record_Type (Array_Type)
2535 and then Remote_AST_I_Dereference (P)
2539 elsif Try_Container_Indexing (N, P, Exprs) then
2542 elsif Array_Type = Any_Type then
2543 Set_Etype (N, Any_Type);
2545 -- In most cases the analysis of the prefix will have emitted
2546 -- an error already, but if the prefix may be interpreted as a
2547 -- call in prefixed notation, the report is left to the caller.
2548 -- To prevent cascaded errors, report only if no previous ones.
2550 if Serious_Errors_Detected = 0 then
2551 Error_Msg_N ("invalid prefix in indexed component", P);
2553 if Nkind (P) = N_Expanded_Name then
2554 Error_Msg_NE ("\& is not visible", P, Selector_Name (P));
2560 -- Here we definitely have a bad indexing
2563 if Nkind (Parent (N)) = N_Requeue_Statement
2564 and then Present (Pent) and then Ekind (Pent) = E_Entry
2567 ("REQUEUE does not permit parameters", First (Exprs));
2569 elsif Is_Entity_Name (P)
2570 and then Etype (P) = Standard_Void_Type
2572 Error_Msg_NE ("incorrect use of &", P, Entity (P));
2575 Error_Msg_N ("array type required in indexed component", P);
2578 Set_Etype (N, Any_Type);
2582 Index := First_Index (Array_Type);
2583 while Present (Index) and then Present (Exp) loop
2584 if not Has_Compatible_Type (Exp, Etype (Index)) then
2585 Wrong_Type (Exp, Etype (Index));
2586 Set_Etype (N, Any_Type);
2594 Set_Etype (N, Component_Type (Array_Type));
2595 Check_Implicit_Dereference (N, Etype (N));
2597 if Present (Index) then
2599 ("too few subscripts in array reference", First (Exprs));
2601 elsif Present (Exp) then
2602 Error_Msg_N ("too many subscripts in array reference", Exp);
2605 end Process_Indexed_Component;
2607 ----------------------------------------
2608 -- Process_Indexed_Component_Or_Slice --
2609 ----------------------------------------
2611 procedure Process_Indexed_Component_Or_Slice is
2613 Exp := First (Exprs);
2614 while Present (Exp) loop
2615 Analyze_Expression (Exp);
2619 Exp := First (Exprs);
2621 -- If one index is present, and it is a subtype name, then the node
2622 -- denotes a slice (note that the case of an explicit range for a
2623 -- slice was already built as an N_Slice node in the first place,
2624 -- so that case is not handled here).
2626 -- We use a replace rather than a rewrite here because this is one
2627 -- of the cases in which the tree built by the parser is plain wrong.
2630 and then Is_Entity_Name (Exp)
2631 and then Is_Type (Entity (Exp))
2634 Make_Slice (Sloc (N),
2636 Discrete_Range => New_Copy (Exp)));
2639 -- Otherwise (more than one index present, or single index is not
2640 -- a subtype name), then we have the indexed component case.
2643 Process_Indexed_Component;
2645 end Process_Indexed_Component_Or_Slice;
2647 ------------------------------------------
2648 -- Process_Overloaded_Indexed_Component --
2649 ------------------------------------------
2651 procedure Process_Overloaded_Indexed_Component is
2660 Set_Etype (N, Any_Type);
2662 Get_First_Interp (P, I, It);
2663 while Present (It.Nam) loop
2666 if Is_Access_Type (Typ) then
2667 Typ := Designated_Type (Typ);
2669 (Warn_On_Dereference, "?d?implicit dereference", N);
2672 if Is_Array_Type (Typ) then
2674 -- Got a candidate: verify that index types are compatible
2676 Index := First_Index (Typ);
2678 Exp := First (Exprs);
2679 while Present (Index) and then Present (Exp) loop
2680 if Has_Compatible_Type (Exp, Etype (Index)) then
2692 if Found and then No (Index) and then No (Exp) then
2694 CT : constant Entity_Id :=
2695 Base_Type (Component_Type (Typ));
2697 Add_One_Interp (N, CT, CT);
2698 Check_Implicit_Dereference (N, CT);
2702 elsif Try_Container_Indexing (N, P, Exprs) then
2707 Get_Next_Interp (I, It);
2710 if Etype (N) = Any_Type then
2711 Error_Msg_N ("no legal interpretation for indexed component", N);
2712 Set_Is_Overloaded (N, False);
2716 end Process_Overloaded_Indexed_Component;
2718 -- Start of processing for Analyze_Indexed_Component_Form
2721 -- Get name of array, function or type
2725 -- If P is an explicit dereference whose prefix is of a remote access-
2726 -- to-subprogram type, then N has already been rewritten as a subprogram
2727 -- call and analyzed.
2729 if Nkind (N) in N_Subprogram_Call then
2732 -- When the prefix is attribute 'Loop_Entry and the sole expression of
2733 -- the indexed component denotes a loop name, the indexed form is turned
2734 -- into an attribute reference.
2736 elsif Nkind (N) = N_Attribute_Reference
2737 and then Attribute_Name (N) = Name_Loop_Entry
2742 pragma Assert (Nkind (N) = N_Indexed_Component);
2744 P_T := Base_Type (Etype (P));
2746 if Is_Entity_Name (P) and then Present (Entity (P)) then
2749 if Is_Type (U_N) then
2751 -- Reformat node as a type conversion
2753 E := Remove_Head (Exprs);
2755 if Present (First (Exprs)) then
2757 ("argument of type conversion must be single expression", N);
2760 Change_Node (N, N_Type_Conversion);
2761 Set_Subtype_Mark (N, P);
2763 Set_Expression (N, E);
2765 -- After changing the node, call for the specific Analysis
2766 -- routine directly, to avoid a double call to the expander.
2768 Analyze_Type_Conversion (N);
2772 if Is_Overloadable (U_N) then
2773 Process_Function_Call;
2775 elsif Ekind (Etype (P)) = E_Subprogram_Type
2776 or else (Is_Access_Type (Etype (P))
2778 Ekind (Designated_Type (Etype (P))) =
2781 -- Call to access_to-subprogram with possible implicit dereference
2783 Process_Function_Call;
2785 elsif Is_Generic_Subprogram (U_N) then
2787 -- A common beginner's (or C++ templates fan) error
2789 Error_Msg_N ("generic subprogram cannot be called", N);
2790 Set_Etype (N, Any_Type);
2794 Process_Indexed_Component_Or_Slice;
2797 -- If not an entity name, prefix is an expression that may denote
2798 -- an array or an access-to-subprogram.
2801 if Ekind (P_T) = E_Subprogram_Type
2802 or else (Is_Access_Type (P_T)
2804 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
2806 Process_Function_Call;
2808 elsif Nkind (P) = N_Selected_Component
2809 and then Present (Entity (Selector_Name (P)))
2810 and then Is_Overloadable (Entity (Selector_Name (P)))
2812 Process_Function_Call;
2814 -- In ASIS mode within a generic, a prefixed call is analyzed and
2815 -- partially rewritten but the original indexed component has not
2816 -- yet been rewritten as a call. Perform the replacement now.
2818 elsif Nkind (P) = N_Selected_Component
2819 and then Nkind (Parent (P)) = N_Function_Call
2822 Rewrite (N, Parent (P));
2826 -- Indexed component, slice, or a call to a member of a family
2827 -- entry, which will be converted to an entry call later.
2829 Process_Indexed_Component_Or_Slice;
2833 Analyze_Dimension (N);
2834 end Analyze_Indexed_Component_Form;
2836 ------------------------
2837 -- Analyze_Logical_Op --
2838 ------------------------
2840 procedure Analyze_Logical_Op (N : Node_Id) is
2841 L : constant Node_Id := Left_Opnd (N);
2842 R : constant Node_Id := Right_Opnd (N);
2843 Op_Id : Entity_Id := Entity (N);
2846 Set_Etype (N, Any_Type);
2847 Candidate_Type := Empty;
2849 Analyze_Expression (L);
2850 Analyze_Expression (R);
2852 if Present (Op_Id) then
2854 if Ekind (Op_Id) = E_Operator then
2855 Find_Boolean_Types (L, R, Op_Id, N);
2857 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2861 Op_Id := Get_Name_Entity_Id (Chars (N));
2862 while Present (Op_Id) loop
2863 if Ekind (Op_Id) = E_Operator then
2864 Find_Boolean_Types (L, R, Op_Id, N);
2866 Analyze_User_Defined_Binary_Op (N, Op_Id);
2869 Op_Id := Homonym (Op_Id);
2874 Check_Function_Writable_Actuals (N);
2875 end Analyze_Logical_Op;
2877 ---------------------------
2878 -- Analyze_Membership_Op --
2879 ---------------------------
2881 procedure Analyze_Membership_Op (N : Node_Id) is
2882 Loc : constant Source_Ptr := Sloc (N);
2883 L : constant Node_Id := Left_Opnd (N);
2884 R : constant Node_Id := Right_Opnd (N);
2886 Index : Interp_Index;
2888 Found : Boolean := False;
2892 procedure Try_One_Interp (T1 : Entity_Id);
2893 -- Routine to try one proposed interpretation. Note that the context
2894 -- of the operation plays no role in resolving the arguments, so that
2895 -- if there is more than one interpretation of the operands that is
2896 -- compatible with a membership test, the operation is ambiguous.
2898 --------------------
2899 -- Try_One_Interp --
2900 --------------------
2902 procedure Try_One_Interp (T1 : Entity_Id) is
2904 if Has_Compatible_Type (R, T1) then
2906 and then Base_Type (T1) /= Base_Type (T_F)
2908 It := Disambiguate (L, I_F, Index, Any_Type);
2910 if It = No_Interp then
2911 Ambiguous_Operands (N);
2912 Set_Etype (L, Any_Type);
2929 procedure Analyze_Set_Membership;
2930 -- If a set of alternatives is present, analyze each and find the
2931 -- common type to which they must all resolve.
2933 ----------------------------
2934 -- Analyze_Set_Membership --
2935 ----------------------------
2937 procedure Analyze_Set_Membership is
2939 Index : Interp_Index;
2941 Candidate_Interps : Node_Id;
2942 Common_Type : Entity_Id := Empty;
2945 if Comes_From_Source (N) then
2946 Check_Compiler_Unit ("set membership", N);
2950 Candidate_Interps := L;
2952 if not Is_Overloaded (L) then
2953 Common_Type := Etype (L);
2955 Alt := First (Alternatives (N));
2956 while Present (Alt) loop
2959 if not Has_Compatible_Type (Alt, Common_Type) then
2960 Wrong_Type (Alt, Common_Type);
2967 Alt := First (Alternatives (N));
2968 while Present (Alt) loop
2970 if not Is_Overloaded (Alt) then
2971 Common_Type := Etype (Alt);
2974 Get_First_Interp (Alt, Index, It);
2975 while Present (It.Typ) loop
2977 Has_Compatible_Type (Candidate_Interps, It.Typ)
2979 Remove_Interp (Index);
2982 Get_Next_Interp (Index, It);
2985 Get_First_Interp (Alt, Index, It);
2988 Error_Msg_N ("alternative has no legal type", Alt);
2992 -- If alternative is not overloaded, we have a unique type
2995 Set_Etype (Alt, It.Typ);
2997 -- If the alternative is an enumeration literal, use the one
2998 -- for this interpretation.
3000 if Is_Entity_Name (Alt) then
3001 Set_Entity (Alt, It.Nam);
3004 Get_Next_Interp (Index, It);
3007 Set_Is_Overloaded (Alt, False);
3008 Common_Type := Etype (Alt);
3011 Candidate_Interps := Alt;
3018 Set_Etype (N, Standard_Boolean);
3020 if Present (Common_Type) then
3021 Set_Etype (L, Common_Type);
3023 -- The left operand may still be overloaded, to be resolved using
3027 Error_Msg_N ("cannot resolve membership operation", N);
3029 end Analyze_Set_Membership;
3031 -- Start of processing for Analyze_Membership_Op
3034 Analyze_Expression (L);
3037 pragma Assert (Ada_Version >= Ada_2012);
3038 Analyze_Set_Membership;
3039 Check_Function_Writable_Actuals (N);
3043 if Nkind (R) = N_Range
3044 or else (Nkind (R) = N_Attribute_Reference
3045 and then Attribute_Name (R) = Name_Range)
3049 if not Is_Overloaded (L) then
3050 Try_One_Interp (Etype (L));
3053 Get_First_Interp (L, Index, It);
3054 while Present (It.Typ) loop
3055 Try_One_Interp (It.Typ);
3056 Get_Next_Interp (Index, It);
3060 -- If not a range, it can be a subtype mark, or else it is a degenerate
3061 -- membership test with a singleton value, i.e. a test for equality,
3062 -- if the types are compatible.
3067 if Is_Entity_Name (R)
3068 and then Is_Type (Entity (R))
3071 Check_Fully_Declared (Entity (R), R);
3073 elsif Ada_Version >= Ada_2012
3074 and then Has_Compatible_Type (R, Etype (L))
3076 if Nkind (N) = N_In then
3092 -- In all versions of the language, if we reach this point there
3093 -- is a previous error that will be diagnosed below.
3099 -- Compatibility between expression and subtype mark or range is
3100 -- checked during resolution. The result of the operation is Boolean
3103 Set_Etype (N, Standard_Boolean);
3105 if Comes_From_Source (N)
3106 and then Present (Right_Opnd (N))
3107 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
3109 Error_Msg_N ("membership test not applicable to cpp-class types", N);
3112 Check_Function_Writable_Actuals (N);
3113 end Analyze_Membership_Op;
3119 procedure Analyze_Mod (N : Node_Id) is
3121 -- A special warning check, if we have an expression of the form:
3122 -- expr mod 2 * literal
3123 -- where literal is 64 or less, then probably what was meant was
3124 -- expr mod 2 ** literal
3125 -- so issue an appropriate warning.
3127 if Warn_On_Suspicious_Modulus_Value
3128 and then Nkind (Right_Opnd (N)) = N_Integer_Literal
3129 and then Intval (Right_Opnd (N)) = Uint_2
3130 and then Nkind (Parent (N)) = N_Op_Multiply
3131 and then Nkind (Right_Opnd (Parent (N))) = N_Integer_Literal
3132 and then Intval (Right_Opnd (Parent (N))) <= Uint_64
3135 ("suspicious MOD value, was '*'* intended'??M?", Parent (N));
3138 -- Remaining processing is same as for other arithmetic operators
3140 Analyze_Arithmetic_Op (N);
3143 ----------------------
3144 -- Analyze_Negation --
3145 ----------------------
3147 procedure Analyze_Negation (N : Node_Id) is
3148 R : constant Node_Id := Right_Opnd (N);
3149 Op_Id : Entity_Id := Entity (N);
3152 Set_Etype (N, Any_Type);
3153 Candidate_Type := Empty;
3155 Analyze_Expression (R);
3157 if Present (Op_Id) then
3158 if Ekind (Op_Id) = E_Operator then
3159 Find_Negation_Types (R, Op_Id, N);
3161 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3165 Op_Id := Get_Name_Entity_Id (Chars (N));
3166 while Present (Op_Id) loop
3167 if Ekind (Op_Id) = E_Operator then
3168 Find_Negation_Types (R, Op_Id, N);
3170 Analyze_User_Defined_Unary_Op (N, Op_Id);
3173 Op_Id := Homonym (Op_Id);
3178 end Analyze_Negation;
3184 procedure Analyze_Null (N : Node_Id) is
3186 Check_SPARK_05_Restriction ("null is not allowed", N);
3188 Set_Etype (N, Any_Access);
3191 ----------------------
3192 -- Analyze_One_Call --
3193 ----------------------
3195 procedure Analyze_One_Call
3199 Success : out Boolean;
3200 Skip_First : Boolean := False)
3202 Actuals : constant List_Id := Parameter_Associations (N);
3203 Prev_T : constant Entity_Id := Etype (N);
3205 -- Recognize cases of prefixed calls that have been rewritten in
3206 -- various ways. The simplest case is a rewritten selected component,
3207 -- but it can also be an already-examined indexed component, or a
3208 -- prefix that is itself a rewritten prefixed call that is in turn
3209 -- an indexed call (the syntactic ambiguity involving the indexing of
3210 -- a function with defaulted parameters that returns an array).
3211 -- A flag Maybe_Indexed_Call might be useful here ???
3213 Must_Skip : constant Boolean := Skip_First
3214 or else Nkind (Original_Node (N)) = N_Selected_Component
3216 (Nkind (Original_Node (N)) = N_Indexed_Component
3217 and then Nkind (Prefix (Original_Node (N))) =
3218 N_Selected_Component)
3220 (Nkind (Parent (N)) = N_Function_Call
3221 and then Is_Array_Type (Etype (Name (N)))
3222 and then Etype (Original_Node (N)) =
3223 Component_Type (Etype (Name (N)))
3224 and then Nkind (Original_Node (Parent (N))) =
3225 N_Selected_Component);
3227 -- The first formal must be omitted from the match when trying to find
3228 -- a primitive operation that is a possible interpretation, and also
3229 -- after the call has been rewritten, because the corresponding actual
3230 -- is already known to be compatible, and because this may be an
3231 -- indexing of a call with default parameters.
3235 Is_Indexed : Boolean := False;
3236 Is_Indirect : Boolean := False;
3237 Subp_Type : constant Entity_Id := Etype (Nam);
3240 function Compatible_Types_In_Predicate
3242 T2 : Entity_Id) return Boolean;
3243 -- For an Ada 2012 predicate or invariant, a call may mention an
3244 -- incomplete type, while resolution of the corresponding predicate
3245 -- function may see the full view, as a consequence of the delayed
3246 -- resolution of the corresponding expressions. This may occur in
3247 -- the body of a predicate function, or in a call to such. Anomalies
3248 -- involving private and full views can also happen. In each case,
3249 -- rewrite node or add conversions to remove spurious type errors.
3251 procedure Indicate_Name_And_Type;
3252 -- If candidate interpretation matches, indicate name and type of result
3255 function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
3256 -- There may be a user-defined operator that hides the current
3257 -- interpretation. We must check for this independently of the
3258 -- analysis of the call with the user-defined operation, because
3259 -- the parameter names may be wrong and yet the hiding takes place.
3260 -- This fixes a problem with ACATS test B34014O.
3262 -- When the type Address is a visible integer type, and the DEC
3263 -- system extension is visible, the predefined operator may be
3264 -- hidden as well, by one of the address operations in auxdec.
3265 -- Finally, The abstract operations on address do not hide the
3266 -- predefined operator (this is the purpose of making them abstract).
3268 -----------------------------------
3269 -- Compatible_Types_In_Predicate --
3270 -----------------------------------
3272 function Compatible_Types_In_Predicate
3274 T2 : Entity_Id) return Boolean
3276 function Common_Type (T : Entity_Id) return Entity_Id;
3277 -- Find non-private full view if any, without going to ancestor type
3278 -- (as opposed to Underlying_Type).
3284 function Common_Type (T : Entity_Id) return Entity_Id is
3286 if Is_Private_Type (T) and then Present (Full_View (T)) then
3287 return Base_Type (Full_View (T));
3289 return Base_Type (T);
3293 -- Start of processing for Compatible_Types_In_Predicate
3296 if (Ekind (Current_Scope) = E_Function
3297 and then Is_Predicate_Function (Current_Scope))
3299 (Ekind (Nam) = E_Function
3300 and then Is_Predicate_Function (Nam))
3302 if Is_Incomplete_Type (T1)
3303 and then Present (Full_View (T1))
3304 and then Full_View (T1) = T2
3306 Set_Etype (Formal, Etype (Actual));
3309 elsif Common_Type (T1) = Common_Type (T2) then
3310 Rewrite (Actual, Unchecked_Convert_To (Etype (Formal), Actual));
3320 end Compatible_Types_In_Predicate;
3322 ----------------------------
3323 -- Indicate_Name_And_Type --
3324 ----------------------------
3326 procedure Indicate_Name_And_Type is
3328 Add_One_Interp (N, Nam, Etype (Nam));
3329 Check_Implicit_Dereference (N, Etype (Nam));
3332 -- If the prefix of the call is a name, indicate the entity
3333 -- being called. If it is not a name, it is an expression that
3334 -- denotes an access to subprogram or else an entry or family. In
3335 -- the latter case, the name is a selected component, and the entity
3336 -- being called is noted on the selector.
3338 if not Is_Type (Nam) then
3339 if Is_Entity_Name (Name (N)) then
3340 Set_Entity (Name (N), Nam);
3341 Set_Etype (Name (N), Etype (Nam));
3343 elsif Nkind (Name (N)) = N_Selected_Component then
3344 Set_Entity (Selector_Name (Name (N)), Nam);
3348 if Debug_Flag_E and not Report then
3349 Write_Str (" Overloaded call ");
3350 Write_Int (Int (N));
3351 Write_Str (" compatible with ");
3352 Write_Int (Int (Nam));
3355 end Indicate_Name_And_Type;
3357 ------------------------
3358 -- Operator_Hidden_By --
3359 ------------------------
3361 function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
3362 Act1 : constant Node_Id := First_Actual (N);
3363 Act2 : constant Node_Id := Next_Actual (Act1);
3364 Form1 : constant Entity_Id := First_Formal (Fun);
3365 Form2 : constant Entity_Id := Next_Formal (Form1);
3368 if Ekind (Fun) /= E_Function or else Is_Abstract_Subprogram (Fun) then
3371 elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
3374 elsif Present (Form2) then
3376 or else not Has_Compatible_Type (Act2, Etype (Form2))
3381 elsif Present (Act2) then
3385 -- Now we know that the arity of the operator matches the function,
3386 -- and the function call is a valid interpretation. The function
3387 -- hides the operator if it has the right signature, or if one of
3388 -- its operands is a non-abstract operation on Address when this is
3389 -- a visible integer type.
3391 return Hides_Op (Fun, Nam)
3392 or else Is_Descendant_Of_Address (Etype (Form1))
3395 and then Is_Descendant_Of_Address (Etype (Form2)));
3396 end Operator_Hidden_By;
3398 -- Start of processing for Analyze_One_Call
3403 -- If the subprogram has no formals or if all the formals have defaults,
3404 -- and the return type is an array type, the node may denote an indexing
3405 -- of the result of a parameterless call. In Ada 2005, the subprogram
3406 -- may have one non-defaulted formal, and the call may have been written
3407 -- in prefix notation, so that the rebuilt parameter list has more than
3410 if not Is_Overloadable (Nam)
3411 and then Ekind (Nam) /= E_Subprogram_Type
3412 and then Ekind (Nam) /= E_Entry_Family
3417 -- An indexing requires at least one actual. The name of the call cannot
3418 -- be an implicit indirect call, so it cannot be a generated explicit
3421 if not Is_Empty_List (Actuals)
3423 (Needs_No_Actuals (Nam)
3425 (Needs_One_Actual (Nam)
3426 and then Present (Next_Actual (First (Actuals)))))
3428 if Is_Array_Type (Subp_Type)
3430 (Nkind (Name (N)) /= N_Explicit_Dereference
3431 or else Comes_From_Source (Name (N)))
3433 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
3435 elsif Is_Access_Type (Subp_Type)
3436 and then Is_Array_Type (Designated_Type (Subp_Type))
3440 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
3442 -- The prefix can also be a parameterless function that returns an
3443 -- access to subprogram, in which case this is an indirect call.
3444 -- If this succeeds, an explicit dereference is added later on,
3445 -- in Analyze_Call or Resolve_Call.
3447 elsif Is_Access_Type (Subp_Type)
3448 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
3450 Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
3455 -- If the call has been transformed into a slice, it is of the form
3456 -- F (Subtype) where F is parameterless. The node has been rewritten in
3457 -- Try_Indexed_Call and there is nothing else to do.
3460 and then Nkind (N) = N_Slice
3466 (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
3470 -- If an indirect call is a possible interpretation, indicate
3471 -- success to the caller. This may be an indexing of an explicit
3472 -- dereference of a call that returns an access type (see above).
3476 and then Nkind (Name (N)) = N_Explicit_Dereference
3477 and then Comes_From_Source (Name (N)))
3482 -- Mismatch in number or names of parameters
3484 elsif Debug_Flag_E then
3485 Write_Str (" normalization fails in call ");
3486 Write_Int (Int (N));
3487 Write_Str (" with subprogram ");
3488 Write_Int (Int (Nam));
3492 -- If the context expects a function call, discard any interpretation
3493 -- that is a procedure. If the node is not overloaded, leave as is for
3494 -- better error reporting when type mismatch is found.
3496 elsif Nkind (N) = N_Function_Call
3497 and then Is_Overloaded (Name (N))
3498 and then Ekind (Nam) = E_Procedure
3502 -- Ditto for function calls in a procedure context
3504 elsif Nkind (N) = N_Procedure_Call_Statement
3505 and then Is_Overloaded (Name (N))
3506 and then Etype (Nam) /= Standard_Void_Type
3510 elsif No (Actuals) then
3512 -- If Normalize succeeds, then there are default parameters for
3515 Indicate_Name_And_Type;
3517 elsif Ekind (Nam) = E_Operator then
3518 if Nkind (N) = N_Procedure_Call_Statement then
3522 -- This can occur when the prefix of the call is an operator
3523 -- name or an expanded name whose selector is an operator name.
3525 Analyze_Operator_Call (N, Nam);
3527 if Etype (N) /= Prev_T then
3529 -- Check that operator is not hidden by a function interpretation
3531 if Is_Overloaded (Name (N)) then
3537 Get_First_Interp (Name (N), I, It);
3538 while Present (It.Nam) loop
3539 if Operator_Hidden_By (It.Nam) then
3540 Set_Etype (N, Prev_T);
3544 Get_Next_Interp (I, It);
3549 -- If operator matches formals, record its name on the call.
3550 -- If the operator is overloaded, Resolve will select the
3551 -- correct one from the list of interpretations. The call
3552 -- node itself carries the first candidate.
3554 Set_Entity (Name (N), Nam);
3557 elsif Report and then Etype (N) = Any_Type then
3558 Error_Msg_N ("incompatible arguments for operator", N);
3562 -- Normalize_Actuals has chained the named associations in the
3563 -- correct order of the formals.
3565 Actual := First_Actual (N);
3566 Formal := First_Formal (Nam);
3568 -- If we are analyzing a call rewritten from object notation, skip
3569 -- first actual, which may be rewritten later as an explicit
3573 Next_Actual (Actual);
3574 Next_Formal (Formal);
3577 while Present (Actual) and then Present (Formal) loop
3578 if Nkind (Parent (Actual)) /= N_Parameter_Association
3579 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
3581 -- The actual can be compatible with the formal, but we must
3582 -- also check that the context is not an address type that is
3583 -- visibly an integer type. In this case the use of literals is
3584 -- illegal, except in the body of descendants of system, where
3585 -- arithmetic operations on address are of course used.
3587 if Has_Compatible_Type (Actual, Etype (Formal))
3589 (Etype (Actual) /= Universal_Integer
3590 or else not Is_Descendant_Of_Address (Etype (Formal))
3591 or else In_Predefined_Unit (N))
3593 Next_Actual (Actual);
3594 Next_Formal (Formal);
3596 -- In Allow_Integer_Address mode, we allow an actual integer to
3597 -- match a formal address type and vice versa. We only do this
3598 -- if we are certain that an error will otherwise be issued
3600 elsif Address_Integer_Convert_OK
3601 (Etype (Actual), Etype (Formal))
3602 and then (Report and not Is_Indexed and not Is_Indirect)
3604 -- Handle this case by introducing an unchecked conversion
3607 Unchecked_Convert_To (Etype (Formal),
3608 Relocate_Node (Actual)));
3609 Analyze_And_Resolve (Actual, Etype (Formal));
3610 Next_Actual (Actual);
3611 Next_Formal (Formal);
3613 -- Under relaxed RM semantics silently replace occurrences of
3614 -- null by System.Address_Null. We only do this if we know that
3615 -- an error will otherwise be issued.
3617 elsif Null_To_Null_Address_Convert_OK (Actual, Etype (Formal))
3618 and then (Report and not Is_Indexed and not Is_Indirect)
3620 Replace_Null_By_Null_Address (Actual);
3621 Analyze_And_Resolve (Actual, Etype (Formal));
3622 Next_Actual (Actual);
3623 Next_Formal (Formal);
3625 elsif Compatible_Types_In_Predicate
3626 (Etype (Formal), Etype (Actual))
3628 Next_Actual (Actual);
3629 Next_Formal (Formal);
3631 -- In a complex case where an enclosing generic and a nested
3632 -- generic package, both declared with partially parameterized
3633 -- formal subprograms with the same names, are instantiated
3634 -- with the same type, the types of the actual parameter and
3635 -- that of the formal may appear incompatible at first sight.
3638 -- type Outer_T is private;
3639 -- with function Func (Formal : Outer_T)
3640 -- return ... is <>;
3642 -- package Outer_Gen is
3644 -- type Inner_T is private;
3645 -- with function Func (Formal : Inner_T) -- (1)
3646 -- return ... is <>;
3648 -- package Inner_Gen is
3649 -- function Inner_Func (Formal : Inner_T) -- (2)
3650 -- return ... is (Func (Formal));
3652 -- end Outer_Generic;
3654 -- package Outer_Inst is new Outer_Gen (Actual_T);
3655 -- package Inner_Inst is new Outer_Inst.Inner_Gen (Actual_T);
3657 -- In the example above, the type of parameter
3658 -- Inner_Func.Formal at (2) is incompatible with the type of
3659 -- Func.Formal at (1) in the context of instantiations
3660 -- Outer_Inst and Inner_Inst. In reality both types are generic
3661 -- actual subtypes renaming base type Actual_T as part of the
3662 -- generic prologues for the instantiations.
3664 -- Recognize this case and add a type conversion to allow this
3665 -- kind of generic actual subtype conformance. Note that this
3666 -- is done only when the call is non-overloaded because the
3667 -- resolution mechanism already has the means to disambiguate
3670 elsif not Is_Overloaded (Name (N))
3671 and then Is_Type (Etype (Actual))
3672 and then Is_Type (Etype (Formal))
3673 and then Is_Generic_Actual_Type (Etype (Actual))
3674 and then Is_Generic_Actual_Type (Etype (Formal))
3675 and then Base_Type (Etype (Actual)) =
3676 Base_Type (Etype (Formal))
3679 Convert_To (Etype (Formal), Relocate_Node (Actual)));
3680 Analyze_And_Resolve (Actual, Etype (Formal));
3681 Next_Actual (Actual);
3682 Next_Formal (Formal);
3684 -- Handle failed type check
3687 if Debug_Flag_E then
3688 Write_Str (" type checking fails in call ");
3689 Write_Int (Int (N));
3690 Write_Str (" with formal ");
3691 Write_Int (Int (Formal));
3692 Write_Str (" in subprogram ");
3693 Write_Int (Int (Nam));
3697 -- Comment needed on the following test???
3699 if Report and not Is_Indexed and not Is_Indirect then
3701 -- Ada 2005 (AI-251): Complete the error notification
3702 -- to help new Ada 2005 users.
3704 if Is_Class_Wide_Type (Etype (Formal))
3705 and then Is_Interface (Etype (Etype (Formal)))
3706 and then not Interface_Present_In_Ancestor
3707 (Typ => Etype (Actual),
3708 Iface => Etype (Etype (Formal)))
3711 ("(Ada 2005) does not implement interface }",
3712 Actual, Etype (Etype (Formal)));
3715 Wrong_Type (Actual, Etype (Formal));
3717 if Nkind (Actual) = N_Op_Eq
3718 and then Nkind (Left_Opnd (Actual)) = N_Identifier
3720 Formal := First_Formal (Nam);
3721 while Present (Formal) loop
3722 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
3723 Error_Msg_N -- CODEFIX
3724 ("possible misspelling of `='>`!", Actual);
3728 Next_Formal (Formal);
3732 if All_Errors_Mode then
3733 Error_Msg_Sloc := Sloc (Nam);
3735 if Etype (Formal) = Any_Type then
3737 ("there is no legal actual parameter", Actual);
3740 if Is_Overloadable (Nam)
3741 and then Present (Alias (Nam))
3742 and then not Comes_From_Source (Nam)
3745 ("\\ =='> in call to inherited operation & #!",
3748 elsif Ekind (Nam) = E_Subprogram_Type then
3750 Access_To_Subprogram_Typ :
3751 constant Entity_Id :=
3753 (Associated_Node_For_Itype (Nam));
3756 ("\\ =='> in call to dereference of &#!",
3757 Actual, Access_To_Subprogram_Typ);
3762 ("\\ =='> in call to &#!", Actual, Nam);
3772 -- Normalize_Actuals has verified that a default value exists
3773 -- for this formal. Current actual names a subsequent formal.
3775 Next_Formal (Formal);
3779 -- On exit, all actuals match
3781 Indicate_Name_And_Type;
3783 end Analyze_One_Call;
3785 ---------------------------
3786 -- Analyze_Operator_Call --
3787 ---------------------------
3789 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
3790 Op_Name : constant Name_Id := Chars (Op_Id);
3791 Act1 : constant Node_Id := First_Actual (N);
3792 Act2 : constant Node_Id := Next_Actual (Act1);
3795 -- Binary operator case
3797 if Present (Act2) then
3799 -- If more than two operands, then not binary operator after all
3801 if Present (Next_Actual (Act2)) then
3805 -- Otherwise action depends on operator
3816 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
3822 Find_Boolean_Types (Act1, Act2, Op_Id, N);
3829 Find_Comparison_Types (Act1, Act2, Op_Id, N);
3834 Find_Equality_Types (Act1, Act2, Op_Id, N);
3836 when Name_Op_Concat =>
3837 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
3839 -- Is this when others, or should it be an abort???
3845 -- Unary operator case
3853 Find_Unary_Types (Act1, Op_Id, N);
3856 Find_Negation_Types (Act1, Op_Id, N);
3858 -- Is this when others correct, or should it be an abort???
3864 end Analyze_Operator_Call;
3866 -------------------------------------------
3867 -- Analyze_Overloaded_Selected_Component --
3868 -------------------------------------------
3870 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
3871 Nam : constant Node_Id := Prefix (N);
3872 Sel : constant Node_Id := Selector_Name (N);
3879 Set_Etype (Sel, Any_Type);
3881 Get_First_Interp (Nam, I, It);
3882 while Present (It.Typ) loop
3883 if Is_Access_Type (It.Typ) then
3884 T := Designated_Type (It.Typ);
3885 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
3890 -- Locate the component. For a private prefix the selector can denote
3893 if Is_Record_Type (T) or else Is_Private_Type (T) then
3895 -- If the prefix is a class-wide type, the visible components are
3896 -- those of the base type.
3898 if Is_Class_Wide_Type (T) then
3902 Comp := First_Entity (T);
3903 while Present (Comp) loop
3904 if Chars (Comp) = Chars (Sel)
3905 and then Is_Visible_Component (Comp, Sel)
3908 -- AI05-105: if the context is an object renaming with
3909 -- an anonymous access type, the expected type of the
3910 -- object must be anonymous. This is a name resolution rule.
3912 if Nkind (Parent (N)) /= N_Object_Renaming_Declaration
3913 or else No (Access_Definition (Parent (N)))
3914 or else Ekind (Etype (Comp)) = E_Anonymous_Access_Type
3916 Ekind (Etype (Comp)) = E_Anonymous_Access_Subprogram_Type
3918 Set_Entity (Sel, Comp);
3919 Set_Etype (Sel, Etype (Comp));
3920 Add_One_Interp (N, Etype (Comp), Etype (Comp));
3921 Check_Implicit_Dereference (N, Etype (Comp));
3923 -- This also specifies a candidate to resolve the name.
3924 -- Further overloading will be resolved from context.
3925 -- The selector name itself does not carry overloading
3928 Set_Etype (Nam, It.Typ);
3931 -- Named access type in the context of a renaming
3932 -- declaration with an access definition. Remove
3933 -- inapplicable candidate.
3942 elsif Is_Concurrent_Type (T) then
3943 Comp := First_Entity (T);
3944 while Present (Comp)
3945 and then Comp /= First_Private_Entity (T)
3947 if Chars (Comp) = Chars (Sel) then
3948 if Is_Overloadable (Comp) then
3949 Add_One_Interp (Sel, Comp, Etype (Comp));
3951 Set_Entity_With_Checks (Sel, Comp);
3952 Generate_Reference (Comp, Sel);
3955 Set_Etype (Sel, Etype (Comp));
3956 Set_Etype (N, Etype (Comp));
3957 Set_Etype (Nam, It.Typ);
3959 -- For access type case, introduce explicit dereference for
3960 -- more uniform treatment of entry calls. Do this only once
3961 -- if several interpretations yield an access type.
3963 if Is_Access_Type (Etype (Nam))
3964 and then Nkind (Nam) /= N_Explicit_Dereference
3966 Insert_Explicit_Dereference (Nam);
3968 (Warn_On_Dereference, "?d?implicit dereference", N);
3975 Set_Is_Overloaded (N, Is_Overloaded (Sel));
3978 Get_Next_Interp (I, It);
3981 if Etype (N) = Any_Type
3982 and then not Try_Object_Operation (N)
3984 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
3985 Set_Entity (Sel, Any_Id);
3986 Set_Etype (Sel, Any_Type);
3988 end Analyze_Overloaded_Selected_Component;
3990 ----------------------------------
3991 -- Analyze_Qualified_Expression --
3992 ----------------------------------
3994 procedure Analyze_Qualified_Expression (N : Node_Id) is
3995 Mark : constant Entity_Id := Subtype_Mark (N);
3996 Expr : constant Node_Id := Expression (N);
4002 Analyze_Expression (Expr);
4004 Set_Etype (N, Any_Type);
4008 if Nkind_In (Enclosing_Declaration (N), N_Formal_Type_Declaration,
4009 N_Full_Type_Declaration,
4010 N_Incomplete_Type_Declaration,
4011 N_Protected_Type_Declaration,
4012 N_Private_Extension_Declaration,
4013 N_Private_Type_Declaration,
4014 N_Subtype_Declaration,
4015 N_Task_Type_Declaration)
4016 and then T = Defining_Identifier (Enclosing_Declaration (N))
4018 Error_Msg_N ("current instance not allowed", Mark);
4024 if T = Any_Type then
4028 Check_Fully_Declared (T, N);
4030 -- If expected type is class-wide, check for exact match before
4031 -- expansion, because if the expression is a dispatching call it
4032 -- may be rewritten as explicit dereference with class-wide result.
4033 -- If expression is overloaded, retain only interpretations that
4034 -- will yield exact matches.
4036 if Is_Class_Wide_Type (T) then
4037 if not Is_Overloaded (Expr) then
4038 if Base_Type (Etype (Expr)) /= Base_Type (T) then
4039 if Nkind (Expr) = N_Aggregate then
4040 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
4042 Wrong_Type (Expr, T);
4047 Get_First_Interp (Expr, I, It);
4049 while Present (It.Nam) loop
4050 if Base_Type (It.Typ) /= Base_Type (T) then
4054 Get_Next_Interp (I, It);
4060 end Analyze_Qualified_Expression;
4062 -----------------------------------
4063 -- Analyze_Quantified_Expression --
4064 -----------------------------------
4066 procedure Analyze_Quantified_Expression (N : Node_Id) is
4067 function Is_Empty_Range (Typ : Entity_Id) return Boolean;
4068 -- If the iterator is part of a quantified expression, and the range is
4069 -- known to be statically empty, emit a warning and replace expression
4070 -- with its static value. Returns True if the replacement occurs.
4072 function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean;
4073 -- Determine whether if expression If_Expr lacks an else part or if it
4074 -- has one, it evaluates to True.
4076 --------------------
4077 -- Is_Empty_Range --
4078 --------------------
4080 function Is_Empty_Range (Typ : Entity_Id) return Boolean is
4081 Loc : constant Source_Ptr := Sloc (N);
4084 if Is_Array_Type (Typ)
4085 and then Compile_Time_Known_Bounds (Typ)
4087 (Expr_Value (Type_Low_Bound (Etype (First_Index (Typ)))) >
4088 Expr_Value (Type_High_Bound (Etype (First_Index (Typ)))))
4090 Preanalyze_And_Resolve (Condition (N), Standard_Boolean);
4092 if All_Present (N) then
4094 ("??quantified expression with ALL "
4095 & "over a null range has value True", N);
4096 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
4100 ("??quantified expression with SOME "
4101 & "over a null range has value False", N);
4102 Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
4113 -----------------------------
4114 -- No_Else_Or_Trivial_True --
4115 -----------------------------
4117 function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean is
4118 Else_Expr : constant Node_Id :=
4119 Next (Next (First (Expressions (If_Expr))));
4123 or else (Compile_Time_Known_Value (Else_Expr)
4124 and then Is_True (Expr_Value (Else_Expr)));
4125 end No_Else_Or_Trivial_True;
4129 Cond : constant Node_Id := Condition (N);
4130 Loop_Id : Entity_Id;
4131 QE_Scop : Entity_Id;
4133 -- Start of processing for Analyze_Quantified_Expression
4136 Check_SPARK_05_Restriction ("quantified expression is not allowed", N);
4138 -- Create a scope to emulate the loop-like behavior of the quantified
4139 -- expression. The scope is needed to provide proper visibility of the
4142 QE_Scop := New_Internal_Entity (E_Loop, Current_Scope, Sloc (N), 'L');
4143 Set_Etype (QE_Scop, Standard_Void_Type);
4144 Set_Scope (QE_Scop, Current_Scope);
4145 Set_Parent (QE_Scop, N);
4147 Push_Scope (QE_Scop);
4149 -- All constituents are preanalyzed and resolved to avoid untimely
4150 -- generation of various temporaries and types. Full analysis and
4151 -- expansion is carried out when the quantified expression is
4152 -- transformed into an expression with actions.
4154 if Present (Iterator_Specification (N)) then
4155 Preanalyze (Iterator_Specification (N));
4157 -- Do not proceed with the analysis when the range of iteration is
4158 -- empty. The appropriate error is issued by Is_Empty_Range.
4160 if Is_Entity_Name (Name (Iterator_Specification (N)))
4161 and then Is_Empty_Range (Etype (Name (Iterator_Specification (N))))
4166 else pragma Assert (Present (Loop_Parameter_Specification (N)));
4168 Loop_Par : constant Node_Id := Loop_Parameter_Specification (N);
4171 Preanalyze (Loop_Par);
4173 if Nkind (Discrete_Subtype_Definition (Loop_Par)) = N_Function_Call
4174 and then Parent (Loop_Par) /= N
4176 -- The parser cannot distinguish between a loop specification
4177 -- and an iterator specification. If after preanalysis the
4178 -- proper form has been recognized, rewrite the expression to
4179 -- reflect the right kind. This is needed for proper ASIS
4180 -- navigation. If expansion is enabled, the transformation is
4181 -- performed when the expression is rewritten as a loop.
4183 Set_Iterator_Specification (N,
4184 New_Copy_Tree (Iterator_Specification (Parent (Loop_Par))));
4186 Set_Defining_Identifier (Iterator_Specification (N),
4187 Relocate_Node (Defining_Identifier (Loop_Par)));
4188 Set_Name (Iterator_Specification (N),
4189 Relocate_Node (Discrete_Subtype_Definition (Loop_Par)));
4190 Set_Comes_From_Source (Iterator_Specification (N),
4191 Comes_From_Source (Loop_Parameter_Specification (N)));
4192 Set_Loop_Parameter_Specification (N, Empty);
4197 Preanalyze_And_Resolve (Cond, Standard_Boolean);
4200 Set_Etype (N, Standard_Boolean);
4202 -- Verify that the loop variable is used within the condition of the
4203 -- quantified expression.
4205 if Present (Iterator_Specification (N)) then
4206 Loop_Id := Defining_Identifier (Iterator_Specification (N));
4208 Loop_Id := Defining_Identifier (Loop_Parameter_Specification (N));
4211 if Warn_On_Suspicious_Contract
4212 and then not Referenced (Loop_Id, Cond)
4214 -- Generating C, this check causes spurious warnings on inlined
4215 -- postconditions; we can safely disable it because this check
4216 -- was previously performed when analyzing the internally built
4217 -- postconditions procedure.
4219 if Modify_Tree_For_C and then In_Inlined_Body then
4222 Error_Msg_N ("?T?unused variable &", Loop_Id);
4226 -- Diagnose a possible misuse of the SOME existential quantifier. When
4227 -- we have a quantified expression of the form:
4229 -- for some X => (if P then Q [else True])
4231 -- any value for X that makes P False results in the if expression being
4232 -- trivially True, and so also results in the quantified expression
4233 -- being trivially True.
4235 if Warn_On_Suspicious_Contract
4236 and then not All_Present (N)
4237 and then Nkind (Cond) = N_If_Expression
4238 and then No_Else_Or_Trivial_True (Cond)
4240 Error_Msg_N ("?T?suspicious expression", N);
4241 Error_Msg_N ("\\did you mean (for all X ='> (if P then Q))", N);
4242 Error_Msg_N ("\\or (for some X ='> P and then Q) instead'?", N);
4244 end Analyze_Quantified_Expression;
4250 procedure Analyze_Range (N : Node_Id) is
4251 L : constant Node_Id := Low_Bound (N);
4252 H : constant Node_Id := High_Bound (N);
4253 I1, I2 : Interp_Index;
4256 procedure Check_Common_Type (T1, T2 : Entity_Id);
4257 -- Verify the compatibility of two types, and choose the
4258 -- non universal one if the other is universal.
4260 procedure Check_High_Bound (T : Entity_Id);
4261 -- Test one interpretation of the low bound against all those
4262 -- of the high bound.
4264 procedure Check_Universal_Expression (N : Node_Id);
4265 -- In Ada 83, reject bounds of a universal range that are not literals
4268 -----------------------
4269 -- Check_Common_Type --
4270 -----------------------
4272 procedure Check_Common_Type (T1, T2 : Entity_Id) is
4274 if Covers (T1 => T1, T2 => T2)
4276 Covers (T1 => T2, T2 => T1)
4278 if T1 = Universal_Integer
4279 or else T1 = Universal_Real
4280 or else T1 = Any_Character
4282 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
4285 Add_One_Interp (N, T1, T1);
4288 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
4291 end Check_Common_Type;
4293 ----------------------
4294 -- Check_High_Bound --
4295 ----------------------
4297 procedure Check_High_Bound (T : Entity_Id) is
4299 if not Is_Overloaded (H) then
4300 Check_Common_Type (T, Etype (H));
4302 Get_First_Interp (H, I2, It2);
4303 while Present (It2.Typ) loop
4304 Check_Common_Type (T, It2.Typ);
4305 Get_Next_Interp (I2, It2);
4308 end Check_High_Bound;
4310 --------------------------------
4311 -- Check_Universal_Expression --
4312 --------------------------------
4314 procedure Check_Universal_Expression (N : Node_Id) is
4316 if Etype (N) = Universal_Integer
4317 and then Nkind (N) /= N_Integer_Literal
4318 and then not Is_Entity_Name (N)
4319 and then Nkind (N) /= N_Attribute_Reference
4321 Error_Msg_N ("illegal bound in discrete range", N);
4323 end Check_Universal_Expression;
4325 -- Start of processing for Analyze_Range
4328 Set_Etype (N, Any_Type);
4329 Analyze_Expression (L);
4330 Analyze_Expression (H);
4332 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
4336 if not Is_Overloaded (L) then
4337 Check_High_Bound (Etype (L));
4339 Get_First_Interp (L, I1, It1);
4340 while Present (It1.Typ) loop
4341 Check_High_Bound (It1.Typ);
4342 Get_Next_Interp (I1, It1);
4346 -- If result is Any_Type, then we did not find a compatible pair
4348 if Etype (N) = Any_Type then
4349 Error_Msg_N ("incompatible types in range ", N);
4353 if Ada_Version = Ada_83
4355 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
4356 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
4358 Check_Universal_Expression (L);
4359 Check_Universal_Expression (H);
4362 Check_Function_Writable_Actuals (N);
4365 -----------------------
4366 -- Analyze_Reference --
4367 -----------------------
4369 procedure Analyze_Reference (N : Node_Id) is
4370 P : constant Node_Id := Prefix (N);
4373 Acc_Type : Entity_Id;
4378 -- An interesting error check, if we take the 'Ref of an object for
4379 -- which a pragma Atomic or Volatile has been given, and the type of the
4380 -- object is not Atomic or Volatile, then we are in trouble. The problem
4381 -- is that no trace of the atomic/volatile status will remain for the
4382 -- backend to respect when it deals with the resulting pointer, since
4383 -- the pointer type will not be marked atomic (it is a pointer to the
4384 -- base type of the object).
4386 -- It is not clear if that can ever occur, but in case it does, we will
4387 -- generate an error message. Not clear if this message can ever be
4388 -- generated, and pretty clear that it represents a bug if it is, still
4389 -- seems worth checking, except in CodePeer mode where we do not really
4390 -- care and don't want to bother the user.
4394 if Is_Entity_Name (P)
4395 and then Is_Object_Reference (P)
4396 and then not CodePeer_Mode
4401 if (Has_Atomic_Components (E)
4402 and then not Has_Atomic_Components (T))
4404 (Has_Volatile_Components (E)
4405 and then not Has_Volatile_Components (T))
4406 or else (Is_Atomic (E) and then not Is_Atomic (T))
4407 or else (Is_Volatile (E) and then not Is_Volatile (T))
4409 Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
4413 -- Carry on with normal processing
4415 Acc_Type := Create_Itype (E_Allocator_Type, N);
4416 Set_Etype (Acc_Type, Acc_Type);
4417 Set_Directly_Designated_Type (Acc_Type, Etype (P));
4418 Set_Etype (N, Acc_Type);
4419 end Analyze_Reference;
4421 --------------------------------
4422 -- Analyze_Selected_Component --
4423 --------------------------------
4425 -- Prefix is a record type or a task or protected type. In the latter case,
4426 -- the selector must denote a visible entry.
4428 procedure Analyze_Selected_Component (N : Node_Id) is
4429 Name : constant Node_Id := Prefix (N);
4430 Sel : constant Node_Id := Selector_Name (N);
4433 Has_Candidate : Boolean := False;
4434 Hidden_Comp : Entity_Id;
4436 Is_Private_Op : Boolean;
4438 Pent : Entity_Id := Empty;
4439 Prefix_Type : Entity_Id;
4441 Type_To_Use : Entity_Id;
4442 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
4443 -- a class-wide type, we use its root type, whose components are
4444 -- present in the class-wide type.
4446 Is_Single_Concurrent_Object : Boolean;
4447 -- Set True if the prefix is a single task or a single protected object
4449 procedure Find_Component_In_Instance (Rec : Entity_Id);
4450 -- In an instance, a component of a private extension may not be visible
4451 -- while it was visible in the generic. Search candidate scope for a
4452 -- component with the proper identifier. This is only done if all other
4453 -- searches have failed. If a match is found, the Etype of both N and
4454 -- Sel are set from this component, and the entity of Sel is set to
4455 -- reference this component. If no match is found, Entity (Sel) remains
4456 -- unset. For a derived type that is an actual of the instance, the
4457 -- desired component may be found in any ancestor.
4459 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
4460 -- It is known that the parent of N denotes a subprogram call. Comp
4461 -- is an overloadable component of the concurrent type of the prefix.
4462 -- Determine whether all formals of the parent of N and Comp are mode
4463 -- conformant. If the parent node is not analyzed yet it may be an
4464 -- indexed component rather than a function call.
4466 function Has_Dereference (Nod : Node_Id) return Boolean;
4467 -- Check whether prefix includes a dereference at any level.
4469 --------------------------------
4470 -- Find_Component_In_Instance --
4471 --------------------------------
4473 procedure Find_Component_In_Instance (Rec : Entity_Id) is
4479 while Present (Typ) loop
4480 Comp := First_Component (Typ);
4481 while Present (Comp) loop
4482 if Chars (Comp) = Chars (Sel) then
4483 Set_Entity_With_Checks (Sel, Comp);
4484 Set_Etype (Sel, Etype (Comp));
4485 Set_Etype (N, Etype (Comp));
4489 Next_Component (Comp);
4492 -- If not found, the component may be declared in the parent
4493 -- type or its full view, if any.
4495 if Is_Derived_Type (Typ) then
4498 if Is_Private_Type (Typ) then
4499 Typ := Full_View (Typ);
4507 -- If we fall through, no match, so no changes made
4510 end Find_Component_In_Instance;
4512 ------------------------------
4513 -- Has_Mode_Conformant_Spec --
4514 ------------------------------
4516 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
4517 Comp_Param : Entity_Id;
4519 Param_Typ : Entity_Id;
4522 Comp_Param := First_Formal (Comp);
4524 if Nkind (Parent (N)) = N_Indexed_Component then
4525 Param := First (Expressions (Parent (N)));
4527 Param := First (Parameter_Associations (Parent (N)));
4530 while Present (Comp_Param)
4531 and then Present (Param)
4533 Param_Typ := Find_Parameter_Type (Param);
4535 if Present (Param_Typ)
4537 not Conforming_Types
4538 (Etype (Comp_Param), Param_Typ, Mode_Conformant)
4543 Next_Formal (Comp_Param);
4547 -- One of the specs has additional formals; there is no match, unless
4548 -- this may be an indexing of a parameterless call.
4550 -- Note that when expansion is disabled, the corresponding record
4551 -- type of synchronized types is not constructed, so that there is
4552 -- no point is attempting an interpretation as a prefixed call, as
4553 -- this is bound to fail because the primitive operations will not
4554 -- be properly located.
4556 if Present (Comp_Param) or else Present (Param) then
4557 if Needs_No_Actuals (Comp)
4558 and then Is_Array_Type (Etype (Comp))
4559 and then not Expander_Active
4568 end Has_Mode_Conformant_Spec;
4570 ---------------------
4571 -- Has_Dereference --
4572 ---------------------
4574 function Has_Dereference (Nod : Node_Id) return Boolean is
4576 if Nkind (Nod) = N_Explicit_Dereference then
4579 -- When expansion is disabled an explicit dereference may not have
4580 -- been inserted, but if this is an access type the indirection makes
4583 elsif Is_Access_Type (Etype (Nod)) then
4586 elsif Nkind_In (Nod, N_Indexed_Component, N_Selected_Component) then
4587 return Has_Dereference (Prefix (Nod));
4592 end Has_Dereference;
4594 -- Start of processing for Analyze_Selected_Component
4597 Set_Etype (N, Any_Type);
4599 if Is_Overloaded (Name) then
4600 Analyze_Overloaded_Selected_Component (N);
4603 elsif Etype (Name) = Any_Type then
4604 Set_Entity (Sel, Any_Id);
4605 Set_Etype (Sel, Any_Type);
4609 Prefix_Type := Etype (Name);
4612 if Is_Access_Type (Prefix_Type) then
4614 -- A RACW object can never be used as prefix of a selected component
4615 -- since that means it is dereferenced without being a controlling
4616 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
4617 -- reporting an error, we must check whether this is actually a
4618 -- dispatching call in prefix form.
4620 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
4621 and then Comes_From_Source (N)
4623 if Try_Object_Operation (N) then
4627 ("invalid dereference of a remote access-to-class-wide value",
4631 -- Normal case of selected component applied to access type
4634 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
4636 if Is_Entity_Name (Name) then
4637 Pent := Entity (Name);
4638 elsif Nkind (Name) = N_Selected_Component
4639 and then Is_Entity_Name (Selector_Name (Name))
4641 Pent := Entity (Selector_Name (Name));
4644 Prefix_Type := Process_Implicit_Dereference_Prefix (Pent, Name);
4647 -- If we have an explicit dereference of a remote access-to-class-wide
4648 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
4649 -- have to check for the case of a prefix that is a controlling operand
4650 -- of a prefixed dispatching call, as the dereference is legal in that
4651 -- case. Normally this condition is checked in Validate_Remote_Access_
4652 -- To_Class_Wide_Type, but we have to defer the checking for selected
4653 -- component prefixes because of the prefixed dispatching call case.
4654 -- Note that implicit dereferences are checked for this just above.
4656 elsif Nkind (Name) = N_Explicit_Dereference
4657 and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
4658 and then Comes_From_Source (N)
4660 if Try_Object_Operation (N) then
4664 ("invalid dereference of a remote access-to-class-wide value",
4669 -- (Ada 2005): if the prefix is the limited view of a type, and
4670 -- the context already includes the full view, use the full view
4671 -- in what follows, either to retrieve a component of to find
4672 -- a primitive operation. If the prefix is an explicit dereference,
4673 -- set the type of the prefix to reflect this transformation.
4674 -- If the nonlimited view is itself an incomplete type, get the
4675 -- full view if available.
4677 if From_Limited_With (Prefix_Type)
4678 and then Has_Non_Limited_View (Prefix_Type)
4680 Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
4682 if Nkind (N) = N_Explicit_Dereference then
4683 Set_Etype (Prefix (N), Prefix_Type);
4687 if Ekind (Prefix_Type) = E_Private_Subtype then
4688 Prefix_Type := Base_Type (Prefix_Type);
4691 Type_To_Use := Prefix_Type;
4693 -- For class-wide types, use the entity list of the root type. This
4694 -- indirection is specially important for private extensions because
4695 -- only the root type get switched (not the class-wide type).
4697 if Is_Class_Wide_Type (Prefix_Type) then
4698 Type_To_Use := Root_Type (Prefix_Type);
4701 -- If the prefix is a single concurrent object, use its name in error
4702 -- messages, rather than that of its anonymous type.
4704 Is_Single_Concurrent_Object :=
4705 Is_Concurrent_Type (Prefix_Type)
4706 and then Is_Internal_Name (Chars (Prefix_Type))
4707 and then not Is_Derived_Type (Prefix_Type)
4708 and then Is_Entity_Name (Name);
4710 Comp := First_Entity (Type_To_Use);
4712 -- If the selector has an original discriminant, the node appears in
4713 -- an instance. Replace the discriminant with the corresponding one
4714 -- in the current discriminated type. For nested generics, this must
4715 -- be done transitively, so note the new original discriminant.
4717 if Nkind (Sel) = N_Identifier
4718 and then In_Instance
4719 and then Present (Original_Discriminant (Sel))
4721 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
4723 -- Mark entity before rewriting, for completeness and because
4724 -- subsequent semantic checks might examine the original node.
4726 Set_Entity (Sel, Comp);
4727 Rewrite (Selector_Name (N), New_Occurrence_Of (Comp, Sloc (N)));
4728 Set_Original_Discriminant (Selector_Name (N), Comp);
4729 Set_Etype (N, Etype (Comp));
4730 Check_Implicit_Dereference (N, Etype (Comp));
4732 if Is_Access_Type (Etype (Name)) then
4733 Insert_Explicit_Dereference (Name);
4734 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
4737 elsif Is_Record_Type (Prefix_Type) then
4739 -- Find component with given name. In an instance, if the node is
4740 -- known as a prefixed call, do not examine components whose
4741 -- visibility may be accidental.
4743 while Present (Comp) and then not Is_Prefixed_Call (N) loop
4744 if Chars (Comp) = Chars (Sel)
4745 and then Is_Visible_Component (Comp, N)
4747 Set_Entity_With_Checks (Sel, Comp);
4748 Set_Etype (Sel, Etype (Comp));
4750 if Ekind (Comp) = E_Discriminant then
4751 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
4753 ("cannot reference discriminant of unchecked union",
4757 if Is_Generic_Type (Prefix_Type)
4759 Is_Generic_Type (Root_Type (Prefix_Type))
4761 Set_Original_Discriminant (Sel, Comp);
4765 -- Resolve the prefix early otherwise it is not possible to
4766 -- build the actual subtype of the component: it may need
4767 -- to duplicate this prefix and duplication is only allowed
4768 -- on fully resolved expressions.
4772 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
4773 -- subtypes in a package specification.
4776 -- limited with Pkg;
4778 -- type Acc_Inc is access Pkg.T;
4780 -- N : Natural := X.all.Comp; -- ERROR, limited view
4781 -- end Pkg; -- Comp is not visible
4783 if Nkind (Name) = N_Explicit_Dereference
4784 and then From_Limited_With (Etype (Prefix (Name)))
4785 and then not Is_Potentially_Use_Visible (Etype (Name))
4786 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
4787 N_Package_Specification
4790 ("premature usage of incomplete}", Prefix (Name),
4791 Etype (Prefix (Name)));
4794 -- We never need an actual subtype for the case of a selection
4795 -- for a indexed component of a non-packed array, since in
4796 -- this case gigi generates all the checks and can find the
4797 -- necessary bounds information.
4799 -- We also do not need an actual subtype for the case of a
4800 -- first, last, length, or range attribute applied to a
4801 -- non-packed array, since gigi can again get the bounds in
4802 -- these cases (gigi cannot handle the packed case, since it
4803 -- has the bounds of the packed array type, not the original
4804 -- bounds of the type). However, if the prefix is itself a
4805 -- selected component, as in a.b.c (i), gigi may regard a.b.c
4806 -- as a dynamic-sized temporary, so we do generate an actual
4807 -- subtype for this case.
4809 Parent_N := Parent (N);
4811 if not Is_Packed (Etype (Comp))
4813 ((Nkind (Parent_N) = N_Indexed_Component
4814 and then Nkind (Name) /= N_Selected_Component)
4816 (Nkind (Parent_N) = N_Attribute_Reference
4818 Nam_In (Attribute_Name (Parent_N), Name_First,
4823 Set_Etype (N, Etype (Comp));
4825 -- If full analysis is not enabled, we do not generate an
4826 -- actual subtype, because in the absence of expansion
4827 -- reference to a formal of a protected type, for example,
4828 -- will not be properly transformed, and will lead to
4829 -- out-of-scope references in gigi.
4831 -- In all other cases, we currently build an actual subtype.
4832 -- It seems likely that many of these cases can be avoided,
4833 -- but right now, the front end makes direct references to the
4834 -- bounds (e.g. in generating a length check), and if we do
4835 -- not make an actual subtype, we end up getting a direct
4836 -- reference to a discriminant, which will not do.
4838 elsif Full_Analysis then
4840 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
4841 Insert_Action (N, Act_Decl);
4843 if No (Act_Decl) then
4844 Set_Etype (N, Etype (Comp));
4847 -- Component type depends on discriminants. Enter the
4848 -- main attributes of the subtype.
4851 Subt : constant Entity_Id :=
4852 Defining_Identifier (Act_Decl);
4855 Set_Etype (Subt, Base_Type (Etype (Comp)));
4856 Set_Ekind (Subt, Ekind (Etype (Comp)));
4857 Set_Etype (N, Subt);
4861 -- If Full_Analysis not enabled, just set the Etype
4864 Set_Etype (N, Etype (Comp));
4867 Check_Implicit_Dereference (N, Etype (N));
4871 -- If the prefix is a private extension, check only the visible
4872 -- components of the partial view. This must include the tag,
4873 -- which can appear in expanded code in a tag check.
4875 if Ekind (Type_To_Use) = E_Record_Type_With_Private
4876 and then Chars (Selector_Name (N)) /= Name_uTag
4878 exit when Comp = Last_Entity (Type_To_Use);
4884 -- Ada 2005 (AI-252): The selected component can be interpreted as
4885 -- a prefixed view of a subprogram. Depending on the context, this is
4886 -- either a name that can appear in a renaming declaration, or part
4887 -- of an enclosing call given in prefix form.
4889 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
4890 -- selected component should resolve to a name.
4892 if Ada_Version >= Ada_2005
4893 and then Is_Tagged_Type (Prefix_Type)
4894 and then not Is_Concurrent_Type (Prefix_Type)
4896 if Nkind (Parent (N)) = N_Generic_Association
4897 or else Nkind (Parent (N)) = N_Requeue_Statement
4898 or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
4900 if Find_Primitive_Operation (N) then
4904 elsif Try_Object_Operation (N) then
4908 -- If the transformation fails, it will be necessary to redo the
4909 -- analysis with all errors enabled, to indicate candidate
4910 -- interpretations and reasons for each failure ???
4914 elsif Is_Private_Type (Prefix_Type) then
4916 -- Allow access only to discriminants of the type. If the type has
4917 -- no full view, gigi uses the parent type for the components, so we
4918 -- do the same here.
4920 if No (Full_View (Prefix_Type)) then
4921 Type_To_Use := Root_Type (Base_Type (Prefix_Type));
4922 Comp := First_Entity (Type_To_Use);
4925 while Present (Comp) loop
4926 if Chars (Comp) = Chars (Sel) then
4927 if Ekind (Comp) = E_Discriminant then
4928 Set_Entity_With_Checks (Sel, Comp);
4929 Generate_Reference (Comp, Sel);
4931 Set_Etype (Sel, Etype (Comp));
4932 Set_Etype (N, Etype (Comp));
4933 Check_Implicit_Dereference (N, Etype (N));
4935 if Is_Generic_Type (Prefix_Type)
4936 or else Is_Generic_Type (Root_Type (Prefix_Type))
4938 Set_Original_Discriminant (Sel, Comp);
4941 -- Before declaring an error, check whether this is tagged
4942 -- private type and a call to a primitive operation.
4944 elsif Ada_Version >= Ada_2005
4945 and then Is_Tagged_Type (Prefix_Type)
4946 and then Try_Object_Operation (N)
4951 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4952 Error_Msg_NE ("invisible selector& for }", N, Sel);
4953 Set_Entity (Sel, Any_Id);
4954 Set_Etype (N, Any_Type);
4963 elsif Is_Concurrent_Type (Prefix_Type) then
4965 -- Find visible operation with given name. For a protected type,
4966 -- the possible candidates are discriminants, entries or protected
4967 -- subprograms. For a task type, the set can only include entries or
4968 -- discriminants if the task type is not an enclosing scope. If it
4969 -- is an enclosing scope (e.g. in an inner task) then all entities
4970 -- are visible, but the prefix must denote the enclosing scope, i.e.
4971 -- can only be a direct name or an expanded name.
4973 Set_Etype (Sel, Any_Type);
4974 Hidden_Comp := Empty;
4975 In_Scope := In_Open_Scopes (Prefix_Type);
4976 Is_Private_Op := False;
4978 while Present (Comp) loop
4980 -- Do not examine private operations of the type if not within
4983 if Chars (Comp) = Chars (Sel) then
4984 if Is_Overloadable (Comp)
4986 or else Comp /= First_Private_Entity (Type_To_Use))
4988 Add_One_Interp (Sel, Comp, Etype (Comp));
4989 if Comp = First_Private_Entity (Type_To_Use) then
4990 Is_Private_Op := True;
4993 -- If the prefix is tagged, the correct interpretation may
4994 -- lie in the primitive or class-wide operations of the
4995 -- type. Perform a simple conformance check to determine
4996 -- whether Try_Object_Operation should be invoked even if
4997 -- a visible entity is found.
4999 if Is_Tagged_Type (Prefix_Type)
5000 and then Nkind_In (Parent (N), N_Function_Call,
5001 N_Indexed_Component,
5002 N_Procedure_Call_Statement)
5003 and then Has_Mode_Conformant_Spec (Comp)
5005 Has_Candidate := True;
5008 -- Note: a selected component may not denote a component of a
5009 -- protected type (4.1.3(7)).
5011 elsif Ekind_In (Comp, E_Discriminant, E_Entry_Family)
5013 and then not Is_Protected_Type (Prefix_Type)
5014 and then Is_Entity_Name (Name))
5016 Set_Entity_With_Checks (Sel, Comp);
5017 Generate_Reference (Comp, Sel);
5019 -- The selector is not overloadable, so we have a candidate
5022 Has_Candidate := True;
5025 if Ekind (Comp) = E_Component then
5026 Hidden_Comp := Comp;
5032 Set_Etype (Sel, Etype (Comp));
5033 Set_Etype (N, Etype (Comp));
5035 if Ekind (Comp) = E_Discriminant then
5036 Set_Original_Discriminant (Sel, Comp);
5039 -- For access type case, introduce explicit dereference for
5040 -- more uniform treatment of entry calls.
5042 if Is_Access_Type (Etype (Name)) then
5043 Insert_Explicit_Dereference (Name);
5045 (Warn_On_Dereference, "?d?implicit dereference", N);
5050 if Comp = First_Private_Entity (Type_To_Use) then
5051 if Etype (Sel) /= Any_Type then
5053 -- We have a candiate
5058 -- Indicate that subsequent operations are private,
5059 -- for better error reporting.
5061 Is_Private_Op := True;
5065 -- Do not examine private operations if not within scope of
5066 -- the synchronized type.
5068 exit when not In_Scope
5070 Comp = First_Private_Entity (Base_Type (Prefix_Type));
5074 -- If the scope is a current instance, the prefix cannot be an
5075 -- expression of the same type, unless the selector designates a
5076 -- public operation (otherwise that would represent an attempt to
5077 -- reach an internal entity of another synchronized object).
5079 -- This is legal if prefix is an access to such type and there is
5080 -- a dereference, or is a component with a dereferenced prefix.
5081 -- It is also legal if the prefix is a component of a task type,
5082 -- and the selector is one of the task operations.
5085 and then not Is_Entity_Name (Name)
5086 and then not Has_Dereference (Name)
5088 if Is_Task_Type (Prefix_Type)
5089 and then Present (Entity (Sel))
5090 and then Ekind_In (Entity (Sel), E_Entry, E_Entry_Family)
5094 elsif Is_Protected_Type (Prefix_Type)
5095 and then Is_Overloadable (Entity (Sel))
5096 and then not Is_Private_Op
5102 ("invalid reference to internal operation of some object of "
5103 & "type &", N, Type_To_Use);
5104 Set_Entity (Sel, Any_Id);
5105 Set_Etype (Sel, Any_Type);
5109 -- Another special case: the prefix may denote an object of the type
5110 -- (but not a type) in which case this is an external call and the
5111 -- operation must be public.
5114 and then Is_Object_Reference (Original_Node (Prefix (N)))
5115 and then Comes_From_Source (N)
5116 and then Is_Private_Op
5118 if Present (Hidden_Comp) then
5120 ("invalid reference to private component of object of type "
5121 & "&", N, Type_To_Use);
5125 ("invalid reference to private operation of some object of "
5126 & "type &", N, Type_To_Use);
5129 Set_Entity (Sel, Any_Id);
5130 Set_Etype (Sel, Any_Type);
5134 -- If there is no visible entity with the given name or none of the
5135 -- visible entities are plausible interpretations, check whether
5136 -- there is some other primitive operation with that name.
5138 if Ada_Version >= Ada_2005 and then Is_Tagged_Type (Prefix_Type) then
5139 if (Etype (N) = Any_Type
5140 or else not Has_Candidate)
5141 and then Try_Object_Operation (N)
5145 -- If the context is not syntactically a procedure call, it
5146 -- may be a call to a primitive function declared outside of
5147 -- the synchronized type.
5149 -- If the context is a procedure call, there might still be
5150 -- an overloading between an entry and a primitive procedure
5151 -- declared outside of the synchronized type, called in prefix
5152 -- notation. This is harder to disambiguate because in one case
5153 -- the controlling formal is implicit ???
5155 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
5156 and then Nkind (Parent (N)) /= N_Indexed_Component
5157 and then Try_Object_Operation (N)
5162 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
5163 -- entry or procedure of a tagged concurrent type we must check
5164 -- if there are class-wide subprograms covering the primitive. If
5165 -- true then Try_Object_Operation reports the error.
5168 and then Is_Concurrent_Type (Prefix_Type)
5169 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
5171 -- Duplicate the call. This is required to avoid problems with
5172 -- the tree transformations performed by Try_Object_Operation.
5173 -- Set properly the parent of the copied call, because it is
5174 -- about to be reanalyzed.
5177 Par : constant Node_Id := New_Copy_Tree (Parent (N));
5180 Set_Parent (Par, Parent (Parent (N)));
5182 if Try_Object_Operation
5183 (Sinfo.Name (Par), CW_Test_Only => True)
5191 if Etype (N) = Any_Type and then Is_Protected_Type (Prefix_Type) then
5193 -- Case of a prefix of a protected type: selector might denote
5194 -- an invisible private component.
5196 Comp := First_Private_Entity (Base_Type (Prefix_Type));
5197 while Present (Comp) and then Chars (Comp) /= Chars (Sel) loop
5201 if Present (Comp) then
5202 if Is_Single_Concurrent_Object then
5203 Error_Msg_Node_2 := Entity (Name);
5204 Error_Msg_NE ("invisible selector& for &", N, Sel);
5207 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
5208 Error_Msg_NE ("invisible selector& for }", N, Sel);
5214 Set_Is_Overloaded (N, Is_Overloaded (Sel));
5219 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
5222 -- If N still has no type, the component is not defined in the prefix
5224 if Etype (N) = Any_Type then
5226 if Is_Single_Concurrent_Object then
5227 Error_Msg_Node_2 := Entity (Name);
5228 Error_Msg_NE ("no selector& for&", N, Sel);
5230 Check_Misspelled_Selector (Type_To_Use, Sel);
5232 -- If this is a derived formal type, the parent may have different
5233 -- visibility at this point. Try for an inherited component before
5234 -- reporting an error.
5236 elsif Is_Generic_Type (Prefix_Type)
5237 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
5238 and then Prefix_Type /= Etype (Prefix_Type)
5239 and then Is_Record_Type (Etype (Prefix_Type))
5241 Set_Etype (Prefix (N), Etype (Prefix_Type));
5242 Analyze_Selected_Component (N);
5245 -- Similarly, if this is the actual for a formal derived type, or
5246 -- a derived type thereof, the component inherited from the generic
5247 -- parent may not be visible in the actual, but the selected
5248 -- component is legal. Climb up the derivation chain of the generic
5249 -- parent type until we find the proper ancestor type.
5251 elsif In_Instance and then Is_Tagged_Type (Prefix_Type) then
5253 Par : Entity_Id := Prefix_Type;
5255 -- Climb up derivation chain to generic actual subtype
5257 while not Is_Generic_Actual_Type (Par) loop
5258 if Ekind (Par) = E_Record_Type then
5259 Par := Parent_Subtype (Par);
5262 exit when Par = Etype (Par);
5267 if Present (Par) and then Is_Generic_Actual_Type (Par) then
5269 -- Now look for component in ancestor types
5271 Par := Generic_Parent_Type (Declaration_Node (Par));
5273 Find_Component_In_Instance (Par);
5274 exit when Present (Entity (Sel))
5275 or else Par = Etype (Par);
5279 -- Another special case: the type is an extension of a private
5280 -- type T, is an actual in an instance, and we are in the body
5281 -- of the instance, so the generic body had a full view of the
5282 -- type declaration for T or of some ancestor that defines the
5283 -- component in question.
5285 elsif Is_Derived_Type (Type_To_Use)
5286 and then Used_As_Generic_Actual (Type_To_Use)
5287 and then In_Instance_Body
5289 Find_Component_In_Instance (Parent_Subtype (Type_To_Use));
5291 -- In ASIS mode the generic parent type may be absent. Examine
5292 -- the parent type directly for a component that may have been
5293 -- visible in a parent generic unit.
5295 elsif Is_Derived_Type (Prefix_Type) then
5296 Par := Etype (Prefix_Type);
5297 Find_Component_In_Instance (Par);
5301 -- The search above must have eventually succeeded, since the
5302 -- selected component was legal in the generic.
5304 if No (Entity (Sel)) then
5305 raise Program_Error;
5310 -- Component not found, specialize error message when appropriate
5313 if Ekind (Prefix_Type) = E_Record_Subtype then
5315 -- Check whether this is a component of the base type which
5316 -- is absent from a statically constrained subtype. This will
5317 -- raise constraint error at run time, but is not a compile-
5318 -- time error. When the selector is illegal for base type as
5319 -- well fall through and generate a compilation error anyway.
5321 Comp := First_Component (Base_Type (Prefix_Type));
5322 while Present (Comp) loop
5323 if Chars (Comp) = Chars (Sel)
5324 and then Is_Visible_Component (Comp, Sel)
5326 Set_Entity_With_Checks (Sel, Comp);
5327 Generate_Reference (Comp, Sel);
5328 Set_Etype (Sel, Etype (Comp));
5329 Set_Etype (N, Etype (Comp));
5331 -- Emit appropriate message. The node will be replaced
5332 -- by an appropriate raise statement.
5334 -- Note that in SPARK mode, as with all calls to apply a
5335 -- compile time constraint error, this will be made into
5336 -- an error to simplify the processing of the formal
5337 -- verification backend.
5339 Apply_Compile_Time_Constraint_Error
5340 (N, "component not present in }??",
5341 CE_Discriminant_Check_Failed,
5342 Ent => Prefix_Type, Rep => False);
5344 Set_Raises_Constraint_Error (N);
5348 Next_Component (Comp);
5353 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
5354 Error_Msg_NE ("no selector& for}", N, Sel);
5356 -- Add information in the case of an incomplete prefix
5358 if Is_Incomplete_Type (Type_To_Use) then
5360 Inc : constant Entity_Id := First_Subtype (Type_To_Use);
5363 if From_Limited_With (Scope (Type_To_Use)) then
5365 ("\limited view of& has no components", N, Inc);
5369 ("\premature usage of incomplete type&", N, Inc);
5371 if Nkind (Parent (Inc)) =
5372 N_Incomplete_Type_Declaration
5374 -- Record location of premature use in entity so that
5375 -- a continuation message is generated when the
5376 -- completion is seen.
5378 Set_Premature_Use (Parent (Inc), N);
5384 Check_Misspelled_Selector (Type_To_Use, Sel);
5387 Set_Entity (Sel, Any_Id);
5388 Set_Etype (Sel, Any_Type);
5390 end Analyze_Selected_Component;
5392 ---------------------------
5393 -- Analyze_Short_Circuit --
5394 ---------------------------
5396 procedure Analyze_Short_Circuit (N : Node_Id) is
5397 L : constant Node_Id := Left_Opnd (N);
5398 R : constant Node_Id := Right_Opnd (N);
5403 Analyze_Expression (L);
5404 Analyze_Expression (R);
5405 Set_Etype (N, Any_Type);
5407 if not Is_Overloaded (L) then
5408 if Root_Type (Etype (L)) = Standard_Boolean
5409 and then Has_Compatible_Type (R, Etype (L))
5411 Add_One_Interp (N, Etype (L), Etype (L));
5415 Get_First_Interp (L, Ind, It);
5416 while Present (It.Typ) loop
5417 if Root_Type (It.Typ) = Standard_Boolean
5418 and then Has_Compatible_Type (R, It.Typ)
5420 Add_One_Interp (N, It.Typ, It.Typ);
5423 Get_Next_Interp (Ind, It);
5427 -- Here we have failed to find an interpretation. Clearly we know that
5428 -- it is not the case that both operands can have an interpretation of
5429 -- Boolean, but this is by far the most likely intended interpretation.
5430 -- So we simply resolve both operands as Booleans, and at least one of
5431 -- these resolutions will generate an error message, and we do not need
5432 -- to give another error message on the short circuit operation itself.
5434 if Etype (N) = Any_Type then
5435 Resolve (L, Standard_Boolean);
5436 Resolve (R, Standard_Boolean);
5437 Set_Etype (N, Standard_Boolean);
5439 end Analyze_Short_Circuit;
5445 procedure Analyze_Slice (N : Node_Id) is
5446 D : constant Node_Id := Discrete_Range (N);
5447 P : constant Node_Id := Prefix (N);
5448 Array_Type : Entity_Id;
5449 Index_Type : Entity_Id;
5451 procedure Analyze_Overloaded_Slice;
5452 -- If the prefix is overloaded, select those interpretations that
5453 -- yield a one-dimensional array type.
5455 ------------------------------
5456 -- Analyze_Overloaded_Slice --
5457 ------------------------------
5459 procedure Analyze_Overloaded_Slice is
5465 Set_Etype (N, Any_Type);
5467 Get_First_Interp (P, I, It);
5468 while Present (It.Nam) loop
5471 if Is_Access_Type (Typ) then
5472 Typ := Designated_Type (Typ);
5474 (Warn_On_Dereference, "?d?implicit dereference", N);
5477 if Is_Array_Type (Typ)
5478 and then Number_Dimensions (Typ) = 1
5479 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
5481 Add_One_Interp (N, Typ, Typ);
5484 Get_Next_Interp (I, It);
5487 if Etype (N) = Any_Type then
5488 Error_Msg_N ("expect array type in prefix of slice", N);
5490 end Analyze_Overloaded_Slice;
5492 -- Start of processing for Analyze_Slice
5495 if Comes_From_Source (N) then
5496 Check_SPARK_05_Restriction ("slice is not allowed", N);
5502 if Is_Overloaded (P) then
5503 Analyze_Overloaded_Slice;
5506 Array_Type := Etype (P);
5507 Set_Etype (N, Any_Type);
5509 if Is_Access_Type (Array_Type) then
5510 Array_Type := Designated_Type (Array_Type);
5511 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
5514 if not Is_Array_Type (Array_Type) then
5515 Wrong_Type (P, Any_Array);
5517 elsif Number_Dimensions (Array_Type) > 1 then
5519 ("type is not one-dimensional array in slice prefix", N);
5522 if Ekind (Array_Type) = E_String_Literal_Subtype then
5523 Index_Type := Etype (String_Literal_Low_Bound (Array_Type));
5525 Index_Type := Etype (First_Index (Array_Type));
5528 if not Has_Compatible_Type (D, Index_Type) then
5529 Wrong_Type (D, Index_Type);
5531 Set_Etype (N, Array_Type);
5537 -----------------------------
5538 -- Analyze_Type_Conversion --
5539 -----------------------------
5541 procedure Analyze_Type_Conversion (N : Node_Id) is
5542 Expr : constant Node_Id := Expression (N);
5546 -- If Conversion_OK is set, then the Etype is already set, and the only
5547 -- processing required is to analyze the expression. This is used to
5548 -- construct certain "illegal" conversions which are not allowed by Ada
5549 -- semantics, but can be handled by Gigi, see Sinfo for further details.
5551 if Conversion_OK (N) then
5556 -- Otherwise full type analysis is required, as well as some semantic
5557 -- checks to make sure the argument of the conversion is appropriate.
5559 Find_Type (Subtype_Mark (N));
5560 Typ := Entity (Subtype_Mark (N));
5562 Check_Fully_Declared (Typ, N);
5563 Analyze_Expression (Expr);
5564 Validate_Remote_Type_Type_Conversion (N);
5566 -- Only remaining step is validity checks on the argument. These
5567 -- are skipped if the conversion does not come from the source.
5569 if not Comes_From_Source (N) then
5572 -- If there was an error in a generic unit, no need to replicate the
5573 -- error message. Conversely, constant-folding in the generic may
5574 -- transform the argument of a conversion into a string literal, which
5575 -- is legal. Therefore the following tests are not performed in an
5576 -- instance. The same applies to an inlined body.
5578 elsif In_Instance or In_Inlined_Body then
5581 elsif Nkind (Expr) = N_Null then
5582 Error_Msg_N ("argument of conversion cannot be null", N);
5583 Error_Msg_N ("\use qualified expression instead", N);
5584 Set_Etype (N, Any_Type);
5586 elsif Nkind (Expr) = N_Aggregate then
5587 Error_Msg_N ("argument of conversion cannot be aggregate", N);
5588 Error_Msg_N ("\use qualified expression instead", N);
5590 elsif Nkind (Expr) = N_Allocator then
5591 Error_Msg_N ("argument of conversion cannot be an allocator", N);
5592 Error_Msg_N ("\use qualified expression instead", N);
5594 elsif Nkind (Expr) = N_String_Literal then
5595 Error_Msg_N ("argument of conversion cannot be string literal", N);
5596 Error_Msg_N ("\use qualified expression instead", N);
5598 elsif Nkind (Expr) = N_Character_Literal then
5599 if Ada_Version = Ada_83 then
5600 Resolve (Expr, Typ);
5602 Error_Msg_N ("argument of conversion cannot be character literal",
5604 Error_Msg_N ("\use qualified expression instead", N);
5607 elsif Nkind (Expr) = N_Attribute_Reference
5608 and then Nam_In (Attribute_Name (Expr), Name_Access,
5609 Name_Unchecked_Access,
5610 Name_Unrestricted_Access)
5612 Error_Msg_N ("argument of conversion cannot be access", N);
5613 Error_Msg_N ("\use qualified expression instead", N);
5616 -- A formal parameter of a specific tagged type whose related subprogram
5617 -- is subject to pragma Extensions_Visible with value "False" cannot
5618 -- appear in a class-wide conversion (SPARK RM 6.1.7(3)). Do not check
5619 -- internally generated expressions.
5621 if Is_Class_Wide_Type (Typ)
5622 and then Comes_From_Source (Expr)
5623 and then Is_EVF_Expression (Expr)
5626 ("formal parameter cannot be converted to class-wide type when "
5627 & "Extensions_Visible is False", Expr);
5629 end Analyze_Type_Conversion;
5631 ----------------------
5632 -- Analyze_Unary_Op --
5633 ----------------------
5635 procedure Analyze_Unary_Op (N : Node_Id) is
5636 R : constant Node_Id := Right_Opnd (N);
5637 Op_Id : Entity_Id := Entity (N);
5640 Set_Etype (N, Any_Type);
5641 Candidate_Type := Empty;
5643 Analyze_Expression (R);
5645 if Present (Op_Id) then
5646 if Ekind (Op_Id) = E_Operator then
5647 Find_Unary_Types (R, Op_Id, N);
5649 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5653 Op_Id := Get_Name_Entity_Id (Chars (N));
5654 while Present (Op_Id) loop
5655 if Ekind (Op_Id) = E_Operator then
5656 if No (Next_Entity (First_Entity (Op_Id))) then
5657 Find_Unary_Types (R, Op_Id, N);
5660 elsif Is_Overloadable (Op_Id) then
5661 Analyze_User_Defined_Unary_Op (N, Op_Id);
5664 Op_Id := Homonym (Op_Id);
5669 end Analyze_Unary_Op;
5671 ----------------------------------
5672 -- Analyze_Unchecked_Expression --
5673 ----------------------------------
5675 procedure Analyze_Unchecked_Expression (N : Node_Id) is
5677 Analyze (Expression (N), Suppress => All_Checks);
5678 Set_Etype (N, Etype (Expression (N)));
5679 Save_Interps (Expression (N), N);
5680 end Analyze_Unchecked_Expression;
5682 ---------------------------------------
5683 -- Analyze_Unchecked_Type_Conversion --
5684 ---------------------------------------
5686 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
5688 Find_Type (Subtype_Mark (N));
5689 Analyze_Expression (Expression (N));
5690 Set_Etype (N, Entity (Subtype_Mark (N)));
5691 end Analyze_Unchecked_Type_Conversion;
5693 ------------------------------------
5694 -- Analyze_User_Defined_Binary_Op --
5695 ------------------------------------
5697 procedure Analyze_User_Defined_Binary_Op
5702 -- Only do analysis if the operator Comes_From_Source, since otherwise
5703 -- the operator was generated by the expander, and all such operators
5704 -- always refer to the operators in package Standard.
5706 if Comes_From_Source (N) then
5708 F1 : constant Entity_Id := First_Formal (Op_Id);
5709 F2 : constant Entity_Id := Next_Formal (F1);
5712 -- Verify that Op_Id is a visible binary function. Note that since
5713 -- we know Op_Id is overloaded, potentially use visible means use
5714 -- visible for sure (RM 9.4(11)).
5716 if Ekind (Op_Id) = E_Function
5717 and then Present (F2)
5718 and then (Is_Immediately_Visible (Op_Id)
5719 or else Is_Potentially_Use_Visible (Op_Id))
5720 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
5721 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
5723 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5725 -- If the left operand is overloaded, indicate that the current
5726 -- type is a viable candidate. This is redundant in most cases,
5727 -- but for equality and comparison operators where the context
5728 -- does not impose a type on the operands, setting the proper
5729 -- type is necessary to avoid subsequent ambiguities during
5730 -- resolution, when both user-defined and predefined operators
5731 -- may be candidates.
5733 if Is_Overloaded (Left_Opnd (N)) then
5734 Set_Etype (Left_Opnd (N), Etype (F1));
5737 if Debug_Flag_E then
5738 Write_Str ("user defined operator ");
5739 Write_Name (Chars (Op_Id));
5740 Write_Str (" on node ");
5741 Write_Int (Int (N));
5747 end Analyze_User_Defined_Binary_Op;
5749 -----------------------------------
5750 -- Analyze_User_Defined_Unary_Op --
5751 -----------------------------------
5753 procedure Analyze_User_Defined_Unary_Op
5758 -- Only do analysis if the operator Comes_From_Source, since otherwise
5759 -- the operator was generated by the expander, and all such operators
5760 -- always refer to the operators in package Standard.
5762 if Comes_From_Source (N) then
5764 F : constant Entity_Id := First_Formal (Op_Id);
5767 -- Verify that Op_Id is a visible unary function. Note that since
5768 -- we know Op_Id is overloaded, potentially use visible means use
5769 -- visible for sure (RM 9.4(11)).
5771 if Ekind (Op_Id) = E_Function
5772 and then No (Next_Formal (F))
5773 and then (Is_Immediately_Visible (Op_Id)
5774 or else Is_Potentially_Use_Visible (Op_Id))
5775 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
5777 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5781 end Analyze_User_Defined_Unary_Op;
5783 ---------------------------
5784 -- Check_Arithmetic_Pair --
5785 ---------------------------
5787 procedure Check_Arithmetic_Pair
5788 (T1, T2 : Entity_Id;
5792 Op_Name : constant Name_Id := Chars (Op_Id);
5794 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
5795 -- Check whether the fixed-point type Typ has a user-defined operator
5796 -- (multiplication or division) that should hide the corresponding
5797 -- predefined operator. Used to implement Ada 2005 AI-264, to make
5798 -- such operators more visible and therefore useful.
5800 -- If the name of the operation is an expanded name with prefix
5801 -- Standard, the predefined universal fixed operator is available,
5802 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
5804 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
5805 -- Get specific type (i.e. non-universal type if there is one)
5811 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
5812 Bas : constant Entity_Id := Base_Type (Typ);
5818 -- If the universal_fixed operation is given explicitly the rule
5819 -- concerning primitive operations of the type do not apply.
5821 if Nkind (N) = N_Function_Call
5822 and then Nkind (Name (N)) = N_Expanded_Name
5823 and then Entity (Prefix (Name (N))) = Standard_Standard
5828 -- The operation is treated as primitive if it is declared in the
5829 -- same scope as the type, and therefore on the same entity chain.
5831 Ent := Next_Entity (Typ);
5832 while Present (Ent) loop
5833 if Chars (Ent) = Chars (Op) then
5834 F1 := First_Formal (Ent);
5835 F2 := Next_Formal (F1);
5837 -- The operation counts as primitive if either operand or
5838 -- result are of the given base type, and both operands are
5839 -- fixed point types.
5841 if (Base_Type (Etype (F1)) = Bas
5842 and then Is_Fixed_Point_Type (Etype (F2)))
5845 (Base_Type (Etype (F2)) = Bas
5846 and then Is_Fixed_Point_Type (Etype (F1)))
5849 (Base_Type (Etype (Ent)) = Bas
5850 and then Is_Fixed_Point_Type (Etype (F1))
5851 and then Is_Fixed_Point_Type (Etype (F2)))
5867 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
5869 if T1 = Universal_Integer or else T1 = Universal_Real then
5870 return Base_Type (T2);
5872 return Base_Type (T1);
5876 -- Start of processing for Check_Arithmetic_Pair
5879 if Nam_In (Op_Name, Name_Op_Add, Name_Op_Subtract) then
5880 if Is_Numeric_Type (T1)
5881 and then Is_Numeric_Type (T2)
5882 and then (Covers (T1 => T1, T2 => T2)
5884 Covers (T1 => T2, T2 => T1))
5886 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5889 elsif Nam_In (Op_Name, Name_Op_Multiply, Name_Op_Divide) then
5890 if Is_Fixed_Point_Type (T1)
5891 and then (Is_Fixed_Point_Type (T2) or else T2 = Universal_Real)
5893 -- If Treat_Fixed_As_Integer is set then the Etype is already set
5894 -- and no further processing is required (this is the case of an
5895 -- operator constructed by Exp_Fixd for a fixed point operation)
5896 -- Otherwise add one interpretation with universal fixed result
5897 -- If the operator is given in functional notation, it comes
5898 -- from source and Fixed_As_Integer cannot apply.
5900 if (Nkind (N) not in N_Op
5901 or else not Treat_Fixed_As_Integer (N))
5903 (not Has_Fixed_Op (T1, Op_Id)
5904 or else Nkind (Parent (N)) = N_Type_Conversion)
5906 Add_One_Interp (N, Op_Id, Universal_Fixed);
5909 elsif Is_Fixed_Point_Type (T2)
5910 and then (Nkind (N) not in N_Op
5911 or else not Treat_Fixed_As_Integer (N))
5912 and then T1 = Universal_Real
5914 (not Has_Fixed_Op (T1, Op_Id)
5915 or else Nkind (Parent (N)) = N_Type_Conversion)
5917 Add_One_Interp (N, Op_Id, Universal_Fixed);
5919 elsif Is_Numeric_Type (T1)
5920 and then Is_Numeric_Type (T2)
5921 and then (Covers (T1 => T1, T2 => T2)
5923 Covers (T1 => T2, T2 => T1))
5925 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5927 elsif Is_Fixed_Point_Type (T1)
5928 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5929 or else T2 = Universal_Integer)
5931 Add_One_Interp (N, Op_Id, T1);
5933 elsif T2 = Universal_Real
5934 and then Base_Type (T1) = Base_Type (Standard_Integer)
5935 and then Op_Name = Name_Op_Multiply
5937 Add_One_Interp (N, Op_Id, Any_Fixed);
5939 elsif T1 = Universal_Real
5940 and then Base_Type (T2) = Base_Type (Standard_Integer)
5942 Add_One_Interp (N, Op_Id, Any_Fixed);
5944 elsif Is_Fixed_Point_Type (T2)
5945 and then (Base_Type (T1) = Base_Type (Standard_Integer)
5946 or else T1 = Universal_Integer)
5947 and then Op_Name = Name_Op_Multiply
5949 Add_One_Interp (N, Op_Id, T2);
5951 elsif T1 = Universal_Real and then T2 = Universal_Integer then
5952 Add_One_Interp (N, Op_Id, T1);
5954 elsif T2 = Universal_Real
5955 and then T1 = Universal_Integer
5956 and then Op_Name = Name_Op_Multiply
5958 Add_One_Interp (N, Op_Id, T2);
5961 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
5963 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
5964 -- set does not require any special processing, since the Etype is
5965 -- already set (case of operation constructed by Exp_Fixed).
5967 if Is_Integer_Type (T1)
5968 and then (Covers (T1 => T1, T2 => T2)
5970 Covers (T1 => T2, T2 => T1))
5972 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5975 elsif Op_Name = Name_Op_Expon then
5976 if Is_Numeric_Type (T1)
5977 and then not Is_Fixed_Point_Type (T1)
5978 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5979 or else T2 = Universal_Integer)
5981 Add_One_Interp (N, Op_Id, Base_Type (T1));
5984 else pragma Assert (Nkind (N) in N_Op_Shift);
5986 -- If not one of the predefined operators, the node may be one
5987 -- of the intrinsic functions. Its kind is always specific, and
5988 -- we can use it directly, rather than the name of the operation.
5990 if Is_Integer_Type (T1)
5991 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5992 or else T2 = Universal_Integer)
5994 Add_One_Interp (N, Op_Id, Base_Type (T1));
5997 end Check_Arithmetic_Pair;
5999 -------------------------------
6000 -- Check_Misspelled_Selector --
6001 -------------------------------
6003 procedure Check_Misspelled_Selector
6004 (Prefix : Entity_Id;
6007 Max_Suggestions : constant := 2;
6008 Nr_Of_Suggestions : Natural := 0;
6010 Suggestion_1 : Entity_Id := Empty;
6011 Suggestion_2 : Entity_Id := Empty;
6016 -- All the components of the prefix of selector Sel are matched against
6017 -- Sel and a count is maintained of possible misspellings. When at
6018 -- the end of the analysis there are one or two (not more) possible
6019 -- misspellings, these misspellings will be suggested as possible
6022 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
6024 -- Concurrent types should be handled as well ???
6029 Comp := First_Entity (Prefix);
6030 while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
6031 if Is_Visible_Component (Comp, Sel) then
6032 if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
6033 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
6035 case Nr_Of_Suggestions is
6036 when 1 => Suggestion_1 := Comp;
6037 when 2 => Suggestion_2 := Comp;
6038 when others => null;
6043 Comp := Next_Entity (Comp);
6046 -- Report at most two suggestions
6048 if Nr_Of_Suggestions = 1 then
6049 Error_Msg_NE -- CODEFIX
6050 ("\possible misspelling of&", Sel, Suggestion_1);
6052 elsif Nr_Of_Suggestions = 2 then
6053 Error_Msg_Node_2 := Suggestion_2;
6054 Error_Msg_NE -- CODEFIX
6055 ("\possible misspelling of& or&", Sel, Suggestion_1);
6057 end Check_Misspelled_Selector;
6059 ----------------------
6060 -- Defined_In_Scope --
6061 ----------------------
6063 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
6065 S1 : constant Entity_Id := Scope (Base_Type (T));
6068 or else (S1 = System_Aux_Id and then S = Scope (S1));
6069 end Defined_In_Scope;
6075 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
6081 Void_Interp_Seen : Boolean := False;
6084 pragma Warnings (Off, Boolean);
6087 if Ada_Version >= Ada_2005 then
6088 Actual := First_Actual (N);
6089 while Present (Actual) loop
6091 -- Ada 2005 (AI-50217): Post an error in case of premature
6092 -- usage of an entity from the limited view.
6094 if not Analyzed (Etype (Actual))
6095 and then From_Limited_With (Etype (Actual))
6097 Error_Msg_Qual_Level := 1;
6099 ("missing with_clause for scope of imported type&",
6100 Actual, Etype (Actual));
6101 Error_Msg_Qual_Level := 0;
6104 Next_Actual (Actual);
6108 -- Before listing the possible candidates, check whether this is
6109 -- a prefix of a selected component that has been rewritten as a
6110 -- parameterless function call because there is a callable candidate
6111 -- interpretation. If there is a hidden package in the list of homonyms
6112 -- of the function name (bad programming style in any case) suggest that
6113 -- this is the intended entity.
6115 if No (Parameter_Associations (N))
6116 and then Nkind (Parent (N)) = N_Selected_Component
6117 and then Nkind (Parent (Parent (N))) in N_Declaration
6118 and then Is_Overloaded (Nam)
6124 Ent := Current_Entity (Nam);
6125 while Present (Ent) loop
6126 if Ekind (Ent) = E_Package then
6128 ("no legal interpretations as function call,!", Nam);
6129 Error_Msg_NE ("\package& is not visible", N, Ent);
6131 Rewrite (Parent (N),
6132 New_Occurrence_Of (Any_Type, Sloc (N)));
6136 Ent := Homonym (Ent);
6141 -- Analyze each candidate call again, with full error reporting for
6145 ("no candidate interpretations match the actuals:!", Nam);
6146 Err_Mode := All_Errors_Mode;
6147 All_Errors_Mode := True;
6149 -- If this is a call to an operation of a concurrent type,
6150 -- the failed interpretations have been removed from the
6151 -- name. Recover them to provide full diagnostics.
6153 if Nkind (Parent (Nam)) = N_Selected_Component then
6154 Set_Entity (Nam, Empty);
6155 New_Nam := New_Copy_Tree (Parent (Nam));
6156 Set_Is_Overloaded (New_Nam, False);
6157 Set_Is_Overloaded (Selector_Name (New_Nam), False);
6158 Set_Parent (New_Nam, Parent (Parent (Nam)));
6159 Analyze_Selected_Component (New_Nam);
6160 Get_First_Interp (Selector_Name (New_Nam), X, It);
6162 Get_First_Interp (Nam, X, It);
6165 while Present (It.Nam) loop
6166 if Etype (It.Nam) = Standard_Void_Type then
6167 Void_Interp_Seen := True;
6170 Analyze_One_Call (N, It.Nam, True, Success);
6171 Get_Next_Interp (X, It);
6174 if Nkind (N) = N_Function_Call then
6175 Get_First_Interp (Nam, X, It);
6178 and then Ekind (Entity (Name (N))) = E_Function
6179 and then Present (Homonym (Entity (Name (N))))
6181 -- A name may appear overloaded if it has a homonym, even if that
6182 -- homonym is non-overloadable, in which case the overload list is
6183 -- in fact empty. This specialized case deserves a special message
6184 -- if the homonym is a child package.
6187 Nam : constant Node_Id := Name (N);
6188 H : constant Entity_Id := Homonym (Entity (Nam));
6191 if Ekind (H) = E_Package and then Is_Child_Unit (H) then
6192 Error_Msg_Qual_Level := 2;
6193 Error_Msg_NE ("if an entity in package& is meant, ", Nam, H);
6194 Error_Msg_NE ("\use a fully qualified name", Nam, H);
6195 Error_Msg_Qual_Level := 0;
6200 while Present (It.Nam) loop
6201 if Ekind_In (It.Nam, E_Function, E_Operator) then
6204 Get_Next_Interp (X, It);
6208 -- If all interpretations are procedures, this deserves a more
6209 -- precise message. Ditto if this appears as the prefix of a
6210 -- selected component, which may be a lexical error.
6213 ("\context requires function call, found procedure name", Nam);
6215 if Nkind (Parent (N)) = N_Selected_Component
6216 and then N = Prefix (Parent (N))
6218 Error_Msg_N -- CODEFIX
6219 ("\period should probably be semicolon", Parent (N));
6223 elsif Nkind (N) = N_Procedure_Call_Statement
6224 and then not Void_Interp_Seen
6226 Error_Msg_N ("\function name found in procedure call", Nam);
6229 All_Errors_Mode := Err_Mode;
6232 ---------------------------
6233 -- Find_Arithmetic_Types --
6234 ---------------------------
6236 procedure Find_Arithmetic_Types
6241 Index1 : Interp_Index;
6242 Index2 : Interp_Index;
6246 procedure Check_Right_Argument (T : Entity_Id);
6247 -- Check right operand of operator
6249 --------------------------
6250 -- Check_Right_Argument --
6251 --------------------------
6253 procedure Check_Right_Argument (T : Entity_Id) is
6255 if not Is_Overloaded (R) then
6256 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
6258 Get_First_Interp (R, Index2, It2);
6259 while Present (It2.Typ) loop
6260 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
6261 Get_Next_Interp (Index2, It2);
6264 end Check_Right_Argument;
6266 -- Start of processing for Find_Arithmetic_Types
6269 if not Is_Overloaded (L) then
6270 Check_Right_Argument (Etype (L));
6273 Get_First_Interp (L, Index1, It1);
6274 while Present (It1.Typ) loop
6275 Check_Right_Argument (It1.Typ);
6276 Get_Next_Interp (Index1, It1);
6280 end Find_Arithmetic_Types;
6282 ------------------------
6283 -- Find_Boolean_Types --
6284 ------------------------
6286 procedure Find_Boolean_Types
6291 Index : Interp_Index;
6294 procedure Check_Numeric_Argument (T : Entity_Id);
6295 -- Special case for logical operations one of whose operands is an
6296 -- integer literal. If both are literal the result is any modular type.
6298 ----------------------------
6299 -- Check_Numeric_Argument --
6300 ----------------------------
6302 procedure Check_Numeric_Argument (T : Entity_Id) is
6304 if T = Universal_Integer then
6305 Add_One_Interp (N, Op_Id, Any_Modular);
6307 elsif Is_Modular_Integer_Type (T) then
6308 Add_One_Interp (N, Op_Id, T);
6310 end Check_Numeric_Argument;
6312 -- Start of processing for Find_Boolean_Types
6315 if not Is_Overloaded (L) then
6316 if Etype (L) = Universal_Integer
6317 or else Etype (L) = Any_Modular
6319 if not Is_Overloaded (R) then
6320 Check_Numeric_Argument (Etype (R));
6323 Get_First_Interp (R, Index, It);
6324 while Present (It.Typ) loop
6325 Check_Numeric_Argument (It.Typ);
6326 Get_Next_Interp (Index, It);
6330 -- If operands are aggregates, we must assume that they may be
6331 -- boolean arrays, and leave disambiguation for the second pass.
6332 -- If only one is an aggregate, verify that the other one has an
6333 -- interpretation as a boolean array
6335 elsif Nkind (L) = N_Aggregate then
6336 if Nkind (R) = N_Aggregate then
6337 Add_One_Interp (N, Op_Id, Etype (L));
6339 elsif not Is_Overloaded (R) then
6340 if Valid_Boolean_Arg (Etype (R)) then
6341 Add_One_Interp (N, Op_Id, Etype (R));
6345 Get_First_Interp (R, Index, It);
6346 while Present (It.Typ) loop
6347 if Valid_Boolean_Arg (It.Typ) then
6348 Add_One_Interp (N, Op_Id, It.Typ);
6351 Get_Next_Interp (Index, It);
6355 elsif Valid_Boolean_Arg (Etype (L))
6356 and then Has_Compatible_Type (R, Etype (L))
6358 Add_One_Interp (N, Op_Id, Etype (L));
6362 Get_First_Interp (L, Index, It);
6363 while Present (It.Typ) loop
6364 if Valid_Boolean_Arg (It.Typ)
6365 and then Has_Compatible_Type (R, It.Typ)
6367 Add_One_Interp (N, Op_Id, It.Typ);
6370 Get_Next_Interp (Index, It);
6373 end Find_Boolean_Types;
6375 ---------------------------
6376 -- Find_Comparison_Types --
6377 ---------------------------
6379 procedure Find_Comparison_Types
6384 Index : Interp_Index;
6386 Found : Boolean := False;
6389 Scop : Entity_Id := Empty;
6391 procedure Try_One_Interp (T1 : Entity_Id);
6392 -- Routine to try one proposed interpretation. Note that the context
6393 -- of the operator plays no role in resolving the arguments, so that
6394 -- if there is more than one interpretation of the operands that is
6395 -- compatible with comparison, the operation is ambiguous.
6397 --------------------
6398 -- Try_One_Interp --
6399 --------------------
6401 procedure Try_One_Interp (T1 : Entity_Id) is
6403 -- If the operator is an expanded name, then the type of the operand
6404 -- must be defined in the corresponding scope. If the type is
6405 -- universal, the context will impose the correct type. Note that we
6406 -- also avoid returning if we are currently within a generic instance
6407 -- due to the fact that the generic package declaration has already
6408 -- been successfully analyzed and Defined_In_Scope expects the base
6409 -- type to be defined within the instance which will never be the
6413 and then not Defined_In_Scope (T1, Scop)
6414 and then not In_Instance
6415 and then T1 /= Universal_Integer
6416 and then T1 /= Universal_Real
6417 and then T1 /= Any_String
6418 and then T1 /= Any_Composite
6423 if Valid_Comparison_Arg (T1) and then Has_Compatible_Type (R, T1) then
6424 if Found and then Base_Type (T1) /= Base_Type (T_F) then
6425 It := Disambiguate (L, I_F, Index, Any_Type);
6427 if It = No_Interp then
6428 Ambiguous_Operands (N);
6429 Set_Etype (L, Any_Type);
6442 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
6446 -- Start of processing for Find_Comparison_Types
6449 -- If left operand is aggregate, the right operand has to
6450 -- provide a usable type for it.
6452 if Nkind (L) = N_Aggregate and then Nkind (R) /= N_Aggregate then
6453 Find_Comparison_Types (L => R, R => L, Op_Id => Op_Id, N => N);
6457 if Nkind (N) = N_Function_Call
6458 and then Nkind (Name (N)) = N_Expanded_Name
6460 Scop := Entity (Prefix (Name (N)));
6462 -- The prefix may be a package renaming, and the subsequent test
6463 -- requires the original package.
6465 if Ekind (Scop) = E_Package
6466 and then Present (Renamed_Entity (Scop))
6468 Scop := Renamed_Entity (Scop);
6469 Set_Entity (Prefix (Name (N)), Scop);
6473 if not Is_Overloaded (L) then
6474 Try_One_Interp (Etype (L));
6477 Get_First_Interp (L, Index, It);
6478 while Present (It.Typ) loop
6479 Try_One_Interp (It.Typ);
6480 Get_Next_Interp (Index, It);
6483 end Find_Comparison_Types;
6485 ----------------------------------------
6486 -- Find_Non_Universal_Interpretations --
6487 ----------------------------------------
6489 procedure Find_Non_Universal_Interpretations
6495 Index : Interp_Index;
6499 if T1 = Universal_Integer or else T1 = Universal_Real
6501 -- If the left operand of an equality operator is null, the visibility
6502 -- of the operator must be determined from the interpretation of the
6503 -- right operand. This processing must be done for Any_Access, which
6504 -- is the internal representation of the type of the literal null.
6506 or else T1 = Any_Access
6508 if not Is_Overloaded (R) then
6509 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
6511 Get_First_Interp (R, Index, It);
6512 while Present (It.Typ) loop
6513 if Covers (It.Typ, T1) then
6515 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
6518 Get_Next_Interp (Index, It);
6522 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
6524 end Find_Non_Universal_Interpretations;
6526 ------------------------------
6527 -- Find_Concatenation_Types --
6528 ------------------------------
6530 procedure Find_Concatenation_Types
6535 Is_String : constant Boolean := Nkind (L) = N_String_Literal
6537 Nkind (R) = N_String_Literal;
6538 Op_Type : constant Entity_Id := Etype (Op_Id);
6541 if Is_Array_Type (Op_Type)
6543 -- Small but very effective optimization: if at least one operand is a
6544 -- string literal, then the type of the operator must be either array
6545 -- of characters or array of strings.
6547 and then (not Is_String
6549 Is_Character_Type (Component_Type (Op_Type))
6551 Is_String_Type (Component_Type (Op_Type)))
6553 and then not Is_Limited_Type (Op_Type)
6555 and then (Has_Compatible_Type (L, Op_Type)
6557 Has_Compatible_Type (L, Component_Type (Op_Type)))
6559 and then (Has_Compatible_Type (R, Op_Type)
6561 Has_Compatible_Type (R, Component_Type (Op_Type)))
6563 Add_One_Interp (N, Op_Id, Op_Type);
6565 end Find_Concatenation_Types;
6567 -------------------------
6568 -- Find_Equality_Types --
6569 -------------------------
6571 procedure Find_Equality_Types
6576 Index : Interp_Index;
6578 Found : Boolean := False;
6581 Scop : Entity_Id := Empty;
6583 procedure Try_One_Interp (T1 : Entity_Id);
6584 -- The context of the equality operator plays no role in resolving the
6585 -- arguments, so that if there is more than one interpretation of the
6586 -- operands that is compatible with equality, the construct is ambiguous
6587 -- and an error can be emitted now, after trying to disambiguate, i.e.
6588 -- applying preference rules.
6590 --------------------
6591 -- Try_One_Interp --
6592 --------------------
6594 procedure Try_One_Interp (T1 : Entity_Id) is
6598 -- Perform a sanity check in case of previous errors
6604 Bas := Base_Type (T1);
6606 -- If the operator is an expanded name, then the type of the operand
6607 -- must be defined in the corresponding scope. If the type is
6608 -- universal, the context will impose the correct type. An anonymous
6609 -- type for a 'Access reference is also universal in this sense, as
6610 -- the actual type is obtained from context.
6612 -- In Ada 2005, the equality operator for anonymous access types
6613 -- is declared in Standard, and preference rules apply to it.
6615 if Present (Scop) then
6617 -- Note that we avoid returning if we are currently within a
6618 -- generic instance due to the fact that the generic package
6619 -- declaration has already been successfully analyzed and
6620 -- Defined_In_Scope expects the base type to be defined within
6621 -- the instance which will never be the case.
6623 if Defined_In_Scope (T1, Scop)
6625 or else T1 = Universal_Integer
6626 or else T1 = Universal_Real
6627 or else T1 = Any_Access
6628 or else T1 = Any_String
6629 or else T1 = Any_Composite
6630 or else (Ekind (T1) = E_Access_Subprogram_Type
6631 and then not Comes_From_Source (T1))
6635 elsif Ekind (T1) = E_Anonymous_Access_Type
6636 and then Scop = Standard_Standard
6641 -- The scope does not contain an operator for the type
6646 -- If we have infix notation, the operator must be usable. Within
6647 -- an instance, if the type is already established we know it is
6648 -- correct. If an operand is universal it is compatible with any
6651 elsif In_Open_Scopes (Scope (Bas))
6652 or else Is_Potentially_Use_Visible (Bas)
6653 or else In_Use (Bas)
6654 or else (In_Use (Scope (Bas)) and then not Is_Hidden (Bas))
6656 -- In an instance, the type may have been immediately visible.
6657 -- Either the types are compatible, or one operand is universal
6658 -- (numeric or null).
6661 ((In_Instance or else In_Inlined_Body)
6663 (First_Subtype (T1) = First_Subtype (Etype (R))
6664 or else Nkind (R) = N_Null
6666 (Is_Numeric_Type (T1)
6667 and then Is_Universal_Numeric_Type (Etype (R)))))
6669 -- In Ada 2005, the equality on anonymous access types is declared
6670 -- in Standard, and is always visible.
6672 or else Ekind (T1) = E_Anonymous_Access_Type
6677 -- Save candidate type for subsequent error message, if any
6679 if not Is_Limited_Type (T1) then
6680 Candidate_Type := T1;
6686 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
6687 -- Do not allow anonymous access types in equality operators.
6689 if Ada_Version < Ada_2005
6690 and then Ekind (T1) = E_Anonymous_Access_Type
6695 -- If the right operand has a type compatible with T1, check for an
6696 -- acceptable interpretation, unless T1 is limited (no predefined
6697 -- equality available), or this is use of a "/=" for a tagged type.
6698 -- In the latter case, possible interpretations of equality need
6699 -- to be considered, we don't want the default inequality declared
6700 -- in Standard to be chosen, and the "/=" will be rewritten as a
6701 -- negation of "=" (see the end of Analyze_Equality_Op). This ensures
6702 -- that rewriting happens during analysis rather than being
6703 -- delayed until expansion (this is needed for ASIS, which only sees
6704 -- the unexpanded tree). Note that if the node is N_Op_Ne, but Op_Id
6705 -- is Name_Op_Eq then we still proceed with the interpretation,
6706 -- because that indicates the potential rewriting case where the
6707 -- interpretation to consider is actually "=" and the node may be
6708 -- about to be rewritten by Analyze_Equality_Op.
6710 if T1 /= Standard_Void_Type
6711 and then Has_Compatible_Type (R, T1)
6714 ((not Is_Limited_Type (T1)
6715 and then not Is_Limited_Composite (T1))
6719 and then not Is_Limited_Type (Component_Type (T1))
6720 and then Available_Full_View_Of_Component (T1)))
6723 (Nkind (N) /= N_Op_Ne
6724 or else not Is_Tagged_Type (T1)
6725 or else Chars (Op_Id) = Name_Op_Eq)
6728 and then Base_Type (T1) /= Base_Type (T_F)
6730 It := Disambiguate (L, I_F, Index, Any_Type);
6732 if It = No_Interp then
6733 Ambiguous_Operands (N);
6734 Set_Etype (L, Any_Type);
6747 if not Analyzed (L) then
6751 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
6753 -- Case of operator was not visible, Etype still set to Any_Type
6755 if Etype (N) = Any_Type then
6759 elsif Scop = Standard_Standard
6760 and then Ekind (T1) = E_Anonymous_Access_Type
6766 -- Start of processing for Find_Equality_Types
6769 -- If left operand is aggregate, the right operand has to
6770 -- provide a usable type for it.
6772 if Nkind (L) = N_Aggregate
6773 and then Nkind (R) /= N_Aggregate
6775 Find_Equality_Types (L => R, R => L, Op_Id => Op_Id, N => N);
6779 if Nkind (N) = N_Function_Call
6780 and then Nkind (Name (N)) = N_Expanded_Name
6782 Scop := Entity (Prefix (Name (N)));
6784 -- The prefix may be a package renaming, and the subsequent test
6785 -- requires the original package.
6787 if Ekind (Scop) = E_Package
6788 and then Present (Renamed_Entity (Scop))
6790 Scop := Renamed_Entity (Scop);
6791 Set_Entity (Prefix (Name (N)), Scop);
6795 if not Is_Overloaded (L) then
6796 Try_One_Interp (Etype (L));
6799 Get_First_Interp (L, Index, It);
6800 while Present (It.Typ) loop
6801 Try_One_Interp (It.Typ);
6802 Get_Next_Interp (Index, It);
6805 end Find_Equality_Types;
6807 -------------------------
6808 -- Find_Negation_Types --
6809 -------------------------
6811 procedure Find_Negation_Types
6816 Index : Interp_Index;
6820 if not Is_Overloaded (R) then
6821 if Etype (R) = Universal_Integer then
6822 Add_One_Interp (N, Op_Id, Any_Modular);
6823 elsif Valid_Boolean_Arg (Etype (R)) then
6824 Add_One_Interp (N, Op_Id, Etype (R));
6828 Get_First_Interp (R, Index, It);
6829 while Present (It.Typ) loop
6830 if Valid_Boolean_Arg (It.Typ) then
6831 Add_One_Interp (N, Op_Id, It.Typ);
6834 Get_Next_Interp (Index, It);
6837 end Find_Negation_Types;
6839 ------------------------------
6840 -- Find_Primitive_Operation --
6841 ------------------------------
6843 function Find_Primitive_Operation (N : Node_Id) return Boolean is
6844 Obj : constant Node_Id := Prefix (N);
6845 Op : constant Node_Id := Selector_Name (N);
6852 Set_Etype (Op, Any_Type);
6854 if Is_Access_Type (Etype (Obj)) then
6855 Typ := Designated_Type (Etype (Obj));
6860 if Is_Class_Wide_Type (Typ) then
6861 Typ := Root_Type (Typ);
6864 Prims := Primitive_Operations (Typ);
6866 Prim := First_Elmt (Prims);
6867 while Present (Prim) loop
6868 if Chars (Node (Prim)) = Chars (Op) then
6869 Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
6870 Set_Etype (N, Etype (Node (Prim)));
6876 -- Now look for class-wide operations of the type or any of its
6877 -- ancestors by iterating over the homonyms of the selector.
6880 Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
6884 Hom := Current_Entity (Op);
6885 while Present (Hom) loop
6886 if (Ekind (Hom) = E_Procedure
6888 Ekind (Hom) = E_Function)
6889 and then Scope (Hom) = Scope (Typ)
6890 and then Present (First_Formal (Hom))
6892 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
6894 (Is_Access_Type (Etype (First_Formal (Hom)))
6896 Ekind (Etype (First_Formal (Hom))) =
6897 E_Anonymous_Access_Type
6900 (Designated_Type (Etype (First_Formal (Hom)))) =
6903 Add_One_Interp (Op, Hom, Etype (Hom));
6904 Set_Etype (N, Etype (Hom));
6907 Hom := Homonym (Hom);
6911 return Etype (Op) /= Any_Type;
6912 end Find_Primitive_Operation;
6914 ----------------------
6915 -- Find_Unary_Types --
6916 ----------------------
6918 procedure Find_Unary_Types
6923 Index : Interp_Index;
6927 if not Is_Overloaded (R) then
6928 if Is_Numeric_Type (Etype (R)) then
6930 -- In an instance a generic actual may be a numeric type even if
6931 -- the formal in the generic unit was not. In that case, the
6932 -- predefined operator was not a possible interpretation in the
6933 -- generic, and cannot be one in the instance, unless the operator
6934 -- is an actual of an instance.
6938 not Is_Numeric_Type (Corresponding_Generic_Type (Etype (R)))
6942 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
6947 Get_First_Interp (R, Index, It);
6948 while Present (It.Typ) loop
6949 if Is_Numeric_Type (It.Typ) then
6953 (Corresponding_Generic_Type (Etype (It.Typ)))
6958 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
6962 Get_Next_Interp (Index, It);
6965 end Find_Unary_Types;
6971 function Junk_Operand (N : Node_Id) return Boolean is
6975 if Error_Posted (N) then
6979 -- Get entity to be tested
6981 if Is_Entity_Name (N)
6982 and then Present (Entity (N))
6986 -- An odd case, a procedure name gets converted to a very peculiar
6987 -- function call, and here is where we detect this happening.
6989 elsif Nkind (N) = N_Function_Call
6990 and then Is_Entity_Name (Name (N))
6991 and then Present (Entity (Name (N)))
6995 -- Another odd case, there are at least some cases of selected
6996 -- components where the selected component is not marked as having
6997 -- an entity, even though the selector does have an entity
6999 elsif Nkind (N) = N_Selected_Component
7000 and then Present (Entity (Selector_Name (N)))
7002 Enode := Selector_Name (N);
7008 -- Now test the entity we got to see if it is a bad case
7010 case Ekind (Entity (Enode)) is
7013 ("package name cannot be used as operand", Enode);
7015 when Generic_Unit_Kind =>
7017 ("generic unit name cannot be used as operand", Enode);
7021 ("subtype name cannot be used as operand", Enode);
7025 ("entry name cannot be used as operand", Enode);
7029 ("procedure name cannot be used as operand", Enode);
7033 ("exception name cannot be used as operand", Enode);
7040 ("label name cannot be used as operand", Enode);
7049 --------------------
7050 -- Operator_Check --
7051 --------------------
7053 procedure Operator_Check (N : Node_Id) is
7055 Remove_Abstract_Operations (N);
7057 -- Test for case of no interpretation found for operator
7059 if Etype (N) = Any_Type then
7063 Op_Id : Entity_Id := Empty;
7066 R := Right_Opnd (N);
7068 if Nkind (N) in N_Binary_Op then
7074 -- If either operand has no type, then don't complain further,
7075 -- since this simply means that we have a propagated error.
7078 or else Etype (R) = Any_Type
7079 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
7081 -- For the rather unusual case where one of the operands is
7082 -- a Raise_Expression, whose initial type is Any_Type, use
7083 -- the type of the other operand.
7085 if Nkind (L) = N_Raise_Expression then
7086 Set_Etype (L, Etype (R));
7087 Set_Etype (N, Etype (R));
7089 elsif Nkind (R) = N_Raise_Expression then
7090 Set_Etype (R, Etype (L));
7091 Set_Etype (N, Etype (L));
7096 -- We explicitly check for the case of concatenation of component
7097 -- with component to avoid reporting spurious matching array types
7098 -- that might happen to be lurking in distant packages (such as
7099 -- run-time packages). This also prevents inconsistencies in the
7100 -- messages for certain ACVC B tests, which can vary depending on
7101 -- types declared in run-time interfaces. Another improvement when
7102 -- aggregates are present is to look for a well-typed operand.
7104 elsif Present (Candidate_Type)
7105 and then (Nkind (N) /= N_Op_Concat
7106 or else Is_Array_Type (Etype (L))
7107 or else Is_Array_Type (Etype (R)))
7109 if Nkind (N) = N_Op_Concat then
7110 if Etype (L) /= Any_Composite
7111 and then Is_Array_Type (Etype (L))
7113 Candidate_Type := Etype (L);
7115 elsif Etype (R) /= Any_Composite
7116 and then Is_Array_Type (Etype (R))
7118 Candidate_Type := Etype (R);
7122 Error_Msg_NE -- CODEFIX
7123 ("operator for} is not directly visible!",
7124 N, First_Subtype (Candidate_Type));
7127 U : constant Node_Id :=
7128 Cunit (Get_Source_Unit (Candidate_Type));
7130 if Unit_Is_Visible (U) then
7131 Error_Msg_N -- CODEFIX
7132 ("use clause would make operation legal!", N);
7134 Error_Msg_NE -- CODEFIX
7135 ("add with_clause and use_clause for&!",
7136 N, Defining_Entity (Unit (U)));
7141 -- If either operand is a junk operand (e.g. package name), then
7142 -- post appropriate error messages, but do not complain further.
7144 -- Note that the use of OR in this test instead of OR ELSE is
7145 -- quite deliberate, we may as well check both operands in the
7146 -- binary operator case.
7148 elsif Junk_Operand (R)
7149 or -- really mean OR here and not OR ELSE, see above
7150 (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
7154 -- If we have a logical operator, one of whose operands is
7155 -- Boolean, then we know that the other operand cannot resolve to
7156 -- Boolean (since we got no interpretations), but in that case we
7157 -- pretty much know that the other operand should be Boolean, so
7158 -- resolve it that way (generating an error).
7160 elsif Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor) then
7161 if Etype (L) = Standard_Boolean then
7162 Resolve (R, Standard_Boolean);
7164 elsif Etype (R) = Standard_Boolean then
7165 Resolve (L, Standard_Boolean);
7169 -- For an arithmetic operator or comparison operator, if one
7170 -- of the operands is numeric, then we know the other operand
7171 -- is not the same numeric type. If it is a non-numeric type,
7172 -- then probably it is intended to match the other operand.
7174 elsif Nkind_In (N, N_Op_Add,
7180 Nkind_In (N, N_Op_Lt,
7186 -- If Allow_Integer_Address is active, check whether the
7187 -- operation becomes legal after converting an operand.
7189 if Is_Numeric_Type (Etype (L))
7190 and then not Is_Numeric_Type (Etype (R))
7192 if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
7194 Unchecked_Convert_To (Etype (L), Relocate_Node (R)));
7196 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
7197 Analyze_Comparison_Op (N);
7199 Analyze_Arithmetic_Op (N);
7202 Resolve (R, Etype (L));
7207 elsif Is_Numeric_Type (Etype (R))
7208 and then not Is_Numeric_Type (Etype (L))
7210 if Address_Integer_Convert_OK (Etype (L), Etype (R)) then
7212 Unchecked_Convert_To (Etype (R), Relocate_Node (L)));
7214 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
7215 Analyze_Comparison_Op (N);
7217 Analyze_Arithmetic_Op (N);
7223 Resolve (L, Etype (R));
7228 elsif Allow_Integer_Address
7229 and then Is_Descendant_Of_Address (Etype (L))
7230 and then Is_Descendant_Of_Address (Etype (R))
7231 and then not Error_Posted (N)
7234 Addr_Type : constant Entity_Id := Etype (L);
7238 Unchecked_Convert_To (
7239 Standard_Integer, Relocate_Node (L)));
7241 Unchecked_Convert_To (
7242 Standard_Integer, Relocate_Node (R)));
7244 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
7245 Analyze_Comparison_Op (N);
7247 Analyze_Arithmetic_Op (N);
7250 -- If this is an operand in an enclosing arithmetic
7251 -- operation, Convert the result as an address so that
7252 -- arithmetic folding of address can continue.
7254 if Nkind (Parent (N)) in N_Op then
7256 Unchecked_Convert_To (Addr_Type, Relocate_Node (N)));
7262 -- Under relaxed RM semantics silently replace occurrences of
7263 -- null by System.Address_Null.
7265 elsif Null_To_Null_Address_Convert_OK (N) then
7266 Replace_Null_By_Null_Address (N);
7268 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
7269 Analyze_Comparison_Op (N);
7271 Analyze_Arithmetic_Op (N);
7277 -- Comparisons on A'Access are common enough to deserve a
7280 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne)
7281 and then Ekind (Etype (L)) = E_Access_Attribute_Type
7282 and then Ekind (Etype (R)) = E_Access_Attribute_Type
7285 ("two access attributes cannot be compared directly", N);
7287 ("\use qualified expression for one of the operands",
7291 -- Another one for C programmers
7293 elsif Nkind (N) = N_Op_Concat
7294 and then Valid_Boolean_Arg (Etype (L))
7295 and then Valid_Boolean_Arg (Etype (R))
7297 Error_Msg_N ("invalid operands for concatenation", N);
7298 Error_Msg_N -- CODEFIX
7299 ("\maybe AND was meant", N);
7302 -- A special case for comparison of access parameter with null
7304 elsif Nkind (N) = N_Op_Eq
7305 and then Is_Entity_Name (L)
7306 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
7307 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
7309 and then Nkind (R) = N_Null
7311 Error_Msg_N ("access parameter is not allowed to be null", L);
7312 Error_Msg_N ("\(call would raise Constraint_Error)", L);
7315 -- Another special case for exponentiation, where the right
7316 -- operand must be Natural, independently of the base.
7318 elsif Nkind (N) = N_Op_Expon
7319 and then Is_Numeric_Type (Etype (L))
7320 and then not Is_Overloaded (R)
7322 First_Subtype (Base_Type (Etype (R))) /= Standard_Integer
7323 and then Base_Type (Etype (R)) /= Universal_Integer
7325 if Ada_Version >= Ada_2012
7326 and then Has_Dimension_System (Etype (L))
7329 ("exponent for dimensioned type must be a rational" &
7330 ", found}", R, Etype (R));
7333 ("exponent must be of type Natural, found}", R, Etype (R));
7338 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
7339 if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
7341 Unchecked_Convert_To (Etype (L), Relocate_Node (R)));
7342 Analyze_Equality_Op (N);
7345 -- Under relaxed RM semantics silently replace occurrences of
7346 -- null by System.Address_Null.
7348 elsif Null_To_Null_Address_Convert_OK (N) then
7349 Replace_Null_By_Null_Address (N);
7350 Analyze_Equality_Op (N);
7355 -- If we fall through then just give general message. Note that in
7356 -- the following messages, if the operand is overloaded we choose
7357 -- an arbitrary type to complain about, but that is probably more
7358 -- useful than not giving a type at all.
7360 if Nkind (N) in N_Unary_Op then
7361 Error_Msg_Node_2 := Etype (R);
7362 Error_Msg_N ("operator& not defined for}", N);
7366 if Nkind (N) in N_Binary_Op then
7367 if not Is_Overloaded (L)
7368 and then not Is_Overloaded (R)
7369 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
7371 Error_Msg_Node_2 := First_Subtype (Etype (R));
7372 Error_Msg_N ("there is no applicable operator& for}", N);
7375 -- Another attempt to find a fix: one of the candidate
7376 -- interpretations may not be use-visible. This has
7377 -- already been checked for predefined operators, so
7378 -- we examine only user-defined functions.
7380 Op_Id := Get_Name_Entity_Id (Chars (N));
7382 while Present (Op_Id) loop
7383 if Ekind (Op_Id) /= E_Operator
7384 and then Is_Overloadable (Op_Id)
7386 if not Is_Immediately_Visible (Op_Id)
7387 and then not In_Use (Scope (Op_Id))
7388 and then not Is_Abstract_Subprogram (Op_Id)
7389 and then not Is_Hidden (Op_Id)
7390 and then Ekind (Scope (Op_Id)) = E_Package
7393 (L, Etype (First_Formal (Op_Id)))
7395 (Next_Formal (First_Formal (Op_Id)))
7399 Etype (Next_Formal (First_Formal (Op_Id))))
7402 ("no legal interpretation for operator&", N);
7404 ("\use clause on& would make operation legal",
7410 Op_Id := Homonym (Op_Id);
7414 Error_Msg_N ("invalid operand types for operator&", N);
7416 if Nkind (N) /= N_Op_Concat then
7417 Error_Msg_NE ("\left operand has}!", N, Etype (L));
7418 Error_Msg_NE ("\right operand has}!", N, Etype (R));
7420 -- For multiplication and division operators with
7421 -- a fixed-point operand and an integer operand,
7422 -- indicate that the integer operand should be of
7425 if Nkind_In (N, N_Op_Multiply, N_Op_Divide)
7426 and then Is_Fixed_Point_Type (Etype (L))
7427 and then Is_Integer_Type (Etype (R))
7430 ("\convert right operand to `Integer`", N);
7432 elsif Nkind (N) = N_Op_Multiply
7433 and then Is_Fixed_Point_Type (Etype (R))
7434 and then Is_Integer_Type (Etype (L))
7437 ("\convert left operand to `Integer`", N);
7440 -- For concatenation operators it is more difficult to
7441 -- determine which is the wrong operand. It is worth
7442 -- flagging explicitly an access type, for those who
7443 -- might think that a dereference happens here.
7445 elsif Is_Access_Type (Etype (L)) then
7446 Error_Msg_N ("\left operand is access type", N);
7448 elsif Is_Access_Type (Etype (R)) then
7449 Error_Msg_N ("\right operand is access type", N);
7459 -----------------------------------------
7460 -- Process_Implicit_Dereference_Prefix --
7461 -----------------------------------------
7463 function Process_Implicit_Dereference_Prefix
7465 P : Entity_Id) return Entity_Id
7468 Typ : constant Entity_Id := Designated_Type (Etype (P));
7472 and then (Operating_Mode = Check_Semantics or else not Expander_Active)
7474 -- We create a dummy reference to E to ensure that the reference is
7475 -- not considered as part of an assignment (an implicit dereference
7476 -- can never assign to its prefix). The Comes_From_Source attribute
7477 -- needs to be propagated for accurate warnings.
7479 Ref := New_Occurrence_Of (E, Sloc (P));
7480 Set_Comes_From_Source (Ref, Comes_From_Source (P));
7481 Generate_Reference (E, Ref);
7484 -- An implicit dereference is a legal occurrence of an incomplete type
7485 -- imported through a limited_with clause, if the full view is visible.
7487 if From_Limited_With (Typ)
7488 and then not From_Limited_With (Scope (Typ))
7490 (Is_Immediately_Visible (Scope (Typ))
7492 (Is_Child_Unit (Scope (Typ))
7493 and then Is_Visible_Lib_Unit (Scope (Typ))))
7495 return Available_View (Typ);
7499 end Process_Implicit_Dereference_Prefix;
7501 --------------------------------
7502 -- Remove_Abstract_Operations --
7503 --------------------------------
7505 procedure Remove_Abstract_Operations (N : Node_Id) is
7506 Abstract_Op : Entity_Id := Empty;
7507 Address_Descendant : Boolean := False;
7511 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
7512 -- activate this if either extensions are enabled, or if the abstract
7513 -- operation in question comes from a predefined file. This latter test
7514 -- allows us to use abstract to make operations invisible to users. In
7515 -- particular, if type Address is non-private and abstract subprograms
7516 -- are used to hide its operators, they will be truly hidden.
7518 type Operand_Position is (First_Op, Second_Op);
7519 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
7521 procedure Remove_Address_Interpretations (Op : Operand_Position);
7522 -- Ambiguities may arise when the operands are literal and the address
7523 -- operations in s-auxdec are visible. In that case, remove the
7524 -- interpretation of a literal as Address, to retain the semantics
7525 -- of Address as a private type.
7527 ------------------------------------
7528 -- Remove_Address_Interpretations --
7529 ------------------------------------
7531 procedure Remove_Address_Interpretations (Op : Operand_Position) is
7535 if Is_Overloaded (N) then
7536 Get_First_Interp (N, I, It);
7537 while Present (It.Nam) loop
7538 Formal := First_Entity (It.Nam);
7540 if Op = Second_Op then
7541 Formal := Next_Entity (Formal);
7544 if Is_Descendant_Of_Address (Etype (Formal)) then
7545 Address_Descendant := True;
7549 Get_Next_Interp (I, It);
7552 end Remove_Address_Interpretations;
7554 -- Start of processing for Remove_Abstract_Operations
7557 if Is_Overloaded (N) then
7558 if Debug_Flag_V then
7559 Write_Line ("Remove_Abstract_Operations: ");
7560 Write_Overloads (N);
7563 Get_First_Interp (N, I, It);
7565 while Present (It.Nam) loop
7566 if Is_Overloadable (It.Nam)
7567 and then Is_Abstract_Subprogram (It.Nam)
7568 and then not Is_Dispatching_Operation (It.Nam)
7570 Abstract_Op := It.Nam;
7572 if Is_Descendant_Of_Address (It.Typ) then
7573 Address_Descendant := True;
7577 -- In Ada 2005, this operation does not participate in overload
7578 -- resolution. If the operation is defined in a predefined
7579 -- unit, it is one of the operations declared abstract in some
7580 -- variants of System, and it must be removed as well.
7582 elsif Ada_Version >= Ada_2005
7583 or else In_Predefined_Unit (It.Nam)
7590 Get_Next_Interp (I, It);
7593 if No (Abstract_Op) then
7595 -- If some interpretation yields an integer type, it is still
7596 -- possible that there are address interpretations. Remove them
7597 -- if one operand is a literal, to avoid spurious ambiguities
7598 -- on systems where Address is a visible integer type.
7600 if Is_Overloaded (N)
7601 and then Nkind (N) in N_Op
7602 and then Is_Integer_Type (Etype (N))
7604 if Nkind (N) in N_Binary_Op then
7605 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
7606 Remove_Address_Interpretations (Second_Op);
7608 elsif Nkind (Left_Opnd (N)) = N_Integer_Literal then
7609 Remove_Address_Interpretations (First_Op);
7614 elsif Nkind (N) in N_Op then
7616 -- Remove interpretations that treat literals as addresses. This
7617 -- is never appropriate, even when Address is defined as a visible
7618 -- Integer type. The reason is that we would really prefer Address
7619 -- to behave as a private type, even in this case. If Address is a
7620 -- visible integer type, we get lots of overload ambiguities.
7622 if Nkind (N) in N_Binary_Op then
7624 U1 : constant Boolean :=
7625 Present (Universal_Interpretation (Right_Opnd (N)));
7626 U2 : constant Boolean :=
7627 Present (Universal_Interpretation (Left_Opnd (N)));
7631 Remove_Address_Interpretations (Second_Op);
7635 Remove_Address_Interpretations (First_Op);
7638 if not (U1 and U2) then
7640 -- Remove corresponding predefined operator, which is
7641 -- always added to the overload set.
7643 Get_First_Interp (N, I, It);
7644 while Present (It.Nam) loop
7645 if Scope (It.Nam) = Standard_Standard
7646 and then Base_Type (It.Typ) =
7647 Base_Type (Etype (Abstract_Op))
7652 Get_Next_Interp (I, It);
7655 elsif Is_Overloaded (N)
7656 and then Present (Univ_Type)
7658 -- If both operands have a universal interpretation,
7659 -- it is still necessary to remove interpretations that
7660 -- yield Address. Any remaining ambiguities will be
7661 -- removed in Disambiguate.
7663 Get_First_Interp (N, I, It);
7664 while Present (It.Nam) loop
7665 if Is_Descendant_Of_Address (It.Typ) then
7668 elsif not Is_Type (It.Nam) then
7669 Set_Entity (N, It.Nam);
7672 Get_Next_Interp (I, It);
7678 elsif Nkind (N) = N_Function_Call
7680 (Nkind (Name (N)) = N_Operator_Symbol
7682 (Nkind (Name (N)) = N_Expanded_Name
7684 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
7688 Arg1 : constant Node_Id := First (Parameter_Associations (N));
7689 U1 : constant Boolean :=
7690 Present (Universal_Interpretation (Arg1));
7691 U2 : constant Boolean :=
7692 Present (Next (Arg1)) and then
7693 Present (Universal_Interpretation (Next (Arg1)));
7697 Remove_Address_Interpretations (First_Op);
7701 Remove_Address_Interpretations (Second_Op);
7704 if not (U1 and U2) then
7705 Get_First_Interp (N, I, It);
7706 while Present (It.Nam) loop
7707 if Scope (It.Nam) = Standard_Standard
7708 and then It.Typ = Base_Type (Etype (Abstract_Op))
7713 Get_Next_Interp (I, It);
7719 -- If the removal has left no valid interpretations, emit an error
7720 -- message now and label node as illegal.
7722 if Present (Abstract_Op) then
7723 Get_First_Interp (N, I, It);
7727 -- Removal of abstract operation left no viable candidate
7729 Set_Etype (N, Any_Type);
7730 Error_Msg_Sloc := Sloc (Abstract_Op);
7732 ("cannot call abstract operation& declared#", N, Abstract_Op);
7734 -- In Ada 2005, an abstract operation may disable predefined
7735 -- operators. Since the context is not yet known, we mark the
7736 -- predefined operators as potentially hidden. Do not include
7737 -- predefined operators when addresses are involved since this
7738 -- case is handled separately.
7740 elsif Ada_Version >= Ada_2005 and then not Address_Descendant then
7741 while Present (It.Nam) loop
7742 if Is_Numeric_Type (It.Typ)
7743 and then Scope (It.Typ) = Standard_Standard
7745 Set_Abstract_Op (I, Abstract_Op);
7748 Get_Next_Interp (I, It);
7753 if Debug_Flag_V then
7754 Write_Line ("Remove_Abstract_Operations done: ");
7755 Write_Overloads (N);
7758 end Remove_Abstract_Operations;
7760 ----------------------------
7761 -- Try_Container_Indexing --
7762 ----------------------------
7764 function Try_Container_Indexing
7767 Exprs : List_Id) return Boolean
7769 Pref_Typ : constant Entity_Id := Etype (Prefix);
7771 function Constant_Indexing_OK return Boolean;
7772 -- Constant_Indexing is legal if there is no Variable_Indexing defined
7773 -- for the type, or else node not a target of assignment, or an actual
7774 -- for an IN OUT or OUT formal (RM 4.1.6 (11)).
7776 function Expr_Matches_In_Formal
7778 Par : Node_Id) return Boolean;
7779 -- Find formal corresponding to given indexed component that is an
7780 -- actual in a call. Note that the enclosing subprogram call has not
7781 -- been analyzed yet, and the parameter list is not normalized, so
7782 -- that if the argument is a parameter association we must match it
7783 -- by name and not by position.
7785 function Find_Indexing_Operations
7788 Is_Constant : Boolean) return Node_Id;
7789 -- Return a reference to the primitive operation of type T denoted by
7790 -- name Nam. If the operation is overloaded, the reference carries all
7791 -- interpretations. Flag Is_Constant should be set when the context is
7792 -- constant indexing.
7794 --------------------------
7795 -- Constant_Indexing_OK --
7796 --------------------------
7798 function Constant_Indexing_OK return Boolean is
7802 if No (Find_Value_Of_Aspect (Pref_Typ, Aspect_Variable_Indexing)) then
7805 elsif not Is_Variable (Prefix) then
7810 while Present (Par) loop
7811 if Nkind (Parent (Par)) = N_Assignment_Statement
7812 and then Par = Name (Parent (Par))
7816 -- The call may be overloaded, in which case we assume that its
7817 -- resolution does not depend on the type of the parameter that
7818 -- includes the indexing operation.
7820 elsif Nkind_In (Parent (Par), N_Function_Call,
7821 N_Procedure_Call_Statement)
7822 and then Is_Entity_Name (Name (Parent (Par)))
7828 -- We should look for an interpretation with the proper
7829 -- number of formals, and determine whether it is an
7830 -- In_Parameter, but for now we examine the formal that
7831 -- corresponds to the indexing, and assume that variable
7832 -- indexing is required if some interpretation has an
7833 -- assignable formal at that position. Still does not
7834 -- cover the most complex cases ???
7836 if Is_Overloaded (Name (Parent (Par))) then
7838 Proc : constant Node_Id := Name (Parent (Par));
7843 Get_First_Interp (Proc, I, It);
7844 while Present (It.Nam) loop
7845 if not Expr_Matches_In_Formal (It.Nam, Par) then
7849 Get_Next_Interp (I, It);
7853 -- All interpretations have a matching in-mode formal
7858 Proc := Entity (Name (Parent (Par)));
7860 -- If this is an indirect call, get formals from
7863 if Is_Access_Subprogram_Type (Etype (Proc)) then
7864 Proc := Designated_Type (Etype (Proc));
7868 return Expr_Matches_In_Formal (Proc, Par);
7871 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
7874 -- If the indexed component is a prefix it may be the first actual
7875 -- of a prefixed call. Retrieve the called entity, if any, and
7876 -- check its first formal. Determine if the context is a procedure
7877 -- or function call.
7879 elsif Nkind (Parent (Par)) = N_Selected_Component then
7881 Sel : constant Node_Id := Selector_Name (Parent (Par));
7882 Nam : constant Entity_Id := Current_Entity (Sel);
7885 if Present (Nam) and then Is_Overloadable (Nam) then
7886 if Nkind (Parent (Parent (Par))) =
7887 N_Procedure_Call_Statement
7891 elsif Ekind (Nam) = E_Function
7892 and then Present (First_Formal (Nam))
7894 return Ekind (First_Formal (Nam)) = E_In_Parameter;
7899 elsif Nkind (Par) in N_Op then
7903 Par := Parent (Par);
7906 -- In all other cases, constant indexing is legal
7909 end Constant_Indexing_OK;
7911 ----------------------------
7912 -- Expr_Matches_In_Formal --
7913 ----------------------------
7915 function Expr_Matches_In_Formal
7917 Par : Node_Id) return Boolean
7923 Formal := First_Formal (Subp);
7924 Actual := First (Parameter_Associations ((Parent (Par))));
7926 if Nkind (Par) /= N_Parameter_Association then
7928 -- Match by position
7930 while Present (Actual) and then Present (Formal) loop
7931 exit when Actual = Par;
7934 if Present (Formal) then
7935 Next_Formal (Formal);
7937 -- Otherwise this is a parameter mismatch, the error is
7938 -- reported elsewhere, or else variable indexing is implied.
7948 while Present (Formal) loop
7949 exit when Chars (Formal) = Chars (Selector_Name (Par));
7950 Next_Formal (Formal);
7958 return Present (Formal) and then Ekind (Formal) = E_In_Parameter;
7959 end Expr_Matches_In_Formal;
7961 ------------------------------
7962 -- Find_Indexing_Operations --
7963 ------------------------------
7965 function Find_Indexing_Operations
7968 Is_Constant : Boolean) return Node_Id
7970 procedure Inspect_Declarations
7972 Ref : in out Node_Id);
7973 -- Traverse the declarative list where type Typ resides and collect
7974 -- all suitable interpretations in node Ref.
7976 procedure Inspect_Primitives
7978 Ref : in out Node_Id);
7979 -- Traverse the list of primitive operations of type Typ and collect
7980 -- all suitable interpretations in node Ref.
7982 function Is_OK_Candidate
7983 (Subp_Id : Entity_Id;
7984 Typ : Entity_Id) return Boolean;
7985 -- Determine whether subprogram Subp_Id is a suitable indexing
7986 -- operation for type Typ. To qualify as such, the subprogram must
7987 -- be a function, have at least two parameters, and the type of the
7988 -- first parameter must be either Typ, or Typ'Class, or access [to
7989 -- constant] with designated type Typ or Typ'Class.
7991 procedure Record_Interp (Subp_Id : Entity_Id; Ref : in out Node_Id);
7992 -- Store subprogram Subp_Id as an interpretation in node Ref
7994 --------------------------
7995 -- Inspect_Declarations --
7996 --------------------------
7998 procedure Inspect_Declarations
8000 Ref : in out Node_Id)
8002 Typ_Decl : constant Node_Id := Declaration_Node (Typ);
8004 Subp_Id : Entity_Id;
8007 -- Ensure that the routine is not called with itypes, which lack a
8008 -- declarative node.
8010 pragma Assert (Present (Typ_Decl));
8011 pragma Assert (Is_List_Member (Typ_Decl));
8013 Decl := First (List_Containing (Typ_Decl));
8014 while Present (Decl) loop
8015 if Nkind (Decl) = N_Subprogram_Declaration then
8016 Subp_Id := Defining_Entity (Decl);
8018 if Is_OK_Candidate (Subp_Id, Typ) then
8019 Record_Interp (Subp_Id, Ref);
8025 end Inspect_Declarations;
8027 ------------------------
8028 -- Inspect_Primitives --
8029 ------------------------
8031 procedure Inspect_Primitives
8033 Ref : in out Node_Id)
8035 Prim_Elmt : Elmt_Id;
8036 Prim_Id : Entity_Id;
8039 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
8040 while Present (Prim_Elmt) loop
8041 Prim_Id := Node (Prim_Elmt);
8043 if Is_OK_Candidate (Prim_Id, Typ) then
8044 Record_Interp (Prim_Id, Ref);
8047 Next_Elmt (Prim_Elmt);
8049 end Inspect_Primitives;
8051 ---------------------
8052 -- Is_OK_Candidate --
8053 ---------------------
8055 function Is_OK_Candidate
8056 (Subp_Id : Entity_Id;
8057 Typ : Entity_Id) return Boolean
8060 Formal_Typ : Entity_Id;
8061 Param_Typ : Node_Id;
8064 -- To classify as a suitable candidate, the subprogram must be a
8065 -- function whose name matches the argument of aspect Constant or
8066 -- Variable_Indexing.
8068 if Ekind (Subp_Id) = E_Function and then Chars (Subp_Id) = Nam then
8069 Formal := First_Formal (Subp_Id);
8071 -- The candidate requires at least two parameters
8073 if Present (Formal) and then Present (Next_Formal (Formal)) then
8074 Formal_Typ := Empty;
8075 Param_Typ := Parameter_Type (Parent (Formal));
8077 -- Use the designated type when the first parameter is of an
8080 if Nkind (Param_Typ) = N_Access_Definition
8081 and then Present (Subtype_Mark (Param_Typ))
8083 -- When the context is a constant indexing, the access
8084 -- definition must be access-to-constant. This does not
8085 -- apply to variable indexing.
8088 or else Constant_Present (Param_Typ)
8090 Formal_Typ := Etype (Subtype_Mark (Param_Typ));
8093 -- Otherwise use the parameter type
8096 Formal_Typ := Etype (Param_Typ);
8099 if Present (Formal_Typ) then
8101 -- Use the specific type when the parameter type is
8104 if Is_Class_Wide_Type (Formal_Typ) then
8105 Formal_Typ := Etype (Base_Type (Formal_Typ));
8108 -- Use the full view when the parameter type is private
8111 if Is_Incomplete_Or_Private_Type (Formal_Typ)
8112 and then Present (Full_View (Formal_Typ))
8114 Formal_Typ := Full_View (Formal_Typ);
8117 -- The type of the first parameter must denote the type
8118 -- of the container or acts as its ancestor type.
8122 or else Is_Ancestor (Formal_Typ, Typ);
8128 end Is_OK_Candidate;
8134 procedure Record_Interp (Subp_Id : Entity_Id; Ref : in out Node_Id) is
8136 if Present (Ref) then
8137 Add_One_Interp (Ref, Subp_Id, Etype (Subp_Id));
8139 -- Otherwise this is the first interpretation. Create a reference
8140 -- where all remaining interpretations will be collected.
8143 Ref := New_Occurrence_Of (Subp_Id, Sloc (T));
8152 -- Start of processing for Find_Indexing_Operations
8157 -- Use the specific type when the parameter type is class-wide
8159 if Is_Class_Wide_Type (Typ) then
8160 Typ := Root_Type (Typ);
8164 Typ := Underlying_Type (Base_Type (Typ));
8166 Inspect_Primitives (Typ, Ref);
8168 -- Now look for explicit declarations of an indexing operation.
8169 -- If the type is private the operation may be declared in the
8170 -- visible part that contains the partial view.
8172 if Is_Private_Type (T) then
8173 Inspect_Declarations (T, Ref);
8176 Inspect_Declarations (Typ, Ref);
8179 end Find_Indexing_Operations;
8183 Loc : constant Source_Ptr := Sloc (N);
8187 Func_Name : Node_Id;
8190 Is_Constant_Indexing : Boolean := False;
8191 -- This flag reflects the nature of the container indexing. Note that
8192 -- the context may be suited for constant indexing, but the type may
8193 -- lack a Constant_Indexing annotation.
8195 -- Start of processing for Try_Container_Indexing
8198 -- Node may have been analyzed already when testing for a prefixed
8199 -- call, in which case do not redo analysis.
8201 if Present (Generalized_Indexing (N)) then
8207 -- If indexing a class-wide container, obtain indexing primitive from
8210 if Is_Class_Wide_Type (C_Type) then
8211 C_Type := Etype (Base_Type (C_Type));
8214 -- Check whether the type has a specified indexing aspect
8218 -- The context is suitable for constant indexing, so obtain the name of
8219 -- the indexing function from aspect Constant_Indexing.
8221 if Constant_Indexing_OK then
8223 Find_Value_Of_Aspect (Pref_Typ, Aspect_Constant_Indexing);
8226 if Present (Func_Name) then
8227 Is_Constant_Indexing := True;
8229 -- Otherwise attempt variable indexing
8233 Find_Value_Of_Aspect (Pref_Typ, Aspect_Variable_Indexing);
8236 -- The type is not subject to either form of indexing, therefore the
8237 -- indexed component does not denote container indexing. If this is a
8238 -- true error, it is diagnosed by the caller.
8240 if No (Func_Name) then
8242 -- The prefix itself may be an indexing of a container. Rewrite it
8243 -- as such and retry.
8245 if Has_Implicit_Dereference (Pref_Typ) then
8246 Build_Explicit_Dereference (Prefix, First_Discriminant (Pref_Typ));
8247 return Try_Container_Indexing (N, Prefix, Exprs);
8249 -- Otherwise this is definitely not container indexing
8255 -- If the container type is derived from another container type, the
8256 -- value of the inherited aspect is the Reference operation declared
8257 -- for the parent type.
8259 -- However, Reference is also a primitive operation of the type, and the
8260 -- inherited operation has a different signature. We retrieve the right
8261 -- ones (the function may be overloaded) from the list of primitive
8262 -- operations of the derived type.
8264 -- Note that predefined containers are typically all derived from one of
8265 -- the Controlled types. The code below is motivated by containers that
8266 -- are derived from other types with a Reference aspect.
8268 elsif Is_Derived_Type (C_Type)
8269 and then Etype (First_Formal (Entity (Func_Name))) /= Pref_Typ
8272 Find_Indexing_Operations
8274 Nam => Chars (Func_Name),
8275 Is_Constant => Is_Constant_Indexing);
8278 Assoc := New_List (Relocate_Node (Prefix));
8280 -- A generalized indexing may have nore than one index expression, so
8281 -- transfer all of them to the argument list to be used in the call.
8282 -- Note that there may be named associations, in which case the node
8283 -- was rewritten earlier as a call, and has been transformed back into
8284 -- an indexed expression to share the following processing.
8286 -- The generalized indexing node is the one on which analysis and
8287 -- resolution take place. Before expansion the original node is replaced
8288 -- with the generalized indexing node, which is a call, possibly with a
8289 -- dereference operation.
8291 if Comes_From_Source (N) then
8292 Check_Compiler_Unit ("generalized indexing", N);
8295 -- Create argument list for function call that represents generalized
8296 -- indexing. Note that indices (i.e. actuals) may themselves be
8304 Arg := First (Exprs);
8305 while Present (Arg) loop
8306 New_Arg := Relocate_Node (Arg);
8308 -- The arguments can be parameter associations, in which case the
8309 -- explicit actual parameter carries the overloadings.
8311 if Nkind (New_Arg) /= N_Parameter_Association then
8312 Save_Interps (Arg, New_Arg);
8315 Append (New_Arg, Assoc);
8320 if not Is_Overloaded (Func_Name) then
8321 Func := Entity (Func_Name);
8324 Make_Function_Call (Loc,
8325 Name => New_Occurrence_Of (Func, Loc),
8326 Parameter_Associations => Assoc);
8328 Set_Parent (Indexing, Parent (N));
8329 Set_Generalized_Indexing (N, Indexing);
8331 Set_Etype (N, Etype (Indexing));
8333 -- If the return type of the indexing function is a reference type,
8334 -- add the dereference as a possible interpretation. Note that the
8335 -- indexing aspect may be a function that returns the element type
8336 -- with no intervening implicit dereference, and that the reference
8337 -- discriminant is not the first discriminant.
8339 if Has_Discriminants (Etype (Func)) then
8340 Check_Implicit_Dereference (N, Etype (Func));
8344 -- If there are multiple indexing functions, build a function call
8345 -- and analyze it for each of the possible interpretations.
8348 Make_Function_Call (Loc,
8350 Make_Identifier (Loc, Chars (Func_Name)),
8351 Parameter_Associations => Assoc);
8352 Set_Parent (Indexing, Parent (N));
8353 Set_Generalized_Indexing (N, Indexing);
8354 Set_Etype (N, Any_Type);
8355 Set_Etype (Name (Indexing), Any_Type);
8363 Get_First_Interp (Func_Name, I, It);
8364 Set_Etype (Indexing, Any_Type);
8366 -- Analyze each candidate function with the given actuals
8368 while Present (It.Nam) loop
8369 Analyze_One_Call (Indexing, It.Nam, False, Success);
8370 Get_Next_Interp (I, It);
8373 -- If there are several successful candidates, resolution will
8374 -- be by result. Mark the interpretations of the function name
8377 if Is_Overloaded (Indexing) then
8378 Get_First_Interp (Indexing, I, It);
8380 while Present (It.Nam) loop
8381 Add_One_Interp (Name (Indexing), It.Nam, It.Typ);
8382 Get_Next_Interp (I, It);
8386 Set_Etype (Name (Indexing), Etype (Indexing));
8389 -- Now add the candidate interpretations to the indexing node
8390 -- itself, to be replaced later by the function call.
8392 if Is_Overloaded (Name (Indexing)) then
8393 Get_First_Interp (Name (Indexing), I, It);
8395 while Present (It.Nam) loop
8396 Add_One_Interp (N, It.Nam, It.Typ);
8398 -- Add dereference interpretation if the result type has
8399 -- implicit reference discriminants.
8401 if Has_Discriminants (Etype (It.Nam)) then
8402 Check_Implicit_Dereference (N, Etype (It.Nam));
8405 Get_Next_Interp (I, It);
8409 Set_Etype (N, Etype (Name (Indexing)));
8410 if Has_Discriminants (Etype (N)) then
8411 Check_Implicit_Dereference (N, Etype (N));
8417 if Etype (Indexing) = Any_Type then
8419 ("container cannot be indexed with&", N, Etype (First (Exprs)));
8420 Rewrite (N, New_Occurrence_Of (Any_Id, Loc));
8424 end Try_Container_Indexing;
8426 -----------------------
8427 -- Try_Indirect_Call --
8428 -----------------------
8430 function Try_Indirect_Call
8433 Typ : Entity_Id) return Boolean
8439 pragma Warnings (Off, Call_OK);
8442 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
8444 Actual := First_Actual (N);
8445 Formal := First_Formal (Designated_Type (Typ));
8446 while Present (Actual) and then Present (Formal) loop
8447 if not Has_Compatible_Type (Actual, Etype (Formal)) then
8452 Next_Formal (Formal);
8455 if No (Actual) and then No (Formal) then
8456 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
8458 -- Nam is a candidate interpretation for the name in the call,
8459 -- if it is not an indirect call.
8461 if not Is_Type (Nam)
8462 and then Is_Entity_Name (Name (N))
8464 Set_Entity (Name (N), Nam);
8472 end Try_Indirect_Call;
8474 ----------------------
8475 -- Try_Indexed_Call --
8476 ----------------------
8478 function Try_Indexed_Call
8482 Skip_First : Boolean) return Boolean
8484 Loc : constant Source_Ptr := Sloc (N);
8485 Actuals : constant List_Id := Parameter_Associations (N);
8490 Actual := First (Actuals);
8492 -- If the call was originally written in prefix form, skip the first
8493 -- actual, which is obviously not defaulted.
8499 Index := First_Index (Typ);
8500 while Present (Actual) and then Present (Index) loop
8502 -- If the parameter list has a named association, the expression
8503 -- is definitely a call and not an indexed component.
8505 if Nkind (Actual) = N_Parameter_Association then
8509 if Is_Entity_Name (Actual)
8510 and then Is_Type (Entity (Actual))
8511 and then No (Next (Actual))
8513 -- A single actual that is a type name indicates a slice if the
8514 -- type is discrete, and an error otherwise.
8516 if Is_Discrete_Type (Entity (Actual)) then
8520 Make_Function_Call (Loc,
8521 Name => Relocate_Node (Name (N))),
8523 New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
8528 Error_Msg_N ("invalid use of type in expression", Actual);
8529 Set_Etype (N, Any_Type);
8534 elsif not Has_Compatible_Type (Actual, Etype (Index)) then
8542 if No (Actual) and then No (Index) then
8543 Add_One_Interp (N, Nam, Component_Type (Typ));
8545 -- Nam is a candidate interpretation for the name in the call,
8546 -- if it is not an indirect call.
8548 if not Is_Type (Nam)
8549 and then Is_Entity_Name (Name (N))
8551 Set_Entity (Name (N), Nam);
8558 end Try_Indexed_Call;
8560 --------------------------
8561 -- Try_Object_Operation --
8562 --------------------------
8564 function Try_Object_Operation
8565 (N : Node_Id; CW_Test_Only : Boolean := False) return Boolean
8567 K : constant Node_Kind := Nkind (Parent (N));
8568 Is_Subprg_Call : constant Boolean := K in N_Subprogram_Call;
8569 Loc : constant Source_Ptr := Sloc (N);
8570 Obj : constant Node_Id := Prefix (N);
8572 Subprog : constant Node_Id :=
8573 Make_Identifier (Sloc (Selector_Name (N)),
8574 Chars => Chars (Selector_Name (N)));
8575 -- Identifier on which possible interpretations will be collected
8577 Report_Error : Boolean := False;
8578 -- If no candidate interpretation matches the context, redo analysis
8579 -- with Report_Error True to provide additional information.
8582 Candidate : Entity_Id := Empty;
8583 New_Call_Node : Node_Id := Empty;
8584 Node_To_Replace : Node_Id;
8585 Obj_Type : Entity_Id := Etype (Obj);
8586 Success : Boolean := False;
8588 procedure Complete_Object_Operation
8589 (Call_Node : Node_Id;
8590 Node_To_Replace : Node_Id);
8591 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
8592 -- Call_Node, insert the object (or its dereference) as the first actual
8593 -- in the call, and complete the analysis of the call.
8595 procedure Report_Ambiguity (Op : Entity_Id);
8596 -- If a prefixed procedure call is ambiguous, indicate whether the call
8597 -- includes an implicit dereference or an implicit 'Access.
8599 procedure Transform_Object_Operation
8600 (Call_Node : out Node_Id;
8601 Node_To_Replace : out Node_Id);
8602 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
8603 -- Call_Node is the resulting subprogram call, Node_To_Replace is
8604 -- either N or the parent of N, and Subprog is a reference to the
8605 -- subprogram we are trying to match.
8607 function Try_Class_Wide_Operation
8608 (Call_Node : Node_Id;
8609 Node_To_Replace : Node_Id) return Boolean;
8610 -- Traverse all ancestor types looking for a class-wide subprogram for
8611 -- which the current operation is a valid non-dispatching call.
8613 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
8614 -- If prefix is overloaded, its interpretation may include different
8615 -- tagged types, and we must examine the primitive operations and the
8616 -- class-wide operations of each in order to find candidate
8617 -- interpretations for the call as a whole.
8619 function Try_Primitive_Operation
8620 (Call_Node : Node_Id;
8621 Node_To_Replace : Node_Id) return Boolean;
8622 -- Traverse the list of primitive subprograms looking for a dispatching
8623 -- operation for which the current node is a valid call.
8625 function Valid_Candidate
8628 Subp : Entity_Id) return Entity_Id;
8629 -- If the subprogram is a valid interpretation, record it, and add to
8630 -- the list of interpretations of Subprog. Otherwise return Empty.
8632 -------------------------------
8633 -- Complete_Object_Operation --
8634 -------------------------------
8636 procedure Complete_Object_Operation
8637 (Call_Node : Node_Id;
8638 Node_To_Replace : Node_Id)
8640 Control : constant Entity_Id := First_Formal (Entity (Subprog));
8641 Formal_Type : constant Entity_Id := Etype (Control);
8642 First_Actual : Node_Id;
8645 -- Place the name of the operation, with its interpretations,
8646 -- on the rewritten call.
8648 Set_Name (Call_Node, Subprog);
8650 First_Actual := First (Parameter_Associations (Call_Node));
8652 -- For cross-reference purposes, treat the new node as being in the
8653 -- source if the original one is. Set entity and type, even though
8654 -- they may be overwritten during resolution if overloaded.
8656 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
8657 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
8659 if Nkind (N) = N_Selected_Component
8660 and then not Inside_A_Generic
8662 Set_Entity (Selector_Name (N), Entity (Subprog));
8663 Set_Etype (Selector_Name (N), Etype (Entity (Subprog)));
8666 -- If need be, rewrite first actual as an explicit dereference. If
8667 -- the call is overloaded, the rewriting can only be done once the
8668 -- primitive operation is identified.
8670 if Is_Overloaded (Subprog) then
8672 -- The prefix itself may be overloaded, and its interpretations
8673 -- must be propagated to the new actual in the call.
8675 if Is_Overloaded (Obj) then
8676 Save_Interps (Obj, First_Actual);
8679 Rewrite (First_Actual, Obj);
8681 elsif not Is_Access_Type (Formal_Type)
8682 and then Is_Access_Type (Etype (Obj))
8684 Rewrite (First_Actual,
8685 Make_Explicit_Dereference (Sloc (Obj), Obj));
8686 Analyze (First_Actual);
8688 -- If we need to introduce an explicit dereference, verify that
8689 -- the resulting actual is compatible with the mode of the formal.
8691 if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
8692 and then Is_Access_Constant (Etype (Obj))
8695 ("expect variable in call to&", Prefix (N), Entity (Subprog));
8698 -- Conversely, if the formal is an access parameter and the object is
8699 -- not an access type or a reference type (i.e. a type with the
8700 -- Implicit_Dereference aspect specified), replace the actual with a
8701 -- 'Access reference. Its analysis will check that the object is
8704 elsif Is_Access_Type (Formal_Type)
8705 and then not Is_Access_Type (Etype (Obj))
8707 (not Has_Implicit_Dereference (Etype (Obj))
8709 not Is_Access_Type (Designated_Type (Etype
8710 (Get_Reference_Discriminant (Etype (Obj))))))
8712 -- A special case: A.all'Access is illegal if A is an access to a
8713 -- constant and the context requires an access to a variable.
8715 if not Is_Access_Constant (Formal_Type) then
8716 if (Nkind (Obj) = N_Explicit_Dereference
8717 and then Is_Access_Constant (Etype (Prefix (Obj))))
8718 or else not Is_Variable (Obj)
8721 ("actual for & must be a variable", Obj, Control);
8725 Rewrite (First_Actual,
8726 Make_Attribute_Reference (Loc,
8727 Attribute_Name => Name_Access,
8728 Prefix => Relocate_Node (Obj)));
8730 -- If the object is not overloaded verify that taking access of
8731 -- it is legal. Otherwise check is made during resolution.
8733 if not Is_Overloaded (Obj)
8734 and then not Is_Aliased_View (Obj)
8737 ("object in prefixed call to & must be aliased "
8738 & "(RM 4.1.3 (13 1/2))", Prefix (First_Actual), Subprog);
8741 Analyze (First_Actual);
8744 if Is_Overloaded (Obj) then
8745 Save_Interps (Obj, First_Actual);
8748 Rewrite (First_Actual, Obj);
8751 -- The operation is obtained from the dispatch table and not by
8752 -- visibility, and may be declared in a unit that is not explicitly
8753 -- referenced in the source, but is nevertheless required in the
8754 -- context of the current unit. Indicate that operation and its scope
8755 -- are referenced, to prevent spurious and misleading warnings. If
8756 -- the operation is overloaded, all primitives are in the same scope
8757 -- and we can use any of them.
8759 Set_Referenced (Entity (Subprog), True);
8760 Set_Referenced (Scope (Entity (Subprog)), True);
8762 Rewrite (Node_To_Replace, Call_Node);
8764 -- Propagate the interpretations collected in subprog to the new
8765 -- function call node, to be resolved from context.
8767 if Is_Overloaded (Subprog) then
8768 Save_Interps (Subprog, Node_To_Replace);
8771 -- The type of the subprogram may be a limited view obtained
8772 -- transitively from another unit. If full view is available,
8773 -- use it to analyze call. If there is no nonlimited view, then
8774 -- this is diagnosed when analyzing the rewritten call.
8777 T : constant Entity_Id := Etype (Subprog);
8779 if From_Limited_With (T) then
8780 Set_Etype (Entity (Subprog), Available_View (T));
8784 Analyze (Node_To_Replace);
8786 -- If the operation has been rewritten into a call, which may get
8787 -- subsequently an explicit dereference, preserve the type on the
8788 -- original node (selected component or indexed component) for
8789 -- subsequent legality tests, e.g. Is_Variable. which examines
8790 -- the original node.
8792 if Nkind (Node_To_Replace) = N_Function_Call then
8794 (Original_Node (Node_To_Replace), Etype (Node_To_Replace));
8797 end Complete_Object_Operation;
8799 ----------------------
8800 -- Report_Ambiguity --
8801 ----------------------
8803 procedure Report_Ambiguity (Op : Entity_Id) is
8804 Access_Actual : constant Boolean :=
8805 Is_Access_Type (Etype (Prefix (N)));
8806 Access_Formal : Boolean := False;
8809 Error_Msg_Sloc := Sloc (Op);
8811 if Present (First_Formal (Op)) then
8812 Access_Formal := Is_Access_Type (Etype (First_Formal (Op)));
8815 if Access_Formal and then not Access_Actual then
8816 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8818 ("\possible interpretation "
8819 & "(inherited, with implicit 'Access) #", N);
8822 ("\possible interpretation (with implicit 'Access) #", N);
8825 elsif not Access_Formal and then Access_Actual then
8826 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8828 ("\possible interpretation "
8829 & "(inherited, with implicit dereference) #", N);
8832 ("\possible interpretation (with implicit dereference) #", N);
8836 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8837 Error_Msg_N ("\possible interpretation (inherited)#", N);
8839 Error_Msg_N -- CODEFIX
8840 ("\possible interpretation#", N);
8843 end Report_Ambiguity;
8845 --------------------------------
8846 -- Transform_Object_Operation --
8847 --------------------------------
8849 procedure Transform_Object_Operation
8850 (Call_Node : out Node_Id;
8851 Node_To_Replace : out Node_Id)
8853 Dummy : constant Node_Id := New_Copy (Obj);
8854 -- Placeholder used as a first parameter in the call, replaced
8855 -- eventually by the proper object.
8857 Parent_Node : constant Node_Id := Parent (N);
8863 -- Obj may already have been rewritten if it involves an implicit
8864 -- dereference (e.g. if it is an access to a limited view). Preserve
8865 -- a link to the original node for ASIS use.
8867 if not Comes_From_Source (Obj) then
8868 Set_Original_Node (Dummy, Original_Node (Obj));
8871 -- Common case covering 1) Call to a procedure and 2) Call to a
8872 -- function that has some additional actuals.
8874 if Nkind (Parent_Node) in N_Subprogram_Call
8876 -- N is a selected component node containing the name of the
8877 -- subprogram. If N is not the name of the parent node we must
8878 -- not replace the parent node by the new construct. This case
8879 -- occurs when N is a parameterless call to a subprogram that
8880 -- is an actual parameter of a call to another subprogram. For
8882 -- Some_Subprogram (..., Obj.Operation, ...)
8884 and then Name (Parent_Node) = N
8886 Node_To_Replace := Parent_Node;
8888 Actuals := Parameter_Associations (Parent_Node);
8890 if Present (Actuals) then
8891 Prepend (Dummy, Actuals);
8893 Actuals := New_List (Dummy);
8896 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
8898 Make_Procedure_Call_Statement (Loc,
8899 Name => New_Copy (Subprog),
8900 Parameter_Associations => Actuals);
8904 Make_Function_Call (Loc,
8905 Name => New_Copy (Subprog),
8906 Parameter_Associations => Actuals);
8909 -- Before analysis, a function call appears as an indexed component
8910 -- if there are no named associations.
8912 elsif Nkind (Parent_Node) = N_Indexed_Component
8913 and then N = Prefix (Parent_Node)
8915 Node_To_Replace := Parent_Node;
8916 Actuals := Expressions (Parent_Node);
8918 Actual := First (Actuals);
8919 while Present (Actual) loop
8924 Prepend (Dummy, Actuals);
8927 Make_Function_Call (Loc,
8928 Name => New_Copy (Subprog),
8929 Parameter_Associations => Actuals);
8931 -- Parameterless call: Obj.F is rewritten as F (Obj)
8934 Node_To_Replace := N;
8937 Make_Function_Call (Loc,
8938 Name => New_Copy (Subprog),
8939 Parameter_Associations => New_List (Dummy));
8941 end Transform_Object_Operation;
8943 ------------------------------
8944 -- Try_Class_Wide_Operation --
8945 ------------------------------
8947 function Try_Class_Wide_Operation
8948 (Call_Node : Node_Id;
8949 Node_To_Replace : Node_Id) return Boolean
8951 Anc_Type : Entity_Id;
8952 Matching_Op : Entity_Id := Empty;
8955 procedure Traverse_Homonyms
8956 (Anc_Type : Entity_Id;
8957 Error : out Boolean);
8958 -- Traverse the homonym chain of the subprogram searching for those
8959 -- homonyms whose first formal has the Anc_Type's class-wide type,
8960 -- or an anonymous access type designating the class-wide type. If
8961 -- an ambiguity is detected, then Error is set to True.
8963 procedure Traverse_Interfaces
8964 (Anc_Type : Entity_Id;
8965 Error : out Boolean);
8966 -- Traverse the list of interfaces, if any, associated with Anc_Type
8967 -- and search for acceptable class-wide homonyms associated with each
8968 -- interface. If an ambiguity is detected, then Error is set to True.
8970 -----------------------
8971 -- Traverse_Homonyms --
8972 -----------------------
8974 procedure Traverse_Homonyms
8975 (Anc_Type : Entity_Id;
8976 Error : out Boolean)
8978 function First_Formal_Match
8979 (Subp_Id : Entity_Id;
8980 Typ : Entity_Id) return Boolean;
8981 -- Predicate to verify that the first foramal of class-wide
8982 -- subprogram Subp_Id matches type Typ of the prefix.
8984 ------------------------
8985 -- First_Formal_Match --
8986 ------------------------
8988 function First_Formal_Match
8989 (Subp_Id : Entity_Id;
8990 Typ : Entity_Id) return Boolean
8992 Ctrl : constant Entity_Id := First_Formal (Subp_Id);
8998 (Base_Type (Etype (Ctrl)) = Typ
9000 (Ekind (Etype (Ctrl)) = E_Anonymous_Access_Type
9002 Base_Type (Designated_Type (Etype (Ctrl))) =
9004 end First_Formal_Match;
9008 CW_Typ : constant Entity_Id := Class_Wide_Type (Anc_Type);
9010 Candidate : Entity_Id;
9011 -- If homonym is a renaming, examine the renamed program
9017 -- Start of processing for Traverse_Homonyms
9022 -- Find a non-hidden operation whose first parameter is of the
9023 -- class-wide type, a subtype thereof, or an anonymous access
9024 -- to same. If in an instance, the operation can be considered
9025 -- even if hidden (it may be hidden because the instantiation
9026 -- is expanded after the containing package has been analyzed).
9027 -- If the subprogram is a generic actual in an enclosing instance,
9028 -- it appears as a renaming that is a candidate interpretation as
9031 Hom := Current_Entity (Subprog);
9032 while Present (Hom) loop
9033 if Ekind_In (Hom, E_Procedure, E_Function)
9034 and then Present (Renamed_Entity (Hom))
9035 and then Is_Generic_Actual_Subprogram (Hom)
9036 and then In_Open_Scopes (Scope (Hom))
9038 Candidate := Renamed_Entity (Hom);
9043 if Ekind_In (Candidate, E_Function, E_Procedure)
9044 and then (not Is_Hidden (Candidate) or else In_Instance)
9045 and then Scope (Candidate) = Scope (Base_Type (Anc_Type))
9046 and then First_Formal_Match (Candidate, CW_Typ)
9048 -- If the context is a procedure call, ignore functions
9049 -- in the name of the call.
9051 if Ekind (Candidate) = E_Function
9052 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
9053 and then N = Name (Parent (N))
9057 -- If the context is a function call, ignore procedures
9058 -- in the name of the call.
9060 elsif Ekind (Candidate) = E_Procedure
9061 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
9066 Set_Etype (Call_Node, Any_Type);
9067 Set_Is_Overloaded (Call_Node, False);
9070 if No (Matching_Op) then
9071 Hom_Ref := New_Occurrence_Of (Candidate, Sloc (Subprog));
9073 Set_Etype (Call_Node, Any_Type);
9074 Set_Name (Call_Node, Hom_Ref);
9075 Set_Parent (Call_Node, Parent (Node_To_Replace));
9080 Report => Report_Error,
9082 Skip_First => True);
9085 Valid_Candidate (Success, Call_Node, Candidate);
9091 Report => Report_Error,
9093 Skip_First => True);
9095 -- The same operation may be encountered on two homonym
9096 -- traversals, before and after looking at interfaces.
9097 -- Check for this case before reporting a real ambiguity.
9100 (Valid_Candidate (Success, Call_Node, Candidate))
9101 and then Nkind (Call_Node) /= N_Function_Call
9102 and then Candidate /= Matching_Op
9104 Error_Msg_NE ("ambiguous call to&", N, Hom);
9105 Report_Ambiguity (Matching_Op);
9106 Report_Ambiguity (Hom);
9114 Hom := Homonym (Hom);
9116 end Traverse_Homonyms;
9118 -------------------------
9119 -- Traverse_Interfaces --
9120 -------------------------
9122 procedure Traverse_Interfaces
9123 (Anc_Type : Entity_Id;
9124 Error : out Boolean)
9126 Intface_List : constant List_Id :=
9127 Abstract_Interface_List (Anc_Type);
9133 if Is_Non_Empty_List (Intface_List) then
9134 Intface := First (Intface_List);
9135 while Present (Intface) loop
9137 -- Look for acceptable class-wide homonyms associated with
9140 Traverse_Homonyms (Etype (Intface), Error);
9146 -- Continue the search by looking at each of the interface's
9147 -- associated interface ancestors.
9149 Traverse_Interfaces (Etype (Intface), Error);
9158 end Traverse_Interfaces;
9160 -- Start of processing for Try_Class_Wide_Operation
9163 -- If we are searching only for conflicting class-wide subprograms
9164 -- then initialize directly Matching_Op with the target entity.
9166 if CW_Test_Only then
9167 Matching_Op := Entity (Selector_Name (N));
9170 -- Loop through ancestor types (including interfaces), traversing
9171 -- the homonym chain of the subprogram, trying out those homonyms
9172 -- whose first formal has the class-wide type of the ancestor, or
9173 -- an anonymous access type designating the class-wide type.
9175 Anc_Type := Obj_Type;
9177 -- Look for a match among homonyms associated with the ancestor
9179 Traverse_Homonyms (Anc_Type, Error);
9185 -- Continue the search for matches among homonyms associated with
9186 -- any interfaces implemented by the ancestor.
9188 Traverse_Interfaces (Anc_Type, Error);
9194 exit when Etype (Anc_Type) = Anc_Type;
9195 Anc_Type := Etype (Anc_Type);
9198 if Present (Matching_Op) then
9199 Set_Etype (Call_Node, Etype (Matching_Op));
9202 return Present (Matching_Op);
9203 end Try_Class_Wide_Operation;
9205 -----------------------------------
9206 -- Try_One_Prefix_Interpretation --
9207 -----------------------------------
9209 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
9210 Prev_Obj_Type : constant Entity_Id := Obj_Type;
9211 -- If the interpretation does not have a valid candidate type,
9212 -- preserve current value of Obj_Type for subsequent errors.
9217 if Is_Access_Type (Obj_Type) then
9218 Obj_Type := Designated_Type (Obj_Type);
9221 if Ekind_In (Obj_Type, E_Private_Subtype,
9222 E_Record_Subtype_With_Private)
9224 Obj_Type := Base_Type (Obj_Type);
9227 if Is_Class_Wide_Type (Obj_Type) then
9228 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
9231 -- The type may have be obtained through a limited_with clause,
9232 -- in which case the primitive operations are available on its
9233 -- nonlimited view. If still incomplete, retrieve full view.
9235 if Ekind (Obj_Type) = E_Incomplete_Type
9236 and then From_Limited_With (Obj_Type)
9237 and then Has_Non_Limited_View (Obj_Type)
9239 Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
9242 -- If the object is not tagged, or the type is still an incomplete
9243 -- type, this is not a prefixed call. Restore the previous type as
9244 -- the current one is not a legal candidate.
9246 if not Is_Tagged_Type (Obj_Type)
9247 or else Is_Incomplete_Type (Obj_Type)
9249 Obj_Type := Prev_Obj_Type;
9254 Dup_Call_Node : constant Node_Id := New_Copy (New_Call_Node);
9256 Prim_Result : Boolean := False;
9259 if not CW_Test_Only then
9261 Try_Primitive_Operation
9262 (Call_Node => New_Call_Node,
9263 Node_To_Replace => Node_To_Replace);
9266 -- Check if there is a class-wide subprogram covering the
9267 -- primitive. This check must be done even if a candidate
9268 -- was found in order to report ambiguous calls.
9270 if not Prim_Result then
9272 Try_Class_Wide_Operation
9273 (Call_Node => New_Call_Node,
9274 Node_To_Replace => Node_To_Replace);
9276 -- If we found a primitive we search for class-wide subprograms
9277 -- using a duplicate of the call node (done to avoid missing its
9278 -- decoration if there is no ambiguity).
9282 Try_Class_Wide_Operation
9283 (Call_Node => Dup_Call_Node,
9284 Node_To_Replace => Node_To_Replace);
9287 end Try_One_Prefix_Interpretation;
9289 -----------------------------
9290 -- Try_Primitive_Operation --
9291 -----------------------------
9293 function Try_Primitive_Operation
9294 (Call_Node : Node_Id;
9295 Node_To_Replace : Node_Id) return Boolean
9298 Prim_Op : Entity_Id;
9299 Matching_Op : Entity_Id := Empty;
9300 Prim_Op_Ref : Node_Id := Empty;
9302 Corr_Type : Entity_Id := Empty;
9303 -- If the prefix is a synchronized type, the controlling type of
9304 -- the primitive operation is the corresponding record type, else
9305 -- this is the object type itself.
9307 Success : Boolean := False;
9309 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
9310 -- For tagged types the candidate interpretations are found in
9311 -- the list of primitive operations of the type and its ancestors.
9312 -- For formal tagged types we have to find the operations declared
9313 -- in the same scope as the type (including in the generic formal
9314 -- part) because the type itself carries no primitive operations,
9315 -- except for formal derived types that inherit the operations of
9316 -- the parent and progenitors.
9318 -- If the context is a generic subprogram body, the generic formals
9319 -- are visible by name, but are not in the entity list of the
9320 -- subprogram because that list starts with the subprogram formals.
9321 -- We retrieve the candidate operations from the generic declaration.
9323 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id;
9324 -- Prefix notation can also be used on operations that are not
9325 -- primitives of the type, but are declared in the same immediate
9326 -- declarative part, which can only mean the corresponding package
9327 -- body (See RM 4.1.3 (9.2/3)). If we are in that body we extend the
9328 -- list of primitives with body operations with the same name that
9329 -- may be candidates, so that Try_Primitive_Operations can examine
9330 -- them if no real primitive is found.
9332 function Is_Private_Overriding (Op : Entity_Id) return Boolean;
9333 -- An operation that overrides an inherited operation in the private
9334 -- part of its package may be hidden, but if the inherited operation
9335 -- is visible a direct call to it will dispatch to the private one,
9336 -- which is therefore a valid candidate.
9338 function Names_Match
9339 (Obj_Type : Entity_Id;
9340 Prim_Op : Entity_Id;
9341 Subprog : Entity_Id) return Boolean;
9342 -- Return True if the names of Prim_Op and Subprog match. If Obj_Type
9343 -- is a protected type then compare also the original name of Prim_Op
9344 -- with the name of Subprog (since the expander may have added a
9345 -- prefix to its original name --see Exp_Ch9.Build_Selected_Name).
9347 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
9348 -- Verify that the prefix, dereferenced if need be, is a valid
9349 -- controlling argument in a call to Op. The remaining actuals
9350 -- are checked in the subsequent call to Analyze_One_Call.
9352 ------------------------------
9353 -- Collect_Generic_Type_Ops --
9354 ------------------------------
9356 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
9357 Bas : constant Entity_Id := Base_Type (T);
9358 Candidates : constant Elist_Id := New_Elmt_List;
9362 procedure Check_Candidate;
9363 -- The operation is a candidate if its first parameter is a
9364 -- controlling operand of the desired type.
9366 -----------------------
9367 -- Check_Candidate; --
9368 -----------------------
9370 procedure Check_Candidate is
9372 Formal := First_Formal (Subp);
9375 and then Is_Controlling_Formal (Formal)
9377 (Base_Type (Etype (Formal)) = Bas
9379 (Is_Access_Type (Etype (Formal))
9380 and then Designated_Type (Etype (Formal)) = Bas))
9382 Append_Elmt (Subp, Candidates);
9384 end Check_Candidate;
9386 -- Start of processing for Collect_Generic_Type_Ops
9389 if Is_Derived_Type (T) then
9390 return Primitive_Operations (T);
9392 elsif Ekind_In (Scope (T), E_Procedure, E_Function) then
9394 -- Scan the list of generic formals to find subprograms
9395 -- that may have a first controlling formal of the type.
9397 if Nkind (Unit_Declaration_Node (Scope (T))) =
9398 N_Generic_Subprogram_Declaration
9405 First (Generic_Formal_Declarations
9406 (Unit_Declaration_Node (Scope (T))));
9407 while Present (Decl) loop
9408 if Nkind (Decl) in N_Formal_Subprogram_Declaration then
9409 Subp := Defining_Entity (Decl);
9420 -- Scan the list of entities declared in the same scope as
9421 -- the type. In general this will be an open scope, given that
9422 -- the call we are analyzing can only appear within a generic
9423 -- declaration or body (either the one that declares T, or a
9426 -- For a subtype representing a generic actual type, go to the
9429 if Is_Generic_Actual_Type (T) then
9430 Subp := First_Entity (Scope (Base_Type (T)));
9432 Subp := First_Entity (Scope (T));
9435 while Present (Subp) loop
9436 if Is_Overloadable (Subp) then
9445 end Collect_Generic_Type_Ops;
9447 ----------------------------
9448 -- Extended_Primitive_Ops --
9449 ----------------------------
9451 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id is
9452 Type_Scope : constant Entity_Id := Scope (T);
9454 Body_Decls : List_Id;
9460 Op_List := Primitive_Operations (T);
9462 if Ekind (Type_Scope) = E_Package
9463 and then In_Package_Body (Type_Scope)
9464 and then In_Open_Scopes (Type_Scope)
9466 -- Retrieve list of declarations of package body.
9470 (Unit_Declaration_Node
9472 (Unit_Declaration_Node (Type_Scope))));
9474 Op := Current_Entity (Subprog);
9476 while Present (Op) loop
9477 if Comes_From_Source (Op)
9478 and then Is_Overloadable (Op)
9480 -- Exclude overriding primitive operations of a type
9481 -- extension declared in the package body, to prevent
9482 -- duplicates in extended list.
9484 and then not Is_Primitive (Op)
9485 and then Is_List_Member (Unit_Declaration_Node (Op))
9486 and then List_Containing (Unit_Declaration_Node (Op)) =
9489 if not Op_Found then
9491 -- Copy list of primitives so it is not affected for
9494 Op_List := New_Copy_Elist (Op_List);
9498 Append_Elmt (Op, Op_List);
9506 end Extended_Primitive_Ops;
9508 ---------------------------
9509 -- Is_Private_Overriding --
9510 ---------------------------
9512 function Is_Private_Overriding (Op : Entity_Id) return Boolean is
9513 Visible_Op : Entity_Id;
9516 -- The subprogram may be overloaded with both visible and private
9517 -- entities with the same name. We have to scan the chain of
9518 -- homonyms to determine whether there is a previous implicit
9519 -- declaration in the same scope that is overridden by the
9520 -- private candidate.
9522 Visible_Op := Homonym (Op);
9523 while Present (Visible_Op) loop
9524 if Scope (Op) /= Scope (Visible_Op) then
9527 elsif not Comes_From_Source (Visible_Op)
9528 and then Alias (Visible_Op) = Op
9529 and then not Is_Hidden (Visible_Op)
9534 Visible_Op := Homonym (Visible_Op);
9538 end Is_Private_Overriding;
9544 function Names_Match
9545 (Obj_Type : Entity_Id;
9546 Prim_Op : Entity_Id;
9547 Subprog : Entity_Id) return Boolean is
9549 -- Common case: exact match
9551 if Chars (Prim_Op) = Chars (Subprog) then
9554 -- For protected type primitives the expander may have built the
9555 -- name of the dispatching primitive prepending the type name to
9556 -- avoid conflicts with the name of the protected subprogram (see
9557 -- Exp_Ch9.Build_Selected_Name).
9559 elsif Is_Protected_Type (Obj_Type) then
9561 Present (Original_Protected_Subprogram (Prim_Op))
9562 and then Chars (Original_Protected_Subprogram (Prim_Op)) =
9565 -- In an instance, the selector name may be a generic actual that
9566 -- renames a primitive operation of the type of the prefix.
9568 elsif In_Instance and then Present (Current_Entity (Subprog)) then
9570 Subp : constant Entity_Id := Current_Entity (Subprog);
9573 and then Is_Subprogram (Subp)
9574 and then Present (Renamed_Entity (Subp))
9575 and then Is_Generic_Actual_Subprogram (Subp)
9576 and then Chars (Renamed_Entity (Subp)) = Chars (Prim_Op)
9586 -----------------------------
9587 -- Valid_First_Argument_Of --
9588 -----------------------------
9590 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
9591 Typ : Entity_Id := Etype (First_Formal (Op));
9594 if Is_Concurrent_Type (Typ)
9595 and then Present (Corresponding_Record_Type (Typ))
9597 Typ := Corresponding_Record_Type (Typ);
9600 -- Simple case. Object may be a subtype of the tagged type or may
9601 -- be the corresponding record of a synchronized type.
9603 return Obj_Type = Typ
9604 or else Base_Type (Obj_Type) = Typ
9605 or else Corr_Type = Typ
9607 -- Object may be of a derived type whose parent has unknown
9608 -- discriminants, in which case the type matches the underlying
9609 -- record view of its base.
9612 (Has_Unknown_Discriminants (Typ)
9613 and then Typ = Underlying_Record_View (Base_Type (Obj_Type)))
9615 -- Prefix can be dereferenced
9618 (Is_Access_Type (Corr_Type)
9619 and then Designated_Type (Corr_Type) = Typ)
9621 -- Formal is an access parameter, for which the object can
9622 -- provide an access.
9625 (Ekind (Typ) = E_Anonymous_Access_Type
9627 Base_Type (Designated_Type (Typ)) = Base_Type (Corr_Type));
9628 end Valid_First_Argument_Of;
9630 -- Start of processing for Try_Primitive_Operation
9633 -- Look for subprograms in the list of primitive operations. The name
9634 -- must be identical, and the kind of call indicates the expected
9635 -- kind of operation (function or procedure). If the type is a
9636 -- (tagged) synchronized type, the primitive ops are attached to the
9637 -- corresponding record (base) type.
9639 if Is_Concurrent_Type (Obj_Type) then
9640 if Present (Corresponding_Record_Type (Obj_Type)) then
9641 Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
9642 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
9644 Corr_Type := Obj_Type;
9645 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
9648 elsif not Is_Generic_Type (Obj_Type) then
9649 Corr_Type := Obj_Type;
9650 Elmt := First_Elmt (Extended_Primitive_Ops (Obj_Type));
9653 Corr_Type := Obj_Type;
9654 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
9657 while Present (Elmt) loop
9658 Prim_Op := Node (Elmt);
9660 if Names_Match (Obj_Type, Prim_Op, Subprog)
9661 and then Present (First_Formal (Prim_Op))
9662 and then Valid_First_Argument_Of (Prim_Op)
9664 (Nkind (Call_Node) = N_Function_Call)
9666 (Ekind (Prim_Op) = E_Function)
9668 -- Ada 2005 (AI-251): If this primitive operation corresponds
9669 -- to an immediate ancestor interface there is no need to add
9670 -- it to the list of interpretations; the corresponding aliased
9671 -- primitive is also in this list of primitive operations and
9672 -- will be used instead.
9674 if (Present (Interface_Alias (Prim_Op))
9675 and then Is_Ancestor (Find_Dispatching_Type
9676 (Alias (Prim_Op)), Corr_Type))
9678 -- Do not consider hidden primitives unless the type is in an
9679 -- open scope or we are within an instance, where visibility
9680 -- is known to be correct, or else if this is an overriding
9681 -- operation in the private part for an inherited operation.
9683 or else (Is_Hidden (Prim_Op)
9684 and then not Is_Immediately_Visible (Obj_Type)
9685 and then not In_Instance
9686 and then not Is_Private_Overriding (Prim_Op))
9691 Set_Etype (Call_Node, Any_Type);
9692 Set_Is_Overloaded (Call_Node, False);
9694 if No (Matching_Op) then
9695 Prim_Op_Ref := New_Occurrence_Of (Prim_Op, Sloc (Subprog));
9696 Candidate := Prim_Op;
9698 Set_Parent (Call_Node, Parent (Node_To_Replace));
9700 Set_Name (Call_Node, Prim_Op_Ref);
9706 Report => Report_Error,
9708 Skip_First => True);
9710 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
9712 -- More than one interpretation, collect for subsequent
9713 -- disambiguation. If this is a procedure call and there
9714 -- is another match, report ambiguity now.
9720 Report => Report_Error,
9722 Skip_First => True);
9724 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
9725 and then Nkind (Call_Node) /= N_Function_Call
9727 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
9728 Report_Ambiguity (Matching_Op);
9729 Report_Ambiguity (Prim_Op);
9739 if Present (Matching_Op) then
9740 Set_Etype (Call_Node, Etype (Matching_Op));
9743 return Present (Matching_Op);
9744 end Try_Primitive_Operation;
9746 ---------------------
9747 -- Valid_Candidate --
9748 ---------------------
9750 function Valid_Candidate
9753 Subp : Entity_Id) return Entity_Id
9755 Arr_Type : Entity_Id;
9756 Comp_Type : Entity_Id;
9759 -- If the subprogram is a valid interpretation, record it in global
9760 -- variable Subprog, to collect all possible overloadings.
9763 if Subp /= Entity (Subprog) then
9764 Add_One_Interp (Subprog, Subp, Etype (Subp));
9768 -- If the call may be an indexed call, retrieve component type of
9769 -- resulting expression, and add possible interpretation.
9774 if Nkind (Call) = N_Function_Call
9775 and then Nkind (Parent (N)) = N_Indexed_Component
9776 and then Needs_One_Actual (Subp)
9778 if Is_Array_Type (Etype (Subp)) then
9779 Arr_Type := Etype (Subp);
9781 elsif Is_Access_Type (Etype (Subp))
9782 and then Is_Array_Type (Designated_Type (Etype (Subp)))
9784 Arr_Type := Designated_Type (Etype (Subp));
9788 if Present (Arr_Type) then
9790 -- Verify that the actuals (excluding the object) match the types
9798 Actual := Next (First_Actual (Call));
9799 Index := First_Index (Arr_Type);
9800 while Present (Actual) and then Present (Index) loop
9801 if not Has_Compatible_Type (Actual, Etype (Index)) then
9806 Next_Actual (Actual);
9812 and then Present (Arr_Type)
9814 Comp_Type := Component_Type (Arr_Type);
9818 if Present (Comp_Type)
9819 and then Etype (Subprog) /= Comp_Type
9821 Add_One_Interp (Subprog, Subp, Comp_Type);
9825 if Etype (Call) /= Any_Type then
9830 end Valid_Candidate;
9832 -- Start of processing for Try_Object_Operation
9835 Analyze_Expression (Obj);
9837 -- Analyze the actuals if node is known to be a subprogram call
9839 if Is_Subprg_Call and then N = Name (Parent (N)) then
9840 Actual := First (Parameter_Associations (Parent (N)));
9841 while Present (Actual) loop
9842 Analyze_Expression (Actual);
9847 -- Build a subprogram call node, using a copy of Obj as its first
9848 -- actual. This is a placeholder, to be replaced by an explicit
9849 -- dereference when needed.
9851 Transform_Object_Operation
9852 (Call_Node => New_Call_Node,
9853 Node_To_Replace => Node_To_Replace);
9855 Set_Etype (New_Call_Node, Any_Type);
9856 Set_Etype (Subprog, Any_Type);
9857 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
9859 if not Is_Overloaded (Obj) then
9860 Try_One_Prefix_Interpretation (Obj_Type);
9867 Get_First_Interp (Obj, I, It);
9868 while Present (It.Nam) loop
9869 Try_One_Prefix_Interpretation (It.Typ);
9870 Get_Next_Interp (I, It);
9875 if Etype (New_Call_Node) /= Any_Type then
9877 -- No need to complete the tree transformations if we are only
9878 -- searching for conflicting class-wide subprograms
9880 if CW_Test_Only then
9883 Complete_Object_Operation
9884 (Call_Node => New_Call_Node,
9885 Node_To_Replace => Node_To_Replace);
9889 elsif Present (Candidate) then
9891 -- The argument list is not type correct. Re-analyze with error
9892 -- reporting enabled, and use one of the possible candidates.
9893 -- In All_Errors_Mode, re-analyze all failed interpretations.
9895 if All_Errors_Mode then
9896 Report_Error := True;
9897 if Try_Primitive_Operation
9898 (Call_Node => New_Call_Node,
9899 Node_To_Replace => Node_To_Replace)
9902 Try_Class_Wide_Operation
9903 (Call_Node => New_Call_Node,
9904 Node_To_Replace => Node_To_Replace)
9911 (N => New_Call_Node,
9915 Skip_First => True);
9918 -- No need for further errors
9923 -- There was no candidate operation, so report it as an error
9924 -- in the caller: Analyze_Selected_Component.
9928 end Try_Object_Operation;
9934 procedure wpo (T : Entity_Id) is
9939 if not Is_Tagged_Type (T) then
9943 E := First_Elmt (Primitive_Operations (Base_Type (T)));
9944 while Present (E) loop
9946 Write_Int (Int (Op));
9947 Write_Str (" === ");
9948 Write_Name (Chars (Op));
9950 Write_Name (Chars (Scope (Op)));