1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Exp_Util; use Exp_Util;
34 with Fname; use Fname;
35 with Itypes; use Itypes;
37 with Lib.Xref; use Lib.Xref;
38 with Namet; use Namet;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
42 with Output; use Output;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
46 with Sem_Cat; use Sem_Cat;
47 with Sem_Ch3; use Sem_Ch3;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Dist; use Sem_Dist;
50 with Sem_Eval; use Sem_Eval;
51 with Sem_Res; use Sem_Res;
52 with Sem_Util; use Sem_Util;
53 with Sem_Type; use Sem_Type;
54 with Stand; use Stand;
55 with Sinfo; use Sinfo;
56 with Snames; use Snames;
57 with Tbuild; use Tbuild;
59 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
61 package body Sem_Ch4 is
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 procedure Analyze_Expression (N : Node_Id);
68 -- For expressions that are not names, this is just a call to analyze.
69 -- If the expression is a name, it may be a call to a parameterless
70 -- function, and if so must be converted into an explicit call node
71 -- and analyzed as such. This deproceduring must be done during the first
72 -- pass of overload resolution, because otherwise a procedure call with
73 -- overloaded actuals may fail to resolve. See 4327-001 for an example.
75 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
76 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
77 -- is an operator name or an expanded name whose selector is an operator
78 -- name, and one possible interpretation is as a predefined operator.
80 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
81 -- If the prefix of a selected_component is overloaded, the proper
82 -- interpretation that yields a record type with the proper selector
83 -- name must be selected.
85 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
86 -- Procedure to analyze a user defined binary operator, which is resolved
87 -- like a function, but instead of a list of actuals it is presented
88 -- with the left and right operands of an operator node.
90 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
91 -- Procedure to analyze a user defined unary operator, which is resolved
92 -- like a function, but instead of a list of actuals, it is presented with
93 -- the operand of the operator node.
95 procedure Ambiguous_Operands (N : Node_Id);
96 -- for equality, membership, and comparison operators with overloaded
97 -- arguments, list possible interpretations.
99 procedure Analyze_One_Call
103 Success : out Boolean);
104 -- Check one interpretation of an overloaded subprogram name for
105 -- compatibility with the types of the actuals in a call. If there is a
106 -- single interpretation which does not match, post error if Report is
109 -- Nam is the entity that provides the formals against which the actuals
110 -- are checked. Nam is either the name of a subprogram, or the internal
111 -- subprogram type constructed for an access_to_subprogram. If the actuals
112 -- are compatible with Nam, then Nam is added to the list of candidate
113 -- interpretations for N, and Success is set to True.
115 procedure Check_Misspelled_Selector
118 -- Give possible misspelling diagnostic if Sel is likely to be
119 -- a misspelling of one of the selectors of the Prefix.
120 -- This is called by Analyze_Selected_Component after producing
121 -- an invalid selector error message.
123 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
124 -- Verify that type T is declared in scope S. Used to find intepretations
125 -- for operators given by expanded names. This is abstracted as a separate
126 -- function to handle extensions to System, where S is System, but T is
127 -- declared in the extension.
129 procedure Find_Arithmetic_Types
133 -- L and R are the operands of an arithmetic operator. Find
134 -- consistent pairs of interpretations for L and R that have a
135 -- numeric type consistent with the semantics of the operator.
137 procedure Find_Comparison_Types
141 -- L and R are operands of a comparison operator. Find consistent
142 -- pairs of interpretations for L and R.
144 procedure Find_Concatenation_Types
148 -- For the four varieties of concatenation.
150 procedure Find_Equality_Types
154 -- Ditto for equality operators.
156 procedure Find_Boolean_Types
160 -- Ditto for binary logical operations.
162 procedure Find_Negation_Types
166 -- Find consistent interpretation for operand of negation operator.
168 procedure Find_Non_Universal_Interpretations
173 -- For equality and comparison operators, the result is always boolean,
174 -- and the legality of the operation is determined from the visibility
175 -- of the operand types. If one of the operands has a universal interpre-
176 -- tation, the legality check uses some compatible non-universal
177 -- interpretation of the other operand. N can be an operator node, or
178 -- a function call whose name is an operator designator.
180 procedure Find_Unary_Types
184 -- Unary arithmetic types: plus, minus, abs.
186 procedure Check_Arithmetic_Pair
190 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
191 -- types for left and right operand. Determine whether they constitute
192 -- a valid pair for the given operator, and record the corresponding
193 -- interpretation of the operator node. The node N may be an operator
194 -- node (the usual case) or a function call whose prefix is an operator
195 -- designator. In both cases Op_Id is the operator name itself.
197 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
198 -- Give detailed information on overloaded call where none of the
199 -- interpretations match. N is the call node, Nam the designator for
200 -- the overloaded entity being called.
202 function Junk_Operand (N : Node_Id) return Boolean;
203 -- Test for an operand that is an inappropriate entity (e.g. a package
204 -- name or a label). If so, issue an error message and return True. If
205 -- the operand is not an inappropriate entity kind, return False.
207 procedure Operator_Check (N : Node_Id);
208 -- Verify that an operator has received some valid interpretation.
209 -- If none was found, determine whether a use clause would make the
210 -- operation legal. The variable Candidate_Type (defined in Sem_Type) is
211 -- set for every type compatible with the operator, even if the operator
212 -- for the type is not directly visible. The routine uses this type to emit
213 -- a more informative message.
215 procedure Remove_Abstract_Operations (N : Node_Id);
216 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
217 -- operation is not a candidate interpretation.
219 function Try_Indexed_Call
222 Typ : Entity_Id) return Boolean;
223 -- If a function has defaults for all its actuals, a call to it may
224 -- in fact be an indexing on the result of the call. Try_Indexed_Call
225 -- attempts the interpretation as an indexing, prior to analysis as
226 -- a call. If both are possible, the node is overloaded with both
227 -- interpretations (same symbol but two different types).
229 function Try_Indirect_Call
232 Typ : Entity_Id) return Boolean;
233 -- Similarly, a function F that needs no actuals can return an access
234 -- to a subprogram, and the call F (X) interpreted as F.all (X). In
235 -- this case the call may be overloaded with both interpretations.
237 function Try_Object_Operation (N : Node_Id) return Boolean;
238 -- Ada 2005 (AI-252): Give support to the object operation notation
240 ------------------------
241 -- Ambiguous_Operands --
242 ------------------------
244 procedure Ambiguous_Operands (N : Node_Id) is
245 procedure List_Operand_Interps (Opnd : Node_Id);
247 --------------------------
248 -- List_Operand_Interps --
249 --------------------------
251 procedure List_Operand_Interps (Opnd : Node_Id) is
256 if Is_Overloaded (Opnd) then
257 if Nkind (Opnd) in N_Op then
259 elsif Nkind (Opnd) = N_Function_Call then
269 if Opnd = Left_Opnd (N) then
271 ("\left operand has the following interpretations", N);
274 ("\right operand has the following interpretations", N);
278 List_Interps (Nam, Err);
279 end List_Operand_Interps;
281 -- Start of processing for Ambiguous_Operands
285 or else Nkind (N) = N_Not_In
287 Error_Msg_N ("ambiguous operands for membership", N);
289 elsif Nkind (N) = N_Op_Eq
290 or else Nkind (N) = N_Op_Ne
292 Error_Msg_N ("ambiguous operands for equality", N);
295 Error_Msg_N ("ambiguous operands for comparison", N);
298 if All_Errors_Mode then
299 List_Operand_Interps (Left_Opnd (N));
300 List_Operand_Interps (Right_Opnd (N));
302 Error_Msg_N ("\use -gnatf switch for details", N);
304 end Ambiguous_Operands;
306 -----------------------
307 -- Analyze_Aggregate --
308 -----------------------
310 -- Most of the analysis of Aggregates requires that the type be known,
311 -- and is therefore put off until resolution.
313 procedure Analyze_Aggregate (N : Node_Id) is
315 if No (Etype (N)) then
316 Set_Etype (N, Any_Composite);
318 end Analyze_Aggregate;
320 -----------------------
321 -- Analyze_Allocator --
322 -----------------------
324 procedure Analyze_Allocator (N : Node_Id) is
325 Loc : constant Source_Ptr := Sloc (N);
326 Sav_Errs : constant Nat := Serious_Errors_Detected;
327 E : Node_Id := Expression (N);
328 Acc_Type : Entity_Id;
332 Check_Restriction (No_Allocators, N);
334 if Nkind (E) = N_Qualified_Expression then
335 Acc_Type := Create_Itype (E_Allocator_Type, N);
336 Set_Etype (Acc_Type, Acc_Type);
337 Init_Size_Align (Acc_Type);
338 Find_Type (Subtype_Mark (E));
339 Type_Id := Entity (Subtype_Mark (E));
340 Check_Fully_Declared (Type_Id, N);
341 Set_Directly_Designated_Type (Acc_Type, Type_Id);
343 if Is_Limited_Type (Type_Id)
344 and then Comes_From_Source (N)
345 and then not In_Instance_Body
347 -- Ada 2005 (AI-287): Do not post an error if the expression
348 -- corresponds to a limited aggregate. Limited aggregates
349 -- are checked in sem_aggr in a per-component manner
350 -- (compare with handling of Get_Value subprogram).
352 if Ada_Version >= Ada_05
353 and then Nkind (Expression (E)) = N_Aggregate
357 Error_Msg_N ("initialization not allowed for limited types", N);
358 Explain_Limited_Type (Type_Id, N);
362 Analyze_And_Resolve (Expression (E), Type_Id);
364 -- A qualified expression requires an exact match of the type,
365 -- class-wide matching is not allowed.
367 if Is_Class_Wide_Type (Type_Id)
368 and then Base_Type (Etype (Expression (E))) /= Base_Type (Type_Id)
370 Wrong_Type (Expression (E), Type_Id);
373 Check_Non_Static_Context (Expression (E));
375 -- We don't analyze the qualified expression itself because it's
376 -- part of the allocator
378 Set_Etype (E, Type_Id);
380 -- Case where no qualified expression is present
387 -- If the allocator includes a N_Subtype_Indication then a
388 -- constraint is present, otherwise the node is a subtype mark.
389 -- Introduce an explicit subtype declaration into the tree
390 -- defining some anonymous subtype and rewrite the allocator to
391 -- use this subtype rather than the subtype indication.
393 -- It is important to introduce the explicit subtype declaration
394 -- so that the bounds of the subtype indication are attached to
395 -- the tree in case the allocator is inside a generic unit.
397 if Nkind (E) = N_Subtype_Indication then
399 -- A constraint is only allowed for a composite type in Ada
400 -- 95. In Ada 83, a constraint is also allowed for an
401 -- access-to-composite type, but the constraint is ignored.
403 Find_Type (Subtype_Mark (E));
405 if Is_Elementary_Type (Entity (Subtype_Mark (E))) then
406 if not (Ada_Version = Ada_83
407 and then Is_Access_Type (Entity (Subtype_Mark (E))))
409 Error_Msg_N ("constraint not allowed here", E);
411 if Nkind (Constraint (E))
412 = N_Index_Or_Discriminant_Constraint
415 ("\if qualified expression was meant, " &
416 "use apostrophe", Constraint (E));
420 -- Get rid of the bogus constraint:
422 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
423 Analyze_Allocator (N);
427 if Expander_Active then
429 Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
432 Make_Subtype_Declaration (Loc,
433 Defining_Identifier => Def_Id,
434 Subtype_Indication => Relocate_Node (E)));
436 if Sav_Errs /= Serious_Errors_Detected
437 and then Nkind (Constraint (E))
438 = N_Index_Or_Discriminant_Constraint
441 ("if qualified expression was meant, " &
442 "use apostrophe!", Constraint (E));
445 E := New_Occurrence_Of (Def_Id, Loc);
446 Rewrite (Expression (N), E);
450 Type_Id := Process_Subtype (E, N);
451 Acc_Type := Create_Itype (E_Allocator_Type, N);
452 Set_Etype (Acc_Type, Acc_Type);
453 Init_Size_Align (Acc_Type);
454 Set_Directly_Designated_Type (Acc_Type, Type_Id);
455 Check_Fully_Declared (Type_Id, N);
459 if Can_Never_Be_Null (Type_Id) then
460 Error_Msg_N ("(Ada 2005) qualified expression required",
464 -- Check restriction against dynamically allocated protected
465 -- objects. Note that when limited aggregates are supported,
466 -- a similar test should be applied to an allocator with a
467 -- qualified expression ???
469 if Is_Protected_Type (Type_Id) then
470 Check_Restriction (No_Protected_Type_Allocators, N);
473 -- Check for missing initialization. Skip this check if we already
474 -- had errors on analyzing the allocator, since in that case these
475 -- are probably cascaded errors
477 if Is_Indefinite_Subtype (Type_Id)
478 and then Serious_Errors_Detected = Sav_Errs
480 if Is_Class_Wide_Type (Type_Id) then
482 ("initialization required in class-wide allocation", N);
485 ("initialization required in unconstrained allocation", N);
491 if Is_Abstract (Type_Id) then
492 Error_Msg_N ("cannot allocate abstract object", E);
495 if Has_Task (Designated_Type (Acc_Type)) then
496 Check_Restriction (No_Tasking, N);
497 Check_Restriction (Max_Tasks, N);
498 Check_Restriction (No_Task_Allocators, N);
501 Set_Etype (N, Acc_Type);
503 if not Is_Library_Level_Entity (Acc_Type) then
504 Check_Restriction (No_Local_Allocators, N);
507 -- Ada 2005 (AI-231): Static checks
509 if Ada_Version >= Ada_05
510 and then (Null_Exclusion_Present (N)
511 or else Can_Never_Be_Null (Etype (N)))
513 Null_Exclusion_Static_Checks (N);
516 if Serious_Errors_Detected > Sav_Errs then
517 Set_Error_Posted (N);
518 Set_Etype (N, Any_Type);
520 end Analyze_Allocator;
522 ---------------------------
523 -- Analyze_Arithmetic_Op --
524 ---------------------------
526 procedure Analyze_Arithmetic_Op (N : Node_Id) is
527 L : constant Node_Id := Left_Opnd (N);
528 R : constant Node_Id := Right_Opnd (N);
532 Candidate_Type := Empty;
533 Analyze_Expression (L);
534 Analyze_Expression (R);
536 -- If the entity is already set, the node is the instantiation of
537 -- a generic node with a non-local reference, or was manufactured
538 -- by a call to Make_Op_xxx. In either case the entity is known to
539 -- be valid, and we do not need to collect interpretations, instead
540 -- we just get the single possible interpretation.
544 if Present (Op_Id) then
545 if Ekind (Op_Id) = E_Operator then
547 if (Nkind (N) = N_Op_Divide or else
548 Nkind (N) = N_Op_Mod or else
549 Nkind (N) = N_Op_Multiply or else
550 Nkind (N) = N_Op_Rem)
551 and then Treat_Fixed_As_Integer (N)
555 Set_Etype (N, Any_Type);
556 Find_Arithmetic_Types (L, R, Op_Id, N);
560 Set_Etype (N, Any_Type);
561 Add_One_Interp (N, Op_Id, Etype (Op_Id));
564 -- Entity is not already set, so we do need to collect interpretations
567 Op_Id := Get_Name_Entity_Id (Chars (N));
568 Set_Etype (N, Any_Type);
570 while Present (Op_Id) loop
571 if Ekind (Op_Id) = E_Operator
572 and then Present (Next_Entity (First_Entity (Op_Id)))
574 Find_Arithmetic_Types (L, R, Op_Id, N);
576 -- The following may seem superfluous, because an operator cannot
577 -- be generic, but this ignores the cleverness of the author of
580 elsif Is_Overloadable (Op_Id) then
581 Analyze_User_Defined_Binary_Op (N, Op_Id);
584 Op_Id := Homonym (Op_Id);
589 end Analyze_Arithmetic_Op;
595 -- Function, procedure, and entry calls are checked here. The Name in
596 -- the call may be overloaded. The actuals have been analyzed and may
597 -- themselves be overloaded. On exit from this procedure, the node N
598 -- may have zero, one or more interpretations. In the first case an
599 -- error message is produced. In the last case, the node is flagged
600 -- as overloaded and the interpretations are collected in All_Interp.
602 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
603 -- the type-checking is similar to that of other calls.
605 procedure Analyze_Call (N : Node_Id) is
606 Actuals : constant List_Id := Parameter_Associations (N);
607 Nam : Node_Id := Name (N);
611 Success : Boolean := False;
613 function Name_Denotes_Function return Boolean;
614 -- If the type of the name is an access to subprogram, this may be
615 -- the type of a name, or the return type of the function being called.
616 -- If the name is not an entity then it can denote a protected function.
617 -- Until we distinguish Etype from Return_Type, we must use this
618 -- routine to resolve the meaning of the name in the call.
620 ---------------------------
621 -- Name_Denotes_Function --
622 ---------------------------
624 function Name_Denotes_Function return Boolean is
626 if Is_Entity_Name (Nam) then
627 return Ekind (Entity (Nam)) = E_Function;
629 elsif Nkind (Nam) = N_Selected_Component then
630 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
635 end Name_Denotes_Function;
637 -- Start of processing for Analyze_Call
640 -- Initialize the type of the result of the call to the error type,
641 -- which will be reset if the type is successfully resolved.
643 Set_Etype (N, Any_Type);
645 if not Is_Overloaded (Nam) then
647 -- Only one interpretation to check
649 if Ekind (Etype (Nam)) = E_Subprogram_Type then
650 Nam_Ent := Etype (Nam);
652 elsif Is_Access_Type (Etype (Nam))
653 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
654 and then not Name_Denotes_Function
656 Nam_Ent := Designated_Type (Etype (Nam));
657 Insert_Explicit_Dereference (Nam);
659 -- Selected component case. Simple entry or protected operation,
660 -- where the entry name is given by the selector name.
662 elsif Nkind (Nam) = N_Selected_Component then
663 Nam_Ent := Entity (Selector_Name (Nam));
665 if Ekind (Nam_Ent) /= E_Entry
666 and then Ekind (Nam_Ent) /= E_Entry_Family
667 and then Ekind (Nam_Ent) /= E_Function
668 and then Ekind (Nam_Ent) /= E_Procedure
670 Error_Msg_N ("name in call is not a callable entity", Nam);
671 Set_Etype (N, Any_Type);
675 -- If the name is an Indexed component, it can be a call to a member
676 -- of an entry family. The prefix must be a selected component whose
677 -- selector is the entry. Analyze_Procedure_Call normalizes several
678 -- kinds of call into this form.
680 elsif Nkind (Nam) = N_Indexed_Component then
682 if Nkind (Prefix (Nam)) = N_Selected_Component then
683 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
685 Error_Msg_N ("name in call is not a callable entity", Nam);
686 Set_Etype (N, Any_Type);
690 elsif not Is_Entity_Name (Nam) then
691 Error_Msg_N ("name in call is not a callable entity", Nam);
692 Set_Etype (N, Any_Type);
696 Nam_Ent := Entity (Nam);
698 -- If no interpretations, give error message
700 if not Is_Overloadable (Nam_Ent) then
702 L : constant Boolean := Is_List_Member (N);
703 K : constant Node_Kind := Nkind (Parent (N));
706 -- If the node is in a list whose parent is not an
707 -- expression then it must be an attempted procedure call.
709 if L and then K not in N_Subexpr then
710 if Ekind (Entity (Nam)) = E_Generic_Procedure then
712 ("must instantiate generic procedure& before call",
716 ("procedure or entry name expected", Nam);
719 -- Check for tasking cases where only an entry call will do
722 and then (K = N_Entry_Call_Alternative
723 or else K = N_Triggering_Alternative)
725 Error_Msg_N ("entry name expected", Nam);
727 -- Otherwise give general error message
730 Error_Msg_N ("invalid prefix in call", Nam);
738 Analyze_One_Call (N, Nam_Ent, True, Success);
741 -- An overloaded selected component must denote overloaded
742 -- operations of a concurrent type. The interpretations are
743 -- attached to the simple name of those operations.
745 if Nkind (Nam) = N_Selected_Component then
746 Nam := Selector_Name (Nam);
749 Get_First_Interp (Nam, X, It);
751 while Present (It.Nam) loop
754 -- Name may be call that returns an access to subprogram, or more
755 -- generally an overloaded expression one of whose interpretations
756 -- yields an access to subprogram. If the name is an entity, we
757 -- do not dereference, because the node is a call that returns
758 -- the access type: note difference between f(x), where the call
759 -- may return an access subprogram type, and f(x)(y), where the
760 -- type returned by the call to f is implicitly dereferenced to
761 -- analyze the outer call.
763 if Is_Access_Type (Nam_Ent) then
764 Nam_Ent := Designated_Type (Nam_Ent);
766 elsif Is_Access_Type (Etype (Nam_Ent))
767 and then not Is_Entity_Name (Nam)
768 and then Ekind (Designated_Type (Etype (Nam_Ent)))
771 Nam_Ent := Designated_Type (Etype (Nam_Ent));
774 Analyze_One_Call (N, Nam_Ent, False, Success);
776 -- If the interpretation succeeds, mark the proper type of the
777 -- prefix (any valid candidate will do). If not, remove the
778 -- candidate interpretation. This only needs to be done for
779 -- overloaded protected operations, for other entities disambi-
780 -- guation is done directly in Resolve.
783 Set_Etype (Nam, It.Typ);
785 elsif Nkind (Name (N)) = N_Selected_Component
786 or else Nkind (Name (N)) = N_Function_Call
791 Get_Next_Interp (X, It);
794 -- If the name is the result of a function call, it can only
795 -- be a call to a function returning an access to subprogram.
796 -- Insert explicit dereference.
798 if Nkind (Nam) = N_Function_Call then
799 Insert_Explicit_Dereference (Nam);
802 if Etype (N) = Any_Type then
804 -- None of the interpretations is compatible with the actuals
806 Diagnose_Call (N, Nam);
808 -- Special checks for uninstantiated put routines
810 if Nkind (N) = N_Procedure_Call_Statement
811 and then Is_Entity_Name (Nam)
812 and then Chars (Nam) = Name_Put
813 and then List_Length (Actuals) = 1
816 Arg : constant Node_Id := First (Actuals);
820 if Nkind (Arg) = N_Parameter_Association then
821 Typ := Etype (Explicit_Actual_Parameter (Arg));
826 if Is_Signed_Integer_Type (Typ) then
828 ("possible missing instantiation of " &
829 "'Text_'I'O.'Integer_'I'O!", Nam);
831 elsif Is_Modular_Integer_Type (Typ) then
833 ("possible missing instantiation of " &
834 "'Text_'I'O.'Modular_'I'O!", Nam);
836 elsif Is_Floating_Point_Type (Typ) then
838 ("possible missing instantiation of " &
839 "'Text_'I'O.'Float_'I'O!", Nam);
841 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
843 ("possible missing instantiation of " &
844 "'Text_'I'O.'Fixed_'I'O!", Nam);
846 elsif Is_Decimal_Fixed_Point_Type (Typ) then
848 ("possible missing instantiation of " &
849 "'Text_'I'O.'Decimal_'I'O!", Nam);
851 elsif Is_Enumeration_Type (Typ) then
853 ("possible missing instantiation of " &
854 "'Text_'I'O.'Enumeration_'I'O!", Nam);
859 elsif not Is_Overloaded (N)
860 and then Is_Entity_Name (Nam)
862 -- Resolution yields a single interpretation. Verify that
863 -- is has the proper capitalization.
865 Set_Entity_With_Style_Check (Nam, Entity (Nam));
866 Generate_Reference (Entity (Nam), Nam);
868 Set_Etype (Nam, Etype (Entity (Nam)));
870 Remove_Abstract_Operations (N);
877 ---------------------------
878 -- Analyze_Comparison_Op --
879 ---------------------------
881 procedure Analyze_Comparison_Op (N : Node_Id) is
882 L : constant Node_Id := Left_Opnd (N);
883 R : constant Node_Id := Right_Opnd (N);
884 Op_Id : Entity_Id := Entity (N);
887 Set_Etype (N, Any_Type);
888 Candidate_Type := Empty;
890 Analyze_Expression (L);
891 Analyze_Expression (R);
893 if Present (Op_Id) then
894 if Ekind (Op_Id) = E_Operator then
895 Find_Comparison_Types (L, R, Op_Id, N);
897 Add_One_Interp (N, Op_Id, Etype (Op_Id));
900 if Is_Overloaded (L) then
901 Set_Etype (L, Intersect_Types (L, R));
905 Op_Id := Get_Name_Entity_Id (Chars (N));
906 while Present (Op_Id) loop
907 if Ekind (Op_Id) = E_Operator then
908 Find_Comparison_Types (L, R, Op_Id, N);
910 Analyze_User_Defined_Binary_Op (N, Op_Id);
913 Op_Id := Homonym (Op_Id);
918 end Analyze_Comparison_Op;
920 ---------------------------
921 -- Analyze_Concatenation --
922 ---------------------------
924 -- If the only one-dimensional array type in scope is String,
925 -- this is the resulting type of the operation. Otherwise there
926 -- will be a concatenation operation defined for each user-defined
927 -- one-dimensional array.
929 procedure Analyze_Concatenation (N : Node_Id) is
930 L : constant Node_Id := Left_Opnd (N);
931 R : constant Node_Id := Right_Opnd (N);
932 Op_Id : Entity_Id := Entity (N);
937 Set_Etype (N, Any_Type);
938 Candidate_Type := Empty;
940 Analyze_Expression (L);
941 Analyze_Expression (R);
943 -- If the entity is present, the node appears in an instance,
944 -- and denotes a predefined concatenation operation. The resulting
945 -- type is obtained from the arguments when possible. If the arguments
946 -- are aggregates, the array type and the concatenation type must be
949 if Present (Op_Id) then
950 if Ekind (Op_Id) = E_Operator then
952 LT := Base_Type (Etype (L));
953 RT := Base_Type (Etype (R));
955 if Is_Array_Type (LT)
956 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
958 Add_One_Interp (N, Op_Id, LT);
960 elsif Is_Array_Type (RT)
961 and then LT = Base_Type (Component_Type (RT))
963 Add_One_Interp (N, Op_Id, RT);
965 -- If one operand is a string type or a user-defined array type,
966 -- and the other is a literal, result is of the specific type.
969 (Root_Type (LT) = Standard_String
970 or else Scope (LT) /= Standard_Standard)
971 and then Etype (R) = Any_String
973 Add_One_Interp (N, Op_Id, LT);
976 (Root_Type (RT) = Standard_String
977 or else Scope (RT) /= Standard_Standard)
978 and then Etype (L) = Any_String
980 Add_One_Interp (N, Op_Id, RT);
982 elsif not Is_Generic_Type (Etype (Op_Id)) then
983 Add_One_Interp (N, Op_Id, Etype (Op_Id));
986 -- Type and its operations must be visible
988 Set_Entity (N, Empty);
989 Analyze_Concatenation (N);
993 Add_One_Interp (N, Op_Id, Etype (Op_Id));
997 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
998 while Present (Op_Id) loop
999 if Ekind (Op_Id) = E_Operator then
1000 Find_Concatenation_Types (L, R, Op_Id, N);
1002 Analyze_User_Defined_Binary_Op (N, Op_Id);
1005 Op_Id := Homonym (Op_Id);
1010 end Analyze_Concatenation;
1012 ------------------------------------
1013 -- Analyze_Conditional_Expression --
1014 ------------------------------------
1016 procedure Analyze_Conditional_Expression (N : Node_Id) is
1017 Condition : constant Node_Id := First (Expressions (N));
1018 Then_Expr : constant Node_Id := Next (Condition);
1019 Else_Expr : constant Node_Id := Next (Then_Expr);
1021 Analyze_Expression (Condition);
1022 Analyze_Expression (Then_Expr);
1023 Analyze_Expression (Else_Expr);
1024 Set_Etype (N, Etype (Then_Expr));
1025 end Analyze_Conditional_Expression;
1027 -------------------------
1028 -- Analyze_Equality_Op --
1029 -------------------------
1031 procedure Analyze_Equality_Op (N : Node_Id) is
1032 Loc : constant Source_Ptr := Sloc (N);
1033 L : constant Node_Id := Left_Opnd (N);
1034 R : constant Node_Id := Right_Opnd (N);
1038 Set_Etype (N, Any_Type);
1039 Candidate_Type := Empty;
1041 Analyze_Expression (L);
1042 Analyze_Expression (R);
1044 -- If the entity is set, the node is a generic instance with a non-local
1045 -- reference to the predefined operator or to a user-defined function.
1046 -- It can also be an inequality that is expanded into the negation of a
1047 -- call to a user-defined equality operator.
1049 -- For the predefined case, the result is Boolean, regardless of the
1050 -- type of the operands. The operands may even be limited, if they are
1051 -- generic actuals. If they are overloaded, label the left argument with
1052 -- the common type that must be present, or with the type of the formal
1053 -- of the user-defined function.
1055 if Present (Entity (N)) then
1056 Op_Id := Entity (N);
1058 if Ekind (Op_Id) = E_Operator then
1059 Add_One_Interp (N, Op_Id, Standard_Boolean);
1061 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1064 if Is_Overloaded (L) then
1065 if Ekind (Op_Id) = E_Operator then
1066 Set_Etype (L, Intersect_Types (L, R));
1068 Set_Etype (L, Etype (First_Formal (Op_Id)));
1073 Op_Id := Get_Name_Entity_Id (Chars (N));
1074 while Present (Op_Id) loop
1075 if Ekind (Op_Id) = E_Operator then
1076 Find_Equality_Types (L, R, Op_Id, N);
1078 Analyze_User_Defined_Binary_Op (N, Op_Id);
1081 Op_Id := Homonym (Op_Id);
1085 -- If there was no match, and the operator is inequality, this may
1086 -- be a case where inequality has not been made explicit, as for
1087 -- tagged types. Analyze the node as the negation of an equality
1088 -- operation. This cannot be done earlier, because before analysis
1089 -- we cannot rule out the presence of an explicit inequality.
1091 if Etype (N) = Any_Type
1092 and then Nkind (N) = N_Op_Ne
1094 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1096 while Present (Op_Id) loop
1098 if Ekind (Op_Id) = E_Operator then
1099 Find_Equality_Types (L, R, Op_Id, N);
1101 Analyze_User_Defined_Binary_Op (N, Op_Id);
1104 Op_Id := Homonym (Op_Id);
1107 if Etype (N) /= Any_Type then
1108 Op_Id := Entity (N);
1114 Left_Opnd => Relocate_Node (Left_Opnd (N)),
1115 Right_Opnd => Relocate_Node (Right_Opnd (N)))));
1117 Set_Entity (Right_Opnd (N), Op_Id);
1123 end Analyze_Equality_Op;
1125 ----------------------------------
1126 -- Analyze_Explicit_Dereference --
1127 ----------------------------------
1129 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1130 Loc : constant Source_Ptr := Sloc (N);
1131 P : constant Node_Id := Prefix (N);
1137 function Is_Function_Type return Boolean;
1138 -- Check whether node may be interpreted as an implicit function call
1140 ----------------------
1141 -- Is_Function_Type --
1142 ----------------------
1144 function Is_Function_Type return Boolean is
1149 if not Is_Overloaded (N) then
1150 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1151 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1154 Get_First_Interp (N, I, It);
1156 while Present (It.Nam) loop
1157 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1158 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1163 Get_Next_Interp (I, It);
1168 end Is_Function_Type;
1170 -- Start of processing for Analyze_Explicit_Deference
1174 Set_Etype (N, Any_Type);
1176 -- Test for remote access to subprogram type, and if so return
1177 -- after rewriting the original tree.
1179 if Remote_AST_E_Dereference (P) then
1183 -- Normal processing for other than remote access to subprogram type
1185 if not Is_Overloaded (P) then
1186 if Is_Access_Type (Etype (P)) then
1188 -- Set the Etype. We need to go thru Is_For_Access_Subtypes
1189 -- to avoid other problems caused by the Private_Subtype
1190 -- and it is safe to go to the Base_Type because this is the
1191 -- same as converting the access value to its Base_Type.
1194 DT : Entity_Id := Designated_Type (Etype (P));
1197 if Ekind (DT) = E_Private_Subtype
1198 and then Is_For_Access_Subtype (DT)
1200 DT := Base_Type (DT);
1206 elsif Etype (P) /= Any_Type then
1207 Error_Msg_N ("prefix of dereference must be an access type", N);
1212 Get_First_Interp (P, I, It);
1214 while Present (It.Nam) loop
1217 if Is_Access_Type (T) then
1218 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1221 Get_Next_Interp (I, It);
1226 -- Error if no interpretation of the prefix has an access type.
1228 if Etype (N) = Any_Type then
1230 ("access type required in prefix of explicit dereference", P);
1231 Set_Etype (N, Any_Type);
1237 and then Nkind (Parent (N)) /= N_Indexed_Component
1239 and then (Nkind (Parent (N)) /= N_Function_Call
1240 or else N /= Name (Parent (N)))
1242 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1243 or else N /= Name (Parent (N)))
1245 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1246 and then (Nkind (Parent (N)) /= N_Attribute_Reference
1248 (Attribute_Name (Parent (N)) /= Name_Address
1250 Attribute_Name (Parent (N)) /= Name_Access))
1252 -- Name is a function call with no actuals, in a context that
1253 -- requires deproceduring (including as an actual in an enclosing
1254 -- function or procedure call). We can conceive of pathological cases
1255 -- where the prefix might include functions that return access to
1256 -- subprograms and others that return a regular type. Disambiguation
1257 -- of those will have to take place in Resolve. See e.g. 7117-014.
1260 Make_Function_Call (Loc,
1261 Name => Make_Explicit_Dereference (Loc, P),
1262 Parameter_Associations => New_List);
1264 -- If the prefix is overloaded, remove operations that have formals,
1265 -- we know that this is a parameterless call.
1267 if Is_Overloaded (P) then
1268 Get_First_Interp (P, I, It);
1269 while Present (It.Nam) loop
1272 if No (First_Formal (Base_Type (Designated_Type (T)))) then
1278 Get_Next_Interp (I, It);
1286 -- A value of remote access-to-class-wide must not be dereferenced
1289 Validate_Remote_Access_To_Class_Wide_Type (N);
1290 end Analyze_Explicit_Dereference;
1292 ------------------------
1293 -- Analyze_Expression --
1294 ------------------------
1296 procedure Analyze_Expression (N : Node_Id) is
1299 Check_Parameterless_Call (N);
1300 end Analyze_Expression;
1302 ------------------------------------
1303 -- Analyze_Indexed_Component_Form --
1304 ------------------------------------
1306 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
1307 P : constant Node_Id := Prefix (N);
1308 Exprs : constant List_Id := Expressions (N);
1314 procedure Process_Function_Call;
1315 -- Prefix in indexed component form is an overloadable entity,
1316 -- so the node is a function call. Reformat it as such.
1318 procedure Process_Indexed_Component;
1319 -- Prefix in indexed component form is actually an indexed component.
1320 -- This routine processes it, knowing that the prefix is already
1323 procedure Process_Indexed_Component_Or_Slice;
1324 -- An indexed component with a single index may designate a slice if
1325 -- the index is a subtype mark. This routine disambiguates these two
1326 -- cases by resolving the prefix to see if it is a subtype mark.
1328 procedure Process_Overloaded_Indexed_Component;
1329 -- If the prefix of an indexed component is overloaded, the proper
1330 -- interpretation is selected by the index types and the context.
1332 ---------------------------
1333 -- Process_Function_Call --
1334 ---------------------------
1336 procedure Process_Function_Call is
1340 Change_Node (N, N_Function_Call);
1342 Set_Parameter_Associations (N, Exprs);
1344 Actual := First (Parameter_Associations (N));
1345 while Present (Actual) loop
1347 Check_Parameterless_Call (Actual);
1348 Next_Actual (Actual);
1352 end Process_Function_Call;
1354 -------------------------------
1355 -- Process_Indexed_Component --
1356 -------------------------------
1358 procedure Process_Indexed_Component is
1360 Array_Type : Entity_Id;
1362 Entry_Family : Entity_Id;
1365 Exp := First (Exprs);
1367 if Is_Overloaded (P) then
1368 Process_Overloaded_Indexed_Component;
1371 Array_Type := Etype (P);
1373 -- Prefix must be appropriate for an array type.
1374 -- Dereference the prefix if it is an access type.
1376 if Is_Access_Type (Array_Type) then
1377 Array_Type := Designated_Type (Array_Type);
1378 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1381 if Is_Array_Type (Array_Type) then
1384 elsif (Is_Entity_Name (P)
1386 Ekind (Entity (P)) = E_Entry_Family)
1388 (Nkind (P) = N_Selected_Component
1390 Is_Entity_Name (Selector_Name (P))
1392 Ekind (Entity (Selector_Name (P))) = E_Entry_Family)
1394 if Is_Entity_Name (P) then
1395 Entry_Family := Entity (P);
1397 Entry_Family := Entity (Selector_Name (P));
1401 Set_Etype (N, Any_Type);
1403 if not Has_Compatible_Type
1404 (Exp, Entry_Index_Type (Entry_Family))
1406 Error_Msg_N ("invalid index type in entry name", N);
1408 elsif Present (Next (Exp)) then
1409 Error_Msg_N ("too many subscripts in entry reference", N);
1412 Set_Etype (N, Etype (P));
1417 elsif Is_Record_Type (Array_Type)
1418 and then Remote_AST_I_Dereference (P)
1422 elsif Array_Type = Any_Type then
1423 Set_Etype (N, Any_Type);
1426 -- Here we definitely have a bad indexing
1429 if Nkind (Parent (N)) = N_Requeue_Statement
1431 ((Is_Entity_Name (P)
1432 and then Ekind (Entity (P)) = E_Entry)
1434 (Nkind (P) = N_Selected_Component
1435 and then Is_Entity_Name (Selector_Name (P))
1436 and then Ekind (Entity (Selector_Name (P))) = E_Entry))
1439 ("REQUEUE does not permit parameters", First (Exprs));
1441 elsif Is_Entity_Name (P)
1442 and then Etype (P) = Standard_Void_Type
1444 Error_Msg_NE ("incorrect use of&", P, Entity (P));
1447 Error_Msg_N ("array type required in indexed component", P);
1450 Set_Etype (N, Any_Type);
1454 Index := First_Index (Array_Type);
1456 while Present (Index) and then Present (Exp) loop
1457 if not Has_Compatible_Type (Exp, Etype (Index)) then
1458 Wrong_Type (Exp, Etype (Index));
1459 Set_Etype (N, Any_Type);
1467 Set_Etype (N, Component_Type (Array_Type));
1469 if Present (Index) then
1471 ("too few subscripts in array reference", First (Exprs));
1473 elsif Present (Exp) then
1474 Error_Msg_N ("too many subscripts in array reference", Exp);
1477 end Process_Indexed_Component;
1479 ----------------------------------------
1480 -- Process_Indexed_Component_Or_Slice --
1481 ----------------------------------------
1483 procedure Process_Indexed_Component_Or_Slice is
1485 Exp := First (Exprs);
1486 while Present (Exp) loop
1487 Analyze_Expression (Exp);
1491 Exp := First (Exprs);
1493 -- If one index is present, and it is a subtype name, then the
1494 -- node denotes a slice (note that the case of an explicit range
1495 -- for a slice was already built as an N_Slice node in the first
1496 -- place, so that case is not handled here).
1498 -- We use a replace rather than a rewrite here because this is one
1499 -- of the cases in which the tree built by the parser is plain wrong.
1502 and then Is_Entity_Name (Exp)
1503 and then Is_Type (Entity (Exp))
1506 Make_Slice (Sloc (N),
1508 Discrete_Range => New_Copy (Exp)));
1511 -- Otherwise (more than one index present, or single index is not
1512 -- a subtype name), then we have the indexed component case.
1515 Process_Indexed_Component;
1517 end Process_Indexed_Component_Or_Slice;
1519 ------------------------------------------
1520 -- Process_Overloaded_Indexed_Component --
1521 ------------------------------------------
1523 procedure Process_Overloaded_Indexed_Component is
1532 Set_Etype (N, Any_Type);
1534 Get_First_Interp (P, I, It);
1535 while Present (It.Nam) loop
1538 if Is_Access_Type (Typ) then
1539 Typ := Designated_Type (Typ);
1540 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1543 if Is_Array_Type (Typ) then
1545 -- Got a candidate: verify that index types are compatible
1547 Index := First_Index (Typ);
1549 Exp := First (Exprs);
1550 while Present (Index) and then Present (Exp) loop
1551 if Has_Compatible_Type (Exp, Etype (Index)) then
1563 if Found and then No (Index) and then No (Exp) then
1565 Etype (Component_Type (Typ)),
1566 Etype (Component_Type (Typ)));
1570 Get_Next_Interp (I, It);
1573 if Etype (N) = Any_Type then
1574 Error_Msg_N ("no legal interpetation for indexed component", N);
1575 Set_Is_Overloaded (N, False);
1579 end Process_Overloaded_Indexed_Component;
1581 -- Start of processing for Analyze_Indexed_Component_Form
1584 -- Get name of array, function or type
1587 if Nkind (N) = N_Function_Call
1588 or else Nkind (N) = N_Procedure_Call_Statement
1590 -- If P is an explicit dereference whose prefix is of a
1591 -- remote access-to-subprogram type, then N has already
1592 -- been rewritten as a subprogram call and analyzed.
1597 pragma Assert (Nkind (N) = N_Indexed_Component);
1599 P_T := Base_Type (Etype (P));
1601 if Is_Entity_Name (P)
1602 or else Nkind (P) = N_Operator_Symbol
1606 if Ekind (U_N) in Type_Kind then
1608 -- Reformat node as a type conversion
1610 E := Remove_Head (Exprs);
1612 if Present (First (Exprs)) then
1614 ("argument of type conversion must be single expression", N);
1617 Change_Node (N, N_Type_Conversion);
1618 Set_Subtype_Mark (N, P);
1620 Set_Expression (N, E);
1622 -- After changing the node, call for the specific Analysis
1623 -- routine directly, to avoid a double call to the expander.
1625 Analyze_Type_Conversion (N);
1629 if Is_Overloadable (U_N) then
1630 Process_Function_Call;
1632 elsif Ekind (Etype (P)) = E_Subprogram_Type
1633 or else (Is_Access_Type (Etype (P))
1635 Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type)
1637 -- Call to access_to-subprogram with possible implicit dereference
1639 Process_Function_Call;
1641 elsif Is_Generic_Subprogram (U_N) then
1643 -- A common beginner's (or C++ templates fan) error
1645 Error_Msg_N ("generic subprogram cannot be called", N);
1646 Set_Etype (N, Any_Type);
1650 Process_Indexed_Component_Or_Slice;
1653 -- If not an entity name, prefix is an expression that may denote
1654 -- an array or an access-to-subprogram.
1657 if Ekind (P_T) = E_Subprogram_Type
1658 or else (Is_Access_Type (P_T)
1660 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
1662 Process_Function_Call;
1664 elsif Nkind (P) = N_Selected_Component
1665 and then Ekind (Entity (Selector_Name (P))) = E_Function
1667 Process_Function_Call;
1670 -- Indexed component, slice, or a call to a member of a family
1671 -- entry, which will be converted to an entry call later.
1673 Process_Indexed_Component_Or_Slice;
1676 end Analyze_Indexed_Component_Form;
1678 ------------------------
1679 -- Analyze_Logical_Op --
1680 ------------------------
1682 procedure Analyze_Logical_Op (N : Node_Id) is
1683 L : constant Node_Id := Left_Opnd (N);
1684 R : constant Node_Id := Right_Opnd (N);
1685 Op_Id : Entity_Id := Entity (N);
1688 Set_Etype (N, Any_Type);
1689 Candidate_Type := Empty;
1691 Analyze_Expression (L);
1692 Analyze_Expression (R);
1694 if Present (Op_Id) then
1696 if Ekind (Op_Id) = E_Operator then
1697 Find_Boolean_Types (L, R, Op_Id, N);
1699 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1703 Op_Id := Get_Name_Entity_Id (Chars (N));
1705 while Present (Op_Id) loop
1706 if Ekind (Op_Id) = E_Operator then
1707 Find_Boolean_Types (L, R, Op_Id, N);
1709 Analyze_User_Defined_Binary_Op (N, Op_Id);
1712 Op_Id := Homonym (Op_Id);
1717 end Analyze_Logical_Op;
1719 ---------------------------
1720 -- Analyze_Membership_Op --
1721 ---------------------------
1723 procedure Analyze_Membership_Op (N : Node_Id) is
1724 L : constant Node_Id := Left_Opnd (N);
1725 R : constant Node_Id := Right_Opnd (N);
1727 Index : Interp_Index;
1729 Found : Boolean := False;
1733 procedure Try_One_Interp (T1 : Entity_Id);
1734 -- Routine to try one proposed interpretation. Note that the context
1735 -- of the operation plays no role in resolving the arguments, so that
1736 -- if there is more than one interpretation of the operands that is
1737 -- compatible with a membership test, the operation is ambiguous.
1739 --------------------
1740 -- Try_One_Interp --
1741 --------------------
1743 procedure Try_One_Interp (T1 : Entity_Id) is
1745 if Has_Compatible_Type (R, T1) then
1747 and then Base_Type (T1) /= Base_Type (T_F)
1749 It := Disambiguate (L, I_F, Index, Any_Type);
1751 if It = No_Interp then
1752 Ambiguous_Operands (N);
1753 Set_Etype (L, Any_Type);
1771 -- Start of processing for Analyze_Membership_Op
1774 Analyze_Expression (L);
1776 if Nkind (R) = N_Range
1777 or else (Nkind (R) = N_Attribute_Reference
1778 and then Attribute_Name (R) = Name_Range)
1782 if not Is_Overloaded (L) then
1783 Try_One_Interp (Etype (L));
1786 Get_First_Interp (L, Index, It);
1788 while Present (It.Typ) loop
1789 Try_One_Interp (It.Typ);
1790 Get_Next_Interp (Index, It);
1794 -- If not a range, it can only be a subtype mark, or else there
1795 -- is a more basic error, to be diagnosed in Find_Type.
1800 if Is_Entity_Name (R) then
1801 Check_Fully_Declared (Entity (R), R);
1805 -- Compatibility between expression and subtype mark or range is
1806 -- checked during resolution. The result of the operation is Boolean
1809 Set_Etype (N, Standard_Boolean);
1810 end Analyze_Membership_Op;
1812 ----------------------
1813 -- Analyze_Negation --
1814 ----------------------
1816 procedure Analyze_Negation (N : Node_Id) is
1817 R : constant Node_Id := Right_Opnd (N);
1818 Op_Id : Entity_Id := Entity (N);
1821 Set_Etype (N, Any_Type);
1822 Candidate_Type := Empty;
1824 Analyze_Expression (R);
1826 if Present (Op_Id) then
1827 if Ekind (Op_Id) = E_Operator then
1828 Find_Negation_Types (R, Op_Id, N);
1830 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1834 Op_Id := Get_Name_Entity_Id (Chars (N));
1835 while Present (Op_Id) loop
1836 if Ekind (Op_Id) = E_Operator then
1837 Find_Negation_Types (R, Op_Id, N);
1839 Analyze_User_Defined_Unary_Op (N, Op_Id);
1842 Op_Id := Homonym (Op_Id);
1847 end Analyze_Negation;
1853 procedure Analyze_Null (N : Node_Id) is
1855 Set_Etype (N, Any_Access);
1858 ----------------------
1859 -- Analyze_One_Call --
1860 ----------------------
1862 procedure Analyze_One_Call
1866 Success : out Boolean)
1868 Actuals : constant List_Id := Parameter_Associations (N);
1869 Prev_T : constant Entity_Id := Etype (N);
1872 Is_Indexed : Boolean := False;
1873 Subp_Type : constant Entity_Id := Etype (Nam);
1876 procedure Indicate_Name_And_Type;
1877 -- If candidate interpretation matches, indicate name and type of
1878 -- result on call node.
1880 ----------------------------
1881 -- Indicate_Name_And_Type --
1882 ----------------------------
1884 procedure Indicate_Name_And_Type is
1886 Add_One_Interp (N, Nam, Etype (Nam));
1889 -- If the prefix of the call is a name, indicate the entity
1890 -- being called. If it is not a name, it is an expression that
1891 -- denotes an access to subprogram or else an entry or family. In
1892 -- the latter case, the name is a selected component, and the entity
1893 -- being called is noted on the selector.
1895 if not Is_Type (Nam) then
1896 if Is_Entity_Name (Name (N))
1897 or else Nkind (Name (N)) = N_Operator_Symbol
1899 Set_Entity (Name (N), Nam);
1901 elsif Nkind (Name (N)) = N_Selected_Component then
1902 Set_Entity (Selector_Name (Name (N)), Nam);
1906 if Debug_Flag_E and not Report then
1907 Write_Str (" Overloaded call ");
1908 Write_Int (Int (N));
1909 Write_Str (" compatible with ");
1910 Write_Int (Int (Nam));
1913 end Indicate_Name_And_Type;
1915 -- Start of processing for Analyze_One_Call
1920 -- If the subprogram has no formals, or if all the formals have
1921 -- defaults, and the return type is an array type, the node may
1922 -- denote an indexing of the result of a parameterless call.
1924 if Needs_No_Actuals (Nam)
1925 and then Present (Actuals)
1927 if Is_Array_Type (Subp_Type) then
1928 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type);
1930 elsif Is_Access_Type (Subp_Type)
1931 and then Is_Array_Type (Designated_Type (Subp_Type))
1934 Try_Indexed_Call (N, Nam, Designated_Type (Subp_Type));
1936 elsif Is_Access_Type (Subp_Type)
1937 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
1939 Is_Indexed := Try_Indirect_Call (N, Nam, Subp_Type);
1944 Normalize_Actuals (N, Nam, (Report and not Is_Indexed), Norm_OK);
1948 -- Mismatch in number or names of parameters
1950 if Debug_Flag_E then
1951 Write_Str (" normalization fails in call ");
1952 Write_Int (Int (N));
1953 Write_Str (" with subprogram ");
1954 Write_Int (Int (Nam));
1958 -- If the context expects a function call, discard any interpretation
1959 -- that is a procedure. If the node is not overloaded, leave as is for
1960 -- better error reporting when type mismatch is found.
1962 elsif Nkind (N) = N_Function_Call
1963 and then Is_Overloaded (Name (N))
1964 and then Ekind (Nam) = E_Procedure
1968 -- Ditto for function calls in a procedure context
1970 elsif Nkind (N) = N_Procedure_Call_Statement
1971 and then Is_Overloaded (Name (N))
1972 and then Etype (Nam) /= Standard_Void_Type
1976 elsif not Present (Actuals) then
1978 -- If Normalize succeeds, then there are default parameters for
1981 Indicate_Name_And_Type;
1983 elsif Ekind (Nam) = E_Operator then
1984 if Nkind (N) = N_Procedure_Call_Statement then
1988 -- This can occur when the prefix of the call is an operator
1989 -- name or an expanded name whose selector is an operator name.
1991 Analyze_Operator_Call (N, Nam);
1993 if Etype (N) /= Prev_T then
1995 -- There may be a user-defined operator that hides the
1996 -- current interpretation. We must check for this independently
1997 -- of the analysis of the call with the user-defined operation,
1998 -- because the parameter names may be wrong and yet the hiding
1999 -- takes place. Fixes b34014o.
2001 if Is_Overloaded (Name (N)) then
2007 Get_First_Interp (Name (N), I, It);
2008 while Present (It.Nam) loop
2009 if Ekind (It.Nam) /= E_Operator
2010 and then Hides_Op (It.Nam, Nam)
2013 (First_Actual (N), Etype (First_Formal (It.Nam)))
2014 and then (No (Next_Actual (First_Actual (N)))
2015 or else Has_Compatible_Type
2016 (Next_Actual (First_Actual (N)),
2017 Etype (Next_Formal (First_Formal (It.Nam)))))
2019 Set_Etype (N, Prev_T);
2023 Get_Next_Interp (I, It);
2028 -- If operator matches formals, record its name on the call.
2029 -- If the operator is overloaded, Resolve will select the
2030 -- correct one from the list of interpretations. The call
2031 -- node itself carries the first candidate.
2033 Set_Entity (Name (N), Nam);
2036 elsif Report and then Etype (N) = Any_Type then
2037 Error_Msg_N ("incompatible arguments for operator", N);
2041 -- Normalize_Actuals has chained the named associations in the
2042 -- correct order of the formals.
2044 Actual := First_Actual (N);
2045 Formal := First_Formal (Nam);
2046 while Present (Actual) and then Present (Formal) loop
2047 if Nkind (Parent (Actual)) /= N_Parameter_Association
2048 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
2050 if Has_Compatible_Type (Actual, Etype (Formal)) then
2051 Next_Actual (Actual);
2052 Next_Formal (Formal);
2055 if Debug_Flag_E then
2056 Write_Str (" type checking fails in call ");
2057 Write_Int (Int (N));
2058 Write_Str (" with formal ");
2059 Write_Int (Int (Formal));
2060 Write_Str (" in subprogram ");
2061 Write_Int (Int (Nam));
2065 if Report and not Is_Indexed then
2066 Wrong_Type (Actual, Etype (Formal));
2068 if Nkind (Actual) = N_Op_Eq
2069 and then Nkind (Left_Opnd (Actual)) = N_Identifier
2071 Formal := First_Formal (Nam);
2073 while Present (Formal) loop
2075 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
2077 ("possible misspelling of `='>`!", Actual);
2081 Next_Formal (Formal);
2085 if All_Errors_Mode then
2086 Error_Msg_Sloc := Sloc (Nam);
2088 if Is_Overloadable (Nam)
2089 and then Present (Alias (Nam))
2090 and then not Comes_From_Source (Nam)
2093 (" =='> in call to &#(inherited)!", Actual, Nam);
2095 elsif Ekind (Nam) = E_Subprogram_Type then
2097 Access_To_Subprogram_Typ :
2098 constant Entity_Id :=
2100 (Associated_Node_For_Itype (Nam));
2103 " =='> in call to dereference of &#!",
2104 Actual, Access_To_Subprogram_Typ);
2108 Error_Msg_NE (" =='> in call to &#!", Actual, Nam);
2118 -- Normalize_Actuals has verified that a default value exists
2119 -- for this formal. Current actual names a subsequent formal.
2121 Next_Formal (Formal);
2125 -- On exit, all actuals match
2127 Indicate_Name_And_Type;
2129 end Analyze_One_Call;
2131 ---------------------------
2132 -- Analyze_Operator_Call --
2133 ---------------------------
2135 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
2136 Op_Name : constant Name_Id := Chars (Op_Id);
2137 Act1 : constant Node_Id := First_Actual (N);
2138 Act2 : constant Node_Id := Next_Actual (Act1);
2141 -- Binary operator case
2143 if Present (Act2) then
2145 -- If more than two operands, then not binary operator after all
2147 if Present (Next_Actual (Act2)) then
2150 elsif Op_Name = Name_Op_Add
2151 or else Op_Name = Name_Op_Subtract
2152 or else Op_Name = Name_Op_Multiply
2153 or else Op_Name = Name_Op_Divide
2154 or else Op_Name = Name_Op_Mod
2155 or else Op_Name = Name_Op_Rem
2156 or else Op_Name = Name_Op_Expon
2158 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
2160 elsif Op_Name = Name_Op_And
2161 or else Op_Name = Name_Op_Or
2162 or else Op_Name = Name_Op_Xor
2164 Find_Boolean_Types (Act1, Act2, Op_Id, N);
2166 elsif Op_Name = Name_Op_Lt
2167 or else Op_Name = Name_Op_Le
2168 or else Op_Name = Name_Op_Gt
2169 or else Op_Name = Name_Op_Ge
2171 Find_Comparison_Types (Act1, Act2, Op_Id, N);
2173 elsif Op_Name = Name_Op_Eq
2174 or else Op_Name = Name_Op_Ne
2176 Find_Equality_Types (Act1, Act2, Op_Id, N);
2178 elsif Op_Name = Name_Op_Concat then
2179 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
2181 -- Is this else null correct, or should it be an abort???
2187 -- Unary operator case
2190 if Op_Name = Name_Op_Subtract or else
2191 Op_Name = Name_Op_Add or else
2192 Op_Name = Name_Op_Abs
2194 Find_Unary_Types (Act1, Op_Id, N);
2197 Op_Name = Name_Op_Not
2199 Find_Negation_Types (Act1, Op_Id, N);
2201 -- Is this else null correct, or should it be an abort???
2207 end Analyze_Operator_Call;
2209 -------------------------------------------
2210 -- Analyze_Overloaded_Selected_Component --
2211 -------------------------------------------
2213 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
2214 Nam : constant Node_Id := Prefix (N);
2215 Sel : constant Node_Id := Selector_Name (N);
2222 Set_Etype (Sel, Any_Type);
2224 Get_First_Interp (Nam, I, It);
2225 while Present (It.Typ) loop
2226 if Is_Access_Type (It.Typ) then
2227 T := Designated_Type (It.Typ);
2228 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2233 if Is_Record_Type (T) then
2234 Comp := First_Entity (T);
2235 while Present (Comp) loop
2236 if Chars (Comp) = Chars (Sel)
2237 and then Is_Visible_Component (Comp)
2239 Set_Entity_With_Style_Check (Sel, Comp);
2240 Generate_Reference (Comp, Sel);
2242 Set_Etype (Sel, Etype (Comp));
2243 Add_One_Interp (N, Etype (Comp), Etype (Comp));
2245 -- This also specifies a candidate to resolve the name.
2246 -- Further overloading will be resolved from context.
2248 Set_Etype (Nam, It.Typ);
2254 elsif Is_Concurrent_Type (T) then
2255 Comp := First_Entity (T);
2256 while Present (Comp)
2257 and then Comp /= First_Private_Entity (T)
2259 if Chars (Comp) = Chars (Sel) then
2260 if Is_Overloadable (Comp) then
2261 Add_One_Interp (Sel, Comp, Etype (Comp));
2263 Set_Entity_With_Style_Check (Sel, Comp);
2264 Generate_Reference (Comp, Sel);
2267 Set_Etype (Sel, Etype (Comp));
2268 Set_Etype (N, Etype (Comp));
2269 Set_Etype (Nam, It.Typ);
2271 -- For access type case, introduce explicit deference for
2272 -- more uniform treatment of entry calls.
2274 if Is_Access_Type (Etype (Nam)) then
2275 Insert_Explicit_Dereference (Nam);
2277 (Warn_On_Dereference, "?implicit dereference", N);
2284 Set_Is_Overloaded (N, Is_Overloaded (Sel));
2287 Get_Next_Interp (I, It);
2290 if Etype (N) = Any_Type then
2291 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
2292 Set_Entity (Sel, Any_Id);
2293 Set_Etype (Sel, Any_Type);
2295 end Analyze_Overloaded_Selected_Component;
2297 ----------------------------------
2298 -- Analyze_Qualified_Expression --
2299 ----------------------------------
2301 procedure Analyze_Qualified_Expression (N : Node_Id) is
2302 Mark : constant Entity_Id := Subtype_Mark (N);
2306 Set_Etype (N, Any_Type);
2310 if T = Any_Type then
2314 Check_Fully_Declared (T, N);
2315 Analyze_Expression (Expression (N));
2317 end Analyze_Qualified_Expression;
2323 procedure Analyze_Range (N : Node_Id) is
2324 L : constant Node_Id := Low_Bound (N);
2325 H : constant Node_Id := High_Bound (N);
2326 I1, I2 : Interp_Index;
2329 procedure Check_Common_Type (T1, T2 : Entity_Id);
2330 -- Verify the compatibility of two types, and choose the
2331 -- non universal one if the other is universal.
2333 procedure Check_High_Bound (T : Entity_Id);
2334 -- Test one interpretation of the low bound against all those
2335 -- of the high bound.
2337 procedure Check_Universal_Expression (N : Node_Id);
2338 -- In Ada83, reject bounds of a universal range that are not
2339 -- literals or entity names.
2341 -----------------------
2342 -- Check_Common_Type --
2343 -----------------------
2345 procedure Check_Common_Type (T1, T2 : Entity_Id) is
2347 if Covers (T1, T2) or else Covers (T2, T1) then
2348 if T1 = Universal_Integer
2349 or else T1 = Universal_Real
2350 or else T1 = Any_Character
2352 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
2355 Add_One_Interp (N, T1, T1);
2358 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
2361 end Check_Common_Type;
2363 ----------------------
2364 -- Check_High_Bound --
2365 ----------------------
2367 procedure Check_High_Bound (T : Entity_Id) is
2369 if not Is_Overloaded (H) then
2370 Check_Common_Type (T, Etype (H));
2372 Get_First_Interp (H, I2, It2);
2373 while Present (It2.Typ) loop
2374 Check_Common_Type (T, It2.Typ);
2375 Get_Next_Interp (I2, It2);
2378 end Check_High_Bound;
2380 -----------------------------
2381 -- Is_Universal_Expression --
2382 -----------------------------
2384 procedure Check_Universal_Expression (N : Node_Id) is
2386 if Etype (N) = Universal_Integer
2387 and then Nkind (N) /= N_Integer_Literal
2388 and then not Is_Entity_Name (N)
2389 and then Nkind (N) /= N_Attribute_Reference
2391 Error_Msg_N ("illegal bound in discrete range", N);
2393 end Check_Universal_Expression;
2395 -- Start of processing for Analyze_Range
2398 Set_Etype (N, Any_Type);
2399 Analyze_Expression (L);
2400 Analyze_Expression (H);
2402 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
2406 if not Is_Overloaded (L) then
2407 Check_High_Bound (Etype (L));
2409 Get_First_Interp (L, I1, It1);
2410 while Present (It1.Typ) loop
2411 Check_High_Bound (It1.Typ);
2412 Get_Next_Interp (I1, It1);
2416 -- If result is Any_Type, then we did not find a compatible pair
2418 if Etype (N) = Any_Type then
2419 Error_Msg_N ("incompatible types in range ", N);
2423 if Ada_Version = Ada_83
2425 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
2426 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
2428 Check_Universal_Expression (L);
2429 Check_Universal_Expression (H);
2433 -----------------------
2434 -- Analyze_Reference --
2435 -----------------------
2437 procedure Analyze_Reference (N : Node_Id) is
2438 P : constant Node_Id := Prefix (N);
2439 Acc_Type : Entity_Id;
2442 Acc_Type := Create_Itype (E_Allocator_Type, N);
2443 Set_Etype (Acc_Type, Acc_Type);
2444 Init_Size_Align (Acc_Type);
2445 Set_Directly_Designated_Type (Acc_Type, Etype (P));
2446 Set_Etype (N, Acc_Type);
2447 end Analyze_Reference;
2449 --------------------------------
2450 -- Analyze_Selected_Component --
2451 --------------------------------
2453 -- Prefix is a record type or a task or protected type. In the
2454 -- later case, the selector must denote a visible entry.
2456 procedure Analyze_Selected_Component (N : Node_Id) is
2457 Name : constant Node_Id := Prefix (N);
2458 Sel : constant Node_Id := Selector_Name (N);
2460 Entity_List : Entity_Id;
2461 Prefix_Type : Entity_Id;
2466 -- Start of processing for Analyze_Selected_Component
2469 Set_Etype (N, Any_Type);
2471 if Is_Overloaded (Name) then
2472 Analyze_Overloaded_Selected_Component (N);
2475 elsif Etype (Name) = Any_Type then
2476 Set_Entity (Sel, Any_Id);
2477 Set_Etype (Sel, Any_Type);
2481 -- Function calls that are prefixes of selected components must be
2482 -- fully resolved in case we need to build an actual subtype, or
2483 -- do some other operation requiring a fully resolved prefix.
2485 -- Note: Resolving all Nkinds of nodes here doesn't work.
2486 -- (Breaks 2129-008) ???.
2488 if Nkind (Name) = N_Function_Call then
2492 Prefix_Type := Etype (Name);
2495 if Is_Access_Type (Prefix_Type) then
2497 -- A RACW object can never be used as prefix of a selected
2498 -- component since that means it is dereferenced without
2499 -- being a controlling operand of a dispatching operation
2502 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
2503 and then Comes_From_Source (N)
2506 ("invalid dereference of a remote access to class-wide value",
2509 -- Normal case of selected component applied to access type
2512 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2515 Prefix_Type := Designated_Type (Prefix_Type);
2518 if Ekind (Prefix_Type) = E_Private_Subtype then
2519 Prefix_Type := Base_Type (Prefix_Type);
2522 Entity_List := Prefix_Type;
2524 -- For class-wide types, use the entity list of the root type. This
2525 -- indirection is specially important for private extensions because
2526 -- only the root type get switched (not the class-wide type).
2528 if Is_Class_Wide_Type (Prefix_Type) then
2529 Entity_List := Root_Type (Prefix_Type);
2532 Comp := First_Entity (Entity_List);
2534 -- If the selector has an original discriminant, the node appears in
2535 -- an instance. Replace the discriminant with the corresponding one
2536 -- in the current discriminated type. For nested generics, this must
2537 -- be done transitively, so note the new original discriminant.
2539 if Nkind (Sel) = N_Identifier
2540 and then Present (Original_Discriminant (Sel))
2542 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
2544 -- Mark entity before rewriting, for completeness and because
2545 -- subsequent semantic checks might examine the original node.
2547 Set_Entity (Sel, Comp);
2548 Rewrite (Selector_Name (N),
2549 New_Occurrence_Of (Comp, Sloc (N)));
2550 Set_Original_Discriminant (Selector_Name (N), Comp);
2551 Set_Etype (N, Etype (Comp));
2553 if Is_Access_Type (Etype (Name)) then
2554 Insert_Explicit_Dereference (Name);
2555 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2558 elsif Is_Record_Type (Prefix_Type) then
2560 -- Find component with given name
2562 while Present (Comp) loop
2563 if Chars (Comp) = Chars (Sel)
2564 and then Is_Visible_Component (Comp)
2566 Set_Entity_With_Style_Check (Sel, Comp);
2567 Generate_Reference (Comp, Sel);
2569 Set_Etype (Sel, Etype (Comp));
2571 if Ekind (Comp) = E_Discriminant then
2572 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
2574 ("cannot reference discriminant of Unchecked_Union",
2578 if Is_Generic_Type (Prefix_Type)
2580 Is_Generic_Type (Root_Type (Prefix_Type))
2582 Set_Original_Discriminant (Sel, Comp);
2586 -- Resolve the prefix early otherwise it is not possible to
2587 -- build the actual subtype of the component: it may need
2588 -- to duplicate this prefix and duplication is only allowed
2589 -- on fully resolved expressions.
2593 -- We never need an actual subtype for the case of a selection
2594 -- for a indexed component of a non-packed array, since in
2595 -- this case gigi generates all the checks and can find the
2596 -- necessary bounds information.
2598 -- We also do not need an actual subtype for the case of
2599 -- a first, last, length, or range attribute applied to a
2600 -- non-packed array, since gigi can again get the bounds in
2601 -- these cases (gigi cannot handle the packed case, since it
2602 -- has the bounds of the packed array type, not the original
2603 -- bounds of the type). However, if the prefix is itself a
2604 -- selected component, as in a.b.c (i), gigi may regard a.b.c
2605 -- as a dynamic-sized temporary, so we do generate an actual
2606 -- subtype for this case.
2608 Parent_N := Parent (N);
2610 if not Is_Packed (Etype (Comp))
2612 ((Nkind (Parent_N) = N_Indexed_Component
2613 and then Nkind (Name) /= N_Selected_Component)
2615 (Nkind (Parent_N) = N_Attribute_Reference
2616 and then (Attribute_Name (Parent_N) = Name_First
2618 Attribute_Name (Parent_N) = Name_Last
2620 Attribute_Name (Parent_N) = Name_Length
2622 Attribute_Name (Parent_N) = Name_Range)))
2624 Set_Etype (N, Etype (Comp));
2626 -- In all other cases, we currently build an actual subtype. It
2627 -- seems likely that many of these cases can be avoided, but
2628 -- right now, the front end makes direct references to the
2629 -- bounds (e.g. in generating a length check), and if we do
2630 -- not make an actual subtype, we end up getting a direct
2631 -- reference to a discriminant which will not do.
2635 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
2636 Insert_Action (N, Act_Decl);
2638 if No (Act_Decl) then
2639 Set_Etype (N, Etype (Comp));
2642 -- Component type depends on discriminants. Enter the
2643 -- main attributes of the subtype.
2646 Subt : constant Entity_Id :=
2647 Defining_Identifier (Act_Decl);
2650 Set_Etype (Subt, Base_Type (Etype (Comp)));
2651 Set_Ekind (Subt, Ekind (Etype (Comp)));
2652 Set_Etype (N, Subt);
2663 -- Ada 2005 (AI-252)
2665 if Ada_Version >= Ada_05
2666 and then Is_Tagged_Type (Prefix_Type)
2667 and then Try_Object_Operation (N)
2671 -- If the transformation fails, it will be necessary
2672 -- to redo the analysis with all errors enabled, to indicate
2673 -- candidate interpretations and reasons for each failure ???
2677 elsif Is_Private_Type (Prefix_Type) then
2679 -- Allow access only to discriminants of the type. If the
2680 -- type has no full view, gigi uses the parent type for
2681 -- the components, so we do the same here.
2683 if No (Full_View (Prefix_Type)) then
2684 Entity_List := Root_Type (Base_Type (Prefix_Type));
2685 Comp := First_Entity (Entity_List);
2688 while Present (Comp) loop
2689 if Chars (Comp) = Chars (Sel) then
2690 if Ekind (Comp) = E_Discriminant then
2691 Set_Entity_With_Style_Check (Sel, Comp);
2692 Generate_Reference (Comp, Sel);
2694 Set_Etype (Sel, Etype (Comp));
2695 Set_Etype (N, Etype (Comp));
2697 if Is_Generic_Type (Prefix_Type)
2699 Is_Generic_Type (Root_Type (Prefix_Type))
2701 Set_Original_Discriminant (Sel, Comp);
2706 ("invisible selector for }",
2707 N, First_Subtype (Prefix_Type));
2708 Set_Entity (Sel, Any_Id);
2709 Set_Etype (N, Any_Type);
2718 elsif Is_Concurrent_Type (Prefix_Type) then
2720 -- Prefix is concurrent type. Find visible operation with given name
2721 -- For a task, this can only include entries or discriminants if
2722 -- the task type is not an enclosing scope. If it is an enclosing
2723 -- scope (e.g. in an inner task) then all entities are visible, but
2724 -- the prefix must denote the enclosing scope, i.e. can only be
2725 -- a direct name or an expanded name.
2727 Set_Etype (Sel, Any_Type);
2728 In_Scope := In_Open_Scopes (Prefix_Type);
2730 while Present (Comp) loop
2731 if Chars (Comp) = Chars (Sel) then
2732 if Is_Overloadable (Comp) then
2733 Add_One_Interp (Sel, Comp, Etype (Comp));
2735 elsif Ekind (Comp) = E_Discriminant
2736 or else Ekind (Comp) = E_Entry_Family
2738 and then Is_Entity_Name (Name))
2740 Set_Entity_With_Style_Check (Sel, Comp);
2741 Generate_Reference (Comp, Sel);
2747 Set_Etype (Sel, Etype (Comp));
2748 Set_Etype (N, Etype (Comp));
2750 if Ekind (Comp) = E_Discriminant then
2751 Set_Original_Discriminant (Sel, Comp);
2754 -- For access type case, introduce explicit deference for
2755 -- more uniform treatment of entry calls.
2757 if Is_Access_Type (Etype (Name)) then
2758 Insert_Explicit_Dereference (Name);
2760 (Warn_On_Dereference, "?implicit dereference", N);
2766 exit when not In_Scope
2768 Comp = First_Private_Entity (Base_Type (Prefix_Type));
2771 Set_Is_Overloaded (N, Is_Overloaded (Sel));
2776 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
2779 -- If N still has no type, the component is not defined in the prefix
2781 if Etype (N) = Any_Type then
2783 -- If the prefix is a single concurrent object, use its name in
2784 -- the error message, rather than that of its anonymous type.
2786 if Is_Concurrent_Type (Prefix_Type)
2787 and then Is_Internal_Name (Chars (Prefix_Type))
2788 and then not Is_Derived_Type (Prefix_Type)
2789 and then Is_Entity_Name (Name)
2792 Error_Msg_Node_2 := Entity (Name);
2793 Error_Msg_NE ("no selector& for&", N, Sel);
2795 Check_Misspelled_Selector (Entity_List, Sel);
2797 elsif Is_Generic_Type (Prefix_Type)
2798 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
2799 and then Prefix_Type /= Etype (Prefix_Type)
2800 and then Is_Record_Type (Etype (Prefix_Type))
2802 -- If this is a derived formal type, the parent may have a
2803 -- different visibility at this point. Try for an inherited
2804 -- component before reporting an error.
2806 Set_Etype (Prefix (N), Etype (Prefix_Type));
2807 Analyze_Selected_Component (N);
2810 elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
2811 and then Is_Generic_Actual_Type (Prefix_Type)
2812 and then Present (Full_View (Prefix_Type))
2814 -- Similarly, if this the actual for a formal derived type, the
2815 -- component inherited from the generic parent may not be visible
2816 -- in the actual, but the selected component is legal.
2823 First_Component (Generic_Parent_Type (Parent (Prefix_Type)));
2824 while Present (Comp) loop
2825 if Chars (Comp) = Chars (Sel) then
2826 Set_Entity_With_Style_Check (Sel, Comp);
2827 Set_Etype (Sel, Etype (Comp));
2828 Set_Etype (N, Etype (Comp));
2832 Next_Component (Comp);
2835 pragma Assert (Etype (N) /= Any_Type);
2839 if Ekind (Prefix_Type) = E_Record_Subtype then
2841 -- Check whether this is a component of the base type
2842 -- which is absent from a statically constrained subtype.
2843 -- This will raise constraint error at run-time, but is
2844 -- not a compile-time error. When the selector is illegal
2845 -- for base type as well fall through and generate a
2846 -- compilation error anyway.
2848 Comp := First_Component (Base_Type (Prefix_Type));
2849 while Present (Comp) loop
2850 if Chars (Comp) = Chars (Sel)
2851 and then Is_Visible_Component (Comp)
2853 Set_Entity_With_Style_Check (Sel, Comp);
2854 Generate_Reference (Comp, Sel);
2855 Set_Etype (Sel, Etype (Comp));
2856 Set_Etype (N, Etype (Comp));
2858 -- Emit appropriate message. Gigi will replace the
2859 -- node subsequently with the appropriate Raise.
2861 Apply_Compile_Time_Constraint_Error
2862 (N, "component not present in }?",
2863 CE_Discriminant_Check_Failed,
2864 Ent => Prefix_Type, Rep => False);
2865 Set_Raises_Constraint_Error (N);
2869 Next_Component (Comp);
2874 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
2875 Error_Msg_NE ("no selector& for}", N, Sel);
2877 Check_Misspelled_Selector (Entity_List, Sel);
2881 Set_Entity (Sel, Any_Id);
2882 Set_Etype (Sel, Any_Type);
2884 end Analyze_Selected_Component;
2886 ---------------------------
2887 -- Analyze_Short_Circuit --
2888 ---------------------------
2890 procedure Analyze_Short_Circuit (N : Node_Id) is
2891 L : constant Node_Id := Left_Opnd (N);
2892 R : constant Node_Id := Right_Opnd (N);
2897 Analyze_Expression (L);
2898 Analyze_Expression (R);
2899 Set_Etype (N, Any_Type);
2901 if not Is_Overloaded (L) then
2903 if Root_Type (Etype (L)) = Standard_Boolean
2904 and then Has_Compatible_Type (R, Etype (L))
2906 Add_One_Interp (N, Etype (L), Etype (L));
2910 Get_First_Interp (L, Ind, It);
2912 while Present (It.Typ) loop
2913 if Root_Type (It.Typ) = Standard_Boolean
2914 and then Has_Compatible_Type (R, It.Typ)
2916 Add_One_Interp (N, It.Typ, It.Typ);
2919 Get_Next_Interp (Ind, It);
2923 -- Here we have failed to find an interpretation. Clearly we
2924 -- know that it is not the case that both operands can have
2925 -- an interpretation of Boolean, but this is by far the most
2926 -- likely intended interpretation. So we simply resolve both
2927 -- operands as Booleans, and at least one of these resolutions
2928 -- will generate an error message, and we do not need to give
2929 -- a further error message on the short circuit operation itself.
2931 if Etype (N) = Any_Type then
2932 Resolve (L, Standard_Boolean);
2933 Resolve (R, Standard_Boolean);
2934 Set_Etype (N, Standard_Boolean);
2936 end Analyze_Short_Circuit;
2942 procedure Analyze_Slice (N : Node_Id) is
2943 P : constant Node_Id := Prefix (N);
2944 D : constant Node_Id := Discrete_Range (N);
2945 Array_Type : Entity_Id;
2947 procedure Analyze_Overloaded_Slice;
2948 -- If the prefix is overloaded, select those interpretations that
2949 -- yield a one-dimensional array type.
2951 ------------------------------
2952 -- Analyze_Overloaded_Slice --
2953 ------------------------------
2955 procedure Analyze_Overloaded_Slice is
2961 Set_Etype (N, Any_Type);
2963 Get_First_Interp (P, I, It);
2964 while Present (It.Nam) loop
2967 if Is_Access_Type (Typ) then
2968 Typ := Designated_Type (Typ);
2969 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2972 if Is_Array_Type (Typ)
2973 and then Number_Dimensions (Typ) = 1
2974 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
2976 Add_One_Interp (N, Typ, Typ);
2979 Get_Next_Interp (I, It);
2982 if Etype (N) = Any_Type then
2983 Error_Msg_N ("expect array type in prefix of slice", N);
2985 end Analyze_Overloaded_Slice;
2987 -- Start of processing for Analyze_Slice
2993 if Is_Overloaded (P) then
2994 Analyze_Overloaded_Slice;
2997 Array_Type := Etype (P);
2998 Set_Etype (N, Any_Type);
3000 if Is_Access_Type (Array_Type) then
3001 Array_Type := Designated_Type (Array_Type);
3002 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3005 if not Is_Array_Type (Array_Type) then
3006 Wrong_Type (P, Any_Array);
3008 elsif Number_Dimensions (Array_Type) > 1 then
3010 ("type is not one-dimensional array in slice prefix", N);
3013 Has_Compatible_Type (D, Etype (First_Index (Array_Type)))
3015 Wrong_Type (D, Etype (First_Index (Array_Type)));
3018 Set_Etype (N, Array_Type);
3023 -----------------------------
3024 -- Analyze_Type_Conversion --
3025 -----------------------------
3027 procedure Analyze_Type_Conversion (N : Node_Id) is
3028 Expr : constant Node_Id := Expression (N);
3032 -- If Conversion_OK is set, then the Etype is already set, and the
3033 -- only processing required is to analyze the expression. This is
3034 -- used to construct certain "illegal" conversions which are not
3035 -- allowed by Ada semantics, but can be handled OK by Gigi, see
3036 -- Sinfo for further details.
3038 if Conversion_OK (N) then
3043 -- Otherwise full type analysis is required, as well as some semantic
3044 -- checks to make sure the argument of the conversion is appropriate.
3046 Find_Type (Subtype_Mark (N));
3047 T := Entity (Subtype_Mark (N));
3049 Check_Fully_Declared (T, N);
3050 Analyze_Expression (Expr);
3051 Validate_Remote_Type_Type_Conversion (N);
3053 -- Only remaining step is validity checks on the argument. These
3054 -- are skipped if the conversion does not come from the source.
3056 if not Comes_From_Source (N) then
3059 elsif Nkind (Expr) = N_Null then
3060 Error_Msg_N ("argument of conversion cannot be null", N);
3061 Error_Msg_N ("\use qualified expression instead", N);
3062 Set_Etype (N, Any_Type);
3064 elsif Nkind (Expr) = N_Aggregate then
3065 Error_Msg_N ("argument of conversion cannot be aggregate", N);
3066 Error_Msg_N ("\use qualified expression instead", N);
3068 elsif Nkind (Expr) = N_Allocator then
3069 Error_Msg_N ("argument of conversion cannot be an allocator", N);
3070 Error_Msg_N ("\use qualified expression instead", N);
3072 elsif Nkind (Expr) = N_String_Literal then
3073 Error_Msg_N ("argument of conversion cannot be string literal", N);
3074 Error_Msg_N ("\use qualified expression instead", N);
3076 elsif Nkind (Expr) = N_Character_Literal then
3077 if Ada_Version = Ada_83 then
3080 Error_Msg_N ("argument of conversion cannot be character literal",
3082 Error_Msg_N ("\use qualified expression instead", N);
3085 elsif Nkind (Expr) = N_Attribute_Reference
3087 (Attribute_Name (Expr) = Name_Access or else
3088 Attribute_Name (Expr) = Name_Unchecked_Access or else
3089 Attribute_Name (Expr) = Name_Unrestricted_Access)
3091 Error_Msg_N ("argument of conversion cannot be access", N);
3092 Error_Msg_N ("\use qualified expression instead", N);
3094 end Analyze_Type_Conversion;
3096 ----------------------
3097 -- Analyze_Unary_Op --
3098 ----------------------
3100 procedure Analyze_Unary_Op (N : Node_Id) is
3101 R : constant Node_Id := Right_Opnd (N);
3102 Op_Id : Entity_Id := Entity (N);
3105 Set_Etype (N, Any_Type);
3106 Candidate_Type := Empty;
3108 Analyze_Expression (R);
3110 if Present (Op_Id) then
3111 if Ekind (Op_Id) = E_Operator then
3112 Find_Unary_Types (R, Op_Id, N);
3114 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3118 Op_Id := Get_Name_Entity_Id (Chars (N));
3119 while Present (Op_Id) loop
3120 if Ekind (Op_Id) = E_Operator then
3121 if No (Next_Entity (First_Entity (Op_Id))) then
3122 Find_Unary_Types (R, Op_Id, N);
3125 elsif Is_Overloadable (Op_Id) then
3126 Analyze_User_Defined_Unary_Op (N, Op_Id);
3129 Op_Id := Homonym (Op_Id);
3134 end Analyze_Unary_Op;
3136 ----------------------------------
3137 -- Analyze_Unchecked_Expression --
3138 ----------------------------------
3140 procedure Analyze_Unchecked_Expression (N : Node_Id) is
3142 Analyze (Expression (N), Suppress => All_Checks);
3143 Set_Etype (N, Etype (Expression (N)));
3144 Save_Interps (Expression (N), N);
3145 end Analyze_Unchecked_Expression;
3147 ---------------------------------------
3148 -- Analyze_Unchecked_Type_Conversion --
3149 ---------------------------------------
3151 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
3153 Find_Type (Subtype_Mark (N));
3154 Analyze_Expression (Expression (N));
3155 Set_Etype (N, Entity (Subtype_Mark (N)));
3156 end Analyze_Unchecked_Type_Conversion;
3158 ------------------------------------
3159 -- Analyze_User_Defined_Binary_Op --
3160 ------------------------------------
3162 procedure Analyze_User_Defined_Binary_Op
3167 -- Only do analysis if the operator Comes_From_Source, since otherwise
3168 -- the operator was generated by the expander, and all such operators
3169 -- always refer to the operators in package Standard.
3171 if Comes_From_Source (N) then
3173 F1 : constant Entity_Id := First_Formal (Op_Id);
3174 F2 : constant Entity_Id := Next_Formal (F1);
3177 -- Verify that Op_Id is a visible binary function. Note that since
3178 -- we know Op_Id is overloaded, potentially use visible means use
3179 -- visible for sure (RM 9.4(11)).
3181 if Ekind (Op_Id) = E_Function
3182 and then Present (F2)
3183 and then (Is_Immediately_Visible (Op_Id)
3184 or else Is_Potentially_Use_Visible (Op_Id))
3185 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
3186 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
3188 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3190 if Debug_Flag_E then
3191 Write_Str ("user defined operator ");
3192 Write_Name (Chars (Op_Id));
3193 Write_Str (" on node ");
3194 Write_Int (Int (N));
3200 end Analyze_User_Defined_Binary_Op;
3202 -----------------------------------
3203 -- Analyze_User_Defined_Unary_Op --
3204 -----------------------------------
3206 procedure Analyze_User_Defined_Unary_Op
3211 -- Only do analysis if the operator Comes_From_Source, since otherwise
3212 -- the operator was generated by the expander, and all such operators
3213 -- always refer to the operators in package Standard.
3215 if Comes_From_Source (N) then
3217 F : constant Entity_Id := First_Formal (Op_Id);
3220 -- Verify that Op_Id is a visible unary function. Note that since
3221 -- we know Op_Id is overloaded, potentially use visible means use
3222 -- visible for sure (RM 9.4(11)).
3224 if Ekind (Op_Id) = E_Function
3225 and then No (Next_Formal (F))
3226 and then (Is_Immediately_Visible (Op_Id)
3227 or else Is_Potentially_Use_Visible (Op_Id))
3228 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
3230 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3234 end Analyze_User_Defined_Unary_Op;
3236 ---------------------------
3237 -- Check_Arithmetic_Pair --
3238 ---------------------------
3240 procedure Check_Arithmetic_Pair
3241 (T1, T2 : Entity_Id;
3245 Op_Name : constant Name_Id := Chars (Op_Id);
3247 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
3248 -- Get specific type (i.e. non-universal type if there is one)
3254 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
3256 if T1 = Universal_Integer or else T1 = Universal_Real then
3257 return Base_Type (T2);
3259 return Base_Type (T1);
3263 -- Start of processing for Check_Arithmetic_Pair
3266 if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
3268 if Is_Numeric_Type (T1)
3269 and then Is_Numeric_Type (T2)
3270 and then (Covers (T1, T2) or else Covers (T2, T1))
3272 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3275 elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
3277 if Is_Fixed_Point_Type (T1)
3278 and then (Is_Fixed_Point_Type (T2)
3279 or else T2 = Universal_Real)
3281 -- If Treat_Fixed_As_Integer is set then the Etype is already set
3282 -- and no further processing is required (this is the case of an
3283 -- operator constructed by Exp_Fixd for a fixed point operation)
3284 -- Otherwise add one interpretation with universal fixed result
3285 -- If the operator is given in functional notation, it comes
3286 -- from source and Fixed_As_Integer cannot apply.
3288 if Nkind (N) not in N_Op
3289 or else not Treat_Fixed_As_Integer (N)
3291 Add_One_Interp (N, Op_Id, Universal_Fixed);
3294 elsif Is_Fixed_Point_Type (T2)
3295 and then (Nkind (N) not in N_Op
3296 or else not Treat_Fixed_As_Integer (N))
3297 and then T1 = Universal_Real
3299 Add_One_Interp (N, Op_Id, Universal_Fixed);
3301 elsif Is_Numeric_Type (T1)
3302 and then Is_Numeric_Type (T2)
3303 and then (Covers (T1, T2) or else Covers (T2, T1))
3305 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3307 elsif Is_Fixed_Point_Type (T1)
3308 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3309 or else T2 = Universal_Integer)
3311 Add_One_Interp (N, Op_Id, T1);
3313 elsif T2 = Universal_Real
3314 and then Base_Type (T1) = Base_Type (Standard_Integer)
3315 and then Op_Name = Name_Op_Multiply
3317 Add_One_Interp (N, Op_Id, Any_Fixed);
3319 elsif T1 = Universal_Real
3320 and then Base_Type (T2) = Base_Type (Standard_Integer)
3322 Add_One_Interp (N, Op_Id, Any_Fixed);
3324 elsif Is_Fixed_Point_Type (T2)
3325 and then (Base_Type (T1) = Base_Type (Standard_Integer)
3326 or else T1 = Universal_Integer)
3327 and then Op_Name = Name_Op_Multiply
3329 Add_One_Interp (N, Op_Id, T2);
3331 elsif T1 = Universal_Real and then T2 = Universal_Integer then
3332 Add_One_Interp (N, Op_Id, T1);
3334 elsif T2 = Universal_Real
3335 and then T1 = Universal_Integer
3336 and then Op_Name = Name_Op_Multiply
3338 Add_One_Interp (N, Op_Id, T2);
3341 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
3343 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
3344 -- set does not require any special processing, since the Etype is
3345 -- already set (case of operation constructed by Exp_Fixed).
3347 if Is_Integer_Type (T1)
3348 and then (Covers (T1, T2) or else Covers (T2, T1))
3350 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3353 elsif Op_Name = Name_Op_Expon then
3354 if Is_Numeric_Type (T1)
3355 and then not Is_Fixed_Point_Type (T1)
3356 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3357 or else T2 = Universal_Integer)
3359 Add_One_Interp (N, Op_Id, Base_Type (T1));
3362 else pragma Assert (Nkind (N) in N_Op_Shift);
3364 -- If not one of the predefined operators, the node may be one
3365 -- of the intrinsic functions. Its kind is always specific, and
3366 -- we can use it directly, rather than the name of the operation.
3368 if Is_Integer_Type (T1)
3369 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3370 or else T2 = Universal_Integer)
3372 Add_One_Interp (N, Op_Id, Base_Type (T1));
3375 end Check_Arithmetic_Pair;
3377 -------------------------------
3378 -- Check_Misspelled_Selector --
3379 -------------------------------
3381 procedure Check_Misspelled_Selector
3382 (Prefix : Entity_Id;
3385 Max_Suggestions : constant := 2;
3386 Nr_Of_Suggestions : Natural := 0;
3388 Suggestion_1 : Entity_Id := Empty;
3389 Suggestion_2 : Entity_Id := Empty;
3394 -- All the components of the prefix of selector Sel are matched
3395 -- against Sel and a count is maintained of possible misspellings.
3396 -- When at the end of the analysis there are one or two (not more!)
3397 -- possible misspellings, these misspellings will be suggested as
3398 -- possible correction.
3400 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
3402 -- Concurrent types should be handled as well ???
3407 Get_Name_String (Chars (Sel));
3410 S : constant String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
3413 Comp := First_Entity (Prefix);
3414 while Nr_Of_Suggestions <= Max_Suggestions
3415 and then Present (Comp)
3417 if Is_Visible_Component (Comp) then
3418 Get_Name_String (Chars (Comp));
3420 if Is_Bad_Spelling_Of (Name_Buffer (1 .. Name_Len), S) then
3421 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
3423 case Nr_Of_Suggestions is
3424 when 1 => Suggestion_1 := Comp;
3425 when 2 => Suggestion_2 := Comp;
3426 when others => exit;
3431 Comp := Next_Entity (Comp);
3434 -- Report at most two suggestions
3436 if Nr_Of_Suggestions = 1 then
3437 Error_Msg_NE ("\possible misspelling of&", Sel, Suggestion_1);
3439 elsif Nr_Of_Suggestions = 2 then
3440 Error_Msg_Node_2 := Suggestion_2;
3441 Error_Msg_NE ("\possible misspelling of& or&",
3445 end Check_Misspelled_Selector;
3447 ----------------------
3448 -- Defined_In_Scope --
3449 ----------------------
3451 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
3453 S1 : constant Entity_Id := Scope (Base_Type (T));
3456 or else (S1 = System_Aux_Id and then S = Scope (S1));
3457 end Defined_In_Scope;
3463 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
3470 Void_Interp_Seen : Boolean := False;
3473 if Ada_Version >= Ada_05 then
3474 Actual := First_Actual (N);
3475 while Present (Actual) loop
3477 -- Ada 2005 (AI-50217): Post an error in case of premature
3478 -- usage of an entity from the limited view.
3480 if not Analyzed (Etype (Actual))
3481 and then From_With_Type (Etype (Actual))
3483 Error_Msg_Qual_Level := 1;
3485 ("missing with_clause for scope of imported type&",
3486 Actual, Etype (Actual));
3487 Error_Msg_Qual_Level := 0;
3490 Next_Actual (Actual);
3494 -- Analyze each candidate call again, with full error reporting
3498 ("no candidate interpretations match the actuals:!", Nam);
3499 Err_Mode := All_Errors_Mode;
3500 All_Errors_Mode := True;
3502 -- If this is a call to an operation of a concurrent type,
3503 -- the failed interpretations have been removed from the
3504 -- name. Recover them to provide full diagnostics.
3506 if Nkind (Parent (Nam)) = N_Selected_Component then
3507 Set_Entity (Nam, Empty);
3508 New_Nam := New_Copy_Tree (Parent (Nam));
3509 Set_Is_Overloaded (New_Nam, False);
3510 Set_Is_Overloaded (Selector_Name (New_Nam), False);
3511 Set_Parent (New_Nam, Parent (Parent (Nam)));
3512 Analyze_Selected_Component (New_Nam);
3513 Get_First_Interp (Selector_Name (New_Nam), X, It);
3515 Get_First_Interp (Nam, X, It);
3518 while Present (It.Nam) loop
3519 if Etype (It.Nam) = Standard_Void_Type then
3520 Void_Interp_Seen := True;
3523 Analyze_One_Call (N, It.Nam, True, Success);
3524 Get_Next_Interp (X, It);
3527 if Nkind (N) = N_Function_Call then
3528 Get_First_Interp (Nam, X, It);
3529 while Present (It.Nam) loop
3530 if Ekind (It.Nam) = E_Function
3531 or else Ekind (It.Nam) = E_Operator
3535 Get_Next_Interp (X, It);
3539 -- If all interpretations are procedures, this deserves a
3540 -- more precise message. Ditto if this appears as the prefix
3541 -- of a selected component, which may be a lexical error.
3544 ("\context requires function call, found procedure name", Nam);
3546 if Nkind (Parent (N)) = N_Selected_Component
3547 and then N = Prefix (Parent (N))
3550 "\period should probably be semicolon", Parent (N));
3553 elsif Nkind (N) = N_Procedure_Call_Statement
3554 and then not Void_Interp_Seen
3557 "\function name found in procedure call", Nam);
3560 All_Errors_Mode := Err_Mode;
3563 ---------------------------
3564 -- Find_Arithmetic_Types --
3565 ---------------------------
3567 procedure Find_Arithmetic_Types
3572 Index1 : Interp_Index;
3573 Index2 : Interp_Index;
3577 procedure Check_Right_Argument (T : Entity_Id);
3578 -- Check right operand of operator
3580 --------------------------
3581 -- Check_Right_Argument --
3582 --------------------------
3584 procedure Check_Right_Argument (T : Entity_Id) is
3586 if not Is_Overloaded (R) then
3587 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
3589 Get_First_Interp (R, Index2, It2);
3590 while Present (It2.Typ) loop
3591 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
3592 Get_Next_Interp (Index2, It2);
3595 end Check_Right_Argument;
3597 -- Start processing for Find_Arithmetic_Types
3600 if not Is_Overloaded (L) then
3601 Check_Right_Argument (Etype (L));
3604 Get_First_Interp (L, Index1, It1);
3606 while Present (It1.Typ) loop
3607 Check_Right_Argument (It1.Typ);
3608 Get_Next_Interp (Index1, It1);
3612 end Find_Arithmetic_Types;
3614 ------------------------
3615 -- Find_Boolean_Types --
3616 ------------------------
3618 procedure Find_Boolean_Types
3623 Index : Interp_Index;
3626 procedure Check_Numeric_Argument (T : Entity_Id);
3627 -- Special case for logical operations one of whose operands is an
3628 -- integer literal. If both are literal the result is any modular type.
3630 ----------------------------
3631 -- Check_Numeric_Argument --
3632 ----------------------------
3634 procedure Check_Numeric_Argument (T : Entity_Id) is
3636 if T = Universal_Integer then
3637 Add_One_Interp (N, Op_Id, Any_Modular);
3639 elsif Is_Modular_Integer_Type (T) then
3640 Add_One_Interp (N, Op_Id, T);
3642 end Check_Numeric_Argument;
3644 -- Start of processing for Find_Boolean_Types
3647 if not Is_Overloaded (L) then
3648 if Etype (L) = Universal_Integer
3649 or else Etype (L) = Any_Modular
3651 if not Is_Overloaded (R) then
3652 Check_Numeric_Argument (Etype (R));
3655 Get_First_Interp (R, Index, It);
3656 while Present (It.Typ) loop
3657 Check_Numeric_Argument (It.Typ);
3658 Get_Next_Interp (Index, It);
3662 elsif Valid_Boolean_Arg (Etype (L))
3663 and then Has_Compatible_Type (R, Etype (L))
3665 Add_One_Interp (N, Op_Id, Etype (L));
3669 Get_First_Interp (L, Index, It);
3670 while Present (It.Typ) loop
3671 if Valid_Boolean_Arg (It.Typ)
3672 and then Has_Compatible_Type (R, It.Typ)
3674 Add_One_Interp (N, Op_Id, It.Typ);
3677 Get_Next_Interp (Index, It);
3680 end Find_Boolean_Types;
3682 ---------------------------
3683 -- Find_Comparison_Types --
3684 ---------------------------
3686 procedure Find_Comparison_Types
3691 Index : Interp_Index;
3693 Found : Boolean := False;
3696 Scop : Entity_Id := Empty;
3698 procedure Try_One_Interp (T1 : Entity_Id);
3699 -- Routine to try one proposed interpretation. Note that the context
3700 -- of the operator plays no role in resolving the arguments, so that
3701 -- if there is more than one interpretation of the operands that is
3702 -- compatible with comparison, the operation is ambiguous.
3704 --------------------
3705 -- Try_One_Interp --
3706 --------------------
3708 procedure Try_One_Interp (T1 : Entity_Id) is
3711 -- If the operator is an expanded name, then the type of the operand
3712 -- must be defined in the corresponding scope. If the type is
3713 -- universal, the context will impose the correct type.
3716 and then not Defined_In_Scope (T1, Scop)
3717 and then T1 /= Universal_Integer
3718 and then T1 /= Universal_Real
3719 and then T1 /= Any_String
3720 and then T1 /= Any_Composite
3725 if Valid_Comparison_Arg (T1)
3726 and then Has_Compatible_Type (R, T1)
3729 and then Base_Type (T1) /= Base_Type (T_F)
3731 It := Disambiguate (L, I_F, Index, Any_Type);
3733 if It = No_Interp then
3734 Ambiguous_Operands (N);
3735 Set_Etype (L, Any_Type);
3749 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
3754 -- Start processing for Find_Comparison_Types
3757 -- If left operand is aggregate, the right operand has to
3758 -- provide a usable type for it.
3760 if Nkind (L) = N_Aggregate
3761 and then Nkind (R) /= N_Aggregate
3763 Find_Comparison_Types (R, L, Op_Id, N);
3767 if Nkind (N) = N_Function_Call
3768 and then Nkind (Name (N)) = N_Expanded_Name
3770 Scop := Entity (Prefix (Name (N)));
3772 -- The prefix may be a package renaming, and the subsequent test
3773 -- requires the original package.
3775 if Ekind (Scop) = E_Package
3776 and then Present (Renamed_Entity (Scop))
3778 Scop := Renamed_Entity (Scop);
3779 Set_Entity (Prefix (Name (N)), Scop);
3783 if not Is_Overloaded (L) then
3784 Try_One_Interp (Etype (L));
3787 Get_First_Interp (L, Index, It);
3788 while Present (It.Typ) loop
3789 Try_One_Interp (It.Typ);
3790 Get_Next_Interp (Index, It);
3793 end Find_Comparison_Types;
3795 ----------------------------------------
3796 -- Find_Non_Universal_Interpretations --
3797 ----------------------------------------
3799 procedure Find_Non_Universal_Interpretations
3805 Index : Interp_Index;
3809 if T1 = Universal_Integer
3810 or else T1 = Universal_Real
3812 if not Is_Overloaded (R) then
3814 (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
3816 Get_First_Interp (R, Index, It);
3817 while Present (It.Typ) loop
3818 if Covers (It.Typ, T1) then
3820 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
3823 Get_Next_Interp (Index, It);
3827 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
3829 end Find_Non_Universal_Interpretations;
3831 ------------------------------
3832 -- Find_Concatenation_Types --
3833 ------------------------------
3835 procedure Find_Concatenation_Types
3840 Op_Type : constant Entity_Id := Etype (Op_Id);
3843 if Is_Array_Type (Op_Type)
3844 and then not Is_Limited_Type (Op_Type)
3846 and then (Has_Compatible_Type (L, Op_Type)
3848 Has_Compatible_Type (L, Component_Type (Op_Type)))
3850 and then (Has_Compatible_Type (R, Op_Type)
3852 Has_Compatible_Type (R, Component_Type (Op_Type)))
3854 Add_One_Interp (N, Op_Id, Op_Type);
3856 end Find_Concatenation_Types;
3858 -------------------------
3859 -- Find_Equality_Types --
3860 -------------------------
3862 procedure Find_Equality_Types
3867 Index : Interp_Index;
3869 Found : Boolean := False;
3872 Scop : Entity_Id := Empty;
3874 procedure Try_One_Interp (T1 : Entity_Id);
3875 -- The context of the operator plays no role in resolving the
3876 -- arguments, so that if there is more than one interpretation
3877 -- of the operands that is compatible with equality, the construct
3878 -- is ambiguous and an error can be emitted now, after trying to
3879 -- disambiguate, i.e. applying preference rules.
3881 --------------------
3882 -- Try_One_Interp --
3883 --------------------
3885 procedure Try_One_Interp (T1 : Entity_Id) is
3887 -- If the operator is an expanded name, then the type of the operand
3888 -- must be defined in the corresponding scope. If the type is
3889 -- universal, the context will impose the correct type. An anonymous
3890 -- type for a 'Access reference is also universal in this sense, as
3891 -- the actual type is obtained from context.
3894 and then not Defined_In_Scope (T1, Scop)
3895 and then T1 /= Universal_Integer
3896 and then T1 /= Universal_Real
3897 and then T1 /= Any_Access
3898 and then T1 /= Any_String
3899 and then T1 /= Any_Composite
3900 and then (Ekind (T1) /= E_Access_Subprogram_Type
3901 or else Comes_From_Source (T1))
3906 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
3907 -- Do not allow anonymous access types in equality operators.
3909 if Ada_Version < Ada_05
3910 and then Ekind (T1) = E_Anonymous_Access_Type
3915 if T1 /= Standard_Void_Type
3916 and then not Is_Limited_Type (T1)
3917 and then not Is_Limited_Composite (T1)
3918 and then Has_Compatible_Type (R, T1)
3921 and then Base_Type (T1) /= Base_Type (T_F)
3923 It := Disambiguate (L, I_F, Index, Any_Type);
3925 if It = No_Interp then
3926 Ambiguous_Operands (N);
3927 Set_Etype (L, Any_Type);
3940 if not Analyzed (L) then
3944 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
3946 if Etype (N) = Any_Type then
3948 -- Operator was not visible.
3955 -- Start of processing for Find_Equality_Types
3958 -- If left operand is aggregate, the right operand has to
3959 -- provide a usable type for it.
3961 if Nkind (L) = N_Aggregate
3962 and then Nkind (R) /= N_Aggregate
3964 Find_Equality_Types (R, L, Op_Id, N);
3968 if Nkind (N) = N_Function_Call
3969 and then Nkind (Name (N)) = N_Expanded_Name
3971 Scop := Entity (Prefix (Name (N)));
3973 -- The prefix may be a package renaming, and the subsequent test
3974 -- requires the original package.
3976 if Ekind (Scop) = E_Package
3977 and then Present (Renamed_Entity (Scop))
3979 Scop := Renamed_Entity (Scop);
3980 Set_Entity (Prefix (Name (N)), Scop);
3984 if not Is_Overloaded (L) then
3985 Try_One_Interp (Etype (L));
3988 Get_First_Interp (L, Index, It);
3989 while Present (It.Typ) loop
3990 Try_One_Interp (It.Typ);
3991 Get_Next_Interp (Index, It);
3994 end Find_Equality_Types;
3996 -------------------------
3997 -- Find_Negation_Types --
3998 -------------------------
4000 procedure Find_Negation_Types
4005 Index : Interp_Index;
4009 if not Is_Overloaded (R) then
4010 if Etype (R) = Universal_Integer then
4011 Add_One_Interp (N, Op_Id, Any_Modular);
4012 elsif Valid_Boolean_Arg (Etype (R)) then
4013 Add_One_Interp (N, Op_Id, Etype (R));
4017 Get_First_Interp (R, Index, It);
4018 while Present (It.Typ) loop
4019 if Valid_Boolean_Arg (It.Typ) then
4020 Add_One_Interp (N, Op_Id, It.Typ);
4023 Get_Next_Interp (Index, It);
4026 end Find_Negation_Types;
4028 ----------------------
4029 -- Find_Unary_Types --
4030 ----------------------
4032 procedure Find_Unary_Types
4037 Index : Interp_Index;
4041 if not Is_Overloaded (R) then
4042 if Is_Numeric_Type (Etype (R)) then
4043 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
4047 Get_First_Interp (R, Index, It);
4048 while Present (It.Typ) loop
4049 if Is_Numeric_Type (It.Typ) then
4050 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
4053 Get_Next_Interp (Index, It);
4056 end Find_Unary_Types;
4062 function Junk_Operand (N : Node_Id) return Boolean is
4066 if Error_Posted (N) then
4070 -- Get entity to be tested
4072 if Is_Entity_Name (N)
4073 and then Present (Entity (N))
4077 -- An odd case, a procedure name gets converted to a very peculiar
4078 -- function call, and here is where we detect this happening.
4080 elsif Nkind (N) = N_Function_Call
4081 and then Is_Entity_Name (Name (N))
4082 and then Present (Entity (Name (N)))
4086 -- Another odd case, there are at least some cases of selected
4087 -- components where the selected component is not marked as having
4088 -- an entity, even though the selector does have an entity
4090 elsif Nkind (N) = N_Selected_Component
4091 and then Present (Entity (Selector_Name (N)))
4093 Enode := Selector_Name (N);
4099 -- Now test the entity we got to see if it a bad case
4101 case Ekind (Entity (Enode)) is
4105 ("package name cannot be used as operand", Enode);
4107 when Generic_Unit_Kind =>
4109 ("generic unit name cannot be used as operand", Enode);
4113 ("subtype name cannot be used as operand", Enode);
4117 ("entry name cannot be used as operand", Enode);
4121 ("procedure name cannot be used as operand", Enode);
4125 ("exception name cannot be used as operand", Enode);
4127 when E_Block | E_Label | E_Loop =>
4129 ("label name cannot be used as operand", Enode);
4139 --------------------
4140 -- Operator_Check --
4141 --------------------
4143 procedure Operator_Check (N : Node_Id) is
4145 Remove_Abstract_Operations (N);
4147 -- Test for case of no interpretation found for operator
4149 if Etype (N) = Any_Type then
4155 R := Right_Opnd (N);
4157 if Nkind (N) in N_Binary_Op then
4163 -- If either operand has no type, then don't complain further,
4164 -- since this simply means that we have a propragated error.
4167 or else Etype (R) = Any_Type
4168 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
4172 -- We explicitly check for the case of concatenation of component
4173 -- with component to avoid reporting spurious matching array types
4174 -- that might happen to be lurking in distant packages (such as
4175 -- run-time packages). This also prevents inconsistencies in the
4176 -- messages for certain ACVC B tests, which can vary depending on
4177 -- types declared in run-time interfaces. Another improvement when
4178 -- aggregates are present is to look for a well-typed operand.
4180 elsif Present (Candidate_Type)
4181 and then (Nkind (N) /= N_Op_Concat
4182 or else Is_Array_Type (Etype (L))
4183 or else Is_Array_Type (Etype (R)))
4186 if Nkind (N) = N_Op_Concat then
4187 if Etype (L) /= Any_Composite
4188 and then Is_Array_Type (Etype (L))
4190 Candidate_Type := Etype (L);
4192 elsif Etype (R) /= Any_Composite
4193 and then Is_Array_Type (Etype (R))
4195 Candidate_Type := Etype (R);
4200 ("operator for} is not directly visible!",
4201 N, First_Subtype (Candidate_Type));
4202 Error_Msg_N ("use clause would make operation legal!", N);
4205 -- If either operand is a junk operand (e.g. package name), then
4206 -- post appropriate error messages, but do not complain further.
4208 -- Note that the use of OR in this test instead of OR ELSE
4209 -- is quite deliberate, we may as well check both operands
4210 -- in the binary operator case.
4212 elsif Junk_Operand (R)
4213 or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
4217 -- If we have a logical operator, one of whose operands is
4218 -- Boolean, then we know that the other operand cannot resolve
4219 -- to Boolean (since we got no interpretations), but in that
4220 -- case we pretty much know that the other operand should be
4221 -- Boolean, so resolve it that way (generating an error)
4223 elsif Nkind (N) = N_Op_And
4227 Nkind (N) = N_Op_Xor
4229 if Etype (L) = Standard_Boolean then
4230 Resolve (R, Standard_Boolean);
4232 elsif Etype (R) = Standard_Boolean then
4233 Resolve (L, Standard_Boolean);
4237 -- For an arithmetic operator or comparison operator, if one
4238 -- of the operands is numeric, then we know the other operand
4239 -- is not the same numeric type. If it is a non-numeric type,
4240 -- then probably it is intended to match the other operand.
4242 elsif Nkind (N) = N_Op_Add or else
4243 Nkind (N) = N_Op_Divide or else
4244 Nkind (N) = N_Op_Ge or else
4245 Nkind (N) = N_Op_Gt or else
4246 Nkind (N) = N_Op_Le or else
4247 Nkind (N) = N_Op_Lt or else
4248 Nkind (N) = N_Op_Mod or else
4249 Nkind (N) = N_Op_Multiply or else
4250 Nkind (N) = N_Op_Rem or else
4251 Nkind (N) = N_Op_Subtract
4253 if Is_Numeric_Type (Etype (L))
4254 and then not Is_Numeric_Type (Etype (R))
4256 Resolve (R, Etype (L));
4259 elsif Is_Numeric_Type (Etype (R))
4260 and then not Is_Numeric_Type (Etype (L))
4262 Resolve (L, Etype (R));
4266 -- Comparisons on A'Access are common enough to deserve a
4269 elsif (Nkind (N) = N_Op_Eq or else
4270 Nkind (N) = N_Op_Ne)
4271 and then Ekind (Etype (L)) = E_Access_Attribute_Type
4272 and then Ekind (Etype (R)) = E_Access_Attribute_Type
4275 ("two access attributes cannot be compared directly", N);
4277 ("\they must be converted to an explicit type for comparison",
4281 -- Another one for C programmers
4283 elsif Nkind (N) = N_Op_Concat
4284 and then Valid_Boolean_Arg (Etype (L))
4285 and then Valid_Boolean_Arg (Etype (R))
4287 Error_Msg_N ("invalid operands for concatenation", N);
4288 Error_Msg_N ("\maybe AND was meant", N);
4291 -- A special case for comparison of access parameter with null
4293 elsif Nkind (N) = N_Op_Eq
4294 and then Is_Entity_Name (L)
4295 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
4296 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
4298 and then Nkind (R) = N_Null
4300 Error_Msg_N ("access parameter is not allowed to be null", L);
4301 Error_Msg_N ("\(call would raise Constraint_Error)", L);
4305 -- If we fall through then just give general message. Note
4306 -- that in the following messages, if the operand is overloaded
4307 -- we choose an arbitrary type to complain about, but that is
4308 -- probably more useful than not giving a type at all.
4310 if Nkind (N) in N_Unary_Op then
4311 Error_Msg_Node_2 := Etype (R);
4312 Error_Msg_N ("operator& not defined for}", N);
4316 if Nkind (N) in N_Binary_Op then
4317 if not Is_Overloaded (L)
4318 and then not Is_Overloaded (R)
4319 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
4321 Error_Msg_Node_2 := Etype (R);
4322 Error_Msg_N ("there is no applicable operator& for}", N);
4325 Error_Msg_N ("invalid operand types for operator&", N);
4327 if Nkind (N) /= N_Op_Concat then
4328 Error_Msg_NE ("\left operand has}!", N, Etype (L));
4329 Error_Msg_NE ("\right operand has}!", N, Etype (R));
4338 --------------------------------
4339 -- Remove_Abstract_Operations --
4340 --------------------------------
4342 procedure Remove_Abstract_Operations (N : Node_Id) is
4345 Abstract_Op : Entity_Id := Empty;
4347 -- AI-310: If overloaded, remove abstract non-dispatching
4348 -- operations. We activate this if either extensions are
4349 -- enabled, or if the abstract operation in question comes
4350 -- from a predefined file. This latter test allows us to
4351 -- use abstract to make operations invisible to users. In
4352 -- particular, if type Address is non-private and abstract
4353 -- subprograms are used to hide its operators, they will be
4356 type Operand_Position is (First_Op, Second_Op);
4357 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
4359 procedure Remove_Address_Interpretations (Op : Operand_Position);
4360 -- Ambiguities may arise when the operands are literal and the
4361 -- address operations in s-auxdec are visible. In that case, remove
4362 -- the interpretation of a literal as Address, to retain the semantics
4363 -- of Address as a private type.
4365 ------------------------------------
4366 -- Remove_Address_Interpretations --
4367 ------------------------------------
4369 procedure Remove_Address_Interpretations (Op : Operand_Position) is
4373 if Is_Overloaded (N) then
4374 Get_First_Interp (N, I, It);
4375 while Present (It.Nam) loop
4376 Formal := First_Entity (It.Nam);
4378 if Op = Second_Op then
4379 Formal := Next_Entity (Formal);
4382 if Is_Descendent_Of_Address (Etype (Formal)) then
4386 Get_Next_Interp (I, It);
4389 end Remove_Address_Interpretations;
4391 -- Start of processing for Remove_Abstract_Operations
4394 if Is_Overloaded (N) then
4395 Get_First_Interp (N, I, It);
4397 while Present (It.Nam) loop
4398 if not Is_Type (It.Nam)
4399 and then Is_Abstract (It.Nam)
4400 and then not Is_Dispatching_Operation (It.Nam)
4402 (Ada_Version >= Ada_05
4403 or else Is_Predefined_File_Name
4404 (Unit_File_Name (Get_Source_Unit (It.Nam))))
4407 Abstract_Op := It.Nam;
4412 Get_Next_Interp (I, It);
4415 if No (Abstract_Op) then
4418 elsif Nkind (N) in N_Op then
4420 -- Remove interpretations that treat literals as addresses.
4421 -- This is never appropriate.
4423 if Nkind (N) in N_Binary_Op then
4425 U1 : constant Boolean :=
4426 Present (Universal_Interpretation (Right_Opnd (N)));
4427 U2 : constant Boolean :=
4428 Present (Universal_Interpretation (Left_Opnd (N)));
4431 if U1 and then not U2 then
4432 Remove_Address_Interpretations (Second_Op);
4434 elsif U2 and then not U1 then
4435 Remove_Address_Interpretations (First_Op);
4438 if not (U1 and U2) then
4440 -- Remove corresponding predefined operator, which is
4441 -- always added to the overload set.
4443 Get_First_Interp (N, I, It);
4444 while Present (It.Nam) loop
4445 if Scope (It.Nam) = Standard_Standard
4446 and then Base_Type (It.Typ) =
4447 Base_Type (Etype (Abstract_Op))
4452 Get_Next_Interp (I, It);
4455 elsif Is_Overloaded (N)
4456 and then Present (Univ_Type)
4458 -- If both operands have a universal interpretation,
4459 -- select the predefined operator and discard others.
4461 Get_First_Interp (N, I, It);
4463 while Present (It.Nam) loop
4464 if Scope (It.Nam) = Standard_Standard then
4465 Set_Etype (N, Univ_Type);
4466 Set_Entity (N, It.Nam);
4467 Set_Is_Overloaded (N, False);
4471 Get_Next_Interp (I, It);
4477 elsif Nkind (N) = N_Function_Call
4479 (Nkind (Name (N)) = N_Operator_Symbol
4481 (Nkind (Name (N)) = N_Expanded_Name
4483 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
4487 Arg1 : constant Node_Id := First (Parameter_Associations (N));
4488 U1 : constant Boolean :=
4489 Present (Universal_Interpretation (Arg1));
4490 U2 : constant Boolean :=
4491 Present (Next (Arg1)) and then
4492 Present (Universal_Interpretation (Next (Arg1)));
4495 if U1 and then not U2 then
4496 Remove_Address_Interpretations (First_Op);
4498 elsif U2 and then not U1 then
4499 Remove_Address_Interpretations (Second_Op);
4502 if not (U1 and U2) then
4503 Get_First_Interp (N, I, It);
4504 while Present (It.Nam) loop
4505 if Scope (It.Nam) = Standard_Standard
4506 and then It.Typ = Base_Type (Etype (Abstract_Op))
4511 Get_Next_Interp (I, It);
4517 -- If the removal has left no valid interpretations, emit
4518 -- error message now and label node as illegal.
4520 if Present (Abstract_Op) then
4521 Get_First_Interp (N, I, It);
4525 -- Removal of abstract operation left no viable candidate.
4527 Set_Etype (N, Any_Type);
4528 Error_Msg_Sloc := Sloc (Abstract_Op);
4530 ("cannot call abstract operation& declared#", N, Abstract_Op);
4534 end Remove_Abstract_Operations;
4536 -----------------------
4537 -- Try_Indirect_Call --
4538 -----------------------
4540 function Try_Indirect_Call
4543 Typ : Entity_Id) return Boolean
4550 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
4551 Actual := First_Actual (N);
4552 Formal := First_Formal (Designated_Type (Typ));
4554 while Present (Actual)
4555 and then Present (Formal)
4557 if not Has_Compatible_Type (Actual, Etype (Formal)) then
4562 Next_Formal (Formal);
4565 if No (Actual) and then No (Formal) then
4566 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
4568 -- Nam is a candidate interpretation for the name in the call,
4569 -- if it is not an indirect call.
4571 if not Is_Type (Nam)
4572 and then Is_Entity_Name (Name (N))
4574 Set_Entity (Name (N), Nam);
4581 end Try_Indirect_Call;
4583 ----------------------
4584 -- Try_Indexed_Call --
4585 ----------------------
4587 function Try_Indexed_Call
4590 Typ : Entity_Id) return Boolean
4592 Actuals : constant List_Id := Parameter_Associations (N);
4597 Actual := First (Actuals);
4598 Index := First_Index (Typ);
4599 while Present (Actual)
4600 and then Present (Index)
4602 -- If the parameter list has a named association, the expression
4603 -- is definitely a call and not an indexed component.
4605 if Nkind (Actual) = N_Parameter_Association then
4609 if not Has_Compatible_Type (Actual, Etype (Index)) then
4617 if No (Actual) and then No (Index) then
4618 Add_One_Interp (N, Nam, Component_Type (Typ));
4620 -- Nam is a candidate interpretation for the name in the call,
4621 -- if it is not an indirect call.
4623 if not Is_Type (Nam)
4624 and then Is_Entity_Name (Name (N))
4626 Set_Entity (Name (N), Nam);
4633 end Try_Indexed_Call;
4635 --------------------------
4636 -- Try_Object_Operation --
4637 --------------------------
4639 function Try_Object_Operation (N : Node_Id) return Boolean is
4640 K : constant Node_Kind := Nkind (Parent (N));
4641 Loc : constant Source_Ptr := Sloc (N);
4642 Is_Subprg_Call : constant Boolean := K = N_Procedure_Call_Statement
4643 or else K = N_Function_Call;
4644 Obj : constant Node_Id := Prefix (N);
4645 Subprog : constant Node_Id := Selector_Name (N);
4648 Call_Node : Node_Id;
4649 Call_Node_Case : Node_Id := Empty;
4650 First_Actual : Node_Id;
4651 Node_To_Replace : Node_Id;
4652 Obj_Type : Entity_Id := Etype (Obj);
4654 procedure Complete_Object_Operation
4655 (Call_Node : Node_Id;
4656 Node_To_Replace : Node_Id;
4658 -- Set Subprog as the name of Call_Node, replace Node_To_Replace with
4659 -- Call_Node and reanalyze Node_To_Replace.
4661 procedure Transform_Object_Operation
4662 (Call_Node : out Node_Id;
4663 First_Actual : Node_Id;
4664 Node_To_Replace : out Node_Id;
4666 -- Transform Object.Operation (...) to Operation (Object, ...)
4667 -- Call_Node is the resulting subprogram call node, First_Actual is
4668 -- either the object Obj or an explicit dereference of Obj in certain
4669 -- cases, Node_To_Replace is either N or the parent of N, and Subprog
4670 -- is the subprogram we are trying to match.
4672 function Try_Class_Wide_Operation
4673 (Call_Node : Node_Id;
4674 Node_To_Replace : Node_Id) return Boolean;
4675 -- Traverse all the ancestor types looking for a class-wide subprogram
4676 -- that matches Subprog.
4678 function Try_Primitive_Operation
4679 (Call_Node : Node_Id;
4680 Node_To_Replace : Node_Id) return Boolean;
4681 -- Traverse the list of primitive subprograms looking for a subprogram
4682 -- than matches Subprog.
4684 -------------------------------
4685 -- Complete_Object_Operation --
4686 -------------------------------
4688 procedure Complete_Object_Operation
4689 (Call_Node : Node_Id;
4690 Node_To_Replace : Node_Id;
4694 Set_Name (Call_Node, New_Copy_Tree (Subprog));
4695 Set_Analyzed (Call_Node, False);
4696 Replace (Node_To_Replace, Call_Node);
4697 Analyze (Node_To_Replace);
4699 end Complete_Object_Operation;
4701 --------------------------------
4702 -- Transform_Object_Operation --
4703 --------------------------------
4705 procedure Transform_Object_Operation
4706 (Call_Node : out Node_Id;
4707 First_Actual : Node_Id;
4708 Node_To_Replace : out Node_Id;
4712 Parent_Node : constant Node_Id := Parent (N);
4715 Actuals := New_List (New_Copy_Tree (First_Actual));
4717 if (Nkind (Parent_Node) = N_Function_Call
4719 Nkind (Parent_Node) = N_Procedure_Call_Statement)
4721 -- Avoid recursive calls
4723 and then N /= First (Parameter_Associations (Parent_Node))
4725 Node_To_Replace := Parent_Node;
4727 Append_List_To (Actuals,
4728 New_Copy_List (Parameter_Associations (Parent_Node)));
4730 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
4732 Make_Procedure_Call_Statement (Loc,
4733 Name => New_Copy_Tree (Subprog),
4734 Parameter_Associations => Actuals);
4737 pragma Assert (Nkind (Parent_Node) = N_Function_Call);
4740 Make_Function_Call (Loc,
4741 Name => New_Copy_Tree (Subprog),
4742 Parameter_Associations => Actuals);
4746 -- Parameterless call
4749 Node_To_Replace := N;
4752 Make_Function_Call (Loc,
4753 Name => New_Copy_Tree (Subprog),
4754 Parameter_Associations => Actuals);
4757 end Transform_Object_Operation;
4759 ------------------------------
4760 -- Try_Class_Wide_Operation --
4761 ------------------------------
4763 function Try_Class_Wide_Operation
4764 (Call_Node : Node_Id;
4765 Node_To_Replace : Node_Id) return Boolean
4767 Anc_Type : Entity_Id;
4774 -- Loop through ancestor types, traverse their homonym chains and
4775 -- gather all interpretations of the subprogram.
4777 Anc_Type := Obj_Type;
4779 Hom := Current_Entity (Subprog);
4780 while Present (Hom) loop
4781 if (Ekind (Hom) = E_Procedure
4783 Ekind (Hom) = E_Function)
4784 and then Present (First_Formal (Hom))
4785 and then Etype (First_Formal (Hom)) =
4786 Class_Wide_Type (Anc_Type)
4788 Hom_Ref := New_Reference_To (Hom, Loc);
4790 -- When both the type of the object and the type of the
4791 -- first formal of the primitive operation are tagged
4792 -- access types, we use a node with the object as first
4795 if Is_Access_Type (Etype (Obj))
4796 and then Ekind (Etype (First_Formal (Hom))) =
4797 E_Anonymous_Access_Type
4799 -- Allocate the node only once
4801 if not Present (Call_Node_Case) then
4802 Transform_Object_Operation (
4803 Call_Node => Call_Node_Case,
4804 First_Actual => Obj,
4805 Node_To_Replace => Dummy,
4806 Subprog => Subprog);
4808 Set_Etype (Call_Node_Case, Any_Type);
4809 Set_Parent (Call_Node_Case, Parent (Node_To_Replace));
4812 Set_Name (Call_Node_Case, Hom_Ref);
4815 N => Call_Node_Case,
4818 Success => Success);
4821 Complete_Object_Operation (
4822 Call_Node => Call_Node_Case,
4823 Node_To_Replace => Node_To_Replace,
4824 Subprog => Hom_Ref);
4829 -- ??? comment required
4832 Set_Name (Call_Node, Hom_Ref);
4838 Success => Success);
4841 Complete_Object_Operation (
4842 Call_Node => Call_Node,
4843 Node_To_Replace => Node_To_Replace,
4844 Subprog => Hom_Ref);
4851 Hom := Homonym (Hom);
4854 -- Climb to ancestor type if there is one
4856 exit when Etype (Anc_Type) = Anc_Type;
4857 Anc_Type := Etype (Anc_Type);
4861 end Try_Class_Wide_Operation;
4863 -----------------------------
4864 -- Try_Primitive_Operation --
4865 -----------------------------
4867 function Try_Primitive_Operation
4868 (Call_Node : Node_Id;
4869 Node_To_Replace : Node_Id) return Boolean
4873 Prim_Op : Entity_Id;
4874 Prim_Op_Ref : Node_Id;
4878 -- Look for the subprogram in the list of primitive operations.
4880 Elmt := First_Elmt (Primitive_Operations (Obj_Type));
4881 while Present (Elmt) loop
4882 Prim_Op := Node (Elmt);
4884 if Chars (Prim_Op) = Chars (Subprog)
4885 and then Present (First_Formal (Prim_Op))
4887 Prim_Op_Ref := New_Reference_To (Prim_Op, Loc);
4889 -- When both the type of the object and the type of the first
4890 -- formal of the primitive operation are tagged access types,
4891 -- we use a node with the object as first actual.
4893 if Is_Access_Type (Etype (Obj))
4894 and then Ekind (Etype (First_Formal (Prim_Op))) =
4895 E_Anonymous_Access_Type
4897 -- Allocate the node only once
4899 if not Present (Call_Node_Case) then
4900 Transform_Object_Operation (
4901 Call_Node => Call_Node_Case,
4902 First_Actual => Obj,
4903 Node_To_Replace => Dummy,
4904 Subprog => Subprog);
4906 Set_Etype (Call_Node_Case, Any_Type);
4907 Set_Parent (Call_Node_Case, Parent (Node_To_Replace));
4910 Set_Name (Call_Node_Case, Prim_Op_Ref);
4913 N => Call_Node_Case,
4916 Success => Success);
4919 Complete_Object_Operation (
4920 Call_Node => Call_Node_Case,
4921 Node_To_Replace => Node_To_Replace,
4922 Subprog => Prim_Op_Ref);
4927 -- Comment required ???
4930 Set_Name (Call_Node, Prim_Op_Ref);
4936 Success => Success);
4939 Complete_Object_Operation (
4940 Call_Node => Call_Node,
4941 Node_To_Replace => Node_To_Replace,
4942 Subprog => Prim_Op_Ref);
4953 end Try_Primitive_Operation;
4955 -- Start of processing for Try_Object_Operation
4958 if Is_Access_Type (Obj_Type) then
4959 Obj_Type := Designated_Type (Obj_Type);
4962 if Ekind (Obj_Type) = E_Private_Subtype then
4963 Obj_Type := Base_Type (Obj_Type);
4966 if Is_Class_Wide_Type (Obj_Type) then
4967 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
4970 -- Analyze the actuals in case of subprogram call
4972 if Is_Subprg_Call and then N = Name (Parent (N)) then
4973 Actual := First (Parameter_Associations (Parent (N)));
4974 while Present (Actual) loop
4976 Check_Parameterless_Call (Actual);
4981 -- If the object is of an Access type, explicit dereference is
4984 if Is_Access_Type (Etype (Obj)) then
4986 Make_Explicit_Dereference (Sloc (Obj), Obj);
4987 Set_Etype (First_Actual, Obj_Type);
4989 First_Actual := Obj;
4992 -- Build a subprogram call node
4994 Transform_Object_Operation (
4995 Call_Node => Call_Node,
4996 First_Actual => First_Actual,
4997 Node_To_Replace => Node_To_Replace,
4998 Subprog => Subprog);
5000 Set_Etype (Call_Node, Any_Type);
5001 Set_Parent (Call_Node, Parent (Node_To_Replace));
5004 Try_Primitive_Operation
5005 (Call_Node => Call_Node,
5006 Node_To_Replace => Node_To_Replace)
5008 Try_Class_Wide_Operation
5009 (Call_Node => Call_Node,
5010 Node_To_Replace => Node_To_Replace);
5011 end Try_Object_Operation;