1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Util; use Exp_Util;
33 with Fname; use Fname;
34 with Itypes; use Itypes;
36 with Lib.Xref; use Lib.Xref;
37 with Namet; use Namet;
38 with Namet.Sp; use Namet.Sp;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
42 with Output; use Output;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
46 with Sem_Aux; use Sem_Aux;
47 with Sem_Case; use Sem_Case;
48 with Sem_Cat; use Sem_Cat;
49 with Sem_Ch3; use Sem_Ch3;
50 with Sem_Ch6; use Sem_Ch6;
51 with Sem_Ch8; use Sem_Ch8;
52 with Sem_Dim; use Sem_Dim;
53 with Sem_Disp; use Sem_Disp;
54 with Sem_Dist; use Sem_Dist;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Res; use Sem_Res;
57 with Sem_Type; use Sem_Type;
58 with Sem_Util; use Sem_Util;
59 with Sem_Warn; use Sem_Warn;
60 with Stand; use Stand;
61 with Sinfo; use Sinfo;
62 with Snames; use Snames;
63 with Tbuild; use Tbuild;
64 with Uintp; use Uintp;
66 package body Sem_Ch4 is
68 -- Tables which speed up the identification of dangerous calls to Ada 2012
69 -- functions with writable actuals (AI05-0144).
71 -- The following table enumerates the Ada constructs which may evaluate in
72 -- arbitrary order. It does not cover all the language constructs which can
73 -- be evaluated in arbitrary order but the subset needed for AI05-0144.
75 Has_Arbitrary_Evaluation_Order : constant array (Node_Kind) of Boolean :=
77 N_Assignment_Statement => True,
78 N_Entry_Call_Statement => True,
79 N_Extension_Aggregate => True,
80 N_Full_Type_Declaration => True,
81 N_Indexed_Component => True,
82 N_Object_Declaration => True,
86 N_Array_Type_Definition => True,
87 N_Membership_Test => True,
89 N_Subprogram_Call => True,
92 -- The following table enumerates the nodes on which we stop climbing when
93 -- locating the outermost Ada construct that can be evaluated in arbitrary
96 Stop_Subtree_Climbing : constant array (Node_Kind) of Boolean :=
98 N_Assignment_Statement => True,
99 N_Entry_Call_Statement => True,
100 N_Extended_Return_Statement => True,
101 N_Extension_Aggregate => True,
102 N_Full_Type_Declaration => True,
103 N_Object_Declaration => True,
104 N_Object_Renaming_Declaration => True,
105 N_Package_Specification => True,
107 N_Procedure_Call_Statement => True,
108 N_Simple_Return_Statement => True,
109 N_Has_Condition => True,
112 -----------------------
113 -- Local Subprograms --
114 -----------------------
116 procedure Analyze_Concatenation_Rest (N : Node_Id);
117 -- Does the "rest" of the work of Analyze_Concatenation, after the left
118 -- operand has been analyzed. See Analyze_Concatenation for details.
120 procedure Analyze_Expression (N : Node_Id);
121 -- For expressions that are not names, this is just a call to analyze. If
122 -- the expression is a name, it may be a call to a parameterless function,
123 -- and if so must be converted into an explicit call node and analyzed as
124 -- such. This deproceduring must be done during the first pass of overload
125 -- resolution, because otherwise a procedure call with overloaded actuals
126 -- may fail to resolve.
128 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
129 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call is an
130 -- operator name or an expanded name whose selector is an operator name,
131 -- and one possible interpretation is as a predefined operator.
133 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
134 -- If the prefix of a selected_component is overloaded, the proper
135 -- interpretation that yields a record type with the proper selector
136 -- name must be selected.
138 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
139 -- Procedure to analyze a user defined binary operator, which is resolved
140 -- like a function, but instead of a list of actuals it is presented
141 -- with the left and right operands of an operator node.
143 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
144 -- Procedure to analyze a user defined unary operator, which is resolved
145 -- like a function, but instead of a list of actuals, it is presented with
146 -- the operand of the operator node.
148 procedure Ambiguous_Operands (N : Node_Id);
149 -- For equality, membership, and comparison operators with overloaded
150 -- arguments, list possible interpretations.
152 procedure Analyze_One_Call
156 Success : out Boolean;
157 Skip_First : Boolean := False);
158 -- Check one interpretation of an overloaded subprogram name for
159 -- compatibility with the types of the actuals in a call. If there is a
160 -- single interpretation which does not match, post error if Report is
163 -- Nam is the entity that provides the formals against which the actuals
164 -- are checked. Nam is either the name of a subprogram, or the internal
165 -- subprogram type constructed for an access_to_subprogram. If the actuals
166 -- are compatible with Nam, then Nam is added to the list of candidate
167 -- interpretations for N, and Success is set to True.
169 -- The flag Skip_First is used when analyzing a call that was rewritten
170 -- from object notation. In this case the first actual may have to receive
171 -- an explicit dereference, depending on the first formal of the operation
172 -- being called. The caller will have verified that the object is legal
173 -- for the call. If the remaining parameters match, the first parameter
174 -- will rewritten as a dereference if needed, prior to completing analysis.
176 procedure Check_Misspelled_Selector
179 -- Give possible misspelling message if Sel seems likely to be a mis-
180 -- spelling of one of the selectors of the Prefix. This is called by
181 -- Analyze_Selected_Component after producing an invalid selector error
184 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
185 -- Verify that type T is declared in scope S. Used to find interpretations
186 -- for operators given by expanded names. This is abstracted as a separate
187 -- function to handle extensions to System, where S is System, but T is
188 -- declared in the extension.
190 procedure Find_Arithmetic_Types
194 -- L and R are the operands of an arithmetic operator. Find consistent
195 -- pairs of interpretations for L and R that have a numeric type consistent
196 -- with the semantics of the operator.
198 procedure Find_Comparison_Types
202 -- L and R are operands of a comparison operator. Find consistent pairs of
203 -- interpretations for L and R.
205 procedure Find_Concatenation_Types
209 -- For the four varieties of concatenation
211 procedure Find_Equality_Types
215 -- Ditto for equality operators
217 procedure Find_Boolean_Types
221 -- Ditto for binary logical operations
223 procedure Find_Negation_Types
227 -- Find consistent interpretation for operand of negation operator
229 procedure Find_Non_Universal_Interpretations
234 -- For equality and comparison operators, the result is always boolean,
235 -- and the legality of the operation is determined from the visibility
236 -- of the operand types. If one of the operands has a universal interpre-
237 -- tation, the legality check uses some compatible non-universal
238 -- interpretation of the other operand. N can be an operator node, or
239 -- a function call whose name is an operator designator. Any_Access, which
240 -- is the initial type of the literal NULL, is a universal type for the
241 -- purpose of this routine.
243 function Find_Primitive_Operation (N : Node_Id) return Boolean;
244 -- Find candidate interpretations for the name Obj.Proc when it appears
245 -- in a subprogram renaming declaration.
247 procedure Find_Unary_Types
251 -- Unary arithmetic types: plus, minus, abs
253 procedure Check_Arithmetic_Pair
257 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid types
258 -- for left and right operand. Determine whether they constitute a valid
259 -- pair for the given operator, and record the corresponding interpretation
260 -- of the operator node. The node N may be an operator node (the usual
261 -- case) or a function call whose prefix is an operator designator. In
262 -- both cases Op_Id is the operator name itself.
264 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
265 -- Give detailed information on overloaded call where none of the
266 -- interpretations match. N is the call node, Nam the designator for
267 -- the overloaded entity being called.
269 function Junk_Operand (N : Node_Id) return Boolean;
270 -- Test for an operand that is an inappropriate entity (e.g. a package
271 -- name or a label). If so, issue an error message and return True. If
272 -- the operand is not an inappropriate entity kind, return False.
274 procedure Operator_Check (N : Node_Id);
275 -- Verify that an operator has received some valid interpretation. If none
276 -- was found, determine whether a use clause would make the operation
277 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
278 -- every type compatible with the operator, even if the operator for the
279 -- type is not directly visible. The routine uses this type to emit a more
280 -- informative message.
282 function Process_Implicit_Dereference_Prefix
284 P : Node_Id) return Entity_Id;
285 -- Called when P is the prefix of an implicit dereference, denoting an
286 -- object E. The function returns the designated type of the prefix, taking
287 -- into account that the designated type of an anonymous access type may be
288 -- a limited view, when the non-limited view is visible.
290 -- If in semantics only mode (-gnatc or generic), the function also records
291 -- that the prefix is a reference to E, if any. Normally, such a reference
292 -- is generated only when the implicit dereference is expanded into an
293 -- explicit one, but for consistency we must generate the reference when
294 -- expansion is disabled as well.
296 procedure Remove_Abstract_Operations (N : Node_Id);
297 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
298 -- operation is not a candidate interpretation.
300 function Try_Container_Indexing
303 Exprs : List_Id) return Boolean;
304 -- AI05-0139: Generalized indexing to support iterators over containers
306 function Try_Indexed_Call
310 Skip_First : Boolean) return Boolean;
311 -- If a function has defaults for all its actuals, a call to it may in fact
312 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
313 -- interpretation as an indexing, prior to analysis as a call. If both are
314 -- possible, the node is overloaded with both interpretations (same symbol
315 -- but two different types). If the call is written in prefix form, the
316 -- prefix becomes the first parameter in the call, and only the remaining
317 -- actuals must be checked for the presence of defaults.
319 function Try_Indirect_Call
322 Typ : Entity_Id) return Boolean;
323 -- Similarly, a function F that needs no actuals can return an access to a
324 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
325 -- the call may be overloaded with both interpretations.
327 function Try_Object_Operation
329 CW_Test_Only : Boolean := False) return Boolean;
330 -- Ada 2005 (AI-252): Support the object.operation notation. If node N
331 -- is a call in this notation, it is transformed into a normal subprogram
332 -- call where the prefix is a parameter, and True is returned. If node
333 -- N is not of this form, it is unchanged, and False is returned. If
334 -- CW_Test_Only is true then N is an N_Selected_Component node which
335 -- is part of a call to an entry or procedure of a tagged concurrent
336 -- type and this routine is invoked to search for class-wide subprograms
337 -- conflicting with the target entity.
339 procedure wpo (T : Entity_Id);
340 pragma Warnings (Off, wpo);
341 -- Used for debugging: obtain list of primitive operations even if
342 -- type is not frozen and dispatch table is not built yet.
344 ------------------------
345 -- Ambiguous_Operands --
346 ------------------------
348 procedure Ambiguous_Operands (N : Node_Id) is
349 procedure List_Operand_Interps (Opnd : Node_Id);
351 --------------------------
352 -- List_Operand_Interps --
353 --------------------------
355 procedure List_Operand_Interps (Opnd : Node_Id) is
360 if Is_Overloaded (Opnd) then
361 if Nkind (Opnd) in N_Op then
364 elsif Nkind (Opnd) = N_Function_Call then
367 elsif Ada_Version >= Ada_2012 then
373 Get_First_Interp (Opnd, I, It);
374 while Present (It.Nam) loop
375 if Has_Implicit_Dereference (It.Typ) then
377 ("can be interpreted as implicit dereference", Opnd);
381 Get_Next_Interp (I, It);
392 if Opnd = Left_Opnd (N) then
394 ("\left operand has the following interpretations", N);
397 ("\right operand has the following interpretations", N);
401 List_Interps (Nam, Err);
402 end List_Operand_Interps;
404 -- Start of processing for Ambiguous_Operands
407 if Nkind (N) in N_Membership_Test then
408 Error_Msg_N ("ambiguous operands for membership", N);
410 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
411 Error_Msg_N ("ambiguous operands for equality", N);
414 Error_Msg_N ("ambiguous operands for comparison", N);
417 if All_Errors_Mode then
418 List_Operand_Interps (Left_Opnd (N));
419 List_Operand_Interps (Right_Opnd (N));
421 Error_Msg_N ("\use -gnatf switch for details", N);
423 end Ambiguous_Operands;
425 -----------------------
426 -- Analyze_Aggregate --
427 -----------------------
429 -- Most of the analysis of Aggregates requires that the type be known,
430 -- and is therefore put off until resolution.
432 procedure Analyze_Aggregate (N : Node_Id) is
434 if No (Etype (N)) then
435 Set_Etype (N, Any_Composite);
437 end Analyze_Aggregate;
439 -----------------------
440 -- Analyze_Allocator --
441 -----------------------
443 procedure Analyze_Allocator (N : Node_Id) is
444 Loc : constant Source_Ptr := Sloc (N);
445 Sav_Errs : constant Nat := Serious_Errors_Detected;
446 E : Node_Id := Expression (N);
447 Acc_Type : Entity_Id;
454 Check_SPARK_05_Restriction ("allocator is not allowed", N);
456 -- Deal with allocator restrictions
458 -- In accordance with H.4(7), the No_Allocators restriction only applies
459 -- to user-written allocators. The same consideration applies to the
460 -- No_Standard_Allocators_Before_Elaboration restriction.
462 if Comes_From_Source (N) then
463 Check_Restriction (No_Allocators, N);
465 -- Processing for No_Standard_Allocators_After_Elaboration, loop to
466 -- look at enclosing context, checking task/main subprogram case.
470 while Present (P) loop
472 -- For the task case we need a handled sequence of statements,
473 -- where the occurrence of the allocator is within the statements
474 -- and the parent is a task body
476 if Nkind (P) = N_Handled_Sequence_Of_Statements
477 and then Is_List_Member (C)
478 and then List_Containing (C) = Statements (P)
480 Onode := Original_Node (Parent (P));
482 -- Check for allocator within task body, this is a definite
483 -- violation of No_Allocators_After_Elaboration we can detect
486 if Nkind (Onode) = N_Task_Body then
488 (No_Standard_Allocators_After_Elaboration, N);
493 -- The other case is appearance in a subprogram body. This is
494 -- a violation if this is a library level subprogram with no
495 -- parameters. Note that this is now a static error even if the
496 -- subprogram is not the main program (this is a change, in an
497 -- earlier version only the main program was affected, and the
498 -- check had to be done in the binder.
500 if Nkind (P) = N_Subprogram_Body
501 and then Nkind (Parent (P)) = N_Compilation_Unit
502 and then No (Parameter_Specifications (Specification (P)))
505 (No_Standard_Allocators_After_Elaboration, N);
513 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
514 -- any. The expected type for the name is any type. A non-overloading
515 -- rule then requires it to be of a type descended from
516 -- System.Storage_Pools.Subpools.Subpool_Handle.
518 -- This isn't exactly what the AI says, but it seems to be the right
519 -- rule. The AI should be fixed.???
522 Subpool : constant Node_Id := Subpool_Handle_Name (N);
525 if Present (Subpool) then
528 if Is_Overloaded (Subpool) then
529 Error_Msg_N ("ambiguous subpool handle", Subpool);
532 -- Check that Etype (Subpool) is descended from Subpool_Handle
538 -- Analyze the qualified expression or subtype indication
540 if Nkind (E) = N_Qualified_Expression then
541 Acc_Type := Create_Itype (E_Allocator_Type, N);
542 Set_Etype (Acc_Type, Acc_Type);
543 Find_Type (Subtype_Mark (E));
545 -- Analyze the qualified expression, and apply the name resolution
546 -- rule given in 4.7(3).
549 Type_Id := Etype (E);
550 Set_Directly_Designated_Type (Acc_Type, Type_Id);
552 -- A qualified expression requires an exact match of the type,
553 -- class-wide matching is not allowed.
555 -- if Is_Class_Wide_Type (Type_Id)
556 -- and then Base_Type
557 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
559 -- Wrong_Type (Expression (E), Type_Id);
562 -- We don't analyze the qualified expression itself because it's
563 -- part of the allocator. It is fully analyzed and resolved when
564 -- the allocator is resolved with the context type.
566 Set_Etype (E, Type_Id);
568 -- Case where allocator has a subtype indication
573 Base_Typ : Entity_Id;
576 -- If the allocator includes a N_Subtype_Indication then a
577 -- constraint is present, otherwise the node is a subtype mark.
578 -- Introduce an explicit subtype declaration into the tree
579 -- defining some anonymous subtype and rewrite the allocator to
580 -- use this subtype rather than the subtype indication.
582 -- It is important to introduce the explicit subtype declaration
583 -- so that the bounds of the subtype indication are attached to
584 -- the tree in case the allocator is inside a generic unit.
586 if Nkind (E) = N_Subtype_Indication then
588 -- A constraint is only allowed for a composite type in Ada
589 -- 95. In Ada 83, a constraint is also allowed for an
590 -- access-to-composite type, but the constraint is ignored.
592 Find_Type (Subtype_Mark (E));
593 Base_Typ := Entity (Subtype_Mark (E));
595 if Is_Elementary_Type (Base_Typ) then
596 if not (Ada_Version = Ada_83
597 and then Is_Access_Type (Base_Typ))
599 Error_Msg_N ("constraint not allowed here", E);
601 if Nkind (Constraint (E)) =
602 N_Index_Or_Discriminant_Constraint
604 Error_Msg_N -- CODEFIX
605 ("\if qualified expression was meant, " &
606 "use apostrophe", Constraint (E));
610 -- Get rid of the bogus constraint:
612 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
613 Analyze_Allocator (N);
617 if Expander_Active then
618 Def_Id := Make_Temporary (Loc, 'S');
621 Make_Subtype_Declaration (Loc,
622 Defining_Identifier => Def_Id,
623 Subtype_Indication => Relocate_Node (E)));
625 if Sav_Errs /= Serious_Errors_Detected
626 and then Nkind (Constraint (E)) =
627 N_Index_Or_Discriminant_Constraint
629 Error_Msg_N -- CODEFIX
630 ("if qualified expression was meant, "
631 & "use apostrophe!", Constraint (E));
634 E := New_Occurrence_Of (Def_Id, Loc);
635 Rewrite (Expression (N), E);
639 Type_Id := Process_Subtype (E, N);
640 Acc_Type := Create_Itype (E_Allocator_Type, N);
641 Set_Etype (Acc_Type, Acc_Type);
642 Set_Directly_Designated_Type (Acc_Type, Type_Id);
643 Check_Fully_Declared (Type_Id, N);
645 -- Ada 2005 (AI-231): If the designated type is itself an access
646 -- type that excludes null, its default initialization will
647 -- be a null object, and we can insert an unconditional raise
648 -- before the allocator.
650 -- Ada 2012 (AI-104): A not null indication here is altogether
653 if Can_Never_Be_Null (Type_Id) then
655 Not_Null_Check : constant Node_Id :=
656 Make_Raise_Constraint_Error (Sloc (E),
657 Reason => CE_Null_Not_Allowed);
660 if Expander_Active then
661 Insert_Action (N, Not_Null_Check);
662 Analyze (Not_Null_Check);
664 elsif Warn_On_Ada_2012_Compatibility then
666 ("null value not allowed here in Ada 2012?y?", E);
671 -- Check for missing initialization. Skip this check if we already
672 -- had errors on analyzing the allocator, since in that case these
673 -- are probably cascaded errors.
675 if not Is_Definite_Subtype (Type_Id)
676 and then Serious_Errors_Detected = Sav_Errs
678 -- The build-in-place machinery may produce an allocator when
679 -- the designated type is indefinite but the underlying type is
680 -- not. In this case the unknown discriminants are meaningless
681 -- and should not trigger error messages. Check the parent node
682 -- because the allocator is marked as coming from source.
684 if Present (Underlying_Type (Type_Id))
685 and then Is_Definite_Subtype (Underlying_Type (Type_Id))
686 and then not Comes_From_Source (Parent (N))
690 elsif Is_Class_Wide_Type (Type_Id) then
692 ("initialization required in class-wide allocation", N);
695 if Ada_Version < Ada_2005
696 and then Is_Limited_Type (Type_Id)
698 Error_Msg_N ("unconstrained allocation not allowed", N);
700 if Is_Array_Type (Type_Id) then
702 ("\constraint with array bounds required", N);
704 elsif Has_Unknown_Discriminants (Type_Id) then
707 else pragma Assert (Has_Discriminants (Type_Id));
709 ("\constraint with discriminant values required", N);
712 -- Limited Ada 2005 and general non-limited case
716 ("uninitialized unconstrained allocation not "
719 if Is_Array_Type (Type_Id) then
721 ("\qualified expression or constraint with "
722 & "array bounds required", N);
724 elsif Has_Unknown_Discriminants (Type_Id) then
725 Error_Msg_N ("\qualified expression required", N);
727 else pragma Assert (Has_Discriminants (Type_Id));
729 ("\qualified expression or constraint with "
730 & "discriminant values required", N);
738 if Is_Abstract_Type (Type_Id) then
739 Error_Msg_N ("cannot allocate abstract object", E);
742 if Has_Task (Designated_Type (Acc_Type)) then
743 Check_Restriction (No_Tasking, N);
744 Check_Restriction (Max_Tasks, N);
745 Check_Restriction (No_Task_Allocators, N);
748 -- Check restriction against dynamically allocated protected objects
750 if Has_Protected (Designated_Type (Acc_Type)) then
751 Check_Restriction (No_Protected_Type_Allocators, N);
754 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
755 -- type is nested, and the designated type needs finalization. The rule
756 -- is conservative in that class-wide types need finalization.
758 if Needs_Finalization (Designated_Type (Acc_Type))
759 and then not Is_Library_Level_Entity (Acc_Type)
761 Check_Restriction (No_Nested_Finalization, N);
764 -- Check that an allocator of a nested access type doesn't create a
765 -- protected object when restriction No_Local_Protected_Objects applies.
767 if Has_Protected (Designated_Type (Acc_Type))
768 and then not Is_Library_Level_Entity (Acc_Type)
770 Check_Restriction (No_Local_Protected_Objects, N);
773 -- If the No_Streams restriction is set, check that the type of the
774 -- object is not, and does not contain, any subtype derived from
775 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
776 -- Has_Stream just for efficiency reasons. There is no point in
777 -- spending time on a Has_Stream check if the restriction is not set.
779 if Restriction_Check_Required (No_Streams) then
780 if Has_Stream (Designated_Type (Acc_Type)) then
781 Check_Restriction (No_Streams, N);
785 Set_Etype (N, Acc_Type);
787 if not Is_Library_Level_Entity (Acc_Type) then
788 Check_Restriction (No_Local_Allocators, N);
791 if Serious_Errors_Detected > Sav_Errs then
792 Set_Error_Posted (N);
793 Set_Etype (N, Any_Type);
795 end Analyze_Allocator;
797 ---------------------------
798 -- Analyze_Arithmetic_Op --
799 ---------------------------
801 procedure Analyze_Arithmetic_Op (N : Node_Id) is
802 L : constant Node_Id := Left_Opnd (N);
803 R : constant Node_Id := Right_Opnd (N);
807 Candidate_Type := Empty;
808 Analyze_Expression (L);
809 Analyze_Expression (R);
811 -- If the entity is already set, the node is the instantiation of a
812 -- generic node with a non-local reference, or was manufactured by a
813 -- call to Make_Op_xxx. In either case the entity is known to be valid,
814 -- and we do not need to collect interpretations, instead we just get
815 -- the single possible interpretation.
819 if Present (Op_Id) then
820 if Ekind (Op_Id) = E_Operator then
822 if Nkind_In (N, N_Op_Divide, N_Op_Mod, N_Op_Multiply, N_Op_Rem)
823 and then Treat_Fixed_As_Integer (N)
827 Set_Etype (N, Any_Type);
828 Find_Arithmetic_Types (L, R, Op_Id, N);
832 Set_Etype (N, Any_Type);
833 Add_One_Interp (N, Op_Id, Etype (Op_Id));
836 -- Entity is not already set, so we do need to collect interpretations
839 Set_Etype (N, Any_Type);
841 Op_Id := Get_Name_Entity_Id (Chars (N));
842 while Present (Op_Id) loop
843 if Ekind (Op_Id) = E_Operator
844 and then Present (Next_Entity (First_Entity (Op_Id)))
846 Find_Arithmetic_Types (L, R, Op_Id, N);
848 -- The following may seem superfluous, because an operator cannot
849 -- be generic, but this ignores the cleverness of the author of
852 elsif Is_Overloadable (Op_Id) then
853 Analyze_User_Defined_Binary_Op (N, Op_Id);
856 Op_Id := Homonym (Op_Id);
861 Check_Function_Writable_Actuals (N);
862 end Analyze_Arithmetic_Op;
868 -- Function, procedure, and entry calls are checked here. The Name in
869 -- the call may be overloaded. The actuals have been analyzed and may
870 -- themselves be overloaded. On exit from this procedure, the node N
871 -- may have zero, one or more interpretations. In the first case an
872 -- error message is produced. In the last case, the node is flagged
873 -- as overloaded and the interpretations are collected in All_Interp.
875 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
876 -- the type-checking is similar to that of other calls.
878 procedure Analyze_Call (N : Node_Id) is
879 Actuals : constant List_Id := Parameter_Associations (N);
884 Success : Boolean := False;
886 Deref : Boolean := False;
887 -- Flag indicates whether an interpretation of the prefix is a
888 -- parameterless call that returns an access_to_subprogram.
890 procedure Check_Mixed_Parameter_And_Named_Associations;
891 -- Check that parameter and named associations are not mixed. This is
892 -- a restriction in SPARK mode.
894 procedure Check_Writable_Actuals (N : Node_Id);
895 -- If the call has out or in-out parameters then mark its outermost
896 -- enclosing construct as a node on which the writable actuals check
897 -- must be performed.
899 function Name_Denotes_Function return Boolean;
900 -- If the type of the name is an access to subprogram, this may be the
901 -- type of a name, or the return type of the function being called. If
902 -- the name is not an entity then it can denote a protected function.
903 -- Until we distinguish Etype from Return_Type, we must use this routine
904 -- to resolve the meaning of the name in the call.
906 procedure No_Interpretation;
907 -- Output error message when no valid interpretation exists
909 --------------------------------------------------
910 -- Check_Mixed_Parameter_And_Named_Associations --
911 --------------------------------------------------
913 procedure Check_Mixed_Parameter_And_Named_Associations is
915 Named_Seen : Boolean;
920 Actual := First (Actuals);
921 while Present (Actual) loop
922 case Nkind (Actual) is
923 when N_Parameter_Association =>
925 Check_SPARK_05_Restriction
926 ("named association cannot follow positional one",
937 end Check_Mixed_Parameter_And_Named_Associations;
939 ----------------------------
940 -- Check_Writable_Actuals --
941 ----------------------------
943 -- The identification of conflicts in calls to functions with writable
944 -- actuals is performed in the analysis phase of the front end to ensure
945 -- that it reports exactly the same errors compiling with and without
946 -- expansion enabled. It is performed in two stages:
948 -- 1) When a call to a function with out-mode parameters is found,
949 -- we climb to the outermost enclosing construct that can be
950 -- evaluated in arbitrary order and we mark it with the flag
953 -- 2) When the analysis of the marked node is complete, we traverse
954 -- its decorated subtree searching for conflicts (see function
955 -- Sem_Util.Check_Function_Writable_Actuals).
957 -- The unique exception to this general rule is for aggregates, since
958 -- their analysis is performed by the front end in the resolution
959 -- phase. For aggregates we do not climb to their enclosing construct:
960 -- we restrict the analysis to the subexpressions initializing the
961 -- aggregate components.
963 -- This implies that the analysis of expressions containing aggregates
964 -- is not complete, since there may be conflicts on writable actuals
965 -- involving subexpressions of the enclosing logical or arithmetic
966 -- expressions. However, we cannot wait and perform the analysis when
967 -- the whole subtree is resolved, since the subtrees may be transformed,
968 -- thus adding extra complexity and computation cost to identify and
969 -- report exactly the same errors compiling with and without expansion
972 procedure Check_Writable_Actuals (N : Node_Id) is
974 if Comes_From_Source (N)
975 and then Present (Get_Subprogram_Entity (N))
976 and then Has_Out_Or_In_Out_Parameter (Get_Subprogram_Entity (N))
978 -- For procedures and entries there is no need to climb since
979 -- we only need to check if the actuals of this call invoke
980 -- functions whose out-mode parameters overlap.
982 if Nkind (N) /= N_Function_Call then
983 Set_Check_Actuals (N);
985 -- For calls to functions we climb to the outermost enclosing
986 -- construct where the out-mode actuals of this function may
987 -- introduce conflicts.
995 while Present (P) loop
997 -- For object declarations we can climb to the node from
998 -- its object definition branch or from its initializing
999 -- expression. We prefer to mark the child node as the
1000 -- outermost construct to avoid adding further complexity
1001 -- to the routine that will later take care of
1002 -- performing the writable actuals check.
1004 if Has_Arbitrary_Evaluation_Order (Nkind (P))
1005 and then not Nkind_In (P, N_Assignment_Statement,
1006 N_Object_Declaration)
1011 -- Avoid climbing more than needed!
1013 exit when Stop_Subtree_Climbing (Nkind (P))
1014 or else (Nkind (P) = N_Range
1016 Nkind_In (Parent (P), N_In, N_Not_In));
1021 Set_Check_Actuals (Outermost);
1025 end Check_Writable_Actuals;
1027 ---------------------------
1028 -- Name_Denotes_Function --
1029 ---------------------------
1031 function Name_Denotes_Function return Boolean is
1033 if Is_Entity_Name (Nam) then
1034 return Ekind (Entity (Nam)) = E_Function;
1035 elsif Nkind (Nam) = N_Selected_Component then
1036 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
1040 end Name_Denotes_Function;
1042 -----------------------
1043 -- No_Interpretation --
1044 -----------------------
1046 procedure No_Interpretation is
1047 L : constant Boolean := Is_List_Member (N);
1048 K : constant Node_Kind := Nkind (Parent (N));
1051 -- If the node is in a list whose parent is not an expression then it
1052 -- must be an attempted procedure call.
1054 if L and then K not in N_Subexpr then
1055 if Ekind (Entity (Nam)) = E_Generic_Procedure then
1057 ("must instantiate generic procedure& before call",
1060 Error_Msg_N ("procedure or entry name expected", Nam);
1063 -- Check for tasking cases where only an entry call will do
1066 and then Nkind_In (K, N_Entry_Call_Alternative,
1067 N_Triggering_Alternative)
1069 Error_Msg_N ("entry name expected", Nam);
1071 -- Otherwise give general error message
1074 Error_Msg_N ("invalid prefix in call", Nam);
1076 end No_Interpretation;
1078 -- Start of processing for Analyze_Call
1081 if Restriction_Check_Required (SPARK_05) then
1082 Check_Mixed_Parameter_And_Named_Associations;
1085 -- Initialize the type of the result of the call to the error type,
1086 -- which will be reset if the type is successfully resolved.
1088 Set_Etype (N, Any_Type);
1092 if not Is_Overloaded (Nam) then
1094 -- Only one interpretation to check
1096 if Ekind (Etype (Nam)) = E_Subprogram_Type then
1097 Nam_Ent := Etype (Nam);
1099 -- If the prefix is an access_to_subprogram, this may be an indirect
1100 -- call. This is the case if the name in the call is not an entity
1101 -- name, or if it is a function name in the context of a procedure
1102 -- call. In this latter case, we have a call to a parameterless
1103 -- function that returns a pointer_to_procedure which is the entity
1104 -- being called. Finally, F (X) may be a call to a parameterless
1105 -- function that returns a pointer to a function with parameters.
1106 -- Note that if F returns an access-to-subprogram whose designated
1107 -- type is an array, F (X) cannot be interpreted as an indirect call
1108 -- through the result of the call to F.
1110 elsif Is_Access_Type (Etype (Nam))
1111 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
1113 (not Name_Denotes_Function
1114 or else Nkind (N) = N_Procedure_Call_Statement
1116 (Nkind (Parent (N)) /= N_Explicit_Dereference
1117 and then Is_Entity_Name (Nam)
1118 and then No (First_Formal (Entity (Nam)))
1120 Is_Array_Type (Etype (Designated_Type (Etype (Nam))))
1121 and then Present (Actuals)))
1123 Nam_Ent := Designated_Type (Etype (Nam));
1124 Insert_Explicit_Dereference (Nam);
1126 -- Selected component case. Simple entry or protected operation,
1127 -- where the entry name is given by the selector name.
1129 elsif Nkind (Nam) = N_Selected_Component then
1130 Nam_Ent := Entity (Selector_Name (Nam));
1132 if not Ekind_In (Nam_Ent, E_Entry,
1137 Error_Msg_N ("name in call is not a callable entity", Nam);
1138 Set_Etype (N, Any_Type);
1142 -- If the name is an Indexed component, it can be a call to a member
1143 -- of an entry family. The prefix must be a selected component whose
1144 -- selector is the entry. Analyze_Procedure_Call normalizes several
1145 -- kinds of call into this form.
1147 elsif Nkind (Nam) = N_Indexed_Component then
1148 if Nkind (Prefix (Nam)) = N_Selected_Component then
1149 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
1151 Error_Msg_N ("name in call is not a callable entity", Nam);
1152 Set_Etype (N, Any_Type);
1156 elsif not Is_Entity_Name (Nam) then
1157 Error_Msg_N ("name in call is not a callable entity", Nam);
1158 Set_Etype (N, Any_Type);
1162 Nam_Ent := Entity (Nam);
1164 -- If not overloadable, this may be a generalized indexing
1165 -- operation with named associations. Rewrite again as an
1166 -- indexed component and analyze as container indexing.
1168 if not Is_Overloadable (Nam_Ent) then
1170 (Find_Value_Of_Aspect
1171 (Etype (Nam_Ent), Aspect_Constant_Indexing))
1174 Make_Indexed_Component (Sloc (N),
1176 Expressions => Parameter_Associations (N)));
1178 if Try_Container_Indexing (N, Nam, Expressions (N)) then
1192 -- Operations generated for RACW stub types are called only through
1193 -- dispatching, and can never be the static interpretation of a call.
1195 if Is_RACW_Stub_Type_Operation (Nam_Ent) then
1200 Analyze_One_Call (N, Nam_Ent, True, Success);
1202 -- If this is an indirect call, the return type of the access_to
1203 -- subprogram may be an incomplete type. At the point of the call,
1204 -- use the full type if available, and at the same time update the
1205 -- return type of the access_to_subprogram.
1208 and then Nkind (Nam) = N_Explicit_Dereference
1209 and then Ekind (Etype (N)) = E_Incomplete_Type
1210 and then Present (Full_View (Etype (N)))
1212 Set_Etype (N, Full_View (Etype (N)));
1213 Set_Etype (Nam_Ent, Etype (N));
1219 -- An overloaded selected component must denote overloaded operations
1220 -- of a concurrent type. The interpretations are attached to the
1221 -- simple name of those operations.
1223 if Nkind (Nam) = N_Selected_Component then
1224 Nam := Selector_Name (Nam);
1227 Get_First_Interp (Nam, X, It);
1228 while Present (It.Nam) loop
1232 -- Name may be call that returns an access to subprogram, or more
1233 -- generally an overloaded expression one of whose interpretations
1234 -- yields an access to subprogram. If the name is an entity, we do
1235 -- not dereference, because the node is a call that returns the
1236 -- access type: note difference between f(x), where the call may
1237 -- return an access subprogram type, and f(x)(y), where the type
1238 -- returned by the call to f is implicitly dereferenced to analyze
1241 if Is_Access_Type (Nam_Ent) then
1242 Nam_Ent := Designated_Type (Nam_Ent);
1244 elsif Is_Access_Type (Etype (Nam_Ent))
1246 (not Is_Entity_Name (Nam)
1247 or else Nkind (N) = N_Procedure_Call_Statement)
1248 and then Ekind (Designated_Type (Etype (Nam_Ent)))
1251 Nam_Ent := Designated_Type (Etype (Nam_Ent));
1253 if Is_Entity_Name (Nam) then
1258 -- If the call has been rewritten from a prefixed call, the first
1259 -- parameter has been analyzed, but may need a subsequent
1260 -- dereference, so skip its analysis now.
1262 if N /= Original_Node (N)
1263 and then Nkind (Original_Node (N)) = Nkind (N)
1264 and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N)))
1265 and then Present (Parameter_Associations (N))
1266 and then Present (Etype (First (Parameter_Associations (N))))
1269 (N, Nam_Ent, False, Success, Skip_First => True);
1271 Analyze_One_Call (N, Nam_Ent, False, Success);
1274 -- If the interpretation succeeds, mark the proper type of the
1275 -- prefix (any valid candidate will do). If not, remove the
1276 -- candidate interpretation. This only needs to be done for
1277 -- overloaded protected operations, for other entities disambi-
1278 -- guation is done directly in Resolve.
1282 and then Nkind (Parent (N)) /= N_Explicit_Dereference
1284 Set_Entity (Nam, It.Nam);
1285 Insert_Explicit_Dereference (Nam);
1286 Set_Etype (Nam, Nam_Ent);
1289 Set_Etype (Nam, It.Typ);
1292 elsif Nkind_In (Name (N), N_Selected_Component,
1298 Get_Next_Interp (X, It);
1301 -- If the name is the result of a function call, it can only be a
1302 -- call to a function returning an access to subprogram. Insert
1303 -- explicit dereference.
1305 if Nkind (Nam) = N_Function_Call then
1306 Insert_Explicit_Dereference (Nam);
1309 if Etype (N) = Any_Type then
1311 -- None of the interpretations is compatible with the actuals
1313 Diagnose_Call (N, Nam);
1315 -- Special checks for uninstantiated put routines
1317 if Nkind (N) = N_Procedure_Call_Statement
1318 and then Is_Entity_Name (Nam)
1319 and then Chars (Nam) = Name_Put
1320 and then List_Length (Actuals) = 1
1323 Arg : constant Node_Id := First (Actuals);
1327 if Nkind (Arg) = N_Parameter_Association then
1328 Typ := Etype (Explicit_Actual_Parameter (Arg));
1333 if Is_Signed_Integer_Type (Typ) then
1335 ("possible missing instantiation of "
1336 & "'Text_'I'O.'Integer_'I'O!", Nam);
1338 elsif Is_Modular_Integer_Type (Typ) then
1340 ("possible missing instantiation of "
1341 & "'Text_'I'O.'Modular_'I'O!", Nam);
1343 elsif Is_Floating_Point_Type (Typ) then
1345 ("possible missing instantiation of "
1346 & "'Text_'I'O.'Float_'I'O!", Nam);
1348 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
1350 ("possible missing instantiation of "
1351 & "'Text_'I'O.'Fixed_'I'O!", Nam);
1353 elsif Is_Decimal_Fixed_Point_Type (Typ) then
1355 ("possible missing instantiation of "
1356 & "'Text_'I'O.'Decimal_'I'O!", Nam);
1358 elsif Is_Enumeration_Type (Typ) then
1360 ("possible missing instantiation of "
1361 & "'Text_'I'O.'Enumeration_'I'O!", Nam);
1366 elsif not Is_Overloaded (N)
1367 and then Is_Entity_Name (Nam)
1369 -- Resolution yields a single interpretation. Verify that the
1370 -- reference has capitalization consistent with the declaration.
1372 Set_Entity_With_Checks (Nam, Entity (Nam));
1373 Generate_Reference (Entity (Nam), Nam);
1375 Set_Etype (Nam, Etype (Entity (Nam)));
1377 Remove_Abstract_Operations (N);
1383 if Ada_Version >= Ada_2012 then
1385 -- Check if the call contains a function with writable actuals
1387 Check_Writable_Actuals (N);
1389 -- If found and the outermost construct that can be evaluated in
1390 -- an arbitrary order is precisely this call, then check all its
1393 Check_Function_Writable_Actuals (N);
1397 -----------------------------
1398 -- Analyze_Case_Expression --
1399 -----------------------------
1401 procedure Analyze_Case_Expression (N : Node_Id) is
1402 procedure Non_Static_Choice_Error (Choice : Node_Id);
1403 -- Error routine invoked by the generic instantiation below when
1404 -- the case expression has a non static choice.
1406 package Case_Choices_Analysis is new
1407 Generic_Analyze_Choices
1408 (Process_Associated_Node => No_OP);
1409 use Case_Choices_Analysis;
1411 package Case_Choices_Checking is new
1412 Generic_Check_Choices
1413 (Process_Empty_Choice => No_OP,
1414 Process_Non_Static_Choice => Non_Static_Choice_Error,
1415 Process_Associated_Node => No_OP);
1416 use Case_Choices_Checking;
1418 -----------------------------
1419 -- Non_Static_Choice_Error --
1420 -----------------------------
1422 procedure Non_Static_Choice_Error (Choice : Node_Id) is
1424 Flag_Non_Static_Expr
1425 ("choice given in case expression is not static!", Choice);
1426 end Non_Static_Choice_Error;
1430 Expr : constant Node_Id := Expression (N);
1432 Exp_Type : Entity_Id;
1433 Exp_Btype : Entity_Id;
1435 FirstX : Node_Id := Empty;
1436 -- First expression in the case for which there is some type information
1437 -- available, i.e. it is not Any_Type, which can happen because of some
1438 -- error, or from the use of e.g. raise Constraint_Error.
1440 Others_Present : Boolean;
1441 -- Indicates if Others was present
1443 Wrong_Alt : Node_Id;
1444 -- For error reporting
1446 -- Start of processing for Analyze_Case_Expression
1449 if Comes_From_Source (N) then
1450 Check_Compiler_Unit ("case expression", N);
1453 Analyze_And_Resolve (Expr, Any_Discrete);
1454 Check_Unset_Reference (Expr);
1455 Exp_Type := Etype (Expr);
1456 Exp_Btype := Base_Type (Exp_Type);
1458 Alt := First (Alternatives (N));
1459 while Present (Alt) loop
1460 Analyze (Expression (Alt));
1462 if No (FirstX) and then Etype (Expression (Alt)) /= Any_Type then
1463 FirstX := Expression (Alt);
1469 -- Get our initial type from the first expression for which we got some
1470 -- useful type information from the expression.
1472 if not Is_Overloaded (FirstX) then
1473 Set_Etype (N, Etype (FirstX));
1481 Set_Etype (N, Any_Type);
1483 Get_First_Interp (FirstX, I, It);
1484 while Present (It.Nam) loop
1486 -- For each interpretation of the first expression, we only
1487 -- add the interpretation if every other expression in the
1488 -- case expression alternatives has a compatible type.
1490 Alt := Next (First (Alternatives (N)));
1491 while Present (Alt) loop
1492 exit when not Has_Compatible_Type (Expression (Alt), It.Typ);
1497 Add_One_Interp (N, It.Typ, It.Typ);
1502 Get_Next_Interp (I, It);
1507 Exp_Btype := Base_Type (Exp_Type);
1509 -- The expression must be of a discrete type which must be determinable
1510 -- independently of the context in which the expression occurs, but
1511 -- using the fact that the expression must be of a discrete type.
1512 -- Moreover, the type this expression must not be a character literal
1513 -- (which is always ambiguous).
1515 -- If error already reported by Resolve, nothing more to do
1517 if Exp_Btype = Any_Discrete or else Exp_Btype = Any_Type then
1520 -- Special casee message for character literal
1522 elsif Exp_Btype = Any_Character then
1524 ("character literal as case expression is ambiguous", Expr);
1528 if Etype (N) = Any_Type and then Present (Wrong_Alt) then
1530 ("type incompatible with that of previous alternatives",
1531 Expression (Wrong_Alt));
1535 -- If the case expression is a formal object of mode in out, then
1536 -- treat it as having a nonstatic subtype by forcing use of the base
1537 -- type (which has to get passed to Check_Case_Choices below). Also
1538 -- use base type when the case expression is parenthesized.
1540 if Paren_Count (Expr) > 0
1541 or else (Is_Entity_Name (Expr)
1542 and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter)
1544 Exp_Type := Exp_Btype;
1547 -- The case expression alternatives cover the range of a static subtype
1548 -- subject to aspect Static_Predicate. Do not check the choices when the
1549 -- case expression has not been fully analyzed yet because this may lead
1552 if Is_OK_Static_Subtype (Exp_Type)
1553 and then Has_Static_Predicate_Aspect (Exp_Type)
1554 and then In_Spec_Expression
1558 -- Call Analyze_Choices and Check_Choices to do the rest of the work
1561 Analyze_Choices (Alternatives (N), Exp_Type);
1562 Check_Choices (N, Alternatives (N), Exp_Type, Others_Present);
1565 if Exp_Type = Universal_Integer and then not Others_Present then
1567 ("case on universal integer requires OTHERS choice", Expr);
1569 end Analyze_Case_Expression;
1571 ---------------------------
1572 -- Analyze_Comparison_Op --
1573 ---------------------------
1575 procedure Analyze_Comparison_Op (N : Node_Id) is
1576 L : constant Node_Id := Left_Opnd (N);
1577 R : constant Node_Id := Right_Opnd (N);
1578 Op_Id : Entity_Id := Entity (N);
1581 Set_Etype (N, Any_Type);
1582 Candidate_Type := Empty;
1584 Analyze_Expression (L);
1585 Analyze_Expression (R);
1587 if Present (Op_Id) then
1588 if Ekind (Op_Id) = E_Operator then
1589 Find_Comparison_Types (L, R, Op_Id, N);
1591 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1594 if Is_Overloaded (L) then
1595 Set_Etype (L, Intersect_Types (L, R));
1599 Op_Id := Get_Name_Entity_Id (Chars (N));
1600 while Present (Op_Id) loop
1601 if Ekind (Op_Id) = E_Operator then
1602 Find_Comparison_Types (L, R, Op_Id, N);
1604 Analyze_User_Defined_Binary_Op (N, Op_Id);
1607 Op_Id := Homonym (Op_Id);
1612 Check_Function_Writable_Actuals (N);
1613 end Analyze_Comparison_Op;
1615 ---------------------------
1616 -- Analyze_Concatenation --
1617 ---------------------------
1619 procedure Analyze_Concatenation (N : Node_Id) is
1621 -- We wish to avoid deep recursion, because concatenations are often
1622 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1623 -- operands nonrecursively until we find something that is not a
1624 -- concatenation (A in this case), or has already been analyzed. We
1625 -- analyze that, and then walk back up the tree following Parent
1626 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1627 -- work at each level. The Parent pointers allow us to avoid recursion,
1628 -- and thus avoid running out of memory.
1634 Candidate_Type := Empty;
1636 -- The following code is equivalent to:
1638 -- Set_Etype (N, Any_Type);
1639 -- Analyze_Expression (Left_Opnd (N));
1640 -- Analyze_Concatenation_Rest (N);
1642 -- where the Analyze_Expression call recurses back here if the left
1643 -- operand is a concatenation.
1645 -- Walk down left operands
1648 Set_Etype (NN, Any_Type);
1649 L := Left_Opnd (NN);
1650 exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
1654 -- Now (given the above example) NN is A&B and L is A
1656 -- First analyze L ...
1658 Analyze_Expression (L);
1660 -- ... then walk NN back up until we reach N (where we started), calling
1661 -- Analyze_Concatenation_Rest along the way.
1664 Analyze_Concatenation_Rest (NN);
1668 end Analyze_Concatenation;
1670 --------------------------------
1671 -- Analyze_Concatenation_Rest --
1672 --------------------------------
1674 -- If the only one-dimensional array type in scope is String,
1675 -- this is the resulting type of the operation. Otherwise there
1676 -- will be a concatenation operation defined for each user-defined
1677 -- one-dimensional array.
1679 procedure Analyze_Concatenation_Rest (N : Node_Id) is
1680 L : constant Node_Id := Left_Opnd (N);
1681 R : constant Node_Id := Right_Opnd (N);
1682 Op_Id : Entity_Id := Entity (N);
1687 Analyze_Expression (R);
1689 -- If the entity is present, the node appears in an instance, and
1690 -- denotes a predefined concatenation operation. The resulting type is
1691 -- obtained from the arguments when possible. If the arguments are
1692 -- aggregates, the array type and the concatenation type must be
1695 if Present (Op_Id) then
1696 if Ekind (Op_Id) = E_Operator then
1697 LT := Base_Type (Etype (L));
1698 RT := Base_Type (Etype (R));
1700 if Is_Array_Type (LT)
1701 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1703 Add_One_Interp (N, Op_Id, LT);
1705 elsif Is_Array_Type (RT)
1706 and then LT = Base_Type (Component_Type (RT))
1708 Add_One_Interp (N, Op_Id, RT);
1710 -- If one operand is a string type or a user-defined array type,
1711 -- and the other is a literal, result is of the specific type.
1714 (Root_Type (LT) = Standard_String
1715 or else Scope (LT) /= Standard_Standard)
1716 and then Etype (R) = Any_String
1718 Add_One_Interp (N, Op_Id, LT);
1721 (Root_Type (RT) = Standard_String
1722 or else Scope (RT) /= Standard_Standard)
1723 and then Etype (L) = Any_String
1725 Add_One_Interp (N, Op_Id, RT);
1727 elsif not Is_Generic_Type (Etype (Op_Id)) then
1728 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1731 -- Type and its operations must be visible
1733 Set_Entity (N, Empty);
1734 Analyze_Concatenation (N);
1738 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1742 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1743 while Present (Op_Id) loop
1744 if Ekind (Op_Id) = E_Operator then
1746 -- Do not consider operators declared in dead code, they can
1747 -- not be part of the resolution.
1749 if Is_Eliminated (Op_Id) then
1752 Find_Concatenation_Types (L, R, Op_Id, N);
1756 Analyze_User_Defined_Binary_Op (N, Op_Id);
1759 Op_Id := Homonym (Op_Id);
1764 end Analyze_Concatenation_Rest;
1766 -------------------------
1767 -- Analyze_Equality_Op --
1768 -------------------------
1770 procedure Analyze_Equality_Op (N : Node_Id) is
1771 Loc : constant Source_Ptr := Sloc (N);
1772 L : constant Node_Id := Left_Opnd (N);
1773 R : constant Node_Id := Right_Opnd (N);
1777 Set_Etype (N, Any_Type);
1778 Candidate_Type := Empty;
1780 Analyze_Expression (L);
1781 Analyze_Expression (R);
1783 -- If the entity is set, the node is a generic instance with a non-local
1784 -- reference to the predefined operator or to a user-defined function.
1785 -- It can also be an inequality that is expanded into the negation of a
1786 -- call to a user-defined equality operator.
1788 -- For the predefined case, the result is Boolean, regardless of the
1789 -- type of the operands. The operands may even be limited, if they are
1790 -- generic actuals. If they are overloaded, label the left argument with
1791 -- the common type that must be present, or with the type of the formal
1792 -- of the user-defined function.
1794 if Present (Entity (N)) then
1795 Op_Id := Entity (N);
1797 if Ekind (Op_Id) = E_Operator then
1798 Add_One_Interp (N, Op_Id, Standard_Boolean);
1800 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1803 if Is_Overloaded (L) then
1804 if Ekind (Op_Id) = E_Operator then
1805 Set_Etype (L, Intersect_Types (L, R));
1807 Set_Etype (L, Etype (First_Formal (Op_Id)));
1812 Op_Id := Get_Name_Entity_Id (Chars (N));
1813 while Present (Op_Id) loop
1814 if Ekind (Op_Id) = E_Operator then
1815 Find_Equality_Types (L, R, Op_Id, N);
1817 Analyze_User_Defined_Binary_Op (N, Op_Id);
1820 Op_Id := Homonym (Op_Id);
1824 -- If there was no match, and the operator is inequality, this may be
1825 -- a case where inequality has not been made explicit, as for tagged
1826 -- types. Analyze the node as the negation of an equality operation.
1827 -- This cannot be done earlier, because before analysis we cannot rule
1828 -- out the presence of an explicit inequality.
1830 if Etype (N) = Any_Type
1831 and then Nkind (N) = N_Op_Ne
1833 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1834 while Present (Op_Id) loop
1835 if Ekind (Op_Id) = E_Operator then
1836 Find_Equality_Types (L, R, Op_Id, N);
1838 Analyze_User_Defined_Binary_Op (N, Op_Id);
1841 Op_Id := Homonym (Op_Id);
1844 if Etype (N) /= Any_Type then
1845 Op_Id := Entity (N);
1851 Left_Opnd => Left_Opnd (N),
1852 Right_Opnd => Right_Opnd (N))));
1854 Set_Entity (Right_Opnd (N), Op_Id);
1860 Check_Function_Writable_Actuals (N);
1861 end Analyze_Equality_Op;
1863 ----------------------------------
1864 -- Analyze_Explicit_Dereference --
1865 ----------------------------------
1867 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1868 Loc : constant Source_Ptr := Sloc (N);
1869 P : constant Node_Id := Prefix (N);
1875 function Is_Function_Type return Boolean;
1876 -- Check whether node may be interpreted as an implicit function call
1878 ----------------------
1879 -- Is_Function_Type --
1880 ----------------------
1882 function Is_Function_Type return Boolean is
1887 if not Is_Overloaded (N) then
1888 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1889 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1892 Get_First_Interp (N, I, It);
1893 while Present (It.Nam) loop
1894 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1895 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1900 Get_Next_Interp (I, It);
1905 end Is_Function_Type;
1907 -- Start of processing for Analyze_Explicit_Dereference
1910 -- If source node, check SPARK restriction. We guard this with the
1911 -- source node check, because ???
1913 if Comes_From_Source (N) then
1914 Check_SPARK_05_Restriction ("explicit dereference is not allowed", N);
1917 -- In formal verification mode, keep track of all reads and writes
1918 -- through explicit dereferences.
1920 if GNATprove_Mode then
1921 SPARK_Specific.Generate_Dereference (N);
1925 Set_Etype (N, Any_Type);
1927 -- Test for remote access to subprogram type, and if so return
1928 -- after rewriting the original tree.
1930 if Remote_AST_E_Dereference (P) then
1934 -- Normal processing for other than remote access to subprogram type
1936 if not Is_Overloaded (P) then
1937 if Is_Access_Type (Etype (P)) then
1939 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
1940 -- avoid other problems caused by the Private_Subtype and it is
1941 -- safe to go to the Base_Type because this is the same as
1942 -- converting the access value to its Base_Type.
1945 DT : Entity_Id := Designated_Type (Etype (P));
1948 if Ekind (DT) = E_Private_Subtype
1949 and then Is_For_Access_Subtype (DT)
1951 DT := Base_Type (DT);
1954 -- An explicit dereference is a legal occurrence of an
1955 -- incomplete type imported through a limited_with clause, if
1956 -- the full view is visible, or if we are within an instance
1957 -- body, where the enclosing body has a regular with_clause
1960 if From_Limited_With (DT)
1961 and then not From_Limited_With (Scope (DT))
1963 (Is_Immediately_Visible (Scope (DT))
1965 (Is_Child_Unit (Scope (DT))
1966 and then Is_Visible_Lib_Unit (Scope (DT)))
1967 or else In_Instance_Body)
1969 Set_Etype (N, Available_View (DT));
1976 elsif Etype (P) /= Any_Type then
1977 Error_Msg_N ("prefix of dereference must be an access type", N);
1982 Get_First_Interp (P, I, It);
1983 while Present (It.Nam) loop
1986 if Is_Access_Type (T) then
1987 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1990 Get_Next_Interp (I, It);
1993 -- Error if no interpretation of the prefix has an access type
1995 if Etype (N) = Any_Type then
1997 ("access type required in prefix of explicit dereference", P);
1998 Set_Etype (N, Any_Type);
2004 and then Nkind (Parent (N)) /= N_Indexed_Component
2006 and then (Nkind (Parent (N)) /= N_Function_Call
2007 or else N /= Name (Parent (N)))
2009 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
2010 or else N /= Name (Parent (N)))
2012 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
2013 and then (Nkind (Parent (N)) /= N_Attribute_Reference
2015 (Attribute_Name (Parent (N)) /= Name_Address
2017 Attribute_Name (Parent (N)) /= Name_Access))
2019 -- Name is a function call with no actuals, in a context that
2020 -- requires deproceduring (including as an actual in an enclosing
2021 -- function or procedure call). There are some pathological cases
2022 -- where the prefix might include functions that return access to
2023 -- subprograms and others that return a regular type. Disambiguation
2024 -- of those has to take place in Resolve.
2027 Make_Function_Call (Loc,
2028 Name => Make_Explicit_Dereference (Loc, P),
2029 Parameter_Associations => New_List);
2031 -- If the prefix is overloaded, remove operations that have formals,
2032 -- we know that this is a parameterless call.
2034 if Is_Overloaded (P) then
2035 Get_First_Interp (P, I, It);
2036 while Present (It.Nam) loop
2039 if No (First_Formal (Base_Type (Designated_Type (T)))) then
2045 Get_Next_Interp (I, It);
2052 elsif not Is_Function_Type
2053 and then Is_Overloaded (N)
2055 -- The prefix may include access to subprograms and other access
2056 -- types. If the context selects the interpretation that is a
2057 -- function call (not a procedure call) we cannot rewrite the node
2058 -- yet, but we include the result of the call interpretation.
2060 Get_First_Interp (N, I, It);
2061 while Present (It.Nam) loop
2062 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
2063 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
2064 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
2066 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
2069 Get_Next_Interp (I, It);
2073 -- A value of remote access-to-class-wide must not be dereferenced
2076 Validate_Remote_Access_To_Class_Wide_Type (N);
2077 end Analyze_Explicit_Dereference;
2079 ------------------------
2080 -- Analyze_Expression --
2081 ------------------------
2083 procedure Analyze_Expression (N : Node_Id) is
2086 -- If the expression is an indexed component that will be rewritten
2087 -- as a container indexing, it has already been analyzed.
2089 if Nkind (N) = N_Indexed_Component
2090 and then Present (Generalized_Indexing (N))
2096 Check_Parameterless_Call (N);
2098 end Analyze_Expression;
2100 -------------------------------------
2101 -- Analyze_Expression_With_Actions --
2102 -------------------------------------
2104 procedure Analyze_Expression_With_Actions (N : Node_Id) is
2108 A := First (Actions (N));
2109 while Present (A) loop
2114 Analyze_Expression (Expression (N));
2115 Set_Etype (N, Etype (Expression (N)));
2116 end Analyze_Expression_With_Actions;
2118 ---------------------------
2119 -- Analyze_If_Expression --
2120 ---------------------------
2122 procedure Analyze_If_Expression (N : Node_Id) is
2123 Condition : constant Node_Id := First (Expressions (N));
2124 Then_Expr : constant Node_Id := Next (Condition);
2125 Else_Expr : Node_Id;
2128 -- Defend against error of missing expressions from previous error
2130 if No (Then_Expr) then
2131 Check_Error_Detected;
2135 if Comes_From_Source (N) then
2136 Check_SPARK_05_Restriction ("if expression is not allowed", N);
2139 Else_Expr := Next (Then_Expr);
2141 if Comes_From_Source (N) then
2142 Check_Compiler_Unit ("if expression", N);
2145 -- Analyze and resolve the condition. We need to resolve this now so
2146 -- that it gets folded to True/False if possible, before we analyze
2147 -- the THEN/ELSE branches, because when analyzing these branches, we
2148 -- may call Is_Statically_Unevaluated, which expects the condition of
2149 -- an enclosing IF to have been analyze/resolved/evaluated.
2151 Analyze_Expression (Condition);
2152 Resolve (Condition, Any_Boolean);
2154 -- Analyze THEN expression and (if present) ELSE expression. For those
2155 -- we delay resolution in the normal manner, because of overloading etc.
2157 Analyze_Expression (Then_Expr);
2159 if Present (Else_Expr) then
2160 Analyze_Expression (Else_Expr);
2163 -- If then expression not overloaded, then that decides the type
2165 if not Is_Overloaded (Then_Expr) then
2166 Set_Etype (N, Etype (Then_Expr));
2168 -- Case where then expression is overloaded
2176 Set_Etype (N, Any_Type);
2178 -- Loop through interpretations of Then_Expr
2180 Get_First_Interp (Then_Expr, I, It);
2181 while Present (It.Nam) loop
2183 -- Add possible interpretation of Then_Expr if no Else_Expr, or
2184 -- Else_Expr is present and has a compatible type.
2187 or else Has_Compatible_Type (Else_Expr, It.Typ)
2189 Add_One_Interp (N, It.Typ, It.Typ);
2192 Get_Next_Interp (I, It);
2195 -- If no valid interpretation has been found, then the type of the
2196 -- ELSE expression does not match any interpretation of the THEN
2199 if Etype (N) = Any_Type then
2201 ("type incompatible with that of `THEN` expression",
2207 end Analyze_If_Expression;
2209 ------------------------------------
2210 -- Analyze_Indexed_Component_Form --
2211 ------------------------------------
2213 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
2214 P : constant Node_Id := Prefix (N);
2215 Exprs : constant List_Id := Expressions (N);
2221 procedure Process_Function_Call;
2222 -- Prefix in indexed component form is an overloadable entity, so the
2223 -- node is a function call. Reformat it as such.
2225 procedure Process_Indexed_Component;
2226 -- Prefix in indexed component form is actually an indexed component.
2227 -- This routine processes it, knowing that the prefix is already
2230 procedure Process_Indexed_Component_Or_Slice;
2231 -- An indexed component with a single index may designate a slice if
2232 -- the index is a subtype mark. This routine disambiguates these two
2233 -- cases by resolving the prefix to see if it is a subtype mark.
2235 procedure Process_Overloaded_Indexed_Component;
2236 -- If the prefix of an indexed component is overloaded, the proper
2237 -- interpretation is selected by the index types and the context.
2239 ---------------------------
2240 -- Process_Function_Call --
2241 ---------------------------
2243 procedure Process_Function_Call is
2244 Loc : constant Source_Ptr := Sloc (N);
2248 Change_Node (N, N_Function_Call);
2250 Set_Parameter_Associations (N, Exprs);
2252 -- Analyze actuals prior to analyzing the call itself
2254 Actual := First (Parameter_Associations (N));
2255 while Present (Actual) loop
2257 Check_Parameterless_Call (Actual);
2259 -- Move to next actual. Note that we use Next, not Next_Actual
2260 -- here. The reason for this is a bit subtle. If a function call
2261 -- includes named associations, the parser recognizes the node
2262 -- as a call, and it is analyzed as such. If all associations are
2263 -- positional, the parser builds an indexed_component node, and
2264 -- it is only after analysis of the prefix that the construct
2265 -- is recognized as a call, in which case Process_Function_Call
2266 -- rewrites the node and analyzes the actuals. If the list of
2267 -- actuals is malformed, the parser may leave the node as an
2268 -- indexed component (despite the presence of named associations).
2269 -- The iterator Next_Actual is equivalent to Next if the list is
2270 -- positional, but follows the normalized chain of actuals when
2271 -- named associations are present. In this case normalization has
2272 -- not taken place, and actuals remain unanalyzed, which leads to
2273 -- subsequent crashes or loops if there is an attempt to continue
2274 -- analysis of the program.
2276 -- IF there is a single actual and it is a type name, the node
2277 -- can only be interpreted as a slice of a parameterless call.
2278 -- Rebuild the node as such and analyze.
2280 if No (Next (Actual))
2281 and then Is_Entity_Name (Actual)
2282 and then Is_Type (Entity (Actual))
2283 and then Is_Discrete_Type (Entity (Actual))
2289 New_Occurrence_Of (Entity (Actual), Loc)));
2299 end Process_Function_Call;
2301 -------------------------------
2302 -- Process_Indexed_Component --
2303 -------------------------------
2305 procedure Process_Indexed_Component is
2307 Array_Type : Entity_Id;
2309 Pent : Entity_Id := Empty;
2312 Exp := First (Exprs);
2314 if Is_Overloaded (P) then
2315 Process_Overloaded_Indexed_Component;
2318 Array_Type := Etype (P);
2320 if Is_Entity_Name (P) then
2322 elsif Nkind (P) = N_Selected_Component
2323 and then Is_Entity_Name (Selector_Name (P))
2325 Pent := Entity (Selector_Name (P));
2328 -- Prefix must be appropriate for an array type, taking into
2329 -- account a possible implicit dereference.
2331 if Is_Access_Type (Array_Type) then
2333 (Warn_On_Dereference, "?d?implicit dereference", N);
2334 Array_Type := Process_Implicit_Dereference_Prefix (Pent, P);
2337 if Is_Array_Type (Array_Type) then
2340 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
2342 Set_Etype (N, Any_Type);
2344 if not Has_Compatible_Type
2345 (Exp, Entry_Index_Type (Pent))
2347 Error_Msg_N ("invalid index type in entry name", N);
2349 elsif Present (Next (Exp)) then
2350 Error_Msg_N ("too many subscripts in entry reference", N);
2353 Set_Etype (N, Etype (P));
2358 elsif Is_Record_Type (Array_Type)
2359 and then Remote_AST_I_Dereference (P)
2363 elsif Try_Container_Indexing (N, P, Exprs) then
2366 elsif Array_Type = Any_Type then
2367 Set_Etype (N, Any_Type);
2369 -- In most cases the analysis of the prefix will have emitted
2370 -- an error already, but if the prefix may be interpreted as a
2371 -- call in prefixed notation, the report is left to the caller.
2372 -- To prevent cascaded errors, report only if no previous ones.
2374 if Serious_Errors_Detected = 0 then
2375 Error_Msg_N ("invalid prefix in indexed component", P);
2377 if Nkind (P) = N_Expanded_Name then
2378 Error_Msg_NE ("\& is not visible", P, Selector_Name (P));
2384 -- Here we definitely have a bad indexing
2387 if Nkind (Parent (N)) = N_Requeue_Statement
2388 and then Present (Pent) and then Ekind (Pent) = E_Entry
2391 ("REQUEUE does not permit parameters", First (Exprs));
2393 elsif Is_Entity_Name (P)
2394 and then Etype (P) = Standard_Void_Type
2396 Error_Msg_NE ("incorrect use of &", P, Entity (P));
2399 Error_Msg_N ("array type required in indexed component", P);
2402 Set_Etype (N, Any_Type);
2406 Index := First_Index (Array_Type);
2407 while Present (Index) and then Present (Exp) loop
2408 if not Has_Compatible_Type (Exp, Etype (Index)) then
2409 Wrong_Type (Exp, Etype (Index));
2410 Set_Etype (N, Any_Type);
2418 Set_Etype (N, Component_Type (Array_Type));
2419 Check_Implicit_Dereference (N, Etype (N));
2421 if Present (Index) then
2423 ("too few subscripts in array reference", First (Exprs));
2425 elsif Present (Exp) then
2426 Error_Msg_N ("too many subscripts in array reference", Exp);
2429 end Process_Indexed_Component;
2431 ----------------------------------------
2432 -- Process_Indexed_Component_Or_Slice --
2433 ----------------------------------------
2435 procedure Process_Indexed_Component_Or_Slice is
2437 Exp := First (Exprs);
2438 while Present (Exp) loop
2439 Analyze_Expression (Exp);
2443 Exp := First (Exprs);
2445 -- If one index is present, and it is a subtype name, then the node
2446 -- denotes a slice (note that the case of an explicit range for a
2447 -- slice was already built as an N_Slice node in the first place,
2448 -- so that case is not handled here).
2450 -- We use a replace rather than a rewrite here because this is one
2451 -- of the cases in which the tree built by the parser is plain wrong.
2454 and then Is_Entity_Name (Exp)
2455 and then Is_Type (Entity (Exp))
2458 Make_Slice (Sloc (N),
2460 Discrete_Range => New_Copy (Exp)));
2463 -- Otherwise (more than one index present, or single index is not
2464 -- a subtype name), then we have the indexed component case.
2467 Process_Indexed_Component;
2469 end Process_Indexed_Component_Or_Slice;
2471 ------------------------------------------
2472 -- Process_Overloaded_Indexed_Component --
2473 ------------------------------------------
2475 procedure Process_Overloaded_Indexed_Component is
2484 Set_Etype (N, Any_Type);
2486 Get_First_Interp (P, I, It);
2487 while Present (It.Nam) loop
2490 if Is_Access_Type (Typ) then
2491 Typ := Designated_Type (Typ);
2493 (Warn_On_Dereference, "?d?implicit dereference", N);
2496 if Is_Array_Type (Typ) then
2498 -- Got a candidate: verify that index types are compatible
2500 Index := First_Index (Typ);
2502 Exp := First (Exprs);
2503 while Present (Index) and then Present (Exp) loop
2504 if Has_Compatible_Type (Exp, Etype (Index)) then
2516 if Found and then No (Index) and then No (Exp) then
2518 CT : constant Entity_Id :=
2519 Base_Type (Component_Type (Typ));
2521 Add_One_Interp (N, CT, CT);
2522 Check_Implicit_Dereference (N, CT);
2526 elsif Try_Container_Indexing (N, P, Exprs) then
2531 Get_Next_Interp (I, It);
2534 if Etype (N) = Any_Type then
2535 Error_Msg_N ("no legal interpretation for indexed component", N);
2536 Set_Is_Overloaded (N, False);
2540 end Process_Overloaded_Indexed_Component;
2542 -- Start of processing for Analyze_Indexed_Component_Form
2545 -- Get name of array, function or type
2549 -- If P is an explicit dereference whose prefix is of a remote access-
2550 -- to-subprogram type, then N has already been rewritten as a subprogram
2551 -- call and analyzed.
2553 if Nkind (N) in N_Subprogram_Call then
2556 -- When the prefix is attribute 'Loop_Entry and the sole expression of
2557 -- the indexed component denotes a loop name, the indexed form is turned
2558 -- into an attribute reference.
2560 elsif Nkind (N) = N_Attribute_Reference
2561 and then Attribute_Name (N) = Name_Loop_Entry
2566 pragma Assert (Nkind (N) = N_Indexed_Component);
2568 P_T := Base_Type (Etype (P));
2570 if Is_Entity_Name (P) and then Present (Entity (P)) then
2573 if Is_Type (U_N) then
2575 -- Reformat node as a type conversion
2577 E := Remove_Head (Exprs);
2579 if Present (First (Exprs)) then
2581 ("argument of type conversion must be single expression", N);
2584 Change_Node (N, N_Type_Conversion);
2585 Set_Subtype_Mark (N, P);
2587 Set_Expression (N, E);
2589 -- After changing the node, call for the specific Analysis
2590 -- routine directly, to avoid a double call to the expander.
2592 Analyze_Type_Conversion (N);
2596 if Is_Overloadable (U_N) then
2597 Process_Function_Call;
2599 elsif Ekind (Etype (P)) = E_Subprogram_Type
2600 or else (Is_Access_Type (Etype (P))
2602 Ekind (Designated_Type (Etype (P))) =
2605 -- Call to access_to-subprogram with possible implicit dereference
2607 Process_Function_Call;
2609 elsif Is_Generic_Subprogram (U_N) then
2611 -- A common beginner's (or C++ templates fan) error
2613 Error_Msg_N ("generic subprogram cannot be called", N);
2614 Set_Etype (N, Any_Type);
2618 Process_Indexed_Component_Or_Slice;
2621 -- If not an entity name, prefix is an expression that may denote
2622 -- an array or an access-to-subprogram.
2625 if Ekind (P_T) = E_Subprogram_Type
2626 or else (Is_Access_Type (P_T)
2628 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
2630 Process_Function_Call;
2632 elsif Nkind (P) = N_Selected_Component
2633 and then Present (Entity (Selector_Name (P)))
2634 and then Is_Overloadable (Entity (Selector_Name (P)))
2636 Process_Function_Call;
2638 -- In ASIS mode within a generic, a prefixed call is analyzed and
2639 -- partially rewritten but the original indexed component has not
2640 -- yet been rewritten as a call. Perform the replacement now.
2642 elsif Nkind (P) = N_Selected_Component
2643 and then Nkind (Parent (P)) = N_Function_Call
2646 Rewrite (N, Parent (P));
2650 -- Indexed component, slice, or a call to a member of a family
2651 -- entry, which will be converted to an entry call later.
2653 Process_Indexed_Component_Or_Slice;
2657 Analyze_Dimension (N);
2658 end Analyze_Indexed_Component_Form;
2660 ------------------------
2661 -- Analyze_Logical_Op --
2662 ------------------------
2664 procedure Analyze_Logical_Op (N : Node_Id) is
2665 L : constant Node_Id := Left_Opnd (N);
2666 R : constant Node_Id := Right_Opnd (N);
2667 Op_Id : Entity_Id := Entity (N);
2670 Set_Etype (N, Any_Type);
2671 Candidate_Type := Empty;
2673 Analyze_Expression (L);
2674 Analyze_Expression (R);
2676 if Present (Op_Id) then
2678 if Ekind (Op_Id) = E_Operator then
2679 Find_Boolean_Types (L, R, Op_Id, N);
2681 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2685 Op_Id := Get_Name_Entity_Id (Chars (N));
2686 while Present (Op_Id) loop
2687 if Ekind (Op_Id) = E_Operator then
2688 Find_Boolean_Types (L, R, Op_Id, N);
2690 Analyze_User_Defined_Binary_Op (N, Op_Id);
2693 Op_Id := Homonym (Op_Id);
2698 Check_Function_Writable_Actuals (N);
2699 end Analyze_Logical_Op;
2701 ---------------------------
2702 -- Analyze_Membership_Op --
2703 ---------------------------
2705 procedure Analyze_Membership_Op (N : Node_Id) is
2706 Loc : constant Source_Ptr := Sloc (N);
2707 L : constant Node_Id := Left_Opnd (N);
2708 R : constant Node_Id := Right_Opnd (N);
2710 Index : Interp_Index;
2712 Found : Boolean := False;
2716 procedure Try_One_Interp (T1 : Entity_Id);
2717 -- Routine to try one proposed interpretation. Note that the context
2718 -- of the operation plays no role in resolving the arguments, so that
2719 -- if there is more than one interpretation of the operands that is
2720 -- compatible with a membership test, the operation is ambiguous.
2722 --------------------
2723 -- Try_One_Interp --
2724 --------------------
2726 procedure Try_One_Interp (T1 : Entity_Id) is
2728 if Has_Compatible_Type (R, T1) then
2730 and then Base_Type (T1) /= Base_Type (T_F)
2732 It := Disambiguate (L, I_F, Index, Any_Type);
2734 if It = No_Interp then
2735 Ambiguous_Operands (N);
2736 Set_Etype (L, Any_Type);
2753 procedure Analyze_Set_Membership;
2754 -- If a set of alternatives is present, analyze each and find the
2755 -- common type to which they must all resolve.
2757 ----------------------------
2758 -- Analyze_Set_Membership --
2759 ----------------------------
2761 procedure Analyze_Set_Membership is
2763 Index : Interp_Index;
2765 Candidate_Interps : Node_Id;
2766 Common_Type : Entity_Id := Empty;
2769 if Comes_From_Source (N) then
2770 Check_Compiler_Unit ("set membership", N);
2774 Candidate_Interps := L;
2776 if not Is_Overloaded (L) then
2777 Common_Type := Etype (L);
2779 Alt := First (Alternatives (N));
2780 while Present (Alt) loop
2783 if not Has_Compatible_Type (Alt, Common_Type) then
2784 Wrong_Type (Alt, Common_Type);
2791 Alt := First (Alternatives (N));
2792 while Present (Alt) loop
2794 if not Is_Overloaded (Alt) then
2795 Common_Type := Etype (Alt);
2798 Get_First_Interp (Alt, Index, It);
2799 while Present (It.Typ) loop
2801 Has_Compatible_Type (Candidate_Interps, It.Typ)
2803 Remove_Interp (Index);
2806 Get_Next_Interp (Index, It);
2809 Get_First_Interp (Alt, Index, It);
2812 Error_Msg_N ("alternative has no legal type", Alt);
2816 -- If alternative is not overloaded, we have a unique type
2819 Set_Etype (Alt, It.Typ);
2820 Get_Next_Interp (Index, It);
2823 Set_Is_Overloaded (Alt, False);
2824 Common_Type := Etype (Alt);
2827 Candidate_Interps := Alt;
2834 Set_Etype (N, Standard_Boolean);
2836 if Present (Common_Type) then
2837 Set_Etype (L, Common_Type);
2839 -- The left operand may still be overloaded, to be resolved using
2843 Error_Msg_N ("cannot resolve membership operation", N);
2845 end Analyze_Set_Membership;
2847 -- Start of processing for Analyze_Membership_Op
2850 Analyze_Expression (L);
2852 if No (R) and then Ada_Version >= Ada_2012 then
2853 Analyze_Set_Membership;
2854 Check_Function_Writable_Actuals (N);
2859 if Nkind (R) = N_Range
2860 or else (Nkind (R) = N_Attribute_Reference
2861 and then Attribute_Name (R) = Name_Range)
2865 if not Is_Overloaded (L) then
2866 Try_One_Interp (Etype (L));
2869 Get_First_Interp (L, Index, It);
2870 while Present (It.Typ) loop
2871 Try_One_Interp (It.Typ);
2872 Get_Next_Interp (Index, It);
2876 -- If not a range, it can be a subtype mark, or else it is a degenerate
2877 -- membership test with a singleton value, i.e. a test for equality,
2878 -- if the types are compatible.
2883 if Is_Entity_Name (R)
2884 and then Is_Type (Entity (R))
2887 Check_Fully_Declared (Entity (R), R);
2889 elsif Ada_Version >= Ada_2012
2890 and then Has_Compatible_Type (R, Etype (L))
2892 if Nkind (N) = N_In then
2908 -- In all versions of the language, if we reach this point there
2909 -- is a previous error that will be diagnosed below.
2915 -- Compatibility between expression and subtype mark or range is
2916 -- checked during resolution. The result of the operation is Boolean
2919 Set_Etype (N, Standard_Boolean);
2921 if Comes_From_Source (N)
2922 and then Present (Right_Opnd (N))
2923 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
2925 Error_Msg_N ("membership test not applicable to cpp-class types", N);
2928 Check_Function_Writable_Actuals (N);
2929 end Analyze_Membership_Op;
2935 procedure Analyze_Mod (N : Node_Id) is
2937 -- A special warning check, if we have an expression of the form:
2938 -- expr mod 2 * literal
2939 -- where literal is 64 or less, then probably what was meant was
2940 -- expr mod 2 ** literal
2941 -- so issue an appropriate warning.
2943 if Warn_On_Suspicious_Modulus_Value
2944 and then Nkind (Right_Opnd (N)) = N_Integer_Literal
2945 and then Intval (Right_Opnd (N)) = Uint_2
2946 and then Nkind (Parent (N)) = N_Op_Multiply
2947 and then Nkind (Right_Opnd (Parent (N))) = N_Integer_Literal
2948 and then Intval (Right_Opnd (Parent (N))) <= Uint_64
2951 ("suspicious MOD value, was '*'* intended'??M?", Parent (N));
2954 -- Remaining processing is same as for other arithmetic operators
2956 Analyze_Arithmetic_Op (N);
2959 ----------------------
2960 -- Analyze_Negation --
2961 ----------------------
2963 procedure Analyze_Negation (N : Node_Id) is
2964 R : constant Node_Id := Right_Opnd (N);
2965 Op_Id : Entity_Id := Entity (N);
2968 Set_Etype (N, Any_Type);
2969 Candidate_Type := Empty;
2971 Analyze_Expression (R);
2973 if Present (Op_Id) then
2974 if Ekind (Op_Id) = E_Operator then
2975 Find_Negation_Types (R, Op_Id, N);
2977 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2981 Op_Id := Get_Name_Entity_Id (Chars (N));
2982 while Present (Op_Id) loop
2983 if Ekind (Op_Id) = E_Operator then
2984 Find_Negation_Types (R, Op_Id, N);
2986 Analyze_User_Defined_Unary_Op (N, Op_Id);
2989 Op_Id := Homonym (Op_Id);
2994 end Analyze_Negation;
3000 procedure Analyze_Null (N : Node_Id) is
3002 Check_SPARK_05_Restriction ("null is not allowed", N);
3004 Set_Etype (N, Any_Access);
3007 ----------------------
3008 -- Analyze_One_Call --
3009 ----------------------
3011 procedure Analyze_One_Call
3015 Success : out Boolean;
3016 Skip_First : Boolean := False)
3018 Actuals : constant List_Id := Parameter_Associations (N);
3019 Prev_T : constant Entity_Id := Etype (N);
3021 Must_Skip : constant Boolean := Skip_First
3022 or else Nkind (Original_Node (N)) = N_Selected_Component
3024 (Nkind (Original_Node (N)) = N_Indexed_Component
3025 and then Nkind (Prefix (Original_Node (N)))
3026 = N_Selected_Component);
3027 -- The first formal must be omitted from the match when trying to find
3028 -- a primitive operation that is a possible interpretation, and also
3029 -- after the call has been rewritten, because the corresponding actual
3030 -- is already known to be compatible, and because this may be an
3031 -- indexing of a call with default parameters.
3035 Is_Indexed : Boolean := False;
3036 Is_Indirect : Boolean := False;
3037 Subp_Type : constant Entity_Id := Etype (Nam);
3040 function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
3041 -- There may be a user-defined operator that hides the current
3042 -- interpretation. We must check for this independently of the
3043 -- analysis of the call with the user-defined operation, because
3044 -- the parameter names may be wrong and yet the hiding takes place.
3045 -- This fixes a problem with ACATS test B34014O.
3047 -- When the type Address is a visible integer type, and the DEC
3048 -- system extension is visible, the predefined operator may be
3049 -- hidden as well, by one of the address operations in auxdec.
3050 -- Finally, The abstract operations on address do not hide the
3051 -- predefined operator (this is the purpose of making them abstract).
3053 procedure Indicate_Name_And_Type;
3054 -- If candidate interpretation matches, indicate name and type of
3055 -- result on call node.
3057 ----------------------------
3058 -- Indicate_Name_And_Type --
3059 ----------------------------
3061 procedure Indicate_Name_And_Type is
3063 Add_One_Interp (N, Nam, Etype (Nam));
3064 Check_Implicit_Dereference (N, Etype (Nam));
3067 -- If the prefix of the call is a name, indicate the entity
3068 -- being called. If it is not a name, it is an expression that
3069 -- denotes an access to subprogram or else an entry or family. In
3070 -- the latter case, the name is a selected component, and the entity
3071 -- being called is noted on the selector.
3073 if not Is_Type (Nam) then
3074 if Is_Entity_Name (Name (N)) then
3075 Set_Entity (Name (N), Nam);
3076 Set_Etype (Name (N), Etype (Nam));
3078 elsif Nkind (Name (N)) = N_Selected_Component then
3079 Set_Entity (Selector_Name (Name (N)), Nam);
3083 if Debug_Flag_E and not Report then
3084 Write_Str (" Overloaded call ");
3085 Write_Int (Int (N));
3086 Write_Str (" compatible with ");
3087 Write_Int (Int (Nam));
3090 end Indicate_Name_And_Type;
3092 ------------------------
3093 -- Operator_Hidden_By --
3094 ------------------------
3096 function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
3097 Act1 : constant Node_Id := First_Actual (N);
3098 Act2 : constant Node_Id := Next_Actual (Act1);
3099 Form1 : constant Entity_Id := First_Formal (Fun);
3100 Form2 : constant Entity_Id := Next_Formal (Form1);
3103 if Ekind (Fun) /= E_Function or else Is_Abstract_Subprogram (Fun) then
3106 elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
3109 elsif Present (Form2) then
3111 or else not Has_Compatible_Type (Act2, Etype (Form2))
3116 elsif Present (Act2) then
3120 -- Now we know that the arity of the operator matches the function,
3121 -- and the function call is a valid interpretation. The function
3122 -- hides the operator if it has the right signature, or if one of
3123 -- its operands is a non-abstract operation on Address when this is
3124 -- a visible integer type.
3126 return Hides_Op (Fun, Nam)
3127 or else Is_Descendant_Of_Address (Etype (Form1))
3130 and then Is_Descendant_Of_Address (Etype (Form2)));
3131 end Operator_Hidden_By;
3133 -- Start of processing for Analyze_One_Call
3138 -- If the subprogram has no formals or if all the formals have defaults,
3139 -- and the return type is an array type, the node may denote an indexing
3140 -- of the result of a parameterless call. In Ada 2005, the subprogram
3141 -- may have one non-defaulted formal, and the call may have been written
3142 -- in prefix notation, so that the rebuilt parameter list has more than
3145 if not Is_Overloadable (Nam)
3146 and then Ekind (Nam) /= E_Subprogram_Type
3147 and then Ekind (Nam) /= E_Entry_Family
3152 -- An indexing requires at least one actual. The name of the call cannot
3153 -- be an implicit indirect call, so it cannot be a generated explicit
3156 if not Is_Empty_List (Actuals)
3158 (Needs_No_Actuals (Nam)
3160 (Needs_One_Actual (Nam)
3161 and then Present (Next_Actual (First (Actuals)))))
3163 if Is_Array_Type (Subp_Type)
3165 (Nkind (Name (N)) /= N_Explicit_Dereference
3166 or else Comes_From_Source (Name (N)))
3168 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
3170 elsif Is_Access_Type (Subp_Type)
3171 and then Is_Array_Type (Designated_Type (Subp_Type))
3175 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
3177 -- The prefix can also be a parameterless function that returns an
3178 -- access to subprogram, in which case this is an indirect call.
3179 -- If this succeeds, an explicit dereference is added later on,
3180 -- in Analyze_Call or Resolve_Call.
3182 elsif Is_Access_Type (Subp_Type)
3183 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
3185 Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
3190 -- If the call has been transformed into a slice, it is of the form
3191 -- F (Subtype) where F is parameterless. The node has been rewritten in
3192 -- Try_Indexed_Call and there is nothing else to do.
3195 and then Nkind (N) = N_Slice
3201 (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
3205 -- If an indirect call is a possible interpretation, indicate
3206 -- success to the caller. This may be an indexing of an explicit
3207 -- dereference of a call that returns an access type (see above).
3211 and then Nkind (Name (N)) = N_Explicit_Dereference
3212 and then Comes_From_Source (Name (N)))
3217 -- Mismatch in number or names of parameters
3219 elsif Debug_Flag_E then
3220 Write_Str (" normalization fails in call ");
3221 Write_Int (Int (N));
3222 Write_Str (" with subprogram ");
3223 Write_Int (Int (Nam));
3227 -- If the context expects a function call, discard any interpretation
3228 -- that is a procedure. If the node is not overloaded, leave as is for
3229 -- better error reporting when type mismatch is found.
3231 elsif Nkind (N) = N_Function_Call
3232 and then Is_Overloaded (Name (N))
3233 and then Ekind (Nam) = E_Procedure
3237 -- Ditto for function calls in a procedure context
3239 elsif Nkind (N) = N_Procedure_Call_Statement
3240 and then Is_Overloaded (Name (N))
3241 and then Etype (Nam) /= Standard_Void_Type
3245 elsif No (Actuals) then
3247 -- If Normalize succeeds, then there are default parameters for
3250 Indicate_Name_And_Type;
3252 elsif Ekind (Nam) = E_Operator then
3253 if Nkind (N) = N_Procedure_Call_Statement then
3257 -- This can occur when the prefix of the call is an operator
3258 -- name or an expanded name whose selector is an operator name.
3260 Analyze_Operator_Call (N, Nam);
3262 if Etype (N) /= Prev_T then
3264 -- Check that operator is not hidden by a function interpretation
3266 if Is_Overloaded (Name (N)) then
3272 Get_First_Interp (Name (N), I, It);
3273 while Present (It.Nam) loop
3274 if Operator_Hidden_By (It.Nam) then
3275 Set_Etype (N, Prev_T);
3279 Get_Next_Interp (I, It);
3284 -- If operator matches formals, record its name on the call.
3285 -- If the operator is overloaded, Resolve will select the
3286 -- correct one from the list of interpretations. The call
3287 -- node itself carries the first candidate.
3289 Set_Entity (Name (N), Nam);
3292 elsif Report and then Etype (N) = Any_Type then
3293 Error_Msg_N ("incompatible arguments for operator", N);
3297 -- Normalize_Actuals has chained the named associations in the
3298 -- correct order of the formals.
3300 Actual := First_Actual (N);
3301 Formal := First_Formal (Nam);
3303 -- If we are analyzing a call rewritten from object notation, skip
3304 -- first actual, which may be rewritten later as an explicit
3308 Next_Actual (Actual);
3309 Next_Formal (Formal);
3312 while Present (Actual) and then Present (Formal) loop
3313 if Nkind (Parent (Actual)) /= N_Parameter_Association
3314 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
3316 -- The actual can be compatible with the formal, but we must
3317 -- also check that the context is not an address type that is
3318 -- visibly an integer type. In this case the use of literals is
3319 -- illegal, except in the body of descendants of system, where
3320 -- arithmetic operations on address are of course used.
3322 if Has_Compatible_Type (Actual, Etype (Formal))
3324 (Etype (Actual) /= Universal_Integer
3325 or else not Is_Descendant_Of_Address (Etype (Formal))
3327 Is_Predefined_File_Name
3328 (Unit_File_Name (Get_Source_Unit (N))))
3330 Next_Actual (Actual);
3331 Next_Formal (Formal);
3333 -- In Allow_Integer_Address mode, we allow an actual integer to
3334 -- match a formal address type and vice versa. We only do this
3335 -- if we are certain that an error will otherwise be issued
3337 elsif Address_Integer_Convert_OK
3338 (Etype (Actual), Etype (Formal))
3339 and then (Report and not Is_Indexed and not Is_Indirect)
3341 -- Handle this case by introducing an unchecked conversion
3344 Unchecked_Convert_To (Etype (Formal),
3345 Relocate_Node (Actual)));
3346 Analyze_And_Resolve (Actual, Etype (Formal));
3347 Next_Actual (Actual);
3348 Next_Formal (Formal);
3350 -- For an Ada 2012 predicate or invariant, a call may mention
3351 -- an incomplete type, while resolution of the corresponding
3352 -- predicate function may see the full view, as a consequence
3353 -- of the delayed resolution of the corresponding expressions.
3355 elsif Ekind (Etype (Formal)) = E_Incomplete_Type
3356 and then Full_View (Etype (Formal)) = Etype (Actual)
3358 Set_Etype (Formal, Etype (Actual));
3359 Next_Actual (Actual);
3360 Next_Formal (Formal);
3363 if Debug_Flag_E then
3364 Write_Str (" type checking fails in call ");
3365 Write_Int (Int (N));
3366 Write_Str (" with formal ");
3367 Write_Int (Int (Formal));
3368 Write_Str (" in subprogram ");
3369 Write_Int (Int (Nam));
3373 -- Comment needed on the following test???
3375 if Report and not Is_Indexed and not Is_Indirect then
3377 -- Ada 2005 (AI-251): Complete the error notification
3378 -- to help new Ada 2005 users.
3380 if Is_Class_Wide_Type (Etype (Formal))
3381 and then Is_Interface (Etype (Etype (Formal)))
3382 and then not Interface_Present_In_Ancestor
3383 (Typ => Etype (Actual),
3384 Iface => Etype (Etype (Formal)))
3387 ("(Ada 2005) does not implement interface }",
3388 Actual, Etype (Etype (Formal)));
3391 Wrong_Type (Actual, Etype (Formal));
3393 if Nkind (Actual) = N_Op_Eq
3394 and then Nkind (Left_Opnd (Actual)) = N_Identifier
3396 Formal := First_Formal (Nam);
3397 while Present (Formal) loop
3398 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
3399 Error_Msg_N -- CODEFIX
3400 ("possible misspelling of `='>`!", Actual);
3404 Next_Formal (Formal);
3408 if All_Errors_Mode then
3409 Error_Msg_Sloc := Sloc (Nam);
3411 if Etype (Formal) = Any_Type then
3413 ("there is no legal actual parameter", Actual);
3416 if Is_Overloadable (Nam)
3417 and then Present (Alias (Nam))
3418 and then not Comes_From_Source (Nam)
3421 ("\\ =='> in call to inherited operation & #!",
3424 elsif Ekind (Nam) = E_Subprogram_Type then
3426 Access_To_Subprogram_Typ :
3427 constant Entity_Id :=
3429 (Associated_Node_For_Itype (Nam));
3432 ("\\ =='> in call to dereference of &#!",
3433 Actual, Access_To_Subprogram_Typ);
3438 ("\\ =='> in call to &#!", Actual, Nam);
3448 -- Normalize_Actuals has verified that a default value exists
3449 -- for this formal. Current actual names a subsequent formal.
3451 Next_Formal (Formal);
3455 -- On exit, all actuals match
3457 Indicate_Name_And_Type;
3459 end Analyze_One_Call;
3461 ---------------------------
3462 -- Analyze_Operator_Call --
3463 ---------------------------
3465 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
3466 Op_Name : constant Name_Id := Chars (Op_Id);
3467 Act1 : constant Node_Id := First_Actual (N);
3468 Act2 : constant Node_Id := Next_Actual (Act1);
3471 -- Binary operator case
3473 if Present (Act2) then
3475 -- If more than two operands, then not binary operator after all
3477 if Present (Next_Actual (Act2)) then
3481 -- Otherwise action depends on operator
3491 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
3496 Find_Boolean_Types (Act1, Act2, Op_Id, N);
3502 Find_Comparison_Types (Act1, Act2, Op_Id, N);
3506 Find_Equality_Types (Act1, Act2, Op_Id, N);
3508 when Name_Op_Concat =>
3509 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
3511 -- Is this when others, or should it be an abort???
3517 -- Unary operator case
3521 when Name_Op_Subtract |
3524 Find_Unary_Types (Act1, Op_Id, N);
3527 Find_Negation_Types (Act1, Op_Id, N);
3529 -- Is this when others correct, or should it be an abort???
3535 end Analyze_Operator_Call;
3537 -------------------------------------------
3538 -- Analyze_Overloaded_Selected_Component --
3539 -------------------------------------------
3541 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
3542 Nam : constant Node_Id := Prefix (N);
3543 Sel : constant Node_Id := Selector_Name (N);
3550 Set_Etype (Sel, Any_Type);
3552 Get_First_Interp (Nam, I, It);
3553 while Present (It.Typ) loop
3554 if Is_Access_Type (It.Typ) then
3555 T := Designated_Type (It.Typ);
3556 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
3561 -- Locate the component. For a private prefix the selector can denote
3564 if Is_Record_Type (T) or else Is_Private_Type (T) then
3566 -- If the prefix is a class-wide type, the visible components are
3567 -- those of the base type.
3569 if Is_Class_Wide_Type (T) then
3573 Comp := First_Entity (T);
3574 while Present (Comp) loop
3575 if Chars (Comp) = Chars (Sel)
3576 and then Is_Visible_Component (Comp)
3579 -- AI05-105: if the context is an object renaming with
3580 -- an anonymous access type, the expected type of the
3581 -- object must be anonymous. This is a name resolution rule.
3583 if Nkind (Parent (N)) /= N_Object_Renaming_Declaration
3584 or else No (Access_Definition (Parent (N)))
3585 or else Ekind (Etype (Comp)) = E_Anonymous_Access_Type
3587 Ekind (Etype (Comp)) = E_Anonymous_Access_Subprogram_Type
3589 Set_Entity (Sel, Comp);
3590 Set_Etype (Sel, Etype (Comp));
3591 Add_One_Interp (N, Etype (Comp), Etype (Comp));
3592 Check_Implicit_Dereference (N, Etype (Comp));
3594 -- This also specifies a candidate to resolve the name.
3595 -- Further overloading will be resolved from context.
3596 -- The selector name itself does not carry overloading
3599 Set_Etype (Nam, It.Typ);
3602 -- Named access type in the context of a renaming
3603 -- declaration with an access definition. Remove
3604 -- inapplicable candidate.
3613 elsif Is_Concurrent_Type (T) then
3614 Comp := First_Entity (T);
3615 while Present (Comp)
3616 and then Comp /= First_Private_Entity (T)
3618 if Chars (Comp) = Chars (Sel) then
3619 if Is_Overloadable (Comp) then
3620 Add_One_Interp (Sel, Comp, Etype (Comp));
3622 Set_Entity_With_Checks (Sel, Comp);
3623 Generate_Reference (Comp, Sel);
3626 Set_Etype (Sel, Etype (Comp));
3627 Set_Etype (N, Etype (Comp));
3628 Set_Etype (Nam, It.Typ);
3630 -- For access type case, introduce explicit dereference for
3631 -- more uniform treatment of entry calls. Do this only once
3632 -- if several interpretations yield an access type.
3634 if Is_Access_Type (Etype (Nam))
3635 and then Nkind (Nam) /= N_Explicit_Dereference
3637 Insert_Explicit_Dereference (Nam);
3639 (Warn_On_Dereference, "?d?implicit dereference", N);
3646 Set_Is_Overloaded (N, Is_Overloaded (Sel));
3649 Get_Next_Interp (I, It);
3652 if Etype (N) = Any_Type
3653 and then not Try_Object_Operation (N)
3655 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
3656 Set_Entity (Sel, Any_Id);
3657 Set_Etype (Sel, Any_Type);
3659 end Analyze_Overloaded_Selected_Component;
3661 ----------------------------------
3662 -- Analyze_Qualified_Expression --
3663 ----------------------------------
3665 procedure Analyze_Qualified_Expression (N : Node_Id) is
3666 Mark : constant Entity_Id := Subtype_Mark (N);
3667 Expr : constant Node_Id := Expression (N);
3673 Analyze_Expression (Expr);
3675 Set_Etype (N, Any_Type);
3680 if T = Any_Type then
3684 Check_Fully_Declared (T, N);
3686 -- If expected type is class-wide, check for exact match before
3687 -- expansion, because if the expression is a dispatching call it
3688 -- may be rewritten as explicit dereference with class-wide result.
3689 -- If expression is overloaded, retain only interpretations that
3690 -- will yield exact matches.
3692 if Is_Class_Wide_Type (T) then
3693 if not Is_Overloaded (Expr) then
3694 if Base_Type (Etype (Expr)) /= Base_Type (T) then
3695 if Nkind (Expr) = N_Aggregate then
3696 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
3698 Wrong_Type (Expr, T);
3703 Get_First_Interp (Expr, I, It);
3705 while Present (It.Nam) loop
3706 if Base_Type (It.Typ) /= Base_Type (T) then
3710 Get_Next_Interp (I, It);
3716 end Analyze_Qualified_Expression;
3718 -----------------------------------
3719 -- Analyze_Quantified_Expression --
3720 -----------------------------------
3722 procedure Analyze_Quantified_Expression (N : Node_Id) is
3723 function Is_Empty_Range (Typ : Entity_Id) return Boolean;
3724 -- If the iterator is part of a quantified expression, and the range is
3725 -- known to be statically empty, emit a warning and replace expression
3726 -- with its static value. Returns True if the replacement occurs.
3728 function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean;
3729 -- Determine whether if expression If_Expr lacks an else part or if it
3730 -- has one, it evaluates to True.
3732 --------------------
3733 -- Is_Empty_Range --
3734 --------------------
3736 function Is_Empty_Range (Typ : Entity_Id) return Boolean is
3737 Loc : constant Source_Ptr := Sloc (N);
3740 if Is_Array_Type (Typ)
3741 and then Compile_Time_Known_Bounds (Typ)
3743 (Expr_Value (Type_Low_Bound (Etype (First_Index (Typ)))) >
3744 Expr_Value (Type_High_Bound (Etype (First_Index (Typ)))))
3746 Preanalyze_And_Resolve (Condition (N), Standard_Boolean);
3748 if All_Present (N) then
3750 ("??quantified expression with ALL "
3751 & "over a null range has value True", N);
3752 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
3756 ("??quantified expression with SOME "
3757 & "over a null range has value False", N);
3758 Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
3769 -----------------------------
3770 -- No_Else_Or_Trivial_True --
3771 -----------------------------
3773 function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean is
3774 Else_Expr : constant Node_Id :=
3775 Next (Next (First (Expressions (If_Expr))));
3779 or else (Compile_Time_Known_Value (Else_Expr)
3780 and then Is_True (Expr_Value (Else_Expr)));
3781 end No_Else_Or_Trivial_True;
3785 Cond : constant Node_Id := Condition (N);
3786 Loop_Id : Entity_Id;
3787 QE_Scop : Entity_Id;
3789 -- Start of processing for Analyze_Quantified_Expression
3792 Check_SPARK_05_Restriction ("quantified expression is not allowed", N);
3794 -- Create a scope to emulate the loop-like behavior of the quantified
3795 -- expression. The scope is needed to provide proper visibility of the
3798 QE_Scop := New_Internal_Entity (E_Loop, Current_Scope, Sloc (N), 'L');
3799 Set_Etype (QE_Scop, Standard_Void_Type);
3800 Set_Scope (QE_Scop, Current_Scope);
3801 Set_Parent (QE_Scop, N);
3803 Push_Scope (QE_Scop);
3805 -- All constituents are preanalyzed and resolved to avoid untimely
3806 -- generation of various temporaries and types. Full analysis and
3807 -- expansion is carried out when the quantified expression is
3808 -- transformed into an expression with actions.
3810 if Present (Iterator_Specification (N)) then
3811 Preanalyze (Iterator_Specification (N));
3813 -- Do not proceed with the analysis when the range of iteration is
3814 -- empty. The appropriate error is issued by Is_Empty_Range.
3816 if Is_Entity_Name (Name (Iterator_Specification (N)))
3817 and then Is_Empty_Range (Etype (Name (Iterator_Specification (N))))
3822 else pragma Assert (Present (Loop_Parameter_Specification (N)));
3824 Loop_Par : constant Node_Id := Loop_Parameter_Specification (N);
3827 Preanalyze (Loop_Par);
3829 if Nkind (Discrete_Subtype_Definition (Loop_Par)) = N_Function_Call
3830 and then Parent (Loop_Par) /= N
3832 -- The parser cannot distinguish between a loop specification
3833 -- and an iterator specification. If after pre-analysis the
3834 -- proper form has been recognized, rewrite the expression to
3835 -- reflect the right kind. This is needed for proper ASIS
3836 -- navigation. If expansion is enabled, the transformation is
3837 -- performed when the expression is rewritten as a loop.
3839 Set_Iterator_Specification (N,
3840 New_Copy_Tree (Iterator_Specification (Parent (Loop_Par))));
3842 Set_Defining_Identifier (Iterator_Specification (N),
3843 Relocate_Node (Defining_Identifier (Loop_Par)));
3844 Set_Name (Iterator_Specification (N),
3845 Relocate_Node (Discrete_Subtype_Definition (Loop_Par)));
3846 Set_Comes_From_Source (Iterator_Specification (N),
3847 Comes_From_Source (Loop_Parameter_Specification (N)));
3848 Set_Loop_Parameter_Specification (N, Empty);
3853 Preanalyze_And_Resolve (Cond, Standard_Boolean);
3856 Set_Etype (N, Standard_Boolean);
3858 -- Verify that the loop variable is used within the condition of the
3859 -- quantified expression.
3861 if Present (Iterator_Specification (N)) then
3862 Loop_Id := Defining_Identifier (Iterator_Specification (N));
3864 Loop_Id := Defining_Identifier (Loop_Parameter_Specification (N));
3867 if Warn_On_Suspicious_Contract
3868 and then not Referenced (Loop_Id, Cond)
3870 Error_Msg_N ("?T?unused variable &", Loop_Id);
3873 -- Diagnose a possible misuse of the SOME existential quantifier. When
3874 -- we have a quantified expression of the form:
3876 -- for some X => (if P then Q [else True])
3878 -- any value for X that makes P False results in the if expression being
3879 -- trivially True, and so also results in the quantified expression
3880 -- being trivially True.
3882 if Warn_On_Suspicious_Contract
3883 and then not All_Present (N)
3884 and then Nkind (Cond) = N_If_Expression
3885 and then No_Else_Or_Trivial_True (Cond)
3887 Error_Msg_N ("?T?suspicious expression", N);
3888 Error_Msg_N ("\\did you mean (for all X ='> (if P then Q))", N);
3889 Error_Msg_N ("\\or (for some X ='> P and then Q) instead'?", N);
3891 end Analyze_Quantified_Expression;
3897 procedure Analyze_Range (N : Node_Id) is
3898 L : constant Node_Id := Low_Bound (N);
3899 H : constant Node_Id := High_Bound (N);
3900 I1, I2 : Interp_Index;
3903 procedure Check_Common_Type (T1, T2 : Entity_Id);
3904 -- Verify the compatibility of two types, and choose the
3905 -- non universal one if the other is universal.
3907 procedure Check_High_Bound (T : Entity_Id);
3908 -- Test one interpretation of the low bound against all those
3909 -- of the high bound.
3911 procedure Check_Universal_Expression (N : Node_Id);
3912 -- In Ada 83, reject bounds of a universal range that are not literals
3915 -----------------------
3916 -- Check_Common_Type --
3917 -----------------------
3919 procedure Check_Common_Type (T1, T2 : Entity_Id) is
3921 if Covers (T1 => T1, T2 => T2)
3923 Covers (T1 => T2, T2 => T1)
3925 if T1 = Universal_Integer
3926 or else T1 = Universal_Real
3927 or else T1 = Any_Character
3929 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
3932 Add_One_Interp (N, T1, T1);
3935 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
3938 end Check_Common_Type;
3940 ----------------------
3941 -- Check_High_Bound --
3942 ----------------------
3944 procedure Check_High_Bound (T : Entity_Id) is
3946 if not Is_Overloaded (H) then
3947 Check_Common_Type (T, Etype (H));
3949 Get_First_Interp (H, I2, It2);
3950 while Present (It2.Typ) loop
3951 Check_Common_Type (T, It2.Typ);
3952 Get_Next_Interp (I2, It2);
3955 end Check_High_Bound;
3957 -----------------------------
3958 -- Is_Universal_Expression --
3959 -----------------------------
3961 procedure Check_Universal_Expression (N : Node_Id) is
3963 if Etype (N) = Universal_Integer
3964 and then Nkind (N) /= N_Integer_Literal
3965 and then not Is_Entity_Name (N)
3966 and then Nkind (N) /= N_Attribute_Reference
3968 Error_Msg_N ("illegal bound in discrete range", N);
3970 end Check_Universal_Expression;
3972 -- Start of processing for Analyze_Range
3975 Set_Etype (N, Any_Type);
3976 Analyze_Expression (L);
3977 Analyze_Expression (H);
3979 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
3983 if not Is_Overloaded (L) then
3984 Check_High_Bound (Etype (L));
3986 Get_First_Interp (L, I1, It1);
3987 while Present (It1.Typ) loop
3988 Check_High_Bound (It1.Typ);
3989 Get_Next_Interp (I1, It1);
3993 -- If result is Any_Type, then we did not find a compatible pair
3995 if Etype (N) = Any_Type then
3996 Error_Msg_N ("incompatible types in range ", N);
4000 if Ada_Version = Ada_83
4002 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
4003 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
4005 Check_Universal_Expression (L);
4006 Check_Universal_Expression (H);
4009 Check_Function_Writable_Actuals (N);
4012 -----------------------
4013 -- Analyze_Reference --
4014 -----------------------
4016 procedure Analyze_Reference (N : Node_Id) is
4017 P : constant Node_Id := Prefix (N);
4020 Acc_Type : Entity_Id;
4025 -- An interesting error check, if we take the 'Ref of an object for
4026 -- which a pragma Atomic or Volatile has been given, and the type of the
4027 -- object is not Atomic or Volatile, then we are in trouble. The problem
4028 -- is that no trace of the atomic/volatile status will remain for the
4029 -- backend to respect when it deals with the resulting pointer, since
4030 -- the pointer type will not be marked atomic (it is a pointer to the
4031 -- base type of the object).
4033 -- It is not clear if that can ever occur, but in case it does, we will
4034 -- generate an error message. Not clear if this message can ever be
4035 -- generated, and pretty clear that it represents a bug if it is, still
4036 -- seems worth checking, except in CodePeer mode where we do not really
4037 -- care and don't want to bother the user.
4041 if Is_Entity_Name (P)
4042 and then Is_Object_Reference (P)
4043 and then not CodePeer_Mode
4048 if (Has_Atomic_Components (E)
4049 and then not Has_Atomic_Components (T))
4051 (Has_Volatile_Components (E)
4052 and then not Has_Volatile_Components (T))
4053 or else (Is_Atomic (E) and then not Is_Atomic (T))
4054 or else (Is_Volatile (E) and then not Is_Volatile (T))
4056 Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
4060 -- Carry on with normal processing
4062 Acc_Type := Create_Itype (E_Allocator_Type, N);
4063 Set_Etype (Acc_Type, Acc_Type);
4064 Set_Directly_Designated_Type (Acc_Type, Etype (P));
4065 Set_Etype (N, Acc_Type);
4066 end Analyze_Reference;
4068 --------------------------------
4069 -- Analyze_Selected_Component --
4070 --------------------------------
4072 -- Prefix is a record type or a task or protected type. In the latter case,
4073 -- the selector must denote a visible entry.
4075 procedure Analyze_Selected_Component (N : Node_Id) is
4076 Name : constant Node_Id := Prefix (N);
4077 Sel : constant Node_Id := Selector_Name (N);
4080 Has_Candidate : Boolean := False;
4083 Pent : Entity_Id := Empty;
4084 Prefix_Type : Entity_Id;
4086 Type_To_Use : Entity_Id;
4087 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
4088 -- a class-wide type, we use its root type, whose components are
4089 -- present in the class-wide type.
4091 Is_Single_Concurrent_Object : Boolean;
4092 -- Set True if the prefix is a single task or a single protected object
4094 procedure Find_Component_In_Instance (Rec : Entity_Id);
4095 -- In an instance, a component of a private extension may not be visible
4096 -- while it was visible in the generic. Search candidate scope for a
4097 -- component with the proper identifier. This is only done if all other
4098 -- searches have failed. If a match is found, the Etype of both N and
4099 -- Sel are set from this component, and the entity of Sel is set to
4100 -- reference this component. If no match is found, Entity (Sel) remains
4101 -- unset. For a derived type that is an actual of the instance, the
4102 -- desired component may be found in any ancestor.
4104 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
4105 -- It is known that the parent of N denotes a subprogram call. Comp
4106 -- is an overloadable component of the concurrent type of the prefix.
4107 -- Determine whether all formals of the parent of N and Comp are mode
4108 -- conformant. If the parent node is not analyzed yet it may be an
4109 -- indexed component rather than a function call.
4111 function Has_Dereference (Nod : Node_Id) return Boolean;
4112 -- Check whether prefix includes a dereference at any level.
4114 --------------------------------
4115 -- Find_Component_In_Instance --
4116 --------------------------------
4118 procedure Find_Component_In_Instance (Rec : Entity_Id) is
4124 while Present (Typ) loop
4125 Comp := First_Component (Typ);
4126 while Present (Comp) loop
4127 if Chars (Comp) = Chars (Sel) then
4128 Set_Entity_With_Checks (Sel, Comp);
4129 Set_Etype (Sel, Etype (Comp));
4130 Set_Etype (N, Etype (Comp));
4134 Next_Component (Comp);
4137 -- If not found, the component may be declared in the parent
4138 -- type or its full view, if any.
4140 if Is_Derived_Type (Typ) then
4143 if Is_Private_Type (Typ) then
4144 Typ := Full_View (Typ);
4152 -- If we fall through, no match, so no changes made
4155 end Find_Component_In_Instance;
4157 ------------------------------
4158 -- Has_Mode_Conformant_Spec --
4159 ------------------------------
4161 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
4162 Comp_Param : Entity_Id;
4164 Param_Typ : Entity_Id;
4167 Comp_Param := First_Formal (Comp);
4169 if Nkind (Parent (N)) = N_Indexed_Component then
4170 Param := First (Expressions (Parent (N)));
4172 Param := First (Parameter_Associations (Parent (N)));
4175 while Present (Comp_Param)
4176 and then Present (Param)
4178 Param_Typ := Find_Parameter_Type (Param);
4180 if Present (Param_Typ)
4182 not Conforming_Types
4183 (Etype (Comp_Param), Param_Typ, Mode_Conformant)
4188 Next_Formal (Comp_Param);
4192 -- One of the specs has additional formals; there is no match, unless
4193 -- this may be an indexing of a parameterless call.
4195 -- Note that when expansion is disabled, the corresponding record
4196 -- type of synchronized types is not constructed, so that there is
4197 -- no point is attempting an interpretation as a prefixed call, as
4198 -- this is bound to fail because the primitive operations will not
4199 -- be properly located.
4201 if Present (Comp_Param) or else Present (Param) then
4202 if Needs_No_Actuals (Comp)
4203 and then Is_Array_Type (Etype (Comp))
4204 and then not Expander_Active
4213 end Has_Mode_Conformant_Spec;
4215 ---------------------
4216 -- Has_Dereference --
4217 ---------------------
4219 function Has_Dereference (Nod : Node_Id) return Boolean is
4221 if Nkind (Nod) = N_Explicit_Dereference then
4224 -- When expansion is disabled an explicit dereference may not have
4225 -- been inserted, but if this is an access type the indirection makes
4228 elsif Is_Access_Type (Etype (Nod)) then
4231 elsif Nkind_In (Nod, N_Indexed_Component, N_Selected_Component) then
4232 return Has_Dereference (Prefix (Nod));
4237 end Has_Dereference;
4239 -- Start of processing for Analyze_Selected_Component
4242 Set_Etype (N, Any_Type);
4244 if Is_Overloaded (Name) then
4245 Analyze_Overloaded_Selected_Component (N);
4248 elsif Etype (Name) = Any_Type then
4249 Set_Entity (Sel, Any_Id);
4250 Set_Etype (Sel, Any_Type);
4254 Prefix_Type := Etype (Name);
4257 if Is_Access_Type (Prefix_Type) then
4259 -- A RACW object can never be used as prefix of a selected component
4260 -- since that means it is dereferenced without being a controlling
4261 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
4262 -- reporting an error, we must check whether this is actually a
4263 -- dispatching call in prefix form.
4265 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
4266 and then Comes_From_Source (N)
4268 if Try_Object_Operation (N) then
4272 ("invalid dereference of a remote access-to-class-wide value",
4276 -- Normal case of selected component applied to access type
4279 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
4281 if Is_Entity_Name (Name) then
4282 Pent := Entity (Name);
4283 elsif Nkind (Name) = N_Selected_Component
4284 and then Is_Entity_Name (Selector_Name (Name))
4286 Pent := Entity (Selector_Name (Name));
4289 Prefix_Type := Process_Implicit_Dereference_Prefix (Pent, Name);
4292 -- If we have an explicit dereference of a remote access-to-class-wide
4293 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
4294 -- have to check for the case of a prefix that is a controlling operand
4295 -- of a prefixed dispatching call, as the dereference is legal in that
4296 -- case. Normally this condition is checked in Validate_Remote_Access_
4297 -- To_Class_Wide_Type, but we have to defer the checking for selected
4298 -- component prefixes because of the prefixed dispatching call case.
4299 -- Note that implicit dereferences are checked for this just above.
4301 elsif Nkind (Name) = N_Explicit_Dereference
4302 and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
4303 and then Comes_From_Source (N)
4305 if Try_Object_Operation (N) then
4309 ("invalid dereference of a remote access-to-class-wide value",
4314 -- (Ada 2005): if the prefix is the limited view of a type, and
4315 -- the context already includes the full view, use the full view
4316 -- in what follows, either to retrieve a component of to find
4317 -- a primitive operation. If the prefix is an explicit dereference,
4318 -- set the type of the prefix to reflect this transformation.
4319 -- If the non-limited view is itself an incomplete type, get the
4320 -- full view if available.
4322 if From_Limited_With (Prefix_Type)
4323 and then Has_Non_Limited_View (Prefix_Type)
4325 Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
4327 if Nkind (N) = N_Explicit_Dereference then
4328 Set_Etype (Prefix (N), Prefix_Type);
4332 if Ekind (Prefix_Type) = E_Private_Subtype then
4333 Prefix_Type := Base_Type (Prefix_Type);
4336 Type_To_Use := Prefix_Type;
4338 -- For class-wide types, use the entity list of the root type. This
4339 -- indirection is specially important for private extensions because
4340 -- only the root type get switched (not the class-wide type).
4342 if Is_Class_Wide_Type (Prefix_Type) then
4343 Type_To_Use := Root_Type (Prefix_Type);
4346 -- If the prefix is a single concurrent object, use its name in error
4347 -- messages, rather than that of its anonymous type.
4349 Is_Single_Concurrent_Object :=
4350 Is_Concurrent_Type (Prefix_Type)
4351 and then Is_Internal_Name (Chars (Prefix_Type))
4352 and then not Is_Derived_Type (Prefix_Type)
4353 and then Is_Entity_Name (Name);
4355 Comp := First_Entity (Type_To_Use);
4357 -- If the selector has an original discriminant, the node appears in
4358 -- an instance. Replace the discriminant with the corresponding one
4359 -- in the current discriminated type. For nested generics, this must
4360 -- be done transitively, so note the new original discriminant.
4362 if Nkind (Sel) = N_Identifier
4363 and then In_Instance
4364 and then Present (Original_Discriminant (Sel))
4366 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
4368 -- Mark entity before rewriting, for completeness and because
4369 -- subsequent semantic checks might examine the original node.
4371 Set_Entity (Sel, Comp);
4372 Rewrite (Selector_Name (N), New_Occurrence_Of (Comp, Sloc (N)));
4373 Set_Original_Discriminant (Selector_Name (N), Comp);
4374 Set_Etype (N, Etype (Comp));
4375 Check_Implicit_Dereference (N, Etype (Comp));
4377 if Is_Access_Type (Etype (Name)) then
4378 Insert_Explicit_Dereference (Name);
4379 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
4382 elsif Is_Record_Type (Prefix_Type) then
4384 -- Find component with given name. In an instance, if the node is
4385 -- known as a prefixed call, do not examine components whose
4386 -- visibility may be accidental.
4388 while Present (Comp) and then not Is_Prefixed_Call (N) loop
4389 if Chars (Comp) = Chars (Sel)
4390 and then Is_Visible_Component (Comp, N)
4392 Set_Entity_With_Checks (Sel, Comp);
4393 Set_Etype (Sel, Etype (Comp));
4395 if Ekind (Comp) = E_Discriminant then
4396 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
4398 ("cannot reference discriminant of unchecked union",
4402 if Is_Generic_Type (Prefix_Type)
4404 Is_Generic_Type (Root_Type (Prefix_Type))
4406 Set_Original_Discriminant (Sel, Comp);
4410 -- Resolve the prefix early otherwise it is not possible to
4411 -- build the actual subtype of the component: it may need
4412 -- to duplicate this prefix and duplication is only allowed
4413 -- on fully resolved expressions.
4417 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
4418 -- subtypes in a package specification.
4421 -- limited with Pkg;
4423 -- type Acc_Inc is access Pkg.T;
4425 -- N : Natural := X.all.Comp; -- ERROR, limited view
4426 -- end Pkg; -- Comp is not visible
4428 if Nkind (Name) = N_Explicit_Dereference
4429 and then From_Limited_With (Etype (Prefix (Name)))
4430 and then not Is_Potentially_Use_Visible (Etype (Name))
4431 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
4432 N_Package_Specification
4435 ("premature usage of incomplete}", Prefix (Name),
4436 Etype (Prefix (Name)));
4439 -- We never need an actual subtype for the case of a selection
4440 -- for a indexed component of a non-packed array, since in
4441 -- this case gigi generates all the checks and can find the
4442 -- necessary bounds information.
4444 -- We also do not need an actual subtype for the case of a
4445 -- first, last, length, or range attribute applied to a
4446 -- non-packed array, since gigi can again get the bounds in
4447 -- these cases (gigi cannot handle the packed case, since it
4448 -- has the bounds of the packed array type, not the original
4449 -- bounds of the type). However, if the prefix is itself a
4450 -- selected component, as in a.b.c (i), gigi may regard a.b.c
4451 -- as a dynamic-sized temporary, so we do generate an actual
4452 -- subtype for this case.
4454 Parent_N := Parent (N);
4456 if not Is_Packed (Etype (Comp))
4458 ((Nkind (Parent_N) = N_Indexed_Component
4459 and then Nkind (Name) /= N_Selected_Component)
4461 (Nkind (Parent_N) = N_Attribute_Reference
4463 Nam_In (Attribute_Name (Parent_N), Name_First,
4468 Set_Etype (N, Etype (Comp));
4470 -- If full analysis is not enabled, we do not generate an
4471 -- actual subtype, because in the absence of expansion
4472 -- reference to a formal of a protected type, for example,
4473 -- will not be properly transformed, and will lead to
4474 -- out-of-scope references in gigi.
4476 -- In all other cases, we currently build an actual subtype.
4477 -- It seems likely that many of these cases can be avoided,
4478 -- but right now, the front end makes direct references to the
4479 -- bounds (e.g. in generating a length check), and if we do
4480 -- not make an actual subtype, we end up getting a direct
4481 -- reference to a discriminant, which will not do.
4483 elsif Full_Analysis then
4485 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
4486 Insert_Action (N, Act_Decl);
4488 if No (Act_Decl) then
4489 Set_Etype (N, Etype (Comp));
4492 -- Component type depends on discriminants. Enter the
4493 -- main attributes of the subtype.
4496 Subt : constant Entity_Id :=
4497 Defining_Identifier (Act_Decl);
4500 Set_Etype (Subt, Base_Type (Etype (Comp)));
4501 Set_Ekind (Subt, Ekind (Etype (Comp)));
4502 Set_Etype (N, Subt);
4506 -- If Full_Analysis not enabled, just set the Etype
4509 Set_Etype (N, Etype (Comp));
4512 Check_Implicit_Dereference (N, Etype (N));
4516 -- If the prefix is a private extension, check only the visible
4517 -- components of the partial view. This must include the tag,
4518 -- which can appear in expanded code in a tag check.
4520 if Ekind (Type_To_Use) = E_Record_Type_With_Private
4521 and then Chars (Selector_Name (N)) /= Name_uTag
4523 exit when Comp = Last_Entity (Type_To_Use);
4529 -- Ada 2005 (AI-252): The selected component can be interpreted as
4530 -- a prefixed view of a subprogram. Depending on the context, this is
4531 -- either a name that can appear in a renaming declaration, or part
4532 -- of an enclosing call given in prefix form.
4534 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
4535 -- selected component should resolve to a name.
4537 if Ada_Version >= Ada_2005
4538 and then Is_Tagged_Type (Prefix_Type)
4539 and then not Is_Concurrent_Type (Prefix_Type)
4541 if Nkind (Parent (N)) = N_Generic_Association
4542 or else Nkind (Parent (N)) = N_Requeue_Statement
4543 or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
4545 if Find_Primitive_Operation (N) then
4549 elsif Try_Object_Operation (N) then
4553 -- If the transformation fails, it will be necessary to redo the
4554 -- analysis with all errors enabled, to indicate candidate
4555 -- interpretations and reasons for each failure ???
4559 elsif Is_Private_Type (Prefix_Type) then
4561 -- Allow access only to discriminants of the type. If the type has
4562 -- no full view, gigi uses the parent type for the components, so we
4563 -- do the same here.
4565 if No (Full_View (Prefix_Type)) then
4566 Type_To_Use := Root_Type (Base_Type (Prefix_Type));
4567 Comp := First_Entity (Type_To_Use);
4570 while Present (Comp) loop
4571 if Chars (Comp) = Chars (Sel) then
4572 if Ekind (Comp) = E_Discriminant then
4573 Set_Entity_With_Checks (Sel, Comp);
4574 Generate_Reference (Comp, Sel);
4576 Set_Etype (Sel, Etype (Comp));
4577 Set_Etype (N, Etype (Comp));
4578 Check_Implicit_Dereference (N, Etype (N));
4580 if Is_Generic_Type (Prefix_Type)
4581 or else Is_Generic_Type (Root_Type (Prefix_Type))
4583 Set_Original_Discriminant (Sel, Comp);
4586 -- Before declaring an error, check whether this is tagged
4587 -- private type and a call to a primitive operation.
4589 elsif Ada_Version >= Ada_2005
4590 and then Is_Tagged_Type (Prefix_Type)
4591 and then Try_Object_Operation (N)
4596 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4597 Error_Msg_NE ("invisible selector& for }", N, Sel);
4598 Set_Entity (Sel, Any_Id);
4599 Set_Etype (N, Any_Type);
4608 elsif Is_Concurrent_Type (Prefix_Type) then
4610 -- Find visible operation with given name. For a protected type,
4611 -- the possible candidates are discriminants, entries or protected
4612 -- procedures. For a task type, the set can only include entries or
4613 -- discriminants if the task type is not an enclosing scope. If it
4614 -- is an enclosing scope (e.g. in an inner task) then all entities
4615 -- are visible, but the prefix must denote the enclosing scope, i.e.
4616 -- can only be a direct name or an expanded name.
4618 Set_Etype (Sel, Any_Type);
4619 In_Scope := In_Open_Scopes (Prefix_Type);
4621 while Present (Comp) loop
4622 if Chars (Comp) = Chars (Sel) then
4623 if Is_Overloadable (Comp) then
4624 Add_One_Interp (Sel, Comp, Etype (Comp));
4626 -- If the prefix is tagged, the correct interpretation may
4627 -- lie in the primitive or class-wide operations of the
4628 -- type. Perform a simple conformance check to determine
4629 -- whether Try_Object_Operation should be invoked even if
4630 -- a visible entity is found.
4632 if Is_Tagged_Type (Prefix_Type)
4634 Nkind_In (Parent (N), N_Procedure_Call_Statement,
4636 N_Indexed_Component)
4637 and then Has_Mode_Conformant_Spec (Comp)
4639 Has_Candidate := True;
4642 -- Note: a selected component may not denote a component of a
4643 -- protected type (4.1.3(7)).
4645 elsif Ekind_In (Comp, E_Discriminant, E_Entry_Family)
4647 and then not Is_Protected_Type (Prefix_Type)
4648 and then Is_Entity_Name (Name))
4650 Set_Entity_With_Checks (Sel, Comp);
4651 Generate_Reference (Comp, Sel);
4653 -- The selector is not overloadable, so we have a candidate
4656 Has_Candidate := True;
4662 Set_Etype (Sel, Etype (Comp));
4663 Set_Etype (N, Etype (Comp));
4665 if Ekind (Comp) = E_Discriminant then
4666 Set_Original_Discriminant (Sel, Comp);
4669 -- For access type case, introduce explicit dereference for
4670 -- more uniform treatment of entry calls.
4672 if Is_Access_Type (Etype (Name)) then
4673 Insert_Explicit_Dereference (Name);
4675 (Warn_On_Dereference, "?d?implicit dereference", N);
4681 exit when not In_Scope
4683 Comp = First_Private_Entity (Base_Type (Prefix_Type));
4686 -- If the scope is a current instance, the prefix cannot be an
4687 -- expression of the same type, unless the selector designates a
4688 -- public operation (otherwise that would represent an attempt to
4689 -- reach an internal entity of another synchronized object).
4690 -- This is legal if prefix is an access to such type and there is
4691 -- a dereference, or is a component with a dereferenced prefix.
4692 -- It is also legal if the prefix is a component of a task type,
4693 -- and the selector is one of the task operations.
4696 and then not Is_Entity_Name (Name)
4697 and then not Has_Dereference (Name)
4699 if Is_Task_Type (Prefix_Type)
4700 and then Present (Entity (Sel))
4701 and then Ekind_In (Entity (Sel), E_Entry, E_Entry_Family)
4707 ("invalid reference to internal operation of some object of "
4708 & "type &", N, Type_To_Use);
4709 Set_Entity (Sel, Any_Id);
4710 Set_Etype (Sel, Any_Type);
4715 -- If there is no visible entity with the given name or none of the
4716 -- visible entities are plausible interpretations, check whether
4717 -- there is some other primitive operation with that name.
4719 if Ada_Version >= Ada_2005 and then Is_Tagged_Type (Prefix_Type) then
4720 if (Etype (N) = Any_Type
4721 or else not Has_Candidate)
4722 and then Try_Object_Operation (N)
4726 -- If the context is not syntactically a procedure call, it
4727 -- may be a call to a primitive function declared outside of
4728 -- the synchronized type.
4730 -- If the context is a procedure call, there might still be
4731 -- an overloading between an entry and a primitive procedure
4732 -- declared outside of the synchronized type, called in prefix
4733 -- notation. This is harder to disambiguate because in one case
4734 -- the controlling formal is implicit ???
4736 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
4737 and then Nkind (Parent (N)) /= N_Indexed_Component
4738 and then Try_Object_Operation (N)
4743 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
4744 -- entry or procedure of a tagged concurrent type we must check
4745 -- if there are class-wide subprograms covering the primitive. If
4746 -- true then Try_Object_Operation reports the error.
4749 and then Is_Concurrent_Type (Prefix_Type)
4750 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
4752 -- Duplicate the call. This is required to avoid problems with
4753 -- the tree transformations performed by Try_Object_Operation.
4754 -- Set properly the parent of the copied call, because it is
4755 -- about to be reanalyzed.
4758 Par : constant Node_Id := New_Copy_Tree (Parent (N));
4761 Set_Parent (Par, Parent (Parent (N)));
4763 if Try_Object_Operation
4764 (Sinfo.Name (Par), CW_Test_Only => True)
4772 if Etype (N) = Any_Type and then Is_Protected_Type (Prefix_Type) then
4774 -- Case of a prefix of a protected type: selector might denote
4775 -- an invisible private component.
4777 Comp := First_Private_Entity (Base_Type (Prefix_Type));
4778 while Present (Comp) and then Chars (Comp) /= Chars (Sel) loop
4782 if Present (Comp) then
4783 if Is_Single_Concurrent_Object then
4784 Error_Msg_Node_2 := Entity (Name);
4785 Error_Msg_NE ("invisible selector& for &", N, Sel);
4788 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4789 Error_Msg_NE ("invisible selector& for }", N, Sel);
4795 Set_Is_Overloaded (N, Is_Overloaded (Sel));
4800 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
4803 -- If N still has no type, the component is not defined in the prefix
4805 if Etype (N) = Any_Type then
4807 if Is_Single_Concurrent_Object then
4808 Error_Msg_Node_2 := Entity (Name);
4809 Error_Msg_NE ("no selector& for&", N, Sel);
4811 Check_Misspelled_Selector (Type_To_Use, Sel);
4813 -- If this is a derived formal type, the parent may have different
4814 -- visibility at this point. Try for an inherited component before
4815 -- reporting an error.
4817 elsif Is_Generic_Type (Prefix_Type)
4818 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
4819 and then Prefix_Type /= Etype (Prefix_Type)
4820 and then Is_Record_Type (Etype (Prefix_Type))
4822 Set_Etype (Prefix (N), Etype (Prefix_Type));
4823 Analyze_Selected_Component (N);
4826 -- Similarly, if this is the actual for a formal derived type, or
4827 -- a derived type thereof, the component inherited from the generic
4828 -- parent may not be visible in the actual, but the selected
4829 -- component is legal. Climb up the derivation chain of the generic
4830 -- parent type until we find the proper ancestor type.
4832 elsif In_Instance and then Is_Tagged_Type (Prefix_Type) then
4834 Par : Entity_Id := Prefix_Type;
4836 -- Climb up derivation chain to generic actual subtype
4838 while not Is_Generic_Actual_Type (Par) loop
4839 if Ekind (Par) = E_Record_Type then
4840 Par := Parent_Subtype (Par);
4843 exit when Par = Etype (Par);
4848 if Present (Par) and then Is_Generic_Actual_Type (Par) then
4850 -- Now look for component in ancestor types
4852 Par := Generic_Parent_Type (Declaration_Node (Par));
4854 Find_Component_In_Instance (Par);
4855 exit when Present (Entity (Sel))
4856 or else Par = Etype (Par);
4860 -- Another special case: the type is an extension of a private
4861 -- type T, is an actual in an instance, and we are in the body
4862 -- of the instance, so the generic body had a full view of the
4863 -- type declaration for T or of some ancestor that defines the
4864 -- component in question.
4866 elsif Is_Derived_Type (Type_To_Use)
4867 and then Used_As_Generic_Actual (Type_To_Use)
4868 and then In_Instance_Body
4870 Find_Component_In_Instance (Parent_Subtype (Type_To_Use));
4872 -- In ASIS mode the generic parent type may be absent. Examine
4873 -- the parent type directly for a component that may have been
4874 -- visible in a parent generic unit.
4876 elsif Is_Derived_Type (Prefix_Type) then
4877 Par := Etype (Prefix_Type);
4878 Find_Component_In_Instance (Par);
4882 -- The search above must have eventually succeeded, since the
4883 -- selected component was legal in the generic.
4885 if No (Entity (Sel)) then
4886 raise Program_Error;
4891 -- Component not found, specialize error message when appropriate
4894 if Ekind (Prefix_Type) = E_Record_Subtype then
4896 -- Check whether this is a component of the base type which
4897 -- is absent from a statically constrained subtype. This will
4898 -- raise constraint error at run time, but is not a compile-
4899 -- time error. When the selector is illegal for base type as
4900 -- well fall through and generate a compilation error anyway.
4902 Comp := First_Component (Base_Type (Prefix_Type));
4903 while Present (Comp) loop
4904 if Chars (Comp) = Chars (Sel)
4905 and then Is_Visible_Component (Comp)
4907 Set_Entity_With_Checks (Sel, Comp);
4908 Generate_Reference (Comp, Sel);
4909 Set_Etype (Sel, Etype (Comp));
4910 Set_Etype (N, Etype (Comp));
4912 -- Emit appropriate message. The node will be replaced
4913 -- by an appropriate raise statement.
4915 -- Note that in SPARK mode, as with all calls to apply a
4916 -- compile time constraint error, this will be made into
4917 -- an error to simplify the processing of the formal
4918 -- verification backend.
4920 Apply_Compile_Time_Constraint_Error
4921 (N, "component not present in }??",
4922 CE_Discriminant_Check_Failed,
4923 Ent => Prefix_Type, Rep => False);
4925 Set_Raises_Constraint_Error (N);
4929 Next_Component (Comp);
4934 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4935 Error_Msg_NE ("no selector& for}", N, Sel);
4937 -- Add information in the case of an incomplete prefix
4939 if Is_Incomplete_Type (Type_To_Use) then
4941 Inc : constant Entity_Id := First_Subtype (Type_To_Use);
4944 if From_Limited_With (Scope (Type_To_Use)) then
4946 ("\limited view of& has no components", N, Inc);
4950 ("\premature usage of incomplete type&", N, Inc);
4952 if Nkind (Parent (Inc)) =
4953 N_Incomplete_Type_Declaration
4955 -- Record location of premature use in entity so that
4956 -- a continuation message is generated when the
4957 -- completion is seen.
4959 Set_Premature_Use (Parent (Inc), N);
4965 Check_Misspelled_Selector (Type_To_Use, Sel);
4968 Set_Entity (Sel, Any_Id);
4969 Set_Etype (Sel, Any_Type);
4971 end Analyze_Selected_Component;
4973 ---------------------------
4974 -- Analyze_Short_Circuit --
4975 ---------------------------
4977 procedure Analyze_Short_Circuit (N : Node_Id) is
4978 L : constant Node_Id := Left_Opnd (N);
4979 R : constant Node_Id := Right_Opnd (N);
4984 Analyze_Expression (L);
4985 Analyze_Expression (R);
4986 Set_Etype (N, Any_Type);
4988 if not Is_Overloaded (L) then
4989 if Root_Type (Etype (L)) = Standard_Boolean
4990 and then Has_Compatible_Type (R, Etype (L))
4992 Add_One_Interp (N, Etype (L), Etype (L));
4996 Get_First_Interp (L, Ind, It);
4997 while Present (It.Typ) loop
4998 if Root_Type (It.Typ) = Standard_Boolean
4999 and then Has_Compatible_Type (R, It.Typ)
5001 Add_One_Interp (N, It.Typ, It.Typ);
5004 Get_Next_Interp (Ind, It);
5008 -- Here we have failed to find an interpretation. Clearly we know that
5009 -- it is not the case that both operands can have an interpretation of
5010 -- Boolean, but this is by far the most likely intended interpretation.
5011 -- So we simply resolve both operands as Booleans, and at least one of
5012 -- these resolutions will generate an error message, and we do not need
5013 -- to give another error message on the short circuit operation itself.
5015 if Etype (N) = Any_Type then
5016 Resolve (L, Standard_Boolean);
5017 Resolve (R, Standard_Boolean);
5018 Set_Etype (N, Standard_Boolean);
5020 end Analyze_Short_Circuit;
5026 procedure Analyze_Slice (N : Node_Id) is
5027 D : constant Node_Id := Discrete_Range (N);
5028 P : constant Node_Id := Prefix (N);
5029 Array_Type : Entity_Id;
5030 Index_Type : Entity_Id;
5032 procedure Analyze_Overloaded_Slice;
5033 -- If the prefix is overloaded, select those interpretations that
5034 -- yield a one-dimensional array type.
5036 ------------------------------
5037 -- Analyze_Overloaded_Slice --
5038 ------------------------------
5040 procedure Analyze_Overloaded_Slice is
5046 Set_Etype (N, Any_Type);
5048 Get_First_Interp (P, I, It);
5049 while Present (It.Nam) loop
5052 if Is_Access_Type (Typ) then
5053 Typ := Designated_Type (Typ);
5055 (Warn_On_Dereference, "?d?implicit dereference", N);
5058 if Is_Array_Type (Typ)
5059 and then Number_Dimensions (Typ) = 1
5060 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
5062 Add_One_Interp (N, Typ, Typ);
5065 Get_Next_Interp (I, It);
5068 if Etype (N) = Any_Type then
5069 Error_Msg_N ("expect array type in prefix of slice", N);
5071 end Analyze_Overloaded_Slice;
5073 -- Start of processing for Analyze_Slice
5076 if Comes_From_Source (N) then
5077 Check_SPARK_05_Restriction ("slice is not allowed", N);
5083 if Is_Overloaded (P) then
5084 Analyze_Overloaded_Slice;
5087 Array_Type := Etype (P);
5088 Set_Etype (N, Any_Type);
5090 if Is_Access_Type (Array_Type) then
5091 Array_Type := Designated_Type (Array_Type);
5092 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
5095 if not Is_Array_Type (Array_Type) then
5096 Wrong_Type (P, Any_Array);
5098 elsif Number_Dimensions (Array_Type) > 1 then
5100 ("type is not one-dimensional array in slice prefix", N);
5103 if Ekind (Array_Type) = E_String_Literal_Subtype then
5104 Index_Type := Etype (String_Literal_Low_Bound (Array_Type));
5106 Index_Type := Etype (First_Index (Array_Type));
5109 if not Has_Compatible_Type (D, Index_Type) then
5110 Wrong_Type (D, Index_Type);
5112 Set_Etype (N, Array_Type);
5118 -----------------------------
5119 -- Analyze_Type_Conversion --
5120 -----------------------------
5122 procedure Analyze_Type_Conversion (N : Node_Id) is
5123 Expr : constant Node_Id := Expression (N);
5127 -- If Conversion_OK is set, then the Etype is already set, and the only
5128 -- processing required is to analyze the expression. This is used to
5129 -- construct certain "illegal" conversions which are not allowed by Ada
5130 -- semantics, but can be handled by Gigi, see Sinfo for further details.
5132 if Conversion_OK (N) then
5137 -- Otherwise full type analysis is required, as well as some semantic
5138 -- checks to make sure the argument of the conversion is appropriate.
5140 Find_Type (Subtype_Mark (N));
5141 Typ := Entity (Subtype_Mark (N));
5143 Check_Fully_Declared (Typ, N);
5144 Analyze_Expression (Expr);
5145 Validate_Remote_Type_Type_Conversion (N);
5147 -- Only remaining step is validity checks on the argument. These
5148 -- are skipped if the conversion does not come from the source.
5150 if not Comes_From_Source (N) then
5153 -- If there was an error in a generic unit, no need to replicate the
5154 -- error message. Conversely, constant-folding in the generic may
5155 -- transform the argument of a conversion into a string literal, which
5156 -- is legal. Therefore the following tests are not performed in an
5157 -- instance. The same applies to an inlined body.
5159 elsif In_Instance or In_Inlined_Body then
5162 elsif Nkind (Expr) = N_Null then
5163 Error_Msg_N ("argument of conversion cannot be null", N);
5164 Error_Msg_N ("\use qualified expression instead", N);
5165 Set_Etype (N, Any_Type);
5167 elsif Nkind (Expr) = N_Aggregate then
5168 Error_Msg_N ("argument of conversion cannot be aggregate", N);
5169 Error_Msg_N ("\use qualified expression instead", N);
5171 elsif Nkind (Expr) = N_Allocator then
5172 Error_Msg_N ("argument of conversion cannot be an allocator", N);
5173 Error_Msg_N ("\use qualified expression instead", N);
5175 elsif Nkind (Expr) = N_String_Literal then
5176 Error_Msg_N ("argument of conversion cannot be string literal", N);
5177 Error_Msg_N ("\use qualified expression instead", N);
5179 elsif Nkind (Expr) = N_Character_Literal then
5180 if Ada_Version = Ada_83 then
5181 Resolve (Expr, Typ);
5183 Error_Msg_N ("argument of conversion cannot be character literal",
5185 Error_Msg_N ("\use qualified expression instead", N);
5188 elsif Nkind (Expr) = N_Attribute_Reference
5189 and then Nam_In (Attribute_Name (Expr), Name_Access,
5190 Name_Unchecked_Access,
5191 Name_Unrestricted_Access)
5193 Error_Msg_N ("argument of conversion cannot be access", N);
5194 Error_Msg_N ("\use qualified expression instead", N);
5197 -- A formal parameter of a specific tagged type whose related subprogram
5198 -- is subject to pragma Extensions_Visible with value "False" cannot
5199 -- appear in a class-wide conversion (SPARK RM 6.1.7(3)). Do not check
5200 -- internally generated expressions.
5202 if Is_Class_Wide_Type (Typ)
5203 and then Comes_From_Source (Expr)
5204 and then Is_EVF_Expression (Expr)
5207 ("formal parameter with Extensions_Visible False cannot be "
5208 & "converted to class-wide type", Expr);
5210 end Analyze_Type_Conversion;
5212 ----------------------
5213 -- Analyze_Unary_Op --
5214 ----------------------
5216 procedure Analyze_Unary_Op (N : Node_Id) is
5217 R : constant Node_Id := Right_Opnd (N);
5218 Op_Id : Entity_Id := Entity (N);
5221 Set_Etype (N, Any_Type);
5222 Candidate_Type := Empty;
5224 Analyze_Expression (R);
5226 if Present (Op_Id) then
5227 if Ekind (Op_Id) = E_Operator then
5228 Find_Unary_Types (R, Op_Id, N);
5230 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5234 Op_Id := Get_Name_Entity_Id (Chars (N));
5235 while Present (Op_Id) loop
5236 if Ekind (Op_Id) = E_Operator then
5237 if No (Next_Entity (First_Entity (Op_Id))) then
5238 Find_Unary_Types (R, Op_Id, N);
5241 elsif Is_Overloadable (Op_Id) then
5242 Analyze_User_Defined_Unary_Op (N, Op_Id);
5245 Op_Id := Homonym (Op_Id);
5250 end Analyze_Unary_Op;
5252 ----------------------------------
5253 -- Analyze_Unchecked_Expression --
5254 ----------------------------------
5256 procedure Analyze_Unchecked_Expression (N : Node_Id) is
5258 Analyze (Expression (N), Suppress => All_Checks);
5259 Set_Etype (N, Etype (Expression (N)));
5260 Save_Interps (Expression (N), N);
5261 end Analyze_Unchecked_Expression;
5263 ---------------------------------------
5264 -- Analyze_Unchecked_Type_Conversion --
5265 ---------------------------------------
5267 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
5269 Find_Type (Subtype_Mark (N));
5270 Analyze_Expression (Expression (N));
5271 Set_Etype (N, Entity (Subtype_Mark (N)));
5272 end Analyze_Unchecked_Type_Conversion;
5274 ------------------------------------
5275 -- Analyze_User_Defined_Binary_Op --
5276 ------------------------------------
5278 procedure Analyze_User_Defined_Binary_Op
5283 -- Only do analysis if the operator Comes_From_Source, since otherwise
5284 -- the operator was generated by the expander, and all such operators
5285 -- always refer to the operators in package Standard.
5287 if Comes_From_Source (N) then
5289 F1 : constant Entity_Id := First_Formal (Op_Id);
5290 F2 : constant Entity_Id := Next_Formal (F1);
5293 -- Verify that Op_Id is a visible binary function. Note that since
5294 -- we know Op_Id is overloaded, potentially use visible means use
5295 -- visible for sure (RM 9.4(11)).
5297 if Ekind (Op_Id) = E_Function
5298 and then Present (F2)
5299 and then (Is_Immediately_Visible (Op_Id)
5300 or else Is_Potentially_Use_Visible (Op_Id))
5301 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
5302 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
5304 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5306 -- If the left operand is overloaded, indicate that the current
5307 -- type is a viable candidate. This is redundant in most cases,
5308 -- but for equality and comparison operators where the context
5309 -- does not impose a type on the operands, setting the proper
5310 -- type is necessary to avoid subsequent ambiguities during
5311 -- resolution, when both user-defined and predefined operators
5312 -- may be candidates.
5314 if Is_Overloaded (Left_Opnd (N)) then
5315 Set_Etype (Left_Opnd (N), Etype (F1));
5318 if Debug_Flag_E then
5319 Write_Str ("user defined operator ");
5320 Write_Name (Chars (Op_Id));
5321 Write_Str (" on node ");
5322 Write_Int (Int (N));
5328 end Analyze_User_Defined_Binary_Op;
5330 -----------------------------------
5331 -- Analyze_User_Defined_Unary_Op --
5332 -----------------------------------
5334 procedure Analyze_User_Defined_Unary_Op
5339 -- Only do analysis if the operator Comes_From_Source, since otherwise
5340 -- the operator was generated by the expander, and all such operators
5341 -- always refer to the operators in package Standard.
5343 if Comes_From_Source (N) then
5345 F : constant Entity_Id := First_Formal (Op_Id);
5348 -- Verify that Op_Id is a visible unary function. Note that since
5349 -- we know Op_Id is overloaded, potentially use visible means use
5350 -- visible for sure (RM 9.4(11)).
5352 if Ekind (Op_Id) = E_Function
5353 and then No (Next_Formal (F))
5354 and then (Is_Immediately_Visible (Op_Id)
5355 or else Is_Potentially_Use_Visible (Op_Id))
5356 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
5358 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5362 end Analyze_User_Defined_Unary_Op;
5364 ---------------------------
5365 -- Check_Arithmetic_Pair --
5366 ---------------------------
5368 procedure Check_Arithmetic_Pair
5369 (T1, T2 : Entity_Id;
5373 Op_Name : constant Name_Id := Chars (Op_Id);
5375 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
5376 -- Check whether the fixed-point type Typ has a user-defined operator
5377 -- (multiplication or division) that should hide the corresponding
5378 -- predefined operator. Used to implement Ada 2005 AI-264, to make
5379 -- such operators more visible and therefore useful.
5381 -- If the name of the operation is an expanded name with prefix
5382 -- Standard, the predefined universal fixed operator is available,
5383 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
5385 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
5386 -- Get specific type (i.e. non-universal type if there is one)
5392 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
5393 Bas : constant Entity_Id := Base_Type (Typ);
5399 -- If the universal_fixed operation is given explicitly the rule
5400 -- concerning primitive operations of the type do not apply.
5402 if Nkind (N) = N_Function_Call
5403 and then Nkind (Name (N)) = N_Expanded_Name
5404 and then Entity (Prefix (Name (N))) = Standard_Standard
5409 -- The operation is treated as primitive if it is declared in the
5410 -- same scope as the type, and therefore on the same entity chain.
5412 Ent := Next_Entity (Typ);
5413 while Present (Ent) loop
5414 if Chars (Ent) = Chars (Op) then
5415 F1 := First_Formal (Ent);
5416 F2 := Next_Formal (F1);
5418 -- The operation counts as primitive if either operand or
5419 -- result are of the given base type, and both operands are
5420 -- fixed point types.
5422 if (Base_Type (Etype (F1)) = Bas
5423 and then Is_Fixed_Point_Type (Etype (F2)))
5426 (Base_Type (Etype (F2)) = Bas
5427 and then Is_Fixed_Point_Type (Etype (F1)))
5430 (Base_Type (Etype (Ent)) = Bas
5431 and then Is_Fixed_Point_Type (Etype (F1))
5432 and then Is_Fixed_Point_Type (Etype (F2)))
5448 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
5450 if T1 = Universal_Integer or else T1 = Universal_Real then
5451 return Base_Type (T2);
5453 return Base_Type (T1);
5457 -- Start of processing for Check_Arithmetic_Pair
5460 if Nam_In (Op_Name, Name_Op_Add, Name_Op_Subtract) then
5461 if Is_Numeric_Type (T1)
5462 and then Is_Numeric_Type (T2)
5463 and then (Covers (T1 => T1, T2 => T2)
5465 Covers (T1 => T2, T2 => T1))
5467 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5470 elsif Nam_In (Op_Name, Name_Op_Multiply, Name_Op_Divide) then
5471 if Is_Fixed_Point_Type (T1)
5472 and then (Is_Fixed_Point_Type (T2) or else T2 = Universal_Real)
5474 -- If Treat_Fixed_As_Integer is set then the Etype is already set
5475 -- and no further processing is required (this is the case of an
5476 -- operator constructed by Exp_Fixd for a fixed point operation)
5477 -- Otherwise add one interpretation with universal fixed result
5478 -- If the operator is given in functional notation, it comes
5479 -- from source and Fixed_As_Integer cannot apply.
5481 if (Nkind (N) not in N_Op
5482 or else not Treat_Fixed_As_Integer (N))
5484 (not Has_Fixed_Op (T1, Op_Id)
5485 or else Nkind (Parent (N)) = N_Type_Conversion)
5487 Add_One_Interp (N, Op_Id, Universal_Fixed);
5490 elsif Is_Fixed_Point_Type (T2)
5491 and then (Nkind (N) not in N_Op
5492 or else not Treat_Fixed_As_Integer (N))
5493 and then T1 = Universal_Real
5495 (not Has_Fixed_Op (T1, Op_Id)
5496 or else Nkind (Parent (N)) = N_Type_Conversion)
5498 Add_One_Interp (N, Op_Id, Universal_Fixed);
5500 elsif Is_Numeric_Type (T1)
5501 and then Is_Numeric_Type (T2)
5502 and then (Covers (T1 => T1, T2 => T2)
5504 Covers (T1 => T2, T2 => T1))
5506 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5508 elsif Is_Fixed_Point_Type (T1)
5509 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5510 or else T2 = Universal_Integer)
5512 Add_One_Interp (N, Op_Id, T1);
5514 elsif T2 = Universal_Real
5515 and then Base_Type (T1) = Base_Type (Standard_Integer)
5516 and then Op_Name = Name_Op_Multiply
5518 Add_One_Interp (N, Op_Id, Any_Fixed);
5520 elsif T1 = Universal_Real
5521 and then Base_Type (T2) = Base_Type (Standard_Integer)
5523 Add_One_Interp (N, Op_Id, Any_Fixed);
5525 elsif Is_Fixed_Point_Type (T2)
5526 and then (Base_Type (T1) = Base_Type (Standard_Integer)
5527 or else T1 = Universal_Integer)
5528 and then Op_Name = Name_Op_Multiply
5530 Add_One_Interp (N, Op_Id, T2);
5532 elsif T1 = Universal_Real and then T2 = Universal_Integer then
5533 Add_One_Interp (N, Op_Id, T1);
5535 elsif T2 = Universal_Real
5536 and then T1 = Universal_Integer
5537 and then Op_Name = Name_Op_Multiply
5539 Add_One_Interp (N, Op_Id, T2);
5542 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
5544 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
5545 -- set does not require any special processing, since the Etype is
5546 -- already set (case of operation constructed by Exp_Fixed).
5548 if Is_Integer_Type (T1)
5549 and then (Covers (T1 => T1, T2 => T2)
5551 Covers (T1 => T2, T2 => T1))
5553 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5556 elsif Op_Name = Name_Op_Expon then
5557 if Is_Numeric_Type (T1)
5558 and then not Is_Fixed_Point_Type (T1)
5559 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5560 or else T2 = Universal_Integer)
5562 Add_One_Interp (N, Op_Id, Base_Type (T1));
5565 else pragma Assert (Nkind (N) in N_Op_Shift);
5567 -- If not one of the predefined operators, the node may be one
5568 -- of the intrinsic functions. Its kind is always specific, and
5569 -- we can use it directly, rather than the name of the operation.
5571 if Is_Integer_Type (T1)
5572 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5573 or else T2 = Universal_Integer)
5575 Add_One_Interp (N, Op_Id, Base_Type (T1));
5578 end Check_Arithmetic_Pair;
5580 -------------------------------
5581 -- Check_Misspelled_Selector --
5582 -------------------------------
5584 procedure Check_Misspelled_Selector
5585 (Prefix : Entity_Id;
5588 Max_Suggestions : constant := 2;
5589 Nr_Of_Suggestions : Natural := 0;
5591 Suggestion_1 : Entity_Id := Empty;
5592 Suggestion_2 : Entity_Id := Empty;
5597 -- All the components of the prefix of selector Sel are matched against
5598 -- Sel and a count is maintained of possible misspellings. When at
5599 -- the end of the analysis there are one or two (not more) possible
5600 -- misspellings, these misspellings will be suggested as possible
5603 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
5605 -- Concurrent types should be handled as well ???
5610 Comp := First_Entity (Prefix);
5611 while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
5612 if Is_Visible_Component (Comp) then
5613 if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
5614 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
5616 case Nr_Of_Suggestions is
5617 when 1 => Suggestion_1 := Comp;
5618 when 2 => Suggestion_2 := Comp;
5619 when others => exit;
5624 Comp := Next_Entity (Comp);
5627 -- Report at most two suggestions
5629 if Nr_Of_Suggestions = 1 then
5630 Error_Msg_NE -- CODEFIX
5631 ("\possible misspelling of&", Sel, Suggestion_1);
5633 elsif Nr_Of_Suggestions = 2 then
5634 Error_Msg_Node_2 := Suggestion_2;
5635 Error_Msg_NE -- CODEFIX
5636 ("\possible misspelling of& or&", Sel, Suggestion_1);
5638 end Check_Misspelled_Selector;
5640 ----------------------
5641 -- Defined_In_Scope --
5642 ----------------------
5644 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
5646 S1 : constant Entity_Id := Scope (Base_Type (T));
5649 or else (S1 = System_Aux_Id and then S = Scope (S1));
5650 end Defined_In_Scope;
5656 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
5662 Void_Interp_Seen : Boolean := False;
5665 pragma Warnings (Off, Boolean);
5668 if Ada_Version >= Ada_2005 then
5669 Actual := First_Actual (N);
5670 while Present (Actual) loop
5672 -- Ada 2005 (AI-50217): Post an error in case of premature
5673 -- usage of an entity from the limited view.
5675 if not Analyzed (Etype (Actual))
5676 and then From_Limited_With (Etype (Actual))
5678 Error_Msg_Qual_Level := 1;
5680 ("missing with_clause for scope of imported type&",
5681 Actual, Etype (Actual));
5682 Error_Msg_Qual_Level := 0;
5685 Next_Actual (Actual);
5689 -- Analyze each candidate call again, with full error reporting
5693 ("no candidate interpretations match the actuals:!", Nam);
5694 Err_Mode := All_Errors_Mode;
5695 All_Errors_Mode := True;
5697 -- If this is a call to an operation of a concurrent type,
5698 -- the failed interpretations have been removed from the
5699 -- name. Recover them to provide full diagnostics.
5701 if Nkind (Parent (Nam)) = N_Selected_Component then
5702 Set_Entity (Nam, Empty);
5703 New_Nam := New_Copy_Tree (Parent (Nam));
5704 Set_Is_Overloaded (New_Nam, False);
5705 Set_Is_Overloaded (Selector_Name (New_Nam), False);
5706 Set_Parent (New_Nam, Parent (Parent (Nam)));
5707 Analyze_Selected_Component (New_Nam);
5708 Get_First_Interp (Selector_Name (New_Nam), X, It);
5710 Get_First_Interp (Nam, X, It);
5713 while Present (It.Nam) loop
5714 if Etype (It.Nam) = Standard_Void_Type then
5715 Void_Interp_Seen := True;
5718 Analyze_One_Call (N, It.Nam, True, Success);
5719 Get_Next_Interp (X, It);
5722 if Nkind (N) = N_Function_Call then
5723 Get_First_Interp (Nam, X, It);
5724 while Present (It.Nam) loop
5725 if Ekind_In (It.Nam, E_Function, E_Operator) then
5728 Get_Next_Interp (X, It);
5732 -- If all interpretations are procedures, this deserves a
5733 -- more precise message. Ditto if this appears as the prefix
5734 -- of a selected component, which may be a lexical error.
5737 ("\context requires function call, found procedure name", Nam);
5739 if Nkind (Parent (N)) = N_Selected_Component
5740 and then N = Prefix (Parent (N))
5742 Error_Msg_N -- CODEFIX
5743 ("\period should probably be semicolon", Parent (N));
5746 elsif Nkind (N) = N_Procedure_Call_Statement
5747 and then not Void_Interp_Seen
5750 "\function name found in procedure call", Nam);
5753 All_Errors_Mode := Err_Mode;
5756 ---------------------------
5757 -- Find_Arithmetic_Types --
5758 ---------------------------
5760 procedure Find_Arithmetic_Types
5765 Index1 : Interp_Index;
5766 Index2 : Interp_Index;
5770 procedure Check_Right_Argument (T : Entity_Id);
5771 -- Check right operand of operator
5773 --------------------------
5774 -- Check_Right_Argument --
5775 --------------------------
5777 procedure Check_Right_Argument (T : Entity_Id) is
5779 if not Is_Overloaded (R) then
5780 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
5782 Get_First_Interp (R, Index2, It2);
5783 while Present (It2.Typ) loop
5784 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
5785 Get_Next_Interp (Index2, It2);
5788 end Check_Right_Argument;
5790 -- Start of processing for Find_Arithmetic_Types
5793 if not Is_Overloaded (L) then
5794 Check_Right_Argument (Etype (L));
5797 Get_First_Interp (L, Index1, It1);
5798 while Present (It1.Typ) loop
5799 Check_Right_Argument (It1.Typ);
5800 Get_Next_Interp (Index1, It1);
5804 end Find_Arithmetic_Types;
5806 ------------------------
5807 -- Find_Boolean_Types --
5808 ------------------------
5810 procedure Find_Boolean_Types
5815 Index : Interp_Index;
5818 procedure Check_Numeric_Argument (T : Entity_Id);
5819 -- Special case for logical operations one of whose operands is an
5820 -- integer literal. If both are literal the result is any modular type.
5822 ----------------------------
5823 -- Check_Numeric_Argument --
5824 ----------------------------
5826 procedure Check_Numeric_Argument (T : Entity_Id) is
5828 if T = Universal_Integer then
5829 Add_One_Interp (N, Op_Id, Any_Modular);
5831 elsif Is_Modular_Integer_Type (T) then
5832 Add_One_Interp (N, Op_Id, T);
5834 end Check_Numeric_Argument;
5836 -- Start of processing for Find_Boolean_Types
5839 if not Is_Overloaded (L) then
5840 if Etype (L) = Universal_Integer
5841 or else Etype (L) = Any_Modular
5843 if not Is_Overloaded (R) then
5844 Check_Numeric_Argument (Etype (R));
5847 Get_First_Interp (R, Index, It);
5848 while Present (It.Typ) loop
5849 Check_Numeric_Argument (It.Typ);
5850 Get_Next_Interp (Index, It);
5854 -- If operands are aggregates, we must assume that they may be
5855 -- boolean arrays, and leave disambiguation for the second pass.
5856 -- If only one is an aggregate, verify that the other one has an
5857 -- interpretation as a boolean array
5859 elsif Nkind (L) = N_Aggregate then
5860 if Nkind (R) = N_Aggregate then
5861 Add_One_Interp (N, Op_Id, Etype (L));
5863 elsif not Is_Overloaded (R) then
5864 if Valid_Boolean_Arg (Etype (R)) then
5865 Add_One_Interp (N, Op_Id, Etype (R));
5869 Get_First_Interp (R, Index, It);
5870 while Present (It.Typ) loop
5871 if Valid_Boolean_Arg (It.Typ) then
5872 Add_One_Interp (N, Op_Id, It.Typ);
5875 Get_Next_Interp (Index, It);
5879 elsif Valid_Boolean_Arg (Etype (L))
5880 and then Has_Compatible_Type (R, Etype (L))
5882 Add_One_Interp (N, Op_Id, Etype (L));
5886 Get_First_Interp (L, Index, It);
5887 while Present (It.Typ) loop
5888 if Valid_Boolean_Arg (It.Typ)
5889 and then Has_Compatible_Type (R, It.Typ)
5891 Add_One_Interp (N, Op_Id, It.Typ);
5894 Get_Next_Interp (Index, It);
5897 end Find_Boolean_Types;
5899 ---------------------------
5900 -- Find_Comparison_Types --
5901 ---------------------------
5903 procedure Find_Comparison_Types
5908 Index : Interp_Index;
5910 Found : Boolean := False;
5913 Scop : Entity_Id := Empty;
5915 procedure Try_One_Interp (T1 : Entity_Id);
5916 -- Routine to try one proposed interpretation. Note that the context
5917 -- of the operator plays no role in resolving the arguments, so that
5918 -- if there is more than one interpretation of the operands that is
5919 -- compatible with comparison, the operation is ambiguous.
5921 --------------------
5922 -- Try_One_Interp --
5923 --------------------
5925 procedure Try_One_Interp (T1 : Entity_Id) is
5928 -- If the operator is an expanded name, then the type of the operand
5929 -- must be defined in the corresponding scope. If the type is
5930 -- universal, the context will impose the correct type.
5933 and then not Defined_In_Scope (T1, Scop)
5934 and then T1 /= Universal_Integer
5935 and then T1 /= Universal_Real
5936 and then T1 /= Any_String
5937 and then T1 /= Any_Composite
5942 if Valid_Comparison_Arg (T1) and then Has_Compatible_Type (R, T1) then
5943 if Found and then Base_Type (T1) /= Base_Type (T_F) then
5944 It := Disambiguate (L, I_F, Index, Any_Type);
5946 if It = No_Interp then
5947 Ambiguous_Operands (N);
5948 Set_Etype (L, Any_Type);
5962 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
5967 -- Start of processing for Find_Comparison_Types
5970 -- If left operand is aggregate, the right operand has to
5971 -- provide a usable type for it.
5973 if Nkind (L) = N_Aggregate and then Nkind (R) /= N_Aggregate then
5974 Find_Comparison_Types (L => R, R => L, Op_Id => Op_Id, N => N);
5978 if Nkind (N) = N_Function_Call
5979 and then Nkind (Name (N)) = N_Expanded_Name
5981 Scop := Entity (Prefix (Name (N)));
5983 -- The prefix may be a package renaming, and the subsequent test
5984 -- requires the original package.
5986 if Ekind (Scop) = E_Package
5987 and then Present (Renamed_Entity (Scop))
5989 Scop := Renamed_Entity (Scop);
5990 Set_Entity (Prefix (Name (N)), Scop);
5994 if not Is_Overloaded (L) then
5995 Try_One_Interp (Etype (L));
5998 Get_First_Interp (L, Index, It);
5999 while Present (It.Typ) loop
6000 Try_One_Interp (It.Typ);
6001 Get_Next_Interp (Index, It);
6004 end Find_Comparison_Types;
6006 ----------------------------------------
6007 -- Find_Non_Universal_Interpretations --
6008 ----------------------------------------
6010 procedure Find_Non_Universal_Interpretations
6016 Index : Interp_Index;
6020 if T1 = Universal_Integer or else T1 = Universal_Real
6022 -- If the left operand of an equality operator is null, the visibility
6023 -- of the operator must be determined from the interpretation of the
6024 -- right operand. This processing must be done for Any_Access, which
6025 -- is the internal representation of the type of the literal null.
6027 or else T1 = Any_Access
6029 if not Is_Overloaded (R) then
6030 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
6032 Get_First_Interp (R, Index, It);
6033 while Present (It.Typ) loop
6034 if Covers (It.Typ, T1) then
6036 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
6039 Get_Next_Interp (Index, It);
6043 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
6045 end Find_Non_Universal_Interpretations;
6047 ------------------------------
6048 -- Find_Concatenation_Types --
6049 ------------------------------
6051 procedure Find_Concatenation_Types
6056 Op_Type : constant Entity_Id := Etype (Op_Id);
6059 if Is_Array_Type (Op_Type)
6060 and then not Is_Limited_Type (Op_Type)
6062 and then (Has_Compatible_Type (L, Op_Type)
6064 Has_Compatible_Type (L, Component_Type (Op_Type)))
6066 and then (Has_Compatible_Type (R, Op_Type)
6068 Has_Compatible_Type (R, Component_Type (Op_Type)))
6070 Add_One_Interp (N, Op_Id, Op_Type);
6072 end Find_Concatenation_Types;
6074 -------------------------
6075 -- Find_Equality_Types --
6076 -------------------------
6078 procedure Find_Equality_Types
6083 Index : Interp_Index;
6085 Found : Boolean := False;
6088 Scop : Entity_Id := Empty;
6090 procedure Try_One_Interp (T1 : Entity_Id);
6091 -- The context of the equality operator plays no role in resolving the
6092 -- arguments, so that if there is more than one interpretation of the
6093 -- operands that is compatible with equality, the construct is ambiguous
6094 -- and an error can be emitted now, after trying to disambiguate, i.e.
6095 -- applying preference rules.
6097 --------------------
6098 -- Try_One_Interp --
6099 --------------------
6101 procedure Try_One_Interp (T1 : Entity_Id) is
6102 Bas : constant Entity_Id := Base_Type (T1);
6105 -- If the operator is an expanded name, then the type of the operand
6106 -- must be defined in the corresponding scope. If the type is
6107 -- universal, the context will impose the correct type. An anonymous
6108 -- type for a 'Access reference is also universal in this sense, as
6109 -- the actual type is obtained from context.
6111 -- In Ada 2005, the equality operator for anonymous access types
6112 -- is declared in Standard, and preference rules apply to it.
6114 if Present (Scop) then
6115 if Defined_In_Scope (T1, Scop)
6116 or else T1 = Universal_Integer
6117 or else T1 = Universal_Real
6118 or else T1 = Any_Access
6119 or else T1 = Any_String
6120 or else T1 = Any_Composite
6121 or else (Ekind (T1) = E_Access_Subprogram_Type
6122 and then not Comes_From_Source (T1))
6126 elsif Ekind (T1) = E_Anonymous_Access_Type
6127 and then Scop = Standard_Standard
6132 -- The scope does not contain an operator for the type
6137 -- If we have infix notation, the operator must be usable. Within
6138 -- an instance, if the type is already established we know it is
6139 -- correct. If an operand is universal it is compatible with any
6142 elsif In_Open_Scopes (Scope (Bas))
6143 or else Is_Potentially_Use_Visible (Bas)
6144 or else In_Use (Bas)
6145 or else (In_Use (Scope (Bas)) and then not Is_Hidden (Bas))
6147 -- In an instance, the type may have been immediately visible.
6148 -- Either the types are compatible, or one operand is universal
6149 -- (numeric or null).
6151 or else (In_Instance
6153 (First_Subtype (T1) = First_Subtype (Etype (R))
6154 or else Nkind (R) = N_Null
6156 (Is_Numeric_Type (T1)
6157 and then Is_Universal_Numeric_Type (Etype (R)))))
6159 -- In Ada 2005, the equality on anonymous access types is declared
6160 -- in Standard, and is always visible.
6162 or else Ekind (T1) = E_Anonymous_Access_Type
6167 -- Save candidate type for subsequent error message, if any
6169 if not Is_Limited_Type (T1) then
6170 Candidate_Type := T1;
6176 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
6177 -- Do not allow anonymous access types in equality operators.
6179 if Ada_Version < Ada_2005
6180 and then Ekind (T1) = E_Anonymous_Access_Type
6185 -- If the right operand has a type compatible with T1, check for an
6186 -- acceptable interpretation, unless T1 is limited (no predefined
6187 -- equality available), or this is use of a "/=" for a tagged type.
6188 -- In the latter case, possible interpretations of equality need
6189 -- to be considered, we don't want the default inequality declared
6190 -- in Standard to be chosen, and the "/=" will be rewritten as a
6191 -- negation of "=" (see the end of Analyze_Equality_Op). This ensures
6192 -- that rewriting happens during analysis rather than being
6193 -- delayed until expansion (this is needed for ASIS, which only sees
6194 -- the unexpanded tree). Note that if the node is N_Op_Ne, but Op_Id
6195 -- is Name_Op_Eq then we still proceed with the interpretation,
6196 -- because that indicates the potential rewriting case where the
6197 -- interpretation to consider is actually "=" and the node may be
6198 -- about to be rewritten by Analyze_Equality_Op.
6200 if T1 /= Standard_Void_Type
6201 and then Has_Compatible_Type (R, T1)
6204 ((not Is_Limited_Type (T1)
6205 and then not Is_Limited_Composite (T1))
6209 and then not Is_Limited_Type (Component_Type (T1))
6210 and then Available_Full_View_Of_Component (T1)))
6213 (Nkind (N) /= N_Op_Ne
6214 or else not Is_Tagged_Type (T1)
6215 or else Chars (Op_Id) = Name_Op_Eq)
6218 and then Base_Type (T1) /= Base_Type (T_F)
6220 It := Disambiguate (L, I_F, Index, Any_Type);
6222 if It = No_Interp then
6223 Ambiguous_Operands (N);
6224 Set_Etype (L, Any_Type);
6237 if not Analyzed (L) then
6241 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
6243 -- Case of operator was not visible, Etype still set to Any_Type
6245 if Etype (N) = Any_Type then
6249 elsif Scop = Standard_Standard
6250 and then Ekind (T1) = E_Anonymous_Access_Type
6256 -- Start of processing for Find_Equality_Types
6259 -- If left operand is aggregate, the right operand has to
6260 -- provide a usable type for it.
6262 if Nkind (L) = N_Aggregate
6263 and then Nkind (R) /= N_Aggregate
6265 Find_Equality_Types (L => R, R => L, Op_Id => Op_Id, N => N);
6269 if Nkind (N) = N_Function_Call
6270 and then Nkind (Name (N)) = N_Expanded_Name
6272 Scop := Entity (Prefix (Name (N)));
6274 -- The prefix may be a package renaming, and the subsequent test
6275 -- requires the original package.
6277 if Ekind (Scop) = E_Package
6278 and then Present (Renamed_Entity (Scop))
6280 Scop := Renamed_Entity (Scop);
6281 Set_Entity (Prefix (Name (N)), Scop);
6285 if not Is_Overloaded (L) then
6286 Try_One_Interp (Etype (L));
6289 Get_First_Interp (L, Index, It);
6290 while Present (It.Typ) loop
6291 Try_One_Interp (It.Typ);
6292 Get_Next_Interp (Index, It);
6295 end Find_Equality_Types;
6297 -------------------------
6298 -- Find_Negation_Types --
6299 -------------------------
6301 procedure Find_Negation_Types
6306 Index : Interp_Index;
6310 if not Is_Overloaded (R) then
6311 if Etype (R) = Universal_Integer then
6312 Add_One_Interp (N, Op_Id, Any_Modular);
6313 elsif Valid_Boolean_Arg (Etype (R)) then
6314 Add_One_Interp (N, Op_Id, Etype (R));
6318 Get_First_Interp (R, Index, It);
6319 while Present (It.Typ) loop
6320 if Valid_Boolean_Arg (It.Typ) then
6321 Add_One_Interp (N, Op_Id, It.Typ);
6324 Get_Next_Interp (Index, It);
6327 end Find_Negation_Types;
6329 ------------------------------
6330 -- Find_Primitive_Operation --
6331 ------------------------------
6333 function Find_Primitive_Operation (N : Node_Id) return Boolean is
6334 Obj : constant Node_Id := Prefix (N);
6335 Op : constant Node_Id := Selector_Name (N);
6342 Set_Etype (Op, Any_Type);
6344 if Is_Access_Type (Etype (Obj)) then
6345 Typ := Designated_Type (Etype (Obj));
6350 if Is_Class_Wide_Type (Typ) then
6351 Typ := Root_Type (Typ);
6354 Prims := Primitive_Operations (Typ);
6356 Prim := First_Elmt (Prims);
6357 while Present (Prim) loop
6358 if Chars (Node (Prim)) = Chars (Op) then
6359 Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
6360 Set_Etype (N, Etype (Node (Prim)));
6366 -- Now look for class-wide operations of the type or any of its
6367 -- ancestors by iterating over the homonyms of the selector.
6370 Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
6374 Hom := Current_Entity (Op);
6375 while Present (Hom) loop
6376 if (Ekind (Hom) = E_Procedure
6378 Ekind (Hom) = E_Function)
6379 and then Scope (Hom) = Scope (Typ)
6380 and then Present (First_Formal (Hom))
6382 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
6384 (Is_Access_Type (Etype (First_Formal (Hom)))
6386 Ekind (Etype (First_Formal (Hom))) =
6387 E_Anonymous_Access_Type
6390 (Designated_Type (Etype (First_Formal (Hom)))) =
6393 Add_One_Interp (Op, Hom, Etype (Hom));
6394 Set_Etype (N, Etype (Hom));
6397 Hom := Homonym (Hom);
6401 return Etype (Op) /= Any_Type;
6402 end Find_Primitive_Operation;
6404 ----------------------
6405 -- Find_Unary_Types --
6406 ----------------------
6408 procedure Find_Unary_Types
6413 Index : Interp_Index;
6417 if not Is_Overloaded (R) then
6418 if Is_Numeric_Type (Etype (R)) then
6420 -- In an instance a generic actual may be a numeric type even if
6421 -- the formal in the generic unit was not. In that case, the
6422 -- predefined operator was not a possible interpretation in the
6423 -- generic, and cannot be one in the instance, unless the operator
6424 -- is an actual of an instance.
6428 not Is_Numeric_Type (Corresponding_Generic_Type (Etype (R)))
6432 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
6437 Get_First_Interp (R, Index, It);
6438 while Present (It.Typ) loop
6439 if Is_Numeric_Type (It.Typ) then
6443 (Corresponding_Generic_Type (Etype (It.Typ)))
6448 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
6452 Get_Next_Interp (Index, It);
6455 end Find_Unary_Types;
6461 function Junk_Operand (N : Node_Id) return Boolean is
6465 if Error_Posted (N) then
6469 -- Get entity to be tested
6471 if Is_Entity_Name (N)
6472 and then Present (Entity (N))
6476 -- An odd case, a procedure name gets converted to a very peculiar
6477 -- function call, and here is where we detect this happening.
6479 elsif Nkind (N) = N_Function_Call
6480 and then Is_Entity_Name (Name (N))
6481 and then Present (Entity (Name (N)))
6485 -- Another odd case, there are at least some cases of selected
6486 -- components where the selected component is not marked as having
6487 -- an entity, even though the selector does have an entity
6489 elsif Nkind (N) = N_Selected_Component
6490 and then Present (Entity (Selector_Name (N)))
6492 Enode := Selector_Name (N);
6498 -- Now test the entity we got to see if it is a bad case
6500 case Ekind (Entity (Enode)) is
6504 ("package name cannot be used as operand", Enode);
6506 when Generic_Unit_Kind =>
6508 ("generic unit name cannot be used as operand", Enode);
6512 ("subtype name cannot be used as operand", Enode);
6516 ("entry name cannot be used as operand", Enode);
6520 ("procedure name cannot be used as operand", Enode);
6524 ("exception name cannot be used as operand", Enode);
6526 when E_Block | E_Label | E_Loop =>
6528 ("label name cannot be used as operand", Enode);
6538 --------------------
6539 -- Operator_Check --
6540 --------------------
6542 procedure Operator_Check (N : Node_Id) is
6544 Remove_Abstract_Operations (N);
6546 -- Test for case of no interpretation found for operator
6548 if Etype (N) = Any_Type then
6552 Op_Id : Entity_Id := Empty;
6555 R := Right_Opnd (N);
6557 if Nkind (N) in N_Binary_Op then
6563 -- If either operand has no type, then don't complain further,
6564 -- since this simply means that we have a propagated error.
6567 or else Etype (R) = Any_Type
6568 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
6570 -- For the rather unusual case where one of the operands is
6571 -- a Raise_Expression, whose initial type is Any_Type, use
6572 -- the type of the other operand.
6574 if Nkind (L) = N_Raise_Expression then
6575 Set_Etype (L, Etype (R));
6576 Set_Etype (N, Etype (R));
6578 elsif Nkind (R) = N_Raise_Expression then
6579 Set_Etype (R, Etype (L));
6580 Set_Etype (N, Etype (L));
6585 -- We explicitly check for the case of concatenation of component
6586 -- with component to avoid reporting spurious matching array types
6587 -- that might happen to be lurking in distant packages (such as
6588 -- run-time packages). This also prevents inconsistencies in the
6589 -- messages for certain ACVC B tests, which can vary depending on
6590 -- types declared in run-time interfaces. Another improvement when
6591 -- aggregates are present is to look for a well-typed operand.
6593 elsif Present (Candidate_Type)
6594 and then (Nkind (N) /= N_Op_Concat
6595 or else Is_Array_Type (Etype (L))
6596 or else Is_Array_Type (Etype (R)))
6598 if Nkind (N) = N_Op_Concat then
6599 if Etype (L) /= Any_Composite
6600 and then Is_Array_Type (Etype (L))
6602 Candidate_Type := Etype (L);
6604 elsif Etype (R) /= Any_Composite
6605 and then Is_Array_Type (Etype (R))
6607 Candidate_Type := Etype (R);
6611 Error_Msg_NE -- CODEFIX
6612 ("operator for} is not directly visible!",
6613 N, First_Subtype (Candidate_Type));
6616 U : constant Node_Id :=
6617 Cunit (Get_Source_Unit (Candidate_Type));
6619 if Unit_Is_Visible (U) then
6620 Error_Msg_N -- CODEFIX
6621 ("use clause would make operation legal!", N);
6623 Error_Msg_NE -- CODEFIX
6624 ("add with_clause and use_clause for&!",
6625 N, Defining_Entity (Unit (U)));
6630 -- If either operand is a junk operand (e.g. package name), then
6631 -- post appropriate error messages, but do not complain further.
6633 -- Note that the use of OR in this test instead of OR ELSE is
6634 -- quite deliberate, we may as well check both operands in the
6635 -- binary operator case.
6637 elsif Junk_Operand (R)
6638 or -- really mean OR here and not OR ELSE, see above
6639 (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
6643 -- If we have a logical operator, one of whose operands is
6644 -- Boolean, then we know that the other operand cannot resolve to
6645 -- Boolean (since we got no interpretations), but in that case we
6646 -- pretty much know that the other operand should be Boolean, so
6647 -- resolve it that way (generating an error).
6649 elsif Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor) then
6650 if Etype (L) = Standard_Boolean then
6651 Resolve (R, Standard_Boolean);
6653 elsif Etype (R) = Standard_Boolean then
6654 Resolve (L, Standard_Boolean);
6658 -- For an arithmetic operator or comparison operator, if one
6659 -- of the operands is numeric, then we know the other operand
6660 -- is not the same numeric type. If it is a non-numeric type,
6661 -- then probably it is intended to match the other operand.
6663 elsif Nkind_In (N, N_Op_Add,
6669 Nkind_In (N, N_Op_Lt,
6675 -- If Allow_Integer_Address is active, check whether the
6676 -- operation becomes legal after converting an operand.
6678 if Is_Numeric_Type (Etype (L))
6679 and then not Is_Numeric_Type (Etype (R))
6681 if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
6683 Unchecked_Convert_To (Etype (L), Relocate_Node (R)));
6685 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
6686 Analyze_Comparison_Op (N);
6688 Analyze_Arithmetic_Op (N);
6691 Resolve (R, Etype (L));
6696 elsif Is_Numeric_Type (Etype (R))
6697 and then not Is_Numeric_Type (Etype (L))
6699 if Address_Integer_Convert_OK (Etype (L), Etype (R)) then
6701 Unchecked_Convert_To (Etype (R), Relocate_Node (L)));
6703 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
6704 Analyze_Comparison_Op (N);
6706 Analyze_Arithmetic_Op (N);
6712 Resolve (L, Etype (R));
6717 elsif Allow_Integer_Address
6718 and then Is_Descendant_Of_Address (Etype (L))
6719 and then Is_Descendant_Of_Address (Etype (R))
6720 and then not Error_Posted (N)
6723 Addr_Type : constant Entity_Id := Etype (L);
6727 Unchecked_Convert_To (
6728 Standard_Integer, Relocate_Node (L)));
6730 Unchecked_Convert_To (
6731 Standard_Integer, Relocate_Node (R)));
6733 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
6734 Analyze_Comparison_Op (N);
6736 Analyze_Arithmetic_Op (N);
6739 -- If this is an operand in an enclosing arithmetic
6740 -- operation, Convert the result as an address so that
6741 -- arithmetic folding of address can continue.
6743 if Nkind (Parent (N)) in N_Op then
6745 Unchecked_Convert_To (Addr_Type, Relocate_Node (N)));
6752 -- Comparisons on A'Access are common enough to deserve a
6755 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne)
6756 and then Ekind (Etype (L)) = E_Access_Attribute_Type
6757 and then Ekind (Etype (R)) = E_Access_Attribute_Type
6760 ("two access attributes cannot be compared directly", N);
6762 ("\use qualified expression for one of the operands",
6766 -- Another one for C programmers
6768 elsif Nkind (N) = N_Op_Concat
6769 and then Valid_Boolean_Arg (Etype (L))
6770 and then Valid_Boolean_Arg (Etype (R))
6772 Error_Msg_N ("invalid operands for concatenation", N);
6773 Error_Msg_N -- CODEFIX
6774 ("\maybe AND was meant", N);
6777 -- A special case for comparison of access parameter with null
6779 elsif Nkind (N) = N_Op_Eq
6780 and then Is_Entity_Name (L)
6781 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
6782 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
6784 and then Nkind (R) = N_Null
6786 Error_Msg_N ("access parameter is not allowed to be null", L);
6787 Error_Msg_N ("\(call would raise Constraint_Error)", L);
6790 -- Another special case for exponentiation, where the right
6791 -- operand must be Natural, independently of the base.
6793 elsif Nkind (N) = N_Op_Expon
6794 and then Is_Numeric_Type (Etype (L))
6795 and then not Is_Overloaded (R)
6797 First_Subtype (Base_Type (Etype (R))) /= Standard_Integer
6798 and then Base_Type (Etype (R)) /= Universal_Integer
6800 if Ada_Version >= Ada_2012
6801 and then Has_Dimension_System (Etype (L))
6804 ("exponent for dimensioned type must be a rational" &
6805 ", found}", R, Etype (R));
6808 ("exponent must be of type Natural, found}", R, Etype (R));
6813 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
6814 if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
6816 Unchecked_Convert_To (Etype (L), Relocate_Node (R)));
6817 Analyze_Equality_Op (N);
6822 -- If we fall through then just give general message. Note that in
6823 -- the following messages, if the operand is overloaded we choose
6824 -- an arbitrary type to complain about, but that is probably more
6825 -- useful than not giving a type at all.
6827 if Nkind (N) in N_Unary_Op then
6828 Error_Msg_Node_2 := Etype (R);
6829 Error_Msg_N ("operator& not defined for}", N);
6833 if Nkind (N) in N_Binary_Op then
6834 if not Is_Overloaded (L)
6835 and then not Is_Overloaded (R)
6836 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
6838 Error_Msg_Node_2 := First_Subtype (Etype (R));
6839 Error_Msg_N ("there is no applicable operator& for}", N);
6842 -- Another attempt to find a fix: one of the candidate
6843 -- interpretations may not be use-visible. This has
6844 -- already been checked for predefined operators, so
6845 -- we examine only user-defined functions.
6847 Op_Id := Get_Name_Entity_Id (Chars (N));
6849 while Present (Op_Id) loop
6850 if Ekind (Op_Id) /= E_Operator
6851 and then Is_Overloadable (Op_Id)
6853 if not Is_Immediately_Visible (Op_Id)
6854 and then not In_Use (Scope (Op_Id))
6855 and then not Is_Abstract_Subprogram (Op_Id)
6856 and then not Is_Hidden (Op_Id)
6857 and then Ekind (Scope (Op_Id)) = E_Package
6860 (L, Etype (First_Formal (Op_Id)))
6862 (Next_Formal (First_Formal (Op_Id)))
6866 Etype (Next_Formal (First_Formal (Op_Id))))
6869 ("No legal interpretation for operator&", N);
6871 ("\use clause on& would make operation legal",
6877 Op_Id := Homonym (Op_Id);
6881 Error_Msg_N ("invalid operand types for operator&", N);
6883 if Nkind (N) /= N_Op_Concat then
6884 Error_Msg_NE ("\left operand has}!", N, Etype (L));
6885 Error_Msg_NE ("\right operand has}!", N, Etype (R));
6887 -- For concatenation operators it is more difficult to
6888 -- determine which is the wrong operand. It is worth
6889 -- flagging explicitly an access type, for those who
6890 -- might think that a dereference happens here.
6892 elsif Is_Access_Type (Etype (L)) then
6893 Error_Msg_N ("\left operand is access type", N);
6895 elsif Is_Access_Type (Etype (R)) then
6896 Error_Msg_N ("\right operand is access type", N);
6906 -----------------------------------------
6907 -- Process_Implicit_Dereference_Prefix --
6908 -----------------------------------------
6910 function Process_Implicit_Dereference_Prefix
6912 P : Entity_Id) return Entity_Id
6915 Typ : constant Entity_Id := Designated_Type (Etype (P));
6919 and then (Operating_Mode = Check_Semantics or else not Expander_Active)
6921 -- We create a dummy reference to E to ensure that the reference is
6922 -- not considered as part of an assignment (an implicit dereference
6923 -- can never assign to its prefix). The Comes_From_Source attribute
6924 -- needs to be propagated for accurate warnings.
6926 Ref := New_Occurrence_Of (E, Sloc (P));
6927 Set_Comes_From_Source (Ref, Comes_From_Source (P));
6928 Generate_Reference (E, Ref);
6931 -- An implicit dereference is a legal occurrence of an incomplete type
6932 -- imported through a limited_with clause, if the full view is visible.
6934 if From_Limited_With (Typ)
6935 and then not From_Limited_With (Scope (Typ))
6937 (Is_Immediately_Visible (Scope (Typ))
6939 (Is_Child_Unit (Scope (Typ))
6940 and then Is_Visible_Lib_Unit (Scope (Typ))))
6942 return Available_View (Typ);
6946 end Process_Implicit_Dereference_Prefix;
6948 --------------------------------
6949 -- Remove_Abstract_Operations --
6950 --------------------------------
6952 procedure Remove_Abstract_Operations (N : Node_Id) is
6953 Abstract_Op : Entity_Id := Empty;
6954 Address_Descendant : Boolean := False;
6958 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
6959 -- activate this if either extensions are enabled, or if the abstract
6960 -- operation in question comes from a predefined file. This latter test
6961 -- allows us to use abstract to make operations invisible to users. In
6962 -- particular, if type Address is non-private and abstract subprograms
6963 -- are used to hide its operators, they will be truly hidden.
6965 type Operand_Position is (First_Op, Second_Op);
6966 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
6968 procedure Remove_Address_Interpretations (Op : Operand_Position);
6969 -- Ambiguities may arise when the operands are literal and the address
6970 -- operations in s-auxdec are visible. In that case, remove the
6971 -- interpretation of a literal as Address, to retain the semantics
6972 -- of Address as a private type.
6974 ------------------------------------
6975 -- Remove_Address_Interpretations --
6976 ------------------------------------
6978 procedure Remove_Address_Interpretations (Op : Operand_Position) is
6982 if Is_Overloaded (N) then
6983 Get_First_Interp (N, I, It);
6984 while Present (It.Nam) loop
6985 Formal := First_Entity (It.Nam);
6987 if Op = Second_Op then
6988 Formal := Next_Entity (Formal);
6991 if Is_Descendant_Of_Address (Etype (Formal)) then
6992 Address_Descendant := True;
6996 Get_Next_Interp (I, It);
6999 end Remove_Address_Interpretations;
7001 -- Start of processing for Remove_Abstract_Operations
7004 if Is_Overloaded (N) then
7005 if Debug_Flag_V then
7006 Write_Str ("Remove_Abstract_Operations: ");
7007 Write_Overloads (N);
7010 Get_First_Interp (N, I, It);
7012 while Present (It.Nam) loop
7013 if Is_Overloadable (It.Nam)
7014 and then Is_Abstract_Subprogram (It.Nam)
7015 and then not Is_Dispatching_Operation (It.Nam)
7017 Abstract_Op := It.Nam;
7019 if Is_Descendant_Of_Address (It.Typ) then
7020 Address_Descendant := True;
7024 -- In Ada 2005, this operation does not participate in overload
7025 -- resolution. If the operation is defined in a predefined
7026 -- unit, it is one of the operations declared abstract in some
7027 -- variants of System, and it must be removed as well.
7029 elsif Ada_Version >= Ada_2005
7030 or else Is_Predefined_File_Name
7031 (Unit_File_Name (Get_Source_Unit (It.Nam)))
7038 Get_Next_Interp (I, It);
7041 if No (Abstract_Op) then
7043 -- If some interpretation yields an integer type, it is still
7044 -- possible that there are address interpretations. Remove them
7045 -- if one operand is a literal, to avoid spurious ambiguities
7046 -- on systems where Address is a visible integer type.
7048 if Is_Overloaded (N)
7049 and then Nkind (N) in N_Op
7050 and then Is_Integer_Type (Etype (N))
7052 if Nkind (N) in N_Binary_Op then
7053 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
7054 Remove_Address_Interpretations (Second_Op);
7056 elsif Nkind (Right_Opnd (N)) = N_Integer_Literal then
7057 Remove_Address_Interpretations (First_Op);
7062 elsif Nkind (N) in N_Op then
7064 -- Remove interpretations that treat literals as addresses. This
7065 -- is never appropriate, even when Address is defined as a visible
7066 -- Integer type. The reason is that we would really prefer Address
7067 -- to behave as a private type, even in this case. If Address is a
7068 -- visible integer type, we get lots of overload ambiguities.
7070 if Nkind (N) in N_Binary_Op then
7072 U1 : constant Boolean :=
7073 Present (Universal_Interpretation (Right_Opnd (N)));
7074 U2 : constant Boolean :=
7075 Present (Universal_Interpretation (Left_Opnd (N)));
7079 Remove_Address_Interpretations (Second_Op);
7083 Remove_Address_Interpretations (First_Op);
7086 if not (U1 and U2) then
7088 -- Remove corresponding predefined operator, which is
7089 -- always added to the overload set.
7091 Get_First_Interp (N, I, It);
7092 while Present (It.Nam) loop
7093 if Scope (It.Nam) = Standard_Standard
7094 and then Base_Type (It.Typ) =
7095 Base_Type (Etype (Abstract_Op))
7100 Get_Next_Interp (I, It);
7103 elsif Is_Overloaded (N)
7104 and then Present (Univ_Type)
7106 -- If both operands have a universal interpretation,
7107 -- it is still necessary to remove interpretations that
7108 -- yield Address. Any remaining ambiguities will be
7109 -- removed in Disambiguate.
7111 Get_First_Interp (N, I, It);
7112 while Present (It.Nam) loop
7113 if Is_Descendant_Of_Address (It.Typ) then
7116 elsif not Is_Type (It.Nam) then
7117 Set_Entity (N, It.Nam);
7120 Get_Next_Interp (I, It);
7126 elsif Nkind (N) = N_Function_Call
7128 (Nkind (Name (N)) = N_Operator_Symbol
7130 (Nkind (Name (N)) = N_Expanded_Name
7132 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
7136 Arg1 : constant Node_Id := First (Parameter_Associations (N));
7137 U1 : constant Boolean :=
7138 Present (Universal_Interpretation (Arg1));
7139 U2 : constant Boolean :=
7140 Present (Next (Arg1)) and then
7141 Present (Universal_Interpretation (Next (Arg1)));
7145 Remove_Address_Interpretations (First_Op);
7149 Remove_Address_Interpretations (Second_Op);
7152 if not (U1 and U2) then
7153 Get_First_Interp (N, I, It);
7154 while Present (It.Nam) loop
7155 if Scope (It.Nam) = Standard_Standard
7156 and then It.Typ = Base_Type (Etype (Abstract_Op))
7161 Get_Next_Interp (I, It);
7167 -- If the removal has left no valid interpretations, emit an error
7168 -- message now and label node as illegal.
7170 if Present (Abstract_Op) then
7171 Get_First_Interp (N, I, It);
7175 -- Removal of abstract operation left no viable candidate
7177 Set_Etype (N, Any_Type);
7178 Error_Msg_Sloc := Sloc (Abstract_Op);
7180 ("cannot call abstract operation& declared#", N, Abstract_Op);
7182 -- In Ada 2005, an abstract operation may disable predefined
7183 -- operators. Since the context is not yet known, we mark the
7184 -- predefined operators as potentially hidden. Do not include
7185 -- predefined operators when addresses are involved since this
7186 -- case is handled separately.
7188 elsif Ada_Version >= Ada_2005 and then not Address_Descendant then
7189 while Present (It.Nam) loop
7190 if Is_Numeric_Type (It.Typ)
7191 and then Scope (It.Typ) = Standard_Standard
7193 Set_Abstract_Op (I, Abstract_Op);
7196 Get_Next_Interp (I, It);
7201 if Debug_Flag_V then
7202 Write_Str ("Remove_Abstract_Operations done: ");
7203 Write_Overloads (N);
7206 end Remove_Abstract_Operations;
7208 ----------------------------
7209 -- Try_Container_Indexing --
7210 ----------------------------
7212 function Try_Container_Indexing
7215 Exprs : List_Id) return Boolean
7217 function Constant_Indexing_OK return Boolean;
7218 -- Constant_Indexing is legal if there is no Variable_Indexing defined
7219 -- for the type, or else node not a target of assignment, or an actual
7220 -- for an IN OUT or OUT formal (RM 4.1.6 (11)).
7222 --------------------------
7223 -- Constant_Indexing_OK --
7224 --------------------------
7226 function Constant_Indexing_OK return Boolean is
7230 if No (Find_Value_Of_Aspect
7231 (Etype (Prefix), Aspect_Variable_Indexing))
7235 elsif not Is_Variable (Prefix) then
7240 while Present (Par) loop
7241 if Nkind (Parent (Par)) = N_Assignment_Statement
7242 and then Par = Name (Parent (Par))
7246 -- The call may be overloaded, in which case we assume that its
7247 -- resolution does not depend on the type of the parameter that
7248 -- includes the indexing operation.
7250 elsif Nkind_In (Parent (Par), N_Function_Call,
7251 N_Procedure_Call_Statement)
7252 and then Is_Entity_Name (Name (Parent (Par)))
7260 -- We should look for an interpretation with the proper
7261 -- number of formals, and determine whether it is an
7262 -- In_Parameter, but for now we examine the formal that
7263 -- corresponds to the indexing, and assume that variable
7264 -- indexing is required if some interpretation has an
7265 -- assignable formal at that position. Still does not
7266 -- cover the most complex cases ???
7268 if Is_Overloaded (Name (Parent (Par))) then
7270 Proc : constant Node_Id := Name (Parent (Par));
7277 Get_First_Interp (Proc, I, It);
7278 while Present (It.Nam) loop
7279 F := First_Formal (It.Nam);
7280 A := First (Parameter_Associations (Parent (Par)));
7282 while Present (F) and then Present (A) loop
7284 if Ekind (F) /= E_In_Parameter then
7287 exit; -- interpretation is safe
7295 Get_Next_Interp (I, It);
7302 Proc := Entity (Name (Parent (Par)));
7304 -- If this is an indirect call, get formals from
7307 if Is_Access_Subprogram_Type (Etype (Proc)) then
7308 Proc := Designated_Type (Etype (Proc));
7312 Formal := First_Formal (Proc);
7313 Actual := First_Actual (Parent (Par));
7315 -- Find corresponding actual
7317 while Present (Actual) loop
7318 exit when Actual = Par;
7319 Next_Actual (Actual);
7321 if Present (Formal) then
7322 Next_Formal (Formal);
7324 -- Otherwise this is a parameter mismatch, the error is
7325 -- reported elsewhere.
7332 return Ekind (Formal) = E_In_Parameter;
7335 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
7338 -- If the indexed component is a prefix it may be the first actual
7339 -- of a prefixed call. Retrieve the called entity, if any, and
7340 -- check its first formal. Determine if the context is a procedure
7341 -- or function call.
7343 elsif Nkind (Parent (Par)) = N_Selected_Component then
7345 Sel : constant Node_Id := Selector_Name (Parent (Par));
7346 Nam : constant Entity_Id := Current_Entity (Sel);
7349 if Present (Nam) and then Is_Overloadable (Nam) then
7350 if Nkind (Parent (Parent (Par))) =
7351 N_Procedure_Call_Statement
7355 elsif Ekind (Nam) = E_Function
7356 and then Present (First_Formal (Nam))
7358 return Ekind (First_Formal (Nam)) = E_In_Parameter;
7363 elsif Nkind ((Par)) in N_Op then
7367 Par := Parent (Par);
7370 -- In all other cases, constant indexing is legal
7373 end Constant_Indexing_OK;
7377 Loc : constant Source_Ptr := Sloc (N);
7381 Func_Name : Node_Id;
7384 -- Start of processing for Try_Container_Indexing
7387 -- Node may have been analyzed already when testing for a prefixed
7388 -- call, in which case do not redo analysis.
7390 if Present (Generalized_Indexing (N)) then
7394 C_Type := Etype (Prefix);
7396 -- If indexing a class-wide container, obtain indexing primitive from
7399 if Is_Class_Wide_Type (C_Type) then
7400 C_Type := Etype (Base_Type (C_Type));
7403 -- Check whether type has a specified indexing aspect
7407 if Constant_Indexing_OK then
7409 Find_Value_Of_Aspect (Etype (Prefix), Aspect_Constant_Indexing);
7412 if No (Func_Name) then
7414 Find_Value_Of_Aspect (Etype (Prefix), Aspect_Variable_Indexing);
7417 -- If aspect does not exist the expression is illegal. Error is
7418 -- diagnosed in caller.
7420 if No (Func_Name) then
7422 -- The prefix itself may be an indexing of a container: rewrite as
7423 -- such and re-analyze.
7425 if Has_Implicit_Dereference (Etype (Prefix)) then
7426 Build_Explicit_Dereference
7427 (Prefix, First_Discriminant (Etype (Prefix)));
7428 return Try_Container_Indexing (N, Prefix, Exprs);
7434 -- If the container type is derived from another container type, the
7435 -- value of the inherited aspect is the Reference operation declared
7436 -- for the parent type.
7438 -- However, Reference is also a primitive operation of the type, and the
7439 -- inherited operation has a different signature. We retrieve the right
7440 -- ones (the function may be overloaded) from the list of primitive
7441 -- operations of the derived type.
7443 -- Note that predefined containers are typically all derived from one of
7444 -- the Controlled types. The code below is motivated by containers that
7445 -- are derived from other types with a Reference aspect.
7447 elsif Is_Derived_Type (C_Type)
7448 and then Etype (First_Formal (Entity (Func_Name))) /= Etype (Prefix)
7450 Func_Name := Find_Primitive_Operations (C_Type, Chars (Func_Name));
7453 Assoc := New_List (Relocate_Node (Prefix));
7455 -- A generalized indexing may have nore than one index expression, so
7456 -- transfer all of them to the argument list to be used in the call.
7457 -- Note that there may be named associations, in which case the node
7458 -- was rewritten earlier as a call, and has been transformed back into
7459 -- an indexed expression to share the following processing.
7461 -- The generalized indexing node is the one on which analysis and
7462 -- resolution take place. Before expansion the original node is replaced
7463 -- with the generalized indexing node, which is a call, possibly with a
7464 -- dereference operation.
7466 if Comes_From_Source (N) then
7467 Check_Compiler_Unit ("generalized indexing", N);
7470 -- Create argument list for function call that represents generalized
7471 -- indexing. Note that indices (i.e. actuals) may themselves be
7479 Arg := First (Exprs);
7480 while Present (Arg) loop
7481 New_Arg := Relocate_Node (Arg);
7483 -- The arguments can be parameter associations, in which case the
7484 -- explicit actual parameter carries the overloadings.
7486 if Nkind (New_Arg) /= N_Parameter_Association then
7487 Save_Interps (Arg, New_Arg);
7490 Append (New_Arg, Assoc);
7495 if not Is_Overloaded (Func_Name) then
7496 Func := Entity (Func_Name);
7498 Make_Function_Call (Loc,
7499 Name => New_Occurrence_Of (Func, Loc),
7500 Parameter_Associations => Assoc);
7501 Set_Parent (Indexing, Parent (N));
7502 Set_Generalized_Indexing (N, Indexing);
7504 Set_Etype (N, Etype (Indexing));
7506 -- If the return type of the indexing function is a reference type,
7507 -- add the dereference as a possible interpretation. Note that the
7508 -- indexing aspect may be a function that returns the element type
7509 -- with no intervening implicit dereference, and that the reference
7510 -- discriminant is not the first discriminant.
7512 if Has_Discriminants (Etype (Func)) then
7513 Check_Implicit_Dereference (N, Etype (Func));
7517 -- If there are multiple indexing functions, build a function call
7518 -- and analyze it for each of the possible interpretations.
7521 Make_Function_Call (Loc,
7523 Make_Identifier (Loc, Chars (Func_Name)),
7524 Parameter_Associations => Assoc);
7526 Set_Parent (Indexing, Parent (N));
7527 Set_Generalized_Indexing (N, Indexing);
7528 Set_Etype (N, Any_Type);
7529 Set_Etype (Name (Indexing), Any_Type);
7537 Get_First_Interp (Func_Name, I, It);
7538 Set_Etype (Indexing, Any_Type);
7540 while Present (It.Nam) loop
7541 Analyze_One_Call (Indexing, It.Nam, False, Success);
7545 -- Function in current interpretation is a valid candidate.
7546 -- Its result type is also a potential type for the
7547 -- original Indexed_Component node.
7549 Add_One_Interp (Name (Indexing), It.Nam, It.Typ);
7550 Add_One_Interp (N, It.Nam, It.Typ);
7552 -- Add implicit dereference interpretation to original node
7554 if Has_Discriminants (Etype (It.Nam)) then
7555 Check_Implicit_Dereference (N, Etype (It.Nam));
7559 Get_Next_Interp (I, It);
7564 if Etype (Indexing) = Any_Type then
7566 ("container cannot be indexed with&", N, Etype (First (Exprs)));
7567 Rewrite (N, New_Occurrence_Of (Any_Id, Loc));
7571 end Try_Container_Indexing;
7573 -----------------------
7574 -- Try_Indirect_Call --
7575 -----------------------
7577 function Try_Indirect_Call
7580 Typ : Entity_Id) return Boolean
7586 pragma Warnings (Off, Call_OK);
7589 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
7591 Actual := First_Actual (N);
7592 Formal := First_Formal (Designated_Type (Typ));
7593 while Present (Actual) and then Present (Formal) loop
7594 if not Has_Compatible_Type (Actual, Etype (Formal)) then
7599 Next_Formal (Formal);
7602 if No (Actual) and then No (Formal) then
7603 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
7605 -- Nam is a candidate interpretation for the name in the call,
7606 -- if it is not an indirect call.
7608 if not Is_Type (Nam)
7609 and then Is_Entity_Name (Name (N))
7611 Set_Entity (Name (N), Nam);
7619 end Try_Indirect_Call;
7621 ----------------------
7622 -- Try_Indexed_Call --
7623 ----------------------
7625 function Try_Indexed_Call
7629 Skip_First : Boolean) return Boolean
7631 Loc : constant Source_Ptr := Sloc (N);
7632 Actuals : constant List_Id := Parameter_Associations (N);
7637 Actual := First (Actuals);
7639 -- If the call was originally written in prefix form, skip the first
7640 -- actual, which is obviously not defaulted.
7646 Index := First_Index (Typ);
7647 while Present (Actual) and then Present (Index) loop
7649 -- If the parameter list has a named association, the expression
7650 -- is definitely a call and not an indexed component.
7652 if Nkind (Actual) = N_Parameter_Association then
7656 if Is_Entity_Name (Actual)
7657 and then Is_Type (Entity (Actual))
7658 and then No (Next (Actual))
7660 -- A single actual that is a type name indicates a slice if the
7661 -- type is discrete, and an error otherwise.
7663 if Is_Discrete_Type (Entity (Actual)) then
7667 Make_Function_Call (Loc,
7668 Name => Relocate_Node (Name (N))),
7670 New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
7675 Error_Msg_N ("invalid use of type in expression", Actual);
7676 Set_Etype (N, Any_Type);
7681 elsif not Has_Compatible_Type (Actual, Etype (Index)) then
7689 if No (Actual) and then No (Index) then
7690 Add_One_Interp (N, Nam, Component_Type (Typ));
7692 -- Nam is a candidate interpretation for the name in the call,
7693 -- if it is not an indirect call.
7695 if not Is_Type (Nam)
7696 and then Is_Entity_Name (Name (N))
7698 Set_Entity (Name (N), Nam);
7705 end Try_Indexed_Call;
7707 --------------------------
7708 -- Try_Object_Operation --
7709 --------------------------
7711 function Try_Object_Operation
7712 (N : Node_Id; CW_Test_Only : Boolean := False) return Boolean
7714 K : constant Node_Kind := Nkind (Parent (N));
7715 Is_Subprg_Call : constant Boolean := K in N_Subprogram_Call;
7716 Loc : constant Source_Ptr := Sloc (N);
7717 Obj : constant Node_Id := Prefix (N);
7719 Subprog : constant Node_Id :=
7720 Make_Identifier (Sloc (Selector_Name (N)),
7721 Chars => Chars (Selector_Name (N)));
7722 -- Identifier on which possible interpretations will be collected
7724 Report_Error : Boolean := False;
7725 -- If no candidate interpretation matches the context, redo analysis
7726 -- with Report_Error True to provide additional information.
7729 Candidate : Entity_Id := Empty;
7730 New_Call_Node : Node_Id := Empty;
7731 Node_To_Replace : Node_Id;
7732 Obj_Type : Entity_Id := Etype (Obj);
7733 Success : Boolean := False;
7735 function Valid_Candidate
7738 Subp : Entity_Id) return Entity_Id;
7739 -- If the subprogram is a valid interpretation, record it, and add
7740 -- to the list of interpretations of Subprog. Otherwise return Empty.
7742 procedure Complete_Object_Operation
7743 (Call_Node : Node_Id;
7744 Node_To_Replace : Node_Id);
7745 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
7746 -- Call_Node, insert the object (or its dereference) as the first actual
7747 -- in the call, and complete the analysis of the call.
7749 procedure Report_Ambiguity (Op : Entity_Id);
7750 -- If a prefixed procedure call is ambiguous, indicate whether the
7751 -- call includes an implicit dereference or an implicit 'Access.
7753 procedure Transform_Object_Operation
7754 (Call_Node : out Node_Id;
7755 Node_To_Replace : out Node_Id);
7756 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
7757 -- Call_Node is the resulting subprogram call, Node_To_Replace is
7758 -- either N or the parent of N, and Subprog is a reference to the
7759 -- subprogram we are trying to match.
7761 function Try_Class_Wide_Operation
7762 (Call_Node : Node_Id;
7763 Node_To_Replace : Node_Id) return Boolean;
7764 -- Traverse all ancestor types looking for a class-wide subprogram
7765 -- for which the current operation is a valid non-dispatching call.
7767 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
7768 -- If prefix is overloaded, its interpretation may include different
7769 -- tagged types, and we must examine the primitive operations and
7770 -- the class-wide operations of each in order to find candidate
7771 -- interpretations for the call as a whole.
7773 function Try_Primitive_Operation
7774 (Call_Node : Node_Id;
7775 Node_To_Replace : Node_Id) return Boolean;
7776 -- Traverse the list of primitive subprograms looking for a dispatching
7777 -- operation for which the current node is a valid call .
7779 ---------------------
7780 -- Valid_Candidate --
7781 ---------------------
7783 function Valid_Candidate
7786 Subp : Entity_Id) return Entity_Id
7788 Arr_Type : Entity_Id;
7789 Comp_Type : Entity_Id;
7792 -- If the subprogram is a valid interpretation, record it in global
7793 -- variable Subprog, to collect all possible overloadings.
7796 if Subp /= Entity (Subprog) then
7797 Add_One_Interp (Subprog, Subp, Etype (Subp));
7801 -- If the call may be an indexed call, retrieve component type of
7802 -- resulting expression, and add possible interpretation.
7807 if Nkind (Call) = N_Function_Call
7808 and then Nkind (Parent (N)) = N_Indexed_Component
7809 and then Needs_One_Actual (Subp)
7811 if Is_Array_Type (Etype (Subp)) then
7812 Arr_Type := Etype (Subp);
7814 elsif Is_Access_Type (Etype (Subp))
7815 and then Is_Array_Type (Designated_Type (Etype (Subp)))
7817 Arr_Type := Designated_Type (Etype (Subp));
7821 if Present (Arr_Type) then
7823 -- Verify that the actuals (excluding the object) match the types
7831 Actual := Next (First_Actual (Call));
7832 Index := First_Index (Arr_Type);
7833 while Present (Actual) and then Present (Index) loop
7834 if not Has_Compatible_Type (Actual, Etype (Index)) then
7839 Next_Actual (Actual);
7845 and then Present (Arr_Type)
7847 Comp_Type := Component_Type (Arr_Type);
7851 if Present (Comp_Type)
7852 and then Etype (Subprog) /= Comp_Type
7854 Add_One_Interp (Subprog, Subp, Comp_Type);
7858 if Etype (Call) /= Any_Type then
7863 end Valid_Candidate;
7865 -------------------------------
7866 -- Complete_Object_Operation --
7867 -------------------------------
7869 procedure Complete_Object_Operation
7870 (Call_Node : Node_Id;
7871 Node_To_Replace : Node_Id)
7873 Control : constant Entity_Id := First_Formal (Entity (Subprog));
7874 Formal_Type : constant Entity_Id := Etype (Control);
7875 First_Actual : Node_Id;
7878 -- Place the name of the operation, with its interpretations,
7879 -- on the rewritten call.
7881 Set_Name (Call_Node, Subprog);
7883 First_Actual := First (Parameter_Associations (Call_Node));
7885 -- For cross-reference purposes, treat the new node as being in the
7886 -- source if the original one is. Set entity and type, even though
7887 -- they may be overwritten during resolution if overloaded.
7889 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
7890 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
7892 if Nkind (N) = N_Selected_Component
7893 and then not Inside_A_Generic
7895 Set_Entity (Selector_Name (N), Entity (Subprog));
7896 Set_Etype (Selector_Name (N), Etype (Entity (Subprog)));
7899 -- If need be, rewrite first actual as an explicit dereference. If
7900 -- the call is overloaded, the rewriting can only be done once the
7901 -- primitive operation is identified.
7903 if Is_Overloaded (Subprog) then
7905 -- The prefix itself may be overloaded, and its interpretations
7906 -- must be propagated to the new actual in the call.
7908 if Is_Overloaded (Obj) then
7909 Save_Interps (Obj, First_Actual);
7912 Rewrite (First_Actual, Obj);
7914 elsif not Is_Access_Type (Formal_Type)
7915 and then Is_Access_Type (Etype (Obj))
7917 Rewrite (First_Actual,
7918 Make_Explicit_Dereference (Sloc (Obj), Obj));
7919 Analyze (First_Actual);
7921 -- If we need to introduce an explicit dereference, verify that
7922 -- the resulting actual is compatible with the mode of the formal.
7924 if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
7925 and then Is_Access_Constant (Etype (Obj))
7928 ("expect variable in call to&", Prefix (N), Entity (Subprog));
7931 -- Conversely, if the formal is an access parameter and the object
7932 -- is not, replace the actual with a 'Access reference. Its analysis
7933 -- will check that the object is aliased.
7935 elsif Is_Access_Type (Formal_Type)
7936 and then not Is_Access_Type (Etype (Obj))
7938 -- A special case: A.all'access is illegal if A is an access to a
7939 -- constant and the context requires an access to a variable.
7941 if not Is_Access_Constant (Formal_Type) then
7942 if (Nkind (Obj) = N_Explicit_Dereference
7943 and then Is_Access_Constant (Etype (Prefix (Obj))))
7944 or else not Is_Variable (Obj)
7947 ("actual for & must be a variable", Obj, Control);
7951 Rewrite (First_Actual,
7952 Make_Attribute_Reference (Loc,
7953 Attribute_Name => Name_Access,
7954 Prefix => Relocate_Node (Obj)));
7956 if not Is_Aliased_View (Obj) then
7958 ("object in prefixed call to & must be aliased "
7959 & "(RM 4.1.3 (13 1/2))", Prefix (First_Actual), Subprog);
7962 Analyze (First_Actual);
7965 if Is_Overloaded (Obj) then
7966 Save_Interps (Obj, First_Actual);
7969 Rewrite (First_Actual, Obj);
7972 -- The operation is obtained from the dispatch table and not by
7973 -- visibility, and may be declared in a unit that is not explicitly
7974 -- referenced in the source, but is nevertheless required in the
7975 -- context of the current unit. Indicate that operation and its scope
7976 -- are referenced, to prevent spurious and misleading warnings. If
7977 -- the operation is overloaded, all primitives are in the same scope
7978 -- and we can use any of them.
7980 Set_Referenced (Entity (Subprog), True);
7981 Set_Referenced (Scope (Entity (Subprog)), True);
7983 Rewrite (Node_To_Replace, Call_Node);
7985 -- Propagate the interpretations collected in subprog to the new
7986 -- function call node, to be resolved from context.
7988 if Is_Overloaded (Subprog) then
7989 Save_Interps (Subprog, Node_To_Replace);
7992 -- The type of the subprogram may be a limited view obtained
7993 -- transitively from another unit. If full view is available,
7994 -- use it to analyze call.
7997 T : constant Entity_Id := Etype (Subprog);
7999 if From_Limited_With (T) then
8000 Set_Etype (Entity (Subprog), Available_View (T));
8004 Analyze (Node_To_Replace);
8006 -- If the operation has been rewritten into a call, which may get
8007 -- subsequently an explicit dereference, preserve the type on the
8008 -- original node (selected component or indexed component) for
8009 -- subsequent legality tests, e.g. Is_Variable. which examines
8010 -- the original node.
8012 if Nkind (Node_To_Replace) = N_Function_Call then
8014 (Original_Node (Node_To_Replace), Etype (Node_To_Replace));
8017 end Complete_Object_Operation;
8019 ----------------------
8020 -- Report_Ambiguity --
8021 ----------------------
8023 procedure Report_Ambiguity (Op : Entity_Id) is
8024 Access_Actual : constant Boolean :=
8025 Is_Access_Type (Etype (Prefix (N)));
8026 Access_Formal : Boolean := False;
8029 Error_Msg_Sloc := Sloc (Op);
8031 if Present (First_Formal (Op)) then
8032 Access_Formal := Is_Access_Type (Etype (First_Formal (Op)));
8035 if Access_Formal and then not Access_Actual then
8036 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8038 ("\possible interpretation "
8039 & "(inherited, with implicit 'Access) #", N);
8042 ("\possible interpretation (with implicit 'Access) #", N);
8045 elsif not Access_Formal and then Access_Actual then
8046 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8048 ("\possible interpretation "
8049 & "(inherited, with implicit dereference) #", N);
8052 ("\possible interpretation (with implicit dereference) #", N);
8056 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8057 Error_Msg_N ("\possible interpretation (inherited)#", N);
8059 Error_Msg_N -- CODEFIX
8060 ("\possible interpretation#", N);
8063 end Report_Ambiguity;
8065 --------------------------------
8066 -- Transform_Object_Operation --
8067 --------------------------------
8069 procedure Transform_Object_Operation
8070 (Call_Node : out Node_Id;
8071 Node_To_Replace : out Node_Id)
8073 Dummy : constant Node_Id := New_Copy (Obj);
8074 -- Placeholder used as a first parameter in the call, replaced
8075 -- eventually by the proper object.
8077 Parent_Node : constant Node_Id := Parent (N);
8083 -- Common case covering 1) Call to a procedure and 2) Call to a
8084 -- function that has some additional actuals.
8086 if Nkind (Parent_Node) in N_Subprogram_Call
8088 -- N is a selected component node containing the name of the
8089 -- subprogram. If N is not the name of the parent node we must
8090 -- not replace the parent node by the new construct. This case
8091 -- occurs when N is a parameterless call to a subprogram that
8092 -- is an actual parameter of a call to another subprogram. For
8094 -- Some_Subprogram (..., Obj.Operation, ...)
8096 and then Name (Parent_Node) = N
8098 Node_To_Replace := Parent_Node;
8100 Actuals := Parameter_Associations (Parent_Node);
8102 if Present (Actuals) then
8103 Prepend (Dummy, Actuals);
8105 Actuals := New_List (Dummy);
8108 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
8110 Make_Procedure_Call_Statement (Loc,
8111 Name => New_Copy (Subprog),
8112 Parameter_Associations => Actuals);
8116 Make_Function_Call (Loc,
8117 Name => New_Copy (Subprog),
8118 Parameter_Associations => Actuals);
8121 -- Before analysis, a function call appears as an indexed component
8122 -- if there are no named associations.
8124 elsif Nkind (Parent_Node) = N_Indexed_Component
8125 and then N = Prefix (Parent_Node)
8127 Node_To_Replace := Parent_Node;
8128 Actuals := Expressions (Parent_Node);
8130 Actual := First (Actuals);
8131 while Present (Actual) loop
8136 Prepend (Dummy, Actuals);
8139 Make_Function_Call (Loc,
8140 Name => New_Copy (Subprog),
8141 Parameter_Associations => Actuals);
8143 -- Parameterless call: Obj.F is rewritten as F (Obj)
8146 Node_To_Replace := N;
8149 Make_Function_Call (Loc,
8150 Name => New_Copy (Subprog),
8151 Parameter_Associations => New_List (Dummy));
8153 end Transform_Object_Operation;
8155 ------------------------------
8156 -- Try_Class_Wide_Operation --
8157 ------------------------------
8159 function Try_Class_Wide_Operation
8160 (Call_Node : Node_Id;
8161 Node_To_Replace : Node_Id) return Boolean
8163 Anc_Type : Entity_Id;
8164 Matching_Op : Entity_Id := Empty;
8167 procedure Traverse_Homonyms
8168 (Anc_Type : Entity_Id;
8169 Error : out Boolean);
8170 -- Traverse the homonym chain of the subprogram searching for those
8171 -- homonyms whose first formal has the Anc_Type's class-wide type,
8172 -- or an anonymous access type designating the class-wide type. If
8173 -- an ambiguity is detected, then Error is set to True.
8175 procedure Traverse_Interfaces
8176 (Anc_Type : Entity_Id;
8177 Error : out Boolean);
8178 -- Traverse the list of interfaces, if any, associated with Anc_Type
8179 -- and search for acceptable class-wide homonyms associated with each
8180 -- interface. If an ambiguity is detected, then Error is set to True.
8182 -----------------------
8183 -- Traverse_Homonyms --
8184 -----------------------
8186 procedure Traverse_Homonyms
8187 (Anc_Type : Entity_Id;
8188 Error : out Boolean)
8190 Cls_Type : Entity_Id;
8198 Cls_Type := Class_Wide_Type (Anc_Type);
8200 Hom := Current_Entity (Subprog);
8202 -- Find a non-hidden operation whose first parameter is of the
8203 -- class-wide type, a subtype thereof, or an anonymous access
8204 -- to same. If in an instance, the operation can be considered
8205 -- even if hidden (it may be hidden because the instantiation
8206 -- is expanded after the containing package has been analyzed).
8208 while Present (Hom) loop
8209 if Ekind_In (Hom, E_Procedure, E_Function)
8210 and then (not Is_Hidden (Hom) or else In_Instance)
8211 and then Scope (Hom) = Scope (Anc_Type)
8212 and then Present (First_Formal (Hom))
8214 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
8216 (Is_Access_Type (Etype (First_Formal (Hom)))
8218 Ekind (Etype (First_Formal (Hom))) =
8219 E_Anonymous_Access_Type
8222 (Designated_Type (Etype (First_Formal (Hom)))) =
8225 -- If the context is a procedure call, ignore functions
8226 -- in the name of the call.
8228 if Ekind (Hom) = E_Function
8229 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
8230 and then N = Name (Parent (N))
8234 -- If the context is a function call, ignore procedures
8235 -- in the name of the call.
8237 elsif Ekind (Hom) = E_Procedure
8238 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
8243 Set_Etype (Call_Node, Any_Type);
8244 Set_Is_Overloaded (Call_Node, False);
8247 if No (Matching_Op) then
8248 Hom_Ref := New_Occurrence_Of (Hom, Sloc (Subprog));
8249 Set_Etype (Call_Node, Any_Type);
8250 Set_Parent (Call_Node, Parent (Node_To_Replace));
8252 Set_Name (Call_Node, Hom_Ref);
8257 Report => Report_Error,
8259 Skip_First => True);
8262 Valid_Candidate (Success, Call_Node, Hom);
8268 Report => Report_Error,
8270 Skip_First => True);
8272 if Present (Valid_Candidate (Success, Call_Node, Hom))
8273 and then Nkind (Call_Node) /= N_Function_Call
8275 Error_Msg_NE ("ambiguous call to&", N, Hom);
8276 Report_Ambiguity (Matching_Op);
8277 Report_Ambiguity (Hom);
8285 Hom := Homonym (Hom);
8287 end Traverse_Homonyms;
8289 -------------------------
8290 -- Traverse_Interfaces --
8291 -------------------------
8293 procedure Traverse_Interfaces
8294 (Anc_Type : Entity_Id;
8295 Error : out Boolean)
8297 Intface_List : constant List_Id :=
8298 Abstract_Interface_List (Anc_Type);
8304 if Is_Non_Empty_List (Intface_List) then
8305 Intface := First (Intface_List);
8306 while Present (Intface) loop
8308 -- Look for acceptable class-wide homonyms associated with
8311 Traverse_Homonyms (Etype (Intface), Error);
8317 -- Continue the search by looking at each of the interface's
8318 -- associated interface ancestors.
8320 Traverse_Interfaces (Etype (Intface), Error);
8329 end Traverse_Interfaces;
8331 -- Start of processing for Try_Class_Wide_Operation
8334 -- If we are searching only for conflicting class-wide subprograms
8335 -- then initialize directly Matching_Op with the target entity.
8337 if CW_Test_Only then
8338 Matching_Op := Entity (Selector_Name (N));
8341 -- Loop through ancestor types (including interfaces), traversing
8342 -- the homonym chain of the subprogram, trying out those homonyms
8343 -- whose first formal has the class-wide type of the ancestor, or
8344 -- an anonymous access type designating the class-wide type.
8346 Anc_Type := Obj_Type;
8348 -- Look for a match among homonyms associated with the ancestor
8350 Traverse_Homonyms (Anc_Type, Error);
8356 -- Continue the search for matches among homonyms associated with
8357 -- any interfaces implemented by the ancestor.
8359 Traverse_Interfaces (Anc_Type, Error);
8365 exit when Etype (Anc_Type) = Anc_Type;
8366 Anc_Type := Etype (Anc_Type);
8369 if Present (Matching_Op) then
8370 Set_Etype (Call_Node, Etype (Matching_Op));
8373 return Present (Matching_Op);
8374 end Try_Class_Wide_Operation;
8376 -----------------------------------
8377 -- Try_One_Prefix_Interpretation --
8378 -----------------------------------
8380 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
8382 -- If the interpretation does not have a valid candidate type,
8383 -- preserve current value of Obj_Type for subsequent errors.
8385 Prev_Obj_Type : constant Entity_Id := Obj_Type;
8390 if Is_Access_Type (Obj_Type) then
8391 Obj_Type := Designated_Type (Obj_Type);
8394 if Ekind (Obj_Type) = E_Private_Subtype then
8395 Obj_Type := Base_Type (Obj_Type);
8398 if Is_Class_Wide_Type (Obj_Type) then
8399 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
8402 -- The type may have be obtained through a limited_with clause,
8403 -- in which case the primitive operations are available on its
8404 -- non-limited view. If still incomplete, retrieve full view.
8406 if Ekind (Obj_Type) = E_Incomplete_Type
8407 and then From_Limited_With (Obj_Type)
8408 and then Has_Non_Limited_View (Obj_Type)
8410 Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
8413 -- If the object is not tagged, or the type is still an incomplete
8414 -- type, this is not a prefixed call.
8416 if not Is_Tagged_Type (Obj_Type)
8417 or else Is_Incomplete_Type (Obj_Type)
8420 -- Restore previous type if current one is not legal candidate
8422 Obj_Type := Prev_Obj_Type;
8427 Dup_Call_Node : constant Node_Id := New_Copy (New_Call_Node);
8428 CW_Result : Boolean;
8429 Prim_Result : Boolean;
8430 pragma Unreferenced (CW_Result);
8433 if not CW_Test_Only then
8435 Try_Primitive_Operation
8436 (Call_Node => New_Call_Node,
8437 Node_To_Replace => Node_To_Replace);
8440 -- Check if there is a class-wide subprogram covering the
8441 -- primitive. This check must be done even if a candidate
8442 -- was found in order to report ambiguous calls.
8444 if not (Prim_Result) then
8446 Try_Class_Wide_Operation
8447 (Call_Node => New_Call_Node,
8448 Node_To_Replace => Node_To_Replace);
8450 -- If we found a primitive we search for class-wide subprograms
8451 -- using a duplicate of the call node (done to avoid missing its
8452 -- decoration if there is no ambiguity).
8456 Try_Class_Wide_Operation
8457 (Call_Node => Dup_Call_Node,
8458 Node_To_Replace => Node_To_Replace);
8461 end Try_One_Prefix_Interpretation;
8463 -----------------------------
8464 -- Try_Primitive_Operation --
8465 -----------------------------
8467 function Try_Primitive_Operation
8468 (Call_Node : Node_Id;
8469 Node_To_Replace : Node_Id) return Boolean
8472 Prim_Op : Entity_Id;
8473 Matching_Op : Entity_Id := Empty;
8474 Prim_Op_Ref : Node_Id := Empty;
8476 Corr_Type : Entity_Id := Empty;
8477 -- If the prefix is a synchronized type, the controlling type of
8478 -- the primitive operation is the corresponding record type, else
8479 -- this is the object type itself.
8481 Success : Boolean := False;
8483 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
8484 -- For tagged types the candidate interpretations are found in
8485 -- the list of primitive operations of the type and its ancestors.
8486 -- For formal tagged types we have to find the operations declared
8487 -- in the same scope as the type (including in the generic formal
8488 -- part) because the type itself carries no primitive operations,
8489 -- except for formal derived types that inherit the operations of
8490 -- the parent and progenitors.
8492 -- If the context is a generic subprogram body, the generic formals
8493 -- are visible by name, but are not in the entity list of the
8494 -- subprogram because that list starts with the subprogram formals.
8495 -- We retrieve the candidate operations from the generic declaration.
8497 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id;
8498 -- Prefix notation can also be used on operations that are not
8499 -- primitives of the type, but are declared in the same immediate
8500 -- declarative part, which can only mean the corresponding package
8501 -- body (See RM 4.1.3 (9.2/3)). If we are in that body we extend the
8502 -- list of primitives with body operations with the same name that
8503 -- may be candidates, so that Try_Primitive_Operations can examine
8504 -- them if no real primitive is found.
8506 function Is_Private_Overriding (Op : Entity_Id) return Boolean;
8507 -- An operation that overrides an inherited operation in the private
8508 -- part of its package may be hidden, but if the inherited operation
8509 -- is visible a direct call to it will dispatch to the private one,
8510 -- which is therefore a valid candidate.
8512 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
8513 -- Verify that the prefix, dereferenced if need be, is a valid
8514 -- controlling argument in a call to Op. The remaining actuals
8515 -- are checked in the subsequent call to Analyze_One_Call.
8517 ------------------------------
8518 -- Collect_Generic_Type_Ops --
8519 ------------------------------
8521 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
8522 Bas : constant Entity_Id := Base_Type (T);
8523 Candidates : constant Elist_Id := New_Elmt_List;
8527 procedure Check_Candidate;
8528 -- The operation is a candidate if its first parameter is a
8529 -- controlling operand of the desired type.
8531 -----------------------
8532 -- Check_Candidate; --
8533 -----------------------
8535 procedure Check_Candidate is
8537 Formal := First_Formal (Subp);
8540 and then Is_Controlling_Formal (Formal)
8542 (Base_Type (Etype (Formal)) = Bas
8544 (Is_Access_Type (Etype (Formal))
8545 and then Designated_Type (Etype (Formal)) = Bas))
8547 Append_Elmt (Subp, Candidates);
8549 end Check_Candidate;
8551 -- Start of processing for Collect_Generic_Type_Ops
8554 if Is_Derived_Type (T) then
8555 return Primitive_Operations (T);
8557 elsif Ekind_In (Scope (T), E_Procedure, E_Function) then
8559 -- Scan the list of generic formals to find subprograms
8560 -- that may have a first controlling formal of the type.
8562 if Nkind (Unit_Declaration_Node (Scope (T))) =
8563 N_Generic_Subprogram_Declaration
8570 First (Generic_Formal_Declarations
8571 (Unit_Declaration_Node (Scope (T))));
8572 while Present (Decl) loop
8573 if Nkind (Decl) in N_Formal_Subprogram_Declaration then
8574 Subp := Defining_Entity (Decl);
8585 -- Scan the list of entities declared in the same scope as
8586 -- the type. In general this will be an open scope, given that
8587 -- the call we are analyzing can only appear within a generic
8588 -- declaration or body (either the one that declares T, or a
8591 -- For a subtype representing a generic actual type, go to the
8594 if Is_Generic_Actual_Type (T) then
8595 Subp := First_Entity (Scope (Base_Type (T)));
8597 Subp := First_Entity (Scope (T));
8600 while Present (Subp) loop
8601 if Is_Overloadable (Subp) then
8610 end Collect_Generic_Type_Ops;
8612 ----------------------------
8613 -- Extended_Primitive_Ops --
8614 ----------------------------
8616 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id is
8617 Type_Scope : constant Entity_Id := Scope (T);
8619 Body_Decls : List_Id;
8625 Op_List := Primitive_Operations (T);
8627 if Ekind (Type_Scope) = E_Package
8628 and then In_Package_Body (Type_Scope)
8629 and then In_Open_Scopes (Type_Scope)
8631 -- Retrieve list of declarations of package body.
8635 (Unit_Declaration_Node
8637 (Unit_Declaration_Node (Type_Scope))));
8639 Op := Current_Entity (Subprog);
8641 while Present (Op) loop
8642 if Comes_From_Source (Op)
8643 and then Is_Overloadable (Op)
8645 -- Exclude overriding primitive operations of a type
8646 -- extension declared in the package body, to prevent
8647 -- duplicates in extended list.
8649 and then not Is_Primitive (Op)
8650 and then Is_List_Member (Unit_Declaration_Node (Op))
8651 and then List_Containing (Unit_Declaration_Node (Op)) =
8654 if not Op_Found then
8656 -- Copy list of primitives so it is not affected for
8659 Op_List := New_Copy_Elist (Op_List);
8663 Append_Elmt (Op, Op_List);
8671 end Extended_Primitive_Ops;
8673 ---------------------------
8674 -- Is_Private_Overriding --
8675 ---------------------------
8677 function Is_Private_Overriding (Op : Entity_Id) return Boolean is
8678 Visible_Op : constant Entity_Id := Homonym (Op);
8681 return Present (Visible_Op)
8682 and then Scope (Op) = Scope (Visible_Op)
8683 and then not Comes_From_Source (Visible_Op)
8684 and then Alias (Visible_Op) = Op
8685 and then not Is_Hidden (Visible_Op);
8686 end Is_Private_Overriding;
8688 -----------------------------
8689 -- Valid_First_Argument_Of --
8690 -----------------------------
8692 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
8693 Typ : Entity_Id := Etype (First_Formal (Op));
8696 if Is_Concurrent_Type (Typ)
8697 and then Present (Corresponding_Record_Type (Typ))
8699 Typ := Corresponding_Record_Type (Typ);
8702 -- Simple case. Object may be a subtype of the tagged type or
8703 -- may be the corresponding record of a synchronized type.
8705 return Obj_Type = Typ
8706 or else Base_Type (Obj_Type) = Typ
8707 or else Corr_Type = Typ
8709 -- Prefix can be dereferenced
8712 (Is_Access_Type (Corr_Type)
8713 and then Designated_Type (Corr_Type) = Typ)
8715 -- Formal is an access parameter, for which the object
8716 -- can provide an access.
8719 (Ekind (Typ) = E_Anonymous_Access_Type
8721 Base_Type (Designated_Type (Typ)) = Base_Type (Corr_Type));
8722 end Valid_First_Argument_Of;
8724 -- Start of processing for Try_Primitive_Operation
8727 -- Look for subprograms in the list of primitive operations. The name
8728 -- must be identical, and the kind of call indicates the expected
8729 -- kind of operation (function or procedure). If the type is a
8730 -- (tagged) synchronized type, the primitive ops are attached to the
8731 -- corresponding record (base) type.
8733 if Is_Concurrent_Type (Obj_Type) then
8734 if Present (Corresponding_Record_Type (Obj_Type)) then
8735 Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
8736 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
8738 Corr_Type := Obj_Type;
8739 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
8742 elsif not Is_Generic_Type (Obj_Type) then
8743 Corr_Type := Obj_Type;
8744 Elmt := First_Elmt (Extended_Primitive_Ops (Obj_Type));
8747 Corr_Type := Obj_Type;
8748 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
8751 while Present (Elmt) loop
8752 Prim_Op := Node (Elmt);
8754 if Chars (Prim_Op) = Chars (Subprog)
8755 and then Present (First_Formal (Prim_Op))
8756 and then Valid_First_Argument_Of (Prim_Op)
8758 (Nkind (Call_Node) = N_Function_Call)
8760 (Ekind (Prim_Op) = E_Function)
8762 -- Ada 2005 (AI-251): If this primitive operation corresponds
8763 -- to an immediate ancestor interface there is no need to add
8764 -- it to the list of interpretations; the corresponding aliased
8765 -- primitive is also in this list of primitive operations and
8766 -- will be used instead.
8768 if (Present (Interface_Alias (Prim_Op))
8769 and then Is_Ancestor (Find_Dispatching_Type
8770 (Alias (Prim_Op)), Corr_Type))
8772 -- Do not consider hidden primitives unless the type is in an
8773 -- open scope or we are within an instance, where visibility
8774 -- is known to be correct, or else if this is an overriding
8775 -- operation in the private part for an inherited operation.
8777 or else (Is_Hidden (Prim_Op)
8778 and then not Is_Immediately_Visible (Obj_Type)
8779 and then not In_Instance
8780 and then not Is_Private_Overriding (Prim_Op))
8785 Set_Etype (Call_Node, Any_Type);
8786 Set_Is_Overloaded (Call_Node, False);
8788 if No (Matching_Op) then
8789 Prim_Op_Ref := New_Occurrence_Of (Prim_Op, Sloc (Subprog));
8790 Candidate := Prim_Op;
8792 Set_Parent (Call_Node, Parent (Node_To_Replace));
8794 Set_Name (Call_Node, Prim_Op_Ref);
8800 Report => Report_Error,
8802 Skip_First => True);
8804 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
8806 -- More than one interpretation, collect for subsequent
8807 -- disambiguation. If this is a procedure call and there
8808 -- is another match, report ambiguity now.
8814 Report => Report_Error,
8816 Skip_First => True);
8818 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
8819 and then Nkind (Call_Node) /= N_Function_Call
8821 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
8822 Report_Ambiguity (Matching_Op);
8823 Report_Ambiguity (Prim_Op);
8833 if Present (Matching_Op) then
8834 Set_Etype (Call_Node, Etype (Matching_Op));
8837 return Present (Matching_Op);
8838 end Try_Primitive_Operation;
8840 -- Start of processing for Try_Object_Operation
8843 Analyze_Expression (Obj);
8845 -- Analyze the actuals if node is known to be a subprogram call
8847 if Is_Subprg_Call and then N = Name (Parent (N)) then
8848 Actual := First (Parameter_Associations (Parent (N)));
8849 while Present (Actual) loop
8850 Analyze_Expression (Actual);
8855 -- Build a subprogram call node, using a copy of Obj as its first
8856 -- actual. This is a placeholder, to be replaced by an explicit
8857 -- dereference when needed.
8859 Transform_Object_Operation
8860 (Call_Node => New_Call_Node,
8861 Node_To_Replace => Node_To_Replace);
8863 Set_Etype (New_Call_Node, Any_Type);
8864 Set_Etype (Subprog, Any_Type);
8865 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
8867 if not Is_Overloaded (Obj) then
8868 Try_One_Prefix_Interpretation (Obj_Type);
8875 Get_First_Interp (Obj, I, It);
8876 while Present (It.Nam) loop
8877 Try_One_Prefix_Interpretation (It.Typ);
8878 Get_Next_Interp (I, It);
8883 if Etype (New_Call_Node) /= Any_Type then
8885 -- No need to complete the tree transformations if we are only
8886 -- searching for conflicting class-wide subprograms
8888 if CW_Test_Only then
8891 Complete_Object_Operation
8892 (Call_Node => New_Call_Node,
8893 Node_To_Replace => Node_To_Replace);
8897 elsif Present (Candidate) then
8899 -- The argument list is not type correct. Re-analyze with error
8900 -- reporting enabled, and use one of the possible candidates.
8901 -- In All_Errors_Mode, re-analyze all failed interpretations.
8903 if All_Errors_Mode then
8904 Report_Error := True;
8905 if Try_Primitive_Operation
8906 (Call_Node => New_Call_Node,
8907 Node_To_Replace => Node_To_Replace)
8910 Try_Class_Wide_Operation
8911 (Call_Node => New_Call_Node,
8912 Node_To_Replace => Node_To_Replace)
8919 (N => New_Call_Node,
8923 Skip_First => True);
8926 -- No need for further errors
8931 -- There was no candidate operation, so report it as an error
8932 -- in the caller: Analyze_Selected_Component.
8936 end Try_Object_Operation;
8942 procedure wpo (T : Entity_Id) is
8947 if not Is_Tagged_Type (T) then
8951 E := First_Elmt (Primitive_Operations (Base_Type (T)));
8952 while Present (E) loop
8954 Write_Int (Int (Op));
8955 Write_Str (" === ");
8956 Write_Name (Chars (Op));
8958 Write_Name (Chars (Scope (Op)));