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