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