1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, 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 Expander; use Expander;
34 with Fname; use Fname;
35 with Itypes; use Itypes;
37 with Lib.Xref; use Lib.Xref;
38 with Namet; use Namet;
39 with Namet.Sp; use Namet.Sp;
40 with Nlists; use Nlists;
41 with Nmake; use Nmake;
43 with Output; use Output;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
47 with Sem_Aux; use Sem_Aux;
48 with Sem_Case; use Sem_Case;
49 with Sem_Cat; use Sem_Cat;
50 with Sem_Ch3; use Sem_Ch3;
51 with Sem_Ch5; use Sem_Ch5;
52 with Sem_Ch6; use Sem_Ch6;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Disp; use Sem_Disp;
55 with Sem_Dist; use Sem_Dist;
56 with Sem_Eval; use Sem_Eval;
57 with Sem_Res; use Sem_Res;
58 with Sem_Type; use Sem_Type;
59 with Sem_Util; use Sem_Util;
60 with Sem_Warn; use Sem_Warn;
61 with Stand; use Stand;
62 with Sinfo; use Sinfo;
63 with Snames; use Snames;
64 with Tbuild; use Tbuild;
66 package body Sem_Ch4 is
68 -----------------------
69 -- Local Subprograms --
70 -----------------------
72 procedure Analyze_Concatenation_Rest (N : Node_Id);
73 -- Does the "rest" of the work of Analyze_Concatenation, after the left
74 -- operand has been analyzed. See Analyze_Concatenation for details.
76 procedure Analyze_Expression (N : Node_Id);
77 -- For expressions that are not names, this is just a call to analyze.
78 -- If the expression is a name, it may be a call to a parameterless
79 -- function, and if so must be converted into an explicit call node
80 -- and analyzed as such. This deproceduring must be done during the first
81 -- pass of overload resolution, because otherwise a procedure call with
82 -- overloaded actuals may fail to resolve.
84 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
85 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
86 -- is an operator name or an expanded name whose selector is an operator
87 -- name, and one possible interpretation is as a predefined operator.
89 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
90 -- If the prefix of a selected_component is overloaded, the proper
91 -- interpretation that yields a record type with the proper selector
92 -- name must be selected.
94 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
95 -- Procedure to analyze a user defined binary operator, which is resolved
96 -- like a function, but instead of a list of actuals it is presented
97 -- with the left and right operands of an operator node.
99 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
100 -- Procedure to analyze a user defined unary operator, which is resolved
101 -- like a function, but instead of a list of actuals, it is presented with
102 -- the operand of the operator node.
104 procedure Ambiguous_Operands (N : Node_Id);
105 -- For equality, membership, and comparison operators with overloaded
106 -- arguments, list possible interpretations.
108 procedure Analyze_One_Call
112 Success : out Boolean;
113 Skip_First : Boolean := False);
114 -- Check one interpretation of an overloaded subprogram name for
115 -- compatibility with the types of the actuals in a call. If there is a
116 -- single interpretation which does not match, post error if Report is
119 -- Nam is the entity that provides the formals against which the actuals
120 -- are checked. Nam is either the name of a subprogram, or the internal
121 -- subprogram type constructed for an access_to_subprogram. If the actuals
122 -- are compatible with Nam, then Nam is added to the list of candidate
123 -- interpretations for N, and Success is set to True.
125 -- The flag Skip_First is used when analyzing a call that was rewritten
126 -- from object notation. In this case the first actual may have to receive
127 -- an explicit dereference, depending on the first formal of the operation
128 -- being called. The caller will have verified that the object is legal
129 -- for the call. If the remaining parameters match, the first parameter
130 -- will rewritten as a dereference if needed, prior to completing analysis.
132 procedure Check_Misspelled_Selector
135 -- Give possible misspelling diagnostic if Sel is likely to be a mis-
136 -- spelling of one of the selectors of the Prefix. This is called by
137 -- Analyze_Selected_Component after producing an invalid selector error
140 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
141 -- Verify that type T is declared in scope S. Used to find interpretations
142 -- for operators given by expanded names. This is abstracted as a separate
143 -- function to handle extensions to System, where S is System, but T is
144 -- declared in the extension.
146 procedure Find_Arithmetic_Types
150 -- L and R are the operands of an arithmetic operator. Find
151 -- consistent pairs of interpretations for L and R that have a
152 -- numeric type consistent with the semantics of the operator.
154 procedure Find_Comparison_Types
158 -- L and R are operands of a comparison operator. Find consistent
159 -- pairs of interpretations for L and R.
161 procedure Find_Concatenation_Types
165 -- For the four varieties of concatenation
167 procedure Find_Equality_Types
171 -- Ditto for equality operators
173 procedure Find_Boolean_Types
177 -- Ditto for binary logical operations
179 procedure Find_Negation_Types
183 -- Find consistent interpretation for operand of negation operator
185 procedure Find_Non_Universal_Interpretations
190 -- For equality and comparison operators, the result is always boolean,
191 -- and the legality of the operation is determined from the visibility
192 -- of the operand types. If one of the operands has a universal interpre-
193 -- tation, the legality check uses some compatible non-universal
194 -- interpretation of the other operand. N can be an operator node, or
195 -- a function call whose name is an operator designator.
197 function Find_Primitive_Operation (N : Node_Id) return Boolean;
198 -- Find candidate interpretations for the name Obj.Proc when it appears
199 -- in a subprogram renaming declaration.
201 procedure Find_Unary_Types
205 -- Unary arithmetic types: plus, minus, abs
207 procedure Check_Arithmetic_Pair
211 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
212 -- types for left and right operand. Determine whether they constitute
213 -- a valid pair for the given operator, and record the corresponding
214 -- interpretation of the operator node. The node N may be an operator
215 -- node (the usual case) or a function call whose prefix is an operator
216 -- designator. In both cases Op_Id is the operator name itself.
218 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
219 -- Give detailed information on overloaded call where none of the
220 -- interpretations match. N is the call node, Nam the designator for
221 -- the overloaded entity being called.
223 function Junk_Operand (N : Node_Id) return Boolean;
224 -- Test for an operand that is an inappropriate entity (e.g. a package
225 -- name or a label). If so, issue an error message and return True. If
226 -- the operand is not an inappropriate entity kind, return False.
228 procedure Operator_Check (N : Node_Id);
229 -- Verify that an operator has received some valid interpretation. If none
230 -- was found, determine whether a use clause would make the operation
231 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
232 -- every type compatible with the operator, even if the operator for the
233 -- type is not directly visible. The routine uses this type to emit a more
234 -- informative message.
236 function Process_Implicit_Dereference_Prefix
238 P : Node_Id) return Entity_Id;
239 -- Called when P is the prefix of an implicit dereference, denoting an
240 -- object E. The function returns the designated type of the prefix, taking
241 -- into account that the designated type of an anonymous access type may be
242 -- a limited view, when the non-limited view is visible.
243 -- If in semantics only mode (-gnatc or generic), the function also records
244 -- that the prefix is a reference to E, if any. Normally, such a reference
245 -- is generated only when the implicit dereference is expanded into an
246 -- explicit one, but for consistency we must generate the reference when
247 -- expansion is disabled as well.
249 procedure Remove_Abstract_Operations (N : Node_Id);
250 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
251 -- operation is not a candidate interpretation.
253 function Try_Container_Indexing
256 Expr : Node_Id) return Boolean;
257 -- AI05-0139: Generalized indexing to support iterators over containers
259 function Try_Indexed_Call
263 Skip_First : Boolean) return Boolean;
264 -- If a function has defaults for all its actuals, a call to it may in fact
265 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
266 -- interpretation as an indexing, prior to analysis as a call. If both are
267 -- possible, the node is overloaded with both interpretations (same symbol
268 -- but two different types). If the call is written in prefix form, the
269 -- prefix becomes the first parameter in the call, and only the remaining
270 -- actuals must be checked for the presence of defaults.
272 function Try_Indirect_Call
275 Typ : Entity_Id) return Boolean;
276 -- Similarly, a function F that needs no actuals can return an access to a
277 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
278 -- the call may be overloaded with both interpretations.
280 function Try_Object_Operation (N : Node_Id) return Boolean;
281 -- Ada 2005 (AI-252): Support the object.operation notation. If node N
282 -- is a call in this notation, it is transformed into a normal subprogram
283 -- call where the prefix is a parameter, and True is returned. If node
284 -- N is not of this form, it is unchanged, and False is returned.
286 procedure wpo (T : Entity_Id);
287 pragma Warnings (Off, wpo);
288 -- Used for debugging: obtain list of primitive operations even if
289 -- type is not frozen and dispatch table is not built yet.
291 ------------------------
292 -- Ambiguous_Operands --
293 ------------------------
295 procedure Ambiguous_Operands (N : Node_Id) is
296 procedure List_Operand_Interps (Opnd : Node_Id);
298 --------------------------
299 -- List_Operand_Interps --
300 --------------------------
302 procedure List_Operand_Interps (Opnd : Node_Id) is
307 if Is_Overloaded (Opnd) then
308 if Nkind (Opnd) in N_Op then
310 elsif Nkind (Opnd) = N_Function_Call then
312 elsif Ada_Version >= Ada_2012 then
318 Get_First_Interp (Opnd, I, It);
319 while Present (It.Nam) loop
320 if Has_Implicit_Dereference (It.Typ) then
322 ("can be interpreted as implicit dereference", Opnd);
326 Get_Next_Interp (I, It);
337 if Opnd = Left_Opnd (N) then
338 Error_Msg_N ("\left operand has the following interpretations", N);
341 ("\right operand has the following interpretations", N);
345 List_Interps (Nam, Err);
346 end List_Operand_Interps;
348 -- Start of processing for Ambiguous_Operands
351 if Nkind (N) in N_Membership_Test then
352 Error_Msg_N ("ambiguous operands for membership", N);
354 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
355 Error_Msg_N ("ambiguous operands for equality", N);
358 Error_Msg_N ("ambiguous operands for comparison", N);
361 if All_Errors_Mode then
362 List_Operand_Interps (Left_Opnd (N));
363 List_Operand_Interps (Right_Opnd (N));
365 Error_Msg_N ("\use -gnatf switch for details", N);
367 end Ambiguous_Operands;
369 -----------------------
370 -- Analyze_Aggregate --
371 -----------------------
373 -- Most of the analysis of Aggregates requires that the type be known,
374 -- and is therefore put off until resolution.
376 procedure Analyze_Aggregate (N : Node_Id) is
378 if No (Etype (N)) then
379 Set_Etype (N, Any_Composite);
381 end Analyze_Aggregate;
383 -----------------------
384 -- Analyze_Allocator --
385 -----------------------
387 procedure Analyze_Allocator (N : Node_Id) is
388 Loc : constant Source_Ptr := Sloc (N);
389 Sav_Errs : constant Nat := Serious_Errors_Detected;
390 E : Node_Id := Expression (N);
391 Acc_Type : Entity_Id;
397 Check_SPARK_Restriction ("allocator is not allowed", N);
399 -- Deal with allocator restrictions
401 -- In accordance with H.4(7), the No_Allocators restriction only applies
402 -- to user-written allocators. The same consideration applies to the
403 -- No_Allocators_Before_Elaboration restriction.
405 if Comes_From_Source (N) then
406 Check_Restriction (No_Allocators, N);
408 -- Processing for No_Allocators_After_Elaboration, loop to look at
409 -- enclosing context, checking task case and main subprogram case.
413 while Present (P) loop
415 -- In both cases we need a handled sequence of statements, where
416 -- the occurrence of the allocator is within the statements.
418 if Nkind (P) = N_Handled_Sequence_Of_Statements
419 and then Is_List_Member (C)
420 and then List_Containing (C) = Statements (P)
422 -- Check for allocator within task body, this is a definite
423 -- violation of No_Allocators_After_Elaboration we can detect.
425 if Nkind (Original_Node (Parent (P))) = N_Task_Body then
426 Check_Restriction (No_Allocators_After_Elaboration, N);
430 -- The other case is appearance in a subprogram body. This may
431 -- be a violation if this is a library level subprogram, and it
432 -- turns out to be used as the main program, but only the
433 -- binder knows that, so just record the occurrence.
435 if Nkind (Original_Node (Parent (P))) = N_Subprogram_Body
436 and then Nkind (Parent (Parent (P))) = N_Compilation_Unit
438 Set_Has_Allocator (Current_Sem_Unit);
447 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
448 -- any. The expected type for the name is any type. A non-overloading
449 -- rule then requires it to be of a type descended from
450 -- System.Storage_Pools.Subpools.Subpool_Handle.
452 -- This isn't exactly what the AI says, but it seems to be the right
453 -- rule. The AI should be fixed.???
456 Subpool : constant Node_Id := Subpool_Handle_Name (N);
459 if Present (Subpool) then
462 if Is_Overloaded (Subpool) then
463 Error_Msg_N ("ambiguous subpool handle", Subpool);
466 -- Check that Etype (Subpool) is descended from Subpool_Handle
472 -- Analyze the qualified expression or subtype indication
474 if Nkind (E) = N_Qualified_Expression then
475 Acc_Type := Create_Itype (E_Allocator_Type, N);
476 Set_Etype (Acc_Type, Acc_Type);
477 Find_Type (Subtype_Mark (E));
479 -- Analyze the qualified expression, and apply the name resolution
480 -- rule given in 4.7(3).
483 Type_Id := Etype (E);
484 Set_Directly_Designated_Type (Acc_Type, Type_Id);
486 Resolve (Expression (E), Type_Id);
488 if Is_Limited_Type (Type_Id)
489 and then Comes_From_Source (N)
490 and then not In_Instance_Body
492 if not OK_For_Limited_Init (Type_Id, Expression (E)) then
493 Error_Msg_N ("initialization not allowed for limited types", N);
494 Explain_Limited_Type (Type_Id, N);
498 -- A qualified expression requires an exact match of the type,
499 -- class-wide matching is not allowed.
501 -- if Is_Class_Wide_Type (Type_Id)
502 -- and then Base_Type
503 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
505 -- Wrong_Type (Expression (E), Type_Id);
508 Check_Non_Static_Context (Expression (E));
510 -- We don't analyze the qualified expression itself because it's
511 -- part of the allocator
513 Set_Etype (E, Type_Id);
515 -- Case where allocator has a subtype indication
520 Base_Typ : Entity_Id;
523 -- If the allocator includes a N_Subtype_Indication then a
524 -- constraint is present, otherwise the node is a subtype mark.
525 -- Introduce an explicit subtype declaration into the tree
526 -- defining some anonymous subtype and rewrite the allocator to
527 -- use this subtype rather than the subtype indication.
529 -- It is important to introduce the explicit subtype declaration
530 -- so that the bounds of the subtype indication are attached to
531 -- the tree in case the allocator is inside a generic unit.
533 if Nkind (E) = N_Subtype_Indication then
535 -- A constraint is only allowed for a composite type in Ada
536 -- 95. In Ada 83, a constraint is also allowed for an
537 -- access-to-composite type, but the constraint is ignored.
539 Find_Type (Subtype_Mark (E));
540 Base_Typ := Entity (Subtype_Mark (E));
542 if Is_Elementary_Type (Base_Typ) then
543 if not (Ada_Version = Ada_83
544 and then Is_Access_Type (Base_Typ))
546 Error_Msg_N ("constraint not allowed here", E);
548 if Nkind (Constraint (E)) =
549 N_Index_Or_Discriminant_Constraint
551 Error_Msg_N -- CODEFIX
552 ("\if qualified expression was meant, " &
553 "use apostrophe", Constraint (E));
557 -- Get rid of the bogus constraint:
559 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
560 Analyze_Allocator (N);
563 -- Ada 2005, AI-363: if the designated type has a constrained
564 -- partial view, it cannot receive a discriminant constraint,
565 -- and the allocated object is unconstrained.
567 elsif Ada_Version >= Ada_2005
568 and then Has_Constrained_Partial_View (Base_Typ)
571 ("constraint no allowed when type " &
572 "has a constrained partial view", Constraint (E));
575 if Expander_Active then
576 Def_Id := Make_Temporary (Loc, 'S');
579 Make_Subtype_Declaration (Loc,
580 Defining_Identifier => Def_Id,
581 Subtype_Indication => Relocate_Node (E)));
583 if Sav_Errs /= Serious_Errors_Detected
584 and then Nkind (Constraint (E)) =
585 N_Index_Or_Discriminant_Constraint
587 Error_Msg_N -- CODEFIX
588 ("if qualified expression was meant, " &
589 "use apostrophe!", Constraint (E));
592 E := New_Occurrence_Of (Def_Id, Loc);
593 Rewrite (Expression (N), E);
597 Type_Id := Process_Subtype (E, N);
598 Acc_Type := Create_Itype (E_Allocator_Type, N);
599 Set_Etype (Acc_Type, Acc_Type);
600 Set_Directly_Designated_Type (Acc_Type, Type_Id);
601 Check_Fully_Declared (Type_Id, N);
603 -- Ada 2005 (AI-231): If the designated type is itself an access
604 -- type that excludes null, its default initialization will
605 -- be a null object, and we can insert an unconditional raise
606 -- before the allocator.
608 -- Ada 2012 (AI-104): A not null indication here is altogether
611 if Can_Never_Be_Null (Type_Id) then
613 Not_Null_Check : constant Node_Id :=
614 Make_Raise_Constraint_Error (Sloc (E),
615 Reason => CE_Null_Not_Allowed);
618 if Ada_Version >= Ada_2012 then
620 ("an uninitialized allocator cannot have"
621 & " a null exclusion", N);
623 elsif Expander_Active then
624 Insert_Action (N, Not_Null_Check);
625 Analyze (Not_Null_Check);
628 Error_Msg_N ("null value not allowed here?", E);
633 -- Check restriction against dynamically allocated protected
634 -- objects. Note that when limited aggregates are supported,
635 -- a similar test should be applied to an allocator with a
636 -- qualified expression ???
638 if Is_Protected_Type (Type_Id) then
639 Check_Restriction (No_Protected_Type_Allocators, N);
642 -- Check for missing initialization. Skip this check if we already
643 -- had errors on analyzing the allocator, since in that case these
644 -- are probably cascaded errors.
646 if Is_Indefinite_Subtype (Type_Id)
647 and then Serious_Errors_Detected = Sav_Errs
649 if Is_Class_Wide_Type (Type_Id) then
651 ("initialization required in class-wide allocation", N);
653 if Ada_Version < Ada_2005
654 and then Is_Limited_Type (Type_Id)
656 Error_Msg_N ("unconstrained allocation not allowed", N);
658 if Is_Array_Type (Type_Id) then
660 ("\constraint with array bounds required", N);
662 elsif Has_Unknown_Discriminants (Type_Id) then
665 else pragma Assert (Has_Discriminants (Type_Id));
667 ("\constraint with discriminant values required", N);
670 -- Limited Ada 2005 and general non-limited case
674 ("uninitialized unconstrained allocation not allowed",
677 if Is_Array_Type (Type_Id) then
679 ("\qualified expression or constraint with " &
680 "array bounds required", N);
682 elsif Has_Unknown_Discriminants (Type_Id) then
683 Error_Msg_N ("\qualified expression required", N);
685 else pragma Assert (Has_Discriminants (Type_Id));
687 ("\qualified expression or constraint with " &
688 "discriminant values required", N);
696 if Is_Abstract_Type (Type_Id) then
697 Error_Msg_N ("cannot allocate abstract object", E);
700 if Has_Task (Designated_Type (Acc_Type)) then
701 Check_Restriction (No_Tasking, N);
702 Check_Restriction (Max_Tasks, N);
703 Check_Restriction (No_Task_Allocators, N);
706 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
707 -- type is nested, and the designated type needs finalization. The rule
708 -- is conservative in that class-wide types need finalization.
710 if Needs_Finalization (Designated_Type (Acc_Type))
711 and then not Is_Library_Level_Entity (Acc_Type)
713 Check_Restriction (No_Nested_Finalization, N);
716 -- Check that an allocator of a nested access type doesn't create a
717 -- protected object when restriction No_Local_Protected_Objects applies.
718 -- We don't have an equivalent to Has_Task for protected types, so only
719 -- cases where the designated type itself is a protected type are
720 -- currently checked. ???
722 if Is_Protected_Type (Designated_Type (Acc_Type))
723 and then not Is_Library_Level_Entity (Acc_Type)
725 Check_Restriction (No_Local_Protected_Objects, N);
728 -- If the No_Streams restriction is set, check that the type of the
729 -- object is not, and does not contain, any subtype derived from
730 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
731 -- Has_Stream just for efficiency reasons. There is no point in
732 -- spending time on a Has_Stream check if the restriction is not set.
734 if Restriction_Check_Required (No_Streams) then
735 if Has_Stream (Designated_Type (Acc_Type)) then
736 Check_Restriction (No_Streams, N);
740 Set_Etype (N, Acc_Type);
742 if not Is_Library_Level_Entity (Acc_Type) then
743 Check_Restriction (No_Local_Allocators, N);
746 if Serious_Errors_Detected > Sav_Errs then
747 Set_Error_Posted (N);
748 Set_Etype (N, Any_Type);
750 end Analyze_Allocator;
752 ---------------------------
753 -- Analyze_Arithmetic_Op --
754 ---------------------------
756 procedure Analyze_Arithmetic_Op (N : Node_Id) is
757 L : constant Node_Id := Left_Opnd (N);
758 R : constant Node_Id := Right_Opnd (N);
762 Candidate_Type := Empty;
763 Analyze_Expression (L);
764 Analyze_Expression (R);
766 -- If the entity is already set, the node is the instantiation of a
767 -- generic node with a non-local reference, or was manufactured by a
768 -- call to Make_Op_xxx. In either case the entity is known to be valid,
769 -- and we do not need to collect interpretations, instead we just get
770 -- the single possible interpretation.
774 if Present (Op_Id) then
775 if Ekind (Op_Id) = E_Operator then
777 if Nkind_In (N, N_Op_Divide, N_Op_Mod, N_Op_Multiply, N_Op_Rem)
778 and then Treat_Fixed_As_Integer (N)
782 Set_Etype (N, Any_Type);
783 Find_Arithmetic_Types (L, R, Op_Id, N);
787 Set_Etype (N, Any_Type);
788 Add_One_Interp (N, Op_Id, Etype (Op_Id));
791 -- Entity is not already set, so we do need to collect interpretations
794 Op_Id := Get_Name_Entity_Id (Chars (N));
795 Set_Etype (N, Any_Type);
797 while Present (Op_Id) loop
798 if Ekind (Op_Id) = E_Operator
799 and then Present (Next_Entity (First_Entity (Op_Id)))
801 Find_Arithmetic_Types (L, R, Op_Id, N);
803 -- The following may seem superfluous, because an operator cannot
804 -- be generic, but this ignores the cleverness of the author of
807 elsif Is_Overloadable (Op_Id) then
808 Analyze_User_Defined_Binary_Op (N, Op_Id);
811 Op_Id := Homonym (Op_Id);
816 end Analyze_Arithmetic_Op;
822 -- Function, procedure, and entry calls are checked here. The Name in
823 -- the call may be overloaded. The actuals have been analyzed and may
824 -- themselves be overloaded. On exit from this procedure, the node N
825 -- may have zero, one or more interpretations. In the first case an
826 -- error message is produced. In the last case, the node is flagged
827 -- as overloaded and the interpretations are collected in All_Interp.
829 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
830 -- the type-checking is similar to that of other calls.
832 procedure Analyze_Call (N : Node_Id) is
833 Actuals : constant List_Id := Parameter_Associations (N);
838 Success : Boolean := False;
840 Deref : Boolean := False;
841 -- Flag indicates whether an interpretation of the prefix is a
842 -- parameterless call that returns an access_to_subprogram.
844 procedure Check_Mixed_Parameter_And_Named_Associations;
845 -- Check that parameter and named associations are not mixed. This is
846 -- a restriction in SPARK mode.
848 function Name_Denotes_Function return Boolean;
849 -- If the type of the name is an access to subprogram, this may be the
850 -- type of a name, or the return type of the function being called. If
851 -- the name is not an entity then it can denote a protected function.
852 -- Until we distinguish Etype from Return_Type, we must use this routine
853 -- to resolve the meaning of the name in the call.
855 procedure No_Interpretation;
856 -- Output error message when no valid interpretation exists
858 --------------------------------------------------
859 -- Check_Mixed_Parameter_And_Named_Associations --
860 --------------------------------------------------
862 procedure Check_Mixed_Parameter_And_Named_Associations is
864 Named_Seen : Boolean;
869 Actual := First (Actuals);
870 while Present (Actual) loop
871 case Nkind (Actual) is
872 when N_Parameter_Association =>
874 Check_SPARK_Restriction
875 ("named association cannot follow positional one",
885 end Check_Mixed_Parameter_And_Named_Associations;
887 ---------------------------
888 -- Name_Denotes_Function --
889 ---------------------------
891 function Name_Denotes_Function return Boolean is
893 if Is_Entity_Name (Nam) then
894 return Ekind (Entity (Nam)) = E_Function;
896 elsif Nkind (Nam) = N_Selected_Component then
897 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
902 end Name_Denotes_Function;
904 -----------------------
905 -- No_Interpretation --
906 -----------------------
908 procedure No_Interpretation is
909 L : constant Boolean := Is_List_Member (N);
910 K : constant Node_Kind := Nkind (Parent (N));
913 -- If the node is in a list whose parent is not an expression then it
914 -- must be an attempted procedure call.
916 if L and then K not in N_Subexpr then
917 if Ekind (Entity (Nam)) = E_Generic_Procedure then
919 ("must instantiate generic procedure& before call",
923 ("procedure or entry name expected", Nam);
926 -- Check for tasking cases where only an entry call will do
929 and then Nkind_In (K, N_Entry_Call_Alternative,
930 N_Triggering_Alternative)
932 Error_Msg_N ("entry name expected", Nam);
934 -- Otherwise give general error message
937 Error_Msg_N ("invalid prefix in call", Nam);
939 end No_Interpretation;
941 -- Start of processing for Analyze_Call
944 if Restriction_Check_Required (SPARK) then
945 Check_Mixed_Parameter_And_Named_Associations;
948 -- Initialize the type of the result of the call to the error type,
949 -- which will be reset if the type is successfully resolved.
951 Set_Etype (N, Any_Type);
955 if not Is_Overloaded (Nam) then
957 -- Only one interpretation to check
959 if Ekind (Etype (Nam)) = E_Subprogram_Type then
960 Nam_Ent := Etype (Nam);
962 -- If the prefix is an access_to_subprogram, this may be an indirect
963 -- call. This is the case if the name in the call is not an entity
964 -- name, or if it is a function name in the context of a procedure
965 -- call. In this latter case, we have a call to a parameterless
966 -- function that returns a pointer_to_procedure which is the entity
967 -- being called. Finally, F (X) may be a call to a parameterless
968 -- function that returns a pointer to a function with parameters.
970 elsif Is_Access_Type (Etype (Nam))
971 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
973 (not Name_Denotes_Function
974 or else Nkind (N) = N_Procedure_Call_Statement
976 (Nkind (Parent (N)) /= N_Explicit_Dereference
977 and then Is_Entity_Name (Nam)
978 and then No (First_Formal (Entity (Nam)))
979 and then Present (Actuals)))
981 Nam_Ent := Designated_Type (Etype (Nam));
982 Insert_Explicit_Dereference (Nam);
984 -- Selected component case. Simple entry or protected operation,
985 -- where the entry name is given by the selector name.
987 elsif Nkind (Nam) = N_Selected_Component then
988 Nam_Ent := Entity (Selector_Name (Nam));
990 if not Ekind_In (Nam_Ent, E_Entry,
995 Error_Msg_N ("name in call is not a callable entity", Nam);
996 Set_Etype (N, Any_Type);
1000 -- If the name is an Indexed component, it can be a call to a member
1001 -- of an entry family. The prefix must be a selected component whose
1002 -- selector is the entry. Analyze_Procedure_Call normalizes several
1003 -- kinds of call into this form.
1005 elsif Nkind (Nam) = N_Indexed_Component then
1006 if Nkind (Prefix (Nam)) = N_Selected_Component then
1007 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
1009 Error_Msg_N ("name in call is not a callable entity", Nam);
1010 Set_Etype (N, Any_Type);
1014 elsif not Is_Entity_Name (Nam) then
1015 Error_Msg_N ("name in call is not a callable entity", Nam);
1016 Set_Etype (N, Any_Type);
1020 Nam_Ent := Entity (Nam);
1022 -- If no interpretations, give error message
1024 if not Is_Overloadable (Nam_Ent) then
1030 -- Operations generated for RACW stub types are called only through
1031 -- dispatching, and can never be the static interpretation of a call.
1033 if Is_RACW_Stub_Type_Operation (Nam_Ent) then
1038 Analyze_One_Call (N, Nam_Ent, True, Success);
1040 -- If this is an indirect call, the return type of the access_to
1041 -- subprogram may be an incomplete type. At the point of the call,
1042 -- use the full type if available, and at the same time update the
1043 -- return type of the access_to_subprogram.
1046 and then Nkind (Nam) = N_Explicit_Dereference
1047 and then Ekind (Etype (N)) = E_Incomplete_Type
1048 and then Present (Full_View (Etype (N)))
1050 Set_Etype (N, Full_View (Etype (N)));
1051 Set_Etype (Nam_Ent, Etype (N));
1055 -- An overloaded selected component must denote overloaded operations
1056 -- of a concurrent type. The interpretations are attached to the
1057 -- simple name of those operations.
1059 if Nkind (Nam) = N_Selected_Component then
1060 Nam := Selector_Name (Nam);
1063 Get_First_Interp (Nam, X, It);
1065 while Present (It.Nam) loop
1069 -- Name may be call that returns an access to subprogram, or more
1070 -- generally an overloaded expression one of whose interpretations
1071 -- yields an access to subprogram. If the name is an entity, we do
1072 -- not dereference, because the node is a call that returns the
1073 -- access type: note difference between f(x), where the call may
1074 -- return an access subprogram type, and f(x)(y), where the type
1075 -- returned by the call to f is implicitly dereferenced to analyze
1078 if Is_Access_Type (Nam_Ent) then
1079 Nam_Ent := Designated_Type (Nam_Ent);
1081 elsif Is_Access_Type (Etype (Nam_Ent))
1083 (not Is_Entity_Name (Nam)
1084 or else Nkind (N) = N_Procedure_Call_Statement)
1085 and then Ekind (Designated_Type (Etype (Nam_Ent)))
1088 Nam_Ent := Designated_Type (Etype (Nam_Ent));
1090 if Is_Entity_Name (Nam) then
1095 -- If the call has been rewritten from a prefixed call, the first
1096 -- parameter has been analyzed, but may need a subsequent
1097 -- dereference, so skip its analysis now.
1099 if N /= Original_Node (N)
1100 and then Nkind (Original_Node (N)) = Nkind (N)
1101 and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N)))
1102 and then Present (Parameter_Associations (N))
1103 and then Present (Etype (First (Parameter_Associations (N))))
1106 (N, Nam_Ent, False, Success, Skip_First => True);
1108 Analyze_One_Call (N, Nam_Ent, False, Success);
1111 -- If the interpretation succeeds, mark the proper type of the
1112 -- prefix (any valid candidate will do). If not, remove the
1113 -- candidate interpretation. This only needs to be done for
1114 -- overloaded protected operations, for other entities disambi-
1115 -- guation is done directly in Resolve.
1119 and then Nkind (Parent (N)) /= N_Explicit_Dereference
1121 Set_Entity (Nam, It.Nam);
1122 Insert_Explicit_Dereference (Nam);
1123 Set_Etype (Nam, Nam_Ent);
1126 Set_Etype (Nam, It.Typ);
1129 elsif Nkind_In (Name (N), N_Selected_Component,
1135 Get_Next_Interp (X, It);
1138 -- If the name is the result of a function call, it can only
1139 -- be a call to a function returning an access to subprogram.
1140 -- Insert explicit dereference.
1142 if Nkind (Nam) = N_Function_Call then
1143 Insert_Explicit_Dereference (Nam);
1146 if Etype (N) = Any_Type then
1148 -- None of the interpretations is compatible with the actuals
1150 Diagnose_Call (N, Nam);
1152 -- Special checks for uninstantiated put routines
1154 if Nkind (N) = N_Procedure_Call_Statement
1155 and then Is_Entity_Name (Nam)
1156 and then Chars (Nam) = Name_Put
1157 and then List_Length (Actuals) = 1
1160 Arg : constant Node_Id := First (Actuals);
1164 if Nkind (Arg) = N_Parameter_Association then
1165 Typ := Etype (Explicit_Actual_Parameter (Arg));
1170 if Is_Signed_Integer_Type (Typ) then
1172 ("possible missing instantiation of " &
1173 "'Text_'I'O.'Integer_'I'O!", Nam);
1175 elsif Is_Modular_Integer_Type (Typ) then
1177 ("possible missing instantiation of " &
1178 "'Text_'I'O.'Modular_'I'O!", Nam);
1180 elsif Is_Floating_Point_Type (Typ) then
1182 ("possible missing instantiation of " &
1183 "'Text_'I'O.'Float_'I'O!", Nam);
1185 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
1187 ("possible missing instantiation of " &
1188 "'Text_'I'O.'Fixed_'I'O!", Nam);
1190 elsif Is_Decimal_Fixed_Point_Type (Typ) then
1192 ("possible missing instantiation of " &
1193 "'Text_'I'O.'Decimal_'I'O!", Nam);
1195 elsif Is_Enumeration_Type (Typ) then
1197 ("possible missing instantiation of " &
1198 "'Text_'I'O.'Enumeration_'I'O!", Nam);
1203 elsif not Is_Overloaded (N)
1204 and then Is_Entity_Name (Nam)
1206 -- Resolution yields a single interpretation. Verify that the
1207 -- reference has capitalization consistent with the declaration.
1209 Set_Entity_With_Style_Check (Nam, Entity (Nam));
1210 Generate_Reference (Entity (Nam), Nam);
1212 Set_Etype (Nam, Etype (Entity (Nam)));
1214 Remove_Abstract_Operations (N);
1221 -----------------------------
1222 -- Analyze_Case_Expression --
1223 -----------------------------
1225 procedure Analyze_Case_Expression (N : Node_Id) is
1226 Expr : constant Node_Id := Expression (N);
1227 FirstX : constant Node_Id := Expression (First (Alternatives (N)));
1229 Exp_Type : Entity_Id;
1230 Exp_Btype : Entity_Id;
1232 Dont_Care : Boolean;
1233 Others_Present : Boolean;
1235 procedure Non_Static_Choice_Error (Choice : Node_Id);
1236 -- Error routine invoked by the generic instantiation below when
1237 -- the case expression has a non static choice.
1239 package Case_Choices_Processing is new
1240 Generic_Choices_Processing
1241 (Get_Alternatives => Alternatives,
1242 Get_Choices => Discrete_Choices,
1243 Process_Empty_Choice => No_OP,
1244 Process_Non_Static_Choice => Non_Static_Choice_Error,
1245 Process_Associated_Node => No_OP);
1246 use Case_Choices_Processing;
1248 -----------------------------
1249 -- Non_Static_Choice_Error --
1250 -----------------------------
1252 procedure Non_Static_Choice_Error (Choice : Node_Id) is
1254 Flag_Non_Static_Expr
1255 ("choice given in case expression is not static!", Choice);
1256 end Non_Static_Choice_Error;
1258 -- Start of processing for Analyze_Case_Expression
1261 if Comes_From_Source (N) then
1262 Check_Compiler_Unit (N);
1265 Analyze_And_Resolve (Expr, Any_Discrete);
1266 Check_Unset_Reference (Expr);
1267 Exp_Type := Etype (Expr);
1268 Exp_Btype := Base_Type (Exp_Type);
1270 Alt := First (Alternatives (N));
1271 while Present (Alt) loop
1272 Analyze (Expression (Alt));
1276 if not Is_Overloaded (FirstX) then
1277 Set_Etype (N, Etype (FirstX));
1285 Set_Etype (N, Any_Type);
1287 Get_First_Interp (FirstX, I, It);
1288 while Present (It.Nam) loop
1290 -- For each interpretation of the first expression, we only
1291 -- add the interpretation if every other expression in the
1292 -- case expression alternatives has a compatible type.
1294 Alt := Next (First (Alternatives (N)));
1295 while Present (Alt) loop
1296 exit when not Has_Compatible_Type (Expression (Alt), It.Typ);
1301 Add_One_Interp (N, It.Typ, It.Typ);
1304 Get_Next_Interp (I, It);
1309 Exp_Btype := Base_Type (Exp_Type);
1311 -- The expression must be of a discrete type which must be determinable
1312 -- independently of the context in which the expression occurs, but
1313 -- using the fact that the expression must be of a discrete type.
1314 -- Moreover, the type this expression must not be a character literal
1315 -- (which is always ambiguous).
1317 -- If error already reported by Resolve, nothing more to do
1319 if Exp_Btype = Any_Discrete
1320 or else Exp_Btype = Any_Type
1324 elsif Exp_Btype = Any_Character then
1326 ("character literal as case expression is ambiguous", Expr);
1330 -- If the case expression is a formal object of mode in out, then
1331 -- treat it as having a nonstatic subtype by forcing use of the base
1332 -- type (which has to get passed to Check_Case_Choices below). Also
1333 -- use base type when the case expression is parenthesized.
1335 if Paren_Count (Expr) > 0
1336 or else (Is_Entity_Name (Expr)
1337 and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter)
1339 Exp_Type := Exp_Btype;
1342 -- Call instantiated Analyze_Choices which does the rest of the work
1344 Analyze_Choices (N, Exp_Type, Dont_Care, Others_Present);
1346 if Exp_Type = Universal_Integer and then not Others_Present then
1348 ("case on universal integer requires OTHERS choice", Expr);
1350 end Analyze_Case_Expression;
1352 ---------------------------
1353 -- Analyze_Comparison_Op --
1354 ---------------------------
1356 procedure Analyze_Comparison_Op (N : Node_Id) is
1357 L : constant Node_Id := Left_Opnd (N);
1358 R : constant Node_Id := Right_Opnd (N);
1359 Op_Id : Entity_Id := Entity (N);
1362 Set_Etype (N, Any_Type);
1363 Candidate_Type := Empty;
1365 Analyze_Expression (L);
1366 Analyze_Expression (R);
1368 if Present (Op_Id) then
1369 if Ekind (Op_Id) = E_Operator then
1370 Find_Comparison_Types (L, R, Op_Id, N);
1372 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1375 if Is_Overloaded (L) then
1376 Set_Etype (L, Intersect_Types (L, R));
1380 Op_Id := Get_Name_Entity_Id (Chars (N));
1381 while Present (Op_Id) loop
1382 if Ekind (Op_Id) = E_Operator then
1383 Find_Comparison_Types (L, R, Op_Id, N);
1385 Analyze_User_Defined_Binary_Op (N, Op_Id);
1388 Op_Id := Homonym (Op_Id);
1393 end Analyze_Comparison_Op;
1395 ---------------------------
1396 -- Analyze_Concatenation --
1397 ---------------------------
1399 procedure Analyze_Concatenation (N : Node_Id) is
1401 -- We wish to avoid deep recursion, because concatenations are often
1402 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1403 -- operands nonrecursively until we find something that is not a
1404 -- concatenation (A in this case), or has already been analyzed. We
1405 -- analyze that, and then walk back up the tree following Parent
1406 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1407 -- work at each level. The Parent pointers allow us to avoid recursion,
1408 -- and thus avoid running out of memory.
1414 Candidate_Type := Empty;
1416 -- The following code is equivalent to:
1418 -- Set_Etype (N, Any_Type);
1419 -- Analyze_Expression (Left_Opnd (N));
1420 -- Analyze_Concatenation_Rest (N);
1422 -- where the Analyze_Expression call recurses back here if the left
1423 -- operand is a concatenation.
1425 -- Walk down left operands
1428 Set_Etype (NN, Any_Type);
1429 L := Left_Opnd (NN);
1430 exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
1434 -- Now (given the above example) NN is A&B and L is A
1436 -- First analyze L ...
1438 Analyze_Expression (L);
1440 -- ... then walk NN back up until we reach N (where we started), calling
1441 -- Analyze_Concatenation_Rest along the way.
1444 Analyze_Concatenation_Rest (NN);
1448 end Analyze_Concatenation;
1450 --------------------------------
1451 -- Analyze_Concatenation_Rest --
1452 --------------------------------
1454 -- If the only one-dimensional array type in scope is String,
1455 -- this is the resulting type of the operation. Otherwise there
1456 -- will be a concatenation operation defined for each user-defined
1457 -- one-dimensional array.
1459 procedure Analyze_Concatenation_Rest (N : Node_Id) is
1460 L : constant Node_Id := Left_Opnd (N);
1461 R : constant Node_Id := Right_Opnd (N);
1462 Op_Id : Entity_Id := Entity (N);
1467 Analyze_Expression (R);
1469 -- If the entity is present, the node appears in an instance, and
1470 -- denotes a predefined concatenation operation. The resulting type is
1471 -- obtained from the arguments when possible. If the arguments are
1472 -- aggregates, the array type and the concatenation type must be
1475 if Present (Op_Id) then
1476 if Ekind (Op_Id) = E_Operator then
1477 LT := Base_Type (Etype (L));
1478 RT := Base_Type (Etype (R));
1480 if Is_Array_Type (LT)
1481 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1483 Add_One_Interp (N, Op_Id, LT);
1485 elsif Is_Array_Type (RT)
1486 and then LT = Base_Type (Component_Type (RT))
1488 Add_One_Interp (N, Op_Id, RT);
1490 -- If one operand is a string type or a user-defined array type,
1491 -- and the other is a literal, result is of the specific type.
1494 (Root_Type (LT) = Standard_String
1495 or else Scope (LT) /= Standard_Standard)
1496 and then Etype (R) = Any_String
1498 Add_One_Interp (N, Op_Id, LT);
1501 (Root_Type (RT) = Standard_String
1502 or else Scope (RT) /= Standard_Standard)
1503 and then Etype (L) = Any_String
1505 Add_One_Interp (N, Op_Id, RT);
1507 elsif not Is_Generic_Type (Etype (Op_Id)) then
1508 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1511 -- Type and its operations must be visible
1513 Set_Entity (N, Empty);
1514 Analyze_Concatenation (N);
1518 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1522 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1523 while Present (Op_Id) loop
1524 if Ekind (Op_Id) = E_Operator then
1526 -- Do not consider operators declared in dead code, they can
1527 -- not be part of the resolution.
1529 if Is_Eliminated (Op_Id) then
1532 Find_Concatenation_Types (L, R, Op_Id, N);
1536 Analyze_User_Defined_Binary_Op (N, Op_Id);
1539 Op_Id := Homonym (Op_Id);
1544 end Analyze_Concatenation_Rest;
1546 ------------------------------------
1547 -- Analyze_Conditional_Expression --
1548 ------------------------------------
1550 procedure Analyze_Conditional_Expression (N : Node_Id) is
1551 Condition : constant Node_Id := First (Expressions (N));
1552 Then_Expr : constant Node_Id := Next (Condition);
1553 Else_Expr : Node_Id;
1556 -- Defend against error of missing expressions from previous error
1558 if No (Then_Expr) then
1562 Check_SPARK_Restriction ("conditional expression is not allowed", N);
1564 Else_Expr := Next (Then_Expr);
1566 if Comes_From_Source (N) then
1567 Check_Compiler_Unit (N);
1570 Analyze_Expression (Condition);
1571 Analyze_Expression (Then_Expr);
1573 if Present (Else_Expr) then
1574 Analyze_Expression (Else_Expr);
1577 -- If then expression not overloaded, then that decides the type
1579 if not Is_Overloaded (Then_Expr) then
1580 Set_Etype (N, Etype (Then_Expr));
1582 -- Case where then expression is overloaded
1590 Set_Etype (N, Any_Type);
1592 -- Shouldn't the following statement be down in the ELSE of the
1593 -- following loop? ???
1595 Get_First_Interp (Then_Expr, I, It);
1597 -- if no Else_Expression the conditional must be boolean
1599 if No (Else_Expr) then
1600 Set_Etype (N, Standard_Boolean);
1602 -- Else_Expression Present. For each possible intepretation of
1603 -- the Then_Expression, add it only if the Else_Expression has
1604 -- a compatible type.
1607 while Present (It.Nam) loop
1608 if Has_Compatible_Type (Else_Expr, It.Typ) then
1609 Add_One_Interp (N, It.Typ, It.Typ);
1612 Get_Next_Interp (I, It);
1617 end Analyze_Conditional_Expression;
1619 -------------------------
1620 -- Analyze_Equality_Op --
1621 -------------------------
1623 procedure Analyze_Equality_Op (N : Node_Id) is
1624 Loc : constant Source_Ptr := Sloc (N);
1625 L : constant Node_Id := Left_Opnd (N);
1626 R : constant Node_Id := Right_Opnd (N);
1630 Set_Etype (N, Any_Type);
1631 Candidate_Type := Empty;
1633 Analyze_Expression (L);
1634 Analyze_Expression (R);
1636 -- If the entity is set, the node is a generic instance with a non-local
1637 -- reference to the predefined operator or to a user-defined function.
1638 -- It can also be an inequality that is expanded into the negation of a
1639 -- call to a user-defined equality operator.
1641 -- For the predefined case, the result is Boolean, regardless of the
1642 -- type of the operands. The operands may even be limited, if they are
1643 -- generic actuals. If they are overloaded, label the left argument with
1644 -- the common type that must be present, or with the type of the formal
1645 -- of the user-defined function.
1647 if Present (Entity (N)) then
1648 Op_Id := Entity (N);
1650 if Ekind (Op_Id) = E_Operator then
1651 Add_One_Interp (N, Op_Id, Standard_Boolean);
1653 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1656 if Is_Overloaded (L) then
1657 if Ekind (Op_Id) = E_Operator then
1658 Set_Etype (L, Intersect_Types (L, R));
1660 Set_Etype (L, Etype (First_Formal (Op_Id)));
1665 Op_Id := Get_Name_Entity_Id (Chars (N));
1666 while Present (Op_Id) loop
1667 if Ekind (Op_Id) = E_Operator then
1668 Find_Equality_Types (L, R, Op_Id, N);
1670 Analyze_User_Defined_Binary_Op (N, Op_Id);
1673 Op_Id := Homonym (Op_Id);
1677 -- If there was no match, and the operator is inequality, this may
1678 -- be a case where inequality has not been made explicit, as for
1679 -- tagged types. Analyze the node as the negation of an equality
1680 -- operation. This cannot be done earlier, because before analysis
1681 -- we cannot rule out the presence of an explicit inequality.
1683 if Etype (N) = Any_Type
1684 and then Nkind (N) = N_Op_Ne
1686 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1687 while Present (Op_Id) loop
1688 if Ekind (Op_Id) = E_Operator then
1689 Find_Equality_Types (L, R, Op_Id, N);
1691 Analyze_User_Defined_Binary_Op (N, Op_Id);
1694 Op_Id := Homonym (Op_Id);
1697 if Etype (N) /= Any_Type then
1698 Op_Id := Entity (N);
1704 Left_Opnd => Left_Opnd (N),
1705 Right_Opnd => Right_Opnd (N))));
1707 Set_Entity (Right_Opnd (N), Op_Id);
1713 end Analyze_Equality_Op;
1715 ----------------------------------
1716 -- Analyze_Explicit_Dereference --
1717 ----------------------------------
1719 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1720 Loc : constant Source_Ptr := Sloc (N);
1721 P : constant Node_Id := Prefix (N);
1727 function Is_Function_Type return Boolean;
1728 -- Check whether node may be interpreted as an implicit function call
1730 ----------------------
1731 -- Is_Function_Type --
1732 ----------------------
1734 function Is_Function_Type return Boolean is
1739 if not Is_Overloaded (N) then
1740 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1741 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1744 Get_First_Interp (N, I, It);
1745 while Present (It.Nam) loop
1746 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1747 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1752 Get_Next_Interp (I, It);
1757 end Is_Function_Type;
1759 -- Start of processing for Analyze_Explicit_Dereference
1762 Check_SPARK_Restriction ("explicit dereference is not allowed", N);
1765 Set_Etype (N, Any_Type);
1767 -- Test for remote access to subprogram type, and if so return
1768 -- after rewriting the original tree.
1770 if Remote_AST_E_Dereference (P) then
1774 -- Normal processing for other than remote access to subprogram type
1776 if not Is_Overloaded (P) then
1777 if Is_Access_Type (Etype (P)) then
1779 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
1780 -- avoid other problems caused by the Private_Subtype and it is
1781 -- safe to go to the Base_Type because this is the same as
1782 -- converting the access value to its Base_Type.
1785 DT : Entity_Id := Designated_Type (Etype (P));
1788 if Ekind (DT) = E_Private_Subtype
1789 and then Is_For_Access_Subtype (DT)
1791 DT := Base_Type (DT);
1794 -- An explicit dereference is a legal occurrence of an
1795 -- incomplete type imported through a limited_with clause,
1796 -- if the full view is visible.
1798 if From_With_Type (DT)
1799 and then not From_With_Type (Scope (DT))
1801 (Is_Immediately_Visible (Scope (DT))
1803 (Is_Child_Unit (Scope (DT))
1804 and then Is_Visible_Child_Unit (Scope (DT))))
1806 Set_Etype (N, Available_View (DT));
1813 elsif Etype (P) /= Any_Type then
1814 Error_Msg_N ("prefix of dereference must be an access type", N);
1819 Get_First_Interp (P, I, It);
1820 while Present (It.Nam) loop
1823 if Is_Access_Type (T) then
1824 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1827 Get_Next_Interp (I, It);
1830 -- Error if no interpretation of the prefix has an access type
1832 if Etype (N) = Any_Type then
1834 ("access type required in prefix of explicit dereference", P);
1835 Set_Etype (N, Any_Type);
1841 and then Nkind (Parent (N)) /= N_Indexed_Component
1843 and then (Nkind (Parent (N)) /= N_Function_Call
1844 or else N /= Name (Parent (N)))
1846 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1847 or else N /= Name (Parent (N)))
1849 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1850 and then (Nkind (Parent (N)) /= N_Attribute_Reference
1852 (Attribute_Name (Parent (N)) /= Name_Address
1854 Attribute_Name (Parent (N)) /= Name_Access))
1856 -- Name is a function call with no actuals, in a context that
1857 -- requires deproceduring (including as an actual in an enclosing
1858 -- function or procedure call). There are some pathological cases
1859 -- where the prefix might include functions that return access to
1860 -- subprograms and others that return a regular type. Disambiguation
1861 -- of those has to take place in Resolve.
1864 Make_Function_Call (Loc,
1865 Name => Make_Explicit_Dereference (Loc, P),
1866 Parameter_Associations => New_List);
1868 -- If the prefix is overloaded, remove operations that have formals,
1869 -- we know that this is a parameterless call.
1871 if Is_Overloaded (P) then
1872 Get_First_Interp (P, I, It);
1873 while Present (It.Nam) loop
1876 if No (First_Formal (Base_Type (Designated_Type (T)))) then
1882 Get_Next_Interp (I, It);
1889 elsif not Is_Function_Type
1890 and then Is_Overloaded (N)
1892 -- The prefix may include access to subprograms and other access
1893 -- types. If the context selects the interpretation that is a
1894 -- function call (not a procedure call) we cannot rewrite the node
1895 -- yet, but we include the result of the call interpretation.
1897 Get_First_Interp (N, I, It);
1898 while Present (It.Nam) loop
1899 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
1900 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
1901 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
1903 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
1906 Get_Next_Interp (I, It);
1910 -- A value of remote access-to-class-wide must not be dereferenced
1913 Validate_Remote_Access_To_Class_Wide_Type (N);
1914 end Analyze_Explicit_Dereference;
1916 ------------------------
1917 -- Analyze_Expression --
1918 ------------------------
1920 procedure Analyze_Expression (N : Node_Id) is
1923 Check_Parameterless_Call (N);
1924 end Analyze_Expression;
1926 -------------------------------------
1927 -- Analyze_Expression_With_Actions --
1928 -------------------------------------
1930 procedure Analyze_Expression_With_Actions (N : Node_Id) is
1934 A := First (Actions (N));
1941 Analyze_Expression (Expression (N));
1942 Set_Etype (N, Etype (Expression (N)));
1943 end Analyze_Expression_With_Actions;
1945 ------------------------------------
1946 -- Analyze_Indexed_Component_Form --
1947 ------------------------------------
1949 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
1950 P : constant Node_Id := Prefix (N);
1951 Exprs : constant List_Id := Expressions (N);
1957 procedure Process_Function_Call;
1958 -- Prefix in indexed component form is an overloadable entity,
1959 -- so the node is a function call. Reformat it as such.
1961 procedure Process_Indexed_Component;
1962 -- Prefix in indexed component form is actually an indexed component.
1963 -- This routine processes it, knowing that the prefix is already
1966 procedure Process_Indexed_Component_Or_Slice;
1967 -- An indexed component with a single index may designate a slice if
1968 -- the index is a subtype mark. This routine disambiguates these two
1969 -- cases by resolving the prefix to see if it is a subtype mark.
1971 procedure Process_Overloaded_Indexed_Component;
1972 -- If the prefix of an indexed component is overloaded, the proper
1973 -- interpretation is selected by the index types and the context.
1975 ---------------------------
1976 -- Process_Function_Call --
1977 ---------------------------
1979 procedure Process_Function_Call is
1983 Change_Node (N, N_Function_Call);
1985 Set_Parameter_Associations (N, Exprs);
1987 -- Analyze actuals prior to analyzing the call itself
1989 Actual := First (Parameter_Associations (N));
1990 while Present (Actual) loop
1992 Check_Parameterless_Call (Actual);
1994 -- Move to next actual. Note that we use Next, not Next_Actual
1995 -- here. The reason for this is a bit subtle. If a function call
1996 -- includes named associations, the parser recognizes the node as
1997 -- a call, and it is analyzed as such. If all associations are
1998 -- positional, the parser builds an indexed_component node, and
1999 -- it is only after analysis of the prefix that the construct
2000 -- is recognized as a call, in which case Process_Function_Call
2001 -- rewrites the node and analyzes the actuals. If the list of
2002 -- actuals is malformed, the parser may leave the node as an
2003 -- indexed component (despite the presence of named associations).
2004 -- The iterator Next_Actual is equivalent to Next if the list is
2005 -- positional, but follows the normalized chain of actuals when
2006 -- named associations are present. In this case normalization has
2007 -- not taken place, and actuals remain unanalyzed, which leads to
2008 -- subsequent crashes or loops if there is an attempt to continue
2009 -- analysis of the program.
2015 end Process_Function_Call;
2017 -------------------------------
2018 -- Process_Indexed_Component --
2019 -------------------------------
2021 procedure Process_Indexed_Component is
2023 Array_Type : Entity_Id;
2025 Pent : Entity_Id := Empty;
2028 Exp := First (Exprs);
2030 if Is_Overloaded (P) then
2031 Process_Overloaded_Indexed_Component;
2034 Array_Type := Etype (P);
2036 if Is_Entity_Name (P) then
2038 elsif Nkind (P) = N_Selected_Component
2039 and then Is_Entity_Name (Selector_Name (P))
2041 Pent := Entity (Selector_Name (P));
2044 -- Prefix must be appropriate for an array type, taking into
2045 -- account a possible implicit dereference.
2047 if Is_Access_Type (Array_Type) then
2048 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2049 Array_Type := Process_Implicit_Dereference_Prefix (Pent, P);
2052 if Is_Array_Type (Array_Type) then
2055 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
2057 Set_Etype (N, Any_Type);
2059 if not Has_Compatible_Type
2060 (Exp, Entry_Index_Type (Pent))
2062 Error_Msg_N ("invalid index type in entry name", N);
2064 elsif Present (Next (Exp)) then
2065 Error_Msg_N ("too many subscripts in entry reference", N);
2068 Set_Etype (N, Etype (P));
2073 elsif Is_Record_Type (Array_Type)
2074 and then Remote_AST_I_Dereference (P)
2078 elsif Try_Container_Indexing (N, P, Exp) then
2081 elsif Array_Type = Any_Type then
2082 Set_Etype (N, Any_Type);
2084 -- In most cases the analysis of the prefix will have emitted
2085 -- an error already, but if the prefix may be interpreted as a
2086 -- call in prefixed notation, the report is left to the caller.
2087 -- To prevent cascaded errors, report only if no previous ones.
2089 if Serious_Errors_Detected = 0 then
2090 Error_Msg_N ("invalid prefix in indexed component", P);
2092 if Nkind (P) = N_Expanded_Name then
2093 Error_Msg_NE ("\& is not visible", P, Selector_Name (P));
2099 -- Here we definitely have a bad indexing
2102 if Nkind (Parent (N)) = N_Requeue_Statement
2103 and then Present (Pent) and then Ekind (Pent) = E_Entry
2106 ("REQUEUE does not permit parameters", First (Exprs));
2108 elsif Is_Entity_Name (P)
2109 and then Etype (P) = Standard_Void_Type
2111 Error_Msg_NE ("incorrect use of&", P, Entity (P));
2114 Error_Msg_N ("array type required in indexed component", P);
2117 Set_Etype (N, Any_Type);
2121 Index := First_Index (Array_Type);
2122 while Present (Index) and then Present (Exp) loop
2123 if not Has_Compatible_Type (Exp, Etype (Index)) then
2124 Wrong_Type (Exp, Etype (Index));
2125 Set_Etype (N, Any_Type);
2133 Set_Etype (N, Component_Type (Array_Type));
2134 Check_Implicit_Dereference (N, Etype (N));
2136 if Present (Index) then
2138 ("too few subscripts in array reference", First (Exprs));
2140 elsif Present (Exp) then
2141 Error_Msg_N ("too many subscripts in array reference", Exp);
2144 end Process_Indexed_Component;
2146 ----------------------------------------
2147 -- Process_Indexed_Component_Or_Slice --
2148 ----------------------------------------
2150 procedure Process_Indexed_Component_Or_Slice is
2152 Exp := First (Exprs);
2153 while Present (Exp) loop
2154 Analyze_Expression (Exp);
2158 Exp := First (Exprs);
2160 -- If one index is present, and it is a subtype name, then the
2161 -- node denotes a slice (note that the case of an explicit range
2162 -- for a slice was already built as an N_Slice node in the first
2163 -- place, so that case is not handled here).
2165 -- We use a replace rather than a rewrite here because this is one
2166 -- of the cases in which the tree built by the parser is plain wrong.
2169 and then Is_Entity_Name (Exp)
2170 and then Is_Type (Entity (Exp))
2173 Make_Slice (Sloc (N),
2175 Discrete_Range => New_Copy (Exp)));
2178 -- Otherwise (more than one index present, or single index is not
2179 -- a subtype name), then we have the indexed component case.
2182 Process_Indexed_Component;
2184 end Process_Indexed_Component_Or_Slice;
2186 ------------------------------------------
2187 -- Process_Overloaded_Indexed_Component --
2188 ------------------------------------------
2190 procedure Process_Overloaded_Indexed_Component is
2199 Set_Etype (N, Any_Type);
2201 Get_First_Interp (P, I, It);
2202 while Present (It.Nam) loop
2205 if Is_Access_Type (Typ) then
2206 Typ := Designated_Type (Typ);
2207 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2210 if Is_Array_Type (Typ) then
2212 -- Got a candidate: verify that index types are compatible
2214 Index := First_Index (Typ);
2216 Exp := First (Exprs);
2217 while Present (Index) and then Present (Exp) loop
2218 if Has_Compatible_Type (Exp, Etype (Index)) then
2230 if Found and then No (Index) and then No (Exp) then
2232 CT : constant Entity_Id :=
2233 Base_Type (Component_Type (Typ));
2235 Add_One_Interp (N, CT, CT);
2236 Check_Implicit_Dereference (N, CT);
2240 elsif Try_Container_Indexing (N, P, First (Exprs)) then
2245 Get_Next_Interp (I, It);
2248 if Etype (N) = Any_Type then
2249 Error_Msg_N ("no legal interpretation for indexed component", N);
2250 Set_Is_Overloaded (N, False);
2254 end Process_Overloaded_Indexed_Component;
2256 -- Start of processing for Analyze_Indexed_Component_Form
2259 -- Get name of array, function or type
2263 if Nkind_In (N, N_Function_Call, N_Procedure_Call_Statement) then
2265 -- If P is an explicit dereference whose prefix is of a
2266 -- remote access-to-subprogram type, then N has already
2267 -- been rewritten as a subprogram call and analyzed.
2272 pragma Assert (Nkind (N) = N_Indexed_Component);
2274 P_T := Base_Type (Etype (P));
2276 if Is_Entity_Name (P) and then Present (Entity (P)) then
2279 if Is_Type (U_N) then
2281 -- Reformat node as a type conversion
2283 E := Remove_Head (Exprs);
2285 if Present (First (Exprs)) then
2287 ("argument of type conversion must be single expression", N);
2290 Change_Node (N, N_Type_Conversion);
2291 Set_Subtype_Mark (N, P);
2293 Set_Expression (N, E);
2295 -- After changing the node, call for the specific Analysis
2296 -- routine directly, to avoid a double call to the expander.
2298 Analyze_Type_Conversion (N);
2302 if Is_Overloadable (U_N) then
2303 Process_Function_Call;
2305 elsif Ekind (Etype (P)) = E_Subprogram_Type
2306 or else (Is_Access_Type (Etype (P))
2308 Ekind (Designated_Type (Etype (P))) =
2311 -- Call to access_to-subprogram with possible implicit dereference
2313 Process_Function_Call;
2315 elsif Is_Generic_Subprogram (U_N) then
2317 -- A common beginner's (or C++ templates fan) error
2319 Error_Msg_N ("generic subprogram cannot be called", N);
2320 Set_Etype (N, Any_Type);
2324 Process_Indexed_Component_Or_Slice;
2327 -- If not an entity name, prefix is an expression that may denote
2328 -- an array or an access-to-subprogram.
2331 if Ekind (P_T) = E_Subprogram_Type
2332 or else (Is_Access_Type (P_T)
2334 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
2336 Process_Function_Call;
2338 elsif Nkind (P) = N_Selected_Component
2339 and then Is_Overloadable (Entity (Selector_Name (P)))
2341 Process_Function_Call;
2344 -- Indexed component, slice, or a call to a member of a family
2345 -- entry, which will be converted to an entry call later.
2347 Process_Indexed_Component_Or_Slice;
2350 end Analyze_Indexed_Component_Form;
2352 ------------------------
2353 -- Analyze_Logical_Op --
2354 ------------------------
2356 procedure Analyze_Logical_Op (N : Node_Id) is
2357 L : constant Node_Id := Left_Opnd (N);
2358 R : constant Node_Id := Right_Opnd (N);
2359 Op_Id : Entity_Id := Entity (N);
2362 Set_Etype (N, Any_Type);
2363 Candidate_Type := Empty;
2365 Analyze_Expression (L);
2366 Analyze_Expression (R);
2368 if Present (Op_Id) then
2370 if Ekind (Op_Id) = E_Operator then
2371 Find_Boolean_Types (L, R, Op_Id, N);
2373 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2377 Op_Id := Get_Name_Entity_Id (Chars (N));
2378 while Present (Op_Id) loop
2379 if Ekind (Op_Id) = E_Operator then
2380 Find_Boolean_Types (L, R, Op_Id, N);
2382 Analyze_User_Defined_Binary_Op (N, Op_Id);
2385 Op_Id := Homonym (Op_Id);
2390 end Analyze_Logical_Op;
2392 ---------------------------
2393 -- Analyze_Membership_Op --
2394 ---------------------------
2396 procedure Analyze_Membership_Op (N : Node_Id) is
2397 Loc : constant Source_Ptr := Sloc (N);
2398 L : constant Node_Id := Left_Opnd (N);
2399 R : constant Node_Id := Right_Opnd (N);
2401 Index : Interp_Index;
2403 Found : Boolean := False;
2407 procedure Try_One_Interp (T1 : Entity_Id);
2408 -- Routine to try one proposed interpretation. Note that the context
2409 -- of the operation plays no role in resolving the arguments, so that
2410 -- if there is more than one interpretation of the operands that is
2411 -- compatible with a membership test, the operation is ambiguous.
2413 --------------------
2414 -- Try_One_Interp --
2415 --------------------
2417 procedure Try_One_Interp (T1 : Entity_Id) is
2419 if Has_Compatible_Type (R, T1) then
2421 and then Base_Type (T1) /= Base_Type (T_F)
2423 It := Disambiguate (L, I_F, Index, Any_Type);
2425 if It = No_Interp then
2426 Ambiguous_Operands (N);
2427 Set_Etype (L, Any_Type);
2444 procedure Analyze_Set_Membership;
2445 -- If a set of alternatives is present, analyze each and find the
2446 -- common type to which they must all resolve.
2448 ----------------------------
2449 -- Analyze_Set_Membership --
2450 ----------------------------
2452 procedure Analyze_Set_Membership is
2454 Index : Interp_Index;
2456 Candidate_Interps : Node_Id;
2457 Common_Type : Entity_Id := Empty;
2461 Candidate_Interps := L;
2463 if not Is_Overloaded (L) then
2464 Common_Type := Etype (L);
2466 Alt := First (Alternatives (N));
2467 while Present (Alt) loop
2470 if not Has_Compatible_Type (Alt, Common_Type) then
2471 Wrong_Type (Alt, Common_Type);
2478 Alt := First (Alternatives (N));
2479 while Present (Alt) loop
2481 if not Is_Overloaded (Alt) then
2482 Common_Type := Etype (Alt);
2485 Get_First_Interp (Alt, Index, It);
2486 while Present (It.Typ) loop
2488 Has_Compatible_Type (Candidate_Interps, It.Typ)
2490 Remove_Interp (Index);
2493 Get_Next_Interp (Index, It);
2496 Get_First_Interp (Alt, Index, It);
2499 Error_Msg_N ("alternative has no legal type", Alt);
2503 -- If alternative is not overloaded, we have a unique type
2506 Set_Etype (Alt, It.Typ);
2507 Get_Next_Interp (Index, It);
2510 Set_Is_Overloaded (Alt, False);
2511 Common_Type := Etype (Alt);
2514 Candidate_Interps := Alt;
2521 Set_Etype (N, Standard_Boolean);
2523 if Present (Common_Type) then
2524 Set_Etype (L, Common_Type);
2525 Set_Is_Overloaded (L, False);
2528 Error_Msg_N ("cannot resolve membership operation", N);
2530 end Analyze_Set_Membership;
2532 -- Start of processing for Analyze_Membership_Op
2535 Analyze_Expression (L);
2538 and then Ada_Version >= Ada_2012
2540 Analyze_Set_Membership;
2544 if Nkind (R) = N_Range
2545 or else (Nkind (R) = N_Attribute_Reference
2546 and then Attribute_Name (R) = Name_Range)
2550 if not Is_Overloaded (L) then
2551 Try_One_Interp (Etype (L));
2554 Get_First_Interp (L, Index, It);
2555 while Present (It.Typ) loop
2556 Try_One_Interp (It.Typ);
2557 Get_Next_Interp (Index, It);
2561 -- If not a range, it can be a subtype mark, or else it is a degenerate
2562 -- membership test with a singleton value, i.e. a test for equality,
2563 -- if the types are compatible.
2568 if Is_Entity_Name (R)
2569 and then Is_Type (Entity (R))
2572 Check_Fully_Declared (Entity (R), R);
2574 elsif Ada_Version >= Ada_2012
2575 and then Has_Compatible_Type (R, Etype (L))
2577 if Nkind (N) = N_In then
2593 -- In all versions of the language, if we reach this point there
2594 -- is a previous error that will be diagnosed below.
2600 -- Compatibility between expression and subtype mark or range is
2601 -- checked during resolution. The result of the operation is Boolean
2604 Set_Etype (N, Standard_Boolean);
2606 if Comes_From_Source (N)
2607 and then Present (Right_Opnd (N))
2608 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
2610 Error_Msg_N ("membership test not applicable to cpp-class types", N);
2612 end Analyze_Membership_Op;
2614 ----------------------
2615 -- Analyze_Negation --
2616 ----------------------
2618 procedure Analyze_Negation (N : Node_Id) is
2619 R : constant Node_Id := Right_Opnd (N);
2620 Op_Id : Entity_Id := Entity (N);
2623 Set_Etype (N, Any_Type);
2624 Candidate_Type := Empty;
2626 Analyze_Expression (R);
2628 if Present (Op_Id) then
2629 if Ekind (Op_Id) = E_Operator then
2630 Find_Negation_Types (R, Op_Id, N);
2632 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2636 Op_Id := Get_Name_Entity_Id (Chars (N));
2637 while Present (Op_Id) loop
2638 if Ekind (Op_Id) = E_Operator then
2639 Find_Negation_Types (R, Op_Id, N);
2641 Analyze_User_Defined_Unary_Op (N, Op_Id);
2644 Op_Id := Homonym (Op_Id);
2649 end Analyze_Negation;
2655 procedure Analyze_Null (N : Node_Id) is
2657 Check_SPARK_Restriction ("null is not allowed", N);
2659 Set_Etype (N, Any_Access);
2662 ----------------------
2663 -- Analyze_One_Call --
2664 ----------------------
2666 procedure Analyze_One_Call
2670 Success : out Boolean;
2671 Skip_First : Boolean := False)
2673 Actuals : constant List_Id := Parameter_Associations (N);
2674 Prev_T : constant Entity_Id := Etype (N);
2676 Must_Skip : constant Boolean := Skip_First
2677 or else Nkind (Original_Node (N)) = N_Selected_Component
2679 (Nkind (Original_Node (N)) = N_Indexed_Component
2680 and then Nkind (Prefix (Original_Node (N)))
2681 = N_Selected_Component);
2682 -- The first formal must be omitted from the match when trying to find
2683 -- a primitive operation that is a possible interpretation, and also
2684 -- after the call has been rewritten, because the corresponding actual
2685 -- is already known to be compatible, and because this may be an
2686 -- indexing of a call with default parameters.
2690 Is_Indexed : Boolean := False;
2691 Is_Indirect : Boolean := False;
2692 Subp_Type : constant Entity_Id := Etype (Nam);
2695 function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
2696 -- There may be a user-defined operator that hides the current
2697 -- interpretation. We must check for this independently of the
2698 -- analysis of the call with the user-defined operation, because
2699 -- the parameter names may be wrong and yet the hiding takes place.
2700 -- This fixes a problem with ACATS test B34014O.
2702 -- When the type Address is a visible integer type, and the DEC
2703 -- system extension is visible, the predefined operator may be
2704 -- hidden as well, by one of the address operations in auxdec.
2705 -- Finally, The abstract operations on address do not hide the
2706 -- predefined operator (this is the purpose of making them abstract).
2708 procedure Indicate_Name_And_Type;
2709 -- If candidate interpretation matches, indicate name and type of
2710 -- result on call node.
2712 ----------------------------
2713 -- Indicate_Name_And_Type --
2714 ----------------------------
2716 procedure Indicate_Name_And_Type is
2718 Add_One_Interp (N, Nam, Etype (Nam));
2719 Check_Implicit_Dereference (N, Etype (Nam));
2722 -- If the prefix of the call is a name, indicate the entity
2723 -- being called. If it is not a name, it is an expression that
2724 -- denotes an access to subprogram or else an entry or family. In
2725 -- the latter case, the name is a selected component, and the entity
2726 -- being called is noted on the selector.
2728 if not Is_Type (Nam) then
2729 if Is_Entity_Name (Name (N)) then
2730 Set_Entity (Name (N), Nam);
2732 elsif Nkind (Name (N)) = N_Selected_Component then
2733 Set_Entity (Selector_Name (Name (N)), Nam);
2737 if Debug_Flag_E and not Report then
2738 Write_Str (" Overloaded call ");
2739 Write_Int (Int (N));
2740 Write_Str (" compatible with ");
2741 Write_Int (Int (Nam));
2744 end Indicate_Name_And_Type;
2746 ------------------------
2747 -- Operator_Hidden_By --
2748 ------------------------
2750 function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
2751 Act1 : constant Node_Id := First_Actual (N);
2752 Act2 : constant Node_Id := Next_Actual (Act1);
2753 Form1 : constant Entity_Id := First_Formal (Fun);
2754 Form2 : constant Entity_Id := Next_Formal (Form1);
2757 if Ekind (Fun) /= E_Function
2758 or else Is_Abstract_Subprogram (Fun)
2762 elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
2765 elsif Present (Form2) then
2767 No (Act2) or else not Has_Compatible_Type (Act2, Etype (Form2))
2772 elsif Present (Act2) then
2776 -- Now we know that the arity of the operator matches the function,
2777 -- and the function call is a valid interpretation. The function
2778 -- hides the operator if it has the right signature, or if one of
2779 -- its operands is a non-abstract operation on Address when this is
2780 -- a visible integer type.
2782 return Hides_Op (Fun, Nam)
2783 or else Is_Descendent_Of_Address (Etype (Form1))
2786 and then Is_Descendent_Of_Address (Etype (Form2)));
2787 end Operator_Hidden_By;
2789 -- Start of processing for Analyze_One_Call
2794 -- If the subprogram has no formals or if all the formals have defaults,
2795 -- and the return type is an array type, the node may denote an indexing
2796 -- of the result of a parameterless call. In Ada 2005, the subprogram
2797 -- may have one non-defaulted formal, and the call may have been written
2798 -- in prefix notation, so that the rebuilt parameter list has more than
2801 if not Is_Overloadable (Nam)
2802 and then Ekind (Nam) /= E_Subprogram_Type
2803 and then Ekind (Nam) /= E_Entry_Family
2808 -- An indexing requires at least one actual
2810 if not Is_Empty_List (Actuals)
2812 (Needs_No_Actuals (Nam)
2814 (Needs_One_Actual (Nam)
2815 and then Present (Next_Actual (First (Actuals)))))
2817 if Is_Array_Type (Subp_Type) then
2818 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
2820 elsif Is_Access_Type (Subp_Type)
2821 and then Is_Array_Type (Designated_Type (Subp_Type))
2825 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
2827 -- The prefix can also be a parameterless function that returns an
2828 -- access to subprogram, in which case this is an indirect call.
2829 -- If this succeeds, an explicit dereference is added later on,
2830 -- in Analyze_Call or Resolve_Call.
2832 elsif Is_Access_Type (Subp_Type)
2833 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
2835 Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
2840 -- If the call has been transformed into a slice, it is of the form
2841 -- F (Subtype) where F is parameterless. The node has been rewritten in
2842 -- Try_Indexed_Call and there is nothing else to do.
2845 and then Nkind (N) = N_Slice
2851 (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
2855 -- If an indirect call is a possible interpretation, indicate
2856 -- success to the caller.
2862 -- Mismatch in number or names of parameters
2864 elsif Debug_Flag_E then
2865 Write_Str (" normalization fails in call ");
2866 Write_Int (Int (N));
2867 Write_Str (" with subprogram ");
2868 Write_Int (Int (Nam));
2872 -- If the context expects a function call, discard any interpretation
2873 -- that is a procedure. If the node is not overloaded, leave as is for
2874 -- better error reporting when type mismatch is found.
2876 elsif Nkind (N) = N_Function_Call
2877 and then Is_Overloaded (Name (N))
2878 and then Ekind (Nam) = E_Procedure
2882 -- Ditto for function calls in a procedure context
2884 elsif Nkind (N) = N_Procedure_Call_Statement
2885 and then Is_Overloaded (Name (N))
2886 and then Etype (Nam) /= Standard_Void_Type
2890 elsif No (Actuals) then
2892 -- If Normalize succeeds, then there are default parameters for
2895 Indicate_Name_And_Type;
2897 elsif Ekind (Nam) = E_Operator then
2898 if Nkind (N) = N_Procedure_Call_Statement then
2902 -- This can occur when the prefix of the call is an operator
2903 -- name or an expanded name whose selector is an operator name.
2905 Analyze_Operator_Call (N, Nam);
2907 if Etype (N) /= Prev_T then
2909 -- Check that operator is not hidden by a function interpretation
2911 if Is_Overloaded (Name (N)) then
2917 Get_First_Interp (Name (N), I, It);
2918 while Present (It.Nam) loop
2919 if Operator_Hidden_By (It.Nam) then
2920 Set_Etype (N, Prev_T);
2924 Get_Next_Interp (I, It);
2929 -- If operator matches formals, record its name on the call.
2930 -- If the operator is overloaded, Resolve will select the
2931 -- correct one from the list of interpretations. The call
2932 -- node itself carries the first candidate.
2934 Set_Entity (Name (N), Nam);
2937 elsif Report and then Etype (N) = Any_Type then
2938 Error_Msg_N ("incompatible arguments for operator", N);
2942 -- Normalize_Actuals has chained the named associations in the
2943 -- correct order of the formals.
2945 Actual := First_Actual (N);
2946 Formal := First_Formal (Nam);
2948 -- If we are analyzing a call rewritten from object notation, skip
2949 -- first actual, which may be rewritten later as an explicit
2953 Next_Actual (Actual);
2954 Next_Formal (Formal);
2957 while Present (Actual) and then Present (Formal) loop
2958 if Nkind (Parent (Actual)) /= N_Parameter_Association
2959 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
2961 -- The actual can be compatible with the formal, but we must
2962 -- also check that the context is not an address type that is
2963 -- visibly an integer type, as is the case in VMS_64. In this
2964 -- case the use of literals is illegal, except in the body of
2965 -- descendents of system, where arithmetic operations on
2966 -- address are of course used.
2968 if Has_Compatible_Type (Actual, Etype (Formal))
2970 (Etype (Actual) /= Universal_Integer
2971 or else not Is_Descendent_Of_Address (Etype (Formal))
2973 Is_Predefined_File_Name
2974 (Unit_File_Name (Get_Source_Unit (N))))
2976 Next_Actual (Actual);
2977 Next_Formal (Formal);
2980 if Debug_Flag_E then
2981 Write_Str (" type checking fails in call ");
2982 Write_Int (Int (N));
2983 Write_Str (" with formal ");
2984 Write_Int (Int (Formal));
2985 Write_Str (" in subprogram ");
2986 Write_Int (Int (Nam));
2990 if Report and not Is_Indexed and not Is_Indirect then
2992 -- Ada 2005 (AI-251): Complete the error notification
2993 -- to help new Ada 2005 users.
2995 if Is_Class_Wide_Type (Etype (Formal))
2996 and then Is_Interface (Etype (Etype (Formal)))
2997 and then not Interface_Present_In_Ancestor
2998 (Typ => Etype (Actual),
2999 Iface => Etype (Etype (Formal)))
3002 ("(Ada 2005) does not implement interface }",
3003 Actual, Etype (Etype (Formal)));
3006 Wrong_Type (Actual, Etype (Formal));
3008 if Nkind (Actual) = N_Op_Eq
3009 and then Nkind (Left_Opnd (Actual)) = N_Identifier
3011 Formal := First_Formal (Nam);
3012 while Present (Formal) loop
3013 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
3014 Error_Msg_N -- CODEFIX
3015 ("possible misspelling of `='>`!", Actual);
3019 Next_Formal (Formal);
3023 if All_Errors_Mode then
3024 Error_Msg_Sloc := Sloc (Nam);
3026 if Etype (Formal) = Any_Type then
3028 ("there is no legal actual parameter", Actual);
3031 if Is_Overloadable (Nam)
3032 and then Present (Alias (Nam))
3033 and then not Comes_From_Source (Nam)
3036 ("\\ =='> in call to inherited operation & #!",
3039 elsif Ekind (Nam) = E_Subprogram_Type then
3041 Access_To_Subprogram_Typ :
3042 constant Entity_Id :=
3044 (Associated_Node_For_Itype (Nam));
3047 "\\ =='> in call to dereference of &#!",
3048 Actual, Access_To_Subprogram_Typ);
3053 ("\\ =='> in call to &#!", Actual, Nam);
3063 -- Normalize_Actuals has verified that a default value exists
3064 -- for this formal. Current actual names a subsequent formal.
3066 Next_Formal (Formal);
3070 -- On exit, all actuals match
3072 Indicate_Name_And_Type;
3074 end Analyze_One_Call;
3076 ---------------------------
3077 -- Analyze_Operator_Call --
3078 ---------------------------
3080 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
3081 Op_Name : constant Name_Id := Chars (Op_Id);
3082 Act1 : constant Node_Id := First_Actual (N);
3083 Act2 : constant Node_Id := Next_Actual (Act1);
3086 -- Binary operator case
3088 if Present (Act2) then
3090 -- If more than two operands, then not binary operator after all
3092 if Present (Next_Actual (Act2)) then
3095 elsif Op_Name = Name_Op_Add
3096 or else Op_Name = Name_Op_Subtract
3097 or else Op_Name = Name_Op_Multiply
3098 or else Op_Name = Name_Op_Divide
3099 or else Op_Name = Name_Op_Mod
3100 or else Op_Name = Name_Op_Rem
3101 or else Op_Name = Name_Op_Expon
3103 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
3105 elsif Op_Name = Name_Op_And
3106 or else Op_Name = Name_Op_Or
3107 or else Op_Name = Name_Op_Xor
3109 Find_Boolean_Types (Act1, Act2, Op_Id, N);
3111 elsif Op_Name = Name_Op_Lt
3112 or else Op_Name = Name_Op_Le
3113 or else Op_Name = Name_Op_Gt
3114 or else Op_Name = Name_Op_Ge
3116 Find_Comparison_Types (Act1, Act2, Op_Id, N);
3118 elsif Op_Name = Name_Op_Eq
3119 or else Op_Name = Name_Op_Ne
3121 Find_Equality_Types (Act1, Act2, Op_Id, N);
3123 elsif Op_Name = Name_Op_Concat then
3124 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
3126 -- Is this else null correct, or should it be an abort???
3132 -- Unary operator case
3135 if Op_Name = Name_Op_Subtract or else
3136 Op_Name = Name_Op_Add or else
3137 Op_Name = Name_Op_Abs
3139 Find_Unary_Types (Act1, Op_Id, N);
3142 Op_Name = Name_Op_Not
3144 Find_Negation_Types (Act1, Op_Id, N);
3146 -- Is this else null correct, or should it be an abort???
3152 end Analyze_Operator_Call;
3154 -------------------------------------------
3155 -- Analyze_Overloaded_Selected_Component --
3156 -------------------------------------------
3158 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
3159 Nam : constant Node_Id := Prefix (N);
3160 Sel : constant Node_Id := Selector_Name (N);
3167 Set_Etype (Sel, Any_Type);
3169 Get_First_Interp (Nam, I, It);
3170 while Present (It.Typ) loop
3171 if Is_Access_Type (It.Typ) then
3172 T := Designated_Type (It.Typ);
3173 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3178 -- Locate the component. For a private prefix the selector can denote
3181 if Is_Record_Type (T) or else Is_Private_Type (T) then
3183 -- If the prefix is a class-wide type, the visible components are
3184 -- those of the base type.
3186 if Is_Class_Wide_Type (T) then
3190 Comp := First_Entity (T);
3191 while Present (Comp) loop
3192 if Chars (Comp) = Chars (Sel)
3193 and then Is_Visible_Component (Comp)
3196 -- AI05-105: if the context is an object renaming with
3197 -- an anonymous access type, the expected type of the
3198 -- object must be anonymous. This is a name resolution rule.
3200 if Nkind (Parent (N)) /= N_Object_Renaming_Declaration
3201 or else No (Access_Definition (Parent (N)))
3202 or else Ekind (Etype (Comp)) = E_Anonymous_Access_Type
3204 Ekind (Etype (Comp)) = E_Anonymous_Access_Subprogram_Type
3206 Set_Entity (Sel, Comp);
3207 Set_Etype (Sel, Etype (Comp));
3208 Add_One_Interp (N, Etype (Comp), Etype (Comp));
3209 Check_Implicit_Dereference (N, Etype (Comp));
3211 -- This also specifies a candidate to resolve the name.
3212 -- Further overloading will be resolved from context.
3213 -- The selector name itself does not carry overloading
3216 Set_Etype (Nam, It.Typ);
3219 -- Named access type in the context of a renaming
3220 -- declaration with an access definition. Remove
3221 -- inapplicable candidate.
3230 elsif Is_Concurrent_Type (T) then
3231 Comp := First_Entity (T);
3232 while Present (Comp)
3233 and then Comp /= First_Private_Entity (T)
3235 if Chars (Comp) = Chars (Sel) then
3236 if Is_Overloadable (Comp) then
3237 Add_One_Interp (Sel, Comp, Etype (Comp));
3239 Set_Entity_With_Style_Check (Sel, Comp);
3240 Generate_Reference (Comp, Sel);
3243 Set_Etype (Sel, Etype (Comp));
3244 Set_Etype (N, Etype (Comp));
3245 Set_Etype (Nam, It.Typ);
3247 -- For access type case, introduce explicit dereference for
3248 -- more uniform treatment of entry calls. Do this only once
3249 -- if several interpretations yield an access type.
3251 if Is_Access_Type (Etype (Nam))
3252 and then Nkind (Nam) /= N_Explicit_Dereference
3254 Insert_Explicit_Dereference (Nam);
3256 (Warn_On_Dereference, "?implicit dereference", N);
3263 Set_Is_Overloaded (N, Is_Overloaded (Sel));
3266 Get_Next_Interp (I, It);
3269 if Etype (N) = Any_Type
3270 and then not Try_Object_Operation (N)
3272 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
3273 Set_Entity (Sel, Any_Id);
3274 Set_Etype (Sel, Any_Type);
3276 end Analyze_Overloaded_Selected_Component;
3278 ----------------------------------
3279 -- Analyze_Qualified_Expression --
3280 ----------------------------------
3282 procedure Analyze_Qualified_Expression (N : Node_Id) is
3283 Mark : constant Entity_Id := Subtype_Mark (N);
3284 Expr : constant Node_Id := Expression (N);
3290 Analyze_Expression (Expr);
3292 Set_Etype (N, Any_Type);
3297 if T = Any_Type then
3301 Check_Fully_Declared (T, N);
3303 -- If expected type is class-wide, check for exact match before
3304 -- expansion, because if the expression is a dispatching call it
3305 -- may be rewritten as explicit dereference with class-wide result.
3306 -- If expression is overloaded, retain only interpretations that
3307 -- will yield exact matches.
3309 if Is_Class_Wide_Type (T) then
3310 if not Is_Overloaded (Expr) then
3311 if Base_Type (Etype (Expr)) /= Base_Type (T) then
3312 if Nkind (Expr) = N_Aggregate then
3313 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
3315 Wrong_Type (Expr, T);
3320 Get_First_Interp (Expr, I, It);
3322 while Present (It.Nam) loop
3323 if Base_Type (It.Typ) /= Base_Type (T) then
3327 Get_Next_Interp (I, It);
3333 end Analyze_Qualified_Expression;
3335 -----------------------------------
3336 -- Analyze_Quantified_Expression --
3337 -----------------------------------
3339 procedure Analyze_Quantified_Expression (N : Node_Id) is
3340 Loc : constant Source_Ptr := Sloc (N);
3341 Ent : constant Entity_Id :=
3343 (E_Loop, Current_Scope, Sloc (N), 'L');
3348 Expander_Mode_Save_And_Set (False);
3349 Check_SPARK_Restriction ("quantified expression is not allowed", N);
3351 Set_Etype (Ent, Standard_Void_Type);
3352 Set_Parent (Ent, N);
3354 if Present (Loop_Parameter_Specification (N)) then
3356 Make_Iteration_Scheme (Loc,
3357 Loop_Parameter_Specification =>
3358 Loop_Parameter_Specification (N));
3361 Make_Iteration_Scheme (Loc,
3362 Iterator_Specification =>
3363 Iterator_Specification (N));
3367 Set_Parent (Iterator, N);
3368 Analyze_Iteration_Scheme (Iterator);
3370 -- The loop specification may have been converted into an
3371 -- iterator specification during its analysis. Update the
3372 -- quantified node accordingly.
3374 if Present (Iterator_Specification (Iterator)) then
3375 Set_Iterator_Specification
3376 (N, Iterator_Specification (Iterator));
3377 Set_Loop_Parameter_Specification (N, Empty);
3380 Analyze (Condition (N));
3382 Set_Etype (N, Standard_Boolean);
3383 Expander_Mode_Restore;
3384 end Analyze_Quantified_Expression;
3390 procedure Analyze_Range (N : Node_Id) is
3391 L : constant Node_Id := Low_Bound (N);
3392 H : constant Node_Id := High_Bound (N);
3393 I1, I2 : Interp_Index;
3396 procedure Check_Common_Type (T1, T2 : Entity_Id);
3397 -- Verify the compatibility of two types, and choose the
3398 -- non universal one if the other is universal.
3400 procedure Check_High_Bound (T : Entity_Id);
3401 -- Test one interpretation of the low bound against all those
3402 -- of the high bound.
3404 procedure Check_Universal_Expression (N : Node_Id);
3405 -- In Ada83, reject bounds of a universal range that are not
3406 -- literals or entity names.
3408 -----------------------
3409 -- Check_Common_Type --
3410 -----------------------
3412 procedure Check_Common_Type (T1, T2 : Entity_Id) is
3414 if Covers (T1 => T1, T2 => T2)
3416 Covers (T1 => T2, T2 => T1)
3418 if T1 = Universal_Integer
3419 or else T1 = Universal_Real
3420 or else T1 = Any_Character
3422 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
3425 Add_One_Interp (N, T1, T1);
3428 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
3431 end Check_Common_Type;
3433 ----------------------
3434 -- Check_High_Bound --
3435 ----------------------
3437 procedure Check_High_Bound (T : Entity_Id) is
3439 if not Is_Overloaded (H) then
3440 Check_Common_Type (T, Etype (H));
3442 Get_First_Interp (H, I2, It2);
3443 while Present (It2.Typ) loop
3444 Check_Common_Type (T, It2.Typ);
3445 Get_Next_Interp (I2, It2);
3448 end Check_High_Bound;
3450 -----------------------------
3451 -- Is_Universal_Expression --
3452 -----------------------------
3454 procedure Check_Universal_Expression (N : Node_Id) is
3456 if Etype (N) = Universal_Integer
3457 and then Nkind (N) /= N_Integer_Literal
3458 and then not Is_Entity_Name (N)
3459 and then Nkind (N) /= N_Attribute_Reference
3461 Error_Msg_N ("illegal bound in discrete range", N);
3463 end Check_Universal_Expression;
3465 -- Start of processing for Analyze_Range
3468 Set_Etype (N, Any_Type);
3469 Analyze_Expression (L);
3470 Analyze_Expression (H);
3472 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
3476 if not Is_Overloaded (L) then
3477 Check_High_Bound (Etype (L));
3479 Get_First_Interp (L, I1, It1);
3480 while Present (It1.Typ) loop
3481 Check_High_Bound (It1.Typ);
3482 Get_Next_Interp (I1, It1);
3486 -- If result is Any_Type, then we did not find a compatible pair
3488 if Etype (N) = Any_Type then
3489 Error_Msg_N ("incompatible types in range ", N);
3493 if Ada_Version = Ada_83
3495 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
3496 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
3498 Check_Universal_Expression (L);
3499 Check_Universal_Expression (H);
3503 -----------------------
3504 -- Analyze_Reference --
3505 -----------------------
3507 procedure Analyze_Reference (N : Node_Id) is
3508 P : constant Node_Id := Prefix (N);
3511 Acc_Type : Entity_Id;
3516 -- An interesting error check, if we take the 'Reference of an object
3517 -- for which a pragma Atomic or Volatile has been given, and the type
3518 -- of the object is not Atomic or Volatile, then we are in trouble. The
3519 -- problem is that no trace of the atomic/volatile status will remain
3520 -- for the backend to respect when it deals with the resulting pointer,
3521 -- since the pointer type will not be marked atomic (it is a pointer to
3522 -- the base type of the object).
3524 -- It is not clear if that can ever occur, but in case it does, we will
3525 -- generate an error message. Not clear if this message can ever be
3526 -- generated, and pretty clear that it represents a bug if it is, still
3527 -- seems worth checking, except in CodePeer mode where we do not really
3528 -- care and don't want to bother the user.
3532 if Is_Entity_Name (P)
3533 and then Is_Object_Reference (P)
3534 and then not CodePeer_Mode
3539 if (Has_Atomic_Components (E)
3540 and then not Has_Atomic_Components (T))
3542 (Has_Volatile_Components (E)
3543 and then not Has_Volatile_Components (T))
3544 or else (Is_Atomic (E) and then not Is_Atomic (T))
3545 or else (Is_Volatile (E) and then not Is_Volatile (T))
3547 Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
3551 -- Carry on with normal processing
3553 Acc_Type := Create_Itype (E_Allocator_Type, N);
3554 Set_Etype (Acc_Type, Acc_Type);
3555 Set_Directly_Designated_Type (Acc_Type, Etype (P));
3556 Set_Etype (N, Acc_Type);
3557 end Analyze_Reference;
3559 --------------------------------
3560 -- Analyze_Selected_Component --
3561 --------------------------------
3563 -- Prefix is a record type or a task or protected type. In the latter case,
3564 -- the selector must denote a visible entry.
3566 procedure Analyze_Selected_Component (N : Node_Id) is
3567 Name : constant Node_Id := Prefix (N);
3568 Sel : constant Node_Id := Selector_Name (N);
3571 Has_Candidate : Boolean := False;
3574 Pent : Entity_Id := Empty;
3575 Prefix_Type : Entity_Id;
3577 Type_To_Use : Entity_Id;
3578 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
3579 -- a class-wide type, we use its root type, whose components are
3580 -- present in the class-wide type.
3582 Is_Single_Concurrent_Object : Boolean;
3583 -- Set True if the prefix is a single task or a single protected object
3585 procedure Find_Component_In_Instance (Rec : Entity_Id);
3586 -- In an instance, a component of a private extension may not be visible
3587 -- while it was visible in the generic. Search candidate scope for a
3588 -- component with the proper identifier. This is only done if all other
3589 -- searches have failed. When the match is found (it always will be),
3590 -- the Etype of both N and Sel are set from this component, and the
3591 -- entity of Sel is set to reference this component.
3593 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
3594 -- It is known that the parent of N denotes a subprogram call. Comp
3595 -- is an overloadable component of the concurrent type of the prefix.
3596 -- Determine whether all formals of the parent of N and Comp are mode
3597 -- conformant. If the parent node is not analyzed yet it may be an
3598 -- indexed component rather than a function call.
3600 --------------------------------
3601 -- Find_Component_In_Instance --
3602 --------------------------------
3604 procedure Find_Component_In_Instance (Rec : Entity_Id) is
3608 Comp := First_Component (Rec);
3609 while Present (Comp) loop
3610 if Chars (Comp) = Chars (Sel) then
3611 Set_Entity_With_Style_Check (Sel, Comp);
3612 Set_Etype (Sel, Etype (Comp));
3613 Set_Etype (N, Etype (Comp));
3617 Next_Component (Comp);
3620 -- This must succeed because code was legal in the generic
3622 raise Program_Error;
3623 end Find_Component_In_Instance;
3625 ------------------------------
3626 -- Has_Mode_Conformant_Spec --
3627 ------------------------------
3629 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
3630 Comp_Param : Entity_Id;
3632 Param_Typ : Entity_Id;
3635 Comp_Param := First_Formal (Comp);
3637 if Nkind (Parent (N)) = N_Indexed_Component then
3638 Param := First (Expressions (Parent (N)));
3640 Param := First (Parameter_Associations (Parent (N)));
3643 while Present (Comp_Param)
3644 and then Present (Param)
3646 Param_Typ := Find_Parameter_Type (Param);
3648 if Present (Param_Typ)
3650 not Conforming_Types
3651 (Etype (Comp_Param), Param_Typ, Mode_Conformant)
3656 Next_Formal (Comp_Param);
3660 -- One of the specs has additional formals
3662 if Present (Comp_Param) or else Present (Param) then
3667 end Has_Mode_Conformant_Spec;
3669 -- Start of processing for Analyze_Selected_Component
3672 Set_Etype (N, Any_Type);
3674 if Is_Overloaded (Name) then
3675 Analyze_Overloaded_Selected_Component (N);
3678 elsif Etype (Name) = Any_Type then
3679 Set_Entity (Sel, Any_Id);
3680 Set_Etype (Sel, Any_Type);
3684 Prefix_Type := Etype (Name);
3687 if Is_Access_Type (Prefix_Type) then
3689 -- A RACW object can never be used as prefix of a selected component
3690 -- since that means it is dereferenced without being a controlling
3691 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
3692 -- reporting an error, we must check whether this is actually a
3693 -- dispatching call in prefix form.
3695 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
3696 and then Comes_From_Source (N)
3698 if Try_Object_Operation (N) then
3702 ("invalid dereference of a remote access-to-class-wide value",
3706 -- Normal case of selected component applied to access type
3709 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3711 if Is_Entity_Name (Name) then
3712 Pent := Entity (Name);
3713 elsif Nkind (Name) = N_Selected_Component
3714 and then Is_Entity_Name (Selector_Name (Name))
3716 Pent := Entity (Selector_Name (Name));
3719 Prefix_Type := Process_Implicit_Dereference_Prefix (Pent, Name);
3722 -- If we have an explicit dereference of a remote access-to-class-wide
3723 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
3724 -- have to check for the case of a prefix that is a controlling operand
3725 -- of a prefixed dispatching call, as the dereference is legal in that
3726 -- case. Normally this condition is checked in Validate_Remote_Access_
3727 -- To_Class_Wide_Type, but we have to defer the checking for selected
3728 -- component prefixes because of the prefixed dispatching call case.
3729 -- Note that implicit dereferences are checked for this just above.
3731 elsif Nkind (Name) = N_Explicit_Dereference
3732 and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
3733 and then Comes_From_Source (N)
3735 if Try_Object_Operation (N) then
3739 ("invalid dereference of a remote access-to-class-wide value",
3744 -- (Ada 2005): if the prefix is the limited view of a type, and
3745 -- the context already includes the full view, use the full view
3746 -- in what follows, either to retrieve a component of to find
3747 -- a primitive operation. If the prefix is an explicit dereference,
3748 -- set the type of the prefix to reflect this transformation.
3749 -- If the non-limited view is itself an incomplete type, get the
3750 -- full view if available.
3752 if Is_Incomplete_Type (Prefix_Type)
3753 and then From_With_Type (Prefix_Type)
3754 and then Present (Non_Limited_View (Prefix_Type))
3756 Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
3758 if Nkind (N) = N_Explicit_Dereference then
3759 Set_Etype (Prefix (N), Prefix_Type);
3762 elsif Ekind (Prefix_Type) = E_Class_Wide_Type
3763 and then From_With_Type (Prefix_Type)
3764 and then Present (Non_Limited_View (Etype (Prefix_Type)))
3767 Class_Wide_Type (Non_Limited_View (Etype (Prefix_Type)));
3769 if Nkind (N) = N_Explicit_Dereference then
3770 Set_Etype (Prefix (N), Prefix_Type);
3774 if Ekind (Prefix_Type) = E_Private_Subtype then
3775 Prefix_Type := Base_Type (Prefix_Type);
3778 Type_To_Use := Prefix_Type;
3780 -- For class-wide types, use the entity list of the root type. This
3781 -- indirection is specially important for private extensions because
3782 -- only the root type get switched (not the class-wide type).
3784 if Is_Class_Wide_Type (Prefix_Type) then
3785 Type_To_Use := Root_Type (Prefix_Type);
3788 -- If the prefix is a single concurrent object, use its name in error
3789 -- messages, rather than that of its anonymous type.
3791 Is_Single_Concurrent_Object :=
3792 Is_Concurrent_Type (Prefix_Type)
3793 and then Is_Internal_Name (Chars (Prefix_Type))
3794 and then not Is_Derived_Type (Prefix_Type)
3795 and then Is_Entity_Name (Name);
3797 Comp := First_Entity (Type_To_Use);
3799 -- If the selector has an original discriminant, the node appears in
3800 -- an instance. Replace the discriminant with the corresponding one
3801 -- in the current discriminated type. For nested generics, this must
3802 -- be done transitively, so note the new original discriminant.
3804 if Nkind (Sel) = N_Identifier
3805 and then In_Instance
3806 and then Present (Original_Discriminant (Sel))
3808 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
3810 -- Mark entity before rewriting, for completeness and because
3811 -- subsequent semantic checks might examine the original node.
3813 Set_Entity (Sel, Comp);
3814 Rewrite (Selector_Name (N),
3815 New_Occurrence_Of (Comp, Sloc (N)));
3816 Set_Original_Discriminant (Selector_Name (N), Comp);
3817 Set_Etype (N, Etype (Comp));
3818 Check_Implicit_Dereference (N, Etype (Comp));
3820 if Is_Access_Type (Etype (Name)) then
3821 Insert_Explicit_Dereference (Name);
3822 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3825 elsif Is_Record_Type (Prefix_Type) then
3827 -- Find component with given name
3829 while Present (Comp) loop
3830 if Chars (Comp) = Chars (Sel)
3831 and then Is_Visible_Component (Comp)
3833 Set_Entity_With_Style_Check (Sel, Comp);
3834 Set_Etype (Sel, Etype (Comp));
3836 if Ekind (Comp) = E_Discriminant then
3837 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
3839 ("cannot reference discriminant of Unchecked_Union",
3843 if Is_Generic_Type (Prefix_Type)
3845 Is_Generic_Type (Root_Type (Prefix_Type))
3847 Set_Original_Discriminant (Sel, Comp);
3851 -- Resolve the prefix early otherwise it is not possible to
3852 -- build the actual subtype of the component: it may need
3853 -- to duplicate this prefix and duplication is only allowed
3854 -- on fully resolved expressions.
3858 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
3859 -- subtypes in a package specification.
3862 -- limited with Pkg;
3864 -- type Acc_Inc is access Pkg.T;
3866 -- N : Natural := X.all.Comp; -- ERROR, limited view
3867 -- end Pkg; -- Comp is not visible
3869 if Nkind (Name) = N_Explicit_Dereference
3870 and then From_With_Type (Etype (Prefix (Name)))
3871 and then not Is_Potentially_Use_Visible (Etype (Name))
3872 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
3873 N_Package_Specification
3876 ("premature usage of incomplete}", Prefix (Name),
3877 Etype (Prefix (Name)));
3880 -- We never need an actual subtype for the case of a selection
3881 -- for a indexed component of a non-packed array, since in
3882 -- this case gigi generates all the checks and can find the
3883 -- necessary bounds information.
3885 -- We also do not need an actual subtype for the case of a
3886 -- first, last, length, or range attribute applied to a
3887 -- non-packed array, since gigi can again get the bounds in
3888 -- these cases (gigi cannot handle the packed case, since it
3889 -- has the bounds of the packed array type, not the original
3890 -- bounds of the type). However, if the prefix is itself a
3891 -- selected component, as in a.b.c (i), gigi may regard a.b.c
3892 -- as a dynamic-sized temporary, so we do generate an actual
3893 -- subtype for this case.
3895 Parent_N := Parent (N);
3897 if not Is_Packed (Etype (Comp))
3899 ((Nkind (Parent_N) = N_Indexed_Component
3900 and then Nkind (Name) /= N_Selected_Component)
3902 (Nkind (Parent_N) = N_Attribute_Reference
3903 and then (Attribute_Name (Parent_N) = Name_First
3905 Attribute_Name (Parent_N) = Name_Last
3907 Attribute_Name (Parent_N) = Name_Length
3909 Attribute_Name (Parent_N) = Name_Range)))
3911 Set_Etype (N, Etype (Comp));
3913 -- If full analysis is not enabled, we do not generate an
3914 -- actual subtype, because in the absence of expansion
3915 -- reference to a formal of a protected type, for example,
3916 -- will not be properly transformed, and will lead to
3917 -- out-of-scope references in gigi.
3919 -- In all other cases, we currently build an actual subtype.
3920 -- It seems likely that many of these cases can be avoided,
3921 -- but right now, the front end makes direct references to the
3922 -- bounds (e.g. in generating a length check), and if we do
3923 -- not make an actual subtype, we end up getting a direct
3924 -- reference to a discriminant, which will not do.
3926 elsif Full_Analysis then
3928 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
3929 Insert_Action (N, Act_Decl);
3931 if No (Act_Decl) then
3932 Set_Etype (N, Etype (Comp));
3935 -- Component type depends on discriminants. Enter the
3936 -- main attributes of the subtype.
3939 Subt : constant Entity_Id :=
3940 Defining_Identifier (Act_Decl);
3943 Set_Etype (Subt, Base_Type (Etype (Comp)));
3944 Set_Ekind (Subt, Ekind (Etype (Comp)));
3945 Set_Etype (N, Subt);
3949 -- If Full_Analysis not enabled, just set the Etype
3952 Set_Etype (N, Etype (Comp));
3955 Check_Implicit_Dereference (N, Etype (N));
3959 -- If the prefix is a private extension, check only the visible
3960 -- components of the partial view. This must include the tag,
3961 -- which can appear in expanded code in a tag check.
3963 if Ekind (Type_To_Use) = E_Record_Type_With_Private
3964 and then Chars (Selector_Name (N)) /= Name_uTag
3966 exit when Comp = Last_Entity (Type_To_Use);
3972 -- Ada 2005 (AI-252): The selected component can be interpreted as
3973 -- a prefixed view of a subprogram. Depending on the context, this is
3974 -- either a name that can appear in a renaming declaration, or part
3975 -- of an enclosing call given in prefix form.
3977 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
3978 -- selected component should resolve to a name.
3980 if Ada_Version >= Ada_2005
3981 and then Is_Tagged_Type (Prefix_Type)
3982 and then not Is_Concurrent_Type (Prefix_Type)
3984 if Nkind (Parent (N)) = N_Generic_Association
3985 or else Nkind (Parent (N)) = N_Requeue_Statement
3986 or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
3988 if Find_Primitive_Operation (N) then
3992 elsif Try_Object_Operation (N) then
3996 -- If the transformation fails, it will be necessary to redo the
3997 -- analysis with all errors enabled, to indicate candidate
3998 -- interpretations and reasons for each failure ???
4002 elsif Is_Private_Type (Prefix_Type) then
4004 -- Allow access only to discriminants of the type. If the type has
4005 -- no full view, gigi uses the parent type for the components, so we
4006 -- do the same here.
4008 if No (Full_View (Prefix_Type)) then
4009 Type_To_Use := Root_Type (Base_Type (Prefix_Type));
4010 Comp := First_Entity (Type_To_Use);
4013 while Present (Comp) loop
4014 if Chars (Comp) = Chars (Sel) then
4015 if Ekind (Comp) = E_Discriminant then
4016 Set_Entity_With_Style_Check (Sel, Comp);
4017 Generate_Reference (Comp, Sel);
4019 Set_Etype (Sel, Etype (Comp));
4020 Set_Etype (N, Etype (Comp));
4021 Check_Implicit_Dereference (N, Etype (N));
4023 if Is_Generic_Type (Prefix_Type)
4024 or else Is_Generic_Type (Root_Type (Prefix_Type))
4026 Set_Original_Discriminant (Sel, Comp);
4029 -- Before declaring an error, check whether this is tagged
4030 -- private type and a call to a primitive operation.
4032 elsif Ada_Version >= Ada_2005
4033 and then Is_Tagged_Type (Prefix_Type)
4034 and then Try_Object_Operation (N)
4039 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4040 Error_Msg_NE ("invisible selector& for }", N, Sel);
4041 Set_Entity (Sel, Any_Id);
4042 Set_Etype (N, Any_Type);
4051 elsif Is_Concurrent_Type (Prefix_Type) then
4053 -- Find visible operation with given name. For a protected type,
4054 -- the possible candidates are discriminants, entries or protected
4055 -- procedures. For a task type, the set can only include entries or
4056 -- discriminants if the task type is not an enclosing scope. If it
4057 -- is an enclosing scope (e.g. in an inner task) then all entities
4058 -- are visible, but the prefix must denote the enclosing scope, i.e.
4059 -- can only be a direct name or an expanded name.
4061 Set_Etype (Sel, Any_Type);
4062 In_Scope := In_Open_Scopes (Prefix_Type);
4064 while Present (Comp) loop
4065 if Chars (Comp) = Chars (Sel) then
4066 if Is_Overloadable (Comp) then
4067 Add_One_Interp (Sel, Comp, Etype (Comp));
4069 -- If the prefix is tagged, the correct interpretation may
4070 -- lie in the primitive or class-wide operations of the
4071 -- type. Perform a simple conformance check to determine
4072 -- whether Try_Object_Operation should be invoked even if
4073 -- a visible entity is found.
4075 if Is_Tagged_Type (Prefix_Type)
4077 Nkind_In (Parent (N), N_Procedure_Call_Statement,
4079 N_Indexed_Component)
4080 and then Has_Mode_Conformant_Spec (Comp)
4082 Has_Candidate := True;
4085 -- Note: a selected component may not denote a component of a
4086 -- protected type (4.1.3(7)).
4088 elsif Ekind_In (Comp, E_Discriminant, E_Entry_Family)
4090 and then not Is_Protected_Type (Prefix_Type)
4091 and then Is_Entity_Name (Name))
4093 Set_Entity_With_Style_Check (Sel, Comp);
4094 Generate_Reference (Comp, Sel);
4100 Set_Etype (Sel, Etype (Comp));
4101 Set_Etype (N, Etype (Comp));
4103 if Ekind (Comp) = E_Discriminant then
4104 Set_Original_Discriminant (Sel, Comp);
4107 -- For access type case, introduce explicit dereference for
4108 -- more uniform treatment of entry calls.
4110 if Is_Access_Type (Etype (Name)) then
4111 Insert_Explicit_Dereference (Name);
4113 (Warn_On_Dereference, "?implicit dereference", N);
4119 exit when not In_Scope
4121 Comp = First_Private_Entity (Base_Type (Prefix_Type));
4124 -- If there is no visible entity with the given name or none of the
4125 -- visible entities are plausible interpretations, check whether
4126 -- there is some other primitive operation with that name.
4128 if Ada_Version >= Ada_2005
4129 and then Is_Tagged_Type (Prefix_Type)
4131 if (Etype (N) = Any_Type
4132 or else not Has_Candidate)
4133 and then Try_Object_Operation (N)
4137 -- If the context is not syntactically a procedure call, it
4138 -- may be a call to a primitive function declared outside of
4139 -- the synchronized type.
4141 -- If the context is a procedure call, there might still be
4142 -- an overloading between an entry and a primitive procedure
4143 -- declared outside of the synchronized type, called in prefix
4144 -- notation. This is harder to disambiguate because in one case
4145 -- the controlling formal is implicit ???
4147 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
4148 and then Nkind (Parent (N)) /= N_Indexed_Component
4149 and then Try_Object_Operation (N)
4155 if Etype (N) = Any_Type and then Is_Protected_Type (Prefix_Type) then
4156 -- Case of a prefix of a protected type: selector might denote
4157 -- an invisible private component.
4159 Comp := First_Private_Entity (Base_Type (Prefix_Type));
4160 while Present (Comp) and then Chars (Comp) /= Chars (Sel) loop
4164 if Present (Comp) then
4165 if Is_Single_Concurrent_Object then
4166 Error_Msg_Node_2 := Entity (Name);
4167 Error_Msg_NE ("invisible selector& for &", N, Sel);
4170 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4171 Error_Msg_NE ("invisible selector& for }", N, Sel);
4177 Set_Is_Overloaded (N, Is_Overloaded (Sel));
4182 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
4185 -- If N still has no type, the component is not defined in the prefix
4187 if Etype (N) = Any_Type then
4189 if Is_Single_Concurrent_Object then
4190 Error_Msg_Node_2 := Entity (Name);
4191 Error_Msg_NE ("no selector& for&", N, Sel);
4193 Check_Misspelled_Selector (Type_To_Use, Sel);
4195 elsif Is_Generic_Type (Prefix_Type)
4196 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
4197 and then Prefix_Type /= Etype (Prefix_Type)
4198 and then Is_Record_Type (Etype (Prefix_Type))
4200 -- If this is a derived formal type, the parent may have
4201 -- different visibility at this point. Try for an inherited
4202 -- component before reporting an error.
4204 Set_Etype (Prefix (N), Etype (Prefix_Type));
4205 Analyze_Selected_Component (N);
4208 -- Similarly, if this is the actual for a formal derived type, the
4209 -- component inherited from the generic parent may not be visible
4210 -- in the actual, but the selected component is legal.
4212 elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
4213 and then Is_Generic_Actual_Type (Prefix_Type)
4214 and then Present (Full_View (Prefix_Type))
4217 Find_Component_In_Instance
4218 (Generic_Parent_Type (Parent (Prefix_Type)));
4221 -- Finally, the formal and the actual may be private extensions,
4222 -- but the generic is declared in a child unit of the parent, and
4223 -- an additional step is needed to retrieve the proper scope.
4226 and then Present (Parent_Subtype (Etype (Base_Type (Prefix_Type))))
4228 Find_Component_In_Instance
4229 (Parent_Subtype (Etype (Base_Type (Prefix_Type))));
4232 -- Component not found, specialize error message when appropriate
4235 if Ekind (Prefix_Type) = E_Record_Subtype then
4237 -- Check whether this is a component of the base type which
4238 -- is absent from a statically constrained subtype. This will
4239 -- raise constraint error at run time, but is not a compile-
4240 -- time error. When the selector is illegal for base type as
4241 -- well fall through and generate a compilation error anyway.
4243 Comp := First_Component (Base_Type (Prefix_Type));
4244 while Present (Comp) loop
4245 if Chars (Comp) = Chars (Sel)
4246 and then Is_Visible_Component (Comp)
4248 Set_Entity_With_Style_Check (Sel, Comp);
4249 Generate_Reference (Comp, Sel);
4250 Set_Etype (Sel, Etype (Comp));
4251 Set_Etype (N, Etype (Comp));
4253 -- Emit appropriate message. Gigi will replace the
4254 -- node subsequently with the appropriate Raise.
4256 Apply_Compile_Time_Constraint_Error
4257 (N, "component not present in }?",
4258 CE_Discriminant_Check_Failed,
4259 Ent => Prefix_Type, Rep => False);
4260 Set_Raises_Constraint_Error (N);
4264 Next_Component (Comp);
4269 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4270 Error_Msg_NE ("no selector& for}", N, Sel);
4272 Check_Misspelled_Selector (Type_To_Use, Sel);
4275 Set_Entity (Sel, Any_Id);
4276 Set_Etype (Sel, Any_Type);
4278 end Analyze_Selected_Component;
4280 ---------------------------
4281 -- Analyze_Short_Circuit --
4282 ---------------------------
4284 procedure Analyze_Short_Circuit (N : Node_Id) is
4285 L : constant Node_Id := Left_Opnd (N);
4286 R : constant Node_Id := Right_Opnd (N);
4291 Analyze_Expression (L);
4292 Analyze_Expression (R);
4293 Set_Etype (N, Any_Type);
4295 if not Is_Overloaded (L) then
4296 if Root_Type (Etype (L)) = Standard_Boolean
4297 and then Has_Compatible_Type (R, Etype (L))
4299 Add_One_Interp (N, Etype (L), Etype (L));
4303 Get_First_Interp (L, Ind, It);
4304 while Present (It.Typ) loop
4305 if Root_Type (It.Typ) = Standard_Boolean
4306 and then Has_Compatible_Type (R, It.Typ)
4308 Add_One_Interp (N, It.Typ, It.Typ);
4311 Get_Next_Interp (Ind, It);
4315 -- Here we have failed to find an interpretation. Clearly we know that
4316 -- it is not the case that both operands can have an interpretation of
4317 -- Boolean, but this is by far the most likely intended interpretation.
4318 -- So we simply resolve both operands as Booleans, and at least one of
4319 -- these resolutions will generate an error message, and we do not need
4320 -- to give another error message on the short circuit operation itself.
4322 if Etype (N) = Any_Type then
4323 Resolve (L, Standard_Boolean);
4324 Resolve (R, Standard_Boolean);
4325 Set_Etype (N, Standard_Boolean);
4327 end Analyze_Short_Circuit;
4333 procedure Analyze_Slice (N : Node_Id) is
4334 P : constant Node_Id := Prefix (N);
4335 D : constant Node_Id := Discrete_Range (N);
4336 Array_Type : Entity_Id;
4338 procedure Analyze_Overloaded_Slice;
4339 -- If the prefix is overloaded, select those interpretations that
4340 -- yield a one-dimensional array type.
4342 ------------------------------
4343 -- Analyze_Overloaded_Slice --
4344 ------------------------------
4346 procedure Analyze_Overloaded_Slice is
4352 Set_Etype (N, Any_Type);
4354 Get_First_Interp (P, I, It);
4355 while Present (It.Nam) loop
4358 if Is_Access_Type (Typ) then
4359 Typ := Designated_Type (Typ);
4360 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
4363 if Is_Array_Type (Typ)
4364 and then Number_Dimensions (Typ) = 1
4365 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
4367 Add_One_Interp (N, Typ, Typ);
4370 Get_Next_Interp (I, It);
4373 if Etype (N) = Any_Type then
4374 Error_Msg_N ("expect array type in prefix of slice", N);
4376 end Analyze_Overloaded_Slice;
4378 -- Start of processing for Analyze_Slice
4381 Check_SPARK_Restriction ("slice is not allowed", N);
4386 if Is_Overloaded (P) then
4387 Analyze_Overloaded_Slice;
4390 Array_Type := Etype (P);
4391 Set_Etype (N, Any_Type);
4393 if Is_Access_Type (Array_Type) then
4394 Array_Type := Designated_Type (Array_Type);
4395 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
4398 if not Is_Array_Type (Array_Type) then
4399 Wrong_Type (P, Any_Array);
4401 elsif Number_Dimensions (Array_Type) > 1 then
4403 ("type is not one-dimensional array in slice prefix", N);
4406 Has_Compatible_Type (D, Etype (First_Index (Array_Type)))
4408 Wrong_Type (D, Etype (First_Index (Array_Type)));
4411 Set_Etype (N, Array_Type);
4416 -----------------------------
4417 -- Analyze_Type_Conversion --
4418 -----------------------------
4420 procedure Analyze_Type_Conversion (N : Node_Id) is
4421 Expr : constant Node_Id := Expression (N);
4425 -- If Conversion_OK is set, then the Etype is already set, and the
4426 -- only processing required is to analyze the expression. This is
4427 -- used to construct certain "illegal" conversions which are not
4428 -- allowed by Ada semantics, but can be handled OK by Gigi, see
4429 -- Sinfo for further details.
4431 if Conversion_OK (N) then
4436 -- Otherwise full type analysis is required, as well as some semantic
4437 -- checks to make sure the argument of the conversion is appropriate.
4439 Find_Type (Subtype_Mark (N));
4440 T := Entity (Subtype_Mark (N));
4442 Check_Fully_Declared (T, N);
4443 Analyze_Expression (Expr);
4444 Validate_Remote_Type_Type_Conversion (N);
4446 -- Only remaining step is validity checks on the argument. These
4447 -- are skipped if the conversion does not come from the source.
4449 if not Comes_From_Source (N) then
4452 -- If there was an error in a generic unit, no need to replicate the
4453 -- error message. Conversely, constant-folding in the generic may
4454 -- transform the argument of a conversion into a string literal, which
4455 -- is legal. Therefore the following tests are not performed in an
4458 elsif In_Instance then
4461 elsif Nkind (Expr) = N_Null then
4462 Error_Msg_N ("argument of conversion cannot be null", N);
4463 Error_Msg_N ("\use qualified expression instead", N);
4464 Set_Etype (N, Any_Type);
4466 elsif Nkind (Expr) = N_Aggregate then
4467 Error_Msg_N ("argument of conversion cannot be aggregate", N);
4468 Error_Msg_N ("\use qualified expression instead", N);
4470 elsif Nkind (Expr) = N_Allocator then
4471 Error_Msg_N ("argument of conversion cannot be an allocator", N);
4472 Error_Msg_N ("\use qualified expression instead", N);
4474 elsif Nkind (Expr) = N_String_Literal then
4475 Error_Msg_N ("argument of conversion cannot be string literal", N);
4476 Error_Msg_N ("\use qualified expression instead", N);
4478 elsif Nkind (Expr) = N_Character_Literal then
4479 if Ada_Version = Ada_83 then
4482 Error_Msg_N ("argument of conversion cannot be character literal",
4484 Error_Msg_N ("\use qualified expression instead", N);
4487 elsif Nkind (Expr) = N_Attribute_Reference
4489 (Attribute_Name (Expr) = Name_Access or else
4490 Attribute_Name (Expr) = Name_Unchecked_Access or else
4491 Attribute_Name (Expr) = Name_Unrestricted_Access)
4493 Error_Msg_N ("argument of conversion cannot be access", N);
4494 Error_Msg_N ("\use qualified expression instead", N);
4496 end Analyze_Type_Conversion;
4498 ----------------------
4499 -- Analyze_Unary_Op --
4500 ----------------------
4502 procedure Analyze_Unary_Op (N : Node_Id) is
4503 R : constant Node_Id := Right_Opnd (N);
4504 Op_Id : Entity_Id := Entity (N);
4507 Set_Etype (N, Any_Type);
4508 Candidate_Type := Empty;
4510 Analyze_Expression (R);
4512 if Present (Op_Id) then
4513 if Ekind (Op_Id) = E_Operator then
4514 Find_Unary_Types (R, Op_Id, N);
4516 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4520 Op_Id := Get_Name_Entity_Id (Chars (N));
4521 while Present (Op_Id) loop
4522 if Ekind (Op_Id) = E_Operator then
4523 if No (Next_Entity (First_Entity (Op_Id))) then
4524 Find_Unary_Types (R, Op_Id, N);
4527 elsif Is_Overloadable (Op_Id) then
4528 Analyze_User_Defined_Unary_Op (N, Op_Id);
4531 Op_Id := Homonym (Op_Id);
4536 end Analyze_Unary_Op;
4538 ----------------------------------
4539 -- Analyze_Unchecked_Expression --
4540 ----------------------------------
4542 procedure Analyze_Unchecked_Expression (N : Node_Id) is
4544 Analyze (Expression (N), Suppress => All_Checks);
4545 Set_Etype (N, Etype (Expression (N)));
4546 Save_Interps (Expression (N), N);
4547 end Analyze_Unchecked_Expression;
4549 ---------------------------------------
4550 -- Analyze_Unchecked_Type_Conversion --
4551 ---------------------------------------
4553 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
4555 Find_Type (Subtype_Mark (N));
4556 Analyze_Expression (Expression (N));
4557 Set_Etype (N, Entity (Subtype_Mark (N)));
4558 end Analyze_Unchecked_Type_Conversion;
4560 ------------------------------------
4561 -- Analyze_User_Defined_Binary_Op --
4562 ------------------------------------
4564 procedure Analyze_User_Defined_Binary_Op
4569 -- Only do analysis if the operator Comes_From_Source, since otherwise
4570 -- the operator was generated by the expander, and all such operators
4571 -- always refer to the operators in package Standard.
4573 if Comes_From_Source (N) then
4575 F1 : constant Entity_Id := First_Formal (Op_Id);
4576 F2 : constant Entity_Id := Next_Formal (F1);
4579 -- Verify that Op_Id is a visible binary function. Note that since
4580 -- we know Op_Id is overloaded, potentially use visible means use
4581 -- visible for sure (RM 9.4(11)).
4583 if Ekind (Op_Id) = E_Function
4584 and then Present (F2)
4585 and then (Is_Immediately_Visible (Op_Id)
4586 or else Is_Potentially_Use_Visible (Op_Id))
4587 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
4588 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
4590 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4592 -- If the left operand is overloaded, indicate that the
4593 -- current type is a viable candidate. This is redundant
4594 -- in most cases, but for equality and comparison operators
4595 -- where the context does not impose a type on the operands,
4596 -- setting the proper type is necessary to avoid subsequent
4597 -- ambiguities during resolution, when both user-defined and
4598 -- predefined operators may be candidates.
4600 if Is_Overloaded (Left_Opnd (N)) then
4601 Set_Etype (Left_Opnd (N), Etype (F1));
4604 if Debug_Flag_E then
4605 Write_Str ("user defined operator ");
4606 Write_Name (Chars (Op_Id));
4607 Write_Str (" on node ");
4608 Write_Int (Int (N));
4614 end Analyze_User_Defined_Binary_Op;
4616 -----------------------------------
4617 -- Analyze_User_Defined_Unary_Op --
4618 -----------------------------------
4620 procedure Analyze_User_Defined_Unary_Op
4625 -- Only do analysis if the operator Comes_From_Source, since otherwise
4626 -- the operator was generated by the expander, and all such operators
4627 -- always refer to the operators in package Standard.
4629 if Comes_From_Source (N) then
4631 F : constant Entity_Id := First_Formal (Op_Id);
4634 -- Verify that Op_Id is a visible unary function. Note that since
4635 -- we know Op_Id is overloaded, potentially use visible means use
4636 -- visible for sure (RM 9.4(11)).
4638 if Ekind (Op_Id) = E_Function
4639 and then No (Next_Formal (F))
4640 and then (Is_Immediately_Visible (Op_Id)
4641 or else Is_Potentially_Use_Visible (Op_Id))
4642 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
4644 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4648 end Analyze_User_Defined_Unary_Op;
4650 ---------------------------
4651 -- Check_Arithmetic_Pair --
4652 ---------------------------
4654 procedure Check_Arithmetic_Pair
4655 (T1, T2 : Entity_Id;
4659 Op_Name : constant Name_Id := Chars (Op_Id);
4661 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
4662 -- Check whether the fixed-point type Typ has a user-defined operator
4663 -- (multiplication or division) that should hide the corresponding
4664 -- predefined operator. Used to implement Ada 2005 AI-264, to make
4665 -- such operators more visible and therefore useful.
4667 -- If the name of the operation is an expanded name with prefix
4668 -- Standard, the predefined universal fixed operator is available,
4669 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
4671 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
4672 -- Get specific type (i.e. non-universal type if there is one)
4678 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
4679 Bas : constant Entity_Id := Base_Type (Typ);
4685 -- If the universal_fixed operation is given explicitly the rule
4686 -- concerning primitive operations of the type do not apply.
4688 if Nkind (N) = N_Function_Call
4689 and then Nkind (Name (N)) = N_Expanded_Name
4690 and then Entity (Prefix (Name (N))) = Standard_Standard
4695 -- The operation is treated as primitive if it is declared in the
4696 -- same scope as the type, and therefore on the same entity chain.
4698 Ent := Next_Entity (Typ);
4699 while Present (Ent) loop
4700 if Chars (Ent) = Chars (Op) then
4701 F1 := First_Formal (Ent);
4702 F2 := Next_Formal (F1);
4704 -- The operation counts as primitive if either operand or
4705 -- result are of the given base type, and both operands are
4706 -- fixed point types.
4708 if (Base_Type (Etype (F1)) = Bas
4709 and then Is_Fixed_Point_Type (Etype (F2)))
4712 (Base_Type (Etype (F2)) = Bas
4713 and then Is_Fixed_Point_Type (Etype (F1)))
4716 (Base_Type (Etype (Ent)) = Bas
4717 and then Is_Fixed_Point_Type (Etype (F1))
4718 and then Is_Fixed_Point_Type (Etype (F2)))
4734 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
4736 if T1 = Universal_Integer or else T1 = Universal_Real then
4737 return Base_Type (T2);
4739 return Base_Type (T1);
4743 -- Start of processing for Check_Arithmetic_Pair
4746 if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
4748 if Is_Numeric_Type (T1)
4749 and then Is_Numeric_Type (T2)
4750 and then (Covers (T1 => T1, T2 => T2)
4752 Covers (T1 => T2, T2 => T1))
4754 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4757 elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
4759 if Is_Fixed_Point_Type (T1)
4760 and then (Is_Fixed_Point_Type (T2)
4761 or else T2 = Universal_Real)
4763 -- If Treat_Fixed_As_Integer is set then the Etype is already set
4764 -- and no further processing is required (this is the case of an
4765 -- operator constructed by Exp_Fixd for a fixed point operation)
4766 -- Otherwise add one interpretation with universal fixed result
4767 -- If the operator is given in functional notation, it comes
4768 -- from source and Fixed_As_Integer cannot apply.
4770 if (Nkind (N) not in N_Op
4771 or else not Treat_Fixed_As_Integer (N))
4773 (not Has_Fixed_Op (T1, Op_Id)
4774 or else Nkind (Parent (N)) = N_Type_Conversion)
4776 Add_One_Interp (N, Op_Id, Universal_Fixed);
4779 elsif Is_Fixed_Point_Type (T2)
4780 and then (Nkind (N) not in N_Op
4781 or else not Treat_Fixed_As_Integer (N))
4782 and then T1 = Universal_Real
4784 (not Has_Fixed_Op (T1, Op_Id)
4785 or else Nkind (Parent (N)) = N_Type_Conversion)
4787 Add_One_Interp (N, Op_Id, Universal_Fixed);
4789 elsif Is_Numeric_Type (T1)
4790 and then Is_Numeric_Type (T2)
4791 and then (Covers (T1 => T1, T2 => T2)
4793 Covers (T1 => T2, T2 => T1))
4795 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4797 elsif Is_Fixed_Point_Type (T1)
4798 and then (Base_Type (T2) = Base_Type (Standard_Integer)
4799 or else T2 = Universal_Integer)
4801 Add_One_Interp (N, Op_Id, T1);
4803 elsif T2 = Universal_Real
4804 and then Base_Type (T1) = Base_Type (Standard_Integer)
4805 and then Op_Name = Name_Op_Multiply
4807 Add_One_Interp (N, Op_Id, Any_Fixed);
4809 elsif T1 = Universal_Real
4810 and then Base_Type (T2) = Base_Type (Standard_Integer)
4812 Add_One_Interp (N, Op_Id, Any_Fixed);
4814 elsif Is_Fixed_Point_Type (T2)
4815 and then (Base_Type (T1) = Base_Type (Standard_Integer)
4816 or else T1 = Universal_Integer)
4817 and then Op_Name = Name_Op_Multiply
4819 Add_One_Interp (N, Op_Id, T2);
4821 elsif T1 = Universal_Real and then T2 = Universal_Integer then
4822 Add_One_Interp (N, Op_Id, T1);
4824 elsif T2 = Universal_Real
4825 and then T1 = Universal_Integer
4826 and then Op_Name = Name_Op_Multiply
4828 Add_One_Interp (N, Op_Id, T2);
4831 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
4833 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
4834 -- set does not require any special processing, since the Etype is
4835 -- already set (case of operation constructed by Exp_Fixed).
4837 if Is_Integer_Type (T1)
4838 and then (Covers (T1 => T1, T2 => T2)
4840 Covers (T1 => T2, T2 => T1))
4842 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4845 elsif Op_Name = Name_Op_Expon then
4846 if Is_Numeric_Type (T1)
4847 and then not Is_Fixed_Point_Type (T1)
4848 and then (Base_Type (T2) = Base_Type (Standard_Integer)
4849 or else T2 = Universal_Integer)
4851 Add_One_Interp (N, Op_Id, Base_Type (T1));
4854 else pragma Assert (Nkind (N) in N_Op_Shift);
4856 -- If not one of the predefined operators, the node may be one
4857 -- of the intrinsic functions. Its kind is always specific, and
4858 -- we can use it directly, rather than the name of the operation.
4860 if Is_Integer_Type (T1)
4861 and then (Base_Type (T2) = Base_Type (Standard_Integer)
4862 or else T2 = Universal_Integer)
4864 Add_One_Interp (N, Op_Id, Base_Type (T1));
4867 end Check_Arithmetic_Pair;
4869 -------------------------------
4870 -- Check_Misspelled_Selector --
4871 -------------------------------
4873 procedure Check_Misspelled_Selector
4874 (Prefix : Entity_Id;
4877 Max_Suggestions : constant := 2;
4878 Nr_Of_Suggestions : Natural := 0;
4880 Suggestion_1 : Entity_Id := Empty;
4881 Suggestion_2 : Entity_Id := Empty;
4886 -- All the components of the prefix of selector Sel are matched
4887 -- against Sel and a count is maintained of possible misspellings.
4888 -- When at the end of the analysis there are one or two (not more!)
4889 -- possible misspellings, these misspellings will be suggested as
4890 -- possible correction.
4892 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
4894 -- Concurrent types should be handled as well ???
4899 Comp := First_Entity (Prefix);
4900 while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
4901 if Is_Visible_Component (Comp) then
4902 if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
4903 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
4905 case Nr_Of_Suggestions is
4906 when 1 => Suggestion_1 := Comp;
4907 when 2 => Suggestion_2 := Comp;
4908 when others => exit;
4913 Comp := Next_Entity (Comp);
4916 -- Report at most two suggestions
4918 if Nr_Of_Suggestions = 1 then
4919 Error_Msg_NE -- CODEFIX
4920 ("\possible misspelling of&", Sel, Suggestion_1);
4922 elsif Nr_Of_Suggestions = 2 then
4923 Error_Msg_Node_2 := Suggestion_2;
4924 Error_Msg_NE -- CODEFIX
4925 ("\possible misspelling of& or&", Sel, Suggestion_1);
4927 end Check_Misspelled_Selector;
4929 ----------------------
4930 -- Defined_In_Scope --
4931 ----------------------
4933 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
4935 S1 : constant Entity_Id := Scope (Base_Type (T));
4938 or else (S1 = System_Aux_Id and then S = Scope (S1));
4939 end Defined_In_Scope;
4945 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
4951 Void_Interp_Seen : Boolean := False;
4954 pragma Warnings (Off, Boolean);
4957 if Ada_Version >= Ada_2005 then
4958 Actual := First_Actual (N);
4959 while Present (Actual) loop
4961 -- Ada 2005 (AI-50217): Post an error in case of premature
4962 -- usage of an entity from the limited view.
4964 if not Analyzed (Etype (Actual))
4965 and then From_With_Type (Etype (Actual))
4967 Error_Msg_Qual_Level := 1;
4969 ("missing with_clause for scope of imported type&",
4970 Actual, Etype (Actual));
4971 Error_Msg_Qual_Level := 0;
4974 Next_Actual (Actual);
4978 -- Analyze each candidate call again, with full error reporting
4982 ("no candidate interpretations match the actuals:!", Nam);
4983 Err_Mode := All_Errors_Mode;
4984 All_Errors_Mode := True;
4986 -- If this is a call to an operation of a concurrent type,
4987 -- the failed interpretations have been removed from the
4988 -- name. Recover them to provide full diagnostics.
4990 if Nkind (Parent (Nam)) = N_Selected_Component then
4991 Set_Entity (Nam, Empty);
4992 New_Nam := New_Copy_Tree (Parent (Nam));
4993 Set_Is_Overloaded (New_Nam, False);
4994 Set_Is_Overloaded (Selector_Name (New_Nam), False);
4995 Set_Parent (New_Nam, Parent (Parent (Nam)));
4996 Analyze_Selected_Component (New_Nam);
4997 Get_First_Interp (Selector_Name (New_Nam), X, It);
4999 Get_First_Interp (Nam, X, It);
5002 while Present (It.Nam) loop
5003 if Etype (It.Nam) = Standard_Void_Type then
5004 Void_Interp_Seen := True;
5007 Analyze_One_Call (N, It.Nam, True, Success);
5008 Get_Next_Interp (X, It);
5011 if Nkind (N) = N_Function_Call then
5012 Get_First_Interp (Nam, X, It);
5013 while Present (It.Nam) loop
5014 if Ekind_In (It.Nam, E_Function, E_Operator) then
5017 Get_Next_Interp (X, It);
5021 -- If all interpretations are procedures, this deserves a
5022 -- more precise message. Ditto if this appears as the prefix
5023 -- of a selected component, which may be a lexical error.
5026 ("\context requires function call, found procedure name", Nam);
5028 if Nkind (Parent (N)) = N_Selected_Component
5029 and then N = Prefix (Parent (N))
5031 Error_Msg_N -- CODEFIX
5032 ("\period should probably be semicolon", Parent (N));
5035 elsif Nkind (N) = N_Procedure_Call_Statement
5036 and then not Void_Interp_Seen
5039 "\function name found in procedure call", Nam);
5042 All_Errors_Mode := Err_Mode;
5045 ---------------------------
5046 -- Find_Arithmetic_Types --
5047 ---------------------------
5049 procedure Find_Arithmetic_Types
5054 Index1 : Interp_Index;
5055 Index2 : Interp_Index;
5059 procedure Check_Right_Argument (T : Entity_Id);
5060 -- Check right operand of operator
5062 --------------------------
5063 -- Check_Right_Argument --
5064 --------------------------
5066 procedure Check_Right_Argument (T : Entity_Id) is
5068 if not Is_Overloaded (R) then
5069 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
5071 Get_First_Interp (R, Index2, It2);
5072 while Present (It2.Typ) loop
5073 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
5074 Get_Next_Interp (Index2, It2);
5077 end Check_Right_Argument;
5079 -- Start of processing for Find_Arithmetic_Types
5082 if not Is_Overloaded (L) then
5083 Check_Right_Argument (Etype (L));
5086 Get_First_Interp (L, Index1, It1);
5087 while Present (It1.Typ) loop
5088 Check_Right_Argument (It1.Typ);
5089 Get_Next_Interp (Index1, It1);
5093 end Find_Arithmetic_Types;
5095 ------------------------
5096 -- Find_Boolean_Types --
5097 ------------------------
5099 procedure Find_Boolean_Types
5104 Index : Interp_Index;
5107 procedure Check_Numeric_Argument (T : Entity_Id);
5108 -- Special case for logical operations one of whose operands is an
5109 -- integer literal. If both are literal the result is any modular type.
5111 ----------------------------
5112 -- Check_Numeric_Argument --
5113 ----------------------------
5115 procedure Check_Numeric_Argument (T : Entity_Id) is
5117 if T = Universal_Integer then
5118 Add_One_Interp (N, Op_Id, Any_Modular);
5120 elsif Is_Modular_Integer_Type (T) then
5121 Add_One_Interp (N, Op_Id, T);
5123 end Check_Numeric_Argument;
5125 -- Start of processing for Find_Boolean_Types
5128 if not Is_Overloaded (L) then
5129 if Etype (L) = Universal_Integer
5130 or else Etype (L) = Any_Modular
5132 if not Is_Overloaded (R) then
5133 Check_Numeric_Argument (Etype (R));
5136 Get_First_Interp (R, Index, It);
5137 while Present (It.Typ) loop
5138 Check_Numeric_Argument (It.Typ);
5139 Get_Next_Interp (Index, It);
5143 -- If operands are aggregates, we must assume that they may be
5144 -- boolean arrays, and leave disambiguation for the second pass.
5145 -- If only one is an aggregate, verify that the other one has an
5146 -- interpretation as a boolean array
5148 elsif Nkind (L) = N_Aggregate then
5149 if Nkind (R) = N_Aggregate then
5150 Add_One_Interp (N, Op_Id, Etype (L));
5152 elsif not Is_Overloaded (R) then
5153 if Valid_Boolean_Arg (Etype (R)) then
5154 Add_One_Interp (N, Op_Id, Etype (R));
5158 Get_First_Interp (R, Index, It);
5159 while Present (It.Typ) loop
5160 if Valid_Boolean_Arg (It.Typ) then
5161 Add_One_Interp (N, Op_Id, It.Typ);
5164 Get_Next_Interp (Index, It);
5168 elsif Valid_Boolean_Arg (Etype (L))
5169 and then Has_Compatible_Type (R, Etype (L))
5171 Add_One_Interp (N, Op_Id, Etype (L));
5175 Get_First_Interp (L, Index, It);
5176 while Present (It.Typ) loop
5177 if Valid_Boolean_Arg (It.Typ)
5178 and then Has_Compatible_Type (R, It.Typ)
5180 Add_One_Interp (N, Op_Id, It.Typ);
5183 Get_Next_Interp (Index, It);
5186 end Find_Boolean_Types;
5188 ---------------------------
5189 -- Find_Comparison_Types --
5190 ---------------------------
5192 procedure Find_Comparison_Types
5197 Index : Interp_Index;
5199 Found : Boolean := False;
5202 Scop : Entity_Id := Empty;
5204 procedure Try_One_Interp (T1 : Entity_Id);
5205 -- Routine to try one proposed interpretation. Note that the context
5206 -- of the operator plays no role in resolving the arguments, so that
5207 -- if there is more than one interpretation of the operands that is
5208 -- compatible with comparison, the operation is ambiguous.
5210 --------------------
5211 -- Try_One_Interp --
5212 --------------------
5214 procedure Try_One_Interp (T1 : Entity_Id) is
5217 -- If the operator is an expanded name, then the type of the operand
5218 -- must be defined in the corresponding scope. If the type is
5219 -- universal, the context will impose the correct type.
5222 and then not Defined_In_Scope (T1, Scop)
5223 and then T1 /= Universal_Integer
5224 and then T1 /= Universal_Real
5225 and then T1 /= Any_String
5226 and then T1 /= Any_Composite
5231 if Valid_Comparison_Arg (T1)
5232 and then Has_Compatible_Type (R, T1)
5235 and then Base_Type (T1) /= Base_Type (T_F)
5237 It := Disambiguate (L, I_F, Index, Any_Type);
5239 if It = No_Interp then
5240 Ambiguous_Operands (N);
5241 Set_Etype (L, Any_Type);
5255 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
5260 -- Start of processing for Find_Comparison_Types
5263 -- If left operand is aggregate, the right operand has to
5264 -- provide a usable type for it.
5266 if Nkind (L) = N_Aggregate
5267 and then Nkind (R) /= N_Aggregate
5269 Find_Comparison_Types (L => R, R => L, Op_Id => Op_Id, N => N);
5273 if Nkind (N) = N_Function_Call
5274 and then Nkind (Name (N)) = N_Expanded_Name
5276 Scop := Entity (Prefix (Name (N)));
5278 -- The prefix may be a package renaming, and the subsequent test
5279 -- requires the original package.
5281 if Ekind (Scop) = E_Package
5282 and then Present (Renamed_Entity (Scop))
5284 Scop := Renamed_Entity (Scop);
5285 Set_Entity (Prefix (Name (N)), Scop);
5289 if not Is_Overloaded (L) then
5290 Try_One_Interp (Etype (L));
5293 Get_First_Interp (L, Index, It);
5294 while Present (It.Typ) loop
5295 Try_One_Interp (It.Typ);
5296 Get_Next_Interp (Index, It);
5299 end Find_Comparison_Types;
5301 ----------------------------------------
5302 -- Find_Non_Universal_Interpretations --
5303 ----------------------------------------
5305 procedure Find_Non_Universal_Interpretations
5311 Index : Interp_Index;
5315 if T1 = Universal_Integer
5316 or else T1 = Universal_Real
5318 if not Is_Overloaded (R) then
5320 (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
5322 Get_First_Interp (R, Index, It);
5323 while Present (It.Typ) loop
5324 if Covers (It.Typ, T1) then
5326 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
5329 Get_Next_Interp (Index, It);
5333 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
5335 end Find_Non_Universal_Interpretations;
5337 ------------------------------
5338 -- Find_Concatenation_Types --
5339 ------------------------------
5341 procedure Find_Concatenation_Types
5346 Op_Type : constant Entity_Id := Etype (Op_Id);
5349 if Is_Array_Type (Op_Type)
5350 and then not Is_Limited_Type (Op_Type)
5352 and then (Has_Compatible_Type (L, Op_Type)
5354 Has_Compatible_Type (L, Component_Type (Op_Type)))
5356 and then (Has_Compatible_Type (R, Op_Type)
5358 Has_Compatible_Type (R, Component_Type (Op_Type)))
5360 Add_One_Interp (N, Op_Id, Op_Type);
5362 end Find_Concatenation_Types;
5364 -------------------------
5365 -- Find_Equality_Types --
5366 -------------------------
5368 procedure Find_Equality_Types
5373 Index : Interp_Index;
5375 Found : Boolean := False;
5378 Scop : Entity_Id := Empty;
5380 procedure Try_One_Interp (T1 : Entity_Id);
5381 -- The context of the equality operator plays no role in resolving the
5382 -- arguments, so that if there is more than one interpretation of the
5383 -- operands that is compatible with equality, the construct is ambiguous
5384 -- and an error can be emitted now, after trying to disambiguate, i.e.
5385 -- applying preference rules.
5387 --------------------
5388 -- Try_One_Interp --
5389 --------------------
5391 procedure Try_One_Interp (T1 : Entity_Id) is
5392 Bas : constant Entity_Id := Base_Type (T1);
5395 -- If the operator is an expanded name, then the type of the operand
5396 -- must be defined in the corresponding scope. If the type is
5397 -- universal, the context will impose the correct type. An anonymous
5398 -- type for a 'Access reference is also universal in this sense, as
5399 -- the actual type is obtained from context.
5400 -- In Ada 2005, the equality operator for anonymous access types
5401 -- is declared in Standard, and preference rules apply to it.
5403 if Present (Scop) then
5404 if Defined_In_Scope (T1, Scop)
5405 or else T1 = Universal_Integer
5406 or else T1 = Universal_Real
5407 or else T1 = Any_Access
5408 or else T1 = Any_String
5409 or else T1 = Any_Composite
5410 or else (Ekind (T1) = E_Access_Subprogram_Type
5411 and then not Comes_From_Source (T1))
5415 elsif Ekind (T1) = E_Anonymous_Access_Type
5416 and then Scop = Standard_Standard
5421 -- The scope does not contain an operator for the type
5426 -- If we have infix notation, the operator must be usable.
5427 -- Within an instance, if the type is already established we
5428 -- know it is correct.
5429 -- In Ada 2005, the equality on anonymous access types is declared
5430 -- in Standard, and is always visible.
5432 elsif In_Open_Scopes (Scope (Bas))
5433 or else Is_Potentially_Use_Visible (Bas)
5434 or else In_Use (Bas)
5435 or else (In_Use (Scope (Bas))
5436 and then not Is_Hidden (Bas))
5437 or else (In_Instance
5438 and then First_Subtype (T1) = First_Subtype (Etype (R)))
5439 or else Ekind (T1) = E_Anonymous_Access_Type
5444 -- Save candidate type for subsequent error message, if any
5446 if not Is_Limited_Type (T1) then
5447 Candidate_Type := T1;
5453 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
5454 -- Do not allow anonymous access types in equality operators.
5456 if Ada_Version < Ada_2005
5457 and then Ekind (T1) = E_Anonymous_Access_Type
5462 if T1 /= Standard_Void_Type
5463 and then not Is_Limited_Type (T1)
5464 and then not Is_Limited_Composite (T1)
5465 and then Has_Compatible_Type (R, T1)
5468 and then Base_Type (T1) /= Base_Type (T_F)
5470 It := Disambiguate (L, I_F, Index, Any_Type);
5472 if It = No_Interp then
5473 Ambiguous_Operands (N);
5474 Set_Etype (L, Any_Type);
5487 if not Analyzed (L) then
5491 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
5493 -- Case of operator was not visible, Etype still set to Any_Type
5495 if Etype (N) = Any_Type then
5499 elsif Scop = Standard_Standard
5500 and then Ekind (T1) = E_Anonymous_Access_Type
5506 -- Start of processing for Find_Equality_Types
5509 -- If left operand is aggregate, the right operand has to
5510 -- provide a usable type for it.
5512 if Nkind (L) = N_Aggregate
5513 and then Nkind (R) /= N_Aggregate
5515 Find_Equality_Types (L => R, R => L, Op_Id => Op_Id, N => N);
5519 if Nkind (N) = N_Function_Call
5520 and then Nkind (Name (N)) = N_Expanded_Name
5522 Scop := Entity (Prefix (Name (N)));
5524 -- The prefix may be a package renaming, and the subsequent test
5525 -- requires the original package.
5527 if Ekind (Scop) = E_Package
5528 and then Present (Renamed_Entity (Scop))
5530 Scop := Renamed_Entity (Scop);
5531 Set_Entity (Prefix (Name (N)), Scop);
5535 if not Is_Overloaded (L) then
5536 Try_One_Interp (Etype (L));
5539 Get_First_Interp (L, Index, It);
5540 while Present (It.Typ) loop
5541 Try_One_Interp (It.Typ);
5542 Get_Next_Interp (Index, It);
5545 end Find_Equality_Types;
5547 -------------------------
5548 -- Find_Negation_Types --
5549 -------------------------
5551 procedure Find_Negation_Types
5556 Index : Interp_Index;
5560 if not Is_Overloaded (R) then
5561 if Etype (R) = Universal_Integer then
5562 Add_One_Interp (N, Op_Id, Any_Modular);
5563 elsif Valid_Boolean_Arg (Etype (R)) then
5564 Add_One_Interp (N, Op_Id, Etype (R));
5568 Get_First_Interp (R, Index, It);
5569 while Present (It.Typ) loop
5570 if Valid_Boolean_Arg (It.Typ) then
5571 Add_One_Interp (N, Op_Id, It.Typ);
5574 Get_Next_Interp (Index, It);
5577 end Find_Negation_Types;
5579 ------------------------------
5580 -- Find_Primitive_Operation --
5581 ------------------------------
5583 function Find_Primitive_Operation (N : Node_Id) return Boolean is
5584 Obj : constant Node_Id := Prefix (N);
5585 Op : constant Node_Id := Selector_Name (N);
5592 Set_Etype (Op, Any_Type);
5594 if Is_Access_Type (Etype (Obj)) then
5595 Typ := Designated_Type (Etype (Obj));
5600 if Is_Class_Wide_Type (Typ) then
5601 Typ := Root_Type (Typ);
5604 Prims := Primitive_Operations (Typ);
5606 Prim := First_Elmt (Prims);
5607 while Present (Prim) loop
5608 if Chars (Node (Prim)) = Chars (Op) then
5609 Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
5610 Set_Etype (N, Etype (Node (Prim)));
5616 -- Now look for class-wide operations of the type or any of its
5617 -- ancestors by iterating over the homonyms of the selector.
5620 Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
5624 Hom := Current_Entity (Op);
5625 while Present (Hom) loop
5626 if (Ekind (Hom) = E_Procedure
5628 Ekind (Hom) = E_Function)
5629 and then Scope (Hom) = Scope (Typ)
5630 and then Present (First_Formal (Hom))
5632 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
5634 (Is_Access_Type (Etype (First_Formal (Hom)))
5636 Ekind (Etype (First_Formal (Hom))) =
5637 E_Anonymous_Access_Type
5640 (Designated_Type (Etype (First_Formal (Hom)))) =
5643 Add_One_Interp (Op, Hom, Etype (Hom));
5644 Set_Etype (N, Etype (Hom));
5647 Hom := Homonym (Hom);
5651 return Etype (Op) /= Any_Type;
5652 end Find_Primitive_Operation;
5654 ----------------------
5655 -- Find_Unary_Types --
5656 ----------------------
5658 procedure Find_Unary_Types
5663 Index : Interp_Index;
5667 if not Is_Overloaded (R) then
5668 if Is_Numeric_Type (Etype (R)) then
5669 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
5673 Get_First_Interp (R, Index, It);
5674 while Present (It.Typ) loop
5675 if Is_Numeric_Type (It.Typ) then
5676 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
5679 Get_Next_Interp (Index, It);
5682 end Find_Unary_Types;
5688 function Junk_Operand (N : Node_Id) return Boolean is
5692 if Error_Posted (N) then
5696 -- Get entity to be tested
5698 if Is_Entity_Name (N)
5699 and then Present (Entity (N))
5703 -- An odd case, a procedure name gets converted to a very peculiar
5704 -- function call, and here is where we detect this happening.
5706 elsif Nkind (N) = N_Function_Call
5707 and then Is_Entity_Name (Name (N))
5708 and then Present (Entity (Name (N)))
5712 -- Another odd case, there are at least some cases of selected
5713 -- components where the selected component is not marked as having
5714 -- an entity, even though the selector does have an entity
5716 elsif Nkind (N) = N_Selected_Component
5717 and then Present (Entity (Selector_Name (N)))
5719 Enode := Selector_Name (N);
5725 -- Now test the entity we got to see if it is a bad case
5727 case Ekind (Entity (Enode)) is
5731 ("package name cannot be used as operand", Enode);
5733 when Generic_Unit_Kind =>
5735 ("generic unit name cannot be used as operand", Enode);
5739 ("subtype name cannot be used as operand", Enode);
5743 ("entry name cannot be used as operand", Enode);
5747 ("procedure name cannot be used as operand", Enode);
5751 ("exception name cannot be used as operand", Enode);
5753 when E_Block | E_Label | E_Loop =>
5755 ("label name cannot be used as operand", Enode);
5765 --------------------
5766 -- Operator_Check --
5767 --------------------
5769 procedure Operator_Check (N : Node_Id) is
5771 Remove_Abstract_Operations (N);
5773 -- Test for case of no interpretation found for operator
5775 if Etype (N) = Any_Type then
5779 Op_Id : Entity_Id := Empty;
5782 R := Right_Opnd (N);
5784 if Nkind (N) in N_Binary_Op then
5790 -- If either operand has no type, then don't complain further,
5791 -- since this simply means that we have a propagated error.
5794 or else Etype (R) = Any_Type
5795 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
5799 -- We explicitly check for the case of concatenation of component
5800 -- with component to avoid reporting spurious matching array types
5801 -- that might happen to be lurking in distant packages (such as
5802 -- run-time packages). This also prevents inconsistencies in the
5803 -- messages for certain ACVC B tests, which can vary depending on
5804 -- types declared in run-time interfaces. Another improvement when
5805 -- aggregates are present is to look for a well-typed operand.
5807 elsif Present (Candidate_Type)
5808 and then (Nkind (N) /= N_Op_Concat
5809 or else Is_Array_Type (Etype (L))
5810 or else Is_Array_Type (Etype (R)))
5812 if Nkind (N) = N_Op_Concat then
5813 if Etype (L) /= Any_Composite
5814 and then Is_Array_Type (Etype (L))
5816 Candidate_Type := Etype (L);
5818 elsif Etype (R) /= Any_Composite
5819 and then Is_Array_Type (Etype (R))
5821 Candidate_Type := Etype (R);
5825 Error_Msg_NE -- CODEFIX
5826 ("operator for} is not directly visible!",
5827 N, First_Subtype (Candidate_Type));
5830 U : constant Node_Id :=
5831 Cunit (Get_Source_Unit (Candidate_Type));
5833 if Unit_Is_Visible (U) then
5834 Error_Msg_N -- CODEFIX
5835 ("use clause would make operation legal!", N);
5837 Error_Msg_NE -- CODEFIX
5838 ("add with_clause and use_clause for&!",
5839 N, Defining_Entity (Unit (U)));
5844 -- If either operand is a junk operand (e.g. package name), then
5845 -- post appropriate error messages, but do not complain further.
5847 -- Note that the use of OR in this test instead of OR ELSE is
5848 -- quite deliberate, we may as well check both operands in the
5849 -- binary operator case.
5851 elsif Junk_Operand (R)
5852 or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
5856 -- If we have a logical operator, one of whose operands is
5857 -- Boolean, then we know that the other operand cannot resolve to
5858 -- Boolean (since we got no interpretations), but in that case we
5859 -- pretty much know that the other operand should be Boolean, so
5860 -- resolve it that way (generating an error)
5862 elsif Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor) then
5863 if Etype (L) = Standard_Boolean then
5864 Resolve (R, Standard_Boolean);
5866 elsif Etype (R) = Standard_Boolean then
5867 Resolve (L, Standard_Boolean);
5871 -- For an arithmetic operator or comparison operator, if one
5872 -- of the operands is numeric, then we know the other operand
5873 -- is not the same numeric type. If it is a non-numeric type,
5874 -- then probably it is intended to match the other operand.
5876 elsif Nkind_In (N, N_Op_Add,
5882 Nkind_In (N, N_Op_Lt,
5888 if Is_Numeric_Type (Etype (L))
5889 and then not Is_Numeric_Type (Etype (R))
5891 Resolve (R, Etype (L));
5894 elsif Is_Numeric_Type (Etype (R))
5895 and then not Is_Numeric_Type (Etype (L))
5897 Resolve (L, Etype (R));
5901 -- Comparisons on A'Access are common enough to deserve a
5904 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne)
5905 and then Ekind (Etype (L)) = E_Access_Attribute_Type
5906 and then Ekind (Etype (R)) = E_Access_Attribute_Type
5909 ("two access attributes cannot be compared directly", N);
5911 ("\use qualified expression for one of the operands",
5915 -- Another one for C programmers
5917 elsif Nkind (N) = N_Op_Concat
5918 and then Valid_Boolean_Arg (Etype (L))
5919 and then Valid_Boolean_Arg (Etype (R))
5921 Error_Msg_N ("invalid operands for concatenation", N);
5922 Error_Msg_N -- CODEFIX
5923 ("\maybe AND was meant", N);
5926 -- A special case for comparison of access parameter with null
5928 elsif Nkind (N) = N_Op_Eq
5929 and then Is_Entity_Name (L)
5930 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
5931 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
5933 and then Nkind (R) = N_Null
5935 Error_Msg_N ("access parameter is not allowed to be null", L);
5936 Error_Msg_N ("\(call would raise Constraint_Error)", L);
5939 -- Another special case for exponentiation, where the right
5940 -- operand must be Natural, independently of the base.
5942 elsif Nkind (N) = N_Op_Expon
5943 and then Is_Numeric_Type (Etype (L))
5944 and then not Is_Overloaded (R)
5946 First_Subtype (Base_Type (Etype (R))) /= Standard_Integer
5947 and then Base_Type (Etype (R)) /= Universal_Integer
5950 ("exponent must be of type Natural, found}", R, Etype (R));
5954 -- If we fall through then just give general message. Note that in
5955 -- the following messages, if the operand is overloaded we choose
5956 -- an arbitrary type to complain about, but that is probably more
5957 -- useful than not giving a type at all.
5959 if Nkind (N) in N_Unary_Op then
5960 Error_Msg_Node_2 := Etype (R);
5961 Error_Msg_N ("operator& not defined for}", N);
5965 if Nkind (N) in N_Binary_Op then
5966 if not Is_Overloaded (L)
5967 and then not Is_Overloaded (R)
5968 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
5970 Error_Msg_Node_2 := First_Subtype (Etype (R));
5971 Error_Msg_N ("there is no applicable operator& for}", N);
5974 -- Another attempt to find a fix: one of the candidate
5975 -- interpretations may not be use-visible. This has
5976 -- already been checked for predefined operators, so
5977 -- we examine only user-defined functions.
5979 Op_Id := Get_Name_Entity_Id (Chars (N));
5981 while Present (Op_Id) loop
5982 if Ekind (Op_Id) /= E_Operator
5983 and then Is_Overloadable (Op_Id)
5985 if not Is_Immediately_Visible (Op_Id)
5986 and then not In_Use (Scope (Op_Id))
5987 and then not Is_Abstract_Subprogram (Op_Id)
5988 and then not Is_Hidden (Op_Id)
5989 and then Ekind (Scope (Op_Id)) = E_Package
5992 (L, Etype (First_Formal (Op_Id)))
5994 (Next_Formal (First_Formal (Op_Id)))
5998 Etype (Next_Formal (First_Formal (Op_Id))))
6001 ("No legal interpretation for operator&", N);
6003 ("\use clause on& would make operation legal",
6009 Op_Id := Homonym (Op_Id);
6013 Error_Msg_N ("invalid operand types for operator&", N);
6015 if Nkind (N) /= N_Op_Concat then
6016 Error_Msg_NE ("\left operand has}!", N, Etype (L));
6017 Error_Msg_NE ("\right operand has}!", N, Etype (R));
6027 -----------------------------------------
6028 -- Process_Implicit_Dereference_Prefix --
6029 -----------------------------------------
6031 function Process_Implicit_Dereference_Prefix
6033 P : Entity_Id) return Entity_Id
6036 Typ : constant Entity_Id := Designated_Type (Etype (P));
6040 and then (Operating_Mode = Check_Semantics or else not Expander_Active)
6042 -- We create a dummy reference to E to ensure that the reference
6043 -- is not considered as part of an assignment (an implicit
6044 -- dereference can never assign to its prefix). The Comes_From_Source
6045 -- attribute needs to be propagated for accurate warnings.
6047 Ref := New_Reference_To (E, Sloc (P));
6048 Set_Comes_From_Source (Ref, Comes_From_Source (P));
6049 Generate_Reference (E, Ref);
6052 -- An implicit dereference is a legal occurrence of an
6053 -- incomplete type imported through a limited_with clause,
6054 -- if the full view is visible.
6056 if From_With_Type (Typ)
6057 and then not From_With_Type (Scope (Typ))
6059 (Is_Immediately_Visible (Scope (Typ))
6061 (Is_Child_Unit (Scope (Typ))
6062 and then Is_Visible_Child_Unit (Scope (Typ))))
6064 return Available_View (Typ);
6069 end Process_Implicit_Dereference_Prefix;
6071 --------------------------------
6072 -- Remove_Abstract_Operations --
6073 --------------------------------
6075 procedure Remove_Abstract_Operations (N : Node_Id) is
6076 Abstract_Op : Entity_Id := Empty;
6077 Address_Kludge : Boolean := False;
6081 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
6082 -- activate this if either extensions are enabled, or if the abstract
6083 -- operation in question comes from a predefined file. This latter test
6084 -- allows us to use abstract to make operations invisible to users. In
6085 -- particular, if type Address is non-private and abstract subprograms
6086 -- are used to hide its operators, they will be truly hidden.
6088 type Operand_Position is (First_Op, Second_Op);
6089 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
6091 procedure Remove_Address_Interpretations (Op : Operand_Position);
6092 -- Ambiguities may arise when the operands are literal and the address
6093 -- operations in s-auxdec are visible. In that case, remove the
6094 -- interpretation of a literal as Address, to retain the semantics of
6095 -- Address as a private type.
6097 ------------------------------------
6098 -- Remove_Address_Interpretations --
6099 ------------------------------------
6101 procedure Remove_Address_Interpretations (Op : Operand_Position) is
6105 if Is_Overloaded (N) then
6106 Get_First_Interp (N, I, It);
6107 while Present (It.Nam) loop
6108 Formal := First_Entity (It.Nam);
6110 if Op = Second_Op then
6111 Formal := Next_Entity (Formal);
6114 if Is_Descendent_Of_Address (Etype (Formal)) then
6115 Address_Kludge := True;
6119 Get_Next_Interp (I, It);
6122 end Remove_Address_Interpretations;
6124 -- Start of processing for Remove_Abstract_Operations
6127 if Is_Overloaded (N) then
6128 Get_First_Interp (N, I, It);
6130 while Present (It.Nam) loop
6131 if Is_Overloadable (It.Nam)
6132 and then Is_Abstract_Subprogram (It.Nam)
6133 and then not Is_Dispatching_Operation (It.Nam)
6135 Abstract_Op := It.Nam;
6137 if Is_Descendent_Of_Address (It.Typ) then
6138 Address_Kludge := True;
6142 -- In Ada 2005, this operation does not participate in Overload
6143 -- resolution. If the operation is defined in a predefined
6144 -- unit, it is one of the operations declared abstract in some
6145 -- variants of System, and it must be removed as well.
6147 elsif Ada_Version >= Ada_2005
6148 or else Is_Predefined_File_Name
6149 (Unit_File_Name (Get_Source_Unit (It.Nam)))
6156 Get_Next_Interp (I, It);
6159 if No (Abstract_Op) then
6161 -- If some interpretation yields an integer type, it is still
6162 -- possible that there are address interpretations. Remove them
6163 -- if one operand is a literal, to avoid spurious ambiguities
6164 -- on systems where Address is a visible integer type.
6166 if Is_Overloaded (N)
6167 and then Nkind (N) in N_Op
6168 and then Is_Integer_Type (Etype (N))
6170 if Nkind (N) in N_Binary_Op then
6171 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
6172 Remove_Address_Interpretations (Second_Op);
6174 elsif Nkind (Right_Opnd (N)) = N_Integer_Literal then
6175 Remove_Address_Interpretations (First_Op);
6180 elsif Nkind (N) in N_Op then
6182 -- Remove interpretations that treat literals as addresses. This
6183 -- is never appropriate, even when Address is defined as a visible
6184 -- Integer type. The reason is that we would really prefer Address
6185 -- to behave as a private type, even in this case, which is there
6186 -- only to accommodate oddities of VMS address sizes. If Address
6187 -- is a visible integer type, we get lots of overload ambiguities.
6189 if Nkind (N) in N_Binary_Op then
6191 U1 : constant Boolean :=
6192 Present (Universal_Interpretation (Right_Opnd (N)));
6193 U2 : constant Boolean :=
6194 Present (Universal_Interpretation (Left_Opnd (N)));
6198 Remove_Address_Interpretations (Second_Op);
6202 Remove_Address_Interpretations (First_Op);
6205 if not (U1 and U2) then
6207 -- Remove corresponding predefined operator, which is
6208 -- always added to the overload set.
6210 Get_First_Interp (N, I, It);
6211 while Present (It.Nam) loop
6212 if Scope (It.Nam) = Standard_Standard
6213 and then Base_Type (It.Typ) =
6214 Base_Type (Etype (Abstract_Op))
6219 Get_Next_Interp (I, It);
6222 elsif Is_Overloaded (N)
6223 and then Present (Univ_Type)
6225 -- If both operands have a universal interpretation,
6226 -- it is still necessary to remove interpretations that
6227 -- yield Address. Any remaining ambiguities will be
6228 -- removed in Disambiguate.
6230 Get_First_Interp (N, I, It);
6231 while Present (It.Nam) loop
6232 if Is_Descendent_Of_Address (It.Typ) then
6235 elsif not Is_Type (It.Nam) then
6236 Set_Entity (N, It.Nam);
6239 Get_Next_Interp (I, It);
6245 elsif Nkind (N) = N_Function_Call
6247 (Nkind (Name (N)) = N_Operator_Symbol
6249 (Nkind (Name (N)) = N_Expanded_Name
6251 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
6255 Arg1 : constant Node_Id := First (Parameter_Associations (N));
6256 U1 : constant Boolean :=
6257 Present (Universal_Interpretation (Arg1));
6258 U2 : constant Boolean :=
6259 Present (Next (Arg1)) and then
6260 Present (Universal_Interpretation (Next (Arg1)));
6264 Remove_Address_Interpretations (First_Op);
6268 Remove_Address_Interpretations (Second_Op);
6271 if not (U1 and U2) then
6272 Get_First_Interp (N, I, It);
6273 while Present (It.Nam) loop
6274 if Scope (It.Nam) = Standard_Standard
6275 and then It.Typ = Base_Type (Etype (Abstract_Op))
6280 Get_Next_Interp (I, It);
6286 -- If the removal has left no valid interpretations, emit an error
6287 -- message now and label node as illegal.
6289 if Present (Abstract_Op) then
6290 Get_First_Interp (N, I, It);
6294 -- Removal of abstract operation left no viable candidate
6296 Set_Etype (N, Any_Type);
6297 Error_Msg_Sloc := Sloc (Abstract_Op);
6299 ("cannot call abstract operation& declared#", N, Abstract_Op);
6301 -- In Ada 2005, an abstract operation may disable predefined
6302 -- operators. Since the context is not yet known, we mark the
6303 -- predefined operators as potentially hidden. Do not include
6304 -- predefined operators when addresses are involved since this
6305 -- case is handled separately.
6307 elsif Ada_Version >= Ada_2005
6308 and then not Address_Kludge
6310 while Present (It.Nam) loop
6311 if Is_Numeric_Type (It.Typ)
6312 and then Scope (It.Typ) = Standard_Standard
6314 Set_Abstract_Op (I, Abstract_Op);
6317 Get_Next_Interp (I, It);
6322 end Remove_Abstract_Operations;
6324 ----------------------------
6325 -- Try_Container_Indexing --
6326 ----------------------------
6328 function Try_Container_Indexing
6331 Expr : Node_Id) return Boolean
6333 Loc : constant Source_Ptr := Sloc (N);
6336 Func_Name : Node_Id;
6343 -- Check whether type has a specified indexing aspect.
6348 Ritem := First_Rep_Item (Etype (Prefix));
6349 while Present (Ritem) loop
6350 if Nkind (Ritem) = N_Aspect_Specification then
6352 -- Prefer Variable_Indexing, but will settle for Constant.
6354 if Get_Aspect_Id (Chars (Identifier (Ritem))) =
6355 Aspect_Constant_Indexing
6357 Func_Name := Expression (Ritem);
6359 elsif Get_Aspect_Id (Chars (Identifier (Ritem))) =
6360 Aspect_Variable_Indexing
6362 Func_Name := Expression (Ritem);
6368 Next_Rep_Item (Ritem);
6371 -- If aspect does not exist the expression is illegal. Error is
6372 -- diagnosed in caller.
6374 if No (Func_Name) then
6376 -- The prefix itself may be an indexing of a container
6377 -- rewrite as such and re-analyze.
6379 if Has_Implicit_Dereference (Etype (Prefix)) then
6380 Build_Explicit_Dereference
6381 (Prefix, First_Discriminant (Etype (Prefix)));
6382 return Try_Container_Indexing (N, Prefix, Expr);
6390 and then not Is_Variable (Prefix)
6392 Error_Msg_N ("Variable indexing cannot be applied to a constant", N);
6395 if not Is_Overloaded (Func_Name) then
6396 Func := Entity (Func_Name);
6397 Indexing := Make_Function_Call (Loc,
6398 Name => New_Occurrence_Of (Func, Loc),
6399 Parameter_Associations =>
6400 New_List (Relocate_Node (Prefix), Relocate_Node (Expr)));
6401 Rewrite (N, Indexing);
6404 -- The return type of the indexing function is a reference type, so
6405 -- add the dereference as a possible interpretation.
6407 Disc := First_Discriminant (Etype (Func));
6408 while Present (Disc) loop
6409 if Has_Implicit_Dereference (Disc) then
6410 Add_One_Interp (N, Disc, Designated_Type (Etype (Disc)));
6414 Next_Discriminant (Disc);
6418 Indexing := Make_Function_Call (Loc,
6419 Name => Make_Identifier (Loc, Chars (Func_Name)),
6420 Parameter_Associations =>
6421 New_List (Relocate_Node (Prefix), Relocate_Node (Expr)));
6423 Rewrite (N, Indexing);
6431 Get_First_Interp (Func_Name, I, It);
6432 Set_Etype (N, Any_Type);
6433 while Present (It.Nam) loop
6434 Analyze_One_Call (N, It.Nam, False, Success);
6436 Set_Etype (Name (N), It.Typ);
6438 -- Add implicit dereference interpretation.
6440 Disc := First_Discriminant (Etype (It.Nam));
6442 while Present (Disc) loop
6443 if Has_Implicit_Dereference (Disc) then
6445 (N, Disc, Designated_Type (Etype (Disc)));
6449 Next_Discriminant (Disc);
6452 Get_Next_Interp (I, It);
6458 end Try_Container_Indexing;
6460 -----------------------
6461 -- Try_Indirect_Call --
6462 -----------------------
6464 function Try_Indirect_Call
6467 Typ : Entity_Id) return Boolean
6473 pragma Warnings (Off, Call_OK);
6476 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
6478 Actual := First_Actual (N);
6479 Formal := First_Formal (Designated_Type (Typ));
6480 while Present (Actual) and then Present (Formal) loop
6481 if not Has_Compatible_Type (Actual, Etype (Formal)) then
6486 Next_Formal (Formal);
6489 if No (Actual) and then No (Formal) then
6490 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
6492 -- Nam is a candidate interpretation for the name in the call,
6493 -- if it is not an indirect call.
6495 if not Is_Type (Nam)
6496 and then Is_Entity_Name (Name (N))
6498 Set_Entity (Name (N), Nam);
6505 end Try_Indirect_Call;
6507 ----------------------
6508 -- Try_Indexed_Call --
6509 ----------------------
6511 function Try_Indexed_Call
6515 Skip_First : Boolean) return Boolean
6517 Loc : constant Source_Ptr := Sloc (N);
6518 Actuals : constant List_Id := Parameter_Associations (N);
6523 Actual := First (Actuals);
6525 -- If the call was originally written in prefix form, skip the first
6526 -- actual, which is obviously not defaulted.
6532 Index := First_Index (Typ);
6533 while Present (Actual) and then Present (Index) loop
6535 -- If the parameter list has a named association, the expression
6536 -- is definitely a call and not an indexed component.
6538 if Nkind (Actual) = N_Parameter_Association then
6542 if Is_Entity_Name (Actual)
6543 and then Is_Type (Entity (Actual))
6544 and then No (Next (Actual))
6546 -- A single actual that is a type name indicates a slice if the
6547 -- type is discrete, and an error otherwise.
6549 if Is_Discrete_Type (Entity (Actual)) then
6553 Make_Function_Call (Loc,
6554 Name => Relocate_Node (Name (N))),
6556 New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
6561 Error_Msg_N ("invalid use of type in expression", Actual);
6562 Set_Etype (N, Any_Type);
6567 elsif not Has_Compatible_Type (Actual, Etype (Index)) then
6575 if No (Actual) and then No (Index) then
6576 Add_One_Interp (N, Nam, Component_Type (Typ));
6578 -- Nam is a candidate interpretation for the name in the call,
6579 -- if it is not an indirect call.
6581 if not Is_Type (Nam)
6582 and then Is_Entity_Name (Name (N))
6584 Set_Entity (Name (N), Nam);
6591 end Try_Indexed_Call;
6593 --------------------------
6594 -- Try_Object_Operation --
6595 --------------------------
6597 function Try_Object_Operation (N : Node_Id) return Boolean is
6598 K : constant Node_Kind := Nkind (Parent (N));
6599 Is_Subprg_Call : constant Boolean := Nkind_In
6600 (K, N_Procedure_Call_Statement,
6602 Loc : constant Source_Ptr := Sloc (N);
6603 Obj : constant Node_Id := Prefix (N);
6605 Subprog : constant Node_Id :=
6606 Make_Identifier (Sloc (Selector_Name (N)),
6607 Chars => Chars (Selector_Name (N)));
6608 -- Identifier on which possible interpretations will be collected
6610 Report_Error : Boolean := False;
6611 -- If no candidate interpretation matches the context, redo the
6612 -- analysis with error enabled to provide additional information.
6615 Candidate : Entity_Id := Empty;
6616 New_Call_Node : Node_Id := Empty;
6617 Node_To_Replace : Node_Id;
6618 Obj_Type : Entity_Id := Etype (Obj);
6619 Success : Boolean := False;
6621 function Valid_Candidate
6624 Subp : Entity_Id) return Entity_Id;
6625 -- If the subprogram is a valid interpretation, record it, and add
6626 -- to the list of interpretations of Subprog.
6628 procedure Complete_Object_Operation
6629 (Call_Node : Node_Id;
6630 Node_To_Replace : Node_Id);
6631 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
6632 -- Call_Node, insert the object (or its dereference) as the first actual
6633 -- in the call, and complete the analysis of the call.
6635 procedure Report_Ambiguity (Op : Entity_Id);
6636 -- If a prefixed procedure call is ambiguous, indicate whether the
6637 -- call includes an implicit dereference or an implicit 'Access.
6639 procedure Transform_Object_Operation
6640 (Call_Node : out Node_Id;
6641 Node_To_Replace : out Node_Id);
6642 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
6643 -- Call_Node is the resulting subprogram call, Node_To_Replace is
6644 -- either N or the parent of N, and Subprog is a reference to the
6645 -- subprogram we are trying to match.
6647 function Try_Class_Wide_Operation
6648 (Call_Node : Node_Id;
6649 Node_To_Replace : Node_Id) return Boolean;
6650 -- Traverse all ancestor types looking for a class-wide subprogram
6651 -- for which the current operation is a valid non-dispatching call.
6653 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
6654 -- If prefix is overloaded, its interpretation may include different
6655 -- tagged types, and we must examine the primitive operations and
6656 -- the class-wide operations of each in order to find candidate
6657 -- interpretations for the call as a whole.
6659 function Try_Primitive_Operation
6660 (Call_Node : Node_Id;
6661 Node_To_Replace : Node_Id) return Boolean;
6662 -- Traverse the list of primitive subprograms looking for a dispatching
6663 -- operation for which the current node is a valid call .
6665 ---------------------
6666 -- Valid_Candidate --
6667 ---------------------
6669 function Valid_Candidate
6672 Subp : Entity_Id) return Entity_Id
6674 Arr_Type : Entity_Id;
6675 Comp_Type : Entity_Id;
6678 -- If the subprogram is a valid interpretation, record it in global
6679 -- variable Subprog, to collect all possible overloadings.
6682 if Subp /= Entity (Subprog) then
6683 Add_One_Interp (Subprog, Subp, Etype (Subp));
6687 -- If the call may be an indexed call, retrieve component type of
6688 -- resulting expression, and add possible interpretation.
6693 if Nkind (Call) = N_Function_Call
6694 and then Nkind (Parent (N)) = N_Indexed_Component
6695 and then Needs_One_Actual (Subp)
6697 if Is_Array_Type (Etype (Subp)) then
6698 Arr_Type := Etype (Subp);
6700 elsif Is_Access_Type (Etype (Subp))
6701 and then Is_Array_Type (Designated_Type (Etype (Subp)))
6703 Arr_Type := Designated_Type (Etype (Subp));
6707 if Present (Arr_Type) then
6709 -- Verify that the actuals (excluding the object) match the types
6717 Actual := Next (First_Actual (Call));
6718 Index := First_Index (Arr_Type);
6719 while Present (Actual) and then Present (Index) loop
6720 if not Has_Compatible_Type (Actual, Etype (Index)) then
6725 Next_Actual (Actual);
6731 and then Present (Arr_Type)
6733 Comp_Type := Component_Type (Arr_Type);
6737 if Present (Comp_Type)
6738 and then Etype (Subprog) /= Comp_Type
6740 Add_One_Interp (Subprog, Subp, Comp_Type);
6744 if Etype (Call) /= Any_Type then
6749 end Valid_Candidate;
6751 -------------------------------
6752 -- Complete_Object_Operation --
6753 -------------------------------
6755 procedure Complete_Object_Operation
6756 (Call_Node : Node_Id;
6757 Node_To_Replace : Node_Id)
6759 Control : constant Entity_Id := First_Formal (Entity (Subprog));
6760 Formal_Type : constant Entity_Id := Etype (Control);
6761 First_Actual : Node_Id;
6764 -- Place the name of the operation, with its interpretations,
6765 -- on the rewritten call.
6767 Set_Name (Call_Node, Subprog);
6769 First_Actual := First (Parameter_Associations (Call_Node));
6771 -- For cross-reference purposes, treat the new node as being in
6772 -- the source if the original one is.
6774 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
6775 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
6777 if Nkind (N) = N_Selected_Component
6778 and then not Inside_A_Generic
6780 Set_Entity (Selector_Name (N), Entity (Subprog));
6783 -- If need be, rewrite first actual as an explicit dereference
6784 -- If the call is overloaded, the rewriting can only be done
6785 -- once the primitive operation is identified.
6787 if Is_Overloaded (Subprog) then
6789 -- The prefix itself may be overloaded, and its interpretations
6790 -- must be propagated to the new actual in the call.
6792 if Is_Overloaded (Obj) then
6793 Save_Interps (Obj, First_Actual);
6796 Rewrite (First_Actual, Obj);
6798 elsif not Is_Access_Type (Formal_Type)
6799 and then Is_Access_Type (Etype (Obj))
6801 Rewrite (First_Actual,
6802 Make_Explicit_Dereference (Sloc (Obj), Obj));
6803 Analyze (First_Actual);
6805 -- If we need to introduce an explicit dereference, verify that
6806 -- the resulting actual is compatible with the mode of the formal.
6808 if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
6809 and then Is_Access_Constant (Etype (Obj))
6812 ("expect variable in call to&", Prefix (N), Entity (Subprog));
6815 -- Conversely, if the formal is an access parameter and the object
6816 -- is not, replace the actual with a 'Access reference. Its analysis
6817 -- will check that the object is aliased.
6819 elsif Is_Access_Type (Formal_Type)
6820 and then not Is_Access_Type (Etype (Obj))
6822 -- A special case: A.all'access is illegal if A is an access to a
6823 -- constant and the context requires an access to a variable.
6825 if not Is_Access_Constant (Formal_Type) then
6826 if (Nkind (Obj) = N_Explicit_Dereference
6827 and then Is_Access_Constant (Etype (Prefix (Obj))))
6828 or else not Is_Variable (Obj)
6831 ("actual for& must be a variable", Obj, Control);
6835 Rewrite (First_Actual,
6836 Make_Attribute_Reference (Loc,
6837 Attribute_Name => Name_Access,
6838 Prefix => Relocate_Node (Obj)));
6840 if not Is_Aliased_View (Obj) then
6842 ("object in prefixed call to& must be aliased"
6843 & " (RM-2005 4.3.1 (13))",
6844 Prefix (First_Actual), Subprog);
6847 Analyze (First_Actual);
6850 if Is_Overloaded (Obj) then
6851 Save_Interps (Obj, First_Actual);
6854 Rewrite (First_Actual, Obj);
6857 Rewrite (Node_To_Replace, Call_Node);
6859 -- Propagate the interpretations collected in subprog to the new
6860 -- function call node, to be resolved from context.
6862 if Is_Overloaded (Subprog) then
6863 Save_Interps (Subprog, Node_To_Replace);
6866 Analyze (Node_To_Replace);
6868 -- If the operation has been rewritten into a call, which may get
6869 -- subsequently an explicit dereference, preserve the type on the
6870 -- original node (selected component or indexed component) for
6871 -- subsequent legality tests, e.g. Is_Variable. which examines
6872 -- the original node.
6874 if Nkind (Node_To_Replace) = N_Function_Call then
6876 (Original_Node (Node_To_Replace), Etype (Node_To_Replace));
6879 end Complete_Object_Operation;
6881 ----------------------
6882 -- Report_Ambiguity --
6883 ----------------------
6885 procedure Report_Ambiguity (Op : Entity_Id) is
6886 Access_Formal : constant Boolean :=
6887 Is_Access_Type (Etype (First_Formal (Op)));
6888 Access_Actual : constant Boolean :=
6889 Is_Access_Type (Etype (Prefix (N)));
6892 Error_Msg_Sloc := Sloc (Op);
6894 if Access_Formal and then not Access_Actual then
6895 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
6897 ("\possible interpretation"
6898 & " (inherited, with implicit 'Access) #", N);
6901 ("\possible interpretation (with implicit 'Access) #", N);
6904 elsif not Access_Formal and then Access_Actual then
6905 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
6907 ("\possible interpretation"
6908 & " ( inherited, with implicit dereference) #", N);
6911 ("\possible interpretation (with implicit dereference) #", N);
6915 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
6916 Error_Msg_N ("\possible interpretation (inherited)#", N);
6918 Error_Msg_N -- CODEFIX
6919 ("\possible interpretation#", N);
6922 end Report_Ambiguity;
6924 --------------------------------
6925 -- Transform_Object_Operation --
6926 --------------------------------
6928 procedure Transform_Object_Operation
6929 (Call_Node : out Node_Id;
6930 Node_To_Replace : out Node_Id)
6932 Dummy : constant Node_Id := New_Copy (Obj);
6933 -- Placeholder used as a first parameter in the call, replaced
6934 -- eventually by the proper object.
6936 Parent_Node : constant Node_Id := Parent (N);
6942 -- Common case covering 1) Call to a procedure and 2) Call to a
6943 -- function that has some additional actuals.
6945 if Nkind_In (Parent_Node, N_Function_Call,
6946 N_Procedure_Call_Statement)
6948 -- N is a selected component node containing the name of the
6949 -- subprogram. If N is not the name of the parent node we must
6950 -- not replace the parent node by the new construct. This case
6951 -- occurs when N is a parameterless call to a subprogram that
6952 -- is an actual parameter of a call to another subprogram. For
6954 -- Some_Subprogram (..., Obj.Operation, ...)
6956 and then Name (Parent_Node) = N
6958 Node_To_Replace := Parent_Node;
6960 Actuals := Parameter_Associations (Parent_Node);
6962 if Present (Actuals) then
6963 Prepend (Dummy, Actuals);
6965 Actuals := New_List (Dummy);
6968 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
6970 Make_Procedure_Call_Statement (Loc,
6971 Name => New_Copy (Subprog),
6972 Parameter_Associations => Actuals);
6976 Make_Function_Call (Loc,
6977 Name => New_Copy (Subprog),
6978 Parameter_Associations => Actuals);
6982 -- Before analysis, a function call appears as an indexed component
6983 -- if there are no named associations.
6985 elsif Nkind (Parent_Node) = N_Indexed_Component
6986 and then N = Prefix (Parent_Node)
6988 Node_To_Replace := Parent_Node;
6989 Actuals := Expressions (Parent_Node);
6991 Actual := First (Actuals);
6992 while Present (Actual) loop
6997 Prepend (Dummy, Actuals);
7000 Make_Function_Call (Loc,
7001 Name => New_Copy (Subprog),
7002 Parameter_Associations => Actuals);
7004 -- Parameterless call: Obj.F is rewritten as F (Obj)
7007 Node_To_Replace := N;
7010 Make_Function_Call (Loc,
7011 Name => New_Copy (Subprog),
7012 Parameter_Associations => New_List (Dummy));
7014 end Transform_Object_Operation;
7016 ------------------------------
7017 -- Try_Class_Wide_Operation --
7018 ------------------------------
7020 function Try_Class_Wide_Operation
7021 (Call_Node : Node_Id;
7022 Node_To_Replace : Node_Id) return Boolean
7024 Anc_Type : Entity_Id;
7025 Matching_Op : Entity_Id := Empty;
7028 procedure Traverse_Homonyms
7029 (Anc_Type : Entity_Id;
7030 Error : out Boolean);
7031 -- Traverse the homonym chain of the subprogram searching for those
7032 -- homonyms whose first formal has the Anc_Type's class-wide type,
7033 -- or an anonymous access type designating the class-wide type. If
7034 -- an ambiguity is detected, then Error is set to True.
7036 procedure Traverse_Interfaces
7037 (Anc_Type : Entity_Id;
7038 Error : out Boolean);
7039 -- Traverse the list of interfaces, if any, associated with Anc_Type
7040 -- and search for acceptable class-wide homonyms associated with each
7041 -- interface. If an ambiguity is detected, then Error is set to True.
7043 -----------------------
7044 -- Traverse_Homonyms --
7045 -----------------------
7047 procedure Traverse_Homonyms
7048 (Anc_Type : Entity_Id;
7049 Error : out Boolean)
7051 Cls_Type : Entity_Id;
7059 Cls_Type := Class_Wide_Type (Anc_Type);
7061 Hom := Current_Entity (Subprog);
7063 -- Find a non-hidden operation whose first parameter is of the
7064 -- class-wide type, a subtype thereof, or an anonymous access
7067 while Present (Hom) loop
7068 if Ekind_In (Hom, E_Procedure, E_Function)
7069 and then not Is_Hidden (Hom)
7070 and then Scope (Hom) = Scope (Anc_Type)
7071 and then Present (First_Formal (Hom))
7073 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
7075 (Is_Access_Type (Etype (First_Formal (Hom)))
7077 Ekind (Etype (First_Formal (Hom))) =
7078 E_Anonymous_Access_Type
7081 (Designated_Type (Etype (First_Formal (Hom)))) =
7084 -- If the context is a procedure call, ignore functions
7085 -- in the name of the call.
7087 if Ekind (Hom) = E_Function
7088 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
7089 and then N = Name (Parent (N))
7094 Set_Etype (Call_Node, Any_Type);
7095 Set_Is_Overloaded (Call_Node, False);
7098 if No (Matching_Op) then
7099 Hom_Ref := New_Reference_To (Hom, Sloc (Subprog));
7100 Set_Etype (Call_Node, Any_Type);
7101 Set_Parent (Call_Node, Parent (Node_To_Replace));
7103 Set_Name (Call_Node, Hom_Ref);
7108 Report => Report_Error,
7110 Skip_First => True);
7113 Valid_Candidate (Success, Call_Node, Hom);
7119 Report => Report_Error,
7121 Skip_First => True);
7123 if Present (Valid_Candidate (Success, Call_Node, Hom))
7124 and then Nkind (Call_Node) /= N_Function_Call
7126 Error_Msg_NE ("ambiguous call to&", N, Hom);
7127 Report_Ambiguity (Matching_Op);
7128 Report_Ambiguity (Hom);
7136 Hom := Homonym (Hom);
7138 end Traverse_Homonyms;
7140 -------------------------
7141 -- Traverse_Interfaces --
7142 -------------------------
7144 procedure Traverse_Interfaces
7145 (Anc_Type : Entity_Id;
7146 Error : out Boolean)
7148 Intface_List : constant List_Id :=
7149 Abstract_Interface_List (Anc_Type);
7155 if Is_Non_Empty_List (Intface_List) then
7156 Intface := First (Intface_List);
7157 while Present (Intface) loop
7159 -- Look for acceptable class-wide homonyms associated with
7162 Traverse_Homonyms (Etype (Intface), Error);
7168 -- Continue the search by looking at each of the interface's
7169 -- associated interface ancestors.
7171 Traverse_Interfaces (Etype (Intface), Error);
7180 end Traverse_Interfaces;
7182 -- Start of processing for Try_Class_Wide_Operation
7185 -- Loop through ancestor types (including interfaces), traversing
7186 -- the homonym chain of the subprogram, trying out those homonyms
7187 -- whose first formal has the class-wide type of the ancestor, or
7188 -- an anonymous access type designating the class-wide type.
7190 Anc_Type := Obj_Type;
7192 -- Look for a match among homonyms associated with the ancestor
7194 Traverse_Homonyms (Anc_Type, Error);
7200 -- Continue the search for matches among homonyms associated with
7201 -- any interfaces implemented by the ancestor.
7203 Traverse_Interfaces (Anc_Type, Error);
7209 exit when Etype (Anc_Type) = Anc_Type;
7210 Anc_Type := Etype (Anc_Type);
7213 if Present (Matching_Op) then
7214 Set_Etype (Call_Node, Etype (Matching_Op));
7217 return Present (Matching_Op);
7218 end Try_Class_Wide_Operation;
7220 -----------------------------------
7221 -- Try_One_Prefix_Interpretation --
7222 -----------------------------------
7224 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
7228 if Is_Access_Type (Obj_Type) then
7229 Obj_Type := Designated_Type (Obj_Type);
7232 if Ekind (Obj_Type) = E_Private_Subtype then
7233 Obj_Type := Base_Type (Obj_Type);
7236 if Is_Class_Wide_Type (Obj_Type) then
7237 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
7240 -- The type may have be obtained through a limited_with clause,
7241 -- in which case the primitive operations are available on its
7242 -- non-limited view. If still incomplete, retrieve full view.
7244 if Ekind (Obj_Type) = E_Incomplete_Type
7245 and then From_With_Type (Obj_Type)
7247 Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
7250 -- If the object is not tagged, or the type is still an incomplete
7251 -- type, this is not a prefixed call.
7253 if not Is_Tagged_Type (Obj_Type)
7254 or else Is_Incomplete_Type (Obj_Type)
7259 if Try_Primitive_Operation
7260 (Call_Node => New_Call_Node,
7261 Node_To_Replace => Node_To_Replace)
7263 Try_Class_Wide_Operation
7264 (Call_Node => New_Call_Node,
7265 Node_To_Replace => Node_To_Replace)
7269 end Try_One_Prefix_Interpretation;
7271 -----------------------------
7272 -- Try_Primitive_Operation --
7273 -----------------------------
7275 function Try_Primitive_Operation
7276 (Call_Node : Node_Id;
7277 Node_To_Replace : Node_Id) return Boolean
7280 Prim_Op : Entity_Id;
7281 Matching_Op : Entity_Id := Empty;
7282 Prim_Op_Ref : Node_Id := Empty;
7284 Corr_Type : Entity_Id := Empty;
7285 -- If the prefix is a synchronized type, the controlling type of
7286 -- the primitive operation is the corresponding record type, else
7287 -- this is the object type itself.
7289 Success : Boolean := False;
7291 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
7292 -- For tagged types the candidate interpretations are found in
7293 -- the list of primitive operations of the type and its ancestors.
7294 -- For formal tagged types we have to find the operations declared
7295 -- in the same scope as the type (including in the generic formal
7296 -- part) because the type itself carries no primitive operations,
7297 -- except for formal derived types that inherit the operations of
7298 -- the parent and progenitors.
7299 -- If the context is a generic subprogram body, the generic formals
7300 -- are visible by name, but are not in the entity list of the
7301 -- subprogram because that list starts with the subprogram formals.
7302 -- We retrieve the candidate operations from the generic declaration.
7304 function Is_Private_Overriding (Op : Entity_Id) return Boolean;
7305 -- An operation that overrides an inherited operation in the private
7306 -- part of its package may be hidden, but if the inherited operation
7307 -- is visible a direct call to it will dispatch to the private one,
7308 -- which is therefore a valid candidate.
7310 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
7311 -- Verify that the prefix, dereferenced if need be, is a valid
7312 -- controlling argument in a call to Op. The remaining actuals
7313 -- are checked in the subsequent call to Analyze_One_Call.
7315 ------------------------------
7316 -- Collect_Generic_Type_Ops --
7317 ------------------------------
7319 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
7320 Bas : constant Entity_Id := Base_Type (T);
7321 Candidates : constant Elist_Id := New_Elmt_List;
7325 procedure Check_Candidate;
7326 -- The operation is a candidate if its first parameter is a
7327 -- controlling operand of the desired type.
7329 -----------------------
7330 -- Check_Candidate; --
7331 -----------------------
7333 procedure Check_Candidate is
7335 Formal := First_Formal (Subp);
7338 and then Is_Controlling_Formal (Formal)
7340 (Base_Type (Etype (Formal)) = Bas
7342 (Is_Access_Type (Etype (Formal))
7343 and then Designated_Type (Etype (Formal)) = Bas))
7345 Append_Elmt (Subp, Candidates);
7347 end Check_Candidate;
7349 -- Start of processing for Collect_Generic_Type_Ops
7352 if Is_Derived_Type (T) then
7353 return Primitive_Operations (T);
7355 elsif Ekind_In (Scope (T), E_Procedure, E_Function) then
7357 -- Scan the list of generic formals to find subprograms
7358 -- that may have a first controlling formal of the type.
7360 if Nkind (Unit_Declaration_Node (Scope (T)))
7361 = N_Generic_Subprogram_Declaration
7368 First (Generic_Formal_Declarations
7369 (Unit_Declaration_Node (Scope (T))));
7370 while Present (Decl) loop
7371 if Nkind (Decl) in N_Formal_Subprogram_Declaration then
7372 Subp := Defining_Entity (Decl);
7383 -- Scan the list of entities declared in the same scope as
7384 -- the type. In general this will be an open scope, given that
7385 -- the call we are analyzing can only appear within a generic
7386 -- declaration or body (either the one that declares T, or a
7389 -- For a subtype representing a generic actual type, go to the
7392 if Is_Generic_Actual_Type (T) then
7393 Subp := First_Entity (Scope (Base_Type (T)));
7395 Subp := First_Entity (Scope (T));
7398 while Present (Subp) loop
7399 if Is_Overloadable (Subp) then
7408 end Collect_Generic_Type_Ops;
7410 ---------------------------
7411 -- Is_Private_Overriding --
7412 ---------------------------
7414 function Is_Private_Overriding (Op : Entity_Id) return Boolean is
7415 Visible_Op : constant Entity_Id := Homonym (Op);
7418 return Present (Visible_Op)
7419 and then Scope (Op) = Scope (Visible_Op)
7420 and then not Comes_From_Source (Visible_Op)
7421 and then Alias (Visible_Op) = Op
7422 and then not Is_Hidden (Visible_Op);
7423 end Is_Private_Overriding;
7425 -----------------------------
7426 -- Valid_First_Argument_Of --
7427 -----------------------------
7429 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
7430 Typ : Entity_Id := Etype (First_Formal (Op));
7433 if Is_Concurrent_Type (Typ)
7434 and then Present (Corresponding_Record_Type (Typ))
7436 Typ := Corresponding_Record_Type (Typ);
7439 -- Simple case. Object may be a subtype of the tagged type or
7440 -- may be the corresponding record of a synchronized type.
7442 return Obj_Type = Typ
7443 or else Base_Type (Obj_Type) = Typ
7444 or else Corr_Type = Typ
7446 -- Prefix can be dereferenced
7449 (Is_Access_Type (Corr_Type)
7450 and then Designated_Type (Corr_Type) = Typ)
7452 -- Formal is an access parameter, for which the object
7453 -- can provide an access.
7456 (Ekind (Typ) = E_Anonymous_Access_Type
7458 Base_Type (Designated_Type (Typ)) = Base_Type (Corr_Type));
7459 end Valid_First_Argument_Of;
7461 -- Start of processing for Try_Primitive_Operation
7464 -- Look for subprograms in the list of primitive operations. The name
7465 -- must be identical, and the kind of call indicates the expected
7466 -- kind of operation (function or procedure). If the type is a
7467 -- (tagged) synchronized type, the primitive ops are attached to the
7468 -- corresponding record (base) type.
7470 if Is_Concurrent_Type (Obj_Type) then
7471 if Present (Corresponding_Record_Type (Obj_Type)) then
7472 Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
7473 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
7475 Corr_Type := Obj_Type;
7476 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
7479 elsif not Is_Generic_Type (Obj_Type) then
7480 Corr_Type := Obj_Type;
7481 Elmt := First_Elmt (Primitive_Operations (Obj_Type));
7484 Corr_Type := Obj_Type;
7485 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
7488 while Present (Elmt) loop
7489 Prim_Op := Node (Elmt);
7491 if Chars (Prim_Op) = Chars (Subprog)
7492 and then Present (First_Formal (Prim_Op))
7493 and then Valid_First_Argument_Of (Prim_Op)
7495 (Nkind (Call_Node) = N_Function_Call)
7496 = (Ekind (Prim_Op) = E_Function)
7498 -- Ada 2005 (AI-251): If this primitive operation corresponds
7499 -- with an immediate ancestor interface there is no need to add
7500 -- it to the list of interpretations; the corresponding aliased
7501 -- primitive is also in this list of primitive operations and
7502 -- will be used instead.
7504 if (Present (Interface_Alias (Prim_Op))
7505 and then Is_Ancestor (Find_Dispatching_Type
7506 (Alias (Prim_Op)), Corr_Type))
7508 -- Do not consider hidden primitives unless the type is in an
7509 -- open scope or we are within an instance, where visibility
7510 -- is known to be correct, or else if this is an overriding
7511 -- operation in the private part for an inherited operation.
7513 or else (Is_Hidden (Prim_Op)
7514 and then not Is_Immediately_Visible (Obj_Type)
7515 and then not In_Instance
7516 and then not Is_Private_Overriding (Prim_Op))
7521 Set_Etype (Call_Node, Any_Type);
7522 Set_Is_Overloaded (Call_Node, False);
7524 if No (Matching_Op) then
7525 Prim_Op_Ref := New_Reference_To (Prim_Op, Sloc (Subprog));
7526 Candidate := Prim_Op;
7528 Set_Parent (Call_Node, Parent (Node_To_Replace));
7530 Set_Name (Call_Node, Prim_Op_Ref);
7536 Report => Report_Error,
7538 Skip_First => True);
7540 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
7542 -- More than one interpretation, collect for subsequent
7543 -- disambiguation. If this is a procedure call and there
7544 -- is another match, report ambiguity now.
7550 Report => Report_Error,
7552 Skip_First => True);
7554 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
7555 and then Nkind (Call_Node) /= N_Function_Call
7557 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
7558 Report_Ambiguity (Matching_Op);
7559 Report_Ambiguity (Prim_Op);
7569 if Present (Matching_Op) then
7570 Set_Etype (Call_Node, Etype (Matching_Op));
7573 return Present (Matching_Op);
7574 end Try_Primitive_Operation;
7576 -- Start of processing for Try_Object_Operation
7579 Analyze_Expression (Obj);
7581 -- Analyze the actuals if node is known to be a subprogram call
7583 if Is_Subprg_Call and then N = Name (Parent (N)) then
7584 Actual := First (Parameter_Associations (Parent (N)));
7585 while Present (Actual) loop
7586 Analyze_Expression (Actual);
7591 -- Build a subprogram call node, using a copy of Obj as its first
7592 -- actual. This is a placeholder, to be replaced by an explicit
7593 -- dereference when needed.
7595 Transform_Object_Operation
7596 (Call_Node => New_Call_Node,
7597 Node_To_Replace => Node_To_Replace);
7599 Set_Etype (New_Call_Node, Any_Type);
7600 Set_Etype (Subprog, Any_Type);
7601 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
7603 if not Is_Overloaded (Obj) then
7604 Try_One_Prefix_Interpretation (Obj_Type);
7611 Get_First_Interp (Obj, I, It);
7612 while Present (It.Nam) loop
7613 Try_One_Prefix_Interpretation (It.Typ);
7614 Get_Next_Interp (I, It);
7619 if Etype (New_Call_Node) /= Any_Type then
7620 Complete_Object_Operation
7621 (Call_Node => New_Call_Node,
7622 Node_To_Replace => Node_To_Replace);
7625 elsif Present (Candidate) then
7627 -- The argument list is not type correct. Re-analyze with error
7628 -- reporting enabled, and use one of the possible candidates.
7629 -- In All_Errors_Mode, re-analyze all failed interpretations.
7631 if All_Errors_Mode then
7632 Report_Error := True;
7633 if Try_Primitive_Operation
7634 (Call_Node => New_Call_Node,
7635 Node_To_Replace => Node_To_Replace)
7638 Try_Class_Wide_Operation
7639 (Call_Node => New_Call_Node,
7640 Node_To_Replace => Node_To_Replace)
7647 (N => New_Call_Node,
7651 Skip_First => True);
7654 -- No need for further errors
7659 -- There was no candidate operation, so report it as an error
7660 -- in the caller: Analyze_Selected_Component.
7664 end Try_Object_Operation;
7670 procedure wpo (T : Entity_Id) is
7675 if not Is_Tagged_Type (T) then
7679 E := First_Elmt (Primitive_Operations (Base_Type (T)));
7680 while Present (E) loop
7682 Write_Int (Int (Op));
7683 Write_Str (" === ");
7684 Write_Name (Chars (Op));
7686 Write_Name (Chars (Scope (Op)));