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