PR c++/79377
[official-gcc.git] / gcc / ada / sem_ch4.adb
blob1cdb7a03288550f95ef21376f8d77e27201778f0
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ C H 4 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Util; use Exp_Util;
33 with Fname; use Fname;
34 with Itypes; use Itypes;
35 with Lib; use Lib;
36 with Lib.Xref; use Lib.Xref;
37 with Namet; use Namet;
38 with Namet.Sp; use Namet.Sp;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
41 with Opt; use Opt;
42 with Output; use Output;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
45 with Sem; use Sem;
46 with Sem_Aux; use Sem_Aux;
47 with Sem_Case; use Sem_Case;
48 with Sem_Cat; use Sem_Cat;
49 with Sem_Ch3; use Sem_Ch3;
50 with Sem_Ch6; use Sem_Ch6;
51 with Sem_Ch8; use Sem_Ch8;
52 with Sem_Dim; use Sem_Dim;
53 with Sem_Disp; use Sem_Disp;
54 with Sem_Dist; use Sem_Dist;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Res; use Sem_Res;
57 with Sem_Type; use Sem_Type;
58 with Sem_Util; use Sem_Util;
59 with Sem_Warn; use Sem_Warn;
60 with Stand; use Stand;
61 with Sinfo; use Sinfo;
62 with Snames; use Snames;
63 with Tbuild; use Tbuild;
64 with Uintp; use Uintp;
66 package body Sem_Ch4 is
68 -- Tables which speed up the identification of dangerous calls to Ada 2012
69 -- functions with writable actuals (AI05-0144).
71 -- The following table enumerates the Ada constructs which may evaluate in
72 -- arbitrary order. It does not cover all the language constructs which can
73 -- be evaluated in arbitrary order but the subset needed for AI05-0144.
75 Has_Arbitrary_Evaluation_Order : constant array (Node_Kind) of Boolean :=
76 (N_Aggregate => True,
77 N_Assignment_Statement => True,
78 N_Entry_Call_Statement => True,
79 N_Extension_Aggregate => True,
80 N_Full_Type_Declaration => True,
81 N_Indexed_Component => True,
82 N_Object_Declaration => True,
83 N_Pragma => True,
84 N_Range => True,
85 N_Slice => True,
86 N_Array_Type_Definition => True,
87 N_Membership_Test => True,
88 N_Binary_Op => True,
89 N_Subprogram_Call => True,
90 others => False);
92 -- The following table enumerates the nodes on which we stop climbing when
93 -- locating the outermost Ada construct that can be evaluated in arbitrary
94 -- order.
96 Stop_Subtree_Climbing : constant array (Node_Kind) of Boolean :=
97 (N_Aggregate => True,
98 N_Assignment_Statement => True,
99 N_Entry_Call_Statement => True,
100 N_Extended_Return_Statement => True,
101 N_Extension_Aggregate => True,
102 N_Full_Type_Declaration => True,
103 N_Object_Declaration => True,
104 N_Object_Renaming_Declaration => True,
105 N_Package_Specification => True,
106 N_Pragma => True,
107 N_Procedure_Call_Statement => True,
108 N_Simple_Return_Statement => True,
109 N_Has_Condition => True,
110 others => False);
112 -----------------------
113 -- Local Subprograms --
114 -----------------------
116 procedure Analyze_Concatenation_Rest (N : Node_Id);
117 -- Does the "rest" of the work of Analyze_Concatenation, after the left
118 -- operand has been analyzed. See Analyze_Concatenation for details.
120 procedure Analyze_Expression (N : Node_Id);
121 -- For expressions that are not names, this is just a call to analyze. If
122 -- the expression is a name, it may be a call to a parameterless function,
123 -- and if so must be converted into an explicit call node and analyzed as
124 -- such. This deproceduring must be done during the first pass of overload
125 -- resolution, because otherwise a procedure call with overloaded actuals
126 -- may fail to resolve.
128 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
129 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call is an
130 -- operator name or an expanded name whose selector is an operator name,
131 -- and one possible interpretation is as a predefined operator.
133 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
134 -- If the prefix of a selected_component is overloaded, the proper
135 -- interpretation that yields a record type with the proper selector
136 -- name must be selected.
138 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
139 -- Procedure to analyze a user defined binary operator, which is resolved
140 -- like a function, but instead of a list of actuals it is presented
141 -- with the left and right operands of an operator node.
143 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
144 -- Procedure to analyze a user defined unary operator, which is resolved
145 -- like a function, but instead of a list of actuals, it is presented with
146 -- the operand of the operator node.
148 procedure Ambiguous_Operands (N : Node_Id);
149 -- For equality, membership, and comparison operators with overloaded
150 -- arguments, list possible interpretations.
152 procedure Analyze_One_Call
153 (N : Node_Id;
154 Nam : Entity_Id;
155 Report : Boolean;
156 Success : out Boolean;
157 Skip_First : Boolean := False);
158 -- Check one interpretation of an overloaded subprogram name for
159 -- compatibility with the types of the actuals in a call. If there is a
160 -- single interpretation which does not match, post error if Report is
161 -- set to True.
163 -- Nam is the entity that provides the formals against which the actuals
164 -- are checked. Nam is either the name of a subprogram, or the internal
165 -- subprogram type constructed for an access_to_subprogram. If the actuals
166 -- are compatible with Nam, then Nam is added to the list of candidate
167 -- interpretations for N, and Success is set to True.
169 -- The flag Skip_First is used when analyzing a call that was rewritten
170 -- from object notation. In this case the first actual may have to receive
171 -- an explicit dereference, depending on the first formal of the operation
172 -- being called. The caller will have verified that the object is legal
173 -- for the call. If the remaining parameters match, the first parameter
174 -- will rewritten as a dereference if needed, prior to completing analysis.
176 procedure Check_Misspelled_Selector
177 (Prefix : Entity_Id;
178 Sel : Node_Id);
179 -- Give possible misspelling message if Sel seems likely to be a mis-
180 -- spelling of one of the selectors of the Prefix. This is called by
181 -- Analyze_Selected_Component after producing an invalid selector error
182 -- message.
184 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
185 -- Verify that type T is declared in scope S. Used to find interpretations
186 -- for operators given by expanded names. This is abstracted as a separate
187 -- function to handle extensions to System, where S is System, but T is
188 -- declared in the extension.
190 procedure Find_Arithmetic_Types
191 (L, R : Node_Id;
192 Op_Id : Entity_Id;
193 N : Node_Id);
194 -- L and R are the operands of an arithmetic operator. Find consistent
195 -- pairs of interpretations for L and R that have a numeric type consistent
196 -- with the semantics of the operator.
198 procedure Find_Comparison_Types
199 (L, R : Node_Id;
200 Op_Id : Entity_Id;
201 N : Node_Id);
202 -- L and R are operands of a comparison operator. Find consistent pairs of
203 -- interpretations for L and R.
205 procedure Find_Concatenation_Types
206 (L, R : Node_Id;
207 Op_Id : Entity_Id;
208 N : Node_Id);
209 -- For the four varieties of concatenation
211 procedure Find_Equality_Types
212 (L, R : Node_Id;
213 Op_Id : Entity_Id;
214 N : Node_Id);
215 -- Ditto for equality operators
217 procedure Find_Boolean_Types
218 (L, R : Node_Id;
219 Op_Id : Entity_Id;
220 N : Node_Id);
221 -- Ditto for binary logical operations
223 procedure Find_Negation_Types
224 (R : Node_Id;
225 Op_Id : Entity_Id;
226 N : Node_Id);
227 -- Find consistent interpretation for operand of negation operator
229 procedure Find_Non_Universal_Interpretations
230 (N : Node_Id;
231 R : Node_Id;
232 Op_Id : Entity_Id;
233 T1 : Entity_Id);
234 -- For equality and comparison operators, the result is always boolean, and
235 -- the legality of the operation is determined from the visibility of the
236 -- operand types. If one of the operands has a universal interpretation,
237 -- the legality check uses some compatible non-universal interpretation of
238 -- the other operand. N can be an operator node, or a function call whose
239 -- name is an operator designator. Any_Access, which is the initial type of
240 -- the literal NULL, is a universal type for the purpose of this routine.
242 function Find_Primitive_Operation (N : Node_Id) return Boolean;
243 -- Find candidate interpretations for the name Obj.Proc when it appears in
244 -- a subprogram renaming declaration.
246 procedure Find_Unary_Types
247 (R : Node_Id;
248 Op_Id : Entity_Id;
249 N : Node_Id);
250 -- Unary arithmetic types: plus, minus, abs
252 procedure Check_Arithmetic_Pair
253 (T1, T2 : Entity_Id;
254 Op_Id : Entity_Id;
255 N : Node_Id);
256 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid types
257 -- for left and right operand. Determine whether they constitute a valid
258 -- pair for the given operator, and record the corresponding interpretation
259 -- of the operator node. The node N may be an operator node (the usual
260 -- case) or a function call whose prefix is an operator designator. In
261 -- both cases Op_Id is the operator name itself.
263 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
264 -- Give detailed information on overloaded call where none of the
265 -- interpretations match. N is the call node, Nam the designator for
266 -- the overloaded entity being called.
268 function Junk_Operand (N : Node_Id) return Boolean;
269 -- Test for an operand that is an inappropriate entity (e.g. a package
270 -- name or a label). If so, issue an error message and return True. If
271 -- the operand is not an inappropriate entity kind, return False.
273 procedure Operator_Check (N : Node_Id);
274 -- Verify that an operator has received some valid interpretation. If none
275 -- was found, determine whether a use clause would make the operation
276 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
277 -- every type compatible with the operator, even if the operator for the
278 -- type is not directly visible. The routine uses this type to emit a more
279 -- informative message.
281 function Process_Implicit_Dereference_Prefix
282 (E : Entity_Id;
283 P : Node_Id) return Entity_Id;
284 -- Called when P is the prefix of an implicit dereference, denoting an
285 -- object E. The function returns the designated type of the prefix, taking
286 -- into account that the designated type of an anonymous access type may be
287 -- a limited view, when the non-limited view is visible.
289 -- If in semantics only mode (-gnatc or generic), the function also records
290 -- that the prefix is a reference to E, if any. Normally, such a reference
291 -- is generated only when the implicit dereference is expanded into an
292 -- explicit one, but for consistency we must generate the reference when
293 -- expansion is disabled as well.
295 procedure Remove_Abstract_Operations (N : Node_Id);
296 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
297 -- operation is not a candidate interpretation.
299 function Try_Container_Indexing
300 (N : Node_Id;
301 Prefix : Node_Id;
302 Exprs : List_Id) return Boolean;
303 -- AI05-0139: Generalized indexing to support iterators over containers
305 function Try_Indexed_Call
306 (N : Node_Id;
307 Nam : Entity_Id;
308 Typ : Entity_Id;
309 Skip_First : Boolean) return Boolean;
310 -- If a function has defaults for all its actuals, a call to it may in fact
311 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
312 -- interpretation as an indexing, prior to analysis as a call. If both are
313 -- possible, the node is overloaded with both interpretations (same symbol
314 -- but two different types). If the call is written in prefix form, the
315 -- prefix becomes the first parameter in the call, and only the remaining
316 -- actuals must be checked for the presence of defaults.
318 function Try_Indirect_Call
319 (N : Node_Id;
320 Nam : Entity_Id;
321 Typ : Entity_Id) return Boolean;
322 -- Similarly, a function F that needs no actuals can return an access to a
323 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
324 -- the call may be overloaded with both interpretations.
326 procedure wpo (T : Entity_Id);
327 pragma Warnings (Off, wpo);
328 -- Used for debugging: obtain list of primitive operations even if
329 -- type is not frozen and dispatch table is not built yet.
331 ------------------------
332 -- Ambiguous_Operands --
333 ------------------------
335 procedure Ambiguous_Operands (N : Node_Id) is
336 procedure List_Operand_Interps (Opnd : Node_Id);
338 --------------------------
339 -- List_Operand_Interps --
340 --------------------------
342 procedure List_Operand_Interps (Opnd : Node_Id) is
343 Nam : Node_Id;
344 Err : Node_Id := N;
346 begin
347 if Is_Overloaded (Opnd) then
348 if Nkind (Opnd) in N_Op then
349 Nam := Opnd;
351 elsif Nkind (Opnd) = N_Function_Call then
352 Nam := Name (Opnd);
354 elsif Ada_Version >= Ada_2012 then
355 declare
356 It : Interp;
357 I : Interp_Index;
359 begin
360 Get_First_Interp (Opnd, I, It);
361 while Present (It.Nam) loop
362 if Has_Implicit_Dereference (It.Typ) then
363 Error_Msg_N
364 ("can be interpreted as implicit dereference", Opnd);
365 return;
366 end if;
368 Get_Next_Interp (I, It);
369 end loop;
370 end;
372 return;
373 end if;
375 else
376 return;
377 end if;
379 if Opnd = Left_Opnd (N) then
380 Error_Msg_N
381 ("\left operand has the following interpretations", N);
382 else
383 Error_Msg_N
384 ("\right operand has the following interpretations", N);
385 Err := Opnd;
386 end if;
388 List_Interps (Nam, Err);
389 end List_Operand_Interps;
391 -- Start of processing for Ambiguous_Operands
393 begin
394 if Nkind (N) in N_Membership_Test then
395 Error_Msg_N ("ambiguous operands for membership", N);
397 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
398 Error_Msg_N ("ambiguous operands for equality", N);
400 else
401 Error_Msg_N ("ambiguous operands for comparison", N);
402 end if;
404 if All_Errors_Mode then
405 List_Operand_Interps (Left_Opnd (N));
406 List_Operand_Interps (Right_Opnd (N));
407 else
408 Error_Msg_N ("\use -gnatf switch for details", N);
409 end if;
410 end Ambiguous_Operands;
412 -----------------------
413 -- Analyze_Aggregate --
414 -----------------------
416 -- Most of the analysis of Aggregates requires that the type be known,
417 -- and is therefore put off until resolution.
419 procedure Analyze_Aggregate (N : Node_Id) is
420 begin
421 if No (Etype (N)) then
422 Set_Etype (N, Any_Composite);
423 end if;
424 end Analyze_Aggregate;
426 -----------------------
427 -- Analyze_Allocator --
428 -----------------------
430 procedure Analyze_Allocator (N : Node_Id) is
431 Loc : constant Source_Ptr := Sloc (N);
432 Sav_Errs : constant Nat := Serious_Errors_Detected;
433 E : Node_Id := Expression (N);
434 Acc_Type : Entity_Id;
435 Type_Id : Entity_Id;
436 P : Node_Id;
437 C : Node_Id;
438 Onode : Node_Id;
440 begin
441 Check_SPARK_05_Restriction ("allocator is not allowed", N);
443 -- Deal with allocator restrictions
445 -- In accordance with H.4(7), the No_Allocators restriction only applies
446 -- to user-written allocators. The same consideration applies to the
447 -- No_Standard_Allocators_Before_Elaboration restriction.
449 if Comes_From_Source (N) then
450 Check_Restriction (No_Allocators, N);
452 -- Processing for No_Standard_Allocators_After_Elaboration, loop to
453 -- look at enclosing context, checking task/main subprogram case.
455 C := N;
456 P := Parent (C);
457 while Present (P) loop
459 -- For the task case we need a handled sequence of statements,
460 -- where the occurrence of the allocator is within the statements
461 -- and the parent is a task body
463 if Nkind (P) = N_Handled_Sequence_Of_Statements
464 and then Is_List_Member (C)
465 and then List_Containing (C) = Statements (P)
466 then
467 Onode := Original_Node (Parent (P));
469 -- Check for allocator within task body, this is a definite
470 -- violation of No_Allocators_After_Elaboration we can detect
471 -- at compile time.
473 if Nkind (Onode) = N_Task_Body then
474 Check_Restriction
475 (No_Standard_Allocators_After_Elaboration, N);
476 exit;
477 end if;
478 end if;
480 -- The other case is appearance in a subprogram body. This is
481 -- a violation if this is a library level subprogram with no
482 -- parameters. Note that this is now a static error even if the
483 -- subprogram is not the main program (this is a change, in an
484 -- earlier version only the main program was affected, and the
485 -- check had to be done in the binder.
487 if Nkind (P) = N_Subprogram_Body
488 and then Nkind (Parent (P)) = N_Compilation_Unit
489 and then No (Parameter_Specifications (Specification (P)))
490 then
491 Check_Restriction
492 (No_Standard_Allocators_After_Elaboration, N);
493 end if;
495 C := P;
496 P := Parent (C);
497 end loop;
498 end if;
500 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
501 -- any. The expected type for the name is any type. A non-overloading
502 -- rule then requires it to be of a type descended from
503 -- System.Storage_Pools.Subpools.Subpool_Handle.
505 -- This isn't exactly what the AI says, but it seems to be the right
506 -- rule. The AI should be fixed.???
508 declare
509 Subpool : constant Node_Id := Subpool_Handle_Name (N);
511 begin
512 if Present (Subpool) then
513 Analyze (Subpool);
515 if Is_Overloaded (Subpool) then
516 Error_Msg_N ("ambiguous subpool handle", Subpool);
517 end if;
519 -- Check that Etype (Subpool) is descended from Subpool_Handle
521 Resolve (Subpool);
522 end if;
523 end;
525 -- Analyze the qualified expression or subtype indication
527 if Nkind (E) = N_Qualified_Expression then
528 Acc_Type := Create_Itype (E_Allocator_Type, N);
529 Set_Etype (Acc_Type, Acc_Type);
530 Find_Type (Subtype_Mark (E));
532 -- Analyze the qualified expression, and apply the name resolution
533 -- rule given in 4.7(3).
535 Analyze (E);
536 Type_Id := Etype (E);
537 Set_Directly_Designated_Type (Acc_Type, Type_Id);
539 -- A qualified expression requires an exact match of the type,
540 -- class-wide matching is not allowed.
542 -- if Is_Class_Wide_Type (Type_Id)
543 -- and then Base_Type
544 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
545 -- then
546 -- Wrong_Type (Expression (E), Type_Id);
547 -- end if;
549 -- We don't analyze the qualified expression itself because it's
550 -- part of the allocator. It is fully analyzed and resolved when
551 -- the allocator is resolved with the context type.
553 Set_Etype (E, Type_Id);
555 -- Case where allocator has a subtype indication
557 else
558 declare
559 Def_Id : Entity_Id;
560 Base_Typ : Entity_Id;
562 begin
563 -- If the allocator includes a N_Subtype_Indication then a
564 -- constraint is present, otherwise the node is a subtype mark.
565 -- Introduce an explicit subtype declaration into the tree
566 -- defining some anonymous subtype and rewrite the allocator to
567 -- use this subtype rather than the subtype indication.
569 -- It is important to introduce the explicit subtype declaration
570 -- so that the bounds of the subtype indication are attached to
571 -- the tree in case the allocator is inside a generic unit.
573 -- Finally, if there is no subtype indication and the type is
574 -- a tagged unconstrained type with discriminants, the designated
575 -- object is constrained by their default values, and it is
576 -- simplest to introduce an explicit constraint now. In some cases
577 -- this is done during expansion, but freeze actions are certain
578 -- to be emitted in the proper order if constraint is explicit.
580 if Is_Entity_Name (E) and then Expander_Active then
581 Find_Type (E);
582 Type_Id := Entity (E);
584 if Is_Tagged_Type (Type_Id)
585 and then Has_Discriminants (Type_Id)
586 and then not Is_Constrained (Type_Id)
587 and then
588 Present
589 (Discriminant_Default_Value
590 (First_Discriminant (Type_Id)))
591 then
592 declare
593 Constr : constant List_Id := New_List;
594 Loc : constant Source_Ptr := Sloc (E);
595 Discr : Entity_Id := First_Discriminant (Type_Id);
597 begin
598 if Present (Discriminant_Default_Value (Discr)) then
599 while Present (Discr) loop
600 Append (Discriminant_Default_Value (Discr), Constr);
601 Next_Discriminant (Discr);
602 end loop;
604 Rewrite (E,
605 Make_Subtype_Indication (Loc,
606 Subtype_Mark => New_Occurrence_Of (Type_Id, Loc),
607 Constraint =>
608 Make_Index_Or_Discriminant_Constraint (Loc,
609 Constraints => Constr)));
610 end if;
611 end;
612 end if;
613 end if;
615 if Nkind (E) = N_Subtype_Indication then
617 -- A constraint is only allowed for a composite type in Ada
618 -- 95. In Ada 83, a constraint is also allowed for an
619 -- access-to-composite type, but the constraint is ignored.
621 Find_Type (Subtype_Mark (E));
622 Base_Typ := Entity (Subtype_Mark (E));
624 if Is_Elementary_Type (Base_Typ) then
625 if not (Ada_Version = Ada_83
626 and then Is_Access_Type (Base_Typ))
627 then
628 Error_Msg_N ("constraint not allowed here", E);
630 if Nkind (Constraint (E)) =
631 N_Index_Or_Discriminant_Constraint
632 then
633 Error_Msg_N -- CODEFIX
634 ("\if qualified expression was meant, " &
635 "use apostrophe", Constraint (E));
636 end if;
637 end if;
639 -- Get rid of the bogus constraint:
641 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
642 Analyze_Allocator (N);
643 return;
644 end if;
646 if Expander_Active then
647 Def_Id := Make_Temporary (Loc, 'S');
649 Insert_Action (E,
650 Make_Subtype_Declaration (Loc,
651 Defining_Identifier => Def_Id,
652 Subtype_Indication => Relocate_Node (E)));
654 if Sav_Errs /= Serious_Errors_Detected
655 and then Nkind (Constraint (E)) =
656 N_Index_Or_Discriminant_Constraint
657 then
658 Error_Msg_N -- CODEFIX
659 ("if qualified expression was meant, "
660 & "use apostrophe!", Constraint (E));
661 end if;
663 E := New_Occurrence_Of (Def_Id, Loc);
664 Rewrite (Expression (N), E);
665 end if;
666 end if;
668 Type_Id := Process_Subtype (E, N);
669 Acc_Type := Create_Itype (E_Allocator_Type, N);
670 Set_Etype (Acc_Type, Acc_Type);
671 Set_Directly_Designated_Type (Acc_Type, Type_Id);
672 Check_Fully_Declared (Type_Id, N);
674 -- Ada 2005 (AI-231): If the designated type is itself an access
675 -- type that excludes null, its default initialization will
676 -- be a null object, and we can insert an unconditional raise
677 -- before the allocator.
679 -- Ada 2012 (AI-104): A not null indication here is altogether
680 -- illegal.
682 if Can_Never_Be_Null (Type_Id) then
683 declare
684 Not_Null_Check : constant Node_Id :=
685 Make_Raise_Constraint_Error (Sloc (E),
686 Reason => CE_Null_Not_Allowed);
688 begin
689 if Expander_Active then
690 Insert_Action (N, Not_Null_Check);
691 Analyze (Not_Null_Check);
693 elsif Warn_On_Ada_2012_Compatibility then
694 Error_Msg_N
695 ("null value not allowed here in Ada 2012?y?", E);
696 end if;
697 end;
698 end if;
700 -- Check for missing initialization. Skip this check if we already
701 -- had errors on analyzing the allocator, since in that case these
702 -- are probably cascaded errors.
704 if not Is_Definite_Subtype (Type_Id)
705 and then Serious_Errors_Detected = Sav_Errs
706 then
707 -- The build-in-place machinery may produce an allocator when
708 -- the designated type is indefinite but the underlying type is
709 -- not. In this case the unknown discriminants are meaningless
710 -- and should not trigger error messages. Check the parent node
711 -- because the allocator is marked as coming from source.
713 if Present (Underlying_Type (Type_Id))
714 and then Is_Definite_Subtype (Underlying_Type (Type_Id))
715 and then not Comes_From_Source (Parent (N))
716 then
717 null;
719 -- An unusual case arises when the parent of a derived type is
720 -- a limited record extension with unknown discriminants, and
721 -- its full view has no discriminants.
723 -- A more general fix might be to create the proper underlying
724 -- type for such a derived type, but it is a record type with
725 -- no private attributes, so this required extending the
726 -- meaning of this attribute. ???
728 elsif Ekind (Etype (Type_Id)) = E_Record_Type_With_Private
729 and then Present (Underlying_Type (Etype (Type_Id)))
730 and then
731 not Has_Discriminants (Underlying_Type (Etype (Type_Id)))
732 and then not Comes_From_Source (Parent (N))
733 then
734 null;
736 elsif Is_Class_Wide_Type (Type_Id) then
737 Error_Msg_N
738 ("initialization required in class-wide allocation", N);
740 else
741 if Ada_Version < Ada_2005
742 and then Is_Limited_Type (Type_Id)
743 then
744 Error_Msg_N ("unconstrained allocation not allowed", N);
746 if Is_Array_Type (Type_Id) then
747 Error_Msg_N
748 ("\constraint with array bounds required", N);
750 elsif Has_Unknown_Discriminants (Type_Id) then
751 null;
753 else pragma Assert (Has_Discriminants (Type_Id));
754 Error_Msg_N
755 ("\constraint with discriminant values required", N);
756 end if;
758 -- Limited Ada 2005 and general non-limited case
760 else
761 Error_Msg_N
762 ("uninitialized unconstrained allocation not "
763 & "allowed", N);
765 if Is_Array_Type (Type_Id) then
766 Error_Msg_N
767 ("\qualified expression or constraint with "
768 & "array bounds required", N);
770 elsif Has_Unknown_Discriminants (Type_Id) then
771 Error_Msg_N ("\qualified expression required", N);
773 else pragma Assert (Has_Discriminants (Type_Id));
774 Error_Msg_N
775 ("\qualified expression or constraint with "
776 & "discriminant values required", N);
777 end if;
778 end if;
779 end if;
780 end if;
781 end;
782 end if;
784 if Is_Abstract_Type (Type_Id) then
785 Error_Msg_N ("cannot allocate abstract object", E);
786 end if;
788 if Has_Task (Designated_Type (Acc_Type)) then
789 Check_Restriction (No_Tasking, N);
790 Check_Restriction (Max_Tasks, N);
791 Check_Restriction (No_Task_Allocators, N);
792 end if;
794 -- Check restriction against dynamically allocated protected objects
796 if Has_Protected (Designated_Type (Acc_Type)) then
797 Check_Restriction (No_Protected_Type_Allocators, N);
798 end if;
800 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
801 -- type is nested, and the designated type needs finalization. The rule
802 -- is conservative in that class-wide types need finalization.
804 if Needs_Finalization (Designated_Type (Acc_Type))
805 and then not Is_Library_Level_Entity (Acc_Type)
806 then
807 Check_Restriction (No_Nested_Finalization, N);
808 end if;
810 -- Check that an allocator of a nested access type doesn't create a
811 -- protected object when restriction No_Local_Protected_Objects applies.
813 if Has_Protected (Designated_Type (Acc_Type))
814 and then not Is_Library_Level_Entity (Acc_Type)
815 then
816 Check_Restriction (No_Local_Protected_Objects, N);
817 end if;
819 -- Likewise for No_Local_Timing_Events
821 if Has_Timing_Event (Designated_Type (Acc_Type))
822 and then not Is_Library_Level_Entity (Acc_Type)
823 then
824 Check_Restriction (No_Local_Timing_Events, N);
825 end if;
827 -- If the No_Streams restriction is set, check that the type of the
828 -- object is not, and does not contain, any subtype derived from
829 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
830 -- Has_Stream just for efficiency reasons. There is no point in
831 -- spending time on a Has_Stream check if the restriction is not set.
833 if Restriction_Check_Required (No_Streams) then
834 if Has_Stream (Designated_Type (Acc_Type)) then
835 Check_Restriction (No_Streams, N);
836 end if;
837 end if;
839 Set_Etype (N, Acc_Type);
841 if not Is_Library_Level_Entity (Acc_Type) then
842 Check_Restriction (No_Local_Allocators, N);
843 end if;
845 if Serious_Errors_Detected > Sav_Errs then
846 Set_Error_Posted (N);
847 Set_Etype (N, Any_Type);
848 end if;
849 end Analyze_Allocator;
851 ---------------------------
852 -- Analyze_Arithmetic_Op --
853 ---------------------------
855 procedure Analyze_Arithmetic_Op (N : Node_Id) is
856 L : constant Node_Id := Left_Opnd (N);
857 R : constant Node_Id := Right_Opnd (N);
858 Op_Id : Entity_Id;
860 begin
861 Candidate_Type := Empty;
862 Analyze_Expression (L);
863 Analyze_Expression (R);
865 -- If the entity is already set, the node is the instantiation of a
866 -- generic node with a non-local reference, or was manufactured by a
867 -- call to Make_Op_xxx. In either case the entity is known to be valid,
868 -- and we do not need to collect interpretations, instead we just get
869 -- the single possible interpretation.
871 Op_Id := Entity (N);
873 if Present (Op_Id) then
874 if Ekind (Op_Id) = E_Operator then
876 if Nkind_In (N, N_Op_Divide, N_Op_Mod, N_Op_Multiply, N_Op_Rem)
877 and then Treat_Fixed_As_Integer (N)
878 then
879 null;
880 else
881 Set_Etype (N, Any_Type);
882 Find_Arithmetic_Types (L, R, Op_Id, N);
883 end if;
885 else
886 Set_Etype (N, Any_Type);
887 Add_One_Interp (N, Op_Id, Etype (Op_Id));
888 end if;
890 -- Entity is not already set, so we do need to collect interpretations
892 else
893 Set_Etype (N, Any_Type);
895 Op_Id := Get_Name_Entity_Id (Chars (N));
896 while Present (Op_Id) loop
897 if Ekind (Op_Id) = E_Operator
898 and then Present (Next_Entity (First_Entity (Op_Id)))
899 then
900 Find_Arithmetic_Types (L, R, Op_Id, N);
902 -- The following may seem superfluous, because an operator cannot
903 -- be generic, but this ignores the cleverness of the author of
904 -- ACVC bc1013a.
906 elsif Is_Overloadable (Op_Id) then
907 Analyze_User_Defined_Binary_Op (N, Op_Id);
908 end if;
910 Op_Id := Homonym (Op_Id);
911 end loop;
912 end if;
914 Operator_Check (N);
915 Check_Function_Writable_Actuals (N);
916 end Analyze_Arithmetic_Op;
918 ------------------
919 -- Analyze_Call --
920 ------------------
922 -- Function, procedure, and entry calls are checked here. The Name in
923 -- the call may be overloaded. The actuals have been analyzed and may
924 -- themselves be overloaded. On exit from this procedure, the node N
925 -- may have zero, one or more interpretations. In the first case an
926 -- error message is produced. In the last case, the node is flagged
927 -- as overloaded and the interpretations are collected in All_Interp.
929 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
930 -- the type-checking is similar to that of other calls.
932 procedure Analyze_Call (N : Node_Id) is
933 Actuals : constant List_Id := Parameter_Associations (N);
934 Loc : constant Source_Ptr := Sloc (N);
935 Nam : Node_Id;
936 X : Interp_Index;
937 It : Interp;
938 Nam_Ent : Entity_Id;
939 Success : Boolean := False;
941 Deref : Boolean := False;
942 -- Flag indicates whether an interpretation of the prefix is a
943 -- parameterless call that returns an access_to_subprogram.
945 procedure Check_Mixed_Parameter_And_Named_Associations;
946 -- Check that parameter and named associations are not mixed. This is
947 -- a restriction in SPARK mode.
949 procedure Check_Writable_Actuals (N : Node_Id);
950 -- If the call has out or in-out parameters then mark its outermost
951 -- enclosing construct as a node on which the writable actuals check
952 -- must be performed.
954 function Name_Denotes_Function return Boolean;
955 -- If the type of the name is an access to subprogram, this may be the
956 -- type of a name, or the return type of the function being called. If
957 -- the name is not an entity then it can denote a protected function.
958 -- Until we distinguish Etype from Return_Type, we must use this routine
959 -- to resolve the meaning of the name in the call.
961 procedure No_Interpretation;
962 -- Output error message when no valid interpretation exists
964 --------------------------------------------------
965 -- Check_Mixed_Parameter_And_Named_Associations --
966 --------------------------------------------------
968 procedure Check_Mixed_Parameter_And_Named_Associations is
969 Actual : Node_Id;
970 Named_Seen : Boolean;
972 begin
973 Named_Seen := False;
975 Actual := First (Actuals);
976 while Present (Actual) loop
977 case Nkind (Actual) is
978 when N_Parameter_Association =>
979 if Named_Seen then
980 Check_SPARK_05_Restriction
981 ("named association cannot follow positional one",
982 Actual);
983 exit;
984 end if;
986 when others =>
987 Named_Seen := True;
988 end case;
990 Next (Actual);
991 end loop;
992 end Check_Mixed_Parameter_And_Named_Associations;
994 ----------------------------
995 -- Check_Writable_Actuals --
996 ----------------------------
998 -- The identification of conflicts in calls to functions with writable
999 -- actuals is performed in the analysis phase of the front end to ensure
1000 -- that it reports exactly the same errors compiling with and without
1001 -- expansion enabled. It is performed in two stages:
1003 -- 1) When a call to a function with out-mode parameters is found,
1004 -- we climb to the outermost enclosing construct that can be
1005 -- evaluated in arbitrary order and we mark it with the flag
1006 -- Check_Actuals.
1008 -- 2) When the analysis of the marked node is complete, we traverse
1009 -- its decorated subtree searching for conflicts (see function
1010 -- Sem_Util.Check_Function_Writable_Actuals).
1012 -- The unique exception to this general rule is for aggregates, since
1013 -- their analysis is performed by the front end in the resolution
1014 -- phase. For aggregates we do not climb to their enclosing construct:
1015 -- we restrict the analysis to the subexpressions initializing the
1016 -- aggregate components.
1018 -- This implies that the analysis of expressions containing aggregates
1019 -- is not complete, since there may be conflicts on writable actuals
1020 -- involving subexpressions of the enclosing logical or arithmetic
1021 -- expressions. However, we cannot wait and perform the analysis when
1022 -- the whole subtree is resolved, since the subtrees may be transformed,
1023 -- thus adding extra complexity and computation cost to identify and
1024 -- report exactly the same errors compiling with and without expansion
1025 -- enabled.
1027 procedure Check_Writable_Actuals (N : Node_Id) is
1028 begin
1029 if Comes_From_Source (N)
1030 and then Present (Get_Subprogram_Entity (N))
1031 and then Has_Out_Or_In_Out_Parameter (Get_Subprogram_Entity (N))
1032 then
1033 -- For procedures and entries there is no need to climb since
1034 -- we only need to check if the actuals of this call invoke
1035 -- functions whose out-mode parameters overlap.
1037 if Nkind (N) /= N_Function_Call then
1038 Set_Check_Actuals (N);
1040 -- For calls to functions we climb to the outermost enclosing
1041 -- construct where the out-mode actuals of this function may
1042 -- introduce conflicts.
1044 else
1045 declare
1046 Outermost : Node_Id;
1047 P : Node_Id := N;
1049 begin
1050 while Present (P) loop
1052 -- For object declarations we can climb to the node from
1053 -- its object definition branch or from its initializing
1054 -- expression. We prefer to mark the child node as the
1055 -- outermost construct to avoid adding further complexity
1056 -- to the routine that will later take care of
1057 -- performing the writable actuals check.
1059 if Has_Arbitrary_Evaluation_Order (Nkind (P))
1060 and then not Nkind_In (P, N_Assignment_Statement,
1061 N_Object_Declaration)
1062 then
1063 Outermost := P;
1064 end if;
1066 -- Avoid climbing more than needed!
1068 exit when Stop_Subtree_Climbing (Nkind (P))
1069 or else (Nkind (P) = N_Range
1070 and then not
1071 Nkind_In (Parent (P), N_In, N_Not_In));
1073 P := Parent (P);
1074 end loop;
1076 Set_Check_Actuals (Outermost);
1077 end;
1078 end if;
1079 end if;
1080 end Check_Writable_Actuals;
1082 ---------------------------
1083 -- Name_Denotes_Function --
1084 ---------------------------
1086 function Name_Denotes_Function return Boolean is
1087 begin
1088 if Is_Entity_Name (Nam) then
1089 return Ekind (Entity (Nam)) = E_Function;
1090 elsif Nkind (Nam) = N_Selected_Component then
1091 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
1092 else
1093 return False;
1094 end if;
1095 end Name_Denotes_Function;
1097 -----------------------
1098 -- No_Interpretation --
1099 -----------------------
1101 procedure No_Interpretation is
1102 L : constant Boolean := Is_List_Member (N);
1103 K : constant Node_Kind := Nkind (Parent (N));
1105 begin
1106 -- If the node is in a list whose parent is not an expression then it
1107 -- must be an attempted procedure call.
1109 if L and then K not in N_Subexpr then
1110 if Ekind (Entity (Nam)) = E_Generic_Procedure then
1111 Error_Msg_NE
1112 ("must instantiate generic procedure& before call",
1113 Nam, Entity (Nam));
1114 else
1115 Error_Msg_N ("procedure or entry name expected", Nam);
1116 end if;
1118 -- Check for tasking cases where only an entry call will do
1120 elsif not L
1121 and then Nkind_In (K, N_Entry_Call_Alternative,
1122 N_Triggering_Alternative)
1123 then
1124 Error_Msg_N ("entry name expected", Nam);
1126 -- Otherwise give general error message
1128 else
1129 Error_Msg_N ("invalid prefix in call", Nam);
1130 end if;
1131 end No_Interpretation;
1133 -- Start of processing for Analyze_Call
1135 begin
1136 if Restriction_Check_Required (SPARK_05) then
1137 Check_Mixed_Parameter_And_Named_Associations;
1138 end if;
1140 -- Initialize the type of the result of the call to the error type,
1141 -- which will be reset if the type is successfully resolved.
1143 Set_Etype (N, Any_Type);
1145 Nam := Name (N);
1147 if not Is_Overloaded (Nam) then
1149 -- Only one interpretation to check
1151 if Ekind (Etype (Nam)) = E_Subprogram_Type then
1152 Nam_Ent := Etype (Nam);
1154 -- If the prefix is an access_to_subprogram, this may be an indirect
1155 -- call. This is the case if the name in the call is not an entity
1156 -- name, or if it is a function name in the context of a procedure
1157 -- call. In this latter case, we have a call to a parameterless
1158 -- function that returns a pointer_to_procedure which is the entity
1159 -- being called. Finally, F (X) may be a call to a parameterless
1160 -- function that returns a pointer to a function with parameters.
1161 -- Note that if F returns an access-to-subprogram whose designated
1162 -- type is an array, F (X) cannot be interpreted as an indirect call
1163 -- through the result of the call to F.
1165 elsif Is_Access_Type (Etype (Nam))
1166 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
1167 and then
1168 (not Name_Denotes_Function
1169 or else Nkind (N) = N_Procedure_Call_Statement
1170 or else
1171 (Nkind (Parent (N)) /= N_Explicit_Dereference
1172 and then Is_Entity_Name (Nam)
1173 and then No (First_Formal (Entity (Nam)))
1174 and then not
1175 Is_Array_Type (Etype (Designated_Type (Etype (Nam))))
1176 and then Present (Actuals)))
1177 then
1178 Nam_Ent := Designated_Type (Etype (Nam));
1179 Insert_Explicit_Dereference (Nam);
1181 -- Selected component case. Simple entry or protected operation,
1182 -- where the entry name is given by the selector name.
1184 elsif Nkind (Nam) = N_Selected_Component then
1185 Nam_Ent := Entity (Selector_Name (Nam));
1187 if not Ekind_In (Nam_Ent, E_Entry,
1188 E_Entry_Family,
1189 E_Function,
1190 E_Procedure)
1191 then
1192 Error_Msg_N ("name in call is not a callable entity", Nam);
1193 Set_Etype (N, Any_Type);
1194 return;
1195 end if;
1197 -- If the name is an Indexed component, it can be a call to a member
1198 -- of an entry family. The prefix must be a selected component whose
1199 -- selector is the entry. Analyze_Procedure_Call normalizes several
1200 -- kinds of call into this form.
1202 elsif Nkind (Nam) = N_Indexed_Component then
1203 if Nkind (Prefix (Nam)) = N_Selected_Component then
1204 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
1205 else
1206 Error_Msg_N ("name in call is not a callable entity", Nam);
1207 Set_Etype (N, Any_Type);
1208 return;
1209 end if;
1211 elsif not Is_Entity_Name (Nam) then
1212 Error_Msg_N ("name in call is not a callable entity", Nam);
1213 Set_Etype (N, Any_Type);
1214 return;
1216 else
1217 Nam_Ent := Entity (Nam);
1219 -- If not overloadable, this may be a generalized indexing
1220 -- operation with named associations. Rewrite again as an
1221 -- indexed component and analyze as container indexing.
1223 if not Is_Overloadable (Nam_Ent) then
1224 if Present
1225 (Find_Value_Of_Aspect
1226 (Etype (Nam_Ent), Aspect_Constant_Indexing))
1227 then
1228 Replace (N,
1229 Make_Indexed_Component (Sloc (N),
1230 Prefix => Nam,
1231 Expressions => Parameter_Associations (N)));
1233 if Try_Container_Indexing (N, Nam, Expressions (N)) then
1234 return;
1235 else
1236 No_Interpretation;
1237 end if;
1239 else
1240 No_Interpretation;
1241 end if;
1243 return;
1244 end if;
1245 end if;
1247 -- Operations generated for RACW stub types are called only through
1248 -- dispatching, and can never be the static interpretation of a call.
1250 if Is_RACW_Stub_Type_Operation (Nam_Ent) then
1251 No_Interpretation;
1252 return;
1253 end if;
1255 Analyze_One_Call (N, Nam_Ent, True, Success);
1257 -- If this is an indirect call, the return type of the access_to
1258 -- subprogram may be an incomplete type. At the point of the call,
1259 -- use the full type if available, and at the same time update the
1260 -- return type of the access_to_subprogram.
1262 if Success
1263 and then Nkind (Nam) = N_Explicit_Dereference
1264 and then Ekind (Etype (N)) = E_Incomplete_Type
1265 and then Present (Full_View (Etype (N)))
1266 then
1267 Set_Etype (N, Full_View (Etype (N)));
1268 Set_Etype (Nam_Ent, Etype (N));
1269 end if;
1271 -- Overloaded call
1273 else
1274 -- An overloaded selected component must denote overloaded operations
1275 -- of a concurrent type. The interpretations are attached to the
1276 -- simple name of those operations.
1278 if Nkind (Nam) = N_Selected_Component then
1279 Nam := Selector_Name (Nam);
1280 end if;
1282 Get_First_Interp (Nam, X, It);
1283 while Present (It.Nam) loop
1284 Nam_Ent := It.Nam;
1285 Deref := False;
1287 -- Name may be call that returns an access to subprogram, or more
1288 -- generally an overloaded expression one of whose interpretations
1289 -- yields an access to subprogram. If the name is an entity, we do
1290 -- not dereference, because the node is a call that returns the
1291 -- access type: note difference between f(x), where the call may
1292 -- return an access subprogram type, and f(x)(y), where the type
1293 -- returned by the call to f is implicitly dereferenced to analyze
1294 -- the outer call.
1296 if Is_Access_Type (Nam_Ent) then
1297 Nam_Ent := Designated_Type (Nam_Ent);
1299 elsif Is_Access_Type (Etype (Nam_Ent))
1300 and then
1301 (not Is_Entity_Name (Nam)
1302 or else Nkind (N) = N_Procedure_Call_Statement)
1303 and then Ekind (Designated_Type (Etype (Nam_Ent)))
1304 = E_Subprogram_Type
1305 then
1306 Nam_Ent := Designated_Type (Etype (Nam_Ent));
1308 if Is_Entity_Name (Nam) then
1309 Deref := True;
1310 end if;
1311 end if;
1313 -- If the call has been rewritten from a prefixed call, the first
1314 -- parameter has been analyzed, but may need a subsequent
1315 -- dereference, so skip its analysis now.
1317 if N /= Original_Node (N)
1318 and then Nkind (Original_Node (N)) = Nkind (N)
1319 and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N)))
1320 and then Present (Parameter_Associations (N))
1321 and then Present (Etype (First (Parameter_Associations (N))))
1322 then
1323 Analyze_One_Call
1324 (N, Nam_Ent, False, Success, Skip_First => True);
1325 else
1326 Analyze_One_Call (N, Nam_Ent, False, Success);
1327 end if;
1329 -- If the interpretation succeeds, mark the proper type of the
1330 -- prefix (any valid candidate will do). If not, remove the
1331 -- candidate interpretation. If this is a parameterless call
1332 -- on an anonymous access to subprogram, X is a variable with
1333 -- an access discriminant D, the entity in the interpretation is
1334 -- D, so rewrite X as X.D.all.
1336 if Success then
1337 if Deref
1338 and then Nkind (Parent (N)) /= N_Explicit_Dereference
1339 then
1340 if Ekind (It.Nam) = E_Discriminant
1341 and then Has_Implicit_Dereference (It.Nam)
1342 then
1343 Rewrite (Name (N),
1344 Make_Explicit_Dereference (Loc,
1345 Prefix =>
1346 Make_Selected_Component (Loc,
1347 Prefix =>
1348 New_Occurrence_Of (Entity (Nam), Loc),
1349 Selector_Name =>
1350 New_Occurrence_Of (It.Nam, Loc))));
1352 Analyze (N);
1353 return;
1355 else
1356 Set_Entity (Nam, It.Nam);
1357 Insert_Explicit_Dereference (Nam);
1358 Set_Etype (Nam, Nam_Ent);
1359 end if;
1361 else
1362 Set_Etype (Nam, It.Typ);
1363 end if;
1365 elsif Nkind_In (Name (N), N_Function_Call, N_Selected_Component)
1366 then
1367 Remove_Interp (X);
1368 end if;
1370 Get_Next_Interp (X, It);
1371 end loop;
1373 -- If the name is the result of a function call, it can only be a
1374 -- call to a function returning an access to subprogram. Insert
1375 -- explicit dereference.
1377 if Nkind (Nam) = N_Function_Call then
1378 Insert_Explicit_Dereference (Nam);
1379 end if;
1381 if Etype (N) = Any_Type then
1383 -- None of the interpretations is compatible with the actuals
1385 Diagnose_Call (N, Nam);
1387 -- Special checks for uninstantiated put routines
1389 if Nkind (N) = N_Procedure_Call_Statement
1390 and then Is_Entity_Name (Nam)
1391 and then Chars (Nam) = Name_Put
1392 and then List_Length (Actuals) = 1
1393 then
1394 declare
1395 Arg : constant Node_Id := First (Actuals);
1396 Typ : Entity_Id;
1398 begin
1399 if Nkind (Arg) = N_Parameter_Association then
1400 Typ := Etype (Explicit_Actual_Parameter (Arg));
1401 else
1402 Typ := Etype (Arg);
1403 end if;
1405 if Is_Signed_Integer_Type (Typ) then
1406 Error_Msg_N
1407 ("possible missing instantiation of "
1408 & "'Text_'I'O.'Integer_'I'O!", Nam);
1410 elsif Is_Modular_Integer_Type (Typ) then
1411 Error_Msg_N
1412 ("possible missing instantiation of "
1413 & "'Text_'I'O.'Modular_'I'O!", Nam);
1415 elsif Is_Floating_Point_Type (Typ) then
1416 Error_Msg_N
1417 ("possible missing instantiation of "
1418 & "'Text_'I'O.'Float_'I'O!", Nam);
1420 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
1421 Error_Msg_N
1422 ("possible missing instantiation of "
1423 & "'Text_'I'O.'Fixed_'I'O!", Nam);
1425 elsif Is_Decimal_Fixed_Point_Type (Typ) then
1426 Error_Msg_N
1427 ("possible missing instantiation of "
1428 & "'Text_'I'O.'Decimal_'I'O!", Nam);
1430 elsif Is_Enumeration_Type (Typ) then
1431 Error_Msg_N
1432 ("possible missing instantiation of "
1433 & "'Text_'I'O.'Enumeration_'I'O!", Nam);
1434 end if;
1435 end;
1436 end if;
1438 elsif not Is_Overloaded (N)
1439 and then Is_Entity_Name (Nam)
1440 then
1441 -- Resolution yields a single interpretation. Verify that the
1442 -- reference has capitalization consistent with the declaration.
1444 Set_Entity_With_Checks (Nam, Entity (Nam));
1445 Generate_Reference (Entity (Nam), Nam);
1447 Set_Etype (Nam, Etype (Entity (Nam)));
1448 else
1449 Remove_Abstract_Operations (N);
1450 end if;
1452 End_Interp_List;
1453 end if;
1455 if Ada_Version >= Ada_2012 then
1457 -- Check if the call contains a function with writable actuals
1459 Check_Writable_Actuals (N);
1461 -- If found and the outermost construct that can be evaluated in
1462 -- an arbitrary order is precisely this call, then check all its
1463 -- actuals.
1465 Check_Function_Writable_Actuals (N);
1466 end if;
1467 end Analyze_Call;
1469 -----------------------------
1470 -- Analyze_Case_Expression --
1471 -----------------------------
1473 procedure Analyze_Case_Expression (N : Node_Id) is
1474 procedure Non_Static_Choice_Error (Choice : Node_Id);
1475 -- Error routine invoked by the generic instantiation below when
1476 -- the case expression has a non static choice.
1478 package Case_Choices_Analysis is new
1479 Generic_Analyze_Choices
1480 (Process_Associated_Node => No_OP);
1481 use Case_Choices_Analysis;
1483 package Case_Choices_Checking is new
1484 Generic_Check_Choices
1485 (Process_Empty_Choice => No_OP,
1486 Process_Non_Static_Choice => Non_Static_Choice_Error,
1487 Process_Associated_Node => No_OP);
1488 use Case_Choices_Checking;
1490 -----------------------------
1491 -- Non_Static_Choice_Error --
1492 -----------------------------
1494 procedure Non_Static_Choice_Error (Choice : Node_Id) is
1495 begin
1496 Flag_Non_Static_Expr
1497 ("choice given in case expression is not static!", Choice);
1498 end Non_Static_Choice_Error;
1500 -- Local variables
1502 Expr : constant Node_Id := Expression (N);
1503 Alt : Node_Id;
1504 Exp_Type : Entity_Id;
1505 Exp_Btype : Entity_Id;
1507 FirstX : Node_Id := Empty;
1508 -- First expression in the case for which there is some type information
1509 -- available, i.e. it is not Any_Type, which can happen because of some
1510 -- error, or from the use of e.g. raise Constraint_Error.
1512 Others_Present : Boolean;
1513 -- Indicates if Others was present
1515 Wrong_Alt : Node_Id := Empty;
1516 -- For error reporting
1518 -- Start of processing for Analyze_Case_Expression
1520 begin
1521 if Comes_From_Source (N) then
1522 Check_Compiler_Unit ("case expression", N);
1523 end if;
1525 Analyze_And_Resolve (Expr, Any_Discrete);
1526 Check_Unset_Reference (Expr);
1527 Exp_Type := Etype (Expr);
1528 Exp_Btype := Base_Type (Exp_Type);
1530 Alt := First (Alternatives (N));
1531 while Present (Alt) loop
1532 Analyze (Expression (Alt));
1534 if No (FirstX) and then Etype (Expression (Alt)) /= Any_Type then
1535 FirstX := Expression (Alt);
1536 end if;
1538 Next (Alt);
1539 end loop;
1541 -- Get our initial type from the first expression for which we got some
1542 -- useful type information from the expression.
1544 if not Is_Overloaded (FirstX) then
1545 Set_Etype (N, Etype (FirstX));
1547 else
1548 declare
1549 I : Interp_Index;
1550 It : Interp;
1552 begin
1553 Set_Etype (N, Any_Type);
1555 Get_First_Interp (FirstX, I, It);
1556 while Present (It.Nam) loop
1558 -- For each interpretation of the first expression, we only
1559 -- add the interpretation if every other expression in the
1560 -- case expression alternatives has a compatible type.
1562 Alt := Next (First (Alternatives (N)));
1563 while Present (Alt) loop
1564 exit when not Has_Compatible_Type (Expression (Alt), It.Typ);
1565 Next (Alt);
1566 end loop;
1568 if No (Alt) then
1569 Add_One_Interp (N, It.Typ, It.Typ);
1570 else
1571 Wrong_Alt := Alt;
1572 end if;
1574 Get_Next_Interp (I, It);
1575 end loop;
1576 end;
1577 end if;
1579 Exp_Btype := Base_Type (Exp_Type);
1581 -- The expression must be of a discrete type which must be determinable
1582 -- independently of the context in which the expression occurs, but
1583 -- using the fact that the expression must be of a discrete type.
1584 -- Moreover, the type this expression must not be a character literal
1585 -- (which is always ambiguous).
1587 -- If error already reported by Resolve, nothing more to do
1589 if Exp_Btype = Any_Discrete or else Exp_Btype = Any_Type then
1590 return;
1592 -- Special casee message for character literal
1594 elsif Exp_Btype = Any_Character then
1595 Error_Msg_N
1596 ("character literal as case expression is ambiguous", Expr);
1597 return;
1598 end if;
1600 if Etype (N) = Any_Type and then Present (Wrong_Alt) then
1601 Error_Msg_N
1602 ("type incompatible with that of previous alternatives",
1603 Expression (Wrong_Alt));
1604 return;
1605 end if;
1607 -- If the case expression is a formal object of mode in out, then
1608 -- treat it as having a nonstatic subtype by forcing use of the base
1609 -- type (which has to get passed to Check_Case_Choices below). Also
1610 -- use base type when the case expression is parenthesized.
1612 if Paren_Count (Expr) > 0
1613 or else (Is_Entity_Name (Expr)
1614 and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter)
1615 then
1616 Exp_Type := Exp_Btype;
1617 end if;
1619 -- The case expression alternatives cover the range of a static subtype
1620 -- subject to aspect Static_Predicate. Do not check the choices when the
1621 -- case expression has not been fully analyzed yet because this may lead
1622 -- to bogus errors.
1624 if Is_OK_Static_Subtype (Exp_Type)
1625 and then Has_Static_Predicate_Aspect (Exp_Type)
1626 and then In_Spec_Expression
1627 then
1628 null;
1630 -- Call Analyze_Choices and Check_Choices to do the rest of the work
1632 else
1633 Analyze_Choices (Alternatives (N), Exp_Type);
1634 Check_Choices (N, Alternatives (N), Exp_Type, Others_Present);
1635 end if;
1637 if Exp_Type = Universal_Integer and then not Others_Present then
1638 Error_Msg_N
1639 ("case on universal integer requires OTHERS choice", Expr);
1640 end if;
1641 end Analyze_Case_Expression;
1643 ---------------------------
1644 -- Analyze_Comparison_Op --
1645 ---------------------------
1647 procedure Analyze_Comparison_Op (N : Node_Id) is
1648 L : constant Node_Id := Left_Opnd (N);
1649 R : constant Node_Id := Right_Opnd (N);
1650 Op_Id : Entity_Id := Entity (N);
1652 begin
1653 Set_Etype (N, Any_Type);
1654 Candidate_Type := Empty;
1656 Analyze_Expression (L);
1657 Analyze_Expression (R);
1659 if Present (Op_Id) then
1660 if Ekind (Op_Id) = E_Operator then
1661 Find_Comparison_Types (L, R, Op_Id, N);
1662 else
1663 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1664 end if;
1666 if Is_Overloaded (L) then
1667 Set_Etype (L, Intersect_Types (L, R));
1668 end if;
1670 else
1671 Op_Id := Get_Name_Entity_Id (Chars (N));
1672 while Present (Op_Id) loop
1673 if Ekind (Op_Id) = E_Operator then
1674 Find_Comparison_Types (L, R, Op_Id, N);
1675 else
1676 Analyze_User_Defined_Binary_Op (N, Op_Id);
1677 end if;
1679 Op_Id := Homonym (Op_Id);
1680 end loop;
1681 end if;
1683 Operator_Check (N);
1684 Check_Function_Writable_Actuals (N);
1685 end Analyze_Comparison_Op;
1687 ---------------------------
1688 -- Analyze_Concatenation --
1689 ---------------------------
1691 procedure Analyze_Concatenation (N : Node_Id) is
1693 -- We wish to avoid deep recursion, because concatenations are often
1694 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1695 -- operands nonrecursively until we find something that is not a
1696 -- concatenation (A in this case), or has already been analyzed. We
1697 -- analyze that, and then walk back up the tree following Parent
1698 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1699 -- work at each level. The Parent pointers allow us to avoid recursion,
1700 -- and thus avoid running out of memory.
1702 NN : Node_Id := N;
1703 L : Node_Id;
1705 begin
1706 Candidate_Type := Empty;
1708 -- The following code is equivalent to:
1710 -- Set_Etype (N, Any_Type);
1711 -- Analyze_Expression (Left_Opnd (N));
1712 -- Analyze_Concatenation_Rest (N);
1714 -- where the Analyze_Expression call recurses back here if the left
1715 -- operand is a concatenation.
1717 -- Walk down left operands
1719 loop
1720 Set_Etype (NN, Any_Type);
1721 L := Left_Opnd (NN);
1722 exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
1723 NN := L;
1724 end loop;
1726 -- Now (given the above example) NN is A&B and L is A
1728 -- First analyze L ...
1730 Analyze_Expression (L);
1732 -- ... then walk NN back up until we reach N (where we started), calling
1733 -- Analyze_Concatenation_Rest along the way.
1735 loop
1736 Analyze_Concatenation_Rest (NN);
1737 exit when NN = N;
1738 NN := Parent (NN);
1739 end loop;
1740 end Analyze_Concatenation;
1742 --------------------------------
1743 -- Analyze_Concatenation_Rest --
1744 --------------------------------
1746 -- If the only one-dimensional array type in scope is String,
1747 -- this is the resulting type of the operation. Otherwise there
1748 -- will be a concatenation operation defined for each user-defined
1749 -- one-dimensional array.
1751 procedure Analyze_Concatenation_Rest (N : Node_Id) is
1752 L : constant Node_Id := Left_Opnd (N);
1753 R : constant Node_Id := Right_Opnd (N);
1754 Op_Id : Entity_Id := Entity (N);
1755 LT : Entity_Id;
1756 RT : Entity_Id;
1758 begin
1759 Analyze_Expression (R);
1761 -- If the entity is present, the node appears in an instance, and
1762 -- denotes a predefined concatenation operation. The resulting type is
1763 -- obtained from the arguments when possible. If the arguments are
1764 -- aggregates, the array type and the concatenation type must be
1765 -- visible.
1767 if Present (Op_Id) then
1768 if Ekind (Op_Id) = E_Operator then
1769 LT := Base_Type (Etype (L));
1770 RT := Base_Type (Etype (R));
1772 if Is_Array_Type (LT)
1773 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1774 then
1775 Add_One_Interp (N, Op_Id, LT);
1777 elsif Is_Array_Type (RT)
1778 and then LT = Base_Type (Component_Type (RT))
1779 then
1780 Add_One_Interp (N, Op_Id, RT);
1782 -- If one operand is a string type or a user-defined array type,
1783 -- and the other is a literal, result is of the specific type.
1785 elsif
1786 (Root_Type (LT) = Standard_String
1787 or else Scope (LT) /= Standard_Standard)
1788 and then Etype (R) = Any_String
1789 then
1790 Add_One_Interp (N, Op_Id, LT);
1792 elsif
1793 (Root_Type (RT) = Standard_String
1794 or else Scope (RT) /= Standard_Standard)
1795 and then Etype (L) = Any_String
1796 then
1797 Add_One_Interp (N, Op_Id, RT);
1799 elsif not Is_Generic_Type (Etype (Op_Id)) then
1800 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1802 else
1803 -- Type and its operations must be visible
1805 Set_Entity (N, Empty);
1806 Analyze_Concatenation (N);
1807 end if;
1809 else
1810 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1811 end if;
1813 else
1814 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1815 while Present (Op_Id) loop
1816 if Ekind (Op_Id) = E_Operator then
1818 -- Do not consider operators declared in dead code, they can
1819 -- not be part of the resolution.
1821 if Is_Eliminated (Op_Id) then
1822 null;
1823 else
1824 Find_Concatenation_Types (L, R, Op_Id, N);
1825 end if;
1827 else
1828 Analyze_User_Defined_Binary_Op (N, Op_Id);
1829 end if;
1831 Op_Id := Homonym (Op_Id);
1832 end loop;
1833 end if;
1835 Operator_Check (N);
1836 end Analyze_Concatenation_Rest;
1838 -------------------------
1839 -- Analyze_Equality_Op --
1840 -------------------------
1842 procedure Analyze_Equality_Op (N : Node_Id) is
1843 Loc : constant Source_Ptr := Sloc (N);
1844 L : constant Node_Id := Left_Opnd (N);
1845 R : constant Node_Id := Right_Opnd (N);
1846 Op_Id : Entity_Id;
1848 begin
1849 Set_Etype (N, Any_Type);
1850 Candidate_Type := Empty;
1852 Analyze_Expression (L);
1853 Analyze_Expression (R);
1855 -- If the entity is set, the node is a generic instance with a non-local
1856 -- reference to the predefined operator or to a user-defined function.
1857 -- It can also be an inequality that is expanded into the negation of a
1858 -- call to a user-defined equality operator.
1860 -- For the predefined case, the result is Boolean, regardless of the
1861 -- type of the operands. The operands may even be limited, if they are
1862 -- generic actuals. If they are overloaded, label the left argument with
1863 -- the common type that must be present, or with the type of the formal
1864 -- of the user-defined function.
1866 if Present (Entity (N)) then
1867 Op_Id := Entity (N);
1869 if Ekind (Op_Id) = E_Operator then
1870 Add_One_Interp (N, Op_Id, Standard_Boolean);
1871 else
1872 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1873 end if;
1875 if Is_Overloaded (L) then
1876 if Ekind (Op_Id) = E_Operator then
1877 Set_Etype (L, Intersect_Types (L, R));
1878 else
1879 Set_Etype (L, Etype (First_Formal (Op_Id)));
1880 end if;
1881 end if;
1883 else
1884 Op_Id := Get_Name_Entity_Id (Chars (N));
1885 while Present (Op_Id) loop
1886 if Ekind (Op_Id) = E_Operator then
1887 Find_Equality_Types (L, R, Op_Id, N);
1888 else
1889 Analyze_User_Defined_Binary_Op (N, Op_Id);
1890 end if;
1892 Op_Id := Homonym (Op_Id);
1893 end loop;
1894 end if;
1896 -- If there was no match, and the operator is inequality, this may be
1897 -- a case where inequality has not been made explicit, as for tagged
1898 -- types. Analyze the node as the negation of an equality operation.
1899 -- This cannot be done earlier, because before analysis we cannot rule
1900 -- out the presence of an explicit inequality.
1902 if Etype (N) = Any_Type
1903 and then Nkind (N) = N_Op_Ne
1904 then
1905 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1906 while Present (Op_Id) loop
1907 if Ekind (Op_Id) = E_Operator then
1908 Find_Equality_Types (L, R, Op_Id, N);
1909 else
1910 Analyze_User_Defined_Binary_Op (N, Op_Id);
1911 end if;
1913 Op_Id := Homonym (Op_Id);
1914 end loop;
1916 if Etype (N) /= Any_Type then
1917 Op_Id := Entity (N);
1919 Rewrite (N,
1920 Make_Op_Not (Loc,
1921 Right_Opnd =>
1922 Make_Op_Eq (Loc,
1923 Left_Opnd => Left_Opnd (N),
1924 Right_Opnd => Right_Opnd (N))));
1926 Set_Entity (Right_Opnd (N), Op_Id);
1927 Analyze (N);
1928 end if;
1929 end if;
1931 Operator_Check (N);
1932 Check_Function_Writable_Actuals (N);
1933 end Analyze_Equality_Op;
1935 ----------------------------------
1936 -- Analyze_Explicit_Dereference --
1937 ----------------------------------
1939 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1940 Loc : constant Source_Ptr := Sloc (N);
1941 P : constant Node_Id := Prefix (N);
1942 T : Entity_Id;
1943 I : Interp_Index;
1944 It : Interp;
1945 New_N : Node_Id;
1947 function Is_Function_Type return Boolean;
1948 -- Check whether node may be interpreted as an implicit function call
1950 ----------------------
1951 -- Is_Function_Type --
1952 ----------------------
1954 function Is_Function_Type return Boolean is
1955 I : Interp_Index;
1956 It : Interp;
1958 begin
1959 if not Is_Overloaded (N) then
1960 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1961 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1963 else
1964 Get_First_Interp (N, I, It);
1965 while Present (It.Nam) loop
1966 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1967 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1968 then
1969 return False;
1970 end if;
1972 Get_Next_Interp (I, It);
1973 end loop;
1975 return True;
1976 end if;
1977 end Is_Function_Type;
1979 -- Start of processing for Analyze_Explicit_Dereference
1981 begin
1982 -- If source node, check SPARK restriction. We guard this with the
1983 -- source node check, because ???
1985 if Comes_From_Source (N) then
1986 Check_SPARK_05_Restriction ("explicit dereference is not allowed", N);
1987 end if;
1989 -- In formal verification mode, keep track of all reads and writes
1990 -- through explicit dereferences.
1992 if GNATprove_Mode then
1993 SPARK_Specific.Generate_Dereference (N);
1994 end if;
1996 Analyze (P);
1997 Set_Etype (N, Any_Type);
1999 -- Test for remote access to subprogram type, and if so return
2000 -- after rewriting the original tree.
2002 if Remote_AST_E_Dereference (P) then
2003 return;
2004 end if;
2006 -- Normal processing for other than remote access to subprogram type
2008 if not Is_Overloaded (P) then
2009 if Is_Access_Type (Etype (P)) then
2011 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
2012 -- avoid other problems caused by the Private_Subtype and it is
2013 -- safe to go to the Base_Type because this is the same as
2014 -- converting the access value to its Base_Type.
2016 declare
2017 DT : Entity_Id := Designated_Type (Etype (P));
2019 begin
2020 if Ekind (DT) = E_Private_Subtype
2021 and then Is_For_Access_Subtype (DT)
2022 then
2023 DT := Base_Type (DT);
2024 end if;
2026 -- An explicit dereference is a legal occurrence of an
2027 -- incomplete type imported through a limited_with clause, if
2028 -- the full view is visible, or if we are within an instance
2029 -- body, where the enclosing body has a regular with_clause
2030 -- on the unit.
2032 if From_Limited_With (DT)
2033 and then not From_Limited_With (Scope (DT))
2034 and then
2035 (Is_Immediately_Visible (Scope (DT))
2036 or else
2037 (Is_Child_Unit (Scope (DT))
2038 and then Is_Visible_Lib_Unit (Scope (DT)))
2039 or else In_Instance_Body)
2040 then
2041 Set_Etype (N, Available_View (DT));
2043 else
2044 Set_Etype (N, DT);
2045 end if;
2046 end;
2048 elsif Etype (P) /= Any_Type then
2049 Error_Msg_N ("prefix of dereference must be an access type", N);
2050 return;
2051 end if;
2053 else
2054 Get_First_Interp (P, I, It);
2055 while Present (It.Nam) loop
2056 T := It.Typ;
2058 if Is_Access_Type (T) then
2059 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
2060 end if;
2062 Get_Next_Interp (I, It);
2063 end loop;
2065 -- Error if no interpretation of the prefix has an access type
2067 if Etype (N) = Any_Type then
2068 Error_Msg_N
2069 ("access type required in prefix of explicit dereference", P);
2070 Set_Etype (N, Any_Type);
2071 return;
2072 end if;
2073 end if;
2075 if Is_Function_Type
2076 and then Nkind (Parent (N)) /= N_Indexed_Component
2078 and then (Nkind (Parent (N)) /= N_Function_Call
2079 or else N /= Name (Parent (N)))
2081 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
2082 or else N /= Name (Parent (N)))
2084 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
2085 and then (Nkind (Parent (N)) /= N_Attribute_Reference
2086 or else
2087 (Attribute_Name (Parent (N)) /= Name_Address
2088 and then
2089 Attribute_Name (Parent (N)) /= Name_Access))
2090 then
2091 -- Name is a function call with no actuals, in a context that
2092 -- requires deproceduring (including as an actual in an enclosing
2093 -- function or procedure call). There are some pathological cases
2094 -- where the prefix might include functions that return access to
2095 -- subprograms and others that return a regular type. Disambiguation
2096 -- of those has to take place in Resolve.
2098 New_N :=
2099 Make_Function_Call (Loc,
2100 Name => Make_Explicit_Dereference (Loc, P),
2101 Parameter_Associations => New_List);
2103 -- If the prefix is overloaded, remove operations that have formals,
2104 -- we know that this is a parameterless call.
2106 if Is_Overloaded (P) then
2107 Get_First_Interp (P, I, It);
2108 while Present (It.Nam) loop
2109 T := It.Typ;
2111 if No (First_Formal (Base_Type (Designated_Type (T)))) then
2112 Set_Etype (P, T);
2113 else
2114 Remove_Interp (I);
2115 end if;
2117 Get_Next_Interp (I, It);
2118 end loop;
2119 end if;
2121 Rewrite (N, New_N);
2122 Analyze (N);
2124 elsif not Is_Function_Type
2125 and then Is_Overloaded (N)
2126 then
2127 -- The prefix may include access to subprograms and other access
2128 -- types. If the context selects the interpretation that is a
2129 -- function call (not a procedure call) we cannot rewrite the node
2130 -- yet, but we include the result of the call interpretation.
2132 Get_First_Interp (N, I, It);
2133 while Present (It.Nam) loop
2134 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
2135 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
2136 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
2137 then
2138 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
2139 end if;
2141 Get_Next_Interp (I, It);
2142 end loop;
2143 end if;
2145 -- A value of remote access-to-class-wide must not be dereferenced
2146 -- (RM E.2.2(16)).
2148 Validate_Remote_Access_To_Class_Wide_Type (N);
2149 end Analyze_Explicit_Dereference;
2151 ------------------------
2152 -- Analyze_Expression --
2153 ------------------------
2155 procedure Analyze_Expression (N : Node_Id) is
2156 begin
2158 -- If the expression is an indexed component that will be rewritten
2159 -- as a container indexing, it has already been analyzed.
2161 if Nkind (N) = N_Indexed_Component
2162 and then Present (Generalized_Indexing (N))
2163 then
2164 null;
2166 else
2167 Analyze (N);
2168 Check_Parameterless_Call (N);
2169 end if;
2170 end Analyze_Expression;
2172 -------------------------------------
2173 -- Analyze_Expression_With_Actions --
2174 -------------------------------------
2176 procedure Analyze_Expression_With_Actions (N : Node_Id) is
2177 A : Node_Id;
2179 begin
2180 A := First (Actions (N));
2181 while Present (A) loop
2182 Analyze (A);
2183 Next (A);
2184 end loop;
2186 Analyze_Expression (Expression (N));
2187 Set_Etype (N, Etype (Expression (N)));
2188 end Analyze_Expression_With_Actions;
2190 ---------------------------
2191 -- Analyze_If_Expression --
2192 ---------------------------
2194 procedure Analyze_If_Expression (N : Node_Id) is
2195 Condition : constant Node_Id := First (Expressions (N));
2196 Then_Expr : constant Node_Id := Next (Condition);
2197 Else_Expr : Node_Id;
2199 begin
2200 -- Defend against error of missing expressions from previous error
2202 if No (Then_Expr) then
2203 Check_Error_Detected;
2204 return;
2205 end if;
2207 if Comes_From_Source (N) then
2208 Check_SPARK_05_Restriction ("if expression is not allowed", N);
2209 end if;
2211 Else_Expr := Next (Then_Expr);
2213 if Comes_From_Source (N) then
2214 Check_Compiler_Unit ("if expression", N);
2215 end if;
2217 -- Analyze and resolve the condition. We need to resolve this now so
2218 -- that it gets folded to True/False if possible, before we analyze
2219 -- the THEN/ELSE branches, because when analyzing these branches, we
2220 -- may call Is_Statically_Unevaluated, which expects the condition of
2221 -- an enclosing IF to have been analyze/resolved/evaluated.
2223 Analyze_Expression (Condition);
2224 Resolve (Condition, Any_Boolean);
2226 -- Analyze THEN expression and (if present) ELSE expression. For those
2227 -- we delay resolution in the normal manner, because of overloading etc.
2229 Analyze_Expression (Then_Expr);
2231 if Present (Else_Expr) then
2232 Analyze_Expression (Else_Expr);
2233 end if;
2235 -- If then expression not overloaded, then that decides the type
2237 if not Is_Overloaded (Then_Expr) then
2238 Set_Etype (N, Etype (Then_Expr));
2240 -- Case where then expression is overloaded
2242 else
2243 declare
2244 I : Interp_Index;
2245 It : Interp;
2247 begin
2248 Set_Etype (N, Any_Type);
2250 -- Loop through interpretations of Then_Expr
2252 Get_First_Interp (Then_Expr, I, It);
2253 while Present (It.Nam) loop
2255 -- Add possible interpretation of Then_Expr if no Else_Expr, or
2256 -- Else_Expr is present and has a compatible type.
2258 if No (Else_Expr)
2259 or else Has_Compatible_Type (Else_Expr, It.Typ)
2260 then
2261 Add_One_Interp (N, It.Typ, It.Typ);
2262 end if;
2264 Get_Next_Interp (I, It);
2265 end loop;
2267 -- If no valid interpretation has been found, then the type of the
2268 -- ELSE expression does not match any interpretation of the THEN
2269 -- expression.
2271 if Etype (N) = Any_Type then
2272 Error_Msg_N
2273 ("type incompatible with that of `THEN` expression",
2274 Else_Expr);
2275 return;
2276 end if;
2277 end;
2278 end if;
2279 end Analyze_If_Expression;
2281 ------------------------------------
2282 -- Analyze_Indexed_Component_Form --
2283 ------------------------------------
2285 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
2286 P : constant Node_Id := Prefix (N);
2287 Exprs : constant List_Id := Expressions (N);
2288 Exp : Node_Id;
2289 P_T : Entity_Id;
2290 E : Node_Id;
2291 U_N : Entity_Id;
2293 procedure Process_Function_Call;
2294 -- Prefix in indexed component form is an overloadable entity, so the
2295 -- node is a function call. Reformat it as such.
2297 procedure Process_Indexed_Component;
2298 -- Prefix in indexed component form is actually an indexed component.
2299 -- This routine processes it, knowing that the prefix is already
2300 -- resolved.
2302 procedure Process_Indexed_Component_Or_Slice;
2303 -- An indexed component with a single index may designate a slice if
2304 -- the index is a subtype mark. This routine disambiguates these two
2305 -- cases by resolving the prefix to see if it is a subtype mark.
2307 procedure Process_Overloaded_Indexed_Component;
2308 -- If the prefix of an indexed component is overloaded, the proper
2309 -- interpretation is selected by the index types and the context.
2311 ---------------------------
2312 -- Process_Function_Call --
2313 ---------------------------
2315 procedure Process_Function_Call is
2316 Loc : constant Source_Ptr := Sloc (N);
2317 Actual : Node_Id;
2319 begin
2320 Change_Node (N, N_Function_Call);
2321 Set_Name (N, P);
2322 Set_Parameter_Associations (N, Exprs);
2324 -- Analyze actuals prior to analyzing the call itself
2326 Actual := First (Parameter_Associations (N));
2327 while Present (Actual) loop
2328 Analyze (Actual);
2329 Check_Parameterless_Call (Actual);
2331 -- Move to next actual. Note that we use Next, not Next_Actual
2332 -- here. The reason for this is a bit subtle. If a function call
2333 -- includes named associations, the parser recognizes the node
2334 -- as a call, and it is analyzed as such. If all associations are
2335 -- positional, the parser builds an indexed_component node, and
2336 -- it is only after analysis of the prefix that the construct
2337 -- is recognized as a call, in which case Process_Function_Call
2338 -- rewrites the node and analyzes the actuals. If the list of
2339 -- actuals is malformed, the parser may leave the node as an
2340 -- indexed component (despite the presence of named associations).
2341 -- The iterator Next_Actual is equivalent to Next if the list is
2342 -- positional, but follows the normalized chain of actuals when
2343 -- named associations are present. In this case normalization has
2344 -- not taken place, and actuals remain unanalyzed, which leads to
2345 -- subsequent crashes or loops if there is an attempt to continue
2346 -- analysis of the program.
2348 -- IF there is a single actual and it is a type name, the node
2349 -- can only be interpreted as a slice of a parameterless call.
2350 -- Rebuild the node as such and analyze.
2352 if No (Next (Actual))
2353 and then Is_Entity_Name (Actual)
2354 and then Is_Type (Entity (Actual))
2355 and then Is_Discrete_Type (Entity (Actual))
2356 then
2357 Replace (N,
2358 Make_Slice (Loc,
2359 Prefix => P,
2360 Discrete_Range =>
2361 New_Occurrence_Of (Entity (Actual), Loc)));
2362 Analyze (N);
2363 return;
2365 else
2366 Next (Actual);
2367 end if;
2368 end loop;
2370 Analyze_Call (N);
2371 end Process_Function_Call;
2373 -------------------------------
2374 -- Process_Indexed_Component --
2375 -------------------------------
2377 procedure Process_Indexed_Component is
2378 Exp : Node_Id;
2379 Array_Type : Entity_Id;
2380 Index : Node_Id;
2381 Pent : Entity_Id := Empty;
2383 begin
2384 Exp := First (Exprs);
2386 if Is_Overloaded (P) then
2387 Process_Overloaded_Indexed_Component;
2389 else
2390 Array_Type := Etype (P);
2392 if Is_Entity_Name (P) then
2393 Pent := Entity (P);
2394 elsif Nkind (P) = N_Selected_Component
2395 and then Is_Entity_Name (Selector_Name (P))
2396 then
2397 Pent := Entity (Selector_Name (P));
2398 end if;
2400 -- Prefix must be appropriate for an array type, taking into
2401 -- account a possible implicit dereference.
2403 if Is_Access_Type (Array_Type) then
2404 Error_Msg_NW
2405 (Warn_On_Dereference, "?d?implicit dereference", N);
2406 Array_Type := Process_Implicit_Dereference_Prefix (Pent, P);
2407 end if;
2409 if Is_Array_Type (Array_Type) then
2411 -- In order to correctly access First_Index component later,
2412 -- replace string literal subtype by its parent type.
2414 if Ekind (Array_Type) = E_String_Literal_Subtype then
2415 Array_Type := Etype (Array_Type);
2416 end if;
2418 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
2419 Analyze (Exp);
2420 Set_Etype (N, Any_Type);
2422 if not Has_Compatible_Type (Exp, Entry_Index_Type (Pent)) then
2423 Error_Msg_N ("invalid index type in entry name", N);
2425 elsif Present (Next (Exp)) then
2426 Error_Msg_N ("too many subscripts in entry reference", N);
2428 else
2429 Set_Etype (N, Etype (P));
2430 end if;
2432 return;
2434 elsif Is_Record_Type (Array_Type)
2435 and then Remote_AST_I_Dereference (P)
2436 then
2437 return;
2439 elsif Try_Container_Indexing (N, P, Exprs) then
2440 return;
2442 elsif Array_Type = Any_Type then
2443 Set_Etype (N, Any_Type);
2445 -- In most cases the analysis of the prefix will have emitted
2446 -- an error already, but if the prefix may be interpreted as a
2447 -- call in prefixed notation, the report is left to the caller.
2448 -- To prevent cascaded errors, report only if no previous ones.
2450 if Serious_Errors_Detected = 0 then
2451 Error_Msg_N ("invalid prefix in indexed component", P);
2453 if Nkind (P) = N_Expanded_Name then
2454 Error_Msg_NE ("\& is not visible", P, Selector_Name (P));
2455 end if;
2456 end if;
2458 return;
2460 -- Here we definitely have a bad indexing
2462 else
2463 if Nkind (Parent (N)) = N_Requeue_Statement
2464 and then Present (Pent) and then Ekind (Pent) = E_Entry
2465 then
2466 Error_Msg_N
2467 ("REQUEUE does not permit parameters", First (Exprs));
2469 elsif Is_Entity_Name (P)
2470 and then Etype (P) = Standard_Void_Type
2471 then
2472 Error_Msg_NE ("incorrect use of &", P, Entity (P));
2474 else
2475 Error_Msg_N ("array type required in indexed component", P);
2476 end if;
2478 Set_Etype (N, Any_Type);
2479 return;
2480 end if;
2482 Index := First_Index (Array_Type);
2483 while Present (Index) and then Present (Exp) loop
2484 if not Has_Compatible_Type (Exp, Etype (Index)) then
2485 Wrong_Type (Exp, Etype (Index));
2486 Set_Etype (N, Any_Type);
2487 return;
2488 end if;
2490 Next_Index (Index);
2491 Next (Exp);
2492 end loop;
2494 Set_Etype (N, Component_Type (Array_Type));
2495 Check_Implicit_Dereference (N, Etype (N));
2497 if Present (Index) then
2498 Error_Msg_N
2499 ("too few subscripts in array reference", First (Exprs));
2501 elsif Present (Exp) then
2502 Error_Msg_N ("too many subscripts in array reference", Exp);
2503 end if;
2504 end if;
2505 end Process_Indexed_Component;
2507 ----------------------------------------
2508 -- Process_Indexed_Component_Or_Slice --
2509 ----------------------------------------
2511 procedure Process_Indexed_Component_Or_Slice is
2512 begin
2513 Exp := First (Exprs);
2514 while Present (Exp) loop
2515 Analyze_Expression (Exp);
2516 Next (Exp);
2517 end loop;
2519 Exp := First (Exprs);
2521 -- If one index is present, and it is a subtype name, then the node
2522 -- denotes a slice (note that the case of an explicit range for a
2523 -- slice was already built as an N_Slice node in the first place,
2524 -- so that case is not handled here).
2526 -- We use a replace rather than a rewrite here because this is one
2527 -- of the cases in which the tree built by the parser is plain wrong.
2529 if No (Next (Exp))
2530 and then Is_Entity_Name (Exp)
2531 and then Is_Type (Entity (Exp))
2532 then
2533 Replace (N,
2534 Make_Slice (Sloc (N),
2535 Prefix => P,
2536 Discrete_Range => New_Copy (Exp)));
2537 Analyze (N);
2539 -- Otherwise (more than one index present, or single index is not
2540 -- a subtype name), then we have the indexed component case.
2542 else
2543 Process_Indexed_Component;
2544 end if;
2545 end Process_Indexed_Component_Or_Slice;
2547 ------------------------------------------
2548 -- Process_Overloaded_Indexed_Component --
2549 ------------------------------------------
2551 procedure Process_Overloaded_Indexed_Component is
2552 Exp : Node_Id;
2553 I : Interp_Index;
2554 It : Interp;
2555 Typ : Entity_Id;
2556 Index : Node_Id;
2557 Found : Boolean;
2559 begin
2560 Set_Etype (N, Any_Type);
2562 Get_First_Interp (P, I, It);
2563 while Present (It.Nam) loop
2564 Typ := It.Typ;
2566 if Is_Access_Type (Typ) then
2567 Typ := Designated_Type (Typ);
2568 Error_Msg_NW
2569 (Warn_On_Dereference, "?d?implicit dereference", N);
2570 end if;
2572 if Is_Array_Type (Typ) then
2574 -- Got a candidate: verify that index types are compatible
2576 Index := First_Index (Typ);
2577 Found := True;
2578 Exp := First (Exprs);
2579 while Present (Index) and then Present (Exp) loop
2580 if Has_Compatible_Type (Exp, Etype (Index)) then
2581 null;
2582 else
2583 Found := False;
2584 Remove_Interp (I);
2585 exit;
2586 end if;
2588 Next_Index (Index);
2589 Next (Exp);
2590 end loop;
2592 if Found and then No (Index) and then No (Exp) then
2593 declare
2594 CT : constant Entity_Id :=
2595 Base_Type (Component_Type (Typ));
2596 begin
2597 Add_One_Interp (N, CT, CT);
2598 Check_Implicit_Dereference (N, CT);
2599 end;
2600 end if;
2602 elsif Try_Container_Indexing (N, P, Exprs) then
2603 return;
2605 end if;
2607 Get_Next_Interp (I, It);
2608 end loop;
2610 if Etype (N) = Any_Type then
2611 Error_Msg_N ("no legal interpretation for indexed component", N);
2612 Set_Is_Overloaded (N, False);
2613 end if;
2615 End_Interp_List;
2616 end Process_Overloaded_Indexed_Component;
2618 -- Start of processing for Analyze_Indexed_Component_Form
2620 begin
2621 -- Get name of array, function or type
2623 Analyze (P);
2625 -- If P is an explicit dereference whose prefix is of a remote access-
2626 -- to-subprogram type, then N has already been rewritten as a subprogram
2627 -- call and analyzed.
2629 if Nkind (N) in N_Subprogram_Call then
2630 return;
2632 -- When the prefix is attribute 'Loop_Entry and the sole expression of
2633 -- the indexed component denotes a loop name, the indexed form is turned
2634 -- into an attribute reference.
2636 elsif Nkind (N) = N_Attribute_Reference
2637 and then Attribute_Name (N) = Name_Loop_Entry
2638 then
2639 return;
2640 end if;
2642 pragma Assert (Nkind (N) = N_Indexed_Component);
2644 P_T := Base_Type (Etype (P));
2646 if Is_Entity_Name (P) and then Present (Entity (P)) then
2647 U_N := Entity (P);
2649 if Is_Type (U_N) then
2651 -- Reformat node as a type conversion
2653 E := Remove_Head (Exprs);
2655 if Present (First (Exprs)) then
2656 Error_Msg_N
2657 ("argument of type conversion must be single expression", N);
2658 end if;
2660 Change_Node (N, N_Type_Conversion);
2661 Set_Subtype_Mark (N, P);
2662 Set_Etype (N, U_N);
2663 Set_Expression (N, E);
2665 -- After changing the node, call for the specific Analysis
2666 -- routine directly, to avoid a double call to the expander.
2668 Analyze_Type_Conversion (N);
2669 return;
2670 end if;
2672 if Is_Overloadable (U_N) then
2673 Process_Function_Call;
2675 elsif Ekind (Etype (P)) = E_Subprogram_Type
2676 or else (Is_Access_Type (Etype (P))
2677 and then
2678 Ekind (Designated_Type (Etype (P))) =
2679 E_Subprogram_Type)
2680 then
2681 -- Call to access_to-subprogram with possible implicit dereference
2683 Process_Function_Call;
2685 elsif Is_Generic_Subprogram (U_N) then
2687 -- A common beginner's (or C++ templates fan) error
2689 Error_Msg_N ("generic subprogram cannot be called", N);
2690 Set_Etype (N, Any_Type);
2691 return;
2693 else
2694 Process_Indexed_Component_Or_Slice;
2695 end if;
2697 -- If not an entity name, prefix is an expression that may denote
2698 -- an array or an access-to-subprogram.
2700 else
2701 if Ekind (P_T) = E_Subprogram_Type
2702 or else (Is_Access_Type (P_T)
2703 and then
2704 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
2705 then
2706 Process_Function_Call;
2708 elsif Nkind (P) = N_Selected_Component
2709 and then Present (Entity (Selector_Name (P)))
2710 and then Is_Overloadable (Entity (Selector_Name (P)))
2711 then
2712 Process_Function_Call;
2714 -- In ASIS mode within a generic, a prefixed call is analyzed and
2715 -- partially rewritten but the original indexed component has not
2716 -- yet been rewritten as a call. Perform the replacement now.
2718 elsif Nkind (P) = N_Selected_Component
2719 and then Nkind (Parent (P)) = N_Function_Call
2720 and then ASIS_Mode
2721 then
2722 Rewrite (N, Parent (P));
2723 Analyze (N);
2725 else
2726 -- Indexed component, slice, or a call to a member of a family
2727 -- entry, which will be converted to an entry call later.
2729 Process_Indexed_Component_Or_Slice;
2730 end if;
2731 end if;
2733 Analyze_Dimension (N);
2734 end Analyze_Indexed_Component_Form;
2736 ------------------------
2737 -- Analyze_Logical_Op --
2738 ------------------------
2740 procedure Analyze_Logical_Op (N : Node_Id) is
2741 L : constant Node_Id := Left_Opnd (N);
2742 R : constant Node_Id := Right_Opnd (N);
2743 Op_Id : Entity_Id := Entity (N);
2745 begin
2746 Set_Etype (N, Any_Type);
2747 Candidate_Type := Empty;
2749 Analyze_Expression (L);
2750 Analyze_Expression (R);
2752 if Present (Op_Id) then
2754 if Ekind (Op_Id) = E_Operator then
2755 Find_Boolean_Types (L, R, Op_Id, N);
2756 else
2757 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2758 end if;
2760 else
2761 Op_Id := Get_Name_Entity_Id (Chars (N));
2762 while Present (Op_Id) loop
2763 if Ekind (Op_Id) = E_Operator then
2764 Find_Boolean_Types (L, R, Op_Id, N);
2765 else
2766 Analyze_User_Defined_Binary_Op (N, Op_Id);
2767 end if;
2769 Op_Id := Homonym (Op_Id);
2770 end loop;
2771 end if;
2773 Operator_Check (N);
2774 Check_Function_Writable_Actuals (N);
2775 end Analyze_Logical_Op;
2777 ---------------------------
2778 -- Analyze_Membership_Op --
2779 ---------------------------
2781 procedure Analyze_Membership_Op (N : Node_Id) is
2782 Loc : constant Source_Ptr := Sloc (N);
2783 L : constant Node_Id := Left_Opnd (N);
2784 R : constant Node_Id := Right_Opnd (N);
2786 Index : Interp_Index;
2787 It : Interp;
2788 Found : Boolean := False;
2789 I_F : Interp_Index;
2790 T_F : Entity_Id;
2792 procedure Try_One_Interp (T1 : Entity_Id);
2793 -- Routine to try one proposed interpretation. Note that the context
2794 -- of the operation plays no role in resolving the arguments, so that
2795 -- if there is more than one interpretation of the operands that is
2796 -- compatible with a membership test, the operation is ambiguous.
2798 --------------------
2799 -- Try_One_Interp --
2800 --------------------
2802 procedure Try_One_Interp (T1 : Entity_Id) is
2803 begin
2804 if Has_Compatible_Type (R, T1) then
2805 if Found
2806 and then Base_Type (T1) /= Base_Type (T_F)
2807 then
2808 It := Disambiguate (L, I_F, Index, Any_Type);
2810 if It = No_Interp then
2811 Ambiguous_Operands (N);
2812 Set_Etype (L, Any_Type);
2813 return;
2815 else
2816 T_F := It.Typ;
2817 end if;
2819 else
2820 Found := True;
2821 T_F := T1;
2822 I_F := Index;
2823 end if;
2825 Set_Etype (L, T_F);
2826 end if;
2827 end Try_One_Interp;
2829 procedure Analyze_Set_Membership;
2830 -- If a set of alternatives is present, analyze each and find the
2831 -- common type to which they must all resolve.
2833 ----------------------------
2834 -- Analyze_Set_Membership --
2835 ----------------------------
2837 procedure Analyze_Set_Membership is
2838 Alt : Node_Id;
2839 Index : Interp_Index;
2840 It : Interp;
2841 Candidate_Interps : Node_Id;
2842 Common_Type : Entity_Id := Empty;
2844 begin
2845 if Comes_From_Source (N) then
2846 Check_Compiler_Unit ("set membership", N);
2847 end if;
2849 Analyze (L);
2850 Candidate_Interps := L;
2852 if not Is_Overloaded (L) then
2853 Common_Type := Etype (L);
2855 Alt := First (Alternatives (N));
2856 while Present (Alt) loop
2857 Analyze (Alt);
2859 if not Has_Compatible_Type (Alt, Common_Type) then
2860 Wrong_Type (Alt, Common_Type);
2861 end if;
2863 Next (Alt);
2864 end loop;
2866 else
2867 Alt := First (Alternatives (N));
2868 while Present (Alt) loop
2869 Analyze (Alt);
2870 if not Is_Overloaded (Alt) then
2871 Common_Type := Etype (Alt);
2873 else
2874 Get_First_Interp (Alt, Index, It);
2875 while Present (It.Typ) loop
2876 if not
2877 Has_Compatible_Type (Candidate_Interps, It.Typ)
2878 then
2879 Remove_Interp (Index);
2880 end if;
2882 Get_Next_Interp (Index, It);
2883 end loop;
2885 Get_First_Interp (Alt, Index, It);
2887 if No (It.Typ) then
2888 Error_Msg_N ("alternative has no legal type", Alt);
2889 return;
2890 end if;
2892 -- If alternative is not overloaded, we have a unique type
2893 -- for all of them.
2895 Set_Etype (Alt, It.Typ);
2896 Get_Next_Interp (Index, It);
2898 if No (It.Typ) then
2899 Set_Is_Overloaded (Alt, False);
2900 Common_Type := Etype (Alt);
2901 end if;
2903 Candidate_Interps := Alt;
2904 end if;
2906 Next (Alt);
2907 end loop;
2908 end if;
2910 Set_Etype (N, Standard_Boolean);
2912 if Present (Common_Type) then
2913 Set_Etype (L, Common_Type);
2915 -- The left operand may still be overloaded, to be resolved using
2916 -- the Common_Type.
2918 else
2919 Error_Msg_N ("cannot resolve membership operation", N);
2920 end if;
2921 end Analyze_Set_Membership;
2923 -- Start of processing for Analyze_Membership_Op
2925 begin
2926 Analyze_Expression (L);
2928 if No (R) and then Ada_Version >= Ada_2012 then
2929 Analyze_Set_Membership;
2930 Check_Function_Writable_Actuals (N);
2932 return;
2933 end if;
2935 if Nkind (R) = N_Range
2936 or else (Nkind (R) = N_Attribute_Reference
2937 and then Attribute_Name (R) = Name_Range)
2938 then
2939 Analyze (R);
2941 if not Is_Overloaded (L) then
2942 Try_One_Interp (Etype (L));
2944 else
2945 Get_First_Interp (L, Index, It);
2946 while Present (It.Typ) loop
2947 Try_One_Interp (It.Typ);
2948 Get_Next_Interp (Index, It);
2949 end loop;
2950 end if;
2952 -- If not a range, it can be a subtype mark, or else it is a degenerate
2953 -- membership test with a singleton value, i.e. a test for equality,
2954 -- if the types are compatible.
2956 else
2957 Analyze (R);
2959 if Is_Entity_Name (R)
2960 and then Is_Type (Entity (R))
2961 then
2962 Find_Type (R);
2963 Check_Fully_Declared (Entity (R), R);
2965 elsif Ada_Version >= Ada_2012
2966 and then Has_Compatible_Type (R, Etype (L))
2967 then
2968 if Nkind (N) = N_In then
2969 Rewrite (N,
2970 Make_Op_Eq (Loc,
2971 Left_Opnd => L,
2972 Right_Opnd => R));
2973 else
2974 Rewrite (N,
2975 Make_Op_Ne (Loc,
2976 Left_Opnd => L,
2977 Right_Opnd => R));
2978 end if;
2980 Analyze (N);
2981 return;
2983 else
2984 -- In all versions of the language, if we reach this point there
2985 -- is a previous error that will be diagnosed below.
2987 Find_Type (R);
2988 end if;
2989 end if;
2991 -- Compatibility between expression and subtype mark or range is
2992 -- checked during resolution. The result of the operation is Boolean
2993 -- in any case.
2995 Set_Etype (N, Standard_Boolean);
2997 if Comes_From_Source (N)
2998 and then Present (Right_Opnd (N))
2999 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
3000 then
3001 Error_Msg_N ("membership test not applicable to cpp-class types", N);
3002 end if;
3004 Check_Function_Writable_Actuals (N);
3005 end Analyze_Membership_Op;
3007 -----------------
3008 -- Analyze_Mod --
3009 -----------------
3011 procedure Analyze_Mod (N : Node_Id) is
3012 begin
3013 -- A special warning check, if we have an expression of the form:
3014 -- expr mod 2 * literal
3015 -- where literal is 64 or less, then probably what was meant was
3016 -- expr mod 2 ** literal
3017 -- so issue an appropriate warning.
3019 if Warn_On_Suspicious_Modulus_Value
3020 and then Nkind (Right_Opnd (N)) = N_Integer_Literal
3021 and then Intval (Right_Opnd (N)) = Uint_2
3022 and then Nkind (Parent (N)) = N_Op_Multiply
3023 and then Nkind (Right_Opnd (Parent (N))) = N_Integer_Literal
3024 and then Intval (Right_Opnd (Parent (N))) <= Uint_64
3025 then
3026 Error_Msg_N
3027 ("suspicious MOD value, was '*'* intended'??M?", Parent (N));
3028 end if;
3030 -- Remaining processing is same as for other arithmetic operators
3032 Analyze_Arithmetic_Op (N);
3033 end Analyze_Mod;
3035 ----------------------
3036 -- Analyze_Negation --
3037 ----------------------
3039 procedure Analyze_Negation (N : Node_Id) is
3040 R : constant Node_Id := Right_Opnd (N);
3041 Op_Id : Entity_Id := Entity (N);
3043 begin
3044 Set_Etype (N, Any_Type);
3045 Candidate_Type := Empty;
3047 Analyze_Expression (R);
3049 if Present (Op_Id) then
3050 if Ekind (Op_Id) = E_Operator then
3051 Find_Negation_Types (R, Op_Id, N);
3052 else
3053 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3054 end if;
3056 else
3057 Op_Id := Get_Name_Entity_Id (Chars (N));
3058 while Present (Op_Id) loop
3059 if Ekind (Op_Id) = E_Operator then
3060 Find_Negation_Types (R, Op_Id, N);
3061 else
3062 Analyze_User_Defined_Unary_Op (N, Op_Id);
3063 end if;
3065 Op_Id := Homonym (Op_Id);
3066 end loop;
3067 end if;
3069 Operator_Check (N);
3070 end Analyze_Negation;
3072 ------------------
3073 -- Analyze_Null --
3074 ------------------
3076 procedure Analyze_Null (N : Node_Id) is
3077 begin
3078 Check_SPARK_05_Restriction ("null is not allowed", N);
3080 Set_Etype (N, Any_Access);
3081 end Analyze_Null;
3083 ----------------------
3084 -- Analyze_One_Call --
3085 ----------------------
3087 procedure Analyze_One_Call
3088 (N : Node_Id;
3089 Nam : Entity_Id;
3090 Report : Boolean;
3091 Success : out Boolean;
3092 Skip_First : Boolean := False)
3094 Actuals : constant List_Id := Parameter_Associations (N);
3095 Prev_T : constant Entity_Id := Etype (N);
3097 Must_Skip : constant Boolean := Skip_First
3098 or else Nkind (Original_Node (N)) = N_Selected_Component
3099 or else
3100 (Nkind (Original_Node (N)) = N_Indexed_Component
3101 and then Nkind (Prefix (Original_Node (N)))
3102 = N_Selected_Component);
3103 -- The first formal must be omitted from the match when trying to find
3104 -- a primitive operation that is a possible interpretation, and also
3105 -- after the call has been rewritten, because the corresponding actual
3106 -- is already known to be compatible, and because this may be an
3107 -- indexing of a call with default parameters.
3109 Formal : Entity_Id;
3110 Actual : Node_Id;
3111 Is_Indexed : Boolean := False;
3112 Is_Indirect : Boolean := False;
3113 Subp_Type : constant Entity_Id := Etype (Nam);
3114 Norm_OK : Boolean;
3116 function Compatible_Types_In_Predicate
3117 (T1 : Entity_Id;
3118 T2 : Entity_Id) return Boolean;
3119 -- For an Ada 2012 predicate or invariant, a call may mention an
3120 -- incomplete type, while resolution of the corresponding predicate
3121 -- function may see the full view, as a consequence of the delayed
3122 -- resolution of the corresponding expressions. This may occur in
3123 -- the body of a predicate function, or in a call to such. Anomalies
3124 -- involving private and full views can also happen. In each case,
3125 -- rewrite node or add conversions to remove spurious type errors.
3127 procedure Indicate_Name_And_Type;
3128 -- If candidate interpretation matches, indicate name and type of result
3129 -- on call node.
3131 function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
3132 -- There may be a user-defined operator that hides the current
3133 -- interpretation. We must check for this independently of the
3134 -- analysis of the call with the user-defined operation, because
3135 -- the parameter names may be wrong and yet the hiding takes place.
3136 -- This fixes a problem with ACATS test B34014O.
3138 -- When the type Address is a visible integer type, and the DEC
3139 -- system extension is visible, the predefined operator may be
3140 -- hidden as well, by one of the address operations in auxdec.
3141 -- Finally, The abstract operations on address do not hide the
3142 -- predefined operator (this is the purpose of making them abstract).
3144 -----------------------------------
3145 -- Compatible_Types_In_Predicate --
3146 -----------------------------------
3148 function Compatible_Types_In_Predicate
3149 (T1 : Entity_Id;
3150 T2 : Entity_Id) return Boolean
3152 function Common_Type (T : Entity_Id) return Entity_Id;
3153 -- Find non-private full view if any, without going to ancestor type
3154 -- (as opposed to Underlying_Type).
3156 -----------------
3157 -- Common_Type --
3158 -----------------
3160 function Common_Type (T : Entity_Id) return Entity_Id is
3161 begin
3162 if Is_Private_Type (T) and then Present (Full_View (T)) then
3163 return Base_Type (Full_View (T));
3164 else
3165 return Base_Type (T);
3166 end if;
3167 end Common_Type;
3169 -- Start of processing for Compatible_Types_In_Predicate
3171 begin
3172 if (Ekind (Current_Scope) = E_Function
3173 and then Is_Predicate_Function (Current_Scope))
3174 or else
3175 (Ekind (Nam) = E_Function
3176 and then Is_Predicate_Function (Nam))
3177 then
3178 if Is_Incomplete_Type (T1)
3179 and then Present (Full_View (T1))
3180 and then Full_View (T1) = T2
3181 then
3182 Set_Etype (Formal, Etype (Actual));
3183 return True;
3185 elsif Common_Type (T1) = Common_Type (T2) then
3186 Rewrite (Actual, Unchecked_Convert_To (Etype (Formal), Actual));
3187 return True;
3189 else
3190 return False;
3191 end if;
3193 else
3194 return False;
3195 end if;
3196 end Compatible_Types_In_Predicate;
3198 ----------------------------
3199 -- Indicate_Name_And_Type --
3200 ----------------------------
3202 procedure Indicate_Name_And_Type is
3203 begin
3204 Add_One_Interp (N, Nam, Etype (Nam));
3205 Check_Implicit_Dereference (N, Etype (Nam));
3206 Success := True;
3208 -- If the prefix of the call is a name, indicate the entity
3209 -- being called. If it is not a name, it is an expression that
3210 -- denotes an access to subprogram or else an entry or family. In
3211 -- the latter case, the name is a selected component, and the entity
3212 -- being called is noted on the selector.
3214 if not Is_Type (Nam) then
3215 if Is_Entity_Name (Name (N)) then
3216 Set_Entity (Name (N), Nam);
3217 Set_Etype (Name (N), Etype (Nam));
3219 elsif Nkind (Name (N)) = N_Selected_Component then
3220 Set_Entity (Selector_Name (Name (N)), Nam);
3221 end if;
3222 end if;
3224 if Debug_Flag_E and not Report then
3225 Write_Str (" Overloaded call ");
3226 Write_Int (Int (N));
3227 Write_Str (" compatible with ");
3228 Write_Int (Int (Nam));
3229 Write_Eol;
3230 end if;
3231 end Indicate_Name_And_Type;
3233 ------------------------
3234 -- Operator_Hidden_By --
3235 ------------------------
3237 function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
3238 Act1 : constant Node_Id := First_Actual (N);
3239 Act2 : constant Node_Id := Next_Actual (Act1);
3240 Form1 : constant Entity_Id := First_Formal (Fun);
3241 Form2 : constant Entity_Id := Next_Formal (Form1);
3243 begin
3244 if Ekind (Fun) /= E_Function or else Is_Abstract_Subprogram (Fun) then
3245 return False;
3247 elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
3248 return False;
3250 elsif Present (Form2) then
3251 if No (Act2)
3252 or else not Has_Compatible_Type (Act2, Etype (Form2))
3253 then
3254 return False;
3255 end if;
3257 elsif Present (Act2) then
3258 return False;
3259 end if;
3261 -- Now we know that the arity of the operator matches the function,
3262 -- and the function call is a valid interpretation. The function
3263 -- hides the operator if it has the right signature, or if one of
3264 -- its operands is a non-abstract operation on Address when this is
3265 -- a visible integer type.
3267 return Hides_Op (Fun, Nam)
3268 or else Is_Descendant_Of_Address (Etype (Form1))
3269 or else
3270 (Present (Form2)
3271 and then Is_Descendant_Of_Address (Etype (Form2)));
3272 end Operator_Hidden_By;
3274 -- Start of processing for Analyze_One_Call
3276 begin
3277 Success := False;
3279 -- If the subprogram has no formals or if all the formals have defaults,
3280 -- and the return type is an array type, the node may denote an indexing
3281 -- of the result of a parameterless call. In Ada 2005, the subprogram
3282 -- may have one non-defaulted formal, and the call may have been written
3283 -- in prefix notation, so that the rebuilt parameter list has more than
3284 -- one actual.
3286 if not Is_Overloadable (Nam)
3287 and then Ekind (Nam) /= E_Subprogram_Type
3288 and then Ekind (Nam) /= E_Entry_Family
3289 then
3290 return;
3291 end if;
3293 -- An indexing requires at least one actual. The name of the call cannot
3294 -- be an implicit indirect call, so it cannot be a generated explicit
3295 -- dereference.
3297 if not Is_Empty_List (Actuals)
3298 and then
3299 (Needs_No_Actuals (Nam)
3300 or else
3301 (Needs_One_Actual (Nam)
3302 and then Present (Next_Actual (First (Actuals)))))
3303 then
3304 if Is_Array_Type (Subp_Type)
3305 and then
3306 (Nkind (Name (N)) /= N_Explicit_Dereference
3307 or else Comes_From_Source (Name (N)))
3308 then
3309 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
3311 elsif Is_Access_Type (Subp_Type)
3312 and then Is_Array_Type (Designated_Type (Subp_Type))
3313 then
3314 Is_Indexed :=
3315 Try_Indexed_Call
3316 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
3318 -- The prefix can also be a parameterless function that returns an
3319 -- access to subprogram, in which case this is an indirect call.
3320 -- If this succeeds, an explicit dereference is added later on,
3321 -- in Analyze_Call or Resolve_Call.
3323 elsif Is_Access_Type (Subp_Type)
3324 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
3325 then
3326 Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
3327 end if;
3329 end if;
3331 -- If the call has been transformed into a slice, it is of the form
3332 -- F (Subtype) where F is parameterless. The node has been rewritten in
3333 -- Try_Indexed_Call and there is nothing else to do.
3335 if Is_Indexed
3336 and then Nkind (N) = N_Slice
3337 then
3338 return;
3339 end if;
3341 Normalize_Actuals
3342 (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
3344 if not Norm_OK then
3346 -- If an indirect call is a possible interpretation, indicate
3347 -- success to the caller. This may be an indexing of an explicit
3348 -- dereference of a call that returns an access type (see above).
3350 if Is_Indirect
3351 or else (Is_Indexed
3352 and then Nkind (Name (N)) = N_Explicit_Dereference
3353 and then Comes_From_Source (Name (N)))
3354 then
3355 Success := True;
3356 return;
3358 -- Mismatch in number or names of parameters
3360 elsif Debug_Flag_E then
3361 Write_Str (" normalization fails in call ");
3362 Write_Int (Int (N));
3363 Write_Str (" with subprogram ");
3364 Write_Int (Int (Nam));
3365 Write_Eol;
3366 end if;
3368 -- If the context expects a function call, discard any interpretation
3369 -- that is a procedure. If the node is not overloaded, leave as is for
3370 -- better error reporting when type mismatch is found.
3372 elsif Nkind (N) = N_Function_Call
3373 and then Is_Overloaded (Name (N))
3374 and then Ekind (Nam) = E_Procedure
3375 then
3376 return;
3378 -- Ditto for function calls in a procedure context
3380 elsif Nkind (N) = N_Procedure_Call_Statement
3381 and then Is_Overloaded (Name (N))
3382 and then Etype (Nam) /= Standard_Void_Type
3383 then
3384 return;
3386 elsif No (Actuals) then
3388 -- If Normalize succeeds, then there are default parameters for
3389 -- all formals.
3391 Indicate_Name_And_Type;
3393 elsif Ekind (Nam) = E_Operator then
3394 if Nkind (N) = N_Procedure_Call_Statement then
3395 return;
3396 end if;
3398 -- This can occur when the prefix of the call is an operator
3399 -- name or an expanded name whose selector is an operator name.
3401 Analyze_Operator_Call (N, Nam);
3403 if Etype (N) /= Prev_T then
3405 -- Check that operator is not hidden by a function interpretation
3407 if Is_Overloaded (Name (N)) then
3408 declare
3409 I : Interp_Index;
3410 It : Interp;
3412 begin
3413 Get_First_Interp (Name (N), I, It);
3414 while Present (It.Nam) loop
3415 if Operator_Hidden_By (It.Nam) then
3416 Set_Etype (N, Prev_T);
3417 return;
3418 end if;
3420 Get_Next_Interp (I, It);
3421 end loop;
3422 end;
3423 end if;
3425 -- If operator matches formals, record its name on the call.
3426 -- If the operator is overloaded, Resolve will select the
3427 -- correct one from the list of interpretations. The call
3428 -- node itself carries the first candidate.
3430 Set_Entity (Name (N), Nam);
3431 Success := True;
3433 elsif Report and then Etype (N) = Any_Type then
3434 Error_Msg_N ("incompatible arguments for operator", N);
3435 end if;
3437 else
3438 -- Normalize_Actuals has chained the named associations in the
3439 -- correct order of the formals.
3441 Actual := First_Actual (N);
3442 Formal := First_Formal (Nam);
3444 -- If we are analyzing a call rewritten from object notation, skip
3445 -- first actual, which may be rewritten later as an explicit
3446 -- dereference.
3448 if Must_Skip then
3449 Next_Actual (Actual);
3450 Next_Formal (Formal);
3451 end if;
3453 while Present (Actual) and then Present (Formal) loop
3454 if Nkind (Parent (Actual)) /= N_Parameter_Association
3455 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
3456 then
3457 -- The actual can be compatible with the formal, but we must
3458 -- also check that the context is not an address type that is
3459 -- visibly an integer type. In this case the use of literals is
3460 -- illegal, except in the body of descendants of system, where
3461 -- arithmetic operations on address are of course used.
3463 if Has_Compatible_Type (Actual, Etype (Formal))
3464 and then
3465 (Etype (Actual) /= Universal_Integer
3466 or else not Is_Descendant_Of_Address (Etype (Formal))
3467 or else
3468 Is_Predefined_File_Name
3469 (Unit_File_Name (Get_Source_Unit (N))))
3470 then
3471 Next_Actual (Actual);
3472 Next_Formal (Formal);
3474 -- In Allow_Integer_Address mode, we allow an actual integer to
3475 -- match a formal address type and vice versa. We only do this
3476 -- if we are certain that an error will otherwise be issued
3478 elsif Address_Integer_Convert_OK
3479 (Etype (Actual), Etype (Formal))
3480 and then (Report and not Is_Indexed and not Is_Indirect)
3481 then
3482 -- Handle this case by introducing an unchecked conversion
3484 Rewrite (Actual,
3485 Unchecked_Convert_To (Etype (Formal),
3486 Relocate_Node (Actual)));
3487 Analyze_And_Resolve (Actual, Etype (Formal));
3488 Next_Actual (Actual);
3489 Next_Formal (Formal);
3491 -- Under relaxed RM semantics silently replace occurrences of
3492 -- null by System.Address_Null. We only do this if we know that
3493 -- an error will otherwise be issued.
3495 elsif Null_To_Null_Address_Convert_OK (Actual, Etype (Formal))
3496 and then (Report and not Is_Indexed and not Is_Indirect)
3497 then
3498 Replace_Null_By_Null_Address (Actual);
3499 Analyze_And_Resolve (Actual, Etype (Formal));
3500 Next_Actual (Actual);
3501 Next_Formal (Formal);
3503 elsif Compatible_Types_In_Predicate
3504 (Etype (Formal), Etype (Actual))
3505 then
3506 Next_Actual (Actual);
3507 Next_Formal (Formal);
3509 -- In a complex case where an enclosing generic and a nested
3510 -- generic package, both declared with partially parameterized
3511 -- formal subprograms with the same names, are instantiated
3512 -- with the same type, the types of the actual parameter and
3513 -- that of the formal may appear incompatible at first sight.
3515 -- generic
3516 -- type Outer_T is private;
3517 -- with function Func (Formal : Outer_T)
3518 -- return ... is <>;
3520 -- package Outer_Gen is
3521 -- generic
3522 -- type Inner_T is private;
3523 -- with function Func (Formal : Inner_T) -- (1)
3524 -- return ... is <>;
3526 -- package Inner_Gen is
3527 -- function Inner_Func (Formal : Inner_T) -- (2)
3528 -- return ... is (Func (Formal));
3529 -- end Inner_Gen;
3530 -- end Outer_Generic;
3532 -- package Outer_Inst is new Outer_Gen (Actual_T);
3533 -- package Inner_Inst is new Outer_Inst.Inner_Gen (Actual_T);
3535 -- In the example above, the type of parameter
3536 -- Inner_Func.Formal at (2) is incompatible with the type of
3537 -- Func.Formal at (1) in the context of instantiations
3538 -- Outer_Inst and Inner_Inst. In reality both types are generic
3539 -- actual subtypes renaming base type Actual_T as part of the
3540 -- generic prologues for the instantiations.
3542 -- Recognize this case and add a type conversion to allow this
3543 -- kind of generic actual subtype conformance. Note that this
3544 -- is done only when the call is non-overloaded because the
3545 -- resolution mechanism already has the means to disambiguate
3546 -- similar cases.
3548 elsif not Is_Overloaded (Name (N))
3549 and then Is_Type (Etype (Actual))
3550 and then Is_Type (Etype (Formal))
3551 and then Is_Generic_Actual_Type (Etype (Actual))
3552 and then Is_Generic_Actual_Type (Etype (Formal))
3553 and then Base_Type (Etype (Actual)) =
3554 Base_Type (Etype (Formal))
3555 then
3556 Rewrite (Actual,
3557 Convert_To (Etype (Formal), Relocate_Node (Actual)));
3558 Analyze_And_Resolve (Actual, Etype (Formal));
3559 Next_Actual (Actual);
3560 Next_Formal (Formal);
3562 -- Handle failed type check
3564 else
3565 if Debug_Flag_E then
3566 Write_Str (" type checking fails in call ");
3567 Write_Int (Int (N));
3568 Write_Str (" with formal ");
3569 Write_Int (Int (Formal));
3570 Write_Str (" in subprogram ");
3571 Write_Int (Int (Nam));
3572 Write_Eol;
3573 end if;
3575 -- Comment needed on the following test???
3577 if Report and not Is_Indexed and not Is_Indirect then
3579 -- Ada 2005 (AI-251): Complete the error notification
3580 -- to help new Ada 2005 users.
3582 if Is_Class_Wide_Type (Etype (Formal))
3583 and then Is_Interface (Etype (Etype (Formal)))
3584 and then not Interface_Present_In_Ancestor
3585 (Typ => Etype (Actual),
3586 Iface => Etype (Etype (Formal)))
3587 then
3588 Error_Msg_NE
3589 ("(Ada 2005) does not implement interface }",
3590 Actual, Etype (Etype (Formal)));
3591 end if;
3593 Wrong_Type (Actual, Etype (Formal));
3595 if Nkind (Actual) = N_Op_Eq
3596 and then Nkind (Left_Opnd (Actual)) = N_Identifier
3597 then
3598 Formal := First_Formal (Nam);
3599 while Present (Formal) loop
3600 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
3601 Error_Msg_N -- CODEFIX
3602 ("possible misspelling of `='>`!", Actual);
3603 exit;
3604 end if;
3606 Next_Formal (Formal);
3607 end loop;
3608 end if;
3610 if All_Errors_Mode then
3611 Error_Msg_Sloc := Sloc (Nam);
3613 if Etype (Formal) = Any_Type then
3614 Error_Msg_N
3615 ("there is no legal actual parameter", Actual);
3616 end if;
3618 if Is_Overloadable (Nam)
3619 and then Present (Alias (Nam))
3620 and then not Comes_From_Source (Nam)
3621 then
3622 Error_Msg_NE
3623 ("\\ =='> in call to inherited operation & #!",
3624 Actual, Nam);
3626 elsif Ekind (Nam) = E_Subprogram_Type then
3627 declare
3628 Access_To_Subprogram_Typ :
3629 constant Entity_Id :=
3630 Defining_Identifier
3631 (Associated_Node_For_Itype (Nam));
3632 begin
3633 Error_Msg_NE
3634 ("\\ =='> in call to dereference of &#!",
3635 Actual, Access_To_Subprogram_Typ);
3636 end;
3638 else
3639 Error_Msg_NE
3640 ("\\ =='> in call to &#!", Actual, Nam);
3642 end if;
3643 end if;
3644 end if;
3646 return;
3647 end if;
3649 else
3650 -- Normalize_Actuals has verified that a default value exists
3651 -- for this formal. Current actual names a subsequent formal.
3653 Next_Formal (Formal);
3654 end if;
3655 end loop;
3657 -- On exit, all actuals match
3659 Indicate_Name_And_Type;
3660 end if;
3661 end Analyze_One_Call;
3663 ---------------------------
3664 -- Analyze_Operator_Call --
3665 ---------------------------
3667 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
3668 Op_Name : constant Name_Id := Chars (Op_Id);
3669 Act1 : constant Node_Id := First_Actual (N);
3670 Act2 : constant Node_Id := Next_Actual (Act1);
3672 begin
3673 -- Binary operator case
3675 if Present (Act2) then
3677 -- If more than two operands, then not binary operator after all
3679 if Present (Next_Actual (Act2)) then
3680 return;
3681 end if;
3683 -- Otherwise action depends on operator
3685 case Op_Name is
3686 when Name_Op_Add
3687 | Name_Op_Divide
3688 | Name_Op_Expon
3689 | Name_Op_Mod
3690 | Name_Op_Multiply
3691 | Name_Op_Rem
3692 | Name_Op_Subtract
3694 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
3696 when Name_Op_And
3697 | Name_Op_Or
3698 | Name_Op_Xor
3700 Find_Boolean_Types (Act1, Act2, Op_Id, N);
3702 when Name_Op_Ge
3703 | Name_Op_Gt
3704 | Name_Op_Le
3705 | Name_Op_Lt
3707 Find_Comparison_Types (Act1, Act2, Op_Id, N);
3709 when Name_Op_Eq
3710 | Name_Op_Ne
3712 Find_Equality_Types (Act1, Act2, Op_Id, N);
3714 when Name_Op_Concat =>
3715 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
3717 -- Is this when others, or should it be an abort???
3719 when others =>
3720 null;
3721 end case;
3723 -- Unary operator case
3725 else
3726 case Op_Name is
3727 when Name_Op_Abs
3728 | Name_Op_Add
3729 | Name_Op_Subtract
3731 Find_Unary_Types (Act1, Op_Id, N);
3733 when Name_Op_Not =>
3734 Find_Negation_Types (Act1, Op_Id, N);
3736 -- Is this when others correct, or should it be an abort???
3738 when others =>
3739 null;
3740 end case;
3741 end if;
3742 end Analyze_Operator_Call;
3744 -------------------------------------------
3745 -- Analyze_Overloaded_Selected_Component --
3746 -------------------------------------------
3748 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
3749 Nam : constant Node_Id := Prefix (N);
3750 Sel : constant Node_Id := Selector_Name (N);
3751 Comp : Entity_Id;
3752 I : Interp_Index;
3753 It : Interp;
3754 T : Entity_Id;
3756 begin
3757 Set_Etype (Sel, Any_Type);
3759 Get_First_Interp (Nam, I, It);
3760 while Present (It.Typ) loop
3761 if Is_Access_Type (It.Typ) then
3762 T := Designated_Type (It.Typ);
3763 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
3764 else
3765 T := It.Typ;
3766 end if;
3768 -- Locate the component. For a private prefix the selector can denote
3769 -- a discriminant.
3771 if Is_Record_Type (T) or else Is_Private_Type (T) then
3773 -- If the prefix is a class-wide type, the visible components are
3774 -- those of the base type.
3776 if Is_Class_Wide_Type (T) then
3777 T := Etype (T);
3778 end if;
3780 Comp := First_Entity (T);
3781 while Present (Comp) loop
3782 if Chars (Comp) = Chars (Sel)
3783 and then Is_Visible_Component (Comp)
3784 then
3786 -- AI05-105: if the context is an object renaming with
3787 -- an anonymous access type, the expected type of the
3788 -- object must be anonymous. This is a name resolution rule.
3790 if Nkind (Parent (N)) /= N_Object_Renaming_Declaration
3791 or else No (Access_Definition (Parent (N)))
3792 or else Ekind (Etype (Comp)) = E_Anonymous_Access_Type
3793 or else
3794 Ekind (Etype (Comp)) = E_Anonymous_Access_Subprogram_Type
3795 then
3796 Set_Entity (Sel, Comp);
3797 Set_Etype (Sel, Etype (Comp));
3798 Add_One_Interp (N, Etype (Comp), Etype (Comp));
3799 Check_Implicit_Dereference (N, Etype (Comp));
3801 -- This also specifies a candidate to resolve the name.
3802 -- Further overloading will be resolved from context.
3803 -- The selector name itself does not carry overloading
3804 -- information.
3806 Set_Etype (Nam, It.Typ);
3808 else
3809 -- Named access type in the context of a renaming
3810 -- declaration with an access definition. Remove
3811 -- inapplicable candidate.
3813 Remove_Interp (I);
3814 end if;
3815 end if;
3817 Next_Entity (Comp);
3818 end loop;
3820 elsif Is_Concurrent_Type (T) then
3821 Comp := First_Entity (T);
3822 while Present (Comp)
3823 and then Comp /= First_Private_Entity (T)
3824 loop
3825 if Chars (Comp) = Chars (Sel) then
3826 if Is_Overloadable (Comp) then
3827 Add_One_Interp (Sel, Comp, Etype (Comp));
3828 else
3829 Set_Entity_With_Checks (Sel, Comp);
3830 Generate_Reference (Comp, Sel);
3831 end if;
3833 Set_Etype (Sel, Etype (Comp));
3834 Set_Etype (N, Etype (Comp));
3835 Set_Etype (Nam, It.Typ);
3837 -- For access type case, introduce explicit dereference for
3838 -- more uniform treatment of entry calls. Do this only once
3839 -- if several interpretations yield an access type.
3841 if Is_Access_Type (Etype (Nam))
3842 and then Nkind (Nam) /= N_Explicit_Dereference
3843 then
3844 Insert_Explicit_Dereference (Nam);
3845 Error_Msg_NW
3846 (Warn_On_Dereference, "?d?implicit dereference", N);
3847 end if;
3848 end if;
3850 Next_Entity (Comp);
3851 end loop;
3853 Set_Is_Overloaded (N, Is_Overloaded (Sel));
3854 end if;
3856 Get_Next_Interp (I, It);
3857 end loop;
3859 if Etype (N) = Any_Type
3860 and then not Try_Object_Operation (N)
3861 then
3862 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
3863 Set_Entity (Sel, Any_Id);
3864 Set_Etype (Sel, Any_Type);
3865 end if;
3866 end Analyze_Overloaded_Selected_Component;
3868 ----------------------------------
3869 -- Analyze_Qualified_Expression --
3870 ----------------------------------
3872 procedure Analyze_Qualified_Expression (N : Node_Id) is
3873 Mark : constant Entity_Id := Subtype_Mark (N);
3874 Expr : constant Node_Id := Expression (N);
3875 I : Interp_Index;
3876 It : Interp;
3877 T : Entity_Id;
3879 begin
3880 Analyze_Expression (Expr);
3882 Set_Etype (N, Any_Type);
3883 Find_Type (Mark);
3884 T := Entity (Mark);
3885 Set_Etype (N, T);
3887 if T = Any_Type then
3888 return;
3889 end if;
3891 Check_Fully_Declared (T, N);
3893 -- If expected type is class-wide, check for exact match before
3894 -- expansion, because if the expression is a dispatching call it
3895 -- may be rewritten as explicit dereference with class-wide result.
3896 -- If expression is overloaded, retain only interpretations that
3897 -- will yield exact matches.
3899 if Is_Class_Wide_Type (T) then
3900 if not Is_Overloaded (Expr) then
3901 if Base_Type (Etype (Expr)) /= Base_Type (T) then
3902 if Nkind (Expr) = N_Aggregate then
3903 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
3904 else
3905 Wrong_Type (Expr, T);
3906 end if;
3907 end if;
3909 else
3910 Get_First_Interp (Expr, I, It);
3912 while Present (It.Nam) loop
3913 if Base_Type (It.Typ) /= Base_Type (T) then
3914 Remove_Interp (I);
3915 end if;
3917 Get_Next_Interp (I, It);
3918 end loop;
3919 end if;
3920 end if;
3922 Set_Etype (N, T);
3923 end Analyze_Qualified_Expression;
3925 -----------------------------------
3926 -- Analyze_Quantified_Expression --
3927 -----------------------------------
3929 procedure Analyze_Quantified_Expression (N : Node_Id) is
3930 function Is_Empty_Range (Typ : Entity_Id) return Boolean;
3931 -- If the iterator is part of a quantified expression, and the range is
3932 -- known to be statically empty, emit a warning and replace expression
3933 -- with its static value. Returns True if the replacement occurs.
3935 function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean;
3936 -- Determine whether if expression If_Expr lacks an else part or if it
3937 -- has one, it evaluates to True.
3939 --------------------
3940 -- Is_Empty_Range --
3941 --------------------
3943 function Is_Empty_Range (Typ : Entity_Id) return Boolean is
3944 Loc : constant Source_Ptr := Sloc (N);
3946 begin
3947 if Is_Array_Type (Typ)
3948 and then Compile_Time_Known_Bounds (Typ)
3949 and then
3950 (Expr_Value (Type_Low_Bound (Etype (First_Index (Typ)))) >
3951 Expr_Value (Type_High_Bound (Etype (First_Index (Typ)))))
3952 then
3953 Preanalyze_And_Resolve (Condition (N), Standard_Boolean);
3955 if All_Present (N) then
3956 Error_Msg_N
3957 ("??quantified expression with ALL "
3958 & "over a null range has value True", N);
3959 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
3961 else
3962 Error_Msg_N
3963 ("??quantified expression with SOME "
3964 & "over a null range has value False", N);
3965 Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
3966 end if;
3968 Analyze (N);
3969 return True;
3971 else
3972 return False;
3973 end if;
3974 end Is_Empty_Range;
3976 -----------------------------
3977 -- No_Else_Or_Trivial_True --
3978 -----------------------------
3980 function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean is
3981 Else_Expr : constant Node_Id :=
3982 Next (Next (First (Expressions (If_Expr))));
3983 begin
3984 return
3985 No (Else_Expr)
3986 or else (Compile_Time_Known_Value (Else_Expr)
3987 and then Is_True (Expr_Value (Else_Expr)));
3988 end No_Else_Or_Trivial_True;
3990 -- Local variables
3992 Cond : constant Node_Id := Condition (N);
3993 Loop_Id : Entity_Id;
3994 QE_Scop : Entity_Id;
3996 -- Start of processing for Analyze_Quantified_Expression
3998 begin
3999 Check_SPARK_05_Restriction ("quantified expression is not allowed", N);
4001 -- Create a scope to emulate the loop-like behavior of the quantified
4002 -- expression. The scope is needed to provide proper visibility of the
4003 -- loop variable.
4005 QE_Scop := New_Internal_Entity (E_Loop, Current_Scope, Sloc (N), 'L');
4006 Set_Etype (QE_Scop, Standard_Void_Type);
4007 Set_Scope (QE_Scop, Current_Scope);
4008 Set_Parent (QE_Scop, N);
4010 Push_Scope (QE_Scop);
4012 -- All constituents are preanalyzed and resolved to avoid untimely
4013 -- generation of various temporaries and types. Full analysis and
4014 -- expansion is carried out when the quantified expression is
4015 -- transformed into an expression with actions.
4017 if Present (Iterator_Specification (N)) then
4018 Preanalyze (Iterator_Specification (N));
4020 -- Do not proceed with the analysis when the range of iteration is
4021 -- empty. The appropriate error is issued by Is_Empty_Range.
4023 if Is_Entity_Name (Name (Iterator_Specification (N)))
4024 and then Is_Empty_Range (Etype (Name (Iterator_Specification (N))))
4025 then
4026 return;
4027 end if;
4029 else pragma Assert (Present (Loop_Parameter_Specification (N)));
4030 declare
4031 Loop_Par : constant Node_Id := Loop_Parameter_Specification (N);
4033 begin
4034 Preanalyze (Loop_Par);
4036 if Nkind (Discrete_Subtype_Definition (Loop_Par)) = N_Function_Call
4037 and then Parent (Loop_Par) /= N
4038 then
4039 -- The parser cannot distinguish between a loop specification
4040 -- and an iterator specification. If after pre-analysis the
4041 -- proper form has been recognized, rewrite the expression to
4042 -- reflect the right kind. This is needed for proper ASIS
4043 -- navigation. If expansion is enabled, the transformation is
4044 -- performed when the expression is rewritten as a loop.
4046 Set_Iterator_Specification (N,
4047 New_Copy_Tree (Iterator_Specification (Parent (Loop_Par))));
4049 Set_Defining_Identifier (Iterator_Specification (N),
4050 Relocate_Node (Defining_Identifier (Loop_Par)));
4051 Set_Name (Iterator_Specification (N),
4052 Relocate_Node (Discrete_Subtype_Definition (Loop_Par)));
4053 Set_Comes_From_Source (Iterator_Specification (N),
4054 Comes_From_Source (Loop_Parameter_Specification (N)));
4055 Set_Loop_Parameter_Specification (N, Empty);
4056 end if;
4057 end;
4058 end if;
4060 Preanalyze_And_Resolve (Cond, Standard_Boolean);
4062 End_Scope;
4063 Set_Etype (N, Standard_Boolean);
4065 -- Verify that the loop variable is used within the condition of the
4066 -- quantified expression.
4068 if Present (Iterator_Specification (N)) then
4069 Loop_Id := Defining_Identifier (Iterator_Specification (N));
4070 else
4071 Loop_Id := Defining_Identifier (Loop_Parameter_Specification (N));
4072 end if;
4074 if Warn_On_Suspicious_Contract
4075 and then not Referenced (Loop_Id, Cond)
4076 then
4077 -- Generating C, this check causes spurious warnings on inlined
4078 -- postconditions; we can safely disable it because this check
4079 -- was previously performed when analyzing the internally built
4080 -- postconditions procedure.
4082 if Modify_Tree_For_C and then In_Inlined_Body then
4083 null;
4084 else
4085 Error_Msg_N ("?T?unused variable &", Loop_Id);
4086 end if;
4087 end if;
4089 -- Diagnose a possible misuse of the SOME existential quantifier. When
4090 -- we have a quantified expression of the form:
4092 -- for some X => (if P then Q [else True])
4094 -- any value for X that makes P False results in the if expression being
4095 -- trivially True, and so also results in the quantified expression
4096 -- being trivially True.
4098 if Warn_On_Suspicious_Contract
4099 and then not All_Present (N)
4100 and then Nkind (Cond) = N_If_Expression
4101 and then No_Else_Or_Trivial_True (Cond)
4102 then
4103 Error_Msg_N ("?T?suspicious expression", N);
4104 Error_Msg_N ("\\did you mean (for all X ='> (if P then Q))", N);
4105 Error_Msg_N ("\\or (for some X ='> P and then Q) instead'?", N);
4106 end if;
4107 end Analyze_Quantified_Expression;
4109 -------------------
4110 -- Analyze_Range --
4111 -------------------
4113 procedure Analyze_Range (N : Node_Id) is
4114 L : constant Node_Id := Low_Bound (N);
4115 H : constant Node_Id := High_Bound (N);
4116 I1, I2 : Interp_Index;
4117 It1, It2 : Interp;
4119 procedure Check_Common_Type (T1, T2 : Entity_Id);
4120 -- Verify the compatibility of two types, and choose the
4121 -- non universal one if the other is universal.
4123 procedure Check_High_Bound (T : Entity_Id);
4124 -- Test one interpretation of the low bound against all those
4125 -- of the high bound.
4127 procedure Check_Universal_Expression (N : Node_Id);
4128 -- In Ada 83, reject bounds of a universal range that are not literals
4129 -- or entity names.
4131 -----------------------
4132 -- Check_Common_Type --
4133 -----------------------
4135 procedure Check_Common_Type (T1, T2 : Entity_Id) is
4136 begin
4137 if Covers (T1 => T1, T2 => T2)
4138 or else
4139 Covers (T1 => T2, T2 => T1)
4140 then
4141 if T1 = Universal_Integer
4142 or else T1 = Universal_Real
4143 or else T1 = Any_Character
4144 then
4145 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
4147 elsif T1 = T2 then
4148 Add_One_Interp (N, T1, T1);
4150 else
4151 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
4152 end if;
4153 end if;
4154 end Check_Common_Type;
4156 ----------------------
4157 -- Check_High_Bound --
4158 ----------------------
4160 procedure Check_High_Bound (T : Entity_Id) is
4161 begin
4162 if not Is_Overloaded (H) then
4163 Check_Common_Type (T, Etype (H));
4164 else
4165 Get_First_Interp (H, I2, It2);
4166 while Present (It2.Typ) loop
4167 Check_Common_Type (T, It2.Typ);
4168 Get_Next_Interp (I2, It2);
4169 end loop;
4170 end if;
4171 end Check_High_Bound;
4173 -----------------------------
4174 -- Is_Universal_Expression --
4175 -----------------------------
4177 procedure Check_Universal_Expression (N : Node_Id) is
4178 begin
4179 if Etype (N) = Universal_Integer
4180 and then Nkind (N) /= N_Integer_Literal
4181 and then not Is_Entity_Name (N)
4182 and then Nkind (N) /= N_Attribute_Reference
4183 then
4184 Error_Msg_N ("illegal bound in discrete range", N);
4185 end if;
4186 end Check_Universal_Expression;
4188 -- Start of processing for Analyze_Range
4190 begin
4191 Set_Etype (N, Any_Type);
4192 Analyze_Expression (L);
4193 Analyze_Expression (H);
4195 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
4196 return;
4198 else
4199 if not Is_Overloaded (L) then
4200 Check_High_Bound (Etype (L));
4201 else
4202 Get_First_Interp (L, I1, It1);
4203 while Present (It1.Typ) loop
4204 Check_High_Bound (It1.Typ);
4205 Get_Next_Interp (I1, It1);
4206 end loop;
4207 end if;
4209 -- If result is Any_Type, then we did not find a compatible pair
4211 if Etype (N) = Any_Type then
4212 Error_Msg_N ("incompatible types in range ", N);
4213 end if;
4214 end if;
4216 if Ada_Version = Ada_83
4217 and then
4218 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
4219 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
4220 then
4221 Check_Universal_Expression (L);
4222 Check_Universal_Expression (H);
4223 end if;
4225 Check_Function_Writable_Actuals (N);
4226 end Analyze_Range;
4228 -----------------------
4229 -- Analyze_Reference --
4230 -----------------------
4232 procedure Analyze_Reference (N : Node_Id) is
4233 P : constant Node_Id := Prefix (N);
4234 E : Entity_Id;
4235 T : Entity_Id;
4236 Acc_Type : Entity_Id;
4238 begin
4239 Analyze (P);
4241 -- An interesting error check, if we take the 'Ref of an object for
4242 -- which a pragma Atomic or Volatile has been given, and the type of the
4243 -- object is not Atomic or Volatile, then we are in trouble. The problem
4244 -- is that no trace of the atomic/volatile status will remain for the
4245 -- backend to respect when it deals with the resulting pointer, since
4246 -- the pointer type will not be marked atomic (it is a pointer to the
4247 -- base type of the object).
4249 -- It is not clear if that can ever occur, but in case it does, we will
4250 -- generate an error message. Not clear if this message can ever be
4251 -- generated, and pretty clear that it represents a bug if it is, still
4252 -- seems worth checking, except in CodePeer mode where we do not really
4253 -- care and don't want to bother the user.
4255 T := Etype (P);
4257 if Is_Entity_Name (P)
4258 and then Is_Object_Reference (P)
4259 and then not CodePeer_Mode
4260 then
4261 E := Entity (P);
4262 T := Etype (P);
4264 if (Has_Atomic_Components (E)
4265 and then not Has_Atomic_Components (T))
4266 or else
4267 (Has_Volatile_Components (E)
4268 and then not Has_Volatile_Components (T))
4269 or else (Is_Atomic (E) and then not Is_Atomic (T))
4270 or else (Is_Volatile (E) and then not Is_Volatile (T))
4271 then
4272 Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
4273 end if;
4274 end if;
4276 -- Carry on with normal processing
4278 Acc_Type := Create_Itype (E_Allocator_Type, N);
4279 Set_Etype (Acc_Type, Acc_Type);
4280 Set_Directly_Designated_Type (Acc_Type, Etype (P));
4281 Set_Etype (N, Acc_Type);
4282 end Analyze_Reference;
4284 --------------------------------
4285 -- Analyze_Selected_Component --
4286 --------------------------------
4288 -- Prefix is a record type or a task or protected type. In the latter case,
4289 -- the selector must denote a visible entry.
4291 procedure Analyze_Selected_Component (N : Node_Id) is
4292 Name : constant Node_Id := Prefix (N);
4293 Sel : constant Node_Id := Selector_Name (N);
4294 Act_Decl : Node_Id;
4295 Comp : Entity_Id;
4296 Has_Candidate : Boolean := False;
4297 In_Scope : Boolean;
4298 Parent_N : Node_Id;
4299 Pent : Entity_Id := Empty;
4300 Prefix_Type : Entity_Id;
4302 Type_To_Use : Entity_Id;
4303 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
4304 -- a class-wide type, we use its root type, whose components are
4305 -- present in the class-wide type.
4307 Is_Single_Concurrent_Object : Boolean;
4308 -- Set True if the prefix is a single task or a single protected object
4310 procedure Find_Component_In_Instance (Rec : Entity_Id);
4311 -- In an instance, a component of a private extension may not be visible
4312 -- while it was visible in the generic. Search candidate scope for a
4313 -- component with the proper identifier. This is only done if all other
4314 -- searches have failed. If a match is found, the Etype of both N and
4315 -- Sel are set from this component, and the entity of Sel is set to
4316 -- reference this component. If no match is found, Entity (Sel) remains
4317 -- unset. For a derived type that is an actual of the instance, the
4318 -- desired component may be found in any ancestor.
4320 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
4321 -- It is known that the parent of N denotes a subprogram call. Comp
4322 -- is an overloadable component of the concurrent type of the prefix.
4323 -- Determine whether all formals of the parent of N and Comp are mode
4324 -- conformant. If the parent node is not analyzed yet it may be an
4325 -- indexed component rather than a function call.
4327 function Has_Dereference (Nod : Node_Id) return Boolean;
4328 -- Check whether prefix includes a dereference at any level.
4330 --------------------------------
4331 -- Find_Component_In_Instance --
4332 --------------------------------
4334 procedure Find_Component_In_Instance (Rec : Entity_Id) is
4335 Comp : Entity_Id;
4336 Typ : Entity_Id;
4338 begin
4339 Typ := Rec;
4340 while Present (Typ) loop
4341 Comp := First_Component (Typ);
4342 while Present (Comp) loop
4343 if Chars (Comp) = Chars (Sel) then
4344 Set_Entity_With_Checks (Sel, Comp);
4345 Set_Etype (Sel, Etype (Comp));
4346 Set_Etype (N, Etype (Comp));
4347 return;
4348 end if;
4350 Next_Component (Comp);
4351 end loop;
4353 -- If not found, the component may be declared in the parent
4354 -- type or its full view, if any.
4356 if Is_Derived_Type (Typ) then
4357 Typ := Etype (Typ);
4359 if Is_Private_Type (Typ) then
4360 Typ := Full_View (Typ);
4361 end if;
4363 else
4364 return;
4365 end if;
4366 end loop;
4368 -- If we fall through, no match, so no changes made
4370 return;
4371 end Find_Component_In_Instance;
4373 ------------------------------
4374 -- Has_Mode_Conformant_Spec --
4375 ------------------------------
4377 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
4378 Comp_Param : Entity_Id;
4379 Param : Node_Id;
4380 Param_Typ : Entity_Id;
4382 begin
4383 Comp_Param := First_Formal (Comp);
4385 if Nkind (Parent (N)) = N_Indexed_Component then
4386 Param := First (Expressions (Parent (N)));
4387 else
4388 Param := First (Parameter_Associations (Parent (N)));
4389 end if;
4391 while Present (Comp_Param)
4392 and then Present (Param)
4393 loop
4394 Param_Typ := Find_Parameter_Type (Param);
4396 if Present (Param_Typ)
4397 and then
4398 not Conforming_Types
4399 (Etype (Comp_Param), Param_Typ, Mode_Conformant)
4400 then
4401 return False;
4402 end if;
4404 Next_Formal (Comp_Param);
4405 Next (Param);
4406 end loop;
4408 -- One of the specs has additional formals; there is no match, unless
4409 -- this may be an indexing of a parameterless call.
4411 -- Note that when expansion is disabled, the corresponding record
4412 -- type of synchronized types is not constructed, so that there is
4413 -- no point is attempting an interpretation as a prefixed call, as
4414 -- this is bound to fail because the primitive operations will not
4415 -- be properly located.
4417 if Present (Comp_Param) or else Present (Param) then
4418 if Needs_No_Actuals (Comp)
4419 and then Is_Array_Type (Etype (Comp))
4420 and then not Expander_Active
4421 then
4422 return True;
4423 else
4424 return False;
4425 end if;
4426 end if;
4428 return True;
4429 end Has_Mode_Conformant_Spec;
4431 ---------------------
4432 -- Has_Dereference --
4433 ---------------------
4435 function Has_Dereference (Nod : Node_Id) return Boolean is
4436 begin
4437 if Nkind (Nod) = N_Explicit_Dereference then
4438 return True;
4440 -- When expansion is disabled an explicit dereference may not have
4441 -- been inserted, but if this is an access type the indirection makes
4442 -- the call safe.
4444 elsif Is_Access_Type (Etype (Nod)) then
4445 return True;
4447 elsif Nkind_In (Nod, N_Indexed_Component, N_Selected_Component) then
4448 return Has_Dereference (Prefix (Nod));
4450 else
4451 return False;
4452 end if;
4453 end Has_Dereference;
4455 -- Start of processing for Analyze_Selected_Component
4457 begin
4458 Set_Etype (N, Any_Type);
4460 if Is_Overloaded (Name) then
4461 Analyze_Overloaded_Selected_Component (N);
4462 return;
4464 elsif Etype (Name) = Any_Type then
4465 Set_Entity (Sel, Any_Id);
4466 Set_Etype (Sel, Any_Type);
4467 return;
4469 else
4470 Prefix_Type := Etype (Name);
4471 end if;
4473 if Is_Access_Type (Prefix_Type) then
4475 -- A RACW object can never be used as prefix of a selected component
4476 -- since that means it is dereferenced without being a controlling
4477 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
4478 -- reporting an error, we must check whether this is actually a
4479 -- dispatching call in prefix form.
4481 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
4482 and then Comes_From_Source (N)
4483 then
4484 if Try_Object_Operation (N) then
4485 return;
4486 else
4487 Error_Msg_N
4488 ("invalid dereference of a remote access-to-class-wide value",
4490 end if;
4492 -- Normal case of selected component applied to access type
4494 else
4495 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
4497 if Is_Entity_Name (Name) then
4498 Pent := Entity (Name);
4499 elsif Nkind (Name) = N_Selected_Component
4500 and then Is_Entity_Name (Selector_Name (Name))
4501 then
4502 Pent := Entity (Selector_Name (Name));
4503 end if;
4505 Prefix_Type := Process_Implicit_Dereference_Prefix (Pent, Name);
4506 end if;
4508 -- If we have an explicit dereference of a remote access-to-class-wide
4509 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
4510 -- have to check for the case of a prefix that is a controlling operand
4511 -- of a prefixed dispatching call, as the dereference is legal in that
4512 -- case. Normally this condition is checked in Validate_Remote_Access_
4513 -- To_Class_Wide_Type, but we have to defer the checking for selected
4514 -- component prefixes because of the prefixed dispatching call case.
4515 -- Note that implicit dereferences are checked for this just above.
4517 elsif Nkind (Name) = N_Explicit_Dereference
4518 and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
4519 and then Comes_From_Source (N)
4520 then
4521 if Try_Object_Operation (N) then
4522 return;
4523 else
4524 Error_Msg_N
4525 ("invalid dereference of a remote access-to-class-wide value",
4527 end if;
4528 end if;
4530 -- (Ada 2005): if the prefix is the limited view of a type, and
4531 -- the context already includes the full view, use the full view
4532 -- in what follows, either to retrieve a component of to find
4533 -- a primitive operation. If the prefix is an explicit dereference,
4534 -- set the type of the prefix to reflect this transformation.
4535 -- If the non-limited view is itself an incomplete type, get the
4536 -- full view if available.
4538 if From_Limited_With (Prefix_Type)
4539 and then Has_Non_Limited_View (Prefix_Type)
4540 then
4541 Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
4543 if Nkind (N) = N_Explicit_Dereference then
4544 Set_Etype (Prefix (N), Prefix_Type);
4545 end if;
4546 end if;
4548 if Ekind (Prefix_Type) = E_Private_Subtype then
4549 Prefix_Type := Base_Type (Prefix_Type);
4550 end if;
4552 Type_To_Use := Prefix_Type;
4554 -- For class-wide types, use the entity list of the root type. This
4555 -- indirection is specially important for private extensions because
4556 -- only the root type get switched (not the class-wide type).
4558 if Is_Class_Wide_Type (Prefix_Type) then
4559 Type_To_Use := Root_Type (Prefix_Type);
4560 end if;
4562 -- If the prefix is a single concurrent object, use its name in error
4563 -- messages, rather than that of its anonymous type.
4565 Is_Single_Concurrent_Object :=
4566 Is_Concurrent_Type (Prefix_Type)
4567 and then Is_Internal_Name (Chars (Prefix_Type))
4568 and then not Is_Derived_Type (Prefix_Type)
4569 and then Is_Entity_Name (Name);
4571 Comp := First_Entity (Type_To_Use);
4573 -- If the selector has an original discriminant, the node appears in
4574 -- an instance. Replace the discriminant with the corresponding one
4575 -- in the current discriminated type. For nested generics, this must
4576 -- be done transitively, so note the new original discriminant.
4578 if Nkind (Sel) = N_Identifier
4579 and then In_Instance
4580 and then Present (Original_Discriminant (Sel))
4581 then
4582 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
4584 -- Mark entity before rewriting, for completeness and because
4585 -- subsequent semantic checks might examine the original node.
4587 Set_Entity (Sel, Comp);
4588 Rewrite (Selector_Name (N), New_Occurrence_Of (Comp, Sloc (N)));
4589 Set_Original_Discriminant (Selector_Name (N), Comp);
4590 Set_Etype (N, Etype (Comp));
4591 Check_Implicit_Dereference (N, Etype (Comp));
4593 if Is_Access_Type (Etype (Name)) then
4594 Insert_Explicit_Dereference (Name);
4595 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
4596 end if;
4598 elsif Is_Record_Type (Prefix_Type) then
4600 -- Find component with given name. In an instance, if the node is
4601 -- known as a prefixed call, do not examine components whose
4602 -- visibility may be accidental.
4604 while Present (Comp) and then not Is_Prefixed_Call (N) loop
4605 if Chars (Comp) = Chars (Sel)
4606 and then Is_Visible_Component (Comp, N)
4607 then
4608 Set_Entity_With_Checks (Sel, Comp);
4609 Set_Etype (Sel, Etype (Comp));
4611 if Ekind (Comp) = E_Discriminant then
4612 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
4613 Error_Msg_N
4614 ("cannot reference discriminant of unchecked union",
4615 Sel);
4616 end if;
4618 if Is_Generic_Type (Prefix_Type)
4619 or else
4620 Is_Generic_Type (Root_Type (Prefix_Type))
4621 then
4622 Set_Original_Discriminant (Sel, Comp);
4623 end if;
4624 end if;
4626 -- Resolve the prefix early otherwise it is not possible to
4627 -- build the actual subtype of the component: it may need
4628 -- to duplicate this prefix and duplication is only allowed
4629 -- on fully resolved expressions.
4631 Resolve (Name);
4633 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
4634 -- subtypes in a package specification.
4635 -- Example:
4637 -- limited with Pkg;
4638 -- package Pkg is
4639 -- type Acc_Inc is access Pkg.T;
4640 -- X : Acc_Inc;
4641 -- N : Natural := X.all.Comp; -- ERROR, limited view
4642 -- end Pkg; -- Comp is not visible
4644 if Nkind (Name) = N_Explicit_Dereference
4645 and then From_Limited_With (Etype (Prefix (Name)))
4646 and then not Is_Potentially_Use_Visible (Etype (Name))
4647 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
4648 N_Package_Specification
4649 then
4650 Error_Msg_NE
4651 ("premature usage of incomplete}", Prefix (Name),
4652 Etype (Prefix (Name)));
4653 end if;
4655 -- We never need an actual subtype for the case of a selection
4656 -- for a indexed component of a non-packed array, since in
4657 -- this case gigi generates all the checks and can find the
4658 -- necessary bounds information.
4660 -- We also do not need an actual subtype for the case of a
4661 -- first, last, length, or range attribute applied to a
4662 -- non-packed array, since gigi can again get the bounds in
4663 -- these cases (gigi cannot handle the packed case, since it
4664 -- has the bounds of the packed array type, not the original
4665 -- bounds of the type). However, if the prefix is itself a
4666 -- selected component, as in a.b.c (i), gigi may regard a.b.c
4667 -- as a dynamic-sized temporary, so we do generate an actual
4668 -- subtype for this case.
4670 Parent_N := Parent (N);
4672 if not Is_Packed (Etype (Comp))
4673 and then
4674 ((Nkind (Parent_N) = N_Indexed_Component
4675 and then Nkind (Name) /= N_Selected_Component)
4676 or else
4677 (Nkind (Parent_N) = N_Attribute_Reference
4678 and then
4679 Nam_In (Attribute_Name (Parent_N), Name_First,
4680 Name_Last,
4681 Name_Length,
4682 Name_Range)))
4683 then
4684 Set_Etype (N, Etype (Comp));
4686 -- If full analysis is not enabled, we do not generate an
4687 -- actual subtype, because in the absence of expansion
4688 -- reference to a formal of a protected type, for example,
4689 -- will not be properly transformed, and will lead to
4690 -- out-of-scope references in gigi.
4692 -- In all other cases, we currently build an actual subtype.
4693 -- It seems likely that many of these cases can be avoided,
4694 -- but right now, the front end makes direct references to the
4695 -- bounds (e.g. in generating a length check), and if we do
4696 -- not make an actual subtype, we end up getting a direct
4697 -- reference to a discriminant, which will not do.
4699 elsif Full_Analysis then
4700 Act_Decl :=
4701 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
4702 Insert_Action (N, Act_Decl);
4704 if No (Act_Decl) then
4705 Set_Etype (N, Etype (Comp));
4707 else
4708 -- Component type depends on discriminants. Enter the
4709 -- main attributes of the subtype.
4711 declare
4712 Subt : constant Entity_Id :=
4713 Defining_Identifier (Act_Decl);
4715 begin
4716 Set_Etype (Subt, Base_Type (Etype (Comp)));
4717 Set_Ekind (Subt, Ekind (Etype (Comp)));
4718 Set_Etype (N, Subt);
4719 end;
4720 end if;
4722 -- If Full_Analysis not enabled, just set the Etype
4724 else
4725 Set_Etype (N, Etype (Comp));
4726 end if;
4728 Check_Implicit_Dereference (N, Etype (N));
4729 return;
4730 end if;
4732 -- If the prefix is a private extension, check only the visible
4733 -- components of the partial view. This must include the tag,
4734 -- which can appear in expanded code in a tag check.
4736 if Ekind (Type_To_Use) = E_Record_Type_With_Private
4737 and then Chars (Selector_Name (N)) /= Name_uTag
4738 then
4739 exit when Comp = Last_Entity (Type_To_Use);
4740 end if;
4742 Next_Entity (Comp);
4743 end loop;
4745 -- Ada 2005 (AI-252): The selected component can be interpreted as
4746 -- a prefixed view of a subprogram. Depending on the context, this is
4747 -- either a name that can appear in a renaming declaration, or part
4748 -- of an enclosing call given in prefix form.
4750 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
4751 -- selected component should resolve to a name.
4753 if Ada_Version >= Ada_2005
4754 and then Is_Tagged_Type (Prefix_Type)
4755 and then not Is_Concurrent_Type (Prefix_Type)
4756 then
4757 if Nkind (Parent (N)) = N_Generic_Association
4758 or else Nkind (Parent (N)) = N_Requeue_Statement
4759 or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
4760 then
4761 if Find_Primitive_Operation (N) then
4762 return;
4763 end if;
4765 elsif Try_Object_Operation (N) then
4766 return;
4767 end if;
4769 -- If the transformation fails, it will be necessary to redo the
4770 -- analysis with all errors enabled, to indicate candidate
4771 -- interpretations and reasons for each failure ???
4773 end if;
4775 elsif Is_Private_Type (Prefix_Type) then
4777 -- Allow access only to discriminants of the type. If the type has
4778 -- no full view, gigi uses the parent type for the components, so we
4779 -- do the same here.
4781 if No (Full_View (Prefix_Type)) then
4782 Type_To_Use := Root_Type (Base_Type (Prefix_Type));
4783 Comp := First_Entity (Type_To_Use);
4784 end if;
4786 while Present (Comp) loop
4787 if Chars (Comp) = Chars (Sel) then
4788 if Ekind (Comp) = E_Discriminant then
4789 Set_Entity_With_Checks (Sel, Comp);
4790 Generate_Reference (Comp, Sel);
4792 Set_Etype (Sel, Etype (Comp));
4793 Set_Etype (N, Etype (Comp));
4794 Check_Implicit_Dereference (N, Etype (N));
4796 if Is_Generic_Type (Prefix_Type)
4797 or else Is_Generic_Type (Root_Type (Prefix_Type))
4798 then
4799 Set_Original_Discriminant (Sel, Comp);
4800 end if;
4802 -- Before declaring an error, check whether this is tagged
4803 -- private type and a call to a primitive operation.
4805 elsif Ada_Version >= Ada_2005
4806 and then Is_Tagged_Type (Prefix_Type)
4807 and then Try_Object_Operation (N)
4808 then
4809 return;
4811 else
4812 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4813 Error_Msg_NE ("invisible selector& for }", N, Sel);
4814 Set_Entity (Sel, Any_Id);
4815 Set_Etype (N, Any_Type);
4816 end if;
4818 return;
4819 end if;
4821 Next_Entity (Comp);
4822 end loop;
4824 elsif Is_Concurrent_Type (Prefix_Type) then
4826 -- Find visible operation with given name. For a protected type,
4827 -- the possible candidates are discriminants, entries or protected
4828 -- procedures. For a task type, the set can only include entries or
4829 -- discriminants if the task type is not an enclosing scope. If it
4830 -- is an enclosing scope (e.g. in an inner task) then all entities
4831 -- are visible, but the prefix must denote the enclosing scope, i.e.
4832 -- can only be a direct name or an expanded name.
4834 Set_Etype (Sel, Any_Type);
4835 In_Scope := In_Open_Scopes (Prefix_Type);
4837 while Present (Comp) loop
4839 -- Do not examine private operations of the type if not within
4840 -- its scope.
4842 if Chars (Comp) = Chars (Sel) then
4843 if Is_Overloadable (Comp)
4844 and then (In_Scope
4845 or else Comp /= First_Private_Entity (Type_To_Use))
4846 then
4847 Add_One_Interp (Sel, Comp, Etype (Comp));
4849 -- If the prefix is tagged, the correct interpretation may
4850 -- lie in the primitive or class-wide operations of the
4851 -- type. Perform a simple conformance check to determine
4852 -- whether Try_Object_Operation should be invoked even if
4853 -- a visible entity is found.
4855 if Is_Tagged_Type (Prefix_Type)
4856 and then Nkind_In (Parent (N), N_Function_Call,
4857 N_Indexed_Component,
4858 N_Procedure_Call_Statement)
4859 and then Has_Mode_Conformant_Spec (Comp)
4860 then
4861 Has_Candidate := True;
4862 end if;
4864 -- Note: a selected component may not denote a component of a
4865 -- protected type (4.1.3(7)).
4867 elsif Ekind_In (Comp, E_Discriminant, E_Entry_Family)
4868 or else (In_Scope
4869 and then not Is_Protected_Type (Prefix_Type)
4870 and then Is_Entity_Name (Name))
4871 then
4872 Set_Entity_With_Checks (Sel, Comp);
4873 Generate_Reference (Comp, Sel);
4875 -- The selector is not overloadable, so we have a candidate
4876 -- interpretation.
4878 Has_Candidate := True;
4880 else
4881 goto Next_Comp;
4882 end if;
4884 Set_Etype (Sel, Etype (Comp));
4885 Set_Etype (N, Etype (Comp));
4887 if Ekind (Comp) = E_Discriminant then
4888 Set_Original_Discriminant (Sel, Comp);
4889 end if;
4891 -- For access type case, introduce explicit dereference for
4892 -- more uniform treatment of entry calls.
4894 if Is_Access_Type (Etype (Name)) then
4895 Insert_Explicit_Dereference (Name);
4896 Error_Msg_NW
4897 (Warn_On_Dereference, "?d?implicit dereference", N);
4898 end if;
4899 end if;
4901 <<Next_Comp>>
4902 Next_Entity (Comp);
4903 exit when not In_Scope
4904 and then
4905 Comp = First_Private_Entity (Base_Type (Prefix_Type));
4906 end loop;
4908 -- If the scope is a current instance, the prefix cannot be an
4909 -- expression of the same type, unless the selector designates a
4910 -- public operation (otherwise that would represent an attempt to
4911 -- reach an internal entity of another synchronized object).
4912 -- This is legal if prefix is an access to such type and there is
4913 -- a dereference, or is a component with a dereferenced prefix.
4914 -- It is also legal if the prefix is a component of a task type,
4915 -- and the selector is one of the task operations.
4917 if In_Scope
4918 and then not Is_Entity_Name (Name)
4919 and then not Has_Dereference (Name)
4920 then
4921 if Is_Task_Type (Prefix_Type)
4922 and then Present (Entity (Sel))
4923 and then Ekind_In (Entity (Sel), E_Entry, E_Entry_Family)
4924 then
4925 null;
4927 else
4928 Error_Msg_NE
4929 ("invalid reference to internal operation of some object of "
4930 & "type &", N, Type_To_Use);
4931 Set_Entity (Sel, Any_Id);
4932 Set_Etype (Sel, Any_Type);
4933 return;
4934 end if;
4935 end if;
4937 -- If there is no visible entity with the given name or none of the
4938 -- visible entities are plausible interpretations, check whether
4939 -- there is some other primitive operation with that name.
4941 if Ada_Version >= Ada_2005 and then Is_Tagged_Type (Prefix_Type) then
4942 if (Etype (N) = Any_Type
4943 or else not Has_Candidate)
4944 and then Try_Object_Operation (N)
4945 then
4946 return;
4948 -- If the context is not syntactically a procedure call, it
4949 -- may be a call to a primitive function declared outside of
4950 -- the synchronized type.
4952 -- If the context is a procedure call, there might still be
4953 -- an overloading between an entry and a primitive procedure
4954 -- declared outside of the synchronized type, called in prefix
4955 -- notation. This is harder to disambiguate because in one case
4956 -- the controlling formal is implicit ???
4958 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
4959 and then Nkind (Parent (N)) /= N_Indexed_Component
4960 and then Try_Object_Operation (N)
4961 then
4962 return;
4963 end if;
4965 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
4966 -- entry or procedure of a tagged concurrent type we must check
4967 -- if there are class-wide subprograms covering the primitive. If
4968 -- true then Try_Object_Operation reports the error.
4970 if Has_Candidate
4971 and then Is_Concurrent_Type (Prefix_Type)
4972 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
4973 then
4974 -- Duplicate the call. This is required to avoid problems with
4975 -- the tree transformations performed by Try_Object_Operation.
4976 -- Set properly the parent of the copied call, because it is
4977 -- about to be reanalyzed.
4979 declare
4980 Par : constant Node_Id := New_Copy_Tree (Parent (N));
4982 begin
4983 Set_Parent (Par, Parent (Parent (N)));
4985 if Try_Object_Operation
4986 (Sinfo.Name (Par), CW_Test_Only => True)
4987 then
4988 return;
4989 end if;
4990 end;
4991 end if;
4992 end if;
4994 if Etype (N) = Any_Type and then Is_Protected_Type (Prefix_Type) then
4996 -- Case of a prefix of a protected type: selector might denote
4997 -- an invisible private component.
4999 Comp := First_Private_Entity (Base_Type (Prefix_Type));
5000 while Present (Comp) and then Chars (Comp) /= Chars (Sel) loop
5001 Next_Entity (Comp);
5002 end loop;
5004 if Present (Comp) then
5005 if Is_Single_Concurrent_Object then
5006 Error_Msg_Node_2 := Entity (Name);
5007 Error_Msg_NE ("invisible selector& for &", N, Sel);
5009 else
5010 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
5011 Error_Msg_NE ("invisible selector& for }", N, Sel);
5012 end if;
5013 return;
5014 end if;
5015 end if;
5017 Set_Is_Overloaded (N, Is_Overloaded (Sel));
5019 else
5020 -- Invalid prefix
5022 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
5023 end if;
5025 -- If N still has no type, the component is not defined in the prefix
5027 if Etype (N) = Any_Type then
5029 if Is_Single_Concurrent_Object then
5030 Error_Msg_Node_2 := Entity (Name);
5031 Error_Msg_NE ("no selector& for&", N, Sel);
5033 Check_Misspelled_Selector (Type_To_Use, Sel);
5035 -- If this is a derived formal type, the parent may have different
5036 -- visibility at this point. Try for an inherited component before
5037 -- reporting an error.
5039 elsif Is_Generic_Type (Prefix_Type)
5040 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
5041 and then Prefix_Type /= Etype (Prefix_Type)
5042 and then Is_Record_Type (Etype (Prefix_Type))
5043 then
5044 Set_Etype (Prefix (N), Etype (Prefix_Type));
5045 Analyze_Selected_Component (N);
5046 return;
5048 -- Similarly, if this is the actual for a formal derived type, or
5049 -- a derived type thereof, the component inherited from the generic
5050 -- parent may not be visible in the actual, but the selected
5051 -- component is legal. Climb up the derivation chain of the generic
5052 -- parent type until we find the proper ancestor type.
5054 elsif In_Instance and then Is_Tagged_Type (Prefix_Type) then
5055 declare
5056 Par : Entity_Id := Prefix_Type;
5057 begin
5058 -- Climb up derivation chain to generic actual subtype
5060 while not Is_Generic_Actual_Type (Par) loop
5061 if Ekind (Par) = E_Record_Type then
5062 Par := Parent_Subtype (Par);
5063 exit when No (Par);
5064 else
5065 exit when Par = Etype (Par);
5066 Par := Etype (Par);
5067 end if;
5068 end loop;
5070 if Present (Par) and then Is_Generic_Actual_Type (Par) then
5072 -- Now look for component in ancestor types
5074 Par := Generic_Parent_Type (Declaration_Node (Par));
5075 loop
5076 Find_Component_In_Instance (Par);
5077 exit when Present (Entity (Sel))
5078 or else Par = Etype (Par);
5079 Par := Etype (Par);
5080 end loop;
5082 -- Another special case: the type is an extension of a private
5083 -- type T, is an actual in an instance, and we are in the body
5084 -- of the instance, so the generic body had a full view of the
5085 -- type declaration for T or of some ancestor that defines the
5086 -- component in question.
5088 elsif Is_Derived_Type (Type_To_Use)
5089 and then Used_As_Generic_Actual (Type_To_Use)
5090 and then In_Instance_Body
5091 then
5092 Find_Component_In_Instance (Parent_Subtype (Type_To_Use));
5094 -- In ASIS mode the generic parent type may be absent. Examine
5095 -- the parent type directly for a component that may have been
5096 -- visible in a parent generic unit.
5098 elsif Is_Derived_Type (Prefix_Type) then
5099 Par := Etype (Prefix_Type);
5100 Find_Component_In_Instance (Par);
5101 end if;
5102 end;
5104 -- The search above must have eventually succeeded, since the
5105 -- selected component was legal in the generic.
5107 if No (Entity (Sel)) then
5108 raise Program_Error;
5109 end if;
5111 return;
5113 -- Component not found, specialize error message when appropriate
5115 else
5116 if Ekind (Prefix_Type) = E_Record_Subtype then
5118 -- Check whether this is a component of the base type which
5119 -- is absent from a statically constrained subtype. This will
5120 -- raise constraint error at run time, but is not a compile-
5121 -- time error. When the selector is illegal for base type as
5122 -- well fall through and generate a compilation error anyway.
5124 Comp := First_Component (Base_Type (Prefix_Type));
5125 while Present (Comp) loop
5126 if Chars (Comp) = Chars (Sel)
5127 and then Is_Visible_Component (Comp)
5128 then
5129 Set_Entity_With_Checks (Sel, Comp);
5130 Generate_Reference (Comp, Sel);
5131 Set_Etype (Sel, Etype (Comp));
5132 Set_Etype (N, Etype (Comp));
5134 -- Emit appropriate message. The node will be replaced
5135 -- by an appropriate raise statement.
5137 -- Note that in SPARK mode, as with all calls to apply a
5138 -- compile time constraint error, this will be made into
5139 -- an error to simplify the processing of the formal
5140 -- verification backend.
5142 Apply_Compile_Time_Constraint_Error
5143 (N, "component not present in }??",
5144 CE_Discriminant_Check_Failed,
5145 Ent => Prefix_Type, Rep => False);
5147 Set_Raises_Constraint_Error (N);
5148 return;
5149 end if;
5151 Next_Component (Comp);
5152 end loop;
5154 end if;
5156 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
5157 Error_Msg_NE ("no selector& for}", N, Sel);
5159 -- Add information in the case of an incomplete prefix
5161 if Is_Incomplete_Type (Type_To_Use) then
5162 declare
5163 Inc : constant Entity_Id := First_Subtype (Type_To_Use);
5165 begin
5166 if From_Limited_With (Scope (Type_To_Use)) then
5167 Error_Msg_NE
5168 ("\limited view of& has no components", N, Inc);
5170 else
5171 Error_Msg_NE
5172 ("\premature usage of incomplete type&", N, Inc);
5174 if Nkind (Parent (Inc)) =
5175 N_Incomplete_Type_Declaration
5176 then
5177 -- Record location of premature use in entity so that
5178 -- a continuation message is generated when the
5179 -- completion is seen.
5181 Set_Premature_Use (Parent (Inc), N);
5182 end if;
5183 end if;
5184 end;
5185 end if;
5187 Check_Misspelled_Selector (Type_To_Use, Sel);
5188 end if;
5190 Set_Entity (Sel, Any_Id);
5191 Set_Etype (Sel, Any_Type);
5192 end if;
5193 end Analyze_Selected_Component;
5195 ---------------------------
5196 -- Analyze_Short_Circuit --
5197 ---------------------------
5199 procedure Analyze_Short_Circuit (N : Node_Id) is
5200 L : constant Node_Id := Left_Opnd (N);
5201 R : constant Node_Id := Right_Opnd (N);
5202 Ind : Interp_Index;
5203 It : Interp;
5205 begin
5206 Analyze_Expression (L);
5207 Analyze_Expression (R);
5208 Set_Etype (N, Any_Type);
5210 if not Is_Overloaded (L) then
5211 if Root_Type (Etype (L)) = Standard_Boolean
5212 and then Has_Compatible_Type (R, Etype (L))
5213 then
5214 Add_One_Interp (N, Etype (L), Etype (L));
5215 end if;
5217 else
5218 Get_First_Interp (L, Ind, It);
5219 while Present (It.Typ) loop
5220 if Root_Type (It.Typ) = Standard_Boolean
5221 and then Has_Compatible_Type (R, It.Typ)
5222 then
5223 Add_One_Interp (N, It.Typ, It.Typ);
5224 end if;
5226 Get_Next_Interp (Ind, It);
5227 end loop;
5228 end if;
5230 -- Here we have failed to find an interpretation. Clearly we know that
5231 -- it is not the case that both operands can have an interpretation of
5232 -- Boolean, but this is by far the most likely intended interpretation.
5233 -- So we simply resolve both operands as Booleans, and at least one of
5234 -- these resolutions will generate an error message, and we do not need
5235 -- to give another error message on the short circuit operation itself.
5237 if Etype (N) = Any_Type then
5238 Resolve (L, Standard_Boolean);
5239 Resolve (R, Standard_Boolean);
5240 Set_Etype (N, Standard_Boolean);
5241 end if;
5242 end Analyze_Short_Circuit;
5244 -------------------
5245 -- Analyze_Slice --
5246 -------------------
5248 procedure Analyze_Slice (N : Node_Id) is
5249 D : constant Node_Id := Discrete_Range (N);
5250 P : constant Node_Id := Prefix (N);
5251 Array_Type : Entity_Id;
5252 Index_Type : Entity_Id;
5254 procedure Analyze_Overloaded_Slice;
5255 -- If the prefix is overloaded, select those interpretations that
5256 -- yield a one-dimensional array type.
5258 ------------------------------
5259 -- Analyze_Overloaded_Slice --
5260 ------------------------------
5262 procedure Analyze_Overloaded_Slice is
5263 I : Interp_Index;
5264 It : Interp;
5265 Typ : Entity_Id;
5267 begin
5268 Set_Etype (N, Any_Type);
5270 Get_First_Interp (P, I, It);
5271 while Present (It.Nam) loop
5272 Typ := It.Typ;
5274 if Is_Access_Type (Typ) then
5275 Typ := Designated_Type (Typ);
5276 Error_Msg_NW
5277 (Warn_On_Dereference, "?d?implicit dereference", N);
5278 end if;
5280 if Is_Array_Type (Typ)
5281 and then Number_Dimensions (Typ) = 1
5282 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
5283 then
5284 Add_One_Interp (N, Typ, Typ);
5285 end if;
5287 Get_Next_Interp (I, It);
5288 end loop;
5290 if Etype (N) = Any_Type then
5291 Error_Msg_N ("expect array type in prefix of slice", N);
5292 end if;
5293 end Analyze_Overloaded_Slice;
5295 -- Start of processing for Analyze_Slice
5297 begin
5298 if Comes_From_Source (N) then
5299 Check_SPARK_05_Restriction ("slice is not allowed", N);
5300 end if;
5302 Analyze (P);
5303 Analyze (D);
5305 if Is_Overloaded (P) then
5306 Analyze_Overloaded_Slice;
5308 else
5309 Array_Type := Etype (P);
5310 Set_Etype (N, Any_Type);
5312 if Is_Access_Type (Array_Type) then
5313 Array_Type := Designated_Type (Array_Type);
5314 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
5315 end if;
5317 if not Is_Array_Type (Array_Type) then
5318 Wrong_Type (P, Any_Array);
5320 elsif Number_Dimensions (Array_Type) > 1 then
5321 Error_Msg_N
5322 ("type is not one-dimensional array in slice prefix", N);
5324 else
5325 if Ekind (Array_Type) = E_String_Literal_Subtype then
5326 Index_Type := Etype (String_Literal_Low_Bound (Array_Type));
5327 else
5328 Index_Type := Etype (First_Index (Array_Type));
5329 end if;
5331 if not Has_Compatible_Type (D, Index_Type) then
5332 Wrong_Type (D, Index_Type);
5333 else
5334 Set_Etype (N, Array_Type);
5335 end if;
5336 end if;
5337 end if;
5338 end Analyze_Slice;
5340 -----------------------------
5341 -- Analyze_Type_Conversion --
5342 -----------------------------
5344 procedure Analyze_Type_Conversion (N : Node_Id) is
5345 Expr : constant Node_Id := Expression (N);
5346 Typ : Entity_Id;
5348 begin
5349 -- If Conversion_OK is set, then the Etype is already set, and the only
5350 -- processing required is to analyze the expression. This is used to
5351 -- construct certain "illegal" conversions which are not allowed by Ada
5352 -- semantics, but can be handled by Gigi, see Sinfo for further details.
5354 if Conversion_OK (N) then
5355 Analyze (Expr);
5356 return;
5357 end if;
5359 -- Otherwise full type analysis is required, as well as some semantic
5360 -- checks to make sure the argument of the conversion is appropriate.
5362 Find_Type (Subtype_Mark (N));
5363 Typ := Entity (Subtype_Mark (N));
5364 Set_Etype (N, Typ);
5365 Check_Fully_Declared (Typ, N);
5366 Analyze_Expression (Expr);
5367 Validate_Remote_Type_Type_Conversion (N);
5369 -- Only remaining step is validity checks on the argument. These
5370 -- are skipped if the conversion does not come from the source.
5372 if not Comes_From_Source (N) then
5373 return;
5375 -- If there was an error in a generic unit, no need to replicate the
5376 -- error message. Conversely, constant-folding in the generic may
5377 -- transform the argument of a conversion into a string literal, which
5378 -- is legal. Therefore the following tests are not performed in an
5379 -- instance. The same applies to an inlined body.
5381 elsif In_Instance or In_Inlined_Body then
5382 return;
5384 elsif Nkind (Expr) = N_Null then
5385 Error_Msg_N ("argument of conversion cannot be null", N);
5386 Error_Msg_N ("\use qualified expression instead", N);
5387 Set_Etype (N, Any_Type);
5389 elsif Nkind (Expr) = N_Aggregate then
5390 Error_Msg_N ("argument of conversion cannot be aggregate", N);
5391 Error_Msg_N ("\use qualified expression instead", N);
5393 elsif Nkind (Expr) = N_Allocator then
5394 Error_Msg_N ("argument of conversion cannot be an allocator", N);
5395 Error_Msg_N ("\use qualified expression instead", N);
5397 elsif Nkind (Expr) = N_String_Literal then
5398 Error_Msg_N ("argument of conversion cannot be string literal", N);
5399 Error_Msg_N ("\use qualified expression instead", N);
5401 elsif Nkind (Expr) = N_Character_Literal then
5402 if Ada_Version = Ada_83 then
5403 Resolve (Expr, Typ);
5404 else
5405 Error_Msg_N ("argument of conversion cannot be character literal",
5407 Error_Msg_N ("\use qualified expression instead", N);
5408 end if;
5410 elsif Nkind (Expr) = N_Attribute_Reference
5411 and then Nam_In (Attribute_Name (Expr), Name_Access,
5412 Name_Unchecked_Access,
5413 Name_Unrestricted_Access)
5414 then
5415 Error_Msg_N ("argument of conversion cannot be access", N);
5416 Error_Msg_N ("\use qualified expression instead", N);
5417 end if;
5419 -- A formal parameter of a specific tagged type whose related subprogram
5420 -- is subject to pragma Extensions_Visible with value "False" cannot
5421 -- appear in a class-wide conversion (SPARK RM 6.1.7(3)). Do not check
5422 -- internally generated expressions.
5424 if Is_Class_Wide_Type (Typ)
5425 and then Comes_From_Source (Expr)
5426 and then Is_EVF_Expression (Expr)
5427 then
5428 Error_Msg_N
5429 ("formal parameter cannot be converted to class-wide type when "
5430 & "Extensions_Visible is False", Expr);
5431 end if;
5432 end Analyze_Type_Conversion;
5434 ----------------------
5435 -- Analyze_Unary_Op --
5436 ----------------------
5438 procedure Analyze_Unary_Op (N : Node_Id) is
5439 R : constant Node_Id := Right_Opnd (N);
5440 Op_Id : Entity_Id := Entity (N);
5442 begin
5443 Set_Etype (N, Any_Type);
5444 Candidate_Type := Empty;
5446 Analyze_Expression (R);
5448 if Present (Op_Id) then
5449 if Ekind (Op_Id) = E_Operator then
5450 Find_Unary_Types (R, Op_Id, N);
5451 else
5452 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5453 end if;
5455 else
5456 Op_Id := Get_Name_Entity_Id (Chars (N));
5457 while Present (Op_Id) loop
5458 if Ekind (Op_Id) = E_Operator then
5459 if No (Next_Entity (First_Entity (Op_Id))) then
5460 Find_Unary_Types (R, Op_Id, N);
5461 end if;
5463 elsif Is_Overloadable (Op_Id) then
5464 Analyze_User_Defined_Unary_Op (N, Op_Id);
5465 end if;
5467 Op_Id := Homonym (Op_Id);
5468 end loop;
5469 end if;
5471 Operator_Check (N);
5472 end Analyze_Unary_Op;
5474 ----------------------------------
5475 -- Analyze_Unchecked_Expression --
5476 ----------------------------------
5478 procedure Analyze_Unchecked_Expression (N : Node_Id) is
5479 begin
5480 Analyze (Expression (N), Suppress => All_Checks);
5481 Set_Etype (N, Etype (Expression (N)));
5482 Save_Interps (Expression (N), N);
5483 end Analyze_Unchecked_Expression;
5485 ---------------------------------------
5486 -- Analyze_Unchecked_Type_Conversion --
5487 ---------------------------------------
5489 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
5490 begin
5491 Find_Type (Subtype_Mark (N));
5492 Analyze_Expression (Expression (N));
5493 Set_Etype (N, Entity (Subtype_Mark (N)));
5494 end Analyze_Unchecked_Type_Conversion;
5496 ------------------------------------
5497 -- Analyze_User_Defined_Binary_Op --
5498 ------------------------------------
5500 procedure Analyze_User_Defined_Binary_Op
5501 (N : Node_Id;
5502 Op_Id : Entity_Id)
5504 begin
5505 -- Only do analysis if the operator Comes_From_Source, since otherwise
5506 -- the operator was generated by the expander, and all such operators
5507 -- always refer to the operators in package Standard.
5509 if Comes_From_Source (N) then
5510 declare
5511 F1 : constant Entity_Id := First_Formal (Op_Id);
5512 F2 : constant Entity_Id := Next_Formal (F1);
5514 begin
5515 -- Verify that Op_Id is a visible binary function. Note that since
5516 -- we know Op_Id is overloaded, potentially use visible means use
5517 -- visible for sure (RM 9.4(11)).
5519 if Ekind (Op_Id) = E_Function
5520 and then Present (F2)
5521 and then (Is_Immediately_Visible (Op_Id)
5522 or else Is_Potentially_Use_Visible (Op_Id))
5523 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
5524 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
5525 then
5526 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5528 -- If the left operand is overloaded, indicate that the current
5529 -- type is a viable candidate. This is redundant in most cases,
5530 -- but for equality and comparison operators where the context
5531 -- does not impose a type on the operands, setting the proper
5532 -- type is necessary to avoid subsequent ambiguities during
5533 -- resolution, when both user-defined and predefined operators
5534 -- may be candidates.
5536 if Is_Overloaded (Left_Opnd (N)) then
5537 Set_Etype (Left_Opnd (N), Etype (F1));
5538 end if;
5540 if Debug_Flag_E then
5541 Write_Str ("user defined operator ");
5542 Write_Name (Chars (Op_Id));
5543 Write_Str (" on node ");
5544 Write_Int (Int (N));
5545 Write_Eol;
5546 end if;
5547 end if;
5548 end;
5549 end if;
5550 end Analyze_User_Defined_Binary_Op;
5552 -----------------------------------
5553 -- Analyze_User_Defined_Unary_Op --
5554 -----------------------------------
5556 procedure Analyze_User_Defined_Unary_Op
5557 (N : Node_Id;
5558 Op_Id : Entity_Id)
5560 begin
5561 -- Only do analysis if the operator Comes_From_Source, since otherwise
5562 -- the operator was generated by the expander, and all such operators
5563 -- always refer to the operators in package Standard.
5565 if Comes_From_Source (N) then
5566 declare
5567 F : constant Entity_Id := First_Formal (Op_Id);
5569 begin
5570 -- Verify that Op_Id is a visible unary function. Note that since
5571 -- we know Op_Id is overloaded, potentially use visible means use
5572 -- visible for sure (RM 9.4(11)).
5574 if Ekind (Op_Id) = E_Function
5575 and then No (Next_Formal (F))
5576 and then (Is_Immediately_Visible (Op_Id)
5577 or else Is_Potentially_Use_Visible (Op_Id))
5578 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
5579 then
5580 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5581 end if;
5582 end;
5583 end if;
5584 end Analyze_User_Defined_Unary_Op;
5586 ---------------------------
5587 -- Check_Arithmetic_Pair --
5588 ---------------------------
5590 procedure Check_Arithmetic_Pair
5591 (T1, T2 : Entity_Id;
5592 Op_Id : Entity_Id;
5593 N : Node_Id)
5595 Op_Name : constant Name_Id := Chars (Op_Id);
5597 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
5598 -- Check whether the fixed-point type Typ has a user-defined operator
5599 -- (multiplication or division) that should hide the corresponding
5600 -- predefined operator. Used to implement Ada 2005 AI-264, to make
5601 -- such operators more visible and therefore useful.
5603 -- If the name of the operation is an expanded name with prefix
5604 -- Standard, the predefined universal fixed operator is available,
5605 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
5607 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
5608 -- Get specific type (i.e. non-universal type if there is one)
5610 ------------------
5611 -- Has_Fixed_Op --
5612 ------------------
5614 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
5615 Bas : constant Entity_Id := Base_Type (Typ);
5616 Ent : Entity_Id;
5617 F1 : Entity_Id;
5618 F2 : Entity_Id;
5620 begin
5621 -- If the universal_fixed operation is given explicitly the rule
5622 -- concerning primitive operations of the type do not apply.
5624 if Nkind (N) = N_Function_Call
5625 and then Nkind (Name (N)) = N_Expanded_Name
5626 and then Entity (Prefix (Name (N))) = Standard_Standard
5627 then
5628 return False;
5629 end if;
5631 -- The operation is treated as primitive if it is declared in the
5632 -- same scope as the type, and therefore on the same entity chain.
5634 Ent := Next_Entity (Typ);
5635 while Present (Ent) loop
5636 if Chars (Ent) = Chars (Op) then
5637 F1 := First_Formal (Ent);
5638 F2 := Next_Formal (F1);
5640 -- The operation counts as primitive if either operand or
5641 -- result are of the given base type, and both operands are
5642 -- fixed point types.
5644 if (Base_Type (Etype (F1)) = Bas
5645 and then Is_Fixed_Point_Type (Etype (F2)))
5647 or else
5648 (Base_Type (Etype (F2)) = Bas
5649 and then Is_Fixed_Point_Type (Etype (F1)))
5651 or else
5652 (Base_Type (Etype (Ent)) = Bas
5653 and then Is_Fixed_Point_Type (Etype (F1))
5654 and then Is_Fixed_Point_Type (Etype (F2)))
5655 then
5656 return True;
5657 end if;
5658 end if;
5660 Next_Entity (Ent);
5661 end loop;
5663 return False;
5664 end Has_Fixed_Op;
5666 -------------------
5667 -- Specific_Type --
5668 -------------------
5670 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
5671 begin
5672 if T1 = Universal_Integer or else T1 = Universal_Real then
5673 return Base_Type (T2);
5674 else
5675 return Base_Type (T1);
5676 end if;
5677 end Specific_Type;
5679 -- Start of processing for Check_Arithmetic_Pair
5681 begin
5682 if Nam_In (Op_Name, Name_Op_Add, Name_Op_Subtract) then
5683 if Is_Numeric_Type (T1)
5684 and then Is_Numeric_Type (T2)
5685 and then (Covers (T1 => T1, T2 => T2)
5686 or else
5687 Covers (T1 => T2, T2 => T1))
5688 then
5689 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5690 end if;
5692 elsif Nam_In (Op_Name, Name_Op_Multiply, Name_Op_Divide) then
5693 if Is_Fixed_Point_Type (T1)
5694 and then (Is_Fixed_Point_Type (T2) or else T2 = Universal_Real)
5695 then
5696 -- If Treat_Fixed_As_Integer is set then the Etype is already set
5697 -- and no further processing is required (this is the case of an
5698 -- operator constructed by Exp_Fixd for a fixed point operation)
5699 -- Otherwise add one interpretation with universal fixed result
5700 -- If the operator is given in functional notation, it comes
5701 -- from source and Fixed_As_Integer cannot apply.
5703 if (Nkind (N) not in N_Op
5704 or else not Treat_Fixed_As_Integer (N))
5705 and then
5706 (not Has_Fixed_Op (T1, Op_Id)
5707 or else Nkind (Parent (N)) = N_Type_Conversion)
5708 then
5709 Add_One_Interp (N, Op_Id, Universal_Fixed);
5710 end if;
5712 elsif Is_Fixed_Point_Type (T2)
5713 and then (Nkind (N) not in N_Op
5714 or else not Treat_Fixed_As_Integer (N))
5715 and then T1 = Universal_Real
5716 and then
5717 (not Has_Fixed_Op (T1, Op_Id)
5718 or else Nkind (Parent (N)) = N_Type_Conversion)
5719 then
5720 Add_One_Interp (N, Op_Id, Universal_Fixed);
5722 elsif Is_Numeric_Type (T1)
5723 and then Is_Numeric_Type (T2)
5724 and then (Covers (T1 => T1, T2 => T2)
5725 or else
5726 Covers (T1 => T2, T2 => T1))
5727 then
5728 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5730 elsif Is_Fixed_Point_Type (T1)
5731 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5732 or else T2 = Universal_Integer)
5733 then
5734 Add_One_Interp (N, Op_Id, T1);
5736 elsif T2 = Universal_Real
5737 and then Base_Type (T1) = Base_Type (Standard_Integer)
5738 and then Op_Name = Name_Op_Multiply
5739 then
5740 Add_One_Interp (N, Op_Id, Any_Fixed);
5742 elsif T1 = Universal_Real
5743 and then Base_Type (T2) = Base_Type (Standard_Integer)
5744 then
5745 Add_One_Interp (N, Op_Id, Any_Fixed);
5747 elsif Is_Fixed_Point_Type (T2)
5748 and then (Base_Type (T1) = Base_Type (Standard_Integer)
5749 or else T1 = Universal_Integer)
5750 and then Op_Name = Name_Op_Multiply
5751 then
5752 Add_One_Interp (N, Op_Id, T2);
5754 elsif T1 = Universal_Real and then T2 = Universal_Integer then
5755 Add_One_Interp (N, Op_Id, T1);
5757 elsif T2 = Universal_Real
5758 and then T1 = Universal_Integer
5759 and then Op_Name = Name_Op_Multiply
5760 then
5761 Add_One_Interp (N, Op_Id, T2);
5762 end if;
5764 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
5766 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
5767 -- set does not require any special processing, since the Etype is
5768 -- already set (case of operation constructed by Exp_Fixed).
5770 if Is_Integer_Type (T1)
5771 and then (Covers (T1 => T1, T2 => T2)
5772 or else
5773 Covers (T1 => T2, T2 => T1))
5774 then
5775 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5776 end if;
5778 elsif Op_Name = Name_Op_Expon then
5779 if Is_Numeric_Type (T1)
5780 and then not Is_Fixed_Point_Type (T1)
5781 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5782 or else T2 = Universal_Integer)
5783 then
5784 Add_One_Interp (N, Op_Id, Base_Type (T1));
5785 end if;
5787 else pragma Assert (Nkind (N) in N_Op_Shift);
5789 -- If not one of the predefined operators, the node may be one
5790 -- of the intrinsic functions. Its kind is always specific, and
5791 -- we can use it directly, rather than the name of the operation.
5793 if Is_Integer_Type (T1)
5794 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5795 or else T2 = Universal_Integer)
5796 then
5797 Add_One_Interp (N, Op_Id, Base_Type (T1));
5798 end if;
5799 end if;
5800 end Check_Arithmetic_Pair;
5802 -------------------------------
5803 -- Check_Misspelled_Selector --
5804 -------------------------------
5806 procedure Check_Misspelled_Selector
5807 (Prefix : Entity_Id;
5808 Sel : Node_Id)
5810 Max_Suggestions : constant := 2;
5811 Nr_Of_Suggestions : Natural := 0;
5813 Suggestion_1 : Entity_Id := Empty;
5814 Suggestion_2 : Entity_Id := Empty;
5816 Comp : Entity_Id;
5818 begin
5819 -- All the components of the prefix of selector Sel are matched against
5820 -- Sel and a count is maintained of possible misspellings. When at
5821 -- the end of the analysis there are one or two (not more) possible
5822 -- misspellings, these misspellings will be suggested as possible
5823 -- correction.
5825 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
5827 -- Concurrent types should be handled as well ???
5829 return;
5830 end if;
5832 Comp := First_Entity (Prefix);
5833 while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
5834 if Is_Visible_Component (Comp) then
5835 if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
5836 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
5838 case Nr_Of_Suggestions is
5839 when 1 => Suggestion_1 := Comp;
5840 when 2 => Suggestion_2 := Comp;
5841 when others => null;
5842 end case;
5843 end if;
5844 end if;
5846 Comp := Next_Entity (Comp);
5847 end loop;
5849 -- Report at most two suggestions
5851 if Nr_Of_Suggestions = 1 then
5852 Error_Msg_NE -- CODEFIX
5853 ("\possible misspelling of&", Sel, Suggestion_1);
5855 elsif Nr_Of_Suggestions = 2 then
5856 Error_Msg_Node_2 := Suggestion_2;
5857 Error_Msg_NE -- CODEFIX
5858 ("\possible misspelling of& or&", Sel, Suggestion_1);
5859 end if;
5860 end Check_Misspelled_Selector;
5862 ----------------------
5863 -- Defined_In_Scope --
5864 ----------------------
5866 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
5868 S1 : constant Entity_Id := Scope (Base_Type (T));
5869 begin
5870 return S1 = S
5871 or else (S1 = System_Aux_Id and then S = Scope (S1));
5872 end Defined_In_Scope;
5874 -------------------
5875 -- Diagnose_Call --
5876 -------------------
5878 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
5879 Actual : Node_Id;
5880 X : Interp_Index;
5881 It : Interp;
5882 Err_Mode : Boolean;
5883 New_Nam : Node_Id;
5884 Void_Interp_Seen : Boolean := False;
5886 Success : Boolean;
5887 pragma Warnings (Off, Boolean);
5889 begin
5890 if Ada_Version >= Ada_2005 then
5891 Actual := First_Actual (N);
5892 while Present (Actual) loop
5894 -- Ada 2005 (AI-50217): Post an error in case of premature
5895 -- usage of an entity from the limited view.
5897 if not Analyzed (Etype (Actual))
5898 and then From_Limited_With (Etype (Actual))
5899 then
5900 Error_Msg_Qual_Level := 1;
5901 Error_Msg_NE
5902 ("missing with_clause for scope of imported type&",
5903 Actual, Etype (Actual));
5904 Error_Msg_Qual_Level := 0;
5905 end if;
5907 Next_Actual (Actual);
5908 end loop;
5909 end if;
5911 -- Before listing the possible candidates, check whether this is
5912 -- a prefix of a selected component that has been rewritten as a
5913 -- parameterless function call because there is a callable candidate
5914 -- interpretation. If there is a hidden package in the list of homonyms
5915 -- of the function name (bad programming style in any case) suggest that
5916 -- this is the intended entity.
5918 if No (Parameter_Associations (N))
5919 and then Nkind (Parent (N)) = N_Selected_Component
5920 and then Nkind (Parent (Parent (N))) in N_Declaration
5921 and then Is_Overloaded (Nam)
5922 then
5923 declare
5924 Ent : Entity_Id;
5926 begin
5927 Ent := Current_Entity (Nam);
5928 while Present (Ent) loop
5929 if Ekind (Ent) = E_Package then
5930 Error_Msg_N
5931 ("no legal interpretations as function call,!", Nam);
5932 Error_Msg_NE ("\package& is not visible", N, Ent);
5934 Rewrite (Parent (N),
5935 New_Occurrence_Of (Any_Type, Sloc (N)));
5936 return;
5937 end if;
5939 Ent := Homonym (Ent);
5940 end loop;
5941 end;
5942 end if;
5944 -- Analyze each candidate call again, with full error reporting for
5945 -- each.
5947 Error_Msg_N
5948 ("no candidate interpretations match the actuals:!", Nam);
5949 Err_Mode := All_Errors_Mode;
5950 All_Errors_Mode := True;
5952 -- If this is a call to an operation of a concurrent type,
5953 -- the failed interpretations have been removed from the
5954 -- name. Recover them to provide full diagnostics.
5956 if Nkind (Parent (Nam)) = N_Selected_Component then
5957 Set_Entity (Nam, Empty);
5958 New_Nam := New_Copy_Tree (Parent (Nam));
5959 Set_Is_Overloaded (New_Nam, False);
5960 Set_Is_Overloaded (Selector_Name (New_Nam), False);
5961 Set_Parent (New_Nam, Parent (Parent (Nam)));
5962 Analyze_Selected_Component (New_Nam);
5963 Get_First_Interp (Selector_Name (New_Nam), X, It);
5964 else
5965 Get_First_Interp (Nam, X, It);
5966 end if;
5968 while Present (It.Nam) loop
5969 if Etype (It.Nam) = Standard_Void_Type then
5970 Void_Interp_Seen := True;
5971 end if;
5973 Analyze_One_Call (N, It.Nam, True, Success);
5974 Get_Next_Interp (X, It);
5975 end loop;
5977 if Nkind (N) = N_Function_Call then
5978 Get_First_Interp (Nam, X, It);
5979 while Present (It.Nam) loop
5980 if Ekind_In (It.Nam, E_Function, E_Operator) then
5981 return;
5982 else
5983 Get_Next_Interp (X, It);
5984 end if;
5985 end loop;
5987 -- If all interpretations are procedures, this deserves a
5988 -- more precise message. Ditto if this appears as the prefix
5989 -- of a selected component, which may be a lexical error.
5991 Error_Msg_N
5992 ("\context requires function call, found procedure name", Nam);
5994 if Nkind (Parent (N)) = N_Selected_Component
5995 and then N = Prefix (Parent (N))
5996 then
5997 Error_Msg_N -- CODEFIX
5998 ("\period should probably be semicolon", Parent (N));
5999 end if;
6001 elsif Nkind (N) = N_Procedure_Call_Statement
6002 and then not Void_Interp_Seen
6003 then
6004 Error_Msg_N (
6005 "\function name found in procedure call", Nam);
6006 end if;
6008 All_Errors_Mode := Err_Mode;
6009 end Diagnose_Call;
6011 ---------------------------
6012 -- Find_Arithmetic_Types --
6013 ---------------------------
6015 procedure Find_Arithmetic_Types
6016 (L, R : Node_Id;
6017 Op_Id : Entity_Id;
6018 N : Node_Id)
6020 Index1 : Interp_Index;
6021 Index2 : Interp_Index;
6022 It1 : Interp;
6023 It2 : Interp;
6025 procedure Check_Right_Argument (T : Entity_Id);
6026 -- Check right operand of operator
6028 --------------------------
6029 -- Check_Right_Argument --
6030 --------------------------
6032 procedure Check_Right_Argument (T : Entity_Id) is
6033 begin
6034 if not Is_Overloaded (R) then
6035 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
6036 else
6037 Get_First_Interp (R, Index2, It2);
6038 while Present (It2.Typ) loop
6039 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
6040 Get_Next_Interp (Index2, It2);
6041 end loop;
6042 end if;
6043 end Check_Right_Argument;
6045 -- Start of processing for Find_Arithmetic_Types
6047 begin
6048 if not Is_Overloaded (L) then
6049 Check_Right_Argument (Etype (L));
6051 else
6052 Get_First_Interp (L, Index1, It1);
6053 while Present (It1.Typ) loop
6054 Check_Right_Argument (It1.Typ);
6055 Get_Next_Interp (Index1, It1);
6056 end loop;
6057 end if;
6059 end Find_Arithmetic_Types;
6061 ------------------------
6062 -- Find_Boolean_Types --
6063 ------------------------
6065 procedure Find_Boolean_Types
6066 (L, R : Node_Id;
6067 Op_Id : Entity_Id;
6068 N : Node_Id)
6070 Index : Interp_Index;
6071 It : Interp;
6073 procedure Check_Numeric_Argument (T : Entity_Id);
6074 -- Special case for logical operations one of whose operands is an
6075 -- integer literal. If both are literal the result is any modular type.
6077 ----------------------------
6078 -- Check_Numeric_Argument --
6079 ----------------------------
6081 procedure Check_Numeric_Argument (T : Entity_Id) is
6082 begin
6083 if T = Universal_Integer then
6084 Add_One_Interp (N, Op_Id, Any_Modular);
6086 elsif Is_Modular_Integer_Type (T) then
6087 Add_One_Interp (N, Op_Id, T);
6088 end if;
6089 end Check_Numeric_Argument;
6091 -- Start of processing for Find_Boolean_Types
6093 begin
6094 if not Is_Overloaded (L) then
6095 if Etype (L) = Universal_Integer
6096 or else Etype (L) = Any_Modular
6097 then
6098 if not Is_Overloaded (R) then
6099 Check_Numeric_Argument (Etype (R));
6101 else
6102 Get_First_Interp (R, Index, It);
6103 while Present (It.Typ) loop
6104 Check_Numeric_Argument (It.Typ);
6105 Get_Next_Interp (Index, It);
6106 end loop;
6107 end if;
6109 -- If operands are aggregates, we must assume that they may be
6110 -- boolean arrays, and leave disambiguation for the second pass.
6111 -- If only one is an aggregate, verify that the other one has an
6112 -- interpretation as a boolean array
6114 elsif Nkind (L) = N_Aggregate then
6115 if Nkind (R) = N_Aggregate then
6116 Add_One_Interp (N, Op_Id, Etype (L));
6118 elsif not Is_Overloaded (R) then
6119 if Valid_Boolean_Arg (Etype (R)) then
6120 Add_One_Interp (N, Op_Id, Etype (R));
6121 end if;
6123 else
6124 Get_First_Interp (R, Index, It);
6125 while Present (It.Typ) loop
6126 if Valid_Boolean_Arg (It.Typ) then
6127 Add_One_Interp (N, Op_Id, It.Typ);
6128 end if;
6130 Get_Next_Interp (Index, It);
6131 end loop;
6132 end if;
6134 elsif Valid_Boolean_Arg (Etype (L))
6135 and then Has_Compatible_Type (R, Etype (L))
6136 then
6137 Add_One_Interp (N, Op_Id, Etype (L));
6138 end if;
6140 else
6141 Get_First_Interp (L, Index, It);
6142 while Present (It.Typ) loop
6143 if Valid_Boolean_Arg (It.Typ)
6144 and then Has_Compatible_Type (R, It.Typ)
6145 then
6146 Add_One_Interp (N, Op_Id, It.Typ);
6147 end if;
6149 Get_Next_Interp (Index, It);
6150 end loop;
6151 end if;
6152 end Find_Boolean_Types;
6154 ---------------------------
6155 -- Find_Comparison_Types --
6156 ---------------------------
6158 procedure Find_Comparison_Types
6159 (L, R : Node_Id;
6160 Op_Id : Entity_Id;
6161 N : Node_Id)
6163 Index : Interp_Index;
6164 It : Interp;
6165 Found : Boolean := False;
6166 I_F : Interp_Index;
6167 T_F : Entity_Id;
6168 Scop : Entity_Id := Empty;
6170 procedure Try_One_Interp (T1 : Entity_Id);
6171 -- Routine to try one proposed interpretation. Note that the context
6172 -- of the operator plays no role in resolving the arguments, so that
6173 -- if there is more than one interpretation of the operands that is
6174 -- compatible with comparison, the operation is ambiguous.
6176 --------------------
6177 -- Try_One_Interp --
6178 --------------------
6180 procedure Try_One_Interp (T1 : Entity_Id) is
6181 begin
6183 -- If the operator is an expanded name, then the type of the operand
6184 -- must be defined in the corresponding scope. If the type is
6185 -- universal, the context will impose the correct type.
6187 if Present (Scop)
6188 and then not Defined_In_Scope (T1, Scop)
6189 and then T1 /= Universal_Integer
6190 and then T1 /= Universal_Real
6191 and then T1 /= Any_String
6192 and then T1 /= Any_Composite
6193 then
6194 return;
6195 end if;
6197 if Valid_Comparison_Arg (T1) and then Has_Compatible_Type (R, T1) then
6198 if Found and then Base_Type (T1) /= Base_Type (T_F) then
6199 It := Disambiguate (L, I_F, Index, Any_Type);
6201 if It = No_Interp then
6202 Ambiguous_Operands (N);
6203 Set_Etype (L, Any_Type);
6204 return;
6206 else
6207 T_F := It.Typ;
6208 end if;
6210 else
6211 Found := True;
6212 T_F := T1;
6213 I_F := Index;
6214 end if;
6216 Set_Etype (L, T_F);
6217 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
6219 end if;
6220 end Try_One_Interp;
6222 -- Start of processing for Find_Comparison_Types
6224 begin
6225 -- If left operand is aggregate, the right operand has to
6226 -- provide a usable type for it.
6228 if Nkind (L) = N_Aggregate and then Nkind (R) /= N_Aggregate then
6229 Find_Comparison_Types (L => R, R => L, Op_Id => Op_Id, N => N);
6230 return;
6231 end if;
6233 if Nkind (N) = N_Function_Call
6234 and then Nkind (Name (N)) = N_Expanded_Name
6235 then
6236 Scop := Entity (Prefix (Name (N)));
6238 -- The prefix may be a package renaming, and the subsequent test
6239 -- requires the original package.
6241 if Ekind (Scop) = E_Package
6242 and then Present (Renamed_Entity (Scop))
6243 then
6244 Scop := Renamed_Entity (Scop);
6245 Set_Entity (Prefix (Name (N)), Scop);
6246 end if;
6247 end if;
6249 if not Is_Overloaded (L) then
6250 Try_One_Interp (Etype (L));
6252 else
6253 Get_First_Interp (L, Index, It);
6254 while Present (It.Typ) loop
6255 Try_One_Interp (It.Typ);
6256 Get_Next_Interp (Index, It);
6257 end loop;
6258 end if;
6259 end Find_Comparison_Types;
6261 ----------------------------------------
6262 -- Find_Non_Universal_Interpretations --
6263 ----------------------------------------
6265 procedure Find_Non_Universal_Interpretations
6266 (N : Node_Id;
6267 R : Node_Id;
6268 Op_Id : Entity_Id;
6269 T1 : Entity_Id)
6271 Index : Interp_Index;
6272 It : Interp;
6274 begin
6275 if T1 = Universal_Integer or else T1 = Universal_Real
6277 -- If the left operand of an equality operator is null, the visibility
6278 -- of the operator must be determined from the interpretation of the
6279 -- right operand. This processing must be done for Any_Access, which
6280 -- is the internal representation of the type of the literal null.
6282 or else T1 = Any_Access
6283 then
6284 if not Is_Overloaded (R) then
6285 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
6286 else
6287 Get_First_Interp (R, Index, It);
6288 while Present (It.Typ) loop
6289 if Covers (It.Typ, T1) then
6290 Add_One_Interp
6291 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
6292 end if;
6294 Get_Next_Interp (Index, It);
6295 end loop;
6296 end if;
6297 else
6298 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
6299 end if;
6300 end Find_Non_Universal_Interpretations;
6302 ------------------------------
6303 -- Find_Concatenation_Types --
6304 ------------------------------
6306 procedure Find_Concatenation_Types
6307 (L, R : Node_Id;
6308 Op_Id : Entity_Id;
6309 N : Node_Id)
6311 Op_Type : constant Entity_Id := Etype (Op_Id);
6313 begin
6314 if Is_Array_Type (Op_Type)
6315 and then not Is_Limited_Type (Op_Type)
6317 and then (Has_Compatible_Type (L, Op_Type)
6318 or else
6319 Has_Compatible_Type (L, Component_Type (Op_Type)))
6321 and then (Has_Compatible_Type (R, Op_Type)
6322 or else
6323 Has_Compatible_Type (R, Component_Type (Op_Type)))
6324 then
6325 Add_One_Interp (N, Op_Id, Op_Type);
6326 end if;
6327 end Find_Concatenation_Types;
6329 -------------------------
6330 -- Find_Equality_Types --
6331 -------------------------
6333 procedure Find_Equality_Types
6334 (L, R : Node_Id;
6335 Op_Id : Entity_Id;
6336 N : Node_Id)
6338 Index : Interp_Index;
6339 It : Interp;
6340 Found : Boolean := False;
6341 I_F : Interp_Index;
6342 T_F : Entity_Id;
6343 Scop : Entity_Id := Empty;
6345 procedure Try_One_Interp (T1 : Entity_Id);
6346 -- The context of the equality operator plays no role in resolving the
6347 -- arguments, so that if there is more than one interpretation of the
6348 -- operands that is compatible with equality, the construct is ambiguous
6349 -- and an error can be emitted now, after trying to disambiguate, i.e.
6350 -- applying preference rules.
6352 --------------------
6353 -- Try_One_Interp --
6354 --------------------
6356 procedure Try_One_Interp (T1 : Entity_Id) is
6357 Bas : constant Entity_Id := Base_Type (T1);
6359 begin
6360 -- If the operator is an expanded name, then the type of the operand
6361 -- must be defined in the corresponding scope. If the type is
6362 -- universal, the context will impose the correct type. An anonymous
6363 -- type for a 'Access reference is also universal in this sense, as
6364 -- the actual type is obtained from context.
6366 -- In Ada 2005, the equality operator for anonymous access types
6367 -- is declared in Standard, and preference rules apply to it.
6369 if Present (Scop) then
6370 if Defined_In_Scope (T1, Scop)
6371 or else T1 = Universal_Integer
6372 or else T1 = Universal_Real
6373 or else T1 = Any_Access
6374 or else T1 = Any_String
6375 or else T1 = Any_Composite
6376 or else (Ekind (T1) = E_Access_Subprogram_Type
6377 and then not Comes_From_Source (T1))
6378 then
6379 null;
6381 elsif Ekind (T1) = E_Anonymous_Access_Type
6382 and then Scop = Standard_Standard
6383 then
6384 null;
6386 else
6387 -- The scope does not contain an operator for the type
6389 return;
6390 end if;
6392 -- If we have infix notation, the operator must be usable. Within
6393 -- an instance, if the type is already established we know it is
6394 -- correct. If an operand is universal it is compatible with any
6395 -- numeric type.
6397 elsif In_Open_Scopes (Scope (Bas))
6398 or else Is_Potentially_Use_Visible (Bas)
6399 or else In_Use (Bas)
6400 or else (In_Use (Scope (Bas)) and then not Is_Hidden (Bas))
6402 -- In an instance, the type may have been immediately visible.
6403 -- Either the types are compatible, or one operand is universal
6404 -- (numeric or null).
6406 or else (In_Instance
6407 and then
6408 (First_Subtype (T1) = First_Subtype (Etype (R))
6409 or else Nkind (R) = N_Null
6410 or else
6411 (Is_Numeric_Type (T1)
6412 and then Is_Universal_Numeric_Type (Etype (R)))))
6414 -- In Ada 2005, the equality on anonymous access types is declared
6415 -- in Standard, and is always visible.
6417 or else Ekind (T1) = E_Anonymous_Access_Type
6418 then
6419 null;
6421 else
6422 -- Save candidate type for subsequent error message, if any
6424 if not Is_Limited_Type (T1) then
6425 Candidate_Type := T1;
6426 end if;
6428 return;
6429 end if;
6431 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
6432 -- Do not allow anonymous access types in equality operators.
6434 if Ada_Version < Ada_2005
6435 and then Ekind (T1) = E_Anonymous_Access_Type
6436 then
6437 return;
6438 end if;
6440 -- If the right operand has a type compatible with T1, check for an
6441 -- acceptable interpretation, unless T1 is limited (no predefined
6442 -- equality available), or this is use of a "/=" for a tagged type.
6443 -- In the latter case, possible interpretations of equality need
6444 -- to be considered, we don't want the default inequality declared
6445 -- in Standard to be chosen, and the "/=" will be rewritten as a
6446 -- negation of "=" (see the end of Analyze_Equality_Op). This ensures
6447 -- that rewriting happens during analysis rather than being
6448 -- delayed until expansion (this is needed for ASIS, which only sees
6449 -- the unexpanded tree). Note that if the node is N_Op_Ne, but Op_Id
6450 -- is Name_Op_Eq then we still proceed with the interpretation,
6451 -- because that indicates the potential rewriting case where the
6452 -- interpretation to consider is actually "=" and the node may be
6453 -- about to be rewritten by Analyze_Equality_Op.
6455 if T1 /= Standard_Void_Type
6456 and then Has_Compatible_Type (R, T1)
6458 and then
6459 ((not Is_Limited_Type (T1)
6460 and then not Is_Limited_Composite (T1))
6462 or else
6463 (Is_Array_Type (T1)
6464 and then not Is_Limited_Type (Component_Type (T1))
6465 and then Available_Full_View_Of_Component (T1)))
6467 and then
6468 (Nkind (N) /= N_Op_Ne
6469 or else not Is_Tagged_Type (T1)
6470 or else Chars (Op_Id) = Name_Op_Eq)
6471 then
6472 if Found
6473 and then Base_Type (T1) /= Base_Type (T_F)
6474 then
6475 It := Disambiguate (L, I_F, Index, Any_Type);
6477 if It = No_Interp then
6478 Ambiguous_Operands (N);
6479 Set_Etype (L, Any_Type);
6480 return;
6482 else
6483 T_F := It.Typ;
6484 end if;
6486 else
6487 Found := True;
6488 T_F := T1;
6489 I_F := Index;
6490 end if;
6492 if not Analyzed (L) then
6493 Set_Etype (L, T_F);
6494 end if;
6496 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
6498 -- Case of operator was not visible, Etype still set to Any_Type
6500 if Etype (N) = Any_Type then
6501 Found := False;
6502 end if;
6504 elsif Scop = Standard_Standard
6505 and then Ekind (T1) = E_Anonymous_Access_Type
6506 then
6507 Found := True;
6508 end if;
6509 end Try_One_Interp;
6511 -- Start of processing for Find_Equality_Types
6513 begin
6514 -- If left operand is aggregate, the right operand has to
6515 -- provide a usable type for it.
6517 if Nkind (L) = N_Aggregate
6518 and then Nkind (R) /= N_Aggregate
6519 then
6520 Find_Equality_Types (L => R, R => L, Op_Id => Op_Id, N => N);
6521 return;
6522 end if;
6524 if Nkind (N) = N_Function_Call
6525 and then Nkind (Name (N)) = N_Expanded_Name
6526 then
6527 Scop := Entity (Prefix (Name (N)));
6529 -- The prefix may be a package renaming, and the subsequent test
6530 -- requires the original package.
6532 if Ekind (Scop) = E_Package
6533 and then Present (Renamed_Entity (Scop))
6534 then
6535 Scop := Renamed_Entity (Scop);
6536 Set_Entity (Prefix (Name (N)), Scop);
6537 end if;
6538 end if;
6540 if not Is_Overloaded (L) then
6541 Try_One_Interp (Etype (L));
6543 else
6544 Get_First_Interp (L, Index, It);
6545 while Present (It.Typ) loop
6546 Try_One_Interp (It.Typ);
6547 Get_Next_Interp (Index, It);
6548 end loop;
6549 end if;
6550 end Find_Equality_Types;
6552 -------------------------
6553 -- Find_Negation_Types --
6554 -------------------------
6556 procedure Find_Negation_Types
6557 (R : Node_Id;
6558 Op_Id : Entity_Id;
6559 N : Node_Id)
6561 Index : Interp_Index;
6562 It : Interp;
6564 begin
6565 if not Is_Overloaded (R) then
6566 if Etype (R) = Universal_Integer then
6567 Add_One_Interp (N, Op_Id, Any_Modular);
6568 elsif Valid_Boolean_Arg (Etype (R)) then
6569 Add_One_Interp (N, Op_Id, Etype (R));
6570 end if;
6572 else
6573 Get_First_Interp (R, Index, It);
6574 while Present (It.Typ) loop
6575 if Valid_Boolean_Arg (It.Typ) then
6576 Add_One_Interp (N, Op_Id, It.Typ);
6577 end if;
6579 Get_Next_Interp (Index, It);
6580 end loop;
6581 end if;
6582 end Find_Negation_Types;
6584 ------------------------------
6585 -- Find_Primitive_Operation --
6586 ------------------------------
6588 function Find_Primitive_Operation (N : Node_Id) return Boolean is
6589 Obj : constant Node_Id := Prefix (N);
6590 Op : constant Node_Id := Selector_Name (N);
6592 Prim : Elmt_Id;
6593 Prims : Elist_Id;
6594 Typ : Entity_Id;
6596 begin
6597 Set_Etype (Op, Any_Type);
6599 if Is_Access_Type (Etype (Obj)) then
6600 Typ := Designated_Type (Etype (Obj));
6601 else
6602 Typ := Etype (Obj);
6603 end if;
6605 if Is_Class_Wide_Type (Typ) then
6606 Typ := Root_Type (Typ);
6607 end if;
6609 Prims := Primitive_Operations (Typ);
6611 Prim := First_Elmt (Prims);
6612 while Present (Prim) loop
6613 if Chars (Node (Prim)) = Chars (Op) then
6614 Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
6615 Set_Etype (N, Etype (Node (Prim)));
6616 end if;
6618 Next_Elmt (Prim);
6619 end loop;
6621 -- Now look for class-wide operations of the type or any of its
6622 -- ancestors by iterating over the homonyms of the selector.
6624 declare
6625 Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
6626 Hom : Entity_Id;
6628 begin
6629 Hom := Current_Entity (Op);
6630 while Present (Hom) loop
6631 if (Ekind (Hom) = E_Procedure
6632 or else
6633 Ekind (Hom) = E_Function)
6634 and then Scope (Hom) = Scope (Typ)
6635 and then Present (First_Formal (Hom))
6636 and then
6637 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
6638 or else
6639 (Is_Access_Type (Etype (First_Formal (Hom)))
6640 and then
6641 Ekind (Etype (First_Formal (Hom))) =
6642 E_Anonymous_Access_Type
6643 and then
6644 Base_Type
6645 (Designated_Type (Etype (First_Formal (Hom)))) =
6646 Cls_Type))
6647 then
6648 Add_One_Interp (Op, Hom, Etype (Hom));
6649 Set_Etype (N, Etype (Hom));
6650 end if;
6652 Hom := Homonym (Hom);
6653 end loop;
6654 end;
6656 return Etype (Op) /= Any_Type;
6657 end Find_Primitive_Operation;
6659 ----------------------
6660 -- Find_Unary_Types --
6661 ----------------------
6663 procedure Find_Unary_Types
6664 (R : Node_Id;
6665 Op_Id : Entity_Id;
6666 N : Node_Id)
6668 Index : Interp_Index;
6669 It : Interp;
6671 begin
6672 if not Is_Overloaded (R) then
6673 if Is_Numeric_Type (Etype (R)) then
6675 -- In an instance a generic actual may be a numeric type even if
6676 -- the formal in the generic unit was not. In that case, the
6677 -- predefined operator was not a possible interpretation in the
6678 -- generic, and cannot be one in the instance, unless the operator
6679 -- is an actual of an instance.
6681 if In_Instance
6682 and then
6683 not Is_Numeric_Type (Corresponding_Generic_Type (Etype (R)))
6684 then
6685 null;
6686 else
6687 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
6688 end if;
6689 end if;
6691 else
6692 Get_First_Interp (R, Index, It);
6693 while Present (It.Typ) loop
6694 if Is_Numeric_Type (It.Typ) then
6695 if In_Instance
6696 and then
6697 not Is_Numeric_Type
6698 (Corresponding_Generic_Type (Etype (It.Typ)))
6699 then
6700 null;
6702 else
6703 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
6704 end if;
6705 end if;
6707 Get_Next_Interp (Index, It);
6708 end loop;
6709 end if;
6710 end Find_Unary_Types;
6712 ------------------
6713 -- Junk_Operand --
6714 ------------------
6716 function Junk_Operand (N : Node_Id) return Boolean is
6717 Enode : Node_Id;
6719 begin
6720 if Error_Posted (N) then
6721 return False;
6722 end if;
6724 -- Get entity to be tested
6726 if Is_Entity_Name (N)
6727 and then Present (Entity (N))
6728 then
6729 Enode := N;
6731 -- An odd case, a procedure name gets converted to a very peculiar
6732 -- function call, and here is where we detect this happening.
6734 elsif Nkind (N) = N_Function_Call
6735 and then Is_Entity_Name (Name (N))
6736 and then Present (Entity (Name (N)))
6737 then
6738 Enode := Name (N);
6740 -- Another odd case, there are at least some cases of selected
6741 -- components where the selected component is not marked as having
6742 -- an entity, even though the selector does have an entity
6744 elsif Nkind (N) = N_Selected_Component
6745 and then Present (Entity (Selector_Name (N)))
6746 then
6747 Enode := Selector_Name (N);
6749 else
6750 return False;
6751 end if;
6753 -- Now test the entity we got to see if it is a bad case
6755 case Ekind (Entity (Enode)) is
6756 when E_Package =>
6757 Error_Msg_N
6758 ("package name cannot be used as operand", Enode);
6760 when Generic_Unit_Kind =>
6761 Error_Msg_N
6762 ("generic unit name cannot be used as operand", Enode);
6764 when Type_Kind =>
6765 Error_Msg_N
6766 ("subtype name cannot be used as operand", Enode);
6768 when Entry_Kind =>
6769 Error_Msg_N
6770 ("entry name cannot be used as operand", Enode);
6772 when E_Procedure =>
6773 Error_Msg_N
6774 ("procedure name cannot be used as operand", Enode);
6776 when E_Exception =>
6777 Error_Msg_N
6778 ("exception name cannot be used as operand", Enode);
6780 when E_Block
6781 | E_Label
6782 | E_Loop
6784 Error_Msg_N
6785 ("label name cannot be used as operand", Enode);
6787 when others =>
6788 return False;
6789 end case;
6791 return True;
6792 end Junk_Operand;
6794 --------------------
6795 -- Operator_Check --
6796 --------------------
6798 procedure Operator_Check (N : Node_Id) is
6799 begin
6800 Remove_Abstract_Operations (N);
6802 -- Test for case of no interpretation found for operator
6804 if Etype (N) = Any_Type then
6805 declare
6806 L : Node_Id;
6807 R : Node_Id;
6808 Op_Id : Entity_Id := Empty;
6810 begin
6811 R := Right_Opnd (N);
6813 if Nkind (N) in N_Binary_Op then
6814 L := Left_Opnd (N);
6815 else
6816 L := Empty;
6817 end if;
6819 -- If either operand has no type, then don't complain further,
6820 -- since this simply means that we have a propagated error.
6822 if R = Error
6823 or else Etype (R) = Any_Type
6824 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
6825 then
6826 -- For the rather unusual case where one of the operands is
6827 -- a Raise_Expression, whose initial type is Any_Type, use
6828 -- the type of the other operand.
6830 if Nkind (L) = N_Raise_Expression then
6831 Set_Etype (L, Etype (R));
6832 Set_Etype (N, Etype (R));
6834 elsif Nkind (R) = N_Raise_Expression then
6835 Set_Etype (R, Etype (L));
6836 Set_Etype (N, Etype (L));
6837 end if;
6839 return;
6841 -- We explicitly check for the case of concatenation of component
6842 -- with component to avoid reporting spurious matching array types
6843 -- that might happen to be lurking in distant packages (such as
6844 -- run-time packages). This also prevents inconsistencies in the
6845 -- messages for certain ACVC B tests, which can vary depending on
6846 -- types declared in run-time interfaces. Another improvement when
6847 -- aggregates are present is to look for a well-typed operand.
6849 elsif Present (Candidate_Type)
6850 and then (Nkind (N) /= N_Op_Concat
6851 or else Is_Array_Type (Etype (L))
6852 or else Is_Array_Type (Etype (R)))
6853 then
6854 if Nkind (N) = N_Op_Concat then
6855 if Etype (L) /= Any_Composite
6856 and then Is_Array_Type (Etype (L))
6857 then
6858 Candidate_Type := Etype (L);
6860 elsif Etype (R) /= Any_Composite
6861 and then Is_Array_Type (Etype (R))
6862 then
6863 Candidate_Type := Etype (R);
6864 end if;
6865 end if;
6867 Error_Msg_NE -- CODEFIX
6868 ("operator for} is not directly visible!",
6869 N, First_Subtype (Candidate_Type));
6871 declare
6872 U : constant Node_Id :=
6873 Cunit (Get_Source_Unit (Candidate_Type));
6874 begin
6875 if Unit_Is_Visible (U) then
6876 Error_Msg_N -- CODEFIX
6877 ("use clause would make operation legal!", N);
6878 else
6879 Error_Msg_NE -- CODEFIX
6880 ("add with_clause and use_clause for&!",
6881 N, Defining_Entity (Unit (U)));
6882 end if;
6883 end;
6884 return;
6886 -- If either operand is a junk operand (e.g. package name), then
6887 -- post appropriate error messages, but do not complain further.
6889 -- Note that the use of OR in this test instead of OR ELSE is
6890 -- quite deliberate, we may as well check both operands in the
6891 -- binary operator case.
6893 elsif Junk_Operand (R)
6894 or -- really mean OR here and not OR ELSE, see above
6895 (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
6896 then
6897 return;
6899 -- If we have a logical operator, one of whose operands is
6900 -- Boolean, then we know that the other operand cannot resolve to
6901 -- Boolean (since we got no interpretations), but in that case we
6902 -- pretty much know that the other operand should be Boolean, so
6903 -- resolve it that way (generating an error).
6905 elsif Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor) then
6906 if Etype (L) = Standard_Boolean then
6907 Resolve (R, Standard_Boolean);
6908 return;
6909 elsif Etype (R) = Standard_Boolean then
6910 Resolve (L, Standard_Boolean);
6911 return;
6912 end if;
6914 -- For an arithmetic operator or comparison operator, if one
6915 -- of the operands is numeric, then we know the other operand
6916 -- is not the same numeric type. If it is a non-numeric type,
6917 -- then probably it is intended to match the other operand.
6919 elsif Nkind_In (N, N_Op_Add,
6920 N_Op_Divide,
6921 N_Op_Ge,
6922 N_Op_Gt,
6923 N_Op_Le)
6924 or else
6925 Nkind_In (N, N_Op_Lt,
6926 N_Op_Mod,
6927 N_Op_Multiply,
6928 N_Op_Rem,
6929 N_Op_Subtract)
6930 then
6931 -- If Allow_Integer_Address is active, check whether the
6932 -- operation becomes legal after converting an operand.
6934 if Is_Numeric_Type (Etype (L))
6935 and then not Is_Numeric_Type (Etype (R))
6936 then
6937 if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
6938 Rewrite (R,
6939 Unchecked_Convert_To (Etype (L), Relocate_Node (R)));
6941 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
6942 Analyze_Comparison_Op (N);
6943 else
6944 Analyze_Arithmetic_Op (N);
6945 end if;
6946 else
6947 Resolve (R, Etype (L));
6948 end if;
6950 return;
6952 elsif Is_Numeric_Type (Etype (R))
6953 and then not Is_Numeric_Type (Etype (L))
6954 then
6955 if Address_Integer_Convert_OK (Etype (L), Etype (R)) then
6956 Rewrite (L,
6957 Unchecked_Convert_To (Etype (R), Relocate_Node (L)));
6959 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
6960 Analyze_Comparison_Op (N);
6961 else
6962 Analyze_Arithmetic_Op (N);
6963 end if;
6965 return;
6967 else
6968 Resolve (L, Etype (R));
6969 end if;
6971 return;
6973 elsif Allow_Integer_Address
6974 and then Is_Descendant_Of_Address (Etype (L))
6975 and then Is_Descendant_Of_Address (Etype (R))
6976 and then not Error_Posted (N)
6977 then
6978 declare
6979 Addr_Type : constant Entity_Id := Etype (L);
6981 begin
6982 Rewrite (L,
6983 Unchecked_Convert_To (
6984 Standard_Integer, Relocate_Node (L)));
6985 Rewrite (R,
6986 Unchecked_Convert_To (
6987 Standard_Integer, Relocate_Node (R)));
6989 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
6990 Analyze_Comparison_Op (N);
6991 else
6992 Analyze_Arithmetic_Op (N);
6993 end if;
6995 -- If this is an operand in an enclosing arithmetic
6996 -- operation, Convert the result as an address so that
6997 -- arithmetic folding of address can continue.
6999 if Nkind (Parent (N)) in N_Op then
7000 Rewrite (N,
7001 Unchecked_Convert_To (Addr_Type, Relocate_Node (N)));
7002 end if;
7004 return;
7005 end;
7007 -- Under relaxed RM semantics silently replace occurrences of
7008 -- null by System.Address_Null.
7010 elsif Null_To_Null_Address_Convert_OK (N) then
7011 Replace_Null_By_Null_Address (N);
7013 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
7014 Analyze_Comparison_Op (N);
7015 else
7016 Analyze_Arithmetic_Op (N);
7017 end if;
7019 return;
7020 end if;
7022 -- Comparisons on A'Access are common enough to deserve a
7023 -- special message.
7025 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne)
7026 and then Ekind (Etype (L)) = E_Access_Attribute_Type
7027 and then Ekind (Etype (R)) = E_Access_Attribute_Type
7028 then
7029 Error_Msg_N
7030 ("two access attributes cannot be compared directly", N);
7031 Error_Msg_N
7032 ("\use qualified expression for one of the operands",
7034 return;
7036 -- Another one for C programmers
7038 elsif Nkind (N) = N_Op_Concat
7039 and then Valid_Boolean_Arg (Etype (L))
7040 and then Valid_Boolean_Arg (Etype (R))
7041 then
7042 Error_Msg_N ("invalid operands for concatenation", N);
7043 Error_Msg_N -- CODEFIX
7044 ("\maybe AND was meant", N);
7045 return;
7047 -- A special case for comparison of access parameter with null
7049 elsif Nkind (N) = N_Op_Eq
7050 and then Is_Entity_Name (L)
7051 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
7052 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
7053 N_Access_Definition
7054 and then Nkind (R) = N_Null
7055 then
7056 Error_Msg_N ("access parameter is not allowed to be null", L);
7057 Error_Msg_N ("\(call would raise Constraint_Error)", L);
7058 return;
7060 -- Another special case for exponentiation, where the right
7061 -- operand must be Natural, independently of the base.
7063 elsif Nkind (N) = N_Op_Expon
7064 and then Is_Numeric_Type (Etype (L))
7065 and then not Is_Overloaded (R)
7066 and then
7067 First_Subtype (Base_Type (Etype (R))) /= Standard_Integer
7068 and then Base_Type (Etype (R)) /= Universal_Integer
7069 then
7070 if Ada_Version >= Ada_2012
7071 and then Has_Dimension_System (Etype (L))
7072 then
7073 Error_Msg_NE
7074 ("exponent for dimensioned type must be a rational" &
7075 ", found}", R, Etype (R));
7076 else
7077 Error_Msg_NE
7078 ("exponent must be of type Natural, found}", R, Etype (R));
7079 end if;
7081 return;
7083 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
7084 if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
7085 Rewrite (R,
7086 Unchecked_Convert_To (Etype (L), Relocate_Node (R)));
7087 Analyze_Equality_Op (N);
7088 return;
7090 -- Under relaxed RM semantics silently replace occurrences of
7091 -- null by System.Address_Null.
7093 elsif Null_To_Null_Address_Convert_OK (N) then
7094 Replace_Null_By_Null_Address (N);
7095 Analyze_Equality_Op (N);
7096 return;
7097 end if;
7098 end if;
7100 -- If we fall through then just give general message. Note that in
7101 -- the following messages, if the operand is overloaded we choose
7102 -- an arbitrary type to complain about, but that is probably more
7103 -- useful than not giving a type at all.
7105 if Nkind (N) in N_Unary_Op then
7106 Error_Msg_Node_2 := Etype (R);
7107 Error_Msg_N ("operator& not defined for}", N);
7108 return;
7110 else
7111 if Nkind (N) in N_Binary_Op then
7112 if not Is_Overloaded (L)
7113 and then not Is_Overloaded (R)
7114 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
7115 then
7116 Error_Msg_Node_2 := First_Subtype (Etype (R));
7117 Error_Msg_N ("there is no applicable operator& for}", N);
7119 else
7120 -- Another attempt to find a fix: one of the candidate
7121 -- interpretations may not be use-visible. This has
7122 -- already been checked for predefined operators, so
7123 -- we examine only user-defined functions.
7125 Op_Id := Get_Name_Entity_Id (Chars (N));
7127 while Present (Op_Id) loop
7128 if Ekind (Op_Id) /= E_Operator
7129 and then Is_Overloadable (Op_Id)
7130 then
7131 if not Is_Immediately_Visible (Op_Id)
7132 and then not In_Use (Scope (Op_Id))
7133 and then not Is_Abstract_Subprogram (Op_Id)
7134 and then not Is_Hidden (Op_Id)
7135 and then Ekind (Scope (Op_Id)) = E_Package
7136 and then
7137 Has_Compatible_Type
7138 (L, Etype (First_Formal (Op_Id)))
7139 and then Present
7140 (Next_Formal (First_Formal (Op_Id)))
7141 and then
7142 Has_Compatible_Type
7144 Etype (Next_Formal (First_Formal (Op_Id))))
7145 then
7146 Error_Msg_N
7147 ("No legal interpretation for operator&", N);
7148 Error_Msg_NE
7149 ("\use clause on& would make operation legal",
7150 N, Scope (Op_Id));
7151 exit;
7152 end if;
7153 end if;
7155 Op_Id := Homonym (Op_Id);
7156 end loop;
7158 if No (Op_Id) then
7159 Error_Msg_N ("invalid operand types for operator&", N);
7161 if Nkind (N) /= N_Op_Concat then
7162 Error_Msg_NE ("\left operand has}!", N, Etype (L));
7163 Error_Msg_NE ("\right operand has}!", N, Etype (R));
7165 -- For concatenation operators it is more difficult to
7166 -- determine which is the wrong operand. It is worth
7167 -- flagging explicitly an access type, for those who
7168 -- might think that a dereference happens here.
7170 elsif Is_Access_Type (Etype (L)) then
7171 Error_Msg_N ("\left operand is access type", N);
7173 elsif Is_Access_Type (Etype (R)) then
7174 Error_Msg_N ("\right operand is access type", N);
7175 end if;
7176 end if;
7177 end if;
7178 end if;
7179 end if;
7180 end;
7181 end if;
7182 end Operator_Check;
7184 -----------------------------------------
7185 -- Process_Implicit_Dereference_Prefix --
7186 -----------------------------------------
7188 function Process_Implicit_Dereference_Prefix
7189 (E : Entity_Id;
7190 P : Entity_Id) return Entity_Id
7192 Ref : Node_Id;
7193 Typ : constant Entity_Id := Designated_Type (Etype (P));
7195 begin
7196 if Present (E)
7197 and then (Operating_Mode = Check_Semantics or else not Expander_Active)
7198 then
7199 -- We create a dummy reference to E to ensure that the reference is
7200 -- not considered as part of an assignment (an implicit dereference
7201 -- can never assign to its prefix). The Comes_From_Source attribute
7202 -- needs to be propagated for accurate warnings.
7204 Ref := New_Occurrence_Of (E, Sloc (P));
7205 Set_Comes_From_Source (Ref, Comes_From_Source (P));
7206 Generate_Reference (E, Ref);
7207 end if;
7209 -- An implicit dereference is a legal occurrence of an incomplete type
7210 -- imported through a limited_with clause, if the full view is visible.
7212 if From_Limited_With (Typ)
7213 and then not From_Limited_With (Scope (Typ))
7214 and then
7215 (Is_Immediately_Visible (Scope (Typ))
7216 or else
7217 (Is_Child_Unit (Scope (Typ))
7218 and then Is_Visible_Lib_Unit (Scope (Typ))))
7219 then
7220 return Available_View (Typ);
7221 else
7222 return Typ;
7223 end if;
7224 end Process_Implicit_Dereference_Prefix;
7226 --------------------------------
7227 -- Remove_Abstract_Operations --
7228 --------------------------------
7230 procedure Remove_Abstract_Operations (N : Node_Id) is
7231 Abstract_Op : Entity_Id := Empty;
7232 Address_Descendant : Boolean := False;
7233 I : Interp_Index;
7234 It : Interp;
7236 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
7237 -- activate this if either extensions are enabled, or if the abstract
7238 -- operation in question comes from a predefined file. This latter test
7239 -- allows us to use abstract to make operations invisible to users. In
7240 -- particular, if type Address is non-private and abstract subprograms
7241 -- are used to hide its operators, they will be truly hidden.
7243 type Operand_Position is (First_Op, Second_Op);
7244 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
7246 procedure Remove_Address_Interpretations (Op : Operand_Position);
7247 -- Ambiguities may arise when the operands are literal and the address
7248 -- operations in s-auxdec are visible. In that case, remove the
7249 -- interpretation of a literal as Address, to retain the semantics
7250 -- of Address as a private type.
7252 ------------------------------------
7253 -- Remove_Address_Interpretations --
7254 ------------------------------------
7256 procedure Remove_Address_Interpretations (Op : Operand_Position) is
7257 Formal : Entity_Id;
7259 begin
7260 if Is_Overloaded (N) then
7261 Get_First_Interp (N, I, It);
7262 while Present (It.Nam) loop
7263 Formal := First_Entity (It.Nam);
7265 if Op = Second_Op then
7266 Formal := Next_Entity (Formal);
7267 end if;
7269 if Is_Descendant_Of_Address (Etype (Formal)) then
7270 Address_Descendant := True;
7271 Remove_Interp (I);
7272 end if;
7274 Get_Next_Interp (I, It);
7275 end loop;
7276 end if;
7277 end Remove_Address_Interpretations;
7279 -- Start of processing for Remove_Abstract_Operations
7281 begin
7282 if Is_Overloaded (N) then
7283 if Debug_Flag_V then
7284 Write_Str ("Remove_Abstract_Operations: ");
7285 Write_Overloads (N);
7286 end if;
7288 Get_First_Interp (N, I, It);
7290 while Present (It.Nam) loop
7291 if Is_Overloadable (It.Nam)
7292 and then Is_Abstract_Subprogram (It.Nam)
7293 and then not Is_Dispatching_Operation (It.Nam)
7294 then
7295 Abstract_Op := It.Nam;
7297 if Is_Descendant_Of_Address (It.Typ) then
7298 Address_Descendant := True;
7299 Remove_Interp (I);
7300 exit;
7302 -- In Ada 2005, this operation does not participate in overload
7303 -- resolution. If the operation is defined in a predefined
7304 -- unit, it is one of the operations declared abstract in some
7305 -- variants of System, and it must be removed as well.
7307 elsif Ada_Version >= Ada_2005
7308 or else Is_Predefined_File_Name
7309 (Unit_File_Name (Get_Source_Unit (It.Nam)))
7310 then
7311 Remove_Interp (I);
7312 exit;
7313 end if;
7314 end if;
7316 Get_Next_Interp (I, It);
7317 end loop;
7319 if No (Abstract_Op) then
7321 -- If some interpretation yields an integer type, it is still
7322 -- possible that there are address interpretations. Remove them
7323 -- if one operand is a literal, to avoid spurious ambiguities
7324 -- on systems where Address is a visible integer type.
7326 if Is_Overloaded (N)
7327 and then Nkind (N) in N_Op
7328 and then Is_Integer_Type (Etype (N))
7329 then
7330 if Nkind (N) in N_Binary_Op then
7331 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
7332 Remove_Address_Interpretations (Second_Op);
7334 elsif Nkind (Right_Opnd (N)) = N_Integer_Literal then
7335 Remove_Address_Interpretations (First_Op);
7336 end if;
7337 end if;
7338 end if;
7340 elsif Nkind (N) in N_Op then
7342 -- Remove interpretations that treat literals as addresses. This
7343 -- is never appropriate, even when Address is defined as a visible
7344 -- Integer type. The reason is that we would really prefer Address
7345 -- to behave as a private type, even in this case. If Address is a
7346 -- visible integer type, we get lots of overload ambiguities.
7348 if Nkind (N) in N_Binary_Op then
7349 declare
7350 U1 : constant Boolean :=
7351 Present (Universal_Interpretation (Right_Opnd (N)));
7352 U2 : constant Boolean :=
7353 Present (Universal_Interpretation (Left_Opnd (N)));
7355 begin
7356 if U1 then
7357 Remove_Address_Interpretations (Second_Op);
7358 end if;
7360 if U2 then
7361 Remove_Address_Interpretations (First_Op);
7362 end if;
7364 if not (U1 and U2) then
7366 -- Remove corresponding predefined operator, which is
7367 -- always added to the overload set.
7369 Get_First_Interp (N, I, It);
7370 while Present (It.Nam) loop
7371 if Scope (It.Nam) = Standard_Standard
7372 and then Base_Type (It.Typ) =
7373 Base_Type (Etype (Abstract_Op))
7374 then
7375 Remove_Interp (I);
7376 end if;
7378 Get_Next_Interp (I, It);
7379 end loop;
7381 elsif Is_Overloaded (N)
7382 and then Present (Univ_Type)
7383 then
7384 -- If both operands have a universal interpretation,
7385 -- it is still necessary to remove interpretations that
7386 -- yield Address. Any remaining ambiguities will be
7387 -- removed in Disambiguate.
7389 Get_First_Interp (N, I, It);
7390 while Present (It.Nam) loop
7391 if Is_Descendant_Of_Address (It.Typ) then
7392 Remove_Interp (I);
7394 elsif not Is_Type (It.Nam) then
7395 Set_Entity (N, It.Nam);
7396 end if;
7398 Get_Next_Interp (I, It);
7399 end loop;
7400 end if;
7401 end;
7402 end if;
7404 elsif Nkind (N) = N_Function_Call
7405 and then
7406 (Nkind (Name (N)) = N_Operator_Symbol
7407 or else
7408 (Nkind (Name (N)) = N_Expanded_Name
7409 and then
7410 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
7411 then
7413 declare
7414 Arg1 : constant Node_Id := First (Parameter_Associations (N));
7415 U1 : constant Boolean :=
7416 Present (Universal_Interpretation (Arg1));
7417 U2 : constant Boolean :=
7418 Present (Next (Arg1)) and then
7419 Present (Universal_Interpretation (Next (Arg1)));
7421 begin
7422 if U1 then
7423 Remove_Address_Interpretations (First_Op);
7424 end if;
7426 if U2 then
7427 Remove_Address_Interpretations (Second_Op);
7428 end if;
7430 if not (U1 and U2) then
7431 Get_First_Interp (N, I, It);
7432 while Present (It.Nam) loop
7433 if Scope (It.Nam) = Standard_Standard
7434 and then It.Typ = Base_Type (Etype (Abstract_Op))
7435 then
7436 Remove_Interp (I);
7437 end if;
7439 Get_Next_Interp (I, It);
7440 end loop;
7441 end if;
7442 end;
7443 end if;
7445 -- If the removal has left no valid interpretations, emit an error
7446 -- message now and label node as illegal.
7448 if Present (Abstract_Op) then
7449 Get_First_Interp (N, I, It);
7451 if No (It.Nam) then
7453 -- Removal of abstract operation left no viable candidate
7455 Set_Etype (N, Any_Type);
7456 Error_Msg_Sloc := Sloc (Abstract_Op);
7457 Error_Msg_NE
7458 ("cannot call abstract operation& declared#", N, Abstract_Op);
7460 -- In Ada 2005, an abstract operation may disable predefined
7461 -- operators. Since the context is not yet known, we mark the
7462 -- predefined operators as potentially hidden. Do not include
7463 -- predefined operators when addresses are involved since this
7464 -- case is handled separately.
7466 elsif Ada_Version >= Ada_2005 and then not Address_Descendant then
7467 while Present (It.Nam) loop
7468 if Is_Numeric_Type (It.Typ)
7469 and then Scope (It.Typ) = Standard_Standard
7470 then
7471 Set_Abstract_Op (I, Abstract_Op);
7472 end if;
7474 Get_Next_Interp (I, It);
7475 end loop;
7476 end if;
7477 end if;
7479 if Debug_Flag_V then
7480 Write_Str ("Remove_Abstract_Operations done: ");
7481 Write_Overloads (N);
7482 end if;
7483 end if;
7484 end Remove_Abstract_Operations;
7486 ----------------------------
7487 -- Try_Container_Indexing --
7488 ----------------------------
7490 function Try_Container_Indexing
7491 (N : Node_Id;
7492 Prefix : Node_Id;
7493 Exprs : List_Id) return Boolean
7495 Pref_Typ : constant Entity_Id := Etype (Prefix);
7497 function Constant_Indexing_OK return Boolean;
7498 -- Constant_Indexing is legal if there is no Variable_Indexing defined
7499 -- for the type, or else node not a target of assignment, or an actual
7500 -- for an IN OUT or OUT formal (RM 4.1.6 (11)).
7502 function Find_Indexing_Operations
7503 (T : Entity_Id;
7504 Nam : Name_Id;
7505 Is_Constant : Boolean) return Node_Id;
7506 -- Return a reference to the primitive operation of type T denoted by
7507 -- name Nam. If the operation is overloaded, the reference carries all
7508 -- interpretations. Flag Is_Constant should be set when the context is
7509 -- constant indexing.
7511 --------------------------
7512 -- Constant_Indexing_OK --
7513 --------------------------
7515 function Constant_Indexing_OK return Boolean is
7516 Par : Node_Id;
7518 begin
7519 if No (Find_Value_Of_Aspect (Pref_Typ, Aspect_Variable_Indexing)) then
7520 return True;
7522 elsif not Is_Variable (Prefix) then
7523 return True;
7524 end if;
7526 Par := N;
7527 while Present (Par) loop
7528 if Nkind (Parent (Par)) = N_Assignment_Statement
7529 and then Par = Name (Parent (Par))
7530 then
7531 return False;
7533 -- The call may be overloaded, in which case we assume that its
7534 -- resolution does not depend on the type of the parameter that
7535 -- includes the indexing operation.
7537 elsif Nkind_In (Parent (Par), N_Function_Call,
7538 N_Procedure_Call_Statement)
7539 and then Is_Entity_Name (Name (Parent (Par)))
7540 then
7541 declare
7542 Actual : Node_Id;
7543 Formal : Entity_Id;
7544 Proc : Entity_Id;
7546 begin
7547 -- We should look for an interpretation with the proper
7548 -- number of formals, and determine whether it is an
7549 -- In_Parameter, but for now we examine the formal that
7550 -- corresponds to the indexing, and assume that variable
7551 -- indexing is required if some interpretation has an
7552 -- assignable formal at that position. Still does not
7553 -- cover the most complex cases ???
7555 if Is_Overloaded (Name (Parent (Par))) then
7556 declare
7557 Proc : constant Node_Id := Name (Parent (Par));
7558 A : Node_Id;
7559 F : Entity_Id;
7560 I : Interp_Index;
7561 It : Interp;
7563 begin
7564 Get_First_Interp (Proc, I, It);
7565 while Present (It.Nam) loop
7566 F := First_Formal (It.Nam);
7567 A := First (Parameter_Associations (Parent (Par)));
7569 while Present (F) and then Present (A) loop
7570 if A = Par then
7571 if Ekind (F) /= E_In_Parameter then
7572 return False;
7573 else
7574 exit; -- interpretation is safe
7575 end if;
7576 end if;
7578 Next_Formal (F);
7579 Next_Actual (A);
7580 end loop;
7582 Get_Next_Interp (I, It);
7583 end loop;
7584 end;
7586 return True;
7588 else
7589 Proc := Entity (Name (Parent (Par)));
7591 -- If this is an indirect call, get formals from
7592 -- designated type.
7594 if Is_Access_Subprogram_Type (Etype (Proc)) then
7595 Proc := Designated_Type (Etype (Proc));
7596 end if;
7597 end if;
7599 Formal := First_Formal (Proc);
7600 Actual := First_Actual (Parent (Par));
7602 -- Find corresponding actual
7604 while Present (Actual) loop
7605 exit when Actual = Par;
7606 Next_Actual (Actual);
7608 if Present (Formal) then
7609 Next_Formal (Formal);
7611 -- Otherwise this is a parameter mismatch, the error is
7612 -- reported elsewhere.
7614 else
7615 return False;
7616 end if;
7617 end loop;
7619 return Ekind (Formal) = E_In_Parameter;
7620 end;
7622 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
7623 return False;
7625 -- If the indexed component is a prefix it may be the first actual
7626 -- of a prefixed call. Retrieve the called entity, if any, and
7627 -- check its first formal. Determine if the context is a procedure
7628 -- or function call.
7630 elsif Nkind (Parent (Par)) = N_Selected_Component then
7631 declare
7632 Sel : constant Node_Id := Selector_Name (Parent (Par));
7633 Nam : constant Entity_Id := Current_Entity (Sel);
7635 begin
7636 if Present (Nam) and then Is_Overloadable (Nam) then
7637 if Nkind (Parent (Parent (Par))) =
7638 N_Procedure_Call_Statement
7639 then
7640 return False;
7642 elsif Ekind (Nam) = E_Function
7643 and then Present (First_Formal (Nam))
7644 then
7645 return Ekind (First_Formal (Nam)) = E_In_Parameter;
7646 end if;
7647 end if;
7648 end;
7650 elsif Nkind (Par) in N_Op then
7651 return True;
7652 end if;
7654 Par := Parent (Par);
7655 end loop;
7657 -- In all other cases, constant indexing is legal
7659 return True;
7660 end Constant_Indexing_OK;
7662 ------------------------------
7663 -- Find_Indexing_Operations --
7664 ------------------------------
7666 function Find_Indexing_Operations
7667 (T : Entity_Id;
7668 Nam : Name_Id;
7669 Is_Constant : Boolean) return Node_Id
7671 procedure Inspect_Declarations
7672 (Typ : Entity_Id;
7673 Ref : in out Node_Id);
7674 -- Traverse the declarative list where type Typ resides and collect
7675 -- all suitable interpretations in node Ref.
7677 procedure Inspect_Primitives
7678 (Typ : Entity_Id;
7679 Ref : in out Node_Id);
7680 -- Traverse the list of primitive operations of type Typ and collect
7681 -- all suitable interpretations in node Ref.
7683 function Is_OK_Candidate
7684 (Subp_Id : Entity_Id;
7685 Typ : Entity_Id) return Boolean;
7686 -- Determine whether subprogram Subp_Id is a suitable indexing
7687 -- operation for type Typ. To qualify as such, the subprogram must
7688 -- be a function, have at least two parameters, and the type of the
7689 -- first parameter must be either Typ, or Typ'Class, or access [to
7690 -- constant] with designated type Typ or Typ'Class.
7692 procedure Record_Interp (Subp_Id : Entity_Id; Ref : in out Node_Id);
7693 -- Store subprogram Subp_Id as an interpretation in node Ref
7695 --------------------------
7696 -- Inspect_Declarations --
7697 --------------------------
7699 procedure Inspect_Declarations
7700 (Typ : Entity_Id;
7701 Ref : in out Node_Id)
7703 Typ_Decl : constant Node_Id := Declaration_Node (Typ);
7704 Decl : Node_Id;
7705 Subp_Id : Entity_Id;
7707 begin
7708 -- Ensure that the routine is not called with itypes, which lack a
7709 -- declarative node.
7711 pragma Assert (Present (Typ_Decl));
7712 pragma Assert (Is_List_Member (Typ_Decl));
7714 Decl := First (List_Containing (Typ_Decl));
7715 while Present (Decl) loop
7716 if Nkind (Decl) = N_Subprogram_Declaration then
7717 Subp_Id := Defining_Entity (Decl);
7719 if Is_OK_Candidate (Subp_Id, Typ) then
7720 Record_Interp (Subp_Id, Ref);
7721 end if;
7722 end if;
7724 Next (Decl);
7725 end loop;
7726 end Inspect_Declarations;
7728 ------------------------
7729 -- Inspect_Primitives --
7730 ------------------------
7732 procedure Inspect_Primitives
7733 (Typ : Entity_Id;
7734 Ref : in out Node_Id)
7736 Prim_Elmt : Elmt_Id;
7737 Prim_Id : Entity_Id;
7739 begin
7740 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
7741 while Present (Prim_Elmt) loop
7742 Prim_Id := Node (Prim_Elmt);
7744 if Is_OK_Candidate (Prim_Id, Typ) then
7745 Record_Interp (Prim_Id, Ref);
7746 end if;
7748 Next_Elmt (Prim_Elmt);
7749 end loop;
7750 end Inspect_Primitives;
7752 ---------------------
7753 -- Is_OK_Candidate --
7754 ---------------------
7756 function Is_OK_Candidate
7757 (Subp_Id : Entity_Id;
7758 Typ : Entity_Id) return Boolean
7760 Formal : Entity_Id;
7761 Formal_Typ : Entity_Id;
7762 Param_Typ : Node_Id;
7764 begin
7765 -- To classify as a suitable candidate, the subprogram must be a
7766 -- function whose name matches the argument of aspect Constant or
7767 -- Variable_Indexing.
7769 if Ekind (Subp_Id) = E_Function and then Chars (Subp_Id) = Nam then
7770 Formal := First_Formal (Subp_Id);
7772 -- The candidate requires at least two parameters
7774 if Present (Formal) and then Present (Next_Formal (Formal)) then
7775 Formal_Typ := Empty;
7776 Param_Typ := Parameter_Type (Parent (Formal));
7778 -- Use the designated type when the first parameter is of an
7779 -- access type.
7781 if Nkind (Param_Typ) = N_Access_Definition
7782 and then Present (Subtype_Mark (Param_Typ))
7783 then
7784 -- When the context is a constant indexing, the access
7785 -- definition must be access-to-constant. This does not
7786 -- apply to variable indexing.
7788 if not Is_Constant
7789 or else Constant_Present (Param_Typ)
7790 then
7791 Formal_Typ := Etype (Subtype_Mark (Param_Typ));
7792 end if;
7794 -- Otherwise use the parameter type
7796 else
7797 Formal_Typ := Etype (Param_Typ);
7798 end if;
7800 if Present (Formal_Typ) then
7802 -- Use the specific type when the parameter type is
7803 -- class-wide.
7805 if Is_Class_Wide_Type (Formal_Typ) then
7806 Formal_Typ := Etype (Base_Type (Formal_Typ));
7807 end if;
7809 -- Use the full view when the parameter type is private
7810 -- or incomplete.
7812 if Is_Incomplete_Or_Private_Type (Formal_Typ)
7813 and then Present (Full_View (Formal_Typ))
7814 then
7815 Formal_Typ := Full_View (Formal_Typ);
7816 end if;
7818 -- The type of the first parameter must denote the type
7819 -- of the container or acts as its ancestor type.
7821 return
7822 Formal_Typ = Typ
7823 or else Is_Ancestor (Formal_Typ, Typ);
7824 end if;
7825 end if;
7826 end if;
7828 return False;
7829 end Is_OK_Candidate;
7831 -------------------
7832 -- Record_Interp --
7833 -------------------
7835 procedure Record_Interp (Subp_Id : Entity_Id; Ref : in out Node_Id) is
7836 begin
7837 if Present (Ref) then
7838 Add_One_Interp (Ref, Subp_Id, Etype (Subp_Id));
7840 -- Otherwise this is the first interpretation. Create a reference
7841 -- where all remaining interpretations will be collected.
7843 else
7844 Ref := New_Occurrence_Of (Subp_Id, Sloc (T));
7845 end if;
7846 end Record_Interp;
7848 -- Local variables
7850 Ref : Node_Id;
7851 Typ : Entity_Id;
7853 -- Start of processing for Find_Indexing_Operations
7855 begin
7856 Typ := T;
7858 -- Use the specific type when the parameter type is class-wide
7860 if Is_Class_Wide_Type (Typ) then
7861 Typ := Root_Type (Typ);
7862 end if;
7864 Ref := Empty;
7865 Typ := Underlying_Type (Base_Type (Typ));
7867 Inspect_Primitives (Typ, Ref);
7869 -- Now look for explicit declarations of an indexing operation.
7870 -- If the type is private the operation may be declared in the
7871 -- visible part that contains the partial view.
7873 if Is_Private_Type (T) then
7874 Inspect_Declarations (T, Ref);
7875 end if;
7877 Inspect_Declarations (Typ, Ref);
7879 return Ref;
7880 end Find_Indexing_Operations;
7882 -- Local variables
7884 Loc : constant Source_Ptr := Sloc (N);
7885 Assoc : List_Id;
7886 C_Type : Entity_Id;
7887 Func : Entity_Id;
7888 Func_Name : Node_Id;
7889 Indexing : Node_Id;
7891 Is_Constant_Indexing : Boolean := False;
7892 -- This flag reflects the nature of the container indexing. Note that
7893 -- the context may be suited for constant indexing, but the type may
7894 -- lack a Constant_Indexing annotation.
7896 -- Start of processing for Try_Container_Indexing
7898 begin
7899 -- Node may have been analyzed already when testing for a prefixed
7900 -- call, in which case do not redo analysis.
7902 if Present (Generalized_Indexing (N)) then
7903 return True;
7904 end if;
7906 C_Type := Pref_Typ;
7908 -- If indexing a class-wide container, obtain indexing primitive from
7909 -- specific type.
7911 if Is_Class_Wide_Type (C_Type) then
7912 C_Type := Etype (Base_Type (C_Type));
7913 end if;
7915 -- Check whether the type has a specified indexing aspect
7917 Func_Name := Empty;
7919 -- The context is suitable for constant indexing, so obtain the name of
7920 -- the indexing function from aspect Constant_Indexing.
7922 if Constant_Indexing_OK then
7923 Func_Name :=
7924 Find_Value_Of_Aspect (Pref_Typ, Aspect_Constant_Indexing);
7925 end if;
7927 if Present (Func_Name) then
7928 Is_Constant_Indexing := True;
7930 -- Otherwise attempt variable indexing
7932 else
7933 Func_Name :=
7934 Find_Value_Of_Aspect (Pref_Typ, Aspect_Variable_Indexing);
7935 end if;
7937 -- The type is not subject to either form of indexing, therefore the
7938 -- indexed component does not denote container indexing. If this is a
7939 -- true error, it is diagnosed by the caller.
7941 if No (Func_Name) then
7943 -- The prefix itself may be an indexing of a container. Rewrite it
7944 -- as such and retry.
7946 if Has_Implicit_Dereference (Pref_Typ) then
7947 Build_Explicit_Dereference (Prefix, First_Discriminant (Pref_Typ));
7948 return Try_Container_Indexing (N, Prefix, Exprs);
7950 -- Otherwise this is definitely not container indexing
7952 else
7953 return False;
7954 end if;
7956 -- If the container type is derived from another container type, the
7957 -- value of the inherited aspect is the Reference operation declared
7958 -- for the parent type.
7960 -- However, Reference is also a primitive operation of the type, and the
7961 -- inherited operation has a different signature. We retrieve the right
7962 -- ones (the function may be overloaded) from the list of primitive
7963 -- operations of the derived type.
7965 -- Note that predefined containers are typically all derived from one of
7966 -- the Controlled types. The code below is motivated by containers that
7967 -- are derived from other types with a Reference aspect.
7969 elsif Is_Derived_Type (C_Type)
7970 and then Etype (First_Formal (Entity (Func_Name))) /= Pref_Typ
7971 then
7972 Func_Name :=
7973 Find_Indexing_Operations
7974 (T => C_Type,
7975 Nam => Chars (Func_Name),
7976 Is_Constant => Is_Constant_Indexing);
7977 end if;
7979 Assoc := New_List (Relocate_Node (Prefix));
7981 -- A generalized indexing may have nore than one index expression, so
7982 -- transfer all of them to the argument list to be used in the call.
7983 -- Note that there may be named associations, in which case the node
7984 -- was rewritten earlier as a call, and has been transformed back into
7985 -- an indexed expression to share the following processing.
7987 -- The generalized indexing node is the one on which analysis and
7988 -- resolution take place. Before expansion the original node is replaced
7989 -- with the generalized indexing node, which is a call, possibly with a
7990 -- dereference operation.
7992 if Comes_From_Source (N) then
7993 Check_Compiler_Unit ("generalized indexing", N);
7994 end if;
7996 -- Create argument list for function call that represents generalized
7997 -- indexing. Note that indices (i.e. actuals) may themselves be
7998 -- overloaded.
8000 declare
8001 Arg : Node_Id;
8002 New_Arg : Node_Id;
8004 begin
8005 Arg := First (Exprs);
8006 while Present (Arg) loop
8007 New_Arg := Relocate_Node (Arg);
8009 -- The arguments can be parameter associations, in which case the
8010 -- explicit actual parameter carries the overloadings.
8012 if Nkind (New_Arg) /= N_Parameter_Association then
8013 Save_Interps (Arg, New_Arg);
8014 end if;
8016 Append (New_Arg, Assoc);
8017 Next (Arg);
8018 end loop;
8019 end;
8021 if not Is_Overloaded (Func_Name) then
8022 Func := Entity (Func_Name);
8024 Indexing :=
8025 Make_Function_Call (Loc,
8026 Name => New_Occurrence_Of (Func, Loc),
8027 Parameter_Associations => Assoc);
8029 Set_Parent (Indexing, Parent (N));
8030 Set_Generalized_Indexing (N, Indexing);
8031 Analyze (Indexing);
8032 Set_Etype (N, Etype (Indexing));
8034 -- If the return type of the indexing function is a reference type,
8035 -- add the dereference as a possible interpretation. Note that the
8036 -- indexing aspect may be a function that returns the element type
8037 -- with no intervening implicit dereference, and that the reference
8038 -- discriminant is not the first discriminant.
8040 if Has_Discriminants (Etype (Func)) then
8041 Check_Implicit_Dereference (N, Etype (Func));
8042 end if;
8044 else
8045 -- If there are multiple indexing functions, build a function call
8046 -- and analyze it for each of the possible interpretations.
8048 Indexing :=
8049 Make_Function_Call (Loc,
8050 Name =>
8051 Make_Identifier (Loc, Chars (Func_Name)),
8052 Parameter_Associations => Assoc);
8053 Set_Parent (Indexing, Parent (N));
8054 Set_Generalized_Indexing (N, Indexing);
8055 Set_Etype (N, Any_Type);
8056 Set_Etype (Name (Indexing), Any_Type);
8058 declare
8059 I : Interp_Index;
8060 It : Interp;
8061 Success : Boolean;
8063 begin
8064 Get_First_Interp (Func_Name, I, It);
8065 Set_Etype (Indexing, Any_Type);
8067 -- Analyze each candidate function with the given actuals
8069 while Present (It.Nam) loop
8070 Analyze_One_Call (Indexing, It.Nam, False, Success);
8071 Get_Next_Interp (I, It);
8072 end loop;
8074 -- If there are several successful candidates, resolution will
8075 -- be by result. Mark the interpretations of the function name
8076 -- itself.
8078 if Is_Overloaded (Indexing) then
8079 Get_First_Interp (Indexing, I, It);
8081 while Present (It.Nam) loop
8082 Add_One_Interp (Name (Indexing), It.Nam, It.Typ);
8083 Get_Next_Interp (I, It);
8084 end loop;
8086 else
8087 Set_Etype (Name (Indexing), Etype (Indexing));
8088 end if;
8090 -- Now add the candidate interpretations to the indexing node
8091 -- itself, to be replaced later by the function call.
8093 if Is_Overloaded (Name (Indexing)) then
8094 Get_First_Interp (Name (Indexing), I, It);
8096 while Present (It.Nam) loop
8097 Add_One_Interp (N, It.Nam, It.Typ);
8099 -- Add dereference interpretation if the result type has
8100 -- implicit reference discriminants.
8102 if Has_Discriminants (Etype (It.Nam)) then
8103 Check_Implicit_Dereference (N, Etype (It.Nam));
8104 end if;
8106 Get_Next_Interp (I, It);
8107 end loop;
8109 else
8110 Set_Etype (N, Etype (Name (Indexing)));
8111 if Has_Discriminants (Etype (N)) then
8112 Check_Implicit_Dereference (N, Etype (N));
8113 end if;
8114 end if;
8115 end;
8116 end if;
8118 if Etype (Indexing) = Any_Type then
8119 Error_Msg_NE
8120 ("container cannot be indexed with&", N, Etype (First (Exprs)));
8121 Rewrite (N, New_Occurrence_Of (Any_Id, Loc));
8122 end if;
8124 return True;
8125 end Try_Container_Indexing;
8127 -----------------------
8128 -- Try_Indirect_Call --
8129 -----------------------
8131 function Try_Indirect_Call
8132 (N : Node_Id;
8133 Nam : Entity_Id;
8134 Typ : Entity_Id) return Boolean
8136 Actual : Node_Id;
8137 Formal : Entity_Id;
8139 Call_OK : Boolean;
8140 pragma Warnings (Off, Call_OK);
8142 begin
8143 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
8145 Actual := First_Actual (N);
8146 Formal := First_Formal (Designated_Type (Typ));
8147 while Present (Actual) and then Present (Formal) loop
8148 if not Has_Compatible_Type (Actual, Etype (Formal)) then
8149 return False;
8150 end if;
8152 Next (Actual);
8153 Next_Formal (Formal);
8154 end loop;
8156 if No (Actual) and then No (Formal) then
8157 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
8159 -- Nam is a candidate interpretation for the name in the call,
8160 -- if it is not an indirect call.
8162 if not Is_Type (Nam)
8163 and then Is_Entity_Name (Name (N))
8164 then
8165 Set_Entity (Name (N), Nam);
8166 end if;
8168 return True;
8170 else
8171 return False;
8172 end if;
8173 end Try_Indirect_Call;
8175 ----------------------
8176 -- Try_Indexed_Call --
8177 ----------------------
8179 function Try_Indexed_Call
8180 (N : Node_Id;
8181 Nam : Entity_Id;
8182 Typ : Entity_Id;
8183 Skip_First : Boolean) return Boolean
8185 Loc : constant Source_Ptr := Sloc (N);
8186 Actuals : constant List_Id := Parameter_Associations (N);
8187 Actual : Node_Id;
8188 Index : Entity_Id;
8190 begin
8191 Actual := First (Actuals);
8193 -- If the call was originally written in prefix form, skip the first
8194 -- actual, which is obviously not defaulted.
8196 if Skip_First then
8197 Next (Actual);
8198 end if;
8200 Index := First_Index (Typ);
8201 while Present (Actual) and then Present (Index) loop
8203 -- If the parameter list has a named association, the expression
8204 -- is definitely a call and not an indexed component.
8206 if Nkind (Actual) = N_Parameter_Association then
8207 return False;
8208 end if;
8210 if Is_Entity_Name (Actual)
8211 and then Is_Type (Entity (Actual))
8212 and then No (Next (Actual))
8213 then
8214 -- A single actual that is a type name indicates a slice if the
8215 -- type is discrete, and an error otherwise.
8217 if Is_Discrete_Type (Entity (Actual)) then
8218 Rewrite (N,
8219 Make_Slice (Loc,
8220 Prefix =>
8221 Make_Function_Call (Loc,
8222 Name => Relocate_Node (Name (N))),
8223 Discrete_Range =>
8224 New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
8226 Analyze (N);
8228 else
8229 Error_Msg_N ("invalid use of type in expression", Actual);
8230 Set_Etype (N, Any_Type);
8231 end if;
8233 return True;
8235 elsif not Has_Compatible_Type (Actual, Etype (Index)) then
8236 return False;
8237 end if;
8239 Next (Actual);
8240 Next_Index (Index);
8241 end loop;
8243 if No (Actual) and then No (Index) then
8244 Add_One_Interp (N, Nam, Component_Type (Typ));
8246 -- Nam is a candidate interpretation for the name in the call,
8247 -- if it is not an indirect call.
8249 if not Is_Type (Nam)
8250 and then Is_Entity_Name (Name (N))
8251 then
8252 Set_Entity (Name (N), Nam);
8253 end if;
8255 return True;
8256 else
8257 return False;
8258 end if;
8259 end Try_Indexed_Call;
8261 --------------------------
8262 -- Try_Object_Operation --
8263 --------------------------
8265 function Try_Object_Operation
8266 (N : Node_Id; CW_Test_Only : Boolean := False) return Boolean
8268 K : constant Node_Kind := Nkind (Parent (N));
8269 Is_Subprg_Call : constant Boolean := K in N_Subprogram_Call;
8270 Loc : constant Source_Ptr := Sloc (N);
8271 Obj : constant Node_Id := Prefix (N);
8273 Subprog : constant Node_Id :=
8274 Make_Identifier (Sloc (Selector_Name (N)),
8275 Chars => Chars (Selector_Name (N)));
8276 -- Identifier on which possible interpretations will be collected
8278 Report_Error : Boolean := False;
8279 -- If no candidate interpretation matches the context, redo analysis
8280 -- with Report_Error True to provide additional information.
8282 Actual : Node_Id;
8283 Candidate : Entity_Id := Empty;
8284 New_Call_Node : Node_Id := Empty;
8285 Node_To_Replace : Node_Id;
8286 Obj_Type : Entity_Id := Etype (Obj);
8287 Success : Boolean := False;
8289 function Valid_Candidate
8290 (Success : Boolean;
8291 Call : Node_Id;
8292 Subp : Entity_Id) return Entity_Id;
8293 -- If the subprogram is a valid interpretation, record it, and add
8294 -- to the list of interpretations of Subprog. Otherwise return Empty.
8296 procedure Complete_Object_Operation
8297 (Call_Node : Node_Id;
8298 Node_To_Replace : Node_Id);
8299 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
8300 -- Call_Node, insert the object (or its dereference) as the first actual
8301 -- in the call, and complete the analysis of the call.
8303 procedure Report_Ambiguity (Op : Entity_Id);
8304 -- If a prefixed procedure call is ambiguous, indicate whether the
8305 -- call includes an implicit dereference or an implicit 'Access.
8307 procedure Transform_Object_Operation
8308 (Call_Node : out Node_Id;
8309 Node_To_Replace : out Node_Id);
8310 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
8311 -- Call_Node is the resulting subprogram call, Node_To_Replace is
8312 -- either N or the parent of N, and Subprog is a reference to the
8313 -- subprogram we are trying to match.
8315 function Try_Class_Wide_Operation
8316 (Call_Node : Node_Id;
8317 Node_To_Replace : Node_Id) return Boolean;
8318 -- Traverse all ancestor types looking for a class-wide subprogram
8319 -- for which the current operation is a valid non-dispatching call.
8321 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
8322 -- If prefix is overloaded, its interpretation may include different
8323 -- tagged types, and we must examine the primitive operations and
8324 -- the class-wide operations of each in order to find candidate
8325 -- interpretations for the call as a whole.
8327 function Try_Primitive_Operation
8328 (Call_Node : Node_Id;
8329 Node_To_Replace : Node_Id) return Boolean;
8330 -- Traverse the list of primitive subprograms looking for a dispatching
8331 -- operation for which the current node is a valid call .
8333 ---------------------
8334 -- Valid_Candidate --
8335 ---------------------
8337 function Valid_Candidate
8338 (Success : Boolean;
8339 Call : Node_Id;
8340 Subp : Entity_Id) return Entity_Id
8342 Arr_Type : Entity_Id;
8343 Comp_Type : Entity_Id;
8345 begin
8346 -- If the subprogram is a valid interpretation, record it in global
8347 -- variable Subprog, to collect all possible overloadings.
8349 if Success then
8350 if Subp /= Entity (Subprog) then
8351 Add_One_Interp (Subprog, Subp, Etype (Subp));
8352 end if;
8353 end if;
8355 -- If the call may be an indexed call, retrieve component type of
8356 -- resulting expression, and add possible interpretation.
8358 Arr_Type := Empty;
8359 Comp_Type := Empty;
8361 if Nkind (Call) = N_Function_Call
8362 and then Nkind (Parent (N)) = N_Indexed_Component
8363 and then Needs_One_Actual (Subp)
8364 then
8365 if Is_Array_Type (Etype (Subp)) then
8366 Arr_Type := Etype (Subp);
8368 elsif Is_Access_Type (Etype (Subp))
8369 and then Is_Array_Type (Designated_Type (Etype (Subp)))
8370 then
8371 Arr_Type := Designated_Type (Etype (Subp));
8372 end if;
8373 end if;
8375 if Present (Arr_Type) then
8377 -- Verify that the actuals (excluding the object) match the types
8378 -- of the indexes.
8380 declare
8381 Actual : Node_Id;
8382 Index : Node_Id;
8384 begin
8385 Actual := Next (First_Actual (Call));
8386 Index := First_Index (Arr_Type);
8387 while Present (Actual) and then Present (Index) loop
8388 if not Has_Compatible_Type (Actual, Etype (Index)) then
8389 Arr_Type := Empty;
8390 exit;
8391 end if;
8393 Next_Actual (Actual);
8394 Next_Index (Index);
8395 end loop;
8397 if No (Actual)
8398 and then No (Index)
8399 and then Present (Arr_Type)
8400 then
8401 Comp_Type := Component_Type (Arr_Type);
8402 end if;
8403 end;
8405 if Present (Comp_Type)
8406 and then Etype (Subprog) /= Comp_Type
8407 then
8408 Add_One_Interp (Subprog, Subp, Comp_Type);
8409 end if;
8410 end if;
8412 if Etype (Call) /= Any_Type then
8413 return Subp;
8414 else
8415 return Empty;
8416 end if;
8417 end Valid_Candidate;
8419 -------------------------------
8420 -- Complete_Object_Operation --
8421 -------------------------------
8423 procedure Complete_Object_Operation
8424 (Call_Node : Node_Id;
8425 Node_To_Replace : Node_Id)
8427 Control : constant Entity_Id := First_Formal (Entity (Subprog));
8428 Formal_Type : constant Entity_Id := Etype (Control);
8429 First_Actual : Node_Id;
8431 begin
8432 -- Place the name of the operation, with its interpretations,
8433 -- on the rewritten call.
8435 Set_Name (Call_Node, Subprog);
8437 First_Actual := First (Parameter_Associations (Call_Node));
8439 -- For cross-reference purposes, treat the new node as being in the
8440 -- source if the original one is. Set entity and type, even though
8441 -- they may be overwritten during resolution if overloaded.
8443 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
8444 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
8446 if Nkind (N) = N_Selected_Component
8447 and then not Inside_A_Generic
8448 then
8449 Set_Entity (Selector_Name (N), Entity (Subprog));
8450 Set_Etype (Selector_Name (N), Etype (Entity (Subprog)));
8451 end if;
8453 -- If need be, rewrite first actual as an explicit dereference. If
8454 -- the call is overloaded, the rewriting can only be done once the
8455 -- primitive operation is identified.
8457 if Is_Overloaded (Subprog) then
8459 -- The prefix itself may be overloaded, and its interpretations
8460 -- must be propagated to the new actual in the call.
8462 if Is_Overloaded (Obj) then
8463 Save_Interps (Obj, First_Actual);
8464 end if;
8466 Rewrite (First_Actual, Obj);
8468 elsif not Is_Access_Type (Formal_Type)
8469 and then Is_Access_Type (Etype (Obj))
8470 then
8471 Rewrite (First_Actual,
8472 Make_Explicit_Dereference (Sloc (Obj), Obj));
8473 Analyze (First_Actual);
8475 -- If we need to introduce an explicit dereference, verify that
8476 -- the resulting actual is compatible with the mode of the formal.
8478 if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
8479 and then Is_Access_Constant (Etype (Obj))
8480 then
8481 Error_Msg_NE
8482 ("expect variable in call to&", Prefix (N), Entity (Subprog));
8483 end if;
8485 -- Conversely, if the formal is an access parameter and the object
8486 -- is not, replace the actual with a 'Access reference. Its analysis
8487 -- will check that the object is aliased.
8489 elsif Is_Access_Type (Formal_Type)
8490 and then not Is_Access_Type (Etype (Obj))
8491 then
8492 -- A special case: A.all'access is illegal if A is an access to a
8493 -- constant and the context requires an access to a variable.
8495 if not Is_Access_Constant (Formal_Type) then
8496 if (Nkind (Obj) = N_Explicit_Dereference
8497 and then Is_Access_Constant (Etype (Prefix (Obj))))
8498 or else not Is_Variable (Obj)
8499 then
8500 Error_Msg_NE
8501 ("actual for & must be a variable", Obj, Control);
8502 end if;
8503 end if;
8505 Rewrite (First_Actual,
8506 Make_Attribute_Reference (Loc,
8507 Attribute_Name => Name_Access,
8508 Prefix => Relocate_Node (Obj)));
8510 if not Is_Aliased_View (Obj) then
8511 Error_Msg_NE
8512 ("object in prefixed call to & must be aliased "
8513 & "(RM 4.1.3 (13 1/2))", Prefix (First_Actual), Subprog);
8514 end if;
8516 Analyze (First_Actual);
8518 else
8519 if Is_Overloaded (Obj) then
8520 Save_Interps (Obj, First_Actual);
8521 end if;
8523 Rewrite (First_Actual, Obj);
8524 end if;
8526 -- The operation is obtained from the dispatch table and not by
8527 -- visibility, and may be declared in a unit that is not explicitly
8528 -- referenced in the source, but is nevertheless required in the
8529 -- context of the current unit. Indicate that operation and its scope
8530 -- are referenced, to prevent spurious and misleading warnings. If
8531 -- the operation is overloaded, all primitives are in the same scope
8532 -- and we can use any of them.
8534 Set_Referenced (Entity (Subprog), True);
8535 Set_Referenced (Scope (Entity (Subprog)), True);
8537 Rewrite (Node_To_Replace, Call_Node);
8539 -- Propagate the interpretations collected in subprog to the new
8540 -- function call node, to be resolved from context.
8542 if Is_Overloaded (Subprog) then
8543 Save_Interps (Subprog, Node_To_Replace);
8545 else
8546 -- The type of the subprogram may be a limited view obtained
8547 -- transitively from another unit. If full view is available,
8548 -- use it to analyze call.
8550 declare
8551 T : constant Entity_Id := Etype (Subprog);
8552 begin
8553 if From_Limited_With (T) then
8554 Set_Etype (Entity (Subprog), Available_View (T));
8555 end if;
8556 end;
8558 Analyze (Node_To_Replace);
8560 -- If the operation has been rewritten into a call, which may get
8561 -- subsequently an explicit dereference, preserve the type on the
8562 -- original node (selected component or indexed component) for
8563 -- subsequent legality tests, e.g. Is_Variable. which examines
8564 -- the original node.
8566 if Nkind (Node_To_Replace) = N_Function_Call then
8567 Set_Etype
8568 (Original_Node (Node_To_Replace), Etype (Node_To_Replace));
8569 end if;
8570 end if;
8571 end Complete_Object_Operation;
8573 ----------------------
8574 -- Report_Ambiguity --
8575 ----------------------
8577 procedure Report_Ambiguity (Op : Entity_Id) is
8578 Access_Actual : constant Boolean :=
8579 Is_Access_Type (Etype (Prefix (N)));
8580 Access_Formal : Boolean := False;
8582 begin
8583 Error_Msg_Sloc := Sloc (Op);
8585 if Present (First_Formal (Op)) then
8586 Access_Formal := Is_Access_Type (Etype (First_Formal (Op)));
8587 end if;
8589 if Access_Formal and then not Access_Actual then
8590 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8591 Error_Msg_N
8592 ("\possible interpretation "
8593 & "(inherited, with implicit 'Access) #", N);
8594 else
8595 Error_Msg_N
8596 ("\possible interpretation (with implicit 'Access) #", N);
8597 end if;
8599 elsif not Access_Formal and then Access_Actual then
8600 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8601 Error_Msg_N
8602 ("\possible interpretation "
8603 & "(inherited, with implicit dereference) #", N);
8604 else
8605 Error_Msg_N
8606 ("\possible interpretation (with implicit dereference) #", N);
8607 end if;
8609 else
8610 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8611 Error_Msg_N ("\possible interpretation (inherited)#", N);
8612 else
8613 Error_Msg_N -- CODEFIX
8614 ("\possible interpretation#", N);
8615 end if;
8616 end if;
8617 end Report_Ambiguity;
8619 --------------------------------
8620 -- Transform_Object_Operation --
8621 --------------------------------
8623 procedure Transform_Object_Operation
8624 (Call_Node : out Node_Id;
8625 Node_To_Replace : out Node_Id)
8627 Dummy : constant Node_Id := New_Copy (Obj);
8628 -- Placeholder used as a first parameter in the call, replaced
8629 -- eventually by the proper object.
8631 Parent_Node : constant Node_Id := Parent (N);
8633 Actual : Node_Id;
8634 Actuals : List_Id;
8636 begin
8637 -- Common case covering 1) Call to a procedure and 2) Call to a
8638 -- function that has some additional actuals.
8640 if Nkind (Parent_Node) in N_Subprogram_Call
8642 -- N is a selected component node containing the name of the
8643 -- subprogram. If N is not the name of the parent node we must
8644 -- not replace the parent node by the new construct. This case
8645 -- occurs when N is a parameterless call to a subprogram that
8646 -- is an actual parameter of a call to another subprogram. For
8647 -- example:
8648 -- Some_Subprogram (..., Obj.Operation, ...)
8650 and then Name (Parent_Node) = N
8651 then
8652 Node_To_Replace := Parent_Node;
8654 Actuals := Parameter_Associations (Parent_Node);
8656 if Present (Actuals) then
8657 Prepend (Dummy, Actuals);
8658 else
8659 Actuals := New_List (Dummy);
8660 end if;
8662 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
8663 Call_Node :=
8664 Make_Procedure_Call_Statement (Loc,
8665 Name => New_Copy (Subprog),
8666 Parameter_Associations => Actuals);
8668 else
8669 Call_Node :=
8670 Make_Function_Call (Loc,
8671 Name => New_Copy (Subprog),
8672 Parameter_Associations => Actuals);
8673 end if;
8675 -- Before analysis, a function call appears as an indexed component
8676 -- if there are no named associations.
8678 elsif Nkind (Parent_Node) = N_Indexed_Component
8679 and then N = Prefix (Parent_Node)
8680 then
8681 Node_To_Replace := Parent_Node;
8682 Actuals := Expressions (Parent_Node);
8684 Actual := First (Actuals);
8685 while Present (Actual) loop
8686 Analyze (Actual);
8687 Next (Actual);
8688 end loop;
8690 Prepend (Dummy, Actuals);
8692 Call_Node :=
8693 Make_Function_Call (Loc,
8694 Name => New_Copy (Subprog),
8695 Parameter_Associations => Actuals);
8697 -- Parameterless call: Obj.F is rewritten as F (Obj)
8699 else
8700 Node_To_Replace := N;
8702 Call_Node :=
8703 Make_Function_Call (Loc,
8704 Name => New_Copy (Subprog),
8705 Parameter_Associations => New_List (Dummy));
8706 end if;
8707 end Transform_Object_Operation;
8709 ------------------------------
8710 -- Try_Class_Wide_Operation --
8711 ------------------------------
8713 function Try_Class_Wide_Operation
8714 (Call_Node : Node_Id;
8715 Node_To_Replace : Node_Id) return Boolean
8717 Anc_Type : Entity_Id;
8718 Matching_Op : Entity_Id := Empty;
8719 Error : Boolean;
8721 procedure Traverse_Homonyms
8722 (Anc_Type : Entity_Id;
8723 Error : out Boolean);
8724 -- Traverse the homonym chain of the subprogram searching for those
8725 -- homonyms whose first formal has the Anc_Type's class-wide type,
8726 -- or an anonymous access type designating the class-wide type. If
8727 -- an ambiguity is detected, then Error is set to True.
8729 procedure Traverse_Interfaces
8730 (Anc_Type : Entity_Id;
8731 Error : out Boolean);
8732 -- Traverse the list of interfaces, if any, associated with Anc_Type
8733 -- and search for acceptable class-wide homonyms associated with each
8734 -- interface. If an ambiguity is detected, then Error is set to True.
8736 -----------------------
8737 -- Traverse_Homonyms --
8738 -----------------------
8740 procedure Traverse_Homonyms
8741 (Anc_Type : Entity_Id;
8742 Error : out Boolean)
8744 Cls_Type : Entity_Id;
8745 Hom : Entity_Id;
8746 Hom_Ref : Node_Id;
8747 Success : Boolean;
8749 begin
8750 Error := False;
8752 Cls_Type := Class_Wide_Type (Anc_Type);
8754 Hom := Current_Entity (Subprog);
8756 -- Find a non-hidden operation whose first parameter is of the
8757 -- class-wide type, a subtype thereof, or an anonymous access
8758 -- to same. If in an instance, the operation can be considered
8759 -- even if hidden (it may be hidden because the instantiation
8760 -- is expanded after the containing package has been analyzed).
8762 while Present (Hom) loop
8763 if Ekind_In (Hom, E_Procedure, E_Function)
8764 and then (not Is_Hidden (Hom) or else In_Instance)
8765 and then Scope (Hom) = Scope (Anc_Type)
8766 and then Present (First_Formal (Hom))
8767 and then
8768 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
8769 or else
8770 (Is_Access_Type (Etype (First_Formal (Hom)))
8771 and then
8772 Ekind (Etype (First_Formal (Hom))) =
8773 E_Anonymous_Access_Type
8774 and then
8775 Base_Type
8776 (Designated_Type (Etype (First_Formal (Hom)))) =
8777 Cls_Type))
8778 then
8779 -- If the context is a procedure call, ignore functions
8780 -- in the name of the call.
8782 if Ekind (Hom) = E_Function
8783 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
8784 and then N = Name (Parent (N))
8785 then
8786 goto Next_Hom;
8788 -- If the context is a function call, ignore procedures
8789 -- in the name of the call.
8791 elsif Ekind (Hom) = E_Procedure
8792 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
8793 then
8794 goto Next_Hom;
8795 end if;
8797 Set_Etype (Call_Node, Any_Type);
8798 Set_Is_Overloaded (Call_Node, False);
8799 Success := False;
8801 if No (Matching_Op) then
8802 Hom_Ref := New_Occurrence_Of (Hom, Sloc (Subprog));
8803 Set_Etype (Call_Node, Any_Type);
8804 Set_Parent (Call_Node, Parent (Node_To_Replace));
8806 Set_Name (Call_Node, Hom_Ref);
8808 Analyze_One_Call
8809 (N => Call_Node,
8810 Nam => Hom,
8811 Report => Report_Error,
8812 Success => Success,
8813 Skip_First => True);
8815 Matching_Op :=
8816 Valid_Candidate (Success, Call_Node, Hom);
8818 else
8819 Analyze_One_Call
8820 (N => Call_Node,
8821 Nam => Hom,
8822 Report => Report_Error,
8823 Success => Success,
8824 Skip_First => True);
8826 if Present (Valid_Candidate (Success, Call_Node, Hom))
8827 and then Nkind (Call_Node) /= N_Function_Call
8828 then
8829 Error_Msg_NE ("ambiguous call to&", N, Hom);
8830 Report_Ambiguity (Matching_Op);
8831 Report_Ambiguity (Hom);
8832 Error := True;
8833 return;
8834 end if;
8835 end if;
8836 end if;
8838 <<Next_Hom>>
8839 Hom := Homonym (Hom);
8840 end loop;
8841 end Traverse_Homonyms;
8843 -------------------------
8844 -- Traverse_Interfaces --
8845 -------------------------
8847 procedure Traverse_Interfaces
8848 (Anc_Type : Entity_Id;
8849 Error : out Boolean)
8851 Intface_List : constant List_Id :=
8852 Abstract_Interface_List (Anc_Type);
8853 Intface : Node_Id;
8855 begin
8856 Error := False;
8858 if Is_Non_Empty_List (Intface_List) then
8859 Intface := First (Intface_List);
8860 while Present (Intface) loop
8862 -- Look for acceptable class-wide homonyms associated with
8863 -- the interface.
8865 Traverse_Homonyms (Etype (Intface), Error);
8867 if Error then
8868 return;
8869 end if;
8871 -- Continue the search by looking at each of the interface's
8872 -- associated interface ancestors.
8874 Traverse_Interfaces (Etype (Intface), Error);
8876 if Error then
8877 return;
8878 end if;
8880 Next (Intface);
8881 end loop;
8882 end if;
8883 end Traverse_Interfaces;
8885 -- Start of processing for Try_Class_Wide_Operation
8887 begin
8888 -- If we are searching only for conflicting class-wide subprograms
8889 -- then initialize directly Matching_Op with the target entity.
8891 if CW_Test_Only then
8892 Matching_Op := Entity (Selector_Name (N));
8893 end if;
8895 -- Loop through ancestor types (including interfaces), traversing
8896 -- the homonym chain of the subprogram, trying out those homonyms
8897 -- whose first formal has the class-wide type of the ancestor, or
8898 -- an anonymous access type designating the class-wide type.
8900 Anc_Type := Obj_Type;
8901 loop
8902 -- Look for a match among homonyms associated with the ancestor
8904 Traverse_Homonyms (Anc_Type, Error);
8906 if Error then
8907 return True;
8908 end if;
8910 -- Continue the search for matches among homonyms associated with
8911 -- any interfaces implemented by the ancestor.
8913 Traverse_Interfaces (Anc_Type, Error);
8915 if Error then
8916 return True;
8917 end if;
8919 exit when Etype (Anc_Type) = Anc_Type;
8920 Anc_Type := Etype (Anc_Type);
8921 end loop;
8923 if Present (Matching_Op) then
8924 Set_Etype (Call_Node, Etype (Matching_Op));
8925 end if;
8927 return Present (Matching_Op);
8928 end Try_Class_Wide_Operation;
8930 -----------------------------------
8931 -- Try_One_Prefix_Interpretation --
8932 -----------------------------------
8934 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
8936 -- If the interpretation does not have a valid candidate type,
8937 -- preserve current value of Obj_Type for subsequent errors.
8939 Prev_Obj_Type : constant Entity_Id := Obj_Type;
8941 begin
8942 Obj_Type := T;
8944 if Is_Access_Type (Obj_Type) then
8945 Obj_Type := Designated_Type (Obj_Type);
8946 end if;
8948 if Ekind (Obj_Type) = E_Private_Subtype then
8949 Obj_Type := Base_Type (Obj_Type);
8950 end if;
8952 if Is_Class_Wide_Type (Obj_Type) then
8953 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
8954 end if;
8956 -- The type may have be obtained through a limited_with clause,
8957 -- in which case the primitive operations are available on its
8958 -- non-limited view. If still incomplete, retrieve full view.
8960 if Ekind (Obj_Type) = E_Incomplete_Type
8961 and then From_Limited_With (Obj_Type)
8962 and then Has_Non_Limited_View (Obj_Type)
8963 then
8964 Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
8965 end if;
8967 -- If the object is not tagged, or the type is still an incomplete
8968 -- type, this is not a prefixed call.
8970 if not Is_Tagged_Type (Obj_Type)
8971 or else Is_Incomplete_Type (Obj_Type)
8972 then
8974 -- Restore previous type if current one is not legal candidate
8976 Obj_Type := Prev_Obj_Type;
8977 return;
8978 end if;
8980 declare
8981 Dup_Call_Node : constant Node_Id := New_Copy (New_Call_Node);
8982 CW_Result : Boolean;
8983 Prim_Result : Boolean;
8984 pragma Unreferenced (CW_Result);
8986 begin
8987 if not CW_Test_Only then
8988 Prim_Result :=
8989 Try_Primitive_Operation
8990 (Call_Node => New_Call_Node,
8991 Node_To_Replace => Node_To_Replace);
8992 end if;
8994 -- Check if there is a class-wide subprogram covering the
8995 -- primitive. This check must be done even if a candidate
8996 -- was found in order to report ambiguous calls.
8998 if not (Prim_Result) then
8999 CW_Result :=
9000 Try_Class_Wide_Operation
9001 (Call_Node => New_Call_Node,
9002 Node_To_Replace => Node_To_Replace);
9004 -- If we found a primitive we search for class-wide subprograms
9005 -- using a duplicate of the call node (done to avoid missing its
9006 -- decoration if there is no ambiguity).
9008 else
9009 CW_Result :=
9010 Try_Class_Wide_Operation
9011 (Call_Node => Dup_Call_Node,
9012 Node_To_Replace => Node_To_Replace);
9013 end if;
9014 end;
9015 end Try_One_Prefix_Interpretation;
9017 -----------------------------
9018 -- Try_Primitive_Operation --
9019 -----------------------------
9021 function Try_Primitive_Operation
9022 (Call_Node : Node_Id;
9023 Node_To_Replace : Node_Id) return Boolean
9025 Elmt : Elmt_Id;
9026 Prim_Op : Entity_Id;
9027 Matching_Op : Entity_Id := Empty;
9028 Prim_Op_Ref : Node_Id := Empty;
9030 Corr_Type : Entity_Id := Empty;
9031 -- If the prefix is a synchronized type, the controlling type of
9032 -- the primitive operation is the corresponding record type, else
9033 -- this is the object type itself.
9035 Success : Boolean := False;
9037 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
9038 -- For tagged types the candidate interpretations are found in
9039 -- the list of primitive operations of the type and its ancestors.
9040 -- For formal tagged types we have to find the operations declared
9041 -- in the same scope as the type (including in the generic formal
9042 -- part) because the type itself carries no primitive operations,
9043 -- except for formal derived types that inherit the operations of
9044 -- the parent and progenitors.
9046 -- If the context is a generic subprogram body, the generic formals
9047 -- are visible by name, but are not in the entity list of the
9048 -- subprogram because that list starts with the subprogram formals.
9049 -- We retrieve the candidate operations from the generic declaration.
9051 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id;
9052 -- Prefix notation can also be used on operations that are not
9053 -- primitives of the type, but are declared in the same immediate
9054 -- declarative part, which can only mean the corresponding package
9055 -- body (See RM 4.1.3 (9.2/3)). If we are in that body we extend the
9056 -- list of primitives with body operations with the same name that
9057 -- may be candidates, so that Try_Primitive_Operations can examine
9058 -- them if no real primitive is found.
9060 function Is_Private_Overriding (Op : Entity_Id) return Boolean;
9061 -- An operation that overrides an inherited operation in the private
9062 -- part of its package may be hidden, but if the inherited operation
9063 -- is visible a direct call to it will dispatch to the private one,
9064 -- which is therefore a valid candidate.
9066 function Names_Match
9067 (Obj_Type : Entity_Id;
9068 Prim_Op : Entity_Id;
9069 Subprog : Entity_Id) return Boolean;
9070 -- Return True if the names of Prim_Op and Subprog match. If Obj_Type
9071 -- is a protected type then compare also the original name of Prim_Op
9072 -- with the name of Subprog (since the expander may have added a
9073 -- prefix to its original name --see Exp_Ch9.Build_Selected_Name).
9075 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
9076 -- Verify that the prefix, dereferenced if need be, is a valid
9077 -- controlling argument in a call to Op. The remaining actuals
9078 -- are checked in the subsequent call to Analyze_One_Call.
9080 ------------------------------
9081 -- Collect_Generic_Type_Ops --
9082 ------------------------------
9084 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
9085 Bas : constant Entity_Id := Base_Type (T);
9086 Candidates : constant Elist_Id := New_Elmt_List;
9087 Subp : Entity_Id;
9088 Formal : Entity_Id;
9090 procedure Check_Candidate;
9091 -- The operation is a candidate if its first parameter is a
9092 -- controlling operand of the desired type.
9094 -----------------------
9095 -- Check_Candidate; --
9096 -----------------------
9098 procedure Check_Candidate is
9099 begin
9100 Formal := First_Formal (Subp);
9102 if Present (Formal)
9103 and then Is_Controlling_Formal (Formal)
9104 and then
9105 (Base_Type (Etype (Formal)) = Bas
9106 or else
9107 (Is_Access_Type (Etype (Formal))
9108 and then Designated_Type (Etype (Formal)) = Bas))
9109 then
9110 Append_Elmt (Subp, Candidates);
9111 end if;
9112 end Check_Candidate;
9114 -- Start of processing for Collect_Generic_Type_Ops
9116 begin
9117 if Is_Derived_Type (T) then
9118 return Primitive_Operations (T);
9120 elsif Ekind_In (Scope (T), E_Procedure, E_Function) then
9122 -- Scan the list of generic formals to find subprograms
9123 -- that may have a first controlling formal of the type.
9125 if Nkind (Unit_Declaration_Node (Scope (T))) =
9126 N_Generic_Subprogram_Declaration
9127 then
9128 declare
9129 Decl : Node_Id;
9131 begin
9132 Decl :=
9133 First (Generic_Formal_Declarations
9134 (Unit_Declaration_Node (Scope (T))));
9135 while Present (Decl) loop
9136 if Nkind (Decl) in N_Formal_Subprogram_Declaration then
9137 Subp := Defining_Entity (Decl);
9138 Check_Candidate;
9139 end if;
9141 Next (Decl);
9142 end loop;
9143 end;
9144 end if;
9145 return Candidates;
9147 else
9148 -- Scan the list of entities declared in the same scope as
9149 -- the type. In general this will be an open scope, given that
9150 -- the call we are analyzing can only appear within a generic
9151 -- declaration or body (either the one that declares T, or a
9152 -- child unit).
9154 -- For a subtype representing a generic actual type, go to the
9155 -- base type.
9157 if Is_Generic_Actual_Type (T) then
9158 Subp := First_Entity (Scope (Base_Type (T)));
9159 else
9160 Subp := First_Entity (Scope (T));
9161 end if;
9163 while Present (Subp) loop
9164 if Is_Overloadable (Subp) then
9165 Check_Candidate;
9166 end if;
9168 Next_Entity (Subp);
9169 end loop;
9171 return Candidates;
9172 end if;
9173 end Collect_Generic_Type_Ops;
9175 ----------------------------
9176 -- Extended_Primitive_Ops --
9177 ----------------------------
9179 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id is
9180 Type_Scope : constant Entity_Id := Scope (T);
9182 Body_Decls : List_Id;
9183 Op_Found : Boolean;
9184 Op : Entity_Id;
9185 Op_List : Elist_Id;
9187 begin
9188 Op_List := Primitive_Operations (T);
9190 if Ekind (Type_Scope) = E_Package
9191 and then In_Package_Body (Type_Scope)
9192 and then In_Open_Scopes (Type_Scope)
9193 then
9194 -- Retrieve list of declarations of package body.
9196 Body_Decls :=
9197 Declarations
9198 (Unit_Declaration_Node
9199 (Corresponding_Body
9200 (Unit_Declaration_Node (Type_Scope))));
9202 Op := Current_Entity (Subprog);
9203 Op_Found := False;
9204 while Present (Op) loop
9205 if Comes_From_Source (Op)
9206 and then Is_Overloadable (Op)
9208 -- Exclude overriding primitive operations of a type
9209 -- extension declared in the package body, to prevent
9210 -- duplicates in extended list.
9212 and then not Is_Primitive (Op)
9213 and then Is_List_Member (Unit_Declaration_Node (Op))
9214 and then List_Containing (Unit_Declaration_Node (Op)) =
9215 Body_Decls
9216 then
9217 if not Op_Found then
9219 -- Copy list of primitives so it is not affected for
9220 -- other uses.
9222 Op_List := New_Copy_Elist (Op_List);
9223 Op_Found := True;
9224 end if;
9226 Append_Elmt (Op, Op_List);
9227 end if;
9229 Op := Homonym (Op);
9230 end loop;
9231 end if;
9233 return Op_List;
9234 end Extended_Primitive_Ops;
9236 ---------------------------
9237 -- Is_Private_Overriding --
9238 ---------------------------
9240 function Is_Private_Overriding (Op : Entity_Id) return Boolean is
9241 Visible_Op : constant Entity_Id := Homonym (Op);
9243 begin
9244 return Present (Visible_Op)
9245 and then Scope (Op) = Scope (Visible_Op)
9246 and then not Comes_From_Source (Visible_Op)
9247 and then Alias (Visible_Op) = Op
9248 and then not Is_Hidden (Visible_Op);
9249 end Is_Private_Overriding;
9251 -----------------
9252 -- Names_Match --
9253 -----------------
9255 function Names_Match
9256 (Obj_Type : Entity_Id;
9257 Prim_Op : Entity_Id;
9258 Subprog : Entity_Id) return Boolean is
9259 begin
9260 -- Common case: exact match
9262 if Chars (Prim_Op) = Chars (Subprog) then
9263 return True;
9265 -- For protected type primitives the expander may have built the
9266 -- name of the dispatching primitive prepending the type name to
9267 -- avoid conflicts with the name of the protected subprogram (see
9268 -- Exp_Ch9.Build_Selected_Name).
9270 elsif Is_Protected_Type (Obj_Type) then
9271 return
9272 Present (Original_Protected_Subprogram (Prim_Op))
9273 and then Chars (Original_Protected_Subprogram (Prim_Op)) =
9274 Chars (Subprog);
9275 end if;
9277 return False;
9278 end Names_Match;
9280 -----------------------------
9281 -- Valid_First_Argument_Of --
9282 -----------------------------
9284 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
9285 Typ : Entity_Id := Etype (First_Formal (Op));
9287 begin
9288 if Is_Concurrent_Type (Typ)
9289 and then Present (Corresponding_Record_Type (Typ))
9290 then
9291 Typ := Corresponding_Record_Type (Typ);
9292 end if;
9294 -- Simple case. Object may be a subtype of the tagged type or may
9295 -- be the corresponding record of a synchronized type.
9297 return Obj_Type = Typ
9298 or else Base_Type (Obj_Type) = Typ
9299 or else Corr_Type = Typ
9301 -- Object may be of a derived type whose parent has unknown
9302 -- discriminants, in which case the type matches the underlying
9303 -- record view of its base.
9305 or else
9306 (Has_Unknown_Discriminants (Typ)
9307 and then Typ = Underlying_Record_View (Base_Type (Obj_Type)))
9309 -- Prefix can be dereferenced
9311 or else
9312 (Is_Access_Type (Corr_Type)
9313 and then Designated_Type (Corr_Type) = Typ)
9315 -- Formal is an access parameter, for which the object can
9316 -- provide an access.
9318 or else
9319 (Ekind (Typ) = E_Anonymous_Access_Type
9320 and then
9321 Base_Type (Designated_Type (Typ)) = Base_Type (Corr_Type));
9322 end Valid_First_Argument_Of;
9324 -- Start of processing for Try_Primitive_Operation
9326 begin
9327 -- Look for subprograms in the list of primitive operations. The name
9328 -- must be identical, and the kind of call indicates the expected
9329 -- kind of operation (function or procedure). If the type is a
9330 -- (tagged) synchronized type, the primitive ops are attached to the
9331 -- corresponding record (base) type.
9333 if Is_Concurrent_Type (Obj_Type) then
9334 if Present (Corresponding_Record_Type (Obj_Type)) then
9335 Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
9336 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
9337 else
9338 Corr_Type := Obj_Type;
9339 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
9340 end if;
9342 elsif not Is_Generic_Type (Obj_Type) then
9343 Corr_Type := Obj_Type;
9344 Elmt := First_Elmt (Extended_Primitive_Ops (Obj_Type));
9346 else
9347 Corr_Type := Obj_Type;
9348 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
9349 end if;
9351 while Present (Elmt) loop
9352 Prim_Op := Node (Elmt);
9354 if Names_Match (Obj_Type, Prim_Op, Subprog)
9355 and then Present (First_Formal (Prim_Op))
9356 and then Valid_First_Argument_Of (Prim_Op)
9357 and then
9358 (Nkind (Call_Node) = N_Function_Call)
9360 (Ekind (Prim_Op) = E_Function)
9361 then
9362 -- Ada 2005 (AI-251): If this primitive operation corresponds
9363 -- to an immediate ancestor interface there is no need to add
9364 -- it to the list of interpretations; the corresponding aliased
9365 -- primitive is also in this list of primitive operations and
9366 -- will be used instead.
9368 if (Present (Interface_Alias (Prim_Op))
9369 and then Is_Ancestor (Find_Dispatching_Type
9370 (Alias (Prim_Op)), Corr_Type))
9372 -- Do not consider hidden primitives unless the type is in an
9373 -- open scope or we are within an instance, where visibility
9374 -- is known to be correct, or else if this is an overriding
9375 -- operation in the private part for an inherited operation.
9377 or else (Is_Hidden (Prim_Op)
9378 and then not Is_Immediately_Visible (Obj_Type)
9379 and then not In_Instance
9380 and then not Is_Private_Overriding (Prim_Op))
9381 then
9382 goto Continue;
9383 end if;
9385 Set_Etype (Call_Node, Any_Type);
9386 Set_Is_Overloaded (Call_Node, False);
9388 if No (Matching_Op) then
9389 Prim_Op_Ref := New_Occurrence_Of (Prim_Op, Sloc (Subprog));
9390 Candidate := Prim_Op;
9392 Set_Parent (Call_Node, Parent (Node_To_Replace));
9394 Set_Name (Call_Node, Prim_Op_Ref);
9395 Success := False;
9397 Analyze_One_Call
9398 (N => Call_Node,
9399 Nam => Prim_Op,
9400 Report => Report_Error,
9401 Success => Success,
9402 Skip_First => True);
9404 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
9406 -- More than one interpretation, collect for subsequent
9407 -- disambiguation. If this is a procedure call and there
9408 -- is another match, report ambiguity now.
9410 else
9411 Analyze_One_Call
9412 (N => Call_Node,
9413 Nam => Prim_Op,
9414 Report => Report_Error,
9415 Success => Success,
9416 Skip_First => True);
9418 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
9419 and then Nkind (Call_Node) /= N_Function_Call
9420 then
9421 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
9422 Report_Ambiguity (Matching_Op);
9423 Report_Ambiguity (Prim_Op);
9424 return True;
9425 end if;
9426 end if;
9427 end if;
9429 <<Continue>>
9430 Next_Elmt (Elmt);
9431 end loop;
9433 if Present (Matching_Op) then
9434 Set_Etype (Call_Node, Etype (Matching_Op));
9435 end if;
9437 return Present (Matching_Op);
9438 end Try_Primitive_Operation;
9440 -- Start of processing for Try_Object_Operation
9442 begin
9443 Analyze_Expression (Obj);
9445 -- Analyze the actuals if node is known to be a subprogram call
9447 if Is_Subprg_Call and then N = Name (Parent (N)) then
9448 Actual := First (Parameter_Associations (Parent (N)));
9449 while Present (Actual) loop
9450 Analyze_Expression (Actual);
9451 Next (Actual);
9452 end loop;
9453 end if;
9455 -- Build a subprogram call node, using a copy of Obj as its first
9456 -- actual. This is a placeholder, to be replaced by an explicit
9457 -- dereference when needed.
9459 Transform_Object_Operation
9460 (Call_Node => New_Call_Node,
9461 Node_To_Replace => Node_To_Replace);
9463 Set_Etype (New_Call_Node, Any_Type);
9464 Set_Etype (Subprog, Any_Type);
9465 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
9467 if not Is_Overloaded (Obj) then
9468 Try_One_Prefix_Interpretation (Obj_Type);
9470 else
9471 declare
9472 I : Interp_Index;
9473 It : Interp;
9474 begin
9475 Get_First_Interp (Obj, I, It);
9476 while Present (It.Nam) loop
9477 Try_One_Prefix_Interpretation (It.Typ);
9478 Get_Next_Interp (I, It);
9479 end loop;
9480 end;
9481 end if;
9483 if Etype (New_Call_Node) /= Any_Type then
9485 -- No need to complete the tree transformations if we are only
9486 -- searching for conflicting class-wide subprograms
9488 if CW_Test_Only then
9489 return False;
9490 else
9491 Complete_Object_Operation
9492 (Call_Node => New_Call_Node,
9493 Node_To_Replace => Node_To_Replace);
9494 return True;
9495 end if;
9497 elsif Present (Candidate) then
9499 -- The argument list is not type correct. Re-analyze with error
9500 -- reporting enabled, and use one of the possible candidates.
9501 -- In All_Errors_Mode, re-analyze all failed interpretations.
9503 if All_Errors_Mode then
9504 Report_Error := True;
9505 if Try_Primitive_Operation
9506 (Call_Node => New_Call_Node,
9507 Node_To_Replace => Node_To_Replace)
9509 or else
9510 Try_Class_Wide_Operation
9511 (Call_Node => New_Call_Node,
9512 Node_To_Replace => Node_To_Replace)
9513 then
9514 null;
9515 end if;
9517 else
9518 Analyze_One_Call
9519 (N => New_Call_Node,
9520 Nam => Candidate,
9521 Report => True,
9522 Success => Success,
9523 Skip_First => True);
9524 end if;
9526 -- No need for further errors
9528 return True;
9530 else
9531 -- There was no candidate operation, so report it as an error
9532 -- in the caller: Analyze_Selected_Component.
9534 return False;
9535 end if;
9536 end Try_Object_Operation;
9538 ---------
9539 -- wpo --
9540 ---------
9542 procedure wpo (T : Entity_Id) is
9543 Op : Entity_Id;
9544 E : Elmt_Id;
9546 begin
9547 if not Is_Tagged_Type (T) then
9548 return;
9549 end if;
9551 E := First_Elmt (Primitive_Operations (Base_Type (T)));
9552 while Present (E) loop
9553 Op := Node (E);
9554 Write_Int (Int (Op));
9555 Write_Str (" === ");
9556 Write_Name (Chars (Op));
9557 Write_Str (" in ");
9558 Write_Name (Chars (Scope (Op)));
9559 Next_Elmt (E);
9560 Write_Eol;
9561 end loop;
9562 end wpo;
9564 end Sem_Ch4;