1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Errout
; use Errout
;
32 with Exp_Util
; use Exp_Util
;
33 with Itypes
; use Itypes
;
34 with Lib
.Xref
; use Lib
.Xref
;
35 with Namet
; use Namet
;
36 with Nlists
; use Nlists
;
37 with Nmake
; use Nmake
;
39 with Output
; use Output
;
40 with Restrict
; use Restrict
;
41 with Rident
; use Rident
;
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 Analyze_One_Call
100 Success
: out Boolean);
101 -- Check one interpretation of an overloaded subprogram name for
102 -- compatibility with the types of the actuals in a call. If there is a
103 -- single interpretation which does not match, post error if Report is
106 -- Nam is the entity that provides the formals against which the actuals
107 -- are checked. Nam is either the name of a subprogram, or the internal
108 -- subprogram type constructed for an access_to_subprogram. If the actuals
109 -- are compatible with Nam, then Nam is added to the list of candidate
110 -- interpretations for N, and Success is set to True.
112 procedure Check_Misspelled_Selector
115 -- Give possible misspelling diagnostic if Sel is likely to be
116 -- a misspelling of one of the selectors of the Prefix.
117 -- This is called by Analyze_Selected_Component after producing
118 -- an invalid selector error message.
120 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean;
121 -- Verify that type T is declared in scope S. Used to find intepretations
122 -- for operators given by expanded names. This is abstracted as a separate
123 -- function to handle extensions to System, where S is System, but T is
124 -- declared in the extension.
126 procedure Find_Arithmetic_Types
130 -- L and R are the operands of an arithmetic operator. Find
131 -- consistent pairs of interpretations for L and R that have a
132 -- numeric type consistent with the semantics of the operator.
134 procedure Find_Comparison_Types
138 -- L and R are operands of a comparison operator. Find consistent
139 -- pairs of interpretations for L and R.
141 procedure Find_Concatenation_Types
145 -- For the four varieties of concatenation.
147 procedure Find_Equality_Types
151 -- Ditto for equality operators.
153 procedure Find_Boolean_Types
157 -- Ditto for binary logical operations.
159 procedure Find_Negation_Types
163 -- Find consistent interpretation for operand of negation operator.
165 procedure Find_Non_Universal_Interpretations
170 -- For equality and comparison operators, the result is always boolean,
171 -- and the legality of the operation is determined from the visibility
172 -- of the operand types. If one of the operands has a universal interpre-
173 -- tation, the legality check uses some compatible non-universal
174 -- interpretation of the other operand. N can be an operator node, or
175 -- a function call whose name is an operator designator.
177 procedure Find_Unary_Types
181 -- Unary arithmetic types: plus, minus, abs.
183 procedure Check_Arithmetic_Pair
187 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
188 -- types for left and right operand. Determine whether they constitute
189 -- a valid pair for the given operator, and record the corresponding
190 -- interpretation of the operator node. The node N may be an operator
191 -- node (the usual case) or a function call whose prefix is an operator
192 -- designator. In both cases Op_Id is the operator name itself.
194 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
);
195 -- Give detailed information on overloaded call where none of the
196 -- interpretations match. N is the call node, Nam the designator for
197 -- the overloaded entity being called.
199 function Junk_Operand
(N
: Node_Id
) return Boolean;
200 -- Test for an operand that is an inappropriate entity (e.g. a package
201 -- name or a label). If so, issue an error message and return True. If
202 -- the operand is not an inappropriate entity kind, return False.
204 procedure Operator_Check
(N
: Node_Id
);
205 -- Verify that an operator has received some valid interpretation.
206 -- If none was found, determine whether a use clause would make the
207 -- operation legal. The variable Candidate_Type (defined in Sem_Type) is
208 -- set for every type compatible with the operator, even if the operator
209 -- for the type is not directly visible. The routine uses this type to emit
210 -- a more informative message.
212 procedure Remove_Abstract_Operations
(N
: Node_Id
);
213 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
214 -- operation is not a candidate interpretation.
216 function Try_Indexed_Call
219 Typ
: Entity_Id
) return Boolean;
220 -- If a function has defaults for all its actuals, a call to it may
221 -- in fact be an indexing on the result of the call. Try_Indexed_Call
222 -- attempts the interpretation as an indexing, prior to analysis as
223 -- a call. If both are possible, the node is overloaded with both
224 -- interpretations (same symbol but two different types).
226 function Try_Indirect_Call
229 Typ
: Entity_Id
) return Boolean;
230 -- Similarly, a function F that needs no actuals can return an access
231 -- to a subprogram, and the call F (X) interpreted as F.all (X). In
232 -- this case the call may be overloaded with both interpretations.
234 ------------------------
235 -- Ambiguous_Operands --
236 ------------------------
238 procedure Ambiguous_Operands
(N
: Node_Id
) is
239 procedure List_Operand_Interps
(Opnd
: Node_Id
);
241 procedure List_Operand_Interps
(Opnd
: Node_Id
) is
246 if Is_Overloaded
(Opnd
) then
247 if Nkind
(Opnd
) in N_Op
then
250 elsif Nkind
(Opnd
) = N_Function_Call
then
261 if Opnd
= Left_Opnd
(N
) then
263 ("\left operand has the following interpretations", N
);
266 ("\right operand has the following interpretations", N
);
270 List_Interps
(Nam
, Err
);
271 end List_Operand_Interps
;
275 or else Nkind
(N
) = N_Not_In
277 Error_Msg_N
("ambiguous operands for membership", N
);
279 elsif Nkind
(N
) = N_Op_Eq
280 or else Nkind
(N
) = N_Op_Ne
282 Error_Msg_N
("ambiguous operands for equality", N
);
285 Error_Msg_N
("ambiguous operands for comparison", N
);
288 if All_Errors_Mode
then
289 List_Operand_Interps
(Left_Opnd
(N
));
290 List_Operand_Interps
(Right_Opnd
(N
));
292 Error_Msg_N
("\use -gnatf switch for details", N
);
294 end Ambiguous_Operands
;
296 -----------------------
297 -- Analyze_Aggregate --
298 -----------------------
300 -- Most of the analysis of Aggregates requires that the type be known,
301 -- and is therefore put off until resolution.
303 procedure Analyze_Aggregate
(N
: Node_Id
) is
305 if No
(Etype
(N
)) then
306 Set_Etype
(N
, Any_Composite
);
308 end Analyze_Aggregate
;
310 -----------------------
311 -- Analyze_Allocator --
312 -----------------------
314 procedure Analyze_Allocator
(N
: Node_Id
) is
315 Loc
: constant Source_Ptr
:= Sloc
(N
);
316 Sav_Errs
: constant Nat
:= Serious_Errors_Detected
;
317 E
: Node_Id
:= Expression
(N
);
318 Acc_Type
: Entity_Id
;
322 Check_Restriction
(No_Allocators
, N
);
324 if Nkind
(E
) = N_Qualified_Expression
then
325 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
326 Set_Etype
(Acc_Type
, Acc_Type
);
327 Init_Size_Align
(Acc_Type
);
328 Find_Type
(Subtype_Mark
(E
));
329 Type_Id
:= Entity
(Subtype_Mark
(E
));
330 Check_Fully_Declared
(Type_Id
, N
);
331 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
333 if Is_Limited_Type
(Type_Id
)
334 and then Comes_From_Source
(N
)
335 and then not In_Instance_Body
337 -- Ada 0Y (AI-287): Do not post an error if the expression
338 -- corresponds to a limited aggregate. Limited aggregates
339 -- are checked in sem_aggr in a per-component manner
340 -- (compare with handling of Get_Value subprogram).
342 if Extensions_Allowed
343 and then Nkind
(Expression
(E
)) = N_Aggregate
347 Error_Msg_N
("initialization not allowed for limited types", N
);
348 Explain_Limited_Type
(Type_Id
, N
);
352 Analyze_And_Resolve
(Expression
(E
), Type_Id
);
354 -- A qualified expression requires an exact match of the type,
355 -- class-wide matching is not allowed.
357 if Is_Class_Wide_Type
(Type_Id
)
358 and then Base_Type
(Etype
(Expression
(E
))) /= Base_Type
(Type_Id
)
360 Wrong_Type
(Expression
(E
), Type_Id
);
363 Check_Non_Static_Context
(Expression
(E
));
365 -- We don't analyze the qualified expression itself because it's
366 -- part of the allocator
368 Set_Etype
(E
, Type_Id
);
375 -- If the allocator includes a N_Subtype_Indication then a
376 -- constraint is present, otherwise the node is a subtype mark.
377 -- Introduce an explicit subtype declaration into the tree
378 -- defining some anonymous subtype and rewrite the allocator to
379 -- use this subtype rather than the subtype indication.
381 -- It is important to introduce the explicit subtype declaration
382 -- so that the bounds of the subtype indication are attached to
383 -- the tree in case the allocator is inside a generic unit.
385 if Nkind
(E
) = N_Subtype_Indication
then
387 -- A constraint is only allowed for a composite type in Ada
388 -- 95. In Ada 83, a constraint is also allowed for an
389 -- access-to-composite type, but the constraint is ignored.
391 Find_Type
(Subtype_Mark
(E
));
393 if Is_Elementary_Type
(Entity
(Subtype_Mark
(E
))) then
395 and then Is_Access_Type
(Entity
(Subtype_Mark
(E
))))
397 Error_Msg_N
("constraint not allowed here", E
);
399 if Nkind
(Constraint
(E
))
400 = N_Index_Or_Discriminant_Constraint
403 ("\if qualified expression was meant, " &
404 "use apostrophe", Constraint
(E
));
408 -- Get rid of the bogus constraint:
410 Rewrite
(E
, New_Copy_Tree
(Subtype_Mark
(E
)));
411 Analyze_Allocator
(N
);
415 if Expander_Active
then
417 Make_Defining_Identifier
(Loc
, New_Internal_Name
('S'));
420 Make_Subtype_Declaration
(Loc
,
421 Defining_Identifier
=> Def_Id
,
422 Subtype_Indication
=> Relocate_Node
(E
)));
424 if Sav_Errs
/= Serious_Errors_Detected
425 and then Nkind
(Constraint
(E
))
426 = N_Index_Or_Discriminant_Constraint
429 ("if qualified expression was meant, " &
430 "use apostrophe!", Constraint
(E
));
433 E
:= New_Occurrence_Of
(Def_Id
, Loc
);
434 Rewrite
(Expression
(N
), E
);
438 Type_Id
:= Process_Subtype
(E
, N
);
439 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
440 Set_Etype
(Acc_Type
, Acc_Type
);
441 Init_Size_Align
(Acc_Type
);
442 Set_Directly_Designated_Type
(Acc_Type
, Type_Id
);
443 Check_Fully_Declared
(Type_Id
, N
);
447 if Can_Never_Be_Null
(Type_Id
) then
448 Error_Msg_N
("(Ada 0Y) qualified expression required",
452 -- Check restriction against dynamically allocated protected
453 -- objects. Note that when limited aggregates are supported,
454 -- a similar test should be applied to an allocator with a
455 -- qualified expression ???
457 if Is_Protected_Type
(Type_Id
) then
458 Check_Restriction
(No_Protected_Type_Allocators
, N
);
461 -- Check for missing initialization. Skip this check if we already
462 -- had errors on analyzing the allocator, since in that case these
463 -- are probably cascaded errors
465 if Is_Indefinite_Subtype
(Type_Id
)
466 and then Serious_Errors_Detected
= Sav_Errs
468 if Is_Class_Wide_Type
(Type_Id
) then
470 ("initialization required in class-wide allocation", N
);
473 ("initialization required in unconstrained allocation", N
);
479 if Is_Abstract
(Type_Id
) then
480 Error_Msg_N
("cannot allocate abstract object", E
);
483 if Has_Task
(Designated_Type
(Acc_Type
)) then
484 Check_Restriction
(No_Tasking
, N
);
485 Check_Restriction
(Max_Tasks
, N
);
486 Check_Restriction
(No_Task_Allocators
, N
);
489 Set_Etype
(N
, Acc_Type
);
491 if not Is_Library_Level_Entity
(Acc_Type
) then
492 Check_Restriction
(No_Local_Allocators
, N
);
495 -- Ada 0Y (AI-231): Static checks
497 if Extensions_Allowed
498 and then (Null_Exclusion_Present
(N
)
499 or else Can_Never_Be_Null
(Etype
(N
)))
501 Null_Exclusion_Static_Checks
(N
);
504 if Serious_Errors_Detected
> Sav_Errs
then
505 Set_Error_Posted
(N
);
506 Set_Etype
(N
, Any_Type
);
508 end Analyze_Allocator
;
510 ---------------------------
511 -- Analyze_Arithmetic_Op --
512 ---------------------------
514 procedure Analyze_Arithmetic_Op
(N
: Node_Id
) is
515 L
: constant Node_Id
:= Left_Opnd
(N
);
516 R
: constant Node_Id
:= Right_Opnd
(N
);
520 Candidate_Type
:= Empty
;
521 Analyze_Expression
(L
);
522 Analyze_Expression
(R
);
524 -- If the entity is already set, the node is the instantiation of
525 -- a generic node with a non-local reference, or was manufactured
526 -- by a call to Make_Op_xxx. In either case the entity is known to
527 -- be valid, and we do not need to collect interpretations, instead
528 -- we just get the single possible interpretation.
532 if Present
(Op_Id
) then
533 if Ekind
(Op_Id
) = E_Operator
then
535 if (Nkind
(N
) = N_Op_Divide
or else
536 Nkind
(N
) = N_Op_Mod
or else
537 Nkind
(N
) = N_Op_Multiply
or else
538 Nkind
(N
) = N_Op_Rem
)
539 and then Treat_Fixed_As_Integer
(N
)
543 Set_Etype
(N
, Any_Type
);
544 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
548 Set_Etype
(N
, Any_Type
);
549 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
552 -- Entity is not already set, so we do need to collect interpretations
555 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
556 Set_Etype
(N
, Any_Type
);
558 while Present
(Op_Id
) loop
559 if Ekind
(Op_Id
) = E_Operator
560 and then Present
(Next_Entity
(First_Entity
(Op_Id
)))
562 Find_Arithmetic_Types
(L
, R
, Op_Id
, N
);
564 -- The following may seem superfluous, because an operator cannot
565 -- be generic, but this ignores the cleverness of the author of
568 elsif Is_Overloadable
(Op_Id
) then
569 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
572 Op_Id
:= Homonym
(Op_Id
);
577 end Analyze_Arithmetic_Op
;
583 -- Function, procedure, and entry calls are checked here. The Name
584 -- in the call may be overloaded. The actuals have been analyzed
585 -- and may themselves be overloaded. On exit from this procedure, the node
586 -- N may have zero, one or more interpretations. In the first case an error
587 -- message is produced. In the last case, the node is flagged as overloaded
588 -- and the interpretations are collected in All_Interp.
590 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
591 -- the type-checking is similar to that of other calls.
593 procedure Analyze_Call
(N
: Node_Id
) is
594 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
595 Nam
: Node_Id
:= Name
(N
);
599 Success
: Boolean := False;
601 function Name_Denotes_Function
return Boolean;
602 -- If the type of the name is an access to subprogram, this may be
603 -- the type of a name, or the return type of the function being called.
604 -- If the name is not an entity then it can denote a protected function.
605 -- Until we distinguish Etype from Return_Type, we must use this
606 -- routine to resolve the meaning of the name in the call.
608 ---------------------------
609 -- Name_Denotes_Function --
610 ---------------------------
612 function Name_Denotes_Function
return Boolean is
614 if Is_Entity_Name
(Nam
) then
615 return Ekind
(Entity
(Nam
)) = E_Function
;
617 elsif Nkind
(Nam
) = N_Selected_Component
then
618 return Ekind
(Entity
(Selector_Name
(Nam
))) = E_Function
;
623 end Name_Denotes_Function
;
625 -- Start of processing for Analyze_Call
628 -- Initialize the type of the result of the call to the error type,
629 -- which will be reset if the type is successfully resolved.
631 Set_Etype
(N
, Any_Type
);
633 if not Is_Overloaded
(Nam
) then
635 -- Only one interpretation to check
637 if Ekind
(Etype
(Nam
)) = E_Subprogram_Type
then
638 Nam_Ent
:= Etype
(Nam
);
640 elsif Is_Access_Type
(Etype
(Nam
))
641 and then Ekind
(Designated_Type
(Etype
(Nam
))) = E_Subprogram_Type
642 and then not Name_Denotes_Function
644 Nam_Ent
:= Designated_Type
(Etype
(Nam
));
645 Insert_Explicit_Dereference
(Nam
);
647 -- Selected component case. Simple entry or protected operation,
648 -- where the entry name is given by the selector name.
650 elsif Nkind
(Nam
) = N_Selected_Component
then
651 Nam_Ent
:= Entity
(Selector_Name
(Nam
));
653 if Ekind
(Nam_Ent
) /= E_Entry
654 and then Ekind
(Nam_Ent
) /= E_Entry_Family
655 and then Ekind
(Nam_Ent
) /= E_Function
656 and then Ekind
(Nam_Ent
) /= E_Procedure
658 Error_Msg_N
("name in call is not a callable entity", Nam
);
659 Set_Etype
(N
, Any_Type
);
663 -- If the name is an Indexed component, it can be a call to a member
664 -- of an entry family. The prefix must be a selected component whose
665 -- selector is the entry. Analyze_Procedure_Call normalizes several
666 -- kinds of call into this form.
668 elsif Nkind
(Nam
) = N_Indexed_Component
then
670 if Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
671 Nam_Ent
:= Entity
(Selector_Name
(Prefix
(Nam
)));
674 Error_Msg_N
("name in call is not a callable entity", Nam
);
675 Set_Etype
(N
, Any_Type
);
680 elsif not Is_Entity_Name
(Nam
) then
681 Error_Msg_N
("name in call is not a callable entity", Nam
);
682 Set_Etype
(N
, Any_Type
);
686 Nam_Ent
:= Entity
(Nam
);
688 -- If no interpretations, give error message
690 if not Is_Overloadable
(Nam_Ent
) then
692 L
: constant Boolean := Is_List_Member
(N
);
693 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
696 -- If the node is in a list whose parent is not an
697 -- expression then it must be an attempted procedure call.
699 if L
and then K
not in N_Subexpr
then
700 if Ekind
(Entity
(Nam
)) = E_Generic_Procedure
then
702 ("must instantiate generic procedure& before call",
706 ("procedure or entry name expected", Nam
);
709 -- Check for tasking cases where only an entry call will do
712 and then (K
= N_Entry_Call_Alternative
713 or else K
= N_Triggering_Alternative
)
715 Error_Msg_N
("entry name expected", Nam
);
717 -- Otherwise give general error message
720 Error_Msg_N
("invalid prefix in call", Nam
);
728 Analyze_One_Call
(N
, Nam_Ent
, True, Success
);
731 -- An overloaded selected component must denote overloaded
732 -- operations of a concurrent type. The interpretations are
733 -- attached to the simple name of those operations.
735 if Nkind
(Nam
) = N_Selected_Component
then
736 Nam
:= Selector_Name
(Nam
);
739 Get_First_Interp
(Nam
, X
, It
);
741 while Present
(It
.Nam
) loop
744 -- Name may be call that returns an access to subprogram, or more
745 -- generally an overloaded expression one of whose interpretations
746 -- yields an access to subprogram. If the name is an entity, we
747 -- do not dereference, because the node is a call that returns
748 -- the access type: note difference between f(x), where the call
749 -- may return an access subprogram type, and f(x)(y), where the
750 -- type returned by the call to f is implicitly dereferenced to
751 -- analyze the outer call.
753 if Is_Access_Type
(Nam_Ent
) then
754 Nam_Ent
:= Designated_Type
(Nam_Ent
);
756 elsif Is_Access_Type
(Etype
(Nam_Ent
))
757 and then not Is_Entity_Name
(Nam
)
758 and then Ekind
(Designated_Type
(Etype
(Nam_Ent
)))
761 Nam_Ent
:= Designated_Type
(Etype
(Nam_Ent
));
764 Analyze_One_Call
(N
, Nam_Ent
, False, Success
);
766 -- If the interpretation succeeds, mark the proper type of the
767 -- prefix (any valid candidate will do). If not, remove the
768 -- candidate interpretation. This only needs to be done for
769 -- overloaded protected operations, for other entities disambi-
770 -- guation is done directly in Resolve.
773 Set_Etype
(Nam
, It
.Typ
);
775 elsif Nkind
(Name
(N
)) = N_Selected_Component
776 or else Nkind
(Name
(N
)) = N_Function_Call
781 Get_Next_Interp
(X
, It
);
784 -- If the name is the result of a function call, it can only
785 -- be a call to a function returning an access to subprogram.
786 -- Insert explicit dereference.
788 if Nkind
(Nam
) = N_Function_Call
then
789 Insert_Explicit_Dereference
(Nam
);
792 if Etype
(N
) = Any_Type
then
794 -- None of the interpretations is compatible with the actuals
796 Diagnose_Call
(N
, Nam
);
798 -- Special checks for uninstantiated put routines
800 if Nkind
(N
) = N_Procedure_Call_Statement
801 and then Is_Entity_Name
(Nam
)
802 and then Chars
(Nam
) = Name_Put
803 and then List_Length
(Actuals
) = 1
806 Arg
: constant Node_Id
:= First
(Actuals
);
810 if Nkind
(Arg
) = N_Parameter_Association
then
811 Typ
:= Etype
(Explicit_Actual_Parameter
(Arg
));
816 if Is_Signed_Integer_Type
(Typ
) then
818 ("possible missing instantiation of " &
819 "'Text_'I'O.'Integer_'I'O!", Nam
);
821 elsif Is_Modular_Integer_Type
(Typ
) then
823 ("possible missing instantiation of " &
824 "'Text_'I'O.'Modular_'I'O!", Nam
);
826 elsif Is_Floating_Point_Type
(Typ
) then
828 ("possible missing instantiation of " &
829 "'Text_'I'O.'Float_'I'O!", Nam
);
831 elsif Is_Ordinary_Fixed_Point_Type
(Typ
) then
833 ("possible missing instantiation of " &
834 "'Text_'I'O.'Fixed_'I'O!", Nam
);
836 elsif Is_Decimal_Fixed_Point_Type
(Typ
) then
838 ("possible missing instantiation of " &
839 "'Text_'I'O.'Decimal_'I'O!", Nam
);
841 elsif Is_Enumeration_Type
(Typ
) then
843 ("possible missing instantiation of " &
844 "'Text_'I'O.'Enumeration_'I'O!", Nam
);
849 elsif not Is_Overloaded
(N
)
850 and then Is_Entity_Name
(Nam
)
852 -- Resolution yields a single interpretation. Verify that
853 -- is has the proper capitalization.
855 Set_Entity_With_Style_Check
(Nam
, Entity
(Nam
));
856 Generate_Reference
(Entity
(Nam
), Nam
);
858 Set_Etype
(Nam
, Etype
(Entity
(Nam
)));
860 Remove_Abstract_Operations
(N
);
867 ---------------------------
868 -- Analyze_Comparison_Op --
869 ---------------------------
871 procedure Analyze_Comparison_Op
(N
: Node_Id
) is
872 L
: constant Node_Id
:= Left_Opnd
(N
);
873 R
: constant Node_Id
:= Right_Opnd
(N
);
874 Op_Id
: Entity_Id
:= Entity
(N
);
877 Set_Etype
(N
, Any_Type
);
878 Candidate_Type
:= Empty
;
880 Analyze_Expression
(L
);
881 Analyze_Expression
(R
);
883 if Present
(Op_Id
) then
885 if Ekind
(Op_Id
) = E_Operator
then
886 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
888 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
891 if Is_Overloaded
(L
) then
892 Set_Etype
(L
, Intersect_Types
(L
, R
));
896 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
898 while Present
(Op_Id
) loop
900 if Ekind
(Op_Id
) = E_Operator
then
901 Find_Comparison_Types
(L
, R
, Op_Id
, N
);
903 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
906 Op_Id
:= Homonym
(Op_Id
);
911 end Analyze_Comparison_Op
;
913 ---------------------------
914 -- Analyze_Concatenation --
915 ---------------------------
917 -- If the only one-dimensional array type in scope is String,
918 -- this is the resulting type of the operation. Otherwise there
919 -- will be a concatenation operation defined for each user-defined
920 -- one-dimensional array.
922 procedure Analyze_Concatenation
(N
: Node_Id
) is
923 L
: constant Node_Id
:= Left_Opnd
(N
);
924 R
: constant Node_Id
:= Right_Opnd
(N
);
925 Op_Id
: Entity_Id
:= Entity
(N
);
930 Set_Etype
(N
, Any_Type
);
931 Candidate_Type
:= Empty
;
933 Analyze_Expression
(L
);
934 Analyze_Expression
(R
);
936 -- If the entity is present, the node appears in an instance,
937 -- and denotes a predefined concatenation operation. The resulting
938 -- type is obtained from the arguments when possible. If the arguments
939 -- are aggregates, the array type and the concatenation type must be
942 if Present
(Op_Id
) then
943 if Ekind
(Op_Id
) = E_Operator
then
945 LT
:= Base_Type
(Etype
(L
));
946 RT
:= Base_Type
(Etype
(R
));
948 if Is_Array_Type
(LT
)
949 and then (RT
= LT
or else RT
= Base_Type
(Component_Type
(LT
)))
951 Add_One_Interp
(N
, Op_Id
, LT
);
953 elsif Is_Array_Type
(RT
)
954 and then LT
= Base_Type
(Component_Type
(RT
))
956 Add_One_Interp
(N
, Op_Id
, RT
);
958 -- If one operand is a string type or a user-defined array type,
959 -- and the other is a literal, result is of the specific type.
962 (Root_Type
(LT
) = Standard_String
963 or else Scope
(LT
) /= Standard_Standard
)
964 and then Etype
(R
) = Any_String
966 Add_One_Interp
(N
, Op_Id
, LT
);
969 (Root_Type
(RT
) = Standard_String
970 or else Scope
(RT
) /= Standard_Standard
)
971 and then Etype
(L
) = Any_String
973 Add_One_Interp
(N
, Op_Id
, RT
);
975 elsif not Is_Generic_Type
(Etype
(Op_Id
)) then
976 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
979 -- Type and its operations must be visible.
981 Set_Entity
(N
, Empty
);
982 Analyze_Concatenation
(N
);
987 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
991 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Concat
);
993 while Present
(Op_Id
) loop
994 if Ekind
(Op_Id
) = E_Operator
then
995 Find_Concatenation_Types
(L
, R
, Op_Id
, N
);
997 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1000 Op_Id
:= Homonym
(Op_Id
);
1005 end Analyze_Concatenation
;
1007 ------------------------------------
1008 -- Analyze_Conditional_Expression --
1009 ------------------------------------
1011 procedure Analyze_Conditional_Expression
(N
: Node_Id
) is
1012 Condition
: constant Node_Id
:= First
(Expressions
(N
));
1013 Then_Expr
: constant Node_Id
:= Next
(Condition
);
1014 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
1017 Analyze_Expression
(Condition
);
1018 Analyze_Expression
(Then_Expr
);
1019 Analyze_Expression
(Else_Expr
);
1020 Set_Etype
(N
, Etype
(Then_Expr
));
1021 end Analyze_Conditional_Expression
;
1023 -------------------------
1024 -- Analyze_Equality_Op --
1025 -------------------------
1027 procedure Analyze_Equality_Op
(N
: Node_Id
) is
1028 Loc
: constant Source_Ptr
:= Sloc
(N
);
1029 L
: constant Node_Id
:= Left_Opnd
(N
);
1030 R
: constant Node_Id
:= Right_Opnd
(N
);
1034 Set_Etype
(N
, Any_Type
);
1035 Candidate_Type
:= Empty
;
1037 Analyze_Expression
(L
);
1038 Analyze_Expression
(R
);
1040 -- If the entity is set, the node is a generic instance with a non-local
1041 -- reference to the predefined operator or to a user-defined function.
1042 -- It can also be an inequality that is expanded into the negation of a
1043 -- call to a user-defined equality operator.
1045 -- For the predefined case, the result is Boolean, regardless of the
1046 -- type of the operands. The operands may even be limited, if they are
1047 -- generic actuals. If they are overloaded, label the left argument with
1048 -- the common type that must be present, or with the type of the formal
1049 -- of the user-defined function.
1051 if Present
(Entity
(N
)) then
1053 Op_Id
:= Entity
(N
);
1055 if Ekind
(Op_Id
) = E_Operator
then
1056 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
);
1058 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1061 if Is_Overloaded
(L
) then
1063 if Ekind
(Op_Id
) = E_Operator
then
1064 Set_Etype
(L
, Intersect_Types
(L
, R
));
1066 Set_Etype
(L
, Etype
(First_Formal
(Op_Id
)));
1071 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1073 while Present
(Op_Id
) loop
1075 if Ekind
(Op_Id
) = E_Operator
then
1076 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1078 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1081 Op_Id
:= Homonym
(Op_Id
);
1085 -- If there was no match, and the operator is inequality, this may
1086 -- be a case where inequality has not been made explicit, as for
1087 -- tagged types. Analyze the node as the negation of an equality
1088 -- operation. This cannot be done earlier, because before analysis
1089 -- we cannot rule out the presence of an explicit inequality.
1091 if Etype
(N
) = Any_Type
1092 and then Nkind
(N
) = N_Op_Ne
1094 Op_Id
:= Get_Name_Entity_Id
(Name_Op_Eq
);
1096 while Present
(Op_Id
) loop
1098 if Ekind
(Op_Id
) = E_Operator
then
1099 Find_Equality_Types
(L
, R
, Op_Id
, N
);
1101 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1104 Op_Id
:= Homonym
(Op_Id
);
1107 if Etype
(N
) /= Any_Type
then
1108 Op_Id
:= Entity
(N
);
1114 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
1115 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
)))));
1117 Set_Entity
(Right_Opnd
(N
), Op_Id
);
1123 end Analyze_Equality_Op
;
1125 ----------------------------------
1126 -- Analyze_Explicit_Dereference --
1127 ----------------------------------
1129 procedure Analyze_Explicit_Dereference
(N
: Node_Id
) is
1130 Loc
: constant Source_Ptr
:= Sloc
(N
);
1131 P
: constant Node_Id
:= Prefix
(N
);
1137 function Is_Function_Type
return Boolean;
1138 -- Check whether node may be interpreted as an implicit function call.
1140 function Is_Function_Type
return Boolean is
1145 if not Is_Overloaded
(N
) then
1146 return Ekind
(Base_Type
(Etype
(N
))) = E_Subprogram_Type
1147 and then Etype
(Base_Type
(Etype
(N
))) /= Standard_Void_Type
;
1150 Get_First_Interp
(N
, I
, It
);
1152 while Present
(It
.Nam
) loop
1153 if Ekind
(Base_Type
(It
.Typ
)) /= E_Subprogram_Type
1154 or else Etype
(Base_Type
(It
.Typ
)) = Standard_Void_Type
1159 Get_Next_Interp
(I
, It
);
1164 end Is_Function_Type
;
1168 Set_Etype
(N
, Any_Type
);
1170 -- Test for remote access to subprogram type, and if so return
1171 -- after rewriting the original tree.
1173 if Remote_AST_E_Dereference
(P
) then
1177 -- Normal processing for other than remote access to subprogram type
1179 if not Is_Overloaded
(P
) then
1180 if Is_Access_Type
(Etype
(P
)) then
1182 -- Set the Etype. We need to go thru Is_For_Access_Subtypes
1183 -- to avoid other problems caused by the Private_Subtype
1184 -- and it is safe to go to the Base_Type because this is the
1185 -- same as converting the access value to its Base_Type.
1188 DT
: Entity_Id
:= Designated_Type
(Etype
(P
));
1191 if Ekind
(DT
) = E_Private_Subtype
1192 and then Is_For_Access_Subtype
(DT
)
1194 DT
:= Base_Type
(DT
);
1200 elsif Etype
(P
) /= Any_Type
then
1201 Error_Msg_N
("prefix of dereference must be an access type", N
);
1206 Get_First_Interp
(P
, I
, It
);
1208 while Present
(It
.Nam
) loop
1211 if Is_Access_Type
(T
) then
1212 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
1215 Get_Next_Interp
(I
, It
);
1220 -- Error if no interpretation of the prefix has an access type.
1222 if Etype
(N
) = Any_Type
then
1224 ("access type required in prefix of explicit dereference", P
);
1225 Set_Etype
(N
, Any_Type
);
1231 and then Nkind
(Parent
(N
)) /= N_Indexed_Component
1233 and then (Nkind
(Parent
(N
)) /= N_Function_Call
1234 or else N
/= Name
(Parent
(N
)))
1236 and then (Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1237 or else N
/= Name
(Parent
(N
)))
1239 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
1240 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
1242 (Attribute_Name
(Parent
(N
)) /= Name_Address
1244 Attribute_Name
(Parent
(N
)) /= Name_Access
))
1246 -- Name is a function call with no actuals, in a context that
1247 -- requires deproceduring (including as an actual in an enclosing
1248 -- function or procedure call). We can conceive of pathological cases
1249 -- where the prefix might include functions that return access to
1250 -- subprograms and others that return a regular type. Disambiguation
1251 -- of those will have to take place in Resolve. See e.g. 7117-014.
1254 Make_Function_Call
(Loc
,
1255 Name
=> Make_Explicit_Dereference
(Loc
, P
),
1256 Parameter_Associations
=> New_List
);
1258 -- If the prefix is overloaded, remove operations that have formals,
1259 -- we know that this is a parameterless call.
1261 if Is_Overloaded
(P
) then
1262 Get_First_Interp
(P
, I
, It
);
1264 while Present
(It
.Nam
) loop
1267 if No
(First_Formal
(Base_Type
(Designated_Type
(T
)))) then
1273 Get_Next_Interp
(I
, It
);
1281 -- A value of remote access-to-class-wide must not be dereferenced
1284 Validate_Remote_Access_To_Class_Wide_Type
(N
);
1286 end Analyze_Explicit_Dereference
;
1288 ------------------------
1289 -- Analyze_Expression --
1290 ------------------------
1292 procedure Analyze_Expression
(N
: Node_Id
) is
1295 Check_Parameterless_Call
(N
);
1296 end Analyze_Expression
;
1298 ------------------------------------
1299 -- Analyze_Indexed_Component_Form --
1300 ------------------------------------
1302 procedure Analyze_Indexed_Component_Form
(N
: Node_Id
) is
1303 P
: constant Node_Id
:= Prefix
(N
);
1304 Exprs
: constant List_Id
:= Expressions
(N
);
1310 procedure Process_Function_Call
;
1311 -- Prefix in indexed component form is an overloadable entity,
1312 -- so the node is a function call. Reformat it as such.
1314 procedure Process_Indexed_Component
;
1315 -- Prefix in indexed component form is actually an indexed component.
1316 -- This routine processes it, knowing that the prefix is already
1319 procedure Process_Indexed_Component_Or_Slice
;
1320 -- An indexed component with a single index may designate a slice if
1321 -- the index is a subtype mark. This routine disambiguates these two
1322 -- cases by resolving the prefix to see if it is a subtype mark.
1324 procedure Process_Overloaded_Indexed_Component
;
1325 -- If the prefix of an indexed component is overloaded, the proper
1326 -- interpretation is selected by the index types and the context.
1328 ---------------------------
1329 -- Process_Function_Call --
1330 ---------------------------
1332 procedure Process_Function_Call
is
1336 Change_Node
(N
, N_Function_Call
);
1338 Set_Parameter_Associations
(N
, Exprs
);
1339 Actual
:= First
(Parameter_Associations
(N
));
1341 while Present
(Actual
) loop
1343 Check_Parameterless_Call
(Actual
);
1344 Next_Actual
(Actual
);
1348 end Process_Function_Call
;
1350 -------------------------------
1351 -- Process_Indexed_Component --
1352 -------------------------------
1354 procedure Process_Indexed_Component
is
1356 Array_Type
: Entity_Id
;
1358 Entry_Family
: Entity_Id
;
1361 Exp
:= First
(Exprs
);
1363 if Is_Overloaded
(P
) then
1364 Process_Overloaded_Indexed_Component
;
1367 Array_Type
:= Etype
(P
);
1369 -- Prefix must be appropriate for an array type.
1370 -- Dereference the prefix if it is an access type.
1372 if Is_Access_Type
(Array_Type
) then
1373 Array_Type
:= Designated_Type
(Array_Type
);
1374 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
1377 if Is_Array_Type
(Array_Type
) then
1380 elsif (Is_Entity_Name
(P
)
1382 Ekind
(Entity
(P
)) = E_Entry_Family
)
1384 (Nkind
(P
) = N_Selected_Component
1386 Is_Entity_Name
(Selector_Name
(P
))
1388 Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
)
1390 if Is_Entity_Name
(P
) then
1391 Entry_Family
:= Entity
(P
);
1393 Entry_Family
:= Entity
(Selector_Name
(P
));
1397 Set_Etype
(N
, Any_Type
);
1399 if not Has_Compatible_Type
1400 (Exp
, Entry_Index_Type
(Entry_Family
))
1402 Error_Msg_N
("invalid index type in entry name", N
);
1404 elsif Present
(Next
(Exp
)) then
1405 Error_Msg_N
("too many subscripts in entry reference", N
);
1408 Set_Etype
(N
, Etype
(P
));
1413 elsif Is_Record_Type
(Array_Type
)
1414 and then Remote_AST_I_Dereference
(P
)
1418 elsif Array_Type
= Any_Type
then
1419 Set_Etype
(N
, Any_Type
);
1422 -- Here we definitely have a bad indexing
1425 if Nkind
(Parent
(N
)) = N_Requeue_Statement
1427 ((Is_Entity_Name
(P
)
1428 and then Ekind
(Entity
(P
)) = E_Entry
)
1430 (Nkind
(P
) = N_Selected_Component
1431 and then Is_Entity_Name
(Selector_Name
(P
))
1432 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
))
1435 ("REQUEUE does not permit parameters", First
(Exprs
));
1437 elsif Is_Entity_Name
(P
)
1438 and then Etype
(P
) = Standard_Void_Type
1440 Error_Msg_NE
("incorrect use of&", P
, Entity
(P
));
1443 Error_Msg_N
("array type required in indexed component", P
);
1446 Set_Etype
(N
, Any_Type
);
1450 Index
:= First_Index
(Array_Type
);
1452 while Present
(Index
) and then Present
(Exp
) loop
1453 if not Has_Compatible_Type
(Exp
, Etype
(Index
)) then
1454 Wrong_Type
(Exp
, Etype
(Index
));
1455 Set_Etype
(N
, Any_Type
);
1463 Set_Etype
(N
, Component_Type
(Array_Type
));
1465 if Present
(Index
) then
1467 ("too few subscripts in array reference", First
(Exprs
));
1469 elsif Present
(Exp
) then
1470 Error_Msg_N
("too many subscripts in array reference", Exp
);
1474 end Process_Indexed_Component
;
1476 ----------------------------------------
1477 -- Process_Indexed_Component_Or_Slice --
1478 ----------------------------------------
1480 procedure Process_Indexed_Component_Or_Slice
is
1482 Exp
:= First
(Exprs
);
1484 while Present
(Exp
) loop
1485 Analyze_Expression
(Exp
);
1489 Exp
:= First
(Exprs
);
1491 -- If one index is present, and it is a subtype name, then the
1492 -- node denotes a slice (note that the case of an explicit range
1493 -- for a slice was already built as an N_Slice node in the first
1494 -- place, so that case is not handled here).
1496 -- We use a replace rather than a rewrite here because this is one
1497 -- of the cases in which the tree built by the parser is plain wrong.
1500 and then Is_Entity_Name
(Exp
)
1501 and then Is_Type
(Entity
(Exp
))
1504 Make_Slice
(Sloc
(N
),
1506 Discrete_Range
=> New_Copy
(Exp
)));
1509 -- Otherwise (more than one index present, or single index is not
1510 -- a subtype name), then we have the indexed component case.
1513 Process_Indexed_Component
;
1515 end Process_Indexed_Component_Or_Slice
;
1517 ------------------------------------------
1518 -- Process_Overloaded_Indexed_Component --
1519 ------------------------------------------
1521 procedure Process_Overloaded_Indexed_Component
is
1530 Set_Etype
(N
, Any_Type
);
1531 Get_First_Interp
(P
, I
, It
);
1533 while Present
(It
.Nam
) loop
1536 if Is_Access_Type
(Typ
) then
1537 Typ
:= Designated_Type
(Typ
);
1538 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
1541 if Is_Array_Type
(Typ
) then
1543 -- Got a candidate: verify that index types are compatible
1545 Index
:= First_Index
(Typ
);
1548 Exp
:= First
(Exprs
);
1550 while Present
(Index
) and then Present
(Exp
) loop
1551 if Has_Compatible_Type
(Exp
, Etype
(Index
)) then
1563 if Found
and then No
(Index
) and then No
(Exp
) then
1565 Etype
(Component_Type
(Typ
)),
1566 Etype
(Component_Type
(Typ
)));
1570 Get_Next_Interp
(I
, It
);
1573 if Etype
(N
) = Any_Type
then
1574 Error_Msg_N
("no legal interpetation for indexed component", N
);
1575 Set_Is_Overloaded
(N
, False);
1579 end Process_Overloaded_Indexed_Component
;
1581 ------------------------------------
1582 -- Analyze_Indexed_Component_Form --
1583 ------------------------------------
1586 -- Get name of array, function or type
1589 if Nkind
(N
) = N_Function_Call
1590 or else Nkind
(N
) = N_Procedure_Call_Statement
1592 -- If P is an explicit dereference whose prefix is of a
1593 -- remote access-to-subprogram type, then N has already
1594 -- been rewritten as a subprogram call and analyzed.
1599 pragma Assert
(Nkind
(N
) = N_Indexed_Component
);
1601 P_T
:= Base_Type
(Etype
(P
));
1603 if Is_Entity_Name
(P
)
1604 or else Nkind
(P
) = N_Operator_Symbol
1608 if Ekind
(U_N
) in Type_Kind
then
1610 -- Reformat node as a type conversion.
1612 E
:= Remove_Head
(Exprs
);
1614 if Present
(First
(Exprs
)) then
1616 ("argument of type conversion must be single expression", N
);
1619 Change_Node
(N
, N_Type_Conversion
);
1620 Set_Subtype_Mark
(N
, P
);
1622 Set_Expression
(N
, E
);
1624 -- After changing the node, call for the specific Analysis
1625 -- routine directly, to avoid a double call to the expander.
1627 Analyze_Type_Conversion
(N
);
1631 if Is_Overloadable
(U_N
) then
1632 Process_Function_Call
;
1634 elsif Ekind
(Etype
(P
)) = E_Subprogram_Type
1635 or else (Is_Access_Type
(Etype
(P
))
1637 Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
)
1639 -- Call to access_to-subprogram with possible implicit dereference
1641 Process_Function_Call
;
1643 elsif Is_Generic_Subprogram
(U_N
) then
1645 -- A common beginner's (or C++ templates fan) error.
1647 Error_Msg_N
("generic subprogram cannot be called", N
);
1648 Set_Etype
(N
, Any_Type
);
1652 Process_Indexed_Component_Or_Slice
;
1655 -- If not an entity name, prefix is an expression that may denote
1656 -- an array or an access-to-subprogram.
1659 if Ekind
(P_T
) = E_Subprogram_Type
1660 or else (Is_Access_Type
(P_T
)
1662 Ekind
(Designated_Type
(P_T
)) = E_Subprogram_Type
)
1664 Process_Function_Call
;
1666 elsif Nkind
(P
) = N_Selected_Component
1667 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
1669 Process_Function_Call
;
1672 -- Indexed component, slice, or a call to a member of a family
1673 -- entry, which will be converted to an entry call later.
1675 Process_Indexed_Component_Or_Slice
;
1678 end Analyze_Indexed_Component_Form
;
1680 ------------------------
1681 -- Analyze_Logical_Op --
1682 ------------------------
1684 procedure Analyze_Logical_Op
(N
: Node_Id
) is
1685 L
: constant Node_Id
:= Left_Opnd
(N
);
1686 R
: constant Node_Id
:= Right_Opnd
(N
);
1687 Op_Id
: Entity_Id
:= Entity
(N
);
1690 Set_Etype
(N
, Any_Type
);
1691 Candidate_Type
:= Empty
;
1693 Analyze_Expression
(L
);
1694 Analyze_Expression
(R
);
1696 if Present
(Op_Id
) then
1698 if Ekind
(Op_Id
) = E_Operator
then
1699 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
1701 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1705 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1707 while Present
(Op_Id
) loop
1708 if Ekind
(Op_Id
) = E_Operator
then
1709 Find_Boolean_Types
(L
, R
, Op_Id
, N
);
1711 Analyze_User_Defined_Binary_Op
(N
, Op_Id
);
1714 Op_Id
:= Homonym
(Op_Id
);
1719 end Analyze_Logical_Op
;
1721 ---------------------------
1722 -- Analyze_Membership_Op --
1723 ---------------------------
1725 procedure Analyze_Membership_Op
(N
: Node_Id
) is
1726 L
: constant Node_Id
:= Left_Opnd
(N
);
1727 R
: constant Node_Id
:= Right_Opnd
(N
);
1729 Index
: Interp_Index
;
1731 Found
: Boolean := False;
1735 procedure Try_One_Interp
(T1
: Entity_Id
);
1736 -- Routine to try one proposed interpretation. Note that the context
1737 -- of the operation plays no role in resolving the arguments, so that
1738 -- if there is more than one interpretation of the operands that is
1739 -- compatible with a membership test, the operation is ambiguous.
1741 procedure Try_One_Interp
(T1
: Entity_Id
) is
1743 if Has_Compatible_Type
(R
, T1
) then
1745 and then Base_Type
(T1
) /= Base_Type
(T_F
)
1747 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
1749 if It
= No_Interp
then
1750 Ambiguous_Operands
(N
);
1751 Set_Etype
(L
, Any_Type
);
1769 -- Start of processing for Analyze_Membership_Op
1772 Analyze_Expression
(L
);
1774 if Nkind
(R
) = N_Range
1775 or else (Nkind
(R
) = N_Attribute_Reference
1776 and then Attribute_Name
(R
) = Name_Range
)
1780 if not Is_Overloaded
(L
) then
1781 Try_One_Interp
(Etype
(L
));
1784 Get_First_Interp
(L
, Index
, It
);
1786 while Present
(It
.Typ
) loop
1787 Try_One_Interp
(It
.Typ
);
1788 Get_Next_Interp
(Index
, It
);
1792 -- If not a range, it can only be a subtype mark, or else there
1793 -- is a more basic error, to be diagnosed in Find_Type.
1798 if Is_Entity_Name
(R
) then
1799 Check_Fully_Declared
(Entity
(R
), R
);
1803 -- Compatibility between expression and subtype mark or range is
1804 -- checked during resolution. The result of the operation is Boolean
1807 Set_Etype
(N
, Standard_Boolean
);
1808 end Analyze_Membership_Op
;
1810 ----------------------
1811 -- Analyze_Negation --
1812 ----------------------
1814 procedure Analyze_Negation
(N
: Node_Id
) is
1815 R
: constant Node_Id
:= Right_Opnd
(N
);
1816 Op_Id
: Entity_Id
:= Entity
(N
);
1819 Set_Etype
(N
, Any_Type
);
1820 Candidate_Type
:= Empty
;
1822 Analyze_Expression
(R
);
1824 if Present
(Op_Id
) then
1825 if Ekind
(Op_Id
) = E_Operator
then
1826 Find_Negation_Types
(R
, Op_Id
, N
);
1828 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
1832 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
1834 while Present
(Op_Id
) loop
1835 if Ekind
(Op_Id
) = E_Operator
then
1836 Find_Negation_Types
(R
, Op_Id
, N
);
1838 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
1841 Op_Id
:= Homonym
(Op_Id
);
1846 end Analyze_Negation
;
1852 procedure Analyze_Null
(N
: Node_Id
) is
1854 Set_Etype
(N
, Any_Access
);
1857 ----------------------
1858 -- Analyze_One_Call --
1859 ----------------------
1861 procedure Analyze_One_Call
1865 Success
: out Boolean)
1867 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
1868 Prev_T
: constant Entity_Id
:= Etype
(N
);
1871 Is_Indexed
: Boolean := False;
1872 Subp_Type
: constant Entity_Id
:= Etype
(Nam
);
1875 procedure Indicate_Name_And_Type
;
1876 -- If candidate interpretation matches, indicate name and type of
1877 -- result on call node.
1879 ----------------------------
1880 -- Indicate_Name_And_Type --
1881 ----------------------------
1883 procedure Indicate_Name_And_Type
is
1885 Add_One_Interp
(N
, Nam
, Etype
(Nam
));
1888 -- If the prefix of the call is a name, indicate the entity
1889 -- being called. If it is not a name, it is an expression that
1890 -- denotes an access to subprogram or else an entry or family. In
1891 -- the latter case, the name is a selected component, and the entity
1892 -- being called is noted on the selector.
1894 if not Is_Type
(Nam
) then
1895 if Is_Entity_Name
(Name
(N
))
1896 or else Nkind
(Name
(N
)) = N_Operator_Symbol
1898 Set_Entity
(Name
(N
), Nam
);
1900 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
1901 Set_Entity
(Selector_Name
(Name
(N
)), Nam
);
1905 if Debug_Flag_E
and not Report
then
1906 Write_Str
(" Overloaded call ");
1907 Write_Int
(Int
(N
));
1908 Write_Str
(" compatible with ");
1909 Write_Int
(Int
(Nam
));
1912 end Indicate_Name_And_Type
;
1914 -- Start of processing for Analyze_One_Call
1919 -- If the subprogram has no formals, or if all the formals have
1920 -- defaults, and the return type is an array type, the node may
1921 -- denote an indexing of the result of a parameterless call.
1923 if Needs_No_Actuals
(Nam
)
1924 and then Present
(Actuals
)
1926 if Is_Array_Type
(Subp_Type
) then
1927 Is_Indexed
:= Try_Indexed_Call
(N
, Nam
, Subp_Type
);
1929 elsif Is_Access_Type
(Subp_Type
)
1930 and then Is_Array_Type
(Designated_Type
(Subp_Type
))
1933 Try_Indexed_Call
(N
, Nam
, Designated_Type
(Subp_Type
));
1935 elsif Is_Access_Type
(Subp_Type
)
1936 and then Ekind
(Designated_Type
(Subp_Type
)) = E_Subprogram_Type
1938 Is_Indexed
:= Try_Indirect_Call
(N
, Nam
, Subp_Type
);
1943 Normalize_Actuals
(N
, Nam
, (Report
and not Is_Indexed
), Norm_OK
);
1947 -- Mismatch in number or names of parameters
1949 if Debug_Flag_E
then
1950 Write_Str
(" normalization fails in call ");
1951 Write_Int
(Int
(N
));
1952 Write_Str
(" with subprogram ");
1953 Write_Int
(Int
(Nam
));
1957 -- If the context expects a function call, discard any interpretation
1958 -- that is a procedure. If the node is not overloaded, leave as is for
1959 -- better error reporting when type mismatch is found.
1961 elsif Nkind
(N
) = N_Function_Call
1962 and then Is_Overloaded
(Name
(N
))
1963 and then Ekind
(Nam
) = E_Procedure
1967 -- Ditto for function calls in a procedure context.
1969 elsif Nkind
(N
) = N_Procedure_Call_Statement
1970 and then Is_Overloaded
(Name
(N
))
1971 and then Etype
(Nam
) /= Standard_Void_Type
1975 elsif not Present
(Actuals
) then
1977 -- If Normalize succeeds, then there are default parameters for
1980 Indicate_Name_And_Type
;
1982 elsif Ekind
(Nam
) = E_Operator
then
1983 if Nkind
(N
) = N_Procedure_Call_Statement
then
1987 -- This can occur when the prefix of the call is an operator
1988 -- name or an expanded name whose selector is an operator name.
1990 Analyze_Operator_Call
(N
, Nam
);
1992 if Etype
(N
) /= Prev_T
then
1994 -- There may be a user-defined operator that hides the
1995 -- current interpretation. We must check for this independently
1996 -- of the analysis of the call with the user-defined operation,
1997 -- because the parameter names may be wrong and yet the hiding
1998 -- takes place. Fixes b34014o.
2000 if Is_Overloaded
(Name
(N
)) then
2006 Get_First_Interp
(Name
(N
), I
, It
);
2008 while Present
(It
.Nam
) loop
2010 if Ekind
(It
.Nam
) /= E_Operator
2011 and then Hides_Op
(It
.Nam
, Nam
)
2014 (First_Actual
(N
), Etype
(First_Formal
(It
.Nam
)))
2015 and then (No
(Next_Actual
(First_Actual
(N
)))
2016 or else Has_Compatible_Type
2017 (Next_Actual
(First_Actual
(N
)),
2018 Etype
(Next_Formal
(First_Formal
(It
.Nam
)))))
2020 Set_Etype
(N
, Prev_T
);
2024 Get_Next_Interp
(I
, It
);
2029 -- If operator matches formals, record its name on the call.
2030 -- If the operator is overloaded, Resolve will select the
2031 -- correct one from the list of interpretations. The call
2032 -- node itself carries the first candidate.
2034 Set_Entity
(Name
(N
), Nam
);
2037 elsif Report
and then Etype
(N
) = Any_Type
then
2038 Error_Msg_N
("incompatible arguments for operator", N
);
2042 -- Normalize_Actuals has chained the named associations in the
2043 -- correct order of the formals.
2045 Actual
:= First_Actual
(N
);
2046 Formal
:= First_Formal
(Nam
);
2048 while Present
(Actual
) and then Present
(Formal
) loop
2050 if Nkind
(Parent
(Actual
)) /= N_Parameter_Association
2051 or else Chars
(Selector_Name
(Parent
(Actual
))) = Chars
(Formal
)
2053 if Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
2054 Next_Actual
(Actual
);
2055 Next_Formal
(Formal
);
2058 if Debug_Flag_E
then
2059 Write_Str
(" type checking fails in call ");
2060 Write_Int
(Int
(N
));
2061 Write_Str
(" with formal ");
2062 Write_Int
(Int
(Formal
));
2063 Write_Str
(" in subprogram ");
2064 Write_Int
(Int
(Nam
));
2068 if Report
and not Is_Indexed
then
2070 Wrong_Type
(Actual
, Etype
(Formal
));
2072 if Nkind
(Actual
) = N_Op_Eq
2073 and then Nkind
(Left_Opnd
(Actual
)) = N_Identifier
2075 Formal
:= First_Formal
(Nam
);
2077 while Present
(Formal
) loop
2079 if Chars
(Left_Opnd
(Actual
)) = Chars
(Formal
) then
2081 ("possible misspelling of `='>`!", Actual
);
2085 Next_Formal
(Formal
);
2089 if All_Errors_Mode
then
2090 Error_Msg_Sloc
:= Sloc
(Nam
);
2092 if Is_Overloadable
(Nam
)
2093 and then Present
(Alias
(Nam
))
2094 and then not Comes_From_Source
(Nam
)
2097 (" =='> in call to &#(inherited)!", Actual
, Nam
);
2099 Error_Msg_NE
(" =='> in call to &#!", Actual
, Nam
);
2108 -- Normalize_Actuals has verified that a default value exists
2109 -- for this formal. Current actual names a subsequent formal.
2111 Next_Formal
(Formal
);
2115 -- On exit, all actuals match.
2117 Indicate_Name_And_Type
;
2119 end Analyze_One_Call
;
2121 ----------------------------
2122 -- Analyze_Operator_Call --
2123 ----------------------------
2125 procedure Analyze_Operator_Call
(N
: Node_Id
; Op_Id
: Entity_Id
) is
2126 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
2127 Act1
: constant Node_Id
:= First_Actual
(N
);
2128 Act2
: constant Node_Id
:= Next_Actual
(Act1
);
2131 if Present
(Act2
) then
2133 -- Maybe binary operators
2135 if Present
(Next_Actual
(Act2
)) then
2137 -- Too many actuals for an operator
2141 elsif Op_Name
= Name_Op_Add
2142 or else Op_Name
= Name_Op_Subtract
2143 or else Op_Name
= Name_Op_Multiply
2144 or else Op_Name
= Name_Op_Divide
2145 or else Op_Name
= Name_Op_Mod
2146 or else Op_Name
= Name_Op_Rem
2147 or else Op_Name
= Name_Op_Expon
2149 Find_Arithmetic_Types
(Act1
, Act2
, Op_Id
, N
);
2151 elsif Op_Name
= Name_Op_And
2152 or else Op_Name
= Name_Op_Or
2153 or else Op_Name
= Name_Op_Xor
2155 Find_Boolean_Types
(Act1
, Act2
, Op_Id
, N
);
2157 elsif Op_Name
= Name_Op_Lt
2158 or else Op_Name
= Name_Op_Le
2159 or else Op_Name
= Name_Op_Gt
2160 or else Op_Name
= Name_Op_Ge
2162 Find_Comparison_Types
(Act1
, Act2
, Op_Id
, N
);
2164 elsif Op_Name
= Name_Op_Eq
2165 or else Op_Name
= Name_Op_Ne
2167 Find_Equality_Types
(Act1
, Act2
, Op_Id
, N
);
2169 elsif Op_Name
= Name_Op_Concat
then
2170 Find_Concatenation_Types
(Act1
, Act2
, Op_Id
, N
);
2172 -- Is this else null correct, or should it be an abort???
2181 if Op_Name
= Name_Op_Subtract
or else
2182 Op_Name
= Name_Op_Add
or else
2183 Op_Name
= Name_Op_Abs
2185 Find_Unary_Types
(Act1
, Op_Id
, N
);
2188 Op_Name
= Name_Op_Not
2190 Find_Negation_Types
(Act1
, Op_Id
, N
);
2192 -- Is this else null correct, or should it be an abort???
2198 end Analyze_Operator_Call
;
2200 -------------------------------------------
2201 -- Analyze_Overloaded_Selected_Component --
2202 -------------------------------------------
2204 procedure Analyze_Overloaded_Selected_Component
(N
: Node_Id
) is
2205 Nam
: constant Node_Id
:= Prefix
(N
);
2206 Sel
: constant Node_Id
:= Selector_Name
(N
);
2213 Get_First_Interp
(Nam
, I
, It
);
2215 Set_Etype
(Sel
, Any_Type
);
2217 while Present
(It
.Typ
) loop
2218 if Is_Access_Type
(It
.Typ
) then
2219 T
:= Designated_Type
(It
.Typ
);
2220 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
2226 if Is_Record_Type
(T
) then
2227 Comp
:= First_Entity
(T
);
2229 while Present
(Comp
) loop
2231 if Chars
(Comp
) = Chars
(Sel
)
2232 and then Is_Visible_Component
(Comp
)
2234 Set_Entity_With_Style_Check
(Sel
, Comp
);
2235 Generate_Reference
(Comp
, Sel
);
2237 Set_Etype
(Sel
, Etype
(Comp
));
2238 Add_One_Interp
(N
, Etype
(Comp
), Etype
(Comp
));
2240 -- This also specifies a candidate to resolve the name.
2241 -- Further overloading will be resolved from context.
2243 Set_Etype
(Nam
, It
.Typ
);
2249 elsif Is_Concurrent_Type
(T
) then
2250 Comp
:= First_Entity
(T
);
2252 while Present
(Comp
)
2253 and then Comp
/= First_Private_Entity
(T
)
2255 if Chars
(Comp
) = Chars
(Sel
) then
2256 if Is_Overloadable
(Comp
) then
2257 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
2259 Set_Entity_With_Style_Check
(Sel
, Comp
);
2260 Generate_Reference
(Comp
, Sel
);
2263 Set_Etype
(Sel
, Etype
(Comp
));
2264 Set_Etype
(N
, Etype
(Comp
));
2265 Set_Etype
(Nam
, It
.Typ
);
2267 -- For access type case, introduce explicit deference for
2268 -- more uniform treatment of entry calls.
2270 if Is_Access_Type
(Etype
(Nam
)) then
2271 Insert_Explicit_Dereference
(Nam
);
2273 (Warn_On_Dereference
, "?implicit dereference", N
);
2280 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
2283 Get_Next_Interp
(I
, It
);
2286 if Etype
(N
) = Any_Type
then
2287 Error_Msg_NE
("undefined selector& for overloaded prefix", N
, Sel
);
2288 Set_Entity
(Sel
, Any_Id
);
2289 Set_Etype
(Sel
, Any_Type
);
2292 end Analyze_Overloaded_Selected_Component
;
2294 ----------------------------------
2295 -- Analyze_Qualified_Expression --
2296 ----------------------------------
2298 procedure Analyze_Qualified_Expression
(N
: Node_Id
) is
2299 Mark
: constant Entity_Id
:= Subtype_Mark
(N
);
2303 Set_Etype
(N
, Any_Type
);
2307 if T
= Any_Type
then
2310 Check_Fully_Declared
(T
, N
);
2312 Analyze_Expression
(Expression
(N
));
2314 end Analyze_Qualified_Expression
;
2320 procedure Analyze_Range
(N
: Node_Id
) is
2321 L
: constant Node_Id
:= Low_Bound
(N
);
2322 H
: constant Node_Id
:= High_Bound
(N
);
2323 I1
, I2
: Interp_Index
;
2326 procedure Check_Common_Type
(T1
, T2
: Entity_Id
);
2327 -- Verify the compatibility of two types, and choose the
2328 -- non universal one if the other is universal.
2330 procedure Check_High_Bound
(T
: Entity_Id
);
2331 -- Test one interpretation of the low bound against all those
2332 -- of the high bound.
2334 procedure Check_Universal_Expression
(N
: Node_Id
);
2335 -- In Ada83, reject bounds of a universal range that are not
2336 -- literals or entity names.
2338 -----------------------
2339 -- Check_Common_Type --
2340 -----------------------
2342 procedure Check_Common_Type
(T1
, T2
: Entity_Id
) is
2344 if Covers
(T1
, T2
) or else Covers
(T2
, T1
) then
2345 if T1
= Universal_Integer
2346 or else T1
= Universal_Real
2347 or else T1
= Any_Character
2349 Add_One_Interp
(N
, Base_Type
(T2
), Base_Type
(T2
));
2352 Add_One_Interp
(N
, T1
, T1
);
2355 Add_One_Interp
(N
, Base_Type
(T1
), Base_Type
(T1
));
2358 end Check_Common_Type
;
2360 ----------------------
2361 -- Check_High_Bound --
2362 ----------------------
2364 procedure Check_High_Bound
(T
: Entity_Id
) is
2366 if not Is_Overloaded
(H
) then
2367 Check_Common_Type
(T
, Etype
(H
));
2369 Get_First_Interp
(H
, I2
, It2
);
2371 while Present
(It2
.Typ
) loop
2372 Check_Common_Type
(T
, It2
.Typ
);
2373 Get_Next_Interp
(I2
, It2
);
2376 end Check_High_Bound
;
2378 -----------------------------
2379 -- Is_Universal_Expression --
2380 -----------------------------
2382 procedure Check_Universal_Expression
(N
: Node_Id
) is
2384 if Etype
(N
) = Universal_Integer
2385 and then Nkind
(N
) /= N_Integer_Literal
2386 and then not Is_Entity_Name
(N
)
2387 and then Nkind
(N
) /= N_Attribute_Reference
2389 Error_Msg_N
("illegal bound in discrete range", N
);
2391 end Check_Universal_Expression
;
2393 -- Start of processing for Analyze_Range
2396 Set_Etype
(N
, Any_Type
);
2397 Analyze_Expression
(L
);
2398 Analyze_Expression
(H
);
2400 if Etype
(L
) = Any_Type
or else Etype
(H
) = Any_Type
then
2404 if not Is_Overloaded
(L
) then
2405 Check_High_Bound
(Etype
(L
));
2407 Get_First_Interp
(L
, I1
, It1
);
2409 while Present
(It1
.Typ
) loop
2410 Check_High_Bound
(It1
.Typ
);
2411 Get_Next_Interp
(I1
, It1
);
2415 -- If result is Any_Type, then we did not find a compatible pair
2417 if Etype
(N
) = Any_Type
then
2418 Error_Msg_N
("incompatible types in range ", N
);
2424 (Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
2425 or else Nkind
(Parent
(N
)) = N_Constrained_Array_Definition
)
2427 Check_Universal_Expression
(L
);
2428 Check_Universal_Expression
(H
);
2432 -----------------------
2433 -- Analyze_Reference --
2434 -----------------------
2436 procedure Analyze_Reference
(N
: Node_Id
) is
2437 P
: constant Node_Id
:= Prefix
(N
);
2438 Acc_Type
: Entity_Id
;
2442 Acc_Type
:= Create_Itype
(E_Allocator_Type
, N
);
2443 Set_Etype
(Acc_Type
, Acc_Type
);
2444 Init_Size_Align
(Acc_Type
);
2445 Set_Directly_Designated_Type
(Acc_Type
, Etype
(P
));
2446 Set_Etype
(N
, Acc_Type
);
2447 end Analyze_Reference
;
2449 --------------------------------
2450 -- Analyze_Selected_Component --
2451 --------------------------------
2453 -- Prefix is a record type or a task or protected type. In the
2454 -- later case, the selector must denote a visible entry.
2456 procedure Analyze_Selected_Component
(N
: Node_Id
) is
2457 Name
: constant Node_Id
:= Prefix
(N
);
2458 Sel
: constant Node_Id
:= Selector_Name
(N
);
2460 Entity_List
: Entity_Id
;
2461 Prefix_Type
: Entity_Id
;
2466 -- Start of processing for Analyze_Selected_Component
2469 Set_Etype
(N
, Any_Type
);
2471 if Is_Overloaded
(Name
) then
2472 Analyze_Overloaded_Selected_Component
(N
);
2475 elsif Etype
(Name
) = Any_Type
then
2476 Set_Entity
(Sel
, Any_Id
);
2477 Set_Etype
(Sel
, Any_Type
);
2481 -- Function calls that are prefixes of selected components must be
2482 -- fully resolved in case we need to build an actual subtype, or
2483 -- do some other operation requiring a fully resolved prefix.
2485 -- Note: Resolving all Nkinds of nodes here doesn't work.
2486 -- (Breaks 2129-008) ???.
2488 if Nkind
(Name
) = N_Function_Call
then
2492 Prefix_Type
:= Etype
(Name
);
2495 if Is_Access_Type
(Prefix_Type
) then
2497 -- A RACW object can never be used as prefix of a selected
2498 -- component since that means it is dereferenced without
2499 -- being a controlling operand of a dispatching operation
2502 if Is_Remote_Access_To_Class_Wide_Type
(Prefix_Type
)
2503 and then Comes_From_Source
(N
)
2506 ("invalid dereference of a remote access to class-wide value",
2509 -- Normal case of selected component applied to access type
2512 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
2515 Prefix_Type
:= Designated_Type
(Prefix_Type
);
2518 if Ekind
(Prefix_Type
) = E_Private_Subtype
then
2519 Prefix_Type
:= Base_Type
(Prefix_Type
);
2522 Entity_List
:= Prefix_Type
;
2524 -- For class-wide types, use the entity list of the root type. This
2525 -- indirection is specially important for private extensions because
2526 -- only the root type get switched (not the class-wide type).
2528 if Is_Class_Wide_Type
(Prefix_Type
) then
2529 Entity_List
:= Root_Type
(Prefix_Type
);
2532 Comp
:= First_Entity
(Entity_List
);
2534 -- If the selector has an original discriminant, the node appears in
2535 -- an instance. Replace the discriminant with the corresponding one
2536 -- in the current discriminated type. For nested generics, this must
2537 -- be done transitively, so note the new original discriminant.
2539 if Nkind
(Sel
) = N_Identifier
2540 and then Present
(Original_Discriminant
(Sel
))
2542 Comp
:= Find_Corresponding_Discriminant
(Sel
, Prefix_Type
);
2544 -- Mark entity before rewriting, for completeness and because
2545 -- subsequent semantic checks might examine the original node.
2547 Set_Entity
(Sel
, Comp
);
2548 Rewrite
(Selector_Name
(N
),
2549 New_Occurrence_Of
(Comp
, Sloc
(N
)));
2550 Set_Original_Discriminant
(Selector_Name
(N
), Comp
);
2551 Set_Etype
(N
, Etype
(Comp
));
2553 if Is_Access_Type
(Etype
(Name
)) then
2554 Insert_Explicit_Dereference
(Name
);
2555 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
2558 elsif Is_Record_Type
(Prefix_Type
) then
2560 -- Find component with given name
2562 while Present
(Comp
) loop
2564 if Chars
(Comp
) = Chars
(Sel
)
2565 and then Is_Visible_Component
(Comp
)
2567 Set_Entity_With_Style_Check
(Sel
, Comp
);
2568 Generate_Reference
(Comp
, Sel
);
2570 Set_Etype
(Sel
, Etype
(Comp
));
2572 if Ekind
(Comp
) = E_Discriminant
then
2573 if Is_Unchecked_Union
(Prefix_Type
) then
2575 ("cannot reference discriminant of Unchecked_Union",
2579 if Is_Generic_Type
(Prefix_Type
)
2581 Is_Generic_Type
(Root_Type
(Prefix_Type
))
2583 Set_Original_Discriminant
(Sel
, Comp
);
2587 -- Resolve the prefix early otherwise it is not possible to
2588 -- build the actual subtype of the component: it may need
2589 -- to duplicate this prefix and duplication is only allowed
2590 -- on fully resolved expressions.
2594 -- We never need an actual subtype for the case of a selection
2595 -- for a indexed component of a non-packed array, since in
2596 -- this case gigi generates all the checks and can find the
2597 -- necessary bounds information.
2599 -- We also do not need an actual subtype for the case of
2600 -- a first, last, length, or range attribute applied to a
2601 -- non-packed array, since gigi can again get the bounds in
2602 -- these cases (gigi cannot handle the packed case, since it
2603 -- has the bounds of the packed array type, not the original
2604 -- bounds of the type). However, if the prefix is itself a
2605 -- selected component, as in a.b.c (i), gigi may regard a.b.c
2606 -- as a dynamic-sized temporary, so we do generate an actual
2607 -- subtype for this case.
2609 Parent_N
:= Parent
(N
);
2611 if not Is_Packed
(Etype
(Comp
))
2613 ((Nkind
(Parent_N
) = N_Indexed_Component
2614 and then Nkind
(Name
) /= N_Selected_Component
)
2616 (Nkind
(Parent_N
) = N_Attribute_Reference
2617 and then (Attribute_Name
(Parent_N
) = Name_First
2619 Attribute_Name
(Parent_N
) = Name_Last
2621 Attribute_Name
(Parent_N
) = Name_Length
2623 Attribute_Name
(Parent_N
) = Name_Range
)))
2625 Set_Etype
(N
, Etype
(Comp
));
2627 -- In all other cases, we currently build an actual subtype. It
2628 -- seems likely that many of these cases can be avoided, but
2629 -- right now, the front end makes direct references to the
2630 -- bounds (e.g. in generating a length check), and if we do
2631 -- not make an actual subtype, we end up getting a direct
2632 -- reference to a discriminant which will not do.
2636 Build_Actual_Subtype_Of_Component
(Etype
(Comp
), N
);
2637 Insert_Action
(N
, Act_Decl
);
2639 if No
(Act_Decl
) then
2640 Set_Etype
(N
, Etype
(Comp
));
2643 -- Component type depends on discriminants. Enter the
2644 -- main attributes of the subtype.
2647 Subt
: constant Entity_Id
:=
2648 Defining_Identifier
(Act_Decl
);
2651 Set_Etype
(Subt
, Base_Type
(Etype
(Comp
)));
2652 Set_Ekind
(Subt
, Ekind
(Etype
(Comp
)));
2653 Set_Etype
(N
, Subt
);
2664 elsif Is_Private_Type
(Prefix_Type
) then
2666 -- Allow access only to discriminants of the type. If the
2667 -- type has no full view, gigi uses the parent type for
2668 -- the components, so we do the same here.
2670 if No
(Full_View
(Prefix_Type
)) then
2671 Entity_List
:= Root_Type
(Base_Type
(Prefix_Type
));
2672 Comp
:= First_Entity
(Entity_List
);
2675 while Present
(Comp
) loop
2677 if Chars
(Comp
) = Chars
(Sel
) then
2678 if Ekind
(Comp
) = E_Discriminant
then
2679 Set_Entity_With_Style_Check
(Sel
, Comp
);
2680 Generate_Reference
(Comp
, Sel
);
2682 Set_Etype
(Sel
, Etype
(Comp
));
2683 Set_Etype
(N
, Etype
(Comp
));
2685 if Is_Generic_Type
(Prefix_Type
)
2687 Is_Generic_Type
(Root_Type
(Prefix_Type
))
2689 Set_Original_Discriminant
(Sel
, Comp
);
2694 ("invisible selector for }",
2695 N
, First_Subtype
(Prefix_Type
));
2696 Set_Entity
(Sel
, Any_Id
);
2697 Set_Etype
(N
, Any_Type
);
2706 elsif Is_Concurrent_Type
(Prefix_Type
) then
2708 -- Prefix is concurrent type. Find visible operation with given name
2709 -- For a task, this can only include entries or discriminants if
2710 -- the task type is not an enclosing scope. If it is an enclosing
2711 -- scope (e.g. in an inner task) then all entities are visible, but
2712 -- the prefix must denote the enclosing scope, i.e. can only be
2713 -- a direct name or an expanded name.
2715 Set_Etype
(Sel
, Any_Type
);
2716 In_Scope
:= In_Open_Scopes
(Prefix_Type
);
2718 while Present
(Comp
) loop
2719 if Chars
(Comp
) = Chars
(Sel
) then
2720 if Is_Overloadable
(Comp
) then
2721 Add_One_Interp
(Sel
, Comp
, Etype
(Comp
));
2723 elsif Ekind
(Comp
) = E_Discriminant
2724 or else Ekind
(Comp
) = E_Entry_Family
2726 and then Is_Entity_Name
(Name
))
2728 Set_Entity_With_Style_Check
(Sel
, Comp
);
2729 Generate_Reference
(Comp
, Sel
);
2735 Set_Etype
(Sel
, Etype
(Comp
));
2736 Set_Etype
(N
, Etype
(Comp
));
2738 if Ekind
(Comp
) = E_Discriminant
then
2739 Set_Original_Discriminant
(Sel
, Comp
);
2742 -- For access type case, introduce explicit deference for
2743 -- more uniform treatment of entry calls.
2745 if Is_Access_Type
(Etype
(Name
)) then
2746 Insert_Explicit_Dereference
(Name
);
2748 (Warn_On_Dereference
, "?implicit dereference", N
);
2754 exit when not In_Scope
2755 and then Comp
= First_Private_Entity
(Prefix_Type
);
2758 Set_Is_Overloaded
(N
, Is_Overloaded
(Sel
));
2763 Error_Msg_NE
("invalid prefix in selected component&", N
, Sel
);
2766 -- If N still has no type, the component is not defined in the prefix.
2768 if Etype
(N
) = Any_Type
then
2770 -- If the prefix is a single concurrent object, use its name in
2771 -- the error message, rather than that of its anonymous type.
2773 if Is_Concurrent_Type
(Prefix_Type
)
2774 and then Is_Internal_Name
(Chars
(Prefix_Type
))
2775 and then not Is_Derived_Type
(Prefix_Type
)
2776 and then Is_Entity_Name
(Name
)
2779 Error_Msg_Node_2
:= Entity
(Name
);
2780 Error_Msg_NE
("no selector& for&", N
, Sel
);
2782 Check_Misspelled_Selector
(Entity_List
, Sel
);
2784 elsif Is_Generic_Type
(Prefix_Type
)
2785 and then Ekind
(Prefix_Type
) = E_Record_Type_With_Private
2786 and then Prefix_Type
/= Etype
(Prefix_Type
)
2787 and then Is_Record_Type
(Etype
(Prefix_Type
))
2789 -- If this is a derived formal type, the parent may have a
2790 -- different visibility at this point. Try for an inherited
2791 -- component before reporting an error.
2793 Set_Etype
(Prefix
(N
), Etype
(Prefix_Type
));
2794 Analyze_Selected_Component
(N
);
2797 elsif Ekind
(Prefix_Type
) = E_Record_Subtype_With_Private
2798 and then Is_Generic_Actual_Type
(Prefix_Type
)
2799 and then Present
(Full_View
(Prefix_Type
))
2801 -- Similarly, if this the actual for a formal derived type,
2802 -- the component inherited from the generic parent may not
2803 -- be visible in the actual, but the selected component is
2810 First_Component
(Generic_Parent_Type
(Parent
(Prefix_Type
)));
2812 while Present
(Comp
) loop
2813 if Chars
(Comp
) = Chars
(Sel
) then
2814 Set_Entity_With_Style_Check
(Sel
, Comp
);
2815 Set_Etype
(Sel
, Etype
(Comp
));
2816 Set_Etype
(N
, Etype
(Comp
));
2820 Next_Component
(Comp
);
2823 pragma Assert
(Etype
(N
) /= Any_Type
);
2827 if Ekind
(Prefix_Type
) = E_Record_Subtype
then
2829 -- Check whether this is a component of the base type
2830 -- which is absent from a statically constrained subtype.
2831 -- This will raise constraint error at run-time, but is
2832 -- not a compile-time error. When the selector is illegal
2833 -- for base type as well fall through and generate a
2834 -- compilation error anyway.
2836 Comp
:= First_Component
(Base_Type
(Prefix_Type
));
2838 while Present
(Comp
) loop
2840 if Chars
(Comp
) = Chars
(Sel
)
2841 and then Is_Visible_Component
(Comp
)
2843 Set_Entity_With_Style_Check
(Sel
, Comp
);
2844 Generate_Reference
(Comp
, Sel
);
2845 Set_Etype
(Sel
, Etype
(Comp
));
2846 Set_Etype
(N
, Etype
(Comp
));
2848 -- Emit appropriate message. Gigi will replace the
2849 -- node subsequently with the appropriate Raise.
2851 Apply_Compile_Time_Constraint_Error
2852 (N
, "component not present in }?",
2853 CE_Discriminant_Check_Failed
,
2854 Ent
=> Prefix_Type
, Rep
=> False);
2855 Set_Raises_Constraint_Error
(N
);
2859 Next_Component
(Comp
);
2864 Error_Msg_Node_2
:= First_Subtype
(Prefix_Type
);
2865 Error_Msg_NE
("no selector& for}", N
, Sel
);
2867 Check_Misspelled_Selector
(Entity_List
, Sel
);
2871 Set_Entity
(Sel
, Any_Id
);
2872 Set_Etype
(Sel
, Any_Type
);
2874 end Analyze_Selected_Component
;
2876 ---------------------------
2877 -- Analyze_Short_Circuit --
2878 ---------------------------
2880 procedure Analyze_Short_Circuit
(N
: Node_Id
) is
2881 L
: constant Node_Id
:= Left_Opnd
(N
);
2882 R
: constant Node_Id
:= Right_Opnd
(N
);
2887 Analyze_Expression
(L
);
2888 Analyze_Expression
(R
);
2889 Set_Etype
(N
, Any_Type
);
2891 if not Is_Overloaded
(L
) then
2893 if Root_Type
(Etype
(L
)) = Standard_Boolean
2894 and then Has_Compatible_Type
(R
, Etype
(L
))
2896 Add_One_Interp
(N
, Etype
(L
), Etype
(L
));
2900 Get_First_Interp
(L
, Ind
, It
);
2902 while Present
(It
.Typ
) loop
2903 if Root_Type
(It
.Typ
) = Standard_Boolean
2904 and then Has_Compatible_Type
(R
, It
.Typ
)
2906 Add_One_Interp
(N
, It
.Typ
, It
.Typ
);
2909 Get_Next_Interp
(Ind
, It
);
2913 -- Here we have failed to find an interpretation. Clearly we
2914 -- know that it is not the case that both operands can have
2915 -- an interpretation of Boolean, but this is by far the most
2916 -- likely intended interpretation. So we simply resolve both
2917 -- operands as Booleans, and at least one of these resolutions
2918 -- will generate an error message, and we do not need to give
2919 -- a further error message on the short circuit operation itself.
2921 if Etype
(N
) = Any_Type
then
2922 Resolve
(L
, Standard_Boolean
);
2923 Resolve
(R
, Standard_Boolean
);
2924 Set_Etype
(N
, Standard_Boolean
);
2926 end Analyze_Short_Circuit
;
2932 procedure Analyze_Slice
(N
: Node_Id
) is
2933 P
: constant Node_Id
:= Prefix
(N
);
2934 D
: constant Node_Id
:= Discrete_Range
(N
);
2935 Array_Type
: Entity_Id
;
2937 procedure Analyze_Overloaded_Slice
;
2938 -- If the prefix is overloaded, select those interpretations that
2939 -- yield a one-dimensional array type.
2941 procedure Analyze_Overloaded_Slice
is
2947 Set_Etype
(N
, Any_Type
);
2948 Get_First_Interp
(P
, I
, It
);
2950 while Present
(It
.Nam
) loop
2953 if Is_Access_Type
(Typ
) then
2954 Typ
:= Designated_Type
(Typ
);
2955 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
2958 if Is_Array_Type
(Typ
)
2959 and then Number_Dimensions
(Typ
) = 1
2960 and then Has_Compatible_Type
(D
, Etype
(First_Index
(Typ
)))
2962 Add_One_Interp
(N
, Typ
, Typ
);
2965 Get_Next_Interp
(I
, It
);
2968 if Etype
(N
) = Any_Type
then
2969 Error_Msg_N
("expect array type in prefix of slice", N
);
2971 end Analyze_Overloaded_Slice
;
2973 -- Start of processing for Analyze_Slice
2976 -- Analyze the prefix if not done already
2978 if No
(Etype
(P
)) then
2984 if Is_Overloaded
(P
) then
2985 Analyze_Overloaded_Slice
;
2988 Array_Type
:= Etype
(P
);
2989 Set_Etype
(N
, Any_Type
);
2991 if Is_Access_Type
(Array_Type
) then
2992 Array_Type
:= Designated_Type
(Array_Type
);
2993 Error_Msg_NW
(Warn_On_Dereference
, "?implicit dereference", N
);
2996 if not Is_Array_Type
(Array_Type
) then
2997 Wrong_Type
(P
, Any_Array
);
2999 elsif Number_Dimensions
(Array_Type
) > 1 then
3001 ("type is not one-dimensional array in slice prefix", N
);
3004 Has_Compatible_Type
(D
, Etype
(First_Index
(Array_Type
)))
3006 Wrong_Type
(D
, Etype
(First_Index
(Array_Type
)));
3009 Set_Etype
(N
, Array_Type
);
3014 -----------------------------
3015 -- Analyze_Type_Conversion --
3016 -----------------------------
3018 procedure Analyze_Type_Conversion
(N
: Node_Id
) is
3019 Expr
: constant Node_Id
:= Expression
(N
);
3023 -- If Conversion_OK is set, then the Etype is already set, and the
3024 -- only processing required is to analyze the expression. This is
3025 -- used to construct certain "illegal" conversions which are not
3026 -- allowed by Ada semantics, but can be handled OK by Gigi, see
3027 -- Sinfo for further details.
3029 if Conversion_OK
(N
) then
3034 -- Otherwise full type analysis is required, as well as some semantic
3035 -- checks to make sure the argument of the conversion is appropriate.
3037 Find_Type
(Subtype_Mark
(N
));
3038 T
:= Entity
(Subtype_Mark
(N
));
3040 Check_Fully_Declared
(T
, N
);
3041 Analyze_Expression
(Expr
);
3042 Validate_Remote_Type_Type_Conversion
(N
);
3044 -- Only remaining step is validity checks on the argument. These
3045 -- are skipped if the conversion does not come from the source.
3047 if not Comes_From_Source
(N
) then
3050 elsif Nkind
(Expr
) = N_Null
then
3051 Error_Msg_N
("argument of conversion cannot be null", N
);
3052 Error_Msg_N
("\use qualified expression instead", N
);
3053 Set_Etype
(N
, Any_Type
);
3055 elsif Nkind
(Expr
) = N_Aggregate
then
3056 Error_Msg_N
("argument of conversion cannot be aggregate", N
);
3057 Error_Msg_N
("\use qualified expression instead", N
);
3059 elsif Nkind
(Expr
) = N_Allocator
then
3060 Error_Msg_N
("argument of conversion cannot be an allocator", N
);
3061 Error_Msg_N
("\use qualified expression instead", N
);
3063 elsif Nkind
(Expr
) = N_String_Literal
then
3064 Error_Msg_N
("argument of conversion cannot be string literal", N
);
3065 Error_Msg_N
("\use qualified expression instead", N
);
3067 elsif Nkind
(Expr
) = N_Character_Literal
then
3071 Error_Msg_N
("argument of conversion cannot be character literal",
3073 Error_Msg_N
("\use qualified expression instead", N
);
3076 elsif Nkind
(Expr
) = N_Attribute_Reference
3078 (Attribute_Name
(Expr
) = Name_Access
or else
3079 Attribute_Name
(Expr
) = Name_Unchecked_Access
or else
3080 Attribute_Name
(Expr
) = Name_Unrestricted_Access
)
3082 Error_Msg_N
("argument of conversion cannot be access", N
);
3083 Error_Msg_N
("\use qualified expression instead", N
);
3086 end Analyze_Type_Conversion
;
3088 ----------------------
3089 -- Analyze_Unary_Op --
3090 ----------------------
3092 procedure Analyze_Unary_Op
(N
: Node_Id
) is
3093 R
: constant Node_Id
:= Right_Opnd
(N
);
3094 Op_Id
: Entity_Id
:= Entity
(N
);
3097 Set_Etype
(N
, Any_Type
);
3098 Candidate_Type
:= Empty
;
3100 Analyze_Expression
(R
);
3102 if Present
(Op_Id
) then
3103 if Ekind
(Op_Id
) = E_Operator
then
3104 Find_Unary_Types
(R
, Op_Id
, N
);
3106 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3110 Op_Id
:= Get_Name_Entity_Id
(Chars
(N
));
3112 while Present
(Op_Id
) loop
3114 if Ekind
(Op_Id
) = E_Operator
then
3115 if No
(Next_Entity
(First_Entity
(Op_Id
))) then
3116 Find_Unary_Types
(R
, Op_Id
, N
);
3119 elsif Is_Overloadable
(Op_Id
) then
3120 Analyze_User_Defined_Unary_Op
(N
, Op_Id
);
3123 Op_Id
:= Homonym
(Op_Id
);
3128 end Analyze_Unary_Op
;
3130 ----------------------------------
3131 -- Analyze_Unchecked_Expression --
3132 ----------------------------------
3134 procedure Analyze_Unchecked_Expression
(N
: Node_Id
) is
3136 Analyze
(Expression
(N
), Suppress
=> All_Checks
);
3137 Set_Etype
(N
, Etype
(Expression
(N
)));
3138 Save_Interps
(Expression
(N
), N
);
3139 end Analyze_Unchecked_Expression
;
3141 ---------------------------------------
3142 -- Analyze_Unchecked_Type_Conversion --
3143 ---------------------------------------
3145 procedure Analyze_Unchecked_Type_Conversion
(N
: Node_Id
) is
3147 Find_Type
(Subtype_Mark
(N
));
3148 Analyze_Expression
(Expression
(N
));
3149 Set_Etype
(N
, Entity
(Subtype_Mark
(N
)));
3150 end Analyze_Unchecked_Type_Conversion
;
3152 ------------------------------------
3153 -- Analyze_User_Defined_Binary_Op --
3154 ------------------------------------
3156 procedure Analyze_User_Defined_Binary_Op
3161 -- Only do analysis if the operator Comes_From_Source, since otherwise
3162 -- the operator was generated by the expander, and all such operators
3163 -- always refer to the operators in package Standard.
3165 if Comes_From_Source
(N
) then
3167 F1
: constant Entity_Id
:= First_Formal
(Op_Id
);
3168 F2
: constant Entity_Id
:= Next_Formal
(F1
);
3171 -- Verify that Op_Id is a visible binary function. Note that since
3172 -- we know Op_Id is overloaded, potentially use visible means use
3173 -- visible for sure (RM 9.4(11)).
3175 if Ekind
(Op_Id
) = E_Function
3176 and then Present
(F2
)
3177 and then (Is_Immediately_Visible
(Op_Id
)
3178 or else Is_Potentially_Use_Visible
(Op_Id
))
3179 and then Has_Compatible_Type
(Left_Opnd
(N
), Etype
(F1
))
3180 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F2
))
3182 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3184 if Debug_Flag_E
then
3185 Write_Str
("user defined operator ");
3186 Write_Name
(Chars
(Op_Id
));
3187 Write_Str
(" on node ");
3188 Write_Int
(Int
(N
));
3194 end Analyze_User_Defined_Binary_Op
;
3196 -----------------------------------
3197 -- Analyze_User_Defined_Unary_Op --
3198 -----------------------------------
3200 procedure Analyze_User_Defined_Unary_Op
3205 -- Only do analysis if the operator Comes_From_Source, since otherwise
3206 -- the operator was generated by the expander, and all such operators
3207 -- always refer to the operators in package Standard.
3209 if Comes_From_Source
(N
) then
3211 F
: constant Entity_Id
:= First_Formal
(Op_Id
);
3214 -- Verify that Op_Id is a visible unary function. Note that since
3215 -- we know Op_Id is overloaded, potentially use visible means use
3216 -- visible for sure (RM 9.4(11)).
3218 if Ekind
(Op_Id
) = E_Function
3219 and then No
(Next_Formal
(F
))
3220 and then (Is_Immediately_Visible
(Op_Id
)
3221 or else Is_Potentially_Use_Visible
(Op_Id
))
3222 and then Has_Compatible_Type
(Right_Opnd
(N
), Etype
(F
))
3224 Add_One_Interp
(N
, Op_Id
, Etype
(Op_Id
));
3228 end Analyze_User_Defined_Unary_Op
;
3230 ---------------------------
3231 -- Check_Arithmetic_Pair --
3232 ---------------------------
3234 procedure Check_Arithmetic_Pair
3235 (T1
, T2
: Entity_Id
;
3239 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
3241 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
;
3242 -- Get specific type (i.e. non-universal type if there is one)
3244 function Specific_Type
(T1
, T2
: Entity_Id
) return Entity_Id
is
3246 if T1
= Universal_Integer
or else T1
= Universal_Real
then
3247 return Base_Type
(T2
);
3249 return Base_Type
(T1
);
3253 -- Start of processing for Check_Arithmetic_Pair
3256 if Op_Name
= Name_Op_Add
or else Op_Name
= Name_Op_Subtract
then
3258 if Is_Numeric_Type
(T1
)
3259 and then Is_Numeric_Type
(T2
)
3260 and then (Covers
(T1
, T2
) or else Covers
(T2
, T1
))
3262 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
3265 elsif Op_Name
= Name_Op_Multiply
or else Op_Name
= Name_Op_Divide
then
3267 if Is_Fixed_Point_Type
(T1
)
3268 and then (Is_Fixed_Point_Type
(T2
)
3269 or else T2
= Universal_Real
)
3271 -- If Treat_Fixed_As_Integer is set then the Etype is already set
3272 -- and no further processing is required (this is the case of an
3273 -- operator constructed by Exp_Fixd for a fixed point operation)
3274 -- Otherwise add one interpretation with universal fixed result
3275 -- If the operator is given in functional notation, it comes
3276 -- from source and Fixed_As_Integer cannot apply.
3278 if Nkind
(N
) not in N_Op
3279 or else not Treat_Fixed_As_Integer
(N
)
3281 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
3284 elsif Is_Fixed_Point_Type
(T2
)
3285 and then (Nkind
(N
) not in N_Op
3286 or else not Treat_Fixed_As_Integer
(N
))
3287 and then T1
= Universal_Real
3289 Add_One_Interp
(N
, Op_Id
, Universal_Fixed
);
3291 elsif Is_Numeric_Type
(T1
)
3292 and then Is_Numeric_Type
(T2
)
3293 and then (Covers
(T1
, T2
) or else Covers
(T2
, T1
))
3295 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
3297 elsif Is_Fixed_Point_Type
(T1
)
3298 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3299 or else T2
= Universal_Integer
)
3301 Add_One_Interp
(N
, Op_Id
, T1
);
3303 elsif T2
= Universal_Real
3304 and then Base_Type
(T1
) = Base_Type
(Standard_Integer
)
3305 and then Op_Name
= Name_Op_Multiply
3307 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
3309 elsif T1
= Universal_Real
3310 and then Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3312 Add_One_Interp
(N
, Op_Id
, Any_Fixed
);
3314 elsif Is_Fixed_Point_Type
(T2
)
3315 and then (Base_Type
(T1
) = Base_Type
(Standard_Integer
)
3316 or else T1
= Universal_Integer
)
3317 and then Op_Name
= Name_Op_Multiply
3319 Add_One_Interp
(N
, Op_Id
, T2
);
3321 elsif T1
= Universal_Real
and then T2
= Universal_Integer
then
3322 Add_One_Interp
(N
, Op_Id
, T1
);
3324 elsif T2
= Universal_Real
3325 and then T1
= Universal_Integer
3326 and then Op_Name
= Name_Op_Multiply
3328 Add_One_Interp
(N
, Op_Id
, T2
);
3331 elsif Op_Name
= Name_Op_Mod
or else Op_Name
= Name_Op_Rem
then
3333 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
3334 -- set does not require any special processing, since the Etype is
3335 -- already set (case of operation constructed by Exp_Fixed).
3337 if Is_Integer_Type
(T1
)
3338 and then (Covers
(T1
, T2
) or else Covers
(T2
, T1
))
3340 Add_One_Interp
(N
, Op_Id
, Specific_Type
(T1
, T2
));
3343 elsif Op_Name
= Name_Op_Expon
then
3345 if Is_Numeric_Type
(T1
)
3346 and then not Is_Fixed_Point_Type
(T1
)
3347 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3348 or else T2
= Universal_Integer
)
3350 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
3353 else pragma Assert
(Nkind
(N
) in N_Op_Shift
);
3355 -- If not one of the predefined operators, the node may be one
3356 -- of the intrinsic functions. Its kind is always specific, and
3357 -- we can use it directly, rather than the name of the operation.
3359 if Is_Integer_Type
(T1
)
3360 and then (Base_Type
(T2
) = Base_Type
(Standard_Integer
)
3361 or else T2
= Universal_Integer
)
3363 Add_One_Interp
(N
, Op_Id
, Base_Type
(T1
));
3366 end Check_Arithmetic_Pair
;
3368 -------------------------------
3369 -- Check_Misspelled_Selector --
3370 -------------------------------
3372 procedure Check_Misspelled_Selector
3373 (Prefix
: Entity_Id
;
3376 Max_Suggestions
: constant := 2;
3377 Nr_Of_Suggestions
: Natural := 0;
3379 Suggestion_1
: Entity_Id
:= Empty
;
3380 Suggestion_2
: Entity_Id
:= Empty
;
3385 -- All the components of the prefix of selector Sel are matched
3386 -- against Sel and a count is maintained of possible misspellings.
3387 -- When at the end of the analysis there are one or two (not more!)
3388 -- possible misspellings, these misspellings will be suggested as
3389 -- possible correction.
3391 if not (Is_Private_Type
(Prefix
) or Is_Record_Type
(Prefix
)) then
3392 -- Concurrent types should be handled as well ???
3396 Get_Name_String
(Chars
(Sel
));
3399 S
: constant String (1 .. Name_Len
) :=
3400 Name_Buffer
(1 .. Name_Len
);
3403 Comp
:= First_Entity
(Prefix
);
3405 while Nr_Of_Suggestions
<= Max_Suggestions
3406 and then Present
(Comp
)
3409 if Is_Visible_Component
(Comp
) then
3410 Get_Name_String
(Chars
(Comp
));
3412 if Is_Bad_Spelling_Of
(Name_Buffer
(1 .. Name_Len
), S
) then
3413 Nr_Of_Suggestions
:= Nr_Of_Suggestions
+ 1;
3415 case Nr_Of_Suggestions
is
3416 when 1 => Suggestion_1
:= Comp
;
3417 when 2 => Suggestion_2
:= Comp
;
3418 when others => exit;
3423 Comp
:= Next_Entity
(Comp
);
3426 -- Report at most two suggestions
3428 if Nr_Of_Suggestions
= 1 then
3429 Error_Msg_NE
("\possible misspelling of&", Sel
, Suggestion_1
);
3431 elsif Nr_Of_Suggestions
= 2 then
3432 Error_Msg_Node_2
:= Suggestion_2
;
3433 Error_Msg_NE
("\possible misspelling of& or&",
3437 end Check_Misspelled_Selector
;
3439 ----------------------
3440 -- Defined_In_Scope --
3441 ----------------------
3443 function Defined_In_Scope
(T
: Entity_Id
; S
: Entity_Id
) return Boolean
3445 S1
: constant Entity_Id
:= Scope
(Base_Type
(T
));
3449 or else (S1
= System_Aux_Id
and then S
= Scope
(S1
));
3450 end Defined_In_Scope
;
3456 procedure Diagnose_Call
(N
: Node_Id
; Nam
: Node_Id
) is
3463 Void_Interp_Seen
: Boolean := False;
3466 if Extensions_Allowed
then
3467 Actual
:= First_Actual
(N
);
3469 while Present
(Actual
) loop
3470 -- Ada 0Y (AI-50217): Post an error in case of premature usage of
3471 -- an entity from the limited view.
3473 if not Analyzed
(Etype
(Actual
))
3474 and then From_With_Type
(Etype
(Actual
))
3476 Error_Msg_Qual_Level
:= 1;
3478 ("missing with_clause for scope of imported type&",
3479 Actual
, Etype
(Actual
));
3480 Error_Msg_Qual_Level
:= 0;
3483 Next_Actual
(Actual
);
3487 -- Analyze each candidate call again, with full error reporting
3491 ("no candidate interpretations match the actuals:!", Nam
);
3492 Err_Mode
:= All_Errors_Mode
;
3493 All_Errors_Mode
:= True;
3495 -- If this is a call to an operation of a concurrent type,
3496 -- the failed interpretations have been removed from the
3497 -- name. Recover them to provide full diagnostics.
3499 if Nkind
(Parent
(Nam
)) = N_Selected_Component
then
3500 Set_Entity
(Nam
, Empty
);
3501 New_Nam
:= New_Copy_Tree
(Parent
(Nam
));
3502 Set_Is_Overloaded
(New_Nam
, False);
3503 Set_Is_Overloaded
(Selector_Name
(New_Nam
), False);
3504 Set_Parent
(New_Nam
, Parent
(Parent
(Nam
)));
3505 Analyze_Selected_Component
(New_Nam
);
3506 Get_First_Interp
(Selector_Name
(New_Nam
), X
, It
);
3508 Get_First_Interp
(Nam
, X
, It
);
3511 while Present
(It
.Nam
) loop
3512 if Etype
(It
.Nam
) = Standard_Void_Type
then
3513 Void_Interp_Seen
:= True;
3516 Analyze_One_Call
(N
, It
.Nam
, True, Success
);
3517 Get_Next_Interp
(X
, It
);
3520 if Nkind
(N
) = N_Function_Call
then
3521 Get_First_Interp
(Nam
, X
, It
);
3523 while Present
(It
.Nam
) loop
3524 if Ekind
(It
.Nam
) = E_Function
3525 or else Ekind
(It
.Nam
) = E_Operator
3529 Get_Next_Interp
(X
, It
);
3533 -- If all interpretations are procedures, this deserves a
3534 -- more precise message. Ditto if this appears as the prefix
3535 -- of a selected component, which may be a lexical error.
3538 "\context requires function call, found procedure name", Nam
);
3540 if Nkind
(Parent
(N
)) = N_Selected_Component
3541 and then N
= Prefix
(Parent
(N
))
3544 "\period should probably be semicolon", Parent
(N
));
3547 elsif Nkind
(N
) = N_Procedure_Call_Statement
3548 and then not Void_Interp_Seen
3551 "\function name found in procedure call", Nam
);
3554 All_Errors_Mode
:= Err_Mode
;
3557 ---------------------------
3558 -- Find_Arithmetic_Types --
3559 ---------------------------
3561 procedure Find_Arithmetic_Types
3566 Index1
, Index2
: Interp_Index
;
3569 procedure Check_Right_Argument
(T
: Entity_Id
);
3570 -- Check right operand of operator
3572 procedure Check_Right_Argument
(T
: Entity_Id
) is
3574 if not Is_Overloaded
(R
) then
3575 Check_Arithmetic_Pair
(T
, Etype
(R
), Op_Id
, N
);
3577 Get_First_Interp
(R
, Index2
, It2
);
3579 while Present
(It2
.Typ
) loop
3580 Check_Arithmetic_Pair
(T
, It2
.Typ
, Op_Id
, N
);
3581 Get_Next_Interp
(Index2
, It2
);
3584 end Check_Right_Argument
;
3586 -- Start processing for Find_Arithmetic_Types
3589 if not Is_Overloaded
(L
) then
3590 Check_Right_Argument
(Etype
(L
));
3593 Get_First_Interp
(L
, Index1
, It1
);
3595 while Present
(It1
.Typ
) loop
3596 Check_Right_Argument
(It1
.Typ
);
3597 Get_Next_Interp
(Index1
, It1
);
3601 end Find_Arithmetic_Types
;
3603 ------------------------
3604 -- Find_Boolean_Types --
3605 ------------------------
3607 procedure Find_Boolean_Types
3612 Index
: Interp_Index
;
3615 procedure Check_Numeric_Argument
(T
: Entity_Id
);
3616 -- Special case for logical operations one of whose operands is an
3617 -- integer literal. If both are literal the result is any modular type.
3619 procedure Check_Numeric_Argument
(T
: Entity_Id
) is
3621 if T
= Universal_Integer
then
3622 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
3624 elsif Is_Modular_Integer_Type
(T
) then
3625 Add_One_Interp
(N
, Op_Id
, T
);
3627 end Check_Numeric_Argument
;
3629 -- Start of processing for Find_Boolean_Types
3632 if not Is_Overloaded
(L
) then
3634 if Etype
(L
) = Universal_Integer
3635 or else Etype
(L
) = Any_Modular
3637 if not Is_Overloaded
(R
) then
3638 Check_Numeric_Argument
(Etype
(R
));
3641 Get_First_Interp
(R
, Index
, It
);
3643 while Present
(It
.Typ
) loop
3644 Check_Numeric_Argument
(It
.Typ
);
3646 Get_Next_Interp
(Index
, It
);
3650 elsif Valid_Boolean_Arg
(Etype
(L
))
3651 and then Has_Compatible_Type
(R
, Etype
(L
))
3653 Add_One_Interp
(N
, Op_Id
, Etype
(L
));
3657 Get_First_Interp
(L
, Index
, It
);
3659 while Present
(It
.Typ
) loop
3660 if Valid_Boolean_Arg
(It
.Typ
)
3661 and then Has_Compatible_Type
(R
, It
.Typ
)
3663 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
3666 Get_Next_Interp
(Index
, It
);
3669 end Find_Boolean_Types
;
3671 ---------------------------
3672 -- Find_Comparison_Types --
3673 ---------------------------
3675 procedure Find_Comparison_Types
3680 Index
: Interp_Index
;
3682 Found
: Boolean := False;
3685 Scop
: Entity_Id
:= Empty
;
3687 procedure Try_One_Interp
(T1
: Entity_Id
);
3688 -- Routine to try one proposed interpretation. Note that the context
3689 -- of the operator plays no role in resolving the arguments, so that
3690 -- if there is more than one interpretation of the operands that is
3691 -- compatible with comparison, the operation is ambiguous.
3693 procedure Try_One_Interp
(T1
: Entity_Id
) is
3696 -- If the operator is an expanded name, then the type of the operand
3697 -- must be defined in the corresponding scope. If the type is
3698 -- universal, the context will impose the correct type.
3701 and then not Defined_In_Scope
(T1
, Scop
)
3702 and then T1
/= Universal_Integer
3703 and then T1
/= Universal_Real
3704 and then T1
/= Any_String
3705 and then T1
/= Any_Composite
3710 if Valid_Comparison_Arg
(T1
)
3711 and then Has_Compatible_Type
(R
, T1
)
3714 and then Base_Type
(T1
) /= Base_Type
(T_F
)
3716 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
3718 if It
= No_Interp
then
3719 Ambiguous_Operands
(N
);
3720 Set_Etype
(L
, Any_Type
);
3734 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
3739 -- Start processing for Find_Comparison_Types
3742 -- If left operand is aggregate, the right operand has to
3743 -- provide a usable type for it.
3745 if Nkind
(L
) = N_Aggregate
3746 and then Nkind
(R
) /= N_Aggregate
3748 Find_Comparison_Types
(R
, L
, Op_Id
, N
);
3752 if Nkind
(N
) = N_Function_Call
3753 and then Nkind
(Name
(N
)) = N_Expanded_Name
3755 Scop
:= Entity
(Prefix
(Name
(N
)));
3757 -- The prefix may be a package renaming, and the subsequent test
3758 -- requires the original package.
3760 if Ekind
(Scop
) = E_Package
3761 and then Present
(Renamed_Entity
(Scop
))
3763 Scop
:= Renamed_Entity
(Scop
);
3764 Set_Entity
(Prefix
(Name
(N
)), Scop
);
3768 if not Is_Overloaded
(L
) then
3769 Try_One_Interp
(Etype
(L
));
3772 Get_First_Interp
(L
, Index
, It
);
3774 while Present
(It
.Typ
) loop
3775 Try_One_Interp
(It
.Typ
);
3776 Get_Next_Interp
(Index
, It
);
3779 end Find_Comparison_Types
;
3781 ----------------------------------------
3782 -- Find_Non_Universal_Interpretations --
3783 ----------------------------------------
3785 procedure Find_Non_Universal_Interpretations
3791 Index
: Interp_Index
;
3795 if T1
= Universal_Integer
3796 or else T1
= Universal_Real
3798 if not Is_Overloaded
(R
) then
3800 (N
, Op_Id
, Standard_Boolean
, Base_Type
(Etype
(R
)));
3802 Get_First_Interp
(R
, Index
, It
);
3804 while Present
(It
.Typ
) loop
3805 if Covers
(It
.Typ
, T1
) then
3807 (N
, Op_Id
, Standard_Boolean
, Base_Type
(It
.Typ
));
3810 Get_Next_Interp
(Index
, It
);
3814 Add_One_Interp
(N
, Op_Id
, Standard_Boolean
, Base_Type
(T1
));
3816 end Find_Non_Universal_Interpretations
;
3818 ------------------------------
3819 -- Find_Concatenation_Types --
3820 ------------------------------
3822 procedure Find_Concatenation_Types
3827 Op_Type
: constant Entity_Id
:= Etype
(Op_Id
);
3830 if Is_Array_Type
(Op_Type
)
3831 and then not Is_Limited_Type
(Op_Type
)
3833 and then (Has_Compatible_Type
(L
, Op_Type
)
3835 Has_Compatible_Type
(L
, Component_Type
(Op_Type
)))
3837 and then (Has_Compatible_Type
(R
, Op_Type
)
3839 Has_Compatible_Type
(R
, Component_Type
(Op_Type
)))
3841 Add_One_Interp
(N
, Op_Id
, Op_Type
);
3843 end Find_Concatenation_Types
;
3845 -------------------------
3846 -- Find_Equality_Types --
3847 -------------------------
3849 procedure Find_Equality_Types
3854 Index
: Interp_Index
;
3856 Found
: Boolean := False;
3859 Scop
: Entity_Id
:= Empty
;
3861 procedure Try_One_Interp
(T1
: Entity_Id
);
3862 -- The context of the operator plays no role in resolving the
3863 -- arguments, so that if there is more than one interpretation
3864 -- of the operands that is compatible with equality, the construct
3865 -- is ambiguous and an error can be emitted now, after trying to
3866 -- disambiguate, i.e. applying preference rules.
3868 procedure Try_One_Interp
(T1
: Entity_Id
) is
3871 -- If the operator is an expanded name, then the type of the operand
3872 -- must be defined in the corresponding scope. If the type is
3873 -- universal, the context will impose the correct type. An anonymous
3874 -- type for a 'Access reference is also universal in this sense, as
3875 -- the actual type is obtained from context.
3878 and then not Defined_In_Scope
(T1
, Scop
)
3879 and then T1
/= Universal_Integer
3880 and then T1
/= Universal_Real
3881 and then T1
/= Any_Access
3882 and then T1
/= Any_String
3883 and then T1
/= Any_Composite
3884 and then (Ekind
(T1
) /= E_Access_Subprogram_Type
3885 or else Comes_From_Source
(T1
))
3890 -- Ada 0Y (AI-230): Keep restriction imposed by Ada 83 and 95: Do not
3891 -- allow anonymous access types in equality operators.
3893 if not Extensions_Allowed
3894 and then Ekind
(T1
) = E_Anonymous_Access_Type
3899 if T1
/= Standard_Void_Type
3900 and then not Is_Limited_Type
(T1
)
3901 and then not Is_Limited_Composite
(T1
)
3902 and then Has_Compatible_Type
(R
, T1
)
3905 and then Base_Type
(T1
) /= Base_Type
(T_F
)
3907 It
:= Disambiguate
(L
, I_F
, Index
, Any_Type
);
3909 if It
= No_Interp
then
3910 Ambiguous_Operands
(N
);
3911 Set_Etype
(L
, Any_Type
);
3924 if not Analyzed
(L
) then
3928 Find_Non_Universal_Interpretations
(N
, R
, Op_Id
, T1
);
3930 if Etype
(N
) = Any_Type
then
3932 -- Operator was not visible.
3939 -- Start of processing for Find_Equality_Types
3942 -- If left operand is aggregate, the right operand has to
3943 -- provide a usable type for it.
3945 if Nkind
(L
) = N_Aggregate
3946 and then Nkind
(R
) /= N_Aggregate
3948 Find_Equality_Types
(R
, L
, Op_Id
, N
);
3952 if Nkind
(N
) = N_Function_Call
3953 and then Nkind
(Name
(N
)) = N_Expanded_Name
3955 Scop
:= Entity
(Prefix
(Name
(N
)));
3957 -- The prefix may be a package renaming, and the subsequent test
3958 -- requires the original package.
3960 if Ekind
(Scop
) = E_Package
3961 and then Present
(Renamed_Entity
(Scop
))
3963 Scop
:= Renamed_Entity
(Scop
);
3964 Set_Entity
(Prefix
(Name
(N
)), Scop
);
3968 if not Is_Overloaded
(L
) then
3969 Try_One_Interp
(Etype
(L
));
3972 Get_First_Interp
(L
, Index
, It
);
3974 while Present
(It
.Typ
) loop
3975 Try_One_Interp
(It
.Typ
);
3976 Get_Next_Interp
(Index
, It
);
3979 end Find_Equality_Types
;
3981 -------------------------
3982 -- Find_Negation_Types --
3983 -------------------------
3985 procedure Find_Negation_Types
3990 Index
: Interp_Index
;
3994 if not Is_Overloaded
(R
) then
3996 if Etype
(R
) = Universal_Integer
then
3997 Add_One_Interp
(N
, Op_Id
, Any_Modular
);
3999 elsif Valid_Boolean_Arg
(Etype
(R
)) then
4000 Add_One_Interp
(N
, Op_Id
, Etype
(R
));
4004 Get_First_Interp
(R
, Index
, It
);
4006 while Present
(It
.Typ
) loop
4007 if Valid_Boolean_Arg
(It
.Typ
) then
4008 Add_One_Interp
(N
, Op_Id
, It
.Typ
);
4011 Get_Next_Interp
(Index
, It
);
4014 end Find_Negation_Types
;
4016 ----------------------
4017 -- Find_Unary_Types --
4018 ----------------------
4020 procedure Find_Unary_Types
4025 Index
: Interp_Index
;
4029 if not Is_Overloaded
(R
) then
4030 if Is_Numeric_Type
(Etype
(R
)) then
4031 Add_One_Interp
(N
, Op_Id
, Base_Type
(Etype
(R
)));
4035 Get_First_Interp
(R
, Index
, It
);
4037 while Present
(It
.Typ
) loop
4038 if Is_Numeric_Type
(It
.Typ
) then
4039 Add_One_Interp
(N
, Op_Id
, Base_Type
(It
.Typ
));
4042 Get_Next_Interp
(Index
, It
);
4045 end Find_Unary_Types
;
4051 function Junk_Operand
(N
: Node_Id
) return Boolean is
4055 if Error_Posted
(N
) then
4059 -- Get entity to be tested
4061 if Is_Entity_Name
(N
)
4062 and then Present
(Entity
(N
))
4066 -- An odd case, a procedure name gets converted to a very peculiar
4067 -- function call, and here is where we detect this happening.
4069 elsif Nkind
(N
) = N_Function_Call
4070 and then Is_Entity_Name
(Name
(N
))
4071 and then Present
(Entity
(Name
(N
)))
4075 -- Another odd case, there are at least some cases of selected
4076 -- components where the selected component is not marked as having
4077 -- an entity, even though the selector does have an entity
4079 elsif Nkind
(N
) = N_Selected_Component
4080 and then Present
(Entity
(Selector_Name
(N
)))
4082 Enode
:= Selector_Name
(N
);
4088 -- Now test the entity we got to see if it a bad case
4090 case Ekind
(Entity
(Enode
)) is
4094 ("package name cannot be used as operand", Enode
);
4096 when Generic_Unit_Kind
=>
4098 ("generic unit name cannot be used as operand", Enode
);
4102 ("subtype name cannot be used as operand", Enode
);
4106 ("entry name cannot be used as operand", Enode
);
4110 ("procedure name cannot be used as operand", Enode
);
4114 ("exception name cannot be used as operand", Enode
);
4116 when E_Block | E_Label | E_Loop
=>
4118 ("label name cannot be used as operand", Enode
);
4128 --------------------
4129 -- Operator_Check --
4130 --------------------
4132 procedure Operator_Check
(N
: Node_Id
) is
4134 Remove_Abstract_Operations
(N
);
4136 -- Test for case of no interpretation found for operator
4138 if Etype
(N
) = Any_Type
then
4144 R
:= Right_Opnd
(N
);
4146 if Nkind
(N
) in N_Binary_Op
then
4152 -- If either operand has no type, then don't complain further,
4153 -- since this simply means that we have a propragated error.
4156 or else Etype
(R
) = Any_Type
4157 or else (Nkind
(N
) in N_Binary_Op
and then Etype
(L
) = Any_Type
)
4161 -- We explicitly check for the case of concatenation of
4162 -- component with component to avoid reporting spurious
4163 -- matching array types that might happen to be lurking
4164 -- in distant packages (such as run-time packages). This
4165 -- also prevents inconsistencies in the messages for certain
4166 -- ACVC B tests, which can vary depending on types declared
4167 -- in run-time interfaces. A further improvement, when
4168 -- aggregates are present, is to look for a well-typed operand.
4170 elsif Present
(Candidate_Type
)
4171 and then (Nkind
(N
) /= N_Op_Concat
4172 or else Is_Array_Type
(Etype
(L
))
4173 or else Is_Array_Type
(Etype
(R
)))
4176 if Nkind
(N
) = N_Op_Concat
then
4177 if Etype
(L
) /= Any_Composite
4178 and then Is_Array_Type
(Etype
(L
))
4180 Candidate_Type
:= Etype
(L
);
4182 elsif Etype
(R
) /= Any_Composite
4183 and then Is_Array_Type
(Etype
(R
))
4185 Candidate_Type
:= Etype
(R
);
4190 ("operator for} is not directly visible!",
4191 N
, First_Subtype
(Candidate_Type
));
4192 Error_Msg_N
("use clause would make operation legal!", N
);
4195 -- If either operand is a junk operand (e.g. package name), then
4196 -- post appropriate error messages, but do not complain further.
4198 -- Note that the use of OR in this test instead of OR ELSE
4199 -- is quite deliberate, we may as well check both operands
4200 -- in the binary operator case.
4202 elsif Junk_Operand
(R
)
4203 or (Nkind
(N
) in N_Binary_Op
and then Junk_Operand
(L
))
4207 -- If we have a logical operator, one of whose operands is
4208 -- Boolean, then we know that the other operand cannot resolve
4209 -- to Boolean (since we got no interpretations), but in that
4210 -- case we pretty much know that the other operand should be
4211 -- Boolean, so resolve it that way (generating an error)
4213 elsif Nkind
(N
) = N_Op_And
4217 Nkind
(N
) = N_Op_Xor
4219 if Etype
(L
) = Standard_Boolean
then
4220 Resolve
(R
, Standard_Boolean
);
4222 elsif Etype
(R
) = Standard_Boolean
then
4223 Resolve
(L
, Standard_Boolean
);
4227 -- For an arithmetic operator or comparison operator, if one
4228 -- of the operands is numeric, then we know the other operand
4229 -- is not the same numeric type. If it is a non-numeric type,
4230 -- then probably it is intended to match the other operand.
4232 elsif Nkind
(N
) = N_Op_Add
or else
4233 Nkind
(N
) = N_Op_Divide
or else
4234 Nkind
(N
) = N_Op_Ge
or else
4235 Nkind
(N
) = N_Op_Gt
or else
4236 Nkind
(N
) = N_Op_Le
or else
4237 Nkind
(N
) = N_Op_Lt
or else
4238 Nkind
(N
) = N_Op_Mod
or else
4239 Nkind
(N
) = N_Op_Multiply
or else
4240 Nkind
(N
) = N_Op_Rem
or else
4241 Nkind
(N
) = N_Op_Subtract
4243 if Is_Numeric_Type
(Etype
(L
))
4244 and then not Is_Numeric_Type
(Etype
(R
))
4246 Resolve
(R
, Etype
(L
));
4249 elsif Is_Numeric_Type
(Etype
(R
))
4250 and then not Is_Numeric_Type
(Etype
(L
))
4252 Resolve
(L
, Etype
(R
));
4256 -- Comparisons on A'Access are common enough to deserve a
4259 elsif (Nkind
(N
) = N_Op_Eq
or else
4260 Nkind
(N
) = N_Op_Ne
)
4261 and then Ekind
(Etype
(L
)) = E_Access_Attribute_Type
4262 and then Ekind
(Etype
(R
)) = E_Access_Attribute_Type
4265 ("two access attributes cannot be compared directly", N
);
4267 ("\they must be converted to an explicit type for comparison",
4271 -- Another one for C programmers
4273 elsif Nkind
(N
) = N_Op_Concat
4274 and then Valid_Boolean_Arg
(Etype
(L
))
4275 and then Valid_Boolean_Arg
(Etype
(R
))
4277 Error_Msg_N
("invalid operands for concatenation", N
);
4278 Error_Msg_N
("\maybe AND was meant", N
);
4281 -- A special case for comparison of access parameter with null
4283 elsif Nkind
(N
) = N_Op_Eq
4284 and then Is_Entity_Name
(L
)
4285 and then Nkind
(Parent
(Entity
(L
))) = N_Parameter_Specification
4286 and then Nkind
(Parameter_Type
(Parent
(Entity
(L
)))) =
4288 and then Nkind
(R
) = N_Null
4290 Error_Msg_N
("access parameter is not allowed to be null", L
);
4291 Error_Msg_N
("\(call would raise Constraint_Error)", L
);
4295 -- If we fall through then just give general message. Note
4296 -- that in the following messages, if the operand is overloaded
4297 -- we choose an arbitrary type to complain about, but that is
4298 -- probably more useful than not giving a type at all.
4300 if Nkind
(N
) in N_Unary_Op
then
4301 Error_Msg_Node_2
:= Etype
(R
);
4302 Error_Msg_N
("operator& not defined for}", N
);
4306 if Nkind
(N
) in N_Binary_Op
then
4307 if not Is_Overloaded
(L
)
4308 and then not Is_Overloaded
(R
)
4309 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
4311 Error_Msg_Node_2
:= Etype
(R
);
4312 Error_Msg_N
("there is no applicable operator& for}", N
);
4315 Error_Msg_N
("invalid operand types for operator&", N
);
4317 if Nkind
(N
) /= N_Op_Concat
then
4318 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
4319 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
4328 --------------------------------
4329 -- Remove_Abstract_Operations --
4330 --------------------------------
4332 procedure Remove_Abstract_Operations
(N
: Node_Id
) is
4335 Abstract_Op
: Entity_Id
:= Empty
;
4337 -- AI-310: If overloaded, remove abstract non-dispatching
4341 if Extensions_Allowed
4342 and then Is_Overloaded
(N
)
4344 Get_First_Interp
(N
, I
, It
);
4345 while Present
(It
.Nam
) loop
4346 if not Is_Type
(It
.Nam
)
4347 and then Is_Abstract
(It
.Nam
)
4348 and then not Is_Dispatching_Operation
(It
.Nam
)
4350 Abstract_Op
:= It
.Nam
;
4355 Get_Next_Interp
(I
, It
);
4358 -- Remove corresponding predefined operator, which is
4359 -- always added to the overload set, unless it is a universal
4362 if No
(Abstract_Op
) then
4365 elsif Nkind
(N
) in N_Op
then
4366 if Nkind
(N
) in N_Unary_Op
4367 and then Present
(Universal_Interpretation
(Right_Opnd
(N
)))
4371 elsif Nkind
(N
) in N_Binary_Op
4372 and then Present
(Universal_Interpretation
(Right_Opnd
(N
)))
4373 and then Present
(Universal_Interpretation
(Left_Opnd
(N
)))
4378 Get_First_Interp
(N
, I
, It
);
4379 while Present
(It
.Nam
) loop
4380 if Scope
(It
.Nam
) = Standard_Standard
then
4384 Get_Next_Interp
(I
, It
);
4388 elsif Nkind
(N
) = N_Function_Call
4390 (Nkind
(Name
(N
)) = N_Operator_Symbol
4392 (Nkind
(Name
(N
)) = N_Expanded_Name
4394 Nkind
(Selector_Name
(Name
(N
))) = N_Operator_Symbol
))
4397 Arg1
: constant Node_Id
:= First
(Parameter_Associations
(N
));
4400 if Present
(Universal_Interpretation
(Arg1
))
4403 or else Present
(Universal_Interpretation
(Next
(Arg1
))))
4408 Get_First_Interp
(N
, I
, It
);
4409 while Present
(It
.Nam
) loop
4410 if Scope
(It
.Nam
) = Standard_Standard
then
4414 Get_Next_Interp
(I
, It
);
4420 -- If the removal has left no valid interpretations, emit
4421 -- error message now an label node as illegal.
4423 if Present
(Abstract_Op
) then
4424 Get_First_Interp
(N
, I
, It
);
4428 -- Removal of abstract operation left no viable candidate.
4430 Set_Etype
(N
, Any_Type
);
4431 Error_Msg_Sloc
:= Sloc
(Abstract_Op
);
4433 ("cannot call abstract operation& declared#", N
, Abstract_Op
);
4437 end Remove_Abstract_Operations
;
4439 -----------------------
4440 -- Try_Indirect_Call --
4441 -----------------------
4443 function Try_Indirect_Call
4446 Typ
: Entity_Id
) return Boolean
4453 Normalize_Actuals
(N
, Designated_Type
(Typ
), False, Call_OK
);
4454 Actual
:= First_Actual
(N
);
4455 Formal
:= First_Formal
(Designated_Type
(Typ
));
4457 while Present
(Actual
)
4458 and then Present
(Formal
)
4460 if not Has_Compatible_Type
(Actual
, Etype
(Formal
)) then
4465 Next_Formal
(Formal
);
4468 if No
(Actual
) and then No
(Formal
) then
4469 Add_One_Interp
(N
, Nam
, Etype
(Designated_Type
(Typ
)));
4471 -- Nam is a candidate interpretation for the name in the call,
4472 -- if it is not an indirect call.
4474 if not Is_Type
(Nam
)
4475 and then Is_Entity_Name
(Name
(N
))
4477 Set_Entity
(Name
(N
), Nam
);
4484 end Try_Indirect_Call
;
4486 ----------------------
4487 -- Try_Indexed_Call --
4488 ----------------------
4490 function Try_Indexed_Call
4493 Typ
: Entity_Id
) return Boolean
4495 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
4500 Actual
:= First
(Actuals
);
4501 Index
:= First_Index
(Typ
);
4502 while Present
(Actual
)
4503 and then Present
(Index
)
4505 -- If the parameter list has a named association, the expression
4506 -- is definitely a call and not an indexed component.
4508 if Nkind
(Actual
) = N_Parameter_Association
then
4512 if not Has_Compatible_Type
(Actual
, Etype
(Index
)) then
4520 if No
(Actual
) and then No
(Index
) then
4521 Add_One_Interp
(N
, Nam
, Component_Type
(Typ
));
4523 -- Nam is a candidate interpretation for the name in the call,
4524 -- if it is not an indirect call.
4526 if not Is_Type
(Nam
)
4527 and then Is_Entity_Name
(Name
(N
))
4529 Set_Entity
(Name
(N
), Nam
);
4537 end Try_Indexed_Call
;