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