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