1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2025, 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 Accessibility; use Accessibility;
27 with Aspects; use Aspects;
28 with Atree; use Atree;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Einfo.Entities; use Einfo.Entities;
32 with Einfo.Utils; use Einfo.Utils;
33 with Elists; use Elists;
34 with Errid; use Errid;
35 with Errout; use Errout;
36 with Exp_Util; use Exp_Util;
37 with Itypes; use Itypes;
39 with Lib.Xref; use Lib.Xref;
40 with Mutably_Tagged; use Mutably_Tagged;
41 with Namet; use Namet;
42 with Namet.Sp; use Namet.Sp;
43 with Nlists; use Nlists;
44 with Nmake; use Nmake;
46 with Output; use Output;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
51 with Sem_Aux; use Sem_Aux;
52 with Sem_Case; use Sem_Case;
53 with Sem_Cat; use Sem_Cat;
54 with Sem_Ch3; use Sem_Ch3;
55 with Sem_Ch6; use Sem_Ch6;
56 with Sem_Ch8; use Sem_Ch8;
57 with Sem_Dim; use Sem_Dim;
58 with Sem_Disp; use Sem_Disp;
59 with Sem_Dist; use Sem_Dist;
60 with Sem_Eval; use Sem_Eval;
61 with Sem_Res; use Sem_Res;
62 with Sem_Type; use Sem_Type;
63 with Sem_Util; use Sem_Util;
64 with Sem_Warn; use Sem_Warn;
65 with Stand; use Stand;
66 with Sinfo; use Sinfo;
67 with Sinfo.Nodes; use Sinfo.Nodes;
68 with Sinfo.Utils; use Sinfo.Utils;
69 with Snames; use Snames;
70 with Style; use Style;
71 with Tbuild; use Tbuild;
72 with Uintp; use Uintp;
73 with Warnsw; use Warnsw;
75 package body Sem_Ch4 is
77 -- Tables which speed up the identification of dangerous calls to Ada 2012
78 -- functions with writable actuals (AI05-0144).
80 -- The following table enumerates the Ada constructs which may evaluate in
81 -- arbitrary order. It does not cover all the language constructs which can
82 -- be evaluated in arbitrary order but the subset needed for AI05-0144.
84 Has_Arbitrary_Evaluation_Order : constant array (Node_Kind) of Boolean :=
86 N_Assignment_Statement => True,
87 N_Entry_Call_Statement => True,
88 N_Extension_Aggregate => True,
89 N_Full_Type_Declaration => True,
90 N_Indexed_Component => True,
91 N_Object_Declaration => True,
95 N_Array_Type_Definition => True,
96 N_Membership_Test => True,
98 N_Subprogram_Call => True,
101 -- The following table enumerates the nodes on which we stop climbing when
102 -- locating the outermost Ada construct that can be evaluated in arbitrary
105 Stop_Subtree_Climbing : constant array (Node_Kind) of Boolean :=
106 (N_Aggregate => True,
107 N_Assignment_Statement => True,
108 N_Entry_Call_Statement => True,
109 N_Extended_Return_Statement => True,
110 N_Extension_Aggregate => True,
111 N_Full_Type_Declaration => True,
112 N_Object_Declaration => True,
113 N_Object_Renaming_Declaration => True,
114 N_Package_Specification => True,
116 N_Procedure_Call_Statement => True,
117 N_Simple_Return_Statement => True,
118 N_Has_Condition => True,
121 -----------------------
122 -- Local Subprograms --
123 -----------------------
125 procedure Analyze_Concatenation_Rest (N : Node_Id);
126 -- Does the "rest" of the work of Analyze_Concatenation, after the left
127 -- operand has been analyzed. See Analyze_Concatenation for details.
129 procedure Analyze_Expression (N : Node_Id);
130 -- For expressions that are not names, this is just a call to analyze. If
131 -- the expression is a name, it may be a call to a parameterless function,
132 -- and if so must be converted into an explicit call node and analyzed as
133 -- such. This deproceduring must be done during the first pass of overload
134 -- resolution, because otherwise a procedure call with overloaded actuals
135 -- may fail to resolve.
137 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
138 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call is an
139 -- operator name or an expanded name whose selector is an operator name,
140 -- and one possible interpretation is as a predefined operator.
142 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
143 -- If the prefix of a selected_component is overloaded, the proper
144 -- interpretation that yields a record type with the proper selector
145 -- name must be selected.
147 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
148 -- Procedure to analyze a user defined binary operator, which is resolved
149 -- like a function, but instead of a list of actuals it is presented
150 -- with the left and right operands of an operator node.
152 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
153 -- Procedure to analyze a user defined unary operator, which is resolved
154 -- like a function, but instead of a list of actuals, it is presented with
155 -- the operand of the operator node.
157 procedure Analyze_One_Call
161 Success : out Boolean;
162 Skip_First : Boolean := False);
163 -- Check one interpretation of an overloaded subprogram name for
164 -- compatibility with the types of the actuals in a call. If there is a
165 -- single interpretation which does not match, post error if Report is
168 -- Nam is the entity that provides the formals against which the actuals
169 -- are checked. Nam is either the name of a subprogram, or the internal
170 -- subprogram type constructed for an access_to_subprogram. If the actuals
171 -- are compatible with Nam, then Nam is added to the list of candidate
172 -- interpretations for N, and Success is set to True.
174 -- The flag Skip_First is used when analyzing a call that was rewritten
175 -- from object notation. In this case the first actual may have to receive
176 -- an explicit dereference, depending on the first formal of the operation
177 -- being called. The caller will have verified that the object is legal
178 -- for the call. If the remaining parameters match, the first parameter
179 -- will rewritten as a dereference if needed, prior to completing analysis.
181 procedure Check_Misspelled_Selector
184 -- Give possible misspelling message if Sel seems likely to be a mis-
185 -- spelling of one of the selectors of the Prefix. This is called by
186 -- Analyze_Selected_Component after producing an invalid selector error
189 procedure Find_Arithmetic_Types
193 -- L and R are the operands of an arithmetic operator. Find consistent
194 -- pairs of interpretations for L and R that have a numeric type consistent
195 -- with the semantics of the operator.
197 procedure Find_Comparison_Equality_Types
201 -- L and R are operands of a comparison or equality operator. Find valid
202 -- pairs of interpretations for L and R.
204 procedure Find_Concatenation_Types
208 -- For the four varieties of concatenation
210 procedure Find_Boolean_Types
214 -- Ditto for binary logical operations
216 procedure Find_Negation_Types
220 -- Find consistent interpretation for operand of negation operator
222 function Find_Primitive_Operation (N : Node_Id) return Boolean;
223 -- Find candidate interpretations for the name Obj.Proc when it appears in
224 -- a subprogram renaming declaration.
226 procedure Find_Unary_Types
230 -- Unary arithmetic types: plus, minus, abs
232 procedure Check_Arithmetic_Pair
236 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid types
237 -- for left and right operand. Determine whether they constitute a valid
238 -- pair for the given operator, and record the corresponding interpretation
239 -- of the operator node. The node N may be an operator node (the usual
240 -- case) or a function call whose prefix is an operator designator. In
241 -- both cases Op_Id is the operator name itself.
243 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
244 -- Give detailed information on overloaded call where none of the
245 -- interpretations match. N is the call node, Nam the designator for
246 -- the overloaded entity being called.
248 function Junk_Operand (N : Node_Id) return Boolean;
249 -- Test for an operand that is an inappropriate entity (e.g. a package
250 -- name or a label). If so, issue an error message and return True. If
251 -- the operand is not an inappropriate entity kind, return False.
253 procedure Operator_Check (N : Node_Id);
254 -- Verify that an operator has received some valid interpretation. If none
255 -- was found, determine whether a use clause would make the operation
256 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
257 -- every type compatible with the operator, even if the operator for the
258 -- type is not directly visible. The routine uses this type to emit a more
259 -- informative message.
261 function Has_Possible_User_Defined_Literal (N : Node_Id) return Boolean;
262 -- Ada 2022: if an operand is a literal, it may be subject to an
263 -- implicit conversion to a type for which a user-defined literal
264 -- function exists. During the first pass of type resolution we do
265 -- not know the context imposed on the literal, so we assume that
266 -- the literal type is a valid candidate and rely on the second pass
267 -- of resolution to find the type with the proper aspect. We only
268 -- add this interpretation if no other one was found, which may be
269 -- too restrictive but seems sufficient to handle most proper uses
270 -- of the new aspect. It is unclear whether a full implementation of
271 -- these aspects can be achieved without larger modifications to the
272 -- two-pass resolution algorithm.
274 function Is_Effectively_Visible_Operator
275 (N : Node_Id; Typ : Entity_Id) return Boolean
276 is (Is_Visible_Operator (N => N, Typ => Typ)
278 -- test for a rewritten Foo."+" call
279 (N /= Original_Node (N)
280 and then Is_Effectively_Visible_Operator
281 (N => Original_Node (N), Typ => Typ))
282 or else Checking_Potentially_Static_Expression
283 or else not Comes_From_Source (N));
284 -- Return True iff either Is_Visible_Operator returns True or if
285 -- there is a reason it is ok for Is_Visible_Operator to return False.
287 function Possible_Type_For_Conditional_Expression
288 (T1, T2 : Entity_Id) return Entity_Id;
289 -- Given two types T1 and T2 that are _not_ compatible, return a type that
290 -- may still be used as the possible type of a conditional expression whose
291 -- dependent expressions, or part thereof, have type T1 and T2 respectively
292 -- during the first phase of type resolution, or Empty if such a type does
295 -- The typical example is an if_expression whose then_expression is of a
296 -- tagged type and whose else_expresssion is of an extension of this type:
297 -- the types are not compatible but such an if_expression can be legal if
298 -- its expected type is the 'Class of the tagged type, so the function will
299 -- return the tagged type in this case. If the expected type turns out to
300 -- be something else, including the tagged type itself, then an error will
301 -- be given during the second phase of type resolution.
303 procedure Remove_Abstract_Operations (N : Node_Id);
304 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
305 -- operation is not a candidate interpretation.
307 function Try_Container_Indexing
310 Exprs : List_Id) return Boolean;
311 -- AI05-0139: Generalized indexing to support iterators over containers.
312 -- Given the N_Indexed_Component node N, with the given prefix and
313 -- expressions list, check if the generalized indexing is applicable;
314 -- if applicable then build its indexing function, link it to N through
315 -- attribute Generalized_Indexing, and return True; otherwise return
318 function Try_Indexed_Call
322 Skip_First : Boolean) return Boolean;
323 -- If a function has defaults for all its actuals, a call to it may in fact
324 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
325 -- interpretation as an indexing, prior to analysis as a call. If both are
326 -- possible, the node is overloaded with both interpretations (same symbol
327 -- but two different types). If the call is written in prefix form, the
328 -- prefix becomes the first parameter in the call, and only the remaining
329 -- actuals must be checked for the presence of defaults.
331 function Try_Indirect_Call
334 Typ : Entity_Id) return Boolean;
335 -- Similarly, a function F that needs no actuals can return an access to a
336 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
337 -- the call may be overloaded with both interpretations.
339 procedure wpo (T : Entity_Id);
340 pragma Warnings (Off, wpo);
341 -- Used for debugging: obtain list of primitive operations even if
342 -- type is not frozen and dispatch table is not built yet.
344 ------------------------
345 -- Ambiguous_Operands --
346 ------------------------
348 procedure Ambiguous_Operands (N : Node_Id) is
349 procedure List_Operand_Interps (Opnd : Node_Id);
351 --------------------------
352 -- List_Operand_Interps --
353 --------------------------
355 procedure List_Operand_Interps (Opnd : Node_Id) is
356 Nam : Node_Id := Empty;
360 if Is_Overloaded (Opnd) then
361 if Nkind (Opnd) in N_Op then
364 elsif Nkind (Opnd) = N_Function_Call then
367 elsif Ada_Version >= Ada_2012 then
373 Get_First_Interp (Opnd, I, It);
374 while Present (It.Nam) loop
375 if Has_Implicit_Dereference (It.Typ) then
377 ("can be interpreted as implicit dereference", Opnd);
381 Get_Next_Interp (I, It);
392 if Opnd = Left_Opnd (N) then
394 ("\left operand has the following interpretations", N);
397 ("\right operand has the following interpretations", N);
401 List_Interps (Nam, Err);
402 end List_Operand_Interps;
404 -- Start of processing for Ambiguous_Operands
407 if Nkind (N) in N_Membership_Test then
408 Error_Msg_N ("ambiguous operands for membership", N);
410 elsif Nkind (N) in N_Op_Eq | N_Op_Ne then
411 Error_Msg_N ("ambiguous operands for equality", N);
414 Error_Msg_N ("ambiguous operands for comparison", N);
417 if All_Errors_Mode then
418 List_Operand_Interps (Left_Opnd (N));
419 List_Operand_Interps (Right_Opnd (N));
421 Error_Msg_N ("\use -gnatf switch for details", N);
423 end Ambiguous_Operands;
425 -----------------------
426 -- Analyze_Aggregate --
427 -----------------------
429 -- Most of the analysis of Aggregates requires that the type be known, and
430 -- is therefore put off until resolution of the context. Delta aggregates
431 -- have a base component that determines the enclosing aggregate type so
432 -- its type can be ascertained earlier. This also allows delta aggregates
433 -- to appear in the context of a record type with a private extension, as
434 -- per the latest update of AI12-0127.
436 procedure Analyze_Aggregate (N : Node_Id) is
438 if No (Etype (N)) then
439 if Nkind (N) = N_Delta_Aggregate then
441 Base : constant Node_Id := Expression (N);
449 -- If the base is overloaded, propagate interpretations to the
450 -- enclosing aggregate.
452 if Is_Overloaded (Base) then
453 Get_First_Interp (Base, I, It);
454 Set_Etype (N, Any_Type);
456 while Present (It.Nam) loop
457 Add_One_Interp (N, It.Typ, It.Typ);
458 Get_Next_Interp (I, It);
462 Set_Etype (N, Etype (Base));
467 Set_Etype (N, Any_Composite);
470 end Analyze_Aggregate;
472 -----------------------
473 -- Analyze_Allocator --
474 -----------------------
476 procedure Analyze_Allocator (N : Node_Id) is
477 Loc : constant Source_Ptr := Sloc (N);
478 Sav_Errs : constant Nat := Serious_Errors_Detected;
479 E : Node_Id := Expression (N);
480 Acc_Type : Entity_Id;
487 -- Deal with allocator restrictions
489 -- In accordance with H.4(7), the No_Allocators restriction only applies
490 -- to user-written allocators. The same consideration applies to the
491 -- No_Standard_Allocators_Before_Elaboration restriction.
493 if Comes_From_Source (N) then
494 Check_Restriction (No_Allocators, N);
496 -- Processing for No_Standard_Allocators_After_Elaboration, loop to
497 -- look at enclosing context, checking task/main subprogram case.
501 while Present (P) loop
503 -- For the task case we need a handled sequence of statements,
504 -- where the occurrence of the allocator is within the statements
505 -- and the parent is a task body
507 if Nkind (P) = N_Handled_Sequence_Of_Statements
508 and then Is_List_Member (C)
509 and then List_Containing (C) = Statements (P)
511 Onode := Original_Node (Parent (P));
513 -- Check for allocator within task body, this is a definite
514 -- violation of No_Allocators_After_Elaboration we can detect
517 if Nkind (Onode) = N_Task_Body then
519 (No_Standard_Allocators_After_Elaboration, N);
524 -- The other case is appearance in a subprogram body. This is
525 -- a violation if this is a library level subprogram with no
526 -- parameters. Note that this is now a static error even if the
527 -- subprogram is not the main program (this is a change, in an
528 -- earlier version only the main program was affected, and the
529 -- check had to be done in the binder).
531 if Nkind (P) = N_Subprogram_Body
532 and then Nkind (Parent (P)) = N_Compilation_Unit
533 and then No (Parameter_Specifications (Specification (P)))
536 (No_Standard_Allocators_After_Elaboration, N);
544 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
545 -- any. The expected type for the name is any type. A non-overloading
546 -- rule then requires it to be of a type descended from
547 -- System.Storage_Pools.Subpools.Subpool_Handle.
549 -- This isn't exactly what the AI says, but it seems to be the right
550 -- rule. The AI should be fixed.???
553 Subpool : constant Node_Id := Subpool_Handle_Name (N);
556 if Present (Subpool) then
559 if Is_Overloaded (Subpool) then
560 Error_Msg_N ("ambiguous subpool handle", Subpool);
563 -- Check that Etype (Subpool) is descended from Subpool_Handle
569 -- Analyze the qualified expression or subtype indication
571 if Nkind (E) = N_Qualified_Expression then
572 Acc_Type := Create_Itype (E_Allocator_Type, N);
573 Set_Etype (Acc_Type, Acc_Type);
574 Find_Type (Subtype_Mark (E));
576 -- Analyze the qualified expression, and apply the name resolution
577 -- rule given in 4.7(3).
580 Type_Id := Etype (E);
581 Set_Directly_Designated_Type (Acc_Type, Type_Id);
583 -- A qualified expression requires an exact match of the type,
584 -- class-wide matching is not allowed.
586 -- if Is_Class_Wide_Type (Type_Id)
587 -- and then Base_Type
588 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
590 -- Wrong_Type (Expression (E), Type_Id);
593 -- We don't analyze the qualified expression itself because it's
594 -- part of the allocator. It is fully analyzed and resolved when
595 -- the allocator is resolved with the context type.
597 -- Case where allocator has a subtype indication
600 -- If the allocator includes a N_Subtype_Indication then a
601 -- constraint is present, otherwise the node is a subtype mark.
602 -- Introduce an explicit subtype declaration into the tree
603 -- defining some anonymous subtype and rewrite the allocator to
604 -- use this subtype rather than the subtype indication.
606 -- It is important to introduce the explicit subtype declaration
607 -- so that the bounds of the subtype indication are attached to
608 -- the tree in case the allocator is inside a generic unit.
610 -- Finally, if there is no subtype indication and the type is
611 -- a tagged unconstrained type with discriminants, the designated
612 -- object is constrained by their default values, and it is
613 -- simplest to introduce an explicit constraint now. In some cases
614 -- this is done during expansion, but freeze actions are certain
615 -- to be emitted in the proper order if constraint is explicit.
617 if Is_Entity_Name (E) and then Expander_Active then
619 Type_Id := Entity (E);
621 if Is_Tagged_Type (Type_Id)
622 and then Has_Defaulted_Discriminants (Type_Id)
623 and then not Is_Constrained (Type_Id)
626 Constr : constant List_Id := New_List;
627 Loc : constant Source_Ptr := Sloc (E);
628 Discr : Entity_Id := First_Discriminant (Type_Id);
631 while Present (Discr) loop
632 Append (Discriminant_Default_Value (Discr), Constr);
633 Next_Discriminant (Discr);
637 Make_Subtype_Indication (Loc,
638 Subtype_Mark => New_Occurrence_Of (Type_Id, Loc),
640 Make_Index_Or_Discriminant_Constraint (Loc,
641 Constraints => Constr)));
644 -- Rewrite the mutably tagged type to a non-class-wide type for
645 -- proper initialization.
647 elsif Is_Mutably_Tagged_Type (Type_Id) then
648 Rewrite (E, New_Occurrence_Of (Etype (Type_Id), Loc));
652 if Nkind (E) = N_Subtype_Indication then
655 Base_Typ : Entity_Id;
658 -- A constraint is only allowed for a composite type in Ada
659 -- 95. In Ada 83, a constraint is also allowed for an
660 -- access-to-composite type, but the constraint is ignored.
662 Find_Type (Subtype_Mark (E));
663 Base_Typ := Entity (Subtype_Mark (E));
665 if Is_Elementary_Type (Base_Typ) then
666 if not (Ada_Version = Ada_83
667 and then Is_Access_Type (Base_Typ))
669 Error_Msg_N ("constraint not allowed here", E);
671 if Nkind (Constraint (E)) =
672 N_Index_Or_Discriminant_Constraint
674 Error_Msg_N -- CODEFIX
675 ("\if qualified expression was meant, " &
676 "use apostrophe", Constraint (E));
680 -- Get rid of the bogus constraint:
682 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
683 Analyze_Allocator (N);
687 -- In GNATprove mode we need to preserve the link between
688 -- the original subtype indication and the anonymous subtype,
689 -- to extend proofs to constrained access types. We only do
690 -- that outside of spec expressions, otherwise the declaration
691 -- cannot be inserted and analyzed. In such a case, GNATprove
692 -- later rejects the allocator as it is not used here in
693 -- a non-interfering context (SPARK 4.8(2) and 7.1.3(10)).
696 or else (GNATprove_Mode and then not In_Spec_Expression)
698 Def_Id := Make_Temporary (Loc, 'S');
701 Subtype_Decl : constant Node_Id :=
702 Make_Subtype_Declaration (Loc,
703 Defining_Identifier => Def_Id,
704 Subtype_Indication => Relocate_Node (E));
706 Insert_Action (E, Subtype_Decl);
708 -- Handle unusual case where Insert_Action does not
709 -- analyze the declaration. Subtype_Decl must be
710 -- preanalyzed before call to Process_Subtype below.
711 Preanalyze (Subtype_Decl);
714 if Sav_Errs /= Serious_Errors_Detected
715 and then Nkind (Constraint (E)) =
716 N_Index_Or_Discriminant_Constraint
718 Error_Msg_N -- CODEFIX
719 ("if qualified expression was meant, use apostrophe!",
723 E := New_Occurrence_Of (Def_Id, Loc);
724 Rewrite (Expression (N), E);
730 Process_Subtype (E, N, Excludes_Null => Null_Exclusion_Present (N));
731 Acc_Type := Create_Itype (E_Allocator_Type, N);
732 Set_Etype (Acc_Type, Acc_Type);
733 Set_Directly_Designated_Type (Acc_Type, Type_Id);
734 Check_Fully_Declared (Type_Id, N);
736 -- Ada 2005 (AI-231): If the designated type is itself an access
737 -- type that excludes null, its default initialization (if any)
738 -- will be a null object and we can insert an unconditional raise
739 -- before the allocator.
741 -- Ada 2012 (AI-104): A not null indication here is altogether
744 if Can_Never_Be_Null (Type_Id) and then not No_Initialization (N) then
745 if Expander_Active then
746 Apply_Compile_Time_Constraint_Error
747 (N, "null value not allowed here??", CE_Null_Not_Allowed);
749 elsif Warn_On_Ada_2012_Compatibility then
751 ("null value not allowed here in Ada 2012?y?", E);
755 -- Check for missing initialization. Skip this check if the allocator
756 -- is made for a special return object or if we already had errors on
757 -- analyzing the allocator since, in that case, these are very likely
760 if not Is_Definite_Subtype (Type_Id)
761 and then not For_Special_Return_Object (N)
762 and then Serious_Errors_Detected = Sav_Errs
764 if Is_Class_Wide_Type (Type_Id) then
766 ("initialization required in class-wide allocation", N);
769 if Ada_Version < Ada_2005
770 and then Is_Limited_Type (Type_Id)
772 Error_Msg_N ("unconstrained allocation not allowed", N);
774 if Is_Array_Type (Type_Id) then
776 ("\constraint with array bounds required", N);
778 elsif Has_Unknown_Discriminants (Type_Id) then
781 else pragma Assert (Has_Discriminants (Type_Id));
783 ("\constraint with discriminant values required", N);
786 -- Limited Ada 2005 and general nonlimited case.
787 -- This is an error, except in the case of an
788 -- uninitialized allocator that is generated
789 -- for a build-in-place function return of a
790 -- discriminated but compile-time-known-size
794 if Is_Rewrite_Substitution (N)
795 and then Nkind (Original_Node (N)) = N_Allocator
798 Qual : constant Node_Id :=
799 Expression (Original_Node (N));
801 (Nkind (Qual) = N_Qualified_Expression);
802 Call : constant Node_Id := Expression (Qual);
804 (Is_Expanded_Build_In_Place_Call (Call));
811 ("uninitialized unconstrained allocation not "
814 if Is_Array_Type (Type_Id) then
816 ("\qualified expression or constraint with "
817 & "array bounds required", N);
819 elsif Has_Unknown_Discriminants (Type_Id) then
820 Error_Msg_N ("\qualified expression required", N);
822 else pragma Assert (Has_Discriminants (Type_Id));
824 ("\qualified expression or constraint with "
825 & "discriminant values required", N);
833 if Is_Abstract_Type (Type_Id) then
834 Error_Msg_N ("cannot allocate abstract object", E);
837 -- If the type of a constrained array has an unconstrained first
838 -- subtype, its Finalize_Address primitive expects the address of
839 -- an object with a dope vector (see Make_Finalize_Address_Stmts).
841 if Is_Constr_Array_Subt_Of_Unc_With_Controlled (Type_Id) then
842 Set_Is_Constr_Array_Subt_With_Bounds (Type_Id);
845 Set_Etype (N, Acc_Type);
847 -- If this is an allocator for the return stack, then no restriction may
848 -- be violated since it's just a low-level access to the primary stack.
850 if Nkind (Parent (N)) = N_Object_Declaration
851 and then Is_Entity_Name (Object_Definition (Parent (N)))
852 and then Is_Access_Type (Entity (Object_Definition (Parent (N))))
855 Pool : constant Entity_Id :=
856 Associated_Storage_Pool
857 (Root_Type (Entity (Object_Definition (Parent (N)))));
860 if Present (Pool) and then Is_RTE (Pool, RE_RS_Pool) then
866 if Has_Task (Designated_Type (Acc_Type)) then
867 Check_Restriction (No_Tasking, N);
868 Check_Restriction (Max_Tasks, N);
869 Check_Restriction (No_Task_Allocators, N);
872 -- Check restriction against dynamically allocated protected objects
874 if Has_Protected (Designated_Type (Acc_Type)) then
875 Check_Restriction (No_Protected_Type_Allocators, N);
878 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
879 -- type is nested, and the designated type needs finalization. The rule
880 -- is conservative in that class-wide types need finalization.
882 if Needs_Finalization (Designated_Type (Acc_Type))
883 and then not Is_Library_Level_Entity (Acc_Type)
885 Check_Restriction (No_Nested_Finalization, N);
888 -- Check that an allocator of a nested access type doesn't create a
889 -- protected object when restriction No_Local_Protected_Objects applies.
891 if Has_Protected (Designated_Type (Acc_Type))
892 and then not Is_Library_Level_Entity (Acc_Type)
894 Check_Restriction (No_Local_Protected_Objects, N);
897 -- Likewise for No_Local_Timing_Events
899 if Has_Timing_Event (Designated_Type (Acc_Type))
900 and then not Is_Library_Level_Entity (Acc_Type)
902 Check_Restriction (No_Local_Timing_Events, N);
905 -- If the No_Streams restriction is set, check that the type of the
906 -- object is not, and does not contain, any subtype derived from
907 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
908 -- Has_Stream just for efficiency reasons. There is no point in
909 -- spending time on a Has_Stream check if the restriction is not set.
911 if Restriction_Check_Required (No_Streams) then
912 if Has_Stream (Designated_Type (Acc_Type)) then
913 Check_Restriction (No_Streams, N);
917 if not Is_Library_Level_Entity (Acc_Type) then
918 Check_Restriction (No_Local_Allocators, N);
922 if Serious_Errors_Detected > Sav_Errs then
923 Set_Error_Posted (N);
924 Set_Etype (N, Any_Type);
926 end Analyze_Allocator;
928 ---------------------------
929 -- Analyze_Arithmetic_Op --
930 ---------------------------
932 procedure Analyze_Arithmetic_Op (N : Node_Id) is
933 L : constant Node_Id := Left_Opnd (N);
934 R : constant Node_Id := Right_Opnd (N);
939 Set_Etype (N, Any_Type);
940 Candidate_Type := Empty;
942 Analyze_Expression (L);
943 Analyze_Expression (R);
945 -- If the entity is already set, the node is the instantiation of a
946 -- generic node with a non-local reference, or was manufactured by a
947 -- call to Make_Op_xxx. In either case the entity is known to be valid,
948 -- and we do not need to collect interpretations, instead we just get
949 -- the single possible interpretation.
951 if Present (Entity (N)) then
954 if Ekind (Op_Id) = E_Operator then
955 Find_Arithmetic_Types (L, R, Op_Id, N);
957 Add_One_Interp (N, Op_Id, Etype (Op_Id));
960 -- Entity is not already set, so we do need to collect interpretations
963 Op_Id := Get_Name_Entity_Id (Chars (N));
964 while Present (Op_Id) loop
965 if Ekind (Op_Id) = E_Operator
966 and then Present (Next_Entity (First_Entity (Op_Id)))
968 Find_Arithmetic_Types (L, R, Op_Id, N);
970 -- The following may seem superfluous, because an operator cannot
971 -- be generic, but this ignores the cleverness of the author of
974 elsif Is_Overloadable (Op_Id) then
975 Analyze_User_Defined_Binary_Op (N, Op_Id);
978 Op_Id := Homonym (Op_Id);
983 Check_Function_Writable_Actuals (N);
984 end Analyze_Arithmetic_Op;
990 -- Function, procedure, and entry calls are checked here. The Name in
991 -- the call may be overloaded. The actuals have been analyzed and may
992 -- themselves be overloaded. On exit from this procedure, the node N
993 -- may have zero, one or more interpretations. In the first case an
994 -- error message is produced. In the last case, the node is flagged
995 -- as overloaded and the interpretations are collected in All_Interp.
997 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
998 -- the type-checking is similar to that of other calls.
1000 procedure Analyze_Call (N : Node_Id) is
1001 Actuals : constant List_Id := Parameter_Associations (N);
1002 Loc : constant Source_Ptr := Sloc (N);
1006 Nam_Ent : Entity_Id := Empty;
1007 Success : Boolean := False;
1009 Deref : Boolean := False;
1010 -- Flag indicates whether an interpretation of the prefix is a
1011 -- parameterless call that returns an access_to_subprogram.
1013 procedure Check_Writable_Actuals (N : Node_Id);
1014 -- If the call has out or in-out parameters then mark its outermost
1015 -- enclosing construct as a node on which the writable actuals check
1016 -- must be performed.
1018 function Name_Denotes_Function return Boolean;
1019 -- If the type of the name is an access to subprogram, this may be the
1020 -- type of a name, or the return type of the function being called. If
1021 -- the name is not an entity then it can denote a protected function.
1022 -- Until we distinguish Etype from Return_Type, we must use this routine
1023 -- to resolve the meaning of the name in the call.
1025 procedure No_Interpretation;
1026 -- Output error message when no valid interpretation exists
1028 ----------------------------
1029 -- Check_Writable_Actuals --
1030 ----------------------------
1032 -- The identification of conflicts in calls to functions with writable
1033 -- actuals is performed in the analysis phase of the front end to ensure
1034 -- that it reports exactly the same errors compiling with and without
1035 -- expansion enabled. It is performed in two stages:
1037 -- 1) When a call to a function with out-mode parameters is found,
1038 -- we climb to the outermost enclosing construct that can be
1039 -- evaluated in arbitrary order and we mark it with the flag
1042 -- 2) When the analysis of the marked node is complete, we traverse
1043 -- its decorated subtree searching for conflicts (see function
1044 -- Sem_Util.Check_Function_Writable_Actuals).
1046 -- The unique exception to this general rule is for aggregates, since
1047 -- their analysis is performed by the front end in the resolution
1048 -- phase. For aggregates we do not climb to their enclosing construct:
1049 -- we restrict the analysis to the subexpressions initializing the
1050 -- aggregate components.
1052 -- This implies that the analysis of expressions containing aggregates
1053 -- is not complete, since there may be conflicts on writable actuals
1054 -- involving subexpressions of the enclosing logical or arithmetic
1055 -- expressions. However, we cannot wait and perform the analysis when
1056 -- the whole subtree is resolved, since the subtrees may be transformed,
1057 -- thus adding extra complexity and computation cost to identify and
1058 -- report exactly the same errors compiling with and without expansion
1061 procedure Check_Writable_Actuals (N : Node_Id) is
1063 if Comes_From_Source (N)
1064 and then Present (Get_Subprogram_Entity (N))
1065 and then Has_Out_Or_In_Out_Parameter (Get_Subprogram_Entity (N))
1067 -- For procedures and entries there is no need to climb since
1068 -- we only need to check if the actuals of this call invoke
1069 -- functions whose out-mode parameters overlap.
1071 if Nkind (N) /= N_Function_Call then
1072 Set_Check_Actuals (N);
1074 -- For calls to functions we climb to the outermost enclosing
1075 -- construct where the out-mode actuals of this function may
1076 -- introduce conflicts.
1080 Outermost : Node_Id := Empty; -- init to avoid warning
1084 while Present (P) loop
1085 -- For object declarations we can climb to the node from
1086 -- its object definition branch or from its initializing
1087 -- expression. We prefer to mark the child node as the
1088 -- outermost construct to avoid adding further complexity
1089 -- to the routine that will later take care of
1090 -- performing the writable actuals check.
1092 if Has_Arbitrary_Evaluation_Order (Nkind (P))
1093 and then Nkind (P) not in
1094 N_Assignment_Statement | N_Object_Declaration
1099 -- Avoid climbing more than needed
1101 exit when Stop_Subtree_Climbing (Nkind (P))
1102 or else (Nkind (P) = N_Range
1104 Nkind (Parent (P)) not in N_In | N_Not_In);
1109 Set_Check_Actuals (Outermost);
1113 end Check_Writable_Actuals;
1115 ---------------------------
1116 -- Name_Denotes_Function --
1117 ---------------------------
1119 function Name_Denotes_Function return Boolean is
1121 if Is_Entity_Name (Nam) then
1122 return Ekind (Entity (Nam)) = E_Function;
1123 elsif Nkind (Nam) = N_Selected_Component then
1124 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
1128 end Name_Denotes_Function;
1130 -----------------------
1131 -- No_Interpretation --
1132 -----------------------
1134 procedure No_Interpretation is
1135 L : constant Boolean := Is_List_Member (N);
1136 K : constant Node_Kind := Nkind (Parent (N));
1139 -- If the node is in a list whose parent is not an expression then it
1140 -- must be an attempted procedure call.
1142 if L and then K not in N_Subexpr then
1143 if Ekind (Entity (Nam)) = E_Generic_Procedure then
1145 ("must instantiate generic procedure& before call",
1148 Error_Msg_N ("procedure or entry name expected", Nam);
1151 -- Check for tasking cases where only an entry call will do
1154 and then K in N_Entry_Call_Alternative | N_Triggering_Alternative
1156 Error_Msg_N ("entry name expected", Nam);
1158 -- Otherwise give general error message
1161 Error_Msg_N ("invalid prefix in call", Nam);
1163 end No_Interpretation;
1165 -- Start of processing for Analyze_Call
1168 -- Initialize the type of the result of the call to the error type,
1169 -- which will be reset if the type is successfully resolved.
1171 Set_Etype (N, Any_Type);
1175 if not Is_Overloaded (Nam) then
1177 -- Only one interpretation to check
1179 if Ekind (Etype (Nam)) = E_Subprogram_Type then
1180 Nam_Ent := Etype (Nam);
1182 -- If the prefix is an access_to_subprogram, this may be an indirect
1183 -- call. This is the case if the name in the call is not an entity
1184 -- name, or if it is a function name in the context of a procedure
1185 -- call. In this latter case, we have a call to a parameterless
1186 -- function that returns a pointer_to_procedure which is the entity
1187 -- being called. Finally, F (X) may be a call to a parameterless
1188 -- function that returns a pointer to a function with parameters.
1189 -- Note that if F returns an access-to-subprogram whose designated
1190 -- type is an array, F (X) cannot be interpreted as an indirect call
1191 -- through the result of the call to F.
1193 elsif Is_Access_Subprogram_Type (Base_Type (Etype (Nam)))
1195 (not Name_Denotes_Function
1196 or else Nkind (N) = N_Procedure_Call_Statement
1198 (Nkind (Parent (N)) /= N_Explicit_Dereference
1199 and then Is_Entity_Name (Nam)
1200 and then No (First_Formal (Entity (Nam)))
1202 Is_Array_Type (Etype (Designated_Type (Etype (Nam))))
1203 and then Present (Actuals)))
1205 Nam_Ent := Designated_Type (Etype (Nam));
1206 Insert_Explicit_Dereference (Nam);
1208 -- Selected component case. Simple entry or protected operation,
1209 -- where the entry name is given by the selector name.
1211 elsif Nkind (Nam) = N_Selected_Component then
1212 Nam_Ent := Entity (Selector_Name (Nam));
1214 if Ekind (Nam_Ent) not in E_Entry
1219 Error_Msg_N ("name in call is not a callable entity", Nam);
1220 Set_Etype (N, Any_Type);
1224 -- If the name is an Indexed component, it can be a call to a member
1225 -- of an entry family. The prefix must be a selected component whose
1226 -- selector is the entry. Analyze_Procedure_Call normalizes several
1227 -- kinds of call into this form.
1229 elsif Nkind (Nam) = N_Indexed_Component then
1230 if Nkind (Prefix (Nam)) = N_Selected_Component then
1231 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
1233 Error_Msg_N ("name in call is not a callable entity", Nam);
1234 Set_Etype (N, Any_Type);
1238 elsif not Is_Entity_Name (Nam) then
1239 Error_Msg_N ("name in call is not a callable entity", Nam);
1240 Set_Etype (N, Any_Type);
1244 Nam_Ent := Entity (Nam);
1246 -- If not overloadable, this may be a generalized indexing
1247 -- operation with named associations. Rewrite again as an
1248 -- indexed component and analyze as container indexing.
1250 if not Is_Overloadable (Nam_Ent) then
1252 (Find_Value_Of_Aspect
1253 (Etype (Nam_Ent), Aspect_Constant_Indexing))
1256 Make_Indexed_Component (Sloc (N),
1258 Expressions => Parameter_Associations (N)));
1260 if Try_Container_Indexing (N, Nam, Expressions (N)) then
1274 -- Operations generated for RACW stub types are called only through
1275 -- dispatching, and can never be the static interpretation of a call.
1277 if Is_RACW_Stub_Type_Operation (Nam_Ent) then
1282 Analyze_One_Call (N, Nam_Ent, True, Success);
1284 -- If the nonoverloaded interpretation is a call to an abstract
1285 -- nondispatching operation, then flag an error and return.
1287 if Is_Overloadable (Nam_Ent)
1288 and then Is_Abstract_Subprogram (Nam_Ent)
1289 and then not Is_Dispatching_Operation (Nam_Ent)
1291 Nondispatching_Call_To_Abstract_Operation (N, Nam_Ent);
1295 -- If this is an indirect call, the return type of the access_to
1296 -- subprogram may be an incomplete type. At the point of the call,
1297 -- use the full type if available, and at the same time update the
1298 -- return type of the access_to_subprogram.
1301 and then Nkind (Nam) = N_Explicit_Dereference
1302 and then Ekind (Etype (N)) = E_Incomplete_Type
1303 and then Present (Full_View (Etype (N)))
1305 Set_Etype (N, Full_View (Etype (N)));
1306 Set_Etype (Nam_Ent, Etype (N));
1312 -- An overloaded selected component must denote overloaded operations
1313 -- of a concurrent type. The interpretations are attached to the
1314 -- simple name of those operations.
1316 if Nkind (Nam) = N_Selected_Component then
1317 Nam := Selector_Name (Nam);
1320 Get_First_Interp (Nam, X, It);
1321 while Present (It.Nam) loop
1325 -- Name may be call that returns an access to subprogram, or more
1326 -- generally an overloaded expression one of whose interpretations
1327 -- yields an access to subprogram. If the name is an entity, we do
1328 -- not dereference, because the node is a call that returns the
1329 -- access type: note difference between f(x), where the call may
1330 -- return an access subprogram type, and f(x)(y), where the type
1331 -- returned by the call to f is implicitly dereferenced to analyze
1334 if Is_Access_Type (Nam_Ent) then
1335 Nam_Ent := Designated_Type (Nam_Ent);
1337 elsif Is_Access_Type (Etype (Nam_Ent))
1339 (not Is_Entity_Name (Nam)
1340 or else Nkind (N) = N_Procedure_Call_Statement)
1341 and then Ekind (Designated_Type (Etype (Nam_Ent)))
1344 Nam_Ent := Designated_Type (Etype (Nam_Ent));
1346 if Is_Entity_Name (Nam) then
1351 -- If the call has been rewritten from a prefixed call, the first
1352 -- parameter has been analyzed, but may need a subsequent
1353 -- dereference, so skip its analysis now.
1355 if Is_Rewrite_Substitution (N)
1356 and then Nkind (Original_Node (N)) = Nkind (N)
1357 and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N)))
1358 and then Present (Parameter_Associations (N))
1359 and then Present (Etype (First (Parameter_Associations (N))))
1362 (N, Nam_Ent, False, Success, Skip_First => True);
1364 Analyze_One_Call (N, Nam_Ent, False, Success);
1367 -- If the interpretation succeeds, mark the proper type of the
1368 -- prefix (any valid candidate will do). If not, remove the
1369 -- candidate interpretation. If this is a parameterless call
1370 -- on an anonymous access to subprogram, X is a variable with
1371 -- an access discriminant D, the entity in the interpretation is
1372 -- D, so rewrite X as X.D.all.
1376 and then Nkind (Parent (N)) /= N_Explicit_Dereference
1378 if Ekind (It.Nam) = E_Discriminant
1379 and then Has_Implicit_Dereference (It.Nam)
1382 Make_Explicit_Dereference (Loc,
1384 Make_Selected_Component (Loc,
1386 New_Occurrence_Of (Entity (Nam), Loc),
1388 New_Occurrence_Of (It.Nam, Loc))));
1394 Set_Entity (Nam, It.Nam);
1395 Insert_Explicit_Dereference (Nam);
1396 Set_Etype (Nam, Nam_Ent);
1400 Set_Etype (Nam, It.Typ);
1403 elsif Nkind (Name (N)) in N_Function_Call | N_Selected_Component
1408 Get_Next_Interp (X, It);
1411 -- If the name is the result of a function call, it can only be a
1412 -- call to a function returning an access to subprogram. Insert
1413 -- explicit dereference.
1415 if Nkind (Nam) = N_Function_Call then
1416 Insert_Explicit_Dereference (Nam);
1419 if Etype (N) = Any_Type then
1421 -- None of the interpretations is compatible with the actuals
1423 Diagnose_Call (N, Nam);
1425 -- Special checks for uninstantiated put routines
1427 if Nkind (N) = N_Procedure_Call_Statement
1428 and then Is_Entity_Name (Nam)
1429 and then Chars (Nam) = Name_Put
1430 and then List_Length (Actuals) = 1
1433 Arg : constant Node_Id := First (Actuals);
1437 if Nkind (Arg) = N_Parameter_Association then
1438 Typ := Etype (Explicit_Actual_Parameter (Arg));
1443 if Is_Signed_Integer_Type (Typ) then
1445 ("possible missing instantiation of "
1446 & "'Text_'I'O.'Integer_'I'O!", Nam);
1448 elsif Is_Modular_Integer_Type (Typ) then
1450 ("possible missing instantiation of "
1451 & "'Text_'I'O.'Modular_'I'O!", Nam);
1453 elsif Is_Floating_Point_Type (Typ) then
1455 ("possible missing instantiation of "
1456 & "'Text_'I'O.'Float_'I'O!", Nam);
1458 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
1460 ("possible missing instantiation of "
1461 & "'Text_'I'O.'Fixed_'I'O!", Nam);
1463 elsif Is_Decimal_Fixed_Point_Type (Typ) then
1465 ("possible missing instantiation of "
1466 & "'Text_'I'O.'Decimal_'I'O!", Nam);
1468 elsif Is_Enumeration_Type (Typ) then
1470 ("possible missing instantiation of "
1471 & "'Text_'I'O.'Enumeration_'I'O!", Nam);
1476 elsif not Is_Overloaded (N)
1477 and then Is_Entity_Name (Nam)
1479 -- Resolution yields a single interpretation. Verify that the
1480 -- reference has capitalization consistent with the declaration.
1482 Set_Entity_With_Checks (Nam, Entity (Nam));
1483 Generate_Reference (Entity (Nam), Nam);
1485 Set_Etype (Nam, Etype (Entity (Nam)));
1487 Remove_Abstract_Operations (N);
1491 -- Check the accessibility level for actuals for explicitly aliased
1492 -- formals when a function call appears within a return statement.
1493 -- This is only checked if the enclosing subprogram Comes_From_Source,
1494 -- to avoid issuing errors on calls occurring in wrapper subprograms
1495 -- (for example, where the call is part of an expression of an aspect
1496 -- associated with a wrapper, such as Pre'Class).
1498 if Nkind (N) = N_Function_Call
1499 and then Comes_From_Source (N)
1500 and then Present (Nam_Ent)
1501 and then In_Return_Value (N)
1502 and then Comes_From_Source (Current_Subprogram)
1508 Act := First_Actual (N);
1509 Form := First_Formal (Nam_Ent);
1511 while Present (Form) and then Present (Act) loop
1512 -- Check whether the formal is aliased and if the accessibility
1513 -- level of the actual is deeper than the accessibility level
1514 -- of the enclosing subprogram to which the current return
1515 -- statement applies.
1517 -- Should we be checking Is_Entity_Name on Act? Won't this miss
1520 if Is_Explicitly_Aliased (Form)
1521 and then Is_Entity_Name (Act)
1522 and then Static_Accessibility_Level
1523 (Act, Zero_On_Dynamic_Level)
1524 > Subprogram_Access_Level (Current_Subprogram)
1526 Error_Msg_N ("actual for explicitly aliased formal is too"
1527 & " short lived", Act);
1536 if Ada_Version >= Ada_2012 then
1538 -- Check if the call contains a function with writable actuals
1540 Check_Writable_Actuals (N);
1542 -- If found and the outermost construct that can be evaluated in
1543 -- an arbitrary order is precisely this call, then check all its
1546 Check_Function_Writable_Actuals (N);
1548 -- The return type of the function may be incomplete. This can be
1549 -- the case if the type is a generic formal, or a limited view. It
1550 -- can also happen when the function declaration appears before the
1551 -- full view of the type (which is legal in Ada 2012) and the call
1552 -- appears in a different unit, in which case the incomplete view
1553 -- must be replaced with the full view (or the nonlimited view)
1554 -- to prevent subsequent type errors. Note that the usual install/
1555 -- removal of limited_with clauses is not sufficient to handle this
1556 -- case, because the limited view may have been captured in another
1557 -- compilation unit that defines the current function.
1559 if Is_Incomplete_Type (Etype (N)) then
1560 if Present (Full_View (Etype (N))) then
1561 if Is_Entity_Name (Nam) then
1562 Set_Etype (Nam, Full_View (Etype (N)));
1563 Set_Etype (Entity (Nam), Full_View (Etype (N)));
1566 Set_Etype (N, Full_View (Etype (N)));
1568 -- If the call is within a thunk, the nonlimited view should be
1569 -- analyzed eventually (see also Analyze_Return_Type).
1571 elsif From_Limited_With (Etype (N))
1572 and then Present (Non_Limited_View (Etype (N)))
1574 (Ekind (Non_Limited_View (Etype (N))) /= E_Incomplete_Type
1575 or else Is_Thunk (Current_Scope))
1577 Set_Etype (N, Non_Limited_View (Etype (N)));
1579 -- If there is no completion for the type, this may be because
1580 -- there is only a limited view of it and there is nothing in
1581 -- the context of the current unit that has required a regular
1582 -- compilation of the unit containing the type. We recognize
1583 -- this unusual case by the fact that unit is not analyzed.
1584 -- Note that the call being analyzed is in a different unit from
1585 -- the function declaration, and nothing indicates that the type
1586 -- is a limited view.
1588 elsif Ekind (Scope (Etype (N))) = E_Package
1589 and then Present (Limited_View (Scope (Etype (N))))
1590 and then not Analyzed (Unit_Declaration_Node (Scope (Etype (N))))
1593 ("cannot call function that returns limited view of}",
1597 ("\there must be a regular with_clause for package & in the "
1598 & "current unit, or in some unit in its context",
1599 N, Scope (Etype (N)));
1601 Set_Etype (N, Any_Type);
1607 -----------------------------
1608 -- Analyze_Case_Expression --
1609 -----------------------------
1611 procedure Analyze_Case_Expression (N : Node_Id) is
1612 Expr : constant Node_Id := Expression (N);
1613 First_Alt : constant Node_Id := First (Alternatives (N));
1615 First_Expr : Node_Id := Empty;
1616 -- First expression in the case where there is some type information
1617 -- available, i.e. there is not Any_Type everywhere, which can happen
1618 -- because of some error.
1620 Second_Expr : Node_Id := Empty;
1621 -- Second expression as above
1623 Wrong_Alt : Node_Id := Empty;
1624 -- For error reporting
1626 procedure Non_Static_Choice_Error (Choice : Node_Id);
1627 -- Error routine invoked by the generic instantiation below when
1628 -- the case expression has a non static choice.
1630 procedure Check_Next_Expression (T : Entity_Id; Alt : Node_Id);
1631 -- Check one interpretation of the next expression with type T
1633 procedure Check_Expression_Pair (T1, T2 : Entity_Id; Alt : Node_Id);
1634 -- Check first expression with type T1 and next expression with type T2
1636 package Case_Choices_Analysis is new
1637 Generic_Analyze_Choices
1638 (Process_Associated_Node => No_OP);
1639 use Case_Choices_Analysis;
1641 package Case_Choices_Checking is new
1642 Generic_Check_Choices
1643 (Process_Empty_Choice => No_OP,
1644 Process_Non_Static_Choice => Non_Static_Choice_Error,
1645 Process_Associated_Node => No_OP);
1646 use Case_Choices_Checking;
1648 -----------------------------
1649 -- Non_Static_Choice_Error --
1650 -----------------------------
1652 procedure Non_Static_Choice_Error (Choice : Node_Id) is
1654 Flag_Non_Static_Expr
1655 ("choice given in case expression is not static!", Choice);
1656 end Non_Static_Choice_Error;
1658 ---------------------------
1659 -- Check_Next_Expression --
1660 ---------------------------
1662 procedure Check_Next_Expression (T : Entity_Id; Alt : Node_Id) is
1663 Next_Expr : constant Node_Id := Expression (Alt);
1669 if Next_Expr = First_Expr then
1670 Check_Next_Expression (T, Next (Alt));
1674 -- Loop through the interpretations of the next expression
1676 if not Is_Overloaded (Next_Expr) then
1677 Check_Expression_Pair (T, Etype (Next_Expr), Alt);
1680 Get_First_Interp (Next_Expr, I, It);
1681 while Present (It.Typ) loop
1682 Check_Expression_Pair (T, It.Typ, Alt);
1683 Get_Next_Interp (I, It);
1686 end Check_Next_Expression;
1688 ---------------------------
1689 -- Check_Expression_Pair --
1690 ---------------------------
1692 procedure Check_Expression_Pair (T1, T2 : Entity_Id; Alt : Node_Id) is
1693 Next_Expr : constant Node_Id := Expression (Alt);
1698 if Covers (T1 => T1, T2 => T2)
1699 or else Covers (T1 => T2, T2 => T1)
1701 T := Specific_Type (T1, T2);
1703 elsif Is_User_Defined_Literal (First_Expr, T2) then
1706 elsif Is_User_Defined_Literal (Next_Expr, T1) then
1710 T := Possible_Type_For_Conditional_Expression (T1, T2);
1718 if Present (Next (Alt)) then
1719 Check_Next_Expression (T, Next (Alt));
1721 Add_One_Interp (N, T, T);
1723 end Check_Expression_Pair;
1728 Exp_Type : Entity_Id;
1729 Exp_Btype : Entity_Id;
1732 Others_Present : Boolean;
1734 -- Start of processing for Analyze_Case_Expression
1737 Analyze_And_Resolve (Expr, Any_Discrete);
1738 Check_Unset_Reference (Expr);
1739 Exp_Type := Etype (Expr);
1740 Exp_Btype := Base_Type (Exp_Type);
1742 Set_Etype (N, Any_Type);
1745 while Present (Alt) loop
1746 if Error_Posted (Expression (Alt)) then
1750 Analyze_Expression (Expression (Alt));
1752 if Etype (Expression (Alt)) /= Any_Type then
1753 if No (First_Expr) then
1754 First_Expr := Expression (Alt);
1756 elsif No (Second_Expr) then
1757 Second_Expr := Expression (Alt);
1764 -- Get our initial type from the first expression for which we got some
1765 -- useful type information from the expression.
1767 if No (First_Expr) then
1771 -- The expression must be of a discrete type which must be determinable
1772 -- independently of the context in which the expression occurs, but
1773 -- using the fact that the expression must be of a discrete type.
1774 -- Moreover, the type this expression must not be a character literal
1775 -- (which is always ambiguous).
1777 -- If error already reported by Resolve, nothing more to do
1779 if Exp_Btype = Any_Discrete or else Exp_Btype = Any_Type then
1782 -- Special case message for character literal
1784 elsif Exp_Btype = Any_Character then
1786 ("character literal as case expression is ambiguous", Expr);
1790 -- If the case expression is a formal object of mode in out, then
1791 -- treat it as having a nonstatic subtype by forcing use of the base
1792 -- type (which has to get passed to Check_Case_Choices below). Also
1793 -- use base type when the case expression is parenthesized.
1795 if Paren_Count (Expr) > 0
1796 or else (Is_Entity_Name (Expr)
1797 and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter)
1799 Exp_Type := Exp_Btype;
1802 -- The case expression alternatives cover the range of a static subtype
1803 -- subject to aspect Static_Predicate. Do not check the choices when the
1804 -- case expression has not been fully analyzed yet because this may lead
1807 if Is_OK_Static_Subtype (Exp_Type)
1808 and then Has_Static_Predicate_Aspect (Exp_Type)
1809 and then Preanalysis_Active
1813 -- Call Analyze_Choices and Check_Choices to do the rest of the work
1816 Analyze_Choices (Alternatives (N), Exp_Type);
1817 Check_Choices (N, Alternatives (N), Exp_Type, Others_Present);
1819 if Exp_Type = Universal_Integer and then not Others_Present then
1821 ("case on universal integer requires OTHERS choice", Expr);
1826 -- RM 4.5.7(10/3): If the case_expression is the operand of a type
1827 -- conversion, the type of the case_expression is the target type
1828 -- of the conversion.
1830 if Nkind (Parent (N)) = N_Type_Conversion then
1831 Set_Etype (N, Etype (Parent (N)));
1835 -- Loop through the interpretations of the first expression and check
1836 -- the other expressions if present.
1838 if not Is_Overloaded (First_Expr) then
1839 if Present (Second_Expr) then
1840 Check_Next_Expression (Etype (First_Expr), First_Alt);
1842 Set_Etype (N, Etype (First_Expr));
1846 Get_First_Interp (First_Expr, I, It);
1847 while Present (It.Typ) loop
1848 if Present (Second_Expr) then
1849 Check_Next_Expression (It.Typ, First_Alt);
1851 Add_One_Interp (N, It.Typ, It.Typ);
1854 Get_Next_Interp (I, It);
1858 -- If no possible interpretation has been found, the type of the wrong
1859 -- alternative doesn't match any interpretation of the FIRST expression.
1861 if Etype (N) = Any_Type and then Present (Wrong_Alt) then
1862 Second_Expr := Expression (Wrong_Alt);
1864 if Is_Overloaded (First_Expr) then
1865 if Is_Overloaded (Second_Expr) then
1867 ("no interpretation compatible with those of previous "
1872 ("type incompatible with interpretations of previous "
1876 ("\this alternative has}!",
1878 Etype (Second_Expr));
1882 if Is_Overloaded (Second_Expr) then
1884 ("no interpretation compatible with type of previous "
1888 ("\previous alternative has}!",
1890 Etype (First_Expr));
1893 ("type incompatible with that of previous alternative",
1896 ("\previous alternative has}!",
1898 Etype (First_Expr));
1900 ("\this alternative has}!",
1902 Etype (Second_Expr));
1906 end Analyze_Case_Expression;
1908 ---------------------------
1909 -- Analyze_Concatenation --
1910 ---------------------------
1912 procedure Analyze_Concatenation (N : Node_Id) is
1914 -- We wish to avoid deep recursion, because concatenations are often
1915 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1916 -- operands nonrecursively until we find something that is not a
1917 -- concatenation (A in this case), or has already been analyzed. We
1918 -- analyze that, and then walk back up the tree following Parent
1919 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1920 -- work at each level. The Parent pointers allow us to avoid recursion,
1921 -- and thus avoid running out of memory.
1927 Candidate_Type := Empty;
1929 -- The following code is equivalent to:
1931 -- Set_Etype (N, Any_Type);
1932 -- Analyze_Expression (Left_Opnd (N));
1933 -- Analyze_Concatenation_Rest (N);
1935 -- where the Analyze_Expression call recurses back here if the left
1936 -- operand is a concatenation.
1938 -- Walk down left operands
1941 Set_Etype (NN, Any_Type);
1942 L := Left_Opnd (NN);
1943 exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
1947 -- Now (given the above example) NN is A&B and L is A
1949 -- First analyze L ...
1951 Analyze_Expression (L);
1953 -- ... then walk NN back up until we reach N (where we started), calling
1954 -- Analyze_Concatenation_Rest along the way.
1957 Analyze_Concatenation_Rest (NN);
1961 end Analyze_Concatenation;
1963 --------------------------------
1964 -- Analyze_Concatenation_Rest --
1965 --------------------------------
1967 -- If the only one-dimensional array type in scope is String,
1968 -- this is the resulting type of the operation. Otherwise there
1969 -- will be a concatenation operation defined for each user-defined
1970 -- one-dimensional array.
1972 procedure Analyze_Concatenation_Rest (N : Node_Id) is
1973 L : constant Node_Id := Left_Opnd (N);
1974 R : constant Node_Id := Right_Opnd (N);
1975 Op_Id : Entity_Id := Entity (N);
1980 Analyze_Expression (R);
1982 -- If the entity is present, the node appears in an instance, and
1983 -- denotes a predefined concatenation operation. The resulting type is
1984 -- obtained from the arguments when possible. If the arguments are
1985 -- aggregates, the array type and the concatenation type must be
1988 if Present (Op_Id) then
1989 if Ekind (Op_Id) = E_Operator then
1990 LT := Base_Type (Etype (L));
1991 RT := Base_Type (Etype (R));
1993 if Is_Array_Type (LT)
1994 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1996 Add_One_Interp (N, Op_Id, LT);
1998 elsif Is_Array_Type (RT)
1999 and then LT = Base_Type (Component_Type (RT))
2001 Add_One_Interp (N, Op_Id, RT);
2003 -- If one operand is a string type or a user-defined array type,
2004 -- and the other is a literal, result is of the specific type.
2007 (Root_Type (LT) = Standard_String
2008 or else Scope (LT) /= Standard_Standard)
2009 and then Etype (R) = Any_String
2010 and then not Is_Component_Left_Opnd (N)
2012 Add_One_Interp (N, Op_Id, LT);
2015 (Root_Type (RT) = Standard_String
2016 or else Scope (RT) /= Standard_Standard)
2017 and then Etype (L) = Any_String
2018 and then not Is_Component_Right_Opnd (N)
2020 Add_One_Interp (N, Op_Id, RT);
2022 elsif not Is_Generic_Type (Etype (Op_Id)) then
2023 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2026 -- Type and its operations must be visible
2028 Set_Entity (N, Empty);
2029 Analyze_Concatenation (N);
2033 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2037 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
2038 while Present (Op_Id) loop
2039 if Ekind (Op_Id) = E_Operator then
2041 -- Do not consider operators declared in dead code, they
2042 -- cannot be part of the resolution.
2044 if Is_Eliminated (Op_Id) then
2047 Find_Concatenation_Types (L, R, Op_Id, N);
2051 Analyze_User_Defined_Binary_Op (N, Op_Id);
2054 Op_Id := Homonym (Op_Id);
2059 end Analyze_Concatenation_Rest;
2061 ------------------------------------
2062 -- Analyze_Comparison_Equality_Op --
2063 ------------------------------------
2065 procedure Analyze_Comparison_Equality_Op (N : Node_Id) is
2066 Loc : constant Source_Ptr := Sloc (N);
2067 L : constant Node_Id := Left_Opnd (N);
2068 R : constant Node_Id := Right_Opnd (N);
2073 Set_Etype (N, Any_Type);
2074 Candidate_Type := Empty;
2076 Analyze_Expression (L);
2077 Analyze_Expression (R);
2079 -- If the entity is set, the node is a generic instance with a non-local
2080 -- reference to the predefined operator or to a user-defined function.
2081 -- It can also be an inequality that is expanded into the negation of a
2082 -- call to a user-defined equality operator.
2084 -- For the predefined case, the result is Boolean, regardless of the
2085 -- type of the operands. The operands may even be limited, if they are
2086 -- generic actuals. If they are overloaded, label the operands with the
2087 -- compare type if it is present, typically because it is a global type
2088 -- in a generic instance, or with the common type that must be present,
2089 -- or with the type of the formal of the user-defined function.
2091 if Present (Entity (N)) then
2092 Op_Id := Entity (N);
2094 if Ekind (Op_Id) = E_Operator then
2095 Add_One_Interp (N, Op_Id, Standard_Boolean);
2097 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2100 if Is_Overloaded (L) then
2101 if Ekind (Op_Id) = E_Operator then
2103 (if Present (Compare_Type (N))
2104 then Compare_Type (N)
2105 else Intersect_Types (L, R)));
2107 Set_Etype (L, Etype (First_Formal (Op_Id)));
2111 if Is_Overloaded (R) then
2112 if Ekind (Op_Id) = E_Operator then
2114 (if Present (Compare_Type (N))
2115 then Compare_Type (N)
2116 else Intersect_Types (L, R)));
2118 Set_Etype (R, Etype (Next_Formal (First_Formal (Op_Id))));
2123 Op_Id := Get_Name_Entity_Id (Chars (N));
2125 while Present (Op_Id) loop
2126 if Ekind (Op_Id) = E_Operator then
2127 Find_Comparison_Equality_Types (L, R, Op_Id, N);
2129 Analyze_User_Defined_Binary_Op (N, Op_Id);
2132 Op_Id := Homonym (Op_Id);
2136 -- If there was no match and the operator is inequality, this may be
2137 -- a case where inequality has not been made explicit, as for tagged
2138 -- types. Analyze the node as the negation of an equality operation.
2139 -- This cannot be done earlier because, before analysis, we cannot rule
2140 -- out the presence of an explicit inequality.
2142 if Etype (N) = Any_Type and then Nkind (N) = N_Op_Ne then
2143 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
2145 while Present (Op_Id) loop
2146 if Ekind (Op_Id) = E_Operator then
2147 Find_Comparison_Equality_Types (L, R, Op_Id, N);
2149 Analyze_User_Defined_Binary_Op (N, Op_Id);
2152 Op_Id := Homonym (Op_Id);
2155 if Etype (N) /= Any_Type then
2156 Op_Id := Entity (N);
2162 Left_Opnd => Left_Opnd (N),
2163 Right_Opnd => Right_Opnd (N))));
2165 Set_Entity (Right_Opnd (N), Op_Id);
2171 Check_Function_Writable_Actuals (N);
2172 end Analyze_Comparison_Equality_Op;
2174 ----------------------------------
2175 -- Analyze_Explicit_Dereference --
2176 ----------------------------------
2178 procedure Analyze_Explicit_Dereference (N : Node_Id) is
2179 Loc : constant Source_Ptr := Sloc (N);
2180 P : constant Node_Id := Prefix (N);
2186 function Is_Function_Type return Boolean;
2187 -- Check whether node may be interpreted as an implicit function call
2189 ----------------------
2190 -- Is_Function_Type --
2191 ----------------------
2193 function Is_Function_Type return Boolean is
2198 if not Is_Overloaded (N) then
2199 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
2200 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
2203 Get_First_Interp (N, I, It);
2204 while Present (It.Nam) loop
2205 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
2206 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
2211 Get_Next_Interp (I, It);
2216 end Is_Function_Type;
2218 -- Start of processing for Analyze_Explicit_Dereference
2221 -- In formal verification mode, keep track of all reads and writes
2222 -- through explicit dereferences.
2224 if GNATprove_Mode then
2225 SPARK_Specific.Generate_Dereference (N);
2229 Set_Etype (N, Any_Type);
2231 -- Test for remote access to subprogram type, and if so return
2232 -- after rewriting the original tree.
2234 if Remote_AST_E_Dereference (P) then
2238 -- Normal processing for other than remote access to subprogram type
2240 if not Is_Overloaded (P) then
2241 if Is_Access_Type (Etype (P)) then
2246 DT : constant Entity_Id := Designated_Type (Etype (P));
2249 -- An explicit dereference is a legal occurrence of an
2250 -- incomplete type imported through a limited_with clause, if
2251 -- the full view is visible, or if we are within an instance
2252 -- body, where the enclosing body has a regular with_clause
2255 if From_Limited_With (DT)
2256 and then not From_Limited_With (Scope (DT))
2258 (Is_Immediately_Visible (Scope (DT))
2260 (Is_Child_Unit (Scope (DT))
2261 and then Is_Visible_Lib_Unit (Scope (DT)))
2262 or else In_Instance_Body)
2264 Set_Etype (N, Available_View (DT));
2271 elsif Etype (P) /= Any_Type then
2272 Error_Msg_N ("prefix of dereference must be an access type", N);
2277 Get_First_Interp (P, I, It);
2278 while Present (It.Nam) loop
2281 if Is_Access_Type (T) then
2282 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
2285 Get_Next_Interp (I, It);
2288 -- Error if no interpretation of the prefix has an access type
2290 if Etype (N) = Any_Type then
2292 ("access type required in prefix of explicit dereference", P);
2293 Set_Etype (N, Any_Type);
2299 and then Nkind (Parent (N)) /= N_Indexed_Component
2301 and then (Nkind (Parent (N)) /= N_Function_Call
2302 or else N /= Name (Parent (N)))
2304 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
2305 or else N /= Name (Parent (N)))
2307 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
2308 and then (Nkind (Parent (N)) /= N_Attribute_Reference
2310 (Attribute_Name (Parent (N)) /= Name_Address
2312 Attribute_Name (Parent (N)) /= Name_Access))
2314 -- Name is a function call with no actuals, in a context that
2315 -- requires deproceduring (including as an actual in an enclosing
2316 -- function or procedure call). There are some pathological cases
2317 -- where the prefix might include functions that return access to
2318 -- subprograms and others that return a regular type. Disambiguation
2319 -- of those has to take place in Resolve.
2322 Make_Function_Call (Loc,
2323 Name => Make_Explicit_Dereference (Loc, P),
2324 Parameter_Associations => New_List);
2326 -- If the prefix is overloaded, remove operations that have formals,
2327 -- we know that this is a parameterless call.
2329 if Is_Overloaded (P) then
2330 Get_First_Interp (P, I, It);
2331 while Present (It.Nam) loop
2334 if Is_Access_Type (T)
2335 and then No (First_Formal (Base_Type (Designated_Type (T))))
2342 Get_Next_Interp (I, It);
2349 elsif not Is_Function_Type
2350 and then Is_Overloaded (N)
2352 -- The prefix may include access to subprograms and other access
2353 -- types. If the context selects the interpretation that is a
2354 -- function call (not a procedure call) we cannot rewrite the node
2355 -- yet, but we include the result of the call interpretation.
2357 Get_First_Interp (N, I, It);
2358 while Present (It.Nam) loop
2359 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
2360 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
2361 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
2363 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
2366 Get_Next_Interp (I, It);
2370 -- A value of remote access-to-class-wide must not be dereferenced
2373 Validate_Remote_Access_To_Class_Wide_Type (N);
2374 end Analyze_Explicit_Dereference;
2376 ------------------------
2377 -- Analyze_Expression --
2378 ------------------------
2380 procedure Analyze_Expression (N : Node_Id) is
2382 -- If the expression is an indexed component that will be rewritten
2383 -- as a container indexing, it has already been analyzed.
2385 if Nkind (N) = N_Indexed_Component
2386 and then Present (Generalized_Indexing (N))
2392 Check_Parameterless_Call (N);
2394 end Analyze_Expression;
2396 -------------------------------------
2397 -- Analyze_Expression_With_Actions --
2398 -------------------------------------
2400 procedure Analyze_Expression_With_Actions (N : Node_Id) is
2402 procedure Check_Action_OK (A : Node_Id);
2403 -- Check that the action A is allowed as a declare_item of a declare
2404 -- expression if N and A come from source.
2406 ---------------------
2407 -- Check_Action_OK --
2408 ---------------------
2410 procedure Check_Action_OK (A : Node_Id) is
2412 if not Comes_From_Source (N) or else not Comes_From_Source (A) then
2414 -- If, for example, an (illegal) expression function is
2415 -- transformed into a "vanilla" function then we don't want to
2416 -- allow it just because Comes_From_Source is now False. So look
2417 -- at the Original_Node.
2419 if Is_Rewrite_Substitution (A) then
2420 Check_Action_OK (Original_Node (A));
2423 return; -- Allow anything in generated code
2427 when N_Object_Declaration =>
2428 Inspect_Deferred_Constant_Completion (A);
2430 if Nkind (Object_Definition (A)) = N_Access_Definition then
2432 ("anonymous access type not allowed in declare_expression",
2433 Object_Definition (A));
2436 if Aliased_Present (A) then
2437 Error_Msg_N ("ALIASED not allowed in declare_expression", A);
2440 if Constant_Present (A)
2441 and then not Is_Limited_Type (Etype (Defining_Identifier (A)))
2443 return; -- nonlimited constants are OK
2446 when N_Object_Renaming_Declaration =>
2447 if Present (Access_Definition (A)) then
2449 ("anonymous access type not allowed in declare_expression",
2450 Access_Definition (A));
2453 if not Is_Limited_Type (Etype (Defining_Identifier (A))) then
2454 return; -- ???For now; the RM rule is a bit more complicated
2459 -- See AI22-0045 pragma categorization.
2460 subtype Executable_Pragma_Id is Pragma_Id
2461 with Predicate => Executable_Pragma_Id in
2462 -- language-defined executable pragmas
2463 Pragma_Assert | Pragma_Inspection_Point
2465 -- GNAT-defined executable pragmas
2466 | Pragma_Assume | Pragma_Debug;
2468 if Get_Pragma_Id (A) in Executable_Pragma_Id then
2474 null; -- Nothing else allowed
2477 -- We could mention pragmas in the message text; let's not.
2478 Error_Msg_N ("object renaming or constant declaration expected", A);
2479 end Check_Action_OK;
2482 EWA_Scop : Entity_Id;
2484 -- Start of processing for Analyze_Expression_With_Actions
2487 -- Create a scope, which is needed to provide proper visibility of the
2490 EWA_Scop := New_Internal_Entity (E_Block, Current_Scope, Sloc (N), 'B');
2491 Set_Etype (EWA_Scop, Standard_Void_Type);
2492 Set_Scope (EWA_Scop, Current_Scope);
2493 Set_Parent (EWA_Scop, N);
2494 Push_Scope (EWA_Scop);
2496 -- If this Expression_With_Actions node comes from source, then it
2497 -- represents a declare_expression; increment the counter to take note
2500 if Comes_From_Source (N) then
2501 In_Declare_Expr := In_Declare_Expr + 1;
2504 A := First (Actions (N));
2505 while Present (A) loop
2507 Check_Action_OK (A);
2511 Analyze_Expression (Expression (N));
2512 Set_Etype (N, Etype (Expression (N)));
2515 if Comes_From_Source (N) then
2516 In_Declare_Expr := In_Declare_Expr - 1;
2518 end Analyze_Expression_With_Actions;
2520 ---------------------------
2521 -- Analyze_If_Expression --
2522 ---------------------------
2524 procedure Analyze_If_Expression (N : Node_Id) is
2525 Condition : constant Node_Id := First (Expressions (N));
2527 Then_Expr : Node_Id;
2528 Else_Expr : Node_Id;
2530 procedure Check_Else_Expression (T : Entity_Id);
2531 -- Check one interpretation of the THEN expression with type T
2533 procedure Check_Expression_Pair (T1, T2 : Entity_Id);
2534 -- Check THEN expression with type T1 and ELSE expression with type T2
2536 ---------------------------
2537 -- Check_Else_Expression --
2538 ---------------------------
2540 procedure Check_Else_Expression (T : Entity_Id) is
2545 -- Loop through the interpretations of the ELSE expression
2547 if not Is_Overloaded (Else_Expr) then
2548 Check_Expression_Pair (T, Etype (Else_Expr));
2551 Get_First_Interp (Else_Expr, I, It);
2552 while Present (It.Typ) loop
2553 Check_Expression_Pair (T, It.Typ);
2554 Get_Next_Interp (I, It);
2557 end Check_Else_Expression;
2559 ---------------------------
2560 -- Check_Expression_Pair --
2561 ---------------------------
2563 procedure Check_Expression_Pair (T1, T2 : Entity_Id) is
2567 if Covers (T1 => T1, T2 => T2)
2568 or else Covers (T1 => T2, T2 => T1)
2570 T := Specific_Type (T1, T2);
2572 elsif Is_User_Defined_Literal (Then_Expr, T2) then
2575 elsif Is_User_Defined_Literal (Else_Expr, T1) then
2579 T := Possible_Type_For_Conditional_Expression (T1, T2);
2586 Add_One_Interp (N, T, T);
2587 end Check_Expression_Pair;
2594 -- Start of processing for Analyze_If_Expression
2597 -- Defend against error of missing expressions from previous error
2599 if No (Condition) then
2600 Check_Error_Detected;
2604 Set_Etype (N, Any_Type);
2606 Then_Expr := Next (Condition);
2608 if No (Then_Expr) then
2609 Check_Error_Detected;
2613 Else_Expr := Next (Then_Expr);
2615 -- Analyze and resolve the condition. We need to resolve this now so
2616 -- that it gets folded to True/False if possible, before we analyze
2617 -- the THEN/ELSE branches, because when analyzing these branches, we
2618 -- may call Is_Statically_Unevaluated, which expects the condition of
2619 -- an enclosing IF to have been analyze/resolved/evaluated.
2621 Analyze_Expression (Condition);
2622 Resolve (Condition, Any_Boolean);
2624 -- Analyze the THEN expression and (if present) the ELSE expression. For
2625 -- them we delay resolution in the normal manner because of overloading.
2627 Analyze_Expression (Then_Expr);
2629 if Present (Else_Expr) then
2630 Analyze_Expression (Else_Expr);
2633 -- RM 4.5.7(10/3): If the if_expression is the operand of a type
2634 -- conversion, the type of the if_expression is the target type
2635 -- of the conversion.
2637 if Nkind (Parent (N)) = N_Type_Conversion then
2638 Set_Etype (N, Etype (Parent (N)));
2642 -- Loop through the interpretations of the THEN expression and check the
2643 -- ELSE expression if present.
2645 if not Is_Overloaded (Then_Expr) then
2646 if Present (Else_Expr) then
2647 Check_Else_Expression (Etype (Then_Expr));
2649 Set_Etype (N, Etype (Then_Expr));
2653 Get_First_Interp (Then_Expr, I, It);
2654 while Present (It.Typ) loop
2655 if Present (Else_Expr) then
2656 Check_Else_Expression (It.Typ);
2658 Add_One_Interp (N, It.Typ, It.Typ);
2661 Get_Next_Interp (I, It);
2665 -- If no possible interpretation has been found, the type of the
2666 -- ELSE expression does not match any interpretation of the THEN
2669 if Etype (N) = Any_Type then
2670 if Is_Overloaded (Then_Expr) then
2671 if Is_Overloaded (Else_Expr) then
2673 ("no interpretation compatible with those of THEN expression",
2677 ("type of ELSE incompatible with interpretations of THEN "
2681 ("\ELSE expression has}!", Else_Expr, Etype (Else_Expr));
2684 elsif Present (Else_Expr) then
2685 if Is_Overloaded (Else_Expr) then
2687 ("no interpretation compatible with type of THEN expression",
2690 ("\THEN expression has}!", Else_Expr, Etype (Then_Expr));
2693 ("type of ELSE incompatible with that of THEN expression",
2696 ("\THEN expression has}!", Else_Expr, Etype (Then_Expr));
2698 ("\ELSE expression has}!", Else_Expr, Etype (Else_Expr));
2702 end Analyze_If_Expression;
2704 ------------------------------------
2705 -- Analyze_Indexed_Component_Form --
2706 ------------------------------------
2708 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
2709 P : constant Node_Id := Prefix (N);
2710 Exprs : constant List_Id := Expressions (N);
2716 procedure Process_Function_Call;
2717 -- Prefix in indexed component form is an overloadable entity, so the
2718 -- node is very likely a function call; reformat it as such. The only
2719 -- exception is a call to a parameterless function that returns an
2720 -- array type, or an access type thereof, in which case this will be
2721 -- undone later by Resolve_Call or Resolve_Entry_Call.
2723 procedure Process_Indexed_Component;
2724 -- Prefix in indexed component form is actually an indexed component.
2725 -- This routine processes it, knowing that the prefix is already
2728 procedure Process_Indexed_Component_Or_Slice;
2729 -- An indexed component with a single index may designate a slice if
2730 -- the index is a subtype mark. This routine disambiguates these two
2731 -- cases by resolving the prefix to see if it is a subtype mark.
2733 procedure Process_Overloaded_Indexed_Component;
2734 -- If the prefix of an indexed component is overloaded, the proper
2735 -- interpretation is selected by the index types and the context.
2737 ---------------------------
2738 -- Process_Function_Call --
2739 ---------------------------
2741 procedure Process_Function_Call is
2742 Loc : constant Source_Ptr := Sloc (N);
2746 Change_Node (N, N_Function_Call);
2748 Set_Parameter_Associations (N, Exprs);
2750 -- Analyze actuals prior to analyzing the call itself
2752 Actual := First (Parameter_Associations (N));
2753 while Present (Actual) loop
2755 Check_Parameterless_Call (Actual);
2757 -- Move to next actual. Note that we use Next, not Next_Actual
2758 -- here. The reason for this is a bit subtle. If a function call
2759 -- includes named associations, the parser recognizes the node
2760 -- as a call, and it is analyzed as such. If all associations are
2761 -- positional, the parser builds an indexed_component node, and
2762 -- it is only after analysis of the prefix that the construct
2763 -- is recognized as a call, in which case Process_Function_Call
2764 -- rewrites the node and analyzes the actuals. If the list of
2765 -- actuals is malformed, the parser may leave the node as an
2766 -- indexed component (despite the presence of named associations).
2767 -- The iterator Next_Actual is equivalent to Next if the list is
2768 -- positional, but follows the normalized chain of actuals when
2769 -- named associations are present. In this case normalization has
2770 -- not taken place, and actuals remain unanalyzed, which leads to
2771 -- subsequent crashes or loops if there is an attempt to continue
2772 -- analysis of the program.
2774 -- IF there is a single actual and it is a type name, the node
2775 -- can only be interpreted as a slice of a parameterless call.
2776 -- Rebuild the node as such and analyze.
2778 if No (Next (Actual))
2779 and then Is_Entity_Name (Actual)
2780 and then Is_Type (Entity (Actual))
2781 and then Is_Discrete_Type (Entity (Actual))
2782 and then not Is_Current_Instance (Actual)
2788 New_Occurrence_Of (Entity (Actual), Loc)));
2798 end Process_Function_Call;
2800 -------------------------------
2801 -- Process_Indexed_Component --
2802 -------------------------------
2804 procedure Process_Indexed_Component is
2806 Array_Type : Entity_Id;
2808 Pent : Entity_Id := Empty;
2811 Exp := First (Exprs);
2813 if Is_Overloaded (P) then
2814 Process_Overloaded_Indexed_Component;
2817 Array_Type := Etype (P);
2819 if Is_Entity_Name (P) then
2821 elsif Nkind (P) = N_Selected_Component
2822 and then Is_Entity_Name (Selector_Name (P))
2824 Pent := Entity (Selector_Name (P));
2827 -- Prefix must be appropriate for an array type, taking into
2828 -- account a possible implicit dereference.
2830 if Is_Access_Type (Array_Type) then
2832 (Warn_On_Dereference, "?d?implicit dereference", N);
2833 Array_Type := Implicitly_Designated_Type (Array_Type);
2836 if Is_Array_Type (Array_Type) then
2838 -- In order to correctly access First_Index component later,
2839 -- replace string literal subtype by its parent type.
2841 if Ekind (Array_Type) = E_String_Literal_Subtype then
2842 Array_Type := Etype (Array_Type);
2845 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
2847 Set_Etype (N, Any_Type);
2849 if not Has_Compatible_Type (Exp, Entry_Index_Type (Pent)) then
2850 Error_Msg_N ("invalid index type in entry name", N);
2852 elsif Present (Next (Exp)) then
2853 Error_Msg_N ("too many subscripts in entry reference", N);
2856 Set_Etype (N, Etype (P));
2861 elsif Is_Record_Type (Array_Type)
2862 and then Remote_AST_I_Dereference (P)
2866 elsif Try_Container_Indexing (N, P, Exprs) then
2869 elsif Array_Type = Any_Type then
2870 Set_Etype (N, Any_Type);
2872 -- In most cases the analysis of the prefix will have emitted
2873 -- an error already, but if the prefix may be interpreted as a
2874 -- call in prefixed notation, the report is left to the caller.
2875 -- To prevent cascaded errors, report only if no previous ones.
2877 if Serious_Errors_Detected = 0 then
2878 Error_Msg_N ("invalid prefix in indexed component", P);
2880 if Nkind (P) = N_Expanded_Name then
2881 Error_Msg_NE ("\& is not visible", P, Selector_Name (P));
2887 -- Here we definitely have a bad indexing
2890 if Nkind (Parent (N)) = N_Requeue_Statement
2891 and then Present (Pent) and then Ekind (Pent) = E_Entry
2894 ("REQUEUE does not permit parameters", First (Exprs));
2896 elsif Is_Entity_Name (P)
2897 and then Etype (P) = Standard_Void_Type
2899 Error_Msg_NE ("incorrect use of &", P, Entity (P));
2902 Error_Msg_N ("array type required in indexed component", P);
2905 Set_Etype (N, Any_Type);
2909 Index := First_Index (Array_Type);
2910 while Present (Index) and then Present (Exp) loop
2911 if not Has_Compatible_Type (Exp, Etype (Index)) then
2912 Wrong_Type (Exp, Etype (Index));
2913 Set_Etype (N, Any_Type);
2921 Set_Etype (N, Component_Type (Array_Type));
2922 Check_Implicit_Dereference (N, Etype (N));
2924 -- Generate conversion to class-wide type
2926 if Is_Mutably_Tagged_CW_Equivalent_Type (Etype (N)) then
2927 Make_Mutably_Tagged_Conversion (N);
2930 if Present (Index) then
2932 ("too few subscripts in array reference", First (Exprs));
2934 elsif Present (Exp) then
2935 Error_Msg_N ("too many subscripts in array reference", Exp);
2938 end Process_Indexed_Component;
2940 ----------------------------------------
2941 -- Process_Indexed_Component_Or_Slice --
2942 ----------------------------------------
2944 procedure Process_Indexed_Component_Or_Slice is
2946 Exp := First (Exprs);
2947 while Present (Exp) loop
2948 Analyze_Expression (Exp);
2952 Exp := First (Exprs);
2954 -- If one index is present, and it is a subtype name, then the node
2955 -- denotes a slice (note that the case of an explicit range for a
2956 -- slice was already built as an N_Slice node in the first place,
2957 -- so that case is not handled here).
2959 -- We use a replace rather than a rewrite here because this is one
2960 -- of the cases in which the tree built by the parser is plain wrong.
2963 and then Is_Entity_Name (Exp)
2964 and then Is_Type (Entity (Exp))
2967 Make_Slice (Sloc (N),
2969 Discrete_Range => New_Copy (Exp)));
2972 -- Otherwise (more than one index present, or single index is not
2973 -- a subtype name), then we have the indexed component case.
2976 Process_Indexed_Component;
2978 end Process_Indexed_Component_Or_Slice;
2980 ------------------------------------------
2981 -- Process_Overloaded_Indexed_Component --
2982 ------------------------------------------
2984 procedure Process_Overloaded_Indexed_Component is
2993 Set_Etype (N, Any_Type);
2995 Get_First_Interp (P, I, It);
2996 while Present (It.Nam) loop
2999 if Is_Access_Type (Typ) then
3000 Typ := Designated_Type (Typ);
3002 (Warn_On_Dereference, "?d?implicit dereference", N);
3005 if Is_Array_Type (Typ) then
3007 -- Got a candidate: verify that index types are compatible
3009 Index := First_Index (Typ);
3011 Exp := First (Exprs);
3012 while Present (Index) and then Present (Exp) loop
3013 if Has_Compatible_Type (Exp, Etype (Index)) then
3025 if Found and then No (Index) and then No (Exp) then
3027 CT : constant Entity_Id :=
3028 Base_Type (Component_Type (Typ));
3030 Add_One_Interp (N, CT, CT);
3031 Check_Implicit_Dereference (N, CT);
3035 elsif Try_Container_Indexing (N, P, Exprs) then
3040 Get_Next_Interp (I, It);
3043 if Etype (N) = Any_Type then
3044 Error_Msg_N ("no legal interpretation for indexed component", N);
3045 Set_Is_Overloaded (N, False);
3047 end Process_Overloaded_Indexed_Component;
3049 -- Start of processing for Analyze_Indexed_Component_Form
3052 -- Get name of array, function or type
3056 -- If P is an explicit dereference whose prefix is of a remote access-
3057 -- to-subprogram type, then N has already been rewritten as a subprogram
3058 -- call and analyzed.
3060 if Nkind (N) in N_Subprogram_Call then
3063 -- When the prefix is attribute 'Loop_Entry and the sole expression of
3064 -- the indexed component denotes a loop name, the indexed form is turned
3065 -- into an attribute reference.
3067 elsif Is_Attribute_Loop_Entry (N) then
3071 pragma Assert (Nkind (N) = N_Indexed_Component);
3073 P_T := Base_Type (Etype (P));
3075 if Is_Entity_Name (P) and then Present (Entity (P)) then
3078 -- If the prefix is a type name, then reformat the node as a type
3079 -- conversion, but not if it is the current instance of type name,
3080 -- e.g. the expression of a type aspect, when it is analyzed within
3084 and then not (Inside_A_Generic and then Is_Current_Instance (P))
3086 E := Remove_Head (Exprs);
3088 if Present (First (Exprs)) then
3090 ("argument of type conversion must be single expression", N);
3093 Change_Node (N, N_Type_Conversion);
3094 Set_Subtype_Mark (N, P);
3096 Set_Expression (N, E);
3098 -- After changing the node, call for the specific Analysis
3099 -- routine directly, to avoid a double call to the expander.
3101 Analyze_Type_Conversion (N);
3105 if Is_Overloadable (U_N) then
3106 Process_Function_Call;
3108 elsif Ekind (Etype (P)) = E_Subprogram_Type
3109 or else (Is_Access_Type (Etype (P))
3111 Ekind (Designated_Type (Etype (P))) =
3114 -- Call to access_to-subprogram with possible implicit dereference
3116 Process_Function_Call;
3118 elsif Is_Generic_Subprogram (U_N) then
3120 -- A common beginner's (or C++ templates fan) error
3122 Error_Msg_N ("generic subprogram cannot be called", N);
3123 Set_Etype (N, Any_Type);
3127 Process_Indexed_Component_Or_Slice;
3130 -- If not an entity name, prefix is an expression that may denote
3131 -- an array or an access-to-subprogram.
3134 if Ekind (P_T) = E_Subprogram_Type
3135 or else (Is_Access_Type (P_T)
3137 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
3139 Process_Function_Call;
3141 elsif Nkind (P) = N_Selected_Component
3142 and then Present (Entity (Selector_Name (P)))
3143 and then Is_Overloadable (Entity (Selector_Name (P)))
3145 Process_Function_Call;
3147 -- Indexed component, slice, or a call to a member of a family
3148 -- entry, which will be converted to an entry call later.
3150 Process_Indexed_Component_Or_Slice;
3154 Analyze_Dimension (N);
3155 end Analyze_Indexed_Component_Form;
3157 ------------------------
3158 -- Analyze_Logical_Op --
3159 ------------------------
3161 procedure Analyze_Logical_Op (N : Node_Id) is
3162 L : constant Node_Id := Left_Opnd (N);
3163 R : constant Node_Id := Right_Opnd (N);
3168 Set_Etype (N, Any_Type);
3169 Candidate_Type := Empty;
3171 Analyze_Expression (L);
3172 Analyze_Expression (R);
3174 -- If the entity is already set, the node is the instantiation of a
3175 -- generic node with a non-local reference, or was manufactured by a
3176 -- call to Make_Op_xxx. In either case the entity is known to be valid,
3177 -- and we do not need to collect interpretations, instead we just get
3178 -- the single possible interpretation.
3180 if Present (Entity (N)) then
3181 Op_Id := Entity (N);
3183 if Ekind (Op_Id) = E_Operator then
3184 Find_Boolean_Types (L, R, Op_Id, N);
3186 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3189 -- Entity is not already set, so we do need to collect interpretations
3192 Op_Id := Get_Name_Entity_Id (Chars (N));
3193 while Present (Op_Id) loop
3194 if Ekind (Op_Id) = E_Operator then
3195 Find_Boolean_Types (L, R, Op_Id, N);
3197 Analyze_User_Defined_Binary_Op (N, Op_Id);
3200 Op_Id := Homonym (Op_Id);
3205 Check_Function_Writable_Actuals (N);
3208 if Nkind (L) not in N_Short_Circuit | N_Op_And | N_Op_Or | N_Op_Xor
3209 and then Is_Boolean_Type (Etype (L))
3211 Check_Xtra_Parens_Precedence (L);
3214 if Nkind (R) not in N_Short_Circuit | N_Op_And | N_Op_Or | N_Op_Xor
3215 and then Is_Boolean_Type (Etype (R))
3217 Check_Xtra_Parens_Precedence (R);
3220 end Analyze_Logical_Op;
3222 ---------------------------
3223 -- Analyze_Membership_Op --
3224 ---------------------------
3226 procedure Analyze_Membership_Op (N : Node_Id) is
3227 Loc : constant Source_Ptr := Sloc (N);
3228 L : constant Node_Id := Left_Opnd (N);
3229 R : constant Node_Id := Right_Opnd (N);
3231 procedure Analyze_Set_Membership;
3232 -- If a set of alternatives is present, analyze each and find the
3233 -- common type to which they must all resolve.
3235 function Find_Interp return Boolean;
3236 -- Find a valid interpretation of the test. Note that the context of the
3237 -- operation plays no role in resolving the operands, so that if there
3238 -- is more than one interpretation of the operands that is compatible
3239 -- with the test, the operation is ambiguous.
3241 function Try_Left_Interp (T : Entity_Id) return Boolean;
3242 -- Try an interpretation of the left operand with type T. Return true if
3243 -- one interpretation (at least) of the right operand making up a valid
3244 -- operand pair exists, otherwise false if no such pair exists.
3246 function Is_Valid_Pair (T1, T2 : Entity_Id) return Boolean;
3247 -- Return true if T1 and T2 constitute a valid pair of operand types for
3248 -- L and R respectively.
3250 ----------------------------
3251 -- Analyze_Set_Membership --
3252 ----------------------------
3254 procedure Analyze_Set_Membership is
3256 Index : Interp_Index;
3258 Candidate_Interps : Node_Id;
3259 Common_Type : Entity_Id := Empty;
3263 Candidate_Interps := L;
3265 if not Is_Overloaded (L) then
3266 Common_Type := Etype (L);
3268 Alt := First (Alternatives (N));
3269 while Present (Alt) loop
3272 if not Has_Compatible_Type (Alt, Common_Type) then
3273 Wrong_Type (Alt, Common_Type);
3280 Alt := First (Alternatives (N));
3281 while Present (Alt) loop
3283 if not Is_Overloaded (Alt) then
3284 Common_Type := Etype (Alt);
3287 Get_First_Interp (Alt, Index, It);
3288 while Present (It.Typ) loop
3290 Has_Compatible_Type (Candidate_Interps, It.Typ)
3292 Remove_Interp (Index);
3295 Get_Next_Interp (Index, It);
3298 Get_First_Interp (Alt, Index, It);
3301 Error_Msg_N ("alternative has no legal type", Alt);
3305 -- If alternative is not overloaded, we have a unique type
3308 Set_Etype (Alt, It.Typ);
3310 -- If the alternative is an enumeration literal, use the one
3311 -- for this interpretation.
3313 if Is_Entity_Name (Alt) then
3314 Set_Entity (Alt, It.Nam);
3317 Get_Next_Interp (Index, It);
3320 Set_Is_Overloaded (Alt, False);
3321 Common_Type := Etype (Alt);
3324 Candidate_Interps := Alt;
3331 if Present (Common_Type) then
3332 Set_Etype (L, Common_Type);
3334 -- The left operand may still be overloaded, to be resolved using
3338 Error_Msg_N ("cannot resolve membership operation", N);
3340 end Analyze_Set_Membership;
3346 function Find_Interp return Boolean is
3351 Valid_I : Interp_Index;
3354 -- Loop through the interpretations of the left operand
3356 if not Is_Overloaded (L) then
3357 Found := Try_Left_Interp (Etype (L));
3364 Get_First_Interp (L, I, It);
3365 while Present (It.Typ) loop
3366 if Try_Left_Interp (It.Typ) then
3367 -- If several interpretations are possible, disambiguate
3370 and then Base_Type (It.Typ) /= Base_Type (L_Typ)
3372 It := Disambiguate (L, Valid_I, I, Any_Type);
3374 if It = No_Interp then
3375 Ambiguous_Operands (N);
3376 Set_Etype (L, Any_Type);
3385 Set_Etype (L, L_Typ);
3389 Get_Next_Interp (I, It);
3396 ---------------------
3397 -- Try_Left_Interp --
3398 ---------------------
3400 function Try_Left_Interp (T : Entity_Id) return Boolean is
3405 Valid_I : Interp_Index;
3408 -- Defend against previous error
3410 if Nkind (R) = N_Error then
3413 -- Loop through the interpretations of the right operand
3415 elsif not Is_Overloaded (R) then
3416 Found := Is_Valid_Pair (T, Etype (R));
3423 Get_First_Interp (R, I, It);
3424 while Present (It.Typ) loop
3425 if Is_Valid_Pair (T, It.Typ) then
3426 -- If several interpretations are possible, disambiguate
3429 and then Base_Type (It.Typ) /= Base_Type (R_Typ)
3431 It := Disambiguate (R, Valid_I, I, Any_Type);
3433 if It = No_Interp then
3434 Ambiguous_Operands (N);
3435 Set_Etype (R, Any_Type);
3447 Get_Next_Interp (I, It);
3452 end Try_Left_Interp;
3458 function Is_Valid_Pair (T1, T2 : Entity_Id) return Boolean is
3460 return Covers (T1 => T1, T2 => T2)
3461 or else Covers (T1 => T2, T2 => T1)
3462 or else Is_User_Defined_Literal (L, T2)
3463 or else Is_User_Defined_Literal (R, T1);
3471 -- Start of processing for Analyze_Membership_Op
3474 Analyze_Expression (L);
3477 pragma Assert (Ada_Version >= Ada_2012);
3479 Analyze_Set_Membership;
3484 Alt := First (Alternatives (N));
3485 while Present (Alt) loop
3486 if Is_Entity_Name (Alt) and then Is_Type (Entity (Alt)) then
3487 Check_Fully_Declared (Entity (Alt), Alt);
3489 if Has_Ghost_Predicate_Aspect (Entity (Alt)) then
3491 ("subtype& has ghost predicate, "
3492 & "not allowed in membership test",
3501 elsif Nkind (R) = N_Range
3502 or else (Nkind (R) = N_Attribute_Reference
3503 and then Attribute_Name (R) = Name_Range)
3505 Analyze_Expression (R);
3507 Dummy := Find_Interp;
3509 -- If not a range, it can be a subtype mark, or else it is a degenerate
3510 -- membership test with a singleton value, i.e. a test for equality,
3511 -- if the types are compatible.
3514 Analyze_Expression (R);
3516 if Is_Entity_Name (R) and then Is_Type (Entity (R)) then
3518 Check_Fully_Declared (Entity (R), R);
3520 if Has_Ghost_Predicate_Aspect (Entity (R)) then
3522 ("subtype& has ghost predicate, "
3523 & "not allowed in membership test",
3527 elsif Ada_Version >= Ada_2012 and then Find_Interp then
3528 Op := Make_Op_Eq (Loc, Left_Opnd => L, Right_Opnd => R);
3529 Resolve_Membership_Equality (Op, Etype (L));
3531 if Nkind (N) = N_Not_In then
3532 Op := Make_Op_Not (Loc, Op);
3540 -- In all versions of the language, if we reach this point there
3541 -- is a previous error that will be diagnosed below.
3547 -- Compatibility between expression and subtype mark or range is
3548 -- checked during resolution. The result of the operation is Boolean
3551 Set_Etype (N, Standard_Boolean);
3553 if Comes_From_Source (N)
3554 and then Present (Right_Opnd (N))
3555 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
3557 Error_Msg_N ("membership test not applicable to cpp-class types", N);
3560 Check_Function_Writable_Actuals (N);
3561 end Analyze_Membership_Op;
3567 procedure Analyze_Mod (N : Node_Id) is
3569 -- A special warning check, if we have an expression of the form:
3570 -- expr mod 2 * literal
3571 -- where literal is 128 or less, then probably what was meant was
3572 -- expr mod 2 ** literal
3573 -- so issue an appropriate warning.
3575 if Warn_On_Suspicious_Modulus_Value
3576 and then Nkind (Right_Opnd (N)) = N_Integer_Literal
3577 and then Intval (Right_Opnd (N)) = Uint_2
3578 and then Nkind (Parent (N)) = N_Op_Multiply
3579 and then Nkind (Right_Opnd (Parent (N))) = N_Integer_Literal
3580 and then Intval (Right_Opnd (Parent (N))) <= Uint_128
3583 ("suspicious MOD value, was '*'* intended'??.m?", Parent (N));
3586 -- Remaining processing is same as for other arithmetic operators
3588 Analyze_Arithmetic_Op (N);
3591 ----------------------
3592 -- Analyze_Negation --
3593 ----------------------
3595 procedure Analyze_Negation (N : Node_Id) is
3596 R : constant Node_Id := Right_Opnd (N);
3601 Set_Etype (N, Any_Type);
3602 Candidate_Type := Empty;
3604 Analyze_Expression (R);
3606 -- If the entity is already set, the node is the instantiation of a
3607 -- generic node with a non-local reference, or was manufactured by a
3608 -- call to Make_Op_xxx. In either case the entity is known to be valid,
3609 -- and we do not need to collect interpretations, instead we just get
3610 -- the single possible interpretation.
3612 if Present (Entity (N)) then
3613 Op_Id := Entity (N);
3615 if Ekind (Op_Id) = E_Operator then
3616 Find_Negation_Types (R, Op_Id, N);
3618 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3622 Op_Id := Get_Name_Entity_Id (Chars (N));
3623 while Present (Op_Id) loop
3624 if Ekind (Op_Id) = E_Operator then
3625 Find_Negation_Types (R, Op_Id, N);
3627 Analyze_User_Defined_Unary_Op (N, Op_Id);
3630 Op_Id := Homonym (Op_Id);
3635 end Analyze_Negation;
3641 procedure Analyze_Null (N : Node_Id) is
3643 Set_Etype (N, Universal_Access);
3646 ----------------------
3647 -- Analyze_One_Call --
3648 ----------------------
3650 procedure Analyze_One_Call
3654 Success : out Boolean;
3655 Skip_First : Boolean := False)
3657 Actuals : constant List_Id := Parameter_Associations (N);
3658 Prev_T : constant Entity_Id := Etype (N);
3660 -- Recognize cases of prefixed calls that have been rewritten in
3661 -- various ways. The simplest case is a rewritten selected component,
3662 -- but it can also be an already-examined indexed component, or a
3663 -- prefix that is itself a rewritten prefixed call that is in turn
3664 -- an indexed call (the syntactic ambiguity involving the indexing of
3665 -- a function with defaulted parameters that returns an array).
3666 -- A flag Maybe_Indexed_Call might be useful here ???
3668 Must_Skip : constant Boolean := Skip_First
3669 or else Nkind (Original_Node (N)) = N_Selected_Component
3671 (Nkind (Original_Node (N)) = N_Indexed_Component
3672 and then Nkind (Prefix (Original_Node (N))) =
3673 N_Selected_Component)
3675 (Nkind (Parent (N)) = N_Function_Call
3676 and then Is_Array_Type (Etype (Name (N)))
3677 and then Etype (Original_Node (N)) =
3678 Component_Type (Etype (Name (N)))
3679 and then Nkind (Original_Node (Parent (N))) =
3680 N_Selected_Component);
3682 -- The first formal must be omitted from the match when trying to find
3683 -- a primitive operation that is a possible interpretation, and also
3684 -- after the call has been rewritten, because the corresponding actual
3685 -- is already known to be compatible, and because this may be an
3686 -- indexing of a call with default parameters.
3688 First_Form : Entity_Id;
3691 Is_Indexed : Boolean := False;
3692 Is_Indirect : Boolean := False;
3693 Subp_Type : constant Entity_Id := Etype (Nam);
3696 function Compatible_Types_In_Predicate
3698 T2 : Entity_Id) return Boolean;
3699 -- For an Ada 2012 predicate or invariant, a call may mention an
3700 -- incomplete type, while resolution of the corresponding predicate
3701 -- function may see the full view, as a consequence of the delayed
3702 -- resolution of the corresponding expressions. This may occur in
3703 -- the body of a predicate function, or in a call to such. Anomalies
3704 -- involving private and full views can also happen. In each case,
3705 -- rewrite node or add conversions to remove spurious type errors.
3707 procedure Indicate_Name_And_Type;
3708 -- If candidate interpretation matches, indicate name and type of result
3711 function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
3712 -- There may be a user-defined operator that hides the current
3713 -- interpretation. We must check for this independently of the
3714 -- analysis of the call with the user-defined operation, because
3715 -- the parameter names may be wrong and yet the hiding takes place.
3716 -- This fixes a problem with ACATS test B34014O.
3718 -- When the type Address is a visible integer type, and the DEC
3719 -- system extension is visible, the predefined operator may be
3720 -- hidden as well, by one of the address operations in auxdec.
3721 -- Finally, the abstract operations on address do not hide the
3722 -- predefined operator (this is the purpose of making them abstract).
3724 -----------------------------------
3725 -- Compatible_Types_In_Predicate --
3726 -----------------------------------
3728 function Compatible_Types_In_Predicate
3730 T2 : Entity_Id) return Boolean
3732 function Common_Type (T : Entity_Id) return Entity_Id;
3733 -- Find non-private underlying full view if any, without going to
3734 -- ancestor type (as opposed to Underlying_Type).
3740 function Common_Type (T : Entity_Id) return Entity_Id is
3746 if Is_Private_Type (CT) and then Present (Full_View (CT)) then
3747 CT := Full_View (CT);
3750 if Is_Private_Type (CT)
3751 and then Present (Underlying_Full_View (CT))
3753 CT := Underlying_Full_View (CT);
3756 return Base_Type (CT);
3759 -- Start of processing for Compatible_Types_In_Predicate
3762 if (Ekind (Current_Scope) = E_Function
3763 and then Is_Predicate_Function (Current_Scope))
3765 (Ekind (Nam) = E_Function
3766 and then Is_Predicate_Function (Nam))
3768 if Is_Incomplete_Type (T1)
3769 and then Present (Full_View (T1))
3770 and then Full_View (T1) = T2
3772 Set_Etype (Formal, Etype (Actual));
3775 elsif Common_Type (T1) = Common_Type (T2) then
3776 Rewrite (Actual, Unchecked_Convert_To (Etype (Formal), Actual));
3786 end Compatible_Types_In_Predicate;
3788 ----------------------------
3789 -- Indicate_Name_And_Type --
3790 ----------------------------
3792 procedure Indicate_Name_And_Type is
3794 Add_One_Interp (N, Nam, Etype (Nam));
3795 Check_Implicit_Dereference (N, Etype (Nam));
3798 -- If the prefix of the call is a name, indicate the entity
3799 -- being called. If it is not a name, it is an expression that
3800 -- denotes an access to subprogram or else an entry or family. In
3801 -- the latter case, the name is a selected component, and the entity
3802 -- being called is noted on the selector.
3804 if not Is_Type (Nam) then
3805 if Is_Entity_Name (Name (N)) then
3806 Set_Entity (Name (N), Nam);
3807 Set_Etype (Name (N), Etype (Nam));
3809 elsif Nkind (Name (N)) = N_Selected_Component then
3810 Set_Entity (Selector_Name (Name (N)), Nam);
3814 if Debug_Flag_E and not Report then
3815 Write_Str (" Overloaded call ");
3816 Write_Int (Int (N));
3817 Write_Str (" compatible with ");
3818 Write_Int (Int (Nam));
3821 end Indicate_Name_And_Type;
3823 ------------------------
3824 -- Operator_Hidden_By --
3825 ------------------------
3827 function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
3828 Act1 : constant Node_Id := First_Actual (N);
3829 Act2 : constant Node_Id := Next_Actual (Act1);
3830 Form1 : constant Entity_Id := First_Formal (Fun);
3831 Form2 : constant Entity_Id := Next_Formal (Form1);
3834 if Ekind (Fun) /= E_Function or else Is_Abstract_Subprogram (Fun) then
3837 elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
3840 elsif Present (Form2) then
3842 or else not Has_Compatible_Type (Act2, Etype (Form2))
3847 elsif Present (Act2) then
3851 -- Now we know that the arity of the operator matches the function,
3852 -- and the function call is a valid interpretation. The function
3853 -- hides the operator if it has the right signature, or if one of
3854 -- its operands is a non-abstract operation on Address when this is
3855 -- a visible integer type.
3857 return Hides_Op (Fun, Nam)
3858 or else Is_Descendant_Of_Address (Etype (Form1))
3861 and then Is_Descendant_Of_Address (Etype (Form2)));
3862 end Operator_Hidden_By;
3864 -- Start of processing for Analyze_One_Call
3869 -- If the subprogram has no formals or if all the formals have defaults,
3870 -- and the return type is an array type, the node may denote an indexing
3871 -- of the result of a parameterless call. In Ada 2005, the subprogram
3872 -- may have one non-defaulted formal, and the call may have been written
3873 -- in prefix notation, so that the rebuilt parameter list has more than
3876 if not Is_Overloadable (Nam)
3877 and then Ekind (Nam) /= E_Subprogram_Type
3878 and then Ekind (Nam) /= E_Entry_Family
3883 -- An indexing requires at least one actual. The name of the call cannot
3884 -- be an implicit indirect call, so it cannot be a generated explicit
3887 if not Is_Empty_List (Actuals)
3889 (Needs_No_Actuals (Nam)
3891 (Needs_One_Actual (Nam)
3892 and then Present (Next_Actual (First (Actuals)))))
3894 if Is_Array_Type (Subp_Type)
3896 (Nkind (Name (N)) /= N_Explicit_Dereference
3897 or else Comes_From_Source (Name (N)))
3899 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
3901 elsif Is_Access_Type (Subp_Type)
3902 and then Is_Array_Type (Designated_Type (Subp_Type))
3906 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
3908 -- The prefix can also be a parameterless function that returns an
3909 -- access to subprogram, in which case this is an indirect call.
3910 -- If this succeeds, an explicit dereference is added later on,
3911 -- in Analyze_Call or Resolve_Call.
3913 elsif Is_Access_Type (Subp_Type)
3914 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
3916 Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
3921 -- If the call has been transformed into a slice, it is of the form
3922 -- F (Subtype) where F is parameterless. The node has been rewritten in
3923 -- Try_Indexed_Call and there is nothing else to do.
3926 and then Nkind (N) = N_Slice
3932 (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
3936 -- If an indirect call is a possible interpretation, indicate
3937 -- success to the caller. This may be an indexing of an explicit
3938 -- dereference of a call that returns an access type (see above).
3942 and then Nkind (Name (N)) = N_Explicit_Dereference
3943 and then Comes_From_Source (Name (N)))
3948 -- Mismatch in number or names of parameters
3950 elsif Debug_Flag_E then
3951 Write_Str (" normalization fails in call ");
3952 Write_Int (Int (N));
3953 Write_Str (" with subprogram ");
3954 Write_Int (Int (Nam));
3958 -- If the context expects a function call, discard any interpretation
3959 -- that is a procedure. If the node is not overloaded, leave as is for
3960 -- better error reporting when type mismatch is found.
3962 elsif Nkind (N) = N_Function_Call
3963 and then Is_Overloaded (Name (N))
3964 and then Ekind (Nam) = E_Procedure
3968 -- Ditto for function calls in a procedure context
3970 elsif Nkind (N) = N_Procedure_Call_Statement
3971 and then Is_Overloaded (Name (N))
3972 and then Etype (Nam) /= Standard_Void_Type
3976 elsif No (Actuals) then
3978 -- If Normalize succeeds, then there are default parameters for
3981 Indicate_Name_And_Type;
3983 elsif Ekind (Nam) = E_Operator then
3984 if Nkind (N) = N_Procedure_Call_Statement then
3988 -- This occurs when the prefix of the call is an operator name
3989 -- or an expanded name whose selector is an operator name.
3991 Analyze_Operator_Call (N, Nam);
3993 if Etype (N) /= Prev_T then
3995 -- Check that operator is not hidden by a function interpretation
3997 if Is_Overloaded (Name (N)) then
4003 Get_First_Interp (Name (N), I, It);
4004 while Present (It.Nam) loop
4005 if Operator_Hidden_By (It.Nam) then
4006 Set_Etype (N, Prev_T);
4010 Get_Next_Interp (I, It);
4015 -- If operator matches formals, record its name on the call.
4016 -- If the operator is overloaded, Resolve will select the
4017 -- correct one from the list of interpretations. The call
4018 -- node itself carries the first candidate.
4020 Set_Entity (Name (N), Nam);
4023 elsif Report and then Etype (N) = Any_Type then
4024 Error_Msg_N ("incompatible arguments for operator", N);
4028 -- Normalize_Actuals has chained the named associations in the
4029 -- correct order of the formals.
4031 Actual := First_Actual (N);
4032 Formal := First_Formal (Nam);
4033 First_Form := Formal;
4035 -- If we are analyzing a call rewritten from object notation, skip
4036 -- first actual, which may be rewritten later as an explicit
4040 Next_Actual (Actual);
4041 Next_Formal (Formal);
4044 while Present (Actual) and then Present (Formal) loop
4045 if Nkind (Parent (Actual)) /= N_Parameter_Association
4046 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
4048 -- The actual can be compatible with the formal, but we must
4049 -- also check that the context is not an address type that is
4050 -- visibly an integer type. In this case the use of literals is
4051 -- illegal, except in the body of descendants of system, where
4052 -- arithmetic operations on address are of course used.
4054 if Has_Compatible_Type (Actual, Etype (Formal))
4056 (Etype (Actual) /= Universal_Integer
4057 or else not Is_Descendant_Of_Address (Etype (Formal))
4058 or else In_Predefined_Unit (N))
4060 Next_Actual (Actual);
4061 Next_Formal (Formal);
4063 -- In Allow_Integer_Address mode, we allow an actual integer to
4064 -- match a formal address type and vice versa. We only do this
4065 -- if we are certain that an error will otherwise be issued
4067 elsif Address_Integer_Convert_OK
4068 (Etype (Actual), Etype (Formal))
4069 and then (Report and not Is_Indexed and not Is_Indirect)
4071 -- Handle this case by introducing an unchecked conversion
4074 Unchecked_Convert_To (Etype (Formal),
4075 Relocate_Node (Actual)));
4076 Analyze_And_Resolve (Actual, Etype (Formal));
4077 Next_Actual (Actual);
4078 Next_Formal (Formal);
4080 -- Under relaxed RM semantics silently replace occurrences of
4081 -- null by System.Address_Null. We only do this if we know that
4082 -- an error will otherwise be issued.
4084 elsif Null_To_Null_Address_Convert_OK (Actual, Etype (Formal))
4085 and then (Report and not Is_Indexed and not Is_Indirect)
4087 Replace_Null_By_Null_Address (Actual);
4088 Analyze_And_Resolve (Actual, Etype (Formal));
4089 Next_Actual (Actual);
4090 Next_Formal (Formal);
4092 elsif Compatible_Types_In_Predicate
4093 (Etype (Formal), Etype (Actual))
4095 Next_Actual (Actual);
4096 Next_Formal (Formal);
4098 -- A current instance used as an actual of a function,
4099 -- whose body has not been seen, may include a formal
4100 -- whose type is an incomplete view of an enclosing
4101 -- type declaration containing the current call (e.g.
4102 -- in the Expression for a component declaration).
4104 -- In this case, update the signature of the subprogram
4105 -- so the formal has the type of the full view.
4107 elsif Inside_Init_Proc
4108 and then Nkind (Actual) = N_Identifier
4109 and then Ekind (Etype (Formal)) = E_Incomplete_Type
4110 and then Etype (Actual) = Full_View (Etype (Formal))
4112 Set_Etype (Formal, Etype (Actual));
4113 Next_Actual (Actual);
4114 Next_Formal (Formal);
4116 -- Generate a class-wide type conversion for instances of
4117 -- class-wide equivalent types to their corresponding
4118 -- mutably tagged type.
4120 elsif Is_Mutably_Tagged_CW_Equivalent_Type (Etype (Actual))
4121 and then Etype (Formal) = Parent_Subtype (Etype (Actual))
4123 Make_Mutably_Tagged_Conversion (Actual);
4124 Next_Actual (Actual);
4125 Next_Formal (Formal);
4127 -- Handle failed type check
4130 if Debug_Flag_E then
4131 Write_Str (" type checking fails in call ");
4132 Write_Int (Int (N));
4133 Write_Str (" with formal ");
4134 Write_Int (Int (Formal));
4135 Write_Str (" in subprogram ");
4136 Write_Int (Int (Nam));
4140 -- Comment needed on the following test???
4142 if Report and not Is_Indexed and not Is_Indirect then
4144 -- Ada 2005 (AI-251): Complete the error notification
4145 -- to help new Ada 2005 users.
4147 if Is_Class_Wide_Type (Etype (Formal))
4148 and then Is_Interface (Etype (Etype (Formal)))
4149 and then not Interface_Present_In_Ancestor
4150 (Typ => Etype (Actual),
4151 Iface => Etype (Etype (Formal)))
4154 ("(Ada 2005) does not implement interface }",
4155 Actual, Etype (Etype (Formal)));
4158 -- If we are going to output a secondary error message
4159 -- below, we need to have Wrong_Type output the main one.
4162 (Actual, Etype (Formal), Multiple => All_Errors_Mode);
4164 if Nkind (Actual) = N_Op_Eq
4165 and then Nkind (Left_Opnd (Actual)) = N_Identifier
4167 Formal := First_Formal (Nam);
4168 while Present (Formal) loop
4169 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
4170 Error_Msg_N -- CODEFIX
4171 ("possible misspelling of `='>`!", Actual);
4175 Next_Formal (Formal);
4179 if All_Errors_Mode then
4180 Error_Msg_Sloc := Sloc (Nam);
4182 if Etype (Formal) = Any_Type then
4184 ("there is no legal actual parameter", Actual);
4187 if Is_Overloadable (Nam)
4188 and then Present (Alias (Nam))
4189 and then not Comes_From_Source (Nam)
4192 ("\\ =='> in call to inherited operation & #!",
4195 elsif Ekind (Nam) = E_Subprogram_Type then
4197 Access_To_Subprogram_Typ :
4198 constant Entity_Id :=
4200 (Associated_Node_For_Itype (Nam));
4203 ("\\ =='> in call to dereference of &#!",
4204 Actual, Access_To_Subprogram_Typ);
4209 ("\\ =='> in call to &#!", Actual, Nam);
4219 -- Normalize_Actuals has verified that a default value exists
4220 -- for this formal. Current actual names a subsequent formal.
4222 Next_Formal (Formal);
4226 -- Due to our current model of controlled type expansion we may
4227 -- have resolved a user call to a non-visible controlled primitive
4228 -- since these inherited subprograms may be generated in the current
4229 -- scope. This is a side effect of the need for the expander to be
4230 -- able to resolve internally generated calls.
4232 -- Specifically, the issue appears when predefined controlled
4233 -- operations get called on a type extension whose parent is a
4234 -- private extension completed with a controlled extension - see
4238 -- type Par_Typ is tagged private;
4240 -- type Par_Typ is new Controlled with null record;
4243 -- procedure Main is
4244 -- type Ext_Typ is new Par_Typ with null record;
4247 -- Finalize (Obj); -- Will improperly resolve
4250 -- To avoid breaking privacy, Is_Hidden gets set elsewhere on such
4251 -- primitives, but we still need to verify that Nam is indeed a
4252 -- non-visible controlled subprogram. So, we do that here and issue
4253 -- the appropriate error.
4256 and then not In_Instance
4257 and then not Comes_From_Source (Nam)
4258 and then Comes_From_Source (N)
4260 -- Verify Nam is a non-visible controlled primitive
4262 and then Chars (Nam) in Name_Adjust
4265 and then Ekind (Nam) = E_Procedure
4266 and then Is_Controlled (Etype (First_Form))
4267 and then No (Next_Formal (First_Form))
4268 and then not Is_Visibly_Controlled (Etype (First_Form))
4270 Error_Msg_Node_2 := Etype (First_Form);
4271 Error_Msg_NE ("call to non-visible controlled primitive & on type"
4275 -- On exit, all actuals match
4277 Indicate_Name_And_Type;
4279 end Analyze_One_Call;
4281 ---------------------------
4282 -- Analyze_Operator_Call --
4283 ---------------------------
4285 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
4286 Op_Name : constant Name_Id := Chars (Op_Id);
4287 Act1 : constant Node_Id := First_Actual (N);
4288 Act2 : constant Node_Id := Next_Actual (Act1);
4291 -- Binary operator case
4293 if Present (Act2) then
4295 -- If more than two operands, then not binary operator after all
4297 if Present (Next_Actual (Act2)) then
4301 -- Otherwise action depends on operator
4312 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
4318 Find_Boolean_Types (Act1, Act2, Op_Id, N);
4327 Find_Comparison_Equality_Types (Act1, Act2, Op_Id, N);
4329 when Name_Op_Concat =>
4330 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
4332 -- Is this when others, or should it be an abort???
4338 -- Unary operator case
4346 Find_Unary_Types (Act1, Op_Id, N);
4349 Find_Negation_Types (Act1, Op_Id, N);
4351 -- Is this when others correct, or should it be an abort???
4357 end Analyze_Operator_Call;
4359 -------------------------------------------
4360 -- Analyze_Overloaded_Selected_Component --
4361 -------------------------------------------
4363 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
4364 Nam : constant Node_Id := Prefix (N);
4365 Sel : constant Node_Id := Selector_Name (N);
4372 Set_Etype (Sel, Any_Type);
4374 Get_First_Interp (Nam, I, It);
4375 while Present (It.Typ) loop
4376 if Is_Access_Type (It.Typ) then
4377 T := Designated_Type (It.Typ);
4378 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
4383 -- Locate the component. For a private prefix the selector can denote
4386 if Is_Record_Type (T) or else Is_Private_Type (T) then
4388 -- If the prefix is a class-wide type, the visible components are
4389 -- those of the base type.
4391 if Is_Class_Wide_Type (T) then
4395 Comp := First_Entity (T);
4396 while Present (Comp) loop
4397 if Chars (Comp) = Chars (Sel)
4398 and then Is_Visible_Component (Comp, Sel)
4401 -- AI05-105: if the context is an object renaming with
4402 -- an anonymous access type, the expected type of the
4403 -- object must be anonymous. This is a name resolution rule.
4405 if Nkind (Parent (N)) /= N_Object_Renaming_Declaration
4406 or else No (Access_Definition (Parent (N)))
4407 or else Is_Anonymous_Access_Type (Etype (Comp))
4409 Set_Entity (Sel, Comp);
4410 Set_Etype (Sel, Etype (Comp));
4411 Add_One_Interp (N, Etype (Comp), Etype (Comp));
4412 Check_Implicit_Dereference (N, Etype (Comp));
4414 -- This also specifies a candidate to resolve the name.
4415 -- Further overloading will be resolved from context.
4416 -- The selector name itself does not carry overloading
4419 Set_Etype (Nam, It.Typ);
4422 -- Named access type in the context of a renaming
4423 -- declaration with an access definition. Remove
4424 -- inapplicable candidate.
4433 elsif Is_Concurrent_Type (T) then
4434 Comp := First_Entity (T);
4435 while Present (Comp)
4436 and then Comp /= First_Private_Entity (T)
4438 if Chars (Comp) = Chars (Sel) then
4439 if Is_Overloadable (Comp) then
4440 Add_One_Interp (Sel, Comp, Etype (Comp));
4442 Set_Entity_With_Checks (Sel, Comp);
4443 Generate_Reference (Comp, Sel);
4446 Set_Etype (Sel, Etype (Comp));
4447 Set_Etype (N, Etype (Comp));
4448 Set_Etype (Nam, It.Typ);
4454 Set_Is_Overloaded (N, Is_Overloaded (Sel));
4457 Get_Next_Interp (I, It);
4460 if Etype (N) = Any_Type
4461 and then not Try_Object_Operation (N)
4463 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
4464 Set_Entity (Sel, Any_Id);
4465 Set_Etype (Sel, Any_Type);
4467 end Analyze_Overloaded_Selected_Component;
4469 ----------------------------------
4470 -- Analyze_Qualified_Expression --
4471 ----------------------------------
4473 procedure Analyze_Qualified_Expression (N : Node_Id) is
4474 Expr : constant Node_Id := Expression (N);
4475 Mark : constant Entity_Id := Subtype_Mark (N);
4485 if Nkind (Enclosing_Declaration (N)) in
4486 N_Formal_Type_Declaration |
4487 N_Full_Type_Declaration |
4488 N_Incomplete_Type_Declaration |
4489 N_Protected_Type_Declaration |
4490 N_Private_Extension_Declaration |
4491 N_Private_Type_Declaration |
4492 N_Subtype_Declaration |
4493 N_Task_Type_Declaration
4494 and then T = Defining_Identifier (Enclosing_Declaration (N))
4496 Error_Msg_N ("current instance not allowed", Mark);
4502 Analyze_Expression (Expr);
4504 if T = Any_Type then
4508 Check_Fully_Declared (T, N);
4510 -- If expected type is class-wide, check for exact match before
4511 -- expansion, because if the expression is a dispatching call it
4512 -- may be rewritten as explicit dereference with class-wide result.
4513 -- If expression is overloaded, retain only interpretations that
4514 -- will yield exact matches.
4516 if Is_Class_Wide_Type (T) then
4517 if not Is_Overloaded (Expr) then
4518 if Base_Type (Etype (Expr)) /= Base_Type (T)
4519 and then Etype (Expr) /= Raise_Type
4521 if Nkind (Expr) = N_Aggregate then
4522 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
4524 Wrong_Type (Expr, T);
4529 Get_First_Interp (Expr, I, It);
4531 while Present (It.Nam) loop
4532 if Base_Type (It.Typ) /= Base_Type (T) then
4536 Get_Next_Interp (I, It);
4540 end Analyze_Qualified_Expression;
4542 -----------------------------------
4543 -- Analyze_Quantified_Expression --
4544 -----------------------------------
4546 procedure Analyze_Quantified_Expression (N : Node_Id) is
4547 function Is_Empty_Range (Typ : Entity_Id) return Boolean;
4548 -- Return True if the iterator is part of a quantified expression and
4549 -- the range is known to be statically empty.
4551 function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean;
4552 -- Determine whether if expression If_Expr lacks an else part or if it
4553 -- has one, it evaluates to True.
4555 --------------------
4556 -- Is_Empty_Range --
4557 --------------------
4559 function Is_Empty_Range (Typ : Entity_Id) return Boolean is
4561 return Is_Array_Type (Typ)
4562 and then Compile_Time_Known_Bounds (Typ)
4564 Expr_Value (Type_Low_Bound (Etype (First_Index (Typ)))) >
4565 Expr_Value (Type_High_Bound (Etype (First_Index (Typ))));
4568 -----------------------------
4569 -- No_Else_Or_Trivial_True --
4570 -----------------------------
4572 function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean is
4573 Else_Expr : constant Node_Id :=
4574 Next (Next (First (Expressions (If_Expr))));
4578 or else (Compile_Time_Known_Value (Else_Expr)
4579 and then Is_True (Expr_Value (Else_Expr)));
4580 end No_Else_Or_Trivial_True;
4584 Cond : constant Node_Id := Condition (N);
4585 Loc : constant Source_Ptr := Sloc (N);
4586 Loop_Id : Entity_Id;
4587 QE_Scop : Entity_Id;
4589 -- Start of processing for Analyze_Quantified_Expression
4592 -- Create a scope to emulate the loop-like behavior of the quantified
4593 -- expression. The scope is needed to provide proper visibility of the
4596 QE_Scop := New_Internal_Entity (E_Loop, Current_Scope, Loc, 'L');
4597 Set_Etype (QE_Scop, Standard_Void_Type);
4598 Set_Scope (QE_Scop, Current_Scope);
4599 Set_Parent (QE_Scop, N);
4601 Push_Scope (QE_Scop);
4603 -- All constituents are preanalyzed and resolved to avoid untimely
4604 -- generation of various temporaries and types. Full analysis and
4605 -- expansion is carried out when the quantified expression is
4606 -- transformed into an expression with actions.
4608 if Present (Iterator_Specification (N)) then
4609 Preanalyze (Iterator_Specification (N));
4611 -- Do not proceed with the analysis when the range of iteration is
4614 if Is_Entity_Name (Name (Iterator_Specification (N)))
4615 and then Is_Empty_Range (Etype (Name (Iterator_Specification (N))))
4617 Preanalyze_And_Resolve (Condition (N), Standard_Boolean);
4620 -- Emit a warning and replace expression with its static value
4622 if All_Present (N) then
4624 ("??quantified expression with ALL "
4625 & "over a null range has value True", N);
4626 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
4630 ("??quantified expression with SOME "
4631 & "over a null range has value False", N);
4632 Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
4639 else pragma Assert (Present (Loop_Parameter_Specification (N)));
4641 Loop_Par : constant Node_Id := Loop_Parameter_Specification (N);
4644 Preanalyze (Loop_Par);
4646 if Nkind (Discrete_Subtype_Definition (Loop_Par)) = N_Function_Call
4647 and then Parent (Loop_Par) /= N
4649 -- The parser cannot distinguish between a loop specification
4650 -- and an iterator specification. If after preanalysis the
4651 -- proper form has been recognized, rewrite the expression to
4652 -- reflect the right kind. This is needed for proper ASIS
4653 -- navigation. If expansion is enabled, the transformation is
4654 -- performed when the expression is rewritten as a loop.
4655 -- Is this still needed???
4657 Set_Iterator_Specification (N,
4658 New_Copy_Tree (Iterator_Specification (Parent (Loop_Par))));
4660 Set_Defining_Identifier (Iterator_Specification (N),
4661 Relocate_Node (Defining_Identifier (Loop_Par)));
4662 Set_Name (Iterator_Specification (N),
4663 Relocate_Node (Discrete_Subtype_Definition (Loop_Par)));
4664 Set_Comes_From_Source (Iterator_Specification (N),
4665 Comes_From_Source (Loop_Parameter_Specification (N)));
4666 Set_Loop_Parameter_Specification (N, Empty);
4671 Preanalyze_And_Resolve (Cond, Standard_Boolean);
4674 Set_Etype (N, Standard_Boolean);
4676 -- Verify that the loop variable is used within the condition of the
4677 -- quantified expression.
4679 if Present (Iterator_Specification (N)) then
4680 Loop_Id := Defining_Identifier (Iterator_Specification (N));
4682 Loop_Id := Defining_Identifier (Loop_Parameter_Specification (N));
4686 type Subexpr_Kind is (Full, Conjunct, Disjunct);
4688 procedure Check_Subexpr (Expr : Node_Id; Kind : Subexpr_Kind);
4689 -- Check that the quantified variable appears in every sub-expression
4690 -- of the quantified expression. If Kind is Full, Expr is the full
4691 -- expression. If Kind is Conjunct (resp. Disjunct), Expr is a
4692 -- conjunct (resp. disjunct) of the full expression.
4698 procedure Check_Subexpr (Expr : Node_Id; Kind : Subexpr_Kind) is
4700 if Nkind (Expr) in N_Op_And | N_And_Then
4701 and then Kind /= Disjunct
4703 Check_Subexpr (Left_Opnd (Expr), Conjunct);
4704 Check_Subexpr (Right_Opnd (Expr), Conjunct);
4706 elsif Nkind (Expr) in N_Op_Or | N_Or_Else
4707 and then Kind /= Conjunct
4709 Check_Subexpr (Left_Opnd (Expr), Disjunct);
4710 Check_Subexpr (Right_Opnd (Expr), Disjunct);
4713 and then not Referenced (Loop_Id, Expr)
4716 Sub : constant String :=
4717 (if Kind = Conjunct then "conjunct" else "disjunct");
4720 ("?.t?unused variable & in " & Sub, Expr, Loop_Id);
4722 ("\consider extracting " & Sub & " from quantified "
4723 & "expression", Expr, Loop_Id);
4729 if Warn_On_Suspicious_Contract
4730 and then not Is_Internal_Name (Chars (Loop_Id))
4732 if not Referenced (Loop_Id, Cond) then
4733 Error_Msg_N ("?.t?unused variable &", Loop_Id);
4735 Check_Subexpr (Cond, Kind => Full);
4740 -- Diagnose a possible misuse of the SOME existential quantifier. When
4741 -- we have a quantified expression of the form:
4743 -- for some X => (if P then Q [else True])
4745 -- any value for X that makes P False results in the if expression being
4746 -- trivially True, and so also results in the quantified expression
4747 -- being trivially True.
4749 if Warn_On_Suspicious_Contract
4750 and then not All_Present (N)
4751 and then Nkind (Cond) = N_If_Expression
4752 and then No_Else_Or_Trivial_True (Cond)
4754 Error_Msg_N ("?.t?suspicious expression", N);
4755 Error_Msg_N ("\\did you mean (for all X ='> (if P then Q))", N);
4756 Error_Msg_N ("\\or (for some X ='> P and then Q) instead'?", N);
4758 end Analyze_Quantified_Expression;
4764 procedure Analyze_Range (N : Node_Id) is
4765 L : constant Node_Id := Low_Bound (N);
4766 H : constant Node_Id := High_Bound (N);
4767 I1, I2 : Interp_Index;
4770 procedure Check_Common_Type (T1, T2 : Entity_Id);
4771 -- Verify the compatibility of two types, and choose the
4772 -- non universal one if the other is universal.
4774 procedure Check_High_Bound (T : Entity_Id);
4775 -- Test one interpretation of the low bound against all those
4776 -- of the high bound.
4778 procedure Check_Universal_Expression (N : Node_Id);
4779 -- In Ada 83, reject bounds of a universal range that are not literals
4782 -----------------------
4783 -- Check_Common_Type --
4784 -----------------------
4786 procedure Check_Common_Type (T1, T2 : Entity_Id) is
4788 if Covers (T1 => T1, T2 => T2)
4790 Covers (T1 => T2, T2 => T1)
4792 if Is_Universal_Numeric_Type (T1)
4793 or else T1 = Any_Character
4795 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
4798 Add_One_Interp (N, T1, T1);
4801 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
4804 end Check_Common_Type;
4806 ----------------------
4807 -- Check_High_Bound --
4808 ----------------------
4810 procedure Check_High_Bound (T : Entity_Id) is
4812 if not Is_Overloaded (H) then
4813 Check_Common_Type (T, Etype (H));
4815 Get_First_Interp (H, I2, It2);
4816 while Present (It2.Typ) loop
4817 Check_Common_Type (T, It2.Typ);
4818 Get_Next_Interp (I2, It2);
4821 end Check_High_Bound;
4823 --------------------------------
4824 -- Check_Universal_Expression --
4825 --------------------------------
4827 procedure Check_Universal_Expression (N : Node_Id) is
4829 if Etype (N) = Universal_Integer
4830 and then Nkind (N) /= N_Integer_Literal
4831 and then not Is_Entity_Name (N)
4832 and then Nkind (N) /= N_Attribute_Reference
4834 Error_Msg_N ("illegal bound in discrete range", N);
4836 end Check_Universal_Expression;
4838 -- Start of processing for Analyze_Range
4841 Set_Etype (N, Any_Type);
4842 Analyze_Expression (L);
4843 Analyze_Expression (H);
4845 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
4849 if not Is_Overloaded (L) then
4850 Check_High_Bound (Etype (L));
4852 Get_First_Interp (L, I1, It1);
4853 while Present (It1.Typ) loop
4854 Check_High_Bound (It1.Typ);
4855 Get_Next_Interp (I1, It1);
4859 -- If result is Any_Type, then we did not find a compatible pair
4861 if Etype (N) = Any_Type then
4862 Error_Msg_N ("incompatible types in range", N);
4866 if Ada_Version = Ada_83
4868 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
4869 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
4871 Check_Universal_Expression (L);
4872 Check_Universal_Expression (H);
4875 Check_Function_Writable_Actuals (N);
4878 -----------------------
4879 -- Analyze_Reference --
4880 -----------------------
4882 procedure Analyze_Reference (N : Node_Id) is
4883 P : constant Node_Id := Prefix (N);
4886 Acc_Type : Entity_Id;
4891 -- An interesting error check, if we take the 'Ref of an object for
4892 -- which a pragma Atomic or Volatile has been given, and the type of the
4893 -- object is not Atomic or Volatile, then we are in trouble. The problem
4894 -- is that no trace of the atomic/volatile status will remain for the
4895 -- backend to respect when it deals with the resulting pointer, since
4896 -- the pointer type will not be marked atomic (it is a pointer to the
4897 -- base type of the object).
4899 -- It is not clear if that can ever occur, but in case it does, we will
4900 -- generate an error message. Not clear if this message can ever be
4901 -- generated, and pretty clear that it represents a bug if it is, still
4902 -- seems worth checking, except in CodePeer mode where we do not really
4903 -- care and don't want to bother the user.
4907 if Is_Entity_Name (P)
4908 and then Is_Object_Reference (P)
4909 and then not CodePeer_Mode
4914 if (Has_Atomic_Components (E)
4915 and then not Has_Atomic_Components (T))
4917 (Has_Volatile_Components (E)
4918 and then not Has_Volatile_Components (T))
4919 or else (Is_Atomic (E) and then not Is_Atomic (T))
4920 or else (Is_Volatile (E) and then not Is_Volatile (T))
4922 Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
4926 -- Carry on with normal processing
4928 Acc_Type := Create_Itype (E_Allocator_Type, N);
4929 Set_Etype (Acc_Type, Acc_Type);
4930 Set_Directly_Designated_Type (Acc_Type, Etype (P));
4931 Set_Etype (N, Acc_Type);
4932 end Analyze_Reference;
4934 --------------------------------
4935 -- Analyze_Selected_Component --
4936 --------------------------------
4938 -- Prefix is a record type or a task or protected type. In the latter case,
4939 -- the selector must denote a visible entry.
4941 procedure Analyze_Selected_Component (N : Node_Id) is
4942 Pref : constant Node_Id := Prefix (N);
4943 Sel : constant Node_Id := Selector_Name (N);
4945 Comp : Entity_Id := Empty;
4946 Has_Candidate : Boolean := False;
4947 Hidden_Comp : Entity_Id;
4949 Is_Private_Op : Boolean;
4951 Prefix_Type : Entity_Id;
4953 Type_To_Use : Entity_Id;
4954 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
4955 -- a class-wide type, we use its root type, whose components are
4956 -- present in the class-wide type.
4958 Is_Single_Concurrent_Object : Boolean;
4959 -- Set True if the prefix is a single task or a single protected object
4961 function Constraint_Has_Unprefixed_Discriminant_Reference
4962 (Typ : Entity_Id) return Boolean;
4963 -- Given a subtype that is subject to a discriminant-dependent
4964 -- constraint, returns True if any of the values of the constraint
4965 -- (i.e., any of the index values for an index constraint, any of
4966 -- the discriminant values for a discriminant constraint)
4967 -- are unprefixed discriminant names.
4969 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
4970 -- It is known that the parent of N denotes a subprogram call. Comp
4971 -- is an overloadable component of the concurrent type of the prefix.
4972 -- Determine whether all formals of the parent of N and Comp are mode
4973 -- conformant. If the parent node is not analyzed yet it may be an
4974 -- indexed component rather than a function call.
4976 function Has_Dereference (Nod : Node_Id) return Boolean;
4977 -- Check whether Nod includes a dereference, explicit or implicit, at
4978 -- any recursive level.
4980 function Is_Simple_Indexed_Component (Nod : Node_Id) return Boolean;
4981 -- Check whether Nod is a simple indexed component in the context
4983 function Try_By_Protected_Procedure_Prefixed_View return Boolean;
4984 -- Return True if N is an access attribute whose prefix is a prefixed
4985 -- class-wide (synchronized or protected) interface view for which some
4986 -- interpretation is a procedure with synchronization kind By_Protected
4987 -- _Procedure, and collect all its interpretations (since it may be an
4988 -- overloaded interface primitive); otherwise return False.
4990 function Try_Selected_Component_In_Instance
4991 (Typ : Entity_Id) return Boolean;
4992 -- If Typ is the actual for a formal derived type, or a derived type
4993 -- thereof, the component inherited from the generic parent may not
4994 -- be visible in the actual, but the selected component is legal. Climb
4995 -- up the derivation chain of the generic parent type and return True if
4996 -- we find the proper ancestor type; otherwise return False.
4998 ------------------------------------------------------
4999 -- Constraint_Has_Unprefixed_Discriminant_Reference --
5000 ------------------------------------------------------
5002 function Constraint_Has_Unprefixed_Discriminant_Reference
5003 (Typ : Entity_Id) return Boolean
5005 function Is_Discriminant_Name (N : Node_Id) return Boolean is
5006 (Nkind (N) = N_Identifier
5007 and then Ekind (Entity (N)) = E_Discriminant);
5009 if Is_Array_Type (Typ) then
5011 Index : Node_Id := First_Index (Typ);
5014 while Present (Index) loop
5016 if Nkind (Rng) = N_Subtype_Indication then
5017 Rng := Range_Expression (Constraint (Rng));
5020 if Nkind (Rng) = N_Range then
5021 if Is_Discriminant_Name (Low_Bound (Rng))
5022 or else Is_Discriminant_Name (High_Bound (Rng))
5033 Elmt : Elmt_Id := First_Elmt (Discriminant_Constraint (Typ));
5035 while Present (Elmt) loop
5036 if Is_Discriminant_Name (Node (Elmt)) then
5045 end Constraint_Has_Unprefixed_Discriminant_Reference;
5047 ------------------------------
5048 -- Has_Mode_Conformant_Spec --
5049 ------------------------------
5051 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
5052 Comp_Param : Entity_Id;
5054 Param_Typ : Entity_Id;
5057 Comp_Param := First_Formal (Comp);
5059 if Nkind (Parent (N)) = N_Indexed_Component then
5060 Param := First (Expressions (Parent (N)));
5062 Param := First (Parameter_Associations (Parent (N)));
5065 while Present (Comp_Param)
5066 and then Present (Param)
5068 Param_Typ := Find_Parameter_Type (Param);
5070 if Present (Param_Typ)
5072 not Conforming_Types
5073 (Etype (Comp_Param), Param_Typ, Mode_Conformant)
5078 Next_Formal (Comp_Param);
5082 -- One of the specs has additional formals; there is no match, unless
5083 -- this may be an indexing of a parameterless call.
5085 -- Note that when expansion is disabled, the corresponding record
5086 -- type of synchronized types is not constructed, so that there is
5087 -- no point is attempting an interpretation as a prefixed call, as
5088 -- this is bound to fail because the primitive operations will not
5089 -- be properly located.
5091 if Present (Comp_Param) or else Present (Param) then
5092 if Needs_No_Actuals (Comp)
5093 and then Is_Array_Type (Etype (Comp))
5094 and then not Expander_Active
5103 end Has_Mode_Conformant_Spec;
5105 ---------------------
5106 -- Has_Dereference --
5107 ---------------------
5109 function Has_Dereference (Nod : Node_Id) return Boolean is
5111 if Nkind (Nod) = N_Explicit_Dereference then
5114 elsif Is_Access_Type (Etype (Nod)) then
5117 elsif Nkind (Nod) in N_Indexed_Component | N_Selected_Component then
5118 return Has_Dereference (Prefix (Nod));
5123 end Has_Dereference;
5125 ---------------------------------
5126 -- Is_Simple_Indexed_Component --
5127 ---------------------------------
5129 function Is_Simple_Indexed_Component (Nod : Node_Id) return Boolean is
5133 -- Nod must be an indexed component
5135 if Nkind (Nod) /= N_Indexed_Component then
5139 -- The context must not be a nested selected component
5141 if Nkind (Pref) = N_Selected_Component then
5145 -- The expressions must not be case expressions
5147 Expr := First (Expressions (Nod));
5148 while Present (Expr) loop
5149 if Nkind (Expr) = N_Case_Expression then
5157 end Is_Simple_Indexed_Component;
5159 ----------------------------------------------
5160 -- Try_By_Protected_Procedure_Prefixed_View --
5161 ----------------------------------------------
5163 function Try_By_Protected_Procedure_Prefixed_View return Boolean is
5164 Candidate : Node_Id := Empty;
5169 if Nkind (Parent (N)) = N_Attribute_Reference
5170 and then Attribute_Name (Parent (N)) in
5172 | Name_Unchecked_Access
5173 | Name_Unrestricted_Access
5174 and then Is_Class_Wide_Type (Prefix_Type)
5175 and then (Is_Synchronized_Interface (Prefix_Type)
5176 or else Is_Protected_Interface (Prefix_Type))
5178 -- If we have not found yet any interpretation then mark this
5179 -- one as the first interpretation (cf. Add_One_Interp).
5181 if No (Etype (Sel)) then
5182 Set_Etype (Sel, Any_Type);
5185 Elmt := First_Elmt (Primitive_Operations (Etype (Prefix_Type)));
5186 while Present (Elmt) loop
5187 Prim := Node (Elmt);
5189 if Chars (Prim) = Chars (Sel)
5190 and then Is_By_Protected_Procedure (Prim)
5192 Candidate := New_Copy (Prim);
5194 -- Skip the controlling formal; required to check type
5195 -- conformance of the target access to protected type
5196 -- (see Conforming_Types).
5198 Set_First_Entity (Candidate,
5199 Next_Entity (First_Entity (Prim)));
5201 Add_One_Interp (Sel, Candidate, Etype (Prim));
5202 Set_Etype (N, Etype (Prim));
5209 -- Propagate overloaded attribute
5211 if Present (Candidate) and then Is_Overloaded (Sel) then
5212 Set_Is_Overloaded (N);
5215 return Present (Candidate);
5216 end Try_By_Protected_Procedure_Prefixed_View;
5218 ----------------------------------------
5219 -- Try_Selected_Component_In_Instance --
5220 ----------------------------------------
5222 function Try_Selected_Component_In_Instance
5223 (Typ : Entity_Id) return Boolean
5225 procedure Find_Component_In_Instance (Rec : Entity_Id);
5226 -- In an instance, a component of a private extension may not be
5227 -- visible while it was visible in the generic. Search candidate
5228 -- scope for a component with the proper identifier. If a match is
5229 -- found, the Etype of both N and Sel are set from this component,
5230 -- and the entity of Sel is set to reference this component. If no
5231 -- match is found, Entity (Sel) remains unset. For a derived type
5232 -- that is an actual of the instance, the desired component may be
5233 -- found in any ancestor.
5235 --------------------------------
5236 -- Find_Component_In_Instance --
5237 --------------------------------
5239 procedure Find_Component_In_Instance (Rec : Entity_Id) is
5245 while Present (Typ) loop
5246 Comp := First_Component (Typ);
5247 while Present (Comp) loop
5248 if Chars (Comp) = Chars (Sel) then
5249 Set_Entity_With_Checks (Sel, Comp);
5250 Set_Etype (Sel, Etype (Comp));
5251 Set_Etype (N, Etype (Comp));
5255 Next_Component (Comp);
5258 -- If not found, the component may be declared in the parent
5259 -- type or its full view, if any.
5261 if Is_Derived_Type (Typ) then
5264 if Is_Private_Type (Typ) then
5265 Typ := Full_View (Typ);
5273 -- If we fall through, no match, so no changes made
5276 end Find_Component_In_Instance;
5282 -- Start of processing for Try_Selected_Component_In_Instance
5285 pragma Assert (In_Instance and then Is_Tagged_Type (Typ));
5286 pragma Assert (Etype (N) = Any_Type);
5288 -- Climb up derivation chain to generic actual subtype
5291 while not Is_Generic_Actual_Type (Par) loop
5292 if Ekind (Par) = E_Record_Type then
5293 Par := Parent_Subtype (Par);
5296 exit when Par = Etype (Par);
5301 -- Another special case: the type is an extension of a private
5302 -- type T, either is an actual in an instance or is immediately
5303 -- visible, and we are in the body of the instance, which means
5304 -- the generic body had a full view of the type declaration for
5305 -- T or some ancestor that defines the component in question.
5306 -- This happens because Is_Visible_Component returned False on
5307 -- this component, as T or the ancestor is still private since
5308 -- the Has_Private_View mechanism is bypassed because T or the
5309 -- ancestor is not directly referenced in the generic body.
5311 if Is_Derived_Type (Typ)
5312 and then (Used_As_Generic_Actual (Base_Type (Typ))
5313 or else Is_Immediately_Visible (Typ))
5314 and then In_Instance_Body
5315 and then Present (Parent_Subtype (Typ))
5317 Find_Component_In_Instance (Parent_Subtype (Typ));
5319 -- If Par is a generic actual, look for component in ancestor types.
5320 -- Skip this if we have no Declaration_Node, as is the case for
5324 and then Is_Generic_Actual_Type (Par)
5325 and then Present (Declaration_Node (Par))
5327 Par := Generic_Parent_Type (Declaration_Node (Par));
5329 Find_Component_In_Instance (Par);
5330 exit when Present (Entity (Sel))
5331 or else Par = Etype (Par);
5336 return Etype (N) /= Any_Type;
5337 end Try_Selected_Component_In_Instance;
5339 -- Start of processing for Analyze_Selected_Component
5342 Set_Etype (N, Any_Type);
5344 if Is_Overloaded (Pref) then
5345 Analyze_Overloaded_Selected_Component (N);
5348 elsif Etype (Pref) = Any_Type then
5349 Set_Entity (Sel, Any_Id);
5350 Set_Etype (Sel, Any_Type);
5354 Prefix_Type := Etype (Pref);
5357 if Is_Access_Type (Prefix_Type) then
5359 -- A RACW object can never be used as prefix of a selected component
5360 -- since that means it is dereferenced without being a controlling
5361 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
5362 -- reporting an error, we must check whether this is actually a
5363 -- dispatching call in prefix form.
5365 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
5366 and then Comes_From_Source (N)
5368 if Try_Object_Operation (N) then
5372 ("invalid dereference of a remote access-to-class-wide value",
5376 -- Normal case of selected component applied to access type
5379 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
5380 Prefix_Type := Implicitly_Designated_Type (Prefix_Type);
5383 -- Handle mutably tagged types
5385 elsif Is_Class_Wide_Equivalent_Type (Prefix_Type) then
5386 Prefix_Type := Parent_Subtype (Prefix_Type);
5388 -- If we have an explicit dereference of a remote access-to-class-wide
5389 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
5390 -- have to check for the case of a prefix that is a controlling operand
5391 -- of a prefixed dispatching call, as the dereference is legal in that
5392 -- case. Normally this condition is checked in Validate_Remote_Access_
5393 -- To_Class_Wide_Type, but we have to defer the checking for selected
5394 -- component prefixes because of the prefixed dispatching call case.
5395 -- Note that implicit dereferences are checked for this just above.
5397 elsif Nkind (Pref) = N_Explicit_Dereference
5398 and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Pref)))
5399 and then Comes_From_Source (N)
5401 if Try_Object_Operation (N) then
5405 ("invalid dereference of a remote access-to-class-wide value",
5410 -- (Ada 2005): if the prefix is the limited view of a type, and
5411 -- the context already includes the full view, use the full view
5412 -- in what follows, either to retrieve a component of to find
5413 -- a primitive operation. If the prefix is an explicit dereference,
5414 -- set the type of the prefix to reflect this transformation.
5415 -- If the nonlimited view is itself an incomplete type, get the
5416 -- full view if available.
5418 if From_Limited_With (Prefix_Type)
5419 and then Has_Non_Limited_View (Prefix_Type)
5421 Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
5423 if Nkind (N) = N_Explicit_Dereference then
5424 Set_Etype (Prefix (N), Prefix_Type);
5428 if Ekind (Prefix_Type) = E_Private_Subtype then
5429 Prefix_Type := Base_Type (Prefix_Type);
5432 Type_To_Use := Prefix_Type;
5434 -- For class-wide types, use the entity list of the root type. This
5435 -- indirection is specially important for private extensions because
5436 -- only the root type get switched (not the class-wide type).
5438 if Is_Class_Wide_Type (Prefix_Type) then
5439 Type_To_Use := Root_Type (Prefix_Type);
5442 -- If the prefix is a single concurrent object, use its name in error
5443 -- messages, rather than that of its anonymous type.
5445 Is_Single_Concurrent_Object :=
5446 Is_Concurrent_Type (Prefix_Type)
5447 and then Is_Internal_Name (Chars (Prefix_Type))
5448 and then not Is_Derived_Type (Prefix_Type)
5449 and then Is_Entity_Name (Pref);
5451 -- Avoid initializing Comp if that initialization is not needed
5452 -- (and, more importantly, if the call to First_Entity could fail).
5454 if Has_Discriminants (Type_To_Use)
5455 or else Is_Record_Type (Type_To_Use)
5456 or else Is_Private_Type (Type_To_Use)
5457 or else Is_Concurrent_Type (Type_To_Use)
5459 Comp := First_Entity (Type_To_Use);
5462 -- If the selector has an original discriminant, the node appears in
5463 -- an instance. Replace the discriminant with the corresponding one
5464 -- in the current discriminated type. For nested generics, this must
5465 -- be done transitively, so note the new original discriminant.
5467 if Nkind (Sel) = N_Identifier
5468 and then In_Instance
5469 and then Present (Original_Discriminant (Sel))
5471 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
5473 -- Mark entity before rewriting, for completeness and because
5474 -- subsequent semantic checks might examine the original node.
5476 Set_Entity (Sel, Comp);
5477 Rewrite (Sel, New_Occurrence_Of (Comp, Sloc (N)));
5478 Set_Original_Discriminant (Sel, Comp);
5479 Set_Etype (N, Etype (Comp));
5480 Check_Implicit_Dereference (N, Etype (Comp));
5482 elsif Is_Record_Type (Prefix_Type) then
5483 -- Find a component with the given name. If the node is a prefixed
5484 -- call, do not examine components whose visibility may be
5487 while Present (Comp)
5488 and then not Is_Prefixed_Call (N)
5490 -- When the selector has been resolved to a function then we may be
5491 -- looking at a prefixed call which has been preanalyzed already as
5492 -- part of a class condition. In such cases it is possible for a
5493 -- derived type to declare a component which has the same name as
5494 -- a primitive used in a parent's class condition.
5496 -- Avoid seeing components as possible interpretations of the
5497 -- selected component when this is true.
5499 and then not (Inside_Class_Condition_Preanalysis
5500 and then Present (Entity (Sel))
5501 and then Ekind (Entity (Sel)) = E_Function)
5503 if Chars (Comp) = Chars (Sel)
5504 and then Is_Visible_Component (Comp, N)
5506 Set_Entity_With_Checks (Sel, Comp);
5507 Set_Etype (Sel, Etype (Comp));
5509 if Ekind (Comp) = E_Discriminant then
5510 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
5512 ("cannot reference discriminant of unchecked union",
5516 if Is_Generic_Type (Prefix_Type)
5518 Is_Generic_Type (Root_Type (Prefix_Type))
5520 Set_Original_Discriminant (Sel, Comp);
5524 -- Resolve the prefix early otherwise it is not possible to
5525 -- build the actual subtype of the component: it may need
5526 -- to duplicate this prefix and duplication is only allowed
5527 -- on fully resolved expressions.
5531 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
5532 -- subtypes in a package specification.
5535 -- limited with Pkg;
5537 -- type Acc_Inc is access Pkg.T;
5539 -- N : Natural := X.all.Comp; -- ERROR, limited view
5540 -- end Pkg; -- Comp is not visible
5542 if Nkind (Pref) = N_Explicit_Dereference
5543 and then From_Limited_With (Etype (Prefix (Pref)))
5544 and then not Is_Potentially_Use_Visible (Etype (Pref))
5545 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
5546 N_Package_Specification
5549 ("premature usage of incomplete}", Prefix (Pref),
5550 Etype (Prefix (Pref)));
5553 -- We generally do not need an actual subtype for the case of
5554 -- a selection for an indexed component of a non-packed array,
5555 -- since, in this case, gigi can find all the necessary bound
5556 -- information. However, when the prefix is itself a selected
5557 -- component, for example a.b.c (i), gigi may regard a.b.c as
5558 -- a dynamic-sized temporary, so we generate an actual subtype
5559 -- for this case. Moreover, if the expressions are complex,
5560 -- the actual subtype may be needed for constructs generated
5561 -- by their analysis.
5563 -- We also do not need an actual subtype for the case of a
5564 -- first, last, length, or range attribute applied to a
5565 -- non-packed array, since gigi can again get the bounds in
5566 -- these cases (gigi cannot handle the packed case, since it
5567 -- has the bounds of the packed array type, not the original
5568 -- bounds of the type).
5570 Parent_N := Parent (N);
5572 if not Is_Packed (Etype (Comp))
5574 (Is_Simple_Indexed_Component (Parent_N)
5576 (Nkind (Parent_N) = N_Attribute_Reference
5578 Attribute_Name (Parent_N) in Name_First
5583 Set_Etype (N, Etype (Comp));
5585 -- If full analysis is not enabled, we do not generate an
5586 -- actual subtype, because in the absence of expansion
5587 -- reference to a formal of a protected type, for example,
5588 -- will not be properly transformed, and will lead to
5589 -- out-of-scope references in gigi.
5591 -- In all other cases, we currently build an actual subtype.
5592 -- It seems likely that many of these cases can be avoided,
5593 -- but right now, the front end makes direct references to the
5594 -- bounds (e.g. in generating a length check), and if we do
5595 -- not make an actual subtype, we end up getting a direct
5596 -- reference to a discriminant, which will not do.
5598 elsif Full_Analysis then
5600 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
5601 Insert_Action (N, Act_Decl);
5603 if No (Act_Decl) then
5604 Set_Etype (N, Etype (Comp));
5607 -- If discriminants were present in the component
5608 -- declaration, they have been replaced by the
5609 -- actual values in the prefix object.
5612 Subt : constant Entity_Id :=
5613 Defining_Identifier (Act_Decl);
5615 Set_Etype (Subt, Base_Type (Etype (Comp)));
5616 Set_Etype (N, Subt);
5620 -- If Etype (Comp) is an access type whose designated subtype
5621 -- is constrained by an unprefixed discriminant value,
5622 -- then ideally we would build a new subtype with an
5623 -- appropriately prefixed discriminant value and use that
5624 -- instead, as is done in Build_Actual_Subtype_Of_Component.
5625 -- That turns out to be difficult in this context (with
5626 -- Full_Analysis = False, we could be processing a selected
5627 -- component that occurs in a Postcondition pragma;
5628 -- PPC pragmas are odd because they can contain references
5629 -- to formal parameters that occur outside the subprogram).
5630 -- So instead we punt on building a new subtype and we
5631 -- use the base type instead. This might introduce
5632 -- correctness problems if N were the target of an
5633 -- assignment (because a required check might be omitted);
5634 -- fortunately, that's impossible because a reference to the
5635 -- current instance of a type does not denote a variable view
5636 -- when the reference occurs within an aspect_specification.
5637 -- GNAT's Precondition and Postcondition pragmas follow the
5638 -- same rules as a Pre or Post aspect_specification.
5640 elsif Has_Discriminant_Dependent_Constraint (Comp)
5641 and then Ekind (Etype (Comp)) = E_Access_Subtype
5642 and then Constraint_Has_Unprefixed_Discriminant_Reference
5643 (Designated_Type (Etype (Comp)))
5645 Set_Etype (N, Base_Type (Etype (Comp)));
5647 -- If Full_Analysis not enabled, just set the Etype
5650 Set_Etype (N, Etype (Comp));
5653 -- Force the generation of a mutably tagged type conversion
5654 -- when we encounter a special class-wide equivalent type.
5656 if Is_Mutably_Tagged_CW_Equivalent_Type (Etype (Pref)) then
5657 Make_Mutably_Tagged_Conversion (Pref, Force => True);
5660 Check_Implicit_Dereference (N, Etype (N));
5664 -- If the prefix is a private extension, check only the visible
5665 -- components of the partial view. This must include the tag,
5666 -- which can appear in expanded code in a tag check.
5668 if Ekind (Type_To_Use) = E_Record_Type_With_Private
5669 and then Chars (Sel) /= Name_uTag
5671 exit when Comp = Last_Entity (Type_To_Use);
5677 -- Ada 2005 (AI-252): The selected component can be interpreted as
5678 -- a prefixed view of a subprogram. Depending on the context, this is
5679 -- either a name that can appear in a renaming declaration, or part
5680 -- of an enclosing call given in prefix form.
5682 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
5683 -- selected component should resolve to a name.
5685 -- Extension feature: Also support calls with prefixed views for
5686 -- untagged record types.
5688 if Ada_Version >= Ada_2005
5689 and then (Is_Tagged_Type (Prefix_Type)
5690 or else Core_Extensions_Allowed)
5691 and then not Is_Concurrent_Type (Prefix_Type)
5693 if Nkind (Parent (N)) = N_Generic_Association
5694 or else Nkind (Parent (N)) = N_Requeue_Statement
5695 or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
5697 if Find_Primitive_Operation (N) then
5701 elsif Try_By_Protected_Procedure_Prefixed_View then
5704 -- If the prefix type is the actual for a formal derived type,
5705 -- or a derived type thereof, the component inherited from the
5706 -- generic parent may not be visible in the actual, but the
5707 -- selected component is legal. This case must be handled before
5708 -- trying the object.operation notation to avoid reporting
5709 -- spurious errors, but must be skipped when Is_Prefixed_Call has
5710 -- been set (because that means that this node was resolved to an
5711 -- Object.Operation call when the generic unit was analyzed).
5714 and then not Is_Prefixed_Call (N)
5715 and then Is_Tagged_Type (Prefix_Type)
5716 and then Try_Selected_Component_In_Instance (Type_To_Use)
5720 elsif Try_Object_Operation (N) then
5724 -- If the transformation fails, it will be necessary to redo the
5725 -- analysis with all errors enabled, to indicate candidate
5726 -- interpretations and reasons for each failure ???
5730 elsif Is_Private_Type (Prefix_Type) then
5732 -- Allow access only to discriminants of the type. If the type has
5733 -- no full view, gigi uses the parent type for the components, so we
5734 -- do the same here.
5736 if No (Full_View (Prefix_Type)) then
5737 Type_To_Use := Root_Type (Base_Type (Prefix_Type));
5738 Comp := First_Entity (Type_To_Use);
5741 while Present (Comp) loop
5742 if Chars (Comp) = Chars (Sel) then
5743 if Ekind (Comp) = E_Discriminant then
5744 Set_Entity_With_Checks (Sel, Comp);
5745 Generate_Reference (Comp, Sel);
5747 Set_Etype (Sel, Etype (Comp));
5748 Set_Etype (N, Etype (Comp));
5749 Check_Implicit_Dereference (N, Etype (N));
5751 if Is_Generic_Type (Prefix_Type)
5752 or else Is_Generic_Type (Root_Type (Prefix_Type))
5754 Set_Original_Discriminant (Sel, Comp);
5757 -- Before declaring an error, check whether this is tagged
5758 -- private type and a call to a primitive operation.
5760 elsif Ada_Version >= Ada_2005
5761 and then Is_Tagged_Type (Prefix_Type)
5762 and then Try_Object_Operation (N)
5767 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
5768 Error_Msg_NE ("invisible selector& for }", N, Sel);
5769 Set_Entity (Sel, Any_Id);
5770 Set_Etype (N, Any_Type);
5779 -- Extension feature: Also support calls with prefixed views for
5780 -- untagged private types.
5782 if Core_Extensions_Allowed then
5783 if Try_Object_Operation (N) then
5788 elsif Is_Concurrent_Type (Prefix_Type) then
5790 -- Find visible operation with given name. For a protected type,
5791 -- the possible candidates are discriminants, entries or protected
5792 -- subprograms. For a task type, the set can only include entries or
5793 -- discriminants if the task type is not an enclosing scope. If it
5794 -- is an enclosing scope (e.g. in an inner task) then all entities
5795 -- are visible, but the prefix must denote the enclosing scope, i.e.
5796 -- can only be a direct name or an expanded name.
5798 Set_Etype (Sel, Any_Type);
5799 Hidden_Comp := Empty;
5800 In_Scope := In_Open_Scopes (Prefix_Type);
5801 Is_Private_Op := False;
5803 while Present (Comp) loop
5805 -- Do not examine private operations of the type if not within
5808 if Chars (Comp) = Chars (Sel) then
5809 if Is_Overloadable (Comp)
5811 or else Comp /= First_Private_Entity (Type_To_Use))
5813 Add_One_Interp (Sel, Comp, Etype (Comp));
5814 if Comp = First_Private_Entity (Type_To_Use) then
5815 Is_Private_Op := True;
5818 -- If the prefix is tagged, the correct interpretation may
5819 -- lie in the primitive or class-wide operations of the
5820 -- type. Perform a simple conformance check to determine
5821 -- whether Try_Object_Operation should be invoked even if
5822 -- a visible entity is found.
5824 if Is_Tagged_Type (Prefix_Type)
5825 and then Nkind (Parent (N)) in N_Function_Call
5826 | N_Indexed_Component
5827 | N_Procedure_Call_Statement
5828 and then Has_Mode_Conformant_Spec (Comp)
5830 Has_Candidate := True;
5833 -- Note: a selected component may not denote a component of a
5834 -- protected type (4.1.3(7)).
5836 elsif Ekind (Comp) in E_Discriminant | E_Entry_Family
5838 and then not Is_Protected_Type (Prefix_Type)
5839 and then Is_Entity_Name (Pref))
5841 Set_Entity_With_Checks (Sel, Comp);
5842 Generate_Reference (Comp, Sel);
5844 -- The selector is not overloadable, so we have a candidate
5847 Has_Candidate := True;
5850 if Ekind (Comp) = E_Component then
5851 Hidden_Comp := Comp;
5857 Set_Etype (Sel, Etype (Comp));
5858 Set_Etype (N, Etype (Comp));
5860 if Ekind (Comp) = E_Discriminant then
5861 Set_Original_Discriminant (Sel, Comp);
5866 if Comp = First_Private_Entity (Type_To_Use) then
5867 if Etype (Sel) /= Any_Type then
5869 -- If the first private entity's name matches, then treat
5870 -- it as a private op: needed for the error check for
5871 -- illegal selection of private entities further below.
5873 if Chars (Comp) = Chars (Sel) then
5874 Is_Private_Op := True;
5877 -- We have a candidate, so exit the loop
5882 -- Indicate that subsequent operations are private,
5883 -- for better error reporting.
5885 Is_Private_Op := True;
5889 -- Do not examine private operations if not within scope of
5890 -- the synchronized type.
5892 exit when not In_Scope
5894 Comp = First_Private_Entity (Base_Type (Prefix_Type));
5898 -- If the scope is a current instance, the prefix cannot be an
5899 -- expression of the same type, unless the selector designates a
5900 -- public operation (otherwise that would represent an attempt to
5901 -- reach an internal entity of another synchronized object).
5903 -- This is legal if prefix is an access to such type and there is
5904 -- a dereference, or is a component with a dereferenced prefix.
5905 -- It is also legal if the prefix is a component of a task type,
5906 -- and the selector is one of the task operations.
5909 and then not Is_Entity_Name (Pref)
5910 and then not Has_Dereference (Pref)
5912 if Is_Task_Type (Prefix_Type)
5913 and then Present (Entity (Sel))
5914 and then Is_Entry (Entity (Sel))
5918 elsif Is_Protected_Type (Prefix_Type)
5919 and then Is_Overloadable (Entity (Sel))
5920 and then not Is_Private_Op
5926 ("invalid reference to internal operation of some object of "
5927 & "type &", N, Type_To_Use);
5928 Set_Entity (Sel, Any_Id);
5929 Set_Etype (Sel, Any_Type);
5933 -- Another special case: the prefix may denote an object of the type
5934 -- (but not a type) in which case this is an external call and the
5935 -- operation must be public.
5938 and then Is_Object_Reference (Original_Node (Prefix (N)))
5939 and then Comes_From_Source (N)
5940 and then Is_Private_Op
5942 if Present (Hidden_Comp) then
5944 ("invalid reference to private component of object of type "
5945 & "&", N, Type_To_Use);
5949 ("invalid reference to private operation of some object of "
5950 & "type &", N, Type_To_Use);
5953 Set_Entity (Sel, Any_Id);
5954 Set_Etype (Sel, Any_Type);
5958 -- If there is no visible entity with the given name or none of the
5959 -- visible entities are plausible interpretations, check whether
5960 -- there is some other primitive operation with that name.
5962 if Ada_Version >= Ada_2005 and then Is_Tagged_Type (Prefix_Type) then
5963 if (Etype (N) = Any_Type
5964 or else not Has_Candidate)
5965 and then Try_Object_Operation (N)
5969 -- If the context is not syntactically a procedure call, it
5970 -- may be a call to a primitive function declared outside of
5971 -- the synchronized type.
5973 -- If the context is a procedure call, there might still be
5974 -- an overloading between an entry and a primitive procedure
5975 -- declared outside of the synchronized type, called in prefix
5976 -- notation. This is harder to disambiguate because in one case
5977 -- the controlling formal is implicit ???
5979 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
5980 and then Nkind (Parent (N)) /= N_Indexed_Component
5981 and then Try_Object_Operation (N)
5986 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
5987 -- entry or procedure of a tagged concurrent type we must check
5988 -- if there are class-wide subprograms covering the primitive. If
5989 -- true then Try_Object_Operation reports the error.
5992 and then Is_Concurrent_Type (Prefix_Type)
5993 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
5995 -- Duplicate the call. This is required to avoid problems with
5996 -- the tree transformations performed by Try_Object_Operation.
5997 -- Set properly the parent of the copied call, because it is
5998 -- about to be reanalyzed.
6001 Par : constant Node_Id := New_Copy_Tree (Parent (N));
6004 Set_Parent (Par, Parent (Parent (N)));
6006 if Try_Object_Operation
6007 (Sinfo.Nodes.Name (Par), CW_Test_Only => True)
6015 if Etype (N) = Any_Type and then Is_Protected_Type (Prefix_Type) then
6017 -- Case of a prefix of a protected type: selector might denote
6018 -- an invisible private component.
6020 Comp := First_Private_Entity (Base_Type (Prefix_Type));
6021 while Present (Comp) and then Chars (Comp) /= Chars (Sel) loop
6025 if Present (Comp) then
6026 if Is_Single_Concurrent_Object then
6027 Error_Msg_Node_2 := Entity (Pref);
6028 Error_Msg_NE ("invisible selector& for &", N, Sel);
6031 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
6032 Error_Msg_NE ("invisible selector& for }", N, Sel);
6038 Set_Is_Overloaded (N, Is_Overloaded (Sel));
6040 -- Extension feature: Also support calls with prefixed views for
6043 elsif Core_Extensions_Allowed
6044 and then Try_Object_Operation (N)
6051 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
6054 -- If the selector is not labelled with an entity at this point, the
6055 -- component is not defined in the prefix.
6057 if No (Entity (Sel)) then
6059 if Is_Single_Concurrent_Object then
6060 Error_Msg_Node_2 := Entity (Pref);
6061 Error_Msg_NE ("no selector& for&", N, Sel);
6063 Check_Misspelled_Selector (Type_To_Use, Sel);
6065 -- If this is a derived formal type, the parent may have different
6066 -- visibility at this point. Try for an inherited component before
6067 -- reporting an error.
6069 elsif Is_Generic_Type (Prefix_Type)
6070 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
6071 and then Prefix_Type /= Etype (Prefix_Type)
6072 and then Is_Record_Type (Etype (Prefix_Type))
6074 Set_Etype (Prefix (N), Etype (Prefix_Type));
6075 Analyze_Selected_Component (N);
6078 -- Similarly, if this is the actual for a formal derived type, or
6079 -- a derived type thereof, the component inherited from the generic
6080 -- parent may not be visible in the actual, but the selected
6081 -- component is legal.
6083 elsif In_Instance and then Is_Tagged_Type (Prefix_Type) then
6085 -- Climb up the derivation chain of the generic parent type until
6086 -- we find the proper ancestor type.
6088 if Try_Selected_Component_In_Instance (Type_To_Use) then
6091 -- The search above must have eventually succeeded, since the
6092 -- selected component was legal in the generic.
6095 raise Program_Error;
6098 -- Component not found, specialize error message when appropriate
6101 if Ekind (Prefix_Type) = E_Record_Subtype then
6103 -- Check whether this is a component of the base type which
6104 -- is absent from a statically constrained subtype. This will
6105 -- raise constraint error at run time, but is not a compile-
6106 -- time error. When the selector is illegal for base type as
6107 -- well fall through and generate a compilation error anyway.
6109 Comp := First_Component (Base_Type (Prefix_Type));
6110 while Present (Comp) loop
6111 if Chars (Comp) = Chars (Sel)
6112 and then Is_Visible_Component (Comp, Sel)
6114 Set_Entity_With_Checks (Sel, Comp);
6115 Generate_Reference (Comp, Sel);
6116 Set_Etype (Sel, Etype (Comp));
6117 Set_Etype (N, Etype (Comp));
6119 -- Emit appropriate message. The node will be replaced
6120 -- by an appropriate raise statement.
6122 -- Note that in GNATprove mode, as with all calls to
6123 -- apply a compile time constraint error, this will be
6124 -- made into an error to simplify the processing of the
6125 -- formal verification backend.
6127 Apply_Compile_Time_Constraint_Error
6128 (N, "component not present in }??",
6129 CE_Discriminant_Check_Failed,
6132 GNATprove_Mode or not In_Instance_Not_Visible);
6136 Next_Component (Comp);
6141 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
6142 Error_Msg_NE ("no selector& for}", N, Sel);
6144 -- Add information in the case of an incomplete prefix
6146 if Is_Incomplete_Type (Type_To_Use) then
6148 Inc : constant Entity_Id := First_Subtype (Type_To_Use);
6151 if From_Limited_With (Scope (Type_To_Use)) then
6153 ("\limited view of& has no components", N, Inc);
6157 ("\premature usage of incomplete type&", N, Inc);
6159 if Nkind (Parent (Inc)) =
6160 N_Incomplete_Type_Declaration
6162 -- Record location of premature use in entity so that
6163 -- a continuation message is generated when the
6164 -- completion is seen.
6166 Set_Premature_Use (Parent (Inc), N);
6172 Check_Misspelled_Selector (Type_To_Use, Sel);
6175 Set_Entity (Sel, Any_Id);
6176 Set_Etype (Sel, Any_Type);
6178 end Analyze_Selected_Component;
6180 ---------------------------
6181 -- Analyze_Short_Circuit --
6182 ---------------------------
6184 procedure Analyze_Short_Circuit (N : Node_Id) is
6185 L : constant Node_Id := Left_Opnd (N);
6186 R : constant Node_Id := Right_Opnd (N);
6191 Set_Etype (N, Any_Type);
6192 Analyze_Expression (L);
6193 Analyze_Expression (R);
6195 if not Is_Overloaded (L) then
6196 if Root_Type (Etype (L)) = Standard_Boolean
6197 and then Has_Compatible_Type (R, Etype (L))
6199 Add_One_Interp (N, Etype (L), Etype (L));
6203 Get_First_Interp (L, Ind, It);
6204 while Present (It.Typ) loop
6205 if Root_Type (It.Typ) = Standard_Boolean
6206 and then Has_Compatible_Type (R, It.Typ)
6208 Add_One_Interp (N, It.Typ, It.Typ);
6211 Get_Next_Interp (Ind, It);
6215 -- Here we have failed to find an interpretation. Clearly we know that
6216 -- it is not the case that both operands can have an interpretation of
6217 -- Boolean, but this is by far the most likely intended interpretation.
6218 -- So we simply resolve both operands as Booleans, and at least one of
6219 -- these resolutions will generate an error message, and we do not need
6220 -- to give another error message on the short circuit operation itself.
6222 if Etype (N) = Any_Type then
6223 Resolve (L, Standard_Boolean);
6224 Resolve (R, Standard_Boolean);
6225 Set_Etype (N, Standard_Boolean);
6229 if Nkind (L) not in N_Short_Circuit | N_Op_And | N_Op_Or | N_Op_Xor
6231 Check_Xtra_Parens_Precedence (L);
6234 if Nkind (R) not in N_Short_Circuit | N_Op_And | N_Op_Or | N_Op_Xor
6236 Check_Xtra_Parens_Precedence (R);
6239 end Analyze_Short_Circuit;
6245 procedure Analyze_Slice (N : Node_Id) is
6246 D : constant Node_Id := Discrete_Range (N);
6247 P : constant Node_Id := Prefix (N);
6248 Array_Type : Entity_Id;
6249 Index_Type : Entity_Id;
6251 procedure Analyze_Overloaded_Slice;
6252 -- If the prefix is overloaded, select those interpretations that
6253 -- yield a one-dimensional array type.
6255 ------------------------------
6256 -- Analyze_Overloaded_Slice --
6257 ------------------------------
6259 procedure Analyze_Overloaded_Slice is
6265 Set_Etype (N, Any_Type);
6267 Get_First_Interp (P, I, It);
6268 while Present (It.Nam) loop
6271 if Is_Access_Type (Typ) then
6272 Typ := Designated_Type (Typ);
6274 (Warn_On_Dereference, "?d?implicit dereference", N);
6277 if Is_Array_Type (Typ)
6278 and then Number_Dimensions (Typ) = 1
6279 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
6281 Add_One_Interp (N, Typ, Typ);
6284 Get_Next_Interp (I, It);
6287 if Etype (N) = Any_Type then
6288 Error_Msg_N ("expect array type in prefix of slice", N);
6290 end Analyze_Overloaded_Slice;
6292 -- Start of processing for Analyze_Slice
6298 if Is_Overloaded (P) then
6299 Analyze_Overloaded_Slice;
6302 Array_Type := Etype (P);
6303 Set_Etype (N, Any_Type);
6305 if Is_Access_Type (Array_Type) then
6306 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
6307 Array_Type := Implicitly_Designated_Type (Array_Type);
6310 if not Is_Array_Type (Array_Type) then
6311 Wrong_Type (P, Any_Array);
6313 elsif Number_Dimensions (Array_Type) > 1 then
6315 ("type is not one-dimensional array in slice prefix", N);
6318 if Ekind (Array_Type) = E_String_Literal_Subtype then
6319 Index_Type := Etype (String_Literal_Low_Bound (Array_Type));
6321 Index_Type := Etype (First_Index (Array_Type));
6324 if not Has_Compatible_Type (D, Index_Type) then
6325 Wrong_Type (D, Index_Type);
6327 Set_Etype (N, Array_Type);
6333 -----------------------------
6334 -- Analyze_Type_Conversion --
6335 -----------------------------
6337 procedure Analyze_Type_Conversion (N : Node_Id) is
6338 Expr : constant Node_Id := Expression (N);
6339 Mark : constant Entity_Id := Subtype_Mark (N);
6344 -- If Conversion_OK is set, then the Etype is already set, and the only
6345 -- processing required is to analyze the expression. This is used to
6346 -- construct certain "illegal" conversions which are not allowed by Ada
6347 -- semantics, but can be handled by Gigi, see Sinfo for further details.
6349 if Conversion_OK (N) then
6354 -- Otherwise full type analysis is required, as well as some semantic
6355 -- checks to make sure the argument of the conversion is appropriate.
6358 Typ := Entity (Mark);
6361 Analyze_Expression (Expr);
6363 Check_Fully_Declared (Typ, N);
6364 Validate_Remote_Type_Type_Conversion (N);
6366 -- Only remaining step is validity checks on the argument. These
6367 -- are skipped if the conversion does not come from the source.
6369 if not Comes_From_Source (N) then
6372 -- If there was an error in a generic unit, no need to replicate the
6373 -- error message. Conversely, constant-folding in the generic may
6374 -- transform the argument of a conversion into a string literal, which
6375 -- is legal. Therefore the following tests are not performed in an
6376 -- instance. The same applies to an inlined body.
6378 elsif In_Instance or In_Inlined_Body then
6381 elsif Nkind (Expr) = N_Null then
6382 Error_Msg_N ("argument of conversion cannot be null", N);
6383 Error_Msg_N ("\use qualified expression instead", N);
6384 Set_Etype (N, Any_Type);
6386 elsif Nkind (Expr) = N_Aggregate then
6387 Error_Msg_N ("argument of conversion cannot be aggregate", N);
6388 Error_Msg_N ("\use qualified expression instead", N);
6390 elsif Nkind (Expr) = N_Allocator then
6391 Error_Msg_N ("argument of conversion cannot be allocator", N);
6392 Error_Msg_N ("\use qualified expression instead", N);
6394 elsif Nkind (Expr) = N_String_Literal then
6395 Error_Msg_N ("argument of conversion cannot be string literal", N);
6396 Error_Msg_N ("\use qualified expression instead", N);
6398 elsif Nkind (Expr) = N_Character_Literal then
6399 if Ada_Version = Ada_83 then
6400 Resolve (Expr, Typ);
6403 ("argument of conversion cannot be character literal", N);
6404 Error_Msg_N ("\use qualified expression instead", N);
6407 elsif Nkind (Expr) = N_Attribute_Reference
6408 and then Attribute_Name (Expr) in Name_Access
6409 | Name_Unchecked_Access
6410 | Name_Unrestricted_Access
6413 ("argument of conversion cannot be access attribute", N);
6414 Error_Msg_N ("\use qualified expression instead", N);
6417 -- A formal parameter of a specific tagged type whose related subprogram
6418 -- is subject to pragma Extensions_Visible with value "False" cannot
6419 -- appear in a class-wide conversion (SPARK RM 6.1.7(3)). Do not check
6420 -- internally generated expressions.
6422 if Is_Class_Wide_Type (Typ)
6423 and then Comes_From_Source (Expr)
6424 and then Is_EVF_Expression (Expr)
6427 ("formal parameter cannot be converted to class-wide type when "
6428 & "Extensions_Visible is False", Expr);
6431 -- Perform special checking for access to mutably tagged type since they
6432 -- are not compatible with interfaces.
6434 if Is_Access_Type (Typ)
6435 and then Is_Access_Type (Etype (Expr))
6436 and then not Error_Posted (N)
6439 if Is_Mutably_Tagged_Type (Directly_Designated_Type (Typ))
6440 and then Is_Interface (Directly_Designated_Type (Etype (Expr)))
6443 ("argument of conversion to mutably tagged access type cannot "
6444 & "be access to interface", Expr);
6446 elsif Is_Mutably_Tagged_Type (Directly_Designated_Type (Etype (Expr)))
6447 and then Is_Interface (Directly_Designated_Type (Typ))
6450 ("argument of conversion to interface access type cannot "
6451 & "be access to mutably tagged type", Expr);
6454 end Analyze_Type_Conversion;
6456 ----------------------
6457 -- Analyze_Unary_Op --
6458 ----------------------
6460 procedure Analyze_Unary_Op (N : Node_Id) is
6461 R : constant Node_Id := Right_Opnd (N);
6466 Set_Etype (N, Any_Type);
6467 Candidate_Type := Empty;
6469 Analyze_Expression (R);
6471 -- If the entity is already set, the node is the instantiation of a
6472 -- generic node with a non-local reference, or was manufactured by a
6473 -- call to Make_Op_xxx. In either case the entity is known to be valid,
6474 -- and we do not need to collect interpretations, instead we just get
6475 -- the single possible interpretation.
6477 if Present (Entity (N)) then
6478 Op_Id := Entity (N);
6480 if Ekind (Op_Id) = E_Operator then
6481 Find_Unary_Types (R, Op_Id, N);
6483 Add_One_Interp (N, Op_Id, Etype (Op_Id));
6487 Op_Id := Get_Name_Entity_Id (Chars (N));
6488 while Present (Op_Id) loop
6489 if Ekind (Op_Id) = E_Operator then
6490 if No (Next_Entity (First_Entity (Op_Id))) then
6491 Find_Unary_Types (R, Op_Id, N);
6494 elsif Is_Overloadable (Op_Id) then
6495 Analyze_User_Defined_Unary_Op (N, Op_Id);
6498 Op_Id := Homonym (Op_Id);
6503 end Analyze_Unary_Op;
6505 ---------------------------------------
6506 -- Analyze_Unchecked_Type_Conversion --
6507 ---------------------------------------
6509 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
6510 Expr : constant Node_Id := Expression (N);
6511 Mark : constant Entity_Id := Subtype_Mark (N);
6515 Set_Etype (N, Entity (Mark));
6516 Analyze_Expression (Expr);
6517 end Analyze_Unchecked_Type_Conversion;
6519 ------------------------------------
6520 -- Analyze_User_Defined_Binary_Op --
6521 ------------------------------------
6523 procedure Analyze_User_Defined_Binary_Op
6525 Op_Id : Entity_Id) is
6528 F1 : constant Entity_Id := First_Formal (Op_Id);
6529 F2 : constant Entity_Id := Next_Formal (F1);
6532 -- Verify that Op_Id is a visible binary function. Note that since
6533 -- we know Op_Id is overloaded, potentially use visible means use
6534 -- visible for sure (RM 9.4(11)). Be prepared for previous errors.
6536 if Ekind (Op_Id) = E_Function
6537 and then Present (F2)
6538 and then (Is_Immediately_Visible (Op_Id)
6539 or else Is_Potentially_Use_Visible (Op_Id))
6540 and then (Has_Compatible_Type (Left_Opnd (N), Etype (F1))
6541 or else Etype (F1) = Any_Type)
6542 and then (Has_Compatible_Type (Right_Opnd (N), Etype (F2))
6543 or else Etype (F2) = Any_Type)
6545 Add_One_Interp (N, Op_Id, Base_Type (Etype (Op_Id)));
6547 -- If the operands are overloaded, indicate that the current
6548 -- type is a viable candidate. This is redundant in most cases,
6549 -- but for equality and comparison operators where the context
6550 -- does not impose a type on the operands, setting the proper
6551 -- type is necessary to avoid subsequent ambiguities during
6552 -- resolution, when both user-defined and predefined operators
6553 -- may be candidates.
6555 if Is_Overloaded (Left_Opnd (N)) then
6556 Set_Etype (Left_Opnd (N), Etype (F1));
6559 if Is_Overloaded (Right_Opnd (N)) then
6560 Set_Etype (Right_Opnd (N), Etype (F2));
6563 if Debug_Flag_E then
6564 Write_Str ("user defined operator ");
6565 Write_Name (Chars (Op_Id));
6566 Write_Str (" on node ");
6567 Write_Int (Int (N));
6572 end Analyze_User_Defined_Binary_Op;
6574 -----------------------------------
6575 -- Analyze_User_Defined_Unary_Op --
6576 -----------------------------------
6578 procedure Analyze_User_Defined_Unary_Op
6583 -- Only do analysis if the operator Comes_From_Source, since otherwise
6584 -- the operator was generated by the expander, and all such operators
6585 -- always refer to the operators in package Standard.
6587 if Comes_From_Source (N) then
6589 F : constant Entity_Id := First_Formal (Op_Id);
6592 -- Verify that Op_Id is a visible unary function. Note that since
6593 -- we know Op_Id is overloaded, potentially use visible means use
6594 -- visible for sure (RM 9.4(11)).
6596 if Ekind (Op_Id) = E_Function
6597 and then No (Next_Formal (F))
6598 and then (Is_Immediately_Visible (Op_Id)
6599 or else Is_Potentially_Use_Visible (Op_Id))
6600 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
6602 Add_One_Interp (N, Op_Id, Etype (Op_Id));
6606 end Analyze_User_Defined_Unary_Op;
6608 ---------------------------
6609 -- Check_Arithmetic_Pair --
6610 ---------------------------
6612 procedure Check_Arithmetic_Pair
6613 (T1, T2 : Entity_Id;
6617 Op_Name : constant Name_Id := Chars (Op_Id);
6619 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
6620 -- Check whether the fixed-point type Typ has a user-defined operator
6621 -- (multiplication or division) that should hide the corresponding
6622 -- predefined operator. Used to implement Ada 2005 AI-264, to make
6623 -- such operators more visible and therefore useful.
6625 -- If the name of the operation is an expanded name with prefix
6626 -- Standard, the predefined universal fixed operator is available,
6627 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
6633 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
6634 Bas : constant Entity_Id := Base_Type (Typ);
6635 Orig_N : constant Node_Id := Original_Node (N);
6642 -- If the universal_fixed operation is given explicitly, the rule
6643 -- concerning primitive operations of the type do not apply.
6645 if Nkind (Orig_N) = N_Function_Call
6646 and then Nkind (Name (Orig_N)) = N_Expanded_Name
6647 and then Entity (Prefix (Name (Orig_N))) = Standard_Standard
6652 -- The operation is treated as primitive if it is declared in the
6653 -- same scope as the type, and therefore on the same entity chain.
6655 Ent := Next_Entity (Typ);
6656 while Present (Ent) loop
6657 if Chars (Ent) = Chars (Op) then
6658 F1 := First_Formal (Ent);
6659 F2 := Next_Formal (F1);
6661 -- The operation counts as primitive if either operand or
6662 -- result are of the given base type, and both operands are
6663 -- fixed point types.
6665 if (Base_Type (Etype (F1)) = Bas
6666 and then Is_Fixed_Point_Type (Etype (F2)))
6669 (Base_Type (Etype (F2)) = Bas
6670 and then Is_Fixed_Point_Type (Etype (F1)))
6673 (Base_Type (Etype (Ent)) = Bas
6674 and then Is_Fixed_Point_Type (Etype (F1))
6675 and then Is_Fixed_Point_Type (Etype (F2)))
6687 -- Start of processing for Check_Arithmetic_Pair
6690 if Op_Name in Name_Op_Add | Name_Op_Subtract then
6691 if Is_Numeric_Type (T1)
6692 and then Is_Numeric_Type (T2)
6693 and then (Covers (T1 => T1, T2 => T2)
6695 Covers (T1 => T2, T2 => T1))
6696 and then Is_Effectively_Visible_Operator
6697 (N, Specific_Type (T1, T2))
6699 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
6702 elsif Op_Name in Name_Op_Multiply | Name_Op_Divide then
6703 if Is_Fixed_Point_Type (T1)
6704 and then (Is_Fixed_Point_Type (T2) or else T2 = Universal_Real)
6706 -- Add one interpretation with universal fixed result
6708 if not Has_Fixed_Op (T1, Op_Id)
6709 or else Nkind (Parent (N)) = N_Type_Conversion
6711 Add_One_Interp (N, Op_Id, Universal_Fixed);
6714 elsif Is_Fixed_Point_Type (T2)
6715 and then T1 = Universal_Real
6717 (not Has_Fixed_Op (T1, Op_Id)
6718 or else Nkind (Parent (N)) = N_Type_Conversion)
6720 Add_One_Interp (N, Op_Id, Universal_Fixed);
6722 elsif Is_Numeric_Type (T1)
6723 and then Is_Numeric_Type (T2)
6724 and then (Covers (T1 => T1, T2 => T2)
6726 Covers (T1 => T2, T2 => T1))
6727 and then Is_Effectively_Visible_Operator
6728 (N, Specific_Type (T1, T2))
6730 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
6732 elsif Is_Fixed_Point_Type (T1)
6733 and then (Base_Type (T2) = Base_Type (Standard_Integer)
6734 or else T2 = Universal_Integer)
6736 Add_One_Interp (N, Op_Id, T1);
6738 elsif T2 = Universal_Real
6739 and then Base_Type (T1) = Base_Type (Standard_Integer)
6740 and then Op_Name = Name_Op_Multiply
6742 Add_One_Interp (N, Op_Id, Any_Fixed);
6744 elsif T1 = Universal_Real
6745 and then Base_Type (T2) = Base_Type (Standard_Integer)
6747 Add_One_Interp (N, Op_Id, Any_Fixed);
6749 elsif Is_Fixed_Point_Type (T2)
6750 and then (Base_Type (T1) = Base_Type (Standard_Integer)
6751 or else T1 = Universal_Integer)
6752 and then Op_Name = Name_Op_Multiply
6754 Add_One_Interp (N, Op_Id, T2);
6756 elsif T1 = Universal_Real and then T2 = Universal_Integer then
6757 Add_One_Interp (N, Op_Id, T1);
6759 elsif T2 = Universal_Real
6760 and then T1 = Universal_Integer
6761 and then Op_Name = Name_Op_Multiply
6763 Add_One_Interp (N, Op_Id, T2);
6766 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
6768 if Is_Integer_Type (T1)
6769 and then (Covers (T1 => T1, T2 => T2)
6771 Covers (T1 => T2, T2 => T1))
6772 and then Is_Effectively_Visible_Operator
6773 (N, Specific_Type (T1, T2))
6775 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
6778 elsif Op_Name = Name_Op_Expon then
6779 if Is_Numeric_Type (T1)
6780 and then not Is_Fixed_Point_Type (T1)
6781 and then (Base_Type (T2) = Base_Type (Standard_Integer)
6782 or else T2 = Universal_Integer)
6784 Add_One_Interp (N, Op_Id, Base_Type (T1));
6787 else pragma Assert (Nkind (N) in N_Op_Shift);
6789 -- If not one of the predefined operators, the node may be one
6790 -- of the intrinsic functions. Its kind is always specific, and
6791 -- we can use it directly, rather than the name of the operation.
6793 if Is_Integer_Type (T1)
6794 and then (Base_Type (T2) = Base_Type (Standard_Integer)
6795 or else T2 = Universal_Integer)
6797 Add_One_Interp (N, Op_Id, Base_Type (T1));
6800 end Check_Arithmetic_Pair;
6802 -------------------------------
6803 -- Check_Misspelled_Selector --
6804 -------------------------------
6806 procedure Check_Misspelled_Selector
6807 (Prefix : Entity_Id;
6810 Max_Suggestions : constant := 2;
6811 Nr_Of_Suggestions : Natural := 0;
6813 Suggestion_1 : Entity_Id := Empty;
6814 Suggestion_2 : Entity_Id := Empty;
6819 -- All the components of the prefix of selector Sel are matched against
6820 -- Sel and a count is maintained of possible misspellings. When at
6821 -- the end of the analysis there are one or two (not more) possible
6822 -- misspellings, these misspellings will be suggested as possible
6825 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
6827 -- Concurrent types should be handled as well ???
6832 Comp := First_Entity (Prefix);
6833 while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
6834 if Is_Visible_Component (Comp, Sel) then
6835 if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
6836 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
6838 case Nr_Of_Suggestions is
6839 when 1 => Suggestion_1 := Comp;
6840 when 2 => Suggestion_2 := Comp;
6841 when others => null;
6849 -- Report at most two suggestions
6851 if Nr_Of_Suggestions = 1 then
6852 Error_Msg_NE -- CODEFIX
6853 ("\possible misspelling of&", Sel, Suggestion_1);
6855 elsif Nr_Of_Suggestions = 2 then
6856 Error_Msg_Node_2 := Suggestion_2;
6857 Error_Msg_NE -- CODEFIX
6858 ("\possible misspelling of& or&", Sel, Suggestion_1);
6860 end Check_Misspelled_Selector;
6866 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
6872 Num_Actuals : Natural;
6873 Num_Interps : Natural;
6874 Void_Interp_Seen : Boolean := False;
6877 pragma Warnings (Off, Boolean);
6881 Actual := First_Actual (N);
6883 while Present (Actual) loop
6884 -- Ada 2005 (AI-50217): Post an error in case of premature
6885 -- usage of an entity from the limited view.
6887 if not Analyzed (Etype (Actual))
6888 and then From_Limited_With (Etype (Actual))
6889 and then Ada_Version >= Ada_2005
6891 Error_Msg_Qual_Level := 1;
6893 ("missing with_clause for scope of imported type&",
6894 Actual, Etype (Actual));
6895 Error_Msg_Qual_Level := 0;
6898 Num_Actuals := Num_Actuals + 1;
6899 Next_Actual (Actual);
6902 -- Before listing the possible candidates, check whether this is
6903 -- a prefix of a selected component that has been rewritten as a
6904 -- parameterless function call because there is a callable candidate
6905 -- interpretation. If there is a hidden package in the list of homonyms
6906 -- of the function name (bad programming style in any case) suggest that
6907 -- this is the intended entity.
6909 if No (Parameter_Associations (N))
6910 and then Nkind (Parent (N)) = N_Selected_Component
6911 and then Nkind (Parent (Parent (N))) in N_Declaration
6912 and then Is_Overloaded (Nam)
6918 Ent := Current_Entity (Nam);
6919 while Present (Ent) loop
6920 if Ekind (Ent) = E_Package then
6922 ("no legal interpretations as function call,!", Nam);
6923 Error_Msg_NE ("\package& is not visible", N, Ent);
6925 Rewrite (Parent (N),
6926 New_Occurrence_Of (Any_Type, Sloc (N)));
6930 Ent := Homonym (Ent);
6935 -- If this is a call to an operation of a concurrent type, the failed
6936 -- interpretations have been removed from the name. Recover them now
6937 -- in order to provide full diagnostics.
6939 if Nkind (Parent (Nam)) = N_Selected_Component then
6940 Set_Entity (Nam, Empty);
6941 New_Nam := New_Copy_Tree (Parent (Nam));
6942 Set_Is_Overloaded (New_Nam, False);
6943 Set_Is_Overloaded (Selector_Name (New_Nam), False);
6944 Set_Parent (New_Nam, Parent (Parent (Nam)));
6945 Analyze_Selected_Component (New_Nam);
6946 Get_First_Interp (Selector_Name (New_Nam), X, It);
6948 Get_First_Interp (Nam, X, It);
6951 -- If the number of actuals is 2, then remove interpretations involving
6952 -- a unary "+" operator as they might yield confusing errors downstream.
6955 and then Nkind (Parent (Nam)) /= N_Selected_Component
6959 while Present (It.Nam) loop
6960 if Ekind (It.Nam) = E_Operator
6961 and then Chars (It.Nam) = Name_Op_Add
6962 and then (No (First_Formal (It.Nam))
6963 or else No (Next_Formal (First_Formal (It.Nam))))
6967 Num_Interps := Num_Interps + 1;
6970 Get_Next_Interp (X, It);
6973 if Num_Interps = 0 then
6974 Error_Msg_N ("!too many arguments in call to&", Nam);
6978 Get_First_Interp (Nam, X, It);
6981 Num_Interps := 2; -- at least
6984 -- Analyze each candidate call again with full error reporting for each
6986 if Num_Interps > 1 then
6987 Error_Msg_N ("!no candidate interpretations match the actuals:", Nam);
6990 Err_Mode := All_Errors_Mode;
6991 All_Errors_Mode := True;
6993 while Present (It.Nam) loop
6994 if Etype (It.Nam) = Standard_Void_Type then
6995 Void_Interp_Seen := True;
6998 Analyze_One_Call (N, It.Nam, True, Success);
6999 Get_Next_Interp (X, It);
7002 if Nkind (N) = N_Function_Call then
7003 Get_First_Interp (Nam, X, It);
7006 and then Ekind (Entity (Name (N))) = E_Function
7007 and then Present (Homonym (Entity (Name (N))))
7009 -- A name may appear overloaded if it has a homonym, even if that
7010 -- homonym is non-overloadable, in which case the overload list is
7011 -- in fact empty. This specialized case deserves a special message
7012 -- if the homonym is a child package.
7015 Nam : constant Node_Id := Name (N);
7016 H : constant Entity_Id := Homonym (Entity (Nam));
7019 if Ekind (H) = E_Package and then Is_Child_Unit (H) then
7020 Error_Msg_Qual_Level := 2;
7021 Error_Msg_NE ("if an entity in package& is meant, ", Nam, H);
7022 Error_Msg_NE ("\use a fully qualified name", Nam, H);
7023 Error_Msg_Qual_Level := 0;
7028 while Present (It.Nam) loop
7029 if Ekind (It.Nam) in E_Function | E_Operator then
7032 Get_Next_Interp (X, It);
7036 -- If all interpretations are procedures, this deserves a more
7037 -- precise message. Ditto if this appears as the prefix of a
7038 -- selected component, which may be a lexical error.
7041 ("\context requires function call, found procedure name", Nam);
7043 if Nkind (Parent (N)) = N_Selected_Component
7044 and then N = Prefix (Parent (N))
7046 Error_Msg_N -- CODEFIX
7047 ("\period should probably be semicolon", Parent (N));
7051 elsif Nkind (N) = N_Procedure_Call_Statement
7052 and then not Void_Interp_Seen
7054 Error_Msg_N ("\function name found in procedure call", Nam);
7057 All_Errors_Mode := Err_Mode;
7060 ---------------------------
7061 -- Find_Arithmetic_Types --
7062 ---------------------------
7064 procedure Find_Arithmetic_Types
7069 procedure Check_Right_Argument (T : Entity_Id);
7070 -- Check right operand of operator
7072 --------------------------
7073 -- Check_Right_Argument --
7074 --------------------------
7076 procedure Check_Right_Argument (T : Entity_Id) is
7081 if not Is_Overloaded (R) then
7082 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
7085 Get_First_Interp (R, I, It);
7086 while Present (It.Typ) loop
7087 Check_Arithmetic_Pair (T, It.Typ, Op_Id, N);
7088 Get_Next_Interp (I, It);
7091 end Check_Right_Argument;
7098 -- Start of processing for Find_Arithmetic_Types
7101 if not Is_Overloaded (L) then
7102 Check_Right_Argument (Etype (L));
7105 Get_First_Interp (L, I, It);
7106 while Present (It.Typ) loop
7107 Check_Right_Argument (It.Typ);
7108 Get_Next_Interp (I, It);
7111 end Find_Arithmetic_Types;
7113 ------------------------
7114 -- Find_Boolean_Types --
7115 ------------------------
7117 procedure Find_Boolean_Types
7122 procedure Check_Boolean_Pair (T1, T2 : Entity_Id);
7123 -- Check operand pair of operator
7125 procedure Check_Right_Argument (T : Entity_Id);
7126 -- Check right operand of operator
7128 ------------------------
7129 -- Check_Boolean_Pair --
7130 ------------------------
7132 procedure Check_Boolean_Pair (T1, T2 : Entity_Id) is
7136 if Valid_Boolean_Arg (T1)
7137 and then Valid_Boolean_Arg (T2)
7138 and then (Covers (T1 => T1, T2 => T2)
7139 or else Covers (T1 => T2, T2 => T1))
7141 T := Specific_Type (T1, T2);
7143 if T = Universal_Integer then
7147 -- test Is_Effectively_Visible_Operator here ???
7148 Add_One_Interp (N, Op_Id, T);
7150 end Check_Boolean_Pair;
7152 --------------------------
7153 -- Check_Right_Argument --
7154 --------------------------
7156 procedure Check_Right_Argument (T : Entity_Id) is
7161 -- Defend against previous error
7163 if Nkind (R) = N_Error then
7166 elsif not Is_Overloaded (R) then
7167 Check_Boolean_Pair (T, Etype (R));
7170 Get_First_Interp (R, I, It);
7171 while Present (It.Typ) loop
7172 Check_Boolean_Pair (T, It.Typ);
7173 Get_Next_Interp (I, It);
7176 end Check_Right_Argument;
7183 -- Start of processing for Find_Boolean_Types
7186 if not Is_Overloaded (L) then
7187 Check_Right_Argument (Etype (L));
7190 Get_First_Interp (L, I, It);
7191 while Present (It.Typ) loop
7192 Check_Right_Argument (It.Typ);
7193 Get_Next_Interp (I, It);
7196 end Find_Boolean_Types;
7198 ------------------------------------
7199 -- Find_Comparison_Equality_Types --
7200 ------------------------------------
7202 -- The context of the operator plays no role in resolving the operands,
7203 -- so that if there is more than one interpretation of the operands that
7204 -- is compatible with the comparison or equality, then the operation is
7205 -- ambiguous, but this cannot be reported at this point because there is
7206 -- no guarantee that the operation will be resolved to this operator yet.
7208 procedure Find_Comparison_Equality_Types
7213 Op_Name : constant Name_Id := Chars (Op_Id);
7214 Op_Typ : Entity_Id renames Standard_Boolean;
7216 function Try_Left_Interp (T : Entity_Id) return Entity_Id;
7217 -- Try an interpretation of the left operand with type T. Return the
7218 -- type of the interpretation of the right operand making up a valid
7219 -- operand pair, or else Any_Type if the right operand is ambiguous,
7220 -- otherwise Empty if no such pair exists.
7222 function Is_Valid_Comparison_Type (T : Entity_Id) return Boolean;
7223 -- Return true if T is a valid comparison type
7225 function Is_Valid_Equality_Type
7227 Anon_Access : Boolean) return Boolean;
7228 -- Return true if T is a valid equality type
7230 function Is_Valid_Pair (T1, T2 : Entity_Id) return Boolean;
7231 -- Return true if T1 and T2 constitute a valid pair of operand types for
7232 -- L and R respectively.
7234 ---------------------
7235 -- Try_Left_Interp --
7236 ---------------------
7238 function Try_Left_Interp (T : Entity_Id) return Entity_Id is
7242 Valid_I : Interp_Index;
7245 -- Defend against previous error
7247 if Nkind (R) = N_Error then
7250 -- Loop through the interpretations of the right operand
7252 elsif not Is_Overloaded (R) then
7253 if Is_Valid_Pair (T, Etype (R)) then
7261 Get_First_Interp (R, I, It);
7262 while Present (It.Typ) loop
7263 if Is_Valid_Pair (T, It.Typ) then
7264 -- If several interpretations are possible, disambiguate
7267 and then Base_Type (It.Typ) /= Base_Type (R_Typ)
7269 It := Disambiguate (R, Valid_I, I, Any_Type);
7271 if It = No_Interp then
7283 Get_Next_Interp (I, It);
7286 if Present (R_Typ) then
7292 end Try_Left_Interp;
7294 ------------------------------
7295 -- Is_Valid_Comparison_Type --
7296 ------------------------------
7298 function Is_Valid_Comparison_Type (T : Entity_Id) return Boolean is
7300 -- The operation must be performed in a context where the operators
7301 -- of the base type are visible.
7303 if Is_Visible_Operator (N, Base_Type (T)) then
7306 -- Save candidate type for subsequent error message, if any
7309 if Valid_Comparison_Arg (T) then
7310 Candidate_Type := T;
7316 -- Defer to the common implementation for the rest
7318 return Valid_Comparison_Arg (T);
7319 end Is_Valid_Comparison_Type;
7321 ----------------------------
7322 -- Is_Valid_Equality_Type --
7323 ----------------------------
7325 function Is_Valid_Equality_Type
7327 Anon_Access : Boolean) return Boolean
7330 -- The operation must be performed in a context where the operators
7331 -- of the base type are visible. Deal with special types used with
7332 -- access types before type resolution is done.
7334 if Ekind (T) = E_Access_Attribute_Type
7335 or else (Ekind (T) in E_Access_Subprogram_Type
7336 | E_Access_Protected_Subprogram_Type
7338 Ekind (Designated_Type (T)) /= E_Subprogram_Type)
7339 or else Is_Visible_Operator (N, Base_Type (T))
7343 -- AI95-0230: Keep restriction imposed by Ada 83 and 95, do not allow
7344 -- anonymous access types in universal_access equality operators.
7346 elsif Anon_Access then
7347 if Ada_Version < Ada_2005 then
7351 -- Save candidate type for subsequent error message, if any
7354 if Valid_Equality_Arg (T) then
7355 Candidate_Type := T;
7361 -- For the use of a "/=" operator on a tagged type, several possible
7362 -- interpretations of equality need to be considered, we don't want
7363 -- the default inequality declared in Standard to be chosen, and the
7364 -- "/=" operator will be rewritten as a negation of "=" (see the end
7365 -- of Analyze_Comparison_Equality_Op). This ensures the rewriting
7366 -- occurs during analysis rather than being delayed until expansion.
7367 -- Note that, if the node is N_Op_Ne but Op_Id is Name_Op_Eq, then we
7368 -- still proceed with the interpretation, because this indicates
7369 -- the aforementioned rewriting case where the interpretation to be
7370 -- considered is actually that of the "=" operator.
7372 if Nkind (N) = N_Op_Ne
7373 and then Op_Name /= Name_Op_Eq
7374 and then Is_Tagged_Type (T)
7378 -- Defer to the common implementation for the rest
7381 return Valid_Equality_Arg (T);
7383 end Is_Valid_Equality_Type;
7389 function Is_Valid_Pair (T1, T2 : Entity_Id) return Boolean is
7391 if Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne then
7393 Anon_Access : constant Boolean :=
7394 Is_Anonymous_Access_Type (T1)
7395 or else Is_Anonymous_Access_Type (T2);
7396 -- RM 4.5.2(9.1/2): At least one of the operands of an equality
7397 -- operator for universal_access shall be of specific anonymous
7401 if not Is_Valid_Equality_Type (T1, Anon_Access)
7402 or else not Is_Valid_Equality_Type (T2, Anon_Access)
7409 if not Is_Valid_Comparison_Type (T1)
7410 or else not Is_Valid_Comparison_Type (T2)
7416 return Covers (T1 => T1, T2 => T2)
7417 or else Covers (T1 => T2, T2 => T1)
7418 or else Is_User_Defined_Literal (L, T2)
7419 or else Is_User_Defined_Literal (R, T1);
7429 Valid_I : Interp_Index;
7431 -- Start of processing for Find_Comparison_Equality_Types
7434 -- Loop through the interpretations of the left operand
7436 if not Is_Overloaded (L) then
7437 T := Try_Left_Interp (Etype (L));
7441 Add_One_Interp (N, Op_Id, Op_Typ, Find_Unique_Type (L, R));
7449 Get_First_Interp (L, I, It);
7450 while Present (It.Typ) loop
7451 T := Try_Left_Interp (It.Typ);
7454 -- If several interpretations are possible, disambiguate
7457 and then Base_Type (It.Typ) /= Base_Type (L_Typ)
7459 It := Disambiguate (L, Valid_I, I, Any_Type);
7461 -- Note the ambiguity for later, see below
7463 if It = No_Interp then
7477 Get_Next_Interp (I, It);
7480 -- Record the operator as an interpretation of the operation if we
7481 -- have found a valid pair of types for the two operands. If we have
7482 -- found more than one such pair and did not manage to disambiguate
7483 -- them, record an "ambiguous" operator as the interpretation, that
7484 -- Disambiguate in Sem_Type will specifically recognize.
7486 if Present (L_Typ) then
7487 Set_Etype (L, L_Typ);
7488 Set_Etype (R, R_Typ);
7489 Add_One_Interp (N, Op_Id, Op_Typ, Find_Unique_Type (L, R));
7492 end Find_Comparison_Equality_Types;
7494 ------------------------------
7495 -- Find_Concatenation_Types --
7496 ------------------------------
7498 procedure Find_Concatenation_Types
7503 Is_String : constant Boolean := Nkind (L) = N_String_Literal
7505 Nkind (R) = N_String_Literal;
7506 Op_Type : constant Entity_Id := Etype (Op_Id);
7509 if Is_Array_Type (Op_Type)
7511 -- Small but very effective optimization: if at least one operand is a
7512 -- string literal, then the type of the operator must be either array
7513 -- of characters or array of strings.
7515 and then (not Is_String
7517 Is_Character_Type (Component_Type (Op_Type))
7519 Is_String_Type (Component_Type (Op_Type)))
7521 and then not Is_Limited_Type (Op_Type)
7523 and then (Has_Compatible_Type (L, Op_Type)
7525 Has_Compatible_Type (L, Component_Type (Op_Type)))
7527 and then (Has_Compatible_Type (R, Op_Type)
7529 Has_Compatible_Type (R, Component_Type (Op_Type)))
7531 Add_One_Interp (N, Op_Id, Op_Type);
7533 end Find_Concatenation_Types;
7535 -------------------------
7536 -- Find_Negation_Types --
7537 -------------------------
7539 procedure Find_Negation_Types
7544 Index : Interp_Index;
7548 if not Is_Overloaded (R) then
7549 if Etype (R) = Universal_Integer then
7550 Add_One_Interp (N, Op_Id, Any_Modular);
7551 elsif Valid_Boolean_Arg (Etype (R)) then
7552 Add_One_Interp (N, Op_Id, Etype (R));
7556 Get_First_Interp (R, Index, It);
7557 while Present (It.Typ) loop
7558 if Valid_Boolean_Arg (It.Typ) then
7559 Add_One_Interp (N, Op_Id, It.Typ);
7562 Get_Next_Interp (Index, It);
7565 end Find_Negation_Types;
7567 ------------------------------
7568 -- Find_Primitive_Operation --
7569 ------------------------------
7571 function Find_Primitive_Operation (N : Node_Id) return Boolean is
7572 Obj : constant Node_Id := Prefix (N);
7573 Op : constant Node_Id := Selector_Name (N);
7580 Set_Etype (Op, Any_Type);
7582 if Is_Access_Type (Etype (Obj)) then
7583 Typ := Designated_Type (Etype (Obj));
7588 if Is_Class_Wide_Type (Typ) then
7589 Typ := Root_Type (Typ);
7592 Prims := Primitive_Operations (Typ);
7594 Prim := First_Elmt (Prims);
7595 while Present (Prim) loop
7596 if Chars (Node (Prim)) = Chars (Op) then
7597 Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
7598 Set_Etype (N, Etype (Node (Prim)));
7604 -- Now look for class-wide operations of the type or any of its
7605 -- ancestors by iterating over the homonyms of the selector.
7608 Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
7612 Hom := Current_Entity (Op);
7613 while Present (Hom) loop
7614 if (Ekind (Hom) = E_Procedure
7616 Ekind (Hom) = E_Function)
7617 and then Scope (Hom) = Scope (Typ)
7618 and then Present (First_Formal (Hom))
7620 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
7622 (Is_Access_Type (Etype (First_Formal (Hom)))
7624 Ekind (Etype (First_Formal (Hom))) =
7625 E_Anonymous_Access_Type
7628 (Designated_Type (Etype (First_Formal (Hom)))) =
7631 Add_One_Interp (Op, Hom, Etype (Hom));
7632 Set_Etype (N, Etype (Hom));
7635 Hom := Homonym (Hom);
7639 return Etype (Op) /= Any_Type;
7640 end Find_Primitive_Operation;
7642 ----------------------
7643 -- Find_Unary_Types --
7644 ----------------------
7646 procedure Find_Unary_Types
7651 Index : Interp_Index;
7655 if not Is_Overloaded (R) then
7656 if Is_Numeric_Type (Etype (R)) then
7657 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
7661 Get_First_Interp (R, Index, It);
7662 while Present (It.Typ) loop
7663 if Is_Numeric_Type (It.Typ) then
7664 if Is_Effectively_Visible_Operator (N, Base_Type (It.Typ))
7666 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
7670 Get_Next_Interp (Index, It);
7673 end Find_Unary_Types;
7679 function Junk_Operand (N : Node_Id) return Boolean is
7683 if Error_Posted (N) then
7687 -- Get entity to be tested
7689 if Is_Entity_Name (N)
7690 and then Present (Entity (N))
7694 -- An odd case, a procedure name gets converted to a very peculiar
7695 -- function call, and here is where we detect this happening.
7697 elsif Nkind (N) = N_Function_Call
7698 and then Is_Entity_Name (Name (N))
7699 and then Present (Entity (Name (N)))
7703 -- Another odd case, there are at least some cases of selected
7704 -- components where the selected component is not marked as having
7705 -- an entity, even though the selector does have an entity
7707 elsif Nkind (N) = N_Selected_Component
7708 and then Present (Entity (Selector_Name (N)))
7710 Enode := Selector_Name (N);
7716 -- Now test the entity we got to see if it is a bad case
7718 case Ekind (Entity (Enode)) is
7721 ("package name cannot be used as operand", Enode);
7723 when Generic_Unit_Kind =>
7725 ("generic unit name cannot be used as operand", Enode);
7729 ("subtype name cannot be used as operand", Enode);
7733 ("entry name cannot be used as operand", Enode);
7737 ("procedure name cannot be used as operand", Enode);
7741 ("exception name cannot be used as operand", Enode);
7748 ("label name cannot be used as operand", Enode);
7757 --------------------
7758 -- Operator_Check --
7759 --------------------
7761 procedure Operator_Check (N : Node_Id) is
7763 Remove_Abstract_Operations (N);
7765 -- Test for case of no interpretation found for operator
7767 if Etype (N) = Any_Type then
7769 L : constant Node_Id :=
7770 (if Nkind (N) in N_Binary_Op then Left_Opnd (N) else Empty);
7771 R : constant Node_Id := Right_Opnd (N);
7774 -- If either operand has no type, then don't complain further,
7775 -- since this simply means that we have a propagated error.
7778 or else Etype (R) = Any_Type
7779 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
7781 -- For the rather unusual case where one of the operands is
7782 -- a Raise_Expression, whose initial type is Any_Type, use
7783 -- the type of the other operand.
7785 if Nkind (L) = N_Raise_Expression then
7786 Set_Etype (L, Etype (R));
7787 Set_Etype (N, Etype (R));
7789 elsif Nkind (R) = N_Raise_Expression then
7790 Set_Etype (R, Etype (L));
7791 Set_Etype (N, Etype (L));
7796 -- We explicitly check for the case of concatenation of component
7797 -- with component to avoid reporting spurious matching array types
7798 -- that might happen to be lurking in distant packages (such as
7799 -- run-time packages). This also prevents inconsistencies in the
7800 -- messages for certain ACVC B tests, which can vary depending on
7801 -- types declared in run-time interfaces. Another improvement when
7802 -- aggregates are present is to look for a well-typed operand.
7804 elsif Present (Candidate_Type)
7805 and then (Nkind (N) /= N_Op_Concat
7806 or else Is_Array_Type (Etype (L))
7807 or else Is_Array_Type (Etype (R)))
7809 if Nkind (N) = N_Op_Concat then
7810 if Etype (L) /= Any_Composite
7811 and then Is_Array_Type (Etype (L))
7813 Candidate_Type := Etype (L);
7815 elsif Etype (R) /= Any_Composite
7816 and then Is_Array_Type (Etype (R))
7818 Candidate_Type := Etype (R);
7822 Error_Msg_NE -- CODEFIX
7823 ("operator for} is not directly visible!",
7824 N, First_Subtype (Candidate_Type));
7827 U : constant Node_Id :=
7828 Cunit (Get_Source_Unit (Candidate_Type));
7830 if Unit_Is_Visible (U) then
7831 Error_Msg_N -- CODEFIX
7832 ("use clause would make operation legal!", N);
7834 Error_Msg_NE -- CODEFIX
7835 ("add with_clause and use_clause for&!",
7836 N, Defining_Entity (Unit (U)));
7841 -- If either operand is a junk operand (e.g. package name), then
7842 -- post appropriate error messages, but do not complain further.
7844 -- Note that the use of OR in this test instead of OR ELSE is
7845 -- quite deliberate, we may as well check both operands in the
7846 -- binary operator case.
7848 elsif Junk_Operand (R)
7849 or -- really mean OR here and not OR ELSE, see above
7850 (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
7854 -- The handling of user-defined literals is deferred to the second
7855 -- pass of resolution.
7857 elsif Has_Possible_User_Defined_Literal (N) then
7860 -- If we have a logical operator, one of whose operands is
7861 -- Boolean, then we know that the other operand cannot resolve to
7862 -- Boolean (since we got no interpretations), but in that case we
7863 -- pretty much know that the other operand should be Boolean, so
7864 -- resolve it that way (generating an error).
7866 elsif Nkind (N) in N_Op_And | N_Op_Or | N_Op_Xor then
7867 if Etype (L) = Standard_Boolean then
7868 Resolve (R, Standard_Boolean);
7870 elsif Etype (R) = Standard_Boolean then
7871 Resolve (L, Standard_Boolean);
7875 -- For an arithmetic operator or comparison operator, if one
7876 -- of the operands is numeric, then we know the other operand
7877 -- is not the same numeric type. If it is a non-numeric type,
7878 -- then probably it is intended to match the other operand.
7880 elsif Nkind (N) in N_Op_Add
7891 -- If Allow_Integer_Address is active, check whether the
7892 -- operation becomes legal after converting an operand.
7894 if Is_Numeric_Type (Etype (L))
7895 and then not Is_Numeric_Type (Etype (R))
7897 if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
7899 Unchecked_Convert_To (
7900 Standard_Address, Relocate_Node (L)));
7902 Unchecked_Convert_To (
7903 Standard_Address, Relocate_Node (R)));
7905 if Nkind (N) in N_Op_Ge | N_Op_Gt | N_Op_Le | N_Op_Lt then
7906 Analyze_Comparison_Equality_Op (N);
7908 Analyze_Arithmetic_Op (N);
7911 Resolve (R, Etype (L));
7916 elsif Is_Numeric_Type (Etype (R))
7917 and then not Is_Numeric_Type (Etype (L))
7919 if Address_Integer_Convert_OK (Etype (L), Etype (R)) then
7921 Unchecked_Convert_To (
7922 Standard_Address, Relocate_Node (L)));
7924 Unchecked_Convert_To (
7925 Standard_Address, Relocate_Node (R)));
7927 if Nkind (N) in N_Op_Ge | N_Op_Gt | N_Op_Le | N_Op_Lt then
7928 Analyze_Comparison_Equality_Op (N);
7930 Analyze_Arithmetic_Op (N);
7936 Resolve (L, Etype (R));
7941 elsif Allow_Integer_Address
7942 and then Is_Descendant_Of_Address (Etype (L))
7943 and then Is_Descendant_Of_Address (Etype (R))
7944 and then not Error_Posted (N)
7947 Addr_Type : constant Entity_Id := Etype (L);
7951 Unchecked_Convert_To (
7952 Standard_Address, Relocate_Node (L)));
7954 Unchecked_Convert_To (
7955 Standard_Address, Relocate_Node (R)));
7957 if Nkind (N) in N_Op_Ge | N_Op_Gt | N_Op_Le | N_Op_Lt then
7958 Analyze_Comparison_Equality_Op (N);
7960 Analyze_Arithmetic_Op (N);
7963 -- If this is an operand in an enclosing arithmetic
7964 -- operation, Convert the result as an address so that
7965 -- arithmetic folding of address can continue.
7967 if Nkind (Parent (N)) in N_Op then
7969 Unchecked_Convert_To (Addr_Type, Relocate_Node (N)));
7975 -- Under relaxed RM semantics silently replace occurrences of
7976 -- null by System.Address_Null.
7978 elsif Null_To_Null_Address_Convert_OK (N) then
7979 Replace_Null_By_Null_Address (N);
7981 if Nkind (N) in N_Op_Ge | N_Op_Gt | N_Op_Le | N_Op_Lt then
7982 Analyze_Comparison_Equality_Op (N);
7984 Analyze_Arithmetic_Op (N);
7990 -- Comparisons on A'Access are common enough to deserve a
7993 elsif Nkind (N) in N_Op_Eq | N_Op_Ne
7994 and then Ekind (Etype (L)) = E_Access_Attribute_Type
7995 and then Ekind (Etype (R)) = E_Access_Attribute_Type
7998 ("two access attributes cannot be compared directly", N);
8000 ("\use qualified expression for one of the operands",
8004 -- Another one for C programmers
8006 elsif Nkind (N) = N_Op_Concat
8007 and then Valid_Boolean_Arg (Etype (L))
8008 and then Valid_Boolean_Arg (Etype (R))
8010 Error_Msg_N ("invalid operands for concatenation", N);
8011 Error_Msg_N -- CODEFIX
8012 ("\maybe AND was meant", N);
8015 -- A special case for comparison of access parameter with null
8017 elsif Nkind (N) = N_Op_Eq
8018 and then Is_Entity_Name (L)
8019 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
8020 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
8022 and then Nkind (R) = N_Null
8024 Error_Msg_N ("access parameter is not allowed to be null", L);
8025 Error_Msg_N ("\(call would raise Constraint_Error)", L);
8028 -- Another special case for exponentiation, where the right
8029 -- operand must be Natural, independently of the base.
8031 elsif Nkind (N) = N_Op_Expon
8032 and then Is_Numeric_Type (Etype (L))
8033 and then not Is_Overloaded (R)
8035 First_Subtype (Base_Type (Etype (R))) /= Standard_Integer
8036 and then Base_Type (Etype (R)) /= Universal_Integer
8038 if Ada_Version >= Ada_2012
8039 and then Has_Dimension_System (Etype (L))
8042 ("exponent for dimensioned type must be a rational" &
8043 ", found}", R, Etype (R));
8046 ("exponent must be of type Natural, found}", R, Etype (R));
8051 elsif Nkind (N) in N_Op_Eq | N_Op_Ne then
8052 if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
8054 Unchecked_Convert_To (
8055 Standard_Address, Relocate_Node (L)));
8057 Unchecked_Convert_To (
8058 Standard_Address, Relocate_Node (R)));
8059 Analyze_Comparison_Equality_Op (N);
8062 -- Under relaxed RM semantics silently replace occurrences of
8063 -- null by System.Address_Null.
8065 elsif Null_To_Null_Address_Convert_OK (N) then
8066 Replace_Null_By_Null_Address (N);
8067 Analyze_Comparison_Equality_Op (N);
8072 -- If we fall through then just give general message
8074 Unresolved_Operator (N);
8079 ---------------------------------------
8080 -- Has_Possible_User_Defined_Literal --
8081 ---------------------------------------
8083 function Has_Possible_User_Defined_Literal (N : Node_Id) return Boolean is
8084 R : constant Node_Id := Right_Opnd (N);
8086 procedure Check_Literal_Opnd (Opnd : Node_Id);
8087 -- If an operand is a literal to which an aspect may apply,
8088 -- add the corresponding type to operator node.
8090 ------------------------
8091 -- Check_Literal_Opnd --
8092 ------------------------
8094 procedure Check_Literal_Opnd (Opnd : Node_Id) is
8096 if Nkind (Opnd) in N_Numeric_Or_String_Literal
8097 or else (Is_Entity_Name (Opnd)
8098 and then Present (Entity (Opnd))
8099 and then Is_Named_Number (Entity (Opnd)))
8101 Add_One_Interp (N, Etype (Opnd), Etype (Opnd));
8103 end Check_Literal_Opnd;
8105 -- Start of processing for Has_Possible_User_Defined_Literal
8108 if Ada_Version < Ada_2022 then
8112 Check_Literal_Opnd (R);
8114 -- Check left operand only if right one did not provide a
8115 -- possible interpretation. Note that literal types are not
8116 -- overloadable, in the sense that there is no overloadable
8117 -- entity name whose several interpretations can be used to
8118 -- indicate possible resulting types, so there is no way to
8119 -- provide more than one interpretation to the operator node.
8120 -- The choice of one operand over the other is arbitrary at
8121 -- this point, and may lead to spurious resolution when both
8122 -- operands are literals of different kinds, but the second
8123 -- pass of resolution will examine anew both operands to
8124 -- determine whether a user-defined literal may apply to
8127 if Nkind (N) in N_Binary_Op and then Etype (N) = Any_Type then
8128 Check_Literal_Opnd (Left_Opnd (N));
8131 return Etype (N) /= Any_Type;
8132 end Has_Possible_User_Defined_Literal;
8134 -----------------------------------------------
8135 -- Nondispatching_Call_To_Abstract_Operation --
8136 -----------------------------------------------
8138 procedure Nondispatching_Call_To_Abstract_Operation
8140 Abstract_Op : Entity_Id)
8142 Typ : constant Entity_Id := Etype (N);
8145 -- In an instance body, this is a runtime check, but one we know will
8146 -- fail, so give an appropriate warning. As usual this kind of warning
8147 -- is an error in SPARK mode.
8149 Error_Msg_Sloc := Sloc (Abstract_Op);
8151 if In_Instance_Body and then SPARK_Mode /= On then
8153 ("??cannot call abstract operation& declared#",
8155 Error_Msg_N ("\Program_Error [??", N);
8157 Make_Raise_Program_Error (Sloc (N),
8158 Reason => PE_Explicit_Raise));
8164 ("cannot call abstract operation& declared#",
8166 Set_Etype (N, Any_Type);
8168 end Nondispatching_Call_To_Abstract_Operation;
8170 ----------------------------------------------
8171 -- Possible_Type_For_Conditional_Expression --
8172 ----------------------------------------------
8174 function Possible_Type_For_Conditional_Expression
8175 (T1, T2 : Entity_Id) return Entity_Id
8177 function Is_Access_Protected_Subprogram_Attribute
8178 (T : Entity_Id) return Boolean;
8179 -- Return true if T is the type of an access-to-protected-subprogram
8182 function Is_Access_Subprogram_Attribute (T : Entity_Id) return Boolean;
8183 -- Return true if T is the type of an access-to-subprogram attribute
8185 ----------------------------------------------
8186 -- Is_Access_Protected_Subprogram_Attribute --
8187 ----------------------------------------------
8189 function Is_Access_Protected_Subprogram_Attribute
8190 (T : Entity_Id) return Boolean
8193 return Ekind (T) = E_Access_Protected_Subprogram_Type
8194 and then Ekind (Designated_Type (T)) /= E_Subprogram_Type;
8195 end Is_Access_Protected_Subprogram_Attribute;
8197 ------------------------------------
8198 -- Is_Access_Subprogram_Attribute --
8199 ------------------------------------
8201 function Is_Access_Subprogram_Attribute (T : Entity_Id) return Boolean is
8203 return Ekind (T) = E_Access_Subprogram_Type
8204 and then Ekind (Designated_Type (T)) /= E_Subprogram_Type;
8205 end Is_Access_Subprogram_Attribute;
8207 -- Start of processing for Possible_Type_For_Conditional_Expression
8210 -- If both types are those of similar access attributes or allocators,
8211 -- pick one of them, for example the first.
8213 if Ekind (T1) in E_Access_Attribute_Type | E_Allocator_Type
8214 and then Ekind (T2) in E_Access_Attribute_Type | E_Allocator_Type
8218 elsif Is_Access_Subprogram_Attribute (T1)
8219 and then Is_Access_Subprogram_Attribute (T2)
8221 Subtype_Conformant (Designated_Type (T1), Designated_Type (T2))
8225 elsif Is_Access_Protected_Subprogram_Attribute (T1)
8226 and then Is_Access_Protected_Subprogram_Attribute (T2)
8228 Subtype_Conformant (Designated_Type (T1), Designated_Type (T2))
8232 -- The other case to be considered is a pair of tagged types
8234 elsif Is_Tagged_Type (T1) and then Is_Tagged_Type (T2) then
8235 -- Covers performs the same checks when T1 or T2 are a CW type, so
8236 -- we don't need to do them again here.
8238 if not Is_Class_Wide_Type (T1) and then Is_Ancestor (T1, T2) then
8241 elsif not Is_Class_Wide_Type (T2) and then Is_Ancestor (T2, T1) then
8244 -- Neither type is an ancestor of the other, but they may have one in
8245 -- common, so we pick the first type as above. We could perform here
8246 -- the computation of the nearest common ancestors of T1 and T2, but
8247 -- this would require a significant amount of work and the practical
8248 -- benefit would very likely be negligible.
8254 -- Otherwise no type is possible
8259 end Possible_Type_For_Conditional_Expression;
8261 --------------------------------
8262 -- Remove_Abstract_Operations --
8263 --------------------------------
8265 procedure Remove_Abstract_Operations (N : Node_Id) is
8266 Abstract_Op : Entity_Id := Empty;
8267 Address_Descendant : Boolean := False;
8271 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
8272 -- activate this if either extensions are enabled, or if the abstract
8273 -- operation in question comes from a predefined file. This latter test
8274 -- allows us to use abstract to make operations invisible to users. In
8275 -- particular, if type Address is non-private and abstract subprograms
8276 -- are used to hide its operators, they will be truly hidden.
8278 type Operand_Position is (First_Op, Second_Op);
8279 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
8281 procedure Remove_Address_Interpretations (Op : Operand_Position);
8282 -- Ambiguities may arise when the operands are literal and the address
8283 -- operations in s-auxdec are visible. In that case, remove the
8284 -- interpretation of a literal as Address, to retain the semantics
8285 -- of Address as a private type.
8287 ------------------------------------
8288 -- Remove_Address_Interpretations --
8289 ------------------------------------
8291 procedure Remove_Address_Interpretations (Op : Operand_Position) is
8295 if Is_Overloaded (N) then
8296 Get_First_Interp (N, I, It);
8297 while Present (It.Nam) loop
8298 Formal := First_Entity (It.Nam);
8300 if Op = Second_Op then
8301 Next_Entity (Formal);
8304 if Is_Descendant_Of_Address (Etype (Formal)) then
8305 Address_Descendant := True;
8309 Get_Next_Interp (I, It);
8312 end Remove_Address_Interpretations;
8314 -- Start of processing for Remove_Abstract_Operations
8317 if Is_Overloaded (N) then
8318 if Debug_Flag_V then
8319 Write_Line ("Remove_Abstract_Operations: ");
8320 Write_Overloads (N);
8323 Get_First_Interp (N, I, It);
8325 while Present (It.Nam) loop
8326 if Is_Overloadable (It.Nam)
8327 and then Is_Abstract_Subprogram (It.Nam)
8328 and then not Is_Dispatching_Operation (It.Nam)
8330 Abstract_Op := It.Nam;
8332 if Is_Descendant_Of_Address (It.Typ) then
8333 Address_Descendant := True;
8337 -- In Ada 2005, this operation does not participate in overload
8338 -- resolution. If the operation is defined in a predefined
8339 -- unit, it is one of the operations declared abstract in some
8340 -- variants of System, and it must be removed as well.
8342 elsif Ada_Version >= Ada_2005
8343 or else In_Predefined_Unit (It.Nam)
8350 Get_Next_Interp (I, It);
8353 if No (Abstract_Op) then
8355 -- If some interpretation yields an integer type, it is still
8356 -- possible that there are address interpretations. Remove them
8357 -- if one operand is a literal, to avoid spurious ambiguities
8358 -- on systems where Address is a visible integer type.
8360 if Is_Overloaded (N)
8361 and then Nkind (N) in N_Op
8362 and then Is_Integer_Type (Etype (N))
8364 if Nkind (N) in N_Binary_Op then
8365 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
8366 Remove_Address_Interpretations (Second_Op);
8368 elsif Nkind (Left_Opnd (N)) = N_Integer_Literal then
8369 Remove_Address_Interpretations (First_Op);
8374 elsif Nkind (N) in N_Op then
8376 -- Remove interpretations that treat literals as addresses. This
8377 -- is never appropriate, even when Address is defined as a visible
8378 -- Integer type. The reason is that we would really prefer Address
8379 -- to behave as a private type, even in this case. If Address is a
8380 -- visible integer type, we get lots of overload ambiguities.
8382 if Nkind (N) in N_Binary_Op then
8384 U1 : constant Boolean :=
8385 Present (Universal_Interpretation (Right_Opnd (N)));
8386 U2 : constant Boolean :=
8387 Present (Universal_Interpretation (Left_Opnd (N)));
8391 Remove_Address_Interpretations (Second_Op);
8395 Remove_Address_Interpretations (First_Op);
8398 if not (U1 and U2) then
8400 -- Remove corresponding predefined operator, which is
8401 -- always added to the overload set.
8403 Get_First_Interp (N, I, It);
8404 while Present (It.Nam) loop
8405 if Scope (It.Nam) = Standard_Standard
8406 and then Base_Type (It.Typ) =
8407 Base_Type (Etype (Abstract_Op))
8412 Get_Next_Interp (I, It);
8415 elsif Is_Overloaded (N)
8416 and then Present (Univ_Type)
8418 -- If both operands have a universal interpretation,
8419 -- it is still necessary to remove interpretations that
8420 -- yield Address. Any remaining ambiguities will be
8421 -- removed in Disambiguate.
8423 Get_First_Interp (N, I, It);
8424 while Present (It.Nam) loop
8425 if Is_Descendant_Of_Address (It.Typ) then
8428 elsif not Is_Type (It.Nam) then
8429 Set_Entity (N, It.Nam);
8432 Get_Next_Interp (I, It);
8438 elsif Nkind (N) = N_Function_Call
8440 (Nkind (Name (N)) = N_Operator_Symbol
8442 (Nkind (Name (N)) = N_Expanded_Name
8444 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
8448 Arg1 : constant Node_Id := First (Parameter_Associations (N));
8449 U1 : constant Boolean :=
8450 Present (Universal_Interpretation (Arg1));
8451 U2 : constant Boolean :=
8452 Present (Next (Arg1)) and then
8453 Present (Universal_Interpretation (Next (Arg1)));
8457 Remove_Address_Interpretations (First_Op);
8461 Remove_Address_Interpretations (Second_Op);
8464 if not (U1 and U2) then
8465 Get_First_Interp (N, I, It);
8466 while Present (It.Nam) loop
8467 if Scope (It.Nam) = Standard_Standard
8468 and then It.Typ = Base_Type (Etype (Abstract_Op))
8473 Get_Next_Interp (I, It);
8479 -- If the removal has left no valid interpretations, emit an error
8480 -- message now and label node as illegal.
8482 if Present (Abstract_Op) then
8483 Get_First_Interp (N, I, It);
8487 -- Removal of abstract operation left no viable candidate
8489 Nondispatching_Call_To_Abstract_Operation (N, Abstract_Op);
8491 -- In Ada 2005, an abstract operation may disable predefined
8492 -- operators. Since the context is not yet known, we mark the
8493 -- predefined operators as potentially hidden. Do not include
8494 -- predefined operators when addresses are involved since this
8495 -- case is handled separately.
8497 elsif Ada_Version >= Ada_2005 and then not Address_Descendant then
8498 while Present (It.Nam) loop
8499 if Is_Numeric_Type (It.Typ)
8500 and then Scope (It.Typ) = Standard_Standard
8501 and then Ekind (It.Nam) = E_Operator
8503 Set_Abstract_Op (I, Abstract_Op);
8506 Get_Next_Interp (I, It);
8511 if Debug_Flag_V then
8512 Write_Line ("Remove_Abstract_Operations done: ");
8513 Write_Overloads (N);
8516 end Remove_Abstract_Operations;
8518 ----------------------------
8519 -- Try_Container_Indexing --
8520 ----------------------------
8522 function Try_Container_Indexing
8525 Exprs : List_Id) return Boolean
8527 Heuristic : Boolean := False;
8528 Pref_Typ : Entity_Id := Etype (Prefix);
8530 function Constant_Indexing_OK return Boolean;
8531 -- Determines whether the Constant_Indexing aspect has been specified
8532 -- for the type of the prefix and can be interpreted as constant
8533 -- indexing; that is, there is no Variable_Indexing defined for the
8534 -- type, or else the node is not a target of an assignment, or an
8535 -- actual for an IN OUT or OUT formal, or the name in an object
8536 -- renaming (RM 4.1.6 (12/3..15/3)).
8538 -- Given that prefix notation calls have not yet been resolved, if the
8539 -- type of the prefix has both aspects present (Constant_Indexing and
8540 -- Variable_Indexing), and context analysis performed by this routine
8541 -- identifies a potential prefix notation call (i.e., an N_Selected_
8542 -- Component node), this function may rely on heuristics to decide
8543 -- between constant or variable indexing. In such cases, if the
8544 -- decision is later found to be incorrect, Try_Container_Indexing
8545 -- will retry using the alternative indexing aspect.
8547 -- When heuristics are used to compute the result of this function
8548 -- the behavior of Try_Container_Indexing might not be strictly
8549 -- following the rules of the RM.
8551 function Indexing_Interpretations
8553 Aspect_Kind : Aspect_Id) return Node_Id;
8554 -- Return a set of interpretations reflecting all of the functions
8555 -- associated with an indexing aspect of type T of the given kind.
8557 function Try_Indexing_Function
8558 (Func_Name : Node_Id;
8559 Assoc : List_Id) return Entity_Id;
8560 -- Build a call to the given indexing function name with the given
8561 -- parameter associations; if there are several indexing functions
8562 -- the call is analyzed for each of the interpretation; if there are
8563 -- several successfull candidates, resolution is handled by result.
8564 -- Return the Etype of the built function call.
8566 --------------------------
8567 -- Constant_Indexing_OK --
8568 --------------------------
8570 function Constant_Indexing_OK return Boolean is
8572 function Expr_Matches_In_Formal
8574 Subp_Call : Node_Id;
8576 Skip_Controlling_Formal : Boolean := False) return Boolean;
8577 -- Find formal corresponding to given indexed component that is an
8578 -- actual in a call. Note that the enclosing subprogram call has not
8579 -- been analyzed yet, and the parameter list is not normalized, so
8580 -- that if the argument is a parameter association we must match it
8581 -- by name and not by position. In the traversal up the tree done by
8582 -- Constant_Indexing_OK, the previous node in the traversal (that is,
8583 -- the actual parameter used to ascend to the subprogram call node),
8584 -- is passed to this function in formal Param, and it is used to
8585 -- determine wether the argument is passed by name or by position.
8586 -- Skip_Controlling_Formal is set to True to skip the first formal
8589 procedure Handle_Selected_Component
8590 (Current_Node : Node_Id;
8592 Candidate : out Entity_Id;
8593 Is_Constant_Idx : out Boolean);
8594 -- Current_Node is the current node climbing up the tree. Determine
8595 -- if Sel_Comp is a candidate for a prefixed call using constant
8596 -- indexing; if no candidate is found Candidate is returned Empty
8597 -- and Is_Constant_Idx is returned False.
8599 function Has_IN_Mode (Formal : Node_Id) return Boolean is
8600 (Ekind (Formal) = E_In_Parameter);
8601 -- Return True if the given formal has mode IN
8603 ----------------------------
8604 -- Expr_Matches_In_Formal --
8605 ----------------------------
8607 function Expr_Matches_In_Formal
8609 Subp_Call : Node_Id;
8611 Skip_Controlling_Formal : Boolean := False) return Boolean
8613 pragma Assert (Nkind (Subp_Call) in N_Subprogram_Call);
8615 Actual : Node_Id := First (Parameter_Associations (Subp_Call));
8616 Formal : Node_Id := First_Formal (Subp);
8619 if Skip_Controlling_Formal then
8620 Next_Formal (Formal);
8623 -- Match by position
8625 if Nkind (Param) /= N_Parameter_Association then
8626 while Present (Actual) and then Present (Formal) loop
8627 exit when Actual = Param;
8630 if Present (Formal) then
8631 Next_Formal (Formal);
8633 -- Otherwise this is a parameter mismatch, the error is
8634 -- reported elsewhere, or else variable indexing is implied.
8644 while Present (Formal) loop
8645 exit when Chars (Formal) = Chars (Selector_Name (Param));
8646 Next_Formal (Formal);
8654 return Present (Formal) and then Has_IN_Mode (Formal);
8655 end Expr_Matches_In_Formal;
8657 -------------------------------
8658 -- Handle_Selected_Component --
8659 -------------------------------
8661 procedure Handle_Selected_Component
8662 (Current_Node : Node_Id;
8664 Candidate : out Entity_Id;
8665 Is_Constant_Idx : out Boolean)
8667 procedure Search_Constant_Interpretation
8669 Target_Name : Node_Id;
8670 Candidate : out Entity_Id;
8671 Is_Unique : out Boolean;
8672 Unique_Mode : out Boolean);
8673 -- Given a subprogram call, search in the homonyms chain for
8674 -- visible (or potentially visible) dispatching primitives that
8675 -- have at least one formal. Candidate is the entity of the first
8676 -- found candidate; Is_Unique is returned True when the mode of
8677 -- the first formal of all the candidates match. If no candidate
8678 -- is found the out parameter Candidate is returned Empty, and
8679 -- Is_Unique is returned False.
8681 procedure Search_Enclosing_Call
8682 (Call_Node : out Node_Id;
8683 Prev_Node : out Node_Id);
8684 -- Climb up to the tree looking for an enclosing subprogram call
8685 -- of a prefixed notation call. If found then the Call_Node and
8686 -- its Prev_Node in such traversal are returned; otherwise
8687 -- Call_Node and Prev_Node are returned Empty.
8689 ------------------------------------
8690 -- Search_Constant_Interpretation --
8691 ------------------------------------
8693 procedure Search_Constant_Interpretation
8695 Target_Name : Node_Id;
8696 Candidate : out Entity_Id;
8697 Is_Unique : out Boolean;
8698 Unique_Mode : out Boolean)
8700 Constant_Idx : Boolean;
8701 In_Proc_Call : constant Boolean :=
8704 Nkind (Call) = N_Procedure_Call_Statement;
8705 Kind : constant Entity_Kind :=
8706 (if In_Proc_Call then E_Procedure
8708 Target_Subp : constant Entity_Id :=
8709 Current_Entity (Target_Name);
8713 Unique_Mode := False;
8715 if Present (Target_Subp) then
8717 Hom : Entity_Id := Target_Subp;
8720 while Present (Hom) loop
8721 if Is_Overloadable (Hom)
8722 and then Is_Dispatching_Operation (Hom)
8724 (Is_Immediately_Visible (Scope (Hom))
8726 Is_Potentially_Use_Visible (Scope (Hom)))
8727 and then Ekind (Hom) = Kind
8728 and then Present (First_Formal (Hom))
8730 if No (Candidate) then
8733 Unique_Mode := True;
8735 Has_IN_Mode (First_Formal (Candidate));
8740 if Ekind (First_Formal (Hom))
8741 /= Ekind (First_Formal (Candidate))
8742 or else Has_IN_Mode (First_Formal (Hom))
8745 Unique_Mode := False;
8751 Hom := Homonym (Hom);
8755 end Search_Constant_Interpretation;
8757 ---------------------------
8758 -- Search_Enclosing_Call --
8759 ---------------------------
8761 procedure Search_Enclosing_Call
8762 (Call_Node : out Node_Id;
8763 Prev_Node : out Node_Id)
8765 Prev : Node_Id := Current_Node;
8766 Par : Node_Id := Parent (N);
8770 and then Nkind (Par) not in N_Subprogram_Call
8771 | N_Handled_Sequence_Of_Statements
8772 | N_Assignment_Statement
8773 | N_Iterator_Specification
8774 | N_Object_Declaration
8779 | N_Simple_Return_Statement
8782 Par := Parent (Par);
8786 and then Nkind (Par) in N_Subprogram_Call
8787 and then Nkind (Name (Par)) = N_Selected_Component
8795 end Search_Enclosing_Call;
8799 Is_Unique : Boolean;
8800 Unique_Mode : Boolean;
8801 Call_Node : Node_Id;
8802 Prev_Node : Node_Id;
8804 -- Start of processing for Handle_Selected_Component
8807 pragma Assert (Nkind (Sel_Comp) = N_Selected_Component);
8809 -- Climb up the tree starting from Current_Node searching for the
8810 -- enclosing subprogram call of a prefixed notation call.
8812 Search_Enclosing_Call (Call_Node, Prev_Node);
8814 -- Search for a candidate visible (or potentially visible)
8815 -- dispatching primitive that has at least one formal, and may
8816 -- be called using the prefix notation. This must be done even
8817 -- if we did not found an enclosing call since the prefix notation
8818 -- call has not been transformed yet into a subprogram call. The
8819 -- found Call_Node (if any) is passed now to help identifying if
8820 -- the prefix notation call corresponds with a procedure call or
8823 Search_Constant_Interpretation
8825 Target_Name => Selector_Name (Sel_Comp),
8826 Candidate => Candidate,
8827 Is_Unique => Is_Unique,
8828 Unique_Mode => Unique_Mode);
8830 -- If there is no candidate to interpret this node as a prefixed
8831 -- call to a subprogram we return no candidate, and the caller
8832 -- will continue ascending in the tree.
8834 if No (Candidate) then
8835 Is_Constant_Idx := False;
8837 -- If we found an unique candidate and also found the enclosing
8838 -- call node, we differentiate two cases: either we climbed up
8839 -- the tree through the first actual parameter of the call (that
8840 -- is, the name of the selected component), or we climbed up the
8841 -- tree though another actual parameter of the prefixed call and
8842 -- we must skip the controlling formal of the call.
8845 and then Present (Call_Node)
8847 -- First actual parameter
8849 if Name (Call_Node) = Prev_Node
8850 and then Nkind (Prev_Node) = N_Selected_Component
8851 and then Nkind (Selector_Name (Prev_Node)) in N_Has_Chars
8852 and then Chars (Selector_Name (Prev_Node)) = Chars (Candidate)
8854 Is_Constant_Idx := Has_IN_Mode (First_Formal (Candidate));
8856 -- Any other actual parameter
8860 Expr_Matches_In_Formal (Candidate,
8861 Subp_Call => Call_Node,
8863 Skip_Controlling_Formal => True);
8866 -- The mode of the first formal of all the candidates match but,
8867 -- given that we have several candidates, we cannot check if
8868 -- indexing is used in the first actual parameter of the call
8869 -- or in another actual parameter. Heuristically assume here
8870 -- that indexing is used in the prefix of a call.
8872 elsif Unique_Mode then
8874 Is_Constant_Idx := Has_IN_Mode (First_Formal (Candidate));
8876 -- The target candidate subprogram has several possible
8877 -- interpretations; we don't know what to do with an
8878 -- N_Selected_Component node for a prefixed notation call
8879 -- to AA.BB that has several candidate targets and it has
8880 -- not yet been resolved. For now we maintain the
8881 -- behavior that we have had so far; to be improved???
8886 if Nkind (Call_Node) = N_Procedure_Call_Statement then
8887 Is_Constant_Idx := False;
8889 -- For function calls we rely on the mode of the
8890 -- first formal of the first found candidate???
8893 Is_Constant_Idx := Has_IN_Mode (First_Formal (Candidate));
8896 end Handle_Selected_Component;
8900 Asp_Constant : constant Node_Id :=
8901 Find_Value_Of_Aspect (Pref_Typ,
8902 Aspect_Constant_Indexing);
8903 Asp_Variable : constant Node_Id :=
8904 Find_Value_Of_Aspect (Pref_Typ,
8905 Aspect_Variable_Indexing);
8908 -- Start of processing for Constant_Indexing_OK
8911 if No (Asp_Constant) then
8914 -- It is interpreted as constant indexing when the prefix has the
8915 -- Constant_Indexing aspect and the Variable_Indexing aspect is not
8916 -- specified for the type of the prefix.
8918 elsif No (Asp_Variable) then
8921 -- It is interpreted as constant indexing when the prefix denotes
8924 elsif not Is_Variable (Prefix) then
8928 -- Both aspects are present
8930 pragma Assert (Present (Asp_Constant) and Present (Asp_Variable));
8932 -- The prefix must be interpreted as a constant indexing when it
8933 -- is used within a primary where a name denoting a constant is
8937 while Present (Par) loop
8939 -- Avoid climbing more than needed
8941 exit when Nkind (Parent (Par)) in N_Iterator_Specification
8942 | N_Handled_Sequence_Of_Statements;
8944 if Nkind (Parent (Par)) in N_Case_Statement
8948 | N_Simple_Return_Statement
8952 -- It is not interpreted as constant indexing for the variable
8953 -- name in the LHS of an assignment.
8955 elsif Nkind (Parent (Par)) = N_Assignment_Statement then
8956 return Par /= Name (Parent (Par));
8958 -- The call may be overloaded, in which case we assume that its
8959 -- resolution does not depend on the type of the parameter that
8960 -- includes the indexing operation because we cannot invoke
8961 -- Preanalyze_And_Resolve (since it would cause a never-ending
8964 elsif Nkind (Parent (Par)) in N_Subprogram_Call then
8966 -- Regular subprogram call
8968 -- It is not interpreted as constant indexing for the name
8969 -- used for an OUT or IN OUT parameter.
8971 -- We should look for an interpretation with the proper
8972 -- number of formals, and determine whether it is an
8973 -- In_Parameter, but for now we examine the formal that
8974 -- corresponds to the indexing, and assume that variable
8975 -- indexing is required if some interpretation has an
8976 -- assignable formal at that position. Still does not
8977 -- cover the most complex cases ???
8979 if Is_Entity_Name (Name (Parent (Par))) then
8980 if Is_Overloaded (Name (Parent (Par))) then
8982 Proc : constant Node_Id := Name (Parent (Par));
8987 Get_First_Interp (Proc, I, It);
8988 while Present (It.Nam) loop
8989 if not Expr_Matches_In_Formal
8991 Subp_Call => Parent (Par),
8997 Get_Next_Interp (I, It);
9000 -- All interpretations have a matching in-mode formal
9007 Proc : Entity_Id := Entity (Name (Parent (Par)));
9010 -- If this is an indirect call, get formals from
9013 if Is_Access_Subprogram_Type (Etype (Proc)) then
9014 Proc := Designated_Type (Etype (Proc));
9017 return Expr_Matches_In_Formal
9019 Subp_Call => Parent (Par),
9024 -- Continue climbing
9026 elsif Nkind (Name (Parent (Par))) = N_Explicit_Dereference then
9029 -- Not a regular call; we know that we are in a subprogram
9030 -- call, we also know that the name of the call may be a
9031 -- prefixed call, and we know the name of the target
9032 -- subprogram. Search for an unique target candidate in the
9035 elsif Nkind (Name (Parent (Par))) = N_Selected_Component then
9037 Candidate : Entity_Id;
9038 Is_Constant_Idx : Boolean;
9041 Handle_Selected_Component
9042 (Current_Node => Par,
9043 Sel_Comp => Name (Parent (Par)),
9044 Candidate => Candidate,
9045 Is_Constant_Idx => Is_Constant_Idx);
9047 if Present (Candidate) then
9048 return Is_Constant_Idx;
9050 -- Continue climbing
9058 -- It is not interpreted as constant indexing for the name in
9059 -- an object renaming.
9061 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
9064 -- If the indexed component is a prefix it may be an actual of
9065 -- of a prefixed call.
9067 elsif Nkind (Parent (Par)) = N_Selected_Component then
9069 Candidate : Entity_Id;
9070 Is_Constant_Idx : Boolean;
9073 Handle_Selected_Component
9074 (Current_Node => Par,
9075 Sel_Comp => Parent (Par),
9076 Candidate => Candidate,
9077 Is_Constant_Idx => Is_Constant_Idx);
9079 if Present (Candidate) then
9080 return Is_Constant_Idx;
9082 -- Continue climbing
9089 elsif Nkind (Par) in N_Op then
9093 Par := Parent (Par);
9096 -- It is not interpreted as constant indexing when both aspects
9097 -- are present (RM 4.1.6(13/3)).
9100 end Constant_Indexing_OK;
9102 ------------------------------
9103 -- Indexing_Interpretations --
9104 ------------------------------
9106 function Indexing_Interpretations
9108 Aspect_Kind : Aspect_Id) return Node_Id
9110 pragma Assert (Aspect_Kind in Aspect_Constant_Indexing
9111 | Aspect_Variable_Indexing);
9113 Indexing_Aspect : constant Node_Id := Find_Aspect (T, Aspect_Kind);
9114 Indexing_Func_Elmt : Elmt_Id;
9115 Subp_Id : Entity_Id;
9116 Indexing_Func : Node_Id := Empty;
9119 if No (Indexing_Aspect)
9120 -- Protect against the case where there was an error on the aspect
9121 or else No (Aspect_Subprograms (Indexing_Aspect))
9126 Indexing_Func_Elmt :=
9127 First_Elmt (Aspect_Subprograms (Indexing_Aspect));
9129 pragma Assert (Present (Indexing_Func_Elmt));
9131 while Present (Indexing_Func_Elmt) loop
9132 Subp_Id := Node (Indexing_Func_Elmt);
9134 if Present (Indexing_Func) then
9135 Add_One_Interp (Indexing_Func, Subp_Id, Etype (Subp_Id));
9137 -- Otherwise this is the first interpretation. Create a
9138 -- reference where all remaining interpretations will be
9142 Indexing_Func := New_Occurrence_Of (Subp_Id, Sloc (N));
9145 Next_Elmt (Indexing_Func_Elmt);
9148 return Indexing_Func;
9149 end Indexing_Interpretations;
9151 ---------------------------
9152 -- Try_Indexing_Function --
9153 ---------------------------
9155 function Try_Indexing_Function
9156 (Func_Name : Node_Id;
9157 Assoc : List_Id) return Entity_Id
9159 Loc : constant Source_Ptr := Sloc (N);
9164 if not Is_Overloaded (Func_Name) then
9165 Func := Entity (Func_Name);
9168 Make_Function_Call (Loc,
9169 Name => New_Occurrence_Of (Func, Loc),
9170 Parameter_Associations => Assoc);
9172 Set_Parent (Indexing, Parent (N));
9173 Set_Generalized_Indexing (N, Indexing);
9175 Set_Etype (N, Etype (Indexing));
9177 -- If the return type of the indexing function is a reference
9178 -- type, add the dereference as a possible interpretation. Note
9179 -- that the indexing aspect may be a function that returns the
9180 -- element type with no intervening implicit dereference, and
9181 -- that the reference discriminant is not the first discriminant.
9183 if Has_Discriminants (Etype (Func)) then
9184 Check_Implicit_Dereference (N, Etype (Func));
9188 -- If there are multiple indexing functions, build a function
9189 -- call and analyze it for each of the possible interpretations.
9192 Make_Function_Call (Loc,
9194 Make_Identifier (Loc, Chars (Func_Name)),
9195 Parameter_Associations => Assoc);
9196 Set_Parent (Indexing, Parent (N));
9197 Set_Generalized_Indexing (N, Indexing);
9198 Set_Etype (N, Any_Type);
9199 Set_Etype (Name (Indexing), Any_Type);
9207 Get_First_Interp (Func_Name, I, It);
9208 Set_Etype (Indexing, Any_Type);
9210 -- Analyze each candidate function with the given actuals
9212 while Present (It.Nam) loop
9213 Analyze_One_Call (Indexing, It.Nam, False, Success);
9214 Get_Next_Interp (I, It);
9217 -- If there are several successful candidates, resolution will
9218 -- be by result. Mark the interpretations of the function name
9221 if Is_Overloaded (Indexing) then
9222 Get_First_Interp (Indexing, I, It);
9224 while Present (It.Nam) loop
9225 Add_One_Interp (Name (Indexing), It.Nam, It.Typ);
9226 Get_Next_Interp (I, It);
9230 Set_Etype (Name (Indexing), Etype (Indexing));
9233 -- Now add the candidate interpretations to the indexing node
9234 -- itself, to be replaced later by the function call.
9236 if Is_Overloaded (Name (Indexing)) then
9237 Get_First_Interp (Name (Indexing), I, It);
9239 while Present (It.Nam) loop
9240 Add_One_Interp (N, It.Nam, It.Typ);
9242 -- Add dereference interpretation if the result type has
9243 -- implicit reference discriminants.
9245 if Has_Discriminants (Etype (It.Nam)) then
9246 Check_Implicit_Dereference (N, Etype (It.Nam));
9249 Get_Next_Interp (I, It);
9253 Set_Etype (N, Etype (Name (Indexing)));
9255 if Has_Discriminants (Etype (N)) then
9256 Check_Implicit_Dereference (N, Etype (N));
9262 return Etype (Indexing);
9263 end Try_Indexing_Function;
9267 Loc : constant Source_Ptr := Sloc (N);
9270 Func_Name : Node_Id;
9271 Idx_Type : Entity_Id;
9273 -- Start of processing for Try_Container_Indexing
9276 -- Node may have been analyzed already when testing for a prefixed
9277 -- call, in which case do not redo analysis.
9279 if Present (Generalized_Indexing (N)) then
9282 -- Old language version or unknown type require no action
9284 elsif Ada_Version < Ada_2012
9285 or else Pref_Typ = Any_Type
9290 -- An explicit dereference needs to be created in the case of a prefix
9291 -- that's an access.
9293 -- It seems that this should be done elsewhere, but not clear where that
9294 -- should happen. Normally Insert_Explicit_Dereference is called via
9295 -- Resolve_Implicit_Dereference, called from Resolve_Indexed_Component,
9296 -- but that won't be called in this case because we transform the
9297 -- indexing to a call. Resolve_Call.Check_Prefixed_Call takes care of
9298 -- implicit dereferencing and referencing on prefixed calls, but that
9299 -- would be too late, even if we expanded to a prefix call, because
9300 -- Process_Indexed_Component will flag an error before the resolution
9303 if Is_Access_Type (Pref_Typ) then
9304 Pref_Typ := Implicitly_Designated_Type (Pref_Typ);
9305 Insert_Explicit_Dereference (Prefix);
9306 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
9309 C_Type := Base_Type (Pref_Typ);
9311 -- If indexing a class-wide container, obtain indexing primitive from
9314 if Is_Class_Wide_Type (C_Type) then
9315 C_Type := Etype (C_Type);
9318 -- Check whether the type has a specified indexing aspect
9322 -- The context is suitable for constant indexing, so obtain the name
9323 -- of the indexing functions from aspect Constant_Indexing.
9325 if Constant_Indexing_OK then
9327 Indexing_Interpretations (C_Type, Aspect_Constant_Indexing);
9330 -- Otherwise attempt variable indexing
9332 if No (Func_Name) then
9334 Indexing_Interpretations (C_Type, Aspect_Variable_Indexing);
9337 -- The type is not subject to either form of indexing, therefore the
9338 -- indexed component does not denote container indexing. If this is a
9339 -- true error, it is diagnosed by the caller.
9341 if No (Func_Name) then
9343 -- The prefix itself may be an indexing of a container. Rewrite it
9344 -- as such and retry.
9346 if Has_Implicit_Dereference (Pref_Typ) then
9347 Build_Explicit_Dereference
9348 (Prefix, Get_Reference_Discriminant (Pref_Typ));
9349 return Try_Container_Indexing (N, Prefix, Exprs);
9351 -- Otherwise this is definitely not container indexing
9357 -- Handle cascaded errors
9359 elsif No (Entity (Func_Name)) then
9363 Assoc := New_List (Relocate_Node (Prefix));
9365 -- A generalized indexing may have nore than one index expression, so
9366 -- transfer all of them to the argument list to be used in the call.
9367 -- Note that there may be named associations, in which case the node
9368 -- was rewritten earlier as a call, and has been transformed back into
9369 -- an indexed expression to share the following processing.
9371 -- The generalized indexing node is the one on which analysis and
9372 -- resolution take place. Before expansion the original node is replaced
9373 -- with the generalized indexing node, which is a call, possibly with a
9374 -- dereference operation.
9376 -- Create argument list for function call that represents generalized
9377 -- indexing. Note that indices (i.e. actuals) may themselves be
9385 Arg := First (Exprs);
9386 while Present (Arg) loop
9387 New_Arg := Relocate_Node (Arg);
9389 -- The arguments can be parameter associations, in which case the
9390 -- explicit actual parameter carries the overloadings.
9392 if Nkind (New_Arg) /= N_Parameter_Association then
9393 Save_Interps (Arg, New_Arg);
9396 Append (New_Arg, Assoc);
9401 Idx_Type := Try_Indexing_Function (Func_Name, Assoc);
9403 -- Last chance handling for heuristics: Given that prefix notation
9404 -- calls have not yet been resolved, when the type of the prefix has
9405 -- both operational aspects present (Constant_Indexing and Variable_
9406 -- Indexing), and the analysis of the context identified a potential
9407 -- prefix notation call (i.e. an N_Selected_Component node), the
9408 -- evaluation of Constant_Indexing_OK is based on heuristics; in such
9409 -- case, if the chosen indexing approach is noticed now to be wrong
9410 -- we retry with the other alternative before leaving.
9412 -- Retrying means that the heuristic decision taken when analyzing
9413 -- the context failed in this case, and therefore we should adjust
9414 -- the code of Handle_Selected_Component to improve identification
9415 -- of prefix notation calls. This last chance handling handler is
9416 -- left here for the purpose of improving such routine because it
9417 -- proved to be usefull for identified such cases when the function
9418 -- Handle_Selected_Component was added.
9420 if Idx_Type = Any_Type and then Heuristic then
9422 Tried_Func_Name : constant Node_Id := Func_Name;
9426 Indexing_Interpretations (C_Type,
9427 Aspect_Constant_Indexing);
9429 if Present (Func_Name)
9430 and then Func_Name /= Tried_Func_Name
9432 Idx_Type := Try_Indexing_Function (Func_Name, Assoc);
9436 Indexing_Interpretations (C_Type,
9437 Aspect_Variable_Indexing);
9439 if Present (Func_Name)
9440 and then Func_Name /= Tried_Func_Name
9442 Idx_Type := Try_Indexing_Function (Func_Name, Assoc);
9448 if Idx_Type = Any_Type then
9450 ("container cannot be indexed with&", N, Etype (First (Exprs)));
9451 Rewrite (N, New_Occurrence_Of (Any_Id, Loc));
9455 end Try_Container_Indexing;
9457 -----------------------
9458 -- Try_Indirect_Call --
9459 -----------------------
9461 function Try_Indirect_Call
9464 Typ : Entity_Id) return Boolean
9470 pragma Warnings (Off, Call_OK);
9473 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
9475 Actual := First_Actual (N);
9476 Formal := First_Formal (Designated_Type (Typ));
9477 while Present (Actual) and then Present (Formal) loop
9478 if not Has_Compatible_Type (Actual, Etype (Formal)) then
9483 Next_Formal (Formal);
9486 if No (Actual) and then No (Formal) then
9487 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
9489 -- Nam is a candidate interpretation for the name in the call,
9490 -- if it is not an indirect call.
9492 if not Is_Type (Nam)
9493 and then Is_Entity_Name (Name (N))
9495 Set_Entity (Name (N), Nam);
9503 end Try_Indirect_Call;
9505 ----------------------
9506 -- Try_Indexed_Call --
9507 ----------------------
9509 function Try_Indexed_Call
9513 Skip_First : Boolean) return Boolean
9515 Loc : constant Source_Ptr := Sloc (N);
9516 Actuals : constant List_Id := Parameter_Associations (N);
9521 Actual := First (Actuals);
9523 -- If the call was originally written in prefix form, skip the first
9524 -- actual, which is obviously not defaulted.
9530 Index := First_Index (Typ);
9531 while Present (Actual) and then Present (Index) loop
9533 -- If the parameter list has a named association, the expression
9534 -- is definitely a call and not an indexed component.
9536 if Nkind (Actual) = N_Parameter_Association then
9540 if Is_Entity_Name (Actual)
9541 and then Is_Type (Entity (Actual))
9542 and then No (Next (Actual))
9544 -- A single actual that is a type name indicates a slice if the
9545 -- type is discrete, and an error otherwise.
9547 if Is_Discrete_Type (Entity (Actual)) then
9551 Make_Function_Call (Loc,
9552 Name => Relocate_Node (Name (N))),
9554 New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
9559 Error_Msg_N ("invalid use of type in expression", Actual);
9560 Set_Etype (N, Any_Type);
9565 elsif not Has_Compatible_Type (Actual, Etype (Index)) then
9573 if No (Actual) and then No (Index) then
9574 Add_One_Interp (N, Nam, Component_Type (Typ));
9576 -- Nam is a candidate interpretation for the name in the call,
9577 -- if it is not an indirect call.
9579 if not Is_Type (Nam)
9580 and then Is_Entity_Name (Name (N))
9582 Set_Entity (Name (N), Nam);
9589 end Try_Indexed_Call;
9591 --------------------------
9592 -- Try_Object_Operation --
9593 --------------------------
9595 function Try_Object_Operation
9597 CW_Test_Only : Boolean := False;
9598 Allow_Extensions : Boolean := False) return Boolean
9600 K : constant Node_Kind := Nkind (Parent (N));
9601 Is_Subprg_Call : constant Boolean := K in N_Subprogram_Call;
9602 Loc : constant Source_Ptr := Sloc (N);
9603 Obj : constant Node_Id := Prefix (N);
9605 Subprog : constant Node_Id :=
9606 Make_Identifier (Sloc (Selector_Name (N)),
9607 Chars => Chars (Selector_Name (N)));
9608 -- Identifier on which possible interpretations will be collected
9610 Report_Error : Boolean := False;
9611 -- If no candidate interpretation matches the context, redo analysis
9612 -- with Report_Error True to provide additional information.
9615 Candidate : Entity_Id := Empty;
9616 New_Call_Node : Node_Id := Empty;
9617 Node_To_Replace : Node_Id;
9618 Obj_Type : Entity_Id := Etype (Obj);
9619 Success : Boolean := False;
9621 procedure Complete_Object_Operation
9622 (Call_Node : Node_Id;
9623 Node_To_Replace : Node_Id);
9624 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
9625 -- Call_Node, insert the object (or its dereference) as the first actual
9626 -- in the call, and complete the analysis of the call.
9628 procedure Report_Ambiguity (Op : Entity_Id);
9629 -- If a prefixed procedure call is ambiguous, indicate whether the call
9630 -- includes an implicit dereference or an implicit 'Access.
9632 procedure Transform_Object_Operation
9633 (Call_Node : out Node_Id;
9634 Node_To_Replace : out Node_Id);
9635 -- Transform Obj.Operation (X, Y, ...) into Operation (Obj, X, Y ...).
9636 -- Call_Node is the resulting subprogram call, Node_To_Replace is
9637 -- either N or the parent of N, and Subprog is a reference to the
9638 -- subprogram we are trying to match. Note that the transformation
9639 -- may be partially destructive for the parent of N, so it needs to
9640 -- be undone in the case where Try_Object_Operation returns false.
9642 function Try_Class_Wide_Operation
9643 (Call_Node : Node_Id;
9644 Node_To_Replace : Node_Id) return Boolean;
9645 -- Traverse all ancestor types looking for a class-wide subprogram for
9646 -- which the current operation is a valid non-dispatching call.
9648 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
9649 -- If prefix is overloaded, its interpretation may include different
9650 -- tagged types, and we must examine the primitive operations and the
9651 -- class-wide operations of each in order to find candidate
9652 -- interpretations for the call as a whole.
9654 function Try_Primitive_Operation
9655 (Call_Node : Node_Id;
9656 Node_To_Replace : Node_Id) return Boolean;
9657 -- Traverse the list of primitive subprograms looking for a dispatching
9658 -- operation for which the current node is a valid call.
9660 function Valid_Candidate
9663 Subp : Entity_Id) return Entity_Id;
9664 -- If the subprogram is a valid interpretation, record it, and add to
9665 -- the list of interpretations of Subprog. Otherwise return Empty.
9667 -------------------------------
9668 -- Complete_Object_Operation --
9669 -------------------------------
9671 procedure Complete_Object_Operation
9672 (Call_Node : Node_Id;
9673 Node_To_Replace : Node_Id)
9675 Control : constant Entity_Id := First_Formal (Entity (Subprog));
9676 Formal_Type : constant Entity_Id := Etype (Control);
9677 First_Actual : Node_Id;
9680 -- Place the name of the operation, with its interpretations,
9681 -- on the rewritten call.
9683 Set_Name (Call_Node, Subprog);
9685 First_Actual := First (Parameter_Associations (Call_Node));
9687 -- For cross-reference purposes, treat the new node as being in the
9688 -- source if the original one is. Set entity and type, even though
9689 -- they may be overwritten during resolution if overloaded.
9691 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
9692 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
9694 if Nkind (N) = N_Selected_Component
9695 and then not Inside_A_Generic
9697 Set_Entity (Selector_Name (N), Entity (Subprog));
9698 Set_Etype (Selector_Name (N), Etype (Entity (Subprog)));
9701 -- If need be, rewrite first actual as an explicit dereference. If
9702 -- the call is overloaded, the rewriting can only be done once the
9703 -- primitive operation is identified.
9705 if Is_Overloaded (Subprog) then
9707 -- The prefix itself may be overloaded, and its interpretations
9708 -- must be propagated to the new actual in the call.
9710 if Is_Overloaded (Obj) then
9711 Save_Interps (Obj, First_Actual);
9714 Rewrite (First_Actual, Obj);
9716 elsif not Is_Access_Type (Formal_Type)
9717 and then Is_Access_Type (Etype (Obj))
9719 Rewrite (First_Actual,
9720 Make_Explicit_Dereference (Sloc (Obj), Obj));
9721 Analyze (First_Actual);
9723 -- If we need to introduce an explicit dereference, verify that
9724 -- the resulting actual is compatible with the mode of the formal.
9726 if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
9727 and then Is_Access_Constant (Etype (Obj))
9730 ("expect variable in call to&", Prefix (N), Entity (Subprog));
9732 -- Conversely, if the formal is an access parameter and the object is
9733 -- not an access type or a reference type (i.e. a type with the
9734 -- Implicit_Dereference aspect specified), replace the actual with a
9735 -- 'Access reference. Its analysis will check that the object is
9738 elsif Is_Access_Type (Formal_Type)
9739 and then not Is_Access_Type (Etype (Obj))
9741 (not Has_Implicit_Dereference (Etype (Obj))
9743 not Is_Access_Type (Designated_Type (Etype
9744 (Get_Reference_Discriminant (Etype (Obj))))))
9746 -- A special case: A.all'Access is illegal if A is an access to a
9747 -- constant and the context requires an access to a variable.
9749 if not Is_Access_Constant (Formal_Type) then
9750 if (Nkind (Obj) = N_Explicit_Dereference
9751 and then Is_Access_Constant (Etype (Prefix (Obj))))
9752 or else not Is_Variable (Obj)
9755 ("actual for & must be a variable", Obj, Control);
9759 Rewrite (First_Actual,
9760 Make_Attribute_Reference (Loc,
9761 Attribute_Name => Name_Access,
9762 Prefix => Relocate_Node (Obj)));
9764 -- If the object is not overloaded verify that taking access of
9765 -- it is legal. Otherwise check is made during resolution.
9767 if not Is_Overloaded (Obj)
9768 and then not Is_Aliased_View (Obj)
9771 ("object in prefixed call to & must be aliased "
9772 & "(RM 4.1.3 (13 1/2))", Prefix (First_Actual), Subprog);
9775 Analyze (First_Actual);
9778 if Is_Overloaded (Obj) then
9779 Save_Interps (Obj, First_Actual);
9782 Rewrite (First_Actual, Obj);
9785 if In_Extended_Main_Source_Unit (Current_Scope) then
9786 -- The operation is obtained from the dispatch table and not by
9787 -- visibility, and may be declared in a unit that is not
9788 -- explicitly referenced in the source, but is nevertheless
9789 -- required in the context of the current unit. Indicate that
9790 -- operation and its scope are referenced, to prevent spurious and
9791 -- misleading warnings. If the operation is overloaded, all
9792 -- primitives are in the same scope and we can use any of them.
9793 -- Don't do that outside the main unit since otherwise this will
9794 -- e.g. prevent the detection of some unused with clauses.
9796 Set_Referenced (Entity (Subprog), True);
9797 Set_Referenced (Scope (Entity (Subprog)), True);
9800 Rewrite (Node_To_Replace, Call_Node);
9802 Set_Is_Expanded_Prefixed_Call (Node_To_Replace);
9804 -- Propagate the interpretations collected in subprog to the new
9805 -- function call node, to be resolved from context.
9807 if Is_Overloaded (Subprog) then
9808 Save_Interps (Subprog, Node_To_Replace);
9811 Analyze (Node_To_Replace);
9813 -- If the operation has been rewritten into a call, which may get
9814 -- subsequently an explicit dereference, preserve the type on the
9815 -- original node (selected component or indexed component) for
9816 -- subsequent legality tests, e.g. Is_Variable. which examines
9817 -- the original node.
9819 if Nkind (Node_To_Replace) = N_Function_Call then
9821 (Original_Node (Node_To_Replace), Etype (Node_To_Replace));
9824 end Complete_Object_Operation;
9826 ----------------------
9827 -- Report_Ambiguity --
9828 ----------------------
9830 procedure Report_Ambiguity (Op : Entity_Id) is
9831 Access_Actual : constant Boolean :=
9832 Is_Access_Type (Etype (Prefix (N)));
9833 Access_Formal : Boolean := False;
9836 Error_Msg_Sloc := Sloc (Op);
9838 if Present (First_Formal (Op)) then
9839 Access_Formal := Is_Access_Type (Etype (First_Formal (Op)));
9842 if Access_Formal and then not Access_Actual then
9843 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
9845 ("\possible interpretation "
9846 & "(inherited, with implicit 'Access) #", N);
9849 ("\possible interpretation (with implicit 'Access) #", N);
9852 elsif not Access_Formal and then Access_Actual then
9853 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
9855 ("\possible interpretation "
9856 & "(inherited, with implicit dereference) #", N);
9859 ("\possible interpretation (with implicit dereference) #", N);
9863 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
9864 Error_Msg_N ("\possible interpretation (inherited)#", N);
9866 Error_Msg_N -- CODEFIX
9867 ("\possible interpretation#", N);
9870 end Report_Ambiguity;
9872 --------------------------------
9873 -- Transform_Object_Operation --
9874 --------------------------------
9876 procedure Transform_Object_Operation
9877 (Call_Node : out Node_Id;
9878 Node_To_Replace : out Node_Id)
9880 Dummy : constant Node_Id := New_Copy (Obj);
9881 -- Placeholder used as a first parameter in the call, replaced
9882 -- eventually by the proper object.
9884 Parent_Node : constant Node_Id := Parent (N);
9890 -- Common case covering 1) Call to a procedure and 2) Call to a
9891 -- function that has some additional actuals.
9893 if Nkind (Parent_Node) in N_Subprogram_Call
9895 -- N is a selected component node containing the name of the
9896 -- subprogram. If N is not the name of the parent node we must
9897 -- not replace the parent node by the new construct. This case
9898 -- occurs when N is a parameterless call to a subprogram that
9899 -- is an actual parameter of a call to another subprogram. For
9901 -- Some_Subprogram (..., Obj.Operation, ...)
9903 and then N = Name (Parent_Node)
9905 Node_To_Replace := Parent_Node;
9907 Actuals := Parameter_Associations (Parent_Node);
9909 if Present (Actuals) then
9910 Prepend (Dummy, Actuals);
9912 Actuals := New_List (Dummy);
9915 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
9917 Make_Procedure_Call_Statement (Loc,
9918 Name => New_Copy (Subprog),
9919 Parameter_Associations => Actuals);
9923 Make_Function_Call (Loc,
9924 Name => New_Copy (Subprog),
9925 Parameter_Associations => Actuals);
9928 -- Before analysis, a function call appears as an indexed component
9929 -- if there are no named associations.
9931 elsif Nkind (Parent_Node) = N_Indexed_Component
9932 and then N = Prefix (Parent_Node)
9934 Node_To_Replace := Parent_Node;
9935 Actuals := Expressions (Parent_Node);
9937 Actual := First (Actuals);
9938 while Present (Actual) loop
9943 Prepend (Dummy, Actuals);
9946 Make_Function_Call (Loc,
9947 Name => New_Copy (Subprog),
9948 Parameter_Associations => Actuals);
9950 -- Parameterless call: Obj.F is rewritten as F (Obj)
9953 Node_To_Replace := N;
9956 Make_Function_Call (Loc,
9957 Name => New_Copy (Subprog),
9958 Parameter_Associations => New_List (Dummy));
9960 end Transform_Object_Operation;
9962 ------------------------------
9963 -- Try_Class_Wide_Operation --
9964 ------------------------------
9966 function Try_Class_Wide_Operation
9967 (Call_Node : Node_Id;
9968 Node_To_Replace : Node_Id) return Boolean
9970 Anc_Type : Entity_Id;
9971 Matching_Op : Entity_Id := Empty;
9974 procedure Traverse_Homonyms
9975 (Anc_Type : Entity_Id;
9976 Error : out Boolean);
9977 -- Traverse the homonym chain of the subprogram searching for those
9978 -- homonyms whose first formal has the Anc_Type's class-wide type,
9979 -- or an anonymous access type designating the class-wide type. If
9980 -- an ambiguity is detected, then Error is set to True.
9982 procedure Traverse_Interfaces
9983 (Anc_Type : Entity_Id;
9984 Error : out Boolean);
9985 -- Traverse the list of interfaces, if any, associated with Anc_Type
9986 -- and search for acceptable class-wide homonyms associated with each
9987 -- interface. If an ambiguity is detected, then Error is set to True.
9989 -----------------------
9990 -- Traverse_Homonyms --
9991 -----------------------
9993 procedure Traverse_Homonyms
9994 (Anc_Type : Entity_Id;
9995 Error : out Boolean)
9997 function First_Formal_Match
9998 (Subp_Id : Entity_Id;
9999 Typ : Entity_Id) return Boolean;
10000 -- Predicate to verify that the first foramal of class-wide
10001 -- subprogram Subp_Id matches type Typ of the prefix.
10003 ------------------------
10004 -- First_Formal_Match --
10005 ------------------------
10007 function First_Formal_Match
10008 (Subp_Id : Entity_Id;
10009 Typ : Entity_Id) return Boolean
10011 Ctrl : constant Entity_Id := First_Formal (Subp_Id);
10017 (Base_Type (Etype (Ctrl)) = Typ
10019 (Ekind (Etype (Ctrl)) = E_Anonymous_Access_Type
10021 Base_Type (Designated_Type (Etype (Ctrl))) =
10023 end First_Formal_Match;
10027 CW_Typ : constant Entity_Id := Class_Wide_Type (Anc_Type);
10029 Candidate : Entity_Id;
10030 -- If homonym is a renaming, examine the renamed program
10036 -- Start of processing for Traverse_Homonyms
10041 -- Find a non-hidden operation whose first parameter is of the
10042 -- class-wide type, a subtype thereof, or an anonymous access
10043 -- to same. If in an instance, the operation can be considered
10044 -- even if hidden (it may be hidden because the instantiation
10045 -- is expanded after the containing package has been analyzed).
10046 -- If the subprogram is a generic actual in an enclosing instance,
10047 -- it appears as a renaming that is a candidate interpretation as
10050 Hom := Current_Entity (Subprog);
10051 while Present (Hom) loop
10052 if Ekind (Hom) in E_Procedure | E_Function
10053 and then Present (Renamed_Entity (Hom))
10054 and then Is_Generic_Actual_Subprogram (Hom)
10055 and then In_Open_Scopes (Scope (Hom))
10057 Candidate := Renamed_Entity (Hom);
10062 if Ekind (Candidate) in E_Function | E_Procedure
10063 and then (not Is_Hidden (Candidate) or else In_Instance)
10064 and then Scope (Candidate) = Scope (Base_Type (Anc_Type))
10065 and then First_Formal_Match (Candidate, CW_Typ)
10067 -- If the context is a procedure call, ignore functions
10068 -- in the name of the call.
10070 if Ekind (Candidate) = E_Function
10071 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
10072 and then N = Name (Parent (N))
10076 -- If the context is a function call, ignore procedures
10077 -- in the name of the call.
10079 elsif Ekind (Candidate) = E_Procedure
10080 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
10085 Set_Etype (Call_Node, Any_Type);
10086 Set_Is_Overloaded (Call_Node, False);
10089 if No (Matching_Op) then
10090 Hom_Ref := New_Occurrence_Of (Candidate, Sloc (Subprog));
10092 Set_Etype (Call_Node, Any_Type);
10093 Set_Name (Call_Node, Hom_Ref);
10094 Set_Parent (Call_Node, Parent (Node_To_Replace));
10099 Report => Report_Error,
10100 Success => Success,
10101 Skip_First => True);
10104 Valid_Candidate (Success, Call_Node, Candidate);
10110 Report => Report_Error,
10111 Success => Success,
10112 Skip_First => True);
10114 -- The same operation may be encountered on two homonym
10115 -- traversals, before and after looking at interfaces.
10116 -- Check for this case before reporting a real ambiguity.
10119 (Valid_Candidate (Success, Call_Node, Candidate))
10120 and then Nkind (Call_Node) /= N_Function_Call
10121 and then Candidate /= Matching_Op
10123 Error_Msg_NE ("ambiguous call to&", N, Hom);
10124 Report_Ambiguity (Matching_Op);
10125 Report_Ambiguity (Hom);
10126 Check_Ambiguous_Aggregate (New_Call_Node);
10134 Hom := Homonym (Hom);
10136 end Traverse_Homonyms;
10138 -------------------------
10139 -- Traverse_Interfaces --
10140 -------------------------
10142 procedure Traverse_Interfaces
10143 (Anc_Type : Entity_Id;
10144 Error : out Boolean)
10146 Intface_List : constant List_Id :=
10147 Abstract_Interface_List (Anc_Type);
10153 -- When climbing through the parents of an interface type,
10154 -- look for acceptable class-wide homonyms associated with
10155 -- the interface type.
10157 if Is_Interface (Anc_Type) then
10158 Traverse_Homonyms (Anc_Type, Error);
10165 Intface := First (Intface_List);
10166 while Present (Intface) loop
10168 -- Look for acceptable class-wide homonyms associated with the
10171 Traverse_Homonyms (Etype (Intface), Error);
10177 -- Continue the search by looking at each of the interface's
10178 -- associated interface ancestors.
10180 Traverse_Interfaces (Etype (Intface), Error);
10189 -- For derived interface types continue the search climbing to
10190 -- the parent type.
10192 if Is_Interface (Anc_Type)
10193 and then Etype (Anc_Type) /= Anc_Type
10195 Traverse_Interfaces (Etype (Anc_Type), Error);
10197 end Traverse_Interfaces;
10199 -- Start of processing for Try_Class_Wide_Operation
10202 -- If we are searching only for conflicting class-wide subprograms
10203 -- then initialize directly Matching_Op with the target entity.
10205 if CW_Test_Only then
10206 Matching_Op := Entity (Selector_Name (N));
10209 -- Loop through ancestor types (including interfaces), traversing
10210 -- the homonym chain of the subprogram, trying out those homonyms
10211 -- whose first formal has the class-wide type of the ancestor, or
10212 -- an anonymous access type designating the class-wide type.
10214 Anc_Type := Obj_Type;
10216 -- Look for a match among homonyms associated with the ancestor
10218 Traverse_Homonyms (Anc_Type, Error);
10224 -- Continue the search for matches among homonyms associated with
10225 -- any interfaces implemented by the ancestor.
10227 Traverse_Interfaces (Anc_Type, Error);
10233 exit when Etype (Anc_Type) = Anc_Type;
10234 Anc_Type := Etype (Anc_Type);
10237 if Present (Matching_Op) then
10238 Set_Etype (Call_Node, Etype (Matching_Op));
10241 return Present (Matching_Op);
10242 end Try_Class_Wide_Operation;
10244 -----------------------------------
10245 -- Try_One_Prefix_Interpretation --
10246 -----------------------------------
10248 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
10249 Prev_Obj_Type : constant Entity_Id := Obj_Type;
10250 -- If the interpretation does not have a valid candidate type,
10251 -- preserve current value of Obj_Type for subsequent errors.
10256 if Is_Access_Type (Obj_Type) then
10257 Obj_Type := Designated_Type (Obj_Type);
10260 if Ekind (Obj_Type)
10261 in E_Private_Subtype | E_Record_Subtype_With_Private
10263 Obj_Type := Base_Type (Obj_Type);
10266 if Is_Class_Wide_Type (Obj_Type) then
10267 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
10270 -- The type may have be obtained through a limited_with clause,
10271 -- in which case the primitive operations are available on its
10272 -- nonlimited view. If still incomplete, retrieve full view.
10274 if Ekind (Obj_Type) = E_Incomplete_Type
10275 and then From_Limited_With (Obj_Type)
10276 and then Has_Non_Limited_View (Obj_Type)
10278 Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
10281 -- If the object is not tagged, or the type is still an incomplete
10282 -- type, this is not a prefixed call. Restore the previous type as
10283 -- the current one is not a legal candidate.
10285 -- Extension feature: Calls with prefixed views are also supported
10286 -- for untagged types, so skip the early return when extensions are
10287 -- enabled, unless the type doesn't have a primitive operations list
10288 -- (such as in the case of predefined types).
10290 if (not Is_Tagged_Type (Obj_Type)
10292 (not (Core_Extensions_Allowed or Allow_Extensions)
10293 or else No (Primitive_Operations (Obj_Type))))
10294 or else Is_Incomplete_Type (Obj_Type)
10296 Obj_Type := Prev_Obj_Type;
10301 Dup_Call_Node : constant Node_Id := New_Copy (New_Call_Node);
10303 Prim_Result : Boolean := False;
10306 if not CW_Test_Only then
10308 Try_Primitive_Operation
10309 (Call_Node => New_Call_Node,
10310 Node_To_Replace => Node_To_Replace);
10312 -- Extension feature: In the case where the prefix is of an
10313 -- access type, and a primitive wasn't found for the designated
10314 -- type, then if the access type has primitives we attempt a
10315 -- prefixed call using one of its primitives. (It seems that
10316 -- this isn't quite right to give preference to the designated
10317 -- type in the case where both the access and designated types
10318 -- have homographic prefixed-view operations that could result
10319 -- in an ambiguity, but handling properly may be tricky. ???)
10321 if (Core_Extensions_Allowed or Allow_Extensions)
10322 and then not Prim_Result
10323 and then Is_Named_Access_Type (Prev_Obj_Type)
10324 and then Present (Direct_Primitive_Operations (Prev_Obj_Type))
10326 -- Temporarily reset Obj_Type to the original access type
10328 Obj_Type := Prev_Obj_Type;
10331 Try_Primitive_Operation
10332 (Call_Node => New_Call_Node,
10333 Node_To_Replace => Node_To_Replace);
10335 -- Restore Obj_Type to the designated type (is this really
10336 -- necessary, or should it only be done when Prim_Result is
10339 Obj_Type := Designated_Type (Obj_Type);
10343 -- Check if there is a class-wide subprogram covering the
10344 -- primitive. This check must be done even if a candidate
10345 -- was found in order to report ambiguous calls.
10347 if not Prim_Result then
10349 Try_Class_Wide_Operation
10350 (Call_Node => New_Call_Node,
10351 Node_To_Replace => Node_To_Replace);
10353 -- If we found a primitive we search for class-wide subprograms
10354 -- using a duplicate of the call node (done to avoid missing its
10355 -- decoration if there is no ambiguity).
10359 Try_Class_Wide_Operation
10360 (Call_Node => Dup_Call_Node,
10361 Node_To_Replace => Node_To_Replace);
10364 end Try_One_Prefix_Interpretation;
10366 -----------------------------
10367 -- Try_Primitive_Operation --
10368 -----------------------------
10370 function Try_Primitive_Operation
10371 (Call_Node : Node_Id;
10372 Node_To_Replace : Node_Id) return Boolean
10375 Prim_Op : Entity_Id;
10376 Matching_Op : Entity_Id := Empty;
10377 Prim_Op_Ref : Node_Id := Empty;
10379 Corr_Type : Entity_Id := Empty;
10380 -- If the prefix is a synchronized type, the controlling type of
10381 -- the primitive operation is the corresponding record type, else
10382 -- this is the object type itself.
10384 Success : Boolean := False;
10386 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
10387 -- For tagged types the candidate interpretations are found in
10388 -- the list of primitive operations of the type and its ancestors.
10389 -- For formal tagged types we have to find the operations declared
10390 -- in the same scope as the type (including in the generic formal
10391 -- part) because the type itself carries no primitive operations,
10392 -- except for formal derived types that inherit the operations of
10393 -- the parent and progenitors.
10395 -- If the context is a generic subprogram body, the generic formals
10396 -- are visible by name, but are not in the entity list of the
10397 -- subprogram because that list starts with the subprogram formals.
10398 -- We retrieve the candidate operations from the generic declaration.
10400 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id;
10401 -- Prefix notation can also be used on operations that are not
10402 -- primitives of the type, but are declared in the same immediate
10403 -- declarative part, which can only mean the corresponding package
10404 -- body (see RM 4.1.3 (9.2/3)). If we are in that body we extend the
10405 -- list of primitives with body operations with the same name that
10406 -- may be candidates, so that Try_Primitive_Operations can examine
10407 -- them if no real primitive is found.
10409 function Is_Private_Overriding (Op : Entity_Id) return Boolean;
10410 -- An operation that overrides an inherited operation in the private
10411 -- part of its package may be hidden, but if the inherited operation
10412 -- is visible a direct call to it will dispatch to the private one,
10413 -- which is therefore a valid candidate.
10415 function Names_Match
10416 (Obj_Type : Entity_Id;
10417 Prim_Op : Entity_Id;
10418 Subprog : Entity_Id) return Boolean;
10419 -- Return True if the names of Prim_Op and Subprog match. If Obj_Type
10420 -- is a protected type then compare also the original name of Prim_Op
10421 -- with the name of Subprog (since the expander may have added a
10422 -- prefix to its original name --see Exp_Ch9.Build_Selected_Name).
10424 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
10425 -- Verify that the prefix, dereferenced if need be, is a valid
10426 -- controlling argument in a call to Op. The remaining actuals
10427 -- are checked in the subsequent call to Analyze_One_Call.
10429 ------------------------------
10430 -- Collect_Generic_Type_Ops --
10431 ------------------------------
10433 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
10434 Bas : constant Entity_Id := Base_Type (T);
10435 Candidates : constant Elist_Id := New_Elmt_List;
10437 Formal : Entity_Id;
10439 procedure Check_Candidate;
10440 -- The operation is a candidate if its first parameter is a
10441 -- controlling operand of the desired type.
10443 -----------------------
10444 -- Check_Candidate; --
10445 -----------------------
10447 procedure Check_Candidate is
10449 Formal := First_Formal (Subp);
10451 if Present (Formal)
10452 and then Is_Controlling_Formal (Formal)
10454 (Base_Type (Etype (Formal)) = Bas
10456 (Is_Access_Type (Etype (Formal))
10457 and then Designated_Type (Etype (Formal)) = Bas))
10459 Append_Elmt (Subp, Candidates);
10461 end Check_Candidate;
10463 -- Start of processing for Collect_Generic_Type_Ops
10466 if Is_Derived_Type (T) then
10467 return Primitive_Operations (T);
10469 elsif Ekind (Scope (T)) in E_Procedure | E_Function then
10471 -- Scan the list of generic formals to find subprograms
10472 -- that may have a first controlling formal of the type.
10474 if Nkind (Unit_Declaration_Node (Scope (T))) =
10475 N_Generic_Subprogram_Declaration
10482 First (Generic_Formal_Declarations
10483 (Unit_Declaration_Node (Scope (T))));
10484 while Present (Decl) loop
10485 if Nkind (Decl) in N_Formal_Subprogram_Declaration then
10486 Subp := Defining_Entity (Decl);
10497 -- Scan the list of entities declared in the same scope as
10498 -- the type. In general this will be an open scope, given that
10499 -- the call we are analyzing can only appear within a generic
10500 -- declaration or body (either the one that declares T, or a
10503 -- For a subtype representing a generic actual type, go to the
10506 if Is_Generic_Actual_Type (T) then
10507 Subp := First_Entity (Scope (Base_Type (T)));
10509 Subp := First_Entity (Scope (T));
10512 while Present (Subp) loop
10513 if Is_Overloadable (Subp) then
10517 Next_Entity (Subp);
10522 end Collect_Generic_Type_Ops;
10524 ----------------------------
10525 -- Extended_Primitive_Ops --
10526 ----------------------------
10528 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id is
10529 Type_Scope : constant Entity_Id := Scope (T);
10530 Op_List : Elist_Id := Primitive_Operations (T);
10532 if Is_Package_Or_Generic_Package (Type_Scope)
10533 and then ((In_Package_Body (Type_Scope)
10534 and then In_Open_Scopes (Type_Scope)) or else In_Instance_Body)
10536 -- Retrieve list of declarations of package body if possible
10539 The_Body : constant Node_Id :=
10540 Corresponding_Body (Unit_Declaration_Node (Type_Scope));
10542 if Present (The_Body) then
10544 Body_Decls : constant List_Id :=
10545 Declarations (Unit_Declaration_Node (The_Body));
10546 Op_Found : Boolean := False;
10547 Op : Entity_Id := Current_Entity (Subprog);
10549 while Present (Op) loop
10550 if Comes_From_Source (Op)
10551 and then Is_Overloadable (Op)
10553 -- Exclude overriding primitive operations of a
10554 -- type extension declared in the package body,
10555 -- to prevent duplicates in extended list.
10557 and then not Is_Primitive (Op)
10558 and then Is_List_Member
10559 (Unit_Declaration_Node (Op))
10560 and then List_Containing
10561 (Unit_Declaration_Node (Op)) = Body_Decls
10563 if not Op_Found then
10564 -- Copy list of primitives so it is not
10565 -- affected for other uses.
10567 Op_List := New_Copy_Elist (Op_List);
10571 Append_Elmt (Op, Op_List);
10574 Op := Homonym (Op);
10582 end Extended_Primitive_Ops;
10584 ---------------------------
10585 -- Is_Private_Overriding --
10586 ---------------------------
10588 function Is_Private_Overriding (Op : Entity_Id) return Boolean is
10589 Visible_Op : Entity_Id;
10592 -- The subprogram may be overloaded with both visible and private
10593 -- entities with the same name. We have to scan the chain of
10594 -- homonyms to determine whether there is a previous implicit
10595 -- declaration in the same scope that is overridden by the
10596 -- private candidate.
10598 Visible_Op := Homonym (Op);
10599 while Present (Visible_Op) loop
10600 if Scope (Op) /= Scope (Visible_Op) then
10603 elsif not Comes_From_Source (Visible_Op)
10604 and then Alias (Visible_Op) = Op
10606 -- If Visible_Op or what it overrides is not hidden, then we
10607 -- have found what we're looking for.
10609 if not Is_Hidden (Visible_Op)
10610 or else not Is_Hidden (Overridden_Operation (Op))
10616 Visible_Op := Homonym (Visible_Op);
10620 end Is_Private_Overriding;
10626 function Names_Match
10627 (Obj_Type : Entity_Id;
10628 Prim_Op : Entity_Id;
10629 Subprog : Entity_Id) return Boolean is
10631 -- Common case: exact match
10633 if Chars (Prim_Op) = Chars (Subprog) then
10636 -- For protected type primitives the expander may have built the
10637 -- name of the dispatching primitive prepending the type name to
10638 -- avoid conflicts with the name of the protected subprogram (see
10639 -- Exp_Ch9.Build_Selected_Name).
10641 elsif Is_Protected_Type (Obj_Type) then
10643 Present (Original_Protected_Subprogram (Prim_Op))
10644 and then Chars (Original_Protected_Subprogram (Prim_Op)) =
10647 -- In an instance, the selector name may be a generic actual that
10648 -- renames a primitive operation of the type of the prefix.
10650 elsif In_Instance and then Present (Current_Entity (Subprog)) then
10652 Subp : constant Entity_Id := Current_Entity (Subprog);
10655 and then Is_Subprogram (Subp)
10656 and then Present (Renamed_Entity (Subp))
10657 and then Is_Generic_Actual_Subprogram (Subp)
10658 and then Chars (Renamed_Entity (Subp)) = Chars (Prim_Op)
10668 -----------------------------
10669 -- Valid_First_Argument_Of --
10670 -----------------------------
10672 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
10673 Typ : Entity_Id := Etype (First_Formal (Op));
10676 if Is_Concurrent_Type (Typ)
10677 and then Present (Corresponding_Record_Type (Typ))
10679 Typ := Corresponding_Record_Type (Typ);
10682 -- Simple case. Object may be a subtype of the tagged type or may
10683 -- be the corresponding record of a synchronized type.
10685 return Obj_Type = Typ
10686 or else Base_Type (Obj_Type) = Base_Type (Typ)
10687 or else Corr_Type = Typ
10689 -- Object may be of a derived type whose parent has unknown
10690 -- discriminants, in which case the type matches the underlying
10691 -- record view of its base.
10694 (Has_Unknown_Discriminants (Typ)
10695 and then Typ = Underlying_Record_View (Base_Type (Obj_Type)))
10697 -- Prefix can be dereferenced
10700 (Is_Access_Type (Corr_Type)
10701 and then Designated_Type (Corr_Type) = Typ)
10703 -- Formal is an access parameter, for which the object can
10704 -- provide an access.
10707 (Ekind (Typ) = E_Anonymous_Access_Type
10709 Base_Type (Designated_Type (Typ)) = Base_Type (Corr_Type));
10710 end Valid_First_Argument_Of;
10712 -- Start of processing for Try_Primitive_Operation
10715 -- Look for subprograms in the list of primitive operations. The name
10716 -- must be identical, and the kind of call indicates the expected
10717 -- kind of operation (function or procedure). If the type is a
10718 -- (tagged) synchronized type, the primitive ops are attached to the
10719 -- corresponding record (base) type.
10721 if Is_Concurrent_Type (Obj_Type) then
10722 if Present (Corresponding_Record_Type (Obj_Type)) then
10723 Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
10724 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
10726 Corr_Type := Obj_Type;
10727 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
10730 elsif not Is_Generic_Type (Obj_Type) then
10731 Corr_Type := Obj_Type;
10732 Elmt := First_Elmt (Extended_Primitive_Ops (Obj_Type));
10735 Corr_Type := Obj_Type;
10736 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
10739 while Present (Elmt) loop
10740 Prim_Op := Node (Elmt);
10742 if Names_Match (Obj_Type, Prim_Op, Subprog)
10743 and then Present (First_Formal (Prim_Op))
10744 and then Valid_First_Argument_Of (Prim_Op)
10746 (Nkind (Call_Node) = N_Function_Call)
10748 (Ekind (Prim_Op) = E_Function)
10750 -- Ada 2005 (AI-251): If this primitive operation corresponds
10751 -- to an immediate ancestor interface there is no need to add
10752 -- it to the list of interpretations; the corresponding aliased
10753 -- primitive is also in this list of primitive operations and
10754 -- will be used instead.
10756 if (Present (Interface_Alias (Prim_Op))
10757 and then Is_Ancestor (Find_Dispatching_Type
10758 (Alias (Prim_Op)), Corr_Type))
10760 -- Do not consider hidden primitives unless the type is in an
10761 -- open scope or we are within an instance, where visibility
10762 -- is known to be correct, or else if this is an overriding
10763 -- operation in the private part for an inherited operation.
10765 or else (Is_Hidden (Prim_Op)
10766 and then not Is_Immediately_Visible (Obj_Type)
10767 and then not In_Instance
10768 and then not Is_Private_Overriding (Prim_Op))
10773 Set_Etype (Call_Node, Any_Type);
10774 Set_Is_Overloaded (Call_Node, False);
10776 if No (Matching_Op) then
10777 Prim_Op_Ref := New_Occurrence_Of (Prim_Op, Sloc (Subprog));
10778 Candidate := Prim_Op;
10780 Set_Parent (Call_Node, Parent (Node_To_Replace));
10782 Set_Name (Call_Node, Prim_Op_Ref);
10788 Report => Report_Error,
10789 Success => Success,
10790 Skip_First => True);
10792 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
10794 -- More than one interpretation, collect for subsequent
10795 -- disambiguation. If this is a procedure call and there
10796 -- is another match, report ambiguity now.
10802 Report => Report_Error,
10803 Success => Success,
10804 Skip_First => True);
10806 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
10807 and then Nkind (Call_Node) /= N_Function_Call
10809 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
10810 Report_Ambiguity (Matching_Op);
10811 Report_Ambiguity (Prim_Op);
10812 Check_Ambiguous_Aggregate (Call_Node);
10822 if Present (Matching_Op) then
10823 Set_Etype (Call_Node, Etype (Matching_Op));
10826 return Present (Matching_Op);
10827 end Try_Primitive_Operation;
10829 ---------------------
10830 -- Valid_Candidate --
10831 ---------------------
10833 function Valid_Candidate
10834 (Success : Boolean;
10836 Subp : Entity_Id) return Entity_Id
10838 Arr_Type : Entity_Id;
10839 Comp_Type : Entity_Id;
10842 -- If the subprogram is a valid interpretation, record it in global
10843 -- variable Subprog, to collect all possible overloadings.
10846 if Subp /= Entity (Subprog) then
10847 Add_One_Interp (Subprog, Subp, Etype (Subp));
10851 -- If the call may be an indexed call, retrieve component type of
10852 -- resulting expression, and add possible interpretation.
10855 Comp_Type := Empty;
10857 if Nkind (Call) = N_Function_Call
10858 and then Nkind (Parent (N)) = N_Indexed_Component
10859 and then Needs_One_Actual (Subp)
10861 if Is_Array_Type (Etype (Subp)) then
10862 Arr_Type := Etype (Subp);
10864 elsif Is_Access_Type (Etype (Subp))
10865 and then Is_Array_Type (Designated_Type (Etype (Subp)))
10867 Arr_Type := Designated_Type (Etype (Subp));
10871 if Present (Arr_Type) then
10873 -- Verify that the actuals (excluding the object) match the types
10881 Actual := Next (First_Actual (Call));
10882 Index := First_Index (Arr_Type);
10883 while Present (Actual) and then Present (Index) loop
10884 if not Has_Compatible_Type (Actual, Etype (Index)) then
10889 Next_Actual (Actual);
10890 Next_Index (Index);
10894 and then No (Index)
10895 and then Present (Arr_Type)
10897 Comp_Type := Component_Type (Arr_Type);
10901 if Present (Comp_Type)
10902 and then Etype (Subprog) /= Comp_Type
10904 Add_One_Interp (Subprog, Subp, Comp_Type);
10908 if Etype (Call) /= Any_Type then
10913 end Valid_Candidate;
10915 -- Start of processing for Try_Object_Operation
10918 if Is_Class_Wide_Equivalent_Type (Obj_Type) then
10919 Obj_Type := Corresponding_Mutably_Tagged_Type (Obj_Type);
10922 Analyze_Expression (Obj);
10924 -- Analyze the actuals if node is known to be a subprogram call
10926 if Is_Subprg_Call and then N = Name (Parent (N)) then
10927 Actual := First (Parameter_Associations (Parent (N)));
10928 while Present (Actual) loop
10929 Analyze_Expression (Actual);
10934 -- Build a subprogram call node, using a copy of Obj as its first
10935 -- actual. This is a placeholder, to be replaced by an explicit
10936 -- dereference when needed.
10938 Transform_Object_Operation
10939 (Call_Node => New_Call_Node,
10940 Node_To_Replace => Node_To_Replace);
10942 Set_Etype (New_Call_Node, Any_Type);
10943 Set_Etype (Subprog, Any_Type);
10944 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
10946 -- Perform the analysis searching for a candidate with Report_Error
10947 -- set to False (see above); if no candidate interpretation matches
10948 -- the context, this analysis will be redone with Report_Error set
10949 -- to True to provide additional information.
10951 if not Is_Overloaded (Obj) then
10952 Try_One_Prefix_Interpretation (Obj_Type);
10959 Get_First_Interp (Obj, I, It);
10960 while Present (It.Nam) loop
10961 Try_One_Prefix_Interpretation (It.Typ);
10962 Get_Next_Interp (I, It);
10967 if Etype (New_Call_Node) /= Any_Type then
10969 -- No need to complete the tree transformations if we are only
10970 -- searching for conflicting class-wide subprograms
10972 if CW_Test_Only then
10975 Complete_Object_Operation
10976 (Call_Node => New_Call_Node,
10977 Node_To_Replace => Node_To_Replace);
10982 elsif Present (Candidate) then
10984 -- The argument list is not type correct. Re-analyze with error
10985 -- reporting enabled, and use one of the possible candidates.
10986 -- In All_Errors_Mode, re-analyze all failed interpretations.
10988 if All_Errors_Mode then
10989 Report_Error := True;
10991 if not Is_Overloaded (Obj) then
10992 Try_One_Prefix_Interpretation (Obj_Type);
10999 Get_First_Interp (Obj, I, It);
11000 while Present (It.Nam) loop
11001 Try_One_Prefix_Interpretation (It.Typ);
11002 Get_Next_Interp (I, It);
11008 (N => New_Call_Node,
11011 Success => Success,
11012 Skip_First => True);
11014 -- The error may hot have been reported yet for overloaded
11015 -- prefixed calls, depending on the non-matching candidate,
11016 -- in which case provide a concise error now.
11018 if Serious_Errors_Detected = 0 then
11020 ("cannot resolve prefixed call to primitive operation of&",
11025 -- No need for further errors
11030 -- There was no candidate operation, but Analyze_Selected_Component
11031 -- may continue the analysis so we need to undo the change possibly
11032 -- made to the Parent of N earlier by Transform_Object_Operation.
11035 Parent_Node : constant Node_Id := Parent (N);
11038 if Node_To_Replace = Parent_Node then
11039 Remove (First (Parameter_Associations (New_Call_Node)));
11041 (Parameter_Associations (New_Call_Node), Parent_Node);
11047 end Try_Object_Operation;
11049 -------------------------
11050 -- Unresolved_Operator --
11051 -------------------------
11053 procedure Unresolved_Operator (N : Node_Id) is
11054 L : constant Node_Id :=
11055 (if Nkind (N) in N_Binary_Op then Left_Opnd (N) else Empty);
11056 R : constant Node_Id := Right_Opnd (N);
11061 -- Note that in the following messages, if the operand is overloaded we
11062 -- choose an arbitrary type to complain about, but that is probably more
11063 -- useful than not giving a type at all.
11065 if Nkind (N) in N_Unary_Op then
11066 Error_Msg_Node_2 := Etype (R);
11067 Error_Msg_N ("operator& not defined for}", N);
11069 elsif Nkind (N) in N_Binary_Op then
11070 if not Is_Overloaded (L)
11071 and then not Is_Overloaded (R)
11072 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
11074 Error_Msg_Node_2 := First_Subtype (Etype (R));
11075 Error_Msg_N ("there is no applicable operator& for}", N);
11078 -- Another attempt to find a fix: one of the candidate
11079 -- interpretations may not be use-visible. This has
11080 -- already been checked for predefined operators, so
11081 -- we examine only user-defined functions.
11083 Op_Id := Get_Name_Entity_Id (Chars (N));
11085 while Present (Op_Id) loop
11086 if Ekind (Op_Id) /= E_Operator
11087 and then Is_Overloadable (Op_Id)
11088 and then not Is_Immediately_Visible (Op_Id)
11089 and then not In_Use (Scope (Op_Id))
11090 and then not Is_Abstract_Subprogram (Op_Id)
11091 and then not Is_Hidden (Op_Id)
11092 and then Ekind (Scope (Op_Id)) = E_Package
11093 and then Has_Compatible_Type (L, Etype (First_Formal (Op_Id)))
11094 and then Present (Next_Formal (First_Formal (Op_Id)))
11096 Has_Compatible_Type
11097 (R, Etype (Next_Formal (First_Formal (Op_Id))))
11099 Error_Msg_N ("no legal interpretation for operator&", N);
11100 Error_Msg_NE ("\use clause on& would make operation legal",
11105 Op_Id := Homonym (Op_Id);
11110 ("invalid operand types for operator&", N,
11113 if Nkind (N) /= N_Op_Concat then
11115 ("\left operand has}!", N, Etype (L));
11117 ("\right operand has}!", N, Etype (R));
11119 -- For multiplication and division operators with
11120 -- a fixed-point operand and an integer operand,
11121 -- indicate that the integer operand should be of
11124 if Nkind (N) in N_Op_Multiply | N_Op_Divide
11125 and then Is_Fixed_Point_Type (Etype (L))
11126 and then Is_Integer_Type (Etype (R))
11129 ("\convert right operand to `Integer`", N);
11131 elsif Nkind (N) = N_Op_Multiply
11132 and then Is_Fixed_Point_Type (Etype (R))
11133 and then Is_Integer_Type (Etype (L))
11136 ("\convert left operand to `Integer`", N);
11139 -- For concatenation operators it is more difficult to
11140 -- determine which is the wrong operand. It is worth
11141 -- flagging explicitly an access type, for those who
11142 -- might think that a dereference happens here.
11144 elsif Is_Access_Type (Etype (L)) then
11145 Error_Msg_N ("\left operand is access type", N);
11147 elsif Is_Access_Type (Etype (R)) then
11148 Error_Msg_N ("\right operand is access type", N);
11153 end Unresolved_Operator;
11159 procedure wpo (T : Entity_Id) is
11164 if not Is_Tagged_Type (T) then
11168 E := First_Elmt (Primitive_Operations (Base_Type (T)));
11169 while Present (E) loop
11171 Write_Int (Int (Op));
11172 Write_Str (" === ");
11173 Write_Name (Chars (Op));
11174 Write_Str (" in ");
11175 Write_Name (Chars (Scope (Op)));