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