]> gcc.gnu.org Git - gcc.git/blob - gcc/ada/sem_ch4.adb
[Ada] Declare expressions
[gcc.git] / gcc / ada / sem_ch4.adb
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-2020, 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 ------------------------------------------------------------------------------
25
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Util; use Exp_Util;
33 with Itypes; use Itypes;
34 with Lib; use Lib;
35 with Lib.Xref; use Lib.Xref;
36 with Namet; use Namet;
37 with Namet.Sp; use Namet.Sp;
38 with Nlists; use Nlists;
39 with Nmake; use Nmake;
40 with Opt; use Opt;
41 with Output; use Output;
42 with Restrict; use Restrict;
43 with Rident; use Rident;
44 with Sem; use Sem;
45 with Sem_Aux; use Sem_Aux;
46 with Sem_Case; use Sem_Case;
47 with Sem_Cat; use Sem_Cat;
48 with Sem_Ch3; use Sem_Ch3;
49 with Sem_Ch6; use Sem_Ch6;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Dim; use Sem_Dim;
52 with Sem_Disp; use Sem_Disp;
53 with Sem_Dist; use Sem_Dist;
54 with Sem_Eval; use Sem_Eval;
55 with Sem_Res; use Sem_Res;
56 with Sem_Type; use Sem_Type;
57 with Sem_Util; use Sem_Util;
58 with Sem_Warn; use Sem_Warn;
59 with Stand; use Stand;
60 with Sinfo; use Sinfo;
61 with Snames; use Snames;
62 with Tbuild; use Tbuild;
63 with Uintp; use Uintp;
64
65 package body Sem_Ch4 is
66
67 -- Tables which speed up the identification of dangerous calls to Ada 2012
68 -- functions with writable actuals (AI05-0144).
69
70 -- The following table enumerates the Ada constructs which may evaluate in
71 -- arbitrary order. It does not cover all the language constructs which can
72 -- be evaluated in arbitrary order but the subset needed for AI05-0144.
73
74 Has_Arbitrary_Evaluation_Order : constant array (Node_Kind) of Boolean :=
75 (N_Aggregate => True,
76 N_Assignment_Statement => True,
77 N_Entry_Call_Statement => True,
78 N_Extension_Aggregate => True,
79 N_Full_Type_Declaration => True,
80 N_Indexed_Component => True,
81 N_Object_Declaration => True,
82 N_Pragma => True,
83 N_Range => True,
84 N_Slice => True,
85 N_Array_Type_Definition => True,
86 N_Membership_Test => True,
87 N_Binary_Op => True,
88 N_Subprogram_Call => True,
89 others => False);
90
91 -- The following table enumerates the nodes on which we stop climbing when
92 -- locating the outermost Ada construct that can be evaluated in arbitrary
93 -- order.
94
95 Stop_Subtree_Climbing : constant array (Node_Kind) of Boolean :=
96 (N_Aggregate => True,
97 N_Assignment_Statement => True,
98 N_Entry_Call_Statement => True,
99 N_Extended_Return_Statement => True,
100 N_Extension_Aggregate => True,
101 N_Full_Type_Declaration => True,
102 N_Object_Declaration => True,
103 N_Object_Renaming_Declaration => True,
104 N_Package_Specification => True,
105 N_Pragma => True,
106 N_Procedure_Call_Statement => True,
107 N_Simple_Return_Statement => True,
108 N_Has_Condition => True,
109 others => False);
110
111 -----------------------
112 -- Local Subprograms --
113 -----------------------
114
115 procedure Analyze_Concatenation_Rest (N : Node_Id);
116 -- Does the "rest" of the work of Analyze_Concatenation, after the left
117 -- operand has been analyzed. See Analyze_Concatenation for details.
118
119 procedure Analyze_Expression (N : Node_Id);
120 -- For expressions that are not names, this is just a call to analyze. If
121 -- the expression is a name, it may be a call to a parameterless function,
122 -- and if so must be converted into an explicit call node and analyzed as
123 -- such. This deproceduring must be done during the first pass of overload
124 -- resolution, because otherwise a procedure call with overloaded actuals
125 -- may fail to resolve.
126
127 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
128 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call is an
129 -- operator name or an expanded name whose selector is an operator name,
130 -- and one possible interpretation is as a predefined operator.
131
132 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
133 -- If the prefix of a selected_component is overloaded, the proper
134 -- interpretation that yields a record type with the proper selector
135 -- name must be selected.
136
137 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
138 -- Procedure to analyze a user defined binary operator, which is resolved
139 -- like a function, but instead of a list of actuals it is presented
140 -- with the left and right operands of an operator node.
141
142 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
143 -- Procedure to analyze a user defined unary operator, which is resolved
144 -- like a function, but instead of a list of actuals, it is presented with
145 -- the operand of the operator node.
146
147 procedure Ambiguous_Operands (N : Node_Id);
148 -- For equality, membership, and comparison operators with overloaded
149 -- arguments, list possible interpretations.
150
151 procedure Analyze_One_Call
152 (N : Node_Id;
153 Nam : Entity_Id;
154 Report : Boolean;
155 Success : out Boolean;
156 Skip_First : Boolean := False);
157 -- Check one interpretation of an overloaded subprogram name for
158 -- compatibility with the types of the actuals in a call. If there is a
159 -- single interpretation which does not match, post error if Report is
160 -- set to True.
161 --
162 -- Nam is the entity that provides the formals against which the actuals
163 -- are checked. Nam is either the name of a subprogram, or the internal
164 -- subprogram type constructed for an access_to_subprogram. If the actuals
165 -- are compatible with Nam, then Nam is added to the list of candidate
166 -- interpretations for N, and Success is set to True.
167 --
168 -- The flag Skip_First is used when analyzing a call that was rewritten
169 -- from object notation. In this case the first actual may have to receive
170 -- an explicit dereference, depending on the first formal of the operation
171 -- being called. The caller will have verified that the object is legal
172 -- for the call. If the remaining parameters match, the first parameter
173 -- will rewritten as a dereference if needed, prior to completing analysis.
174
175 procedure Check_Misspelled_Selector
176 (Prefix : Entity_Id;
177 Sel : Node_Id);
178 -- Give possible misspelling message if Sel seems likely to be a mis-
179 -- spelling of one of the selectors of the Prefix. This is called by
180 -- Analyze_Selected_Component after producing an invalid selector error
181 -- message.
182
183 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
184 -- Verify that type T is declared in scope S. Used to find interpretations
185 -- for operators given by expanded names. This is abstracted as a separate
186 -- function to handle extensions to System, where S is System, but T is
187 -- declared in the extension.
188
189 procedure Find_Arithmetic_Types
190 (L, R : Node_Id;
191 Op_Id : Entity_Id;
192 N : Node_Id);
193 -- L and R are the operands of an arithmetic operator. Find consistent
194 -- pairs of interpretations for L and R that have a numeric type consistent
195 -- with the semantics of the operator.
196
197 procedure Find_Comparison_Types
198 (L, R : Node_Id;
199 Op_Id : Entity_Id;
200 N : Node_Id);
201 -- L and R are operands of a comparison operator. Find consistent pairs of
202 -- interpretations for L and R.
203
204 procedure Find_Concatenation_Types
205 (L, R : Node_Id;
206 Op_Id : Entity_Id;
207 N : Node_Id);
208 -- For the four varieties of concatenation
209
210 procedure Find_Equality_Types
211 (L, R : Node_Id;
212 Op_Id : Entity_Id;
213 N : Node_Id);
214 -- Ditto for equality operators
215
216 procedure Find_Boolean_Types
217 (L, R : Node_Id;
218 Op_Id : Entity_Id;
219 N : Node_Id);
220 -- Ditto for binary logical operations
221
222 procedure Find_Negation_Types
223 (R : Node_Id;
224 Op_Id : Entity_Id;
225 N : Node_Id);
226 -- Find consistent interpretation for operand of negation operator
227
228 procedure Find_Non_Universal_Interpretations
229 (N : Node_Id;
230 R : Node_Id;
231 Op_Id : Entity_Id;
232 T1 : Entity_Id);
233 -- For equality and comparison operators, the result is always boolean, and
234 -- the legality of the operation is determined from the visibility of the
235 -- operand types. If one of the operands has a universal interpretation,
236 -- the legality check uses some compatible non-universal interpretation of
237 -- the other operand. N can be an operator node, or a function call whose
238 -- name is an operator designator. Any_Access, which is the initial type of
239 -- the literal NULL, is a universal type for the purpose of this routine.
240
241 function Find_Primitive_Operation (N : Node_Id) return Boolean;
242 -- Find candidate interpretations for the name Obj.Proc when it appears in
243 -- a subprogram renaming declaration.
244
245 procedure Find_Unary_Types
246 (R : Node_Id;
247 Op_Id : Entity_Id;
248 N : Node_Id);
249 -- Unary arithmetic types: plus, minus, abs
250
251 procedure Check_Arithmetic_Pair
252 (T1, T2 : Entity_Id;
253 Op_Id : Entity_Id;
254 N : Node_Id);
255 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid types
256 -- for left and right operand. Determine whether they constitute a valid
257 -- pair for the given operator, and record the corresponding interpretation
258 -- of the operator node. The node N may be an operator node (the usual
259 -- case) or a function call whose prefix is an operator designator. In
260 -- both cases Op_Id is the operator name itself.
261
262 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
263 -- Give detailed information on overloaded call where none of the
264 -- interpretations match. N is the call node, Nam the designator for
265 -- the overloaded entity being called.
266
267 function Junk_Operand (N : Node_Id) return Boolean;
268 -- Test for an operand that is an inappropriate entity (e.g. a package
269 -- name or a label). If so, issue an error message and return True. If
270 -- the operand is not an inappropriate entity kind, return False.
271
272 procedure Operator_Check (N : Node_Id);
273 -- Verify that an operator has received some valid interpretation. If none
274 -- was found, determine whether a use clause would make the operation
275 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
276 -- every type compatible with the operator, even if the operator for the
277 -- type is not directly visible. The routine uses this type to emit a more
278 -- informative message.
279
280 procedure Remove_Abstract_Operations (N : Node_Id);
281 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
282 -- operation is not a candidate interpretation.
283
284 function Try_Container_Indexing
285 (N : Node_Id;
286 Prefix : Node_Id;
287 Exprs : List_Id) return Boolean;
288 -- AI05-0139: Generalized indexing to support iterators over containers
289
290 function Try_Indexed_Call
291 (N : Node_Id;
292 Nam : Entity_Id;
293 Typ : Entity_Id;
294 Skip_First : Boolean) return Boolean;
295 -- If a function has defaults for all its actuals, a call to it may in fact
296 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
297 -- interpretation as an indexing, prior to analysis as a call. If both are
298 -- possible, the node is overloaded with both interpretations (same symbol
299 -- but two different types). If the call is written in prefix form, the
300 -- prefix becomes the first parameter in the call, and only the remaining
301 -- actuals must be checked for the presence of defaults.
302
303 function Try_Indirect_Call
304 (N : Node_Id;
305 Nam : Entity_Id;
306 Typ : Entity_Id) return Boolean;
307 -- Similarly, a function F that needs no actuals can return an access to a
308 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
309 -- the call may be overloaded with both interpretations.
310
311 procedure wpo (T : Entity_Id);
312 pragma Warnings (Off, wpo);
313 -- Used for debugging: obtain list of primitive operations even if
314 -- type is not frozen and dispatch table is not built yet.
315
316 ------------------------
317 -- Ambiguous_Operands --
318 ------------------------
319
320 procedure Ambiguous_Operands (N : Node_Id) is
321 procedure List_Operand_Interps (Opnd : Node_Id);
322
323 --------------------------
324 -- List_Operand_Interps --
325 --------------------------
326
327 procedure List_Operand_Interps (Opnd : Node_Id) is
328 Nam : Node_Id := Empty;
329 Err : Node_Id := N;
330
331 begin
332 if Is_Overloaded (Opnd) then
333 if Nkind (Opnd) in N_Op then
334 Nam := Opnd;
335
336 elsif Nkind (Opnd) = N_Function_Call then
337 Nam := Name (Opnd);
338
339 elsif Ada_Version >= Ada_2012 then
340 declare
341 It : Interp;
342 I : Interp_Index;
343
344 begin
345 Get_First_Interp (Opnd, I, It);
346 while Present (It.Nam) loop
347 if Has_Implicit_Dereference (It.Typ) then
348 Error_Msg_N
349 ("can be interpreted as implicit dereference", Opnd);
350 return;
351 end if;
352
353 Get_Next_Interp (I, It);
354 end loop;
355 end;
356
357 return;
358 end if;
359
360 else
361 return;
362 end if;
363
364 if Opnd = Left_Opnd (N) then
365 Error_Msg_N
366 ("\left operand has the following interpretations", N);
367 else
368 Error_Msg_N
369 ("\right operand has the following interpretations", N);
370 Err := Opnd;
371 end if;
372
373 List_Interps (Nam, Err);
374 end List_Operand_Interps;
375
376 -- Start of processing for Ambiguous_Operands
377
378 begin
379 if Nkind (N) in N_Membership_Test then
380 Error_Msg_N ("ambiguous operands for membership", N);
381
382 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
383 Error_Msg_N ("ambiguous operands for equality", N);
384
385 else
386 Error_Msg_N ("ambiguous operands for comparison", N);
387 end if;
388
389 if All_Errors_Mode then
390 List_Operand_Interps (Left_Opnd (N));
391 List_Operand_Interps (Right_Opnd (N));
392 else
393 Error_Msg_N ("\use -gnatf switch for details", N);
394 end if;
395 end Ambiguous_Operands;
396
397 -----------------------
398 -- Analyze_Aggregate --
399 -----------------------
400
401 -- Most of the analysis of Aggregates requires that the type be known, and
402 -- is therefore put off until resolution of the context. Delta aggregates
403 -- have a base component that determines the enclosing aggregate type so
404 -- its type can be ascertained earlier. This also allows delta aggregates
405 -- to appear in the context of a record type with a private extension, as
406 -- per the latest update of AI12-0127.
407
408 procedure Analyze_Aggregate (N : Node_Id) is
409 begin
410 if No (Etype (N)) then
411 if Nkind (N) = N_Delta_Aggregate then
412 declare
413 Base : constant Node_Id := Expression (N);
414
415 I : Interp_Index;
416 It : Interp;
417
418 begin
419 Analyze (Base);
420
421 -- If the base is overloaded, propagate interpretations to the
422 -- enclosing aggregate.
423
424 if Is_Overloaded (Base) then
425 Get_First_Interp (Base, I, It);
426 Set_Etype (N, Any_Type);
427
428 while Present (It.Nam) loop
429 Add_One_Interp (N, It.Typ, It.Typ);
430 Get_Next_Interp (I, It);
431 end loop;
432
433 else
434 Set_Etype (N, Etype (Base));
435 end if;
436 end;
437
438 else
439 Set_Etype (N, Any_Composite);
440 end if;
441 end if;
442 end Analyze_Aggregate;
443
444 -----------------------
445 -- Analyze_Allocator --
446 -----------------------
447
448 procedure Analyze_Allocator (N : Node_Id) is
449 Loc : constant Source_Ptr := Sloc (N);
450 Sav_Errs : constant Nat := Serious_Errors_Detected;
451 E : Node_Id := Expression (N);
452 Acc_Type : Entity_Id;
453 Type_Id : Entity_Id;
454 P : Node_Id;
455 C : Node_Id;
456 Onode : Node_Id;
457
458 begin
459 -- Deal with allocator restrictions
460
461 -- In accordance with H.4(7), the No_Allocators restriction only applies
462 -- to user-written allocators. The same consideration applies to the
463 -- No_Standard_Allocators_Before_Elaboration restriction.
464
465 if Comes_From_Source (N) then
466 Check_Restriction (No_Allocators, N);
467
468 -- Processing for No_Standard_Allocators_After_Elaboration, loop to
469 -- look at enclosing context, checking task/main subprogram case.
470
471 C := N;
472 P := Parent (C);
473 while Present (P) loop
474
475 -- For the task case we need a handled sequence of statements,
476 -- where the occurrence of the allocator is within the statements
477 -- and the parent is a task body
478
479 if Nkind (P) = N_Handled_Sequence_Of_Statements
480 and then Is_List_Member (C)
481 and then List_Containing (C) = Statements (P)
482 then
483 Onode := Original_Node (Parent (P));
484
485 -- Check for allocator within task body, this is a definite
486 -- violation of No_Allocators_After_Elaboration we can detect
487 -- at compile time.
488
489 if Nkind (Onode) = N_Task_Body then
490 Check_Restriction
491 (No_Standard_Allocators_After_Elaboration, N);
492 exit;
493 end if;
494 end if;
495
496 -- The other case is appearance in a subprogram body. This is
497 -- a violation if this is a library level subprogram with no
498 -- parameters. Note that this is now a static error even if the
499 -- subprogram is not the main program (this is a change, in an
500 -- earlier version only the main program was affected, and the
501 -- check had to be done in the binder.
502
503 if Nkind (P) = N_Subprogram_Body
504 and then Nkind (Parent (P)) = N_Compilation_Unit
505 and then No (Parameter_Specifications (Specification (P)))
506 then
507 Check_Restriction
508 (No_Standard_Allocators_After_Elaboration, N);
509 end if;
510
511 C := P;
512 P := Parent (C);
513 end loop;
514 end if;
515
516 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
517 -- any. The expected type for the name is any type. A non-overloading
518 -- rule then requires it to be of a type descended from
519 -- System.Storage_Pools.Subpools.Subpool_Handle.
520
521 -- This isn't exactly what the AI says, but it seems to be the right
522 -- rule. The AI should be fixed.???
523
524 declare
525 Subpool : constant Node_Id := Subpool_Handle_Name (N);
526
527 begin
528 if Present (Subpool) then
529 Analyze (Subpool);
530
531 if Is_Overloaded (Subpool) then
532 Error_Msg_N ("ambiguous subpool handle", Subpool);
533 end if;
534
535 -- Check that Etype (Subpool) is descended from Subpool_Handle
536
537 Resolve (Subpool);
538 end if;
539 end;
540
541 -- Analyze the qualified expression or subtype indication
542
543 if Nkind (E) = N_Qualified_Expression then
544 Acc_Type := Create_Itype (E_Allocator_Type, N);
545 Set_Etype (Acc_Type, Acc_Type);
546 Find_Type (Subtype_Mark (E));
547
548 -- Analyze the qualified expression, and apply the name resolution
549 -- rule given in 4.7(3).
550
551 Analyze (E);
552 Type_Id := Etype (E);
553 Set_Directly_Designated_Type (Acc_Type, Type_Id);
554
555 -- A qualified expression requires an exact match of the type,
556 -- class-wide matching is not allowed.
557
558 -- if Is_Class_Wide_Type (Type_Id)
559 -- and then Base_Type
560 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
561 -- then
562 -- Wrong_Type (Expression (E), Type_Id);
563 -- end if;
564
565 -- We don't analyze the qualified expression itself because it's
566 -- part of the allocator. It is fully analyzed and resolved when
567 -- the allocator is resolved with the context type.
568
569 Set_Etype (E, Type_Id);
570
571 -- Case where allocator has a subtype indication
572
573 else
574 declare
575 Def_Id : Entity_Id;
576 Base_Typ : Entity_Id;
577
578 begin
579 -- If the allocator includes a N_Subtype_Indication then a
580 -- constraint is present, otherwise the node is a subtype mark.
581 -- Introduce an explicit subtype declaration into the tree
582 -- defining some anonymous subtype and rewrite the allocator to
583 -- use this subtype rather than the subtype indication.
584
585 -- It is important to introduce the explicit subtype declaration
586 -- so that the bounds of the subtype indication are attached to
587 -- the tree in case the allocator is inside a generic unit.
588
589 -- Finally, if there is no subtype indication and the type is
590 -- a tagged unconstrained type with discriminants, the designated
591 -- object is constrained by their default values, and it is
592 -- simplest to introduce an explicit constraint now. In some cases
593 -- this is done during expansion, but freeze actions are certain
594 -- to be emitted in the proper order if constraint is explicit.
595
596 if Is_Entity_Name (E) and then Expander_Active then
597 Find_Type (E);
598 Type_Id := Entity (E);
599
600 if Is_Tagged_Type (Type_Id)
601 and then Has_Discriminants (Type_Id)
602 and then not Is_Constrained (Type_Id)
603 and then
604 Present
605 (Discriminant_Default_Value
606 (First_Discriminant (Type_Id)))
607 then
608 declare
609 Constr : constant List_Id := New_List;
610 Loc : constant Source_Ptr := Sloc (E);
611 Discr : Entity_Id := First_Discriminant (Type_Id);
612
613 begin
614 if Present (Discriminant_Default_Value (Discr)) then
615 while Present (Discr) loop
616 Append (Discriminant_Default_Value (Discr), Constr);
617 Next_Discriminant (Discr);
618 end loop;
619
620 Rewrite (E,
621 Make_Subtype_Indication (Loc,
622 Subtype_Mark => New_Occurrence_Of (Type_Id, Loc),
623 Constraint =>
624 Make_Index_Or_Discriminant_Constraint (Loc,
625 Constraints => Constr)));
626 end if;
627 end;
628 end if;
629 end if;
630
631 if Nkind (E) = N_Subtype_Indication then
632
633 -- A constraint is only allowed for a composite type in Ada
634 -- 95. In Ada 83, a constraint is also allowed for an
635 -- access-to-composite type, but the constraint is ignored.
636
637 Find_Type (Subtype_Mark (E));
638 Base_Typ := Entity (Subtype_Mark (E));
639
640 if Is_Elementary_Type (Base_Typ) then
641 if not (Ada_Version = Ada_83
642 and then Is_Access_Type (Base_Typ))
643 then
644 Error_Msg_N ("constraint not allowed here", E);
645
646 if Nkind (Constraint (E)) =
647 N_Index_Or_Discriminant_Constraint
648 then
649 Error_Msg_N -- CODEFIX
650 ("\if qualified expression was meant, " &
651 "use apostrophe", Constraint (E));
652 end if;
653 end if;
654
655 -- Get rid of the bogus constraint:
656
657 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
658 Analyze_Allocator (N);
659 return;
660 end if;
661
662 -- In GNATprove mode we need to preserve the link between
663 -- the original subtype indication and the anonymous subtype,
664 -- to extend proofs to constrained access types. We only do
665 -- that outside of spec expressions, otherwise the declaration
666 -- cannot be inserted and analyzed. In such a case, GNATprove
667 -- later rejects the allocator as it is not used here in
668 -- a non-interfering context (SPARK 4.8(2) and 7.1.3(10)).
669
670 if Expander_Active
671 or else (GNATprove_Mode and then not In_Spec_Expression)
672 then
673 Def_Id := Make_Temporary (Loc, 'S');
674
675 Insert_Action (E,
676 Make_Subtype_Declaration (Loc,
677 Defining_Identifier => Def_Id,
678 Subtype_Indication => Relocate_Node (E)));
679
680 if Sav_Errs /= Serious_Errors_Detected
681 and then Nkind (Constraint (E)) =
682 N_Index_Or_Discriminant_Constraint
683 then
684 Error_Msg_N -- CODEFIX
685 ("if qualified expression was meant, "
686 & "use apostrophe!", Constraint (E));
687 end if;
688
689 E := New_Occurrence_Of (Def_Id, Loc);
690 Rewrite (Expression (N), E);
691 end if;
692 end if;
693
694 Type_Id := Process_Subtype (E, N);
695 Acc_Type := Create_Itype (E_Allocator_Type, N);
696 Set_Etype (Acc_Type, Acc_Type);
697 Set_Directly_Designated_Type (Acc_Type, Type_Id);
698 Check_Fully_Declared (Type_Id, N);
699
700 -- Ada 2005 (AI-231): If the designated type is itself an access
701 -- type that excludes null, its default initialization will
702 -- be a null object, and we can insert an unconditional raise
703 -- before the allocator.
704
705 -- Ada 2012 (AI-104): A not null indication here is altogether
706 -- illegal.
707
708 if Can_Never_Be_Null (Type_Id) then
709 declare
710 Not_Null_Check : constant Node_Id :=
711 Make_Raise_Constraint_Error (Sloc (E),
712 Reason => CE_Null_Not_Allowed);
713
714 begin
715 if Expander_Active then
716 Insert_Action (N, Not_Null_Check);
717 Analyze (Not_Null_Check);
718
719 elsif Warn_On_Ada_2012_Compatibility then
720 Error_Msg_N
721 ("null value not allowed here in Ada 2012?y?", E);
722 end if;
723 end;
724 end if;
725
726 -- Check for missing initialization. Skip this check if we already
727 -- had errors on analyzing the allocator, since in that case these
728 -- are probably cascaded errors.
729
730 if not Is_Definite_Subtype (Type_Id)
731 and then Serious_Errors_Detected = Sav_Errs
732 then
733 -- The build-in-place machinery may produce an allocator when
734 -- the designated type is indefinite but the underlying type is
735 -- not. In this case the unknown discriminants are meaningless
736 -- and should not trigger error messages. Check the parent node
737 -- because the allocator is marked as coming from source.
738
739 if Present (Underlying_Type (Type_Id))
740 and then Is_Definite_Subtype (Underlying_Type (Type_Id))
741 and then not Comes_From_Source (Parent (N))
742 then
743 null;
744
745 -- An unusual case arises when the parent of a derived type is
746 -- a limited record extension with unknown discriminants, and
747 -- its full view has no discriminants.
748 --
749 -- A more general fix might be to create the proper underlying
750 -- type for such a derived type, but it is a record type with
751 -- no private attributes, so this required extending the
752 -- meaning of this attribute. ???
753
754 elsif Ekind (Etype (Type_Id)) = E_Record_Type_With_Private
755 and then Present (Underlying_Type (Etype (Type_Id)))
756 and then
757 not Has_Discriminants (Underlying_Type (Etype (Type_Id)))
758 and then not Comes_From_Source (Parent (N))
759 then
760 null;
761
762 elsif Is_Class_Wide_Type (Type_Id) then
763 Error_Msg_N
764 ("initialization required in class-wide allocation", N);
765
766 else
767 if Ada_Version < Ada_2005
768 and then Is_Limited_Type (Type_Id)
769 then
770 Error_Msg_N ("unconstrained allocation not allowed", N);
771
772 if Is_Array_Type (Type_Id) then
773 Error_Msg_N
774 ("\constraint with array bounds required", N);
775
776 elsif Has_Unknown_Discriminants (Type_Id) then
777 null;
778
779 else pragma Assert (Has_Discriminants (Type_Id));
780 Error_Msg_N
781 ("\constraint with discriminant values required", N);
782 end if;
783
784 -- Limited Ada 2005 and general nonlimited case.
785 -- This is an error, except in the case of an
786 -- uninitialized allocator that is generated
787 -- for a build-in-place function return of a
788 -- discriminated but compile-time-known-size
789 -- type.
790
791 else
792 if Original_Node (N) /= N
793 and then Nkind (Original_Node (N)) = N_Allocator
794 then
795 declare
796 Qual : constant Node_Id :=
797 Expression (Original_Node (N));
798 pragma Assert
799 (Nkind (Qual) = N_Qualified_Expression);
800 Call : constant Node_Id := Expression (Qual);
801 pragma Assert
802 (Is_Expanded_Build_In_Place_Call (Call));
803 begin
804 null;
805 end;
806
807 else
808 Error_Msg_N
809 ("uninitialized unconstrained allocation not "
810 & "allowed", N);
811
812 if Is_Array_Type (Type_Id) then
813 Error_Msg_N
814 ("\qualified expression or constraint with "
815 & "array bounds required", N);
816
817 elsif Has_Unknown_Discriminants (Type_Id) then
818 Error_Msg_N ("\qualified expression required", N);
819
820 else pragma Assert (Has_Discriminants (Type_Id));
821 Error_Msg_N
822 ("\qualified expression or constraint with "
823 & "discriminant values required", N);
824 end if;
825 end if;
826 end if;
827 end if;
828 end if;
829 end;
830 end if;
831
832 if Is_Abstract_Type (Type_Id) then
833 Error_Msg_N ("cannot allocate abstract object", E);
834 end if;
835
836 if Has_Task (Designated_Type (Acc_Type)) then
837 Check_Restriction (No_Tasking, N);
838 Check_Restriction (Max_Tasks, N);
839 Check_Restriction (No_Task_Allocators, N);
840 end if;
841
842 -- Check restriction against dynamically allocated protected objects
843
844 if Has_Protected (Designated_Type (Acc_Type)) then
845 Check_Restriction (No_Protected_Type_Allocators, N);
846 end if;
847
848 -- AI05-0013-1: No_Nested_Finalization forbids allocators if the access
849 -- type is nested, and the designated type needs finalization. The rule
850 -- is conservative in that class-wide types need finalization.
851
852 if Needs_Finalization (Designated_Type (Acc_Type))
853 and then not Is_Library_Level_Entity (Acc_Type)
854 then
855 Check_Restriction (No_Nested_Finalization, N);
856 end if;
857
858 -- Check that an allocator of a nested access type doesn't create a
859 -- protected object when restriction No_Local_Protected_Objects applies.
860
861 if Has_Protected (Designated_Type (Acc_Type))
862 and then not Is_Library_Level_Entity (Acc_Type)
863 then
864 Check_Restriction (No_Local_Protected_Objects, N);
865 end if;
866
867 -- Likewise for No_Local_Timing_Events
868
869 if Has_Timing_Event (Designated_Type (Acc_Type))
870 and then not Is_Library_Level_Entity (Acc_Type)
871 then
872 Check_Restriction (No_Local_Timing_Events, N);
873 end if;
874
875 -- If the No_Streams restriction is set, check that the type of the
876 -- object is not, and does not contain, any subtype derived from
877 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
878 -- Has_Stream just for efficiency reasons. There is no point in
879 -- spending time on a Has_Stream check if the restriction is not set.
880
881 if Restriction_Check_Required (No_Streams) then
882 if Has_Stream (Designated_Type (Acc_Type)) then
883 Check_Restriction (No_Streams, N);
884 end if;
885 end if;
886
887 Set_Etype (N, Acc_Type);
888
889 if not Is_Library_Level_Entity (Acc_Type) then
890 Check_Restriction (No_Local_Allocators, N);
891 end if;
892
893 if Serious_Errors_Detected > Sav_Errs then
894 Set_Error_Posted (N);
895 Set_Etype (N, Any_Type);
896 end if;
897 end Analyze_Allocator;
898
899 ---------------------------
900 -- Analyze_Arithmetic_Op --
901 ---------------------------
902
903 procedure Analyze_Arithmetic_Op (N : Node_Id) is
904 L : constant Node_Id := Left_Opnd (N);
905 R : constant Node_Id := Right_Opnd (N);
906 Op_Id : Entity_Id;
907
908 begin
909 Candidate_Type := Empty;
910 Analyze_Expression (L);
911 Analyze_Expression (R);
912
913 -- If the entity is already set, the node is the instantiation of a
914 -- generic node with a non-local reference, or was manufactured by a
915 -- call to Make_Op_xxx. In either case the entity is known to be valid,
916 -- and we do not need to collect interpretations, instead we just get
917 -- the single possible interpretation.
918
919 Op_Id := Entity (N);
920
921 if Present (Op_Id) then
922 if Ekind (Op_Id) = E_Operator then
923 Set_Etype (N, Any_Type);
924 Find_Arithmetic_Types (L, R, Op_Id, N);
925 else
926 Set_Etype (N, Any_Type);
927 Add_One_Interp (N, Op_Id, Etype (Op_Id));
928 end if;
929
930 -- Entity is not already set, so we do need to collect interpretations
931
932 else
933 Set_Etype (N, Any_Type);
934
935 Op_Id := Get_Name_Entity_Id (Chars (N));
936 while Present (Op_Id) loop
937 if Ekind (Op_Id) = E_Operator
938 and then Present (Next_Entity (First_Entity (Op_Id)))
939 then
940 Find_Arithmetic_Types (L, R, Op_Id, N);
941
942 -- The following may seem superfluous, because an operator cannot
943 -- be generic, but this ignores the cleverness of the author of
944 -- ACVC bc1013a.
945
946 elsif Is_Overloadable (Op_Id) then
947 Analyze_User_Defined_Binary_Op (N, Op_Id);
948 end if;
949
950 Op_Id := Homonym (Op_Id);
951 end loop;
952 end if;
953
954 Operator_Check (N);
955 Check_Function_Writable_Actuals (N);
956 end Analyze_Arithmetic_Op;
957
958 ------------------
959 -- Analyze_Call --
960 ------------------
961
962 -- Function, procedure, and entry calls are checked here. The Name in
963 -- the call may be overloaded. The actuals have been analyzed and may
964 -- themselves be overloaded. On exit from this procedure, the node N
965 -- may have zero, one or more interpretations. In the first case an
966 -- error message is produced. In the last case, the node is flagged
967 -- as overloaded and the interpretations are collected in All_Interp.
968
969 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
970 -- the type-checking is similar to that of other calls.
971
972 procedure Analyze_Call (N : Node_Id) is
973 Actuals : constant List_Id := Parameter_Associations (N);
974 Loc : constant Source_Ptr := Sloc (N);
975 Nam : Node_Id;
976 X : Interp_Index;
977 It : Interp;
978 Nam_Ent : Entity_Id;
979 Success : Boolean := False;
980
981 Deref : Boolean := False;
982 -- Flag indicates whether an interpretation of the prefix is a
983 -- parameterless call that returns an access_to_subprogram.
984
985 procedure Check_Writable_Actuals (N : Node_Id);
986 -- If the call has out or in-out parameters then mark its outermost
987 -- enclosing construct as a node on which the writable actuals check
988 -- must be performed.
989
990 function Name_Denotes_Function return Boolean;
991 -- If the type of the name is an access to subprogram, this may be the
992 -- type of a name, or the return type of the function being called. If
993 -- the name is not an entity then it can denote a protected function.
994 -- Until we distinguish Etype from Return_Type, we must use this routine
995 -- to resolve the meaning of the name in the call.
996
997 procedure No_Interpretation;
998 -- Output error message when no valid interpretation exists
999
1000 ----------------------------
1001 -- Check_Writable_Actuals --
1002 ----------------------------
1003
1004 -- The identification of conflicts in calls to functions with writable
1005 -- actuals is performed in the analysis phase of the front end to ensure
1006 -- that it reports exactly the same errors compiling with and without
1007 -- expansion enabled. It is performed in two stages:
1008
1009 -- 1) When a call to a function with out-mode parameters is found,
1010 -- we climb to the outermost enclosing construct that can be
1011 -- evaluated in arbitrary order and we mark it with the flag
1012 -- Check_Actuals.
1013
1014 -- 2) When the analysis of the marked node is complete, we traverse
1015 -- its decorated subtree searching for conflicts (see function
1016 -- Sem_Util.Check_Function_Writable_Actuals).
1017
1018 -- The unique exception to this general rule is for aggregates, since
1019 -- their analysis is performed by the front end in the resolution
1020 -- phase. For aggregates we do not climb to their enclosing construct:
1021 -- we restrict the analysis to the subexpressions initializing the
1022 -- aggregate components.
1023
1024 -- This implies that the analysis of expressions containing aggregates
1025 -- is not complete, since there may be conflicts on writable actuals
1026 -- involving subexpressions of the enclosing logical or arithmetic
1027 -- expressions. However, we cannot wait and perform the analysis when
1028 -- the whole subtree is resolved, since the subtrees may be transformed,
1029 -- thus adding extra complexity and computation cost to identify and
1030 -- report exactly the same errors compiling with and without expansion
1031 -- enabled.
1032
1033 procedure Check_Writable_Actuals (N : Node_Id) is
1034 begin
1035 if Comes_From_Source (N)
1036 and then Present (Get_Subprogram_Entity (N))
1037 and then Has_Out_Or_In_Out_Parameter (Get_Subprogram_Entity (N))
1038 then
1039 -- For procedures and entries there is no need to climb since
1040 -- we only need to check if the actuals of this call invoke
1041 -- functions whose out-mode parameters overlap.
1042
1043 if Nkind (N) /= N_Function_Call then
1044 Set_Check_Actuals (N);
1045
1046 -- For calls to functions we climb to the outermost enclosing
1047 -- construct where the out-mode actuals of this function may
1048 -- introduce conflicts.
1049
1050 else
1051 declare
1052 Outermost : Node_Id := Empty; -- init to avoid warning
1053 P : Node_Id := N;
1054
1055 begin
1056 while Present (P) loop
1057 -- For object declarations we can climb to the node from
1058 -- its object definition branch or from its initializing
1059 -- expression. We prefer to mark the child node as the
1060 -- outermost construct to avoid adding further complexity
1061 -- to the routine that will later take care of
1062 -- performing the writable actuals check.
1063
1064 if Has_Arbitrary_Evaluation_Order (Nkind (P))
1065 and then not Nkind_In (P, N_Assignment_Statement,
1066 N_Object_Declaration)
1067 then
1068 Outermost := P;
1069 end if;
1070
1071 -- Avoid climbing more than needed
1072
1073 exit when Stop_Subtree_Climbing (Nkind (P))
1074 or else (Nkind (P) = N_Range
1075 and then not
1076 Nkind_In (Parent (P), N_In, N_Not_In));
1077
1078 P := Parent (P);
1079 end loop;
1080
1081 Set_Check_Actuals (Outermost);
1082 end;
1083 end if;
1084 end if;
1085 end Check_Writable_Actuals;
1086
1087 ---------------------------
1088 -- Name_Denotes_Function --
1089 ---------------------------
1090
1091 function Name_Denotes_Function return Boolean is
1092 begin
1093 if Is_Entity_Name (Nam) then
1094 return Ekind (Entity (Nam)) = E_Function;
1095 elsif Nkind (Nam) = N_Selected_Component then
1096 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
1097 else
1098 return False;
1099 end if;
1100 end Name_Denotes_Function;
1101
1102 -----------------------
1103 -- No_Interpretation --
1104 -----------------------
1105
1106 procedure No_Interpretation is
1107 L : constant Boolean := Is_List_Member (N);
1108 K : constant Node_Kind := Nkind (Parent (N));
1109
1110 begin
1111 -- If the node is in a list whose parent is not an expression then it
1112 -- must be an attempted procedure call.
1113
1114 if L and then K not in N_Subexpr then
1115 if Ekind (Entity (Nam)) = E_Generic_Procedure then
1116 Error_Msg_NE
1117 ("must instantiate generic procedure& before call",
1118 Nam, Entity (Nam));
1119 else
1120 Error_Msg_N ("procedure or entry name expected", Nam);
1121 end if;
1122
1123 -- Check for tasking cases where only an entry call will do
1124
1125 elsif not L
1126 and then Nkind_In (K, N_Entry_Call_Alternative,
1127 N_Triggering_Alternative)
1128 then
1129 Error_Msg_N ("entry name expected", Nam);
1130
1131 -- Otherwise give general error message
1132
1133 else
1134 Error_Msg_N ("invalid prefix in call", Nam);
1135 end if;
1136 end No_Interpretation;
1137
1138 -- Start of processing for Analyze_Call
1139
1140 begin
1141 -- Initialize the type of the result of the call to the error type,
1142 -- which will be reset if the type is successfully resolved.
1143
1144 Set_Etype (N, Any_Type);
1145
1146 Nam := Name (N);
1147
1148 if not Is_Overloaded (Nam) then
1149
1150 -- Only one interpretation to check
1151
1152 if Ekind (Etype (Nam)) = E_Subprogram_Type then
1153 Nam_Ent := Etype (Nam);
1154
1155 -- If the prefix is an access_to_subprogram, this may be an indirect
1156 -- call. This is the case if the name in the call is not an entity
1157 -- name, or if it is a function name in the context of a procedure
1158 -- call. In this latter case, we have a call to a parameterless
1159 -- function that returns a pointer_to_procedure which is the entity
1160 -- being called. Finally, F (X) may be a call to a parameterless
1161 -- function that returns a pointer to a function with parameters.
1162 -- Note that if F returns an access-to-subprogram whose designated
1163 -- type is an array, F (X) cannot be interpreted as an indirect call
1164 -- through the result of the call to F.
1165
1166 elsif Is_Access_Subprogram_Type (Base_Type (Etype (Nam)))
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);
1180
1181 -- Selected component case. Simple entry or protected operation,
1182 -- where the entry name is given by the selector name.
1183
1184 elsif Nkind (Nam) = N_Selected_Component then
1185 Nam_Ent := Entity (Selector_Name (Nam));
1186
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;
1196
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.
1201
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;
1210
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;
1215
1216 else
1217 Nam_Ent := Entity (Nam);
1218
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.
1222
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)));
1232
1233 if Try_Container_Indexing (N, Nam, Expressions (N)) then
1234 return;
1235 else
1236 No_Interpretation;
1237 end if;
1238
1239 else
1240 No_Interpretation;
1241 end if;
1242
1243 return;
1244 end if;
1245 end if;
1246
1247 -- Operations generated for RACW stub types are called only through
1248 -- dispatching, and can never be the static interpretation of a call.
1249
1250 if Is_RACW_Stub_Type_Operation (Nam_Ent) then
1251 No_Interpretation;
1252 return;
1253 end if;
1254
1255 Analyze_One_Call (N, Nam_Ent, True, Success);
1256
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.
1261
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;
1270
1271 -- Overloaded call
1272
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.
1277
1278 if Nkind (Nam) = N_Selected_Component then
1279 Nam := Selector_Name (Nam);
1280 end if;
1281
1282 Get_First_Interp (Nam, X, It);
1283 while Present (It.Nam) loop
1284 Nam_Ent := It.Nam;
1285 Deref := False;
1286
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.
1295
1296 if Is_Access_Type (Nam_Ent) then
1297 Nam_Ent := Designated_Type (Nam_Ent);
1298
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));
1307
1308 if Is_Entity_Name (Nam) then
1309 Deref := True;
1310 end if;
1311 end if;
1312
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.
1316
1317 if Is_Rewrite_Substitution (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;
1328
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.
1335
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))));
1351
1352 Analyze (N);
1353 return;
1354
1355 else
1356 Set_Entity (Nam, It.Nam);
1357 Insert_Explicit_Dereference (Nam);
1358 Set_Etype (Nam, Nam_Ent);
1359 end if;
1360
1361 else
1362 Set_Etype (Nam, It.Typ);
1363 end if;
1364
1365 elsif Nkind_In (Name (N), N_Function_Call, N_Selected_Component)
1366 then
1367 Remove_Interp (X);
1368 end if;
1369
1370 Get_Next_Interp (X, It);
1371 end loop;
1372
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.
1376
1377 if Nkind (Nam) = N_Function_Call then
1378 Insert_Explicit_Dereference (Nam);
1379 end if;
1380
1381 if Etype (N) = Any_Type then
1382
1383 -- None of the interpretations is compatible with the actuals
1384
1385 Diagnose_Call (N, Nam);
1386
1387 -- Special checks for uninstantiated put routines
1388
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;
1397
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;
1404
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);
1409
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);
1414
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);
1419
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);
1424
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);
1429
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;
1437
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.
1443
1444 Set_Entity_With_Checks (Nam, Entity (Nam));
1445 Generate_Reference (Entity (Nam), Nam);
1446
1447 Set_Etype (Nam, Etype (Entity (Nam)));
1448 else
1449 Remove_Abstract_Operations (N);
1450 end if;
1451
1452 End_Interp_List;
1453 end if;
1454
1455 if Ada_Version >= Ada_2012 then
1456
1457 -- Check if the call contains a function with writable actuals
1458
1459 Check_Writable_Actuals (N);
1460
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.
1464
1465 Check_Function_Writable_Actuals (N);
1466
1467 -- The return type of the function may be incomplete. This can be
1468 -- the case if the type is a generic formal, or a limited view. It
1469 -- can also happen when the function declaration appears before the
1470 -- full view of the type (which is legal in Ada 2012) and the call
1471 -- appears in a different unit, in which case the incomplete view
1472 -- must be replaced with the full view (or the nonlimited view)
1473 -- to prevent subsequent type errors. Note that the usual install/
1474 -- removal of limited_with clauses is not sufficient to handle this
1475 -- case, because the limited view may have been captured in another
1476 -- compilation unit that defines the current function.
1477
1478 if Is_Incomplete_Type (Etype (N)) then
1479 if Present (Full_View (Etype (N))) then
1480 if Is_Entity_Name (Nam) then
1481 Set_Etype (Nam, Full_View (Etype (N)));
1482 Set_Etype (Entity (Nam), Full_View (Etype (N)));
1483 end if;
1484
1485 Set_Etype (N, Full_View (Etype (N)));
1486
1487 elsif From_Limited_With (Etype (N))
1488 and then Present (Non_Limited_View (Etype (N)))
1489 then
1490 Set_Etype (N, Non_Limited_View (Etype (N)));
1491
1492 -- If there is no completion for the type, this may be because
1493 -- there is only a limited view of it and there is nothing in
1494 -- the context of the current unit that has required a regular
1495 -- compilation of the unit containing the type. We recognize
1496 -- this unusual case by the fact that unit is not analyzed.
1497 -- Note that the call being analyzed is in a different unit from
1498 -- the function declaration, and nothing indicates that the type
1499 -- is a limited view.
1500
1501 elsif Ekind (Scope (Etype (N))) = E_Package
1502 and then Present (Limited_View (Scope (Etype (N))))
1503 and then not Analyzed (Unit_Declaration_Node (Scope (Etype (N))))
1504 then
1505 Error_Msg_NE
1506 ("cannot call function that returns limited view of}",
1507 N, Etype (N));
1508
1509 Error_Msg_NE
1510 ("\there must be a regular with_clause for package & in the "
1511 & "current unit, or in some unit in its context",
1512 N, Scope (Etype (N)));
1513
1514 Set_Etype (N, Any_Type);
1515 end if;
1516 end if;
1517 end if;
1518 end Analyze_Call;
1519
1520 -----------------------------
1521 -- Analyze_Case_Expression --
1522 -----------------------------
1523
1524 procedure Analyze_Case_Expression (N : Node_Id) is
1525 procedure Non_Static_Choice_Error (Choice : Node_Id);
1526 -- Error routine invoked by the generic instantiation below when
1527 -- the case expression has a non static choice.
1528
1529 package Case_Choices_Analysis is new
1530 Generic_Analyze_Choices
1531 (Process_Associated_Node => No_OP);
1532 use Case_Choices_Analysis;
1533
1534 package Case_Choices_Checking is new
1535 Generic_Check_Choices
1536 (Process_Empty_Choice => No_OP,
1537 Process_Non_Static_Choice => Non_Static_Choice_Error,
1538 Process_Associated_Node => No_OP);
1539 use Case_Choices_Checking;
1540
1541 -----------------------------
1542 -- Non_Static_Choice_Error --
1543 -----------------------------
1544
1545 procedure Non_Static_Choice_Error (Choice : Node_Id) is
1546 begin
1547 Flag_Non_Static_Expr
1548 ("choice given in case expression is not static!", Choice);
1549 end Non_Static_Choice_Error;
1550
1551 -- Local variables
1552
1553 Expr : constant Node_Id := Expression (N);
1554 Alt : Node_Id;
1555 Exp_Type : Entity_Id;
1556 Exp_Btype : Entity_Id;
1557
1558 FirstX : Node_Id := Empty;
1559 -- First expression in the case for which there is some type information
1560 -- available, i.e. it is not Any_Type, which can happen because of some
1561 -- error, or from the use of e.g. raise Constraint_Error.
1562
1563 Others_Present : Boolean;
1564 -- Indicates if Others was present
1565
1566 Wrong_Alt : Node_Id := Empty;
1567 -- For error reporting
1568
1569 -- Start of processing for Analyze_Case_Expression
1570
1571 begin
1572 if Comes_From_Source (N) then
1573 Check_Compiler_Unit ("case expression", N);
1574 end if;
1575
1576 Analyze_And_Resolve (Expr, Any_Discrete);
1577 Check_Unset_Reference (Expr);
1578 Exp_Type := Etype (Expr);
1579 Exp_Btype := Base_Type (Exp_Type);
1580
1581 Alt := First (Alternatives (N));
1582 while Present (Alt) loop
1583 if Error_Posted (Expression (Alt)) then
1584 return;
1585 end if;
1586
1587 Analyze (Expression (Alt));
1588
1589 if No (FirstX) and then Etype (Expression (Alt)) /= Any_Type then
1590 FirstX := Expression (Alt);
1591 end if;
1592
1593 Next (Alt);
1594 end loop;
1595
1596 -- Get our initial type from the first expression for which we got some
1597 -- useful type information from the expression.
1598
1599 if No (FirstX) then
1600 return;
1601 end if;
1602
1603 if not Is_Overloaded (FirstX) then
1604 Set_Etype (N, Etype (FirstX));
1605
1606 else
1607 declare
1608 I : Interp_Index;
1609 It : Interp;
1610
1611 begin
1612 Set_Etype (N, Any_Type);
1613
1614 Get_First_Interp (FirstX, I, It);
1615 while Present (It.Nam) loop
1616
1617 -- For each interpretation of the first expression, we only
1618 -- add the interpretation if every other expression in the
1619 -- case expression alternatives has a compatible type.
1620
1621 Alt := Next (First (Alternatives (N)));
1622 while Present (Alt) loop
1623 exit when not Has_Compatible_Type (Expression (Alt), It.Typ);
1624 Next (Alt);
1625 end loop;
1626
1627 if No (Alt) then
1628 Add_One_Interp (N, It.Typ, It.Typ);
1629 else
1630 Wrong_Alt := Alt;
1631 end if;
1632
1633 Get_Next_Interp (I, It);
1634 end loop;
1635 end;
1636 end if;
1637
1638 Exp_Btype := Base_Type (Exp_Type);
1639
1640 -- The expression must be of a discrete type which must be determinable
1641 -- independently of the context in which the expression occurs, but
1642 -- using the fact that the expression must be of a discrete type.
1643 -- Moreover, the type this expression must not be a character literal
1644 -- (which is always ambiguous).
1645
1646 -- If error already reported by Resolve, nothing more to do
1647
1648 if Exp_Btype = Any_Discrete or else Exp_Btype = Any_Type then
1649 return;
1650
1651 -- Special casee message for character literal
1652
1653 elsif Exp_Btype = Any_Character then
1654 Error_Msg_N
1655 ("character literal as case expression is ambiguous", Expr);
1656 return;
1657 end if;
1658
1659 if Etype (N) = Any_Type and then Present (Wrong_Alt) then
1660 Error_Msg_N
1661 ("type incompatible with that of previous alternatives",
1662 Expression (Wrong_Alt));
1663 return;
1664 end if;
1665
1666 -- If the case expression is a formal object of mode in out, then
1667 -- treat it as having a nonstatic subtype by forcing use of the base
1668 -- type (which has to get passed to Check_Case_Choices below). Also
1669 -- use base type when the case expression is parenthesized.
1670
1671 if Paren_Count (Expr) > 0
1672 or else (Is_Entity_Name (Expr)
1673 and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter)
1674 then
1675 Exp_Type := Exp_Btype;
1676 end if;
1677
1678 -- The case expression alternatives cover the range of a static subtype
1679 -- subject to aspect Static_Predicate. Do not check the choices when the
1680 -- case expression has not been fully analyzed yet because this may lead
1681 -- to bogus errors.
1682
1683 if Is_OK_Static_Subtype (Exp_Type)
1684 and then Has_Static_Predicate_Aspect (Exp_Type)
1685 and then In_Spec_Expression
1686 then
1687 null;
1688
1689 -- Call Analyze_Choices and Check_Choices to do the rest of the work
1690
1691 else
1692 Analyze_Choices (Alternatives (N), Exp_Type);
1693 Check_Choices (N, Alternatives (N), Exp_Type, Others_Present);
1694
1695 if Exp_Type = Universal_Integer and then not Others_Present then
1696 Error_Msg_N
1697 ("case on universal integer requires OTHERS choice", Expr);
1698 end if;
1699 end if;
1700 end Analyze_Case_Expression;
1701
1702 ---------------------------
1703 -- Analyze_Comparison_Op --
1704 ---------------------------
1705
1706 procedure Analyze_Comparison_Op (N : Node_Id) is
1707 L : constant Node_Id := Left_Opnd (N);
1708 R : constant Node_Id := Right_Opnd (N);
1709 Op_Id : Entity_Id := Entity (N);
1710
1711 begin
1712 Set_Etype (N, Any_Type);
1713 Candidate_Type := Empty;
1714
1715 Analyze_Expression (L);
1716 Analyze_Expression (R);
1717
1718 if Present (Op_Id) then
1719 if Ekind (Op_Id) = E_Operator then
1720 Find_Comparison_Types (L, R, Op_Id, N);
1721 else
1722 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1723 end if;
1724
1725 if Is_Overloaded (L) then
1726 Set_Etype (L, Intersect_Types (L, R));
1727 end if;
1728
1729 else
1730 Op_Id := Get_Name_Entity_Id (Chars (N));
1731 while Present (Op_Id) loop
1732 if Ekind (Op_Id) = E_Operator then
1733 Find_Comparison_Types (L, R, Op_Id, N);
1734 else
1735 Analyze_User_Defined_Binary_Op (N, Op_Id);
1736 end if;
1737
1738 Op_Id := Homonym (Op_Id);
1739 end loop;
1740 end if;
1741
1742 Operator_Check (N);
1743 Check_Function_Writable_Actuals (N);
1744 end Analyze_Comparison_Op;
1745
1746 ---------------------------
1747 -- Analyze_Concatenation --
1748 ---------------------------
1749
1750 procedure Analyze_Concatenation (N : Node_Id) is
1751
1752 -- We wish to avoid deep recursion, because concatenations are often
1753 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1754 -- operands nonrecursively until we find something that is not a
1755 -- concatenation (A in this case), or has already been analyzed. We
1756 -- analyze that, and then walk back up the tree following Parent
1757 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1758 -- work at each level. The Parent pointers allow us to avoid recursion,
1759 -- and thus avoid running out of memory.
1760
1761 NN : Node_Id := N;
1762 L : Node_Id;
1763
1764 begin
1765 Candidate_Type := Empty;
1766
1767 -- The following code is equivalent to:
1768
1769 -- Set_Etype (N, Any_Type);
1770 -- Analyze_Expression (Left_Opnd (N));
1771 -- Analyze_Concatenation_Rest (N);
1772
1773 -- where the Analyze_Expression call recurses back here if the left
1774 -- operand is a concatenation.
1775
1776 -- Walk down left operands
1777
1778 loop
1779 Set_Etype (NN, Any_Type);
1780 L := Left_Opnd (NN);
1781 exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
1782 NN := L;
1783 end loop;
1784
1785 -- Now (given the above example) NN is A&B and L is A
1786
1787 -- First analyze L ...
1788
1789 Analyze_Expression (L);
1790
1791 -- ... then walk NN back up until we reach N (where we started), calling
1792 -- Analyze_Concatenation_Rest along the way.
1793
1794 loop
1795 Analyze_Concatenation_Rest (NN);
1796 exit when NN = N;
1797 NN := Parent (NN);
1798 end loop;
1799 end Analyze_Concatenation;
1800
1801 --------------------------------
1802 -- Analyze_Concatenation_Rest --
1803 --------------------------------
1804
1805 -- If the only one-dimensional array type in scope is String,
1806 -- this is the resulting type of the operation. Otherwise there
1807 -- will be a concatenation operation defined for each user-defined
1808 -- one-dimensional array.
1809
1810 procedure Analyze_Concatenation_Rest (N : Node_Id) is
1811 L : constant Node_Id := Left_Opnd (N);
1812 R : constant Node_Id := Right_Opnd (N);
1813 Op_Id : Entity_Id := Entity (N);
1814 LT : Entity_Id;
1815 RT : Entity_Id;
1816
1817 begin
1818 Analyze_Expression (R);
1819
1820 -- If the entity is present, the node appears in an instance, and
1821 -- denotes a predefined concatenation operation. The resulting type is
1822 -- obtained from the arguments when possible. If the arguments are
1823 -- aggregates, the array type and the concatenation type must be
1824 -- visible.
1825
1826 if Present (Op_Id) then
1827 if Ekind (Op_Id) = E_Operator then
1828 LT := Base_Type (Etype (L));
1829 RT := Base_Type (Etype (R));
1830
1831 if Is_Array_Type (LT)
1832 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1833 then
1834 Add_One_Interp (N, Op_Id, LT);
1835
1836 elsif Is_Array_Type (RT)
1837 and then LT = Base_Type (Component_Type (RT))
1838 then
1839 Add_One_Interp (N, Op_Id, RT);
1840
1841 -- If one operand is a string type or a user-defined array type,
1842 -- and the other is a literal, result is of the specific type.
1843
1844 elsif
1845 (Root_Type (LT) = Standard_String
1846 or else Scope (LT) /= Standard_Standard)
1847 and then Etype (R) = Any_String
1848 then
1849 Add_One_Interp (N, Op_Id, LT);
1850
1851 elsif
1852 (Root_Type (RT) = Standard_String
1853 or else Scope (RT) /= Standard_Standard)
1854 and then Etype (L) = Any_String
1855 then
1856 Add_One_Interp (N, Op_Id, RT);
1857
1858 elsif not Is_Generic_Type (Etype (Op_Id)) then
1859 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1860
1861 else
1862 -- Type and its operations must be visible
1863
1864 Set_Entity (N, Empty);
1865 Analyze_Concatenation (N);
1866 end if;
1867
1868 else
1869 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1870 end if;
1871
1872 else
1873 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1874 while Present (Op_Id) loop
1875 if Ekind (Op_Id) = E_Operator then
1876
1877 -- Do not consider operators declared in dead code, they
1878 -- cannot be part of the resolution.
1879
1880 if Is_Eliminated (Op_Id) then
1881 null;
1882 else
1883 Find_Concatenation_Types (L, R, Op_Id, N);
1884 end if;
1885
1886 else
1887 Analyze_User_Defined_Binary_Op (N, Op_Id);
1888 end if;
1889
1890 Op_Id := Homonym (Op_Id);
1891 end loop;
1892 end if;
1893
1894 Operator_Check (N);
1895 end Analyze_Concatenation_Rest;
1896
1897 -------------------------
1898 -- Analyze_Equality_Op --
1899 -------------------------
1900
1901 procedure Analyze_Equality_Op (N : Node_Id) is
1902 Loc : constant Source_Ptr := Sloc (N);
1903 L : constant Node_Id := Left_Opnd (N);
1904 R : constant Node_Id := Right_Opnd (N);
1905 Op_Id : Entity_Id;
1906
1907 begin
1908 Set_Etype (N, Any_Type);
1909 Candidate_Type := Empty;
1910
1911 Analyze_Expression (L);
1912 Analyze_Expression (R);
1913
1914 -- If the entity is set, the node is a generic instance with a non-local
1915 -- reference to the predefined operator or to a user-defined function.
1916 -- It can also be an inequality that is expanded into the negation of a
1917 -- call to a user-defined equality operator.
1918
1919 -- For the predefined case, the result is Boolean, regardless of the
1920 -- type of the operands. The operands may even be limited, if they are
1921 -- generic actuals. If they are overloaded, label the left argument with
1922 -- the common type that must be present, or with the type of the formal
1923 -- of the user-defined function.
1924
1925 if Present (Entity (N)) then
1926 Op_Id := Entity (N);
1927
1928 if Ekind (Op_Id) = E_Operator then
1929 Add_One_Interp (N, Op_Id, Standard_Boolean);
1930 else
1931 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1932 end if;
1933
1934 if Is_Overloaded (L) then
1935 if Ekind (Op_Id) = E_Operator then
1936 Set_Etype (L, Intersect_Types (L, R));
1937 else
1938 Set_Etype (L, Etype (First_Formal (Op_Id)));
1939 end if;
1940 end if;
1941
1942 else
1943 Op_Id := Get_Name_Entity_Id (Chars (N));
1944 while Present (Op_Id) loop
1945 if Ekind (Op_Id) = E_Operator then
1946 Find_Equality_Types (L, R, Op_Id, N);
1947 else
1948 Analyze_User_Defined_Binary_Op (N, Op_Id);
1949 end if;
1950
1951 Op_Id := Homonym (Op_Id);
1952 end loop;
1953 end if;
1954
1955 -- If there was no match, and the operator is inequality, this may be
1956 -- a case where inequality has not been made explicit, as for tagged
1957 -- types. Analyze the node as the negation of an equality operation.
1958 -- This cannot be done earlier, because before analysis we cannot rule
1959 -- out the presence of an explicit inequality.
1960
1961 if Etype (N) = Any_Type
1962 and then Nkind (N) = N_Op_Ne
1963 then
1964 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1965 while Present (Op_Id) loop
1966 if Ekind (Op_Id) = E_Operator then
1967 Find_Equality_Types (L, R, Op_Id, N);
1968 else
1969 Analyze_User_Defined_Binary_Op (N, Op_Id);
1970 end if;
1971
1972 Op_Id := Homonym (Op_Id);
1973 end loop;
1974
1975 if Etype (N) /= Any_Type then
1976 Op_Id := Entity (N);
1977
1978 Rewrite (N,
1979 Make_Op_Not (Loc,
1980 Right_Opnd =>
1981 Make_Op_Eq (Loc,
1982 Left_Opnd => Left_Opnd (N),
1983 Right_Opnd => Right_Opnd (N))));
1984
1985 Set_Entity (Right_Opnd (N), Op_Id);
1986 Analyze (N);
1987 end if;
1988 end if;
1989
1990 Operator_Check (N);
1991 Check_Function_Writable_Actuals (N);
1992 end Analyze_Equality_Op;
1993
1994 ----------------------------------
1995 -- Analyze_Explicit_Dereference --
1996 ----------------------------------
1997
1998 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1999 Loc : constant Source_Ptr := Sloc (N);
2000 P : constant Node_Id := Prefix (N);
2001 T : Entity_Id;
2002 I : Interp_Index;
2003 It : Interp;
2004 New_N : Node_Id;
2005
2006 function Is_Function_Type return Boolean;
2007 -- Check whether node may be interpreted as an implicit function call
2008
2009 ----------------------
2010 -- Is_Function_Type --
2011 ----------------------
2012
2013 function Is_Function_Type return Boolean is
2014 I : Interp_Index;
2015 It : Interp;
2016
2017 begin
2018 if not Is_Overloaded (N) then
2019 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
2020 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
2021
2022 else
2023 Get_First_Interp (N, I, It);
2024 while Present (It.Nam) loop
2025 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
2026 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
2027 then
2028 return False;
2029 end if;
2030
2031 Get_Next_Interp (I, It);
2032 end loop;
2033
2034 return True;
2035 end if;
2036 end Is_Function_Type;
2037
2038 -- Start of processing for Analyze_Explicit_Dereference
2039
2040 begin
2041 -- In formal verification mode, keep track of all reads and writes
2042 -- through explicit dereferences.
2043
2044 if GNATprove_Mode then
2045 SPARK_Specific.Generate_Dereference (N);
2046 end if;
2047
2048 Analyze (P);
2049 Set_Etype (N, Any_Type);
2050
2051 -- Test for remote access to subprogram type, and if so return
2052 -- after rewriting the original tree.
2053
2054 if Remote_AST_E_Dereference (P) then
2055 return;
2056 end if;
2057
2058 -- Normal processing for other than remote access to subprogram type
2059
2060 if not Is_Overloaded (P) then
2061 if Is_Access_Type (Etype (P)) then
2062
2063 -- Set the Etype
2064
2065 declare
2066 DT : constant Entity_Id := Designated_Type (Etype (P));
2067
2068 begin
2069 -- An explicit dereference is a legal occurrence of an
2070 -- incomplete type imported through a limited_with clause, if
2071 -- the full view is visible, or if we are within an instance
2072 -- body, where the enclosing body has a regular with_clause
2073 -- on the unit.
2074
2075 if From_Limited_With (DT)
2076 and then not From_Limited_With (Scope (DT))
2077 and then
2078 (Is_Immediately_Visible (Scope (DT))
2079 or else
2080 (Is_Child_Unit (Scope (DT))
2081 and then Is_Visible_Lib_Unit (Scope (DT)))
2082 or else In_Instance_Body)
2083 then
2084 Set_Etype (N, Available_View (DT));
2085
2086 else
2087 Set_Etype (N, DT);
2088 end if;
2089 end;
2090
2091 elsif Etype (P) /= Any_Type then
2092 Error_Msg_N ("prefix of dereference must be an access type", N);
2093 return;
2094 end if;
2095
2096 else
2097 Get_First_Interp (P, I, It);
2098 while Present (It.Nam) loop
2099 T := It.Typ;
2100
2101 if Is_Access_Type (T) then
2102 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
2103 end if;
2104
2105 Get_Next_Interp (I, It);
2106 end loop;
2107
2108 -- Error if no interpretation of the prefix has an access type
2109
2110 if Etype (N) = Any_Type then
2111 Error_Msg_N
2112 ("access type required in prefix of explicit dereference", P);
2113 Set_Etype (N, Any_Type);
2114 return;
2115 end if;
2116 end if;
2117
2118 if Is_Function_Type
2119 and then Nkind (Parent (N)) /= N_Indexed_Component
2120
2121 and then (Nkind (Parent (N)) /= N_Function_Call
2122 or else N /= Name (Parent (N)))
2123
2124 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
2125 or else N /= Name (Parent (N)))
2126
2127 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
2128 and then (Nkind (Parent (N)) /= N_Attribute_Reference
2129 or else
2130 (Attribute_Name (Parent (N)) /= Name_Address
2131 and then
2132 Attribute_Name (Parent (N)) /= Name_Access))
2133 then
2134 -- Name is a function call with no actuals, in a context that
2135 -- requires deproceduring (including as an actual in an enclosing
2136 -- function or procedure call). There are some pathological cases
2137 -- where the prefix might include functions that return access to
2138 -- subprograms and others that return a regular type. Disambiguation
2139 -- of those has to take place in Resolve.
2140
2141 New_N :=
2142 Make_Function_Call (Loc,
2143 Name => Make_Explicit_Dereference (Loc, P),
2144 Parameter_Associations => New_List);
2145
2146 -- If the prefix is overloaded, remove operations that have formals,
2147 -- we know that this is a parameterless call.
2148
2149 if Is_Overloaded (P) then
2150 Get_First_Interp (P, I, It);
2151 while Present (It.Nam) loop
2152 T := It.Typ;
2153
2154 if No (First_Formal (Base_Type (Designated_Type (T)))) then
2155 Set_Etype (P, T);
2156 else
2157 Remove_Interp (I);
2158 end if;
2159
2160 Get_Next_Interp (I, It);
2161 end loop;
2162 end if;
2163
2164 Rewrite (N, New_N);
2165 Analyze (N);
2166
2167 elsif not Is_Function_Type
2168 and then Is_Overloaded (N)
2169 then
2170 -- The prefix may include access to subprograms and other access
2171 -- types. If the context selects the interpretation that is a
2172 -- function call (not a procedure call) we cannot rewrite the node
2173 -- yet, but we include the result of the call interpretation.
2174
2175 Get_First_Interp (N, I, It);
2176 while Present (It.Nam) loop
2177 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
2178 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
2179 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
2180 then
2181 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
2182 end if;
2183
2184 Get_Next_Interp (I, It);
2185 end loop;
2186 end if;
2187
2188 -- A value of remote access-to-class-wide must not be dereferenced
2189 -- (RM E.2.2(16)).
2190
2191 Validate_Remote_Access_To_Class_Wide_Type (N);
2192 end Analyze_Explicit_Dereference;
2193
2194 ------------------------
2195 -- Analyze_Expression --
2196 ------------------------
2197
2198 procedure Analyze_Expression (N : Node_Id) is
2199 begin
2200
2201 -- If the expression is an indexed component that will be rewritten
2202 -- as a container indexing, it has already been analyzed.
2203
2204 if Nkind (N) = N_Indexed_Component
2205 and then Present (Generalized_Indexing (N))
2206 then
2207 null;
2208
2209 else
2210 Analyze (N);
2211 Check_Parameterless_Call (N);
2212 end if;
2213 end Analyze_Expression;
2214
2215 -------------------------------------
2216 -- Analyze_Expression_With_Actions --
2217 -------------------------------------
2218
2219 -- Start of processing for Analyze_Quantified_Expression
2220
2221 procedure Analyze_Expression_With_Actions (N : Node_Id) is
2222
2223 procedure Check_Action_OK (A : Node_Id);
2224 -- Check that the action is something that is allows as a declare_item
2225 -- of a declare_expression, except the checks are suppressed for
2226 -- generated code.
2227
2228 procedure Check_Action_OK (A : Node_Id) is
2229 begin
2230 if not Comes_From_Source (N) or else not Comes_From_Source (A) then
2231 return; -- Allow anything in generated code
2232 end if;
2233
2234 case Nkind (A) is
2235 when N_Object_Declaration =>
2236 if Nkind (Object_Definition (A)) = N_Access_Definition then
2237 Error_Msg_N
2238 ("anonymous access type not allowed in declare_expression",
2239 Object_Definition (A));
2240 end if;
2241
2242 if Aliased_Present (A) then
2243 Error_Msg_N ("aliased not allowed in declare_expression", A);
2244 end if;
2245
2246 if Constant_Present (A)
2247 and then not Is_Limited_Type (Etype (Defining_Identifier (A)))
2248 then
2249 return; -- nonlimited constants are OK
2250 end if;
2251
2252 when N_Object_Renaming_Declaration =>
2253 if Present (Access_Definition (A)) then
2254 Error_Msg_N
2255 ("anonymous access type not allowed in declare_expression",
2256 Access_Definition (A));
2257 end if;
2258
2259 if not Is_Limited_Type (Etype (Defining_Identifier (A))) then
2260 return; -- ???For now; the RM rule is a bit more complicated
2261 end if;
2262
2263 when others =>
2264 null; -- Nothing else allowed, not even pragmas
2265 end case;
2266
2267 Error_Msg_N ("object renaming or constant declaration expected", A);
2268 end Check_Action_OK;
2269
2270 A : Node_Id;
2271 EWA_Scop : Entity_Id;
2272
2273 -- Start of processing for Analyze_Expression_With_Actions
2274
2275 begin
2276 -- Create a scope, which is needed to provide proper visibility of the
2277 -- declare_items.
2278
2279 EWA_Scop := New_Internal_Entity (E_Block, Current_Scope, Sloc (N), 'B');
2280 Set_Etype (EWA_Scop, Standard_Void_Type);
2281 Set_Scope (EWA_Scop, Current_Scope);
2282 Set_Parent (EWA_Scop, N);
2283 Push_Scope (EWA_Scop);
2284
2285 -- If this Expression_With_Actions node comes from source, then it
2286 -- represents a declare_expression; increment the counter to take note
2287 -- of that.
2288
2289 if Comes_From_Source (N) then
2290 In_Declare_Expr := In_Declare_Expr + 1;
2291 end if;
2292
2293 A := First (Actions (N));
2294 while Present (A) loop
2295 Analyze (A);
2296 Check_Action_OK (A);
2297 Next (A);
2298 end loop;
2299
2300 Analyze_Expression (Expression (N));
2301 Set_Etype (N, Etype (Expression (N)));
2302 End_Scope;
2303
2304 if Comes_From_Source (N) then
2305 In_Declare_Expr := In_Declare_Expr - 1;
2306 end if;
2307 end Analyze_Expression_With_Actions;
2308
2309 ---------------------------
2310 -- Analyze_If_Expression --
2311 ---------------------------
2312
2313 procedure Analyze_If_Expression (N : Node_Id) is
2314 Condition : constant Node_Id := First (Expressions (N));
2315 Then_Expr : Node_Id;
2316 Else_Expr : Node_Id;
2317
2318 begin
2319 -- Defend against error of missing expressions from previous error
2320
2321 if No (Condition) then
2322 Check_Error_Detected;
2323 return;
2324 end if;
2325
2326 Then_Expr := Next (Condition);
2327
2328 if No (Then_Expr) then
2329 Check_Error_Detected;
2330 return;
2331 end if;
2332
2333 Else_Expr := Next (Then_Expr);
2334
2335 if Comes_From_Source (N) then
2336 Check_Compiler_Unit ("if expression", N);
2337 end if;
2338
2339 -- Analyze and resolve the condition. We need to resolve this now so
2340 -- that it gets folded to True/False if possible, before we analyze
2341 -- the THEN/ELSE branches, because when analyzing these branches, we
2342 -- may call Is_Statically_Unevaluated, which expects the condition of
2343 -- an enclosing IF to have been analyze/resolved/evaluated.
2344
2345 Analyze_Expression (Condition);
2346 Resolve (Condition, Any_Boolean);
2347
2348 -- Analyze THEN expression and (if present) ELSE expression. For those
2349 -- we delay resolution in the normal manner, because of overloading etc.
2350
2351 Analyze_Expression (Then_Expr);
2352
2353 if Present (Else_Expr) then
2354 Analyze_Expression (Else_Expr);
2355 end if;
2356
2357 -- If then expression not overloaded, then that decides the type
2358
2359 if not Is_Overloaded (Then_Expr) then
2360 Set_Etype (N, Etype (Then_Expr));
2361
2362 -- Case where then expression is overloaded
2363
2364 else
2365 declare
2366 I : Interp_Index;
2367 It : Interp;
2368
2369 begin
2370 Set_Etype (N, Any_Type);
2371
2372 -- Loop through interpretations of Then_Expr
2373
2374 Get_First_Interp (Then_Expr, I, It);
2375 while Present (It.Nam) loop
2376
2377 -- Add possible interpretation of Then_Expr if no Else_Expr, or
2378 -- Else_Expr is present and has a compatible type.
2379
2380 if No (Else_Expr)
2381 or else Has_Compatible_Type (Else_Expr, It.Typ)
2382 then
2383 Add_One_Interp (N, It.Typ, It.Typ);
2384 end if;
2385
2386 Get_Next_Interp (I, It);
2387 end loop;
2388
2389 -- If no valid interpretation has been found, then the type of the
2390 -- ELSE expression does not match any interpretation of the THEN
2391 -- expression.
2392
2393 if Etype (N) = Any_Type then
2394 Error_Msg_N
2395 ("type incompatible with that of `THEN` expression",
2396 Else_Expr);
2397 return;
2398 end if;
2399 end;
2400 end if;
2401 end Analyze_If_Expression;
2402
2403 ------------------------------------
2404 -- Analyze_Indexed_Component_Form --
2405 ------------------------------------
2406
2407 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
2408 P : constant Node_Id := Prefix (N);
2409 Exprs : constant List_Id := Expressions (N);
2410 Exp : Node_Id;
2411 P_T : Entity_Id;
2412 E : Node_Id;
2413 U_N : Entity_Id;
2414
2415 procedure Process_Function_Call;
2416 -- Prefix in indexed component form is an overloadable entity, so the
2417 -- node is very likely a function call; reformat it as such. The only
2418 -- exception is a call to a parameterless function that returns an
2419 -- array type, or an access type thereof, in which case this will be
2420 -- undone later by Resolve_Call or Resolve_Entry_Call.
2421
2422 procedure Process_Indexed_Component;
2423 -- Prefix in indexed component form is actually an indexed component.
2424 -- This routine processes it, knowing that the prefix is already
2425 -- resolved.
2426
2427 procedure Process_Indexed_Component_Or_Slice;
2428 -- An indexed component with a single index may designate a slice if
2429 -- the index is a subtype mark. This routine disambiguates these two
2430 -- cases by resolving the prefix to see if it is a subtype mark.
2431
2432 procedure Process_Overloaded_Indexed_Component;
2433 -- If the prefix of an indexed component is overloaded, the proper
2434 -- interpretation is selected by the index types and the context.
2435
2436 ---------------------------
2437 -- Process_Function_Call --
2438 ---------------------------
2439
2440 procedure Process_Function_Call is
2441 Loc : constant Source_Ptr := Sloc (N);
2442 Actual : Node_Id;
2443
2444 begin
2445 Change_Node (N, N_Function_Call);
2446 Set_Name (N, P);
2447 Set_Parameter_Associations (N, Exprs);
2448
2449 -- Analyze actuals prior to analyzing the call itself
2450
2451 Actual := First (Parameter_Associations (N));
2452 while Present (Actual) loop
2453 Analyze (Actual);
2454 Check_Parameterless_Call (Actual);
2455
2456 -- Move to next actual. Note that we use Next, not Next_Actual
2457 -- here. The reason for this is a bit subtle. If a function call
2458 -- includes named associations, the parser recognizes the node
2459 -- as a call, and it is analyzed as such. If all associations are
2460 -- positional, the parser builds an indexed_component node, and
2461 -- it is only after analysis of the prefix that the construct
2462 -- is recognized as a call, in which case Process_Function_Call
2463 -- rewrites the node and analyzes the actuals. If the list of
2464 -- actuals is malformed, the parser may leave the node as an
2465 -- indexed component (despite the presence of named associations).
2466 -- The iterator Next_Actual is equivalent to Next if the list is
2467 -- positional, but follows the normalized chain of actuals when
2468 -- named associations are present. In this case normalization has
2469 -- not taken place, and actuals remain unanalyzed, which leads to
2470 -- subsequent crashes or loops if there is an attempt to continue
2471 -- analysis of the program.
2472
2473 -- IF there is a single actual and it is a type name, the node
2474 -- can only be interpreted as a slice of a parameterless call.
2475 -- Rebuild the node as such and analyze.
2476
2477 if No (Next (Actual))
2478 and then Is_Entity_Name (Actual)
2479 and then Is_Type (Entity (Actual))
2480 and then Is_Discrete_Type (Entity (Actual))
2481 then
2482 Replace (N,
2483 Make_Slice (Loc,
2484 Prefix => P,
2485 Discrete_Range =>
2486 New_Occurrence_Of (Entity (Actual), Loc)));
2487 Analyze (N);
2488 return;
2489
2490 else
2491 Next (Actual);
2492 end if;
2493 end loop;
2494
2495 Analyze_Call (N);
2496 end Process_Function_Call;
2497
2498 -------------------------------
2499 -- Process_Indexed_Component --
2500 -------------------------------
2501
2502 procedure Process_Indexed_Component is
2503 Exp : Node_Id;
2504 Array_Type : Entity_Id;
2505 Index : Node_Id;
2506 Pent : Entity_Id := Empty;
2507
2508 begin
2509 Exp := First (Exprs);
2510
2511 if Is_Overloaded (P) then
2512 Process_Overloaded_Indexed_Component;
2513
2514 else
2515 Array_Type := Etype (P);
2516
2517 if Is_Entity_Name (P) then
2518 Pent := Entity (P);
2519 elsif Nkind (P) = N_Selected_Component
2520 and then Is_Entity_Name (Selector_Name (P))
2521 then
2522 Pent := Entity (Selector_Name (P));
2523 end if;
2524
2525 -- Prefix must be appropriate for an array type, taking into
2526 -- account a possible implicit dereference.
2527
2528 if Is_Access_Type (Array_Type) then
2529 Error_Msg_NW
2530 (Warn_On_Dereference, "?d?implicit dereference", N);
2531 Array_Type := Implicitly_Designated_Type (Array_Type);
2532 end if;
2533
2534 if Is_Array_Type (Array_Type) then
2535
2536 -- In order to correctly access First_Index component later,
2537 -- replace string literal subtype by its parent type.
2538
2539 if Ekind (Array_Type) = E_String_Literal_Subtype then
2540 Array_Type := Etype (Array_Type);
2541 end if;
2542
2543 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
2544 Analyze (Exp);
2545 Set_Etype (N, Any_Type);
2546
2547 if not Has_Compatible_Type (Exp, Entry_Index_Type (Pent)) then
2548 Error_Msg_N ("invalid index type in entry name", N);
2549
2550 elsif Present (Next (Exp)) then
2551 Error_Msg_N ("too many subscripts in entry reference", N);
2552
2553 else
2554 Set_Etype (N, Etype (P));
2555 end if;
2556
2557 return;
2558
2559 elsif Is_Record_Type (Array_Type)
2560 and then Remote_AST_I_Dereference (P)
2561 then
2562 return;
2563
2564 elsif Try_Container_Indexing (N, P, Exprs) then
2565 return;
2566
2567 elsif Array_Type = Any_Type then
2568 Set_Etype (N, Any_Type);
2569
2570 -- In most cases the analysis of the prefix will have emitted
2571 -- an error already, but if the prefix may be interpreted as a
2572 -- call in prefixed notation, the report is left to the caller.
2573 -- To prevent cascaded errors, report only if no previous ones.
2574
2575 if Serious_Errors_Detected = 0 then
2576 Error_Msg_N ("invalid prefix in indexed component", P);
2577
2578 if Nkind (P) = N_Expanded_Name then
2579 Error_Msg_NE ("\& is not visible", P, Selector_Name (P));
2580 end if;
2581 end if;
2582
2583 return;
2584
2585 -- Here we definitely have a bad indexing
2586
2587 else
2588 if Nkind (Parent (N)) = N_Requeue_Statement
2589 and then Present (Pent) and then Ekind (Pent) = E_Entry
2590 then
2591 Error_Msg_N
2592 ("REQUEUE does not permit parameters", First (Exprs));
2593
2594 elsif Is_Entity_Name (P)
2595 and then Etype (P) = Standard_Void_Type
2596 then
2597 Error_Msg_NE ("incorrect use of &", P, Entity (P));
2598
2599 else
2600 Error_Msg_N ("array type required in indexed component", P);
2601 end if;
2602
2603 Set_Etype (N, Any_Type);
2604 return;
2605 end if;
2606
2607 Index := First_Index (Array_Type);
2608 while Present (Index) and then Present (Exp) loop
2609 if not Has_Compatible_Type (Exp, Etype (Index)) then
2610 Wrong_Type (Exp, Etype (Index));
2611 Set_Etype (N, Any_Type);
2612 return;
2613 end if;
2614
2615 Next_Index (Index);
2616 Next (Exp);
2617 end loop;
2618
2619 Set_Etype (N, Component_Type (Array_Type));
2620 Check_Implicit_Dereference (N, Etype (N));
2621
2622 if Present (Index) then
2623 Error_Msg_N
2624 ("too few subscripts in array reference", First (Exprs));
2625
2626 elsif Present (Exp) then
2627 Error_Msg_N ("too many subscripts in array reference", Exp);
2628 end if;
2629 end if;
2630 end Process_Indexed_Component;
2631
2632 ----------------------------------------
2633 -- Process_Indexed_Component_Or_Slice --
2634 ----------------------------------------
2635
2636 procedure Process_Indexed_Component_Or_Slice is
2637 begin
2638 Exp := First (Exprs);
2639 while Present (Exp) loop
2640 Analyze_Expression (Exp);
2641 Next (Exp);
2642 end loop;
2643
2644 Exp := First (Exprs);
2645
2646 -- If one index is present, and it is a subtype name, then the node
2647 -- denotes a slice (note that the case of an explicit range for a
2648 -- slice was already built as an N_Slice node in the first place,
2649 -- so that case is not handled here).
2650
2651 -- We use a replace rather than a rewrite here because this is one
2652 -- of the cases in which the tree built by the parser is plain wrong.
2653
2654 if No (Next (Exp))
2655 and then Is_Entity_Name (Exp)
2656 and then Is_Type (Entity (Exp))
2657 then
2658 Replace (N,
2659 Make_Slice (Sloc (N),
2660 Prefix => P,
2661 Discrete_Range => New_Copy (Exp)));
2662 Analyze (N);
2663
2664 -- Otherwise (more than one index present, or single index is not
2665 -- a subtype name), then we have the indexed component case.
2666
2667 else
2668 Process_Indexed_Component;
2669 end if;
2670 end Process_Indexed_Component_Or_Slice;
2671
2672 ------------------------------------------
2673 -- Process_Overloaded_Indexed_Component --
2674 ------------------------------------------
2675
2676 procedure Process_Overloaded_Indexed_Component is
2677 Exp : Node_Id;
2678 I : Interp_Index;
2679 It : Interp;
2680 Typ : Entity_Id;
2681 Index : Node_Id;
2682 Found : Boolean;
2683
2684 begin
2685 Set_Etype (N, Any_Type);
2686
2687 Get_First_Interp (P, I, It);
2688 while Present (It.Nam) loop
2689 Typ := It.Typ;
2690
2691 if Is_Access_Type (Typ) then
2692 Typ := Designated_Type (Typ);
2693 Error_Msg_NW
2694 (Warn_On_Dereference, "?d?implicit dereference", N);
2695 end if;
2696
2697 if Is_Array_Type (Typ) then
2698
2699 -- Got a candidate: verify that index types are compatible
2700
2701 Index := First_Index (Typ);
2702 Found := True;
2703 Exp := First (Exprs);
2704 while Present (Index) and then Present (Exp) loop
2705 if Has_Compatible_Type (Exp, Etype (Index)) then
2706 null;
2707 else
2708 Found := False;
2709 Remove_Interp (I);
2710 exit;
2711 end if;
2712
2713 Next_Index (Index);
2714 Next (Exp);
2715 end loop;
2716
2717 if Found and then No (Index) and then No (Exp) then
2718 declare
2719 CT : constant Entity_Id :=
2720 Base_Type (Component_Type (Typ));
2721 begin
2722 Add_One_Interp (N, CT, CT);
2723 Check_Implicit_Dereference (N, CT);
2724 end;
2725 end if;
2726
2727 elsif Try_Container_Indexing (N, P, Exprs) then
2728 return;
2729
2730 end if;
2731
2732 Get_Next_Interp (I, It);
2733 end loop;
2734
2735 if Etype (N) = Any_Type then
2736 Error_Msg_N ("no legal interpretation for indexed component", N);
2737 Set_Is_Overloaded (N, False);
2738 end if;
2739
2740 End_Interp_List;
2741 end Process_Overloaded_Indexed_Component;
2742
2743 -- Start of processing for Analyze_Indexed_Component_Form
2744
2745 begin
2746 -- Get name of array, function or type
2747
2748 Analyze (P);
2749
2750 -- If P is an explicit dereference whose prefix is of a remote access-
2751 -- to-subprogram type, then N has already been rewritten as a subprogram
2752 -- call and analyzed.
2753
2754 if Nkind (N) in N_Subprogram_Call then
2755 return;
2756
2757 -- When the prefix is attribute 'Loop_Entry and the sole expression of
2758 -- the indexed component denotes a loop name, the indexed form is turned
2759 -- into an attribute reference.
2760
2761 elsif Nkind (N) = N_Attribute_Reference
2762 and then Attribute_Name (N) = Name_Loop_Entry
2763 then
2764 return;
2765 end if;
2766
2767 pragma Assert (Nkind (N) = N_Indexed_Component);
2768
2769 P_T := Base_Type (Etype (P));
2770
2771 if Is_Entity_Name (P) and then Present (Entity (P)) then
2772 U_N := Entity (P);
2773
2774 if Is_Type (U_N) then
2775
2776 -- Reformat node as a type conversion
2777
2778 E := Remove_Head (Exprs);
2779
2780 if Present (First (Exprs)) then
2781 Error_Msg_N
2782 ("argument of type conversion must be single expression", N);
2783 end if;
2784
2785 Change_Node (N, N_Type_Conversion);
2786 Set_Subtype_Mark (N, P);
2787 Set_Etype (N, U_N);
2788 Set_Expression (N, E);
2789
2790 -- After changing the node, call for the specific Analysis
2791 -- routine directly, to avoid a double call to the expander.
2792
2793 Analyze_Type_Conversion (N);
2794 return;
2795 end if;
2796
2797 if Is_Overloadable (U_N) then
2798 Process_Function_Call;
2799
2800 elsif Ekind (Etype (P)) = E_Subprogram_Type
2801 or else (Is_Access_Type (Etype (P))
2802 and then
2803 Ekind (Designated_Type (Etype (P))) =
2804 E_Subprogram_Type)
2805 then
2806 -- Call to access_to-subprogram with possible implicit dereference
2807
2808 Process_Function_Call;
2809
2810 elsif Is_Generic_Subprogram (U_N) then
2811
2812 -- A common beginner's (or C++ templates fan) error
2813
2814 Error_Msg_N ("generic subprogram cannot be called", N);
2815 Set_Etype (N, Any_Type);
2816 return;
2817
2818 else
2819 Process_Indexed_Component_Or_Slice;
2820 end if;
2821
2822 -- If not an entity name, prefix is an expression that may denote
2823 -- an array or an access-to-subprogram.
2824
2825 else
2826 if Ekind (P_T) = E_Subprogram_Type
2827 or else (Is_Access_Type (P_T)
2828 and then
2829 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
2830 then
2831 Process_Function_Call;
2832
2833 elsif Nkind (P) = N_Selected_Component
2834 and then Present (Entity (Selector_Name (P)))
2835 and then Is_Overloadable (Entity (Selector_Name (P)))
2836 then
2837 Process_Function_Call;
2838 else
2839 -- Indexed component, slice, or a call to a member of a family
2840 -- entry, which will be converted to an entry call later.
2841
2842 Process_Indexed_Component_Or_Slice;
2843 end if;
2844 end if;
2845
2846 Analyze_Dimension (N);
2847 end Analyze_Indexed_Component_Form;
2848
2849 ------------------------
2850 -- Analyze_Logical_Op --
2851 ------------------------
2852
2853 procedure Analyze_Logical_Op (N : Node_Id) is
2854 L : constant Node_Id := Left_Opnd (N);
2855 R : constant Node_Id := Right_Opnd (N);
2856 Op_Id : Entity_Id := Entity (N);
2857
2858 begin
2859 Set_Etype (N, Any_Type);
2860 Candidate_Type := Empty;
2861
2862 Analyze_Expression (L);
2863 Analyze_Expression (R);
2864
2865 if Present (Op_Id) then
2866
2867 if Ekind (Op_Id) = E_Operator then
2868 Find_Boolean_Types (L, R, Op_Id, N);
2869 else
2870 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2871 end if;
2872
2873 else
2874 Op_Id := Get_Name_Entity_Id (Chars (N));
2875 while Present (Op_Id) loop
2876 if Ekind (Op_Id) = E_Operator then
2877 Find_Boolean_Types (L, R, Op_Id, N);
2878 else
2879 Analyze_User_Defined_Binary_Op (N, Op_Id);
2880 end if;
2881
2882 Op_Id := Homonym (Op_Id);
2883 end loop;
2884 end if;
2885
2886 Operator_Check (N);
2887 Check_Function_Writable_Actuals (N);
2888 end Analyze_Logical_Op;
2889
2890 ---------------------------
2891 -- Analyze_Membership_Op --
2892 ---------------------------
2893
2894 procedure Analyze_Membership_Op (N : Node_Id) is
2895 Loc : constant Source_Ptr := Sloc (N);
2896 L : constant Node_Id := Left_Opnd (N);
2897 R : constant Node_Id := Right_Opnd (N);
2898
2899 Index : Interp_Index;
2900 It : Interp;
2901 Found : Boolean := False;
2902 I_F : Interp_Index;
2903 T_F : Entity_Id;
2904
2905 procedure Try_One_Interp (T1 : Entity_Id);
2906 -- Routine to try one proposed interpretation. Note that the context
2907 -- of the operation plays no role in resolving the arguments, so that
2908 -- if there is more than one interpretation of the operands that is
2909 -- compatible with a membership test, the operation is ambiguous.
2910
2911 --------------------
2912 -- Try_One_Interp --
2913 --------------------
2914
2915 procedure Try_One_Interp (T1 : Entity_Id) is
2916 begin
2917 if Has_Compatible_Type (R, T1) then
2918 if Found
2919 and then Base_Type (T1) /= Base_Type (T_F)
2920 then
2921 It := Disambiguate (L, I_F, Index, Any_Type);
2922
2923 if It = No_Interp then
2924 Ambiguous_Operands (N);
2925 Set_Etype (L, Any_Type);
2926 return;
2927
2928 else
2929 T_F := It.Typ;
2930 end if;
2931
2932 else
2933 Found := True;
2934 T_F := T1;
2935 I_F := Index;
2936 end if;
2937
2938 Set_Etype (L, T_F);
2939 end if;
2940 end Try_One_Interp;
2941
2942 procedure Analyze_Set_Membership;
2943 -- If a set of alternatives is present, analyze each and find the
2944 -- common type to which they must all resolve.
2945
2946 ----------------------------
2947 -- Analyze_Set_Membership --
2948 ----------------------------
2949
2950 procedure Analyze_Set_Membership is
2951 Alt : Node_Id;
2952 Index : Interp_Index;
2953 It : Interp;
2954 Candidate_Interps : Node_Id;
2955 Common_Type : Entity_Id := Empty;
2956
2957 begin
2958 if Comes_From_Source (N) then
2959 Check_Compiler_Unit ("set membership", N);
2960 end if;
2961
2962 Analyze (L);
2963 Candidate_Interps := L;
2964
2965 if not Is_Overloaded (L) then
2966 Common_Type := Etype (L);
2967
2968 Alt := First (Alternatives (N));
2969 while Present (Alt) loop
2970 Analyze (Alt);
2971
2972 if not Has_Compatible_Type (Alt, Common_Type) then
2973 Wrong_Type (Alt, Common_Type);
2974 end if;
2975
2976 Next (Alt);
2977 end loop;
2978
2979 else
2980 Alt := First (Alternatives (N));
2981 while Present (Alt) loop
2982 Analyze (Alt);
2983 if not Is_Overloaded (Alt) then
2984 Common_Type := Etype (Alt);
2985
2986 else
2987 Get_First_Interp (Alt, Index, It);
2988 while Present (It.Typ) loop
2989 if not
2990 Has_Compatible_Type (Candidate_Interps, It.Typ)
2991 then
2992 Remove_Interp (Index);
2993 end if;
2994
2995 Get_Next_Interp (Index, It);
2996 end loop;
2997
2998 Get_First_Interp (Alt, Index, It);
2999
3000 if No (It.Typ) then
3001 Error_Msg_N ("alternative has no legal type", Alt);
3002 return;
3003 end if;
3004
3005 -- If alternative is not overloaded, we have a unique type
3006 -- for all of them.
3007
3008 Set_Etype (Alt, It.Typ);
3009
3010 -- If the alternative is an enumeration literal, use the one
3011 -- for this interpretation.
3012
3013 if Is_Entity_Name (Alt) then
3014 Set_Entity (Alt, It.Nam);
3015 end if;
3016
3017 Get_Next_Interp (Index, It);
3018
3019 if No (It.Typ) then
3020 Set_Is_Overloaded (Alt, False);
3021 Common_Type := Etype (Alt);
3022 end if;
3023
3024 Candidate_Interps := Alt;
3025 end if;
3026
3027 Next (Alt);
3028 end loop;
3029 end if;
3030
3031 Set_Etype (N, Standard_Boolean);
3032
3033 if Present (Common_Type) then
3034 Set_Etype (L, Common_Type);
3035
3036 -- The left operand may still be overloaded, to be resolved using
3037 -- the Common_Type.
3038
3039 else
3040 Error_Msg_N ("cannot resolve membership operation", N);
3041 end if;
3042 end Analyze_Set_Membership;
3043
3044 Op : Node_Id;
3045
3046 -- Start of processing for Analyze_Membership_Op
3047
3048 begin
3049 Analyze_Expression (L);
3050
3051 if No (R) then
3052 pragma Assert (Ada_Version >= Ada_2012);
3053 Analyze_Set_Membership;
3054 Check_Function_Writable_Actuals (N);
3055 return;
3056 end if;
3057
3058 if Nkind (R) = N_Range
3059 or else (Nkind (R) = N_Attribute_Reference
3060 and then Attribute_Name (R) = Name_Range)
3061 then
3062 Analyze (R);
3063
3064 if not Is_Overloaded (L) then
3065 Try_One_Interp (Etype (L));
3066
3067 else
3068 Get_First_Interp (L, Index, It);
3069 while Present (It.Typ) loop
3070 Try_One_Interp (It.Typ);
3071 Get_Next_Interp (Index, It);
3072 end loop;
3073 end if;
3074
3075 -- If not a range, it can be a subtype mark, or else it is a degenerate
3076 -- membership test with a singleton value, i.e. a test for equality,
3077 -- if the types are compatible.
3078
3079 else
3080 Analyze (R);
3081
3082 if Is_Entity_Name (R)
3083 and then Is_Type (Entity (R))
3084 then
3085 Find_Type (R);
3086 Check_Fully_Declared (Entity (R), R);
3087
3088 elsif Ada_Version >= Ada_2012
3089 and then Has_Compatible_Type (R, Etype (L))
3090 then
3091 if Nkind (N) = N_In then
3092 Op := Make_Op_Eq (Loc, Left_Opnd => L, Right_Opnd => R);
3093 else
3094 Op := Make_Op_Ne (Loc, Left_Opnd => L, Right_Opnd => R);
3095 end if;
3096
3097 if Is_Record_Or_Limited_Type (Etype (L)) then
3098
3099 -- We reset the Entity in order to use the primitive equality
3100 -- of the type, as per RM 4.5.2 (28.1/4).
3101
3102 Set_Entity (Op, Empty);
3103 end if;
3104
3105 Rewrite (N, Op);
3106 Analyze (N);
3107 return;
3108
3109 else
3110 -- In all versions of the language, if we reach this point there
3111 -- is a previous error that will be diagnosed below.
3112
3113 Find_Type (R);
3114 end if;
3115 end if;
3116
3117 -- Compatibility between expression and subtype mark or range is
3118 -- checked during resolution. The result of the operation is Boolean
3119 -- in any case.
3120
3121 Set_Etype (N, Standard_Boolean);
3122
3123 if Comes_From_Source (N)
3124 and then Present (Right_Opnd (N))
3125 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
3126 then
3127 Error_Msg_N ("membership test not applicable to cpp-class types", N);
3128 end if;
3129
3130 Check_Function_Writable_Actuals (N);
3131 end Analyze_Membership_Op;
3132
3133 -----------------
3134 -- Analyze_Mod --
3135 -----------------
3136
3137 procedure Analyze_Mod (N : Node_Id) is
3138 begin
3139 -- A special warning check, if we have an expression of the form:
3140 -- expr mod 2 * literal
3141 -- where literal is 64 or less, then probably what was meant was
3142 -- expr mod 2 ** literal
3143 -- so issue an appropriate warning.
3144
3145 if Warn_On_Suspicious_Modulus_Value
3146 and then Nkind (Right_Opnd (N)) = N_Integer_Literal
3147 and then Intval (Right_Opnd (N)) = Uint_2
3148 and then Nkind (Parent (N)) = N_Op_Multiply
3149 and then Nkind (Right_Opnd (Parent (N))) = N_Integer_Literal
3150 and then Intval (Right_Opnd (Parent (N))) <= Uint_64
3151 then
3152 Error_Msg_N
3153 ("suspicious MOD value, was '*'* intended'??M?", Parent (N));
3154 end if;
3155
3156 -- Remaining processing is same as for other arithmetic operators
3157
3158 Analyze_Arithmetic_Op (N);
3159 end Analyze_Mod;
3160
3161 ----------------------
3162 -- Analyze_Negation --
3163 ----------------------
3164
3165 procedure Analyze_Negation (N : Node_Id) is
3166 R : constant Node_Id := Right_Opnd (N);
3167 Op_Id : Entity_Id := Entity (N);
3168
3169 begin
3170 Set_Etype (N, Any_Type);
3171 Candidate_Type := Empty;
3172
3173 Analyze_Expression (R);
3174
3175 if Present (Op_Id) then
3176 if Ekind (Op_Id) = E_Operator then
3177 Find_Negation_Types (R, Op_Id, N);
3178 else
3179 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3180 end if;
3181
3182 else
3183 Op_Id := Get_Name_Entity_Id (Chars (N));
3184 while Present (Op_Id) loop
3185 if Ekind (Op_Id) = E_Operator then
3186 Find_Negation_Types (R, Op_Id, N);
3187 else
3188 Analyze_User_Defined_Unary_Op (N, Op_Id);
3189 end if;
3190
3191 Op_Id := Homonym (Op_Id);
3192 end loop;
3193 end if;
3194
3195 Operator_Check (N);
3196 end Analyze_Negation;
3197
3198 ------------------
3199 -- Analyze_Null --
3200 ------------------
3201
3202 procedure Analyze_Null (N : Node_Id) is
3203 begin
3204 Set_Etype (N, Any_Access);
3205 end Analyze_Null;
3206
3207 ----------------------
3208 -- Analyze_One_Call --
3209 ----------------------
3210
3211 procedure Analyze_One_Call
3212 (N : Node_Id;
3213 Nam : Entity_Id;
3214 Report : Boolean;
3215 Success : out Boolean;
3216 Skip_First : Boolean := False)
3217 is
3218 Actuals : constant List_Id := Parameter_Associations (N);
3219 Prev_T : constant Entity_Id := Etype (N);
3220
3221 -- Recognize cases of prefixed calls that have been rewritten in
3222 -- various ways. The simplest case is a rewritten selected component,
3223 -- but it can also be an already-examined indexed component, or a
3224 -- prefix that is itself a rewritten prefixed call that is in turn
3225 -- an indexed call (the syntactic ambiguity involving the indexing of
3226 -- a function with defaulted parameters that returns an array).
3227 -- A flag Maybe_Indexed_Call might be useful here ???
3228
3229 Must_Skip : constant Boolean := Skip_First
3230 or else Nkind (Original_Node (N)) = N_Selected_Component
3231 or else
3232 (Nkind (Original_Node (N)) = N_Indexed_Component
3233 and then Nkind (Prefix (Original_Node (N))) =
3234 N_Selected_Component)
3235 or else
3236 (Nkind (Parent (N)) = N_Function_Call
3237 and then Is_Array_Type (Etype (Name (N)))
3238 and then Etype (Original_Node (N)) =
3239 Component_Type (Etype (Name (N)))
3240 and then Nkind (Original_Node (Parent (N))) =
3241 N_Selected_Component);
3242
3243 -- The first formal must be omitted from the match when trying to find
3244 -- a primitive operation that is a possible interpretation, and also
3245 -- after the call has been rewritten, because the corresponding actual
3246 -- is already known to be compatible, and because this may be an
3247 -- indexing of a call with default parameters.
3248
3249 First_Form : Entity_Id;
3250 Formal : Entity_Id;
3251 Actual : Node_Id;
3252 Is_Indexed : Boolean := False;
3253 Is_Indirect : Boolean := False;
3254 Subp_Type : constant Entity_Id := Etype (Nam);
3255 Norm_OK : Boolean;
3256
3257 function Compatible_Types_In_Predicate
3258 (T1 : Entity_Id;
3259 T2 : Entity_Id) return Boolean;
3260 -- For an Ada 2012 predicate or invariant, a call may mention an
3261 -- incomplete type, while resolution of the corresponding predicate
3262 -- function may see the full view, as a consequence of the delayed
3263 -- resolution of the corresponding expressions. This may occur in
3264 -- the body of a predicate function, or in a call to such. Anomalies
3265 -- involving private and full views can also happen. In each case,
3266 -- rewrite node or add conversions to remove spurious type errors.
3267
3268 procedure Indicate_Name_And_Type;
3269 -- If candidate interpretation matches, indicate name and type of result
3270 -- on call node.
3271
3272 function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
3273 -- There may be a user-defined operator that hides the current
3274 -- interpretation. We must check for this independently of the
3275 -- analysis of the call with the user-defined operation, because
3276 -- the parameter names may be wrong and yet the hiding takes place.
3277 -- This fixes a problem with ACATS test B34014O.
3278 --
3279 -- When the type Address is a visible integer type, and the DEC
3280 -- system extension is visible, the predefined operator may be
3281 -- hidden as well, by one of the address operations in auxdec.
3282 -- Finally, The abstract operations on address do not hide the
3283 -- predefined operator (this is the purpose of making them abstract).
3284
3285 -----------------------------------
3286 -- Compatible_Types_In_Predicate --
3287 -----------------------------------
3288
3289 function Compatible_Types_In_Predicate
3290 (T1 : Entity_Id;
3291 T2 : Entity_Id) return Boolean
3292 is
3293 function Common_Type (T : Entity_Id) return Entity_Id;
3294 -- Find non-private full view if any, without going to ancestor type
3295 -- (as opposed to Underlying_Type).
3296
3297 -----------------
3298 -- Common_Type --
3299 -----------------
3300
3301 function Common_Type (T : Entity_Id) return Entity_Id is
3302 begin
3303 if Is_Private_Type (T) and then Present (Full_View (T)) then
3304 return Base_Type (Full_View (T));
3305 else
3306 return Base_Type (T);
3307 end if;
3308 end Common_Type;
3309
3310 -- Start of processing for Compatible_Types_In_Predicate
3311
3312 begin
3313 if (Ekind (Current_Scope) = E_Function
3314 and then Is_Predicate_Function (Current_Scope))
3315 or else
3316 (Ekind (Nam) = E_Function
3317 and then Is_Predicate_Function (Nam))
3318 then
3319 if Is_Incomplete_Type (T1)
3320 and then Present (Full_View (T1))
3321 and then Full_View (T1) = T2
3322 then
3323 Set_Etype (Formal, Etype (Actual));
3324 return True;
3325
3326 elsif Common_Type (T1) = Common_Type (T2) then
3327 Rewrite (Actual, Unchecked_Convert_To (Etype (Formal), Actual));
3328 return True;
3329
3330 else
3331 return False;
3332 end if;
3333
3334 else
3335 return False;
3336 end if;
3337 end Compatible_Types_In_Predicate;
3338
3339 ----------------------------
3340 -- Indicate_Name_And_Type --
3341 ----------------------------
3342
3343 procedure Indicate_Name_And_Type is
3344 begin
3345 Add_One_Interp (N, Nam, Etype (Nam));
3346 Check_Implicit_Dereference (N, Etype (Nam));
3347 Success := True;
3348
3349 -- If the prefix of the call is a name, indicate the entity
3350 -- being called. If it is not a name, it is an expression that
3351 -- denotes an access to subprogram or else an entry or family. In
3352 -- the latter case, the name is a selected component, and the entity
3353 -- being called is noted on the selector.
3354
3355 if not Is_Type (Nam) then
3356 if Is_Entity_Name (Name (N)) then
3357 Set_Entity (Name (N), Nam);
3358 Set_Etype (Name (N), Etype (Nam));
3359
3360 elsif Nkind (Name (N)) = N_Selected_Component then
3361 Set_Entity (Selector_Name (Name (N)), Nam);
3362 end if;
3363 end if;
3364
3365 if Debug_Flag_E and not Report then
3366 Write_Str (" Overloaded call ");
3367 Write_Int (Int (N));
3368 Write_Str (" compatible with ");
3369 Write_Int (Int (Nam));
3370 Write_Eol;
3371 end if;
3372 end Indicate_Name_And_Type;
3373
3374 ------------------------
3375 -- Operator_Hidden_By --
3376 ------------------------
3377
3378 function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
3379 Act1 : constant Node_Id := First_Actual (N);
3380 Act2 : constant Node_Id := Next_Actual (Act1);
3381 Form1 : constant Entity_Id := First_Formal (Fun);
3382 Form2 : constant Entity_Id := Next_Formal (Form1);
3383
3384 begin
3385 if Ekind (Fun) /= E_Function or else Is_Abstract_Subprogram (Fun) then
3386 return False;
3387
3388 elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
3389 return False;
3390
3391 elsif Present (Form2) then
3392 if No (Act2)
3393 or else not Has_Compatible_Type (Act2, Etype (Form2))
3394 then
3395 return False;
3396 end if;
3397
3398 elsif Present (Act2) then
3399 return False;
3400 end if;
3401
3402 -- Now we know that the arity of the operator matches the function,
3403 -- and the function call is a valid interpretation. The function
3404 -- hides the operator if it has the right signature, or if one of
3405 -- its operands is a non-abstract operation on Address when this is
3406 -- a visible integer type.
3407
3408 return Hides_Op (Fun, Nam)
3409 or else Is_Descendant_Of_Address (Etype (Form1))
3410 or else
3411 (Present (Form2)
3412 and then Is_Descendant_Of_Address (Etype (Form2)));
3413 end Operator_Hidden_By;
3414
3415 -- Start of processing for Analyze_One_Call
3416
3417 begin
3418 Success := False;
3419
3420 -- If the subprogram has no formals or if all the formals have defaults,
3421 -- and the return type is an array type, the node may denote an indexing
3422 -- of the result of a parameterless call. In Ada 2005, the subprogram
3423 -- may have one non-defaulted formal, and the call may have been written
3424 -- in prefix notation, so that the rebuilt parameter list has more than
3425 -- one actual.
3426
3427 if not Is_Overloadable (Nam)
3428 and then Ekind (Nam) /= E_Subprogram_Type
3429 and then Ekind (Nam) /= E_Entry_Family
3430 then
3431 return;
3432 end if;
3433
3434 -- An indexing requires at least one actual. The name of the call cannot
3435 -- be an implicit indirect call, so it cannot be a generated explicit
3436 -- dereference.
3437
3438 if not Is_Empty_List (Actuals)
3439 and then
3440 (Needs_No_Actuals (Nam)
3441 or else
3442 (Needs_One_Actual (Nam)
3443 and then Present (Next_Actual (First (Actuals)))))
3444 then
3445 if Is_Array_Type (Subp_Type)
3446 and then
3447 (Nkind (Name (N)) /= N_Explicit_Dereference
3448 or else Comes_From_Source (Name (N)))
3449 then
3450 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
3451
3452 elsif Is_Access_Type (Subp_Type)
3453 and then Is_Array_Type (Designated_Type (Subp_Type))
3454 then
3455 Is_Indexed :=
3456 Try_Indexed_Call
3457 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
3458
3459 -- The prefix can also be a parameterless function that returns an
3460 -- access to subprogram, in which case this is an indirect call.
3461 -- If this succeeds, an explicit dereference is added later on,
3462 -- in Analyze_Call or Resolve_Call.
3463
3464 elsif Is_Access_Type (Subp_Type)
3465 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
3466 then
3467 Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
3468 end if;
3469
3470 end if;
3471
3472 -- If the call has been transformed into a slice, it is of the form
3473 -- F (Subtype) where F is parameterless. The node has been rewritten in
3474 -- Try_Indexed_Call and there is nothing else to do.
3475
3476 if Is_Indexed
3477 and then Nkind (N) = N_Slice
3478 then
3479 return;
3480 end if;
3481
3482 Normalize_Actuals
3483 (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
3484
3485 if not Norm_OK then
3486
3487 -- If an indirect call is a possible interpretation, indicate
3488 -- success to the caller. This may be an indexing of an explicit
3489 -- dereference of a call that returns an access type (see above).
3490
3491 if Is_Indirect
3492 or else (Is_Indexed
3493 and then Nkind (Name (N)) = N_Explicit_Dereference
3494 and then Comes_From_Source (Name (N)))
3495 then
3496 Success := True;
3497 return;
3498
3499 -- Mismatch in number or names of parameters
3500
3501 elsif Debug_Flag_E then
3502 Write_Str (" normalization fails in call ");
3503 Write_Int (Int (N));
3504 Write_Str (" with subprogram ");
3505 Write_Int (Int (Nam));
3506 Write_Eol;
3507 end if;
3508
3509 -- If the context expects a function call, discard any interpretation
3510 -- that is a procedure. If the node is not overloaded, leave as is for
3511 -- better error reporting when type mismatch is found.
3512
3513 elsif Nkind (N) = N_Function_Call
3514 and then Is_Overloaded (Name (N))
3515 and then Ekind (Nam) = E_Procedure
3516 then
3517 return;
3518
3519 -- Ditto for function calls in a procedure context
3520
3521 elsif Nkind (N) = N_Procedure_Call_Statement
3522 and then Is_Overloaded (Name (N))
3523 and then Etype (Nam) /= Standard_Void_Type
3524 then
3525 return;
3526
3527 elsif No (Actuals) then
3528
3529 -- If Normalize succeeds, then there are default parameters for
3530 -- all formals.
3531
3532 Indicate_Name_And_Type;
3533
3534 elsif Ekind (Nam) = E_Operator then
3535 if Nkind (N) = N_Procedure_Call_Statement then
3536 return;
3537 end if;
3538
3539 -- This can occur when the prefix of the call is an operator
3540 -- name or an expanded name whose selector is an operator name.
3541
3542 Analyze_Operator_Call (N, Nam);
3543
3544 if Etype (N) /= Prev_T then
3545
3546 -- Check that operator is not hidden by a function interpretation
3547
3548 if Is_Overloaded (Name (N)) then
3549 declare
3550 I : Interp_Index;
3551 It : Interp;
3552
3553 begin
3554 Get_First_Interp (Name (N), I, It);
3555 while Present (It.Nam) loop
3556 if Operator_Hidden_By (It.Nam) then
3557 Set_Etype (N, Prev_T);
3558 return;
3559 end if;
3560
3561 Get_Next_Interp (I, It);
3562 end loop;
3563 end;
3564 end if;
3565
3566 -- If operator matches formals, record its name on the call.
3567 -- If the operator is overloaded, Resolve will select the
3568 -- correct one from the list of interpretations. The call
3569 -- node itself carries the first candidate.
3570
3571 Set_Entity (Name (N), Nam);
3572 Success := True;
3573
3574 elsif Report and then Etype (N) = Any_Type then
3575 Error_Msg_N ("incompatible arguments for operator", N);
3576 end if;
3577
3578 else
3579 -- Normalize_Actuals has chained the named associations in the
3580 -- correct order of the formals.
3581
3582 Actual := First_Actual (N);
3583 Formal := First_Formal (Nam);
3584 First_Form := Formal;
3585
3586 -- If we are analyzing a call rewritten from object notation, skip
3587 -- first actual, which may be rewritten later as an explicit
3588 -- dereference.
3589
3590 if Must_Skip then
3591 Next_Actual (Actual);
3592 Next_Formal (Formal);
3593 end if;
3594
3595 while Present (Actual) and then Present (Formal) loop
3596 if Nkind (Parent (Actual)) /= N_Parameter_Association
3597 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
3598 then
3599 -- The actual can be compatible with the formal, but we must
3600 -- also check that the context is not an address type that is
3601 -- visibly an integer type. In this case the use of literals is
3602 -- illegal, except in the body of descendants of system, where
3603 -- arithmetic operations on address are of course used.
3604
3605 if Has_Compatible_Type (Actual, Etype (Formal))
3606 and then
3607 (Etype (Actual) /= Universal_Integer
3608 or else not Is_Descendant_Of_Address (Etype (Formal))
3609 or else In_Predefined_Unit (N))
3610 then
3611 Next_Actual (Actual);
3612 Next_Formal (Formal);
3613
3614 -- In Allow_Integer_Address mode, we allow an actual integer to
3615 -- match a formal address type and vice versa. We only do this
3616 -- if we are certain that an error will otherwise be issued
3617
3618 elsif Address_Integer_Convert_OK
3619 (Etype (Actual), Etype (Formal))
3620 and then (Report and not Is_Indexed and not Is_Indirect)
3621 then
3622 -- Handle this case by introducing an unchecked conversion
3623
3624 Rewrite (Actual,
3625 Unchecked_Convert_To (Etype (Formal),
3626 Relocate_Node (Actual)));
3627 Analyze_And_Resolve (Actual, Etype (Formal));
3628 Next_Actual (Actual);
3629 Next_Formal (Formal);
3630
3631 -- Under relaxed RM semantics silently replace occurrences of
3632 -- null by System.Address_Null. We only do this if we know that
3633 -- an error will otherwise be issued.
3634
3635 elsif Null_To_Null_Address_Convert_OK (Actual, Etype (Formal))
3636 and then (Report and not Is_Indexed and not Is_Indirect)
3637 then
3638 Replace_Null_By_Null_Address (Actual);
3639 Analyze_And_Resolve (Actual, Etype (Formal));
3640 Next_Actual (Actual);
3641 Next_Formal (Formal);
3642
3643 elsif Compatible_Types_In_Predicate
3644 (Etype (Formal), Etype (Actual))
3645 then
3646 Next_Actual (Actual);
3647 Next_Formal (Formal);
3648
3649 -- Handle failed type check
3650
3651 else
3652 if Debug_Flag_E then
3653 Write_Str (" type checking fails in call ");
3654 Write_Int (Int (N));
3655 Write_Str (" with formal ");
3656 Write_Int (Int (Formal));
3657 Write_Str (" in subprogram ");
3658 Write_Int (Int (Nam));
3659 Write_Eol;
3660 end if;
3661
3662 -- Comment needed on the following test???
3663
3664 if Report and not Is_Indexed and not Is_Indirect then
3665
3666 -- Ada 2005 (AI-251): Complete the error notification
3667 -- to help new Ada 2005 users.
3668
3669 if Is_Class_Wide_Type (Etype (Formal))
3670 and then Is_Interface (Etype (Etype (Formal)))
3671 and then not Interface_Present_In_Ancestor
3672 (Typ => Etype (Actual),
3673 Iface => Etype (Etype (Formal)))
3674 then
3675 Error_Msg_NE
3676 ("(Ada 2005) does not implement interface }",
3677 Actual, Etype (Etype (Formal)));
3678 end if;
3679
3680 Wrong_Type (Actual, Etype (Formal));
3681
3682 if Nkind (Actual) = N_Op_Eq
3683 and then Nkind (Left_Opnd (Actual)) = N_Identifier
3684 then
3685 Formal := First_Formal (Nam);
3686 while Present (Formal) loop
3687 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
3688 Error_Msg_N -- CODEFIX
3689 ("possible misspelling of `='>`!", Actual);
3690 exit;
3691 end if;
3692
3693 Next_Formal (Formal);
3694 end loop;
3695 end if;
3696
3697 if All_Errors_Mode then
3698 Error_Msg_Sloc := Sloc (Nam);
3699
3700 if Etype (Formal) = Any_Type then
3701 Error_Msg_N
3702 ("there is no legal actual parameter", Actual);
3703 end if;
3704
3705 if Is_Overloadable (Nam)
3706 and then Present (Alias (Nam))
3707 and then not Comes_From_Source (Nam)
3708 then
3709 Error_Msg_NE
3710 ("\\ =='> in call to inherited operation & #!",
3711 Actual, Nam);
3712
3713 elsif Ekind (Nam) = E_Subprogram_Type then
3714 declare
3715 Access_To_Subprogram_Typ :
3716 constant Entity_Id :=
3717 Defining_Identifier
3718 (Associated_Node_For_Itype (Nam));
3719 begin
3720 Error_Msg_NE
3721 ("\\ =='> in call to dereference of &#!",
3722 Actual, Access_To_Subprogram_Typ);
3723 end;
3724
3725 else
3726 Error_Msg_NE
3727 ("\\ =='> in call to &#!", Actual, Nam);
3728
3729 end if;
3730 end if;
3731 end if;
3732
3733 return;
3734 end if;
3735
3736 else
3737 -- Normalize_Actuals has verified that a default value exists
3738 -- for this formal. Current actual names a subsequent formal.
3739
3740 Next_Formal (Formal);
3741 end if;
3742 end loop;
3743
3744 -- Due to our current model of controlled type expansion we may
3745 -- have resolved a user call to a non-visible controlled primitive
3746 -- since these inherited subprograms may be generated in the current
3747 -- scope. This is a side effect of the need for the expander to be
3748 -- able to resolve internally generated calls.
3749
3750 -- Specifically, the issue appears when predefined controlled
3751 -- operations get called on a type extension whose parent is a
3752 -- private extension completed with a controlled extension - see
3753 -- below:
3754
3755 -- package X is
3756 -- type Par_Typ is tagged private;
3757 -- private
3758 -- type Par_Typ is new Controlled with null record;
3759 -- end;
3760 -- ...
3761 -- procedure Main is
3762 -- type Ext_Typ is new Par_Typ with null record;
3763 -- Obj : Ext_Typ;
3764 -- begin
3765 -- Finalize (Obj); -- Will improperly resolve
3766 -- end;
3767
3768 -- To avoid breaking privacy, Is_Hidden gets set elsewhere on such
3769 -- primitives, but we still need to verify that Nam is indeed a
3770 -- non-visible controlled subprogram. So, we do that here and issue
3771 -- the appropriate error.
3772
3773 if Is_Hidden (Nam)
3774 and then not In_Instance
3775 and then not Comes_From_Source (Nam)
3776 and then Comes_From_Source (N)
3777
3778 -- Verify Nam is a non-visible controlled primitive
3779
3780 and then Nam_In (Chars (Nam), Name_Adjust,
3781 Name_Finalize,
3782 Name_Initialize)
3783 and then Ekind (Nam) = E_Procedure
3784 and then Is_Controlled (Etype (First_Form))
3785 and then No (Next_Formal (First_Form))
3786 and then not Is_Visibly_Controlled (Etype (First_Form))
3787 then
3788 Error_Msg_Node_2 := Etype (First_Form);
3789 Error_Msg_NE ("call to non-visible controlled primitive & on type"
3790 & " &", N, Nam);
3791 end if;
3792
3793 -- On exit, all actuals match
3794
3795 Indicate_Name_And_Type;
3796 end if;
3797 end Analyze_One_Call;
3798
3799 ---------------------------
3800 -- Analyze_Operator_Call --
3801 ---------------------------
3802
3803 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
3804 Op_Name : constant Name_Id := Chars (Op_Id);
3805 Act1 : constant Node_Id := First_Actual (N);
3806 Act2 : constant Node_Id := Next_Actual (Act1);
3807
3808 begin
3809 -- Binary operator case
3810
3811 if Present (Act2) then
3812
3813 -- If more than two operands, then not binary operator after all
3814
3815 if Present (Next_Actual (Act2)) then
3816 return;
3817 end if;
3818
3819 -- Otherwise action depends on operator
3820
3821 case Op_Name is
3822 when Name_Op_Add
3823 | Name_Op_Divide
3824 | Name_Op_Expon
3825 | Name_Op_Mod
3826 | Name_Op_Multiply
3827 | Name_Op_Rem
3828 | Name_Op_Subtract
3829 =>
3830 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
3831
3832 when Name_Op_And
3833 | Name_Op_Or
3834 | Name_Op_Xor
3835 =>
3836 Find_Boolean_Types (Act1, Act2, Op_Id, N);
3837
3838 when Name_Op_Ge
3839 | Name_Op_Gt
3840 | Name_Op_Le
3841 | Name_Op_Lt
3842 =>
3843 Find_Comparison_Types (Act1, Act2, Op_Id, N);
3844
3845 when Name_Op_Eq
3846 | Name_Op_Ne
3847 =>
3848 Find_Equality_Types (Act1, Act2, Op_Id, N);
3849
3850 when Name_Op_Concat =>
3851 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
3852
3853 -- Is this when others, or should it be an abort???
3854
3855 when others =>
3856 null;
3857 end case;
3858
3859 -- Unary operator case
3860
3861 else
3862 case Op_Name is
3863 when Name_Op_Abs
3864 | Name_Op_Add
3865 | Name_Op_Subtract
3866 =>
3867 Find_Unary_Types (Act1, Op_Id, N);
3868
3869 when Name_Op_Not =>
3870 Find_Negation_Types (Act1, Op_Id, N);
3871
3872 -- Is this when others correct, or should it be an abort???
3873
3874 when others =>
3875 null;
3876 end case;
3877 end if;
3878 end Analyze_Operator_Call;
3879
3880 -------------------------------------------
3881 -- Analyze_Overloaded_Selected_Component --
3882 -------------------------------------------
3883
3884 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
3885 Nam : constant Node_Id := Prefix (N);
3886 Sel : constant Node_Id := Selector_Name (N);
3887 Comp : Entity_Id;
3888 I : Interp_Index;
3889 It : Interp;
3890 T : Entity_Id;
3891
3892 begin
3893 Set_Etype (Sel, Any_Type);
3894
3895 Get_First_Interp (Nam, I, It);
3896 while Present (It.Typ) loop
3897 if Is_Access_Type (It.Typ) then
3898 T := Designated_Type (It.Typ);
3899 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
3900 else
3901 T := It.Typ;
3902 end if;
3903
3904 -- Locate the component. For a private prefix the selector can denote
3905 -- a discriminant.
3906
3907 if Is_Record_Type (T) or else Is_Private_Type (T) then
3908
3909 -- If the prefix is a class-wide type, the visible components are
3910 -- those of the base type.
3911
3912 if Is_Class_Wide_Type (T) then
3913 T := Etype (T);
3914 end if;
3915
3916 Comp := First_Entity (T);
3917 while Present (Comp) loop
3918 if Chars (Comp) = Chars (Sel)
3919 and then Is_Visible_Component (Comp, Sel)
3920 then
3921
3922 -- AI05-105: if the context is an object renaming with
3923 -- an anonymous access type, the expected type of the
3924 -- object must be anonymous. This is a name resolution rule.
3925
3926 if Nkind (Parent (N)) /= N_Object_Renaming_Declaration
3927 or else No (Access_Definition (Parent (N)))
3928 or else Ekind (Etype (Comp)) = E_Anonymous_Access_Type
3929 or else
3930 Ekind (Etype (Comp)) = E_Anonymous_Access_Subprogram_Type
3931 then
3932 Set_Entity (Sel, Comp);
3933 Set_Etype (Sel, Etype (Comp));
3934 Add_One_Interp (N, Etype (Comp), Etype (Comp));
3935 Check_Implicit_Dereference (N, Etype (Comp));
3936
3937 -- This also specifies a candidate to resolve the name.
3938 -- Further overloading will be resolved from context.
3939 -- The selector name itself does not carry overloading
3940 -- information.
3941
3942 Set_Etype (Nam, It.Typ);
3943
3944 else
3945 -- Named access type in the context of a renaming
3946 -- declaration with an access definition. Remove
3947 -- inapplicable candidate.
3948
3949 Remove_Interp (I);
3950 end if;
3951 end if;
3952
3953 Next_Entity (Comp);
3954 end loop;
3955
3956 elsif Is_Concurrent_Type (T) then
3957 Comp := First_Entity (T);
3958 while Present (Comp)
3959 and then Comp /= First_Private_Entity (T)
3960 loop
3961 if Chars (Comp) = Chars (Sel) then
3962 if Is_Overloadable (Comp) then
3963 Add_One_Interp (Sel, Comp, Etype (Comp));
3964 else
3965 Set_Entity_With_Checks (Sel, Comp);
3966 Generate_Reference (Comp, Sel);
3967 end if;
3968
3969 Set_Etype (Sel, Etype (Comp));
3970 Set_Etype (N, Etype (Comp));
3971 Set_Etype (Nam, It.Typ);
3972 end if;
3973
3974 Next_Entity (Comp);
3975 end loop;
3976
3977 Set_Is_Overloaded (N, Is_Overloaded (Sel));
3978 end if;
3979
3980 Get_Next_Interp (I, It);
3981 end loop;
3982
3983 if Etype (N) = Any_Type
3984 and then not Try_Object_Operation (N)
3985 then
3986 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
3987 Set_Entity (Sel, Any_Id);
3988 Set_Etype (Sel, Any_Type);
3989 end if;
3990 end Analyze_Overloaded_Selected_Component;
3991
3992 ----------------------------------
3993 -- Analyze_Qualified_Expression --
3994 ----------------------------------
3995
3996 procedure Analyze_Qualified_Expression (N : Node_Id) is
3997 Mark : constant Entity_Id := Subtype_Mark (N);
3998 Expr : constant Node_Id := Expression (N);
3999 I : Interp_Index;
4000 It : Interp;
4001 T : Entity_Id;
4002
4003 begin
4004 Analyze_Expression (Expr);
4005
4006 Set_Etype (N, Any_Type);
4007 Find_Type (Mark);
4008 T := Entity (Mark);
4009
4010 if Nkind_In (Enclosing_Declaration (N), N_Formal_Type_Declaration,
4011 N_Full_Type_Declaration,
4012 N_Incomplete_Type_Declaration,
4013 N_Protected_Type_Declaration,
4014 N_Private_Extension_Declaration,
4015 N_Private_Type_Declaration,
4016 N_Subtype_Declaration,
4017 N_Task_Type_Declaration)
4018 and then T = Defining_Identifier (Enclosing_Declaration (N))
4019 then
4020 Error_Msg_N ("current instance not allowed", Mark);
4021 T := Any_Type;
4022 end if;
4023
4024 Set_Etype (N, T);
4025
4026 if T = Any_Type then
4027 return;
4028 end if;
4029
4030 Check_Fully_Declared (T, N);
4031
4032 -- If expected type is class-wide, check for exact match before
4033 -- expansion, because if the expression is a dispatching call it
4034 -- may be rewritten as explicit dereference with class-wide result.
4035 -- If expression is overloaded, retain only interpretations that
4036 -- will yield exact matches.
4037
4038 if Is_Class_Wide_Type (T) then
4039 if not Is_Overloaded (Expr) then
4040 if Base_Type (Etype (Expr)) /= Base_Type (T)
4041 and then Etype (Expr) /= Raise_Type
4042 then
4043 if Nkind (Expr) = N_Aggregate then
4044 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
4045 else
4046 Wrong_Type (Expr, T);
4047 end if;
4048 end if;
4049
4050 else
4051 Get_First_Interp (Expr, I, It);
4052
4053 while Present (It.Nam) loop
4054 if Base_Type (It.Typ) /= Base_Type (T) then
4055 Remove_Interp (I);
4056 end if;
4057
4058 Get_Next_Interp (I, It);
4059 end loop;
4060 end if;
4061 end if;
4062
4063 Set_Etype (N, T);
4064 end Analyze_Qualified_Expression;
4065
4066 -----------------------------------
4067 -- Analyze_Quantified_Expression --
4068 -----------------------------------
4069
4070 procedure Analyze_Quantified_Expression (N : Node_Id) is
4071 function Is_Empty_Range (Typ : Entity_Id) return Boolean;
4072 -- If the iterator is part of a quantified expression, and the range is
4073 -- known to be statically empty, emit a warning and replace expression
4074 -- with its static value. Returns True if the replacement occurs.
4075
4076 function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean;
4077 -- Determine whether if expression If_Expr lacks an else part or if it
4078 -- has one, it evaluates to True.
4079
4080 --------------------
4081 -- Is_Empty_Range --
4082 --------------------
4083
4084 function Is_Empty_Range (Typ : Entity_Id) return Boolean is
4085 Loc : constant Source_Ptr := Sloc (N);
4086
4087 begin
4088 if Is_Array_Type (Typ)
4089 and then Compile_Time_Known_Bounds (Typ)
4090 and then
4091 (Expr_Value (Type_Low_Bound (Etype (First_Index (Typ)))) >
4092 Expr_Value (Type_High_Bound (Etype (First_Index (Typ)))))
4093 then
4094 Preanalyze_And_Resolve (Condition (N), Standard_Boolean);
4095
4096 if All_Present (N) then
4097 Error_Msg_N
4098 ("??quantified expression with ALL "
4099 & "over a null range has value True", N);
4100 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
4101
4102 else
4103 Error_Msg_N
4104 ("??quantified expression with SOME "
4105 & "over a null range has value False", N);
4106 Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
4107 end if;
4108
4109 Analyze (N);
4110 return True;
4111
4112 else
4113 return False;
4114 end if;
4115 end Is_Empty_Range;
4116
4117 -----------------------------
4118 -- No_Else_Or_Trivial_True --
4119 -----------------------------
4120
4121 function No_Else_Or_Trivial_True (If_Expr : Node_Id) return Boolean is
4122 Else_Expr : constant Node_Id :=
4123 Next (Next (First (Expressions (If_Expr))));
4124 begin
4125 return
4126 No (Else_Expr)
4127 or else (Compile_Time_Known_Value (Else_Expr)
4128 and then Is_True (Expr_Value (Else_Expr)));
4129 end No_Else_Or_Trivial_True;
4130
4131 -- Local variables
4132
4133 Cond : constant Node_Id := Condition (N);
4134 Loop_Id : Entity_Id;
4135 QE_Scop : Entity_Id;
4136
4137 -- Start of processing for Analyze_Quantified_Expression
4138
4139 begin
4140 -- Create a scope to emulate the loop-like behavior of the quantified
4141 -- expression. The scope is needed to provide proper visibility of the
4142 -- loop variable.
4143
4144 QE_Scop := New_Internal_Entity (E_Loop, Current_Scope, Sloc (N), 'L');
4145 Set_Etype (QE_Scop, Standard_Void_Type);
4146 Set_Scope (QE_Scop, Current_Scope);
4147 Set_Parent (QE_Scop, N);
4148
4149 Push_Scope (QE_Scop);
4150
4151 -- All constituents are preanalyzed and resolved to avoid untimely
4152 -- generation of various temporaries and types. Full analysis and
4153 -- expansion is carried out when the quantified expression is
4154 -- transformed into an expression with actions.
4155
4156 if Present (Iterator_Specification (N)) then
4157 Preanalyze (Iterator_Specification (N));
4158
4159 -- Do not proceed with the analysis when the range of iteration is
4160 -- empty. The appropriate error is issued by Is_Empty_Range.
4161
4162 if Is_Entity_Name (Name (Iterator_Specification (N)))
4163 and then Is_Empty_Range (Etype (Name (Iterator_Specification (N))))
4164 then
4165 return;
4166 end if;
4167
4168 else pragma Assert (Present (Loop_Parameter_Specification (N)));
4169 declare
4170 Loop_Par : constant Node_Id := Loop_Parameter_Specification (N);
4171
4172 begin
4173 Preanalyze (Loop_Par);
4174
4175 if Nkind (Discrete_Subtype_Definition (Loop_Par)) = N_Function_Call
4176 and then Parent (Loop_Par) /= N
4177 then
4178 -- The parser cannot distinguish between a loop specification
4179 -- and an iterator specification. If after preanalysis the
4180 -- proper form has been recognized, rewrite the expression to
4181 -- reflect the right kind. This is needed for proper ASIS
4182 -- navigation. If expansion is enabled, the transformation is
4183 -- performed when the expression is rewritten as a loop.
4184 -- Is this still needed???
4185
4186 Set_Iterator_Specification (N,
4187 New_Copy_Tree (Iterator_Specification (Parent (Loop_Par))));
4188
4189 Set_Defining_Identifier (Iterator_Specification (N),
4190 Relocate_Node (Defining_Identifier (Loop_Par)));
4191 Set_Name (Iterator_Specification (N),
4192 Relocate_Node (Discrete_Subtype_Definition (Loop_Par)));
4193 Set_Comes_From_Source (Iterator_Specification (N),
4194 Comes_From_Source (Loop_Parameter_Specification (N)));
4195 Set_Loop_Parameter_Specification (N, Empty);
4196 end if;
4197 end;
4198 end if;
4199
4200 Preanalyze_And_Resolve (Cond, Standard_Boolean);
4201
4202 End_Scope;
4203 Set_Etype (N, Standard_Boolean);
4204
4205 -- Verify that the loop variable is used within the condition of the
4206 -- quantified expression.
4207
4208 if Present (Iterator_Specification (N)) then
4209 Loop_Id := Defining_Identifier (Iterator_Specification (N));
4210 else
4211 Loop_Id := Defining_Identifier (Loop_Parameter_Specification (N));
4212 end if;
4213
4214 if Warn_On_Suspicious_Contract
4215 and then not Referenced (Loop_Id, Cond)
4216 then
4217 -- Generating C, this check causes spurious warnings on inlined
4218 -- postconditions; we can safely disable it because this check
4219 -- was previously performed when analyzing the internally built
4220 -- postconditions procedure.
4221
4222 if Modify_Tree_For_C and then In_Inlined_Body then
4223 null;
4224 else
4225 Error_Msg_N ("?T?unused variable &", Loop_Id);
4226 end if;
4227 end if;
4228
4229 -- Diagnose a possible misuse of the SOME existential quantifier. When
4230 -- we have a quantified expression of the form:
4231
4232 -- for some X => (if P then Q [else True])
4233
4234 -- any value for X that makes P False results in the if expression being
4235 -- trivially True, and so also results in the quantified expression
4236 -- being trivially True.
4237
4238 if Warn_On_Suspicious_Contract
4239 and then not All_Present (N)
4240 and then Nkind (Cond) = N_If_Expression
4241 and then No_Else_Or_Trivial_True (Cond)
4242 then
4243 Error_Msg_N ("?T?suspicious expression", N);
4244 Error_Msg_N ("\\did you mean (for all X ='> (if P then Q))", N);
4245 Error_Msg_N ("\\or (for some X ='> P and then Q) instead'?", N);
4246 end if;
4247 end Analyze_Quantified_Expression;
4248
4249 -------------------
4250 -- Analyze_Range --
4251 -------------------
4252
4253 procedure Analyze_Range (N : Node_Id) is
4254 L : constant Node_Id := Low_Bound (N);
4255 H : constant Node_Id := High_Bound (N);
4256 I1, I2 : Interp_Index;
4257 It1, It2 : Interp;
4258
4259 procedure Check_Common_Type (T1, T2 : Entity_Id);
4260 -- Verify the compatibility of two types, and choose the
4261 -- non universal one if the other is universal.
4262
4263 procedure Check_High_Bound (T : Entity_Id);
4264 -- Test one interpretation of the low bound against all those
4265 -- of the high bound.
4266
4267 procedure Check_Universal_Expression (N : Node_Id);
4268 -- In Ada 83, reject bounds of a universal range that are not literals
4269 -- or entity names.
4270
4271 -----------------------
4272 -- Check_Common_Type --
4273 -----------------------
4274
4275 procedure Check_Common_Type (T1, T2 : Entity_Id) is
4276 begin
4277 if Covers (T1 => T1, T2 => T2)
4278 or else
4279 Covers (T1 => T2, T2 => T1)
4280 then
4281 if T1 = Universal_Integer
4282 or else T1 = Universal_Real
4283 or else T1 = Any_Character
4284 then
4285 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
4286
4287 elsif T1 = T2 then
4288 Add_One_Interp (N, T1, T1);
4289
4290 else
4291 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
4292 end if;
4293 end if;
4294 end Check_Common_Type;
4295
4296 ----------------------
4297 -- Check_High_Bound --
4298 ----------------------
4299
4300 procedure Check_High_Bound (T : Entity_Id) is
4301 begin
4302 if not Is_Overloaded (H) then
4303 Check_Common_Type (T, Etype (H));
4304 else
4305 Get_First_Interp (H, I2, It2);
4306 while Present (It2.Typ) loop
4307 Check_Common_Type (T, It2.Typ);
4308 Get_Next_Interp (I2, It2);
4309 end loop;
4310 end if;
4311 end Check_High_Bound;
4312
4313 --------------------------------
4314 -- Check_Universal_Expression --
4315 --------------------------------
4316
4317 procedure Check_Universal_Expression (N : Node_Id) is
4318 begin
4319 if Etype (N) = Universal_Integer
4320 and then Nkind (N) /= N_Integer_Literal
4321 and then not Is_Entity_Name (N)
4322 and then Nkind (N) /= N_Attribute_Reference
4323 then
4324 Error_Msg_N ("illegal bound in discrete range", N);
4325 end if;
4326 end Check_Universal_Expression;
4327
4328 -- Start of processing for Analyze_Range
4329
4330 begin
4331 Set_Etype (N, Any_Type);
4332 Analyze_Expression (L);
4333 Analyze_Expression (H);
4334
4335 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
4336 return;
4337
4338 else
4339 if not Is_Overloaded (L) then
4340 Check_High_Bound (Etype (L));
4341 else
4342 Get_First_Interp (L, I1, It1);
4343 while Present (It1.Typ) loop
4344 Check_High_Bound (It1.Typ);
4345 Get_Next_Interp (I1, It1);
4346 end loop;
4347 end if;
4348
4349 -- If result is Any_Type, then we did not find a compatible pair
4350
4351 if Etype (N) = Any_Type then
4352 Error_Msg_N ("incompatible types in range ", N);
4353 end if;
4354 end if;
4355
4356 if Ada_Version = Ada_83
4357 and then
4358 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
4359 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
4360 then
4361 Check_Universal_Expression (L);
4362 Check_Universal_Expression (H);
4363 end if;
4364
4365 Check_Function_Writable_Actuals (N);
4366 end Analyze_Range;
4367
4368 -----------------------
4369 -- Analyze_Reference --
4370 -----------------------
4371
4372 procedure Analyze_Reference (N : Node_Id) is
4373 P : constant Node_Id := Prefix (N);
4374 E : Entity_Id;
4375 T : Entity_Id;
4376 Acc_Type : Entity_Id;
4377
4378 begin
4379 Analyze (P);
4380
4381 -- An interesting error check, if we take the 'Ref of an object for
4382 -- which a pragma Atomic or Volatile has been given, and the type of the
4383 -- object is not Atomic or Volatile, then we are in trouble. The problem
4384 -- is that no trace of the atomic/volatile status will remain for the
4385 -- backend to respect when it deals with the resulting pointer, since
4386 -- the pointer type will not be marked atomic (it is a pointer to the
4387 -- base type of the object).
4388
4389 -- It is not clear if that can ever occur, but in case it does, we will
4390 -- generate an error message. Not clear if this message can ever be
4391 -- generated, and pretty clear that it represents a bug if it is, still
4392 -- seems worth checking, except in CodePeer mode where we do not really
4393 -- care and don't want to bother the user.
4394
4395 T := Etype (P);
4396
4397 if Is_Entity_Name (P)
4398 and then Is_Object_Reference (P)
4399 and then not CodePeer_Mode
4400 then
4401 E := Entity (P);
4402 T := Etype (P);
4403
4404 if (Has_Atomic_Components (E)
4405 and then not Has_Atomic_Components (T))
4406 or else
4407 (Has_Volatile_Components (E)
4408 and then not Has_Volatile_Components (T))
4409 or else (Is_Atomic (E) and then not Is_Atomic (T))
4410 or else (Is_Volatile (E) and then not Is_Volatile (T))
4411 then
4412 Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
4413 end if;
4414 end if;
4415
4416 -- Carry on with normal processing
4417
4418 Acc_Type := Create_Itype (E_Allocator_Type, N);
4419 Set_Etype (Acc_Type, Acc_Type);
4420 Set_Directly_Designated_Type (Acc_Type, Etype (P));
4421 Set_Etype (N, Acc_Type);
4422 end Analyze_Reference;
4423
4424 --------------------------------
4425 -- Analyze_Selected_Component --
4426 --------------------------------
4427
4428 -- Prefix is a record type or a task or protected type. In the latter case,
4429 -- the selector must denote a visible entry.
4430
4431 procedure Analyze_Selected_Component (N : Node_Id) is
4432 Name : constant Node_Id := Prefix (N);
4433 Sel : constant Node_Id := Selector_Name (N);
4434 Act_Decl : Node_Id;
4435 Comp : Entity_Id;
4436 Has_Candidate : Boolean := False;
4437 Hidden_Comp : Entity_Id;
4438 In_Scope : Boolean;
4439 Is_Private_Op : Boolean;
4440 Parent_N : Node_Id;
4441 Prefix_Type : Entity_Id;
4442
4443 Type_To_Use : Entity_Id;
4444 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
4445 -- a class-wide type, we use its root type, whose components are
4446 -- present in the class-wide type.
4447
4448 Is_Single_Concurrent_Object : Boolean;
4449 -- Set True if the prefix is a single task or a single protected object
4450
4451 procedure Find_Component_In_Instance (Rec : Entity_Id);
4452 -- In an instance, a component of a private extension may not be visible
4453 -- while it was visible in the generic. Search candidate scope for a
4454 -- component with the proper identifier. This is only done if all other
4455 -- searches have failed. If a match is found, the Etype of both N and
4456 -- Sel are set from this component, and the entity of Sel is set to
4457 -- reference this component. If no match is found, Entity (Sel) remains
4458 -- unset. For a derived type that is an actual of the instance, the
4459 -- desired component may be found in any ancestor.
4460
4461 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
4462 -- It is known that the parent of N denotes a subprogram call. Comp
4463 -- is an overloadable component of the concurrent type of the prefix.
4464 -- Determine whether all formals of the parent of N and Comp are mode
4465 -- conformant. If the parent node is not analyzed yet it may be an
4466 -- indexed component rather than a function call.
4467
4468 function Has_Dereference (Nod : Node_Id) return Boolean;
4469 -- Check whether prefix includes a dereference, explicit or implicit,
4470 -- at any recursive level.
4471
4472 --------------------------------
4473 -- Find_Component_In_Instance --
4474 --------------------------------
4475
4476 procedure Find_Component_In_Instance (Rec : Entity_Id) is
4477 Comp : Entity_Id;
4478 Typ : Entity_Id;
4479
4480 begin
4481 Typ := Rec;
4482 while Present (Typ) loop
4483 Comp := First_Component (Typ);
4484 while Present (Comp) loop
4485 if Chars (Comp) = Chars (Sel) then
4486 Set_Entity_With_Checks (Sel, Comp);
4487 Set_Etype (Sel, Etype (Comp));
4488 Set_Etype (N, Etype (Comp));
4489 return;
4490 end if;
4491
4492 Next_Component (Comp);
4493 end loop;
4494
4495 -- If not found, the component may be declared in the parent
4496 -- type or its full view, if any.
4497
4498 if Is_Derived_Type (Typ) then
4499 Typ := Etype (Typ);
4500
4501 if Is_Private_Type (Typ) then
4502 Typ := Full_View (Typ);
4503 end if;
4504
4505 else
4506 return;
4507 end if;
4508 end loop;
4509
4510 -- If we fall through, no match, so no changes made
4511
4512 return;
4513 end Find_Component_In_Instance;
4514
4515 ------------------------------
4516 -- Has_Mode_Conformant_Spec --
4517 ------------------------------
4518
4519 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
4520 Comp_Param : Entity_Id;
4521 Param : Node_Id;
4522 Param_Typ : Entity_Id;
4523
4524 begin
4525 Comp_Param := First_Formal (Comp);
4526
4527 if Nkind (Parent (N)) = N_Indexed_Component then
4528 Param := First (Expressions (Parent (N)));
4529 else
4530 Param := First (Parameter_Associations (Parent (N)));
4531 end if;
4532
4533 while Present (Comp_Param)
4534 and then Present (Param)
4535 loop
4536 Param_Typ := Find_Parameter_Type (Param);
4537
4538 if Present (Param_Typ)
4539 and then
4540 not Conforming_Types
4541 (Etype (Comp_Param), Param_Typ, Mode_Conformant)
4542 then
4543 return False;
4544 end if;
4545
4546 Next_Formal (Comp_Param);
4547 Next (Param);
4548 end loop;
4549
4550 -- One of the specs has additional formals; there is no match, unless
4551 -- this may be an indexing of a parameterless call.
4552
4553 -- Note that when expansion is disabled, the corresponding record
4554 -- type of synchronized types is not constructed, so that there is
4555 -- no point is attempting an interpretation as a prefixed call, as
4556 -- this is bound to fail because the primitive operations will not
4557 -- be properly located.
4558
4559 if Present (Comp_Param) or else Present (Param) then
4560 if Needs_No_Actuals (Comp)
4561 and then Is_Array_Type (Etype (Comp))
4562 and then not Expander_Active
4563 then
4564 return True;
4565 else
4566 return False;
4567 end if;
4568 end if;
4569
4570 return True;
4571 end Has_Mode_Conformant_Spec;
4572
4573 ---------------------
4574 -- Has_Dereference --
4575 ---------------------
4576
4577 function Has_Dereference (Nod : Node_Id) return Boolean is
4578 begin
4579 if Nkind (Nod) = N_Explicit_Dereference then
4580 return True;
4581
4582 elsif Is_Access_Type (Etype (Nod)) then
4583 return True;
4584
4585 elsif Nkind_In (Nod, N_Indexed_Component, N_Selected_Component) then
4586 return Has_Dereference (Prefix (Nod));
4587
4588 else
4589 return False;
4590 end if;
4591 end Has_Dereference;
4592
4593 -- Start of processing for Analyze_Selected_Component
4594
4595 begin
4596 Set_Etype (N, Any_Type);
4597
4598 if Is_Overloaded (Name) then
4599 Analyze_Overloaded_Selected_Component (N);
4600 return;
4601
4602 elsif Etype (Name) = Any_Type then
4603 Set_Entity (Sel, Any_Id);
4604 Set_Etype (Sel, Any_Type);
4605 return;
4606
4607 else
4608 Prefix_Type := Etype (Name);
4609 end if;
4610
4611 if Is_Access_Type (Prefix_Type) then
4612
4613 -- A RACW object can never be used as prefix of a selected component
4614 -- since that means it is dereferenced without being a controlling
4615 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
4616 -- reporting an error, we must check whether this is actually a
4617 -- dispatching call in prefix form.
4618
4619 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
4620 and then Comes_From_Source (N)
4621 then
4622 if Try_Object_Operation (N) then
4623 return;
4624 else
4625 Error_Msg_N
4626 ("invalid dereference of a remote access-to-class-wide value",
4627 N);
4628 end if;
4629
4630 -- Normal case of selected component applied to access type
4631
4632 else
4633 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
4634 Prefix_Type := Implicitly_Designated_Type (Prefix_Type);
4635 end if;
4636
4637 -- If we have an explicit dereference of a remote access-to-class-wide
4638 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
4639 -- have to check for the case of a prefix that is a controlling operand
4640 -- of a prefixed dispatching call, as the dereference is legal in that
4641 -- case. Normally this condition is checked in Validate_Remote_Access_
4642 -- To_Class_Wide_Type, but we have to defer the checking for selected
4643 -- component prefixes because of the prefixed dispatching call case.
4644 -- Note that implicit dereferences are checked for this just above.
4645
4646 elsif Nkind (Name) = N_Explicit_Dereference
4647 and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
4648 and then Comes_From_Source (N)
4649 then
4650 if Try_Object_Operation (N) then
4651 return;
4652 else
4653 Error_Msg_N
4654 ("invalid dereference of a remote access-to-class-wide value",
4655 N);
4656 end if;
4657 end if;
4658
4659 -- (Ada 2005): if the prefix is the limited view of a type, and
4660 -- the context already includes the full view, use the full view
4661 -- in what follows, either to retrieve a component of to find
4662 -- a primitive operation. If the prefix is an explicit dereference,
4663 -- set the type of the prefix to reflect this transformation.
4664 -- If the nonlimited view is itself an incomplete type, get the
4665 -- full view if available.
4666
4667 if From_Limited_With (Prefix_Type)
4668 and then Has_Non_Limited_View (Prefix_Type)
4669 then
4670 Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
4671
4672 if Nkind (N) = N_Explicit_Dereference then
4673 Set_Etype (Prefix (N), Prefix_Type);
4674 end if;
4675 end if;
4676
4677 if Ekind (Prefix_Type) = E_Private_Subtype then
4678 Prefix_Type := Base_Type (Prefix_Type);
4679 end if;
4680
4681 Type_To_Use := Prefix_Type;
4682
4683 -- For class-wide types, use the entity list of the root type. This
4684 -- indirection is specially important for private extensions because
4685 -- only the root type get switched (not the class-wide type).
4686
4687 if Is_Class_Wide_Type (Prefix_Type) then
4688 Type_To_Use := Root_Type (Prefix_Type);
4689 end if;
4690
4691 -- If the prefix is a single concurrent object, use its name in error
4692 -- messages, rather than that of its anonymous type.
4693
4694 Is_Single_Concurrent_Object :=
4695 Is_Concurrent_Type (Prefix_Type)
4696 and then Is_Internal_Name (Chars (Prefix_Type))
4697 and then not Is_Derived_Type (Prefix_Type)
4698 and then Is_Entity_Name (Name);
4699
4700 Comp := First_Entity (Type_To_Use);
4701
4702 -- If the selector has an original discriminant, the node appears in
4703 -- an instance. Replace the discriminant with the corresponding one
4704 -- in the current discriminated type. For nested generics, this must
4705 -- be done transitively, so note the new original discriminant.
4706
4707 if Nkind (Sel) = N_Identifier
4708 and then In_Instance
4709 and then Present (Original_Discriminant (Sel))
4710 then
4711 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
4712
4713 -- Mark entity before rewriting, for completeness and because
4714 -- subsequent semantic checks might examine the original node.
4715
4716 Set_Entity (Sel, Comp);
4717 Rewrite (Selector_Name (N), New_Occurrence_Of (Comp, Sloc (N)));
4718 Set_Original_Discriminant (Selector_Name (N), Comp);
4719 Set_Etype (N, Etype (Comp));
4720 Check_Implicit_Dereference (N, Etype (Comp));
4721
4722 elsif Is_Record_Type (Prefix_Type) then
4723
4724 -- Find component with given name. In an instance, if the node is
4725 -- known as a prefixed call, do not examine components whose
4726 -- visibility may be accidental.
4727
4728 while Present (Comp) and then not Is_Prefixed_Call (N) loop
4729 if Chars (Comp) = Chars (Sel)
4730 and then Is_Visible_Component (Comp, N)
4731 then
4732 Set_Entity_With_Checks (Sel, Comp);
4733 Set_Etype (Sel, Etype (Comp));
4734
4735 if Ekind (Comp) = E_Discriminant then
4736 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
4737 Error_Msg_N
4738 ("cannot reference discriminant of unchecked union",
4739 Sel);
4740 end if;
4741
4742 if Is_Generic_Type (Prefix_Type)
4743 or else
4744 Is_Generic_Type (Root_Type (Prefix_Type))
4745 then
4746 Set_Original_Discriminant (Sel, Comp);
4747 end if;
4748 end if;
4749
4750 -- Resolve the prefix early otherwise it is not possible to
4751 -- build the actual subtype of the component: it may need
4752 -- to duplicate this prefix and duplication is only allowed
4753 -- on fully resolved expressions.
4754
4755 Resolve (Name);
4756
4757 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
4758 -- subtypes in a package specification.
4759 -- Example:
4760
4761 -- limited with Pkg;
4762 -- package Pkg is
4763 -- type Acc_Inc is access Pkg.T;
4764 -- X : Acc_Inc;
4765 -- N : Natural := X.all.Comp; -- ERROR, limited view
4766 -- end Pkg; -- Comp is not visible
4767
4768 if Nkind (Name) = N_Explicit_Dereference
4769 and then From_Limited_With (Etype (Prefix (Name)))
4770 and then not Is_Potentially_Use_Visible (Etype (Name))
4771 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
4772 N_Package_Specification
4773 then
4774 Error_Msg_NE
4775 ("premature usage of incomplete}", Prefix (Name),
4776 Etype (Prefix (Name)));
4777 end if;
4778
4779 -- We never need an actual subtype for the case of a selection
4780 -- for a indexed component of a non-packed array, since in
4781 -- this case gigi generates all the checks and can find the
4782 -- necessary bounds information.
4783
4784 -- We also do not need an actual subtype for the case of a
4785 -- first, last, length, or range attribute applied to a
4786 -- non-packed array, since gigi can again get the bounds in
4787 -- these cases (gigi cannot handle the packed case, since it
4788 -- has the bounds of the packed array type, not the original
4789 -- bounds of the type). However, if the prefix is itself a
4790 -- selected component, as in a.b.c (i), gigi may regard a.b.c
4791 -- as a dynamic-sized temporary, so we do generate an actual
4792 -- subtype for this case.
4793
4794 Parent_N := Parent (N);
4795
4796 if not Is_Packed (Etype (Comp))
4797 and then
4798 ((Nkind (Parent_N) = N_Indexed_Component
4799 and then Nkind (Name) /= N_Selected_Component)
4800 or else
4801 (Nkind (Parent_N) = N_Attribute_Reference
4802 and then
4803 Nam_In (Attribute_Name (Parent_N), Name_First,
4804 Name_Last,
4805 Name_Length,
4806 Name_Range)))
4807 then
4808 Set_Etype (N, Etype (Comp));
4809
4810 -- If full analysis is not enabled, we do not generate an
4811 -- actual subtype, because in the absence of expansion
4812 -- reference to a formal of a protected type, for example,
4813 -- will not be properly transformed, and will lead to
4814 -- out-of-scope references in gigi.
4815
4816 -- In all other cases, we currently build an actual subtype.
4817 -- It seems likely that many of these cases can be avoided,
4818 -- but right now, the front end makes direct references to the
4819 -- bounds (e.g. in generating a length check), and if we do
4820 -- not make an actual subtype, we end up getting a direct
4821 -- reference to a discriminant, which will not do.
4822
4823 elsif Full_Analysis then
4824 Act_Decl :=
4825 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
4826 Insert_Action (N, Act_Decl);
4827
4828 if No (Act_Decl) then
4829 Set_Etype (N, Etype (Comp));
4830
4831 else
4832 -- If discriminants were present in the component
4833 -- declaration, they have been replaced by the
4834 -- actual values in the prefix object.
4835
4836 declare
4837 Subt : constant Entity_Id :=
4838 Defining_Identifier (Act_Decl);
4839 begin
4840 Set_Etype (Subt, Base_Type (Etype (Comp)));
4841 Set_Etype (N, Subt);
4842 end;
4843 end if;
4844
4845 -- If Full_Analysis not enabled, just set the Etype
4846
4847 else
4848 Set_Etype (N, Etype (Comp));
4849 end if;
4850
4851 Check_Implicit_Dereference (N, Etype (N));
4852 return;
4853 end if;
4854
4855 -- If the prefix is a private extension, check only the visible
4856 -- components of the partial view. This must include the tag,
4857 -- which can appear in expanded code in a tag check.
4858
4859 if Ekind (Type_To_Use) = E_Record_Type_With_Private
4860 and then Chars (Selector_Name (N)) /= Name_uTag
4861 then
4862 exit when Comp = Last_Entity (Type_To_Use);
4863 end if;
4864
4865 Next_Entity (Comp);
4866 end loop;
4867
4868 -- Ada 2005 (AI-252): The selected component can be interpreted as
4869 -- a prefixed view of a subprogram. Depending on the context, this is
4870 -- either a name that can appear in a renaming declaration, or part
4871 -- of an enclosing call given in prefix form.
4872
4873 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
4874 -- selected component should resolve to a name.
4875
4876 if Ada_Version >= Ada_2005
4877 and then Is_Tagged_Type (Prefix_Type)
4878 and then not Is_Concurrent_Type (Prefix_Type)
4879 then
4880 if Nkind (Parent (N)) = N_Generic_Association
4881 or else Nkind (Parent (N)) = N_Requeue_Statement
4882 or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
4883 then
4884 if Find_Primitive_Operation (N) then
4885 return;
4886 end if;
4887
4888 elsif Try_Object_Operation (N) then
4889 return;
4890 end if;
4891
4892 -- If the transformation fails, it will be necessary to redo the
4893 -- analysis with all errors enabled, to indicate candidate
4894 -- interpretations and reasons for each failure ???
4895
4896 end if;
4897
4898 elsif Is_Private_Type (Prefix_Type) then
4899
4900 -- Allow access only to discriminants of the type. If the type has
4901 -- no full view, gigi uses the parent type for the components, so we
4902 -- do the same here.
4903
4904 if No (Full_View (Prefix_Type)) then
4905 Type_To_Use := Root_Type (Base_Type (Prefix_Type));
4906 Comp := First_Entity (Type_To_Use);
4907 end if;
4908
4909 while Present (Comp) loop
4910 if Chars (Comp) = Chars (Sel) then
4911 if Ekind (Comp) = E_Discriminant then
4912 Set_Entity_With_Checks (Sel, Comp);
4913 Generate_Reference (Comp, Sel);
4914
4915 Set_Etype (Sel, Etype (Comp));
4916 Set_Etype (N, Etype (Comp));
4917 Check_Implicit_Dereference (N, Etype (N));
4918
4919 if Is_Generic_Type (Prefix_Type)
4920 or else Is_Generic_Type (Root_Type (Prefix_Type))
4921 then
4922 Set_Original_Discriminant (Sel, Comp);
4923 end if;
4924
4925 -- Before declaring an error, check whether this is tagged
4926 -- private type and a call to a primitive operation.
4927
4928 elsif Ada_Version >= Ada_2005
4929 and then Is_Tagged_Type (Prefix_Type)
4930 and then Try_Object_Operation (N)
4931 then
4932 return;
4933
4934 else
4935 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4936 Error_Msg_NE ("invisible selector& for }", N, Sel);
4937 Set_Entity (Sel, Any_Id);
4938 Set_Etype (N, Any_Type);
4939 end if;
4940
4941 return;
4942 end if;
4943
4944 Next_Entity (Comp);
4945 end loop;
4946
4947 elsif Is_Concurrent_Type (Prefix_Type) then
4948
4949 -- Find visible operation with given name. For a protected type,
4950 -- the possible candidates are discriminants, entries or protected
4951 -- subprograms. For a task type, the set can only include entries or
4952 -- discriminants if the task type is not an enclosing scope. If it
4953 -- is an enclosing scope (e.g. in an inner task) then all entities
4954 -- are visible, but the prefix must denote the enclosing scope, i.e.
4955 -- can only be a direct name or an expanded name.
4956
4957 Set_Etype (Sel, Any_Type);
4958 Hidden_Comp := Empty;
4959 In_Scope := In_Open_Scopes (Prefix_Type);
4960 Is_Private_Op := False;
4961
4962 while Present (Comp) loop
4963
4964 -- Do not examine private operations of the type if not within
4965 -- its scope.
4966
4967 if Chars (Comp) = Chars (Sel) then
4968 if Is_Overloadable (Comp)
4969 and then (In_Scope
4970 or else Comp /= First_Private_Entity (Type_To_Use))
4971 then
4972 Add_One_Interp (Sel, Comp, Etype (Comp));
4973 if Comp = First_Private_Entity (Type_To_Use) then
4974 Is_Private_Op := True;
4975 end if;
4976
4977 -- If the prefix is tagged, the correct interpretation may
4978 -- lie in the primitive or class-wide operations of the
4979 -- type. Perform a simple conformance check to determine
4980 -- whether Try_Object_Operation should be invoked even if
4981 -- a visible entity is found.
4982
4983 if Is_Tagged_Type (Prefix_Type)
4984 and then Nkind_In (Parent (N), N_Function_Call,
4985 N_Indexed_Component,
4986 N_Procedure_Call_Statement)
4987 and then Has_Mode_Conformant_Spec (Comp)
4988 then
4989 Has_Candidate := True;
4990 end if;
4991
4992 -- Note: a selected component may not denote a component of a
4993 -- protected type (4.1.3(7)).
4994
4995 elsif Ekind_In (Comp, E_Discriminant, E_Entry_Family)
4996 or else (In_Scope
4997 and then not Is_Protected_Type (Prefix_Type)
4998 and then Is_Entity_Name (Name))
4999 then
5000 Set_Entity_With_Checks (Sel, Comp);
5001 Generate_Reference (Comp, Sel);
5002
5003 -- The selector is not overloadable, so we have a candidate
5004 -- interpretation.
5005
5006 Has_Candidate := True;
5007
5008 else
5009 if Ekind (Comp) = E_Component then
5010 Hidden_Comp := Comp;
5011 end if;
5012
5013 goto Next_Comp;
5014 end if;
5015
5016 Set_Etype (Sel, Etype (Comp));
5017 Set_Etype (N, Etype (Comp));
5018
5019 if Ekind (Comp) = E_Discriminant then
5020 Set_Original_Discriminant (Sel, Comp);
5021 end if;
5022 end if;
5023
5024 <<Next_Comp>>
5025 if Comp = First_Private_Entity (Type_To_Use) then
5026 if Etype (Sel) /= Any_Type then
5027
5028 -- If the first private entity's name matches, then treat
5029 -- it as a private op: needed for the error check for
5030 -- illegal selection of private entities further below.
5031
5032 if Chars (Comp) = Chars (Sel) then
5033 Is_Private_Op := True;
5034 end if;
5035
5036 -- We have a candidate, so exit the loop
5037
5038 exit;
5039
5040 else
5041 -- Indicate that subsequent operations are private,
5042 -- for better error reporting.
5043
5044 Is_Private_Op := True;
5045 end if;
5046 end if;
5047
5048 -- Do not examine private operations if not within scope of
5049 -- the synchronized type.
5050
5051 exit when not In_Scope
5052 and then
5053 Comp = First_Private_Entity (Base_Type (Prefix_Type));
5054 Next_Entity (Comp);
5055 end loop;
5056
5057 -- If the scope is a current instance, the prefix cannot be an
5058 -- expression of the same type, unless the selector designates a
5059 -- public operation (otherwise that would represent an attempt to
5060 -- reach an internal entity of another synchronized object).
5061
5062 -- This is legal if prefix is an access to such type and there is
5063 -- a dereference, or is a component with a dereferenced prefix.
5064 -- It is also legal if the prefix is a component of a task type,
5065 -- and the selector is one of the task operations.
5066
5067 if In_Scope
5068 and then not Is_Entity_Name (Name)
5069 and then not Has_Dereference (Name)
5070 then
5071 if Is_Task_Type (Prefix_Type)
5072 and then Present (Entity (Sel))
5073 and then Is_Entry (Entity (Sel))
5074 then
5075 null;
5076
5077 elsif Is_Protected_Type (Prefix_Type)
5078 and then Is_Overloadable (Entity (Sel))
5079 and then not Is_Private_Op
5080 then
5081 null;
5082
5083 else
5084 Error_Msg_NE
5085 ("invalid reference to internal operation of some object of "
5086 & "type &", N, Type_To_Use);
5087 Set_Entity (Sel, Any_Id);
5088 Set_Etype (Sel, Any_Type);
5089 return;
5090 end if;
5091
5092 -- Another special case: the prefix may denote an object of the type
5093 -- (but not a type) in which case this is an external call and the
5094 -- operation must be public.
5095
5096 elsif In_Scope
5097 and then Is_Object_Reference (Original_Node (Prefix (N)))
5098 and then Comes_From_Source (N)
5099 and then Is_Private_Op
5100 then
5101 if Present (Hidden_Comp) then
5102 Error_Msg_NE
5103 ("invalid reference to private component of object of type "
5104 & "&", N, Type_To_Use);
5105
5106 else
5107 Error_Msg_NE
5108 ("invalid reference to private operation of some object of "
5109 & "type &", N, Type_To_Use);
5110 end if;
5111
5112 Set_Entity (Sel, Any_Id);
5113 Set_Etype (Sel, Any_Type);
5114 return;
5115 end if;
5116
5117 -- If there is no visible entity with the given name or none of the
5118 -- visible entities are plausible interpretations, check whether
5119 -- there is some other primitive operation with that name.
5120
5121 if Ada_Version >= Ada_2005 and then Is_Tagged_Type (Prefix_Type) then
5122 if (Etype (N) = Any_Type
5123 or else not Has_Candidate)
5124 and then Try_Object_Operation (N)
5125 then
5126 return;
5127
5128 -- If the context is not syntactically a procedure call, it
5129 -- may be a call to a primitive function declared outside of
5130 -- the synchronized type.
5131
5132 -- If the context is a procedure call, there might still be
5133 -- an overloading between an entry and a primitive procedure
5134 -- declared outside of the synchronized type, called in prefix
5135 -- notation. This is harder to disambiguate because in one case
5136 -- the controlling formal is implicit ???
5137
5138 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
5139 and then Nkind (Parent (N)) /= N_Indexed_Component
5140 and then Try_Object_Operation (N)
5141 then
5142 return;
5143 end if;
5144
5145 -- Ada 2012 (AI05-0090-1): If we found a candidate of a call to an
5146 -- entry or procedure of a tagged concurrent type we must check
5147 -- if there are class-wide subprograms covering the primitive. If
5148 -- true then Try_Object_Operation reports the error.
5149
5150 if Has_Candidate
5151 and then Is_Concurrent_Type (Prefix_Type)
5152 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
5153 then
5154 -- Duplicate the call. This is required to avoid problems with
5155 -- the tree transformations performed by Try_Object_Operation.
5156 -- Set properly the parent of the copied call, because it is
5157 -- about to be reanalyzed.
5158
5159 declare
5160 Par : constant Node_Id := New_Copy_Tree (Parent (N));
5161
5162 begin
5163 Set_Parent (Par, Parent (Parent (N)));
5164
5165 if Try_Object_Operation
5166 (Sinfo.Name (Par), CW_Test_Only => True)
5167 then
5168 return;
5169 end if;
5170 end;
5171 end if;
5172 end if;
5173
5174 if Etype (N) = Any_Type and then Is_Protected_Type (Prefix_Type) then
5175
5176 -- Case of a prefix of a protected type: selector might denote
5177 -- an invisible private component.
5178
5179 Comp := First_Private_Entity (Base_Type (Prefix_Type));
5180 while Present (Comp) and then Chars (Comp) /= Chars (Sel) loop
5181 Next_Entity (Comp);
5182 end loop;
5183
5184 if Present (Comp) then
5185 if Is_Single_Concurrent_Object then
5186 Error_Msg_Node_2 := Entity (Name);
5187 Error_Msg_NE ("invisible selector& for &", N, Sel);
5188
5189 else
5190 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
5191 Error_Msg_NE ("invisible selector& for }", N, Sel);
5192 end if;
5193 return;
5194 end if;
5195 end if;
5196
5197 Set_Is_Overloaded (N, Is_Overloaded (Sel));
5198
5199 else
5200 -- Invalid prefix
5201
5202 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
5203 end if;
5204
5205 -- If N still has no type, the component is not defined in the prefix
5206
5207 if Etype (N) = Any_Type then
5208
5209 if Is_Single_Concurrent_Object then
5210 Error_Msg_Node_2 := Entity (Name);
5211 Error_Msg_NE ("no selector& for&", N, Sel);
5212
5213 Check_Misspelled_Selector (Type_To_Use, Sel);
5214
5215 -- If this is a derived formal type, the parent may have different
5216 -- visibility at this point. Try for an inherited component before
5217 -- reporting an error.
5218
5219 elsif Is_Generic_Type (Prefix_Type)
5220 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
5221 and then Prefix_Type /= Etype (Prefix_Type)
5222 and then Is_Record_Type (Etype (Prefix_Type))
5223 then
5224 Set_Etype (Prefix (N), Etype (Prefix_Type));
5225 Analyze_Selected_Component (N);
5226 return;
5227
5228 -- Similarly, if this is the actual for a formal derived type, or
5229 -- a derived type thereof, the component inherited from the generic
5230 -- parent may not be visible in the actual, but the selected
5231 -- component is legal. Climb up the derivation chain of the generic
5232 -- parent type until we find the proper ancestor type.
5233
5234 elsif In_Instance and then Is_Tagged_Type (Prefix_Type) then
5235 declare
5236 Par : Entity_Id := Prefix_Type;
5237 begin
5238 -- Climb up derivation chain to generic actual subtype
5239
5240 while not Is_Generic_Actual_Type (Par) loop
5241 if Ekind (Par) = E_Record_Type then
5242 Par := Parent_Subtype (Par);
5243 exit when No (Par);
5244 else
5245 exit when Par = Etype (Par);
5246 Par := Etype (Par);
5247 end if;
5248 end loop;
5249
5250 if Present (Par) and then Is_Generic_Actual_Type (Par) then
5251
5252 -- Now look for component in ancestor types
5253
5254 Par := Generic_Parent_Type (Declaration_Node (Par));
5255 loop
5256 Find_Component_In_Instance (Par);
5257 exit when Present (Entity (Sel))
5258 or else Par = Etype (Par);
5259 Par := Etype (Par);
5260 end loop;
5261
5262 -- Another special case: the type is an extension of a private
5263 -- type T, is an actual in an instance, and we are in the body
5264 -- of the instance, so the generic body had a full view of the
5265 -- type declaration for T or of some ancestor that defines the
5266 -- component in question.
5267
5268 elsif Is_Derived_Type (Type_To_Use)
5269 and then Used_As_Generic_Actual (Type_To_Use)
5270 and then In_Instance_Body
5271 then
5272 Find_Component_In_Instance (Parent_Subtype (Type_To_Use));
5273
5274 -- In ASIS mode the generic parent type may be absent. Examine
5275 -- the parent type directly for a component that may have been
5276 -- visible in a parent generic unit.
5277 -- ??? Revisit now that ASIS mode is gone
5278
5279 elsif Is_Derived_Type (Prefix_Type) then
5280 Par := Etype (Prefix_Type);
5281 Find_Component_In_Instance (Par);
5282 end if;
5283 end;
5284
5285 -- The search above must have eventually succeeded, since the
5286 -- selected component was legal in the generic.
5287
5288 if No (Entity (Sel)) then
5289 raise Program_Error;
5290 end if;
5291
5292 return;
5293
5294 -- Component not found, specialize error message when appropriate
5295
5296 else
5297 if Ekind (Prefix_Type) = E_Record_Subtype then
5298
5299 -- Check whether this is a component of the base type which
5300 -- is absent from a statically constrained subtype. This will
5301 -- raise constraint error at run time, but is not a compile-
5302 -- time error. When the selector is illegal for base type as
5303 -- well fall through and generate a compilation error anyway.
5304
5305 Comp := First_Component (Base_Type (Prefix_Type));
5306 while Present (Comp) loop
5307 if Chars (Comp) = Chars (Sel)
5308 and then Is_Visible_Component (Comp, Sel)
5309 then
5310 Set_Entity_With_Checks (Sel, Comp);
5311 Generate_Reference (Comp, Sel);
5312 Set_Etype (Sel, Etype (Comp));
5313 Set_Etype (N, Etype (Comp));
5314
5315 -- Emit appropriate message. The node will be replaced
5316 -- by an appropriate raise statement.
5317
5318 -- Note that in SPARK mode, as with all calls to apply a
5319 -- compile time constraint error, this will be made into
5320 -- an error to simplify the processing of the formal
5321 -- verification backend.
5322
5323 Apply_Compile_Time_Constraint_Error
5324 (N, "component not present in }??",
5325 CE_Discriminant_Check_Failed,
5326 Ent => Prefix_Type, Rep => False);
5327
5328 Set_Raises_Constraint_Error (N);
5329 return;
5330 end if;
5331
5332 Next_Component (Comp);
5333 end loop;
5334
5335 end if;
5336
5337 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
5338 Error_Msg_NE ("no selector& for}", N, Sel);
5339
5340 -- Add information in the case of an incomplete prefix
5341
5342 if Is_Incomplete_Type (Type_To_Use) then
5343 declare
5344 Inc : constant Entity_Id := First_Subtype (Type_To_Use);
5345
5346 begin
5347 if From_Limited_With (Scope (Type_To_Use)) then
5348 Error_Msg_NE
5349 ("\limited view of& has no components", N, Inc);
5350
5351 else
5352 Error_Msg_NE
5353 ("\premature usage of incomplete type&", N, Inc);
5354
5355 if Nkind (Parent (Inc)) =
5356 N_Incomplete_Type_Declaration
5357 then
5358 -- Record location of premature use in entity so that
5359 -- a continuation message is generated when the
5360 -- completion is seen.
5361
5362 Set_Premature_Use (Parent (Inc), N);
5363 end if;
5364 end if;
5365 end;
5366 end if;
5367
5368 Check_Misspelled_Selector (Type_To_Use, Sel);
5369 end if;
5370
5371 Set_Entity (Sel, Any_Id);
5372 Set_Etype (Sel, Any_Type);
5373 end if;
5374 end Analyze_Selected_Component;
5375
5376 ---------------------------
5377 -- Analyze_Short_Circuit --
5378 ---------------------------
5379
5380 procedure Analyze_Short_Circuit (N : Node_Id) is
5381 L : constant Node_Id := Left_Opnd (N);
5382 R : constant Node_Id := Right_Opnd (N);
5383 Ind : Interp_Index;
5384 It : Interp;
5385
5386 begin
5387 Analyze_Expression (L);
5388 Analyze_Expression (R);
5389 Set_Etype (N, Any_Type);
5390
5391 if not Is_Overloaded (L) then
5392 if Root_Type (Etype (L)) = Standard_Boolean
5393 and then Has_Compatible_Type (R, Etype (L))
5394 then
5395 Add_One_Interp (N, Etype (L), Etype (L));
5396 end if;
5397
5398 else
5399 Get_First_Interp (L, Ind, It);
5400 while Present (It.Typ) loop
5401 if Root_Type (It.Typ) = Standard_Boolean
5402 and then Has_Compatible_Type (R, It.Typ)
5403 then
5404 Add_One_Interp (N, It.Typ, It.Typ);
5405 end if;
5406
5407 Get_Next_Interp (Ind, It);
5408 end loop;
5409 end if;
5410
5411 -- Here we have failed to find an interpretation. Clearly we know that
5412 -- it is not the case that both operands can have an interpretation of
5413 -- Boolean, but this is by far the most likely intended interpretation.
5414 -- So we simply resolve both operands as Booleans, and at least one of
5415 -- these resolutions will generate an error message, and we do not need
5416 -- to give another error message on the short circuit operation itself.
5417
5418 if Etype (N) = Any_Type then
5419 Resolve (L, Standard_Boolean);
5420 Resolve (R, Standard_Boolean);
5421 Set_Etype (N, Standard_Boolean);
5422 end if;
5423 end Analyze_Short_Circuit;
5424
5425 -------------------
5426 -- Analyze_Slice --
5427 -------------------
5428
5429 procedure Analyze_Slice (N : Node_Id) is
5430 D : constant Node_Id := Discrete_Range (N);
5431 P : constant Node_Id := Prefix (N);
5432 Array_Type : Entity_Id;
5433 Index_Type : Entity_Id;
5434
5435 procedure Analyze_Overloaded_Slice;
5436 -- If the prefix is overloaded, select those interpretations that
5437 -- yield a one-dimensional array type.
5438
5439 ------------------------------
5440 -- Analyze_Overloaded_Slice --
5441 ------------------------------
5442
5443 procedure Analyze_Overloaded_Slice is
5444 I : Interp_Index;
5445 It : Interp;
5446 Typ : Entity_Id;
5447
5448 begin
5449 Set_Etype (N, Any_Type);
5450
5451 Get_First_Interp (P, I, It);
5452 while Present (It.Nam) loop
5453 Typ := It.Typ;
5454
5455 if Is_Access_Type (Typ) then
5456 Typ := Designated_Type (Typ);
5457 Error_Msg_NW
5458 (Warn_On_Dereference, "?d?implicit dereference", N);
5459 end if;
5460
5461 if Is_Array_Type (Typ)
5462 and then Number_Dimensions (Typ) = 1
5463 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
5464 then
5465 Add_One_Interp (N, Typ, Typ);
5466 end if;
5467
5468 Get_Next_Interp (I, It);
5469 end loop;
5470
5471 if Etype (N) = Any_Type then
5472 Error_Msg_N ("expect array type in prefix of slice", N);
5473 end if;
5474 end Analyze_Overloaded_Slice;
5475
5476 -- Start of processing for Analyze_Slice
5477
5478 begin
5479 Analyze (P);
5480 Analyze (D);
5481
5482 if Is_Overloaded (P) then
5483 Analyze_Overloaded_Slice;
5484
5485 else
5486 Array_Type := Etype (P);
5487 Set_Etype (N, Any_Type);
5488
5489 if Is_Access_Type (Array_Type) then
5490 Error_Msg_NW (Warn_On_Dereference, "?d?implicit dereference", N);
5491 Array_Type := Implicitly_Designated_Type (Array_Type);
5492 end if;
5493
5494 if not Is_Array_Type (Array_Type) then
5495 Wrong_Type (P, Any_Array);
5496
5497 elsif Number_Dimensions (Array_Type) > 1 then
5498 Error_Msg_N
5499 ("type is not one-dimensional array in slice prefix", N);
5500
5501 else
5502 if Ekind (Array_Type) = E_String_Literal_Subtype then
5503 Index_Type := Etype (String_Literal_Low_Bound (Array_Type));
5504 else
5505 Index_Type := Etype (First_Index (Array_Type));
5506 end if;
5507
5508 if not Has_Compatible_Type (D, Index_Type) then
5509 Wrong_Type (D, Index_Type);
5510 else
5511 Set_Etype (N, Array_Type);
5512 end if;
5513 end if;
5514 end if;
5515 end Analyze_Slice;
5516
5517 -----------------------------
5518 -- Analyze_Type_Conversion --
5519 -----------------------------
5520
5521 procedure Analyze_Type_Conversion (N : Node_Id) is
5522 Expr : constant Node_Id := Expression (N);
5523 Typ : Entity_Id;
5524
5525 begin
5526 -- If Conversion_OK is set, then the Etype is already set, and the only
5527 -- processing required is to analyze the expression. This is used to
5528 -- construct certain "illegal" conversions which are not allowed by Ada
5529 -- semantics, but can be handled by Gigi, see Sinfo for further details.
5530
5531 if Conversion_OK (N) then
5532 Analyze (Expr);
5533 return;
5534 end if;
5535
5536 -- Otherwise full type analysis is required, as well as some semantic
5537 -- checks to make sure the argument of the conversion is appropriate.
5538
5539 Find_Type (Subtype_Mark (N));
5540 Typ := Entity (Subtype_Mark (N));
5541 Set_Etype (N, Typ);
5542 Check_Fully_Declared (Typ, N);
5543 Analyze_Expression (Expr);
5544 Validate_Remote_Type_Type_Conversion (N);
5545
5546 -- Only remaining step is validity checks on the argument. These
5547 -- are skipped if the conversion does not come from the source.
5548
5549 if not Comes_From_Source (N) then
5550 return;
5551
5552 -- If there was an error in a generic unit, no need to replicate the
5553 -- error message. Conversely, constant-folding in the generic may
5554 -- transform the argument of a conversion into a string literal, which
5555 -- is legal. Therefore the following tests are not performed in an
5556 -- instance. The same applies to an inlined body.
5557
5558 elsif In_Instance or In_Inlined_Body then
5559 return;
5560
5561 elsif Nkind (Expr) = N_Null then
5562 Error_Msg_N ("argument of conversion cannot be null", N);
5563 Error_Msg_N ("\use qualified expression instead", N);
5564 Set_Etype (N, Any_Type);
5565
5566 elsif Nkind (Expr) = N_Aggregate then
5567 Error_Msg_N ("argument of conversion cannot be aggregate", N);
5568 Error_Msg_N ("\use qualified expression instead", N);
5569
5570 elsif Nkind (Expr) = N_Allocator then
5571 Error_Msg_N ("argument of conversion cannot be an allocator", N);
5572 Error_Msg_N ("\use qualified expression instead", N);
5573
5574 elsif Nkind (Expr) = N_String_Literal then
5575 Error_Msg_N ("argument of conversion cannot be string literal", N);
5576 Error_Msg_N ("\use qualified expression instead", N);
5577
5578 elsif Nkind (Expr) = N_Character_Literal then
5579 if Ada_Version = Ada_83 then
5580 Resolve (Expr, Typ);
5581 else
5582 Error_Msg_N ("argument of conversion cannot be character literal",
5583 N);
5584 Error_Msg_N ("\use qualified expression instead", N);
5585 end if;
5586
5587 elsif Nkind (Expr) = N_Attribute_Reference
5588 and then Nam_In (Attribute_Name (Expr), Name_Access,
5589 Name_Unchecked_Access,
5590 Name_Unrestricted_Access)
5591 then
5592 Error_Msg_N ("argument of conversion cannot be access", N);
5593 Error_Msg_N ("\use qualified expression instead", N);
5594 end if;
5595
5596 -- A formal parameter of a specific tagged type whose related subprogram
5597 -- is subject to pragma Extensions_Visible with value "False" cannot
5598 -- appear in a class-wide conversion (SPARK RM 6.1.7(3)). Do not check
5599 -- internally generated expressions.
5600
5601 if Is_Class_Wide_Type (Typ)
5602 and then Comes_From_Source (Expr)
5603 and then Is_EVF_Expression (Expr)
5604 then
5605 Error_Msg_N
5606 ("formal parameter cannot be converted to class-wide type when "
5607 & "Extensions_Visible is False", Expr);
5608 end if;
5609 end Analyze_Type_Conversion;
5610
5611 ----------------------
5612 -- Analyze_Unary_Op --
5613 ----------------------
5614
5615 procedure Analyze_Unary_Op (N : Node_Id) is
5616 R : constant Node_Id := Right_Opnd (N);
5617 Op_Id : Entity_Id := Entity (N);
5618
5619 begin
5620 Set_Etype (N, Any_Type);
5621 Candidate_Type := Empty;
5622
5623 Analyze_Expression (R);
5624
5625 if Present (Op_Id) then
5626 if Ekind (Op_Id) = E_Operator then
5627 Find_Unary_Types (R, Op_Id, N);
5628 else
5629 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5630 end if;
5631
5632 else
5633 Op_Id := Get_Name_Entity_Id (Chars (N));
5634 while Present (Op_Id) loop
5635 if Ekind (Op_Id) = E_Operator then
5636 if No (Next_Entity (First_Entity (Op_Id))) then
5637 Find_Unary_Types (R, Op_Id, N);
5638 end if;
5639
5640 elsif Is_Overloadable (Op_Id) then
5641 Analyze_User_Defined_Unary_Op (N, Op_Id);
5642 end if;
5643
5644 Op_Id := Homonym (Op_Id);
5645 end loop;
5646 end if;
5647
5648 Operator_Check (N);
5649 end Analyze_Unary_Op;
5650
5651 ----------------------------------
5652 -- Analyze_Unchecked_Expression --
5653 ----------------------------------
5654
5655 procedure Analyze_Unchecked_Expression (N : Node_Id) is
5656 begin
5657 Analyze (Expression (N), Suppress => All_Checks);
5658 Set_Etype (N, Etype (Expression (N)));
5659 Save_Interps (Expression (N), N);
5660 end Analyze_Unchecked_Expression;
5661
5662 ---------------------------------------
5663 -- Analyze_Unchecked_Type_Conversion --
5664 ---------------------------------------
5665
5666 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
5667 begin
5668 Find_Type (Subtype_Mark (N));
5669 Analyze_Expression (Expression (N));
5670 Set_Etype (N, Entity (Subtype_Mark (N)));
5671 end Analyze_Unchecked_Type_Conversion;
5672
5673 ------------------------------------
5674 -- Analyze_User_Defined_Binary_Op --
5675 ------------------------------------
5676
5677 procedure Analyze_User_Defined_Binary_Op
5678 (N : Node_Id;
5679 Op_Id : Entity_Id) is
5680 begin
5681 declare
5682 F1 : constant Entity_Id := First_Formal (Op_Id);
5683 F2 : constant Entity_Id := Next_Formal (F1);
5684
5685 begin
5686 -- Verify that Op_Id is a visible binary function. Note that since
5687 -- we know Op_Id is overloaded, potentially use visible means use
5688 -- visible for sure (RM 9.4(11)).
5689
5690 if Ekind (Op_Id) = E_Function
5691 and then Present (F2)
5692 and then (Is_Immediately_Visible (Op_Id)
5693 or else Is_Potentially_Use_Visible (Op_Id))
5694 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
5695 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
5696 then
5697 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5698
5699 -- If the left operand is overloaded, indicate that the current
5700 -- type is a viable candidate. This is redundant in most cases,
5701 -- but for equality and comparison operators where the context
5702 -- does not impose a type on the operands, setting the proper
5703 -- type is necessary to avoid subsequent ambiguities during
5704 -- resolution, when both user-defined and predefined operators
5705 -- may be candidates.
5706
5707 if Is_Overloaded (Left_Opnd (N)) then
5708 Set_Etype (Left_Opnd (N), Etype (F1));
5709 end if;
5710
5711 if Debug_Flag_E then
5712 Write_Str ("user defined operator ");
5713 Write_Name (Chars (Op_Id));
5714 Write_Str (" on node ");
5715 Write_Int (Int (N));
5716 Write_Eol;
5717 end if;
5718 end if;
5719 end;
5720 end Analyze_User_Defined_Binary_Op;
5721
5722 -----------------------------------
5723 -- Analyze_User_Defined_Unary_Op --
5724 -----------------------------------
5725
5726 procedure Analyze_User_Defined_Unary_Op
5727 (N : Node_Id;
5728 Op_Id : Entity_Id)
5729 is
5730 begin
5731 -- Only do analysis if the operator Comes_From_Source, since otherwise
5732 -- the operator was generated by the expander, and all such operators
5733 -- always refer to the operators in package Standard.
5734
5735 if Comes_From_Source (N) then
5736 declare
5737 F : constant Entity_Id := First_Formal (Op_Id);
5738
5739 begin
5740 -- Verify that Op_Id is a visible unary function. Note that since
5741 -- we know Op_Id is overloaded, potentially use visible means use
5742 -- visible for sure (RM 9.4(11)).
5743
5744 if Ekind (Op_Id) = E_Function
5745 and then No (Next_Formal (F))
5746 and then (Is_Immediately_Visible (Op_Id)
5747 or else Is_Potentially_Use_Visible (Op_Id))
5748 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
5749 then
5750 Add_One_Interp (N, Op_Id, Etype (Op_Id));
5751 end if;
5752 end;
5753 end if;
5754 end Analyze_User_Defined_Unary_Op;
5755
5756 ---------------------------
5757 -- Check_Arithmetic_Pair --
5758 ---------------------------
5759
5760 procedure Check_Arithmetic_Pair
5761 (T1, T2 : Entity_Id;
5762 Op_Id : Entity_Id;
5763 N : Node_Id)
5764 is
5765 Op_Name : constant Name_Id := Chars (Op_Id);
5766
5767 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
5768 -- Check whether the fixed-point type Typ has a user-defined operator
5769 -- (multiplication or division) that should hide the corresponding
5770 -- predefined operator. Used to implement Ada 2005 AI-264, to make
5771 -- such operators more visible and therefore useful.
5772 --
5773 -- If the name of the operation is an expanded name with prefix
5774 -- Standard, the predefined universal fixed operator is available,
5775 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
5776
5777 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
5778 -- Get specific type (i.e. non-universal type if there is one)
5779
5780 ------------------
5781 -- Has_Fixed_Op --
5782 ------------------
5783
5784 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
5785 Bas : constant Entity_Id := Base_Type (Typ);
5786 Ent : Entity_Id;
5787 F1 : Entity_Id;
5788 F2 : Entity_Id;
5789
5790 begin
5791 -- If the universal_fixed operation is given explicitly the rule
5792 -- concerning primitive operations of the type do not apply.
5793
5794 if Nkind (N) = N_Function_Call
5795 and then Nkind (Name (N)) = N_Expanded_Name
5796 and then Entity (Prefix (Name (N))) = Standard_Standard
5797 then
5798 return False;
5799 end if;
5800
5801 -- The operation is treated as primitive if it is declared in the
5802 -- same scope as the type, and therefore on the same entity chain.
5803
5804 Ent := Next_Entity (Typ);
5805 while Present (Ent) loop
5806 if Chars (Ent) = Chars (Op) then
5807 F1 := First_Formal (Ent);
5808 F2 := Next_Formal (F1);
5809
5810 -- The operation counts as primitive if either operand or
5811 -- result are of the given base type, and both operands are
5812 -- fixed point types.
5813
5814 if (Base_Type (Etype (F1)) = Bas
5815 and then Is_Fixed_Point_Type (Etype (F2)))
5816
5817 or else
5818 (Base_Type (Etype (F2)) = Bas
5819 and then Is_Fixed_Point_Type (Etype (F1)))
5820
5821 or else
5822 (Base_Type (Etype (Ent)) = Bas
5823 and then Is_Fixed_Point_Type (Etype (F1))
5824 and then Is_Fixed_Point_Type (Etype (F2)))
5825 then
5826 return True;
5827 end if;
5828 end if;
5829
5830 Next_Entity (Ent);
5831 end loop;
5832
5833 return False;
5834 end Has_Fixed_Op;
5835
5836 -------------------
5837 -- Specific_Type --
5838 -------------------
5839
5840 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
5841 begin
5842 if T1 = Universal_Integer or else T1 = Universal_Real then
5843 return Base_Type (T2);
5844 else
5845 return Base_Type (T1);
5846 end if;
5847 end Specific_Type;
5848
5849 -- Start of processing for Check_Arithmetic_Pair
5850
5851 begin
5852 if Nam_In (Op_Name, Name_Op_Add, Name_Op_Subtract) then
5853 if Is_Numeric_Type (T1)
5854 and then Is_Numeric_Type (T2)
5855 and then (Covers (T1 => T1, T2 => T2)
5856 or else
5857 Covers (T1 => T2, T2 => T1))
5858 then
5859 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5860 end if;
5861
5862 elsif Nam_In (Op_Name, Name_Op_Multiply, Name_Op_Divide) then
5863 if Is_Fixed_Point_Type (T1)
5864 and then (Is_Fixed_Point_Type (T2) or else T2 = Universal_Real)
5865 then
5866 -- Add one interpretation with universal fixed result
5867
5868 if not Has_Fixed_Op (T1, Op_Id)
5869 or else Nkind (Parent (N)) = N_Type_Conversion
5870 then
5871 Add_One_Interp (N, Op_Id, Universal_Fixed);
5872 end if;
5873
5874 elsif Is_Fixed_Point_Type (T2)
5875 and then T1 = Universal_Real
5876 and then
5877 (not Has_Fixed_Op (T1, Op_Id)
5878 or else Nkind (Parent (N)) = N_Type_Conversion)
5879 then
5880 Add_One_Interp (N, Op_Id, Universal_Fixed);
5881
5882 elsif Is_Numeric_Type (T1)
5883 and then Is_Numeric_Type (T2)
5884 and then (Covers (T1 => T1, T2 => T2)
5885 or else
5886 Covers (T1 => T2, T2 => T1))
5887 then
5888 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5889
5890 elsif Is_Fixed_Point_Type (T1)
5891 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5892 or else T2 = Universal_Integer)
5893 then
5894 Add_One_Interp (N, Op_Id, T1);
5895
5896 elsif T2 = Universal_Real
5897 and then Base_Type (T1) = Base_Type (Standard_Integer)
5898 and then Op_Name = Name_Op_Multiply
5899 then
5900 Add_One_Interp (N, Op_Id, Any_Fixed);
5901
5902 elsif T1 = Universal_Real
5903 and then Base_Type (T2) = Base_Type (Standard_Integer)
5904 then
5905 Add_One_Interp (N, Op_Id, Any_Fixed);
5906
5907 elsif Is_Fixed_Point_Type (T2)
5908 and then (Base_Type (T1) = Base_Type (Standard_Integer)
5909 or else T1 = Universal_Integer)
5910 and then Op_Name = Name_Op_Multiply
5911 then
5912 Add_One_Interp (N, Op_Id, T2);
5913
5914 elsif T1 = Universal_Real and then T2 = Universal_Integer then
5915 Add_One_Interp (N, Op_Id, T1);
5916
5917 elsif T2 = Universal_Real
5918 and then T1 = Universal_Integer
5919 and then Op_Name = Name_Op_Multiply
5920 then
5921 Add_One_Interp (N, Op_Id, T2);
5922 end if;
5923
5924 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
5925
5926 if Is_Integer_Type (T1)
5927 and then (Covers (T1 => T1, T2 => T2)
5928 or else
5929 Covers (T1 => T2, T2 => T1))
5930 then
5931 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
5932 end if;
5933
5934 elsif Op_Name = Name_Op_Expon then
5935 if Is_Numeric_Type (T1)
5936 and then not Is_Fixed_Point_Type (T1)
5937 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5938 or else T2 = Universal_Integer)
5939 then
5940 Add_One_Interp (N, Op_Id, Base_Type (T1));
5941 end if;
5942
5943 else pragma Assert (Nkind (N) in N_Op_Shift);
5944
5945 -- If not one of the predefined operators, the node may be one
5946 -- of the intrinsic functions. Its kind is always specific, and
5947 -- we can use it directly, rather than the name of the operation.
5948
5949 if Is_Integer_Type (T1)
5950 and then (Base_Type (T2) = Base_Type (Standard_Integer)
5951 or else T2 = Universal_Integer)
5952 then
5953 Add_One_Interp (N, Op_Id, Base_Type (T1));
5954 end if;
5955 end if;
5956 end Check_Arithmetic_Pair;
5957
5958 -------------------------------
5959 -- Check_Misspelled_Selector --
5960 -------------------------------
5961
5962 procedure Check_Misspelled_Selector
5963 (Prefix : Entity_Id;
5964 Sel : Node_Id)
5965 is
5966 Max_Suggestions : constant := 2;
5967 Nr_Of_Suggestions : Natural := 0;
5968
5969 Suggestion_1 : Entity_Id := Empty;
5970 Suggestion_2 : Entity_Id := Empty;
5971
5972 Comp : Entity_Id;
5973
5974 begin
5975 -- All the components of the prefix of selector Sel are matched against
5976 -- Sel and a count is maintained of possible misspellings. When at
5977 -- the end of the analysis there are one or two (not more) possible
5978 -- misspellings, these misspellings will be suggested as possible
5979 -- correction.
5980
5981 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
5982
5983 -- Concurrent types should be handled as well ???
5984
5985 return;
5986 end if;
5987
5988 Comp := First_Entity (Prefix);
5989 while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
5990 if Is_Visible_Component (Comp, Sel) then
5991 if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
5992 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
5993
5994 case Nr_Of_Suggestions is
5995 when 1 => Suggestion_1 := Comp;
5996 when 2 => Suggestion_2 := Comp;
5997 when others => null;
5998 end case;
5999 end if;
6000 end if;
6001
6002 Next_Entity (Comp);
6003 end loop;
6004
6005 -- Report at most two suggestions
6006
6007 if Nr_Of_Suggestions = 1 then
6008 Error_Msg_NE -- CODEFIX
6009 ("\possible misspelling of&", Sel, Suggestion_1);
6010
6011 elsif Nr_Of_Suggestions = 2 then
6012 Error_Msg_Node_2 := Suggestion_2;
6013 Error_Msg_NE -- CODEFIX
6014 ("\possible misspelling of& or&", Sel, Suggestion_1);
6015 end if;
6016 end Check_Misspelled_Selector;
6017
6018 ----------------------
6019 -- Defined_In_Scope --
6020 ----------------------
6021
6022 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
6023 is
6024 S1 : constant Entity_Id := Scope (Base_Type (T));
6025 begin
6026 return S1 = S
6027 or else (S1 = System_Aux_Id and then S = Scope (S1));
6028 end Defined_In_Scope;
6029
6030 -------------------
6031 -- Diagnose_Call --
6032 -------------------
6033
6034 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
6035 Actual : Node_Id;
6036 X : Interp_Index;
6037 It : Interp;
6038 Err_Mode : Boolean;
6039 New_Nam : Node_Id;
6040 Void_Interp_Seen : Boolean := False;
6041
6042 Success : Boolean;
6043 pragma Warnings (Off, Boolean);
6044
6045 begin
6046 if Ada_Version >= Ada_2005 then
6047 Actual := First_Actual (N);
6048 while Present (Actual) loop
6049
6050 -- Ada 2005 (AI-50217): Post an error in case of premature
6051 -- usage of an entity from the limited view.
6052
6053 if not Analyzed (Etype (Actual))
6054 and then From_Limited_With (Etype (Actual))
6055 then
6056 Error_Msg_Qual_Level := 1;
6057 Error_Msg_NE
6058 ("missing with_clause for scope of imported type&",
6059 Actual, Etype (Actual));
6060 Error_Msg_Qual_Level := 0;
6061 end if;
6062
6063 Next_Actual (Actual);
6064 end loop;
6065 end if;
6066
6067 -- Before listing the possible candidates, check whether this is
6068 -- a prefix of a selected component that has been rewritten as a
6069 -- parameterless function call because there is a callable candidate
6070 -- interpretation. If there is a hidden package in the list of homonyms
6071 -- of the function name (bad programming style in any case) suggest that
6072 -- this is the intended entity.
6073
6074 if No (Parameter_Associations (N))
6075 and then Nkind (Parent (N)) = N_Selected_Component
6076 and then Nkind (Parent (Parent (N))) in N_Declaration
6077 and then Is_Overloaded (Nam)
6078 then
6079 declare
6080 Ent : Entity_Id;
6081
6082 begin
6083 Ent := Current_Entity (Nam);
6084 while Present (Ent) loop
6085 if Ekind (Ent) = E_Package then
6086 Error_Msg_N
6087 ("no legal interpretations as function call,!", Nam);
6088 Error_Msg_NE ("\package& is not visible", N, Ent);
6089
6090 Rewrite (Parent (N),
6091 New_Occurrence_Of (Any_Type, Sloc (N)));
6092 return;
6093 end if;
6094
6095 Ent := Homonym (Ent);
6096 end loop;
6097 end;
6098 end if;
6099
6100 -- Analyze each candidate call again, with full error reporting for
6101 -- each.
6102
6103 Error_Msg_N
6104 ("no candidate interpretations match the actuals:!", Nam);
6105 Err_Mode := All_Errors_Mode;
6106 All_Errors_Mode := True;
6107
6108 -- If this is a call to an operation of a concurrent type,
6109 -- the failed interpretations have been removed from the
6110 -- name. Recover them to provide full diagnostics.
6111
6112 if Nkind (Parent (Nam)) = N_Selected_Component then
6113 Set_Entity (Nam, Empty);
6114 New_Nam := New_Copy_Tree (Parent (Nam));
6115 Set_Is_Overloaded (New_Nam, False);
6116 Set_Is_Overloaded (Selector_Name (New_Nam), False);
6117 Set_Parent (New_Nam, Parent (Parent (Nam)));
6118 Analyze_Selected_Component (New_Nam);
6119 Get_First_Interp (Selector_Name (New_Nam), X, It);
6120 else
6121 Get_First_Interp (Nam, X, It);
6122 end if;
6123
6124 while Present (It.Nam) loop
6125 if Etype (It.Nam) = Standard_Void_Type then
6126 Void_Interp_Seen := True;
6127 end if;
6128
6129 Analyze_One_Call (N, It.Nam, True, Success);
6130 Get_Next_Interp (X, It);
6131 end loop;
6132
6133 if Nkind (N) = N_Function_Call then
6134 Get_First_Interp (Nam, X, It);
6135
6136 if No (It.Typ)
6137 and then Ekind (Entity (Name (N))) = E_Function
6138 and then Present (Homonym (Entity (Name (N))))
6139 then
6140 -- A name may appear overloaded if it has a homonym, even if that
6141 -- homonym is non-overloadable, in which case the overload list is
6142 -- in fact empty. This specialized case deserves a special message
6143 -- if the homonym is a child package.
6144
6145 declare
6146 Nam : constant Node_Id := Name (N);
6147 H : constant Entity_Id := Homonym (Entity (Nam));
6148
6149 begin
6150 if Ekind (H) = E_Package and then Is_Child_Unit (H) then
6151 Error_Msg_Qual_Level := 2;
6152 Error_Msg_NE ("if an entity in package& is meant, ", Nam, H);
6153 Error_Msg_NE ("\use a fully qualified name", Nam, H);
6154 Error_Msg_Qual_Level := 0;
6155 end if;
6156 end;
6157
6158 else
6159 while Present (It.Nam) loop
6160 if Ekind_In (It.Nam, E_Function, E_Operator) then
6161 return;
6162 else
6163 Get_Next_Interp (X, It);
6164 end if;
6165 end loop;
6166
6167 -- If all interpretations are procedures, this deserves a more
6168 -- precise message. Ditto if this appears as the prefix of a
6169 -- selected component, which may be a lexical error.
6170
6171 Error_Msg_N
6172 ("\context requires function call, found procedure name", Nam);
6173
6174 if Nkind (Parent (N)) = N_Selected_Component
6175 and then N = Prefix (Parent (N))
6176 then
6177 Error_Msg_N -- CODEFIX
6178 ("\period should probably be semicolon", Parent (N));
6179 end if;
6180 end if;
6181
6182 elsif Nkind (N) = N_Procedure_Call_Statement
6183 and then not Void_Interp_Seen
6184 then
6185 Error_Msg_N ("\function name found in procedure call", Nam);
6186 end if;
6187
6188 All_Errors_Mode := Err_Mode;
6189 end Diagnose_Call;
6190
6191 ---------------------------
6192 -- Find_Arithmetic_Types --
6193 ---------------------------
6194
6195 procedure Find_Arithmetic_Types
6196 (L, R : Node_Id;
6197 Op_Id : Entity_Id;
6198 N : Node_Id)
6199 is
6200 Index1 : Interp_Index;
6201 Index2 : Interp_Index;
6202 It1 : Interp;
6203 It2 : Interp;
6204
6205 procedure Check_Right_Argument (T : Entity_Id);
6206 -- Check right operand of operator
6207
6208 --------------------------
6209 -- Check_Right_Argument --
6210 --------------------------
6211
6212 procedure Check_Right_Argument (T : Entity_Id) is
6213 begin
6214 if not Is_Overloaded (R) then
6215 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
6216 else
6217 Get_First_Interp (R, Index2, It2);
6218 while Present (It2.Typ) loop
6219 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
6220 Get_Next_Interp (Index2, It2);
6221 end loop;
6222 end if;
6223 end Check_Right_Argument;
6224
6225 -- Start of processing for Find_Arithmetic_Types
6226
6227 begin
6228 if not Is_Overloaded (L) then
6229 Check_Right_Argument (Etype (L));
6230
6231 else
6232 Get_First_Interp (L, Index1, It1);
6233 while Present (It1.Typ) loop
6234 Check_Right_Argument (It1.Typ);
6235 Get_Next_Interp (Index1, It1);
6236 end loop;
6237 end if;
6238
6239 end Find_Arithmetic_Types;
6240
6241 ------------------------
6242 -- Find_Boolean_Types --
6243 ------------------------
6244
6245 procedure Find_Boolean_Types
6246 (L, R : Node_Id;
6247 Op_Id : Entity_Id;
6248 N : Node_Id)
6249 is
6250 Index : Interp_Index;
6251 It : Interp;
6252
6253 procedure Check_Numeric_Argument (T : Entity_Id);
6254 -- Special case for logical operations one of whose operands is an
6255 -- integer literal. If both are literal the result is any modular type.
6256
6257 ----------------------------
6258 -- Check_Numeric_Argument --
6259 ----------------------------
6260
6261 procedure Check_Numeric_Argument (T : Entity_Id) is
6262 begin
6263 if T = Universal_Integer then
6264 Add_One_Interp (N, Op_Id, Any_Modular);
6265
6266 elsif Is_Modular_Integer_Type (T) then
6267 Add_One_Interp (N, Op_Id, T);
6268 end if;
6269 end Check_Numeric_Argument;
6270
6271 -- Start of processing for Find_Boolean_Types
6272
6273 begin
6274 if not Is_Overloaded (L) then
6275 if Etype (L) = Universal_Integer
6276 or else Etype (L) = Any_Modular
6277 then
6278 if not Is_Overloaded (R) then
6279 Check_Numeric_Argument (Etype (R));
6280
6281 else
6282 Get_First_Interp (R, Index, It);
6283 while Present (It.Typ) loop
6284 Check_Numeric_Argument (It.Typ);
6285 Get_Next_Interp (Index, It);
6286 end loop;
6287 end if;
6288
6289 -- If operands are aggregates, we must assume that they may be
6290 -- boolean arrays, and leave disambiguation for the second pass.
6291 -- If only one is an aggregate, verify that the other one has an
6292 -- interpretation as a boolean array
6293
6294 elsif Nkind (L) = N_Aggregate then
6295 if Nkind (R) = N_Aggregate then
6296 Add_One_Interp (N, Op_Id, Etype (L));
6297
6298 elsif not Is_Overloaded (R) then
6299 if Valid_Boolean_Arg (Etype (R)) then
6300 Add_One_Interp (N, Op_Id, Etype (R));
6301 end if;
6302
6303 else
6304 Get_First_Interp (R, Index, It);
6305 while Present (It.Typ) loop
6306 if Valid_Boolean_Arg (It.Typ) then
6307 Add_One_Interp (N, Op_Id, It.Typ);
6308 end if;
6309
6310 Get_Next_Interp (Index, It);
6311 end loop;
6312 end if;
6313
6314 elsif Valid_Boolean_Arg (Etype (L))
6315 and then Has_Compatible_Type (R, Etype (L))
6316 then
6317 Add_One_Interp (N, Op_Id, Etype (L));
6318 end if;
6319
6320 else
6321 Get_First_Interp (L, Index, It);
6322 while Present (It.Typ) loop
6323 if Valid_Boolean_Arg (It.Typ)
6324 and then Has_Compatible_Type (R, It.Typ)
6325 then
6326 Add_One_Interp (N, Op_Id, It.Typ);
6327 end if;
6328
6329 Get_Next_Interp (Index, It);
6330 end loop;
6331 end if;
6332 end Find_Boolean_Types;
6333
6334 ---------------------------
6335 -- Find_Comparison_Types --
6336 ---------------------------
6337
6338 procedure Find_Comparison_Types
6339 (L, R : Node_Id;
6340 Op_Id : Entity_Id;
6341 N : Node_Id)
6342 is
6343 Index : Interp_Index;
6344 It : Interp;
6345 Found : Boolean := False;
6346 I_F : Interp_Index;
6347 T_F : Entity_Id;
6348 Scop : Entity_Id := Empty;
6349
6350 procedure Try_One_Interp (T1 : Entity_Id);
6351 -- Routine to try one proposed interpretation. Note that the context
6352 -- of the operator plays no role in resolving the arguments, so that
6353 -- if there is more than one interpretation of the operands that is
6354 -- compatible with comparison, the operation is ambiguous.
6355
6356 --------------------
6357 -- Try_One_Interp --
6358 --------------------
6359
6360 procedure Try_One_Interp (T1 : Entity_Id) is
6361 begin
6362 -- If the operator is an expanded name, then the type of the operand
6363 -- must be defined in the corresponding scope. If the type is
6364 -- universal, the context will impose the correct type. Note that we
6365 -- also avoid returning if we are currently within a generic instance
6366 -- due to the fact that the generic package declaration has already
6367 -- been successfully analyzed and Defined_In_Scope expects the base
6368 -- type to be defined within the instance which will never be the
6369 -- case.
6370
6371 if Present (Scop)
6372 and then not Defined_In_Scope (T1, Scop)
6373 and then not In_Instance
6374 and then T1 /= Universal_Integer
6375 and then T1 /= Universal_Real
6376 and then T1 /= Any_String
6377 and then T1 /= Any_Composite
6378 then
6379 return;
6380 end if;
6381
6382 if Valid_Comparison_Arg (T1) and then Has_Compatible_Type (R, T1) then
6383 if Found and then Base_Type (T1) /= Base_Type (T_F) then
6384 It := Disambiguate (L, I_F, Index, Any_Type);
6385
6386 if It = No_Interp then
6387 Ambiguous_Operands (N);
6388 Set_Etype (L, Any_Type);
6389 return;
6390
6391 else
6392 T_F := It.Typ;
6393 end if;
6394 else
6395 Found := True;
6396 T_F := T1;
6397 I_F := Index;
6398 end if;
6399
6400 Set_Etype (L, T_F);
6401 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
6402 end if;
6403 end Try_One_Interp;
6404
6405 -- Start of processing for Find_Comparison_Types
6406
6407 begin
6408 -- If left operand is aggregate, the right operand has to
6409 -- provide a usable type for it.
6410
6411 if Nkind (L) = N_Aggregate and then Nkind (R) /= N_Aggregate then
6412 Find_Comparison_Types (L => R, R => L, Op_Id => Op_Id, N => N);
6413 return;
6414 end if;
6415
6416 if Nkind (N) = N_Function_Call
6417 and then Nkind (Name (N)) = N_Expanded_Name
6418 then
6419 Scop := Entity (Prefix (Name (N)));
6420
6421 -- The prefix may be a package renaming, and the subsequent test
6422 -- requires the original package.
6423
6424 if Ekind (Scop) = E_Package
6425 and then Present (Renamed_Entity (Scop))
6426 then
6427 Scop := Renamed_Entity (Scop);
6428 Set_Entity (Prefix (Name (N)), Scop);
6429 end if;
6430 end if;
6431
6432 if not Is_Overloaded (L) then
6433 Try_One_Interp (Etype (L));
6434
6435 else
6436 Get_First_Interp (L, Index, It);
6437 while Present (It.Typ) loop
6438 Try_One_Interp (It.Typ);
6439 Get_Next_Interp (Index, It);
6440 end loop;
6441 end if;
6442 end Find_Comparison_Types;
6443
6444 ----------------------------------------
6445 -- Find_Non_Universal_Interpretations --
6446 ----------------------------------------
6447
6448 procedure Find_Non_Universal_Interpretations
6449 (N : Node_Id;
6450 R : Node_Id;
6451 Op_Id : Entity_Id;
6452 T1 : Entity_Id)
6453 is
6454 Index : Interp_Index;
6455 It : Interp;
6456
6457 begin
6458 if T1 = Universal_Integer or else T1 = Universal_Real
6459
6460 -- If the left operand of an equality operator is null, the visibility
6461 -- of the operator must be determined from the interpretation of the
6462 -- right operand. This processing must be done for Any_Access, which
6463 -- is the internal representation of the type of the literal null.
6464
6465 or else T1 = Any_Access
6466 then
6467 if not Is_Overloaded (R) then
6468 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
6469 else
6470 Get_First_Interp (R, Index, It);
6471 while Present (It.Typ) loop
6472 if Covers (It.Typ, T1) then
6473 Add_One_Interp
6474 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
6475 end if;
6476
6477 Get_Next_Interp (Index, It);
6478 end loop;
6479 end if;
6480 else
6481 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
6482 end if;
6483 end Find_Non_Universal_Interpretations;
6484
6485 ------------------------------
6486 -- Find_Concatenation_Types --
6487 ------------------------------
6488
6489 procedure Find_Concatenation_Types
6490 (L, R : Node_Id;
6491 Op_Id : Entity_Id;
6492 N : Node_Id)
6493 is
6494 Is_String : constant Boolean := Nkind (L) = N_String_Literal
6495 or else
6496 Nkind (R) = N_String_Literal;
6497 Op_Type : constant Entity_Id := Etype (Op_Id);
6498
6499 begin
6500 if Is_Array_Type (Op_Type)
6501
6502 -- Small but very effective optimization: if at least one operand is a
6503 -- string literal, then the type of the operator must be either array
6504 -- of characters or array of strings.
6505
6506 and then (not Is_String
6507 or else
6508 Is_Character_Type (Component_Type (Op_Type))
6509 or else
6510 Is_String_Type (Component_Type (Op_Type)))
6511
6512 and then not Is_Limited_Type (Op_Type)
6513
6514 and then (Has_Compatible_Type (L, Op_Type)
6515 or else
6516 Has_Compatible_Type (L, Component_Type (Op_Type)))
6517
6518 and then (Has_Compatible_Type (R, Op_Type)
6519 or else
6520 Has_Compatible_Type (R, Component_Type (Op_Type)))
6521 then
6522 Add_One_Interp (N, Op_Id, Op_Type);
6523 end if;
6524 end Find_Concatenation_Types;
6525
6526 -------------------------
6527 -- Find_Equality_Types --
6528 -------------------------
6529
6530 procedure Find_Equality_Types
6531 (L, R : Node_Id;
6532 Op_Id : Entity_Id;
6533 N : Node_Id)
6534 is
6535 Index : Interp_Index;
6536 It : Interp;
6537 Found : Boolean := False;
6538 I_F : Interp_Index;
6539 T_F : Entity_Id;
6540 Scop : Entity_Id := Empty;
6541
6542 procedure Try_One_Interp (T1 : Entity_Id);
6543 -- The context of the equality operator plays no role in resolving the
6544 -- arguments, so that if there is more than one interpretation of the
6545 -- operands that is compatible with equality, the construct is ambiguous
6546 -- and an error can be emitted now, after trying to disambiguate, i.e.
6547 -- applying preference rules.
6548
6549 --------------------
6550 -- Try_One_Interp --
6551 --------------------
6552
6553 procedure Try_One_Interp (T1 : Entity_Id) is
6554 Bas : Entity_Id;
6555
6556 begin
6557 -- Perform a sanity check in case of previous errors
6558
6559 if No (T1) then
6560 return;
6561 end if;
6562
6563 Bas := Base_Type (T1);
6564
6565 -- If the operator is an expanded name, then the type of the operand
6566 -- must be defined in the corresponding scope. If the type is
6567 -- universal, the context will impose the correct type. An anonymous
6568 -- type for a 'Access reference is also universal in this sense, as
6569 -- the actual type is obtained from context.
6570
6571 -- In Ada 2005, the equality operator for anonymous access types
6572 -- is declared in Standard, and preference rules apply to it.
6573
6574 if Present (Scop) then
6575
6576 -- Note that we avoid returning if we are currently within a
6577 -- generic instance due to the fact that the generic package
6578 -- declaration has already been successfully analyzed and
6579 -- Defined_In_Scope expects the base type to be defined within
6580 -- the instance which will never be the case.
6581
6582 if Defined_In_Scope (T1, Scop)
6583 or else In_Instance
6584 or else T1 = Universal_Integer
6585 or else T1 = Universal_Real
6586 or else T1 = Any_Access
6587 or else T1 = Any_String
6588 or else T1 = Any_Composite
6589 or else (Ekind (T1) = E_Access_Subprogram_Type
6590 and then not Comes_From_Source (T1))
6591 then
6592 null;
6593
6594 elsif Ekind (T1) = E_Anonymous_Access_Type
6595 and then Scop = Standard_Standard
6596 then
6597 null;
6598
6599 else
6600 -- The scope does not contain an operator for the type
6601
6602 return;
6603 end if;
6604
6605 -- If we have infix notation, the operator must be usable. Within
6606 -- an instance, if the type is already established we know it is
6607 -- correct. If an operand is universal it is compatible with any
6608 -- numeric type.
6609
6610 elsif In_Open_Scopes (Scope (Bas))
6611 or else Is_Potentially_Use_Visible (Bas)
6612 or else In_Use (Bas)
6613 or else (In_Use (Scope (Bas)) and then not Is_Hidden (Bas))
6614
6615 -- In an instance, the type may have been immediately visible.
6616 -- Either the types are compatible, or one operand is universal
6617 -- (numeric or null).
6618
6619 or else
6620 ((In_Instance or else In_Inlined_Body)
6621 and then
6622 (First_Subtype (T1) = First_Subtype (Etype (R))
6623 or else Nkind (R) = N_Null
6624 or else
6625 (Is_Numeric_Type (T1)
6626 and then Is_Universal_Numeric_Type (Etype (R)))))
6627
6628 -- In Ada 2005, the equality on anonymous access types is declared
6629 -- in Standard, and is always visible.
6630
6631 or else Ekind (T1) = E_Anonymous_Access_Type
6632 then
6633 null;
6634
6635 else
6636 -- Save candidate type for subsequent error message, if any
6637
6638 if not Is_Limited_Type (T1) then
6639 Candidate_Type := T1;
6640 end if;
6641
6642 return;
6643 end if;
6644
6645 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
6646 -- Do not allow anonymous access types in equality operators.
6647
6648 if Ada_Version < Ada_2005
6649 and then Ekind (T1) = E_Anonymous_Access_Type
6650 then
6651 return;
6652 end if;
6653
6654 -- If the right operand has a type compatible with T1, check for an
6655 -- acceptable interpretation, unless T1 is limited (no predefined
6656 -- equality available), or this is use of a "/=" for a tagged type.
6657 -- In the latter case, possible interpretations of equality need
6658 -- to be considered, we don't want the default inequality declared
6659 -- in Standard to be chosen, and the "/=" will be rewritten as a
6660 -- negation of "=" (see the end of Analyze_Equality_Op). This ensures
6661 -- that rewriting happens during analysis rather than being
6662 -- delayed until expansion (is this still needed now that ASIS mode
6663 -- is gone???). Note that if the node is N_Op_Ne, but Op_Id
6664 -- is Name_Op_Eq then we still proceed with the interpretation,
6665 -- because that indicates the potential rewriting case where the
6666 -- interpretation to consider is actually "=" and the node may be
6667 -- about to be rewritten by Analyze_Equality_Op.
6668
6669 if T1 /= Standard_Void_Type
6670 and then Has_Compatible_Type (R, T1)
6671
6672 and then
6673 ((not Is_Limited_Type (T1)
6674 and then not Is_Limited_Composite (T1))
6675
6676 or else
6677 (Is_Array_Type (T1)
6678 and then not Is_Limited_Type (Component_Type (T1))
6679 and then Available_Full_View_Of_Component (T1)))
6680
6681 and then
6682 (Nkind (N) /= N_Op_Ne
6683 or else not Is_Tagged_Type (T1)
6684 or else Chars (Op_Id) = Name_Op_Eq)
6685 then
6686 if Found
6687 and then Base_Type (T1) /= Base_Type (T_F)
6688 then
6689 It := Disambiguate (L, I_F, Index, Any_Type);
6690
6691 if It = No_Interp then
6692 Ambiguous_Operands (N);
6693 Set_Etype (L, Any_Type);
6694 return;
6695
6696 else
6697 T_F := It.Typ;
6698 end if;
6699
6700 else
6701 Found := True;
6702 T_F := T1;
6703 I_F := Index;
6704 end if;
6705
6706 if not Analyzed (L) then
6707 Set_Etype (L, T_F);
6708 end if;
6709
6710 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
6711
6712 -- Case of operator was not visible, Etype still set to Any_Type
6713
6714 if Etype (N) = Any_Type then
6715 Found := False;
6716 end if;
6717
6718 elsif Scop = Standard_Standard
6719 and then Ekind (T1) = E_Anonymous_Access_Type
6720 then
6721 Found := True;
6722 end if;
6723 end Try_One_Interp;
6724
6725 -- Start of processing for Find_Equality_Types
6726
6727 begin
6728 -- If left operand is aggregate, the right operand has to
6729 -- provide a usable type for it.
6730
6731 if Nkind (L) = N_Aggregate
6732 and then Nkind (R) /= N_Aggregate
6733 then
6734 Find_Equality_Types (L => R, R => L, Op_Id => Op_Id, N => N);
6735 return;
6736 end if;
6737
6738 if Nkind (N) = N_Function_Call
6739 and then Nkind (Name (N)) = N_Expanded_Name
6740 then
6741 Scop := Entity (Prefix (Name (N)));
6742
6743 -- The prefix may be a package renaming, and the subsequent test
6744 -- requires the original package.
6745
6746 if Ekind (Scop) = E_Package
6747 and then Present (Renamed_Entity (Scop))
6748 then
6749 Scop := Renamed_Entity (Scop);
6750 Set_Entity (Prefix (Name (N)), Scop);
6751 end if;
6752 end if;
6753
6754 if not Is_Overloaded (L) then
6755 Try_One_Interp (Etype (L));
6756
6757 else
6758 Get_First_Interp (L, Index, It);
6759 while Present (It.Typ) loop
6760 Try_One_Interp (It.Typ);
6761 Get_Next_Interp (Index, It);
6762 end loop;
6763 end if;
6764 end Find_Equality_Types;
6765
6766 -------------------------
6767 -- Find_Negation_Types --
6768 -------------------------
6769
6770 procedure Find_Negation_Types
6771 (R : Node_Id;
6772 Op_Id : Entity_Id;
6773 N : Node_Id)
6774 is
6775 Index : Interp_Index;
6776 It : Interp;
6777
6778 begin
6779 if not Is_Overloaded (R) then
6780 if Etype (R) = Universal_Integer then
6781 Add_One_Interp (N, Op_Id, Any_Modular);
6782 elsif Valid_Boolean_Arg (Etype (R)) then
6783 Add_One_Interp (N, Op_Id, Etype (R));
6784 end if;
6785
6786 else
6787 Get_First_Interp (R, Index, It);
6788 while Present (It.Typ) loop
6789 if Valid_Boolean_Arg (It.Typ) then
6790 Add_One_Interp (N, Op_Id, It.Typ);
6791 end if;
6792
6793 Get_Next_Interp (Index, It);
6794 end loop;
6795 end if;
6796 end Find_Negation_Types;
6797
6798 ------------------------------
6799 -- Find_Primitive_Operation --
6800 ------------------------------
6801
6802 function Find_Primitive_Operation (N : Node_Id) return Boolean is
6803 Obj : constant Node_Id := Prefix (N);
6804 Op : constant Node_Id := Selector_Name (N);
6805
6806 Prim : Elmt_Id;
6807 Prims : Elist_Id;
6808 Typ : Entity_Id;
6809
6810 begin
6811 Set_Etype (Op, Any_Type);
6812
6813 if Is_Access_Type (Etype (Obj)) then
6814 Typ := Designated_Type (Etype (Obj));
6815 else
6816 Typ := Etype (Obj);
6817 end if;
6818
6819 if Is_Class_Wide_Type (Typ) then
6820 Typ := Root_Type (Typ);
6821 end if;
6822
6823 Prims := Primitive_Operations (Typ);
6824
6825 Prim := First_Elmt (Prims);
6826 while Present (Prim) loop
6827 if Chars (Node (Prim)) = Chars (Op) then
6828 Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
6829 Set_Etype (N, Etype (Node (Prim)));
6830 end if;
6831
6832 Next_Elmt (Prim);
6833 end loop;
6834
6835 -- Now look for class-wide operations of the type or any of its
6836 -- ancestors by iterating over the homonyms of the selector.
6837
6838 declare
6839 Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
6840 Hom : Entity_Id;
6841
6842 begin
6843 Hom := Current_Entity (Op);
6844 while Present (Hom) loop
6845 if (Ekind (Hom) = E_Procedure
6846 or else
6847 Ekind (Hom) = E_Function)
6848 and then Scope (Hom) = Scope (Typ)
6849 and then Present (First_Formal (Hom))
6850 and then
6851 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
6852 or else
6853 (Is_Access_Type (Etype (First_Formal (Hom)))
6854 and then
6855 Ekind (Etype (First_Formal (Hom))) =
6856 E_Anonymous_Access_Type
6857 and then
6858 Base_Type
6859 (Designated_Type (Etype (First_Formal (Hom)))) =
6860 Cls_Type))
6861 then
6862 Add_One_Interp (Op, Hom, Etype (Hom));
6863 Set_Etype (N, Etype (Hom));
6864 end if;
6865
6866 Hom := Homonym (Hom);
6867 end loop;
6868 end;
6869
6870 return Etype (Op) /= Any_Type;
6871 end Find_Primitive_Operation;
6872
6873 ----------------------
6874 -- Find_Unary_Types --
6875 ----------------------
6876
6877 procedure Find_Unary_Types
6878 (R : Node_Id;
6879 Op_Id : Entity_Id;
6880 N : Node_Id)
6881 is
6882 Index : Interp_Index;
6883 It : Interp;
6884
6885 begin
6886 if not Is_Overloaded (R) then
6887 if Is_Numeric_Type (Etype (R)) then
6888
6889 -- In an instance a generic actual may be a numeric type even if
6890 -- the formal in the generic unit was not. In that case, the
6891 -- predefined operator was not a possible interpretation in the
6892 -- generic, and cannot be one in the instance, unless the operator
6893 -- is an actual of an instance.
6894
6895 if In_Instance
6896 and then
6897 not Is_Numeric_Type (Corresponding_Generic_Type (Etype (R)))
6898 then
6899 null;
6900 else
6901 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
6902 end if;
6903 end if;
6904
6905 else
6906 Get_First_Interp (R, Index, It);
6907 while Present (It.Typ) loop
6908 if Is_Numeric_Type (It.Typ) then
6909 if In_Instance
6910 and then
6911 not Is_Numeric_Type
6912 (Corresponding_Generic_Type (Etype (It.Typ)))
6913 then
6914 null;
6915
6916 else
6917 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
6918 end if;
6919 end if;
6920
6921 Get_Next_Interp (Index, It);
6922 end loop;
6923 end if;
6924 end Find_Unary_Types;
6925
6926 ------------------
6927 -- Junk_Operand --
6928 ------------------
6929
6930 function Junk_Operand (N : Node_Id) return Boolean is
6931 Enode : Node_Id;
6932
6933 begin
6934 if Error_Posted (N) then
6935 return False;
6936 end if;
6937
6938 -- Get entity to be tested
6939
6940 if Is_Entity_Name (N)
6941 and then Present (Entity (N))
6942 then
6943 Enode := N;
6944
6945 -- An odd case, a procedure name gets converted to a very peculiar
6946 -- function call, and here is where we detect this happening.
6947
6948 elsif Nkind (N) = N_Function_Call
6949 and then Is_Entity_Name (Name (N))
6950 and then Present (Entity (Name (N)))
6951 then
6952 Enode := Name (N);
6953
6954 -- Another odd case, there are at least some cases of selected
6955 -- components where the selected component is not marked as having
6956 -- an entity, even though the selector does have an entity
6957
6958 elsif Nkind (N) = N_Selected_Component
6959 and then Present (Entity (Selector_Name (N)))
6960 then
6961 Enode := Selector_Name (N);
6962
6963 else
6964 return False;
6965 end if;
6966
6967 -- Now test the entity we got to see if it is a bad case
6968
6969 case Ekind (Entity (Enode)) is
6970 when E_Package =>
6971 Error_Msg_N
6972 ("package name cannot be used as operand", Enode);
6973
6974 when Generic_Unit_Kind =>
6975 Error_Msg_N
6976 ("generic unit name cannot be used as operand", Enode);
6977
6978 when Type_Kind =>
6979 Error_Msg_N
6980 ("subtype name cannot be used as operand", Enode);
6981
6982 when Entry_Kind =>
6983 Error_Msg_N
6984 ("entry name cannot be used as operand", Enode);
6985
6986 when E_Procedure =>
6987 Error_Msg_N
6988 ("procedure name cannot be used as operand", Enode);
6989
6990 when E_Exception =>
6991 Error_Msg_N
6992 ("exception name cannot be used as operand", Enode);
6993
6994 when E_Block
6995 | E_Label
6996 | E_Loop
6997 =>
6998 Error_Msg_N
6999 ("label name cannot be used as operand", Enode);
7000
7001 when others =>
7002 return False;
7003 end case;
7004
7005 return True;
7006 end Junk_Operand;
7007
7008 --------------------
7009 -- Operator_Check --
7010 --------------------
7011
7012 procedure Operator_Check (N : Node_Id) is
7013 begin
7014 Remove_Abstract_Operations (N);
7015
7016 -- Test for case of no interpretation found for operator
7017
7018 if Etype (N) = Any_Type then
7019 declare
7020 L : Node_Id;
7021 R : Node_Id;
7022 Op_Id : Entity_Id := Empty;
7023
7024 begin
7025 R := Right_Opnd (N);
7026
7027 if Nkind (N) in N_Binary_Op then
7028 L := Left_Opnd (N);
7029 else
7030 L := Empty;
7031 end if;
7032
7033 -- If either operand has no type, then don't complain further,
7034 -- since this simply means that we have a propagated error.
7035
7036 if R = Error
7037 or else Etype (R) = Any_Type
7038 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
7039 then
7040 -- For the rather unusual case where one of the operands is
7041 -- a Raise_Expression, whose initial type is Any_Type, use
7042 -- the type of the other operand.
7043
7044 if Nkind (L) = N_Raise_Expression then
7045 Set_Etype (L, Etype (R));
7046 Set_Etype (N, Etype (R));
7047
7048 elsif Nkind (R) = N_Raise_Expression then
7049 Set_Etype (R, Etype (L));
7050 Set_Etype (N, Etype (L));
7051 end if;
7052
7053 return;
7054
7055 -- We explicitly check for the case of concatenation of component
7056 -- with component to avoid reporting spurious matching array types
7057 -- that might happen to be lurking in distant packages (such as
7058 -- run-time packages). This also prevents inconsistencies in the
7059 -- messages for certain ACVC B tests, which can vary depending on
7060 -- types declared in run-time interfaces. Another improvement when
7061 -- aggregates are present is to look for a well-typed operand.
7062
7063 elsif Present (Candidate_Type)
7064 and then (Nkind (N) /= N_Op_Concat
7065 or else Is_Array_Type (Etype (L))
7066 or else Is_Array_Type (Etype (R)))
7067 then
7068 if Nkind (N) = N_Op_Concat then
7069 if Etype (L) /= Any_Composite
7070 and then Is_Array_Type (Etype (L))
7071 then
7072 Candidate_Type := Etype (L);
7073
7074 elsif Etype (R) /= Any_Composite
7075 and then Is_Array_Type (Etype (R))
7076 then
7077 Candidate_Type := Etype (R);
7078 end if;
7079 end if;
7080
7081 Error_Msg_NE -- CODEFIX
7082 ("operator for} is not directly visible!",
7083 N, First_Subtype (Candidate_Type));
7084
7085 declare
7086 U : constant Node_Id :=
7087 Cunit (Get_Source_Unit (Candidate_Type));
7088 begin
7089 if Unit_Is_Visible (U) then
7090 Error_Msg_N -- CODEFIX
7091 ("use clause would make operation legal!", N);
7092 else
7093 Error_Msg_NE -- CODEFIX
7094 ("add with_clause and use_clause for&!",
7095 N, Defining_Entity (Unit (U)));
7096 end if;
7097 end;
7098 return;
7099
7100 -- If either operand is a junk operand (e.g. package name), then
7101 -- post appropriate error messages, but do not complain further.
7102
7103 -- Note that the use of OR in this test instead of OR ELSE is
7104 -- quite deliberate, we may as well check both operands in the
7105 -- binary operator case.
7106
7107 elsif Junk_Operand (R)
7108 or -- really mean OR here and not OR ELSE, see above
7109 (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
7110 then
7111 return;
7112
7113 -- If we have a logical operator, one of whose operands is
7114 -- Boolean, then we know that the other operand cannot resolve to
7115 -- Boolean (since we got no interpretations), but in that case we
7116 -- pretty much know that the other operand should be Boolean, so
7117 -- resolve it that way (generating an error).
7118
7119 elsif Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor) then
7120 if Etype (L) = Standard_Boolean then
7121 Resolve (R, Standard_Boolean);
7122 return;
7123 elsif Etype (R) = Standard_Boolean then
7124 Resolve (L, Standard_Boolean);
7125 return;
7126 end if;
7127
7128 -- For an arithmetic operator or comparison operator, if one
7129 -- of the operands is numeric, then we know the other operand
7130 -- is not the same numeric type. If it is a non-numeric type,
7131 -- then probably it is intended to match the other operand.
7132
7133 elsif Nkind_In (N, N_Op_Add,
7134 N_Op_Divide,
7135 N_Op_Ge,
7136 N_Op_Gt,
7137 N_Op_Le,
7138 N_Op_Lt,
7139 N_Op_Mod,
7140 N_Op_Multiply,
7141 N_Op_Rem,
7142 N_Op_Subtract)
7143 then
7144 -- If Allow_Integer_Address is active, check whether the
7145 -- operation becomes legal after converting an operand.
7146
7147 if Is_Numeric_Type (Etype (L))
7148 and then not Is_Numeric_Type (Etype (R))
7149 then
7150 if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
7151 Rewrite (L,
7152 Unchecked_Convert_To (
7153 Standard_Address, Relocate_Node (L)));
7154 Rewrite (R,
7155 Unchecked_Convert_To (
7156 Standard_Address, Relocate_Node (R)));
7157
7158 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
7159 Analyze_Comparison_Op (N);
7160 else
7161 Analyze_Arithmetic_Op (N);
7162 end if;
7163 else
7164 Resolve (R, Etype (L));
7165 end if;
7166
7167 return;
7168
7169 elsif Is_Numeric_Type (Etype (R))
7170 and then not Is_Numeric_Type (Etype (L))
7171 then
7172 if Address_Integer_Convert_OK (Etype (L), Etype (R)) then
7173 Rewrite (L,
7174 Unchecked_Convert_To (
7175 Standard_Address, Relocate_Node (L)));
7176 Rewrite (R,
7177 Unchecked_Convert_To (
7178 Standard_Address, Relocate_Node (R)));
7179
7180 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
7181 Analyze_Comparison_Op (N);
7182 else
7183 Analyze_Arithmetic_Op (N);
7184 end if;
7185
7186 return;
7187
7188 else
7189 Resolve (L, Etype (R));
7190 end if;
7191
7192 return;
7193
7194 elsif Allow_Integer_Address
7195 and then Is_Descendant_Of_Address (Etype (L))
7196 and then Is_Descendant_Of_Address (Etype (R))
7197 and then not Error_Posted (N)
7198 then
7199 declare
7200 Addr_Type : constant Entity_Id := Etype (L);
7201
7202 begin
7203 Rewrite (L,
7204 Unchecked_Convert_To (
7205 Standard_Address, Relocate_Node (L)));
7206 Rewrite (R,
7207 Unchecked_Convert_To (
7208 Standard_Address, Relocate_Node (R)));
7209
7210 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
7211 Analyze_Comparison_Op (N);
7212 else
7213 Analyze_Arithmetic_Op (N);
7214 end if;
7215
7216 -- If this is an operand in an enclosing arithmetic
7217 -- operation, Convert the result as an address so that
7218 -- arithmetic folding of address can continue.
7219
7220 if Nkind (Parent (N)) in N_Op then
7221 Rewrite (N,
7222 Unchecked_Convert_To (Addr_Type, Relocate_Node (N)));
7223 end if;
7224
7225 return;
7226 end;
7227
7228 -- Under relaxed RM semantics silently replace occurrences of
7229 -- null by System.Address_Null.
7230
7231 elsif Null_To_Null_Address_Convert_OK (N) then
7232 Replace_Null_By_Null_Address (N);
7233
7234 if Nkind_In (N, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt) then
7235 Analyze_Comparison_Op (N);
7236 else
7237 Analyze_Arithmetic_Op (N);
7238 end if;
7239
7240 return;
7241 end if;
7242
7243 -- Comparisons on A'Access are common enough to deserve a
7244 -- special message.
7245
7246 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne)
7247 and then Ekind (Etype (L)) = E_Access_Attribute_Type
7248 and then Ekind (Etype (R)) = E_Access_Attribute_Type
7249 then
7250 Error_Msg_N
7251 ("two access attributes cannot be compared directly", N);
7252 Error_Msg_N
7253 ("\use qualified expression for one of the operands",
7254 N);
7255 return;
7256
7257 -- Another one for C programmers
7258
7259 elsif Nkind (N) = N_Op_Concat
7260 and then Valid_Boolean_Arg (Etype (L))
7261 and then Valid_Boolean_Arg (Etype (R))
7262 then
7263 Error_Msg_N ("invalid operands for concatenation", N);
7264 Error_Msg_N -- CODEFIX
7265 ("\maybe AND was meant", N);
7266 return;
7267
7268 -- A special case for comparison of access parameter with null
7269
7270 elsif Nkind (N) = N_Op_Eq
7271 and then Is_Entity_Name (L)
7272 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
7273 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
7274 N_Access_Definition
7275 and then Nkind (R) = N_Null
7276 then
7277 Error_Msg_N ("access parameter is not allowed to be null", L);
7278 Error_Msg_N ("\(call would raise Constraint_Error)", L);
7279 return;
7280
7281 -- Another special case for exponentiation, where the right
7282 -- operand must be Natural, independently of the base.
7283
7284 elsif Nkind (N) = N_Op_Expon
7285 and then Is_Numeric_Type (Etype (L))
7286 and then not Is_Overloaded (R)
7287 and then
7288 First_Subtype (Base_Type (Etype (R))) /= Standard_Integer
7289 and then Base_Type (Etype (R)) /= Universal_Integer
7290 then
7291 if Ada_Version >= Ada_2012
7292 and then Has_Dimension_System (Etype (L))
7293 then
7294 Error_Msg_NE
7295 ("exponent for dimensioned type must be a rational" &
7296 ", found}", R, Etype (R));
7297 else
7298 Error_Msg_NE
7299 ("exponent must be of type Natural, found}", R, Etype (R));
7300 end if;
7301
7302 return;
7303
7304 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
7305 if Address_Integer_Convert_OK (Etype (R), Etype (L)) then
7306 Rewrite (L,
7307 Unchecked_Convert_To (
7308 Standard_Address, Relocate_Node (L)));
7309 Rewrite (R,
7310 Unchecked_Convert_To (
7311 Standard_Address, Relocate_Node (R)));
7312 Analyze_Equality_Op (N);
7313 return;
7314
7315 -- Under relaxed RM semantics silently replace occurrences of
7316 -- null by System.Address_Null.
7317
7318 elsif Null_To_Null_Address_Convert_OK (N) then
7319 Replace_Null_By_Null_Address (N);
7320 Analyze_Equality_Op (N);
7321 return;
7322 end if;
7323 end if;
7324
7325 -- If we fall through then just give general message. Note that in
7326 -- the following messages, if the operand is overloaded we choose
7327 -- an arbitrary type to complain about, but that is probably more
7328 -- useful than not giving a type at all.
7329
7330 if Nkind (N) in N_Unary_Op then
7331 Error_Msg_Node_2 := Etype (R);
7332 Error_Msg_N ("operator& not defined for}", N);
7333 return;
7334
7335 else
7336 if Nkind (N) in N_Binary_Op then
7337 if not Is_Overloaded (L)
7338 and then not Is_Overloaded (R)
7339 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
7340 then
7341 Error_Msg_Node_2 := First_Subtype (Etype (R));
7342 Error_Msg_N ("there is no applicable operator& for}", N);
7343
7344 else
7345 -- Another attempt to find a fix: one of the candidate
7346 -- interpretations may not be use-visible. This has
7347 -- already been checked for predefined operators, so
7348 -- we examine only user-defined functions.
7349
7350 Op_Id := Get_Name_Entity_Id (Chars (N));
7351
7352 while Present (Op_Id) loop
7353 if Ekind (Op_Id) /= E_Operator
7354 and then Is_Overloadable (Op_Id)
7355 then
7356 if not Is_Immediately_Visible (Op_Id)
7357 and then not In_Use (Scope (Op_Id))
7358 and then not Is_Abstract_Subprogram (Op_Id)
7359 and then not Is_Hidden (Op_Id)
7360 and then Ekind (Scope (Op_Id)) = E_Package
7361 and then
7362 Has_Compatible_Type
7363 (L, Etype (First_Formal (Op_Id)))
7364 and then Present
7365 (Next_Formal (First_Formal (Op_Id)))
7366 and then
7367 Has_Compatible_Type
7368 (R,
7369 Etype (Next_Formal (First_Formal (Op_Id))))
7370 then
7371 Error_Msg_N
7372 ("no legal interpretation for operator&", N);
7373 Error_Msg_NE
7374 ("\use clause on& would make operation legal",
7375 N, Scope (Op_Id));
7376 exit;
7377 end if;
7378 end if;
7379
7380 Op_Id := Homonym (Op_Id);
7381 end loop;
7382
7383 if No (Op_Id) then
7384 Error_Msg_N ("invalid operand types for operator&", N);
7385
7386 if Nkind (N) /= N_Op_Concat then
7387 Error_Msg_NE ("\left operand has}!", N, Etype (L));
7388 Error_Msg_NE ("\right operand has}!", N, Etype (R));
7389
7390 -- For multiplication and division operators with
7391 -- a fixed-point operand and an integer operand,
7392 -- indicate that the integer operand should be of
7393 -- type Integer.
7394
7395 if Nkind_In (N, N_Op_Multiply, N_Op_Divide)
7396 and then Is_Fixed_Point_Type (Etype (L))
7397 and then Is_Integer_Type (Etype (R))
7398 then
7399 Error_Msg_N
7400 ("\convert right operand to `Integer`", N);
7401
7402 elsif Nkind (N) = N_Op_Multiply
7403 and then Is_Fixed_Point_Type (Etype (R))
7404 and then Is_Integer_Type (Etype (L))
7405 then
7406 Error_Msg_N
7407 ("\convert left operand to `Integer`", N);
7408 end if;
7409
7410 -- For concatenation operators it is more difficult to
7411 -- determine which is the wrong operand. It is worth
7412 -- flagging explicitly an access type, for those who
7413 -- might think that a dereference happens here.
7414
7415 elsif Is_Access_Type (Etype (L)) then
7416 Error_Msg_N ("\left operand is access type", N);
7417
7418 elsif Is_Access_Type (Etype (R)) then
7419 Error_Msg_N ("\right operand is access type", N);
7420 end if;
7421 end if;
7422 end if;
7423 end if;
7424 end if;
7425 end;
7426 end if;
7427 end Operator_Check;
7428
7429 --------------------------------
7430 -- Remove_Abstract_Operations --
7431 --------------------------------
7432
7433 procedure Remove_Abstract_Operations (N : Node_Id) is
7434 Abstract_Op : Entity_Id := Empty;
7435 Address_Descendant : Boolean := False;
7436 I : Interp_Index;
7437 It : Interp;
7438
7439 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
7440 -- activate this if either extensions are enabled, or if the abstract
7441 -- operation in question comes from a predefined file. This latter test
7442 -- allows us to use abstract to make operations invisible to users. In
7443 -- particular, if type Address is non-private and abstract subprograms
7444 -- are used to hide its operators, they will be truly hidden.
7445
7446 type Operand_Position is (First_Op, Second_Op);
7447 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
7448
7449 procedure Remove_Address_Interpretations (Op : Operand_Position);
7450 -- Ambiguities may arise when the operands are literal and the address
7451 -- operations in s-auxdec are visible. In that case, remove the
7452 -- interpretation of a literal as Address, to retain the semantics
7453 -- of Address as a private type.
7454
7455 ------------------------------------
7456 -- Remove_Address_Interpretations --
7457 ------------------------------------
7458
7459 procedure Remove_Address_Interpretations (Op : Operand_Position) is
7460 Formal : Entity_Id;
7461
7462 begin
7463 if Is_Overloaded (N) then
7464 Get_First_Interp (N, I, It);
7465 while Present (It.Nam) loop
7466 Formal := First_Entity (It.Nam);
7467
7468 if Op = Second_Op then
7469 Next_Entity (Formal);
7470 end if;
7471
7472 if Is_Descendant_Of_Address (Etype (Formal)) then
7473 Address_Descendant := True;
7474 Remove_Interp (I);
7475 end if;
7476
7477 Get_Next_Interp (I, It);
7478 end loop;
7479 end if;
7480 end Remove_Address_Interpretations;
7481
7482 -- Start of processing for Remove_Abstract_Operations
7483
7484 begin
7485 if Is_Overloaded (N) then
7486 if Debug_Flag_V then
7487 Write_Line ("Remove_Abstract_Operations: ");
7488 Write_Overloads (N);
7489 end if;
7490
7491 Get_First_Interp (N, I, It);
7492
7493 while Present (It.Nam) loop
7494 if Is_Overloadable (It.Nam)
7495 and then Is_Abstract_Subprogram (It.Nam)
7496 and then not Is_Dispatching_Operation (It.Nam)
7497 then
7498 Abstract_Op := It.Nam;
7499
7500 if Is_Descendant_Of_Address (It.Typ) then
7501 Address_Descendant := True;
7502 Remove_Interp (I);
7503 exit;
7504
7505 -- In Ada 2005, this operation does not participate in overload
7506 -- resolution. If the operation is defined in a predefined
7507 -- unit, it is one of the operations declared abstract in some
7508 -- variants of System, and it must be removed as well.
7509
7510 elsif Ada_Version >= Ada_2005
7511 or else In_Predefined_Unit (It.Nam)
7512 then
7513 Remove_Interp (I);
7514 exit;
7515 end if;
7516 end if;
7517
7518 Get_Next_Interp (I, It);
7519 end loop;
7520
7521 if No (Abstract_Op) then
7522
7523 -- If some interpretation yields an integer type, it is still
7524 -- possible that there are address interpretations. Remove them
7525 -- if one operand is a literal, to avoid spurious ambiguities
7526 -- on systems where Address is a visible integer type.
7527
7528 if Is_Overloaded (N)
7529 and then Nkind (N) in N_Op
7530 and then Is_Integer_Type (Etype (N))
7531 then
7532 if Nkind (N) in N_Binary_Op then
7533 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
7534 Remove_Address_Interpretations (Second_Op);
7535
7536 elsif Nkind (Left_Opnd (N)) = N_Integer_Literal then
7537 Remove_Address_Interpretations (First_Op);
7538 end if;
7539 end if;
7540 end if;
7541
7542 elsif Nkind (N) in N_Op then
7543
7544 -- Remove interpretations that treat literals as addresses. This
7545 -- is never appropriate, even when Address is defined as a visible
7546 -- Integer type. The reason is that we would really prefer Address
7547 -- to behave as a private type, even in this case. If Address is a
7548 -- visible integer type, we get lots of overload ambiguities.
7549
7550 if Nkind (N) in N_Binary_Op then
7551 declare
7552 U1 : constant Boolean :=
7553 Present (Universal_Interpretation (Right_Opnd (N)));
7554 U2 : constant Boolean :=
7555 Present (Universal_Interpretation (Left_Opnd (N)));
7556
7557 begin
7558 if U1 then
7559 Remove_Address_Interpretations (Second_Op);
7560 end if;
7561
7562 if U2 then
7563 Remove_Address_Interpretations (First_Op);
7564 end if;
7565
7566 if not (U1 and U2) then
7567
7568 -- Remove corresponding predefined operator, which is
7569 -- always added to the overload set.
7570
7571 Get_First_Interp (N, I, It);
7572 while Present (It.Nam) loop
7573 if Scope (It.Nam) = Standard_Standard
7574 and then Base_Type (It.Typ) =
7575 Base_Type (Etype (Abstract_Op))
7576 then
7577 Remove_Interp (I);
7578 end if;
7579
7580 Get_Next_Interp (I, It);
7581 end loop;
7582
7583 elsif Is_Overloaded (N)
7584 and then Present (Univ_Type)
7585 then
7586 -- If both operands have a universal interpretation,
7587 -- it is still necessary to remove interpretations that
7588 -- yield Address. Any remaining ambiguities will be
7589 -- removed in Disambiguate.
7590
7591 Get_First_Interp (N, I, It);
7592 while Present (It.Nam) loop
7593 if Is_Descendant_Of_Address (It.Typ) then
7594 Remove_Interp (I);
7595
7596 elsif not Is_Type (It.Nam) then
7597 Set_Entity (N, It.Nam);
7598 end if;
7599
7600 Get_Next_Interp (I, It);
7601 end loop;
7602 end if;
7603 end;
7604 end if;
7605
7606 elsif Nkind (N) = N_Function_Call
7607 and then
7608 (Nkind (Name (N)) = N_Operator_Symbol
7609 or else
7610 (Nkind (Name (N)) = N_Expanded_Name
7611 and then
7612 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
7613 then
7614
7615 declare
7616 Arg1 : constant Node_Id := First (Parameter_Associations (N));
7617 U1 : constant Boolean :=
7618 Present (Universal_Interpretation (Arg1));
7619 U2 : constant Boolean :=
7620 Present (Next (Arg1)) and then
7621 Present (Universal_Interpretation (Next (Arg1)));
7622
7623 begin
7624 if U1 then
7625 Remove_Address_Interpretations (First_Op);
7626 end if;
7627
7628 if U2 then
7629 Remove_Address_Interpretations (Second_Op);
7630 end if;
7631
7632 if not (U1 and U2) then
7633 Get_First_Interp (N, I, It);
7634 while Present (It.Nam) loop
7635 if Scope (It.Nam) = Standard_Standard
7636 and then It.Typ = Base_Type (Etype (Abstract_Op))
7637 then
7638 Remove_Interp (I);
7639 end if;
7640
7641 Get_Next_Interp (I, It);
7642 end loop;
7643 end if;
7644 end;
7645 end if;
7646
7647 -- If the removal has left no valid interpretations, emit an error
7648 -- message now and label node as illegal.
7649
7650 if Present (Abstract_Op) then
7651 Get_First_Interp (N, I, It);
7652
7653 if No (It.Nam) then
7654
7655 -- Removal of abstract operation left no viable candidate
7656
7657 Set_Etype (N, Any_Type);
7658 Error_Msg_Sloc := Sloc (Abstract_Op);
7659 Error_Msg_NE
7660 ("cannot call abstract operation& declared#", N, Abstract_Op);
7661
7662 -- In Ada 2005, an abstract operation may disable predefined
7663 -- operators. Since the context is not yet known, we mark the
7664 -- predefined operators as potentially hidden. Do not include
7665 -- predefined operators when addresses are involved since this
7666 -- case is handled separately.
7667
7668 elsif Ada_Version >= Ada_2005 and then not Address_Descendant then
7669 while Present (It.Nam) loop
7670 if Is_Numeric_Type (It.Typ)
7671 and then Scope (It.Typ) = Standard_Standard
7672 then
7673 Set_Abstract_Op (I, Abstract_Op);
7674 end if;
7675
7676 Get_Next_Interp (I, It);
7677 end loop;
7678 end if;
7679 end if;
7680
7681 if Debug_Flag_V then
7682 Write_Line ("Remove_Abstract_Operations done: ");
7683 Write_Overloads (N);
7684 end if;
7685 end if;
7686 end Remove_Abstract_Operations;
7687
7688 ----------------------------
7689 -- Try_Container_Indexing --
7690 ----------------------------
7691
7692 function Try_Container_Indexing
7693 (N : Node_Id;
7694 Prefix : Node_Id;
7695 Exprs : List_Id) return Boolean
7696 is
7697 Pref_Typ : constant Entity_Id := Etype (Prefix);
7698
7699 function Constant_Indexing_OK return Boolean;
7700 -- Constant_Indexing is legal if there is no Variable_Indexing defined
7701 -- for the type, or else node not a target of assignment, or an actual
7702 -- for an IN OUT or OUT formal (RM 4.1.6 (11)).
7703
7704 function Expr_Matches_In_Formal
7705 (Subp : Entity_Id;
7706 Par : Node_Id) return Boolean;
7707 -- Find formal corresponding to given indexed component that is an
7708 -- actual in a call. Note that the enclosing subprogram call has not
7709 -- been analyzed yet, and the parameter list is not normalized, so
7710 -- that if the argument is a parameter association we must match it
7711 -- by name and not by position.
7712
7713 function Find_Indexing_Operations
7714 (T : Entity_Id;
7715 Nam : Name_Id;
7716 Is_Constant : Boolean) return Node_Id;
7717 -- Return a reference to the primitive operation of type T denoted by
7718 -- name Nam. If the operation is overloaded, the reference carries all
7719 -- interpretations. Flag Is_Constant should be set when the context is
7720 -- constant indexing.
7721
7722 --------------------------
7723 -- Constant_Indexing_OK --
7724 --------------------------
7725
7726 function Constant_Indexing_OK return Boolean is
7727 Par : Node_Id;
7728
7729 begin
7730 if No (Find_Value_Of_Aspect (Pref_Typ, Aspect_Variable_Indexing)) then
7731 return True;
7732
7733 elsif not Is_Variable (Prefix) then
7734 return True;
7735 end if;
7736
7737 Par := N;
7738 while Present (Par) loop
7739 if Nkind (Parent (Par)) = N_Assignment_Statement
7740 and then Par = Name (Parent (Par))
7741 then
7742 return False;
7743
7744 -- The call may be overloaded, in which case we assume that its
7745 -- resolution does not depend on the type of the parameter that
7746 -- includes the indexing operation.
7747
7748 elsif Nkind_In (Parent (Par), N_Function_Call,
7749 N_Procedure_Call_Statement)
7750 and then Is_Entity_Name (Name (Parent (Par)))
7751 then
7752 declare
7753 Proc : Entity_Id;
7754
7755 begin
7756 -- We should look for an interpretation with the proper
7757 -- number of formals, and determine whether it is an
7758 -- In_Parameter, but for now we examine the formal that
7759 -- corresponds to the indexing, and assume that variable
7760 -- indexing is required if some interpretation has an
7761 -- assignable formal at that position. Still does not
7762 -- cover the most complex cases ???
7763
7764 if Is_Overloaded (Name (Parent (Par))) then
7765 declare
7766 Proc : constant Node_Id := Name (Parent (Par));
7767 I : Interp_Index;
7768 It : Interp;
7769
7770 begin
7771 Get_First_Interp (Proc, I, It);
7772 while Present (It.Nam) loop
7773 if not Expr_Matches_In_Formal (It.Nam, Par) then
7774 return False;
7775 end if;
7776
7777 Get_Next_Interp (I, It);
7778 end loop;
7779 end;
7780
7781 -- All interpretations have a matching in-mode formal
7782
7783 return True;
7784
7785 else
7786 Proc := Entity (Name (Parent (Par)));
7787
7788 -- If this is an indirect call, get formals from
7789 -- designated type.
7790
7791 if Is_Access_Subprogram_Type (Etype (Proc)) then
7792 Proc := Designated_Type (Etype (Proc));
7793 end if;
7794 end if;
7795
7796 return Expr_Matches_In_Formal (Proc, Par);
7797 end;
7798
7799 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
7800 return False;
7801
7802 -- If the indexed component is a prefix it may be the first actual
7803 -- of a prefixed call. Retrieve the called entity, if any, and
7804 -- check its first formal. Determine if the context is a procedure
7805 -- or function call.
7806
7807 elsif Nkind (Parent (Par)) = N_Selected_Component then
7808 declare
7809 Sel : constant Node_Id := Selector_Name (Parent (Par));
7810 Nam : constant Entity_Id := Current_Entity (Sel);
7811
7812 begin
7813 if Present (Nam) and then Is_Overloadable (Nam) then
7814 if Nkind (Parent (Parent (Par))) =
7815 N_Procedure_Call_Statement
7816 then
7817 return False;
7818
7819 elsif Ekind (Nam) = E_Function
7820 and then Present (First_Formal (Nam))
7821 then
7822 return Ekind (First_Formal (Nam)) = E_In_Parameter;
7823 end if;
7824 end if;
7825 end;
7826
7827 elsif Nkind (Par) in N_Op then
7828 return True;
7829 end if;
7830
7831 Par := Parent (Par);
7832 end loop;
7833
7834 -- In all other cases, constant indexing is legal
7835
7836 return True;
7837 end Constant_Indexing_OK;
7838
7839 ----------------------------
7840 -- Expr_Matches_In_Formal --
7841 ----------------------------
7842
7843 function Expr_Matches_In_Formal
7844 (Subp : Entity_Id;
7845 Par : Node_Id) return Boolean
7846 is
7847 Actual : Node_Id;
7848 Formal : Node_Id;
7849
7850 begin
7851 Formal := First_Formal (Subp);
7852 Actual := First (Parameter_Associations ((Parent (Par))));
7853
7854 if Nkind (Par) /= N_Parameter_Association then
7855
7856 -- Match by position
7857
7858 while Present (Actual) and then Present (Formal) loop
7859 exit when Actual = Par;
7860 Next (Actual);
7861
7862 if Present (Formal) then
7863 Next_Formal (Formal);
7864
7865 -- Otherwise this is a parameter mismatch, the error is
7866 -- reported elsewhere, or else variable indexing is implied.
7867
7868 else
7869 return False;
7870 end if;
7871 end loop;
7872
7873 else
7874 -- Match by name
7875
7876 while Present (Formal) loop
7877 exit when Chars (Formal) = Chars (Selector_Name (Par));
7878 Next_Formal (Formal);
7879
7880 if No (Formal) then
7881 return False;
7882 end if;
7883 end loop;
7884 end if;
7885
7886 return Present (Formal) and then Ekind (Formal) = E_In_Parameter;
7887 end Expr_Matches_In_Formal;
7888
7889 ------------------------------
7890 -- Find_Indexing_Operations --
7891 ------------------------------
7892
7893 function Find_Indexing_Operations
7894 (T : Entity_Id;
7895 Nam : Name_Id;
7896 Is_Constant : Boolean) return Node_Id
7897 is
7898 procedure Inspect_Declarations
7899 (Typ : Entity_Id;
7900 Ref : in out Node_Id);
7901 -- Traverse the declarative list where type Typ resides and collect
7902 -- all suitable interpretations in node Ref.
7903
7904 procedure Inspect_Primitives
7905 (Typ : Entity_Id;
7906 Ref : in out Node_Id);
7907 -- Traverse the list of primitive operations of type Typ and collect
7908 -- all suitable interpretations in node Ref.
7909
7910 function Is_OK_Candidate
7911 (Subp_Id : Entity_Id;
7912 Typ : Entity_Id) return Boolean;
7913 -- Determine whether subprogram Subp_Id is a suitable indexing
7914 -- operation for type Typ. To qualify as such, the subprogram must
7915 -- be a function, have at least two parameters, and the type of the
7916 -- first parameter must be either Typ, or Typ'Class, or access [to
7917 -- constant] with designated type Typ or Typ'Class.
7918
7919 procedure Record_Interp (Subp_Id : Entity_Id; Ref : in out Node_Id);
7920 -- Store subprogram Subp_Id as an interpretation in node Ref
7921
7922 --------------------------
7923 -- Inspect_Declarations --
7924 --------------------------
7925
7926 procedure Inspect_Declarations
7927 (Typ : Entity_Id;
7928 Ref : in out Node_Id)
7929 is
7930 Typ_Decl : constant Node_Id := Declaration_Node (Typ);
7931 Decl : Node_Id;
7932 Subp_Id : Entity_Id;
7933
7934 begin
7935 -- Ensure that the routine is not called with itypes, which lack a
7936 -- declarative node.
7937
7938 pragma Assert (Present (Typ_Decl));
7939 pragma Assert (Is_List_Member (Typ_Decl));
7940
7941 Decl := First (List_Containing (Typ_Decl));
7942 while Present (Decl) loop
7943 if Nkind (Decl) = N_Subprogram_Declaration then
7944 Subp_Id := Defining_Entity (Decl);
7945
7946 if Is_OK_Candidate (Subp_Id, Typ) then
7947 Record_Interp (Subp_Id, Ref);
7948 end if;
7949 end if;
7950
7951 Next (Decl);
7952 end loop;
7953 end Inspect_Declarations;
7954
7955 ------------------------
7956 -- Inspect_Primitives --
7957 ------------------------
7958
7959 procedure Inspect_Primitives
7960 (Typ : Entity_Id;
7961 Ref : in out Node_Id)
7962 is
7963 Prim_Elmt : Elmt_Id;
7964 Prim_Id : Entity_Id;
7965
7966 begin
7967 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
7968 while Present (Prim_Elmt) loop
7969 Prim_Id := Node (Prim_Elmt);
7970
7971 if Is_OK_Candidate (Prim_Id, Typ) then
7972 Record_Interp (Prim_Id, Ref);
7973 end if;
7974
7975 Next_Elmt (Prim_Elmt);
7976 end loop;
7977 end Inspect_Primitives;
7978
7979 ---------------------
7980 -- Is_OK_Candidate --
7981 ---------------------
7982
7983 function Is_OK_Candidate
7984 (Subp_Id : Entity_Id;
7985 Typ : Entity_Id) return Boolean
7986 is
7987 Formal : Entity_Id;
7988 Formal_Typ : Entity_Id;
7989 Param_Typ : Node_Id;
7990
7991 begin
7992 -- To classify as a suitable candidate, the subprogram must be a
7993 -- function whose name matches the argument of aspect Constant or
7994 -- Variable_Indexing.
7995
7996 if Ekind (Subp_Id) = E_Function and then Chars (Subp_Id) = Nam then
7997 Formal := First_Formal (Subp_Id);
7998
7999 -- The candidate requires at least two parameters
8000
8001 if Present (Formal) and then Present (Next_Formal (Formal)) then
8002 Formal_Typ := Empty;
8003 Param_Typ := Parameter_Type (Parent (Formal));
8004
8005 -- Use the designated type when the first parameter is of an
8006 -- access type.
8007
8008 if Nkind (Param_Typ) = N_Access_Definition
8009 and then Present (Subtype_Mark (Param_Typ))
8010 then
8011 -- When the context is a constant indexing, the access
8012 -- definition must be access-to-constant. This does not
8013 -- apply to variable indexing.
8014
8015 if not Is_Constant
8016 or else Constant_Present (Param_Typ)
8017 then
8018 Formal_Typ := Etype (Subtype_Mark (Param_Typ));
8019 end if;
8020
8021 -- Otherwise use the parameter type
8022
8023 else
8024 Formal_Typ := Etype (Param_Typ);
8025 end if;
8026
8027 if Present (Formal_Typ) then
8028
8029 -- Use the specific type when the parameter type is
8030 -- class-wide.
8031
8032 if Is_Class_Wide_Type (Formal_Typ) then
8033 Formal_Typ := Etype (Base_Type (Formal_Typ));
8034 end if;
8035
8036 -- Use the full view when the parameter type is private
8037 -- or incomplete.
8038
8039 if Is_Incomplete_Or_Private_Type (Formal_Typ)
8040 and then Present (Full_View (Formal_Typ))
8041 then
8042 Formal_Typ := Full_View (Formal_Typ);
8043 end if;
8044
8045 -- The type of the first parameter must denote the type
8046 -- of the container or acts as its ancestor type.
8047
8048 return
8049 Formal_Typ = Typ
8050 or else Is_Ancestor (Formal_Typ, Typ);
8051 end if;
8052 end if;
8053 end if;
8054
8055 return False;
8056 end Is_OK_Candidate;
8057
8058 -------------------
8059 -- Record_Interp --
8060 -------------------
8061
8062 procedure Record_Interp (Subp_Id : Entity_Id; Ref : in out Node_Id) is
8063 begin
8064 if Present (Ref) then
8065 Add_One_Interp (Ref, Subp_Id, Etype (Subp_Id));
8066
8067 -- Otherwise this is the first interpretation. Create a reference
8068 -- where all remaining interpretations will be collected.
8069
8070 else
8071 Ref := New_Occurrence_Of (Subp_Id, Sloc (T));
8072 end if;
8073 end Record_Interp;
8074
8075 -- Local variables
8076
8077 Ref : Node_Id;
8078 Typ : Entity_Id;
8079
8080 -- Start of processing for Find_Indexing_Operations
8081
8082 begin
8083 Typ := T;
8084
8085 -- Use the specific type when the parameter type is class-wide
8086
8087 if Is_Class_Wide_Type (Typ) then
8088 Typ := Root_Type (Typ);
8089 end if;
8090
8091 Ref := Empty;
8092 Typ := Underlying_Type (Base_Type (Typ));
8093
8094 Inspect_Primitives (Typ, Ref);
8095
8096 -- Now look for explicit declarations of an indexing operation.
8097 -- If the type is private the operation may be declared in the
8098 -- visible part that contains the partial view.
8099
8100 if Is_Private_Type (T) then
8101 Inspect_Declarations (T, Ref);
8102 end if;
8103
8104 Inspect_Declarations (Typ, Ref);
8105
8106 return Ref;
8107 end Find_Indexing_Operations;
8108
8109 -- Local variables
8110
8111 Loc : constant Source_Ptr := Sloc (N);
8112 Assoc : List_Id;
8113 C_Type : Entity_Id;
8114 Func : Entity_Id;
8115 Func_Name : Node_Id;
8116 Indexing : Node_Id;
8117
8118 Is_Constant_Indexing : Boolean := False;
8119 -- This flag reflects the nature of the container indexing. Note that
8120 -- the context may be suited for constant indexing, but the type may
8121 -- lack a Constant_Indexing annotation.
8122
8123 -- Start of processing for Try_Container_Indexing
8124
8125 begin
8126 -- Node may have been analyzed already when testing for a prefixed
8127 -- call, in which case do not redo analysis.
8128
8129 if Present (Generalized_Indexing (N)) then
8130 return True;
8131 end if;
8132
8133 C_Type := Pref_Typ;
8134
8135 -- If indexing a class-wide container, obtain indexing primitive from
8136 -- specific type.
8137
8138 if Is_Class_Wide_Type (C_Type) then
8139 C_Type := Etype (Base_Type (C_Type));
8140 end if;
8141
8142 -- Check whether the type has a specified indexing aspect
8143
8144 Func_Name := Empty;
8145
8146 -- The context is suitable for constant indexing, so obtain the name of
8147 -- the indexing function from aspect Constant_Indexing.
8148
8149 if Constant_Indexing_OK then
8150 Func_Name :=
8151 Find_Value_Of_Aspect (Pref_Typ, Aspect_Constant_Indexing);
8152 end if;
8153
8154 if Present (Func_Name) then
8155 Is_Constant_Indexing := True;
8156
8157 -- Otherwise attempt variable indexing
8158
8159 else
8160 Func_Name :=
8161 Find_Value_Of_Aspect (Pref_Typ, Aspect_Variable_Indexing);
8162 end if;
8163
8164 -- The type is not subject to either form of indexing, therefore the
8165 -- indexed component does not denote container indexing. If this is a
8166 -- true error, it is diagnosed by the caller.
8167
8168 if No (Func_Name) then
8169
8170 -- The prefix itself may be an indexing of a container. Rewrite it
8171 -- as such and retry.
8172
8173 if Has_Implicit_Dereference (Pref_Typ) then
8174 Build_Explicit_Dereference
8175 (Prefix, Get_Reference_Discriminant (Pref_Typ));
8176 return Try_Container_Indexing (N, Prefix, Exprs);
8177
8178 -- Otherwise this is definitely not container indexing
8179
8180 else
8181 return False;
8182 end if;
8183
8184 -- If the container type is derived from another container type, the
8185 -- value of the inherited aspect is the Reference operation declared
8186 -- for the parent type.
8187
8188 -- However, Reference is also a primitive operation of the type, and the
8189 -- inherited operation has a different signature. We retrieve the right
8190 -- ones (the function may be overloaded) from the list of primitive
8191 -- operations of the derived type.
8192
8193 -- Note that predefined containers are typically all derived from one of
8194 -- the Controlled types. The code below is motivated by containers that
8195 -- are derived from other types with a Reference aspect.
8196 -- Note as well that we need to examine the base type, given that
8197 -- the container object may be a constrained subtype or itype that
8198 -- does not have an explicit declaration.
8199
8200 elsif Is_Derived_Type (C_Type)
8201 and then Etype (First_Formal (Entity (Func_Name))) /= Pref_Typ
8202 then
8203 Func_Name :=
8204 Find_Indexing_Operations
8205 (T => Base_Type (C_Type),
8206 Nam => Chars (Func_Name),
8207 Is_Constant => Is_Constant_Indexing);
8208 end if;
8209
8210 Assoc := New_List (Relocate_Node (Prefix));
8211
8212 -- A generalized indexing may have nore than one index expression, so
8213 -- transfer all of them to the argument list to be used in the call.
8214 -- Note that there may be named associations, in which case the node
8215 -- was rewritten earlier as a call, and has been transformed back into
8216 -- an indexed expression to share the following processing.
8217
8218 -- The generalized indexing node is the one on which analysis and
8219 -- resolution take place. Before expansion the original node is replaced
8220 -- with the generalized indexing node, which is a call, possibly with a
8221 -- dereference operation.
8222
8223 if Comes_From_Source (N) then
8224 Check_Compiler_Unit ("generalized indexing", N);
8225 end if;
8226
8227 -- Create argument list for function call that represents generalized
8228 -- indexing. Note that indices (i.e. actuals) may themselves be
8229 -- overloaded.
8230
8231 declare
8232 Arg : Node_Id;
8233 New_Arg : Node_Id;
8234
8235 begin
8236 Arg := First (Exprs);
8237 while Present (Arg) loop
8238 New_Arg := Relocate_Node (Arg);
8239
8240 -- The arguments can be parameter associations, in which case the
8241 -- explicit actual parameter carries the overloadings.
8242
8243 if Nkind (New_Arg) /= N_Parameter_Association then
8244 Save_Interps (Arg, New_Arg);
8245 end if;
8246
8247 Append (New_Arg, Assoc);
8248 Next (Arg);
8249 end loop;
8250 end;
8251
8252 if not Is_Overloaded (Func_Name) then
8253 Func := Entity (Func_Name);
8254
8255 Indexing :=
8256 Make_Function_Call (Loc,
8257 Name => New_Occurrence_Of (Func, Loc),
8258 Parameter_Associations => Assoc);
8259
8260 Set_Parent (Indexing, Parent (N));
8261 Set_Generalized_Indexing (N, Indexing);
8262 Analyze (Indexing);
8263 Set_Etype (N, Etype (Indexing));
8264
8265 -- If the return type of the indexing function is a reference type,
8266 -- add the dereference as a possible interpretation. Note that the
8267 -- indexing aspect may be a function that returns the element type
8268 -- with no intervening implicit dereference, and that the reference
8269 -- discriminant is not the first discriminant.
8270
8271 if Has_Discriminants (Etype (Func)) then
8272 Check_Implicit_Dereference (N, Etype (Func));
8273 end if;
8274
8275 else
8276 -- If there are multiple indexing functions, build a function call
8277 -- and analyze it for each of the possible interpretations.
8278
8279 Indexing :=
8280 Make_Function_Call (Loc,
8281 Name =>
8282 Make_Identifier (Loc, Chars (Func_Name)),
8283 Parameter_Associations => Assoc);
8284 Set_Parent (Indexing, Parent (N));
8285 Set_Generalized_Indexing (N, Indexing);
8286 Set_Etype (N, Any_Type);
8287 Set_Etype (Name (Indexing), Any_Type);
8288
8289 declare
8290 I : Interp_Index;
8291 It : Interp;
8292 Success : Boolean;
8293
8294 begin
8295 Get_First_Interp (Func_Name, I, It);
8296 Set_Etype (Indexing, Any_Type);
8297
8298 -- Analyze each candidate function with the given actuals
8299
8300 while Present (It.Nam) loop
8301 Analyze_One_Call (Indexing, It.Nam, False, Success);
8302 Get_Next_Interp (I, It);
8303 end loop;
8304
8305 -- If there are several successful candidates, resolution will
8306 -- be by result. Mark the interpretations of the function name
8307 -- itself.
8308
8309 if Is_Overloaded (Indexing) then
8310 Get_First_Interp (Indexing, I, It);
8311
8312 while Present (It.Nam) loop
8313 Add_One_Interp (Name (Indexing), It.Nam, It.Typ);
8314 Get_Next_Interp (I, It);
8315 end loop;
8316
8317 else
8318 Set_Etype (Name (Indexing), Etype (Indexing));
8319 end if;
8320
8321 -- Now add the candidate interpretations to the indexing node
8322 -- itself, to be replaced later by the function call.
8323
8324 if Is_Overloaded (Name (Indexing)) then
8325 Get_First_Interp (Name (Indexing), I, It);
8326
8327 while Present (It.Nam) loop
8328 Add_One_Interp (N, It.Nam, It.Typ);
8329
8330 -- Add dereference interpretation if the result type has
8331 -- implicit reference discriminants.
8332
8333 if Has_Discriminants (Etype (It.Nam)) then
8334 Check_Implicit_Dereference (N, Etype (It.Nam));
8335 end if;
8336
8337 Get_Next_Interp (I, It);
8338 end loop;
8339
8340 else
8341 Set_Etype (N, Etype (Name (Indexing)));
8342 if Has_Discriminants (Etype (N)) then
8343 Check_Implicit_Dereference (N, Etype (N));
8344 end if;
8345 end if;
8346 end;
8347 end if;
8348
8349 if Etype (Indexing) = Any_Type then
8350 Error_Msg_NE
8351 ("container cannot be indexed with&", N, Etype (First (Exprs)));
8352 Rewrite (N, New_Occurrence_Of (Any_Id, Loc));
8353 end if;
8354
8355 return True;
8356 end Try_Container_Indexing;
8357
8358 -----------------------
8359 -- Try_Indirect_Call --
8360 -----------------------
8361
8362 function Try_Indirect_Call
8363 (N : Node_Id;
8364 Nam : Entity_Id;
8365 Typ : Entity_Id) return Boolean
8366 is
8367 Actual : Node_Id;
8368 Formal : Entity_Id;
8369
8370 Call_OK : Boolean;
8371 pragma Warnings (Off, Call_OK);
8372
8373 begin
8374 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
8375
8376 Actual := First_Actual (N);
8377 Formal := First_Formal (Designated_Type (Typ));
8378 while Present (Actual) and then Present (Formal) loop
8379 if not Has_Compatible_Type (Actual, Etype (Formal)) then
8380 return False;
8381 end if;
8382
8383 Next (Actual);
8384 Next_Formal (Formal);
8385 end loop;
8386
8387 if No (Actual) and then No (Formal) then
8388 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
8389
8390 -- Nam is a candidate interpretation for the name in the call,
8391 -- if it is not an indirect call.
8392
8393 if not Is_Type (Nam)
8394 and then Is_Entity_Name (Name (N))
8395 then
8396 Set_Entity (Name (N), Nam);
8397 end if;
8398
8399 return True;
8400
8401 else
8402 return False;
8403 end if;
8404 end Try_Indirect_Call;
8405
8406 ----------------------
8407 -- Try_Indexed_Call --
8408 ----------------------
8409
8410 function Try_Indexed_Call
8411 (N : Node_Id;
8412 Nam : Entity_Id;
8413 Typ : Entity_Id;
8414 Skip_First : Boolean) return Boolean
8415 is
8416 Loc : constant Source_Ptr := Sloc (N);
8417 Actuals : constant List_Id := Parameter_Associations (N);
8418 Actual : Node_Id;
8419 Index : Entity_Id;
8420
8421 begin
8422 Actual := First (Actuals);
8423
8424 -- If the call was originally written in prefix form, skip the first
8425 -- actual, which is obviously not defaulted.
8426
8427 if Skip_First then
8428 Next (Actual);
8429 end if;
8430
8431 Index := First_Index (Typ);
8432 while Present (Actual) and then Present (Index) loop
8433
8434 -- If the parameter list has a named association, the expression
8435 -- is definitely a call and not an indexed component.
8436
8437 if Nkind (Actual) = N_Parameter_Association then
8438 return False;
8439 end if;
8440
8441 if Is_Entity_Name (Actual)
8442 and then Is_Type (Entity (Actual))
8443 and then No (Next (Actual))
8444 then
8445 -- A single actual that is a type name indicates a slice if the
8446 -- type is discrete, and an error otherwise.
8447
8448 if Is_Discrete_Type (Entity (Actual)) then
8449 Rewrite (N,
8450 Make_Slice (Loc,
8451 Prefix =>
8452 Make_Function_Call (Loc,
8453 Name => Relocate_Node (Name (N))),
8454 Discrete_Range =>
8455 New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
8456
8457 Analyze (N);
8458
8459 else
8460 Error_Msg_N ("invalid use of type in expression", Actual);
8461 Set_Etype (N, Any_Type);
8462 end if;
8463
8464 return True;
8465
8466 elsif not Has_Compatible_Type (Actual, Etype (Index)) then
8467 return False;
8468 end if;
8469
8470 Next (Actual);
8471 Next_Index (Index);
8472 end loop;
8473
8474 if No (Actual) and then No (Index) then
8475 Add_One_Interp (N, Nam, Component_Type (Typ));
8476
8477 -- Nam is a candidate interpretation for the name in the call,
8478 -- if it is not an indirect call.
8479
8480 if not Is_Type (Nam)
8481 and then Is_Entity_Name (Name (N))
8482 then
8483 Set_Entity (Name (N), Nam);
8484 end if;
8485
8486 return True;
8487 else
8488 return False;
8489 end if;
8490 end Try_Indexed_Call;
8491
8492 --------------------------
8493 -- Try_Object_Operation --
8494 --------------------------
8495
8496 function Try_Object_Operation
8497 (N : Node_Id; CW_Test_Only : Boolean := False) return Boolean
8498 is
8499 K : constant Node_Kind := Nkind (Parent (N));
8500 Is_Subprg_Call : constant Boolean := K in N_Subprogram_Call;
8501 Loc : constant Source_Ptr := Sloc (N);
8502 Obj : constant Node_Id := Prefix (N);
8503
8504 Subprog : constant Node_Id :=
8505 Make_Identifier (Sloc (Selector_Name (N)),
8506 Chars => Chars (Selector_Name (N)));
8507 -- Identifier on which possible interpretations will be collected
8508
8509 Report_Error : Boolean := False;
8510 -- If no candidate interpretation matches the context, redo analysis
8511 -- with Report_Error True to provide additional information.
8512
8513 Actual : Node_Id;
8514 Candidate : Entity_Id := Empty;
8515 New_Call_Node : Node_Id := Empty;
8516 Node_To_Replace : Node_Id;
8517 Obj_Type : Entity_Id := Etype (Obj);
8518 Success : Boolean := False;
8519
8520 procedure Complete_Object_Operation
8521 (Call_Node : Node_Id;
8522 Node_To_Replace : Node_Id);
8523 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
8524 -- Call_Node, insert the object (or its dereference) as the first actual
8525 -- in the call, and complete the analysis of the call.
8526
8527 procedure Report_Ambiguity (Op : Entity_Id);
8528 -- If a prefixed procedure call is ambiguous, indicate whether the call
8529 -- includes an implicit dereference or an implicit 'Access.
8530
8531 procedure Transform_Object_Operation
8532 (Call_Node : out Node_Id;
8533 Node_To_Replace : out Node_Id);
8534 -- Transform Obj.Operation (X, Y, ...) into Operation (Obj, X, Y ...).
8535 -- Call_Node is the resulting subprogram call, Node_To_Replace is
8536 -- either N or the parent of N, and Subprog is a reference to the
8537 -- subprogram we are trying to match. Note that the transformation
8538 -- may be partially destructive for the parent of N, so it needs to
8539 -- be undone in the case where Try_Object_Operation returns false.
8540
8541 function Try_Class_Wide_Operation
8542 (Call_Node : Node_Id;
8543 Node_To_Replace : Node_Id) return Boolean;
8544 -- Traverse all ancestor types looking for a class-wide subprogram for
8545 -- which the current operation is a valid non-dispatching call.
8546
8547 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
8548 -- If prefix is overloaded, its interpretation may include different
8549 -- tagged types, and we must examine the primitive operations and the
8550 -- class-wide operations of each in order to find candidate
8551 -- interpretations for the call as a whole.
8552
8553 function Try_Primitive_Operation
8554 (Call_Node : Node_Id;
8555 Node_To_Replace : Node_Id) return Boolean;
8556 -- Traverse the list of primitive subprograms looking for a dispatching
8557 -- operation for which the current node is a valid call.
8558
8559 function Valid_Candidate
8560 (Success : Boolean;
8561 Call : Node_Id;
8562 Subp : Entity_Id) return Entity_Id;
8563 -- If the subprogram is a valid interpretation, record it, and add to
8564 -- the list of interpretations of Subprog. Otherwise return Empty.
8565
8566 -------------------------------
8567 -- Complete_Object_Operation --
8568 -------------------------------
8569
8570 procedure Complete_Object_Operation
8571 (Call_Node : Node_Id;
8572 Node_To_Replace : Node_Id)
8573 is
8574 Control : constant Entity_Id := First_Formal (Entity (Subprog));
8575 Formal_Type : constant Entity_Id := Etype (Control);
8576 First_Actual : Node_Id;
8577
8578 begin
8579 -- Place the name of the operation, with its interpretations,
8580 -- on the rewritten call.
8581
8582 Set_Name (Call_Node, Subprog);
8583
8584 First_Actual := First (Parameter_Associations (Call_Node));
8585
8586 -- For cross-reference purposes, treat the new node as being in the
8587 -- source if the original one is. Set entity and type, even though
8588 -- they may be overwritten during resolution if overloaded.
8589
8590 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
8591 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
8592
8593 if Nkind (N) = N_Selected_Component
8594 and then not Inside_A_Generic
8595 then
8596 Set_Entity (Selector_Name (N), Entity (Subprog));
8597 Set_Etype (Selector_Name (N), Etype (Entity (Subprog)));
8598 end if;
8599
8600 -- If need be, rewrite first actual as an explicit dereference. If
8601 -- the call is overloaded, the rewriting can only be done once the
8602 -- primitive operation is identified.
8603
8604 if Is_Overloaded (Subprog) then
8605
8606 -- The prefix itself may be overloaded, and its interpretations
8607 -- must be propagated to the new actual in the call.
8608
8609 if Is_Overloaded (Obj) then
8610 Save_Interps (Obj, First_Actual);
8611 end if;
8612
8613 Rewrite (First_Actual, Obj);
8614
8615 elsif not Is_Access_Type (Formal_Type)
8616 and then Is_Access_Type (Etype (Obj))
8617 then
8618 Rewrite (First_Actual,
8619 Make_Explicit_Dereference (Sloc (Obj), Obj));
8620 Analyze (First_Actual);
8621
8622 -- If we need to introduce an explicit dereference, verify that
8623 -- the resulting actual is compatible with the mode of the formal.
8624
8625 if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
8626 and then Is_Access_Constant (Etype (Obj))
8627 then
8628 Error_Msg_NE
8629 ("expect variable in call to&", Prefix (N), Entity (Subprog));
8630 end if;
8631
8632 -- Conversely, if the formal is an access parameter and the object is
8633 -- not an access type or a reference type (i.e. a type with the
8634 -- Implicit_Dereference aspect specified), replace the actual with a
8635 -- 'Access reference. Its analysis will check that the object is
8636 -- aliased.
8637
8638 elsif Is_Access_Type (Formal_Type)
8639 and then not Is_Access_Type (Etype (Obj))
8640 and then
8641 (not Has_Implicit_Dereference (Etype (Obj))
8642 or else
8643 not Is_Access_Type (Designated_Type (Etype
8644 (Get_Reference_Discriminant (Etype (Obj))))))
8645 then
8646 -- A special case: A.all'Access is illegal if A is an access to a
8647 -- constant and the context requires an access to a variable.
8648
8649 if not Is_Access_Constant (Formal_Type) then
8650 if (Nkind (Obj) = N_Explicit_Dereference
8651 and then Is_Access_Constant (Etype (Prefix (Obj))))
8652 or else not Is_Variable (Obj)
8653 then
8654 Error_Msg_NE
8655 ("actual for & must be a variable", Obj, Control);
8656 end if;
8657 end if;
8658
8659 Rewrite (First_Actual,
8660 Make_Attribute_Reference (Loc,
8661 Attribute_Name => Name_Access,
8662 Prefix => Relocate_Node (Obj)));
8663
8664 -- If the object is not overloaded verify that taking access of
8665 -- it is legal. Otherwise check is made during resolution.
8666
8667 if not Is_Overloaded (Obj)
8668 and then not Is_Aliased_View (Obj)
8669 then
8670 Error_Msg_NE
8671 ("object in prefixed call to & must be aliased "
8672 & "(RM 4.1.3 (13 1/2))", Prefix (First_Actual), Subprog);
8673 end if;
8674
8675 Analyze (First_Actual);
8676
8677 else
8678 if Is_Overloaded (Obj) then
8679 Save_Interps (Obj, First_Actual);
8680 end if;
8681
8682 Rewrite (First_Actual, Obj);
8683 end if;
8684
8685 -- The operation is obtained from the dispatch table and not by
8686 -- visibility, and may be declared in a unit that is not explicitly
8687 -- referenced in the source, but is nevertheless required in the
8688 -- context of the current unit. Indicate that operation and its scope
8689 -- are referenced, to prevent spurious and misleading warnings. If
8690 -- the operation is overloaded, all primitives are in the same scope
8691 -- and we can use any of them.
8692
8693 Set_Referenced (Entity (Subprog), True);
8694 Set_Referenced (Scope (Entity (Subprog)), True);
8695
8696 Rewrite (Node_To_Replace, Call_Node);
8697
8698 -- Propagate the interpretations collected in subprog to the new
8699 -- function call node, to be resolved from context.
8700
8701 if Is_Overloaded (Subprog) then
8702 Save_Interps (Subprog, Node_To_Replace);
8703
8704 else
8705 -- The type of the subprogram may be a limited view obtained
8706 -- transitively from another unit. If full view is available,
8707 -- use it to analyze call. If there is no nonlimited view, then
8708 -- this is diagnosed when analyzing the rewritten call.
8709
8710 declare
8711 T : constant Entity_Id := Etype (Subprog);
8712 begin
8713 if From_Limited_With (T) then
8714 Set_Etype (Entity (Subprog), Available_View (T));
8715 end if;
8716 end;
8717
8718 Analyze (Node_To_Replace);
8719
8720 -- If the operation has been rewritten into a call, which may get
8721 -- subsequently an explicit dereference, preserve the type on the
8722 -- original node (selected component or indexed component) for
8723 -- subsequent legality tests, e.g. Is_Variable. which examines
8724 -- the original node.
8725
8726 if Nkind (Node_To_Replace) = N_Function_Call then
8727 Set_Etype
8728 (Original_Node (Node_To_Replace), Etype (Node_To_Replace));
8729 end if;
8730 end if;
8731 end Complete_Object_Operation;
8732
8733 ----------------------
8734 -- Report_Ambiguity --
8735 ----------------------
8736
8737 procedure Report_Ambiguity (Op : Entity_Id) is
8738 Access_Actual : constant Boolean :=
8739 Is_Access_Type (Etype (Prefix (N)));
8740 Access_Formal : Boolean := False;
8741
8742 begin
8743 Error_Msg_Sloc := Sloc (Op);
8744
8745 if Present (First_Formal (Op)) then
8746 Access_Formal := Is_Access_Type (Etype (First_Formal (Op)));
8747 end if;
8748
8749 if Access_Formal and then not Access_Actual then
8750 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8751 Error_Msg_N
8752 ("\possible interpretation "
8753 & "(inherited, with implicit 'Access) #", N);
8754 else
8755 Error_Msg_N
8756 ("\possible interpretation (with implicit 'Access) #", N);
8757 end if;
8758
8759 elsif not Access_Formal and then Access_Actual then
8760 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8761 Error_Msg_N
8762 ("\possible interpretation "
8763 & "(inherited, with implicit dereference) #", N);
8764 else
8765 Error_Msg_N
8766 ("\possible interpretation (with implicit dereference) #", N);
8767 end if;
8768
8769 else
8770 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
8771 Error_Msg_N ("\possible interpretation (inherited)#", N);
8772 else
8773 Error_Msg_N -- CODEFIX
8774 ("\possible interpretation#", N);
8775 end if;
8776 end if;
8777 end Report_Ambiguity;
8778
8779 --------------------------------
8780 -- Transform_Object_Operation --
8781 --------------------------------
8782
8783 procedure Transform_Object_Operation
8784 (Call_Node : out Node_Id;
8785 Node_To_Replace : out Node_Id)
8786 is
8787 Dummy : constant Node_Id := New_Copy (Obj);
8788 -- Placeholder used as a first parameter in the call, replaced
8789 -- eventually by the proper object.
8790
8791 Parent_Node : constant Node_Id := Parent (N);
8792
8793 Actual : Node_Id;
8794 Actuals : List_Id;
8795
8796 begin
8797 -- Common case covering 1) Call to a procedure and 2) Call to a
8798 -- function that has some additional actuals.
8799
8800 if Nkind (Parent_Node) in N_Subprogram_Call
8801
8802 -- N is a selected component node containing the name of the
8803 -- subprogram. If N is not the name of the parent node we must
8804 -- not replace the parent node by the new construct. This case
8805 -- occurs when N is a parameterless call to a subprogram that
8806 -- is an actual parameter of a call to another subprogram. For
8807 -- example:
8808 -- Some_Subprogram (..., Obj.Operation, ...)
8809
8810 and then N = Name (Parent_Node)
8811 then
8812 Node_To_Replace := Parent_Node;
8813
8814 Actuals := Parameter_Associations (Parent_Node);
8815
8816 if Present (Actuals) then
8817 Prepend (Dummy, Actuals);
8818 else
8819 Actuals := New_List (Dummy);
8820 end if;
8821
8822 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
8823 Call_Node :=
8824 Make_Procedure_Call_Statement (Loc,
8825 Name => New_Copy (Subprog),
8826 Parameter_Associations => Actuals);
8827
8828 else
8829 Call_Node :=
8830 Make_Function_Call (Loc,
8831 Name => New_Copy (Subprog),
8832 Parameter_Associations => Actuals);
8833 end if;
8834
8835 -- Before analysis, a function call appears as an indexed component
8836 -- if there are no named associations.
8837
8838 elsif Nkind (Parent_Node) = N_Indexed_Component
8839 and then N = Prefix (Parent_Node)
8840 then
8841 Node_To_Replace := Parent_Node;
8842 Actuals := Expressions (Parent_Node);
8843
8844 Actual := First (Actuals);
8845 while Present (Actual) loop
8846 Analyze (Actual);
8847 Next (Actual);
8848 end loop;
8849
8850 Prepend (Dummy, Actuals);
8851
8852 Call_Node :=
8853 Make_Function_Call (Loc,
8854 Name => New_Copy (Subprog),
8855 Parameter_Associations => Actuals);
8856
8857 -- Parameterless call: Obj.F is rewritten as F (Obj)
8858
8859 else
8860 Node_To_Replace := N;
8861
8862 Call_Node :=
8863 Make_Function_Call (Loc,
8864 Name => New_Copy (Subprog),
8865 Parameter_Associations => New_List (Dummy));
8866 end if;
8867 end Transform_Object_Operation;
8868
8869 ------------------------------
8870 -- Try_Class_Wide_Operation --
8871 ------------------------------
8872
8873 function Try_Class_Wide_Operation
8874 (Call_Node : Node_Id;
8875 Node_To_Replace : Node_Id) return Boolean
8876 is
8877 Anc_Type : Entity_Id;
8878 Matching_Op : Entity_Id := Empty;
8879 Error : Boolean;
8880
8881 procedure Traverse_Homonyms
8882 (Anc_Type : Entity_Id;
8883 Error : out Boolean);
8884 -- Traverse the homonym chain of the subprogram searching for those
8885 -- homonyms whose first formal has the Anc_Type's class-wide type,
8886 -- or an anonymous access type designating the class-wide type. If
8887 -- an ambiguity is detected, then Error is set to True.
8888
8889 procedure Traverse_Interfaces
8890 (Anc_Type : Entity_Id;
8891 Error : out Boolean);
8892 -- Traverse the list of interfaces, if any, associated with Anc_Type
8893 -- and search for acceptable class-wide homonyms associated with each
8894 -- interface. If an ambiguity is detected, then Error is set to True.
8895
8896 -----------------------
8897 -- Traverse_Homonyms --
8898 -----------------------
8899
8900 procedure Traverse_Homonyms
8901 (Anc_Type : Entity_Id;
8902 Error : out Boolean)
8903 is
8904 function First_Formal_Match
8905 (Subp_Id : Entity_Id;
8906 Typ : Entity_Id) return Boolean;
8907 -- Predicate to verify that the first foramal of class-wide
8908 -- subprogram Subp_Id matches type Typ of the prefix.
8909
8910 ------------------------
8911 -- First_Formal_Match --
8912 ------------------------
8913
8914 function First_Formal_Match
8915 (Subp_Id : Entity_Id;
8916 Typ : Entity_Id) return Boolean
8917 is
8918 Ctrl : constant Entity_Id := First_Formal (Subp_Id);
8919
8920 begin
8921 return
8922 Present (Ctrl)
8923 and then
8924 (Base_Type (Etype (Ctrl)) = Typ
8925 or else
8926 (Ekind (Etype (Ctrl)) = E_Anonymous_Access_Type
8927 and then
8928 Base_Type (Designated_Type (Etype (Ctrl))) =
8929 Typ));
8930 end First_Formal_Match;
8931
8932 -- Local variables
8933
8934 CW_Typ : constant Entity_Id := Class_Wide_Type (Anc_Type);
8935
8936 Candidate : Entity_Id;
8937 -- If homonym is a renaming, examine the renamed program
8938
8939 Hom : Entity_Id;
8940 Hom_Ref : Node_Id;
8941 Success : Boolean;
8942
8943 -- Start of processing for Traverse_Homonyms
8944
8945 begin
8946 Error := False;
8947
8948 -- Find a non-hidden operation whose first parameter is of the
8949 -- class-wide type, a subtype thereof, or an anonymous access
8950 -- to same. If in an instance, the operation can be considered
8951 -- even if hidden (it may be hidden because the instantiation
8952 -- is expanded after the containing package has been analyzed).
8953 -- If the subprogram is a generic actual in an enclosing instance,
8954 -- it appears as a renaming that is a candidate interpretation as
8955 -- well.
8956
8957 Hom := Current_Entity (Subprog);
8958 while Present (Hom) loop
8959 if Ekind_In (Hom, E_Procedure, E_Function)
8960 and then Present (Renamed_Entity (Hom))
8961 and then Is_Generic_Actual_Subprogram (Hom)
8962 and then In_Open_Scopes (Scope (Hom))
8963 then
8964 Candidate := Renamed_Entity (Hom);
8965 else
8966 Candidate := Hom;
8967 end if;
8968
8969 if Ekind_In (Candidate, E_Function, E_Procedure)
8970 and then (not Is_Hidden (Candidate) or else In_Instance)
8971 and then Scope (Candidate) = Scope (Base_Type (Anc_Type))
8972 and then First_Formal_Match (Candidate, CW_Typ)
8973 then
8974 -- If the context is a procedure call, ignore functions
8975 -- in the name of the call.
8976
8977 if Ekind (Candidate) = E_Function
8978 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
8979 and then N = Name (Parent (N))
8980 then
8981 goto Next_Hom;
8982
8983 -- If the context is a function call, ignore procedures
8984 -- in the name of the call.
8985
8986 elsif Ekind (Candidate) = E_Procedure
8987 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
8988 then
8989 goto Next_Hom;
8990 end if;
8991
8992 Set_Etype (Call_Node, Any_Type);
8993 Set_Is_Overloaded (Call_Node, False);
8994 Success := False;
8995
8996 if No (Matching_Op) then
8997 Hom_Ref := New_Occurrence_Of (Candidate, Sloc (Subprog));
8998
8999 Set_Etype (Call_Node, Any_Type);
9000 Set_Name (Call_Node, Hom_Ref);
9001 Set_Parent (Call_Node, Parent (Node_To_Replace));
9002
9003 Analyze_One_Call
9004 (N => Call_Node,
9005 Nam => Candidate,
9006 Report => Report_Error,
9007 Success => Success,
9008 Skip_First => True);
9009
9010 Matching_Op :=
9011 Valid_Candidate (Success, Call_Node, Candidate);
9012
9013 else
9014 Analyze_One_Call
9015 (N => Call_Node,
9016 Nam => Candidate,
9017 Report => Report_Error,
9018 Success => Success,
9019 Skip_First => True);
9020
9021 -- The same operation may be encountered on two homonym
9022 -- traversals, before and after looking at interfaces.
9023 -- Check for this case before reporting a real ambiguity.
9024
9025 if Present
9026 (Valid_Candidate (Success, Call_Node, Candidate))
9027 and then Nkind (Call_Node) /= N_Function_Call
9028 and then Candidate /= Matching_Op
9029 then
9030 Error_Msg_NE ("ambiguous call to&", N, Hom);
9031 Report_Ambiguity (Matching_Op);
9032 Report_Ambiguity (Hom);
9033 Error := True;
9034 return;
9035 end if;
9036 end if;
9037 end if;
9038
9039 <<Next_Hom>>
9040 Hom := Homonym (Hom);
9041 end loop;
9042 end Traverse_Homonyms;
9043
9044 -------------------------
9045 -- Traverse_Interfaces --
9046 -------------------------
9047
9048 procedure Traverse_Interfaces
9049 (Anc_Type : Entity_Id;
9050 Error : out Boolean)
9051 is
9052 Intface_List : constant List_Id :=
9053 Abstract_Interface_List (Anc_Type);
9054 Intface : Node_Id;
9055
9056 begin
9057 Error := False;
9058
9059 if Is_Non_Empty_List (Intface_List) then
9060 Intface := First (Intface_List);
9061 while Present (Intface) loop
9062
9063 -- Look for acceptable class-wide homonyms associated with
9064 -- the interface.
9065
9066 Traverse_Homonyms (Etype (Intface), Error);
9067
9068 if Error then
9069 return;
9070 end if;
9071
9072 -- Continue the search by looking at each of the interface's
9073 -- associated interface ancestors.
9074
9075 Traverse_Interfaces (Etype (Intface), Error);
9076
9077 if Error then
9078 return;
9079 end if;
9080
9081 Next (Intface);
9082 end loop;
9083 end if;
9084 end Traverse_Interfaces;
9085
9086 -- Start of processing for Try_Class_Wide_Operation
9087
9088 begin
9089 -- If we are searching only for conflicting class-wide subprograms
9090 -- then initialize directly Matching_Op with the target entity.
9091
9092 if CW_Test_Only then
9093 Matching_Op := Entity (Selector_Name (N));
9094 end if;
9095
9096 -- Loop through ancestor types (including interfaces), traversing
9097 -- the homonym chain of the subprogram, trying out those homonyms
9098 -- whose first formal has the class-wide type of the ancestor, or
9099 -- an anonymous access type designating the class-wide type.
9100
9101 Anc_Type := Obj_Type;
9102 loop
9103 -- Look for a match among homonyms associated with the ancestor
9104
9105 Traverse_Homonyms (Anc_Type, Error);
9106
9107 if Error then
9108 return True;
9109 end if;
9110
9111 -- Continue the search for matches among homonyms associated with
9112 -- any interfaces implemented by the ancestor.
9113
9114 Traverse_Interfaces (Anc_Type, Error);
9115
9116 if Error then
9117 return True;
9118 end if;
9119
9120 exit when Etype (Anc_Type) = Anc_Type;
9121 Anc_Type := Etype (Anc_Type);
9122 end loop;
9123
9124 if Present (Matching_Op) then
9125 Set_Etype (Call_Node, Etype (Matching_Op));
9126 end if;
9127
9128 return Present (Matching_Op);
9129 end Try_Class_Wide_Operation;
9130
9131 -----------------------------------
9132 -- Try_One_Prefix_Interpretation --
9133 -----------------------------------
9134
9135 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
9136 Prev_Obj_Type : constant Entity_Id := Obj_Type;
9137 -- If the interpretation does not have a valid candidate type,
9138 -- preserve current value of Obj_Type for subsequent errors.
9139
9140 begin
9141 Obj_Type := T;
9142
9143 if Is_Access_Type (Obj_Type) then
9144 Obj_Type := Designated_Type (Obj_Type);
9145 end if;
9146
9147 if Ekind_In (Obj_Type, E_Private_Subtype,
9148 E_Record_Subtype_With_Private)
9149 then
9150 Obj_Type := Base_Type (Obj_Type);
9151 end if;
9152
9153 if Is_Class_Wide_Type (Obj_Type) then
9154 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
9155 end if;
9156
9157 -- The type may have be obtained through a limited_with clause,
9158 -- in which case the primitive operations are available on its
9159 -- nonlimited view. If still incomplete, retrieve full view.
9160
9161 if Ekind (Obj_Type) = E_Incomplete_Type
9162 and then From_Limited_With (Obj_Type)
9163 and then Has_Non_Limited_View (Obj_Type)
9164 then
9165 Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
9166 end if;
9167
9168 -- If the object is not tagged, or the type is still an incomplete
9169 -- type, this is not a prefixed call. Restore the previous type as
9170 -- the current one is not a legal candidate.
9171
9172 if not Is_Tagged_Type (Obj_Type)
9173 or else Is_Incomplete_Type (Obj_Type)
9174 then
9175 Obj_Type := Prev_Obj_Type;
9176 return;
9177 end if;
9178
9179 declare
9180 Dup_Call_Node : constant Node_Id := New_Copy (New_Call_Node);
9181 Ignore : Boolean;
9182 Prim_Result : Boolean := False;
9183
9184 begin
9185 if not CW_Test_Only then
9186 Prim_Result :=
9187 Try_Primitive_Operation
9188 (Call_Node => New_Call_Node,
9189 Node_To_Replace => Node_To_Replace);
9190 end if;
9191
9192 -- Check if there is a class-wide subprogram covering the
9193 -- primitive. This check must be done even if a candidate
9194 -- was found in order to report ambiguous calls.
9195
9196 if not Prim_Result then
9197 Ignore :=
9198 Try_Class_Wide_Operation
9199 (Call_Node => New_Call_Node,
9200 Node_To_Replace => Node_To_Replace);
9201
9202 -- If we found a primitive we search for class-wide subprograms
9203 -- using a duplicate of the call node (done to avoid missing its
9204 -- decoration if there is no ambiguity).
9205
9206 else
9207 Ignore :=
9208 Try_Class_Wide_Operation
9209 (Call_Node => Dup_Call_Node,
9210 Node_To_Replace => Node_To_Replace);
9211 end if;
9212 end;
9213 end Try_One_Prefix_Interpretation;
9214
9215 -----------------------------
9216 -- Try_Primitive_Operation --
9217 -----------------------------
9218
9219 function Try_Primitive_Operation
9220 (Call_Node : Node_Id;
9221 Node_To_Replace : Node_Id) return Boolean
9222 is
9223 Elmt : Elmt_Id;
9224 Prim_Op : Entity_Id;
9225 Matching_Op : Entity_Id := Empty;
9226 Prim_Op_Ref : Node_Id := Empty;
9227
9228 Corr_Type : Entity_Id := Empty;
9229 -- If the prefix is a synchronized type, the controlling type of
9230 -- the primitive operation is the corresponding record type, else
9231 -- this is the object type itself.
9232
9233 Success : Boolean := False;
9234
9235 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
9236 -- For tagged types the candidate interpretations are found in
9237 -- the list of primitive operations of the type and its ancestors.
9238 -- For formal tagged types we have to find the operations declared
9239 -- in the same scope as the type (including in the generic formal
9240 -- part) because the type itself carries no primitive operations,
9241 -- except for formal derived types that inherit the operations of
9242 -- the parent and progenitors.
9243 --
9244 -- If the context is a generic subprogram body, the generic formals
9245 -- are visible by name, but are not in the entity list of the
9246 -- subprogram because that list starts with the subprogram formals.
9247 -- We retrieve the candidate operations from the generic declaration.
9248
9249 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id;
9250 -- Prefix notation can also be used on operations that are not
9251 -- primitives of the type, but are declared in the same immediate
9252 -- declarative part, which can only mean the corresponding package
9253 -- body (see RM 4.1.3 (9.2/3)). If we are in that body we extend the
9254 -- list of primitives with body operations with the same name that
9255 -- may be candidates, so that Try_Primitive_Operations can examine
9256 -- them if no real primitive is found.
9257
9258 function Is_Private_Overriding (Op : Entity_Id) return Boolean;
9259 -- An operation that overrides an inherited operation in the private
9260 -- part of its package may be hidden, but if the inherited operation
9261 -- is visible a direct call to it will dispatch to the private one,
9262 -- which is therefore a valid candidate.
9263
9264 function Names_Match
9265 (Obj_Type : Entity_Id;
9266 Prim_Op : Entity_Id;
9267 Subprog : Entity_Id) return Boolean;
9268 -- Return True if the names of Prim_Op and Subprog match. If Obj_Type
9269 -- is a protected type then compare also the original name of Prim_Op
9270 -- with the name of Subprog (since the expander may have added a
9271 -- prefix to its original name --see Exp_Ch9.Build_Selected_Name).
9272
9273 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
9274 -- Verify that the prefix, dereferenced if need be, is a valid
9275 -- controlling argument in a call to Op. The remaining actuals
9276 -- are checked in the subsequent call to Analyze_One_Call.
9277
9278 ------------------------------
9279 -- Collect_Generic_Type_Ops --
9280 ------------------------------
9281
9282 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
9283 Bas : constant Entity_Id := Base_Type (T);
9284 Candidates : constant Elist_Id := New_Elmt_List;
9285 Subp : Entity_Id;
9286 Formal : Entity_Id;
9287
9288 procedure Check_Candidate;
9289 -- The operation is a candidate if its first parameter is a
9290 -- controlling operand of the desired type.
9291
9292 -----------------------
9293 -- Check_Candidate; --
9294 -----------------------
9295
9296 procedure Check_Candidate is
9297 begin
9298 Formal := First_Formal (Subp);
9299
9300 if Present (Formal)
9301 and then Is_Controlling_Formal (Formal)
9302 and then
9303 (Base_Type (Etype (Formal)) = Bas
9304 or else
9305 (Is_Access_Type (Etype (Formal))
9306 and then Designated_Type (Etype (Formal)) = Bas))
9307 then
9308 Append_Elmt (Subp, Candidates);
9309 end if;
9310 end Check_Candidate;
9311
9312 -- Start of processing for Collect_Generic_Type_Ops
9313
9314 begin
9315 if Is_Derived_Type (T) then
9316 return Primitive_Operations (T);
9317
9318 elsif Ekind_In (Scope (T), E_Procedure, E_Function) then
9319
9320 -- Scan the list of generic formals to find subprograms
9321 -- that may have a first controlling formal of the type.
9322
9323 if Nkind (Unit_Declaration_Node (Scope (T))) =
9324 N_Generic_Subprogram_Declaration
9325 then
9326 declare
9327 Decl : Node_Id;
9328
9329 begin
9330 Decl :=
9331 First (Generic_Formal_Declarations
9332 (Unit_Declaration_Node (Scope (T))));
9333 while Present (Decl) loop
9334 if Nkind (Decl) in N_Formal_Subprogram_Declaration then
9335 Subp := Defining_Entity (Decl);
9336 Check_Candidate;
9337 end if;
9338
9339 Next (Decl);
9340 end loop;
9341 end;
9342 end if;
9343 return Candidates;
9344
9345 else
9346 -- Scan the list of entities declared in the same scope as
9347 -- the type. In general this will be an open scope, given that
9348 -- the call we are analyzing can only appear within a generic
9349 -- declaration or body (either the one that declares T, or a
9350 -- child unit).
9351
9352 -- For a subtype representing a generic actual type, go to the
9353 -- base type.
9354
9355 if Is_Generic_Actual_Type (T) then
9356 Subp := First_Entity (Scope (Base_Type (T)));
9357 else
9358 Subp := First_Entity (Scope (T));
9359 end if;
9360
9361 while Present (Subp) loop
9362 if Is_Overloadable (Subp) then
9363 Check_Candidate;
9364 end if;
9365
9366 Next_Entity (Subp);
9367 end loop;
9368
9369 return Candidates;
9370 end if;
9371 end Collect_Generic_Type_Ops;
9372
9373 ----------------------------
9374 -- Extended_Primitive_Ops --
9375 ----------------------------
9376
9377 function Extended_Primitive_Ops (T : Entity_Id) return Elist_Id is
9378 Type_Scope : constant Entity_Id := Scope (T);
9379 Op_List : Elist_Id := Primitive_Operations (T);
9380 begin
9381 if Is_Package_Or_Generic_Package (Type_Scope)
9382 and then ((In_Package_Body (Type_Scope)
9383 and then In_Open_Scopes (Type_Scope)) or else In_Instance_Body)
9384 then
9385 -- Retrieve list of declarations of package body if possible
9386
9387 declare
9388 The_Body : constant Node_Id :=
9389 Corresponding_Body (Unit_Declaration_Node (Type_Scope));
9390 begin
9391 if Present (The_Body) then
9392 declare
9393 Body_Decls : constant List_Id :=
9394 Declarations (Unit_Declaration_Node (The_Body));
9395 Op_Found : Boolean := False;
9396 Op : Entity_Id := Current_Entity (Subprog);
9397 begin
9398 while Present (Op) loop
9399 if Comes_From_Source (Op)
9400 and then Is_Overloadable (Op)
9401
9402 -- Exclude overriding primitive operations of a
9403 -- type extension declared in the package body,
9404 -- to prevent duplicates in extended list.
9405
9406 and then not Is_Primitive (Op)
9407 and then Is_List_Member
9408 (Unit_Declaration_Node (Op))
9409 and then List_Containing
9410 (Unit_Declaration_Node (Op)) = Body_Decls
9411 then
9412 if not Op_Found then
9413 -- Copy list of primitives so it is not
9414 -- affected for other uses.
9415
9416 Op_List := New_Copy_Elist (Op_List);
9417 Op_Found := True;
9418 end if;
9419
9420 Append_Elmt (Op, Op_List);
9421 end if;
9422
9423 Op := Homonym (Op);
9424 end loop;
9425 end;
9426 end if;
9427 end;
9428 end if;
9429
9430 return Op_List;
9431 end Extended_Primitive_Ops;
9432
9433 ---------------------------
9434 -- Is_Private_Overriding --
9435 ---------------------------
9436
9437 function Is_Private_Overriding (Op : Entity_Id) return Boolean is
9438 Visible_Op : Entity_Id;
9439
9440 begin
9441 -- The subprogram may be overloaded with both visible and private
9442 -- entities with the same name. We have to scan the chain of
9443 -- homonyms to determine whether there is a previous implicit
9444 -- declaration in the same scope that is overridden by the
9445 -- private candidate.
9446
9447 Visible_Op := Homonym (Op);
9448 while Present (Visible_Op) loop
9449 if Scope (Op) /= Scope (Visible_Op) then
9450 return False;
9451
9452 elsif not Comes_From_Source (Visible_Op)
9453 and then Alias (Visible_Op) = Op
9454 and then not Is_Hidden (Visible_Op)
9455 then
9456 return True;
9457 end if;
9458
9459 Visible_Op := Homonym (Visible_Op);
9460 end loop;
9461
9462 return False;
9463 end Is_Private_Overriding;
9464
9465 -----------------
9466 -- Names_Match --
9467 -----------------
9468
9469 function Names_Match
9470 (Obj_Type : Entity_Id;
9471 Prim_Op : Entity_Id;
9472 Subprog : Entity_Id) return Boolean is
9473 begin
9474 -- Common case: exact match
9475
9476 if Chars (Prim_Op) = Chars (Subprog) then
9477 return True;
9478
9479 -- For protected type primitives the expander may have built the
9480 -- name of the dispatching primitive prepending the type name to
9481 -- avoid conflicts with the name of the protected subprogram (see
9482 -- Exp_Ch9.Build_Selected_Name).
9483
9484 elsif Is_Protected_Type (Obj_Type) then
9485 return
9486 Present (Original_Protected_Subprogram (Prim_Op))
9487 and then Chars (Original_Protected_Subprogram (Prim_Op)) =
9488 Chars (Subprog);
9489
9490 -- In an instance, the selector name may be a generic actual that
9491 -- renames a primitive operation of the type of the prefix.
9492
9493 elsif In_Instance and then Present (Current_Entity (Subprog)) then
9494 declare
9495 Subp : constant Entity_Id := Current_Entity (Subprog);
9496 begin
9497 if Present (Subp)
9498 and then Is_Subprogram (Subp)
9499 and then Present (Renamed_Entity (Subp))
9500 and then Is_Generic_Actual_Subprogram (Subp)
9501 and then Chars (Renamed_Entity (Subp)) = Chars (Prim_Op)
9502 then
9503 return True;
9504 end if;
9505 end;
9506 end if;
9507
9508 return False;
9509 end Names_Match;
9510
9511 -----------------------------
9512 -- Valid_First_Argument_Of --
9513 -----------------------------
9514
9515 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
9516 Typ : Entity_Id := Etype (First_Formal (Op));
9517
9518 begin
9519 if Is_Concurrent_Type (Typ)
9520 and then Present (Corresponding_Record_Type (Typ))
9521 then
9522 Typ := Corresponding_Record_Type (Typ);
9523 end if;
9524
9525 -- Simple case. Object may be a subtype of the tagged type or may
9526 -- be the corresponding record of a synchronized type.
9527
9528 return Obj_Type = Typ
9529 or else Base_Type (Obj_Type) = Typ
9530 or else Corr_Type = Typ
9531
9532 -- Object may be of a derived type whose parent has unknown
9533 -- discriminants, in which case the type matches the underlying
9534 -- record view of its base.
9535
9536 or else
9537 (Has_Unknown_Discriminants (Typ)
9538 and then Typ = Underlying_Record_View (Base_Type (Obj_Type)))
9539
9540 -- Prefix can be dereferenced
9541
9542 or else
9543 (Is_Access_Type (Corr_Type)
9544 and then Designated_Type (Corr_Type) = Typ)
9545
9546 -- Formal is an access parameter, for which the object can
9547 -- provide an access.
9548
9549 or else
9550 (Ekind (Typ) = E_Anonymous_Access_Type
9551 and then
9552 Base_Type (Designated_Type (Typ)) = Base_Type (Corr_Type));
9553 end Valid_First_Argument_Of;
9554
9555 -- Start of processing for Try_Primitive_Operation
9556
9557 begin
9558 -- Look for subprograms in the list of primitive operations. The name
9559 -- must be identical, and the kind of call indicates the expected
9560 -- kind of operation (function or procedure). If the type is a
9561 -- (tagged) synchronized type, the primitive ops are attached to the
9562 -- corresponding record (base) type.
9563
9564 if Is_Concurrent_Type (Obj_Type) then
9565 if Present (Corresponding_Record_Type (Obj_Type)) then
9566 Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
9567 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
9568 else
9569 Corr_Type := Obj_Type;
9570 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
9571 end if;
9572
9573 elsif not Is_Generic_Type (Obj_Type) then
9574 Corr_Type := Obj_Type;
9575 Elmt := First_Elmt (Extended_Primitive_Ops (Obj_Type));
9576
9577 else
9578 Corr_Type := Obj_Type;
9579 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
9580 end if;
9581
9582 while Present (Elmt) loop
9583 Prim_Op := Node (Elmt);
9584
9585 if Names_Match (Obj_Type, Prim_Op, Subprog)
9586 and then Present (First_Formal (Prim_Op))
9587 and then Valid_First_Argument_Of (Prim_Op)
9588 and then
9589 (Nkind (Call_Node) = N_Function_Call)
9590 =
9591 (Ekind (Prim_Op) = E_Function)
9592 then
9593 -- Ada 2005 (AI-251): If this primitive operation corresponds
9594 -- to an immediate ancestor interface there is no need to add
9595 -- it to the list of interpretations; the corresponding aliased
9596 -- primitive is also in this list of primitive operations and
9597 -- will be used instead.
9598
9599 if (Present (Interface_Alias (Prim_Op))
9600 and then Is_Ancestor (Find_Dispatching_Type
9601 (Alias (Prim_Op)), Corr_Type))
9602
9603 -- Do not consider hidden primitives unless the type is in an
9604 -- open scope or we are within an instance, where visibility
9605 -- is known to be correct, or else if this is an overriding
9606 -- operation in the private part for an inherited operation.
9607
9608 or else (Is_Hidden (Prim_Op)
9609 and then not Is_Immediately_Visible (Obj_Type)
9610 and then not In_Instance
9611 and then not Is_Private_Overriding (Prim_Op))
9612 then
9613 goto Continue;
9614 end if;
9615
9616 Set_Etype (Call_Node, Any_Type);
9617 Set_Is_Overloaded (Call_Node, False);
9618
9619 if No (Matching_Op) then
9620 Prim_Op_Ref := New_Occurrence_Of (Prim_Op, Sloc (Subprog));
9621 Candidate := Prim_Op;
9622
9623 Set_Parent (Call_Node, Parent (Node_To_Replace));
9624
9625 Set_Name (Call_Node, Prim_Op_Ref);
9626 Success := False;
9627
9628 Analyze_One_Call
9629 (N => Call_Node,
9630 Nam => Prim_Op,
9631 Report => Report_Error,
9632 Success => Success,
9633 Skip_First => True);
9634
9635 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
9636
9637 -- More than one interpretation, collect for subsequent
9638 -- disambiguation. If this is a procedure call and there
9639 -- is another match, report ambiguity now.
9640
9641 else
9642 Analyze_One_Call
9643 (N => Call_Node,
9644 Nam => Prim_Op,
9645 Report => Report_Error,
9646 Success => Success,
9647 Skip_First => True);
9648
9649 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
9650 and then Nkind (Call_Node) /= N_Function_Call
9651 then
9652 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
9653 Report_Ambiguity (Matching_Op);
9654 Report_Ambiguity (Prim_Op);
9655 return True;
9656 end if;
9657 end if;
9658 end if;
9659
9660 <<Continue>>
9661 Next_Elmt (Elmt);
9662 end loop;
9663
9664 if Present (Matching_Op) then
9665 Set_Etype (Call_Node, Etype (Matching_Op));
9666 end if;
9667
9668 return Present (Matching_Op);
9669 end Try_Primitive_Operation;
9670
9671 ---------------------
9672 -- Valid_Candidate --
9673 ---------------------
9674
9675 function Valid_Candidate
9676 (Success : Boolean;
9677 Call : Node_Id;
9678 Subp : Entity_Id) return Entity_Id
9679 is
9680 Arr_Type : Entity_Id;
9681 Comp_Type : Entity_Id;
9682
9683 begin
9684 -- If the subprogram is a valid interpretation, record it in global
9685 -- variable Subprog, to collect all possible overloadings.
9686
9687 if Success then
9688 if Subp /= Entity (Subprog) then
9689 Add_One_Interp (Subprog, Subp, Etype (Subp));
9690 end if;
9691 end if;
9692
9693 -- If the call may be an indexed call, retrieve component type of
9694 -- resulting expression, and add possible interpretation.
9695
9696 Arr_Type := Empty;
9697 Comp_Type := Empty;
9698
9699 if Nkind (Call) = N_Function_Call
9700 and then Nkind (Parent (N)) = N_Indexed_Component
9701 and then Needs_One_Actual (Subp)
9702 then
9703 if Is_Array_Type (Etype (Subp)) then
9704 Arr_Type := Etype (Subp);
9705
9706 elsif Is_Access_Type (Etype (Subp))
9707 and then Is_Array_Type (Designated_Type (Etype (Subp)))
9708 then
9709 Arr_Type := Designated_Type (Etype (Subp));
9710 end if;
9711 end if;
9712
9713 if Present (Arr_Type) then
9714
9715 -- Verify that the actuals (excluding the object) match the types
9716 -- of the indexes.
9717
9718 declare
9719 Actual : Node_Id;
9720 Index : Node_Id;
9721
9722 begin
9723 Actual := Next (First_Actual (Call));
9724 Index := First_Index (Arr_Type);
9725 while Present (Actual) and then Present (Index) loop
9726 if not Has_Compatible_Type (Actual, Etype (Index)) then
9727 Arr_Type := Empty;
9728 exit;
9729 end if;
9730
9731 Next_Actual (Actual);
9732 Next_Index (Index);
9733 end loop;
9734
9735 if No (Actual)
9736 and then No (Index)
9737 and then Present (Arr_Type)
9738 then
9739 Comp_Type := Component_Type (Arr_Type);
9740 end if;
9741 end;
9742
9743 if Present (Comp_Type)
9744 and then Etype (Subprog) /= Comp_Type
9745 then
9746 Add_One_Interp (Subprog, Subp, Comp_Type);
9747 end if;
9748 end if;
9749
9750 if Etype (Call) /= Any_Type then
9751 return Subp;
9752 else
9753 return Empty;
9754 end if;
9755 end Valid_Candidate;
9756
9757 -- Start of processing for Try_Object_Operation
9758
9759 begin
9760 Analyze_Expression (Obj);
9761
9762 -- Analyze the actuals if node is known to be a subprogram call
9763
9764 if Is_Subprg_Call and then N = Name (Parent (N)) then
9765 Actual := First (Parameter_Associations (Parent (N)));
9766 while Present (Actual) loop
9767 Analyze_Expression (Actual);
9768 Next (Actual);
9769 end loop;
9770 end if;
9771
9772 -- Build a subprogram call node, using a copy of Obj as its first
9773 -- actual. This is a placeholder, to be replaced by an explicit
9774 -- dereference when needed.
9775
9776 Transform_Object_Operation
9777 (Call_Node => New_Call_Node,
9778 Node_To_Replace => Node_To_Replace);
9779
9780 Set_Etype (New_Call_Node, Any_Type);
9781 Set_Etype (Subprog, Any_Type);
9782 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
9783
9784 if not Is_Overloaded (Obj) then
9785 Try_One_Prefix_Interpretation (Obj_Type);
9786
9787 else
9788 declare
9789 I : Interp_Index;
9790 It : Interp;
9791 begin
9792 Get_First_Interp (Obj, I, It);
9793 while Present (It.Nam) loop
9794 Try_One_Prefix_Interpretation (It.Typ);
9795 Get_Next_Interp (I, It);
9796 end loop;
9797 end;
9798 end if;
9799
9800 if Etype (New_Call_Node) /= Any_Type then
9801
9802 -- No need to complete the tree transformations if we are only
9803 -- searching for conflicting class-wide subprograms
9804
9805 if CW_Test_Only then
9806 return False;
9807 else
9808 Complete_Object_Operation
9809 (Call_Node => New_Call_Node,
9810 Node_To_Replace => Node_To_Replace);
9811 return True;
9812 end if;
9813
9814 elsif Present (Candidate) then
9815
9816 -- The argument list is not type correct. Re-analyze with error
9817 -- reporting enabled, and use one of the possible candidates.
9818 -- In All_Errors_Mode, re-analyze all failed interpretations.
9819
9820 if All_Errors_Mode then
9821 Report_Error := True;
9822 if Try_Primitive_Operation
9823 (Call_Node => New_Call_Node,
9824 Node_To_Replace => Node_To_Replace)
9825
9826 or else
9827 Try_Class_Wide_Operation
9828 (Call_Node => New_Call_Node,
9829 Node_To_Replace => Node_To_Replace)
9830 then
9831 null;
9832 end if;
9833
9834 else
9835 Analyze_One_Call
9836 (N => New_Call_Node,
9837 Nam => Candidate,
9838 Report => True,
9839 Success => Success,
9840 Skip_First => True);
9841 end if;
9842
9843 -- No need for further errors
9844
9845 return True;
9846
9847 else
9848 -- There was no candidate operation, but Analyze_Selected_Component
9849 -- may continue the analysis so we need to undo the change possibly
9850 -- made to the Parent of N earlier by Transform_Object_Operation.
9851
9852 declare
9853 Parent_Node : constant Node_Id := Parent (N);
9854
9855 begin
9856 if Node_To_Replace = Parent_Node then
9857 Remove (First (Parameter_Associations (New_Call_Node)));
9858 Set_Parent
9859 (Parameter_Associations (New_Call_Node), Parent_Node);
9860 end if;
9861 end;
9862
9863 return False;
9864 end if;
9865 end Try_Object_Operation;
9866
9867 ---------
9868 -- wpo --
9869 ---------
9870
9871 procedure wpo (T : Entity_Id) is
9872 Op : Entity_Id;
9873 E : Elmt_Id;
9874
9875 begin
9876 if not Is_Tagged_Type (T) then
9877 return;
9878 end if;
9879
9880 E := First_Elmt (Primitive_Operations (Base_Type (T)));
9881 while Present (E) loop
9882 Op := Node (E);
9883 Write_Int (Int (Op));
9884 Write_Str (" === ");
9885 Write_Name (Chars (Op));
9886 Write_Str (" in ");
9887 Write_Name (Chars (Scope (Op)));
9888 Next_Elmt (E);
9889 Write_Eol;
9890 end loop;
9891 end wpo;
9892
9893 end Sem_Ch4;
This page took 0.505776 seconds and 5 git commands to generate.