1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2002, Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
28 with Atree
; use Atree
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Errout
; use Errout
;
32 with Exp_Util
; use Exp_Util
;
33 with Hostparm
; use Hostparm
;
34 with Itypes
; use Itypes
;
35 with Lib
.Xref
; use Lib
.Xref
;
36 with Namet
; use Namet
;
37 with Nlists
; use Nlists
;
38 with Nmake
; use Nmake
;
40 with Output
; use Output
;
41 with Restrict
; use Restrict
;
43 with Sem_Cat
; use Sem_Cat
;
44 with Sem_Ch3
; use Sem_Ch3
;
45 with Sem_Ch8
; use Sem_Ch8
;
46 with Sem_Dist
; use Sem_Dist
;
47 with Sem_Eval
; use Sem_Eval
;
48 with Sem_Res
; use Sem_Res
;
49 with Sem_Util
; use Sem_Util
;
50 with Sem_Type
; use Sem_Type
;
51 with Stand
; use Stand
;
52 with Sinfo
; use Sinfo
;
53 with Snames
; use Snames
;
54 with Tbuild
; use Tbuild
;
56 with GNAT
.Spelling_Checker
; use GNAT
.Spelling_Checker
;
58 package body Sem_Ch4
is
60 -----------------------
61 -- Local Subprograms --
62 -----------------------
64 procedure Analyze_Expression
(N
: Node_Id
);
65 -- For expressions that are not names, this is just a call to analyze.
66 -- If the expression is a name, it may be a call to a parameterless
67 -- function, and if so must be converted into an explicit call node
68 -- and analyzed as such. This deproceduring must be done during the first
69 -- pass of overload resolution, because otherwise a procedure call with
70 -- overloaded actuals may fail to resolve. See 4327-001 for an example.
72 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
);
73 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
74 -- is an operator name or an expanded name whose selector is an operator
75 -- name, and one possible interpretation is as a predefined operator.
77 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
);
78 -- If the prefix of a selected_component is overloaded, the proper
79 -- interpretation that yields a record type with the proper selector
80 -- name must be selected.
82 procedure Analyze_User_Defined_Binary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
83 -- Procedure to analyze a user defined binary operator, which is resolved
84 -- like a function, but instead of a list of actuals it is presented
85 -- with the left and right operands of an operator node.
87 procedure Analyze_User_Defined_Unary_Op
(N
: Node_Id
; Op_Id
: Entity_Id
);
88 -- Procedure to analyze a user defined unary operator, which is resolved
89 -- like a function, but instead of a list of actuals, it is presented with
90 -- the operand of the operator node.
92 procedure Ambiguous_Operands
(N
: Node_Id
);
93 -- for equality, membership, and comparison operators with overloaded
94 -- arguments, list possible interpretations.
96 procedure Insert_Explicit_Dereference
(N
: Node_Id
);
97 -- In a context that requires a composite or subprogram type and
98 -- where a prefix is an access type, insert an explicit dereference.
100 procedure Analyze_One_Call
104 Success
: out Boolean);
105 -- Check one interpretation of an overloaded subprogram name for
106 -- compatibility with the types of the actuals in a call. If there is a
107 -- single interpretation which does not match, post error if Report is
110 -- Nam is the entity that provides the formals against which the actuals
111 -- are checked. Nam is either the name of a subprogram, or the internal
112 -- subprogram type constructed for an access_to_subprogram. If the actuals
113 -- are compatible with Nam, then Nam is added to the list of candidate
114 -- interpretations for N, and Success is set to True.
116 procedure Check_Misspelled_Selector
119 -- Give possible misspelling diagnostic if Sel is likely to be
120 -- a misspelling of one of the selectors of the Prefix.
121 -- This is called by Analyze_Selected_Component after producing
122 -- an invalid selector error message.
124 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean;
125 -- Verify that type T is declared in scope S. Used to find intepretations
126 -- for operators given by expanded names. This is abstracted as a separate
127 -- function to handle extensions to System, where S is System, but T is
128 -- declared in the extension.
130 procedure Find_Arithmetic_Types
134 -- L and R are the operands of an arithmetic operator. Find
135 -- consistent pairs of interpretations for L and R that have a
136 -- numeric type consistent with the semantics of the operator.
138 procedure Find_Comparison_Types
142 -- L and R are operands of a comparison operator. Find consistent
143 -- pairs of interpretations for L and R.
145 procedure Find_Concatenation_Types
149 -- For the four varieties of concatenation.
151 procedure Find_Equality_Types
155 -- Ditto for equality operators.
157 procedure Find_Boolean_Types
161 -- Ditto for binary logical operations.
163 procedure Find_Negation_Types
167 -- Find consistent interpretation for operand of negation operator.
169 procedure Find_Non_Universal_Interpretations
174 -- For equality and comparison operators, the result is always boolean,
175 -- and the legality of the operation is determined from the visibility
176 -- of the operand types. If one of the operands has a universal interpre-
177 -- tation, the legality check uses some compatible non-universal
178 -- interpretation of the other operand. N can be an operator node, or
179 -- a function call whose name is an operator designator.
181 procedure Find_Unary_Types
185 -- Unary arithmetic types: plus, minus, abs.
187 procedure Check_Arithmetic_Pair
191 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
192 -- types for left and right operand. Determine whether they constitute
193 -- a valid pair for the given operator, and record the corresponding
194 -- interpretation of the operator node. The node N may be an operator
195 -- node (the usual case) or a function call whose prefix is an operator
196 -- designator. In both cases Op_Id is the operator name itself.
198 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
);
199 -- Give detailed information on overloaded call where none of the
200 -- interpretations match. N is the call node, Nam the designator for
201 -- the overloaded entity being called.
203 function Junk_Operand
(N
: Node_Id
) return Boolean;
204 -- Test for an operand that is an inappropriate entity (e.g. a package
205 -- name or a label). If so, issue an error message and return True. If
206 -- the operand is not an inappropriate entity kind, return False.
208 procedure Operator_Check
(N
: Node_Id
);
209 -- Verify that an operator has received some valid interpretation.
210 -- If none was found, determine whether a use clause would make the
211 -- operation legal. The variable Candidate_Type (defined in Sem_Type) is
212 -- set for every type compatible with the operator, even if the operator
213 -- for the type is not directly visible. The routine uses this type to emit
214 -- a more informative message.
216 function Try_Indexed_Call
221 -- If a function has defaults for all its actuals, a call to it may
222 -- in fact be an indexing on the result of the call. Try_Indexed_Call
223 -- attempts the interpretation as an indexing, prior to analysis as
224 -- a call. If both are possible, the node is overloaded with both
225 -- interpretations (same symbol but two different types).
227 function Try_Indirect_Call
232 -- Similarly, a function F that needs no actuals can return an access
233 -- to a subprogram, and the call F (X) interpreted as F.all (X). In
234 -- this case the call may be overloaded with both interpretations.
236 ------------------------
237 -- Ambiguous_Operands --
238 ------------------------
240 procedure Ambiguous_Operands
(N
: Node_Id
) is
241 procedure List_Interps
(Opnd
: Node_Id
);
243 procedure List_Interps
(Opnd
: Node_Id
) is
244 Index
: Interp_Index
;
250 if Is_Overloaded
(Opnd
) then
251 if Nkind
(Opnd
) in N_Op
then
254 elsif Nkind
(Opnd
) = N_Function_Call
then
265 if Opnd
= Left_Opnd
(N
) then
267 ("\left operand has the following interpretations", N
);
270 ("\right operand has the following interpretations", N
);
274 Get_First_Interp
(Nam
, Index
, It
);
276 while Present
(It
.Nam
) loop
278 if Scope
(It
.Nam
) = Standard_Standard
279 and then Scope
(It
.Typ
) /= Standard_Standard
281 Error_Msg_Sloc
:= Sloc
(Parent
(It
.Typ
));
282 Error_Msg_NE
(" & (inherited) declared#!", Err
, It
.Nam
);
285 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
286 Error_Msg_NE
(" & declared#!", Err
, It
.Nam
);
289 Get_Next_Interp
(Index
, It
);
295 or else Nkind
(N
) = N_Not_In
297 Error_Msg_N
("ambiguous operands for membership", N
);
299 elsif Nkind
(N
) = N_Op_Eq
300 or else Nkind
(N
) = N_Op_Ne
302 Error_Msg_N
("ambiguous operands for equality", N
);
305 Error_Msg_N
("ambiguous operands for comparison", N
);
308 if All_Errors_Mode
then
309 List_Interps
(Left_Opnd
(N
));
310 List_Interps
(Right_Opnd
(N
));
315 "\use '/'R'E'P'O'R'T'_'E'R'R'O'R'S'='F'U'L'L for details",
318 Error_Msg_N
("\use -gnatf for details", N
);
321 end Ambiguous_Operands
;
323 -----------------------
324 -- Analyze_Aggregate --
325 -----------------------
327 -- Most of the analysis of Aggregates requires that the type be known,
328 -- and is therefore put off until resolution.
330 procedure Analyze_Aggregate
(N
: Node_Id
) is
332 if No
(Etype
(N
)) then
333 Set_Etype
(N
, Any_Composite
);
335 end Analyze_Aggregate
;
337 -----------------------
338 -- Analyze_Allocator --
339 -----------------------
341 procedure Analyze_Allocator
(N
: Node_Id
) is
342 Loc
: constant Source_Ptr
:= Sloc
(N
);
343 Sav_Errs
: constant Nat
:= Serious_Errors_Detected
;
344 E
: Node_Id
:= Expression
(N
);
345 Acc_Type
: Entity_Id
;
349 Check_Restriction
(No_Allocators
, N
);
351 if Nkind
(E
) = N_Qualified_Expression
then
352 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
353 Set_Etype
(Acc_Type
, Acc_Type
);
354 Init_Size_Align
(Acc_Type
);
355 Find_Type
(Subtype_Mark
(E
));
356 Type_Id
:= Entity
(Subtype_Mark
(E
));
357 Check_Fully_Declared
(Type_Id
, N
);
358 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
360 if Is_Protected_Type
(Type_Id
) then
361 Check_Restriction
(No_Protected_Type_Allocators
, N
);
364 if Is_Limited_Type
(Type_Id
)
365 and then Comes_From_Source
(N
)
366 and then not In_Instance_Body
368 Error_Msg_N
("initialization not allowed for limited types", N
);
371 Analyze_And_Resolve
(Expression
(E
), Type_Id
);
373 -- A qualified expression requires an exact match of the type,
374 -- class-wide matching is not allowed.
376 if Is_Class_Wide_Type
(Type_Id
)
377 and then Base_Type
(Etype
(Expression
(E
))) /= Base_Type
(Type_Id
)
379 Wrong_Type
(Expression
(E
), Type_Id
);
382 Check_Non_Static_Context
(Expression
(E
));
384 -- We don't analyze the qualified expression itself because it's
385 -- part of the allocator
387 Set_Etype
(E
, Type_Id
);
394 -- If the allocator includes a N_Subtype_Indication then a
395 -- constraint is present, otherwise the node is a subtype mark.
396 -- Introduce an explicit subtype declaration into the tree
397 -- defining some anonymous subtype and rewrite the allocator to
398 -- use this subtype rather than the subtype indication.
400 -- It is important to introduce the explicit subtype declaration
401 -- so that the bounds of the subtype indication are attached to
402 -- the tree in case the allocator is inside a generic unit.
404 if Nkind
(E
) = N_Subtype_Indication
then
406 -- A constraint is only allowed for a composite type in Ada
407 -- 95. In Ada 83, a constraint is also allowed for an
408 -- access-to-composite type, but the constraint is ignored.
410 Find_Type
(Subtype_Mark
(E
));
412 if Is_Elementary_Type
(Entity
(Subtype_Mark
(E
))) then
414 and then Is_Access_Type
(Entity
(Subtype_Mark
(E
))))
416 Error_Msg_N
("constraint not allowed here", E
);
418 if Nkind
(Constraint
(E
))
419 = N_Index_Or_Discriminant_Constraint
422 ("\if qualified expression was meant, " &
423 "use apostrophe", Constraint
(E
));
427 -- Get rid of the bogus constraint:
429 Rewrite
(E
, New_Copy_Tree
(Subtype_Mark
(E
)));
430 Analyze_Allocator
(N
);
434 if Expander_Active
then
436 Make_Defining_Identifier
(Loc
, New_Internal_Name
('S'));
439 Make_Subtype_Declaration
(Loc
,
440 Defining_Identifier
=> Def_Id
,
441 Subtype_Indication
=> Relocate_Node
(E
)));
443 if Sav_Errs
/= Serious_Errors_Detected
444 and then Nkind
(Constraint
(E
))
445 = N_Index_Or_Discriminant_Constraint
448 ("if qualified expression was meant, " &
449 "use apostrophe!", Constraint
(E
));
452 E
:= New_Occurrence_Of
(Def_Id
, Loc
);
453 Rewrite
(Expression
(N
), E
);
457 Type_Id
:= Process_Subtype
(E
, N
);
458 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
459 Set_Etype
(Acc_Type
, Acc_Type
);
460 Init_Size_Align
(Acc_Type
);
461 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
462 Check_Fully_Declared
(Type_Id
, N
);
464 -- Check for missing initialization. Skip this check if we already
465 -- had errors on analyzing the allocator, since in that case these
466 -- are probably cascaded errors
468 if Is_Indefinite_Subtype
(Type_Id
)
469 and then Serious_Errors_Detected
= Sav_Errs
471 if Is_Class_Wide_Type
(Type_Id
) then
473 ("initialization required in class-wide allocation", N
);
476 ("initialization required in unconstrained allocation", N
);
482 if Is_Abstract
(Type_Id
) then
483 Error_Msg_N
("cannot allocate abstract object", E
);
486 if Has_Task
(Designated_Type
(Acc_Type
)) then
487 Check_Restriction
(No_Task_Allocators
, N
);
490 Set_Etype
(N
, Acc_Type
);
492 if not Is_Library_Level_Entity
(Acc_Type
) then
493 Check_Restriction
(No_Local_Allocators
, N
);
496 if Serious_Errors_Detected
> Sav_Errs
then
497 Set_Error_Posted
(N
);
498 Set_Etype
(N
, Any_Type
);
501 end Analyze_Allocator
;
503 ---------------------------
504 -- Analyze_Arithmetic_Op --
505 ---------------------------
507 procedure Analyze_Arithmetic_Op
(N
: Node_Id
) is
508 L
: constant Node_Id
:= Left_Opnd
(N
);
509 R
: constant Node_Id
:= Right_Opnd
(N
);
513 Candidate_Type
:= Empty
;
514 Analyze_Expression
(L
);
515 Analyze_Expression
(R
);
517 -- If the entity is already set, the node is the instantiation of
518 -- a generic node with a non-local reference, or was manufactured
519 -- by a call to Make_Op_xxx. In either case the entity is known to
520 -- be valid, and we do not need to collect interpretations, instead
521 -- we just get the single possible interpretation.
525 if Present
(Op_Id
) then
526 if Ekind
(Op_Id
) = E_Operator
then
528 if (Nkind
(N
) = N_Op_Divide
or else
529 Nkind
(N
) = N_Op_Mod
or else
530 Nkind
(N
) = N_Op_Multiply
or else
531 Nkind
(N
) = N_Op_Rem
)
532 and then Treat_Fixed_As_Integer
(N
)
536 Set_Etype
(N
, Any_Type
);
537 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
541 Set_Etype
(N
, Any_Type
);
542 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
545 -- Entity is not already set, so we do need to collect interpretations
548 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
549 Set_Etype
(N
, Any_Type
);
551 while Present
(Op_Id
) loop
552 if Ekind
(Op_Id
) = E_Operator
553 and then Present
(Next_Entity
(First_Entity
(Op_Id
)))
555 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
557 -- The following may seem superfluous, because an operator cannot
558 -- be generic, but this ignores the cleverness of the author of
561 elsif Is_Overloadable
(Op_Id
) then
562 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
565 Op_Id
:= Homonym
(Op_Id
);
570 end Analyze_Arithmetic_Op
;
576 -- Function, procedure, and entry calls are checked here. The Name
577 -- in the call may be overloaded. The actuals have been analyzed
578 -- and may themselves be overloaded. On exit from this procedure, the node
579 -- N may have zero, one or more interpretations. In the first case an error
580 -- message is produced. In the last case, the node is flagged as overloaded
581 -- and the interpretations are collected in All_Interp.
583 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
584 -- the type-checking is similar to that of other calls.
586 procedure Analyze_Call
(N
: Node_Id
) is
587 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
588 Nam
: Node_Id
:= Name
(N
);
592 Success
: Boolean := False;
594 function Name_Denotes_Function
return Boolean;
595 -- If the type of the name is an access to subprogram, this may be
596 -- the type of a name, or the return type of the function being called.
597 -- If the name is not an entity then it can denote a protected function.
598 -- Until we distinguish Etype from Return_Type, we must use this
599 -- routine to resolve the meaning of the name in the call.
601 ---------------------------
602 -- Name_Denotes_Function --
603 ---------------------------
605 function Name_Denotes_Function
return Boolean is
607 if Is_Entity_Name
(Nam
) then
608 return Ekind
(Entity
(Nam
)) = E_Function
;
610 elsif Nkind
(Nam
) = N_Selected_Component
then
611 return Ekind
(Entity
(Selector_Name
(Nam
))) = E_Function
;
616 end Name_Denotes_Function
;
618 -- Start of processing for Analyze_Call
621 -- Initialize the type of the result of the call to the error type,
622 -- which will be reset if the type is successfully resolved.
624 Set_Etype
(N
, Any_Type
);
626 if not Is_Overloaded
(Nam
) then
628 -- Only one interpretation to check
630 if Ekind
(Etype
(Nam
)) = E_Subprogram_Type
then
631 Nam_Ent
:= Etype
(Nam
);
633 elsif Is_Access_Type
(Etype
(Nam
))
634 and then Ekind
(Designated_Type
(Etype
(Nam
))) = E_Subprogram_Type
635 and then not Name_Denotes_Function
637 Nam_Ent
:= Designated_Type
(Etype
(Nam
));
638 Insert_Explicit_Dereference
(Nam
);
640 -- Selected component case. Simple entry or protected operation,
641 -- where the entry name is given by the selector name.
643 elsif Nkind
(Nam
) = N_Selected_Component
then
644 Nam_Ent
:= Entity
(Selector_Name
(Nam
));
646 if Ekind
(Nam_Ent
) /= E_Entry
647 and then Ekind
(Nam_Ent
) /= E_Entry_Family
648 and then Ekind
(Nam_Ent
) /= E_Function
649 and then Ekind
(Nam_Ent
) /= E_Procedure
651 Error_Msg_N
("name in call is not a callable entity", Nam
);
652 Set_Etype
(N
, Any_Type
);
656 -- If the name is an Indexed component, it can be a call to a member
657 -- of an entry family. The prefix must be a selected component whose
658 -- selector is the entry. Analyze_Procedure_Call normalizes several
659 -- kinds of call into this form.
661 elsif Nkind
(Nam
) = N_Indexed_Component
then
663 if Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
664 Nam_Ent
:= Entity
(Selector_Name
(Prefix
(Nam
)));
667 Error_Msg_N
("name in call is not a callable entity", Nam
);
668 Set_Etype
(N
, Any_Type
);
673 elsif not Is_Entity_Name
(Nam
) then
674 Error_Msg_N
("name in call is not a callable entity", Nam
);
675 Set_Etype
(N
, Any_Type
);
679 Nam_Ent
:= Entity
(Nam
);
681 -- If no interpretations, give error message
683 if not Is_Overloadable
(Nam_Ent
) then
685 L
: constant Boolean := Is_List_Member
(N
);
686 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
689 -- If the node is in a list whose parent is not an
690 -- expression then it must be an attempted procedure call.
692 if L
and then K
not in N_Subexpr
then
693 if Ekind
(Entity
(Nam
)) = E_Generic_Procedure
then
695 ("must instantiate generic procedure& before call",
699 ("procedure or entry name expected", Nam
);
702 -- Check for tasking cases where only an entry call will do
705 and then (K
= N_Entry_Call_Alternative
706 or else K
= N_Triggering_Alternative
)
708 Error_Msg_N
("entry name expected", Nam
);
710 -- Otherwise give general error message
713 Error_Msg_N
("invalid prefix in call", Nam
);
721 Analyze_One_Call
(N
, Nam_Ent
, True, Success
);
724 -- An overloaded selected component must denote overloaded
725 -- operations of a concurrent type. The interpretations are
726 -- attached to the simple name of those operations.
728 if Nkind
(Nam
) = N_Selected_Component
then
729 Nam
:= Selector_Name
(Nam
);
732 Get_First_Interp
(Nam
, X
, It
);
734 while Present
(It
.Nam
) loop
737 -- Name may be call that returns an access to subprogram, or more
738 -- generally an overloaded expression one of whose interpretations
739 -- yields an access to subprogram. If the name is an entity, we
740 -- do not dereference, because the node is a call that returns
741 -- the access type: note difference between f(x), where the call
742 -- may return an access subprogram type, and f(x)(y), where the
743 -- type returned by the call to f is implicitly dereferenced to
744 -- analyze the outer call.
746 if Is_Access_Type
(Nam_Ent
) then
747 Nam_Ent
:= Designated_Type
(Nam_Ent
);
749 elsif Is_Access_Type
(Etype
(Nam_Ent
))
750 and then not Is_Entity_Name
(Nam
)
751 and then Ekind
(Designated_Type
(Etype
(Nam_Ent
)))
754 Nam_Ent
:= Designated_Type
(Etype
(Nam_Ent
));
757 Analyze_One_Call
(N
, Nam_Ent
, False, Success
);
759 -- If the interpretation succeeds, mark the proper type of the
760 -- prefix (any valid candidate will do). If not, remove the
761 -- candidate interpretation. This only needs to be done for
762 -- overloaded protected operations, for other entities disambi-
763 -- guation is done directly in Resolve.
766 Set_Etype
(Nam
, It
.Typ
);
768 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
772 Get_Next_Interp
(X
, It
);
775 -- If the name is the result of a function call, it can only
776 -- be a call to a function returning an access to subprogram.
777 -- Insert explicit dereference.
779 if Nkind
(Nam
) = N_Function_Call
then
780 Insert_Explicit_Dereference
(Nam
);
783 if Etype
(N
) = Any_Type
then
785 -- None of the interpretations is compatible with the actuals
787 Diagnose_Call
(N
, Nam
);
789 -- Special checks for uninstantiated put routines
791 if Nkind
(N
) = N_Procedure_Call_Statement
792 and then Is_Entity_Name
(Nam
)
793 and then Chars
(Nam
) = Name_Put
794 and then List_Length
(Actuals
) = 1
797 Arg
: constant Node_Id
:= First
(Actuals
);
801 if Nkind
(Arg
) = N_Parameter_Association
then
802 Typ
:= Etype
(Explicit_Actual_Parameter
(Arg
));
807 if Is_Signed_Integer_Type
(Typ
) then
809 ("possible missing instantiation of " &
810 "'Text_'I'O.'Integer_'I'O!", Nam
);
812 elsif Is_Modular_Integer_Type
(Typ
) then
814 ("possible missing instantiation of " &
815 "'Text_'I'O.'Modular_'I'O!", Nam
);
817 elsif Is_Floating_Point_Type
(Typ
) then
819 ("possible missing instantiation of " &
820 "'Text_'I'O.'Float_'I'O!", Nam
);
822 elsif Is_Ordinary_Fixed_Point_Type
(Typ
) then
824 ("possible missing instantiation of " &
825 "'Text_'I'O.'Fixed_'I'O!", Nam
);
827 elsif Is_Decimal_Fixed_Point_Type
(Typ
) then
829 ("possible missing instantiation of " &
830 "'Text_'I'O.'Decimal_'I'O!", Nam
);
832 elsif Is_Enumeration_Type
(Typ
) then
834 ("possible missing instantiation of " &
835 "'Text_'I'O.'Enumeration_'I'O!", Nam
);
840 elsif not Is_Overloaded
(N
)
841 and then Is_Entity_Name
(Nam
)
843 -- Resolution yields a single interpretation. Verify that
844 -- is has the proper capitalization.
846 Set_Entity_With_Style_Check
(Nam
, Entity
(Nam
));
847 Generate_Reference
(Entity
(Nam
), Nam
);
849 Set_Etype
(Nam
, Etype
(Entity
(Nam
)));
856 ---------------------------
857 -- Analyze_Comparison_Op --
858 ---------------------------
860 procedure Analyze_Comparison_Op
(N
: Node_Id
) is
861 L
: constant Node_Id
:= Left_Opnd
(N
);
862 R
: constant Node_Id
:= Right_Opnd
(N
);
863 Op_Id
: Entity_Id
:= Entity
(N
);
866 Set_Etype
(N
, Any_Type
);
867 Candidate_Type
:= Empty
;
869 Analyze_Expression
(L
);
870 Analyze_Expression
(R
);
872 if Present
(Op_Id
) then
874 if Ekind
(Op_Id
) = E_Operator
then
875 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
877 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
880 if Is_Overloaded
(L
) then
881 Set_Etype
(L
, Intersect_Types
(L
, R
));
885 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
887 while Present
(Op_Id
) loop
889 if Ekind
(Op_Id
) = E_Operator
then
890 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
892 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
895 Op_Id
:= Homonym
(Op_Id
);
900 end Analyze_Comparison_Op
;
902 ---------------------------
903 -- Analyze_Concatenation --
904 ---------------------------
906 -- If the only one-dimensional array type in scope is String,
907 -- this is the resulting type of the operation. Otherwise there
908 -- will be a concatenation operation defined for each user-defined
909 -- one-dimensional array.
911 procedure Analyze_Concatenation
(N
: Node_Id
) is
912 L
: constant Node_Id
:= Left_Opnd
(N
);
913 R
: constant Node_Id
:= Right_Opnd
(N
);
914 Op_Id
: Entity_Id
:= Entity
(N
);
919 Set_Etype
(N
, Any_Type
);
920 Candidate_Type
:= Empty
;
922 Analyze_Expression
(L
);
923 Analyze_Expression
(R
);
925 -- If the entity is present, the node appears in an instance,
926 -- and denotes a predefined concatenation operation. The resulting
927 -- type is obtained from the arguments when possible.
929 if Present
(Op_Id
) then
930 if Ekind
(Op_Id
) = E_Operator
then
932 LT
:= Base_Type
(Etype
(L
));
933 RT
:= Base_Type
(Etype
(R
));
935 if Is_Array_Type
(LT
)
936 and then (RT
= LT
or else RT
= Base_Type
(Component_Type
(LT
)))
938 Add_One_Interp
(N
, Op_Id
, LT
);
940 elsif Is_Array_Type
(RT
)
941 and then LT
= Base_Type
(Component_Type
(RT
))
943 Add_One_Interp
(N
, Op_Id
, RT
);
946 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
950 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
954 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Concat
);
956 while Present
(Op_Id
) loop
957 if Ekind
(Op_Id
) = E_Operator
then
958 Find_Concatenation_Types
(L
, R
, Op_Id
, N
);
960 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
963 Op_Id
:= Homonym
(Op_Id
);
968 end Analyze_Concatenation
;
970 ------------------------------------
971 -- Analyze_Conditional_Expression --
972 ------------------------------------
974 procedure Analyze_Conditional_Expression
(N
: Node_Id
) is
975 Condition
: constant Node_Id
:= First
(Expressions
(N
));
976 Then_Expr
: constant Node_Id
:= Next
(Condition
);
977 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
980 Analyze_Expression
(Condition
);
981 Analyze_Expression
(Then_Expr
);
982 Analyze_Expression
(Else_Expr
);
983 Set_Etype
(N
, Etype
(Then_Expr
));
984 end Analyze_Conditional_Expression
;
986 -------------------------
987 -- Analyze_Equality_Op --
988 -------------------------
990 procedure Analyze_Equality_Op
(N
: Node_Id
) is
991 Loc
: constant Source_Ptr
:= Sloc
(N
);
992 L
: constant Node_Id
:= Left_Opnd
(N
);
993 R
: constant Node_Id
:= Right_Opnd
(N
);
997 Set_Etype
(N
, Any_Type
);
998 Candidate_Type
:= Empty
;
1000 Analyze_Expression
(L
);
1001 Analyze_Expression
(R
);
1003 -- If the entity is set, the node is a generic instance with a non-local
1004 -- reference to the predefined operator or to a user-defined function.
1005 -- It can also be an inequality that is expanded into the negation of a
1006 -- call to a user-defined equality operator.
1008 -- For the predefined case, the result is Boolean, regardless of the
1009 -- type of the operands. The operands may even be limited, if they are
1010 -- generic actuals. If they are overloaded, label the left argument with
1011 -- the common type that must be present, or with the type of the formal
1012 -- of the user-defined function.
1014 if Present
(Entity
(N
)) then
1016 Op_Id
:= Entity
(N
);
1018 if Ekind
(Op_Id
) = E_Operator
then
1019 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
);
1021 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1024 if Is_Overloaded
(L
) then
1026 if Ekind
(Op_Id
) = E_Operator
then
1027 Set_Etype
(L
, Intersect_Types
(L
, R
));
1029 Set_Etype
(L
, Etype
(First_Formal
(Op_Id
)));
1034 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1036 while Present
(Op_Id
) loop
1038 if Ekind
(Op_Id
) = E_Operator
then
1039 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1041 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1044 Op_Id
:= Homonym
(Op_Id
);
1048 -- If there was no match, and the operator is inequality, this may
1049 -- be a case where inequality has not been made explicit, as for
1050 -- tagged types. Analyze the node as the negation of an equality
1051 -- operation. This cannot be done earlier, because before analysis
1052 -- we cannot rule out the presence of an explicit inequality.
1054 if Etype
(N
) = Any_Type
1055 and then Nkind
(N
) = N_Op_Ne
1057 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Eq
);
1059 while Present
(Op_Id
) loop
1061 if Ekind
(Op_Id
) = E_Operator
then
1062 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1064 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1067 Op_Id
:= Homonym
(Op_Id
);
1070 if Etype
(N
) /= Any_Type
then
1071 Op_Id
:= Entity
(N
);
1077 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
1078 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
)))));
1080 Set_Entity
(Right_Opnd
(N
), Op_Id
);
1086 end Analyze_Equality_Op
;
1088 ----------------------------------
1089 -- Analyze_Explicit_Dereference --
1090 ----------------------------------
1092 procedure Analyze_Explicit_Dereference
(N
: Node_Id
) is
1093 Loc
: constant Source_Ptr
:= Sloc
(N
);
1094 P
: constant Node_Id
:= Prefix
(N
);
1100 function Is_Function_Type
return Boolean;
1101 -- Check whether node may be interpreted as an implicit function call.
1103 function Is_Function_Type
return Boolean is
1108 if not Is_Overloaded
(N
) then
1109 return Ekind
(Base_Type
(Etype
(N
))) = E_Subprogram_Type
1110 and then Etype
(Base_Type
(Etype
(N
))) /= Standard_Void_Type
;
1113 Get_First_Interp
(N
, I
, It
);
1115 while Present
(It
.Nam
) loop
1116 if Ekind
(Base_Type
(It
.Typ
)) /= E_Subprogram_Type
1117 or else Etype
(Base_Type
(It
.Typ
)) = Standard_Void_Type
1122 Get_Next_Interp
(I
, It
);
1127 end Is_Function_Type
;
1131 Set_Etype
(N
, Any_Type
);
1133 -- Test for remote access to subprogram type, and if so return
1134 -- after rewriting the original tree.
1136 if Remote_AST_E_Dereference
(P
) then
1140 -- Normal processing for other than remote access to subprogram type
1142 if not Is_Overloaded
(P
) then
1143 if Is_Access_Type
(Etype
(P
)) then
1145 -- Set the Etype. We need to go thru Is_For_Access_Subtypes
1146 -- to avoid other problems caused by the Private_Subtype
1147 -- and it is safe to go to the Base_Type because this is the
1148 -- same as converting the access value to its Base_Type.
1151 DT
: Entity_Id
:= Designated_Type
(Etype
(P
));
1154 if Ekind
(DT
) = E_Private_Subtype
1155 and then Is_For_Access_Subtype
(DT
)
1157 DT
:= Base_Type
(DT
);
1163 elsif Etype
(P
) /= Any_Type
then
1164 Error_Msg_N
("prefix of dereference must be an access type", N
);
1169 Get_First_Interp
(P
, I
, It
);
1171 while Present
(It
.Nam
) loop
1174 if Is_Access_Type
(T
) then
1175 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
1178 Get_Next_Interp
(I
, It
);
1183 -- Error if no interpretation of the prefix has an access type.
1185 if Etype
(N
) = Any_Type
then
1187 ("access type required in prefix of explicit dereference", P
);
1188 Set_Etype
(N
, Any_Type
);
1194 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
1196 and then (Nkind
(Parent
(N
)) /= N_Function_Call
1197 or else N
/= Name
(Parent
(N
)))
1199 and then (Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1200 or else N
/= Name
(Parent
(N
)))
1202 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
1203 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
1205 (Attribute_Name
(Parent
(N
)) /= Name_Address
1207 Attribute_Name
(Parent
(N
)) /= Name_Access
))
1209 -- Name is a function call with no actuals, in a context that
1210 -- requires deproceduring (including as an actual in an enclosing
1211 -- function or procedure call). We can conceive of pathological cases
1212 -- where the prefix might include functions that return access to
1213 -- subprograms and others that return a regular type. Disambiguation
1214 -- of those will have to take place in Resolve. See e.g. 7117-014.
1217 Make_Function_Call
(Loc
,
1218 Name
=> Make_Explicit_Dereference
(Loc
, P
),
1219 Parameter_Associations
=> New_List
);
1221 -- If the prefix is overloaded, remove operations that have formals,
1222 -- we know that this is a parameterless call.
1224 if Is_Overloaded
(P
) then
1225 Get_First_Interp
(P
, I
, It
);
1227 while Present
(It
.Nam
) loop
1230 if No
(First_Formal
(Base_Type
(Designated_Type
(T
)))) then
1236 Get_Next_Interp
(I
, It
);
1244 -- A value of remote access-to-class-wide must not be dereferenced
1247 Validate_Remote_Access_To_Class_Wide_Type
(N
);
1249 end Analyze_Explicit_Dereference
;
1251 ------------------------
1252 -- Analyze_Expression --
1253 ------------------------
1255 procedure Analyze_Expression
(N
: Node_Id
) is
1258 Check_Parameterless_Call
(N
);
1259 end Analyze_Expression
;
1261 ------------------------------------
1262 -- Analyze_Indexed_Component_Form --
1263 ------------------------------------
1265 procedure Analyze_Indexed_Component_Form
(N
: Node_Id
) is
1266 P
: constant Node_Id
:= Prefix
(N
);
1267 Exprs
: List_Id
:= Expressions
(N
);
1273 procedure Process_Function_Call
;
1274 -- Prefix in indexed component form is an overloadable entity,
1275 -- so the node is a function call. Reformat it as such.
1277 procedure Process_Indexed_Component
;
1278 -- Prefix in indexed component form is actually an indexed component.
1279 -- This routine processes it, knowing that the prefix is already
1282 procedure Process_Indexed_Component_Or_Slice
;
1283 -- An indexed component with a single index may designate a slice if
1284 -- the index is a subtype mark. This routine disambiguates these two
1285 -- cases by resolving the prefix to see if it is a subtype mark.
1287 procedure Process_Overloaded_Indexed_Component
;
1288 -- If the prefix of an indexed component is overloaded, the proper
1289 -- interpretation is selected by the index types and the context.
1291 ---------------------------
1292 -- Process_Function_Call --
1293 ---------------------------
1295 procedure Process_Function_Call
is
1299 Change_Node
(N
, N_Function_Call
);
1301 Set_Parameter_Associations
(N
, Exprs
);
1302 Actual
:= First
(Parameter_Associations
(N
));
1304 while Present
(Actual
) loop
1306 Check_Parameterless_Call
(Actual
);
1307 Next_Actual
(Actual
);
1311 end Process_Function_Call
;
1313 -------------------------------
1314 -- Process_Indexed_Component --
1315 -------------------------------
1317 procedure Process_Indexed_Component
is
1319 Array_Type
: Entity_Id
;
1321 Entry_Family
: Entity_Id
;
1324 Exp
:= First
(Exprs
);
1326 if Is_Overloaded
(P
) then
1327 Process_Overloaded_Indexed_Component
;
1330 Array_Type
:= Etype
(P
);
1332 -- Prefix must be appropriate for an array type.
1333 -- Dereference the prefix if it is an access type.
1335 if Is_Access_Type
(Array_Type
) then
1336 Array_Type
:= Designated_Type
(Array_Type
);
1338 if Warn_On_Dereference
then
1339 Error_Msg_N
("?implicit dereference", N
);
1343 if Is_Array_Type
(Array_Type
) then
1346 elsif (Is_Entity_Name
(P
)
1348 Ekind
(Entity
(P
)) = E_Entry_Family
)
1350 (Nkind
(P
) = N_Selected_Component
1352 Is_Entity_Name
(Selector_Name
(P
))
1354 Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
)
1356 if Is_Entity_Name
(P
) then
1357 Entry_Family
:= Entity
(P
);
1359 Entry_Family
:= Entity
(Selector_Name
(P
));
1363 Set_Etype
(N
, Any_Type
);
1365 if not Has_Compatible_Type
1366 (Exp
, Entry_Index_Type
(Entry_Family
))
1368 Error_Msg_N
("invalid index type in entry name", N
);
1370 elsif Present
(Next
(Exp
)) then
1371 Error_Msg_N
("too many subscripts in entry reference", N
);
1374 Set_Etype
(N
, Etype
(P
));
1379 elsif Is_Record_Type
(Array_Type
)
1380 and then Remote_AST_I_Dereference
(P
)
1384 elsif Array_Type
= Any_Type
then
1385 Set_Etype
(N
, Any_Type
);
1388 -- Here we definitely have a bad indexing
1391 if Nkind
(Parent
(N
)) = N_Requeue_Statement
1393 ((Is_Entity_Name
(P
)
1394 and then Ekind
(Entity
(P
)) = E_Entry
)
1396 (Nkind
(P
) = N_Selected_Component
1397 and then Is_Entity_Name
(Selector_Name
(P
))
1398 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
))
1401 ("REQUEUE does not permit parameters", First
(Exprs
));
1403 elsif Is_Entity_Name
(P
)
1404 and then Etype
(P
) = Standard_Void_Type
1406 Error_Msg_NE
("incorrect use of&", P
, Entity
(P
));
1409 Error_Msg_N
("array type required in indexed component", P
);
1412 Set_Etype
(N
, Any_Type
);
1416 Index
:= First_Index
(Array_Type
);
1418 while Present
(Index
) and then Present
(Exp
) loop
1419 if not Has_Compatible_Type
(Exp
, Etype
(Index
)) then
1420 Wrong_Type
(Exp
, Etype
(Index
));
1421 Set_Etype
(N
, Any_Type
);
1429 Set_Etype
(N
, Component_Type
(Array_Type
));
1431 if Present
(Index
) then
1433 ("too few subscripts in array reference", First
(Exprs
));
1435 elsif Present
(Exp
) then
1436 Error_Msg_N
("too many subscripts in array reference", Exp
);
1440 end Process_Indexed_Component
;
1442 ----------------------------------------
1443 -- Process_Indexed_Component_Or_Slice --
1444 ----------------------------------------
1446 procedure Process_Indexed_Component_Or_Slice
is
1448 Exp
:= First
(Exprs
);
1450 while Present
(Exp
) loop
1451 Analyze_Expression
(Exp
);
1455 Exp
:= First
(Exprs
);
1457 -- If one index is present, and it is a subtype name, then the
1458 -- node denotes a slice (note that the case of an explicit range
1459 -- for a slice was already built as an N_Slice node in the first
1460 -- place, so that case is not handled here).
1462 -- We use a replace rather than a rewrite here because this is one
1463 -- of the cases in which the tree built by the parser is plain wrong.
1466 and then Is_Entity_Name
(Exp
)
1467 and then Is_Type
(Entity
(Exp
))
1470 Make_Slice
(Sloc
(N
),
1472 Discrete_Range
=> New_Copy
(Exp
)));
1475 -- Otherwise (more than one index present, or single index is not
1476 -- a subtype name), then we have the indexed component case.
1479 Process_Indexed_Component
;
1481 end Process_Indexed_Component_Or_Slice
;
1483 ------------------------------------------
1484 -- Process_Overloaded_Indexed_Component --
1485 ------------------------------------------
1487 procedure Process_Overloaded_Indexed_Component
is
1496 Set_Etype
(N
, Any_Type
);
1497 Get_First_Interp
(P
, I
, It
);
1499 while Present
(It
.Nam
) loop
1502 if Is_Access_Type
(Typ
) then
1503 Typ
:= Designated_Type
(Typ
);
1505 if Warn_On_Dereference
then
1506 Error_Msg_N
("?implicit dereference", N
);
1510 if Is_Array_Type
(Typ
) then
1512 -- Got a candidate: verify that index types are compatible
1514 Index
:= First_Index
(Typ
);
1517 Exp
:= First
(Exprs
);
1519 while Present
(Index
) and then Present
(Exp
) loop
1520 if Has_Compatible_Type
(Exp
, Etype
(Index
)) then
1532 if Found
and then No
(Index
) and then No
(Exp
) then
1534 Etype
(Component_Type
(Typ
)),
1535 Etype
(Component_Type
(Typ
)));
1539 Get_Next_Interp
(I
, It
);
1542 if Etype
(N
) = Any_Type
then
1543 Error_Msg_N
("no legal interpetation for indexed component", N
);
1544 Set_Is_Overloaded
(N
, False);
1548 end Process_Overloaded_Indexed_Component
;
1550 ------------------------------------
1551 -- Analyze_Indexed_Component_Form --
1552 ------------------------------------
1555 -- Get name of array, function or type
1558 P_T
:= Base_Type
(Etype
(P
));
1560 if Is_Entity_Name
(P
)
1561 or else Nkind
(P
) = N_Operator_Symbol
1565 if Ekind
(U_N
) in Type_Kind
then
1567 -- Reformat node as a type conversion.
1569 E
:= Remove_Head
(Exprs
);
1571 if Present
(First
(Exprs
)) then
1573 ("argument of type conversion must be single expression", N
);
1576 Change_Node
(N
, N_Type_Conversion
);
1577 Set_Subtype_Mark
(N
, P
);
1579 Set_Expression
(N
, E
);
1581 -- After changing the node, call for the specific Analysis
1582 -- routine directly, to avoid a double call to the expander.
1584 Analyze_Type_Conversion
(N
);
1588 if Is_Overloadable
(U_N
) then
1589 Process_Function_Call
;
1591 elsif Ekind
(Etype
(P
)) = E_Subprogram_Type
1592 or else (Is_Access_Type
(Etype
(P
))
1594 Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
)
1596 -- Call to access_to-subprogram with possible implicit dereference
1598 Process_Function_Call
;
1600 elsif Ekind
(U_N
) = E_Generic_Function
1601 or else Ekind
(U_N
) = E_Generic_Procedure
1603 -- A common beginner's (or C++ templates fan) error.
1605 Error_Msg_N
("generic subprogram cannot be called", N
);
1606 Set_Etype
(N
, Any_Type
);
1610 Process_Indexed_Component_Or_Slice
;
1613 -- If not an entity name, prefix is an expression that may denote
1614 -- an array or an access-to-subprogram.
1618 if (Ekind
(P_T
) = E_Subprogram_Type
)
1619 or else (Is_Access_Type
(P_T
)
1621 Ekind
(Designated_Type
(P_T
)) = E_Subprogram_Type
)
1623 Process_Function_Call
;
1625 elsif Nkind
(P
) = N_Selected_Component
1626 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
1628 Process_Function_Call
;
1631 -- Indexed component, slice, or a call to a member of a family
1632 -- entry, which will be converted to an entry call later.
1633 Process_Indexed_Component_Or_Slice
;
1636 end Analyze_Indexed_Component_Form
;
1638 ------------------------
1639 -- Analyze_Logical_Op --
1640 ------------------------
1642 procedure Analyze_Logical_Op
(N
: Node_Id
) is
1643 L
: constant Node_Id
:= Left_Opnd
(N
);
1644 R
: constant Node_Id
:= Right_Opnd
(N
);
1645 Op_Id
: Entity_Id
:= Entity
(N
);
1648 Set_Etype
(N
, Any_Type
);
1649 Candidate_Type
:= Empty
;
1651 Analyze_Expression
(L
);
1652 Analyze_Expression
(R
);
1654 if Present
(Op_Id
) then
1656 if Ekind
(Op_Id
) = E_Operator
then
1657 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
1659 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1663 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1665 while Present
(Op_Id
) loop
1666 if Ekind
(Op_Id
) = E_Operator
then
1667 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
1669 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1672 Op_Id
:= Homonym
(Op_Id
);
1677 end Analyze_Logical_Op
;
1679 ---------------------------
1680 -- Analyze_Membership_Op --
1681 ---------------------------
1683 procedure Analyze_Membership_Op
(N
: Node_Id
) is
1684 L
: constant Node_Id
:= Left_Opnd
(N
);
1685 R
: constant Node_Id
:= Right_Opnd
(N
);
1687 Index
: Interp_Index
;
1689 Found
: Boolean := False;
1693 procedure Try_One_Interp
(T1
: Entity_Id
);
1694 -- Routine to try one proposed interpretation. Note that the context
1695 -- of the operation plays no role in resolving the arguments, so that
1696 -- if there is more than one interpretation of the operands that is
1697 -- compatible with a membership test, the operation is ambiguous.
1699 procedure Try_One_Interp
(T1
: Entity_Id
) is
1701 if Has_Compatible_Type
(R
, T1
) then
1703 and then Base_Type
(T1
) /= Base_Type
(T_F
)
1705 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
1707 if It
= No_Interp
then
1708 Ambiguous_Operands
(N
);
1709 Set_Etype
(L
, Any_Type
);
1727 -- Start of processing for Analyze_Membership_Op
1730 Analyze_Expression
(L
);
1732 if Nkind
(R
) = N_Range
1733 or else (Nkind
(R
) = N_Attribute_Reference
1734 and then Attribute_Name
(R
) = Name_Range
)
1738 if not Is_Overloaded
(L
) then
1739 Try_One_Interp
(Etype
(L
));
1742 Get_First_Interp
(L
, Index
, It
);
1744 while Present
(It
.Typ
) loop
1745 Try_One_Interp
(It
.Typ
);
1746 Get_Next_Interp
(Index
, It
);
1750 -- If not a range, it can only be a subtype mark, or else there
1751 -- is a more basic error, to be diagnosed in Find_Type.
1756 if Is_Entity_Name
(R
) then
1757 Check_Fully_Declared
(Entity
(R
), R
);
1761 -- Compatibility between expression and subtype mark or range is
1762 -- checked during resolution. The result of the operation is Boolean
1765 Set_Etype
(N
, Standard_Boolean
);
1766 end Analyze_Membership_Op
;
1768 ----------------------
1769 -- Analyze_Negation --
1770 ----------------------
1772 procedure Analyze_Negation
(N
: Node_Id
) is
1773 R
: constant Node_Id
:= Right_Opnd
(N
);
1774 Op_Id
: Entity_Id
:= Entity
(N
);
1777 Set_Etype
(N
, Any_Type
);
1778 Candidate_Type
:= Empty
;
1780 Analyze_Expression
(R
);
1782 if Present
(Op_Id
) then
1783 if Ekind
(Op_Id
) = E_Operator
then
1784 Find_Negation_Types
(R
, Op_Id
, N
);
1786 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1790 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1792 while Present
(Op_Id
) loop
1793 if Ekind
(Op_Id
) = E_Operator
then
1794 Find_Negation_Types
(R
, Op_Id
, N
);
1796 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
1799 Op_Id
:= Homonym
(Op_Id
);
1804 end Analyze_Negation
;
1810 procedure Analyze_Null
(N
: Node_Id
) is
1812 Set_Etype
(N
, Any_Access
);
1815 ----------------------
1816 -- Analyze_One_Call --
1817 ----------------------
1819 procedure Analyze_One_Call
1823 Success
: out Boolean)
1825 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
1826 Prev_T
: constant Entity_Id
:= Etype
(N
);
1829 Is_Indexed
: Boolean := False;
1830 Subp_Type
: constant Entity_Id
:= Etype
(Nam
);
1834 -- If candidate interpretation matches, indicate name and type of
1835 -- result on call node.
1841 procedure Set_Name
is
1843 Add_One_Interp
(N
, Nam
, Etype
(Nam
));
1846 -- If the prefix of the call is a name, indicate the entity
1847 -- being called. If it is not a name, it is an expression that
1848 -- denotes an access to subprogram or else an entry or family. In
1849 -- the latter case, the name is a selected component, and the entity
1850 -- being called is noted on the selector.
1852 if not Is_Type
(Nam
) then
1853 if Is_Entity_Name
(Name
(N
))
1854 or else Nkind
(Name
(N
)) = N_Operator_Symbol
1856 Set_Entity
(Name
(N
), Nam
);
1858 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
1859 Set_Entity
(Selector_Name
(Name
(N
)), Nam
);
1863 if Debug_Flag_E
and not Report
then
1864 Write_Str
(" Overloaded call ");
1865 Write_Int
(Int
(N
));
1866 Write_Str
(" compatible with ");
1867 Write_Int
(Int
(Nam
));
1872 -- Start of processing for Analyze_One_Call
1877 -- If the subprogram has no formals, or if all the formals have
1878 -- defaults, and the return type is an array type, the node may
1879 -- denote an indexing of the result of a parameterless call.
1881 if Needs_No_Actuals
(Nam
)
1882 and then Present
(Actuals
)
1884 if Is_Array_Type
(Subp_Type
) then
1885 Is_Indexed
:= Try_Indexed_Call
(N
, Nam
, Subp_Type
);
1887 elsif Is_Access_Type
(Subp_Type
)
1888 and then Is_Array_Type
(Designated_Type
(Subp_Type
))
1891 Try_Indexed_Call
(N
, Nam
, Designated_Type
(Subp_Type
));
1893 elsif Is_Access_Type
(Subp_Type
)
1894 and then Ekind
(Designated_Type
(Subp_Type
)) = E_Subprogram_Type
1896 Is_Indexed
:= Try_Indirect_Call
(N
, Nam
, Subp_Type
);
1901 Normalize_Actuals
(N
, Nam
, (Report
and not Is_Indexed
), Norm_OK
);
1905 -- Mismatch in number or names of parameters
1907 if Debug_Flag_E
then
1908 Write_Str
(" normalization fails in call ");
1909 Write_Int
(Int
(N
));
1910 Write_Str
(" with subprogram ");
1911 Write_Int
(Int
(Nam
));
1915 -- If the context expects a function call, discard any interpretation
1916 -- that is a procedure. If the node is not overloaded, leave as is for
1917 -- better error reporting when type mismatch is found.
1919 elsif Nkind
(N
) = N_Function_Call
1920 and then Is_Overloaded
(Name
(N
))
1921 and then Ekind
(Nam
) = E_Procedure
1925 -- Ditto for function calls in a procedure context.
1927 elsif Nkind
(N
) = N_Procedure_Call_Statement
1928 and then Is_Overloaded
(Name
(N
))
1929 and then Etype
(Nam
) /= Standard_Void_Type
1933 elsif not Present
(Actuals
) then
1935 -- If Normalize succeeds, then there are default parameters for
1940 elsif Ekind
(Nam
) = E_Operator
then
1942 if Nkind
(N
) = N_Procedure_Call_Statement
then
1946 -- This can occur when the prefix of the call is an operator
1947 -- name or an expanded name whose selector is an operator name.
1949 Analyze_Operator_Call
(N
, Nam
);
1951 if Etype
(N
) /= Prev_T
then
1953 -- There may be a user-defined operator that hides the
1954 -- current interpretation. We must check for this independently
1955 -- of the analysis of the call with the user-defined operation,
1956 -- because the parameter names may be wrong and yet the hiding
1957 -- takes place. Fixes b34014o.
1959 if Is_Overloaded
(Name
(N
)) then
1965 Get_First_Interp
(Name
(N
), I
, It
);
1967 while Present
(It
.Nam
) loop
1969 if Ekind
(It
.Nam
) /= E_Operator
1970 and then Hides_Op
(It
.Nam
, Nam
)
1973 (First_Actual
(N
), Etype
(First_Formal
(It
.Nam
)))
1974 and then (No
(Next_Actual
(First_Actual
(N
)))
1975 or else Has_Compatible_Type
1976 (Next_Actual
(First_Actual
(N
)),
1977 Etype
(Next_Formal
(First_Formal
(It
.Nam
)))))
1979 Set_Etype
(N
, Prev_T
);
1983 Get_Next_Interp
(I
, It
);
1988 -- If operator matches formals, record its name on the call.
1989 -- If the operator is overloaded, Resolve will select the
1990 -- correct one from the list of interpretations. The call
1991 -- node itself carries the first candidate.
1993 Set_Entity
(Name
(N
), Nam
);
1996 elsif Report
and then Etype
(N
) = Any_Type
then
1997 Error_Msg_N
("incompatible arguments for operator", N
);
2001 -- Normalize_Actuals has chained the named associations in the
2002 -- correct order of the formals.
2004 Actual
:= First_Actual
(N
);
2005 Formal
:= First_Formal
(Nam
);
2007 while Present
(Actual
) and then Present
(Formal
) loop
2009 if (Nkind
(Parent
(Actual
)) /= N_Parameter_Association
2010 or else Chars
(Selector_Name
(Parent
(Actual
))) = Chars
(Formal
))
2012 if Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
2013 Next_Actual
(Actual
);
2014 Next_Formal
(Formal
);
2017 if Debug_Flag_E
then
2018 Write_Str
(" type checking fails in call ");
2019 Write_Int
(Int
(N
));
2020 Write_Str
(" with formal ");
2021 Write_Int
(Int
(Formal
));
2022 Write_Str
(" in subprogram ");
2023 Write_Int
(Int
(Nam
));
2027 if Report
and not Is_Indexed
then
2029 Wrong_Type
(Actual
, Etype
(Formal
));
2031 if Nkind
(Actual
) = N_Op_Eq
2032 and then Nkind
(Left_Opnd
(Actual
)) = N_Identifier
2034 Formal
:= First_Formal
(Nam
);
2036 while Present
(Formal
) loop
2038 if Chars
(Left_Opnd
(Actual
)) = Chars
(Formal
) then
2040 ("possible misspelling of `=>`!", Actual
);
2044 Next_Formal
(Formal
);
2048 if All_Errors_Mode
then
2049 Error_Msg_Sloc
:= Sloc
(Nam
);
2051 if Is_Overloadable
(Nam
)
2052 and then Present
(Alias
(Nam
))
2053 and then not Comes_From_Source
(Nam
)
2056 (" ==> in call to &#(inherited)!", Actual
, Nam
);
2058 Error_Msg_NE
(" ==> in call to &#!", Actual
, Nam
);
2067 -- Normalize_Actuals has verified that a default value exists
2068 -- for this formal. Current actual names a subsequent formal.
2070 Next_Formal
(Formal
);
2074 -- On exit, all actuals match.
2078 end Analyze_One_Call
;
2080 ----------------------------
2081 -- Analyze_Operator_Call --
2082 ----------------------------
2084 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
) is
2085 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
2086 Act1
: constant Node_Id
:= First_Actual
(N
);
2087 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
2090 if Present
(Act2
) then
2092 -- Maybe binary operators
2094 if Present
(Next_Actual
(Act2
)) then
2096 -- Too many actuals for an operator
2100 elsif Op_Name
= Name_Op_Add
2101 or else Op_Name
= Name_Op_Subtract
2102 or else Op_Name
= Name_Op_Multiply
2103 or else Op_Name
= Name_Op_Divide
2104 or else Op_Name
= Name_Op_Mod
2105 or else Op_Name
= Name_Op_Rem
2106 or else Op_Name
= Name_Op_Expon
2108 Find_Arithmetic_Types
(Act1
, Act2
, Op_Id
, N
);
2110 elsif Op_Name
= Name_Op_And
2111 or else Op_Name
= Name_Op_Or
2112 or else Op_Name
= Name_Op_Xor
2114 Find_Boolean_Types
(Act1
, Act2
, Op_Id
, N
);
2116 elsif Op_Name
= Name_Op_Lt
2117 or else Op_Name
= Name_Op_Le
2118 or else Op_Name
= Name_Op_Gt
2119 or else Op_Name
= Name_Op_Ge
2121 Find_Comparison_Types
(Act1
, Act2
, Op_Id
, N
);
2123 elsif Op_Name
= Name_Op_Eq
2124 or else Op_Name
= Name_Op_Ne
2126 Find_Equality_Types
(Act1
, Act2
, Op_Id
, N
);
2128 elsif Op_Name
= Name_Op_Concat
then
2129 Find_Concatenation_Types
(Act1
, Act2
, Op_Id
, N
);
2131 -- Is this else null correct, or should it be an abort???
2140 if Op_Name
= Name_Op_Subtract
or else
2141 Op_Name
= Name_Op_Add
or else
2142 Op_Name
= Name_Op_Abs
2144 Find_Unary_Types
(Act1
, Op_Id
, N
);
2147 Op_Name
= Name_Op_Not
2149 Find_Negation_Types
(Act1
, Op_Id
, N
);
2151 -- Is this else null correct, or should it be an abort???
2157 end Analyze_Operator_Call
;
2159 -------------------------------------------
2160 -- Analyze_Overloaded_Selected_Component --
2161 -------------------------------------------
2163 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
) is
2165 Nam
: Node_Id
:= Prefix
(N
);
2166 Sel
: Node_Id
:= Selector_Name
(N
);
2172 Get_First_Interp
(Nam
, I
, It
);
2174 Set_Etype
(Sel
, Any_Type
);
2176 while Present
(It
.Typ
) loop
2177 if Is_Access_Type
(It
.Typ
) then
2178 T
:= Designated_Type
(It
.Typ
);
2180 if Warn_On_Dereference
then
2181 Error_Msg_N
("?implicit dereference", N
);
2188 if Is_Record_Type
(T
) then
2189 Comp
:= First_Entity
(T
);
2191 while Present
(Comp
) loop
2193 if Chars
(Comp
) = Chars
(Sel
)
2194 and then Is_Visible_Component
(Comp
)
2196 Set_Entity_With_Style_Check
(Sel
, Comp
);
2197 Generate_Reference
(Comp
, Sel
);
2199 Set_Etype
(Sel
, Etype
(Comp
));
2200 Add_One_Interp
(N
, Etype
(Comp
), Etype
(Comp
));
2202 -- This also specifies a candidate to resolve the name.
2203 -- Further overloading will be resolved from context.
2205 Set_Etype
(Nam
, It
.Typ
);
2211 elsif Is_Concurrent_Type
(T
) then
2212 Comp
:= First_Entity
(T
);
2214 while Present
(Comp
)
2215 and then Comp
/= First_Private_Entity
(T
)
2217 if Chars
(Comp
) = Chars
(Sel
) then
2218 if Is_Overloadable
(Comp
) then
2219 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
2221 Set_Entity_With_Style_Check
(Sel
, Comp
);
2222 Generate_Reference
(Comp
, Sel
);
2225 Set_Etype
(Sel
, Etype
(Comp
));
2226 Set_Etype
(N
, Etype
(Comp
));
2227 Set_Etype
(Nam
, It
.Typ
);
2229 -- For access type case, introduce explicit deference for
2230 -- more uniform treatment of entry calls.
2232 if Is_Access_Type
(Etype
(Nam
)) then
2233 Insert_Explicit_Dereference
(Nam
);
2235 if Warn_On_Dereference
then
2236 Error_Msg_N
("?implicit dereference", N
);
2244 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
2247 Get_Next_Interp
(I
, It
);
2250 if Etype
(N
) = Any_Type
then
2251 Error_Msg_NE
("undefined selector& for overloaded prefix", N
, Sel
);
2252 Set_Entity
(Sel
, Any_Id
);
2253 Set_Etype
(Sel
, Any_Type
);
2256 end Analyze_Overloaded_Selected_Component
;
2258 ----------------------------------
2259 -- Analyze_Qualified_Expression --
2260 ----------------------------------
2262 procedure Analyze_Qualified_Expression
(N
: Node_Id
) is
2263 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
2267 Set_Etype
(N
, Any_Type
);
2271 if T
= Any_Type
then
2274 Check_Fully_Declared
(T
, N
);
2276 Analyze_Expression
(Expression
(N
));
2278 end Analyze_Qualified_Expression
;
2284 procedure Analyze_Range
(N
: Node_Id
) is
2285 L
: constant Node_Id
:= Low_Bound
(N
);
2286 H
: constant Node_Id
:= High_Bound
(N
);
2287 I1
, I2
: Interp_Index
;
2290 procedure Check_Common_Type
(T1
, T2
: Entity_Id
);
2291 -- Verify the compatibility of two types, and choose the
2292 -- non universal one if the other is universal.
2294 procedure Check_High_Bound
(T
: Entity_Id
);
2295 -- Test one interpretation of the low bound against all those
2296 -- of the high bound.
2298 -----------------------
2299 -- Check_Common_Type --
2300 -----------------------
2302 procedure Check_Common_Type
(T1
, T2
: Entity_Id
) is
2304 if Covers
(T1
, T2
) or else Covers
(T2
, T1
) then
2305 if T1
= Universal_Integer
2306 or else T1
= Universal_Real
2307 or else T1
= Any_Character
2309 Add_One_Interp
(N
, Base_Type
(T2
), Base_Type
(T2
));
2311 elsif (T1
= T2
) then
2312 Add_One_Interp
(N
, T1
, T1
);
2315 Add_One_Interp
(N
, Base_Type
(T1
), Base_Type
(T1
));
2318 end Check_Common_Type
;
2320 ----------------------
2321 -- Check_High_Bound --
2322 ----------------------
2324 procedure Check_High_Bound
(T
: Entity_Id
) is
2326 if not Is_Overloaded
(H
) then
2327 Check_Common_Type
(T
, Etype
(H
));
2329 Get_First_Interp
(H
, I2
, It2
);
2331 while Present
(It2
.Typ
) loop
2332 Check_Common_Type
(T
, It2
.Typ
);
2333 Get_Next_Interp
(I2
, It2
);
2336 end Check_High_Bound
;
2338 -- Start of processing for Analyze_Range
2341 Set_Etype
(N
, Any_Type
);
2342 Analyze_Expression
(L
);
2343 Analyze_Expression
(H
);
2345 if Etype
(L
) = Any_Type
or else Etype
(H
) = Any_Type
then
2349 if not Is_Overloaded
(L
) then
2350 Check_High_Bound
(Etype
(L
));
2352 Get_First_Interp
(L
, I1
, It1
);
2354 while Present
(It1
.Typ
) loop
2355 Check_High_Bound
(It1
.Typ
);
2356 Get_Next_Interp
(I1
, It1
);
2360 -- If result is Any_Type, then we did not find a compatible pair
2362 if Etype
(N
) = Any_Type
then
2363 Error_Msg_N
("incompatible types in range ", N
);
2368 -----------------------
2369 -- Analyze_Reference --
2370 -----------------------
2372 procedure Analyze_Reference
(N
: Node_Id
) is
2373 P
: constant Node_Id
:= Prefix
(N
);
2374 Acc_Type
: Entity_Id
;
2378 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
2379 Set_Etype
(Acc_Type
, Acc_Type
);
2380 Init_Size_Align
(Acc_Type
);
2381 Set_Directly_Designated_Type
(Acc_Type
, Etype
(P
));
2382 Set_Etype
(N
, Acc_Type
);
2383 end Analyze_Reference
;
2385 --------------------------------
2386 -- Analyze_Selected_Component --
2387 --------------------------------
2389 -- Prefix is a record type or a task or protected type. In the
2390 -- later case, the selector must denote a visible entry.
2392 procedure Analyze_Selected_Component
(N
: Node_Id
) is
2393 Name
: constant Node_Id
:= Prefix
(N
);
2394 Sel
: constant Node_Id
:= Selector_Name
(N
);
2396 Entity_List
: Entity_Id
;
2397 Prefix_Type
: Entity_Id
;
2402 -- Start of processing for Analyze_Selected_Component
2405 Set_Etype
(N
, Any_Type
);
2407 if Is_Overloaded
(Name
) then
2408 Analyze_Overloaded_Selected_Component
(N
);
2411 elsif Etype
(Name
) = Any_Type
then
2412 Set_Entity
(Sel
, Any_Id
);
2413 Set_Etype
(Sel
, Any_Type
);
2417 -- Function calls that are prefixes of selected components must be
2418 -- fully resolved in case we need to build an actual subtype, or
2419 -- do some other operation requiring a fully resolved prefix.
2421 -- Note: Resolving all Nkinds of nodes here doesn't work.
2422 -- (Breaks 2129-008) ???.
2424 if Nkind
(Name
) = N_Function_Call
then
2425 Resolve
(Name
, Etype
(Name
));
2428 Prefix_Type
:= Etype
(Name
);
2431 if Is_Access_Type
(Prefix_Type
) then
2433 -- A RACW object can never be used as prefix of a selected
2434 -- component since that means it is dereferenced without
2435 -- being a controlling operand of a dispatching operation
2438 if Is_Remote_Access_To_Class_Wide_Type
(Prefix_Type
)
2439 and then Comes_From_Source
(N
)
2442 ("invalid dereference of a remote access to class-wide value",
2445 -- Normal case of selected component applied to access type
2448 if Warn_On_Dereference
then
2449 Error_Msg_N
("?implicit dereference", N
);
2453 Prefix_Type
:= Designated_Type
(Prefix_Type
);
2456 if Ekind
(Prefix_Type
) = E_Private_Subtype
then
2457 Prefix_Type
:= Base_Type
(Prefix_Type
);
2460 Entity_List
:= Prefix_Type
;
2462 -- For class-wide types, use the entity list of the root type. This
2463 -- indirection is specially important for private extensions because
2464 -- only the root type get switched (not the class-wide type).
2466 if Is_Class_Wide_Type
(Prefix_Type
) then
2467 Entity_List
:= Root_Type
(Prefix_Type
);
2470 Comp
:= First_Entity
(Entity_List
);
2472 -- If the selector has an original discriminant, the node appears in
2473 -- an instance. Replace the discriminant with the corresponding one
2474 -- in the current discriminated type. For nested generics, this must
2475 -- be done transitively, so note the new original discriminant.
2477 if Nkind
(Sel
) = N_Identifier
2478 and then Present
(Original_Discriminant
(Sel
))
2480 Comp
:= Find_Corresponding_Discriminant
(Sel
, Prefix_Type
);
2482 -- Mark entity before rewriting, for completeness and because
2483 -- subsequent semantic checks might examine the original node.
2485 Set_Entity
(Sel
, Comp
);
2486 Rewrite
(Selector_Name
(N
),
2487 New_Occurrence_Of
(Comp
, Sloc
(N
)));
2488 Set_Original_Discriminant
(Selector_Name
(N
), Comp
);
2489 Set_Etype
(N
, Etype
(Comp
));
2491 if Is_Access_Type
(Etype
(Name
)) then
2492 Insert_Explicit_Dereference
(Name
);
2494 if Warn_On_Dereference
then
2495 Error_Msg_N
("?implicit dereference", N
);
2499 elsif Is_Record_Type
(Prefix_Type
) then
2501 -- Find component with given name
2503 while Present
(Comp
) loop
2505 if Chars
(Comp
) = Chars
(Sel
)
2506 and then Is_Visible_Component
(Comp
)
2508 Set_Entity_With_Style_Check
(Sel
, Comp
);
2509 Generate_Reference
(Comp
, Sel
);
2511 Set_Etype
(Sel
, Etype
(Comp
));
2513 if Ekind
(Comp
) = E_Discriminant
then
2514 if Is_Unchecked_Union
(Prefix_Type
) then
2516 ("cannot reference discriminant of Unchecked_Union",
2520 if Is_Generic_Type
(Prefix_Type
)
2522 Is_Generic_Type
(Root_Type
(Prefix_Type
))
2524 Set_Original_Discriminant
(Sel
, Comp
);
2528 -- Resolve the prefix early otherwise it is not possible to
2529 -- build the actual subtype of the component: it may need
2530 -- to duplicate this prefix and duplication is only allowed
2531 -- on fully resolved expressions.
2533 Resolve
(Name
, Etype
(Name
));
2535 -- We never need an actual subtype for the case of a selection
2536 -- for a indexed component of a non-packed array, since in
2537 -- this case gigi generates all the checks and can find the
2538 -- necessary bounds information.
2540 -- We also do not need an actual subtype for the case of
2541 -- a first, last, length, or range attribute applied to a
2542 -- non-packed array, since gigi can again get the bounds in
2543 -- these cases (gigi cannot handle the packed case, since it
2544 -- has the bounds of the packed array type, not the original
2545 -- bounds of the type). However, if the prefix is itself a
2546 -- selected component, as in a.b.c (i), gigi may regard a.b.c
2547 -- as a dynamic-sized temporary, so we do generate an actual
2548 -- subtype for this case.
2550 Parent_N
:= Parent
(N
);
2552 if not Is_Packed
(Etype
(Comp
))
2554 ((Nkind
(Parent_N
) = N_Indexed_Component
2555 and then Nkind
(Name
) /= N_Selected_Component
)
2557 (Nkind
(Parent_N
) = N_Attribute_Reference
2558 and then (Attribute_Name
(Parent_N
) = Name_First
2560 Attribute_Name
(Parent_N
) = Name_Last
2562 Attribute_Name
(Parent_N
) = Name_Length
2564 Attribute_Name
(Parent_N
) = Name_Range
)))
2566 Set_Etype
(N
, Etype
(Comp
));
2568 -- In all other cases, we currently build an actual subtype. It
2569 -- seems likely that many of these cases can be avoided, but
2570 -- right now, the front end makes direct references to the
2571 -- bounds (e.g. in egnerating a length check), and if we do
2572 -- not make an actual subtype, we end up getting a direct
2573 -- reference to a discriminant which will not do.
2577 Build_Actual_Subtype_Of_Component
(Etype
(Comp
), N
);
2578 Insert_Action
(N
, Act_Decl
);
2580 if No
(Act_Decl
) then
2581 Set_Etype
(N
, Etype
(Comp
));
2584 -- Component type depends on discriminants. Enter the
2585 -- main attributes of the subtype.
2588 Subt
: Entity_Id
:= Defining_Identifier
(Act_Decl
);
2591 Set_Etype
(Subt
, Base_Type
(Etype
(Comp
)));
2592 Set_Ekind
(Subt
, Ekind
(Etype
(Comp
)));
2593 Set_Etype
(N
, Subt
);
2604 elsif Is_Private_Type
(Prefix_Type
) then
2606 -- Allow access only to discriminants of the type. If the
2607 -- type has no full view, gigi uses the parent type for
2608 -- the components, so we do the same here.
2610 if No
(Full_View
(Prefix_Type
)) then
2611 Entity_List
:= Root_Type
(Base_Type
(Prefix_Type
));
2612 Comp
:= First_Entity
(Entity_List
);
2615 while Present
(Comp
) loop
2617 if Chars
(Comp
) = Chars
(Sel
) then
2618 if Ekind
(Comp
) = E_Discriminant
then
2619 Set_Entity_With_Style_Check
(Sel
, Comp
);
2620 Generate_Reference
(Comp
, Sel
);
2622 Set_Etype
(Sel
, Etype
(Comp
));
2623 Set_Etype
(N
, Etype
(Comp
));
2625 if Is_Generic_Type
(Prefix_Type
)
2627 Is_Generic_Type
(Root_Type
(Prefix_Type
))
2629 Set_Original_Discriminant
(Sel
, Comp
);
2634 ("invisible selector for }",
2635 N
, First_Subtype
(Prefix_Type
));
2636 Set_Entity
(Sel
, Any_Id
);
2637 Set_Etype
(N
, Any_Type
);
2646 elsif Is_Concurrent_Type
(Prefix_Type
) then
2648 -- Prefix is concurrent type. Find visible operation with given name
2649 -- For a task, this can only include entries or discriminants if
2650 -- the task type is not an enclosing scope. If it is an enclosing
2651 -- scope (e.g. in an inner task) then all entities are visible, but
2652 -- the prefix must denote the enclosing scope, i.e. can only be
2653 -- a direct name or an expanded name.
2655 Set_Etype
(Sel
, Any_Type
);
2656 In_Scope
:= In_Open_Scopes
(Prefix_Type
);
2658 while Present
(Comp
) loop
2659 if Chars
(Comp
) = Chars
(Sel
) then
2660 if Is_Overloadable
(Comp
) then
2661 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
2663 elsif Ekind
(Comp
) = E_Discriminant
2664 or else Ekind
(Comp
) = E_Entry_Family
2666 and then Is_Entity_Name
(Name
))
2668 Set_Entity_With_Style_Check
(Sel
, Comp
);
2669 Generate_Reference
(Comp
, Sel
);
2675 Set_Etype
(Sel
, Etype
(Comp
));
2676 Set_Etype
(N
, Etype
(Comp
));
2678 if Ekind
(Comp
) = E_Discriminant
then
2679 Set_Original_Discriminant
(Sel
, Comp
);
2682 -- For access type case, introduce explicit deference for
2683 -- more uniform treatment of entry calls.
2685 if Is_Access_Type
(Etype
(Name
)) then
2686 Insert_Explicit_Dereference
(Name
);
2688 if Warn_On_Dereference
then
2689 Error_Msg_N
("?implicit dereference", N
);
2696 exit when not In_Scope
2697 and then Comp
= First_Private_Entity
(Prefix_Type
);
2700 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
2705 Error_Msg_NE
("invalid prefix in selected component&", N
, Sel
);
2708 -- If N still has no type, the component is not defined in the prefix.
2710 if Etype
(N
) = Any_Type
then
2712 -- If the prefix is a single concurrent object, use its name in
2713 -- the error message, rather than that of its anonymous type.
2715 if Is_Concurrent_Type
(Prefix_Type
)
2716 and then Is_Internal_Name
(Chars
(Prefix_Type
))
2717 and then not Is_Derived_Type
(Prefix_Type
)
2718 and then Is_Entity_Name
(Name
)
2721 Error_Msg_Node_2
:= Entity
(Name
);
2722 Error_Msg_NE
("no selector& for&", N
, Sel
);
2724 Check_Misspelled_Selector
(Entity_List
, Sel
);
2726 elsif Is_Generic_Type
(Prefix_Type
)
2727 and then Ekind
(Prefix_Type
) = E_Record_Type_With_Private
2728 and then Prefix_Type
/= Etype
(Prefix_Type
)
2729 and then Is_Record_Type
(Etype
(Prefix_Type
))
2731 -- If this is a derived formal type, the parent may have a
2732 -- different visibility at this point. Try for an inherited
2733 -- component before reporting an error.
2735 Set_Etype
(Prefix
(N
), Etype
(Prefix_Type
));
2736 Analyze_Selected_Component
(N
);
2740 if Ekind
(Prefix_Type
) = E_Record_Subtype
then
2742 -- Check whether this is a component of the base type
2743 -- which is absent from a statically constrained subtype.
2744 -- This will raise constraint error at run-time, but is
2745 -- not a compile-time error. When the selector is illegal
2746 -- for base type as well fall through and generate a
2747 -- compilation error anyway.
2749 Comp
:= First_Component
(Base_Type
(Prefix_Type
));
2751 while Present
(Comp
) loop
2753 if Chars
(Comp
) = Chars
(Sel
)
2754 and then Is_Visible_Component
(Comp
)
2756 Set_Entity_With_Style_Check
(Sel
, Comp
);
2757 Generate_Reference
(Comp
, Sel
);
2758 Set_Etype
(Sel
, Etype
(Comp
));
2759 Set_Etype
(N
, Etype
(Comp
));
2761 -- Emit appropriate message. Gigi will replace the
2762 -- node subsequently with the appropriate Raise.
2764 Apply_Compile_Time_Constraint_Error
2765 (N
, "component not present in }?",
2766 CE_Discriminant_Check_Failed
,
2767 Ent
=> Prefix_Type
, Rep
=> False);
2768 Set_Raises_Constraint_Error
(N
);
2772 Next_Component
(Comp
);
2777 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
2778 Error_Msg_NE
("no selector& for}", N
, Sel
);
2780 Check_Misspelled_Selector
(Entity_List
, Sel
);
2784 Set_Entity
(Sel
, Any_Id
);
2785 Set_Etype
(Sel
, Any_Type
);
2787 end Analyze_Selected_Component
;
2789 ---------------------------
2790 -- Analyze_Short_Circuit --
2791 ---------------------------
2793 procedure Analyze_Short_Circuit
(N
: Node_Id
) is
2794 L
: constant Node_Id
:= Left_Opnd
(N
);
2795 R
: constant Node_Id
:= Right_Opnd
(N
);
2800 Analyze_Expression
(L
);
2801 Analyze_Expression
(R
);
2802 Set_Etype
(N
, Any_Type
);
2804 if not Is_Overloaded
(L
) then
2806 if Root_Type
(Etype
(L
)) = Standard_Boolean
2807 and then Has_Compatible_Type
(R
, Etype
(L
))
2809 Add_One_Interp
(N
, Etype
(L
), Etype
(L
));
2813 Get_First_Interp
(L
, Ind
, It
);
2815 while Present
(It
.Typ
) loop
2816 if Root_Type
(It
.Typ
) = Standard_Boolean
2817 and then Has_Compatible_Type
(R
, It
.Typ
)
2819 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
2822 Get_Next_Interp
(Ind
, It
);
2826 -- Here we have failed to find an interpretation. Clearly we
2827 -- know that it is not the case that both operands can have
2828 -- an interpretation of Boolean, but this is by far the most
2829 -- likely intended interpretation. So we simply resolve both
2830 -- operands as Booleans, and at least one of these resolutions
2831 -- will generate an error message, and we do not need to give
2832 -- a further error message on the short circuit operation itself.
2834 if Etype
(N
) = Any_Type
then
2835 Resolve
(L
, Standard_Boolean
);
2836 Resolve
(R
, Standard_Boolean
);
2837 Set_Etype
(N
, Standard_Boolean
);
2839 end Analyze_Short_Circuit
;
2845 procedure Analyze_Slice
(N
: Node_Id
) is
2846 P
: constant Node_Id
:= Prefix
(N
);
2847 D
: constant Node_Id
:= Discrete_Range
(N
);
2848 Array_Type
: Entity_Id
;
2850 procedure Analyze_Overloaded_Slice
;
2851 -- If the prefix is overloaded, select those interpretations that
2852 -- yield a one-dimensional array type.
2854 procedure Analyze_Overloaded_Slice
is
2860 Set_Etype
(N
, Any_Type
);
2861 Get_First_Interp
(P
, I
, It
);
2863 while Present
(It
.Nam
) loop
2866 if Is_Access_Type
(Typ
) then
2867 Typ
:= Designated_Type
(Typ
);
2869 if Warn_On_Dereference
then
2870 Error_Msg_N
("?implicit dereference", N
);
2874 if Is_Array_Type
(Typ
)
2875 and then Number_Dimensions
(Typ
) = 1
2876 and then Has_Compatible_Type
(D
, Etype
(First_Index
(Typ
)))
2878 Add_One_Interp
(N
, Typ
, Typ
);
2881 Get_Next_Interp
(I
, It
);
2884 if Etype
(N
) = Any_Type
then
2885 Error_Msg_N
("expect array type in prefix of slice", N
);
2887 end Analyze_Overloaded_Slice
;
2889 -- Start of processing for Analyze_Slice
2892 -- Analyze the prefix if not done already
2894 if No
(Etype
(P
)) then
2900 if Is_Overloaded
(P
) then
2901 Analyze_Overloaded_Slice
;
2904 Array_Type
:= Etype
(P
);
2905 Set_Etype
(N
, Any_Type
);
2907 if Is_Access_Type
(Array_Type
) then
2908 Array_Type
:= Designated_Type
(Array_Type
);
2910 if Warn_On_Dereference
then
2911 Error_Msg_N
("?implicit dereference", N
);
2915 if not Is_Array_Type
(Array_Type
) then
2916 Wrong_Type
(P
, Any_Array
);
2918 elsif Number_Dimensions
(Array_Type
) > 1 then
2920 ("type is not one-dimensional array in slice prefix", N
);
2923 Has_Compatible_Type
(D
, Etype
(First_Index
(Array_Type
)))
2925 Wrong_Type
(D
, Etype
(First_Index
(Array_Type
)));
2928 Set_Etype
(N
, Array_Type
);
2933 -----------------------------
2934 -- Analyze_Type_Conversion --
2935 -----------------------------
2937 procedure Analyze_Type_Conversion
(N
: Node_Id
) is
2938 Expr
: constant Node_Id
:= Expression
(N
);
2942 -- If Conversion_OK is set, then the Etype is already set, and the
2943 -- only processing required is to analyze the expression. This is
2944 -- used to construct certain "illegal" conversions which are not
2945 -- allowed by Ada semantics, but can be handled OK by Gigi, see
2946 -- Sinfo for further details.
2948 if Conversion_OK
(N
) then
2953 -- Otherwise full type analysis is required, as well as some semantic
2954 -- checks to make sure the argument of the conversion is appropriate.
2956 Find_Type
(Subtype_Mark
(N
));
2957 T
:= Entity
(Subtype_Mark
(N
));
2959 Check_Fully_Declared
(T
, N
);
2960 Analyze_Expression
(Expr
);
2961 Validate_Remote_Type_Type_Conversion
(N
);
2963 -- Only remaining step is validity checks on the argument. These
2964 -- are skipped if the conversion does not come from the source.
2966 if not Comes_From_Source
(N
) then
2969 elsif Nkind
(Expr
) = N_Null
then
2970 Error_Msg_N
("argument of conversion cannot be null", N
);
2971 Error_Msg_N
("\use qualified expression instead", N
);
2972 Set_Etype
(N
, Any_Type
);
2974 elsif Nkind
(Expr
) = N_Aggregate
then
2975 Error_Msg_N
("argument of conversion cannot be aggregate", N
);
2976 Error_Msg_N
("\use qualified expression instead", N
);
2978 elsif Nkind
(Expr
) = N_Allocator
then
2979 Error_Msg_N
("argument of conversion cannot be an allocator", N
);
2980 Error_Msg_N
("\use qualified expression instead", N
);
2982 elsif Nkind
(Expr
) = N_String_Literal
then
2983 Error_Msg_N
("argument of conversion cannot be string literal", N
);
2984 Error_Msg_N
("\use qualified expression instead", N
);
2986 elsif Nkind
(Expr
) = N_Character_Literal
then
2990 Error_Msg_N
("argument of conversion cannot be character literal",
2992 Error_Msg_N
("\use qualified expression instead", N
);
2995 elsif Nkind
(Expr
) = N_Attribute_Reference
2997 (Attribute_Name
(Expr
) = Name_Access
or else
2998 Attribute_Name
(Expr
) = Name_Unchecked_Access
or else
2999 Attribute_Name
(Expr
) = Name_Unrestricted_Access
)
3001 Error_Msg_N
("argument of conversion cannot be access", N
);
3002 Error_Msg_N
("\use qualified expression instead", N
);
3005 end Analyze_Type_Conversion
;
3007 ----------------------
3008 -- Analyze_Unary_Op --
3009 ----------------------
3011 procedure Analyze_Unary_Op
(N
: Node_Id
) is
3012 R
: constant Node_Id
:= Right_Opnd
(N
);
3013 Op_Id
: Entity_Id
:= Entity
(N
);
3016 Set_Etype
(N
, Any_Type
);
3017 Candidate_Type
:= Empty
;
3019 Analyze_Expression
(R
);
3021 if Present
(Op_Id
) then
3022 if Ekind
(Op_Id
) = E_Operator
then
3023 Find_Unary_Types
(R
, Op_Id
, N
);
3025 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3029 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
3031 while Present
(Op_Id
) loop
3033 if Ekind
(Op_Id
) = E_Operator
then
3034 if No
(Next_Entity
(First_Entity
(Op_Id
))) then
3035 Find_Unary_Types
(R
, Op_Id
, N
);
3038 elsif Is_Overloadable
(Op_Id
) then
3039 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
3042 Op_Id
:= Homonym
(Op_Id
);
3047 end Analyze_Unary_Op
;
3049 ----------------------------------
3050 -- Analyze_Unchecked_Expression --
3051 ----------------------------------
3053 procedure Analyze_Unchecked_Expression
(N
: Node_Id
) is
3055 Analyze
(Expression
(N
), Suppress
=> All_Checks
);
3056 Set_Etype
(N
, Etype
(Expression
(N
)));
3057 Save_Interps
(Expression
(N
), N
);
3058 end Analyze_Unchecked_Expression
;
3060 ---------------------------------------
3061 -- Analyze_Unchecked_Type_Conversion --
3062 ---------------------------------------
3064 procedure Analyze_Unchecked_Type_Conversion
(N
: Node_Id
) is
3066 Find_Type
(Subtype_Mark
(N
));
3067 Analyze_Expression
(Expression
(N
));
3068 Set_Etype
(N
, Entity
(Subtype_Mark
(N
)));
3069 end Analyze_Unchecked_Type_Conversion
;
3071 ------------------------------------
3072 -- Analyze_User_Defined_Binary_Op --
3073 ------------------------------------
3075 procedure Analyze_User_Defined_Binary_Op
3080 -- Only do analysis if the operator Comes_From_Source, since otherwise
3081 -- the operator was generated by the expander, and all such operators
3082 -- always refer to the operators in package Standard.
3084 if Comes_From_Source
(N
) then
3086 F1
: constant Entity_Id
:= First_Formal
(Op_Id
);
3087 F2
: constant Entity_Id
:= Next_Formal
(F1
);
3090 -- Verify that Op_Id is a visible binary function. Note that since
3091 -- we know Op_Id is overloaded, potentially use visible means use
3092 -- visible for sure (RM 9.4(11)).
3094 if Ekind
(Op_Id
) = E_Function
3095 and then Present
(F2
)
3096 and then (Is_Immediately_Visible
(Op_Id
)
3097 or else Is_Potentially_Use_Visible
(Op_Id
))
3098 and then Has_Compatible_Type
(Left_Opnd
(N
), Etype
(F1
))
3099 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F2
))
3101 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3103 if Debug_Flag_E
then
3104 Write_Str
("user defined operator ");
3105 Write_Name
(Chars
(Op_Id
));
3106 Write_Str
(" on node ");
3107 Write_Int
(Int
(N
));
3113 end Analyze_User_Defined_Binary_Op
;
3115 -----------------------------------
3116 -- Analyze_User_Defined_Unary_Op --
3117 -----------------------------------
3119 procedure Analyze_User_Defined_Unary_Op
3124 -- Only do analysis if the operator Comes_From_Source, since otherwise
3125 -- the operator was generated by the expander, and all such operators
3126 -- always refer to the operators in package Standard.
3128 if Comes_From_Source
(N
) then
3130 F
: constant Entity_Id
:= First_Formal
(Op_Id
);
3133 -- Verify that Op_Id is a visible unary function. Note that since
3134 -- we know Op_Id is overloaded, potentially use visible means use
3135 -- visible for sure (RM 9.4(11)).
3137 if Ekind
(Op_Id
) = E_Function
3138 and then No
(Next_Formal
(F
))
3139 and then (Is_Immediately_Visible
(Op_Id
)
3140 or else Is_Potentially_Use_Visible
(Op_Id
))
3141 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F
))
3143 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3147 end Analyze_User_Defined_Unary_Op
;
3149 ---------------------------
3150 -- Check_Arithmetic_Pair --
3151 ---------------------------
3153 procedure Check_Arithmetic_Pair
3154 (T1
, T2
: Entity_Id
;
3158 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
3160 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
;
3161 -- Get specific type (i.e. non-universal type if there is one)
3163 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
is
3165 if T1
= Universal_Integer
or else T1
= Universal_Real
then
3166 return Base_Type
(T2
);
3168 return Base_Type
(T1
);
3172 -- Start of processing for Check_Arithmetic_Pair
3175 if Op_Name
= Name_Op_Add
or else Op_Name
= Name_Op_Subtract
then
3177 if Is_Numeric_Type
(T1
)
3178 and then Is_Numeric_Type
(T2
)
3179 and then (Covers
(T1
, T2
) or else Covers
(T2
, T1
))
3181 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
3184 elsif Op_Name
= Name_Op_Multiply
or else Op_Name
= Name_Op_Divide
then
3186 if Is_Fixed_Point_Type
(T1
)
3187 and then (Is_Fixed_Point_Type
(T2
)
3188 or else T2
= Universal_Real
)
3190 -- If Treat_Fixed_As_Integer is set then the Etype is already set
3191 -- and no further processing is required (this is the case of an
3192 -- operator constructed by Exp_Fixd for a fixed point operation)
3193 -- Otherwise add one interpretation with universal fixed result
3194 -- If the operator is given in functional notation, it comes
3195 -- from source and Fixed_As_Integer cannot apply.
3197 if Nkind
(N
) not in N_Op
3198 or else not Treat_Fixed_As_Integer
(N
) then
3199 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
3202 elsif Is_Fixed_Point_Type
(T2
)
3203 and then (Nkind
(N
) not in N_Op
3204 or else not Treat_Fixed_As_Integer
(N
))
3205 and then T1
= Universal_Real
3207 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
3209 elsif Is_Numeric_Type
(T1
)
3210 and then Is_Numeric_Type
(T2
)
3211 and then (Covers
(T1
, T2
) or else Covers
(T2
, T1
))
3213 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
3215 elsif Is_Fixed_Point_Type
(T1
)
3216 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3217 or else T2
= Universal_Integer
)
3219 Add_One_Interp
(N
, Op_Id
, T1
);
3221 elsif T2
= Universal_Real
3222 and then Base_Type
(T1
) = Base_Type
(Standard_Integer
)
3223 and then Op_Name
= Name_Op_Multiply
3225 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
3227 elsif T1
= Universal_Real
3228 and then Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3230 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
3232 elsif Is_Fixed_Point_Type
(T2
)
3233 and then (Base_Type
(T1
) = Base_Type
(Standard_Integer
)
3234 or else T1
= Universal_Integer
)
3235 and then Op_Name
= Name_Op_Multiply
3237 Add_One_Interp
(N
, Op_Id
, T2
);
3239 elsif T1
= Universal_Real
and then T2
= Universal_Integer
then
3240 Add_One_Interp
(N
, Op_Id
, T1
);
3242 elsif T2
= Universal_Real
3243 and then T1
= Universal_Integer
3244 and then Op_Name
= Name_Op_Multiply
3246 Add_One_Interp
(N
, Op_Id
, T2
);
3249 elsif Op_Name
= Name_Op_Mod
or else Op_Name
= Name_Op_Rem
then
3251 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
3252 -- set does not require any special processing, since the Etype is
3253 -- already set (case of operation constructed by Exp_Fixed).
3255 if Is_Integer_Type
(T1
)
3256 and then (Covers
(T1
, T2
) or else Covers
(T2
, T1
))
3258 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
3261 elsif Op_Name
= Name_Op_Expon
then
3263 if Is_Numeric_Type
(T1
)
3264 and then not Is_Fixed_Point_Type
(T1
)
3265 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3266 or else T2
= Universal_Integer
)
3268 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
3271 else pragma Assert
(Nkind
(N
) in N_Op_Shift
);
3273 -- If not one of the predefined operators, the node may be one
3274 -- of the intrinsic functions. Its kind is always specific, and
3275 -- we can use it directly, rather than the name of the operation.
3277 if Is_Integer_Type
(T1
)
3278 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3279 or else T2
= Universal_Integer
)
3281 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
3284 end Check_Arithmetic_Pair
;
3286 -------------------------------
3287 -- Check_Misspelled_Selector --
3288 -------------------------------
3290 procedure Check_Misspelled_Selector
3291 (Prefix
: Entity_Id
;
3294 Max_Suggestions
: constant := 2;
3295 Nr_Of_Suggestions
: Natural := 0;
3297 Suggestion_1
: Entity_Id
:= Empty
;
3298 Suggestion_2
: Entity_Id
:= Empty
;
3303 -- All the components of the prefix of selector Sel are matched
3304 -- against Sel and a count is maintained of possible misspellings.
3305 -- When at the end of the analysis there are one or two (not more!)
3306 -- possible misspellings, these misspellings will be suggested as
3307 -- possible correction.
3309 if not (Is_Private_Type
(Prefix
) or Is_Record_Type
(Prefix
)) then
3310 -- Concurrent types should be handled as well ???
3314 Get_Name_String
(Chars
(Sel
));
3317 S
: constant String (1 .. Name_Len
) :=
3318 Name_Buffer
(1 .. Name_Len
);
3321 Comp
:= First_Entity
(Prefix
);
3323 while Nr_Of_Suggestions
<= Max_Suggestions
3324 and then Present
(Comp
)
3327 if Is_Visible_Component
(Comp
) then
3328 Get_Name_String
(Chars
(Comp
));
3330 if Is_Bad_Spelling_Of
(Name_Buffer
(1 .. Name_Len
), S
) then
3331 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
3333 case Nr_Of_Suggestions
is
3334 when 1 => Suggestion_1
:= Comp
;
3335 when 2 => Suggestion_2
:= Comp
;
3336 when others => exit;
3341 Comp
:= Next_Entity
(Comp
);
3344 -- Report at most two suggestions
3346 if Nr_Of_Suggestions
= 1 then
3347 Error_Msg_NE
("\possible misspelling of&", Sel
, Suggestion_1
);
3349 elsif Nr_Of_Suggestions
= 2 then
3350 Error_Msg_Node_2
:= Suggestion_2
;
3351 Error_Msg_NE
("\possible misspelling of& or&",
3355 end Check_Misspelled_Selector
;
3357 ----------------------
3358 -- Defined_In_Scope --
3359 ----------------------
3361 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean
3363 S1
: constant Entity_Id
:= Scope
(Base_Type
(T
));
3367 or else (S1
= System_Aux_Id
and then S
= Scope
(S1
));
3368 end Defined_In_Scope
;
3374 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
) is
3381 if Extensions_Allowed
then
3382 Actual
:= First_Actual
(N
);
3384 while Present
(Actual
) loop
3385 if not Analyzed
(Etype
(Actual
))
3386 and then From_With_Type
(Etype
(Actual
))
3388 Error_Msg_Qual_Level
:= 1;
3390 ("missing with_clause for scope of imported type&",
3391 Actual
, Etype
(Actual
));
3392 Error_Msg_Qual_Level
:= 0;
3395 Next_Actual
(Actual
);
3399 if All_Errors_Mode
then
3401 -- Analyze each candidate call again, with full error reporting
3404 Error_Msg_N
("\no candidate interpretations "
3405 & "match the actuals:!", Nam
);
3407 Get_First_Interp
(Nam
, X
, It
);
3409 while Present
(It
.Nam
) loop
3410 Analyze_One_Call
(N
, It
.Nam
, True, Success
);
3411 Get_Next_Interp
(X
, It
);
3417 ("invalid parameter list in call " &
3418 "('/'R'E'P'O'R'T'_'E'R'R'O'R'S'='F'U'L'L for details)!",
3422 ("invalid parameter list in call (use -gnatf for details)!",
3427 if Nkind
(N
) = N_Function_Call
then
3428 Get_First_Interp
(Nam
, X
, It
);
3430 while Present
(It
.Nam
) loop
3431 if Ekind
(It
.Nam
) = E_Function
3432 or else Ekind
(It
.Nam
) = E_Operator
3436 Get_Next_Interp
(X
, It
);
3440 -- If all interpretations are procedures, this deserves a
3441 -- more precise message. Ditto if this appears as the prefix
3442 -- of a selected component, which may be a lexical error.
3445 "\context requires function call, found procedure name", Nam
);
3447 if Nkind
(Parent
(N
)) = N_Selected_Component
3448 and then N
= Prefix
(Parent
(N
))
3451 "\period should probably be semicolon", Parent
(N
));
3456 ---------------------------
3457 -- Find_Arithmetic_Types --
3458 ---------------------------
3460 procedure Find_Arithmetic_Types
3465 Index1
, Index2
: Interp_Index
;
3468 procedure Check_Right_Argument
(T
: Entity_Id
);
3469 -- Check right operand of operator
3471 procedure Check_Right_Argument
(T
: Entity_Id
) is
3473 if not Is_Overloaded
(R
) then
3474 Check_Arithmetic_Pair
(T
, Etype
(R
), Op_Id
, N
);
3476 Get_First_Interp
(R
, Index2
, It2
);
3478 while Present
(It2
.Typ
) loop
3479 Check_Arithmetic_Pair
(T
, It2
.Typ
, Op_Id
, N
);
3480 Get_Next_Interp
(Index2
, It2
);
3483 end Check_Right_Argument
;
3485 -- Start processing for Find_Arithmetic_Types
3488 if not Is_Overloaded
(L
) then
3489 Check_Right_Argument
(Etype
(L
));
3492 Get_First_Interp
(L
, Index1
, It1
);
3494 while Present
(It1
.Typ
) loop
3495 Check_Right_Argument
(It1
.Typ
);
3496 Get_Next_Interp
(Index1
, It1
);
3500 end Find_Arithmetic_Types
;
3502 ------------------------
3503 -- Find_Boolean_Types --
3504 ------------------------
3506 procedure Find_Boolean_Types
3511 Index
: Interp_Index
;
3514 procedure Check_Numeric_Argument
(T
: Entity_Id
);
3515 -- Special case for logical operations one of whose operands is an
3516 -- integer literal. If both are literal the result is any modular type.
3518 procedure Check_Numeric_Argument
(T
: Entity_Id
) is
3520 if T
= Universal_Integer
then
3521 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
3523 elsif Is_Modular_Integer_Type
(T
) then
3524 Add_One_Interp
(N
, Op_Id
, T
);
3526 end Check_Numeric_Argument
;
3528 -- Start of processing for Find_Boolean_Types
3531 if not Is_Overloaded
(L
) then
3533 if Etype
(L
) = Universal_Integer
3534 or else Etype
(L
) = Any_Modular
3536 if not Is_Overloaded
(R
) then
3537 Check_Numeric_Argument
(Etype
(R
));
3540 Get_First_Interp
(R
, Index
, It
);
3542 while Present
(It
.Typ
) loop
3543 Check_Numeric_Argument
(It
.Typ
);
3545 Get_Next_Interp
(Index
, It
);
3549 elsif Valid_Boolean_Arg
(Etype
(L
))
3550 and then Has_Compatible_Type
(R
, Etype
(L
))
3552 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
3556 Get_First_Interp
(L
, Index
, It
);
3558 while Present
(It
.Typ
) loop
3559 if Valid_Boolean_Arg
(It
.Typ
)
3560 and then Has_Compatible_Type
(R
, It
.Typ
)
3562 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
3565 Get_Next_Interp
(Index
, It
);
3568 end Find_Boolean_Types
;
3570 ---------------------------
3571 -- Find_Comparison_Types --
3572 ---------------------------
3574 procedure Find_Comparison_Types
3579 Index
: Interp_Index
;
3581 Found
: Boolean := False;
3584 Scop
: Entity_Id
:= Empty
;
3586 procedure Try_One_Interp
(T1
: Entity_Id
);
3587 -- Routine to try one proposed interpretation. Note that the context
3588 -- of the operator plays no role in resolving the arguments, so that
3589 -- if there is more than one interpretation of the operands that is
3590 -- compatible with comparison, the operation is ambiguous.
3592 procedure Try_One_Interp
(T1
: Entity_Id
) is
3595 -- If the operator is an expanded name, then the type of the operand
3596 -- must be defined in the corresponding scope. If the type is
3597 -- universal, the context will impose the correct type.
3600 and then not Defined_In_Scope
(T1
, Scop
)
3601 and then T1
/= Universal_Integer
3602 and then T1
/= Universal_Real
3603 and then T1
/= Any_String
3604 and then T1
/= Any_Composite
3609 if Valid_Comparison_Arg
(T1
)
3610 and then Has_Compatible_Type
(R
, T1
)
3613 and then Base_Type
(T1
) /= Base_Type
(T_F
)
3615 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
3617 if It
= No_Interp
then
3618 Ambiguous_Operands
(N
);
3619 Set_Etype
(L
, Any_Type
);
3633 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
3638 -- Start processing for Find_Comparison_Types
3642 if Nkind
(N
) = N_Function_Call
3643 and then Nkind
(Name
(N
)) = N_Expanded_Name
3645 Scop
:= Entity
(Prefix
(Name
(N
)));
3647 -- The prefix may be a package renaming, and the subsequent test
3648 -- requires the original package.
3650 if Ekind
(Scop
) = E_Package
3651 and then Present
(Renamed_Entity
(Scop
))
3653 Scop
:= Renamed_Entity
(Scop
);
3654 Set_Entity
(Prefix
(Name
(N
)), Scop
);
3658 if not Is_Overloaded
(L
) then
3659 Try_One_Interp
(Etype
(L
));
3662 Get_First_Interp
(L
, Index
, It
);
3664 while Present
(It
.Typ
) loop
3665 Try_One_Interp
(It
.Typ
);
3666 Get_Next_Interp
(Index
, It
);
3669 end Find_Comparison_Types
;
3671 ----------------------------------------
3672 -- Find_Non_Universal_Interpretations --
3673 ----------------------------------------
3675 procedure Find_Non_Universal_Interpretations
3681 Index
: Interp_Index
;
3685 if T1
= Universal_Integer
3686 or else T1
= Universal_Real
3688 if not Is_Overloaded
(R
) then
3690 (N
, Op_Id
, Standard_Boolean
, Base_Type
(Etype
(R
)));
3692 Get_First_Interp
(R
, Index
, It
);
3694 while Present
(It
.Typ
) loop
3695 if Covers
(It
.Typ
, T1
) then
3697 (N
, Op_Id
, Standard_Boolean
, Base_Type
(It
.Typ
));
3700 Get_Next_Interp
(Index
, It
);
3704 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(T1
));
3706 end Find_Non_Universal_Interpretations
;
3708 ------------------------------
3709 -- Find_Concatenation_Types --
3710 ------------------------------
3712 procedure Find_Concatenation_Types
3717 Op_Type
: constant Entity_Id
:= Etype
(Op_Id
);
3720 if Is_Array_Type
(Op_Type
)
3721 and then not Is_Limited_Type
(Op_Type
)
3723 and then (Has_Compatible_Type
(L
, Op_Type
)
3725 Has_Compatible_Type
(L
, Component_Type
(Op_Type
)))
3727 and then (Has_Compatible_Type
(R
, Op_Type
)
3729 Has_Compatible_Type
(R
, Component_Type
(Op_Type
)))
3731 Add_One_Interp
(N
, Op_Id
, Op_Type
);
3733 end Find_Concatenation_Types
;
3735 -------------------------
3736 -- Find_Equality_Types --
3737 -------------------------
3739 procedure Find_Equality_Types
3744 Index
: Interp_Index
;
3746 Found
: Boolean := False;
3749 Scop
: Entity_Id
:= Empty
;
3751 procedure Try_One_Interp
(T1
: Entity_Id
);
3752 -- The context of the operator plays no role in resolving the
3753 -- arguments, so that if there is more than one interpretation
3754 -- of the operands that is compatible with equality, the construct
3755 -- is ambiguous and an error can be emitted now, after trying to
3756 -- disambiguate, i.e. applying preference rules.
3758 procedure Try_One_Interp
(T1
: Entity_Id
) is
3761 -- If the operator is an expanded name, then the type of the operand
3762 -- must be defined in the corresponding scope. If the type is
3763 -- universal, the context will impose the correct type. An anonymous
3764 -- type for a 'Access reference is also universal in this sense, as
3765 -- the actual type is obtained from context.
3768 and then not Defined_In_Scope
(T1
, Scop
)
3769 and then T1
/= Universal_Integer
3770 and then T1
/= Universal_Real
3771 and then T1
/= Any_Access
3772 and then T1
/= Any_String
3773 and then T1
/= Any_Composite
3774 and then (Ekind
(T1
) /= E_Access_Subprogram_Type
3775 or else Comes_From_Source
(T1
))
3780 if T1
/= Standard_Void_Type
3781 and then not Is_Limited_Type
(T1
)
3782 and then not Is_Limited_Composite
(T1
)
3783 and then Ekind
(T1
) /= E_Anonymous_Access_Type
3784 and then Has_Compatible_Type
(R
, T1
)
3787 and then Base_Type
(T1
) /= Base_Type
(T_F
)
3789 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
3791 if It
= No_Interp
then
3792 Ambiguous_Operands
(N
);
3793 Set_Etype
(L
, Any_Type
);
3806 if not Analyzed
(L
) then
3810 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
3812 if Etype
(N
) = Any_Type
then
3814 -- Operator was not visible.
3821 -- Start of processing for Find_Equality_Types
3825 if Nkind
(N
) = N_Function_Call
3826 and then Nkind
(Name
(N
)) = N_Expanded_Name
3828 Scop
:= Entity
(Prefix
(Name
(N
)));
3830 -- The prefix may be a package renaming, and the subsequent test
3831 -- requires the original package.
3833 if Ekind
(Scop
) = E_Package
3834 and then Present
(Renamed_Entity
(Scop
))
3836 Scop
:= Renamed_Entity
(Scop
);
3837 Set_Entity
(Prefix
(Name
(N
)), Scop
);
3841 if not Is_Overloaded
(L
) then
3842 Try_One_Interp
(Etype
(L
));
3845 Get_First_Interp
(L
, Index
, It
);
3847 while Present
(It
.Typ
) loop
3848 Try_One_Interp
(It
.Typ
);
3849 Get_Next_Interp
(Index
, It
);
3852 end Find_Equality_Types
;
3854 -------------------------
3855 -- Find_Negation_Types --
3856 -------------------------
3858 procedure Find_Negation_Types
3863 Index
: Interp_Index
;
3867 if not Is_Overloaded
(R
) then
3869 if Etype
(R
) = Universal_Integer
then
3870 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
3872 elsif Valid_Boolean_Arg
(Etype
(R
)) then
3873 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
3877 Get_First_Interp
(R
, Index
, It
);
3879 while Present
(It
.Typ
) loop
3880 if Valid_Boolean_Arg
(It
.Typ
) then
3881 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
3884 Get_Next_Interp
(Index
, It
);
3887 end Find_Negation_Types
;
3889 ----------------------
3890 -- Find_Unary_Types --
3891 ----------------------
3893 procedure Find_Unary_Types
3898 Index
: Interp_Index
;
3902 if not Is_Overloaded
(R
) then
3903 if Is_Numeric_Type
(Etype
(R
)) then
3904 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(R
)));
3908 Get_First_Interp
(R
, Index
, It
);
3910 while Present
(It
.Typ
) loop
3911 if Is_Numeric_Type
(It
.Typ
) then
3912 Add_One_Interp
(N
, Op_Id
, Base_Type
(It
.Typ
));
3915 Get_Next_Interp
(Index
, It
);
3918 end Find_Unary_Types
;
3920 ---------------------------------
3921 -- Insert_Explicit_Dereference --
3922 ---------------------------------
3924 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
3925 New_Prefix
: Node_Id
:= Relocate_Node
(N
);
3931 Save_Interps
(N
, New_Prefix
);
3933 Make_Explicit_Dereference
(Sloc
(N
), Prefix
=> New_Prefix
));
3935 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
3937 if Is_Overloaded
(New_Prefix
) then
3939 -- The deference is also overloaded, and its interpretations are the
3940 -- designated types of the interpretations of the original node.
3942 Set_Is_Overloaded
(N
);
3943 Get_First_Interp
(New_Prefix
, I
, It
);
3945 while Present
(It
.Nam
) loop
3948 if Is_Access_Type
(T
) then
3949 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
3952 Get_Next_Interp
(I
, It
);
3958 end Insert_Explicit_Dereference
;
3964 function Junk_Operand
(N
: Node_Id
) return Boolean is
3968 if Error_Posted
(N
) then
3972 -- Get entity to be tested
3974 if Is_Entity_Name
(N
)
3975 and then Present
(Entity
(N
))
3979 -- An odd case, a procedure name gets converted to a very peculiar
3980 -- function call, and here is where we detect this happening.
3982 elsif Nkind
(N
) = N_Function_Call
3983 and then Is_Entity_Name
(Name
(N
))
3984 and then Present
(Entity
(Name
(N
)))
3988 -- Another odd case, there are at least some cases of selected
3989 -- components where the selected component is not marked as having
3990 -- an entity, even though the selector does have an entity
3992 elsif Nkind
(N
) = N_Selected_Component
3993 and then Present
(Entity
(Selector_Name
(N
)))
3995 Enode
:= Selector_Name
(N
);
4001 -- Now test the entity we got to see if it a bad case
4003 case Ekind
(Entity
(Enode
)) is
4007 ("package name cannot be used as operand", Enode
);
4009 when Generic_Unit_Kind
=>
4011 ("generic unit name cannot be used as operand", Enode
);
4015 ("subtype name cannot be used as operand", Enode
);
4019 ("entry name cannot be used as operand", Enode
);
4023 ("procedure name cannot be used as operand", Enode
);
4027 ("exception name cannot be used as operand", Enode
);
4029 when E_Block | E_Label | E_Loop
=>
4031 ("label name cannot be used as operand", Enode
);
4041 --------------------
4042 -- Operator_Check --
4043 --------------------
4045 procedure Operator_Check
(N
: Node_Id
) is
4047 -- Test for case of no interpretation found for operator
4049 if Etype
(N
) = Any_Type
then
4055 R
:= Right_Opnd
(N
);
4057 if Nkind
(N
) in N_Binary_Op
then
4063 -- If either operand has no type, then don't complain further,
4064 -- since this simply means that we have a propragated error.
4067 or else Etype
(R
) = Any_Type
4068 or else (Nkind
(N
) in N_Binary_Op
and then Etype
(L
) = Any_Type
)
4072 -- We explicitly check for the case of concatenation of
4073 -- component with component to avoid reporting spurious
4074 -- matching array types that might happen to be lurking
4075 -- in distant packages (such as run-time packages). This
4076 -- also prevents inconsistencies in the messages for certain
4077 -- ACVC B tests, which can vary depending on types declared
4078 -- in run-time interfaces. A further improvement, when
4079 -- aggregates are present, is to look for a well-typed operand.
4081 elsif Present
(Candidate_Type
)
4082 and then (Nkind
(N
) /= N_Op_Concat
4083 or else Is_Array_Type
(Etype
(L
))
4084 or else Is_Array_Type
(Etype
(R
)))
4087 if Nkind
(N
) = N_Op_Concat
then
4088 if Etype
(L
) /= Any_Composite
4089 and then Is_Array_Type
(Etype
(L
))
4091 Candidate_Type
:= Etype
(L
);
4093 elsif Etype
(R
) /= Any_Composite
4094 and then Is_Array_Type
(Etype
(R
))
4096 Candidate_Type
:= Etype
(R
);
4101 ("operator for} is not directly visible!",
4102 N
, First_Subtype
(Candidate_Type
));
4103 Error_Msg_N
("use clause would make operation legal!", N
);
4106 -- If either operand is a junk operand (e.g. package name), then
4107 -- post appropriate error messages, but do not complain further.
4109 -- Note that the use of OR in this test instead of OR ELSE
4110 -- is quite deliberate, we may as well check both operands
4111 -- in the binary operator case.
4113 elsif Junk_Operand
(R
)
4114 or (Nkind
(N
) in N_Binary_Op
and then Junk_Operand
(L
))
4118 -- If we have a logical operator, one of whose operands is
4119 -- Boolean, then we know that the other operand cannot resolve
4120 -- to Boolean (since we got no interpretations), but in that
4121 -- case we pretty much know that the other operand should be
4122 -- Boolean, so resolve it that way (generating an error)
4124 elsif Nkind
(N
) = N_Op_And
4128 Nkind
(N
) = N_Op_Xor
4130 if Etype
(L
) = Standard_Boolean
then
4131 Resolve
(R
, Standard_Boolean
);
4133 elsif Etype
(R
) = Standard_Boolean
then
4134 Resolve
(L
, Standard_Boolean
);
4138 -- For an arithmetic operator or comparison operator, if one
4139 -- of the operands is numeric, then we know the other operand
4140 -- is not the same numeric type. If it is a non-numeric type,
4141 -- then probably it is intended to match the other operand.
4143 elsif Nkind
(N
) = N_Op_Add
or else
4144 Nkind
(N
) = N_Op_Divide
or else
4145 Nkind
(N
) = N_Op_Ge
or else
4146 Nkind
(N
) = N_Op_Gt
or else
4147 Nkind
(N
) = N_Op_Le
or else
4148 Nkind
(N
) = N_Op_Lt
or else
4149 Nkind
(N
) = N_Op_Mod
or else
4150 Nkind
(N
) = N_Op_Multiply
or else
4151 Nkind
(N
) = N_Op_Rem
or else
4152 Nkind
(N
) = N_Op_Subtract
4154 if Is_Numeric_Type
(Etype
(L
))
4155 and then not Is_Numeric_Type
(Etype
(R
))
4157 Resolve
(R
, Etype
(L
));
4160 elsif Is_Numeric_Type
(Etype
(R
))
4161 and then not Is_Numeric_Type
(Etype
(L
))
4163 Resolve
(L
, Etype
(R
));
4167 -- Comparisons on A'Access are common enough to deserve a
4170 elsif (Nkind
(N
) = N_Op_Eq
or else
4171 Nkind
(N
) = N_Op_Ne
)
4172 and then Ekind
(Etype
(L
)) = E_Access_Attribute_Type
4173 and then Ekind
(Etype
(R
)) = E_Access_Attribute_Type
4176 ("two access attributes cannot be compared directly", N
);
4178 ("\they must be converted to an explicit type for comparison",
4182 -- Another one for C programmers
4184 elsif Nkind
(N
) = N_Op_Concat
4185 and then Valid_Boolean_Arg
(Etype
(L
))
4186 and then Valid_Boolean_Arg
(Etype
(R
))
4188 Error_Msg_N
("invalid operands for concatenation", N
);
4189 Error_Msg_N
("\maybe AND was meant", N
);
4192 -- A special case for comparison of access parameter with null
4194 elsif Nkind
(N
) = N_Op_Eq
4195 and then Is_Entity_Name
(L
)
4196 and then Nkind
(Parent
(Entity
(L
))) = N_Parameter_Specification
4197 and then Nkind
(Parameter_Type
(Parent
(Entity
(L
)))) =
4199 and then Nkind
(R
) = N_Null
4201 Error_Msg_N
("access parameter is not allowed to be null", L
);
4202 Error_Msg_N
("\(call would raise Constraint_Error)", L
);
4206 -- If we fall through then just give general message. Note
4207 -- that in the following messages, if the operand is overloaded
4208 -- we choose an arbitrary type to complain about, but that is
4209 -- probably more useful than not giving a type at all.
4211 if Nkind
(N
) in N_Unary_Op
then
4212 Error_Msg_Node_2
:= Etype
(R
);
4213 Error_Msg_N
("operator& not defined for}", N
);
4217 Error_Msg_N
("invalid operand types for operator&", N
);
4219 if Nkind
(N
) in N_Binary_Op
4220 and then Nkind
(N
) /= N_Op_Concat
4222 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
4223 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
4230 -----------------------
4231 -- Try_Indirect_Call --
4232 -----------------------
4234 function Try_Indirect_Call
4240 Actuals
: List_Id
:= Parameter_Associations
(N
);
4241 Actual
: Node_Id
:= First
(Actuals
);
4242 Formal
: Entity_Id
:= First_Formal
(Designated_Type
(Typ
));
4245 while Present
(Actual
)
4246 and then Present
(Formal
)
4248 if not Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
4253 Next_Formal
(Formal
);
4256 if No
(Actual
) and then No
(Formal
) then
4257 Add_One_Interp
(N
, Nam
, Etype
(Designated_Type
(Typ
)));
4259 -- Nam is a candidate interpretation for the name in the call,
4260 -- if it is not an indirect call.
4262 if not Is_Type
(Nam
)
4263 and then Is_Entity_Name
(Name
(N
))
4265 Set_Entity
(Name
(N
), Nam
);
4272 end Try_Indirect_Call
;
4274 ----------------------
4275 -- Try_Indexed_Call --
4276 ----------------------
4278 function Try_Indexed_Call
4284 Actuals
: List_Id
:= Parameter_Associations
(N
);
4285 Actual
: Node_Id
:= First
(Actuals
);
4286 Index
: Entity_Id
:= First_Index
(Typ
);
4289 while Present
(Actual
)
4290 and then Present
(Index
)
4292 -- If the parameter list has a named association, the expression
4293 -- is definitely a call and not an indexed component.
4295 if Nkind
(Actual
) = N_Parameter_Association
then
4299 if not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
4307 if No
(Actual
) and then No
(Index
) then
4308 Add_One_Interp
(N
, Nam
, Component_Type
(Typ
));
4310 -- Nam is a candidate interpretation for the name in the call,
4311 -- if it is not an indirect call.
4313 if not Is_Type
(Nam
)
4314 and then Is_Entity_Name
(Name
(N
))
4316 Set_Entity
(Name
(N
), Nam
);
4324 end Try_Indexed_Call
;