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