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