]> 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-- --
2ba431e5 9-- Copyright (C) 1992-2011, 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;
d935a36e 33with Fname; use Fname;
996ae0b0 34with Itypes; use Itypes;
d935a36e 35with Lib; use Lib;
996ae0b0
RK
36with Lib.Xref; use Lib.Xref;
37with Namet; use Namet;
d469eabe 38with Namet.Sp; use Namet.Sp;
996ae0b0
RK
39with Nlists; use Nlists;
40with Nmake; use Nmake;
41with Opt; use Opt;
42with Output; use Output;
43with Restrict; use Restrict;
6e937c1c 44with Rident; use Rident;
996ae0b0 45with Sem; use Sem;
a4100e55 46with Sem_Aux; use Sem_Aux;
19d846a0 47with Sem_Case; use Sem_Case;
996ae0b0
RK
48with Sem_Cat; use Sem_Cat;
49with Sem_Ch3; use Sem_Ch3;
a961aa79 50with Sem_Ch5; use Sem_Ch5;
d469eabe 51with Sem_Ch6; use Sem_Ch6;
996ae0b0 52with Sem_Ch8; use Sem_Ch8;
b67a385c 53with Sem_Disp; use Sem_Disp;
996ae0b0
RK
54with Sem_Dist; use Sem_Dist;
55with Sem_Eval; use Sem_Eval;
56with Sem_Res; use Sem_Res;
996ae0b0 57with Sem_Type; use Sem_Type;
19d846a0
RD
58with Sem_Util; use Sem_Util;
59with Sem_Warn; use Sem_Warn;
996ae0b0
RK
60with Stand; use Stand;
61with Sinfo; use Sinfo;
62with Snames; use Snames;
63with Tbuild; use Tbuild;
64
996ae0b0
RK
65package body Sem_Ch4 is
66
67 -----------------------
68 -- Local Subprograms --
69 -----------------------
70
fe39cf20
BD
71 procedure Analyze_Concatenation_Rest (N : Node_Id);
72 -- Does the "rest" of the work of Analyze_Concatenation, after the left
73 -- operand has been analyzed. See Analyze_Concatenation for details.
74
996ae0b0
RK
75 procedure Analyze_Expression (N : Node_Id);
76 -- For expressions that are not names, this is just a call to analyze.
77 -- If the expression is a name, it may be a call to a parameterless
78 -- function, and if so must be converted into an explicit call node
79 -- and analyzed as such. This deproceduring must be done during the first
80 -- pass of overload resolution, because otherwise a procedure call with
b4592168 81 -- overloaded actuals may fail to resolve.
996ae0b0
RK
82
83 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
84 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
85 -- is an operator name or an expanded name whose selector is an operator
86 -- name, and one possible interpretation is as a predefined operator.
87
88 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
89 -- If the prefix of a selected_component is overloaded, the proper
90 -- interpretation that yields a record type with the proper selector
91 -- name must be selected.
92
93 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
94 -- Procedure to analyze a user defined binary operator, which is resolved
95 -- like a function, but instead of a list of actuals it is presented
96 -- with the left and right operands of an operator node.
97
98 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
99 -- Procedure to analyze a user defined unary operator, which is resolved
100 -- like a function, but instead of a list of actuals, it is presented with
101 -- the operand of the operator node.
102
103 procedure Ambiguous_Operands (N : Node_Id);
0877856b 104 -- For equality, membership, and comparison operators with overloaded
996ae0b0
RK
105 -- arguments, list possible interpretations.
106
996ae0b0 107 procedure Analyze_One_Call
ec6078e3
ES
108 (N : Node_Id;
109 Nam : Entity_Id;
110 Report : Boolean;
111 Success : out Boolean;
112 Skip_First : Boolean := False);
996ae0b0
RK
113 -- Check one interpretation of an overloaded subprogram name for
114 -- compatibility with the types of the actuals in a call. If there is a
115 -- single interpretation which does not match, post error if Report is
116 -- set to True.
117 --
118 -- Nam is the entity that provides the formals against which the actuals
119 -- are checked. Nam is either the name of a subprogram, or the internal
120 -- subprogram type constructed for an access_to_subprogram. If the actuals
121 -- are compatible with Nam, then Nam is added to the list of candidate
122 -- interpretations for N, and Success is set to True.
ec6078e3
ES
123 --
124 -- The flag Skip_First is used when analyzing a call that was rewritten
125 -- from object notation. In this case the first actual may have to receive
126 -- an explicit dereference, depending on the first formal of the operation
127 -- being called. The caller will have verified that the object is legal
128 -- for the call. If the remaining parameters match, the first parameter
129 -- will rewritten as a dereference if needed, prior to completing analysis.
996ae0b0
RK
130
131 procedure Check_Misspelled_Selector
132 (Prefix : Entity_Id;
133 Sel : Node_Id);
8dbf3473
AC
134 -- Give possible misspelling diagnostic if Sel is likely to be a mis-
135 -- spelling of one of the selectors of the Prefix. This is called by
136 -- Analyze_Selected_Component after producing an invalid selector error
137 -- message.
996ae0b0
RK
138
139 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
f3d57416 140 -- Verify that type T is declared in scope S. Used to find interpretations
996ae0b0
RK
141 -- for operators given by expanded names. This is abstracted as a separate
142 -- function to handle extensions to System, where S is System, but T is
143 -- declared in the extension.
144
145 procedure Find_Arithmetic_Types
146 (L, R : Node_Id;
147 Op_Id : Entity_Id;
148 N : Node_Id);
149 -- L and R are the operands of an arithmetic operator. Find
150 -- consistent pairs of interpretations for L and R that have a
151 -- numeric type consistent with the semantics of the operator.
152
153 procedure Find_Comparison_Types
154 (L, R : Node_Id;
155 Op_Id : Entity_Id;
156 N : Node_Id);
157 -- L and R are operands of a comparison operator. Find consistent
158 -- pairs of interpretations for L and R.
159
160 procedure Find_Concatenation_Types
161 (L, R : Node_Id;
162 Op_Id : Entity_Id;
163 N : Node_Id);
6e73e3ab 164 -- For the four varieties of concatenation
996ae0b0
RK
165
166 procedure Find_Equality_Types
167 (L, R : Node_Id;
168 Op_Id : Entity_Id;
169 N : Node_Id);
6e73e3ab 170 -- Ditto for equality operators
996ae0b0
RK
171
172 procedure Find_Boolean_Types
173 (L, R : Node_Id;
174 Op_Id : Entity_Id;
175 N : Node_Id);
6e73e3ab 176 -- Ditto for binary logical operations
996ae0b0
RK
177
178 procedure Find_Negation_Types
179 (R : Node_Id;
180 Op_Id : Entity_Id;
181 N : Node_Id);
6e73e3ab 182 -- Find consistent interpretation for operand of negation operator
996ae0b0
RK
183
184 procedure Find_Non_Universal_Interpretations
185 (N : Node_Id;
186 R : Node_Id;
187 Op_Id : Entity_Id;
188 T1 : Entity_Id);
189 -- For equality and comparison operators, the result is always boolean,
190 -- and the legality of the operation is determined from the visibility
191 -- of the operand types. If one of the operands has a universal interpre-
192 -- tation, the legality check uses some compatible non-universal
193 -- interpretation of the other operand. N can be an operator node, or
194 -- a function call whose name is an operator designator.
195
d469eabe
HK
196 function Find_Primitive_Operation (N : Node_Id) return Boolean;
197 -- Find candidate interpretations for the name Obj.Proc when it appears
198 -- in a subprogram renaming declaration.
199
996ae0b0
RK
200 procedure Find_Unary_Types
201 (R : Node_Id;
202 Op_Id : Entity_Id;
203 N : Node_Id);
6e73e3ab 204 -- Unary arithmetic types: plus, minus, abs
996ae0b0
RK
205
206 procedure Check_Arithmetic_Pair
207 (T1, T2 : Entity_Id;
208 Op_Id : Entity_Id;
209 N : Node_Id);
210 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
211 -- types for left and right operand. Determine whether they constitute
212 -- a valid pair for the given operator, and record the corresponding
213 -- interpretation of the operator node. The node N may be an operator
214 -- node (the usual case) or a function call whose prefix is an operator
401093c1 215 -- designator. In both cases Op_Id is the operator name itself.
996ae0b0
RK
216
217 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
218 -- Give detailed information on overloaded call where none of the
219 -- interpretations match. N is the call node, Nam the designator for
220 -- the overloaded entity being called.
221
222 function Junk_Operand (N : Node_Id) return Boolean;
223 -- Test for an operand that is an inappropriate entity (e.g. a package
224 -- name or a label). If so, issue an error message and return True. If
225 -- the operand is not an inappropriate entity kind, return False.
226
227 procedure Operator_Check (N : Node_Id);
da709d08
AC
228 -- Verify that an operator has received some valid interpretation. If none
229 -- was found, determine whether a use clause would make the operation
230 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
231 -- every type compatible with the operator, even if the operator for the
232 -- type is not directly visible. The routine uses this type to emit a more
233 -- informative message.
996ae0b0 234
d469eabe 235 function Process_Implicit_Dereference_Prefix
da709d08 236 (E : Entity_Id;
d469eabe 237 P : Node_Id) return Entity_Id;
da709d08 238 -- Called when P is the prefix of an implicit dereference, denoting an
d469eabe
HK
239 -- object E. The function returns the designated type of the prefix, taking
240 -- into account that the designated type of an anonymous access type may be
241 -- a limited view, when the non-limited view is visible.
242 -- If in semantics only mode (-gnatc or generic), the function also records
243 -- that the prefix is a reference to E, if any. Normally, such a reference
244 -- is generated only when the implicit dereference is expanded into an
245 -- explicit one, but for consistency we must generate the reference when
246 -- expansion is disabled as well.
6e73e3ab 247
30c20106
AC
248 procedure Remove_Abstract_Operations (N : Node_Id);
249 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
250 -- operation is not a candidate interpretation.
251
d50f4827
AC
252 function Try_Container_Indexing
253 (N : Node_Id;
254 Prefix : Node_Id;
255 Expr : Node_Id) return Boolean;
256 -- AI05-0139: Generalized indexing to support iterators over containers
257
996ae0b0 258 function Try_Indexed_Call
aab883ec
ES
259 (N : Node_Id;
260 Nam : Entity_Id;
261 Typ : Entity_Id;
262 Skip_First : Boolean) return Boolean;
263 -- If a function has defaults for all its actuals, a call to it may in fact
264 -- be an indexing on the result of the call. Try_Indexed_Call attempts the
265 -- interpretation as an indexing, prior to analysis as a call. If both are
266 -- possible, the node is overloaded with both interpretations (same symbol
267 -- but two different types). If the call is written in prefix form, the
268 -- prefix becomes the first parameter in the call, and only the remaining
269 -- actuals must be checked for the presence of defaults.
996ae0b0
RK
270
271 function Try_Indirect_Call
91b1417d
AC
272 (N : Node_Id;
273 Nam : Entity_Id;
274 Typ : Entity_Id) return Boolean;
aab883ec
ES
275 -- Similarly, a function F that needs no actuals can return an access to a
276 -- subprogram, and the call F (X) interpreted as F.all (X). In this case
277 -- the call may be overloaded with both interpretations.
996ae0b0 278
35ae2ed8 279 function Try_Object_Operation (N : Node_Id) return Boolean;
0d57c6f4
RD
280 -- Ada 2005 (AI-252): Support the object.operation notation. If node N
281 -- is a call in this notation, it is transformed into a normal subprogram
282 -- call where the prefix is a parameter, and True is returned. If node
283 -- N is not of this form, it is unchanged, and False is returned.
35ae2ed8 284
b4592168
GD
285 procedure wpo (T : Entity_Id);
286 pragma Warnings (Off, wpo);
287 -- Used for debugging: obtain list of primitive operations even if
288 -- type is not frozen and dispatch table is not built yet.
289
996ae0b0
RK
290 ------------------------
291 -- Ambiguous_Operands --
292 ------------------------
293
294 procedure Ambiguous_Operands (N : Node_Id) is
fbf5a39b 295 procedure List_Operand_Interps (Opnd : Node_Id);
996ae0b0 296
4c46b835
AC
297 --------------------------
298 -- List_Operand_Interps --
299 --------------------------
300
fbf5a39b 301 procedure List_Operand_Interps (Opnd : Node_Id) is
996ae0b0
RK
302 Nam : Node_Id;
303 Err : Node_Id := N;
304
305 begin
306 if Is_Overloaded (Opnd) then
307 if Nkind (Opnd) in N_Op then
308 Nam := Opnd;
996ae0b0
RK
309 elsif Nkind (Opnd) = N_Function_Call then
310 Nam := Name (Opnd);
44a10091
AC
311 elsif Ada_Version >= Ada_2012 then
312 declare
313 It : Interp;
314 I : Interp_Index;
315
316 begin
317 Get_First_Interp (Opnd, I, It);
318 while Present (It.Nam) loop
319 if Has_Implicit_Dereference (It.Typ) then
320 Error_Msg_N
321 ("can be interpreted as implicit dereference", Opnd);
322 return;
323 end if;
324
325 Get_Next_Interp (I, It);
326 end loop;
327 end;
328
996ae0b0
RK
329 return;
330 end if;
331
332 else
333 return;
334 end if;
335
336 if Opnd = Left_Opnd (N) then
ed2233dc 337 Error_Msg_N ("\left operand has the following interpretations", N);
996ae0b0 338 else
ed2233dc 339 Error_Msg_N
996ae0b0
RK
340 ("\right operand has the following interpretations", N);
341 Err := Opnd;
342 end if;
343
fbf5a39b
AC
344 List_Interps (Nam, Err);
345 end List_Operand_Interps;
996ae0b0 346
4c46b835
AC
347 -- Start of processing for Ambiguous_Operands
348
996ae0b0 349 begin
b67a385c 350 if Nkind (N) in N_Membership_Test then
ed2233dc 351 Error_Msg_N ("ambiguous operands for membership", N);
996ae0b0 352
d469eabe 353 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
ed2233dc 354 Error_Msg_N ("ambiguous operands for equality", N);
996ae0b0
RK
355
356 else
ed2233dc 357 Error_Msg_N ("ambiguous operands for comparison", N);
996ae0b0
RK
358 end if;
359
360 if All_Errors_Mode then
fbf5a39b
AC
361 List_Operand_Interps (Left_Opnd (N));
362 List_Operand_Interps (Right_Opnd (N));
996ae0b0 363 else
555360a5 364 Error_Msg_N ("\use -gnatf switch for details", N);
996ae0b0
RK
365 end if;
366 end Ambiguous_Operands;
367
368 -----------------------
369 -- Analyze_Aggregate --
370 -----------------------
371
372 -- Most of the analysis of Aggregates requires that the type be known,
373 -- and is therefore put off until resolution.
374
375 procedure Analyze_Aggregate (N : Node_Id) is
376 begin
377 if No (Etype (N)) then
378 Set_Etype (N, Any_Composite);
379 end if;
380 end Analyze_Aggregate;
381
382 -----------------------
383 -- Analyze_Allocator --
384 -----------------------
385
386 procedure Analyze_Allocator (N : Node_Id) is
387 Loc : constant Source_Ptr := Sloc (N);
07fc65c4 388 Sav_Errs : constant Nat := Serious_Errors_Detected;
b67a385c 389 E : Node_Id := Expression (N);
996ae0b0
RK
390 Acc_Type : Entity_Id;
391 Type_Id : Entity_Id;
87003b28
RD
392 P : Node_Id;
393 C : Node_Id;
996ae0b0
RK
394
395 begin
2ba431e5 396 Check_SPARK_Restriction ("allocator is not allowed", N);
1d801f21 397
87003b28
RD
398 -- Deal with allocator restrictions
399
50cff367 400 -- In accordance with H.4(7), the No_Allocators restriction only applies
87003b28
RD
401 -- to user-written allocators. The same consideration applies to the
402 -- No_Allocators_Before_Elaboration restriction.
50cff367
GD
403
404 if Comes_From_Source (N) then
405 Check_Restriction (No_Allocators, N);
87003b28
RD
406
407 -- Processing for No_Allocators_After_Elaboration, loop to look at
408 -- enclosing context, checking task case and main subprogram case.
409
410 C := N;
411 P := Parent (C);
412 while Present (P) loop
413
414 -- In both cases we need a handled sequence of statements, where
415 -- the occurrence of the allocator is within the statements.
416
417 if Nkind (P) = N_Handled_Sequence_Of_Statements
418 and then Is_List_Member (C)
419 and then List_Containing (C) = Statements (P)
420 then
421 -- Check for allocator within task body, this is a definite
422 -- violation of No_Allocators_After_Elaboration we can detect.
423
424 if Nkind (Original_Node (Parent (P))) = N_Task_Body then
425 Check_Restriction (No_Allocators_After_Elaboration, N);
426 exit;
427 end if;
428
308e6f3a 429 -- The other case is appearance in a subprogram body. This may
87003b28
RD
430 -- be a violation if this is a library level subprogram, and it
431 -- turns out to be used as the main program, but only the
432 -- binder knows that, so just record the occurrence.
433
434 if Nkind (Original_Node (Parent (P))) = N_Subprogram_Body
435 and then Nkind (Parent (Parent (P))) = N_Compilation_Unit
436 then
437 Set_Has_Allocator (Current_Sem_Unit);
438 end if;
439 end if;
440
441 C := P;
442 P := Parent (C);
443 end loop;
50cff367 444 end if;
996ae0b0 445
df170605
AC
446 -- Ada 2012 (AI05-0111-3): Analyze the subpool_specification, if
447 -- any. The expected type for the name is any type. A non-overloading
448 -- rule then requires it to be of a type descended from
f0f88eb6
RD
449 -- System.Storage_Pools.Subpools.Subpool_Handle.
450
451 -- This isn't exactly what the AI says, but it seems to be the right
452 -- rule. The AI should be fixed.???
df170605
AC
453
454 declare
455 Subpool : constant Node_Id := Subpool_Handle_Name (N);
f0f88eb6 456
df170605
AC
457 begin
458 if Present (Subpool) then
459 Analyze (Subpool);
f0f88eb6 460
df170605
AC
461 if Is_Overloaded (Subpool) then
462 Error_Msg_N ("ambiguous subpool handle", Subpool);
463 end if;
464
f0f88eb6 465 -- Check that Etype (Subpool) is descended from Subpool_Handle
df170605
AC
466
467 Resolve (Subpool);
468 end if;
469 end;
470
471 -- Analyze the qualified expression or subtype indication
87003b28 472
996ae0b0
RK
473 if Nkind (E) = N_Qualified_Expression then
474 Acc_Type := Create_Itype (E_Allocator_Type, N);
475 Set_Etype (Acc_Type, Acc_Type);
996ae0b0 476 Find_Type (Subtype_Mark (E));
45c8b94b
ES
477
478 -- Analyze the qualified expression, and apply the name resolution
f0f88eb6 479 -- rule given in 4.7(3).
45c8b94b
ES
480
481 Analyze (E);
482 Type_Id := Etype (E);
996ae0b0
RK
483 Set_Directly_Designated_Type (Acc_Type, Type_Id);
484
45c8b94b 485 Resolve (Expression (E), Type_Id);
b67a385c 486
d05ef0ab 487 if Is_Limited_Type (Type_Id)
996ae0b0
RK
488 and then Comes_From_Source (N)
489 and then not In_Instance_Body
490 then
2a31c32b 491 if not OK_For_Limited_Init (Type_Id, Expression (E)) then
d05ef0ab
AC
492 Error_Msg_N ("initialization not allowed for limited types", N);
493 Explain_Limited_Type (Type_Id, N);
494 end if;
996ae0b0
RK
495 end if;
496
996ae0b0
RK
497 -- A qualified expression requires an exact match of the type,
498 -- class-wide matching is not allowed.
499
45c8b94b
ES
500 -- if Is_Class_Wide_Type (Type_Id)
501 -- and then Base_Type
502 -- (Etype (Expression (E))) /= Base_Type (Type_Id)
503 -- then
504 -- Wrong_Type (Expression (E), Type_Id);
505 -- end if;
996ae0b0
RK
506
507 Check_Non_Static_Context (Expression (E));
508
509 -- We don't analyze the qualified expression itself because it's
510 -- part of the allocator
511
512 Set_Etype (E, Type_Id);
513
aab883ec 514 -- Case where allocator has a subtype indication
4c46b835 515
996ae0b0
RK
516 else
517 declare
758c442c
GD
518 Def_Id : Entity_Id;
519 Base_Typ : Entity_Id;
996ae0b0
RK
520
521 begin
522 -- If the allocator includes a N_Subtype_Indication then a
523 -- constraint is present, otherwise the node is a subtype mark.
524 -- Introduce an explicit subtype declaration into the tree
525 -- defining some anonymous subtype and rewrite the allocator to
526 -- use this subtype rather than the subtype indication.
527
528 -- It is important to introduce the explicit subtype declaration
529 -- so that the bounds of the subtype indication are attached to
530 -- the tree in case the allocator is inside a generic unit.
531
532 if Nkind (E) = N_Subtype_Indication then
533
534 -- A constraint is only allowed for a composite type in Ada
535 -- 95. In Ada 83, a constraint is also allowed for an
536 -- access-to-composite type, but the constraint is ignored.
537
538 Find_Type (Subtype_Mark (E));
758c442c 539 Base_Typ := Entity (Subtype_Mark (E));
996ae0b0 540
758c442c 541 if Is_Elementary_Type (Base_Typ) then
0ab80019 542 if not (Ada_Version = Ada_83
758c442c 543 and then Is_Access_Type (Base_Typ))
996ae0b0
RK
544 then
545 Error_Msg_N ("constraint not allowed here", E);
546
24657705
HK
547 if Nkind (Constraint (E)) =
548 N_Index_Or_Discriminant_Constraint
996ae0b0 549 then
4e7a4f6e 550 Error_Msg_N -- CODEFIX
996ae0b0
RK
551 ("\if qualified expression was meant, " &
552 "use apostrophe", Constraint (E));
553 end if;
554 end if;
555
556 -- Get rid of the bogus constraint:
557
558 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
559 Analyze_Allocator (N);
560 return;
758c442c
GD
561
562 -- Ada 2005, AI-363: if the designated type has a constrained
563 -- partial view, it cannot receive a discriminant constraint,
564 -- and the allocated object is unconstrained.
565
0791fbe9 566 elsif Ada_Version >= Ada_2005
758c442c
GD
567 and then Has_Constrained_Partial_View (Base_Typ)
568 then
569 Error_Msg_N
570 ("constraint no allowed when type " &
571 "has a constrained partial view", Constraint (E));
996ae0b0
RK
572 end if;
573
574 if Expander_Active then
092ef350 575 Def_Id := Make_Temporary (Loc, 'S');
996ae0b0
RK
576
577 Insert_Action (E,
578 Make_Subtype_Declaration (Loc,
579 Defining_Identifier => Def_Id,
580 Subtype_Indication => Relocate_Node (E)));
581
07fc65c4 582 if Sav_Errs /= Serious_Errors_Detected
d469eabe
HK
583 and then Nkind (Constraint (E)) =
584 N_Index_Or_Discriminant_Constraint
996ae0b0 585 then
4e7a4f6e 586 Error_Msg_N -- CODEFIX
996ae0b0
RK
587 ("if qualified expression was meant, " &
588 "use apostrophe!", Constraint (E));
589 end if;
590
591 E := New_Occurrence_Of (Def_Id, Loc);
592 Rewrite (Expression (N), E);
593 end if;
594 end if;
595
596 Type_Id := Process_Subtype (E, N);
597 Acc_Type := Create_Itype (E_Allocator_Type, N);
598 Set_Etype (Acc_Type, Acc_Type);
996ae0b0
RK
599 Set_Directly_Designated_Type (Acc_Type, Type_Id);
600 Check_Fully_Declared (Type_Id, N);
601
1baa4d2d 602 -- Ada 2005 (AI-231): If the designated type is itself an access
16b05213 603 -- type that excludes null, its default initialization will
75ad5042
ES
604 -- be a null object, and we can insert an unconditional raise
605 -- before the allocator.
2820d220 606
bfae1846 607 -- Ada 2012 (AI-104): A not null indication here is altogether
518ade91
AC
608 -- illegal.
609
2820d220 610 if Can_Never_Be_Null (Type_Id) then
75ad5042
ES
611 declare
612 Not_Null_Check : constant Node_Id :=
613 Make_Raise_Constraint_Error (Sloc (E),
614 Reason => CE_Null_Not_Allowed);
40b93859 615
75ad5042 616 begin
dbe945f1 617 if Ada_Version >= Ada_2012 then
518ade91
AC
618 Error_Msg_N
619 ("an uninitialized allocator cannot have"
620 & " a null exclusion", N);
621
622 elsif Expander_Active then
75ad5042
ES
623 Insert_Action (N, Not_Null_Check);
624 Analyze (Not_Null_Check);
40b93859 625
75ad5042
ES
626 else
627 Error_Msg_N ("null value not allowed here?", E);
628 end if;
629 end;
2820d220
AC
630 end if;
631
91b1417d
AC
632 -- Check restriction against dynamically allocated protected
633 -- objects. Note that when limited aggregates are supported,
634 -- a similar test should be applied to an allocator with a
635 -- qualified expression ???
636
637 if Is_Protected_Type (Type_Id) then
638 Check_Restriction (No_Protected_Type_Allocators, N);
639 end if;
640
996ae0b0
RK
641 -- Check for missing initialization. Skip this check if we already
642 -- had errors on analyzing the allocator, since in that case these
24657705 643 -- are probably cascaded errors.
996ae0b0
RK
644
645 if Is_Indefinite_Subtype (Type_Id)
07fc65c4 646 and then Serious_Errors_Detected = Sav_Errs
996ae0b0
RK
647 then
648 if Is_Class_Wide_Type (Type_Id) then
649 Error_Msg_N
650 ("initialization required in class-wide allocation", N);
651 else
0791fbe9 652 if Ada_Version < Ada_2005
24657705
HK
653 and then Is_Limited_Type (Type_Id)
654 then
655 Error_Msg_N ("unconstrained allocation not allowed", N);
656
657 if Is_Array_Type (Type_Id) then
658 Error_Msg_N
659 ("\constraint with array bounds required", N);
660
661 elsif Has_Unknown_Discriminants (Type_Id) then
662 null;
663
664 else pragma Assert (Has_Discriminants (Type_Id));
665 Error_Msg_N
666 ("\constraint with discriminant values required", N);
667 end if;
668
669 -- Limited Ada 2005 and general non-limited case
670
671 else
672 Error_Msg_N
673 ("uninitialized unconstrained allocation not allowed",
674 N);
675
676 if Is_Array_Type (Type_Id) then
677 Error_Msg_N
678 ("\qualified expression or constraint with " &
679 "array bounds required", N);
680
681 elsif Has_Unknown_Discriminants (Type_Id) then
682 Error_Msg_N ("\qualified expression required", N);
683
684 else pragma Assert (Has_Discriminants (Type_Id));
685 Error_Msg_N
686 ("\qualified expression or constraint with " &
687 "discriminant values required", N);
688 end if;
689 end if;
996ae0b0
RK
690 end if;
691 end if;
692 end;
693 end if;
694
aab883ec 695 if Is_Abstract_Type (Type_Id) then
996ae0b0
RK
696 Error_Msg_N ("cannot allocate abstract object", E);
697 end if;
698
699 if Has_Task (Designated_Type (Acc_Type)) then
6e937c1c 700 Check_Restriction (No_Tasking, N);
fbf5a39b 701 Check_Restriction (Max_Tasks, N);
996ae0b0 702 Check_Restriction (No_Task_Allocators, N);
70b3b953
GD
703 end if;
704
705 -- Check that an allocator of a nested access type doesn't create a
706 -- protected object when restriction No_Local_Protected_Objects applies.
707 -- We don't have an equivalent to Has_Task for protected types, so only
708 -- cases where the designated type itself is a protected type are
709 -- currently checked. ???
710
711 if Is_Protected_Type (Designated_Type (Acc_Type))
712 and then not Is_Library_Level_Entity (Acc_Type)
713 then
714 Check_Restriction (No_Local_Protected_Objects, N);
996ae0b0
RK
715 end if;
716
ffe9aba8
AC
717 -- If the No_Streams restriction is set, check that the type of the
718 -- object is not, and does not contain, any subtype derived from
719 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
720 -- Has_Stream just for efficiency reasons. There is no point in
721 -- spending time on a Has_Stream check if the restriction is not set.
722
7a963087 723 if Restriction_Check_Required (No_Streams) then
ffe9aba8
AC
724 if Has_Stream (Designated_Type (Acc_Type)) then
725 Check_Restriction (No_Streams, N);
726 end if;
727 end if;
728
996ae0b0
RK
729 Set_Etype (N, Acc_Type);
730
731 if not Is_Library_Level_Entity (Acc_Type) then
732 Check_Restriction (No_Local_Allocators, N);
733 end if;
2820d220 734
07fc65c4 735 if Serious_Errors_Detected > Sav_Errs then
996ae0b0
RK
736 Set_Error_Posted (N);
737 Set_Etype (N, Any_Type);
738 end if;
996ae0b0
RK
739 end Analyze_Allocator;
740
741 ---------------------------
742 -- Analyze_Arithmetic_Op --
743 ---------------------------
744
745 procedure Analyze_Arithmetic_Op (N : Node_Id) is
746 L : constant Node_Id := Left_Opnd (N);
747 R : constant Node_Id := Right_Opnd (N);
748 Op_Id : Entity_Id;
749
750 begin
751 Candidate_Type := Empty;
752 Analyze_Expression (L);
753 Analyze_Expression (R);
754
d469eabe
HK
755 -- If the entity is already set, the node is the instantiation of a
756 -- generic node with a non-local reference, or was manufactured by a
757 -- call to Make_Op_xxx. In either case the entity is known to be valid,
758 -- and we do not need to collect interpretations, instead we just get
759 -- the single possible interpretation.
996ae0b0
RK
760
761 Op_Id := Entity (N);
762
763 if Present (Op_Id) then
764 if Ekind (Op_Id) = E_Operator then
765
d469eabe 766 if Nkind_In (N, N_Op_Divide, N_Op_Mod, N_Op_Multiply, N_Op_Rem)
996ae0b0
RK
767 and then Treat_Fixed_As_Integer (N)
768 then
769 null;
770 else
771 Set_Etype (N, Any_Type);
772 Find_Arithmetic_Types (L, R, Op_Id, N);
773 end if;
774
775 else
776 Set_Etype (N, Any_Type);
777 Add_One_Interp (N, Op_Id, Etype (Op_Id));
778 end if;
779
780 -- Entity is not already set, so we do need to collect interpretations
781
782 else
783 Op_Id := Get_Name_Entity_Id (Chars (N));
784 Set_Etype (N, Any_Type);
785
786 while Present (Op_Id) loop
787 if Ekind (Op_Id) = E_Operator
788 and then Present (Next_Entity (First_Entity (Op_Id)))
789 then
790 Find_Arithmetic_Types (L, R, Op_Id, N);
791
792 -- The following may seem superfluous, because an operator cannot
793 -- be generic, but this ignores the cleverness of the author of
794 -- ACVC bc1013a.
795
796 elsif Is_Overloadable (Op_Id) then
797 Analyze_User_Defined_Binary_Op (N, Op_Id);
798 end if;
799
800 Op_Id := Homonym (Op_Id);
801 end loop;
802 end if;
803
804 Operator_Check (N);
805 end Analyze_Arithmetic_Op;
806
807 ------------------
808 -- Analyze_Call --
809 ------------------
810
4c46b835
AC
811 -- Function, procedure, and entry calls are checked here. The Name in
812 -- the call may be overloaded. The actuals have been analyzed and may
813 -- themselves be overloaded. On exit from this procedure, the node N
814 -- may have zero, one or more interpretations. In the first case an
815 -- error message is produced. In the last case, the node is flagged
816 -- as overloaded and the interpretations are collected in All_Interp.
996ae0b0
RK
817
818 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
819 -- the type-checking is similar to that of other calls.
820
821 procedure Analyze_Call (N : Node_Id) is
822 Actuals : constant List_Id := Parameter_Associations (N);
63319f58 823 Nam : Node_Id;
996ae0b0
RK
824 X : Interp_Index;
825 It : Interp;
826 Nam_Ent : Entity_Id;
63319f58
RD
827 Success : Boolean := False;
828
829 Deref : Boolean := False;
1cb17b78
AC
830 -- Flag indicates whether an interpretation of the prefix is a
831 -- parameterless call that returns an access_to_subprogram.
996ae0b0 832
23685ae6
AC
833 procedure Check_Mixed_Parameter_And_Named_Associations;
834 -- Check that parameter and named associations are not mixed. This is
835 -- a restriction in SPARK mode.
836
996ae0b0 837 function Name_Denotes_Function return Boolean;
5ff22245
ES
838 -- If the type of the name is an access to subprogram, this may be the
839 -- type of a name, or the return type of the function being called. If
840 -- the name is not an entity then it can denote a protected function.
841 -- Until we distinguish Etype from Return_Type, we must use this routine
842 -- to resolve the meaning of the name in the call.
843
844 procedure No_Interpretation;
845 -- Output error message when no valid interpretation exists
996ae0b0 846
23685ae6
AC
847 --------------------------------------------------
848 -- Check_Mixed_Parameter_And_Named_Associations --
849 --------------------------------------------------
850
851 procedure Check_Mixed_Parameter_And_Named_Associations is
852 Actual : Node_Id;
853 Named_Seen : Boolean;
f5afb270 854
23685ae6 855 begin
23685ae6 856 Named_Seen := False;
f5afb270
AC
857
858 Actual := First (Actuals);
23685ae6
AC
859 while Present (Actual) loop
860 case Nkind (Actual) is
861 when N_Parameter_Association =>
862 if Named_Seen then
2ba431e5 863 Check_SPARK_Restriction
23685ae6
AC
864 ("named association cannot follow positional one",
865 Actual);
866 exit;
867 end if;
868 when others =>
869 Named_Seen := True;
870 end case;
871
872 Next (Actual);
873 end loop;
874 end Check_Mixed_Parameter_And_Named_Associations;
875
996ae0b0
RK
876 ---------------------------
877 -- Name_Denotes_Function --
878 ---------------------------
879
880 function Name_Denotes_Function return Boolean is
881 begin
882 if Is_Entity_Name (Nam) then
883 return Ekind (Entity (Nam)) = E_Function;
884
885 elsif Nkind (Nam) = N_Selected_Component then
886 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
887
888 else
889 return False;
890 end if;
891 end Name_Denotes_Function;
892
5ff22245
ES
893 -----------------------
894 -- No_Interpretation --
895 -----------------------
896
897 procedure No_Interpretation is
898 L : constant Boolean := Is_List_Member (N);
899 K : constant Node_Kind := Nkind (Parent (N));
900
901 begin
902 -- If the node is in a list whose parent is not an expression then it
903 -- must be an attempted procedure call.
904
905 if L and then K not in N_Subexpr then
906 if Ekind (Entity (Nam)) = E_Generic_Procedure then
907 Error_Msg_NE
908 ("must instantiate generic procedure& before call",
909 Nam, Entity (Nam));
910 else
911 Error_Msg_N
912 ("procedure or entry name expected", Nam);
913 end if;
914
915 -- Check for tasking cases where only an entry call will do
916
917 elsif not L
918 and then Nkind_In (K, N_Entry_Call_Alternative,
919 N_Triggering_Alternative)
920 then
921 Error_Msg_N ("entry name expected", Nam);
922
923 -- Otherwise give general error message
924
925 else
926 Error_Msg_N ("invalid prefix in call", Nam);
927 end if;
928 end No_Interpretation;
929
996ae0b0
RK
930 -- Start of processing for Analyze_Call
931
932 begin
24558db8 933 if Restriction_Check_Required (SPARK) then
23685ae6
AC
934 Check_Mixed_Parameter_And_Named_Associations;
935 end if;
936
996ae0b0
RK
937 -- Initialize the type of the result of the call to the error type,
938 -- which will be reset if the type is successfully resolved.
939
940 Set_Etype (N, Any_Type);
941
63319f58
RD
942 Nam := Name (N);
943
996ae0b0
RK
944 if not Is_Overloaded (Nam) then
945
946 -- Only one interpretation to check
947
948 if Ekind (Etype (Nam)) = E_Subprogram_Type then
949 Nam_Ent := Etype (Nam);
950
758c442c
GD
951 -- If the prefix is an access_to_subprogram, this may be an indirect
952 -- call. This is the case if the name in the call is not an entity
953 -- name, or if it is a function name in the context of a procedure
954 -- call. In this latter case, we have a call to a parameterless
955 -- function that returns a pointer_to_procedure which is the entity
5ff22245
ES
956 -- being called. Finally, F (X) may be a call to a parameterless
957 -- function that returns a pointer to a function with parameters.
758c442c 958
996ae0b0
RK
959 elsif Is_Access_Type (Etype (Nam))
960 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
758c442c
GD
961 and then
962 (not Name_Denotes_Function
5ff22245
ES
963 or else Nkind (N) = N_Procedure_Call_Statement
964 or else
965 (Nkind (Parent (N)) /= N_Explicit_Dereference
966 and then Is_Entity_Name (Nam)
967 and then No (First_Formal (Entity (Nam)))
968 and then Present (Actuals)))
996ae0b0
RK
969 then
970 Nam_Ent := Designated_Type (Etype (Nam));
971 Insert_Explicit_Dereference (Nam);
972
973 -- Selected component case. Simple entry or protected operation,
974 -- where the entry name is given by the selector name.
975
976 elsif Nkind (Nam) = N_Selected_Component then
977 Nam_Ent := Entity (Selector_Name (Nam));
978
bce79204
AC
979 if not Ekind_In (Nam_Ent, E_Entry,
980 E_Entry_Family,
981 E_Function,
982 E_Procedure)
996ae0b0
RK
983 then
984 Error_Msg_N ("name in call is not a callable entity", Nam);
985 Set_Etype (N, Any_Type);
986 return;
987 end if;
988
989 -- If the name is an Indexed component, it can be a call to a member
990 -- of an entry family. The prefix must be a selected component whose
991 -- selector is the entry. Analyze_Procedure_Call normalizes several
992 -- kinds of call into this form.
993
994 elsif Nkind (Nam) = N_Indexed_Component then
996ae0b0
RK
995 if Nkind (Prefix (Nam)) = N_Selected_Component then
996 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
996ae0b0
RK
997 else
998 Error_Msg_N ("name in call is not a callable entity", Nam);
999 Set_Etype (N, Any_Type);
1000 return;
996ae0b0
RK
1001 end if;
1002
1003 elsif not Is_Entity_Name (Nam) then
1004 Error_Msg_N ("name in call is not a callable entity", Nam);
1005 Set_Etype (N, Any_Type);
1006 return;
1007
1008 else
1009 Nam_Ent := Entity (Nam);
1010
1011 -- If no interpretations, give error message
1012
1013 if not Is_Overloadable (Nam_Ent) then
5ff22245
ES
1014 No_Interpretation;
1015 return;
1016 end if;
1017 end if;
996ae0b0 1018
5ff22245
ES
1019 -- Operations generated for RACW stub types are called only through
1020 -- dispatching, and can never be the static interpretation of a call.
996ae0b0 1021
5ff22245
ES
1022 if Is_RACW_Stub_Type_Operation (Nam_Ent) then
1023 No_Interpretation;
1024 return;
996ae0b0
RK
1025 end if;
1026
1027 Analyze_One_Call (N, Nam_Ent, True, Success);
1028
ec6078e3
ES
1029 -- If this is an indirect call, the return type of the access_to
1030 -- subprogram may be an incomplete type. At the point of the call,
947430d5
AC
1031 -- use the full type if available, and at the same time update the
1032 -- return type of the access_to_subprogram.
ec6078e3
ES
1033
1034 if Success
d469eabe 1035 and then Nkind (Nam) = N_Explicit_Dereference
ec6078e3
ES
1036 and then Ekind (Etype (N)) = E_Incomplete_Type
1037 and then Present (Full_View (Etype (N)))
1038 then
1039 Set_Etype (N, Full_View (Etype (N)));
1040 Set_Etype (Nam_Ent, Etype (N));
1041 end if;
1042
996ae0b0 1043 else
5ff22245
ES
1044 -- An overloaded selected component must denote overloaded operations
1045 -- of a concurrent type. The interpretations are attached to the
1046 -- simple name of those operations.
996ae0b0
RK
1047
1048 if Nkind (Nam) = N_Selected_Component then
1049 Nam := Selector_Name (Nam);
1050 end if;
1051
1052 Get_First_Interp (Nam, X, It);
1053
1054 while Present (It.Nam) loop
1055 Nam_Ent := It.Nam;
1cb17b78 1056 Deref := False;
996ae0b0
RK
1057
1058 -- Name may be call that returns an access to subprogram, or more
1059 -- generally an overloaded expression one of whose interpretations
947430d5
AC
1060 -- yields an access to subprogram. If the name is an entity, we do
1061 -- not dereference, because the node is a call that returns the
1062 -- access type: note difference between f(x), where the call may
1063 -- return an access subprogram type, and f(x)(y), where the type
1064 -- returned by the call to f is implicitly dereferenced to analyze
1065 -- the outer call.
996ae0b0
RK
1066
1067 if Is_Access_Type (Nam_Ent) then
1068 Nam_Ent := Designated_Type (Nam_Ent);
1069
1070 elsif Is_Access_Type (Etype (Nam_Ent))
1cb17b78
AC
1071 and then
1072 (not Is_Entity_Name (Nam)
1073 or else Nkind (N) = N_Procedure_Call_Statement)
996ae0b0
RK
1074 and then Ekind (Designated_Type (Etype (Nam_Ent)))
1075 = E_Subprogram_Type
1076 then
1077 Nam_Ent := Designated_Type (Etype (Nam_Ent));
1cb17b78
AC
1078
1079 if Is_Entity_Name (Nam) then
1080 Deref := True;
1081 end if;
996ae0b0
RK
1082 end if;
1083
7415029d
AC
1084 -- If the call has been rewritten from a prefixed call, the first
1085 -- parameter has been analyzed, but may need a subsequent
1086 -- dereference, so skip its analysis now.
1087
1088 if N /= Original_Node (N)
1089 and then Nkind (Original_Node (N)) = Nkind (N)
1090 and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N)))
1091 and then Present (Parameter_Associations (N))
1092 and then Present (Etype (First (Parameter_Associations (N))))
1093 then
1094 Analyze_One_Call
1095 (N, Nam_Ent, False, Success, Skip_First => True);
1096 else
1097 Analyze_One_Call (N, Nam_Ent, False, Success);
1098 end if;
996ae0b0
RK
1099
1100 -- If the interpretation succeeds, mark the proper type of the
1101 -- prefix (any valid candidate will do). If not, remove the
1102 -- candidate interpretation. This only needs to be done for
1103 -- overloaded protected operations, for other entities disambi-
1104 -- guation is done directly in Resolve.
1105
1106 if Success then
1cb17b78
AC
1107 if Deref
1108 and then Nkind (Parent (N)) /= N_Explicit_Dereference
1109 then
1110 Set_Entity (Nam, It.Nam);
1111 Insert_Explicit_Dereference (Nam);
1112 Set_Etype (Nam, Nam_Ent);
1113
1114 else
1115 Set_Etype (Nam, It.Typ);
1116 end if;
996ae0b0 1117
d469eabe
HK
1118 elsif Nkind_In (Name (N), N_Selected_Component,
1119 N_Function_Call)
fbf5a39b 1120 then
996ae0b0
RK
1121 Remove_Interp (X);
1122 end if;
1123
1124 Get_Next_Interp (X, It);
1125 end loop;
1126
1127 -- If the name is the result of a function call, it can only
1128 -- be a call to a function returning an access to subprogram.
1129 -- Insert explicit dereference.
1130
1131 if Nkind (Nam) = N_Function_Call then
1132 Insert_Explicit_Dereference (Nam);
1133 end if;
1134
1135 if Etype (N) = Any_Type then
1136
1137 -- None of the interpretations is compatible with the actuals
1138
1139 Diagnose_Call (N, Nam);
1140
1141 -- Special checks for uninstantiated put routines
1142
1143 if Nkind (N) = N_Procedure_Call_Statement
1144 and then Is_Entity_Name (Nam)
1145 and then Chars (Nam) = Name_Put
1146 and then List_Length (Actuals) = 1
1147 then
1148 declare
1149 Arg : constant Node_Id := First (Actuals);
1150 Typ : Entity_Id;
1151
1152 begin
1153 if Nkind (Arg) = N_Parameter_Association then
1154 Typ := Etype (Explicit_Actual_Parameter (Arg));
1155 else
1156 Typ := Etype (Arg);
1157 end if;
1158
1159 if Is_Signed_Integer_Type (Typ) then
1160 Error_Msg_N
1161 ("possible missing instantiation of " &
1162 "'Text_'I'O.'Integer_'I'O!", Nam);
1163
1164 elsif Is_Modular_Integer_Type (Typ) then
1165 Error_Msg_N
1166 ("possible missing instantiation of " &
1167 "'Text_'I'O.'Modular_'I'O!", Nam);
1168
1169 elsif Is_Floating_Point_Type (Typ) then
1170 Error_Msg_N
1171 ("possible missing instantiation of " &
1172 "'Text_'I'O.'Float_'I'O!", Nam);
1173
1174 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
1175 Error_Msg_N
1176 ("possible missing instantiation of " &
1177 "'Text_'I'O.'Fixed_'I'O!", Nam);
1178
1179 elsif Is_Decimal_Fixed_Point_Type (Typ) then
1180 Error_Msg_N
1181 ("possible missing instantiation of " &
1182 "'Text_'I'O.'Decimal_'I'O!", Nam);
1183
1184 elsif Is_Enumeration_Type (Typ) then
1185 Error_Msg_N
1186 ("possible missing instantiation of " &
1187 "'Text_'I'O.'Enumeration_'I'O!", Nam);
1188 end if;
1189 end;
1190 end if;
1191
1192 elsif not Is_Overloaded (N)
1193 and then Is_Entity_Name (Nam)
1194 then
aab883ec
ES
1195 -- Resolution yields a single interpretation. Verify that the
1196 -- reference has capitalization consistent with the declaration.
996ae0b0
RK
1197
1198 Set_Entity_With_Style_Check (Nam, Entity (Nam));
1199 Generate_Reference (Entity (Nam), Nam);
1200
1201 Set_Etype (Nam, Etype (Entity (Nam)));
30c20106
AC
1202 else
1203 Remove_Abstract_Operations (N);
996ae0b0
RK
1204 end if;
1205
1206 End_Interp_List;
1207 end if;
1208 end Analyze_Call;
1209
19d846a0
RD
1210 -----------------------------
1211 -- Analyze_Case_Expression --
1212 -----------------------------
1213
1214 procedure Analyze_Case_Expression (N : Node_Id) is
1215 Expr : constant Node_Id := Expression (N);
1216 FirstX : constant Node_Id := Expression (First (Alternatives (N)));
1217 Alt : Node_Id;
1218 Exp_Type : Entity_Id;
1219 Exp_Btype : Entity_Id;
1220
19d846a0
RD
1221 Dont_Care : Boolean;
1222 Others_Present : Boolean;
1223
1224 procedure Non_Static_Choice_Error (Choice : Node_Id);
1225 -- Error routine invoked by the generic instantiation below when
1226 -- the case expression has a non static choice.
1227
1228 package Case_Choices_Processing is new
1229 Generic_Choices_Processing
1230 (Get_Alternatives => Alternatives,
1231 Get_Choices => Discrete_Choices,
1232 Process_Empty_Choice => No_OP,
1233 Process_Non_Static_Choice => Non_Static_Choice_Error,
1234 Process_Associated_Node => No_OP);
1235 use Case_Choices_Processing;
1236
19d846a0
RD
1237 -----------------------------
1238 -- Non_Static_Choice_Error --
1239 -----------------------------
1240
1241 procedure Non_Static_Choice_Error (Choice : Node_Id) is
1242 begin
1243 Flag_Non_Static_Expr
1244 ("choice given in case expression is not static!", Choice);
1245 end Non_Static_Choice_Error;
1246
1247 -- Start of processing for Analyze_Case_Expression
1248
1249 begin
1250 if Comes_From_Source (N) then
1251 Check_Compiler_Unit (N);
1252 end if;
1253
1254 Analyze_And_Resolve (Expr, Any_Discrete);
1255 Check_Unset_Reference (Expr);
1256 Exp_Type := Etype (Expr);
1257 Exp_Btype := Base_Type (Exp_Type);
1258
1259 Alt := First (Alternatives (N));
1260 while Present (Alt) loop
1261 Analyze (Expression (Alt));
1262 Next (Alt);
1263 end loop;
1264
1265 if not Is_Overloaded (FirstX) then
1266 Set_Etype (N, Etype (FirstX));
1267
1268 else
1269 declare
1270 I : Interp_Index;
1271 It : Interp;
1272
1273 begin
1274 Set_Etype (N, Any_Type);
1275
1276 Get_First_Interp (FirstX, I, It);
1277 while Present (It.Nam) loop
1278
308e6f3a
RW
1279 -- For each interpretation of the first expression, we only
1280 -- add the interpretation if every other expression in the
19d846a0
RD
1281 -- case expression alternatives has a compatible type.
1282
1283 Alt := Next (First (Alternatives (N)));
1284 while Present (Alt) loop
1285 exit when not Has_Compatible_Type (Expression (Alt), It.Typ);
1286 Next (Alt);
1287 end loop;
1288
1289 if No (Alt) then
1290 Add_One_Interp (N, It.Typ, It.Typ);
1291 end if;
1292
1293 Get_Next_Interp (I, It);
1294 end loop;
1295 end;
1296 end if;
1297
1298 Exp_Btype := Base_Type (Exp_Type);
1299
1300 -- The expression must be of a discrete type which must be determinable
1301 -- independently of the context in which the expression occurs, but
1302 -- using the fact that the expression must be of a discrete type.
1303 -- Moreover, the type this expression must not be a character literal
1304 -- (which is always ambiguous).
1305
1306 -- If error already reported by Resolve, nothing more to do
1307
1308 if Exp_Btype = Any_Discrete
1309 or else Exp_Btype = Any_Type
1310 then
1311 return;
1312
1313 elsif Exp_Btype = Any_Character then
1314 Error_Msg_N
1315 ("character literal as case expression is ambiguous", Expr);
1316 return;
1317 end if;
1318
1319 -- If the case expression is a formal object of mode in out, then
1320 -- treat it as having a nonstatic subtype by forcing use of the base
1321 -- type (which has to get passed to Check_Case_Choices below). Also
1322 -- use base type when the case expression is parenthesized.
1323
1324 if Paren_Count (Expr) > 0
1325 or else (Is_Entity_Name (Expr)
1326 and then Ekind (Entity (Expr)) = E_Generic_In_Out_Parameter)
1327 then
1328 Exp_Type := Exp_Btype;
1329 end if;
1330
1331 -- Call instantiated Analyze_Choices which does the rest of the work
1332
86200f66 1333 Analyze_Choices (N, Exp_Type, Dont_Care, Others_Present);
19d846a0
RD
1334
1335 if Exp_Type = Universal_Integer and then not Others_Present then
1336 Error_Msg_N
1337 ("case on universal integer requires OTHERS choice", Expr);
1338 end if;
1339 end Analyze_Case_Expression;
1340
996ae0b0
RK
1341 ---------------------------
1342 -- Analyze_Comparison_Op --
1343 ---------------------------
1344
1345 procedure Analyze_Comparison_Op (N : Node_Id) is
1346 L : constant Node_Id := Left_Opnd (N);
1347 R : constant Node_Id := Right_Opnd (N);
1348 Op_Id : Entity_Id := Entity (N);
1349
1350 begin
1351 Set_Etype (N, Any_Type);
1352 Candidate_Type := Empty;
1353
1354 Analyze_Expression (L);
1355 Analyze_Expression (R);
1356
1357 if Present (Op_Id) then
996ae0b0
RK
1358 if Ekind (Op_Id) = E_Operator then
1359 Find_Comparison_Types (L, R, Op_Id, N);
1360 else
1361 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1362 end if;
1363
1364 if Is_Overloaded (L) then
1365 Set_Etype (L, Intersect_Types (L, R));
1366 end if;
1367
1368 else
1369 Op_Id := Get_Name_Entity_Id (Chars (N));
996ae0b0 1370 while Present (Op_Id) loop
996ae0b0
RK
1371 if Ekind (Op_Id) = E_Operator then
1372 Find_Comparison_Types (L, R, Op_Id, N);
1373 else
1374 Analyze_User_Defined_Binary_Op (N, Op_Id);
1375 end if;
1376
1377 Op_Id := Homonym (Op_Id);
1378 end loop;
1379 end if;
1380
1381 Operator_Check (N);
1382 end Analyze_Comparison_Op;
1383
1384 ---------------------------
1385 -- Analyze_Concatenation --
1386 ---------------------------
1387
fe39cf20
BD
1388 procedure Analyze_Concatenation (N : Node_Id) is
1389
1390 -- We wish to avoid deep recursion, because concatenations are often
1391 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1392 -- operands nonrecursively until we find something that is not a
1393 -- concatenation (A in this case), or has already been analyzed. We
1394 -- analyze that, and then walk back up the tree following Parent
1395 -- pointers, calling Analyze_Concatenation_Rest to do the rest of the
1396 -- work at each level. The Parent pointers allow us to avoid recursion,
1397 -- and thus avoid running out of memory.
1398
1399 NN : Node_Id := N;
1400 L : Node_Id;
1401
1402 begin
1403 Candidate_Type := Empty;
1404
1405 -- The following code is equivalent to:
1406
1407 -- Set_Etype (N, Any_Type);
1408 -- Analyze_Expression (Left_Opnd (N));
1409 -- Analyze_Concatenation_Rest (N);
1410
1411 -- where the Analyze_Expression call recurses back here if the left
1412 -- operand is a concatenation.
1413
1414 -- Walk down left operands
1415
1416 loop
1417 Set_Etype (NN, Any_Type);
1418 L := Left_Opnd (NN);
1419 exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
1420 NN := L;
1421 end loop;
1422
1423 -- Now (given the above example) NN is A&B and L is A
1424
1425 -- First analyze L ...
1426
1427 Analyze_Expression (L);
1428
1429 -- ... then walk NN back up until we reach N (where we started), calling
1430 -- Analyze_Concatenation_Rest along the way.
1431
1432 loop
1433 Analyze_Concatenation_Rest (NN);
1434 exit when NN = N;
1435 NN := Parent (NN);
1436 end loop;
1437 end Analyze_Concatenation;
1438
1439 --------------------------------
1440 -- Analyze_Concatenation_Rest --
1441 --------------------------------
1442
996ae0b0
RK
1443 -- If the only one-dimensional array type in scope is String,
1444 -- this is the resulting type of the operation. Otherwise there
1445 -- will be a concatenation operation defined for each user-defined
1446 -- one-dimensional array.
1447
fe39cf20 1448 procedure Analyze_Concatenation_Rest (N : Node_Id) is
996ae0b0
RK
1449 L : constant Node_Id := Left_Opnd (N);
1450 R : constant Node_Id := Right_Opnd (N);
1451 Op_Id : Entity_Id := Entity (N);
1452 LT : Entity_Id;
1453 RT : Entity_Id;
1454
1455 begin
996ae0b0
RK
1456 Analyze_Expression (R);
1457
cd3cd5b1
AC
1458 -- If the entity is present, the node appears in an instance, and
1459 -- denotes a predefined concatenation operation. The resulting type is
1460 -- obtained from the arguments when possible. If the arguments are
1461 -- aggregates, the array type and the concatenation type must be
fbf5a39b 1462 -- visible.
996ae0b0
RK
1463
1464 if Present (Op_Id) then
1465 if Ekind (Op_Id) = E_Operator then
996ae0b0
RK
1466 LT := Base_Type (Etype (L));
1467 RT := Base_Type (Etype (R));
1468
1469 if Is_Array_Type (LT)
1470 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1471 then
1472 Add_One_Interp (N, Op_Id, LT);
1473
1474 elsif Is_Array_Type (RT)
1475 and then LT = Base_Type (Component_Type (RT))
1476 then
1477 Add_One_Interp (N, Op_Id, RT);
1478
fbf5a39b
AC
1479 -- If one operand is a string type or a user-defined array type,
1480 -- and the other is a literal, result is of the specific type.
1481
1482 elsif
1483 (Root_Type (LT) = Standard_String
1484 or else Scope (LT) /= Standard_Standard)
1485 and then Etype (R) = Any_String
1486 then
1487 Add_One_Interp (N, Op_Id, LT);
1488
1489 elsif
1490 (Root_Type (RT) = Standard_String
1491 or else Scope (RT) /= Standard_Standard)
1492 and then Etype (L) = Any_String
1493 then
1494 Add_One_Interp (N, Op_Id, RT);
1495
1496 elsif not Is_Generic_Type (Etype (Op_Id)) then
996ae0b0 1497 Add_One_Interp (N, Op_Id, Etype (Op_Id));
fbf5a39b
AC
1498
1499 else
4c46b835 1500 -- Type and its operations must be visible
fbf5a39b
AC
1501
1502 Set_Entity (N, Empty);
1503 Analyze_Concatenation (N);
996ae0b0
RK
1504 end if;
1505
1506 else
1507 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1508 end if;
1509
1510 else
1a8fae99 1511 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
996ae0b0
RK
1512 while Present (Op_Id) loop
1513 if Ekind (Op_Id) = E_Operator then
1a8fae99
ES
1514
1515 -- Do not consider operators declared in dead code, they can
1516 -- not be part of the resolution.
1517
1518 if Is_Eliminated (Op_Id) then
1519 null;
1520 else
1521 Find_Concatenation_Types (L, R, Op_Id, N);
1522 end if;
1523
996ae0b0
RK
1524 else
1525 Analyze_User_Defined_Binary_Op (N, Op_Id);
1526 end if;
1527
1528 Op_Id := Homonym (Op_Id);
1529 end loop;
1530 end if;
1531
1532 Operator_Check (N);
fe39cf20 1533 end Analyze_Concatenation_Rest;
996ae0b0
RK
1534
1535 ------------------------------------
1536 -- Analyze_Conditional_Expression --
1537 ------------------------------------
1538
1539 procedure Analyze_Conditional_Expression (N : Node_Id) is
1540 Condition : constant Node_Id := First (Expressions (N));
1541 Then_Expr : constant Node_Id := Next (Condition);
6c994759 1542 Else_Expr : Node_Id;
b46be8a2 1543
996ae0b0 1544 begin
6c994759
AC
1545 -- Defend against error of missing expressions from previous error
1546
1547 if No (Then_Expr) then
1548 return;
1549 end if;
1550
2ba431e5 1551 Check_SPARK_Restriction ("conditional expression is not allowed", N);
1d801f21 1552
6c994759
AC
1553 Else_Expr := Next (Then_Expr);
1554
b46be8a2
RD
1555 if Comes_From_Source (N) then
1556 Check_Compiler_Unit (N);
1557 end if;
1558
996ae0b0
RK
1559 Analyze_Expression (Condition);
1560 Analyze_Expression (Then_Expr);
b46be8a2
RD
1561
1562 if Present (Else_Expr) then
1563 Analyze_Expression (Else_Expr);
1564 end if;
1565
19d846a0
RD
1566 -- If then expression not overloaded, then that decides the type
1567
bee2a781 1568 if not Is_Overloaded (Then_Expr) then
e0ba1bfd 1569 Set_Etype (N, Etype (Then_Expr));
19d846a0
RD
1570
1571 -- Case where then expression is overloaded
1572
e0ba1bfd
ES
1573 else
1574 declare
1575 I : Interp_Index;
1576 It : Interp;
1577
1578 begin
1579 Set_Etype (N, Any_Type);
8d606a78
RD
1580
1581 -- Shouldn't the following statement be down in the ELSE of the
1582 -- following loop? ???
1583
e0ba1bfd 1584 Get_First_Interp (Then_Expr, I, It);
19d846a0 1585
8d606a78
RD
1586 -- if no Else_Expression the conditional must be boolean
1587
1588 if No (Else_Expr) then
2010d078 1589 Set_Etype (N, Standard_Boolean);
19d846a0 1590
8d606a78
RD
1591 -- Else_Expression Present. For each possible intepretation of
1592 -- the Then_Expression, add it only if the Else_Expression has
1593 -- a compatible type.
19d846a0 1594
8d606a78
RD
1595 else
1596 while Present (It.Nam) loop
2010d078
AC
1597 if Has_Compatible_Type (Else_Expr, It.Typ) then
1598 Add_One_Interp (N, It.Typ, It.Typ);
1599 end if;
e0ba1bfd 1600
2010d078
AC
1601 Get_Next_Interp (I, It);
1602 end loop;
1603 end if;
e0ba1bfd
ES
1604 end;
1605 end if;
996ae0b0
RK
1606 end Analyze_Conditional_Expression;
1607
1608 -------------------------
1609 -- Analyze_Equality_Op --
1610 -------------------------
1611
1612 procedure Analyze_Equality_Op (N : Node_Id) is
4c46b835
AC
1613 Loc : constant Source_Ptr := Sloc (N);
1614 L : constant Node_Id := Left_Opnd (N);
1615 R : constant Node_Id := Right_Opnd (N);
1616 Op_Id : Entity_Id;
996ae0b0
RK
1617
1618 begin
1619 Set_Etype (N, Any_Type);
1620 Candidate_Type := Empty;
1621
1622 Analyze_Expression (L);
1623 Analyze_Expression (R);
1624
1625 -- If the entity is set, the node is a generic instance with a non-local
1626 -- reference to the predefined operator or to a user-defined function.
1627 -- It can also be an inequality that is expanded into the negation of a
1628 -- call to a user-defined equality operator.
1629
1630 -- For the predefined case, the result is Boolean, regardless of the
1631 -- type of the operands. The operands may even be limited, if they are
1632 -- generic actuals. If they are overloaded, label the left argument with
1633 -- the common type that must be present, or with the type of the formal
1634 -- of the user-defined function.
1635
1636 if Present (Entity (N)) then
996ae0b0
RK
1637 Op_Id := Entity (N);
1638
1639 if Ekind (Op_Id) = E_Operator then
1640 Add_One_Interp (N, Op_Id, Standard_Boolean);
1641 else
1642 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1643 end if;
1644
1645 if Is_Overloaded (L) then
996ae0b0
RK
1646 if Ekind (Op_Id) = E_Operator then
1647 Set_Etype (L, Intersect_Types (L, R));
1648 else
1649 Set_Etype (L, Etype (First_Formal (Op_Id)));
1650 end if;
1651 end if;
1652
1653 else
1654 Op_Id := Get_Name_Entity_Id (Chars (N));
996ae0b0 1655 while Present (Op_Id) loop
996ae0b0
RK
1656 if Ekind (Op_Id) = E_Operator then
1657 Find_Equality_Types (L, R, Op_Id, N);
1658 else
1659 Analyze_User_Defined_Binary_Op (N, Op_Id);
1660 end if;
1661
1662 Op_Id := Homonym (Op_Id);
1663 end loop;
1664 end if;
1665
1666 -- If there was no match, and the operator is inequality, this may
1667 -- be a case where inequality has not been made explicit, as for
1668 -- tagged types. Analyze the node as the negation of an equality
1669 -- operation. This cannot be done earlier, because before analysis
1670 -- we cannot rule out the presence of an explicit inequality.
1671
1672 if Etype (N) = Any_Type
1673 and then Nkind (N) = N_Op_Ne
1674 then
1675 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
996ae0b0 1676 while Present (Op_Id) loop
996ae0b0
RK
1677 if Ekind (Op_Id) = E_Operator then
1678 Find_Equality_Types (L, R, Op_Id, N);
1679 else
1680 Analyze_User_Defined_Binary_Op (N, Op_Id);
1681 end if;
1682
1683 Op_Id := Homonym (Op_Id);
1684 end loop;
1685
1686 if Etype (N) /= Any_Type then
1687 Op_Id := Entity (N);
1688
1689 Rewrite (N,
1690 Make_Op_Not (Loc,
1691 Right_Opnd =>
1692 Make_Op_Eq (Loc,
aab883ec
ES
1693 Left_Opnd => Left_Opnd (N),
1694 Right_Opnd => Right_Opnd (N))));
996ae0b0
RK
1695
1696 Set_Entity (Right_Opnd (N), Op_Id);
1697 Analyze (N);
1698 end if;
1699 end if;
1700
1701 Operator_Check (N);
1702 end Analyze_Equality_Op;
1703
1704 ----------------------------------
1705 -- Analyze_Explicit_Dereference --
1706 ----------------------------------
1707
1708 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1709 Loc : constant Source_Ptr := Sloc (N);
1710 P : constant Node_Id := Prefix (N);
1711 T : Entity_Id;
1712 I : Interp_Index;
1713 It : Interp;
1714 New_N : Node_Id;
1715
1716 function Is_Function_Type return Boolean;
4c46b835
AC
1717 -- Check whether node may be interpreted as an implicit function call
1718
1719 ----------------------
1720 -- Is_Function_Type --
1721 ----------------------
996ae0b0
RK
1722
1723 function Is_Function_Type return Boolean is
4c46b835
AC
1724 I : Interp_Index;
1725 It : Interp;
996ae0b0
RK
1726
1727 begin
1728 if not Is_Overloaded (N) then
1729 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1730 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1731
1732 else
1733 Get_First_Interp (N, I, It);
996ae0b0
RK
1734 while Present (It.Nam) loop
1735 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1736 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1737 then
1738 return False;
1739 end if;
1740
1741 Get_Next_Interp (I, It);
1742 end loop;
1743
1744 return True;
1745 end if;
1746 end Is_Function_Type;
1747
98123480 1748 -- Start of processing for Analyze_Explicit_Dereference
4c46b835 1749
996ae0b0 1750 begin
2ba431e5 1751 Check_SPARK_Restriction ("explicit dereference is not allowed", N);
1d801f21 1752
996ae0b0
RK
1753 Analyze (P);
1754 Set_Etype (N, Any_Type);
1755
1756 -- Test for remote access to subprogram type, and if so return
1757 -- after rewriting the original tree.
1758
1759 if Remote_AST_E_Dereference (P) then
1760 return;
1761 end if;
1762
1763 -- Normal processing for other than remote access to subprogram type
1764
1765 if not Is_Overloaded (P) then
1766 if Is_Access_Type (Etype (P)) then
1767
f3d57416 1768 -- Set the Etype. We need to go through Is_For_Access_Subtypes to
0a36105d
JM
1769 -- avoid other problems caused by the Private_Subtype and it is
1770 -- safe to go to the Base_Type because this is the same as
1771 -- converting the access value to its Base_Type.
996ae0b0
RK
1772
1773 declare
1774 DT : Entity_Id := Designated_Type (Etype (P));
1775
1776 begin
1777 if Ekind (DT) = E_Private_Subtype
1778 and then Is_For_Access_Subtype (DT)
1779 then
1780 DT := Base_Type (DT);
1781 end if;
1782
0a36105d
JM
1783 -- An explicit dereference is a legal occurrence of an
1784 -- incomplete type imported through a limited_with clause,
1785 -- if the full view is visible.
1786
1787 if From_With_Type (DT)
1788 and then not From_With_Type (Scope (DT))
1789 and then
1790 (Is_Immediately_Visible (Scope (DT))
1791 or else
1792 (Is_Child_Unit (Scope (DT))
1793 and then Is_Visible_Child_Unit (Scope (DT))))
1794 then
1795 Set_Etype (N, Available_View (DT));
1796
1797 else
1798 Set_Etype (N, DT);
1799 end if;
996ae0b0
RK
1800 end;
1801
1802 elsif Etype (P) /= Any_Type then
1803 Error_Msg_N ("prefix of dereference must be an access type", N);
1804 return;
1805 end if;
1806
1807 else
1808 Get_First_Interp (P, I, It);
996ae0b0
RK
1809 while Present (It.Nam) loop
1810 T := It.Typ;
1811
1812 if Is_Access_Type (T) then
1813 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1814 end if;
1815
1816 Get_Next_Interp (I, It);
1817 end loop;
1818
6e73e3ab 1819 -- Error if no interpretation of the prefix has an access type
996ae0b0
RK
1820
1821 if Etype (N) = Any_Type then
1822 Error_Msg_N
1823 ("access type required in prefix of explicit dereference", P);
1824 Set_Etype (N, Any_Type);
1825 return;
1826 end if;
1827 end if;
1828
1829 if Is_Function_Type
1830 and then Nkind (Parent (N)) /= N_Indexed_Component
1831
1832 and then (Nkind (Parent (N)) /= N_Function_Call
1833 or else N /= Name (Parent (N)))
1834
1835 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1836 or else N /= Name (Parent (N)))
1837
1838 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1839 and then (Nkind (Parent (N)) /= N_Attribute_Reference
1840 or else
1841 (Attribute_Name (Parent (N)) /= Name_Address
1842 and then
1843 Attribute_Name (Parent (N)) /= Name_Access))
1844 then
1845 -- Name is a function call with no actuals, in a context that
1846 -- requires deproceduring (including as an actual in an enclosing
98123480 1847 -- function or procedure call). There are some pathological cases
996ae0b0
RK
1848 -- where the prefix might include functions that return access to
1849 -- subprograms and others that return a regular type. Disambiguation
98123480 1850 -- of those has to take place in Resolve.
996ae0b0
RK
1851
1852 New_N :=
1853 Make_Function_Call (Loc,
1854 Name => Make_Explicit_Dereference (Loc, P),
1855 Parameter_Associations => New_List);
1856
1857 -- If the prefix is overloaded, remove operations that have formals,
1858 -- we know that this is a parameterless call.
1859
1860 if Is_Overloaded (P) then
1861 Get_First_Interp (P, I, It);
996ae0b0
RK
1862 while Present (It.Nam) loop
1863 T := It.Typ;
1864
1865 if No (First_Formal (Base_Type (Designated_Type (T)))) then
1866 Set_Etype (P, T);
1867 else
1868 Remove_Interp (I);
1869 end if;
1870
1871 Get_Next_Interp (I, It);
1872 end loop;
1873 end if;
1874
1875 Rewrite (N, New_N);
1876 Analyze (N);
98123480
ES
1877
1878 elsif not Is_Function_Type
1879 and then Is_Overloaded (N)
1880 then
1881 -- The prefix may include access to subprograms and other access
1cb17b78 1882 -- types. If the context selects the interpretation that is a
56a7a3ab
TQ
1883 -- function call (not a procedure call) we cannot rewrite the node
1884 -- yet, but we include the result of the call interpretation.
98123480
ES
1885
1886 Get_First_Interp (N, I, It);
1887 while Present (It.Nam) loop
1888 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
1889 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
1cb17b78 1890 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
98123480
ES
1891 then
1892 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
1893 end if;
1894
1895 Get_Next_Interp (I, It);
1896 end loop;
996ae0b0
RK
1897 end if;
1898
1899 -- A value of remote access-to-class-wide must not be dereferenced
1900 -- (RM E.2.2(16)).
1901
1902 Validate_Remote_Access_To_Class_Wide_Type (N);
996ae0b0
RK
1903 end Analyze_Explicit_Dereference;
1904
1905 ------------------------
1906 -- Analyze_Expression --
1907 ------------------------
1908
1909 procedure Analyze_Expression (N : Node_Id) is
1910 begin
1911 Analyze (N);
1912 Check_Parameterless_Call (N);
1913 end Analyze_Expression;
1914
955871d3
AC
1915 -------------------------------------
1916 -- Analyze_Expression_With_Actions --
1917 -------------------------------------
1918
1919 procedure Analyze_Expression_With_Actions (N : Node_Id) is
1920 A : Node_Id;
1921
1922 begin
1923 A := First (Actions (N));
1924 loop
1925 Analyze (A);
1926 Next (A);
1927 exit when No (A);
1928 end loop;
1929
1930 Analyze_Expression (Expression (N));
1931 Set_Etype (N, Etype (Expression (N)));
1932 end Analyze_Expression_With_Actions;
1933
996ae0b0
RK
1934 ------------------------------------
1935 -- Analyze_Indexed_Component_Form --
1936 ------------------------------------
1937
1938 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
fbf5a39b
AC
1939 P : constant Node_Id := Prefix (N);
1940 Exprs : constant List_Id := Expressions (N);
1941 Exp : Node_Id;
1942 P_T : Entity_Id;
1943 E : Node_Id;
1944 U_N : Entity_Id;
996ae0b0
RK
1945
1946 procedure Process_Function_Call;
1947 -- Prefix in indexed component form is an overloadable entity,
1948 -- so the node is a function call. Reformat it as such.
1949
1950 procedure Process_Indexed_Component;
1951 -- Prefix in indexed component form is actually an indexed component.
1952 -- This routine processes it, knowing that the prefix is already
1953 -- resolved.
1954
1955 procedure Process_Indexed_Component_Or_Slice;
1956 -- An indexed component with a single index may designate a slice if
1957 -- the index is a subtype mark. This routine disambiguates these two
1958 -- cases by resolving the prefix to see if it is a subtype mark.
1959
1960 procedure Process_Overloaded_Indexed_Component;
1961 -- If the prefix of an indexed component is overloaded, the proper
1962 -- interpretation is selected by the index types and the context.
1963
1964 ---------------------------
1965 -- Process_Function_Call --
1966 ---------------------------
1967
1968 procedure Process_Function_Call is
f5afb270
AC
1969 Actual : Node_Id;
1970
996ae0b0
RK
1971 begin
1972 Change_Node (N, N_Function_Call);
1973 Set_Name (N, P);
1974 Set_Parameter_Associations (N, Exprs);
996ae0b0 1975
401093c1 1976 -- Analyze actuals prior to analyzing the call itself
0a36105d 1977
4c46b835 1978 Actual := First (Parameter_Associations (N));
996ae0b0
RK
1979 while Present (Actual) loop
1980 Analyze (Actual);
1981 Check_Parameterless_Call (Actual);
0a36105d
JM
1982
1983 -- Move to next actual. Note that we use Next, not Next_Actual
1984 -- here. The reason for this is a bit subtle. If a function call
1985 -- includes named associations, the parser recognizes the node as
1986 -- a call, and it is analyzed as such. If all associations are
1987 -- positional, the parser builds an indexed_component node, and
1988 -- it is only after analysis of the prefix that the construct
1989 -- is recognized as a call, in which case Process_Function_Call
1990 -- rewrites the node and analyzes the actuals. If the list of
1991 -- actuals is malformed, the parser may leave the node as an
1992 -- indexed component (despite the presence of named associations).
1993 -- The iterator Next_Actual is equivalent to Next if the list is
1994 -- positional, but follows the normalized chain of actuals when
1995 -- named associations are present. In this case normalization has
1996 -- not taken place, and actuals remain unanalyzed, which leads to
1997 -- subsequent crashes or loops if there is an attempt to continue
1998 -- analysis of the program.
1999
2000 Next (Actual);
996ae0b0
RK
2001 end loop;
2002
2003 Analyze_Call (N);
2004 end Process_Function_Call;
2005
2006 -------------------------------
2007 -- Process_Indexed_Component --
2008 -------------------------------
2009
2010 procedure Process_Indexed_Component is
fe39cf20
BD
2011 Exp : Node_Id;
2012 Array_Type : Entity_Id;
2013 Index : Node_Id;
2014 Pent : Entity_Id := Empty;
996ae0b0
RK
2015
2016 begin
2017 Exp := First (Exprs);
2018
2019 if Is_Overloaded (P) then
2020 Process_Overloaded_Indexed_Component;
2021
2022 else
2023 Array_Type := Etype (P);
2024
6e73e3ab
AC
2025 if Is_Entity_Name (P) then
2026 Pent := Entity (P);
2027 elsif Nkind (P) = N_Selected_Component
2028 and then Is_Entity_Name (Selector_Name (P))
2029 then
2030 Pent := Entity (Selector_Name (P));
2031 end if;
2032
2033 -- Prefix must be appropriate for an array type, taking into
2034 -- account a possible implicit dereference.
996ae0b0
RK
2035
2036 if Is_Access_Type (Array_Type) then
fbf5a39b 2037 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
d469eabe 2038 Array_Type := Process_Implicit_Dereference_Prefix (Pent, P);
996ae0b0
RK
2039 end if;
2040
2041 if Is_Array_Type (Array_Type) then
2042 null;
2043
6e73e3ab 2044 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
996ae0b0
RK
2045 Analyze (Exp);
2046 Set_Etype (N, Any_Type);
2047
2048 if not Has_Compatible_Type
6e73e3ab 2049 (Exp, Entry_Index_Type (Pent))
996ae0b0
RK
2050 then
2051 Error_Msg_N ("invalid index type in entry name", N);
2052
2053 elsif Present (Next (Exp)) then
2054 Error_Msg_N ("too many subscripts in entry reference", N);
2055
2056 else
2057 Set_Etype (N, Etype (P));
2058 end if;
2059
2060 return;
2061
2062 elsif Is_Record_Type (Array_Type)
2063 and then Remote_AST_I_Dereference (P)
2064 then
2065 return;
2066
d50f4827
AC
2067 elsif Try_Container_Indexing (N, P, Exp) then
2068 return;
2069
996ae0b0
RK
2070 elsif Array_Type = Any_Type then
2071 Set_Etype (N, Any_Type);
6465b6a7
AC
2072
2073 -- In most cases the analysis of the prefix will have emitted
2074 -- an error already, but if the prefix may be interpreted as a
2075 -- call in prefixed notation, the report is left to the caller.
2076 -- To prevent cascaded errors, report only if no previous ones.
2077
2078 if Serious_Errors_Detected = 0 then
2079 Error_Msg_N ("invalid prefix in indexed component", P);
2080
2081 if Nkind (P) = N_Expanded_Name then
2082 Error_Msg_NE ("\& is not visible", P, Selector_Name (P));
2083 end if;
2084 end if;
2085
996ae0b0
RK
2086 return;
2087
2088 -- Here we definitely have a bad indexing
2089
2090 else
2091 if Nkind (Parent (N)) = N_Requeue_Statement
6e73e3ab 2092 and then Present (Pent) and then Ekind (Pent) = E_Entry
996ae0b0
RK
2093 then
2094 Error_Msg_N
2095 ("REQUEUE does not permit parameters", First (Exprs));
2096
2097 elsif Is_Entity_Name (P)
2098 and then Etype (P) = Standard_Void_Type
2099 then
2100 Error_Msg_NE ("incorrect use of&", P, Entity (P));
2101
2102 else
2103 Error_Msg_N ("array type required in indexed component", P);
2104 end if;
2105
2106 Set_Etype (N, Any_Type);
2107 return;
2108 end if;
2109
2110 Index := First_Index (Array_Type);
996ae0b0
RK
2111 while Present (Index) and then Present (Exp) loop
2112 if not Has_Compatible_Type (Exp, Etype (Index)) then
2113 Wrong_Type (Exp, Etype (Index));
2114 Set_Etype (N, Any_Type);
2115 return;
2116 end if;
2117
2118 Next_Index (Index);
2119 Next (Exp);
2120 end loop;
2121
2122 Set_Etype (N, Component_Type (Array_Type));
44a10091 2123 Check_Implicit_Dereference (N, Etype (N));
996ae0b0
RK
2124
2125 if Present (Index) then
2126 Error_Msg_N
2127 ("too few subscripts in array reference", First (Exprs));
2128
2129 elsif Present (Exp) then
2130 Error_Msg_N ("too many subscripts in array reference", Exp);
2131 end if;
2132 end if;
996ae0b0
RK
2133 end Process_Indexed_Component;
2134
2135 ----------------------------------------
2136 -- Process_Indexed_Component_Or_Slice --
2137 ----------------------------------------
2138
2139 procedure Process_Indexed_Component_Or_Slice is
2140 begin
2141 Exp := First (Exprs);
996ae0b0
RK
2142 while Present (Exp) loop
2143 Analyze_Expression (Exp);
2144 Next (Exp);
2145 end loop;
2146
2147 Exp := First (Exprs);
2148
2149 -- If one index is present, and it is a subtype name, then the
2150 -- node denotes a slice (note that the case of an explicit range
2151 -- for a slice was already built as an N_Slice node in the first
2152 -- place, so that case is not handled here).
2153
2154 -- We use a replace rather than a rewrite here because this is one
2155 -- of the cases in which the tree built by the parser is plain wrong.
2156
2157 if No (Next (Exp))
2158 and then Is_Entity_Name (Exp)
2159 and then Is_Type (Entity (Exp))
2160 then
2161 Replace (N,
2162 Make_Slice (Sloc (N),
2163 Prefix => P,
2164 Discrete_Range => New_Copy (Exp)));
2165 Analyze (N);
2166
2167 -- Otherwise (more than one index present, or single index is not
2168 -- a subtype name), then we have the indexed component case.
2169
2170 else
2171 Process_Indexed_Component;
2172 end if;
2173 end Process_Indexed_Component_Or_Slice;
2174
2175 ------------------------------------------
2176 -- Process_Overloaded_Indexed_Component --
2177 ------------------------------------------
2178
2179 procedure Process_Overloaded_Indexed_Component is
2180 Exp : Node_Id;
2181 I : Interp_Index;
2182 It : Interp;
2183 Typ : Entity_Id;
2184 Index : Node_Id;
2185 Found : Boolean;
2186
2187 begin
2188 Set_Etype (N, Any_Type);
996ae0b0 2189
4c46b835 2190 Get_First_Interp (P, I, It);
996ae0b0
RK
2191 while Present (It.Nam) loop
2192 Typ := It.Typ;
2193
2194 if Is_Access_Type (Typ) then
2195 Typ := Designated_Type (Typ);
fbf5a39b 2196 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
996ae0b0
RK
2197 end if;
2198
2199 if Is_Array_Type (Typ) then
2200
2201 -- Got a candidate: verify that index types are compatible
2202
2203 Index := First_Index (Typ);
2204 Found := True;
996ae0b0 2205 Exp := First (Exprs);
996ae0b0
RK
2206 while Present (Index) and then Present (Exp) loop
2207 if Has_Compatible_Type (Exp, Etype (Index)) then
2208 null;
2209 else
2210 Found := False;
2211 Remove_Interp (I);
2212 exit;
2213 end if;
2214
2215 Next_Index (Index);
2216 Next (Exp);
2217 end loop;
2218
2219 if Found and then No (Index) and then No (Exp) then
44a10091
AC
2220 declare
2221 CT : constant Entity_Id :=
2222 Base_Type (Component_Type (Typ));
2223 begin
2224 Add_One_Interp (N, CT, CT);
2225 Check_Implicit_Dereference (N, CT);
2226 end;
996ae0b0
RK
2227 end if;
2228 end if;
2229
2230 Get_Next_Interp (I, It);
2231 end loop;
2232
2233 if Etype (N) = Any_Type then
ad6b5b00 2234 Error_Msg_N ("no legal interpretation for indexed component", N);
996ae0b0
RK
2235 Set_Is_Overloaded (N, False);
2236 end if;
2237
2238 End_Interp_List;
2239 end Process_Overloaded_Indexed_Component;
2240
4c46b835 2241 -- Start of processing for Analyze_Indexed_Component_Form
996ae0b0
RK
2242
2243 begin
2244 -- Get name of array, function or type
2245
2246 Analyze (P);
d469eabe
HK
2247
2248 if Nkind_In (N, N_Function_Call, N_Procedure_Call_Statement) then
2249
fbf5a39b
AC
2250 -- If P is an explicit dereference whose prefix is of a
2251 -- remote access-to-subprogram type, then N has already
2252 -- been rewritten as a subprogram call and analyzed.
2253
2254 return;
2255 end if;
2256
2257 pragma Assert (Nkind (N) = N_Indexed_Component);
2258
996ae0b0
RK
2259 P_T := Base_Type (Etype (P));
2260
878f708a 2261 if Is_Entity_Name (P) and then Present (Entity (P)) then
996ae0b0
RK
2262 U_N := Entity (P);
2263
aab883ec 2264 if Is_Type (U_N) then
996ae0b0 2265
4c46b835 2266 -- Reformat node as a type conversion
996ae0b0
RK
2267
2268 E := Remove_Head (Exprs);
2269
2270 if Present (First (Exprs)) then
2271 Error_Msg_N
2272 ("argument of type conversion must be single expression", N);
2273 end if;
2274
2275 Change_Node (N, N_Type_Conversion);
2276 Set_Subtype_Mark (N, P);
2277 Set_Etype (N, U_N);
2278 Set_Expression (N, E);
2279
2280 -- After changing the node, call for the specific Analysis
2281 -- routine directly, to avoid a double call to the expander.
2282
2283 Analyze_Type_Conversion (N);
2284 return;
2285 end if;
2286
2287 if Is_Overloadable (U_N) then
2288 Process_Function_Call;
2289
2290 elsif Ekind (Etype (P)) = E_Subprogram_Type
2291 or else (Is_Access_Type (Etype (P))
2292 and then
bce79204
AC
2293 Ekind (Designated_Type (Etype (P))) =
2294 E_Subprogram_Type)
996ae0b0
RK
2295 then
2296 -- Call to access_to-subprogram with possible implicit dereference
2297
2298 Process_Function_Call;
2299
fbf5a39b
AC
2300 elsif Is_Generic_Subprogram (U_N) then
2301
4c46b835 2302 -- A common beginner's (or C++ templates fan) error
996ae0b0
RK
2303
2304 Error_Msg_N ("generic subprogram cannot be called", N);
2305 Set_Etype (N, Any_Type);
2306 return;
2307
2308 else
2309 Process_Indexed_Component_Or_Slice;
2310 end if;
2311
2312 -- If not an entity name, prefix is an expression that may denote
2313 -- an array or an access-to-subprogram.
2314
2315 else
fbf5a39b 2316 if Ekind (P_T) = E_Subprogram_Type
996ae0b0
RK
2317 or else (Is_Access_Type (P_T)
2318 and then
bce79204 2319 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
996ae0b0
RK
2320 then
2321 Process_Function_Call;
2322
2323 elsif Nkind (P) = N_Selected_Component
ffe9aba8 2324 and then Is_Overloadable (Entity (Selector_Name (P)))
996ae0b0
RK
2325 then
2326 Process_Function_Call;
2327
2328 else
2329 -- Indexed component, slice, or a call to a member of a family
2330 -- entry, which will be converted to an entry call later.
fbf5a39b 2331
996ae0b0
RK
2332 Process_Indexed_Component_Or_Slice;
2333 end if;
2334 end if;
2335 end Analyze_Indexed_Component_Form;
2336
2337 ------------------------
2338 -- Analyze_Logical_Op --
2339 ------------------------
2340
2341 procedure Analyze_Logical_Op (N : Node_Id) is
2342 L : constant Node_Id := Left_Opnd (N);
2343 R : constant Node_Id := Right_Opnd (N);
2344 Op_Id : Entity_Id := Entity (N);
2345
2346 begin
2347 Set_Etype (N, Any_Type);
2348 Candidate_Type := Empty;
2349
2350 Analyze_Expression (L);
2351 Analyze_Expression (R);
2352
2353 if Present (Op_Id) then
2354
2355 if Ekind (Op_Id) = E_Operator then
2356 Find_Boolean_Types (L, R, Op_Id, N);
2357 else
2358 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2359 end if;
2360
2361 else
2362 Op_Id := Get_Name_Entity_Id (Chars (N));
996ae0b0
RK
2363 while Present (Op_Id) loop
2364 if Ekind (Op_Id) = E_Operator then
2365 Find_Boolean_Types (L, R, Op_Id, N);
2366 else
2367 Analyze_User_Defined_Binary_Op (N, Op_Id);
2368 end if;
2369
2370 Op_Id := Homonym (Op_Id);
2371 end loop;
2372 end if;
2373
2374 Operator_Check (N);
2375 end Analyze_Logical_Op;
2376
2377 ---------------------------
2378 -- Analyze_Membership_Op --
2379 ---------------------------
2380
2381 procedure Analyze_Membership_Op (N : Node_Id) is
66150d01 2382 Loc : constant Source_Ptr := Sloc (N);
f2acf80c
AC
2383 L : constant Node_Id := Left_Opnd (N);
2384 R : constant Node_Id := Right_Opnd (N);
996ae0b0
RK
2385
2386 Index : Interp_Index;
2387 It : Interp;
2388 Found : Boolean := False;
2389 I_F : Interp_Index;
2390 T_F : Entity_Id;
2391
2392 procedure Try_One_Interp (T1 : Entity_Id);
2393 -- Routine to try one proposed interpretation. Note that the context
2394 -- of the operation plays no role in resolving the arguments, so that
2395 -- if there is more than one interpretation of the operands that is
2396 -- compatible with a membership test, the operation is ambiguous.
2397
4c46b835
AC
2398 --------------------
2399 -- Try_One_Interp --
2400 --------------------
2401
996ae0b0
RK
2402 procedure Try_One_Interp (T1 : Entity_Id) is
2403 begin
2404 if Has_Compatible_Type (R, T1) then
2405 if Found
2406 and then Base_Type (T1) /= Base_Type (T_F)
2407 then
2408 It := Disambiguate (L, I_F, Index, Any_Type);
2409
2410 if It = No_Interp then
2411 Ambiguous_Operands (N);
2412 Set_Etype (L, Any_Type);
2413 return;
2414
2415 else
2416 T_F := It.Typ;
2417 end if;
2418
2419 else
2420 Found := True;
2421 T_F := T1;
2422 I_F := Index;
2423 end if;
2424
2425 Set_Etype (L, T_F);
2426 end if;
996ae0b0
RK
2427 end Try_One_Interp;
2428
197e4514
AC
2429 procedure Analyze_Set_Membership;
2430 -- If a set of alternatives is present, analyze each and find the
2431 -- common type to which they must all resolve.
2432
2433 ----------------------------
2434 -- Analyze_Set_Membership --
2435 ----------------------------
2436
2437 procedure Analyze_Set_Membership is
2438 Alt : Node_Id;
2439 Index : Interp_Index;
2440 It : Interp;
197e4514
AC
2441 Candidate_Interps : Node_Id;
2442 Common_Type : Entity_Id := Empty;
2443
2444 begin
2445 Analyze (L);
2446 Candidate_Interps := L;
2447
2448 if not Is_Overloaded (L) then
2449 Common_Type := Etype (L);
2450
2451 Alt := First (Alternatives (N));
2452 while Present (Alt) loop
2453 Analyze (Alt);
2454
2455 if not Has_Compatible_Type (Alt, Common_Type) then
2456 Wrong_Type (Alt, Common_Type);
2457 end if;
2458
2459 Next (Alt);
2460 end loop;
2461
2462 else
2463 Alt := First (Alternatives (N));
2464 while Present (Alt) loop
2465 Analyze (Alt);
2466 if not Is_Overloaded (Alt) then
2467 Common_Type := Etype (Alt);
2468
2469 else
2470 Get_First_Interp (Alt, Index, It);
2471 while Present (It.Typ) loop
442c0581
RD
2472 if not
2473 Has_Compatible_Type (Candidate_Interps, It.Typ)
197e4514
AC
2474 then
2475 Remove_Interp (Index);
2476 end if;
442c0581 2477
197e4514
AC
2478 Get_Next_Interp (Index, It);
2479 end loop;
2480
2481 Get_First_Interp (Alt, Index, It);
442c0581 2482
197e4514
AC
2483 if No (It.Typ) then
2484 Error_Msg_N ("alternative has no legal type", Alt);
2485 return;
2486 end if;
2487
442c0581
RD
2488 -- If alternative is not overloaded, we have a unique type
2489 -- for all of them.
197e4514
AC
2490
2491 Set_Etype (Alt, It.Typ);
2492 Get_Next_Interp (Index, It);
2493
2494 if No (It.Typ) then
2495 Set_Is_Overloaded (Alt, False);
2496 Common_Type := Etype (Alt);
2497 end if;
2498
2499 Candidate_Interps := Alt;
2500 end if;
2501
2502 Next (Alt);
2503 end loop;
2504 end if;
2505
2506 Set_Etype (N, Standard_Boolean);
2507
2508 if Present (Common_Type) then
2509 Set_Etype (L, Common_Type);
2510 Set_Is_Overloaded (L, False);
2511
2512 else
2513 Error_Msg_N ("cannot resolve membership operation", N);
2514 end if;
2515 end Analyze_Set_Membership;
2516
996ae0b0
RK
2517 -- Start of processing for Analyze_Membership_Op
2518
2519 begin
2520 Analyze_Expression (L);
2521
197e4514 2522 if No (R)
dbe945f1 2523 and then Ada_Version >= Ada_2012
197e4514
AC
2524 then
2525 Analyze_Set_Membership;
2526 return;
2527 end if;
2528
996ae0b0
RK
2529 if Nkind (R) = N_Range
2530 or else (Nkind (R) = N_Attribute_Reference
2531 and then Attribute_Name (R) = Name_Range)
2532 then
2533 Analyze (R);
2534
2535 if not Is_Overloaded (L) then
2536 Try_One_Interp (Etype (L));
2537
2538 else
2539 Get_First_Interp (L, Index, It);
996ae0b0
RK
2540 while Present (It.Typ) loop
2541 Try_One_Interp (It.Typ);
2542 Get_Next_Interp (Index, It);
2543 end loop;
2544 end if;
2545
f6b5dc8e 2546 -- If not a range, it can be a subtype mark, or else it is a degenerate
b0186f71
AC
2547 -- membership test with a singleton value, i.e. a test for equality,
2548 -- if the types are compatible.
996ae0b0
RK
2549
2550 else
66150d01 2551 Analyze (R);
7483c888 2552
66150d01
AC
2553 if Is_Entity_Name (R)
2554 and then Is_Type (Entity (R))
2555 then
2556 Find_Type (R);
996ae0b0 2557 Check_Fully_Declared (Entity (R), R);
66150d01 2558
b0186f71
AC
2559 elsif Ada_Version >= Ada_2012
2560 and then Has_Compatible_Type (R, Etype (L))
2561 then
66150d01
AC
2562 if Nkind (N) = N_In then
2563 Rewrite (N,
2564 Make_Op_Eq (Loc,
2565 Left_Opnd => L,
2566 Right_Opnd => R));
2567 else
2568 Rewrite (N,
2569 Make_Op_Ne (Loc,
2570 Left_Opnd => L,
2571 Right_Opnd => R));
2572 end if;
2573
2574 Analyze (N);
2575 return;
2576
2577 else
b0186f71
AC
2578 -- In all versions of the language, if we reach this point there
2579 -- is a previous error that will be diagnosed below.
66150d01
AC
2580
2581 Find_Type (R);
996ae0b0
RK
2582 end if;
2583 end if;
2584
2585 -- Compatibility between expression and subtype mark or range is
2586 -- checked during resolution. The result of the operation is Boolean
2587 -- in any case.
2588
2589 Set_Etype (N, Standard_Boolean);
fe45e59e
ES
2590
2591 if Comes_From_Source (N)
197e4514 2592 and then Present (Right_Opnd (N))
fe45e59e
ES
2593 and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
2594 then
2595 Error_Msg_N ("membership test not applicable to cpp-class types", N);
2596 end if;
996ae0b0
RK
2597 end Analyze_Membership_Op;
2598
2599 ----------------------
2600 -- Analyze_Negation --
2601 ----------------------
2602
2603 procedure Analyze_Negation (N : Node_Id) is
2604 R : constant Node_Id := Right_Opnd (N);
2605 Op_Id : Entity_Id := Entity (N);
2606
2607 begin
2608 Set_Etype (N, Any_Type);
2609 Candidate_Type := Empty;
2610
2611 Analyze_Expression (R);
2612
2613 if Present (Op_Id) then
2614 if Ekind (Op_Id) = E_Operator then
2615 Find_Negation_Types (R, Op_Id, N);
2616 else
2617 Add_One_Interp (N, Op_Id, Etype (Op_Id));
2618 end if;
2619
2620 else
2621 Op_Id := Get_Name_Entity_Id (Chars (N));
996ae0b0
RK
2622 while Present (Op_Id) loop
2623 if Ekind (Op_Id) = E_Operator then
2624 Find_Negation_Types (R, Op_Id, N);
2625 else
2626 Analyze_User_Defined_Unary_Op (N, Op_Id);
2627 end if;
2628
2629 Op_Id := Homonym (Op_Id);
2630 end loop;
2631 end if;
2632
2633 Operator_Check (N);
2634 end Analyze_Negation;
2635
15ce9ca2
AC
2636 ------------------
2637 -- Analyze_Null --
2638 ------------------
996ae0b0
RK
2639
2640 procedure Analyze_Null (N : Node_Id) is
2641 begin
2ba431e5 2642 Check_SPARK_Restriction ("null is not allowed", N);
1d801f21 2643
996ae0b0
RK
2644 Set_Etype (N, Any_Access);
2645 end Analyze_Null;
2646
2647 ----------------------
2648 -- Analyze_One_Call --
2649 ----------------------
2650
2651 procedure Analyze_One_Call
ec6078e3
ES
2652 (N : Node_Id;
2653 Nam : Entity_Id;
2654 Report : Boolean;
2655 Success : out Boolean;
2656 Skip_First : Boolean := False)
996ae0b0 2657 is
d469eabe
HK
2658 Actuals : constant List_Id := Parameter_Associations (N);
2659 Prev_T : constant Entity_Id := Etype (N);
2660
aab883ec
ES
2661 Must_Skip : constant Boolean := Skip_First
2662 or else Nkind (Original_Node (N)) = N_Selected_Component
2663 or else
2664 (Nkind (Original_Node (N)) = N_Indexed_Component
2665 and then Nkind (Prefix (Original_Node (N)))
2666 = N_Selected_Component);
2667 -- The first formal must be omitted from the match when trying to find
2668 -- a primitive operation that is a possible interpretation, and also
2669 -- after the call has been rewritten, because the corresponding actual
2670 -- is already known to be compatible, and because this may be an
2671 -- indexing of a call with default parameters.
2672
53cf4600
ES
2673 Formal : Entity_Id;
2674 Actual : Node_Id;
2675 Is_Indexed : Boolean := False;
2676 Is_Indirect : Boolean := False;
2677 Subp_Type : constant Entity_Id := Etype (Nam);
2678 Norm_OK : Boolean;
996ae0b0 2679
157a9bf5
ES
2680 function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
2681 -- There may be a user-defined operator that hides the current
2682 -- interpretation. We must check for this independently of the
2683 -- analysis of the call with the user-defined operation, because
2684 -- the parameter names may be wrong and yet the hiding takes place.
2685 -- This fixes a problem with ACATS test B34014O.
2686 --
2687 -- When the type Address is a visible integer type, and the DEC
2688 -- system extension is visible, the predefined operator may be
2689 -- hidden as well, by one of the address operations in auxdec.
2690 -- Finally, The abstract operations on address do not hide the
2691 -- predefined operator (this is the purpose of making them abstract).
2692
fbf5a39b 2693 procedure Indicate_Name_And_Type;
996ae0b0
RK
2694 -- If candidate interpretation matches, indicate name and type of
2695 -- result on call node.
2696
fbf5a39b
AC
2697 ----------------------------
2698 -- Indicate_Name_And_Type --
2699 ----------------------------
996ae0b0 2700
fbf5a39b 2701 procedure Indicate_Name_And_Type is
996ae0b0
RK
2702 begin
2703 Add_One_Interp (N, Nam, Etype (Nam));
44a10091 2704 Check_Implicit_Dereference (N, Etype (Nam));
996ae0b0
RK
2705 Success := True;
2706
2707 -- If the prefix of the call is a name, indicate the entity
2708 -- being called. If it is not a name, it is an expression that
2709 -- denotes an access to subprogram or else an entry or family. In
2710 -- the latter case, the name is a selected component, and the entity
2711 -- being called is noted on the selector.
2712
2713 if not Is_Type (Nam) then
a3f2babd 2714 if Is_Entity_Name (Name (N)) then
996ae0b0
RK
2715 Set_Entity (Name (N), Nam);
2716
2717 elsif Nkind (Name (N)) = N_Selected_Component then
2718 Set_Entity (Selector_Name (Name (N)), Nam);
2719 end if;
2720 end if;
2721
2722 if Debug_Flag_E and not Report then
2723 Write_Str (" Overloaded call ");
2724 Write_Int (Int (N));
2725 Write_Str (" compatible with ");
2726 Write_Int (Int (Nam));
2727 Write_Eol;
2728 end if;
fbf5a39b 2729 end Indicate_Name_And_Type;
996ae0b0 2730
157a9bf5
ES
2731 ------------------------
2732 -- Operator_Hidden_By --
2733 ------------------------
2734
2735 function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
2736 Act1 : constant Node_Id := First_Actual (N);
2737 Act2 : constant Node_Id := Next_Actual (Act1);
2738 Form1 : constant Entity_Id := First_Formal (Fun);
2739 Form2 : constant Entity_Id := Next_Formal (Form1);
2740
2741 begin
2742 if Ekind (Fun) /= E_Function
2743 or else Is_Abstract_Subprogram (Fun)
2744 then
2745 return False;
2746
2747 elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
2748 return False;
2749
2750 elsif Present (Form2) then
2751 if
2752 No (Act2) or else not Has_Compatible_Type (Act2, Etype (Form2))
2753 then
2754 return False;
2755 end if;
2756
2757 elsif Present (Act2) then
2758 return False;
2759 end if;
2760
2761 -- Now we know that the arity of the operator matches the function,
2762 -- and the function call is a valid interpretation. The function
2763 -- hides the operator if it has the right signature, or if one of
2764 -- its operands is a non-abstract operation on Address when this is
2765 -- a visible integer type.
2766
2767 return Hides_Op (Fun, Nam)
2768 or else Is_Descendent_Of_Address (Etype (Form1))
2769 or else
2770 (Present (Form2)
2771 and then Is_Descendent_Of_Address (Etype (Form2)));
2772 end Operator_Hidden_By;
2773
996ae0b0
RK
2774 -- Start of processing for Analyze_One_Call
2775
2776 begin
2777 Success := False;
2778
157a9bf5
ES
2779 -- If the subprogram has no formals or if all the formals have defaults,
2780 -- and the return type is an array type, the node may denote an indexing
2781 -- of the result of a parameterless call. In Ada 2005, the subprogram
2782 -- may have one non-defaulted formal, and the call may have been written
2783 -- in prefix notation, so that the rebuilt parameter list has more than
2784 -- one actual.
996ae0b0 2785
53cf4600
ES
2786 if not Is_Overloadable (Nam)
2787 and then Ekind (Nam) /= E_Subprogram_Type
2788 and then Ekind (Nam) /= E_Entry_Family
2789 then
2790 return;
2791 end if;
2792
8f2eeab7 2793 -- An indexing requires at least one actual
e1f3cb58
AC
2794
2795 if not Is_Empty_List (Actuals)
aab883ec
ES
2796 and then
2797 (Needs_No_Actuals (Nam)
2798 or else
2799 (Needs_One_Actual (Nam)
2800 and then Present (Next_Actual (First (Actuals)))))
996ae0b0
RK
2801 then
2802 if Is_Array_Type (Subp_Type) then
aab883ec 2803 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
996ae0b0
RK
2804
2805 elsif Is_Access_Type (Subp_Type)
2806 and then Is_Array_Type (Designated_Type (Subp_Type))
2807 then
2808 Is_Indexed :=
aab883ec
ES
2809 Try_Indexed_Call
2810 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
996ae0b0 2811
758c442c 2812 -- The prefix can also be a parameterless function that returns an
f3d57416 2813 -- access to subprogram, in which case this is an indirect call.
53cf4600
ES
2814 -- If this succeeds, an explicit dereference is added later on,
2815 -- in Analyze_Call or Resolve_Call.
758c442c 2816
996ae0b0 2817 elsif Is_Access_Type (Subp_Type)
401093c1 2818 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
996ae0b0 2819 then
53cf4600 2820 Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
996ae0b0
RK
2821 end if;
2822
2823 end if;
2824
5ff22245 2825 -- If the call has been transformed into a slice, it is of the form
30783513 2826 -- F (Subtype) where F is parameterless. The node has been rewritten in
5ff22245
ES
2827 -- Try_Indexed_Call and there is nothing else to do.
2828
2829 if Is_Indexed
2830 and then Nkind (N) = N_Slice
2831 then
2832 return;
2833 end if;
2834
53cf4600
ES
2835 Normalize_Actuals
2836 (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
996ae0b0
RK
2837
2838 if not Norm_OK then
2839
53cf4600
ES
2840 -- If an indirect call is a possible interpretation, indicate
2841 -- success to the caller.
2842
2843 if Is_Indirect then
2844 Success := True;
2845 return;
2846
996ae0b0
RK
2847 -- Mismatch in number or names of parameters
2848
53cf4600 2849 elsif Debug_Flag_E then
996ae0b0
RK
2850 Write_Str (" normalization fails in call ");
2851 Write_Int (Int (N));
2852 Write_Str (" with subprogram ");
2853 Write_Int (Int (Nam));
2854 Write_Eol;
2855 end if;
2856
2857 -- If the context expects a function call, discard any interpretation
2858 -- that is a procedure. If the node is not overloaded, leave as is for
2859 -- better error reporting when type mismatch is found.
2860
2861 elsif Nkind (N) = N_Function_Call
2862 and then Is_Overloaded (Name (N))
2863 and then Ekind (Nam) = E_Procedure
2864 then
2865 return;
2866
4c46b835 2867 -- Ditto for function calls in a procedure context
996ae0b0
RK
2868
2869 elsif Nkind (N) = N_Procedure_Call_Statement
2870 and then Is_Overloaded (Name (N))
2871 and then Etype (Nam) /= Standard_Void_Type
2872 then
2873 return;
2874
fe45e59e 2875 elsif No (Actuals) then
996ae0b0
RK
2876
2877 -- If Normalize succeeds, then there are default parameters for
2878 -- all formals.
2879
fbf5a39b 2880 Indicate_Name_And_Type;
996ae0b0
RK
2881
2882 elsif Ekind (Nam) = E_Operator then
996ae0b0
RK
2883 if Nkind (N) = N_Procedure_Call_Statement then
2884 return;
2885 end if;
2886
2887 -- This can occur when the prefix of the call is an operator
2888 -- name or an expanded name whose selector is an operator name.
2889
2890 Analyze_Operator_Call (N, Nam);
2891
2892 if Etype (N) /= Prev_T then
2893
157a9bf5 2894 -- Check that operator is not hidden by a function interpretation
996ae0b0
RK
2895
2896 if Is_Overloaded (Name (N)) then
2897 declare
2898 I : Interp_Index;
2899 It : Interp;
2900
2901 begin
2902 Get_First_Interp (Name (N), I, It);
996ae0b0 2903 while Present (It.Nam) loop
157a9bf5 2904 if Operator_Hidden_By (It.Nam) then
996ae0b0
RK
2905 Set_Etype (N, Prev_T);
2906 return;
2907 end if;
2908
2909 Get_Next_Interp (I, It);
2910 end loop;
2911 end;
2912 end if;
2913
2914 -- If operator matches formals, record its name on the call.
2915 -- If the operator is overloaded, Resolve will select the
2916 -- correct one from the list of interpretations. The call
2917 -- node itself carries the first candidate.
2918
2919 Set_Entity (Name (N), Nam);
2920 Success := True;
2921
2922 elsif Report and then Etype (N) = Any_Type then
2923 Error_Msg_N ("incompatible arguments for operator", N);
2924 end if;
2925
2926 else
2927 -- Normalize_Actuals has chained the named associations in the
2928 -- correct order of the formals.
2929
2930 Actual := First_Actual (N);
2931 Formal := First_Formal (Nam);
ec6078e3 2932
df3e68b1
HK
2933 -- If we are analyzing a call rewritten from object notation, skip
2934 -- first actual, which may be rewritten later as an explicit
2935 -- dereference.
ec6078e3 2936
aab883ec 2937 if Must_Skip then
ec6078e3
ES
2938 Next_Actual (Actual);
2939 Next_Formal (Formal);
2940 end if;
2941
996ae0b0 2942 while Present (Actual) and then Present (Formal) loop
fbf5a39b
AC
2943 if Nkind (Parent (Actual)) /= N_Parameter_Association
2944 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
996ae0b0 2945 then
9c510803
ES
2946 -- The actual can be compatible with the formal, but we must
2947 -- also check that the context is not an address type that is
2948 -- visibly an integer type, as is the case in VMS_64. In this
2949 -- case the use of literals is illegal, except in the body of
2950 -- descendents of system, where arithmetic operations on
2951 -- address are of course used.
2952
2953 if Has_Compatible_Type (Actual, Etype (Formal))
2954 and then
2955 (Etype (Actual) /= Universal_Integer
2956 or else not Is_Descendent_Of_Address (Etype (Formal))
2957 or else
2958 Is_Predefined_File_Name
2959 (Unit_File_Name (Get_Source_Unit (N))))
2960 then
996ae0b0
RK
2961 Next_Actual (Actual);
2962 Next_Formal (Formal);
2963
2964 else
2965 if Debug_Flag_E then
2966 Write_Str (" type checking fails in call ");
2967 Write_Int (Int (N));
2968 Write_Str (" with formal ");
2969 Write_Int (Int (Formal));
2970 Write_Str (" in subprogram ");
2971 Write_Int (Int (Nam));
2972 Write_Eol;
2973 end if;
2974
53cf4600 2975 if Report and not Is_Indexed and not Is_Indirect then
758c442c
GD
2976
2977 -- Ada 2005 (AI-251): Complete the error notification
8f2eeab7 2978 -- to help new Ada 2005 users.
758c442c
GD
2979
2980 if Is_Class_Wide_Type (Etype (Formal))
2981 and then Is_Interface (Etype (Etype (Formal)))
2982 and then not Interface_Present_In_Ancestor
2983 (Typ => Etype (Actual),
2984 Iface => Etype (Etype (Formal)))
2985 then
758c442c 2986 Error_Msg_NE
ec6078e3 2987 ("(Ada 2005) does not implement interface }",
758c442c
GD
2988 Actual, Etype (Etype (Formal)));
2989 end if;
2990
996ae0b0
RK
2991 Wrong_Type (Actual, Etype (Formal));
2992
2993 if Nkind (Actual) = N_Op_Eq
2994 and then Nkind (Left_Opnd (Actual)) = N_Identifier
2995 then
2996 Formal := First_Formal (Nam);
996ae0b0 2997 while Present (Formal) loop
996ae0b0 2998 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
4e7a4f6e 2999 Error_Msg_N -- CODEFIX
fbf5a39b 3000 ("possible misspelling of `='>`!", Actual);
996ae0b0
RK
3001 exit;
3002 end if;
3003
3004 Next_Formal (Formal);
3005 end loop;
3006 end if;
3007
3008 if All_Errors_Mode then
3009 Error_Msg_Sloc := Sloc (Nam);
3010
3b42c566
RD
3011 if Etype (Formal) = Any_Type then
3012 Error_Msg_N
3013 ("there is no legal actual parameter", Actual);
3014 end if;
3015
996ae0b0
RK
3016 if Is_Overloadable (Nam)
3017 and then Present (Alias (Nam))
3018 and then not Comes_From_Source (Nam)
3019 then
3020 Error_Msg_NE
401093c1
ES
3021 ("\\ =='> in call to inherited operation & #!",
3022 Actual, Nam);
7324bf49
AC
3023
3024 elsif Ekind (Nam) = E_Subprogram_Type then
3025 declare
3026 Access_To_Subprogram_Typ :
3027 constant Entity_Id :=
3028 Defining_Identifier
3029 (Associated_Node_For_Itype (Nam));
3030 begin
3031 Error_Msg_NE (
401093c1 3032 "\\ =='> in call to dereference of &#!",
7324bf49
AC
3033 Actual, Access_To_Subprogram_Typ);
3034 end;
3035
996ae0b0 3036 else
401093c1
ES
3037 Error_Msg_NE
3038 ("\\ =='> in call to &#!", Actual, Nam);
7324bf49 3039
996ae0b0
RK
3040 end if;
3041 end if;
3042 end if;
3043
3044 return;
3045 end if;
3046
3047 else
3048 -- Normalize_Actuals has verified that a default value exists
3049 -- for this formal. Current actual names a subsequent formal.
3050
3051 Next_Formal (Formal);
3052 end if;
3053 end loop;
3054
4c46b835 3055 -- On exit, all actuals match
996ae0b0 3056
fbf5a39b 3057 Indicate_Name_And_Type;
996ae0b0
RK
3058 end if;
3059 end Analyze_One_Call;
3060
15ce9ca2
AC
3061 ---------------------------
3062 -- Analyze_Operator_Call --
3063 ---------------------------
996ae0b0
RK
3064
3065 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
3066 Op_Name : constant Name_Id := Chars (Op_Id);
3067 Act1 : constant Node_Id := First_Actual (N);
3068 Act2 : constant Node_Id := Next_Actual (Act1);
3069
3070 begin
4c46b835
AC
3071 -- Binary operator case
3072
996ae0b0
RK
3073 if Present (Act2) then
3074
4c46b835 3075 -- If more than two operands, then not binary operator after all
996ae0b0
RK
3076
3077 if Present (Next_Actual (Act2)) then
996ae0b0
RK
3078 return;
3079
3080 elsif Op_Name = Name_Op_Add
3081 or else Op_Name = Name_Op_Subtract
3082 or else Op_Name = Name_Op_Multiply
3083 or else Op_Name = Name_Op_Divide
3084 or else Op_Name = Name_Op_Mod
3085 or else Op_Name = Name_Op_Rem
3086 or else Op_Name = Name_Op_Expon
3087 then
3088 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
3089
3090 elsif Op_Name = Name_Op_And
3091 or else Op_Name = Name_Op_Or
3092 or else Op_Name = Name_Op_Xor
3093 then
3094 Find_Boolean_Types (Act1, Act2, Op_Id, N);
3095
3096 elsif Op_Name = Name_Op_Lt
3097 or else Op_Name = Name_Op_Le
3098 or else Op_Name = Name_Op_Gt
3099 or else Op_Name = Name_Op_Ge
3100 then
3101 Find_Comparison_Types (Act1, Act2, Op_Id, N);
3102
3103 elsif Op_Name = Name_Op_Eq
3104 or else Op_Name = Name_Op_Ne
3105 then
3106 Find_Equality_Types (Act1, Act2, Op_Id, N);
3107
3108 elsif Op_Name = Name_Op_Concat then
3109 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
3110
3111 -- Is this else null correct, or should it be an abort???
3112
3113 else
3114 null;
3115 end if;
3116
4c46b835 3117 -- Unary operator case
996ae0b0 3118
4c46b835 3119 else
996ae0b0
RK
3120 if Op_Name = Name_Op_Subtract or else
3121 Op_Name = Name_Op_Add or else
3122 Op_Name = Name_Op_Abs
3123 then
3124 Find_Unary_Types (Act1, Op_Id, N);
3125
3126 elsif
3127 Op_Name = Name_Op_Not
3128 then
3129 Find_Negation_Types (Act1, Op_Id, N);
3130
3131 -- Is this else null correct, or should it be an abort???
3132
3133 else
3134 null;
3135 end if;
3136 end if;
3137 end Analyze_Operator_Call;
3138
3139 -------------------------------------------
3140 -- Analyze_Overloaded_Selected_Component --
3141 -------------------------------------------
3142
3143 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
fbf5a39b
AC
3144 Nam : constant Node_Id := Prefix (N);
3145 Sel : constant Node_Id := Selector_Name (N);
996ae0b0 3146 Comp : Entity_Id;
996ae0b0
RK
3147 I : Interp_Index;
3148 It : Interp;
3149 T : Entity_Id;
3150
3151 begin
4c46b835 3152 Set_Etype (Sel, Any_Type);
996ae0b0 3153
4c46b835 3154 Get_First_Interp (Nam, I, It);
996ae0b0
RK
3155 while Present (It.Typ) loop
3156 if Is_Access_Type (It.Typ) then
3157 T := Designated_Type (It.Typ);
fbf5a39b 3158 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
996ae0b0
RK
3159 else
3160 T := It.Typ;
3161 end if;
3162
95eb8b69
AC
3163 -- Locate the component. For a private prefix the selector can denote
3164 -- a discriminant.
3165
3166 if Is_Record_Type (T) or else Is_Private_Type (T) then
d469eabe
HK
3167
3168 -- If the prefix is a class-wide type, the visible components are
3169 -- those of the base type.
3170
3171 if Is_Class_Wide_Type (T) then
3172 T := Etype (T);
3173 end if;
3174
996ae0b0 3175 Comp := First_Entity (T);
996ae0b0 3176 while Present (Comp) loop
996ae0b0
RK
3177 if Chars (Comp) = Chars (Sel)
3178 and then Is_Visible_Component (Comp)
3179 then
996ae0b0 3180
f16d05d9
AC
3181 -- AI05-105: if the context is an object renaming with
3182 -- an anonymous access type, the expected type of the
3183 -- object must be anonymous. This is a name resolution rule.
996ae0b0 3184
f16d05d9
AC
3185 if Nkind (Parent (N)) /= N_Object_Renaming_Declaration
3186 or else No (Access_Definition (Parent (N)))
3187 or else Ekind (Etype (Comp)) = E_Anonymous_Access_Type
3188 or else
3189 Ekind (Etype (Comp)) = E_Anonymous_Access_Subprogram_Type
3190 then
3191 Set_Entity (Sel, Comp);
3192 Set_Etype (Sel, Etype (Comp));
3193 Add_One_Interp (N, Etype (Comp), Etype (Comp));
44a10091 3194 Check_Implicit_Dereference (N, Etype (Comp));
f16d05d9
AC
3195
3196 -- This also specifies a candidate to resolve the name.
3197 -- Further overloading will be resolved from context.
3198 -- The selector name itself does not carry overloading
3199 -- information.
3200
3201 Set_Etype (Nam, It.Typ);
3202
3203 else
b61ee1aa 3204 -- Named access type in the context of a renaming
f16d05d9
AC
3205 -- declaration with an access definition. Remove
3206 -- inapplicable candidate.
3207
3208 Remove_Interp (I);
3209 end if;
996ae0b0
RK
3210 end if;
3211
3212 Next_Entity (Comp);
3213 end loop;
3214
3215 elsif Is_Concurrent_Type (T) then
3216 Comp := First_Entity (T);
996ae0b0
RK
3217 while Present (Comp)
3218 and then Comp /= First_Private_Entity (T)
3219 loop
3220 if Chars (Comp) = Chars (Sel) then
3221 if Is_Overloadable (Comp) then
3222 Add_One_Interp (Sel, Comp, Etype (Comp));
3223 else
3224 Set_Entity_With_Style_Check (Sel, Comp);
3225 Generate_Reference (Comp, Sel);
3226 end if;
3227
3228 Set_Etype (Sel, Etype (Comp));
3229 Set_Etype (N, Etype (Comp));
3230 Set_Etype (Nam, It.Typ);
3231
09494c32
AC
3232 -- For access type case, introduce explicit dereference for
3233 -- more uniform treatment of entry calls. Do this only once
3234 -- if several interpretations yield an access type.
996ae0b0 3235
d469eabe
HK
3236 if Is_Access_Type (Etype (Nam))
3237 and then Nkind (Nam) /= N_Explicit_Dereference
3238 then
996ae0b0 3239 Insert_Explicit_Dereference (Nam);
fbf5a39b
AC
3240 Error_Msg_NW
3241 (Warn_On_Dereference, "?implicit dereference", N);
996ae0b0
RK
3242 end if;
3243 end if;
3244
3245 Next_Entity (Comp);
3246 end loop;
3247
3248 Set_Is_Overloaded (N, Is_Overloaded (Sel));
996ae0b0
RK
3249 end if;
3250
3251 Get_Next_Interp (I, It);
3252 end loop;
3253
0a36105d
JM
3254 if Etype (N) = Any_Type
3255 and then not Try_Object_Operation (N)
3256 then
996ae0b0
RK
3257 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
3258 Set_Entity (Sel, Any_Id);
3259 Set_Etype (Sel, Any_Type);
3260 end if;
996ae0b0
RK
3261 end Analyze_Overloaded_Selected_Component;
3262
3263 ----------------------------------
3264 -- Analyze_Qualified_Expression --
3265 ----------------------------------
3266
3267 procedure Analyze_Qualified_Expression (N : Node_Id) is
3268 Mark : constant Entity_Id := Subtype_Mark (N);
45c8b94b
ES
3269 Expr : constant Node_Id := Expression (N);
3270 I : Interp_Index;
3271 It : Interp;
996ae0b0
RK
3272 T : Entity_Id;
3273
3274 begin
45c8b94b
ES
3275 Analyze_Expression (Expr);
3276
996ae0b0
RK
3277 Set_Etype (N, Any_Type);
3278 Find_Type (Mark);
3279 T := Entity (Mark);
45c8b94b 3280 Set_Etype (N, T);
996ae0b0
RK
3281
3282 if T = Any_Type then
3283 return;
3284 end if;
996ae0b0 3285
4c46b835 3286 Check_Fully_Declared (T, N);
45c8b94b
ES
3287
3288 -- If expected type is class-wide, check for exact match before
3289 -- expansion, because if the expression is a dispatching call it
3290 -- may be rewritten as explicit dereference with class-wide result.
3291 -- If expression is overloaded, retain only interpretations that
3292 -- will yield exact matches.
3293
3294 if Is_Class_Wide_Type (T) then
3295 if not Is_Overloaded (Expr) then
3296 if Base_Type (Etype (Expr)) /= Base_Type (T) then
3297 if Nkind (Expr) = N_Aggregate then
3298 Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
3299 else
3300 Wrong_Type (Expr, T);
3301 end if;
3302 end if;
3303
3304 else
3305 Get_First_Interp (Expr, I, It);
3306
3307 while Present (It.Nam) loop
3308 if Base_Type (It.Typ) /= Base_Type (T) then
3309 Remove_Interp (I);
3310 end if;
3311
3312 Get_Next_Interp (I, It);
3313 end loop;
3314 end if;
3315 end if;
3316
996ae0b0
RK
3317 Set_Etype (N, T);
3318 end Analyze_Qualified_Expression;
3319
a961aa79
AC
3320 -----------------------------------
3321 -- Analyze_Quantified_Expression --
3322 -----------------------------------
3323
3324 procedure Analyze_Quantified_Expression (N : Node_Id) is
3325 Loc : constant Source_Ptr := Sloc (N);
3326 Ent : constant Entity_Id :=
3327 New_Internal_Entity
3328 (E_Loop, Current_Scope, Sloc (N), 'L');
3329
3330 Iterator : Node_Id;
90c63b09 3331
a961aa79 3332 begin
2ba431e5 3333 Check_SPARK_Restriction ("quantified expression is not allowed", N);
1d801f21 3334
a961aa79
AC
3335 Set_Etype (Ent, Standard_Void_Type);
3336 Set_Parent (Ent, N);
3337
c56a9ba4
AC
3338 if Present (Loop_Parameter_Specification (N)) then
3339 Iterator :=
3340 Make_Iteration_Scheme (Loc,
4561baf7
ES
3341 Loop_Parameter_Specification =>
3342 Loop_Parameter_Specification (N));
c56a9ba4
AC
3343 else
3344 Iterator :=
3345 Make_Iteration_Scheme (Loc,
3346 Iterator_Specification =>
3347 Iterator_Specification (N));
3348 end if;
a961aa79
AC
3349
3350 Push_Scope (Ent);
c56a9ba4 3351 Set_Parent (Iterator, N);
a961aa79 3352 Analyze_Iteration_Scheme (Iterator);
c56a9ba4
AC
3353
3354 -- The loop specification may have been converted into an
3355 -- iterator specification during its analysis. Update the
3356 -- quantified node accordingly.
3357
3358 if Present (Iterator_Specification (Iterator)) then
3359 Set_Iterator_Specification
3360 (N, Iterator_Specification (Iterator));
3361 Set_Loop_Parameter_Specification (N, Empty);
3362 end if;
3363
a961aa79
AC
3364 Analyze (Condition (N));
3365 End_Scope;
90c63b09 3366
a961aa79
AC
3367 Set_Etype (N, Standard_Boolean);
3368 end Analyze_Quantified_Expression;
3369
996ae0b0
RK
3370 -------------------
3371 -- Analyze_Range --
3372 -------------------
3373
3374 procedure Analyze_Range (N : Node_Id) is
3375 L : constant Node_Id := Low_Bound (N);
3376 H : constant Node_Id := High_Bound (N);
3377 I1, I2 : Interp_Index;
3378 It1, It2 : Interp;
3379
3380 procedure Check_Common_Type (T1, T2 : Entity_Id);
3381 -- Verify the compatibility of two types, and choose the
3382 -- non universal one if the other is universal.
3383
3384 procedure Check_High_Bound (T : Entity_Id);
3385 -- Test one interpretation of the low bound against all those
3386 -- of the high bound.
3387
fbf5a39b
AC
3388 procedure Check_Universal_Expression (N : Node_Id);
3389 -- In Ada83, reject bounds of a universal range that are not
3390 -- literals or entity names.
3391
996ae0b0
RK
3392 -----------------------
3393 -- Check_Common_Type --
3394 -----------------------
3395
3396 procedure Check_Common_Type (T1, T2 : Entity_Id) is
3397 begin
b4592168
GD
3398 if Covers (T1 => T1, T2 => T2)
3399 or else
3400 Covers (T1 => T2, T2 => T1)
3401 then
996ae0b0
RK
3402 if T1 = Universal_Integer
3403 or else T1 = Universal_Real
3404 or else T1 = Any_Character
3405 then
3406 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
3407
fbf5a39b 3408 elsif T1 = T2 then
996ae0b0
RK
3409 Add_One_Interp (N, T1, T1);
3410
3411 else
3412 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
3413 end if;
3414 end if;
3415 end Check_Common_Type;
3416
3417 ----------------------
3418 -- Check_High_Bound --
3419 ----------------------
3420
3421 procedure Check_High_Bound (T : Entity_Id) is
3422 begin
3423 if not Is_Overloaded (H) then
3424 Check_Common_Type (T, Etype (H));
3425 else
3426 Get_First_Interp (H, I2, It2);
996ae0b0
RK
3427 while Present (It2.Typ) loop
3428 Check_Common_Type (T, It2.Typ);
3429 Get_Next_Interp (I2, It2);
3430 end loop;
3431 end if;
3432 end Check_High_Bound;
3433
fbf5a39b
AC
3434 -----------------------------
3435 -- Is_Universal_Expression --
3436 -----------------------------
3437
3438 procedure Check_Universal_Expression (N : Node_Id) is
3439 begin
3440 if Etype (N) = Universal_Integer
3441 and then Nkind (N) /= N_Integer_Literal
3442 and then not Is_Entity_Name (N)
3443 and then Nkind (N) /= N_Attribute_Reference
3444 then
3445 Error_Msg_N ("illegal bound in discrete range", N);
3446 end if;
3447 end Check_Universal_Expression;
3448
996ae0b0
RK
3449 -- Start of processing for Analyze_Range
3450
3451 begin
3452 Set_Etype (N, Any_Type);
3453 Analyze_Expression (L);
3454 Analyze_Expression (H);
3455
3456 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
3457 return;
3458
3459 else
3460 if not Is_Overloaded (L) then
3461 Check_High_Bound (Etype (L));
3462 else
3463 Get_First_Interp (L, I1, It1);
996ae0b0
RK
3464 while Present (It1.Typ) loop
3465 Check_High_Bound (It1.Typ);
3466 Get_Next_Interp (I1, It1);
3467 end loop;
3468 end if;
3469
3470 -- If result is Any_Type, then we did not find a compatible pair
3471
3472 if Etype (N) = Any_Type then
3473 Error_Msg_N ("incompatible types in range ", N);
3474 end if;
3475 end if;
fbf5a39b 3476
0ab80019 3477 if Ada_Version = Ada_83
fbf5a39b
AC
3478 and then
3479 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
4c46b835 3480 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
fbf5a39b
AC
3481 then
3482 Check_Universal_Expression (L);
3483 Check_Universal_Expression (H);
3484 end if;
996ae0b0
RK
3485 end Analyze_Range;
3486
3487 -----------------------
3488 -- Analyze_Reference --
3489 -----------------------
3490
3491 procedure Analyze_Reference (N : Node_Id) is
3492 P : constant Node_Id := Prefix (N);
b4592168
GD
3493 E : Entity_Id;
3494 T : Entity_Id;
996ae0b0 3495 Acc_Type : Entity_Id;
b4592168 3496
996ae0b0
RK
3497 begin
3498 Analyze (P);
b4592168
GD
3499
3500 -- An interesting error check, if we take the 'Reference of an object
3501 -- for which a pragma Atomic or Volatile has been given, and the type
3502 -- of the object is not Atomic or Volatile, then we are in trouble. The
3503 -- problem is that no trace of the atomic/volatile status will remain
3504 -- for the backend to respect when it deals with the resulting pointer,
3505 -- since the pointer type will not be marked atomic (it is a pointer to
3506 -- the base type of the object).
3507
3508 -- It is not clear if that can ever occur, but in case it does, we will
3509 -- generate an error message. Not clear if this message can ever be
3510 -- generated, and pretty clear that it represents a bug if it is, still
d2f25cd1
AC
3511 -- seems worth checking, except in CodePeer mode where we do not really
3512 -- care and don't want to bother the user.
b4592168
GD
3513
3514 T := Etype (P);
3515
3516 if Is_Entity_Name (P)
3517 and then Is_Object_Reference (P)
d2f25cd1 3518 and then not CodePeer_Mode
b4592168
GD
3519 then
3520 E := Entity (P);
3521 T := Etype (P);
3522
3523 if (Has_Atomic_Components (E)
3524 and then not Has_Atomic_Components (T))
3525 or else
3526 (Has_Volatile_Components (E)
3527 and then not Has_Volatile_Components (T))
3528 or else (Is_Atomic (E) and then not Is_Atomic (T))
3529 or else (Is_Volatile (E) and then not Is_Volatile (T))
3530 then
3531 Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
3532 end if;
3533 end if;
3534
3535 -- Carry on with normal processing
3536
996ae0b0 3537 Acc_Type := Create_Itype (E_Allocator_Type, N);
b4592168 3538 Set_Etype (Acc_Type, Acc_Type);
996ae0b0
RK
3539 Set_Directly_Designated_Type (Acc_Type, Etype (P));
3540 Set_Etype (N, Acc_Type);
3541 end Analyze_Reference;
3542
3543 --------------------------------
3544 -- Analyze_Selected_Component --
3545 --------------------------------
3546
2383acbd
AC
3547 -- Prefix is a record type or a task or protected type. In the latter case,
3548 -- the selector must denote a visible entry.
996ae0b0
RK
3549
3550 procedure Analyze_Selected_Component (N : Node_Id) is
d469eabe
HK
3551 Name : constant Node_Id := Prefix (N);
3552 Sel : constant Node_Id := Selector_Name (N);
3553 Act_Decl : Node_Id;
3554 Comp : Entity_Id;
3555 Has_Candidate : Boolean := False;
3556 In_Scope : Boolean;
3557 Parent_N : Node_Id;
3558 Pent : Entity_Id := Empty;
3559 Prefix_Type : Entity_Id;
401093c1
ES
3560
3561 Type_To_Use : Entity_Id;
3562 -- In most cases this is the Prefix_Type, but if the Prefix_Type is
3563 -- a class-wide type, we use its root type, whose components are
3564 -- present in the class-wide type.
3565
2383acbd
AC
3566 Is_Single_Concurrent_Object : Boolean;
3567 -- Set True if the prefix is a single task or a single protected object
3568
20261dc1
AC
3569 procedure Find_Component_In_Instance (Rec : Entity_Id);
3570 -- In an instance, a component of a private extension may not be visible
3571 -- while it was visible in the generic. Search candidate scope for a
3572 -- component with the proper identifier. This is only done if all other
3573 -- searches have failed. When the match is found (it always will be),
3574 -- the Etype of both N and Sel are set from this component, and the
3575 -- entity of Sel is set to reference this component.
3576
d469eabe
HK
3577 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
3578 -- It is known that the parent of N denotes a subprogram call. Comp
3579 -- is an overloadable component of the concurrent type of the prefix.
3580 -- Determine whether all formals of the parent of N and Comp are mode
b4592168
GD
3581 -- conformant. If the parent node is not analyzed yet it may be an
3582 -- indexed component rather than a function call.
d469eabe 3583
20261dc1
AC
3584 --------------------------------
3585 -- Find_Component_In_Instance --
3586 --------------------------------
3587
3588 procedure Find_Component_In_Instance (Rec : Entity_Id) is
3589 Comp : Entity_Id;
3590
3591 begin
3592 Comp := First_Component (Rec);
3593 while Present (Comp) loop
3594 if Chars (Comp) = Chars (Sel) then
3595 Set_Entity_With_Style_Check (Sel, Comp);
3596 Set_Etype (Sel, Etype (Comp));
3597 Set_Etype (N, Etype (Comp));
3598 return;
3599 end if;
3600
3601 Next_Component (Comp);
3602 end loop;
3603
3604 -- This must succeed because code was legal in the generic
3605
3606 raise Program_Error;
3607 end Find_Component_In_Instance;
3608
d469eabe
HK
3609 ------------------------------
3610 -- Has_Mode_Conformant_Spec --
3611 ------------------------------
3612
3613 function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
3614 Comp_Param : Entity_Id;
3615 Param : Node_Id;
3616 Param_Typ : Entity_Id;
3617
3618 begin
3619 Comp_Param := First_Formal (Comp);
b4592168
GD
3620
3621 if Nkind (Parent (N)) = N_Indexed_Component then
3622 Param := First (Expressions (Parent (N)));
3623 else
3624 Param := First (Parameter_Associations (Parent (N)));
3625 end if;
3626
d469eabe
HK
3627 while Present (Comp_Param)
3628 and then Present (Param)
3629 loop
3630 Param_Typ := Find_Parameter_Type (Param);
3631
3632 if Present (Param_Typ)
3633 and then
3634 not Conforming_Types
3635 (Etype (Comp_Param), Param_Typ, Mode_Conformant)
3636 then
3637 return False;
3638 end if;
3639
3640 Next_Formal (Comp_Param);
3641 Next (Param);
3642 end loop;
3643
3644 -- One of the specs has additional formals
3645
3646 if Present (Comp_Param) or else Present (Param) then
3647 return False;
3648 end if;
3649
3650 return True;
3651 end Has_Mode_Conformant_Spec;
996ae0b0
RK
3652
3653 -- Start of processing for Analyze_Selected_Component
3654
3655 begin
3656 Set_Etype (N, Any_Type);
3657
3658 if Is_Overloaded (Name) then
3659 Analyze_Overloaded_Selected_Component (N);
3660 return;
3661
3662 elsif Etype (Name) = Any_Type then
3663 Set_Entity (Sel, Any_Id);
3664 Set_Etype (Sel, Any_Type);
3665 return;
3666
3667 else
996ae0b0
RK
3668 Prefix_Type := Etype (Name);
3669 end if;
3670
3671 if Is_Access_Type (Prefix_Type) then
07fc65c4 3672
0d57c6f4
RD
3673 -- A RACW object can never be used as prefix of a selected component
3674 -- since that means it is dereferenced without being a controlling
3675 -- operand of a dispatching operation (RM E.2.2(16/1)). Before
3676 -- reporting an error, we must check whether this is actually a
3677 -- dispatching call in prefix form.
07fc65c4 3678
996ae0b0
RK
3679 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
3680 and then Comes_From_Source (N)
3681 then
b4592168
GD
3682 if Try_Object_Operation (N) then
3683 return;
3684 else
3685 Error_Msg_N
3686 ("invalid dereference of a remote access-to-class-wide value",
3687 N);
3688 end if;
07fc65c4
GB
3689
3690 -- Normal case of selected component applied to access type
3691
3692 else
fbf5a39b 3693 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
da709d08 3694
6e73e3ab
AC
3695 if Is_Entity_Name (Name) then
3696 Pent := Entity (Name);
3697 elsif Nkind (Name) = N_Selected_Component
3698 and then Is_Entity_Name (Selector_Name (Name))
3699 then
3700 Pent := Entity (Selector_Name (Name));
3701 end if;
da709d08 3702
d469eabe 3703 Prefix_Type := Process_Implicit_Dereference_Prefix (Pent, Name);
996ae0b0 3704 end if;
b4592168
GD
3705
3706 -- If we have an explicit dereference of a remote access-to-class-wide
3707 -- value, then issue an error (see RM-E.2.2(16/1)). However we first
3708 -- have to check for the case of a prefix that is a controlling operand
3709 -- of a prefixed dispatching call, as the dereference is legal in that
3710 -- case. Normally this condition is checked in Validate_Remote_Access_
3711 -- To_Class_Wide_Type, but we have to defer the checking for selected
3712 -- component prefixes because of the prefixed dispatching call case.
3713 -- Note that implicit dereferences are checked for this just above.
3714
3715 elsif Nkind (Name) = N_Explicit_Dereference
3716 and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
3717 and then Comes_From_Source (N)
3718 then
3719 if Try_Object_Operation (N) then
3720 return;
3721 else
3722 Error_Msg_N
3723 ("invalid dereference of a remote access-to-class-wide value",
3724 N);
3725 end if;
aab883ec 3726 end if;
b67a385c 3727
aab883ec
ES
3728 -- (Ada 2005): if the prefix is the limited view of a type, and
3729 -- the context already includes the full view, use the full view
3730 -- in what follows, either to retrieve a component of to find
3731 -- a primitive operation. If the prefix is an explicit dereference,
3732 -- set the type of the prefix to reflect this transformation.
401093c1
ES
3733 -- If the non-limited view is itself an incomplete type, get the
3734 -- full view if available.
aab883ec
ES
3735
3736 if Is_Incomplete_Type (Prefix_Type)
3737 and then From_With_Type (Prefix_Type)
3738 and then Present (Non_Limited_View (Prefix_Type))
3739 then
401093c1 3740 Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
aab883ec
ES
3741
3742 if Nkind (N) = N_Explicit_Dereference then
3743 Set_Etype (Prefix (N), Prefix_Type);
3744 end if;
3745
3746 elsif Ekind (Prefix_Type) = E_Class_Wide_Type
3747 and then From_With_Type (Prefix_Type)
3748 and then Present (Non_Limited_View (Etype (Prefix_Type)))
3749 then
3750 Prefix_Type :=
3751 Class_Wide_Type (Non_Limited_View (Etype (Prefix_Type)));
3752
3753 if Nkind (N) = N_Explicit_Dereference then
3754 Set_Etype (Prefix (N), Prefix_Type);
b67a385c 3755 end if;
996ae0b0
RK
3756 end if;
3757
3758 if Ekind (Prefix_Type) = E_Private_Subtype then
3759 Prefix_Type := Base_Type (Prefix_Type);
3760 end if;
3761
401093c1 3762 Type_To_Use := Prefix_Type;
996ae0b0
RK
3763
3764 -- For class-wide types, use the entity list of the root type. This
3765 -- indirection is specially important for private extensions because
3766 -- only the root type get switched (not the class-wide type).
3767
3768 if Is_Class_Wide_Type (Prefix_Type) then
401093c1 3769 Type_To_Use := Root_Type (Prefix_Type);
996ae0b0
RK
3770 end if;
3771
2383acbd
AC
3772 -- If the prefix is a single concurrent object, use its name in error
3773 -- messages, rather than that of its anonymous type.
3774
3775 Is_Single_Concurrent_Object :=
3776 Is_Concurrent_Type (Prefix_Type)
3777 and then Is_Internal_Name (Chars (Prefix_Type))
3778 and then not Is_Derived_Type (Prefix_Type)
3779 and then Is_Entity_Name (Name);
3780
401093c1 3781 Comp := First_Entity (Type_To_Use);
996ae0b0
RK
3782
3783 -- If the selector has an original discriminant, the node appears in
3784 -- an instance. Replace the discriminant with the corresponding one
3785 -- in the current discriminated type. For nested generics, this must
3786 -- be done transitively, so note the new original discriminant.
3787
3788 if Nkind (Sel) = N_Identifier
c0b11850 3789 and then In_Instance
996ae0b0
RK
3790 and then Present (Original_Discriminant (Sel))
3791 then
3792 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
3793
3794 -- Mark entity before rewriting, for completeness and because
3795 -- subsequent semantic checks might examine the original node.
3796
3797 Set_Entity (Sel, Comp);
3798 Rewrite (Selector_Name (N),
3799 New_Occurrence_Of (Comp, Sloc (N)));
3800 Set_Original_Discriminant (Selector_Name (N), Comp);
3801 Set_Etype (N, Etype (Comp));
44a10091 3802 Check_Implicit_Dereference (N, Etype (Comp));
996ae0b0
RK
3803
3804 if Is_Access_Type (Etype (Name)) then
3805 Insert_Explicit_Dereference (Name);
fbf5a39b 3806 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
996ae0b0
RK
3807 end if;
3808
3809 elsif Is_Record_Type (Prefix_Type) then
3810
3811 -- Find component with given name
3812
3813 while Present (Comp) loop
996ae0b0
RK
3814 if Chars (Comp) = Chars (Sel)
3815 and then Is_Visible_Component (Comp)
3816 then
3817 Set_Entity_With_Style_Check (Sel, Comp);
996ae0b0
RK
3818 Set_Etype (Sel, Etype (Comp));
3819
3820 if Ekind (Comp) = E_Discriminant then
5d09245e 3821 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
996ae0b0
RK
3822 Error_Msg_N
3823 ("cannot reference discriminant of Unchecked_Union",
3824 Sel);
3825 end if;
3826
3827 if Is_Generic_Type (Prefix_Type)
3828 or else
3829 Is_Generic_Type (Root_Type (Prefix_Type))
3830 then
3831 Set_Original_Discriminant (Sel, Comp);
3832 end if;
3833 end if;
3834
3835 -- Resolve the prefix early otherwise it is not possible to
3836 -- build the actual subtype of the component: it may need
3837 -- to duplicate this prefix and duplication is only allowed
3838 -- on fully resolved expressions.
3839
fbf5a39b 3840 Resolve (Name);
996ae0b0 3841
b67a385c
ES
3842 -- Ada 2005 (AI-50217): Check wrong use of incomplete types or
3843 -- subtypes in a package specification.
28be29ce
ES
3844 -- Example:
3845
3846 -- limited with Pkg;
3847 -- package Pkg is
3848 -- type Acc_Inc is access Pkg.T;
3849 -- X : Acc_Inc;
b67a385c
ES
3850 -- N : Natural := X.all.Comp; -- ERROR, limited view
3851 -- end Pkg; -- Comp is not visible
28be29ce
ES
3852
3853 if Nkind (Name) = N_Explicit_Dereference
3854 and then From_With_Type (Etype (Prefix (Name)))
3855 and then not Is_Potentially_Use_Visible (Etype (Name))
b67a385c
ES
3856 and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
3857 N_Package_Specification
28be29ce
ES
3858 then
3859 Error_Msg_NE
3860 ("premature usage of incomplete}", Prefix (Name),
3861 Etype (Prefix (Name)));
3862 end if;
3863
996ae0b0
RK
3864 -- We never need an actual subtype for the case of a selection
3865 -- for a indexed component of a non-packed array, since in
3866 -- this case gigi generates all the checks and can find the
3867 -- necessary bounds information.
3868
0d57c6f4
RD
3869 -- We also do not need an actual subtype for the case of a
3870 -- first, last, length, or range attribute applied to a
996ae0b0
RK
3871 -- non-packed array, since gigi can again get the bounds in
3872 -- these cases (gigi cannot handle the packed case, since it
3873 -- has the bounds of the packed array type, not the original
3874 -- bounds of the type). However, if the prefix is itself a
3875 -- selected component, as in a.b.c (i), gigi may regard a.b.c
3876 -- as a dynamic-sized temporary, so we do generate an actual
3877 -- subtype for this case.
3878
3879 Parent_N := Parent (N);
3880
3881 if not Is_Packed (Etype (Comp))
3882 and then
3883 ((Nkind (Parent_N) = N_Indexed_Component
d469eabe 3884 and then Nkind (Name) /= N_Selected_Component)
996ae0b0
RK
3885 or else
3886 (Nkind (Parent_N) = N_Attribute_Reference
3887 and then (Attribute_Name (Parent_N) = Name_First
ffe9aba8 3888 or else
996ae0b0 3889 Attribute_Name (Parent_N) = Name_Last
ffe9aba8 3890 or else
996ae0b0 3891 Attribute_Name (Parent_N) = Name_Length
ffe9aba8 3892 or else
996ae0b0
RK
3893 Attribute_Name (Parent_N) = Name_Range)))
3894 then
3895 Set_Etype (N, Etype (Comp));
3896
98123480
ES
3897 -- If full analysis is not enabled, we do not generate an
3898 -- actual subtype, because in the absence of expansion
3899 -- reference to a formal of a protected type, for example,
3900 -- will not be properly transformed, and will lead to
3901 -- out-of-scope references in gigi.
3902
3903 -- In all other cases, we currently build an actual subtype.
3904 -- It seems likely that many of these cases can be avoided,
3905 -- but right now, the front end makes direct references to the
fbf5a39b 3906 -- bounds (e.g. in generating a length check), and if we do
996ae0b0 3907 -- not make an actual subtype, we end up getting a direct
98123480 3908 -- reference to a discriminant, which will not do.
996ae0b0 3909
98123480 3910 elsif Full_Analysis then
996ae0b0
RK
3911 Act_Decl :=
3912 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
3913 Insert_Action (N, Act_Decl);
3914
3915 if No (Act_Decl) then
3916 Set_Etype (N, Etype (Comp));
3917
3918 else
3919 -- Component type depends on discriminants. Enter the
3920 -- main attributes of the subtype.
3921
3922 declare
fbf5a39b
AC
3923 Subt : constant Entity_Id :=
3924 Defining_Identifier (Act_Decl);
996ae0b0
RK
3925
3926 begin
3927 Set_Etype (Subt, Base_Type (Etype (Comp)));
3928 Set_Ekind (Subt, Ekind (Etype (Comp)));
3929 Set_Etype (N, Subt);
3930 end;
3931 end if;
98123480
ES
3932
3933 -- If Full_Analysis not enabled, just set the Etype
3934
3935 else
3936 Set_Etype (N, Etype (Comp));
996ae0b0
RK
3937 end if;
3938
44a10091 3939 Check_Implicit_Dereference (N, Etype (N));
996ae0b0
RK
3940 return;
3941 end if;
3942
aab883ec 3943 -- If the prefix is a private extension, check only the visible
9c510803 3944 -- components of the partial view. This must include the tag,
f3d57416 3945 -- which can appear in expanded code in a tag check.
aab883ec 3946
9c510803 3947 if Ekind (Type_To_Use) = E_Record_Type_With_Private
df3e68b1 3948 and then Chars (Selector_Name (N)) /= Name_uTag
9c510803 3949 then
401093c1 3950 exit when Comp = Last_Entity (Type_To_Use);
aab883ec
ES
3951 end if;
3952
996ae0b0
RK
3953 Next_Entity (Comp);
3954 end loop;
3955
d469eabe
HK
3956 -- Ada 2005 (AI-252): The selected component can be interpreted as
3957 -- a prefixed view of a subprogram. Depending on the context, this is
3958 -- either a name that can appear in a renaming declaration, or part
3959 -- of an enclosing call given in prefix form.
3960
3961 -- Ada 2005 (AI05-0030): In the case of dispatching requeue, the
3962 -- selected component should resolve to a name.
35ae2ed8 3963
0791fbe9 3964 if Ada_Version >= Ada_2005
35ae2ed8 3965 and then Is_Tagged_Type (Prefix_Type)
d469eabe 3966 and then not Is_Concurrent_Type (Prefix_Type)
35ae2ed8 3967 then
d469eabe
HK
3968 if Nkind (Parent (N)) = N_Generic_Association
3969 or else Nkind (Parent (N)) = N_Requeue_Statement
3970 or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
3971 then
3972 if Find_Primitive_Operation (N) then
3973 return;
3974 end if;
3975
3976 elsif Try_Object_Operation (N) then
3977 return;
3978 end if;
4c46b835 3979
98123480
ES
3980 -- If the transformation fails, it will be necessary to redo the
3981 -- analysis with all errors enabled, to indicate candidate
3982 -- interpretations and reasons for each failure ???
4c46b835 3983
35ae2ed8
AC
3984 end if;
3985
996ae0b0 3986 elsif Is_Private_Type (Prefix_Type) then
d469eabe 3987
98123480
ES
3988 -- Allow access only to discriminants of the type. If the type has
3989 -- no full view, gigi uses the parent type for the components, so we
3990 -- do the same here.
996ae0b0
RK
3991
3992 if No (Full_View (Prefix_Type)) then
401093c1
ES
3993 Type_To_Use := Root_Type (Base_Type (Prefix_Type));
3994 Comp := First_Entity (Type_To_Use);
996ae0b0
RK
3995 end if;
3996
3997 while Present (Comp) loop
996ae0b0
RK
3998 if Chars (Comp) = Chars (Sel) then
3999 if Ekind (Comp) = E_Discriminant then
4000 Set_Entity_With_Style_Check (Sel, Comp);
4001 Generate_Reference (Comp, Sel);
4002
4003 Set_Etype (Sel, Etype (Comp));
4004 Set_Etype (N, Etype (Comp));
44a10091 4005 Check_Implicit_Dereference (N, Etype (N));
996ae0b0
RK
4006
4007 if Is_Generic_Type (Prefix_Type)
d469eabe 4008 or else Is_Generic_Type (Root_Type (Prefix_Type))
996ae0b0
RK
4009 then
4010 Set_Original_Discriminant (Sel, Comp);
4011 end if;
4012
f3d57416 4013 -- Before declaring an error, check whether this is tagged
aab883ec
ES
4014 -- private type and a call to a primitive operation.
4015
0791fbe9 4016 elsif Ada_Version >= Ada_2005
aab883ec
ES
4017 and then Is_Tagged_Type (Prefix_Type)
4018 and then Try_Object_Operation (N)
4019 then
4020 return;
4021
996ae0b0 4022 else
2383acbd
AC
4023 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4024 Error_Msg_NE ("invisible selector& for }", N, Sel);
996ae0b0
RK
4025 Set_Entity (Sel, Any_Id);
4026 Set_Etype (N, Any_Type);
4027 end if;
4028
4029 return;
4030 end if;
4031
4032 Next_Entity (Comp);
4033 end loop;
4034
4035 elsif Is_Concurrent_Type (Prefix_Type) then
4036
d469eabe
HK
4037 -- Find visible operation with given name. For a protected type,
4038 -- the possible candidates are discriminants, entries or protected
4039 -- procedures. For a task type, the set can only include entries or
4040 -- discriminants if the task type is not an enclosing scope. If it
4041 -- is an enclosing scope (e.g. in an inner task) then all entities
4042 -- are visible, but the prefix must denote the enclosing scope, i.e.
4043 -- can only be a direct name or an expanded name.
996ae0b0 4044
d469eabe 4045 Set_Etype (Sel, Any_Type);
996ae0b0
RK
4046 In_Scope := In_Open_Scopes (Prefix_Type);
4047
4048 while Present (Comp) loop
4049 if Chars (Comp) = Chars (Sel) then
4050 if Is_Overloadable (Comp) then
4051 Add_One_Interp (Sel, Comp, Etype (Comp));
4052
d469eabe
HK
4053 -- If the prefix is tagged, the correct interpretation may
4054 -- lie in the primitive or class-wide operations of the
4055 -- type. Perform a simple conformance check to determine
4056 -- whether Try_Object_Operation should be invoked even if
4057 -- a visible entity is found.
4058
4059 if Is_Tagged_Type (Prefix_Type)
4060 and then
4061 Nkind_In (Parent (N), N_Procedure_Call_Statement,
b4592168
GD
4062 N_Function_Call,
4063 N_Indexed_Component)
d469eabe
HK
4064 and then Has_Mode_Conformant_Spec (Comp)
4065 then
4066 Has_Candidate := True;
4067 end if;
4068
2383acbd
AC
4069 -- Note: a selected component may not denote a component of a
4070 -- protected type (4.1.3(7)).
4071
bce79204 4072 elsif Ekind_In (Comp, E_Discriminant, E_Entry_Family)
2383acbd
AC
4073 or else (In_Scope
4074 and then not Is_Protected_Type (Prefix_Type)
4075 and then Is_Entity_Name (Name))
996ae0b0
RK
4076 then
4077 Set_Entity_With_Style_Check (Sel, Comp);
4078 Generate_Reference (Comp, Sel);
4079
4080 else
4081 goto Next_Comp;
4082 end if;
4083
4084 Set_Etype (Sel, Etype (Comp));
4085 Set_Etype (N, Etype (Comp));
4086
4087 if Ekind (Comp) = E_Discriminant then
4088 Set_Original_Discriminant (Sel, Comp);
4089 end if;
4090
09494c32
AC
4091 -- For access type case, introduce explicit dereference for
4092 -- more uniform treatment of entry calls.
996ae0b0
RK
4093
4094 if Is_Access_Type (Etype (Name)) then
4095 Insert_Explicit_Dereference (Name);
fbf5a39b
AC
4096 Error_Msg_NW
4097 (Warn_On_Dereference, "?implicit dereference", N);
996ae0b0
RK
4098 end if;
4099 end if;
4100
4101 <<Next_Comp>>
4102 Next_Entity (Comp);
4103 exit when not In_Scope
9bc856dd
AC
4104 and then
4105 Comp = First_Private_Entity (Base_Type (Prefix_Type));
996ae0b0
RK
4106 end loop;
4107
d469eabe
HK
4108 -- If there is no visible entity with the given name or none of the
4109 -- visible entities are plausible interpretations, check whether
4110 -- there is some other primitive operation with that name.
aab883ec 4111
0791fbe9 4112 if Ada_Version >= Ada_2005
aab883ec 4113 and then Is_Tagged_Type (Prefix_Type)
aab883ec 4114 then
d469eabe
HK
4115 if (Etype (N) = Any_Type
4116 or else not Has_Candidate)
0a36105d
JM
4117 and then Try_Object_Operation (N)
4118 then
4119 return;
4120
4121 -- If the context is not syntactically a procedure call, it
4122 -- may be a call to a primitive function declared outside of
4123 -- the synchronized type.
4124
4125 -- If the context is a procedure call, there might still be
4126 -- an overloading between an entry and a primitive procedure
4127 -- declared outside of the synchronized type, called in prefix
4128 -- notation. This is harder to disambiguate because in one case
4129 -- the controlling formal is implicit ???
4130
4131 elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
b4592168 4132 and then Nkind (Parent (N)) /= N_Indexed_Component
0a36105d
JM
4133 and then Try_Object_Operation (N)
4134 then
4135 return;
4136 end if;
aab883ec
ES
4137 end if;
4138
2383acbd
AC
4139 if Etype (N) = Any_Type and then Is_Protected_Type (Prefix_Type) then
4140 -- Case of a prefix of a protected type: selector might denote
4141 -- an invisible private component.
4142
4143 Comp := First_Private_Entity (Base_Type (Prefix_Type));
4144 while Present (Comp) and then Chars (Comp) /= Chars (Sel) loop
4145 Next_Entity (Comp);
4146 end loop;
4147
4148 if Present (Comp) then
4149 if Is_Single_Concurrent_Object then
4150 Error_Msg_Node_2 := Entity (Name);
4151 Error_Msg_NE ("invisible selector& for &", N, Sel);
4152
4153 else
4154 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4155 Error_Msg_NE ("invisible selector& for }", N, Sel);
4156 end if;
4157 return;
4158 end if;
4159 end if;
4160
996ae0b0
RK
4161 Set_Is_Overloaded (N, Is_Overloaded (Sel));
4162
4163 else
4164 -- Invalid prefix
4165
4166 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
4167 end if;
4168
4c46b835 4169 -- If N still has no type, the component is not defined in the prefix
996ae0b0
RK
4170
4171 if Etype (N) = Any_Type then
4172
2383acbd 4173 if Is_Single_Concurrent_Object then
996ae0b0
RK
4174 Error_Msg_Node_2 := Entity (Name);
4175 Error_Msg_NE ("no selector& for&", N, Sel);
4176
401093c1 4177 Check_Misspelled_Selector (Type_To_Use, Sel);
996ae0b0 4178
de76a39c
GB
4179 elsif Is_Generic_Type (Prefix_Type)
4180 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
07fc65c4 4181 and then Prefix_Type /= Etype (Prefix_Type)
de76a39c
GB
4182 and then Is_Record_Type (Etype (Prefix_Type))
4183 then
98123480 4184 -- If this is a derived formal type, the parent may have
de76a39c
GB
4185 -- different visibility at this point. Try for an inherited
4186 -- component before reporting an error.
4187
4188 Set_Etype (Prefix (N), Etype (Prefix_Type));
4189 Analyze_Selected_Component (N);
4190 return;
4191
20261dc1
AC
4192 -- Similarly, if this is the actual for a formal derived type, the
4193 -- component inherited from the generic parent may not be visible
4194 -- in the actual, but the selected component is legal.
4195
fbf5a39b
AC
4196 elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
4197 and then Is_Generic_Actual_Type (Prefix_Type)
4198 and then Present (Full_View (Prefix_Type))
4199 then
fbf5a39b 4200
20261dc1
AC
4201 Find_Component_In_Instance
4202 (Generic_Parent_Type (Parent (Prefix_Type)));
4203 return;
4c46b835 4204
20261dc1
AC
4205 -- Finally, the formal and the actual may be private extensions,
4206 -- but the generic is declared in a child unit of the parent, and
308e6f3a 4207 -- an additional step is needed to retrieve the proper scope.
fbf5a39b 4208
20261dc1
AC
4209 elsif In_Instance
4210 and then Present (Parent_Subtype (Etype (Base_Type (Prefix_Type))))
4211 then
4212 Find_Component_In_Instance
4213 (Parent_Subtype (Etype (Base_Type (Prefix_Type))));
4214 return;
fbf5a39b 4215
20261dc1 4216 -- Component not found, specialize error message when appropriate
fbf5a39b 4217
996ae0b0
RK
4218 else
4219 if Ekind (Prefix_Type) = E_Record_Subtype then
4220
f4b049db
AC
4221 -- Check whether this is a component of the base type which
4222 -- is absent from a statically constrained subtype. This will
4223 -- raise constraint error at run time, but is not a compile-
4224 -- time error. When the selector is illegal for base type as
4225 -- well fall through and generate a compilation error anyway.
996ae0b0
RK
4226
4227 Comp := First_Component (Base_Type (Prefix_Type));
996ae0b0 4228 while Present (Comp) loop
996ae0b0
RK
4229 if Chars (Comp) = Chars (Sel)
4230 and then Is_Visible_Component (Comp)
4231 then
4232 Set_Entity_With_Style_Check (Sel, Comp);
4233 Generate_Reference (Comp, Sel);
4234 Set_Etype (Sel, Etype (Comp));
4235 Set_Etype (N, Etype (Comp));
4236
4237 -- Emit appropriate message. Gigi will replace the
4238 -- node subsequently with the appropriate Raise.
4239
4240 Apply_Compile_Time_Constraint_Error
4241 (N, "component not present in }?",
07fc65c4 4242 CE_Discriminant_Check_Failed,
996ae0b0
RK
4243 Ent => Prefix_Type, Rep => False);
4244 Set_Raises_Constraint_Error (N);
4245 return;
4246 end if;
4247
4248 Next_Component (Comp);
4249 end loop;
4250
4251 end if;
4252
4253 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
4254 Error_Msg_NE ("no selector& for}", N, Sel);
4255
401093c1 4256 Check_Misspelled_Selector (Type_To_Use, Sel);
996ae0b0
RK
4257 end if;
4258
4259 Set_Entity (Sel, Any_Id);
4260 Set_Etype (Sel, Any_Type);
4261 end if;
4262 end Analyze_Selected_Component;
4263
4264 ---------------------------
4265 -- Analyze_Short_Circuit --
4266 ---------------------------
4267
4268 procedure Analyze_Short_Circuit (N : Node_Id) is
4269 L : constant Node_Id := Left_Opnd (N);
4270 R : constant Node_Id := Right_Opnd (N);
4271 Ind : Interp_Index;
4272 It : Interp;
4273
4274 begin
4275 Analyze_Expression (L);
4276 Analyze_Expression (R);
4277 Set_Etype (N, Any_Type);
4278
4279 if not Is_Overloaded (L) then
996ae0b0
RK
4280 if Root_Type (Etype (L)) = Standard_Boolean
4281 and then Has_Compatible_Type (R, Etype (L))
4282 then
4283 Add_One_Interp (N, Etype (L), Etype (L));
4284 end if;
4285
4286 else
4287 Get_First_Interp (L, Ind, It);
996ae0b0
RK
4288 while Present (It.Typ) loop
4289 if Root_Type (It.Typ) = Standard_Boolean
4290 and then Has_Compatible_Type (R, It.Typ)
4291 then
4292 Add_One_Interp (N, It.Typ, It.Typ);
4293 end if;
4294
4295 Get_Next_Interp (Ind, It);
4296 end loop;
4297 end if;
4298
d469eabe
HK
4299 -- Here we have failed to find an interpretation. Clearly we know that
4300 -- it is not the case that both operands can have an interpretation of
4301 -- Boolean, but this is by far the most likely intended interpretation.
4302 -- So we simply resolve both operands as Booleans, and at least one of
4303 -- these resolutions will generate an error message, and we do not need
4304 -- to give another error message on the short circuit operation itself.
996ae0b0
RK
4305
4306 if Etype (N) = Any_Type then
4307 Resolve (L, Standard_Boolean);
4308 Resolve (R, Standard_Boolean);
4309 Set_Etype (N, Standard_Boolean);
4310 end if;
4311 end Analyze_Short_Circuit;
4312
4313 -------------------
4314 -- Analyze_Slice --
4315 -------------------
4316
4317 procedure Analyze_Slice (N : Node_Id) is
4318 P : constant Node_Id := Prefix (N);
4319 D : constant Node_Id := Discrete_Range (N);
4320 Array_Type : Entity_Id;
4321
4322 procedure Analyze_Overloaded_Slice;
4323 -- If the prefix is overloaded, select those interpretations that
4324 -- yield a one-dimensional array type.
4325
4c46b835
AC
4326 ------------------------------
4327 -- Analyze_Overloaded_Slice --
4328 ------------------------------
4329
996ae0b0
RK
4330 procedure Analyze_Overloaded_Slice is
4331 I : Interp_Index;
4332 It : Interp;
4333 Typ : Entity_Id;
4334
4335 begin
4336 Set_Etype (N, Any_Type);
996ae0b0 4337
4c46b835 4338 Get_First_Interp (P, I, It);
996ae0b0
RK
4339 while Present (It.Nam) loop
4340 Typ := It.Typ;
4341
4342 if Is_Access_Type (Typ) then
4343 Typ := Designated_Type (Typ);
fbf5a39b 4344 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
996ae0b0
RK
4345 end if;
4346
4347 if Is_Array_Type (Typ)
4348 and then Number_Dimensions (Typ) = 1
4349 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
4350 then
4351 Add_One_Interp (N, Typ, Typ);
4352 end if;
4353
4354 Get_Next_Interp (I, It);
4355 end loop;
4356
4357 if Etype (N) = Any_Type then
4358 Error_Msg_N ("expect array type in prefix of slice", N);
4359 end if;
4360 end Analyze_Overloaded_Slice;
4361
4362 -- Start of processing for Analyze_Slice
4363
4364 begin
2ba431e5 4365 Check_SPARK_Restriction ("slice is not allowed", N);
1d801f21 4366
523456db 4367 Analyze (P);
996ae0b0
RK
4368 Analyze (D);
4369
4370 if Is_Overloaded (P) then
4371 Analyze_Overloaded_Slice;
4372
4373 else
4374 Array_Type := Etype (P);
4375 Set_Etype (N, Any_Type);
4376
4377 if Is_Access_Type (Array_Type) then
4378 Array_Type := Designated_Type (Array_Type);
fbf5a39b 4379 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
996ae0b0
RK
4380 end if;
4381
4382 if not Is_Array_Type (Array_Type) then
4383 Wrong_Type (P, Any_Array);
4384
4385 elsif Number_Dimensions (Array_Type) > 1 then
4386 Error_Msg_N
4387 ("type is not one-dimensional array in slice prefix", N);
4388
4389 elsif not
4390 Has_Compatible_Type (D, Etype (First_Index (Array_Type)))
4391 then
4392 Wrong_Type (D, Etype (First_Index (Array_Type)));
4393
4394 else
4395 Set_Etype (N, Array_Type);
4396 end if;
4397 end if;
4398 end Analyze_Slice;
4399
4400 -----------------------------
4401 -- Analyze_Type_Conversion --
4402 -----------------------------
4403
4404 procedure Analyze_Type_Conversion (N : Node_Id) is
4405 Expr : constant Node_Id := Expression (N);
4406 T : Entity_Id;
4407
4408 begin
4409 -- If Conversion_OK is set, then the Etype is already set, and the
4410 -- only processing required is to analyze the expression. This is
4411 -- used to construct certain "illegal" conversions which are not
4412 -- allowed by Ada semantics, but can be handled OK by Gigi, see
4413 -- Sinfo for further details.
4414
4415 if Conversion_OK (N) then
4416 Analyze (Expr);
4417 return;
4418 end if;
4419
4420 -- Otherwise full type analysis is required, as well as some semantic
4421 -- checks to make sure the argument of the conversion is appropriate.
4422
4423 Find_Type (Subtype_Mark (N));
4424 T := Entity (Subtype_Mark (N));
4425 Set_Etype (N, T);
4426 Check_Fully_Declared (T, N);
4427 Analyze_Expression (Expr);
4428 Validate_Remote_Type_Type_Conversion (N);
5e8c8e44 4429
996ae0b0
RK
4430 -- Only remaining step is validity checks on the argument. These
4431 -- are skipped if the conversion does not come from the source.
4432
4433 if not Comes_From_Source (N) then
4434 return;
4435
b67a385c
ES
4436 -- If there was an error in a generic unit, no need to replicate the
4437 -- error message. Conversely, constant-folding in the generic may
4438 -- transform the argument of a conversion into a string literal, which
4439 -- is legal. Therefore the following tests are not performed in an
4440 -- instance.
4441
4442 elsif In_Instance then
4443 return;
4444
996ae0b0
RK
4445 elsif Nkind (Expr) = N_Null then
4446 Error_Msg_N ("argument of conversion cannot be null", N);
ed2233dc 4447 Error_Msg_N ("\use qualified expression instead", N);
996ae0b0
RK
4448 Set_Etype (N, Any_Type);
4449
4450 elsif Nkind (Expr) = N_Aggregate then
4451 Error_Msg_N ("argument of conversion cannot be aggregate", N);
ed2233dc 4452 Error_Msg_N ("\use qualified expression instead", N);
996ae0b0
RK
4453
4454 elsif Nkind (Expr) = N_Allocator then
4455 Error_Msg_N ("argument of conversion cannot be an allocator", N);
ed2233dc 4456 Error_Msg_N ("\use qualified expression instead", N);
996ae0b0
RK
4457
4458 elsif Nkind (Expr) = N_String_Literal then
4459 Error_Msg_N ("argument of conversion cannot be string literal", N);
ed2233dc 4460 Error_Msg_N ("\use qualified expression instead", N);
996ae0b0
RK
4461
4462 elsif Nkind (Expr) = N_Character_Literal then
0ab80019 4463 if Ada_Version = Ada_83 then
996ae0b0
RK
4464 Resolve (Expr, T);
4465 else
4466 Error_Msg_N ("argument of conversion cannot be character literal",
4467 N);
ed2233dc 4468 Error_Msg_N ("\use qualified expression instead", N);
996ae0b0
RK
4469 end if;
4470
4471 elsif Nkind (Expr) = N_Attribute_Reference
4472 and then
4473 (Attribute_Name (Expr) = Name_Access or else
4474 Attribute_Name (Expr) = Name_Unchecked_Access or else
4475 Attribute_Name (Expr) = Name_Unrestricted_Access)
4476 then
4477 Error_Msg_N ("argument of conversion cannot be access", N);
ed2233dc 4478 Error_Msg_N ("\use qualified expression instead", N);
996ae0b0 4479 end if;
996ae0b0
RK
4480 end Analyze_Type_Conversion;
4481
4482 ----------------------
4483 -- Analyze_Unary_Op --
4484 ----------------------
4485
4486 procedure Analyze_Unary_Op (N : Node_Id) is
4487 R : constant Node_Id := Right_Opnd (N);
4488 Op_Id : Entity_Id := Entity (N);
4489
4490 begin
4491 Set_Etype (N, Any_Type);
4492 Candidate_Type := Empty;
4493
4494 Analyze_Expression (R);
4495
4496 if Present (Op_Id) then
4497 if Ekind (Op_Id) = E_Operator then
4498 Find_Unary_Types (R, Op_Id, N);
4499 else
4500 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4501 end if;
4502
4503 else
4504 Op_Id := Get_Name_Entity_Id (Chars (N));
996ae0b0 4505 while Present (Op_Id) loop
996ae0b0
RK
4506 if Ekind (Op_Id) = E_Operator then
4507 if No (Next_Entity (First_Entity (Op_Id))) then
4508 Find_Unary_Types (R, Op_Id, N);
4509 end if;
4510
4511 elsif Is_Overloadable (Op_Id) then
4512 Analyze_User_Defined_Unary_Op (N, Op_Id);
4513 end if;
4514
4515 Op_Id := Homonym (Op_Id);
4516 end loop;
4517 end if;
4518
4519 Operator_Check (N);
4520 end Analyze_Unary_Op;
4521
4522 ----------------------------------
4523 -- Analyze_Unchecked_Expression --
4524 ----------------------------------
4525
4526 procedure Analyze_Unchecked_Expression (N : Node_Id) is
4527 begin
4528 Analyze (Expression (N), Suppress => All_Checks);
4529 Set_Etype (N, Etype (Expression (N)));
4530 Save_Interps (Expression (N), N);
4531 end Analyze_Unchecked_Expression;
4532
4533 ---------------------------------------
4534 -- Analyze_Unchecked_Type_Conversion --
4535 ---------------------------------------
4536
4537 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
4538 begin
4539 Find_Type (Subtype_Mark (N));
4540 Analyze_Expression (Expression (N));
4541 Set_Etype (N, Entity (Subtype_Mark (N)));
4542 end Analyze_Unchecked_Type_Conversion;
4543
4544 ------------------------------------
4545 -- Analyze_User_Defined_Binary_Op --
4546 ------------------------------------
4547
4548 procedure Analyze_User_Defined_Binary_Op
4549 (N : Node_Id;
4550 Op_Id : Entity_Id)
4551 is
4552 begin
4553 -- Only do analysis if the operator Comes_From_Source, since otherwise
4554 -- the operator was generated by the expander, and all such operators
4555 -- always refer to the operators in package Standard.
4556
4557 if Comes_From_Source (N) then
4558 declare
4559 F1 : constant Entity_Id := First_Formal (Op_Id);
4560 F2 : constant Entity_Id := Next_Formal (F1);
4561
4562 begin
4563 -- Verify that Op_Id is a visible binary function. Note that since
4564 -- we know Op_Id is overloaded, potentially use visible means use
4565 -- visible for sure (RM 9.4(11)).
4566
4567 if Ekind (Op_Id) = E_Function
4568 and then Present (F2)
4569 and then (Is_Immediately_Visible (Op_Id)
4570 or else Is_Potentially_Use_Visible (Op_Id))
4571 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
4572 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
4573 then
4574 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4575
7340e432
AC
4576 -- If the left operand is overloaded, indicate that the
4577 -- current type is a viable candidate. This is redundant
4578 -- in most cases, but for equality and comparison operators
4579 -- where the context does not impose a type on the operands,
4580 -- setting the proper type is necessary to avoid subsequent
4581 -- ambiguities during resolution, when both user-defined and
4582 -- predefined operators may be candidates.
4583
4584 if Is_Overloaded (Left_Opnd (N)) then
4585 Set_Etype (Left_Opnd (N), Etype (F1));
4586 end if;
4587
996ae0b0
RK
4588 if Debug_Flag_E then
4589 Write_Str ("user defined operator ");
4590 Write_Name (Chars (Op_Id));
4591 Write_Str (" on node ");
4592 Write_Int (Int (N));
4593 Write_Eol;
4594 end if;
4595 end if;
4596 end;
4597 end if;
4598 end Analyze_User_Defined_Binary_Op;
4599
4600 -----------------------------------
4601 -- Analyze_User_Defined_Unary_Op --
4602 -----------------------------------
4603
4604 procedure Analyze_User_Defined_Unary_Op
4605 (N : Node_Id;
4606 Op_Id : Entity_Id)
4607 is
4608 begin
4609 -- Only do analysis if the operator Comes_From_Source, since otherwise
4610 -- the operator was generated by the expander, and all such operators
4611 -- always refer to the operators in package Standard.
4612
4613 if Comes_From_Source (N) then
4614 declare
4615 F : constant Entity_Id := First_Formal (Op_Id);
4616
4617 begin
4618 -- Verify that Op_Id is a visible unary function. Note that since
4619 -- we know Op_Id is overloaded, potentially use visible means use
4620 -- visible for sure (RM 9.4(11)).
4621
4622 if Ekind (Op_Id) = E_Function
4623 and then No (Next_Formal (F))
4624 and then (Is_Immediately_Visible (Op_Id)
4625 or else Is_Potentially_Use_Visible (Op_Id))
4626 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
4627 then
4628 Add_One_Interp (N, Op_Id, Etype (Op_Id));
4629 end if;
4630 end;
4631 end if;
4632 end Analyze_User_Defined_Unary_Op;
4633
4634 ---------------------------
4635 -- Check_Arithmetic_Pair --
4636 ---------------------------
4637
4638 procedure Check_Arithmetic_Pair
4639 (T1, T2 : Entity_Id;
4640 Op_Id : Entity_Id;
4641 N : Node_Id)
4642 is
401093c1 4643 Op_Name : constant Name_Id := Chars (Op_Id);
996ae0b0 4644
da709d08
AC
4645 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
4646 -- Check whether the fixed-point type Typ has a user-defined operator
4647 -- (multiplication or division) that should hide the corresponding
4648 -- predefined operator. Used to implement Ada 2005 AI-264, to make
4649 -- such operators more visible and therefore useful.
4650
50cff367
GD
4651 -- If the name of the operation is an expanded name with prefix
4652 -- Standard, the predefined universal fixed operator is available,
4653 -- as specified by AI-420 (RM 4.5.5 (19.1/2)).
4654
996ae0b0
RK
4655 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
4656 -- Get specific type (i.e. non-universal type if there is one)
4657
da709d08
AC
4658 ------------------
4659 -- Has_Fixed_Op --
4660 ------------------
4661
4662 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
401093c1 4663 Bas : constant Entity_Id := Base_Type (Typ);
da709d08
AC
4664 Ent : Entity_Id;
4665 F1 : Entity_Id;
4666 F2 : Entity_Id;
4667
4668 begin
50cff367
GD
4669 -- If the universal_fixed operation is given explicitly the rule
4670 -- concerning primitive operations of the type do not apply.
4671
4672 if Nkind (N) = N_Function_Call
4673 and then Nkind (Name (N)) = N_Expanded_Name
4674 and then Entity (Prefix (Name (N))) = Standard_Standard
4675 then
4676 return False;
4677 end if;
4678
da709d08
AC
4679 -- The operation is treated as primitive if it is declared in the
4680 -- same scope as the type, and therefore on the same entity chain.
4681
4682 Ent := Next_Entity (Typ);
4683 while Present (Ent) loop
4684 if Chars (Ent) = Chars (Op) then
4685 F1 := First_Formal (Ent);
4686 F2 := Next_Formal (F1);
4687
4688 -- The operation counts as primitive if either operand or
401093c1
ES
4689 -- result are of the given base type, and both operands are
4690 -- fixed point types.
da709d08 4691
401093c1 4692 if (Base_Type (Etype (F1)) = Bas
da709d08
AC
4693 and then Is_Fixed_Point_Type (Etype (F2)))
4694
4695 or else
401093c1 4696 (Base_Type (Etype (F2)) = Bas
da709d08
AC
4697 and then Is_Fixed_Point_Type (Etype (F1)))
4698
4699 or else
401093c1 4700 (Base_Type (Etype (Ent)) = Bas
da709d08
AC
4701 and then Is_Fixed_Point_Type (Etype (F1))
4702 and then Is_Fixed_Point_Type (Etype (F2)))
4703 then
4704 return True;
4705 end if;
4706 end if;
4707
4708 Next_Entity (Ent);
4709 end loop;
4710
4711 return False;
4712 end Has_Fixed_Op;
4713
4c46b835
AC
4714 -------------------
4715 -- Specific_Type --
4716 -------------------
4717
996ae0b0
RK
4718 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
4719 begin
4720 if T1 = Universal_Integer or else T1 = Universal_Real then
4721 return Base_Type (T2);
4722 else
4723 return Base_Type (T1);
4724 end if;
4725 end Specific_Type;
4726
4727 -- Start of processing for Check_Arithmetic_Pair
4728
4729 begin
4730 if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
4731
4732 if Is_Numeric_Type (T1)
4733 and then Is_Numeric_Type (T2)
b4592168
GD
4734 and then (Covers (T1 => T1, T2 => T2)
4735 or else
4736 Covers (T1 => T2, T2 => T1))
996ae0b0
RK
4737 then
4738 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4739 end if;
4740
4741 elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
4742
4743 if Is_Fixed_Point_Type (T1)
4744 and then (Is_Fixed_Point_Type (T2)
4745 or else T2 = Universal_Real)
4746 then
4747 -- If Treat_Fixed_As_Integer is set then the Etype is already set
4748 -- and no further processing is required (this is the case of an
4749 -- operator constructed by Exp_Fixd for a fixed point operation)
4750 -- Otherwise add one interpretation with universal fixed result
4751 -- If the operator is given in functional notation, it comes
4752 -- from source and Fixed_As_Integer cannot apply.
4753
da709d08
AC
4754 if (Nkind (N) not in N_Op
4755 or else not Treat_Fixed_As_Integer (N))
4756 and then
401093c1 4757 (not Has_Fixed_Op (T1, Op_Id)
da709d08 4758 or else Nkind (Parent (N)) = N_Type_Conversion)
fbf5a39b 4759 then
996ae0b0
RK
4760 Add_One_Interp (N, Op_Id, Universal_Fixed);
4761 end if;
4762
4763 elsif Is_Fixed_Point_Type (T2)
4764 and then (Nkind (N) not in N_Op
4765 or else not Treat_Fixed_As_Integer (N))
4766 and then T1 = Universal_Real
da709d08 4767 and then
401093c1 4768 (not Has_Fixed_Op (T1, Op_Id)
da709d08 4769 or else Nkind (Parent (N)) = N_Type_Conversion)
996ae0b0
RK
4770 then
4771 Add_One_Interp (N, Op_Id, Universal_Fixed);
4772
4773 elsif Is_Numeric_Type (T1)
4774 and then Is_Numeric_Type (T2)
b4592168
GD
4775 and then (Covers (T1 => T1, T2 => T2)
4776 or else
4777 Covers (T1 => T2, T2 => T1))
996ae0b0
RK
4778 then
4779 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4780
4781 elsif Is_Fixed_Point_Type (T1)
4782 and then (Base_Type (T2) = Base_Type (Standard_Integer)
4783 or else T2 = Universal_Integer)
4784 then
4785 Add_One_Interp (N, Op_Id, T1);
4786
4787 elsif T2 = Universal_Real
4788 and then Base_Type (T1) = Base_Type (Standard_Integer)
4789 and then Op_Name = Name_Op_Multiply
4790 then
4791 Add_One_Interp (N, Op_Id, Any_Fixed);
4792
4793 elsif T1 = Universal_Real
4794 and then Base_Type (T2) = Base_Type (Standard_Integer)
4795 then
4796 Add_One_Interp (N, Op_Id, Any_Fixed);
4797
4798 elsif Is_Fixed_Point_Type (T2)
4799 and then (Base_Type (T1) = Base_Type (Standard_Integer)
4800 or else T1 = Universal_Integer)
4801 and then Op_Name = Name_Op_Multiply
4802 then
4803 Add_One_Interp (N, Op_Id, T2);
4804
4805 elsif T1 = Universal_Real and then T2 = Universal_Integer then
4806 Add_One_Interp (N, Op_Id, T1);
4807
4808 elsif T2 = Universal_Real
4809 and then T1 = Universal_Integer
4810 and then Op_Name = Name_Op_Multiply
4811 then
4812 Add_One_Interp (N, Op_Id, T2);
4813 end if;
4814
4815 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
4816
4817 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
4818 -- set does not require any special processing, since the Etype is
4819 -- already set (case of operation constructed by Exp_Fixed).
4820
4821 if Is_Integer_Type (T1)
b4592168
GD
4822 and then (Covers (T1 => T1, T2 => T2)
4823 or else
4824 Covers (T1 => T2, T2 => T1))
996ae0b0
RK
4825 then
4826 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4827 end if;
4828
4829 elsif Op_Name = Name_Op_Expon then
996ae0b0
RK
4830 if Is_Numeric_Type (T1)
4831 and then not Is_Fixed_Point_Type (T1)
4832 and then (Base_Type (T2) = Base_Type (Standard_Integer)
4833 or else T2 = Universal_Integer)
4834 then
4835 Add_One_Interp (N, Op_Id, Base_Type (T1));
4836 end if;
4837
4838 else pragma Assert (Nkind (N) in N_Op_Shift);
4839
4840 -- If not one of the predefined operators, the node may be one
4841 -- of the intrinsic functions. Its kind is always specific, and
4842 -- we can use it directly, rather than the name of the operation.
4843
4844 if Is_Integer_Type (T1)
4845 and then (Base_Type (T2) = Base_Type (Standard_Integer)
4846 or else T2 = Universal_Integer)
4847 then
4848 Add_One_Interp (N, Op_Id, Base_Type (T1));
4849 end if;
4850 end if;
4851 end Check_Arithmetic_Pair;
4852
4853 -------------------------------
4854 -- Check_Misspelled_Selector --
4855 -------------------------------
4856
4857 procedure Check_Misspelled_Selector
4858 (Prefix : Entity_Id;
4859 Sel : Node_Id)
4860 is
4861 Max_Suggestions : constant := 2;
4862 Nr_Of_Suggestions : Natural := 0;
4863
4864 Suggestion_1 : Entity_Id := Empty;
4865 Suggestion_2 : Entity_Id := Empty;
4866
4867 Comp : Entity_Id;
4868
4869 begin
4870 -- All the components of the prefix of selector Sel are matched
4871 -- against Sel and a count is maintained of possible misspellings.
4872 -- When at the end of the analysis there are one or two (not more!)
4873 -- possible misspellings, these misspellings will be suggested as
4874 -- possible correction.
4875
4c46b835
AC
4876 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
4877
996ae0b0 4878 -- Concurrent types should be handled as well ???
4c46b835 4879
996ae0b0
RK
4880 return;
4881 end if;
4882
d469eabe
HK
4883 Comp := First_Entity (Prefix);
4884 while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
4885 if Is_Visible_Component (Comp) then
4886 if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
4887 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
4888
4889 case Nr_Of_Suggestions is
4890 when 1 => Suggestion_1 := Comp;
4891 when 2 => Suggestion_2 := Comp;
4892 when others => exit;
4893 end case;
996ae0b0 4894 end if;
d469eabe 4895 end if;
996ae0b0 4896
d469eabe
HK
4897 Comp := Next_Entity (Comp);
4898 end loop;
996ae0b0 4899
d469eabe 4900 -- Report at most two suggestions
996ae0b0 4901
d469eabe 4902 if Nr_Of_Suggestions = 1 then
4e7a4f6e 4903 Error_Msg_NE -- CODEFIX
d469eabe 4904 ("\possible misspelling of&", Sel, Suggestion_1);
996ae0b0 4905
d469eabe
HK
4906 elsif Nr_Of_Suggestions = 2 then
4907 Error_Msg_Node_2 := Suggestion_2;
4e7a4f6e 4908 Error_Msg_NE -- CODEFIX
d469eabe
HK
4909 ("\possible misspelling of& or&", Sel, Suggestion_1);
4910 end if;
996ae0b0
RK
4911 end Check_Misspelled_Selector;
4912
4913 ----------------------
4914 -- Defined_In_Scope --
4915 ----------------------
4916
4917 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
4918 is
4919 S1 : constant Entity_Id := Scope (Base_Type (T));
996ae0b0
RK
4920 begin
4921 return S1 = S
4922 or else (S1 = System_Aux_Id and then S = Scope (S1));
4923 end Defined_In_Scope;
4924
4925 -------------------
4926 -- Diagnose_Call --
4927 -------------------
4928
4929 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
fbf5a39b
AC
4930 Actual : Node_Id;
4931 X : Interp_Index;
4932 It : Interp;
fbf5a39b
AC
4933 Err_Mode : Boolean;
4934 New_Nam : Node_Id;
4935 Void_Interp_Seen : Boolean := False;
996ae0b0 4936
24657705
HK
4937 Success : Boolean;
4938 pragma Warnings (Off, Boolean);
4939
996ae0b0 4940 begin
0791fbe9 4941 if Ada_Version >= Ada_2005 then
996ae0b0 4942 Actual := First_Actual (N);
996ae0b0 4943 while Present (Actual) loop
0ab80019
AC
4944
4945 -- Ada 2005 (AI-50217): Post an error in case of premature
4946 -- usage of an entity from the limited view.
19f0526a 4947
996ae0b0
RK
4948 if not Analyzed (Etype (Actual))
4949 and then From_With_Type (Etype (Actual))
4950 then
4951 Error_Msg_Qual_Level := 1;
ed2233dc 4952 Error_Msg_NE
996ae0b0
RK
4953 ("missing with_clause for scope of imported type&",
4954 Actual, Etype (Actual));
4955 Error_Msg_Qual_Level := 0;
4956 end if;
4957
4958 Next_Actual (Actual);
4959 end loop;
4960 end if;
4961
fbf5a39b
AC
4962 -- Analyze each candidate call again, with full error reporting
4963 -- for each.
4964
4965 Error_Msg_N
4966 ("no candidate interpretations match the actuals:!", Nam);
4967 Err_Mode := All_Errors_Mode;
4968 All_Errors_Mode := True;
4969
4970 -- If this is a call to an operation of a concurrent type,
4971 -- the failed interpretations have been removed from the
4972 -- name. Recover them to provide full diagnostics.
4973
4974 if Nkind (Parent (Nam)) = N_Selected_Component then
4975 Set_Entity (Nam, Empty);
4976 New_Nam := New_Copy_Tree (Parent (Nam));
4977 Set_Is_Overloaded (New_Nam, False);
4978 Set_Is_Overloaded (Selector_Name (New_Nam), False);
4979 Set_Parent (New_Nam, Parent (Parent (Nam)));
4980 Analyze_Selected_Component (New_Nam);
4981 Get_First_Interp (Selector_Name (New_Nam), X, It);
4982 else
996ae0b0 4983 Get_First_Interp (Nam, X, It);
fbf5a39b 4984 end if;
996ae0b0 4985
fbf5a39b
AC
4986 while Present (It.Nam) loop
4987 if Etype (It.Nam) = Standard_Void_Type then
4988 Void_Interp_Seen := True;
996ae0b0 4989 end if;
fbf5a39b
AC
4990
4991 Analyze_One_Call (N, It.Nam, True, Success);
4992 Get_Next_Interp (X, It);
4993 end loop;
996ae0b0
RK
4994
4995 if Nkind (N) = N_Function_Call then
4996 Get_First_Interp (Nam, X, It);
996ae0b0 4997 while Present (It.Nam) loop
bce79204 4998 if Ekind_In (It.Nam, E_Function, E_Operator) then
996ae0b0
RK
4999 return;
5000 else
5001 Get_Next_Interp (X, It);
5002 end if;
5003 end loop;
5004
5005 -- If all interpretations are procedures, this deserves a
5006 -- more precise message. Ditto if this appears as the prefix
5007 -- of a selected component, which may be a lexical error.
5008
4c46b835
AC
5009 Error_Msg_N
5010 ("\context requires function call, found procedure name", Nam);
996ae0b0
RK
5011
5012 if Nkind (Parent (N)) = N_Selected_Component
5013 and then N = Prefix (Parent (N))
5014 then
4e7a4f6e
AC
5015 Error_Msg_N -- CODEFIX
5016 ("\period should probably be semicolon", Parent (N));
996ae0b0 5017 end if;
fbf5a39b
AC
5018
5019 elsif Nkind (N) = N_Procedure_Call_Statement
5020 and then not Void_Interp_Seen
5021 then
5022 Error_Msg_N (
5023 "\function name found in procedure call", Nam);
996ae0b0 5024 end if;
fbf5a39b
AC
5025
5026 All_Errors_Mode := Err_Mode;
996ae0b0
RK
5027 end Diagnose_Call;
5028
5029 ---------------------------
5030 -- Find_Arithmetic_Types --
5031 ---------------------------
5032
5033 procedure Find_Arithmetic_Types
5034 (L, R : Node_Id;
5035 Op_Id : Entity_Id;
5036 N : Node_Id)
5037 is
4c46b835
AC
5038 Index1 : Interp_Index;
5039 Index2 : Interp_Index;
5040 It1 : Interp;
5041 It2 : Interp;
996ae0b0
RK
5042
5043 procedure Check_Right_Argument (T : Entity_Id);
5044 -- Check right operand of operator
5045
4c46b835
AC
5046 --------------------------
5047 -- Check_Right_Argument --
5048 --------------------------
5049
996ae0b0
RK
5050 procedure Check_Right_Argument (T : Entity_Id) is
5051 begin
5052 if not Is_Overloaded (R) then
5053 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
5054 else
5055 Get_First_Interp (R, Index2, It2);
996ae0b0
RK
5056 while Present (It2.Typ) loop
5057 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
5058 Get_Next_Interp (Index2, It2);
5059 end loop;
5060 end if;
5061 end Check_Right_Argument;
5062
d8221f45 5063 -- Start of processing for Find_Arithmetic_Types
996ae0b0
RK
5064
5065 begin
5066 if not Is_Overloaded (L) then
5067 Check_Right_Argument (Etype (L));
5068
5069 else
5070 Get_First_Interp (L, Index1, It1);
996ae0b0
RK
5071 while Present (It1.Typ) loop
5072 Check_Right_Argument (It1.Typ);
5073 Get_Next_Interp (Index1, It1);
5074 end loop;
5075 end if;
5076
5077 end Find_Arithmetic_Types;
5078
5079 ------------------------
5080 -- Find_Boolean_Types --
5081 ------------------------
5082
5083 procedure Find_Boolean_Types
5084 (L, R : Node_Id;
5085 Op_Id : Entity_Id;
5086 N : Node_Id)
5087 is
5088 Index : Interp_Index;
5089 It : Interp;
5090
5091 procedure Check_Numeric_Argument (T : Entity_Id);
5092 -- Special case for logical operations one of whose operands is an
5093 -- integer literal. If both are literal the result is any modular type.
5094
4c46b835
AC
5095 ----------------------------
5096 -- Check_Numeric_Argument --
5097 ----------------------------
5098
996ae0b0
RK
5099 procedure Check_Numeric_Argument (T : Entity_Id) is
5100 begin
5101 if T = Universal_Integer then
5102 Add_One_Interp (N, Op_Id, Any_Modular);
5103
5104 elsif Is_Modular_Integer_Type (T) then
5105 Add_One_Interp (N, Op_Id, T);
5106 end if;
5107 end Check_Numeric_Argument;
5108
5109 -- Start of processing for Find_Boolean_Types
5110
5111 begin
5112 if not Is_Overloaded (L) then
996ae0b0
RK
5113 if Etype (L) = Universal_Integer
5114 or else Etype (L) = Any_Modular
5115 then
5116 if not Is_Overloaded (R) then
5117 Check_Numeric_Argument (Etype (R));
5118
5119 else
5120 Get_First_Interp (R, Index, It);
996ae0b0
RK
5121 while Present (It.Typ) loop
5122 Check_Numeric_Argument (It.Typ);
996ae0b0
RK
5123 Get_Next_Interp (Index, It);
5124 end loop;
5125 end if;
5126
69e6a03e
ES
5127 -- If operands are aggregates, we must assume that they may be
5128 -- boolean arrays, and leave disambiguation for the second pass.
5129 -- If only one is an aggregate, verify that the other one has an
5130 -- interpretation as a boolean array
5131
5132 elsif Nkind (L) = N_Aggregate then
5133 if Nkind (R) = N_Aggregate then
5134 Add_One_Interp (N, Op_Id, Etype (L));
5135
5136 elsif not Is_Overloaded (R) then
5137 if Valid_Boolean_Arg (Etype (R)) then
5138 Add_One_Interp (N, Op_Id, Etype (R));
5139 end if;
5140
5141 else
5142 Get_First_Interp (R, Index, It);
5143 while Present (It.Typ) loop
5144 if Valid_Boolean_Arg (It.Typ) then
5145 Add_One_Interp (N, Op_Id, It.Typ);
5146 end if;
5147
5148 Get_Next_Interp (Index, It);
5149 end loop;
5150 end if;
5151
996ae0b0
RK
5152 elsif Valid_Boolean_Arg (Etype (L))
5153 and then Has_Compatible_Type (R, Etype (L))
5154 then
5155 Add_One_Interp (N, Op_Id, Etype (L));
5156 end if;
5157
5158 else
5159 Get_First_Interp (L, Index, It);
996ae0b0
RK
5160 while Present (It.Typ) loop
5161 if Valid_Boolean_Arg (It.Typ)
5162 and then Has_Compatible_Type (R, It.Typ)
5163 then
5164 Add_One_Interp (N, Op_Id, It.Typ);
5165 end if;
5166
5167 Get_Next_Interp (Index, It);
5168 end loop;
5169 end if;
5170 end Find_Boolean_Types;
5171
5172 ---------------------------
5173 -- Find_Comparison_Types --
5174 ---------------------------
5175
5176 procedure Find_Comparison_Types
5177 (L, R : Node_Id;
5178 Op_Id : Entity_Id;
5179 N : Node_Id)
5180 is
5181 Index : Interp_Index;
5182 It : Interp;
5183 Found : Boolean := False;
5184 I_F : Interp_Index;
5185 T_F : Entity_Id;
5186 Scop : Entity_Id := Empty;
5187
5188 procedure Try_One_Interp (T1 : Entity_Id);
5189 -- Routine to try one proposed interpretation. Note that the context
5190 -- of the operator plays no role in resolving the arguments, so that
5191 -- if there is more than one interpretation of the operands that is
5192 -- compatible with comparison, the operation is ambiguous.
5193
4c46b835
AC
5194 --------------------
5195 -- Try_One_Interp --
5196 --------------------
5197
996ae0b0
RK
5198 procedure Try_One_Interp (T1 : Entity_Id) is
5199 begin
5200
5201 -- If the operator is an expanded name, then the type of the operand
5202 -- must be defined in the corresponding scope. If the type is
5203 -- universal, the context will impose the correct type.
5204
5205 if Present (Scop)
5206 and then not Defined_In_Scope (T1, Scop)
5207 and then T1 /= Universal_Integer
5208 and then T1 /= Universal_Real
5209 and then T1 /= Any_String
5210 and then T1 /= Any_Composite
5211 then
5212 return;
5213 end if;
5214
5215 if Valid_Comparison_Arg (T1)
5216 and then Has_Compatible_Type (R, T1)
5217 then
5218 if Found
5219 and then Base_Type (T1) /= Base_Type (T_F)
5220 then
5221 It := Disambiguate (L, I_F, Index, Any_Type);
5222
5223 if It = No_Interp then
5224 Ambiguous_Operands (N);
5225 Set_Etype (L, Any_Type);
5226 return;
5227
5228 else
5229 T_F := It.Typ;
5230 end if;
5231
5232 else
5233 Found := True;
5234 T_F := T1;
5235 I_F := Index;
5236 end if;
5237
5238 Set_Etype (L, T_F);
5239 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
5240
5241 end if;
5242 end Try_One_Interp;
5243
d8221f45 5244 -- Start of processing for Find_Comparison_Types
996ae0b0
RK
5245
5246 begin
fbf5a39b
AC
5247 -- If left operand is aggregate, the right operand has to
5248 -- provide a usable type for it.
5249
5250 if Nkind (L) = N_Aggregate
5251 and then Nkind (R) /= N_Aggregate
5252 then
b4592168 5253 Find_Comparison_Types (L => R, R => L, Op_Id => Op_Id, N => N);
fbf5a39b
AC
5254 return;
5255 end if;
996ae0b0
RK
5256
5257 if Nkind (N) = N_Function_Call
5258 and then Nkind (Name (N)) = N_Expanded_Name
5259 then
5260 Scop := Entity (Prefix (Name (N)));
5261
5262 -- The prefix may be a package renaming, and the subsequent test
5263 -- requires the original package.
5264
5265 if Ekind (Scop) = E_Package
5266 and then Present (Renamed_Entity (Scop))
5267 then
5268 Scop := Renamed_Entity (Scop);
5269 Set_Entity (Prefix (Name (N)), Scop);
5270 end if;
5271 end if;
5272
5273 if not Is_Overloaded (L) then
5274 Try_One_Interp (Etype (L));
5275
5276 else
5277 Get_First_Interp (L, Index, It);
996ae0b0
RK
5278 while Present (It.Typ) loop
5279 Try_One_Interp (It.Typ);
5280 Get_Next_Interp (Index, It);
5281 end loop;
5282 end if;
5283 end Find_Comparison_Types;
5284
5285 ----------------------------------------
5286 -- Find_Non_Universal_Interpretations --
5287 ----------------------------------------
5288
5289 procedure Find_Non_Universal_Interpretations
5290 (N : Node_Id;
5291 R : Node_Id;
5292 Op_Id : Entity_Id;
5293 T1 : Entity_Id)
5294 is
5295 Index : Interp_Index;
4c46b835 5296 It : Interp;
996ae0b0
RK
5297
5298 begin
5299 if T1 = Universal_Integer
5300 or else T1 = Universal_Real
5301 then
5302 if not Is_Overloaded (R) then
5303 Add_One_Interp
5304 (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
5305 else
5306 Get_First_Interp (R, Index, It);
996ae0b0
RK
5307 while Present (It.Typ) loop
5308 if Covers (It.Typ, T1) then
5309 Add_One_Interp
5310 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
5311 end if;
5312
5313 Get_Next_Interp (Index, It);
5314 end loop;
5315 end if;
5316 else
5317 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
5318 end if;
5319 end Find_Non_Universal_Interpretations;
5320
5321 ------------------------------
5322 -- Find_Concatenation_Types --
5323 ------------------------------
5324
5325 procedure Find_Concatenation_Types
5326 (L, R : Node_Id;
5327 Op_Id : Entity_Id;
5328 N : Node_Id)
5329 is
5330 Op_Type : constant Entity_Id := Etype (Op_Id);
5331
5332 begin
5333 if Is_Array_Type (Op_Type)
5334 and then not Is_Limited_Type (Op_Type)
5335
5336 and then (Has_Compatible_Type (L, Op_Type)
5337 or else
5338 Has_Compatible_Type (L, Component_Type (Op_Type)))
5339
5340 and then (Has_Compatible_Type (R, Op_Type)
5341 or else
5342 Has_Compatible_Type (R, Component_Type (Op_Type)))
5343 then
5344 Add_One_Interp (N, Op_Id, Op_Type);
5345 end if;
5346 end Find_Concatenation_Types;
5347
5348 -------------------------
5349 -- Find_Equality_Types --
5350 -------------------------
5351
5352 procedure Find_Equality_Types
5353 (L, R : Node_Id;
5354 Op_Id : Entity_Id;
5355 N : Node_Id)
5356 is
5357 Index : Interp_Index;
5358 It : Interp;
5359 Found : Boolean := False;
5360 I_F : Interp_Index;
5361 T_F : Entity_Id;
5362 Scop : Entity_Id := Empty;
5363
5364 procedure Try_One_Interp (T1 : Entity_Id);
a8e65aa5
AC
5365 -- The context of the equality operator plays no role in resolving the
5366 -- arguments, so that if there is more than one interpretation of the
5367 -- operands that is compatible with equality, the construct is ambiguous
5368 -- and an error can be emitted now, after trying to disambiguate, i.e.
5369 -- applying preference rules.
996ae0b0 5370
4c46b835
AC
5371 --------------------
5372 -- Try_One_Interp --
5373 --------------------
5374
996ae0b0 5375 procedure Try_One_Interp (T1 : Entity_Id) is
a8e65aa5
AC
5376 Bas : constant Entity_Id := Base_Type (T1);
5377
996ae0b0 5378 begin
996ae0b0
RK
5379 -- If the operator is an expanded name, then the type of the operand
5380 -- must be defined in the corresponding scope. If the type is
5381 -- universal, the context will impose the correct type. An anonymous
5382 -- type for a 'Access reference is also universal in this sense, as
5383 -- the actual type is obtained from context.
fe45e59e
ES
5384 -- In Ada 2005, the equality operator for anonymous access types
5385 -- is declared in Standard, and preference rules apply to it.
996ae0b0 5386
fe45e59e
ES
5387 if Present (Scop) then
5388 if Defined_In_Scope (T1, Scop)
5389 or else T1 = Universal_Integer
5390 or else T1 = Universal_Real
5391 or else T1 = Any_Access
5392 or else T1 = Any_String
5393 or else T1 = Any_Composite
5394 or else (Ekind (T1) = E_Access_Subprogram_Type
a8e65aa5 5395 and then not Comes_From_Source (T1))
fe45e59e
ES
5396 then
5397 null;
5398
5399 elsif Ekind (T1) = E_Anonymous_Access_Type
5400 and then Scop = Standard_Standard
5401 then
5402 null;
5403
5404 else
5405 -- The scope does not contain an operator for the type
5406
5407 return;
5408 end if;
a8e65aa5
AC
5409
5410 -- If we have infix notation, the operator must be usable.
5411 -- Within an instance, if the type is already established we
5412 -- know it is correct.
5413 -- In Ada 2005, the equality on anonymous access types is declared
5414 -- in Standard, and is always visible.
5415
5416 elsif In_Open_Scopes (Scope (Bas))
5417 or else Is_Potentially_Use_Visible (Bas)
5418 or else In_Use (Bas)
5419 or else (In_Use (Scope (Bas))
5420 and then not Is_Hidden (Bas))
5421 or else (In_Instance
5422 and then First_Subtype (T1) = First_Subtype (Etype (R)))
5423 or else Ekind (T1) = E_Anonymous_Access_Type
5424 then
5425 null;
5426
5427 else
308e6f3a 5428 -- Save candidate type for subsequent error message, if any
a8e65aa5
AC
5429
5430 if not Is_Limited_Type (T1) then
5431 Candidate_Type := T1;
5432 end if;
5433
5434 return;
996ae0b0
RK
5435 end if;
5436
0ab80019
AC
5437 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
5438 -- Do not allow anonymous access types in equality operators.
6e937c1c 5439
0791fbe9 5440 if Ada_Version < Ada_2005
6e937c1c
AC
5441 and then Ekind (T1) = E_Anonymous_Access_Type
5442 then
5443 return;
5444 end if;
5445
996ae0b0
RK
5446 if T1 /= Standard_Void_Type
5447 and then not Is_Limited_Type (T1)
5448 and then not Is_Limited_Composite (T1)
996ae0b0
RK
5449 and then Has_Compatible_Type (R, T1)
5450 then
5451 if Found
5452 and then Base_Type (T1) /= Base_Type (T_F)
5453 then
5454 It := Disambiguate (L, I_F, Index, Any_Type);
5455
5456 if It = No_Interp then
5457 Ambiguous_Operands (N);
5458 Set_Etype (L, Any_Type);
5459 return;
5460
5461 else
5462 T_F := It.Typ;
5463 end if;
5464
5465 else
5466 Found := True;
5467 T_F := T1;
5468 I_F := Index;
5469 end if;
5470
5471 if not Analyzed (L) then
5472 Set_Etype (L, T_F);
5473 end if;
5474
5475 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
5476
6e73e3ab 5477 -- Case of operator was not visible, Etype still set to Any_Type
996ae0b0 5478
6e73e3ab 5479 if Etype (N) = Any_Type then
996ae0b0
RK
5480 Found := False;
5481 end if;
fe45e59e
ES
5482
5483 elsif Scop = Standard_Standard
5484 and then Ekind (T1) = E_Anonymous_Access_Type
5485 then
5486 Found := True;
996ae0b0
RK
5487 end if;
5488 end Try_One_Interp;
5489
5490 -- Start of processing for Find_Equality_Types
5491
5492 begin
fbf5a39b
AC
5493 -- If left operand is aggregate, the right operand has to
5494 -- provide a usable type for it.
5495
5496 if Nkind (L) = N_Aggregate
5497 and then Nkind (R) /= N_Aggregate
5498 then
b4592168 5499 Find_Equality_Types (L => R, R => L, Op_Id => Op_Id, N => N);
fbf5a39b
AC
5500 return;
5501 end if;
996ae0b0
RK
5502
5503 if Nkind (N) = N_Function_Call
5504 and then Nkind (Name (N)) = N_Expanded_Name
5505 then
5506 Scop := Entity (Prefix (Name (N)));
5507
5508 -- The prefix may be a package renaming, and the subsequent test
5509 -- requires the original package.
5510
5511 if Ekind (Scop) = E_Package
5512 and then Present (Renamed_Entity (Scop))
5513 then
5514 Scop := Renamed_Entity (Scop);
5515 Set_Entity (Prefix (Name (N)), Scop);
5516 end if;
5517 end if;
5518
5519 if not Is_Overloaded (L) then
5520 Try_One_Interp (Etype (L));
996ae0b0 5521
4c46b835 5522 else
996ae0b0 5523 Get_First_Interp (L, Index, It);
996ae0b0
RK
5524 while Present (It.Typ) loop
5525 Try_One_Interp (It.Typ);
5526 Get_Next_Interp (Index, It);
5527 end loop;
5528 end if;
5529 end Find_Equality_Types;
5530
5531 -------------------------
5532 -- Find_Negation_Types --
5533 -------------------------
5534
5535 procedure Find_Negation_Types
5536 (R : Node_Id;
5537 Op_Id : Entity_Id;
5538 N : Node_Id)
5539 is
5540 Index : Interp_Index;
5541 It : Interp;
5542
5543 begin
5544 if not Is_Overloaded (R) then
996ae0b0
RK
5545 if Etype (R) = Universal_Integer then
5546 Add_One_Interp (N, Op_Id, Any_Modular);
996ae0b0
RK
5547 elsif Valid_Boolean_Arg (Etype (R)) then
5548 Add_One_Interp (N, Op_Id, Etype (R));
5549 end if;
5550
5551 else
5552 Get_First_Interp (R, Index, It);
996ae0b0
RK
5553 while Present (It.Typ) loop
5554 if Valid_Boolean_Arg (It.Typ) then
5555 Add_One_Interp (N, Op_Id, It.Typ);
5556 end if;
5557
5558 Get_Next_Interp (Index, It);
5559 end loop;
5560 end if;
5561 end Find_Negation_Types;
5562
d469eabe
HK
5563 ------------------------------
5564 -- Find_Primitive_Operation --
5565 ------------------------------
5566
5567 function Find_Primitive_Operation (N : Node_Id) return Boolean is
5568 Obj : constant Node_Id := Prefix (N);
5569 Op : constant Node_Id := Selector_Name (N);
5570
5571 Prim : Elmt_Id;
5572 Prims : Elist_Id;
5573 Typ : Entity_Id;
5574
5575 begin
5576 Set_Etype (Op, Any_Type);
5577
5578 if Is_Access_Type (Etype (Obj)) then
5579 Typ := Designated_Type (Etype (Obj));
5580 else
5581 Typ := Etype (Obj);
5582 end if;
5583
5584 if Is_Class_Wide_Type (Typ) then
5585 Typ := Root_Type (Typ);
5586 end if;
5587
5588 Prims := Primitive_Operations (Typ);
5589
5590 Prim := First_Elmt (Prims);
5591 while Present (Prim) loop
5592 if Chars (Node (Prim)) = Chars (Op) then
5593 Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
5594 Set_Etype (N, Etype (Node (Prim)));
5595 end if;
5596
5597 Next_Elmt (Prim);
5598 end loop;
5599
5600 -- Now look for class-wide operations of the type or any of its
5601 -- ancestors by iterating over the homonyms of the selector.
5602
5603 declare
5604 Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
5605 Hom : Entity_Id;
5606
5607 begin
5608 Hom := Current_Entity (Op);
5609 while Present (Hom) loop
5610 if (Ekind (Hom) = E_Procedure
5611 or else
5612 Ekind (Hom) = E_Function)
5613 and then Scope (Hom) = Scope (Typ)
5614 and then Present (First_Formal (Hom))
5615 and then
5616 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
5617 or else
5618 (Is_Access_Type (Etype (First_Formal (Hom)))
5619 and then
5620 Ekind (Etype (First_Formal (Hom))) =
5621 E_Anonymous_Access_Type
5622 and then
5623 Base_Type
5624 (Designated_Type (Etype (First_Formal (Hom)))) =
5625 Cls_Type))
5626 then
5627 Add_One_Interp (Op, Hom, Etype (Hom));
5628 Set_Etype (N, Etype (Hom));
5629 end if;
5630
5631 Hom := Homonym (Hom);
5632 end loop;
5633 end;
5634
5635 return Etype (Op) /= Any_Type;
5636 end Find_Primitive_Operation;
5637
996ae0b0
RK
5638 ----------------------
5639 -- Find_Unary_Types --
5640 ----------------------
5641
5642 procedure Find_Unary_Types
5643 (R : Node_Id;
5644 Op_Id : Entity_Id;
5645 N : Node_Id)
5646 is
5647 Index : Interp_Index;
5648 It : Interp;
5649
5650 begin
5651 if not Is_Overloaded (R) then
5652 if Is_Numeric_Type (Etype (R)) then
5653 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
5654 end if;
5655
5656 else
5657 Get_First_Interp (R, Index, It);
996ae0b0
RK
5658 while Present (It.Typ) loop
5659 if Is_Numeric_Type (It.Typ) then
5660 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
5661 end if;
5662
5663 Get_Next_Interp (Index, It);
5664 end loop;
5665 end if;
5666 end Find_Unary_Types;
5667
996ae0b0
RK
5668 ------------------
5669 -- Junk_Operand --
5670 ------------------
5671
5672 function Junk_Operand (N : Node_Id) return Boolean is
5673 Enode : Node_Id;
5674
5675 begin
5676 if Error_Posted (N) then
5677 return False;
5678 end if;
5679
5680 -- Get entity to be tested
5681
5682 if Is_Entity_Name (N)
5683 and then Present (Entity (N))
5684 then
5685 Enode := N;
5686
5687 -- An odd case, a procedure name gets converted to a very peculiar
5688 -- function call, and here is where we detect this happening.
5689
5690 elsif Nkind (N) = N_Function_Call
5691 and then Is_Entity_Name (Name (N))
5692 and then Present (Entity (Name (N)))
5693 then
5694 Enode := Name (N);
5695
5696 -- Another odd case, there are at least some cases of selected
5697 -- components where the selected component is not marked as having
5698 -- an entity, even though the selector does have an entity
5699
5700 elsif Nkind (N) = N_Selected_Component
5701 and then Present (Entity (Selector_Name (N)))
5702 then
5703 Enode := Selector_Name (N);
5704
5705 else
5706 return False;
5707 end if;
5708
9de61fcb 5709 -- Now test the entity we got to see if it is a bad case
996ae0b0
RK
5710
5711 case Ekind (Entity (Enode)) is
5712
5713 when E_Package =>
5714 Error_Msg_N
5715 ("package name cannot be used as operand", Enode);
5716
5717 when Generic_Unit_Kind =>
5718 Error_Msg_N
5719 ("generic unit name cannot be used as operand", Enode);
5720
5721 when Type_Kind =>
5722 Error_Msg_N
5723 ("subtype name cannot be used as operand", Enode);
5724
5725 when Entry_Kind =>
5726 Error_Msg_N
5727 ("entry name cannot be used as operand", Enode);
5728
5729 when E_Procedure =>
5730 Error_Msg_N
5731 ("procedure name cannot be used as operand", Enode);
5732
5733 when E_Exception =>
5734 Error_Msg_N
5735 ("exception name cannot be used as operand", Enode);
5736
5737 when E_Block | E_Label | E_Loop =>
5738 Error_Msg_N
5739 ("label name cannot be used as operand", Enode);
5740
5741 when others =>
5742 return False;
5743
5744 end case;
5745
5746 return True;
5747 end Junk_Operand;
5748
5749 --------------------
5750 -- Operator_Check --
5751 --------------------
5752
5753 procedure Operator_Check (N : Node_Id) is
5754 begin
30c20106
AC
5755 Remove_Abstract_Operations (N);
5756
996ae0b0
RK
5757 -- Test for case of no interpretation found for operator
5758
5759 if Etype (N) = Any_Type then
5760 declare
b67a385c
ES
5761 L : Node_Id;
5762 R : Node_Id;
5763 Op_Id : Entity_Id := Empty;
996ae0b0
RK
5764
5765 begin
5766 R := Right_Opnd (N);
5767
5768 if Nkind (N) in N_Binary_Op then
5769 L := Left_Opnd (N);
5770 else
5771 L := Empty;
5772 end if;
5773
5774 -- If either operand has no type, then don't complain further,
9de61fcb 5775 -- since this simply means that we have a propagated error.
996ae0b0
RK
5776
5777 if R = Error
5778 or else Etype (R) = Any_Type
5779 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
5780 then
5781 return;
5782
4c46b835
AC
5783 -- We explicitly check for the case of concatenation of component
5784 -- with component to avoid reporting spurious matching array types
5785 -- that might happen to be lurking in distant packages (such as
5786 -- run-time packages). This also prevents inconsistencies in the
5787 -- messages for certain ACVC B tests, which can vary depending on
5788 -- types declared in run-time interfaces. Another improvement when
5789 -- aggregates are present is to look for a well-typed operand.
996ae0b0
RK
5790
5791 elsif Present (Candidate_Type)
5792 and then (Nkind (N) /= N_Op_Concat
5793 or else Is_Array_Type (Etype (L))
5794 or else Is_Array_Type (Etype (R)))
5795 then
996ae0b0
RK
5796 if Nkind (N) = N_Op_Concat then
5797 if Etype (L) /= Any_Composite
5798 and then Is_Array_Type (Etype (L))
5799 then
5800 Candidate_Type := Etype (L);
5801
5802 elsif Etype (R) /= Any_Composite
5803 and then Is_Array_Type (Etype (R))
5804 then
5805 Candidate_Type := Etype (R);
5806 end if;
5807 end if;
5808
19d846a0 5809 Error_Msg_NE -- CODEFIX
996ae0b0
RK
5810 ("operator for} is not directly visible!",
5811 N, First_Subtype (Candidate_Type));
4561baf7
ES
5812
5813 declare
5814 U : constant Node_Id :=
5815 Cunit (Get_Source_Unit (Candidate_Type));
4561baf7
ES
5816 begin
5817 if Unit_Is_Visible (U) then
5818 Error_Msg_N -- CODEFIX
5819 ("use clause would make operation legal!", N);
4561baf7
ES
5820 else
5821 Error_Msg_NE -- CODEFIX
5822 ("add with_clause and use_clause for&!",
5823 N, Defining_Entity (Unit (U)));
5824 end if;
5825 end;
996ae0b0
RK
5826 return;
5827
5828 -- If either operand is a junk operand (e.g. package name), then
5829 -- post appropriate error messages, but do not complain further.
5830
0e0eecec
ES
5831 -- Note that the use of OR in this test instead of OR ELSE is
5832 -- quite deliberate, we may as well check both operands in the
5833 -- binary operator case.
996ae0b0
RK
5834
5835 elsif Junk_Operand (R)
5836 or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
5837 then
5838 return;
5839
5840 -- If we have a logical operator, one of whose operands is
0e0eecec
ES
5841 -- Boolean, then we know that the other operand cannot resolve to
5842 -- Boolean (since we got no interpretations), but in that case we
5843 -- pretty much know that the other operand should be Boolean, so
5844 -- resolve it that way (generating an error)
996ae0b0 5845
d469eabe 5846 elsif Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor) then
996ae0b0
RK
5847 if Etype (L) = Standard_Boolean then
5848 Resolve (R, Standard_Boolean);
5849 return;
5850 elsif Etype (R) = Standard_Boolean then
5851 Resolve (L, Standard_Boolean);
5852 return;
5853 end if;
5854
5855 -- For an arithmetic operator or comparison operator, if one
5856 -- of the operands is numeric, then we know the other operand
5857 -- is not the same numeric type. If it is a non-numeric type,
5858 -- then probably it is intended to match the other operand.
5859
d469eabe
HK
5860 elsif Nkind_In (N, N_Op_Add,
5861 N_Op_Divide,
5862 N_Op_Ge,
5863 N_Op_Gt,
5864 N_Op_Le)
5865 or else
5866 Nkind_In (N, N_Op_Lt,
5867 N_Op_Mod,
5868 N_Op_Multiply,
5869 N_Op_Rem,
5870 N_Op_Subtract)
996ae0b0
RK
5871 then
5872 if Is_Numeric_Type (Etype (L))
5873 and then not Is_Numeric_Type (Etype (R))
5874 then
5875 Resolve (R, Etype (L));
5876 return;
5877
5878 elsif Is_Numeric_Type (Etype (R))
5879 and then not Is_Numeric_Type (Etype (L))
5880 then
5881 Resolve (L, Etype (R));
5882 return;
5883 end if;
5884
5885 -- Comparisons on A'Access are common enough to deserve a
5886 -- special message.
5887
d469eabe 5888 elsif Nkind_In (N, N_Op_Eq, N_Op_Ne)
996ae0b0
RK
5889 and then Ekind (Etype (L)) = E_Access_Attribute_Type
5890 and then Ekind (Etype (R)) = E_Access_Attribute_Type
5891 then
5892 Error_Msg_N
5893 ("two access attributes cannot be compared directly", N);
5894 Error_Msg_N
aab883ec 5895 ("\use qualified expression for one of the operands",
996ae0b0
RK
5896 N);
5897 return;
5898
5899 -- Another one for C programmers
5900
5901 elsif Nkind (N) = N_Op_Concat
5902 and then Valid_Boolean_Arg (Etype (L))
5903 and then Valid_Boolean_Arg (Etype (R))
5904 then
5905 Error_Msg_N ("invalid operands for concatenation", N);
4e7a4f6e
AC
5906 Error_Msg_N -- CODEFIX
5907 ("\maybe AND was meant", N);
996ae0b0
RK
5908 return;
5909
5910 -- A special case for comparison of access parameter with null
5911
5912 elsif Nkind (N) = N_Op_Eq
5913 and then Is_Entity_Name (L)
5914 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
5915 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
5916 N_Access_Definition
5917 and then Nkind (R) = N_Null
5918 then
5919 Error_Msg_N ("access parameter is not allowed to be null", L);
5920 Error_Msg_N ("\(call would raise Constraint_Error)", L);
5921 return;
61bee0e3
AC
5922
5923 -- Another special case for exponentiation, where the right
5924 -- operand must be Natural, independently of the base.
5925
5926 elsif Nkind (N) = N_Op_Expon
5927 and then Is_Numeric_Type (Etype (L))
5928 and then not Is_Overloaded (R)
5929 and then
5930 First_Subtype (Base_Type (Etype (R))) /= Standard_Integer
5931 and then Base_Type (Etype (R)) /= Universal_Integer
5932 then
5933 Error_Msg_NE
5934 ("exponent must be of type Natural, found}", R, Etype (R));
5935 return;
996ae0b0
RK
5936 end if;
5937
0e0eecec
ES
5938 -- If we fall through then just give general message. Note that in
5939 -- the following messages, if the operand is overloaded we choose
5940 -- an arbitrary type to complain about, but that is probably more
5941 -- useful than not giving a type at all.
996ae0b0
RK
5942
5943 if Nkind (N) in N_Unary_Op then
5944 Error_Msg_Node_2 := Etype (R);
5945 Error_Msg_N ("operator& not defined for}", N);
5946 return;
5947
5948 else
fbf5a39b
AC
5949 if Nkind (N) in N_Binary_Op then
5950 if not Is_Overloaded (L)
5951 and then not Is_Overloaded (R)
5952 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
5953 then
7ffd9312 5954 Error_Msg_Node_2 := First_Subtype (Etype (R));
fbf5a39b 5955 Error_Msg_N ("there is no applicable operator& for}", N);
996ae0b0 5956
fbf5a39b 5957 else
b67a385c
ES
5958 -- Another attempt to find a fix: one of the candidate
5959 -- interpretations may not be use-visible. This has
5960 -- already been checked for predefined operators, so
5961 -- we examine only user-defined functions.
5962
5963 Op_Id := Get_Name_Entity_Id (Chars (N));
5964
5965 while Present (Op_Id) loop
5966 if Ekind (Op_Id) /= E_Operator
5967 and then Is_Overloadable (Op_Id)
5968 then
5969 if not Is_Immediately_Visible (Op_Id)
5970 and then not In_Use (Scope (Op_Id))
aab883ec 5971 and then not Is_Abstract_Subprogram (Op_Id)
b67a385c
ES
5972 and then not Is_Hidden (Op_Id)
5973 and then Ekind (Scope (Op_Id)) = E_Package
5974 and then
5975 Has_Compatible_Type
5976 (L, Etype (First_Formal (Op_Id)))
5977 and then Present
5978 (Next_Formal (First_Formal (Op_Id)))
5979 and then
5980 Has_Compatible_Type
5981 (R,
5982 Etype (Next_Formal (First_Formal (Op_Id))))
5983 then
ed2233dc 5984 Error_Msg_N
b67a385c 5985 ("No legal interpretation for operator&", N);
ed2233dc 5986 Error_Msg_NE
b67a385c
ES
5987 ("\use clause on& would make operation legal",
5988 N, Scope (Op_Id));
5989 exit;
5990 end if;
5991 end if;
fbf5a39b 5992
b67a385c
ES
5993 Op_Id := Homonym (Op_Id);
5994 end loop;
5995
5996 if No (Op_Id) then
5997 Error_Msg_N ("invalid operand types for operator&", N);
5998
5999 if Nkind (N) /= N_Op_Concat then
6000 Error_Msg_NE ("\left operand has}!", N, Etype (L));
6001 Error_Msg_NE ("\right operand has}!", N, Etype (R));
6002 end if;
fbf5a39b
AC
6003 end if;
6004 end if;
996ae0b0
RK
6005 end if;
6006 end if;
6007 end;
6008 end if;
6009 end Operator_Check;
6010
6e73e3ab
AC
6011 -----------------------------------------
6012 -- Process_Implicit_Dereference_Prefix --
6013 -----------------------------------------
6014
d469eabe 6015 function Process_Implicit_Dereference_Prefix
da709d08 6016 (E : Entity_Id;
d469eabe 6017 P : Entity_Id) return Entity_Id
6e73e3ab
AC
6018 is
6019 Ref : Node_Id;
d469eabe 6020 Typ : constant Entity_Id := Designated_Type (Etype (P));
da709d08 6021
6e73e3ab 6022 begin
1a8fae99
ES
6023 if Present (E)
6024 and then (Operating_Mode = Check_Semantics or else not Expander_Active)
6025 then
6e73e3ab
AC
6026 -- We create a dummy reference to E to ensure that the reference
6027 -- is not considered as part of an assignment (an implicit
6028 -- dereference can never assign to its prefix). The Comes_From_Source
6029 -- attribute needs to be propagated for accurate warnings.
6030
6031 Ref := New_Reference_To (E, Sloc (P));
6032 Set_Comes_From_Source (Ref, Comes_From_Source (P));
6033 Generate_Reference (E, Ref);
6034 end if;
d469eabe
HK
6035
6036 -- An implicit dereference is a legal occurrence of an
6037 -- incomplete type imported through a limited_with clause,
6038 -- if the full view is visible.
6039
6040 if From_With_Type (Typ)
6041 and then not From_With_Type (Scope (Typ))
6042 and then
6043 (Is_Immediately_Visible (Scope (Typ))
6044 or else
6045 (Is_Child_Unit (Scope (Typ))
6046 and then Is_Visible_Child_Unit (Scope (Typ))))
6047 then
6048 return Available_View (Typ);
6049 else
6050 return Typ;
6051 end if;
6052
6e73e3ab
AC
6053 end Process_Implicit_Dereference_Prefix;
6054
30c20106
AC
6055 --------------------------------
6056 -- Remove_Abstract_Operations --
6057 --------------------------------
6058
6059 procedure Remove_Abstract_Operations (N : Node_Id) is
401093c1
ES
6060 Abstract_Op : Entity_Id := Empty;
6061 Address_Kludge : Boolean := False;
6062 I : Interp_Index;
6063 It : Interp;
30c20106 6064
0e0eecec
ES
6065 -- AI-310: If overloaded, remove abstract non-dispatching operations. We
6066 -- activate this if either extensions are enabled, or if the abstract
6067 -- operation in question comes from a predefined file. This latter test
6068 -- allows us to use abstract to make operations invisible to users. In
6069 -- particular, if type Address is non-private and abstract subprograms
6070 -- are used to hide its operators, they will be truly hidden.
30c20106 6071
5950a3ac 6072 type Operand_Position is (First_Op, Second_Op);
8a36a0cc 6073 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
5950a3ac
AC
6074
6075 procedure Remove_Address_Interpretations (Op : Operand_Position);
0e0eecec
ES
6076 -- Ambiguities may arise when the operands are literal and the address
6077 -- operations in s-auxdec are visible. In that case, remove the
6078 -- interpretation of a literal as Address, to retain the semantics of
6079 -- Address as a private type.
9f4fd324
AC
6080
6081 ------------------------------------
5950a3ac 6082 -- Remove_Address_Interpretations --
9f4fd324
AC
6083 ------------------------------------
6084
5950a3ac 6085 procedure Remove_Address_Interpretations (Op : Operand_Position) is
9f4fd324
AC
6086 Formal : Entity_Id;
6087
6088 begin
6089 if Is_Overloaded (N) then
6090 Get_First_Interp (N, I, It);
6091 while Present (It.Nam) loop
6092 Formal := First_Entity (It.Nam);
6093
5950a3ac
AC
6094 if Op = Second_Op then
6095 Formal := Next_Entity (Formal);
6096 end if;
6097
6098 if Is_Descendent_Of_Address (Etype (Formal)) then
401093c1 6099 Address_Kludge := True;
9f4fd324
AC
6100 Remove_Interp (I);
6101 end if;
6102
6103 Get_Next_Interp (I, It);
6104 end loop;
6105 end if;
6106 end Remove_Address_Interpretations;
6107
6108 -- Start of processing for Remove_Abstract_Operations
6109
30c20106 6110 begin
d935a36e 6111 if Is_Overloaded (N) then
30c20106 6112 Get_First_Interp (N, I, It);
d935a36e 6113
30c20106 6114 while Present (It.Nam) loop
aab883ec
ES
6115 if Is_Overloadable (It.Nam)
6116 and then Is_Abstract_Subprogram (It.Nam)
30c20106
AC
6117 and then not Is_Dispatching_Operation (It.Nam)
6118 then
af152989 6119 Abstract_Op := It.Nam;
fe45e59e 6120
401093c1
ES
6121 if Is_Descendent_Of_Address (It.Typ) then
6122 Address_Kludge := True;
6123 Remove_Interp (I);
6124 exit;
6125
fe45e59e 6126 -- In Ada 2005, this operation does not participate in Overload
9c510803 6127 -- resolution. If the operation is defined in a predefined
fe45e59e
ES
6128 -- unit, it is one of the operations declared abstract in some
6129 -- variants of System, and it must be removed as well.
6130
0791fbe9 6131 elsif Ada_Version >= Ada_2005
401093c1
ES
6132 or else Is_Predefined_File_Name
6133 (Unit_File_Name (Get_Source_Unit (It.Nam)))
fe45e59e
ES
6134 then
6135 Remove_Interp (I);
6136 exit;
6137 end if;
30c20106
AC
6138 end if;
6139
6140 Get_Next_Interp (I, It);
6141 end loop;
6142
af152989 6143 if No (Abstract_Op) then
fe45e59e
ES
6144
6145 -- If some interpretation yields an integer type, it is still
6146 -- possible that there are address interpretations. Remove them
6147 -- if one operand is a literal, to avoid spurious ambiguities
6148 -- on systems where Address is a visible integer type.
6149
6150 if Is_Overloaded (N)
401093c1 6151 and then Nkind (N) in N_Op
fe45e59e
ES
6152 and then Is_Integer_Type (Etype (N))
6153 then
6154 if Nkind (N) in N_Binary_Op then
6155 if Nkind (Right_Opnd (N)) = N_Integer_Literal then
6156 Remove_Address_Interpretations (Second_Op);
6157
6158 elsif Nkind (Right_Opnd (N)) = N_Integer_Literal then
6159 Remove_Address_Interpretations (First_Op);
6160 end if;
6161 end if;
6162 end if;
3984e89a
AC
6163
6164 elsif Nkind (N) in N_Op then
4c46b835 6165
fe45e59e
ES
6166 -- Remove interpretations that treat literals as addresses. This
6167 -- is never appropriate, even when Address is defined as a visible
6168 -- Integer type. The reason is that we would really prefer Address
6169 -- to behave as a private type, even in this case, which is there
f3d57416
RW
6170 -- only to accommodate oddities of VMS address sizes. If Address
6171 -- is a visible integer type, we get lots of overload ambiguities.
30c20106 6172
5950a3ac
AC
6173 if Nkind (N) in N_Binary_Op then
6174 declare
6175 U1 : constant Boolean :=
6176 Present (Universal_Interpretation (Right_Opnd (N)));
6177 U2 : constant Boolean :=
6178 Present (Universal_Interpretation (Left_Opnd (N)));
30c20106 6179
5950a3ac 6180 begin
0e0eecec 6181 if U1 then
5950a3ac 6182 Remove_Address_Interpretations (Second_Op);
0e0eecec 6183 end if;
5950a3ac 6184
0e0eecec 6185 if U2 then
5950a3ac 6186 Remove_Address_Interpretations (First_Op);
30c20106
AC
6187 end if;
6188
5950a3ac
AC
6189 if not (U1 and U2) then
6190
6191 -- Remove corresponding predefined operator, which is
6192 -- always added to the overload set.
6193
6194 Get_First_Interp (N, I, It);
6195 while Present (It.Nam) loop
0ab80019
AC
6196 if Scope (It.Nam) = Standard_Standard
6197 and then Base_Type (It.Typ) =
6198 Base_Type (Etype (Abstract_Op))
6199 then
5950a3ac
AC
6200 Remove_Interp (I);
6201 end if;
6202
8a36a0cc
AC
6203 Get_Next_Interp (I, It);
6204 end loop;
6205
6206 elsif Is_Overloaded (N)
6207 and then Present (Univ_Type)
6208 then
6209 -- If both operands have a universal interpretation,
0e0eecec
ES
6210 -- it is still necessary to remove interpretations that
6211 -- yield Address. Any remaining ambiguities will be
6212 -- removed in Disambiguate.
8a36a0cc
AC
6213
6214 Get_First_Interp (N, I, It);
8a36a0cc 6215 while Present (It.Nam) loop
0e0eecec
ES
6216 if Is_Descendent_Of_Address (It.Typ) then
6217 Remove_Interp (I);
6218
6219 elsif not Is_Type (It.Nam) then
8a36a0cc 6220 Set_Entity (N, It.Nam);
8a36a0cc
AC
6221 end if;
6222
5950a3ac
AC
6223 Get_Next_Interp (I, It);
6224 end loop;
6225 end if;
6226 end;
30c20106 6227 end if;
3984e89a
AC
6228
6229 elsif Nkind (N) = N_Function_Call
6230 and then
6231 (Nkind (Name (N)) = N_Operator_Symbol
6232 or else
6233 (Nkind (Name (N)) = N_Expanded_Name
6234 and then
6235 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
6236 then
5950a3ac 6237
3984e89a
AC
6238 declare
6239 Arg1 : constant Node_Id := First (Parameter_Associations (N));
5950a3ac
AC
6240 U1 : constant Boolean :=
6241 Present (Universal_Interpretation (Arg1));
6242 U2 : constant Boolean :=
6243 Present (Next (Arg1)) and then
6244 Present (Universal_Interpretation (Next (Arg1)));
3984e89a
AC
6245
6246 begin
0e0eecec 6247 if U1 then
5950a3ac 6248 Remove_Address_Interpretations (First_Op);
0e0eecec 6249 end if;
3984e89a 6250
0e0eecec 6251 if U2 then
5950a3ac
AC
6252 Remove_Address_Interpretations (Second_Op);
6253 end if;
6254
6255 if not (U1 and U2) then
3984e89a
AC
6256 Get_First_Interp (N, I, It);
6257 while Present (It.Nam) loop
9f4fd324
AC
6258 if Scope (It.Nam) = Standard_Standard
6259 and then It.Typ = Base_Type (Etype (Abstract_Op))
6260 then
3984e89a
AC
6261 Remove_Interp (I);
6262 end if;
6263
6264 Get_Next_Interp (I, It);
6265 end loop;
6266 end if;
6267 end;
30c20106 6268 end if;
af152989 6269
401093c1
ES
6270 -- If the removal has left no valid interpretations, emit an error
6271 -- message now and label node as illegal.
af152989
AC
6272
6273 if Present (Abstract_Op) then
6274 Get_First_Interp (N, I, It);
6275
6276 if No (It.Nam) then
6277
6e73e3ab 6278 -- Removal of abstract operation left no viable candidate
af152989
AC
6279
6280 Set_Etype (N, Any_Type);
6281 Error_Msg_Sloc := Sloc (Abstract_Op);
6282 Error_Msg_NE
6283 ("cannot call abstract operation& declared#", N, Abstract_Op);
401093c1
ES
6284
6285 -- In Ada 2005, an abstract operation may disable predefined
6286 -- operators. Since the context is not yet known, we mark the
6287 -- predefined operators as potentially hidden. Do not include
6288 -- predefined operators when addresses are involved since this
6289 -- case is handled separately.
6290
0791fbe9 6291 elsif Ada_Version >= Ada_2005
401093c1
ES
6292 and then not Address_Kludge
6293 then
6294 while Present (It.Nam) loop
6295 if Is_Numeric_Type (It.Typ)
6296 and then Scope (It.Typ) = Standard_Standard
6297 then
6298 Set_Abstract_Op (I, Abstract_Op);
6299 end if;
6300
6301 Get_Next_Interp (I, It);
6302 end loop;
af152989
AC
6303 end if;
6304 end if;
30c20106
AC
6305 end if;
6306 end Remove_Abstract_Operations;
6307
d50f4827
AC
6308 ----------------------------
6309 -- Try_Container_Indexing --
6310 ----------------------------
6311
6312 function Try_Container_Indexing
6313 (N : Node_Id;
6314 Prefix : Node_Id;
6315 Expr : Node_Id) return Boolean
6316 is
6317 Loc : constant Source_Ptr := Sloc (N);
6318 Disc : Entity_Id;
6319 Func : Entity_Id;
6320 Func_Name : Node_Id;
6321 Indexing : Node_Id;
6322 Is_Var : Boolean;
6323 Ritem : Node_Id;
6324
6325 begin
6326
6327 -- Check whether type has a specified indexing aspect.
6328
6329 Func_Name := Empty;
6330 Is_Var := False;
d50f4827 6331
dedac3eb 6332 Ritem := First_Rep_Item (Etype (Prefix));
d50f4827
AC
6333 while Present (Ritem) loop
6334 if Nkind (Ritem) = N_Aspect_Specification then
6335
6336 -- Prefer Variable_Indexing, but will settle for Constant.
6337
6338 if Get_Aspect_Id (Chars (Identifier (Ritem))) =
dedac3eb 6339 Aspect_Constant_Indexing
d50f4827
AC
6340 then
6341 Func_Name := Expression (Ritem);
6342
6343 elsif Get_Aspect_Id (Chars (Identifier (Ritem))) =
dedac3eb 6344 Aspect_Variable_Indexing
d50f4827
AC
6345 then
6346 Func_Name := Expression (Ritem);
6347 Is_Var := True;
6348 exit;
6349 end if;
6350 end if;
dedac3eb 6351
d50f4827
AC
6352 Next_Rep_Item (Ritem);
6353 end loop;
6354
6355 -- If aspect does not exist the expression is illegal. Error is
6356 -- diagnosed in caller.
6357
6358 if No (Func_Name) then
6359 return False;
6360 end if;
6361
6362 if Is_Var
6363 and then not Is_Variable (Prefix)
6364 then
6365 Error_Msg_N ("Variable indexing cannot be applied to a constant", N);
6366 end if;
6367
6368 if not Is_Overloaded (Func_Name) then
6369 Func := Entity (Func_Name);
6370 Indexing := Make_Function_Call (Loc,
6371 Name => New_Occurrence_Of (Func, Loc),
6372 Parameter_Associations =>
6373 New_List (Relocate_Node (Prefix), Relocate_Node (Expr)));
6374 Rewrite (N, Indexing);
6375 Analyze (N);
6376
6377 -- The return type of the indexing function is a reference type, so
6378 -- add the dereference as a possible interpretation.
6379
6380 Disc := First_Discriminant (Etype (Func));
6381 while Present (Disc) loop
6382 if Has_Implicit_Dereference (Disc) then
6383 Add_One_Interp (N, Disc, Designated_Type (Etype (Disc)));
6384 exit;
6385 end if;
6386
6387 Next_Discriminant (Disc);
6388 end loop;
6389
6390 else
6391 Indexing := Make_Function_Call (Loc,
6392 Name => Make_Identifier (Loc, Chars (Func_Name)),
6393 Parameter_Associations =>
6394 New_List (Relocate_Node (Prefix), Relocate_Node (Expr)));
6395
6396 Rewrite (N, Indexing);
6397
6398 declare
6399 I : Interp_Index;
6400 It : Interp;
6401 Success : Boolean;
6402
6403 begin
6404 Get_First_Interp (Func_Name, I, It);
6405 Set_Etype (N, Any_Type);
6406 while Present (It.Nam) loop
6407 Analyze_One_Call (N, It.Nam, False, Success);
6408 if Success then
6409 Set_Etype (Name (N), It.Typ);
6410
6411 -- Add implicit dereference interpretation.
6412
6413 Disc := First_Discriminant (Etype (It.Nam));
6414
6415 while Present (Disc) loop
6416 if Has_Implicit_Dereference (Disc) then
6417 Add_One_Interp
6418 (N, Disc, Designated_Type (Etype (Disc)));
6419 exit;
6420 end if;
6421
6422 Next_Discriminant (Disc);
6423 end loop;
6424 end if;
6425 Get_Next_Interp (I, It);
6426 end loop;
6427 end;
6428 end if;
6429
6430 return True;
6431 end Try_Container_Indexing;
6432
996ae0b0
RK
6433 -----------------------
6434 -- Try_Indirect_Call --
6435 -----------------------
6436
6437 function Try_Indirect_Call
91b1417d
AC
6438 (N : Node_Id;
6439 Nam : Entity_Id;
6440 Typ : Entity_Id) return Boolean
996ae0b0 6441 is
24657705
HK
6442 Actual : Node_Id;
6443 Formal : Entity_Id;
6444
8a7988f5 6445 Call_OK : Boolean;
24657705 6446 pragma Warnings (Off, Call_OK);
996ae0b0
RK
6447
6448 begin
8a7988f5 6449 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
9de61fcb 6450
8a7988f5 6451 Actual := First_Actual (N);
fbf5a39b 6452 Formal := First_Formal (Designated_Type (Typ));
9de61fcb 6453 while Present (Actual) and then Present (Formal) loop
996ae0b0
RK
6454 if not Has_Compatible_Type (Actual, Etype (Formal)) then
6455 return False;
6456 end if;
6457
6458 Next (Actual);
6459 Next_Formal (Formal);
6460 end loop;
6461
6462 if No (Actual) and then No (Formal) then
6463 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
6464
6465 -- Nam is a candidate interpretation for the name in the call,
6466 -- if it is not an indirect call.
6467
6468 if not Is_Type (Nam)
6469 and then Is_Entity_Name (Name (N))
6470 then
6471 Set_Entity (Name (N), Nam);
6472 end if;
6473
6474 return True;
6475 else
6476 return False;
6477 end if;
6478 end Try_Indirect_Call;
6479
6480 ----------------------
6481 -- Try_Indexed_Call --
6482 ----------------------
6483
6484 function Try_Indexed_Call
aab883ec
ES
6485 (N : Node_Id;
6486 Nam : Entity_Id;
6487 Typ : Entity_Id;
6488 Skip_First : Boolean) return Boolean
996ae0b0 6489 is
5ff22245
ES
6490 Loc : constant Source_Ptr := Sloc (N);
6491 Actuals : constant List_Id := Parameter_Associations (N);
6492 Actual : Node_Id;
6493 Index : Entity_Id;
996ae0b0
RK
6494
6495 begin
fbf5a39b 6496 Actual := First (Actuals);
aab883ec
ES
6497
6498 -- If the call was originally written in prefix form, skip the first
6499 -- actual, which is obviously not defaulted.
6500
6501 if Skip_First then
6502 Next (Actual);
6503 end if;
6504
fbf5a39b 6505 Index := First_Index (Typ);
9de61fcb
RD
6506 while Present (Actual) and then Present (Index) loop
6507
996ae0b0
RK
6508 -- If the parameter list has a named association, the expression
6509 -- is definitely a call and not an indexed component.
6510
6511 if Nkind (Actual) = N_Parameter_Association then
6512 return False;
6513 end if;
6514
5ff22245
ES
6515 if Is_Entity_Name (Actual)
6516 and then Is_Type (Entity (Actual))
6517 and then No (Next (Actual))
6518 then
1c218ac3
AC
6519 -- A single actual that is a type name indicates a slice if the
6520 -- type is discrete, and an error otherwise.
6521
6522 if Is_Discrete_Type (Entity (Actual)) then
6523 Rewrite (N,
6524 Make_Slice (Loc,
22b77f68
RD
6525 Prefix =>
6526 Make_Function_Call (Loc,
6527 Name => Relocate_Node (Name (N))),
6528 Discrete_Range =>
1c218ac3
AC
6529 New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
6530
6531 Analyze (N);
6532
6533 else
6534 Error_Msg_N ("invalid use of type in expression", Actual);
6535 Set_Etype (N, Any_Type);
6536 end if;
5ff22245 6537
5ff22245
ES
6538 return True;
6539
6540 elsif not Has_Compatible_Type (Actual, Etype (Index)) then
996ae0b0
RK
6541 return False;
6542 end if;
6543
6544 Next (Actual);
6545 Next_Index (Index);
6546 end loop;
6547
6548 if No (Actual) and then No (Index) then
6549 Add_One_Interp (N, Nam, Component_Type (Typ));
6550
6551 -- Nam is a candidate interpretation for the name in the call,
6552 -- if it is not an indirect call.
6553
6554 if not Is_Type (Nam)
6555 and then Is_Entity_Name (Name (N))
6556 then
6557 Set_Entity (Name (N), Nam);
6558 end if;
6559
6560 return True;
6561 else
6562 return False;
6563 end if;
996ae0b0
RK
6564 end Try_Indexed_Call;
6565
35ae2ed8
AC
6566 --------------------------
6567 -- Try_Object_Operation --
6568 --------------------------
6569
6570 function Try_Object_Operation (N : Node_Id) return Boolean is
b67a385c 6571 K : constant Node_Kind := Nkind (Parent (N));
d469eabe
HK
6572 Is_Subprg_Call : constant Boolean := Nkind_In
6573 (K, N_Procedure_Call_Statement,
6574 N_Function_Call);
b67a385c 6575 Loc : constant Source_Ptr := Sloc (N);
b67a385c 6576 Obj : constant Node_Id := Prefix (N);
0d57c6f4
RD
6577
6578 Subprog : constant Node_Id :=
6579 Make_Identifier (Sloc (Selector_Name (N)),
6580 Chars => Chars (Selector_Name (N)));
401093c1 6581 -- Identifier on which possible interpretations will be collected
0a36105d 6582
b67a385c
ES
6583 Report_Error : Boolean := False;
6584 -- If no candidate interpretation matches the context, redo the
6585 -- analysis with error enabled to provide additional information.
28d6470f
JM
6586
6587 Actual : Node_Id;
d469eabe 6588 Candidate : Entity_Id := Empty;
b67a385c 6589 New_Call_Node : Node_Id := Empty;
4c46b835 6590 Node_To_Replace : Node_Id;
28d6470f 6591 Obj_Type : Entity_Id := Etype (Obj);
d469eabe 6592 Success : Boolean := False;
4c46b835 6593
0a36105d
JM
6594 function Valid_Candidate
6595 (Success : Boolean;
6596 Call : Node_Id;
6597 Subp : Entity_Id) return Entity_Id;
6598 -- If the subprogram is a valid interpretation, record it, and add
6599 -- to the list of interpretations of Subprog.
6600
4c46b835
AC
6601 procedure Complete_Object_Operation
6602 (Call_Node : Node_Id;
0a36105d 6603 Node_To_Replace : Node_Id);
ec6078e3
ES
6604 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
6605 -- Call_Node, insert the object (or its dereference) as the first actual
6606 -- in the call, and complete the analysis of the call.
4c46b835 6607
0a36105d
JM
6608 procedure Report_Ambiguity (Op : Entity_Id);
6609 -- If a prefixed procedure call is ambiguous, indicate whether the
6610 -- call includes an implicit dereference or an implicit 'Access.
6611
4c46b835
AC
6612 procedure Transform_Object_Operation
6613 (Call_Node : out Node_Id;
0a36105d 6614 Node_To_Replace : out Node_Id);
ec6078e3 6615 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
d469eabe
HK
6616 -- Call_Node is the resulting subprogram call, Node_To_Replace is
6617 -- either N or the parent of N, and Subprog is a reference to the
6618 -- subprogram we are trying to match.
35ae2ed8
AC
6619
6620 function Try_Class_Wide_Operation
4c46b835
AC
6621 (Call_Node : Node_Id;
6622 Node_To_Replace : Node_Id) return Boolean;
ec6078e3
ES
6623 -- Traverse all ancestor types looking for a class-wide subprogram
6624 -- for which the current operation is a valid non-dispatching call.
35ae2ed8 6625
0a36105d
JM
6626 procedure Try_One_Prefix_Interpretation (T : Entity_Id);
6627 -- If prefix is overloaded, its interpretation may include different
6628 -- tagged types, and we must examine the primitive operations and
6629 -- the class-wide operations of each in order to find candidate
6630 -- interpretations for the call as a whole.
6631
4c46b835
AC
6632 function Try_Primitive_Operation
6633 (Call_Node : Node_Id;
6634 Node_To_Replace : Node_Id) return Boolean;
ec6078e3
ES
6635 -- Traverse the list of primitive subprograms looking for a dispatching
6636 -- operation for which the current node is a valid call .
4c46b835 6637
0a36105d
JM
6638 ---------------------
6639 -- Valid_Candidate --
6640 ---------------------
6641
6642 function Valid_Candidate
6643 (Success : Boolean;
6644 Call : Node_Id;
6645 Subp : Entity_Id) return Entity_Id
6646 is
ee9aa7b6 6647 Arr_Type : Entity_Id;
0a36105d
JM
6648 Comp_Type : Entity_Id;
6649
6650 begin
6651 -- If the subprogram is a valid interpretation, record it in global
6652 -- variable Subprog, to collect all possible overloadings.
6653
6654 if Success then
6655 if Subp /= Entity (Subprog) then
6656 Add_One_Interp (Subprog, Subp, Etype (Subp));
6657 end if;
6658 end if;
6659
d469eabe
HK
6660 -- If the call may be an indexed call, retrieve component type of
6661 -- resulting expression, and add possible interpretation.
0a36105d 6662
ee9aa7b6 6663 Arr_Type := Empty;
0a36105d
JM
6664 Comp_Type := Empty;
6665
6666 if Nkind (Call) = N_Function_Call
d469eabe
HK
6667 and then Nkind (Parent (N)) = N_Indexed_Component
6668 and then Needs_One_Actual (Subp)
0a36105d
JM
6669 then
6670 if Is_Array_Type (Etype (Subp)) then
ee9aa7b6 6671 Arr_Type := Etype (Subp);
0a36105d
JM
6672
6673 elsif Is_Access_Type (Etype (Subp))
6674 and then Is_Array_Type (Designated_Type (Etype (Subp)))
6675 then
ee9aa7b6 6676 Arr_Type := Designated_Type (Etype (Subp));
0a36105d
JM
6677 end if;
6678 end if;
6679
ee9aa7b6
AC
6680 if Present (Arr_Type) then
6681
3b42c566
RD
6682 -- Verify that the actuals (excluding the object) match the types
6683 -- of the indexes.
ee9aa7b6
AC
6684
6685 declare
6686 Actual : Node_Id;
6687 Index : Node_Id;
6688
6689 begin
6690 Actual := Next (First_Actual (Call));
6691 Index := First_Index (Arr_Type);
ee9aa7b6
AC
6692 while Present (Actual) and then Present (Index) loop
6693 if not Has_Compatible_Type (Actual, Etype (Index)) then
6694 Arr_Type := Empty;
6695 exit;
6696 end if;
6697
6698 Next_Actual (Actual);
6699 Next_Index (Index);
6700 end loop;
6701
6702 if No (Actual)
6703 and then No (Index)
6704 and then Present (Arr_Type)
6705 then
6706 Comp_Type := Component_Type (Arr_Type);
6707 end if;
6708 end;
6709
6710 if Present (Comp_Type)
6711 and then Etype (Subprog) /= Comp_Type
6712 then
6713 Add_One_Interp (Subprog, Subp, Comp_Type);
6714 end if;
0a36105d
JM
6715 end if;
6716
6717 if Etype (Call) /= Any_Type then
6718 return Subp;
6719 else
6720 return Empty;
6721 end if;
6722 end Valid_Candidate;
6723
4c46b835
AC
6724 -------------------------------
6725 -- Complete_Object_Operation --
6726 -------------------------------
6727
6728 procedure Complete_Object_Operation
6729 (Call_Node : Node_Id;
0a36105d 6730 Node_To_Replace : Node_Id)
4c46b835 6731 is
b4592168
GD
6732 Control : constant Entity_Id := First_Formal (Entity (Subprog));
6733 Formal_Type : constant Entity_Id := Etype (Control);
ec6078e3
ES
6734 First_Actual : Node_Id;
6735
4c46b835 6736 begin
955871d3
AC
6737 -- Place the name of the operation, with its interpretations,
6738 -- on the rewritten call.
0a36105d 6739
ec6078e3
ES
6740 Set_Name (Call_Node, Subprog);
6741
0a36105d
JM
6742 First_Actual := First (Parameter_Associations (Call_Node));
6743
b67a385c
ES
6744 -- For cross-reference purposes, treat the new node as being in
6745 -- the source if the original one is.
6746
6747 Set_Comes_From_Source (Subprog, Comes_From_Source (N));
6748 Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
6749
ec6078e3
ES
6750 if Nkind (N) = N_Selected_Component
6751 and then not Inside_A_Generic
6752 then
6753 Set_Entity (Selector_Name (N), Entity (Subprog));
6754 end if;
6755
6756 -- If need be, rewrite first actual as an explicit dereference
0a36105d
JM
6757 -- If the call is overloaded, the rewriting can only be done
6758 -- once the primitive operation is identified.
6759
6760 if Is_Overloaded (Subprog) then
ec6078e3 6761
0a36105d
JM
6762 -- The prefix itself may be overloaded, and its interpretations
6763 -- must be propagated to the new actual in the call.
6764
6765 if Is_Overloaded (Obj) then
6766 Save_Interps (Obj, First_Actual);
6767 end if;
6768
6769 Rewrite (First_Actual, Obj);
6770
6771 elsif not Is_Access_Type (Formal_Type)
ec6078e3
ES
6772 and then Is_Access_Type (Etype (Obj))
6773 then
6774 Rewrite (First_Actual,
6775 Make_Explicit_Dereference (Sloc (Obj), Obj));
6776 Analyze (First_Actual);
fe45e59e 6777
401093c1
ES
6778 -- If we need to introduce an explicit dereference, verify that
6779 -- the resulting actual is compatible with the mode of the formal.
6780
6781 if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
6782 and then Is_Access_Constant (Etype (Obj))
6783 then
6784 Error_Msg_NE
6785 ("expect variable in call to&", Prefix (N), Entity (Subprog));
6786 end if;
6787
d469eabe
HK
6788 -- Conversely, if the formal is an access parameter and the object
6789 -- is not, replace the actual with a 'Access reference. Its analysis
6790 -- will check that the object is aliased.
fe45e59e
ES
6791
6792 elsif Is_Access_Type (Formal_Type)
6793 and then not Is_Access_Type (Etype (Obj))
6794 then
b4592168
GD
6795 -- A special case: A.all'access is illegal if A is an access to a
6796 -- constant and the context requires an access to a variable.
6797
6798 if not Is_Access_Constant (Formal_Type) then
6799 if (Nkind (Obj) = N_Explicit_Dereference
6800 and then Is_Access_Constant (Etype (Prefix (Obj))))
6801 or else not Is_Variable (Obj)
6802 then
6803 Error_Msg_NE
6804 ("actual for& must be a variable", Obj, Control);
6805 end if;
6806 end if;
6807
fe45e59e
ES
6808 Rewrite (First_Actual,
6809 Make_Attribute_Reference (Loc,
6810 Attribute_Name => Name_Access,
6811 Prefix => Relocate_Node (Obj)));
0a36105d
JM
6812
6813 if not Is_Aliased_View (Obj) then
ed2233dc 6814 Error_Msg_NE
0a36105d 6815 ("object in prefixed call to& must be aliased"
401093c1 6816 & " (RM-2005 4.3.1 (13))",
0a36105d
JM
6817 Prefix (First_Actual), Subprog);
6818 end if;
6819
fe45e59e
ES
6820 Analyze (First_Actual);
6821
ec6078e3 6822 else
0a36105d
JM
6823 if Is_Overloaded (Obj) then
6824 Save_Interps (Obj, First_Actual);
6825 end if;
ec6078e3 6826
0a36105d 6827 Rewrite (First_Actual, Obj);
aab883ec
ES
6828 end if;
6829
7ffd9312 6830 Rewrite (Node_To_Replace, Call_Node);
0a36105d
JM
6831
6832 -- Propagate the interpretations collected in subprog to the new
6833 -- function call node, to be resolved from context.
6834
6835 if Is_Overloaded (Subprog) then
6836 Save_Interps (Subprog, Node_To_Replace);
7415029d 6837
0a36105d
JM
6838 else
6839 Analyze (Node_To_Replace);
438ff97c 6840
199c6a10
AC
6841 -- If the operation has been rewritten into a call, which may get
6842 -- subsequently an explicit dereference, preserve the type on the
6843 -- original node (selected component or indexed component) for
6844 -- subsequent legality tests, e.g. Is_Variable. which examines
6845 -- the original node.
438ff97c
ES
6846
6847 if Nkind (Node_To_Replace) = N_Function_Call then
6848 Set_Etype
6849 (Original_Node (Node_To_Replace), Etype (Node_To_Replace));
6850 end if;
0a36105d 6851 end if;
4c46b835
AC
6852 end Complete_Object_Operation;
6853
0a36105d
JM
6854 ----------------------
6855 -- Report_Ambiguity --
6856 ----------------------
6857
6858 procedure Report_Ambiguity (Op : Entity_Id) is
6859 Access_Formal : constant Boolean :=
6860 Is_Access_Type (Etype (First_Formal (Op)));
6861 Access_Actual : constant Boolean :=
6862 Is_Access_Type (Etype (Prefix (N)));
6863
6864 begin
6865 Error_Msg_Sloc := Sloc (Op);
6866
6867 if Access_Formal and then not Access_Actual then
6868 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
ed2233dc 6869 Error_Msg_N
0a36105d
JM
6870 ("\possible interpretation"
6871 & " (inherited, with implicit 'Access) #", N);
6872 else
ed2233dc 6873 Error_Msg_N
0a36105d
JM
6874 ("\possible interpretation (with implicit 'Access) #", N);
6875 end if;
6876
6877 elsif not Access_Formal and then Access_Actual then
6878 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
ed2233dc 6879 Error_Msg_N
0a36105d
JM
6880 ("\possible interpretation"
6881 & " ( inherited, with implicit dereference) #", N);
6882 else
ed2233dc 6883 Error_Msg_N
0a36105d
JM
6884 ("\possible interpretation (with implicit dereference) #", N);
6885 end if;
6886
6887 else
6888 if Nkind (Parent (Op)) = N_Full_Type_Declaration then
ed2233dc 6889 Error_Msg_N ("\possible interpretation (inherited)#", N);
0a36105d 6890 else
4e7a4f6e
AC
6891 Error_Msg_N -- CODEFIX
6892 ("\possible interpretation#", N);
0a36105d
JM
6893 end if;
6894 end if;
6895 end Report_Ambiguity;
6896
4c46b835
AC
6897 --------------------------------
6898 -- Transform_Object_Operation --
6899 --------------------------------
6900
6901 procedure Transform_Object_Operation
6902 (Call_Node : out Node_Id;
0a36105d 6903 Node_To_Replace : out Node_Id)
35ae2ed8 6904 is
ec6078e3
ES
6905 Dummy : constant Node_Id := New_Copy (Obj);
6906 -- Placeholder used as a first parameter in the call, replaced
6907 -- eventually by the proper object.
6908
d469eabe
HK
6909 Parent_Node : constant Node_Id := Parent (N);
6910
ec6078e3 6911 Actual : Node_Id;
d469eabe 6912 Actuals : List_Id;
ec6078e3 6913
35ae2ed8 6914 begin
ec6078e3
ES
6915 -- Common case covering 1) Call to a procedure and 2) Call to a
6916 -- function that has some additional actuals.
35ae2ed8 6917
d469eabe
HK
6918 if Nkind_In (Parent_Node, N_Function_Call,
6919 N_Procedure_Call_Statement)
35ae2ed8 6920
ec6078e3
ES
6921 -- N is a selected component node containing the name of the
6922 -- subprogram. If N is not the name of the parent node we must
6923 -- not replace the parent node by the new construct. This case
6924 -- occurs when N is a parameterless call to a subprogram that
6925 -- is an actual parameter of a call to another subprogram. For
6926 -- example:
6927 -- Some_Subprogram (..., Obj.Operation, ...)
35ae2ed8 6928
ec6078e3 6929 and then Name (Parent_Node) = N
4c46b835
AC
6930 then
6931 Node_To_Replace := Parent_Node;
35ae2ed8 6932
ec6078e3 6933 Actuals := Parameter_Associations (Parent_Node);
d3e65aad 6934
ec6078e3
ES
6935 if Present (Actuals) then
6936 Prepend (Dummy, Actuals);
6937 else
6938 Actuals := New_List (Dummy);
6939 end if;
4c46b835
AC
6940
6941 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
6942 Call_Node :=
6943 Make_Procedure_Call_Statement (Loc,
0a36105d 6944 Name => New_Copy (Subprog),
4c46b835
AC
6945 Parameter_Associations => Actuals);
6946
6947 else
4c46b835
AC
6948 Call_Node :=
6949 Make_Function_Call (Loc,
0a36105d 6950 Name => New_Copy (Subprog),
4c46b835 6951 Parameter_Associations => Actuals);
35ae2ed8 6952
35ae2ed8
AC
6953 end if;
6954
d469eabe 6955 -- Before analysis, a function call appears as an indexed component
ec6078e3 6956 -- if there are no named associations.
758c442c 6957
ec6078e3
ES
6958 elsif Nkind (Parent_Node) = N_Indexed_Component
6959 and then N = Prefix (Parent_Node)
6960 then
758c442c 6961 Node_To_Replace := Parent_Node;
ec6078e3
ES
6962 Actuals := Expressions (Parent_Node);
6963
6964 Actual := First (Actuals);
6965 while Present (Actual) loop
6966 Analyze (Actual);
6967 Next (Actual);
6968 end loop;
6969
6970 Prepend (Dummy, Actuals);
758c442c
GD
6971
6972 Call_Node :=
6973 Make_Function_Call (Loc,
0a36105d 6974 Name => New_Copy (Subprog),
758c442c
GD
6975 Parameter_Associations => Actuals);
6976
d469eabe 6977 -- Parameterless call: Obj.F is rewritten as F (Obj)
35ae2ed8 6978
4c46b835
AC
6979 else
6980 Node_To_Replace := N;
6981
6982 Call_Node :=
6983 Make_Function_Call (Loc,
0a36105d 6984 Name => New_Copy (Subprog),
ec6078e3 6985 Parameter_Associations => New_List (Dummy));
4c46b835
AC
6986 end if;
6987 end Transform_Object_Operation;
35ae2ed8
AC
6988
6989 ------------------------------
6990 -- Try_Class_Wide_Operation --
6991 ------------------------------
6992
6993 function Try_Class_Wide_Operation
4c46b835
AC
6994 (Call_Node : Node_Id;
6995 Node_To_Replace : Node_Id) return Boolean
35ae2ed8 6996 is
0a36105d
JM
6997 Anc_Type : Entity_Id;
6998 Matching_Op : Entity_Id := Empty;
6999 Error : Boolean;
7000
7001 procedure Traverse_Homonyms
7002 (Anc_Type : Entity_Id;
7003 Error : out Boolean);
7004 -- Traverse the homonym chain of the subprogram searching for those
7005 -- homonyms whose first formal has the Anc_Type's class-wide type,
d469eabe
HK
7006 -- or an anonymous access type designating the class-wide type. If
7007 -- an ambiguity is detected, then Error is set to True.
0a36105d
JM
7008
7009 procedure Traverse_Interfaces
7010 (Anc_Type : Entity_Id;
7011 Error : out Boolean);
7012 -- Traverse the list of interfaces, if any, associated with Anc_Type
7013 -- and search for acceptable class-wide homonyms associated with each
7014 -- interface. If an ambiguity is detected, then Error is set to True.
7015
7016 -----------------------
7017 -- Traverse_Homonyms --
7018 -----------------------
7019
7020 procedure Traverse_Homonyms
7021 (Anc_Type : Entity_Id;
7022 Error : out Boolean)
7023 is
7024 Cls_Type : Entity_Id;
7025 Hom : Entity_Id;
7026 Hom_Ref : Node_Id;
7027 Success : Boolean;
35ae2ed8 7028
0a36105d
JM
7029 begin
7030 Error := False;
ec6078e3 7031
b67a385c
ES
7032 Cls_Type := Class_Wide_Type (Anc_Type);
7033
4c46b835 7034 Hom := Current_Entity (Subprog);
401093c1 7035
383e179e
AC
7036 -- Find a non-hidden operation whose first parameter is of the
7037 -- class-wide type, a subtype thereof, or an anonymous access
7038 -- to same.
401093c1 7039
35ae2ed8 7040 while Present (Hom) loop
6a2e4f0b 7041 if Ekind_In (Hom, E_Procedure, E_Function)
383e179e 7042 and then not Is_Hidden (Hom)
b67a385c 7043 and then Scope (Hom) = Scope (Anc_Type)
4c46b835 7044 and then Present (First_Formal (Hom))
b67a385c 7045 and then
401093c1 7046 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
b67a385c
ES
7047 or else
7048 (Is_Access_Type (Etype (First_Formal (Hom)))
0a36105d
JM
7049 and then
7050 Ekind (Etype (First_Formal (Hom))) =
7051 E_Anonymous_Access_Type
b67a385c 7052 and then
401093c1
ES
7053 Base_Type
7054 (Designated_Type (Etype (First_Formal (Hom)))) =
0a36105d 7055 Cls_Type))
35ae2ed8 7056 then
88f47280
AC
7057 -- If the context is a procedure call, ignore functions
7058 -- in the name of the call.
7059
7060 if Ekind (Hom) = E_Function
7061 and then Nkind (Parent (N)) = N_Procedure_Call_Statement
7062 and then N = Name (Parent (N))
7063 then
7064 goto Next_Hom;
7065 end if;
7066
ec6078e3 7067 Set_Etype (Call_Node, Any_Type);
0a36105d
JM
7068 Set_Is_Overloaded (Call_Node, False);
7069 Success := False;
4c46b835 7070
0a36105d
JM
7071 if No (Matching_Op) then
7072 Hom_Ref := New_Reference_To (Hom, Sloc (Subprog));
7073 Set_Etype (Call_Node, Any_Type);
7074 Set_Parent (Call_Node, Parent (Node_To_Replace));
4c46b835 7075
0a36105d 7076 Set_Name (Call_Node, Hom_Ref);
4c46b835 7077
0a36105d
JM
7078 Analyze_One_Call
7079 (N => Call_Node,
7080 Nam => Hom,
7081 Report => Report_Error,
7082 Success => Success,
7083 Skip_First => True);
4c46b835 7084
0a36105d
JM
7085 Matching_Op :=
7086 Valid_Candidate (Success, Call_Node, Hom);
4c46b835 7087
0a36105d
JM
7088 else
7089 Analyze_One_Call
7090 (N => Call_Node,
7091 Nam => Hom,
7092 Report => Report_Error,
7093 Success => Success,
7094 Skip_First => True);
7095
7096 if Present (Valid_Candidate (Success, Call_Node, Hom))
7097 and then Nkind (Call_Node) /= N_Function_Call
7098 then
ed2233dc 7099 Error_Msg_NE ("ambiguous call to&", N, Hom);
0a36105d
JM
7100 Report_Ambiguity (Matching_Op);
7101 Report_Ambiguity (Hom);
7102 Error := True;
7103 return;
7104 end if;
35ae2ed8
AC
7105 end if;
7106 end if;
7107
88f47280
AC
7108 <<Next_Hom>>
7109 Hom := Homonym (Hom);
35ae2ed8 7110 end loop;
0a36105d
JM
7111 end Traverse_Homonyms;
7112
7113 -------------------------
7114 -- Traverse_Interfaces --
7115 -------------------------
35ae2ed8 7116
0a36105d
JM
7117 procedure Traverse_Interfaces
7118 (Anc_Type : Entity_Id;
7119 Error : out Boolean)
7120 is
0a36105d
JM
7121 Intface_List : constant List_Id :=
7122 Abstract_Interface_List (Anc_Type);
d469eabe 7123 Intface : Node_Id;
0a36105d
JM
7124
7125 begin
7126 Error := False;
7127
7128 if Is_Non_Empty_List (Intface_List) then
7129 Intface := First (Intface_List);
7130 while Present (Intface) loop
7131
7132 -- Look for acceptable class-wide homonyms associated with
7133 -- the interface.
7134
7135 Traverse_Homonyms (Etype (Intface), Error);
7136
7137 if Error then
7138 return;
7139 end if;
7140
7141 -- Continue the search by looking at each of the interface's
7142 -- associated interface ancestors.
7143
7144 Traverse_Interfaces (Etype (Intface), Error);
7145
7146 if Error then
7147 return;
7148 end if;
7149
7150 Next (Intface);
7151 end loop;
7152 end if;
7153 end Traverse_Interfaces;
7154
7155 -- Start of processing for Try_Class_Wide_Operation
7156
7157 begin
d469eabe
HK
7158 -- Loop through ancestor types (including interfaces), traversing
7159 -- the homonym chain of the subprogram, trying out those homonyms
7160 -- whose first formal has the class-wide type of the ancestor, or
7161 -- an anonymous access type designating the class-wide type.
0a36105d
JM
7162
7163 Anc_Type := Obj_Type;
7164 loop
7165 -- Look for a match among homonyms associated with the ancestor
7166
7167 Traverse_Homonyms (Anc_Type, Error);
7168
7169 if Error then
7170 return True;
7171 end if;
7172
7173 -- Continue the search for matches among homonyms associated with
7174 -- any interfaces implemented by the ancestor.
7175
7176 Traverse_Interfaces (Anc_Type, Error);
7177
7178 if Error then
7179 return True;
7180 end if;
35ae2ed8 7181
4c46b835
AC
7182 exit when Etype (Anc_Type) = Anc_Type;
7183 Anc_Type := Etype (Anc_Type);
35ae2ed8
AC
7184 end loop;
7185
0a36105d
JM
7186 if Present (Matching_Op) then
7187 Set_Etype (Call_Node, Etype (Matching_Op));
7188 end if;
ec6078e3 7189
0a36105d 7190 return Present (Matching_Op);
35ae2ed8
AC
7191 end Try_Class_Wide_Operation;
7192
0a36105d
JM
7193 -----------------------------------
7194 -- Try_One_Prefix_Interpretation --
7195 -----------------------------------
7196
7197 procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
7198 begin
7199 Obj_Type := T;
7200
7201 if Is_Access_Type (Obj_Type) then
7202 Obj_Type := Designated_Type (Obj_Type);
7203 end if;
7204
7205 if Ekind (Obj_Type) = E_Private_Subtype then
7206 Obj_Type := Base_Type (Obj_Type);
7207 end if;
7208
7209 if Is_Class_Wide_Type (Obj_Type) then
7210 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
7211 end if;
7212
7213 -- The type may have be obtained through a limited_with clause,
7214 -- in which case the primitive operations are available on its
401093c1 7215 -- non-limited view. If still incomplete, retrieve full view.
0a36105d
JM
7216
7217 if Ekind (Obj_Type) = E_Incomplete_Type
7218 and then From_With_Type (Obj_Type)
7219 then
401093c1 7220 Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
0a36105d
JM
7221 end if;
7222
7223 -- If the object is not tagged, or the type is still an incomplete
7224 -- type, this is not a prefixed call.
7225
7226 if not Is_Tagged_Type (Obj_Type)
7227 or else Is_Incomplete_Type (Obj_Type)
7228 then
7229 return;
7230 end if;
7231
7232 if Try_Primitive_Operation
7233 (Call_Node => New_Call_Node,
7234 Node_To_Replace => Node_To_Replace)
7235 or else
7236 Try_Class_Wide_Operation
7237 (Call_Node => New_Call_Node,
7238 Node_To_Replace => Node_To_Replace)
7239 then
7240 null;
7241 end if;
7242 end Try_One_Prefix_Interpretation;
7243
4c46b835
AC
7244 -----------------------------
7245 -- Try_Primitive_Operation --
7246 -----------------------------
35ae2ed8 7247
4c46b835
AC
7248 function Try_Primitive_Operation
7249 (Call_Node : Node_Id;
7250 Node_To_Replace : Node_Id) return Boolean
35ae2ed8 7251 is
6e73e3ab
AC
7252 Elmt : Elmt_Id;
7253 Prim_Op : Entity_Id;
0a36105d
JM
7254 Matching_Op : Entity_Id := Empty;
7255 Prim_Op_Ref : Node_Id := Empty;
7256
7257 Corr_Type : Entity_Id := Empty;
7258 -- If the prefix is a synchronized type, the controlling type of
7259 -- the primitive operation is the corresponding record type, else
7260 -- this is the object type itself.
7261
7262 Success : Boolean := False;
35ae2ed8 7263
401093c1
ES
7264 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
7265 -- For tagged types the candidate interpretations are found in
7266 -- the list of primitive operations of the type and its ancestors.
7267 -- For formal tagged types we have to find the operations declared
7268 -- in the same scope as the type (including in the generic formal
7269 -- part) because the type itself carries no primitive operations,
7270 -- except for formal derived types that inherit the operations of
7271 -- the parent and progenitors.
d469eabe
HK
7272 -- If the context is a generic subprogram body, the generic formals
7273 -- are visible by name, but are not in the entity list of the
7274 -- subprogram because that list starts with the subprogram formals.
7275 -- We retrieve the candidate operations from the generic declaration.
401093c1 7276
dfcfdc0a
AC
7277 function Is_Private_Overriding (Op : Entity_Id) return Boolean;
7278 -- An operation that overrides an inherited operation in the private
7279 -- part of its package may be hidden, but if the inherited operation
7280 -- is visible a direct call to it will dispatch to the private one,
7281 -- which is therefore a valid candidate.
7282
ec6078e3
ES
7283 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
7284 -- Verify that the prefix, dereferenced if need be, is a valid
7285 -- controlling argument in a call to Op. The remaining actuals
7286 -- are checked in the subsequent call to Analyze_One_Call.
35ae2ed8 7287
401093c1
ES
7288 ------------------------------
7289 -- Collect_Generic_Type_Ops --
7290 ------------------------------
7291
7292 function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
7293 Bas : constant Entity_Id := Base_Type (T);
7294 Candidates : constant Elist_Id := New_Elmt_List;
7295 Subp : Entity_Id;
7296 Formal : Entity_Id;
7297
d469eabe
HK
7298 procedure Check_Candidate;
7299 -- The operation is a candidate if its first parameter is a
7300 -- controlling operand of the desired type.
7301
7302 -----------------------
7303 -- Check_Candidate; --
7304 -----------------------
7305
7306 procedure Check_Candidate is
7307 begin
7308 Formal := First_Formal (Subp);
7309
7310 if Present (Formal)
7311 and then Is_Controlling_Formal (Formal)
7312 and then
7313 (Base_Type (Etype (Formal)) = Bas
7314 or else
7315 (Is_Access_Type (Etype (Formal))
7316 and then Designated_Type (Etype (Formal)) = Bas))
7317 then
7318 Append_Elmt (Subp, Candidates);
7319 end if;
7320 end Check_Candidate;
7321
7322 -- Start of processing for Collect_Generic_Type_Ops
7323
401093c1
ES
7324 begin
7325 if Is_Derived_Type (T) then
7326 return Primitive_Operations (T);
7327
bce79204
AC
7328 elsif Ekind_In (Scope (T), E_Procedure, E_Function) then
7329
d469eabe
HK
7330 -- Scan the list of generic formals to find subprograms
7331 -- that may have a first controlling formal of the type.
7332
bb10b891
AC
7333 if Nkind (Unit_Declaration_Node (Scope (T)))
7334 = N_Generic_Subprogram_Declaration
7335 then
7336 declare
7337 Decl : Node_Id;
7338
7339 begin
7340 Decl :=
7341 First (Generic_Formal_Declarations
7342 (Unit_Declaration_Node (Scope (T))));
7343 while Present (Decl) loop
7344 if Nkind (Decl) in N_Formal_Subprogram_Declaration then
7345 Subp := Defining_Entity (Decl);
7346 Check_Candidate;
7347 end if;
d469eabe 7348
bb10b891
AC
7349 Next (Decl);
7350 end loop;
7351 end;
7352 end if;
d469eabe
HK
7353 return Candidates;
7354
401093c1
ES
7355 else
7356 -- Scan the list of entities declared in the same scope as
7357 -- the type. In general this will be an open scope, given that
7358 -- the call we are analyzing can only appear within a generic
7359 -- declaration or body (either the one that declares T, or a
7360 -- child unit).
7361
bb10b891
AC
7362 -- For a subtype representing a generic actual type, go to the
7363 -- base type.
7364
7365 if Is_Generic_Actual_Type (T) then
7366 Subp := First_Entity (Scope (Base_Type (T)));
7367 else
7368 Subp := First_Entity (Scope (T));
7369 end if;
7370
401093c1
ES
7371 while Present (Subp) loop
7372 if Is_Overloadable (Subp) then
d469eabe 7373 Check_Candidate;
401093c1
ES
7374 end if;
7375
7376 Next_Entity (Subp);
7377 end loop;
7378
7379 return Candidates;
7380 end if;
7381 end Collect_Generic_Type_Ops;
7382
dfcfdc0a
AC
7383 ---------------------------
7384 -- Is_Private_Overriding --
7385 ---------------------------
7386
7387 function Is_Private_Overriding (Op : Entity_Id) return Boolean is
7388 Visible_Op : constant Entity_Id := Homonym (Op);
7389
7390 begin
7391 return Present (Visible_Op)
6465b6a7 7392 and then Scope (Op) = Scope (Visible_Op)
dfcfdc0a
AC
7393 and then not Comes_From_Source (Visible_Op)
7394 and then Alias (Visible_Op) = Op
7395 and then not Is_Hidden (Visible_Op);
7396 end Is_Private_Overriding;
7397
ec6078e3
ES
7398 -----------------------------
7399 -- Valid_First_Argument_Of --
7400 -----------------------------
35ae2ed8 7401
ec6078e3 7402 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
9febb58f 7403 Typ : Entity_Id := Etype (First_Formal (Op));
35ae2ed8 7404
ec6078e3 7405 begin
9febb58f
JM
7406 if Is_Concurrent_Type (Typ)
7407 and then Present (Corresponding_Record_Type (Typ))
7408 then
7409 Typ := Corresponding_Record_Type (Typ);
7410 end if;
7411
d469eabe
HK
7412 -- Simple case. Object may be a subtype of the tagged type or
7413 -- may be the corresponding record of a synchronized type.
5d09245e 7414
aab883ec 7415 return Obj_Type = Typ
d469eabe 7416 or else Base_Type (Obj_Type) = Typ
0a36105d
JM
7417 or else Corr_Type = Typ
7418
7419 -- Prefix can be dereferenced
725e2a15 7420
ec6078e3 7421 or else
0a36105d
JM
7422 (Is_Access_Type (Corr_Type)
7423 and then Designated_Type (Corr_Type) = Typ)
5d09245e 7424
0a36105d
JM
7425 -- Formal is an access parameter, for which the object
7426 -- can provide an access.
35ae2ed8 7427
ec6078e3
ES
7428 or else
7429 (Ekind (Typ) = E_Anonymous_Access_Type
9fde638d
RD
7430 and then
7431 Base_Type (Designated_Type (Typ)) = Base_Type (Corr_Type));
ec6078e3 7432 end Valid_First_Argument_Of;
35ae2ed8 7433
ec6078e3 7434 -- Start of processing for Try_Primitive_Operation
35ae2ed8 7435
ec6078e3 7436 begin
d469eabe 7437 -- Look for subprograms in the list of primitive operations. The name
0a36105d
JM
7438 -- must be identical, and the kind of call indicates the expected
7439 -- kind of operation (function or procedure). If the type is a
d469eabe 7440 -- (tagged) synchronized type, the primitive ops are attached to the
b4592168 7441 -- corresponding record (base) type.
aab883ec
ES
7442
7443 if Is_Concurrent_Type (Obj_Type) then
bb10b891
AC
7444 if Present (Corresponding_Record_Type (Obj_Type)) then
7445 Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
7446 Elmt := First_Elmt (Primitive_Operations (Corr_Type));
7447 else
7448 Corr_Type := Obj_Type;
7449 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
15e4986c
JM
7450 end if;
7451
401093c1 7452 elsif not Is_Generic_Type (Obj_Type) then
0a36105d 7453 Corr_Type := Obj_Type;
aab883ec 7454 Elmt := First_Elmt (Primitive_Operations (Obj_Type));
401093c1
ES
7455
7456 else
7457 Corr_Type := Obj_Type;
7458 Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
aab883ec 7459 end if;
35ae2ed8 7460
ec6078e3
ES
7461 while Present (Elmt) loop
7462 Prim_Op := Node (Elmt);
7463
7464 if Chars (Prim_Op) = Chars (Subprog)
7465 and then Present (First_Formal (Prim_Op))
7466 and then Valid_First_Argument_Of (Prim_Op)
fe45e59e 7467 and then
7415029d 7468 (Nkind (Call_Node) = N_Function_Call)
fe45e59e 7469 = (Ekind (Prim_Op) = E_Function)
ec6078e3 7470 then
b67a385c
ES
7471 -- Ada 2005 (AI-251): If this primitive operation corresponds
7472 -- with an immediate ancestor interface there is no need to add
7473 -- it to the list of interpretations; the corresponding aliased
7474 -- primitive is also in this list of primitive operations and
7475 -- will be used instead.
fe45e59e 7476
ce2b6ba5
JM
7477 if (Present (Interface_Alias (Prim_Op))
7478 and then Is_Ancestor (Find_Dispatching_Type
7479 (Alias (Prim_Op)), Corr_Type))
0a36105d 7480
dfcfdc0a
AC
7481 -- Do not consider hidden primitives unless the type is in an
7482 -- open scope or we are within an instance, where visibility
7483 -- is known to be correct, or else if this is an overriding
7484 -- operation in the private part for an inherited operation.
0a36105d 7485
dfcfdc0a
AC
7486 or else (Is_Hidden (Prim_Op)
7487 and then not Is_Immediately_Visible (Obj_Type)
7488 and then not In_Instance
7489 and then not Is_Private_Overriding (Prim_Op))
fe45e59e
ES
7490 then
7491 goto Continue;
7492 end if;
7493
0a36105d
JM
7494 Set_Etype (Call_Node, Any_Type);
7495 Set_Is_Overloaded (Call_Node, False);
7496
7497 if No (Matching_Op) then
fe45e59e 7498 Prim_Op_Ref := New_Reference_To (Prim_Op, Sloc (Subprog));
b67a385c 7499 Candidate := Prim_Op;
35ae2ed8 7500
fe45e59e 7501 Set_Parent (Call_Node, Parent (Node_To_Replace));
35ae2ed8 7502
fe45e59e 7503 Set_Name (Call_Node, Prim_Op_Ref);
0a36105d 7504 Success := False;
35ae2ed8 7505
fe45e59e
ES
7506 Analyze_One_Call
7507 (N => Call_Node,
7508 Nam => Prim_Op,
b67a385c 7509 Report => Report_Error,
fe45e59e
ES
7510 Success => Success,
7511 Skip_First => True);
35ae2ed8 7512
0a36105d 7513 Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
fe45e59e 7514
d469eabe
HK
7515 -- More than one interpretation, collect for subsequent
7516 -- disambiguation. If this is a procedure call and there
7517 -- is another match, report ambiguity now.
0a36105d 7518
d469eabe 7519 else
0a36105d
JM
7520 Analyze_One_Call
7521 (N => Call_Node,
7522 Nam => Prim_Op,
7523 Report => Report_Error,
7524 Success => Success,
7525 Skip_First => True);
fe45e59e 7526
0a36105d
JM
7527 if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
7528 and then Nkind (Call_Node) /= N_Function_Call
7529 then
ed2233dc 7530 Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
0a36105d
JM
7531 Report_Ambiguity (Matching_Op);
7532 Report_Ambiguity (Prim_Op);
7533 return True;
7534 end if;
4c46b835
AC
7535 end if;
7536 end if;
35ae2ed8 7537
fe45e59e 7538 <<Continue>>
4c46b835
AC
7539 Next_Elmt (Elmt);
7540 end loop;
35ae2ed8 7541
0a36105d
JM
7542 if Present (Matching_Op) then
7543 Set_Etype (Call_Node, Etype (Matching_Op));
fe45e59e
ES
7544 end if;
7545
0a36105d 7546 return Present (Matching_Op);
4c46b835 7547 end Try_Primitive_Operation;
35ae2ed8 7548
4c46b835 7549 -- Start of processing for Try_Object_Operation
35ae2ed8 7550
4c46b835 7551 begin
0a36105d 7552 Analyze_Expression (Obj);
ec6078e3 7553
0a36105d 7554 -- Analyze the actuals if node is known to be a subprogram call
28d6470f
JM
7555
7556 if Is_Subprg_Call and then N = Name (Parent (N)) then
7557 Actual := First (Parameter_Associations (Parent (N)));
7558 while Present (Actual) loop
725e2a15 7559 Analyze_Expression (Actual);
28d6470f
JM
7560 Next (Actual);
7561 end loop;
7562 end if;
5d09245e 7563
ec6078e3
ES
7564 -- Build a subprogram call node, using a copy of Obj as its first
7565 -- actual. This is a placeholder, to be replaced by an explicit
7566 -- dereference when needed.
4c46b835 7567
ec6078e3
ES
7568 Transform_Object_Operation
7569 (Call_Node => New_Call_Node,
0a36105d 7570 Node_To_Replace => Node_To_Replace);
4c46b835 7571
ec6078e3 7572 Set_Etype (New_Call_Node, Any_Type);
0a36105d 7573 Set_Etype (Subprog, Any_Type);
ec6078e3 7574 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
4c46b835 7575
0a36105d
JM
7576 if not Is_Overloaded (Obj) then
7577 Try_One_Prefix_Interpretation (Obj_Type);
ec6078e3 7578
0a36105d
JM
7579 else
7580 declare
7581 I : Interp_Index;
7582 It : Interp;
7583 begin
7584 Get_First_Interp (Obj, I, It);
7585 while Present (It.Nam) loop
7586 Try_One_Prefix_Interpretation (It.Typ);
7587 Get_Next_Interp (I, It);
7588 end loop;
7589 end;
7590 end if;
7591
7592 if Etype (New_Call_Node) /= Any_Type then
7593 Complete_Object_Operation
7594 (Call_Node => New_Call_Node,
7595 Node_To_Replace => Node_To_Replace);
b67a385c
ES
7596 return True;
7597
7598 elsif Present (Candidate) then
7599
7600 -- The argument list is not type correct. Re-analyze with error
7601 -- reporting enabled, and use one of the possible candidates.
d469eabe 7602 -- In All_Errors_Mode, re-analyze all failed interpretations.
b67a385c
ES
7603
7604 if All_Errors_Mode then
7605 Report_Error := True;
7606 if Try_Primitive_Operation
7607 (Call_Node => New_Call_Node,
7608 Node_To_Replace => Node_To_Replace)
7609
7610 or else
7611 Try_Class_Wide_Operation
7612 (Call_Node => New_Call_Node,
7613 Node_To_Replace => Node_To_Replace)
7614 then
7615 null;
7616 end if;
7617
7618 else
7619 Analyze_One_Call
7620 (N => New_Call_Node,
7621 Nam => Candidate,
7622 Report => True,
7623 Success => Success,
7624 Skip_First => True);
7625 end if;
7626
d469eabe
HK
7627 -- No need for further errors
7628
7629 return True;
b67a385c
ES
7630
7631 else
7632 -- There was no candidate operation, so report it as an error
7633 -- in the caller: Analyze_Selected_Component.
7634
7635 return False;
7636 end if;
35ae2ed8
AC
7637 end Try_Object_Operation;
7638
b4592168
GD
7639 ---------
7640 -- wpo --
7641 ---------
7642
7643 procedure wpo (T : Entity_Id) is
7644 Op : Entity_Id;
7645 E : Elmt_Id;
7646
7647 begin
7648 if not Is_Tagged_Type (T) then
7649 return;
7650 end if;
7651
7652 E := First_Elmt (Primitive_Operations (Base_Type (T)));
7653 while Present (E) loop
7654 Op := Node (E);
7655 Write_Int (Int (Op));
7656 Write_Str (" === ");
7657 Write_Name (Chars (Op));
7658 Write_Str (" in ");
7659 Write_Name (Chars (Scope (Op)));
7660 Next_Elmt (E);
7661 Write_Eol;
7662 end loop;
7663 end wpo;
7664
996ae0b0 7665end Sem_Ch4;