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