1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- Extensive contributions were provided by Ada Core Technologies Inc. --
27 ------------------------------------------------------------------------------
29 with Atree
; use Atree
;
30 with Debug
; use Debug
;
31 with Einfo
; use Einfo
;
32 with Errout
; use Errout
;
33 with Exp_Util
; use Exp_Util
;
34 with Hostparm
; use Hostparm
;
35 with Itypes
; use Itypes
;
36 with Lib
.Xref
; use Lib
.Xref
;
37 with Namet
; use Namet
;
38 with Nlists
; use Nlists
;
39 with Nmake
; use Nmake
;
41 with Output
; use Output
;
42 with Restrict
; use Restrict
;
44 with Sem_Cat
; use Sem_Cat
;
45 with Sem_Ch3
; use Sem_Ch3
;
46 with Sem_Ch8
; use Sem_Ch8
;
47 with Sem_Dist
; use Sem_Dist
;
48 with Sem_Eval
; use Sem_Eval
;
49 with Sem_Res
; use Sem_Res
;
50 with Sem_Util
; use Sem_Util
;
51 with Sem_Type
; use Sem_Type
;
52 with Stand
; use Stand
;
53 with Sinfo
; use Sinfo
;
54 with Snames
; use Snames
;
55 with Tbuild
; use Tbuild
;
57 with GNAT
.Spelling_Checker
; use GNAT
.Spelling_Checker
;
59 package body Sem_Ch4
is
61 -----------------------
62 -- Local Subprograms --
63 -----------------------
65 procedure Analyze_Expression
(N
: Node_Id
);
66 -- For expressions that are not names, this is just a call to analyze.
67 -- If the expression is a name, it may be a call to a parameterless
68 -- function, and if so must be converted into an explicit call node
69 -- and analyzed as such. This deproceduring must be done during the first
70 -- pass of overload resolution, because otherwise a procedure call with
71 -- overloaded actuals may fail to resolve. See 4327-001 for an example.
73 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
);
74 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
75 -- is an operator name or an expanded name whose selector is an operator
76 -- name, and one possible interpretation is as a predefined operator.
78 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
);
79 -- If the prefix of a selected_component is overloaded, the proper
80 -- interpretation that yields a record type with the proper selector
81 -- name must be selected.
83 procedure Analyze_User_Defined_Binary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
84 -- Procedure to analyze a user defined binary operator, which is resolved
85 -- like a function, but instead of a list of actuals it is presented
86 -- with the left and right operands of an operator node.
88 procedure Analyze_User_Defined_Unary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
89 -- Procedure to analyze a user defined unary operator, which is resolved
90 -- like a function, but instead of a list of actuals, it is presented with
91 -- the operand of the operator node.
93 procedure Ambiguous_Operands
(N
: Node_Id
);
94 -- for equality, membership, and comparison operators with overloaded
95 -- arguments, list possible interpretations.
97 procedure Insert_Explicit_Dereference
(N
: Node_Id
);
98 -- In a context that requires a composite or subprogram type and
99 -- where a prefix is an access type, insert an explicit dereference.
101 procedure Analyze_One_Call
105 Success
: out Boolean);
106 -- Check one interpretation of an overloaded subprogram name for
107 -- compatibility with the types of the actuals in a call. If there is a
108 -- single interpretation which does not match, post error if Report is
111 -- Nam is the entity that provides the formals against which the actuals
112 -- are checked. Nam is either the name of a subprogram, or the internal
113 -- subprogram type constructed for an access_to_subprogram. If the actuals
114 -- are compatible with Nam, then Nam is added to the list of candidate
115 -- interpretations for N, and Success is set to True.
117 procedure Check_Misspelled_Selector
120 -- Give possible misspelling diagnostic if Sel is likely to be
121 -- a misspelling of one of the selectors of the Prefix.
122 -- This is called by Analyze_Selected_Component after producing
123 -- an invalid selector error message.
125 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean;
126 -- Verify that type T is declared in scope S. Used to find intepretations
127 -- for operators given by expanded names. This is abstracted as a separate
128 -- function to handle extensions to System, where S is System, but T is
129 -- declared in the extension.
131 procedure Find_Arithmetic_Types
135 -- L and R are the operands of an arithmetic operator. Find
136 -- consistent pairs of interpretations for L and R that have a
137 -- numeric type consistent with the semantics of the operator.
139 procedure Find_Comparison_Types
143 -- L and R are operands of a comparison operator. Find consistent
144 -- pairs of interpretations for L and R.
146 procedure Find_Concatenation_Types
150 -- For the four varieties of concatenation.
152 procedure Find_Equality_Types
156 -- Ditto for equality operators.
158 procedure Find_Boolean_Types
162 -- Ditto for binary logical operations.
164 procedure Find_Negation_Types
168 -- Find consistent interpretation for operand of negation operator.
170 procedure Find_Non_Universal_Interpretations
175 -- For equality and comparison operators, the result is always boolean,
176 -- and the legality of the operation is determined from the visibility
177 -- of the operand types. If one of the operands has a universal interpre-
178 -- tation, the legality check uses some compatible non-universal
179 -- interpretation of the other operand. N can be an operator node, or
180 -- a function call whose name is an operator designator.
182 procedure Find_Unary_Types
186 -- Unary arithmetic types: plus, minus, abs.
188 procedure Check_Arithmetic_Pair
192 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
193 -- types for left and right operand. Determine whether they constitute
194 -- a valid pair for the given operator, and record the corresponding
195 -- interpretation of the operator node. The node N may be an operator
196 -- node (the usual case) or a function call whose prefix is an operator
197 -- designator. In both cases Op_Id is the operator name itself.
199 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
);
200 -- Give detailed information on overloaded call where none of the
201 -- interpretations match. N is the call node, Nam the designator for
202 -- the overloaded entity being called.
204 function Junk_Operand
(N
: Node_Id
) return Boolean;
205 -- Test for an operand that is an inappropriate entity (e.g. a package
206 -- name or a label). If so, issue an error message and return True. If
207 -- the operand is not an inappropriate entity kind, return False.
209 procedure Operator_Check
(N
: Node_Id
);
210 -- Verify that an operator has received some valid interpretation.
211 -- If none was found, determine whether a use clause would make the
212 -- operation legal. The variable Candidate_Type (defined in Sem_Type) is
213 -- set for every type compatible with the operator, even if the operator
214 -- for the type is not directly visible. The routine uses this type to emit
215 -- a more informative message.
217 function Try_Indexed_Call
222 -- If a function has defaults for all its actuals, a call to it may
223 -- in fact be an indexing on the result of the call. Try_Indexed_Call
224 -- attempts the interpretation as an indexing, prior to analysis as
225 -- a call. If both are possible, the node is overloaded with both
226 -- interpretations (same symbol but two different types).
228 function Try_Indirect_Call
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 ------------------------
238 -- Ambiguous_Operands --
239 ------------------------
241 procedure Ambiguous_Operands
(N
: Node_Id
) is
242 procedure List_Interps
(Opnd
: Node_Id
);
244 procedure List_Interps
(Opnd
: Node_Id
) is
245 Index
: Interp_Index
;
251 if Is_Overloaded
(Opnd
) then
252 if Nkind
(Opnd
) in N_Op
then
255 elsif Nkind
(Opnd
) = N_Function_Call
then
266 if Opnd
= Left_Opnd
(N
) then
268 ("\left operand has the following interpretations", N
);
271 ("\right operand has the following interpretations", N
);
275 Get_First_Interp
(Nam
, Index
, It
);
277 while Present
(It
.Nam
) loop
279 if Scope
(It
.Nam
) = Standard_Standard
280 and then Scope
(It
.Typ
) /= Standard_Standard
282 Error_Msg_Sloc
:= Sloc
(Parent
(It
.Typ
));
283 Error_Msg_NE
(" & (inherited) declared#!", Err
, It
.Nam
);
286 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
287 Error_Msg_NE
(" & declared#!", Err
, It
.Nam
);
290 Get_Next_Interp
(Index
, It
);
296 or else Nkind
(N
) = N_Not_In
298 Error_Msg_N
("ambiguous operands for membership", N
);
300 elsif Nkind
(N
) = N_Op_Eq
301 or else Nkind
(N
) = N_Op_Ne
303 Error_Msg_N
("ambiguous operands for equality", N
);
306 Error_Msg_N
("ambiguous operands for comparison", N
);
309 if All_Errors_Mode
then
310 List_Interps
(Left_Opnd
(N
));
311 List_Interps
(Right_Opnd
(N
));
316 "\use '/'R'E'P'O'R'T'_'E'R'R'O'R'S'='F'U'L'L for details",
319 Error_Msg_N
("\use -gnatf for details", N
);
322 end Ambiguous_Operands
;
324 -----------------------
325 -- Analyze_Aggregate --
326 -----------------------
328 -- Most of the analysis of Aggregates requires that the type be known,
329 -- and is therefore put off until resolution.
331 procedure Analyze_Aggregate
(N
: Node_Id
) is
333 if No
(Etype
(N
)) then
334 Set_Etype
(N
, Any_Composite
);
336 end Analyze_Aggregate
;
338 -----------------------
339 -- Analyze_Allocator --
340 -----------------------
342 procedure Analyze_Allocator
(N
: Node_Id
) is
343 Loc
: constant Source_Ptr
:= Sloc
(N
);
344 Sav_Errs
: constant Nat
:= Errors_Detected
;
345 E
: Node_Id
:= Expression
(N
);
346 Acc_Type
: Entity_Id
;
350 Check_Restriction
(No_Allocators
, N
);
352 if Nkind
(E
) = N_Qualified_Expression
then
353 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
354 Set_Etype
(Acc_Type
, Acc_Type
);
355 Init_Size_Align
(Acc_Type
);
356 Find_Type
(Subtype_Mark
(E
));
357 Type_Id
:= Entity
(Subtype_Mark
(E
));
358 Check_Fully_Declared
(Type_Id
, N
);
359 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
361 if Is_Protected_Type
(Type_Id
) then
362 Check_Restriction
(No_Protected_Type_Allocators
, N
);
365 if Is_Limited_Type
(Type_Id
)
366 and then Comes_From_Source
(N
)
367 and then not In_Instance_Body
369 Error_Msg_N
("initialization not allowed for limited types", N
);
372 Analyze_And_Resolve
(Expression
(E
), Type_Id
);
374 -- A qualified expression requires an exact match of the type,
375 -- class-wide matching is not allowed.
377 if Is_Class_Wide_Type
(Type_Id
)
378 and then Base_Type
(Etype
(Expression
(E
))) /= Base_Type
(Type_Id
)
380 Wrong_Type
(Expression
(E
), Type_Id
);
383 Check_Non_Static_Context
(Expression
(E
));
385 -- We don't analyze the qualified expression itself because it's
386 -- part of the allocator
388 Set_Etype
(E
, Type_Id
);
395 -- If the allocator includes a N_Subtype_Indication then a
396 -- constraint is present, otherwise the node is a subtype mark.
397 -- Introduce an explicit subtype declaration into the tree
398 -- defining some anonymous subtype and rewrite the allocator to
399 -- use this subtype rather than the subtype indication.
401 -- It is important to introduce the explicit subtype declaration
402 -- so that the bounds of the subtype indication are attached to
403 -- the tree in case the allocator is inside a generic unit.
405 if Nkind
(E
) = N_Subtype_Indication
then
407 -- A constraint is only allowed for a composite type in Ada
408 -- 95. In Ada 83, a constraint is also allowed for an
409 -- access-to-composite type, but the constraint is ignored.
411 Find_Type
(Subtype_Mark
(E
));
413 if Is_Elementary_Type
(Entity
(Subtype_Mark
(E
))) then
415 and then Is_Access_Type
(Entity
(Subtype_Mark
(E
))))
417 Error_Msg_N
("constraint not allowed here", E
);
419 if Nkind
(Constraint
(E
))
420 = N_Index_Or_Discriminant_Constraint
423 ("\if qualified expression was meant, " &
424 "use apostrophe", Constraint
(E
));
428 -- Get rid of the bogus constraint:
430 Rewrite
(E
, New_Copy_Tree
(Subtype_Mark
(E
)));
431 Analyze_Allocator
(N
);
435 if Expander_Active
then
437 Make_Defining_Identifier
(Loc
, New_Internal_Name
('S'));
440 Make_Subtype_Declaration
(Loc
,
441 Defining_Identifier
=> Def_Id
,
442 Subtype_Indication
=> Relocate_Node
(E
)));
444 if Sav_Errs
/= Errors_Detected
445 and then Nkind
(Constraint
(E
))
446 = N_Index_Or_Discriminant_Constraint
449 ("if qualified expression was meant, " &
450 "use apostrophe!", Constraint
(E
));
453 E
:= New_Occurrence_Of
(Def_Id
, Loc
);
454 Rewrite
(Expression
(N
), E
);
458 Type_Id
:= Process_Subtype
(E
, N
);
459 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
460 Set_Etype
(Acc_Type
, Acc_Type
);
461 Init_Size_Align
(Acc_Type
);
462 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
463 Check_Fully_Declared
(Type_Id
, N
);
465 -- Check for missing initialization. Skip this check if we already
466 -- had errors on analyzing the allocator, since in that case these
467 -- are probably cascaded errors
469 if Is_Indefinite_Subtype
(Type_Id
)
470 and then Errors_Detected
= Sav_Errs
472 if Is_Class_Wide_Type
(Type_Id
) then
474 ("initialization required in class-wide allocation", N
);
477 ("initialization required in unconstrained allocation", N
);
483 if Is_Abstract
(Type_Id
) then
484 Error_Msg_N
("cannot allocate abstract object", E
);
487 if Has_Task
(Designated_Type
(Acc_Type
)) then
488 Check_Restriction
(No_Task_Allocators
, N
);
491 Set_Etype
(N
, Acc_Type
);
493 if not Is_Library_Level_Entity
(Acc_Type
) then
494 Check_Restriction
(No_Local_Allocators
, N
);
497 if Errors_Detected
> Sav_Errs
then
498 Set_Error_Posted
(N
);
499 Set_Etype
(N
, Any_Type
);
502 end Analyze_Allocator
;
504 ---------------------------
505 -- Analyze_Arithmetic_Op --
506 ---------------------------
508 procedure Analyze_Arithmetic_Op
(N
: Node_Id
) is
509 L
: constant Node_Id
:= Left_Opnd
(N
);
510 R
: constant Node_Id
:= Right_Opnd
(N
);
514 Candidate_Type
:= Empty
;
515 Analyze_Expression
(L
);
516 Analyze_Expression
(R
);
518 -- If the entity is already set, the node is the instantiation of
519 -- a generic node with a non-local reference, or was manufactured
520 -- by a call to Make_Op_xxx. In either case the entity is known to
521 -- be valid, and we do not need to collect interpretations, instead
522 -- we just get the single possible interpretation.
526 if Present
(Op_Id
) then
527 if Ekind
(Op_Id
) = E_Operator
then
529 if (Nkind
(N
) = N_Op_Divide
or else
530 Nkind
(N
) = N_Op_Mod
or else
531 Nkind
(N
) = N_Op_Multiply
or else
532 Nkind
(N
) = N_Op_Rem
)
533 and then Treat_Fixed_As_Integer
(N
)
537 Set_Etype
(N
, Any_Type
);
538 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
542 Set_Etype
(N
, Any_Type
);
543 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
546 -- Entity is not already set, so we do need to collect interpretations
549 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
550 Set_Etype
(N
, Any_Type
);
552 while Present
(Op_Id
) loop
553 if Ekind
(Op_Id
) = E_Operator
554 and then Present
(Next_Entity
(First_Entity
(Op_Id
)))
556 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
558 -- The following may seem superfluous, because an operator cannot
559 -- be generic, but this ignores the cleverness of the author of
562 elsif Is_Overloadable
(Op_Id
) then
563 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
566 Op_Id
:= Homonym
(Op_Id
);
571 end Analyze_Arithmetic_Op
;
577 -- Function, procedure, and entry calls are checked here. The Name
578 -- in the call may be overloaded. The actuals have been analyzed
579 -- and may themselves be overloaded. On exit from this procedure, the node
580 -- N may have zero, one or more interpretations. In the first case an error
581 -- message is produced. In the last case, the node is flagged as overloaded
582 -- and the interpretations are collected in All_Interp.
584 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
585 -- the type-checking is similar to that of other calls.
587 procedure Analyze_Call
(N
: Node_Id
) is
588 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
589 Nam
: Node_Id
:= Name
(N
);
593 Success
: Boolean := False;
595 function Name_Denotes_Function
return Boolean;
596 -- If the type of the name is an access to subprogram, this may be
597 -- the type of a name, or the return type of the function being called.
598 -- If the name is not an entity then it can denote a protected function.
599 -- Until we distinguish Etype from Return_Type, we must use this
600 -- routine to resolve the meaning of the name in the call.
602 ---------------------------
603 -- Name_Denotes_Function --
604 ---------------------------
606 function Name_Denotes_Function
return Boolean is
608 if Is_Entity_Name
(Nam
) then
609 return Ekind
(Entity
(Nam
)) = E_Function
;
611 elsif Nkind
(Nam
) = N_Selected_Component
then
612 return Ekind
(Entity
(Selector_Name
(Nam
))) = E_Function
;
617 end Name_Denotes_Function
;
619 -- Start of processing for Analyze_Call
622 -- Initialize the type of the result of the call to the error type,
623 -- which will be reset if the type is successfully resolved.
625 Set_Etype
(N
, Any_Type
);
627 if not Is_Overloaded
(Nam
) then
629 -- Only one interpretation to check
631 if Ekind
(Etype
(Nam
)) = E_Subprogram_Type
then
632 Nam_Ent
:= Etype
(Nam
);
634 elsif Is_Access_Type
(Etype
(Nam
))
635 and then Ekind
(Designated_Type
(Etype
(Nam
))) = E_Subprogram_Type
636 and then not Name_Denotes_Function
638 Nam_Ent
:= Designated_Type
(Etype
(Nam
));
639 Insert_Explicit_Dereference
(Nam
);
641 -- Selected component case. Simple entry or protected operation,
642 -- where the entry name is given by the selector name.
644 elsif Nkind
(Nam
) = N_Selected_Component
then
645 Nam_Ent
:= Entity
(Selector_Name
(Nam
));
647 if Ekind
(Nam_Ent
) /= E_Entry
648 and then Ekind
(Nam_Ent
) /= E_Entry_Family
649 and then Ekind
(Nam_Ent
) /= E_Function
650 and then Ekind
(Nam_Ent
) /= E_Procedure
652 Error_Msg_N
("name in call is not a callable entity", Nam
);
653 Set_Etype
(N
, Any_Type
);
657 -- If the name is an Indexed component, it can be a call to a member
658 -- of an entry family. The prefix must be a selected component whose
659 -- selector is the entry. Analyze_Procedure_Call normalizes several
660 -- kinds of call into this form.
662 elsif Nkind
(Nam
) = N_Indexed_Component
then
664 if Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
665 Nam_Ent
:= Entity
(Selector_Name
(Prefix
(Nam
)));
668 Error_Msg_N
("name in call is not a callable entity", Nam
);
669 Set_Etype
(N
, Any_Type
);
674 elsif not Is_Entity_Name
(Nam
) then
675 Error_Msg_N
("name in call is not a callable entity", Nam
);
676 Set_Etype
(N
, Any_Type
);
680 Nam_Ent
:= Entity
(Nam
);
682 -- If no interpretations, give error message
684 if not Is_Overloadable
(Nam_Ent
) then
686 L
: constant Boolean := Is_List_Member
(N
);
687 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
690 -- If the node is in a list whose parent is not an
691 -- expression then it must be an attempted procedure call.
693 if L
and then K
not in N_Subexpr
then
694 if Ekind
(Entity
(Nam
)) = E_Generic_Procedure
then
696 ("must instantiate generic procedure& before call",
700 ("procedure or entry name expected", Nam
);
703 -- Check for tasking cases where only an entry call will do
706 and then (K
= N_Entry_Call_Alternative
707 or else K
= N_Triggering_Alternative
)
709 Error_Msg_N
("entry name expected", Nam
);
711 -- Otherwise give general error message
714 Error_Msg_N
("invalid prefix in call", Nam
);
722 Analyze_One_Call
(N
, Nam_Ent
, True, Success
);
725 -- An overloaded selected component must denote overloaded
726 -- operations of a concurrent type. The interpretations are
727 -- attached to the simple name of those operations.
729 if Nkind
(Nam
) = N_Selected_Component
then
730 Nam
:= Selector_Name
(Nam
);
733 Get_First_Interp
(Nam
, X
, It
);
735 while Present
(It
.Nam
) loop
738 -- Name may be call that returns an access to subprogram, or more
739 -- generally an overloaded expression one of whose interpretations
740 -- yields an access to subprogram. If the name is an entity, we
741 -- do not dereference, because the node is a call that returns
742 -- the access type: note difference between f(x), where the call
743 -- may return an access subprogram type, and f(x)(y), where the
744 -- type returned by the call to f is implicitly dereferenced to
745 -- analyze the outer call.
747 if Is_Access_Type
(Nam_Ent
) then
748 Nam_Ent
:= Designated_Type
(Nam_Ent
);
750 elsif Is_Access_Type
(Etype
(Nam_Ent
))
751 and then not Is_Entity_Name
(Nam
)
752 and then Ekind
(Designated_Type
(Etype
(Nam_Ent
)))
755 Nam_Ent
:= Designated_Type
(Etype
(Nam_Ent
));
758 Analyze_One_Call
(N
, Nam_Ent
, False, Success
);
760 -- If the interpretation succeeds, mark the proper type of the
761 -- prefix (any valid candidate will do). If not, remove the
762 -- candidate interpretation. This only needs to be done for
763 -- overloaded protected operations, for other entities disambi-
764 -- guation is done directly in Resolve.
767 Set_Etype
(Nam
, It
.Typ
);
769 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
773 Get_Next_Interp
(X
, It
);
776 -- If the name is the result of a function call, it can only
777 -- be a call to a function returning an access to subprogram.
778 -- Insert explicit dereference.
780 if Nkind
(Nam
) = N_Function_Call
then
781 Insert_Explicit_Dereference
(Nam
);
784 if Etype
(N
) = Any_Type
then
786 -- None of the interpretations is compatible with the actuals
788 Diagnose_Call
(N
, Nam
);
790 -- Special checks for uninstantiated put routines
792 if Nkind
(N
) = N_Procedure_Call_Statement
793 and then Is_Entity_Name
(Nam
)
794 and then Chars
(Nam
) = Name_Put
795 and then List_Length
(Actuals
) = 1
798 Arg
: constant Node_Id
:= First
(Actuals
);
802 if Nkind
(Arg
) = N_Parameter_Association
then
803 Typ
:= Etype
(Explicit_Actual_Parameter
(Arg
));
808 if Is_Signed_Integer_Type
(Typ
) then
810 ("possible missing instantiation of " &
811 "'Text_'I'O.'Integer_'I'O!", Nam
);
813 elsif Is_Modular_Integer_Type
(Typ
) then
815 ("possible missing instantiation of " &
816 "'Text_'I'O.'Modular_'I'O!", Nam
);
818 elsif Is_Floating_Point_Type
(Typ
) then
820 ("possible missing instantiation of " &
821 "'Text_'I'O.'Float_'I'O!", Nam
);
823 elsif Is_Ordinary_Fixed_Point_Type
(Typ
) then
825 ("possible missing instantiation of " &
826 "'Text_'I'O.'Fixed_'I'O!", Nam
);
828 elsif Is_Decimal_Fixed_Point_Type
(Typ
) then
830 ("possible missing instantiation of " &
831 "'Text_'I'O.'Decimal_'I'O!", Nam
);
833 elsif Is_Enumeration_Type
(Typ
) then
835 ("possible missing instantiation of " &
836 "'Text_'I'O.'Enumeration_'I'O!", Nam
);
841 elsif not Is_Overloaded
(N
)
842 and then Is_Entity_Name
(Nam
)
844 -- Resolution yields a single interpretation. Verify that
845 -- is has the proper capitalization.
847 Set_Entity_With_Style_Check
(Nam
, Entity
(Nam
));
848 Generate_Reference
(Entity
(Nam
), Nam
);
850 Set_Etype
(Nam
, Etype
(Entity
(Nam
)));
857 ---------------------------
858 -- Analyze_Comparison_Op --
859 ---------------------------
861 procedure Analyze_Comparison_Op
(N
: Node_Id
) is
862 L
: constant Node_Id
:= Left_Opnd
(N
);
863 R
: constant Node_Id
:= Right_Opnd
(N
);
864 Op_Id
: Entity_Id
:= Entity
(N
);
867 Set_Etype
(N
, Any_Type
);
868 Candidate_Type
:= Empty
;
870 Analyze_Expression
(L
);
871 Analyze_Expression
(R
);
873 if Present
(Op_Id
) then
875 if Ekind
(Op_Id
) = E_Operator
then
876 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
878 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
881 if Is_Overloaded
(L
) then
882 Set_Etype
(L
, Intersect_Types
(L
, R
));
886 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
888 while Present
(Op_Id
) loop
890 if Ekind
(Op_Id
) = E_Operator
then
891 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
893 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
896 Op_Id
:= Homonym
(Op_Id
);
901 end Analyze_Comparison_Op
;
903 ---------------------------
904 -- Analyze_Concatenation --
905 ---------------------------
907 -- If the only one-dimensional array type in scope is String,
908 -- this is the resulting type of the operation. Otherwise there
909 -- will be a concatenation operation defined for each user-defined
910 -- one-dimensional array.
912 procedure Analyze_Concatenation
(N
: Node_Id
) is
913 L
: constant Node_Id
:= Left_Opnd
(N
);
914 R
: constant Node_Id
:= Right_Opnd
(N
);
915 Op_Id
: Entity_Id
:= Entity
(N
);
920 Set_Etype
(N
, Any_Type
);
921 Candidate_Type
:= Empty
;
923 Analyze_Expression
(L
);
924 Analyze_Expression
(R
);
926 -- If the entity is present, the node appears in an instance,
927 -- and denotes a predefined concatenation operation. The resulting
928 -- type is obtained from the arguments when possible.
930 if Present
(Op_Id
) then
931 if Ekind
(Op_Id
) = E_Operator
then
933 LT
:= Base_Type
(Etype
(L
));
934 RT
:= Base_Type
(Etype
(R
));
936 if Is_Array_Type
(LT
)
937 and then (RT
= LT
or else RT
= Base_Type
(Component_Type
(LT
)))
939 Add_One_Interp
(N
, Op_Id
, LT
);
941 elsif Is_Array_Type
(RT
)
942 and then LT
= Base_Type
(Component_Type
(RT
))
944 Add_One_Interp
(N
, Op_Id
, RT
);
947 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
951 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
955 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Concat
);
957 while Present
(Op_Id
) loop
958 if Ekind
(Op_Id
) = E_Operator
then
959 Find_Concatenation_Types
(L
, R
, Op_Id
, N
);
961 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
964 Op_Id
:= Homonym
(Op_Id
);
969 end Analyze_Concatenation
;
971 ------------------------------------
972 -- Analyze_Conditional_Expression --
973 ------------------------------------
975 procedure Analyze_Conditional_Expression
(N
: Node_Id
) is
976 Condition
: constant Node_Id
:= First
(Expressions
(N
));
977 Then_Expr
: constant Node_Id
:= Next
(Condition
);
978 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
981 Analyze_Expression
(Condition
);
982 Analyze_Expression
(Then_Expr
);
983 Analyze_Expression
(Else_Expr
);
984 Set_Etype
(N
, Etype
(Then_Expr
));
985 end Analyze_Conditional_Expression
;
987 -------------------------
988 -- Analyze_Equality_Op --
989 -------------------------
991 procedure Analyze_Equality_Op
(N
: Node_Id
) is
992 Loc
: constant Source_Ptr
:= Sloc
(N
);
993 L
: constant Node_Id
:= Left_Opnd
(N
);
994 R
: constant Node_Id
:= Right_Opnd
(N
);
998 Set_Etype
(N
, Any_Type
);
999 Candidate_Type
:= Empty
;
1001 Analyze_Expression
(L
);
1002 Analyze_Expression
(R
);
1004 -- If the entity is set, the node is a generic instance with a non-local
1005 -- reference to the predefined operator or to a user-defined function.
1006 -- It can also be an inequality that is expanded into the negation of a
1007 -- call to a user-defined equality operator.
1009 -- For the predefined case, the result is Boolean, regardless of the
1010 -- type of the operands. The operands may even be limited, if they are
1011 -- generic actuals. If they are overloaded, label the left argument with
1012 -- the common type that must be present, or with the type of the formal
1013 -- of the user-defined function.
1015 if Present
(Entity
(N
)) then
1017 Op_Id
:= Entity
(N
);
1019 if Ekind
(Op_Id
) = E_Operator
then
1020 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
);
1022 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1025 if Is_Overloaded
(L
) then
1027 if Ekind
(Op_Id
) = E_Operator
then
1028 Set_Etype
(L
, Intersect_Types
(L
, R
));
1030 Set_Etype
(L
, Etype
(First_Formal
(Op_Id
)));
1035 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1037 while Present
(Op_Id
) loop
1039 if Ekind
(Op_Id
) = E_Operator
then
1040 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1042 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1045 Op_Id
:= Homonym
(Op_Id
);
1049 -- If there was no match, and the operator is inequality, this may
1050 -- be a case where inequality has not been made explicit, as for
1051 -- tagged types. Analyze the node as the negation of an equality
1052 -- operation. This cannot be done earlier, because before analysis
1053 -- we cannot rule out the presence of an explicit inequality.
1055 if Etype
(N
) = Any_Type
1056 and then Nkind
(N
) = N_Op_Ne
1058 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Eq
);
1060 while Present
(Op_Id
) loop
1062 if Ekind
(Op_Id
) = E_Operator
then
1063 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1065 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1068 Op_Id
:= Homonym
(Op_Id
);
1071 if Etype
(N
) /= Any_Type
then
1072 Op_Id
:= Entity
(N
);
1078 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
1079 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
)))));
1081 Set_Entity
(Right_Opnd
(N
), Op_Id
);
1087 end Analyze_Equality_Op
;
1089 ----------------------------------
1090 -- Analyze_Explicit_Dereference --
1091 ----------------------------------
1093 procedure Analyze_Explicit_Dereference
(N
: Node_Id
) is
1094 Loc
: constant Source_Ptr
:= Sloc
(N
);
1095 P
: constant Node_Id
:= Prefix
(N
);
1101 function Is_Function_Type
return Boolean;
1102 -- Check whether node may be interpreted as an implicit function call.
1104 function Is_Function_Type
return Boolean is
1109 if not Is_Overloaded
(N
) then
1110 return Ekind
(Base_Type
(Etype
(N
))) = E_Subprogram_Type
1111 and then Etype
(Base_Type
(Etype
(N
))) /= Standard_Void_Type
;
1114 Get_First_Interp
(N
, I
, It
);
1116 while Present
(It
.Nam
) loop
1117 if Ekind
(Base_Type
(It
.Typ
)) /= E_Subprogram_Type
1118 or else Etype
(Base_Type
(It
.Typ
)) = Standard_Void_Type
1123 Get_Next_Interp
(I
, It
);
1128 end Is_Function_Type
;
1132 Set_Etype
(N
, Any_Type
);
1134 -- Test for remote access to subprogram type, and if so return
1135 -- after rewriting the original tree.
1137 if Remote_AST_E_Dereference
(P
) then
1141 -- Normal processing for other than remote access to subprogram type
1143 if not Is_Overloaded
(P
) then
1144 if Is_Access_Type
(Etype
(P
)) then
1146 -- Set the Etype. We need to go thru Is_For_Access_Subtypes
1147 -- to avoid other problems caused by the Private_Subtype
1148 -- and it is safe to go to the Base_Type because this is the
1149 -- same as converting the access value to its Base_Type.
1152 DT
: Entity_Id
:= Designated_Type
(Etype
(P
));
1155 if Ekind
(DT
) = E_Private_Subtype
1156 and then Is_For_Access_Subtype
(DT
)
1158 DT
:= Base_Type
(DT
);
1164 elsif Etype
(P
) /= Any_Type
then
1165 Error_Msg_N
("prefix of dereference must be an access type", N
);
1170 Get_First_Interp
(P
, I
, It
);
1172 while Present
(It
.Nam
) loop
1175 if Is_Access_Type
(T
) then
1176 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
1179 Get_Next_Interp
(I
, It
);
1184 -- Error if no interpretation of the prefix has an access type.
1186 if Etype
(N
) = Any_Type
then
1188 ("access type required in prefix of explicit dereference", P
);
1189 Set_Etype
(N
, Any_Type
);
1195 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
1197 and then (Nkind
(Parent
(N
)) /= N_Function_Call
1198 or else N
/= Name
(Parent
(N
)))
1200 and then (Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1201 or else N
/= Name
(Parent
(N
)))
1203 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
1204 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
1206 (Attribute_Name
(Parent
(N
)) /= Name_Address
1208 Attribute_Name
(Parent
(N
)) /= Name_Access
))
1210 -- Name is a function call with no actuals, in a context that
1211 -- requires deproceduring (including as an actual in an enclosing
1212 -- function or procedure call). We can conceive of pathological cases
1213 -- where the prefix might include functions that return access to
1214 -- subprograms and others that return a regular type. Disambiguation
1215 -- of those will have to take place in Resolve. See e.g. 7117-014.
1218 Make_Function_Call
(Loc
,
1219 Name
=> Make_Explicit_Dereference
(Loc
, P
),
1220 Parameter_Associations
=> New_List
);
1222 -- If the prefix is overloaded, remove operations that have formals,
1223 -- we know that this is a parameterless call.
1225 if Is_Overloaded
(P
) then
1226 Get_First_Interp
(P
, I
, It
);
1228 while Present
(It
.Nam
) loop
1231 if No
(First_Formal
(Base_Type
(Designated_Type
(T
)))) then
1237 Get_Next_Interp
(I
, It
);
1245 -- A value of remote access-to-class-wide must not be dereferenced
1248 Validate_Remote_Access_To_Class_Wide_Type
(N
);
1250 end Analyze_Explicit_Dereference
;
1252 ------------------------
1253 -- Analyze_Expression --
1254 ------------------------
1256 procedure Analyze_Expression
(N
: Node_Id
) is
1259 Check_Parameterless_Call
(N
);
1260 end Analyze_Expression
;
1262 ------------------------------------
1263 -- Analyze_Indexed_Component_Form --
1264 ------------------------------------
1266 procedure Analyze_Indexed_Component_Form
(N
: Node_Id
) is
1267 P
: constant Node_Id
:= Prefix
(N
);
1268 Exprs
: List_Id
:= Expressions
(N
);
1274 procedure Process_Function_Call
;
1275 -- Prefix in indexed component form is an overloadable entity,
1276 -- so the node is a function call. Reformat it as such.
1278 procedure Process_Indexed_Component
;
1279 -- Prefix in indexed component form is actually an indexed component.
1280 -- This routine processes it, knowing that the prefix is already
1283 procedure Process_Indexed_Component_Or_Slice
;
1284 -- An indexed component with a single index may designate a slice if
1285 -- the index is a subtype mark. This routine disambiguates these two
1286 -- cases by resolving the prefix to see if it is a subtype mark.
1288 procedure Process_Overloaded_Indexed_Component
;
1289 -- If the prefix of an indexed component is overloaded, the proper
1290 -- interpretation is selected by the index types and the context.
1292 ---------------------------
1293 -- Process_Function_Call --
1294 ---------------------------
1296 procedure Process_Function_Call
is
1300 Change_Node
(N
, N_Function_Call
);
1302 Set_Parameter_Associations
(N
, Exprs
);
1303 Actual
:= First
(Parameter_Associations
(N
));
1305 while Present
(Actual
) loop
1307 Check_Parameterless_Call
(Actual
);
1308 Next_Actual
(Actual
);
1312 end Process_Function_Call
;
1314 -------------------------------
1315 -- Process_Indexed_Component --
1316 -------------------------------
1318 procedure Process_Indexed_Component
is
1320 Array_Type
: Entity_Id
;
1322 Entry_Family
: Entity_Id
;
1325 Exp
:= First
(Exprs
);
1327 if Is_Overloaded
(P
) then
1328 Process_Overloaded_Indexed_Component
;
1331 Array_Type
:= Etype
(P
);
1333 -- Prefix must be appropriate for an array type.
1334 -- Dereference the prefix if it is an access type.
1336 if Is_Access_Type
(Array_Type
) then
1337 Array_Type
:= Designated_Type
(Array_Type
);
1340 if Is_Array_Type
(Array_Type
) then
1343 elsif (Is_Entity_Name
(P
)
1345 Ekind
(Entity
(P
)) = E_Entry_Family
)
1347 (Nkind
(P
) = N_Selected_Component
1349 Is_Entity_Name
(Selector_Name
(P
))
1351 Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
)
1353 if Is_Entity_Name
(P
) then
1354 Entry_Family
:= Entity
(P
);
1356 Entry_Family
:= Entity
(Selector_Name
(P
));
1360 Set_Etype
(N
, Any_Type
);
1362 if not Has_Compatible_Type
1363 (Exp
, Entry_Index_Type
(Entry_Family
))
1365 Error_Msg_N
("invalid index type in entry name", N
);
1367 elsif Present
(Next
(Exp
)) then
1368 Error_Msg_N
("too many subscripts in entry reference", N
);
1371 Set_Etype
(N
, Etype
(P
));
1376 elsif Is_Record_Type
(Array_Type
)
1377 and then Remote_AST_I_Dereference
(P
)
1381 elsif Array_Type
= Any_Type
then
1382 Set_Etype
(N
, Any_Type
);
1385 -- Here we definitely have a bad indexing
1388 if Nkind
(Parent
(N
)) = N_Requeue_Statement
1390 ((Is_Entity_Name
(P
)
1391 and then Ekind
(Entity
(P
)) = E_Entry
)
1393 (Nkind
(P
) = N_Selected_Component
1394 and then Is_Entity_Name
(Selector_Name
(P
))
1395 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
))
1398 ("REQUEUE does not permit parameters", First
(Exprs
));
1400 elsif Is_Entity_Name
(P
)
1401 and then Etype
(P
) = Standard_Void_Type
1403 Error_Msg_NE
("incorrect use of&", P
, Entity
(P
));
1406 Error_Msg_N
("array type required in indexed component", P
);
1409 Set_Etype
(N
, Any_Type
);
1413 Index
:= First_Index
(Array_Type
);
1415 while Present
(Index
) and then Present
(Exp
) loop
1416 if not Has_Compatible_Type
(Exp
, Etype
(Index
)) then
1417 Wrong_Type
(Exp
, Etype
(Index
));
1418 Set_Etype
(N
, Any_Type
);
1426 Set_Etype
(N
, Component_Type
(Array_Type
));
1428 if Present
(Index
) then
1430 ("too few subscripts in array reference", First
(Exprs
));
1432 elsif Present
(Exp
) then
1433 Error_Msg_N
("too many subscripts in array reference", Exp
);
1437 end Process_Indexed_Component
;
1439 ----------------------------------------
1440 -- Process_Indexed_Component_Or_Slice --
1441 ----------------------------------------
1443 procedure Process_Indexed_Component_Or_Slice
is
1445 Exp
:= First
(Exprs
);
1447 while Present
(Exp
) loop
1448 Analyze_Expression
(Exp
);
1452 Exp
:= First
(Exprs
);
1454 -- If one index is present, and it is a subtype name, then the
1455 -- node denotes a slice (note that the case of an explicit range
1456 -- for a slice was already built as an N_Slice node in the first
1457 -- place, so that case is not handled here).
1459 -- We use a replace rather than a rewrite here because this is one
1460 -- of the cases in which the tree built by the parser is plain wrong.
1463 and then Is_Entity_Name
(Exp
)
1464 and then Is_Type
(Entity
(Exp
))
1467 Make_Slice
(Sloc
(N
),
1469 Discrete_Range
=> New_Copy
(Exp
)));
1472 -- Otherwise (more than one index present, or single index is not
1473 -- a subtype name), then we have the indexed component case.
1476 Process_Indexed_Component
;
1478 end Process_Indexed_Component_Or_Slice
;
1480 ------------------------------------------
1481 -- Process_Overloaded_Indexed_Component --
1482 ------------------------------------------
1484 procedure Process_Overloaded_Indexed_Component
is
1493 Set_Etype
(N
, Any_Type
);
1494 Get_First_Interp
(P
, I
, It
);
1496 while Present
(It
.Nam
) loop
1499 if Is_Access_Type
(Typ
) then
1500 Typ
:= Designated_Type
(Typ
);
1503 if Is_Array_Type
(Typ
) then
1505 -- Got a candidate: verify that index types are compatible
1507 Index
:= First_Index
(Typ
);
1510 Exp
:= First
(Exprs
);
1512 while Present
(Index
) and then Present
(Exp
) loop
1513 if Has_Compatible_Type
(Exp
, Etype
(Index
)) then
1525 if Found
and then No
(Index
) and then No
(Exp
) then
1527 Etype
(Component_Type
(Typ
)),
1528 Etype
(Component_Type
(Typ
)));
1532 Get_Next_Interp
(I
, It
);
1535 if Etype
(N
) = Any_Type
then
1536 Error_Msg_N
("no legal interpetation for indexed component", N
);
1537 Set_Is_Overloaded
(N
, False);
1541 end Process_Overloaded_Indexed_Component
;
1543 ------------------------------------
1544 -- Analyze_Indexed_Component_Form --
1545 ------------------------------------
1548 -- Get name of array, function or type
1551 P_T
:= Base_Type
(Etype
(P
));
1553 if Is_Entity_Name
(P
)
1554 or else Nkind
(P
) = N_Operator_Symbol
1558 if Ekind
(U_N
) in Type_Kind
then
1560 -- Reformat node as a type conversion.
1562 E
:= Remove_Head
(Exprs
);
1564 if Present
(First
(Exprs
)) then
1566 ("argument of type conversion must be single expression", N
);
1569 Change_Node
(N
, N_Type_Conversion
);
1570 Set_Subtype_Mark
(N
, P
);
1572 Set_Expression
(N
, E
);
1574 -- After changing the node, call for the specific Analysis
1575 -- routine directly, to avoid a double call to the expander.
1577 Analyze_Type_Conversion
(N
);
1581 if Is_Overloadable
(U_N
) then
1582 Process_Function_Call
;
1584 elsif Ekind
(Etype
(P
)) = E_Subprogram_Type
1585 or else (Is_Access_Type
(Etype
(P
))
1587 Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
)
1589 -- Call to access_to-subprogram with possible implicit dereference
1591 Process_Function_Call
;
1593 elsif Ekind
(U_N
) = E_Generic_Function
1594 or else Ekind
(U_N
) = E_Generic_Procedure
1596 -- A common beginner's (or C++ templates fan) error.
1598 Error_Msg_N
("generic subprogram cannot be called", N
);
1599 Set_Etype
(N
, Any_Type
);
1603 Process_Indexed_Component_Or_Slice
;
1606 -- If not an entity name, prefix is an expression that may denote
1607 -- an array or an access-to-subprogram.
1611 if (Ekind
(P_T
) = E_Subprogram_Type
)
1612 or else (Is_Access_Type
(P_T
)
1614 Ekind
(Designated_Type
(P_T
)) = E_Subprogram_Type
)
1616 Process_Function_Call
;
1618 elsif Nkind
(P
) = N_Selected_Component
1619 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
1621 Process_Function_Call
;
1624 -- Indexed component, slice, or a call to a member of a family
1625 -- entry, which will be converted to an entry call later.
1626 Process_Indexed_Component_Or_Slice
;
1629 end Analyze_Indexed_Component_Form
;
1631 ------------------------
1632 -- Analyze_Logical_Op --
1633 ------------------------
1635 procedure Analyze_Logical_Op
(N
: Node_Id
) is
1636 L
: constant Node_Id
:= Left_Opnd
(N
);
1637 R
: constant Node_Id
:= Right_Opnd
(N
);
1638 Op_Id
: Entity_Id
:= Entity
(N
);
1641 Set_Etype
(N
, Any_Type
);
1642 Candidate_Type
:= Empty
;
1644 Analyze_Expression
(L
);
1645 Analyze_Expression
(R
);
1647 if Present
(Op_Id
) then
1649 if Ekind
(Op_Id
) = E_Operator
then
1650 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
1652 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1656 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1658 while Present
(Op_Id
) loop
1659 if Ekind
(Op_Id
) = E_Operator
then
1660 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
1662 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1665 Op_Id
:= Homonym
(Op_Id
);
1670 end Analyze_Logical_Op
;
1672 ---------------------------
1673 -- Analyze_Membership_Op --
1674 ---------------------------
1676 procedure Analyze_Membership_Op
(N
: Node_Id
) is
1677 L
: constant Node_Id
:= Left_Opnd
(N
);
1678 R
: constant Node_Id
:= Right_Opnd
(N
);
1680 Index
: Interp_Index
;
1682 Found
: Boolean := False;
1686 procedure Try_One_Interp
(T1
: Entity_Id
);
1687 -- Routine to try one proposed interpretation. Note that the context
1688 -- of the operation plays no role in resolving the arguments, so that
1689 -- if there is more than one interpretation of the operands that is
1690 -- compatible with a membership test, the operation is ambiguous.
1692 procedure Try_One_Interp
(T1
: Entity_Id
) is
1694 if Has_Compatible_Type
(R
, T1
) then
1696 and then Base_Type
(T1
) /= Base_Type
(T_F
)
1698 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
1700 if It
= No_Interp
then
1701 Ambiguous_Operands
(N
);
1702 Set_Etype
(L
, Any_Type
);
1720 -- Start of processing for Analyze_Membership_Op
1723 Analyze_Expression
(L
);
1725 if Nkind
(R
) = N_Range
1726 or else (Nkind
(R
) = N_Attribute_Reference
1727 and then Attribute_Name
(R
) = Name_Range
)
1731 if not Is_Overloaded
(L
) then
1732 Try_One_Interp
(Etype
(L
));
1735 Get_First_Interp
(L
, Index
, It
);
1737 while Present
(It
.Typ
) loop
1738 Try_One_Interp
(It
.Typ
);
1739 Get_Next_Interp
(Index
, It
);
1743 -- If not a range, it can only be a subtype mark, or else there
1744 -- is a more basic error, to be diagnosed in Find_Type.
1749 if Is_Entity_Name
(R
) then
1750 Check_Fully_Declared
(Entity
(R
), R
);
1754 -- Compatibility between expression and subtype mark or range is
1755 -- checked during resolution. The result of the operation is Boolean
1758 Set_Etype
(N
, Standard_Boolean
);
1759 end Analyze_Membership_Op
;
1761 ----------------------
1762 -- Analyze_Negation --
1763 ----------------------
1765 procedure Analyze_Negation
(N
: Node_Id
) is
1766 R
: constant Node_Id
:= Right_Opnd
(N
);
1767 Op_Id
: Entity_Id
:= Entity
(N
);
1770 Set_Etype
(N
, Any_Type
);
1771 Candidate_Type
:= Empty
;
1773 Analyze_Expression
(R
);
1775 if Present
(Op_Id
) then
1776 if Ekind
(Op_Id
) = E_Operator
then
1777 Find_Negation_Types
(R
, Op_Id
, N
);
1779 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1783 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1785 while Present
(Op_Id
) loop
1786 if Ekind
(Op_Id
) = E_Operator
then
1787 Find_Negation_Types
(R
, Op_Id
, N
);
1789 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
1792 Op_Id
:= Homonym
(Op_Id
);
1797 end Analyze_Negation
;
1803 procedure Analyze_Null
(N
: Node_Id
) is
1805 Set_Etype
(N
, Any_Access
);
1808 ----------------------
1809 -- Analyze_One_Call --
1810 ----------------------
1812 procedure Analyze_One_Call
1816 Success
: out Boolean)
1818 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
1819 Prev_T
: constant Entity_Id
:= Etype
(N
);
1822 Is_Indexed
: Boolean := False;
1823 Subp_Type
: constant Entity_Id
:= Etype
(Nam
);
1827 -- If candidate interpretation matches, indicate name and type of
1828 -- result on call node.
1834 procedure Set_Name
is
1836 Add_One_Interp
(N
, Nam
, Etype
(Nam
));
1839 -- If the prefix of the call is a name, indicate the entity
1840 -- being called. If it is not a name, it is an expression that
1841 -- denotes an access to subprogram or else an entry or family. In
1842 -- the latter case, the name is a selected component, and the entity
1843 -- being called is noted on the selector.
1845 if not Is_Type
(Nam
) then
1846 if Is_Entity_Name
(Name
(N
))
1847 or else Nkind
(Name
(N
)) = N_Operator_Symbol
1849 Set_Entity
(Name
(N
), Nam
);
1851 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
1852 Set_Entity
(Selector_Name
(Name
(N
)), Nam
);
1856 if Debug_Flag_E
and not Report
then
1857 Write_Str
(" Overloaded call ");
1858 Write_Int
(Int
(N
));
1859 Write_Str
(" compatible with ");
1860 Write_Int
(Int
(Nam
));
1865 -- Start of processing for Analyze_One_Call
1870 -- If the subprogram has no formals, or if all the formals have
1871 -- defaults, and the return type is an array type, the node may
1872 -- denote an indexing of the result of a parameterless call.
1874 if Needs_No_Actuals
(Nam
)
1875 and then Present
(Actuals
)
1877 if Is_Array_Type
(Subp_Type
) then
1878 Is_Indexed
:= Try_Indexed_Call
(N
, Nam
, Subp_Type
);
1880 elsif Is_Access_Type
(Subp_Type
)
1881 and then Is_Array_Type
(Designated_Type
(Subp_Type
))
1884 Try_Indexed_Call
(N
, Nam
, Designated_Type
(Subp_Type
));
1886 elsif Is_Access_Type
(Subp_Type
)
1887 and then Ekind
(Designated_Type
(Subp_Type
)) = E_Subprogram_Type
1889 Is_Indexed
:= Try_Indirect_Call
(N
, Nam
, Subp_Type
);
1894 Normalize_Actuals
(N
, Nam
, (Report
and not Is_Indexed
), Norm_OK
);
1898 -- Mismatch in number or names of parameters
1900 if Debug_Flag_E
then
1901 Write_Str
(" normalization fails in call ");
1902 Write_Int
(Int
(N
));
1903 Write_Str
(" with subprogram ");
1904 Write_Int
(Int
(Nam
));
1908 -- If the context expects a function call, discard any interpretation
1909 -- that is a procedure. If the node is not overloaded, leave as is for
1910 -- better error reporting when type mismatch is found.
1912 elsif Nkind
(N
) = N_Function_Call
1913 and then Is_Overloaded
(Name
(N
))
1914 and then Ekind
(Nam
) = E_Procedure
1918 -- Ditto for function calls in a procedure context.
1920 elsif Nkind
(N
) = N_Procedure_Call_Statement
1921 and then Is_Overloaded
(Name
(N
))
1922 and then Etype
(Nam
) /= Standard_Void_Type
1926 elsif not Present
(Actuals
) then
1928 -- If Normalize succeeds, then there are default parameters for
1933 elsif Ekind
(Nam
) = E_Operator
then
1935 if Nkind
(N
) = N_Procedure_Call_Statement
then
1939 -- This can occur when the prefix of the call is an operator
1940 -- name or an expanded name whose selector is an operator name.
1942 Analyze_Operator_Call
(N
, Nam
);
1944 if Etype
(N
) /= Prev_T
then
1946 -- There may be a user-defined operator that hides the
1947 -- current interpretation. We must check for this independently
1948 -- of the analysis of the call with the user-defined operation,
1949 -- because the parameter names may be wrong and yet the hiding
1950 -- takes place. Fixes b34014o.
1952 if Is_Overloaded
(Name
(N
)) then
1958 Get_First_Interp
(Name
(N
), I
, It
);
1960 while Present
(It
.Nam
) loop
1962 if Ekind
(It
.Nam
) /= E_Operator
1963 and then Hides_Op
(It
.Nam
, Nam
)
1966 (First_Actual
(N
), Etype
(First_Formal
(It
.Nam
)))
1967 and then (No
(Next_Actual
(First_Actual
(N
)))
1968 or else Has_Compatible_Type
1969 (Next_Actual
(First_Actual
(N
)),
1970 Etype
(Next_Formal
(First_Formal
(It
.Nam
)))))
1972 Set_Etype
(N
, Prev_T
);
1976 Get_Next_Interp
(I
, It
);
1981 -- If operator matches formals, record its name on the call.
1982 -- If the operator is overloaded, Resolve will select the
1983 -- correct one from the list of interpretations. The call
1984 -- node itself carries the first candidate.
1986 Set_Entity
(Name
(N
), Nam
);
1989 elsif Report
and then Etype
(N
) = Any_Type
then
1990 Error_Msg_N
("incompatible arguments for operator", N
);
1994 -- Normalize_Actuals has chained the named associations in the
1995 -- correct order of the formals.
1997 Actual
:= First_Actual
(N
);
1998 Formal
:= First_Formal
(Nam
);
2000 while Present
(Actual
) and then Present
(Formal
) loop
2002 if (Nkind
(Parent
(Actual
)) /= N_Parameter_Association
2003 or else Chars
(Selector_Name
(Parent
(Actual
))) = Chars
(Formal
))
2005 if Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
2006 Next_Actual
(Actual
);
2007 Next_Formal
(Formal
);
2010 if Debug_Flag_E
then
2011 Write_Str
(" type checking fails in call ");
2012 Write_Int
(Int
(N
));
2013 Write_Str
(" with formal ");
2014 Write_Int
(Int
(Formal
));
2015 Write_Str
(" in subprogram ");
2016 Write_Int
(Int
(Nam
));
2020 if Report
and not Is_Indexed
then
2022 Wrong_Type
(Actual
, Etype
(Formal
));
2024 if Nkind
(Actual
) = N_Op_Eq
2025 and then Nkind
(Left_Opnd
(Actual
)) = N_Identifier
2027 Formal
:= First_Formal
(Nam
);
2029 while Present
(Formal
) loop
2031 if Chars
(Left_Opnd
(Actual
)) = Chars
(Formal
) then
2033 ("possible misspelling of `=>`!", Actual
);
2037 Next_Formal
(Formal
);
2041 if All_Errors_Mode
then
2042 Error_Msg_Sloc
:= Sloc
(Nam
);
2044 if Is_Overloadable
(Nam
)
2045 and then Present
(Alias
(Nam
))
2046 and then not Comes_From_Source
(Nam
)
2049 (" ==> in call to &#(inherited)!", Actual
, Nam
);
2051 Error_Msg_NE
(" ==> in call to &#!", Actual
, Nam
);
2060 -- Normalize_Actuals has verified that a default value exists
2061 -- for this formal. Current actual names a subsequent formal.
2063 Next_Formal
(Formal
);
2067 -- On exit, all actuals match.
2071 end Analyze_One_Call
;
2073 ----------------------------
2074 -- Analyze_Operator_Call --
2075 ----------------------------
2077 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
) is
2078 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
2079 Act1
: constant Node_Id
:= First_Actual
(N
);
2080 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
2083 if Present
(Act2
) then
2085 -- Maybe binary operators
2087 if Present
(Next_Actual
(Act2
)) then
2089 -- Too many actuals for an operator
2093 elsif Op_Name
= Name_Op_Add
2094 or else Op_Name
= Name_Op_Subtract
2095 or else Op_Name
= Name_Op_Multiply
2096 or else Op_Name
= Name_Op_Divide
2097 or else Op_Name
= Name_Op_Mod
2098 or else Op_Name
= Name_Op_Rem
2099 or else Op_Name
= Name_Op_Expon
2101 Find_Arithmetic_Types
(Act1
, Act2
, Op_Id
, N
);
2103 elsif Op_Name
= Name_Op_And
2104 or else Op_Name
= Name_Op_Or
2105 or else Op_Name
= Name_Op_Xor
2107 Find_Boolean_Types
(Act1
, Act2
, Op_Id
, N
);
2109 elsif Op_Name
= Name_Op_Lt
2110 or else Op_Name
= Name_Op_Le
2111 or else Op_Name
= Name_Op_Gt
2112 or else Op_Name
= Name_Op_Ge
2114 Find_Comparison_Types
(Act1
, Act2
, Op_Id
, N
);
2116 elsif Op_Name
= Name_Op_Eq
2117 or else Op_Name
= Name_Op_Ne
2119 Find_Equality_Types
(Act1
, Act2
, Op_Id
, N
);
2121 elsif Op_Name
= Name_Op_Concat
then
2122 Find_Concatenation_Types
(Act1
, Act2
, Op_Id
, N
);
2124 -- Is this else null correct, or should it be an abort???
2133 if Op_Name
= Name_Op_Subtract
or else
2134 Op_Name
= Name_Op_Add
or else
2135 Op_Name
= Name_Op_Abs
2137 Find_Unary_Types
(Act1
, Op_Id
, N
);
2140 Op_Name
= Name_Op_Not
2142 Find_Negation_Types
(Act1
, Op_Id
, N
);
2144 -- Is this else null correct, or should it be an abort???
2150 end Analyze_Operator_Call
;
2152 -------------------------------------------
2153 -- Analyze_Overloaded_Selected_Component --
2154 -------------------------------------------
2156 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
) is
2158 Nam
: Node_Id
:= Prefix
(N
);
2159 Sel
: Node_Id
:= Selector_Name
(N
);
2165 Get_First_Interp
(Nam
, I
, It
);
2167 Set_Etype
(Sel
, Any_Type
);
2169 while Present
(It
.Typ
) loop
2170 if Is_Access_Type
(It
.Typ
) then
2171 T
:= Designated_Type
(It
.Typ
);
2176 if Is_Record_Type
(T
) then
2177 Comp
:= First_Entity
(T
);
2179 while Present
(Comp
) loop
2181 if Chars
(Comp
) = Chars
(Sel
)
2182 and then Is_Visible_Component
(Comp
)
2184 Set_Entity_With_Style_Check
(Sel
, Comp
);
2185 Generate_Reference
(Comp
, Sel
);
2187 Set_Etype
(Sel
, Etype
(Comp
));
2188 Add_One_Interp
(N
, Etype
(Comp
), Etype
(Comp
));
2190 -- This also specifies a candidate to resolve the name.
2191 -- Further overloading will be resolved from context.
2193 Set_Etype
(Nam
, It
.Typ
);
2199 elsif Is_Concurrent_Type
(T
) then
2200 Comp
:= First_Entity
(T
);
2202 while Present
(Comp
)
2203 and then Comp
/= First_Private_Entity
(T
)
2205 if Chars
(Comp
) = Chars
(Sel
) then
2206 if Is_Overloadable
(Comp
) then
2207 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
2209 Set_Entity_With_Style_Check
(Sel
, Comp
);
2210 Generate_Reference
(Comp
, Sel
);
2213 Set_Etype
(Sel
, Etype
(Comp
));
2214 Set_Etype
(N
, Etype
(Comp
));
2215 Set_Etype
(Nam
, It
.Typ
);
2217 -- For access type case, introduce explicit deference for
2218 -- more uniform treatment of entry calls.
2220 if Is_Access_Type
(Etype
(Nam
)) then
2221 Insert_Explicit_Dereference
(Nam
);
2228 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
2232 Get_Next_Interp
(I
, It
);
2235 if Etype
(N
) = Any_Type
then
2236 Error_Msg_NE
("undefined selector& for overloaded prefix", N
, Sel
);
2237 Set_Entity
(Sel
, Any_Id
);
2238 Set_Etype
(Sel
, Any_Type
);
2241 end Analyze_Overloaded_Selected_Component
;
2243 ----------------------------------
2244 -- Analyze_Qualified_Expression --
2245 ----------------------------------
2247 procedure Analyze_Qualified_Expression
(N
: Node_Id
) is
2248 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
2252 Set_Etype
(N
, Any_Type
);
2256 if T
= Any_Type
then
2259 Check_Fully_Declared
(T
, N
);
2261 Analyze_Expression
(Expression
(N
));
2263 end Analyze_Qualified_Expression
;
2269 procedure Analyze_Range
(N
: Node_Id
) is
2270 L
: constant Node_Id
:= Low_Bound
(N
);
2271 H
: constant Node_Id
:= High_Bound
(N
);
2272 I1
, I2
: Interp_Index
;
2275 procedure Check_Common_Type
(T1
, T2
: Entity_Id
);
2276 -- Verify the compatibility of two types, and choose the
2277 -- non universal one if the other is universal.
2279 procedure Check_High_Bound
(T
: Entity_Id
);
2280 -- Test one interpretation of the low bound against all those
2281 -- of the high bound.
2283 -----------------------
2284 -- Check_Common_Type --
2285 -----------------------
2287 procedure Check_Common_Type
(T1
, T2
: Entity_Id
) is
2289 if Covers
(T1
, T2
) or else Covers
(T2
, T1
) then
2290 if T1
= Universal_Integer
2291 or else T1
= Universal_Real
2292 or else T1
= Any_Character
2294 Add_One_Interp
(N
, Base_Type
(T2
), Base_Type
(T2
));
2296 elsif (T1
= T2
) then
2297 Add_One_Interp
(N
, T1
, T1
);
2300 Add_One_Interp
(N
, Base_Type
(T1
), Base_Type
(T1
));
2303 end Check_Common_Type
;
2305 ----------------------
2306 -- Check_High_Bound --
2307 ----------------------
2309 procedure Check_High_Bound
(T
: Entity_Id
) is
2311 if not Is_Overloaded
(H
) then
2312 Check_Common_Type
(T
, Etype
(H
));
2314 Get_First_Interp
(H
, I2
, It2
);
2316 while Present
(It2
.Typ
) loop
2317 Check_Common_Type
(T
, It2
.Typ
);
2318 Get_Next_Interp
(I2
, It2
);
2321 end Check_High_Bound
;
2323 -- Start of processing for Analyze_Range
2326 Set_Etype
(N
, Any_Type
);
2327 Analyze_Expression
(L
);
2328 Analyze_Expression
(H
);
2330 if Etype
(L
) = Any_Type
or else Etype
(H
) = Any_Type
then
2334 if not Is_Overloaded
(L
) then
2335 Check_High_Bound
(Etype
(L
));
2337 Get_First_Interp
(L
, I1
, It1
);
2339 while Present
(It1
.Typ
) loop
2340 Check_High_Bound
(It1
.Typ
);
2341 Get_Next_Interp
(I1
, It1
);
2345 -- If result is Any_Type, then we did not find a compatible pair
2347 if Etype
(N
) = Any_Type
then
2348 Error_Msg_N
("incompatible types in range ", N
);
2353 -----------------------
2354 -- Analyze_Reference --
2355 -----------------------
2357 procedure Analyze_Reference
(N
: Node_Id
) is
2358 P
: constant Node_Id
:= Prefix
(N
);
2359 Acc_Type
: Entity_Id
;
2363 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
2364 Set_Etype
(Acc_Type
, Acc_Type
);
2365 Init_Size_Align
(Acc_Type
);
2366 Set_Directly_Designated_Type
(Acc_Type
, Etype
(P
));
2367 Set_Etype
(N
, Acc_Type
);
2368 end Analyze_Reference
;
2370 --------------------------------
2371 -- Analyze_Selected_Component --
2372 --------------------------------
2374 -- Prefix is a record type or a task or protected type. In the
2375 -- later case, the selector must denote a visible entry.
2377 procedure Analyze_Selected_Component
(N
: Node_Id
) is
2378 Name
: constant Node_Id
:= Prefix
(N
);
2379 Sel
: constant Node_Id
:= Selector_Name
(N
);
2381 Entity_List
: Entity_Id
;
2382 Prefix_Type
: Entity_Id
;
2387 -- Start of processing for Analyze_Selected_Component
2390 Set_Etype
(N
, Any_Type
);
2392 if Is_Overloaded
(Name
) then
2393 Analyze_Overloaded_Selected_Component
(N
);
2396 elsif Etype
(Name
) = Any_Type
then
2397 Set_Entity
(Sel
, Any_Id
);
2398 Set_Etype
(Sel
, Any_Type
);
2402 -- Function calls that are prefixes of selected components must be
2403 -- fully resolved in case we need to build an actual subtype, or
2404 -- do some other operation requiring a fully resolved prefix.
2406 -- Note: Resolving all Nkinds of nodes here doesn't work.
2407 -- (Breaks 2129-008) ???.
2409 if Nkind
(Name
) = N_Function_Call
then
2410 Resolve
(Name
, Etype
(Name
));
2413 Prefix_Type
:= Etype
(Name
);
2416 if Is_Access_Type
(Prefix_Type
) then
2417 if Is_Remote_Access_To_Class_Wide_Type
(Prefix_Type
)
2418 and then Comes_From_Source
(N
)
2420 -- A RACW object can never be used as prefix of a selected
2421 -- component since that means it is dereferenced without
2422 -- being a controlling operand of a dispatching operation
2426 ("invalid dereference of a remote access to class-wide value",
2429 Prefix_Type
:= Designated_Type
(Prefix_Type
);
2432 if Ekind
(Prefix_Type
) = E_Private_Subtype
then
2433 Prefix_Type
:= Base_Type
(Prefix_Type
);
2436 Entity_List
:= Prefix_Type
;
2438 -- For class-wide types, use the entity list of the root type. This
2439 -- indirection is specially important for private extensions because
2440 -- only the root type get switched (not the class-wide type).
2442 if Is_Class_Wide_Type
(Prefix_Type
) then
2443 Entity_List
:= Root_Type
(Prefix_Type
);
2446 Comp
:= First_Entity
(Entity_List
);
2448 -- If the selector has an original discriminant, the node appears in
2449 -- an instance. Replace the discriminant with the corresponding one
2450 -- in the current discriminated type. For nested generics, this must
2451 -- be done transitively, so note the new original discriminant.
2453 if Nkind
(Sel
) = N_Identifier
2454 and then Present
(Original_Discriminant
(Sel
))
2456 Comp
:= Find_Corresponding_Discriminant
(Sel
, Prefix_Type
);
2458 -- Mark entity before rewriting, for completeness and because
2459 -- subsequent semantic checks might examine the original node.
2461 Set_Entity
(Sel
, Comp
);
2462 Rewrite
(Selector_Name
(N
),
2463 New_Occurrence_Of
(Comp
, Sloc
(N
)));
2464 Set_Original_Discriminant
(Selector_Name
(N
), Comp
);
2465 Set_Etype
(N
, Etype
(Comp
));
2467 if Is_Access_Type
(Etype
(Name
)) then
2468 Insert_Explicit_Dereference
(Name
);
2471 elsif Is_Record_Type
(Prefix_Type
) then
2473 -- Find component with given name
2475 while Present
(Comp
) loop
2477 if Chars
(Comp
) = Chars
(Sel
)
2478 and then Is_Visible_Component
(Comp
)
2480 Set_Entity_With_Style_Check
(Sel
, Comp
);
2481 Generate_Reference
(Comp
, Sel
);
2483 Set_Etype
(Sel
, Etype
(Comp
));
2485 if Ekind
(Comp
) = E_Discriminant
then
2486 if Is_Unchecked_Union
(Prefix_Type
) then
2488 ("cannot reference discriminant of Unchecked_Union",
2492 if Is_Generic_Type
(Prefix_Type
)
2494 Is_Generic_Type
(Root_Type
(Prefix_Type
))
2496 Set_Original_Discriminant
(Sel
, Comp
);
2500 -- Resolve the prefix early otherwise it is not possible to
2501 -- build the actual subtype of the component: it may need
2502 -- to duplicate this prefix and duplication is only allowed
2503 -- on fully resolved expressions.
2505 Resolve
(Name
, Etype
(Name
));
2507 -- We never need an actual subtype for the case of a selection
2508 -- for a indexed component of a non-packed array, since in
2509 -- this case gigi generates all the checks and can find the
2510 -- necessary bounds information.
2512 -- We also do not need an actual subtype for the case of
2513 -- a first, last, length, or range attribute applied to a
2514 -- non-packed array, since gigi can again get the bounds in
2515 -- these cases (gigi cannot handle the packed case, since it
2516 -- has the bounds of the packed array type, not the original
2517 -- bounds of the type). However, if the prefix is itself a
2518 -- selected component, as in a.b.c (i), gigi may regard a.b.c
2519 -- as a dynamic-sized temporary, so we do generate an actual
2520 -- subtype for this case.
2522 Parent_N
:= Parent
(N
);
2524 if not Is_Packed
(Etype
(Comp
))
2526 ((Nkind
(Parent_N
) = N_Indexed_Component
2527 and then Nkind
(Name
) /= N_Selected_Component
)
2529 (Nkind
(Parent_N
) = N_Attribute_Reference
2530 and then (Attribute_Name
(Parent_N
) = Name_First
2532 Attribute_Name
(Parent_N
) = Name_Last
2534 Attribute_Name
(Parent_N
) = Name_Length
2536 Attribute_Name
(Parent_N
) = Name_Range
)))
2538 Set_Etype
(N
, Etype
(Comp
));
2540 -- In all other cases, we currently build an actual subtype. It
2541 -- seems likely that many of these cases can be avoided, but
2542 -- right now, the front end makes direct references to the
2543 -- bounds (e.g. in egnerating a length check), and if we do
2544 -- not make an actual subtype, we end up getting a direct
2545 -- reference to a discriminant which will not do.
2549 Build_Actual_Subtype_Of_Component
(Etype
(Comp
), N
);
2550 Insert_Action
(N
, Act_Decl
);
2552 if No
(Act_Decl
) then
2553 Set_Etype
(N
, Etype
(Comp
));
2556 -- Component type depends on discriminants. Enter the
2557 -- main attributes of the subtype.
2560 Subt
: Entity_Id
:= Defining_Identifier
(Act_Decl
);
2563 Set_Etype
(Subt
, Base_Type
(Etype
(Comp
)));
2564 Set_Ekind
(Subt
, Ekind
(Etype
(Comp
)));
2565 Set_Etype
(N
, Subt
);
2576 elsif Is_Private_Type
(Prefix_Type
) then
2578 -- Allow access only to discriminants of the type. If the
2579 -- type has no full view, gigi uses the parent type for
2580 -- the components, so we do the same here.
2582 if No
(Full_View
(Prefix_Type
)) then
2583 Entity_List
:= Root_Type
(Base_Type
(Prefix_Type
));
2584 Comp
:= First_Entity
(Entity_List
);
2587 while Present
(Comp
) loop
2589 if Chars
(Comp
) = Chars
(Sel
) then
2590 if Ekind
(Comp
) = E_Discriminant
then
2591 Set_Entity_With_Style_Check
(Sel
, Comp
);
2592 Generate_Reference
(Comp
, Sel
);
2594 Set_Etype
(Sel
, Etype
(Comp
));
2595 Set_Etype
(N
, Etype
(Comp
));
2597 if Is_Generic_Type
(Prefix_Type
)
2599 Is_Generic_Type
(Root_Type
(Prefix_Type
))
2601 Set_Original_Discriminant
(Sel
, Comp
);
2606 ("invisible selector for }",
2607 N
, First_Subtype
(Prefix_Type
));
2608 Set_Entity
(Sel
, Any_Id
);
2609 Set_Etype
(N
, Any_Type
);
2618 elsif Is_Concurrent_Type
(Prefix_Type
) then
2620 -- Prefix is concurrent type. Find visible operation with given name
2621 -- For a task, this can only include entries or discriminants if
2622 -- the task type is not an enclosing scope. If it is an enclosing
2623 -- scope (e.g. in an inner task) then all entities are visible, but
2624 -- the prefix must denote the enclosing scope, i.e. can only be
2625 -- a direct name or an expanded name.
2627 Set_Etype
(Sel
, Any_Type
);
2628 In_Scope
:= In_Open_Scopes
(Prefix_Type
);
2630 while Present
(Comp
) loop
2631 if Chars
(Comp
) = Chars
(Sel
) then
2632 if Is_Overloadable
(Comp
) then
2633 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
2635 elsif Ekind
(Comp
) = E_Discriminant
2636 or else Ekind
(Comp
) = E_Entry_Family
2638 and then Is_Entity_Name
(Name
))
2640 Set_Entity_With_Style_Check
(Sel
, Comp
);
2641 Generate_Reference
(Comp
, Sel
);
2647 Set_Etype
(Sel
, Etype
(Comp
));
2648 Set_Etype
(N
, Etype
(Comp
));
2650 if Ekind
(Comp
) = E_Discriminant
then
2651 Set_Original_Discriminant
(Sel
, Comp
);
2654 -- For access type case, introduce explicit deference for
2655 -- more uniform treatment of entry calls.
2657 if Is_Access_Type
(Etype
(Name
)) then
2658 Insert_Explicit_Dereference
(Name
);
2664 exit when not In_Scope
2665 and then Comp
= First_Private_Entity
(Prefix_Type
);
2668 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
2673 Error_Msg_NE
("invalid prefix in selected component&", N
, Sel
);
2676 -- If N still has no type, the component is not defined in the prefix.
2678 if Etype
(N
) = Any_Type
then
2680 -- If the prefix is a single concurrent object, use its name in
2681 -- the error message, rather than that of its anonymous type.
2683 if Is_Concurrent_Type
(Prefix_Type
)
2684 and then Is_Internal_Name
(Chars
(Prefix_Type
))
2685 and then not Is_Derived_Type
(Prefix_Type
)
2686 and then Is_Entity_Name
(Name
)
2689 Error_Msg_Node_2
:= Entity
(Name
);
2690 Error_Msg_NE
("no selector& for&", N
, Sel
);
2692 Check_Misspelled_Selector
(Entity_List
, Sel
);
2694 elsif Is_Generic_Type
(Prefix_Type
)
2695 and then Ekind
(Prefix_Type
) = E_Record_Type_With_Private
2696 and then Is_Record_Type
(Etype
(Prefix_Type
))
2698 -- If this is a derived formal type, the parent may have a
2699 -- different visibility at this point. Try for an inherited
2700 -- component before reporting an error.
2702 Set_Etype
(Prefix
(N
), Etype
(Prefix_Type
));
2703 Analyze_Selected_Component
(N
);
2707 if Ekind
(Prefix_Type
) = E_Record_Subtype
then
2709 -- Check whether this is a component of the base type
2710 -- which is absent from a statically constrained subtype.
2711 -- This will raise constraint error at run-time, but is
2712 -- not a compile-time error. When the selector is illegal
2713 -- for base type as well fall through and generate a
2714 -- compilation error anyway.
2716 Comp
:= First_Component
(Base_Type
(Prefix_Type
));
2718 while Present
(Comp
) loop
2720 if Chars
(Comp
) = Chars
(Sel
)
2721 and then Is_Visible_Component
(Comp
)
2723 Set_Entity_With_Style_Check
(Sel
, Comp
);
2724 Generate_Reference
(Comp
, Sel
);
2725 Set_Etype
(Sel
, Etype
(Comp
));
2726 Set_Etype
(N
, Etype
(Comp
));
2728 -- Emit appropriate message. Gigi will replace the
2729 -- node subsequently with the appropriate Raise.
2731 Apply_Compile_Time_Constraint_Error
2732 (N
, "component not present in }?",
2733 Ent
=> Prefix_Type
, Rep
=> False);
2734 Set_Raises_Constraint_Error
(N
);
2738 Next_Component
(Comp
);
2743 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
2744 Error_Msg_NE
("no selector& for}", N
, Sel
);
2746 Check_Misspelled_Selector
(Entity_List
, Sel
);
2750 Set_Entity
(Sel
, Any_Id
);
2751 Set_Etype
(Sel
, Any_Type
);
2753 end Analyze_Selected_Component
;
2755 ---------------------------
2756 -- Analyze_Short_Circuit --
2757 ---------------------------
2759 procedure Analyze_Short_Circuit
(N
: Node_Id
) is
2760 L
: constant Node_Id
:= Left_Opnd
(N
);
2761 R
: constant Node_Id
:= Right_Opnd
(N
);
2766 Analyze_Expression
(L
);
2767 Analyze_Expression
(R
);
2768 Set_Etype
(N
, Any_Type
);
2770 if not Is_Overloaded
(L
) then
2772 if Root_Type
(Etype
(L
)) = Standard_Boolean
2773 and then Has_Compatible_Type
(R
, Etype
(L
))
2775 Add_One_Interp
(N
, Etype
(L
), Etype
(L
));
2779 Get_First_Interp
(L
, Ind
, It
);
2781 while Present
(It
.Typ
) loop
2782 if Root_Type
(It
.Typ
) = Standard_Boolean
2783 and then Has_Compatible_Type
(R
, It
.Typ
)
2785 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
2788 Get_Next_Interp
(Ind
, It
);
2792 -- Here we have failed to find an interpretation. Clearly we
2793 -- know that it is not the case that both operands can have
2794 -- an interpretation of Boolean, but this is by far the most
2795 -- likely intended interpretation. So we simply resolve both
2796 -- operands as Booleans, and at least one of these resolutions
2797 -- will generate an error message, and we do not need to give
2798 -- a further error message on the short circuit operation itself.
2800 if Etype
(N
) = Any_Type
then
2801 Resolve
(L
, Standard_Boolean
);
2802 Resolve
(R
, Standard_Boolean
);
2803 Set_Etype
(N
, Standard_Boolean
);
2805 end Analyze_Short_Circuit
;
2811 procedure Analyze_Slice
(N
: Node_Id
) is
2812 P
: constant Node_Id
:= Prefix
(N
);
2813 D
: constant Node_Id
:= Discrete_Range
(N
);
2814 Array_Type
: Entity_Id
;
2816 procedure Analyze_Overloaded_Slice
;
2817 -- If the prefix is overloaded, select those interpretations that
2818 -- yield a one-dimensional array type.
2820 procedure Analyze_Overloaded_Slice
is
2826 Set_Etype
(N
, Any_Type
);
2827 Get_First_Interp
(P
, I
, It
);
2829 while Present
(It
.Nam
) loop
2832 if Is_Access_Type
(Typ
) then
2833 Typ
:= Designated_Type
(Typ
);
2836 if Is_Array_Type
(Typ
)
2837 and then Number_Dimensions
(Typ
) = 1
2838 and then Has_Compatible_Type
(D
, Etype
(First_Index
(Typ
)))
2840 Add_One_Interp
(N
, Typ
, Typ
);
2843 Get_Next_Interp
(I
, It
);
2846 if Etype
(N
) = Any_Type
then
2847 Error_Msg_N
("expect array type in prefix of slice", N
);
2849 end Analyze_Overloaded_Slice
;
2851 -- Start of processing for Analyze_Slice
2854 -- Analyze the prefix if not done already
2856 if No
(Etype
(P
)) then
2862 if Is_Overloaded
(P
) then
2863 Analyze_Overloaded_Slice
;
2866 Array_Type
:= Etype
(P
);
2867 Set_Etype
(N
, Any_Type
);
2869 if Is_Access_Type
(Array_Type
) then
2870 Array_Type
:= Designated_Type
(Array_Type
);
2873 if not Is_Array_Type
(Array_Type
) then
2874 Wrong_Type
(P
, Any_Array
);
2876 elsif Number_Dimensions
(Array_Type
) > 1 then
2878 ("type is not one-dimensional array in slice prefix", N
);
2881 Has_Compatible_Type
(D
, Etype
(First_Index
(Array_Type
)))
2883 Wrong_Type
(D
, Etype
(First_Index
(Array_Type
)));
2886 Set_Etype
(N
, Array_Type
);
2891 -----------------------------
2892 -- Analyze_Type_Conversion --
2893 -----------------------------
2895 procedure Analyze_Type_Conversion
(N
: Node_Id
) is
2896 Expr
: constant Node_Id
:= Expression
(N
);
2900 -- If Conversion_OK is set, then the Etype is already set, and the
2901 -- only processing required is to analyze the expression. This is
2902 -- used to construct certain "illegal" conversions which are not
2903 -- allowed by Ada semantics, but can be handled OK by Gigi, see
2904 -- Sinfo for further details.
2906 if Conversion_OK
(N
) then
2911 -- Otherwise full type analysis is required, as well as some semantic
2912 -- checks to make sure the argument of the conversion is appropriate.
2914 Find_Type
(Subtype_Mark
(N
));
2915 T
:= Entity
(Subtype_Mark
(N
));
2917 Check_Fully_Declared
(T
, N
);
2918 Analyze_Expression
(Expr
);
2919 Validate_Remote_Type_Type_Conversion
(N
);
2921 -- Only remaining step is validity checks on the argument. These
2922 -- are skipped if the conversion does not come from the source.
2924 if not Comes_From_Source
(N
) then
2927 elsif Nkind
(Expr
) = N_Null
then
2928 Error_Msg_N
("argument of conversion cannot be null", N
);
2929 Error_Msg_N
("\use qualified expression instead", N
);
2930 Set_Etype
(N
, Any_Type
);
2932 elsif Nkind
(Expr
) = N_Aggregate
then
2933 Error_Msg_N
("argument of conversion cannot be aggregate", N
);
2934 Error_Msg_N
("\use qualified expression instead", N
);
2936 elsif Nkind
(Expr
) = N_Allocator
then
2937 Error_Msg_N
("argument of conversion cannot be an allocator", N
);
2938 Error_Msg_N
("\use qualified expression instead", N
);
2940 elsif Nkind
(Expr
) = N_String_Literal
then
2941 Error_Msg_N
("argument of conversion cannot be string literal", N
);
2942 Error_Msg_N
("\use qualified expression instead", N
);
2944 elsif Nkind
(Expr
) = N_Character_Literal
then
2948 Error_Msg_N
("argument of conversion cannot be character literal",
2950 Error_Msg_N
("\use qualified expression instead", N
);
2953 elsif Nkind
(Expr
) = N_Attribute_Reference
2955 (Attribute_Name
(Expr
) = Name_Access
or else
2956 Attribute_Name
(Expr
) = Name_Unchecked_Access
or else
2957 Attribute_Name
(Expr
) = Name_Unrestricted_Access
)
2959 Error_Msg_N
("argument of conversion cannot be access", N
);
2960 Error_Msg_N
("\use qualified expression instead", N
);
2963 end Analyze_Type_Conversion
;
2965 ----------------------
2966 -- Analyze_Unary_Op --
2967 ----------------------
2969 procedure Analyze_Unary_Op
(N
: Node_Id
) is
2970 R
: constant Node_Id
:= Right_Opnd
(N
);
2971 Op_Id
: Entity_Id
:= Entity
(N
);
2974 Set_Etype
(N
, Any_Type
);
2975 Candidate_Type
:= Empty
;
2977 Analyze_Expression
(R
);
2979 if Present
(Op_Id
) then
2980 if Ekind
(Op_Id
) = E_Operator
then
2981 Find_Unary_Types
(R
, Op_Id
, N
);
2983 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
2987 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
2989 while Present
(Op_Id
) loop
2991 if Ekind
(Op_Id
) = E_Operator
then
2992 if No
(Next_Entity
(First_Entity
(Op_Id
))) then
2993 Find_Unary_Types
(R
, Op_Id
, N
);
2996 elsif Is_Overloadable
(Op_Id
) then
2997 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
3000 Op_Id
:= Homonym
(Op_Id
);
3005 end Analyze_Unary_Op
;
3007 ----------------------------------
3008 -- Analyze_Unchecked_Expression --
3009 ----------------------------------
3011 procedure Analyze_Unchecked_Expression
(N
: Node_Id
) is
3013 Analyze
(Expression
(N
), Suppress
=> All_Checks
);
3014 Set_Etype
(N
, Etype
(Expression
(N
)));
3015 Save_Interps
(Expression
(N
), N
);
3016 end Analyze_Unchecked_Expression
;
3018 ---------------------------------------
3019 -- Analyze_Unchecked_Type_Conversion --
3020 ---------------------------------------
3022 procedure Analyze_Unchecked_Type_Conversion
(N
: Node_Id
) is
3024 Find_Type
(Subtype_Mark
(N
));
3025 Analyze_Expression
(Expression
(N
));
3026 Set_Etype
(N
, Entity
(Subtype_Mark
(N
)));
3027 end Analyze_Unchecked_Type_Conversion
;
3029 ------------------------------------
3030 -- Analyze_User_Defined_Binary_Op --
3031 ------------------------------------
3033 procedure Analyze_User_Defined_Binary_Op
3038 -- Only do analysis if the operator Comes_From_Source, since otherwise
3039 -- the operator was generated by the expander, and all such operators
3040 -- always refer to the operators in package Standard.
3042 if Comes_From_Source
(N
) then
3044 F1
: constant Entity_Id
:= First_Formal
(Op_Id
);
3045 F2
: constant Entity_Id
:= Next_Formal
(F1
);
3048 -- Verify that Op_Id is a visible binary function. Note that since
3049 -- we know Op_Id is overloaded, potentially use visible means use
3050 -- visible for sure (RM 9.4(11)).
3052 if Ekind
(Op_Id
) = E_Function
3053 and then Present
(F2
)
3054 and then (Is_Immediately_Visible
(Op_Id
)
3055 or else Is_Potentially_Use_Visible
(Op_Id
))
3056 and then Has_Compatible_Type
(Left_Opnd
(N
), Etype
(F1
))
3057 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F2
))
3059 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3061 if Debug_Flag_E
then
3062 Write_Str
("user defined operator ");
3063 Write_Name
(Chars
(Op_Id
));
3064 Write_Str
(" on node ");
3065 Write_Int
(Int
(N
));
3071 end Analyze_User_Defined_Binary_Op
;
3073 -----------------------------------
3074 -- Analyze_User_Defined_Unary_Op --
3075 -----------------------------------
3077 procedure Analyze_User_Defined_Unary_Op
3082 -- Only do analysis if the operator Comes_From_Source, since otherwise
3083 -- the operator was generated by the expander, and all such operators
3084 -- always refer to the operators in package Standard.
3086 if Comes_From_Source
(N
) then
3088 F
: constant Entity_Id
:= First_Formal
(Op_Id
);
3091 -- Verify that Op_Id is a visible unary function. Note that since
3092 -- we know Op_Id is overloaded, potentially use visible means use
3093 -- visible for sure (RM 9.4(11)).
3095 if Ekind
(Op_Id
) = E_Function
3096 and then No
(Next_Formal
(F
))
3097 and then (Is_Immediately_Visible
(Op_Id
)
3098 or else Is_Potentially_Use_Visible
(Op_Id
))
3099 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F
))
3101 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3105 end Analyze_User_Defined_Unary_Op
;
3107 ---------------------------
3108 -- Check_Arithmetic_Pair --
3109 ---------------------------
3111 procedure Check_Arithmetic_Pair
3112 (T1
, T2
: Entity_Id
;
3116 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
3118 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
;
3119 -- Get specific type (i.e. non-universal type if there is one)
3121 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
is
3123 if T1
= Universal_Integer
or else T1
= Universal_Real
then
3124 return Base_Type
(T2
);
3126 return Base_Type
(T1
);
3130 -- Start of processing for Check_Arithmetic_Pair
3133 if Op_Name
= Name_Op_Add
or else Op_Name
= Name_Op_Subtract
then
3135 if Is_Numeric_Type
(T1
)
3136 and then Is_Numeric_Type
(T2
)
3137 and then (Covers
(T1
, T2
) or else Covers
(T2
, T1
))
3139 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
3142 elsif Op_Name
= Name_Op_Multiply
or else Op_Name
= Name_Op_Divide
then
3144 if Is_Fixed_Point_Type
(T1
)
3145 and then (Is_Fixed_Point_Type
(T2
)
3146 or else T2
= Universal_Real
)
3148 -- If Treat_Fixed_As_Integer is set then the Etype is already set
3149 -- and no further processing is required (this is the case of an
3150 -- operator constructed by Exp_Fixd for a fixed point operation)
3151 -- Otherwise add one interpretation with universal fixed result
3152 -- If the operator is given in functional notation, it comes
3153 -- from source and Fixed_As_Integer cannot apply.
3155 if Nkind
(N
) not in N_Op
3156 or else not Treat_Fixed_As_Integer
(N
) then
3157 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
3160 elsif Is_Fixed_Point_Type
(T2
)
3161 and then (Nkind
(N
) not in N_Op
3162 or else not Treat_Fixed_As_Integer
(N
))
3163 and then T1
= Universal_Real
3165 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
3167 elsif Is_Numeric_Type
(T1
)
3168 and then Is_Numeric_Type
(T2
)
3169 and then (Covers
(T1
, T2
) or else Covers
(T2
, T1
))
3171 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
3173 elsif Is_Fixed_Point_Type
(T1
)
3174 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3175 or else T2
= Universal_Integer
)
3177 Add_One_Interp
(N
, Op_Id
, T1
);
3179 elsif T2
= Universal_Real
3180 and then Base_Type
(T1
) = Base_Type
(Standard_Integer
)
3181 and then Op_Name
= Name_Op_Multiply
3183 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
3185 elsif T1
= Universal_Real
3186 and then Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3188 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
3190 elsif Is_Fixed_Point_Type
(T2
)
3191 and then (Base_Type
(T1
) = Base_Type
(Standard_Integer
)
3192 or else T1
= Universal_Integer
)
3193 and then Op_Name
= Name_Op_Multiply
3195 Add_One_Interp
(N
, Op_Id
, T2
);
3197 elsif T1
= Universal_Real
and then T2
= Universal_Integer
then
3198 Add_One_Interp
(N
, Op_Id
, T1
);
3200 elsif T2
= Universal_Real
3201 and then T1
= Universal_Integer
3202 and then Op_Name
= Name_Op_Multiply
3204 Add_One_Interp
(N
, Op_Id
, T2
);
3207 elsif Op_Name
= Name_Op_Mod
or else Op_Name
= Name_Op_Rem
then
3209 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
3210 -- set does not require any special processing, since the Etype is
3211 -- already set (case of operation constructed by Exp_Fixed).
3213 if Is_Integer_Type
(T1
)
3214 and then (Covers
(T1
, T2
) or else Covers
(T2
, T1
))
3216 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
3219 elsif Op_Name
= Name_Op_Expon
then
3221 if Is_Numeric_Type
(T1
)
3222 and then not Is_Fixed_Point_Type
(T1
)
3223 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3224 or else T2
= Universal_Integer
)
3226 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
3229 else pragma Assert
(Nkind
(N
) in N_Op_Shift
);
3231 -- If not one of the predefined operators, the node may be one
3232 -- of the intrinsic functions. Its kind is always specific, and
3233 -- we can use it directly, rather than the name of the operation.
3235 if Is_Integer_Type
(T1
)
3236 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3237 or else T2
= Universal_Integer
)
3239 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
3242 end Check_Arithmetic_Pair
;
3244 -------------------------------
3245 -- Check_Misspelled_Selector --
3246 -------------------------------
3248 procedure Check_Misspelled_Selector
3249 (Prefix
: Entity_Id
;
3252 Max_Suggestions
: constant := 2;
3253 Nr_Of_Suggestions
: Natural := 0;
3255 Suggestion_1
: Entity_Id
:= Empty
;
3256 Suggestion_2
: Entity_Id
:= Empty
;
3261 -- All the components of the prefix of selector Sel are matched
3262 -- against Sel and a count is maintained of possible misspellings.
3263 -- When at the end of the analysis there are one or two (not more!)
3264 -- possible misspellings, these misspellings will be suggested as
3265 -- possible correction.
3267 if not (Is_Private_Type
(Prefix
) or Is_Record_Type
(Prefix
)) then
3268 -- Concurrent types should be handled as well ???
3272 Get_Name_String
(Chars
(Sel
));
3275 S
: constant String (1 .. Name_Len
) :=
3276 Name_Buffer
(1 .. Name_Len
);
3279 Comp
:= First_Entity
(Prefix
);
3281 while Nr_Of_Suggestions
<= Max_Suggestions
3282 and then Present
(Comp
)
3285 if Is_Visible_Component
(Comp
) then
3286 Get_Name_String
(Chars
(Comp
));
3288 if Is_Bad_Spelling_Of
(Name_Buffer
(1 .. Name_Len
), S
) then
3289 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
3291 case Nr_Of_Suggestions
is
3292 when 1 => Suggestion_1
:= Comp
;
3293 when 2 => Suggestion_2
:= Comp
;
3294 when others => exit;
3299 Comp
:= Next_Entity
(Comp
);
3302 -- Report at most two suggestions
3304 if Nr_Of_Suggestions
= 1 then
3305 Error_Msg_NE
("\possible misspelling of&", Sel
, Suggestion_1
);
3307 elsif Nr_Of_Suggestions
= 2 then
3308 Error_Msg_Node_2
:= Suggestion_2
;
3309 Error_Msg_NE
("\possible misspelling of& or&",
3313 end Check_Misspelled_Selector
;
3315 ----------------------
3316 -- Defined_In_Scope --
3317 ----------------------
3319 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean
3321 S1
: constant Entity_Id
:= Scope
(Base_Type
(T
));
3325 or else (S1
= System_Aux_Id
and then S
= Scope
(S1
));
3326 end Defined_In_Scope
;
3332 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
) is
3339 if Extensions_Allowed
then
3340 Actual
:= First_Actual
(N
);
3342 while Present
(Actual
) loop
3343 if not Analyzed
(Etype
(Actual
))
3344 and then From_With_Type
(Etype
(Actual
))
3346 Error_Msg_Qual_Level
:= 1;
3348 ("missing with_clause for scope of imported type&",
3349 Actual
, Etype
(Actual
));
3350 Error_Msg_Qual_Level
:= 0;
3353 Next_Actual
(Actual
);
3357 if All_Errors_Mode
then
3359 -- Analyze each candidate call again, with full error reporting
3362 Error_Msg_N
("\no candidate interpretations "
3363 & "match the actuals:!", Nam
);
3365 Get_First_Interp
(Nam
, X
, It
);
3367 while Present
(It
.Nam
) loop
3368 Analyze_One_Call
(N
, It
.Nam
, True, Success
);
3369 Get_Next_Interp
(X
, It
);
3375 ("invalid parameter list in call " &
3376 "('/'R'E'P'O'R'T'_'E'R'R'O'R'S'='F'U'L'L for details)!",
3380 ("invalid parameter list in call (use -gnatf for details)!",
3385 if Nkind
(N
) = N_Function_Call
then
3386 Get_First_Interp
(Nam
, X
, It
);
3388 while Present
(It
.Nam
) loop
3389 if Ekind
(It
.Nam
) = E_Function
3390 or else Ekind
(It
.Nam
) = E_Operator
3394 Get_Next_Interp
(X
, It
);
3398 -- If all interpretations are procedures, this deserves a
3399 -- more precise message. Ditto if this appears as the prefix
3400 -- of a selected component, which may be a lexical error.
3403 "\context requires function call, found procedure name", Nam
);
3405 if Nkind
(Parent
(N
)) = N_Selected_Component
3406 and then N
= Prefix
(Parent
(N
))
3409 "\period should probably be semicolon", Parent
(N
));
3414 ---------------------------
3415 -- Find_Arithmetic_Types --
3416 ---------------------------
3418 procedure Find_Arithmetic_Types
3423 Index1
, Index2
: Interp_Index
;
3426 procedure Check_Right_Argument
(T
: Entity_Id
);
3427 -- Check right operand of operator
3429 procedure Check_Right_Argument
(T
: Entity_Id
) is
3431 if not Is_Overloaded
(R
) then
3432 Check_Arithmetic_Pair
(T
, Etype
(R
), Op_Id
, N
);
3434 Get_First_Interp
(R
, Index2
, It2
);
3436 while Present
(It2
.Typ
) loop
3437 Check_Arithmetic_Pair
(T
, It2
.Typ
, Op_Id
, N
);
3438 Get_Next_Interp
(Index2
, It2
);
3441 end Check_Right_Argument
;
3443 -- Start processing for Find_Arithmetic_Types
3446 if not Is_Overloaded
(L
) then
3447 Check_Right_Argument
(Etype
(L
));
3450 Get_First_Interp
(L
, Index1
, It1
);
3452 while Present
(It1
.Typ
) loop
3453 Check_Right_Argument
(It1
.Typ
);
3454 Get_Next_Interp
(Index1
, It1
);
3458 end Find_Arithmetic_Types
;
3460 ------------------------
3461 -- Find_Boolean_Types --
3462 ------------------------
3464 procedure Find_Boolean_Types
3469 Index
: Interp_Index
;
3472 procedure Check_Numeric_Argument
(T
: Entity_Id
);
3473 -- Special case for logical operations one of whose operands is an
3474 -- integer literal. If both are literal the result is any modular type.
3476 procedure Check_Numeric_Argument
(T
: Entity_Id
) is
3478 if T
= Universal_Integer
then
3479 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
3481 elsif Is_Modular_Integer_Type
(T
) then
3482 Add_One_Interp
(N
, Op_Id
, T
);
3484 end Check_Numeric_Argument
;
3486 -- Start of processing for Find_Boolean_Types
3489 if not Is_Overloaded
(L
) then
3491 if Etype
(L
) = Universal_Integer
3492 or else Etype
(L
) = Any_Modular
3494 if not Is_Overloaded
(R
) then
3495 Check_Numeric_Argument
(Etype
(R
));
3498 Get_First_Interp
(R
, Index
, It
);
3500 while Present
(It
.Typ
) loop
3501 Check_Numeric_Argument
(It
.Typ
);
3503 Get_Next_Interp
(Index
, It
);
3507 elsif Valid_Boolean_Arg
(Etype
(L
))
3508 and then Has_Compatible_Type
(R
, Etype
(L
))
3510 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
3514 Get_First_Interp
(L
, Index
, It
);
3516 while Present
(It
.Typ
) loop
3517 if Valid_Boolean_Arg
(It
.Typ
)
3518 and then Has_Compatible_Type
(R
, It
.Typ
)
3520 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
3523 Get_Next_Interp
(Index
, It
);
3526 end Find_Boolean_Types
;
3528 ---------------------------
3529 -- Find_Comparison_Types --
3530 ---------------------------
3532 procedure Find_Comparison_Types
3537 Index
: Interp_Index
;
3539 Found
: Boolean := False;
3542 Scop
: Entity_Id
:= Empty
;
3544 procedure Try_One_Interp
(T1
: Entity_Id
);
3545 -- Routine to try one proposed interpretation. Note that the context
3546 -- of the operator plays no role in resolving the arguments, so that
3547 -- if there is more than one interpretation of the operands that is
3548 -- compatible with comparison, the operation is ambiguous.
3550 procedure Try_One_Interp
(T1
: Entity_Id
) is
3553 -- If the operator is an expanded name, then the type of the operand
3554 -- must be defined in the corresponding scope. If the type is
3555 -- universal, the context will impose the correct type.
3558 and then not Defined_In_Scope
(T1
, Scop
)
3559 and then T1
/= Universal_Integer
3560 and then T1
/= Universal_Real
3561 and then T1
/= Any_String
3562 and then T1
/= Any_Composite
3567 if Valid_Comparison_Arg
(T1
)
3568 and then Has_Compatible_Type
(R
, T1
)
3571 and then Base_Type
(T1
) /= Base_Type
(T_F
)
3573 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
3575 if It
= No_Interp
then
3576 Ambiguous_Operands
(N
);
3577 Set_Etype
(L
, Any_Type
);
3591 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
3596 -- Start processing for Find_Comparison_Types
3600 if Nkind
(N
) = N_Function_Call
3601 and then Nkind
(Name
(N
)) = N_Expanded_Name
3603 Scop
:= Entity
(Prefix
(Name
(N
)));
3605 -- The prefix may be a package renaming, and the subsequent test
3606 -- requires the original package.
3608 if Ekind
(Scop
) = E_Package
3609 and then Present
(Renamed_Entity
(Scop
))
3611 Scop
:= Renamed_Entity
(Scop
);
3612 Set_Entity
(Prefix
(Name
(N
)), Scop
);
3616 if not Is_Overloaded
(L
) then
3617 Try_One_Interp
(Etype
(L
));
3620 Get_First_Interp
(L
, Index
, It
);
3622 while Present
(It
.Typ
) loop
3623 Try_One_Interp
(It
.Typ
);
3624 Get_Next_Interp
(Index
, It
);
3627 end Find_Comparison_Types
;
3629 ----------------------------------------
3630 -- Find_Non_Universal_Interpretations --
3631 ----------------------------------------
3633 procedure Find_Non_Universal_Interpretations
3639 Index
: Interp_Index
;
3643 if T1
= Universal_Integer
3644 or else T1
= Universal_Real
3646 if not Is_Overloaded
(R
) then
3648 (N
, Op_Id
, Standard_Boolean
, Base_Type
(Etype
(R
)));
3650 Get_First_Interp
(R
, Index
, It
);
3652 while Present
(It
.Typ
) loop
3653 if Covers
(It
.Typ
, T1
) then
3655 (N
, Op_Id
, Standard_Boolean
, Base_Type
(It
.Typ
));
3658 Get_Next_Interp
(Index
, It
);
3662 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(T1
));
3664 end Find_Non_Universal_Interpretations
;
3666 ------------------------------
3667 -- Find_Concatenation_Types --
3668 ------------------------------
3670 procedure Find_Concatenation_Types
3675 Op_Type
: constant Entity_Id
:= Etype
(Op_Id
);
3678 if Is_Array_Type
(Op_Type
)
3679 and then not Is_Limited_Type
(Op_Type
)
3681 and then (Has_Compatible_Type
(L
, Op_Type
)
3683 Has_Compatible_Type
(L
, Component_Type
(Op_Type
)))
3685 and then (Has_Compatible_Type
(R
, Op_Type
)
3687 Has_Compatible_Type
(R
, Component_Type
(Op_Type
)))
3689 Add_One_Interp
(N
, Op_Id
, Op_Type
);
3691 end Find_Concatenation_Types
;
3693 -------------------------
3694 -- Find_Equality_Types --
3695 -------------------------
3697 procedure Find_Equality_Types
3702 Index
: Interp_Index
;
3704 Found
: Boolean := False;
3707 Scop
: Entity_Id
:= Empty
;
3709 procedure Try_One_Interp
(T1
: Entity_Id
);
3710 -- The context of the operator plays no role in resolving the
3711 -- arguments, so that if there is more than one interpretation
3712 -- of the operands that is compatible with equality, the construct
3713 -- is ambiguous and an error can be emitted now, after trying to
3714 -- disambiguate, i.e. applying preference rules.
3716 procedure Try_One_Interp
(T1
: Entity_Id
) is
3719 -- If the operator is an expanded name, then the type of the operand
3720 -- must be defined in the corresponding scope. If the type is
3721 -- universal, the context will impose the correct type. An anonymous
3722 -- type for a 'Access reference is also universal in this sense, as
3723 -- the actual type is obtained from context.
3726 and then not Defined_In_Scope
(T1
, Scop
)
3727 and then T1
/= Universal_Integer
3728 and then T1
/= Universal_Real
3729 and then T1
/= Any_Access
3730 and then T1
/= Any_String
3731 and then T1
/= Any_Composite
3732 and then (Ekind
(T1
) /= E_Access_Subprogram_Type
3733 or else Comes_From_Source
(T1
))
3738 if T1
/= Standard_Void_Type
3739 and then not Is_Limited_Type
(T1
)
3740 and then not Is_Limited_Composite
(T1
)
3741 and then Ekind
(T1
) /= E_Anonymous_Access_Type
3742 and then Has_Compatible_Type
(R
, T1
)
3745 and then Base_Type
(T1
) /= Base_Type
(T_F
)
3747 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
3749 if It
= No_Interp
then
3750 Ambiguous_Operands
(N
);
3751 Set_Etype
(L
, Any_Type
);
3764 if not Analyzed
(L
) then
3768 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
3770 if Etype
(N
) = Any_Type
then
3772 -- Operator was not visible.
3779 -- Start of processing for Find_Equality_Types
3783 if Nkind
(N
) = N_Function_Call
3784 and then Nkind
(Name
(N
)) = N_Expanded_Name
3786 Scop
:= Entity
(Prefix
(Name
(N
)));
3788 -- The prefix may be a package renaming, and the subsequent test
3789 -- requires the original package.
3791 if Ekind
(Scop
) = E_Package
3792 and then Present
(Renamed_Entity
(Scop
))
3794 Scop
:= Renamed_Entity
(Scop
);
3795 Set_Entity
(Prefix
(Name
(N
)), Scop
);
3799 if not Is_Overloaded
(L
) then
3800 Try_One_Interp
(Etype
(L
));
3803 Get_First_Interp
(L
, Index
, It
);
3805 while Present
(It
.Typ
) loop
3806 Try_One_Interp
(It
.Typ
);
3807 Get_Next_Interp
(Index
, It
);
3810 end Find_Equality_Types
;
3812 -------------------------
3813 -- Find_Negation_Types --
3814 -------------------------
3816 procedure Find_Negation_Types
3821 Index
: Interp_Index
;
3825 if not Is_Overloaded
(R
) then
3827 if Etype
(R
) = Universal_Integer
then
3828 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
3830 elsif Valid_Boolean_Arg
(Etype
(R
)) then
3831 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
3835 Get_First_Interp
(R
, Index
, It
);
3837 while Present
(It
.Typ
) loop
3838 if Valid_Boolean_Arg
(It
.Typ
) then
3839 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
3842 Get_Next_Interp
(Index
, It
);
3845 end Find_Negation_Types
;
3847 ----------------------
3848 -- Find_Unary_Types --
3849 ----------------------
3851 procedure Find_Unary_Types
3856 Index
: Interp_Index
;
3860 if not Is_Overloaded
(R
) then
3861 if Is_Numeric_Type
(Etype
(R
)) then
3862 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(R
)));
3866 Get_First_Interp
(R
, Index
, It
);
3868 while Present
(It
.Typ
) loop
3869 if Is_Numeric_Type
(It
.Typ
) then
3870 Add_One_Interp
(N
, Op_Id
, Base_Type
(It
.Typ
));
3873 Get_Next_Interp
(Index
, It
);
3876 end Find_Unary_Types
;
3878 ---------------------------------
3879 -- Insert_Explicit_Dereference --
3880 ---------------------------------
3882 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
3883 New_Prefix
: Node_Id
:= Relocate_Node
(N
);
3889 Save_Interps
(N
, New_Prefix
);
3891 Make_Explicit_Dereference
(Sloc
(N
), Prefix
=> New_Prefix
));
3893 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
3895 if Is_Overloaded
(New_Prefix
) then
3897 -- The deference is also overloaded, and its interpretations are the
3898 -- designated types of the interpretations of the original node.
3900 Set_Is_Overloaded
(N
);
3901 Get_First_Interp
(New_Prefix
, I
, It
);
3903 while Present
(It
.Nam
) loop
3906 if Is_Access_Type
(T
) then
3907 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
3910 Get_Next_Interp
(I
, It
);
3916 end Insert_Explicit_Dereference
;
3922 function Junk_Operand
(N
: Node_Id
) return Boolean is
3926 if Error_Posted
(N
) then
3930 -- Get entity to be tested
3932 if Is_Entity_Name
(N
)
3933 and then Present
(Entity
(N
))
3937 -- An odd case, a procedure name gets converted to a very peculiar
3938 -- function call, and here is where we detect this happening.
3940 elsif Nkind
(N
) = N_Function_Call
3941 and then Is_Entity_Name
(Name
(N
))
3942 and then Present
(Entity
(Name
(N
)))
3946 -- Another odd case, there are at least some cases of selected
3947 -- components where the selected component is not marked as having
3948 -- an entity, even though the selector does have an entity
3950 elsif Nkind
(N
) = N_Selected_Component
3951 and then Present
(Entity
(Selector_Name
(N
)))
3953 Enode
:= Selector_Name
(N
);
3959 -- Now test the entity we got to see if it a bad case
3961 case Ekind
(Entity
(Enode
)) is
3965 ("package name cannot be used as operand", Enode
);
3967 when Generic_Unit_Kind
=>
3969 ("generic unit name cannot be used as operand", Enode
);
3973 ("subtype name cannot be used as operand", Enode
);
3977 ("entry name cannot be used as operand", Enode
);
3981 ("procedure name cannot be used as operand", Enode
);
3985 ("exception name cannot be used as operand", Enode
);
3987 when E_Block | E_Label | E_Loop
=>
3989 ("label name cannot be used as operand", Enode
);
3999 --------------------
4000 -- Operator_Check --
4001 --------------------
4003 procedure Operator_Check
(N
: Node_Id
) is
4005 -- Test for case of no interpretation found for operator
4007 if Etype
(N
) = Any_Type
then
4013 R
:= Right_Opnd
(N
);
4015 if Nkind
(N
) in N_Binary_Op
then
4021 -- If either operand has no type, then don't complain further,
4022 -- since this simply means that we have a propragated error.
4025 or else Etype
(R
) = Any_Type
4026 or else (Nkind
(N
) in N_Binary_Op
and then Etype
(L
) = Any_Type
)
4030 -- We explicitly check for the case of concatenation of
4031 -- component with component to avoid reporting spurious
4032 -- matching array types that might happen to be lurking
4033 -- in distant packages (such as run-time packages). This
4034 -- also prevents inconsistencies in the messages for certain
4035 -- ACVC B tests, which can vary depending on types declared
4036 -- in run-time interfaces. A further improvement, when
4037 -- aggregates are present, is to look for a well-typed operand.
4039 elsif Present
(Candidate_Type
)
4040 and then (Nkind
(N
) /= N_Op_Concat
4041 or else Is_Array_Type
(Etype
(L
))
4042 or else Is_Array_Type
(Etype
(R
)))
4045 if Nkind
(N
) = N_Op_Concat
then
4046 if Etype
(L
) /= Any_Composite
4047 and then Is_Array_Type
(Etype
(L
))
4049 Candidate_Type
:= Etype
(L
);
4051 elsif Etype
(R
) /= Any_Composite
4052 and then Is_Array_Type
(Etype
(R
))
4054 Candidate_Type
:= Etype
(R
);
4059 ("operator for} is not directly visible!",
4060 N
, First_Subtype
(Candidate_Type
));
4061 Error_Msg_N
("use clause would make operation legal!", N
);
4064 -- If either operand is a junk operand (e.g. package name), then
4065 -- post appropriate error messages, but do not complain further.
4067 -- Note that the use of OR in this test instead of OR ELSE
4068 -- is quite deliberate, we may as well check both operands
4069 -- in the binary operator case.
4071 elsif Junk_Operand
(R
)
4072 or (Nkind
(N
) in N_Binary_Op
and then Junk_Operand
(L
))
4076 -- If we have a logical operator, one of whose operands is
4077 -- Boolean, then we know that the other operand cannot resolve
4078 -- to Boolean (since we got no interpretations), but in that
4079 -- case we pretty much know that the other operand should be
4080 -- Boolean, so resolve it that way (generating an error)
4082 elsif Nkind
(N
) = N_Op_And
4086 Nkind
(N
) = N_Op_Xor
4088 if Etype
(L
) = Standard_Boolean
then
4089 Resolve
(R
, Standard_Boolean
);
4091 elsif Etype
(R
) = Standard_Boolean
then
4092 Resolve
(L
, Standard_Boolean
);
4096 -- For an arithmetic operator or comparison operator, if one
4097 -- of the operands is numeric, then we know the other operand
4098 -- is not the same numeric type. If it is a non-numeric type,
4099 -- then probably it is intended to match the other operand.
4101 elsif Nkind
(N
) = N_Op_Add
or else
4102 Nkind
(N
) = N_Op_Divide
or else
4103 Nkind
(N
) = N_Op_Ge
or else
4104 Nkind
(N
) = N_Op_Gt
or else
4105 Nkind
(N
) = N_Op_Le
or else
4106 Nkind
(N
) = N_Op_Lt
or else
4107 Nkind
(N
) = N_Op_Mod
or else
4108 Nkind
(N
) = N_Op_Multiply
or else
4109 Nkind
(N
) = N_Op_Rem
or else
4110 Nkind
(N
) = N_Op_Subtract
4112 if Is_Numeric_Type
(Etype
(L
))
4113 and then not Is_Numeric_Type
(Etype
(R
))
4115 Resolve
(R
, Etype
(L
));
4118 elsif Is_Numeric_Type
(Etype
(R
))
4119 and then not Is_Numeric_Type
(Etype
(L
))
4121 Resolve
(L
, Etype
(R
));
4125 -- Comparisons on A'Access are common enough to deserve a
4128 elsif (Nkind
(N
) = N_Op_Eq
or else
4129 Nkind
(N
) = N_Op_Ne
)
4130 and then Ekind
(Etype
(L
)) = E_Access_Attribute_Type
4131 and then Ekind
(Etype
(R
)) = E_Access_Attribute_Type
4134 ("two access attributes cannot be compared directly", N
);
4136 ("\they must be converted to an explicit type for comparison",
4140 -- Another one for C programmers
4142 elsif Nkind
(N
) = N_Op_Concat
4143 and then Valid_Boolean_Arg
(Etype
(L
))
4144 and then Valid_Boolean_Arg
(Etype
(R
))
4146 Error_Msg_N
("invalid operands for concatenation", N
);
4147 Error_Msg_N
("\maybe AND was meant", N
);
4150 -- A special case for comparison of access parameter with null
4152 elsif Nkind
(N
) = N_Op_Eq
4153 and then Is_Entity_Name
(L
)
4154 and then Nkind
(Parent
(Entity
(L
))) = N_Parameter_Specification
4155 and then Nkind
(Parameter_Type
(Parent
(Entity
(L
)))) =
4157 and then Nkind
(R
) = N_Null
4159 Error_Msg_N
("access parameter is not allowed to be null", L
);
4160 Error_Msg_N
("\(call would raise Constraint_Error)", L
);
4164 -- If we fall through then just give general message. Note
4165 -- that in the following messages, if the operand is overloaded
4166 -- we choose an arbitrary type to complain about, but that is
4167 -- probably more useful than not giving a type at all.
4169 if Nkind
(N
) in N_Unary_Op
then
4170 Error_Msg_Node_2
:= Etype
(R
);
4171 Error_Msg_N
("operator& not defined for}", N
);
4175 Error_Msg_N
("invalid operand types for operator&", N
);
4177 if Nkind
(N
) in N_Binary_Op
4178 and then Nkind
(N
) /= N_Op_Concat
4180 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
4181 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
4188 -----------------------
4189 -- Try_Indirect_Call --
4190 -----------------------
4192 function Try_Indirect_Call
4198 Actuals
: List_Id
:= Parameter_Associations
(N
);
4199 Actual
: Node_Id
:= First
(Actuals
);
4200 Formal
: Entity_Id
:= First_Formal
(Designated_Type
(Typ
));
4203 while Present
(Actual
)
4204 and then Present
(Formal
)
4206 if not Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
4211 Next_Formal
(Formal
);
4214 if No
(Actual
) and then No
(Formal
) then
4215 Add_One_Interp
(N
, Nam
, Etype
(Designated_Type
(Typ
)));
4217 -- Nam is a candidate interpretation for the name in the call,
4218 -- if it is not an indirect call.
4220 if not Is_Type
(Nam
)
4221 and then Is_Entity_Name
(Name
(N
))
4223 Set_Entity
(Name
(N
), Nam
);
4230 end Try_Indirect_Call
;
4232 ----------------------
4233 -- Try_Indexed_Call --
4234 ----------------------
4236 function Try_Indexed_Call
4242 Actuals
: List_Id
:= Parameter_Associations
(N
);
4243 Actual
: Node_Id
:= First
(Actuals
);
4244 Index
: Entity_Id
:= First_Index
(Typ
);
4247 while Present
(Actual
)
4248 and then Present
(Index
)
4250 -- If the parameter list has a named association, the expression
4251 -- is definitely a call and not an indexed component.
4253 if Nkind
(Actual
) = N_Parameter_Association
then
4257 if not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
4265 if No
(Actual
) and then No
(Index
) then
4266 Add_One_Interp
(N
, Nam
, Component_Type
(Typ
));
4268 -- Nam is a candidate interpretation for the name in the call,
4269 -- if it is not an indirect call.
4271 if not Is_Type
(Nam
)
4272 and then Is_Entity_Name
(Name
(N
))
4274 Set_Entity
(Name
(N
), Nam
);
4282 end Try_Indexed_Call
;